three.js 862 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649306503065130652306533065430655306563065730658306593066030661306623066330664306653066630667306683066930670306713067230673306743067530676306773067830679306803068130682306833068430685306863068730688306893069030691306923069330694306953069630697306983069930700307013070230703307043070530706307073070830709307103071130712307133071430715307163071730718307193072030721307223072330724307253072630727307283072930730307313073230733307343073530736307373073830739307403074130742307433074430745307463074730748307493075030751307523075330754307553075630757307583075930760307613076230763307643076530766307673076830769307703077130772307733077430775307763077730778307793078030781307823078330784307853078630787307883078930790307913079230793307943079530796307973079830799308003080130802308033080430805308063080730808308093081030811308123081330814308153081630817308183081930820308213082230823308243082530826308273082830829308303083130832308333083430835308363083730838308393084030841308423084330844308453084630847308483084930850308513085230853308543085530856308573085830859308603086130862308633086430865308663086730868308693087030871308723087330874308753087630877308783087930880308813088230883308843088530886308873088830889308903089130892308933089430895308963089730898308993090030901309023090330904309053090630907309083090930910309113091230913309143091530916309173091830919309203092130922309233092430925309263092730928309293093030931309323093330934309353093630937309383093930940309413094230943309443094530946309473094830949309503095130952309533095430955309563095730958309593096030961309623096330964309653096630967309683096930970309713097230973309743097530976309773097830979309803098130982309833098430985309863098730988309893099030991309923099330994309953099630997309983099931000310013100231003310043100531006310073100831009310103101131012310133101431015310163101731018310193102031021310223102331024310253102631027310283102931030310313103231033310343103531036310373103831039310403104131042310433104431045310463104731048310493105031051310523105331054310553105631057310583105931060310613106231063310643106531066310673106831069310703107131072310733107431075310763107731078310793108031081310823108331084310853108631087310883108931090310913109231093310943109531096310973109831099311003110131102311033110431105311063110731108311093111031111311123111331114311153111631117311183111931120311213112231123311243112531126311273112831129311303113131132311333113431135311363113731138311393114031141311423114331144311453114631147311483114931150311513115231153311543115531156311573115831159311603116131162311633116431165311663116731168311693117031171311723117331174311753117631177311783117931180311813118231183311843118531186311873118831189311903119131192311933119431195311963119731198311993120031201312023120331204312053120631207312083120931210312113121231213312143121531216312173121831219312203122131222312233122431225312263122731228312293123031231312323123331234312353123631237312383123931240312413124231243312443124531246312473124831249312503125131252312533125431255312563125731258312593126031261312623126331264312653126631267312683126931270312713127231273312743127531276312773127831279312803128131282312833128431285312863128731288312893129031291312923129331294312953129631297312983129931300313013130231303313043130531306313073130831309313103131131312313133131431315313163131731318313193132031321313223132331324313253132631327313283132931330313313133231333313343133531336313373133831339313403134131342313433134431345313463134731348313493135031351313523135331354313553135631357313583135931360313613136231363313643136531366313673136831369313703137131372313733137431375313763137731378313793138031381313823138331384313853138631387313883138931390313913139231393313943139531396313973139831399314003140131402314033140431405314063140731408314093141031411314123141331414314153141631417314183141931420314213142231423314243142531426314273142831429314303143131432314333143431435314363143731438314393144031441314423144331444314453144631447314483144931450314513145231453314543145531456314573145831459314603146131462314633146431465314663146731468314693147031471314723147331474314753147631477314783147931480314813148231483314843148531486314873148831489314903149131492314933149431495314963149731498314993150031501315023150331504315053150631507315083150931510315113151231513315143151531516315173151831519315203152131522315233152431525315263152731528315293153031531315323153331534315353153631537315383153931540315413154231543315443154531546315473154831549315503155131552315533155431555315563155731558315593156031561315623156331564315653156631567315683156931570315713157231573315743157531576315773157831579315803158131582315833158431585315863158731588315893159031591315923159331594315953159631597315983159931600316013160231603316043160531606316073160831609316103161131612316133161431615316163161731618316193162031621316223162331624316253162631627316283162931630316313163231633316343163531636316373163831639316403164131642316433164431645316463164731648316493165031651316523165331654316553165631657316583165931660316613166231663316643166531666316673166831669316703167131672316733167431675316763167731678316793168031681316823168331684316853168631687316883168931690316913169231693316943169531696316973169831699317003170131702317033170431705317063170731708317093171031711317123171331714317153171631717317183171931720317213172231723317243172531726317273172831729317303173131732317333173431735317363173731738317393174031741317423174331744317453174631747317483174931750317513175231753317543175531756317573175831759317603176131762317633176431765317663176731768317693177031771317723177331774317753177631777317783177931780317813178231783317843178531786317873178831789317903179131792317933179431795317963179731798317993180031801318023180331804318053180631807318083180931810318113181231813318143181531816318173181831819318203182131822318233182431825318263182731828318293183031831318323183331834318353183631837318383183931840318413184231843318443184531846318473184831849318503185131852318533185431855318563185731858318593186031861318623186331864318653186631867318683186931870318713187231873318743187531876318773187831879318803188131882318833188431885318863188731888318893189031891318923189331894318953189631897318983189931900319013190231903319043190531906319073190831909319103191131912319133191431915319163191731918319193192031921319223192331924319253192631927319283192931930319313193231933319343193531936319373193831939319403194131942319433194431945319463194731948319493195031951319523195331954319553195631957319583195931960319613196231963319643196531966319673196831969319703197131972319733197431975319763197731978319793198031981319823198331984319853198631987319883198931990319913199231993319943199531996319973199831999320003200132002320033200432005320063200732008320093201032011320123201332014320153201632017320183201932020320213202232023320243202532026320273202832029320303203132032320333203432035320363203732038320393204032041320423204332044320453204632047320483204932050320513205232053320543205532056320573205832059320603206132062320633206432065320663206732068320693207032071320723207332074320753207632077320783207932080320813208232083320843208532086320873208832089320903209132092320933209432095320963209732098320993210032101321023210332104321053210632107321083210932110321113211232113321143211532116321173211832119321203212132122321233212432125321263212732128321293213032131321323213332134321353213632137321383213932140321413214232143321443214532146321473214832149321503215132152321533215432155321563215732158321593216032161321623216332164321653216632167321683216932170321713217232173321743217532176321773217832179321803218132182321833218432185321863218732188321893219032191321923219332194321953219632197321983219932200322013220232203322043220532206322073220832209322103221132212322133221432215322163221732218322193222032221322223222332224322253222632227322283222932230322313223232233322343223532236322373223832239322403224132242322433224432245322463224732248322493225032251322523225332254322553225632257322583225932260322613226232263322643226532266322673226832269322703227132272322733227432275322763227732278322793228032281322823228332284322853228632287322883228932290322913229232293322943229532296322973229832299323003230132302323033230432305323063230732308323093231032311323123231332314323153231632317323183231932320323213232232323323243232532326323273232832329323303233132332323333233432335323363233732338323393234032341323423234332344323453234632347323483234932350323513235232353323543235532356323573235832359323603236132362323633236432365323663236732368323693237032371323723237332374323753237632377323783237932380323813238232383323843238532386323873238832389323903239132392323933239432395323963239732398323993240032401324023240332404324053240632407324083240932410324113241232413324143241532416324173241832419324203242132422324233242432425324263242732428324293243032431324323243332434324353243632437324383243932440324413244232443324443244532446324473244832449324503245132452324533245432455324563245732458324593246032461324623246332464324653246632467324683246932470324713247232473324743247532476324773247832479324803248132482324833248432485324863248732488324893249032491324923249332494324953249632497324983249932500325013250232503325043250532506325073250832509325103251132512325133251432515325163251732518325193252032521325223252332524325253252632527325283252932530325313253232533325343253532536325373253832539325403254132542325433254432545325463254732548325493255032551325523255332554325553255632557325583255932560325613256232563325643256532566325673256832569325703257132572325733257432575325763257732578325793258032581325823258332584325853258632587325883258932590325913259232593325943259532596325973259832599326003260132602326033260432605326063260732608326093261032611326123261332614326153261632617326183261932620326213262232623326243262532626326273262832629326303263132632326333263432635326363263732638326393264032641326423264332644326453264632647326483264932650326513265232653326543265532656326573265832659326603266132662326633266432665326663266732668326693267032671326723267332674326753267632677326783267932680326813268232683326843268532686326873268832689326903269132692326933269432695326963269732698326993270032701327023270332704327053270632707327083270932710327113271232713327143271532716327173271832719327203272132722327233272432725327263272732728327293273032731327323273332734327353273632737327383273932740327413274232743327443274532746327473274832749327503275132752327533275432755327563275732758327593276032761327623276332764327653276632767327683276932770327713277232773327743277532776327773277832779327803278132782327833278432785327863278732788327893279032791327923279332794327953279632797327983279932800328013280232803328043280532806328073280832809328103281132812328133281432815328163281732818328193282032821328223282332824328253282632827328283282932830328313283232833328343283532836328373283832839328403284132842328433284432845328463284732848328493285032851328523285332854328553285632857328583285932860328613286232863328643286532866328673286832869328703287132872328733287432875328763287732878328793288032881328823288332884328853288632887328883288932890328913289232893328943289532896328973289832899329003290132902329033290432905329063290732908329093291032911329123291332914329153291632917329183291932920329213292232923329243292532926329273292832929329303293132932329333293432935329363293732938329393294032941329423294332944329453294632947329483294932950329513295232953329543295532956329573295832959329603296132962329633296432965329663296732968329693297032971329723297332974329753297632977329783297932980329813298232983329843298532986329873298832989329903299132992329933299432995329963299732998329993300033001330023300333004330053300633007330083300933010330113301233013330143301533016330173301833019330203302133022330233302433025330263302733028330293303033031330323303333034330353303633037330383303933040330413304233043330443304533046330473304833049330503305133052330533305433055330563305733058330593306033061330623306333064330653306633067330683306933070330713307233073330743307533076330773307833079330803308133082330833308433085330863308733088330893309033091330923309333094330953309633097330983309933100331013310233103331043310533106331073310833109331103311133112331133311433115331163311733118331193312033121331223312333124331253312633127331283312933130331313313233133331343313533136331373313833139331403314133142331433314433145331463314733148331493315033151331523315333154331553315633157331583315933160331613316233163331643316533166331673316833169331703317133172331733317433175331763317733178331793318033181331823318333184331853318633187331883318933190331913319233193331943319533196331973319833199332003320133202332033320433205332063320733208332093321033211332123321333214332153321633217332183321933220332213322233223332243322533226332273322833229332303323133232332333323433235332363323733238332393324033241332423324333244332453324633247332483324933250332513325233253332543325533256332573325833259332603326133262332633326433265332663326733268332693327033271332723327333274332753327633277332783327933280332813328233283332843328533286332873328833289332903329133292332933329433295332963329733298332993330033301333023330333304333053330633307333083330933310333113331233313333143331533316333173331833319333203332133322333233332433325333263332733328333293333033331333323333333334333353333633337333383333933340333413334233343333443334533346333473334833349333503335133352333533335433355333563335733358333593336033361333623336333364333653336633367333683336933370333713337233373333743337533376333773337833379333803338133382333833338433385333863338733388333893339033391333923339333394333953339633397333983339933400334013340233403334043340533406334073340833409334103341133412334133341433415334163341733418334193342033421334223342333424334253342633427334283342933430334313343233433334343343533436334373343833439334403344133442334433344433445334463344733448334493345033451334523345333454334553345633457334583345933460334613346233463334643346533466334673346833469334703347133472334733347433475334763347733478334793348033481334823348333484334853348633487334883348933490334913349233493334943349533496334973349833499335003350133502335033350433505335063350733508335093351033511335123351333514335153351633517335183351933520335213352233523335243352533526335273352833529335303353133532335333353433535335363353733538335393354033541335423354333544335453354633547335483354933550335513355233553335543355533556335573355833559335603356133562335633356433565335663356733568335693357033571335723357333574335753357633577335783357933580335813358233583335843358533586335873358833589335903359133592335933359433595335963359733598335993360033601336023360333604336053360633607336083360933610336113361233613336143361533616336173361833619336203362133622336233362433625336263362733628336293363033631336323363333634336353363633637336383363933640336413364233643336443364533646336473364833649336503365133652336533365433655336563365733658336593366033661336623366333664336653366633667336683366933670336713367233673336743367533676336773367833679336803368133682336833368433685336863368733688336893369033691336923369333694336953369633697336983369933700337013370233703337043370533706337073370833709337103371133712337133371433715337163371733718337193372033721337223372333724337253372633727337283372933730337313373233733337343373533736337373373833739337403374133742337433374433745337463374733748337493375033751337523375333754337553375633757337583375933760337613376233763337643376533766337673376833769337703377133772337733377433775337763377733778337793378033781337823378333784337853378633787337883378933790337913379233793337943379533796337973379833799338003380133802338033380433805338063380733808338093381033811338123381333814338153381633817338183381933820338213382233823338243382533826338273382833829338303383133832338333383433835338363383733838338393384033841338423384333844338453384633847338483384933850338513385233853338543385533856338573385833859338603386133862338633386433865338663386733868338693387033871338723387333874338753387633877338783387933880338813388233883338843388533886338873388833889338903389133892338933389433895338963389733898338993390033901339023390333904339053390633907339083390933910339113391233913339143391533916339173391833919339203392133922339233392433925339263392733928339293393033931339323393333934339353393633937339383393933940339413394233943339443394533946339473394833949339503395133952339533395433955339563395733958339593396033961339623396333964339653396633967339683396933970339713397233973339743397533976339773397833979339803398133982339833398433985339863398733988339893399033991339923399333994339953399633997339983399934000340013400234003340043400534006340073400834009340103401134012340133401434015340163401734018340193402034021340223402334024340253402634027340283402934030340313403234033340343403534036340373403834039340403404134042340433404434045340463404734048340493405034051340523405334054340553405634057340583405934060340613406234063340643406534066340673406834069340703407134072340733407434075340763407734078340793408034081340823408334084340853408634087340883408934090340913409234093340943409534096340973409834099341003410134102341033410434105341063410734108341093411034111341123411334114341153411634117341183411934120341213412234123341243412534126341273412834129341303413134132341333413434135341363413734138341393414034141341423414334144341453414634147341483414934150341513415234153341543415534156341573415834159341603416134162341633416434165341663416734168341693417034171341723417334174341753417634177341783417934180341813418234183341843418534186341873418834189341903419134192341933419434195341963419734198341993420034201342023420334204342053420634207342083420934210342113421234213342143421534216342173421834219342203422134222342233422434225342263422734228342293423034231342323423334234342353423634237342383423934240342413424234243342443424534246342473424834249342503425134252342533425434255342563425734258342593426034261342623426334264342653426634267342683426934270342713427234273342743427534276342773427834279342803428134282342833428434285342863428734288342893429034291342923429334294342953429634297342983429934300343013430234303343043430534306343073430834309343103431134312343133431434315343163431734318343193432034321343223432334324343253432634327343283432934330343313433234333343343433534336343373433834339343403434134342343433434434345343463434734348343493435034351343523435334354343553435634357343583435934360343613436234363343643436534366343673436834369343703437134372343733437434375343763437734378343793438034381343823438334384343853438634387343883438934390343913439234393343943439534396343973439834399344003440134402344033440434405344063440734408344093441034411344123441334414344153441634417344183441934420344213442234423344243442534426344273442834429344303443134432344333443434435344363443734438344393444034441344423444334444344453444634447344483444934450344513445234453344543445534456344573445834459344603446134462344633446434465344663446734468344693447034471344723447334474344753447634477344783447934480344813448234483344843448534486344873448834489344903449134492344933449434495344963449734498344993450034501345023450334504345053450634507345083450934510345113451234513345143451534516345173451834519345203452134522345233452434525345263452734528345293453034531345323453334534345353453634537345383453934540345413454234543345443454534546345473454834549345503455134552345533455434555345563455734558345593456034561345623456334564345653456634567345683456934570345713457234573345743457534576345773457834579345803458134582345833458434585345863458734588345893459034591345923459334594345953459634597345983459934600346013460234603346043460534606346073460834609346103461134612346133461434615346163461734618346193462034621346223462334624346253462634627346283462934630346313463234633346343463534636346373463834639346403464134642346433464434645346463464734648346493465034651346523465334654346553465634657346583465934660346613466234663346643466534666346673466834669346703467134672346733467434675346763467734678346793468034681346823468334684346853468634687346883468934690346913469234693346943469534696346973469834699347003470134702347033470434705347063470734708347093471034711347123471334714347153471634717347183471934720347213472234723347243472534726347273472834729347303473134732347333473434735347363473734738347393474034741347423474334744347453474634747347483474934750347513475234753347543475534756347573475834759347603476134762347633476434765347663476734768347693477034771347723477334774347753477634777347783477934780347813478234783347843478534786347873478834789347903479134792347933479434795347963479734798347993480034801348023480334804348053480634807348083480934810348113481234813348143481534816348173481834819348203482134822348233482434825348263482734828348293483034831348323483334834348353483634837348383483934840348413484234843348443484534846348473484834849348503485134852348533485434855348563485734858348593486034861348623486334864348653486634867348683486934870348713487234873348743487534876348773487834879348803488134882348833488434885348863488734888348893489034891348923489334894348953489634897348983489934900349013490234903349043490534906349073490834909349103491134912349133491434915349163491734918349193492034921349223492334924349253492634927349283492934930349313493234933349343493534936349373493834939349403494134942349433494434945349463494734948349493495034951349523495334954349553495634957349583495934960349613496234963349643496534966349673496834969349703497134972349733497434975349763497734978349793498034981349823498334984349853498634987349883498934990349913499234993349943499534996349973499834999350003500135002350033500435005350063500735008350093501035011350123501335014350153501635017350183501935020350213502235023350243502535026350273502835029350303503135032350333503435035350363503735038350393504035041350423504335044350453504635047350483504935050350513505235053350543505535056350573505835059350603506135062350633506435065350663506735068350693507035071350723507335074350753507635077350783507935080350813508235083350843508535086350873508835089350903509135092350933509435095350963509735098350993510035101351023510335104351053510635107351083510935110351113511235113351143511535116351173511835119351203512135122351233512435125351263512735128351293513035131351323513335134351353513635137351383513935140351413514235143351443514535146351473514835149351503515135152351533515435155351563515735158351593516035161351623516335164351653516635167351683516935170351713517235173351743517535176351773517835179351803518135182351833518435185351863518735188351893519035191351923519335194351953519635197351983519935200352013520235203352043520535206352073520835209352103521135212352133521435215352163521735218352193522035221352223522335224352253522635227352283522935230352313523235233352343523535236352373523835239352403524135242352433524435245352463524735248352493525035251352523525335254352553525635257352583525935260352613526235263352643526535266352673526835269352703527135272352733527435275352763527735278352793528035281352823528335284352853528635287352883528935290352913529235293352943529535296352973529835299353003530135302353033530435305353063530735308353093531035311353123531335314353153531635317353183531935320353213532235323353243532535326353273532835329353303533135332353333533435335353363533735338353393534035341353423534335344353453534635347353483534935350353513535235353353543535535356353573535835359353603536135362353633536435365353663536735368353693537035371353723537335374353753537635377353783537935380353813538235383353843538535386353873538835389353903539135392353933539435395353963539735398353993540035401354023540335404354053540635407354083540935410354113541235413354143541535416354173541835419354203542135422354233542435425354263542735428354293543035431354323543335434354353543635437354383543935440354413544235443354443544535446354473544835449354503545135452354533545435455354563545735458354593546035461354623546335464354653546635467354683546935470354713547235473354743547535476354773547835479354803548135482354833548435485354863548735488354893549035491354923549335494354953549635497354983549935500355013550235503355043550535506355073550835509355103551135512355133551435515355163551735518355193552035521355223552335524355253552635527355283552935530355313553235533355343553535536355373553835539355403554135542355433554435545355463554735548355493555035551355523555335554355553555635557355583555935560355613556235563355643556535566355673556835569355703557135572355733557435575355763557735578355793558035581355823558335584355853558635587355883558935590355913559235593355943559535596355973559835599356003560135602356033560435605356063560735608356093561035611356123561335614356153561635617356183561935620356213562235623356243562535626356273562835629356303563135632356333563435635356363563735638356393564035641356423564335644356453564635647356483564935650356513565235653356543565535656356573565835659356603566135662356633566435665356663566735668356693567035671356723567335674356753567635677356783567935680356813568235683356843568535686356873568835689356903569135692356933569435695356963569735698356993570035701357023570335704357053570635707357083570935710357113571235713357143571535716357173571835719357203572135722357233572435725357263572735728357293573035731357323573335734357353573635737357383573935740357413574235743357443574535746357473574835749357503575135752357533575435755357563575735758357593576035761357623576335764357653576635767357683576935770357713577235773357743577535776357773577835779357803578135782357833578435785357863578735788357893579035791357923579335794357953579635797357983579935800358013580235803358043580535806358073580835809358103581135812358133581435815358163581735818358193582035821358223582335824358253582635827358283582935830358313583235833358343583535836358373583835839358403584135842358433584435845358463584735848358493585035851358523585335854358553585635857358583585935860358613586235863358643586535866358673586835869358703587135872358733587435875358763587735878358793588035881358823588335884358853588635887358883588935890358913589235893358943589535896358973589835899359003590135902359033590435905359063590735908359093591035911359123591335914359153591635917359183591935920359213592235923359243592535926359273592835929359303593135932359333593435935359363593735938359393594035941359423594335944359453594635947359483594935950359513595235953359543595535956359573595835959359603596135962359633596435965359663596735968359693597035971359723597335974359753597635977359783597935980359813598235983359843598535986359873598835989359903599135992359933599435995359963599735998359993600036001360023600336004360053600636007360083600936010360113601236013360143601536016360173601836019360203602136022360233602436025360263602736028360293603036031360323603336034360353603636037360383603936040360413604236043360443604536046360473604836049360503605136052360533605436055360563605736058360593606036061360623606336064360653606636067360683606936070360713607236073360743607536076360773607836079360803608136082360833608436085360863608736088360893609036091360923609336094360953609636097360983609936100361013610236103361043610536106361073610836109361103611136112361133611436115361163611736118361193612036121361223612336124361253612636127361283612936130361313613236133361343613536136361373613836139361403614136142361433614436145361463614736148361493615036151361523615336154361553615636157361583615936160361613616236163361643616536166361673616836169361703617136172361733617436175361763617736178361793618036181361823618336184361853618636187361883618936190361913619236193361943619536196361973619836199362003620136202362033620436205362063620736208362093621036211362123621336214362153621636217362183621936220362213622236223362243622536226362273622836229362303623136232362333623436235362363623736238362393624036241362423624336244362453624636247362483624936250362513625236253362543625536256362573625836259362603626136262362633626436265362663626736268362693627036271362723627336274362753627636277362783627936280362813628236283362843628536286362873628836289362903629136292362933629436295362963629736298362993630036301363023630336304363053630636307363083630936310363113631236313363143631536316363173631836319363203632136322363233632436325363263632736328363293633036331363323633336334363353633636337363383633936340363413634236343363443634536346363473634836349363503635136352363533635436355363563635736358363593636036361363623636336364363653636636367363683636936370363713637236373363743637536376363773637836379363803638136382363833638436385363863638736388363893639036391363923639336394363953639636397363983639936400364013640236403364043640536406364073640836409364103641136412364133641436415364163641736418364193642036421364223642336424364253642636427364283642936430364313643236433364343643536436364373643836439364403644136442364433644436445364463644736448364493645036451364523645336454364553645636457364583645936460364613646236463364643646536466364673646836469364703647136472364733647436475364763647736478364793648036481364823648336484364853648636487364883648936490364913649236493364943649536496364973649836499365003650136502365033650436505365063650736508365093651036511365123651336514365153651636517365183651936520365213652236523365243652536526365273652836529365303653136532365333653436535365363653736538365393654036541365423654336544365453654636547365483654936550365513655236553365543655536556365573655836559365603656136562365633656436565365663656736568365693657036571365723657336574365753657636577365783657936580365813658236583365843658536586365873658836589365903659136592365933659436595365963659736598365993660036601366023660336604366053660636607366083660936610366113661236613366143661536616366173661836619366203662136622366233662436625366263662736628366293663036631366323663336634366353663636637366383663936640366413664236643366443664536646366473664836649366503665136652366533665436655366563665736658366593666036661366623666336664366653666636667366683666936670366713667236673366743667536676366773667836679366803668136682366833668436685366863668736688366893669036691366923669336694366953669636697366983669936700367013670236703367043670536706367073670836709367103671136712367133671436715367163671736718367193672036721367223672336724367253672636727367283672936730367313673236733367343673536736367373673836739367403674136742367433674436745367463674736748367493675036751367523675336754367553675636757367583675936760367613676236763367643676536766367673676836769367703677136772367733677436775367763677736778367793678036781367823678336784367853678636787367883678936790367913679236793367943679536796367973679836799368003680136802368033680436805368063680736808368093681036811368123681336814368153681636817368183681936820368213682236823368243682536826368273682836829368303683136832368333683436835368363683736838368393684036841368423684336844368453684636847368483684936850368513685236853368543685536856368573685836859368603686136862368633686436865368663686736868368693687036871368723687336874368753687636877368783687936880368813688236883368843688536886368873688836889368903689136892368933689436895368963689736898368993690036901369023690336904369053690636907369083690936910369113691236913369143691536916369173691836919369203692136922369233692436925369263692736928369293693036931369323693336934369353693636937369383693936940369413694236943369443694536946369473694836949369503695136952369533695436955369563695736958369593696036961369623696336964369653696636967369683696936970369713697236973369743697536976369773697836979369803698136982369833698436985369863698736988369893699036991369923699336994369953699636997369983699937000370013700237003370043700537006370073700837009370103701137012370133701437015370163701737018370193702037021370223702337024370253702637027370283702937030370313703237033370343703537036370373703837039370403704137042370433704437045370463704737048370493705037051370523705337054370553705637057370583705937060370613706237063370643706537066370673706837069370703707137072370733707437075370763707737078370793708037081370823708337084370853708637087370883708937090370913709237093370943709537096370973709837099371003710137102371033710437105371063710737108371093711037111371123711337114371153711637117371183711937120371213712237123371243712537126371273712837129371303713137132371333713437135371363713737138371393714037141371423714337144371453714637147371483714937150371513715237153371543715537156371573715837159371603716137162371633716437165371663716737168371693717037171371723717337174371753717637177371783717937180371813718237183371843718537186371873718837189371903719137192371933719437195371963719737198371993720037201372023720337204372053720637207372083720937210372113721237213372143721537216372173721837219372203722137222372233722437225372263722737228372293723037231372323723337234372353723637237372383723937240372413724237243372443724537246372473724837249372503725137252372533725437255372563725737258372593726037261372623726337264372653726637267372683726937270372713727237273372743727537276372773727837279372803728137282372833728437285372863728737288372893729037291372923729337294372953729637297372983729937300373013730237303373043730537306373073730837309373103731137312373133731437315373163731737318373193732037321373223732337324373253732637327373283732937330373313733237333373343733537336373373733837339373403734137342373433734437345373463734737348373493735037351373523735337354373553735637357373583735937360373613736237363373643736537366373673736837369373703737137372373733737437375373763737737378373793738037381373823738337384373853738637387373883738937390373913739237393373943739537396373973739837399374003740137402374033740437405374063740737408374093741037411374123741337414374153741637417374183741937420374213742237423374243742537426374273742837429374303743137432374333743437435374363743737438374393744037441374423744337444374453744637447374483744937450374513745237453374543745537456374573745837459374603746137462374633746437465374663746737468374693747037471374723747337474374753747637477374783747937480374813748237483374843748537486374873748837489374903749137492374933749437495374963749737498374993750037501375023750337504375053750637507375083750937510375113751237513375143751537516375173751837519375203752137522375233752437525375263752737528375293753037531375323753337534375353753637537375383753937540375413754237543375443754537546375473754837549375503755137552375533755437555375563755737558375593756037561375623756337564375653756637567375683756937570375713757237573375743757537576375773757837579375803758137582375833758437585375863758737588375893759037591375923759337594375953759637597375983759937600376013760237603376043760537606376073760837609376103761137612376133761437615376163761737618376193762037621376223762337624376253762637627376283762937630376313763237633376343763537636376373763837639376403764137642376433764437645376463764737648376493765037651376523765337654376553765637657376583765937660376613766237663376643766537666376673766837669376703767137672376733767437675376763767737678376793768037681376823768337684376853768637687376883768937690376913769237693376943769537696376973769837699377003770137702377033770437705377063770737708377093771037711377123771337714377153771637717377183771937720377213772237723377243772537726377273772837729377303773137732377333773437735377363773737738377393774037741377423774337744377453774637747377483774937750377513775237753377543775537756377573775837759377603776137762377633776437765377663776737768377693777037771377723777337774377753777637777377783777937780377813778237783377843778537786377873778837789377903779137792377933779437795377963779737798377993780037801378023780337804378053780637807378083780937810378113781237813378143781537816378173781837819378203782137822378233782437825378263782737828378293783037831378323783337834378353783637837378383783937840378413784237843378443784537846378473784837849378503785137852378533785437855378563785737858378593786037861378623786337864378653786637867378683786937870378713787237873378743787537876378773787837879378803788137882378833788437885378863788737888378893789037891378923789337894378953789637897378983789937900379013790237903379043790537906379073790837909379103791137912379133791437915379163791737918379193792037921379223792337924379253792637927379283792937930379313793237933379343793537936379373793837939379403794137942379433794437945379463794737948379493795037951379523795337954379553795637957379583795937960379613796237963379643796537966379673796837969379703797137972379733797437975379763797737978379793798037981379823798337984379853798637987379883798937990379913799237993379943799537996379973799837999380003800138002380033800438005380063800738008380093801038011380123801338014380153801638017380183801938020380213802238023380243802538026380273802838029380303803138032380333803438035380363803738038380393804038041380423804338044380453804638047380483804938050380513805238053380543805538056380573805838059380603806138062380633806438065380663806738068380693807038071380723807338074380753807638077380783807938080380813808238083380843808538086380873808838089380903809138092380933809438095380963809738098380993810038101381023810338104381053810638107381083810938110381113811238113381143811538116381173811838119381203812138122381233812438125381263812738128381293813038131381323813338134381353813638137381383813938140381413814238143381443814538146381473814838149381503815138152381533815438155381563815738158381593816038161381623816338164381653816638167381683816938170381713817238173381743817538176381773817838179381803818138182381833818438185381863818738188381893819038191381923819338194381953819638197381983819938200382013820238203382043820538206382073820838209382103821138212382133821438215382163821738218382193822038221382223822338224382253822638227382283822938230382313823238233382343823538236382373823838239382403824138242382433824438245382463824738248382493825038251382523825338254382553825638257382583825938260382613826238263382643826538266382673826838269382703827138272382733827438275382763827738278382793828038281382823828338284382853828638287382883828938290382913829238293382943829538296382973829838299383003830138302383033830438305383063830738308383093831038311383123831338314383153831638317383183831938320383213832238323383243832538326383273832838329383303833138332383333833438335383363833738338383393834038341383423834338344383453834638347383483834938350383513835238353383543835538356383573835838359383603836138362383633836438365383663836738368383693837038371383723837338374383753837638377383783837938380383813838238383383843838538386383873838838389383903839138392383933839438395383963839738398383993840038401384023840338404384053840638407384083840938410384113841238413384143841538416384173841838419384203842138422384233842438425384263842738428384293843038431384323843338434384353843638437384383843938440384413844238443384443844538446384473844838449384503845138452384533845438455384563845738458384593846038461384623846338464384653846638467384683846938470384713847238473384743847538476384773847838479384803848138482384833848438485384863848738488384893849038491384923849338494384953849638497384983849938500385013850238503385043850538506385073850838509385103851138512385133851438515385163851738518385193852038521385223852338524385253852638527385283852938530385313853238533385343853538536385373853838539385403854138542385433854438545385463854738548385493855038551385523855338554385553855638557385583855938560385613856238563385643856538566385673856838569385703857138572385733857438575385763857738578385793858038581385823858338584385853858638587385883858938590385913859238593385943859538596385973859838599386003860138602386033860438605386063860738608386093861038611386123861338614386153861638617386183861938620386213862238623386243862538626386273862838629386303863138632386333863438635386363863738638386393864038641386423864338644386453864638647386483864938650386513865238653386543865538656386573865838659386603866138662386633866438665386663866738668386693867038671386723867338674386753867638677386783867938680386813868238683386843868538686386873868838689386903869138692386933869438695386963869738698386993870038701387023870338704387053870638707387083870938710387113871238713387143871538716387173871838719387203872138722387233872438725387263872738728387293873038731387323873338734387353873638737387383873938740387413874238743387443874538746387473874838749387503875138752387533875438755387563875738758387593876038761387623876338764387653876638767387683876938770387713877238773387743877538776387773877838779387803878138782387833878438785387863878738788387893879038791387923879338794387953879638797387983879938800388013880238803388043880538806388073880838809388103881138812388133881438815388163881738818388193882038821388223882338824388253882638827388283882938830388313883238833388343883538836388373883838839388403884138842388433884438845388463884738848388493885038851388523885338854388553885638857388583885938860388613886238863388643886538866388673886838869388703887138872388733887438875388763887738878388793888038881388823888338884388853888638887388883888938890388913889238893388943889538896388973889838899389003890138902389033890438905389063890738908389093891038911389123891338914389153891638917389183891938920389213892238923389243892538926389273892838929389303893138932389333893438935389363893738938389393894038941389423894338944389453894638947389483894938950389513895238953389543895538956389573895838959389603896138962389633896438965389663896738968389693897038971389723897338974389753897638977389783897938980389813898238983389843898538986389873898838989389903899138992389933899438995389963899738998389993900039001390023900339004390053900639007390083900939010390113901239013390143901539016390173901839019390203902139022390233902439025390263902739028390293903039031390323903339034390353903639037390383903939040390413904239043390443904539046390473904839049390503905139052390533905439055390563905739058390593906039061390623906339064390653906639067390683906939070390713907239073390743907539076390773907839079390803908139082390833908439085390863908739088390893909039091390923909339094390953909639097390983909939100391013910239103391043910539106391073910839109391103911139112391133911439115391163911739118391193912039121391223912339124391253912639127391283912939130391313913239133391343913539136391373913839139391403914139142391433914439145391463914739148391493915039151391523915339154391553915639157391583915939160391613916239163391643916539166391673916839169391703917139172391733917439175391763917739178391793918039181391823918339184391853918639187391883918939190391913919239193391943919539196391973919839199392003920139202392033920439205392063920739208392093921039211392123921339214392153921639217392183921939220392213922239223392243922539226392273922839229392303923139232392333923439235392363923739238392393924039241392423924339244392453924639247392483924939250392513925239253392543925539256392573925839259392603926139262392633926439265392663926739268392693927039271392723927339274392753927639277392783927939280392813928239283
  1. // File:src/Three.js
  2. /**
  3. * @author mrdoob / http://mrdoob.com/
  4. */
  5. var THREE = { REVISION: '74dev' };
  6. //
  7. if ( typeof define === 'function' && define.amd ) {
  8. define( 'three', THREE );
  9. } else if ( 'undefined' !== typeof exports && 'undefined' !== typeof module ) {
  10. module.exports = THREE;
  11. }
  12. // polyfills
  13. if ( self.requestAnimationFrame === undefined || self.cancelAnimationFrame === undefined ) {
  14. // Missing in Android stock browser.
  15. ( function () {
  16. var lastTime = 0;
  17. var vendors = [ 'ms', 'moz', 'webkit', 'o' ];
  18. for ( var x = 0; x < vendors.length && ! self.requestAnimationFrame; ++ x ) {
  19. self.requestAnimationFrame = self[ vendors[ x ] + 'RequestAnimationFrame' ];
  20. self.cancelAnimationFrame = self[ vendors[ x ] + 'CancelAnimationFrame' ] || self[ vendors[ x ] + 'CancelRequestAnimationFrame' ];
  21. }
  22. if ( self.requestAnimationFrame === undefined && self.setTimeout !== undefined ) {
  23. self.requestAnimationFrame = function ( callback ) {
  24. var currTime = Date.now(), timeToCall = Math.max( 0, 16 - ( currTime - lastTime ) );
  25. var id = self.setTimeout( function () {
  26. callback( currTime + timeToCall );
  27. }, timeToCall );
  28. lastTime = currTime + timeToCall;
  29. return id;
  30. };
  31. }
  32. if ( self.cancelAnimationFrame === undefined && self.clearTimeout !== undefined ) {
  33. self.cancelAnimationFrame = function ( id ) {
  34. self.clearTimeout( id );
  35. };
  36. }
  37. } )();
  38. }
  39. //
  40. if ( self.performance === undefined ) {
  41. self.performance = {};
  42. }
  43. if ( self.performance.now === undefined ) {
  44. ( function () {
  45. var start = Date.now();
  46. self.performance.now = function () {
  47. return Date.now() - start;
  48. }
  49. } )();
  50. }
  51. //
  52. if ( Number.EPSILON === undefined ) {
  53. Number.EPSILON = Math.pow( 2, -52 );
  54. }
  55. //
  56. if ( Math.sign === undefined ) {
  57. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
  58. Math.sign = function ( x ) {
  59. return ( x < 0 ) ? - 1 : ( x > 0 ) ? 1 : + x;
  60. };
  61. }
  62. if ( Function.prototype.name === undefined && Object.defineProperty !== undefined ) {
  63. // Missing in IE9-11.
  64. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
  65. Object.defineProperty( Function.prototype, 'name', {
  66. get: function () {
  67. return this.toString().match( /^\s*function\s*(\S*)\s*\(/ )[ 1 ];
  68. }
  69. } );
  70. }
  71. if ( Object.assign === undefined ) {
  72. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
  73. Object.defineProperty( Object, 'assign', {
  74. writable: true,
  75. configurable: true,
  76. value: function(target) {
  77. 'use strict';
  78. if ( target === undefined || target === null ) {
  79. throw new TypeError( "Cannot convert first argument to object" );
  80. }
  81. var to = Object( target );
  82. for ( var i = 1, n = arguments.length; i !== n; ++ i ) {
  83. var nextSource = arguments[ i ];
  84. if ( nextSource === undefined || nextSource === null ) continue;
  85. nextSource = Object( nextSource );
  86. var keysArray = Object.keys( nextSource );
  87. for ( var nextIndex = 0, len = keysArray.length; nextIndex !== len; ++ nextIndex ) {
  88. var nextKey = keysArray[ nextIndex ];
  89. var desc = Object.getOwnPropertyDescriptor( nextSource, nextKey );
  90. if ( desc !== undefined && desc.enumerable ) {
  91. to[ nextKey ] = nextSource[ nextKey ];
  92. }
  93. }
  94. }
  95. return to;
  96. }
  97. } );
  98. }
  99. // https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent.button
  100. THREE.MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2 };
  101. // GL STATE CONSTANTS
  102. THREE.CullFaceNone = 0;
  103. THREE.CullFaceBack = 1;
  104. THREE.CullFaceFront = 2;
  105. THREE.CullFaceFrontBack = 3;
  106. THREE.FrontFaceDirectionCW = 0;
  107. THREE.FrontFaceDirectionCCW = 1;
  108. // SHADOWING TYPES
  109. THREE.BasicShadowMap = 0;
  110. THREE.PCFShadowMap = 1;
  111. THREE.PCFSoftShadowMap = 2;
  112. // MATERIAL CONSTANTS
  113. // side
  114. THREE.FrontSide = 0;
  115. THREE.BackSide = 1;
  116. THREE.DoubleSide = 2;
  117. // shading
  118. THREE.FlatShading = 1;
  119. THREE.SmoothShading = 2;
  120. // colors
  121. THREE.NoColors = 0;
  122. THREE.FaceColors = 1;
  123. THREE.VertexColors = 2;
  124. // blending modes
  125. THREE.NoBlending = 0;
  126. THREE.NormalBlending = 1;
  127. THREE.AdditiveBlending = 2;
  128. THREE.SubtractiveBlending = 3;
  129. THREE.MultiplyBlending = 4;
  130. THREE.CustomBlending = 5;
  131. // custom blending equations
  132. // (numbers start from 100 not to clash with other
  133. // mappings to OpenGL constants defined in Texture.js)
  134. THREE.AddEquation = 100;
  135. THREE.SubtractEquation = 101;
  136. THREE.ReverseSubtractEquation = 102;
  137. THREE.MinEquation = 103;
  138. THREE.MaxEquation = 104;
  139. // custom blending destination factors
  140. THREE.ZeroFactor = 200;
  141. THREE.OneFactor = 201;
  142. THREE.SrcColorFactor = 202;
  143. THREE.OneMinusSrcColorFactor = 203;
  144. THREE.SrcAlphaFactor = 204;
  145. THREE.OneMinusSrcAlphaFactor = 205;
  146. THREE.DstAlphaFactor = 206;
  147. THREE.OneMinusDstAlphaFactor = 207;
  148. // custom blending source factors
  149. //THREE.ZeroFactor = 200;
  150. //THREE.OneFactor = 201;
  151. //THREE.SrcAlphaFactor = 204;
  152. //THREE.OneMinusSrcAlphaFactor = 205;
  153. //THREE.DstAlphaFactor = 206;
  154. //THREE.OneMinusDstAlphaFactor = 207;
  155. THREE.DstColorFactor = 208;
  156. THREE.OneMinusDstColorFactor = 209;
  157. THREE.SrcAlphaSaturateFactor = 210;
  158. // depth modes
  159. THREE.NeverDepth = 0;
  160. THREE.AlwaysDepth = 1;
  161. THREE.LessDepth = 2;
  162. THREE.LessEqualDepth = 3;
  163. THREE.EqualDepth = 4;
  164. THREE.GreaterEqualDepth = 5;
  165. THREE.GreaterDepth = 6;
  166. THREE.NotEqualDepth = 7;
  167. // TEXTURE CONSTANTS
  168. THREE.MultiplyOperation = 0;
  169. THREE.MixOperation = 1;
  170. THREE.AddOperation = 2;
  171. // Mapping modes
  172. THREE.UVMapping = 300;
  173. THREE.CubeReflectionMapping = 301;
  174. THREE.CubeRefractionMapping = 302;
  175. THREE.EquirectangularReflectionMapping = 303;
  176. THREE.EquirectangularRefractionMapping = 304;
  177. THREE.SphericalReflectionMapping = 305;
  178. // Wrapping modes
  179. THREE.RepeatWrapping = 1000;
  180. THREE.ClampToEdgeWrapping = 1001;
  181. THREE.MirroredRepeatWrapping = 1002;
  182. // Filters
  183. THREE.NearestFilter = 1003;
  184. THREE.NearestMipMapNearestFilter = 1004;
  185. THREE.NearestMipMapLinearFilter = 1005;
  186. THREE.LinearFilter = 1006;
  187. THREE.LinearMipMapNearestFilter = 1007;
  188. THREE.LinearMipMapLinearFilter = 1008;
  189. // Data types
  190. THREE.UnsignedByteType = 1009;
  191. THREE.ByteType = 1010;
  192. THREE.ShortType = 1011;
  193. THREE.UnsignedShortType = 1012;
  194. THREE.IntType = 1013;
  195. THREE.UnsignedIntType = 1014;
  196. THREE.FloatType = 1015;
  197. THREE.HalfFloatType = 1025;
  198. // Pixel types
  199. //THREE.UnsignedByteType = 1009;
  200. THREE.UnsignedShort4444Type = 1016;
  201. THREE.UnsignedShort5551Type = 1017;
  202. THREE.UnsignedShort565Type = 1018;
  203. // Pixel formats
  204. THREE.AlphaFormat = 1019;
  205. THREE.RGBFormat = 1020;
  206. THREE.RGBAFormat = 1021;
  207. THREE.LuminanceFormat = 1022;
  208. THREE.LuminanceAlphaFormat = 1023;
  209. // THREE.RGBEFormat handled as THREE.RGBAFormat in shaders
  210. THREE.RGBEFormat = THREE.RGBAFormat; //1024;
  211. // DDS / ST3C Compressed texture formats
  212. THREE.RGB_S3TC_DXT1_Format = 2001;
  213. THREE.RGBA_S3TC_DXT1_Format = 2002;
  214. THREE.RGBA_S3TC_DXT3_Format = 2003;
  215. THREE.RGBA_S3TC_DXT5_Format = 2004;
  216. // PVRTC compressed texture formats
  217. THREE.RGB_PVRTC_4BPPV1_Format = 2100;
  218. THREE.RGB_PVRTC_2BPPV1_Format = 2101;
  219. THREE.RGBA_PVRTC_4BPPV1_Format = 2102;
  220. THREE.RGBA_PVRTC_2BPPV1_Format = 2103;
  221. // Loop styles for AnimationAction
  222. THREE.LoopOnce = 2200;
  223. THREE.LoopRepeat = 2201;
  224. THREE.LoopPingPong = 2202;
  225. // Interpolation
  226. THREE.InterpolateDiscrete = 2300;
  227. THREE.InterpolateLinear = 2301;
  228. THREE.InterpolateSmooth = 2302;
  229. // Interpolant ending modes
  230. THREE.ZeroCurvatureEnding = 2400;
  231. THREE.ZeroSlopeEnding = 2401;
  232. THREE.WrapAroundEnding = 2402;
  233. // File:src/math/Color.js
  234. /**
  235. * @author mrdoob / http://mrdoob.com/
  236. */
  237. THREE.Color = function ( color ) {
  238. if ( arguments.length === 3 ) {
  239. return this.fromArray( arguments );
  240. }
  241. return this.set( color );
  242. };
  243. THREE.Color.prototype = {
  244. constructor: THREE.Color,
  245. r: 1, g: 1, b: 1,
  246. set: function ( value ) {
  247. if ( value instanceof THREE.Color ) {
  248. this.copy( value );
  249. } else if ( typeof value === 'number' ) {
  250. this.setHex( value );
  251. } else if ( typeof value === 'string' ) {
  252. this.setStyle( value );
  253. }
  254. return this;
  255. },
  256. setHex: function ( hex ) {
  257. hex = Math.floor( hex );
  258. this.r = ( hex >> 16 & 255 ) / 255;
  259. this.g = ( hex >> 8 & 255 ) / 255;
  260. this.b = ( hex & 255 ) / 255;
  261. return this;
  262. },
  263. setRGB: function ( r, g, b ) {
  264. this.r = r;
  265. this.g = g;
  266. this.b = b;
  267. return this;
  268. },
  269. setHSL: function () {
  270. function hue2rgb( p, q, t ) {
  271. if ( t < 0 ) t += 1;
  272. if ( t > 1 ) t -= 1;
  273. if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
  274. if ( t < 1 / 2 ) return q;
  275. if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
  276. return p;
  277. }
  278. return function ( h, s, l ) {
  279. // h,s,l ranges are in 0.0 - 1.0
  280. h = THREE.Math.euclideanModulo( h, 1 );
  281. s = THREE.Math.clamp( s, 0, 1 );
  282. l = THREE.Math.clamp( l, 0, 1 );
  283. if ( s === 0 ) {
  284. this.r = this.g = this.b = l;
  285. } else {
  286. var p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  287. var q = ( 2 * l ) - p;
  288. this.r = hue2rgb( q, p, h + 1 / 3 );
  289. this.g = hue2rgb( q, p, h );
  290. this.b = hue2rgb( q, p, h - 1 / 3 );
  291. }
  292. return this;
  293. };
  294. }(),
  295. setStyle: function ( style ) {
  296. function handleAlpha( string ) {
  297. if ( string === undefined ) return;
  298. if ( parseFloat( string ) < 1 ) {
  299. console.warn( 'THREE.Color: Alpha component of ' + style + ' will be ignored.' );
  300. }
  301. }
  302. var m;
  303. if ( m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec( style ) ) {
  304. // rgb / hsl
  305. var color;
  306. var name = m[ 1 ];
  307. var components = m[ 2 ];
  308. switch ( name ) {
  309. case 'rgb':
  310. case 'rgba':
  311. if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  312. // rgb(255,0,0) rgba(255,0,0,0.5)
  313. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  314. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  315. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  316. handleAlpha( color[ 5 ] );
  317. return this;
  318. }
  319. if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  320. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  321. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  322. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  323. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  324. handleAlpha( color[ 5 ] );
  325. return this;
  326. }
  327. break;
  328. case 'hsl':
  329. case 'hsla':
  330. if ( color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  331. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  332. var h = parseFloat( color[ 1 ] ) / 360;
  333. var s = parseInt( color[ 2 ], 10 ) / 100;
  334. var l = parseInt( color[ 3 ], 10 ) / 100;
  335. handleAlpha( color[ 5 ] );
  336. return this.setHSL( h, s, l );
  337. }
  338. break;
  339. }
  340. } else if ( m = /^\#([A-Fa-f0-9]+)$/.exec( style ) ) {
  341. // hex color
  342. var hex = m[ 1 ];
  343. var size = hex.length;
  344. if ( size === 3 ) {
  345. // #ff0
  346. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 0 ), 16 ) / 255;
  347. this.g = parseInt( hex.charAt( 1 ) + hex.charAt( 1 ), 16 ) / 255;
  348. this.b = parseInt( hex.charAt( 2 ) + hex.charAt( 2 ), 16 ) / 255;
  349. return this;
  350. } else if ( size === 6 ) {
  351. // #ff0000
  352. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 1 ), 16 ) / 255;
  353. this.g = parseInt( hex.charAt( 2 ) + hex.charAt( 3 ), 16 ) / 255;
  354. this.b = parseInt( hex.charAt( 4 ) + hex.charAt( 5 ), 16 ) / 255;
  355. return this;
  356. }
  357. }
  358. if ( style && style.length > 0 ) {
  359. // color keywords
  360. var hex = THREE.ColorKeywords[ style ];
  361. if ( hex !== undefined ) {
  362. // red
  363. this.setHex( hex );
  364. } else {
  365. // unknown color
  366. console.warn( 'THREE.Color: Unknown color ' + style );
  367. }
  368. }
  369. return this;
  370. },
  371. clone: function () {
  372. return new this.constructor( this.r, this.g, this.b );
  373. },
  374. copy: function ( color ) {
  375. this.r = color.r;
  376. this.g = color.g;
  377. this.b = color.b;
  378. return this;
  379. },
  380. copyGammaToLinear: function ( color, gammaFactor ) {
  381. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  382. this.r = Math.pow( color.r, gammaFactor );
  383. this.g = Math.pow( color.g, gammaFactor );
  384. this.b = Math.pow( color.b, gammaFactor );
  385. return this;
  386. },
  387. copyLinearToGamma: function ( color, gammaFactor ) {
  388. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  389. var safeInverse = ( gammaFactor > 0 ) ? ( 1.0 / gammaFactor ) : 1.0;
  390. this.r = Math.pow( color.r, safeInverse );
  391. this.g = Math.pow( color.g, safeInverse );
  392. this.b = Math.pow( color.b, safeInverse );
  393. return this;
  394. },
  395. convertGammaToLinear: function () {
  396. var r = this.r, g = this.g, b = this.b;
  397. this.r = r * r;
  398. this.g = g * g;
  399. this.b = b * b;
  400. return this;
  401. },
  402. convertLinearToGamma: function () {
  403. this.r = Math.sqrt( this.r );
  404. this.g = Math.sqrt( this.g );
  405. this.b = Math.sqrt( this.b );
  406. return this;
  407. },
  408. getHex: function () {
  409. return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
  410. },
  411. getHexString: function () {
  412. return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
  413. },
  414. getHSL: function ( optionalTarget ) {
  415. // h,s,l ranges are in 0.0 - 1.0
  416. var hsl = optionalTarget || { h: 0, s: 0, l: 0 };
  417. var r = this.r, g = this.g, b = this.b;
  418. var max = Math.max( r, g, b );
  419. var min = Math.min( r, g, b );
  420. var hue, saturation;
  421. var lightness = ( min + max ) / 2.0;
  422. if ( min === max ) {
  423. hue = 0;
  424. saturation = 0;
  425. } else {
  426. var delta = max - min;
  427. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  428. switch ( max ) {
  429. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  430. case g: hue = ( b - r ) / delta + 2; break;
  431. case b: hue = ( r - g ) / delta + 4; break;
  432. }
  433. hue /= 6;
  434. }
  435. hsl.h = hue;
  436. hsl.s = saturation;
  437. hsl.l = lightness;
  438. return hsl;
  439. },
  440. getStyle: function () {
  441. return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
  442. },
  443. offsetHSL: function ( h, s, l ) {
  444. var hsl = this.getHSL();
  445. hsl.h += h; hsl.s += s; hsl.l += l;
  446. this.setHSL( hsl.h, hsl.s, hsl.l );
  447. return this;
  448. },
  449. add: function ( color ) {
  450. this.r += color.r;
  451. this.g += color.g;
  452. this.b += color.b;
  453. return this;
  454. },
  455. addColors: function ( color1, color2 ) {
  456. this.r = color1.r + color2.r;
  457. this.g = color1.g + color2.g;
  458. this.b = color1.b + color2.b;
  459. return this;
  460. },
  461. addScalar: function ( s ) {
  462. this.r += s;
  463. this.g += s;
  464. this.b += s;
  465. return this;
  466. },
  467. multiply: function ( color ) {
  468. this.r *= color.r;
  469. this.g *= color.g;
  470. this.b *= color.b;
  471. return this;
  472. },
  473. multiplyScalar: function ( s ) {
  474. this.r *= s;
  475. this.g *= s;
  476. this.b *= s;
  477. return this;
  478. },
  479. lerp: function ( color, alpha ) {
  480. this.r += ( color.r - this.r ) * alpha;
  481. this.g += ( color.g - this.g ) * alpha;
  482. this.b += ( color.b - this.b ) * alpha;
  483. return this;
  484. },
  485. equals: function ( c ) {
  486. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  487. },
  488. fromArray: function ( array, offset ) {
  489. if ( offset === undefined ) offset = 0;
  490. this.r = array[ offset ];
  491. this.g = array[ offset + 1 ];
  492. this.b = array[ offset + 2 ];
  493. return this;
  494. },
  495. toArray: function ( array, offset ) {
  496. if ( array === undefined ) array = [];
  497. if ( offset === undefined ) offset = 0;
  498. array[ offset ] = this.r;
  499. array[ offset + 1 ] = this.g;
  500. array[ offset + 2 ] = this.b;
  501. return array;
  502. }
  503. };
  504. THREE.ColorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  505. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  506. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  507. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  508. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  509. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  510. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  511. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  512. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  513. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  514. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  515. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  516. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  517. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  518. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  519. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  520. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  521. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  522. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  523. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  524. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  525. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  526. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  527. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  528. // File:src/math/Quaternion.js
  529. /**
  530. * @author mikael emtinger / http://gomo.se/
  531. * @author alteredq / http://alteredqualia.com/
  532. * @author WestLangley / http://github.com/WestLangley
  533. * @author bhouston / http://clara.io
  534. */
  535. THREE.Quaternion = function ( x, y, z, w ) {
  536. this._x = x || 0;
  537. this._y = y || 0;
  538. this._z = z || 0;
  539. this._w = ( w !== undefined ) ? w : 1;
  540. };
  541. THREE.Quaternion.prototype = {
  542. constructor: THREE.Quaternion,
  543. get x () {
  544. return this._x;
  545. },
  546. set x ( value ) {
  547. this._x = value;
  548. this.onChangeCallback();
  549. },
  550. get y () {
  551. return this._y;
  552. },
  553. set y ( value ) {
  554. this._y = value;
  555. this.onChangeCallback();
  556. },
  557. get z () {
  558. return this._z;
  559. },
  560. set z ( value ) {
  561. this._z = value;
  562. this.onChangeCallback();
  563. },
  564. get w () {
  565. return this._w;
  566. },
  567. set w ( value ) {
  568. this._w = value;
  569. this.onChangeCallback();
  570. },
  571. set: function ( x, y, z, w ) {
  572. this._x = x;
  573. this._y = y;
  574. this._z = z;
  575. this._w = w;
  576. this.onChangeCallback();
  577. return this;
  578. },
  579. clone: function () {
  580. return new this.constructor( this._x, this._y, this._z, this._w );
  581. },
  582. copy: function ( quaternion ) {
  583. this._x = quaternion.x;
  584. this._y = quaternion.y;
  585. this._z = quaternion.z;
  586. this._w = quaternion.w;
  587. this.onChangeCallback();
  588. return this;
  589. },
  590. setFromEuler: function ( euler, update ) {
  591. if ( euler instanceof THREE.Euler === false ) {
  592. throw new Error( 'THREE.Quaternion: .setFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  593. }
  594. // http://www.mathworks.com/matlabcentral/fileexchange/
  595. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  596. // content/SpinCalc.m
  597. var c1 = Math.cos( euler._x / 2 );
  598. var c2 = Math.cos( euler._y / 2 );
  599. var c3 = Math.cos( euler._z / 2 );
  600. var s1 = Math.sin( euler._x / 2 );
  601. var s2 = Math.sin( euler._y / 2 );
  602. var s3 = Math.sin( euler._z / 2 );
  603. var order = euler.order;
  604. if ( order === 'XYZ' ) {
  605. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  606. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  607. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  608. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  609. } else if ( order === 'YXZ' ) {
  610. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  611. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  612. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  613. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  614. } else if ( order === 'ZXY' ) {
  615. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  616. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  617. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  618. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  619. } else if ( order === 'ZYX' ) {
  620. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  621. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  622. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  623. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  624. } else if ( order === 'YZX' ) {
  625. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  626. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  627. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  628. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  629. } else if ( order === 'XZY' ) {
  630. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  631. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  632. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  633. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  634. }
  635. if ( update !== false ) this.onChangeCallback();
  636. return this;
  637. },
  638. setFromAxisAngle: function ( axis, angle ) {
  639. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  640. // assumes axis is normalized
  641. var halfAngle = angle / 2, s = Math.sin( halfAngle );
  642. this._x = axis.x * s;
  643. this._y = axis.y * s;
  644. this._z = axis.z * s;
  645. this._w = Math.cos( halfAngle );
  646. this.onChangeCallback();
  647. return this;
  648. },
  649. setFromRotationMatrix: function ( m ) {
  650. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  651. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  652. var te = m.elements,
  653. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  654. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  655. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ],
  656. trace = m11 + m22 + m33,
  657. s;
  658. if ( trace > 0 ) {
  659. s = 0.5 / Math.sqrt( trace + 1.0 );
  660. this._w = 0.25 / s;
  661. this._x = ( m32 - m23 ) * s;
  662. this._y = ( m13 - m31 ) * s;
  663. this._z = ( m21 - m12 ) * s;
  664. } else if ( m11 > m22 && m11 > m33 ) {
  665. s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );
  666. this._w = ( m32 - m23 ) / s;
  667. this._x = 0.25 * s;
  668. this._y = ( m12 + m21 ) / s;
  669. this._z = ( m13 + m31 ) / s;
  670. } else if ( m22 > m33 ) {
  671. s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );
  672. this._w = ( m13 - m31 ) / s;
  673. this._x = ( m12 + m21 ) / s;
  674. this._y = 0.25 * s;
  675. this._z = ( m23 + m32 ) / s;
  676. } else {
  677. s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );
  678. this._w = ( m21 - m12 ) / s;
  679. this._x = ( m13 + m31 ) / s;
  680. this._y = ( m23 + m32 ) / s;
  681. this._z = 0.25 * s;
  682. }
  683. this.onChangeCallback();
  684. return this;
  685. },
  686. setFromUnitVectors: function () {
  687. // http://lolengine.net/blog/2014/02/24/quaternion-from-two-vectors-final
  688. // assumes direction vectors vFrom and vTo are normalized
  689. var v1, r;
  690. var EPS = 0.000001;
  691. return function ( vFrom, vTo ) {
  692. if ( v1 === undefined ) v1 = new THREE.Vector3();
  693. r = vFrom.dot( vTo ) + 1;
  694. if ( r < EPS ) {
  695. r = 0;
  696. if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) {
  697. v1.set( - vFrom.y, vFrom.x, 0 );
  698. } else {
  699. v1.set( 0, - vFrom.z, vFrom.y );
  700. }
  701. } else {
  702. v1.crossVectors( vFrom, vTo );
  703. }
  704. this._x = v1.x;
  705. this._y = v1.y;
  706. this._z = v1.z;
  707. this._w = r;
  708. this.normalize();
  709. return this;
  710. }
  711. }(),
  712. inverse: function () {
  713. this.conjugate().normalize();
  714. return this;
  715. },
  716. conjugate: function () {
  717. this._x *= - 1;
  718. this._y *= - 1;
  719. this._z *= - 1;
  720. this.onChangeCallback();
  721. return this;
  722. },
  723. dot: function ( v ) {
  724. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  725. },
  726. lengthSq: function () {
  727. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  728. },
  729. length: function () {
  730. return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );
  731. },
  732. normalize: function () {
  733. var l = this.length();
  734. if ( l === 0 ) {
  735. this._x = 0;
  736. this._y = 0;
  737. this._z = 0;
  738. this._w = 1;
  739. } else {
  740. l = 1 / l;
  741. this._x = this._x * l;
  742. this._y = this._y * l;
  743. this._z = this._z * l;
  744. this._w = this._w * l;
  745. }
  746. this.onChangeCallback();
  747. return this;
  748. },
  749. multiply: function ( q, p ) {
  750. if ( p !== undefined ) {
  751. console.warn( 'THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.' );
  752. return this.multiplyQuaternions( q, p );
  753. }
  754. return this.multiplyQuaternions( this, q );
  755. },
  756. multiplyQuaternions: function ( a, b ) {
  757. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  758. var qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
  759. var qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
  760. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  761. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  762. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  763. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  764. this.onChangeCallback();
  765. return this;
  766. },
  767. slerp: function ( qb, t ) {
  768. if ( t === 0 ) return this;
  769. if ( t === 1 ) return this.copy( qb );
  770. var x = this._x, y = this._y, z = this._z, w = this._w;
  771. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  772. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  773. if ( cosHalfTheta < 0 ) {
  774. this._w = - qb._w;
  775. this._x = - qb._x;
  776. this._y = - qb._y;
  777. this._z = - qb._z;
  778. cosHalfTheta = - cosHalfTheta;
  779. } else {
  780. this.copy( qb );
  781. }
  782. if ( cosHalfTheta >= 1.0 ) {
  783. this._w = w;
  784. this._x = x;
  785. this._y = y;
  786. this._z = z;
  787. return this;
  788. }
  789. var sinHalfTheta = Math.sqrt( 1.0 - cosHalfTheta * cosHalfTheta );
  790. if ( Math.abs( sinHalfTheta ) < 0.001 ) {
  791. this._w = 0.5 * ( w + this._w );
  792. this._x = 0.5 * ( x + this._x );
  793. this._y = 0.5 * ( y + this._y );
  794. this._z = 0.5 * ( z + this._z );
  795. return this;
  796. }
  797. var halfTheta = Math.atan2( sinHalfTheta, cosHalfTheta );
  798. var ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  799. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  800. this._w = ( w * ratioA + this._w * ratioB );
  801. this._x = ( x * ratioA + this._x * ratioB );
  802. this._y = ( y * ratioA + this._y * ratioB );
  803. this._z = ( z * ratioA + this._z * ratioB );
  804. this.onChangeCallback();
  805. return this;
  806. },
  807. equals: function ( quaternion ) {
  808. return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
  809. },
  810. fromArray: function ( array, offset ) {
  811. if ( offset === undefined ) offset = 0;
  812. this._x = array[ offset ];
  813. this._y = array[ offset + 1 ];
  814. this._z = array[ offset + 2 ];
  815. this._w = array[ offset + 3 ];
  816. this.onChangeCallback();
  817. return this;
  818. },
  819. toArray: function ( array, offset ) {
  820. if ( array === undefined ) array = [];
  821. if ( offset === undefined ) offset = 0;
  822. array[ offset ] = this._x;
  823. array[ offset + 1 ] = this._y;
  824. array[ offset + 2 ] = this._z;
  825. array[ offset + 3 ] = this._w;
  826. return array;
  827. },
  828. onChange: function ( callback ) {
  829. this.onChangeCallback = callback;
  830. return this;
  831. },
  832. onChangeCallback: function () {}
  833. };
  834. Object.assign( THREE.Quaternion, {
  835. slerp: function( qa, qb, qm, t ) {
  836. return qm.copy( qa ).slerp( qb, t );
  837. },
  838. slerpFlat: function(
  839. dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t ) {
  840. // fuzz-free, array-based Quaternion SLERP operation
  841. var x0 = src0[ srcOffset0 ],
  842. y0 = src0[ srcOffset0 + 1 ],
  843. z0 = src0[ srcOffset0 + 2 ],
  844. w0 = src0[ srcOffset0 + 3 ],
  845. x1 = src1[ srcOffset1 ],
  846. y1 = src1[ srcOffset1 + 1 ],
  847. z1 = src1[ srcOffset1 + 2 ],
  848. w1 = src1[ srcOffset1 + 3 ];
  849. if ( w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1 ) {
  850. var s = 1 - t,
  851. cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  852. dir = ( cos >= 0 ? 1 : -1 ),
  853. sqrSin = 1 - cos * cos;
  854. // Skip the Slerp for tiny steps to avoid numeric problems:
  855. if ( sqrSin > Number.EPSILON ) {
  856. var sin = Math.sqrt( sqrSin ),
  857. len = Math.atan2( sin, cos * dir );
  858. s = Math.sin( s * len ) / sin;
  859. t = Math.sin( t * len ) / sin;
  860. }
  861. var tDir = t * dir;
  862. x0 = x0 * s + x1 * tDir;
  863. y0 = y0 * s + y1 * tDir;
  864. z0 = z0 * s + z1 * tDir;
  865. w0 = w0 * s + w1 * tDir;
  866. // Normalize in case we just did a lerp:
  867. if ( s === 1 - t ) {
  868. var f = 1 / Math.sqrt( x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0 );
  869. x0 *= f;
  870. y0 *= f;
  871. z0 *= f;
  872. w0 *= f;
  873. }
  874. }
  875. dst[ dstOffset ] = x0;
  876. dst[ dstOffset + 1 ] = y0;
  877. dst[ dstOffset + 2 ] = z0;
  878. dst[ dstOffset + 3 ] = w0;
  879. }
  880. } );
  881. // File:src/math/Vector2.js
  882. /**
  883. * @author mrdoob / http://mrdoob.com/
  884. * @author philogb / http://blog.thejit.org/
  885. * @author egraether / http://egraether.com/
  886. * @author zz85 / http://www.lab4games.net/zz85/blog
  887. */
  888. THREE.Vector2 = function ( x, y ) {
  889. this.x = x || 0;
  890. this.y = y || 0;
  891. };
  892. THREE.Vector2.prototype = {
  893. constructor: THREE.Vector2,
  894. get width() { return this.x },
  895. set width( value ) { this.x = value },
  896. get height() { return this.y },
  897. set height( value ) { this.y = value },
  898. //
  899. set: function ( x, y ) {
  900. this.x = x;
  901. this.y = y;
  902. return this;
  903. },
  904. setX: function ( x ) {
  905. this.x = x;
  906. return this;
  907. },
  908. setY: function ( y ) {
  909. this.y = y;
  910. return this;
  911. },
  912. setComponent: function ( index, value ) {
  913. switch ( index ) {
  914. case 0: this.x = value; break;
  915. case 1: this.y = value; break;
  916. default: throw new Error( 'index is out of range: ' + index );
  917. }
  918. },
  919. getComponent: function ( index ) {
  920. switch ( index ) {
  921. case 0: return this.x;
  922. case 1: return this.y;
  923. default: throw new Error( 'index is out of range: ' + index );
  924. }
  925. },
  926. clone: function () {
  927. return new this.constructor( this.x, this.y );
  928. },
  929. copy: function ( v ) {
  930. this.x = v.x;
  931. this.y = v.y;
  932. return this;
  933. },
  934. add: function ( v, w ) {
  935. if ( w !== undefined ) {
  936. console.warn( 'THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  937. return this.addVectors( v, w );
  938. }
  939. this.x += v.x;
  940. this.y += v.y;
  941. return this;
  942. },
  943. addScalar: function ( s ) {
  944. this.x += s;
  945. this.y += s;
  946. return this;
  947. },
  948. addVectors: function ( a, b ) {
  949. this.x = a.x + b.x;
  950. this.y = a.y + b.y;
  951. return this;
  952. },
  953. addScaledVector: function ( v, s ) {
  954. this.x += v.x * s;
  955. this.y += v.y * s;
  956. return this;
  957. },
  958. sub: function ( v, w ) {
  959. if ( w !== undefined ) {
  960. console.warn( 'THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  961. return this.subVectors( v, w );
  962. }
  963. this.x -= v.x;
  964. this.y -= v.y;
  965. return this;
  966. },
  967. subScalar: function ( s ) {
  968. this.x -= s;
  969. this.y -= s;
  970. return this;
  971. },
  972. subVectors: function ( a, b ) {
  973. this.x = a.x - b.x;
  974. this.y = a.y - b.y;
  975. return this;
  976. },
  977. multiply: function ( v ) {
  978. this.x *= v.x;
  979. this.y *= v.y;
  980. return this;
  981. },
  982. multiplyScalar: function ( scalar ) {
  983. if ( isFinite( scalar ) ) {
  984. this.x *= scalar;
  985. this.y *= scalar;
  986. } else {
  987. this.x = 0;
  988. this.y = 0;
  989. }
  990. return this;
  991. },
  992. divide: function ( v ) {
  993. this.x /= v.x;
  994. this.y /= v.y;
  995. return this;
  996. },
  997. divideScalar: function ( scalar ) {
  998. return this.multiplyScalar( 1 / scalar );
  999. },
  1000. min: function ( v ) {
  1001. this.x = Math.min( this.x, v.x );
  1002. this.y = Math.min( this.y, v.y );
  1003. return this;
  1004. },
  1005. max: function ( v ) {
  1006. this.x = Math.max( this.x, v.x );
  1007. this.y = Math.max( this.y, v.y );
  1008. return this;
  1009. },
  1010. clamp: function ( min, max ) {
  1011. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1012. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1013. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1014. return this;
  1015. },
  1016. clampScalar: function () {
  1017. var min, max;
  1018. return function clampScalar( minVal, maxVal ) {
  1019. if ( min === undefined ) {
  1020. min = new THREE.Vector2();
  1021. max = new THREE.Vector2();
  1022. }
  1023. min.set( minVal, minVal );
  1024. max.set( maxVal, maxVal );
  1025. return this.clamp( min, max );
  1026. };
  1027. }(),
  1028. clampLength: function ( min, max ) {
  1029. var length = this.length();
  1030. this.multiplyScalar( Math.max( min, Math.min( max, length ) ) / length );
  1031. return this;
  1032. },
  1033. floor: function () {
  1034. this.x = Math.floor( this.x );
  1035. this.y = Math.floor( this.y );
  1036. return this;
  1037. },
  1038. ceil: function () {
  1039. this.x = Math.ceil( this.x );
  1040. this.y = Math.ceil( this.y );
  1041. return this;
  1042. },
  1043. round: function () {
  1044. this.x = Math.round( this.x );
  1045. this.y = Math.round( this.y );
  1046. return this;
  1047. },
  1048. roundToZero: function () {
  1049. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1050. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1051. return this;
  1052. },
  1053. negate: function () {
  1054. this.x = - this.x;
  1055. this.y = - this.y;
  1056. return this;
  1057. },
  1058. dot: function ( v ) {
  1059. return this.x * v.x + this.y * v.y;
  1060. },
  1061. lengthSq: function () {
  1062. return this.x * this.x + this.y * this.y;
  1063. },
  1064. length: function () {
  1065. return Math.sqrt( this.x * this.x + this.y * this.y );
  1066. },
  1067. lengthManhattan: function() {
  1068. return Math.abs( this.x ) + Math.abs( this.y );
  1069. },
  1070. normalize: function () {
  1071. return this.divideScalar( this.length() );
  1072. },
  1073. distanceTo: function ( v ) {
  1074. return Math.sqrt( this.distanceToSquared( v ) );
  1075. },
  1076. distanceToSquared: function ( v ) {
  1077. var dx = this.x - v.x, dy = this.y - v.y;
  1078. return dx * dx + dy * dy;
  1079. },
  1080. setLength: function ( length ) {
  1081. return this.multiplyScalar( length / this.length() );
  1082. },
  1083. lerp: function ( v, alpha ) {
  1084. this.x += ( v.x - this.x ) * alpha;
  1085. this.y += ( v.y - this.y ) * alpha;
  1086. return this;
  1087. },
  1088. lerpVectors: function ( v1, v2, alpha ) {
  1089. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1090. return this;
  1091. },
  1092. equals: function ( v ) {
  1093. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  1094. },
  1095. fromArray: function ( array, offset ) {
  1096. if ( offset === undefined ) offset = 0;
  1097. this.x = array[ offset ];
  1098. this.y = array[ offset + 1 ];
  1099. return this;
  1100. },
  1101. toArray: function ( array, offset ) {
  1102. if ( array === undefined ) array = [];
  1103. if ( offset === undefined ) offset = 0;
  1104. array[ offset ] = this.x;
  1105. array[ offset + 1 ] = this.y;
  1106. return array;
  1107. },
  1108. fromAttribute: function ( attribute, index, offset ) {
  1109. if ( offset === undefined ) offset = 0;
  1110. index = index * attribute.itemSize + offset;
  1111. this.x = attribute.array[ index ];
  1112. this.y = attribute.array[ index + 1 ];
  1113. return this;
  1114. },
  1115. rotateAround: function ( center, angle ) {
  1116. var c = Math.cos( angle ), s = Math.sin( angle );
  1117. var x = this.x - center.x;
  1118. var y = this.y - center.y;
  1119. this.x = x * c - y * s + center.x;
  1120. this.y = x * s + y * c + center.y;
  1121. return this;
  1122. }
  1123. };
  1124. // File:src/math/Vector3.js
  1125. /**
  1126. * @author mrdoob / http://mrdoob.com/
  1127. * @author *kile / http://kile.stravaganza.org/
  1128. * @author philogb / http://blog.thejit.org/
  1129. * @author mikael emtinger / http://gomo.se/
  1130. * @author egraether / http://egraether.com/
  1131. * @author WestLangley / http://github.com/WestLangley
  1132. */
  1133. THREE.Vector3 = function ( x, y, z ) {
  1134. this.x = x || 0;
  1135. this.y = y || 0;
  1136. this.z = z || 0;
  1137. };
  1138. THREE.Vector3.prototype = {
  1139. constructor: THREE.Vector3,
  1140. set: function ( x, y, z ) {
  1141. this.x = x;
  1142. this.y = y;
  1143. this.z = z;
  1144. return this;
  1145. },
  1146. setX: function ( x ) {
  1147. this.x = x;
  1148. return this;
  1149. },
  1150. setY: function ( y ) {
  1151. this.y = y;
  1152. return this;
  1153. },
  1154. setZ: function ( z ) {
  1155. this.z = z;
  1156. return this;
  1157. },
  1158. setComponent: function ( index, value ) {
  1159. switch ( index ) {
  1160. case 0: this.x = value; break;
  1161. case 1: this.y = value; break;
  1162. case 2: this.z = value; break;
  1163. default: throw new Error( 'index is out of range: ' + index );
  1164. }
  1165. },
  1166. getComponent: function ( index ) {
  1167. switch ( index ) {
  1168. case 0: return this.x;
  1169. case 1: return this.y;
  1170. case 2: return this.z;
  1171. default: throw new Error( 'index is out of range: ' + index );
  1172. }
  1173. },
  1174. clone: function () {
  1175. return new this.constructor( this.x, this.y, this.z );
  1176. },
  1177. copy: function ( v ) {
  1178. this.x = v.x;
  1179. this.y = v.y;
  1180. this.z = v.z;
  1181. return this;
  1182. },
  1183. add: function ( v, w ) {
  1184. if ( w !== undefined ) {
  1185. console.warn( 'THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1186. return this.addVectors( v, w );
  1187. }
  1188. this.x += v.x;
  1189. this.y += v.y;
  1190. this.z += v.z;
  1191. return this;
  1192. },
  1193. addScalar: function ( s ) {
  1194. this.x += s;
  1195. this.y += s;
  1196. this.z += s;
  1197. return this;
  1198. },
  1199. addVectors: function ( a, b ) {
  1200. this.x = a.x + b.x;
  1201. this.y = a.y + b.y;
  1202. this.z = a.z + b.z;
  1203. return this;
  1204. },
  1205. addScaledVector: function ( v, s ) {
  1206. this.x += v.x * s;
  1207. this.y += v.y * s;
  1208. this.z += v.z * s;
  1209. return this;
  1210. },
  1211. sub: function ( v, w ) {
  1212. if ( w !== undefined ) {
  1213. console.warn( 'THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1214. return this.subVectors( v, w );
  1215. }
  1216. this.x -= v.x;
  1217. this.y -= v.y;
  1218. this.z -= v.z;
  1219. return this;
  1220. },
  1221. subScalar: function ( s ) {
  1222. this.x -= s;
  1223. this.y -= s;
  1224. this.z -= s;
  1225. return this;
  1226. },
  1227. subVectors: function ( a, b ) {
  1228. this.x = a.x - b.x;
  1229. this.y = a.y - b.y;
  1230. this.z = a.z - b.z;
  1231. return this;
  1232. },
  1233. multiply: function ( v, w ) {
  1234. if ( w !== undefined ) {
  1235. console.warn( 'THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.' );
  1236. return this.multiplyVectors( v, w );
  1237. }
  1238. this.x *= v.x;
  1239. this.y *= v.y;
  1240. this.z *= v.z;
  1241. return this;
  1242. },
  1243. multiplyScalar: function ( scalar ) {
  1244. if ( isFinite( scalar ) ) {
  1245. this.x *= scalar;
  1246. this.y *= scalar;
  1247. this.z *= scalar;
  1248. } else {
  1249. this.x = 0;
  1250. this.y = 0;
  1251. this.z = 0;
  1252. }
  1253. return this;
  1254. },
  1255. multiplyVectors: function ( a, b ) {
  1256. this.x = a.x * b.x;
  1257. this.y = a.y * b.y;
  1258. this.z = a.z * b.z;
  1259. return this;
  1260. },
  1261. applyEuler: function () {
  1262. var quaternion;
  1263. return function applyEuler( euler ) {
  1264. if ( euler instanceof THREE.Euler === false ) {
  1265. console.error( 'THREE.Vector3: .applyEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  1266. }
  1267. if ( quaternion === undefined ) quaternion = new THREE.Quaternion();
  1268. this.applyQuaternion( quaternion.setFromEuler( euler ) );
  1269. return this;
  1270. };
  1271. }(),
  1272. applyAxisAngle: function () {
  1273. var quaternion;
  1274. return function applyAxisAngle( axis, angle ) {
  1275. if ( quaternion === undefined ) quaternion = new THREE.Quaternion();
  1276. this.applyQuaternion( quaternion.setFromAxisAngle( axis, angle ) );
  1277. return this;
  1278. };
  1279. }(),
  1280. applyMatrix3: function ( m ) {
  1281. var x = this.x;
  1282. var y = this.y;
  1283. var z = this.z;
  1284. var e = m.elements;
  1285. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
  1286. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
  1287. this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
  1288. return this;
  1289. },
  1290. applyMatrix4: function ( m ) {
  1291. // input: THREE.Matrix4 affine matrix
  1292. var x = this.x, y = this.y, z = this.z;
  1293. var e = m.elements;
  1294. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ];
  1295. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ];
  1296. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ];
  1297. return this;
  1298. },
  1299. applyProjection: function ( m ) {
  1300. // input: THREE.Matrix4 projection matrix
  1301. var x = this.x, y = this.y, z = this.z;
  1302. var e = m.elements;
  1303. var d = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] ); // perspective divide
  1304. this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * d;
  1305. this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * d;
  1306. this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * d;
  1307. return this;
  1308. },
  1309. applyQuaternion: function ( q ) {
  1310. var x = this.x;
  1311. var y = this.y;
  1312. var z = this.z;
  1313. var qx = q.x;
  1314. var qy = q.y;
  1315. var qz = q.z;
  1316. var qw = q.w;
  1317. // calculate quat * vector
  1318. var ix = qw * x + qy * z - qz * y;
  1319. var iy = qw * y + qz * x - qx * z;
  1320. var iz = qw * z + qx * y - qy * x;
  1321. var iw = - qx * x - qy * y - qz * z;
  1322. // calculate result * inverse quat
  1323. this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
  1324. this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
  1325. this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
  1326. return this;
  1327. },
  1328. project: function () {
  1329. var matrix;
  1330. return function project( camera ) {
  1331. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  1332. matrix.multiplyMatrices( camera.projectionMatrix, matrix.getInverse( camera.matrixWorld ) );
  1333. return this.applyProjection( matrix );
  1334. };
  1335. }(),
  1336. unproject: function () {
  1337. var matrix;
  1338. return function unproject( camera ) {
  1339. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  1340. matrix.multiplyMatrices( camera.matrixWorld, matrix.getInverse( camera.projectionMatrix ) );
  1341. return this.applyProjection( matrix );
  1342. };
  1343. }(),
  1344. transformDirection: function ( m ) {
  1345. // input: THREE.Matrix4 affine matrix
  1346. // vector interpreted as a direction
  1347. var x = this.x, y = this.y, z = this.z;
  1348. var e = m.elements;
  1349. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
  1350. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
  1351. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
  1352. this.normalize();
  1353. return this;
  1354. },
  1355. divide: function ( v ) {
  1356. this.x /= v.x;
  1357. this.y /= v.y;
  1358. this.z /= v.z;
  1359. return this;
  1360. },
  1361. divideScalar: function ( scalar ) {
  1362. return this.multiplyScalar( 1 / scalar );
  1363. },
  1364. min: function ( v ) {
  1365. this.x = Math.min( this.x, v.x );
  1366. this.y = Math.min( this.y, v.y );
  1367. this.z = Math.min( this.z, v.z );
  1368. return this;
  1369. },
  1370. max: function ( v ) {
  1371. this.x = Math.max( this.x, v.x );
  1372. this.y = Math.max( this.y, v.y );
  1373. this.z = Math.max( this.z, v.z );
  1374. return this;
  1375. },
  1376. clamp: function ( min, max ) {
  1377. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1378. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1379. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1380. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  1381. return this;
  1382. },
  1383. clampScalar: function () {
  1384. var min, max;
  1385. return function clampScalar( minVal, maxVal ) {
  1386. if ( min === undefined ) {
  1387. min = new THREE.Vector3();
  1388. max = new THREE.Vector3();
  1389. }
  1390. min.set( minVal, minVal, minVal );
  1391. max.set( maxVal, maxVal, maxVal );
  1392. return this.clamp( min, max );
  1393. };
  1394. }(),
  1395. clampLength: function ( min, max ) {
  1396. var length = this.length();
  1397. this.multiplyScalar( Math.max( min, Math.min( max, length ) ) / length );
  1398. return this;
  1399. },
  1400. floor: function () {
  1401. this.x = Math.floor( this.x );
  1402. this.y = Math.floor( this.y );
  1403. this.z = Math.floor( this.z );
  1404. return this;
  1405. },
  1406. ceil: function () {
  1407. this.x = Math.ceil( this.x );
  1408. this.y = Math.ceil( this.y );
  1409. this.z = Math.ceil( this.z );
  1410. return this;
  1411. },
  1412. round: function () {
  1413. this.x = Math.round( this.x );
  1414. this.y = Math.round( this.y );
  1415. this.z = Math.round( this.z );
  1416. return this;
  1417. },
  1418. roundToZero: function () {
  1419. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1420. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1421. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1422. return this;
  1423. },
  1424. negate: function () {
  1425. this.x = - this.x;
  1426. this.y = - this.y;
  1427. this.z = - this.z;
  1428. return this;
  1429. },
  1430. dot: function ( v ) {
  1431. return this.x * v.x + this.y * v.y + this.z * v.z;
  1432. },
  1433. lengthSq: function () {
  1434. return this.x * this.x + this.y * this.y + this.z * this.z;
  1435. },
  1436. length: function () {
  1437. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
  1438. },
  1439. lengthManhattan: function () {
  1440. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  1441. },
  1442. normalize: function () {
  1443. return this.divideScalar( this.length() );
  1444. },
  1445. setLength: function ( length ) {
  1446. return this.multiplyScalar( length / this.length() );
  1447. },
  1448. lerp: function ( v, alpha ) {
  1449. this.x += ( v.x - this.x ) * alpha;
  1450. this.y += ( v.y - this.y ) * alpha;
  1451. this.z += ( v.z - this.z ) * alpha;
  1452. return this;
  1453. },
  1454. lerpVectors: function ( v1, v2, alpha ) {
  1455. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1456. return this;
  1457. },
  1458. cross: function ( v, w ) {
  1459. if ( w !== undefined ) {
  1460. console.warn( 'THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.' );
  1461. return this.crossVectors( v, w );
  1462. }
  1463. var x = this.x, y = this.y, z = this.z;
  1464. this.x = y * v.z - z * v.y;
  1465. this.y = z * v.x - x * v.z;
  1466. this.z = x * v.y - y * v.x;
  1467. return this;
  1468. },
  1469. crossVectors: function ( a, b ) {
  1470. var ax = a.x, ay = a.y, az = a.z;
  1471. var bx = b.x, by = b.y, bz = b.z;
  1472. this.x = ay * bz - az * by;
  1473. this.y = az * bx - ax * bz;
  1474. this.z = ax * by - ay * bx;
  1475. return this;
  1476. },
  1477. projectOnVector: function () {
  1478. var v1, dot;
  1479. return function projectOnVector( vector ) {
  1480. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1481. v1.copy( vector ).normalize();
  1482. dot = this.dot( v1 );
  1483. return this.copy( v1 ).multiplyScalar( dot );
  1484. };
  1485. }(),
  1486. projectOnPlane: function () {
  1487. var v1;
  1488. return function projectOnPlane( planeNormal ) {
  1489. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1490. v1.copy( this ).projectOnVector( planeNormal );
  1491. return this.sub( v1 );
  1492. }
  1493. }(),
  1494. reflect: function () {
  1495. // reflect incident vector off plane orthogonal to normal
  1496. // normal is assumed to have unit length
  1497. var v1;
  1498. return function reflect( normal ) {
  1499. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1500. return this.sub( v1.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
  1501. }
  1502. }(),
  1503. angleTo: function ( v ) {
  1504. var theta = this.dot( v ) / ( Math.sqrt( this.lengthSq() * v.lengthSq() ) );
  1505. // clamp, to handle numerical problems
  1506. return Math.acos( THREE.Math.clamp( theta, - 1, 1 ) );
  1507. },
  1508. distanceTo: function ( v ) {
  1509. return Math.sqrt( this.distanceToSquared( v ) );
  1510. },
  1511. distanceToSquared: function ( v ) {
  1512. var dx = this.x - v.x;
  1513. var dy = this.y - v.y;
  1514. var dz = this.z - v.z;
  1515. return dx * dx + dy * dy + dz * dz;
  1516. },
  1517. setFromMatrixPosition: function ( m ) {
  1518. this.x = m.elements[ 12 ];
  1519. this.y = m.elements[ 13 ];
  1520. this.z = m.elements[ 14 ];
  1521. return this;
  1522. },
  1523. setFromMatrixScale: function ( m ) {
  1524. var sx = this.set( m.elements[ 0 ], m.elements[ 1 ], m.elements[ 2 ] ).length();
  1525. var sy = this.set( m.elements[ 4 ], m.elements[ 5 ], m.elements[ 6 ] ).length();
  1526. var sz = this.set( m.elements[ 8 ], m.elements[ 9 ], m.elements[ 10 ] ).length();
  1527. this.x = sx;
  1528. this.y = sy;
  1529. this.z = sz;
  1530. return this;
  1531. },
  1532. setFromMatrixColumn: function ( index, matrix ) {
  1533. var offset = index * 4;
  1534. var me = matrix.elements;
  1535. this.x = me[ offset ];
  1536. this.y = me[ offset + 1 ];
  1537. this.z = me[ offset + 2 ];
  1538. return this;
  1539. },
  1540. equals: function ( v ) {
  1541. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  1542. },
  1543. fromArray: function ( array, offset ) {
  1544. if ( offset === undefined ) offset = 0;
  1545. this.x = array[ offset ];
  1546. this.y = array[ offset + 1 ];
  1547. this.z = array[ offset + 2 ];
  1548. return this;
  1549. },
  1550. toArray: function ( array, offset ) {
  1551. if ( array === undefined ) array = [];
  1552. if ( offset === undefined ) offset = 0;
  1553. array[ offset ] = this.x;
  1554. array[ offset + 1 ] = this.y;
  1555. array[ offset + 2 ] = this.z;
  1556. return array;
  1557. },
  1558. fromAttribute: function ( attribute, index, offset ) {
  1559. if ( offset === undefined ) offset = 0;
  1560. index = index * attribute.itemSize + offset;
  1561. this.x = attribute.array[ index ];
  1562. this.y = attribute.array[ index + 1 ];
  1563. this.z = attribute.array[ index + 2 ];
  1564. return this;
  1565. }
  1566. };
  1567. // File:src/math/Vector4.js
  1568. /**
  1569. * @author supereggbert / http://www.paulbrunt.co.uk/
  1570. * @author philogb / http://blog.thejit.org/
  1571. * @author mikael emtinger / http://gomo.se/
  1572. * @author egraether / http://egraether.com/
  1573. * @author WestLangley / http://github.com/WestLangley
  1574. */
  1575. THREE.Vector4 = function ( x, y, z, w ) {
  1576. this.x = x || 0;
  1577. this.y = y || 0;
  1578. this.z = z || 0;
  1579. this.w = ( w !== undefined ) ? w : 1;
  1580. };
  1581. THREE.Vector4.prototype = {
  1582. constructor: THREE.Vector4,
  1583. set: function ( x, y, z, w ) {
  1584. this.x = x;
  1585. this.y = y;
  1586. this.z = z;
  1587. this.w = w;
  1588. return this;
  1589. },
  1590. setX: function ( x ) {
  1591. this.x = x;
  1592. return this;
  1593. },
  1594. setY: function ( y ) {
  1595. this.y = y;
  1596. return this;
  1597. },
  1598. setZ: function ( z ) {
  1599. this.z = z;
  1600. return this;
  1601. },
  1602. setW: function ( w ) {
  1603. this.w = w;
  1604. return this;
  1605. },
  1606. setComponent: function ( index, value ) {
  1607. switch ( index ) {
  1608. case 0: this.x = value; break;
  1609. case 1: this.y = value; break;
  1610. case 2: this.z = value; break;
  1611. case 3: this.w = value; break;
  1612. default: throw new Error( 'index is out of range: ' + index );
  1613. }
  1614. },
  1615. getComponent: function ( index ) {
  1616. switch ( index ) {
  1617. case 0: return this.x;
  1618. case 1: return this.y;
  1619. case 2: return this.z;
  1620. case 3: return this.w;
  1621. default: throw new Error( 'index is out of range: ' + index );
  1622. }
  1623. },
  1624. clone: function () {
  1625. return new this.constructor( this.x, this.y, this.z, this.w );
  1626. },
  1627. copy: function ( v ) {
  1628. this.x = v.x;
  1629. this.y = v.y;
  1630. this.z = v.z;
  1631. this.w = ( v.w !== undefined ) ? v.w : 1;
  1632. return this;
  1633. },
  1634. add: function ( v, w ) {
  1635. if ( w !== undefined ) {
  1636. console.warn( 'THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1637. return this.addVectors( v, w );
  1638. }
  1639. this.x += v.x;
  1640. this.y += v.y;
  1641. this.z += v.z;
  1642. this.w += v.w;
  1643. return this;
  1644. },
  1645. addScalar: function ( s ) {
  1646. this.x += s;
  1647. this.y += s;
  1648. this.z += s;
  1649. this.w += s;
  1650. return this;
  1651. },
  1652. addVectors: function ( a, b ) {
  1653. this.x = a.x + b.x;
  1654. this.y = a.y + b.y;
  1655. this.z = a.z + b.z;
  1656. this.w = a.w + b.w;
  1657. return this;
  1658. },
  1659. addScaledVector: function ( v, s ) {
  1660. this.x += v.x * s;
  1661. this.y += v.y * s;
  1662. this.z += v.z * s;
  1663. this.w += v.w * s;
  1664. return this;
  1665. },
  1666. sub: function ( v, w ) {
  1667. if ( w !== undefined ) {
  1668. console.warn( 'THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1669. return this.subVectors( v, w );
  1670. }
  1671. this.x -= v.x;
  1672. this.y -= v.y;
  1673. this.z -= v.z;
  1674. this.w -= v.w;
  1675. return this;
  1676. },
  1677. subScalar: function ( s ) {
  1678. this.x -= s;
  1679. this.y -= s;
  1680. this.z -= s;
  1681. this.w -= s;
  1682. return this;
  1683. },
  1684. subVectors: function ( a, b ) {
  1685. this.x = a.x - b.x;
  1686. this.y = a.y - b.y;
  1687. this.z = a.z - b.z;
  1688. this.w = a.w - b.w;
  1689. return this;
  1690. },
  1691. multiplyScalar: function ( scalar ) {
  1692. if ( isFinite( scalar ) ) {
  1693. this.x *= scalar;
  1694. this.y *= scalar;
  1695. this.z *= scalar;
  1696. this.w *= scalar;
  1697. } else {
  1698. this.x = 0;
  1699. this.y = 0;
  1700. this.z = 0;
  1701. this.w = 0;
  1702. }
  1703. return this;
  1704. },
  1705. applyMatrix4: function ( m ) {
  1706. var x = this.x;
  1707. var y = this.y;
  1708. var z = this.z;
  1709. var w = this.w;
  1710. var e = m.elements;
  1711. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  1712. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  1713. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  1714. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  1715. return this;
  1716. },
  1717. divideScalar: function ( scalar ) {
  1718. return this.multiplyScalar( 1 / scalar );
  1719. },
  1720. setAxisAngleFromQuaternion: function ( q ) {
  1721. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  1722. // q is assumed to be normalized
  1723. this.w = 2 * Math.acos( q.w );
  1724. var s = Math.sqrt( 1 - q.w * q.w );
  1725. if ( s < 0.0001 ) {
  1726. this.x = 1;
  1727. this.y = 0;
  1728. this.z = 0;
  1729. } else {
  1730. this.x = q.x / s;
  1731. this.y = q.y / s;
  1732. this.z = q.z / s;
  1733. }
  1734. return this;
  1735. },
  1736. setAxisAngleFromRotationMatrix: function ( m ) {
  1737. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  1738. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1739. var angle, x, y, z, // variables for result
  1740. epsilon = 0.01, // margin to allow for rounding errors
  1741. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  1742. te = m.elements,
  1743. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  1744. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  1745. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  1746. if ( ( Math.abs( m12 - m21 ) < epsilon )
  1747. && ( Math.abs( m13 - m31 ) < epsilon )
  1748. && ( Math.abs( m23 - m32 ) < epsilon ) ) {
  1749. // singularity found
  1750. // first check for identity matrix which must have +1 for all terms
  1751. // in leading diagonal and zero in other terms
  1752. if ( ( Math.abs( m12 + m21 ) < epsilon2 )
  1753. && ( Math.abs( m13 + m31 ) < epsilon2 )
  1754. && ( Math.abs( m23 + m32 ) < epsilon2 )
  1755. && ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  1756. // this singularity is identity matrix so angle = 0
  1757. this.set( 1, 0, 0, 0 );
  1758. return this; // zero angle, arbitrary axis
  1759. }
  1760. // otherwise this singularity is angle = 180
  1761. angle = Math.PI;
  1762. var xx = ( m11 + 1 ) / 2;
  1763. var yy = ( m22 + 1 ) / 2;
  1764. var zz = ( m33 + 1 ) / 2;
  1765. var xy = ( m12 + m21 ) / 4;
  1766. var xz = ( m13 + m31 ) / 4;
  1767. var yz = ( m23 + m32 ) / 4;
  1768. if ( ( xx > yy ) && ( xx > zz ) ) {
  1769. // m11 is the largest diagonal term
  1770. if ( xx < epsilon ) {
  1771. x = 0;
  1772. y = 0.707106781;
  1773. z = 0.707106781;
  1774. } else {
  1775. x = Math.sqrt( xx );
  1776. y = xy / x;
  1777. z = xz / x;
  1778. }
  1779. } else if ( yy > zz ) {
  1780. // m22 is the largest diagonal term
  1781. if ( yy < epsilon ) {
  1782. x = 0.707106781;
  1783. y = 0;
  1784. z = 0.707106781;
  1785. } else {
  1786. y = Math.sqrt( yy );
  1787. x = xy / y;
  1788. z = yz / y;
  1789. }
  1790. } else {
  1791. // m33 is the largest diagonal term so base result on this
  1792. if ( zz < epsilon ) {
  1793. x = 0.707106781;
  1794. y = 0.707106781;
  1795. z = 0;
  1796. } else {
  1797. z = Math.sqrt( zz );
  1798. x = xz / z;
  1799. y = yz / z;
  1800. }
  1801. }
  1802. this.set( x, y, z, angle );
  1803. return this; // return 180 deg rotation
  1804. }
  1805. // as we have reached here there are no singularities so we can handle normally
  1806. var s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 )
  1807. + ( m13 - m31 ) * ( m13 - m31 )
  1808. + ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  1809. if ( Math.abs( s ) < 0.001 ) s = 1;
  1810. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  1811. // caught by singularity test above, but I've left it in just in case
  1812. this.x = ( m32 - m23 ) / s;
  1813. this.y = ( m13 - m31 ) / s;
  1814. this.z = ( m21 - m12 ) / s;
  1815. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  1816. return this;
  1817. },
  1818. min: function ( v ) {
  1819. this.x = Math.min( this.x, v.x );
  1820. this.y = Math.min( this.y, v.y );
  1821. this.z = Math.min( this.z, v.z );
  1822. this.w = Math.min( this.w, v.w );
  1823. return this;
  1824. },
  1825. max: function ( v ) {
  1826. this.x = Math.max( this.x, v.x );
  1827. this.y = Math.max( this.y, v.y );
  1828. this.z = Math.max( this.z, v.z );
  1829. this.w = Math.max( this.w, v.w );
  1830. return this;
  1831. },
  1832. clamp: function ( min, max ) {
  1833. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1834. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1835. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1836. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  1837. this.w = Math.max( min.w, Math.min( max.w, this.w ) );
  1838. return this;
  1839. },
  1840. clampScalar: function () {
  1841. var min, max;
  1842. return function clampScalar( minVal, maxVal ) {
  1843. if ( min === undefined ) {
  1844. min = new THREE.Vector4();
  1845. max = new THREE.Vector4();
  1846. }
  1847. min.set( minVal, minVal, minVal, minVal );
  1848. max.set( maxVal, maxVal, maxVal, maxVal );
  1849. return this.clamp( min, max );
  1850. };
  1851. }(),
  1852. floor: function () {
  1853. this.x = Math.floor( this.x );
  1854. this.y = Math.floor( this.y );
  1855. this.z = Math.floor( this.z );
  1856. this.w = Math.floor( this.w );
  1857. return this;
  1858. },
  1859. ceil: function () {
  1860. this.x = Math.ceil( this.x );
  1861. this.y = Math.ceil( this.y );
  1862. this.z = Math.ceil( this.z );
  1863. this.w = Math.ceil( this.w );
  1864. return this;
  1865. },
  1866. round: function () {
  1867. this.x = Math.round( this.x );
  1868. this.y = Math.round( this.y );
  1869. this.z = Math.round( this.z );
  1870. this.w = Math.round( this.w );
  1871. return this;
  1872. },
  1873. roundToZero: function () {
  1874. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1875. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1876. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1877. this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
  1878. return this;
  1879. },
  1880. negate: function () {
  1881. this.x = - this.x;
  1882. this.y = - this.y;
  1883. this.z = - this.z;
  1884. this.w = - this.w;
  1885. return this;
  1886. },
  1887. dot: function ( v ) {
  1888. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  1889. },
  1890. lengthSq: function () {
  1891. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  1892. },
  1893. length: function () {
  1894. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  1895. },
  1896. lengthManhattan: function () {
  1897. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  1898. },
  1899. normalize: function () {
  1900. return this.divideScalar( this.length() );
  1901. },
  1902. setLength: function ( length ) {
  1903. return this.multiplyScalar( length / this.length() );
  1904. },
  1905. lerp: function ( v, alpha ) {
  1906. this.x += ( v.x - this.x ) * alpha;
  1907. this.y += ( v.y - this.y ) * alpha;
  1908. this.z += ( v.z - this.z ) * alpha;
  1909. this.w += ( v.w - this.w ) * alpha;
  1910. return this;
  1911. },
  1912. lerpVectors: function ( v1, v2, alpha ) {
  1913. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1914. return this;
  1915. },
  1916. equals: function ( v ) {
  1917. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  1918. },
  1919. fromArray: function ( array, offset ) {
  1920. if ( offset === undefined ) offset = 0;
  1921. this.x = array[ offset ];
  1922. this.y = array[ offset + 1 ];
  1923. this.z = array[ offset + 2 ];
  1924. this.w = array[ offset + 3 ];
  1925. return this;
  1926. },
  1927. toArray: function ( array, offset ) {
  1928. if ( array === undefined ) array = [];
  1929. if ( offset === undefined ) offset = 0;
  1930. array[ offset ] = this.x;
  1931. array[ offset + 1 ] = this.y;
  1932. array[ offset + 2 ] = this.z;
  1933. array[ offset + 3 ] = this.w;
  1934. return array;
  1935. },
  1936. fromAttribute: function ( attribute, index, offset ) {
  1937. if ( offset === undefined ) offset = 0;
  1938. index = index * attribute.itemSize + offset;
  1939. this.x = attribute.array[ index ];
  1940. this.y = attribute.array[ index + 1 ];
  1941. this.z = attribute.array[ index + 2 ];
  1942. this.w = attribute.array[ index + 3 ];
  1943. return this;
  1944. }
  1945. };
  1946. // File:src/math/Euler.js
  1947. /**
  1948. * @author mrdoob / http://mrdoob.com/
  1949. * @author WestLangley / http://github.com/WestLangley
  1950. * @author bhouston / http://clara.io
  1951. */
  1952. THREE.Euler = function ( x, y, z, order ) {
  1953. this._x = x || 0;
  1954. this._y = y || 0;
  1955. this._z = z || 0;
  1956. this._order = order || THREE.Euler.DefaultOrder;
  1957. };
  1958. THREE.Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
  1959. THREE.Euler.DefaultOrder = 'XYZ';
  1960. THREE.Euler.prototype = {
  1961. constructor: THREE.Euler,
  1962. get x () {
  1963. return this._x;
  1964. },
  1965. set x ( value ) {
  1966. this._x = value;
  1967. this.onChangeCallback();
  1968. },
  1969. get y () {
  1970. return this._y;
  1971. },
  1972. set y ( value ) {
  1973. this._y = value;
  1974. this.onChangeCallback();
  1975. },
  1976. get z () {
  1977. return this._z;
  1978. },
  1979. set z ( value ) {
  1980. this._z = value;
  1981. this.onChangeCallback();
  1982. },
  1983. get order () {
  1984. return this._order;
  1985. },
  1986. set order ( value ) {
  1987. this._order = value;
  1988. this.onChangeCallback();
  1989. },
  1990. set: function ( x, y, z, order ) {
  1991. this._x = x;
  1992. this._y = y;
  1993. this._z = z;
  1994. this._order = order || this._order;
  1995. this.onChangeCallback();
  1996. return this;
  1997. },
  1998. clone: function () {
  1999. return new this.constructor( this._x, this._y, this._z, this._order);
  2000. },
  2001. copy: function ( euler ) {
  2002. this._x = euler._x;
  2003. this._y = euler._y;
  2004. this._z = euler._z;
  2005. this._order = euler._order;
  2006. this.onChangeCallback();
  2007. return this;
  2008. },
  2009. setFromRotationMatrix: function ( m, order, update ) {
  2010. var clamp = THREE.Math.clamp;
  2011. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2012. var te = m.elements;
  2013. var m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  2014. var m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  2015. var m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  2016. order = order || this._order;
  2017. if ( order === 'XYZ' ) {
  2018. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  2019. if ( Math.abs( m13 ) < 0.99999 ) {
  2020. this._x = Math.atan2( - m23, m33 );
  2021. this._z = Math.atan2( - m12, m11 );
  2022. } else {
  2023. this._x = Math.atan2( m32, m22 );
  2024. this._z = 0;
  2025. }
  2026. } else if ( order === 'YXZ' ) {
  2027. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  2028. if ( Math.abs( m23 ) < 0.99999 ) {
  2029. this._y = Math.atan2( m13, m33 );
  2030. this._z = Math.atan2( m21, m22 );
  2031. } else {
  2032. this._y = Math.atan2( - m31, m11 );
  2033. this._z = 0;
  2034. }
  2035. } else if ( order === 'ZXY' ) {
  2036. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  2037. if ( Math.abs( m32 ) < 0.99999 ) {
  2038. this._y = Math.atan2( - m31, m33 );
  2039. this._z = Math.atan2( - m12, m22 );
  2040. } else {
  2041. this._y = 0;
  2042. this._z = Math.atan2( m21, m11 );
  2043. }
  2044. } else if ( order === 'ZYX' ) {
  2045. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  2046. if ( Math.abs( m31 ) < 0.99999 ) {
  2047. this._x = Math.atan2( m32, m33 );
  2048. this._z = Math.atan2( m21, m11 );
  2049. } else {
  2050. this._x = 0;
  2051. this._z = Math.atan2( - m12, m22 );
  2052. }
  2053. } else if ( order === 'YZX' ) {
  2054. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  2055. if ( Math.abs( m21 ) < 0.99999 ) {
  2056. this._x = Math.atan2( - m23, m22 );
  2057. this._y = Math.atan2( - m31, m11 );
  2058. } else {
  2059. this._x = 0;
  2060. this._y = Math.atan2( m13, m33 );
  2061. }
  2062. } else if ( order === 'XZY' ) {
  2063. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  2064. if ( Math.abs( m12 ) < 0.99999 ) {
  2065. this._x = Math.atan2( m32, m22 );
  2066. this._y = Math.atan2( m13, m11 );
  2067. } else {
  2068. this._x = Math.atan2( - m23, m33 );
  2069. this._y = 0;
  2070. }
  2071. } else {
  2072. console.warn( 'THREE.Euler: .setFromRotationMatrix() given unsupported order: ' + order )
  2073. }
  2074. this._order = order;
  2075. if ( update !== false ) this.onChangeCallback();
  2076. return this;
  2077. },
  2078. setFromQuaternion: function () {
  2079. var matrix;
  2080. return function ( q, order, update ) {
  2081. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  2082. matrix.makeRotationFromQuaternion( q );
  2083. this.setFromRotationMatrix( matrix, order, update );
  2084. return this;
  2085. };
  2086. }(),
  2087. setFromVector3: function ( v, order ) {
  2088. return this.set( v.x, v.y, v.z, order || this._order );
  2089. },
  2090. reorder: function () {
  2091. // WARNING: this discards revolution information -bhouston
  2092. var q = new THREE.Quaternion();
  2093. return function ( newOrder ) {
  2094. q.setFromEuler( this );
  2095. this.setFromQuaternion( q, newOrder );
  2096. };
  2097. }(),
  2098. equals: function ( euler ) {
  2099. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  2100. },
  2101. fromArray: function ( array ) {
  2102. this._x = array[ 0 ];
  2103. this._y = array[ 1 ];
  2104. this._z = array[ 2 ];
  2105. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  2106. this.onChangeCallback();
  2107. return this;
  2108. },
  2109. toArray: function ( array, offset ) {
  2110. if ( array === undefined ) array = [];
  2111. if ( offset === undefined ) offset = 0;
  2112. array[ offset ] = this._x;
  2113. array[ offset + 1 ] = this._y;
  2114. array[ offset + 2 ] = this._z;
  2115. array[ offset + 3 ] = this._order;
  2116. return array;
  2117. },
  2118. toVector3: function ( optionalResult ) {
  2119. if ( optionalResult ) {
  2120. return optionalResult.set( this._x, this._y, this._z );
  2121. } else {
  2122. return new THREE.Vector3( this._x, this._y, this._z );
  2123. }
  2124. },
  2125. onChange: function ( callback ) {
  2126. this.onChangeCallback = callback;
  2127. return this;
  2128. },
  2129. onChangeCallback: function () {}
  2130. };
  2131. // File:src/math/Line3.js
  2132. /**
  2133. * @author bhouston / http://clara.io
  2134. */
  2135. THREE.Line3 = function ( start, end ) {
  2136. this.start = ( start !== undefined ) ? start : new THREE.Vector3();
  2137. this.end = ( end !== undefined ) ? end : new THREE.Vector3();
  2138. };
  2139. THREE.Line3.prototype = {
  2140. constructor: THREE.Line3,
  2141. set: function ( start, end ) {
  2142. this.start.copy( start );
  2143. this.end.copy( end );
  2144. return this;
  2145. },
  2146. clone: function () {
  2147. return new this.constructor().copy( this );
  2148. },
  2149. copy: function ( line ) {
  2150. this.start.copy( line.start );
  2151. this.end.copy( line.end );
  2152. return this;
  2153. },
  2154. center: function ( optionalTarget ) {
  2155. var result = optionalTarget || new THREE.Vector3();
  2156. return result.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  2157. },
  2158. delta: function ( optionalTarget ) {
  2159. var result = optionalTarget || new THREE.Vector3();
  2160. return result.subVectors( this.end, this.start );
  2161. },
  2162. distanceSq: function () {
  2163. return this.start.distanceToSquared( this.end );
  2164. },
  2165. distance: function () {
  2166. return this.start.distanceTo( this.end );
  2167. },
  2168. at: function ( t, optionalTarget ) {
  2169. var result = optionalTarget || new THREE.Vector3();
  2170. return this.delta( result ).multiplyScalar( t ).add( this.start );
  2171. },
  2172. closestPointToPointParameter: function () {
  2173. var startP = new THREE.Vector3();
  2174. var startEnd = new THREE.Vector3();
  2175. return function ( point, clampToLine ) {
  2176. startP.subVectors( point, this.start );
  2177. startEnd.subVectors( this.end, this.start );
  2178. var startEnd2 = startEnd.dot( startEnd );
  2179. var startEnd_startP = startEnd.dot( startP );
  2180. var t = startEnd_startP / startEnd2;
  2181. if ( clampToLine ) {
  2182. t = THREE.Math.clamp( t, 0, 1 );
  2183. }
  2184. return t;
  2185. };
  2186. }(),
  2187. closestPointToPoint: function ( point, clampToLine, optionalTarget ) {
  2188. var t = this.closestPointToPointParameter( point, clampToLine );
  2189. var result = optionalTarget || new THREE.Vector3();
  2190. return this.delta( result ).multiplyScalar( t ).add( this.start );
  2191. },
  2192. applyMatrix4: function ( matrix ) {
  2193. this.start.applyMatrix4( matrix );
  2194. this.end.applyMatrix4( matrix );
  2195. return this;
  2196. },
  2197. equals: function ( line ) {
  2198. return line.start.equals( this.start ) && line.end.equals( this.end );
  2199. }
  2200. };
  2201. // File:src/math/Box2.js
  2202. /**
  2203. * @author bhouston / http://clara.io
  2204. */
  2205. THREE.Box2 = function ( min, max ) {
  2206. this.min = ( min !== undefined ) ? min : new THREE.Vector2( Infinity, Infinity );
  2207. this.max = ( max !== undefined ) ? max : new THREE.Vector2( - Infinity, - Infinity );
  2208. };
  2209. THREE.Box2.prototype = {
  2210. constructor: THREE.Box2,
  2211. set: function ( min, max ) {
  2212. this.min.copy( min );
  2213. this.max.copy( max );
  2214. return this;
  2215. },
  2216. setFromPoints: function ( points ) {
  2217. this.makeEmpty();
  2218. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2219. this.expandByPoint( points[ i ] )
  2220. }
  2221. return this;
  2222. },
  2223. setFromCenterAndSize: function () {
  2224. var v1 = new THREE.Vector2();
  2225. return function ( center, size ) {
  2226. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2227. this.min.copy( center ).sub( halfSize );
  2228. this.max.copy( center ).add( halfSize );
  2229. return this;
  2230. };
  2231. }(),
  2232. clone: function () {
  2233. return new this.constructor().copy( this );
  2234. },
  2235. copy: function ( box ) {
  2236. this.min.copy( box.min );
  2237. this.max.copy( box.max );
  2238. return this;
  2239. },
  2240. makeEmpty: function () {
  2241. this.min.x = this.min.y = Infinity;
  2242. this.max.x = this.max.y = - Infinity;
  2243. return this;
  2244. },
  2245. empty: function () {
  2246. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2247. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  2248. },
  2249. center: function ( optionalTarget ) {
  2250. var result = optionalTarget || new THREE.Vector2();
  2251. return result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2252. },
  2253. size: function ( optionalTarget ) {
  2254. var result = optionalTarget || new THREE.Vector2();
  2255. return result.subVectors( this.max, this.min );
  2256. },
  2257. expandByPoint: function ( point ) {
  2258. this.min.min( point );
  2259. this.max.max( point );
  2260. return this;
  2261. },
  2262. expandByVector: function ( vector ) {
  2263. this.min.sub( vector );
  2264. this.max.add( vector );
  2265. return this;
  2266. },
  2267. expandByScalar: function ( scalar ) {
  2268. this.min.addScalar( - scalar );
  2269. this.max.addScalar( scalar );
  2270. return this;
  2271. },
  2272. containsPoint: function ( point ) {
  2273. if ( point.x < this.min.x || point.x > this.max.x ||
  2274. point.y < this.min.y || point.y > this.max.y ) {
  2275. return false;
  2276. }
  2277. return true;
  2278. },
  2279. containsBox: function ( box ) {
  2280. if ( ( this.min.x <= box.min.x ) && ( box.max.x <= this.max.x ) &&
  2281. ( this.min.y <= box.min.y ) && ( box.max.y <= this.max.y ) ) {
  2282. return true;
  2283. }
  2284. return false;
  2285. },
  2286. getParameter: function ( point, optionalTarget ) {
  2287. // This can potentially have a divide by zero if the box
  2288. // has a size dimension of 0.
  2289. var result = optionalTarget || new THREE.Vector2();
  2290. return result.set(
  2291. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2292. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  2293. );
  2294. },
  2295. intersectsBox: function ( box ) {
  2296. // using 6 splitting planes to rule out intersections.
  2297. if ( box.max.x < this.min.x || box.min.x > this.max.x ||
  2298. box.max.y < this.min.y || box.min.y > this.max.y ) {
  2299. return false;
  2300. }
  2301. return true;
  2302. },
  2303. clampPoint: function ( point, optionalTarget ) {
  2304. var result = optionalTarget || new THREE.Vector2();
  2305. return result.copy( point ).clamp( this.min, this.max );
  2306. },
  2307. distanceToPoint: function () {
  2308. var v1 = new THREE.Vector2();
  2309. return function ( point ) {
  2310. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  2311. return clampedPoint.sub( point ).length();
  2312. };
  2313. }(),
  2314. intersect: function ( box ) {
  2315. this.min.max( box.min );
  2316. this.max.min( box.max );
  2317. return this;
  2318. },
  2319. union: function ( box ) {
  2320. this.min.min( box.min );
  2321. this.max.max( box.max );
  2322. return this;
  2323. },
  2324. translate: function ( offset ) {
  2325. this.min.add( offset );
  2326. this.max.add( offset );
  2327. return this;
  2328. },
  2329. equals: function ( box ) {
  2330. return box.min.equals( this.min ) && box.max.equals( this.max );
  2331. }
  2332. };
  2333. // File:src/math/Box3.js
  2334. /**
  2335. * @author bhouston / http://clara.io
  2336. * @author WestLangley / http://github.com/WestLangley
  2337. */
  2338. THREE.Box3 = function ( min, max ) {
  2339. this.min = ( min !== undefined ) ? min : new THREE.Vector3( Infinity, Infinity, Infinity );
  2340. this.max = ( max !== undefined ) ? max : new THREE.Vector3( - Infinity, - Infinity, - Infinity );
  2341. };
  2342. THREE.Box3.prototype = {
  2343. constructor: THREE.Box3,
  2344. set: function ( min, max ) {
  2345. this.min.copy( min );
  2346. this.max.copy( max );
  2347. return this;
  2348. },
  2349. setFromPoints: function ( points ) {
  2350. this.makeEmpty();
  2351. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2352. this.expandByPoint( points[ i ] );
  2353. }
  2354. return this;
  2355. },
  2356. setFromCenterAndSize: function () {
  2357. var v1 = new THREE.Vector3();
  2358. return function ( center, size ) {
  2359. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2360. this.min.copy( center ).sub( halfSize );
  2361. this.max.copy( center ).add( halfSize );
  2362. return this;
  2363. };
  2364. }(),
  2365. setFromObject: function () {
  2366. // Computes the world-axis-aligned bounding box of an object (including its children),
  2367. // accounting for both the object's, and children's, world transforms
  2368. var v1 = new THREE.Vector3();
  2369. return function ( object ) {
  2370. var scope = this;
  2371. object.updateMatrixWorld( true );
  2372. this.makeEmpty();
  2373. object.traverse( function ( node ) {
  2374. var geometry = node.geometry;
  2375. if ( geometry !== undefined ) {
  2376. if ( geometry instanceof THREE.Geometry ) {
  2377. var vertices = geometry.vertices;
  2378. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  2379. v1.copy( vertices[ i ] );
  2380. v1.applyMatrix4( node.matrixWorld );
  2381. scope.expandByPoint( v1 );
  2382. }
  2383. } else if ( geometry instanceof THREE.BufferGeometry && geometry.attributes[ 'position' ] !== undefined ) {
  2384. var positions = geometry.attributes[ 'position' ].array;
  2385. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  2386. v1.set( positions[ i ], positions[ i + 1 ], positions[ i + 2 ] );
  2387. v1.applyMatrix4( node.matrixWorld );
  2388. scope.expandByPoint( v1 );
  2389. }
  2390. }
  2391. }
  2392. } );
  2393. return this;
  2394. };
  2395. }(),
  2396. clone: function () {
  2397. return new this.constructor().copy( this );
  2398. },
  2399. copy: function ( box ) {
  2400. this.min.copy( box.min );
  2401. this.max.copy( box.max );
  2402. return this;
  2403. },
  2404. makeEmpty: function () {
  2405. this.min.x = this.min.y = this.min.z = Infinity;
  2406. this.max.x = this.max.y = this.max.z = - Infinity;
  2407. return this;
  2408. },
  2409. empty: function () {
  2410. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2411. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  2412. },
  2413. center: function ( optionalTarget ) {
  2414. var result = optionalTarget || new THREE.Vector3();
  2415. return result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2416. },
  2417. size: function ( optionalTarget ) {
  2418. var result = optionalTarget || new THREE.Vector3();
  2419. return result.subVectors( this.max, this.min );
  2420. },
  2421. expandByPoint: function ( point ) {
  2422. this.min.min( point );
  2423. this.max.max( point );
  2424. return this;
  2425. },
  2426. expandByVector: function ( vector ) {
  2427. this.min.sub( vector );
  2428. this.max.add( vector );
  2429. return this;
  2430. },
  2431. expandByScalar: function ( scalar ) {
  2432. this.min.addScalar( - scalar );
  2433. this.max.addScalar( scalar );
  2434. return this;
  2435. },
  2436. containsPoint: function ( point ) {
  2437. if ( point.x < this.min.x || point.x > this.max.x ||
  2438. point.y < this.min.y || point.y > this.max.y ||
  2439. point.z < this.min.z || point.z > this.max.z ) {
  2440. return false;
  2441. }
  2442. return true;
  2443. },
  2444. containsBox: function ( box ) {
  2445. if ( ( this.min.x <= box.min.x ) && ( box.max.x <= this.max.x ) &&
  2446. ( this.min.y <= box.min.y ) && ( box.max.y <= this.max.y ) &&
  2447. ( this.min.z <= box.min.z ) && ( box.max.z <= this.max.z ) ) {
  2448. return true;
  2449. }
  2450. return false;
  2451. },
  2452. getParameter: function ( point, optionalTarget ) {
  2453. // This can potentially have a divide by zero if the box
  2454. // has a size dimension of 0.
  2455. var result = optionalTarget || new THREE.Vector3();
  2456. return result.set(
  2457. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2458. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  2459. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  2460. );
  2461. },
  2462. intersectsBox: function ( box ) {
  2463. // using 6 splitting planes to rule out intersections.
  2464. if ( box.max.x < this.min.x || box.min.x > this.max.x ||
  2465. box.max.y < this.min.y || box.min.y > this.max.y ||
  2466. box.max.z < this.min.z || box.min.z > this.max.z ) {
  2467. return false;
  2468. }
  2469. return true;
  2470. },
  2471. intersectsSphere: ( function () {
  2472. var closestPoint;
  2473. return function intersectsSphere( sphere ) {
  2474. if ( closestPoint === undefined ) closestPoint = new THREE.Vector3();
  2475. // Find the point on the AABB closest to the sphere center.
  2476. this.clampPoint( sphere.center, closestPoint );
  2477. // If that point is inside the sphere, the AABB and sphere intersect.
  2478. return closestPoint.distanceToSquared( sphere.center ) <= ( sphere.radius * sphere.radius );
  2479. };
  2480. } )(),
  2481. intersectsPlane: function ( plane ) {
  2482. // We compute the minimum and maximum dot product values. If those values
  2483. // are on the same side (back or front) of the plane, then there is no intersection.
  2484. var min, max;
  2485. if( plane.normal.x > 0 ) {
  2486. min = plane.normal.x * this.min.x;
  2487. max = plane.normal.x * this.max.x;
  2488. } else {
  2489. min = plane.normal.x * this.max.x;
  2490. max = plane.normal.x * this.min.x;
  2491. }
  2492. if( plane.normal.y > 0 ) {
  2493. min += plane.normal.y * this.min.y;
  2494. max += plane.normal.y * this.max.y;
  2495. } else {
  2496. min += plane.normal.y * this.max.y;
  2497. max += plane.normal.y * this.min.y;
  2498. }
  2499. if( plane.normal.z > 0 ) {
  2500. min += plane.normal.z * this.min.z;
  2501. max += plane.normal.z * this.max.z;
  2502. } else {
  2503. min += plane.normal.z * this.max.z;
  2504. max += plane.normal.z * this.min.z;
  2505. }
  2506. return ( min <= plane.constant && max >= plane.constant );
  2507. },
  2508. clampPoint: function ( point, optionalTarget ) {
  2509. var result = optionalTarget || new THREE.Vector3();
  2510. return result.copy( point ).clamp( this.min, this.max );
  2511. },
  2512. distanceToPoint: function () {
  2513. var v1 = new THREE.Vector3();
  2514. return function ( point ) {
  2515. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  2516. return clampedPoint.sub( point ).length();
  2517. };
  2518. }(),
  2519. getBoundingSphere: function () {
  2520. var v1 = new THREE.Vector3();
  2521. return function ( optionalTarget ) {
  2522. var result = optionalTarget || new THREE.Sphere();
  2523. result.center = this.center();
  2524. result.radius = this.size( v1 ).length() * 0.5;
  2525. return result;
  2526. };
  2527. }(),
  2528. intersect: function ( box ) {
  2529. this.min.max( box.min );
  2530. this.max.min( box.max );
  2531. return this;
  2532. },
  2533. union: function ( box ) {
  2534. this.min.min( box.min );
  2535. this.max.max( box.max );
  2536. return this;
  2537. },
  2538. applyMatrix4: function () {
  2539. var points = [
  2540. new THREE.Vector3(),
  2541. new THREE.Vector3(),
  2542. new THREE.Vector3(),
  2543. new THREE.Vector3(),
  2544. new THREE.Vector3(),
  2545. new THREE.Vector3(),
  2546. new THREE.Vector3(),
  2547. new THREE.Vector3()
  2548. ];
  2549. return function ( matrix ) {
  2550. // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  2551. points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
  2552. points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
  2553. points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
  2554. points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
  2555. points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
  2556. points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
  2557. points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
  2558. points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
  2559. this.makeEmpty();
  2560. this.setFromPoints( points );
  2561. return this;
  2562. };
  2563. }(),
  2564. translate: function ( offset ) {
  2565. this.min.add( offset );
  2566. this.max.add( offset );
  2567. return this;
  2568. },
  2569. equals: function ( box ) {
  2570. return box.min.equals( this.min ) && box.max.equals( this.max );
  2571. }
  2572. };
  2573. // File:src/math/Matrix3.js
  2574. /**
  2575. * @author alteredq / http://alteredqualia.com/
  2576. * @author WestLangley / http://github.com/WestLangley
  2577. * @author bhouston / http://clara.io
  2578. */
  2579. THREE.Matrix3 = function () {
  2580. this.elements = new Float32Array( [
  2581. 1, 0, 0,
  2582. 0, 1, 0,
  2583. 0, 0, 1
  2584. ] );
  2585. if ( arguments.length > 0 ) {
  2586. console.error( 'THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.' );
  2587. }
  2588. };
  2589. THREE.Matrix3.prototype = {
  2590. constructor: THREE.Matrix3,
  2591. set: function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  2592. var te = this.elements;
  2593. te[ 0 ] = n11; te[ 3 ] = n12; te[ 6 ] = n13;
  2594. te[ 1 ] = n21; te[ 4 ] = n22; te[ 7 ] = n23;
  2595. te[ 2 ] = n31; te[ 5 ] = n32; te[ 8 ] = n33;
  2596. return this;
  2597. },
  2598. identity: function () {
  2599. this.set(
  2600. 1, 0, 0,
  2601. 0, 1, 0,
  2602. 0, 0, 1
  2603. );
  2604. return this;
  2605. },
  2606. clone: function () {
  2607. return new this.constructor().fromArray( this.elements );
  2608. },
  2609. copy: function ( m ) {
  2610. var me = m.elements;
  2611. this.set(
  2612. me[ 0 ], me[ 3 ], me[ 6 ],
  2613. me[ 1 ], me[ 4 ], me[ 7 ],
  2614. me[ 2 ], me[ 5 ], me[ 8 ]
  2615. );
  2616. return this;
  2617. },
  2618. applyToVector3Array: function () {
  2619. var v1;
  2620. return function ( array, offset, length ) {
  2621. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2622. if ( offset === undefined ) offset = 0;
  2623. if ( length === undefined ) length = array.length;
  2624. for ( var i = 0, j = offset; i < length; i += 3, j += 3 ) {
  2625. v1.fromArray( array, j );
  2626. v1.applyMatrix3( this );
  2627. v1.toArray( array, j );
  2628. }
  2629. return array;
  2630. };
  2631. }(),
  2632. applyToBuffer: function () {
  2633. var v1;
  2634. return function applyToBuffer( buffer, offset, length ) {
  2635. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2636. if ( offset === undefined ) offset = 0;
  2637. if ( length === undefined ) length = buffer.length / buffer.itemSize;
  2638. for ( var i = 0, j = offset; i < length; i ++, j ++ ) {
  2639. v1.x = buffer.getX( j );
  2640. v1.y = buffer.getY( j );
  2641. v1.z = buffer.getZ( j );
  2642. v1.applyMatrix3( this );
  2643. buffer.setXYZ( v1.x, v1.y, v1.z );
  2644. }
  2645. return buffer;
  2646. };
  2647. }(),
  2648. multiplyScalar: function ( s ) {
  2649. var te = this.elements;
  2650. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  2651. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  2652. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  2653. return this;
  2654. },
  2655. determinant: function () {
  2656. var te = this.elements;
  2657. var a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  2658. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  2659. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  2660. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  2661. },
  2662. getInverse: function ( matrix, throwOnInvertible ) {
  2663. // input: THREE.Matrix4
  2664. // ( based on http://code.google.com/p/webgl-mjs/ )
  2665. var me = matrix.elements;
  2666. var te = this.elements;
  2667. te[ 0 ] = me[ 10 ] * me[ 5 ] - me[ 6 ] * me[ 9 ];
  2668. te[ 1 ] = - me[ 10 ] * me[ 1 ] + me[ 2 ] * me[ 9 ];
  2669. te[ 2 ] = me[ 6 ] * me[ 1 ] - me[ 2 ] * me[ 5 ];
  2670. te[ 3 ] = - me[ 10 ] * me[ 4 ] + me[ 6 ] * me[ 8 ];
  2671. te[ 4 ] = me[ 10 ] * me[ 0 ] - me[ 2 ] * me[ 8 ];
  2672. te[ 5 ] = - me[ 6 ] * me[ 0 ] + me[ 2 ] * me[ 4 ];
  2673. te[ 6 ] = me[ 9 ] * me[ 4 ] - me[ 5 ] * me[ 8 ];
  2674. te[ 7 ] = - me[ 9 ] * me[ 0 ] + me[ 1 ] * me[ 8 ];
  2675. te[ 8 ] = me[ 5 ] * me[ 0 ] - me[ 1 ] * me[ 4 ];
  2676. var det = me[ 0 ] * te[ 0 ] + me[ 1 ] * te[ 3 ] + me[ 2 ] * te[ 6 ];
  2677. // no inverse
  2678. if ( det === 0 ) {
  2679. var msg = "THREE.Matrix3.getInverse(): can't invert matrix, determinant is 0";
  2680. if ( throwOnInvertible || false ) {
  2681. throw new Error( msg );
  2682. } else {
  2683. console.warn( msg );
  2684. }
  2685. this.identity();
  2686. return this;
  2687. }
  2688. this.multiplyScalar( 1.0 / det );
  2689. return this;
  2690. },
  2691. transpose: function () {
  2692. var tmp, m = this.elements;
  2693. tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
  2694. tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
  2695. tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
  2696. return this;
  2697. },
  2698. flattenToArrayOffset: function ( array, offset ) {
  2699. var te = this.elements;
  2700. array[ offset ] = te[ 0 ];
  2701. array[ offset + 1 ] = te[ 1 ];
  2702. array[ offset + 2 ] = te[ 2 ];
  2703. array[ offset + 3 ] = te[ 3 ];
  2704. array[ offset + 4 ] = te[ 4 ];
  2705. array[ offset + 5 ] = te[ 5 ];
  2706. array[ offset + 6 ] = te[ 6 ];
  2707. array[ offset + 7 ] = te[ 7 ];
  2708. array[ offset + 8 ] = te[ 8 ];
  2709. return array;
  2710. },
  2711. getNormalMatrix: function ( m ) {
  2712. // input: THREE.Matrix4
  2713. this.getInverse( m ).transpose();
  2714. return this;
  2715. },
  2716. transposeIntoArray: function ( r ) {
  2717. var m = this.elements;
  2718. r[ 0 ] = m[ 0 ];
  2719. r[ 1 ] = m[ 3 ];
  2720. r[ 2 ] = m[ 6 ];
  2721. r[ 3 ] = m[ 1 ];
  2722. r[ 4 ] = m[ 4 ];
  2723. r[ 5 ] = m[ 7 ];
  2724. r[ 6 ] = m[ 2 ];
  2725. r[ 7 ] = m[ 5 ];
  2726. r[ 8 ] = m[ 8 ];
  2727. return this;
  2728. },
  2729. fromArray: function ( array ) {
  2730. this.elements.set( array );
  2731. return this;
  2732. },
  2733. toArray: function () {
  2734. var te = this.elements;
  2735. return [
  2736. te[ 0 ], te[ 1 ], te[ 2 ],
  2737. te[ 3 ], te[ 4 ], te[ 5 ],
  2738. te[ 6 ], te[ 7 ], te[ 8 ]
  2739. ];
  2740. }
  2741. };
  2742. // File:src/math/Matrix4.js
  2743. /**
  2744. * @author mrdoob / http://mrdoob.com/
  2745. * @author supereggbert / http://www.paulbrunt.co.uk/
  2746. * @author philogb / http://blog.thejit.org/
  2747. * @author jordi_ros / http://plattsoft.com
  2748. * @author D1plo1d / http://github.com/D1plo1d
  2749. * @author alteredq / http://alteredqualia.com/
  2750. * @author mikael emtinger / http://gomo.se/
  2751. * @author timknip / http://www.floorplanner.com/
  2752. * @author bhouston / http://clara.io
  2753. * @author WestLangley / http://github.com/WestLangley
  2754. */
  2755. THREE.Matrix4 = function () {
  2756. this.elements = new Float32Array( [
  2757. 1, 0, 0, 0,
  2758. 0, 1, 0, 0,
  2759. 0, 0, 1, 0,
  2760. 0, 0, 0, 1
  2761. ] );
  2762. if ( arguments.length > 0 ) {
  2763. console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' );
  2764. }
  2765. };
  2766. THREE.Matrix4.prototype = {
  2767. constructor: THREE.Matrix4,
  2768. set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  2769. var te = this.elements;
  2770. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  2771. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  2772. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  2773. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  2774. return this;
  2775. },
  2776. identity: function () {
  2777. this.set(
  2778. 1, 0, 0, 0,
  2779. 0, 1, 0, 0,
  2780. 0, 0, 1, 0,
  2781. 0, 0, 0, 1
  2782. );
  2783. return this;
  2784. },
  2785. clone: function () {
  2786. return new THREE.Matrix4().fromArray( this.elements );
  2787. },
  2788. copy: function ( m ) {
  2789. this.elements.set( m.elements );
  2790. return this;
  2791. },
  2792. copyPosition: function ( m ) {
  2793. var te = this.elements;
  2794. var me = m.elements;
  2795. te[ 12 ] = me[ 12 ];
  2796. te[ 13 ] = me[ 13 ];
  2797. te[ 14 ] = me[ 14 ];
  2798. return this;
  2799. },
  2800. extractBasis: function ( xAxis, yAxis, zAxis ) {
  2801. var te = this.elements;
  2802. xAxis.set( te[ 0 ], te[ 1 ], te[ 2 ] );
  2803. yAxis.set( te[ 4 ], te[ 5 ], te[ 6 ] );
  2804. zAxis.set( te[ 8 ], te[ 9 ], te[ 10 ] );
  2805. return this;
  2806. },
  2807. makeBasis: function ( xAxis, yAxis, zAxis ) {
  2808. this.set(
  2809. xAxis.x, yAxis.x, zAxis.x, 0,
  2810. xAxis.y, yAxis.y, zAxis.y, 0,
  2811. xAxis.z, yAxis.z, zAxis.z, 0,
  2812. 0, 0, 0, 1
  2813. );
  2814. return this;
  2815. },
  2816. extractRotation: function () {
  2817. var v1;
  2818. return function ( m ) {
  2819. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2820. var te = this.elements;
  2821. var me = m.elements;
  2822. var scaleX = 1 / v1.set( me[ 0 ], me[ 1 ], me[ 2 ] ).length();
  2823. var scaleY = 1 / v1.set( me[ 4 ], me[ 5 ], me[ 6 ] ).length();
  2824. var scaleZ = 1 / v1.set( me[ 8 ], me[ 9 ], me[ 10 ] ).length();
  2825. te[ 0 ] = me[ 0 ] * scaleX;
  2826. te[ 1 ] = me[ 1 ] * scaleX;
  2827. te[ 2 ] = me[ 2 ] * scaleX;
  2828. te[ 4 ] = me[ 4 ] * scaleY;
  2829. te[ 5 ] = me[ 5 ] * scaleY;
  2830. te[ 6 ] = me[ 6 ] * scaleY;
  2831. te[ 8 ] = me[ 8 ] * scaleZ;
  2832. te[ 9 ] = me[ 9 ] * scaleZ;
  2833. te[ 10 ] = me[ 10 ] * scaleZ;
  2834. return this;
  2835. };
  2836. }(),
  2837. makeRotationFromEuler: function ( euler ) {
  2838. if ( euler instanceof THREE.Euler === false ) {
  2839. console.error( 'THREE.Matrix: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  2840. }
  2841. var te = this.elements;
  2842. var x = euler.x, y = euler.y, z = euler.z;
  2843. var a = Math.cos( x ), b = Math.sin( x );
  2844. var c = Math.cos( y ), d = Math.sin( y );
  2845. var e = Math.cos( z ), f = Math.sin( z );
  2846. if ( euler.order === 'XYZ' ) {
  2847. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2848. te[ 0 ] = c * e;
  2849. te[ 4 ] = - c * f;
  2850. te[ 8 ] = d;
  2851. te[ 1 ] = af + be * d;
  2852. te[ 5 ] = ae - bf * d;
  2853. te[ 9 ] = - b * c;
  2854. te[ 2 ] = bf - ae * d;
  2855. te[ 6 ] = be + af * d;
  2856. te[ 10 ] = a * c;
  2857. } else if ( euler.order === 'YXZ' ) {
  2858. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2859. te[ 0 ] = ce + df * b;
  2860. te[ 4 ] = de * b - cf;
  2861. te[ 8 ] = a * d;
  2862. te[ 1 ] = a * f;
  2863. te[ 5 ] = a * e;
  2864. te[ 9 ] = - b;
  2865. te[ 2 ] = cf * b - de;
  2866. te[ 6 ] = df + ce * b;
  2867. te[ 10 ] = a * c;
  2868. } else if ( euler.order === 'ZXY' ) {
  2869. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2870. te[ 0 ] = ce - df * b;
  2871. te[ 4 ] = - a * f;
  2872. te[ 8 ] = de + cf * b;
  2873. te[ 1 ] = cf + de * b;
  2874. te[ 5 ] = a * e;
  2875. te[ 9 ] = df - ce * b;
  2876. te[ 2 ] = - a * d;
  2877. te[ 6 ] = b;
  2878. te[ 10 ] = a * c;
  2879. } else if ( euler.order === 'ZYX' ) {
  2880. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2881. te[ 0 ] = c * e;
  2882. te[ 4 ] = be * d - af;
  2883. te[ 8 ] = ae * d + bf;
  2884. te[ 1 ] = c * f;
  2885. te[ 5 ] = bf * d + ae;
  2886. te[ 9 ] = af * d - be;
  2887. te[ 2 ] = - d;
  2888. te[ 6 ] = b * c;
  2889. te[ 10 ] = a * c;
  2890. } else if ( euler.order === 'YZX' ) {
  2891. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2892. te[ 0 ] = c * e;
  2893. te[ 4 ] = bd - ac * f;
  2894. te[ 8 ] = bc * f + ad;
  2895. te[ 1 ] = f;
  2896. te[ 5 ] = a * e;
  2897. te[ 9 ] = - b * e;
  2898. te[ 2 ] = - d * e;
  2899. te[ 6 ] = ad * f + bc;
  2900. te[ 10 ] = ac - bd * f;
  2901. } else if ( euler.order === 'XZY' ) {
  2902. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2903. te[ 0 ] = c * e;
  2904. te[ 4 ] = - f;
  2905. te[ 8 ] = d * e;
  2906. te[ 1 ] = ac * f + bd;
  2907. te[ 5 ] = a * e;
  2908. te[ 9 ] = ad * f - bc;
  2909. te[ 2 ] = bc * f - ad;
  2910. te[ 6 ] = b * e;
  2911. te[ 10 ] = bd * f + ac;
  2912. }
  2913. // last column
  2914. te[ 3 ] = 0;
  2915. te[ 7 ] = 0;
  2916. te[ 11 ] = 0;
  2917. // bottom row
  2918. te[ 12 ] = 0;
  2919. te[ 13 ] = 0;
  2920. te[ 14 ] = 0;
  2921. te[ 15 ] = 1;
  2922. return this;
  2923. },
  2924. makeRotationFromQuaternion: function ( q ) {
  2925. var te = this.elements;
  2926. var x = q.x, y = q.y, z = q.z, w = q.w;
  2927. var x2 = x + x, y2 = y + y, z2 = z + z;
  2928. var xx = x * x2, xy = x * y2, xz = x * z2;
  2929. var yy = y * y2, yz = y * z2, zz = z * z2;
  2930. var wx = w * x2, wy = w * y2, wz = w * z2;
  2931. te[ 0 ] = 1 - ( yy + zz );
  2932. te[ 4 ] = xy - wz;
  2933. te[ 8 ] = xz + wy;
  2934. te[ 1 ] = xy + wz;
  2935. te[ 5 ] = 1 - ( xx + zz );
  2936. te[ 9 ] = yz - wx;
  2937. te[ 2 ] = xz - wy;
  2938. te[ 6 ] = yz + wx;
  2939. te[ 10 ] = 1 - ( xx + yy );
  2940. // last column
  2941. te[ 3 ] = 0;
  2942. te[ 7 ] = 0;
  2943. te[ 11 ] = 0;
  2944. // bottom row
  2945. te[ 12 ] = 0;
  2946. te[ 13 ] = 0;
  2947. te[ 14 ] = 0;
  2948. te[ 15 ] = 1;
  2949. return this;
  2950. },
  2951. lookAt: function () {
  2952. var x, y, z;
  2953. return function ( eye, target, up ) {
  2954. if ( x === undefined ) x = new THREE.Vector3();
  2955. if ( y === undefined ) y = new THREE.Vector3();
  2956. if ( z === undefined ) z = new THREE.Vector3();
  2957. var te = this.elements;
  2958. z.subVectors( eye, target ).normalize();
  2959. if ( z.lengthSq() === 0 ) {
  2960. z.z = 1;
  2961. }
  2962. x.crossVectors( up, z ).normalize();
  2963. if ( x.lengthSq() === 0 ) {
  2964. z.x += 0.0001;
  2965. x.crossVectors( up, z ).normalize();
  2966. }
  2967. y.crossVectors( z, x );
  2968. te[ 0 ] = x.x; te[ 4 ] = y.x; te[ 8 ] = z.x;
  2969. te[ 1 ] = x.y; te[ 5 ] = y.y; te[ 9 ] = z.y;
  2970. te[ 2 ] = x.z; te[ 6 ] = y.z; te[ 10 ] = z.z;
  2971. return this;
  2972. };
  2973. }(),
  2974. multiply: function ( m, n ) {
  2975. if ( n !== undefined ) {
  2976. console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' );
  2977. return this.multiplyMatrices( m, n );
  2978. }
  2979. return this.multiplyMatrices( this, m );
  2980. },
  2981. multiplyMatrices: function ( a, b ) {
  2982. var ae = a.elements;
  2983. var be = b.elements;
  2984. var te = this.elements;
  2985. var a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  2986. var a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  2987. var a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  2988. var a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  2989. var b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  2990. var b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  2991. var b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  2992. var b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  2993. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  2994. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  2995. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  2996. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  2997. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  2998. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  2999. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  3000. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  3001. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  3002. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  3003. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  3004. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  3005. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  3006. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  3007. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  3008. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  3009. return this;
  3010. },
  3011. multiplyToArray: function ( a, b, r ) {
  3012. var te = this.elements;
  3013. this.multiplyMatrices( a, b );
  3014. r[ 0 ] = te[ 0 ]; r[ 1 ] = te[ 1 ]; r[ 2 ] = te[ 2 ]; r[ 3 ] = te[ 3 ];
  3015. r[ 4 ] = te[ 4 ]; r[ 5 ] = te[ 5 ]; r[ 6 ] = te[ 6 ]; r[ 7 ] = te[ 7 ];
  3016. r[ 8 ] = te[ 8 ]; r[ 9 ] = te[ 9 ]; r[ 10 ] = te[ 10 ]; r[ 11 ] = te[ 11 ];
  3017. r[ 12 ] = te[ 12 ]; r[ 13 ] = te[ 13 ]; r[ 14 ] = te[ 14 ]; r[ 15 ] = te[ 15 ];
  3018. return this;
  3019. },
  3020. multiplyScalar: function ( s ) {
  3021. var te = this.elements;
  3022. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  3023. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  3024. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  3025. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  3026. return this;
  3027. },
  3028. applyToVector3Array: function () {
  3029. var v1;
  3030. return function ( array, offset, length ) {
  3031. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3032. if ( offset === undefined ) offset = 0;
  3033. if ( length === undefined ) length = array.length;
  3034. for ( var i = 0, j = offset; i < length; i += 3, j += 3 ) {
  3035. v1.fromArray( array, j );
  3036. v1.applyMatrix4( this );
  3037. v1.toArray( array, j );
  3038. }
  3039. return array;
  3040. };
  3041. }(),
  3042. applyToBuffer: function () {
  3043. var v1;
  3044. return function applyToBuffer( buffer, offset, length ) {
  3045. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3046. if ( offset === undefined ) offset = 0;
  3047. if ( length === undefined ) length = buffer.length / buffer.itemSize;
  3048. for ( var i = 0, j = offset; i < length; i ++, j ++ ) {
  3049. v1.x = buffer.getX( j );
  3050. v1.y = buffer.getY( j );
  3051. v1.z = buffer.getZ( j );
  3052. v1.applyMatrix4( this );
  3053. buffer.setXYZ( v1.x, v1.y, v1.z );
  3054. }
  3055. return buffer;
  3056. };
  3057. }(),
  3058. determinant: function () {
  3059. var te = this.elements;
  3060. var n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  3061. var n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  3062. var n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  3063. var n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  3064. //TODO: make this more efficient
  3065. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  3066. return (
  3067. n41 * (
  3068. + n14 * n23 * n32
  3069. - n13 * n24 * n32
  3070. - n14 * n22 * n33
  3071. + n12 * n24 * n33
  3072. + n13 * n22 * n34
  3073. - n12 * n23 * n34
  3074. ) +
  3075. n42 * (
  3076. + n11 * n23 * n34
  3077. - n11 * n24 * n33
  3078. + n14 * n21 * n33
  3079. - n13 * n21 * n34
  3080. + n13 * n24 * n31
  3081. - n14 * n23 * n31
  3082. ) +
  3083. n43 * (
  3084. + n11 * n24 * n32
  3085. - n11 * n22 * n34
  3086. - n14 * n21 * n32
  3087. + n12 * n21 * n34
  3088. + n14 * n22 * n31
  3089. - n12 * n24 * n31
  3090. ) +
  3091. n44 * (
  3092. - n13 * n22 * n31
  3093. - n11 * n23 * n32
  3094. + n11 * n22 * n33
  3095. + n13 * n21 * n32
  3096. - n12 * n21 * n33
  3097. + n12 * n23 * n31
  3098. )
  3099. );
  3100. },
  3101. transpose: function () {
  3102. var te = this.elements;
  3103. var tmp;
  3104. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  3105. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  3106. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  3107. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  3108. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  3109. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  3110. return this;
  3111. },
  3112. flattenToArrayOffset: function ( array, offset ) {
  3113. var te = this.elements;
  3114. array[ offset ] = te[ 0 ];
  3115. array[ offset + 1 ] = te[ 1 ];
  3116. array[ offset + 2 ] = te[ 2 ];
  3117. array[ offset + 3 ] = te[ 3 ];
  3118. array[ offset + 4 ] = te[ 4 ];
  3119. array[ offset + 5 ] = te[ 5 ];
  3120. array[ offset + 6 ] = te[ 6 ];
  3121. array[ offset + 7 ] = te[ 7 ];
  3122. array[ offset + 8 ] = te[ 8 ];
  3123. array[ offset + 9 ] = te[ 9 ];
  3124. array[ offset + 10 ] = te[ 10 ];
  3125. array[ offset + 11 ] = te[ 11 ];
  3126. array[ offset + 12 ] = te[ 12 ];
  3127. array[ offset + 13 ] = te[ 13 ];
  3128. array[ offset + 14 ] = te[ 14 ];
  3129. array[ offset + 15 ] = te[ 15 ];
  3130. return array;
  3131. },
  3132. getPosition: function () {
  3133. var v1;
  3134. return function () {
  3135. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3136. console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
  3137. var te = this.elements;
  3138. return v1.set( te[ 12 ], te[ 13 ], te[ 14 ] );
  3139. };
  3140. }(),
  3141. setPosition: function ( v ) {
  3142. var te = this.elements;
  3143. te[ 12 ] = v.x;
  3144. te[ 13 ] = v.y;
  3145. te[ 14 ] = v.z;
  3146. return this;
  3147. },
  3148. getInverse: function ( m, throwOnInvertible ) {
  3149. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  3150. var te = this.elements;
  3151. var me = m.elements;
  3152. var n11 = me[ 0 ], n12 = me[ 4 ], n13 = me[ 8 ], n14 = me[ 12 ];
  3153. var n21 = me[ 1 ], n22 = me[ 5 ], n23 = me[ 9 ], n24 = me[ 13 ];
  3154. var n31 = me[ 2 ], n32 = me[ 6 ], n33 = me[ 10 ], n34 = me[ 14 ];
  3155. var n41 = me[ 3 ], n42 = me[ 7 ], n43 = me[ 11 ], n44 = me[ 15 ];
  3156. te[ 0 ] = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44;
  3157. te[ 4 ] = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44;
  3158. te[ 8 ] = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44;
  3159. te[ 12 ] = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  3160. te[ 1 ] = n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44;
  3161. te[ 5 ] = n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44;
  3162. te[ 9 ] = n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44;
  3163. te[ 13 ] = n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34;
  3164. te[ 2 ] = n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44;
  3165. te[ 6 ] = n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44;
  3166. te[ 10 ] = n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44;
  3167. te[ 14 ] = n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34;
  3168. te[ 3 ] = n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43;
  3169. te[ 7 ] = n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43;
  3170. te[ 11 ] = n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43;
  3171. te[ 15 ] = n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33;
  3172. var det = n11 * te[ 0 ] + n21 * te[ 4 ] + n31 * te[ 8 ] + n41 * te[ 12 ];
  3173. if ( det === 0 ) {
  3174. var msg = "THREE.Matrix4.getInverse(): can't invert matrix, determinant is 0";
  3175. if ( throwOnInvertible || false ) {
  3176. throw new Error( msg );
  3177. } else {
  3178. console.warn( msg );
  3179. }
  3180. this.identity();
  3181. return this;
  3182. }
  3183. this.multiplyScalar( 1 / det );
  3184. return this;
  3185. },
  3186. scale: function ( v ) {
  3187. var te = this.elements;
  3188. var x = v.x, y = v.y, z = v.z;
  3189. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  3190. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  3191. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  3192. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  3193. return this;
  3194. },
  3195. getMaxScaleOnAxis: function () {
  3196. var te = this.elements;
  3197. var scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  3198. var scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  3199. var scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  3200. return Math.sqrt( Math.max( scaleXSq, scaleYSq, scaleZSq ) );
  3201. },
  3202. makeTranslation: function ( x, y, z ) {
  3203. this.set(
  3204. 1, 0, 0, x,
  3205. 0, 1, 0, y,
  3206. 0, 0, 1, z,
  3207. 0, 0, 0, 1
  3208. );
  3209. return this;
  3210. },
  3211. makeRotationX: function ( theta ) {
  3212. var c = Math.cos( theta ), s = Math.sin( theta );
  3213. this.set(
  3214. 1, 0, 0, 0,
  3215. 0, c, - s, 0,
  3216. 0, s, c, 0,
  3217. 0, 0, 0, 1
  3218. );
  3219. return this;
  3220. },
  3221. makeRotationY: function ( theta ) {
  3222. var c = Math.cos( theta ), s = Math.sin( theta );
  3223. this.set(
  3224. c, 0, s, 0,
  3225. 0, 1, 0, 0,
  3226. - s, 0, c, 0,
  3227. 0, 0, 0, 1
  3228. );
  3229. return this;
  3230. },
  3231. makeRotationZ: function ( theta ) {
  3232. var c = Math.cos( theta ), s = Math.sin( theta );
  3233. this.set(
  3234. c, - s, 0, 0,
  3235. s, c, 0, 0,
  3236. 0, 0, 1, 0,
  3237. 0, 0, 0, 1
  3238. );
  3239. return this;
  3240. },
  3241. makeRotationAxis: function ( axis, angle ) {
  3242. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  3243. var c = Math.cos( angle );
  3244. var s = Math.sin( angle );
  3245. var t = 1 - c;
  3246. var x = axis.x, y = axis.y, z = axis.z;
  3247. var tx = t * x, ty = t * y;
  3248. this.set(
  3249. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  3250. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  3251. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  3252. 0, 0, 0, 1
  3253. );
  3254. return this;
  3255. },
  3256. makeScale: function ( x, y, z ) {
  3257. this.set(
  3258. x, 0, 0, 0,
  3259. 0, y, 0, 0,
  3260. 0, 0, z, 0,
  3261. 0, 0, 0, 1
  3262. );
  3263. return this;
  3264. },
  3265. compose: function ( position, quaternion, scale ) {
  3266. this.makeRotationFromQuaternion( quaternion );
  3267. this.scale( scale );
  3268. this.setPosition( position );
  3269. return this;
  3270. },
  3271. decompose: function () {
  3272. var vector, matrix;
  3273. return function ( position, quaternion, scale ) {
  3274. if ( vector === undefined ) vector = new THREE.Vector3();
  3275. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  3276. var te = this.elements;
  3277. var sx = vector.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  3278. var sy = vector.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  3279. var sz = vector.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  3280. // if determine is negative, we need to invert one scale
  3281. var det = this.determinant();
  3282. if ( det < 0 ) {
  3283. sx = - sx;
  3284. }
  3285. position.x = te[ 12 ];
  3286. position.y = te[ 13 ];
  3287. position.z = te[ 14 ];
  3288. // scale the rotation part
  3289. matrix.elements.set( this.elements ); // at this point matrix is incomplete so we can't use .copy()
  3290. var invSX = 1 / sx;
  3291. var invSY = 1 / sy;
  3292. var invSZ = 1 / sz;
  3293. matrix.elements[ 0 ] *= invSX;
  3294. matrix.elements[ 1 ] *= invSX;
  3295. matrix.elements[ 2 ] *= invSX;
  3296. matrix.elements[ 4 ] *= invSY;
  3297. matrix.elements[ 5 ] *= invSY;
  3298. matrix.elements[ 6 ] *= invSY;
  3299. matrix.elements[ 8 ] *= invSZ;
  3300. matrix.elements[ 9 ] *= invSZ;
  3301. matrix.elements[ 10 ] *= invSZ;
  3302. quaternion.setFromRotationMatrix( matrix );
  3303. scale.x = sx;
  3304. scale.y = sy;
  3305. scale.z = sz;
  3306. return this;
  3307. };
  3308. }(),
  3309. makeFrustum: function ( left, right, bottom, top, near, far ) {
  3310. var te = this.elements;
  3311. var x = 2 * near / ( right - left );
  3312. var y = 2 * near / ( top - bottom );
  3313. var a = ( right + left ) / ( right - left );
  3314. var b = ( top + bottom ) / ( top - bottom );
  3315. var c = - ( far + near ) / ( far - near );
  3316. var d = - 2 * far * near / ( far - near );
  3317. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  3318. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  3319. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  3320. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  3321. return this;
  3322. },
  3323. makePerspective: function ( fov, aspect, near, far ) {
  3324. var ymax = near * Math.tan( THREE.Math.degToRad( fov * 0.5 ) );
  3325. var ymin = - ymax;
  3326. var xmin = ymin * aspect;
  3327. var xmax = ymax * aspect;
  3328. return this.makeFrustum( xmin, xmax, ymin, ymax, near, far );
  3329. },
  3330. makeOrthographic: function ( left, right, top, bottom, near, far ) {
  3331. var te = this.elements;
  3332. var w = right - left;
  3333. var h = top - bottom;
  3334. var p = far - near;
  3335. var x = ( right + left ) / w;
  3336. var y = ( top + bottom ) / h;
  3337. var z = ( far + near ) / p;
  3338. te[ 0 ] = 2 / w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  3339. te[ 1 ] = 0; te[ 5 ] = 2 / h; te[ 9 ] = 0; te[ 13 ] = - y;
  3340. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 / p; te[ 14 ] = - z;
  3341. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  3342. return this;
  3343. },
  3344. equals: function ( matrix ) {
  3345. var te = this.elements;
  3346. var me = matrix.elements;
  3347. for ( var i = 0; i < 16; i ++ ) {
  3348. if ( te[ i ] !== me[ i ] ) return false;
  3349. }
  3350. return true;
  3351. },
  3352. fromArray: function ( array ) {
  3353. this.elements.set( array );
  3354. return this;
  3355. },
  3356. toArray: function () {
  3357. var te = this.elements;
  3358. return [
  3359. te[ 0 ], te[ 1 ], te[ 2 ], te[ 3 ],
  3360. te[ 4 ], te[ 5 ], te[ 6 ], te[ 7 ],
  3361. te[ 8 ], te[ 9 ], te[ 10 ], te[ 11 ],
  3362. te[ 12 ], te[ 13 ], te[ 14 ], te[ 15 ]
  3363. ];
  3364. }
  3365. };
  3366. // File:src/math/Ray.js
  3367. /**
  3368. * @author bhouston / http://clara.io
  3369. */
  3370. THREE.Ray = function ( origin, direction ) {
  3371. this.origin = ( origin !== undefined ) ? origin : new THREE.Vector3();
  3372. this.direction = ( direction !== undefined ) ? direction : new THREE.Vector3();
  3373. };
  3374. THREE.Ray.prototype = {
  3375. constructor: THREE.Ray,
  3376. set: function ( origin, direction ) {
  3377. this.origin.copy( origin );
  3378. this.direction.copy( direction );
  3379. return this;
  3380. },
  3381. clone: function () {
  3382. return new this.constructor().copy( this );
  3383. },
  3384. copy: function ( ray ) {
  3385. this.origin.copy( ray.origin );
  3386. this.direction.copy( ray.direction );
  3387. return this;
  3388. },
  3389. at: function ( t, optionalTarget ) {
  3390. var result = optionalTarget || new THREE.Vector3();
  3391. return result.copy( this.direction ).multiplyScalar( t ).add( this.origin );
  3392. },
  3393. recast: function () {
  3394. var v1 = new THREE.Vector3();
  3395. return function ( t ) {
  3396. this.origin.copy( this.at( t, v1 ) );
  3397. return this;
  3398. };
  3399. }(),
  3400. closestPointToPoint: function ( point, optionalTarget ) {
  3401. var result = optionalTarget || new THREE.Vector3();
  3402. result.subVectors( point, this.origin );
  3403. var directionDistance = result.dot( this.direction );
  3404. if ( directionDistance < 0 ) {
  3405. return result.copy( this.origin );
  3406. }
  3407. return result.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  3408. },
  3409. distanceToPoint: function ( point ) {
  3410. return Math.sqrt( this.distanceSqToPoint( point ) );
  3411. },
  3412. distanceSqToPoint: function () {
  3413. var v1 = new THREE.Vector3();
  3414. return function ( point ) {
  3415. var directionDistance = v1.subVectors( point, this.origin ).dot( this.direction );
  3416. // point behind the ray
  3417. if ( directionDistance < 0 ) {
  3418. return this.origin.distanceToSquared( point );
  3419. }
  3420. v1.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  3421. return v1.distanceToSquared( point );
  3422. };
  3423. }(),
  3424. distanceSqToSegment: function () {
  3425. var segCenter = new THREE.Vector3();
  3426. var segDir = new THREE.Vector3();
  3427. var diff = new THREE.Vector3();
  3428. return function ( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  3429. // from http://www.geometrictools.com/LibMathematics/Distance/Wm5DistRay3Segment3.cpp
  3430. // It returns the min distance between the ray and the segment
  3431. // defined by v0 and v1
  3432. // It can also set two optional targets :
  3433. // - The closest point on the ray
  3434. // - The closest point on the segment
  3435. segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  3436. segDir.copy( v1 ).sub( v0 ).normalize();
  3437. diff.copy( this.origin ).sub( segCenter );
  3438. var segExtent = v0.distanceTo( v1 ) * 0.5;
  3439. var a01 = - this.direction.dot( segDir );
  3440. var b0 = diff.dot( this.direction );
  3441. var b1 = - diff.dot( segDir );
  3442. var c = diff.lengthSq();
  3443. var det = Math.abs( 1 - a01 * a01 );
  3444. var s0, s1, sqrDist, extDet;
  3445. if ( det > 0 ) {
  3446. // The ray and segment are not parallel.
  3447. s0 = a01 * b1 - b0;
  3448. s1 = a01 * b0 - b1;
  3449. extDet = segExtent * det;
  3450. if ( s0 >= 0 ) {
  3451. if ( s1 >= - extDet ) {
  3452. if ( s1 <= extDet ) {
  3453. // region 0
  3454. // Minimum at interior points of ray and segment.
  3455. var invDet = 1 / det;
  3456. s0 *= invDet;
  3457. s1 *= invDet;
  3458. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  3459. } else {
  3460. // region 1
  3461. s1 = segExtent;
  3462. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3463. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3464. }
  3465. } else {
  3466. // region 5
  3467. s1 = - segExtent;
  3468. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3469. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3470. }
  3471. } else {
  3472. if ( s1 <= - extDet ) {
  3473. // region 4
  3474. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  3475. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3476. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3477. } else if ( s1 <= extDet ) {
  3478. // region 3
  3479. s0 = 0;
  3480. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3481. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  3482. } else {
  3483. // region 2
  3484. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  3485. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3486. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3487. }
  3488. }
  3489. } else {
  3490. // Ray and segment are parallel.
  3491. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  3492. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3493. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3494. }
  3495. if ( optionalPointOnRay ) {
  3496. optionalPointOnRay.copy( this.direction ).multiplyScalar( s0 ).add( this.origin );
  3497. }
  3498. if ( optionalPointOnSegment ) {
  3499. optionalPointOnSegment.copy( segDir ).multiplyScalar( s1 ).add( segCenter );
  3500. }
  3501. return sqrDist;
  3502. };
  3503. }(),
  3504. intersectSphere: function () {
  3505. // from http://www.scratchapixel.com/lessons/3d-basic-lessons/lesson-7-intersecting-simple-shapes/ray-sphere-intersection/
  3506. var v1 = new THREE.Vector3();
  3507. return function ( sphere, optionalTarget ) {
  3508. v1.subVectors( sphere.center, this.origin );
  3509. var tca = v1.dot( this.direction );
  3510. var d2 = v1.dot( v1 ) - tca * tca;
  3511. var radius2 = sphere.radius * sphere.radius;
  3512. if ( d2 > radius2 ) return null;
  3513. var thc = Math.sqrt( radius2 - d2 );
  3514. // t0 = first intersect point - entrance on front of sphere
  3515. var t0 = tca - thc;
  3516. // t1 = second intersect point - exit point on back of sphere
  3517. var t1 = tca + thc;
  3518. // test to see if both t0 and t1 are behind the ray - if so, return null
  3519. if ( t0 < 0 && t1 < 0 ) return null;
  3520. // test to see if t0 is behind the ray:
  3521. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  3522. // in order to always return an intersect point that is in front of the ray.
  3523. if ( t0 < 0 ) return this.at( t1, optionalTarget );
  3524. // else t0 is in front of the ray, so return the first collision point scaled by t0
  3525. return this.at( t0, optionalTarget );
  3526. }
  3527. }(),
  3528. intersectsSphere: function ( sphere ) {
  3529. return this.distanceToPoint( sphere.center ) <= sphere.radius;
  3530. },
  3531. distanceToPlane: function ( plane ) {
  3532. var denominator = plane.normal.dot( this.direction );
  3533. if ( denominator === 0 ) {
  3534. // line is coplanar, return origin
  3535. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  3536. return 0;
  3537. }
  3538. // Null is preferable to undefined since undefined means.... it is undefined
  3539. return null;
  3540. }
  3541. var t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  3542. // Return if the ray never intersects the plane
  3543. return t >= 0 ? t : null;
  3544. },
  3545. intersectPlane: function ( plane, optionalTarget ) {
  3546. var t = this.distanceToPlane( plane );
  3547. if ( t === null ) {
  3548. return null;
  3549. }
  3550. return this.at( t, optionalTarget );
  3551. },
  3552. intersectsPlane: function ( plane ) {
  3553. // check if the ray lies on the plane first
  3554. var distToPoint = plane.distanceToPoint( this.origin );
  3555. if ( distToPoint === 0 ) {
  3556. return true;
  3557. }
  3558. var denominator = plane.normal.dot( this.direction );
  3559. if ( denominator * distToPoint < 0 ) {
  3560. return true;
  3561. }
  3562. // ray origin is behind the plane (and is pointing behind it)
  3563. return false;
  3564. },
  3565. intersectBox: function ( box, optionalTarget ) {
  3566. // http://www.scratchapixel.com/lessons/3d-basic-lessons/lesson-7-intersecting-simple-shapes/ray-box-intersection/
  3567. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  3568. var invdirx = 1 / this.direction.x,
  3569. invdiry = 1 / this.direction.y,
  3570. invdirz = 1 / this.direction.z;
  3571. var origin = this.origin;
  3572. if ( invdirx >= 0 ) {
  3573. tmin = ( box.min.x - origin.x ) * invdirx;
  3574. tmax = ( box.max.x - origin.x ) * invdirx;
  3575. } else {
  3576. tmin = ( box.max.x - origin.x ) * invdirx;
  3577. tmax = ( box.min.x - origin.x ) * invdirx;
  3578. }
  3579. if ( invdiry >= 0 ) {
  3580. tymin = ( box.min.y - origin.y ) * invdiry;
  3581. tymax = ( box.max.y - origin.y ) * invdiry;
  3582. } else {
  3583. tymin = ( box.max.y - origin.y ) * invdiry;
  3584. tymax = ( box.min.y - origin.y ) * invdiry;
  3585. }
  3586. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  3587. // These lines also handle the case where tmin or tmax is NaN
  3588. // (result of 0 * Infinity). x !== x returns true if x is NaN
  3589. if ( tymin > tmin || tmin !== tmin ) tmin = tymin;
  3590. if ( tymax < tmax || tmax !== tmax ) tmax = tymax;
  3591. if ( invdirz >= 0 ) {
  3592. tzmin = ( box.min.z - origin.z ) * invdirz;
  3593. tzmax = ( box.max.z - origin.z ) * invdirz;
  3594. } else {
  3595. tzmin = ( box.max.z - origin.z ) * invdirz;
  3596. tzmax = ( box.min.z - origin.z ) * invdirz;
  3597. }
  3598. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  3599. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  3600. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  3601. //return point closest to the ray (positive side)
  3602. if ( tmax < 0 ) return null;
  3603. return this.at( tmin >= 0 ? tmin : tmax, optionalTarget );
  3604. },
  3605. intersectsBox: ( function () {
  3606. var v = new THREE.Vector3();
  3607. return function ( box ) {
  3608. return this.intersectBox( box, v ) !== null;
  3609. };
  3610. } )(),
  3611. intersectTriangle: function () {
  3612. // Compute the offset origin, edges, and normal.
  3613. var diff = new THREE.Vector3();
  3614. var edge1 = new THREE.Vector3();
  3615. var edge2 = new THREE.Vector3();
  3616. var normal = new THREE.Vector3();
  3617. return function ( a, b, c, backfaceCulling, optionalTarget ) {
  3618. // from http://www.geometrictools.com/LibMathematics/Intersection/Wm5IntrRay3Triangle3.cpp
  3619. edge1.subVectors( b, a );
  3620. edge2.subVectors( c, a );
  3621. normal.crossVectors( edge1, edge2 );
  3622. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  3623. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  3624. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  3625. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  3626. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  3627. var DdN = this.direction.dot( normal );
  3628. var sign;
  3629. if ( DdN > 0 ) {
  3630. if ( backfaceCulling ) return null;
  3631. sign = 1;
  3632. } else if ( DdN < 0 ) {
  3633. sign = - 1;
  3634. DdN = - DdN;
  3635. } else {
  3636. return null;
  3637. }
  3638. diff.subVectors( this.origin, a );
  3639. var DdQxE2 = sign * this.direction.dot( edge2.crossVectors( diff, edge2 ) );
  3640. // b1 < 0, no intersection
  3641. if ( DdQxE2 < 0 ) {
  3642. return null;
  3643. }
  3644. var DdE1xQ = sign * this.direction.dot( edge1.cross( diff ) );
  3645. // b2 < 0, no intersection
  3646. if ( DdE1xQ < 0 ) {
  3647. return null;
  3648. }
  3649. // b1+b2 > 1, no intersection
  3650. if ( DdQxE2 + DdE1xQ > DdN ) {
  3651. return null;
  3652. }
  3653. // Line intersects triangle, check if ray does.
  3654. var QdN = - sign * diff.dot( normal );
  3655. // t < 0, no intersection
  3656. if ( QdN < 0 ) {
  3657. return null;
  3658. }
  3659. // Ray intersects triangle.
  3660. return this.at( QdN / DdN, optionalTarget );
  3661. };
  3662. }(),
  3663. applyMatrix4: function ( matrix4 ) {
  3664. this.direction.add( this.origin ).applyMatrix4( matrix4 );
  3665. this.origin.applyMatrix4( matrix4 );
  3666. this.direction.sub( this.origin );
  3667. this.direction.normalize();
  3668. return this;
  3669. },
  3670. equals: function ( ray ) {
  3671. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  3672. }
  3673. };
  3674. // File:src/math/Sphere.js
  3675. /**
  3676. * @author bhouston / http://clara.io
  3677. * @author mrdoob / http://mrdoob.com/
  3678. */
  3679. THREE.Sphere = function ( center, radius ) {
  3680. this.center = ( center !== undefined ) ? center : new THREE.Vector3();
  3681. this.radius = ( radius !== undefined ) ? radius : 0;
  3682. };
  3683. THREE.Sphere.prototype = {
  3684. constructor: THREE.Sphere,
  3685. set: function ( center, radius ) {
  3686. this.center.copy( center );
  3687. this.radius = radius;
  3688. return this;
  3689. },
  3690. setFromPoints: function () {
  3691. var box = new THREE.Box3();
  3692. return function ( points, optionalCenter ) {
  3693. var center = this.center;
  3694. if ( optionalCenter !== undefined ) {
  3695. center.copy( optionalCenter );
  3696. } else {
  3697. box.setFromPoints( points ).center( center );
  3698. }
  3699. var maxRadiusSq = 0;
  3700. for ( var i = 0, il = points.length; i < il; i ++ ) {
  3701. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  3702. }
  3703. this.radius = Math.sqrt( maxRadiusSq );
  3704. return this;
  3705. };
  3706. }(),
  3707. clone: function () {
  3708. return new this.constructor().copy( this );
  3709. },
  3710. copy: function ( sphere ) {
  3711. this.center.copy( sphere.center );
  3712. this.radius = sphere.radius;
  3713. return this;
  3714. },
  3715. empty: function () {
  3716. return ( this.radius <= 0 );
  3717. },
  3718. containsPoint: function ( point ) {
  3719. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  3720. },
  3721. distanceToPoint: function ( point ) {
  3722. return ( point.distanceTo( this.center ) - this.radius );
  3723. },
  3724. intersectsSphere: function ( sphere ) {
  3725. var radiusSum = this.radius + sphere.radius;
  3726. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  3727. },
  3728. intersectsBox: function ( box ) {
  3729. return box.intersectsSphere( this );
  3730. },
  3731. intersectsPlane: function ( plane ) {
  3732. // We use the following equation to compute the signed distance from
  3733. // the center of the sphere to the plane.
  3734. //
  3735. // distance = q * n - d
  3736. //
  3737. // If this distance is greater than the radius of the sphere,
  3738. // then there is no intersection.
  3739. return Math.abs( this.center.dot( plane.normal ) - plane.constant ) <= this.radius;
  3740. },
  3741. clampPoint: function ( point, optionalTarget ) {
  3742. var deltaLengthSq = this.center.distanceToSquared( point );
  3743. var result = optionalTarget || new THREE.Vector3();
  3744. result.copy( point );
  3745. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  3746. result.sub( this.center ).normalize();
  3747. result.multiplyScalar( this.radius ).add( this.center );
  3748. }
  3749. return result;
  3750. },
  3751. getBoundingBox: function ( optionalTarget ) {
  3752. var box = optionalTarget || new THREE.Box3();
  3753. box.set( this.center, this.center );
  3754. box.expandByScalar( this.radius );
  3755. return box;
  3756. },
  3757. applyMatrix4: function ( matrix ) {
  3758. this.center.applyMatrix4( matrix );
  3759. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  3760. return this;
  3761. },
  3762. translate: function ( offset ) {
  3763. this.center.add( offset );
  3764. return this;
  3765. },
  3766. equals: function ( sphere ) {
  3767. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  3768. }
  3769. };
  3770. // File:src/math/Frustum.js
  3771. /**
  3772. * @author mrdoob / http://mrdoob.com/
  3773. * @author alteredq / http://alteredqualia.com/
  3774. * @author bhouston / http://clara.io
  3775. */
  3776. THREE.Frustum = function ( p0, p1, p2, p3, p4, p5 ) {
  3777. this.planes = [
  3778. ( p0 !== undefined ) ? p0 : new THREE.Plane(),
  3779. ( p1 !== undefined ) ? p1 : new THREE.Plane(),
  3780. ( p2 !== undefined ) ? p2 : new THREE.Plane(),
  3781. ( p3 !== undefined ) ? p3 : new THREE.Plane(),
  3782. ( p4 !== undefined ) ? p4 : new THREE.Plane(),
  3783. ( p5 !== undefined ) ? p5 : new THREE.Plane()
  3784. ];
  3785. };
  3786. THREE.Frustum.prototype = {
  3787. constructor: THREE.Frustum,
  3788. set: function ( p0, p1, p2, p3, p4, p5 ) {
  3789. var planes = this.planes;
  3790. planes[ 0 ].copy( p0 );
  3791. planes[ 1 ].copy( p1 );
  3792. planes[ 2 ].copy( p2 );
  3793. planes[ 3 ].copy( p3 );
  3794. planes[ 4 ].copy( p4 );
  3795. planes[ 5 ].copy( p5 );
  3796. return this;
  3797. },
  3798. clone: function () {
  3799. return new this.constructor().copy( this );
  3800. },
  3801. copy: function ( frustum ) {
  3802. var planes = this.planes;
  3803. for ( var i = 0; i < 6; i ++ ) {
  3804. planes[ i ].copy( frustum.planes[ i ] );
  3805. }
  3806. return this;
  3807. },
  3808. setFromMatrix: function ( m ) {
  3809. var planes = this.planes;
  3810. var me = m.elements;
  3811. var me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  3812. var me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  3813. var me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  3814. var me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  3815. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  3816. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  3817. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  3818. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  3819. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  3820. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  3821. return this;
  3822. },
  3823. intersectsObject: function () {
  3824. var sphere = new THREE.Sphere();
  3825. return function ( object ) {
  3826. var geometry = object.geometry;
  3827. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  3828. sphere.copy( geometry.boundingSphere );
  3829. sphere.applyMatrix4( object.matrixWorld );
  3830. return this.intersectsSphere( sphere );
  3831. };
  3832. }(),
  3833. intersectsSphere: function ( sphere ) {
  3834. var planes = this.planes;
  3835. var center = sphere.center;
  3836. var negRadius = - sphere.radius;
  3837. for ( var i = 0; i < 6; i ++ ) {
  3838. var distance = planes[ i ].distanceToPoint( center );
  3839. if ( distance < negRadius ) {
  3840. return false;
  3841. }
  3842. }
  3843. return true;
  3844. },
  3845. intersectsBox: function () {
  3846. var p1 = new THREE.Vector3(),
  3847. p2 = new THREE.Vector3();
  3848. return function ( box ) {
  3849. var planes = this.planes;
  3850. for ( var i = 0; i < 6 ; i ++ ) {
  3851. var plane = planes[ i ];
  3852. p1.x = plane.normal.x > 0 ? box.min.x : box.max.x;
  3853. p2.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  3854. p1.y = plane.normal.y > 0 ? box.min.y : box.max.y;
  3855. p2.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  3856. p1.z = plane.normal.z > 0 ? box.min.z : box.max.z;
  3857. p2.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  3858. var d1 = plane.distanceToPoint( p1 );
  3859. var d2 = plane.distanceToPoint( p2 );
  3860. // if both outside plane, no intersection
  3861. if ( d1 < 0 && d2 < 0 ) {
  3862. return false;
  3863. }
  3864. }
  3865. return true;
  3866. };
  3867. }(),
  3868. containsPoint: function ( point ) {
  3869. var planes = this.planes;
  3870. for ( var i = 0; i < 6; i ++ ) {
  3871. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  3872. return false;
  3873. }
  3874. }
  3875. return true;
  3876. }
  3877. };
  3878. // File:src/math/Plane.js
  3879. /**
  3880. * @author bhouston / http://clara.io
  3881. */
  3882. THREE.Plane = function ( normal, constant ) {
  3883. this.normal = ( normal !== undefined ) ? normal : new THREE.Vector3( 1, 0, 0 );
  3884. this.constant = ( constant !== undefined ) ? constant : 0;
  3885. };
  3886. THREE.Plane.prototype = {
  3887. constructor: THREE.Plane,
  3888. set: function ( normal, constant ) {
  3889. this.normal.copy( normal );
  3890. this.constant = constant;
  3891. return this;
  3892. },
  3893. setComponents: function ( x, y, z, w ) {
  3894. this.normal.set( x, y, z );
  3895. this.constant = w;
  3896. return this;
  3897. },
  3898. setFromNormalAndCoplanarPoint: function ( normal, point ) {
  3899. this.normal.copy( normal );
  3900. this.constant = - point.dot( this.normal ); // must be this.normal, not normal, as this.normal is normalized
  3901. return this;
  3902. },
  3903. setFromCoplanarPoints: function () {
  3904. var v1 = new THREE.Vector3();
  3905. var v2 = new THREE.Vector3();
  3906. return function ( a, b, c ) {
  3907. var normal = v1.subVectors( c, b ).cross( v2.subVectors( a, b ) ).normalize();
  3908. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  3909. this.setFromNormalAndCoplanarPoint( normal, a );
  3910. return this;
  3911. };
  3912. }(),
  3913. clone: function () {
  3914. return new this.constructor().copy( this );
  3915. },
  3916. copy: function ( plane ) {
  3917. this.normal.copy( plane.normal );
  3918. this.constant = plane.constant;
  3919. return this;
  3920. },
  3921. normalize: function () {
  3922. // Note: will lead to a divide by zero if the plane is invalid.
  3923. var inverseNormalLength = 1.0 / this.normal.length();
  3924. this.normal.multiplyScalar( inverseNormalLength );
  3925. this.constant *= inverseNormalLength;
  3926. return this;
  3927. },
  3928. negate: function () {
  3929. this.constant *= - 1;
  3930. this.normal.negate();
  3931. return this;
  3932. },
  3933. distanceToPoint: function ( point ) {
  3934. return this.normal.dot( point ) + this.constant;
  3935. },
  3936. distanceToSphere: function ( sphere ) {
  3937. return this.distanceToPoint( sphere.center ) - sphere.radius;
  3938. },
  3939. projectPoint: function ( point, optionalTarget ) {
  3940. return this.orthoPoint( point, optionalTarget ).sub( point ).negate();
  3941. },
  3942. orthoPoint: function ( point, optionalTarget ) {
  3943. var perpendicularMagnitude = this.distanceToPoint( point );
  3944. var result = optionalTarget || new THREE.Vector3();
  3945. return result.copy( this.normal ).multiplyScalar( perpendicularMagnitude );
  3946. },
  3947. intersectLine: function () {
  3948. var v1 = new THREE.Vector3();
  3949. return function ( line, optionalTarget ) {
  3950. var result = optionalTarget || new THREE.Vector3();
  3951. var direction = line.delta( v1 );
  3952. var denominator = this.normal.dot( direction );
  3953. if ( denominator === 0 ) {
  3954. // line is coplanar, return origin
  3955. if ( this.distanceToPoint( line.start ) === 0 ) {
  3956. return result.copy( line.start );
  3957. }
  3958. // Unsure if this is the correct method to handle this case.
  3959. return undefined;
  3960. }
  3961. var t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  3962. if ( t < 0 || t > 1 ) {
  3963. return undefined;
  3964. }
  3965. return result.copy( direction ).multiplyScalar( t ).add( line.start );
  3966. };
  3967. }(),
  3968. intersectsLine: function ( line ) {
  3969. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  3970. var startSign = this.distanceToPoint( line.start );
  3971. var endSign = this.distanceToPoint( line.end );
  3972. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  3973. },
  3974. intersectsBox: function ( box ) {
  3975. return box.intersectsPlane( this );
  3976. },
  3977. intersectsSphere: function ( sphere ) {
  3978. return sphere.intersectsPlane( this );
  3979. },
  3980. coplanarPoint: function ( optionalTarget ) {
  3981. var result = optionalTarget || new THREE.Vector3();
  3982. return result.copy( this.normal ).multiplyScalar( - this.constant );
  3983. },
  3984. applyMatrix4: function () {
  3985. var v1 = new THREE.Vector3();
  3986. var v2 = new THREE.Vector3();
  3987. var m1 = new THREE.Matrix3();
  3988. return function ( matrix, optionalNormalMatrix ) {
  3989. // compute new normal based on theory here:
  3990. // http://www.songho.ca/opengl/gl_normaltransform.html
  3991. var normalMatrix = optionalNormalMatrix || m1.getNormalMatrix( matrix );
  3992. var newNormal = v1.copy( this.normal ).applyMatrix3( normalMatrix );
  3993. var newCoplanarPoint = this.coplanarPoint( v2 );
  3994. newCoplanarPoint.applyMatrix4( matrix );
  3995. this.setFromNormalAndCoplanarPoint( newNormal, newCoplanarPoint );
  3996. return this;
  3997. };
  3998. }(),
  3999. translate: function ( offset ) {
  4000. this.constant = this.constant - offset.dot( this.normal );
  4001. return this;
  4002. },
  4003. equals: function ( plane ) {
  4004. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  4005. }
  4006. };
  4007. // File:src/math/Math.js
  4008. /**
  4009. * @author alteredq / http://alteredqualia.com/
  4010. * @author mrdoob / http://mrdoob.com/
  4011. */
  4012. THREE.Math = {
  4013. generateUUID: function () {
  4014. // http://www.broofa.com/Tools/Math.uuid.htm
  4015. var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split( '' );
  4016. var uuid = new Array( 36 );
  4017. var rnd = 0, r;
  4018. return function () {
  4019. for ( var i = 0; i < 36; i ++ ) {
  4020. if ( i === 8 || i === 13 || i === 18 || i === 23 ) {
  4021. uuid[ i ] = '-';
  4022. } else if ( i === 14 ) {
  4023. uuid[ i ] = '4';
  4024. } else {
  4025. if ( rnd <= 0x02 ) rnd = 0x2000000 + ( Math.random() * 0x1000000 ) | 0;
  4026. r = rnd & 0xf;
  4027. rnd = rnd >> 4;
  4028. uuid[ i ] = chars[ ( i === 19 ) ? ( r & 0x3 ) | 0x8 : r ];
  4029. }
  4030. }
  4031. return uuid.join( '' );
  4032. };
  4033. }(),
  4034. clamp: function ( value, min, max ) {
  4035. return Math.max( min, Math.min( max, value ) );
  4036. },
  4037. // compute euclidian modulo of m % n
  4038. // https://en.wikipedia.org/wiki/Modulo_operation
  4039. euclideanModulo: function ( n, m ) {
  4040. return ( ( n % m ) + m ) % m;
  4041. },
  4042. // Linear mapping from range <a1, a2> to range <b1, b2>
  4043. mapLinear: function ( x, a1, a2, b1, b2 ) {
  4044. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  4045. },
  4046. // http://en.wikipedia.org/wiki/Smoothstep
  4047. smoothstep: function ( x, min, max ) {
  4048. if ( x <= min ) return 0;
  4049. if ( x >= max ) return 1;
  4050. x = ( x - min ) / ( max - min );
  4051. return x * x * ( 3 - 2 * x );
  4052. },
  4053. smootherstep: function ( x, min, max ) {
  4054. if ( x <= min ) return 0;
  4055. if ( x >= max ) return 1;
  4056. x = ( x - min ) / ( max - min );
  4057. return x * x * x * ( x * ( x * 6 - 15 ) + 10 );
  4058. },
  4059. // Random float from <0, 1> with 16 bits of randomness
  4060. // (standard Math.random() creates repetitive patterns when applied over larger space)
  4061. random16: function () {
  4062. return ( 65280 * Math.random() + 255 * Math.random() ) / 65535;
  4063. },
  4064. // Random integer from <low, high> interval
  4065. randInt: function ( low, high ) {
  4066. return low + Math.floor( Math.random() * ( high - low + 1 ) );
  4067. },
  4068. // Random float from <low, high> interval
  4069. randFloat: function ( low, high ) {
  4070. return low + Math.random() * ( high - low );
  4071. },
  4072. // Random float from <-range/2, range/2> interval
  4073. randFloatSpread: function ( range ) {
  4074. return range * ( 0.5 - Math.random() );
  4075. },
  4076. degToRad: function () {
  4077. var degreeToRadiansFactor = Math.PI / 180;
  4078. return function ( degrees ) {
  4079. return degrees * degreeToRadiansFactor;
  4080. };
  4081. }(),
  4082. radToDeg: function () {
  4083. var radianToDegreesFactor = 180 / Math.PI;
  4084. return function ( radians ) {
  4085. return radians * radianToDegreesFactor;
  4086. };
  4087. }(),
  4088. isPowerOfTwo: function ( value ) {
  4089. return ( value & ( value - 1 ) ) === 0 && value !== 0;
  4090. },
  4091. nearestPowerOfTwo: function ( value ) {
  4092. return Math.pow( 2, Math.round( Math.log( value ) / Math.LN2 ) );
  4093. },
  4094. nextPowerOfTwo: function ( value ) {
  4095. value --;
  4096. value |= value >> 1;
  4097. value |= value >> 2;
  4098. value |= value >> 4;
  4099. value |= value >> 8;
  4100. value |= value >> 16;
  4101. value ++;
  4102. return value;
  4103. }
  4104. };
  4105. // File:src/math/Spline.js
  4106. /**
  4107. * Spline from Tween.js, slightly optimized (and trashed)
  4108. * http://sole.github.com/tween.js/examples/05_spline.html
  4109. *
  4110. * @author mrdoob / http://mrdoob.com/
  4111. * @author alteredq / http://alteredqualia.com/
  4112. */
  4113. THREE.Spline = function ( points ) {
  4114. this.points = points;
  4115. var c = [], v3 = { x: 0, y: 0, z: 0 },
  4116. point, intPoint, weight, w2, w3,
  4117. pa, pb, pc, pd;
  4118. this.initFromArray = function ( a ) {
  4119. this.points = [];
  4120. for ( var i = 0; i < a.length; i ++ ) {
  4121. this.points[ i ] = { x: a[ i ][ 0 ], y: a[ i ][ 1 ], z: a[ i ][ 2 ] };
  4122. }
  4123. };
  4124. this.getPoint = function ( k ) {
  4125. point = ( this.points.length - 1 ) * k;
  4126. intPoint = Math.floor( point );
  4127. weight = point - intPoint;
  4128. c[ 0 ] = intPoint === 0 ? intPoint : intPoint - 1;
  4129. c[ 1 ] = intPoint;
  4130. c[ 2 ] = intPoint > this.points.length - 2 ? this.points.length - 1 : intPoint + 1;
  4131. c[ 3 ] = intPoint > this.points.length - 3 ? this.points.length - 1 : intPoint + 2;
  4132. pa = this.points[ c[ 0 ] ];
  4133. pb = this.points[ c[ 1 ] ];
  4134. pc = this.points[ c[ 2 ] ];
  4135. pd = this.points[ c[ 3 ] ];
  4136. w2 = weight * weight;
  4137. w3 = weight * w2;
  4138. v3.x = interpolate( pa.x, pb.x, pc.x, pd.x, weight, w2, w3 );
  4139. v3.y = interpolate( pa.y, pb.y, pc.y, pd.y, weight, w2, w3 );
  4140. v3.z = interpolate( pa.z, pb.z, pc.z, pd.z, weight, w2, w3 );
  4141. return v3;
  4142. };
  4143. this.getControlPointsArray = function () {
  4144. var i, p, l = this.points.length,
  4145. coords = [];
  4146. for ( i = 0; i < l; i ++ ) {
  4147. p = this.points[ i ];
  4148. coords[ i ] = [ p.x, p.y, p.z ];
  4149. }
  4150. return coords;
  4151. };
  4152. // approximate length by summing linear segments
  4153. this.getLength = function ( nSubDivisions ) {
  4154. var i, index, nSamples, position,
  4155. point = 0, intPoint = 0, oldIntPoint = 0,
  4156. oldPosition = new THREE.Vector3(),
  4157. tmpVec = new THREE.Vector3(),
  4158. chunkLengths = [],
  4159. totalLength = 0;
  4160. // first point has 0 length
  4161. chunkLengths[ 0 ] = 0;
  4162. if ( ! nSubDivisions ) nSubDivisions = 100;
  4163. nSamples = this.points.length * nSubDivisions;
  4164. oldPosition.copy( this.points[ 0 ] );
  4165. for ( i = 1; i < nSamples; i ++ ) {
  4166. index = i / nSamples;
  4167. position = this.getPoint( index );
  4168. tmpVec.copy( position );
  4169. totalLength += tmpVec.distanceTo( oldPosition );
  4170. oldPosition.copy( position );
  4171. point = ( this.points.length - 1 ) * index;
  4172. intPoint = Math.floor( point );
  4173. if ( intPoint !== oldIntPoint ) {
  4174. chunkLengths[ intPoint ] = totalLength;
  4175. oldIntPoint = intPoint;
  4176. }
  4177. }
  4178. // last point ends with total length
  4179. chunkLengths[ chunkLengths.length ] = totalLength;
  4180. return { chunks: chunkLengths, total: totalLength };
  4181. };
  4182. this.reparametrizeByArcLength = function ( samplingCoef ) {
  4183. var i, j,
  4184. index, indexCurrent, indexNext,
  4185. realDistance,
  4186. sampling, position,
  4187. newpoints = [],
  4188. tmpVec = new THREE.Vector3(),
  4189. sl = this.getLength();
  4190. newpoints.push( tmpVec.copy( this.points[ 0 ] ).clone() );
  4191. for ( i = 1; i < this.points.length; i ++ ) {
  4192. //tmpVec.copy( this.points[ i - 1 ] );
  4193. //linearDistance = tmpVec.distanceTo( this.points[ i ] );
  4194. realDistance = sl.chunks[ i ] - sl.chunks[ i - 1 ];
  4195. sampling = Math.ceil( samplingCoef * realDistance / sl.total );
  4196. indexCurrent = ( i - 1 ) / ( this.points.length - 1 );
  4197. indexNext = i / ( this.points.length - 1 );
  4198. for ( j = 1; j < sampling - 1; j ++ ) {
  4199. index = indexCurrent + j * ( 1 / sampling ) * ( indexNext - indexCurrent );
  4200. position = this.getPoint( index );
  4201. newpoints.push( tmpVec.copy( position ).clone() );
  4202. }
  4203. newpoints.push( tmpVec.copy( this.points[ i ] ).clone() );
  4204. }
  4205. this.points = newpoints;
  4206. };
  4207. // Catmull-Rom
  4208. function interpolate( p0, p1, p2, p3, t, t2, t3 ) {
  4209. var v0 = ( p2 - p0 ) * 0.5,
  4210. v1 = ( p3 - p1 ) * 0.5;
  4211. return ( 2 * ( p1 - p2 ) + v0 + v1 ) * t3 + ( - 3 * ( p1 - p2 ) - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  4212. }
  4213. };
  4214. // File:src/math/Triangle.js
  4215. /**
  4216. * @author bhouston / http://clara.io
  4217. * @author mrdoob / http://mrdoob.com/
  4218. */
  4219. THREE.Triangle = function ( a, b, c ) {
  4220. this.a = ( a !== undefined ) ? a : new THREE.Vector3();
  4221. this.b = ( b !== undefined ) ? b : new THREE.Vector3();
  4222. this.c = ( c !== undefined ) ? c : new THREE.Vector3();
  4223. };
  4224. THREE.Triangle.normal = function () {
  4225. var v0 = new THREE.Vector3();
  4226. return function ( a, b, c, optionalTarget ) {
  4227. var result = optionalTarget || new THREE.Vector3();
  4228. result.subVectors( c, b );
  4229. v0.subVectors( a, b );
  4230. result.cross( v0 );
  4231. var resultLengthSq = result.lengthSq();
  4232. if ( resultLengthSq > 0 ) {
  4233. return result.multiplyScalar( 1 / Math.sqrt( resultLengthSq ) );
  4234. }
  4235. return result.set( 0, 0, 0 );
  4236. };
  4237. }();
  4238. // static/instance method to calculate barycentric coordinates
  4239. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  4240. THREE.Triangle.barycoordFromPoint = function () {
  4241. var v0 = new THREE.Vector3();
  4242. var v1 = new THREE.Vector3();
  4243. var v2 = new THREE.Vector3();
  4244. return function ( point, a, b, c, optionalTarget ) {
  4245. v0.subVectors( c, a );
  4246. v1.subVectors( b, a );
  4247. v2.subVectors( point, a );
  4248. var dot00 = v0.dot( v0 );
  4249. var dot01 = v0.dot( v1 );
  4250. var dot02 = v0.dot( v2 );
  4251. var dot11 = v1.dot( v1 );
  4252. var dot12 = v1.dot( v2 );
  4253. var denom = ( dot00 * dot11 - dot01 * dot01 );
  4254. var result = optionalTarget || new THREE.Vector3();
  4255. // collinear or singular triangle
  4256. if ( denom === 0 ) {
  4257. // arbitrary location outside of triangle?
  4258. // not sure if this is the best idea, maybe should be returning undefined
  4259. return result.set( - 2, - 1, - 1 );
  4260. }
  4261. var invDenom = 1 / denom;
  4262. var u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  4263. var v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  4264. // barycentric coordinates must always sum to 1
  4265. return result.set( 1 - u - v, v, u );
  4266. };
  4267. }();
  4268. THREE.Triangle.containsPoint = function () {
  4269. var v1 = new THREE.Vector3();
  4270. return function ( point, a, b, c ) {
  4271. var result = THREE.Triangle.barycoordFromPoint( point, a, b, c, v1 );
  4272. return ( result.x >= 0 ) && ( result.y >= 0 ) && ( ( result.x + result.y ) <= 1 );
  4273. };
  4274. }();
  4275. THREE.Triangle.prototype = {
  4276. constructor: THREE.Triangle,
  4277. set: function ( a, b, c ) {
  4278. this.a.copy( a );
  4279. this.b.copy( b );
  4280. this.c.copy( c );
  4281. return this;
  4282. },
  4283. setFromPointsAndIndices: function ( points, i0, i1, i2 ) {
  4284. this.a.copy( points[ i0 ] );
  4285. this.b.copy( points[ i1 ] );
  4286. this.c.copy( points[ i2 ] );
  4287. return this;
  4288. },
  4289. clone: function () {
  4290. return new this.constructor().copy( this );
  4291. },
  4292. copy: function ( triangle ) {
  4293. this.a.copy( triangle.a );
  4294. this.b.copy( triangle.b );
  4295. this.c.copy( triangle.c );
  4296. return this;
  4297. },
  4298. area: function () {
  4299. var v0 = new THREE.Vector3();
  4300. var v1 = new THREE.Vector3();
  4301. return function () {
  4302. v0.subVectors( this.c, this.b );
  4303. v1.subVectors( this.a, this.b );
  4304. return v0.cross( v1 ).length() * 0.5;
  4305. };
  4306. }(),
  4307. midpoint: function ( optionalTarget ) {
  4308. var result = optionalTarget || new THREE.Vector3();
  4309. return result.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  4310. },
  4311. normal: function ( optionalTarget ) {
  4312. return THREE.Triangle.normal( this.a, this.b, this.c, optionalTarget );
  4313. },
  4314. plane: function ( optionalTarget ) {
  4315. var result = optionalTarget || new THREE.Plane();
  4316. return result.setFromCoplanarPoints( this.a, this.b, this.c );
  4317. },
  4318. barycoordFromPoint: function ( point, optionalTarget ) {
  4319. return THREE.Triangle.barycoordFromPoint( point, this.a, this.b, this.c, optionalTarget );
  4320. },
  4321. containsPoint: function ( point ) {
  4322. return THREE.Triangle.containsPoint( point, this.a, this.b, this.c );
  4323. },
  4324. equals: function ( triangle ) {
  4325. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  4326. }
  4327. };
  4328. // File:src/math/Interpolant.js
  4329. /**
  4330. * Abstract base class of interpolants over parametric samples.
  4331. *
  4332. * The parameter domain is one dimensional, typically the time or a path
  4333. * along a curve defined by the data.
  4334. *
  4335. * The sample values can have any dimensionality and derived classes may
  4336. * apply special interpretations to the data.
  4337. *
  4338. * This class provides the interval seek in a Template Method, deferring
  4339. * the actual interpolation to derived classes.
  4340. *
  4341. * Time complexity is O(1) for linear access crossing at most two points
  4342. * and O(log N) for random access, where N is the number of positions.
  4343. *
  4344. * References:
  4345. *
  4346. * http://www.oodesign.com/template-method-pattern.html
  4347. *
  4348. * @author tschw
  4349. */
  4350. THREE.Interpolant = function(
  4351. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4352. this.parameterPositions = parameterPositions;
  4353. this._cachedIndex = 0;
  4354. this.resultBuffer = resultBuffer !== undefined ?
  4355. resultBuffer : new sampleValues.constructor( sampleSize );
  4356. this.sampleValues = sampleValues;
  4357. this.valueSize = sampleSize;
  4358. };
  4359. THREE.Interpolant.prototype = {
  4360. constructor: THREE.Intepolant,
  4361. evaluate: function( t ) {
  4362. var pp = this.parameterPositions,
  4363. i1 = this._cachedIndex,
  4364. t1 = pp[ i1 ],
  4365. t0 = pp[ i1 - 1 ];
  4366. validate_interval: {
  4367. seek: {
  4368. var right;
  4369. linear_scan: {
  4370. //- See http://jsperf.com/comparison-to-undefined/3
  4371. //- slower code:
  4372. //-
  4373. //- if ( t >= t1 || t1 === undefined ) {
  4374. forward_scan: if ( ! ( t < t1 ) ) {
  4375. for ( var giveUpAt = i1 + 2; ;) {
  4376. if ( t1 === undefined ) {
  4377. if ( t < t0 ) break forward_scan;
  4378. // after end
  4379. i1 = pp.length;
  4380. this._cachedIndex = i1;
  4381. return this.afterEnd_( i1 - 1, t, t0 );
  4382. }
  4383. if ( i1 === giveUpAt ) break; // this loop
  4384. t0 = t1;
  4385. t1 = pp[ ++ i1 ];
  4386. if ( t < t1 ) {
  4387. // we have arrived at the sought interval
  4388. break seek;
  4389. }
  4390. }
  4391. // prepare binary search on the right side of the index
  4392. right = pp.length;
  4393. break linear_scan;
  4394. }
  4395. //- slower code:
  4396. //- if ( t < t0 || t0 === undefined ) {
  4397. if ( ! ( t >= t0 ) ) {
  4398. // looping?
  4399. var t1global = pp[ 1 ];
  4400. if ( t < t1global ) {
  4401. i1 = 2; // + 1, using the scan for the details
  4402. t0 = t1global;
  4403. }
  4404. // linear reverse scan
  4405. for ( var giveUpAt = i1 - 2; ;) {
  4406. if ( t0 === undefined ) {
  4407. // before start
  4408. this._cachedIndex = 0;
  4409. return this.beforeStart_( 0, t, t1 );
  4410. }
  4411. if ( i1 === giveUpAt ) break; // this loop
  4412. t1 = t0;
  4413. t0 = pp[ -- i1 - 1 ];
  4414. if ( t >= t0 ) {
  4415. // we have arrived at the sought interval
  4416. break seek;
  4417. }
  4418. }
  4419. // prepare binary search on the left side of the index
  4420. right = i1;
  4421. i1 = 0;
  4422. break linear_scan;
  4423. }
  4424. // the interval is valid
  4425. break validate_interval;
  4426. } // linear scan
  4427. // binary search
  4428. while ( i1 < right ) {
  4429. var mid = ( i1 + right ) >>> 1;
  4430. if ( t < pp[ mid ] ) {
  4431. right = mid;
  4432. } else {
  4433. i1 = mid + 1;
  4434. }
  4435. }
  4436. t1 = pp[ i1 ];
  4437. t0 = pp[ i1 - 1 ];
  4438. // check boundary cases, again
  4439. if ( t0 === undefined ) {
  4440. this._cachedIndex = 0;
  4441. return this.beforeStart_( 0, t, t1 );
  4442. }
  4443. if ( t1 === undefined ) {
  4444. i1 = pp.length;
  4445. this._cachedIndex = i1;
  4446. return this.afterEnd_( i1 - 1, t0, t );
  4447. }
  4448. } // seek
  4449. this._cachedIndex = i1;
  4450. this.intervalChanged_( i1, t0, t1 );
  4451. } // validate_interval
  4452. return this.interpolate_( i1, t0, t, t1 );
  4453. },
  4454. settings: null, // optional, subclass-specific settings structure
  4455. // Note: The indirection allows central control of many interpolants.
  4456. // --- Protected interface
  4457. DefaultSettings_: {},
  4458. getSettings_: function() {
  4459. return this.settings || this.DefaultSettings_;
  4460. },
  4461. copySampleValue_: function( index ) {
  4462. // copies a sample value to the result buffer
  4463. var result = this.resultBuffer,
  4464. values = this.sampleValues,
  4465. stride = this.valueSize,
  4466. offset = index * stride;
  4467. for ( var i = 0; i !== stride; ++ i ) {
  4468. result[ i ] = values[ offset + i ];
  4469. }
  4470. return result;
  4471. },
  4472. // Template methods for derived classes:
  4473. interpolate_: function( i1, t0, t, t1 ) {
  4474. throw new Error( "call to abstract method" );
  4475. // implementations shall return this.resultBuffer
  4476. },
  4477. intervalChanged_: function( i1, t0, t1 ) {
  4478. // empty
  4479. }
  4480. };
  4481. Object.assign( THREE.Interpolant.prototype, {
  4482. beforeStart_: //( 0, t, t0 ), returns this.resultBuffer
  4483. THREE.Interpolant.prototype.copySampleValue_,
  4484. afterEnd_: //( N-1, tN-1, t ), returns this.resultBuffer
  4485. THREE.Interpolant.prototype.copySampleValue_
  4486. } );
  4487. // File:src/math/interpolants/CubicInterpolant.js
  4488. /**
  4489. * Fast and simple cubic spline interpolant.
  4490. *
  4491. * It was derived from a Hermitian construction setting the first derivative
  4492. * at each sample position to the linear slope between neighboring positions
  4493. * over their parameter interval.
  4494. *
  4495. * @author tschw
  4496. */
  4497. THREE.CubicInterpolant = function(
  4498. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4499. THREE.Interpolant.call(
  4500. this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  4501. this._weightPrev = -0;
  4502. this._offsetPrev = -0;
  4503. this._weightNext = -0;
  4504. this._offsetNext = -0;
  4505. };
  4506. THREE.CubicInterpolant.prototype =
  4507. Object.assign( Object.create( THREE.Interpolant.prototype ), {
  4508. constructor: THREE.CubicInterpolant,
  4509. DefaultSettings_: {
  4510. endingStart: THREE.ZeroCurvatureEnding,
  4511. endingEnd: THREE.ZeroCurvatureEnding
  4512. },
  4513. intervalChanged_: function( i1, t0, t1 ) {
  4514. var pp = this.parameterPositions,
  4515. iPrev = i1 - 2,
  4516. iNext = i1 + 1,
  4517. tPrev = pp[ iPrev ],
  4518. tNext = pp[ iNext ];
  4519. if ( tPrev === undefined ) {
  4520. switch ( this.getSettings_().endingStart ) {
  4521. case THREE.ZeroSlopeEnding:
  4522. // f'(t0) = 0
  4523. iPrev = i1;
  4524. tPrev = 2 * t0 - t1;
  4525. break;
  4526. case THREE.WrapAroundEnding:
  4527. // use the other end of the curve
  4528. iPrev = pp.length - 2;
  4529. tPrev = t0 + pp[ iPrev ] - pp[ iPrev + 1 ];
  4530. break;
  4531. default: // ZeroCurvatureEnding
  4532. // f''(t0) = 0 a.k.a. Natural Spline
  4533. iPrev = i1;
  4534. tPrev = t1;
  4535. }
  4536. }
  4537. if ( tNext === undefined ) {
  4538. switch ( this.getSettings_().endingEnd ) {
  4539. case THREE.ZeroSlopeEnding:
  4540. // f'(tN) = 0
  4541. iNext = i1;
  4542. tNext = 2 * t1 - t0;
  4543. break;
  4544. case THREE.WrapAroundEnding:
  4545. // use the other end of the curve
  4546. iNext = 1;
  4547. tNext = t1 + pp[ 1 ] - pp[ 0 ];
  4548. break;
  4549. default: // ZeroCurvatureEnding
  4550. // f''(tN) = 0, a.k.a. Natural Spline
  4551. iNext = i1 - 1;
  4552. tNext = t0;
  4553. }
  4554. }
  4555. var halfDt = ( t1 - t0 ) * 0.5,
  4556. stride = this.valueSize;
  4557. this._weightPrev = halfDt / ( t0 - tPrev );
  4558. this._weightNext = halfDt / ( tNext - t1 );
  4559. this._offsetPrev = iPrev * stride;
  4560. this._offsetNext = iNext * stride;
  4561. },
  4562. interpolate_: function( i1, t0, t, t1 ) {
  4563. var result = this.resultBuffer,
  4564. values = this.sampleValues,
  4565. stride = this.valueSize,
  4566. o1 = i1 * stride, o0 = o1 - stride,
  4567. oP = this._offsetPrev, oN = this._offsetNext,
  4568. wP = this._weightPrev, wN = this._weightNext,
  4569. p = ( t - t0 ) / ( t1 - t0 ),
  4570. pp = p * p,
  4571. ppp = pp * p;
  4572. // evaluate polynomials
  4573. var sP = - wP * ppp + 2 * wP * pp - wP * p;
  4574. var s0 = ( 1 + wP ) * ppp + (-1.5 - 2 * wP ) * pp + ( -0.5 + wP ) * p + 1;
  4575. var s1 = (-1 - wN ) * ppp + ( 1.5 + wN ) * pp + 0.5 * p;
  4576. var sN = wN * ppp - wN * pp;
  4577. // combine data linearly
  4578. for ( var i = 0; i !== stride; ++ i ) {
  4579. result[ i ] =
  4580. sP * values[ oP + i ] +
  4581. s0 * values[ o0 + i ] +
  4582. s1 * values[ o1 + i ] +
  4583. sN * values[ oN + i ];
  4584. }
  4585. return result;
  4586. }
  4587. } );
  4588. // File:src/math/interpolants/DiscreteInterpolant.js
  4589. /**
  4590. *
  4591. * Interpolant that evaluates to the sample value at the position preceeding
  4592. * the parameter.
  4593. *
  4594. * @author tschw
  4595. */
  4596. THREE.DiscreteInterpolant = function(
  4597. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4598. THREE.Interpolant.call(
  4599. this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  4600. };
  4601. THREE.DiscreteInterpolant.prototype =
  4602. Object.assign( Object.create( THREE.Interpolant.prototype ), {
  4603. constructor: THREE.DiscreteInterpolant,
  4604. interpolate_: function( i1, t0, t, t1 ) {
  4605. return this.copySampleValue_( i1 - 1 );
  4606. }
  4607. } );
  4608. // File:src/math/interpolants/LinearInterpolant.js
  4609. /**
  4610. * @author tschw
  4611. */
  4612. THREE.LinearInterpolant = function(
  4613. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4614. THREE.Interpolant.call(
  4615. this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  4616. };
  4617. THREE.LinearInterpolant.prototype =
  4618. Object.assign( Object.create( THREE.Interpolant.prototype ), {
  4619. constructor: THREE.LinearInterpolant,
  4620. interpolate_: function( i1, t0, t, t1 ) {
  4621. var result = this.resultBuffer,
  4622. values = this.sampleValues,
  4623. stride = this.valueSize,
  4624. offset1 = i1 * stride,
  4625. offset0 = offset1 - stride,
  4626. weight1 = ( t - t0 ) / ( t1 - t0 ),
  4627. weight0 = 1 - weight1;
  4628. for ( var i = 0; i !== stride; ++ i ) {
  4629. result[ i ] =
  4630. values[ offset0 + i ] * weight0 +
  4631. values[ offset1 + i ] * weight1;
  4632. }
  4633. return result;
  4634. }
  4635. } );
  4636. // File:src/math/interpolants/QuaternionLinearInterpolant.js
  4637. /**
  4638. * Spherical linear unit quaternion interpolant.
  4639. *
  4640. * @author tschw
  4641. */
  4642. THREE.QuaternionLinearInterpolant = function(
  4643. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4644. THREE.Interpolant.call(
  4645. this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  4646. };
  4647. THREE.QuaternionLinearInterpolant.prototype =
  4648. Object.assign( Object.create( THREE.Interpolant.prototype ), {
  4649. constructor: THREE.QuaternionLinearInterpolant,
  4650. interpolate_: function( i1, t0, t, t1 ) {
  4651. var result = this.resultBuffer,
  4652. values = this.sampleValues,
  4653. stride = this.valueSize,
  4654. offset = i1 * stride,
  4655. alpha = ( t - t0 ) / ( t1 - t0 );
  4656. for ( var end = offset + stride; offset !== end; offset += 4 ) {
  4657. THREE.Quaternion.slerpFlat( result, 0,
  4658. values, offset - stride, values, offset, alpha );
  4659. }
  4660. return result;
  4661. }
  4662. } );
  4663. // File:src/core/Clock.js
  4664. /**
  4665. * @author alteredq / http://alteredqualia.com/
  4666. */
  4667. THREE.Clock = function ( autoStart ) {
  4668. this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
  4669. this.startTime = 0;
  4670. this.oldTime = 0;
  4671. this.elapsedTime = 0;
  4672. this.running = false;
  4673. };
  4674. THREE.Clock.prototype = {
  4675. constructor: THREE.Clock,
  4676. start: function () {
  4677. this.startTime = self.performance.now();
  4678. this.oldTime = this.startTime;
  4679. this.running = true;
  4680. },
  4681. stop: function () {
  4682. this.getElapsedTime();
  4683. this.running = false;
  4684. },
  4685. getElapsedTime: function () {
  4686. this.getDelta();
  4687. return this.elapsedTime;
  4688. },
  4689. getDelta: function () {
  4690. var diff = 0;
  4691. if ( this.autoStart && ! this.running ) {
  4692. this.start();
  4693. }
  4694. if ( this.running ) {
  4695. var newTime = self.performance.now();
  4696. diff = 0.001 * ( newTime - this.oldTime );
  4697. this.oldTime = newTime;
  4698. this.elapsedTime += diff;
  4699. }
  4700. return diff;
  4701. }
  4702. };
  4703. // File:src/core/EventDispatcher.js
  4704. /**
  4705. * https://github.com/mrdoob/eventdispatcher.js/
  4706. */
  4707. THREE.EventDispatcher = function () {};
  4708. THREE.EventDispatcher.prototype = {
  4709. constructor: THREE.EventDispatcher,
  4710. apply: function ( object ) {
  4711. object.addEventListener = THREE.EventDispatcher.prototype.addEventListener;
  4712. object.hasEventListener = THREE.EventDispatcher.prototype.hasEventListener;
  4713. object.removeEventListener = THREE.EventDispatcher.prototype.removeEventListener;
  4714. object.dispatchEvent = THREE.EventDispatcher.prototype.dispatchEvent;
  4715. },
  4716. addEventListener: function ( type, listener ) {
  4717. if ( this._listeners === undefined ) this._listeners = {};
  4718. var listeners = this._listeners;
  4719. if ( listeners[ type ] === undefined ) {
  4720. listeners[ type ] = [];
  4721. }
  4722. if ( listeners[ type ].indexOf( listener ) === - 1 ) {
  4723. listeners[ type ].push( listener );
  4724. }
  4725. },
  4726. hasEventListener: function ( type, listener ) {
  4727. if ( this._listeners === undefined ) return false;
  4728. var listeners = this._listeners;
  4729. if ( listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1 ) {
  4730. return true;
  4731. }
  4732. return false;
  4733. },
  4734. removeEventListener: function ( type, listener ) {
  4735. if ( this._listeners === undefined ) return;
  4736. var listeners = this._listeners;
  4737. var listenerArray = listeners[ type ];
  4738. if ( listenerArray !== undefined ) {
  4739. var index = listenerArray.indexOf( listener );
  4740. if ( index !== - 1 ) {
  4741. listenerArray.splice( index, 1 );
  4742. }
  4743. }
  4744. },
  4745. dispatchEvent: function ( event ) {
  4746. if ( this._listeners === undefined ) return;
  4747. var listeners = this._listeners;
  4748. var listenerArray = listeners[ event.type ];
  4749. if ( listenerArray !== undefined ) {
  4750. event.target = this;
  4751. var array = [];
  4752. var length = listenerArray.length;
  4753. for ( var i = 0; i < length; i ++ ) {
  4754. array[ i ] = listenerArray[ i ];
  4755. }
  4756. for ( var i = 0; i < length; i ++ ) {
  4757. array[ i ].call( this, event );
  4758. }
  4759. }
  4760. }
  4761. };
  4762. // File:src/core/Layers.js
  4763. /**
  4764. * @author mrdoob / http://mrdoob.com/
  4765. */
  4766. THREE.Layers = function () {
  4767. this.mask = 1;
  4768. };
  4769. THREE.Layers.prototype = {
  4770. constructor: THREE.Layers,
  4771. set: function ( channel ) {
  4772. this.mask = 1 << channel;
  4773. },
  4774. enable: function ( channel ) {
  4775. this.mask |= 1 << channel;
  4776. },
  4777. toggle: function ( channel ) {
  4778. this.mask ^= 1 << channel;
  4779. },
  4780. disable: function ( channel ) {
  4781. this.mask &= ~ ( 1 << channel );
  4782. },
  4783. test: function ( layers ) {
  4784. return ( this.mask & layers.mask ) !== 0;
  4785. }
  4786. };
  4787. // File:src/core/Raycaster.js
  4788. /**
  4789. * @author mrdoob / http://mrdoob.com/
  4790. * @author bhouston / http://clara.io/
  4791. * @author stephomi / http://stephaneginier.com/
  4792. */
  4793. ( function ( THREE ) {
  4794. THREE.Raycaster = function ( origin, direction, near, far ) {
  4795. this.ray = new THREE.Ray( origin, direction );
  4796. // direction is assumed to be normalized (for accurate distance calculations)
  4797. this.near = near || 0;
  4798. this.far = far || Infinity;
  4799. this.params = {
  4800. Mesh: {},
  4801. Line: {},
  4802. LOD: {},
  4803. Points: { threshold: 1 },
  4804. Sprite: {}
  4805. };
  4806. Object.defineProperties( this.params, {
  4807. PointCloud: {
  4808. get: function () {
  4809. console.warn( 'THREE.Raycaster: params.PointCloud has been renamed to params.Points.' );
  4810. return this.Points;
  4811. }
  4812. }
  4813. } );
  4814. };
  4815. function descSort( a, b ) {
  4816. return a.distance - b.distance;
  4817. }
  4818. function intersectObject( object, raycaster, intersects, recursive ) {
  4819. if ( object.visible === false ) return;
  4820. object.raycast( raycaster, intersects );
  4821. if ( recursive === true ) {
  4822. var children = object.children;
  4823. for ( var i = 0, l = children.length; i < l; i ++ ) {
  4824. intersectObject( children[ i ], raycaster, intersects, true );
  4825. }
  4826. }
  4827. }
  4828. //
  4829. THREE.Raycaster.prototype = {
  4830. constructor: THREE.Raycaster,
  4831. linePrecision: 1,
  4832. set: function ( origin, direction ) {
  4833. // direction is assumed to be normalized (for accurate distance calculations)
  4834. this.ray.set( origin, direction );
  4835. },
  4836. setFromCamera: function ( coords, camera ) {
  4837. if ( camera instanceof THREE.PerspectiveCamera ) {
  4838. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  4839. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  4840. } else if ( camera instanceof THREE.OrthographicCamera ) {
  4841. this.ray.origin.set( coords.x, coords.y, - 1 ).unproject( camera );
  4842. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  4843. } else {
  4844. console.error( 'THREE.Raycaster: Unsupported camera type.' );
  4845. }
  4846. },
  4847. intersectObject: function ( object, recursive ) {
  4848. var intersects = [];
  4849. intersectObject( object, this, intersects, recursive );
  4850. intersects.sort( descSort );
  4851. return intersects;
  4852. },
  4853. intersectObjects: function ( objects, recursive ) {
  4854. var intersects = [];
  4855. if ( Array.isArray( objects ) === false ) {
  4856. console.warn( 'THREE.Raycaster.intersectObjects: objects is not an Array.' );
  4857. return intersects;
  4858. }
  4859. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  4860. intersectObject( objects[ i ], this, intersects, recursive );
  4861. }
  4862. intersects.sort( descSort );
  4863. return intersects;
  4864. }
  4865. };
  4866. }( THREE ) );
  4867. // File:src/core/Object3D.js
  4868. /**
  4869. * @author mrdoob / http://mrdoob.com/
  4870. * @author mikael emtinger / http://gomo.se/
  4871. * @author alteredq / http://alteredqualia.com/
  4872. * @author WestLangley / http://github.com/WestLangley
  4873. * @author elephantatwork / www.elephantatwork.ch
  4874. */
  4875. THREE.Object3D = function () {
  4876. Object.defineProperty( this, 'id', { value: THREE.Object3DIdCount ++ } );
  4877. this.uuid = THREE.Math.generateUUID();
  4878. this.name = '';
  4879. this.type = 'Object3D';
  4880. this.parent = null;
  4881. this.children = [];
  4882. this.up = THREE.Object3D.DefaultUp.clone();
  4883. var position = new THREE.Vector3();
  4884. var rotation = new THREE.Euler();
  4885. var quaternion = new THREE.Quaternion();
  4886. var scale = new THREE.Vector3( 1, 1, 1 );
  4887. function onRotationChange() {
  4888. quaternion.setFromEuler( rotation, false );
  4889. }
  4890. function onQuaternionChange() {
  4891. rotation.setFromQuaternion( quaternion, undefined, false );
  4892. }
  4893. rotation.onChange( onRotationChange );
  4894. quaternion.onChange( onQuaternionChange );
  4895. Object.defineProperties( this, {
  4896. position: {
  4897. enumerable: true,
  4898. value: position
  4899. },
  4900. rotation: {
  4901. enumerable: true,
  4902. value: rotation
  4903. },
  4904. quaternion: {
  4905. enumerable: true,
  4906. value: quaternion
  4907. },
  4908. scale: {
  4909. enumerable: true,
  4910. value: scale
  4911. },
  4912. modelViewMatrix: {
  4913. value: new THREE.Matrix4()
  4914. },
  4915. normalMatrix: {
  4916. value: new THREE.Matrix3()
  4917. }
  4918. } );
  4919. this.rotationAutoUpdate = true;
  4920. this.matrix = new THREE.Matrix4();
  4921. this.matrixWorld = new THREE.Matrix4();
  4922. this.matrixAutoUpdate = THREE.Object3D.DefaultMatrixAutoUpdate;
  4923. this.matrixWorldNeedsUpdate = false;
  4924. this.layers = new THREE.Layers();
  4925. this.visible = true;
  4926. this.castShadow = false;
  4927. this.receiveShadow = false;
  4928. this.frustumCulled = true;
  4929. this.renderOrder = 0;
  4930. this.userData = {};
  4931. };
  4932. THREE.Object3D.DefaultUp = new THREE.Vector3( 0, 1, 0 );
  4933. THREE.Object3D.DefaultMatrixAutoUpdate = true;
  4934. THREE.Object3D.prototype = {
  4935. constructor: THREE.Object3D,
  4936. applyMatrix: function ( matrix ) {
  4937. this.matrix.multiplyMatrices( matrix, this.matrix );
  4938. this.matrix.decompose( this.position, this.quaternion, this.scale );
  4939. },
  4940. setRotationFromAxisAngle: function ( axis, angle ) {
  4941. // assumes axis is normalized
  4942. this.quaternion.setFromAxisAngle( axis, angle );
  4943. },
  4944. setRotationFromEuler: function ( euler ) {
  4945. this.quaternion.setFromEuler( euler, true );
  4946. },
  4947. setRotationFromMatrix: function ( m ) {
  4948. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4949. this.quaternion.setFromRotationMatrix( m );
  4950. },
  4951. setRotationFromQuaternion: function ( q ) {
  4952. // assumes q is normalized
  4953. this.quaternion.copy( q );
  4954. },
  4955. rotateOnAxis: function () {
  4956. // rotate object on axis in object space
  4957. // axis is assumed to be normalized
  4958. var q1 = new THREE.Quaternion();
  4959. return function ( axis, angle ) {
  4960. q1.setFromAxisAngle( axis, angle );
  4961. this.quaternion.multiply( q1 );
  4962. return this;
  4963. };
  4964. }(),
  4965. rotateX: function () {
  4966. var v1 = new THREE.Vector3( 1, 0, 0 );
  4967. return function ( angle ) {
  4968. return this.rotateOnAxis( v1, angle );
  4969. };
  4970. }(),
  4971. rotateY: function () {
  4972. var v1 = new THREE.Vector3( 0, 1, 0 );
  4973. return function ( angle ) {
  4974. return this.rotateOnAxis( v1, angle );
  4975. };
  4976. }(),
  4977. rotateZ: function () {
  4978. var v1 = new THREE.Vector3( 0, 0, 1 );
  4979. return function ( angle ) {
  4980. return this.rotateOnAxis( v1, angle );
  4981. };
  4982. }(),
  4983. translateOnAxis: function () {
  4984. // translate object by distance along axis in object space
  4985. // axis is assumed to be normalized
  4986. var v1 = new THREE.Vector3();
  4987. return function ( axis, distance ) {
  4988. v1.copy( axis ).applyQuaternion( this.quaternion );
  4989. this.position.add( v1.multiplyScalar( distance ) );
  4990. return this;
  4991. };
  4992. }(),
  4993. translateX: function () {
  4994. var v1 = new THREE.Vector3( 1, 0, 0 );
  4995. return function ( distance ) {
  4996. return this.translateOnAxis( v1, distance );
  4997. };
  4998. }(),
  4999. translateY: function () {
  5000. var v1 = new THREE.Vector3( 0, 1, 0 );
  5001. return function ( distance ) {
  5002. return this.translateOnAxis( v1, distance );
  5003. };
  5004. }(),
  5005. translateZ: function () {
  5006. var v1 = new THREE.Vector3( 0, 0, 1 );
  5007. return function ( distance ) {
  5008. return this.translateOnAxis( v1, distance );
  5009. };
  5010. }(),
  5011. localToWorld: function ( vector ) {
  5012. return vector.applyMatrix4( this.matrixWorld );
  5013. },
  5014. worldToLocal: function () {
  5015. var m1 = new THREE.Matrix4();
  5016. return function ( vector ) {
  5017. return vector.applyMatrix4( m1.getInverse( this.matrixWorld ) );
  5018. };
  5019. }(),
  5020. lookAt: function () {
  5021. // This routine does not support objects with rotated and/or translated parent(s)
  5022. var m1 = new THREE.Matrix4();
  5023. return function ( vector ) {
  5024. m1.lookAt( vector, this.position, this.up );
  5025. this.quaternion.setFromRotationMatrix( m1 );
  5026. };
  5027. }(),
  5028. add: function ( object ) {
  5029. if ( arguments.length > 1 ) {
  5030. for ( var i = 0; i < arguments.length; i ++ ) {
  5031. this.add( arguments[ i ] );
  5032. }
  5033. return this;
  5034. }
  5035. if ( object === this ) {
  5036. console.error( "THREE.Object3D.add: object can't be added as a child of itself.", object );
  5037. return this;
  5038. }
  5039. if ( object instanceof THREE.Object3D ) {
  5040. if ( object.parent !== null ) {
  5041. object.parent.remove( object );
  5042. }
  5043. object.parent = this;
  5044. object.dispatchEvent( { type: 'added' } );
  5045. this.children.push( object );
  5046. } else {
  5047. console.error( "THREE.Object3D.add: object not an instance of THREE.Object3D.", object );
  5048. }
  5049. return this;
  5050. },
  5051. remove: function ( object ) {
  5052. if ( arguments.length > 1 ) {
  5053. for ( var i = 0; i < arguments.length; i ++ ) {
  5054. this.remove( arguments[ i ] );
  5055. }
  5056. }
  5057. var index = this.children.indexOf( object );
  5058. if ( index !== - 1 ) {
  5059. object.parent = null;
  5060. object.dispatchEvent( { type: 'removed' } );
  5061. this.children.splice( index, 1 );
  5062. }
  5063. },
  5064. getObjectById: function ( id ) {
  5065. return this.getObjectByProperty( 'id', id );
  5066. },
  5067. getObjectByName: function ( name ) {
  5068. return this.getObjectByProperty( 'name', name );
  5069. },
  5070. getObjectByProperty: function ( name, value ) {
  5071. if ( this[ name ] === value ) return this;
  5072. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  5073. var child = this.children[ i ];
  5074. var object = child.getObjectByProperty( name, value );
  5075. if ( object !== undefined ) {
  5076. return object;
  5077. }
  5078. }
  5079. return undefined;
  5080. },
  5081. getWorldPosition: function ( optionalTarget ) {
  5082. var result = optionalTarget || new THREE.Vector3();
  5083. this.updateMatrixWorld( true );
  5084. return result.setFromMatrixPosition( this.matrixWorld );
  5085. },
  5086. getWorldQuaternion: function () {
  5087. var position = new THREE.Vector3();
  5088. var scale = new THREE.Vector3();
  5089. return function ( optionalTarget ) {
  5090. var result = optionalTarget || new THREE.Quaternion();
  5091. this.updateMatrixWorld( true );
  5092. this.matrixWorld.decompose( position, result, scale );
  5093. return result;
  5094. };
  5095. }(),
  5096. getWorldRotation: function () {
  5097. var quaternion = new THREE.Quaternion();
  5098. return function ( optionalTarget ) {
  5099. var result = optionalTarget || new THREE.Euler();
  5100. this.getWorldQuaternion( quaternion );
  5101. return result.setFromQuaternion( quaternion, this.rotation.order, false );
  5102. };
  5103. }(),
  5104. getWorldScale: function () {
  5105. var position = new THREE.Vector3();
  5106. var quaternion = new THREE.Quaternion();
  5107. return function ( optionalTarget ) {
  5108. var result = optionalTarget || new THREE.Vector3();
  5109. this.updateMatrixWorld( true );
  5110. this.matrixWorld.decompose( position, quaternion, result );
  5111. return result;
  5112. };
  5113. }(),
  5114. getWorldDirection: function () {
  5115. var quaternion = new THREE.Quaternion();
  5116. return function ( optionalTarget ) {
  5117. var result = optionalTarget || new THREE.Vector3();
  5118. this.getWorldQuaternion( quaternion );
  5119. return result.set( 0, 0, 1 ).applyQuaternion( quaternion );
  5120. };
  5121. }(),
  5122. raycast: function () {},
  5123. traverse: function ( callback ) {
  5124. callback( this );
  5125. var children = this.children;
  5126. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5127. children[ i ].traverse( callback );
  5128. }
  5129. },
  5130. traverseVisible: function ( callback ) {
  5131. if ( this.visible === false ) return;
  5132. callback( this );
  5133. var children = this.children;
  5134. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5135. children[ i ].traverseVisible( callback );
  5136. }
  5137. },
  5138. traverseAncestors: function ( callback ) {
  5139. var parent = this.parent;
  5140. if ( parent !== null ) {
  5141. callback( parent );
  5142. parent.traverseAncestors( callback );
  5143. }
  5144. },
  5145. updateMatrix: function () {
  5146. this.matrix.compose( this.position, this.quaternion, this.scale );
  5147. this.matrixWorldNeedsUpdate = true;
  5148. },
  5149. updateMatrixWorld: function ( force ) {
  5150. if ( this.matrixAutoUpdate === true ) this.updateMatrix();
  5151. if ( this.matrixWorldNeedsUpdate === true || force === true ) {
  5152. if ( this.parent === null ) {
  5153. this.matrixWorld.copy( this.matrix );
  5154. } else {
  5155. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  5156. }
  5157. this.matrixWorldNeedsUpdate = false;
  5158. force = true;
  5159. }
  5160. // update children
  5161. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  5162. this.children[ i ].updateMatrixWorld( force );
  5163. }
  5164. },
  5165. toJSON: function ( meta ) {
  5166. var isRootObject = ( meta === undefined );
  5167. var output = {};
  5168. // meta is a hash used to collect geometries, materials.
  5169. // not providing it implies that this is the root object
  5170. // being serialized.
  5171. if ( isRootObject ) {
  5172. // initialize meta obj
  5173. meta = {
  5174. geometries: {},
  5175. materials: {},
  5176. textures: {},
  5177. images: {}
  5178. };
  5179. output.metadata = {
  5180. version: 4.4,
  5181. type: 'Object',
  5182. generator: 'Object3D.toJSON'
  5183. };
  5184. }
  5185. // standard Object3D serialization
  5186. var object = {};
  5187. object.uuid = this.uuid;
  5188. object.type = this.type;
  5189. if ( this.name !== '' ) object.name = this.name;
  5190. if ( JSON.stringify( this.userData ) !== '{}' ) object.userData = this.userData;
  5191. if ( this.castShadow === true ) object.castShadow = true;
  5192. if ( this.receiveShadow === true ) object.receiveShadow = true;
  5193. if ( this.visible === false ) object.visible = false;
  5194. object.matrix = this.matrix.toArray();
  5195. //
  5196. if ( this.geometry !== undefined ) {
  5197. if ( meta.geometries[ this.geometry.uuid ] === undefined ) {
  5198. meta.geometries[ this.geometry.uuid ] = this.geometry.toJSON( meta );
  5199. }
  5200. object.geometry = this.geometry.uuid;
  5201. }
  5202. if ( this.material !== undefined ) {
  5203. if ( meta.materials[ this.material.uuid ] === undefined ) {
  5204. meta.materials[ this.material.uuid ] = this.material.toJSON( meta );
  5205. }
  5206. object.material = this.material.uuid;
  5207. }
  5208. //
  5209. if ( this.children.length > 0 ) {
  5210. object.children = [];
  5211. for ( var i = 0; i < this.children.length; i ++ ) {
  5212. object.children.push( this.children[ i ].toJSON( meta ).object );
  5213. }
  5214. }
  5215. if ( isRootObject ) {
  5216. var geometries = extractFromCache( meta.geometries );
  5217. var materials = extractFromCache( meta.materials );
  5218. var textures = extractFromCache( meta.textures );
  5219. var images = extractFromCache( meta.images );
  5220. if ( geometries.length > 0 ) output.geometries = geometries;
  5221. if ( materials.length > 0 ) output.materials = materials;
  5222. if ( textures.length > 0 ) output.textures = textures;
  5223. if ( images.length > 0 ) output.images = images;
  5224. }
  5225. output.object = object;
  5226. return output;
  5227. // extract data from the cache hash
  5228. // remove metadata on each item
  5229. // and return as array
  5230. function extractFromCache ( cache ) {
  5231. var values = [];
  5232. for ( var key in cache ) {
  5233. var data = cache[ key ];
  5234. delete data.metadata;
  5235. values.push( data );
  5236. }
  5237. return values;
  5238. }
  5239. },
  5240. clone: function ( recursive ) {
  5241. return new this.constructor().copy( this, recursive );
  5242. },
  5243. copy: function ( source, recursive ) {
  5244. if ( recursive === undefined ) recursive = true;
  5245. this.name = source.name;
  5246. this.up.copy( source.up );
  5247. this.position.copy( source.position );
  5248. this.quaternion.copy( source.quaternion );
  5249. this.scale.copy( source.scale );
  5250. this.rotationAutoUpdate = source.rotationAutoUpdate;
  5251. this.matrix.copy( source.matrix );
  5252. this.matrixWorld.copy( source.matrixWorld );
  5253. this.matrixAutoUpdate = source.matrixAutoUpdate;
  5254. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  5255. this.visible = source.visible;
  5256. this.castShadow = source.castShadow;
  5257. this.receiveShadow = source.receiveShadow;
  5258. this.frustumCulled = source.frustumCulled;
  5259. this.renderOrder = source.renderOrder;
  5260. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  5261. if ( recursive === true ) {
  5262. for ( var i = 0; i < source.children.length; i ++ ) {
  5263. var child = source.children[ i ];
  5264. this.add( child.clone() );
  5265. }
  5266. }
  5267. return this;
  5268. }
  5269. };
  5270. THREE.EventDispatcher.prototype.apply( THREE.Object3D.prototype );
  5271. THREE.Object3DIdCount = 0;
  5272. // File:src/core/Face3.js
  5273. /**
  5274. * @author mrdoob / http://mrdoob.com/
  5275. * @author alteredq / http://alteredqualia.com/
  5276. */
  5277. THREE.Face3 = function ( a, b, c, normal, color, materialIndex ) {
  5278. this.a = a;
  5279. this.b = b;
  5280. this.c = c;
  5281. this.normal = normal instanceof THREE.Vector3 ? normal : new THREE.Vector3();
  5282. this.vertexNormals = Array.isArray( normal ) ? normal : [];
  5283. this.color = color instanceof THREE.Color ? color : new THREE.Color();
  5284. this.vertexColors = Array.isArray( color ) ? color : [];
  5285. this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
  5286. };
  5287. THREE.Face3.prototype = {
  5288. constructor: THREE.Face3,
  5289. clone: function () {
  5290. return new this.constructor().copy( this );
  5291. },
  5292. copy: function ( source ) {
  5293. this.a = source.a;
  5294. this.b = source.b;
  5295. this.c = source.c;
  5296. this.normal.copy( source.normal );
  5297. this.color.copy( source.color );
  5298. this.materialIndex = source.materialIndex;
  5299. for ( var i = 0, il = source.vertexNormals.length; i < il; i ++ ) {
  5300. this.vertexNormals[ i ] = source.vertexNormals[ i ].clone();
  5301. }
  5302. for ( var i = 0, il = source.vertexColors.length; i < il; i ++ ) {
  5303. this.vertexColors[ i ] = source.vertexColors[ i ].clone();
  5304. }
  5305. return this;
  5306. }
  5307. };
  5308. // File:src/core/Face4.js
  5309. /**
  5310. * @author mrdoob / http://mrdoob.com/
  5311. */
  5312. THREE.Face4 = function ( a, b, c, d, normal, color, materialIndex ) {
  5313. console.warn( 'THREE.Face4 has been removed. A THREE.Face3 will be created instead.' );
  5314. return new THREE.Face3( a, b, c, normal, color, materialIndex );
  5315. };
  5316. // File:src/core/BufferAttribute.js
  5317. /**
  5318. * @author mrdoob / http://mrdoob.com/
  5319. */
  5320. THREE.BufferAttribute = function ( array, itemSize ) {
  5321. this.uuid = THREE.Math.generateUUID();
  5322. this.array = array;
  5323. this.itemSize = itemSize;
  5324. this.dynamic = false;
  5325. this.updateRange = { offset: 0, count: - 1 };
  5326. this.version = 0;
  5327. };
  5328. THREE.BufferAttribute.prototype = {
  5329. constructor: THREE.BufferAttribute,
  5330. get length() {
  5331. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Please use .count.' );
  5332. return this.array.length;
  5333. },
  5334. get count() {
  5335. return this.array.length / this.itemSize;
  5336. },
  5337. set needsUpdate( value ) {
  5338. if ( value === true ) this.version ++;
  5339. },
  5340. setDynamic: function ( value ) {
  5341. this.dynamic = value;
  5342. return this;
  5343. },
  5344. copy: function ( source ) {
  5345. this.array = new source.array.constructor( source.array );
  5346. this.itemSize = source.itemSize;
  5347. this.dynamic = source.dynamic;
  5348. return this;
  5349. },
  5350. copyAt: function ( index1, attribute, index2 ) {
  5351. index1 *= this.itemSize;
  5352. index2 *= attribute.itemSize;
  5353. for ( var i = 0, l = this.itemSize; i < l; i ++ ) {
  5354. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5355. }
  5356. return this;
  5357. },
  5358. copyArray: function ( array ) {
  5359. this.array.set( array );
  5360. return this;
  5361. },
  5362. copyColorsArray: function ( colors ) {
  5363. var array = this.array, offset = 0;
  5364. for ( var i = 0, l = colors.length; i < l; i ++ ) {
  5365. var color = colors[ i ];
  5366. if ( color === undefined ) {
  5367. console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
  5368. color = new THREE.Color();
  5369. }
  5370. array[ offset ++ ] = color.r;
  5371. array[ offset ++ ] = color.g;
  5372. array[ offset ++ ] = color.b;
  5373. }
  5374. return this;
  5375. },
  5376. copyIndicesArray: function ( indices ) {
  5377. var array = this.array, offset = 0;
  5378. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  5379. var index = indices[ i ];
  5380. array[ offset ++ ] = index.a;
  5381. array[ offset ++ ] = index.b;
  5382. array[ offset ++ ] = index.c;
  5383. }
  5384. return this;
  5385. },
  5386. copyVector2sArray: function ( vectors ) {
  5387. var array = this.array, offset = 0;
  5388. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5389. var vector = vectors[ i ];
  5390. if ( vector === undefined ) {
  5391. console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
  5392. vector = new THREE.Vector2();
  5393. }
  5394. array[ offset ++ ] = vector.x;
  5395. array[ offset ++ ] = vector.y;
  5396. }
  5397. return this;
  5398. },
  5399. copyVector3sArray: function ( vectors ) {
  5400. var array = this.array, offset = 0;
  5401. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5402. var vector = vectors[ i ];
  5403. if ( vector === undefined ) {
  5404. console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
  5405. vector = new THREE.Vector3();
  5406. }
  5407. array[ offset ++ ] = vector.x;
  5408. array[ offset ++ ] = vector.y;
  5409. array[ offset ++ ] = vector.z;
  5410. }
  5411. return this;
  5412. },
  5413. copyVector4sArray: function ( vectors ) {
  5414. var array = this.array, offset = 0;
  5415. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5416. var vector = vectors[ i ];
  5417. if ( vector === undefined ) {
  5418. console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i );
  5419. vector = new THREE.Vector4();
  5420. }
  5421. array[ offset ++ ] = vector.x;
  5422. array[ offset ++ ] = vector.y;
  5423. array[ offset ++ ] = vector.z;
  5424. array[ offset ++ ] = vector.w;
  5425. }
  5426. return this;
  5427. },
  5428. set: function ( value, offset ) {
  5429. if ( offset === undefined ) offset = 0;
  5430. this.array.set( value, offset );
  5431. return this;
  5432. },
  5433. getX: function ( index ) {
  5434. return this.array[ index * this.itemSize ];
  5435. },
  5436. setX: function ( index, x ) {
  5437. this.array[ index * this.itemSize ] = x;
  5438. return this;
  5439. },
  5440. getY: function ( index ) {
  5441. return this.array[ index * this.itemSize + 1 ];
  5442. },
  5443. setY: function ( index, y ) {
  5444. this.array[ index * this.itemSize + 1 ] = y;
  5445. return this;
  5446. },
  5447. getZ: function ( index ) {
  5448. return this.array[ index * this.itemSize + 2 ];
  5449. },
  5450. setZ: function ( index, z ) {
  5451. this.array[ index * this.itemSize + 2 ] = z;
  5452. return this;
  5453. },
  5454. getW: function ( index ) {
  5455. return this.array[ index * this.itemSize + 3 ];
  5456. },
  5457. setW: function ( index, w ) {
  5458. this.array[ index * this.itemSize + 3 ] = w;
  5459. return this;
  5460. },
  5461. setXY: function ( index, x, y ) {
  5462. index *= this.itemSize;
  5463. this.array[ index + 0 ] = x;
  5464. this.array[ index + 1 ] = y;
  5465. return this;
  5466. },
  5467. setXYZ: function ( index, x, y, z ) {
  5468. index *= this.itemSize;
  5469. this.array[ index + 0 ] = x;
  5470. this.array[ index + 1 ] = y;
  5471. this.array[ index + 2 ] = z;
  5472. return this;
  5473. },
  5474. setXYZW: function ( index, x, y, z, w ) {
  5475. index *= this.itemSize;
  5476. this.array[ index + 0 ] = x;
  5477. this.array[ index + 1 ] = y;
  5478. this.array[ index + 2 ] = z;
  5479. this.array[ index + 3 ] = w;
  5480. return this;
  5481. },
  5482. clone: function () {
  5483. return new this.constructor().copy( this );
  5484. }
  5485. };
  5486. //
  5487. THREE.Int8Attribute = function ( array, itemSize ) {
  5488. return new THREE.BufferAttribute( new Int8Array( array ), itemSize );
  5489. };
  5490. THREE.Uint8Attribute = function ( array, itemSize ) {
  5491. return new THREE.BufferAttribute( new Uint8Array( array ), itemSize );
  5492. };
  5493. THREE.Uint8ClampedAttribute = function ( array, itemSize ) {
  5494. return new THREE.BufferAttribute( new Uint8ClampedArray( array ), itemSize );
  5495. };
  5496. THREE.Int16Attribute = function ( array, itemSize ) {
  5497. return new THREE.BufferAttribute( new Int16Array( array ), itemSize );
  5498. };
  5499. THREE.Uint16Attribute = function ( array, itemSize ) {
  5500. return new THREE.BufferAttribute( new Uint16Array( array ), itemSize );
  5501. };
  5502. THREE.Int32Attribute = function ( array, itemSize ) {
  5503. return new THREE.BufferAttribute( new Int32Array( array ), itemSize );
  5504. };
  5505. THREE.Uint32Attribute = function ( array, itemSize ) {
  5506. return new THREE.BufferAttribute( new Uint32Array( array ), itemSize );
  5507. };
  5508. THREE.Float32Attribute = function ( array, itemSize ) {
  5509. return new THREE.BufferAttribute( new Float32Array( array ), itemSize );
  5510. };
  5511. THREE.Float64Attribute = function ( array, itemSize ) {
  5512. return new THREE.BufferAttribute( new Float64Array( array ), itemSize );
  5513. };
  5514. // Deprecated
  5515. THREE.DynamicBufferAttribute = function ( array, itemSize ) {
  5516. console.warn( 'THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setDynamic( true ) instead.' );
  5517. return new THREE.BufferAttribute( array, itemSize ).setDynamic( true );
  5518. };
  5519. // File:src/core/InstancedBufferAttribute.js
  5520. /**
  5521. * @author benaadams / https://twitter.com/ben_a_adams
  5522. */
  5523. THREE.InstancedBufferAttribute = function ( array, itemSize, meshPerAttribute ) {
  5524. THREE.BufferAttribute.call( this, array, itemSize );
  5525. this.meshPerAttribute = meshPerAttribute || 1;
  5526. };
  5527. THREE.InstancedBufferAttribute.prototype = Object.create( THREE.BufferAttribute.prototype );
  5528. THREE.InstancedBufferAttribute.prototype.constructor = THREE.InstancedBufferAttribute;
  5529. THREE.InstancedBufferAttribute.prototype.copy = function ( source ) {
  5530. THREE.BufferAttribute.prototype.copy.call( this, source );
  5531. this.meshPerAttribute = source.meshPerAttribute;
  5532. return this;
  5533. };
  5534. // File:src/core/InterleavedBuffer.js
  5535. /**
  5536. * @author benaadams / https://twitter.com/ben_a_adams
  5537. */
  5538. THREE.InterleavedBuffer = function ( array, stride ) {
  5539. this.uuid = THREE.Math.generateUUID();
  5540. this.array = array;
  5541. this.stride = stride;
  5542. this.dynamic = false;
  5543. this.updateRange = { offset: 0, count: - 1 };
  5544. this.version = 0;
  5545. };
  5546. THREE.InterleavedBuffer.prototype = {
  5547. constructor: THREE.InterleavedBuffer,
  5548. get length () {
  5549. return this.array.length;
  5550. },
  5551. get count () {
  5552. return this.array.length / this.stride;
  5553. },
  5554. set needsUpdate( value ) {
  5555. if ( value === true ) this.version ++;
  5556. },
  5557. setDynamic: function ( value ) {
  5558. this.dynamic = value;
  5559. return this;
  5560. },
  5561. copy: function ( source ) {
  5562. this.array = new source.array.constructor( source.array );
  5563. this.stride = source.stride;
  5564. this.dynamic = source.dynamic;
  5565. },
  5566. copyAt: function ( index1, attribute, index2 ) {
  5567. index1 *= this.stride;
  5568. index2 *= attribute.stride;
  5569. for ( var i = 0, l = this.stride; i < l; i ++ ) {
  5570. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5571. }
  5572. return this;
  5573. },
  5574. set: function ( value, offset ) {
  5575. if ( offset === undefined ) offset = 0;
  5576. this.array.set( value, offset );
  5577. return this;
  5578. },
  5579. clone: function () {
  5580. return new this.constructor().copy( this );
  5581. }
  5582. };
  5583. // File:src/core/InstancedInterleavedBuffer.js
  5584. /**
  5585. * @author benaadams / https://twitter.com/ben_a_adams
  5586. */
  5587. THREE.InstancedInterleavedBuffer = function ( array, stride, meshPerAttribute ) {
  5588. THREE.InterleavedBuffer.call( this, array, stride );
  5589. this.meshPerAttribute = meshPerAttribute || 1;
  5590. };
  5591. THREE.InstancedInterleavedBuffer.prototype = Object.create( THREE.InterleavedBuffer.prototype );
  5592. THREE.InstancedInterleavedBuffer.prototype.constructor = THREE.InstancedInterleavedBuffer;
  5593. THREE.InstancedInterleavedBuffer.prototype.copy = function ( source ) {
  5594. THREE.InterleavedBuffer.prototype.copy.call( this, source );
  5595. this.meshPerAttribute = source.meshPerAttribute;
  5596. return this;
  5597. };
  5598. // File:src/core/InterleavedBufferAttribute.js
  5599. /**
  5600. * @author benaadams / https://twitter.com/ben_a_adams
  5601. */
  5602. THREE.InterleavedBufferAttribute = function ( interleavedBuffer, itemSize, offset ) {
  5603. this.uuid = THREE.Math.generateUUID();
  5604. this.data = interleavedBuffer;
  5605. this.itemSize = itemSize;
  5606. this.offset = offset;
  5607. };
  5608. THREE.InterleavedBufferAttribute.prototype = {
  5609. constructor: THREE.InterleavedBufferAttribute,
  5610. get length() {
  5611. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Please use .count.' );
  5612. return this.array.length;
  5613. },
  5614. get count() {
  5615. return this.data.array.length / this.data.stride;
  5616. },
  5617. setX: function ( index, x ) {
  5618. this.data.array[ index * this.data.stride + this.offset ] = x;
  5619. return this;
  5620. },
  5621. setY: function ( index, y ) {
  5622. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  5623. return this;
  5624. },
  5625. setZ: function ( index, z ) {
  5626. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  5627. return this;
  5628. },
  5629. setW: function ( index, w ) {
  5630. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  5631. return this;
  5632. },
  5633. getX: function ( index ) {
  5634. return this.data.array[ index * this.data.stride + this.offset ];
  5635. },
  5636. getY: function ( index ) {
  5637. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  5638. },
  5639. getZ: function ( index ) {
  5640. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  5641. },
  5642. getW: function ( index ) {
  5643. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  5644. },
  5645. setXY: function ( index, x, y ) {
  5646. index = index * this.data.stride + this.offset;
  5647. this.data.array[ index + 0 ] = x;
  5648. this.data.array[ index + 1 ] = y;
  5649. return this;
  5650. },
  5651. setXYZ: function ( index, x, y, z ) {
  5652. index = index * this.data.stride + this.offset;
  5653. this.data.array[ index + 0 ] = x;
  5654. this.data.array[ index + 1 ] = y;
  5655. this.data.array[ index + 2 ] = z;
  5656. return this;
  5657. },
  5658. setXYZW: function ( index, x, y, z, w ) {
  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. this.data.array[ index + 3 ] = w;
  5664. return this;
  5665. }
  5666. };
  5667. // File:src/core/Geometry.js
  5668. /**
  5669. * @author mrdoob / http://mrdoob.com/
  5670. * @author kile / http://kile.stravaganza.org/
  5671. * @author alteredq / http://alteredqualia.com/
  5672. * @author mikael emtinger / http://gomo.se/
  5673. * @author zz85 / http://www.lab4games.net/zz85/blog
  5674. * @author bhouston / http://clara.io
  5675. */
  5676. THREE.Geometry = function () {
  5677. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  5678. this.uuid = THREE.Math.generateUUID();
  5679. this.name = '';
  5680. this.type = 'Geometry';
  5681. this.vertices = [];
  5682. this.colors = [];
  5683. this.faces = [];
  5684. this.faceVertexUvs = [ [] ];
  5685. this.morphTargets = [];
  5686. this.morphNormals = [];
  5687. this.skinWeights = [];
  5688. this.skinIndices = [];
  5689. this.lineDistances = [];
  5690. this.boundingBox = null;
  5691. this.boundingSphere = null;
  5692. // update flags
  5693. this.verticesNeedUpdate = false;
  5694. this.elementsNeedUpdate = false;
  5695. this.uvsNeedUpdate = false;
  5696. this.normalsNeedUpdate = false;
  5697. this.colorsNeedUpdate = false;
  5698. this.lineDistancesNeedUpdate = false;
  5699. this.groupsNeedUpdate = false;
  5700. };
  5701. THREE.Geometry.prototype = {
  5702. constructor: THREE.Geometry,
  5703. applyMatrix: function ( matrix ) {
  5704. var normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  5705. for ( var i = 0, il = this.vertices.length; i < il; i ++ ) {
  5706. var vertex = this.vertices[ i ];
  5707. vertex.applyMatrix4( matrix );
  5708. }
  5709. for ( var i = 0, il = this.faces.length; i < il; i ++ ) {
  5710. var face = this.faces[ i ];
  5711. face.normal.applyMatrix3( normalMatrix ).normalize();
  5712. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  5713. face.vertexNormals[ j ].applyMatrix3( normalMatrix ).normalize();
  5714. }
  5715. }
  5716. if ( this.boundingBox !== null ) {
  5717. this.computeBoundingBox();
  5718. }
  5719. if ( this.boundingSphere !== null ) {
  5720. this.computeBoundingSphere();
  5721. }
  5722. this.verticesNeedUpdate = true;
  5723. this.normalsNeedUpdate = true;
  5724. },
  5725. rotateX: function () {
  5726. // rotate geometry around world x-axis
  5727. var m1;
  5728. return function rotateX( angle ) {
  5729. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5730. m1.makeRotationX( angle );
  5731. this.applyMatrix( m1 );
  5732. return this;
  5733. };
  5734. }(),
  5735. rotateY: function () {
  5736. // rotate geometry around world y-axis
  5737. var m1;
  5738. return function rotateY( angle ) {
  5739. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5740. m1.makeRotationY( angle );
  5741. this.applyMatrix( m1 );
  5742. return this;
  5743. };
  5744. }(),
  5745. rotateZ: function () {
  5746. // rotate geometry around world z-axis
  5747. var m1;
  5748. return function rotateZ( angle ) {
  5749. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5750. m1.makeRotationZ( angle );
  5751. this.applyMatrix( m1 );
  5752. return this;
  5753. };
  5754. }(),
  5755. translate: function () {
  5756. // translate geometry
  5757. var m1;
  5758. return function translate( x, y, z ) {
  5759. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5760. m1.makeTranslation( x, y, z );
  5761. this.applyMatrix( m1 );
  5762. return this;
  5763. };
  5764. }(),
  5765. scale: function () {
  5766. // scale geometry
  5767. var m1;
  5768. return function scale( x, y, z ) {
  5769. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5770. m1.makeScale( x, y, z );
  5771. this.applyMatrix( m1 );
  5772. return this;
  5773. };
  5774. }(),
  5775. lookAt: function () {
  5776. var obj;
  5777. return function lookAt( vector ) {
  5778. if ( obj === undefined ) obj = new THREE.Object3D();
  5779. obj.lookAt( vector );
  5780. obj.updateMatrix();
  5781. this.applyMatrix( obj.matrix );
  5782. };
  5783. }(),
  5784. fromBufferGeometry: function ( geometry ) {
  5785. var scope = this;
  5786. var indices = geometry.index !== null ? geometry.index.array : undefined;
  5787. var attributes = geometry.attributes;
  5788. var vertices = attributes.position.array;
  5789. var normals = attributes.normal !== undefined ? attributes.normal.array : undefined;
  5790. var colors = attributes.color !== undefined ? attributes.color.array : undefined;
  5791. var uvs = attributes.uv !== undefined ? attributes.uv.array : undefined;
  5792. var uvs2 = attributes.uv2 !== undefined ? attributes.uv2.array : undefined;
  5793. if ( uvs2 !== undefined ) this.faceVertexUvs[ 1 ] = [];
  5794. var tempNormals = [];
  5795. var tempUVs = [];
  5796. var tempUVs2 = [];
  5797. for ( var i = 0, j = 0, k = 0; i < vertices.length; i += 3, j += 2, k += 4 ) {
  5798. scope.vertices.push( new THREE.Vector3( vertices[ i ], vertices[ i + 1 ], vertices[ i + 2 ] ) );
  5799. if ( normals !== undefined ) {
  5800. tempNormals.push( new THREE.Vector3( normals[ i ], normals[ i + 1 ], normals[ i + 2 ] ) );
  5801. }
  5802. if ( colors !== undefined ) {
  5803. scope.colors.push( new THREE.Color( colors[ i ], colors[ i + 1 ], colors[ i + 2 ] ) );
  5804. }
  5805. if ( uvs !== undefined ) {
  5806. tempUVs.push( new THREE.Vector2( uvs[ j ], uvs[ j + 1 ] ) );
  5807. }
  5808. if ( uvs2 !== undefined ) {
  5809. tempUVs2.push( new THREE.Vector2( uvs2[ j ], uvs2[ j + 1 ] ) );
  5810. }
  5811. }
  5812. function addFace( a, b, c ) {
  5813. var vertexNormals = normals !== undefined ? [ tempNormals[ a ].clone(), tempNormals[ b ].clone(), tempNormals[ c ].clone() ] : [];
  5814. var vertexColors = colors !== undefined ? [ scope.colors[ a ].clone(), scope.colors[ b ].clone(), scope.colors[ c ].clone() ] : [];
  5815. var face = new THREE.Face3( a, b, c, vertexNormals, vertexColors );
  5816. scope.faces.push( face );
  5817. if ( uvs !== undefined ) {
  5818. scope.faceVertexUvs[ 0 ].push( [ tempUVs[ a ].clone(), tempUVs[ b ].clone(), tempUVs[ c ].clone() ] );
  5819. }
  5820. if ( uvs2 !== undefined ) {
  5821. scope.faceVertexUvs[ 1 ].push( [ tempUVs2[ a ].clone(), tempUVs2[ b ].clone(), tempUVs2[ c ].clone() ] );
  5822. }
  5823. };
  5824. if ( indices !== undefined ) {
  5825. var groups = geometry.groups;
  5826. if ( groups.length > 0 ) {
  5827. for ( var i = 0; i < groups.length; i ++ ) {
  5828. var group = groups[ i ];
  5829. var start = group.start;
  5830. var count = group.count;
  5831. for ( var j = start, jl = start + count; j < jl; j += 3 ) {
  5832. addFace( indices[ j ], indices[ j + 1 ], indices[ j + 2 ] );
  5833. }
  5834. }
  5835. } else {
  5836. for ( var i = 0; i < indices.length; i += 3 ) {
  5837. addFace( indices[ i ], indices[ i + 1 ], indices[ i + 2 ] );
  5838. }
  5839. }
  5840. } else {
  5841. for ( var i = 0; i < vertices.length / 3; i += 3 ) {
  5842. addFace( i, i + 1, i + 2 );
  5843. }
  5844. }
  5845. this.computeFaceNormals();
  5846. if ( geometry.boundingBox !== null ) {
  5847. this.boundingBox = geometry.boundingBox.clone();
  5848. }
  5849. if ( geometry.boundingSphere !== null ) {
  5850. this.boundingSphere = geometry.boundingSphere.clone();
  5851. }
  5852. return this;
  5853. },
  5854. center: function () {
  5855. this.computeBoundingBox();
  5856. var offset = this.boundingBox.center().negate();
  5857. this.translate( offset.x, offset.y, offset.z );
  5858. return offset;
  5859. },
  5860. normalize: function () {
  5861. this.computeBoundingSphere();
  5862. var center = this.boundingSphere.center;
  5863. var radius = this.boundingSphere.radius;
  5864. var s = radius === 0 ? 1 : 1.0 / radius;
  5865. var matrix = new THREE.Matrix4();
  5866. matrix.set(
  5867. s, 0, 0, - s * center.x,
  5868. 0, s, 0, - s * center.y,
  5869. 0, 0, s, - s * center.z,
  5870. 0, 0, 0, 1
  5871. );
  5872. this.applyMatrix( matrix );
  5873. return this;
  5874. },
  5875. computeFaceNormals: function () {
  5876. var cb = new THREE.Vector3(), ab = new THREE.Vector3();
  5877. for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5878. var face = this.faces[ f ];
  5879. var vA = this.vertices[ face.a ];
  5880. var vB = this.vertices[ face.b ];
  5881. var vC = this.vertices[ face.c ];
  5882. cb.subVectors( vC, vB );
  5883. ab.subVectors( vA, vB );
  5884. cb.cross( ab );
  5885. cb.normalize();
  5886. face.normal.copy( cb );
  5887. }
  5888. },
  5889. computeVertexNormals: function ( areaWeighted ) {
  5890. var v, vl, f, fl, face, vertices;
  5891. vertices = new Array( this.vertices.length );
  5892. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5893. vertices[ v ] = new THREE.Vector3();
  5894. }
  5895. if ( areaWeighted ) {
  5896. // vertex normals weighted by triangle areas
  5897. // http://www.iquilezles.org/www/articles/normals/normals.htm
  5898. var vA, vB, vC;
  5899. var cb = new THREE.Vector3(), ab = new THREE.Vector3();
  5900. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5901. face = this.faces[ f ];
  5902. vA = this.vertices[ face.a ];
  5903. vB = this.vertices[ face.b ];
  5904. vC = this.vertices[ face.c ];
  5905. cb.subVectors( vC, vB );
  5906. ab.subVectors( vA, vB );
  5907. cb.cross( ab );
  5908. vertices[ face.a ].add( cb );
  5909. vertices[ face.b ].add( cb );
  5910. vertices[ face.c ].add( cb );
  5911. }
  5912. } else {
  5913. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5914. face = this.faces[ f ];
  5915. vertices[ face.a ].add( face.normal );
  5916. vertices[ face.b ].add( face.normal );
  5917. vertices[ face.c ].add( face.normal );
  5918. }
  5919. }
  5920. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5921. vertices[ v ].normalize();
  5922. }
  5923. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5924. face = this.faces[ f ];
  5925. var vertexNormals = face.vertexNormals;
  5926. if ( vertexNormals.length === 3 ) {
  5927. vertexNormals[ 0 ].copy( vertices[ face.a ] );
  5928. vertexNormals[ 1 ].copy( vertices[ face.b ] );
  5929. vertexNormals[ 2 ].copy( vertices[ face.c ] );
  5930. } else {
  5931. vertexNormals[ 0 ] = vertices[ face.a ].clone();
  5932. vertexNormals[ 1 ] = vertices[ face.b ].clone();
  5933. vertexNormals[ 2 ] = vertices[ face.c ].clone();
  5934. }
  5935. }
  5936. },
  5937. computeMorphNormals: function () {
  5938. var i, il, f, fl, face;
  5939. // save original normals
  5940. // - create temp variables on first access
  5941. // otherwise just copy (for faster repeated calls)
  5942. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5943. face = this.faces[ f ];
  5944. if ( ! face.__originalFaceNormal ) {
  5945. face.__originalFaceNormal = face.normal.clone();
  5946. } else {
  5947. face.__originalFaceNormal.copy( face.normal );
  5948. }
  5949. if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
  5950. for ( i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
  5951. if ( ! face.__originalVertexNormals[ i ] ) {
  5952. face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
  5953. } else {
  5954. face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
  5955. }
  5956. }
  5957. }
  5958. // use temp geometry to compute face and vertex normals for each morph
  5959. var tmpGeo = new THREE.Geometry();
  5960. tmpGeo.faces = this.faces;
  5961. for ( i = 0, il = this.morphTargets.length; i < il; i ++ ) {
  5962. // create on first access
  5963. if ( ! this.morphNormals[ i ] ) {
  5964. this.morphNormals[ i ] = {};
  5965. this.morphNormals[ i ].faceNormals = [];
  5966. this.morphNormals[ i ].vertexNormals = [];
  5967. var dstNormalsFace = this.morphNormals[ i ].faceNormals;
  5968. var dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
  5969. var faceNormal, vertexNormals;
  5970. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5971. faceNormal = new THREE.Vector3();
  5972. vertexNormals = { a: new THREE.Vector3(), b: new THREE.Vector3(), c: new THREE.Vector3() };
  5973. dstNormalsFace.push( faceNormal );
  5974. dstNormalsVertex.push( vertexNormals );
  5975. }
  5976. }
  5977. var morphNormals = this.morphNormals[ i ];
  5978. // set vertices to morph target
  5979. tmpGeo.vertices = this.morphTargets[ i ].vertices;
  5980. // compute morph normals
  5981. tmpGeo.computeFaceNormals();
  5982. tmpGeo.computeVertexNormals();
  5983. // store morph normals
  5984. var faceNormal, vertexNormals;
  5985. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5986. face = this.faces[ f ];
  5987. faceNormal = morphNormals.faceNormals[ f ];
  5988. vertexNormals = morphNormals.vertexNormals[ f ];
  5989. faceNormal.copy( face.normal );
  5990. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  5991. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  5992. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  5993. }
  5994. }
  5995. // restore original normals
  5996. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5997. face = this.faces[ f ];
  5998. face.normal = face.__originalFaceNormal;
  5999. face.vertexNormals = face.__originalVertexNormals;
  6000. }
  6001. },
  6002. computeTangents: function () {
  6003. console.warn( 'THREE.Geometry: .computeTangents() has been removed.' );
  6004. },
  6005. computeLineDistances: function () {
  6006. var d = 0;
  6007. var vertices = this.vertices;
  6008. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  6009. if ( i > 0 ) {
  6010. d += vertices[ i ].distanceTo( vertices[ i - 1 ] );
  6011. }
  6012. this.lineDistances[ i ] = d;
  6013. }
  6014. },
  6015. computeBoundingBox: function () {
  6016. if ( this.boundingBox === null ) {
  6017. this.boundingBox = new THREE.Box3();
  6018. }
  6019. this.boundingBox.setFromPoints( this.vertices );
  6020. },
  6021. computeBoundingSphere: function () {
  6022. if ( this.boundingSphere === null ) {
  6023. this.boundingSphere = new THREE.Sphere();
  6024. }
  6025. this.boundingSphere.setFromPoints( this.vertices );
  6026. },
  6027. merge: function ( geometry, matrix, materialIndexOffset ) {
  6028. if ( geometry instanceof THREE.Geometry === false ) {
  6029. console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry );
  6030. return;
  6031. }
  6032. var normalMatrix,
  6033. vertexOffset = this.vertices.length,
  6034. vertices1 = this.vertices,
  6035. vertices2 = geometry.vertices,
  6036. faces1 = this.faces,
  6037. faces2 = geometry.faces,
  6038. uvs1 = this.faceVertexUvs[ 0 ],
  6039. uvs2 = geometry.faceVertexUvs[ 0 ];
  6040. if ( materialIndexOffset === undefined ) materialIndexOffset = 0;
  6041. if ( matrix !== undefined ) {
  6042. normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  6043. }
  6044. // vertices
  6045. for ( var i = 0, il = vertices2.length; i < il; i ++ ) {
  6046. var vertex = vertices2[ i ];
  6047. var vertexCopy = vertex.clone();
  6048. if ( matrix !== undefined ) vertexCopy.applyMatrix4( matrix );
  6049. vertices1.push( vertexCopy );
  6050. }
  6051. // faces
  6052. for ( i = 0, il = faces2.length; i < il; i ++ ) {
  6053. var face = faces2[ i ], faceCopy, normal, color,
  6054. faceVertexNormals = face.vertexNormals,
  6055. faceVertexColors = face.vertexColors;
  6056. faceCopy = new THREE.Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset );
  6057. faceCopy.normal.copy( face.normal );
  6058. if ( normalMatrix !== undefined ) {
  6059. faceCopy.normal.applyMatrix3( normalMatrix ).normalize();
  6060. }
  6061. for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
  6062. normal = faceVertexNormals[ j ].clone();
  6063. if ( normalMatrix !== undefined ) {
  6064. normal.applyMatrix3( normalMatrix ).normalize();
  6065. }
  6066. faceCopy.vertexNormals.push( normal );
  6067. }
  6068. faceCopy.color.copy( face.color );
  6069. for ( var j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
  6070. color = faceVertexColors[ j ];
  6071. faceCopy.vertexColors.push( color.clone() );
  6072. }
  6073. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  6074. faces1.push( faceCopy );
  6075. }
  6076. // uvs
  6077. for ( i = 0, il = uvs2.length; i < il; i ++ ) {
  6078. var uv = uvs2[ i ], uvCopy = [];
  6079. if ( uv === undefined ) {
  6080. continue;
  6081. }
  6082. for ( var j = 0, jl = uv.length; j < jl; j ++ ) {
  6083. uvCopy.push( uv[ j ].clone() );
  6084. }
  6085. uvs1.push( uvCopy );
  6086. }
  6087. },
  6088. mergeMesh: function ( mesh ) {
  6089. if ( mesh instanceof THREE.Mesh === false ) {
  6090. console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh );
  6091. return;
  6092. }
  6093. mesh.matrixAutoUpdate && mesh.updateMatrix();
  6094. this.merge( mesh.geometry, mesh.matrix );
  6095. },
  6096. /*
  6097. * Checks for duplicate vertices with hashmap.
  6098. * Duplicated vertices are removed
  6099. * and faces' vertices are updated.
  6100. */
  6101. mergeVertices: function () {
  6102. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  6103. var unique = [], changes = [];
  6104. var v, key;
  6105. var precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001
  6106. var precision = Math.pow( 10, precisionPoints );
  6107. var i, il, face;
  6108. var indices, j, jl;
  6109. for ( i = 0, il = this.vertices.length; i < il; i ++ ) {
  6110. v = this.vertices[ i ];
  6111. key = Math.round( v.x * precision ) + '_' + Math.round( v.y * precision ) + '_' + Math.round( v.z * precision );
  6112. if ( verticesMap[ key ] === undefined ) {
  6113. verticesMap[ key ] = i;
  6114. unique.push( this.vertices[ i ] );
  6115. changes[ i ] = unique.length - 1;
  6116. } else {
  6117. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  6118. changes[ i ] = changes[ verticesMap[ key ] ];
  6119. }
  6120. }
  6121. // if faces are completely degenerate after merging vertices, we
  6122. // have to remove them from the geometry.
  6123. var faceIndicesToRemove = [];
  6124. for ( i = 0, il = this.faces.length; i < il; i ++ ) {
  6125. face = this.faces[ i ];
  6126. face.a = changes[ face.a ];
  6127. face.b = changes[ face.b ];
  6128. face.c = changes[ face.c ];
  6129. indices = [ face.a, face.b, face.c ];
  6130. var dupIndex = - 1;
  6131. // if any duplicate vertices are found in a Face3
  6132. // we have to remove the face as nothing can be saved
  6133. for ( var n = 0; n < 3; n ++ ) {
  6134. if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) {
  6135. dupIndex = n;
  6136. faceIndicesToRemove.push( i );
  6137. break;
  6138. }
  6139. }
  6140. }
  6141. for ( i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
  6142. var idx = faceIndicesToRemove[ i ];
  6143. this.faces.splice( idx, 1 );
  6144. for ( j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {
  6145. this.faceVertexUvs[ j ].splice( idx, 1 );
  6146. }
  6147. }
  6148. // Use unique set of vertices
  6149. var diff = this.vertices.length - unique.length;
  6150. this.vertices = unique;
  6151. return diff;
  6152. },
  6153. sortFacesByMaterialIndex: function () {
  6154. var faces = this.faces;
  6155. var length = faces.length;
  6156. // tag faces
  6157. for ( var i = 0; i < length; i ++ ) {
  6158. faces[ i ]._id = i;
  6159. }
  6160. // sort faces
  6161. function materialIndexSort( a, b ) {
  6162. return a.materialIndex - b.materialIndex;
  6163. }
  6164. faces.sort( materialIndexSort );
  6165. // sort uvs
  6166. var uvs1 = this.faceVertexUvs[ 0 ];
  6167. var uvs2 = this.faceVertexUvs[ 1 ];
  6168. var newUvs1, newUvs2;
  6169. if ( uvs1 && uvs1.length === length ) newUvs1 = [];
  6170. if ( uvs2 && uvs2.length === length ) newUvs2 = [];
  6171. for ( var i = 0; i < length; i ++ ) {
  6172. var id = faces[ i ]._id;
  6173. if ( newUvs1 ) newUvs1.push( uvs1[ id ] );
  6174. if ( newUvs2 ) newUvs2.push( uvs2[ id ] );
  6175. }
  6176. if ( newUvs1 ) this.faceVertexUvs[ 0 ] = newUvs1;
  6177. if ( newUvs2 ) this.faceVertexUvs[ 1 ] = newUvs2;
  6178. },
  6179. toJSON: function () {
  6180. var data = {
  6181. metadata: {
  6182. version: 4.4,
  6183. type: 'Geometry',
  6184. generator: 'Geometry.toJSON'
  6185. }
  6186. };
  6187. // standard Geometry serialization
  6188. data.uuid = this.uuid;
  6189. data.type = this.type;
  6190. if ( this.name !== '' ) data.name = this.name;
  6191. if ( this.parameters !== undefined ) {
  6192. var parameters = this.parameters;
  6193. for ( var key in parameters ) {
  6194. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  6195. }
  6196. return data;
  6197. }
  6198. var vertices = [];
  6199. for ( var i = 0; i < this.vertices.length; i ++ ) {
  6200. var vertex = this.vertices[ i ];
  6201. vertices.push( vertex.x, vertex.y, vertex.z );
  6202. }
  6203. var faces = [];
  6204. var normals = [];
  6205. var normalsHash = {};
  6206. var colors = [];
  6207. var colorsHash = {};
  6208. var uvs = [];
  6209. var uvsHash = {};
  6210. for ( var i = 0; i < this.faces.length; i ++ ) {
  6211. var face = this.faces[ i ];
  6212. var hasMaterial = true;
  6213. var hasFaceUv = false; // deprecated
  6214. var hasFaceVertexUv = this.faceVertexUvs[ 0 ][ i ] !== undefined;
  6215. var hasFaceNormal = face.normal.length() > 0;
  6216. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  6217. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  6218. var hasFaceVertexColor = face.vertexColors.length > 0;
  6219. var faceType = 0;
  6220. faceType = setBit( faceType, 0, 0 ); // isQuad
  6221. faceType = setBit( faceType, 1, hasMaterial );
  6222. faceType = setBit( faceType, 2, hasFaceUv );
  6223. faceType = setBit( faceType, 3, hasFaceVertexUv );
  6224. faceType = setBit( faceType, 4, hasFaceNormal );
  6225. faceType = setBit( faceType, 5, hasFaceVertexNormal );
  6226. faceType = setBit( faceType, 6, hasFaceColor );
  6227. faceType = setBit( faceType, 7, hasFaceVertexColor );
  6228. faces.push( faceType );
  6229. faces.push( face.a, face.b, face.c );
  6230. faces.push( face.materialIndex );
  6231. if ( hasFaceVertexUv ) {
  6232. var faceVertexUvs = this.faceVertexUvs[ 0 ][ i ];
  6233. faces.push(
  6234. getUvIndex( faceVertexUvs[ 0 ] ),
  6235. getUvIndex( faceVertexUvs[ 1 ] ),
  6236. getUvIndex( faceVertexUvs[ 2 ] )
  6237. );
  6238. }
  6239. if ( hasFaceNormal ) {
  6240. faces.push( getNormalIndex( face.normal ) );
  6241. }
  6242. if ( hasFaceVertexNormal ) {
  6243. var vertexNormals = face.vertexNormals;
  6244. faces.push(
  6245. getNormalIndex( vertexNormals[ 0 ] ),
  6246. getNormalIndex( vertexNormals[ 1 ] ),
  6247. getNormalIndex( vertexNormals[ 2 ] )
  6248. );
  6249. }
  6250. if ( hasFaceColor ) {
  6251. faces.push( getColorIndex( face.color ) );
  6252. }
  6253. if ( hasFaceVertexColor ) {
  6254. var vertexColors = face.vertexColors;
  6255. faces.push(
  6256. getColorIndex( vertexColors[ 0 ] ),
  6257. getColorIndex( vertexColors[ 1 ] ),
  6258. getColorIndex( vertexColors[ 2 ] )
  6259. );
  6260. }
  6261. }
  6262. function setBit( value, position, enabled ) {
  6263. return enabled ? value | ( 1 << position ) : value & ( ~ ( 1 << position ) );
  6264. }
  6265. function getNormalIndex( normal ) {
  6266. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  6267. if ( normalsHash[ hash ] !== undefined ) {
  6268. return normalsHash[ hash ];
  6269. }
  6270. normalsHash[ hash ] = normals.length / 3;
  6271. normals.push( normal.x, normal.y, normal.z );
  6272. return normalsHash[ hash ];
  6273. }
  6274. function getColorIndex( color ) {
  6275. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  6276. if ( colorsHash[ hash ] !== undefined ) {
  6277. return colorsHash[ hash ];
  6278. }
  6279. colorsHash[ hash ] = colors.length;
  6280. colors.push( color.getHex() );
  6281. return colorsHash[ hash ];
  6282. }
  6283. function getUvIndex( uv ) {
  6284. var hash = uv.x.toString() + uv.y.toString();
  6285. if ( uvsHash[ hash ] !== undefined ) {
  6286. return uvsHash[ hash ];
  6287. }
  6288. uvsHash[ hash ] = uvs.length / 2;
  6289. uvs.push( uv.x, uv.y );
  6290. return uvsHash[ hash ];
  6291. }
  6292. data.data = {};
  6293. data.data.vertices = vertices;
  6294. data.data.normals = normals;
  6295. if ( colors.length > 0 ) data.data.colors = colors;
  6296. if ( uvs.length > 0 ) data.data.uvs = [ uvs ]; // temporal backward compatibility
  6297. data.data.faces = faces;
  6298. return data;
  6299. },
  6300. clone: function () {
  6301. // Handle primitives
  6302. var parameters = this.parameters;
  6303. if ( parameters !== undefined ) {
  6304. var values = [];
  6305. for ( var key in parameters ) {
  6306. values.push( parameters[ key ] );
  6307. }
  6308. var geometry = Object.create( this.constructor.prototype );
  6309. this.constructor.apply( geometry, values );
  6310. return geometry;
  6311. }
  6312. return new this.constructor().copy( this );
  6313. },
  6314. copy: function ( source ) {
  6315. this.vertices = [];
  6316. this.faces = [];
  6317. this.faceVertexUvs = [ [] ];
  6318. var vertices = source.vertices;
  6319. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  6320. this.vertices.push( vertices[ i ].clone() );
  6321. }
  6322. var faces = source.faces;
  6323. for ( var i = 0, il = faces.length; i < il; i ++ ) {
  6324. this.faces.push( faces[ i ].clone() );
  6325. }
  6326. for ( var i = 0, il = source.faceVertexUvs.length; i < il; i ++ ) {
  6327. var faceVertexUvs = source.faceVertexUvs[ i ];
  6328. if ( this.faceVertexUvs[ i ] === undefined ) {
  6329. this.faceVertexUvs[ i ] = [];
  6330. }
  6331. for ( var j = 0, jl = faceVertexUvs.length; j < jl; j ++ ) {
  6332. var uvs = faceVertexUvs[ j ], uvsCopy = [];
  6333. for ( var k = 0, kl = uvs.length; k < kl; k ++ ) {
  6334. var uv = uvs[ k ];
  6335. uvsCopy.push( uv.clone() );
  6336. }
  6337. this.faceVertexUvs[ i ].push( uvsCopy );
  6338. }
  6339. }
  6340. return this;
  6341. },
  6342. dispose: function () {
  6343. this.dispatchEvent( { type: 'dispose' } );
  6344. }
  6345. };
  6346. THREE.EventDispatcher.prototype.apply( THREE.Geometry.prototype );
  6347. THREE.GeometryIdCount = 0;
  6348. // File:src/core/DirectGeometry.js
  6349. /**
  6350. * @author mrdoob / http://mrdoob.com/
  6351. */
  6352. THREE.DirectGeometry = function () {
  6353. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  6354. this.uuid = THREE.Math.generateUUID();
  6355. this.name = '';
  6356. this.type = 'DirectGeometry';
  6357. this.indices = [];
  6358. this.vertices = [];
  6359. this.normals = [];
  6360. this.colors = [];
  6361. this.uvs = [];
  6362. this.uvs2 = [];
  6363. this.groups = [];
  6364. this.morphTargets = {};
  6365. this.skinWeights = [];
  6366. this.skinIndices = [];
  6367. // this.lineDistances = [];
  6368. this.boundingBox = null;
  6369. this.boundingSphere = null;
  6370. // update flags
  6371. this.verticesNeedUpdate = false;
  6372. this.normalsNeedUpdate = false;
  6373. this.colorsNeedUpdate = false;
  6374. this.uvsNeedUpdate = false;
  6375. this.groupsNeedUpdate = false;
  6376. };
  6377. THREE.DirectGeometry.prototype = {
  6378. constructor: THREE.DirectGeometry,
  6379. computeBoundingBox: THREE.Geometry.prototype.computeBoundingBox,
  6380. computeBoundingSphere: THREE.Geometry.prototype.computeBoundingSphere,
  6381. computeFaceNormals: function () {
  6382. console.warn( 'THREE.DirectGeometry: computeFaceNormals() is not a method of this type of geometry.' );
  6383. },
  6384. computeVertexNormals: function () {
  6385. console.warn( 'THREE.DirectGeometry: computeVertexNormals() is not a method of this type of geometry.' );
  6386. },
  6387. computeGroups: function ( geometry ) {
  6388. var group;
  6389. var groups = [];
  6390. var materialIndex;
  6391. var faces = geometry.faces;
  6392. for ( var i = 0; i < faces.length; i ++ ) {
  6393. var face = faces[ i ];
  6394. // materials
  6395. if ( face.materialIndex !== materialIndex ) {
  6396. materialIndex = face.materialIndex;
  6397. if ( group !== undefined ) {
  6398. group.count = ( i * 3 ) - group.start;
  6399. groups.push( group );
  6400. }
  6401. group = {
  6402. start: i * 3,
  6403. materialIndex: materialIndex
  6404. };
  6405. }
  6406. }
  6407. if ( group !== undefined ) {
  6408. group.count = ( i * 3 ) - group.start;
  6409. groups.push( group );
  6410. }
  6411. this.groups = groups;
  6412. },
  6413. fromGeometry: function ( geometry ) {
  6414. var faces = geometry.faces;
  6415. var vertices = geometry.vertices;
  6416. var faceVertexUvs = geometry.faceVertexUvs;
  6417. var hasFaceVertexUv = faceVertexUvs[ 0 ] && faceVertexUvs[ 0 ].length > 0;
  6418. var hasFaceVertexUv2 = faceVertexUvs[ 1 ] && faceVertexUvs[ 1 ].length > 0;
  6419. // morphs
  6420. var morphTargets = geometry.morphTargets;
  6421. var morphTargetsLength = morphTargets.length;
  6422. if ( morphTargetsLength > 0 ) {
  6423. var morphTargetsPosition = [];
  6424. for ( var i = 0; i < morphTargetsLength; i ++ ) {
  6425. morphTargetsPosition[ i ] = [];
  6426. }
  6427. this.morphTargets.position = morphTargetsPosition;
  6428. }
  6429. var morphNormals = geometry.morphNormals;
  6430. var morphNormalsLength = morphNormals.length;
  6431. if ( morphNormalsLength > 0 ) {
  6432. var morphTargetsNormal = [];
  6433. for ( var i = 0; i < morphNormalsLength; i ++ ) {
  6434. morphTargetsNormal[ i ] = [];
  6435. }
  6436. this.morphTargets.normal = morphTargetsNormal;
  6437. }
  6438. // skins
  6439. var skinIndices = geometry.skinIndices;
  6440. var skinWeights = geometry.skinWeights;
  6441. var hasSkinIndices = skinIndices.length === vertices.length;
  6442. var hasSkinWeights = skinWeights.length === vertices.length;
  6443. //
  6444. for ( var i = 0; i < faces.length; i ++ ) {
  6445. var face = faces[ i ];
  6446. this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] );
  6447. var vertexNormals = face.vertexNormals;
  6448. if ( vertexNormals.length === 3 ) {
  6449. this.normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
  6450. } else {
  6451. var normal = face.normal;
  6452. this.normals.push( normal, normal, normal );
  6453. }
  6454. var vertexColors = face.vertexColors;
  6455. if ( vertexColors.length === 3 ) {
  6456. this.colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
  6457. } else {
  6458. var color = face.color;
  6459. this.colors.push( color, color, color );
  6460. }
  6461. if ( hasFaceVertexUv === true ) {
  6462. var vertexUvs = faceVertexUvs[ 0 ][ i ];
  6463. if ( vertexUvs !== undefined ) {
  6464. this.uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6465. } else {
  6466. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', i );
  6467. this.uvs.push( new THREE.Vector2(), new THREE.Vector2(), new THREE.Vector2() );
  6468. }
  6469. }
  6470. if ( hasFaceVertexUv2 === true ) {
  6471. var vertexUvs = faceVertexUvs[ 1 ][ i ];
  6472. if ( vertexUvs !== undefined ) {
  6473. this.uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6474. } else {
  6475. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', i );
  6476. this.uvs2.push( new THREE.Vector2(), new THREE.Vector2(), new THREE.Vector2() );
  6477. }
  6478. }
  6479. // morphs
  6480. for ( var j = 0; j < morphTargetsLength; j ++ ) {
  6481. var morphTarget = morphTargets[ j ].vertices;
  6482. morphTargetsPosition[ j ].push( morphTarget[ face.a ], morphTarget[ face.b ], morphTarget[ face.c ] );
  6483. }
  6484. for ( var j = 0; j < morphNormalsLength; j ++ ) {
  6485. var morphNormal = morphNormals[ j ].vertexNormals[ i ];
  6486. morphTargetsNormal[ j ].push( morphNormal.a, morphNormal.b, morphNormal.c );
  6487. }
  6488. // skins
  6489. if ( hasSkinIndices ) {
  6490. this.skinIndices.push( skinIndices[ face.a ], skinIndices[ face.b ], skinIndices[ face.c ] );
  6491. }
  6492. if ( hasSkinWeights ) {
  6493. this.skinWeights.push( skinWeights[ face.a ], skinWeights[ face.b ], skinWeights[ face.c ] );
  6494. }
  6495. }
  6496. this.computeGroups( geometry );
  6497. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6498. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6499. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6500. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6501. this.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6502. return this;
  6503. },
  6504. dispose: function () {
  6505. this.dispatchEvent( { type: 'dispose' } );
  6506. }
  6507. };
  6508. THREE.EventDispatcher.prototype.apply( THREE.DirectGeometry.prototype );
  6509. // File:src/core/BufferGeometry.js
  6510. /**
  6511. * @author alteredq / http://alteredqualia.com/
  6512. * @author mrdoob / http://mrdoob.com/
  6513. */
  6514. THREE.BufferGeometry = function () {
  6515. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  6516. this.uuid = THREE.Math.generateUUID();
  6517. this.name = '';
  6518. this.type = 'BufferGeometry';
  6519. this.index = null;
  6520. this.attributes = {};
  6521. this.morphAttributes = {};
  6522. this.groups = [];
  6523. this.boundingBox = null;
  6524. this.boundingSphere = null;
  6525. this.drawRange = { start: 0, count: Infinity };
  6526. };
  6527. THREE.BufferGeometry.prototype = {
  6528. constructor: THREE.BufferGeometry,
  6529. addIndex: function ( index ) {
  6530. console.warn( 'THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().' );
  6531. this.setIndex( index );
  6532. },
  6533. getIndex: function () {
  6534. return this.index;
  6535. },
  6536. setIndex: function ( index ) {
  6537. this.index = index;
  6538. },
  6539. addAttribute: function ( name, attribute ) {
  6540. if ( attribute instanceof THREE.BufferAttribute === false && attribute instanceof THREE.InterleavedBufferAttribute === false ) {
  6541. console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
  6542. this.addAttribute( name, new THREE.BufferAttribute( arguments[ 1 ], arguments[ 2 ] ) );
  6543. return;
  6544. }
  6545. if ( name === 'index' ) {
  6546. console.warn( 'THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.' );
  6547. this.setIndex( attribute );
  6548. return;
  6549. }
  6550. this.attributes[ name ] = attribute;
  6551. },
  6552. getAttribute: function ( name ) {
  6553. return this.attributes[ name ];
  6554. },
  6555. removeAttribute: function ( name ) {
  6556. delete this.attributes[ name ];
  6557. },
  6558. get drawcalls() {
  6559. console.error( 'THREE.BufferGeometry: .drawcalls has been renamed to .groups.' );
  6560. return this.groups;
  6561. },
  6562. get offsets() {
  6563. console.warn( 'THREE.BufferGeometry: .offsets has been renamed to .groups.' );
  6564. return this.groups;
  6565. },
  6566. addDrawCall: function ( start, count, indexOffset ) {
  6567. if ( indexOffset !== undefined ) {
  6568. console.warn( 'THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.' );
  6569. }
  6570. console.warn( 'THREE.BufferGeometry: .addDrawCall() is now .addGroup().' );
  6571. this.addGroup( start, count );
  6572. },
  6573. clearDrawCalls: function () {
  6574. console.warn( 'THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().' );
  6575. this.clearGroups();
  6576. },
  6577. addGroup: function ( start, count, materialIndex ) {
  6578. this.groups.push( {
  6579. start: start,
  6580. count: count,
  6581. materialIndex: materialIndex !== undefined ? materialIndex : 0
  6582. } );
  6583. },
  6584. clearGroups: function () {
  6585. this.groups = [];
  6586. },
  6587. setDrawRange: function ( start, count ) {
  6588. this.drawRange.start = start;
  6589. this.drawRange.count = count;
  6590. },
  6591. applyMatrix: function ( matrix ) {
  6592. var position = this.attributes.position;
  6593. if ( position !== undefined ) {
  6594. matrix.applyToVector3Array( position.array );
  6595. position.needsUpdate = true;
  6596. }
  6597. var normal = this.attributes.normal;
  6598. if ( normal !== undefined ) {
  6599. var normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  6600. normalMatrix.applyToVector3Array( normal.array );
  6601. normal.needsUpdate = true;
  6602. }
  6603. if ( this.boundingBox !== null ) {
  6604. this.computeBoundingBox();
  6605. }
  6606. if ( this.boundingSphere !== null ) {
  6607. this.computeBoundingSphere();
  6608. }
  6609. },
  6610. rotateX: function () {
  6611. // rotate geometry around world x-axis
  6612. var m1;
  6613. return function rotateX( angle ) {
  6614. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6615. m1.makeRotationX( angle );
  6616. this.applyMatrix( m1 );
  6617. return this;
  6618. };
  6619. }(),
  6620. rotateY: function () {
  6621. // rotate geometry around world y-axis
  6622. var m1;
  6623. return function rotateY( angle ) {
  6624. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6625. m1.makeRotationY( angle );
  6626. this.applyMatrix( m1 );
  6627. return this;
  6628. };
  6629. }(),
  6630. rotateZ: function () {
  6631. // rotate geometry around world z-axis
  6632. var m1;
  6633. return function rotateZ( angle ) {
  6634. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6635. m1.makeRotationZ( angle );
  6636. this.applyMatrix( m1 );
  6637. return this;
  6638. };
  6639. }(),
  6640. translate: function () {
  6641. // translate geometry
  6642. var m1;
  6643. return function translate( x, y, z ) {
  6644. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6645. m1.makeTranslation( x, y, z );
  6646. this.applyMatrix( m1 );
  6647. return this;
  6648. };
  6649. }(),
  6650. scale: function () {
  6651. // scale geometry
  6652. var m1;
  6653. return function scale( x, y, z ) {
  6654. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6655. m1.makeScale( x, y, z );
  6656. this.applyMatrix( m1 );
  6657. return this;
  6658. };
  6659. }(),
  6660. lookAt: function () {
  6661. var obj;
  6662. return function lookAt( vector ) {
  6663. if ( obj === undefined ) obj = new THREE.Object3D();
  6664. obj.lookAt( vector );
  6665. obj.updateMatrix();
  6666. this.applyMatrix( obj.matrix );
  6667. };
  6668. }(),
  6669. center: function () {
  6670. this.computeBoundingBox();
  6671. var offset = this.boundingBox.center().negate();
  6672. this.translate( offset.x, offset.y, offset.z );
  6673. return offset;
  6674. },
  6675. setFromObject: function ( object ) {
  6676. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  6677. var geometry = object.geometry;
  6678. if ( object instanceof THREE.Points || object instanceof THREE.Line ) {
  6679. var positions = new THREE.Float32Attribute( geometry.vertices.length * 3, 3 );
  6680. var colors = new THREE.Float32Attribute( geometry.colors.length * 3, 3 );
  6681. this.addAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) );
  6682. this.addAttribute( 'color', colors.copyColorsArray( geometry.colors ) );
  6683. if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) {
  6684. var lineDistances = new THREE.Float32Attribute( geometry.lineDistances.length, 1 );
  6685. this.addAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) );
  6686. }
  6687. if ( geometry.boundingSphere !== null ) {
  6688. this.boundingSphere = geometry.boundingSphere.clone();
  6689. }
  6690. if ( geometry.boundingBox !== null ) {
  6691. this.boundingBox = geometry.boundingBox.clone();
  6692. }
  6693. } else if ( object instanceof THREE.Mesh ) {
  6694. if ( geometry instanceof THREE.Geometry ) {
  6695. this.fromGeometry( geometry );
  6696. }
  6697. }
  6698. return this;
  6699. },
  6700. updateFromObject: function ( object ) {
  6701. var geometry = object.geometry;
  6702. if ( object instanceof THREE.Mesh ) {
  6703. var direct = geometry.__directGeometry;
  6704. if ( direct === undefined ) {
  6705. return this.fromGeometry( geometry );
  6706. }
  6707. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6708. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6709. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6710. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6711. direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6712. geometry.verticesNeedUpdate = false;
  6713. geometry.normalsNeedUpdate = false;
  6714. geometry.colorsNeedUpdate = false;
  6715. geometry.uvsNeedUpdate = false;
  6716. geometry.groupsNeedUpdate = false;
  6717. geometry = direct;
  6718. }
  6719. if ( geometry.verticesNeedUpdate === true ) {
  6720. var attribute = this.attributes.position;
  6721. if ( attribute !== undefined ) {
  6722. attribute.copyVector3sArray( geometry.vertices );
  6723. attribute.needsUpdate = true;
  6724. }
  6725. geometry.verticesNeedUpdate = false;
  6726. }
  6727. if ( geometry.normalsNeedUpdate === true ) {
  6728. var attribute = this.attributes.normal;
  6729. if ( attribute !== undefined ) {
  6730. attribute.copyVector3sArray( geometry.normals );
  6731. attribute.needsUpdate = true;
  6732. }
  6733. geometry.normalsNeedUpdate = false;
  6734. }
  6735. if ( geometry.colorsNeedUpdate === true ) {
  6736. var attribute = this.attributes.color;
  6737. if ( attribute !== undefined ) {
  6738. attribute.copyColorsArray( geometry.colors );
  6739. attribute.needsUpdate = true;
  6740. }
  6741. geometry.colorsNeedUpdate = false;
  6742. }
  6743. if ( geometry.uvsNeedUpdate ) {
  6744. var attribute = this.attributes.uv;
  6745. if ( attribute !== undefined ) {
  6746. attribute.copyVector2sArray( geometry.uvs );
  6747. attribute.needsUpdate = true;
  6748. }
  6749. geometry.uvsNeedUpdate = false;
  6750. }
  6751. if ( geometry.lineDistancesNeedUpdate ) {
  6752. var attribute = this.attributes.lineDistance;
  6753. if ( attribute !== undefined ) {
  6754. attribute.copyArray( geometry.lineDistances );
  6755. attribute.needsUpdate = true;
  6756. }
  6757. geometry.lineDistancesNeedUpdate = false;
  6758. }
  6759. if ( geometry.groupsNeedUpdate ) {
  6760. geometry.computeGroups( object.geometry );
  6761. this.groups = geometry.groups;
  6762. geometry.groupsNeedUpdate = false;
  6763. }
  6764. return this;
  6765. },
  6766. fromGeometry: function ( geometry ) {
  6767. geometry.__directGeometry = new THREE.DirectGeometry().fromGeometry( geometry );
  6768. return this.fromDirectGeometry( geometry.__directGeometry );
  6769. },
  6770. fromDirectGeometry: function ( geometry ) {
  6771. var positions = new Float32Array( geometry.vertices.length * 3 );
  6772. this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) );
  6773. if ( geometry.normals.length > 0 ) {
  6774. var normals = new Float32Array( geometry.normals.length * 3 );
  6775. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) );
  6776. }
  6777. if ( geometry.colors.length > 0 ) {
  6778. var colors = new Float32Array( geometry.colors.length * 3 );
  6779. this.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors ) );
  6780. }
  6781. if ( geometry.uvs.length > 0 ) {
  6782. var uvs = new Float32Array( geometry.uvs.length * 2 );
  6783. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs ) );
  6784. }
  6785. if ( geometry.uvs2.length > 0 ) {
  6786. var uvs2 = new Float32Array( geometry.uvs2.length * 2 );
  6787. this.addAttribute( 'uv2', new THREE.BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 ) );
  6788. }
  6789. if ( geometry.indices.length > 0 ) {
  6790. var TypeArray = geometry.vertices.length > 65535 ? Uint32Array : Uint16Array;
  6791. var indices = new TypeArray( geometry.indices.length * 3 );
  6792. this.setIndex( new THREE.BufferAttribute( indices, 1 ).copyIndicesArray( geometry.indices ) );
  6793. }
  6794. // groups
  6795. this.groups = geometry.groups;
  6796. // morphs
  6797. for ( var name in geometry.morphTargets ) {
  6798. var array = [];
  6799. var morphTargets = geometry.morphTargets[ name ];
  6800. for ( var i = 0, l = morphTargets.length; i < l; i ++ ) {
  6801. var morphTarget = morphTargets[ i ];
  6802. var attribute = new THREE.Float32Attribute( morphTarget.length * 3, 3 );
  6803. array.push( attribute.copyVector3sArray( morphTarget ) );
  6804. }
  6805. this.morphAttributes[ name ] = array;
  6806. }
  6807. // skinning
  6808. if ( geometry.skinIndices.length > 0 ) {
  6809. var skinIndices = new THREE.Float32Attribute( geometry.skinIndices.length * 4, 4 );
  6810. this.addAttribute( 'skinIndex', skinIndices.copyVector4sArray( geometry.skinIndices ) );
  6811. }
  6812. if ( geometry.skinWeights.length > 0 ) {
  6813. var skinWeights = new THREE.Float32Attribute( geometry.skinWeights.length * 4, 4 );
  6814. this.addAttribute( 'skinWeight', skinWeights.copyVector4sArray( geometry.skinWeights ) );
  6815. }
  6816. //
  6817. if ( geometry.boundingSphere !== null ) {
  6818. this.boundingSphere = geometry.boundingSphere.clone();
  6819. }
  6820. if ( geometry.boundingBox !== null ) {
  6821. this.boundingBox = geometry.boundingBox.clone();
  6822. }
  6823. return this;
  6824. },
  6825. computeBoundingBox: function () {
  6826. var vector = new THREE.Vector3();
  6827. return function () {
  6828. if ( this.boundingBox === null ) {
  6829. this.boundingBox = new THREE.Box3();
  6830. }
  6831. var positions = this.attributes.position.array;
  6832. if ( positions ) {
  6833. var bb = this.boundingBox;
  6834. bb.makeEmpty();
  6835. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  6836. vector.fromArray( positions, i );
  6837. bb.expandByPoint( vector );
  6838. }
  6839. }
  6840. if ( positions === undefined || positions.length === 0 ) {
  6841. this.boundingBox.min.set( 0, 0, 0 );
  6842. this.boundingBox.max.set( 0, 0, 0 );
  6843. }
  6844. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  6845. console.error( 'THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  6846. }
  6847. };
  6848. }(),
  6849. computeBoundingSphere: function () {
  6850. var box = new THREE.Box3();
  6851. var vector = new THREE.Vector3();
  6852. return function () {
  6853. if ( this.boundingSphere === null ) {
  6854. this.boundingSphere = new THREE.Sphere();
  6855. }
  6856. var positions = this.attributes.position.array;
  6857. if ( positions ) {
  6858. box.makeEmpty();
  6859. var center = this.boundingSphere.center;
  6860. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  6861. vector.fromArray( positions, i );
  6862. box.expandByPoint( vector );
  6863. }
  6864. box.center( center );
  6865. // hoping to find a boundingSphere with a radius smaller than the
  6866. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  6867. var maxRadiusSq = 0;
  6868. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  6869. vector.fromArray( positions, i );
  6870. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
  6871. }
  6872. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  6873. if ( isNaN( this.boundingSphere.radius ) ) {
  6874. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  6875. }
  6876. }
  6877. };
  6878. }(),
  6879. computeFaceNormals: function () {
  6880. // backwards compatibility
  6881. },
  6882. computeVertexNormals: function () {
  6883. var index = this.index;
  6884. var attributes = this.attributes;
  6885. var groups = this.groups;
  6886. if ( attributes.position ) {
  6887. var positions = attributes.position.array;
  6888. if ( attributes.normal === undefined ) {
  6889. this.addAttribute( 'normal', new THREE.BufferAttribute( new Float32Array( positions.length ), 3 ) );
  6890. } else {
  6891. // reset existing normals to zero
  6892. var normals = attributes.normal.array;
  6893. for ( var i = 0, il = normals.length; i < il; i ++ ) {
  6894. normals[ i ] = 0;
  6895. }
  6896. }
  6897. var normals = attributes.normal.array;
  6898. var vA, vB, vC,
  6899. pA = new THREE.Vector3(),
  6900. pB = new THREE.Vector3(),
  6901. pC = new THREE.Vector3(),
  6902. cb = new THREE.Vector3(),
  6903. ab = new THREE.Vector3();
  6904. // indexed elements
  6905. if ( index ) {
  6906. var indices = index.array;
  6907. if ( groups.length === 0 ) {
  6908. this.addGroup( 0, indices.length );
  6909. }
  6910. for ( var j = 0, jl = groups.length; j < jl; ++ j ) {
  6911. var group = groups[ j ];
  6912. var start = group.start;
  6913. var count = group.count;
  6914. for ( var i = start, il = start + count; i < il; i += 3 ) {
  6915. vA = indices[ i + 0 ] * 3;
  6916. vB = indices[ i + 1 ] * 3;
  6917. vC = indices[ i + 2 ] * 3;
  6918. pA.fromArray( positions, vA );
  6919. pB.fromArray( positions, vB );
  6920. pC.fromArray( positions, vC );
  6921. cb.subVectors( pC, pB );
  6922. ab.subVectors( pA, pB );
  6923. cb.cross( ab );
  6924. normals[ vA ] += cb.x;
  6925. normals[ vA + 1 ] += cb.y;
  6926. normals[ vA + 2 ] += cb.z;
  6927. normals[ vB ] += cb.x;
  6928. normals[ vB + 1 ] += cb.y;
  6929. normals[ vB + 2 ] += cb.z;
  6930. normals[ vC ] += cb.x;
  6931. normals[ vC + 1 ] += cb.y;
  6932. normals[ vC + 2 ] += cb.z;
  6933. }
  6934. }
  6935. } else {
  6936. // non-indexed elements (unconnected triangle soup)
  6937. for ( var i = 0, il = positions.length; i < il; i += 9 ) {
  6938. pA.fromArray( positions, i );
  6939. pB.fromArray( positions, i + 3 );
  6940. pC.fromArray( positions, i + 6 );
  6941. cb.subVectors( pC, pB );
  6942. ab.subVectors( pA, pB );
  6943. cb.cross( ab );
  6944. normals[ i ] = cb.x;
  6945. normals[ i + 1 ] = cb.y;
  6946. normals[ i + 2 ] = cb.z;
  6947. normals[ i + 3 ] = cb.x;
  6948. normals[ i + 4 ] = cb.y;
  6949. normals[ i + 5 ] = cb.z;
  6950. normals[ i + 6 ] = cb.x;
  6951. normals[ i + 7 ] = cb.y;
  6952. normals[ i + 8 ] = cb.z;
  6953. }
  6954. }
  6955. this.normalizeNormals();
  6956. attributes.normal.needsUpdate = true;
  6957. }
  6958. },
  6959. computeTangents: function () {
  6960. console.warn( 'THREE.BufferGeometry: .computeTangents() has been removed.' );
  6961. },
  6962. computeOffsets: function ( size ) {
  6963. console.warn( 'THREE.BufferGeometry: .computeOffsets() has been removed.');
  6964. },
  6965. merge: function ( geometry, offset ) {
  6966. if ( geometry instanceof THREE.BufferGeometry === false ) {
  6967. console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
  6968. return;
  6969. }
  6970. if ( offset === undefined ) offset = 0;
  6971. var attributes = this.attributes;
  6972. for ( var key in attributes ) {
  6973. if ( geometry.attributes[ key ] === undefined ) continue;
  6974. var attribute1 = attributes[ key ];
  6975. var attributeArray1 = attribute1.array;
  6976. var attribute2 = geometry.attributes[ key ];
  6977. var attributeArray2 = attribute2.array;
  6978. var attributeSize = attribute2.itemSize;
  6979. for ( var i = 0, j = attributeSize * offset; i < attributeArray2.length; i ++, j ++ ) {
  6980. attributeArray1[ j ] = attributeArray2[ i ];
  6981. }
  6982. }
  6983. return this;
  6984. },
  6985. normalizeNormals: function () {
  6986. var normals = this.attributes.normal.array;
  6987. var x, y, z, n;
  6988. for ( var i = 0, il = normals.length; i < il; i += 3 ) {
  6989. x = normals[ i ];
  6990. y = normals[ i + 1 ];
  6991. z = normals[ i + 2 ];
  6992. n = 1.0 / Math.sqrt( x * x + y * y + z * z );
  6993. normals[ i ] *= n;
  6994. normals[ i + 1 ] *= n;
  6995. normals[ i + 2 ] *= n;
  6996. }
  6997. },
  6998. toJSON: function () {
  6999. var data = {
  7000. metadata: {
  7001. version: 4.4,
  7002. type: 'BufferGeometry',
  7003. generator: 'BufferGeometry.toJSON'
  7004. }
  7005. };
  7006. // standard BufferGeometry serialization
  7007. data.uuid = this.uuid;
  7008. data.type = this.type;
  7009. if ( this.name !== '' ) data.name = this.name;
  7010. if ( this.parameters !== undefined ) {
  7011. var parameters = this.parameters;
  7012. for ( var key in parameters ) {
  7013. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  7014. }
  7015. return data;
  7016. }
  7017. data.data = { attributes: {} };
  7018. var index = this.index;
  7019. if ( index !== null ) {
  7020. var array = Array.prototype.slice.call( index.array );
  7021. data.data.index = {
  7022. type: index.array.constructor.name,
  7023. array: array
  7024. };
  7025. }
  7026. var attributes = this.attributes;
  7027. for ( var key in attributes ) {
  7028. var attribute = attributes[ key ];
  7029. var array = Array.prototype.slice.call( attribute.array );
  7030. data.data.attributes[ key ] = {
  7031. itemSize: attribute.itemSize,
  7032. type: attribute.array.constructor.name,
  7033. array: array
  7034. };
  7035. }
  7036. var groups = this.groups;
  7037. if ( groups.length > 0 ) {
  7038. data.data.groups = JSON.parse( JSON.stringify( groups ) );
  7039. }
  7040. var boundingSphere = this.boundingSphere;
  7041. if ( boundingSphere !== null ) {
  7042. data.data.boundingSphere = {
  7043. center: boundingSphere.center.toArray(),
  7044. radius: boundingSphere.radius
  7045. };
  7046. }
  7047. return data;
  7048. },
  7049. clone: function () {
  7050. // Handle primitives
  7051. var parameters = this.parameters;
  7052. if ( parameters !== undefined ) {
  7053. var values = [];
  7054. for ( var key in parameters ) {
  7055. values.push( parameters[ key ] );
  7056. }
  7057. var geometry = Object.create( this.constructor.prototype );
  7058. this.constructor.apply( geometry, values );
  7059. return geometry;
  7060. }
  7061. return new this.constructor().copy( this );
  7062. },
  7063. copy: function ( source ) {
  7064. var index = source.index;
  7065. if ( index !== null ) {
  7066. this.setIndex( index.clone() );
  7067. }
  7068. var attributes = source.attributes;
  7069. for ( var name in attributes ) {
  7070. var attribute = attributes[ name ];
  7071. this.addAttribute( name, attribute.clone() );
  7072. }
  7073. var groups = source.groups;
  7074. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  7075. var group = groups[ i ];
  7076. this.addGroup( group.start, group.count );
  7077. }
  7078. return this;
  7079. },
  7080. dispose: function () {
  7081. this.dispatchEvent( { type: 'dispose' } );
  7082. }
  7083. };
  7084. THREE.EventDispatcher.prototype.apply( THREE.BufferGeometry.prototype );
  7085. THREE.BufferGeometry.MaxIndex = 65535;
  7086. // File:src/core/InstancedBufferGeometry.js
  7087. /**
  7088. * @author benaadams / https://twitter.com/ben_a_adams
  7089. */
  7090. THREE.InstancedBufferGeometry = function () {
  7091. THREE.BufferGeometry.call( this );
  7092. this.type = 'InstancedBufferGeometry';
  7093. this.maxInstancedCount = undefined;
  7094. };
  7095. THREE.InstancedBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  7096. THREE.InstancedBufferGeometry.prototype.constructor = THREE.InstancedBufferGeometry;
  7097. THREE.InstancedBufferGeometry.prototype.addGroup = function ( start, count, instances ) {
  7098. this.groups.push( {
  7099. start: start,
  7100. count: count,
  7101. instances: instances
  7102. } );
  7103. };
  7104. THREE.InstancedBufferGeometry.prototype.copy = function ( source ) {
  7105. var index = source.index;
  7106. if ( index !== null ) {
  7107. this.setIndex( index.clone() );
  7108. }
  7109. var attributes = source.attributes;
  7110. for ( var name in attributes ) {
  7111. var attribute = attributes[ name ];
  7112. this.addAttribute( name, attribute.clone() );
  7113. }
  7114. var groups = source.groups;
  7115. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  7116. var group = groups[ i ];
  7117. this.addGroup( group.start, group.count, group.instances );
  7118. }
  7119. return this;
  7120. };
  7121. THREE.EventDispatcher.prototype.apply( THREE.InstancedBufferGeometry.prototype );
  7122. // File:src/animation/AnimationClip.js
  7123. /**
  7124. *
  7125. * Reusable set of Tracks that represent an animation.
  7126. *
  7127. * @author Ben Houston / http://clara.io/
  7128. * @author David Sarno / http://lighthaus.us/
  7129. */
  7130. THREE.AnimationClip = function ( name, duration, tracks ) {
  7131. this.name = name || THREE.Math.generateUUID();
  7132. this.tracks = tracks;
  7133. this.duration = ( duration !== undefined ) ? duration : -1;
  7134. // this means it should figure out its duration by scanning the tracks
  7135. if ( this.duration < 0 ) {
  7136. for ( var i = 0; i < this.tracks.length; i ++ ) {
  7137. var track = this.tracks[i];
  7138. this.duration = Math.max( track.times[ track.times.length - 1 ] );
  7139. }
  7140. }
  7141. // maybe only do these on demand, as doing them here could potentially slow down loading
  7142. // but leaving these here during development as this ensures a lot of testing of these functions
  7143. this.trim();
  7144. this.optimize();
  7145. };
  7146. THREE.AnimationClip.prototype = {
  7147. constructor: THREE.AnimationClip,
  7148. trim: function() {
  7149. for ( var i = 0; i < this.tracks.length; i ++ ) {
  7150. this.tracks[ i ].trim( 0, this.duration );
  7151. }
  7152. return this;
  7153. },
  7154. optimize: function() {
  7155. for ( var i = 0; i < this.tracks.length; i ++ ) {
  7156. this.tracks[ i ].optimize();
  7157. }
  7158. return this;
  7159. }
  7160. };
  7161. // Static methods:
  7162. Object.assign( THREE.AnimationClip, {
  7163. parse: function( json ) {
  7164. var tracks = [],
  7165. jsonTracks = json.tracks,
  7166. frameTime = 1.0 / ( json.fps || 1.0 );
  7167. for ( var i = 0, n = jsonTracks.length; i !== n; ++ i ) {
  7168. tracks.push( THREE.KeyframeTrack.parse( jsonTracks[ i ] ).scale( frameTime ) );
  7169. }
  7170. return new THREE.AnimationClip( json.name, json.duration, tracks );
  7171. },
  7172. toJSON: function( clip ) {
  7173. var tracks = [],
  7174. clipTracks = clip.tracks;
  7175. var json = {
  7176. 'name': clip.name,
  7177. 'duration': clip.duration,
  7178. 'tracks': tracks
  7179. };
  7180. for ( var i = 0, n = clipTracks.length; i !== n; ++ i ) {
  7181. tracks.push( THREE.KeyframeTrack.toJSON( clipTracks[ i ] ) );
  7182. }
  7183. return json;
  7184. },
  7185. CreateFromMorphTargetSequence: function( name, morphTargetSequence, fps ) {
  7186. var numMorphTargets = morphTargetSequence.length;
  7187. var tracks = [];
  7188. for ( var i = 0; i < numMorphTargets; i ++ ) {
  7189. var times = [];
  7190. var values = [];
  7191. times.push(
  7192. ( i + numMorphTargets - 1 ) % numMorphTargets,
  7193. i,
  7194. ( i + 1 ) % numMorphTargets );
  7195. values.push( 0, 1, 0 );
  7196. var order = THREE.AnimationUtils.getKeyframeOrder( times );
  7197. times = THREE.AnimationUtils.sortedArray( times, 1, order );
  7198. values = THREE.AnimationUtils.sortedArray( values, 1, order );
  7199. // if there is a key at the first frame, duplicate it as the
  7200. // last frame as well for perfect loop.
  7201. if ( times[ 0 ] === 0 ) {
  7202. times.push( numMorphTargets );
  7203. values.push( values[ 0 ] );
  7204. }
  7205. tracks.push(
  7206. new THREE.NumberKeyframeTrack(
  7207. '.morphTargetInfluences[' + morphTargetSequence[ i ].name + ']',
  7208. times, values
  7209. ).scale( 1.0 / fps ) );
  7210. }
  7211. return new THREE.AnimationClip( name, -1, tracks );
  7212. },
  7213. findByName: function( clipArray, name ) {
  7214. for ( var i = 0; i < clipArray.length; i ++ ) {
  7215. if ( clipArray[ i ].name === name ) {
  7216. return clipArray[ i ];
  7217. }
  7218. }
  7219. return null;
  7220. },
  7221. CreateClipsFromMorphTargetSequences: function( morphTargets, fps ) {
  7222. var animationToMorphTargets = {};
  7223. // tested with https://regex101.com/ on trick sequences
  7224. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  7225. var pattern = /^([\w-]*?)([\d]+)$/;
  7226. // sort morph target names into animation groups based
  7227. // patterns like Walk_001, Walk_002, Run_001, Run_002
  7228. for ( var i = 0, il = morphTargets.length; i < il; i ++ ) {
  7229. var morphTarget = morphTargets[ i ];
  7230. var parts = morphTarget.name.match( pattern );
  7231. if ( parts && parts.length > 1 ) {
  7232. var name = parts[ 1 ];
  7233. var animationMorphTargets = animationToMorphTargets[ name ];
  7234. if ( ! animationMorphTargets ) {
  7235. animationToMorphTargets[ name ] = animationMorphTargets = [];
  7236. }
  7237. animationMorphTargets.push( morphTarget );
  7238. }
  7239. }
  7240. var clips = [];
  7241. for ( var name in animationToMorphTargets ) {
  7242. clips.push( THREE.AnimationClip.CreateFromMorphTargetSequence( name, animationToMorphTargets[ name ], fps ) );
  7243. }
  7244. return clips;
  7245. },
  7246. // parse the animation.hierarchy format
  7247. parseAnimation: function( animation, bones, nodeName ) {
  7248. if ( ! animation ) {
  7249. console.error( " no animation in JSONLoader data" );
  7250. return null;
  7251. }
  7252. var addNonemptyTrack = function(
  7253. trackType, trackName, animationKeys, propertyName, destTracks ) {
  7254. // only return track if there are actually keys.
  7255. if ( animationKeys.length !== 0 ) {
  7256. var times = [];
  7257. var values = [];
  7258. THREE.AnimationUtils.flattenJSON(
  7259. animationKeys, times, values, propertyName );
  7260. // empty keys are filtered out, so check again
  7261. if ( times.length !== 0 ) {
  7262. destTracks.push( new trackType( trackName, times, values ) );
  7263. }
  7264. }
  7265. };
  7266. var tracks = [];
  7267. var clipName = animation.name || 'default';
  7268. // automatic length determination in AnimationClip.
  7269. var duration = animation.length || -1;
  7270. var fps = animation.fps || 30;
  7271. var hierarchyTracks = animation.hierarchy || [];
  7272. for ( var h = 0; h < hierarchyTracks.length; h ++ ) {
  7273. var animationKeys = hierarchyTracks[ h ].keys;
  7274. // skip empty tracks
  7275. if ( ! animationKeys || animationKeys.length == 0 ) continue;
  7276. // process morph targets in a way exactly compatible
  7277. // with AnimationHandler.init( animation )
  7278. if ( animationKeys[0].morphTargets ) {
  7279. // figure out all morph targets used in this track
  7280. var morphTargetNames = {};
  7281. for ( var k = 0; k < animationKeys.length; k ++ ) {
  7282. if ( animationKeys[k].morphTargets ) {
  7283. for ( var m = 0; m < animationKeys[k].morphTargets.length; m ++ ) {
  7284. morphTargetNames[ animationKeys[k].morphTargets[m] ] = -1;
  7285. }
  7286. }
  7287. }
  7288. // create a track for each morph target with all zero
  7289. // morphTargetInfluences except for the keys in which
  7290. // the morphTarget is named.
  7291. for ( var morphTargetName in morphTargetNames ) {
  7292. var times = [];
  7293. var values = [];
  7294. for ( var m = 0;
  7295. m !== animationKeys[k].morphTargets.length; ++ m ) {
  7296. var animationKey = animationKeys[k];
  7297. times.push( animationKey.time );
  7298. values.push( ( animationKey.morphTarget === morphTargetName ) ? 1 : 0 )
  7299. }
  7300. tracks.push( new THREE.NumberKeyframeTrack(
  7301. '.morphTargetInfluence[' + morphTargetName + ']', times, values ) );
  7302. }
  7303. duration = morphTargetNames.length * ( fps || 1.0 );
  7304. } else {
  7305. // ...assume skeletal animation
  7306. var boneName = '.bones[' + bones[ h ].name + ']';
  7307. addNonemptyTrack(
  7308. THREE.VectorKeyframeTrack, boneName + '.position',
  7309. animationKeys, 'pos', tracks );
  7310. addNonemptyTrack(
  7311. THREE.QuaternionKeyframeTrack, boneName + '.quaternion',
  7312. animationKeys, 'rot', tracks );
  7313. addNonemptyTrack(
  7314. THREE.VectorKeyframeTrack, boneName + '.scale',
  7315. animationKeys, 'scl', tracks );
  7316. }
  7317. }
  7318. if ( tracks.length === 0 ) {
  7319. return null;
  7320. }
  7321. var clip = new THREE.AnimationClip( clipName, duration, tracks );
  7322. return clip;
  7323. }
  7324. } );
  7325. // File:src/animation/AnimationMixer.js
  7326. /**
  7327. *
  7328. * Player for AnimationClips.
  7329. *
  7330. *
  7331. * @author Ben Houston / http://clara.io/
  7332. * @author David Sarno / http://lighthaus.us/
  7333. * @author tschw
  7334. */
  7335. THREE.AnimationMixer = function( root ) {
  7336. this._root = root;
  7337. this._initMemoryManager();
  7338. this._accuIndex = 0;
  7339. this.time = 0;
  7340. this.timeScale = 1.0;
  7341. };
  7342. THREE.AnimationMixer.prototype = {
  7343. constructor: THREE.AnimationMixer,
  7344. // return an action for a clip optionally using a custom root target
  7345. // object (this method allocates a lot of dynamic memory in case a
  7346. // previously unknown clip/root combination is specified)
  7347. clipAction: function( clip, optionalRoot ) {
  7348. var root = optionalRoot || this._root,
  7349. rootUuid = root.uuid,
  7350. clipName = ( typeof clip === 'string' ) ? clip : clip.name,
  7351. clipObject = ( clip !== clipName ) ? clip : null,
  7352. actionsForClip = this._actionsByClip[ clipName ],
  7353. prototypeAction;
  7354. if ( actionsForClip !== undefined ) {
  7355. var existingAction =
  7356. actionsForClip.actionByRoot[ rootUuid ];
  7357. if ( existingAction !== undefined ) {
  7358. return existingAction;
  7359. }
  7360. // we know the clip, so we don't have to parse all
  7361. // the bindings again but can just copy
  7362. prototypeAction = actionsForClip.knownActions[ 0 ];
  7363. // also, take the clip from the prototype action
  7364. clipObject = prototypeAction._clip;
  7365. if ( clip !== clipName && clip !== clipObject ) {
  7366. throw new Error(
  7367. "Different clips with the same name detected!" );
  7368. }
  7369. }
  7370. // clip must be known when specified via string
  7371. if ( clipObject === null ) return null;
  7372. // allocate all resources required to run it
  7373. var newAction = new THREE.
  7374. AnimationMixer._Action( this, clipObject, optionalRoot );
  7375. this._bindAction( newAction, prototypeAction );
  7376. // and make the action known to the memory manager
  7377. this._addInactiveAction( newAction, clipName, rootUuid );
  7378. return newAction;
  7379. },
  7380. // get an existing action
  7381. existingAction: function( clip, optionalRoot ) {
  7382. var root = optionalRoot || this._root,
  7383. rootUuid = root.uuid,
  7384. clipName = ( typeof clip === 'string' ) ? clip : clip.name,
  7385. actionsForClip = this._actionsByClip[ clipName ];
  7386. if ( actionsForClip !== undefined ) {
  7387. return actionsForClip.actionByRoot[ rootUuid ] || null;
  7388. }
  7389. return null;
  7390. },
  7391. // deactivates all previously scheduled actions
  7392. stopAllAction: function() {
  7393. var actions = this._actions,
  7394. nActions = this._nActiveActions,
  7395. bindings = this._bindings,
  7396. nBindings = this._nActiveBindings;
  7397. this._nActiveActions = 0;
  7398. this._nActiveBindings = 0;
  7399. for ( var i = 0; i !== nActions; ++ i ) {
  7400. actions[ i ].reset();
  7401. }
  7402. for ( var i = 0; i !== nBindings; ++ i ) {
  7403. bindings[ i ].useCount = 0;
  7404. }
  7405. return this;
  7406. },
  7407. // advance the time and update apply the animation
  7408. update: function( deltaTime ) {
  7409. deltaTime *= this.timeScale;
  7410. var actions = this._actions,
  7411. nActions = this._nActiveActions,
  7412. time = this.time += deltaTime,
  7413. timeDirection = Math.sign( deltaTime ),
  7414. accuIndex = this._accuIndex ^= 1;
  7415. // run active actions
  7416. for ( var i = 0; i !== nActions; ++ i ) {
  7417. var action = actions[ i ];
  7418. if ( action.enabled ) {
  7419. action._update( time, deltaTime, timeDirection, accuIndex );
  7420. }
  7421. }
  7422. // update scene graph
  7423. var bindings = this._bindings,
  7424. nBindings = this._nActiveBindings;
  7425. for ( var i = 0; i !== nBindings; ++ i ) {
  7426. bindings[ i ].apply( accuIndex );
  7427. }
  7428. return this;
  7429. },
  7430. // return this mixer's root target object
  7431. getRoot: function() {
  7432. return this._root;
  7433. },
  7434. // free all resources specific to a particular clip
  7435. uncacheClip: function( clip ) {
  7436. var actions = this._actions,
  7437. clipName = clip.name,
  7438. actionsByClip = this._actionsByClip,
  7439. actionsForClip = actionsByClip[ clipName ];
  7440. if ( actionsForClip !== undefined ) {
  7441. // note: just calling _removeInactiveAction would mess up the
  7442. // iteration state and also require updating the state we can
  7443. // just throw away
  7444. var actionsToRemove = actionsForClip.knownActions;
  7445. for ( var i = 0, n = actionsToRemove.length; i !== n; ++ i ) {
  7446. var action = actionsToRemove[ i ];
  7447. this._deactivateAction( action );
  7448. var cacheIndex = action._cacheIndex,
  7449. lastInactiveAction = actions[ actions.length - 1 ];
  7450. action._cacheIndex = null;
  7451. action._byClipCacheIndex = null;
  7452. lastInactiveAction._cacheIndex = cacheIndex;
  7453. actions[ cacheIndex ] = lastInactiveAction;
  7454. actions.pop();
  7455. this._removeInactiveBindingsForAction( action );
  7456. }
  7457. delete actionsByClip[ clipName ];
  7458. }
  7459. },
  7460. // free all resources specific to a particular root target object
  7461. uncacheRoot: function( root ) {
  7462. var rootUuid = root.uuid,
  7463. actionsByClip = this._actionsByClip;
  7464. for ( var clipName in actionsByClip ) {
  7465. var actionByRoot = actionsByClip[ clipName ].actionByRoot,
  7466. action = actionByRoot[ rootUuid ];
  7467. if ( action !== undefined ) {
  7468. this._deactivateAction( action );
  7469. this._removeInactiveAction( action );
  7470. }
  7471. }
  7472. var bindingsByRoot = this._bindingsByRootAndName,
  7473. bindingByName = bindingsByRoot[ rootUuid ];
  7474. if ( bindingByName !== undefined ) {
  7475. for ( var trackName in bindingByName ) {
  7476. var binding = bindingByName[ trackName ];
  7477. binding.restoreOriginalState();
  7478. this._removeInactiveBinding( binding );
  7479. }
  7480. }
  7481. },
  7482. // remove a targeted clip from the cache
  7483. uncacheAction: function( clip, optionalRoot ) {
  7484. var action = this.existingAction( clip, optionalRoot );
  7485. if ( action !== null ) {
  7486. this._deactivateAction( action );
  7487. this._removeInactiveAction( action );
  7488. }
  7489. }
  7490. };
  7491. THREE.EventDispatcher.prototype.apply( THREE.AnimationMixer.prototype );
  7492. THREE.AnimationMixer._Action =
  7493. function( mixer, clip, localRoot ) {
  7494. this._mixer = mixer;
  7495. this._clip = clip;
  7496. this._localRoot = localRoot || null;
  7497. var tracks = clip.tracks,
  7498. nTracks = tracks.length,
  7499. interpolants = new Array( nTracks );
  7500. var interpolantSettings = {
  7501. endingStart: THREE.ZeroCurvatureEnding,
  7502. endingEnd: THREE.ZeroCurvatureEnding
  7503. };
  7504. for ( var i = 0; i !== nTracks; ++ i ) {
  7505. var interpolant = tracks[ i ].createInterpolant( null );
  7506. interpolants[ i ] = interpolant;
  7507. interpolant.settings = interpolantSettings
  7508. }
  7509. this._interpolantSettings = interpolantSettings;
  7510. this._interpolants = interpolants; // bound by the mixer
  7511. // inside: PropertyMixer (managed by the mixer)
  7512. this._propertyBindings = new Array( nTracks );
  7513. this._cacheIndex = null; // for the memory manager
  7514. this._byClipCacheIndex = null; // for the memory manager
  7515. this._timeScaleInterpolant = null;
  7516. this._weightInterpolant = null;
  7517. this.loop = THREE.LoopRepeat;
  7518. this._loopCount = -1;
  7519. // global mixer time when the action is to be started
  7520. // it's set back to 'null' upon start of the action
  7521. this._startTime = null;
  7522. // scaled local time of the action
  7523. // gets clamped or wrapped to 0..clip.duration according to loop
  7524. this.time = 0;
  7525. this.timeScale = 1;
  7526. this._effectiveTimeScale = 1;
  7527. this.weight = 1;
  7528. this._effectiveWeight = 1;
  7529. this.repetitions = Infinity; // no. of repetitions when looping
  7530. this.paused = false; // false -> zero effective time scale
  7531. this.enabled = true; // true -> zero effective weight
  7532. this.clampWhenFinished = false; // keep feeding the last frame?
  7533. this.zeroSlopeAtStart = true; // for smooth interpolation w/o separate
  7534. this.zeroSlopeAtEnd = true; // clips for start, loop and end
  7535. };
  7536. THREE.AnimationMixer._Action.prototype = {
  7537. constructor: THREE.AnimationMixer._Action,
  7538. // State & Scheduling
  7539. play: function() {
  7540. this._mixer._activateAction( this );
  7541. return this;
  7542. },
  7543. stop: function() {
  7544. this._mixer._deactivateAction( this );
  7545. return this.reset();
  7546. },
  7547. reset: function() {
  7548. this.paused = false;
  7549. this.enabled = true;
  7550. this.time = 0; // restart clip
  7551. this._loopCount = -1; // forget previous loops
  7552. this._startTime = null; // forget scheduling
  7553. return this.stopFading().stopWarping();
  7554. },
  7555. isRunning: function() {
  7556. var start = this._startTime;
  7557. return this.enabled && ! this.paused && this.timeScale !== 0 &&
  7558. this._startTime === null && this._mixer._isActiveAction( this )
  7559. },
  7560. // return true when play has been called
  7561. isScheduled: function() {
  7562. return this._mixer._isActiveAction( this );
  7563. },
  7564. startAt: function( time ) {
  7565. this._startTime = time;
  7566. return this;
  7567. },
  7568. setLoop: function( mode, repetitions ) {
  7569. this.loop = mode;
  7570. this.repetitions = repetitions;
  7571. return this;
  7572. },
  7573. // Weight
  7574. // set the weight stopping any scheduled fading
  7575. // although .enabled = false yields an effective weight of zero, this
  7576. // method does *not* change .enabled, because it would be confusing
  7577. setEffectiveWeight: function( weight ) {
  7578. this.weight = weight;
  7579. // note: same logic as when updated at runtime
  7580. this._effectiveWeight = this.enabled ? weight : 0;
  7581. return this.stopFading();
  7582. },
  7583. // return the weight considering fading and .enabled
  7584. getEffectiveWeight: function() {
  7585. return this._effectiveWeight;
  7586. },
  7587. fadeIn: function( duration ) {
  7588. return this._scheduleFading( duration, 0, 1 );
  7589. },
  7590. fadeOut: function( duration ) {
  7591. return this._scheduleFading( duration, 1, 0 );
  7592. },
  7593. crossFadeFrom: function( fadeOutAction, duration, warp ) {
  7594. var mixer = this._mixer;
  7595. fadeOutAction.fadeOut( duration );
  7596. this.fadeIn( duration );
  7597. if( warp ) {
  7598. var fadeInDuration = this._clip.duration,
  7599. fadeOutDuration = fadeOutAction._clip.duration,
  7600. startEndRatio = fadeOutDuration / fadeInDuration,
  7601. endStartRatio = fadeInDuration / fadeOutDuration;
  7602. fadeOutAction.warp( 1.0, startEndRatio, duration );
  7603. this.warp( endStartRatio, 1.0, duration );
  7604. }
  7605. return this;
  7606. },
  7607. crossFadeTo: function( fadeInAction, duration, warp ) {
  7608. return fadeInAction.crossFadeFrom( this, duration, warp );
  7609. },
  7610. stopFading: function() {
  7611. var weightInterpolant = this._weightInterpolant;
  7612. if ( weightInterpolant !== null ) {
  7613. this._weightInterpolant = null;
  7614. this._mixer._takeBackControlInterpolant( weightInterpolant );
  7615. }
  7616. return this;
  7617. },
  7618. // Time Scale Control
  7619. // set the weight stopping any scheduled warping
  7620. // although .paused = true yields an effective time scale of zero, this
  7621. // method does *not* change .paused, because it would be confusing
  7622. setEffectiveTimeScale: function( timeScale ) {
  7623. this.timeScale = timeScale;
  7624. this._effectiveTimeScale = this.paused ? 0 :timeScale;
  7625. return this.stopWarping();
  7626. },
  7627. // return the time scale considering warping and .paused
  7628. getEffectiveTimeScale: function() {
  7629. return this._effectiveTimeScale;
  7630. },
  7631. setDuration: function( duration ) {
  7632. this.timeScale = this._clip.duration / duration;
  7633. return this.stopWarping();
  7634. },
  7635. syncWith: function( action ) {
  7636. this.time = action.time;
  7637. this.timeScale = action.timeScale;
  7638. return this.stopWarping();
  7639. },
  7640. halt: function( duration ) {
  7641. return this.warp( this._currentTimeScale, 0, duration );
  7642. },
  7643. warp: function( startTimeScale, endTimeScale, duration ) {
  7644. var mixer = this._mixer, now = mixer.time,
  7645. interpolant = this._timeScaleInterpolant,
  7646. timeScale = this.timeScale;
  7647. if ( interpolant === null ) {
  7648. interpolant = mixer._lendControlInterpolant(),
  7649. this._timeScaleInterpolant = interpolant;
  7650. }
  7651. var times = interpolant.parameterPositions,
  7652. values = interpolant.sampleValues;
  7653. times[ 0 ] = now;
  7654. times[ 1 ] = now + duration;
  7655. values[ 0 ] = startTimeScale / timeScale;
  7656. values[ 1 ] = endTimeScale / timeScale;
  7657. return this;
  7658. },
  7659. stopWarping: function() {
  7660. var timeScaleInterpolant = this._timeScaleInterpolant;
  7661. if ( timeScaleInterpolant !== null ) {
  7662. this._timeScaleInterpolant = null;
  7663. this._mixer._takeBackControlInterpolant( timeScaleInterpolant );
  7664. }
  7665. return this;
  7666. },
  7667. // Object Accessors
  7668. getMixer: function() {
  7669. return this._mixer;
  7670. },
  7671. getClip: function() {
  7672. return this._clip;
  7673. },
  7674. getRoot: function() {
  7675. return this._localRoot || this._mixer._root;
  7676. },
  7677. // Interna
  7678. _update: function( time, deltaTime, timeDirection, accuIndex ) {
  7679. // called by the mixer
  7680. var startTime = this._startTime;
  7681. if ( startTime !== null ) {
  7682. // check for scheduled start of action
  7683. var timeRunning = ( time - startTime ) * timeDirection;
  7684. if ( timeRunning < 0 || timeDirection === 0 ) {
  7685. return; // yet to come / don't decide when delta = 0
  7686. }
  7687. // start
  7688. this._startTime = null; // unschedule
  7689. deltaTime = timeDirection * timeRunning;
  7690. }
  7691. // apply time scale and advance time
  7692. deltaTime *= this._updateTimeScale( time );
  7693. var clipTime = this._updateTime( deltaTime );
  7694. // note: _updateTime may disable the action resulting in
  7695. // an effective weight of 0
  7696. var weight = this._updateWeight( time );
  7697. if ( weight > 0 ) {
  7698. var interpolants = this._interpolants;
  7699. var propertyMixers = this._propertyBindings;
  7700. for ( var j = 0, m = interpolants.length; j !== m; ++ j ) {
  7701. interpolants[ j ].evaluate( clipTime );
  7702. propertyMixers[ j ].accumulate( accuIndex, weight );
  7703. }
  7704. }
  7705. },
  7706. _updateWeight: function( time ) {
  7707. var weight = 0;
  7708. if ( this.enabled ) {
  7709. weight = this.weight;
  7710. var interpolant = this._weightInterpolant;
  7711. if ( interpolant !== null ) {
  7712. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  7713. weight *= interpolantValue;
  7714. if ( time > interpolant.parameterPositions[ 1 ] ) {
  7715. this.stopFading();
  7716. if ( interpolantValue === 0 ) {
  7717. // faded out, disable
  7718. this.enabled = false;
  7719. }
  7720. }
  7721. }
  7722. }
  7723. this._effectiveWeight = weight;
  7724. return weight;
  7725. },
  7726. _updateTimeScale: function( time ) {
  7727. var timeScale = 0;
  7728. if ( ! this.paused ) {
  7729. timeScale = this.timeScale;
  7730. var interpolant = this._timeScaleInterpolant;
  7731. if ( interpolant !== null ) {
  7732. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  7733. timeScale *= interpolantValue;
  7734. if ( time > interpolant.parameterPositions[ 1 ] ) {
  7735. this.stopWarping();
  7736. if ( timeScale === 0 ) {
  7737. // motion has halted, pause
  7738. this.pause = true;
  7739. } else {
  7740. // warp done - apply final time scale
  7741. this.timeScale = timeScale;
  7742. }
  7743. }
  7744. }
  7745. }
  7746. this._effectiveTimeScale = timeScale;
  7747. return timeScale;
  7748. },
  7749. _updateTime: function( deltaTime ) {
  7750. var time = this.time + deltaTime;
  7751. if ( deltaTime === 0 ) return time;
  7752. var duration = this._clip.duration,
  7753. loop = this.loop,
  7754. loopCount = this._loopCount,
  7755. pingPong = false;
  7756. switch ( loop ) {
  7757. case THREE.LoopOnce:
  7758. case THREE.LoopOnceClamp:
  7759. if ( loopCount === -1 ) {
  7760. // just started
  7761. this.loopCount = 0;
  7762. this._setEndings( true, true, false );
  7763. }
  7764. if ( time >= duration ) {
  7765. time = duration;
  7766. } else if ( time < 0 ) {
  7767. time = 0;
  7768. } else break;
  7769. // reached the end
  7770. if ( this.clampWhenFinished ) this.pause = true;
  7771. else this.enabled = false;
  7772. this._mixer.dispatchEvent( {
  7773. type: 'finished', action: this,
  7774. direction: deltaTime < 0 ? -1 : 1
  7775. } );
  7776. break;
  7777. case THREE.LoopPingPong:
  7778. pingPong = true;
  7779. case THREE.LoopRepeat:
  7780. if ( loopCount === -1 ) {
  7781. // just started
  7782. if ( deltaTime > 0 ) {
  7783. loopCount = 0;
  7784. this._setEndings(
  7785. true, this.repetitions === 0, pingPong );
  7786. } else {
  7787. // when looping in reverse direction, the initial
  7788. // transition through zero counts as a repetition,
  7789. // so leave loopCount at -1
  7790. this._setEndings(
  7791. this.repetitions === 0, true, pingPong );
  7792. }
  7793. }
  7794. if ( time >= duration || time < 0 ) {
  7795. // wrap around
  7796. var loopDelta = Math.floor( time / duration ); // signed
  7797. time -= duration * loopDelta;
  7798. loopCount += Math.abs( loopDelta );
  7799. var pending = this.repetitions - loopCount;
  7800. if ( pending < 0 ) {
  7801. // stop (switch state, clamp time, fire event)
  7802. if ( this.clampWhenFinished ) this.paused = true;
  7803. else this.enabled = false;
  7804. time = deltaTime > 0 ? duration : 0;
  7805. this._mixer.dispatchEvent( {
  7806. type: 'finished', action: this,
  7807. direction: deltaTime > 0 ? 1 : -1
  7808. } );
  7809. break;
  7810. } else if ( pending === 0 ) {
  7811. // transition to last round
  7812. var atStart = deltaTime < 0;
  7813. this._setEndings( atStart, ! atStart, pingPong );
  7814. } else {
  7815. this._setEndings( false, false, pingPong );
  7816. }
  7817. this._loopCount = loopCount;
  7818. this._mixer.dispatchEvent( {
  7819. type: 'loop', action: this, loopDelta: loopDelta
  7820. } );
  7821. }
  7822. if ( loop === THREE.LoopPingPong && ( loopCount & 1 ) === 1 ) {
  7823. // invert time for the "pong round"
  7824. this.time = time;
  7825. return duration - time;
  7826. }
  7827. break;
  7828. }
  7829. this.time = time;
  7830. return time;
  7831. },
  7832. _setEndings: function( atStart, atEnd, pingPong ) {
  7833. var settings = this._interpolantSettings;
  7834. if ( pingPong ) {
  7835. settings.endingStart = THREE.ZeroSlopeEnding;
  7836. settings.endingEnd = THREE.ZeroSlopeEnding;
  7837. } else {
  7838. // assuming for LoopOnce atStart == atEnd == true
  7839. if ( atStart ) {
  7840. settings.endingStart = this.zeroSlopeAtStart ?
  7841. THREE.ZeroSlopeEnding : THREE.ZeroCurvatureEnding;
  7842. } else {
  7843. settings.endingStart = THREE.WrapAroundEnding;
  7844. }
  7845. if ( atEnd ) {
  7846. settings.endingEnd = this.zeroSlopeAtEnd ?
  7847. THREE.ZeroSlopeEnding : THREE.ZeroCurvatureEnding;
  7848. } else {
  7849. settings.endingEnd = THREE.WrapAroundEnding;
  7850. }
  7851. }
  7852. },
  7853. _scheduleFading: function( duration, weightNow, weightThen ) {
  7854. var mixer = this._mixer, now = mixer.time,
  7855. interpolant = this._weightInterpolant;
  7856. if ( interpolant === null ) {
  7857. interpolant = mixer._lendControlInterpolant(),
  7858. this._weightInterpolant = interpolant;
  7859. }
  7860. var times = interpolant.parameterPositions,
  7861. values = interpolant.sampleValues;
  7862. times[ 0 ] = now; values[ 0 ] = weightNow;
  7863. times[ 1 ] = now + duration; values[ 1 ] = weightThen;
  7864. return this;
  7865. }
  7866. };
  7867. // Implementation details:
  7868. Object.assign( THREE.AnimationMixer.prototype, {
  7869. _bindAction: function( action, prototypeAction ) {
  7870. var root = action._localRoot || this._root,
  7871. tracks = action._clip.tracks,
  7872. nTracks = tracks.length,
  7873. bindings = action._propertyBindings,
  7874. interpolants = action._interpolants,
  7875. rootUuid = root.uuid,
  7876. bindingsByRoot = this._bindingsByRootAndName,
  7877. bindingsByName = bindingsByRoot[ rootUuid ];
  7878. if ( bindingsByName === undefined ) {
  7879. bindingsByName = {};
  7880. bindingsByRoot[ rootUuid ] = bindingsByName;
  7881. }
  7882. for ( var i = 0; i !== nTracks; ++ i ) {
  7883. var track = tracks[ i ],
  7884. trackName = track.name,
  7885. binding = bindingsByName[ trackName ];
  7886. if ( binding !== undefined ) {
  7887. bindings[ i ] = binding;
  7888. } else {
  7889. binding = bindings[ i ];
  7890. if ( binding !== undefined ) {
  7891. // existing binding, make sure the cache knows
  7892. if ( binding._cacheIndex === null ) {
  7893. ++ binding.referenceCount;
  7894. this._addInactiveBinding( binding, rootUuid, trackName );
  7895. }
  7896. continue;
  7897. }
  7898. var path = prototypeAction && prototypeAction.
  7899. _propertyBindings[ i ].binding.parsedPath;
  7900. binding = new THREE.PropertyMixer(
  7901. THREE.PropertyBinding.create( root, trackName, path ),
  7902. track.ValueTypeName, track.getValueSize() );
  7903. ++ binding.referenceCount;
  7904. this._addInactiveBinding( binding, rootUuid, trackName );
  7905. bindings[ i ] = binding;
  7906. }
  7907. interpolants[ i ].resultBuffer = binding.buffer;
  7908. }
  7909. },
  7910. _activateAction: function( action ) {
  7911. if ( ! this._isActiveAction( action ) ) {
  7912. if ( action._cacheIndex === null ) {
  7913. // this action has been forgotten by the cache, but the user
  7914. // appears to be still using it -> rebind
  7915. var rootUuid = ( action._localRoot || this._root ).uuid,
  7916. clipName = action._clip.name,
  7917. actionsForClip = this._actionsByClip[ clipName ];
  7918. this._bindAction( action,
  7919. actionsForClip && actionsForClip.knownActions[ 0 ] );
  7920. this._addInactiveAction( action, clipName, rootUuid );
  7921. }
  7922. var bindings = action._propertyBindings;
  7923. // increment reference counts / sort out state
  7924. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  7925. var binding = bindings[ i ];
  7926. if ( binding.useCount ++ === 0 ) {
  7927. this._lendBinding( binding );
  7928. binding.saveOriginalState();
  7929. }
  7930. }
  7931. this._lendAction( action );
  7932. }
  7933. },
  7934. _deactivateAction: function( action ) {
  7935. if ( this._isActiveAction( action ) ) {
  7936. var bindings = action._propertyBindings;
  7937. // decrement reference counts / sort out state
  7938. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  7939. var binding = bindings[ i ];
  7940. if ( -- binding.useCount === 0 ) {
  7941. binding.restoreOriginalState();
  7942. this._takeBackBinding( binding );
  7943. }
  7944. }
  7945. this._takeBackAction( action );
  7946. }
  7947. },
  7948. // Memory manager
  7949. _initMemoryManager: function() {
  7950. this._actions = []; // 'nActiveActions' followed by inactive ones
  7951. this._nActiveActions = 0;
  7952. this._actionsByClip = {};
  7953. // inside:
  7954. // {
  7955. // knownActions: Array< _Action > - used as prototypes
  7956. // actionByRoot: _Action - lookup
  7957. // }
  7958. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  7959. this._nActiveBindings = 0;
  7960. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  7961. this._controlInterpolants = []; // same game as above
  7962. this._nActiveControlInterpolants = 0;
  7963. var scope = this;
  7964. this.stats = {
  7965. actions: {
  7966. get total() { return scope._actions.length; },
  7967. get inUse() { return scope._nActiveActions; }
  7968. },
  7969. bindings: {
  7970. get total() { return scope._bindings.length; },
  7971. get inUse() { return scope._nActiveBindings; }
  7972. },
  7973. controlInterpolants: {
  7974. get total() { return scope._controlInterpolants.length; },
  7975. get inUse() { return scope._nActiveControlInterpolants; }
  7976. }
  7977. };
  7978. },
  7979. // Memory management for _Action objects
  7980. _isActiveAction: function( action ) {
  7981. var index = action._cacheIndex;
  7982. return index !== null && index < this._nActiveActions;
  7983. },
  7984. _addInactiveAction: function( action, clipName, rootUuid ) {
  7985. var actions = this._actions,
  7986. actionsByClip = this._actionsByClip,
  7987. actionsForClip = actionsByClip[ clipName ];
  7988. if ( actionsForClip === undefined ) {
  7989. actionsForClip = {
  7990. knownActions: [ action ],
  7991. actionByRoot: {}
  7992. };
  7993. action._byClipCacheIndex = 0;
  7994. actionsByClip[ clipName ] = actionsForClip;
  7995. } else {
  7996. var knownActions = actionsForClip.knownActions;
  7997. action._byClipCacheIndex = knownActions.length;
  7998. knownActions.push( action );
  7999. }
  8000. action._cacheIndex = actions.length;
  8001. actions.push( action );
  8002. actionsForClip.actionByRoot[ rootUuid ] = action;
  8003. },
  8004. _removeInactiveAction: function( action ) {
  8005. var actions = this._actions,
  8006. lastInactiveAction = actions[ actions.length - 1 ],
  8007. cacheIndex = action._cacheIndex;
  8008. lastInactiveAction._cacheIndex = cacheIndex;
  8009. actions[ cacheIndex ] = lastInactiveAction;
  8010. actions.pop();
  8011. action._cacheIndex = null;
  8012. var clipName = action._clip.name,
  8013. actionsByClip = this._actionsByClip,
  8014. actionsForClip = actionsByClip[ clipName ],
  8015. knownActionsForClip = actionsForClip.knownActions,
  8016. lastKnownAction =
  8017. knownActionsForClip[ knownActionsForClip.length - 1 ],
  8018. byClipCacheIndex = action._byClipCacheIndex;
  8019. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  8020. knownActionsForClip[ byClipCacheIndex ] = lastKnownAction;
  8021. knownActionsForClip.pop();
  8022. action._byClipCacheIndex = null;
  8023. var actionByRoot = actionsForClip.actionByRoot,
  8024. rootUuid = ( actions._localRoot || this._root ).uuid;
  8025. delete actionByRoot[ rootUuid ];
  8026. if ( knownActionsForClip.length === 0 ) {
  8027. delete actionsByClip[ clipName ];
  8028. }
  8029. this._removeInactiveBindingsForAction( action );
  8030. },
  8031. _removeInactiveBindingsForAction: function( action ) {
  8032. var bindings = action._propertyBindings;
  8033. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  8034. var binding = bindings[ i ];
  8035. if ( -- binding.referenceCount === 0 ) {
  8036. this._removeInactiveBinding( binding );
  8037. }
  8038. }
  8039. },
  8040. _lendAction: function( action ) {
  8041. // [ active actions | inactive actions ]
  8042. // [ active actions >| inactive actions ]
  8043. // s a
  8044. // <-swap->
  8045. // a s
  8046. var actions = this._actions,
  8047. prevIndex = action._cacheIndex,
  8048. lastActiveIndex = this._nActiveActions ++,
  8049. firstInactiveAction = actions[ lastActiveIndex ];
  8050. action._cacheIndex = lastActiveIndex;
  8051. actions[ lastActiveIndex ] = action;
  8052. firstInactiveAction._cacheIndex = prevIndex;
  8053. actions[ prevIndex ] = firstInactiveAction;
  8054. },
  8055. _takeBackAction: function( action ) {
  8056. // [ active actions | inactive actions ]
  8057. // [ active actions |< inactive actions ]
  8058. // a s
  8059. // <-swap->
  8060. // s a
  8061. var actions = this._actions,
  8062. prevIndex = action._cacheIndex,
  8063. firstInactiveIndex = -- this._nActiveActions,
  8064. lastActiveAction = actions[ firstInactiveIndex ];
  8065. action._cacheIndex = firstInactiveIndex;
  8066. actions[ firstInactiveIndex ] = action;
  8067. lastActiveAction._cacheIndex = prevIndex;
  8068. actions[ prevIndex ] = lastActiveAction;
  8069. },
  8070. // Memory management for PropertyMixer objects
  8071. _addInactiveBinding: function( binding, rootUuid, trackName ) {
  8072. var bindingsByRoot = this._bindingsByRootAndName,
  8073. bindingByName = bindingsByRoot[ rootUuid ],
  8074. bindings = this._bindings;
  8075. if ( bindingByName === undefined ) {
  8076. bindingByName = {};
  8077. bindingsByRoot[ rootUuid ] = bindingByName;
  8078. }
  8079. bindingByName[ trackName ] = binding;
  8080. binding._cacheIndex = bindings.length;
  8081. bindings.push( binding );
  8082. },
  8083. _removeInactiveBinding: function( binding ) {
  8084. var bindings = this._bindings,
  8085. propBinding = binding.binding,
  8086. rootUuid = propBinding.rootNode.uuid,
  8087. trackName = propBinding.path,
  8088. bindingsByRoot = this._bindingsByRootAndName,
  8089. bindingByName = bindingsByRoot[ rootUuid ],
  8090. lastInactiveBinding = bindings[ bindings.length - 1 ],
  8091. cacheIndex = binding._cacheIndex;
  8092. lastInactiveBinding._cacheIndex = cacheIndex;
  8093. bindings[ cacheIndex ] = lastInactiveBinding;
  8094. bindings.pop();
  8095. delete bindingByName[ trackName ];
  8096. remove_empty_map: {
  8097. for ( var _ in bindingByName ) break remove_empty_map;
  8098. delete bindingsByRoot[ rootUuid ];
  8099. }
  8100. },
  8101. _lendBinding: function( binding ) {
  8102. var bindings = this._bindings,
  8103. prevIndex = binding._cacheIndex,
  8104. lastActiveIndex = this._nActiveBindings ++,
  8105. firstInactiveBinding = bindings[ lastActiveIndex ];
  8106. binding._cacheIndex = lastActiveIndex;
  8107. bindings[ lastActiveIndex ] = binding;
  8108. firstInactiveBinding._cacheIndex = prevIndex;
  8109. bindings[ prevIndex ] = firstInactiveBinding;
  8110. },
  8111. _takeBackBinding: function( binding ) {
  8112. var bindings = this._bindings,
  8113. prevIndex = binding._cacheIndex,
  8114. firstInactiveIndex = -- this._nActiveBindings,
  8115. lastActiveBinding = bindings[ firstInactiveIndex ];
  8116. binding._cacheIndex = firstInactiveIndex;
  8117. bindings[ firstInactiveIndex ] = binding;
  8118. lastActiveBinding._cacheIndex = prevIndex;
  8119. bindings[ prevIndex ] = lastActiveBinding;
  8120. },
  8121. // Memory management of Interpolants for weight and time scale
  8122. _lendControlInterpolant: function() {
  8123. var interpolants = this._controlInterpolants,
  8124. lastActiveIndex = this._nActiveControlInterpolants ++,
  8125. interpolant = interpolants[ lastActiveIndex ];
  8126. if ( interpolant === undefined ) {
  8127. interpolant = new THREE.LinearInterpolant(
  8128. new Float32Array( 2 ), new Float32Array( 2 ),
  8129. 1, this._controlInterpolantsResultBuffer );
  8130. interpolant.__cacheIndex = lastActiveIndex;
  8131. interpolants[ lastActiveIndex ] = interpolant;
  8132. }
  8133. return interpolant;
  8134. },
  8135. _takeBackControlInterpolant: function( interpolant ) {
  8136. var interpolants = this._controlInterpolants,
  8137. prevIndex = interpolant.__cacheIndex,
  8138. firstInactiveIndex = -- this._nActiveControlInterpolants,
  8139. lastActiveInterpolant = interpolants[ firstInactiveIndex ];
  8140. interpolant.__cacheIndex = firstInactiveIndex;
  8141. interpolants[ firstInactiveIndex ] = interpolant;
  8142. lastActiveInterpolant.__cacheIndex = prevIndex;
  8143. interpolants[ prevIndex ] = lastActiveInterpolant;
  8144. },
  8145. _controlInterpolantsResultBuffer: new Float32Array( 1 )
  8146. } );
  8147. // File:src/animation/AnimationObjectGroup.js
  8148. /**
  8149. *
  8150. * A group of objects that receives a shared animation state.
  8151. *
  8152. * Usage:
  8153. *
  8154. * - Add objects you would otherwise pass as 'root' to the
  8155. * constructor or the .clipAction method of AnimationMixer.
  8156. *
  8157. * - Instead pass this object as 'root'.
  8158. *
  8159. * - You can also add and remove objects later when the mixer
  8160. * is running.
  8161. *
  8162. * Note:
  8163. *
  8164. * Objects of this class appear as one object to the mixer,
  8165. * so cache control of the individual objects must be done
  8166. * on the group.
  8167. *
  8168. * Limitation:
  8169. *
  8170. * - The animated properties must be compatible among the
  8171. * all objects in the group.
  8172. *
  8173. * - A single property can either be controlled through a
  8174. * target group or directly, but not both.
  8175. *
  8176. * @author tschw
  8177. */
  8178. THREE.AnimationObjectGroup = function( var_args ) {
  8179. this.uuid = THREE.Math.generateUUID();
  8180. // cached objects followed by the active ones
  8181. this._objects = Array.prototype.slice.call( arguments );
  8182. this.nCachedObjects_ = 0; // threshold
  8183. // note: read by PropertyBinding.Composite
  8184. var indices = {};
  8185. this._indicesByUUID = indices; // for bookkeeping
  8186. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  8187. indices[ arguments[ i ].uuid ] = i;
  8188. }
  8189. this._paths = []; // inside: string
  8190. this._parsedPaths = []; // inside: { we don't care, here }
  8191. this._bindings = []; // inside: Array< PropertyBinding >
  8192. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  8193. var scope = this;
  8194. this.stats = {
  8195. objects: {
  8196. get total() { return scope._objects.length; },
  8197. get inUse() { return this.total - scope.nCachedObjects_; }
  8198. },
  8199. get bindingsPerObject() { return scope._bindings.length; }
  8200. };
  8201. };
  8202. THREE.AnimationObjectGroup.prototype = {
  8203. constructor: THREE.AnimationObjectGroup,
  8204. add: function( var_args ) {
  8205. var objects = this._objects,
  8206. nObjects = objects.length,
  8207. nCachedObjects = this.nCachedObjects_,
  8208. indicesByUUID = this._indicesByUUID,
  8209. paths = this._paths,
  8210. parsedPaths = this._parsedPaths,
  8211. bindings = this._bindings,
  8212. nBindings = bindings.length;
  8213. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  8214. var object = arguments[ i ],
  8215. uuid = object.uuid,
  8216. index = indicesByUUID[ uuid ];
  8217. if ( index === undefined ) {
  8218. // unknown object -> add it to the ACTIVE region
  8219. index = nObjects ++;
  8220. indicesByUUID[ uuid ] = index;
  8221. objects.push( object );
  8222. // accounting is done, now do the same for all bindings
  8223. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8224. bindings[ j ].push(
  8225. new THREE.PropertyBinding(
  8226. object, paths[ j ], parsedPaths[ j ] ) );
  8227. }
  8228. } else if ( index < nCachedObjects ) {
  8229. var knownObject = objects[ index ];
  8230. // move existing object to the ACTIVE region
  8231. var firstActiveIndex = -- nCachedObjects,
  8232. lastCachedObject = objects[ firstActiveIndex ];
  8233. indicesByUUID[ lastCachedObject.uuid ] = index;
  8234. objects[ index ] = lastCachedObject;
  8235. indicesByUUID[ uuid ] = firstActiveIndex;
  8236. objects[ firstActiveIndex ] = object;
  8237. // accounting is done, now do the same for all bindings
  8238. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8239. var bindingsForPath = bindings[ j ],
  8240. lastCached = bindingsForPath[ firstActiveIndex ],
  8241. binding = bindingsForPath[ index ];
  8242. bindingsForPath[ index ] = lastCached;
  8243. if ( binding === undefined ) {
  8244. // since we do not bother to create new bindings
  8245. // for objects that are cached, the binding may
  8246. // or may not exist
  8247. binding = new THREE.PropertyBinding(
  8248. object, paths[ j ], parsedPaths[ j ] );
  8249. }
  8250. bindingsForPath[ firstActiveIndex ] = binding;
  8251. }
  8252. } else if ( objects[ index ] !== knownObject) {
  8253. console.error( "Different objects with the same UUID " +
  8254. "detected. Clean the caches or recreate your " +
  8255. "infrastructure when reloading scenes..." );
  8256. } // else the object is already where we want it to be
  8257. } // for arguments
  8258. this.nCachedObjects_ = nCachedObjects;
  8259. },
  8260. remove: function( var_args ) {
  8261. var objects = this._objects,
  8262. nObjects = objects.length,
  8263. nCachedObjects = this.nCachedObjects_,
  8264. indicesByUUID = this._indicesByUUID,
  8265. bindings = this._bindings,
  8266. nBindings = bindings.length;
  8267. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  8268. var object = arguments[ i ],
  8269. uuid = object.uuid,
  8270. index = indicesByUUID[ uuid ];
  8271. if ( index !== undefined && index >= nCachedObjects ) {
  8272. // move existing object into the CACHED region
  8273. var lastCachedIndex = nCachedObjects ++,
  8274. firstActiveObject = objects[ lastCachedIndex ];
  8275. indicesByUUID[ firstActiveObject.uuid ] = index;
  8276. objects[ index ] = firstActiveObject;
  8277. indicesByUUID[ uuid ] = lastCachedIndex;
  8278. objects[ lastCachedIndex ] = object;
  8279. // accounting is done, now do the same for all bindings
  8280. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8281. var bindingsForPath = bindings[ j ],
  8282. firstActive = bindingsForPath[ lastCachedIndex ],
  8283. binding = bindingsForPath[ index ];
  8284. bindingsForPath[ index ] = firstActive;
  8285. bindingsForPath[ lastCachedIndex ] = binding;
  8286. }
  8287. }
  8288. } // for arguments
  8289. this.nCachedObjects_ = nCachedObjects;
  8290. },
  8291. // remove & forget
  8292. uncache: function( var_args ) {
  8293. var objects = this._objects,
  8294. nObjects = objects.length,
  8295. nCachedObjects = this.nCachedObjects_,
  8296. indicesByUUID = this._indicesByUUID,
  8297. bindings = this._bindings,
  8298. nBindings = bindings.length;
  8299. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  8300. var object = arguments[ i ],
  8301. uuid = object.uuid,
  8302. index = indicesByUUID[ uuid ];
  8303. if ( index !== undefined ) {
  8304. delete indicesByUUID[ uuid ];
  8305. if ( index < nCachedObjects ) {
  8306. // object is cached, shrink the CACHED region
  8307. var firstActiveIndex = -- nCachedObjects,
  8308. lastCachedObject = objects[ firstActiveIndex ],
  8309. lastIndex = -- nObjects,
  8310. lastObject = objects[ lastIndex ];
  8311. // last cached object takes this object's place
  8312. indicesByUUID[ lastCachedObject.uuid ] = index;
  8313. objects[ index ] = lastCachedObject;
  8314. // last object goes to the activated slot and pop
  8315. indicesByUUID[ lastObject.uuid ] = firstActiveIndex;
  8316. objects[ firstActiveIndex ] = lastObject;
  8317. objects.pop();
  8318. // accounting is done, now do the same for all bindings
  8319. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8320. var bindingsForPath = bindings[ j ],
  8321. lastCached = bindingsForPath[ firstActiveIndex ],
  8322. last = bindingsForPath[ lastIndex ];
  8323. bindingsForPath[ index ] = lastCached;
  8324. bindingsForPath[ firstActiveIndex ] = last;
  8325. bindingsForPath.pop();
  8326. }
  8327. } else {
  8328. // object is active, just swap with the last and pop
  8329. var lastIndex = -- nObjects,
  8330. lastObject = objects[ lastIndex ];
  8331. indicesByUUID[ lastObject.uuid ] = index;
  8332. objects[ index ] = lastObject;
  8333. objects.pop();
  8334. // accounting is done, now do the same for all bindings
  8335. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8336. var bindingsForPath = bindings[ j ];
  8337. bindingsForPath[ index ] = bindingsForPath[ lastIndex ];
  8338. bindingsForPath.pop();
  8339. }
  8340. } // cached or active
  8341. } // if object is known
  8342. } // for arguments
  8343. this.nCachedObjects_ = nCachedObjects;
  8344. },
  8345. // Internal interface used by befriended PropertyBinding.Composite:
  8346. subscribe_: function( path, parsedPath ) {
  8347. // returns an array of bindings for the given path that is changed
  8348. // according to the contained objects in the group
  8349. var indicesByPath = this._bindingsIndicesByPath,
  8350. index = indicesByPath[ path ],
  8351. bindings = this._bindings;
  8352. if ( index !== undefined ) return bindings[ index ];
  8353. var paths = this._paths,
  8354. parsedPaths = this._parsedPaths,
  8355. objects = this._objects,
  8356. nObjects = objects.length,
  8357. nCachedObjects = this.nCachedObjects_,
  8358. bindingsForPath = new Array( nObjects );
  8359. index = bindings.length;
  8360. indicesByPath[ path ] = index;
  8361. paths.push( path );
  8362. parsedPaths.push( parsedPath );
  8363. bindings.push( bindingsForPath );
  8364. for ( var i = nCachedObjects,
  8365. n = objects.length; i !== n; ++ i ) {
  8366. var object = objects[ i ];
  8367. bindingsForPath[ i ] =
  8368. new THREE.PropertyBinding( object, path, parsedPath );
  8369. }
  8370. return bindingsForPath;
  8371. },
  8372. unsubscribe_: function( path ) {
  8373. // tells the group to forget about a property path and no longer
  8374. // update the array previously obtained with 'subscribe_'
  8375. var indicesByPath = this._bindingsIndicesByPath,
  8376. index = indicesByPath[ path ];
  8377. if ( index !== undefined ) {
  8378. var paths = this._paths,
  8379. parsedPaths = this._parsedPaths,
  8380. bindings = this._bindings,
  8381. lastBindingsIndex = bindings.length - 1,
  8382. lastBindings = bindings[ lastBindingsIndex ],
  8383. lastBindingsPath = path[ lastBindingsIndex ];
  8384. indicesByPath[ lastBindingsPath ] = index;
  8385. bindings[ index ] = lastBindings;
  8386. bindings.pop();
  8387. parsedPaths[ index ] = parsedPaths[ lastBindingsIndex ];
  8388. parsedPaths.pop();
  8389. paths[ index ] = paths[ lastBindingsIndex ];
  8390. paths.pop();
  8391. }
  8392. }
  8393. };
  8394. // File:src/animation/AnimationUtils.js
  8395. /**
  8396. * @author tschw
  8397. * @author Ben Houston / http://clara.io/
  8398. * @author David Sarno / http://lighthaus.us/
  8399. */
  8400. THREE.AnimationUtils = {
  8401. // same as Array.prototype.slice, but also works on typed arrays
  8402. arraySlice: function( array, from, to ) {
  8403. if ( THREE.AnimationUtils.isTypedArray( array ) ) {
  8404. return new array.constructor( array.subarray( from, to ) );
  8405. }
  8406. return array.slice( from, to );
  8407. },
  8408. // converts an array to a specific type
  8409. convertArray: function( array, type, forceClone ) {
  8410. if ( ! array || // let 'undefined' and 'null' pass
  8411. ! forceClone && array.constructor === type ) return array;
  8412. if ( typeof type.BYTES_PER_ELEMENT === 'number' ) {
  8413. return new type( array ); // create typed array
  8414. }
  8415. return Array.prototype.slice.call( array ); // create Array
  8416. },
  8417. isTypedArray: function( object ) {
  8418. return ArrayBuffer.isView( object ) &&
  8419. ! ( object instanceof DataView );
  8420. },
  8421. // returns an array by which times and values can be sorted
  8422. getKeyframeOrder: function( times ) {
  8423. function compareTime( i, j ) {
  8424. return times[ i ] - times[ j ];
  8425. }
  8426. var n = times.length;
  8427. var result = new Array( n );
  8428. for ( var i = 0; i !== n; ++ i ) result[ i ] = i;
  8429. result.sort( compareTime );
  8430. return result;
  8431. },
  8432. // uses the array previously returned by 'getKeyframeOrder' to sort data
  8433. sortedArray: function( values, stride, order ) {
  8434. var nValues = values.length;
  8435. var result = new values.constructor( nValues );
  8436. for ( var i = 0, dstOffset = 0; dstOffset !== nValues; ++ i ) {
  8437. var srcOffset = order[ i ] * stride;
  8438. for ( var j = 0; j !== stride; ++ j ) {
  8439. result[ dstOffset ++ ] = values[ srcOffset + j ];
  8440. }
  8441. }
  8442. return result;
  8443. },
  8444. // function for parsing AOS keyframe formats
  8445. flattenJSON: function( jsonKeys, times, values, valuePropertyName ) {
  8446. var i = 1, key = jsonKeys[ 0 ];
  8447. while ( key !== undefined && key[ valuePropertyName ] === undefined ) {
  8448. key = jsonKeys[ i ++ ];
  8449. }
  8450. if ( key === undefined ) return; // no data
  8451. var value = key[ valuePropertyName ];
  8452. if ( value === undefined ) return; // no data
  8453. if ( Array.isArray( value ) ) {
  8454. do {
  8455. value = key[ valuePropertyName ];
  8456. if ( value !== undefined ) {
  8457. times.push( key.time );
  8458. values.push.apply( values, value ); // push all elements
  8459. }
  8460. key = jsonKeys[ i ++ ];
  8461. } while ( key !== undefined );
  8462. } else if ( value.toArray !== undefined ) {
  8463. // ...assume THREE.Math-ish
  8464. do {
  8465. value = key[ valuePropertyName ];
  8466. if ( value !== undefined ) {
  8467. times.push( key.time );
  8468. value.toArray( values, values.length );
  8469. }
  8470. key = jsonKeys[ i ++ ];
  8471. } while ( key !== undefined );
  8472. } else {
  8473. // otherwise push as-is
  8474. do {
  8475. value = key[ valuePropertyName ];
  8476. if ( value !== undefined ) {
  8477. times.push( key.time );
  8478. values.push( value );
  8479. }
  8480. key = jsonKeys[ i ++ ];
  8481. } while ( key !== undefined );
  8482. }
  8483. }
  8484. };
  8485. // File:src/animation/KeyframeTrack.js
  8486. /**
  8487. *
  8488. * A timed sequence of keyframes for a specific property.
  8489. *
  8490. *
  8491. * @author Ben Houston / http://clara.io/
  8492. * @author David Sarno / http://lighthaus.us/
  8493. * @author tschw
  8494. */
  8495. THREE.KeyframeTrack = function ( name, times, values, interpolation ) {
  8496. if( name === undefined ) throw new Error( "track name is undefined" );
  8497. if( times === undefined || times.length === 0 ) {
  8498. throw new Error( "no keyframes in track named " + name );
  8499. }
  8500. this.name = name;
  8501. this.times = THREE.AnimationUtils.convertArray( times, this.TimeBufferType );
  8502. this.values = THREE.AnimationUtils.convertArray( values, this.ValueBufferType );
  8503. this.setInterpolation( interpolation || this.DefaultInterpolation );
  8504. this.validate();
  8505. this.optimize();
  8506. };
  8507. THREE.KeyframeTrack.prototype = {
  8508. constructor: THREE.KeyframeTrack,
  8509. TimeBufferType: Float32Array,
  8510. ValueBufferType: Float32Array,
  8511. DefaultInterpolation: THREE.InterpolateLinear,
  8512. InterpolantFactoryMethodDiscrete: function( result ) {
  8513. return new THREE.DiscreteInterpolant(
  8514. this.times, this.values, this.getValueSize(), result );
  8515. },
  8516. InterpolantFactoryMethodLinear: function( result ) {
  8517. return new THREE.LinearInterpolant(
  8518. this.times, this.values, this.getValueSize(), result );
  8519. },
  8520. InterpolantFactoryMethodSmooth: function( result ) {
  8521. return new THREE.CubicInterpolant(
  8522. this.times, this.values, this.getValueSize(), result );
  8523. },
  8524. setInterpolation: function( interpolation ) {
  8525. var factoryMethod = undefined;
  8526. switch ( interpolation ) {
  8527. case THREE.InterpolateDiscrete:
  8528. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  8529. break;
  8530. case THREE.InterpolateLinear:
  8531. factoryMethod = this.InterpolantFactoryMethodLinear;
  8532. break;
  8533. case THREE.InterpolateSmooth:
  8534. factoryMethod = this.InterpolantFactoryMethodSmooth;
  8535. break;
  8536. }
  8537. if ( factoryMethod === undefined ) {
  8538. var message = "unsupported interpolation for " +
  8539. this.ValueTypeName + " keyframe track named " + this.name;
  8540. if ( this.createInterpolant === undefined ) {
  8541. // fall back to default, unless the default itself is messed up
  8542. if ( interpolation !== this.DefaultInterpolation ) {
  8543. this.setInterpolation( this.DefaultInterpolation );
  8544. } else {
  8545. throw new Error( message ); // fatal, in this case
  8546. }
  8547. }
  8548. console.warn( message );
  8549. return;
  8550. }
  8551. this.createInterpolant = factoryMethod;
  8552. },
  8553. getInterpolation: function() {
  8554. switch ( this.createInterpolant ) {
  8555. case this.InterpolantFactoryMethodDiscrete:
  8556. return THREE.InterpolateDiscrete;
  8557. case this.InterpolantFactoryMethodLinear:
  8558. return THREE.InterpolateLinear;
  8559. case this.InterpolantFactoryMethodSmooth:
  8560. return THREE.InterpolateSmooth;
  8561. }
  8562. },
  8563. getValueSize: function() {
  8564. return this.values.length / this.times.length;
  8565. },
  8566. // move all keyframes either forwards or backwards in time
  8567. shift: function( timeOffset ) {
  8568. if( timeOffset !== 0.0 ) {
  8569. var times = this.times;
  8570. for( var i = 0, n = times.length; i !== n; ++ i ) {
  8571. times[ i ] += timeOffset;
  8572. }
  8573. }
  8574. return this;
  8575. },
  8576. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  8577. scale: function( timeScale ) {
  8578. if( timeScale !== 1.0 ) {
  8579. var times = this.times;
  8580. for( var i = 0, n = times.length; i !== n; ++ i ) {
  8581. times[ i ] *= timeScale;
  8582. }
  8583. }
  8584. return this;
  8585. },
  8586. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  8587. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  8588. trim: function( startTime, endTime ) {
  8589. var times = this.times;
  8590. var nKeys = times.length;
  8591. var firstKeysToRemove = 0;
  8592. for ( var i = 1; i !== nKeys; ++ i ) {
  8593. if ( times[i] <= startTime ) ++ firstKeysToRemove;
  8594. }
  8595. var lastKeysToRemove = 0;
  8596. for ( var i = nKeys - 2; i !== 0; -- i ) {
  8597. if ( times[i] >= endTime ) ++ lastKeysToRemove;
  8598. else break;
  8599. }
  8600. // remove last keys first because it doesn't affect the position of the first keys (the otherway around doesn't work as easily)
  8601. if( ( firstKeysToRemove + lastKeysToRemove ) !== 0 ) {
  8602. var from = firstKeysToRemove;
  8603. var to = nKeys - lastKeysToRemove - firstKeysToRemove;
  8604. this.times = THREE.AnimationUtils.arraySlice( times, from, to );
  8605. var values = this.values;
  8606. var stride = this.getValueSize();
  8607. this.values = THREE.AnimationUtils.arraySlice( values, from * stride, to * stride );
  8608. }
  8609. return this;
  8610. },
  8611. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  8612. validate: function() {
  8613. var valid = true;
  8614. var valueSize = this.getValueSize();
  8615. if ( valueSize - Math.floor( valueSize ) !== 0 ) {
  8616. console.error( "invalid value size in track", this );
  8617. valid = false;
  8618. }
  8619. var times = this.times,
  8620. values = this.values,
  8621. nKeys = times.length;
  8622. if( nKeys === 0 ) {
  8623. console.error( "track is empty", this );
  8624. valid = false;
  8625. }
  8626. var prevTime = null;
  8627. for( var i = 0; i !== nKeys; i ++ ) {
  8628. var currTime = times[ i ];
  8629. if ( typeof currTime === 'number' && isNaN( currTime ) ) {
  8630. console.error( "time is not a valid number", this, i, currTime );
  8631. valid = false;
  8632. break;
  8633. }
  8634. if( prevTime !== null && prevTime > currTime ) {
  8635. console.error( "out of order keys", this, i, currTime, prevTime );
  8636. valid = false;
  8637. break;
  8638. }
  8639. prevTime = currTime;
  8640. }
  8641. if ( values !== undefined ) {
  8642. if ( THREE.AnimationUtils.isTypedArray( values ) ) {
  8643. for ( var i = 0, n = values.length; i !== n; ++ i ) {
  8644. var value = values[ i ];
  8645. if ( isNaN( value ) ) {
  8646. console.error( "value is not a valid number", this, i, value );
  8647. valid = false;
  8648. break;
  8649. }
  8650. }
  8651. }
  8652. }
  8653. return valid;
  8654. },
  8655. // removes equivalent sequential keys as common in morph target sequences
  8656. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  8657. optimize: function() {
  8658. var times = this.times,
  8659. values = this.values,
  8660. stride = this.getValueSize(),
  8661. writeIndex = 1;
  8662. for( var i = 1, n = times.length - 1; i <= n; ++ i ) {
  8663. var keep = false;
  8664. var time = times[ i ];
  8665. var timeNext = times[ i + 1 ];
  8666. // remove adjacent keyframes scheduled at the same time
  8667. if ( time !== timeNext && ( i !== 1 || time !== time[ 0 ] ) ) {
  8668. // remove unnecessary keyframes same as their neighbors
  8669. var offset = i * stride,
  8670. offsetP = offset - stride,
  8671. offsetN = offset + stride;
  8672. for ( var j = 0; j !== stride; ++ j ) {
  8673. var value = values[ offset + j ];
  8674. if ( value !== values[ offsetP + j ] ||
  8675. value !== values[ offsetN + j ] ) {
  8676. keep = true;
  8677. break;
  8678. }
  8679. }
  8680. }
  8681. // in-place compaction
  8682. if ( keep ) {
  8683. if ( i !== writeIndex ) {
  8684. times[ writeIndex ] = times[ i ];
  8685. var readOffset = i * stride,
  8686. writeOffset = writeIndex * stride;
  8687. for ( var j = 0; j !== stride; ++ j ) {
  8688. values[ writeOffset + j ] = values[ readOffset + j ];
  8689. }
  8690. }
  8691. ++ writeIndex;
  8692. }
  8693. }
  8694. if ( writeIndex !== times.length ) {
  8695. this.times = THREE.AnimationUtils.arraySlice( times, 0, writeIndex );
  8696. this.values = THREE.AnimationUtils.arraySlice( values, 0, writeIndex * stride );
  8697. }
  8698. return this;
  8699. }
  8700. };
  8701. // Static methods:
  8702. Object.assign( THREE.KeyframeTrack, {
  8703. // Serialization (in static context, because of constructor invocation
  8704. // and automatic invocation of .toJSON):
  8705. parse: function( json ) {
  8706. if( json.type === undefined ) {
  8707. throw new Error( "track type undefined, can not parse" );
  8708. }
  8709. var trackType = THREE.KeyframeTrack._getTrackTypeForValueTypeName( json.type );
  8710. if ( json.times === undefined ) {
  8711. console.warn( "legacy JSON format detected, converting" );
  8712. var times = [], values = [];
  8713. THREE.AnimationUtils.flattenJSON( json.keys, times, values, 'value' );
  8714. json.times = times;
  8715. json.values = values;
  8716. }
  8717. // derived classes can define a static parse method
  8718. if ( trackType.parse !== undefined ) {
  8719. return trackType.parse( json );
  8720. } else {
  8721. // by default, we asssume a constructor compatible with the base
  8722. return new trackType(
  8723. json.name, json.times, json.values, json.interpolation );
  8724. }
  8725. },
  8726. toJSON: function( track ) {
  8727. var trackType = track.constructor;
  8728. var json;
  8729. // derived classes can define a static toJSON method
  8730. if ( trackType.toJSON !== undefined ) {
  8731. json = trackType.toJSON( track );
  8732. } else {
  8733. // by default, we assume the data can be serialized as-is
  8734. json = {
  8735. 'name': track.name,
  8736. 'times': THREE.AnimationUtils.convertArray( track.times, Array ),
  8737. 'values': THREE.AnimationUtils.convertArray( track.values, Array )
  8738. };
  8739. var interpolation = track.getInterpolation();
  8740. if ( interpolation !== track.DefaultInterpolation ) {
  8741. json.interpolation = interpolation;
  8742. }
  8743. }
  8744. json.type = track.ValueTypeName; // mandatory
  8745. return json;
  8746. },
  8747. _getTrackTypeForValueTypeName: function( typeName ) {
  8748. switch( typeName.toLowerCase() ) {
  8749. case "scalar":
  8750. case "double":
  8751. case "float":
  8752. case "number":
  8753. case "integer":
  8754. return THREE.NumberKeyframeTrack;
  8755. case "vector":
  8756. case "vector2":
  8757. case "vector3":
  8758. case "vector4":
  8759. return THREE.VectorKeyframeTrack;
  8760. case "color":
  8761. return THREE.ColorKeyframeTrack;
  8762. case "quaternion":
  8763. return THREE.QuaternionKeyframeTrack;
  8764. case "bool":
  8765. case "boolean":
  8766. return THREE.BooleanKeyframeTrack;
  8767. case "string":
  8768. return THREE.StringKeyframeTrack;
  8769. };
  8770. throw new Error( "Unsupported typeName: " + typeName );
  8771. }
  8772. } );
  8773. // File:src/animation/PropertyBinding.js
  8774. /**
  8775. *
  8776. * A reference to a real property in the scene graph.
  8777. *
  8778. *
  8779. * @author Ben Houston / http://clara.io/
  8780. * @author David Sarno / http://lighthaus.us/
  8781. * @author tschw
  8782. */
  8783. THREE.PropertyBinding = function ( rootNode, path, parsedPath ) {
  8784. this.path = path;
  8785. this.parsedPath = parsedPath ||
  8786. THREE.PropertyBinding.parseTrackName( path );
  8787. this.node = THREE.PropertyBinding.findNode(
  8788. rootNode, this.parsedPath.nodeName ) || rootNode;
  8789. this.rootNode = rootNode;
  8790. };
  8791. THREE.PropertyBinding.prototype = {
  8792. constructor: THREE.PropertyBinding,
  8793. getValue: function getValue_unbound( targetArray, offset ) {
  8794. this.bind();
  8795. this.getValue( targetArray, offset );
  8796. // Note: This class uses a State pattern on a per-method basis:
  8797. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  8798. // prototype version of these methods with one that represents
  8799. // the bound state. When the property is not found, the methods
  8800. // become no-ops.
  8801. },
  8802. setValue: function getValue_unbound( sourceArray, offset ) {
  8803. this.bind();
  8804. this.setValue( sourceArray, offset );
  8805. },
  8806. // create getter / setter pair for a property in the scene graph
  8807. bind: function() {
  8808. var targetObject = this.node,
  8809. parsedPath = this.parsedPath,
  8810. objectName = parsedPath.objectName,
  8811. propertyName = parsedPath.propertyName,
  8812. propertyIndex = parsedPath.propertyIndex;
  8813. if ( ! targetObject ) {
  8814. targetObject = THREE.PropertyBinding.findNode(
  8815. this.rootNode, parsedPath.nodeName ) || this.rootNode;
  8816. this.node = targetObject;
  8817. }
  8818. // set fail state so we can just 'return' on error
  8819. this.getValue = this._getValue_unavailable;
  8820. this.setValue = this._setValue_unavailable;
  8821. // ensure there is a value node
  8822. if ( ! targetObject ) {
  8823. console.error( " trying to update node for track: " + this.path + " but it wasn't found." );
  8824. return;
  8825. }
  8826. if( objectName ) {
  8827. var objectIndex = parsedPath.objectIndex;
  8828. // special cases were we need to reach deeper into the hierarchy to get the face materials....
  8829. switch ( objectName ) {
  8830. case 'materials':
  8831. if( ! targetObject.material ) {
  8832. console.error( ' can not bind to material as node does not have a material', this );
  8833. return;
  8834. }
  8835. if( ! targetObject.material.materials ) {
  8836. console.error( ' can not bind to material.materials as node.material does not have a materials array', this );
  8837. return;
  8838. }
  8839. targetObject = targetObject.material.materials;
  8840. break;
  8841. case 'bones':
  8842. if( ! targetObject.skeleton ) {
  8843. console.error( ' can not bind to bones as node does not have a skeleton', this );
  8844. return;
  8845. }
  8846. // potential future optimization: skip this if propertyIndex is already an integer
  8847. // and convert the integer string to a true integer.
  8848. targetObject = targetObject.skeleton.bones;
  8849. // support resolving morphTarget names into indices.
  8850. for ( var i = 0; i < targetObject.length; i ++ ) {
  8851. if ( targetObject[i].name === objectIndex ) {
  8852. objectIndex = i;
  8853. break;
  8854. }
  8855. }
  8856. break;
  8857. default:
  8858. if ( targetObject[ objectName ] === undefined ) {
  8859. console.error( ' can not bind to objectName of node, undefined', this );
  8860. return;
  8861. }
  8862. targetObject = targetObject[ objectName ];
  8863. }
  8864. if ( objectIndex !== undefined ) {
  8865. if( targetObject[ objectIndex ] === undefined ) {
  8866. console.error( " trying to bind to objectIndex of objectName, but is undefined:", this, targetObject );
  8867. return;
  8868. }
  8869. targetObject = targetObject[ objectIndex ];
  8870. }
  8871. }
  8872. // resolve property
  8873. var nodeProperty = targetObject[ propertyName ];
  8874. if ( ! nodeProperty ) {
  8875. var nodeName = parsedPath.nodeName;
  8876. console.error( " trying to update property for track: " + nodeName +
  8877. '.' + propertyName + " but it wasn't found.", targetObject );
  8878. return;
  8879. }
  8880. // determine versioning scheme
  8881. var versioning = this.Versioning.None;
  8882. if ( targetObject.needsUpdate !== undefined ) { // material
  8883. versioning = this.Versioning.NeedsUpdate;
  8884. this.targetObject = targetObject;
  8885. } else if ( targetObject.matrixWorldNeedsUpdate !== undefined ) { // node transform
  8886. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  8887. this.targetObject = targetObject;
  8888. }
  8889. // determine how the property gets bound
  8890. var bindingType = this.BindingType.Direct;
  8891. if ( propertyIndex !== undefined ) {
  8892. // access a sub element of the property array (only primitives are supported right now)
  8893. if ( propertyName === "morphTargetInfluences" ) {
  8894. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  8895. // support resolving morphTarget names into indices.
  8896. if ( ! targetObject.geometry ) {
  8897. console.error( ' can not bind to morphTargetInfluences becasuse node does not have a geometry', this );
  8898. return;
  8899. }
  8900. if ( ! targetObject.geometry.morphTargets ) {
  8901. console.error( ' can not bind to morphTargetInfluences becasuse node does not have a geometry.morphTargets', this );
  8902. return;
  8903. }
  8904. for ( var i = 0; i < this.node.geometry.morphTargets.length; i ++ ) {
  8905. if ( targetObject.geometry.morphTargets[i].name === propertyIndex ) {
  8906. propertyIndex = i;
  8907. break;
  8908. }
  8909. }
  8910. }
  8911. bindingType = this.BindingType.ArrayElement;
  8912. this.resolvedProperty = nodeProperty;
  8913. this.propertyIndex = propertyIndex;
  8914. } else if ( nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined ) {
  8915. // must use copy for Object3D.Euler/Quaternion
  8916. bindingType = this.BindingType.HasFromToArray;
  8917. this.resolvedProperty = nodeProperty;
  8918. } else {
  8919. this.propertyName = propertyName;
  8920. }
  8921. // select getter / setter
  8922. this.getValue = this.GetterByBindingType[ bindingType ];
  8923. this.setValue = this.SetterByBindingTypeAndVersioning[ bindingType ][ versioning ];
  8924. },
  8925. unbind: function() {
  8926. this.node = null;
  8927. // back to the prototype version of getValue / setValue
  8928. // note: avoiding to mutate the shape of 'this' via 'delete'
  8929. this.getValue = this._getValue_unbound;
  8930. this.setValue = this._setValue_unbound;
  8931. }
  8932. };
  8933. Object.assign( THREE.PropertyBinding.prototype, { // prototype, continued
  8934. // these are used to "bind" a nonexistent property
  8935. _getValue_unavailable: function() {},
  8936. _setValue_unavailable: function() {},
  8937. // initial state of these methods that calls 'bind'
  8938. _getValue_unbound: THREE.PropertyBinding.prototype.getValue,
  8939. _setValue_unbound: THREE.PropertyBinding.prototype.setValue,
  8940. BindingType: {
  8941. Direct: 0,
  8942. ArrayElement: 1,
  8943. HasFromToArray: 2
  8944. },
  8945. Versioning: {
  8946. None: 0,
  8947. NeedsUpdate: 1,
  8948. MatrixWorldNeedsUpdate: 2
  8949. },
  8950. GetterByBindingType: [
  8951. function getValue_direct( buffer, offset ) {
  8952. buffer[ offset ] = this.node[ this.propertyName ];
  8953. },
  8954. function getValue_arrayElement( buffer, offset ) {
  8955. buffer[ offset ] = this.resolvedProperty[ this.propertyIndex ];
  8956. },
  8957. function getValue_toArray( buffer, offset ) {
  8958. this.resolvedProperty.toArray( buffer, offset );
  8959. }
  8960. ],
  8961. SetterByBindingTypeAndVersioning: [
  8962. [
  8963. // Direct
  8964. function setValue_direct( buffer, offset ) {
  8965. this.node[ this.propertyName ] = buffer[ offset ];
  8966. },
  8967. function setValue_direct_setNeedsUpdate( buffer, offset ) {
  8968. this.node[ this.propertyName ] = buffer[ offset ];
  8969. this.targetObject.needsUpdate = true;
  8970. },
  8971. function setValue_direct_setMatrixWorldNeedsUpdate( buffer, offset ) {
  8972. this.node[ this.propertyName ] = buffer[ offset ];
  8973. this.targetObject.matrixWorldNeedsUpdate = true;
  8974. }
  8975. ], [
  8976. // ArrayElement
  8977. function setValue_arrayElement( buffer, offset ) {
  8978. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  8979. },
  8980. function setValue_arrayElement_setNeedsUpdate( buffer, offset ) {
  8981. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  8982. this.targetObject.needsUpdate = true;
  8983. },
  8984. function setValue_arrayElement_setMatrixWorldNeedsUpdate( buffer, offset ) {
  8985. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  8986. this.targetObject.matrixWorldNeedsUpdate = true;
  8987. }
  8988. ], [
  8989. // HasToFromArray
  8990. function setValue_fromArray( buffer, offset ) {
  8991. this.resolvedProperty.fromArray( buffer, offset );
  8992. },
  8993. function setValue_fromArray_setNeedsUpdate( buffer, offset ) {
  8994. this.resolvedProperty.fromArray( buffer, offset );
  8995. this.targetObject.needsUpdate = true;
  8996. },
  8997. function setValue_fromArray_setMatrixWorldNeedsUpdate( buffer, offset ) {
  8998. this.resolvedProperty.fromArray( buffer, offset );
  8999. this.targetObject.matrixWorldNeedsUpdate = true;
  9000. }
  9001. ]
  9002. ]
  9003. } );
  9004. THREE.PropertyBinding.Composite =
  9005. function( targetGroup, path, optionalParsedPath ) {
  9006. var parsedPath = optionalParsedPath ||
  9007. THREE.PropertyBinding.parseTrackName( path );
  9008. this._targetGroup = targetGroup;
  9009. this._bindings = targetGroup.subscribe_( path, parsedPath );
  9010. };
  9011. THREE.PropertyBinding.Composite.prototype = {
  9012. constructor: THREE.PropertyBinding.Composite,
  9013. getValue: function( array, offset ) {
  9014. this.bind(); // bind all binding
  9015. var firstValidIndex = this._targetGroup.nCachedObjects_,
  9016. binding = this._bindings[ firstValidIndex ];
  9017. // and only call .getValue on the first
  9018. if ( binding !== undefined ) binding.getValue( array, offset );
  9019. },
  9020. setValue: function( array, offset ) {
  9021. var bindings = this._bindings;
  9022. for ( var i = this._targetGroup.nCachedObjects_,
  9023. n = bindings.length; i !== n; ++ i ) {
  9024. bindings[ i ].setValue( array, offset );
  9025. }
  9026. },
  9027. bind: function() {
  9028. var bindings = this._bindings;
  9029. for ( var i = this._targetGroup.nCachedObjects_,
  9030. n = bindings.length; i !== n; ++ i ) {
  9031. bindings[ i ].bind();
  9032. }
  9033. },
  9034. unbind: function() {
  9035. var bindings = this._bindings;
  9036. for ( var i = this._targetGroup.nCachedObjects_,
  9037. n = bindings.length; i !== n; ++ i ) {
  9038. bindings[ i ].unbind();
  9039. }
  9040. }
  9041. };
  9042. THREE.PropertyBinding.create = function( root, path, parsedPath ) {
  9043. if ( ! ( root instanceof THREE.AnimationObjectGroup ) ) {
  9044. return new THREE.PropertyBinding( root, path, parsedPath );
  9045. } else {
  9046. return new THREE.PropertyBinding.Composite( root, path, parsedPath );
  9047. }
  9048. };
  9049. THREE.PropertyBinding.parseTrackName = function( trackName ) {
  9050. // matches strings in the form of:
  9051. // nodeName.property
  9052. // nodeName.property[accessor]
  9053. // nodeName.material.property[accessor]
  9054. // uuid.property[accessor]
  9055. // uuid.objectName[objectIndex].propertyName[propertyIndex]
  9056. // parentName/nodeName.property
  9057. // parentName/parentName/nodeName.property[index]
  9058. // .bone[Armature.DEF_cog].position
  9059. // created and tested via https://regex101.com/#javascript
  9060. var re = /^(([\w]+\/)*)([\w-\d]+)?(\.([\w]+)(\[([\w\d\[\]\_. ]+)\])?)?(\.([\w.]+)(\[([\w\d\[\]\_. ]+)\])?)$/;
  9061. var matches = re.exec(trackName);
  9062. if( ! matches ) {
  9063. throw new Error( "cannot parse trackName at all: " + trackName );
  9064. }
  9065. if (matches.index === re.lastIndex) {
  9066. re.lastIndex++;
  9067. }
  9068. var results = {
  9069. // directoryName: matches[1], // (tschw) currently unused
  9070. nodeName: matches[3], // allowed to be null, specified root node.
  9071. objectName: matches[5],
  9072. objectIndex: matches[7],
  9073. propertyName: matches[9],
  9074. propertyIndex: matches[11] // allowed to be null, specifies that the whole property is set.
  9075. };
  9076. if( results.propertyName === null || results.propertyName.length === 0 ) {
  9077. throw new Error( "can not parse propertyName from trackName: " + trackName );
  9078. }
  9079. return results;
  9080. };
  9081. THREE.PropertyBinding.findNode = function( root, nodeName ) {
  9082. if( ! nodeName || nodeName === "" || nodeName === "root" || nodeName === "." || nodeName === -1 || nodeName === root.name || nodeName === root.uuid ) {
  9083. return root;
  9084. }
  9085. // search into skeleton bones.
  9086. if( root.skeleton ) {
  9087. var searchSkeleton = function( skeleton ) {
  9088. for( var i = 0; i < skeleton.bones.length; i ++ ) {
  9089. var bone = skeleton.bones[i];
  9090. if( bone.name === nodeName ) {
  9091. return bone;
  9092. }
  9093. }
  9094. return null;
  9095. };
  9096. var bone = searchSkeleton( root.skeleton );
  9097. if( bone ) {
  9098. return bone;
  9099. }
  9100. }
  9101. // search into node subtree.
  9102. if( root.children ) {
  9103. var searchNodeSubtree = function( children ) {
  9104. for( var i = 0; i < children.length; i ++ ) {
  9105. var childNode = children[i];
  9106. if( childNode.name === nodeName || childNode.uuid === nodeName ) {
  9107. return childNode;
  9108. }
  9109. var result = searchNodeSubtree( childNode.children );
  9110. if( result ) return result;
  9111. }
  9112. return null;
  9113. };
  9114. var subTreeNode = searchNodeSubtree( root.children );
  9115. if( subTreeNode ) {
  9116. return subTreeNode;
  9117. }
  9118. }
  9119. return null;
  9120. }
  9121. // File:src/animation/PropertyMixer.js
  9122. /**
  9123. *
  9124. * Buffered scene graph property that allows weighted accumulation.
  9125. *
  9126. *
  9127. * @author Ben Houston / http://clara.io/
  9128. * @author David Sarno / http://lighthaus.us/
  9129. * @author tschw
  9130. */
  9131. THREE.PropertyMixer = function ( binding, typeName, valueSize ) {
  9132. this.binding = binding;
  9133. this.valueSize = valueSize;
  9134. var bufferType = Float64Array,
  9135. mixFunction;
  9136. switch ( typeName ) {
  9137. case 'quaternion': mixFunction = this._slerp; break;
  9138. case 'string':
  9139. case 'bool':
  9140. bufferType = Array, mixFunction = this._select; break;
  9141. default: mixFunction = this._lerp;
  9142. }
  9143. this.buffer = new bufferType( valueSize * 4 );
  9144. // layout: [ incoming | accu0 | accu1 | orig ]
  9145. //
  9146. // interpolators can use .buffer as their .result
  9147. // the data then goes to 'incoming'
  9148. //
  9149. // 'accu0' and 'accu1' are used frame-interleaved for
  9150. // the cumulative result and are compared to detect
  9151. // changes
  9152. //
  9153. // 'orig' stores the original state of the property
  9154. this._mixBufferRegion = mixFunction;
  9155. this.cumulativeWeight = 0;
  9156. this.useCount = 0;
  9157. this.referenceCount = 0;
  9158. };
  9159. THREE.PropertyMixer.prototype = {
  9160. constructor: THREE.PropertyMixer,
  9161. // accumulate data in the 'incoming' region into 'accu<i>'
  9162. accumulate: function( accuIndex, weight ) {
  9163. // note: happily accumulating nothing when weight = 0, the caller knows
  9164. // the weight and shouldn't have made the call in the first place
  9165. var buffer = this.buffer,
  9166. stride = this.valueSize,
  9167. offset = accuIndex * stride + stride,
  9168. currentWeight = this.cumulativeWeight;
  9169. if ( currentWeight === 0 ) {
  9170. // accuN := incoming * weight
  9171. for ( var i = 0; i !== stride; ++ i ) {
  9172. buffer[ offset + i ] = buffer[ i ];
  9173. }
  9174. currentWeight = weight;
  9175. } else {
  9176. // accuN := accuN + incoming * weight
  9177. currentWeight += weight;
  9178. var mix = weight / currentWeight;
  9179. this._mixBufferRegion( buffer, offset, 0, mix, stride );
  9180. }
  9181. this.cumulativeWeight = currentWeight;
  9182. },
  9183. // apply the state of 'accu<i>' to the binding when accus differ
  9184. apply: function( accuIndex ) {
  9185. var stride = this.valueSize,
  9186. buffer = this.buffer,
  9187. offset = accuIndex * stride + stride,
  9188. weight = this.cumulativeWeight,
  9189. binding = this.binding;
  9190. this.cumulativeWeight = 0;
  9191. if ( weight < 1 ) {
  9192. // accuN := accuN + original * ( 1 - cumulativeWeight )
  9193. var originalValueOffset = stride * 3;
  9194. this._mixBufferRegion(
  9195. buffer, offset, originalValueOffset, 1 - weight, stride );
  9196. }
  9197. for ( var i = stride, e = stride + stride; i !== e; ++ i ) {
  9198. if ( buffer[ i ] !== buffer[ i + stride ] ) {
  9199. // value has changed -> update scene graph
  9200. binding.setValue( buffer, offset );
  9201. break;
  9202. }
  9203. }
  9204. },
  9205. // remember the state of the bound property and copy it to both accus
  9206. saveOriginalState: function() {
  9207. var binding = this.binding;
  9208. var buffer = this.buffer,
  9209. stride = this.valueSize,
  9210. originalValueOffset = stride * 3;
  9211. binding.getValue( buffer, originalValueOffset );
  9212. // accu[0..1] := orig -- initially detect changes against the original
  9213. for ( var i = stride, e = originalValueOffset; i !== e; ++ i ) {
  9214. buffer[ i ] = buffer[ originalValueOffset + ( i % stride ) ];
  9215. }
  9216. this.cumulativeWeight = 0;
  9217. },
  9218. // apply the state previously taken via 'saveOriginalState' to the binding
  9219. restoreOriginalState: function() {
  9220. var originalValueOffset = this.valueSize * 3;
  9221. this.binding.setValue( this.buffer, originalValueOffset );
  9222. },
  9223. // mix functions
  9224. _select: function( buffer, dstOffset, srcOffset, t, stride ) {
  9225. if ( t >= 0.5 ) {
  9226. for ( var i = 0; i !== stride; ++ i ) {
  9227. buffer[ dstOffset + i ] = buffer[ srcOffset + i ];
  9228. }
  9229. }
  9230. },
  9231. _slerp: function( buffer, dstOffset, srcOffset, t, stride ) {
  9232. THREE.Quaternion.slerpFlat( buffer, dstOffset,
  9233. buffer, dstOffset, buffer, srcOffset, t );
  9234. },
  9235. _lerp: function( buffer, dstOffset, srcOffset, t, stride ) {
  9236. var s = 1 - t;
  9237. for ( var i = 0; i !== stride; ++ i ) {
  9238. var j = dstOffset + i;
  9239. buffer[ j ] = buffer[ j ] * s + buffer[ srcOffset + i ] * t;
  9240. }
  9241. }
  9242. };
  9243. // File:src/animation/tracks/BooleanKeyframeTrack.js
  9244. /**
  9245. *
  9246. * A Track of Boolean keyframe values.
  9247. *
  9248. *
  9249. * @author Ben Houston / http://clara.io/
  9250. * @author David Sarno / http://lighthaus.us/
  9251. * @author tschw
  9252. */
  9253. THREE.BooleanKeyframeTrack = function ( name, times, values ) {
  9254. THREE.KeyframeTrack.call( this, name, times, values );
  9255. };
  9256. THREE.BooleanKeyframeTrack.prototype =
  9257. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9258. constructor: THREE.BooleanKeyframeTrack,
  9259. ValueTypeName: 'bool',
  9260. ValueBufferType: Array,
  9261. DefaultInterpolation: THREE.IntepolateDiscrete,
  9262. InterpolantFactoryMethodLinear: undefined,
  9263. InterpolantFactoryMethodSmooth: undefined
  9264. // Note: Actually this track could have a optimized / compressed
  9265. // representation of a single value and a custom interpolant that
  9266. // computes "firstValue ^ isOdd( index )".
  9267. } );
  9268. // File:src/animation/tracks/NumberKeyframeTrack.js
  9269. /**
  9270. *
  9271. * A Track of numeric keyframe values.
  9272. *
  9273. * @author Ben Houston / http://clara.io/
  9274. * @author David Sarno / http://lighthaus.us/
  9275. * @author tschw
  9276. */
  9277. THREE.NumberKeyframeTrack = function ( name, times, values, interpolation ) {
  9278. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9279. };
  9280. THREE.NumberKeyframeTrack.prototype =
  9281. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9282. constructor: THREE.NumberKeyframeTrack,
  9283. ValueTypeName: 'number',
  9284. // ValueBufferType is inherited
  9285. // DefaultInterpolation is inherited
  9286. } );
  9287. // File:src/animation/tracks/QuaternionKeyframeTrack.js
  9288. /**
  9289. *
  9290. * A Track of quaternion keyframe values.
  9291. *
  9292. * @author Ben Houston / http://clara.io/
  9293. * @author David Sarno / http://lighthaus.us/
  9294. * @author tschw
  9295. */
  9296. THREE.QuaternionKeyframeTrack = function ( name, times, values, interpolation ) {
  9297. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9298. };
  9299. THREE.QuaternionKeyframeTrack.prototype =
  9300. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9301. constructor: THREE.QuaternionKeyframeTrack,
  9302. ValueTypeName: 'quaternion',
  9303. // ValueBufferType is inherited
  9304. DefaultInterpolation: THREE.InterpolateLinear,
  9305. InterpolantFactoryMethodLinear: function( result ) {
  9306. return new THREE.QuaternionLinearInterpolant(
  9307. this.times, this.values, this.getValueSize(), result );
  9308. },
  9309. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  9310. } );
  9311. // File:src/animation/tracks/StringKeyframeTrack.js
  9312. /**
  9313. *
  9314. * A Track that interpolates Strings
  9315. *
  9316. *
  9317. * @author Ben Houston / http://clara.io/
  9318. * @author David Sarno / http://lighthaus.us/
  9319. * @author tschw
  9320. */
  9321. THREE.StringKeyframeTrack = function ( name, times, values, interpolation ) {
  9322. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9323. };
  9324. THREE.StringKeyframeTrack.prototype =
  9325. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9326. constructor: THREE.StringKeyframeTrack,
  9327. ValueTypeName: 'string',
  9328. ValueBufferType: Array,
  9329. DefaultInterpolation: THREE.IntepolateDiscrete,
  9330. InterpolantFactoryMethodLinear: undefined,
  9331. InterpolantFactoryMethodSmooth: undefined
  9332. } );
  9333. // File:src/animation/tracks/VectorKeyframeTrack.js
  9334. /**
  9335. *
  9336. * A Track of vectored keyframe values.
  9337. *
  9338. *
  9339. * @author Ben Houston / http://clara.io/
  9340. * @author David Sarno / http://lighthaus.us/
  9341. * @author tschw
  9342. */
  9343. THREE.VectorKeyframeTrack = function ( name, times, values, interpolation ) {
  9344. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9345. };
  9346. THREE.VectorKeyframeTrack.prototype =
  9347. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9348. constructor: THREE.VectorKeyframeTrack,
  9349. ValueTypeName: 'vector'
  9350. // ValueBufferType is inherited
  9351. // DefaultInterpolation is inherited
  9352. } );
  9353. // File:src/audio/Audio.js
  9354. /**
  9355. * @author mrdoob / http://mrdoob.com/
  9356. */
  9357. THREE.Audio = function ( listener ) {
  9358. THREE.Object3D.call( this );
  9359. this.type = 'Audio';
  9360. this.context = listener.context;
  9361. this.source = this.context.createBufferSource();
  9362. this.source.onended = this.onEnded.bind( this );
  9363. this.gain = this.context.createGain();
  9364. this.gain.connect( this.context.destination );
  9365. this.panner = this.context.createPanner();
  9366. this.panner.connect( this.gain );
  9367. this.autoplay = false;
  9368. this.startTime = 0;
  9369. this.playbackRate = 1;
  9370. this.isPlaying = false;
  9371. };
  9372. THREE.Audio.prototype = Object.create( THREE.Object3D.prototype );
  9373. THREE.Audio.prototype.constructor = THREE.Audio;
  9374. THREE.Audio.prototype.load = function ( file ) {
  9375. var scope = this;
  9376. var request = new XMLHttpRequest();
  9377. request.open( 'GET', file, true );
  9378. request.responseType = 'arraybuffer';
  9379. request.onload = function ( e ) {
  9380. scope.context.decodeAudioData( this.response, function ( buffer ) {
  9381. scope.source.buffer = buffer;
  9382. if ( scope.autoplay ) scope.play();
  9383. } );
  9384. };
  9385. request.send();
  9386. return this;
  9387. };
  9388. THREE.Audio.prototype.play = function () {
  9389. if ( this.isPlaying === true ) {
  9390. console.warn( 'THREE.Audio: Audio is already playing.' );
  9391. return;
  9392. }
  9393. var source = this.context.createBufferSource();
  9394. source.buffer = this.source.buffer;
  9395. source.loop = this.source.loop;
  9396. source.onended = this.source.onended;
  9397. source.start( 0, this.startTime );
  9398. source.playbackRate.value = this.playbackRate;
  9399. this.isPlaying = true;
  9400. this.source = source;
  9401. this.connect();
  9402. };
  9403. THREE.Audio.prototype.pause = function () {
  9404. this.source.stop();
  9405. this.startTime = this.context.currentTime;
  9406. };
  9407. THREE.Audio.prototype.stop = function () {
  9408. this.source.stop();
  9409. this.startTime = 0;
  9410. };
  9411. THREE.Audio.prototype.connect = function () {
  9412. if ( this.filter !== undefined ) {
  9413. this.source.connect( this.filter );
  9414. this.filter.connect( this.panner );
  9415. } else {
  9416. this.source.connect( this.panner );
  9417. }
  9418. };
  9419. THREE.Audio.prototype.disconnect = function () {
  9420. if ( this.filter !== undefined ) {
  9421. this.source.disconnect( this.filter );
  9422. this.filter.disconnect( this.panner );
  9423. } else {
  9424. this.source.disconnect( this.panner );
  9425. }
  9426. };
  9427. THREE.Audio.prototype.setFilter = function ( value ) {
  9428. if ( this.isPlaying === true ) {
  9429. this.disconnect();
  9430. this.filter = value;
  9431. this.connect();
  9432. } else {
  9433. this.filter = value;
  9434. }
  9435. };
  9436. THREE.Audio.prototype.getFilter = function () {
  9437. return this.filter;
  9438. };
  9439. THREE.Audio.prototype.setPlaybackRate = function ( value ) {
  9440. this.playbackRate = value;
  9441. if ( this.isPlaying === true ) {
  9442. this.source.playbackRate.value = this.playbackRate;
  9443. }
  9444. };
  9445. THREE.Audio.prototype.getPlaybackRate = function () {
  9446. return this.playbackRate;
  9447. };
  9448. THREE.Audio.prototype.onEnded = function() {
  9449. this.isPlaying = false;
  9450. };
  9451. THREE.Audio.prototype.setLoop = function ( value ) {
  9452. this.source.loop = value;
  9453. };
  9454. THREE.Audio.prototype.getLoop = function () {
  9455. return this.source.loop;
  9456. };
  9457. THREE.Audio.prototype.setRefDistance = function ( value ) {
  9458. this.panner.refDistance = value;
  9459. };
  9460. THREE.Audio.prototype.getRefDistance = function () {
  9461. return this.panner.refDistance;
  9462. };
  9463. THREE.Audio.prototype.setRolloffFactor = function ( value ) {
  9464. this.panner.rolloffFactor = value;
  9465. };
  9466. THREE.Audio.prototype.getRolloffFactor = function () {
  9467. return this.panner.rolloffFactor;
  9468. };
  9469. THREE.Audio.prototype.setVolume = function ( value ) {
  9470. this.gain.gain.value = value;
  9471. };
  9472. THREE.Audio.prototype.getVolume = function () {
  9473. return this.gain.gain.value;
  9474. };
  9475. THREE.Audio.prototype.updateMatrixWorld = ( function () {
  9476. var position = new THREE.Vector3();
  9477. return function updateMatrixWorld( force ) {
  9478. THREE.Object3D.prototype.updateMatrixWorld.call( this, force );
  9479. position.setFromMatrixPosition( this.matrixWorld );
  9480. this.panner.setPosition( position.x, position.y, position.z );
  9481. };
  9482. } )();
  9483. // File:src/audio/AudioListener.js
  9484. /**
  9485. * @author mrdoob / http://mrdoob.com/
  9486. */
  9487. THREE.AudioListener = function () {
  9488. THREE.Object3D.call( this );
  9489. this.type = 'AudioListener';
  9490. this.context = new ( window.AudioContext || window.webkitAudioContext )();
  9491. };
  9492. THREE.AudioListener.prototype = Object.create( THREE.Object3D.prototype );
  9493. THREE.AudioListener.prototype.constructor = THREE.AudioListener;
  9494. THREE.AudioListener.prototype.updateMatrixWorld = ( function () {
  9495. var position = new THREE.Vector3();
  9496. var quaternion = new THREE.Quaternion();
  9497. var scale = new THREE.Vector3();
  9498. var orientation = new THREE.Vector3();
  9499. return function updateMatrixWorld( force ) {
  9500. THREE.Object3D.prototype.updateMatrixWorld.call( this, force );
  9501. var listener = this.context.listener;
  9502. var up = this.up;
  9503. this.matrixWorld.decompose( position, quaternion, scale );
  9504. orientation.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  9505. listener.setPosition( position.x, position.y, position.z );
  9506. listener.setOrientation( orientation.x, orientation.y, orientation.z, up.x, up.y, up.z );
  9507. };
  9508. } )();
  9509. // File:src/cameras/Camera.js
  9510. /**
  9511. * @author mrdoob / http://mrdoob.com/
  9512. * @author mikael emtinger / http://gomo.se/
  9513. * @author WestLangley / http://github.com/WestLangley
  9514. */
  9515. THREE.Camera = function () {
  9516. THREE.Object3D.call( this );
  9517. this.type = 'Camera';
  9518. this.matrixWorldInverse = new THREE.Matrix4();
  9519. this.projectionMatrix = new THREE.Matrix4();
  9520. };
  9521. THREE.Camera.prototype = Object.create( THREE.Object3D.prototype );
  9522. THREE.Camera.prototype.constructor = THREE.Camera;
  9523. THREE.Camera.prototype.getWorldDirection = function () {
  9524. var quaternion = new THREE.Quaternion();
  9525. return function ( optionalTarget ) {
  9526. var result = optionalTarget || new THREE.Vector3();
  9527. this.getWorldQuaternion( quaternion );
  9528. return result.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  9529. };
  9530. }();
  9531. THREE.Camera.prototype.lookAt = function () {
  9532. // This routine does not support cameras with rotated and/or translated parent(s)
  9533. var m1 = new THREE.Matrix4();
  9534. return function ( vector ) {
  9535. m1.lookAt( this.position, vector, this.up );
  9536. this.quaternion.setFromRotationMatrix( m1 );
  9537. };
  9538. }();
  9539. THREE.Camera.prototype.clone = function () {
  9540. return new this.constructor().copy( this );
  9541. };
  9542. THREE.Camera.prototype.copy = function ( source ) {
  9543. THREE.Object3D.prototype.copy.call( this, source );
  9544. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  9545. this.projectionMatrix.copy( source.projectionMatrix );
  9546. return this;
  9547. };
  9548. // File:src/cameras/CubeCamera.js
  9549. /**
  9550. * Camera for rendering cube maps
  9551. * - renders scene into axis-aligned cube
  9552. *
  9553. * @author alteredq / http://alteredqualia.com/
  9554. */
  9555. THREE.CubeCamera = function ( near, far, cubeResolution ) {
  9556. THREE.Object3D.call( this );
  9557. this.type = 'CubeCamera';
  9558. var fov = 90, aspect = 1;
  9559. var cameraPX = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9560. cameraPX.up.set( 0, - 1, 0 );
  9561. cameraPX.lookAt( new THREE.Vector3( 1, 0, 0 ) );
  9562. this.add( cameraPX );
  9563. var cameraNX = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9564. cameraNX.up.set( 0, - 1, 0 );
  9565. cameraNX.lookAt( new THREE.Vector3( - 1, 0, 0 ) );
  9566. this.add( cameraNX );
  9567. var cameraPY = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9568. cameraPY.up.set( 0, 0, 1 );
  9569. cameraPY.lookAt( new THREE.Vector3( 0, 1, 0 ) );
  9570. this.add( cameraPY );
  9571. var cameraNY = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9572. cameraNY.up.set( 0, 0, - 1 );
  9573. cameraNY.lookAt( new THREE.Vector3( 0, - 1, 0 ) );
  9574. this.add( cameraNY );
  9575. var cameraPZ = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9576. cameraPZ.up.set( 0, - 1, 0 );
  9577. cameraPZ.lookAt( new THREE.Vector3( 0, 0, 1 ) );
  9578. this.add( cameraPZ );
  9579. var cameraNZ = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9580. cameraNZ.up.set( 0, - 1, 0 );
  9581. cameraNZ.lookAt( new THREE.Vector3( 0, 0, - 1 ) );
  9582. this.add( cameraNZ );
  9583. this.renderTarget = new THREE.WebGLRenderTargetCube( cubeResolution, cubeResolution, { format: THREE.RGBFormat, magFilter: THREE.LinearFilter, minFilter: THREE.LinearFilter } );
  9584. this.updateCubeMap = function ( renderer, scene ) {
  9585. if ( this.parent === null ) this.updateMatrixWorld();
  9586. var renderTarget = this.renderTarget;
  9587. var generateMipmaps = renderTarget.texture.generateMipmaps;
  9588. renderTarget.texture.generateMipmaps = false;
  9589. renderTarget.activeCubeFace = 0;
  9590. renderer.render( scene, cameraPX, renderTarget );
  9591. renderTarget.activeCubeFace = 1;
  9592. renderer.render( scene, cameraNX, renderTarget );
  9593. renderTarget.activeCubeFace = 2;
  9594. renderer.render( scene, cameraPY, renderTarget );
  9595. renderTarget.activeCubeFace = 3;
  9596. renderer.render( scene, cameraNY, renderTarget );
  9597. renderTarget.activeCubeFace = 4;
  9598. renderer.render( scene, cameraPZ, renderTarget );
  9599. renderTarget.texture.generateMipmaps = generateMipmaps;
  9600. renderTarget.activeCubeFace = 5;
  9601. renderer.render( scene, cameraNZ, renderTarget );
  9602. renderer.setRenderTarget( null );
  9603. };
  9604. };
  9605. THREE.CubeCamera.prototype = Object.create( THREE.Object3D.prototype );
  9606. THREE.CubeCamera.prototype.constructor = THREE.CubeCamera;
  9607. // File:src/cameras/OrthographicCamera.js
  9608. /**
  9609. * @author alteredq / http://alteredqualia.com/
  9610. */
  9611. THREE.OrthographicCamera = function ( left, right, top, bottom, near, far ) {
  9612. THREE.Camera.call( this );
  9613. this.type = 'OrthographicCamera';
  9614. this.zoom = 1;
  9615. this.left = left;
  9616. this.right = right;
  9617. this.top = top;
  9618. this.bottom = bottom;
  9619. this.near = ( near !== undefined ) ? near : 0.1;
  9620. this.far = ( far !== undefined ) ? far : 2000;
  9621. this.updateProjectionMatrix();
  9622. };
  9623. THREE.OrthographicCamera.prototype = Object.create( THREE.Camera.prototype );
  9624. THREE.OrthographicCamera.prototype.constructor = THREE.OrthographicCamera;
  9625. THREE.OrthographicCamera.prototype.updateProjectionMatrix = function () {
  9626. var dx = ( this.right - this.left ) / ( 2 * this.zoom );
  9627. var dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  9628. var cx = ( this.right + this.left ) / 2;
  9629. var cy = ( this.top + this.bottom ) / 2;
  9630. this.projectionMatrix.makeOrthographic( cx - dx, cx + dx, cy + dy, cy - dy, this.near, this.far );
  9631. };
  9632. THREE.OrthographicCamera.prototype.copy = function ( source ) {
  9633. THREE.Camera.prototype.copy.call( this, source );
  9634. this.left = source.left;
  9635. this.right = source.right;
  9636. this.top = source.top;
  9637. this.bottom = source.bottom;
  9638. this.near = source.near;
  9639. this.far = source.far;
  9640. this.zoom = source.zoom;
  9641. return this;
  9642. };
  9643. THREE.OrthographicCamera.prototype.toJSON = function ( meta ) {
  9644. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  9645. data.object.zoom = this.zoom;
  9646. data.object.left = this.left;
  9647. data.object.right = this.right;
  9648. data.object.top = this.top;
  9649. data.object.bottom = this.bottom;
  9650. data.object.near = this.near;
  9651. data.object.far = this.far;
  9652. return data;
  9653. };
  9654. // File:src/cameras/PerspectiveCamera.js
  9655. /**
  9656. * @author mrdoob / http://mrdoob.com/
  9657. * @author greggman / http://games.greggman.com/
  9658. * @author zz85 / http://www.lab4games.net/zz85/blog
  9659. */
  9660. THREE.PerspectiveCamera = function ( fov, aspect, near, far ) {
  9661. THREE.Camera.call( this );
  9662. this.type = 'PerspectiveCamera';
  9663. this.zoom = 1;
  9664. this.fov = fov !== undefined ? fov : 50;
  9665. this.aspect = aspect !== undefined ? aspect : 1;
  9666. this.near = near !== undefined ? near : 0.1;
  9667. this.far = far !== undefined ? far : 2000;
  9668. this.updateProjectionMatrix();
  9669. };
  9670. THREE.PerspectiveCamera.prototype = Object.create( THREE.Camera.prototype );
  9671. THREE.PerspectiveCamera.prototype.constructor = THREE.PerspectiveCamera;
  9672. /**
  9673. * Uses Focal Length (in mm) to estimate and set FOV
  9674. * 35mm (full-frame) camera is used if frame size is not specified;
  9675. * Formula based on http://www.bobatkins.com/photography/technical/field_of_view.html
  9676. */
  9677. THREE.PerspectiveCamera.prototype.setLens = function ( focalLength, frameHeight ) {
  9678. if ( frameHeight === undefined ) frameHeight = 24;
  9679. this.fov = 2 * THREE.Math.radToDeg( Math.atan( frameHeight / ( focalLength * 2 ) ) );
  9680. this.updateProjectionMatrix();
  9681. };
  9682. /**
  9683. * Sets an offset in a larger frustum. This is useful for multi-window or
  9684. * multi-monitor/multi-machine setups.
  9685. *
  9686. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  9687. * the monitors are in grid like this
  9688. *
  9689. * +---+---+---+
  9690. * | A | B | C |
  9691. * +---+---+---+
  9692. * | D | E | F |
  9693. * +---+---+---+
  9694. *
  9695. * then for each monitor you would call it like this
  9696. *
  9697. * var w = 1920;
  9698. * var h = 1080;
  9699. * var fullWidth = w * 3;
  9700. * var fullHeight = h * 2;
  9701. *
  9702. * --A--
  9703. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  9704. * --B--
  9705. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  9706. * --C--
  9707. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  9708. * --D--
  9709. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  9710. * --E--
  9711. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  9712. * --F--
  9713. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  9714. *
  9715. * Note there is no reason monitors have to be the same size or in a grid.
  9716. */
  9717. THREE.PerspectiveCamera.prototype.setViewOffset = function ( fullWidth, fullHeight, x, y, width, height ) {
  9718. this.fullWidth = fullWidth;
  9719. this.fullHeight = fullHeight;
  9720. this.x = x;
  9721. this.y = y;
  9722. this.width = width;
  9723. this.height = height;
  9724. this.updateProjectionMatrix();
  9725. };
  9726. THREE.PerspectiveCamera.prototype.updateProjectionMatrix = function () {
  9727. var fov = THREE.Math.radToDeg( 2 * Math.atan( Math.tan( THREE.Math.degToRad( this.fov ) * 0.5 ) / this.zoom ) );
  9728. if ( this.fullWidth ) {
  9729. var aspect = this.fullWidth / this.fullHeight;
  9730. var top = Math.tan( THREE.Math.degToRad( fov * 0.5 ) ) * this.near;
  9731. var bottom = - top;
  9732. var left = aspect * bottom;
  9733. var right = aspect * top;
  9734. var width = Math.abs( right - left );
  9735. var height = Math.abs( top - bottom );
  9736. this.projectionMatrix.makeFrustum(
  9737. left + this.x * width / this.fullWidth,
  9738. left + ( this.x + this.width ) * width / this.fullWidth,
  9739. top - ( this.y + this.height ) * height / this.fullHeight,
  9740. top - this.y * height / this.fullHeight,
  9741. this.near,
  9742. this.far
  9743. );
  9744. } else {
  9745. this.projectionMatrix.makePerspective( fov, this.aspect, this.near, this.far );
  9746. }
  9747. };
  9748. THREE.PerspectiveCamera.prototype.copy = function ( source ) {
  9749. THREE.Camera.prototype.copy.call( this, source );
  9750. this.fov = source.fov;
  9751. this.aspect = source.aspect;
  9752. this.near = source.near;
  9753. this.far = source.far;
  9754. this.zoom = source.zoom;
  9755. return this;
  9756. };
  9757. THREE.PerspectiveCamera.prototype.toJSON = function ( meta ) {
  9758. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  9759. data.object.zoom = this.zoom;
  9760. data.object.fov = this.fov;
  9761. data.object.aspect = this.aspect;
  9762. data.object.near = this.near;
  9763. data.object.far = this.far;
  9764. return data;
  9765. };
  9766. // File:src/lights/Light.js
  9767. /**
  9768. * @author mrdoob / http://mrdoob.com/
  9769. * @author alteredq / http://alteredqualia.com/
  9770. */
  9771. THREE.Light = function ( color ) {
  9772. THREE.Object3D.call( this );
  9773. this.type = 'Light';
  9774. this.color = new THREE.Color( color );
  9775. this.receiveShadow = undefined;
  9776. };
  9777. THREE.Light.prototype = Object.create( THREE.Object3D.prototype );
  9778. THREE.Light.prototype.constructor = THREE.Light;
  9779. THREE.Light.prototype.copy = function ( source ) {
  9780. THREE.Object3D.prototype.copy.call( this, source );
  9781. this.color.copy( source.color );
  9782. return this;
  9783. };
  9784. THREE.Light.prototype.toJSON = function ( meta ) {
  9785. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  9786. data.object.color = this.color.getHex();
  9787. if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();
  9788. if ( this.intensity !== undefined ) data.object.intensity = this.intensity;
  9789. if ( this.distance !== undefined ) data.object.distance = this.distance;
  9790. if ( this.angle !== undefined ) data.object.angle = this.angle;
  9791. if ( this.decay !== undefined ) data.object.decay = this.decay;
  9792. if ( this.exponent !== undefined ) data.object.exponent = this.exponent;
  9793. return data;
  9794. };
  9795. // File:src/lights/LightShadow.js
  9796. /**
  9797. * @author mrdoob / http://mrdoob.com/
  9798. */
  9799. THREE.LightShadow = function ( camera ) {
  9800. this.camera = camera;
  9801. this.bias = 0;
  9802. this.darkness = 1;
  9803. this.mapSize = new THREE.Vector2( 512, 512 );
  9804. this.map = null;
  9805. this.matrix = null;
  9806. };
  9807. THREE.LightShadow.prototype = {
  9808. constructor: THREE.LightShadow,
  9809. copy: function ( source ) {
  9810. this.camera = source.camera.clone();
  9811. this.bias = source.bias;
  9812. this.darkness = source.darkness;
  9813. this.mapSize.copy( source.mapSize );
  9814. return this;
  9815. },
  9816. clone: function () {
  9817. return new this.constructor().copy( this );
  9818. }
  9819. };
  9820. // File:src/lights/AmbientLight.js
  9821. /**
  9822. * @author mrdoob / http://mrdoob.com/
  9823. */
  9824. THREE.AmbientLight = function ( color ) {
  9825. THREE.Light.call( this, color );
  9826. this.type = 'AmbientLight';
  9827. this.castShadow = undefined;
  9828. };
  9829. THREE.AmbientLight.prototype = Object.create( THREE.Light.prototype );
  9830. THREE.AmbientLight.prototype.constructor = THREE.AmbientLight;
  9831. // File:src/lights/DirectionalLight.js
  9832. /**
  9833. * @author mrdoob / http://mrdoob.com/
  9834. * @author alteredq / http://alteredqualia.com/
  9835. */
  9836. THREE.DirectionalLight = function ( color, intensity ) {
  9837. THREE.Light.call( this, color );
  9838. this.type = 'DirectionalLight';
  9839. this.position.set( 0, 1, 0 );
  9840. this.updateMatrix();
  9841. this.target = new THREE.Object3D();
  9842. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  9843. this.shadow = new THREE.LightShadow( new THREE.OrthographicCamera( - 500, 500, 500, - 500, 50, 5000 ) );
  9844. };
  9845. THREE.DirectionalLight.prototype = Object.create( THREE.Light.prototype );
  9846. THREE.DirectionalLight.prototype.constructor = THREE.DirectionalLight;
  9847. THREE.DirectionalLight.prototype.copy = function ( source ) {
  9848. THREE.Light.prototype.copy.call( this, source );
  9849. this.intensity = source.intensity;
  9850. this.target = source.target.clone();
  9851. this.shadow = source.shadow.clone();
  9852. return this;
  9853. };
  9854. // File:src/lights/HemisphereLight.js
  9855. /**
  9856. * @author alteredq / http://alteredqualia.com/
  9857. */
  9858. THREE.HemisphereLight = function ( skyColor, groundColor, intensity ) {
  9859. THREE.Light.call( this, skyColor );
  9860. this.type = 'HemisphereLight';
  9861. this.castShadow = undefined;
  9862. this.position.set( 0, 1, 0 );
  9863. this.updateMatrix();
  9864. this.groundColor = new THREE.Color( groundColor );
  9865. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  9866. };
  9867. THREE.HemisphereLight.prototype = Object.create( THREE.Light.prototype );
  9868. THREE.HemisphereLight.prototype.constructor = THREE.HemisphereLight;
  9869. THREE.HemisphereLight.prototype.copy = function ( source ) {
  9870. THREE.Light.prototype.copy.call( this, source );
  9871. this.groundColor.copy( source.groundColor );
  9872. this.intensity = source.intensity;
  9873. return this;
  9874. };
  9875. // File:src/lights/PointLight.js
  9876. /**
  9877. * @author mrdoob / http://mrdoob.com/
  9878. */
  9879. THREE.PointLight = function ( color, intensity, distance, decay ) {
  9880. THREE.Light.call( this, color );
  9881. this.type = 'PointLight';
  9882. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  9883. this.distance = ( distance !== undefined ) ? distance : 0;
  9884. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  9885. this.shadow = new THREE.LightShadow( new THREE.PerspectiveCamera( 90, 1, 1, 500 ) );
  9886. };
  9887. THREE.PointLight.prototype = Object.create( THREE.Light.prototype );
  9888. THREE.PointLight.prototype.constructor = THREE.PointLight;
  9889. THREE.PointLight.prototype.copy = function ( source ) {
  9890. THREE.Light.prototype.copy.call( this, source );
  9891. this.intensity = source.intensity;
  9892. this.distance = source.distance;
  9893. this.decay = source.decay;
  9894. this.shadow = source.shadow.clone();
  9895. return this;
  9896. };
  9897. // File:src/lights/SpotLight.js
  9898. /**
  9899. * @author alteredq / http://alteredqualia.com/
  9900. */
  9901. THREE.SpotLight = function ( color, intensity, distance, angle, exponent, decay ) {
  9902. THREE.Light.call( this, color );
  9903. this.type = 'SpotLight';
  9904. this.position.set( 0, 1, 0 );
  9905. this.updateMatrix();
  9906. this.target = new THREE.Object3D();
  9907. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  9908. this.distance = ( distance !== undefined ) ? distance : 0;
  9909. this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
  9910. this.exponent = ( exponent !== undefined ) ? exponent : 10;
  9911. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  9912. this.shadow = new THREE.LightShadow( new THREE.PerspectiveCamera( 50, 1, 50, 5000 ) );
  9913. };
  9914. THREE.SpotLight.prototype = Object.create( THREE.Light.prototype );
  9915. THREE.SpotLight.prototype.constructor = THREE.SpotLight;
  9916. THREE.SpotLight.prototype.copy = function ( source ) {
  9917. THREE.Light.prototype.copy.call( this, source );
  9918. this.intensity = source.intensity;
  9919. this.distance = source.distance;
  9920. this.angle = source.angle;
  9921. this.exponent = source.exponent;
  9922. this.decay = source.decay;
  9923. this.target = source.target.clone();
  9924. this.shadow = source.shadow.clone();
  9925. return this;
  9926. };
  9927. // File:src/loaders/Cache.js
  9928. /**
  9929. * @author mrdoob / http://mrdoob.com/
  9930. */
  9931. THREE.Cache = {
  9932. enabled: false,
  9933. files: {},
  9934. add: function ( key, file ) {
  9935. if ( this.enabled === false ) return;
  9936. // console.log( 'THREE.Cache', 'Adding key:', key );
  9937. this.files[ key ] = file;
  9938. },
  9939. get: function ( key ) {
  9940. if ( this.enabled === false ) return;
  9941. // console.log( 'THREE.Cache', 'Checking key:', key );
  9942. return this.files[ key ];
  9943. },
  9944. remove: function ( key ) {
  9945. delete this.files[ key ];
  9946. },
  9947. clear: function () {
  9948. this.files = {};
  9949. }
  9950. };
  9951. // File:src/loaders/Loader.js
  9952. /**
  9953. * @author alteredq / http://alteredqualia.com/
  9954. */
  9955. THREE.Loader = function () {
  9956. this.onLoadStart = function () {};
  9957. this.onLoadProgress = function () {};
  9958. this.onLoadComplete = function () {};
  9959. };
  9960. THREE.Loader.prototype = {
  9961. constructor: THREE.Loader,
  9962. crossOrigin: undefined,
  9963. extractUrlBase: function ( url ) {
  9964. var parts = url.split( '/' );
  9965. if ( parts.length === 1 ) return './';
  9966. parts.pop();
  9967. return parts.join( '/' ) + '/';
  9968. },
  9969. initMaterials: function ( materials, texturePath, crossOrigin ) {
  9970. var array = [];
  9971. for ( var i = 0; i < materials.length; ++ i ) {
  9972. array[ i ] = this.createMaterial( materials[ i ], texturePath, crossOrigin );
  9973. }
  9974. return array;
  9975. },
  9976. createMaterial: ( function () {
  9977. var color, textureLoader, materialLoader;
  9978. return function ( m, texturePath, crossOrigin ) {
  9979. if ( color === undefined ) color = new THREE.Color();
  9980. if ( textureLoader === undefined ) textureLoader = new THREE.TextureLoader();
  9981. if ( materialLoader === undefined ) materialLoader = new THREE.MaterialLoader();
  9982. // convert from old material format
  9983. var textures = {};
  9984. function loadTexture( path, repeat, offset, wrap, anisotropy ) {
  9985. var fullPath = texturePath + path;
  9986. var loader = THREE.Loader.Handlers.get( fullPath );
  9987. var texture;
  9988. if ( loader !== null ) {
  9989. texture = loader.load( fullPath );
  9990. } else {
  9991. textureLoader.setCrossOrigin( crossOrigin );
  9992. texture = textureLoader.load( fullPath );
  9993. }
  9994. if ( repeat !== undefined ) {
  9995. texture.repeat.fromArray( repeat );
  9996. if ( repeat[ 0 ] !== 1 ) texture.wrapS = THREE.RepeatWrapping;
  9997. if ( repeat[ 1 ] !== 1 ) texture.wrapT = THREE.RepeatWrapping;
  9998. }
  9999. if ( offset !== undefined ) {
  10000. texture.offset.fromArray( offset );
  10001. }
  10002. if ( wrap !== undefined ) {
  10003. if ( wrap[ 0 ] === 'repeat' ) texture.wrapS = THREE.RepeatWrapping;
  10004. if ( wrap[ 0 ] === 'mirror' ) texture.wrapS = THREE.MirroredRepeatWrapping;
  10005. if ( wrap[ 1 ] === 'repeat' ) texture.wrapT = THREE.RepeatWrapping;
  10006. if ( wrap[ 1 ] === 'mirror' ) texture.wrapT = THREE.MirroredRepeatWrapping;
  10007. }
  10008. if ( anisotropy !== undefined ) {
  10009. texture.anisotropy = anisotropy;
  10010. }
  10011. var uuid = THREE.Math.generateUUID();
  10012. textures[ uuid ] = texture;
  10013. return uuid;
  10014. }
  10015. //
  10016. var json = {
  10017. uuid: THREE.Math.generateUUID(),
  10018. type: 'MeshLambertMaterial'
  10019. };
  10020. for ( var name in m ) {
  10021. var value = m[ name ];
  10022. switch ( name ) {
  10023. case 'DbgColor':
  10024. if ( json.color === undefined ) json.color = value;
  10025. break;
  10026. case 'DbgIndex':
  10027. case 'opticalDensity':
  10028. case 'illumination':
  10029. // These were never supported
  10030. break;
  10031. case 'DbgName':
  10032. json.name = value;
  10033. break;
  10034. case 'blending':
  10035. json.blending = THREE[ value ];
  10036. break;
  10037. case 'colorAmbient':
  10038. console.warn( 'THREE.Loader.createMaterial: colorAmbient is no longer supported' );
  10039. break;
  10040. case 'colorDiffuse':
  10041. json.color = color.fromArray( value ).getHex();
  10042. break;
  10043. case 'colorSpecular':
  10044. json.specular = color.fromArray( value ).getHex();
  10045. break;
  10046. case 'colorEmissive':
  10047. json.emissive = color.fromArray( value ).getHex();
  10048. break;
  10049. case 'specularCoef':
  10050. json.shininess = value;
  10051. break;
  10052. case 'shading':
  10053. if ( value.toLowerCase() === 'basic' ) json.type = 'MeshBasicMaterial';
  10054. if ( value.toLowerCase() === 'phong' ) json.type = 'MeshPhongMaterial';
  10055. break;
  10056. case 'mapDiffuse':
  10057. json.map = loadTexture( value, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap, m.mapDiffuseAnisotropy );
  10058. break;
  10059. case 'mapDiffuseRepeat':
  10060. case 'mapDiffuseOffset':
  10061. case 'mapDiffuseWrap':
  10062. case 'mapDiffuseAnisotropy':
  10063. break;
  10064. case 'mapLight':
  10065. json.lightMap = loadTexture( value, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap, m.mapLightAnisotropy );
  10066. break;
  10067. case 'mapLightRepeat':
  10068. case 'mapLightOffset':
  10069. case 'mapLightWrap':
  10070. case 'mapLightAnisotropy':
  10071. break;
  10072. case 'mapAO':
  10073. json.aoMap = loadTexture( value, m.mapAORepeat, m.mapAOOffset, m.mapAOWrap, m.mapAOAnisotropy );
  10074. break;
  10075. case 'mapAORepeat':
  10076. case 'mapAOOffset':
  10077. case 'mapAOWrap':
  10078. case 'mapAOAnisotropy':
  10079. break;
  10080. case 'mapBump':
  10081. json.bumpMap = loadTexture( value, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap, m.mapBumpAnisotropy );
  10082. break;
  10083. case 'mapBumpScale':
  10084. json.bumpScale = value;
  10085. break;
  10086. case 'mapBumpRepeat':
  10087. case 'mapBumpOffset':
  10088. case 'mapBumpWrap':
  10089. case 'mapBumpAnisotropy':
  10090. break;
  10091. case 'mapNormal':
  10092. json.normalMap = loadTexture( value, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap, m.mapNormalAnisotropy );
  10093. break;
  10094. case 'mapNormalFactor':
  10095. json.normalScale = [ value, value ];
  10096. break;
  10097. case 'mapNormalRepeat':
  10098. case 'mapNormalOffset':
  10099. case 'mapNormalWrap':
  10100. case 'mapNormalAnisotropy':
  10101. break;
  10102. case 'mapSpecular':
  10103. json.specularMap = loadTexture( value, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap, m.mapSpecularAnisotropy );
  10104. break;
  10105. case 'mapSpecularRepeat':
  10106. case 'mapSpecularOffset':
  10107. case 'mapSpecularWrap':
  10108. case 'mapSpecularAnisotropy':
  10109. break;
  10110. case 'mapAlpha':
  10111. json.alphaMap = loadTexture( value, m.mapAlphaRepeat, m.mapAlphaOffset, m.mapAlphaWrap, m.mapAlphaAnisotropy );
  10112. break;
  10113. case 'mapAlphaRepeat':
  10114. case 'mapAlphaOffset':
  10115. case 'mapAlphaWrap':
  10116. case 'mapAlphaAnisotropy':
  10117. break;
  10118. case 'flipSided':
  10119. json.side = THREE.BackSide;
  10120. break;
  10121. case 'doubleSided':
  10122. json.side = THREE.DoubleSide;
  10123. break;
  10124. case 'transparency':
  10125. console.warn( 'THREE.Loader.createMaterial: transparency has been renamed to opacity' );
  10126. json.opacity = value;
  10127. break;
  10128. case 'opacity':
  10129. case 'transparent':
  10130. case 'depthTest':
  10131. case 'depthWrite':
  10132. case 'transparent':
  10133. case 'visible':
  10134. case 'wireframe':
  10135. json[ name ] = value;
  10136. break;
  10137. case 'vertexColors':
  10138. if ( value === true ) json.vertexColors = THREE.VertexColors;
  10139. if ( value === 'face' ) json.vertexColors = THREE.FaceColors;
  10140. break;
  10141. default:
  10142. console.error( 'THREE.Loader.createMaterial: Unsupported', name, value );
  10143. break;
  10144. }
  10145. }
  10146. if ( json.type !== 'MeshPhongMaterial' ) delete json.specular;
  10147. if ( json.opacity < 1 ) json.transparent = true;
  10148. materialLoader.setTextures( textures );
  10149. return materialLoader.parse( json );
  10150. };
  10151. } )()
  10152. };
  10153. THREE.Loader.Handlers = {
  10154. handlers: [],
  10155. add: function ( regex, loader ) {
  10156. this.handlers.push( regex, loader );
  10157. },
  10158. get: function ( file ) {
  10159. var handlers = this.handlers;
  10160. for ( var i = 0, l = handlers.length; i < l; i += 2 ) {
  10161. var regex = handlers[ i ];
  10162. var loader = handlers[ i + 1 ];
  10163. if ( regex.test( file ) ) {
  10164. return loader;
  10165. }
  10166. }
  10167. return null;
  10168. }
  10169. };
  10170. // File:src/loaders/XHRLoader.js
  10171. /**
  10172. * @author mrdoob / http://mrdoob.com/
  10173. */
  10174. THREE.XHRLoader = function ( manager ) {
  10175. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10176. };
  10177. THREE.XHRLoader.prototype = {
  10178. constructor: THREE.XHRLoader,
  10179. load: function ( url, onLoad, onProgress, onError ) {
  10180. if ( this.path !== undefined ) url = this.path + url;
  10181. var scope = this;
  10182. var cached = THREE.Cache.get( url );
  10183. if ( cached !== undefined ) {
  10184. if ( onLoad ) {
  10185. setTimeout( function () {
  10186. onLoad( cached );
  10187. }, 0 );
  10188. }
  10189. return cached;
  10190. }
  10191. var request = new XMLHttpRequest();
  10192. request.open( 'GET', url, true );
  10193. request.addEventListener( 'load', function ( event ) {
  10194. var response = event.target.response;
  10195. THREE.Cache.add( url, response );
  10196. if ( onLoad ) onLoad( response );
  10197. scope.manager.itemEnd( url );
  10198. }, false );
  10199. if ( onProgress !== undefined ) {
  10200. request.addEventListener( 'progress', function ( event ) {
  10201. onProgress( event );
  10202. }, false );
  10203. }
  10204. request.addEventListener( 'error', function ( event ) {
  10205. if ( onError ) onError( event );
  10206. scope.manager.itemError( url );
  10207. }, false );
  10208. if ( this.crossOrigin !== undefined ) request.crossOrigin = this.crossOrigin;
  10209. if ( this.responseType !== undefined ) request.responseType = this.responseType;
  10210. if ( this.withCredentials !== undefined ) request.withCredentials = this.withCredentials;
  10211. request.send( null );
  10212. scope.manager.itemStart( url );
  10213. return request;
  10214. },
  10215. setCrossOrigin: function ( value ) {
  10216. this.crossOrigin = value;
  10217. },
  10218. setResponseType: function ( value ) {
  10219. this.responseType = value;
  10220. },
  10221. setPath: function ( value ) {
  10222. this.path = value;
  10223. },
  10224. setWithCredentials: function ( value ) {
  10225. this.withCredentials = value;
  10226. }
  10227. };
  10228. // File:src/loaders/ImageLoader.js
  10229. /**
  10230. * @author mrdoob / http://mrdoob.com/
  10231. */
  10232. THREE.ImageLoader = function ( manager ) {
  10233. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10234. };
  10235. THREE.ImageLoader.prototype = {
  10236. constructor: THREE.ImageLoader,
  10237. load: function ( url, onLoad, onProgress, onError ) {
  10238. if ( this.path !== undefined ) url = this.path + url;
  10239. var scope = this;
  10240. var cached = THREE.Cache.get( url );
  10241. if ( cached !== undefined ) {
  10242. scope.manager.itemStart( url );
  10243. if ( onLoad ) {
  10244. setTimeout( function () {
  10245. onLoad( cached );
  10246. scope.manager.itemEnd( url );
  10247. }, 0 );
  10248. } else {
  10249. scope.manager.itemEnd( url );
  10250. }
  10251. return cached;
  10252. }
  10253. var image = document.createElement( 'img' );
  10254. image.addEventListener( 'load', function ( event ) {
  10255. THREE.Cache.add( url, this );
  10256. if ( onLoad ) onLoad( this );
  10257. scope.manager.itemEnd( url );
  10258. }, false );
  10259. if ( onProgress !== undefined ) {
  10260. image.addEventListener( 'progress', function ( event ) {
  10261. onProgress( event );
  10262. }, false );
  10263. }
  10264. image.addEventListener( 'error', function ( event ) {
  10265. if ( onError ) onError( event );
  10266. scope.manager.itemError( url );
  10267. }, false );
  10268. if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
  10269. scope.manager.itemStart( url );
  10270. image.src = url;
  10271. return image;
  10272. },
  10273. setCrossOrigin: function ( value ) {
  10274. this.crossOrigin = value;
  10275. },
  10276. setPath: function ( value ) {
  10277. this.path = value;
  10278. }
  10279. };
  10280. // File:src/loaders/JSONLoader.js
  10281. /**
  10282. * @author mrdoob / http://mrdoob.com/
  10283. * @author alteredq / http://alteredqualia.com/
  10284. */
  10285. THREE.JSONLoader = function ( manager ) {
  10286. if ( typeof manager === 'boolean' ) {
  10287. console.warn( 'THREE.JSONLoader: showStatus parameter has been removed from constructor.' );
  10288. manager = undefined;
  10289. }
  10290. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10291. this.withCredentials = false;
  10292. };
  10293. THREE.JSONLoader.prototype = {
  10294. constructor: THREE.JSONLoader,
  10295. // Deprecated
  10296. get statusDomElement () {
  10297. if ( this._statusDomElement === undefined ) {
  10298. this._statusDomElement = document.createElement( 'div' );
  10299. }
  10300. console.warn( 'THREE.JSONLoader: .statusDomElement has been removed.' );
  10301. return this._statusDomElement;
  10302. },
  10303. load: function( url, onLoad, onProgress, onError ) {
  10304. var scope = this;
  10305. var texturePath = this.texturePath && ( typeof this.texturePath === "string" ) ? this.texturePath : THREE.Loader.prototype.extractUrlBase( url );
  10306. var loader = new THREE.XHRLoader( this.manager );
  10307. loader.setCrossOrigin( this.crossOrigin );
  10308. loader.setWithCredentials( this.withCredentials );
  10309. loader.load( url, function ( text ) {
  10310. var json = JSON.parse( text );
  10311. var metadata = json.metadata;
  10312. if ( metadata !== undefined ) {
  10313. var type = metadata.type;
  10314. if ( type !== undefined ) {
  10315. if ( type.toLowerCase() === 'object' ) {
  10316. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.ObjectLoader instead.' );
  10317. return;
  10318. }
  10319. if ( type.toLowerCase() === 'scene' ) {
  10320. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.SceneLoader instead.' );
  10321. return;
  10322. }
  10323. }
  10324. }
  10325. var object = scope.parse( json, texturePath );
  10326. onLoad( object.geometry, object.materials );
  10327. } );
  10328. },
  10329. setCrossOrigin: function ( value ) {
  10330. this.crossOrigin = value;
  10331. },
  10332. setTexturePath: function ( value ) {
  10333. this.texturePath = value;
  10334. },
  10335. parse: function ( json, texturePath ) {
  10336. var geometry = new THREE.Geometry(),
  10337. scale = ( json.scale !== undefined ) ? 1.0 / json.scale : 1.0;
  10338. parseModel( scale );
  10339. parseSkin();
  10340. parseMorphing( scale );
  10341. parseAnimations();
  10342. geometry.computeFaceNormals();
  10343. geometry.computeBoundingSphere();
  10344. function parseModel( scale ) {
  10345. function isBitSet( value, position ) {
  10346. return value & ( 1 << position );
  10347. }
  10348. var i, j, fi,
  10349. offset, zLength,
  10350. colorIndex, normalIndex, uvIndex, materialIndex,
  10351. type,
  10352. isQuad,
  10353. hasMaterial,
  10354. hasFaceVertexUv,
  10355. hasFaceNormal, hasFaceVertexNormal,
  10356. hasFaceColor, hasFaceVertexColor,
  10357. vertex, face, faceA, faceB, hex, normal,
  10358. uvLayer, uv, u, v,
  10359. faces = json.faces,
  10360. vertices = json.vertices,
  10361. normals = json.normals,
  10362. colors = json.colors,
  10363. nUvLayers = 0;
  10364. if ( json.uvs !== undefined ) {
  10365. // disregard empty arrays
  10366. for ( i = 0; i < json.uvs.length; i ++ ) {
  10367. if ( json.uvs[ i ].length ) nUvLayers ++;
  10368. }
  10369. for ( i = 0; i < nUvLayers; i ++ ) {
  10370. geometry.faceVertexUvs[ i ] = [];
  10371. }
  10372. }
  10373. offset = 0;
  10374. zLength = vertices.length;
  10375. while ( offset < zLength ) {
  10376. vertex = new THREE.Vector3();
  10377. vertex.x = vertices[ offset ++ ] * scale;
  10378. vertex.y = vertices[ offset ++ ] * scale;
  10379. vertex.z = vertices[ offset ++ ] * scale;
  10380. geometry.vertices.push( vertex );
  10381. }
  10382. offset = 0;
  10383. zLength = faces.length;
  10384. while ( offset < zLength ) {
  10385. type = faces[ offset ++ ];
  10386. isQuad = isBitSet( type, 0 );
  10387. hasMaterial = isBitSet( type, 1 );
  10388. hasFaceVertexUv = isBitSet( type, 3 );
  10389. hasFaceNormal = isBitSet( type, 4 );
  10390. hasFaceVertexNormal = isBitSet( type, 5 );
  10391. hasFaceColor = isBitSet( type, 6 );
  10392. hasFaceVertexColor = isBitSet( type, 7 );
  10393. // console.log("type", type, "bits", isQuad, hasMaterial, hasFaceVertexUv, hasFaceNormal, hasFaceVertexNormal, hasFaceColor, hasFaceVertexColor);
  10394. if ( isQuad ) {
  10395. faceA = new THREE.Face3();
  10396. faceA.a = faces[ offset ];
  10397. faceA.b = faces[ offset + 1 ];
  10398. faceA.c = faces[ offset + 3 ];
  10399. faceB = new THREE.Face3();
  10400. faceB.a = faces[ offset + 1 ];
  10401. faceB.b = faces[ offset + 2 ];
  10402. faceB.c = faces[ offset + 3 ];
  10403. offset += 4;
  10404. if ( hasMaterial ) {
  10405. materialIndex = faces[ offset ++ ];
  10406. faceA.materialIndex = materialIndex;
  10407. faceB.materialIndex = materialIndex;
  10408. }
  10409. // to get face <=> uv index correspondence
  10410. fi = geometry.faces.length;
  10411. if ( hasFaceVertexUv ) {
  10412. for ( i = 0; i < nUvLayers; i ++ ) {
  10413. uvLayer = json.uvs[ i ];
  10414. geometry.faceVertexUvs[ i ][ fi ] = [];
  10415. geometry.faceVertexUvs[ i ][ fi + 1 ] = [];
  10416. for ( j = 0; j < 4; j ++ ) {
  10417. uvIndex = faces[ offset ++ ];
  10418. u = uvLayer[ uvIndex * 2 ];
  10419. v = uvLayer[ uvIndex * 2 + 1 ];
  10420. uv = new THREE.Vector2( u, v );
  10421. if ( j !== 2 ) geometry.faceVertexUvs[ i ][ fi ].push( uv );
  10422. if ( j !== 0 ) geometry.faceVertexUvs[ i ][ fi + 1 ].push( uv );
  10423. }
  10424. }
  10425. }
  10426. if ( hasFaceNormal ) {
  10427. normalIndex = faces[ offset ++ ] * 3;
  10428. faceA.normal.set(
  10429. normals[ normalIndex ++ ],
  10430. normals[ normalIndex ++ ],
  10431. normals[ normalIndex ]
  10432. );
  10433. faceB.normal.copy( faceA.normal );
  10434. }
  10435. if ( hasFaceVertexNormal ) {
  10436. for ( i = 0; i < 4; i ++ ) {
  10437. normalIndex = faces[ offset ++ ] * 3;
  10438. normal = new THREE.Vector3(
  10439. normals[ normalIndex ++ ],
  10440. normals[ normalIndex ++ ],
  10441. normals[ normalIndex ]
  10442. );
  10443. if ( i !== 2 ) faceA.vertexNormals.push( normal );
  10444. if ( i !== 0 ) faceB.vertexNormals.push( normal );
  10445. }
  10446. }
  10447. if ( hasFaceColor ) {
  10448. colorIndex = faces[ offset ++ ];
  10449. hex = colors[ colorIndex ];
  10450. faceA.color.setHex( hex );
  10451. faceB.color.setHex( hex );
  10452. }
  10453. if ( hasFaceVertexColor ) {
  10454. for ( i = 0; i < 4; i ++ ) {
  10455. colorIndex = faces[ offset ++ ];
  10456. hex = colors[ colorIndex ];
  10457. if ( i !== 2 ) faceA.vertexColors.push( new THREE.Color( hex ) );
  10458. if ( i !== 0 ) faceB.vertexColors.push( new THREE.Color( hex ) );
  10459. }
  10460. }
  10461. geometry.faces.push( faceA );
  10462. geometry.faces.push( faceB );
  10463. } else {
  10464. face = new THREE.Face3();
  10465. face.a = faces[ offset ++ ];
  10466. face.b = faces[ offset ++ ];
  10467. face.c = faces[ offset ++ ];
  10468. if ( hasMaterial ) {
  10469. materialIndex = faces[ offset ++ ];
  10470. face.materialIndex = materialIndex;
  10471. }
  10472. // to get face <=> uv index correspondence
  10473. fi = geometry.faces.length;
  10474. if ( hasFaceVertexUv ) {
  10475. for ( i = 0; i < nUvLayers; i ++ ) {
  10476. uvLayer = json.uvs[ i ];
  10477. geometry.faceVertexUvs[ i ][ fi ] = [];
  10478. for ( j = 0; j < 3; j ++ ) {
  10479. uvIndex = faces[ offset ++ ];
  10480. u = uvLayer[ uvIndex * 2 ];
  10481. v = uvLayer[ uvIndex * 2 + 1 ];
  10482. uv = new THREE.Vector2( u, v );
  10483. geometry.faceVertexUvs[ i ][ fi ].push( uv );
  10484. }
  10485. }
  10486. }
  10487. if ( hasFaceNormal ) {
  10488. normalIndex = faces[ offset ++ ] * 3;
  10489. face.normal.set(
  10490. normals[ normalIndex ++ ],
  10491. normals[ normalIndex ++ ],
  10492. normals[ normalIndex ]
  10493. );
  10494. }
  10495. if ( hasFaceVertexNormal ) {
  10496. for ( i = 0; i < 3; i ++ ) {
  10497. normalIndex = faces[ offset ++ ] * 3;
  10498. normal = new THREE.Vector3(
  10499. normals[ normalIndex ++ ],
  10500. normals[ normalIndex ++ ],
  10501. normals[ normalIndex ]
  10502. );
  10503. face.vertexNormals.push( normal );
  10504. }
  10505. }
  10506. if ( hasFaceColor ) {
  10507. colorIndex = faces[ offset ++ ];
  10508. face.color.setHex( colors[ colorIndex ] );
  10509. }
  10510. if ( hasFaceVertexColor ) {
  10511. for ( i = 0; i < 3; i ++ ) {
  10512. colorIndex = faces[ offset ++ ];
  10513. face.vertexColors.push( new THREE.Color( colors[ colorIndex ] ) );
  10514. }
  10515. }
  10516. geometry.faces.push( face );
  10517. }
  10518. }
  10519. };
  10520. function parseSkin() {
  10521. var influencesPerVertex = ( json.influencesPerVertex !== undefined ) ? json.influencesPerVertex : 2;
  10522. if ( json.skinWeights ) {
  10523. for ( var i = 0, l = json.skinWeights.length; i < l; i += influencesPerVertex ) {
  10524. var x = json.skinWeights[ i ];
  10525. var y = ( influencesPerVertex > 1 ) ? json.skinWeights[ i + 1 ] : 0;
  10526. var z = ( influencesPerVertex > 2 ) ? json.skinWeights[ i + 2 ] : 0;
  10527. var w = ( influencesPerVertex > 3 ) ? json.skinWeights[ i + 3 ] : 0;
  10528. geometry.skinWeights.push( new THREE.Vector4( x, y, z, w ) );
  10529. }
  10530. }
  10531. if ( json.skinIndices ) {
  10532. for ( var i = 0, l = json.skinIndices.length; i < l; i += influencesPerVertex ) {
  10533. var a = json.skinIndices[ i ];
  10534. var b = ( influencesPerVertex > 1 ) ? json.skinIndices[ i + 1 ] : 0;
  10535. var c = ( influencesPerVertex > 2 ) ? json.skinIndices[ i + 2 ] : 0;
  10536. var d = ( influencesPerVertex > 3 ) ? json.skinIndices[ i + 3 ] : 0;
  10537. geometry.skinIndices.push( new THREE.Vector4( a, b, c, d ) );
  10538. }
  10539. }
  10540. geometry.bones = json.bones;
  10541. if ( geometry.bones && geometry.bones.length > 0 && ( geometry.skinWeights.length !== geometry.skinIndices.length || geometry.skinIndices.length !== geometry.vertices.length ) ) {
  10542. console.warn( 'When skinning, number of vertices (' + geometry.vertices.length + '), skinIndices (' +
  10543. geometry.skinIndices.length + '), and skinWeights (' + geometry.skinWeights.length + ') should match.' );
  10544. }
  10545. };
  10546. function parseMorphing( scale ) {
  10547. if ( json.morphTargets !== undefined ) {
  10548. for ( var i = 0, l = json.morphTargets.length; i < l; i ++ ) {
  10549. geometry.morphTargets[ i ] = {};
  10550. geometry.morphTargets[ i ].name = json.morphTargets[ i ].name;
  10551. geometry.morphTargets[ i ].vertices = [];
  10552. var dstVertices = geometry.morphTargets[ i ].vertices;
  10553. var srcVertices = json.morphTargets[ i ].vertices;
  10554. for ( var v = 0, vl = srcVertices.length; v < vl; v += 3 ) {
  10555. var vertex = new THREE.Vector3();
  10556. vertex.x = srcVertices[ v ] * scale;
  10557. vertex.y = srcVertices[ v + 1 ] * scale;
  10558. vertex.z = srcVertices[ v + 2 ] * scale;
  10559. dstVertices.push( vertex );
  10560. }
  10561. }
  10562. }
  10563. if ( json.morphColors !== undefined && json.morphColors.length > 0 ) {
  10564. console.warn( 'THREE.JSONLoader: "morphColors" no longer supported. Using them as face colors.' );
  10565. var faces = geometry.faces;
  10566. var morphColors = json.morphColors[ 0 ].colors;
  10567. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  10568. faces[ i ].color.fromArray( morphColors, i * 3 );
  10569. }
  10570. }
  10571. }
  10572. function parseAnimations() {
  10573. var outputAnimations = [];
  10574. // parse old style Bone/Hierarchy animations
  10575. var animations = [];
  10576. if ( json.animation !== undefined ) {
  10577. animations.push( json.animation );
  10578. }
  10579. if ( json.animations !== undefined ) {
  10580. if ( json.animations.length ) {
  10581. animations = animations.concat( json.animations );
  10582. } else {
  10583. animations.push( json.animations );
  10584. }
  10585. }
  10586. for ( var i = 0; i < animations.length; i ++ ) {
  10587. var clip = THREE.AnimationClip.parseAnimation( animations[i], geometry.bones );
  10588. if ( clip ) outputAnimations.push( clip );
  10589. }
  10590. // parse implicit morph animations
  10591. if ( geometry.morphTargets ) {
  10592. // TODO: Figure out what an appropraite FPS is for morph target animations -- defaulting to 10, but really it is completely arbitrary.
  10593. var morphAnimationClips = THREE.AnimationClip.CreateClipsFromMorphTargetSequences( geometry.morphTargets, 10 );
  10594. outputAnimations = outputAnimations.concat( morphAnimationClips );
  10595. }
  10596. if ( outputAnimations.length > 0 ) geometry.animations = outputAnimations;
  10597. };
  10598. if ( json.materials === undefined || json.materials.length === 0 ) {
  10599. return { geometry: geometry };
  10600. } else {
  10601. var materials = THREE.Loader.prototype.initMaterials( json.materials, texturePath, this.crossOrigin );
  10602. return { geometry: geometry, materials: materials };
  10603. }
  10604. }
  10605. };
  10606. // File:src/loaders/LoadingManager.js
  10607. /**
  10608. * @author mrdoob / http://mrdoob.com/
  10609. */
  10610. THREE.LoadingManager = function ( onLoad, onProgress, onError ) {
  10611. var scope = this;
  10612. var isLoading = false, itemsLoaded = 0, itemsTotal = 0;
  10613. this.onStart = undefined;
  10614. this.onLoad = onLoad;
  10615. this.onProgress = onProgress;
  10616. this.onError = onError;
  10617. this.itemStart = function ( url ) {
  10618. itemsTotal ++;
  10619. if ( isLoading === false ) {
  10620. if ( scope.onStart !== undefined ) {
  10621. scope.onStart( url, itemsLoaded, itemsTotal );
  10622. }
  10623. }
  10624. isLoading = true;
  10625. };
  10626. this.itemEnd = function ( url ) {
  10627. itemsLoaded ++;
  10628. if ( scope.onProgress !== undefined ) {
  10629. scope.onProgress( url, itemsLoaded, itemsTotal );
  10630. }
  10631. if ( itemsLoaded === itemsTotal ) {
  10632. isLoading = false;
  10633. if ( scope.onLoad !== undefined ) {
  10634. scope.onLoad();
  10635. }
  10636. }
  10637. };
  10638. this.itemError = function ( url ) {
  10639. if ( scope.onError !== undefined ) {
  10640. scope.onError( url );
  10641. }
  10642. };
  10643. };
  10644. THREE.DefaultLoadingManager = new THREE.LoadingManager();
  10645. // File:src/loaders/BufferGeometryLoader.js
  10646. /**
  10647. * @author mrdoob / http://mrdoob.com/
  10648. */
  10649. THREE.BufferGeometryLoader = function ( manager ) {
  10650. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10651. };
  10652. THREE.BufferGeometryLoader.prototype = {
  10653. constructor: THREE.BufferGeometryLoader,
  10654. load: function ( url, onLoad, onProgress, onError ) {
  10655. var scope = this;
  10656. var loader = new THREE.XHRLoader( scope.manager );
  10657. loader.setCrossOrigin( this.crossOrigin );
  10658. loader.load( url, function ( text ) {
  10659. onLoad( scope.parse( JSON.parse( text ) ) );
  10660. }, onProgress, onError );
  10661. },
  10662. setCrossOrigin: function ( value ) {
  10663. this.crossOrigin = value;
  10664. },
  10665. parse: function ( json ) {
  10666. var geometry = new THREE.BufferGeometry();
  10667. var index = json.data.index;
  10668. if ( index !== undefined ) {
  10669. var typedArray = new self[ index.type ]( index.array );
  10670. geometry.setIndex( new THREE.BufferAttribute( typedArray, 1 ) );
  10671. }
  10672. var attributes = json.data.attributes;
  10673. for ( var key in attributes ) {
  10674. var attribute = attributes[ key ];
  10675. var typedArray = new self[ attribute.type ]( attribute.array );
  10676. geometry.addAttribute( key, new THREE.BufferAttribute( typedArray, attribute.itemSize ) );
  10677. }
  10678. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  10679. if ( groups !== undefined ) {
  10680. for ( var i = 0, n = groups.length; i !== n; ++ i ) {
  10681. var group = groups[ i ];
  10682. geometry.addGroup( group.start, group.count );
  10683. }
  10684. }
  10685. var boundingSphere = json.data.boundingSphere;
  10686. if ( boundingSphere !== undefined ) {
  10687. var center = new THREE.Vector3();
  10688. if ( boundingSphere.center !== undefined ) {
  10689. center.fromArray( boundingSphere.center );
  10690. }
  10691. geometry.boundingSphere = new THREE.Sphere( center, boundingSphere.radius );
  10692. }
  10693. return geometry;
  10694. }
  10695. };
  10696. // File:src/loaders/MaterialLoader.js
  10697. /**
  10698. * @author mrdoob / http://mrdoob.com/
  10699. */
  10700. THREE.MaterialLoader = function ( manager ) {
  10701. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10702. this.textures = {};
  10703. };
  10704. THREE.MaterialLoader.prototype = {
  10705. constructor: THREE.MaterialLoader,
  10706. load: function ( url, onLoad, onProgress, onError ) {
  10707. var scope = this;
  10708. var loader = new THREE.XHRLoader( scope.manager );
  10709. loader.setCrossOrigin( this.crossOrigin );
  10710. loader.load( url, function ( text ) {
  10711. onLoad( scope.parse( JSON.parse( text ) ) );
  10712. }, onProgress, onError );
  10713. },
  10714. setCrossOrigin: function ( value ) {
  10715. this.crossOrigin = value;
  10716. },
  10717. setTextures: function ( value ) {
  10718. this.textures = value;
  10719. },
  10720. getTexture: function ( name ) {
  10721. var textures = this.textures;
  10722. if ( textures[ name ] === undefined ) {
  10723. console.warn( 'THREE.MaterialLoader: Undefined texture', name );
  10724. }
  10725. return textures[ name ];
  10726. },
  10727. parse: function ( json ) {
  10728. var material = new THREE[ json.type ];
  10729. material.uuid = json.uuid;
  10730. if ( json.name !== undefined ) material.name = json.name;
  10731. if ( json.color !== undefined ) material.color.setHex( json.color );
  10732. if ( json.emissive !== undefined ) material.emissive.setHex( json.emissive );
  10733. if ( json.specular !== undefined ) material.specular.setHex( json.specular );
  10734. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  10735. if ( json.uniforms !== undefined ) material.uniforms = json.uniforms;
  10736. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  10737. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  10738. if ( json.vertexColors !== undefined ) material.vertexColors = json.vertexColors;
  10739. if ( json.shading !== undefined ) material.shading = json.shading;
  10740. if ( json.blending !== undefined ) material.blending = json.blending;
  10741. if ( json.side !== undefined ) material.side = json.side;
  10742. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  10743. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  10744. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  10745. if ( json.depthTest !== undefined ) material.depthTest = json.depthTest;
  10746. if ( json.depthWrite !== undefined ) material.depthWrite = json.depthWrite;
  10747. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  10748. if ( json.wireframeLinewidth !== undefined ) material.wireframeLinewidth = json.wireframeLinewidth;
  10749. // for PointsMaterial
  10750. if ( json.size !== undefined ) material.size = json.size;
  10751. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  10752. // maps
  10753. if ( json.map !== undefined ) material.map = this.getTexture( json.map );
  10754. if ( json.alphaMap !== undefined ) {
  10755. material.alphaMap = this.getTexture( json.alphaMap );
  10756. material.transparent = true;
  10757. }
  10758. if ( json.bumpMap !== undefined ) material.bumpMap = this.getTexture( json.bumpMap );
  10759. if ( json.bumpScale !== undefined ) material.bumpScale = json.bumpScale;
  10760. if ( json.normalMap !== undefined ) material.normalMap = this.getTexture( json.normalMap );
  10761. if ( json.normalScale ) {
  10762. var normalScale = json.normalScale;
  10763. if ( Array.isArray( normalScale ) === false ) {
  10764. // Blender exporter used to export a scalar. See #7459
  10765. normalScale = [ normalScale, normalScale ];
  10766. }
  10767. material.normalScale.fromArray( normalScale );
  10768. }
  10769. if ( json.displacementMap !== undefined ) material.displacementMap = this.getTexture( json.displacementMap );
  10770. if ( json.displacementScale !== undefined ) material.displacementScale = json.displacementScale;
  10771. if ( json.displacementBias !== undefined ) material.displacementBias = json.displacementBias;
  10772. if ( json.specularMap !== undefined ) material.specularMap = this.getTexture( json.specularMap );
  10773. if ( json.envMap !== undefined ) {
  10774. material.envMap = this.getTexture( json.envMap );
  10775. material.combine = THREE.MultiplyOperation;
  10776. }
  10777. if ( json.reflectivity ) material.reflectivity = json.reflectivity;
  10778. if ( json.lightMap !== undefined ) material.lightMap = this.getTexture( json.lightMap );
  10779. if ( json.lightMapIntensity !== undefined ) material.lightMapIntensity = json.lightMapIntensity;
  10780. if ( json.aoMap !== undefined ) material.aoMap = this.getTexture( json.aoMap );
  10781. if ( json.aoMapIntensity !== undefined ) material.aoMapIntensity = json.aoMapIntensity;
  10782. // MeshFaceMaterial
  10783. if ( json.materials !== undefined ) {
  10784. for ( var i = 0, l = json.materials.length; i < l; i ++ ) {
  10785. material.materials.push( this.parse( json.materials[ i ] ) );
  10786. }
  10787. }
  10788. return material;
  10789. }
  10790. };
  10791. // File:src/loaders/ObjectLoader.js
  10792. /**
  10793. * @author mrdoob / http://mrdoob.com/
  10794. */
  10795. THREE.ObjectLoader = function ( manager ) {
  10796. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10797. this.texturePath = '';
  10798. };
  10799. THREE.ObjectLoader.prototype = {
  10800. constructor: THREE.ObjectLoader,
  10801. load: function ( url, onLoad, onProgress, onError ) {
  10802. if ( this.texturePath === '' ) {
  10803. this.texturePath = url.substring( 0, url.lastIndexOf( '/' ) + 1 );
  10804. }
  10805. var scope = this;
  10806. var loader = new THREE.XHRLoader( scope.manager );
  10807. loader.setCrossOrigin( this.crossOrigin );
  10808. loader.load( url, function ( text ) {
  10809. scope.parse( JSON.parse( text ), onLoad );
  10810. }, onProgress, onError );
  10811. },
  10812. setTexturePath: function ( value ) {
  10813. this.texturePath = value;
  10814. },
  10815. setCrossOrigin: function ( value ) {
  10816. this.crossOrigin = value;
  10817. },
  10818. parse: function ( json, onLoad ) {
  10819. var geometries = this.parseGeometries( json.geometries );
  10820. var images = this.parseImages( json.images, function () {
  10821. if ( onLoad !== undefined ) onLoad( object );
  10822. } );
  10823. var textures = this.parseTextures( json.textures, images );
  10824. var materials = this.parseMaterials( json.materials, textures );
  10825. var object = this.parseObject( json.object, geometries, materials );
  10826. if ( json.animations ) {
  10827. object.animations = this.parseAnimations( json.animations );
  10828. }
  10829. if ( json.images === undefined || json.images.length === 0 ) {
  10830. if ( onLoad !== undefined ) onLoad( object );
  10831. }
  10832. return object;
  10833. },
  10834. parseGeometries: function ( json ) {
  10835. var geometries = {};
  10836. if ( json !== undefined ) {
  10837. var geometryLoader = new THREE.JSONLoader();
  10838. var bufferGeometryLoader = new THREE.BufferGeometryLoader();
  10839. for ( var i = 0, l = json.length; i < l; i ++ ) {
  10840. var geometry;
  10841. var data = json[ i ];
  10842. switch ( data.type ) {
  10843. case 'PlaneGeometry':
  10844. case 'PlaneBufferGeometry':
  10845. geometry = new THREE[ data.type ](
  10846. data.width,
  10847. data.height,
  10848. data.widthSegments,
  10849. data.heightSegments
  10850. );
  10851. break;
  10852. case 'BoxGeometry':
  10853. case 'CubeGeometry': // backwards compatible
  10854. geometry = new THREE.BoxGeometry(
  10855. data.width,
  10856. data.height,
  10857. data.depth,
  10858. data.widthSegments,
  10859. data.heightSegments,
  10860. data.depthSegments
  10861. );
  10862. break;
  10863. case 'CircleBufferGeometry':
  10864. geometry = new THREE.CircleBufferGeometry(
  10865. data.radius,
  10866. data.segments,
  10867. data.thetaStart,
  10868. data.thetaLength
  10869. );
  10870. break;
  10871. case 'CircleGeometry':
  10872. geometry = new THREE.CircleGeometry(
  10873. data.radius,
  10874. data.segments,
  10875. data.thetaStart,
  10876. data.thetaLength
  10877. );
  10878. break;
  10879. case 'CylinderGeometry':
  10880. geometry = new THREE.CylinderGeometry(
  10881. data.radiusTop,
  10882. data.radiusBottom,
  10883. data.height,
  10884. data.radialSegments,
  10885. data.heightSegments,
  10886. data.openEnded,
  10887. data.thetaStart,
  10888. data.thetaLength
  10889. );
  10890. break;
  10891. case 'SphereGeometry':
  10892. geometry = new THREE.SphereGeometry(
  10893. data.radius,
  10894. data.widthSegments,
  10895. data.heightSegments,
  10896. data.phiStart,
  10897. data.phiLength,
  10898. data.thetaStart,
  10899. data.thetaLength
  10900. );
  10901. break;
  10902. case 'SphereBufferGeometry':
  10903. geometry = new THREE.SphereBufferGeometry(
  10904. data.radius,
  10905. data.widthSegments,
  10906. data.heightSegments,
  10907. data.phiStart,
  10908. data.phiLength,
  10909. data.thetaStart,
  10910. data.thetaLength
  10911. );
  10912. break;
  10913. case 'DodecahedronGeometry':
  10914. geometry = new THREE.DodecahedronGeometry(
  10915. data.radius,
  10916. data.detail
  10917. );
  10918. break;
  10919. case 'IcosahedronGeometry':
  10920. geometry = new THREE.IcosahedronGeometry(
  10921. data.radius,
  10922. data.detail
  10923. );
  10924. break;
  10925. case 'OctahedronGeometry':
  10926. geometry = new THREE.OctahedronGeometry(
  10927. data.radius,
  10928. data.detail
  10929. );
  10930. break;
  10931. case 'TetrahedronGeometry':
  10932. geometry = new THREE.TetrahedronGeometry(
  10933. data.radius,
  10934. data.detail
  10935. );
  10936. break;
  10937. case 'RingGeometry':
  10938. geometry = new THREE.RingGeometry(
  10939. data.innerRadius,
  10940. data.outerRadius,
  10941. data.thetaSegments,
  10942. data.phiSegments,
  10943. data.thetaStart,
  10944. data.thetaLength
  10945. );
  10946. break;
  10947. case 'TorusGeometry':
  10948. geometry = new THREE.TorusGeometry(
  10949. data.radius,
  10950. data.tube,
  10951. data.radialSegments,
  10952. data.tubularSegments,
  10953. data.arc
  10954. );
  10955. break;
  10956. case 'TorusKnotGeometry':
  10957. geometry = new THREE.TorusKnotGeometry(
  10958. data.radius,
  10959. data.tube,
  10960. data.radialSegments,
  10961. data.tubularSegments,
  10962. data.p,
  10963. data.q,
  10964. data.heightScale
  10965. );
  10966. break;
  10967. case 'BufferGeometry':
  10968. geometry = bufferGeometryLoader.parse( data );
  10969. break;
  10970. case 'Geometry':
  10971. geometry = geometryLoader.parse( data.data, this.texturePath ).geometry;
  10972. break;
  10973. default:
  10974. console.warn( 'THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"' );
  10975. continue;
  10976. }
  10977. geometry.uuid = data.uuid;
  10978. if ( data.name !== undefined ) geometry.name = data.name;
  10979. geometries[ data.uuid ] = geometry;
  10980. }
  10981. }
  10982. return geometries;
  10983. },
  10984. parseMaterials: function ( json, textures ) {
  10985. var materials = {};
  10986. if ( json !== undefined ) {
  10987. var loader = new THREE.MaterialLoader();
  10988. loader.setTextures( textures );
  10989. for ( var i = 0, l = json.length; i < l; i ++ ) {
  10990. var material = loader.parse( json[ i ] );
  10991. materials[ material.uuid ] = material;
  10992. }
  10993. }
  10994. return materials;
  10995. },
  10996. parseAnimations: function ( json ) {
  10997. var animations = [];
  10998. for ( var i = 0; i < json.length; i ++ ) {
  10999. var clip = THREE.AnimationClip.parse( json[i] );
  11000. animations.push( clip );
  11001. }
  11002. return animations;
  11003. },
  11004. parseImages: function ( json, onLoad ) {
  11005. var scope = this;
  11006. var images = {};
  11007. function loadImage( url ) {
  11008. scope.manager.itemStart( url );
  11009. return loader.load( url, function () {
  11010. scope.manager.itemEnd( url );
  11011. } );
  11012. }
  11013. if ( json !== undefined && json.length > 0 ) {
  11014. var manager = new THREE.LoadingManager( onLoad );
  11015. var loader = new THREE.ImageLoader( manager );
  11016. loader.setCrossOrigin( this.crossOrigin );
  11017. for ( var i = 0, l = json.length; i < l; i ++ ) {
  11018. var image = json[ i ];
  11019. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( image.url ) ? image.url : scope.texturePath + image.url;
  11020. images[ image.uuid ] = loadImage( path );
  11021. }
  11022. }
  11023. return images;
  11024. },
  11025. parseTextures: function ( json, images ) {
  11026. function parseConstant( value ) {
  11027. if ( typeof( value ) === 'number' ) return value;
  11028. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  11029. return THREE[ value ];
  11030. }
  11031. var textures = {};
  11032. if ( json !== undefined ) {
  11033. for ( var i = 0, l = json.length; i < l; i ++ ) {
  11034. var data = json[ i ];
  11035. if ( data.image === undefined ) {
  11036. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  11037. }
  11038. if ( images[ data.image ] === undefined ) {
  11039. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  11040. }
  11041. var texture = new THREE.Texture( images[ data.image ] );
  11042. texture.needsUpdate = true;
  11043. texture.uuid = data.uuid;
  11044. if ( data.name !== undefined ) texture.name = data.name;
  11045. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping );
  11046. if ( data.offset !== undefined ) texture.offset = new THREE.Vector2( data.offset[ 0 ], data.offset[ 1 ] );
  11047. if ( data.repeat !== undefined ) texture.repeat = new THREE.Vector2( data.repeat[ 0 ], data.repeat[ 1 ] );
  11048. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter );
  11049. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter );
  11050. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  11051. if ( Array.isArray( data.wrap ) ) {
  11052. texture.wrapS = parseConstant( data.wrap[ 0 ] );
  11053. texture.wrapT = parseConstant( data.wrap[ 1 ] );
  11054. }
  11055. textures[ data.uuid ] = texture;
  11056. }
  11057. }
  11058. return textures;
  11059. },
  11060. parseObject: function () {
  11061. var matrix = new THREE.Matrix4();
  11062. return function ( data, geometries, materials ) {
  11063. var object;
  11064. function getGeometry( name ) {
  11065. if ( geometries[ name ] === undefined ) {
  11066. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  11067. }
  11068. return geometries[ name ];
  11069. }
  11070. function getMaterial( name ) {
  11071. if ( name === undefined ) return undefined;
  11072. if ( materials[ name ] === undefined ) {
  11073. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  11074. }
  11075. return materials[ name ];
  11076. }
  11077. switch ( data.type ) {
  11078. case 'Scene':
  11079. object = new THREE.Scene();
  11080. break;
  11081. case 'PerspectiveCamera':
  11082. object = new THREE.PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  11083. break;
  11084. case 'OrthographicCamera':
  11085. object = new THREE.OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  11086. break;
  11087. case 'AmbientLight':
  11088. object = new THREE.AmbientLight( data.color );
  11089. break;
  11090. case 'DirectionalLight':
  11091. object = new THREE.DirectionalLight( data.color, data.intensity );
  11092. break;
  11093. case 'PointLight':
  11094. object = new THREE.PointLight( data.color, data.intensity, data.distance, data.decay );
  11095. break;
  11096. case 'SpotLight':
  11097. object = new THREE.SpotLight( data.color, data.intensity, data.distance, data.angle, data.exponent, data.decay );
  11098. break;
  11099. case 'HemisphereLight':
  11100. object = new THREE.HemisphereLight( data.color, data.groundColor, data.intensity );
  11101. break;
  11102. case 'Mesh':
  11103. var geometry = getGeometry( data.geometry );
  11104. var material = getMaterial( data.material );
  11105. if ( geometry.bones && geometry.bones.length > 0 ) {
  11106. object = new THREE.SkinnedMesh( geometry, material );
  11107. } else {
  11108. object = new THREE.Mesh( geometry, material );
  11109. }
  11110. break;
  11111. case 'LOD':
  11112. object = new THREE.LOD();
  11113. break;
  11114. case 'Line':
  11115. object = new THREE.Line( getGeometry( data.geometry ), getMaterial( data.material ), data.mode );
  11116. break;
  11117. case 'PointCloud':
  11118. case 'Points':
  11119. object = new THREE.Points( getGeometry( data.geometry ), getMaterial( data.material ) );
  11120. break;
  11121. case 'Sprite':
  11122. object = new THREE.Sprite( getMaterial( data.material ) );
  11123. break;
  11124. case 'Group':
  11125. object = new THREE.Group();
  11126. break;
  11127. default:
  11128. object = new THREE.Object3D();
  11129. }
  11130. object.uuid = data.uuid;
  11131. if ( data.name !== undefined ) object.name = data.name;
  11132. if ( data.matrix !== undefined ) {
  11133. matrix.fromArray( data.matrix );
  11134. matrix.decompose( object.position, object.quaternion, object.scale );
  11135. } else {
  11136. if ( data.position !== undefined ) object.position.fromArray( data.position );
  11137. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  11138. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  11139. }
  11140. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  11141. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  11142. if ( data.visible !== undefined ) object.visible = data.visible;
  11143. if ( data.userData !== undefined ) object.userData = data.userData;
  11144. if ( data.children !== undefined ) {
  11145. for ( var child in data.children ) {
  11146. object.add( this.parseObject( data.children[ child ], geometries, materials ) );
  11147. }
  11148. }
  11149. if ( data.type === 'LOD' ) {
  11150. var levels = data.levels;
  11151. for ( var l = 0; l < levels.length; l ++ ) {
  11152. var level = levels[ l ];
  11153. var child = object.getObjectByProperty( 'uuid', level.object );
  11154. if ( child !== undefined ) {
  11155. object.addLevel( child, level.distance );
  11156. }
  11157. }
  11158. }
  11159. return object;
  11160. }
  11161. }()
  11162. };
  11163. // File:src/loaders/TextureLoader.js
  11164. /**
  11165. * @author mrdoob / http://mrdoob.com/
  11166. */
  11167. THREE.TextureLoader = function ( manager ) {
  11168. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11169. };
  11170. THREE.TextureLoader.prototype = {
  11171. constructor: THREE.TextureLoader,
  11172. load: function ( url, onLoad, onProgress, onError ) {
  11173. var texture = new THREE.Texture();
  11174. var loader = new THREE.ImageLoader( this.manager );
  11175. loader.setCrossOrigin( this.crossOrigin );
  11176. loader.setPath( this.path );
  11177. loader.load( url, function ( image ) {
  11178. texture.image = image;
  11179. texture.needsUpdate = true;
  11180. if ( onLoad !== undefined ) {
  11181. onLoad( texture );
  11182. }
  11183. }, onProgress, onError );
  11184. return texture;
  11185. },
  11186. setCrossOrigin: function ( value ) {
  11187. this.crossOrigin = value;
  11188. },
  11189. setPath: function ( value ) {
  11190. this.path = value;
  11191. }
  11192. };
  11193. // File:src/loaders/CubeTextureLoader.js
  11194. /**
  11195. * @author mrdoob / http://mrdoob.com/
  11196. */
  11197. THREE.CubeTextureLoader = function ( manager ) {
  11198. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11199. };
  11200. THREE.CubeTextureLoader.prototype = {
  11201. constructor: THREE.CubeTextureLoader,
  11202. load: function ( urls, onLoad, onProgress, onError ) {
  11203. var texture = new THREE.CubeTexture( [] );
  11204. var loader = new THREE.ImageLoader();
  11205. loader.setCrossOrigin( this.crossOrigin );
  11206. loader.setPath( this.path );
  11207. var loaded = 0;
  11208. function loadTexture( i ) {
  11209. loader.load( urls[ i ], function ( image ) {
  11210. texture.images[ i ] = image;
  11211. loaded ++;
  11212. if ( loaded === 6 ) {
  11213. texture.needsUpdate = true;
  11214. if ( onLoad ) onLoad( texture );
  11215. }
  11216. }, undefined, onError );
  11217. }
  11218. for ( var i = 0; i < urls.length; ++ i ) {
  11219. loadTexture( i );
  11220. }
  11221. return texture;
  11222. },
  11223. setCrossOrigin: function ( value ) {
  11224. this.crossOrigin = value;
  11225. },
  11226. setPath: function ( value ) {
  11227. this.path = value;
  11228. }
  11229. };
  11230. // File:src/loaders/BinaryTextureLoader.js
  11231. /**
  11232. * @author Nikos M. / https://github.com/foo123/
  11233. *
  11234. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  11235. */
  11236. THREE.DataTextureLoader = THREE.BinaryTextureLoader = function ( manager ) {
  11237. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11238. // override in sub classes
  11239. this._parser = null;
  11240. };
  11241. THREE.BinaryTextureLoader.prototype = {
  11242. constructor: THREE.BinaryTextureLoader,
  11243. load: function ( url, onLoad, onProgress, onError ) {
  11244. var scope = this;
  11245. var texture = new THREE.DataTexture();
  11246. var loader = new THREE.XHRLoader( this.manager );
  11247. loader.setCrossOrigin( this.crossOrigin );
  11248. loader.setResponseType( 'arraybuffer' );
  11249. loader.load( url, function ( buffer ) {
  11250. var texData = scope._parser( buffer );
  11251. if ( ! texData ) return;
  11252. if ( undefined !== texData.image ) {
  11253. texture.image = texData.image;
  11254. } else if ( undefined !== texData.data ) {
  11255. texture.image.width = texData.width;
  11256. texture.image.height = texData.height;
  11257. texture.image.data = texData.data;
  11258. }
  11259. texture.wrapS = undefined !== texData.wrapS ? texData.wrapS : THREE.ClampToEdgeWrapping;
  11260. texture.wrapT = undefined !== texData.wrapT ? texData.wrapT : THREE.ClampToEdgeWrapping;
  11261. texture.magFilter = undefined !== texData.magFilter ? texData.magFilter : THREE.LinearFilter;
  11262. texture.minFilter = undefined !== texData.minFilter ? texData.minFilter : THREE.LinearMipMapLinearFilter;
  11263. texture.anisotropy = undefined !== texData.anisotropy ? texData.anisotropy : 1;
  11264. if ( undefined !== texData.format ) {
  11265. texture.format = texData.format;
  11266. }
  11267. if ( undefined !== texData.type ) {
  11268. texture.type = texData.type;
  11269. }
  11270. if ( undefined !== texData.mipmaps ) {
  11271. texture.mipmaps = texData.mipmaps;
  11272. }
  11273. if ( 1 === texData.mipmapCount ) {
  11274. texture.minFilter = THREE.LinearFilter;
  11275. }
  11276. texture.needsUpdate = true;
  11277. if ( onLoad ) onLoad( texture, texData );
  11278. }, onProgress, onError );
  11279. return texture;
  11280. },
  11281. setCrossOrigin: function ( value ) {
  11282. this.crossOrigin = value;
  11283. }
  11284. };
  11285. // File:src/loaders/CompressedTextureLoader.js
  11286. /**
  11287. * @author mrdoob / http://mrdoob.com/
  11288. *
  11289. * Abstract Base class to block based textures loader (dds, pvr, ...)
  11290. */
  11291. THREE.CompressedTextureLoader = function ( manager ) {
  11292. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11293. // override in sub classes
  11294. this._parser = null;
  11295. };
  11296. THREE.CompressedTextureLoader.prototype = {
  11297. constructor: THREE.CompressedTextureLoader,
  11298. load: function ( url, onLoad, onProgress, onError ) {
  11299. var scope = this;
  11300. var images = [];
  11301. var texture = new THREE.CompressedTexture();
  11302. texture.image = images;
  11303. var loader = new THREE.XHRLoader( this.manager );
  11304. loader.setCrossOrigin( this.crossOrigin );
  11305. loader.setPath( this.path );
  11306. loader.setResponseType( 'arraybuffer' );
  11307. function loadTexture( i ) {
  11308. loader.load( url[ i ], function ( buffer ) {
  11309. var texDatas = scope._parser( buffer, true );
  11310. images[ i ] = {
  11311. width: texDatas.width,
  11312. height: texDatas.height,
  11313. format: texDatas.format,
  11314. mipmaps: texDatas.mipmaps
  11315. };
  11316. loaded += 1;
  11317. if ( loaded === 6 ) {
  11318. if ( texDatas.mipmapCount === 1 )
  11319. texture.minFilter = THREE.LinearFilter;
  11320. texture.format = texDatas.format;
  11321. texture.needsUpdate = true;
  11322. if ( onLoad ) onLoad( texture );
  11323. }
  11324. }, onProgress, onError );
  11325. }
  11326. if ( Array.isArray( url ) ) {
  11327. var loaded = 0;
  11328. for ( var i = 0, il = url.length; i < il; ++ i ) {
  11329. loadTexture( i );
  11330. }
  11331. } else {
  11332. // compressed cubemap texture stored in a single DDS file
  11333. loader.load( url, function ( buffer ) {
  11334. var texDatas = scope._parser( buffer, true );
  11335. if ( texDatas.isCubemap ) {
  11336. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  11337. for ( var f = 0; f < faces; f ++ ) {
  11338. images[ f ] = { mipmaps : [] };
  11339. for ( var i = 0; i < texDatas.mipmapCount; i ++ ) {
  11340. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  11341. images[ f ].format = texDatas.format;
  11342. images[ f ].width = texDatas.width;
  11343. images[ f ].height = texDatas.height;
  11344. }
  11345. }
  11346. } else {
  11347. texture.image.width = texDatas.width;
  11348. texture.image.height = texDatas.height;
  11349. texture.mipmaps = texDatas.mipmaps;
  11350. }
  11351. if ( texDatas.mipmapCount === 1 ) {
  11352. texture.minFilter = THREE.LinearFilter;
  11353. }
  11354. texture.format = texDatas.format;
  11355. texture.needsUpdate = true;
  11356. if ( onLoad ) onLoad( texture );
  11357. }, onProgress, onError );
  11358. }
  11359. return texture;
  11360. },
  11361. setCrossOrigin: function ( value ) {
  11362. this.crossOrigin = value;
  11363. },
  11364. setPath: function ( value ) {
  11365. this.path = value;
  11366. }
  11367. };
  11368. // File:src/materials/Material.js
  11369. /**
  11370. * @author mrdoob / http://mrdoob.com/
  11371. * @author alteredq / http://alteredqualia.com/
  11372. */
  11373. THREE.Material = function () {
  11374. Object.defineProperty( this, 'id', { value: THREE.MaterialIdCount ++ } );
  11375. this.uuid = THREE.Math.generateUUID();
  11376. this.name = '';
  11377. this.type = 'Material';
  11378. this.side = THREE.FrontSide;
  11379. this.opacity = 1;
  11380. this.transparent = false;
  11381. this.blending = THREE.NormalBlending;
  11382. this.blendSrc = THREE.SrcAlphaFactor;
  11383. this.blendDst = THREE.OneMinusSrcAlphaFactor;
  11384. this.blendEquation = THREE.AddEquation;
  11385. this.blendSrcAlpha = null;
  11386. this.blendDstAlpha = null;
  11387. this.blendEquationAlpha = null;
  11388. this.depthFunc = THREE.LessEqualDepth;
  11389. this.depthTest = true;
  11390. this.depthWrite = true;
  11391. this.colorWrite = true;
  11392. this.precision = null; // override the renderer's default precision for this material
  11393. this.polygonOffset = false;
  11394. this.polygonOffsetFactor = 0;
  11395. this.polygonOffsetUnits = 0;
  11396. this.alphaTest = 0;
  11397. this.overdraw = 0; // Overdrawn pixels (typically between 0 and 1) for fixing antialiasing gaps in CanvasRenderer
  11398. this.visible = true;
  11399. this._needsUpdate = true;
  11400. };
  11401. THREE.Material.prototype = {
  11402. constructor: THREE.Material,
  11403. get needsUpdate () {
  11404. return this._needsUpdate;
  11405. },
  11406. set needsUpdate ( value ) {
  11407. if ( value === true ) this.update();
  11408. this._needsUpdate = value;
  11409. },
  11410. setValues: function ( values ) {
  11411. if ( values === undefined ) return;
  11412. for ( var key in values ) {
  11413. var newValue = values[ key ];
  11414. if ( newValue === undefined ) {
  11415. console.warn( "THREE.Material: '" + key + "' parameter is undefined." );
  11416. continue;
  11417. }
  11418. var currentValue = this[ key ];
  11419. if ( currentValue === undefined ) {
  11420. console.warn( "THREE." + this.type + ": '" + key + "' is not a property of this material." );
  11421. continue;
  11422. }
  11423. if ( currentValue instanceof THREE.Color ) {
  11424. currentValue.set( newValue );
  11425. } else if ( currentValue instanceof THREE.Vector3 && newValue instanceof THREE.Vector3 ) {
  11426. currentValue.copy( newValue );
  11427. } else if ( key === 'overdraw' ) {
  11428. // ensure overdraw is backwards-compatible with legacy boolean type
  11429. this[ key ] = Number( newValue );
  11430. } else {
  11431. this[ key ] = newValue;
  11432. }
  11433. }
  11434. },
  11435. toJSON: function ( meta ) {
  11436. var isRoot = meta === undefined;
  11437. if ( isRoot ) {
  11438. meta = {
  11439. textures: {},
  11440. images: {}
  11441. };
  11442. }
  11443. var data = {
  11444. metadata: {
  11445. version: 4.4,
  11446. type: 'Material',
  11447. generator: 'Material.toJSON'
  11448. }
  11449. };
  11450. // standard Material serialization
  11451. data.uuid = this.uuid;
  11452. data.type = this.type;
  11453. if ( this.name !== '' ) data.name = this.name;
  11454. if ( this.color instanceof THREE.Color ) data.color = this.color.getHex();
  11455. if ( this.emissive instanceof THREE.Color ) data.emissive = this.emissive.getHex();
  11456. if ( this.specular instanceof THREE.Color ) data.specular = this.specular.getHex();
  11457. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  11458. if ( this.map instanceof THREE.Texture ) data.map = this.map.toJSON( meta ).uuid;
  11459. if ( this.alphaMap instanceof THREE.Texture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  11460. if ( this.lightMap instanceof THREE.Texture ) data.lightMap = this.lightMap.toJSON( meta ).uuid;
  11461. if ( this.bumpMap instanceof THREE.Texture ) {
  11462. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  11463. data.bumpScale = this.bumpScale;
  11464. }
  11465. if ( this.normalMap instanceof THREE.Texture ) {
  11466. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  11467. data.normalScale = this.normalScale.toArray();
  11468. }
  11469. if ( this.displacementMap instanceof THREE.Texture ) {
  11470. data.displacementMap = this.displacementMap.toJSON( meta ).uuid;
  11471. data.displacementScale = this.displacementScale;
  11472. data.displacementBias = this.displacementBias;
  11473. }
  11474. if ( this.specularMap instanceof THREE.Texture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  11475. if ( this.envMap instanceof THREE.Texture ) {
  11476. data.envMap = this.envMap.toJSON( meta ).uuid;
  11477. data.reflectivity = this.reflectivity; // Scale behind envMap
  11478. }
  11479. if ( this.size !== undefined ) data.size = this.size;
  11480. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  11481. if ( this.vertexColors !== undefined && this.vertexColors !== THREE.NoColors ) data.vertexColors = this.vertexColors;
  11482. if ( this.shading !== undefined && this.shading !== THREE.SmoothShading ) data.shading = this.shading;
  11483. if ( this.blending !== undefined && this.blending !== THREE.NormalBlending ) data.blending = this.blending;
  11484. if ( this.side !== undefined && this.side !== THREE.FrontSide ) data.side = this.side;
  11485. if ( this.opacity < 1 ) data.opacity = this.opacity;
  11486. if ( this.transparent === true ) data.transparent = this.transparent;
  11487. if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
  11488. if ( this.wireframe === true ) data.wireframe = this.wireframe;
  11489. if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;
  11490. // TODO: Copied from Object3D.toJSON
  11491. function extractFromCache ( cache ) {
  11492. var values = [];
  11493. for ( var key in cache ) {
  11494. var data = cache[ key ];
  11495. delete data.metadata;
  11496. values.push( data );
  11497. }
  11498. return values;
  11499. }
  11500. if ( isRoot ) {
  11501. var textures = extractFromCache( meta.textures );
  11502. var images = extractFromCache( meta.images );
  11503. if ( textures.length > 0 ) data.textures = textures;
  11504. if ( images.length > 0 ) data.images = images;
  11505. }
  11506. return data;
  11507. },
  11508. clone: function () {
  11509. return new this.constructor().copy( this );
  11510. },
  11511. copy: function ( source ) {
  11512. this.name = source.name;
  11513. this.side = source.side;
  11514. this.opacity = source.opacity;
  11515. this.transparent = source.transparent;
  11516. this.blending = source.blending;
  11517. this.blendSrc = source.blendSrc;
  11518. this.blendDst = source.blendDst;
  11519. this.blendEquation = source.blendEquation;
  11520. this.blendSrcAlpha = source.blendSrcAlpha;
  11521. this.blendDstAlpha = source.blendDstAlpha;
  11522. this.blendEquationAlpha = source.blendEquationAlpha;
  11523. this.depthFunc = source.depthFunc;
  11524. this.depthTest = source.depthTest;
  11525. this.depthWrite = source.depthWrite;
  11526. this.precision = source.precision;
  11527. this.polygonOffset = source.polygonOffset;
  11528. this.polygonOffsetFactor = source.polygonOffsetFactor;
  11529. this.polygonOffsetUnits = source.polygonOffsetUnits;
  11530. this.alphaTest = source.alphaTest;
  11531. this.overdraw = source.overdraw;
  11532. this.visible = source.visible;
  11533. return this;
  11534. },
  11535. update: function () {
  11536. this.dispatchEvent( { type: 'update' } );
  11537. },
  11538. dispose: function () {
  11539. this.dispatchEvent( { type: 'dispose' } );
  11540. }
  11541. };
  11542. THREE.EventDispatcher.prototype.apply( THREE.Material.prototype );
  11543. THREE.MaterialIdCount = 0;
  11544. // File:src/materials/LineBasicMaterial.js
  11545. /**
  11546. * @author mrdoob / http://mrdoob.com/
  11547. * @author alteredq / http://alteredqualia.com/
  11548. *
  11549. * parameters = {
  11550. * color: <hex>,
  11551. * opacity: <float>,
  11552. *
  11553. * blending: THREE.NormalBlending,
  11554. * depthTest: <bool>,
  11555. * depthWrite: <bool>,
  11556. *
  11557. * linewidth: <float>,
  11558. * linecap: "round",
  11559. * linejoin: "round",
  11560. *
  11561. * vertexColors: <bool>
  11562. *
  11563. * fog: <bool>
  11564. * }
  11565. */
  11566. THREE.LineBasicMaterial = function ( parameters ) {
  11567. THREE.Material.call( this );
  11568. this.type = 'LineBasicMaterial';
  11569. this.color = new THREE.Color( 0xffffff );
  11570. this.linewidth = 1;
  11571. this.linecap = 'round';
  11572. this.linejoin = 'round';
  11573. this.vertexColors = THREE.NoColors;
  11574. this.fog = true;
  11575. this.setValues( parameters );
  11576. };
  11577. THREE.LineBasicMaterial.prototype = Object.create( THREE.Material.prototype );
  11578. THREE.LineBasicMaterial.prototype.constructor = THREE.LineBasicMaterial;
  11579. THREE.LineBasicMaterial.prototype.copy = function ( source ) {
  11580. THREE.Material.prototype.copy.call( this, source );
  11581. this.color.copy( source.color );
  11582. this.linewidth = source.linewidth;
  11583. this.linecap = source.linecap;
  11584. this.linejoin = source.linejoin;
  11585. this.vertexColors = source.vertexColors;
  11586. this.fog = source.fog;
  11587. return this;
  11588. };
  11589. // File:src/materials/LineDashedMaterial.js
  11590. /**
  11591. * @author alteredq / http://alteredqualia.com/
  11592. *
  11593. * parameters = {
  11594. * color: <hex>,
  11595. * opacity: <float>,
  11596. *
  11597. * blending: THREE.NormalBlending,
  11598. * depthTest: <bool>,
  11599. * depthWrite: <bool>,
  11600. *
  11601. * linewidth: <float>,
  11602. *
  11603. * scale: <float>,
  11604. * dashSize: <float>,
  11605. * gapSize: <float>,
  11606. *
  11607. * vertexColors: THREE.NoColors / THREE.FaceColors / THREE.VertexColors
  11608. *
  11609. * fog: <bool>
  11610. * }
  11611. */
  11612. THREE.LineDashedMaterial = function ( parameters ) {
  11613. THREE.Material.call( this );
  11614. this.type = 'LineDashedMaterial';
  11615. this.color = new THREE.Color( 0xffffff );
  11616. this.linewidth = 1;
  11617. this.scale = 1;
  11618. this.dashSize = 3;
  11619. this.gapSize = 1;
  11620. this.vertexColors = THREE.NoColors;
  11621. this.fog = true;
  11622. this.setValues( parameters );
  11623. };
  11624. THREE.LineDashedMaterial.prototype = Object.create( THREE.Material.prototype );
  11625. THREE.LineDashedMaterial.prototype.constructor = THREE.LineDashedMaterial;
  11626. THREE.LineDashedMaterial.prototype.copy = function ( source ) {
  11627. THREE.Material.prototype.copy.call( this, source );
  11628. this.color.copy( source.color );
  11629. this.linewidth = source.linewidth;
  11630. this.scale = source.scale;
  11631. this.dashSize = source.dashSize;
  11632. this.gapSize = source.gapSize;
  11633. this.vertexColors = source.vertexColors;
  11634. this.fog = source.fog;
  11635. return this;
  11636. };
  11637. // File:src/materials/MeshBasicMaterial.js
  11638. /**
  11639. * @author mrdoob / http://mrdoob.com/
  11640. * @author alteredq / http://alteredqualia.com/
  11641. *
  11642. * parameters = {
  11643. * color: <hex>,
  11644. * opacity: <float>,
  11645. * map: new THREE.Texture( <Image> ),
  11646. *
  11647. * aoMap: new THREE.Texture( <Image> ),
  11648. * aoMapIntensity: <float>
  11649. *
  11650. * specularMap: new THREE.Texture( <Image> ),
  11651. *
  11652. * alphaMap: new THREE.Texture( <Image> ),
  11653. *
  11654. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  11655. * combine: THREE.Multiply,
  11656. * reflectivity: <float>,
  11657. * refractionRatio: <float>,
  11658. *
  11659. * shading: THREE.SmoothShading,
  11660. * blending: THREE.NormalBlending,
  11661. * depthTest: <bool>,
  11662. * depthWrite: <bool>,
  11663. *
  11664. * wireframe: <boolean>,
  11665. * wireframeLinewidth: <float>,
  11666. *
  11667. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  11668. *
  11669. * skinning: <bool>,
  11670. * morphTargets: <bool>,
  11671. *
  11672. * fog: <bool>
  11673. * }
  11674. */
  11675. THREE.MeshBasicMaterial = function ( parameters ) {
  11676. THREE.Material.call( this );
  11677. this.type = 'MeshBasicMaterial';
  11678. this.color = new THREE.Color( 0xffffff ); // emissive
  11679. this.map = null;
  11680. this.aoMap = null;
  11681. this.aoMapIntensity = 1.0;
  11682. this.specularMap = null;
  11683. this.alphaMap = null;
  11684. this.envMap = null;
  11685. this.combine = THREE.MultiplyOperation;
  11686. this.reflectivity = 1;
  11687. this.refractionRatio = 0.98;
  11688. this.fog = true;
  11689. this.shading = THREE.SmoothShading;
  11690. this.wireframe = false;
  11691. this.wireframeLinewidth = 1;
  11692. this.wireframeLinecap = 'round';
  11693. this.wireframeLinejoin = 'round';
  11694. this.vertexColors = THREE.NoColors;
  11695. this.skinning = false;
  11696. this.morphTargets = false;
  11697. this.setValues( parameters );
  11698. };
  11699. THREE.MeshBasicMaterial.prototype = Object.create( THREE.Material.prototype );
  11700. THREE.MeshBasicMaterial.prototype.constructor = THREE.MeshBasicMaterial;
  11701. THREE.MeshBasicMaterial.prototype.copy = function ( source ) {
  11702. THREE.Material.prototype.copy.call( this, source );
  11703. this.color.copy( source.color );
  11704. this.map = source.map;
  11705. this.aoMap = source.aoMap;
  11706. this.aoMapIntensity = source.aoMapIntensity;
  11707. this.specularMap = source.specularMap;
  11708. this.alphaMap = source.alphaMap;
  11709. this.envMap = source.envMap;
  11710. this.combine = source.combine;
  11711. this.reflectivity = source.reflectivity;
  11712. this.refractionRatio = source.refractionRatio;
  11713. this.fog = source.fog;
  11714. this.shading = source.shading;
  11715. this.wireframe = source.wireframe;
  11716. this.wireframeLinewidth = source.wireframeLinewidth;
  11717. this.wireframeLinecap = source.wireframeLinecap;
  11718. this.wireframeLinejoin = source.wireframeLinejoin;
  11719. this.vertexColors = source.vertexColors;
  11720. this.skinning = source.skinning;
  11721. this.morphTargets = source.morphTargets;
  11722. return this;
  11723. };
  11724. // File:src/materials/MeshLambertMaterial.js
  11725. /**
  11726. * @author mrdoob / http://mrdoob.com/
  11727. * @author alteredq / http://alteredqualia.com/
  11728. *
  11729. * parameters = {
  11730. * color: <hex>,
  11731. * emissive: <hex>,
  11732. * opacity: <float>,
  11733. *
  11734. * map: new THREE.Texture( <Image> ),
  11735. *
  11736. * specularMap: new THREE.Texture( <Image> ),
  11737. *
  11738. * alphaMap: new THREE.Texture( <Image> ),
  11739. *
  11740. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  11741. * combine: THREE.Multiply,
  11742. * reflectivity: <float>,
  11743. * refractionRatio: <float>,
  11744. *
  11745. * blending: THREE.NormalBlending,
  11746. * depthTest: <bool>,
  11747. * depthWrite: <bool>,
  11748. *
  11749. * wireframe: <boolean>,
  11750. * wireframeLinewidth: <float>,
  11751. *
  11752. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  11753. *
  11754. * skinning: <bool>,
  11755. * morphTargets: <bool>,
  11756. * morphNormals: <bool>,
  11757. *
  11758. * fog: <bool>
  11759. * }
  11760. */
  11761. THREE.MeshLambertMaterial = function ( parameters ) {
  11762. THREE.Material.call( this );
  11763. this.type = 'MeshLambertMaterial';
  11764. this.color = new THREE.Color( 0xffffff ); // diffuse
  11765. this.emissive = new THREE.Color( 0x000000 );
  11766. this.map = null;
  11767. this.specularMap = null;
  11768. this.alphaMap = null;
  11769. this.envMap = null;
  11770. this.combine = THREE.MultiplyOperation;
  11771. this.reflectivity = 1;
  11772. this.refractionRatio = 0.98;
  11773. this.fog = true;
  11774. this.wireframe = false;
  11775. this.wireframeLinewidth = 1;
  11776. this.wireframeLinecap = 'round';
  11777. this.wireframeLinejoin = 'round';
  11778. this.vertexColors = THREE.NoColors;
  11779. this.skinning = false;
  11780. this.morphTargets = false;
  11781. this.morphNormals = false;
  11782. this.setValues( parameters );
  11783. };
  11784. THREE.MeshLambertMaterial.prototype = Object.create( THREE.Material.prototype );
  11785. THREE.MeshLambertMaterial.prototype.constructor = THREE.MeshLambertMaterial;
  11786. THREE.MeshLambertMaterial.prototype.copy = function ( source ) {
  11787. THREE.Material.prototype.copy.call( this, source );
  11788. this.color.copy( source.color );
  11789. this.emissive.copy( source.emissive );
  11790. this.map = source.map;
  11791. this.specularMap = source.specularMap;
  11792. this.alphaMap = source.alphaMap;
  11793. this.envMap = source.envMap;
  11794. this.combine = source.combine;
  11795. this.reflectivity = source.reflectivity;
  11796. this.refractionRatio = source.refractionRatio;
  11797. this.fog = source.fog;
  11798. this.wireframe = source.wireframe;
  11799. this.wireframeLinewidth = source.wireframeLinewidth;
  11800. this.wireframeLinecap = source.wireframeLinecap;
  11801. this.wireframeLinejoin = source.wireframeLinejoin;
  11802. this.vertexColors = source.vertexColors;
  11803. this.skinning = source.skinning;
  11804. this.morphTargets = source.morphTargets;
  11805. this.morphNormals = source.morphNormals;
  11806. return this;
  11807. };
  11808. // File:src/materials/MeshPhongMaterial.js
  11809. /**
  11810. * @author mrdoob / http://mrdoob.com/
  11811. * @author alteredq / http://alteredqualia.com/
  11812. *
  11813. * parameters = {
  11814. * color: <hex>,
  11815. * emissive: <hex>,
  11816. * specular: <hex>,
  11817. * shininess: <float>,
  11818. * opacity: <float>,
  11819. *
  11820. * map: new THREE.Texture( <Image> ),
  11821. *
  11822. * lightMap: new THREE.Texture( <Image> ),
  11823. * lightMapIntensity: <float>
  11824. *
  11825. * aoMap: new THREE.Texture( <Image> ),
  11826. * aoMapIntensity: <float>
  11827. *
  11828. * emissiveMap: new THREE.Texture( <Image> ),
  11829. *
  11830. * bumpMap: new THREE.Texture( <Image> ),
  11831. * bumpScale: <float>,
  11832. *
  11833. * normalMap: new THREE.Texture( <Image> ),
  11834. * normalScale: <Vector2>,
  11835. *
  11836. * displacementMap: new THREE.Texture( <Image> ),
  11837. * displacementScale: <float>,
  11838. * displacementBias: <float>,
  11839. *
  11840. * specularMap: new THREE.Texture( <Image> ),
  11841. *
  11842. * alphaMap: new THREE.Texture( <Image> ),
  11843. *
  11844. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  11845. * combine: THREE.Multiply,
  11846. * reflectivity: <float>,
  11847. * refractionRatio: <float>,
  11848. *
  11849. * shading: THREE.SmoothShading,
  11850. * blending: THREE.NormalBlending,
  11851. * depthTest: <bool>,
  11852. * depthWrite: <bool>,
  11853. *
  11854. * wireframe: <boolean>,
  11855. * wireframeLinewidth: <float>,
  11856. *
  11857. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  11858. *
  11859. * skinning: <bool>,
  11860. * morphTargets: <bool>,
  11861. * morphNormals: <bool>,
  11862. *
  11863. * fog: <bool>
  11864. * }
  11865. */
  11866. THREE.MeshPhongMaterial = function ( parameters ) {
  11867. THREE.Material.call( this );
  11868. this.type = 'MeshPhongMaterial';
  11869. this.color = new THREE.Color( 0xffffff ); // diffuse
  11870. this.emissive = new THREE.Color( 0x000000 );
  11871. this.specular = new THREE.Color( 0x111111 );
  11872. this.shininess = 30;
  11873. this.metal = false;
  11874. this.map = null;
  11875. this.lightMap = null;
  11876. this.lightMapIntensity = 1.0;
  11877. this.aoMap = null;
  11878. this.aoMapIntensity = 1.0;
  11879. this.emissiveMap = null;
  11880. this.bumpMap = null;
  11881. this.bumpScale = 1;
  11882. this.normalMap = null;
  11883. this.normalScale = new THREE.Vector2( 1, 1 );
  11884. this.displacementMap = null;
  11885. this.displacementScale = 1;
  11886. this.displacementBias = 0;
  11887. this.specularMap = null;
  11888. this.alphaMap = null;
  11889. this.envMap = null;
  11890. this.combine = THREE.MultiplyOperation;
  11891. this.reflectivity = 1;
  11892. this.refractionRatio = 0.98;
  11893. this.fog = true;
  11894. this.shading = THREE.SmoothShading;
  11895. this.wireframe = false;
  11896. this.wireframeLinewidth = 1;
  11897. this.wireframeLinecap = 'round';
  11898. this.wireframeLinejoin = 'round';
  11899. this.vertexColors = THREE.NoColors;
  11900. this.skinning = false;
  11901. this.morphTargets = false;
  11902. this.morphNormals = false;
  11903. this.setValues( parameters );
  11904. };
  11905. THREE.MeshPhongMaterial.prototype = Object.create( THREE.Material.prototype );
  11906. THREE.MeshPhongMaterial.prototype.constructor = THREE.MeshPhongMaterial;
  11907. THREE.MeshPhongMaterial.prototype.copy = function ( source ) {
  11908. THREE.Material.prototype.copy.call( this, source );
  11909. this.color.copy( source.color );
  11910. this.emissive.copy( source.emissive );
  11911. this.specular.copy( source.specular );
  11912. this.shininess = source.shininess;
  11913. this.metal = source.metal;
  11914. this.map = source.map;
  11915. this.lightMap = source.lightMap;
  11916. this.lightMapIntensity = source.lightMapIntensity;
  11917. this.aoMap = source.aoMap;
  11918. this.aoMapIntensity = source.aoMapIntensity;
  11919. this.emissiveMap = source.emissiveMap;
  11920. this.bumpMap = source.bumpMap;
  11921. this.bumpScale = source.bumpScale;
  11922. this.normalMap = source.normalMap;
  11923. this.normalScale.copy( source.normalScale );
  11924. this.displacementMap = source.displacementMap;
  11925. this.displacementScale = source.displacementScale;
  11926. this.displacementBias = source.displacementBias;
  11927. this.specularMap = source.specularMap;
  11928. this.alphaMap = source.alphaMap;
  11929. this.envMap = source.envMap;
  11930. this.combine = source.combine;
  11931. this.reflectivity = source.reflectivity;
  11932. this.refractionRatio = source.refractionRatio;
  11933. this.fog = source.fog;
  11934. this.shading = source.shading;
  11935. this.wireframe = source.wireframe;
  11936. this.wireframeLinewidth = source.wireframeLinewidth;
  11937. this.wireframeLinecap = source.wireframeLinecap;
  11938. this.wireframeLinejoin = source.wireframeLinejoin;
  11939. this.vertexColors = source.vertexColors;
  11940. this.skinning = source.skinning;
  11941. this.morphTargets = source.morphTargets;
  11942. this.morphNormals = source.morphNormals;
  11943. return this;
  11944. };
  11945. // File:src/materials/MeshPhysicalMaterial.js
  11946. /**
  11947. * @author WestLangley / http://github.com/WestLangley
  11948. *
  11949. * parameters = {
  11950. * color: <hex>,
  11951. * roughness: <float>,
  11952. * reflectivity: <float>,
  11953. * metalness: <float>,
  11954. * emissive: <hex>,
  11955. * opacity: <float>,
  11956. *
  11957. * map: new THREE.Texture( <Image> ),
  11958. *
  11959. * lightMap: new THREE.Texture( <Image> ),
  11960. * lightMapIntensity: <float>
  11961. *
  11962. * aoMap: new THREE.Texture( <Image> ),
  11963. * aoMapIntensity: <float>
  11964. *
  11965. * emissiveMap: new THREE.Texture( <Image> ),
  11966. *
  11967. * bumpMap: new THREE.Texture( <Image> ),
  11968. * bumpScale: <float>,
  11969. *
  11970. * normalMap: new THREE.Texture( <Image> ),
  11971. * normalScale: <Vector2>,
  11972. *
  11973. * displacementMap: new THREE.Texture( <Image> ),
  11974. * displacementScale: <float>,
  11975. * displacementBias: <float>,
  11976. *
  11977. * roughnessMap: new THREE.Texture( <Image> ),
  11978. *
  11979. * reflectivityMap: new THREE.Texture( <Image> ),
  11980. *
  11981. * metalnessMap: new THREE.Texture( <Image> ),
  11982. *
  11983. * alphaMap: new THREE.Texture( <Image> ),
  11984. *
  11985. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  11986. * refractionRatio: <float>,
  11987. *
  11988. * shading: THREE.SmoothShading,
  11989. * blending: THREE.NormalBlending,
  11990. * depthTest: <bool>,
  11991. * depthWrite: <bool>,
  11992. *
  11993. * wireframe: <boolean>,
  11994. * wireframeLinewidth: <float>,
  11995. *
  11996. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  11997. *
  11998. * skinning: <bool>,
  11999. * morphTargets: <bool>,
  12000. * morphNormals: <bool>,
  12001. *
  12002. * fog: <bool>
  12003. * }
  12004. */
  12005. THREE.MeshPhysicalMaterial = function ( parameters ) {
  12006. THREE.Material.call( this );
  12007. this.type = 'MeshPhysicalMaterial';
  12008. this.color = new THREE.Color( 0xffffff ); // diffuse
  12009. this.roughness = 0.5;
  12010. this.reflectivity = 1;
  12011. this.metalness = 0;
  12012. this.emissive = new THREE.Color( 0x000000 );
  12013. this.map = null;
  12014. this.lightMap = null;
  12015. this.lightMapIntensity = 1.0;
  12016. this.aoMap = null;
  12017. this.aoMapIntensity = 1.0;
  12018. this.emissiveMap = null;
  12019. this.bumpMap = null;
  12020. this.bumpScale = 1;
  12021. this.normalMap = null;
  12022. this.normalScale = new THREE.Vector2( 1, 1 );
  12023. this.displacementMap = null;
  12024. this.displacementScale = 1;
  12025. this.displacementBias = 0;
  12026. this.roughnessMap = null;
  12027. this.reflectivityMap = null;
  12028. this.metalnessMap = null;
  12029. this.alphaMap = null;
  12030. this.envMap = null;
  12031. this.envMapIntensity = 1.0;
  12032. this.refractionRatio = 0.98;
  12033. this.fog = true;
  12034. this.shading = THREE.SmoothShading;
  12035. this.wireframe = false;
  12036. this.wireframeLinewidth = 1;
  12037. this.wireframeLinecap = 'round';
  12038. this.wireframeLinejoin = 'round';
  12039. this.vertexColors = THREE.NoColors;
  12040. this.skinning = false;
  12041. this.morphTargets = false;
  12042. this.morphNormals = false;
  12043. this.setValues( parameters );
  12044. };
  12045. THREE.MeshPhysicalMaterial.prototype = Object.create( THREE.Material.prototype );
  12046. THREE.MeshPhysicalMaterial.prototype.constructor = THREE.MeshPhysicalMaterial;
  12047. THREE.MeshPhysicalMaterial.prototype.copy = function ( source ) {
  12048. THREE.Material.prototype.copy.call( this, source );
  12049. this.color.copy( source.color );
  12050. this.roughness = source.roughness;
  12051. this.reflectivity = source.reflectivity;
  12052. this.metalness = source.metalness;
  12053. this.emissive.copy( source.emissive );
  12054. this.map = source.map;
  12055. this.lightMap = source.lightMap;
  12056. this.lightMapIntensity = source.lightMapIntensity;
  12057. this.aoMap = source.aoMap;
  12058. this.aoMapIntensity = source.aoMapIntensity;
  12059. this.emissiveMap = source.emissiveMap;
  12060. this.bumpMap = source.bumpMap;
  12061. this.bumpScale = source.bumpScale;
  12062. this.normalMap = source.normalMap;
  12063. this.normalScale.copy( source.normalScale );
  12064. this.displacementMap = source.displacementMap;
  12065. this.displacementScale = source.displacementScale;
  12066. this.displacementBias = source.displacementBias;
  12067. this.roughnessMap = source.roughnessMap;
  12068. this.reflectivityMap = source.reflectivityMap;
  12069. this.metalnessMap = source.metalnessMap;
  12070. this.alphaMap = source.alphaMap;
  12071. this.envMap = source.envMap;
  12072. this.envMapIntensity = source.envMapIntensity;
  12073. this.refractionRatio = source.refractionRatio;
  12074. this.fog = source.fog;
  12075. this.shading = source.shading;
  12076. this.wireframe = source.wireframe;
  12077. this.wireframeLinewidth = source.wireframeLinewidth;
  12078. this.wireframeLinecap = source.wireframeLinecap;
  12079. this.wireframeLinejoin = source.wireframeLinejoin;
  12080. this.vertexColors = source.vertexColors;
  12081. this.skinning = source.skinning;
  12082. this.morphTargets = source.morphTargets;
  12083. this.morphNormals = source.morphNormals;
  12084. return this;
  12085. };
  12086. // File:src/materials/MeshDepthMaterial.js
  12087. /**
  12088. * @author mrdoob / http://mrdoob.com/
  12089. * @author alteredq / http://alteredqualia.com/
  12090. *
  12091. * parameters = {
  12092. * opacity: <float>,
  12093. *
  12094. * blending: THREE.NormalBlending,
  12095. * depthTest: <bool>,
  12096. * depthWrite: <bool>,
  12097. *
  12098. * wireframe: <boolean>,
  12099. * wireframeLinewidth: <float>
  12100. * }
  12101. */
  12102. THREE.MeshDepthMaterial = function ( parameters ) {
  12103. THREE.Material.call( this );
  12104. this.type = 'MeshDepthMaterial';
  12105. this.morphTargets = false;
  12106. this.wireframe = false;
  12107. this.wireframeLinewidth = 1;
  12108. this.setValues( parameters );
  12109. };
  12110. THREE.MeshDepthMaterial.prototype = Object.create( THREE.Material.prototype );
  12111. THREE.MeshDepthMaterial.prototype.constructor = THREE.MeshDepthMaterial;
  12112. THREE.MeshDepthMaterial.prototype.copy = function ( source ) {
  12113. THREE.Material.prototype.copy.call( this, source );
  12114. this.wireframe = source.wireframe;
  12115. this.wireframeLinewidth = source.wireframeLinewidth;
  12116. return this;
  12117. };
  12118. // File:src/materials/MeshNormalMaterial.js
  12119. /**
  12120. * @author mrdoob / http://mrdoob.com/
  12121. *
  12122. * parameters = {
  12123. * opacity: <float>,
  12124. *
  12125. * shading: THREE.FlatShading,
  12126. * blending: THREE.NormalBlending,
  12127. * depthTest: <bool>,
  12128. * depthWrite: <bool>,
  12129. *
  12130. * wireframe: <boolean>,
  12131. * wireframeLinewidth: <float>
  12132. * }
  12133. */
  12134. THREE.MeshNormalMaterial = function ( parameters ) {
  12135. THREE.Material.call( this, parameters );
  12136. this.type = 'MeshNormalMaterial';
  12137. this.wireframe = false;
  12138. this.wireframeLinewidth = 1;
  12139. this.morphTargets = false;
  12140. this.setValues( parameters );
  12141. };
  12142. THREE.MeshNormalMaterial.prototype = Object.create( THREE.Material.prototype );
  12143. THREE.MeshNormalMaterial.prototype.constructor = THREE.MeshNormalMaterial;
  12144. THREE.MeshNormalMaterial.prototype.copy = function ( source ) {
  12145. THREE.Material.prototype.copy.call( this, source );
  12146. this.wireframe = source.wireframe;
  12147. this.wireframeLinewidth = source.wireframeLinewidth;
  12148. return this;
  12149. };
  12150. // File:src/materials/MultiMaterial.js
  12151. /**
  12152. * @author mrdoob / http://mrdoob.com/
  12153. */
  12154. THREE.MultiMaterial = function ( materials ) {
  12155. this.uuid = THREE.Math.generateUUID();
  12156. this.type = 'MultiMaterial';
  12157. this.materials = materials instanceof Array ? materials : [];
  12158. this.visible = true;
  12159. };
  12160. THREE.MultiMaterial.prototype = {
  12161. constructor: THREE.MultiMaterial,
  12162. toJSON: function ( meta ) {
  12163. var output = {
  12164. metadata: {
  12165. version: 4.2,
  12166. type: 'material',
  12167. generator: 'MaterialExporter'
  12168. },
  12169. uuid: this.uuid,
  12170. type: this.type,
  12171. materials: []
  12172. };
  12173. var materials = this.materials;
  12174. for ( var i = 0, l = materials.length; i < l; i ++ ) {
  12175. var material = materials[ i ].toJSON( meta );
  12176. delete material.metadata;
  12177. output.materials.push( material );
  12178. }
  12179. output.visible = this.visible;
  12180. return output;
  12181. },
  12182. clone: function () {
  12183. var material = new this.constructor();
  12184. for ( var i = 0; i < this.materials.length; i ++ ) {
  12185. material.materials.push( this.materials[ i ].clone() );
  12186. }
  12187. material.visible = this.visible;
  12188. return material;
  12189. }
  12190. };
  12191. // backwards compatibility
  12192. THREE.MeshFaceMaterial = THREE.MultiMaterial;
  12193. // File:src/materials/PointsMaterial.js
  12194. /**
  12195. * @author mrdoob / http://mrdoob.com/
  12196. * @author alteredq / http://alteredqualia.com/
  12197. *
  12198. * parameters = {
  12199. * color: <hex>,
  12200. * opacity: <float>,
  12201. * map: new THREE.Texture( <Image> ),
  12202. *
  12203. * size: <float>,
  12204. * sizeAttenuation: <bool>,
  12205. *
  12206. * blending: THREE.NormalBlending,
  12207. * depthTest: <bool>,
  12208. * depthWrite: <bool>,
  12209. *
  12210. * vertexColors: <bool>,
  12211. *
  12212. * fog: <bool>
  12213. * }
  12214. */
  12215. THREE.PointsMaterial = function ( parameters ) {
  12216. THREE.Material.call( this );
  12217. this.type = 'PointsMaterial';
  12218. this.color = new THREE.Color( 0xffffff );
  12219. this.map = null;
  12220. this.size = 1;
  12221. this.sizeAttenuation = true;
  12222. this.vertexColors = THREE.NoColors;
  12223. this.fog = true;
  12224. this.setValues( parameters );
  12225. };
  12226. THREE.PointsMaterial.prototype = Object.create( THREE.Material.prototype );
  12227. THREE.PointsMaterial.prototype.constructor = THREE.PointsMaterial;
  12228. THREE.PointsMaterial.prototype.copy = function ( source ) {
  12229. THREE.Material.prototype.copy.call( this, source );
  12230. this.color.copy( source.color );
  12231. this.map = source.map;
  12232. this.size = source.size;
  12233. this.sizeAttenuation = source.sizeAttenuation;
  12234. this.vertexColors = source.vertexColors;
  12235. this.fog = source.fog;
  12236. return this;
  12237. };
  12238. // File:src/materials/ShaderMaterial.js
  12239. /**
  12240. * @author alteredq / http://alteredqualia.com/
  12241. *
  12242. * parameters = {
  12243. * defines: { "label" : "value" },
  12244. * uniforms: { "parameter1": { type: "f", value: 1.0 }, "parameter2": { type: "i" value2: 2 } },
  12245. *
  12246. * fragmentShader: <string>,
  12247. * vertexShader: <string>,
  12248. *
  12249. * shading: THREE.SmoothShading,
  12250. * blending: THREE.NormalBlending,
  12251. * depthTest: <bool>,
  12252. * depthWrite: <bool>,
  12253. *
  12254. * wireframe: <boolean>,
  12255. * wireframeLinewidth: <float>,
  12256. *
  12257. * lights: <bool>,
  12258. *
  12259. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  12260. *
  12261. * skinning: <bool>,
  12262. * morphTargets: <bool>,
  12263. * morphNormals: <bool>,
  12264. *
  12265. * fog: <bool>
  12266. * }
  12267. */
  12268. THREE.ShaderMaterial = function ( parameters ) {
  12269. THREE.Material.call( this );
  12270. this.type = 'ShaderMaterial';
  12271. this.defines = {};
  12272. this.uniforms = {};
  12273. this.vertexShader = 'void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}';
  12274. this.fragmentShader = 'void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}';
  12275. this.shading = THREE.SmoothShading;
  12276. this.linewidth = 1;
  12277. this.wireframe = false;
  12278. this.wireframeLinewidth = 1;
  12279. this.fog = false; // set to use scene fog
  12280. this.lights = false; // set to use scene lights
  12281. this.vertexColors = THREE.NoColors; // set to use "color" attribute stream
  12282. this.skinning = false; // set to use skinning attribute streams
  12283. this.morphTargets = false; // set to use morph targets
  12284. this.morphNormals = false; // set to use morph normals
  12285. this.extensions = {
  12286. derivatives: false, // set to use derivatives
  12287. fragDepth: false, // set to use fragment depth values
  12288. drawBuffers: false, // set to use draw buffers
  12289. shaderTextureLOD: false // set to use shader texture LOD
  12290. };
  12291. // When rendered geometry doesn't include these attributes but the material does,
  12292. // use these default values in WebGL. This avoids errors when buffer data is missing.
  12293. this.defaultAttributeValues = {
  12294. 'color': [ 1, 1, 1 ],
  12295. 'uv': [ 0, 0 ],
  12296. 'uv2': [ 0, 0 ]
  12297. };
  12298. this.index0AttributeName = undefined;
  12299. if ( parameters !== undefined ) {
  12300. if ( parameters.attributes !== undefined ) {
  12301. console.error( 'THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.' );
  12302. }
  12303. this.setValues( parameters );
  12304. }
  12305. };
  12306. THREE.ShaderMaterial.prototype = Object.create( THREE.Material.prototype );
  12307. THREE.ShaderMaterial.prototype.constructor = THREE.ShaderMaterial;
  12308. THREE.ShaderMaterial.prototype.copy = function ( source ) {
  12309. THREE.Material.prototype.copy.call( this, source );
  12310. this.fragmentShader = source.fragmentShader;
  12311. this.vertexShader = source.vertexShader;
  12312. this.uniforms = THREE.UniformsUtils.clone( source.uniforms );
  12313. this.attributes = source.attributes;
  12314. this.defines = source.defines;
  12315. this.shading = source.shading;
  12316. this.wireframe = source.wireframe;
  12317. this.wireframeLinewidth = source.wireframeLinewidth;
  12318. this.fog = source.fog;
  12319. this.lights = source.lights;
  12320. this.vertexColors = source.vertexColors;
  12321. this.skinning = source.skinning;
  12322. this.morphTargets = source.morphTargets;
  12323. this.morphNormals = source.morphNormals;
  12324. this.extensions = source.extensions;
  12325. return this;
  12326. };
  12327. THREE.ShaderMaterial.prototype.toJSON = function ( meta ) {
  12328. var data = THREE.Material.prototype.toJSON.call( this, meta );
  12329. data.uniforms = this.uniforms;
  12330. data.attributes = this.attributes;
  12331. data.vertexShader = this.vertexShader;
  12332. data.fragmentShader = this.fragmentShader;
  12333. return data;
  12334. };
  12335. // File:src/materials/RawShaderMaterial.js
  12336. /**
  12337. * @author mrdoob / http://mrdoob.com/
  12338. */
  12339. THREE.RawShaderMaterial = function ( parameters ) {
  12340. THREE.ShaderMaterial.call( this, parameters );
  12341. this.type = 'RawShaderMaterial';
  12342. };
  12343. THREE.RawShaderMaterial.prototype = Object.create( THREE.ShaderMaterial.prototype );
  12344. THREE.RawShaderMaterial.prototype.constructor = THREE.RawShaderMaterial;
  12345. // File:src/materials/SpriteMaterial.js
  12346. /**
  12347. * @author alteredq / http://alteredqualia.com/
  12348. *
  12349. * parameters = {
  12350. * color: <hex>,
  12351. * opacity: <float>,
  12352. * map: new THREE.Texture( <Image> ),
  12353. *
  12354. * blending: THREE.NormalBlending,
  12355. * depthTest: <bool>,
  12356. * depthWrite: <bool>,
  12357. *
  12358. * uvOffset: new THREE.Vector2(),
  12359. * uvScale: new THREE.Vector2(),
  12360. *
  12361. * fog: <bool>
  12362. * }
  12363. */
  12364. THREE.SpriteMaterial = function ( parameters ) {
  12365. THREE.Material.call( this );
  12366. this.type = 'SpriteMaterial';
  12367. this.color = new THREE.Color( 0xffffff );
  12368. this.map = null;
  12369. this.rotation = 0;
  12370. this.fog = false;
  12371. // set parameters
  12372. this.setValues( parameters );
  12373. };
  12374. THREE.SpriteMaterial.prototype = Object.create( THREE.Material.prototype );
  12375. THREE.SpriteMaterial.prototype.constructor = THREE.SpriteMaterial;
  12376. THREE.SpriteMaterial.prototype.copy = function ( source ) {
  12377. THREE.Material.prototype.copy.call( this, source );
  12378. this.color.copy( source.color );
  12379. this.map = source.map;
  12380. this.rotation = source.rotation;
  12381. this.fog = source.fog;
  12382. return this;
  12383. };
  12384. // File:src/textures/Texture.js
  12385. /**
  12386. * @author mrdoob / http://mrdoob.com/
  12387. * @author alteredq / http://alteredqualia.com/
  12388. * @author szimek / https://github.com/szimek/
  12389. */
  12390. THREE.Texture = function ( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  12391. Object.defineProperty( this, 'id', { value: THREE.TextureIdCount ++ } );
  12392. this.uuid = THREE.Math.generateUUID();
  12393. this.name = '';
  12394. this.sourceFile = '';
  12395. this.image = image !== undefined ? image : THREE.Texture.DEFAULT_IMAGE;
  12396. this.mipmaps = [];
  12397. this.mapping = mapping !== undefined ? mapping : THREE.Texture.DEFAULT_MAPPING;
  12398. this.wrapS = wrapS !== undefined ? wrapS : THREE.ClampToEdgeWrapping;
  12399. this.wrapT = wrapT !== undefined ? wrapT : THREE.ClampToEdgeWrapping;
  12400. this.magFilter = magFilter !== undefined ? magFilter : THREE.LinearFilter;
  12401. this.minFilter = minFilter !== undefined ? minFilter : THREE.LinearMipMapLinearFilter;
  12402. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  12403. this.format = format !== undefined ? format : THREE.RGBAFormat;
  12404. this.type = type !== undefined ? type : THREE.UnsignedByteType;
  12405. this.offset = new THREE.Vector2( 0, 0 );
  12406. this.repeat = new THREE.Vector2( 1, 1 );
  12407. this.generateMipmaps = true;
  12408. this.premultiplyAlpha = false;
  12409. this.flipY = true;
  12410. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  12411. this.version = 0;
  12412. this.onUpdate = null;
  12413. };
  12414. THREE.Texture.DEFAULT_IMAGE = undefined;
  12415. THREE.Texture.DEFAULT_MAPPING = THREE.UVMapping;
  12416. THREE.Texture.prototype = {
  12417. constructor: THREE.Texture,
  12418. set needsUpdate ( value ) {
  12419. if ( value === true ) this.version ++;
  12420. },
  12421. clone: function () {
  12422. return new this.constructor().copy( this );
  12423. },
  12424. copy: function ( source ) {
  12425. this.image = source.image;
  12426. this.mipmaps = source.mipmaps.slice( 0 );
  12427. this.mapping = source.mapping;
  12428. this.wrapS = source.wrapS;
  12429. this.wrapT = source.wrapT;
  12430. this.magFilter = source.magFilter;
  12431. this.minFilter = source.minFilter;
  12432. this.anisotropy = source.anisotropy;
  12433. this.format = source.format;
  12434. this.type = source.type;
  12435. this.offset.copy( source.offset );
  12436. this.repeat.copy( source.repeat );
  12437. this.generateMipmaps = source.generateMipmaps;
  12438. this.premultiplyAlpha = source.premultiplyAlpha;
  12439. this.flipY = source.flipY;
  12440. this.unpackAlignment = source.unpackAlignment;
  12441. return this;
  12442. },
  12443. toJSON: function ( meta ) {
  12444. if ( meta.textures[ this.uuid ] !== undefined ) {
  12445. return meta.textures[ this.uuid ];
  12446. }
  12447. function getDataURL( image ) {
  12448. var canvas;
  12449. if ( image.toDataURL !== undefined ) {
  12450. canvas = image;
  12451. } else {
  12452. canvas = document.createElement( 'canvas' );
  12453. canvas.width = image.width;
  12454. canvas.height = image.height;
  12455. canvas.getContext( '2d' ).drawImage( image, 0, 0, image.width, image.height );
  12456. }
  12457. if ( canvas.width > 2048 || canvas.height > 2048 ) {
  12458. return canvas.toDataURL( 'image/jpeg', 0.6 );
  12459. } else {
  12460. return canvas.toDataURL( 'image/png' );
  12461. }
  12462. }
  12463. var output = {
  12464. metadata: {
  12465. version: 4.4,
  12466. type: 'Texture',
  12467. generator: 'Texture.toJSON'
  12468. },
  12469. uuid: this.uuid,
  12470. name: this.name,
  12471. mapping: this.mapping,
  12472. repeat: [ this.repeat.x, this.repeat.y ],
  12473. offset: [ this.offset.x, this.offset.y ],
  12474. wrap: [ this.wrapS, this.wrapT ],
  12475. minFilter: this.minFilter,
  12476. magFilter: this.magFilter,
  12477. anisotropy: this.anisotropy
  12478. };
  12479. if ( this.image !== undefined ) {
  12480. // TODO: Move to THREE.Image
  12481. var image = this.image;
  12482. if ( image.uuid === undefined ) {
  12483. image.uuid = THREE.Math.generateUUID(); // UGH
  12484. }
  12485. if ( meta.images[ image.uuid ] === undefined ) {
  12486. meta.images[ image.uuid ] = {
  12487. uuid: image.uuid,
  12488. url: getDataURL( image )
  12489. };
  12490. }
  12491. output.image = image.uuid;
  12492. }
  12493. meta.textures[ this.uuid ] = output;
  12494. return output;
  12495. },
  12496. dispose: function () {
  12497. this.dispatchEvent( { type: 'dispose' } );
  12498. },
  12499. transformUv: function ( uv ) {
  12500. if ( this.mapping !== THREE.UVMapping ) return;
  12501. uv.multiply( this.repeat );
  12502. uv.add( this.offset );
  12503. if ( uv.x < 0 || uv.x > 1 ) {
  12504. switch ( this.wrapS ) {
  12505. case THREE.RepeatWrapping:
  12506. uv.x = uv.x - Math.floor( uv.x );
  12507. break;
  12508. case THREE.ClampToEdgeWrapping:
  12509. uv.x = uv.x < 0 ? 0 : 1;
  12510. break;
  12511. case THREE.MirroredRepeatWrapping:
  12512. if ( Math.abs( Math.floor( uv.x ) % 2 ) === 1 ) {
  12513. uv.x = Math.ceil( uv.x ) - uv.x;
  12514. } else {
  12515. uv.x = uv.x - Math.floor( uv.x );
  12516. }
  12517. break;
  12518. }
  12519. }
  12520. if ( uv.y < 0 || uv.y > 1 ) {
  12521. switch ( this.wrapT ) {
  12522. case THREE.RepeatWrapping:
  12523. uv.y = uv.y - Math.floor( uv.y );
  12524. break;
  12525. case THREE.ClampToEdgeWrapping:
  12526. uv.y = uv.y < 0 ? 0 : 1;
  12527. break;
  12528. case THREE.MirroredRepeatWrapping:
  12529. if ( Math.abs( Math.floor( uv.y ) % 2 ) === 1 ) {
  12530. uv.y = Math.ceil( uv.y ) - uv.y;
  12531. } else {
  12532. uv.y = uv.y - Math.floor( uv.y );
  12533. }
  12534. break;
  12535. }
  12536. }
  12537. if ( this.flipY ) {
  12538. uv.y = 1 - uv.y;
  12539. }
  12540. }
  12541. };
  12542. THREE.EventDispatcher.prototype.apply( THREE.Texture.prototype );
  12543. THREE.TextureIdCount = 0;
  12544. // File:src/textures/CanvasTexture.js
  12545. /**
  12546. * @author mrdoob / http://mrdoob.com/
  12547. */
  12548. THREE.CanvasTexture = function ( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  12549. THREE.Texture.call( this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  12550. this.needsUpdate = true;
  12551. };
  12552. THREE.CanvasTexture.prototype = Object.create( THREE.Texture.prototype );
  12553. THREE.CanvasTexture.prototype.constructor = THREE.CanvasTexture;
  12554. // File:src/textures/CubeTexture.js
  12555. /**
  12556. * @author mrdoob / http://mrdoob.com/
  12557. */
  12558. THREE.CubeTexture = function ( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  12559. mapping = mapping !== undefined ? mapping : THREE.CubeReflectionMapping;
  12560. THREE.Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  12561. this.images = images;
  12562. this.flipY = false;
  12563. };
  12564. THREE.CubeTexture.prototype = Object.create( THREE.Texture.prototype );
  12565. THREE.CubeTexture.prototype.constructor = THREE.CubeTexture;
  12566. THREE.CubeTexture.prototype.copy = function ( source ) {
  12567. THREE.Texture.prototype.copy.call( this, source );
  12568. this.images = source.images;
  12569. return this;
  12570. };
  12571. // File:src/textures/CompressedTexture.js
  12572. /**
  12573. * @author alteredq / http://alteredqualia.com/
  12574. */
  12575. THREE.CompressedTexture = function ( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy ) {
  12576. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  12577. this.image = { width: width, height: height };
  12578. this.mipmaps = mipmaps;
  12579. // no flipping for cube textures
  12580. // (also flipping doesn't work for compressed textures )
  12581. this.flipY = false;
  12582. // can't generate mipmaps for compressed textures
  12583. // mips must be embedded in DDS files
  12584. this.generateMipmaps = false;
  12585. };
  12586. THREE.CompressedTexture.prototype = Object.create( THREE.Texture.prototype );
  12587. THREE.CompressedTexture.prototype.constructor = THREE.CompressedTexture;
  12588. // File:src/textures/DataTexture.js
  12589. /**
  12590. * @author alteredq / http://alteredqualia.com/
  12591. */
  12592. THREE.DataTexture = function ( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy ) {
  12593. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  12594. this.image = { data: data, width: width, height: height };
  12595. this.magFilter = magFilter !== undefined ? magFilter : THREE.NearestFilter;
  12596. this.minFilter = minFilter !== undefined ? minFilter : THREE.NearestFilter;
  12597. this.flipY = false;
  12598. this.generateMipmaps = false;
  12599. };
  12600. THREE.DataTexture.prototype = Object.create( THREE.Texture.prototype );
  12601. THREE.DataTexture.prototype.constructor = THREE.DataTexture;
  12602. // File:src/textures/VideoTexture.js
  12603. /**
  12604. * @author mrdoob / http://mrdoob.com/
  12605. */
  12606. THREE.VideoTexture = function ( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  12607. THREE.Texture.call( this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  12608. this.generateMipmaps = false;
  12609. var scope = this;
  12610. function update() {
  12611. requestAnimationFrame( update );
  12612. if ( video.readyState === video.HAVE_ENOUGH_DATA ) {
  12613. scope.needsUpdate = true;
  12614. }
  12615. }
  12616. update();
  12617. };
  12618. THREE.VideoTexture.prototype = Object.create( THREE.Texture.prototype );
  12619. THREE.VideoTexture.prototype.constructor = THREE.VideoTexture;
  12620. // File:src/objects/Group.js
  12621. /**
  12622. * @author mrdoob / http://mrdoob.com/
  12623. */
  12624. THREE.Group = function () {
  12625. THREE.Object3D.call( this );
  12626. this.type = 'Group';
  12627. };
  12628. THREE.Group.prototype = Object.create( THREE.Object3D.prototype );
  12629. THREE.Group.prototype.constructor = THREE.Group;
  12630. // File:src/objects/Points.js
  12631. /**
  12632. * @author alteredq / http://alteredqualia.com/
  12633. */
  12634. THREE.Points = function ( geometry, material ) {
  12635. THREE.Object3D.call( this );
  12636. this.type = 'Points';
  12637. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  12638. this.material = material !== undefined ? material : new THREE.PointsMaterial( { color: Math.random() * 0xffffff } );
  12639. };
  12640. THREE.Points.prototype = Object.create( THREE.Object3D.prototype );
  12641. THREE.Points.prototype.constructor = THREE.Points;
  12642. THREE.Points.prototype.raycast = ( function () {
  12643. var inverseMatrix = new THREE.Matrix4();
  12644. var ray = new THREE.Ray();
  12645. return function raycast( raycaster, intersects ) {
  12646. var object = this;
  12647. var geometry = object.geometry;
  12648. var threshold = raycaster.params.Points.threshold;
  12649. inverseMatrix.getInverse( this.matrixWorld );
  12650. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  12651. if ( geometry.boundingBox !== null ) {
  12652. if ( ray.intersectsBox( geometry.boundingBox ) === false ) return;
  12653. }
  12654. var localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  12655. var localThresholdSq = localThreshold * localThreshold;
  12656. var position = new THREE.Vector3();
  12657. function testPoint( point, index ) {
  12658. var rayPointDistanceSq = ray.distanceSqToPoint( point );
  12659. if ( rayPointDistanceSq < localThresholdSq ) {
  12660. var intersectPoint = ray.closestPointToPoint( point );
  12661. intersectPoint.applyMatrix4( object.matrixWorld );
  12662. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  12663. if ( distance < raycaster.near || distance > raycaster.far ) return;
  12664. intersects.push( {
  12665. distance: distance,
  12666. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  12667. point: intersectPoint.clone(),
  12668. index: index,
  12669. face: null,
  12670. object: object
  12671. } );
  12672. }
  12673. }
  12674. if ( geometry instanceof THREE.BufferGeometry ) {
  12675. var index = geometry.index;
  12676. var attributes = geometry.attributes;
  12677. var positions = attributes.position.array;
  12678. if ( index !== null ) {
  12679. var indices = index.array;
  12680. for ( var i = 0, il = indices.length; i < il; i ++ ) {
  12681. var a = indices[ i ];
  12682. position.fromArray( positions, a * 3 );
  12683. testPoint( position, a );
  12684. }
  12685. } else {
  12686. for ( var i = 0, l = positions.length / 3; i < l; i ++ ) {
  12687. position.fromArray( positions, i * 3 );
  12688. testPoint( position, i );
  12689. }
  12690. }
  12691. } else {
  12692. var vertices = geometry.vertices;
  12693. for ( var i = 0, l = vertices.length; i < l; i ++ ) {
  12694. testPoint( vertices[ i ], i );
  12695. }
  12696. }
  12697. };
  12698. }() );
  12699. THREE.Points.prototype.clone = function () {
  12700. return new this.constructor( this.geometry, this.material ).copy( this );
  12701. };
  12702. // File:src/objects/Line.js
  12703. /**
  12704. * @author mrdoob / http://mrdoob.com/
  12705. */
  12706. THREE.Line = function ( geometry, material, mode ) {
  12707. if ( mode === 1 ) {
  12708. console.warn( 'THREE.Line: parameter THREE.LinePieces no longer supported. Created THREE.LineSegments instead.' );
  12709. return new THREE.LineSegments( geometry, material );
  12710. }
  12711. THREE.Object3D.call( this );
  12712. this.type = 'Line';
  12713. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  12714. this.material = material !== undefined ? material : new THREE.LineBasicMaterial( { color: Math.random() * 0xffffff } );
  12715. };
  12716. THREE.Line.prototype = Object.create( THREE.Object3D.prototype );
  12717. THREE.Line.prototype.constructor = THREE.Line;
  12718. THREE.Line.prototype.raycast = ( function () {
  12719. var inverseMatrix = new THREE.Matrix4();
  12720. var ray = new THREE.Ray();
  12721. var sphere = new THREE.Sphere();
  12722. return function raycast( raycaster, intersects ) {
  12723. var precision = raycaster.linePrecision;
  12724. var precisionSq = precision * precision;
  12725. var geometry = this.geometry;
  12726. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  12727. // Checking boundingSphere distance to ray
  12728. sphere.copy( geometry.boundingSphere );
  12729. sphere.applyMatrix4( this.matrixWorld );
  12730. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  12731. inverseMatrix.getInverse( this.matrixWorld );
  12732. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  12733. var vStart = new THREE.Vector3();
  12734. var vEnd = new THREE.Vector3();
  12735. var interSegment = new THREE.Vector3();
  12736. var interRay = new THREE.Vector3();
  12737. var step = this instanceof THREE.LineSegments ? 2 : 1;
  12738. if ( geometry instanceof THREE.BufferGeometry ) {
  12739. var index = geometry.index;
  12740. var attributes = geometry.attributes;
  12741. if ( index !== null ) {
  12742. var indices = index.array;
  12743. var positions = attributes.position.array;
  12744. for ( var i = 0, l = indices.length - 1; i < l; i += step ) {
  12745. var a = indices[ i ];
  12746. var b = indices[ i + 1 ];
  12747. vStart.fromArray( positions, a * 3 );
  12748. vEnd.fromArray( positions, b * 3 );
  12749. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  12750. if ( distSq > precisionSq ) continue;
  12751. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  12752. var distance = raycaster.ray.origin.distanceTo( interRay );
  12753. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  12754. intersects.push( {
  12755. distance: distance,
  12756. // What do we want? intersection point on the ray or on the segment??
  12757. // point: raycaster.ray.at( distance ),
  12758. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  12759. index: i,
  12760. face: null,
  12761. faceIndex: null,
  12762. object: this
  12763. } );
  12764. }
  12765. } else {
  12766. var positions = attributes.position.array;
  12767. for ( var i = 0, l = positions.length / 3 - 1; i < l; i += step ) {
  12768. vStart.fromArray( positions, 3 * i );
  12769. vEnd.fromArray( positions, 3 * i + 3 );
  12770. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  12771. if ( distSq > precisionSq ) continue;
  12772. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  12773. var distance = raycaster.ray.origin.distanceTo( interRay );
  12774. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  12775. intersects.push( {
  12776. distance: distance,
  12777. // What do we want? intersection point on the ray or on the segment??
  12778. // point: raycaster.ray.at( distance ),
  12779. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  12780. index: i,
  12781. face: null,
  12782. faceIndex: null,
  12783. object: this
  12784. } );
  12785. }
  12786. }
  12787. } else if ( geometry instanceof THREE.Geometry ) {
  12788. var vertices = geometry.vertices;
  12789. var nbVertices = vertices.length;
  12790. for ( var i = 0; i < nbVertices - 1; i += step ) {
  12791. var distSq = ray.distanceSqToSegment( vertices[ i ], vertices[ i + 1 ], interRay, interSegment );
  12792. if ( distSq > precisionSq ) continue;
  12793. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  12794. var distance = raycaster.ray.origin.distanceTo( interRay );
  12795. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  12796. intersects.push( {
  12797. distance: distance,
  12798. // What do we want? intersection point on the ray or on the segment??
  12799. // point: raycaster.ray.at( distance ),
  12800. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  12801. index: i,
  12802. face: null,
  12803. faceIndex: null,
  12804. object: this
  12805. } );
  12806. }
  12807. }
  12808. };
  12809. }() );
  12810. THREE.Line.prototype.clone = function () {
  12811. return new this.constructor( this.geometry, this.material ).copy( this );
  12812. };
  12813. // DEPRECATED
  12814. THREE.LineStrip = 0;
  12815. THREE.LinePieces = 1;
  12816. // File:src/objects/LineSegments.js
  12817. /**
  12818. * @author mrdoob / http://mrdoob.com/
  12819. */
  12820. THREE.LineSegments = function ( geometry, material ) {
  12821. THREE.Line.call( this, geometry, material );
  12822. this.type = 'LineSegments';
  12823. };
  12824. THREE.LineSegments.prototype = Object.create( THREE.Line.prototype );
  12825. THREE.LineSegments.prototype.constructor = THREE.LineSegments;
  12826. // File:src/objects/Mesh.js
  12827. /**
  12828. * @author mrdoob / http://mrdoob.com/
  12829. * @author alteredq / http://alteredqualia.com/
  12830. * @author mikael emtinger / http://gomo.se/
  12831. * @author jonobr1 / http://jonobr1.com/
  12832. */
  12833. THREE.Mesh = function ( geometry, material ) {
  12834. THREE.Object3D.call( this );
  12835. this.type = 'Mesh';
  12836. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  12837. this.material = material !== undefined ? material : new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff } );
  12838. this.updateMorphTargets();
  12839. };
  12840. THREE.Mesh.prototype = Object.create( THREE.Object3D.prototype );
  12841. THREE.Mesh.prototype.constructor = THREE.Mesh;
  12842. THREE.Mesh.prototype.updateMorphTargets = function () {
  12843. if ( this.geometry.morphTargets !== undefined && this.geometry.morphTargets.length > 0 ) {
  12844. this.morphTargetBase = - 1;
  12845. this.morphTargetInfluences = [];
  12846. this.morphTargetDictionary = {};
  12847. for ( var m = 0, ml = this.geometry.morphTargets.length; m < ml; m ++ ) {
  12848. this.morphTargetInfluences.push( 0 );
  12849. this.morphTargetDictionary[ this.geometry.morphTargets[ m ].name ] = m;
  12850. }
  12851. }
  12852. };
  12853. THREE.Mesh.prototype.getMorphTargetIndexByName = function ( name ) {
  12854. if ( this.morphTargetDictionary[ name ] !== undefined ) {
  12855. return this.morphTargetDictionary[ name ];
  12856. }
  12857. console.warn( 'THREE.Mesh.getMorphTargetIndexByName: morph target ' + name + ' does not exist. Returning 0.' );
  12858. return 0;
  12859. };
  12860. THREE.Mesh.prototype.raycast = ( function () {
  12861. var inverseMatrix = new THREE.Matrix4();
  12862. var ray = new THREE.Ray();
  12863. var sphere = new THREE.Sphere();
  12864. var vA = new THREE.Vector3();
  12865. var vB = new THREE.Vector3();
  12866. var vC = new THREE.Vector3();
  12867. var tempA = new THREE.Vector3();
  12868. var tempB = new THREE.Vector3();
  12869. var tempC = new THREE.Vector3();
  12870. var uvA = new THREE.Vector2();
  12871. var uvB = new THREE.Vector2();
  12872. var uvC = new THREE.Vector2();
  12873. var barycoord = new THREE.Vector3();
  12874. var intersectionPoint = new THREE.Vector3();
  12875. var intersectionPointWorld = new THREE.Vector3();
  12876. function uvIntersection( point, p1, p2, p3, uv1, uv2, uv3 ) {
  12877. THREE.Triangle.barycoordFromPoint( point, p1, p2, p3, barycoord );
  12878. uv1.multiplyScalar( barycoord.x );
  12879. uv2.multiplyScalar( barycoord.y );
  12880. uv3.multiplyScalar( barycoord.z );
  12881. uv1.add( uv2 ).add( uv3 );
  12882. return uv1.clone();
  12883. }
  12884. function checkIntersection( object, raycaster, ray, pA, pB, pC, point ){
  12885. var intersect;
  12886. var material = object.material;
  12887. if ( material.side === THREE.BackSide ) {
  12888. intersect = ray.intersectTriangle( pC, pB, pA, true, point );
  12889. } else {
  12890. intersect = ray.intersectTriangle( pA, pB, pC, material.side !== THREE.DoubleSide, point );
  12891. }
  12892. if ( intersect === null ) return null;
  12893. intersectionPointWorld.copy( point );
  12894. intersectionPointWorld.applyMatrix4( object.matrixWorld );
  12895. var distance = raycaster.ray.origin.distanceTo( intersectionPointWorld );
  12896. if ( distance < raycaster.near || distance > raycaster.far ) return null;
  12897. return {
  12898. distance: distance,
  12899. point: intersectionPointWorld.clone(),
  12900. object: object
  12901. };
  12902. }
  12903. function checkBufferGeometryIntersection( object, raycaster, ray, positions, uvs, a, b, c ) {
  12904. vA.fromArray( positions, a * 3 );
  12905. vB.fromArray( positions, b * 3 );
  12906. vC.fromArray( positions, c * 3 );
  12907. var intersection = checkIntersection( object, raycaster, ray, vA, vB, vC, intersectionPoint );
  12908. if ( intersection ) {
  12909. if ( uvs ) {
  12910. uvA.fromArray( uvs, a * 2 );
  12911. uvB.fromArray( uvs, b * 2 );
  12912. uvC.fromArray( uvs, c * 2 );
  12913. intersection.uv = uvIntersection( intersectionPoint, vA, vB, vC, uvA, uvB, uvC );
  12914. }
  12915. intersection.face = new THREE.Face3( a, b, c, THREE.Triangle.normal( vA, vB, vC ) );
  12916. intersection.faceIndex = a;
  12917. }
  12918. return intersection;
  12919. }
  12920. return function raycast( raycaster, intersects ) {
  12921. var geometry = this.geometry;
  12922. var material = this.material;
  12923. if ( material === undefined ) return;
  12924. // Checking boundingSphere distance to ray
  12925. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  12926. var matrixWorld = this.matrixWorld;
  12927. sphere.copy( geometry.boundingSphere );
  12928. sphere.applyMatrix4( matrixWorld );
  12929. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  12930. // Check boundingBox before continuing
  12931. inverseMatrix.getInverse( matrixWorld );
  12932. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  12933. if ( geometry.boundingBox !== null ) {
  12934. if ( ray.intersectsBox( geometry.boundingBox ) === false ) return;
  12935. }
  12936. var uvs, intersection;
  12937. if ( geometry instanceof THREE.BufferGeometry ) {
  12938. var a, b, c;
  12939. var index = geometry.index;
  12940. var attributes = geometry.attributes;
  12941. var positions = attributes.position.array;
  12942. if ( attributes.uv !== undefined ){
  12943. uvs = attributes.uv.array;
  12944. }
  12945. if ( index !== null ) {
  12946. var indices = index.array;
  12947. for ( var i = 0, l = indices.length; i < l; i += 3 ) {
  12948. a = indices[ i ];
  12949. b = indices[ i + 1 ];
  12950. c = indices[ i + 2 ];
  12951. intersection = checkBufferGeometryIntersection( this, raycaster, ray, positions, uvs, a, b, c );
  12952. if ( intersection ) {
  12953. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in indices buffer semantics
  12954. intersects.push( intersection );
  12955. }
  12956. }
  12957. } else {
  12958. for ( var i = 0, l = positions.length; i < l; i += 9 ) {
  12959. a = i / 3;
  12960. b = a + 1;
  12961. c = a + 2;
  12962. intersection = checkBufferGeometryIntersection( this, raycaster, ray, positions, uvs, a, b, c );
  12963. if ( intersection ) {
  12964. intersection.index = a; // triangle number in positions buffer semantics
  12965. intersects.push( intersection );
  12966. }
  12967. }
  12968. }
  12969. } else if ( geometry instanceof THREE.Geometry ) {
  12970. var fvA, fvB, fvC;
  12971. var isFaceMaterial = material instanceof THREE.MeshFaceMaterial;
  12972. var materials = isFaceMaterial === true ? material.materials : null;
  12973. var vertices = geometry.vertices;
  12974. var faces = geometry.faces;
  12975. var faceVertexUvs = geometry.faceVertexUvs[ 0 ];
  12976. if ( faceVertexUvs.length > 0 ) uvs = faceVertexUvs;
  12977. for ( var f = 0, fl = faces.length; f < fl; f ++ ) {
  12978. var face = faces[ f ];
  12979. var faceMaterial = isFaceMaterial === true ? materials[ face.materialIndex ] : material;
  12980. if ( faceMaterial === undefined ) continue;
  12981. fvA = vertices[ face.a ];
  12982. fvB = vertices[ face.b ];
  12983. fvC = vertices[ face.c ];
  12984. if ( faceMaterial.morphTargets === true ) {
  12985. var morphTargets = geometry.morphTargets;
  12986. var morphInfluences = this.morphTargetInfluences;
  12987. vA.set( 0, 0, 0 );
  12988. vB.set( 0, 0, 0 );
  12989. vC.set( 0, 0, 0 );
  12990. for ( var t = 0, tl = morphTargets.length; t < tl; t ++ ) {
  12991. var influence = morphInfluences[ t ];
  12992. if ( influence === 0 ) continue;
  12993. var targets = morphTargets[ t ].vertices;
  12994. vA.addScaledVector( tempA.subVectors( targets[ face.a ], fvA ), influence );
  12995. vB.addScaledVector( tempB.subVectors( targets[ face.b ], fvB ), influence );
  12996. vC.addScaledVector( tempC.subVectors( targets[ face.c ], fvC ), influence );
  12997. }
  12998. vA.add( fvA );
  12999. vB.add( fvB );
  13000. vC.add( fvC );
  13001. fvA = vA;
  13002. fvB = vB;
  13003. fvC = vC;
  13004. }
  13005. intersection = checkIntersection( this, raycaster, ray, fvA, fvB, fvC, intersectionPoint );
  13006. if ( intersection ) {
  13007. if ( uvs ) {
  13008. var uvs_f = uvs[ f ];
  13009. uvA.copy( uvs_f[ 0 ] );
  13010. uvB.copy( uvs_f[ 1 ] );
  13011. uvC.copy( uvs_f[ 2 ] );
  13012. intersection.uv = uvIntersection( intersectionPoint, fvA, fvB, fvC, uvA, uvB, uvC );
  13013. }
  13014. intersection.face = face;
  13015. intersection.faceIndex = f;
  13016. intersects.push( intersection );
  13017. }
  13018. }
  13019. }
  13020. };
  13021. }() );
  13022. THREE.Mesh.prototype.clone = function () {
  13023. return new this.constructor( this.geometry, this.material ).copy( this );
  13024. };
  13025. // File:src/objects/Bone.js
  13026. /**
  13027. * @author mikael emtinger / http://gomo.se/
  13028. * @author alteredq / http://alteredqualia.com/
  13029. * @author ikerr / http://verold.com
  13030. */
  13031. THREE.Bone = function ( skin ) {
  13032. THREE.Object3D.call( this );
  13033. this.type = 'Bone';
  13034. this.skin = skin;
  13035. };
  13036. THREE.Bone.prototype = Object.create( THREE.Object3D.prototype );
  13037. THREE.Bone.prototype.constructor = THREE.Bone;
  13038. THREE.Bone.prototype.copy = function ( source ) {
  13039. THREE.Object3D.prototype.copy.call( this, source );
  13040. this.skin = source.skin;
  13041. return this;
  13042. };
  13043. // File:src/objects/Skeleton.js
  13044. /**
  13045. * @author mikael emtinger / http://gomo.se/
  13046. * @author alteredq / http://alteredqualia.com/
  13047. * @author michael guerrero / http://realitymeltdown.com
  13048. * @author ikerr / http://verold.com
  13049. */
  13050. THREE.Skeleton = function ( bones, boneInverses, useVertexTexture ) {
  13051. this.useVertexTexture = useVertexTexture !== undefined ? useVertexTexture : true;
  13052. this.identityMatrix = new THREE.Matrix4();
  13053. // copy the bone array
  13054. bones = bones || [];
  13055. this.bones = bones.slice( 0 );
  13056. // create a bone texture or an array of floats
  13057. if ( this.useVertexTexture ) {
  13058. // layout (1 matrix = 4 pixels)
  13059. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  13060. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  13061. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  13062. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  13063. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  13064. var size = Math.sqrt( this.bones.length * 4 ); // 4 pixels needed for 1 matrix
  13065. size = THREE.Math.nextPowerOfTwo( Math.ceil( size ) );
  13066. size = Math.max( size, 4 );
  13067. this.boneTextureWidth = size;
  13068. this.boneTextureHeight = size;
  13069. this.boneMatrices = new Float32Array( this.boneTextureWidth * this.boneTextureHeight * 4 ); // 4 floats per RGBA pixel
  13070. this.boneTexture = new THREE.DataTexture( this.boneMatrices, this.boneTextureWidth, this.boneTextureHeight, THREE.RGBAFormat, THREE.FloatType );
  13071. } else {
  13072. this.boneMatrices = new Float32Array( 16 * this.bones.length );
  13073. }
  13074. // use the supplied bone inverses or calculate the inverses
  13075. if ( boneInverses === undefined ) {
  13076. this.calculateInverses();
  13077. } else {
  13078. if ( this.bones.length === boneInverses.length ) {
  13079. this.boneInverses = boneInverses.slice( 0 );
  13080. } else {
  13081. console.warn( 'THREE.Skeleton bonInverses is the wrong length.' );
  13082. this.boneInverses = [];
  13083. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13084. this.boneInverses.push( new THREE.Matrix4() );
  13085. }
  13086. }
  13087. }
  13088. };
  13089. THREE.Skeleton.prototype.calculateInverses = function () {
  13090. this.boneInverses = [];
  13091. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13092. var inverse = new THREE.Matrix4();
  13093. if ( this.bones[ b ] ) {
  13094. inverse.getInverse( this.bones[ b ].matrixWorld );
  13095. }
  13096. this.boneInverses.push( inverse );
  13097. }
  13098. };
  13099. THREE.Skeleton.prototype.pose = function () {
  13100. var bone;
  13101. // recover the bind-time world matrices
  13102. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13103. bone = this.bones[ b ];
  13104. if ( bone ) {
  13105. bone.matrixWorld.getInverse( this.boneInverses[ b ] );
  13106. }
  13107. }
  13108. // compute the local matrices, positions, rotations and scales
  13109. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13110. bone = this.bones[ b ];
  13111. if ( bone ) {
  13112. if ( bone.parent ) {
  13113. bone.matrix.getInverse( bone.parent.matrixWorld );
  13114. bone.matrix.multiply( bone.matrixWorld );
  13115. } else {
  13116. bone.matrix.copy( bone.matrixWorld );
  13117. }
  13118. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  13119. }
  13120. }
  13121. };
  13122. THREE.Skeleton.prototype.update = ( function () {
  13123. var offsetMatrix = new THREE.Matrix4();
  13124. return function update() {
  13125. // flatten bone matrices to array
  13126. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13127. // compute the offset between the current and the original transform
  13128. var matrix = this.bones[ b ] ? this.bones[ b ].matrixWorld : this.identityMatrix;
  13129. offsetMatrix.multiplyMatrices( matrix, this.boneInverses[ b ] );
  13130. offsetMatrix.flattenToArrayOffset( this.boneMatrices, b * 16 );
  13131. }
  13132. if ( this.useVertexTexture ) {
  13133. this.boneTexture.needsUpdate = true;
  13134. }
  13135. };
  13136. } )();
  13137. THREE.Skeleton.prototype.clone = function () {
  13138. return new THREE.Skeleton( this.bones, this.boneInverses, this.useVertexTexture );
  13139. };
  13140. // File:src/objects/SkinnedMesh.js
  13141. /**
  13142. * @author mikael emtinger / http://gomo.se/
  13143. * @author alteredq / http://alteredqualia.com/
  13144. * @author ikerr / http://verold.com
  13145. */
  13146. THREE.SkinnedMesh = function ( geometry, material, useVertexTexture ) {
  13147. THREE.Mesh.call( this, geometry, material );
  13148. this.type = 'SkinnedMesh';
  13149. this.bindMode = "attached";
  13150. this.bindMatrix = new THREE.Matrix4();
  13151. this.bindMatrixInverse = new THREE.Matrix4();
  13152. // init bones
  13153. // TODO: remove bone creation as there is no reason (other than
  13154. // convenience) for THREE.SkinnedMesh to do this.
  13155. var bones = [];
  13156. if ( this.geometry && this.geometry.bones !== undefined ) {
  13157. var bone, gbone;
  13158. for ( var b = 0, bl = this.geometry.bones.length; b < bl; ++ b ) {
  13159. gbone = this.geometry.bones[ b ];
  13160. bone = new THREE.Bone( this );
  13161. bones.push( bone );
  13162. bone.name = gbone.name;
  13163. bone.position.fromArray( gbone.pos );
  13164. bone.quaternion.fromArray( gbone.rotq );
  13165. if ( gbone.scl !== undefined ) bone.scale.fromArray( gbone.scl );
  13166. }
  13167. for ( var b = 0, bl = this.geometry.bones.length; b < bl; ++ b ) {
  13168. gbone = this.geometry.bones[ b ];
  13169. if ( gbone.parent !== - 1 && gbone.parent !== null) {
  13170. bones[ gbone.parent ].add( bones[ b ] );
  13171. } else {
  13172. this.add( bones[ b ] );
  13173. }
  13174. }
  13175. }
  13176. this.normalizeSkinWeights();
  13177. this.updateMatrixWorld( true );
  13178. this.bind( new THREE.Skeleton( bones, undefined, useVertexTexture ), this.matrixWorld );
  13179. };
  13180. THREE.SkinnedMesh.prototype = Object.create( THREE.Mesh.prototype );
  13181. THREE.SkinnedMesh.prototype.constructor = THREE.SkinnedMesh;
  13182. THREE.SkinnedMesh.prototype.bind = function( skeleton, bindMatrix ) {
  13183. this.skeleton = skeleton;
  13184. if ( bindMatrix === undefined ) {
  13185. this.updateMatrixWorld( true );
  13186. this.skeleton.calculateInverses();
  13187. bindMatrix = this.matrixWorld;
  13188. }
  13189. this.bindMatrix.copy( bindMatrix );
  13190. this.bindMatrixInverse.getInverse( bindMatrix );
  13191. };
  13192. THREE.SkinnedMesh.prototype.pose = function () {
  13193. this.skeleton.pose();
  13194. };
  13195. THREE.SkinnedMesh.prototype.normalizeSkinWeights = function () {
  13196. if ( this.geometry instanceof THREE.Geometry ) {
  13197. for ( var i = 0; i < this.geometry.skinIndices.length; i ++ ) {
  13198. var sw = this.geometry.skinWeights[ i ];
  13199. var scale = 1.0 / sw.lengthManhattan();
  13200. if ( scale !== Infinity ) {
  13201. sw.multiplyScalar( scale );
  13202. } else {
  13203. sw.set( 1 ); // this will be normalized by the shader anyway
  13204. }
  13205. }
  13206. } else {
  13207. // skinning weights assumed to be normalized for THREE.BufferGeometry
  13208. }
  13209. };
  13210. THREE.SkinnedMesh.prototype.updateMatrixWorld = function( force ) {
  13211. THREE.Mesh.prototype.updateMatrixWorld.call( this, true );
  13212. if ( this.bindMode === "attached" ) {
  13213. this.bindMatrixInverse.getInverse( this.matrixWorld );
  13214. } else if ( this.bindMode === "detached" ) {
  13215. this.bindMatrixInverse.getInverse( this.bindMatrix );
  13216. } else {
  13217. console.warn( 'THREE.SkinnedMesh unrecognized bindMode: ' + this.bindMode );
  13218. }
  13219. };
  13220. THREE.SkinnedMesh.prototype.clone = function() {
  13221. return new this.constructor( this.geometry, this.material, this.useVertexTexture ).copy( this );
  13222. };
  13223. // File:src/objects/LOD.js
  13224. /**
  13225. * @author mikael emtinger / http://gomo.se/
  13226. * @author alteredq / http://alteredqualia.com/
  13227. * @author mrdoob / http://mrdoob.com/
  13228. */
  13229. THREE.LOD = function () {
  13230. THREE.Object3D.call( this );
  13231. this.type = 'LOD';
  13232. Object.defineProperties( this, {
  13233. levels: {
  13234. enumerable: true,
  13235. value: []
  13236. },
  13237. objects: {
  13238. get: function () {
  13239. console.warn( 'THREE.LOD: .objects has been renamed to .levels.' );
  13240. return this.levels;
  13241. }
  13242. }
  13243. } );
  13244. };
  13245. THREE.LOD.prototype = Object.create( THREE.Object3D.prototype );
  13246. THREE.LOD.prototype.constructor = THREE.LOD;
  13247. THREE.LOD.prototype.addLevel = function ( object, distance ) {
  13248. if ( distance === undefined ) distance = 0;
  13249. distance = Math.abs( distance );
  13250. var levels = this.levels;
  13251. for ( var l = 0; l < levels.length; l ++ ) {
  13252. if ( distance < levels[ l ].distance ) {
  13253. break;
  13254. }
  13255. }
  13256. levels.splice( l, 0, { distance: distance, object: object } );
  13257. this.add( object );
  13258. };
  13259. THREE.LOD.prototype.getObjectForDistance = function ( distance ) {
  13260. var levels = this.levels;
  13261. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  13262. if ( distance < levels[ i ].distance ) {
  13263. break;
  13264. }
  13265. }
  13266. return levels[ i - 1 ].object;
  13267. };
  13268. THREE.LOD.prototype.raycast = ( function () {
  13269. var matrixPosition = new THREE.Vector3();
  13270. return function raycast( raycaster, intersects ) {
  13271. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  13272. var distance = raycaster.ray.origin.distanceTo( matrixPosition );
  13273. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  13274. };
  13275. }() );
  13276. THREE.LOD.prototype.update = function () {
  13277. var v1 = new THREE.Vector3();
  13278. var v2 = new THREE.Vector3();
  13279. return function update( camera ) {
  13280. var levels = this.levels;
  13281. if ( levels.length > 1 ) {
  13282. v1.setFromMatrixPosition( camera.matrixWorld );
  13283. v2.setFromMatrixPosition( this.matrixWorld );
  13284. var distance = v1.distanceTo( v2 );
  13285. levels[ 0 ].object.visible = true;
  13286. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  13287. if ( distance >= levels[ i ].distance ) {
  13288. levels[ i - 1 ].object.visible = false;
  13289. levels[ i ].object.visible = true;
  13290. } else {
  13291. break;
  13292. }
  13293. }
  13294. for ( ; i < l; i ++ ) {
  13295. levels[ i ].object.visible = false;
  13296. }
  13297. }
  13298. };
  13299. }();
  13300. THREE.LOD.prototype.copy = function ( source ) {
  13301. THREE.Object3D.prototype.copy.call( this, source, false );
  13302. var levels = source.levels;
  13303. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  13304. var level = levels[ i ];
  13305. this.addLevel( level.object.clone(), level.distance );
  13306. }
  13307. return this;
  13308. };
  13309. THREE.LOD.prototype.toJSON = function ( meta ) {
  13310. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  13311. data.object.levels = [];
  13312. var levels = this.levels;
  13313. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  13314. var level = levels[ i ];
  13315. data.object.levels.push( {
  13316. object: level.object.uuid,
  13317. distance: level.distance
  13318. } );
  13319. }
  13320. return data;
  13321. };
  13322. // File:src/objects/Sprite.js
  13323. /**
  13324. * @author mikael emtinger / http://gomo.se/
  13325. * @author alteredq / http://alteredqualia.com/
  13326. */
  13327. THREE.Sprite = ( function () {
  13328. var indices = new Uint16Array( [ 0, 1, 2, 0, 2, 3 ] );
  13329. var vertices = new Float32Array( [ - 0.5, - 0.5, 0, 0.5, - 0.5, 0, 0.5, 0.5, 0, - 0.5, 0.5, 0 ] );
  13330. var uvs = new Float32Array( [ 0, 0, 1, 0, 1, 1, 0, 1 ] );
  13331. var geometry = new THREE.BufferGeometry();
  13332. geometry.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  13333. geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  13334. geometry.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  13335. return function Sprite( material ) {
  13336. THREE.Object3D.call( this );
  13337. this.type = 'Sprite';
  13338. this.geometry = geometry;
  13339. this.material = ( material !== undefined ) ? material : new THREE.SpriteMaterial();
  13340. };
  13341. } )();
  13342. THREE.Sprite.prototype = Object.create( THREE.Object3D.prototype );
  13343. THREE.Sprite.prototype.constructor = THREE.Sprite;
  13344. THREE.Sprite.prototype.raycast = ( function () {
  13345. var matrixPosition = new THREE.Vector3();
  13346. return function raycast( raycaster, intersects ) {
  13347. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  13348. var distanceSq = raycaster.ray.distanceSqToPoint( matrixPosition );
  13349. var guessSizeSq = this.scale.x * this.scale.y;
  13350. if ( distanceSq > guessSizeSq ) {
  13351. return;
  13352. }
  13353. intersects.push( {
  13354. distance: Math.sqrt( distanceSq ),
  13355. point: this.position,
  13356. face: null,
  13357. object: this
  13358. } );
  13359. };
  13360. }() );
  13361. THREE.Sprite.prototype.clone = function () {
  13362. return new this.constructor( this.material ).copy( this );
  13363. };
  13364. // Backwards compatibility
  13365. THREE.Particle = THREE.Sprite;
  13366. // File:src/objects/LensFlare.js
  13367. /**
  13368. * @author mikael emtinger / http://gomo.se/
  13369. * @author alteredq / http://alteredqualia.com/
  13370. */
  13371. THREE.LensFlare = function ( texture, size, distance, blending, color ) {
  13372. THREE.Object3D.call( this );
  13373. this.lensFlares = [];
  13374. this.positionScreen = new THREE.Vector3();
  13375. this.customUpdateCallback = undefined;
  13376. if ( texture !== undefined ) {
  13377. this.add( texture, size, distance, blending, color );
  13378. }
  13379. };
  13380. THREE.LensFlare.prototype = Object.create( THREE.Object3D.prototype );
  13381. THREE.LensFlare.prototype.constructor = THREE.LensFlare;
  13382. /*
  13383. * Add: adds another flare
  13384. */
  13385. THREE.LensFlare.prototype.add = function ( texture, size, distance, blending, color, opacity ) {
  13386. if ( size === undefined ) size = - 1;
  13387. if ( distance === undefined ) distance = 0;
  13388. if ( opacity === undefined ) opacity = 1;
  13389. if ( color === undefined ) color = new THREE.Color( 0xffffff );
  13390. if ( blending === undefined ) blending = THREE.NormalBlending;
  13391. distance = Math.min( distance, Math.max( 0, distance ) );
  13392. this.lensFlares.push( {
  13393. texture: texture, // THREE.Texture
  13394. size: size, // size in pixels (-1 = use texture.width)
  13395. distance: distance, // distance (0-1) from light source (0=at light source)
  13396. x: 0, y: 0, z: 0, // screen position (-1 => 1) z = 0 is in front z = 1 is back
  13397. scale: 1, // scale
  13398. rotation: 0, // rotation
  13399. opacity: opacity, // opacity
  13400. color: color, // color
  13401. blending: blending // blending
  13402. } );
  13403. };
  13404. /*
  13405. * Update lens flares update positions on all flares based on the screen position
  13406. * Set myLensFlare.customUpdateCallback to alter the flares in your project specific way.
  13407. */
  13408. THREE.LensFlare.prototype.updateLensFlares = function () {
  13409. var f, fl = this.lensFlares.length;
  13410. var flare;
  13411. var vecX = - this.positionScreen.x * 2;
  13412. var vecY = - this.positionScreen.y * 2;
  13413. for ( f = 0; f < fl; f ++ ) {
  13414. flare = this.lensFlares[ f ];
  13415. flare.x = this.positionScreen.x + vecX * flare.distance;
  13416. flare.y = this.positionScreen.y + vecY * flare.distance;
  13417. flare.wantedRotation = flare.x * Math.PI * 0.25;
  13418. flare.rotation += ( flare.wantedRotation - flare.rotation ) * 0.25;
  13419. }
  13420. };
  13421. THREE.LensFlare.prototype.copy = function ( source ) {
  13422. THREE.Object3D.prototype.copy.call( this, source );
  13423. this.positionScreen.copy( source.positionScreen );
  13424. this.customUpdateCallback = source.customUpdateCallback;
  13425. for ( var i = 0, l = source.lensFlares.length; i < l; i ++ ) {
  13426. this.lensFlares.push( source.lensFlares[ i ] );
  13427. }
  13428. return this;
  13429. };
  13430. // File:src/scenes/Scene.js
  13431. /**
  13432. * @author mrdoob / http://mrdoob.com/
  13433. */
  13434. THREE.Scene = function () {
  13435. THREE.Object3D.call( this );
  13436. this.type = 'Scene';
  13437. this.fog = null;
  13438. this.overrideMaterial = null;
  13439. this.autoUpdate = true; // checked by the renderer
  13440. };
  13441. THREE.Scene.prototype = Object.create( THREE.Object3D.prototype );
  13442. THREE.Scene.prototype.constructor = THREE.Scene;
  13443. THREE.Scene.prototype.copy = function ( source ) {
  13444. THREE.Object3D.prototype.copy.call( this, source );
  13445. if ( source.fog !== null ) this.fog = source.fog.clone();
  13446. if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
  13447. this.autoUpdate = source.autoUpdate;
  13448. this.matrixAutoUpdate = source.matrixAutoUpdate;
  13449. return this;
  13450. };
  13451. // File:src/scenes/Fog.js
  13452. /**
  13453. * @author mrdoob / http://mrdoob.com/
  13454. * @author alteredq / http://alteredqualia.com/
  13455. */
  13456. THREE.Fog = function ( color, near, far ) {
  13457. this.name = '';
  13458. this.color = new THREE.Color( color );
  13459. this.near = ( near !== undefined ) ? near : 1;
  13460. this.far = ( far !== undefined ) ? far : 1000;
  13461. };
  13462. THREE.Fog.prototype.clone = function () {
  13463. return new THREE.Fog( this.color.getHex(), this.near, this.far );
  13464. };
  13465. // File:src/scenes/FogExp2.js
  13466. /**
  13467. * @author mrdoob / http://mrdoob.com/
  13468. * @author alteredq / http://alteredqualia.com/
  13469. */
  13470. THREE.FogExp2 = function ( color, density ) {
  13471. this.name = '';
  13472. this.color = new THREE.Color( color );
  13473. this.density = ( density !== undefined ) ? density : 0.00025;
  13474. };
  13475. THREE.FogExp2.prototype.clone = function () {
  13476. return new THREE.FogExp2( this.color.getHex(), this.density );
  13477. };
  13478. // File:src/renderers/shaders/ShaderChunk.js
  13479. THREE.ShaderChunk = {};
  13480. // File:src/renderers/shaders/ShaderChunk/alphamap_fragment.glsl
  13481. THREE.ShaderChunk[ 'alphamap_fragment'] = "#ifdef USE_ALPHAMAP\n diffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif\n";
  13482. // File:src/renderers/shaders/ShaderChunk/alphamap_pars_fragment.glsl
  13483. THREE.ShaderChunk[ 'alphamap_pars_fragment'] = "#ifdef USE_ALPHAMAP\n uniform sampler2D alphaMap;\n#endif\n";
  13484. // File:src/renderers/shaders/ShaderChunk/alphatest_fragment.glsl
  13485. THREE.ShaderChunk[ 'alphatest_fragment'] = "#ifdef ALPHATEST\n if ( diffuseColor.a < ALPHATEST ) discard;\n#endif\n";
  13486. // File:src/renderers/shaders/ShaderChunk/aomap_fragment.glsl
  13487. THREE.ShaderChunk[ 'aomap_fragment'] = "#ifdef USE_AOMAP\n reflectedLight.indirectDiffuse *= ( texture2D( aoMap, vUv2 ).r - 1.0 ) * aoMapIntensity + 1.0;\n#endif\n";
  13488. // File:src/renderers/shaders/ShaderChunk/aomap_pars_fragment.glsl
  13489. THREE.ShaderChunk[ 'aomap_pars_fragment'] = "#ifdef USE_AOMAP\n uniform sampler2D aoMap;\n uniform float aoMapIntensity;\n#endif";
  13490. // File:src/renderers/shaders/ShaderChunk/begin_vertex.glsl
  13491. THREE.ShaderChunk[ 'begin_vertex'] = "\nvec3 transformed = vec3( position );\n";
  13492. // File:src/renderers/shaders/ShaderChunk/beginnormal_vertex.glsl
  13493. THREE.ShaderChunk[ 'beginnormal_vertex'] = "\nvec3 objectNormal = vec3( normal );\n";
  13494. // File:src/renderers/shaders/ShaderChunk/bsdfs.glsl
  13495. THREE.ShaderChunk[ 'bsdfs'] = "float calcLightAttenuation( float lightDistance, float cutoffDistance, 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 diffuseColor;\n}\nvec3 F_Schlick( const in vec3 specularColor, const in float dotLH ) {\n float fresnel = exp2( ( -5.55437 * dotLH - 6.98316 ) * dotLH );\n return ( 1.0 - specularColor ) * fresnel + specularColor;\n}\nfloat G_GGX_Smith( in float alpha, in float dotNL, 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( in float alpha, in float dotNH ) {\n float a2 = alpha * alpha;\n float denom = dotNH * dotNH * ( a2 - 1.0 ) + 1.0;\n return 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 \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, vec3 specularColor, 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 ( 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} // validated";
  13496. // File:src/renderers/shaders/ShaderChunk/bumpmap_pars_fragment.glsl
  13497. 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";
  13498. // File:src/renderers/shaders/ShaderChunk/color_fragment.glsl
  13499. THREE.ShaderChunk[ 'color_fragment'] = "#ifdef USE_COLOR\n diffuseColor.rgb *= vColor;\n#endif";
  13500. // File:src/renderers/shaders/ShaderChunk/color_pars_fragment.glsl
  13501. THREE.ShaderChunk[ 'color_pars_fragment'] = "#ifdef USE_COLOR\n varying vec3 vColor;\n#endif\n";
  13502. // File:src/renderers/shaders/ShaderChunk/color_pars_vertex.glsl
  13503. THREE.ShaderChunk[ 'color_pars_vertex'] = "#ifdef USE_COLOR\n varying vec3 vColor;\n#endif";
  13504. // File:src/renderers/shaders/ShaderChunk/color_vertex.glsl
  13505. THREE.ShaderChunk[ 'color_vertex'] = "#ifdef USE_COLOR\n vColor.xyz = color.xyz;\n#endif";
  13506. // File:src/renderers/shaders/ShaderChunk/common.glsl
  13507. 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 average( const in vec3 color ) { return dot( color, vec3( 0.3333 ) ); }\nstruct IncidentLight {\n vec3 color;\n vec3 direction;\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 normal, in mat4 matrix ) {\n return normalize( ( matrix * vec4( normal, 0.0 ) ).xyz );\n}\nvec3 inverseTransformDirection( in vec3 normal, in mat4 matrix ) {\n return normalize( ( vec4( normal, 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";
  13508. // File:src/renderers/shaders/ShaderChunk/defaultnormal_vertex.glsl
  13509. THREE.ShaderChunk[ 'defaultnormal_vertex'] = "#ifdef FLIP_SIDED\n objectNormal = -objectNormal;\n#endif\nvec3 transformedNormal = normalMatrix * objectNormal;\n";
  13510. // File:src/renderers/shaders/ShaderChunk/displacementmap_vertex.glsl
  13511. THREE.ShaderChunk[ 'displacementmap_vertex'] = "#ifdef USE_DISPLACEMENTMAP\n transformed += normal * ( texture2D( displacementMap, uv ).x * displacementScale + displacementBias );\n#endif\n";
  13512. // File:src/renderers/shaders/ShaderChunk/displacementmap_pars_vertex.glsl
  13513. THREE.ShaderChunk[ 'displacementmap_pars_vertex'] = "#ifdef USE_DISPLACEMENTMAP\n uniform sampler2D displacementMap;\n uniform float displacementScale;\n uniform float displacementBias;\n#endif\n";
  13514. // File:src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl
  13515. 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";
  13516. // File:src/renderers/shaders/ShaderChunk/emissivemap_pars_fragment.glsl
  13517. THREE.ShaderChunk[ 'emissivemap_pars_fragment'] = "#ifdef USE_EMISSIVEMAP\n uniform sampler2D emissiveMap;\n#endif\n";
  13518. // File:src/renderers/shaders/ShaderChunk/envmap_fragment.glsl
  13519. 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";
  13520. // File:src/renderers/shaders/ShaderChunk/envmap_pars_fragment.glsl
  13521. THREE.ShaderChunk[ 'envmap_pars_fragment'] = "#ifdef USE_ENVMAP\n uniform float reflectivity;\n #ifdef ENVMAP_TYPE_CUBE\n uniform samplerCube envMap;\n #else\n uniform sampler2D envMap;\n #endif\n uniform float flipEnvMap;\n #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( PHYSICAL )\n uniform float refractionRatio;\n #else\n varying vec3 vReflect;\n #endif\n#endif\n";
  13522. // File:src/renderers/shaders/ShaderChunk/envmap_pars_vertex.glsl
  13523. THREE.ShaderChunk[ 'envmap_pars_vertex'] = "#if defined( USE_ENVMAP ) && ! defined( USE_BUMPMAP ) && ! defined( USE_NORMALMAP ) && ! defined( PHONG ) && ! defined( PHYSICAL )\n varying vec3 vReflect;\n uniform float refractionRatio;\n#endif\n";
  13524. // File:src/renderers/shaders/ShaderChunk/envmap_vertex.glsl
  13525. THREE.ShaderChunk[ 'envmap_vertex'] = "#if defined( USE_ENVMAP ) && ! defined( USE_BUMPMAP ) && ! defined( USE_NORMALMAP ) && ! defined( PHONG ) && ! defined( PHYSICAL )\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";
  13526. // File:src/renderers/shaders/ShaderChunk/fog_fragment.glsl
  13527. 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";
  13528. // File:src/renderers/shaders/ShaderChunk/fog_pars_fragment.glsl
  13529. 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";
  13530. // File:src/renderers/shaders/ShaderChunk/lights_pars.glsl
  13531. THREE.ShaderChunk[ 'lights_pars'] = "uniform vec3 ambientLightColor;\n#if MAX_DIR_LIGHTS > 0\n struct DirectionalLight {\n vec3 direction;\n vec3 color;\n };\n uniform DirectionalLight directionalLights[ MAX_DIR_LIGHTS ];\n IncidentLight getDirectionalDirectLight( const in DirectionalLight directionalLight, const in GeometricContext geometry ) { \n IncidentLight directLight;\n \n directLight.color = directionalLight.color;\n directLight.direction = directionalLight.direction; \n return directLight;\n }\n#endif\n#if MAX_POINT_LIGHTS > 0\n struct PointLight {\n vec3 position;\n vec3 color;\n float distance;\n float decay;\n };\n uniform PointLight pointLights[ MAX_POINT_LIGHTS ];\n IncidentLight getPointDirectLight( const in PointLight pointLight, const in GeometricContext geometry ) { \n \n IncidentLight directLight;\n \n vec3 lVector = pointLight.position - geometry.position; \n directLight.direction = normalize( lVector ); \n \n directLight.color = pointLight.color; \n directLight.color *= calcLightAttenuation( length( lVector ), pointLight.distance, pointLight.decay ); \n \n return directLight;\n }\n#endif\n#if MAX_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 exponent;\n };\n uniform SpotLight spotLights[ MAX_SPOT_LIGHTS ];\n IncidentLight getSpotDirectLight( const in SpotLight spotLight, const in GeometricContext geometry ) {\n \n IncidentLight directLight;\n vec3 lVector = spotLight.position - geometry.position;\n directLight.direction = normalize( lVector );\n \n float spotEffect = dot( spotLight.direction, directLight.direction );\n spotEffect = saturate( pow( saturate( spotEffect ), spotLight.exponent ) );\n \n directLight.color = spotLight.color;\n directLight.color *= ( spotEffect * calcLightAttenuation( length( lVector ), spotLight.distance, spotLight.decay ) );\n return directLight;\n }\n#endif\n#if MAX_HEMI_LIGHTS > 0\n struct HemisphereLight {\n vec3 direction;\n vec3 skyColor;\n vec3 groundColor;\n };\n uniform HemisphereLight hemisphereLights[ MAX_HEMI_LIGHTS ];\n vec3 getHemisphereIndirectLightColor( const in HemisphereLight hemiLight, const in GeometricContext geometry ) { \n \n float dotNL = dot( geometry.normal, hemiLight.direction );\n float hemiDiffuseWeight = 0.5 * dotNL + 0.5;\n return mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );\n }\n#endif\n#if defined( USE_ENVMAP ) && defined( PHYSICAL )\n vec3 getSpecularLightProbeIndirectLightColor( const in GeometricContext geometry, const in float lodLevel ) { \n \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 #ifdef ENVMAP_TYPE_CUBE\n #if defined( TEXTURE_CUBE_LOD_EXT ) \n vec4 envMapColor = textureCubeLodEXT( envMap, flipNormal * vec3( flipEnvMap * reflectVec.x, reflectVec.yz ), lodLevel );\n #else\n vec4 envMapColor = textureCube( envMap, flipNormal * vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );\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 vec4 envMapColor = 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 envMapColor = texture2D( envMap, reflectView.xy * 0.5 + 0.5 );\n #endif\n envMapColor.rgb = inputToLinear( envMapColor.rgb );\n return envMapColor.rgb * reflectivity;\n }\n#endif\n";
  13532. // File:src/renderers/shaders/ShaderChunk/lightmap_pars_fragment.glsl
  13533. THREE.ShaderChunk[ 'lightmap_pars_fragment'] = "#ifdef USE_LIGHTMAP\n uniform sampler2D lightMap;\n uniform float lightMapIntensity;\n#endif";
  13534. // File:src/renderers/shaders/ShaderChunk/lights_lambert_vertex.glsl
  13535. THREE.ShaderChunk[ 'lights_lambert_vertex'] = "vec3 diffuse = vec3( 1.0 );\nGeometricContext geometry = GeometricContext( mvPosition.xyz, normalize( transformedNormal ), normalize( -mvPosition.xyz ) );\nGeometricContext backGeometry = GeometricContext( geometry.position, -geometry.normal, geometry.viewDir );\nvLightFront = vec3( 0.0 );\n#ifdef DOUBLE_SIDED\n vLightBack = vec3( 0.0 );\n#endif\n#if MAX_POINT_LIGHTS > 0\n for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {\n IncidentLight directLight = getPointDirectLight( pointLights[ i ], geometry );\n float dotNL = dot( geometry.normal, directLight.direction );\n vec3 directLightColor_Diffuse = directLight.color * BRDF_Diffuse_Lambert( diffuse );\n vLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n #ifdef DOUBLE_SIDED\n vLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n #endif\n }\n#endif\n#if MAX_SPOT_LIGHTS > 0\n for ( int i = 0; i < MAX_SPOT_LIGHTS; i ++ ) {\n IncidentLight directLight = getSpotDirectLight( spotLights[ i ], geometry );\n float dotNL = dot( geometry.normal, directLight.direction );\n vec3 directLightColor_Diffuse = directLight.color * BRDF_Diffuse_Lambert( diffuse );\n vLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n #ifdef DOUBLE_SIDED\n vLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n #endif\n }\n#endif\n#if MAX_DIR_LIGHTS > 0\n for ( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {\n IncidentLight directLight = getDirectionalDirectLight( directionalLights[ i ], geometry );\n float dotNL = dot( geometry.normal, directLight.direction );\n vec3 directLightColor_Diffuse = directLight.color * BRDF_Diffuse_Lambert( diffuse );\n vLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n #ifdef DOUBLE_SIDED\n vLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n #endif\n }\n#endif\n {\n vLightFront += ambientLightColor;\n #ifdef DOUBLE_SIDED\n vLightBack += ambientLightColor;\n #endif\n #if MAX_HEMI_LIGHTS > 0\n for ( int i = 0; i < MAX_HEMI_LIGHTS; i ++ ) {\n vLightFront += getHemisphereIndirectLightColor( hemisphereLights[ i ], geometry );\n #ifdef DOUBLE_SIDED\n vLightBack += getHemisphereIndirectLightColor( hemisphereLights[ i ], backGeometry );\n #endif\n }\n #endif\n }\n";
  13536. // File:src/renderers/shaders/ShaderChunk/lights_phong_fragment.glsl
  13537. THREE.ShaderChunk[ 'lights_phong_fragment'] = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;\n#ifdef METAL\n material.diffuseColor = vec3( 0.0 );\n#endif\n";
  13538. // File:src/renderers/shaders/ShaderChunk/lights_phong_pars_fragment.glsl
  13539. 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 BlinnPhongMaterial_RE_DirectLight( 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 reflectedLight.directDiffuse += dotNL * directLight.color * BRDF_Diffuse_Lambert( material.diffuseColor );\n reflectedLight.directSpecular += dotNL * directLight.color * BRDF_Specular_BlinnPhong( directLight, geometry, material.specularColor, material.specularShininess ) * material.specularStrength;\n}\n#define Material_RE_DirectLight BlinnPhongMaterial_RE_DirectLight\nvoid BlinnPhongMaterial_RE_IndirectDiffuseLight( const in vec3 indirectDiffuseColor, const in GeometricContext geometry, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n reflectedLight.indirectDiffuse += indirectDiffuseColor * BRDF_Diffuse_Lambert( material.diffuseColor );\n}\n#define Material_RE_IndirectDiffuseLight BlinnPhongMaterial_RE_IndirectDiffuseLight\n#define Material_LightProbeLOD( material ) (0)\n";
  13540. // File:src/renderers/shaders/ShaderChunk/lights_phong_pars_vertex.glsl
  13541. THREE.ShaderChunk[ 'lights_phong_pars_vertex'] = "#ifdef USE_ENVMAP\n varying vec3 vWorldPosition;\n#endif\n#if MAX_POINT_LIGHTS > 0\n uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];\n#endif\n";
  13542. // File:src/renderers/shaders/ShaderChunk/lights_phong_vertex.glsl
  13543. THREE.ShaderChunk[ 'lights_phong_vertex'] = "#ifdef USE_ENVMAP\n vWorldPosition = worldPosition.xyz;\n#endif\n";
  13544. // File:src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl
  13545. THREE.ShaderChunk[ 'lights_physical_fragment'] = "PhysicalMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );\nmaterial.specularRoughness = roughnessFactor * 0.5 + 0.5;material.specularColor = mix( vec3( 0.04 ), diffuseColor.rgb, metalnessFactor );\n";
  13546. // File:src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl
  13547. THREE.ShaderChunk[ 'lights_physical_pars_fragment'] = "struct PhysicalMaterial {\n vec3 diffuseColor;\n float specularRoughness;\n vec3 specularColor;\n float clearCoatWeight;\n float clearCoatRoughness;\n};\nvoid PhysicalMaterial_RE_DirectLight( const in IncidentLight directLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n float dotNL = saturate( dot( geometry.normal, directLight.direction ) );\n reflectedLight.directDiffuse += dotNL * directLight.color * BRDF_Diffuse_Lambert( material.diffuseColor );\n reflectedLight.directSpecular += dotNL * directLight.color * BRDF_Specular_GGX( directLight, geometry, material.specularColor, material.specularRoughness );\n \n}\n#define Material_RE_DirectLight PhysicalMaterial_RE_DirectLight\nvoid PhysicalMaterial_RE_DiffuseIndirectLight( const in vec3 indirectDiffuseColor, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n reflectedLight.indirectDiffuse += indirectDiffuseColor * BRDF_Diffuse_Lambert( material.diffuseColor );\n}\n#define Material_RE_IndirectDiffuseLight PhysicalMaterial_RE_DiffuseIndirectLight\nvoid PhysicalMaterial_RE_SpecularIndirectLight( const in vec3 indirectSpecularColor, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n reflectedLight.indirectSpecular += indirectSpecularColor * BRDF_Specular_GGX_Environment( geometry, material.specularColor, material.specularRoughness );\n}\n#define Material_LightProbeLOD( material ) (pow( ( material.specularRoughness - 0.5 ) * 2.0, 0.5 ) * 7.0)\n#define Material_RE_IndirectSpecularLight PhysicalMaterial_RE_SpecularIndirectLight\n";
  13548. // File:src/renderers/shaders/ShaderChunk/lights_template.glsl
  13549. THREE.ShaderChunk[ 'lights_template'] = "\nGeometricContext geometry = GeometricContext( -vViewPosition, normalize( normal ), normalize(vViewPosition ) );\n#if ( MAX_POINT_LIGHTS > 0 ) && defined( Material_RE_DirectLight )\n for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {\n IncidentLight directLight = getPointDirectLight( pointLights[ i ], geometry );\n Material_RE_DirectLight( directLight, geometry, material, reflectedLight );\n }\n#endif\n#if ( MAX_SPOT_LIGHTS > 0 ) && defined( Material_RE_DirectLight )\n for ( int i = 0; i < MAX_SPOT_LIGHTS; i ++ ) {\n IncidentLight directLight = getSpotDirectLight( spotLights[ i ], geometry );\n Material_RE_DirectLight( directLight, geometry, material, reflectedLight );\n }\n#endif\n#if ( MAX_DIR_LIGHTS > 0 ) && defined( Material_RE_DirectLight )\n for ( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {\n IncidentLight directLight = getDirectionalDirectLight( directionalLights[ i ], geometry );\n Material_RE_DirectLight( directLight, geometry, material, reflectedLight );\n \n }\n#endif\n#if defined( Material_RE_IndirectDiffuseLight )\n {\n \n vec3 indirectDiffuseColor = ambientLightColor;\n#ifdef USE_LIGHTMAP\n indirectDiffuseColor += texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n#endif\n#if ( MAX_HEMI_LIGHTS > 0 )\n for ( int i = 0; i < MAX_HEMI_LIGHTS; i ++ ) {\n indirectDiffuseColor += getHemisphereIndirectLightColor( hemisphereLights[ i ], geometry );\n }\n#endif\n Material_RE_IndirectDiffuseLight( indirectDiffuseColor, geometry, material, reflectedLight );\n }\n#endif\n#if defined( USE_ENVMAP ) && defined( Material_RE_IndirectSpecularLight )\n {\n vec3 indirectSpecularColor = getSpecularLightProbeIndirectLightColor( geometry, Material_LightProbeLOD( material ) );\n Material_RE_IndirectSpecularLight( indirectSpecularColor, geometry, material, reflectedLight );\n }\n#endif";
  13550. // File:src/renderers/shaders/ShaderChunk/linear_to_gamma_fragment.glsl
  13551. THREE.ShaderChunk[ 'linear_to_gamma_fragment'] = "\n outgoingLight = linearToOutput( outgoingLight );\n";
  13552. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl
  13553. THREE.ShaderChunk[ 'logdepthbuf_fragment'] = "#if defined(USE_LOGDEPTHBUF) && defined(USE_LOGDEPTHBUF_EXT)\n gl_FragDepthEXT = log2(vFragDepth) * logDepthBufFC * 0.5;\n#endif";
  13554. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl
  13555. 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";
  13556. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_pars_vertex.glsl
  13557. 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";
  13558. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl
  13559. 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";
  13560. // File:src/renderers/shaders/ShaderChunk/map_fragment.glsl
  13561. 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";
  13562. // File:src/renderers/shaders/ShaderChunk/map_pars_fragment.glsl
  13563. THREE.ShaderChunk[ 'map_pars_fragment'] = "#ifdef USE_MAP\n uniform sampler2D map;\n#endif";
  13564. // File:src/renderers/shaders/ShaderChunk/map_particle_fragment.glsl
  13565. 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";
  13566. // File:src/renderers/shaders/ShaderChunk/map_particle_pars_fragment.glsl
  13567. THREE.ShaderChunk[ 'map_particle_pars_fragment'] = "#ifdef USE_MAP\n uniform vec4 offsetRepeat;\n uniform sampler2D map;\n#endif\n";
  13568. // File:src/renderers/shaders/ShaderChunk/metalnessmap_fragment.glsl
  13569. THREE.ShaderChunk[ 'metalnessmap_fragment'] = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n vec4 texelMetalness = texture2D( metalnessMap, vUv );\n metalnessFactor = texelMetalness.r;\n#endif\n";
  13570. // File:src/renderers/shaders/ShaderChunk/metalnessmap_pars_fragment.glsl
  13571. THREE.ShaderChunk[ 'metalnessmap_pars_fragment'] = "#ifdef USE_METALNESSMAP\n uniform sampler2D metalnessMap;\n#endif";
  13572. // File:src/renderers/shaders/ShaderChunk/morphnormal_vertex.glsl
  13573. 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";
  13574. // File:src/renderers/shaders/ShaderChunk/morphtarget_pars_vertex.glsl
  13575. 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";
  13576. // File:src/renderers/shaders/ShaderChunk/morphtarget_vertex.glsl
  13577. 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";
  13578. // File:src/renderers/shaders/ShaderChunk/normal_phong_fragment.glsl
  13579. THREE.ShaderChunk[ 'normal_phong_fragment'] = "#ifndef FLAT_SHADED\n vec3 normal = normalize( vNormal );\n #ifdef DOUBLE_SIDED\n normal = normal * ( -1.0 + 2.0 * float( gl_FrontFacing ) );\n #endif\n#else\n vec3 fdx = dFdx( vViewPosition );\n vec3 fdy = dFdy( vViewPosition );\n vec3 normal = normalize( cross( fdx, fdy ) );\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";
  13580. // File:src/renderers/shaders/ShaderChunk/normalmap_pars_fragment.glsl
  13581. 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";
  13582. // File:src/renderers/shaders/ShaderChunk/project_vertex.glsl
  13583. 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";
  13584. // File:src/renderers/shaders/ShaderChunk/roughnessmap_fragment.glsl
  13585. THREE.ShaderChunk[ 'roughnessmap_fragment'] = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n vec4 texelRoughness = texture2D( roughnessMap, vUv );\n roughnessFactor *= texelRoughness.r;\n#endif\n";
  13586. // File:src/renderers/shaders/ShaderChunk/roughnessmap_pars_fragment.glsl
  13587. THREE.ShaderChunk[ 'roughnessmap_pars_fragment'] = "#ifdef USE_ROUGHNESSMAP\n uniform sampler2D roughnessMap;\n#endif";
  13588. // File:src/renderers/shaders/ShaderChunk/shadowmap_fragment.glsl
  13589. THREE.ShaderChunk[ 'shadowmap_fragment'] = "#ifdef USE_SHADOWMAP\n for ( int i = 0; i < MAX_SHADOWS; i ++ ) {\n float texelSizeY = 1.0 / shadowMapSize[ i ].y;\n float shadow = 0.0;\n#if defined( POINT_LIGHT_SHADOWS )\n bool isPointLight = shadowDarkness[ i ] < 0.0;\n if ( isPointLight ) {\n float realShadowDarkness = abs( shadowDarkness[ i ] );\n vec3 lightToPosition = vShadowCoord[ i ].xyz;\n #if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT )\n vec3 bd3D = normalize( lightToPosition );\n float dp = length( lightToPosition );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D, texelSizeY ) ), shadowBias[ i ], shadow );\n #if defined( SHADOWMAP_TYPE_PCF )\n const float Dr = 1.25;\n #elif defined( SHADOWMAP_TYPE_PCF_SOFT )\n const float Dr = 2.25;\n #endif\n float os = Dr * 2.0 * texelSizeY;\n const vec3 Gsd = vec3( - 1, 0, 1 );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.zzz * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.zxz * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.xxz * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.xzz * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.zzx * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.zxx * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.xxx * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.xzx * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.zzy * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.zxy * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.xxy * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.xzy * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.zyz * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.xyz * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.zyx * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.xyx * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.yzz * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.yxz * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.yxx * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.yzx * os, texelSizeY ) ), shadowBias[ i ], shadow );\n shadow *= realShadowDarkness * ( 1.0 / 21.0 );\n #else\n vec3 bd3D = normalize( lightToPosition );\n float dp = length( lightToPosition );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D, texelSizeY ) ), shadowBias[ i ], shadow );\n shadow *= realShadowDarkness;\n #endif\n } else {\n#endif\n float texelSizeX = 1.0 / shadowMapSize[ i ].x;\n vec3 shadowCoord = vShadowCoord[ i ].xyz / vShadowCoord[ i ].w;\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 shadowCoord.z += shadowBias[ i ];\n const float ShadowDelta = 1.0 / 9.0;\n float xPixelOffset = texelSizeX;\n float yPixelOffset = texelSizeY;\n float dx0 = - 1.25 * xPixelOffset;\n float dy0 = - 1.25 * yPixelOffset;\n float dx1 = 1.25 * xPixelOffset;\n float dy1 = 1.25 * yPixelOffset;\n float fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy0 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += ShadowDelta;\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy0 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += ShadowDelta;\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy0 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += ShadowDelta;\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, 0.0 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += ShadowDelta;\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy ) );\n if ( fDepth < shadowCoord.z ) shadow += ShadowDelta;\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, 0.0 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += ShadowDelta;\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy1 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += ShadowDelta;\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy1 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += ShadowDelta;\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy1 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += ShadowDelta;\n shadow *= shadowDarkness[ i ];\n #elif defined( SHADOWMAP_TYPE_PCF_SOFT )\n shadowCoord.z += shadowBias[ i ];\n float xPixelOffset = texelSizeX;\n float yPixelOffset = texelSizeY;\n float dx0 = - 1.0 * xPixelOffset;\n float dy0 = - 1.0 * yPixelOffset;\n float dx1 = 1.0 * xPixelOffset;\n float dy1 = 1.0 * yPixelOffset;\n mat3 shadowKernel;\n mat3 depthKernel;\n depthKernel[ 0 ][ 0 ] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy0 ) ) );\n depthKernel[ 0 ][ 1 ] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, 0.0 ) ) );\n depthKernel[ 0 ][ 2 ] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy1 ) ) );\n depthKernel[ 1 ][ 0 ] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy0 ) ) );\n depthKernel[ 1 ][ 1 ] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy ) );\n depthKernel[ 1 ][ 2 ] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy1 ) ) );\n depthKernel[ 2 ][ 0 ] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy0 ) ) );\n depthKernel[ 2 ][ 1 ] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, 0.0 ) ) );\n depthKernel[ 2 ][ 2 ] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy1 ) ) );\n vec3 shadowZ = vec3( shadowCoord.z );\n shadowKernel[ 0 ] = vec3( lessThan( depthKernel[ 0 ], shadowZ ) );\n shadowKernel[ 0 ] *= vec3( 0.25 );\n shadowKernel[ 1 ] = vec3( lessThan( depthKernel[ 1 ], shadowZ ) );\n shadowKernel[ 1 ] *= vec3( 0.25 );\n shadowKernel[ 2 ] = vec3( lessThan( depthKernel[ 2 ], shadowZ ) );\n shadowKernel[ 2 ] *= vec3( 0.25 );\n vec2 fractionalCoord = 1.0 - fract( shadowCoord.xy * shadowMapSize[ i ].xy );\n shadowKernel[ 0 ] = mix( shadowKernel[ 1 ], shadowKernel[ 0 ], fractionalCoord.x );\n shadowKernel[ 1 ] = mix( shadowKernel[ 2 ], shadowKernel[ 1 ], fractionalCoord.x );\n vec4 shadowValues;\n shadowValues.x = mix( shadowKernel[ 0 ][ 1 ], shadowKernel[ 0 ][ 0 ], fractionalCoord.y );\n shadowValues.y = mix( shadowKernel[ 0 ][ 2 ], shadowKernel[ 0 ][ 1 ], fractionalCoord.y );\n shadowValues.z = mix( shadowKernel[ 1 ][ 1 ], shadowKernel[ 1 ][ 0 ], fractionalCoord.y );\n shadowValues.w = mix( shadowKernel[ 1 ][ 2 ], shadowKernel[ 1 ][ 1 ], fractionalCoord.y );\n shadow = dot( shadowValues, vec4( 1.0 ) ) * shadowDarkness[ i ];\n #else\n shadowCoord.z += shadowBias[ i ];\n vec4 rgbaDepth = texture2D( shadowMap[ i ], shadowCoord.xy );\n float fDepth = unpackDepth( rgbaDepth );\n if ( fDepth < shadowCoord.z )\n shadow = shadowDarkness[ i ];\n #endif\n }\n#ifdef SHADOWMAP_DEBUG\n if ( inFrustum ) {\n if ( i == 0 ) {\n outgoingLight *= vec3( 1.0, 0.5, 0.0 );\n } else if ( i == 1 ) {\n outgoingLight *= vec3( 0.0, 1.0, 0.8 );\n } else {\n outgoingLight *= vec3( 0.0, 0.5, 1.0 );\n }\n }\n#endif\n#if defined( POINT_LIGHT_SHADOWS )\n }\n#endif\n shadowMask = shadowMask * vec3( 1.0 - shadow );\n }\n#endif\n";
  13590. // File:src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl
  13591. THREE.ShaderChunk[ 'shadowmap_pars_fragment'] = "#ifdef USE_SHADOWMAP\n uniform sampler2D shadowMap[ MAX_SHADOWS ];\n uniform vec2 shadowMapSize[ MAX_SHADOWS ];\n uniform float shadowDarkness[ MAX_SHADOWS ];\n uniform float shadowBias[ MAX_SHADOWS ];\n varying vec4 vShadowCoord[ MAX_SHADOWS ];\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 float depth = dot( rgba_depth, bit_shift );\n return depth;\n }\n #if defined(POINT_LIGHT_SHADOWS)\n void adjustShadowValue1K( const float testDepth, const vec4 textureData, const float bias, inout float shadowValue ) {\n const vec4 bitSh = vec4( 1.0 / ( 256.0 * 256.0 * 256.0 ), 1.0 / ( 256.0 * 256.0 ), 1.0 / 256.0, 1.0 );\n if ( testDepth >= dot( textureData, bitSh ) * 1000.0 + bias )\n shadowValue += 1.0;\n }\n 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 #endif\n#endif\n";
  13592. // File:src/renderers/shaders/ShaderChunk/shadowmap_pars_vertex.glsl
  13593. THREE.ShaderChunk[ 'shadowmap_pars_vertex'] = "#ifdef USE_SHADOWMAP\n uniform float shadowDarkness[ MAX_SHADOWS ];\n uniform mat4 shadowMatrix[ MAX_SHADOWS ];\n varying vec4 vShadowCoord[ MAX_SHADOWS ];\n#endif";
  13594. // File:src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl
  13595. THREE.ShaderChunk[ 'shadowmap_vertex'] = "#ifdef USE_SHADOWMAP\n for ( int i = 0; i < MAX_SHADOWS; i ++ ) {\n vShadowCoord[ i ] = shadowMatrix[ i ] * worldPosition;\n }\n#endif";
  13596. // File:src/renderers/shaders/ShaderChunk/skinbase_vertex.glsl
  13597. 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";
  13598. // File:src/renderers/shaders/ShaderChunk/skinning_pars_vertex.glsl
  13599. 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";
  13600. // File:src/renderers/shaders/ShaderChunk/skinning_vertex.glsl
  13601. 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";
  13602. // File:src/renderers/shaders/ShaderChunk/skinnormal_vertex.glsl
  13603. 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";
  13604. // File:src/renderers/shaders/ShaderChunk/specularmap_fragment.glsl
  13605. 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";
  13606. // File:src/renderers/shaders/ShaderChunk/specularmap_pars_fragment.glsl
  13607. THREE.ShaderChunk[ 'specularmap_pars_fragment'] = "#ifdef USE_SPECULARMAP\n uniform sampler2D specularMap;\n#endif";
  13608. // File:src/renderers/shaders/ShaderChunk/uv2_pars_fragment.glsl
  13609. THREE.ShaderChunk[ 'uv2_pars_fragment'] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n varying vec2 vUv2;\n#endif";
  13610. // File:src/renderers/shaders/ShaderChunk/uv2_pars_vertex.glsl
  13611. THREE.ShaderChunk[ 'uv2_pars_vertex'] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n attribute vec2 uv2;\n varying vec2 vUv2;\n#endif";
  13612. // File:src/renderers/shaders/ShaderChunk/uv2_vertex.glsl
  13613. THREE.ShaderChunk[ 'uv2_vertex'] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n vUv2 = uv2;\n#endif";
  13614. // File:src/renderers/shaders/ShaderChunk/uv_pars_fragment.glsl
  13615. 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_REFLECTIVITYMAP ) || defined( USE_METALNESSMAP )\n varying vec2 vUv;\n#endif";
  13616. // File:src/renderers/shaders/ShaderChunk/uv_pars_vertex.glsl
  13617. 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_REFLECTIVITYMAP ) || defined( USE_METALNESSMAP )\n varying vec2 vUv;\n uniform vec4 offsetRepeat;\n#endif\n";
  13618. // File:src/renderers/shaders/ShaderChunk/uv_vertex.glsl
  13619. 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_REFLECTIVITYMAP ) || defined( USE_METALNESSMAP )\n vUv = uv * offsetRepeat.zw + offsetRepeat.xy;\n#endif";
  13620. // File:src/renderers/shaders/ShaderChunk/worldpos_vertex.glsl
  13621. THREE.ShaderChunk[ 'worldpos_vertex'] = "#if defined( USE_ENVMAP ) || defined( PHONG ) || defined( PHYSICAL ) || 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";
  13622. // File:src/renderers/shaders/UniformsUtils.js
  13623. /**
  13624. * Uniform Utilities
  13625. */
  13626. THREE.UniformsUtils = {
  13627. merge: function ( uniforms ) {
  13628. var merged = {};
  13629. for ( var u = 0; u < uniforms.length; u ++ ) {
  13630. var tmp = this.clone( uniforms[ u ] );
  13631. for ( var p in tmp ) {
  13632. merged[ p ] = tmp[ p ];
  13633. }
  13634. }
  13635. return merged;
  13636. },
  13637. clone: function ( uniforms_src ) {
  13638. var uniforms_dst = {};
  13639. for ( var u in uniforms_src ) {
  13640. uniforms_dst[ u ] = {};
  13641. for ( var p in uniforms_src[ u ] ) {
  13642. var parameter_src = uniforms_src[ u ][ p ];
  13643. if ( parameter_src instanceof THREE.Color ||
  13644. parameter_src instanceof THREE.Vector2 ||
  13645. parameter_src instanceof THREE.Vector3 ||
  13646. parameter_src instanceof THREE.Vector4 ||
  13647. parameter_src instanceof THREE.Matrix3 ||
  13648. parameter_src instanceof THREE.Matrix4 ||
  13649. parameter_src instanceof THREE.Texture ) {
  13650. uniforms_dst[ u ][ p ] = parameter_src.clone();
  13651. } else if ( Array.isArray( parameter_src ) ) {
  13652. uniforms_dst[ u ][ p ] = parameter_src.slice();
  13653. } else {
  13654. uniforms_dst[ u ][ p ] = parameter_src;
  13655. }
  13656. }
  13657. }
  13658. return uniforms_dst;
  13659. }
  13660. };
  13661. // File:src/renderers/shaders/UniformsLib.js
  13662. /**
  13663. * Uniforms library for shared webgl shaders
  13664. */
  13665. THREE.UniformsLib = {
  13666. common: {
  13667. "diffuse" : { type: "c", value: new THREE.Color( 0xeeeeee ) },
  13668. "opacity" : { type: "f", value: 1.0 },
  13669. "map" : { type: "t", value: null },
  13670. "offsetRepeat" : { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) },
  13671. "specularMap" : { type: "t", value: null },
  13672. "alphaMap" : { type: "t", value: null },
  13673. "envMap" : { type: "t", value: null },
  13674. "flipEnvMap" : { type: "f", value: - 1 },
  13675. "reflectivity" : { type: "f", value: 1.0 },
  13676. "refractionRatio" : { type: "f", value: 0.98 }
  13677. },
  13678. aomap: {
  13679. "aoMap" : { type: "t", value: null },
  13680. "aoMapIntensity" : { type: "f", value: 1 },
  13681. },
  13682. lightmap: {
  13683. "lightMap" : { type: "t", value: null },
  13684. "lightMapIntensity" : { type: "f", value: 1 },
  13685. },
  13686. emissivemap: {
  13687. "emissiveMap" : { type: "t", value: null },
  13688. },
  13689. bumpmap: {
  13690. "bumpMap" : { type: "t", value: null },
  13691. "bumpScale" : { type: "f", value: 1 }
  13692. },
  13693. normalmap: {
  13694. "normalMap" : { type: "t", value: null },
  13695. "normalScale" : { type: "v2", value: new THREE.Vector2( 1, 1 ) }
  13696. },
  13697. displacementmap: {
  13698. "displacementMap" : { type: "t", value: null },
  13699. "displacementScale" : { type: "f", value: 1 },
  13700. "displacementBias" : { type: "f", value: 0 }
  13701. },
  13702. roughnessmap: {
  13703. "roughnessMap" : { type: "t", value: null }
  13704. },
  13705. reflectivitymap: {
  13706. "reflectivityMap" : { type: "t", value: null }
  13707. },
  13708. metalnessmap: {
  13709. "metalnessMap" : { type: "t", value: null }
  13710. },
  13711. fog : {
  13712. "fogDensity" : { type: "f", value: 0.00025 },
  13713. "fogNear" : { type: "f", value: 1 },
  13714. "fogFar" : { type: "f", value: 2000 },
  13715. "fogColor" : { type: "c", value: new THREE.Color( 0xffffff ) }
  13716. },
  13717. lights: {
  13718. "ambientLightColor" : { type: "fv", value: [] },
  13719. "directionalLights" : { type: "sa", value: [], properties: {
  13720. "direction": { type: "v3" },
  13721. "color": { type: "c" }
  13722. } },
  13723. "hemisphereLights" : { type: "sa", value: [], properties: {
  13724. "direction": { type: "v3" },
  13725. "skyColor": { type: "c" },
  13726. "groundColor": { type: "c" }
  13727. } },
  13728. "pointLights" : { type: "sa", value: [], properties: {
  13729. "color": { type: "c" },
  13730. "position": { type: "v3" },
  13731. "decay": { type: "f" },
  13732. "distance": { type: "f" }
  13733. } },
  13734. "spotLights" : { type: "sa", value: [], properties: {
  13735. "color": { type: "c" },
  13736. "position": { type: "v3" },
  13737. "direction": { type: "v3" },
  13738. "distance": { type: "f" },
  13739. "angleCos": { type: "f" },
  13740. "exponent": { type: "f" },
  13741. "decay": { type: "f" }
  13742. } }
  13743. },
  13744. points: {
  13745. "psColor" : { type: "c", value: new THREE.Color( 0xeeeeee ) },
  13746. "opacity" : { type: "f", value: 1.0 },
  13747. "size" : { type: "f", value: 1.0 },
  13748. "scale" : { type: "f", value: 1.0 },
  13749. "map" : { type: "t", value: null },
  13750. "offsetRepeat" : { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) },
  13751. "fogDensity" : { type: "f", value: 0.00025 },
  13752. "fogNear" : { type: "f", value: 1 },
  13753. "fogFar" : { type: "f", value: 2000 },
  13754. "fogColor" : { type: "c", value: new THREE.Color( 0xffffff ) }
  13755. },
  13756. shadowmap: {
  13757. "shadowMap": { type: "tv", value: [] },
  13758. "shadowMapSize": { type: "v2v", value: [] },
  13759. "shadowBias" : { type: "fv1", value: [] },
  13760. "shadowDarkness": { type: "fv1", value: [] },
  13761. "shadowMatrix" : { type: "m4v", value: [] }
  13762. }
  13763. };
  13764. // File:src/renderers/shaders/ShaderLib.js
  13765. /**
  13766. * Webgl Shader Library for three.js
  13767. *
  13768. * @author alteredq / http://alteredqualia.com/
  13769. * @author mrdoob / http://mrdoob.com/
  13770. * @author mikael emtinger / http://gomo.se/
  13771. */
  13772. THREE.ShaderLib = {
  13773. 'basic': {
  13774. uniforms: THREE.UniformsUtils.merge( [
  13775. THREE.UniformsLib[ "common" ],
  13776. THREE.UniformsLib[ "aomap" ],
  13777. THREE.UniformsLib[ "fog" ],
  13778. THREE.UniformsLib[ "shadowmap" ]
  13779. ] ),
  13780. vertexShader: [
  13781. THREE.ShaderChunk[ "common" ],
  13782. THREE.ShaderChunk[ "uv_pars_vertex" ],
  13783. THREE.ShaderChunk[ "uv2_pars_vertex" ],
  13784. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  13785. THREE.ShaderChunk[ "color_pars_vertex" ],
  13786. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  13787. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  13788. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  13789. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  13790. "void main() {",
  13791. THREE.ShaderChunk[ "uv_vertex" ],
  13792. THREE.ShaderChunk[ "uv2_vertex" ],
  13793. THREE.ShaderChunk[ "color_vertex" ],
  13794. THREE.ShaderChunk[ "skinbase_vertex" ],
  13795. " #ifdef USE_ENVMAP",
  13796. THREE.ShaderChunk[ "beginnormal_vertex" ],
  13797. THREE.ShaderChunk[ "morphnormal_vertex" ],
  13798. THREE.ShaderChunk[ "skinnormal_vertex" ],
  13799. THREE.ShaderChunk[ "defaultnormal_vertex" ],
  13800. " #endif",
  13801. THREE.ShaderChunk[ "begin_vertex" ],
  13802. THREE.ShaderChunk[ "morphtarget_vertex" ],
  13803. THREE.ShaderChunk[ "skinning_vertex" ],
  13804. THREE.ShaderChunk[ "project_vertex" ],
  13805. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  13806. THREE.ShaderChunk[ "worldpos_vertex" ],
  13807. THREE.ShaderChunk[ "envmap_vertex" ],
  13808. THREE.ShaderChunk[ "shadowmap_vertex" ],
  13809. "}"
  13810. ].join( "\n" ),
  13811. fragmentShader: [
  13812. "uniform vec3 diffuse;",
  13813. "uniform float opacity;",
  13814. "#ifndef FLAT_SHADED",
  13815. " varying vec3 vNormal;",
  13816. "#endif",
  13817. THREE.ShaderChunk[ "common" ],
  13818. THREE.ShaderChunk[ "color_pars_fragment" ],
  13819. THREE.ShaderChunk[ "uv_pars_fragment" ],
  13820. THREE.ShaderChunk[ "uv2_pars_fragment" ],
  13821. THREE.ShaderChunk[ "map_pars_fragment" ],
  13822. THREE.ShaderChunk[ "alphamap_pars_fragment" ],
  13823. THREE.ShaderChunk[ "aomap_pars_fragment" ],
  13824. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  13825. THREE.ShaderChunk[ "fog_pars_fragment" ],
  13826. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  13827. THREE.ShaderChunk[ "specularmap_pars_fragment" ],
  13828. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  13829. "void main() {",
  13830. " vec4 diffuseColor = vec4( diffuse, opacity );",
  13831. " vec3 shadowMask = vec3( 1.0 );",
  13832. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  13833. THREE.ShaderChunk[ "map_fragment" ],
  13834. THREE.ShaderChunk[ "color_fragment" ],
  13835. THREE.ShaderChunk[ "alphamap_fragment" ],
  13836. THREE.ShaderChunk[ "alphatest_fragment" ],
  13837. THREE.ShaderChunk[ "specularmap_fragment" ],
  13838. " ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), diffuseColor.rgb, vec3( 0.0 ) );",
  13839. THREE.ShaderChunk[ "aomap_fragment" ],
  13840. THREE.ShaderChunk[ "shadowmap_fragment" ],
  13841. "reflectedLight.indirectDiffuse *= shadowMask;",
  13842. "vec3 outgoingLight = reflectedLight.indirectDiffuse;",
  13843. THREE.ShaderChunk[ "envmap_fragment" ],
  13844. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  13845. THREE.ShaderChunk[ "fog_fragment" ],
  13846. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  13847. "}"
  13848. ].join( "\n" )
  13849. },
  13850. 'lambert': {
  13851. uniforms: THREE.UniformsUtils.merge( [
  13852. THREE.UniformsLib[ "common" ],
  13853. THREE.UniformsLib[ "fog" ],
  13854. THREE.UniformsLib[ "lights" ],
  13855. THREE.UniformsLib[ "shadowmap" ],
  13856. {
  13857. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) }
  13858. }
  13859. ] ),
  13860. vertexShader: [
  13861. "#define LAMBERT",
  13862. "varying vec3 vLightFront;",
  13863. "#ifdef DOUBLE_SIDED",
  13864. " varying vec3 vLightBack;",
  13865. "#endif",
  13866. THREE.ShaderChunk[ "common" ],
  13867. THREE.ShaderChunk[ "uv_pars_vertex" ],
  13868. THREE.ShaderChunk[ "uv2_pars_vertex" ],
  13869. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  13870. THREE.ShaderChunk[ "bsdfs" ],
  13871. THREE.ShaderChunk[ "lights_pars" ],
  13872. THREE.ShaderChunk[ "color_pars_vertex" ],
  13873. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  13874. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  13875. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  13876. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  13877. "void main() {",
  13878. THREE.ShaderChunk[ "uv_vertex" ],
  13879. THREE.ShaderChunk[ "uv2_vertex" ],
  13880. THREE.ShaderChunk[ "color_vertex" ],
  13881. THREE.ShaderChunk[ "beginnormal_vertex" ],
  13882. THREE.ShaderChunk[ "morphnormal_vertex" ],
  13883. THREE.ShaderChunk[ "skinbase_vertex" ],
  13884. THREE.ShaderChunk[ "skinnormal_vertex" ],
  13885. THREE.ShaderChunk[ "defaultnormal_vertex" ],
  13886. THREE.ShaderChunk[ "begin_vertex" ],
  13887. THREE.ShaderChunk[ "morphtarget_vertex" ],
  13888. THREE.ShaderChunk[ "skinning_vertex" ],
  13889. THREE.ShaderChunk[ "project_vertex" ],
  13890. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  13891. THREE.ShaderChunk[ "worldpos_vertex" ],
  13892. THREE.ShaderChunk[ "envmap_vertex" ],
  13893. THREE.ShaderChunk[ "lights_lambert_vertex" ],
  13894. THREE.ShaderChunk[ "shadowmap_vertex" ],
  13895. "}"
  13896. ].join( "\n" ),
  13897. fragmentShader: [
  13898. "uniform vec3 diffuse;",
  13899. "uniform vec3 emissive;",
  13900. "uniform float opacity;",
  13901. "uniform vec3 ambientLightColor;",
  13902. "varying vec3 vLightFront;",
  13903. "#ifdef DOUBLE_SIDED",
  13904. " varying vec3 vLightBack;",
  13905. "#endif",
  13906. THREE.ShaderChunk[ "common" ],
  13907. THREE.ShaderChunk[ "color_pars_fragment" ],
  13908. THREE.ShaderChunk[ "uv_pars_fragment" ],
  13909. THREE.ShaderChunk[ "uv2_pars_fragment" ],
  13910. THREE.ShaderChunk[ "map_pars_fragment" ],
  13911. THREE.ShaderChunk[ "alphamap_pars_fragment" ],
  13912. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  13913. THREE.ShaderChunk[ "fog_pars_fragment" ],
  13914. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  13915. THREE.ShaderChunk[ "specularmap_pars_fragment" ],
  13916. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  13917. "void main() {",
  13918. " vec3 outgoingLight = vec3( 0.0 );", // outgoing light does not have an alpha, the surface does
  13919. " vec4 diffuseColor = vec4( diffuse, opacity );",
  13920. " vec3 totalAmbientLight = ambientLightColor;",
  13921. " vec3 shadowMask = vec3( 1.0 );",
  13922. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  13923. THREE.ShaderChunk[ "map_fragment" ],
  13924. THREE.ShaderChunk[ "color_fragment" ],
  13925. THREE.ShaderChunk[ "alphamap_fragment" ],
  13926. THREE.ShaderChunk[ "alphatest_fragment" ],
  13927. THREE.ShaderChunk[ "specularmap_fragment" ],
  13928. THREE.ShaderChunk[ "shadowmap_fragment" ],
  13929. " #ifdef DOUBLE_SIDED",
  13930. " if ( gl_FrontFacing )",
  13931. " outgoingLight += diffuseColor.rgb * ( vLightFront * shadowMask ) + emissive;",
  13932. " else",
  13933. " outgoingLight += diffuseColor.rgb * ( vLightBack * shadowMask ) + emissive;",
  13934. " #else",
  13935. " outgoingLight += diffuseColor.rgb * ( vLightFront * shadowMask ) + emissive;",
  13936. " #endif",
  13937. THREE.ShaderChunk[ "envmap_fragment" ],
  13938. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  13939. THREE.ShaderChunk[ "fog_fragment" ],
  13940. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  13941. "}"
  13942. ].join( "\n" )
  13943. },
  13944. 'phong': {
  13945. uniforms: THREE.UniformsUtils.merge( [
  13946. THREE.UniformsLib[ "common" ],
  13947. THREE.UniformsLib[ "aomap" ],
  13948. THREE.UniformsLib[ "lightmap" ],
  13949. THREE.UniformsLib[ "emissivemap" ],
  13950. THREE.UniformsLib[ "bumpmap" ],
  13951. THREE.UniformsLib[ "normalmap" ],
  13952. THREE.UniformsLib[ "displacementmap" ],
  13953. THREE.UniformsLib[ "fog" ],
  13954. THREE.UniformsLib[ "lights" ],
  13955. THREE.UniformsLib[ "shadowmap" ],
  13956. {
  13957. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) },
  13958. "specular" : { type: "c", value: new THREE.Color( 0x111111 ) },
  13959. "shininess": { type: "f", value: 30 }
  13960. }
  13961. ] ),
  13962. vertexShader: [
  13963. "#define PHONG",
  13964. "varying vec3 vViewPosition;",
  13965. "#ifndef FLAT_SHADED",
  13966. " varying vec3 vNormal;",
  13967. "#endif",
  13968. THREE.ShaderChunk[ "common" ],
  13969. THREE.ShaderChunk[ "uv_pars_vertex" ],
  13970. THREE.ShaderChunk[ "uv2_pars_vertex" ],
  13971. THREE.ShaderChunk[ "displacementmap_pars_vertex" ],
  13972. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  13973. THREE.ShaderChunk[ "lights_phong_pars_vertex" ],
  13974. THREE.ShaderChunk[ "color_pars_vertex" ],
  13975. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  13976. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  13977. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  13978. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  13979. "void main() {",
  13980. THREE.ShaderChunk[ "uv_vertex" ],
  13981. THREE.ShaderChunk[ "uv2_vertex" ],
  13982. THREE.ShaderChunk[ "color_vertex" ],
  13983. THREE.ShaderChunk[ "beginnormal_vertex" ],
  13984. THREE.ShaderChunk[ "morphnormal_vertex" ],
  13985. THREE.ShaderChunk[ "skinbase_vertex" ],
  13986. THREE.ShaderChunk[ "skinnormal_vertex" ],
  13987. THREE.ShaderChunk[ "defaultnormal_vertex" ],
  13988. "#ifndef FLAT_SHADED", // Normal computed with derivatives when FLAT_SHADED
  13989. " vNormal = normalize( transformedNormal );",
  13990. "#endif",
  13991. THREE.ShaderChunk[ "begin_vertex" ],
  13992. THREE.ShaderChunk[ "displacementmap_vertex" ],
  13993. THREE.ShaderChunk[ "morphtarget_vertex" ],
  13994. THREE.ShaderChunk[ "skinning_vertex" ],
  13995. THREE.ShaderChunk[ "project_vertex" ],
  13996. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  13997. " vViewPosition = - mvPosition.xyz;",
  13998. THREE.ShaderChunk[ "worldpos_vertex" ],
  13999. THREE.ShaderChunk[ "envmap_vertex" ],
  14000. THREE.ShaderChunk[ "lights_phong_vertex" ],
  14001. THREE.ShaderChunk[ "shadowmap_vertex" ],
  14002. "}"
  14003. ].join( "\n" ),
  14004. fragmentShader: [
  14005. "#define PHONG",
  14006. "uniform vec3 diffuse;",
  14007. "uniform vec3 emissive;",
  14008. "uniform vec3 specular;",
  14009. "uniform float shininess;",
  14010. "uniform float opacity;",
  14011. THREE.ShaderChunk[ "common" ],
  14012. THREE.ShaderChunk[ "color_pars_fragment" ],
  14013. THREE.ShaderChunk[ "uv_pars_fragment" ],
  14014. THREE.ShaderChunk[ "uv2_pars_fragment" ],
  14015. THREE.ShaderChunk[ "map_pars_fragment" ],
  14016. THREE.ShaderChunk[ "alphamap_pars_fragment" ],
  14017. THREE.ShaderChunk[ "aomap_pars_fragment" ],
  14018. THREE.ShaderChunk[ "lightmap_pars_fragment" ],
  14019. THREE.ShaderChunk[ "emissivemap_pars_fragment" ],
  14020. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  14021. THREE.ShaderChunk[ "fog_pars_fragment" ],
  14022. THREE.ShaderChunk[ "bsdfs" ],
  14023. THREE.ShaderChunk[ "lights_pars" ],
  14024. THREE.ShaderChunk[ "lights_phong_pars_fragment" ],
  14025. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  14026. THREE.ShaderChunk[ "bumpmap_pars_fragment" ],
  14027. THREE.ShaderChunk[ "normalmap_pars_fragment" ],
  14028. THREE.ShaderChunk[ "specularmap_pars_fragment" ],
  14029. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  14030. "void main() {",
  14031. " vec4 diffuseColor = vec4( diffuse, opacity );",
  14032. " ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );",
  14033. " vec3 totalEmissiveLight = emissive;",
  14034. " vec3 shadowMask = vec3( 1.0 );",
  14035. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  14036. THREE.ShaderChunk[ "map_fragment" ],
  14037. THREE.ShaderChunk[ "color_fragment" ],
  14038. THREE.ShaderChunk[ "alphamap_fragment" ],
  14039. THREE.ShaderChunk[ "alphatest_fragment" ],
  14040. THREE.ShaderChunk[ "specularmap_fragment" ],
  14041. THREE.ShaderChunk[ "normal_phong_fragment" ],
  14042. THREE.ShaderChunk[ "emissivemap_fragment" ],
  14043. // accumulation
  14044. THREE.ShaderChunk[ "lights_phong_fragment" ],
  14045. THREE.ShaderChunk[ "lights_template" ],
  14046. THREE.ShaderChunk[ "lightmap_fragment" ],
  14047. // modulation
  14048. THREE.ShaderChunk[ "aomap_fragment" ],
  14049. THREE.ShaderChunk[ "shadowmap_fragment" ],
  14050. "reflectedLight.directDiffuse *= shadowMask;",
  14051. "reflectedLight.directSpecular *= shadowMask;",
  14052. "#ifdef METAL",
  14053. " vec3 outgoingLight = ( reflectedLight.directDiffuse + reflectedLight.indirectDiffuse ) * specular + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveLight;",
  14054. "#else",
  14055. " vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveLight;",
  14056. "#endif",
  14057. THREE.ShaderChunk[ "envmap_fragment" ],
  14058. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  14059. THREE.ShaderChunk[ "fog_fragment" ],
  14060. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  14061. "}"
  14062. ].join( "\n" )
  14063. },
  14064. 'physical': {
  14065. uniforms: THREE.UniformsUtils.merge( [
  14066. THREE.UniformsLib[ "common" ],
  14067. THREE.UniformsLib[ "aomap" ],
  14068. THREE.UniformsLib[ "lightmap" ],
  14069. THREE.UniformsLib[ "emissivemap" ],
  14070. THREE.UniformsLib[ "bumpmap" ],
  14071. THREE.UniformsLib[ "normalmap" ],
  14072. THREE.UniformsLib[ "displacementmap" ],
  14073. THREE.UniformsLib[ "roughnessmap" ],
  14074. THREE.UniformsLib[ "reflectivitymap" ],
  14075. THREE.UniformsLib[ "metalnessmap" ],
  14076. THREE.UniformsLib[ "fog" ],
  14077. THREE.UniformsLib[ "lights" ],
  14078. THREE.UniformsLib[ "shadowmap" ],
  14079. {
  14080. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) },
  14081. "roughness": { type: "f", value: 0.5 },
  14082. "metalness": { type: "f", value: 0 },
  14083. "envMapIntensity" : { type: "f", value: 1 } // temporary
  14084. }
  14085. ] ),
  14086. vertexShader: [
  14087. "#define PHYSICAL",
  14088. "varying vec3 vViewPosition;",
  14089. "#ifndef FLAT_SHADED",
  14090. " varying vec3 vNormal;",
  14091. "#endif",
  14092. THREE.ShaderChunk[ "common" ],
  14093. THREE.ShaderChunk[ "uv_pars_vertex" ],
  14094. THREE.ShaderChunk[ "uv2_pars_vertex" ],
  14095. THREE.ShaderChunk[ "displacementmap_pars_vertex" ],
  14096. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  14097. THREE.ShaderChunk[ "lights_phong_pars_vertex" ], // use phong chunk for now
  14098. THREE.ShaderChunk[ "color_pars_vertex" ],
  14099. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  14100. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  14101. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  14102. THREE.ShaderChunk[ "specularmap_pars_fragment" ],
  14103. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  14104. "void main() {", // PHYSICAL
  14105. THREE.ShaderChunk[ "uv_vertex" ],
  14106. THREE.ShaderChunk[ "uv2_vertex" ],
  14107. THREE.ShaderChunk[ "color_vertex" ],
  14108. THREE.ShaderChunk[ "beginnormal_vertex" ],
  14109. THREE.ShaderChunk[ "morphnormal_vertex" ],
  14110. THREE.ShaderChunk[ "skinbase_vertex" ],
  14111. THREE.ShaderChunk[ "skinnormal_vertex" ],
  14112. THREE.ShaderChunk[ "defaultnormal_vertex" ],
  14113. "#ifndef FLAT_SHADED", // Normal computed with derivatives when FLAT_SHADED
  14114. " vNormal = normalize( transformedNormal );",
  14115. "#endif",
  14116. THREE.ShaderChunk[ "begin_vertex" ],
  14117. THREE.ShaderChunk[ "displacementmap_vertex" ],
  14118. THREE.ShaderChunk[ "morphtarget_vertex" ],
  14119. THREE.ShaderChunk[ "skinning_vertex" ],
  14120. THREE.ShaderChunk[ "project_vertex" ],
  14121. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  14122. " vViewPosition = - mvPosition.xyz;",
  14123. THREE.ShaderChunk[ "worldpos_vertex" ],
  14124. THREE.ShaderChunk[ "envmap_vertex" ],
  14125. THREE.ShaderChunk[ "lights_phong_vertex" ], // use phong chunk for now
  14126. THREE.ShaderChunk[ "shadowmap_vertex" ],
  14127. "}"
  14128. ].join( "\n" ),
  14129. fragmentShader: [
  14130. "#define PHYSICAL",
  14131. "uniform vec3 diffuse;",
  14132. "uniform vec3 emissive;",
  14133. "uniform float roughness;",
  14134. "uniform float metalness;",
  14135. "uniform float opacity;",
  14136. "uniform float envMapIntensity;", // temporary
  14137. "varying vec3 vViewPosition;",
  14138. "#ifndef FLAT_SHADED",
  14139. " varying vec3 vNormal;",
  14140. "#endif",
  14141. THREE.ShaderChunk[ "common" ],
  14142. THREE.ShaderChunk[ "color_pars_fragment" ],
  14143. THREE.ShaderChunk[ "uv_pars_fragment" ],
  14144. THREE.ShaderChunk[ "uv2_pars_fragment" ],
  14145. THREE.ShaderChunk[ "map_pars_fragment" ],
  14146. THREE.ShaderChunk[ "alphamap_pars_fragment" ],
  14147. THREE.ShaderChunk[ "aomap_pars_fragment" ],
  14148. THREE.ShaderChunk[ "lightmap_pars_fragment" ],
  14149. THREE.ShaderChunk[ "emissivemap_pars_fragment" ],
  14150. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  14151. THREE.ShaderChunk[ "fog_pars_fragment" ],
  14152. THREE.ShaderChunk[ "bsdfs" ],
  14153. THREE.ShaderChunk[ "lights_pars" ],
  14154. THREE.ShaderChunk[ "lights_physical_pars_fragment" ],
  14155. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  14156. THREE.ShaderChunk[ "bumpmap_pars_fragment" ],
  14157. THREE.ShaderChunk[ "normalmap_pars_fragment" ],
  14158. THREE.ShaderChunk[ "roughnessmap_pars_fragment" ],
  14159. //THREE.ShaderChunk[ "reflectivitymap_pars_fragment" ],
  14160. THREE.ShaderChunk[ "metalnessmap_pars_fragment" ],
  14161. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  14162. "void main() {",
  14163. " vec4 diffuseColor = vec4( diffuse, opacity );",
  14164. " ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );",
  14165. " vec3 totalEmissiveLight = emissive;",
  14166. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  14167. THREE.ShaderChunk[ "map_fragment" ],
  14168. THREE.ShaderChunk[ "color_fragment" ],
  14169. THREE.ShaderChunk[ "alphamap_fragment" ],
  14170. THREE.ShaderChunk[ "alphatest_fragment" ],
  14171. THREE.ShaderChunk[ "specularmap_fragment" ],
  14172. THREE.ShaderChunk[ "roughnessmap_fragment" ],
  14173. //THREE.ShaderChunk[ "reflectivitymap_fragment" ],
  14174. THREE.ShaderChunk[ "metalnessmap_fragment" ],
  14175. THREE.ShaderChunk[ "normal_phong_fragment" ], // use phong chunk for now
  14176. THREE.ShaderChunk[ "emissivemap_fragment" ],
  14177. // accumulation
  14178. THREE.ShaderChunk[ "lights_physical_fragment" ],
  14179. THREE.ShaderChunk[ "lights_template" ],
  14180. THREE.ShaderChunk[ "lightmap_fragment" ],
  14181. THREE.ShaderChunk[ "envmap_physical_fragment" ],
  14182. // modulation
  14183. THREE.ShaderChunk[ "aomap_fragment" ],
  14184. "vec3 shadowMask = vec3( 1.0 );",
  14185. THREE.ShaderChunk[ "shadowmap_fragment" ],
  14186. "reflectedLight.directDiffuse *= shadowMask;",
  14187. "reflectedLight.directSpecular *= shadowMask;",
  14188. "vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveLight;",
  14189. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  14190. THREE.ShaderChunk[ "fog_fragment" ],
  14191. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  14192. "}"
  14193. ].join( "\n" )
  14194. },
  14195. 'points': {
  14196. uniforms: THREE.UniformsUtils.merge( [
  14197. THREE.UniformsLib[ "points" ],
  14198. THREE.UniformsLib[ "shadowmap" ]
  14199. ] ),
  14200. vertexShader: [
  14201. "uniform float size;",
  14202. "uniform float scale;",
  14203. THREE.ShaderChunk[ "common" ],
  14204. THREE.ShaderChunk[ "color_pars_vertex" ],
  14205. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  14206. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  14207. "void main() {",
  14208. THREE.ShaderChunk[ "color_vertex" ],
  14209. " vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
  14210. " #ifdef USE_SIZEATTENUATION",
  14211. " gl_PointSize = size * ( scale / -mvPosition.z );",
  14212. " #else",
  14213. " gl_PointSize = size;",
  14214. " #endif",
  14215. " gl_Position = projectionMatrix * mvPosition;",
  14216. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  14217. THREE.ShaderChunk[ "worldpos_vertex" ],
  14218. THREE.ShaderChunk[ "shadowmap_vertex" ],
  14219. "}"
  14220. ].join( "\n" ),
  14221. fragmentShader: [
  14222. "uniform vec3 psColor;",
  14223. "uniform float opacity;",
  14224. THREE.ShaderChunk[ "common" ],
  14225. THREE.ShaderChunk[ "color_pars_fragment" ],
  14226. THREE.ShaderChunk[ "map_particle_pars_fragment" ],
  14227. THREE.ShaderChunk[ "fog_pars_fragment" ],
  14228. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  14229. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  14230. "void main() {",
  14231. " vec3 outgoingLight = vec3( 0.0 );",
  14232. " vec4 diffuseColor = vec4( psColor, opacity );",
  14233. " vec3 shadowMask = vec3( 1.0 );",
  14234. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  14235. THREE.ShaderChunk[ "map_particle_fragment" ],
  14236. THREE.ShaderChunk[ "color_fragment" ],
  14237. THREE.ShaderChunk[ "alphatest_fragment" ],
  14238. THREE.ShaderChunk[ "shadowmap_fragment" ],
  14239. " outgoingLight = diffuseColor.rgb * shadowMask;",
  14240. THREE.ShaderChunk[ "fog_fragment" ],
  14241. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  14242. "}"
  14243. ].join( "\n" )
  14244. },
  14245. 'dashed': {
  14246. uniforms: THREE.UniformsUtils.merge( [
  14247. THREE.UniformsLib[ "common" ],
  14248. THREE.UniformsLib[ "fog" ],
  14249. {
  14250. "scale" : { type: "f", value: 1 },
  14251. "dashSize" : { type: "f", value: 1 },
  14252. "totalSize": { type: "f", value: 2 }
  14253. }
  14254. ] ),
  14255. vertexShader: [
  14256. "uniform float scale;",
  14257. "attribute float lineDistance;",
  14258. "varying float vLineDistance;",
  14259. THREE.ShaderChunk[ "common" ],
  14260. THREE.ShaderChunk[ "color_pars_vertex" ],
  14261. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  14262. "void main() {",
  14263. THREE.ShaderChunk[ "color_vertex" ],
  14264. " vLineDistance = scale * lineDistance;",
  14265. " vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
  14266. " gl_Position = projectionMatrix * mvPosition;",
  14267. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  14268. "}"
  14269. ].join( "\n" ),
  14270. fragmentShader: [
  14271. "uniform vec3 diffuse;",
  14272. "uniform float opacity;",
  14273. "uniform float dashSize;",
  14274. "uniform float totalSize;",
  14275. "varying float vLineDistance;",
  14276. THREE.ShaderChunk[ "common" ],
  14277. THREE.ShaderChunk[ "color_pars_fragment" ],
  14278. THREE.ShaderChunk[ "fog_pars_fragment" ],
  14279. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  14280. "void main() {",
  14281. " if ( mod( vLineDistance, totalSize ) > dashSize ) {",
  14282. " discard;",
  14283. " }",
  14284. " vec3 outgoingLight = vec3( 0.0 );",
  14285. " vec4 diffuseColor = vec4( diffuse, opacity );",
  14286. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  14287. THREE.ShaderChunk[ "color_fragment" ],
  14288. " outgoingLight = diffuseColor.rgb;", // simple shader
  14289. THREE.ShaderChunk[ "fog_fragment" ],
  14290. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  14291. "}"
  14292. ].join( "\n" )
  14293. },
  14294. 'depth': {
  14295. uniforms: {
  14296. "mNear": { type: "f", value: 1.0 },
  14297. "mFar" : { type: "f", value: 2000.0 },
  14298. "opacity" : { type: "f", value: 1.0 }
  14299. },
  14300. vertexShader: [
  14301. THREE.ShaderChunk[ "common" ],
  14302. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  14303. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  14304. "void main() {",
  14305. THREE.ShaderChunk[ "begin_vertex" ],
  14306. THREE.ShaderChunk[ "morphtarget_vertex" ],
  14307. THREE.ShaderChunk[ "project_vertex" ],
  14308. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  14309. "}"
  14310. ].join( "\n" ),
  14311. fragmentShader: [
  14312. "uniform float mNear;",
  14313. "uniform float mFar;",
  14314. "uniform float opacity;",
  14315. THREE.ShaderChunk[ "common" ],
  14316. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  14317. "void main() {",
  14318. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  14319. " #ifdef USE_LOGDEPTHBUF_EXT",
  14320. " float depth = gl_FragDepthEXT / gl_FragCoord.w;",
  14321. " #else",
  14322. " float depth = gl_FragCoord.z / gl_FragCoord.w;",
  14323. " #endif",
  14324. " float color = 1.0 - smoothstep( mNear, mFar, depth );",
  14325. " gl_FragColor = vec4( vec3( color ), opacity );",
  14326. "}"
  14327. ].join( "\n" )
  14328. },
  14329. 'normal': {
  14330. uniforms: {
  14331. "opacity" : { type: "f", value: 1.0 }
  14332. },
  14333. vertexShader: [
  14334. "varying vec3 vNormal;",
  14335. THREE.ShaderChunk[ "common" ],
  14336. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  14337. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  14338. "void main() {",
  14339. " vNormal = normalize( normalMatrix * normal );",
  14340. THREE.ShaderChunk[ "begin_vertex" ],
  14341. THREE.ShaderChunk[ "morphtarget_vertex" ],
  14342. THREE.ShaderChunk[ "project_vertex" ],
  14343. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  14344. "}"
  14345. ].join( "\n" ),
  14346. fragmentShader: [
  14347. "uniform float opacity;",
  14348. "varying vec3 vNormal;",
  14349. THREE.ShaderChunk[ "common" ],
  14350. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  14351. "void main() {",
  14352. " gl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, opacity );",
  14353. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  14354. "}"
  14355. ].join( "\n" )
  14356. },
  14357. /* -------------------------------------------------------------------------
  14358. // Cube map shader
  14359. ------------------------------------------------------------------------- */
  14360. 'cube': {
  14361. uniforms: { "tCube": { type: "t", value: null },
  14362. "tFlip": { type: "f", value: - 1 } },
  14363. vertexShader: [
  14364. "varying vec3 vWorldPosition;",
  14365. THREE.ShaderChunk[ "common" ],
  14366. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  14367. "void main() {",
  14368. " vWorldPosition = transformDirection( position, modelMatrix );",
  14369. " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  14370. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  14371. "}"
  14372. ].join( "\n" ),
  14373. fragmentShader: [
  14374. "uniform samplerCube tCube;",
  14375. "uniform float tFlip;",
  14376. "varying vec3 vWorldPosition;",
  14377. THREE.ShaderChunk[ "common" ],
  14378. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  14379. "void main() {",
  14380. " gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );",
  14381. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  14382. "}"
  14383. ].join( "\n" )
  14384. },
  14385. /* -------------------------------------------------------------------------
  14386. // Cube map shader
  14387. ------------------------------------------------------------------------- */
  14388. 'equirect': {
  14389. uniforms: { "tEquirect": { type: "t", value: null },
  14390. "tFlip": { type: "f", value: - 1 } },
  14391. vertexShader: [
  14392. "varying vec3 vWorldPosition;",
  14393. THREE.ShaderChunk[ "common" ],
  14394. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  14395. "void main() {",
  14396. " vWorldPosition = transformDirection( position, modelMatrix );",
  14397. " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  14398. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  14399. "}"
  14400. ].join( "\n" ),
  14401. fragmentShader: [
  14402. "uniform sampler2D tEquirect;",
  14403. "uniform float tFlip;",
  14404. "varying vec3 vWorldPosition;",
  14405. THREE.ShaderChunk[ "common" ],
  14406. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  14407. "void main() {",
  14408. // " gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );",
  14409. "vec3 direction = normalize( vWorldPosition );",
  14410. "vec2 sampleUV;",
  14411. "sampleUV.y = saturate( tFlip * direction.y * -0.5 + 0.5 );",
  14412. "sampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;",
  14413. "gl_FragColor = texture2D( tEquirect, sampleUV );",
  14414. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  14415. "}"
  14416. ].join( "\n" )
  14417. },
  14418. /* Depth encoding into RGBA texture
  14419. *
  14420. * based on SpiderGL shadow map example
  14421. * http://spidergl.org/example.php?id=6
  14422. *
  14423. * originally from
  14424. * http://www.gamedev.net/topic/442138-packing-a-float-into-a-a8r8g8b8-texture-shader/page__whichpage__1%25EF%25BF%25BD
  14425. *
  14426. * see also
  14427. * http://aras-p.info/blog/2009/07/30/encoding-floats-to-rgba-the-final/
  14428. */
  14429. 'depthRGBA': {
  14430. uniforms: {},
  14431. vertexShader: [
  14432. THREE.ShaderChunk[ "common" ],
  14433. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  14434. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  14435. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  14436. "void main() {",
  14437. THREE.ShaderChunk[ "skinbase_vertex" ],
  14438. THREE.ShaderChunk[ "begin_vertex" ],
  14439. THREE.ShaderChunk[ "morphtarget_vertex" ],
  14440. THREE.ShaderChunk[ "skinning_vertex" ],
  14441. THREE.ShaderChunk[ "project_vertex" ],
  14442. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  14443. "}"
  14444. ].join( "\n" ),
  14445. fragmentShader: [
  14446. THREE.ShaderChunk[ "common" ],
  14447. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  14448. "vec4 pack_depth( const in float depth ) {",
  14449. " const vec4 bit_shift = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );",
  14450. " const vec4 bit_mask = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );",
  14451. " vec4 res = mod( depth * bit_shift * vec4( 255 ), vec4( 256 ) ) / vec4( 255 );", // " vec4 res = fract( depth * bit_shift );",
  14452. " res -= res.xxyz * bit_mask;",
  14453. " return res;",
  14454. "}",
  14455. "void main() {",
  14456. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  14457. " #ifdef USE_LOGDEPTHBUF_EXT",
  14458. " gl_FragData[ 0 ] = pack_depth( gl_FragDepthEXT );",
  14459. " #else",
  14460. " gl_FragData[ 0 ] = pack_depth( gl_FragCoord.z );",
  14461. " #endif",
  14462. //"gl_FragData[ 0 ] = pack_depth( gl_FragCoord.z / gl_FragCoord.w );",
  14463. //"float z = ( ( gl_FragCoord.z / gl_FragCoord.w ) - 3.0 ) / ( 4000.0 - 3.0 );",
  14464. //"gl_FragData[ 0 ] = pack_depth( z );",
  14465. //"gl_FragData[ 0 ] = vec4( z, z, z, 1.0 );",
  14466. "}"
  14467. ].join( "\n" )
  14468. },
  14469. 'distanceRGBA': {
  14470. uniforms: {
  14471. "lightPos": { type: "v3", value: new THREE.Vector3( 0, 0, 0 ) }
  14472. },
  14473. vertexShader: [
  14474. "varying vec4 vWorldPosition;",
  14475. THREE.ShaderChunk[ "common" ],
  14476. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  14477. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  14478. "void main() {",
  14479. THREE.ShaderChunk[ "skinbase_vertex" ],
  14480. THREE.ShaderChunk[ "begin_vertex" ],
  14481. THREE.ShaderChunk[ "morphtarget_vertex" ],
  14482. THREE.ShaderChunk[ "skinning_vertex" ],
  14483. THREE.ShaderChunk[ "project_vertex" ],
  14484. THREE.ShaderChunk[ "worldpos_vertex" ],
  14485. "vWorldPosition = worldPosition;",
  14486. "}"
  14487. ].join( "\n" ),
  14488. fragmentShader: [
  14489. "uniform vec3 lightPos;",
  14490. "varying vec4 vWorldPosition;",
  14491. THREE.ShaderChunk[ "common" ],
  14492. "vec4 pack1K ( float depth ) {",
  14493. " depth /= 1000.0;",
  14494. " const vec4 bitSh = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );",
  14495. " const vec4 bitMsk = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );",
  14496. " vec4 res = fract( depth * bitSh );",
  14497. " res -= res.xxyz * bitMsk;",
  14498. " return res; ",
  14499. "}",
  14500. "float unpack1K ( vec4 color ) {",
  14501. " const vec4 bitSh = vec4( 1.0 / ( 256.0 * 256.0 * 256.0 ), 1.0 / ( 256.0 * 256.0 ), 1.0 / 256.0, 1.0 );",
  14502. " return dot( color, bitSh ) * 1000.0;",
  14503. "}",
  14504. "void main () {",
  14505. " gl_FragColor = pack1K( length( vWorldPosition.xyz - lightPos.xyz ) );",
  14506. "}"
  14507. ].join( "\n" )
  14508. }
  14509. };
  14510. // File:src/renderers/WebGLRenderer.js
  14511. /**
  14512. * @author supereggbert / http://www.paulbrunt.co.uk/
  14513. * @author mrdoob / http://mrdoob.com/
  14514. * @author alteredq / http://alteredqualia.com/
  14515. * @author szimek / https://github.com/szimek/
  14516. */
  14517. THREE.WebGLRenderer = function ( parameters ) {
  14518. console.log( 'THREE.WebGLRenderer', THREE.REVISION );
  14519. parameters = parameters || {};
  14520. var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElement( 'canvas' ),
  14521. _context = parameters.context !== undefined ? parameters.context : null,
  14522. _width = _canvas.width,
  14523. _height = _canvas.height,
  14524. pixelRatio = 1,
  14525. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  14526. _depth = parameters.depth !== undefined ? parameters.depth : true,
  14527. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  14528. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  14529. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  14530. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  14531. _clearColor = new THREE.Color( 0x000000 ),
  14532. _clearAlpha = 0;
  14533. var lights = [];
  14534. var opaqueObjects = [];
  14535. var opaqueObjectsLastIndex = - 1;
  14536. var transparentObjects = [];
  14537. var transparentObjectsLastIndex = - 1;
  14538. var morphInfluences = new Float32Array( 8 );
  14539. var sprites = [];
  14540. var lensFlares = [];
  14541. // public properties
  14542. this.domElement = _canvas;
  14543. this.context = null;
  14544. // clearing
  14545. this.autoClear = true;
  14546. this.autoClearColor = true;
  14547. this.autoClearDepth = true;
  14548. this.autoClearStencil = true;
  14549. // scene graph
  14550. this.sortObjects = true;
  14551. // physically based shading
  14552. this.gammaFactor = 2.0; // for backwards compatibility
  14553. this.gammaInput = false;
  14554. this.gammaOutput = false;
  14555. // morphs
  14556. this.maxMorphTargets = 8;
  14557. this.maxMorphNormals = 4;
  14558. // flags
  14559. this.autoScaleCubemaps = true;
  14560. // internal properties
  14561. var _this = this,
  14562. // internal state cache
  14563. _currentProgram = null,
  14564. _currentFramebuffer = null,
  14565. _currentMaterialId = - 1,
  14566. _currentGeometryProgram = '',
  14567. _currentCamera = null,
  14568. _usedTextureUnits = 0,
  14569. _viewportX = 0,
  14570. _viewportY = 0,
  14571. _viewportWidth = _canvas.width,
  14572. _viewportHeight = _canvas.height,
  14573. _currentWidth = 0,
  14574. _currentHeight = 0,
  14575. // frustum
  14576. _frustum = new THREE.Frustum(),
  14577. // camera matrices cache
  14578. _projScreenMatrix = new THREE.Matrix4(),
  14579. _vector3 = new THREE.Vector3(),
  14580. // light arrays cache
  14581. _lights = {
  14582. ambient: [ 0, 0, 0 ],
  14583. directional: [],
  14584. point: [],
  14585. spot: [],
  14586. hemi: []
  14587. },
  14588. _lightsNeedUpdate = true,
  14589. // info
  14590. _infoMemory = {
  14591. geometries: 0,
  14592. textures: 0
  14593. },
  14594. _infoRender = {
  14595. calls: 0,
  14596. vertices: 0,
  14597. faces: 0,
  14598. points: 0
  14599. };
  14600. this.info = {
  14601. render: _infoRender,
  14602. memory: _infoMemory,
  14603. programs: null
  14604. };
  14605. // initialize
  14606. var _gl;
  14607. try {
  14608. var attributes = {
  14609. alpha: _alpha,
  14610. depth: _depth,
  14611. stencil: _stencil,
  14612. antialias: _antialias,
  14613. premultipliedAlpha: _premultipliedAlpha,
  14614. preserveDrawingBuffer: _preserveDrawingBuffer
  14615. };
  14616. _gl = _context || _canvas.getContext( 'webgl', attributes ) || _canvas.getContext( 'experimental-webgl', attributes );
  14617. if ( _gl === null ) {
  14618. if ( _canvas.getContext( 'webgl' ) !== null ) {
  14619. throw 'Error creating WebGL context with your selected attributes.';
  14620. } else {
  14621. throw 'Error creating WebGL context.';
  14622. }
  14623. }
  14624. _canvas.addEventListener( 'webglcontextlost', onContextLost, false );
  14625. } catch ( error ) {
  14626. console.error( 'THREE.WebGLRenderer: ' + error );
  14627. }
  14628. var extensions = new THREE.WebGLExtensions( _gl );
  14629. extensions.get( 'OES_texture_float' );
  14630. extensions.get( 'OES_texture_float_linear' );
  14631. extensions.get( 'OES_texture_half_float' );
  14632. extensions.get( 'OES_texture_half_float_linear' );
  14633. extensions.get( 'OES_standard_derivatives' );
  14634. extensions.get( 'ANGLE_instanced_arrays' );
  14635. if ( extensions.get( 'OES_element_index_uint' ) ) {
  14636. THREE.BufferGeometry.MaxIndex = 4294967296;
  14637. }
  14638. var capabilities = new THREE.WebGLCapabilities( _gl, extensions, parameters );
  14639. var state = new THREE.WebGLState( _gl, extensions, paramThreeToGL );
  14640. var properties = new THREE.WebGLProperties();
  14641. var objects = new THREE.WebGLObjects( _gl, properties, this.info );
  14642. var programCache = new THREE.WebGLPrograms( this, capabilities );
  14643. this.info.programs = programCache.programs;
  14644. var bufferRenderer = new THREE.WebGLBufferRenderer( _gl, extensions, _infoRender );
  14645. var indexedBufferRenderer = new THREE.WebGLIndexedBufferRenderer( _gl, extensions, _infoRender );
  14646. //
  14647. function glClearColor( r, g, b, a ) {
  14648. if ( _premultipliedAlpha === true ) {
  14649. r *= a; g *= a; b *= a;
  14650. }
  14651. _gl.clearColor( r, g, b, a );
  14652. }
  14653. function setDefaultGLState() {
  14654. state.init();
  14655. _gl.viewport( _viewportX, _viewportY, _viewportWidth, _viewportHeight );
  14656. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  14657. }
  14658. function resetGLState() {
  14659. _currentProgram = null;
  14660. _currentCamera = null;
  14661. _currentGeometryProgram = '';
  14662. _currentMaterialId = - 1;
  14663. _lightsNeedUpdate = true;
  14664. state.reset();
  14665. }
  14666. setDefaultGLState();
  14667. this.context = _gl;
  14668. this.capabilities = capabilities;
  14669. this.extensions = extensions;
  14670. this.state = state;
  14671. // shadow map
  14672. var shadowMap = new THREE.WebGLShadowMap( this, lights, objects );
  14673. this.shadowMap = shadowMap;
  14674. // Plugins
  14675. var spritePlugin = new THREE.SpritePlugin( this, sprites );
  14676. var lensFlarePlugin = new THREE.LensFlarePlugin( this, lensFlares );
  14677. // API
  14678. this.getContext = function () {
  14679. return _gl;
  14680. };
  14681. this.getContextAttributes = function () {
  14682. return _gl.getContextAttributes();
  14683. };
  14684. this.forceContextLoss = function () {
  14685. extensions.get( 'WEBGL_lose_context' ).loseContext();
  14686. };
  14687. this.getMaxAnisotropy = ( function () {
  14688. var value;
  14689. return function getMaxAnisotropy() {
  14690. if ( value !== undefined ) return value;
  14691. var extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  14692. if ( extension !== null ) {
  14693. value = _gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );
  14694. } else {
  14695. value = 0;
  14696. }
  14697. return value;
  14698. }
  14699. } )();
  14700. this.getPrecision = function () {
  14701. return capabilities.precision;
  14702. };
  14703. this.getPixelRatio = function () {
  14704. return pixelRatio;
  14705. };
  14706. this.setPixelRatio = function ( value ) {
  14707. if ( value !== undefined ) pixelRatio = value;
  14708. };
  14709. this.getSize = function () {
  14710. return {
  14711. width: _width,
  14712. height: _height
  14713. };
  14714. };
  14715. this.setSize = function ( width, height, updateStyle ) {
  14716. _width = width;
  14717. _height = height;
  14718. _canvas.width = width * pixelRatio;
  14719. _canvas.height = height * pixelRatio;
  14720. if ( updateStyle !== false ) {
  14721. _canvas.style.width = width + 'px';
  14722. _canvas.style.height = height + 'px';
  14723. }
  14724. this.setViewport( 0, 0, width, height );
  14725. };
  14726. this.setViewport = function ( x, y, width, height ) {
  14727. _viewportX = x * pixelRatio;
  14728. _viewportY = y * pixelRatio;
  14729. _viewportWidth = width * pixelRatio;
  14730. _viewportHeight = height * pixelRatio;
  14731. _gl.viewport( _viewportX, _viewportY, _viewportWidth, _viewportHeight );
  14732. };
  14733. this.getViewport = function ( dimensions ) {
  14734. dimensions.x = _viewportX / pixelRatio;
  14735. dimensions.y = _viewportY / pixelRatio;
  14736. dimensions.z = _viewportWidth / pixelRatio;
  14737. dimensions.w = _viewportHeight / pixelRatio;
  14738. };
  14739. this.setScissor = function ( x, y, width, height ) {
  14740. _gl.scissor(
  14741. x * pixelRatio,
  14742. y * pixelRatio,
  14743. width * pixelRatio,
  14744. height * pixelRatio
  14745. );
  14746. };
  14747. this.enableScissorTest = function ( boolean ) {
  14748. state.setScissorTest( boolean );
  14749. };
  14750. // Clearing
  14751. this.getClearColor = function () {
  14752. return _clearColor;
  14753. };
  14754. this.setClearColor = function ( color, alpha ) {
  14755. _clearColor.set( color );
  14756. _clearAlpha = alpha !== undefined ? alpha : 1;
  14757. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  14758. };
  14759. this.getClearAlpha = function () {
  14760. return _clearAlpha;
  14761. };
  14762. this.setClearAlpha = function ( alpha ) {
  14763. _clearAlpha = alpha;
  14764. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  14765. };
  14766. this.clear = function ( color, depth, stencil ) {
  14767. var bits = 0;
  14768. if ( color === undefined || color ) bits |= _gl.COLOR_BUFFER_BIT;
  14769. if ( depth === undefined || depth ) bits |= _gl.DEPTH_BUFFER_BIT;
  14770. if ( stencil === undefined || stencil ) bits |= _gl.STENCIL_BUFFER_BIT;
  14771. _gl.clear( bits );
  14772. };
  14773. this.clearColor = function () {
  14774. _gl.clear( _gl.COLOR_BUFFER_BIT );
  14775. };
  14776. this.clearDepth = function () {
  14777. _gl.clear( _gl.DEPTH_BUFFER_BIT );
  14778. };
  14779. this.clearStencil = function () {
  14780. _gl.clear( _gl.STENCIL_BUFFER_BIT );
  14781. };
  14782. this.clearTarget = function ( renderTarget, color, depth, stencil ) {
  14783. this.setRenderTarget( renderTarget );
  14784. this.clear( color, depth, stencil );
  14785. };
  14786. // Reset
  14787. this.resetGLState = resetGLState;
  14788. this.dispose = function() {
  14789. _canvas.removeEventListener( 'webglcontextlost', onContextLost, false );
  14790. };
  14791. // Events
  14792. function onContextLost( event ) {
  14793. event.preventDefault();
  14794. resetGLState();
  14795. setDefaultGLState();
  14796. properties.clear();
  14797. };
  14798. function onTextureDispose( event ) {
  14799. var texture = event.target;
  14800. texture.removeEventListener( 'dispose', onTextureDispose );
  14801. deallocateTexture( texture );
  14802. _infoMemory.textures --;
  14803. }
  14804. function onRenderTargetDispose( event ) {
  14805. var renderTarget = event.target;
  14806. renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
  14807. deallocateRenderTarget( renderTarget );
  14808. _infoMemory.textures --;
  14809. }
  14810. function onMaterialDispose( event ) {
  14811. var material = event.target;
  14812. material.removeEventListener( 'dispose', onMaterialDispose );
  14813. deallocateMaterial( material );
  14814. }
  14815. // Buffer deallocation
  14816. function deallocateTexture( texture ) {
  14817. var textureProperties = properties.get( texture );
  14818. if ( texture.image && textureProperties.__image__webglTextureCube ) {
  14819. // cube texture
  14820. _gl.deleteTexture( textureProperties.__image__webglTextureCube );
  14821. } else {
  14822. // 2D texture
  14823. if ( textureProperties.__webglInit === undefined ) return;
  14824. _gl.deleteTexture( textureProperties.__webglTexture );
  14825. }
  14826. // remove all webgl properties
  14827. properties.delete( texture );
  14828. }
  14829. function deallocateRenderTarget( renderTarget ) {
  14830. var renderTargetProperties = properties.get( renderTarget );
  14831. var textureProperties = properties.get( renderTarget.texture );
  14832. if ( ! renderTarget || textureProperties.__webglTexture === undefined ) return;
  14833. _gl.deleteTexture( textureProperties.__webglTexture );
  14834. if ( renderTarget instanceof THREE.WebGLRenderTargetCube ) {
  14835. for ( var i = 0; i < 6; i ++ ) {
  14836. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] );
  14837. _gl.deleteRenderbuffer( renderTargetProperties.__webglRenderbuffer[ i ] );
  14838. }
  14839. } else {
  14840. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer );
  14841. _gl.deleteRenderbuffer( renderTargetProperties.__webglRenderbuffer );
  14842. }
  14843. properties.delete( renderTarget.texture );
  14844. properties.delete( renderTarget );
  14845. }
  14846. function deallocateMaterial( material ) {
  14847. releaseMaterialProgramReference( material );
  14848. properties.delete( material );
  14849. }
  14850. function releaseMaterialProgramReference( material ) {
  14851. var programInfo = properties.get( material ).program;
  14852. material.program = undefined;
  14853. if ( programInfo !== undefined ) {
  14854. programCache.releaseProgram( programInfo );
  14855. }
  14856. }
  14857. // Buffer rendering
  14858. this.renderBufferImmediate = function ( object, program, material ) {
  14859. state.initAttributes();
  14860. var buffers = properties.get( object );
  14861. if ( object.hasPositions && ! buffers.position ) buffers.position = _gl.createBuffer();
  14862. if ( object.hasNormals && ! buffers.normal ) buffers.normal = _gl.createBuffer();
  14863. if ( object.hasUvs && ! buffers.uv ) buffers.uv = _gl.createBuffer();
  14864. if ( object.hasColors && ! buffers.color ) buffers.color = _gl.createBuffer();
  14865. var attributes = program.getAttributes();
  14866. if ( object.hasPositions ) {
  14867. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.position );
  14868. _gl.bufferData( _gl.ARRAY_BUFFER, object.positionArray, _gl.DYNAMIC_DRAW );
  14869. state.enableAttribute( attributes.position );
  14870. _gl.vertexAttribPointer( attributes.position, 3, _gl.FLOAT, false, 0, 0 );
  14871. }
  14872. if ( object.hasNormals ) {
  14873. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.normal );
  14874. if ( material.type !== 'MeshPhongMaterial' && material.type !== 'MeshPhysicalMaterial' && material.shading === THREE.FlatShading ) {
  14875. for ( var i = 0, l = object.count * 3; i < l; i += 9 ) {
  14876. var array = object.normalArray;
  14877. var nx = ( array[ i + 0 ] + array[ i + 3 ] + array[ i + 6 ] ) / 3;
  14878. var ny = ( array[ i + 1 ] + array[ i + 4 ] + array[ i + 7 ] ) / 3;
  14879. var nz = ( array[ i + 2 ] + array[ i + 5 ] + array[ i + 8 ] ) / 3;
  14880. array[ i + 0 ] = nx;
  14881. array[ i + 1 ] = ny;
  14882. array[ i + 2 ] = nz;
  14883. array[ i + 3 ] = nx;
  14884. array[ i + 4 ] = ny;
  14885. array[ i + 5 ] = nz;
  14886. array[ i + 6 ] = nx;
  14887. array[ i + 7 ] = ny;
  14888. array[ i + 8 ] = nz;
  14889. }
  14890. }
  14891. _gl.bufferData( _gl.ARRAY_BUFFER, object.normalArray, _gl.DYNAMIC_DRAW );
  14892. state.enableAttribute( attributes.normal );
  14893. _gl.vertexAttribPointer( attributes.normal, 3, _gl.FLOAT, false, 0, 0 );
  14894. }
  14895. if ( object.hasUvs && material.map ) {
  14896. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.uv );
  14897. _gl.bufferData( _gl.ARRAY_BUFFER, object.uvArray, _gl.DYNAMIC_DRAW );
  14898. state.enableAttribute( attributes.uv );
  14899. _gl.vertexAttribPointer( attributes.uv, 2, _gl.FLOAT, false, 0, 0 );
  14900. }
  14901. if ( object.hasColors && material.vertexColors !== THREE.NoColors ) {
  14902. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.color );
  14903. _gl.bufferData( _gl.ARRAY_BUFFER, object.colorArray, _gl.DYNAMIC_DRAW );
  14904. state.enableAttribute( attributes.color );
  14905. _gl.vertexAttribPointer( attributes.color, 3, _gl.FLOAT, false, 0, 0 );
  14906. }
  14907. state.disableUnusedAttributes();
  14908. _gl.drawArrays( _gl.TRIANGLES, 0, object.count );
  14909. object.count = 0;
  14910. };
  14911. this.renderBufferDirect = function ( camera, lights, fog, geometry, material, object, group ) {
  14912. setMaterial( material );
  14913. var program = setProgram( camera, lights, fog, material, object );
  14914. var updateBuffers = false;
  14915. var geometryProgram = geometry.id + '_' + program.id + '_' + material.wireframe;
  14916. if ( geometryProgram !== _currentGeometryProgram ) {
  14917. _currentGeometryProgram = geometryProgram;
  14918. updateBuffers = true;
  14919. }
  14920. // morph targets
  14921. var morphTargetInfluences = object.morphTargetInfluences;
  14922. if ( morphTargetInfluences !== undefined ) {
  14923. var activeInfluences = [];
  14924. for ( var i = 0, l = morphTargetInfluences.length; i < l; i ++ ) {
  14925. var influence = morphTargetInfluences[ i ];
  14926. activeInfluences.push( [ influence, i ] );
  14927. }
  14928. activeInfluences.sort( numericalSort );
  14929. if ( activeInfluences.length > 8 ) {
  14930. activeInfluences.length = 8;
  14931. }
  14932. var morphAttributes = geometry.morphAttributes;
  14933. for ( var i = 0, l = activeInfluences.length; i < l; i ++ ) {
  14934. var influence = activeInfluences[ i ];
  14935. morphInfluences[ i ] = influence[ 0 ];
  14936. if ( influence[ 0 ] !== 0 ) {
  14937. var index = influence[ 1 ];
  14938. if ( material.morphTargets === true && morphAttributes.position ) geometry.addAttribute( 'morphTarget' + i, morphAttributes.position[ index ] );
  14939. if ( material.morphNormals === true && morphAttributes.normal ) geometry.addAttribute( 'morphNormal' + i, morphAttributes.normal[ index ] );
  14940. } else {
  14941. if ( material.morphTargets === true ) geometry.removeAttribute( 'morphTarget' + i );
  14942. if ( material.morphNormals === true ) geometry.removeAttribute( 'morphNormal' + i );
  14943. }
  14944. }
  14945. var uniforms = program.getUniforms();
  14946. if ( uniforms.morphTargetInfluences !== null ) {
  14947. _gl.uniform1fv( uniforms.morphTargetInfluences, morphInfluences );
  14948. }
  14949. updateBuffers = true;
  14950. }
  14951. //
  14952. var index = geometry.index;
  14953. var position = geometry.attributes.position;
  14954. if ( material.wireframe === true ) {
  14955. index = objects.getWireframeAttribute( geometry );
  14956. }
  14957. var renderer;
  14958. if ( index !== null ) {
  14959. renderer = indexedBufferRenderer;
  14960. renderer.setIndex( index );
  14961. } else {
  14962. renderer = bufferRenderer;
  14963. }
  14964. if ( updateBuffers ) {
  14965. setupVertexAttributes( material, program, geometry );
  14966. if ( index !== null ) {
  14967. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, objects.getAttributeBuffer( index ) );
  14968. }
  14969. }
  14970. //
  14971. var dataStart = 0;
  14972. var dataCount = Infinity;
  14973. if ( index !== null ) {
  14974. dataCount = index.count
  14975. } else if ( position !== undefined ) {
  14976. dataCount = position.count;
  14977. }
  14978. var rangeStart = geometry.drawRange.start;
  14979. var rangeCount = geometry.drawRange.count;
  14980. var groupStart = group !== null ? group.start : 0;
  14981. var groupCount = group !== null ? group.count : Infinity;
  14982. var drawStart = Math.max( dataStart, rangeStart, groupStart );
  14983. var drawEnd = Math.min( dataStart + dataCount, rangeStart + rangeCount, groupStart + groupCount ) - 1;
  14984. var drawCount = Math.max( 0, drawEnd - drawStart + 1 );
  14985. //
  14986. if ( object instanceof THREE.Mesh ) {
  14987. if ( material.wireframe === true ) {
  14988. state.setLineWidth( material.wireframeLinewidth * pixelRatio );
  14989. renderer.setMode( _gl.LINES );
  14990. } else {
  14991. renderer.setMode( _gl.TRIANGLES );
  14992. }
  14993. if ( geometry instanceof THREE.InstancedBufferGeometry && geometry.maxInstancedCount > 0 ) {
  14994. renderer.renderInstances( geometry );
  14995. } else {
  14996. renderer.render( drawStart, drawCount );
  14997. }
  14998. } else if ( object instanceof THREE.Line ) {
  14999. var lineWidth = material.linewidth;
  15000. if ( lineWidth === undefined ) lineWidth = 1; // Not using Line*Material
  15001. state.setLineWidth( lineWidth * pixelRatio );
  15002. if ( object instanceof THREE.LineSegments ) {
  15003. renderer.setMode( _gl.LINES );
  15004. } else {
  15005. renderer.setMode( _gl.LINE_STRIP );
  15006. }
  15007. renderer.render( drawStart, drawCount );
  15008. } else if ( object instanceof THREE.Points ) {
  15009. renderer.setMode( _gl.POINTS );
  15010. renderer.render( drawStart, drawCount );
  15011. }
  15012. };
  15013. function setupVertexAttributes( material, program, geometry, startIndex ) {
  15014. var extension;
  15015. if ( geometry instanceof THREE.InstancedBufferGeometry ) {
  15016. extension = extensions.get( 'ANGLE_instanced_arrays' );
  15017. if ( extension === null ) {
  15018. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  15019. return;
  15020. }
  15021. }
  15022. if ( startIndex === undefined ) startIndex = 0;
  15023. state.initAttributes();
  15024. var geometryAttributes = geometry.attributes;
  15025. var programAttributes = program.getAttributes();
  15026. var materialDefaultAttributeValues = material.defaultAttributeValues;
  15027. for ( var name in programAttributes ) {
  15028. var programAttribute = programAttributes[ name ];
  15029. if ( programAttribute >= 0 ) {
  15030. var geometryAttribute = geometryAttributes[ name ];
  15031. if ( geometryAttribute !== undefined ) {
  15032. var size = geometryAttribute.itemSize;
  15033. var buffer = objects.getAttributeBuffer( geometryAttribute );
  15034. if ( geometryAttribute instanceof THREE.InterleavedBufferAttribute ) {
  15035. var data = geometryAttribute.data;
  15036. var stride = data.stride;
  15037. var offset = geometryAttribute.offset;
  15038. if ( data instanceof THREE.InstancedInterleavedBuffer ) {
  15039. state.enableAttributeAndDivisor( programAttribute, data.meshPerAttribute, extension );
  15040. if ( geometry.maxInstancedCount === undefined ) {
  15041. geometry.maxInstancedCount = data.meshPerAttribute * data.count;
  15042. }
  15043. } else {
  15044. state.enableAttribute( programAttribute );
  15045. }
  15046. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  15047. _gl.vertexAttribPointer( programAttribute, size, _gl.FLOAT, false, stride * data.array.BYTES_PER_ELEMENT, ( startIndex * stride + offset ) * data.array.BYTES_PER_ELEMENT );
  15048. } else {
  15049. if ( geometryAttribute instanceof THREE.InstancedBufferAttribute ) {
  15050. state.enableAttributeAndDivisor( programAttribute, geometryAttribute.meshPerAttribute, extension );
  15051. if ( geometry.maxInstancedCount === undefined ) {
  15052. geometry.maxInstancedCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  15053. }
  15054. } else {
  15055. state.enableAttribute( programAttribute );
  15056. }
  15057. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  15058. _gl.vertexAttribPointer( programAttribute, size, _gl.FLOAT, false, 0, startIndex * size * 4 ); // 4 bytes per Float32
  15059. }
  15060. } else if ( materialDefaultAttributeValues !== undefined ) {
  15061. var value = materialDefaultAttributeValues[ name ];
  15062. if ( value !== undefined ) {
  15063. switch ( value.length ) {
  15064. case 2:
  15065. _gl.vertexAttrib2fv( programAttribute, value );
  15066. break;
  15067. case 3:
  15068. _gl.vertexAttrib3fv( programAttribute, value );
  15069. break;
  15070. case 4:
  15071. _gl.vertexAttrib4fv( programAttribute, value );
  15072. break;
  15073. default:
  15074. _gl.vertexAttrib1fv( programAttribute, value );
  15075. }
  15076. }
  15077. }
  15078. }
  15079. }
  15080. state.disableUnusedAttributes();
  15081. }
  15082. // Sorting
  15083. function numericalSort ( a, b ) {
  15084. return b[ 0 ] - a[ 0 ];
  15085. }
  15086. function painterSortStable ( a, b ) {
  15087. if ( a.object.renderOrder !== b.object.renderOrder ) {
  15088. return a.object.renderOrder - b.object.renderOrder;
  15089. } else if ( a.material.id !== b.material.id ) {
  15090. return a.material.id - b.material.id;
  15091. } else if ( a.z !== b.z ) {
  15092. return a.z - b.z;
  15093. } else {
  15094. return a.id - b.id;
  15095. }
  15096. }
  15097. function reversePainterSortStable ( a, b ) {
  15098. if ( a.object.renderOrder !== b.object.renderOrder ) {
  15099. return a.object.renderOrder - b.object.renderOrder;
  15100. } if ( a.z !== b.z ) {
  15101. return b.z - a.z;
  15102. } else {
  15103. return a.id - b.id;
  15104. }
  15105. }
  15106. // Rendering
  15107. this.render = function ( scene, camera, renderTarget, forceClear ) {
  15108. if ( camera instanceof THREE.Camera === false ) {
  15109. console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
  15110. return;
  15111. }
  15112. var fog = scene.fog;
  15113. // reset caching for this frame
  15114. _currentGeometryProgram = '';
  15115. _currentMaterialId = - 1;
  15116. _currentCamera = null;
  15117. _lightsNeedUpdate = true;
  15118. // update scene graph
  15119. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  15120. // update camera matrices and frustum
  15121. if ( camera.parent === null ) camera.updateMatrixWorld();
  15122. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  15123. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  15124. _frustum.setFromMatrix( _projScreenMatrix );
  15125. lights.length = 0;
  15126. opaqueObjectsLastIndex = - 1;
  15127. transparentObjectsLastIndex = - 1;
  15128. sprites.length = 0;
  15129. lensFlares.length = 0;
  15130. projectObject( scene, camera );
  15131. opaqueObjects.length = opaqueObjectsLastIndex + 1;
  15132. transparentObjects.length = transparentObjectsLastIndex + 1;
  15133. if ( _this.sortObjects === true ) {
  15134. opaqueObjects.sort( painterSortStable );
  15135. transparentObjects.sort( reversePainterSortStable );
  15136. }
  15137. //
  15138. shadowMap.render( scene, camera );
  15139. //
  15140. _infoRender.calls = 0;
  15141. _infoRender.vertices = 0;
  15142. _infoRender.faces = 0;
  15143. _infoRender.points = 0;
  15144. this.setRenderTarget( renderTarget );
  15145. if ( this.autoClear || forceClear ) {
  15146. this.clear( this.autoClearColor, this.autoClearDepth, this.autoClearStencil );
  15147. }
  15148. //
  15149. if ( scene.overrideMaterial ) {
  15150. var overrideMaterial = scene.overrideMaterial;
  15151. renderObjects( opaqueObjects, camera, lights, fog, overrideMaterial );
  15152. renderObjects( transparentObjects, camera, lights, fog, overrideMaterial );
  15153. } else {
  15154. // opaque pass (front-to-back order)
  15155. state.setBlending( THREE.NoBlending );
  15156. renderObjects( opaqueObjects, camera, lights, fog );
  15157. // transparent pass (back-to-front order)
  15158. renderObjects( transparentObjects, camera, lights, fog );
  15159. }
  15160. // custom render plugins (post pass)
  15161. spritePlugin.render( scene, camera );
  15162. lensFlarePlugin.render( scene, camera, _currentWidth, _currentHeight );
  15163. // Generate mipmap if we're using any kind of mipmap filtering
  15164. if ( renderTarget ) {
  15165. var texture = renderTarget.texture;
  15166. if ( texture.generateMipmaps && isPowerOfTwo( renderTarget ) &&
  15167. texture.minFilter !== THREE.NearestFilter &&
  15168. texture.minFilter !== THREE.LinearFilter ) {
  15169. updateRenderTargetMipmap( renderTarget );
  15170. }
  15171. }
  15172. // Ensure depth buffer writing is enabled so it can be cleared on next render
  15173. state.setDepthTest( true );
  15174. state.setDepthWrite( true );
  15175. state.setColorWrite( true );
  15176. // _gl.finish();
  15177. };
  15178. function pushRenderItem( object, geometry, material, z, group ) {
  15179. var array, index;
  15180. // allocate the next position in the appropriate array
  15181. if ( material.transparent ) {
  15182. array = transparentObjects;
  15183. index = ++ transparentObjectsLastIndex;
  15184. } else {
  15185. array = opaqueObjects;
  15186. index = ++ opaqueObjectsLastIndex;
  15187. }
  15188. // recycle existing render item or grow the array
  15189. var renderItem = array[ index ];
  15190. if ( renderItem !== undefined ) {
  15191. renderItem.id = object.id;
  15192. renderItem.object = object;
  15193. renderItem.geometry = geometry;
  15194. renderItem.material = material;
  15195. renderItem.z = _vector3.z;
  15196. renderItem.group = group;
  15197. } else {
  15198. renderItem = {
  15199. id: object.id,
  15200. object: object,
  15201. geometry: geometry,
  15202. material: material,
  15203. z: _vector3.z,
  15204. group: group
  15205. };
  15206. // assert( index === array.length );
  15207. array.push( renderItem );
  15208. }
  15209. }
  15210. function projectObject( object, camera ) {
  15211. if ( object.visible === false ) return;
  15212. if ( object.layers.test( camera.layers ) ) {
  15213. if ( object instanceof THREE.Light ) {
  15214. lights.push( object );
  15215. } else if ( object instanceof THREE.Sprite ) {
  15216. if ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) {
  15217. sprites.push( object );
  15218. }
  15219. } else if ( object instanceof THREE.LensFlare ) {
  15220. lensFlares.push( object );
  15221. } else if ( object instanceof THREE.ImmediateRenderObject ) {
  15222. if ( _this.sortObjects === true ) {
  15223. _vector3.setFromMatrixPosition( object.matrixWorld );
  15224. _vector3.applyProjection( _projScreenMatrix );
  15225. }
  15226. pushRenderItem( object, null, object.material, _vector3.z, null );
  15227. } else if ( object instanceof THREE.Mesh || object instanceof THREE.Line || object instanceof THREE.Points ) {
  15228. if ( object instanceof THREE.SkinnedMesh ) {
  15229. object.skeleton.update();
  15230. }
  15231. if ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) {
  15232. var material = object.material;
  15233. if ( material.visible === true ) {
  15234. if ( _this.sortObjects === true ) {
  15235. _vector3.setFromMatrixPosition( object.matrixWorld );
  15236. _vector3.applyProjection( _projScreenMatrix );
  15237. }
  15238. var geometry = objects.update( object );
  15239. if ( material instanceof THREE.MeshFaceMaterial ) {
  15240. var groups = geometry.groups;
  15241. var materials = material.materials;
  15242. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  15243. var group = groups[ i ];
  15244. var groupMaterial = materials[ group.materialIndex ];
  15245. if ( groupMaterial.visible === true ) {
  15246. pushRenderItem( object, geometry, groupMaterial, _vector3.z, group );
  15247. }
  15248. }
  15249. } else {
  15250. pushRenderItem( object, geometry, material, _vector3.z, null );
  15251. }
  15252. }
  15253. }
  15254. }
  15255. }
  15256. var children = object.children;
  15257. for ( var i = 0, l = children.length; i < l; i ++ ) {
  15258. projectObject( children[ i ], camera );
  15259. }
  15260. }
  15261. function renderObjects( renderList, camera, lights, fog, overrideMaterial ) {
  15262. for ( var i = 0, l = renderList.length; i < l; i ++ ) {
  15263. var renderItem = renderList[ i ];
  15264. var object = renderItem.object;
  15265. var geometry = renderItem.geometry;
  15266. var material = overrideMaterial === undefined ? renderItem.material : overrideMaterial;
  15267. var group = renderItem.group;
  15268. object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  15269. object.normalMatrix.getNormalMatrix( object.modelViewMatrix );
  15270. if ( object instanceof THREE.ImmediateRenderObject ) {
  15271. setMaterial( material );
  15272. var program = setProgram( camera, lights, fog, material, object );
  15273. _currentGeometryProgram = '';
  15274. object.render( function ( object ) {
  15275. _this.renderBufferImmediate( object, program, material );
  15276. } );
  15277. } else {
  15278. _this.renderBufferDirect( camera, lights, fog, geometry, material, object, group );
  15279. }
  15280. }
  15281. }
  15282. function initMaterial( material, lights, fog, object ) {
  15283. var materialProperties = properties.get( material );
  15284. var parameters = programCache.getParameters( material, lights, fog, object );
  15285. var code = programCache.getProgramCode( material, parameters );
  15286. var program = materialProperties.program;
  15287. var programChange = true;
  15288. if ( program === undefined ) {
  15289. // new material
  15290. material.addEventListener( 'dispose', onMaterialDispose );
  15291. } else if ( program.code !== code ) {
  15292. // changed glsl or parameters
  15293. releaseMaterialProgramReference( material );
  15294. } else if ( parameters.shaderID !== undefined ) {
  15295. // same glsl and uniform list
  15296. return;
  15297. } else {
  15298. // only rebuild uniform list
  15299. programChange = false;
  15300. }
  15301. if ( programChange ) {
  15302. if ( parameters.shaderID ) {
  15303. var shader = THREE.ShaderLib[ parameters.shaderID ];
  15304. materialProperties.__webglShader = {
  15305. name: material.type,
  15306. uniforms: THREE.UniformsUtils.clone( shader.uniforms ),
  15307. vertexShader: shader.vertexShader,
  15308. fragmentShader: shader.fragmentShader
  15309. };
  15310. } else {
  15311. materialProperties.__webglShader = {
  15312. name: material.type,
  15313. uniforms: material.uniforms,
  15314. vertexShader: material.vertexShader,
  15315. fragmentShader: material.fragmentShader
  15316. };
  15317. }
  15318. material.__webglShader = materialProperties.__webglShader;
  15319. program = programCache.acquireProgram( material, parameters, code );
  15320. materialProperties.program = program;
  15321. material.program = program;
  15322. }
  15323. var attributes = program.getAttributes();
  15324. if ( material.morphTargets ) {
  15325. material.numSupportedMorphTargets = 0;
  15326. for ( var i = 0; i < _this.maxMorphTargets; i ++ ) {
  15327. if ( attributes[ 'morphTarget' + i ] >= 0 ) {
  15328. material.numSupportedMorphTargets ++;
  15329. }
  15330. }
  15331. }
  15332. if ( material.morphNormals ) {
  15333. material.numSupportedMorphNormals = 0;
  15334. for ( i = 0; i < _this.maxMorphNormals; i ++ ) {
  15335. if ( attributes[ 'morphNormal' + i ] >= 0 ) {
  15336. material.numSupportedMorphNormals ++;
  15337. }
  15338. }
  15339. }
  15340. materialProperties.uniformsList = [];
  15341. var uniforms = materialProperties.__webglShader.uniforms,
  15342. uniformLocations = materialProperties.program.getUniforms();
  15343. for ( var u in uniforms ) {
  15344. var location = uniformLocations[ u ];
  15345. if ( location ) {
  15346. materialProperties.uniformsList.push( [ materialProperties.__webglShader.uniforms[ u ], location ] );
  15347. }
  15348. }
  15349. if ( material instanceof THREE.MeshPhongMaterial ||
  15350. material instanceof THREE.MeshLambertMaterial ||
  15351. material instanceof THREE.MeshPhysicalMaterial ||
  15352. material.lights ) {
  15353. // wire up the material to this renderer's lighting state
  15354. uniforms.ambientLightColor.value = _lights.ambient;
  15355. uniforms.directionalLights.value = _lights.directional;
  15356. uniforms.pointLights.value = _lights.point;
  15357. uniforms.spotLights.value = _lights.spot;
  15358. uniforms.hemisphereLights.value = _lights.hemi;
  15359. }
  15360. }
  15361. function setMaterial( material ) {
  15362. setMaterialFaces( material );
  15363. if ( material.transparent === true ) {
  15364. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha );
  15365. } else {
  15366. state.setBlending( THREE.NoBlending );
  15367. }
  15368. state.setDepthFunc( material.depthFunc );
  15369. state.setDepthTest( material.depthTest );
  15370. state.setDepthWrite( material.depthWrite );
  15371. state.setColorWrite( material.colorWrite );
  15372. state.setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  15373. }
  15374. function setMaterialFaces( material ) {
  15375. material.side !== THREE.DoubleSide ? state.enable( _gl.CULL_FACE ) : state.disable( _gl.CULL_FACE );
  15376. state.setFlipSided( material.side === THREE.BackSide );
  15377. }
  15378. function setProgram( camera, lights, fog, material, object ) {
  15379. _usedTextureUnits = 0;
  15380. var materialProperties = properties.get( material );
  15381. if ( material.needsUpdate || ! materialProperties.program ) {
  15382. initMaterial( material, lights, fog, object );
  15383. material.needsUpdate = false;
  15384. }
  15385. var refreshProgram = false;
  15386. var refreshMaterial = false;
  15387. var refreshLights = false;
  15388. var program = materialProperties.program,
  15389. p_uniforms = program.getUniforms(),
  15390. m_uniforms = materialProperties.__webglShader.uniforms;
  15391. if ( program.id !== _currentProgram ) {
  15392. _gl.useProgram( program.program );
  15393. _currentProgram = program.id;
  15394. refreshProgram = true;
  15395. refreshMaterial = true;
  15396. refreshLights = true;
  15397. }
  15398. if ( material.id !== _currentMaterialId ) {
  15399. _currentMaterialId = material.id;
  15400. refreshMaterial = true;
  15401. }
  15402. if ( refreshProgram || camera !== _currentCamera ) {
  15403. _gl.uniformMatrix4fv( p_uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
  15404. if ( capabilities.logarithmicDepthBuffer ) {
  15405. _gl.uniform1f( p_uniforms.logDepthBufFC, 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
  15406. }
  15407. if ( camera !== _currentCamera ) {
  15408. _currentCamera = camera;
  15409. // lighting uniforms depend on the camera so enforce an update
  15410. // now, in case this material supports lights - or later, when
  15411. // the next material that does gets activated:
  15412. refreshMaterial = true; // set to true on material change
  15413. _lightsNeedUpdate = true; // remains set until update done
  15414. }
  15415. // load material specific uniforms
  15416. // (shader material also gets them for the sake of genericity)
  15417. if ( material instanceof THREE.ShaderMaterial ||
  15418. material instanceof THREE.MeshPhongMaterial ||
  15419. material instanceof THREE.MeshPhysicalMaterial ||
  15420. material.envMap ) {
  15421. if ( p_uniforms.cameraPosition !== undefined ) {
  15422. _vector3.setFromMatrixPosition( camera.matrixWorld );
  15423. _gl.uniform3f( p_uniforms.cameraPosition, _vector3.x, _vector3.y, _vector3.z );
  15424. }
  15425. }
  15426. if ( material instanceof THREE.MeshPhongMaterial ||
  15427. material instanceof THREE.MeshLambertMaterial ||
  15428. material instanceof THREE.MeshBasicMaterial ||
  15429. material instanceof THREE.MeshPhysicalMaterial ||
  15430. material instanceof THREE.ShaderMaterial ||
  15431. material.skinning ) {
  15432. if ( p_uniforms.viewMatrix !== undefined ) {
  15433. _gl.uniformMatrix4fv( p_uniforms.viewMatrix, false, camera.matrixWorldInverse.elements );
  15434. }
  15435. }
  15436. }
  15437. // skinning uniforms must be set even if material didn't change
  15438. // auto-setting of texture unit for bone texture must go before other textures
  15439. // not sure why, but otherwise weird things happen
  15440. if ( material.skinning ) {
  15441. if ( object.bindMatrix && p_uniforms.bindMatrix !== undefined ) {
  15442. _gl.uniformMatrix4fv( p_uniforms.bindMatrix, false, object.bindMatrix.elements );
  15443. }
  15444. if ( object.bindMatrixInverse && p_uniforms.bindMatrixInverse !== undefined ) {
  15445. _gl.uniformMatrix4fv( p_uniforms.bindMatrixInverse, false, object.bindMatrixInverse.elements );
  15446. }
  15447. if ( capabilities.floatVertexTextures && object.skeleton && object.skeleton.useVertexTexture ) {
  15448. if ( p_uniforms.boneTexture !== undefined ) {
  15449. var textureUnit = getTextureUnit();
  15450. _gl.uniform1i( p_uniforms.boneTexture, textureUnit );
  15451. _this.setTexture( object.skeleton.boneTexture, textureUnit );
  15452. }
  15453. if ( p_uniforms.boneTextureWidth !== undefined ) {
  15454. _gl.uniform1i( p_uniforms.boneTextureWidth, object.skeleton.boneTextureWidth );
  15455. }
  15456. if ( p_uniforms.boneTextureHeight !== undefined ) {
  15457. _gl.uniform1i( p_uniforms.boneTextureHeight, object.skeleton.boneTextureHeight );
  15458. }
  15459. } else if ( object.skeleton && object.skeleton.boneMatrices ) {
  15460. if ( p_uniforms.boneGlobalMatrices !== undefined ) {
  15461. _gl.uniformMatrix4fv( p_uniforms.boneGlobalMatrices, false, object.skeleton.boneMatrices );
  15462. }
  15463. }
  15464. }
  15465. if ( refreshMaterial ) {
  15466. // refresh uniforms common to several materials
  15467. if ( fog && material.fog ) {
  15468. refreshUniformsFog( m_uniforms, fog );
  15469. }
  15470. if ( material instanceof THREE.MeshPhongMaterial ||
  15471. material instanceof THREE.MeshLambertMaterial ||
  15472. material instanceof THREE.MeshPhysicalMaterial ||
  15473. material.lights ) {
  15474. // the current material requires lighting info
  15475. // if we haven't done so since the start of the frame, after a
  15476. // reset or camera change, update the lighting uniforms values
  15477. // of all materials (by reference)
  15478. if ( _lightsNeedUpdate ) {
  15479. _lightsNeedUpdate = false;
  15480. setupLights( lights, camera );
  15481. refreshLights = true;
  15482. }
  15483. // use the current material's .needsUpdate flags to set
  15484. // the GL state when required
  15485. markUniformsLightsNeedsUpdate( m_uniforms, refreshLights );
  15486. }
  15487. if ( material instanceof THREE.MeshBasicMaterial ||
  15488. material instanceof THREE.MeshLambertMaterial ||
  15489. material instanceof THREE.MeshPhongMaterial ||
  15490. material instanceof THREE.MeshPhysicalMaterial ) {
  15491. refreshUniformsCommon( m_uniforms, material );
  15492. }
  15493. // refresh single material specific uniforms
  15494. if ( material instanceof THREE.LineBasicMaterial ) {
  15495. refreshUniformsLine( m_uniforms, material );
  15496. } else if ( material instanceof THREE.LineDashedMaterial ) {
  15497. refreshUniformsLine( m_uniforms, material );
  15498. refreshUniformsDash( m_uniforms, material );
  15499. } else if ( material instanceof THREE.PointsMaterial ) {
  15500. refreshUniformsPoints( m_uniforms, material );
  15501. } else if ( material instanceof THREE.MeshPhongMaterial ) {
  15502. refreshUniformsPhong( m_uniforms, material );
  15503. } else if ( material instanceof THREE.MeshPhysicalMaterial ) {
  15504. refreshUniformsStandard( m_uniforms, material );
  15505. } else if ( material instanceof THREE.MeshDepthMaterial ) {
  15506. m_uniforms.mNear.value = camera.near;
  15507. m_uniforms.mFar.value = camera.far;
  15508. m_uniforms.opacity.value = material.opacity;
  15509. } else if ( material instanceof THREE.MeshNormalMaterial ) {
  15510. m_uniforms.opacity.value = material.opacity;
  15511. }
  15512. if ( shadowMap.enabled ) {
  15513. if ( object.receiveShadow && ! material._shadowPass ) {
  15514. refreshUniformsShadow( m_uniforms, lights, camera );
  15515. }
  15516. }
  15517. // load common uniforms
  15518. loadUniformsGeneric( materialProperties.uniformsList );
  15519. }
  15520. loadUniformsMatrices( p_uniforms, object );
  15521. if ( p_uniforms.modelMatrix !== undefined ) {
  15522. _gl.uniformMatrix4fv( p_uniforms.modelMatrix, false, object.matrixWorld.elements );
  15523. }
  15524. return program;
  15525. }
  15526. // Uniforms (refresh uniforms objects)
  15527. function refreshUniformsCommon ( uniforms, material ) {
  15528. uniforms.opacity.value = material.opacity;
  15529. uniforms.diffuse.value = material.color;
  15530. if ( material.emissive ) {
  15531. uniforms.emissive.value = material.emissive;
  15532. }
  15533. uniforms.map.value = material.map;
  15534. uniforms.specularMap.value = material.specularMap;
  15535. uniforms.alphaMap.value = material.alphaMap;
  15536. if ( material.aoMap ) {
  15537. uniforms.aoMap.value = material.aoMap;
  15538. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  15539. }
  15540. // uv repeat and offset setting priorities
  15541. // 1. color map
  15542. // 2. specular map
  15543. // 3. normal map
  15544. // 4. bump map
  15545. // 5. alpha map
  15546. // 6. emissive map
  15547. var uvScaleMap;
  15548. if ( material.map ) {
  15549. uvScaleMap = material.map;
  15550. } else if ( material.specularMap ) {
  15551. uvScaleMap = material.specularMap;
  15552. } else if ( material.displacementMap ) {
  15553. uvScaleMap = material.displacementMap;
  15554. } else if ( material.normalMap ) {
  15555. uvScaleMap = material.normalMap;
  15556. } else if ( material.bumpMap ) {
  15557. uvScaleMap = material.bumpMap;
  15558. } else if ( material.alphaMap ) {
  15559. uvScaleMap = material.alphaMap;
  15560. } else if ( material.emissiveMap ) {
  15561. uvScaleMap = material.emissiveMap;
  15562. }
  15563. if ( uvScaleMap !== undefined ) {
  15564. if ( uvScaleMap instanceof THREE.WebGLRenderTarget ) uvScaleMap = uvScaleMap.texture;
  15565. var offset = uvScaleMap.offset;
  15566. var repeat = uvScaleMap.repeat;
  15567. uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
  15568. }
  15569. uniforms.envMap.value = material.envMap;
  15570. uniforms.flipEnvMap.value = ( material.envMap instanceof THREE.WebGLRenderTargetCube ) ? 1 : - 1;
  15571. uniforms.reflectivity.value = material.reflectivity;
  15572. uniforms.refractionRatio.value = material.refractionRatio;
  15573. }
  15574. function refreshUniformsLine ( uniforms, material ) {
  15575. uniforms.diffuse.value = material.color;
  15576. uniforms.opacity.value = material.opacity;
  15577. }
  15578. function refreshUniformsDash ( uniforms, material ) {
  15579. uniforms.dashSize.value = material.dashSize;
  15580. uniforms.totalSize.value = material.dashSize + material.gapSize;
  15581. uniforms.scale.value = material.scale;
  15582. }
  15583. function refreshUniformsPoints ( uniforms, material ) {
  15584. uniforms.psColor.value = material.color;
  15585. uniforms.opacity.value = material.opacity;
  15586. uniforms.size.value = material.size * pixelRatio;
  15587. uniforms.scale.value = _canvas.height / 2.0; // TODO: Cache this.
  15588. uniforms.map.value = material.map;
  15589. if ( material.map !== null ) {
  15590. var offset = material.map.offset;
  15591. var repeat = material.map.repeat;
  15592. uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
  15593. }
  15594. }
  15595. function refreshUniformsFog ( uniforms, fog ) {
  15596. uniforms.fogColor.value = fog.color;
  15597. if ( fog instanceof THREE.Fog ) {
  15598. uniforms.fogNear.value = fog.near;
  15599. uniforms.fogFar.value = fog.far;
  15600. } else if ( fog instanceof THREE.FogExp2 ) {
  15601. uniforms.fogDensity.value = fog.density;
  15602. }
  15603. }
  15604. function refreshUniformsPhong ( uniforms, material ) {
  15605. uniforms.specular.value = material.specular;
  15606. uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 )
  15607. if ( material.lightMap ) {
  15608. uniforms.lightMap.value = material.lightMap;
  15609. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  15610. }
  15611. if ( material.emissiveMap ) {
  15612. uniforms.emissiveMap.value = material.emissiveMap;
  15613. }
  15614. if ( material.bumpMap ) {
  15615. uniforms.bumpMap.value = material.bumpMap;
  15616. uniforms.bumpScale.value = material.bumpScale;
  15617. }
  15618. if ( material.normalMap ) {
  15619. uniforms.normalMap.value = material.normalMap;
  15620. uniforms.normalScale.value.copy( material.normalScale );
  15621. }
  15622. if ( material.displacementMap ) {
  15623. uniforms.displacementMap.value = material.displacementMap;
  15624. uniforms.displacementScale.value = material.displacementScale;
  15625. uniforms.displacementBias.value = material.displacementBias;
  15626. }
  15627. }
  15628. function refreshUniformsStandard ( uniforms, material ) {
  15629. uniforms.roughness.value = material.roughness;
  15630. //uniforms.reflectivity.value = material.reflectivity; // part of uniforms common
  15631. uniforms.metalness.value = material.metalness;
  15632. if ( material.roughnessMap ) {
  15633. uniforms.roughnessMap.value = material.roughnessMap;
  15634. }
  15635. if ( material.reflectivityMap ) {
  15636. uniforms.reflectivityMap.value = material.reflectivityMap;
  15637. }
  15638. if ( material.metalnessMap ) {
  15639. uniforms.metalnessMap.value = material.metalnessMap;
  15640. }
  15641. if ( material.lightMap ) {
  15642. uniforms.lightMap.value = material.lightMap;
  15643. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  15644. }
  15645. if ( material.emissiveMap ) {
  15646. uniforms.emissiveMap.value = material.emissiveMap;
  15647. }
  15648. if ( material.bumpMap ) {
  15649. uniforms.bumpMap.value = material.bumpMap;
  15650. uniforms.bumpScale.value = material.bumpScale;
  15651. }
  15652. if ( material.normalMap ) {
  15653. uniforms.normalMap.value = material.normalMap;
  15654. uniforms.normalScale.value.copy( material.normalScale );
  15655. }
  15656. if ( material.displacementMap ) {
  15657. uniforms.displacementMap.value = material.displacementMap;
  15658. uniforms.displacementScale.value = material.displacementScale;
  15659. uniforms.displacementBias.value = material.displacementBias;
  15660. }
  15661. if ( material.envMap ) {
  15662. //uniforms.envMap.value = material.envMap; // part of uniforms common
  15663. uniforms.envMapIntensity.value = material.envMapIntensity;
  15664. }
  15665. }
  15666. // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  15667. function markUniformsLightsNeedsUpdate ( uniforms, value ) {
  15668. uniforms.ambientLightColor.needsUpdate = value;
  15669. uniforms.directionalLights.needsUpdate = value;
  15670. uniforms.pointLights.needsUpdate = value;
  15671. uniforms.spotLights.needsUpdate = value;
  15672. uniforms.hemisphereLights.needsUpdate = value;
  15673. }
  15674. function refreshUniformsShadow ( uniforms, lights, camera ) {
  15675. if ( uniforms.shadowMatrix ) {
  15676. var j = 0;
  15677. for ( var i = 0, il = lights.length; i < il; i ++ ) {
  15678. var light = lights[ i ];
  15679. if ( light.castShadow === true ) {
  15680. if ( light instanceof THREE.PointLight || light instanceof THREE.SpotLight || light instanceof THREE.DirectionalLight ) {
  15681. var shadow = light.shadow;
  15682. if ( light instanceof THREE.PointLight ) {
  15683. // for point lights we set the shadow matrix to be a translation-only matrix
  15684. // equal to inverse of the light's position
  15685. _vector3.setFromMatrixPosition( light.matrixWorld ).negate();
  15686. shadow.matrix.identity().setPosition( _vector3 );
  15687. // for point lights we set the sign of the shadowDarkness uniform to be negative
  15688. uniforms.shadowDarkness.value[ j ] = - shadow.darkness;
  15689. } else {
  15690. uniforms.shadowDarkness.value[ j ] = shadow.darkness;
  15691. }
  15692. uniforms.shadowMatrix.value[ j ] = shadow.matrix;
  15693. uniforms.shadowMap.value[ j ] = shadow.map;
  15694. uniforms.shadowMapSize.value[ j ] = shadow.mapSize;
  15695. uniforms.shadowBias.value[ j ] = shadow.bias;
  15696. j ++;
  15697. }
  15698. }
  15699. }
  15700. }
  15701. }
  15702. // Uniforms (load to GPU)
  15703. function loadUniformsMatrices ( uniforms, object ) {
  15704. _gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, object.modelViewMatrix.elements );
  15705. if ( uniforms.normalMatrix ) {
  15706. _gl.uniformMatrix3fv( uniforms.normalMatrix, false, object.normalMatrix.elements );
  15707. }
  15708. }
  15709. function getTextureUnit() {
  15710. var textureUnit = _usedTextureUnits;
  15711. if ( textureUnit >= capabilities.maxTextures ) {
  15712. console.warn( 'WebGLRenderer: trying to use ' + textureUnit + ' texture units while this GPU supports only ' + capabilities.maxTextures );
  15713. }
  15714. _usedTextureUnits += 1;
  15715. return textureUnit;
  15716. }
  15717. function loadUniformsGeneric ( uniforms ) {
  15718. var texture, textureUnit;
  15719. for ( var j = 0, jl = uniforms.length; j < jl; j ++ ) {
  15720. var uniform = uniforms[ j ][ 0 ];
  15721. // needsUpdate property is not added to all uniforms.
  15722. if ( uniform.needsUpdate === false ) continue;
  15723. var type = uniform.type;
  15724. var value = uniform.value;
  15725. var location = uniforms[ j ][ 1 ];
  15726. switch ( type ) {
  15727. case '1i':
  15728. _gl.uniform1i( location, value );
  15729. break;
  15730. case '1f':
  15731. _gl.uniform1f( location, value );
  15732. break;
  15733. case '2f':
  15734. _gl.uniform2f( location, value[ 0 ], value[ 1 ] );
  15735. break;
  15736. case '3f':
  15737. _gl.uniform3f( location, value[ 0 ], value[ 1 ], value[ 2 ] );
  15738. break;
  15739. case '4f':
  15740. _gl.uniform4f( location, value[ 0 ], value[ 1 ], value[ 2 ], value[ 3 ] );
  15741. break;
  15742. case '1iv':
  15743. _gl.uniform1iv( location, value );
  15744. break;
  15745. case '3iv':
  15746. _gl.uniform3iv( location, value );
  15747. break;
  15748. case '1fv':
  15749. _gl.uniform1fv( location, value );
  15750. break;
  15751. case '2fv':
  15752. _gl.uniform2fv( location, value );
  15753. break;
  15754. case '3fv':
  15755. _gl.uniform3fv( location, value );
  15756. break;
  15757. case '4fv':
  15758. _gl.uniform4fv( location, value );
  15759. break;
  15760. case 'Matrix3fv':
  15761. _gl.uniformMatrix3fv( location, false, value );
  15762. break;
  15763. case 'Matrix4fv':
  15764. _gl.uniformMatrix4fv( location, false, value );
  15765. break;
  15766. //
  15767. case 'i':
  15768. // single integer
  15769. _gl.uniform1i( location, value );
  15770. break;
  15771. case 'f':
  15772. // single float
  15773. _gl.uniform1f( location, value );
  15774. break;
  15775. case 'v2':
  15776. // single THREE.Vector2
  15777. _gl.uniform2f( location, value.x, value.y );
  15778. break;
  15779. case 'v3':
  15780. // single THREE.Vector3
  15781. _gl.uniform3f( location, value.x, value.y, value.z );
  15782. break;
  15783. case 'v4':
  15784. // single THREE.Vector4
  15785. _gl.uniform4f( location, value.x, value.y, value.z, value.w );
  15786. break;
  15787. case 'c':
  15788. // single THREE.Color
  15789. _gl.uniform3f( location, value.r, value.g, value.b );
  15790. break;
  15791. case 's':
  15792. // TODO: Optimize this.
  15793. for( var propertyName in uniform.properties ) {
  15794. var property = uniform.properties[ propertyName ];
  15795. var locationProperty = location[ propertyName ];
  15796. var valueProperty = value[ propertyName ];
  15797. switch( property.type ) {
  15798. case 'f':
  15799. _gl.uniform1f( locationProperty, valueProperty );
  15800. break;
  15801. case 'v2':
  15802. _gl.uniform2f( locationProperty, valueProperty.x, valueProperty.y );
  15803. break;
  15804. case 'v3':
  15805. _gl.uniform3f( locationProperty, valueProperty.x, valueProperty.y, valueProperty.z );
  15806. break;
  15807. case 'v4':
  15808. _gl.uniform4f( locationProperty, valueProperty.x, valueProperty.y, valueProperty.z, valueProperty.w );
  15809. break;
  15810. case 'c':
  15811. _gl.uniform3f( locationProperty, valueProperty.r, valueProperty.g, valueProperty.b );
  15812. break;
  15813. };
  15814. }
  15815. break;
  15816. case 'sa':
  15817. // TODO: Optimize this.
  15818. for( var i = 0; i < value.length; i ++ ) {
  15819. for( var propertyName in uniform.properties ) {
  15820. var property = uniform.properties[ propertyName ];
  15821. var locationProperty = location[ i ][ propertyName ];
  15822. var valueProperty = value[i][ propertyName ];
  15823. switch( property.type ) {
  15824. case 'f':
  15825. _gl.uniform1f( locationProperty, valueProperty );
  15826. break;
  15827. case 'v2':
  15828. _gl.uniform2f( locationProperty, valueProperty.x, valueProperty.y );
  15829. break;
  15830. case 'v3':
  15831. _gl.uniform3f( locationProperty, valueProperty.x, valueProperty.y, valueProperty.z );
  15832. break;
  15833. case 'v4':
  15834. _gl.uniform4f( locationProperty, valueProperty.x, valueProperty.y, valueProperty.z, valueProperty.w );
  15835. break;
  15836. case 'c':
  15837. _gl.uniform3f( locationProperty, valueProperty.r, valueProperty.g, valueProperty.b );
  15838. break;
  15839. };
  15840. }
  15841. }
  15842. break;
  15843. case 'iv1':
  15844. // flat array of integers (JS or typed array)
  15845. _gl.uniform1iv( location, value );
  15846. break;
  15847. case 'iv':
  15848. // flat array of integers with 3 x N size (JS or typed array)
  15849. _gl.uniform3iv( location, value );
  15850. break;
  15851. case 'fv1':
  15852. // flat array of floats (JS or typed array)
  15853. _gl.uniform1fv( location, value );
  15854. break;
  15855. case 'fv':
  15856. // flat array of floats with 3 x N size (JS or typed array)
  15857. _gl.uniform3fv( location, value );
  15858. break;
  15859. case 'v2v':
  15860. // array of THREE.Vector2
  15861. if ( uniform._array === undefined ) {
  15862. uniform._array = new Float32Array( 2 * value.length );
  15863. }
  15864. for ( var i = 0, i2 = 0, il = value.length; i < il; i ++, i2 += 2 ) {
  15865. uniform._array[ i2 + 0 ] = value[ i ].x;
  15866. uniform._array[ i2 + 1 ] = value[ i ].y;
  15867. }
  15868. _gl.uniform2fv( location, uniform._array );
  15869. break;
  15870. case 'v3v':
  15871. // array of THREE.Vector3
  15872. if ( uniform._array === undefined ) {
  15873. uniform._array = new Float32Array( 3 * value.length );
  15874. }
  15875. for ( var i = 0, i3 = 0, il = value.length; i < il; i ++, i3 += 3 ) {
  15876. uniform._array[ i3 + 0 ] = value[ i ].x;
  15877. uniform._array[ i3 + 1 ] = value[ i ].y;
  15878. uniform._array[ i3 + 2 ] = value[ i ].z;
  15879. }
  15880. _gl.uniform3fv( location, uniform._array );
  15881. break;
  15882. case 'v4v':
  15883. // array of THREE.Vector4
  15884. if ( uniform._array === undefined ) {
  15885. uniform._array = new Float32Array( 4 * value.length );
  15886. }
  15887. for ( var i = 0, i4 = 0, il = value.length; i < il; i ++, i4 += 4 ) {
  15888. uniform._array[ i4 + 0 ] = value[ i ].x;
  15889. uniform._array[ i4 + 1 ] = value[ i ].y;
  15890. uniform._array[ i4 + 2 ] = value[ i ].z;
  15891. uniform._array[ i4 + 3 ] = value[ i ].w;
  15892. }
  15893. _gl.uniform4fv( location, uniform._array );
  15894. break;
  15895. case 'm3':
  15896. // single THREE.Matrix3
  15897. _gl.uniformMatrix3fv( location, false, value.elements );
  15898. break;
  15899. case 'm3v':
  15900. // array of THREE.Matrix3
  15901. if ( uniform._array === undefined ) {
  15902. uniform._array = new Float32Array( 9 * value.length );
  15903. }
  15904. for ( var i = 0, il = value.length; i < il; i ++ ) {
  15905. value[ i ].flattenToArrayOffset( uniform._array, i * 9 );
  15906. }
  15907. _gl.uniformMatrix3fv( location, false, uniform._array );
  15908. break;
  15909. case 'm4':
  15910. // single THREE.Matrix4
  15911. _gl.uniformMatrix4fv( location, false, value.elements );
  15912. break;
  15913. case 'm4v':
  15914. // array of THREE.Matrix4
  15915. if ( uniform._array === undefined ) {
  15916. uniform._array = new Float32Array( 16 * value.length );
  15917. }
  15918. for ( var i = 0, il = value.length; i < il; i ++ ) {
  15919. value[ i ].flattenToArrayOffset( uniform._array, i * 16 );
  15920. }
  15921. _gl.uniformMatrix4fv( location, false, uniform._array );
  15922. break;
  15923. case 't':
  15924. // single THREE.Texture (2d or cube)
  15925. texture = value;
  15926. textureUnit = getTextureUnit();
  15927. _gl.uniform1i( location, textureUnit );
  15928. if ( ! texture ) continue;
  15929. if ( texture instanceof THREE.CubeTexture ||
  15930. ( Array.isArray( texture.image ) && texture.image.length === 6 ) ) {
  15931. // CompressedTexture can have Array in image :/
  15932. setCubeTexture( texture, textureUnit );
  15933. } else if ( texture instanceof THREE.WebGLRenderTargetCube ) {
  15934. setCubeTextureDynamic( texture.texture, textureUnit );
  15935. } else if ( texture instanceof THREE.WebGLRenderTarget ) {
  15936. _this.setTexture( texture.texture, textureUnit );
  15937. } else {
  15938. _this.setTexture( texture, textureUnit );
  15939. }
  15940. break;
  15941. case 'tv':
  15942. // array of THREE.Texture (2d or cube)
  15943. if ( uniform._array === undefined ) {
  15944. uniform._array = [];
  15945. }
  15946. for ( var i = 0, il = uniform.value.length; i < il; i ++ ) {
  15947. uniform._array[ i ] = getTextureUnit();
  15948. }
  15949. _gl.uniform1iv( location, uniform._array );
  15950. for ( var i = 0, il = uniform.value.length; i < il; i ++ ) {
  15951. texture = uniform.value[ i ];
  15952. textureUnit = uniform._array[ i ];
  15953. if ( ! texture ) continue;
  15954. if ( texture instanceof THREE.CubeTexture ||
  15955. ( texture.image instanceof Array && texture.image.length === 6 ) ) {
  15956. // CompressedTexture can have Array in image :/
  15957. setCubeTexture( texture, textureUnit );
  15958. } else if ( texture instanceof THREE.WebGLRenderTarget ) {
  15959. _this.setTexture( texture.texture, textureUnit );
  15960. } else if ( texture instanceof THREE.WebGLRenderTargetCube ) {
  15961. setCubeTextureDynamic( texture.texture, textureUnit );
  15962. } else {
  15963. _this.setTexture( texture, textureUnit );
  15964. }
  15965. }
  15966. break;
  15967. default:
  15968. console.warn( 'THREE.WebGLRenderer: Unknown uniform type: ' + type );
  15969. }
  15970. }
  15971. }
  15972. function setupLights ( lights, camera ) {
  15973. var l, ll, light,
  15974. r = 0, g = 0, b = 0,
  15975. color,
  15976. intensity,
  15977. distance,
  15978. viewMatrix = camera.matrixWorldInverse,
  15979. writeIndexDirectional = 0,
  15980. writeIndexPoint = 0,
  15981. writeIndexSpot = 0,
  15982. writeIndexHemi = 0;
  15983. for ( l = 0, ll = lights.length; l < ll; l ++ ) {
  15984. light = lights[ l ];
  15985. color = light.color;
  15986. intensity = light.intensity;
  15987. distance = light.distance;
  15988. if ( light instanceof THREE.AmbientLight ) {
  15989. r += color.r;
  15990. g += color.g;
  15991. b += color.b;
  15992. } else if ( light instanceof THREE.DirectionalLight ) {
  15993. if( ! light.__webglUniforms ) {
  15994. light.__webglUniforms = {
  15995. direction: new THREE.Vector3(),
  15996. color: new THREE.Color()
  15997. }
  15998. }
  15999. var uniforms = light.__webglUniforms;
  16000. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  16001. _vector3.setFromMatrixPosition( light.target.matrixWorld );
  16002. uniforms.direction.sub( _vector3 );
  16003. uniforms.direction.transformDirection( viewMatrix );
  16004. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  16005. _lights.directional[ writeIndexDirectional ++ ] = uniforms;
  16006. } else if ( light instanceof THREE.PointLight ) {
  16007. if( ! light.__webglUniforms ) {
  16008. light.__webglUniforms = {
  16009. position: new THREE.Vector3(),
  16010. color: new THREE.Color(),
  16011. distance: 0,
  16012. decay: 0
  16013. }
  16014. }
  16015. var uniforms = light.__webglUniforms;
  16016. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  16017. uniforms.position.applyMatrix4( viewMatrix );
  16018. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  16019. uniforms.distance = light.distance;
  16020. uniforms.decay = ( light.distance === 0 ) ? 0.0 : light.decay;
  16021. _lights.point[ writeIndexPoint ++ ] = uniforms;
  16022. } else if ( light instanceof THREE.SpotLight ) {
  16023. if( ! light.__webglUniforms ) {
  16024. light.__webglUniforms = {
  16025. position: new THREE.Vector3(),
  16026. direction: new THREE.Vector3(),
  16027. color: new THREE.Color(),
  16028. distance: 0,
  16029. decay: 0,
  16030. angleCos: 0
  16031. }
  16032. }
  16033. var uniforms = light.__webglUniforms;
  16034. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  16035. uniforms.position.applyMatrix4( viewMatrix );
  16036. uniforms.color.copy( color ).multiplyScalar( intensity );
  16037. uniforms.distance = distance;
  16038. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  16039. _vector3.setFromMatrixPosition( light.target.matrixWorld );
  16040. uniforms.direction.sub( _vector3 );
  16041. uniforms.direction.transformDirection( viewMatrix );
  16042. uniforms.angleCos = Math.cos( light.angle );
  16043. uniforms.exponent = light.exponent;
  16044. uniforms.decay = ( light.distance === 0 ) ? 0.0 : light.decay;
  16045. _lights.spot[ writeIndexSpot ++ ] = uniforms;
  16046. } else if ( light instanceof THREE.HemisphereLight ) {
  16047. if( ! light.__webglUniforms ) {
  16048. light.__webglUniforms = {
  16049. direction: new THREE.Vector3(),
  16050. skyColor: new THREE.Color(),
  16051. groundColor: new THREE.Color()
  16052. }
  16053. }
  16054. var uniforms = light.__webglUniforms;
  16055. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  16056. uniforms.direction.transformDirection( viewMatrix );
  16057. uniforms.direction.normalize();
  16058. uniforms.skyColor.copy( light.color ).multiplyScalar( intensity );
  16059. uniforms.groundColor.copy( light.groundColor ).multiplyScalar( intensity );
  16060. _lights.hemi[ writeIndexHemi ++ ] = uniforms;
  16061. }
  16062. }
  16063. _lights.ambient[ 0 ] = r;
  16064. _lights.ambient[ 1 ] = g;
  16065. _lights.ambient[ 2 ] = b;
  16066. _lights.directional.length = writeIndexDirectional;
  16067. _lights.point.length = writeIndexPoint;
  16068. _lights.spot.length = writeIndexSpot;
  16069. _lights.hemi.length = writeIndexHemi;
  16070. }
  16071. // GL state setting
  16072. this.setFaceCulling = function ( cullFace, frontFaceDirection ) {
  16073. if ( cullFace === THREE.CullFaceNone ) {
  16074. state.disable( _gl.CULL_FACE );
  16075. } else {
  16076. if ( frontFaceDirection === THREE.FrontFaceDirectionCW ) {
  16077. _gl.frontFace( _gl.CW );
  16078. } else {
  16079. _gl.frontFace( _gl.CCW );
  16080. }
  16081. if ( cullFace === THREE.CullFaceBack ) {
  16082. _gl.cullFace( _gl.BACK );
  16083. } else if ( cullFace === THREE.CullFaceFront ) {
  16084. _gl.cullFace( _gl.FRONT );
  16085. } else {
  16086. _gl.cullFace( _gl.FRONT_AND_BACK );
  16087. }
  16088. state.enable( _gl.CULL_FACE );
  16089. }
  16090. };
  16091. // Textures
  16092. function setTextureParameters ( textureType, texture, isImagePowerOfTwo ) {
  16093. var extension;
  16094. if ( isImagePowerOfTwo ) {
  16095. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, paramThreeToGL( texture.wrapS ) );
  16096. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, paramThreeToGL( texture.wrapT ) );
  16097. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, paramThreeToGL( texture.magFilter ) );
  16098. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, paramThreeToGL( texture.minFilter ) );
  16099. } else {
  16100. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, _gl.CLAMP_TO_EDGE );
  16101. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, _gl.CLAMP_TO_EDGE );
  16102. if ( texture.wrapS !== THREE.ClampToEdgeWrapping || texture.wrapT !== THREE.ClampToEdgeWrapping ) {
  16103. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.', texture );
  16104. }
  16105. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, filterFallback( texture.magFilter ) );
  16106. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, filterFallback( texture.minFilter ) );
  16107. if ( texture.minFilter !== THREE.NearestFilter && texture.minFilter !== THREE.LinearFilter ) {
  16108. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.', texture );
  16109. }
  16110. }
  16111. extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  16112. if ( extension ) {
  16113. if ( texture.type === THREE.FloatType && extensions.get( 'OES_texture_float_linear' ) === null ) return;
  16114. if ( texture.type === THREE.HalfFloatType && extensions.get( 'OES_texture_half_float_linear' ) === null ) return;
  16115. if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
  16116. _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, _this.getMaxAnisotropy() ) );
  16117. properties.get( texture ).__currentAnisotropy = texture.anisotropy;
  16118. }
  16119. }
  16120. }
  16121. function uploadTexture( textureProperties, texture, slot ) {
  16122. if ( textureProperties.__webglInit === undefined ) {
  16123. textureProperties.__webglInit = true;
  16124. texture.addEventListener( 'dispose', onTextureDispose );
  16125. textureProperties.__webglTexture = _gl.createTexture();
  16126. _infoMemory.textures ++;
  16127. }
  16128. state.activeTexture( _gl.TEXTURE0 + slot );
  16129. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  16130. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  16131. _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );
  16132. _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
  16133. texture.image = clampToMaxSize( texture.image, capabilities.maxTextureSize );
  16134. if ( textureNeedsPowerOfTwo( texture ) && isPowerOfTwo( texture.image ) === false ) {
  16135. texture.image = makePowerOfTwo( texture.image );
  16136. }
  16137. var image = texture.image,
  16138. isImagePowerOfTwo = isPowerOfTwo( image ),
  16139. glFormat = paramThreeToGL( texture.format ),
  16140. glType = paramThreeToGL( texture.type );
  16141. setTextureParameters( _gl.TEXTURE_2D, texture, isImagePowerOfTwo );
  16142. var mipmap, mipmaps = texture.mipmaps;
  16143. if ( texture instanceof THREE.DataTexture ) {
  16144. // use manually created mipmaps if available
  16145. // if there are no manual mipmaps
  16146. // set 0 level mipmap and then use GL to generate other mipmap levels
  16147. if ( mipmaps.length > 0 && isImagePowerOfTwo ) {
  16148. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  16149. mipmap = mipmaps[ i ];
  16150. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  16151. }
  16152. texture.generateMipmaps = false;
  16153. } else {
  16154. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, image.width, image.height, 0, glFormat, glType, image.data );
  16155. }
  16156. } else if ( texture instanceof THREE.CompressedTexture ) {
  16157. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  16158. mipmap = mipmaps[ i ];
  16159. if ( texture.format !== THREE.RGBAFormat && texture.format !== THREE.RGBFormat ) {
  16160. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  16161. state.compressedTexImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  16162. } else {
  16163. console.warn( "THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()" );
  16164. }
  16165. } else {
  16166. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  16167. }
  16168. }
  16169. } else {
  16170. // regular Texture (image, video, canvas)
  16171. // use manually created mipmaps if available
  16172. // if there are no manual mipmaps
  16173. // set 0 level mipmap and then use GL to generate other mipmap levels
  16174. if ( mipmaps.length > 0 && isImagePowerOfTwo ) {
  16175. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  16176. mipmap = mipmaps[ i ];
  16177. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, glFormat, glType, mipmap );
  16178. }
  16179. texture.generateMipmaps = false;
  16180. } else {
  16181. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, glFormat, glType, texture.image );
  16182. }
  16183. }
  16184. if ( texture.generateMipmaps && isImagePowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_2D );
  16185. textureProperties.__version = texture.version;
  16186. if ( texture.onUpdate ) texture.onUpdate( texture );
  16187. }
  16188. this.setTexture = function ( texture, slot ) {
  16189. var textureProperties = properties.get( texture );
  16190. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  16191. var image = texture.image;
  16192. if ( image === undefined ) {
  16193. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is undefined', texture );
  16194. return;
  16195. }
  16196. if ( image.complete === false ) {
  16197. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete', texture );
  16198. return;
  16199. }
  16200. uploadTexture( textureProperties, texture, slot );
  16201. return;
  16202. }
  16203. state.activeTexture( _gl.TEXTURE0 + slot );
  16204. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  16205. };
  16206. function clampToMaxSize ( image, maxSize ) {
  16207. if ( image.width > maxSize || image.height > maxSize ) {
  16208. // Warning: Scaling through the canvas will only work with images that use
  16209. // premultiplied alpha.
  16210. var scale = maxSize / Math.max( image.width, image.height );
  16211. var canvas = document.createElement( 'canvas' );
  16212. canvas.width = Math.floor( image.width * scale );
  16213. canvas.height = Math.floor( image.height * scale );
  16214. var context = canvas.getContext( '2d' );
  16215. context.drawImage( image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height );
  16216. console.warn( 'THREE.WebGLRenderer: image is too big (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
  16217. return canvas;
  16218. }
  16219. return image;
  16220. }
  16221. function isPowerOfTwo( image ) {
  16222. return THREE.Math.isPowerOfTwo( image.width ) && THREE.Math.isPowerOfTwo( image.height );
  16223. }
  16224. function textureNeedsPowerOfTwo( texture ) {
  16225. if ( texture.wrapS !== THREE.ClampToEdgeWrapping || texture.wrapT !== THREE.ClampToEdgeWrapping ) return true;
  16226. if ( texture.minFilter !== THREE.NearestFilter && texture.minFilter !== THREE.LinearFilter ) return true;
  16227. return false;
  16228. }
  16229. function makePowerOfTwo( image ) {
  16230. if ( image instanceof HTMLImageElement || image instanceof HTMLCanvasElement ) {
  16231. var canvas = document.createElement( 'canvas' );
  16232. canvas.width = THREE.Math.nearestPowerOfTwo( image.width );
  16233. canvas.height = THREE.Math.nearestPowerOfTwo( image.height );
  16234. var context = canvas.getContext( '2d' );
  16235. context.drawImage( image, 0, 0, canvas.width, canvas.height );
  16236. console.warn( 'THREE.WebGLRenderer: image is not power of two (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
  16237. return canvas;
  16238. }
  16239. return image;
  16240. }
  16241. function setCubeTexture ( texture, slot ) {
  16242. var textureProperties = properties.get( texture );
  16243. if ( texture.image.length === 6 ) {
  16244. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  16245. if ( ! textureProperties.__image__webglTextureCube ) {
  16246. texture.addEventListener( 'dispose', onTextureDispose );
  16247. textureProperties.__image__webglTextureCube = _gl.createTexture();
  16248. _infoMemory.textures ++;
  16249. }
  16250. state.activeTexture( _gl.TEXTURE0 + slot );
  16251. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  16252. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  16253. var isCompressed = texture instanceof THREE.CompressedTexture;
  16254. var isDataTexture = texture.image[ 0 ] instanceof THREE.DataTexture;
  16255. var cubeImage = [];
  16256. for ( var i = 0; i < 6; i ++ ) {
  16257. if ( _this.autoScaleCubemaps && ! isCompressed && ! isDataTexture ) {
  16258. cubeImage[ i ] = clampToMaxSize( texture.image[ i ], capabilities.maxCubemapSize );
  16259. } else {
  16260. cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
  16261. }
  16262. }
  16263. var image = cubeImage[ 0 ],
  16264. isImagePowerOfTwo = isPowerOfTwo( image ),
  16265. glFormat = paramThreeToGL( texture.format ),
  16266. glType = paramThreeToGL( texture.type );
  16267. setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture, isImagePowerOfTwo );
  16268. for ( var i = 0; i < 6; i ++ ) {
  16269. if ( ! isCompressed ) {
  16270. if ( isDataTexture ) {
  16271. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
  16272. } else {
  16273. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, glFormat, glType, cubeImage[ i ] );
  16274. }
  16275. } else {
  16276. var mipmap, mipmaps = cubeImage[ i ].mipmaps;
  16277. for ( var j = 0, jl = mipmaps.length; j < jl; j ++ ) {
  16278. mipmap = mipmaps[ j ];
  16279. if ( texture.format !== THREE.RGBAFormat && texture.format !== THREE.RGBFormat ) {
  16280. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  16281. state.compressedTexImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  16282. } else {
  16283. console.warn( "THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setCubeTexture()" );
  16284. }
  16285. } else {
  16286. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  16287. }
  16288. }
  16289. }
  16290. }
  16291. if ( texture.generateMipmaps && isImagePowerOfTwo ) {
  16292. _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  16293. }
  16294. textureProperties.__version = texture.version;
  16295. if ( texture.onUpdate ) texture.onUpdate( texture );
  16296. } else {
  16297. state.activeTexture( _gl.TEXTURE0 + slot );
  16298. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  16299. }
  16300. }
  16301. }
  16302. function setCubeTextureDynamic ( texture, slot ) {
  16303. state.activeTexture( _gl.TEXTURE0 + slot );
  16304. state.bindTexture( _gl.TEXTURE_CUBE_MAP, properties.get( texture ).__webglTexture );
  16305. }
  16306. // Render targets
  16307. function setupFrameBuffer ( framebuffer, renderTarget, textureTarget ) {
  16308. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  16309. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, textureTarget, properties.get( renderTarget.texture ).__webglTexture, 0 );
  16310. }
  16311. function setupRenderBuffer ( renderbuffer, renderTarget ) {
  16312. _gl.bindRenderbuffer( _gl.RENDERBUFFER, renderbuffer );
  16313. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  16314. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_COMPONENT16, renderTarget.width, renderTarget.height );
  16315. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  16316. /* For some reason this is not working. Defaulting to RGBA4.
  16317. } else if ( ! renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  16318. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.STENCIL_INDEX8, renderTarget.width, renderTarget.height );
  16319. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  16320. */
  16321. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  16322. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_STENCIL, renderTarget.width, renderTarget.height );
  16323. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  16324. } else {
  16325. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.RGBA4, renderTarget.width, renderTarget.height );
  16326. }
  16327. }
  16328. this.setRenderTarget = function ( renderTarget ) {
  16329. var isCube = ( renderTarget instanceof THREE.WebGLRenderTargetCube );
  16330. if ( renderTarget && properties.get( renderTarget ).__webglFramebuffer === undefined ) {
  16331. var renderTargetProperties = properties.get( renderTarget );
  16332. var textureProperties = properties.get( renderTarget.texture );
  16333. if ( renderTarget.depthBuffer === undefined ) renderTarget.depthBuffer = true;
  16334. if ( renderTarget.stencilBuffer === undefined ) renderTarget.stencilBuffer = true;
  16335. renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
  16336. textureProperties.__webglTexture = _gl.createTexture();
  16337. _infoMemory.textures ++;
  16338. // Setup texture, create render and frame buffers
  16339. var isTargetPowerOfTwo = isPowerOfTwo( renderTarget ),
  16340. glFormat = paramThreeToGL( renderTarget.texture.format ),
  16341. glType = paramThreeToGL( renderTarget.texture.type );
  16342. if ( isCube ) {
  16343. renderTargetProperties.__webglFramebuffer = [];
  16344. renderTargetProperties.__webglRenderbuffer = [];
  16345. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__webglTexture );
  16346. setTextureParameters( _gl.TEXTURE_CUBE_MAP, renderTarget.texture, isTargetPowerOfTwo );
  16347. for ( var i = 0; i < 6; i ++ ) {
  16348. renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer();
  16349. renderTargetProperties.__webglRenderbuffer[ i ] = _gl.createRenderbuffer();
  16350. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  16351. setupFrameBuffer( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i );
  16352. setupRenderBuffer( renderTargetProperties.__webglRenderbuffer[ i ], renderTarget );
  16353. }
  16354. if ( renderTarget.texture.generateMipmaps && isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  16355. } else {
  16356. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  16357. if ( renderTarget.shareDepthFrom ) {
  16358. renderTargetProperties.__webglRenderbuffer = renderTarget.shareDepthFrom.__webglRenderbuffer;
  16359. } else {
  16360. renderTargetProperties.__webglRenderbuffer = _gl.createRenderbuffer();
  16361. }
  16362. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  16363. setTextureParameters( _gl.TEXTURE_2D, renderTarget.texture, isTargetPowerOfTwo );
  16364. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  16365. setupFrameBuffer( renderTargetProperties.__webglFramebuffer, renderTarget, _gl.TEXTURE_2D );
  16366. if ( renderTarget.shareDepthFrom ) {
  16367. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  16368. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderTargetProperties.__webglRenderbuffer );
  16369. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  16370. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderTargetProperties.__webglRenderbuffer );
  16371. }
  16372. } else {
  16373. setupRenderBuffer( renderTargetProperties.__webglRenderbuffer, renderTarget );
  16374. }
  16375. if ( renderTarget.texture.generateMipmaps && isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_2D );
  16376. }
  16377. // Release everything
  16378. if ( isCube ) {
  16379. state.bindTexture( _gl.TEXTURE_CUBE_MAP, null );
  16380. } else {
  16381. state.bindTexture( _gl.TEXTURE_2D, null );
  16382. }
  16383. _gl.bindRenderbuffer( _gl.RENDERBUFFER, null );
  16384. _gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
  16385. }
  16386. var framebuffer, width, height, vx, vy;
  16387. if ( renderTarget ) {
  16388. var renderTargetProperties = properties.get( renderTarget );
  16389. if ( isCube ) {
  16390. framebuffer = renderTargetProperties.__webglFramebuffer[ renderTarget.activeCubeFace ];
  16391. } else {
  16392. framebuffer = renderTargetProperties.__webglFramebuffer;
  16393. }
  16394. width = renderTarget.width;
  16395. height = renderTarget.height;
  16396. vx = 0;
  16397. vy = 0;
  16398. } else {
  16399. framebuffer = null;
  16400. width = _viewportWidth;
  16401. height = _viewportHeight;
  16402. vx = _viewportX;
  16403. vy = _viewportY;
  16404. }
  16405. if ( framebuffer !== _currentFramebuffer ) {
  16406. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  16407. _gl.viewport( vx, vy, width, height );
  16408. _currentFramebuffer = framebuffer;
  16409. }
  16410. if ( isCube ) {
  16411. var textureProperties = properties.get( renderTarget.texture );
  16412. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + renderTarget.activeCubeFace, textureProperties.__webglTexture, 0 );
  16413. }
  16414. _currentWidth = width;
  16415. _currentHeight = height;
  16416. };
  16417. this.readRenderTargetPixels = function ( renderTarget, x, y, width, height, buffer ) {
  16418. if ( renderTarget instanceof THREE.WebGLRenderTarget === false ) {
  16419. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
  16420. return;
  16421. }
  16422. var framebuffer = properties.get( renderTarget ).__webglFramebuffer;
  16423. if ( framebuffer ) {
  16424. var restore = false;
  16425. if ( framebuffer !== _currentFramebuffer ) {
  16426. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  16427. restore = true;
  16428. }
  16429. try {
  16430. var texture = renderTarget.texture;
  16431. if ( texture.format !== THREE.RGBAFormat
  16432. && paramThreeToGL( texture.format ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_FORMAT ) ) {
  16433. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
  16434. return;
  16435. }
  16436. if ( texture.type !== THREE.UnsignedByteType
  16437. && paramThreeToGL( texture.type ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_TYPE )
  16438. && ! ( texture.type === THREE.FloatType && extensions.get( 'WEBGL_color_buffer_float' ) )
  16439. && ! ( texture.type === THREE.HalfFloatType && extensions.get( 'EXT_color_buffer_half_float' ) ) ) {
  16440. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' );
  16441. return;
  16442. }
  16443. if ( _gl.checkFramebufferStatus( _gl.FRAMEBUFFER ) === _gl.FRAMEBUFFER_COMPLETE ) {
  16444. _gl.readPixels( x, y, width, height, paramThreeToGL( texture.format ), paramThreeToGL( texture.type ), buffer );
  16445. } else {
  16446. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );
  16447. }
  16448. } finally {
  16449. if ( restore ) {
  16450. _gl.bindFramebuffer( _gl.FRAMEBUFFER, _currentFramebuffer );
  16451. }
  16452. }
  16453. }
  16454. };
  16455. function updateRenderTargetMipmap( renderTarget ) {
  16456. var target = renderTarget instanceof THREE.WebGLRenderTargetCube ? _gl.TEXTURE_CUBE_MAP : _gl.TEXTURE_2D;
  16457. var texture = properties.get( renderTarget.texture ).__webglTexture;
  16458. state.bindTexture( target, texture );
  16459. _gl.generateMipmap( target );
  16460. state.bindTexture( target, null );
  16461. }
  16462. // Fallback filters for non-power-of-2 textures
  16463. function filterFallback ( f ) {
  16464. if ( f === THREE.NearestFilter || f === THREE.NearestMipMapNearestFilter || f === THREE.NearestMipMapLinearFilter ) {
  16465. return _gl.NEAREST;
  16466. }
  16467. return _gl.LINEAR;
  16468. }
  16469. // Map three.js constants to WebGL constants
  16470. function paramThreeToGL ( p ) {
  16471. var extension;
  16472. if ( p === THREE.RepeatWrapping ) return _gl.REPEAT;
  16473. if ( p === THREE.ClampToEdgeWrapping ) return _gl.CLAMP_TO_EDGE;
  16474. if ( p === THREE.MirroredRepeatWrapping ) return _gl.MIRRORED_REPEAT;
  16475. if ( p === THREE.NearestFilter ) return _gl.NEAREST;
  16476. if ( p === THREE.NearestMipMapNearestFilter ) return _gl.NEAREST_MIPMAP_NEAREST;
  16477. if ( p === THREE.NearestMipMapLinearFilter ) return _gl.NEAREST_MIPMAP_LINEAR;
  16478. if ( p === THREE.LinearFilter ) return _gl.LINEAR;
  16479. if ( p === THREE.LinearMipMapNearestFilter ) return _gl.LINEAR_MIPMAP_NEAREST;
  16480. if ( p === THREE.LinearMipMapLinearFilter ) return _gl.LINEAR_MIPMAP_LINEAR;
  16481. if ( p === THREE.UnsignedByteType ) return _gl.UNSIGNED_BYTE;
  16482. if ( p === THREE.UnsignedShort4444Type ) return _gl.UNSIGNED_SHORT_4_4_4_4;
  16483. if ( p === THREE.UnsignedShort5551Type ) return _gl.UNSIGNED_SHORT_5_5_5_1;
  16484. if ( p === THREE.UnsignedShort565Type ) return _gl.UNSIGNED_SHORT_5_6_5;
  16485. if ( p === THREE.ByteType ) return _gl.BYTE;
  16486. if ( p === THREE.ShortType ) return _gl.SHORT;
  16487. if ( p === THREE.UnsignedShortType ) return _gl.UNSIGNED_SHORT;
  16488. if ( p === THREE.IntType ) return _gl.INT;
  16489. if ( p === THREE.UnsignedIntType ) return _gl.UNSIGNED_INT;
  16490. if ( p === THREE.FloatType ) return _gl.FLOAT;
  16491. extension = extensions.get( 'OES_texture_half_float' );
  16492. if ( extension !== null ) {
  16493. if ( p === THREE.HalfFloatType ) return extension.HALF_FLOAT_OES;
  16494. }
  16495. if ( p === THREE.AlphaFormat ) return _gl.ALPHA;
  16496. if ( p === THREE.RGBFormat ) return _gl.RGB;
  16497. if ( p === THREE.RGBAFormat ) return _gl.RGBA;
  16498. if ( p === THREE.LuminanceFormat ) return _gl.LUMINANCE;
  16499. if ( p === THREE.LuminanceAlphaFormat ) return _gl.LUMINANCE_ALPHA;
  16500. if ( p === THREE.AddEquation ) return _gl.FUNC_ADD;
  16501. if ( p === THREE.SubtractEquation ) return _gl.FUNC_SUBTRACT;
  16502. if ( p === THREE.ReverseSubtractEquation ) return _gl.FUNC_REVERSE_SUBTRACT;
  16503. if ( p === THREE.ZeroFactor ) return _gl.ZERO;
  16504. if ( p === THREE.OneFactor ) return _gl.ONE;
  16505. if ( p === THREE.SrcColorFactor ) return _gl.SRC_COLOR;
  16506. if ( p === THREE.OneMinusSrcColorFactor ) return _gl.ONE_MINUS_SRC_COLOR;
  16507. if ( p === THREE.SrcAlphaFactor ) return _gl.SRC_ALPHA;
  16508. if ( p === THREE.OneMinusSrcAlphaFactor ) return _gl.ONE_MINUS_SRC_ALPHA;
  16509. if ( p === THREE.DstAlphaFactor ) return _gl.DST_ALPHA;
  16510. if ( p === THREE.OneMinusDstAlphaFactor ) return _gl.ONE_MINUS_DST_ALPHA;
  16511. if ( p === THREE.DstColorFactor ) return _gl.DST_COLOR;
  16512. if ( p === THREE.OneMinusDstColorFactor ) return _gl.ONE_MINUS_DST_COLOR;
  16513. if ( p === THREE.SrcAlphaSaturateFactor ) return _gl.SRC_ALPHA_SATURATE;
  16514. extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );
  16515. if ( extension !== null ) {
  16516. if ( p === THREE.RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  16517. if ( p === THREE.RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  16518. if ( p === THREE.RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  16519. if ( p === THREE.RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  16520. }
  16521. extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  16522. if ( extension !== null ) {
  16523. if ( p === THREE.RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  16524. if ( p === THREE.RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  16525. if ( p === THREE.RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  16526. if ( p === THREE.RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  16527. }
  16528. extension = extensions.get( 'EXT_blend_minmax' );
  16529. if ( extension !== null ) {
  16530. if ( p === THREE.MinEquation ) return extension.MIN_EXT;
  16531. if ( p === THREE.MaxEquation ) return extension.MAX_EXT;
  16532. }
  16533. return 0;
  16534. }
  16535. };
  16536. // File:src/renderers/WebGLRenderTarget.js
  16537. /**
  16538. * @author szimek / https://github.com/szimek/
  16539. * @author alteredq / http://alteredqualia.com/
  16540. */
  16541. THREE.WebGLRenderTarget = function ( width, height, options ) {
  16542. this.uuid = THREE.Math.generateUUID();
  16543. this.width = width;
  16544. this.height = height;
  16545. options = options || {};
  16546. if ( options.minFilter === undefined ) options.minFilter = THREE.LinearFilter;
  16547. this.texture = new THREE.Texture( undefined, undefined, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy );
  16548. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  16549. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;
  16550. this.shareDepthFrom = options.shareDepthFrom !== undefined ? options.shareDepthFrom : null;
  16551. };
  16552. THREE.WebGLRenderTarget.prototype = {
  16553. constructor: THREE.WebGLRenderTarget,
  16554. setSize: function ( width, height ) {
  16555. if ( this.width !== width || this.height !== height ) {
  16556. this.width = width;
  16557. this.height = height;
  16558. this.dispose();
  16559. }
  16560. },
  16561. clone: function () {
  16562. return new this.constructor().copy( this );
  16563. },
  16564. copy: function ( source ) {
  16565. this.width = source.width;
  16566. this.height = source.height;
  16567. this.texture = source.texture.clone();
  16568. this.depthBuffer = source.depthBuffer;
  16569. this.stencilBuffer = source.stencilBuffer;
  16570. this.shareDepthFrom = source.shareDepthFrom;
  16571. return this;
  16572. },
  16573. dispose: function () {
  16574. this.dispatchEvent( { type: 'dispose' } );
  16575. }
  16576. };
  16577. THREE.EventDispatcher.prototype.apply( THREE.WebGLRenderTarget.prototype );
  16578. // File:src/renderers/WebGLRenderTargetCube.js
  16579. /**
  16580. * @author alteredq / http://alteredqualia.com
  16581. */
  16582. THREE.WebGLRenderTargetCube = function ( width, height, options ) {
  16583. THREE.WebGLRenderTarget.call( this, width, height, options );
  16584. this.activeCubeFace = 0; // PX 0, NX 1, PY 2, NY 3, PZ 4, NZ 5
  16585. };
  16586. THREE.WebGLRenderTargetCube.prototype = Object.create( THREE.WebGLRenderTarget.prototype );
  16587. THREE.WebGLRenderTargetCube.prototype.constructor = THREE.WebGLRenderTargetCube;
  16588. // File:src/renderers/webgl/WebGLBufferRenderer.js
  16589. /**
  16590. * @author mrdoob / http://mrdoob.com/
  16591. */
  16592. THREE.WebGLBufferRenderer = function ( _gl, extensions, _infoRender ) {
  16593. var mode;
  16594. function setMode( value ) {
  16595. mode = value;
  16596. }
  16597. function render( start, count ) {
  16598. _gl.drawArrays( mode, start, count );
  16599. _infoRender.calls ++;
  16600. _infoRender.vertices += count;
  16601. if ( mode === _gl.TRIANGLES ) _infoRender.faces += count / 3;
  16602. }
  16603. function renderInstances( geometry ) {
  16604. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  16605. if ( extension === null ) {
  16606. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  16607. return;
  16608. }
  16609. var position = geometry.attributes.position;
  16610. if ( position instanceof THREE.InterleavedBufferAttribute ) {
  16611. extension.drawArraysInstancedANGLE( mode, 0, position.data.count, geometry.maxInstancedCount );
  16612. } else {
  16613. extension.drawArraysInstancedANGLE( mode, 0, position.count, geometry.maxInstancedCount );
  16614. }
  16615. }
  16616. this.setMode = setMode;
  16617. this.render = render;
  16618. this.renderInstances = renderInstances;
  16619. };
  16620. // File:src/renderers/webgl/WebGLIndexedBufferRenderer.js
  16621. /**
  16622. * @author mrdoob / http://mrdoob.com/
  16623. */
  16624. THREE.WebGLIndexedBufferRenderer = function ( _gl, extensions, _infoRender ) {
  16625. var mode;
  16626. function setMode( value ) {
  16627. mode = value;
  16628. }
  16629. var type, size;
  16630. function setIndex( index ) {
  16631. if ( index.array instanceof Uint32Array && extensions.get( 'OES_element_index_uint' ) ) {
  16632. type = _gl.UNSIGNED_INT;
  16633. size = 4;
  16634. } else {
  16635. type = _gl.UNSIGNED_SHORT;
  16636. size = 2;
  16637. }
  16638. }
  16639. function render( start, count ) {
  16640. _gl.drawElements( mode, count, type, start * size );
  16641. _infoRender.calls ++;
  16642. _infoRender.vertices += count;
  16643. if ( mode === _gl.TRIANGLES ) _infoRender.faces += count / 3;
  16644. }
  16645. function renderInstances( geometry ) {
  16646. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  16647. if ( extension === null ) {
  16648. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  16649. return;
  16650. }
  16651. var index = geometry.index;
  16652. extension.drawElementsInstancedANGLE( mode, index.array.length, type, 0, geometry.maxInstancedCount );
  16653. }
  16654. this.setMode = setMode;
  16655. this.setIndex = setIndex;
  16656. this.render = render;
  16657. this.renderInstances = renderInstances;
  16658. };
  16659. // File:src/renderers/webgl/WebGLExtensions.js
  16660. /**
  16661. * @author mrdoob / http://mrdoob.com/
  16662. */
  16663. THREE.WebGLExtensions = function ( gl ) {
  16664. var extensions = {};
  16665. this.get = function ( name ) {
  16666. if ( extensions[ name ] !== undefined ) {
  16667. return extensions[ name ];
  16668. }
  16669. var extension;
  16670. switch ( name ) {
  16671. case 'EXT_texture_filter_anisotropic':
  16672. extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' );
  16673. break;
  16674. case 'WEBGL_compressed_texture_s3tc':
  16675. extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' );
  16676. break;
  16677. case 'WEBGL_compressed_texture_pvrtc':
  16678. extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' );
  16679. break;
  16680. default:
  16681. extension = gl.getExtension( name );
  16682. }
  16683. if ( extension === null ) {
  16684. console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
  16685. }
  16686. extensions[ name ] = extension;
  16687. return extension;
  16688. };
  16689. };
  16690. // File:src/renderers/webgl/WebGLCapabilities.js
  16691. THREE.WebGLCapabilities = function ( gl, extensions, parameters ) {
  16692. function getMaxPrecision( precision ) {
  16693. if ( precision === 'highp' ) {
  16694. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.HIGH_FLOAT ).precision > 0 &&
  16695. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.HIGH_FLOAT ).precision > 0 ) {
  16696. return 'highp';
  16697. }
  16698. precision = 'mediump';
  16699. }
  16700. if ( precision === 'mediump' ) {
  16701. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.MEDIUM_FLOAT ).precision > 0 &&
  16702. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.MEDIUM_FLOAT ).precision > 0 ) {
  16703. return 'mediump';
  16704. }
  16705. }
  16706. return 'lowp';
  16707. }
  16708. this.getMaxPrecision = getMaxPrecision;
  16709. this.precision = parameters.precision !== undefined ? parameters.precision : 'highp',
  16710. this.logarithmicDepthBuffer = parameters.logarithmicDepthBuffer !== undefined ? parameters.logarithmicDepthBuffer : false;
  16711. this.maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
  16712. this.maxVertexTextures = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS );
  16713. this.maxTextureSize = gl.getParameter( gl.MAX_TEXTURE_SIZE );
  16714. this.maxCubemapSize = gl.getParameter( gl.MAX_CUBE_MAP_TEXTURE_SIZE );
  16715. this.maxAttributes = gl.getParameter( gl.MAX_VERTEX_ATTRIBS );
  16716. this.maxVertexUniforms = gl.getParameter( gl.MAX_VERTEX_UNIFORM_VECTORS );
  16717. this.maxVaryings = gl.getParameter( gl.MAX_VARYING_VECTORS );
  16718. this.maxFragmentUniforms = gl.getParameter( gl.MAX_FRAGMENT_UNIFORM_VECTORS );
  16719. this.vertexTextures = this.maxVertexTextures > 0;
  16720. this.floatFragmentTextures = !! extensions.get( 'OES_texture_float' );
  16721. this.floatVertexTextures = this.vertexTextures && this.floatFragmentTextures;
  16722. var _maxPrecision = getMaxPrecision( this.precision );
  16723. if ( _maxPrecision !== this.precision ) {
  16724. console.warn( 'THREE.WebGLRenderer:', this.precision, 'not supported, using', _maxPrecision, 'instead.' );
  16725. this.precision = _maxPrecision;
  16726. }
  16727. if ( this.logarithmicDepthBuffer ) {
  16728. this.logarithmicDepthBuffer = !! extensions.get( 'EXT_frag_depth' );
  16729. }
  16730. };
  16731. // File:src/renderers/webgl/WebGLGeometries.js
  16732. /**
  16733. * @author mrdoob / http://mrdoob.com/
  16734. */
  16735. THREE.WebGLGeometries = function ( gl, properties, info ) {
  16736. var geometries = {};
  16737. function get( object ) {
  16738. var geometry = object.geometry;
  16739. if ( geometries[ geometry.id ] !== undefined ) {
  16740. return geometries[ geometry.id ];
  16741. }
  16742. geometry.addEventListener( 'dispose', onGeometryDispose );
  16743. var buffergeometry;
  16744. if ( geometry instanceof THREE.BufferGeometry ) {
  16745. buffergeometry = geometry;
  16746. } else if ( geometry instanceof THREE.Geometry ) {
  16747. if ( geometry._bufferGeometry === undefined ) {
  16748. geometry._bufferGeometry = new THREE.BufferGeometry().setFromObject( object );
  16749. }
  16750. buffergeometry = geometry._bufferGeometry;
  16751. }
  16752. geometries[ geometry.id ] = buffergeometry;
  16753. info.memory.geometries ++;
  16754. return buffergeometry;
  16755. }
  16756. function onGeometryDispose( event ) {
  16757. var geometry = event.target;
  16758. var buffergeometry = geometries[ geometry.id ];
  16759. if ( buffergeometry.index !== null ) {
  16760. deleteAttribute( buffergeometry.index );
  16761. }
  16762. deleteAttributes( buffergeometry.attributes );
  16763. geometry.removeEventListener( 'dispose', onGeometryDispose );
  16764. delete geometries[ geometry.id ];
  16765. var property = properties.get( geometry );
  16766. if ( property.wireframe ) deleteAttribute( property.wireframe );
  16767. info.memory.geometries --;
  16768. }
  16769. function getAttributeBuffer( attribute ) {
  16770. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  16771. return properties.get( attribute.data ).__webglBuffer;
  16772. }
  16773. return properties.get( attribute ).__webglBuffer;
  16774. }
  16775. function deleteAttribute( attribute ) {
  16776. var buffer = getAttributeBuffer( attribute );
  16777. if ( buffer !== undefined ) {
  16778. gl.deleteBuffer( buffer );
  16779. removeAttributeBuffer( attribute );
  16780. }
  16781. }
  16782. function deleteAttributes( attributes ) {
  16783. for ( var name in attributes ) {
  16784. deleteAttribute( attributes[ name ] );
  16785. }
  16786. }
  16787. function removeAttributeBuffer( attribute ) {
  16788. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  16789. properties.delete( attribute.data );
  16790. } else {
  16791. properties.delete( attribute );
  16792. }
  16793. }
  16794. this.get = get;
  16795. };
  16796. // File:src/renderers/webgl/WebGLObjects.js
  16797. /**
  16798. * @author mrdoob / http://mrdoob.com/
  16799. */
  16800. THREE.WebGLObjects = function ( gl, properties, info ) {
  16801. var geometries = new THREE.WebGLGeometries( gl, properties, info );
  16802. //
  16803. function update( object ) {
  16804. // TODO: Avoid updating twice (when using shadowMap). Maybe add frame counter.
  16805. var geometry = geometries.get( object );
  16806. if ( object.geometry instanceof THREE.Geometry ) {
  16807. geometry.updateFromObject( object );
  16808. }
  16809. var index = geometry.index;
  16810. var attributes = geometry.attributes;
  16811. if ( index !== null ) {
  16812. updateAttribute( index, gl.ELEMENT_ARRAY_BUFFER );
  16813. }
  16814. for ( var name in attributes ) {
  16815. updateAttribute( attributes[ name ], gl.ARRAY_BUFFER );
  16816. }
  16817. // morph targets
  16818. var morphAttributes = geometry.morphAttributes;
  16819. for ( var name in morphAttributes ) {
  16820. var array = morphAttributes[ name ];
  16821. for ( var i = 0, l = array.length; i < l; i ++ ) {
  16822. updateAttribute( array[ i ], gl.ARRAY_BUFFER );
  16823. }
  16824. }
  16825. return geometry;
  16826. }
  16827. function updateAttribute( attribute, bufferType ) {
  16828. var data = ( attribute instanceof THREE.InterleavedBufferAttribute ) ? attribute.data : attribute;
  16829. var attributeProperties = properties.get( data );
  16830. if ( attributeProperties.__webglBuffer === undefined ) {
  16831. createBuffer( attributeProperties, data, bufferType );
  16832. } else if ( attributeProperties.version !== data.version ) {
  16833. updateBuffer( attributeProperties, data, bufferType );
  16834. }
  16835. }
  16836. function createBuffer( attributeProperties, data, bufferType ) {
  16837. attributeProperties.__webglBuffer = gl.createBuffer();
  16838. gl.bindBuffer( bufferType, attributeProperties.__webglBuffer );
  16839. var usage = data.dynamic ? gl.DYNAMIC_DRAW : gl.STATIC_DRAW;
  16840. gl.bufferData( bufferType, data.array, usage );
  16841. attributeProperties.version = data.version;
  16842. }
  16843. function updateBuffer( attributeProperties, data, bufferType ) {
  16844. gl.bindBuffer( bufferType, attributeProperties.__webglBuffer );
  16845. if ( data.dynamic === false || data.updateRange.count === - 1 ) {
  16846. // Not using update ranges
  16847. gl.bufferSubData( bufferType, 0, data.array );
  16848. } else if ( data.updateRange.count === 0 ) {
  16849. 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.' );
  16850. } else {
  16851. gl.bufferSubData( bufferType, data.updateRange.offset * data.array.BYTES_PER_ELEMENT,
  16852. data.array.subarray( data.updateRange.offset, data.updateRange.offset + data.updateRange.count ) );
  16853. data.updateRange.count = 0; // reset range
  16854. }
  16855. attributeProperties.version = data.version;
  16856. }
  16857. function getAttributeBuffer( attribute ) {
  16858. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  16859. return properties.get( attribute.data ).__webglBuffer;
  16860. }
  16861. return properties.get( attribute ).__webglBuffer;
  16862. }
  16863. function getWireframeAttribute( geometry ) {
  16864. var property = properties.get( geometry );
  16865. if ( property.wireframe !== undefined ) {
  16866. return property.wireframe;
  16867. }
  16868. var indices = [];
  16869. var index = geometry.index;
  16870. var attributes = geometry.attributes;
  16871. var position = attributes.position;
  16872. // console.time( 'wireframe' );
  16873. if ( index !== null ) {
  16874. var edges = {};
  16875. var array = index.array;
  16876. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  16877. var a = array[ i + 0 ];
  16878. var b = array[ i + 1 ];
  16879. var c = array[ i + 2 ];
  16880. if ( checkEdge( edges, a, b ) ) indices.push( a, b );
  16881. if ( checkEdge( edges, b, c ) ) indices.push( b, c );
  16882. if ( checkEdge( edges, c, a ) ) indices.push( c, a );
  16883. }
  16884. } else {
  16885. var array = attributes.position.array;
  16886. for ( var i = 0, l = ( array.length / 3 ) - 1; i < l; i += 3 ) {
  16887. var a = i + 0;
  16888. var b = i + 1;
  16889. var c = i + 2;
  16890. indices.push( a, b, b, c, c, a );
  16891. }
  16892. }
  16893. // console.timeEnd( 'wireframe' );
  16894. var TypeArray = position.count > 65535 ? Uint32Array : Uint16Array;
  16895. var attribute = new THREE.BufferAttribute( new TypeArray( indices ), 1 );
  16896. updateAttribute( attribute, gl.ELEMENT_ARRAY_BUFFER );
  16897. property.wireframe = attribute;
  16898. return attribute;
  16899. }
  16900. function checkEdge( edges, a, b ) {
  16901. if ( a > b ) {
  16902. var tmp = a;
  16903. a = b;
  16904. b = tmp;
  16905. }
  16906. var list = edges[ a ];
  16907. if ( list === undefined ) {
  16908. edges[ a ] = [ b ];
  16909. return true;
  16910. } else if ( list.indexOf( b ) === -1 ) {
  16911. list.push( b );
  16912. return true;
  16913. }
  16914. return false;
  16915. }
  16916. this.getAttributeBuffer = getAttributeBuffer;
  16917. this.getWireframeAttribute = getWireframeAttribute;
  16918. this.update = update;
  16919. };
  16920. // File:src/renderers/webgl/WebGLProgram.js
  16921. THREE.WebGLProgram = ( function () {
  16922. var programIdCount = 0;
  16923. // TODO: Combine the regex
  16924. var structRe = /^([\w\d_]+)\.([\w\d_]+)$/;
  16925. var arrayStructRe = /^([\w\d_]+)\[(\d+)\]\.([\w\d_]+)$/;
  16926. var arrayRe = /^([\w\d_]+)\[0\]$/;
  16927. function generateExtensions( extensions, parameters, rendererExtensions ) {
  16928. extensions = extensions || {};
  16929. var chunks = [
  16930. ( extensions.derivatives || parameters.bumpMap || parameters.normalMap || parameters.flatShading ) ? '#extension GL_OES_standard_derivatives : enable' : '',
  16931. ( extensions.fragDepth || parameters.logarithmicDepthBuffer ) && rendererExtensions.get( 'EXT_frag_depth' ) ? '#extension GL_EXT_frag_depth : enable' : '',
  16932. ( extensions.drawBuffers ) && rendererExtensions.get( 'WEBGL_draw_buffers' ) ? '#extension GL_EXT_draw_buffers : require' : '',
  16933. ( extensions.shaderTextureLOD || parameters.envMap ) && rendererExtensions.get( 'EXT_shader_texture_lod' ) ? '#extension GL_EXT_shader_texture_lod : enable' : '',
  16934. ];
  16935. return chunks.filter( filterEmptyLine ).join( '\n' );
  16936. }
  16937. function generateDefines( defines ) {
  16938. var chunks = [];
  16939. for ( var name in defines ) {
  16940. var value = defines[ name ];
  16941. if ( value === false ) continue;
  16942. chunks.push( '#define ' + name + ' ' + value );
  16943. }
  16944. return chunks.join( '\n' );
  16945. }
  16946. function fetchUniformLocations( gl, program, identifiers ) {
  16947. var uniforms = {};
  16948. var n = gl.getProgramParameter( program, gl.ACTIVE_UNIFORMS );
  16949. for ( var i = 0; i < n; i ++ ) {
  16950. var info = gl.getActiveUniform( program, i );
  16951. var name = info.name;
  16952. var location = gl.getUniformLocation( program, name );
  16953. //console.log("THREE.WebGLProgram: ACTIVE UNIFORM:", name);
  16954. var matches = structRe.exec(name);
  16955. if( matches ) {
  16956. var structName = matches[1];
  16957. var structProperty = matches[2];
  16958. var uniformsStruct = uniforms[ structName ];
  16959. if( ! uniformsStruct ) {
  16960. uniformsStruct = uniforms[ structName ] = {};
  16961. }
  16962. uniformsStruct[ structProperty ] = location;
  16963. continue;
  16964. }
  16965. matches = arrayStructRe.exec(name);
  16966. if( matches ) {
  16967. var arrayName = matches[1];
  16968. var arrayIndex = matches[2];
  16969. var arrayProperty = matches[3];
  16970. var uniformsArray = uniforms[ arrayName ];
  16971. if( ! uniformsArray ) {
  16972. uniformsArray = uniforms[ arrayName ] = [];
  16973. }
  16974. var uniformsArrayIndex = uniformsArray[ arrayIndex ];
  16975. if( ! uniformsArrayIndex ) {
  16976. uniformsArrayIndex = uniformsArray[ arrayIndex ] = {};
  16977. }
  16978. uniformsArrayIndex[ arrayProperty ] = location;
  16979. continue;
  16980. }
  16981. matches = arrayRe.exec(name)
  16982. if( matches ) {
  16983. var arrayName = matches[1];
  16984. uniforms[ arrayName ] = location;
  16985. continue;
  16986. }
  16987. uniforms[ name ] = location;
  16988. }
  16989. return uniforms;
  16990. }
  16991. function fetchAttributeLocations( gl, program, identifiers ) {
  16992. var attributes = {};
  16993. var n = gl.getProgramParameter( program, gl.ACTIVE_ATTRIBUTES );
  16994. for ( var i = 0; i < n; i ++ ) {
  16995. var info = gl.getActiveAttrib( program, i );
  16996. var name = info.name;
  16997. // console.log("THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:", name, i );
  16998. attributes[ name ] = gl.getAttribLocation( program, name );
  16999. }
  17000. return attributes;
  17001. }
  17002. function filterEmptyLine( string ) {
  17003. return string !== '';
  17004. }
  17005. return function WebGLProgram( renderer, code, material, parameters ) {
  17006. var gl = renderer.context;
  17007. var extensions = material.extensions;
  17008. var defines = material.defines;
  17009. var vertexShader = material.__webglShader.vertexShader;
  17010. var fragmentShader = material.__webglShader.fragmentShader;
  17011. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  17012. if ( parameters.shadowMapType === THREE.PCFShadowMap ) {
  17013. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  17014. } else if ( parameters.shadowMapType === THREE.PCFSoftShadowMap ) {
  17015. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  17016. }
  17017. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  17018. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  17019. var envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  17020. if ( parameters.envMap ) {
  17021. switch ( material.envMap.mapping ) {
  17022. case THREE.CubeReflectionMapping:
  17023. case THREE.CubeRefractionMapping:
  17024. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  17025. break;
  17026. case THREE.EquirectangularReflectionMapping:
  17027. case THREE.EquirectangularRefractionMapping:
  17028. envMapTypeDefine = 'ENVMAP_TYPE_EQUIREC';
  17029. break;
  17030. case THREE.SphericalReflectionMapping:
  17031. envMapTypeDefine = 'ENVMAP_TYPE_SPHERE';
  17032. break;
  17033. }
  17034. switch ( material.envMap.mapping ) {
  17035. case THREE.CubeRefractionMapping:
  17036. case THREE.EquirectangularRefractionMapping:
  17037. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  17038. break;
  17039. }
  17040. switch ( material.combine ) {
  17041. case THREE.MultiplyOperation:
  17042. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  17043. break;
  17044. case THREE.MixOperation:
  17045. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  17046. break;
  17047. case THREE.AddOperation:
  17048. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  17049. break;
  17050. }
  17051. }
  17052. var gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
  17053. // console.log( 'building new program ' );
  17054. //
  17055. var customExtensions = generateExtensions( extensions, parameters, renderer.extensions );
  17056. var customDefines = generateDefines( defines );
  17057. //
  17058. var program = gl.createProgram();
  17059. var prefixVertex, prefixFragment;
  17060. if ( material instanceof THREE.RawShaderMaterial ) {
  17061. prefixVertex = '';
  17062. prefixFragment = '';
  17063. } else {
  17064. prefixVertex = [
  17065. 'precision ' + parameters.precision + ' float;',
  17066. 'precision ' + parameters.precision + ' int;',
  17067. '#define SHADER_NAME ' + material.__webglShader.name,
  17068. customDefines,
  17069. parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '',
  17070. renderer.gammaInput ? '#define GAMMA_INPUT' : '',
  17071. renderer.gammaOutput ? '#define GAMMA_OUTPUT' : '',
  17072. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  17073. '#define MAX_DIR_LIGHTS ' + parameters.maxDirLights,
  17074. '#define MAX_POINT_LIGHTS ' + parameters.maxPointLights,
  17075. '#define MAX_SPOT_LIGHTS ' + parameters.maxSpotLights,
  17076. '#define MAX_HEMI_LIGHTS ' + parameters.maxHemiLights,
  17077. '#define MAX_SHADOWS ' + parameters.maxShadows,
  17078. '#define MAX_BONES ' + parameters.maxBones,
  17079. parameters.map ? '#define USE_MAP' : '',
  17080. parameters.envMap ? '#define USE_ENVMAP' : '',
  17081. parameters.envMap ? '#define ' + envMapModeDefine : '',
  17082. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  17083. parameters.aoMap ? '#define USE_AOMAP' : '',
  17084. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  17085. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  17086. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  17087. parameters.displacementMap && parameters.supportsVertexTextures ? '#define USE_DISPLACEMENTMAP' : '',
  17088. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  17089. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  17090. parameters.reflectivityMap ? '#define USE_REFLECTIVITYMAP' : '',
  17091. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  17092. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  17093. parameters.vertexColors ? '#define USE_COLOR' : '',
  17094. parameters.flatShading ? '#define FLAT_SHADED' : '',
  17095. parameters.skinning ? '#define USE_SKINNING' : '',
  17096. parameters.useVertexTexture ? '#define BONE_TEXTURE' : '',
  17097. parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
  17098. parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '',
  17099. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  17100. parameters.flipSided ? '#define FLIP_SIDED' : '',
  17101. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  17102. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  17103. parameters.shadowMapDebug ? '#define SHADOWMAP_DEBUG' : '',
  17104. parameters.pointLightShadows > 0 ? '#define POINT_LIGHT_SHADOWS' : '',
  17105. parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
  17106. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  17107. parameters.logarithmicDepthBuffer && renderer.extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  17108. 'uniform mat4 modelMatrix;',
  17109. 'uniform mat4 modelViewMatrix;',
  17110. 'uniform mat4 projectionMatrix;',
  17111. 'uniform mat4 viewMatrix;',
  17112. 'uniform mat3 normalMatrix;',
  17113. 'uniform vec3 cameraPosition;',
  17114. 'attribute vec3 position;',
  17115. 'attribute vec3 normal;',
  17116. 'attribute vec2 uv;',
  17117. '#ifdef USE_COLOR',
  17118. ' attribute vec3 color;',
  17119. '#endif',
  17120. '#ifdef USE_MORPHTARGETS',
  17121. ' attribute vec3 morphTarget0;',
  17122. ' attribute vec3 morphTarget1;',
  17123. ' attribute vec3 morphTarget2;',
  17124. ' attribute vec3 morphTarget3;',
  17125. ' #ifdef USE_MORPHNORMALS',
  17126. ' attribute vec3 morphNormal0;',
  17127. ' attribute vec3 morphNormal1;',
  17128. ' attribute vec3 morphNormal2;',
  17129. ' attribute vec3 morphNormal3;',
  17130. ' #else',
  17131. ' attribute vec3 morphTarget4;',
  17132. ' attribute vec3 morphTarget5;',
  17133. ' attribute vec3 morphTarget6;',
  17134. ' attribute vec3 morphTarget7;',
  17135. ' #endif',
  17136. '#endif',
  17137. '#ifdef USE_SKINNING',
  17138. ' attribute vec4 skinIndex;',
  17139. ' attribute vec4 skinWeight;',
  17140. '#endif',
  17141. '\n'
  17142. ].filter( filterEmptyLine ).join( '\n' );
  17143. prefixFragment = [
  17144. customExtensions,
  17145. 'precision ' + parameters.precision + ' float;',
  17146. 'precision ' + parameters.precision + ' int;',
  17147. '#define SHADER_NAME ' + material.__webglShader.name,
  17148. customDefines,
  17149. '#define MAX_DIR_LIGHTS ' + parameters.maxDirLights,
  17150. '#define MAX_POINT_LIGHTS ' + parameters.maxPointLights,
  17151. '#define MAX_SPOT_LIGHTS ' + parameters.maxSpotLights,
  17152. '#define MAX_HEMI_LIGHTS ' + parameters.maxHemiLights,
  17153. '#define MAX_SHADOWS ' + parameters.maxShadows,
  17154. parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest : '',
  17155. renderer.gammaInput ? '#define GAMMA_INPUT' : '',
  17156. renderer.gammaOutput ? '#define GAMMA_OUTPUT' : '',
  17157. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  17158. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  17159. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  17160. parameters.map ? '#define USE_MAP' : '',
  17161. parameters.envMap ? '#define USE_ENVMAP' : '',
  17162. parameters.envMap ? '#define ' + envMapTypeDefine : '',
  17163. parameters.envMap ? '#define ' + envMapModeDefine : '',
  17164. parameters.envMap ? '#define ' + envMapBlendingDefine : '',
  17165. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  17166. parameters.aoMap ? '#define USE_AOMAP' : '',
  17167. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  17168. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  17169. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  17170. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  17171. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  17172. parameters.reflectivityMap ? '#define USE_REFLECTIVITYMAP' : '',
  17173. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  17174. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  17175. parameters.vertexColors ? '#define USE_COLOR' : '',
  17176. parameters.flatShading ? '#define FLAT_SHADED' : '',
  17177. parameters.metal ? '#define METAL' : '',
  17178. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  17179. parameters.flipSided ? '#define FLIP_SIDED' : '',
  17180. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  17181. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  17182. parameters.shadowMapDebug ? '#define SHADOWMAP_DEBUG' : '',
  17183. parameters.pointLightShadows > 0 ? '#define POINT_LIGHT_SHADOWS' : '',
  17184. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  17185. parameters.logarithmicDepthBuffer && renderer.extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  17186. parameters.envMap && renderer.extensions.get( 'EXT_shader_texture_lod' ) ? '#define TEXTURE_CUBE_LOD_EXT' : '',
  17187. 'uniform mat4 viewMatrix;',
  17188. 'uniform vec3 cameraPosition;',
  17189. '\n'
  17190. ].filter( filterEmptyLine ).join( '\n' );
  17191. }
  17192. var vertexGlsl = prefixVertex + vertexShader;
  17193. var fragmentGlsl = prefixFragment + fragmentShader;
  17194. var glVertexShader = THREE.WebGLShader( gl, gl.VERTEX_SHADER, vertexGlsl );
  17195. var glFragmentShader = THREE.WebGLShader( gl, gl.FRAGMENT_SHADER, fragmentGlsl );
  17196. gl.attachShader( program, glVertexShader );
  17197. gl.attachShader( program, glFragmentShader );
  17198. // Force a particular attribute to index 0.
  17199. if ( material.index0AttributeName !== undefined ) {
  17200. gl.bindAttribLocation( program, 0, material.index0AttributeName );
  17201. } else if ( parameters.morphTargets === true ) {
  17202. // programs with morphTargets displace position out of attribute 0
  17203. gl.bindAttribLocation( program, 0, 'position' );
  17204. }
  17205. gl.linkProgram( program );
  17206. var programLog = gl.getProgramInfoLog( program );
  17207. var vertexLog = gl.getShaderInfoLog( glVertexShader );
  17208. var fragmentLog = gl.getShaderInfoLog( glFragmentShader );
  17209. var runnable = true;
  17210. var haveDiagnostics = true;
  17211. if ( gl.getProgramParameter( program, gl.LINK_STATUS ) === false ) {
  17212. runnable = false;
  17213. console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), 'gl.VALIDATE_STATUS', gl.getProgramParameter( program, gl.VALIDATE_STATUS ), 'gl.getProgramInfoLog', programLog, vertexLog, fragmentLog );
  17214. } else if ( programLog !== '' ) {
  17215. console.warn( 'THREE.WebGLProgram: gl.getProgramInfoLog()', programLog );
  17216. } else if ( vertexLog === '' || fragmentLog === '' ) {
  17217. haveDiagnostics = false;
  17218. }
  17219. if ( haveDiagnostics ) {
  17220. this.diagnostics = {
  17221. runnable: runnable,
  17222. material: material,
  17223. programLog: programLog,
  17224. vertexShader: {
  17225. log: vertexLog,
  17226. prefix: prefixVertex
  17227. },
  17228. fragmentShader: {
  17229. log: fragmentLog,
  17230. prefix: prefixFragment
  17231. }
  17232. };
  17233. }
  17234. // clean up
  17235. gl.deleteShader( glVertexShader );
  17236. gl.deleteShader( glFragmentShader );
  17237. // set up caching for uniform locations
  17238. var cachedUniforms;
  17239. this.getUniforms = function() {
  17240. if ( cachedUniforms === undefined ) {
  17241. cachedUniforms = fetchUniformLocations( gl, program );
  17242. }
  17243. return cachedUniforms;
  17244. };
  17245. // set up caching for attribute locations
  17246. var cachedAttributes;
  17247. this.getAttributes = function() {
  17248. if ( cachedAttributes === undefined ) {
  17249. cachedAttributes = fetchAttributeLocations( gl, program );
  17250. }
  17251. return cachedAttributes;
  17252. };
  17253. // free resource
  17254. this.destroy = function() {
  17255. gl.deleteProgram( program );
  17256. this.program = undefined;
  17257. };
  17258. // DEPRECATED
  17259. Object.defineProperties( this, {
  17260. uniforms: {
  17261. get: function() {
  17262. console.warn( 'THREE.WebGLProgram: .uniforms is now .getUniforms().' );
  17263. return this.getUniforms();
  17264. }
  17265. },
  17266. attributes: {
  17267. get: function() {
  17268. console.warn( 'THREE.WebGLProgram: .attributes is now .getAttributes().' );
  17269. return this.getAttributes();
  17270. }
  17271. }
  17272. } );
  17273. //
  17274. this.id = programIdCount ++;
  17275. this.code = code;
  17276. this.usedTimes = 1;
  17277. this.program = program;
  17278. this.vertexShader = glVertexShader;
  17279. this.fragmentShader = glFragmentShader;
  17280. return this;
  17281. };
  17282. } )();
  17283. // File:src/renderers/webgl/WebGLPrograms.js
  17284. THREE.WebGLPrograms = function ( renderer, capabilities ) {
  17285. var programs = [];
  17286. var shaderIDs = {
  17287. MeshDepthMaterial: 'depth',
  17288. MeshNormalMaterial: 'normal',
  17289. MeshBasicMaterial: 'basic',
  17290. MeshLambertMaterial: 'lambert',
  17291. MeshPhongMaterial: 'phong',
  17292. MeshPhysicalMaterial: 'physical',
  17293. LineBasicMaterial: 'basic',
  17294. LineDashedMaterial: 'dashed',
  17295. PointsMaterial: 'points'
  17296. };
  17297. var parameterNames = [
  17298. "precision", "supportsVertexTextures", "map", "envMap", "envMapMode",
  17299. "lightMap", "aoMap", "emissiveMap", "bumpMap", "normalMap", "displacementMap", "specularMap",
  17300. "roughnessMap", "reflectivityMap", "metalnessMap",
  17301. "alphaMap", "combine", "vertexColors", "fog", "useFog", "fogExp",
  17302. "flatShading", "sizeAttenuation", "logarithmicDepthBuffer", "skinning",
  17303. "maxBones", "useVertexTexture", "morphTargets", "morphNormals",
  17304. "maxMorphTargets", "maxMorphNormals", "maxDirLights", "maxPointLights",
  17305. "maxSpotLights", "maxHemiLights", "maxShadows", "shadowMapEnabled", "pointLightShadows",
  17306. "shadowMapType", "shadowMapDebug", "alphaTest", "metal", "doubleSided",
  17307. "flipSided"
  17308. ];
  17309. function allocateBones ( object ) {
  17310. if ( capabilities.floatVertexTextures && object && object.skeleton && object.skeleton.useVertexTexture ) {
  17311. return 1024;
  17312. } else {
  17313. // default for when object is not specified
  17314. // ( for example when prebuilding shader to be used with multiple objects )
  17315. //
  17316. // - leave some extra space for other uniforms
  17317. // - limit here is ANGLE's 254 max uniform vectors
  17318. // (up to 54 should be safe)
  17319. var nVertexUniforms = capabilities.maxVertexUniforms;
  17320. var nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 );
  17321. var maxBones = nVertexMatrices;
  17322. if ( object !== undefined && object instanceof THREE.SkinnedMesh ) {
  17323. maxBones = Math.min( object.skeleton.bones.length, maxBones );
  17324. if ( maxBones < object.skeleton.bones.length ) {
  17325. console.warn( 'WebGLRenderer: too many bones - ' + object.skeleton.bones.length + ', this GPU supports just ' + maxBones + ' (try OpenGL instead of ANGLE)' );
  17326. }
  17327. }
  17328. return maxBones;
  17329. }
  17330. }
  17331. function allocateLights( lights ) {
  17332. var dirLights = 0;
  17333. var pointLights = 0;
  17334. var spotLights = 0;
  17335. var hemiLights = 0;
  17336. for ( var l = 0, ll = lights.length; l < ll; l ++ ) {
  17337. var light = lights[ l ];
  17338. if ( light.visible === false ) continue;
  17339. if ( light instanceof THREE.DirectionalLight ) dirLights ++;
  17340. if ( light instanceof THREE.PointLight ) pointLights ++;
  17341. if ( light instanceof THREE.SpotLight ) spotLights ++;
  17342. if ( light instanceof THREE.HemisphereLight ) hemiLights ++;
  17343. }
  17344. return { 'directional': dirLights, 'point': pointLights, 'spot': spotLights, 'hemi': hemiLights };
  17345. }
  17346. function allocateShadows( lights ) {
  17347. var maxShadows = 0;
  17348. var pointLightShadows = 0;
  17349. for ( var l = 0, ll = lights.length; l < ll; l ++ ) {
  17350. var light = lights[ l ];
  17351. if ( ! light.castShadow ) continue;
  17352. if ( light instanceof THREE.SpotLight || light instanceof THREE.DirectionalLight ) maxShadows ++;
  17353. if ( light instanceof THREE.PointLight ) {
  17354. maxShadows ++;
  17355. pointLightShadows ++;
  17356. }
  17357. }
  17358. return { 'maxShadows': maxShadows, 'pointLightShadows': pointLightShadows };
  17359. }
  17360. this.getParameters = function ( material, lights, fog, object ) {
  17361. var shaderID = shaderIDs[ material.type ];
  17362. // heuristics to create shader parameters according to lights in the scene
  17363. // (not to blow over maxLights budget)
  17364. var maxLightCount = allocateLights( lights );
  17365. var allocatedShadows = allocateShadows( lights );
  17366. var maxBones = allocateBones( object );
  17367. var precision = renderer.getPrecision();
  17368. if ( material.precision !== null ) {
  17369. precision = capabilities.getMaxPrecision( material.precision );
  17370. if ( precision !== material.precision ) {
  17371. console.warn( 'THREE.WebGLRenderer.initMaterial:', material.precision, 'not supported, using', precision, 'instead.' );
  17372. }
  17373. }
  17374. var parameters = {
  17375. shaderID: shaderID,
  17376. precision: precision,
  17377. supportsVertexTextures: capabilities.vertexTextures,
  17378. map: !! material.map,
  17379. envMap: !! material.envMap,
  17380. envMapMode: material.envMap && material.envMap.mapping,
  17381. lightMap: !! material.lightMap,
  17382. aoMap: !! material.aoMap,
  17383. emissiveMap: !! material.emissiveMap,
  17384. bumpMap: !! material.bumpMap,
  17385. normalMap: !! material.normalMap,
  17386. displacementMap: !! material.displacementMap,
  17387. roughnessMap: !! material.roughnessMap,
  17388. reflectivityMap: !! material.reflectivityMap,
  17389. metalnessMap: !! material.metalnessMap,
  17390. specularMap: !! material.specularMap,
  17391. alphaMap: !! material.alphaMap,
  17392. combine: material.combine,
  17393. vertexColors: material.vertexColors,
  17394. fog: fog,
  17395. useFog: material.fog,
  17396. fogExp: fog instanceof THREE.FogExp2,
  17397. flatShading: material.shading === THREE.FlatShading,
  17398. sizeAttenuation: material.sizeAttenuation,
  17399. logarithmicDepthBuffer: capabilities.logarithmicDepthBuffer,
  17400. skinning: material.skinning,
  17401. maxBones: maxBones,
  17402. useVertexTexture: capabilities.floatVertexTextures && object && object.skeleton && object.skeleton.useVertexTexture,
  17403. morphTargets: material.morphTargets,
  17404. morphNormals: material.morphNormals,
  17405. maxMorphTargets: renderer.maxMorphTargets,
  17406. maxMorphNormals: renderer.maxMorphNormals,
  17407. maxDirLights: maxLightCount.directional,
  17408. maxPointLights: maxLightCount.point,
  17409. maxSpotLights: maxLightCount.spot,
  17410. maxHemiLights: maxLightCount.hemi,
  17411. maxShadows: allocatedShadows.maxShadows,
  17412. pointLightShadows: allocatedShadows.pointLightShadows,
  17413. shadowMapEnabled: renderer.shadowMap.enabled && object.receiveShadow && allocatedShadows.maxShadows > 0,
  17414. shadowMapType: renderer.shadowMap.type,
  17415. shadowMapDebug: renderer.shadowMap.debug,
  17416. alphaTest: material.alphaTest,
  17417. metal: material.metal,
  17418. doubleSided: material.side === THREE.DoubleSide,
  17419. flipSided: material.side === THREE.BackSide
  17420. };
  17421. return parameters;
  17422. };
  17423. this.getProgramCode = function ( material, parameters ) {
  17424. var chunks = [];
  17425. if ( parameters.shaderID ) {
  17426. chunks.push( parameters.shaderID );
  17427. } else {
  17428. chunks.push( material.fragmentShader );
  17429. chunks.push( material.vertexShader );
  17430. }
  17431. if ( material.defines !== undefined ) {
  17432. for ( var name in material.defines ) {
  17433. chunks.push( name );
  17434. chunks.push( material.defines[ name ] );
  17435. }
  17436. }
  17437. for ( var i = 0; i < parameterNames.length; i ++ ) {
  17438. var parameterName = parameterNames[ i ];
  17439. chunks.push( parameterName );
  17440. chunks.push( parameters[ parameterName ] );
  17441. }
  17442. return chunks.join();
  17443. };
  17444. this.acquireProgram = function ( material, parameters, code ) {
  17445. var program;
  17446. // Check if code has been already compiled
  17447. for ( var p = 0, pl = programs.length; p < pl; p ++ ) {
  17448. var programInfo = programs[ p ];
  17449. if ( programInfo.code === code ) {
  17450. program = programInfo;
  17451. ++ program.usedTimes;
  17452. break;
  17453. }
  17454. }
  17455. if ( program === undefined ) {
  17456. program = new THREE.WebGLProgram( renderer, code, material, parameters );
  17457. programs.push( program );
  17458. }
  17459. return program;
  17460. };
  17461. this.releaseProgram = function( program ) {
  17462. if ( -- program.usedTimes === 0 ) {
  17463. // Remove from unordered set
  17464. var i = programs.indexOf( program );
  17465. programs[ i ] = programs[ programs.length - 1 ];
  17466. programs.pop();
  17467. // Free WebGL resources
  17468. program.destroy();
  17469. }
  17470. };
  17471. // Exposed for resource monitoring & error feedback via renderer.info:
  17472. this.programs = programs;
  17473. };
  17474. // File:src/renderers/webgl/WebGLProperties.js
  17475. /**
  17476. * @author fordacious / fordacious.github.io
  17477. */
  17478. THREE.WebGLProperties = function () {
  17479. var properties = {};
  17480. this.get = function ( object ) {
  17481. var uuid = object.uuid;
  17482. var map = properties[ uuid ];
  17483. if ( map === undefined ) {
  17484. map = {};
  17485. properties[ uuid ] = map;
  17486. }
  17487. return map;
  17488. };
  17489. this.delete = function ( object ) {
  17490. delete properties[ object.uuid ];
  17491. };
  17492. this.clear = function () {
  17493. properties = {};
  17494. };
  17495. };
  17496. // File:src/renderers/webgl/WebGLShader.js
  17497. THREE.WebGLShader = ( function () {
  17498. function addLineNumbers( string ) {
  17499. var lines = string.split( '\n' );
  17500. for ( var i = 0; i < lines.length; i ++ ) {
  17501. lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
  17502. }
  17503. return lines.join( '\n' );
  17504. }
  17505. return function WebGLShader( gl, type, string ) {
  17506. var shader = gl.createShader( type );
  17507. gl.shaderSource( shader, string );
  17508. gl.compileShader( shader );
  17509. if ( gl.getShaderParameter( shader, gl.COMPILE_STATUS ) === false ) {
  17510. console.error( 'THREE.WebGLShader: Shader couldn\'t compile.' );
  17511. }
  17512. if ( gl.getShaderInfoLog( shader ) !== '' ) {
  17513. console.warn( 'THREE.WebGLShader: gl.getShaderInfoLog()', type === gl.VERTEX_SHADER ? 'vertex' : 'fragment', gl.getShaderInfoLog( shader ), addLineNumbers( string ) );
  17514. }
  17515. // --enable-privileged-webgl-extension
  17516. // console.log( type, gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  17517. return shader;
  17518. };
  17519. } )();
  17520. // File:src/renderers/webgl/WebGLShadowMap.js
  17521. /**
  17522. * @author alteredq / http://alteredqualia.com/
  17523. * @author mrdoob / http://mrdoob.com/
  17524. */
  17525. THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
  17526. var _gl = _renderer.context,
  17527. _state = _renderer.state,
  17528. _frustum = new THREE.Frustum(),
  17529. _projScreenMatrix = new THREE.Matrix4(),
  17530. _min = new THREE.Vector3(),
  17531. _max = new THREE.Vector3(),
  17532. _lookTarget = new THREE.Vector3(),
  17533. _lightPositionWorld = new THREE.Vector3(),
  17534. _renderList = [],
  17535. _MorphingFlag = 1,
  17536. _SkinningFlag = 2,
  17537. _NumberOfMaterialVariants = ( _MorphingFlag | _SkinningFlag ) + 1,
  17538. _depthMaterials = new Array( _NumberOfMaterialVariants ),
  17539. _distanceMaterials = new Array( _NumberOfMaterialVariants );
  17540. var cubeDirections = [
  17541. new THREE.Vector3( 1, 0, 0 ), new THREE.Vector3( - 1, 0, 0 ), new THREE.Vector3( 0, 0, 1 ),
  17542. new THREE.Vector3( 0, 0, - 1 ), new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, - 1, 0 )
  17543. ];
  17544. var cubeUps = [
  17545. new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 1, 0 ),
  17546. new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 0, 1 ), new THREE.Vector3( 0, 0, - 1 )
  17547. ];
  17548. var cube2DViewPorts = [
  17549. new THREE.Vector4(), new THREE.Vector4(), new THREE.Vector4(),
  17550. new THREE.Vector4(), new THREE.Vector4(), new THREE.Vector4()
  17551. ];
  17552. var _vector4 = new THREE.Vector4();
  17553. // init
  17554. var depthShader = THREE.ShaderLib[ "depthRGBA" ];
  17555. var depthUniforms = THREE.UniformsUtils.clone( depthShader.uniforms );
  17556. var distanceShader = THREE.ShaderLib[ "distanceRGBA" ];
  17557. var distanceUniforms = THREE.UniformsUtils.clone( distanceShader.uniforms );
  17558. for ( var i = 0; i !== _NumberOfMaterialVariants; ++ i ) {
  17559. var useMorphing = ( i & _MorphingFlag ) !== 0;
  17560. var useSkinning = ( i & _SkinningFlag ) !== 0;
  17561. var depthMaterial = new THREE.ShaderMaterial( {
  17562. uniforms: depthUniforms,
  17563. vertexShader: depthShader.vertexShader,
  17564. fragmentShader: depthShader.fragmentShader,
  17565. morphTargets: useMorphing,
  17566. skinning: useSkinning
  17567. } );
  17568. depthMaterial._shadowPass = true;
  17569. _depthMaterials[ i ] = depthMaterial;
  17570. var distanceMaterial = new THREE.ShaderMaterial( {
  17571. uniforms: distanceUniforms,
  17572. vertexShader: distanceShader.vertexShader,
  17573. fragmentShader: distanceShader.fragmentShader,
  17574. morphTargets: useMorphing,
  17575. skinning: useSkinning
  17576. } );
  17577. distanceMaterial._shadowPass = true;
  17578. _distanceMaterials[ i ] = distanceMaterial;
  17579. }
  17580. //
  17581. var scope = this;
  17582. this.enabled = false;
  17583. this.autoUpdate = true;
  17584. this.needsUpdate = false;
  17585. this.type = THREE.PCFShadowMap;
  17586. this.cullFace = THREE.CullFaceFront;
  17587. this.render = function ( scene, camera ) {
  17588. var faceCount, isPointLight;
  17589. if ( scope.enabled === false ) return;
  17590. if ( scope.autoUpdate === false && scope.needsUpdate === false ) return;
  17591. // Set GL state for depth map.
  17592. _gl.clearColor( 1, 1, 1, 1 );
  17593. _state.disable( _gl.BLEND );
  17594. _state.enable( _gl.CULL_FACE );
  17595. _gl.frontFace( _gl.CCW );
  17596. _gl.cullFace( scope.cullFace === THREE.CullFaceFront ? _gl.FRONT : _gl.BACK );
  17597. _state.setDepthTest( true );
  17598. // save the existing viewport so it can be restored later
  17599. _renderer.getViewport( _vector4 );
  17600. // render depth map
  17601. for ( var i = 0, il = _lights.length; i < il; i ++ ) {
  17602. var light = _lights[ i ];
  17603. if ( light.castShadow === true ) {
  17604. var shadow = light.shadow;
  17605. var shadowCamera = shadow.camera;
  17606. var shadowMapSize = shadow.mapSize;
  17607. if ( light instanceof THREE.PointLight ) {
  17608. faceCount = 6;
  17609. isPointLight = true;
  17610. var vpWidth = shadowMapSize.x / 4.0;
  17611. var vpHeight = shadowMapSize.y / 2.0;
  17612. // These viewports map a cube-map onto a 2D texture with the
  17613. // following orientation:
  17614. //
  17615. // xzXZ
  17616. // y Y
  17617. //
  17618. // X - Positive x direction
  17619. // x - Negative x direction
  17620. // Y - Positive y direction
  17621. // y - Negative y direction
  17622. // Z - Positive z direction
  17623. // z - Negative z direction
  17624. // positive X
  17625. cube2DViewPorts[ 0 ].set( vpWidth * 2, vpHeight, vpWidth, vpHeight );
  17626. // negative X
  17627. cube2DViewPorts[ 1 ].set( 0, vpHeight, vpWidth, vpHeight );
  17628. // positive Z
  17629. cube2DViewPorts[ 2 ].set( vpWidth * 3, vpHeight, vpWidth, vpHeight );
  17630. // negative Z
  17631. cube2DViewPorts[ 3 ].set( vpWidth, vpHeight, vpWidth, vpHeight );
  17632. // positive Y
  17633. cube2DViewPorts[ 4 ].set( vpWidth * 3, 0, vpWidth, vpHeight );
  17634. // negative Y
  17635. cube2DViewPorts[ 5 ].set( vpWidth, 0, vpWidth, vpHeight );
  17636. } else {
  17637. faceCount = 1;
  17638. isPointLight = false;
  17639. }
  17640. if ( shadow.map === null ) {
  17641. var shadowFilter = THREE.LinearFilter;
  17642. if ( scope.type === THREE.PCFSoftShadowMap ) {
  17643. shadowFilter = THREE.NearestFilter;
  17644. }
  17645. var pars = { minFilter: shadowFilter, magFilter: shadowFilter, format: THREE.RGBAFormat };
  17646. shadow.map = new THREE.WebGLRenderTarget( shadowMapSize.x, shadowMapSize.y, pars );
  17647. shadow.matrix = new THREE.Matrix4();
  17648. //
  17649. if ( light instanceof THREE.SpotLight ) {
  17650. shadowCamera.aspect = shadowMapSize.x / shadowMapSize.y;
  17651. }
  17652. shadowCamera.updateProjectionMatrix();
  17653. }
  17654. var shadowMap = shadow.map;
  17655. var shadowMatrix = shadow.matrix;
  17656. _lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  17657. shadowCamera.position.copy( _lightPositionWorld );
  17658. _renderer.setRenderTarget( shadowMap );
  17659. _renderer.clear();
  17660. // render shadow map for each cube face (if omni-directional) or
  17661. // run a single pass if not
  17662. for ( var face = 0; face < faceCount; face ++ ) {
  17663. if ( isPointLight ) {
  17664. _lookTarget.copy( shadowCamera.position );
  17665. _lookTarget.add( cubeDirections[ face ] );
  17666. shadowCamera.up.copy( cubeUps[ face ] );
  17667. shadowCamera.lookAt( _lookTarget );
  17668. var vpDimensions = cube2DViewPorts[ face ];
  17669. _renderer.setViewport( vpDimensions.x, vpDimensions.y, vpDimensions.z, vpDimensions.w );
  17670. } else {
  17671. _lookTarget.setFromMatrixPosition( light.target.matrixWorld );
  17672. shadowCamera.lookAt( _lookTarget );
  17673. }
  17674. shadowCamera.updateMatrixWorld();
  17675. shadowCamera.matrixWorldInverse.getInverse( shadowCamera.matrixWorld );
  17676. // compute shadow matrix
  17677. shadowMatrix.set(
  17678. 0.5, 0.0, 0.0, 0.5,
  17679. 0.0, 0.5, 0.0, 0.5,
  17680. 0.0, 0.0, 0.5, 0.5,
  17681. 0.0, 0.0, 0.0, 1.0
  17682. );
  17683. shadowMatrix.multiply( shadowCamera.projectionMatrix );
  17684. shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
  17685. // update camera matrices and frustum
  17686. _projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  17687. _frustum.setFromMatrix( _projScreenMatrix );
  17688. // set object matrices & frustum culling
  17689. _renderList.length = 0;
  17690. projectObject( scene, camera, shadowCamera );
  17691. // render shadow map
  17692. // render regular objects
  17693. for ( var j = 0, jl = _renderList.length; j < jl; j ++ ) {
  17694. var object = _renderList[ j ];
  17695. var geometry = _objects.update( object );
  17696. var material = object.material;
  17697. if ( material instanceof THREE.MeshFaceMaterial ) {
  17698. var groups = geometry.groups;
  17699. var materials = material.materials;
  17700. for ( var k = 0, kl = groups.length; k < kl; k ++ ) {
  17701. var group = groups[ k ];
  17702. var groupMaterial = materials[ group.materialIndex ];
  17703. if ( groupMaterial.visible === true ) {
  17704. var depthMaterial = getDepthMaterial( object, groupMaterial, isPointLight, _lightPositionWorld );
  17705. _renderer.renderBufferDirect( shadowCamera, _lights, null, geometry, depthMaterial, object, group );
  17706. }
  17707. }
  17708. } else {
  17709. var depthMaterial = getDepthMaterial( object, material, isPointLight, _lightPositionWorld );
  17710. _renderer.renderBufferDirect( shadowCamera, _lights, null, geometry, depthMaterial, object, null );
  17711. }
  17712. }
  17713. }
  17714. // We must call _renderer.resetGLState() at the end of each iteration of
  17715. // the light loop in order to force material updates for each light.
  17716. _renderer.resetGLState();
  17717. }
  17718. }
  17719. _renderer.setViewport( _vector4.x, _vector4.y, _vector4.z, _vector4.w );
  17720. // Restore GL state.
  17721. var clearColor = _renderer.getClearColor(),
  17722. clearAlpha = _renderer.getClearAlpha();
  17723. _renderer.setClearColor( clearColor, clearAlpha );
  17724. _state.enable( _gl.BLEND );
  17725. if ( scope.cullFace === THREE.CullFaceFront ) {
  17726. _gl.cullFace( _gl.BACK );
  17727. }
  17728. _renderer.resetGLState();
  17729. scope.needsUpdate = false;
  17730. };
  17731. function getDepthMaterial( object, material, isPointLight, lightPositionWorld ) {
  17732. var geometry = object.geometry;
  17733. var newMaterial = null;
  17734. var materialVariants = _depthMaterials;
  17735. var customMaterial = object.customDepthMaterial;
  17736. if ( isPointLight ) {
  17737. materialVariants = _distanceMaterials;
  17738. customMaterial = object.customDistanceMaterial;
  17739. }
  17740. if ( ! customMaterial ) {
  17741. var useMorphing = geometry.morphTargets !== undefined &&
  17742. geometry.morphTargets.length > 0 && material.morphTargets;
  17743. var useSkinning = object instanceof THREE.SkinnedMesh && material.skinning;
  17744. var variantIndex = 0;
  17745. if ( useMorphing ) variantIndex |= _MorphingFlag;
  17746. if ( useSkinning ) variantIndex |= _SkinningFlag;
  17747. newMaterial = materialVariants[ variantIndex ];
  17748. } else {
  17749. newMaterial = customMaterial;
  17750. }
  17751. newMaterial.visible = material.visible;
  17752. newMaterial.wireframe = material.wireframe;
  17753. newMaterial.wireframeLinewidth = material.wireframeLinewidth;
  17754. if ( isPointLight && newMaterial.uniforms.lightPos !== undefined ) {
  17755. newMaterial.uniforms.lightPos.value.copy( lightPositionWorld );
  17756. }
  17757. return newMaterial;
  17758. }
  17759. function projectObject( object, camera, shadowCamera ) {
  17760. if ( object.visible === false ) return;
  17761. if ( object.layers.test( camera.layers ) && ( object instanceof THREE.Mesh || object instanceof THREE.Line || object instanceof THREE.Points ) ) {
  17762. if ( object.castShadow && ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) ) {
  17763. var material = object.material;
  17764. if ( material.visible === true ) {
  17765. object.modelViewMatrix.multiplyMatrices( shadowCamera.matrixWorldInverse, object.matrixWorld );
  17766. _renderList.push( object );
  17767. }
  17768. }
  17769. }
  17770. var children = object.children;
  17771. for ( var i = 0, l = children.length; i < l; i ++ ) {
  17772. projectObject( children[ i ], camera, shadowCamera );
  17773. }
  17774. }
  17775. };
  17776. // File:src/renderers/webgl/WebGLState.js
  17777. /**
  17778. * @author mrdoob / http://mrdoob.com/
  17779. */
  17780. THREE.WebGLState = function ( gl, extensions, paramThreeToGL ) {
  17781. var _this = this;
  17782. var newAttributes = new Uint8Array( 16 );
  17783. var enabledAttributes = new Uint8Array( 16 );
  17784. var attributeDivisors = new Uint8Array( 16 );
  17785. var capabilities = {};
  17786. var compressedTextureFormats = null;
  17787. var currentBlending = null;
  17788. var currentBlendEquation = null;
  17789. var currentBlendSrc = null;
  17790. var currentBlendDst = null;
  17791. var currentBlendEquationAlpha = null;
  17792. var currentBlendSrcAlpha = null;
  17793. var currentBlendDstAlpha = null;
  17794. var currentDepthFunc = null;
  17795. var currentDepthWrite = null;
  17796. var currentColorWrite = null;
  17797. var currentFlipSided = null;
  17798. var currentLineWidth = null;
  17799. var currentPolygonOffsetFactor = null;
  17800. var currentPolygonOffsetUnits = null;
  17801. var maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
  17802. var currentTextureSlot = undefined;
  17803. var currentBoundTextures = {};
  17804. this.init = function () {
  17805. gl.clearColor( 0, 0, 0, 1 );
  17806. gl.clearDepth( 1 );
  17807. gl.clearStencil( 0 );
  17808. this.enable( gl.DEPTH_TEST );
  17809. gl.depthFunc( gl.LEQUAL );
  17810. gl.frontFace( gl.CCW );
  17811. gl.cullFace( gl.BACK );
  17812. this.enable( gl.CULL_FACE );
  17813. this.enable( gl.BLEND );
  17814. gl.blendEquation( gl.FUNC_ADD );
  17815. gl.blendFunc( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA );
  17816. };
  17817. this.initAttributes = function () {
  17818. for ( var i = 0, l = newAttributes.length; i < l; i ++ ) {
  17819. newAttributes[ i ] = 0;
  17820. }
  17821. };
  17822. this.enableAttribute = function ( attribute ) {
  17823. newAttributes[ attribute ] = 1;
  17824. if ( enabledAttributes[ attribute ] === 0 ) {
  17825. gl.enableVertexAttribArray( attribute );
  17826. enabledAttributes[ attribute ] = 1;
  17827. }
  17828. if ( attributeDivisors[ attribute ] !== 0 ) {
  17829. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  17830. extension.vertexAttribDivisorANGLE( attribute, 0 );
  17831. attributeDivisors[ attribute ] = 0;
  17832. }
  17833. };
  17834. this.enableAttributeAndDivisor = function ( attribute, meshPerAttribute, extension ) {
  17835. newAttributes[ attribute ] = 1;
  17836. if ( enabledAttributes[ attribute ] === 0 ) {
  17837. gl.enableVertexAttribArray( attribute );
  17838. enabledAttributes[ attribute ] = 1;
  17839. }
  17840. if ( attributeDivisors[ attribute ] !== meshPerAttribute ) {
  17841. extension.vertexAttribDivisorANGLE( attribute, meshPerAttribute );
  17842. attributeDivisors[ attribute ] = meshPerAttribute;
  17843. }
  17844. };
  17845. this.disableUnusedAttributes = function () {
  17846. for ( var i = 0, l = enabledAttributes.length; i < l; i ++ ) {
  17847. if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
  17848. gl.disableVertexAttribArray( i );
  17849. enabledAttributes[ i ] = 0;
  17850. }
  17851. }
  17852. };
  17853. this.enable = function ( id ) {
  17854. if ( capabilities[ id ] !== true ) {
  17855. gl.enable( id );
  17856. capabilities[ id ] = true;
  17857. }
  17858. };
  17859. this.disable = function ( id ) {
  17860. if ( capabilities[ id ] !== false ) {
  17861. gl.disable( id );
  17862. capabilities[ id ] = false;
  17863. }
  17864. };
  17865. this.getCompressedTextureFormats = function () {
  17866. if ( compressedTextureFormats === null ) {
  17867. compressedTextureFormats = [];
  17868. if ( extensions.get( 'WEBGL_compressed_texture_pvrtc' ) ||
  17869. extensions.get( 'WEBGL_compressed_texture_s3tc' ) ) {
  17870. var formats = gl.getParameter( gl.COMPRESSED_TEXTURE_FORMATS );
  17871. for ( var i = 0; i < formats.length; i ++ ) {
  17872. compressedTextureFormats.push( formats[ i ] );
  17873. }
  17874. }
  17875. }
  17876. return compressedTextureFormats;
  17877. };
  17878. this.setBlending = function ( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha ) {
  17879. if ( blending !== currentBlending ) {
  17880. if ( blending === THREE.NoBlending ) {
  17881. this.disable( gl.BLEND );
  17882. } else if ( blending === THREE.AdditiveBlending ) {
  17883. this.enable( gl.BLEND );
  17884. gl.blendEquation( gl.FUNC_ADD );
  17885. gl.blendFunc( gl.SRC_ALPHA, gl.ONE );
  17886. } else if ( blending === THREE.SubtractiveBlending ) {
  17887. // TODO: Find blendFuncSeparate() combination
  17888. this.enable( gl.BLEND );
  17889. gl.blendEquation( gl.FUNC_ADD );
  17890. gl.blendFunc( gl.ZERO, gl.ONE_MINUS_SRC_COLOR );
  17891. } else if ( blending === THREE.MultiplyBlending ) {
  17892. // TODO: Find blendFuncSeparate() combination
  17893. this.enable( gl.BLEND );
  17894. gl.blendEquation( gl.FUNC_ADD );
  17895. gl.blendFunc( gl.ZERO, gl.SRC_COLOR );
  17896. } else if ( blending === THREE.CustomBlending ) {
  17897. this.enable( gl.BLEND );
  17898. } else {
  17899. this.enable( gl.BLEND );
  17900. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  17901. gl.blendFuncSeparate( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
  17902. }
  17903. currentBlending = blending;
  17904. }
  17905. if ( blending === THREE.CustomBlending ) {
  17906. blendEquationAlpha = blendEquationAlpha || blendEquation;
  17907. blendSrcAlpha = blendSrcAlpha || blendSrc;
  17908. blendDstAlpha = blendDstAlpha || blendDst;
  17909. if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
  17910. gl.blendEquationSeparate( paramThreeToGL( blendEquation ), paramThreeToGL( blendEquationAlpha ) );
  17911. currentBlendEquation = blendEquation;
  17912. currentBlendEquationAlpha = blendEquationAlpha;
  17913. }
  17914. if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
  17915. gl.blendFuncSeparate( paramThreeToGL( blendSrc ), paramThreeToGL( blendDst ), paramThreeToGL( blendSrcAlpha ), paramThreeToGL( blendDstAlpha ) );
  17916. currentBlendSrc = blendSrc;
  17917. currentBlendDst = blendDst;
  17918. currentBlendSrcAlpha = blendSrcAlpha;
  17919. currentBlendDstAlpha = blendDstAlpha;
  17920. }
  17921. } else {
  17922. currentBlendEquation = null;
  17923. currentBlendSrc = null;
  17924. currentBlendDst = null;
  17925. currentBlendEquationAlpha = null;
  17926. currentBlendSrcAlpha = null;
  17927. currentBlendDstAlpha = null;
  17928. }
  17929. };
  17930. this.setDepthFunc = function ( depthFunc ) {
  17931. if ( currentDepthFunc !== depthFunc ) {
  17932. if ( depthFunc ) {
  17933. switch ( depthFunc ) {
  17934. case THREE.NeverDepth:
  17935. gl.depthFunc( gl.NEVER );
  17936. break;
  17937. case THREE.AlwaysDepth:
  17938. gl.depthFunc( gl.ALWAYS );
  17939. break;
  17940. case THREE.LessDepth:
  17941. gl.depthFunc( gl.LESS );
  17942. break;
  17943. case THREE.LessEqualDepth:
  17944. gl.depthFunc( gl.LEQUAL );
  17945. break;
  17946. case THREE.EqualDepth:
  17947. gl.depthFunc( gl.EQUAL );
  17948. break;
  17949. case THREE.GreaterEqualDepth:
  17950. gl.depthFunc( gl.GEQUAL );
  17951. break;
  17952. case THREE.GreaterDepth:
  17953. gl.depthFunc( gl.GREATER );
  17954. break;
  17955. case THREE.NotEqualDepth:
  17956. gl.depthFunc( gl.NOTEQUAL );
  17957. break;
  17958. default:
  17959. gl.depthFunc( gl.LEQUAL );
  17960. }
  17961. } else {
  17962. gl.depthFunc( gl.LEQUAL );
  17963. }
  17964. currentDepthFunc = depthFunc;
  17965. }
  17966. };
  17967. this.setDepthTest = function ( depthTest ) {
  17968. if ( depthTest ) {
  17969. this.enable( gl.DEPTH_TEST );
  17970. } else {
  17971. this.disable( gl.DEPTH_TEST );
  17972. }
  17973. };
  17974. this.setDepthWrite = function ( depthWrite ) {
  17975. if ( currentDepthWrite !== depthWrite ) {
  17976. gl.depthMask( depthWrite );
  17977. currentDepthWrite = depthWrite;
  17978. }
  17979. };
  17980. this.setColorWrite = function ( colorWrite ) {
  17981. if ( currentColorWrite !== colorWrite ) {
  17982. gl.colorMask( colorWrite, colorWrite, colorWrite, colorWrite );
  17983. currentColorWrite = colorWrite;
  17984. }
  17985. };
  17986. this.setFlipSided = function ( flipSided ) {
  17987. if ( currentFlipSided !== flipSided ) {
  17988. if ( flipSided ) {
  17989. gl.frontFace( gl.CW );
  17990. } else {
  17991. gl.frontFace( gl.CCW );
  17992. }
  17993. currentFlipSided = flipSided;
  17994. }
  17995. };
  17996. this.setLineWidth = function ( width ) {
  17997. if ( width !== currentLineWidth ) {
  17998. gl.lineWidth( width );
  17999. currentLineWidth = width;
  18000. }
  18001. };
  18002. this.setPolygonOffset = function ( polygonOffset, factor, units ) {
  18003. if ( polygonOffset ) {
  18004. this.enable( gl.POLYGON_OFFSET_FILL );
  18005. } else {
  18006. this.disable( gl.POLYGON_OFFSET_FILL );
  18007. }
  18008. if ( polygonOffset && ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) ) {
  18009. gl.polygonOffset( factor, units );
  18010. currentPolygonOffsetFactor = factor;
  18011. currentPolygonOffsetUnits = units;
  18012. }
  18013. };
  18014. this.setScissorTest = function ( scissorTest ) {
  18015. if ( scissorTest ) {
  18016. this.enable( gl.SCISSOR_TEST );
  18017. } else {
  18018. this.disable( gl.SCISSOR_TEST );
  18019. }
  18020. };
  18021. // texture
  18022. this.activeTexture = function ( webglSlot ) {
  18023. if ( webglSlot === undefined ) webglSlot = gl.TEXTURE0 + maxTextures - 1;
  18024. if ( currentTextureSlot !== webglSlot ) {
  18025. gl.activeTexture( webglSlot );
  18026. currentTextureSlot = webglSlot;
  18027. }
  18028. }
  18029. this.bindTexture = function ( webglType, webglTexture ) {
  18030. if ( currentTextureSlot === undefined ) {
  18031. _this.activeTexture();
  18032. }
  18033. var boundTexture = currentBoundTextures[ currentTextureSlot ];
  18034. if ( boundTexture === undefined ) {
  18035. boundTexture = { type: undefined, texture: undefined };
  18036. currentBoundTextures[ currentTextureSlot ] = boundTexture;
  18037. }
  18038. if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
  18039. gl.bindTexture( webglType, webglTexture );
  18040. boundTexture.type = webglType;
  18041. boundTexture.texture = webglTexture;
  18042. }
  18043. };
  18044. this.compressedTexImage2D = function () {
  18045. try {
  18046. gl.compressedTexImage2D.apply( gl, arguments );
  18047. } catch ( error ) {
  18048. console.error( error );
  18049. }
  18050. };
  18051. this.texImage2D = function () {
  18052. try {
  18053. gl.texImage2D.apply( gl, arguments );
  18054. } catch ( error ) {
  18055. console.error( error );
  18056. }
  18057. };
  18058. //
  18059. this.reset = function () {
  18060. for ( var i = 0; i < enabledAttributes.length; i ++ ) {
  18061. if ( enabledAttributes[ i ] === 1 ) {
  18062. gl.disableVertexAttribArray( i );
  18063. enabledAttributes[ i ] = 0;
  18064. }
  18065. }
  18066. capabilities = {};
  18067. compressedTextureFormats = null;
  18068. currentBlending = null;
  18069. currentDepthWrite = null;
  18070. currentColorWrite = null;
  18071. currentFlipSided = null;
  18072. };
  18073. };
  18074. // File:src/renderers/webgl/plugins/LensFlarePlugin.js
  18075. /**
  18076. * @author mikael emtinger / http://gomo.se/
  18077. * @author alteredq / http://alteredqualia.com/
  18078. */
  18079. THREE.LensFlarePlugin = function ( renderer, flares ) {
  18080. var gl = renderer.context;
  18081. var state = renderer.state;
  18082. var vertexBuffer, elementBuffer;
  18083. var program, attributes, uniforms;
  18084. var hasVertexTexture;
  18085. var tempTexture, occlusionTexture;
  18086. function init() {
  18087. var vertices = new Float32Array( [
  18088. - 1, - 1, 0, 0,
  18089. 1, - 1, 1, 0,
  18090. 1, 1, 1, 1,
  18091. - 1, 1, 0, 1
  18092. ] );
  18093. var faces = new Uint16Array( [
  18094. 0, 1, 2,
  18095. 0, 2, 3
  18096. ] );
  18097. // buffers
  18098. vertexBuffer = gl.createBuffer();
  18099. elementBuffer = gl.createBuffer();
  18100. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  18101. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  18102. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  18103. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  18104. // textures
  18105. tempTexture = gl.createTexture();
  18106. occlusionTexture = gl.createTexture();
  18107. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  18108. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGB, 16, 16, 0, gl.RGB, gl.UNSIGNED_BYTE, null );
  18109. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  18110. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  18111. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  18112. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  18113. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  18114. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGBA, 16, 16, 0, gl.RGBA, gl.UNSIGNED_BYTE, null );
  18115. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  18116. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  18117. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  18118. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  18119. hasVertexTexture = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS ) > 0;
  18120. var shader;
  18121. if ( hasVertexTexture ) {
  18122. shader = {
  18123. vertexShader: [
  18124. "uniform lowp int renderType;",
  18125. "uniform vec3 screenPosition;",
  18126. "uniform vec2 scale;",
  18127. "uniform float rotation;",
  18128. "uniform sampler2D occlusionMap;",
  18129. "attribute vec2 position;",
  18130. "attribute vec2 uv;",
  18131. "varying vec2 vUV;",
  18132. "varying float vVisibility;",
  18133. "void main() {",
  18134. "vUV = uv;",
  18135. "vec2 pos = position;",
  18136. "if ( renderType == 2 ) {",
  18137. "vec4 visibility = texture2D( occlusionMap, vec2( 0.1, 0.1 ) );",
  18138. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.1 ) );",
  18139. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.1 ) );",
  18140. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) );",
  18141. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.9 ) );",
  18142. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) );",
  18143. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.9 ) );",
  18144. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) );",
  18145. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.5 ) );",
  18146. "vVisibility = visibility.r / 9.0;",
  18147. "vVisibility *= 1.0 - visibility.g / 9.0;",
  18148. "vVisibility *= visibility.b / 9.0;",
  18149. "vVisibility *= 1.0 - visibility.a / 9.0;",
  18150. "pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
  18151. "pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
  18152. "}",
  18153. "gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
  18154. "}"
  18155. ].join( "\n" ),
  18156. fragmentShader: [
  18157. "uniform lowp int renderType;",
  18158. "uniform sampler2D map;",
  18159. "uniform float opacity;",
  18160. "uniform vec3 color;",
  18161. "varying vec2 vUV;",
  18162. "varying float vVisibility;",
  18163. "void main() {",
  18164. // pink square
  18165. "if ( renderType == 0 ) {",
  18166. "gl_FragColor = vec4( 1.0, 0.0, 1.0, 0.0 );",
  18167. // restore
  18168. "} else if ( renderType == 1 ) {",
  18169. "gl_FragColor = texture2D( map, vUV );",
  18170. // flare
  18171. "} else {",
  18172. "vec4 texture = texture2D( map, vUV );",
  18173. "texture.a *= opacity * vVisibility;",
  18174. "gl_FragColor = texture;",
  18175. "gl_FragColor.rgb *= color;",
  18176. "}",
  18177. "}"
  18178. ].join( "\n" )
  18179. };
  18180. } else {
  18181. shader = {
  18182. vertexShader: [
  18183. "uniform lowp int renderType;",
  18184. "uniform vec3 screenPosition;",
  18185. "uniform vec2 scale;",
  18186. "uniform float rotation;",
  18187. "attribute vec2 position;",
  18188. "attribute vec2 uv;",
  18189. "varying vec2 vUV;",
  18190. "void main() {",
  18191. "vUV = uv;",
  18192. "vec2 pos = position;",
  18193. "if ( renderType == 2 ) {",
  18194. "pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
  18195. "pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
  18196. "}",
  18197. "gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
  18198. "}"
  18199. ].join( "\n" ),
  18200. fragmentShader: [
  18201. "precision mediump float;",
  18202. "uniform lowp int renderType;",
  18203. "uniform sampler2D map;",
  18204. "uniform sampler2D occlusionMap;",
  18205. "uniform float opacity;",
  18206. "uniform vec3 color;",
  18207. "varying vec2 vUV;",
  18208. "void main() {",
  18209. // pink square
  18210. "if ( renderType == 0 ) {",
  18211. "gl_FragColor = vec4( texture2D( map, vUV ).rgb, 0.0 );",
  18212. // restore
  18213. "} else if ( renderType == 1 ) {",
  18214. "gl_FragColor = texture2D( map, vUV );",
  18215. // flare
  18216. "} else {",
  18217. "float visibility = texture2D( occlusionMap, vec2( 0.5, 0.1 ) ).a;",
  18218. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) ).a;",
  18219. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) ).a;",
  18220. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) ).a;",
  18221. "visibility = ( 1.0 - visibility / 4.0 );",
  18222. "vec4 texture = texture2D( map, vUV );",
  18223. "texture.a *= opacity * visibility;",
  18224. "gl_FragColor = texture;",
  18225. "gl_FragColor.rgb *= color;",
  18226. "}",
  18227. "}"
  18228. ].join( "\n" )
  18229. };
  18230. }
  18231. program = createProgram( shader );
  18232. attributes = {
  18233. vertex: gl.getAttribLocation ( program, "position" ),
  18234. uv: gl.getAttribLocation ( program, "uv" )
  18235. };
  18236. uniforms = {
  18237. renderType: gl.getUniformLocation( program, "renderType" ),
  18238. map: gl.getUniformLocation( program, "map" ),
  18239. occlusionMap: gl.getUniformLocation( program, "occlusionMap" ),
  18240. opacity: gl.getUniformLocation( program, "opacity" ),
  18241. color: gl.getUniformLocation( program, "color" ),
  18242. scale: gl.getUniformLocation( program, "scale" ),
  18243. rotation: gl.getUniformLocation( program, "rotation" ),
  18244. screenPosition: gl.getUniformLocation( program, "screenPosition" )
  18245. };
  18246. }
  18247. /*
  18248. * Render lens flares
  18249. * Method: renders 16x16 0xff00ff-colored points scattered over the light source area,
  18250. * reads these back and calculates occlusion.
  18251. */
  18252. this.render = function ( scene, camera, viewportWidth, viewportHeight ) {
  18253. if ( flares.length === 0 ) return;
  18254. var tempPosition = new THREE.Vector3();
  18255. var invAspect = viewportHeight / viewportWidth,
  18256. halfViewportWidth = viewportWidth * 0.5,
  18257. halfViewportHeight = viewportHeight * 0.5;
  18258. var size = 16 / viewportHeight,
  18259. scale = new THREE.Vector2( size * invAspect, size );
  18260. var screenPosition = new THREE.Vector3( 1, 1, 0 ),
  18261. screenPositionPixels = new THREE.Vector2( 1, 1 );
  18262. if ( program === undefined ) {
  18263. init();
  18264. }
  18265. gl.useProgram( program );
  18266. state.initAttributes();
  18267. state.enableAttribute( attributes.vertex );
  18268. state.enableAttribute( attributes.uv );
  18269. state.disableUnusedAttributes();
  18270. // loop through all lens flares to update their occlusion and positions
  18271. // setup gl and common used attribs/uniforms
  18272. gl.uniform1i( uniforms.occlusionMap, 0 );
  18273. gl.uniform1i( uniforms.map, 1 );
  18274. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  18275. gl.vertexAttribPointer( attributes.vertex, 2, gl.FLOAT, false, 2 * 8, 0 );
  18276. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  18277. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  18278. state.disable( gl.CULL_FACE );
  18279. gl.depthMask( false );
  18280. for ( var i = 0, l = flares.length; i < l; i ++ ) {
  18281. size = 16 / viewportHeight;
  18282. scale.set( size * invAspect, size );
  18283. // calc object screen position
  18284. var flare = flares[ i ];
  18285. tempPosition.set( flare.matrixWorld.elements[ 12 ], flare.matrixWorld.elements[ 13 ], flare.matrixWorld.elements[ 14 ] );
  18286. tempPosition.applyMatrix4( camera.matrixWorldInverse );
  18287. tempPosition.applyProjection( camera.projectionMatrix );
  18288. // setup arrays for gl programs
  18289. screenPosition.copy( tempPosition );
  18290. screenPositionPixels.x = screenPosition.x * halfViewportWidth + halfViewportWidth;
  18291. screenPositionPixels.y = screenPosition.y * halfViewportHeight + halfViewportHeight;
  18292. // screen cull
  18293. if ( hasVertexTexture || (
  18294. screenPositionPixels.x > 0 &&
  18295. screenPositionPixels.x < viewportWidth &&
  18296. screenPositionPixels.y > 0 &&
  18297. screenPositionPixels.y < viewportHeight ) ) {
  18298. // save current RGB to temp texture
  18299. state.activeTexture( gl.TEXTURE0 );
  18300. state.bindTexture( gl.TEXTURE_2D, null );
  18301. state.activeTexture( gl.TEXTURE1 );
  18302. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  18303. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGB, screenPositionPixels.x - 8, screenPositionPixels.y - 8, 16, 16, 0 );
  18304. // render pink quad
  18305. gl.uniform1i( uniforms.renderType, 0 );
  18306. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  18307. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  18308. state.disable( gl.BLEND );
  18309. state.enable( gl.DEPTH_TEST );
  18310. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  18311. // copy result to occlusionMap
  18312. state.activeTexture( gl.TEXTURE0 );
  18313. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  18314. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGBA, screenPositionPixels.x - 8, screenPositionPixels.y - 8, 16, 16, 0 );
  18315. // restore graphics
  18316. gl.uniform1i( uniforms.renderType, 1 );
  18317. state.disable( gl.DEPTH_TEST );
  18318. state.activeTexture( gl.TEXTURE1 );
  18319. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  18320. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  18321. // update object positions
  18322. flare.positionScreen.copy( screenPosition );
  18323. if ( flare.customUpdateCallback ) {
  18324. flare.customUpdateCallback( flare );
  18325. } else {
  18326. flare.updateLensFlares();
  18327. }
  18328. // render flares
  18329. gl.uniform1i( uniforms.renderType, 2 );
  18330. state.enable( gl.BLEND );
  18331. for ( var j = 0, jl = flare.lensFlares.length; j < jl; j ++ ) {
  18332. var sprite = flare.lensFlares[ j ];
  18333. if ( sprite.opacity > 0.001 && sprite.scale > 0.001 ) {
  18334. screenPosition.x = sprite.x;
  18335. screenPosition.y = sprite.y;
  18336. screenPosition.z = sprite.z;
  18337. size = sprite.size * sprite.scale / viewportHeight;
  18338. scale.x = size * invAspect;
  18339. scale.y = size;
  18340. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  18341. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  18342. gl.uniform1f( uniforms.rotation, sprite.rotation );
  18343. gl.uniform1f( uniforms.opacity, sprite.opacity );
  18344. gl.uniform3f( uniforms.color, sprite.color.r, sprite.color.g, sprite.color.b );
  18345. state.setBlending( sprite.blending, sprite.blendEquation, sprite.blendSrc, sprite.blendDst );
  18346. renderer.setTexture( sprite.texture, 1 );
  18347. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  18348. }
  18349. }
  18350. }
  18351. }
  18352. // restore gl
  18353. state.enable( gl.CULL_FACE );
  18354. state.enable( gl.DEPTH_TEST );
  18355. gl.depthMask( true );
  18356. renderer.resetGLState();
  18357. };
  18358. function createProgram ( shader ) {
  18359. var program = gl.createProgram();
  18360. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  18361. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  18362. var prefix = "precision " + renderer.getPrecision() + " float;\n";
  18363. gl.shaderSource( fragmentShader, prefix + shader.fragmentShader );
  18364. gl.shaderSource( vertexShader, prefix + shader.vertexShader );
  18365. gl.compileShader( fragmentShader );
  18366. gl.compileShader( vertexShader );
  18367. gl.attachShader( program, fragmentShader );
  18368. gl.attachShader( program, vertexShader );
  18369. gl.linkProgram( program );
  18370. return program;
  18371. }
  18372. };
  18373. // File:src/renderers/webgl/plugins/SpritePlugin.js
  18374. /**
  18375. * @author mikael emtinger / http://gomo.se/
  18376. * @author alteredq / http://alteredqualia.com/
  18377. */
  18378. THREE.SpritePlugin = function ( renderer, sprites ) {
  18379. var gl = renderer.context;
  18380. var state = renderer.state;
  18381. var vertexBuffer, elementBuffer;
  18382. var program, attributes, uniforms;
  18383. var texture;
  18384. // decompose matrixWorld
  18385. var spritePosition = new THREE.Vector3();
  18386. var spriteRotation = new THREE.Quaternion();
  18387. var spriteScale = new THREE.Vector3();
  18388. function init() {
  18389. var vertices = new Float32Array( [
  18390. - 0.5, - 0.5, 0, 0,
  18391. 0.5, - 0.5, 1, 0,
  18392. 0.5, 0.5, 1, 1,
  18393. - 0.5, 0.5, 0, 1
  18394. ] );
  18395. var faces = new Uint16Array( [
  18396. 0, 1, 2,
  18397. 0, 2, 3
  18398. ] );
  18399. vertexBuffer = gl.createBuffer();
  18400. elementBuffer = gl.createBuffer();
  18401. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  18402. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  18403. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  18404. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  18405. program = createProgram();
  18406. attributes = {
  18407. position: gl.getAttribLocation ( program, 'position' ),
  18408. uv: gl.getAttribLocation ( program, 'uv' )
  18409. };
  18410. uniforms = {
  18411. uvOffset: gl.getUniformLocation( program, 'uvOffset' ),
  18412. uvScale: gl.getUniformLocation( program, 'uvScale' ),
  18413. rotation: gl.getUniformLocation( program, 'rotation' ),
  18414. scale: gl.getUniformLocation( program, 'scale' ),
  18415. color: gl.getUniformLocation( program, 'color' ),
  18416. map: gl.getUniformLocation( program, 'map' ),
  18417. opacity: gl.getUniformLocation( program, 'opacity' ),
  18418. modelViewMatrix: gl.getUniformLocation( program, 'modelViewMatrix' ),
  18419. projectionMatrix: gl.getUniformLocation( program, 'projectionMatrix' ),
  18420. fogType: gl.getUniformLocation( program, 'fogType' ),
  18421. fogDensity: gl.getUniformLocation( program, 'fogDensity' ),
  18422. fogNear: gl.getUniformLocation( program, 'fogNear' ),
  18423. fogFar: gl.getUniformLocation( program, 'fogFar' ),
  18424. fogColor: gl.getUniformLocation( program, 'fogColor' ),
  18425. alphaTest: gl.getUniformLocation( program, 'alphaTest' )
  18426. };
  18427. var canvas = document.createElement( 'canvas' );
  18428. canvas.width = 8;
  18429. canvas.height = 8;
  18430. var context = canvas.getContext( '2d' );
  18431. context.fillStyle = 'white';
  18432. context.fillRect( 0, 0, 8, 8 );
  18433. texture = new THREE.Texture( canvas );
  18434. texture.needsUpdate = true;
  18435. }
  18436. this.render = function ( scene, camera ) {
  18437. if ( sprites.length === 0 ) return;
  18438. // setup gl
  18439. if ( program === undefined ) {
  18440. init();
  18441. }
  18442. gl.useProgram( program );
  18443. state.initAttributes();
  18444. state.enableAttribute( attributes.position );
  18445. state.enableAttribute( attributes.uv );
  18446. state.disableUnusedAttributes();
  18447. state.disable( gl.CULL_FACE );
  18448. state.enable( gl.BLEND );
  18449. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  18450. gl.vertexAttribPointer( attributes.position, 2, gl.FLOAT, false, 2 * 8, 0 );
  18451. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  18452. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  18453. gl.uniformMatrix4fv( uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
  18454. state.activeTexture( gl.TEXTURE0 );
  18455. gl.uniform1i( uniforms.map, 0 );
  18456. var oldFogType = 0;
  18457. var sceneFogType = 0;
  18458. var fog = scene.fog;
  18459. if ( fog ) {
  18460. gl.uniform3f( uniforms.fogColor, fog.color.r, fog.color.g, fog.color.b );
  18461. if ( fog instanceof THREE.Fog ) {
  18462. gl.uniform1f( uniforms.fogNear, fog.near );
  18463. gl.uniform1f( uniforms.fogFar, fog.far );
  18464. gl.uniform1i( uniforms.fogType, 1 );
  18465. oldFogType = 1;
  18466. sceneFogType = 1;
  18467. } else if ( fog instanceof THREE.FogExp2 ) {
  18468. gl.uniform1f( uniforms.fogDensity, fog.density );
  18469. gl.uniform1i( uniforms.fogType, 2 );
  18470. oldFogType = 2;
  18471. sceneFogType = 2;
  18472. }
  18473. } else {
  18474. gl.uniform1i( uniforms.fogType, 0 );
  18475. oldFogType = 0;
  18476. sceneFogType = 0;
  18477. }
  18478. // update positions and sort
  18479. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  18480. var sprite = sprites[ i ];
  18481. sprite.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, sprite.matrixWorld );
  18482. sprite.z = - sprite.modelViewMatrix.elements[ 14 ];
  18483. }
  18484. sprites.sort( painterSortStable );
  18485. // render all sprites
  18486. var scale = [];
  18487. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  18488. var sprite = sprites[ i ];
  18489. var material = sprite.material;
  18490. gl.uniform1f( uniforms.alphaTest, material.alphaTest );
  18491. gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, sprite.modelViewMatrix.elements );
  18492. sprite.matrixWorld.decompose( spritePosition, spriteRotation, spriteScale );
  18493. scale[ 0 ] = spriteScale.x;
  18494. scale[ 1 ] = spriteScale.y;
  18495. var fogType = 0;
  18496. if ( scene.fog && material.fog ) {
  18497. fogType = sceneFogType;
  18498. }
  18499. if ( oldFogType !== fogType ) {
  18500. gl.uniform1i( uniforms.fogType, fogType );
  18501. oldFogType = fogType;
  18502. }
  18503. if ( material.map !== null ) {
  18504. gl.uniform2f( uniforms.uvOffset, material.map.offset.x, material.map.offset.y );
  18505. gl.uniform2f( uniforms.uvScale, material.map.repeat.x, material.map.repeat.y );
  18506. } else {
  18507. gl.uniform2f( uniforms.uvOffset, 0, 0 );
  18508. gl.uniform2f( uniforms.uvScale, 1, 1 );
  18509. }
  18510. gl.uniform1f( uniforms.opacity, material.opacity );
  18511. gl.uniform3f( uniforms.color, material.color.r, material.color.g, material.color.b );
  18512. gl.uniform1f( uniforms.rotation, material.rotation );
  18513. gl.uniform2fv( uniforms.scale, scale );
  18514. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst );
  18515. state.setDepthTest( material.depthTest );
  18516. state.setDepthWrite( material.depthWrite );
  18517. if ( material.map && material.map.image && material.map.image.width ) {
  18518. renderer.setTexture( material.map, 0 );
  18519. } else {
  18520. renderer.setTexture( texture, 0 );
  18521. }
  18522. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  18523. }
  18524. // restore gl
  18525. state.enable( gl.CULL_FACE );
  18526. renderer.resetGLState();
  18527. };
  18528. function createProgram () {
  18529. var program = gl.createProgram();
  18530. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  18531. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  18532. gl.shaderSource( vertexShader, [
  18533. 'precision ' + renderer.getPrecision() + ' float;',
  18534. 'uniform mat4 modelViewMatrix;',
  18535. 'uniform mat4 projectionMatrix;',
  18536. 'uniform float rotation;',
  18537. 'uniform vec2 scale;',
  18538. 'uniform vec2 uvOffset;',
  18539. 'uniform vec2 uvScale;',
  18540. 'attribute vec2 position;',
  18541. 'attribute vec2 uv;',
  18542. 'varying vec2 vUV;',
  18543. 'void main() {',
  18544. 'vUV = uvOffset + uv * uvScale;',
  18545. 'vec2 alignedPosition = position * scale;',
  18546. 'vec2 rotatedPosition;',
  18547. 'rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;',
  18548. 'rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;',
  18549. 'vec4 finalPosition;',
  18550. 'finalPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );',
  18551. 'finalPosition.xy += rotatedPosition;',
  18552. 'finalPosition = projectionMatrix * finalPosition;',
  18553. 'gl_Position = finalPosition;',
  18554. '}'
  18555. ].join( '\n' ) );
  18556. gl.shaderSource( fragmentShader, [
  18557. 'precision ' + renderer.getPrecision() + ' float;',
  18558. 'uniform vec3 color;',
  18559. 'uniform sampler2D map;',
  18560. 'uniform float opacity;',
  18561. 'uniform int fogType;',
  18562. 'uniform vec3 fogColor;',
  18563. 'uniform float fogDensity;',
  18564. 'uniform float fogNear;',
  18565. 'uniform float fogFar;',
  18566. 'uniform float alphaTest;',
  18567. 'varying vec2 vUV;',
  18568. 'void main() {',
  18569. 'vec4 texture = texture2D( map, vUV );',
  18570. 'if ( texture.a < alphaTest ) discard;',
  18571. 'gl_FragColor = vec4( color * texture.xyz, texture.a * opacity );',
  18572. 'if ( fogType > 0 ) {',
  18573. 'float depth = gl_FragCoord.z / gl_FragCoord.w;',
  18574. 'float fogFactor = 0.0;',
  18575. 'if ( fogType == 1 ) {',
  18576. 'fogFactor = smoothstep( fogNear, fogFar, depth );',
  18577. '} else {',
  18578. 'const float LOG2 = 1.442695;',
  18579. 'fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );',
  18580. 'fogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );',
  18581. '}',
  18582. 'gl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );',
  18583. '}',
  18584. '}'
  18585. ].join( '\n' ) );
  18586. gl.compileShader( vertexShader );
  18587. gl.compileShader( fragmentShader );
  18588. gl.attachShader( program, vertexShader );
  18589. gl.attachShader( program, fragmentShader );
  18590. gl.linkProgram( program );
  18591. return program;
  18592. }
  18593. function painterSortStable ( a, b ) {
  18594. if ( a.z !== b.z ) {
  18595. return b.z - a.z;
  18596. } else {
  18597. return b.id - a.id;
  18598. }
  18599. }
  18600. };
  18601. // File:src/Three.Legacy.js
  18602. /**
  18603. * @author mrdoob / http://mrdoob.com/
  18604. */
  18605. Object.defineProperties( THREE.Box2.prototype, {
  18606. isIntersectionBox: {
  18607. value: function ( box ) {
  18608. console.warn( 'THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().' );
  18609. return this.intersectsBox( box );
  18610. }
  18611. }
  18612. } );
  18613. Object.defineProperties( THREE.Box3.prototype, {
  18614. isIntersectionBox: {
  18615. value: function ( box ) {
  18616. console.warn( 'THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().' );
  18617. return this.intersectsBox( box );
  18618. }
  18619. },
  18620. isIntersectionSphere: {
  18621. value: function ( sphere ) {
  18622. console.warn( 'THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  18623. return this.intersectsSphere( sphere );
  18624. }
  18625. }
  18626. } );
  18627. Object.defineProperties( THREE.Matrix3.prototype, {
  18628. multiplyVector3: {
  18629. value: function ( vector ) {
  18630. console.warn( 'THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.' );
  18631. return vector.applyMatrix3( this );
  18632. }
  18633. },
  18634. multiplyVector3Array: {
  18635. value: function ( a ) {
  18636. console.warn( 'THREE.Matrix3: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
  18637. return this.applyToVector3Array( a );
  18638. }
  18639. }
  18640. } );
  18641. Object.defineProperties( THREE.Matrix4.prototype, {
  18642. extractPosition: {
  18643. value: function ( m ) {
  18644. console.warn( 'THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().' );
  18645. return this.copyPosition( m );
  18646. }
  18647. },
  18648. setRotationFromQuaternion: {
  18649. value: function ( q ) {
  18650. console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' );
  18651. return this.makeRotationFromQuaternion( q );
  18652. }
  18653. },
  18654. multiplyVector3: {
  18655. value: function ( vector ) {
  18656. console.warn( 'THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) or vector.applyProjection( matrix ) instead.' );
  18657. return vector.applyProjection( this );
  18658. }
  18659. },
  18660. multiplyVector4: {
  18661. value: function ( vector ) {
  18662. console.warn( 'THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  18663. return vector.applyMatrix4( this );
  18664. }
  18665. },
  18666. multiplyVector3Array: {
  18667. value: function ( a ) {
  18668. console.warn( 'THREE.Matrix4: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
  18669. return this.applyToVector3Array( a );
  18670. }
  18671. },
  18672. rotateAxis: {
  18673. value: function ( v ) {
  18674. console.warn( 'THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.' );
  18675. v.transformDirection( this );
  18676. }
  18677. },
  18678. crossVector: {
  18679. value: function ( vector ) {
  18680. console.warn( 'THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  18681. return vector.applyMatrix4( this );
  18682. }
  18683. },
  18684. translate: {
  18685. value: function ( v ) {
  18686. console.error( 'THREE.Matrix4: .translate() has been removed.' );
  18687. }
  18688. },
  18689. rotateX: {
  18690. value: function ( angle ) {
  18691. console.error( 'THREE.Matrix4: .rotateX() has been removed.' );
  18692. }
  18693. },
  18694. rotateY: {
  18695. value: function ( angle ) {
  18696. console.error( 'THREE.Matrix4: .rotateY() has been removed.' );
  18697. }
  18698. },
  18699. rotateZ: {
  18700. value: function ( angle ) {
  18701. console.error( 'THREE.Matrix4: .rotateZ() has been removed.' );
  18702. }
  18703. },
  18704. rotateByAxis: {
  18705. value: function ( axis, angle ) {
  18706. console.error( 'THREE.Matrix4: .rotateByAxis() has been removed.' );
  18707. }
  18708. }
  18709. } );
  18710. Object.defineProperties( THREE.Plane.prototype, {
  18711. isIntersectionLine: {
  18712. value: function ( line ) {
  18713. console.warn( 'THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().' );
  18714. return this.intersectsLine( line );
  18715. }
  18716. }
  18717. } );
  18718. Object.defineProperties( THREE.Quaternion.prototype, {
  18719. multiplyVector3: {
  18720. value: function ( vector ) {
  18721. console.warn( 'THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.' );
  18722. return vector.applyQuaternion( this );
  18723. }
  18724. }
  18725. } );
  18726. Object.defineProperties( THREE.Ray.prototype, {
  18727. isIntersectionBox: {
  18728. value: function ( box ) {
  18729. console.warn( 'THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().' );
  18730. return this.intersectsBox( box );
  18731. }
  18732. },
  18733. isIntersectionPlane: {
  18734. value: function ( plane ) {
  18735. console.warn( 'THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().' );
  18736. return this.intersectsPlane( plane );
  18737. }
  18738. },
  18739. isIntersectionSphere: {
  18740. value: function ( sphere ) {
  18741. console.warn( 'THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  18742. return this.intersectsSphere( sphere );
  18743. }
  18744. }
  18745. } );
  18746. Object.defineProperties( THREE.Vector3.prototype, {
  18747. setEulerFromRotationMatrix: {
  18748. value: function () {
  18749. console.error( 'THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.' );
  18750. }
  18751. },
  18752. setEulerFromQuaternion: {
  18753. value: function () {
  18754. console.error( 'THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.' );
  18755. }
  18756. },
  18757. getPositionFromMatrix: {
  18758. value: function ( m ) {
  18759. console.warn( 'THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().' );
  18760. return this.setFromMatrixPosition( m );
  18761. }
  18762. },
  18763. getScaleFromMatrix: {
  18764. value: function ( m ) {
  18765. console.warn( 'THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().' );
  18766. return this.setFromMatrixScale( m );
  18767. }
  18768. },
  18769. getColumnFromMatrix: {
  18770. value: function ( index, matrix ) {
  18771. console.warn( 'THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().' );
  18772. return this.setFromMatrixColumn( index, matrix );
  18773. }
  18774. }
  18775. } );
  18776. //
  18777. Object.defineProperties( THREE.Object3D.prototype, {
  18778. eulerOrder: {
  18779. get: function () {
  18780. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  18781. return this.rotation.order;
  18782. },
  18783. set: function ( value ) {
  18784. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  18785. this.rotation.order = value;
  18786. }
  18787. },
  18788. getChildByName: {
  18789. value: function ( name ) {
  18790. console.warn( 'THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().' );
  18791. return this.getObjectByName( name );
  18792. }
  18793. },
  18794. renderDepth: {
  18795. set: function ( value ) {
  18796. console.warn( 'THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.' );
  18797. }
  18798. },
  18799. translate: {
  18800. value: function ( distance, axis ) {
  18801. console.warn( 'THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.' );
  18802. return this.translateOnAxis( axis, distance );
  18803. }
  18804. },
  18805. useQuaternion: {
  18806. get: function () {
  18807. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  18808. },
  18809. set: function ( value ) {
  18810. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  18811. }
  18812. }
  18813. } );
  18814. //
  18815. Object.defineProperties( THREE, {
  18816. PointCloud: {
  18817. value: function ( geometry, material ) {
  18818. console.warn( 'THREE.PointCloud has been renamed to THREE.Points.' );
  18819. return new THREE.Points( geometry, material );
  18820. }
  18821. },
  18822. ParticleSystem: {
  18823. value: function ( geometry, material ) {
  18824. console.warn( 'THREE.ParticleSystem has been renamed to THREE.Points.' );
  18825. return new THREE.Points( geometry, material );
  18826. }
  18827. }
  18828. } );
  18829. //
  18830. Object.defineProperties( THREE.Light.prototype, {
  18831. onlyShadow: {
  18832. set: function ( value ) {
  18833. console.warn( 'THREE.Light: .onlyShadow has been removed.' );
  18834. }
  18835. },
  18836. shadowCameraFov: {
  18837. set: function ( value ) {
  18838. this.shadow.camera.fov = value;
  18839. }
  18840. },
  18841. shadowCameraLeft: {
  18842. set: function ( value ) {
  18843. this.shadow.camera.left = value;
  18844. }
  18845. },
  18846. shadowCameraRight: {
  18847. set: function ( value ) {
  18848. this.shadow.camera.right = value;
  18849. }
  18850. },
  18851. shadowCameraTop: {
  18852. set: function ( value ) {
  18853. this.shadow.camera.top = value;
  18854. }
  18855. },
  18856. shadowCameraBottom: {
  18857. set: function ( value ) {
  18858. this.shadow.camera.bottom = value;
  18859. }
  18860. },
  18861. shadowCameraNear: {
  18862. set: function ( value ) {
  18863. this.shadow.camera.near = value;
  18864. }
  18865. },
  18866. shadowCameraFar: {
  18867. set: function ( value ) {
  18868. this.shadow.camera.far = value;
  18869. }
  18870. },
  18871. shadowCameraVisible: {
  18872. set: function ( value ) {
  18873. console.warn( 'THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow ) instead.' );
  18874. }
  18875. },
  18876. shadowBias: {
  18877. set: function ( value ) {
  18878. this.shadow.bias = value;
  18879. }
  18880. },
  18881. shadowDarkness: {
  18882. set: function ( value ) {
  18883. this.shadow.darkness = value;
  18884. }
  18885. },
  18886. shadowMapWidth: {
  18887. set: function ( value ) {
  18888. this.shadow.mapSize.width = value;
  18889. }
  18890. },
  18891. shadowMapHeight: {
  18892. set: function ( value ) {
  18893. this.shadow.mapSize.height = value;
  18894. }
  18895. }
  18896. } );
  18897. //
  18898. Object.defineProperties( THREE.Material.prototype, {
  18899. wrapAround: {
  18900. get: function () {
  18901. console.warn( 'THREE.' + this.type + ': .wrapAround has been removed.' );
  18902. },
  18903. set: function ( value ) {
  18904. console.warn( 'THREE.' + this.type + ': .wrapAround has been removed.' );
  18905. }
  18906. },
  18907. wrapRGB: {
  18908. get: function () {
  18909. console.warn( 'THREE.' + this.type + ': .wrapRGB has been removed.' );
  18910. return new THREE.Color();
  18911. }
  18912. }
  18913. } );
  18914. Object.defineProperties( THREE, {
  18915. PointCloudMaterial: {
  18916. value: function ( parameters ) {
  18917. console.warn( 'THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.' );
  18918. return new THREE.PointsMaterial( parameters );
  18919. }
  18920. },
  18921. ParticleBasicMaterial: {
  18922. value: function ( parameters ) {
  18923. console.warn( 'THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.' );
  18924. return new THREE.PointsMaterial( parameters );
  18925. }
  18926. },
  18927. ParticleSystemMaterial:{
  18928. value: function ( parameters ) {
  18929. console.warn( 'THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.' );
  18930. return new THREE.PointsMaterial( parameters );
  18931. }
  18932. }
  18933. } );
  18934. Object.defineProperties( THREE.ShaderMaterial.prototype, {
  18935. derivatives: {
  18936. get: function () {
  18937. console.warn( 'THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  18938. return this.extensions.derivatives;
  18939. },
  18940. set: function ( value ) {
  18941. console.warn( 'THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  18942. this.extensions.derivatives = value;
  18943. }
  18944. }
  18945. } );
  18946. //
  18947. Object.defineProperties( THREE.WebGLRenderer.prototype, {
  18948. supportsFloatTextures: {
  18949. value: function () {
  18950. console.warn( 'THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).' );
  18951. return this.extensions.get( 'OES_texture_float' );
  18952. }
  18953. },
  18954. supportsHalfFloatTextures: {
  18955. value: function () {
  18956. console.warn( 'THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).' );
  18957. return this.extensions.get( 'OES_texture_half_float' );
  18958. }
  18959. },
  18960. supportsStandardDerivatives: {
  18961. value: function () {
  18962. console.warn( 'THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).' );
  18963. return this.extensions.get( 'OES_standard_derivatives' );
  18964. }
  18965. },
  18966. supportsCompressedTextureS3TC: {
  18967. value: function () {
  18968. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).' );
  18969. return this.extensions.get( 'WEBGL_compressed_texture_s3tc' );
  18970. }
  18971. },
  18972. supportsCompressedTexturePVRTC: {
  18973. value: function () {
  18974. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).' );
  18975. return this.extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  18976. }
  18977. },
  18978. supportsBlendMinMax: {
  18979. value: function () {
  18980. console.warn( 'THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).' );
  18981. return this.extensions.get( 'EXT_blend_minmax' );
  18982. }
  18983. },
  18984. supportsVertexTextures: {
  18985. value: function () {
  18986. return this.capabilities.vertexTextures;
  18987. }
  18988. },
  18989. supportsInstancedArrays: {
  18990. value: function () {
  18991. console.warn( 'THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).' );
  18992. return this.extensions.get( 'ANGLE_instanced_arrays' );
  18993. }
  18994. },
  18995. initMaterial: {
  18996. value: function () {
  18997. console.warn( 'THREE.WebGLRenderer: .initMaterial() has been removed.' );
  18998. }
  18999. },
  19000. addPrePlugin: {
  19001. value: function () {
  19002. console.warn( 'THREE.WebGLRenderer: .addPrePlugin() has been removed.' );
  19003. }
  19004. },
  19005. addPostPlugin: {
  19006. value: function () {
  19007. console.warn( 'THREE.WebGLRenderer: .addPostPlugin() has been removed.' );
  19008. }
  19009. },
  19010. updateShadowMap: {
  19011. value: function () {
  19012. console.warn( 'THREE.WebGLRenderer: .updateShadowMap() has been removed.' );
  19013. }
  19014. },
  19015. shadowMapEnabled: {
  19016. get: function () {
  19017. return this.shadowMap.enabled;
  19018. },
  19019. set: function ( value ) {
  19020. console.warn( 'THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.' );
  19021. this.shadowMap.enabled = value;
  19022. }
  19023. },
  19024. shadowMapType: {
  19025. get: function () {
  19026. return this.shadowMap.type;
  19027. },
  19028. set: function ( value ) {
  19029. console.warn( 'THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.' );
  19030. this.shadowMap.type = value;
  19031. }
  19032. },
  19033. shadowMapCullFace: {
  19034. get: function () {
  19035. return this.shadowMap.cullFace;
  19036. },
  19037. set: function ( value ) {
  19038. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace is now .shadowMap.cullFace.' );
  19039. this.shadowMap.cullFace = value;
  19040. }
  19041. },
  19042. shadowMapDebug: {
  19043. get: function () {
  19044. return this.shadowMap.debug;
  19045. },
  19046. set: function ( value ) {
  19047. console.warn( 'THREE.WebGLRenderer: .shadowMapDebug is now .shadowMap.debug.' );
  19048. this.shadowMap.debug = value;
  19049. }
  19050. }
  19051. } );
  19052. //
  19053. Object.defineProperties( THREE.WebGLRenderTarget.prototype, {
  19054. wrapS: {
  19055. get: function () {
  19056. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  19057. return this.texture.wrapS;
  19058. },
  19059. set: function ( value ) {
  19060. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  19061. this.texture.wrapS = value;
  19062. }
  19063. },
  19064. wrapT: {
  19065. get: function () {
  19066. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  19067. return this.texture.wrapT;
  19068. },
  19069. set: function ( value ) {
  19070. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  19071. this.texture.wrapT = value;
  19072. }
  19073. },
  19074. magFilter: {
  19075. get: function () {
  19076. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  19077. return this.texture.magFilter;
  19078. },
  19079. set: function ( value ) {
  19080. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  19081. this.texture.magFilter = value;
  19082. }
  19083. },
  19084. minFilter: {
  19085. get: function () {
  19086. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  19087. return this.texture.minFilter;
  19088. },
  19089. set: function ( value ) {
  19090. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  19091. this.texture.minFilter = value;
  19092. }
  19093. },
  19094. anisotropy: {
  19095. get: function () {
  19096. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  19097. return this.texture.anisotropy;
  19098. },
  19099. set: function ( value ) {
  19100. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  19101. this.texture.anisotropy = value;
  19102. }
  19103. },
  19104. offset: {
  19105. get: function () {
  19106. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  19107. return this.texture.offset;
  19108. },
  19109. set: function ( value ) {
  19110. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  19111. this.texture.offset = value;
  19112. }
  19113. },
  19114. repeat: {
  19115. get: function () {
  19116. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  19117. return this.texture.repeat;
  19118. },
  19119. set: function ( value ) {
  19120. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  19121. this.texture.repeat = value;
  19122. }
  19123. },
  19124. format: {
  19125. get: function () {
  19126. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  19127. return this.texture.format;
  19128. },
  19129. set: function ( value ) {
  19130. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  19131. this.texture.format = value;
  19132. }
  19133. },
  19134. type: {
  19135. get: function () {
  19136. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  19137. return this.texture.type;
  19138. },
  19139. set: function ( value ) {
  19140. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  19141. this.texture.type = value;
  19142. }
  19143. },
  19144. generateMipmaps: {
  19145. get: function () {
  19146. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  19147. return this.texture.generateMipmaps;
  19148. },
  19149. set: function ( value ) {
  19150. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  19151. this.texture.generateMipmaps = value;
  19152. }
  19153. }
  19154. } );
  19155. //
  19156. THREE.GeometryUtils = {
  19157. merge: function ( geometry1, geometry2, materialIndexOffset ) {
  19158. console.warn( 'THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.' );
  19159. var matrix;
  19160. if ( geometry2 instanceof THREE.Mesh ) {
  19161. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  19162. matrix = geometry2.matrix;
  19163. geometry2 = geometry2.geometry;
  19164. }
  19165. geometry1.merge( geometry2, matrix, materialIndexOffset );
  19166. },
  19167. center: function ( geometry ) {
  19168. console.warn( 'THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.' );
  19169. return geometry.center();
  19170. }
  19171. };
  19172. THREE.ImageUtils = {
  19173. crossOrigin: undefined,
  19174. loadTexture: function ( url, mapping, onLoad, onError ) {
  19175. console.warn( 'THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.' );
  19176. var loader = new THREE.TextureLoader();
  19177. loader.setCrossOrigin( this.crossOrigin );
  19178. var texture = loader.load( url, onLoad, undefined, onError );
  19179. if ( mapping ) texture.mapping = mapping;
  19180. return texture;
  19181. },
  19182. loadTextureCube: function ( urls, mapping, onLoad, onError ) {
  19183. console.warn( 'THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.' );
  19184. var loader = new THREE.CubeTextureLoader();
  19185. loader.setCrossOrigin( this.crossOrigin );
  19186. var texture = loader.load( urls, onLoad, undefined, onError );
  19187. if ( mapping ) texture.mapping = mapping;
  19188. return texture;
  19189. },
  19190. loadCompressedTexture: function () {
  19191. console.error( 'THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.' )
  19192. },
  19193. loadCompressedTextureCube: function () {
  19194. console.error( 'THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.' )
  19195. }
  19196. };
  19197. //
  19198. THREE.Projector = function () {
  19199. console.error( 'THREE.Projector has been moved to /examples/js/renderers/Projector.js.' );
  19200. this.projectVector = function ( vector, camera ) {
  19201. console.warn( 'THREE.Projector: .projectVector() is now vector.project().' );
  19202. vector.project( camera );
  19203. };
  19204. this.unprojectVector = function ( vector, camera ) {
  19205. console.warn( 'THREE.Projector: .unprojectVector() is now vector.unproject().' );
  19206. vector.unproject( camera );
  19207. };
  19208. this.pickingRay = function ( vector, camera ) {
  19209. console.error( 'THREE.Projector: .pickingRay() is now raycaster.setFromCamera().' );
  19210. };
  19211. };
  19212. //
  19213. THREE.CanvasRenderer = function () {
  19214. console.error( 'THREE.CanvasRenderer has been moved to /examples/js/renderers/CanvasRenderer.js' );
  19215. this.domElement = document.createElement( 'canvas' );
  19216. this.clear = function () {};
  19217. this.render = function () {};
  19218. this.setClearColor = function () {};
  19219. this.setSize = function () {};
  19220. };
  19221. // File:src/extras/CurveUtils.js
  19222. /**
  19223. * @author zz85 / http://www.lab4games.net/zz85/blog
  19224. */
  19225. THREE.CurveUtils = {
  19226. tangentQuadraticBezier: function ( t, p0, p1, p2 ) {
  19227. return 2 * ( 1 - t ) * ( p1 - p0 ) + 2 * t * ( p2 - p1 );
  19228. },
  19229. // Puay Bing, thanks for helping with this derivative!
  19230. tangentCubicBezier: function ( t, p0, p1, p2, p3 ) {
  19231. return - 3 * p0 * ( 1 - t ) * ( 1 - t ) +
  19232. 3 * p1 * ( 1 - t ) * ( 1 - t ) - 6 * t * p1 * ( 1 - t ) +
  19233. 6 * t * p2 * ( 1 - t ) - 3 * t * t * p2 +
  19234. 3 * t * t * p3;
  19235. },
  19236. tangentSpline: function ( t, p0, p1, p2, p3 ) {
  19237. // To check if my formulas are correct
  19238. var h00 = 6 * t * t - 6 * t; // derived from 2t^3 − 3t^2 + 1
  19239. var h10 = 3 * t * t - 4 * t + 1; // t^3 − 2t^2 + t
  19240. var h01 = - 6 * t * t + 6 * t; // − 2t3 + 3t2
  19241. var h11 = 3 * t * t - 2 * t; // t3 − t2
  19242. return h00 + h10 + h01 + h11;
  19243. },
  19244. // Catmull-Rom
  19245. interpolate: function( p0, p1, p2, p3, t ) {
  19246. var v0 = ( p2 - p0 ) * 0.5;
  19247. var v1 = ( p3 - p1 ) * 0.5;
  19248. var t2 = t * t;
  19249. var t3 = t * t2;
  19250. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  19251. }
  19252. };
  19253. // File:src/extras/SceneUtils.js
  19254. /**
  19255. * @author alteredq / http://alteredqualia.com/
  19256. */
  19257. THREE.SceneUtils = {
  19258. createMultiMaterialObject: function ( geometry, materials ) {
  19259. var group = new THREE.Group();
  19260. for ( var i = 0, l = materials.length; i < l; i ++ ) {
  19261. group.add( new THREE.Mesh( geometry, materials[ i ] ) );
  19262. }
  19263. return group;
  19264. },
  19265. detach: function ( child, parent, scene ) {
  19266. child.applyMatrix( parent.matrixWorld );
  19267. parent.remove( child );
  19268. scene.add( child );
  19269. },
  19270. attach: function ( child, scene, parent ) {
  19271. var matrixWorldInverse = new THREE.Matrix4();
  19272. matrixWorldInverse.getInverse( parent.matrixWorld );
  19273. child.applyMatrix( matrixWorldInverse );
  19274. scene.remove( child );
  19275. parent.add( child );
  19276. }
  19277. };
  19278. // File:src/extras/ShapeUtils.js
  19279. /**
  19280. * @author zz85 / http://www.lab4games.net/zz85/blog
  19281. */
  19282. THREE.ShapeUtils = {
  19283. // calculate area of the contour polygon
  19284. area: function ( contour ) {
  19285. var n = contour.length;
  19286. var a = 0.0;
  19287. for ( var p = n - 1, q = 0; q < n; p = q ++ ) {
  19288. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  19289. }
  19290. return a * 0.5;
  19291. },
  19292. triangulate: ( function () {
  19293. /**
  19294. * This code is a quick port of code written in C++ which was submitted to
  19295. * flipcode.com by John W. Ratcliff // July 22, 2000
  19296. * See original code and more information here:
  19297. * http://www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml
  19298. *
  19299. * ported to actionscript by Zevan Rosser
  19300. * www.actionsnippet.com
  19301. *
  19302. * ported to javascript by Joshua Koo
  19303. * http://www.lab4games.net/zz85/blog
  19304. *
  19305. */
  19306. function snip( contour, u, v, w, n, verts ) {
  19307. var p;
  19308. var ax, ay, bx, by;
  19309. var cx, cy, px, py;
  19310. ax = contour[ verts[ u ] ].x;
  19311. ay = contour[ verts[ u ] ].y;
  19312. bx = contour[ verts[ v ] ].x;
  19313. by = contour[ verts[ v ] ].y;
  19314. cx = contour[ verts[ w ] ].x;
  19315. cy = contour[ verts[ w ] ].y;
  19316. if ( Number.EPSILON > ( ( ( bx - ax ) * ( cy - ay ) ) - ( ( by - ay ) * ( cx - ax ) ) ) ) return false;
  19317. var aX, aY, bX, bY, cX, cY;
  19318. var apx, apy, bpx, bpy, cpx, cpy;
  19319. var cCROSSap, bCROSScp, aCROSSbp;
  19320. aX = cx - bx; aY = cy - by;
  19321. bX = ax - cx; bY = ay - cy;
  19322. cX = bx - ax; cY = by - ay;
  19323. for ( p = 0; p < n; p ++ ) {
  19324. px = contour[ verts[ p ] ].x;
  19325. py = contour[ verts[ p ] ].y;
  19326. if ( ( ( px === ax ) && ( py === ay ) ) ||
  19327. ( ( px === bx ) && ( py === by ) ) ||
  19328. ( ( px === cx ) && ( py === cy ) ) ) continue;
  19329. apx = px - ax; apy = py - ay;
  19330. bpx = px - bx; bpy = py - by;
  19331. cpx = px - cx; cpy = py - cy;
  19332. // see if p is inside triangle abc
  19333. aCROSSbp = aX * bpy - aY * bpx;
  19334. cCROSSap = cX * apy - cY * apx;
  19335. bCROSScp = bX * cpy - bY * cpx;
  19336. if ( ( aCROSSbp >= - Number.EPSILON ) && ( bCROSScp >= - Number.EPSILON ) && ( cCROSSap >= - Number.EPSILON ) ) return false;
  19337. }
  19338. return true;
  19339. }
  19340. // takes in an contour array and returns
  19341. return function ( contour, indices ) {
  19342. var n = contour.length;
  19343. if ( n < 3 ) return null;
  19344. var result = [],
  19345. verts = [],
  19346. vertIndices = [];
  19347. /* we want a counter-clockwise polygon in verts */
  19348. var u, v, w;
  19349. if ( THREE.ShapeUtils.area( contour ) > 0.0 ) {
  19350. for ( v = 0; v < n; v ++ ) verts[ v ] = v;
  19351. } else {
  19352. for ( v = 0; v < n; v ++ ) verts[ v ] = ( n - 1 ) - v;
  19353. }
  19354. var nv = n;
  19355. /* remove nv - 2 vertices, creating 1 triangle every time */
  19356. var count = 2 * nv; /* error detection */
  19357. for ( v = nv - 1; nv > 2; ) {
  19358. /* if we loop, it is probably a non-simple polygon */
  19359. if ( ( count -- ) <= 0 ) {
  19360. //** Triangulate: ERROR - probable bad polygon!
  19361. //throw ( "Warning, unable to triangulate polygon!" );
  19362. //return null;
  19363. // Sometimes warning is fine, especially polygons are triangulated in reverse.
  19364. console.warn( 'THREE.ShapeUtils: Unable to triangulate polygon! in triangulate()' );
  19365. if ( indices ) return vertIndices;
  19366. return result;
  19367. }
  19368. /* three consecutive vertices in current polygon, <u,v,w> */
  19369. u = v; if ( nv <= u ) u = 0; /* previous */
  19370. v = u + 1; if ( nv <= v ) v = 0; /* new v */
  19371. w = v + 1; if ( nv <= w ) w = 0; /* next */
  19372. if ( snip( contour, u, v, w, nv, verts ) ) {
  19373. var a, b, c, s, t;
  19374. /* true names of the vertices */
  19375. a = verts[ u ];
  19376. b = verts[ v ];
  19377. c = verts[ w ];
  19378. /* output Triangle */
  19379. result.push( [ contour[ a ],
  19380. contour[ b ],
  19381. contour[ c ] ] );
  19382. vertIndices.push( [ verts[ u ], verts[ v ], verts[ w ] ] );
  19383. /* remove v from the remaining polygon */
  19384. for ( s = v, t = v + 1; t < nv; s ++, t ++ ) {
  19385. verts[ s ] = verts[ t ];
  19386. }
  19387. nv --;
  19388. /* reset error detection counter */
  19389. count = 2 * nv;
  19390. }
  19391. }
  19392. if ( indices ) return vertIndices;
  19393. return result;
  19394. }
  19395. } )(),
  19396. triangulateShape: function ( contour, holes ) {
  19397. function point_in_segment_2D_colin( inSegPt1, inSegPt2, inOtherPt ) {
  19398. // inOtherPt needs to be collinear to the inSegment
  19399. if ( inSegPt1.x !== inSegPt2.x ) {
  19400. if ( inSegPt1.x < inSegPt2.x ) {
  19401. return ( ( inSegPt1.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt2.x ) );
  19402. } else {
  19403. return ( ( inSegPt2.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt1.x ) );
  19404. }
  19405. } else {
  19406. if ( inSegPt1.y < inSegPt2.y ) {
  19407. return ( ( inSegPt1.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt2.y ) );
  19408. } else {
  19409. return ( ( inSegPt2.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt1.y ) );
  19410. }
  19411. }
  19412. }
  19413. function intersect_segments_2D( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1, inSeg2Pt2, inExcludeAdjacentSegs ) {
  19414. var seg1dx = inSeg1Pt2.x - inSeg1Pt1.x, seg1dy = inSeg1Pt2.y - inSeg1Pt1.y;
  19415. var seg2dx = inSeg2Pt2.x - inSeg2Pt1.x, seg2dy = inSeg2Pt2.y - inSeg2Pt1.y;
  19416. var seg1seg2dx = inSeg1Pt1.x - inSeg2Pt1.x;
  19417. var seg1seg2dy = inSeg1Pt1.y - inSeg2Pt1.y;
  19418. var limit = seg1dy * seg2dx - seg1dx * seg2dy;
  19419. var perpSeg1 = seg1dy * seg1seg2dx - seg1dx * seg1seg2dy;
  19420. if ( Math.abs( limit ) > Number.EPSILON ) {
  19421. // not parallel
  19422. var perpSeg2;
  19423. if ( limit > 0 ) {
  19424. if ( ( perpSeg1 < 0 ) || ( perpSeg1 > limit ) ) return [];
  19425. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  19426. if ( ( perpSeg2 < 0 ) || ( perpSeg2 > limit ) ) return [];
  19427. } else {
  19428. if ( ( perpSeg1 > 0 ) || ( perpSeg1 < limit ) ) return [];
  19429. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  19430. if ( ( perpSeg2 > 0 ) || ( perpSeg2 < limit ) ) return [];
  19431. }
  19432. // i.e. to reduce rounding errors
  19433. // intersection at endpoint of segment#1?
  19434. if ( perpSeg2 === 0 ) {
  19435. if ( ( inExcludeAdjacentSegs ) &&
  19436. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  19437. return [ inSeg1Pt1 ];
  19438. }
  19439. if ( perpSeg2 === limit ) {
  19440. if ( ( inExcludeAdjacentSegs ) &&
  19441. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  19442. return [ inSeg1Pt2 ];
  19443. }
  19444. // intersection at endpoint of segment#2?
  19445. if ( perpSeg1 === 0 ) return [ inSeg2Pt1 ];
  19446. if ( perpSeg1 === limit ) return [ inSeg2Pt2 ];
  19447. // return real intersection point
  19448. var factorSeg1 = perpSeg2 / limit;
  19449. return [ { x: inSeg1Pt1.x + factorSeg1 * seg1dx,
  19450. y: inSeg1Pt1.y + factorSeg1 * seg1dy } ];
  19451. } else {
  19452. // parallel or collinear
  19453. if ( ( perpSeg1 !== 0 ) ||
  19454. ( seg2dy * seg1seg2dx !== seg2dx * seg1seg2dy ) ) return [];
  19455. // they are collinear or degenerate
  19456. var seg1Pt = ( ( seg1dx === 0 ) && ( seg1dy === 0 ) ); // segment1 is just a point?
  19457. var seg2Pt = ( ( seg2dx === 0 ) && ( seg2dy === 0 ) ); // segment2 is just a point?
  19458. // both segments are points
  19459. if ( seg1Pt && seg2Pt ) {
  19460. if ( ( inSeg1Pt1.x !== inSeg2Pt1.x ) ||
  19461. ( inSeg1Pt1.y !== inSeg2Pt1.y ) ) return []; // they are distinct points
  19462. return [ inSeg1Pt1 ]; // they are the same point
  19463. }
  19464. // segment#1 is a single point
  19465. if ( seg1Pt ) {
  19466. if ( ! point_in_segment_2D_colin( inSeg2Pt1, inSeg2Pt2, inSeg1Pt1 ) ) return []; // but not in segment#2
  19467. return [ inSeg1Pt1 ];
  19468. }
  19469. // segment#2 is a single point
  19470. if ( seg2Pt ) {
  19471. if ( ! point_in_segment_2D_colin( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1 ) ) return []; // but not in segment#1
  19472. return [ inSeg2Pt1 ];
  19473. }
  19474. // they are collinear segments, which might overlap
  19475. var seg1min, seg1max, seg1minVal, seg1maxVal;
  19476. var seg2min, seg2max, seg2minVal, seg2maxVal;
  19477. if ( seg1dx !== 0 ) {
  19478. // the segments are NOT on a vertical line
  19479. if ( inSeg1Pt1.x < inSeg1Pt2.x ) {
  19480. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.x;
  19481. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.x;
  19482. } else {
  19483. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.x;
  19484. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.x;
  19485. }
  19486. if ( inSeg2Pt1.x < inSeg2Pt2.x ) {
  19487. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.x;
  19488. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.x;
  19489. } else {
  19490. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.x;
  19491. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.x;
  19492. }
  19493. } else {
  19494. // the segments are on a vertical line
  19495. if ( inSeg1Pt1.y < inSeg1Pt2.y ) {
  19496. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.y;
  19497. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.y;
  19498. } else {
  19499. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.y;
  19500. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.y;
  19501. }
  19502. if ( inSeg2Pt1.y < inSeg2Pt2.y ) {
  19503. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.y;
  19504. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.y;
  19505. } else {
  19506. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.y;
  19507. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.y;
  19508. }
  19509. }
  19510. if ( seg1minVal <= seg2minVal ) {
  19511. if ( seg1maxVal < seg2minVal ) return [];
  19512. if ( seg1maxVal === seg2minVal ) {
  19513. if ( inExcludeAdjacentSegs ) return [];
  19514. return [ seg2min ];
  19515. }
  19516. if ( seg1maxVal <= seg2maxVal ) return [ seg2min, seg1max ];
  19517. return [ seg2min, seg2max ];
  19518. } else {
  19519. if ( seg1minVal > seg2maxVal ) return [];
  19520. if ( seg1minVal === seg2maxVal ) {
  19521. if ( inExcludeAdjacentSegs ) return [];
  19522. return [ seg1min ];
  19523. }
  19524. if ( seg1maxVal <= seg2maxVal ) return [ seg1min, seg1max ];
  19525. return [ seg1min, seg2max ];
  19526. }
  19527. }
  19528. }
  19529. function isPointInsideAngle( inVertex, inLegFromPt, inLegToPt, inOtherPt ) {
  19530. // The order of legs is important
  19531. // translation of all points, so that Vertex is at (0,0)
  19532. var legFromPtX = inLegFromPt.x - inVertex.x, legFromPtY = inLegFromPt.y - inVertex.y;
  19533. var legToPtX = inLegToPt.x - inVertex.x, legToPtY = inLegToPt.y - inVertex.y;
  19534. var otherPtX = inOtherPt.x - inVertex.x, otherPtY = inOtherPt.y - inVertex.y;
  19535. // main angle >0: < 180 deg.; 0: 180 deg.; <0: > 180 deg.
  19536. var from2toAngle = legFromPtX * legToPtY - legFromPtY * legToPtX;
  19537. var from2otherAngle = legFromPtX * otherPtY - legFromPtY * otherPtX;
  19538. if ( Math.abs( from2toAngle ) > Number.EPSILON ) {
  19539. // angle != 180 deg.
  19540. var other2toAngle = otherPtX * legToPtY - otherPtY * legToPtX;
  19541. // console.log( "from2to: " + from2toAngle + ", from2other: " + from2otherAngle + ", other2to: " + other2toAngle );
  19542. if ( from2toAngle > 0 ) {
  19543. // main angle < 180 deg.
  19544. return ( ( from2otherAngle >= 0 ) && ( other2toAngle >= 0 ) );
  19545. } else {
  19546. // main angle > 180 deg.
  19547. return ( ( from2otherAngle >= 0 ) || ( other2toAngle >= 0 ) );
  19548. }
  19549. } else {
  19550. // angle == 180 deg.
  19551. // console.log( "from2to: 180 deg., from2other: " + from2otherAngle );
  19552. return ( from2otherAngle > 0 );
  19553. }
  19554. }
  19555. function removeHoles( contour, holes ) {
  19556. var shape = contour.concat(); // work on this shape
  19557. var hole;
  19558. function isCutLineInsideAngles( inShapeIdx, inHoleIdx ) {
  19559. // Check if hole point lies within angle around shape point
  19560. var lastShapeIdx = shape.length - 1;
  19561. var prevShapeIdx = inShapeIdx - 1;
  19562. if ( prevShapeIdx < 0 ) prevShapeIdx = lastShapeIdx;
  19563. var nextShapeIdx = inShapeIdx + 1;
  19564. if ( nextShapeIdx > lastShapeIdx ) nextShapeIdx = 0;
  19565. var insideAngle = isPointInsideAngle( shape[ inShapeIdx ], shape[ prevShapeIdx ], shape[ nextShapeIdx ], hole[ inHoleIdx ] );
  19566. if ( ! insideAngle ) {
  19567. // console.log( "Vertex (Shape): " + inShapeIdx + ", Point: " + hole[inHoleIdx].x + "/" + hole[inHoleIdx].y );
  19568. return false;
  19569. }
  19570. // Check if shape point lies within angle around hole point
  19571. var lastHoleIdx = hole.length - 1;
  19572. var prevHoleIdx = inHoleIdx - 1;
  19573. if ( prevHoleIdx < 0 ) prevHoleIdx = lastHoleIdx;
  19574. var nextHoleIdx = inHoleIdx + 1;
  19575. if ( nextHoleIdx > lastHoleIdx ) nextHoleIdx = 0;
  19576. insideAngle = isPointInsideAngle( hole[ inHoleIdx ], hole[ prevHoleIdx ], hole[ nextHoleIdx ], shape[ inShapeIdx ] );
  19577. if ( ! insideAngle ) {
  19578. // console.log( "Vertex (Hole): " + inHoleIdx + ", Point: " + shape[inShapeIdx].x + "/" + shape[inShapeIdx].y );
  19579. return false;
  19580. }
  19581. return true;
  19582. }
  19583. function intersectsShapeEdge( inShapePt, inHolePt ) {
  19584. // checks for intersections with shape edges
  19585. var sIdx, nextIdx, intersection;
  19586. for ( sIdx = 0; sIdx < shape.length; sIdx ++ ) {
  19587. nextIdx = sIdx + 1; nextIdx %= shape.length;
  19588. intersection = intersect_segments_2D( inShapePt, inHolePt, shape[ sIdx ], shape[ nextIdx ], true );
  19589. if ( intersection.length > 0 ) return true;
  19590. }
  19591. return false;
  19592. }
  19593. var indepHoles = [];
  19594. function intersectsHoleEdge( inShapePt, inHolePt ) {
  19595. // checks for intersections with hole edges
  19596. var ihIdx, chkHole,
  19597. hIdx, nextIdx, intersection;
  19598. for ( ihIdx = 0; ihIdx < indepHoles.length; ihIdx ++ ) {
  19599. chkHole = holes[ indepHoles[ ihIdx ]];
  19600. for ( hIdx = 0; hIdx < chkHole.length; hIdx ++ ) {
  19601. nextIdx = hIdx + 1; nextIdx %= chkHole.length;
  19602. intersection = intersect_segments_2D( inShapePt, inHolePt, chkHole[ hIdx ], chkHole[ nextIdx ], true );
  19603. if ( intersection.length > 0 ) return true;
  19604. }
  19605. }
  19606. return false;
  19607. }
  19608. var holeIndex, shapeIndex,
  19609. shapePt, holePt,
  19610. holeIdx, cutKey, failedCuts = [],
  19611. tmpShape1, tmpShape2,
  19612. tmpHole1, tmpHole2;
  19613. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  19614. indepHoles.push( h );
  19615. }
  19616. var minShapeIndex = 0;
  19617. var counter = indepHoles.length * 2;
  19618. while ( indepHoles.length > 0 ) {
  19619. counter --;
  19620. if ( counter < 0 ) {
  19621. console.log( "Infinite Loop! Holes left:" + indepHoles.length + ", Probably Hole outside Shape!" );
  19622. break;
  19623. }
  19624. // search for shape-vertex and hole-vertex,
  19625. // which can be connected without intersections
  19626. for ( shapeIndex = minShapeIndex; shapeIndex < shape.length; shapeIndex ++ ) {
  19627. shapePt = shape[ shapeIndex ];
  19628. holeIndex = - 1;
  19629. // search for hole which can be reached without intersections
  19630. for ( var h = 0; h < indepHoles.length; h ++ ) {
  19631. holeIdx = indepHoles[ h ];
  19632. // prevent multiple checks
  19633. cutKey = shapePt.x + ":" + shapePt.y + ":" + holeIdx;
  19634. if ( failedCuts[ cutKey ] !== undefined ) continue;
  19635. hole = holes[ holeIdx ];
  19636. for ( var h2 = 0; h2 < hole.length; h2 ++ ) {
  19637. holePt = hole[ h2 ];
  19638. if ( ! isCutLineInsideAngles( shapeIndex, h2 ) ) continue;
  19639. if ( intersectsShapeEdge( shapePt, holePt ) ) continue;
  19640. if ( intersectsHoleEdge( shapePt, holePt ) ) continue;
  19641. holeIndex = h2;
  19642. indepHoles.splice( h, 1 );
  19643. tmpShape1 = shape.slice( 0, shapeIndex + 1 );
  19644. tmpShape2 = shape.slice( shapeIndex );
  19645. tmpHole1 = hole.slice( holeIndex );
  19646. tmpHole2 = hole.slice( 0, holeIndex + 1 );
  19647. shape = tmpShape1.concat( tmpHole1 ).concat( tmpHole2 ).concat( tmpShape2 );
  19648. minShapeIndex = shapeIndex;
  19649. // Debug only, to show the selected cuts
  19650. // glob_CutLines.push( [ shapePt, holePt ] );
  19651. break;
  19652. }
  19653. if ( holeIndex >= 0 ) break; // hole-vertex found
  19654. failedCuts[ cutKey ] = true; // remember failure
  19655. }
  19656. if ( holeIndex >= 0 ) break; // hole-vertex found
  19657. }
  19658. }
  19659. return shape; /* shape with no holes */
  19660. }
  19661. var i, il, f, face,
  19662. key, index,
  19663. allPointsMap = {};
  19664. // 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.
  19665. var allpoints = contour.concat();
  19666. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  19667. Array.prototype.push.apply( allpoints, holes[ h ] );
  19668. }
  19669. //console.log( "allpoints",allpoints, allpoints.length );
  19670. // prepare all points map
  19671. for ( i = 0, il = allpoints.length; i < il; i ++ ) {
  19672. key = allpoints[ i ].x + ":" + allpoints[ i ].y;
  19673. if ( allPointsMap[ key ] !== undefined ) {
  19674. console.warn( "THREE.Shape: Duplicate point", key );
  19675. }
  19676. allPointsMap[ key ] = i;
  19677. }
  19678. // remove holes by cutting paths to holes and adding them to the shape
  19679. var shapeWithoutHoles = removeHoles( contour, holes );
  19680. var triangles = THREE.ShapeUtils.triangulate( shapeWithoutHoles, false ); // True returns indices for points of spooled shape
  19681. //console.log( "triangles",triangles, triangles.length );
  19682. // check all face vertices against all points map
  19683. for ( i = 0, il = triangles.length; i < il; i ++ ) {
  19684. face = triangles[ i ];
  19685. for ( f = 0; f < 3; f ++ ) {
  19686. key = face[ f ].x + ":" + face[ f ].y;
  19687. index = allPointsMap[ key ];
  19688. if ( index !== undefined ) {
  19689. face[ f ] = index;
  19690. }
  19691. }
  19692. }
  19693. return triangles.concat();
  19694. },
  19695. isClockWise: function ( pts ) {
  19696. return THREE.ShapeUtils.area( pts ) < 0;
  19697. },
  19698. // Bezier Curves formulas obtained from
  19699. // http://en.wikipedia.org/wiki/B%C3%A9zier_curve
  19700. // Quad Bezier Functions
  19701. b2: ( function () {
  19702. function b2p0( t, p ) {
  19703. var k = 1 - t;
  19704. return k * k * p;
  19705. }
  19706. function b2p1( t, p ) {
  19707. return 2 * ( 1 - t ) * t * p;
  19708. }
  19709. function b2p2( t, p ) {
  19710. return t * t * p;
  19711. }
  19712. return function ( t, p0, p1, p2 ) {
  19713. return b2p0( t, p0 ) + b2p1( t, p1 ) + b2p2( t, p2 );
  19714. };
  19715. } )(),
  19716. // Cubic Bezier Functions
  19717. b3: ( function () {
  19718. function b3p0( t, p ) {
  19719. var k = 1 - t;
  19720. return k * k * k * p;
  19721. }
  19722. function b3p1( t, p ) {
  19723. var k = 1 - t;
  19724. return 3 * k * k * t * p;
  19725. }
  19726. function b3p2( t, p ) {
  19727. var k = 1 - t;
  19728. return 3 * k * t * t * p;
  19729. }
  19730. function b3p3( t, p ) {
  19731. return t * t * t * p;
  19732. }
  19733. return function ( t, p0, p1, p2, p3 ) {
  19734. return b3p0( t, p0 ) + b3p1( t, p1 ) + b3p2( t, p2 ) + b3p3( t, p3 );
  19735. };
  19736. } )()
  19737. };
  19738. // File:src/extras/core/Curve.js
  19739. /**
  19740. * @author zz85 / http://www.lab4games.net/zz85/blog
  19741. * Extensible curve object
  19742. *
  19743. * Some common of Curve methods
  19744. * .getPoint(t), getTangent(t)
  19745. * .getPointAt(u), getTagentAt(u)
  19746. * .getPoints(), .getSpacedPoints()
  19747. * .getLength()
  19748. * .updateArcLengths()
  19749. *
  19750. * This following classes subclasses THREE.Curve:
  19751. *
  19752. * -- 2d classes --
  19753. * THREE.LineCurve
  19754. * THREE.QuadraticBezierCurve
  19755. * THREE.CubicBezierCurve
  19756. * THREE.SplineCurve
  19757. * THREE.ArcCurve
  19758. * THREE.EllipseCurve
  19759. *
  19760. * -- 3d classes --
  19761. * THREE.LineCurve3
  19762. * THREE.QuadraticBezierCurve3
  19763. * THREE.CubicBezierCurve3
  19764. * THREE.SplineCurve3
  19765. * THREE.ClosedSplineCurve3
  19766. *
  19767. * A series of curves can be represented as a THREE.CurvePath
  19768. *
  19769. **/
  19770. /**************************************************************
  19771. * Abstract Curve base class
  19772. **************************************************************/
  19773. THREE.Curve = function () {
  19774. };
  19775. THREE.Curve.prototype = {
  19776. constructor: THREE.Curve,
  19777. // Virtual base class method to overwrite and implement in subclasses
  19778. // - t [0 .. 1]
  19779. getPoint: function ( t ) {
  19780. console.warn( "THREE.Curve: Warning, getPoint() not implemented!" );
  19781. return null;
  19782. },
  19783. // Get point at relative position in curve according to arc length
  19784. // - u [0 .. 1]
  19785. getPointAt: function ( u ) {
  19786. var t = this.getUtoTmapping( u );
  19787. return this.getPoint( t );
  19788. },
  19789. // Get sequence of points using getPoint( t )
  19790. getPoints: function ( divisions ) {
  19791. if ( ! divisions ) divisions = 5;
  19792. var d, pts = [];
  19793. for ( d = 0; d <= divisions; d ++ ) {
  19794. pts.push( this.getPoint( d / divisions ) );
  19795. }
  19796. return pts;
  19797. },
  19798. // Get sequence of points using getPointAt( u )
  19799. getSpacedPoints: function ( divisions ) {
  19800. if ( ! divisions ) divisions = 5;
  19801. var d, pts = [];
  19802. for ( d = 0; d <= divisions; d ++ ) {
  19803. pts.push( this.getPointAt( d / divisions ) );
  19804. }
  19805. return pts;
  19806. },
  19807. // Get total curve arc length
  19808. getLength: function () {
  19809. var lengths = this.getLengths();
  19810. return lengths[ lengths.length - 1 ];
  19811. },
  19812. // Get list of cumulative segment lengths
  19813. getLengths: function ( divisions ) {
  19814. if ( ! divisions ) divisions = ( this.__arcLengthDivisions ) ? ( this.__arcLengthDivisions ) : 200;
  19815. if ( this.cacheArcLengths
  19816. && ( this.cacheArcLengths.length === divisions + 1 )
  19817. && ! this.needsUpdate ) {
  19818. //console.log( "cached", this.cacheArcLengths );
  19819. return this.cacheArcLengths;
  19820. }
  19821. this.needsUpdate = false;
  19822. var cache = [];
  19823. var current, last = this.getPoint( 0 );
  19824. var p, sum = 0;
  19825. cache.push( 0 );
  19826. for ( p = 1; p <= divisions; p ++ ) {
  19827. current = this.getPoint ( p / divisions );
  19828. sum += current.distanceTo( last );
  19829. cache.push( sum );
  19830. last = current;
  19831. }
  19832. this.cacheArcLengths = cache;
  19833. return cache; // { sums: cache, sum:sum }; Sum is in the last element.
  19834. },
  19835. updateArcLengths: function() {
  19836. this.needsUpdate = true;
  19837. this.getLengths();
  19838. },
  19839. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  19840. getUtoTmapping: function ( u, distance ) {
  19841. var arcLengths = this.getLengths();
  19842. var i = 0, il = arcLengths.length;
  19843. var targetArcLength; // The targeted u distance value to get
  19844. if ( distance ) {
  19845. targetArcLength = distance;
  19846. } else {
  19847. targetArcLength = u * arcLengths[ il - 1 ];
  19848. }
  19849. //var time = Date.now();
  19850. // binary search for the index with largest value smaller than target u distance
  19851. var low = 0, high = il - 1, comparison;
  19852. while ( low <= high ) {
  19853. 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
  19854. comparison = arcLengths[ i ] - targetArcLength;
  19855. if ( comparison < 0 ) {
  19856. low = i + 1;
  19857. } else if ( comparison > 0 ) {
  19858. high = i - 1;
  19859. } else {
  19860. high = i;
  19861. break;
  19862. // DONE
  19863. }
  19864. }
  19865. i = high;
  19866. //console.log('b' , i, low, high, Date.now()- time);
  19867. if ( arcLengths[ i ] === targetArcLength ) {
  19868. var t = i / ( il - 1 );
  19869. return t;
  19870. }
  19871. // we could get finer grain at lengths, or use simple interpolation between two points
  19872. var lengthBefore = arcLengths[ i ];
  19873. var lengthAfter = arcLengths[ i + 1 ];
  19874. var segmentLength = lengthAfter - lengthBefore;
  19875. // determine where we are between the 'before' and 'after' points
  19876. var segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  19877. // add that fractional amount to t
  19878. var t = ( i + segmentFraction ) / ( il - 1 );
  19879. return t;
  19880. },
  19881. // Returns a unit vector tangent at t
  19882. // In case any sub curve does not implement its tangent derivation,
  19883. // 2 points a small delta apart will be used to find its gradient
  19884. // which seems to give a reasonable approximation
  19885. getTangent: function( t ) {
  19886. var delta = 0.0001;
  19887. var t1 = t - delta;
  19888. var t2 = t + delta;
  19889. // Capping in case of danger
  19890. if ( t1 < 0 ) t1 = 0;
  19891. if ( t2 > 1 ) t2 = 1;
  19892. var pt1 = this.getPoint( t1 );
  19893. var pt2 = this.getPoint( t2 );
  19894. var vec = pt2.clone().sub( pt1 );
  19895. return vec.normalize();
  19896. },
  19897. getTangentAt: function ( u ) {
  19898. var t = this.getUtoTmapping( u );
  19899. return this.getTangent( t );
  19900. }
  19901. }
  19902. THREE.Curve.Utils = THREE.CurveUtils; // backwards compatibility
  19903. // TODO: Transformation for Curves?
  19904. /**************************************************************
  19905. * 3D Curves
  19906. **************************************************************/
  19907. // A Factory method for creating new curve subclasses
  19908. THREE.Curve.create = function ( constructor, getPointFunc ) {
  19909. constructor.prototype = Object.create( THREE.Curve.prototype );
  19910. constructor.prototype.constructor = constructor;
  19911. constructor.prototype.getPoint = getPointFunc;
  19912. return constructor;
  19913. };
  19914. // File:src/extras/core/CurvePath.js
  19915. /**
  19916. * @author zz85 / http://www.lab4games.net/zz85/blog
  19917. *
  19918. **/
  19919. /**************************************************************
  19920. * Curved Path - a curve path is simply a array of connected
  19921. * curves, but retains the api of a curve
  19922. **************************************************************/
  19923. THREE.CurvePath = function () {
  19924. this.curves = [];
  19925. this.autoClose = false; // Automatically closes the path
  19926. };
  19927. THREE.CurvePath.prototype = Object.create( THREE.Curve.prototype );
  19928. THREE.CurvePath.prototype.constructor = THREE.CurvePath;
  19929. THREE.CurvePath.prototype.add = function ( curve ) {
  19930. this.curves.push( curve );
  19931. };
  19932. /*
  19933. THREE.CurvePath.prototype.checkConnection = function() {
  19934. // TODO
  19935. // If the ending of curve is not connected to the starting
  19936. // or the next curve, then, this is not a real path
  19937. };
  19938. */
  19939. THREE.CurvePath.prototype.closePath = function() {
  19940. // TODO Test
  19941. // and verify for vector3 (needs to implement equals)
  19942. // Add a line curve if start and end of lines are not connected
  19943. var startPoint = this.curves[ 0 ].getPoint( 0 );
  19944. var endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
  19945. if ( ! startPoint.equals( endPoint ) ) {
  19946. this.curves.push( new THREE.LineCurve( endPoint, startPoint ) );
  19947. }
  19948. };
  19949. // To get accurate point with reference to
  19950. // entire path distance at time t,
  19951. // following has to be done:
  19952. // 1. Length of each sub path have to be known
  19953. // 2. Locate and identify type of curve
  19954. // 3. Get t for the curve
  19955. // 4. Return curve.getPointAt(t')
  19956. THREE.CurvePath.prototype.getPoint = function( t ) {
  19957. var d = t * this.getLength();
  19958. var curveLengths = this.getCurveLengths();
  19959. var i = 0;
  19960. // To think about boundaries points.
  19961. while ( i < curveLengths.length ) {
  19962. if ( curveLengths[ i ] >= d ) {
  19963. var diff = curveLengths[ i ] - d;
  19964. var curve = this.curves[ i ];
  19965. var u = 1 - diff / curve.getLength();
  19966. return curve.getPointAt( u );
  19967. }
  19968. i ++;
  19969. }
  19970. return null;
  19971. // loop where sum != 0, sum > d , sum+1 <d
  19972. };
  19973. /*
  19974. THREE.CurvePath.prototype.getTangent = function( t ) {
  19975. };
  19976. */
  19977. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  19978. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  19979. // getPoint() depends on getLength
  19980. THREE.CurvePath.prototype.getLength = function() {
  19981. var lens = this.getCurveLengths();
  19982. return lens[ lens.length - 1 ];
  19983. };
  19984. // Compute lengths and cache them
  19985. // We cannot overwrite getLengths() because UtoT mapping uses it.
  19986. THREE.CurvePath.prototype.getCurveLengths = function() {
  19987. // We use cache values if curves and cache array are same length
  19988. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  19989. return this.cacheLengths;
  19990. }
  19991. // Get length of sub-curve
  19992. // Push sums into cached array
  19993. var lengths = [], sums = 0;
  19994. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  19995. sums += this.curves[ i ].getLength();
  19996. lengths.push( sums );
  19997. }
  19998. this.cacheLengths = lengths;
  19999. return lengths;
  20000. };
  20001. /**************************************************************
  20002. * Create Geometries Helpers
  20003. **************************************************************/
  20004. /// Generate geometry from path points (for Line or Points objects)
  20005. THREE.CurvePath.prototype.createPointsGeometry = function( divisions ) {
  20006. var pts = this.getPoints( divisions, true );
  20007. return this.createGeometry( pts );
  20008. };
  20009. // Generate geometry from equidistant sampling along the path
  20010. THREE.CurvePath.prototype.createSpacedPointsGeometry = function( divisions ) {
  20011. var pts = this.getSpacedPoints( divisions, true );
  20012. return this.createGeometry( pts );
  20013. };
  20014. THREE.CurvePath.prototype.createGeometry = function( points ) {
  20015. var geometry = new THREE.Geometry();
  20016. for ( var i = 0, l = points.length; i < l; i ++ ) {
  20017. var point = points[ i ];
  20018. geometry.vertices.push( new THREE.Vector3( point.x, point.y, point.z || 0 ) );
  20019. }
  20020. return geometry;
  20021. };
  20022. // File:src/extras/core/Path.js
  20023. /**
  20024. * @author zz85 / http://www.lab4games.net/zz85/blog
  20025. * Creates free form 2d path using series of points, lines or curves.
  20026. *
  20027. **/
  20028. THREE.Path = function ( points ) {
  20029. THREE.CurvePath.call( this );
  20030. this.actions = [];
  20031. if ( points ) {
  20032. this.fromPoints( points );
  20033. }
  20034. };
  20035. THREE.Path.prototype = Object.create( THREE.CurvePath.prototype );
  20036. THREE.Path.prototype.constructor = THREE.Path;
  20037. // TODO Clean up PATH API
  20038. // Create path using straight lines to connect all points
  20039. // - vectors: array of Vector2
  20040. THREE.Path.prototype.fromPoints = function ( vectors ) {
  20041. this.moveTo( vectors[ 0 ].x, vectors[ 0 ].y );
  20042. for ( var i = 1, l = vectors.length; i < l; i ++ ) {
  20043. this.lineTo( vectors[ i ].x, vectors[ i ].y );
  20044. }
  20045. };
  20046. // startPath() endPath()?
  20047. THREE.Path.prototype.moveTo = function ( x, y ) {
  20048. this.actions.push( { action: 'moveTo', args: [ x, y ] } );
  20049. };
  20050. THREE.Path.prototype.lineTo = function ( x, y ) {
  20051. var lastargs = this.actions[ this.actions.length - 1 ].args;
  20052. var x0 = lastargs[ lastargs.length - 2 ];
  20053. var y0 = lastargs[ lastargs.length - 1 ];
  20054. var curve = new THREE.LineCurve( new THREE.Vector2( x0, y0 ), new THREE.Vector2( x, y ) );
  20055. this.curves.push( curve );
  20056. this.actions.push( { action: 'lineTo', args: [ x, y ] } );
  20057. };
  20058. THREE.Path.prototype.quadraticCurveTo = function( aCPx, aCPy, aX, aY ) {
  20059. var lastargs = this.actions[ this.actions.length - 1 ].args;
  20060. var x0 = lastargs[ lastargs.length - 2 ];
  20061. var y0 = lastargs[ lastargs.length - 1 ];
  20062. var curve = new THREE.QuadraticBezierCurve(
  20063. new THREE.Vector2( x0, y0 ),
  20064. new THREE.Vector2( aCPx, aCPy ),
  20065. new THREE.Vector2( aX, aY )
  20066. );
  20067. this.curves.push( curve );
  20068. this.actions.push( { action: 'quadraticCurveTo', args: [ aCPx, aCPy, aX, aY ] } );
  20069. };
  20070. THREE.Path.prototype.bezierCurveTo = function( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  20071. var lastargs = this.actions[ this.actions.length - 1 ].args;
  20072. var x0 = lastargs[ lastargs.length - 2 ];
  20073. var y0 = lastargs[ lastargs.length - 1 ];
  20074. var curve = new THREE.CubicBezierCurve(
  20075. new THREE.Vector2( x0, y0 ),
  20076. new THREE.Vector2( aCP1x, aCP1y ),
  20077. new THREE.Vector2( aCP2x, aCP2y ),
  20078. new THREE.Vector2( aX, aY )
  20079. );
  20080. this.curves.push( curve );
  20081. this.actions.push( { action: 'bezierCurveTo', args: [ aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ] } );
  20082. };
  20083. THREE.Path.prototype.splineThru = function( pts /*Array of Vector*/ ) {
  20084. var args = Array.prototype.slice.call( arguments );
  20085. var lastargs = this.actions[ this.actions.length - 1 ].args;
  20086. var x0 = lastargs[ lastargs.length - 2 ];
  20087. var y0 = lastargs[ lastargs.length - 1 ];
  20088. var npts = [ new THREE.Vector2( x0, y0 ) ];
  20089. Array.prototype.push.apply( npts, pts );
  20090. var curve = new THREE.SplineCurve( npts );
  20091. this.curves.push( curve );
  20092. this.actions.push( { action: 'splineThru', args: args } );
  20093. };
  20094. // FUTURE: Change the API or follow canvas API?
  20095. THREE.Path.prototype.arc = function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  20096. var lastargs = this.actions[ this.actions.length - 1 ].args;
  20097. var x0 = lastargs[ lastargs.length - 2 ];
  20098. var y0 = lastargs[ lastargs.length - 1 ];
  20099. this.absarc( aX + x0, aY + y0, aRadius,
  20100. aStartAngle, aEndAngle, aClockwise );
  20101. };
  20102. THREE.Path.prototype.absarc = function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  20103. this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  20104. };
  20105. THREE.Path.prototype.ellipse = function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  20106. var lastargs = this.actions[ this.actions.length - 1 ].args;
  20107. var x0 = lastargs[ lastargs.length - 2 ];
  20108. var y0 = lastargs[ lastargs.length - 1 ];
  20109. this.absellipse( aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  20110. };
  20111. THREE.Path.prototype.absellipse = function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  20112. var args = [
  20113. aX, aY,
  20114. xRadius, yRadius,
  20115. aStartAngle, aEndAngle,
  20116. aClockwise,
  20117. aRotation || 0 // aRotation is optional.
  20118. ];
  20119. var curve = new THREE.EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  20120. this.curves.push( curve );
  20121. var lastPoint = curve.getPoint( 1 );
  20122. args.push( lastPoint.x );
  20123. args.push( lastPoint.y );
  20124. this.actions.push( { action: 'ellipse', args: args } );
  20125. };
  20126. THREE.Path.prototype.getSpacedPoints = function ( divisions, closedPath ) {
  20127. if ( ! divisions ) divisions = 40;
  20128. var points = [];
  20129. for ( var i = 0; i < divisions; i ++ ) {
  20130. points.push( this.getPoint( i / divisions ) );
  20131. //if ( !this.getPoint( i / divisions ) ) throw "DIE";
  20132. }
  20133. // if ( closedPath ) {
  20134. //
  20135. // points.push( points[ 0 ] );
  20136. //
  20137. // }
  20138. return points;
  20139. };
  20140. /* Return an array of vectors based on contour of the path */
  20141. THREE.Path.prototype.getPoints = function( divisions, closedPath ) {
  20142. divisions = divisions || 12;
  20143. var b2 = THREE.ShapeUtils.b2;
  20144. var b3 = THREE.ShapeUtils.b3;
  20145. var points = [];
  20146. var cpx, cpy, cpx2, cpy2, cpx1, cpy1, cpx0, cpy0,
  20147. laste, tx, ty;
  20148. for ( var i = 0, l = this.actions.length; i < l; i ++ ) {
  20149. var item = this.actions[ i ];
  20150. var action = item.action;
  20151. var args = item.args;
  20152. switch ( action ) {
  20153. case 'moveTo':
  20154. points.push( new THREE.Vector2( args[ 0 ], args[ 1 ] ) );
  20155. break;
  20156. case 'lineTo':
  20157. points.push( new THREE.Vector2( args[ 0 ], args[ 1 ] ) );
  20158. break;
  20159. case 'quadraticCurveTo':
  20160. cpx = args[ 2 ];
  20161. cpy = args[ 3 ];
  20162. cpx1 = args[ 0 ];
  20163. cpy1 = args[ 1 ];
  20164. if ( points.length > 0 ) {
  20165. laste = points[ points.length - 1 ];
  20166. cpx0 = laste.x;
  20167. cpy0 = laste.y;
  20168. } else {
  20169. laste = this.actions[ i - 1 ].args;
  20170. cpx0 = laste[ laste.length - 2 ];
  20171. cpy0 = laste[ laste.length - 1 ];
  20172. }
  20173. for ( var j = 1; j <= divisions; j ++ ) {
  20174. var t = j / divisions;
  20175. tx = b2( t, cpx0, cpx1, cpx );
  20176. ty = b2( t, cpy0, cpy1, cpy );
  20177. points.push( new THREE.Vector2( tx, ty ) );
  20178. }
  20179. break;
  20180. case 'bezierCurveTo':
  20181. cpx = args[ 4 ];
  20182. cpy = args[ 5 ];
  20183. cpx1 = args[ 0 ];
  20184. cpy1 = args[ 1 ];
  20185. cpx2 = args[ 2 ];
  20186. cpy2 = args[ 3 ];
  20187. if ( points.length > 0 ) {
  20188. laste = points[ points.length - 1 ];
  20189. cpx0 = laste.x;
  20190. cpy0 = laste.y;
  20191. } else {
  20192. laste = this.actions[ i - 1 ].args;
  20193. cpx0 = laste[ laste.length - 2 ];
  20194. cpy0 = laste[ laste.length - 1 ];
  20195. }
  20196. for ( var j = 1; j <= divisions; j ++ ) {
  20197. var t = j / divisions;
  20198. tx = b3( t, cpx0, cpx1, cpx2, cpx );
  20199. ty = b3( t, cpy0, cpy1, cpy2, cpy );
  20200. points.push( new THREE.Vector2( tx, ty ) );
  20201. }
  20202. break;
  20203. case 'splineThru':
  20204. laste = this.actions[ i - 1 ].args;
  20205. var last = new THREE.Vector2( laste[ laste.length - 2 ], laste[ laste.length - 1 ] );
  20206. var spts = [ last ];
  20207. var n = divisions * args[ 0 ].length;
  20208. spts = spts.concat( args[ 0 ] );
  20209. var spline = new THREE.SplineCurve( spts );
  20210. for ( var j = 1; j <= n; j ++ ) {
  20211. points.push( spline.getPointAt( j / n ) );
  20212. }
  20213. break;
  20214. case 'arc':
  20215. var aX = args[ 0 ], aY = args[ 1 ],
  20216. aRadius = args[ 2 ],
  20217. aStartAngle = args[ 3 ], aEndAngle = args[ 4 ],
  20218. aClockwise = !! args[ 5 ];
  20219. var deltaAngle = aEndAngle - aStartAngle;
  20220. var angle;
  20221. var tdivisions = divisions * 2;
  20222. for ( var j = 1; j <= tdivisions; j ++ ) {
  20223. var t = j / tdivisions;
  20224. if ( ! aClockwise ) {
  20225. t = 1 - t;
  20226. }
  20227. angle = aStartAngle + t * deltaAngle;
  20228. tx = aX + aRadius * Math.cos( angle );
  20229. ty = aY + aRadius * Math.sin( angle );
  20230. //console.log('t', t, 'angle', angle, 'tx', tx, 'ty', ty);
  20231. points.push( new THREE.Vector2( tx, ty ) );
  20232. }
  20233. //console.log(points);
  20234. break;
  20235. case 'ellipse':
  20236. var aX = args[ 0 ], aY = args[ 1 ],
  20237. xRadius = args[ 2 ],
  20238. yRadius = args[ 3 ],
  20239. aStartAngle = args[ 4 ], aEndAngle = args[ 5 ],
  20240. aClockwise = !! args[ 6 ],
  20241. aRotation = args[ 7 ];
  20242. var deltaAngle = aEndAngle - aStartAngle;
  20243. var angle;
  20244. var tdivisions = divisions * 2;
  20245. var cos, sin;
  20246. if ( aRotation !== 0 ) {
  20247. cos = Math.cos( aRotation );
  20248. sin = Math.sin( aRotation );
  20249. }
  20250. for ( var j = 1; j <= tdivisions; j ++ ) {
  20251. var t = j / tdivisions;
  20252. if ( ! aClockwise ) {
  20253. t = 1 - t;
  20254. }
  20255. angle = aStartAngle + t * deltaAngle;
  20256. tx = aX + xRadius * Math.cos( angle );
  20257. ty = aY + yRadius * Math.sin( angle );
  20258. if ( aRotation !== 0 ) {
  20259. var x = tx, y = ty;
  20260. // Rotate the point about the center of the ellipse.
  20261. tx = ( x - aX ) * cos - ( y - aY ) * sin + aX;
  20262. ty = ( x - aX ) * sin + ( y - aY ) * cos + aY;
  20263. }
  20264. //console.log('t', t, 'angle', angle, 'tx', tx, 'ty', ty);
  20265. points.push( new THREE.Vector2( tx, ty ) );
  20266. }
  20267. //console.log(points);
  20268. break;
  20269. } // end switch
  20270. }
  20271. // Normalize to remove the closing point by default.
  20272. var lastPoint = points[ points.length - 1 ];
  20273. if ( Math.abs( lastPoint.x - points[ 0 ].x ) < Number.EPSILON &&
  20274. Math.abs( lastPoint.y - points[ 0 ].y ) < Number.EPSILON )
  20275. points.splice( points.length - 1, 1 );
  20276. if ( closedPath ) {
  20277. points.push( points[ 0 ] );
  20278. }
  20279. return points;
  20280. };
  20281. //
  20282. // Breaks path into shapes
  20283. //
  20284. // Assumptions (if parameter isCCW==true the opposite holds):
  20285. // - solid shapes are defined clockwise (CW)
  20286. // - holes are defined counterclockwise (CCW)
  20287. //
  20288. // If parameter noHoles==true:
  20289. // - all subPaths are regarded as solid shapes
  20290. // - definition order CW/CCW has no relevance
  20291. //
  20292. THREE.Path.prototype.toShapes = function( isCCW, noHoles ) {
  20293. function extractSubpaths( inActions ) {
  20294. var subPaths = [], lastPath = new THREE.Path();
  20295. for ( var i = 0, l = inActions.length; i < l; i ++ ) {
  20296. var item = inActions[ i ];
  20297. var args = item.args;
  20298. var action = item.action;
  20299. if ( action === 'moveTo' ) {
  20300. if ( lastPath.actions.length !== 0 ) {
  20301. subPaths.push( lastPath );
  20302. lastPath = new THREE.Path();
  20303. }
  20304. }
  20305. lastPath[ action ].apply( lastPath, args );
  20306. }
  20307. if ( lastPath.actions.length !== 0 ) {
  20308. subPaths.push( lastPath );
  20309. }
  20310. // console.log(subPaths);
  20311. return subPaths;
  20312. }
  20313. function toShapesNoHoles( inSubpaths ) {
  20314. var shapes = [];
  20315. for ( var i = 0, l = inSubpaths.length; i < l; i ++ ) {
  20316. var tmpPath = inSubpaths[ i ];
  20317. var tmpShape = new THREE.Shape();
  20318. tmpShape.actions = tmpPath.actions;
  20319. tmpShape.curves = tmpPath.curves;
  20320. shapes.push( tmpShape );
  20321. }
  20322. //console.log("shape", shapes);
  20323. return shapes;
  20324. }
  20325. function isPointInsidePolygon( inPt, inPolygon ) {
  20326. var polyLen = inPolygon.length;
  20327. // inPt on polygon contour => immediate success or
  20328. // toggling of inside/outside at every single! intersection point of an edge
  20329. // with the horizontal line through inPt, left of inPt
  20330. // not counting lowerY endpoints of edges and whole edges on that line
  20331. var inside = false;
  20332. for ( var p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  20333. var edgeLowPt = inPolygon[ p ];
  20334. var edgeHighPt = inPolygon[ q ];
  20335. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  20336. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  20337. if ( Math.abs( edgeDy ) > Number.EPSILON ) {
  20338. // not parallel
  20339. if ( edgeDy < 0 ) {
  20340. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  20341. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  20342. }
  20343. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  20344. if ( inPt.y === edgeLowPt.y ) {
  20345. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  20346. // continue; // no intersection or edgeLowPt => doesn't count !!!
  20347. } else {
  20348. var perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y );
  20349. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  20350. if ( perpEdge < 0 ) continue;
  20351. inside = ! inside; // true intersection left of inPt
  20352. }
  20353. } else {
  20354. // parallel or collinear
  20355. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  20356. // edge lies on the same horizontal line as inPt
  20357. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  20358. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  20359. // continue;
  20360. }
  20361. }
  20362. return inside;
  20363. }
  20364. var isClockWise = THREE.ShapeUtils.isClockWise;
  20365. var subPaths = extractSubpaths( this.actions );
  20366. if ( subPaths.length === 0 ) return [];
  20367. if ( noHoles === true ) return toShapesNoHoles( subPaths );
  20368. var solid, tmpPath, tmpShape, shapes = [];
  20369. if ( subPaths.length === 1 ) {
  20370. tmpPath = subPaths[ 0 ];
  20371. tmpShape = new THREE.Shape();
  20372. tmpShape.actions = tmpPath.actions;
  20373. tmpShape.curves = tmpPath.curves;
  20374. shapes.push( tmpShape );
  20375. return shapes;
  20376. }
  20377. var holesFirst = ! isClockWise( subPaths[ 0 ].getPoints() );
  20378. holesFirst = isCCW ? ! holesFirst : holesFirst;
  20379. // console.log("Holes first", holesFirst);
  20380. var betterShapeHoles = [];
  20381. var newShapes = [];
  20382. var newShapeHoles = [];
  20383. var mainIdx = 0;
  20384. var tmpPoints;
  20385. newShapes[ mainIdx ] = undefined;
  20386. newShapeHoles[ mainIdx ] = [];
  20387. for ( var i = 0, l = subPaths.length; i < l; i ++ ) {
  20388. tmpPath = subPaths[ i ];
  20389. tmpPoints = tmpPath.getPoints();
  20390. solid = isClockWise( tmpPoints );
  20391. solid = isCCW ? ! solid : solid;
  20392. if ( solid ) {
  20393. if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) mainIdx ++;
  20394. newShapes[ mainIdx ] = { s: new THREE.Shape(), p: tmpPoints };
  20395. newShapes[ mainIdx ].s.actions = tmpPath.actions;
  20396. newShapes[ mainIdx ].s.curves = tmpPath.curves;
  20397. if ( holesFirst ) mainIdx ++;
  20398. newShapeHoles[ mainIdx ] = [];
  20399. //console.log('cw', i);
  20400. } else {
  20401. newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } );
  20402. //console.log('ccw', i);
  20403. }
  20404. }
  20405. // only Holes? -> probably all Shapes with wrong orientation
  20406. if ( ! newShapes[ 0 ] ) return toShapesNoHoles( subPaths );
  20407. if ( newShapes.length > 1 ) {
  20408. var ambiguous = false;
  20409. var toChange = [];
  20410. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  20411. betterShapeHoles[ sIdx ] = [];
  20412. }
  20413. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  20414. var sho = newShapeHoles[ sIdx ];
  20415. for ( var hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  20416. var ho = sho[ hIdx ];
  20417. var hole_unassigned = true;
  20418. for ( var s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  20419. if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
  20420. if ( sIdx !== s2Idx ) toChange.push( { froms: sIdx, tos: s2Idx, hole: hIdx } );
  20421. if ( hole_unassigned ) {
  20422. hole_unassigned = false;
  20423. betterShapeHoles[ s2Idx ].push( ho );
  20424. } else {
  20425. ambiguous = true;
  20426. }
  20427. }
  20428. }
  20429. if ( hole_unassigned ) {
  20430. betterShapeHoles[ sIdx ].push( ho );
  20431. }
  20432. }
  20433. }
  20434. // console.log("ambiguous: ", ambiguous);
  20435. if ( toChange.length > 0 ) {
  20436. // console.log("to change: ", toChange);
  20437. if ( ! ambiguous ) newShapeHoles = betterShapeHoles;
  20438. }
  20439. }
  20440. var tmpHoles;
  20441. for ( var i = 0, il = newShapes.length; i < il; i ++ ) {
  20442. tmpShape = newShapes[ i ].s;
  20443. shapes.push( tmpShape );
  20444. tmpHoles = newShapeHoles[ i ];
  20445. for ( var j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  20446. tmpShape.holes.push( tmpHoles[ j ].h );
  20447. }
  20448. }
  20449. //console.log("shape", shapes);
  20450. return shapes;
  20451. };
  20452. // File:src/extras/core/Shape.js
  20453. /**
  20454. * @author zz85 / http://www.lab4games.net/zz85/blog
  20455. * Defines a 2d shape plane using paths.
  20456. **/
  20457. // STEP 1 Create a path.
  20458. // STEP 2 Turn path into shape.
  20459. // STEP 3 ExtrudeGeometry takes in Shape/Shapes
  20460. // STEP 3a - Extract points from each shape, turn to vertices
  20461. // STEP 3b - Triangulate each shape, add faces.
  20462. THREE.Shape = function () {
  20463. THREE.Path.apply( this, arguments );
  20464. this.holes = [];
  20465. };
  20466. THREE.Shape.prototype = Object.create( THREE.Path.prototype );
  20467. THREE.Shape.prototype.constructor = THREE.Shape;
  20468. // Convenience method to return ExtrudeGeometry
  20469. THREE.Shape.prototype.extrude = function ( options ) {
  20470. return new THREE.ExtrudeGeometry( this, options );
  20471. };
  20472. // Convenience method to return ShapeGeometry
  20473. THREE.Shape.prototype.makeGeometry = function ( options ) {
  20474. return new THREE.ShapeGeometry( this, options );
  20475. };
  20476. // Get points of holes
  20477. THREE.Shape.prototype.getPointsHoles = function ( divisions ) {
  20478. var holesPts = [];
  20479. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  20480. holesPts[ i ] = this.holes[ i ].getPoints( divisions );
  20481. }
  20482. return holesPts;
  20483. };
  20484. // Get points of shape and holes (keypoints based on segments parameter)
  20485. THREE.Shape.prototype.extractAllPoints = function ( divisions ) {
  20486. return {
  20487. shape: this.getPoints( divisions ),
  20488. holes: this.getPointsHoles( divisions )
  20489. };
  20490. };
  20491. THREE.Shape.prototype.extractPoints = function ( divisions ) {
  20492. return this.extractAllPoints( divisions );
  20493. };
  20494. THREE.Shape.Utils = THREE.ShapeUtils; // backwards compatibility
  20495. // File:src/extras/curves/LineCurve.js
  20496. /**************************************************************
  20497. * Line
  20498. **************************************************************/
  20499. THREE.LineCurve = function ( v1, v2 ) {
  20500. this.v1 = v1;
  20501. this.v2 = v2;
  20502. };
  20503. THREE.LineCurve.prototype = Object.create( THREE.Curve.prototype );
  20504. THREE.LineCurve.prototype.constructor = THREE.LineCurve;
  20505. THREE.LineCurve.prototype.getPoint = function ( t ) {
  20506. var point = this.v2.clone().sub( this.v1 );
  20507. point.multiplyScalar( t ).add( this.v1 );
  20508. return point;
  20509. };
  20510. // Line curve is linear, so we can overwrite default getPointAt
  20511. THREE.LineCurve.prototype.getPointAt = function ( u ) {
  20512. return this.getPoint( u );
  20513. };
  20514. THREE.LineCurve.prototype.getTangent = function( t ) {
  20515. var tangent = this.v2.clone().sub( this.v1 );
  20516. return tangent.normalize();
  20517. };
  20518. // File:src/extras/curves/QuadraticBezierCurve.js
  20519. /**************************************************************
  20520. * Quadratic Bezier curve
  20521. **************************************************************/
  20522. THREE.QuadraticBezierCurve = function ( v0, v1, v2 ) {
  20523. this.v0 = v0;
  20524. this.v1 = v1;
  20525. this.v2 = v2;
  20526. };
  20527. THREE.QuadraticBezierCurve.prototype = Object.create( THREE.Curve.prototype );
  20528. THREE.QuadraticBezierCurve.prototype.constructor = THREE.QuadraticBezierCurve;
  20529. THREE.QuadraticBezierCurve.prototype.getPoint = function ( t ) {
  20530. var b2 = THREE.ShapeUtils.b2;
  20531. return new THREE.Vector2(
  20532. b2( t, this.v0.x, this.v1.x, this.v2.x ),
  20533. b2( t, this.v0.y, this.v1.y, this.v2.y )
  20534. );
  20535. };
  20536. THREE.QuadraticBezierCurve.prototype.getTangent = function( t ) {
  20537. var tangentQuadraticBezier = THREE.CurveUtils.tangentQuadraticBezier;
  20538. return new THREE.Vector2(
  20539. tangentQuadraticBezier( t, this.v0.x, this.v1.x, this.v2.x ),
  20540. tangentQuadraticBezier( t, this.v0.y, this.v1.y, this.v2.y )
  20541. ).normalize();
  20542. };
  20543. // File:src/extras/curves/CubicBezierCurve.js
  20544. /**************************************************************
  20545. * Cubic Bezier curve
  20546. **************************************************************/
  20547. THREE.CubicBezierCurve = function ( v0, v1, v2, v3 ) {
  20548. this.v0 = v0;
  20549. this.v1 = v1;
  20550. this.v2 = v2;
  20551. this.v3 = v3;
  20552. };
  20553. THREE.CubicBezierCurve.prototype = Object.create( THREE.Curve.prototype );
  20554. THREE.CubicBezierCurve.prototype.constructor = THREE.CubicBezierCurve;
  20555. THREE.CubicBezierCurve.prototype.getPoint = function ( t ) {
  20556. var b3 = THREE.ShapeUtils.b3;
  20557. return new THREE.Vector2(
  20558. b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x ),
  20559. b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y )
  20560. );
  20561. };
  20562. THREE.CubicBezierCurve.prototype.getTangent = function( t ) {
  20563. var tangentCubicBezier = THREE.CurveUtils.tangentCubicBezier;
  20564. return new THREE.Vector2(
  20565. tangentCubicBezier( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x ),
  20566. tangentCubicBezier( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y )
  20567. ).normalize();
  20568. };
  20569. // File:src/extras/curves/SplineCurve.js
  20570. /**************************************************************
  20571. * Spline curve
  20572. **************************************************************/
  20573. THREE.SplineCurve = function ( points /* array of Vector2 */ ) {
  20574. this.points = ( points == undefined ) ? [] : points;
  20575. };
  20576. THREE.SplineCurve.prototype = Object.create( THREE.Curve.prototype );
  20577. THREE.SplineCurve.prototype.constructor = THREE.SplineCurve;
  20578. THREE.SplineCurve.prototype.getPoint = function ( t ) {
  20579. var points = this.points;
  20580. var point = ( points.length - 1 ) * t;
  20581. var intPoint = Math.floor( point );
  20582. var weight = point - intPoint;
  20583. var point0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  20584. var point1 = points[ intPoint ];
  20585. var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  20586. var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  20587. var interpolate = THREE.CurveUtils.interpolate;
  20588. return new THREE.Vector2(
  20589. interpolate( point0.x, point1.x, point2.x, point3.x, weight ),
  20590. interpolate( point0.y, point1.y, point2.y, point3.y, weight )
  20591. );
  20592. };
  20593. // File:src/extras/curves/EllipseCurve.js
  20594. /**************************************************************
  20595. * Ellipse curve
  20596. **************************************************************/
  20597. THREE.EllipseCurve = function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  20598. this.aX = aX;
  20599. this.aY = aY;
  20600. this.xRadius = xRadius;
  20601. this.yRadius = yRadius;
  20602. this.aStartAngle = aStartAngle;
  20603. this.aEndAngle = aEndAngle;
  20604. this.aClockwise = aClockwise;
  20605. this.aRotation = aRotation || 0;
  20606. };
  20607. THREE.EllipseCurve.prototype = Object.create( THREE.Curve.prototype );
  20608. THREE.EllipseCurve.prototype.constructor = THREE.EllipseCurve;
  20609. THREE.EllipseCurve.prototype.getPoint = function ( t ) {
  20610. var deltaAngle = this.aEndAngle - this.aStartAngle;
  20611. if ( deltaAngle < 0 ) deltaAngle += Math.PI * 2;
  20612. if ( deltaAngle > Math.PI * 2 ) deltaAngle -= Math.PI * 2;
  20613. var angle;
  20614. if ( this.aClockwise === true ) {
  20615. angle = this.aEndAngle + ( 1 - t ) * ( Math.PI * 2 - deltaAngle );
  20616. } else {
  20617. angle = this.aStartAngle + t * deltaAngle;
  20618. }
  20619. var x = this.aX + this.xRadius * Math.cos( angle );
  20620. var y = this.aY + this.yRadius * Math.sin( angle );
  20621. if ( this.aRotation !== 0 ) {
  20622. var cos = Math.cos( this.aRotation );
  20623. var sin = Math.sin( this.aRotation );
  20624. var tx = x, ty = y;
  20625. // Rotate the point about the center of the ellipse.
  20626. x = ( tx - this.aX ) * cos - ( ty - this.aY ) * sin + this.aX;
  20627. y = ( tx - this.aX ) * sin + ( ty - this.aY ) * cos + this.aY;
  20628. }
  20629. return new THREE.Vector2( x, y );
  20630. };
  20631. // File:src/extras/curves/ArcCurve.js
  20632. /**************************************************************
  20633. * Arc curve
  20634. **************************************************************/
  20635. THREE.ArcCurve = function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  20636. THREE.EllipseCurve.call( this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  20637. };
  20638. THREE.ArcCurve.prototype = Object.create( THREE.EllipseCurve.prototype );
  20639. THREE.ArcCurve.prototype.constructor = THREE.ArcCurve;
  20640. // File:src/extras/curves/LineCurve3.js
  20641. /**************************************************************
  20642. * Line3D
  20643. **************************************************************/
  20644. THREE.LineCurve3 = THREE.Curve.create(
  20645. function ( v1, v2 ) {
  20646. this.v1 = v1;
  20647. this.v2 = v2;
  20648. },
  20649. function ( t ) {
  20650. var vector = new THREE.Vector3();
  20651. vector.subVectors( this.v2, this.v1 ); // diff
  20652. vector.multiplyScalar( t );
  20653. vector.add( this.v1 );
  20654. return vector;
  20655. }
  20656. );
  20657. // File:src/extras/curves/QuadraticBezierCurve3.js
  20658. /**************************************************************
  20659. * Quadratic Bezier 3D curve
  20660. **************************************************************/
  20661. THREE.QuadraticBezierCurve3 = THREE.Curve.create(
  20662. function ( v0, v1, v2 ) {
  20663. this.v0 = v0;
  20664. this.v1 = v1;
  20665. this.v2 = v2;
  20666. },
  20667. function ( t ) {
  20668. var b2 = THREE.ShapeUtils.b2;
  20669. return new THREE.Vector3(
  20670. b2( t, this.v0.x, this.v1.x, this.v2.x ),
  20671. b2( t, this.v0.y, this.v1.y, this.v2.y ),
  20672. b2( t, this.v0.z, this.v1.z, this.v2.z )
  20673. );
  20674. }
  20675. );
  20676. // File:src/extras/curves/CubicBezierCurve3.js
  20677. /**************************************************************
  20678. * Cubic Bezier 3D curve
  20679. **************************************************************/
  20680. THREE.CubicBezierCurve3 = THREE.Curve.create(
  20681. function ( v0, v1, v2, v3 ) {
  20682. this.v0 = v0;
  20683. this.v1 = v1;
  20684. this.v2 = v2;
  20685. this.v3 = v3;
  20686. },
  20687. function ( t ) {
  20688. var b3 = THREE.ShapeUtils.b3;
  20689. return new THREE.Vector3(
  20690. b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x ),
  20691. b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y ),
  20692. b3( t, this.v0.z, this.v1.z, this.v2.z, this.v3.z )
  20693. );
  20694. }
  20695. );
  20696. // File:src/extras/curves/SplineCurve3.js
  20697. /**************************************************************
  20698. * Spline 3D curve
  20699. **************************************************************/
  20700. THREE.SplineCurve3 = THREE.Curve.create(
  20701. function ( points /* array of Vector3 */ ) {
  20702. console.warn( 'THREE.SplineCurve3 will be deprecated. Please use THREE.CatmullRomCurve3' );
  20703. this.points = ( points == undefined ) ? [] : points;
  20704. },
  20705. function ( t ) {
  20706. var points = this.points;
  20707. var point = ( points.length - 1 ) * t;
  20708. var intPoint = Math.floor( point );
  20709. var weight = point - intPoint;
  20710. var point0 = points[ intPoint == 0 ? intPoint : intPoint - 1 ];
  20711. var point1 = points[ intPoint ];
  20712. var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  20713. var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  20714. var interpolate = THREE.CurveUtils.interpolate;
  20715. return new THREE.Vector3(
  20716. interpolate( point0.x, point1.x, point2.x, point3.x, weight ),
  20717. interpolate( point0.y, point1.y, point2.y, point3.y, weight ),
  20718. interpolate( point0.z, point1.z, point2.z, point3.z, weight )
  20719. );
  20720. }
  20721. );
  20722. // File:src/extras/curves/CatmullRomCurve3.js
  20723. /**
  20724. * @author zz85 https://github.com/zz85
  20725. *
  20726. * Centripetal CatmullRom Curve - which is useful for avoiding
  20727. * cusps and self-intersections in non-uniform catmull rom curves.
  20728. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  20729. *
  20730. * curve.type accepts centripetal(default), chordal and catmullrom
  20731. * curve.tension is used for catmullrom which defaults to 0.5
  20732. */
  20733. THREE.CatmullRomCurve3 = ( function() {
  20734. var
  20735. tmp = new THREE.Vector3(),
  20736. px = new CubicPoly(),
  20737. py = new CubicPoly(),
  20738. pz = new CubicPoly();
  20739. /*
  20740. Based on an optimized c++ solution in
  20741. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  20742. - http://ideone.com/NoEbVM
  20743. This CubicPoly class could be used for reusing some variables and calculations,
  20744. but for three.js curve use, it could be possible inlined and flatten into a single function call
  20745. which can be placed in CurveUtils.
  20746. */
  20747. function CubicPoly() {
  20748. }
  20749. /*
  20750. * Compute coefficients for a cubic polynomial
  20751. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  20752. * such that
  20753. * p(0) = x0, p(1) = x1
  20754. * and
  20755. * p'(0) = t0, p'(1) = t1.
  20756. */
  20757. CubicPoly.prototype.init = function( x0, x1, t0, t1 ) {
  20758. this.c0 = x0;
  20759. this.c1 = t0;
  20760. this.c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  20761. this.c3 = 2 * x0 - 2 * x1 + t0 + t1;
  20762. };
  20763. CubicPoly.prototype.initNonuniformCatmullRom = function( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  20764. // compute tangents when parameterized in [t1,t2]
  20765. var t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  20766. var t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  20767. // rescale tangents for parametrization in [0,1]
  20768. t1 *= dt1;
  20769. t2 *= dt1;
  20770. // initCubicPoly
  20771. this.init( x1, x2, t1, t2 );
  20772. };
  20773. // standard Catmull-Rom spline: interpolate between x1 and x2 with previous/following points x1/x4
  20774. CubicPoly.prototype.initCatmullRom = function( x0, x1, x2, x3, tension ) {
  20775. this.init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  20776. };
  20777. CubicPoly.prototype.calc = function( t ) {
  20778. var t2 = t * t;
  20779. var t3 = t2 * t;
  20780. return this.c0 + this.c1 * t + this.c2 * t2 + this.c3 * t3;
  20781. };
  20782. // Subclass Three.js curve
  20783. return THREE.Curve.create(
  20784. function ( p /* array of Vector3 */ ) {
  20785. this.points = p || [];
  20786. },
  20787. function ( t ) {
  20788. var points = this.points,
  20789. point, intPoint, weight, l;
  20790. l = points.length;
  20791. if ( l < 2 ) console.log( 'duh, you need at least 2 points' );
  20792. point = ( l - 1 ) * t;
  20793. intPoint = Math.floor( point );
  20794. weight = point - intPoint;
  20795. if ( weight === 0 && intPoint === l - 1 ) {
  20796. intPoint = l - 2;
  20797. weight = 1;
  20798. }
  20799. var p0, p1, p2, p3;
  20800. if ( intPoint === 0 ) {
  20801. // extrapolate first point
  20802. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  20803. p0 = tmp;
  20804. } else {
  20805. p0 = points[ intPoint - 1 ];
  20806. }
  20807. p1 = points[ intPoint ];
  20808. p2 = points[ intPoint + 1 ];
  20809. if ( intPoint + 2 < l ) {
  20810. p3 = points[ intPoint + 2 ]
  20811. } else {
  20812. // extrapolate last point
  20813. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 2 ] );
  20814. p3 = tmp;
  20815. }
  20816. if ( this.type === undefined || this.type === 'centripetal' || this.type === 'chordal' ) {
  20817. // init Centripetal / Chordal Catmull-Rom
  20818. var pow = this.type === 'chordal' ? 0.5 : 0.25;
  20819. var dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  20820. var dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  20821. var dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  20822. // safety check for repeated points
  20823. if ( dt1 < 1e-4 ) dt1 = 1.0;
  20824. if ( dt0 < 1e-4 ) dt0 = dt1;
  20825. if ( dt2 < 1e-4 ) dt2 = dt1;
  20826. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  20827. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  20828. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  20829. } else if ( this.type === 'catmullrom' ) {
  20830. var tension = this.tension !== undefined ? this.tension : 0.5;
  20831. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, tension );
  20832. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, tension );
  20833. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, tension );
  20834. }
  20835. var v = new THREE.Vector3(
  20836. px.calc( weight ),
  20837. py.calc( weight ),
  20838. pz.calc( weight )
  20839. );
  20840. return v;
  20841. }
  20842. );
  20843. } )();
  20844. // File:src/extras/curves/ClosedSplineCurve3.js
  20845. /**************************************************************
  20846. * Closed Spline 3D curve
  20847. **************************************************************/
  20848. THREE.ClosedSplineCurve3 = THREE.Curve.create(
  20849. function ( points /* array of Vector3 */ ) {
  20850. this.points = ( points == undefined ) ? [] : points;
  20851. },
  20852. function ( t ) {
  20853. var points = this.points;
  20854. var point = ( points.length - 0 ) * t; // This needs to be from 0-length +1
  20855. var intPoint = Math.floor( point );
  20856. var weight = point - intPoint;
  20857. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / points.length ) + 1 ) * points.length;
  20858. var point0 = points[ ( intPoint - 1 ) % points.length ];
  20859. var point1 = points[ ( intPoint ) % points.length ];
  20860. var point2 = points[ ( intPoint + 1 ) % points.length ];
  20861. var point3 = points[ ( intPoint + 2 ) % points.length ];
  20862. var interpolate = THREE.CurveUtils.interpolate;
  20863. return new THREE.Vector3(
  20864. interpolate( point0.x, point1.x, point2.x, point3.x, weight ),
  20865. interpolate( point0.y, point1.y, point2.y, point3.y, weight ),
  20866. interpolate( point0.z, point1.z, point2.z, point3.z, weight )
  20867. );
  20868. }
  20869. );
  20870. // File:src/extras/geometries/BoxGeometry.js
  20871. /**
  20872. * @author mrdoob / http://mrdoob.com/
  20873. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Cube.as
  20874. */
  20875. THREE.BoxGeometry = function ( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  20876. THREE.Geometry.call( this );
  20877. this.type = 'BoxGeometry';
  20878. this.parameters = {
  20879. width: width,
  20880. height: height,
  20881. depth: depth,
  20882. widthSegments: widthSegments,
  20883. heightSegments: heightSegments,
  20884. depthSegments: depthSegments
  20885. };
  20886. this.widthSegments = widthSegments || 1;
  20887. this.heightSegments = heightSegments || 1;
  20888. this.depthSegments = depthSegments || 1;
  20889. var scope = this;
  20890. var width_half = width / 2;
  20891. var height_half = height / 2;
  20892. var depth_half = depth / 2;
  20893. buildPlane( 'z', 'y', - 1, - 1, depth, height, width_half, 0 ); // px
  20894. buildPlane( 'z', 'y', 1, - 1, depth, height, - width_half, 1 ); // nx
  20895. buildPlane( 'x', 'z', 1, 1, width, depth, height_half, 2 ); // py
  20896. buildPlane( 'x', 'z', 1, - 1, width, depth, - height_half, 3 ); // ny
  20897. buildPlane( 'x', 'y', 1, - 1, width, height, depth_half, 4 ); // pz
  20898. buildPlane( 'x', 'y', - 1, - 1, width, height, - depth_half, 5 ); // nz
  20899. function buildPlane( u, v, udir, vdir, width, height, depth, materialIndex ) {
  20900. var w, ix, iy,
  20901. gridX = scope.widthSegments,
  20902. gridY = scope.heightSegments,
  20903. width_half = width / 2,
  20904. height_half = height / 2,
  20905. offset = scope.vertices.length;
  20906. if ( ( u === 'x' && v === 'y' ) || ( u === 'y' && v === 'x' ) ) {
  20907. w = 'z';
  20908. } else if ( ( u === 'x' && v === 'z' ) || ( u === 'z' && v === 'x' ) ) {
  20909. w = 'y';
  20910. gridY = scope.depthSegments;
  20911. } else if ( ( u === 'z' && v === 'y' ) || ( u === 'y' && v === 'z' ) ) {
  20912. w = 'x';
  20913. gridX = scope.depthSegments;
  20914. }
  20915. var gridX1 = gridX + 1,
  20916. gridY1 = gridY + 1,
  20917. segment_width = width / gridX,
  20918. segment_height = height / gridY,
  20919. normal = new THREE.Vector3();
  20920. normal[ w ] = depth > 0 ? 1 : - 1;
  20921. for ( iy = 0; iy < gridY1; iy ++ ) {
  20922. for ( ix = 0; ix < gridX1; ix ++ ) {
  20923. var vector = new THREE.Vector3();
  20924. vector[ u ] = ( ix * segment_width - width_half ) * udir;
  20925. vector[ v ] = ( iy * segment_height - height_half ) * vdir;
  20926. vector[ w ] = depth;
  20927. scope.vertices.push( vector );
  20928. }
  20929. }
  20930. for ( iy = 0; iy < gridY; iy ++ ) {
  20931. for ( ix = 0; ix < gridX; ix ++ ) {
  20932. var a = ix + gridX1 * iy;
  20933. var b = ix + gridX1 * ( iy + 1 );
  20934. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  20935. var d = ( ix + 1 ) + gridX1 * iy;
  20936. var uva = new THREE.Vector2( ix / gridX, 1 - iy / gridY );
  20937. var uvb = new THREE.Vector2( ix / gridX, 1 - ( iy + 1 ) / gridY );
  20938. var uvc = new THREE.Vector2( ( ix + 1 ) / gridX, 1 - ( iy + 1 ) / gridY );
  20939. var uvd = new THREE.Vector2( ( ix + 1 ) / gridX, 1 - iy / gridY );
  20940. var face = new THREE.Face3( a + offset, b + offset, d + offset );
  20941. face.normal.copy( normal );
  20942. face.vertexNormals.push( normal.clone(), normal.clone(), normal.clone() );
  20943. face.materialIndex = materialIndex;
  20944. scope.faces.push( face );
  20945. scope.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  20946. face = new THREE.Face3( b + offset, c + offset, d + offset );
  20947. face.normal.copy( normal );
  20948. face.vertexNormals.push( normal.clone(), normal.clone(), normal.clone() );
  20949. face.materialIndex = materialIndex;
  20950. scope.faces.push( face );
  20951. scope.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  20952. }
  20953. }
  20954. }
  20955. this.mergeVertices();
  20956. };
  20957. THREE.BoxGeometry.prototype = Object.create( THREE.Geometry.prototype );
  20958. THREE.BoxGeometry.prototype.constructor = THREE.BoxGeometry;
  20959. THREE.CubeGeometry = THREE.BoxGeometry; // backwards compatibility
  20960. // File:src/extras/geometries/CircleGeometry.js
  20961. /**
  20962. * @author hughes
  20963. */
  20964. THREE.CircleGeometry = function ( radius, segments, thetaStart, thetaLength ) {
  20965. THREE.Geometry.call( this );
  20966. this.type = 'CircleGeometry';
  20967. this.parameters = {
  20968. radius: radius,
  20969. segments: segments,
  20970. thetaStart: thetaStart,
  20971. thetaLength: thetaLength
  20972. };
  20973. this.fromBufferGeometry( new THREE.CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) );
  20974. };
  20975. THREE.CircleGeometry.prototype = Object.create( THREE.Geometry.prototype );
  20976. THREE.CircleGeometry.prototype.constructor = THREE.CircleGeometry;
  20977. // File:src/extras/geometries/CircleBufferGeometry.js
  20978. /**
  20979. * @author benaadams / https://twitter.com/ben_a_adams
  20980. */
  20981. THREE.CircleBufferGeometry = function ( radius, segments, thetaStart, thetaLength ) {
  20982. THREE.BufferGeometry.call( this );
  20983. this.type = 'CircleBufferGeometry';
  20984. this.parameters = {
  20985. radius: radius,
  20986. segments: segments,
  20987. thetaStart: thetaStart,
  20988. thetaLength: thetaLength
  20989. };
  20990. radius = radius || 50;
  20991. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  20992. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  20993. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  20994. var vertices = segments + 2;
  20995. var positions = new Float32Array( vertices * 3 );
  20996. var normals = new Float32Array( vertices * 3 );
  20997. var uvs = new Float32Array( vertices * 2 );
  20998. // center data is already zero, but need to set a few extras
  20999. normals[ 2 ] = 1.0;
  21000. uvs[ 0 ] = 0.5;
  21001. uvs[ 1 ] = 0.5;
  21002. for ( var s = 0, i = 3, ii = 2 ; s <= segments; s ++, i += 3, ii += 2 ) {
  21003. var segment = thetaStart + s / segments * thetaLength;
  21004. positions[ i ] = radius * Math.cos( segment );
  21005. positions[ i + 1 ] = radius * Math.sin( segment );
  21006. normals[ i + 2 ] = 1; // normal z
  21007. uvs[ ii ] = ( positions[ i ] / radius + 1 ) / 2;
  21008. uvs[ ii + 1 ] = ( positions[ i + 1 ] / radius + 1 ) / 2;
  21009. }
  21010. var indices = [];
  21011. for ( var i = 1; i <= segments; i ++ ) {
  21012. indices.push( i, i + 1, 0 );
  21013. }
  21014. this.setIndex( new THREE.BufferAttribute( new Uint16Array( indices ), 1 ) );
  21015. this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
  21016. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  21017. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  21018. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  21019. };
  21020. THREE.CircleBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  21021. THREE.CircleBufferGeometry.prototype.constructor = THREE.CircleBufferGeometry;
  21022. // File:src/extras/geometries/CylinderGeometry.js
  21023. /**
  21024. * @author mrdoob / http://mrdoob.com/
  21025. */
  21026. THREE.CylinderGeometry = function ( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  21027. THREE.Geometry.call( this );
  21028. this.type = 'CylinderGeometry';
  21029. this.parameters = {
  21030. radiusTop: radiusTop,
  21031. radiusBottom: radiusBottom,
  21032. height: height,
  21033. radialSegments: radialSegments,
  21034. heightSegments: heightSegments,
  21035. openEnded: openEnded,
  21036. thetaStart: thetaStart,
  21037. thetaLength: thetaLength
  21038. };
  21039. radiusTop = radiusTop !== undefined ? radiusTop : 20;
  21040. radiusBottom = radiusBottom !== undefined ? radiusBottom : 20;
  21041. height = height !== undefined ? height : 100;
  21042. radialSegments = radialSegments || 8;
  21043. heightSegments = heightSegments || 1;
  21044. openEnded = openEnded !== undefined ? openEnded : false;
  21045. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  21046. thetaLength = thetaLength !== undefined ? thetaLength : 2 * Math.PI;
  21047. var heightHalf = height / 2;
  21048. var x, y, vertices = [], uvs = [];
  21049. for ( y = 0; y <= heightSegments; y ++ ) {
  21050. var verticesRow = [];
  21051. var uvsRow = [];
  21052. var v = y / heightSegments;
  21053. var radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  21054. for ( x = 0; x <= radialSegments; x ++ ) {
  21055. var u = x / radialSegments;
  21056. var vertex = new THREE.Vector3();
  21057. vertex.x = radius * Math.sin( u * thetaLength + thetaStart );
  21058. vertex.y = - v * height + heightHalf;
  21059. vertex.z = radius * Math.cos( u * thetaLength + thetaStart );
  21060. this.vertices.push( vertex );
  21061. verticesRow.push( this.vertices.length - 1 );
  21062. uvsRow.push( new THREE.Vector2( u, 1 - v ) );
  21063. }
  21064. vertices.push( verticesRow );
  21065. uvs.push( uvsRow );
  21066. }
  21067. var tanTheta = ( radiusBottom - radiusTop ) / height;
  21068. var na, nb;
  21069. for ( x = 0; x < radialSegments; x ++ ) {
  21070. if ( radiusTop !== 0 ) {
  21071. na = this.vertices[ vertices[ 0 ][ x ] ].clone();
  21072. nb = this.vertices[ vertices[ 0 ][ x + 1 ] ].clone();
  21073. } else {
  21074. na = this.vertices[ vertices[ 1 ][ x ] ].clone();
  21075. nb = this.vertices[ vertices[ 1 ][ x + 1 ] ].clone();
  21076. }
  21077. na.setY( Math.sqrt( na.x * na.x + na.z * na.z ) * tanTheta ).normalize();
  21078. nb.setY( Math.sqrt( nb.x * nb.x + nb.z * nb.z ) * tanTheta ).normalize();
  21079. for ( y = 0; y < heightSegments; y ++ ) {
  21080. var v1 = vertices[ y ][ x ];
  21081. var v2 = vertices[ y + 1 ][ x ];
  21082. var v3 = vertices[ y + 1 ][ x + 1 ];
  21083. var v4 = vertices[ y ][ x + 1 ];
  21084. var n1 = na.clone();
  21085. var n2 = na.clone();
  21086. var n3 = nb.clone();
  21087. var n4 = nb.clone();
  21088. var uv1 = uvs[ y ][ x ].clone();
  21089. var uv2 = uvs[ y + 1 ][ x ].clone();
  21090. var uv3 = uvs[ y + 1 ][ x + 1 ].clone();
  21091. var uv4 = uvs[ y ][ x + 1 ].clone();
  21092. this.faces.push( new THREE.Face3( v1, v2, v4, [ n1, n2, n4 ] ) );
  21093. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv4 ] );
  21094. this.faces.push( new THREE.Face3( v2, v3, v4, [ n2.clone(), n3, n4.clone() ] ) );
  21095. this.faceVertexUvs[ 0 ].push( [ uv2.clone(), uv3, uv4.clone() ] );
  21096. }
  21097. }
  21098. // top cap
  21099. if ( openEnded === false && radiusTop > 0 ) {
  21100. this.vertices.push( new THREE.Vector3( 0, heightHalf, 0 ) );
  21101. for ( x = 0; x < radialSegments; x ++ ) {
  21102. var v1 = vertices[ 0 ][ x ];
  21103. var v2 = vertices[ 0 ][ x + 1 ];
  21104. var v3 = this.vertices.length - 1;
  21105. var n1 = new THREE.Vector3( 0, 1, 0 );
  21106. var n2 = new THREE.Vector3( 0, 1, 0 );
  21107. var n3 = new THREE.Vector3( 0, 1, 0 );
  21108. var uv1 = uvs[ 0 ][ x ].clone();
  21109. var uv2 = uvs[ 0 ][ x + 1 ].clone();
  21110. var uv3 = new THREE.Vector2( uv2.x, 0 );
  21111. this.faces.push( new THREE.Face3( v1, v2, v3, [ n1, n2, n3 ], undefined, 1 ) );
  21112. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3 ] );
  21113. }
  21114. }
  21115. // bottom cap
  21116. if ( openEnded === false && radiusBottom > 0 ) {
  21117. this.vertices.push( new THREE.Vector3( 0, - heightHalf, 0 ) );
  21118. for ( x = 0; x < radialSegments; x ++ ) {
  21119. var v1 = vertices[ heightSegments ][ x + 1 ];
  21120. var v2 = vertices[ heightSegments ][ x ];
  21121. var v3 = this.vertices.length - 1;
  21122. var n1 = new THREE.Vector3( 0, - 1, 0 );
  21123. var n2 = new THREE.Vector3( 0, - 1, 0 );
  21124. var n3 = new THREE.Vector3( 0, - 1, 0 );
  21125. var uv1 = uvs[ heightSegments ][ x + 1 ].clone();
  21126. var uv2 = uvs[ heightSegments ][ x ].clone();
  21127. var uv3 = new THREE.Vector2( uv2.x, 1 );
  21128. this.faces.push( new THREE.Face3( v1, v2, v3, [ n1, n2, n3 ], undefined, 2 ) );
  21129. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3 ] );
  21130. }
  21131. }
  21132. this.computeFaceNormals();
  21133. };
  21134. THREE.CylinderGeometry.prototype = Object.create( THREE.Geometry.prototype );
  21135. THREE.CylinderGeometry.prototype.constructor = THREE.CylinderGeometry;
  21136. // File:src/extras/geometries/EdgesGeometry.js
  21137. /**
  21138. * @author WestLangley / http://github.com/WestLangley
  21139. */
  21140. THREE.EdgesGeometry = function ( geometry, thresholdAngle ) {
  21141. THREE.BufferGeometry.call( this );
  21142. thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
  21143. var thresholdDot = Math.cos( THREE.Math.degToRad( thresholdAngle ) );
  21144. var edge = [ 0, 0 ], hash = {};
  21145. function sortFunction( a, b ) {
  21146. return a - b;
  21147. }
  21148. var keys = [ 'a', 'b', 'c' ];
  21149. var geometry2;
  21150. if ( geometry instanceof THREE.BufferGeometry ) {
  21151. geometry2 = new THREE.Geometry();
  21152. geometry2.fromBufferGeometry( geometry );
  21153. } else {
  21154. geometry2 = geometry.clone();
  21155. }
  21156. geometry2.mergeVertices();
  21157. geometry2.computeFaceNormals();
  21158. var vertices = geometry2.vertices;
  21159. var faces = geometry2.faces;
  21160. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  21161. var face = faces[ i ];
  21162. for ( var j = 0; j < 3; j ++ ) {
  21163. edge[ 0 ] = face[ keys[ j ] ];
  21164. edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
  21165. edge.sort( sortFunction );
  21166. var key = edge.toString();
  21167. if ( hash[ key ] === undefined ) {
  21168. hash[ key ] = { vert1: edge[ 0 ], vert2: edge[ 1 ], face1: i, face2: undefined };
  21169. } else {
  21170. hash[ key ].face2 = i;
  21171. }
  21172. }
  21173. }
  21174. var coords = [];
  21175. for ( var key in hash ) {
  21176. var h = hash[ key ];
  21177. if ( h.face2 === undefined || faces[ h.face1 ].normal.dot( faces[ h.face2 ].normal ) <= thresholdDot ) {
  21178. var vertex = vertices[ h.vert1 ];
  21179. coords.push( vertex.x );
  21180. coords.push( vertex.y );
  21181. coords.push( vertex.z );
  21182. vertex = vertices[ h.vert2 ];
  21183. coords.push( vertex.x );
  21184. coords.push( vertex.y );
  21185. coords.push( vertex.z );
  21186. }
  21187. }
  21188. this.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array( coords ), 3 ) );
  21189. };
  21190. THREE.EdgesGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  21191. THREE.EdgesGeometry.prototype.constructor = THREE.EdgesGeometry;
  21192. // File:src/extras/geometries/ExtrudeGeometry.js
  21193. /**
  21194. * @author zz85 / http://www.lab4games.net/zz85/blog
  21195. *
  21196. * Creates extruded geometry from a path shape.
  21197. *
  21198. * parameters = {
  21199. *
  21200. * curveSegments: <int>, // number of points on the curves
  21201. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  21202. * amount: <int>, // Depth to extrude the shape
  21203. *
  21204. * bevelEnabled: <bool>, // turn on bevel
  21205. * bevelThickness: <float>, // how deep into the original shape bevel goes
  21206. * bevelSize: <float>, // how far from shape outline is bevel
  21207. * bevelSegments: <int>, // number of bevel layers
  21208. *
  21209. * extrudePath: <THREE.CurvePath> // 3d spline path to extrude shape along. (creates Frames if .frames aren't defined)
  21210. * frames: <THREE.TubeGeometry.FrenetFrames> // containing arrays of tangents, normals, binormals
  21211. *
  21212. * uvGenerator: <Object> // object that provides UV generator functions
  21213. *
  21214. * }
  21215. **/
  21216. THREE.ExtrudeGeometry = function ( shapes, options ) {
  21217. if ( typeof( shapes ) === "undefined" ) {
  21218. shapes = [];
  21219. return;
  21220. }
  21221. THREE.Geometry.call( this );
  21222. this.type = 'ExtrudeGeometry';
  21223. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  21224. this.addShapeList( shapes, options );
  21225. this.computeFaceNormals();
  21226. // can't really use automatic vertex normals
  21227. // as then front and back sides get smoothed too
  21228. // should do separate smoothing just for sides
  21229. //this.computeVertexNormals();
  21230. //console.log( "took", ( Date.now() - startTime ) );
  21231. };
  21232. THREE.ExtrudeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  21233. THREE.ExtrudeGeometry.prototype.constructor = THREE.ExtrudeGeometry;
  21234. THREE.ExtrudeGeometry.prototype.addShapeList = function ( shapes, options ) {
  21235. var sl = shapes.length;
  21236. for ( var s = 0; s < sl; s ++ ) {
  21237. var shape = shapes[ s ];
  21238. this.addShape( shape, options );
  21239. }
  21240. };
  21241. THREE.ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
  21242. var amount = options.amount !== undefined ? options.amount : 100;
  21243. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6; // 10
  21244. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2; // 8
  21245. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  21246. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true; // false
  21247. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  21248. var steps = options.steps !== undefined ? options.steps : 1;
  21249. var extrudePath = options.extrudePath;
  21250. var extrudePts, extrudeByPath = false;
  21251. // Use default WorldUVGenerator if no UV generators are specified.
  21252. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : THREE.ExtrudeGeometry.WorldUVGenerator;
  21253. var splineTube, binormal, normal, position2;
  21254. if ( extrudePath ) {
  21255. extrudePts = extrudePath.getSpacedPoints( steps );
  21256. extrudeByPath = true;
  21257. bevelEnabled = false; // bevels not supported for path extrusion
  21258. // SETUP TNB variables
  21259. // Reuse TNB from TubeGeomtry for now.
  21260. // TODO1 - have a .isClosed in spline?
  21261. splineTube = options.frames !== undefined ? options.frames : new THREE.TubeGeometry.FrenetFrames( extrudePath, steps, false );
  21262. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  21263. binormal = new THREE.Vector3();
  21264. normal = new THREE.Vector3();
  21265. position2 = new THREE.Vector3();
  21266. }
  21267. // Safeguards if bevels are not enabled
  21268. if ( ! bevelEnabled ) {
  21269. bevelSegments = 0;
  21270. bevelThickness = 0;
  21271. bevelSize = 0;
  21272. }
  21273. // Variables initialization
  21274. var ahole, h, hl; // looping of holes
  21275. var scope = this;
  21276. var shapesOffset = this.vertices.length;
  21277. var shapePoints = shape.extractPoints( curveSegments );
  21278. var vertices = shapePoints.shape;
  21279. var holes = shapePoints.holes;
  21280. var reverse = ! THREE.ShapeUtils.isClockWise( vertices );
  21281. if ( reverse ) {
  21282. vertices = vertices.reverse();
  21283. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  21284. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  21285. ahole = holes[ h ];
  21286. if ( THREE.ShapeUtils.isClockWise( ahole ) ) {
  21287. holes[ h ] = ahole.reverse();
  21288. }
  21289. }
  21290. reverse = false; // If vertices are in order now, we shouldn't need to worry about them again (hopefully)!
  21291. }
  21292. var faces = THREE.ShapeUtils.triangulateShape( vertices, holes );
  21293. /* Vertices */
  21294. var contour = vertices; // vertices has all points but contour has only points of circumference
  21295. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  21296. ahole = holes[ h ];
  21297. vertices = vertices.concat( ahole );
  21298. }
  21299. function scalePt2 ( pt, vec, size ) {
  21300. if ( ! vec ) console.error( "THREE.ExtrudeGeometry: vec does not exist" );
  21301. return vec.clone().multiplyScalar( size ).add( pt );
  21302. }
  21303. var b, bs, t, z,
  21304. vert, vlen = vertices.length,
  21305. face, flen = faces.length;
  21306. // Find directions for point movement
  21307. function getBevelVec( inPt, inPrev, inNext ) {
  21308. // computes for inPt the corresponding point inPt' on a new contour
  21309. // shifted by 1 unit (length of normalized vector) to the left
  21310. // if we walk along contour clockwise, this new contour is outside the old one
  21311. //
  21312. // inPt' is the intersection of the two lines parallel to the two
  21313. // adjacent edges of inPt at a distance of 1 unit on the left side.
  21314. var v_trans_x, v_trans_y, shrink_by = 1; // resulting translation vector for inPt
  21315. // good reading for geometry algorithms (here: line-line intersection)
  21316. // http://geomalgorithms.com/a05-_intersect-1.html
  21317. var v_prev_x = inPt.x - inPrev.x, v_prev_y = inPt.y - inPrev.y;
  21318. var v_next_x = inNext.x - inPt.x, v_next_y = inNext.y - inPt.y;
  21319. var v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  21320. // check for collinear edges
  21321. var collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  21322. if ( Math.abs( collinear0 ) > Number.EPSILON ) {
  21323. // not collinear
  21324. // length of vectors for normalizing
  21325. var v_prev_len = Math.sqrt( v_prev_lensq );
  21326. var v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  21327. // shift adjacent points by unit vectors to the left
  21328. var ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  21329. var ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  21330. var ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  21331. var ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  21332. // scaling factor for v_prev to intersection point
  21333. var sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  21334. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  21335. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  21336. // vector from inPt to intersection point
  21337. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  21338. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  21339. // Don't normalize!, otherwise sharp corners become ugly
  21340. // but prevent crazy spikes
  21341. var v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  21342. if ( v_trans_lensq <= 2 ) {
  21343. return new THREE.Vector2( v_trans_x, v_trans_y );
  21344. } else {
  21345. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  21346. }
  21347. } else {
  21348. // handle special case of collinear edges
  21349. var direction_eq = false; // assumes: opposite
  21350. if ( v_prev_x > Number.EPSILON ) {
  21351. if ( v_next_x > Number.EPSILON ) {
  21352. direction_eq = true;
  21353. }
  21354. } else {
  21355. if ( v_prev_x < - Number.EPSILON ) {
  21356. if ( v_next_x < - Number.EPSILON ) {
  21357. direction_eq = true;
  21358. }
  21359. } else {
  21360. if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
  21361. direction_eq = true;
  21362. }
  21363. }
  21364. }
  21365. if ( direction_eq ) {
  21366. // console.log("Warning: lines are a straight sequence");
  21367. v_trans_x = - v_prev_y;
  21368. v_trans_y = v_prev_x;
  21369. shrink_by = Math.sqrt( v_prev_lensq );
  21370. } else {
  21371. // console.log("Warning: lines are a straight spike");
  21372. v_trans_x = v_prev_x;
  21373. v_trans_y = v_prev_y;
  21374. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  21375. }
  21376. }
  21377. return new THREE.Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  21378. }
  21379. var contourMovements = [];
  21380. for ( var i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  21381. if ( j === il ) j = 0;
  21382. if ( k === il ) k = 0;
  21383. // (j)---(i)---(k)
  21384. // console.log('i,j,k', i, j , k)
  21385. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  21386. }
  21387. var holesMovements = [], oneHoleMovements, verticesMovements = contourMovements.concat();
  21388. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  21389. ahole = holes[ h ];
  21390. oneHoleMovements = [];
  21391. for ( i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  21392. if ( j === il ) j = 0;
  21393. if ( k === il ) k = 0;
  21394. // (j)---(i)---(k)
  21395. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  21396. }
  21397. holesMovements.push( oneHoleMovements );
  21398. verticesMovements = verticesMovements.concat( oneHoleMovements );
  21399. }
  21400. // Loop bevelSegments, 1 for the front, 1 for the back
  21401. for ( b = 0; b < bevelSegments; b ++ ) {
  21402. //for ( b = bevelSegments; b > 0; b -- ) {
  21403. t = b / bevelSegments;
  21404. z = bevelThickness * ( 1 - t );
  21405. //z = bevelThickness * t;
  21406. bs = bevelSize * ( Math.sin ( t * Math.PI / 2 ) ); // curved
  21407. //bs = bevelSize * t; // linear
  21408. // contract shape
  21409. for ( i = 0, il = contour.length; i < il; i ++ ) {
  21410. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  21411. v( vert.x, vert.y, - z );
  21412. }
  21413. // expand holes
  21414. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  21415. ahole = holes[ h ];
  21416. oneHoleMovements = holesMovements[ h ];
  21417. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  21418. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  21419. v( vert.x, vert.y, - z );
  21420. }
  21421. }
  21422. }
  21423. bs = bevelSize;
  21424. // Back facing vertices
  21425. for ( i = 0; i < vlen; i ++ ) {
  21426. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  21427. if ( ! extrudeByPath ) {
  21428. v( vert.x, vert.y, 0 );
  21429. } else {
  21430. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  21431. normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x );
  21432. binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y );
  21433. position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
  21434. v( position2.x, position2.y, position2.z );
  21435. }
  21436. }
  21437. // Add stepped vertices...
  21438. // Including front facing vertices
  21439. var s;
  21440. for ( s = 1; s <= steps; s ++ ) {
  21441. for ( i = 0; i < vlen; i ++ ) {
  21442. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  21443. if ( ! extrudeByPath ) {
  21444. v( vert.x, vert.y, amount / steps * s );
  21445. } else {
  21446. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  21447. normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x );
  21448. binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y );
  21449. position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
  21450. v( position2.x, position2.y, position2.z );
  21451. }
  21452. }
  21453. }
  21454. // Add bevel segments planes
  21455. //for ( b = 1; b <= bevelSegments; b ++ ) {
  21456. for ( b = bevelSegments - 1; b >= 0; b -- ) {
  21457. t = b / bevelSegments;
  21458. z = bevelThickness * ( 1 - t );
  21459. //bs = bevelSize * ( 1-Math.sin ( ( 1 - t ) * Math.PI/2 ) );
  21460. bs = bevelSize * Math.sin ( t * Math.PI / 2 );
  21461. // contract shape
  21462. for ( i = 0, il = contour.length; i < il; i ++ ) {
  21463. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  21464. v( vert.x, vert.y, amount + z );
  21465. }
  21466. // expand holes
  21467. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  21468. ahole = holes[ h ];
  21469. oneHoleMovements = holesMovements[ h ];
  21470. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  21471. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  21472. if ( ! extrudeByPath ) {
  21473. v( vert.x, vert.y, amount + z );
  21474. } else {
  21475. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  21476. }
  21477. }
  21478. }
  21479. }
  21480. /* Faces */
  21481. // Top and bottom faces
  21482. buildLidFaces();
  21483. // Sides faces
  21484. buildSideFaces();
  21485. ///// Internal functions
  21486. function buildLidFaces() {
  21487. if ( bevelEnabled ) {
  21488. var layer = 0; // steps + 1
  21489. var offset = vlen * layer;
  21490. // Bottom faces
  21491. for ( i = 0; i < flen; i ++ ) {
  21492. face = faces[ i ];
  21493. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  21494. }
  21495. layer = steps + bevelSegments * 2;
  21496. offset = vlen * layer;
  21497. // Top faces
  21498. for ( i = 0; i < flen; i ++ ) {
  21499. face = faces[ i ];
  21500. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  21501. }
  21502. } else {
  21503. // Bottom faces
  21504. for ( i = 0; i < flen; i ++ ) {
  21505. face = faces[ i ];
  21506. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  21507. }
  21508. // Top faces
  21509. for ( i = 0; i < flen; i ++ ) {
  21510. face = faces[ i ];
  21511. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  21512. }
  21513. }
  21514. }
  21515. // Create faces for the z-sides of the shape
  21516. function buildSideFaces() {
  21517. var layeroffset = 0;
  21518. sidewalls( contour, layeroffset );
  21519. layeroffset += contour.length;
  21520. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  21521. ahole = holes[ h ];
  21522. sidewalls( ahole, layeroffset );
  21523. //, true
  21524. layeroffset += ahole.length;
  21525. }
  21526. }
  21527. function sidewalls( contour, layeroffset ) {
  21528. var j, k;
  21529. i = contour.length;
  21530. while ( -- i >= 0 ) {
  21531. j = i;
  21532. k = i - 1;
  21533. if ( k < 0 ) k = contour.length - 1;
  21534. //console.log('b', i,j, i-1, k,vertices.length);
  21535. var s = 0, sl = steps + bevelSegments * 2;
  21536. for ( s = 0; s < sl; s ++ ) {
  21537. var slen1 = vlen * s;
  21538. var slen2 = vlen * ( s + 1 );
  21539. var a = layeroffset + j + slen1,
  21540. b = layeroffset + k + slen1,
  21541. c = layeroffset + k + slen2,
  21542. d = layeroffset + j + slen2;
  21543. f4( a, b, c, d, contour, s, sl, j, k );
  21544. }
  21545. }
  21546. }
  21547. function v( x, y, z ) {
  21548. scope.vertices.push( new THREE.Vector3( x, y, z ) );
  21549. }
  21550. function f3( a, b, c ) {
  21551. a += shapesOffset;
  21552. b += shapesOffset;
  21553. c += shapesOffset;
  21554. scope.faces.push( new THREE.Face3( a, b, c, null, null, 0 ) );
  21555. var uvs = uvgen.generateTopUV( scope, a, b, c );
  21556. scope.faceVertexUvs[ 0 ].push( uvs );
  21557. }
  21558. function f4( a, b, c, d, wallContour, stepIndex, stepsLength, contourIndex1, contourIndex2 ) {
  21559. a += shapesOffset;
  21560. b += shapesOffset;
  21561. c += shapesOffset;
  21562. d += shapesOffset;
  21563. scope.faces.push( new THREE.Face3( a, b, d, null, null, 1 ) );
  21564. scope.faces.push( new THREE.Face3( b, c, d, null, null, 1 ) );
  21565. var uvs = uvgen.generateSideWallUV( scope, a, b, c, d );
  21566. scope.faceVertexUvs[ 0 ].push( [ uvs[ 0 ], uvs[ 1 ], uvs[ 3 ] ] );
  21567. scope.faceVertexUvs[ 0 ].push( [ uvs[ 1 ], uvs[ 2 ], uvs[ 3 ] ] );
  21568. }
  21569. };
  21570. THREE.ExtrudeGeometry.WorldUVGenerator = {
  21571. generateTopUV: function ( geometry, indexA, indexB, indexC ) {
  21572. var vertices = geometry.vertices;
  21573. var a = vertices[ indexA ];
  21574. var b = vertices[ indexB ];
  21575. var c = vertices[ indexC ];
  21576. return [
  21577. new THREE.Vector2( a.x, a.y ),
  21578. new THREE.Vector2( b.x, b.y ),
  21579. new THREE.Vector2( c.x, c.y )
  21580. ];
  21581. },
  21582. generateSideWallUV: function ( geometry, indexA, indexB, indexC, indexD ) {
  21583. var vertices = geometry.vertices;
  21584. var a = vertices[ indexA ];
  21585. var b = vertices[ indexB ];
  21586. var c = vertices[ indexC ];
  21587. var d = vertices[ indexD ];
  21588. if ( Math.abs( a.y - b.y ) < 0.01 ) {
  21589. return [
  21590. new THREE.Vector2( a.x, 1 - a.z ),
  21591. new THREE.Vector2( b.x, 1 - b.z ),
  21592. new THREE.Vector2( c.x, 1 - c.z ),
  21593. new THREE.Vector2( d.x, 1 - d.z )
  21594. ];
  21595. } else {
  21596. return [
  21597. new THREE.Vector2( a.y, 1 - a.z ),
  21598. new THREE.Vector2( b.y, 1 - b.z ),
  21599. new THREE.Vector2( c.y, 1 - c.z ),
  21600. new THREE.Vector2( d.y, 1 - d.z )
  21601. ];
  21602. }
  21603. }
  21604. };
  21605. // File:src/extras/geometries/ShapeGeometry.js
  21606. /**
  21607. * @author jonobr1 / http://jonobr1.com
  21608. *
  21609. * Creates a one-sided polygonal geometry from a path shape. Similar to
  21610. * ExtrudeGeometry.
  21611. *
  21612. * parameters = {
  21613. *
  21614. * curveSegments: <int>, // number of points on the curves. NOT USED AT THE MOMENT.
  21615. *
  21616. * material: <int> // material index for front and back faces
  21617. * uvGenerator: <Object> // object that provides UV generator functions
  21618. *
  21619. * }
  21620. **/
  21621. THREE.ShapeGeometry = function ( shapes, options ) {
  21622. THREE.Geometry.call( this );
  21623. this.type = 'ShapeGeometry';
  21624. if ( Array.isArray( shapes ) === false ) shapes = [ shapes ];
  21625. this.addShapeList( shapes, options );
  21626. this.computeFaceNormals();
  21627. };
  21628. THREE.ShapeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  21629. THREE.ShapeGeometry.prototype.constructor = THREE.ShapeGeometry;
  21630. /**
  21631. * Add an array of shapes to THREE.ShapeGeometry.
  21632. */
  21633. THREE.ShapeGeometry.prototype.addShapeList = function ( shapes, options ) {
  21634. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  21635. this.addShape( shapes[ i ], options );
  21636. }
  21637. return this;
  21638. };
  21639. /**
  21640. * Adds a shape to THREE.ShapeGeometry, based on THREE.ExtrudeGeometry.
  21641. */
  21642. THREE.ShapeGeometry.prototype.addShape = function ( shape, options ) {
  21643. if ( options === undefined ) options = {};
  21644. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  21645. var material = options.material;
  21646. var uvgen = options.UVGenerator === undefined ? THREE.ExtrudeGeometry.WorldUVGenerator : options.UVGenerator;
  21647. //
  21648. var i, l, hole;
  21649. var shapesOffset = this.vertices.length;
  21650. var shapePoints = shape.extractPoints( curveSegments );
  21651. var vertices = shapePoints.shape;
  21652. var holes = shapePoints.holes;
  21653. var reverse = ! THREE.ShapeUtils.isClockWise( vertices );
  21654. if ( reverse ) {
  21655. vertices = vertices.reverse();
  21656. // Maybe we should also check if holes are in the opposite direction, just to be safe...
  21657. for ( i = 0, l = holes.length; i < l; i ++ ) {
  21658. hole = holes[ i ];
  21659. if ( THREE.ShapeUtils.isClockWise( hole ) ) {
  21660. holes[ i ] = hole.reverse();
  21661. }
  21662. }
  21663. reverse = false;
  21664. }
  21665. var faces = THREE.ShapeUtils.triangulateShape( vertices, holes );
  21666. // Vertices
  21667. for ( i = 0, l = holes.length; i < l; i ++ ) {
  21668. hole = holes[ i ];
  21669. vertices = vertices.concat( hole );
  21670. }
  21671. //
  21672. var vert, vlen = vertices.length;
  21673. var face, flen = faces.length;
  21674. for ( i = 0; i < vlen; i ++ ) {
  21675. vert = vertices[ i ];
  21676. this.vertices.push( new THREE.Vector3( vert.x, vert.y, 0 ) );
  21677. }
  21678. for ( i = 0; i < flen; i ++ ) {
  21679. face = faces[ i ];
  21680. var a = face[ 0 ] + shapesOffset;
  21681. var b = face[ 1 ] + shapesOffset;
  21682. var c = face[ 2 ] + shapesOffset;
  21683. this.faces.push( new THREE.Face3( a, b, c, null, null, material ) );
  21684. this.faceVertexUvs[ 0 ].push( uvgen.generateTopUV( this, a, b, c ) );
  21685. }
  21686. };
  21687. // File:src/extras/geometries/LatheGeometry.js
  21688. /**
  21689. * @author astrodud / http://astrodud.isgreat.org/
  21690. * @author zz85 / https://github.com/zz85
  21691. * @author bhouston / http://clara.io
  21692. */
  21693. // points - to create a closed torus, one must use a set of points
  21694. // like so: [ a, b, c, d, a ], see first is the same as last.
  21695. // segments - the number of circumference segments to create
  21696. // phiStart - the starting radian
  21697. // phiLength - the radian (0 to 2*PI) range of the lathed section
  21698. // 2*pi is a closed lathe, less than 2PI is a portion.
  21699. THREE.LatheGeometry = function ( points, segments, phiStart, phiLength ) {
  21700. THREE.Geometry.call( this );
  21701. this.type = 'LatheGeometry';
  21702. this.parameters = {
  21703. points: points,
  21704. segments: segments,
  21705. phiStart: phiStart,
  21706. phiLength: phiLength
  21707. };
  21708. segments = segments || 12;
  21709. phiStart = phiStart || 0;
  21710. phiLength = phiLength || 2 * Math.PI;
  21711. var inversePointLength = 1.0 / ( points.length - 1 );
  21712. var inverseSegments = 1.0 / segments;
  21713. for ( var i = 0, il = segments; i <= il; i ++ ) {
  21714. var phi = phiStart + i * inverseSegments * phiLength;
  21715. var c = Math.cos( phi ),
  21716. s = Math.sin( phi );
  21717. for ( var j = 0, jl = points.length; j < jl; j ++ ) {
  21718. var pt = points[ j ];
  21719. var vertex = new THREE.Vector3();
  21720. vertex.x = c * pt.x - s * pt.y;
  21721. vertex.y = s * pt.x + c * pt.y;
  21722. vertex.z = pt.z;
  21723. this.vertices.push( vertex );
  21724. }
  21725. }
  21726. var np = points.length;
  21727. for ( var i = 0, il = segments; i < il; i ++ ) {
  21728. for ( var j = 0, jl = points.length - 1; j < jl; j ++ ) {
  21729. var base = j + np * i;
  21730. var a = base;
  21731. var b = base + np;
  21732. var c = base + 1 + np;
  21733. var d = base + 1;
  21734. var u0 = i * inverseSegments;
  21735. var v0 = j * inversePointLength;
  21736. var u1 = u0 + inverseSegments;
  21737. var v1 = v0 + inversePointLength;
  21738. this.faces.push( new THREE.Face3( a, b, d ) );
  21739. this.faceVertexUvs[ 0 ].push( [
  21740. new THREE.Vector2( u0, v0 ),
  21741. new THREE.Vector2( u1, v0 ),
  21742. new THREE.Vector2( u0, v1 )
  21743. ] );
  21744. this.faces.push( new THREE.Face3( b, c, d ) );
  21745. this.faceVertexUvs[ 0 ].push( [
  21746. new THREE.Vector2( u1, v0 ),
  21747. new THREE.Vector2( u1, v1 ),
  21748. new THREE.Vector2( u0, v1 )
  21749. ] );
  21750. }
  21751. }
  21752. this.mergeVertices();
  21753. this.computeFaceNormals();
  21754. this.computeVertexNormals();
  21755. };
  21756. THREE.LatheGeometry.prototype = Object.create( THREE.Geometry.prototype );
  21757. THREE.LatheGeometry.prototype.constructor = THREE.LatheGeometry;
  21758. // File:src/extras/geometries/PlaneGeometry.js
  21759. /**
  21760. * @author mrdoob / http://mrdoob.com/
  21761. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
  21762. */
  21763. THREE.PlaneGeometry = function ( width, height, widthSegments, heightSegments ) {
  21764. THREE.Geometry.call( this );
  21765. this.type = 'PlaneGeometry';
  21766. this.parameters = {
  21767. width: width,
  21768. height: height,
  21769. widthSegments: widthSegments,
  21770. heightSegments: heightSegments
  21771. };
  21772. this.fromBufferGeometry( new THREE.PlaneBufferGeometry( width, height, widthSegments, heightSegments ) );
  21773. };
  21774. THREE.PlaneGeometry.prototype = Object.create( THREE.Geometry.prototype );
  21775. THREE.PlaneGeometry.prototype.constructor = THREE.PlaneGeometry;
  21776. // File:src/extras/geometries/PlaneBufferGeometry.js
  21777. /**
  21778. * @author mrdoob / http://mrdoob.com/
  21779. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
  21780. */
  21781. THREE.PlaneBufferGeometry = function ( width, height, widthSegments, heightSegments ) {
  21782. THREE.BufferGeometry.call( this );
  21783. this.type = 'PlaneBufferGeometry';
  21784. this.parameters = {
  21785. width: width,
  21786. height: height,
  21787. widthSegments: widthSegments,
  21788. heightSegments: heightSegments
  21789. };
  21790. var width_half = width / 2;
  21791. var height_half = height / 2;
  21792. var gridX = Math.floor( widthSegments ) || 1;
  21793. var gridY = Math.floor( heightSegments ) || 1;
  21794. var gridX1 = gridX + 1;
  21795. var gridY1 = gridY + 1;
  21796. var segment_width = width / gridX;
  21797. var segment_height = height / gridY;
  21798. var vertices = new Float32Array( gridX1 * gridY1 * 3 );
  21799. var normals = new Float32Array( gridX1 * gridY1 * 3 );
  21800. var uvs = new Float32Array( gridX1 * gridY1 * 2 );
  21801. var offset = 0;
  21802. var offset2 = 0;
  21803. for ( var iy = 0; iy < gridY1; iy ++ ) {
  21804. var y = iy * segment_height - height_half;
  21805. for ( var ix = 0; ix < gridX1; ix ++ ) {
  21806. var x = ix * segment_width - width_half;
  21807. vertices[ offset ] = x;
  21808. vertices[ offset + 1 ] = - y;
  21809. normals[ offset + 2 ] = 1;
  21810. uvs[ offset2 ] = ix / gridX;
  21811. uvs[ offset2 + 1 ] = 1 - ( iy / gridY );
  21812. offset += 3;
  21813. offset2 += 2;
  21814. }
  21815. }
  21816. offset = 0;
  21817. var indices = new ( ( vertices.length / 3 ) > 65535 ? Uint32Array : Uint16Array )( gridX * gridY * 6 );
  21818. for ( var iy = 0; iy < gridY; iy ++ ) {
  21819. for ( var ix = 0; ix < gridX; ix ++ ) {
  21820. var a = ix + gridX1 * iy;
  21821. var b = ix + gridX1 * ( iy + 1 );
  21822. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  21823. var d = ( ix + 1 ) + gridX1 * iy;
  21824. indices[ offset ] = a;
  21825. indices[ offset + 1 ] = b;
  21826. indices[ offset + 2 ] = d;
  21827. indices[ offset + 3 ] = b;
  21828. indices[ offset + 4 ] = c;
  21829. indices[ offset + 5 ] = d;
  21830. offset += 6;
  21831. }
  21832. }
  21833. this.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  21834. this.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  21835. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  21836. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  21837. };
  21838. THREE.PlaneBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  21839. THREE.PlaneBufferGeometry.prototype.constructor = THREE.PlaneBufferGeometry;
  21840. // File:src/extras/geometries/RingGeometry.js
  21841. /**
  21842. * @author Kaleb Murphy
  21843. */
  21844. THREE.RingGeometry = function ( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  21845. THREE.Geometry.call( this );
  21846. this.type = 'RingGeometry';
  21847. this.parameters = {
  21848. innerRadius: innerRadius,
  21849. outerRadius: outerRadius,
  21850. thetaSegments: thetaSegments,
  21851. phiSegments: phiSegments,
  21852. thetaStart: thetaStart,
  21853. thetaLength: thetaLength
  21854. };
  21855. innerRadius = innerRadius || 0;
  21856. outerRadius = outerRadius || 50;
  21857. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  21858. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  21859. thetaSegments = thetaSegments !== undefined ? Math.max( 3, thetaSegments ) : 8;
  21860. phiSegments = phiSegments !== undefined ? Math.max( 1, phiSegments ) : 8;
  21861. var i, o, uvs = [], radius = innerRadius, radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  21862. for ( i = 0; i < phiSegments + 1; i ++ ) {
  21863. // concentric circles inside ring
  21864. for ( o = 0; o < thetaSegments + 1; o ++ ) {
  21865. // number of segments per circle
  21866. var vertex = new THREE.Vector3();
  21867. var segment = thetaStart + o / thetaSegments * thetaLength;
  21868. vertex.x = radius * Math.cos( segment );
  21869. vertex.y = radius * Math.sin( segment );
  21870. this.vertices.push( vertex );
  21871. uvs.push( new THREE.Vector2( ( vertex.x / outerRadius + 1 ) / 2, ( vertex.y / outerRadius + 1 ) / 2 ) );
  21872. }
  21873. radius += radiusStep;
  21874. }
  21875. var n = new THREE.Vector3( 0, 0, 1 );
  21876. for ( i = 0; i < phiSegments; i ++ ) {
  21877. // concentric circles inside ring
  21878. var thetaSegment = i * ( thetaSegments + 1 );
  21879. for ( o = 0; o < thetaSegments ; o ++ ) {
  21880. // number of segments per circle
  21881. var segment = o + thetaSegment;
  21882. var v1 = segment;
  21883. var v2 = segment + thetaSegments + 1;
  21884. var v3 = segment + thetaSegments + 2;
  21885. this.faces.push( new THREE.Face3( v1, v2, v3, [ n.clone(), n.clone(), n.clone() ] ) );
  21886. this.faceVertexUvs[ 0 ].push( [ uvs[ v1 ].clone(), uvs[ v2 ].clone(), uvs[ v3 ].clone() ] );
  21887. v1 = segment;
  21888. v2 = segment + thetaSegments + 2;
  21889. v3 = segment + 1;
  21890. this.faces.push( new THREE.Face3( v1, v2, v3, [ n.clone(), n.clone(), n.clone() ] ) );
  21891. this.faceVertexUvs[ 0 ].push( [ uvs[ v1 ].clone(), uvs[ v2 ].clone(), uvs[ v3 ].clone() ] );
  21892. }
  21893. }
  21894. this.computeFaceNormals();
  21895. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  21896. };
  21897. THREE.RingGeometry.prototype = Object.create( THREE.Geometry.prototype );
  21898. THREE.RingGeometry.prototype.constructor = THREE.RingGeometry;
  21899. // File:src/extras/geometries/SphereGeometry.js
  21900. /**
  21901. * @author mrdoob / http://mrdoob.com/
  21902. */
  21903. THREE.SphereGeometry = function ( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  21904. THREE.Geometry.call( this );
  21905. this.type = 'SphereGeometry';
  21906. this.parameters = {
  21907. radius: radius,
  21908. widthSegments: widthSegments,
  21909. heightSegments: heightSegments,
  21910. phiStart: phiStart,
  21911. phiLength: phiLength,
  21912. thetaStart: thetaStart,
  21913. thetaLength: thetaLength
  21914. };
  21915. this.fromBufferGeometry( new THREE.SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) );
  21916. };
  21917. THREE.SphereGeometry.prototype = Object.create( THREE.Geometry.prototype );
  21918. THREE.SphereGeometry.prototype.constructor = THREE.SphereGeometry;
  21919. // File:src/extras/geometries/SphereBufferGeometry.js
  21920. /**
  21921. * @author benaadams / https://twitter.com/ben_a_adams
  21922. * based on THREE.SphereGeometry
  21923. */
  21924. THREE.SphereBufferGeometry = function ( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  21925. THREE.BufferGeometry.call( this );
  21926. this.type = 'SphereBufferGeometry';
  21927. this.parameters = {
  21928. radius: radius,
  21929. widthSegments: widthSegments,
  21930. heightSegments: heightSegments,
  21931. phiStart: phiStart,
  21932. phiLength: phiLength,
  21933. thetaStart: thetaStart,
  21934. thetaLength: thetaLength
  21935. };
  21936. radius = radius || 50;
  21937. widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
  21938. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  21939. phiStart = phiStart !== undefined ? phiStart : 0;
  21940. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  21941. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  21942. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  21943. var thetaEnd = thetaStart + thetaLength;
  21944. var vertexCount = ( ( widthSegments + 1 ) * ( heightSegments + 1 ) );
  21945. var positions = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  21946. var normals = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  21947. var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
  21948. var index = 0, vertices = [], normal = new THREE.Vector3();
  21949. for ( var y = 0; y <= heightSegments; y ++ ) {
  21950. var verticesRow = [];
  21951. var v = y / heightSegments;
  21952. for ( var x = 0; x <= widthSegments; x ++ ) {
  21953. var u = x / widthSegments;
  21954. var px = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  21955. var py = radius * Math.cos( thetaStart + v * thetaLength );
  21956. var pz = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  21957. normal.set( px, py, pz ).normalize();
  21958. positions.setXYZ( index, px, py, pz );
  21959. normals.setXYZ( index, normal.x, normal.y, normal.z );
  21960. uvs.setXY( index, u, 1 - v );
  21961. verticesRow.push( index );
  21962. index ++;
  21963. }
  21964. vertices.push( verticesRow );
  21965. }
  21966. var indices = [];
  21967. for ( var y = 0; y < heightSegments; y ++ ) {
  21968. for ( var x = 0; x < widthSegments; x ++ ) {
  21969. var v1 = vertices[ y ][ x + 1 ];
  21970. var v2 = vertices[ y ][ x ];
  21971. var v3 = vertices[ y + 1 ][ x ];
  21972. var v4 = vertices[ y + 1 ][ x + 1 ];
  21973. if ( y !== 0 || thetaStart > 0 ) indices.push( v1, v2, v4 );
  21974. if ( y !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( v2, v3, v4 );
  21975. }
  21976. }
  21977. this.setIndex( new ( positions.count > 65535 ? THREE.Uint32Attribute : THREE.Uint16Attribute )( indices, 1 ) );
  21978. this.addAttribute( 'position', positions );
  21979. this.addAttribute( 'normal', normals );
  21980. this.addAttribute( 'uv', uvs );
  21981. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  21982. };
  21983. THREE.SphereBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  21984. THREE.SphereBufferGeometry.prototype.constructor = THREE.SphereBufferGeometry;
  21985. // File:src/extras/geometries/TorusGeometry.js
  21986. /**
  21987. * @author oosmoxiecode
  21988. * @author mrdoob / http://mrdoob.com/
  21989. * based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3DLite/src/away3dlite/primitives/Torus.as?r=2888
  21990. */
  21991. THREE.TorusGeometry = function ( radius, tube, radialSegments, tubularSegments, arc ) {
  21992. THREE.Geometry.call( this );
  21993. this.type = 'TorusGeometry';
  21994. this.parameters = {
  21995. radius: radius,
  21996. tube: tube,
  21997. radialSegments: radialSegments,
  21998. tubularSegments: tubularSegments,
  21999. arc: arc
  22000. };
  22001. radius = radius || 100;
  22002. tube = tube || 40;
  22003. radialSegments = radialSegments || 8;
  22004. tubularSegments = tubularSegments || 6;
  22005. arc = arc || Math.PI * 2;
  22006. var center = new THREE.Vector3(), uvs = [], normals = [];
  22007. for ( var j = 0; j <= radialSegments; j ++ ) {
  22008. for ( var i = 0; i <= tubularSegments; i ++ ) {
  22009. var u = i / tubularSegments * arc;
  22010. var v = j / radialSegments * Math.PI * 2;
  22011. center.x = radius * Math.cos( u );
  22012. center.y = radius * Math.sin( u );
  22013. var vertex = new THREE.Vector3();
  22014. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  22015. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  22016. vertex.z = tube * Math.sin( v );
  22017. this.vertices.push( vertex );
  22018. uvs.push( new THREE.Vector2( i / tubularSegments, j / radialSegments ) );
  22019. normals.push( vertex.clone().sub( center ).normalize() );
  22020. }
  22021. }
  22022. for ( var j = 1; j <= radialSegments; j ++ ) {
  22023. for ( var i = 1; i <= tubularSegments; i ++ ) {
  22024. var a = ( tubularSegments + 1 ) * j + i - 1;
  22025. var b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  22026. var c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  22027. var d = ( tubularSegments + 1 ) * j + i;
  22028. var face = new THREE.Face3( a, b, d, [ normals[ a ].clone(), normals[ b ].clone(), normals[ d ].clone() ] );
  22029. this.faces.push( face );
  22030. this.faceVertexUvs[ 0 ].push( [ uvs[ a ].clone(), uvs[ b ].clone(), uvs[ d ].clone() ] );
  22031. face = new THREE.Face3( b, c, d, [ normals[ b ].clone(), normals[ c ].clone(), normals[ d ].clone() ] );
  22032. this.faces.push( face );
  22033. this.faceVertexUvs[ 0 ].push( [ uvs[ b ].clone(), uvs[ c ].clone(), uvs[ d ].clone() ] );
  22034. }
  22035. }
  22036. this.computeFaceNormals();
  22037. };
  22038. THREE.TorusGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22039. THREE.TorusGeometry.prototype.constructor = THREE.TorusGeometry;
  22040. // File:src/extras/geometries/TorusKnotGeometry.js
  22041. /**
  22042. * @author oosmoxiecode
  22043. * based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3D/src/away3d/primitives/TorusKnot.as?spec=svn2473&r=2473
  22044. */
  22045. THREE.TorusKnotGeometry = function ( radius, tube, radialSegments, tubularSegments, p, q, heightScale ) {
  22046. THREE.Geometry.call( this );
  22047. this.type = 'TorusKnotGeometry';
  22048. this.parameters = {
  22049. radius: radius,
  22050. tube: tube,
  22051. radialSegments: radialSegments,
  22052. tubularSegments: tubularSegments,
  22053. p: p,
  22054. q: q,
  22055. heightScale: heightScale
  22056. };
  22057. radius = radius || 100;
  22058. tube = tube || 40;
  22059. radialSegments = radialSegments || 64;
  22060. tubularSegments = tubularSegments || 8;
  22061. p = p || 2;
  22062. q = q || 3;
  22063. heightScale = heightScale || 1;
  22064. var grid = new Array( radialSegments );
  22065. var tang = new THREE.Vector3();
  22066. var n = new THREE.Vector3();
  22067. var bitan = new THREE.Vector3();
  22068. for ( var i = 0; i < radialSegments; ++ i ) {
  22069. grid[ i ] = new Array( tubularSegments );
  22070. var u = i / radialSegments * 2 * p * Math.PI;
  22071. var p1 = getPos( u, q, p, radius, heightScale );
  22072. var p2 = getPos( u + 0.01, q, p, radius, heightScale );
  22073. tang.subVectors( p2, p1 );
  22074. n.addVectors( p2, p1 );
  22075. bitan.crossVectors( tang, n );
  22076. n.crossVectors( bitan, tang );
  22077. bitan.normalize();
  22078. n.normalize();
  22079. for ( var j = 0; j < tubularSegments; ++ j ) {
  22080. var v = j / tubularSegments * 2 * Math.PI;
  22081. var cx = - tube * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
  22082. var cy = tube * Math.sin( v );
  22083. var pos = new THREE.Vector3();
  22084. pos.x = p1.x + cx * n.x + cy * bitan.x;
  22085. pos.y = p1.y + cx * n.y + cy * bitan.y;
  22086. pos.z = p1.z + cx * n.z + cy * bitan.z;
  22087. grid[ i ][ j ] = this.vertices.push( pos ) - 1;
  22088. }
  22089. }
  22090. for ( var i = 0; i < radialSegments; ++ i ) {
  22091. for ( var j = 0; j < tubularSegments; ++ j ) {
  22092. var ip = ( i + 1 ) % radialSegments;
  22093. var jp = ( j + 1 ) % tubularSegments;
  22094. var a = grid[ i ][ j ];
  22095. var b = grid[ ip ][ j ];
  22096. var c = grid[ ip ][ jp ];
  22097. var d = grid[ i ][ jp ];
  22098. var uva = new THREE.Vector2( i / radialSegments, j / tubularSegments );
  22099. var uvb = new THREE.Vector2( ( i + 1 ) / radialSegments, j / tubularSegments );
  22100. var uvc = new THREE.Vector2( ( i + 1 ) / radialSegments, ( j + 1 ) / tubularSegments );
  22101. var uvd = new THREE.Vector2( i / radialSegments, ( j + 1 ) / tubularSegments );
  22102. this.faces.push( new THREE.Face3( a, b, d ) );
  22103. this.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  22104. this.faces.push( new THREE.Face3( b, c, d ) );
  22105. this.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  22106. }
  22107. }
  22108. this.computeFaceNormals();
  22109. this.computeVertexNormals();
  22110. function getPos( u, in_q, in_p, radius, heightScale ) {
  22111. var cu = Math.cos( u );
  22112. var su = Math.sin( u );
  22113. var quOverP = in_q / in_p * u;
  22114. var cs = Math.cos( quOverP );
  22115. var tx = radius * ( 2 + cs ) * 0.5 * cu;
  22116. var ty = radius * ( 2 + cs ) * su * 0.5;
  22117. var tz = heightScale * radius * Math.sin( quOverP ) * 0.5;
  22118. return new THREE.Vector3( tx, ty, tz );
  22119. }
  22120. };
  22121. THREE.TorusKnotGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22122. THREE.TorusKnotGeometry.prototype.constructor = THREE.TorusKnotGeometry;
  22123. // File:src/extras/geometries/TubeGeometry.js
  22124. /**
  22125. * @author WestLangley / https://github.com/WestLangley
  22126. * @author zz85 / https://github.com/zz85
  22127. * @author miningold / https://github.com/miningold
  22128. * @author jonobr1 / https://github.com/jonobr1
  22129. *
  22130. * Modified from the TorusKnotGeometry by @oosmoxiecode
  22131. *
  22132. * Creates a tube which extrudes along a 3d spline
  22133. *
  22134. * Uses parallel transport frames as described in
  22135. * http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  22136. */
  22137. THREE.TubeGeometry = function ( path, segments, radius, radialSegments, closed, taper ) {
  22138. THREE.Geometry.call( this );
  22139. this.type = 'TubeGeometry';
  22140. this.parameters = {
  22141. path: path,
  22142. segments: segments,
  22143. radius: radius,
  22144. radialSegments: radialSegments,
  22145. closed: closed,
  22146. taper: taper
  22147. };
  22148. segments = segments || 64;
  22149. radius = radius || 1;
  22150. radialSegments = radialSegments || 8;
  22151. closed = closed || false;
  22152. taper = taper || THREE.TubeGeometry.NoTaper;
  22153. var grid = [];
  22154. var scope = this,
  22155. tangent,
  22156. normal,
  22157. binormal,
  22158. numpoints = segments + 1,
  22159. u, v, r,
  22160. cx, cy,
  22161. pos, pos2 = new THREE.Vector3(),
  22162. i, j,
  22163. ip, jp,
  22164. a, b, c, d,
  22165. uva, uvb, uvc, uvd;
  22166. var frames = new THREE.TubeGeometry.FrenetFrames( path, segments, closed ),
  22167. tangents = frames.tangents,
  22168. normals = frames.normals,
  22169. binormals = frames.binormals;
  22170. // proxy internals
  22171. this.tangents = tangents;
  22172. this.normals = normals;
  22173. this.binormals = binormals;
  22174. function vert( x, y, z ) {
  22175. return scope.vertices.push( new THREE.Vector3( x, y, z ) ) - 1;
  22176. }
  22177. // construct the grid
  22178. for ( i = 0; i < numpoints; i ++ ) {
  22179. grid[ i ] = [];
  22180. u = i / ( numpoints - 1 );
  22181. pos = path.getPointAt( u );
  22182. tangent = tangents[ i ];
  22183. normal = normals[ i ];
  22184. binormal = binormals[ i ];
  22185. r = radius * taper( u );
  22186. for ( j = 0; j < radialSegments; j ++ ) {
  22187. v = j / radialSegments * 2 * Math.PI;
  22188. cx = - r * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
  22189. cy = r * Math.sin( v );
  22190. pos2.copy( pos );
  22191. pos2.x += cx * normal.x + cy * binormal.x;
  22192. pos2.y += cx * normal.y + cy * binormal.y;
  22193. pos2.z += cx * normal.z + cy * binormal.z;
  22194. grid[ i ][ j ] = vert( pos2.x, pos2.y, pos2.z );
  22195. }
  22196. }
  22197. // construct the mesh
  22198. for ( i = 0; i < segments; i ++ ) {
  22199. for ( j = 0; j < radialSegments; j ++ ) {
  22200. ip = ( closed ) ? ( i + 1 ) % segments : i + 1;
  22201. jp = ( j + 1 ) % radialSegments;
  22202. a = grid[ i ][ j ]; // *** NOT NECESSARILY PLANAR ! ***
  22203. b = grid[ ip ][ j ];
  22204. c = grid[ ip ][ jp ];
  22205. d = grid[ i ][ jp ];
  22206. uva = new THREE.Vector2( i / segments, j / radialSegments );
  22207. uvb = new THREE.Vector2( ( i + 1 ) / segments, j / radialSegments );
  22208. uvc = new THREE.Vector2( ( i + 1 ) / segments, ( j + 1 ) / radialSegments );
  22209. uvd = new THREE.Vector2( i / segments, ( j + 1 ) / radialSegments );
  22210. this.faces.push( new THREE.Face3( a, b, d ) );
  22211. this.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  22212. this.faces.push( new THREE.Face3( b, c, d ) );
  22213. this.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  22214. }
  22215. }
  22216. this.computeFaceNormals();
  22217. this.computeVertexNormals();
  22218. };
  22219. THREE.TubeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22220. THREE.TubeGeometry.prototype.constructor = THREE.TubeGeometry;
  22221. THREE.TubeGeometry.NoTaper = function ( u ) {
  22222. return 1;
  22223. };
  22224. THREE.TubeGeometry.SinusoidalTaper = function ( u ) {
  22225. return Math.sin( Math.PI * u );
  22226. };
  22227. // For computing of Frenet frames, exposing the tangents, normals and binormals the spline
  22228. THREE.TubeGeometry.FrenetFrames = function ( path, segments, closed ) {
  22229. var normal = new THREE.Vector3(),
  22230. tangents = [],
  22231. normals = [],
  22232. binormals = [],
  22233. vec = new THREE.Vector3(),
  22234. mat = new THREE.Matrix4(),
  22235. numpoints = segments + 1,
  22236. theta,
  22237. smallest,
  22238. tx, ty, tz,
  22239. i, u;
  22240. // expose internals
  22241. this.tangents = tangents;
  22242. this.normals = normals;
  22243. this.binormals = binormals;
  22244. // compute the tangent vectors for each segment on the path
  22245. for ( i = 0; i < numpoints; i ++ ) {
  22246. u = i / ( numpoints - 1 );
  22247. tangents[ i ] = path.getTangentAt( u );
  22248. tangents[ i ].normalize();
  22249. }
  22250. initialNormal3();
  22251. /*
  22252. function initialNormal1(lastBinormal) {
  22253. // fixed start binormal. Has dangers of 0 vectors
  22254. normals[ 0 ] = new THREE.Vector3();
  22255. binormals[ 0 ] = new THREE.Vector3();
  22256. if (lastBinormal===undefined) lastBinormal = new THREE.Vector3( 0, 0, 1 );
  22257. normals[ 0 ].crossVectors( lastBinormal, tangents[ 0 ] ).normalize();
  22258. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] ).normalize();
  22259. }
  22260. function initialNormal2() {
  22261. // This uses the Frenet-Serret formula for deriving binormal
  22262. var t2 = path.getTangentAt( epsilon );
  22263. normals[ 0 ] = new THREE.Vector3().subVectors( t2, tangents[ 0 ] ).normalize();
  22264. binormals[ 0 ] = new THREE.Vector3().crossVectors( tangents[ 0 ], normals[ 0 ] );
  22265. normals[ 0 ].crossVectors( binormals[ 0 ], tangents[ 0 ] ).normalize(); // last binormal x tangent
  22266. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] ).normalize();
  22267. }
  22268. */
  22269. function initialNormal3() {
  22270. // select an initial normal vector perpendicular to the first tangent vector,
  22271. // and in the direction of the smallest tangent xyz component
  22272. normals[ 0 ] = new THREE.Vector3();
  22273. binormals[ 0 ] = new THREE.Vector3();
  22274. smallest = Number.MAX_VALUE;
  22275. tx = Math.abs( tangents[ 0 ].x );
  22276. ty = Math.abs( tangents[ 0 ].y );
  22277. tz = Math.abs( tangents[ 0 ].z );
  22278. if ( tx <= smallest ) {
  22279. smallest = tx;
  22280. normal.set( 1, 0, 0 );
  22281. }
  22282. if ( ty <= smallest ) {
  22283. smallest = ty;
  22284. normal.set( 0, 1, 0 );
  22285. }
  22286. if ( tz <= smallest ) {
  22287. normal.set( 0, 0, 1 );
  22288. }
  22289. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  22290. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  22291. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  22292. }
  22293. // compute the slowly-varying normal and binormal vectors for each segment on the path
  22294. for ( i = 1; i < numpoints; i ++ ) {
  22295. normals[ i ] = normals[ i - 1 ].clone();
  22296. binormals[ i ] = binormals[ i - 1 ].clone();
  22297. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  22298. if ( vec.length() > Number.EPSILON ) {
  22299. vec.normalize();
  22300. theta = Math.acos( THREE.Math.clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  22301. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  22302. }
  22303. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  22304. }
  22305. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  22306. if ( closed ) {
  22307. theta = Math.acos( THREE.Math.clamp( normals[ 0 ].dot( normals[ numpoints - 1 ] ), - 1, 1 ) );
  22308. theta /= ( numpoints - 1 );
  22309. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ numpoints - 1 ] ) ) > 0 ) {
  22310. theta = - theta;
  22311. }
  22312. for ( i = 1; i < numpoints; i ++ ) {
  22313. // twist a little...
  22314. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  22315. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  22316. }
  22317. }
  22318. };
  22319. // File:src/extras/geometries/PolyhedronGeometry.js
  22320. /**
  22321. * @author clockworkgeek / https://github.com/clockworkgeek
  22322. * @author timothypratley / https://github.com/timothypratley
  22323. * @author WestLangley / http://github.com/WestLangley
  22324. */
  22325. THREE.PolyhedronGeometry = function ( vertices, indices, radius, detail ) {
  22326. THREE.Geometry.call( this );
  22327. this.type = 'PolyhedronGeometry';
  22328. this.parameters = {
  22329. vertices: vertices,
  22330. indices: indices,
  22331. radius: radius,
  22332. detail: detail
  22333. };
  22334. radius = radius || 1;
  22335. detail = detail || 0;
  22336. var that = this;
  22337. for ( var i = 0, l = vertices.length; i < l; i += 3 ) {
  22338. prepare( new THREE.Vector3( vertices[ i ], vertices[ i + 1 ], vertices[ i + 2 ] ) );
  22339. }
  22340. var p = this.vertices;
  22341. var faces = [];
  22342. for ( var i = 0, j = 0, l = indices.length; i < l; i += 3, j ++ ) {
  22343. var v1 = p[ indices[ i ] ];
  22344. var v2 = p[ indices[ i + 1 ] ];
  22345. var v3 = p[ indices[ i + 2 ] ];
  22346. faces[ j ] = new THREE.Face3( v1.index, v2.index, v3.index, [ v1.clone(), v2.clone(), v3.clone() ], undefined, j );
  22347. }
  22348. var centroid = new THREE.Vector3();
  22349. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  22350. subdivide( faces[ i ], detail );
  22351. }
  22352. // Handle case when face straddles the seam
  22353. for ( var i = 0, l = this.faceVertexUvs[ 0 ].length; i < l; i ++ ) {
  22354. var uvs = this.faceVertexUvs[ 0 ][ i ];
  22355. var x0 = uvs[ 0 ].x;
  22356. var x1 = uvs[ 1 ].x;
  22357. var x2 = uvs[ 2 ].x;
  22358. var max = Math.max( x0, x1, x2 );
  22359. var min = Math.min( x0, x1, x2 );
  22360. if ( max > 0.9 && min < 0.1 ) {
  22361. // 0.9 is somewhat arbitrary
  22362. if ( x0 < 0.2 ) uvs[ 0 ].x += 1;
  22363. if ( x1 < 0.2 ) uvs[ 1 ].x += 1;
  22364. if ( x2 < 0.2 ) uvs[ 2 ].x += 1;
  22365. }
  22366. }
  22367. // Apply radius
  22368. for ( var i = 0, l = this.vertices.length; i < l; i ++ ) {
  22369. this.vertices[ i ].multiplyScalar( radius );
  22370. }
  22371. // Merge vertices
  22372. this.mergeVertices();
  22373. this.computeFaceNormals();
  22374. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  22375. // Project vector onto sphere's surface
  22376. function prepare( vector ) {
  22377. var vertex = vector.normalize().clone();
  22378. vertex.index = that.vertices.push( vertex ) - 1;
  22379. // Texture coords are equivalent to map coords, calculate angle and convert to fraction of a circle.
  22380. var u = azimuth( vector ) / 2 / Math.PI + 0.5;
  22381. var v = inclination( vector ) / Math.PI + 0.5;
  22382. vertex.uv = new THREE.Vector2( u, 1 - v );
  22383. return vertex;
  22384. }
  22385. // Approximate a curved face with recursively sub-divided triangles.
  22386. function make( v1, v2, v3, materialIndex ) {
  22387. var face = new THREE.Face3( v1.index, v2.index, v3.index, [ v1.clone(), v2.clone(), v3.clone() ], undefined, materialIndex );
  22388. that.faces.push( face );
  22389. centroid.copy( v1 ).add( v2 ).add( v3 ).divideScalar( 3 );
  22390. var azi = azimuth( centroid );
  22391. that.faceVertexUvs[ 0 ].push( [
  22392. correctUV( v1.uv, v1, azi ),
  22393. correctUV( v2.uv, v2, azi ),
  22394. correctUV( v3.uv, v3, azi )
  22395. ] );
  22396. }
  22397. // Analytically subdivide a face to the required detail level.
  22398. function subdivide( face, detail ) {
  22399. var cols = Math.pow( 2, detail );
  22400. var a = prepare( that.vertices[ face.a ] );
  22401. var b = prepare( that.vertices[ face.b ] );
  22402. var c = prepare( that.vertices[ face.c ] );
  22403. var v = [];
  22404. var materialIndex = face.materialIndex;
  22405. // Construct all of the vertices for this subdivision.
  22406. for ( var i = 0 ; i <= cols; i ++ ) {
  22407. v[ i ] = [];
  22408. var aj = prepare( a.clone().lerp( c, i / cols ) );
  22409. var bj = prepare( b.clone().lerp( c, i / cols ) );
  22410. var rows = cols - i;
  22411. for ( var j = 0; j <= rows; j ++ ) {
  22412. if ( j === 0 && i === cols ) {
  22413. v[ i ][ j ] = aj;
  22414. } else {
  22415. v[ i ][ j ] = prepare( aj.clone().lerp( bj, j / rows ) );
  22416. }
  22417. }
  22418. }
  22419. // Construct all of the faces.
  22420. for ( var i = 0; i < cols ; i ++ ) {
  22421. for ( var j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
  22422. var k = Math.floor( j / 2 );
  22423. if ( j % 2 === 0 ) {
  22424. make(
  22425. v[ i ][ k + 1 ],
  22426. v[ i + 1 ][ k ],
  22427. v[ i ][ k ],
  22428. materialIndex
  22429. );
  22430. } else {
  22431. make(
  22432. v[ i ][ k + 1 ],
  22433. v[ i + 1 ][ k + 1 ],
  22434. v[ i + 1 ][ k ],
  22435. materialIndex
  22436. );
  22437. }
  22438. }
  22439. }
  22440. }
  22441. // Angle around the Y axis, counter-clockwise when looking from above.
  22442. function azimuth( vector ) {
  22443. return Math.atan2( vector.z, - vector.x );
  22444. }
  22445. // Angle above the XZ plane.
  22446. function inclination( vector ) {
  22447. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  22448. }
  22449. // Texture fixing helper. Spheres have some odd behaviours.
  22450. function correctUV( uv, vector, azimuth ) {
  22451. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) uv = new THREE.Vector2( uv.x - 1, uv.y );
  22452. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) uv = new THREE.Vector2( azimuth / 2 / Math.PI + 0.5, uv.y );
  22453. return uv.clone();
  22454. }
  22455. };
  22456. THREE.PolyhedronGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22457. THREE.PolyhedronGeometry.prototype.constructor = THREE.PolyhedronGeometry;
  22458. // File:src/extras/geometries/DodecahedronGeometry.js
  22459. /**
  22460. * @author Abe Pazos / https://hamoid.com
  22461. */
  22462. THREE.DodecahedronGeometry = function ( radius, detail ) {
  22463. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  22464. var r = 1 / t;
  22465. var vertices = [
  22466. // (±1, ±1, ±1)
  22467. - 1, - 1, - 1, - 1, - 1, 1,
  22468. - 1, 1, - 1, - 1, 1, 1,
  22469. 1, - 1, - 1, 1, - 1, 1,
  22470. 1, 1, - 1, 1, 1, 1,
  22471. // (0, ±1/φ, ±φ)
  22472. 0, - r, - t, 0, - r, t,
  22473. 0, r, - t, 0, r, t,
  22474. // (±1/φ, ±φ, 0)
  22475. - r, - t, 0, - r, t, 0,
  22476. r, - t, 0, r, t, 0,
  22477. // (±φ, 0, ±1/φ)
  22478. - t, 0, - r, t, 0, - r,
  22479. - t, 0, r, t, 0, r
  22480. ];
  22481. var indices = [
  22482. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  22483. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  22484. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  22485. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  22486. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  22487. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  22488. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  22489. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  22490. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  22491. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  22492. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  22493. 1, 12, 14, 1, 14, 5, 1, 5, 9
  22494. ];
  22495. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  22496. this.type = 'DodecahedronGeometry';
  22497. this.parameters = {
  22498. radius: radius,
  22499. detail: detail
  22500. };
  22501. };
  22502. THREE.DodecahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  22503. THREE.DodecahedronGeometry.prototype.constructor = THREE.DodecahedronGeometry;
  22504. // File:src/extras/geometries/IcosahedronGeometry.js
  22505. /**
  22506. * @author timothypratley / https://github.com/timothypratley
  22507. */
  22508. THREE.IcosahedronGeometry = function ( radius, detail ) {
  22509. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  22510. var vertices = [
  22511. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  22512. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  22513. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  22514. ];
  22515. var indices = [
  22516. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  22517. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  22518. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  22519. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  22520. ];
  22521. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  22522. this.type = 'IcosahedronGeometry';
  22523. this.parameters = {
  22524. radius: radius,
  22525. detail: detail
  22526. };
  22527. };
  22528. THREE.IcosahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  22529. THREE.IcosahedronGeometry.prototype.constructor = THREE.IcosahedronGeometry;
  22530. // File:src/extras/geometries/OctahedronGeometry.js
  22531. /**
  22532. * @author timothypratley / https://github.com/timothypratley
  22533. */
  22534. THREE.OctahedronGeometry = function ( radius, detail ) {
  22535. var vertices = [
  22536. 1, 0, 0, - 1, 0, 0, 0, 1, 0, 0, - 1, 0, 0, 0, 1, 0, 0, - 1
  22537. ];
  22538. var indices = [
  22539. 0, 2, 4, 0, 4, 3, 0, 3, 5, 0, 5, 2, 1, 2, 5, 1, 5, 3, 1, 3, 4, 1, 4, 2
  22540. ];
  22541. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  22542. this.type = 'OctahedronGeometry';
  22543. this.parameters = {
  22544. radius: radius,
  22545. detail: detail
  22546. };
  22547. };
  22548. THREE.OctahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  22549. THREE.OctahedronGeometry.prototype.constructor = THREE.OctahedronGeometry;
  22550. // File:src/extras/geometries/TetrahedronGeometry.js
  22551. /**
  22552. * @author timothypratley / https://github.com/timothypratley
  22553. */
  22554. THREE.TetrahedronGeometry = function ( radius, detail ) {
  22555. var vertices = [
  22556. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  22557. ];
  22558. var indices = [
  22559. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  22560. ];
  22561. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  22562. this.type = 'TetrahedronGeometry';
  22563. this.parameters = {
  22564. radius: radius,
  22565. detail: detail
  22566. };
  22567. };
  22568. THREE.TetrahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  22569. THREE.TetrahedronGeometry.prototype.constructor = THREE.TetrahedronGeometry;
  22570. // File:src/extras/geometries/ParametricGeometry.js
  22571. /**
  22572. * @author zz85 / https://github.com/zz85
  22573. * Parametric Surfaces Geometry
  22574. * based on the brilliant article by @prideout http://prideout.net/blog/?p=44
  22575. *
  22576. * new THREE.ParametricGeometry( parametricFunction, uSegments, ySegements );
  22577. *
  22578. */
  22579. THREE.ParametricGeometry = function ( func, slices, stacks ) {
  22580. THREE.Geometry.call( this );
  22581. this.type = 'ParametricGeometry';
  22582. this.parameters = {
  22583. func: func,
  22584. slices: slices,
  22585. stacks: stacks
  22586. };
  22587. var verts = this.vertices;
  22588. var faces = this.faces;
  22589. var uvs = this.faceVertexUvs[ 0 ];
  22590. var i, j, p;
  22591. var u, v;
  22592. var sliceCount = slices + 1;
  22593. for ( i = 0; i <= stacks; i ++ ) {
  22594. v = i / stacks;
  22595. for ( j = 0; j <= slices; j ++ ) {
  22596. u = j / slices;
  22597. p = func( u, v );
  22598. verts.push( p );
  22599. }
  22600. }
  22601. var a, b, c, d;
  22602. var uva, uvb, uvc, uvd;
  22603. for ( i = 0; i < stacks; i ++ ) {
  22604. for ( j = 0; j < slices; j ++ ) {
  22605. a = i * sliceCount + j;
  22606. b = i * sliceCount + j + 1;
  22607. c = ( i + 1 ) * sliceCount + j + 1;
  22608. d = ( i + 1 ) * sliceCount + j;
  22609. uva = new THREE.Vector2( j / slices, i / stacks );
  22610. uvb = new THREE.Vector2( ( j + 1 ) / slices, i / stacks );
  22611. uvc = new THREE.Vector2( ( j + 1 ) / slices, ( i + 1 ) / stacks );
  22612. uvd = new THREE.Vector2( j / slices, ( i + 1 ) / stacks );
  22613. faces.push( new THREE.Face3( a, b, d ) );
  22614. uvs.push( [ uva, uvb, uvd ] );
  22615. faces.push( new THREE.Face3( b, c, d ) );
  22616. uvs.push( [ uvb.clone(), uvc, uvd.clone() ] );
  22617. }
  22618. }
  22619. // console.log(this);
  22620. // magic bullet
  22621. // var diff = this.mergeVertices();
  22622. // console.log('removed ', diff, ' vertices by merging');
  22623. this.computeFaceNormals();
  22624. this.computeVertexNormals();
  22625. };
  22626. THREE.ParametricGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22627. THREE.ParametricGeometry.prototype.constructor = THREE.ParametricGeometry;
  22628. // File:src/extras/geometries/WireframeGeometry.js
  22629. /**
  22630. * @author mrdoob / http://mrdoob.com/
  22631. */
  22632. THREE.WireframeGeometry = function ( geometry ) {
  22633. THREE.BufferGeometry.call( this );
  22634. var edge = [ 0, 0 ], hash = {};
  22635. function sortFunction( a, b ) {
  22636. return a - b;
  22637. }
  22638. var keys = [ 'a', 'b', 'c' ];
  22639. if ( geometry instanceof THREE.Geometry ) {
  22640. var vertices = geometry.vertices;
  22641. var faces = geometry.faces;
  22642. var numEdges = 0;
  22643. // allocate maximal size
  22644. var edges = new Uint32Array( 6 * faces.length );
  22645. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  22646. var face = faces[ i ];
  22647. for ( var j = 0; j < 3; j ++ ) {
  22648. edge[ 0 ] = face[ keys[ j ] ];
  22649. edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
  22650. edge.sort( sortFunction );
  22651. var key = edge.toString();
  22652. if ( hash[ key ] === undefined ) {
  22653. edges[ 2 * numEdges ] = edge[ 0 ];
  22654. edges[ 2 * numEdges + 1 ] = edge[ 1 ];
  22655. hash[ key ] = true;
  22656. numEdges ++;
  22657. }
  22658. }
  22659. }
  22660. var coords = new Float32Array( numEdges * 2 * 3 );
  22661. for ( var i = 0, l = numEdges; i < l; i ++ ) {
  22662. for ( var j = 0; j < 2; j ++ ) {
  22663. var vertex = vertices[ edges [ 2 * i + j ] ];
  22664. var index = 6 * i + 3 * j;
  22665. coords[ index + 0 ] = vertex.x;
  22666. coords[ index + 1 ] = vertex.y;
  22667. coords[ index + 2 ] = vertex.z;
  22668. }
  22669. }
  22670. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  22671. } else if ( geometry instanceof THREE.BufferGeometry ) {
  22672. if ( geometry.index !== null ) {
  22673. // Indexed BufferGeometry
  22674. var indices = geometry.index.array;
  22675. var vertices = geometry.attributes.position;
  22676. var drawcalls = geometry.drawcalls;
  22677. var numEdges = 0;
  22678. if ( drawcalls.length === 0 ) {
  22679. geometry.addGroup( 0, indices.length );
  22680. }
  22681. // allocate maximal size
  22682. var edges = new Uint32Array( 2 * indices.length );
  22683. for ( var o = 0, ol = drawcalls.length; o < ol; ++ o ) {
  22684. var drawcall = drawcalls[ o ];
  22685. var start = drawcall.start;
  22686. var count = drawcall.count;
  22687. for ( var i = start, il = start + count; i < il; i += 3 ) {
  22688. for ( var j = 0; j < 3; j ++ ) {
  22689. edge[ 0 ] = indices[ i + j ];
  22690. edge[ 1 ] = indices[ i + ( j + 1 ) % 3 ];
  22691. edge.sort( sortFunction );
  22692. var key = edge.toString();
  22693. if ( hash[ key ] === undefined ) {
  22694. edges[ 2 * numEdges ] = edge[ 0 ];
  22695. edges[ 2 * numEdges + 1 ] = edge[ 1 ];
  22696. hash[ key ] = true;
  22697. numEdges ++;
  22698. }
  22699. }
  22700. }
  22701. }
  22702. var coords = new Float32Array( numEdges * 2 * 3 );
  22703. for ( var i = 0, l = numEdges; i < l; i ++ ) {
  22704. for ( var j = 0; j < 2; j ++ ) {
  22705. var index = 6 * i + 3 * j;
  22706. var index2 = edges[ 2 * i + j ];
  22707. coords[ index + 0 ] = vertices.getX( index2 );
  22708. coords[ index + 1 ] = vertices.getY( index2 );
  22709. coords[ index + 2 ] = vertices.getZ( index2 );
  22710. }
  22711. }
  22712. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  22713. } else {
  22714. // non-indexed BufferGeometry
  22715. var vertices = geometry.attributes.position.array;
  22716. var numEdges = vertices.length / 3;
  22717. var numTris = numEdges / 3;
  22718. var coords = new Float32Array( numEdges * 2 * 3 );
  22719. for ( var i = 0, l = numTris; i < l; i ++ ) {
  22720. for ( var j = 0; j < 3; j ++ ) {
  22721. var index = 18 * i + 6 * j;
  22722. var index1 = 9 * i + 3 * j;
  22723. coords[ index + 0 ] = vertices[ index1 ];
  22724. coords[ index + 1 ] = vertices[ index1 + 1 ];
  22725. coords[ index + 2 ] = vertices[ index1 + 2 ];
  22726. var index2 = 9 * i + 3 * ( ( j + 1 ) % 3 );
  22727. coords[ index + 3 ] = vertices[ index2 ];
  22728. coords[ index + 4 ] = vertices[ index2 + 1 ];
  22729. coords[ index + 5 ] = vertices[ index2 + 2 ];
  22730. }
  22731. }
  22732. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  22733. }
  22734. }
  22735. };
  22736. THREE.WireframeGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  22737. THREE.WireframeGeometry.prototype.constructor = THREE.WireframeGeometry;
  22738. // File:src/extras/helpers/AxisHelper.js
  22739. /**
  22740. * @author sroucheray / http://sroucheray.org/
  22741. * @author mrdoob / http://mrdoob.com/
  22742. */
  22743. THREE.AxisHelper = function ( size ) {
  22744. size = size || 1;
  22745. var vertices = new Float32Array( [
  22746. 0, 0, 0, size, 0, 0,
  22747. 0, 0, 0, 0, size, 0,
  22748. 0, 0, 0, 0, 0, size
  22749. ] );
  22750. var colors = new Float32Array( [
  22751. 1, 0, 0, 1, 0.6, 0,
  22752. 0, 1, 0, 0.6, 1, 0,
  22753. 0, 0, 1, 0, 0.6, 1
  22754. ] );
  22755. var geometry = new THREE.BufferGeometry();
  22756. geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  22757. geometry.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ) );
  22758. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
  22759. THREE.LineSegments.call( this, geometry, material );
  22760. };
  22761. THREE.AxisHelper.prototype = Object.create( THREE.LineSegments.prototype );
  22762. THREE.AxisHelper.prototype.constructor = THREE.AxisHelper;
  22763. // File:src/extras/helpers/ArrowHelper.js
  22764. /**
  22765. * @author WestLangley / http://github.com/WestLangley
  22766. * @author zz85 / http://github.com/zz85
  22767. * @author bhouston / http://clara.io
  22768. *
  22769. * Creates an arrow for visualizing directions
  22770. *
  22771. * Parameters:
  22772. * dir - Vector3
  22773. * origin - Vector3
  22774. * length - Number
  22775. * color - color in hex value
  22776. * headLength - Number
  22777. * headWidth - Number
  22778. */
  22779. THREE.ArrowHelper = ( function () {
  22780. var lineGeometry = new THREE.Geometry();
  22781. lineGeometry.vertices.push( new THREE.Vector3( 0, 0, 0 ), new THREE.Vector3( 0, 1, 0 ) );
  22782. var coneGeometry = new THREE.CylinderGeometry( 0, 0.5, 1, 5, 1 );
  22783. coneGeometry.translate( 0, - 0.5, 0 );
  22784. return function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
  22785. // dir is assumed to be normalized
  22786. THREE.Object3D.call( this );
  22787. if ( color === undefined ) color = 0xffff00;
  22788. if ( length === undefined ) length = 1;
  22789. if ( headLength === undefined ) headLength = 0.2 * length;
  22790. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  22791. this.position.copy( origin );
  22792. this.line = new THREE.Line( lineGeometry, new THREE.LineBasicMaterial( { color: color } ) );
  22793. this.line.matrixAutoUpdate = false;
  22794. this.add( this.line );
  22795. this.cone = new THREE.Mesh( coneGeometry, new THREE.MeshBasicMaterial( { color: color } ) );
  22796. this.cone.matrixAutoUpdate = false;
  22797. this.add( this.cone );
  22798. this.setDirection( dir );
  22799. this.setLength( length, headLength, headWidth );
  22800. }
  22801. }() );
  22802. THREE.ArrowHelper.prototype = Object.create( THREE.Object3D.prototype );
  22803. THREE.ArrowHelper.prototype.constructor = THREE.ArrowHelper;
  22804. THREE.ArrowHelper.prototype.setDirection = ( function () {
  22805. var axis = new THREE.Vector3();
  22806. var radians;
  22807. return function setDirection( dir ) {
  22808. // dir is assumed to be normalized
  22809. if ( dir.y > 0.99999 ) {
  22810. this.quaternion.set( 0, 0, 0, 1 );
  22811. } else if ( dir.y < - 0.99999 ) {
  22812. this.quaternion.set( 1, 0, 0, 0 );
  22813. } else {
  22814. axis.set( dir.z, 0, - dir.x ).normalize();
  22815. radians = Math.acos( dir.y );
  22816. this.quaternion.setFromAxisAngle( axis, radians );
  22817. }
  22818. };
  22819. }() );
  22820. THREE.ArrowHelper.prototype.setLength = function ( length, headLength, headWidth ) {
  22821. if ( headLength === undefined ) headLength = 0.2 * length;
  22822. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  22823. this.line.scale.set( 1, Math.max( 0, length - headLength ), 1 );
  22824. this.line.updateMatrix();
  22825. this.cone.scale.set( headWidth, headLength, headWidth );
  22826. this.cone.position.y = length;
  22827. this.cone.updateMatrix();
  22828. };
  22829. THREE.ArrowHelper.prototype.setColor = function ( color ) {
  22830. this.line.material.color.set( color );
  22831. this.cone.material.color.set( color );
  22832. };
  22833. // File:src/extras/helpers/BoxHelper.js
  22834. /**
  22835. * @author mrdoob / http://mrdoob.com/
  22836. */
  22837. THREE.BoxHelper = function ( object ) {
  22838. 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 ] );
  22839. var positions = new Float32Array( 8 * 3 );
  22840. var geometry = new THREE.BufferGeometry();
  22841. geometry.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  22842. geometry.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
  22843. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: 0xffff00 } ) );
  22844. if ( object !== undefined ) {
  22845. this.update( object );
  22846. }
  22847. };
  22848. THREE.BoxHelper.prototype = Object.create( THREE.LineSegments.prototype );
  22849. THREE.BoxHelper.prototype.constructor = THREE.BoxHelper;
  22850. THREE.BoxHelper.prototype.update = ( function () {
  22851. var box = new THREE.Box3();
  22852. return function ( object ) {
  22853. box.setFromObject( object );
  22854. if ( box.empty() ) return;
  22855. var min = box.min;
  22856. var max = box.max;
  22857. /*
  22858. 5____4
  22859. 1/___0/|
  22860. | 6__|_7
  22861. 2/___3/
  22862. 0: max.x, max.y, max.z
  22863. 1: min.x, max.y, max.z
  22864. 2: min.x, min.y, max.z
  22865. 3: max.x, min.y, max.z
  22866. 4: max.x, max.y, min.z
  22867. 5: min.x, max.y, min.z
  22868. 6: min.x, min.y, min.z
  22869. 7: max.x, min.y, min.z
  22870. */
  22871. var position = this.geometry.attributes.position;
  22872. var array = position.array;
  22873. array[ 0 ] = max.x; array[ 1 ] = max.y; array[ 2 ] = max.z;
  22874. array[ 3 ] = min.x; array[ 4 ] = max.y; array[ 5 ] = max.z;
  22875. array[ 6 ] = min.x; array[ 7 ] = min.y; array[ 8 ] = max.z;
  22876. array[ 9 ] = max.x; array[ 10 ] = min.y; array[ 11 ] = max.z;
  22877. array[ 12 ] = max.x; array[ 13 ] = max.y; array[ 14 ] = min.z;
  22878. array[ 15 ] = min.x; array[ 16 ] = max.y; array[ 17 ] = min.z;
  22879. array[ 18 ] = min.x; array[ 19 ] = min.y; array[ 20 ] = min.z;
  22880. array[ 21 ] = max.x; array[ 22 ] = min.y; array[ 23 ] = min.z;
  22881. position.needsUpdate = true;
  22882. this.geometry.computeBoundingSphere();
  22883. }
  22884. } )();
  22885. // File:src/extras/helpers/BoundingBoxHelper.js
  22886. /**
  22887. * @author WestLangley / http://github.com/WestLangley
  22888. */
  22889. // a helper to show the world-axis-aligned bounding box for an object
  22890. THREE.BoundingBoxHelper = function ( object, hex ) {
  22891. var color = ( hex !== undefined ) ? hex : 0x888888;
  22892. this.object = object;
  22893. this.box = new THREE.Box3();
  22894. THREE.Mesh.call( this, new THREE.BoxGeometry( 1, 1, 1 ), new THREE.MeshBasicMaterial( { color: color, wireframe: true } ) );
  22895. };
  22896. THREE.BoundingBoxHelper.prototype = Object.create( THREE.Mesh.prototype );
  22897. THREE.BoundingBoxHelper.prototype.constructor = THREE.BoundingBoxHelper;
  22898. THREE.BoundingBoxHelper.prototype.update = function () {
  22899. this.box.setFromObject( this.object );
  22900. this.box.size( this.scale );
  22901. this.box.center( this.position );
  22902. };
  22903. // File:src/extras/helpers/CameraHelper.js
  22904. /**
  22905. * @author alteredq / http://alteredqualia.com/
  22906. *
  22907. * - shows frustum, line of sight and up of the camera
  22908. * - suitable for fast updates
  22909. * - based on frustum visualization in lightgl.js shadowmap example
  22910. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  22911. */
  22912. THREE.CameraHelper = function ( camera ) {
  22913. var geometry = new THREE.Geometry();
  22914. var material = new THREE.LineBasicMaterial( { color: 0xffffff, vertexColors: THREE.FaceColors } );
  22915. var pointMap = {};
  22916. // colors
  22917. var hexFrustum = 0xffaa00;
  22918. var hexCone = 0xff0000;
  22919. var hexUp = 0x00aaff;
  22920. var hexTarget = 0xffffff;
  22921. var hexCross = 0x333333;
  22922. // near
  22923. addLine( "n1", "n2", hexFrustum );
  22924. addLine( "n2", "n4", hexFrustum );
  22925. addLine( "n4", "n3", hexFrustum );
  22926. addLine( "n3", "n1", hexFrustum );
  22927. // far
  22928. addLine( "f1", "f2", hexFrustum );
  22929. addLine( "f2", "f4", hexFrustum );
  22930. addLine( "f4", "f3", hexFrustum );
  22931. addLine( "f3", "f1", hexFrustum );
  22932. // sides
  22933. addLine( "n1", "f1", hexFrustum );
  22934. addLine( "n2", "f2", hexFrustum );
  22935. addLine( "n3", "f3", hexFrustum );
  22936. addLine( "n4", "f4", hexFrustum );
  22937. // cone
  22938. addLine( "p", "n1", hexCone );
  22939. addLine( "p", "n2", hexCone );
  22940. addLine( "p", "n3", hexCone );
  22941. addLine( "p", "n4", hexCone );
  22942. // up
  22943. addLine( "u1", "u2", hexUp );
  22944. addLine( "u2", "u3", hexUp );
  22945. addLine( "u3", "u1", hexUp );
  22946. // target
  22947. addLine( "c", "t", hexTarget );
  22948. addLine( "p", "c", hexCross );
  22949. // cross
  22950. addLine( "cn1", "cn2", hexCross );
  22951. addLine( "cn3", "cn4", hexCross );
  22952. addLine( "cf1", "cf2", hexCross );
  22953. addLine( "cf3", "cf4", hexCross );
  22954. function addLine( a, b, hex ) {
  22955. addPoint( a, hex );
  22956. addPoint( b, hex );
  22957. }
  22958. function addPoint( id, hex ) {
  22959. geometry.vertices.push( new THREE.Vector3() );
  22960. geometry.colors.push( new THREE.Color( hex ) );
  22961. if ( pointMap[ id ] === undefined ) {
  22962. pointMap[ id ] = [];
  22963. }
  22964. pointMap[ id ].push( geometry.vertices.length - 1 );
  22965. }
  22966. THREE.LineSegments.call( this, geometry, material );
  22967. this.camera = camera;
  22968. this.camera.updateProjectionMatrix();
  22969. this.matrix = camera.matrixWorld;
  22970. this.matrixAutoUpdate = false;
  22971. this.pointMap = pointMap;
  22972. this.update();
  22973. };
  22974. THREE.CameraHelper.prototype = Object.create( THREE.LineSegments.prototype );
  22975. THREE.CameraHelper.prototype.constructor = THREE.CameraHelper;
  22976. THREE.CameraHelper.prototype.update = function () {
  22977. var geometry, pointMap;
  22978. var vector = new THREE.Vector3();
  22979. var camera = new THREE.Camera();
  22980. function setPoint( point, x, y, z ) {
  22981. vector.set( x, y, z ).unproject( camera );
  22982. var points = pointMap[ point ];
  22983. if ( points !== undefined ) {
  22984. for ( var i = 0, il = points.length; i < il; i ++ ) {
  22985. geometry.vertices[ points[ i ] ].copy( vector );
  22986. }
  22987. }
  22988. }
  22989. return function () {
  22990. geometry = this.geometry;
  22991. pointMap = this.pointMap;
  22992. var w = 1, h = 1;
  22993. // we need just camera projection matrix
  22994. // world matrix must be identity
  22995. camera.projectionMatrix.copy( this.camera.projectionMatrix );
  22996. // center / target
  22997. setPoint( "c", 0, 0, - 1 );
  22998. setPoint( "t", 0, 0, 1 );
  22999. // near
  23000. setPoint( "n1", - w, - h, - 1 );
  23001. setPoint( "n2", w, - h, - 1 );
  23002. setPoint( "n3", - w, h, - 1 );
  23003. setPoint( "n4", w, h, - 1 );
  23004. // far
  23005. setPoint( "f1", - w, - h, 1 );
  23006. setPoint( "f2", w, - h, 1 );
  23007. setPoint( "f3", - w, h, 1 );
  23008. setPoint( "f4", w, h, 1 );
  23009. // up
  23010. setPoint( "u1", w * 0.7, h * 1.1, - 1 );
  23011. setPoint( "u2", - w * 0.7, h * 1.1, - 1 );
  23012. setPoint( "u3", 0, h * 2, - 1 );
  23013. // cross
  23014. setPoint( "cf1", - w, 0, 1 );
  23015. setPoint( "cf2", w, 0, 1 );
  23016. setPoint( "cf3", 0, - h, 1 );
  23017. setPoint( "cf4", 0, h, 1 );
  23018. setPoint( "cn1", - w, 0, - 1 );
  23019. setPoint( "cn2", w, 0, - 1 );
  23020. setPoint( "cn3", 0, - h, - 1 );
  23021. setPoint( "cn4", 0, h, - 1 );
  23022. geometry.verticesNeedUpdate = true;
  23023. };
  23024. }();
  23025. // File:src/extras/helpers/DirectionalLightHelper.js
  23026. /**
  23027. * @author alteredq / http://alteredqualia.com/
  23028. * @author mrdoob / http://mrdoob.com/
  23029. * @author WestLangley / http://github.com/WestLangley
  23030. */
  23031. THREE.DirectionalLightHelper = function ( light, size ) {
  23032. THREE.Object3D.call( this );
  23033. this.light = light;
  23034. this.light.updateMatrixWorld();
  23035. this.matrix = light.matrixWorld;
  23036. this.matrixAutoUpdate = false;
  23037. size = size || 1;
  23038. var geometry = new THREE.Geometry();
  23039. geometry.vertices.push(
  23040. new THREE.Vector3( - size, size, 0 ),
  23041. new THREE.Vector3( size, size, 0 ),
  23042. new THREE.Vector3( size, - size, 0 ),
  23043. new THREE.Vector3( - size, - size, 0 ),
  23044. new THREE.Vector3( - size, size, 0 )
  23045. );
  23046. var material = new THREE.LineBasicMaterial( { fog: false } );
  23047. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  23048. this.lightPlane = new THREE.Line( geometry, material );
  23049. this.add( this.lightPlane );
  23050. geometry = new THREE.Geometry();
  23051. geometry.vertices.push(
  23052. new THREE.Vector3(),
  23053. new THREE.Vector3()
  23054. );
  23055. material = new THREE.LineBasicMaterial( { fog: false } );
  23056. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  23057. this.targetLine = new THREE.Line( geometry, material );
  23058. this.add( this.targetLine );
  23059. this.update();
  23060. };
  23061. THREE.DirectionalLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  23062. THREE.DirectionalLightHelper.prototype.constructor = THREE.DirectionalLightHelper;
  23063. THREE.DirectionalLightHelper.prototype.dispose = function () {
  23064. this.lightPlane.geometry.dispose();
  23065. this.lightPlane.material.dispose();
  23066. this.targetLine.geometry.dispose();
  23067. this.targetLine.material.dispose();
  23068. };
  23069. THREE.DirectionalLightHelper.prototype.update = function () {
  23070. var v1 = new THREE.Vector3();
  23071. var v2 = new THREE.Vector3();
  23072. var v3 = new THREE.Vector3();
  23073. return function () {
  23074. v1.setFromMatrixPosition( this.light.matrixWorld );
  23075. v2.setFromMatrixPosition( this.light.target.matrixWorld );
  23076. v3.subVectors( v2, v1 );
  23077. this.lightPlane.lookAt( v3 );
  23078. this.lightPlane.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  23079. this.targetLine.geometry.vertices[ 1 ].copy( v3 );
  23080. this.targetLine.geometry.verticesNeedUpdate = true;
  23081. this.targetLine.material.color.copy( this.lightPlane.material.color );
  23082. };
  23083. }();
  23084. // File:src/extras/helpers/EdgesHelper.js
  23085. /**
  23086. * @author WestLangley / http://github.com/WestLangley
  23087. * @param object THREE.Mesh whose geometry will be used
  23088. * @param hex line color
  23089. * @param thresholdAngle the minimum angle (in degrees),
  23090. * between the face normals of adjacent faces,
  23091. * that is required to render an edge. A value of 10 means
  23092. * an edge is only rendered if the angle is at least 10 degrees.
  23093. */
  23094. THREE.EdgesHelper = function ( object, hex, thresholdAngle ) {
  23095. var color = ( hex !== undefined ) ? hex : 0xffffff;
  23096. THREE.LineSegments.call( this, new THREE.EdgesGeometry( object.geometry, thresholdAngle ), new THREE.LineBasicMaterial( { color: color } ) );
  23097. this.matrix = object.matrixWorld;
  23098. this.matrixAutoUpdate = false;
  23099. };
  23100. THREE.EdgesHelper.prototype = Object.create( THREE.LineSegments.prototype );
  23101. THREE.EdgesHelper.prototype.constructor = THREE.EdgesHelper;
  23102. // File:src/extras/helpers/FaceNormalsHelper.js
  23103. /**
  23104. * @author mrdoob / http://mrdoob.com/
  23105. * @author WestLangley / http://github.com/WestLangley
  23106. */
  23107. THREE.FaceNormalsHelper = function ( object, size, hex, linewidth ) {
  23108. // FaceNormalsHelper only supports THREE.Geometry
  23109. this.object = object;
  23110. this.size = ( size !== undefined ) ? size : 1;
  23111. var color = ( hex !== undefined ) ? hex : 0xffff00;
  23112. var width = ( linewidth !== undefined ) ? linewidth : 1;
  23113. //
  23114. var nNormals = 0;
  23115. var objGeometry = this.object.geometry;
  23116. if ( objGeometry instanceof THREE.Geometry ) {
  23117. nNormals = objGeometry.faces.length;
  23118. } else {
  23119. console.warn( 'THREE.FaceNormalsHelper: only THREE.Geometry is supported. Use THREE.VertexNormalsHelper, instead.' );
  23120. }
  23121. //
  23122. var geometry = new THREE.BufferGeometry();
  23123. var positions = new THREE.Float32Attribute( nNormals * 2 * 3, 3 );
  23124. geometry.addAttribute( 'position', positions );
  23125. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  23126. //
  23127. this.matrixAutoUpdate = false;
  23128. this.update();
  23129. };
  23130. THREE.FaceNormalsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  23131. THREE.FaceNormalsHelper.prototype.constructor = THREE.FaceNormalsHelper;
  23132. THREE.FaceNormalsHelper.prototype.update = ( function () {
  23133. var v1 = new THREE.Vector3();
  23134. var v2 = new THREE.Vector3();
  23135. var normalMatrix = new THREE.Matrix3();
  23136. return function update() {
  23137. this.object.updateMatrixWorld( true );
  23138. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  23139. var matrixWorld = this.object.matrixWorld;
  23140. var position = this.geometry.attributes.position;
  23141. //
  23142. var objGeometry = this.object.geometry;
  23143. var vertices = objGeometry.vertices;
  23144. var faces = objGeometry.faces;
  23145. var idx = 0;
  23146. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  23147. var face = faces[ i ];
  23148. var normal = face.normal;
  23149. v1.copy( vertices[ face.a ] )
  23150. .add( vertices[ face.b ] )
  23151. .add( vertices[ face.c ] )
  23152. .divideScalar( 3 )
  23153. .applyMatrix4( matrixWorld );
  23154. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  23155. position.setXYZ( idx, v1.x, v1.y, v1.z );
  23156. idx = idx + 1;
  23157. position.setXYZ( idx, v2.x, v2.y, v2.z );
  23158. idx = idx + 1;
  23159. }
  23160. position.needsUpdate = true;
  23161. return this;
  23162. }
  23163. }() );
  23164. // File:src/extras/helpers/GridHelper.js
  23165. /**
  23166. * @author mrdoob / http://mrdoob.com/
  23167. */
  23168. THREE.GridHelper = function ( size, step ) {
  23169. var geometry = new THREE.Geometry();
  23170. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
  23171. this.color1 = new THREE.Color( 0x444444 );
  23172. this.color2 = new THREE.Color( 0x888888 );
  23173. for ( var i = - size; i <= size; i += step ) {
  23174. geometry.vertices.push(
  23175. new THREE.Vector3( - size, 0, i ), new THREE.Vector3( size, 0, i ),
  23176. new THREE.Vector3( i, 0, - size ), new THREE.Vector3( i, 0, size )
  23177. );
  23178. var color = i === 0 ? this.color1 : this.color2;
  23179. geometry.colors.push( color, color, color, color );
  23180. }
  23181. THREE.LineSegments.call( this, geometry, material );
  23182. };
  23183. THREE.GridHelper.prototype = Object.create( THREE.LineSegments.prototype );
  23184. THREE.GridHelper.prototype.constructor = THREE.GridHelper;
  23185. THREE.GridHelper.prototype.setColors = function( colorCenterLine, colorGrid ) {
  23186. this.color1.set( colorCenterLine );
  23187. this.color2.set( colorGrid );
  23188. this.geometry.colorsNeedUpdate = true;
  23189. };
  23190. // File:src/extras/helpers/HemisphereLightHelper.js
  23191. /**
  23192. * @author alteredq / http://alteredqualia.com/
  23193. * @author mrdoob / http://mrdoob.com/
  23194. */
  23195. THREE.HemisphereLightHelper = function ( light, sphereSize ) {
  23196. THREE.Object3D.call( this );
  23197. this.light = light;
  23198. this.light.updateMatrixWorld();
  23199. this.matrix = light.matrixWorld;
  23200. this.matrixAutoUpdate = false;
  23201. this.colors = [ new THREE.Color(), new THREE.Color() ];
  23202. var geometry = new THREE.SphereGeometry( sphereSize, 4, 2 );
  23203. geometry.rotateX( - Math.PI / 2 );
  23204. for ( var i = 0, il = 8; i < il; i ++ ) {
  23205. geometry.faces[ i ].color = this.colors[ i < 4 ? 0 : 1 ];
  23206. }
  23207. var material = new THREE.MeshBasicMaterial( { vertexColors: THREE.FaceColors, wireframe: true } );
  23208. this.lightSphere = new THREE.Mesh( geometry, material );
  23209. this.add( this.lightSphere );
  23210. this.update();
  23211. };
  23212. THREE.HemisphereLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  23213. THREE.HemisphereLightHelper.prototype.constructor = THREE.HemisphereLightHelper;
  23214. THREE.HemisphereLightHelper.prototype.dispose = function () {
  23215. this.lightSphere.geometry.dispose();
  23216. this.lightSphere.material.dispose();
  23217. };
  23218. THREE.HemisphereLightHelper.prototype.update = function () {
  23219. var vector = new THREE.Vector3();
  23220. return function () {
  23221. this.colors[ 0 ].copy( this.light.color ).multiplyScalar( this.light.intensity );
  23222. this.colors[ 1 ].copy( this.light.groundColor ).multiplyScalar( this.light.intensity );
  23223. this.lightSphere.lookAt( vector.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  23224. this.lightSphere.geometry.colorsNeedUpdate = true;
  23225. }
  23226. }();
  23227. // File:src/extras/helpers/PointLightHelper.js
  23228. /**
  23229. * @author alteredq / http://alteredqualia.com/
  23230. * @author mrdoob / http://mrdoob.com/
  23231. */
  23232. THREE.PointLightHelper = function ( light, sphereSize ) {
  23233. this.light = light;
  23234. this.light.updateMatrixWorld();
  23235. var geometry = new THREE.SphereGeometry( sphereSize, 4, 2 );
  23236. var material = new THREE.MeshBasicMaterial( { wireframe: true, fog: false } );
  23237. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  23238. THREE.Mesh.call( this, geometry, material );
  23239. this.matrix = this.light.matrixWorld;
  23240. this.matrixAutoUpdate = false;
  23241. /*
  23242. var distanceGeometry = new THREE.IcosahedronGeometry( 1, 2 );
  23243. var distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  23244. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  23245. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  23246. var d = light.distance;
  23247. if ( d === 0.0 ) {
  23248. this.lightDistance.visible = false;
  23249. } else {
  23250. this.lightDistance.scale.set( d, d, d );
  23251. }
  23252. this.add( this.lightDistance );
  23253. */
  23254. };
  23255. THREE.PointLightHelper.prototype = Object.create( THREE.Mesh.prototype );
  23256. THREE.PointLightHelper.prototype.constructor = THREE.PointLightHelper;
  23257. THREE.PointLightHelper.prototype.dispose = function () {
  23258. this.geometry.dispose();
  23259. this.material.dispose();
  23260. };
  23261. THREE.PointLightHelper.prototype.update = function () {
  23262. this.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  23263. /*
  23264. var d = this.light.distance;
  23265. if ( d === 0.0 ) {
  23266. this.lightDistance.visible = false;
  23267. } else {
  23268. this.lightDistance.visible = true;
  23269. this.lightDistance.scale.set( d, d, d );
  23270. }
  23271. */
  23272. };
  23273. // File:src/extras/helpers/SkeletonHelper.js
  23274. /**
  23275. * @author Sean Griffin / http://twitter.com/sgrif
  23276. * @author Michael Guerrero / http://realitymeltdown.com
  23277. * @author mrdoob / http://mrdoob.com/
  23278. * @author ikerr / http://verold.com
  23279. */
  23280. THREE.SkeletonHelper = function ( object ) {
  23281. this.bones = this.getBoneList( object );
  23282. var geometry = new THREE.Geometry();
  23283. for ( var i = 0; i < this.bones.length; i ++ ) {
  23284. var bone = this.bones[ i ];
  23285. if ( bone.parent instanceof THREE.Bone ) {
  23286. geometry.vertices.push( new THREE.Vector3() );
  23287. geometry.vertices.push( new THREE.Vector3() );
  23288. geometry.colors.push( new THREE.Color( 0, 0, 1 ) );
  23289. geometry.colors.push( new THREE.Color( 0, 1, 0 ) );
  23290. }
  23291. }
  23292. geometry.dynamic = true;
  23293. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors, depthTest: false, depthWrite: false, transparent: true } );
  23294. THREE.LineSegments.call( this, geometry, material );
  23295. this.root = object;
  23296. this.matrix = object.matrixWorld;
  23297. this.matrixAutoUpdate = false;
  23298. this.update();
  23299. };
  23300. THREE.SkeletonHelper.prototype = Object.create( THREE.LineSegments.prototype );
  23301. THREE.SkeletonHelper.prototype.constructor = THREE.SkeletonHelper;
  23302. THREE.SkeletonHelper.prototype.getBoneList = function( object ) {
  23303. var boneList = [];
  23304. if ( object instanceof THREE.Bone ) {
  23305. boneList.push( object );
  23306. }
  23307. for ( var i = 0; i < object.children.length; i ++ ) {
  23308. boneList.push.apply( boneList, this.getBoneList( object.children[ i ] ) );
  23309. }
  23310. return boneList;
  23311. };
  23312. THREE.SkeletonHelper.prototype.update = function () {
  23313. var geometry = this.geometry;
  23314. var matrixWorldInv = new THREE.Matrix4().getInverse( this.root.matrixWorld );
  23315. var boneMatrix = new THREE.Matrix4();
  23316. var j = 0;
  23317. for ( var i = 0; i < this.bones.length; i ++ ) {
  23318. var bone = this.bones[ i ];
  23319. if ( bone.parent instanceof THREE.Bone ) {
  23320. boneMatrix.multiplyMatrices( matrixWorldInv, bone.matrixWorld );
  23321. geometry.vertices[ j ].setFromMatrixPosition( boneMatrix );
  23322. boneMatrix.multiplyMatrices( matrixWorldInv, bone.parent.matrixWorld );
  23323. geometry.vertices[ j + 1 ].setFromMatrixPosition( boneMatrix );
  23324. j += 2;
  23325. }
  23326. }
  23327. geometry.verticesNeedUpdate = true;
  23328. geometry.computeBoundingSphere();
  23329. };
  23330. // File:src/extras/helpers/SpotLightHelper.js
  23331. /**
  23332. * @author alteredq / http://alteredqualia.com/
  23333. * @author mrdoob / http://mrdoob.com/
  23334. * @author WestLangley / http://github.com/WestLangley
  23335. */
  23336. THREE.SpotLightHelper = function ( light ) {
  23337. THREE.Object3D.call( this );
  23338. this.light = light;
  23339. this.light.updateMatrixWorld();
  23340. this.matrix = light.matrixWorld;
  23341. this.matrixAutoUpdate = false;
  23342. var geometry = new THREE.CylinderGeometry( 0, 1, 1, 8, 1, true );
  23343. geometry.translate( 0, - 0.5, 0 );
  23344. geometry.rotateX( - Math.PI / 2 );
  23345. var material = new THREE.MeshBasicMaterial( { wireframe: true, fog: false } );
  23346. this.cone = new THREE.Mesh( geometry, material );
  23347. this.add( this.cone );
  23348. this.update();
  23349. };
  23350. THREE.SpotLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  23351. THREE.SpotLightHelper.prototype.constructor = THREE.SpotLightHelper;
  23352. THREE.SpotLightHelper.prototype.dispose = function () {
  23353. this.cone.geometry.dispose();
  23354. this.cone.material.dispose();
  23355. };
  23356. THREE.SpotLightHelper.prototype.update = function () {
  23357. var vector = new THREE.Vector3();
  23358. var vector2 = new THREE.Vector3();
  23359. return function () {
  23360. var coneLength = this.light.distance ? this.light.distance : 10000;
  23361. var coneWidth = coneLength * Math.tan( this.light.angle );
  23362. this.cone.scale.set( coneWidth, coneWidth, coneLength );
  23363. vector.setFromMatrixPosition( this.light.matrixWorld );
  23364. vector2.setFromMatrixPosition( this.light.target.matrixWorld );
  23365. this.cone.lookAt( vector2.sub( vector ) );
  23366. this.cone.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  23367. };
  23368. }();
  23369. // File:src/extras/helpers/VertexNormalsHelper.js
  23370. /**
  23371. * @author mrdoob / http://mrdoob.com/
  23372. * @author WestLangley / http://github.com/WestLangley
  23373. */
  23374. THREE.VertexNormalsHelper = function ( object, size, hex, linewidth ) {
  23375. this.object = object;
  23376. this.size = ( size !== undefined ) ? size : 1;
  23377. var color = ( hex !== undefined ) ? hex : 0xff0000;
  23378. var width = ( linewidth !== undefined ) ? linewidth : 1;
  23379. //
  23380. var nNormals = 0;
  23381. var objGeometry = this.object.geometry;
  23382. if ( objGeometry instanceof THREE.Geometry ) {
  23383. nNormals = objGeometry.faces.length * 3;
  23384. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  23385. nNormals = objGeometry.attributes.normal.count
  23386. }
  23387. //
  23388. var geometry = new THREE.BufferGeometry();
  23389. var positions = new THREE.Float32Attribute( nNormals * 2 * 3, 3 );
  23390. geometry.addAttribute( 'position', positions );
  23391. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  23392. //
  23393. this.matrixAutoUpdate = false;
  23394. this.update();
  23395. };
  23396. THREE.VertexNormalsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  23397. THREE.VertexNormalsHelper.prototype.constructor = THREE.VertexNormalsHelper;
  23398. THREE.VertexNormalsHelper.prototype.update = ( function () {
  23399. var v1 = new THREE.Vector3();
  23400. var v2 = new THREE.Vector3();
  23401. var normalMatrix = new THREE.Matrix3();
  23402. return function update() {
  23403. var keys = [ 'a', 'b', 'c' ];
  23404. this.object.updateMatrixWorld( true );
  23405. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  23406. var matrixWorld = this.object.matrixWorld;
  23407. var position = this.geometry.attributes.position;
  23408. //
  23409. var objGeometry = this.object.geometry;
  23410. if ( objGeometry instanceof THREE.Geometry ) {
  23411. var vertices = objGeometry.vertices;
  23412. var faces = objGeometry.faces;
  23413. var idx = 0;
  23414. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  23415. var face = faces[ i ];
  23416. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  23417. var vertex = vertices[ face[ keys[ j ] ] ];
  23418. var normal = face.vertexNormals[ j ];
  23419. v1.copy( vertex ).applyMatrix4( matrixWorld );
  23420. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  23421. position.setXYZ( idx, v1.x, v1.y, v1.z );
  23422. idx = idx + 1;
  23423. position.setXYZ( idx, v2.x, v2.y, v2.z );
  23424. idx = idx + 1;
  23425. }
  23426. }
  23427. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  23428. var objPos = objGeometry.attributes.position;
  23429. var objNorm = objGeometry.attributes.normal;
  23430. var idx = 0;
  23431. // for simplicity, ignore index and drawcalls, and render every normal
  23432. for ( var j = 0, jl = objPos.count; j < jl; j ++ ) {
  23433. v1.set( objPos.getX( j ), objPos.getY( j ), objPos.getZ( j ) ).applyMatrix4( matrixWorld );
  23434. v2.set( objNorm.getX( j ), objNorm.getY( j ), objNorm.getZ( j ) );
  23435. v2.applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  23436. position.setXYZ( idx, v1.x, v1.y, v1.z );
  23437. idx = idx + 1;
  23438. position.setXYZ( idx, v2.x, v2.y, v2.z );
  23439. idx = idx + 1;
  23440. }
  23441. }
  23442. position.needsUpdate = true;
  23443. return this;
  23444. }
  23445. }() );
  23446. // File:src/extras/helpers/WireframeHelper.js
  23447. /**
  23448. * @author mrdoob / http://mrdoob.com/
  23449. */
  23450. THREE.WireframeHelper = function ( object, hex ) {
  23451. var color = ( hex !== undefined ) ? hex : 0xffffff;
  23452. THREE.LineSegments.call( this, new THREE.WireframeGeometry( object.geometry ), new THREE.LineBasicMaterial( { color: color } ) );
  23453. this.matrix = object.matrixWorld;
  23454. this.matrixAutoUpdate = false;
  23455. };
  23456. THREE.WireframeHelper.prototype = Object.create( THREE.LineSegments.prototype );
  23457. THREE.WireframeHelper.prototype.constructor = THREE.WireframeHelper;
  23458. // File:src/extras/objects/ImmediateRenderObject.js
  23459. /**
  23460. * @author alteredq / http://alteredqualia.com/
  23461. */
  23462. THREE.ImmediateRenderObject = function ( material ) {
  23463. THREE.Object3D.call( this );
  23464. this.material = material;
  23465. this.render = function ( renderCallback ) {};
  23466. };
  23467. THREE.ImmediateRenderObject.prototype = Object.create( THREE.Object3D.prototype );
  23468. THREE.ImmediateRenderObject.prototype.constructor = THREE.ImmediateRenderObject;
  23469. // File:src/extras/objects/MorphBlendMesh.js
  23470. /**
  23471. * @author alteredq / http://alteredqualia.com/
  23472. */
  23473. THREE.MorphBlendMesh = function( geometry, material ) {
  23474. THREE.Mesh.call( this, geometry, material );
  23475. this.animationsMap = {};
  23476. this.animationsList = [];
  23477. // prepare default animation
  23478. // (all frames played together in 1 second)
  23479. var numFrames = this.geometry.morphTargets.length;
  23480. var name = "__default";
  23481. var startFrame = 0;
  23482. var endFrame = numFrames - 1;
  23483. var fps = numFrames / 1;
  23484. this.createAnimation( name, startFrame, endFrame, fps );
  23485. this.setAnimationWeight( name, 1 );
  23486. };
  23487. THREE.MorphBlendMesh.prototype = Object.create( THREE.Mesh.prototype );
  23488. THREE.MorphBlendMesh.prototype.constructor = THREE.MorphBlendMesh;
  23489. THREE.MorphBlendMesh.prototype.createAnimation = function ( name, start, end, fps ) {
  23490. var animation = {
  23491. start: start,
  23492. end: end,
  23493. length: end - start + 1,
  23494. fps: fps,
  23495. duration: ( end - start ) / fps,
  23496. lastFrame: 0,
  23497. currentFrame: 0,
  23498. active: false,
  23499. time: 0,
  23500. direction: 1,
  23501. weight: 1,
  23502. directionBackwards: false,
  23503. mirroredLoop: false
  23504. };
  23505. this.animationsMap[ name ] = animation;
  23506. this.animationsList.push( animation );
  23507. };
  23508. THREE.MorphBlendMesh.prototype.autoCreateAnimations = function ( fps ) {
  23509. var pattern = /([a-z]+)_?(\d+)/;
  23510. var firstAnimation, frameRanges = {};
  23511. var geometry = this.geometry;
  23512. for ( var i = 0, il = geometry.morphTargets.length; i < il; i ++ ) {
  23513. var morph = geometry.morphTargets[ i ];
  23514. var chunks = morph.name.match( pattern );
  23515. if ( chunks && chunks.length > 1 ) {
  23516. var name = chunks[ 1 ];
  23517. if ( ! frameRanges[ name ] ) frameRanges[ name ] = { start: Infinity, end: - Infinity };
  23518. var range = frameRanges[ name ];
  23519. if ( i < range.start ) range.start = i;
  23520. if ( i > range.end ) range.end = i;
  23521. if ( ! firstAnimation ) firstAnimation = name;
  23522. }
  23523. }
  23524. for ( var name in frameRanges ) {
  23525. var range = frameRanges[ name ];
  23526. this.createAnimation( name, range.start, range.end, fps );
  23527. }
  23528. this.firstAnimation = firstAnimation;
  23529. };
  23530. THREE.MorphBlendMesh.prototype.setAnimationDirectionForward = function ( name ) {
  23531. var animation = this.animationsMap[ name ];
  23532. if ( animation ) {
  23533. animation.direction = 1;
  23534. animation.directionBackwards = false;
  23535. }
  23536. };
  23537. THREE.MorphBlendMesh.prototype.setAnimationDirectionBackward = function ( name ) {
  23538. var animation = this.animationsMap[ name ];
  23539. if ( animation ) {
  23540. animation.direction = - 1;
  23541. animation.directionBackwards = true;
  23542. }
  23543. };
  23544. THREE.MorphBlendMesh.prototype.setAnimationFPS = function ( name, fps ) {
  23545. var animation = this.animationsMap[ name ];
  23546. if ( animation ) {
  23547. animation.fps = fps;
  23548. animation.duration = ( animation.end - animation.start ) / animation.fps;
  23549. }
  23550. };
  23551. THREE.MorphBlendMesh.prototype.setAnimationDuration = function ( name, duration ) {
  23552. var animation = this.animationsMap[ name ];
  23553. if ( animation ) {
  23554. animation.duration = duration;
  23555. animation.fps = ( animation.end - animation.start ) / animation.duration;
  23556. }
  23557. };
  23558. THREE.MorphBlendMesh.prototype.setAnimationWeight = function ( name, weight ) {
  23559. var animation = this.animationsMap[ name ];
  23560. if ( animation ) {
  23561. animation.weight = weight;
  23562. }
  23563. };
  23564. THREE.MorphBlendMesh.prototype.setAnimationTime = function ( name, time ) {
  23565. var animation = this.animationsMap[ name ];
  23566. if ( animation ) {
  23567. animation.time = time;
  23568. }
  23569. };
  23570. THREE.MorphBlendMesh.prototype.getAnimationTime = function ( name ) {
  23571. var time = 0;
  23572. var animation = this.animationsMap[ name ];
  23573. if ( animation ) {
  23574. time = animation.time;
  23575. }
  23576. return time;
  23577. };
  23578. THREE.MorphBlendMesh.prototype.getAnimationDuration = function ( name ) {
  23579. var duration = - 1;
  23580. var animation = this.animationsMap[ name ];
  23581. if ( animation ) {
  23582. duration = animation.duration;
  23583. }
  23584. return duration;
  23585. };
  23586. THREE.MorphBlendMesh.prototype.playAnimation = function ( name ) {
  23587. var animation = this.animationsMap[ name ];
  23588. if ( animation ) {
  23589. animation.time = 0;
  23590. animation.active = true;
  23591. } else {
  23592. console.warn( "THREE.MorphBlendMesh: animation[" + name + "] undefined in .playAnimation()" );
  23593. }
  23594. };
  23595. THREE.MorphBlendMesh.prototype.stopAnimation = function ( name ) {
  23596. var animation = this.animationsMap[ name ];
  23597. if ( animation ) {
  23598. animation.active = false;
  23599. }
  23600. };
  23601. THREE.MorphBlendMesh.prototype.update = function ( delta ) {
  23602. for ( var i = 0, il = this.animationsList.length; i < il; i ++ ) {
  23603. var animation = this.animationsList[ i ];
  23604. if ( ! animation.active ) continue;
  23605. var frameTime = animation.duration / animation.length;
  23606. animation.time += animation.direction * delta;
  23607. if ( animation.mirroredLoop ) {
  23608. if ( animation.time > animation.duration || animation.time < 0 ) {
  23609. animation.direction *= - 1;
  23610. if ( animation.time > animation.duration ) {
  23611. animation.time = animation.duration;
  23612. animation.directionBackwards = true;
  23613. }
  23614. if ( animation.time < 0 ) {
  23615. animation.time = 0;
  23616. animation.directionBackwards = false;
  23617. }
  23618. }
  23619. } else {
  23620. animation.time = animation.time % animation.duration;
  23621. if ( animation.time < 0 ) animation.time += animation.duration;
  23622. }
  23623. var keyframe = animation.start + THREE.Math.clamp( Math.floor( animation.time / frameTime ), 0, animation.length - 1 );
  23624. var weight = animation.weight;
  23625. if ( keyframe !== animation.currentFrame ) {
  23626. this.morphTargetInfluences[ animation.lastFrame ] = 0;
  23627. this.morphTargetInfluences[ animation.currentFrame ] = 1 * weight;
  23628. this.morphTargetInfluences[ keyframe ] = 0;
  23629. animation.lastFrame = animation.currentFrame;
  23630. animation.currentFrame = keyframe;
  23631. }
  23632. var mix = ( animation.time % frameTime ) / frameTime;
  23633. if ( animation.directionBackwards ) mix = 1 - mix;
  23634. if ( animation.currentFrame !== animation.lastFrame ) {
  23635. this.morphTargetInfluences[ animation.currentFrame ] = mix * weight;
  23636. this.morphTargetInfluences[ animation.lastFrame ] = ( 1 - mix ) * weight;
  23637. } else {
  23638. this.morphTargetInfluences[ animation.currentFrame ] = weight;
  23639. }
  23640. }
  23641. };