three.js 915 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563
  1. // File:src/Three.js
  2. /**
  3. * @author mrdoob / http://mrdoob.com/
  4. */
  5. var THREE = { REVISION: '75dev' };
  6. //
  7. if ( typeof define === 'function' && define.amd ) {
  8. define( 'three', THREE );
  9. } else if ( 'undefined' !== typeof exports && 'undefined' !== typeof module ) {
  10. module.exports = THREE;
  11. }
  12. //
  13. if ( Number.EPSILON === undefined ) {
  14. Number.EPSILON = Math.pow( 2, - 52 );
  15. }
  16. //
  17. if ( Math.sign === undefined ) {
  18. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
  19. Math.sign = function ( x ) {
  20. return ( x < 0 ) ? - 1 : ( x > 0 ) ? 1 : + x;
  21. };
  22. }
  23. if ( Function.prototype.name === undefined && Object.defineProperty !== undefined ) {
  24. // Missing in IE9-11.
  25. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
  26. Object.defineProperty( Function.prototype, 'name', {
  27. get: function () {
  28. return this.toString().match( /^\s*function\s*(\S*)\s*\(/ )[ 1 ];
  29. }
  30. } );
  31. }
  32. if ( Object.assign === undefined ) {
  33. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
  34. Object.defineProperty( Object, 'assign', {
  35. writable: true,
  36. configurable: true,
  37. value: function ( target ) {
  38. 'use strict';
  39. if ( target === undefined || target === null ) {
  40. throw new TypeError( "Cannot convert first argument to object" );
  41. }
  42. var to = Object( target );
  43. for ( var i = 1, n = arguments.length; i !== n; ++ i ) {
  44. var nextSource = arguments[ i ];
  45. if ( nextSource === undefined || nextSource === null ) continue;
  46. nextSource = Object( nextSource );
  47. var keysArray = Object.keys( nextSource );
  48. for ( var nextIndex = 0, len = keysArray.length; nextIndex !== len; ++ nextIndex ) {
  49. var nextKey = keysArray[ nextIndex ];
  50. var desc = Object.getOwnPropertyDescriptor( nextSource, nextKey );
  51. if ( desc !== undefined && desc.enumerable ) {
  52. to[ nextKey ] = nextSource[ nextKey ];
  53. }
  54. }
  55. }
  56. return to;
  57. }
  58. } );
  59. }
  60. // https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent.button
  61. THREE.MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2 };
  62. // GL STATE CONSTANTS
  63. THREE.CullFaceNone = 0;
  64. THREE.CullFaceBack = 1;
  65. THREE.CullFaceFront = 2;
  66. THREE.CullFaceFrontBack = 3;
  67. THREE.FrontFaceDirectionCW = 0;
  68. THREE.FrontFaceDirectionCCW = 1;
  69. // SHADOWING TYPES
  70. THREE.BasicShadowMap = 0;
  71. THREE.PCFShadowMap = 1;
  72. THREE.PCFSoftShadowMap = 2;
  73. // MATERIAL CONSTANTS
  74. // side
  75. THREE.FrontSide = 0;
  76. THREE.BackSide = 1;
  77. THREE.DoubleSide = 2;
  78. // shading
  79. THREE.FlatShading = 1;
  80. THREE.SmoothShading = 2;
  81. // colors
  82. THREE.NoColors = 0;
  83. THREE.FaceColors = 1;
  84. THREE.VertexColors = 2;
  85. // blending modes
  86. THREE.NoBlending = 0;
  87. THREE.NormalBlending = 1;
  88. THREE.AdditiveBlending = 2;
  89. THREE.SubtractiveBlending = 3;
  90. THREE.MultiplyBlending = 4;
  91. THREE.CustomBlending = 5;
  92. THREE.PremultipliedAlphaBlending = 6;
  93. // custom blending equations
  94. // (numbers start from 100 not to clash with other
  95. // mappings to OpenGL constants defined in Texture.js)
  96. THREE.AddEquation = 100;
  97. THREE.SubtractEquation = 101;
  98. THREE.ReverseSubtractEquation = 102;
  99. THREE.MinEquation = 103;
  100. THREE.MaxEquation = 104;
  101. // custom blending destination factors
  102. THREE.ZeroFactor = 200;
  103. THREE.OneFactor = 201;
  104. THREE.SrcColorFactor = 202;
  105. THREE.OneMinusSrcColorFactor = 203;
  106. THREE.SrcAlphaFactor = 204;
  107. THREE.OneMinusSrcAlphaFactor = 205;
  108. THREE.DstAlphaFactor = 206;
  109. THREE.OneMinusDstAlphaFactor = 207;
  110. // custom blending source factors
  111. //THREE.ZeroFactor = 200;
  112. //THREE.OneFactor = 201;
  113. //THREE.SrcAlphaFactor = 204;
  114. //THREE.OneMinusSrcAlphaFactor = 205;
  115. //THREE.DstAlphaFactor = 206;
  116. //THREE.OneMinusDstAlphaFactor = 207;
  117. THREE.DstColorFactor = 208;
  118. THREE.OneMinusDstColorFactor = 209;
  119. THREE.SrcAlphaSaturateFactor = 210;
  120. // depth modes
  121. THREE.NeverDepth = 0;
  122. THREE.AlwaysDepth = 1;
  123. THREE.LessDepth = 2;
  124. THREE.LessEqualDepth = 3;
  125. THREE.EqualDepth = 4;
  126. THREE.GreaterEqualDepth = 5;
  127. THREE.GreaterDepth = 6;
  128. THREE.NotEqualDepth = 7;
  129. // TEXTURE CONSTANTS
  130. THREE.MultiplyOperation = 0;
  131. THREE.MixOperation = 1;
  132. THREE.AddOperation = 2;
  133. // Tone Mapping modes
  134. THREE.NoToneMapping = 0; // do not do any tone mapping, not even exposure (required for special purpose passes.)
  135. THREE.LinearToneMapping = 1; // only apply exposure.
  136. THREE.ReinhardToneMapping = 2;
  137. THREE.Uncharted2ToneMapping = 3; // John Hable
  138. THREE.CineonToneMapping = 4; // optimized filmic operator by Jim Hejl and Richard Burgess-Dawson
  139. // Mapping modes
  140. THREE.UVMapping = 300;
  141. THREE.CubeReflectionMapping = 301;
  142. THREE.CubeRefractionMapping = 302;
  143. THREE.EquirectangularReflectionMapping = 303;
  144. THREE.EquirectangularRefractionMapping = 304;
  145. THREE.SphericalReflectionMapping = 305;
  146. THREE.CubeUVReflectionMapping = 306;
  147. THREE.CubeUVRefractionMapping = 307;
  148. // Wrapping modes
  149. THREE.RepeatWrapping = 1000;
  150. THREE.ClampToEdgeWrapping = 1001;
  151. THREE.MirroredRepeatWrapping = 1002;
  152. // Filters
  153. THREE.NearestFilter = 1003;
  154. THREE.NearestMipMapNearestFilter = 1004;
  155. THREE.NearestMipMapLinearFilter = 1005;
  156. THREE.LinearFilter = 1006;
  157. THREE.LinearMipMapNearestFilter = 1007;
  158. THREE.LinearMipMapLinearFilter = 1008;
  159. // Data types
  160. THREE.UnsignedByteType = 1009;
  161. THREE.ByteType = 1010;
  162. THREE.ShortType = 1011;
  163. THREE.UnsignedShortType = 1012;
  164. THREE.IntType = 1013;
  165. THREE.UnsignedIntType = 1014;
  166. THREE.FloatType = 1015;
  167. THREE.HalfFloatType = 1025;
  168. // Pixel types
  169. //THREE.UnsignedByteType = 1009;
  170. THREE.UnsignedShort4444Type = 1016;
  171. THREE.UnsignedShort5551Type = 1017;
  172. THREE.UnsignedShort565Type = 1018;
  173. // Pixel formats
  174. THREE.AlphaFormat = 1019;
  175. THREE.RGBFormat = 1020;
  176. THREE.RGBAFormat = 1021;
  177. THREE.LuminanceFormat = 1022;
  178. THREE.LuminanceAlphaFormat = 1023;
  179. // THREE.RGBEFormat handled as THREE.RGBAFormat in shaders
  180. THREE.RGBEFormat = THREE.RGBAFormat; //1024;
  181. // DDS / ST3C Compressed texture formats
  182. THREE.RGB_S3TC_DXT1_Format = 2001;
  183. THREE.RGBA_S3TC_DXT1_Format = 2002;
  184. THREE.RGBA_S3TC_DXT3_Format = 2003;
  185. THREE.RGBA_S3TC_DXT5_Format = 2004;
  186. // PVRTC compressed texture formats
  187. THREE.RGB_PVRTC_4BPPV1_Format = 2100;
  188. THREE.RGB_PVRTC_2BPPV1_Format = 2101;
  189. THREE.RGBA_PVRTC_4BPPV1_Format = 2102;
  190. THREE.RGBA_PVRTC_2BPPV1_Format = 2103;
  191. // ETC compressed texture formats
  192. THREE.RGB_ETC1_Format = 2151;
  193. // Loop styles for AnimationAction
  194. THREE.LoopOnce = 2200;
  195. THREE.LoopRepeat = 2201;
  196. THREE.LoopPingPong = 2202;
  197. // Interpolation
  198. THREE.InterpolateDiscrete = 2300;
  199. THREE.InterpolateLinear = 2301;
  200. THREE.InterpolateSmooth = 2302;
  201. // Interpolant ending modes
  202. THREE.ZeroCurvatureEnding = 2400;
  203. THREE.ZeroSlopeEnding = 2401;
  204. THREE.WrapAroundEnding = 2402;
  205. // Triangle Draw modes
  206. THREE.TrianglesDrawMode = 0;
  207. THREE.TriangleStripDrawMode = 1;
  208. THREE.TriangleFanDrawMode = 2;
  209. // Texture Encodings
  210. THREE.LinearEncoding = 3000; // No encoding at all.
  211. THREE.sRGBEncoding = 3001;
  212. THREE.GammaEncoding = 3007; // uses GAMMA_FACTOR, for backwards compatibility with WebGLRenderer.gammaInput/gammaOutput
  213. // The following Texture Encodings are for RGB-only (no alpha) HDR light emission sources.
  214. // These encodings should not specified as output encodings except in rare situations.
  215. THREE.RGBEEncoding = 3002; // AKA Radiance.
  216. THREE.LogLuvEncoding = 3003;
  217. THREE.RGBM7Encoding = 3004;
  218. THREE.RGBM16Encoding = 3005;
  219. THREE.RGBDEncoding = 3006; // MaxRange is 256.
  220. // File:src/math/Color.js
  221. /**
  222. * @author mrdoob / http://mrdoob.com/
  223. */
  224. THREE.Color = function ( color ) {
  225. if ( arguments.length === 3 ) {
  226. return this.fromArray( arguments );
  227. }
  228. return this.set( color );
  229. };
  230. THREE.Color.prototype = {
  231. constructor: THREE.Color,
  232. r: 1, g: 1, b: 1,
  233. set: function ( value ) {
  234. if ( value instanceof THREE.Color ) {
  235. this.copy( value );
  236. } else if ( typeof value === 'number' ) {
  237. this.setHex( value );
  238. } else if ( typeof value === 'string' ) {
  239. this.setStyle( value );
  240. }
  241. return this;
  242. },
  243. setScalar: function ( scalar ) {
  244. this.r = scalar;
  245. this.g = scalar;
  246. this.b = scalar;
  247. },
  248. setHex: function ( hex ) {
  249. hex = Math.floor( hex );
  250. this.r = ( hex >> 16 & 255 ) / 255;
  251. this.g = ( hex >> 8 & 255 ) / 255;
  252. this.b = ( hex & 255 ) / 255;
  253. return this;
  254. },
  255. setRGB: function ( r, g, b ) {
  256. this.r = r;
  257. this.g = g;
  258. this.b = b;
  259. return this;
  260. },
  261. setHSL: function () {
  262. function hue2rgb( p, q, t ) {
  263. if ( t < 0 ) t += 1;
  264. if ( t > 1 ) t -= 1;
  265. if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
  266. if ( t < 1 / 2 ) return q;
  267. if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
  268. return p;
  269. }
  270. return function ( h, s, l ) {
  271. // h,s,l ranges are in 0.0 - 1.0
  272. h = THREE.Math.euclideanModulo( h, 1 );
  273. s = THREE.Math.clamp( s, 0, 1 );
  274. l = THREE.Math.clamp( l, 0, 1 );
  275. if ( s === 0 ) {
  276. this.r = this.g = this.b = l;
  277. } else {
  278. var p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  279. var q = ( 2 * l ) - p;
  280. this.r = hue2rgb( q, p, h + 1 / 3 );
  281. this.g = hue2rgb( q, p, h );
  282. this.b = hue2rgb( q, p, h - 1 / 3 );
  283. }
  284. return this;
  285. };
  286. }(),
  287. setStyle: function ( style ) {
  288. function handleAlpha( string ) {
  289. if ( string === undefined ) return;
  290. if ( parseFloat( string ) < 1 ) {
  291. console.warn( 'THREE.Color: Alpha component of ' + style + ' will be ignored.' );
  292. }
  293. }
  294. var m;
  295. if ( m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec( style ) ) {
  296. // rgb / hsl
  297. var color;
  298. var name = m[ 1 ];
  299. var components = m[ 2 ];
  300. switch ( name ) {
  301. case 'rgb':
  302. case 'rgba':
  303. if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  304. // rgb(255,0,0) rgba(255,0,0,0.5)
  305. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  306. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  307. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  308. handleAlpha( color[ 5 ] );
  309. return this;
  310. }
  311. if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  312. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  313. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  314. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  315. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  316. handleAlpha( color[ 5 ] );
  317. return this;
  318. }
  319. break;
  320. case 'hsl':
  321. case 'hsla':
  322. if ( color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  323. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  324. var h = parseFloat( color[ 1 ] ) / 360;
  325. var s = parseInt( color[ 2 ], 10 ) / 100;
  326. var l = parseInt( color[ 3 ], 10 ) / 100;
  327. handleAlpha( color[ 5 ] );
  328. return this.setHSL( h, s, l );
  329. }
  330. break;
  331. }
  332. } else if ( m = /^\#([A-Fa-f0-9]+)$/.exec( style ) ) {
  333. // hex color
  334. var hex = m[ 1 ];
  335. var size = hex.length;
  336. if ( size === 3 ) {
  337. // #ff0
  338. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 0 ), 16 ) / 255;
  339. this.g = parseInt( hex.charAt( 1 ) + hex.charAt( 1 ), 16 ) / 255;
  340. this.b = parseInt( hex.charAt( 2 ) + hex.charAt( 2 ), 16 ) / 255;
  341. return this;
  342. } else if ( size === 6 ) {
  343. // #ff0000
  344. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 1 ), 16 ) / 255;
  345. this.g = parseInt( hex.charAt( 2 ) + hex.charAt( 3 ), 16 ) / 255;
  346. this.b = parseInt( hex.charAt( 4 ) + hex.charAt( 5 ), 16 ) / 255;
  347. return this;
  348. }
  349. }
  350. if ( style && style.length > 0 ) {
  351. // color keywords
  352. var hex = THREE.ColorKeywords[ style ];
  353. if ( hex !== undefined ) {
  354. // red
  355. this.setHex( hex );
  356. } else {
  357. // unknown color
  358. console.warn( 'THREE.Color: Unknown color ' + style );
  359. }
  360. }
  361. return this;
  362. },
  363. clone: function () {
  364. return new this.constructor( this.r, this.g, this.b );
  365. },
  366. copy: function ( color ) {
  367. this.r = color.r;
  368. this.g = color.g;
  369. this.b = color.b;
  370. return this;
  371. },
  372. copyGammaToLinear: function ( color, gammaFactor ) {
  373. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  374. this.r = Math.pow( color.r, gammaFactor );
  375. this.g = Math.pow( color.g, gammaFactor );
  376. this.b = Math.pow( color.b, gammaFactor );
  377. return this;
  378. },
  379. copyLinearToGamma: function ( color, gammaFactor ) {
  380. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  381. var safeInverse = ( gammaFactor > 0 ) ? ( 1.0 / gammaFactor ) : 1.0;
  382. this.r = Math.pow( color.r, safeInverse );
  383. this.g = Math.pow( color.g, safeInverse );
  384. this.b = Math.pow( color.b, safeInverse );
  385. return this;
  386. },
  387. convertGammaToLinear: function () {
  388. var r = this.r, g = this.g, b = this.b;
  389. this.r = r * r;
  390. this.g = g * g;
  391. this.b = b * b;
  392. return this;
  393. },
  394. convertLinearToGamma: function () {
  395. this.r = Math.sqrt( this.r );
  396. this.g = Math.sqrt( this.g );
  397. this.b = Math.sqrt( this.b );
  398. return this;
  399. },
  400. getHex: function () {
  401. return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
  402. },
  403. getHexString: function () {
  404. return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
  405. },
  406. getHSL: function ( optionalTarget ) {
  407. // h,s,l ranges are in 0.0 - 1.0
  408. var hsl = optionalTarget || { h: 0, s: 0, l: 0 };
  409. var r = this.r, g = this.g, b = this.b;
  410. var max = Math.max( r, g, b );
  411. var min = Math.min( r, g, b );
  412. var hue, saturation;
  413. var lightness = ( min + max ) / 2.0;
  414. if ( min === max ) {
  415. hue = 0;
  416. saturation = 0;
  417. } else {
  418. var delta = max - min;
  419. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  420. switch ( max ) {
  421. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  422. case g: hue = ( b - r ) / delta + 2; break;
  423. case b: hue = ( r - g ) / delta + 4; break;
  424. }
  425. hue /= 6;
  426. }
  427. hsl.h = hue;
  428. hsl.s = saturation;
  429. hsl.l = lightness;
  430. return hsl;
  431. },
  432. getStyle: function () {
  433. return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
  434. },
  435. offsetHSL: function ( h, s, l ) {
  436. var hsl = this.getHSL();
  437. hsl.h += h; hsl.s += s; hsl.l += l;
  438. this.setHSL( hsl.h, hsl.s, hsl.l );
  439. return this;
  440. },
  441. add: function ( color ) {
  442. this.r += color.r;
  443. this.g += color.g;
  444. this.b += color.b;
  445. return this;
  446. },
  447. addColors: function ( color1, color2 ) {
  448. this.r = color1.r + color2.r;
  449. this.g = color1.g + color2.g;
  450. this.b = color1.b + color2.b;
  451. return this;
  452. },
  453. addScalar: function ( s ) {
  454. this.r += s;
  455. this.g += s;
  456. this.b += s;
  457. return this;
  458. },
  459. multiply: function ( color ) {
  460. this.r *= color.r;
  461. this.g *= color.g;
  462. this.b *= color.b;
  463. return this;
  464. },
  465. multiplyScalar: function ( s ) {
  466. this.r *= s;
  467. this.g *= s;
  468. this.b *= s;
  469. return this;
  470. },
  471. lerp: function ( color, alpha ) {
  472. this.r += ( color.r - this.r ) * alpha;
  473. this.g += ( color.g - this.g ) * alpha;
  474. this.b += ( color.b - this.b ) * alpha;
  475. return this;
  476. },
  477. equals: function ( c ) {
  478. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  479. },
  480. fromArray: function ( array, offset ) {
  481. if ( offset === undefined ) offset = 0;
  482. this.r = array[ offset ];
  483. this.g = array[ offset + 1 ];
  484. this.b = array[ offset + 2 ];
  485. return this;
  486. },
  487. toArray: function ( array, offset ) {
  488. if ( array === undefined ) array = [];
  489. if ( offset === undefined ) offset = 0;
  490. array[ offset ] = this.r;
  491. array[ offset + 1 ] = this.g;
  492. array[ offset + 2 ] = this.b;
  493. return array;
  494. }
  495. };
  496. THREE.ColorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  497. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  498. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  499. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  500. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  501. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  502. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  503. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  504. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  505. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  506. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  507. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  508. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  509. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  510. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  511. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  512. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  513. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  514. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  515. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  516. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  517. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  518. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  519. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  520. // File:src/math/Quaternion.js
  521. /**
  522. * @author mikael emtinger / http://gomo.se/
  523. * @author alteredq / http://alteredqualia.com/
  524. * @author WestLangley / http://github.com/WestLangley
  525. * @author bhouston / http://clara.io
  526. */
  527. THREE.Quaternion = function ( x, y, z, w ) {
  528. this._x = x || 0;
  529. this._y = y || 0;
  530. this._z = z || 0;
  531. this._w = ( w !== undefined ) ? w : 1;
  532. };
  533. THREE.Quaternion.prototype = {
  534. constructor: THREE.Quaternion,
  535. get x () {
  536. return this._x;
  537. },
  538. set x ( value ) {
  539. this._x = value;
  540. this.onChangeCallback();
  541. },
  542. get y () {
  543. return this._y;
  544. },
  545. set y ( value ) {
  546. this._y = value;
  547. this.onChangeCallback();
  548. },
  549. get z () {
  550. return this._z;
  551. },
  552. set z ( value ) {
  553. this._z = value;
  554. this.onChangeCallback();
  555. },
  556. get w () {
  557. return this._w;
  558. },
  559. set w ( value ) {
  560. this._w = value;
  561. this.onChangeCallback();
  562. },
  563. set: function ( x, y, z, w ) {
  564. this._x = x;
  565. this._y = y;
  566. this._z = z;
  567. this._w = w;
  568. this.onChangeCallback();
  569. return this;
  570. },
  571. clone: function () {
  572. return new this.constructor( this._x, this._y, this._z, this._w );
  573. },
  574. copy: function ( quaternion ) {
  575. this._x = quaternion.x;
  576. this._y = quaternion.y;
  577. this._z = quaternion.z;
  578. this._w = quaternion.w;
  579. this.onChangeCallback();
  580. return this;
  581. },
  582. setFromEuler: function ( euler, update ) {
  583. if ( euler instanceof THREE.Euler === false ) {
  584. throw new Error( 'THREE.Quaternion: .setFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  585. }
  586. // http://www.mathworks.com/matlabcentral/fileexchange/
  587. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  588. // content/SpinCalc.m
  589. var c1 = Math.cos( euler._x / 2 );
  590. var c2 = Math.cos( euler._y / 2 );
  591. var c3 = Math.cos( euler._z / 2 );
  592. var s1 = Math.sin( euler._x / 2 );
  593. var s2 = Math.sin( euler._y / 2 );
  594. var s3 = Math.sin( euler._z / 2 );
  595. var order = euler.order;
  596. if ( order === 'XYZ' ) {
  597. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  598. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  599. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  600. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  601. } else if ( order === 'YXZ' ) {
  602. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  603. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  604. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  605. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  606. } else if ( order === 'ZXY' ) {
  607. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  608. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  609. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  610. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  611. } else if ( order === 'ZYX' ) {
  612. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  613. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  614. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  615. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  616. } else if ( order === 'YZX' ) {
  617. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  618. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  619. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  620. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  621. } else if ( order === 'XZY' ) {
  622. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  623. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  624. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  625. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  626. }
  627. if ( update !== false ) this.onChangeCallback();
  628. return this;
  629. },
  630. setFromAxisAngle: function ( axis, angle ) {
  631. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  632. // assumes axis is normalized
  633. var halfAngle = angle / 2, s = Math.sin( halfAngle );
  634. this._x = axis.x * s;
  635. this._y = axis.y * s;
  636. this._z = axis.z * s;
  637. this._w = Math.cos( halfAngle );
  638. this.onChangeCallback();
  639. return this;
  640. },
  641. setFromRotationMatrix: function ( m ) {
  642. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  643. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  644. var te = m.elements,
  645. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  646. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  647. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ],
  648. trace = m11 + m22 + m33,
  649. s;
  650. if ( trace > 0 ) {
  651. s = 0.5 / Math.sqrt( trace + 1.0 );
  652. this._w = 0.25 / s;
  653. this._x = ( m32 - m23 ) * s;
  654. this._y = ( m13 - m31 ) * s;
  655. this._z = ( m21 - m12 ) * s;
  656. } else if ( m11 > m22 && m11 > m33 ) {
  657. s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );
  658. this._w = ( m32 - m23 ) / s;
  659. this._x = 0.25 * s;
  660. this._y = ( m12 + m21 ) / s;
  661. this._z = ( m13 + m31 ) / s;
  662. } else if ( m22 > m33 ) {
  663. s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );
  664. this._w = ( m13 - m31 ) / s;
  665. this._x = ( m12 + m21 ) / s;
  666. this._y = 0.25 * s;
  667. this._z = ( m23 + m32 ) / s;
  668. } else {
  669. s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );
  670. this._w = ( m21 - m12 ) / s;
  671. this._x = ( m13 + m31 ) / s;
  672. this._y = ( m23 + m32 ) / s;
  673. this._z = 0.25 * s;
  674. }
  675. this.onChangeCallback();
  676. return this;
  677. },
  678. setFromUnitVectors: function () {
  679. // http://lolengine.net/blog/2014/02/24/quaternion-from-two-vectors-final
  680. // assumes direction vectors vFrom and vTo are normalized
  681. var v1, r;
  682. var EPS = 0.000001;
  683. return function ( vFrom, vTo ) {
  684. if ( v1 === undefined ) v1 = new THREE.Vector3();
  685. r = vFrom.dot( vTo ) + 1;
  686. if ( r < EPS ) {
  687. r = 0;
  688. if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) {
  689. v1.set( - vFrom.y, vFrom.x, 0 );
  690. } else {
  691. v1.set( 0, - vFrom.z, vFrom.y );
  692. }
  693. } else {
  694. v1.crossVectors( vFrom, vTo );
  695. }
  696. this._x = v1.x;
  697. this._y = v1.y;
  698. this._z = v1.z;
  699. this._w = r;
  700. this.normalize();
  701. return this;
  702. };
  703. }(),
  704. inverse: function () {
  705. this.conjugate().normalize();
  706. return this;
  707. },
  708. conjugate: function () {
  709. this._x *= - 1;
  710. this._y *= - 1;
  711. this._z *= - 1;
  712. this.onChangeCallback();
  713. return this;
  714. },
  715. dot: function ( v ) {
  716. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  717. },
  718. lengthSq: function () {
  719. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  720. },
  721. length: function () {
  722. return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );
  723. },
  724. normalize: function () {
  725. var l = this.length();
  726. if ( l === 0 ) {
  727. this._x = 0;
  728. this._y = 0;
  729. this._z = 0;
  730. this._w = 1;
  731. } else {
  732. l = 1 / l;
  733. this._x = this._x * l;
  734. this._y = this._y * l;
  735. this._z = this._z * l;
  736. this._w = this._w * l;
  737. }
  738. this.onChangeCallback();
  739. return this;
  740. },
  741. multiply: function ( q, p ) {
  742. if ( p !== undefined ) {
  743. console.warn( 'THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.' );
  744. return this.multiplyQuaternions( q, p );
  745. }
  746. return this.multiplyQuaternions( this, q );
  747. },
  748. multiplyQuaternions: function ( a, b ) {
  749. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  750. var qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
  751. var qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
  752. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  753. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  754. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  755. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  756. this.onChangeCallback();
  757. return this;
  758. },
  759. slerp: function ( qb, t ) {
  760. if ( t === 0 ) return this;
  761. if ( t === 1 ) return this.copy( qb );
  762. var x = this._x, y = this._y, z = this._z, w = this._w;
  763. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  764. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  765. if ( cosHalfTheta < 0 ) {
  766. this._w = - qb._w;
  767. this._x = - qb._x;
  768. this._y = - qb._y;
  769. this._z = - qb._z;
  770. cosHalfTheta = - cosHalfTheta;
  771. } else {
  772. this.copy( qb );
  773. }
  774. if ( cosHalfTheta >= 1.0 ) {
  775. this._w = w;
  776. this._x = x;
  777. this._y = y;
  778. this._z = z;
  779. return this;
  780. }
  781. var sinHalfTheta = Math.sqrt( 1.0 - cosHalfTheta * cosHalfTheta );
  782. if ( Math.abs( sinHalfTheta ) < 0.001 ) {
  783. this._w = 0.5 * ( w + this._w );
  784. this._x = 0.5 * ( x + this._x );
  785. this._y = 0.5 * ( y + this._y );
  786. this._z = 0.5 * ( z + this._z );
  787. return this;
  788. }
  789. var halfTheta = Math.atan2( sinHalfTheta, cosHalfTheta );
  790. var ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  791. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  792. this._w = ( w * ratioA + this._w * ratioB );
  793. this._x = ( x * ratioA + this._x * ratioB );
  794. this._y = ( y * ratioA + this._y * ratioB );
  795. this._z = ( z * ratioA + this._z * ratioB );
  796. this.onChangeCallback();
  797. return this;
  798. },
  799. equals: function ( quaternion ) {
  800. return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
  801. },
  802. fromArray: function ( array, offset ) {
  803. if ( offset === undefined ) offset = 0;
  804. this._x = array[ offset ];
  805. this._y = array[ offset + 1 ];
  806. this._z = array[ offset + 2 ];
  807. this._w = array[ offset + 3 ];
  808. this.onChangeCallback();
  809. return this;
  810. },
  811. toArray: function ( array, offset ) {
  812. if ( array === undefined ) array = [];
  813. if ( offset === undefined ) offset = 0;
  814. array[ offset ] = this._x;
  815. array[ offset + 1 ] = this._y;
  816. array[ offset + 2 ] = this._z;
  817. array[ offset + 3 ] = this._w;
  818. return array;
  819. },
  820. onChange: function ( callback ) {
  821. this.onChangeCallback = callback;
  822. return this;
  823. },
  824. onChangeCallback: function () {}
  825. };
  826. Object.assign( THREE.Quaternion, {
  827. slerp: function( qa, qb, qm, t ) {
  828. return qm.copy( qa ).slerp( qb, t );
  829. },
  830. slerpFlat: function(
  831. dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t ) {
  832. // fuzz-free, array-based Quaternion SLERP operation
  833. var x0 = src0[ srcOffset0 + 0 ],
  834. y0 = src0[ srcOffset0 + 1 ],
  835. z0 = src0[ srcOffset0 + 2 ],
  836. w0 = src0[ srcOffset0 + 3 ],
  837. x1 = src1[ srcOffset1 + 0 ],
  838. y1 = src1[ srcOffset1 + 1 ],
  839. z1 = src1[ srcOffset1 + 2 ],
  840. w1 = src1[ srcOffset1 + 3 ];
  841. if ( w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1 ) {
  842. var s = 1 - t,
  843. cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  844. dir = ( cos >= 0 ? 1 : - 1 ),
  845. sqrSin = 1 - cos * cos;
  846. // Skip the Slerp for tiny steps to avoid numeric problems:
  847. if ( sqrSin > Number.EPSILON ) {
  848. var sin = Math.sqrt( sqrSin ),
  849. len = Math.atan2( sin, cos * dir );
  850. s = Math.sin( s * len ) / sin;
  851. t = Math.sin( t * len ) / sin;
  852. }
  853. var tDir = t * dir;
  854. x0 = x0 * s + x1 * tDir;
  855. y0 = y0 * s + y1 * tDir;
  856. z0 = z0 * s + z1 * tDir;
  857. w0 = w0 * s + w1 * tDir;
  858. // Normalize in case we just did a lerp:
  859. if ( s === 1 - t ) {
  860. var f = 1 / Math.sqrt( x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0 );
  861. x0 *= f;
  862. y0 *= f;
  863. z0 *= f;
  864. w0 *= f;
  865. }
  866. }
  867. dst[ dstOffset ] = x0;
  868. dst[ dstOffset + 1 ] = y0;
  869. dst[ dstOffset + 2 ] = z0;
  870. dst[ dstOffset + 3 ] = w0;
  871. }
  872. } );
  873. // File:src/math/Vector2.js
  874. /**
  875. * @author mrdoob / http://mrdoob.com/
  876. * @author philogb / http://blog.thejit.org/
  877. * @author egraether / http://egraether.com/
  878. * @author zz85 / http://www.lab4games.net/zz85/blog
  879. */
  880. THREE.Vector2 = function ( x, y ) {
  881. this.x = x || 0;
  882. this.y = y || 0;
  883. };
  884. THREE.Vector2.prototype = {
  885. constructor: THREE.Vector2,
  886. get width() {
  887. return this.x;
  888. },
  889. set width( value ) {
  890. this.x = value;
  891. },
  892. get height() {
  893. return this.y;
  894. },
  895. set height( value ) {
  896. this.y = value;
  897. },
  898. //
  899. set: function ( x, y ) {
  900. this.x = x;
  901. this.y = y;
  902. return this;
  903. },
  904. setScalar: function ( scalar ) {
  905. this.x = scalar;
  906. this.y = scalar;
  907. return this;
  908. },
  909. setX: function ( x ) {
  910. this.x = x;
  911. return this;
  912. },
  913. setY: function ( y ) {
  914. this.y = y;
  915. return this;
  916. },
  917. setComponent: function ( index, value ) {
  918. switch ( index ) {
  919. case 0: this.x = value; break;
  920. case 1: this.y = value; break;
  921. default: throw new Error( 'index is out of range: ' + index );
  922. }
  923. },
  924. getComponent: function ( index ) {
  925. switch ( index ) {
  926. case 0: return this.x;
  927. case 1: return this.y;
  928. default: throw new Error( 'index is out of range: ' + index );
  929. }
  930. },
  931. clone: function () {
  932. return new this.constructor( this.x, this.y );
  933. },
  934. copy: function ( v ) {
  935. this.x = v.x;
  936. this.y = v.y;
  937. return this;
  938. },
  939. add: function ( v, w ) {
  940. if ( w !== undefined ) {
  941. console.warn( 'THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  942. return this.addVectors( v, w );
  943. }
  944. this.x += v.x;
  945. this.y += v.y;
  946. return this;
  947. },
  948. addScalar: function ( s ) {
  949. this.x += s;
  950. this.y += s;
  951. return this;
  952. },
  953. addVectors: function ( a, b ) {
  954. this.x = a.x + b.x;
  955. this.y = a.y + b.y;
  956. return this;
  957. },
  958. addScaledVector: function ( v, s ) {
  959. this.x += v.x * s;
  960. this.y += v.y * s;
  961. return this;
  962. },
  963. sub: function ( v, w ) {
  964. if ( w !== undefined ) {
  965. console.warn( 'THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  966. return this.subVectors( v, w );
  967. }
  968. this.x -= v.x;
  969. this.y -= v.y;
  970. return this;
  971. },
  972. subScalar: function ( s ) {
  973. this.x -= s;
  974. this.y -= s;
  975. return this;
  976. },
  977. subVectors: function ( a, b ) {
  978. this.x = a.x - b.x;
  979. this.y = a.y - b.y;
  980. return this;
  981. },
  982. multiply: function ( v ) {
  983. this.x *= v.x;
  984. this.y *= v.y;
  985. return this;
  986. },
  987. multiplyScalar: function ( scalar ) {
  988. if ( isFinite( scalar ) ) {
  989. this.x *= scalar;
  990. this.y *= scalar;
  991. } else {
  992. this.x = 0;
  993. this.y = 0;
  994. }
  995. return this;
  996. },
  997. divide: function ( v ) {
  998. this.x /= v.x;
  999. this.y /= v.y;
  1000. return this;
  1001. },
  1002. divideScalar: function ( scalar ) {
  1003. return this.multiplyScalar( 1 / scalar );
  1004. },
  1005. min: function ( v ) {
  1006. this.x = Math.min( this.x, v.x );
  1007. this.y = Math.min( this.y, v.y );
  1008. return this;
  1009. },
  1010. max: function ( v ) {
  1011. this.x = Math.max( this.x, v.x );
  1012. this.y = Math.max( this.y, v.y );
  1013. return this;
  1014. },
  1015. clamp: function ( min, max ) {
  1016. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1017. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1018. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1019. return this;
  1020. },
  1021. clampScalar: function () {
  1022. var min, max;
  1023. return function clampScalar( minVal, maxVal ) {
  1024. if ( min === undefined ) {
  1025. min = new THREE.Vector2();
  1026. max = new THREE.Vector2();
  1027. }
  1028. min.set( minVal, minVal );
  1029. max.set( maxVal, maxVal );
  1030. return this.clamp( min, max );
  1031. };
  1032. }(),
  1033. clampLength: function ( min, max ) {
  1034. var length = this.length();
  1035. this.multiplyScalar( Math.max( min, Math.min( max, length ) ) / length );
  1036. return this;
  1037. },
  1038. floor: function () {
  1039. this.x = Math.floor( this.x );
  1040. this.y = Math.floor( this.y );
  1041. return this;
  1042. },
  1043. ceil: function () {
  1044. this.x = Math.ceil( this.x );
  1045. this.y = Math.ceil( this.y );
  1046. return this;
  1047. },
  1048. round: function () {
  1049. this.x = Math.round( this.x );
  1050. this.y = Math.round( this.y );
  1051. return this;
  1052. },
  1053. roundToZero: function () {
  1054. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1055. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1056. return this;
  1057. },
  1058. negate: function () {
  1059. this.x = - this.x;
  1060. this.y = - this.y;
  1061. return this;
  1062. },
  1063. dot: function ( v ) {
  1064. return this.x * v.x + this.y * v.y;
  1065. },
  1066. lengthSq: function () {
  1067. return this.x * this.x + this.y * this.y;
  1068. },
  1069. length: function () {
  1070. return Math.sqrt( this.x * this.x + this.y * this.y );
  1071. },
  1072. lengthManhattan: function() {
  1073. return Math.abs( this.x ) + Math.abs( this.y );
  1074. },
  1075. normalize: function () {
  1076. return this.divideScalar( this.length() );
  1077. },
  1078. angle: function () {
  1079. // computes the angle in radians with respect to the positive x-axis
  1080. var angle = Math.atan2( this.y, this.x );
  1081. if ( angle < 0 ) angle += 2 * Math.PI;
  1082. return angle;
  1083. },
  1084. distanceTo: function ( v ) {
  1085. return Math.sqrt( this.distanceToSquared( v ) );
  1086. },
  1087. distanceToSquared: function ( v ) {
  1088. var dx = this.x - v.x, dy = this.y - v.y;
  1089. return dx * dx + dy * dy;
  1090. },
  1091. setLength: function ( length ) {
  1092. return this.multiplyScalar( length / this.length() );
  1093. },
  1094. lerp: function ( v, alpha ) {
  1095. this.x += ( v.x - this.x ) * alpha;
  1096. this.y += ( v.y - this.y ) * alpha;
  1097. return this;
  1098. },
  1099. lerpVectors: function ( v1, v2, alpha ) {
  1100. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1101. return this;
  1102. },
  1103. equals: function ( v ) {
  1104. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  1105. },
  1106. fromArray: function ( array, offset ) {
  1107. if ( offset === undefined ) offset = 0;
  1108. this.x = array[ offset ];
  1109. this.y = array[ offset + 1 ];
  1110. return this;
  1111. },
  1112. toArray: function ( array, offset ) {
  1113. if ( array === undefined ) array = [];
  1114. if ( offset === undefined ) offset = 0;
  1115. array[ offset ] = this.x;
  1116. array[ offset + 1 ] = this.y;
  1117. return array;
  1118. },
  1119. fromAttribute: function ( attribute, index, offset ) {
  1120. if ( offset === undefined ) offset = 0;
  1121. index = index * attribute.itemSize + offset;
  1122. this.x = attribute.array[ index ];
  1123. this.y = attribute.array[ index + 1 ];
  1124. return this;
  1125. },
  1126. rotateAround: function ( center, angle ) {
  1127. var c = Math.cos( angle ), s = Math.sin( angle );
  1128. var x = this.x - center.x;
  1129. var y = this.y - center.y;
  1130. this.x = x * c - y * s + center.x;
  1131. this.y = x * s + y * c + center.y;
  1132. return this;
  1133. }
  1134. };
  1135. // File:src/math/Vector3.js
  1136. /**
  1137. * @author mrdoob / http://mrdoob.com/
  1138. * @author *kile / http://kile.stravaganza.org/
  1139. * @author philogb / http://blog.thejit.org/
  1140. * @author mikael emtinger / http://gomo.se/
  1141. * @author egraether / http://egraether.com/
  1142. * @author WestLangley / http://github.com/WestLangley
  1143. */
  1144. THREE.Vector3 = function ( x, y, z ) {
  1145. this.x = x || 0;
  1146. this.y = y || 0;
  1147. this.z = z || 0;
  1148. };
  1149. THREE.Vector3.prototype = {
  1150. constructor: THREE.Vector3,
  1151. set: function ( x, y, z ) {
  1152. this.x = x;
  1153. this.y = y;
  1154. this.z = z;
  1155. return this;
  1156. },
  1157. setScalar: function ( scalar ) {
  1158. this.x = scalar;
  1159. this.y = scalar;
  1160. this.z = scalar;
  1161. return this;
  1162. },
  1163. setX: function ( x ) {
  1164. this.x = x;
  1165. return this;
  1166. },
  1167. setY: function ( y ) {
  1168. this.y = y;
  1169. return this;
  1170. },
  1171. setZ: function ( z ) {
  1172. this.z = z;
  1173. return this;
  1174. },
  1175. setComponent: function ( index, value ) {
  1176. switch ( index ) {
  1177. case 0: this.x = value; break;
  1178. case 1: this.y = value; break;
  1179. case 2: this.z = value; break;
  1180. default: throw new Error( 'index is out of range: ' + index );
  1181. }
  1182. },
  1183. getComponent: function ( index ) {
  1184. switch ( index ) {
  1185. case 0: return this.x;
  1186. case 1: return this.y;
  1187. case 2: return this.z;
  1188. default: throw new Error( 'index is out of range: ' + index );
  1189. }
  1190. },
  1191. clone: function () {
  1192. return new this.constructor( this.x, this.y, this.z );
  1193. },
  1194. copy: function ( v ) {
  1195. this.x = v.x;
  1196. this.y = v.y;
  1197. this.z = v.z;
  1198. return this;
  1199. },
  1200. add: function ( v, w ) {
  1201. if ( w !== undefined ) {
  1202. console.warn( 'THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1203. return this.addVectors( v, w );
  1204. }
  1205. this.x += v.x;
  1206. this.y += v.y;
  1207. this.z += v.z;
  1208. return this;
  1209. },
  1210. addScalar: function ( s ) {
  1211. this.x += s;
  1212. this.y += s;
  1213. this.z += s;
  1214. return this;
  1215. },
  1216. addVectors: function ( a, b ) {
  1217. this.x = a.x + b.x;
  1218. this.y = a.y + b.y;
  1219. this.z = a.z + b.z;
  1220. return this;
  1221. },
  1222. addScaledVector: function ( v, s ) {
  1223. this.x += v.x * s;
  1224. this.y += v.y * s;
  1225. this.z += v.z * s;
  1226. return this;
  1227. },
  1228. sub: function ( v, w ) {
  1229. if ( w !== undefined ) {
  1230. console.warn( 'THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1231. return this.subVectors( v, w );
  1232. }
  1233. this.x -= v.x;
  1234. this.y -= v.y;
  1235. this.z -= v.z;
  1236. return this;
  1237. },
  1238. subScalar: function ( s ) {
  1239. this.x -= s;
  1240. this.y -= s;
  1241. this.z -= s;
  1242. return this;
  1243. },
  1244. subVectors: function ( a, b ) {
  1245. this.x = a.x - b.x;
  1246. this.y = a.y - b.y;
  1247. this.z = a.z - b.z;
  1248. return this;
  1249. },
  1250. multiply: function ( v, w ) {
  1251. if ( w !== undefined ) {
  1252. console.warn( 'THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.' );
  1253. return this.multiplyVectors( v, w );
  1254. }
  1255. this.x *= v.x;
  1256. this.y *= v.y;
  1257. this.z *= v.z;
  1258. return this;
  1259. },
  1260. multiplyScalar: function ( scalar ) {
  1261. if ( isFinite( scalar ) ) {
  1262. this.x *= scalar;
  1263. this.y *= scalar;
  1264. this.z *= scalar;
  1265. } else {
  1266. this.x = 0;
  1267. this.y = 0;
  1268. this.z = 0;
  1269. }
  1270. return this;
  1271. },
  1272. multiplyVectors: function ( a, b ) {
  1273. this.x = a.x * b.x;
  1274. this.y = a.y * b.y;
  1275. this.z = a.z * b.z;
  1276. return this;
  1277. },
  1278. applyEuler: function () {
  1279. var quaternion;
  1280. return function applyEuler( euler ) {
  1281. if ( euler instanceof THREE.Euler === false ) {
  1282. console.error( 'THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  1283. }
  1284. if ( quaternion === undefined ) quaternion = new THREE.Quaternion();
  1285. this.applyQuaternion( quaternion.setFromEuler( euler ) );
  1286. return this;
  1287. };
  1288. }(),
  1289. applyAxisAngle: function () {
  1290. var quaternion;
  1291. return function applyAxisAngle( axis, angle ) {
  1292. if ( quaternion === undefined ) quaternion = new THREE.Quaternion();
  1293. this.applyQuaternion( quaternion.setFromAxisAngle( axis, angle ) );
  1294. return this;
  1295. };
  1296. }(),
  1297. applyMatrix3: function ( m ) {
  1298. var x = this.x;
  1299. var y = this.y;
  1300. var z = this.z;
  1301. var e = m.elements;
  1302. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
  1303. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
  1304. this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
  1305. return this;
  1306. },
  1307. applyMatrix4: function ( m ) {
  1308. // input: THREE.Matrix4 affine matrix
  1309. var x = this.x, y = this.y, z = this.z;
  1310. var e = m.elements;
  1311. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ];
  1312. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ];
  1313. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ];
  1314. return this;
  1315. },
  1316. applyProjection: function ( m ) {
  1317. // input: THREE.Matrix4 projection matrix
  1318. var x = this.x, y = this.y, z = this.z;
  1319. var e = m.elements;
  1320. var d = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] ); // perspective divide
  1321. this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * d;
  1322. this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * d;
  1323. this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * d;
  1324. return this;
  1325. },
  1326. applyQuaternion: function ( q ) {
  1327. var x = this.x;
  1328. var y = this.y;
  1329. var z = this.z;
  1330. var qx = q.x;
  1331. var qy = q.y;
  1332. var qz = q.z;
  1333. var qw = q.w;
  1334. // calculate quat * vector
  1335. var ix = qw * x + qy * z - qz * y;
  1336. var iy = qw * y + qz * x - qx * z;
  1337. var iz = qw * z + qx * y - qy * x;
  1338. var iw = - qx * x - qy * y - qz * z;
  1339. // calculate result * inverse quat
  1340. this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
  1341. this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
  1342. this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
  1343. return this;
  1344. },
  1345. project: function () {
  1346. var matrix;
  1347. return function project( camera ) {
  1348. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  1349. matrix.multiplyMatrices( camera.projectionMatrix, matrix.getInverse( camera.matrixWorld ) );
  1350. return this.applyProjection( matrix );
  1351. };
  1352. }(),
  1353. unproject: function () {
  1354. var matrix;
  1355. return function unproject( camera ) {
  1356. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  1357. matrix.multiplyMatrices( camera.matrixWorld, matrix.getInverse( camera.projectionMatrix ) );
  1358. return this.applyProjection( matrix );
  1359. };
  1360. }(),
  1361. transformDirection: function ( m ) {
  1362. // input: THREE.Matrix4 affine matrix
  1363. // vector interpreted as a direction
  1364. var x = this.x, y = this.y, z = this.z;
  1365. var e = m.elements;
  1366. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
  1367. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
  1368. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
  1369. this.normalize();
  1370. return this;
  1371. },
  1372. divide: function ( v ) {
  1373. this.x /= v.x;
  1374. this.y /= v.y;
  1375. this.z /= v.z;
  1376. return this;
  1377. },
  1378. divideScalar: function ( scalar ) {
  1379. return this.multiplyScalar( 1 / scalar );
  1380. },
  1381. min: function ( v ) {
  1382. this.x = Math.min( this.x, v.x );
  1383. this.y = Math.min( this.y, v.y );
  1384. this.z = Math.min( this.z, v.z );
  1385. return this;
  1386. },
  1387. max: function ( v ) {
  1388. this.x = Math.max( this.x, v.x );
  1389. this.y = Math.max( this.y, v.y );
  1390. this.z = Math.max( this.z, v.z );
  1391. return this;
  1392. },
  1393. clamp: function ( min, max ) {
  1394. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1395. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1396. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1397. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  1398. return this;
  1399. },
  1400. clampScalar: function () {
  1401. var min, max;
  1402. return function clampScalar( minVal, maxVal ) {
  1403. if ( min === undefined ) {
  1404. min = new THREE.Vector3();
  1405. max = new THREE.Vector3();
  1406. }
  1407. min.set( minVal, minVal, minVal );
  1408. max.set( maxVal, maxVal, maxVal );
  1409. return this.clamp( min, max );
  1410. };
  1411. }(),
  1412. clampLength: function ( min, max ) {
  1413. var length = this.length();
  1414. this.multiplyScalar( Math.max( min, Math.min( max, length ) ) / length );
  1415. return this;
  1416. },
  1417. floor: function () {
  1418. this.x = Math.floor( this.x );
  1419. this.y = Math.floor( this.y );
  1420. this.z = Math.floor( this.z );
  1421. return this;
  1422. },
  1423. ceil: function () {
  1424. this.x = Math.ceil( this.x );
  1425. this.y = Math.ceil( this.y );
  1426. this.z = Math.ceil( this.z );
  1427. return this;
  1428. },
  1429. round: function () {
  1430. this.x = Math.round( this.x );
  1431. this.y = Math.round( this.y );
  1432. this.z = Math.round( this.z );
  1433. return this;
  1434. },
  1435. roundToZero: function () {
  1436. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1437. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1438. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1439. return this;
  1440. },
  1441. negate: function () {
  1442. this.x = - this.x;
  1443. this.y = - this.y;
  1444. this.z = - this.z;
  1445. return this;
  1446. },
  1447. dot: function ( v ) {
  1448. return this.x * v.x + this.y * v.y + this.z * v.z;
  1449. },
  1450. lengthSq: function () {
  1451. return this.x * this.x + this.y * this.y + this.z * this.z;
  1452. },
  1453. length: function () {
  1454. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
  1455. },
  1456. lengthManhattan: function () {
  1457. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  1458. },
  1459. normalize: function () {
  1460. return this.divideScalar( this.length() );
  1461. },
  1462. setLength: function ( length ) {
  1463. return this.multiplyScalar( length / this.length() );
  1464. },
  1465. lerp: function ( v, alpha ) {
  1466. this.x += ( v.x - this.x ) * alpha;
  1467. this.y += ( v.y - this.y ) * alpha;
  1468. this.z += ( v.z - this.z ) * alpha;
  1469. return this;
  1470. },
  1471. lerpVectors: function ( v1, v2, alpha ) {
  1472. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1473. return this;
  1474. },
  1475. cross: function ( v, w ) {
  1476. if ( w !== undefined ) {
  1477. console.warn( 'THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.' );
  1478. return this.crossVectors( v, w );
  1479. }
  1480. var x = this.x, y = this.y, z = this.z;
  1481. this.x = y * v.z - z * v.y;
  1482. this.y = z * v.x - x * v.z;
  1483. this.z = x * v.y - y * v.x;
  1484. return this;
  1485. },
  1486. crossVectors: function ( a, b ) {
  1487. var ax = a.x, ay = a.y, az = a.z;
  1488. var bx = b.x, by = b.y, bz = b.z;
  1489. this.x = ay * bz - az * by;
  1490. this.y = az * bx - ax * bz;
  1491. this.z = ax * by - ay * bx;
  1492. return this;
  1493. },
  1494. projectOnVector: function () {
  1495. var v1, dot;
  1496. return function projectOnVector( vector ) {
  1497. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1498. v1.copy( vector ).normalize();
  1499. dot = this.dot( v1 );
  1500. return this.copy( v1 ).multiplyScalar( dot );
  1501. };
  1502. }(),
  1503. projectOnPlane: function () {
  1504. var v1;
  1505. return function projectOnPlane( planeNormal ) {
  1506. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1507. v1.copy( this ).projectOnVector( planeNormal );
  1508. return this.sub( v1 );
  1509. };
  1510. }(),
  1511. reflect: function () {
  1512. // reflect incident vector off plane orthogonal to normal
  1513. // normal is assumed to have unit length
  1514. var v1;
  1515. return function reflect( normal ) {
  1516. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1517. return this.sub( v1.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
  1518. };
  1519. }(),
  1520. angleTo: function ( v ) {
  1521. var theta = this.dot( v ) / ( Math.sqrt( this.lengthSq() * v.lengthSq() ) );
  1522. // clamp, to handle numerical problems
  1523. return Math.acos( THREE.Math.clamp( theta, - 1, 1 ) );
  1524. },
  1525. distanceTo: function ( v ) {
  1526. return Math.sqrt( this.distanceToSquared( v ) );
  1527. },
  1528. distanceToSquared: function ( v ) {
  1529. var dx = this.x - v.x;
  1530. var dy = this.y - v.y;
  1531. var dz = this.z - v.z;
  1532. return dx * dx + dy * dy + dz * dz;
  1533. },
  1534. setFromSpherical: function( s ) {
  1535. var sinPhiRadius = Math.sin( s.phi ) * s.radius;
  1536. this.x = sinPhiRadius * Math.sin( s.theta );
  1537. this.y = Math.cos( s.phi ) * s.radius;
  1538. this.z = sinPhiRadius * Math.cos( s.theta );
  1539. return this;
  1540. },
  1541. setFromMatrixPosition: function ( m ) {
  1542. return this.setFromMatrixColumn( m, 3 );
  1543. },
  1544. setFromMatrixScale: function ( m ) {
  1545. var sx = this.setFromMatrixColumn( m, 0 ).length();
  1546. var sy = this.setFromMatrixColumn( m, 1 ).length();
  1547. var sz = this.setFromMatrixColumn( m, 2 ).length();
  1548. this.x = sx;
  1549. this.y = sy;
  1550. this.z = sz;
  1551. return this;
  1552. },
  1553. setFromMatrixColumn: function ( m, index ) {
  1554. if ( typeof m === 'number' ) {
  1555. console.warn( 'THREE.Vector3: setFromMatrixColumn now expects ( matrix, index ).' );
  1556. m = arguments[ 1 ];
  1557. index = arguments[ 0 ];
  1558. }
  1559. return this.fromArray( m.elements, index * 4 );
  1560. },
  1561. equals: function ( v ) {
  1562. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  1563. },
  1564. fromArray: function ( array, offset ) {
  1565. if ( offset === undefined ) offset = 0;
  1566. this.x = array[ offset ];
  1567. this.y = array[ offset + 1 ];
  1568. this.z = array[ offset + 2 ];
  1569. return this;
  1570. },
  1571. toArray: function ( array, offset ) {
  1572. if ( array === undefined ) array = [];
  1573. if ( offset === undefined ) offset = 0;
  1574. array[ offset ] = this.x;
  1575. array[ offset + 1 ] = this.y;
  1576. array[ offset + 2 ] = this.z;
  1577. return array;
  1578. },
  1579. fromAttribute: function ( attribute, index, offset ) {
  1580. if ( offset === undefined ) offset = 0;
  1581. index = index * attribute.itemSize + offset;
  1582. this.x = attribute.array[ index ];
  1583. this.y = attribute.array[ index + 1 ];
  1584. this.z = attribute.array[ index + 2 ];
  1585. return this;
  1586. }
  1587. };
  1588. // File:src/math/Vector4.js
  1589. /**
  1590. * @author supereggbert / http://www.paulbrunt.co.uk/
  1591. * @author philogb / http://blog.thejit.org/
  1592. * @author mikael emtinger / http://gomo.se/
  1593. * @author egraether / http://egraether.com/
  1594. * @author WestLangley / http://github.com/WestLangley
  1595. */
  1596. THREE.Vector4 = function ( x, y, z, w ) {
  1597. this.x = x || 0;
  1598. this.y = y || 0;
  1599. this.z = z || 0;
  1600. this.w = ( w !== undefined ) ? w : 1;
  1601. };
  1602. THREE.Vector4.prototype = {
  1603. constructor: THREE.Vector4,
  1604. set: function ( x, y, z, w ) {
  1605. this.x = x;
  1606. this.y = y;
  1607. this.z = z;
  1608. this.w = w;
  1609. return this;
  1610. },
  1611. setScalar: function ( scalar ) {
  1612. this.x = scalar;
  1613. this.y = scalar;
  1614. this.z = scalar;
  1615. this.w = scalar;
  1616. return this;
  1617. },
  1618. setX: function ( x ) {
  1619. this.x = x;
  1620. return this;
  1621. },
  1622. setY: function ( y ) {
  1623. this.y = y;
  1624. return this;
  1625. },
  1626. setZ: function ( z ) {
  1627. this.z = z;
  1628. return this;
  1629. },
  1630. setW: function ( w ) {
  1631. this.w = w;
  1632. return this;
  1633. },
  1634. setComponent: function ( index, value ) {
  1635. switch ( index ) {
  1636. case 0: this.x = value; break;
  1637. case 1: this.y = value; break;
  1638. case 2: this.z = value; break;
  1639. case 3: this.w = value; break;
  1640. default: throw new Error( 'index is out of range: ' + index );
  1641. }
  1642. },
  1643. getComponent: function ( index ) {
  1644. switch ( index ) {
  1645. case 0: return this.x;
  1646. case 1: return this.y;
  1647. case 2: return this.z;
  1648. case 3: return this.w;
  1649. default: throw new Error( 'index is out of range: ' + index );
  1650. }
  1651. },
  1652. clone: function () {
  1653. return new this.constructor( this.x, this.y, this.z, this.w );
  1654. },
  1655. copy: function ( v ) {
  1656. this.x = v.x;
  1657. this.y = v.y;
  1658. this.z = v.z;
  1659. this.w = ( v.w !== undefined ) ? v.w : 1;
  1660. return this;
  1661. },
  1662. add: function ( v, w ) {
  1663. if ( w !== undefined ) {
  1664. console.warn( 'THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1665. return this.addVectors( v, w );
  1666. }
  1667. this.x += v.x;
  1668. this.y += v.y;
  1669. this.z += v.z;
  1670. this.w += v.w;
  1671. return this;
  1672. },
  1673. addScalar: function ( s ) {
  1674. this.x += s;
  1675. this.y += s;
  1676. this.z += s;
  1677. this.w += s;
  1678. return this;
  1679. },
  1680. addVectors: function ( a, b ) {
  1681. this.x = a.x + b.x;
  1682. this.y = a.y + b.y;
  1683. this.z = a.z + b.z;
  1684. this.w = a.w + b.w;
  1685. return this;
  1686. },
  1687. addScaledVector: function ( v, s ) {
  1688. this.x += v.x * s;
  1689. this.y += v.y * s;
  1690. this.z += v.z * s;
  1691. this.w += v.w * s;
  1692. return this;
  1693. },
  1694. sub: function ( v, w ) {
  1695. if ( w !== undefined ) {
  1696. console.warn( 'THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1697. return this.subVectors( v, w );
  1698. }
  1699. this.x -= v.x;
  1700. this.y -= v.y;
  1701. this.z -= v.z;
  1702. this.w -= v.w;
  1703. return this;
  1704. },
  1705. subScalar: function ( s ) {
  1706. this.x -= s;
  1707. this.y -= s;
  1708. this.z -= s;
  1709. this.w -= s;
  1710. return this;
  1711. },
  1712. subVectors: function ( a, b ) {
  1713. this.x = a.x - b.x;
  1714. this.y = a.y - b.y;
  1715. this.z = a.z - b.z;
  1716. this.w = a.w - b.w;
  1717. return this;
  1718. },
  1719. multiplyScalar: function ( scalar ) {
  1720. if ( isFinite( scalar ) ) {
  1721. this.x *= scalar;
  1722. this.y *= scalar;
  1723. this.z *= scalar;
  1724. this.w *= scalar;
  1725. } else {
  1726. this.x = 0;
  1727. this.y = 0;
  1728. this.z = 0;
  1729. this.w = 0;
  1730. }
  1731. return this;
  1732. },
  1733. applyMatrix4: function ( m ) {
  1734. var x = this.x;
  1735. var y = this.y;
  1736. var z = this.z;
  1737. var w = this.w;
  1738. var e = m.elements;
  1739. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  1740. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  1741. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  1742. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  1743. return this;
  1744. },
  1745. divideScalar: function ( scalar ) {
  1746. return this.multiplyScalar( 1 / scalar );
  1747. },
  1748. setAxisAngleFromQuaternion: function ( q ) {
  1749. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  1750. // q is assumed to be normalized
  1751. this.w = 2 * Math.acos( q.w );
  1752. var s = Math.sqrt( 1 - q.w * q.w );
  1753. if ( s < 0.0001 ) {
  1754. this.x = 1;
  1755. this.y = 0;
  1756. this.z = 0;
  1757. } else {
  1758. this.x = q.x / s;
  1759. this.y = q.y / s;
  1760. this.z = q.z / s;
  1761. }
  1762. return this;
  1763. },
  1764. setAxisAngleFromRotationMatrix: function ( m ) {
  1765. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  1766. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1767. var angle, x, y, z, // variables for result
  1768. epsilon = 0.01, // margin to allow for rounding errors
  1769. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  1770. te = m.elements,
  1771. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  1772. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  1773. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  1774. if ( ( Math.abs( m12 - m21 ) < epsilon )
  1775. && ( Math.abs( m13 - m31 ) < epsilon )
  1776. && ( Math.abs( m23 - m32 ) < epsilon ) ) {
  1777. // singularity found
  1778. // first check for identity matrix which must have +1 for all terms
  1779. // in leading diagonal and zero in other terms
  1780. if ( ( Math.abs( m12 + m21 ) < epsilon2 )
  1781. && ( Math.abs( m13 + m31 ) < epsilon2 )
  1782. && ( Math.abs( m23 + m32 ) < epsilon2 )
  1783. && ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  1784. // this singularity is identity matrix so angle = 0
  1785. this.set( 1, 0, 0, 0 );
  1786. return this; // zero angle, arbitrary axis
  1787. }
  1788. // otherwise this singularity is angle = 180
  1789. angle = Math.PI;
  1790. var xx = ( m11 + 1 ) / 2;
  1791. var yy = ( m22 + 1 ) / 2;
  1792. var zz = ( m33 + 1 ) / 2;
  1793. var xy = ( m12 + m21 ) / 4;
  1794. var xz = ( m13 + m31 ) / 4;
  1795. var yz = ( m23 + m32 ) / 4;
  1796. if ( ( xx > yy ) && ( xx > zz ) ) {
  1797. // m11 is the largest diagonal term
  1798. if ( xx < epsilon ) {
  1799. x = 0;
  1800. y = 0.707106781;
  1801. z = 0.707106781;
  1802. } else {
  1803. x = Math.sqrt( xx );
  1804. y = xy / x;
  1805. z = xz / x;
  1806. }
  1807. } else if ( yy > zz ) {
  1808. // m22 is the largest diagonal term
  1809. if ( yy < epsilon ) {
  1810. x = 0.707106781;
  1811. y = 0;
  1812. z = 0.707106781;
  1813. } else {
  1814. y = Math.sqrt( yy );
  1815. x = xy / y;
  1816. z = yz / y;
  1817. }
  1818. } else {
  1819. // m33 is the largest diagonal term so base result on this
  1820. if ( zz < epsilon ) {
  1821. x = 0.707106781;
  1822. y = 0.707106781;
  1823. z = 0;
  1824. } else {
  1825. z = Math.sqrt( zz );
  1826. x = xz / z;
  1827. y = yz / z;
  1828. }
  1829. }
  1830. this.set( x, y, z, angle );
  1831. return this; // return 180 deg rotation
  1832. }
  1833. // as we have reached here there are no singularities so we can handle normally
  1834. var s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 )
  1835. + ( m13 - m31 ) * ( m13 - m31 )
  1836. + ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  1837. if ( Math.abs( s ) < 0.001 ) s = 1;
  1838. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  1839. // caught by singularity test above, but I've left it in just in case
  1840. this.x = ( m32 - m23 ) / s;
  1841. this.y = ( m13 - m31 ) / s;
  1842. this.z = ( m21 - m12 ) / s;
  1843. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  1844. return this;
  1845. },
  1846. min: function ( v ) {
  1847. this.x = Math.min( this.x, v.x );
  1848. this.y = Math.min( this.y, v.y );
  1849. this.z = Math.min( this.z, v.z );
  1850. this.w = Math.min( this.w, v.w );
  1851. return this;
  1852. },
  1853. max: function ( v ) {
  1854. this.x = Math.max( this.x, v.x );
  1855. this.y = Math.max( this.y, v.y );
  1856. this.z = Math.max( this.z, v.z );
  1857. this.w = Math.max( this.w, v.w );
  1858. return this;
  1859. },
  1860. clamp: function ( min, max ) {
  1861. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1862. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1863. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1864. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  1865. this.w = Math.max( min.w, Math.min( max.w, this.w ) );
  1866. return this;
  1867. },
  1868. clampScalar: function () {
  1869. var min, max;
  1870. return function clampScalar( minVal, maxVal ) {
  1871. if ( min === undefined ) {
  1872. min = new THREE.Vector4();
  1873. max = new THREE.Vector4();
  1874. }
  1875. min.set( minVal, minVal, minVal, minVal );
  1876. max.set( maxVal, maxVal, maxVal, maxVal );
  1877. return this.clamp( min, max );
  1878. };
  1879. }(),
  1880. floor: function () {
  1881. this.x = Math.floor( this.x );
  1882. this.y = Math.floor( this.y );
  1883. this.z = Math.floor( this.z );
  1884. this.w = Math.floor( this.w );
  1885. return this;
  1886. },
  1887. ceil: function () {
  1888. this.x = Math.ceil( this.x );
  1889. this.y = Math.ceil( this.y );
  1890. this.z = Math.ceil( this.z );
  1891. this.w = Math.ceil( this.w );
  1892. return this;
  1893. },
  1894. round: function () {
  1895. this.x = Math.round( this.x );
  1896. this.y = Math.round( this.y );
  1897. this.z = Math.round( this.z );
  1898. this.w = Math.round( this.w );
  1899. return this;
  1900. },
  1901. roundToZero: function () {
  1902. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1903. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1904. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1905. this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
  1906. return this;
  1907. },
  1908. negate: function () {
  1909. this.x = - this.x;
  1910. this.y = - this.y;
  1911. this.z = - this.z;
  1912. this.w = - this.w;
  1913. return this;
  1914. },
  1915. dot: function ( v ) {
  1916. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  1917. },
  1918. lengthSq: function () {
  1919. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  1920. },
  1921. length: function () {
  1922. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  1923. },
  1924. lengthManhattan: function () {
  1925. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  1926. },
  1927. normalize: function () {
  1928. return this.divideScalar( this.length() );
  1929. },
  1930. setLength: function ( length ) {
  1931. return this.multiplyScalar( length / this.length() );
  1932. },
  1933. lerp: function ( v, alpha ) {
  1934. this.x += ( v.x - this.x ) * alpha;
  1935. this.y += ( v.y - this.y ) * alpha;
  1936. this.z += ( v.z - this.z ) * alpha;
  1937. this.w += ( v.w - this.w ) * alpha;
  1938. return this;
  1939. },
  1940. lerpVectors: function ( v1, v2, alpha ) {
  1941. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1942. return this;
  1943. },
  1944. equals: function ( v ) {
  1945. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  1946. },
  1947. fromArray: function ( array, offset ) {
  1948. if ( offset === undefined ) offset = 0;
  1949. this.x = array[ offset ];
  1950. this.y = array[ offset + 1 ];
  1951. this.z = array[ offset + 2 ];
  1952. this.w = array[ offset + 3 ];
  1953. return this;
  1954. },
  1955. toArray: function ( array, offset ) {
  1956. if ( array === undefined ) array = [];
  1957. if ( offset === undefined ) offset = 0;
  1958. array[ offset ] = this.x;
  1959. array[ offset + 1 ] = this.y;
  1960. array[ offset + 2 ] = this.z;
  1961. array[ offset + 3 ] = this.w;
  1962. return array;
  1963. },
  1964. fromAttribute: function ( attribute, index, offset ) {
  1965. if ( offset === undefined ) offset = 0;
  1966. index = index * attribute.itemSize + offset;
  1967. this.x = attribute.array[ index ];
  1968. this.y = attribute.array[ index + 1 ];
  1969. this.z = attribute.array[ index + 2 ];
  1970. this.w = attribute.array[ index + 3 ];
  1971. return this;
  1972. }
  1973. };
  1974. // File:src/math/Euler.js
  1975. /**
  1976. * @author mrdoob / http://mrdoob.com/
  1977. * @author WestLangley / http://github.com/WestLangley
  1978. * @author bhouston / http://clara.io
  1979. */
  1980. THREE.Euler = function ( x, y, z, order ) {
  1981. this._x = x || 0;
  1982. this._y = y || 0;
  1983. this._z = z || 0;
  1984. this._order = order || THREE.Euler.DefaultOrder;
  1985. };
  1986. THREE.Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
  1987. THREE.Euler.DefaultOrder = 'XYZ';
  1988. THREE.Euler.prototype = {
  1989. constructor: THREE.Euler,
  1990. get x () {
  1991. return this._x;
  1992. },
  1993. set x ( value ) {
  1994. this._x = value;
  1995. this.onChangeCallback();
  1996. },
  1997. get y () {
  1998. return this._y;
  1999. },
  2000. set y ( value ) {
  2001. this._y = value;
  2002. this.onChangeCallback();
  2003. },
  2004. get z () {
  2005. return this._z;
  2006. },
  2007. set z ( value ) {
  2008. this._z = value;
  2009. this.onChangeCallback();
  2010. },
  2011. get order () {
  2012. return this._order;
  2013. },
  2014. set order ( value ) {
  2015. this._order = value;
  2016. this.onChangeCallback();
  2017. },
  2018. set: function ( x, y, z, order ) {
  2019. this._x = x;
  2020. this._y = y;
  2021. this._z = z;
  2022. this._order = order || this._order;
  2023. this.onChangeCallback();
  2024. return this;
  2025. },
  2026. clone: function () {
  2027. return new this.constructor( this._x, this._y, this._z, this._order );
  2028. },
  2029. copy: function ( euler ) {
  2030. this._x = euler._x;
  2031. this._y = euler._y;
  2032. this._z = euler._z;
  2033. this._order = euler._order;
  2034. this.onChangeCallback();
  2035. return this;
  2036. },
  2037. setFromRotationMatrix: function ( m, order, update ) {
  2038. var clamp = THREE.Math.clamp;
  2039. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2040. var te = m.elements;
  2041. var m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  2042. var m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  2043. var m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  2044. order = order || this._order;
  2045. if ( order === 'XYZ' ) {
  2046. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  2047. if ( Math.abs( m13 ) < 0.99999 ) {
  2048. this._x = Math.atan2( - m23, m33 );
  2049. this._z = Math.atan2( - m12, m11 );
  2050. } else {
  2051. this._x = Math.atan2( m32, m22 );
  2052. this._z = 0;
  2053. }
  2054. } else if ( order === 'YXZ' ) {
  2055. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  2056. if ( Math.abs( m23 ) < 0.99999 ) {
  2057. this._y = Math.atan2( m13, m33 );
  2058. this._z = Math.atan2( m21, m22 );
  2059. } else {
  2060. this._y = Math.atan2( - m31, m11 );
  2061. this._z = 0;
  2062. }
  2063. } else if ( order === 'ZXY' ) {
  2064. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  2065. if ( Math.abs( m32 ) < 0.99999 ) {
  2066. this._y = Math.atan2( - m31, m33 );
  2067. this._z = Math.atan2( - m12, m22 );
  2068. } else {
  2069. this._y = 0;
  2070. this._z = Math.atan2( m21, m11 );
  2071. }
  2072. } else if ( order === 'ZYX' ) {
  2073. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  2074. if ( Math.abs( m31 ) < 0.99999 ) {
  2075. this._x = Math.atan2( m32, m33 );
  2076. this._z = Math.atan2( m21, m11 );
  2077. } else {
  2078. this._x = 0;
  2079. this._z = Math.atan2( - m12, m22 );
  2080. }
  2081. } else if ( order === 'YZX' ) {
  2082. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  2083. if ( Math.abs( m21 ) < 0.99999 ) {
  2084. this._x = Math.atan2( - m23, m22 );
  2085. this._y = Math.atan2( - m31, m11 );
  2086. } else {
  2087. this._x = 0;
  2088. this._y = Math.atan2( m13, m33 );
  2089. }
  2090. } else if ( order === 'XZY' ) {
  2091. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  2092. if ( Math.abs( m12 ) < 0.99999 ) {
  2093. this._x = Math.atan2( m32, m22 );
  2094. this._y = Math.atan2( m13, m11 );
  2095. } else {
  2096. this._x = Math.atan2( - m23, m33 );
  2097. this._y = 0;
  2098. }
  2099. } else {
  2100. console.warn( 'THREE.Euler: .setFromRotationMatrix() given unsupported order: ' + order )
  2101. }
  2102. this._order = order;
  2103. if ( update !== false ) this.onChangeCallback();
  2104. return this;
  2105. },
  2106. setFromQuaternion: function () {
  2107. var matrix;
  2108. return function ( q, order, update ) {
  2109. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  2110. matrix.makeRotationFromQuaternion( q );
  2111. this.setFromRotationMatrix( matrix, order, update );
  2112. return this;
  2113. };
  2114. }(),
  2115. setFromVector3: function ( v, order ) {
  2116. return this.set( v.x, v.y, v.z, order || this._order );
  2117. },
  2118. reorder: function () {
  2119. // WARNING: this discards revolution information -bhouston
  2120. var q = new THREE.Quaternion();
  2121. return function ( newOrder ) {
  2122. q.setFromEuler( this );
  2123. this.setFromQuaternion( q, newOrder );
  2124. };
  2125. }(),
  2126. equals: function ( euler ) {
  2127. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  2128. },
  2129. fromArray: function ( array ) {
  2130. this._x = array[ 0 ];
  2131. this._y = array[ 1 ];
  2132. this._z = array[ 2 ];
  2133. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  2134. this.onChangeCallback();
  2135. return this;
  2136. },
  2137. toArray: function ( array, offset ) {
  2138. if ( array === undefined ) array = [];
  2139. if ( offset === undefined ) offset = 0;
  2140. array[ offset ] = this._x;
  2141. array[ offset + 1 ] = this._y;
  2142. array[ offset + 2 ] = this._z;
  2143. array[ offset + 3 ] = this._order;
  2144. return array;
  2145. },
  2146. toVector3: function ( optionalResult ) {
  2147. if ( optionalResult ) {
  2148. return optionalResult.set( this._x, this._y, this._z );
  2149. } else {
  2150. return new THREE.Vector3( this._x, this._y, this._z );
  2151. }
  2152. },
  2153. onChange: function ( callback ) {
  2154. this.onChangeCallback = callback;
  2155. return this;
  2156. },
  2157. onChangeCallback: function () {}
  2158. };
  2159. // File:src/math/Line3.js
  2160. /**
  2161. * @author bhouston / http://clara.io
  2162. */
  2163. THREE.Line3 = function ( start, end ) {
  2164. this.start = ( start !== undefined ) ? start : new THREE.Vector3();
  2165. this.end = ( end !== undefined ) ? end : new THREE.Vector3();
  2166. };
  2167. THREE.Line3.prototype = {
  2168. constructor: THREE.Line3,
  2169. set: function ( start, end ) {
  2170. this.start.copy( start );
  2171. this.end.copy( end );
  2172. return this;
  2173. },
  2174. clone: function () {
  2175. return new this.constructor().copy( this );
  2176. },
  2177. copy: function ( line ) {
  2178. this.start.copy( line.start );
  2179. this.end.copy( line.end );
  2180. return this;
  2181. },
  2182. center: function ( optionalTarget ) {
  2183. var result = optionalTarget || new THREE.Vector3();
  2184. return result.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  2185. },
  2186. delta: function ( optionalTarget ) {
  2187. var result = optionalTarget || new THREE.Vector3();
  2188. return result.subVectors( this.end, this.start );
  2189. },
  2190. distanceSq: function () {
  2191. return this.start.distanceToSquared( this.end );
  2192. },
  2193. distance: function () {
  2194. return this.start.distanceTo( this.end );
  2195. },
  2196. at: function ( t, optionalTarget ) {
  2197. var result = optionalTarget || new THREE.Vector3();
  2198. return this.delta( result ).multiplyScalar( t ).add( this.start );
  2199. },
  2200. closestPointToPointParameter: function () {
  2201. var startP = new THREE.Vector3();
  2202. var startEnd = new THREE.Vector3();
  2203. return function ( point, clampToLine ) {
  2204. startP.subVectors( point, this.start );
  2205. startEnd.subVectors( this.end, this.start );
  2206. var startEnd2 = startEnd.dot( startEnd );
  2207. var startEnd_startP = startEnd.dot( startP );
  2208. var t = startEnd_startP / startEnd2;
  2209. if ( clampToLine ) {
  2210. t = THREE.Math.clamp( t, 0, 1 );
  2211. }
  2212. return t;
  2213. };
  2214. }(),
  2215. closestPointToPoint: function ( point, clampToLine, optionalTarget ) {
  2216. var t = this.closestPointToPointParameter( point, clampToLine );
  2217. var result = optionalTarget || new THREE.Vector3();
  2218. return this.delta( result ).multiplyScalar( t ).add( this.start );
  2219. },
  2220. applyMatrix4: function ( matrix ) {
  2221. this.start.applyMatrix4( matrix );
  2222. this.end.applyMatrix4( matrix );
  2223. return this;
  2224. },
  2225. equals: function ( line ) {
  2226. return line.start.equals( this.start ) && line.end.equals( this.end );
  2227. }
  2228. };
  2229. // File:src/math/Box2.js
  2230. /**
  2231. * @author bhouston / http://clara.io
  2232. */
  2233. THREE.Box2 = function ( min, max ) {
  2234. this.min = ( min !== undefined ) ? min : new THREE.Vector2( + Infinity, + Infinity );
  2235. this.max = ( max !== undefined ) ? max : new THREE.Vector2( - Infinity, - Infinity );
  2236. };
  2237. THREE.Box2.prototype = {
  2238. constructor: THREE.Box2,
  2239. set: function ( min, max ) {
  2240. this.min.copy( min );
  2241. this.max.copy( max );
  2242. return this;
  2243. },
  2244. setFromPoints: function ( points ) {
  2245. this.makeEmpty();
  2246. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2247. this.expandByPoint( points[ i ] );
  2248. }
  2249. return this;
  2250. },
  2251. setFromCenterAndSize: function () {
  2252. var v1 = new THREE.Vector2();
  2253. return function ( center, size ) {
  2254. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2255. this.min.copy( center ).sub( halfSize );
  2256. this.max.copy( center ).add( halfSize );
  2257. return this;
  2258. };
  2259. }(),
  2260. clone: function () {
  2261. return new this.constructor().copy( this );
  2262. },
  2263. copy: function ( box ) {
  2264. this.min.copy( box.min );
  2265. this.max.copy( box.max );
  2266. return this;
  2267. },
  2268. makeEmpty: function () {
  2269. this.min.x = this.min.y = + Infinity;
  2270. this.max.x = this.max.y = - Infinity;
  2271. return this;
  2272. },
  2273. isEmpty: function () {
  2274. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2275. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  2276. },
  2277. center: function ( optionalTarget ) {
  2278. var result = optionalTarget || new THREE.Vector2();
  2279. return result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2280. },
  2281. size: function ( optionalTarget ) {
  2282. var result = optionalTarget || new THREE.Vector2();
  2283. return result.subVectors( this.max, this.min );
  2284. },
  2285. expandByPoint: function ( point ) {
  2286. this.min.min( point );
  2287. this.max.max( point );
  2288. return this;
  2289. },
  2290. expandByVector: function ( vector ) {
  2291. this.min.sub( vector );
  2292. this.max.add( vector );
  2293. return this;
  2294. },
  2295. expandByScalar: function ( scalar ) {
  2296. this.min.addScalar( - scalar );
  2297. this.max.addScalar( scalar );
  2298. return this;
  2299. },
  2300. containsPoint: function ( point ) {
  2301. if ( point.x < this.min.x || point.x > this.max.x ||
  2302. point.y < this.min.y || point.y > this.max.y ) {
  2303. return false;
  2304. }
  2305. return true;
  2306. },
  2307. containsBox: function ( box ) {
  2308. if ( ( this.min.x <= box.min.x ) && ( box.max.x <= this.max.x ) &&
  2309. ( this.min.y <= box.min.y ) && ( box.max.y <= this.max.y ) ) {
  2310. return true;
  2311. }
  2312. return false;
  2313. },
  2314. getParameter: function ( point, optionalTarget ) {
  2315. // This can potentially have a divide by zero if the box
  2316. // has a size dimension of 0.
  2317. var result = optionalTarget || new THREE.Vector2();
  2318. return result.set(
  2319. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2320. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  2321. );
  2322. },
  2323. intersectsBox: function ( box ) {
  2324. // using 6 splitting planes to rule out intersections.
  2325. if ( box.max.x < this.min.x || box.min.x > this.max.x ||
  2326. box.max.y < this.min.y || box.min.y > this.max.y ) {
  2327. return false;
  2328. }
  2329. return true;
  2330. },
  2331. clampPoint: function ( point, optionalTarget ) {
  2332. var result = optionalTarget || new THREE.Vector2();
  2333. return result.copy( point ).clamp( this.min, this.max );
  2334. },
  2335. distanceToPoint: function () {
  2336. var v1 = new THREE.Vector2();
  2337. return function ( point ) {
  2338. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  2339. return clampedPoint.sub( point ).length();
  2340. };
  2341. }(),
  2342. intersect: function ( box ) {
  2343. this.min.max( box.min );
  2344. this.max.min( box.max );
  2345. return this;
  2346. },
  2347. union: function ( box ) {
  2348. this.min.min( box.min );
  2349. this.max.max( box.max );
  2350. return this;
  2351. },
  2352. translate: function ( offset ) {
  2353. this.min.add( offset );
  2354. this.max.add( offset );
  2355. return this;
  2356. },
  2357. equals: function ( box ) {
  2358. return box.min.equals( this.min ) && box.max.equals( this.max );
  2359. }
  2360. };
  2361. // File:src/math/Box3.js
  2362. /**
  2363. * @author bhouston / http://clara.io
  2364. * @author WestLangley / http://github.com/WestLangley
  2365. */
  2366. THREE.Box3 = function ( min, max ) {
  2367. this.min = ( min !== undefined ) ? min : new THREE.Vector3( + Infinity, + Infinity, + Infinity );
  2368. this.max = ( max !== undefined ) ? max : new THREE.Vector3( - Infinity, - Infinity, - Infinity );
  2369. };
  2370. THREE.Box3.prototype = {
  2371. constructor: THREE.Box3,
  2372. set: function ( min, max ) {
  2373. this.min.copy( min );
  2374. this.max.copy( max );
  2375. return this;
  2376. },
  2377. setFromArray: function ( array ) {
  2378. this.makeEmpty();
  2379. var minX = + Infinity;
  2380. var minY = + Infinity;
  2381. var minZ = + Infinity;
  2382. var maxX = - Infinity;
  2383. var maxY = - Infinity;
  2384. var maxZ = - Infinity;
  2385. for ( var i = 0, il = array.length; i < il; i += 3 ) {
  2386. var x = array[ i ];
  2387. var y = array[ i + 1 ];
  2388. var z = array[ i + 2 ];
  2389. if ( x < minX ) minX = x;
  2390. if ( y < minY ) minY = y;
  2391. if ( z < minZ ) minZ = z;
  2392. if ( x > maxX ) maxX = x;
  2393. if ( y > maxY ) maxY = y;
  2394. if ( z > maxZ ) maxZ = z;
  2395. }
  2396. this.min.set( minX, minY, minZ );
  2397. this.max.set( maxX, maxY, maxZ );
  2398. },
  2399. setFromPoints: function ( points ) {
  2400. this.makeEmpty();
  2401. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2402. this.expandByPoint( points[ i ] );
  2403. }
  2404. return this;
  2405. },
  2406. setFromCenterAndSize: function () {
  2407. var v1 = new THREE.Vector3();
  2408. return function ( center, size ) {
  2409. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2410. this.min.copy( center ).sub( halfSize );
  2411. this.max.copy( center ).add( halfSize );
  2412. return this;
  2413. };
  2414. }(),
  2415. setFromObject: function () {
  2416. // Computes the world-axis-aligned bounding box of an object (including its children),
  2417. // accounting for both the object's, and children's, world transforms
  2418. var box;
  2419. return function ( object ) {
  2420. if ( box === undefined ) box = new THREE.Box3();
  2421. var scope = this;
  2422. this.makeEmpty();
  2423. object.updateMatrixWorld( true );
  2424. object.traverse( function ( node ) {
  2425. var geometry = node.geometry;
  2426. if ( geometry !== undefined ) {
  2427. if ( geometry.boundingBox === null ) {
  2428. geometry.computeBoundingBox();
  2429. }
  2430. box.copy( geometry.boundingBox );
  2431. box.applyMatrix4( node.matrixWorld );
  2432. scope.union( box );
  2433. }
  2434. } );
  2435. return this;
  2436. };
  2437. }(),
  2438. clone: function () {
  2439. return new this.constructor().copy( this );
  2440. },
  2441. copy: function ( box ) {
  2442. this.min.copy( box.min );
  2443. this.max.copy( box.max );
  2444. return this;
  2445. },
  2446. makeEmpty: function () {
  2447. this.min.x = this.min.y = this.min.z = + Infinity;
  2448. this.max.x = this.max.y = this.max.z = - Infinity;
  2449. return this;
  2450. },
  2451. isEmpty: function () {
  2452. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2453. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  2454. },
  2455. center: function ( optionalTarget ) {
  2456. var result = optionalTarget || new THREE.Vector3();
  2457. return result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2458. },
  2459. size: function ( optionalTarget ) {
  2460. var result = optionalTarget || new THREE.Vector3();
  2461. return result.subVectors( this.max, this.min );
  2462. },
  2463. expandByPoint: function ( point ) {
  2464. this.min.min( point );
  2465. this.max.max( point );
  2466. return this;
  2467. },
  2468. expandByVector: function ( vector ) {
  2469. this.min.sub( vector );
  2470. this.max.add( vector );
  2471. return this;
  2472. },
  2473. expandByScalar: function ( scalar ) {
  2474. this.min.addScalar( - scalar );
  2475. this.max.addScalar( scalar );
  2476. return this;
  2477. },
  2478. containsPoint: function ( point ) {
  2479. if ( point.x < this.min.x || point.x > this.max.x ||
  2480. point.y < this.min.y || point.y > this.max.y ||
  2481. point.z < this.min.z || point.z > this.max.z ) {
  2482. return false;
  2483. }
  2484. return true;
  2485. },
  2486. containsBox: function ( box ) {
  2487. if ( ( this.min.x <= box.min.x ) && ( box.max.x <= this.max.x ) &&
  2488. ( this.min.y <= box.min.y ) && ( box.max.y <= this.max.y ) &&
  2489. ( this.min.z <= box.min.z ) && ( box.max.z <= this.max.z ) ) {
  2490. return true;
  2491. }
  2492. return false;
  2493. },
  2494. getParameter: function ( point, optionalTarget ) {
  2495. // This can potentially have a divide by zero if the box
  2496. // has a size dimension of 0.
  2497. var result = optionalTarget || new THREE.Vector3();
  2498. return result.set(
  2499. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2500. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  2501. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  2502. );
  2503. },
  2504. intersectsBox: function ( box ) {
  2505. // using 6 splitting planes to rule out intersections.
  2506. if ( box.max.x < this.min.x || box.min.x > this.max.x ||
  2507. box.max.y < this.min.y || box.min.y > this.max.y ||
  2508. box.max.z < this.min.z || box.min.z > this.max.z ) {
  2509. return false;
  2510. }
  2511. return true;
  2512. },
  2513. intersectsSphere: ( function () {
  2514. var closestPoint;
  2515. return function intersectsSphere( sphere ) {
  2516. if ( closestPoint === undefined ) closestPoint = new THREE.Vector3();
  2517. // Find the point on the AABB closest to the sphere center.
  2518. this.clampPoint( sphere.center, closestPoint );
  2519. // If that point is inside the sphere, the AABB and sphere intersect.
  2520. return closestPoint.distanceToSquared( sphere.center ) <= ( sphere.radius * sphere.radius );
  2521. };
  2522. } )(),
  2523. intersectsPlane: function ( plane ) {
  2524. // We compute the minimum and maximum dot product values. If those values
  2525. // are on the same side (back or front) of the plane, then there is no intersection.
  2526. var min, max;
  2527. if ( plane.normal.x > 0 ) {
  2528. min = plane.normal.x * this.min.x;
  2529. max = plane.normal.x * this.max.x;
  2530. } else {
  2531. min = plane.normal.x * this.max.x;
  2532. max = plane.normal.x * this.min.x;
  2533. }
  2534. if ( plane.normal.y > 0 ) {
  2535. min += plane.normal.y * this.min.y;
  2536. max += plane.normal.y * this.max.y;
  2537. } else {
  2538. min += plane.normal.y * this.max.y;
  2539. max += plane.normal.y * this.min.y;
  2540. }
  2541. if ( plane.normal.z > 0 ) {
  2542. min += plane.normal.z * this.min.z;
  2543. max += plane.normal.z * this.max.z;
  2544. } else {
  2545. min += plane.normal.z * this.max.z;
  2546. max += plane.normal.z * this.min.z;
  2547. }
  2548. return ( min <= plane.constant && max >= plane.constant );
  2549. },
  2550. clampPoint: function ( point, optionalTarget ) {
  2551. var result = optionalTarget || new THREE.Vector3();
  2552. return result.copy( point ).clamp( this.min, this.max );
  2553. },
  2554. distanceToPoint: function () {
  2555. var v1 = new THREE.Vector3();
  2556. return function ( point ) {
  2557. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  2558. return clampedPoint.sub( point ).length();
  2559. };
  2560. }(),
  2561. getBoundingSphere: function () {
  2562. var v1 = new THREE.Vector3();
  2563. return function ( optionalTarget ) {
  2564. var result = optionalTarget || new THREE.Sphere();
  2565. result.center = this.center();
  2566. result.radius = this.size( v1 ).length() * 0.5;
  2567. return result;
  2568. };
  2569. }(),
  2570. intersect: function ( box ) {
  2571. this.min.max( box.min );
  2572. this.max.min( box.max );
  2573. return this;
  2574. },
  2575. union: function ( box ) {
  2576. this.min.min( box.min );
  2577. this.max.max( box.max );
  2578. return this;
  2579. },
  2580. applyMatrix4: function () {
  2581. var points = [
  2582. new THREE.Vector3(),
  2583. new THREE.Vector3(),
  2584. new THREE.Vector3(),
  2585. new THREE.Vector3(),
  2586. new THREE.Vector3(),
  2587. new THREE.Vector3(),
  2588. new THREE.Vector3(),
  2589. new THREE.Vector3()
  2590. ];
  2591. return function ( matrix ) {
  2592. // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  2593. points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
  2594. points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
  2595. points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
  2596. points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
  2597. points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
  2598. points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
  2599. points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
  2600. points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
  2601. this.makeEmpty();
  2602. this.setFromPoints( points );
  2603. return this;
  2604. };
  2605. }(),
  2606. translate: function ( offset ) {
  2607. this.min.add( offset );
  2608. this.max.add( offset );
  2609. return this;
  2610. },
  2611. equals: function ( box ) {
  2612. return box.min.equals( this.min ) && box.max.equals( this.max );
  2613. }
  2614. };
  2615. // File:src/math/Matrix3.js
  2616. /**
  2617. * @author alteredq / http://alteredqualia.com/
  2618. * @author WestLangley / http://github.com/WestLangley
  2619. * @author bhouston / http://clara.io
  2620. * @author tschw
  2621. */
  2622. THREE.Matrix3 = function () {
  2623. this.elements = new Float32Array( [
  2624. 1, 0, 0,
  2625. 0, 1, 0,
  2626. 0, 0, 1
  2627. ] );
  2628. if ( arguments.length > 0 ) {
  2629. console.error( 'THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.' );
  2630. }
  2631. };
  2632. THREE.Matrix3.prototype = {
  2633. constructor: THREE.Matrix3,
  2634. set: function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  2635. var te = this.elements;
  2636. te[ 0 ] = n11; te[ 1 ] = n21; te[ 2 ] = n31;
  2637. te[ 3 ] = n12; te[ 4 ] = n22; te[ 5 ] = n32;
  2638. te[ 6 ] = n13; te[ 7 ] = n23; te[ 8 ] = n33;
  2639. return this;
  2640. },
  2641. identity: function () {
  2642. this.set(
  2643. 1, 0, 0,
  2644. 0, 1, 0,
  2645. 0, 0, 1
  2646. );
  2647. return this;
  2648. },
  2649. clone: function () {
  2650. return new this.constructor().fromArray( this.elements );
  2651. },
  2652. copy: function ( m ) {
  2653. var me = m.elements;
  2654. this.set(
  2655. me[ 0 ], me[ 3 ], me[ 6 ],
  2656. me[ 1 ], me[ 4 ], me[ 7 ],
  2657. me[ 2 ], me[ 5 ], me[ 8 ]
  2658. );
  2659. return this;
  2660. },
  2661. setFromMatrix4: function( m ) {
  2662. var me = m.elements;
  2663. this.set(
  2664. me[ 0 ], me[ 4 ], me[ 8 ],
  2665. me[ 1 ], me[ 5 ], me[ 9 ],
  2666. me[ 2 ], me[ 6 ], me[ 10 ]
  2667. );
  2668. return this;
  2669. },
  2670. applyToVector3Array: function () {
  2671. var v1;
  2672. return function ( array, offset, length ) {
  2673. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2674. if ( offset === undefined ) offset = 0;
  2675. if ( length === undefined ) length = array.length;
  2676. for ( var i = 0, j = offset; i < length; i += 3, j += 3 ) {
  2677. v1.fromArray( array, j );
  2678. v1.applyMatrix3( this );
  2679. v1.toArray( array, j );
  2680. }
  2681. return array;
  2682. };
  2683. }(),
  2684. applyToBuffer: function () {
  2685. var v1;
  2686. return function applyToBuffer( buffer, offset, length ) {
  2687. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2688. if ( offset === undefined ) offset = 0;
  2689. if ( length === undefined ) length = buffer.length / buffer.itemSize;
  2690. for ( var i = 0, j = offset; i < length; i ++, j ++ ) {
  2691. v1.x = buffer.getX( j );
  2692. v1.y = buffer.getY( j );
  2693. v1.z = buffer.getZ( j );
  2694. v1.applyMatrix3( this );
  2695. buffer.setXYZ( v1.x, v1.y, v1.z );
  2696. }
  2697. return buffer;
  2698. };
  2699. }(),
  2700. multiplyScalar: function ( s ) {
  2701. var te = this.elements;
  2702. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  2703. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  2704. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  2705. return this;
  2706. },
  2707. determinant: function () {
  2708. var te = this.elements;
  2709. var a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  2710. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  2711. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  2712. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  2713. },
  2714. getInverse: function ( matrix, throwOnDegenerate ) {
  2715. if ( matrix instanceof THREE.Matrix4 ) {
  2716. console.warn( "THREE.Matrix3.getInverse no longer takes a Matrix4 argument." );
  2717. }
  2718. var me = matrix.elements,
  2719. te = this.elements,
  2720. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ],
  2721. n12 = me[ 3 ], n22 = me[ 4 ], n32 = me[ 5 ],
  2722. n13 = me[ 6 ], n23 = me[ 7 ], n33 = me[ 8 ],
  2723. t11 = n33 * n22 - n32 * n23,
  2724. t12 = n32 * n13 - n33 * n12,
  2725. t13 = n23 * n12 - n22 * n13,
  2726. det = n11 * t11 + n21 * t12 + n31 * t13;
  2727. if ( det === 0 ) {
  2728. var msg = "THREE.Matrix3.getInverse(): can't invert matrix, determinant is 0";
  2729. if ( throwOnDegenerate || false ) {
  2730. throw new Error( msg );
  2731. } else {
  2732. console.warn( msg );
  2733. }
  2734. return this.identity();
  2735. }
  2736. te[ 0 ] = t11;
  2737. te[ 1 ] = n31 * n23 - n33 * n21;
  2738. te[ 2 ] = n32 * n21 - n31 * n22;
  2739. te[ 3 ] = t12;
  2740. te[ 4 ] = n33 * n11 - n31 * n13;
  2741. te[ 5 ] = n31 * n12 - n32 * n11;
  2742. te[ 6 ] = t13;
  2743. te[ 7 ] = n21 * n13 - n23 * n11;
  2744. te[ 8 ] = n22 * n11 - n21 * n12;
  2745. return this.multiplyScalar( 1 / det );
  2746. },
  2747. transpose: function () {
  2748. var tmp, m = this.elements;
  2749. tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
  2750. tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
  2751. tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
  2752. return this;
  2753. },
  2754. flattenToArrayOffset: function ( array, offset ) {
  2755. var te = this.elements;
  2756. array[ offset ] = te[ 0 ];
  2757. array[ offset + 1 ] = te[ 1 ];
  2758. array[ offset + 2 ] = te[ 2 ];
  2759. array[ offset + 3 ] = te[ 3 ];
  2760. array[ offset + 4 ] = te[ 4 ];
  2761. array[ offset + 5 ] = te[ 5 ];
  2762. array[ offset + 6 ] = te[ 6 ];
  2763. array[ offset + 7 ] = te[ 7 ];
  2764. array[ offset + 8 ] = te[ 8 ];
  2765. return array;
  2766. },
  2767. getNormalMatrix: function ( matrix4 ) {
  2768. return this.setFromMatrix4( matrix4 ).getInverse( this ).transpose();
  2769. },
  2770. transposeIntoArray: function ( r ) {
  2771. var m = this.elements;
  2772. r[ 0 ] = m[ 0 ];
  2773. r[ 1 ] = m[ 3 ];
  2774. r[ 2 ] = m[ 6 ];
  2775. r[ 3 ] = m[ 1 ];
  2776. r[ 4 ] = m[ 4 ];
  2777. r[ 5 ] = m[ 7 ];
  2778. r[ 6 ] = m[ 2 ];
  2779. r[ 7 ] = m[ 5 ];
  2780. r[ 8 ] = m[ 8 ];
  2781. return this;
  2782. },
  2783. fromArray: function ( array ) {
  2784. this.elements.set( array );
  2785. return this;
  2786. },
  2787. toArray: function () {
  2788. var te = this.elements;
  2789. return [
  2790. te[ 0 ], te[ 1 ], te[ 2 ],
  2791. te[ 3 ], te[ 4 ], te[ 5 ],
  2792. te[ 6 ], te[ 7 ], te[ 8 ]
  2793. ];
  2794. }
  2795. };
  2796. // File:src/math/Matrix4.js
  2797. /**
  2798. * @author mrdoob / http://mrdoob.com/
  2799. * @author supereggbert / http://www.paulbrunt.co.uk/
  2800. * @author philogb / http://blog.thejit.org/
  2801. * @author jordi_ros / http://plattsoft.com
  2802. * @author D1plo1d / http://github.com/D1plo1d
  2803. * @author alteredq / http://alteredqualia.com/
  2804. * @author mikael emtinger / http://gomo.se/
  2805. * @author timknip / http://www.floorplanner.com/
  2806. * @author bhouston / http://clara.io
  2807. * @author WestLangley / http://github.com/WestLangley
  2808. */
  2809. THREE.Matrix4 = function () {
  2810. this.elements = new Float32Array( [
  2811. 1, 0, 0, 0,
  2812. 0, 1, 0, 0,
  2813. 0, 0, 1, 0,
  2814. 0, 0, 0, 1
  2815. ] );
  2816. if ( arguments.length > 0 ) {
  2817. console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' );
  2818. }
  2819. };
  2820. THREE.Matrix4.prototype = {
  2821. constructor: THREE.Matrix4,
  2822. set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  2823. var te = this.elements;
  2824. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  2825. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  2826. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  2827. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  2828. return this;
  2829. },
  2830. identity: function () {
  2831. this.set(
  2832. 1, 0, 0, 0,
  2833. 0, 1, 0, 0,
  2834. 0, 0, 1, 0,
  2835. 0, 0, 0, 1
  2836. );
  2837. return this;
  2838. },
  2839. clone: function () {
  2840. return new THREE.Matrix4().fromArray( this.elements );
  2841. },
  2842. copy: function ( m ) {
  2843. this.elements.set( m.elements );
  2844. return this;
  2845. },
  2846. copyPosition: function ( m ) {
  2847. var te = this.elements;
  2848. var me = m.elements;
  2849. te[ 12 ] = me[ 12 ];
  2850. te[ 13 ] = me[ 13 ];
  2851. te[ 14 ] = me[ 14 ];
  2852. return this;
  2853. },
  2854. extractBasis: function ( xAxis, yAxis, zAxis ) {
  2855. xAxis.setFromMatrixColumn( this, 0 );
  2856. yAxis.setFromMatrixColumn( this, 1 );
  2857. zAxis.setFromMatrixColumn( this, 2 );
  2858. return this;
  2859. },
  2860. makeBasis: function ( xAxis, yAxis, zAxis ) {
  2861. this.set(
  2862. xAxis.x, yAxis.x, zAxis.x, 0,
  2863. xAxis.y, yAxis.y, zAxis.y, 0,
  2864. xAxis.z, yAxis.z, zAxis.z, 0,
  2865. 0, 0, 0, 1
  2866. );
  2867. return this;
  2868. },
  2869. extractRotation: function () {
  2870. var v1;
  2871. return function ( m ) {
  2872. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2873. var te = this.elements;
  2874. var me = m.elements;
  2875. var scaleX = 1 / v1.setFromMatrixColumn( m, 0 ).length();
  2876. var scaleY = 1 / v1.setFromMatrixColumn( m, 1 ).length();
  2877. var scaleZ = 1 / v1.setFromMatrixColumn( m, 2 ).length();
  2878. te[ 0 ] = me[ 0 ] * scaleX;
  2879. te[ 1 ] = me[ 1 ] * scaleX;
  2880. te[ 2 ] = me[ 2 ] * scaleX;
  2881. te[ 4 ] = me[ 4 ] * scaleY;
  2882. te[ 5 ] = me[ 5 ] * scaleY;
  2883. te[ 6 ] = me[ 6 ] * scaleY;
  2884. te[ 8 ] = me[ 8 ] * scaleZ;
  2885. te[ 9 ] = me[ 9 ] * scaleZ;
  2886. te[ 10 ] = me[ 10 ] * scaleZ;
  2887. return this;
  2888. };
  2889. }(),
  2890. makeRotationFromEuler: function ( euler ) {
  2891. if ( euler instanceof THREE.Euler === false ) {
  2892. console.error( 'THREE.Matrix: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  2893. }
  2894. var te = this.elements;
  2895. var x = euler.x, y = euler.y, z = euler.z;
  2896. var a = Math.cos( x ), b = Math.sin( x );
  2897. var c = Math.cos( y ), d = Math.sin( y );
  2898. var e = Math.cos( z ), f = Math.sin( z );
  2899. if ( euler.order === 'XYZ' ) {
  2900. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2901. te[ 0 ] = c * e;
  2902. te[ 4 ] = - c * f;
  2903. te[ 8 ] = d;
  2904. te[ 1 ] = af + be * d;
  2905. te[ 5 ] = ae - bf * d;
  2906. te[ 9 ] = - b * c;
  2907. te[ 2 ] = bf - ae * d;
  2908. te[ 6 ] = be + af * d;
  2909. te[ 10 ] = a * c;
  2910. } else if ( euler.order === 'YXZ' ) {
  2911. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2912. te[ 0 ] = ce + df * b;
  2913. te[ 4 ] = de * b - cf;
  2914. te[ 8 ] = a * d;
  2915. te[ 1 ] = a * f;
  2916. te[ 5 ] = a * e;
  2917. te[ 9 ] = - b;
  2918. te[ 2 ] = cf * b - de;
  2919. te[ 6 ] = df + ce * b;
  2920. te[ 10 ] = a * c;
  2921. } else if ( euler.order === 'ZXY' ) {
  2922. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2923. te[ 0 ] = ce - df * b;
  2924. te[ 4 ] = - a * f;
  2925. te[ 8 ] = de + cf * b;
  2926. te[ 1 ] = cf + de * b;
  2927. te[ 5 ] = a * e;
  2928. te[ 9 ] = df - ce * b;
  2929. te[ 2 ] = - a * d;
  2930. te[ 6 ] = b;
  2931. te[ 10 ] = a * c;
  2932. } else if ( euler.order === 'ZYX' ) {
  2933. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2934. te[ 0 ] = c * e;
  2935. te[ 4 ] = be * d - af;
  2936. te[ 8 ] = ae * d + bf;
  2937. te[ 1 ] = c * f;
  2938. te[ 5 ] = bf * d + ae;
  2939. te[ 9 ] = af * d - be;
  2940. te[ 2 ] = - d;
  2941. te[ 6 ] = b * c;
  2942. te[ 10 ] = a * c;
  2943. } else if ( euler.order === 'YZX' ) {
  2944. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2945. te[ 0 ] = c * e;
  2946. te[ 4 ] = bd - ac * f;
  2947. te[ 8 ] = bc * f + ad;
  2948. te[ 1 ] = f;
  2949. te[ 5 ] = a * e;
  2950. te[ 9 ] = - b * e;
  2951. te[ 2 ] = - d * e;
  2952. te[ 6 ] = ad * f + bc;
  2953. te[ 10 ] = ac - bd * f;
  2954. } else if ( euler.order === 'XZY' ) {
  2955. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2956. te[ 0 ] = c * e;
  2957. te[ 4 ] = - f;
  2958. te[ 8 ] = d * e;
  2959. te[ 1 ] = ac * f + bd;
  2960. te[ 5 ] = a * e;
  2961. te[ 9 ] = ad * f - bc;
  2962. te[ 2 ] = bc * f - ad;
  2963. te[ 6 ] = b * e;
  2964. te[ 10 ] = bd * f + ac;
  2965. }
  2966. // last column
  2967. te[ 3 ] = 0;
  2968. te[ 7 ] = 0;
  2969. te[ 11 ] = 0;
  2970. // bottom row
  2971. te[ 12 ] = 0;
  2972. te[ 13 ] = 0;
  2973. te[ 14 ] = 0;
  2974. te[ 15 ] = 1;
  2975. return this;
  2976. },
  2977. makeRotationFromQuaternion: function ( q ) {
  2978. var te = this.elements;
  2979. var x = q.x, y = q.y, z = q.z, w = q.w;
  2980. var x2 = x + x, y2 = y + y, z2 = z + z;
  2981. var xx = x * x2, xy = x * y2, xz = x * z2;
  2982. var yy = y * y2, yz = y * z2, zz = z * z2;
  2983. var wx = w * x2, wy = w * y2, wz = w * z2;
  2984. te[ 0 ] = 1 - ( yy + zz );
  2985. te[ 4 ] = xy - wz;
  2986. te[ 8 ] = xz + wy;
  2987. te[ 1 ] = xy + wz;
  2988. te[ 5 ] = 1 - ( xx + zz );
  2989. te[ 9 ] = yz - wx;
  2990. te[ 2 ] = xz - wy;
  2991. te[ 6 ] = yz + wx;
  2992. te[ 10 ] = 1 - ( xx + yy );
  2993. // last column
  2994. te[ 3 ] = 0;
  2995. te[ 7 ] = 0;
  2996. te[ 11 ] = 0;
  2997. // bottom row
  2998. te[ 12 ] = 0;
  2999. te[ 13 ] = 0;
  3000. te[ 14 ] = 0;
  3001. te[ 15 ] = 1;
  3002. return this;
  3003. },
  3004. lookAt: function () {
  3005. var x, y, z;
  3006. return function ( eye, target, up ) {
  3007. if ( x === undefined ) x = new THREE.Vector3();
  3008. if ( y === undefined ) y = new THREE.Vector3();
  3009. if ( z === undefined ) z = new THREE.Vector3();
  3010. var te = this.elements;
  3011. z.subVectors( eye, target ).normalize();
  3012. if ( z.lengthSq() === 0 ) {
  3013. z.z = 1;
  3014. }
  3015. x.crossVectors( up, z ).normalize();
  3016. if ( x.lengthSq() === 0 ) {
  3017. z.x += 0.0001;
  3018. x.crossVectors( up, z ).normalize();
  3019. }
  3020. y.crossVectors( z, x );
  3021. te[ 0 ] = x.x; te[ 4 ] = y.x; te[ 8 ] = z.x;
  3022. te[ 1 ] = x.y; te[ 5 ] = y.y; te[ 9 ] = z.y;
  3023. te[ 2 ] = x.z; te[ 6 ] = y.z; te[ 10 ] = z.z;
  3024. return this;
  3025. };
  3026. }(),
  3027. multiply: function ( m, n ) {
  3028. if ( n !== undefined ) {
  3029. console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' );
  3030. return this.multiplyMatrices( m, n );
  3031. }
  3032. return this.multiplyMatrices( this, m );
  3033. },
  3034. multiplyMatrices: function ( a, b ) {
  3035. var ae = a.elements;
  3036. var be = b.elements;
  3037. var te = this.elements;
  3038. var a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  3039. var a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  3040. var a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  3041. var a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  3042. var b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  3043. var b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  3044. var b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  3045. var b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  3046. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  3047. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  3048. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  3049. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  3050. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  3051. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  3052. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  3053. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  3054. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  3055. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  3056. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  3057. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  3058. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  3059. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  3060. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  3061. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  3062. return this;
  3063. },
  3064. multiplyToArray: function ( a, b, r ) {
  3065. var te = this.elements;
  3066. this.multiplyMatrices( a, b );
  3067. r[ 0 ] = te[ 0 ]; r[ 1 ] = te[ 1 ]; r[ 2 ] = te[ 2 ]; r[ 3 ] = te[ 3 ];
  3068. r[ 4 ] = te[ 4 ]; r[ 5 ] = te[ 5 ]; r[ 6 ] = te[ 6 ]; r[ 7 ] = te[ 7 ];
  3069. r[ 8 ] = te[ 8 ]; r[ 9 ] = te[ 9 ]; r[ 10 ] = te[ 10 ]; r[ 11 ] = te[ 11 ];
  3070. r[ 12 ] = te[ 12 ]; r[ 13 ] = te[ 13 ]; r[ 14 ] = te[ 14 ]; r[ 15 ] = te[ 15 ];
  3071. return this;
  3072. },
  3073. multiplyScalar: function ( s ) {
  3074. var te = this.elements;
  3075. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  3076. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  3077. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  3078. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  3079. return this;
  3080. },
  3081. applyToVector3Array: function () {
  3082. var v1;
  3083. return function ( array, offset, length ) {
  3084. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3085. if ( offset === undefined ) offset = 0;
  3086. if ( length === undefined ) length = array.length;
  3087. for ( var i = 0, j = offset; i < length; i += 3, j += 3 ) {
  3088. v1.fromArray( array, j );
  3089. v1.applyMatrix4( this );
  3090. v1.toArray( array, j );
  3091. }
  3092. return array;
  3093. };
  3094. }(),
  3095. applyToBuffer: function () {
  3096. var v1;
  3097. return function applyToBuffer( buffer, offset, length ) {
  3098. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3099. if ( offset === undefined ) offset = 0;
  3100. if ( length === undefined ) length = buffer.length / buffer.itemSize;
  3101. for ( var i = 0, j = offset; i < length; i ++, j ++ ) {
  3102. v1.x = buffer.getX( j );
  3103. v1.y = buffer.getY( j );
  3104. v1.z = buffer.getZ( j );
  3105. v1.applyMatrix4( this );
  3106. buffer.setXYZ( v1.x, v1.y, v1.z );
  3107. }
  3108. return buffer;
  3109. };
  3110. }(),
  3111. determinant: function () {
  3112. var te = this.elements;
  3113. var n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  3114. var n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  3115. var n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  3116. var n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  3117. //TODO: make this more efficient
  3118. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  3119. return (
  3120. n41 * (
  3121. + n14 * n23 * n32
  3122. - n13 * n24 * n32
  3123. - n14 * n22 * n33
  3124. + n12 * n24 * n33
  3125. + n13 * n22 * n34
  3126. - n12 * n23 * n34
  3127. ) +
  3128. n42 * (
  3129. + n11 * n23 * n34
  3130. - n11 * n24 * n33
  3131. + n14 * n21 * n33
  3132. - n13 * n21 * n34
  3133. + n13 * n24 * n31
  3134. - n14 * n23 * n31
  3135. ) +
  3136. n43 * (
  3137. + n11 * n24 * n32
  3138. - n11 * n22 * n34
  3139. - n14 * n21 * n32
  3140. + n12 * n21 * n34
  3141. + n14 * n22 * n31
  3142. - n12 * n24 * n31
  3143. ) +
  3144. n44 * (
  3145. - n13 * n22 * n31
  3146. - n11 * n23 * n32
  3147. + n11 * n22 * n33
  3148. + n13 * n21 * n32
  3149. - n12 * n21 * n33
  3150. + n12 * n23 * n31
  3151. )
  3152. );
  3153. },
  3154. transpose: function () {
  3155. var te = this.elements;
  3156. var tmp;
  3157. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  3158. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  3159. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  3160. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  3161. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  3162. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  3163. return this;
  3164. },
  3165. flattenToArrayOffset: function ( array, offset ) {
  3166. var te = this.elements;
  3167. array[ offset ] = te[ 0 ];
  3168. array[ offset + 1 ] = te[ 1 ];
  3169. array[ offset + 2 ] = te[ 2 ];
  3170. array[ offset + 3 ] = te[ 3 ];
  3171. array[ offset + 4 ] = te[ 4 ];
  3172. array[ offset + 5 ] = te[ 5 ];
  3173. array[ offset + 6 ] = te[ 6 ];
  3174. array[ offset + 7 ] = te[ 7 ];
  3175. array[ offset + 8 ] = te[ 8 ];
  3176. array[ offset + 9 ] = te[ 9 ];
  3177. array[ offset + 10 ] = te[ 10 ];
  3178. array[ offset + 11 ] = te[ 11 ];
  3179. array[ offset + 12 ] = te[ 12 ];
  3180. array[ offset + 13 ] = te[ 13 ];
  3181. array[ offset + 14 ] = te[ 14 ];
  3182. array[ offset + 15 ] = te[ 15 ];
  3183. return array;
  3184. },
  3185. getPosition: function () {
  3186. var v1;
  3187. return function () {
  3188. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3189. console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
  3190. return v1.setFromMatrixColumn( this, 3 );
  3191. };
  3192. }(),
  3193. setPosition: function ( v ) {
  3194. var te = this.elements;
  3195. te[ 12 ] = v.x;
  3196. te[ 13 ] = v.y;
  3197. te[ 14 ] = v.z;
  3198. return this;
  3199. },
  3200. getInverse: function ( m, throwOnDegenerate ) {
  3201. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  3202. var te = this.elements,
  3203. me = m.elements,
  3204. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ], n41 = me[ 3 ],
  3205. n12 = me[ 4 ], n22 = me[ 5 ], n32 = me[ 6 ], n42 = me[ 7 ],
  3206. n13 = me[ 8 ], n23 = me[ 9 ], n33 = me[ 10 ], n43 = me[ 11 ],
  3207. n14 = me[ 12 ], n24 = me[ 13 ], n34 = me[ 14 ], n44 = me[ 15 ],
  3208. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  3209. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  3210. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  3211. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  3212. var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  3213. if ( det === 0 ) {
  3214. var msg = "THREE.Matrix4.getInverse(): can't invert matrix, determinant is 0";
  3215. if ( throwOnDegenerate || false ) {
  3216. throw new Error( msg );
  3217. } else {
  3218. console.warn( msg );
  3219. }
  3220. return this.identity();
  3221. }
  3222. te[ 0 ] = t11;
  3223. te[ 1 ] = n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44;
  3224. te[ 2 ] = n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44;
  3225. te[ 3 ] = n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43;
  3226. te[ 4 ] = t12;
  3227. te[ 5 ] = n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44;
  3228. te[ 6 ] = n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44;
  3229. te[ 7 ] = n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43;
  3230. te[ 8 ] = t13;
  3231. te[ 9 ] = n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44;
  3232. te[ 10 ] = n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44;
  3233. te[ 11 ] = n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43;
  3234. te[ 12 ] = t14;
  3235. te[ 13 ] = n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34;
  3236. te[ 14 ] = n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34;
  3237. te[ 15 ] = n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33;
  3238. return this.multiplyScalar( 1 / det );
  3239. },
  3240. scale: function ( v ) {
  3241. var te = this.elements;
  3242. var x = v.x, y = v.y, z = v.z;
  3243. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  3244. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  3245. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  3246. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  3247. return this;
  3248. },
  3249. getMaxScaleOnAxis: function () {
  3250. var te = this.elements;
  3251. var scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  3252. var scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  3253. var scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  3254. return Math.sqrt( Math.max( scaleXSq, scaleYSq, scaleZSq ) );
  3255. },
  3256. makeTranslation: function ( x, y, z ) {
  3257. this.set(
  3258. 1, 0, 0, x,
  3259. 0, 1, 0, y,
  3260. 0, 0, 1, z,
  3261. 0, 0, 0, 1
  3262. );
  3263. return this;
  3264. },
  3265. makeRotationX: function ( theta ) {
  3266. var c = Math.cos( theta ), s = Math.sin( theta );
  3267. this.set(
  3268. 1, 0, 0, 0,
  3269. 0, c, - s, 0,
  3270. 0, s, c, 0,
  3271. 0, 0, 0, 1
  3272. );
  3273. return this;
  3274. },
  3275. makeRotationY: function ( theta ) {
  3276. var c = Math.cos( theta ), s = Math.sin( theta );
  3277. this.set(
  3278. c, 0, s, 0,
  3279. 0, 1, 0, 0,
  3280. - s, 0, c, 0,
  3281. 0, 0, 0, 1
  3282. );
  3283. return this;
  3284. },
  3285. makeRotationZ: function ( theta ) {
  3286. var c = Math.cos( theta ), s = Math.sin( theta );
  3287. this.set(
  3288. c, - s, 0, 0,
  3289. s, c, 0, 0,
  3290. 0, 0, 1, 0,
  3291. 0, 0, 0, 1
  3292. );
  3293. return this;
  3294. },
  3295. makeRotationAxis: function ( axis, angle ) {
  3296. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  3297. var c = Math.cos( angle );
  3298. var s = Math.sin( angle );
  3299. var t = 1 - c;
  3300. var x = axis.x, y = axis.y, z = axis.z;
  3301. var tx = t * x, ty = t * y;
  3302. this.set(
  3303. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  3304. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  3305. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  3306. 0, 0, 0, 1
  3307. );
  3308. return this;
  3309. },
  3310. makeScale: function ( x, y, z ) {
  3311. this.set(
  3312. x, 0, 0, 0,
  3313. 0, y, 0, 0,
  3314. 0, 0, z, 0,
  3315. 0, 0, 0, 1
  3316. );
  3317. return this;
  3318. },
  3319. compose: function ( position, quaternion, scale ) {
  3320. this.makeRotationFromQuaternion( quaternion );
  3321. this.scale( scale );
  3322. this.setPosition( position );
  3323. return this;
  3324. },
  3325. decompose: function () {
  3326. var vector, matrix;
  3327. return function ( position, quaternion, scale ) {
  3328. if ( vector === undefined ) vector = new THREE.Vector3();
  3329. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  3330. var te = this.elements;
  3331. var sx = vector.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  3332. var sy = vector.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  3333. var sz = vector.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  3334. // if determine is negative, we need to invert one scale
  3335. var det = this.determinant();
  3336. if ( det < 0 ) {
  3337. sx = - sx;
  3338. }
  3339. position.x = te[ 12 ];
  3340. position.y = te[ 13 ];
  3341. position.z = te[ 14 ];
  3342. // scale the rotation part
  3343. matrix.elements.set( this.elements ); // at this point matrix is incomplete so we can't use .copy()
  3344. var invSX = 1 / sx;
  3345. var invSY = 1 / sy;
  3346. var invSZ = 1 / sz;
  3347. matrix.elements[ 0 ] *= invSX;
  3348. matrix.elements[ 1 ] *= invSX;
  3349. matrix.elements[ 2 ] *= invSX;
  3350. matrix.elements[ 4 ] *= invSY;
  3351. matrix.elements[ 5 ] *= invSY;
  3352. matrix.elements[ 6 ] *= invSY;
  3353. matrix.elements[ 8 ] *= invSZ;
  3354. matrix.elements[ 9 ] *= invSZ;
  3355. matrix.elements[ 10 ] *= invSZ;
  3356. quaternion.setFromRotationMatrix( matrix );
  3357. scale.x = sx;
  3358. scale.y = sy;
  3359. scale.z = sz;
  3360. return this;
  3361. };
  3362. }(),
  3363. makeFrustum: function ( left, right, bottom, top, near, far ) {
  3364. var te = this.elements;
  3365. var x = 2 * near / ( right - left );
  3366. var y = 2 * near / ( top - bottom );
  3367. var a = ( right + left ) / ( right - left );
  3368. var b = ( top + bottom ) / ( top - bottom );
  3369. var c = - ( far + near ) / ( far - near );
  3370. var d = - 2 * far * near / ( far - near );
  3371. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  3372. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  3373. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  3374. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  3375. return this;
  3376. },
  3377. makePerspective: function ( fov, aspect, near, far ) {
  3378. var ymax = near * Math.tan( THREE.Math.degToRad( fov * 0.5 ) );
  3379. var ymin = - ymax;
  3380. var xmin = ymin * aspect;
  3381. var xmax = ymax * aspect;
  3382. return this.makeFrustum( xmin, xmax, ymin, ymax, near, far );
  3383. },
  3384. makeOrthographic: function ( left, right, top, bottom, near, far ) {
  3385. var te = this.elements;
  3386. var w = 1.0 / ( right - left );
  3387. var h = 1.0 / ( top - bottom );
  3388. var p = 1.0 / ( far - near );
  3389. var x = ( right + left ) * w;
  3390. var y = ( top + bottom ) * h;
  3391. var z = ( far + near ) * p;
  3392. te[ 0 ] = 2 * w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  3393. te[ 1 ] = 0; te[ 5 ] = 2 * h; te[ 9 ] = 0; te[ 13 ] = - y;
  3394. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 * p; te[ 14 ] = - z;
  3395. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  3396. return this;
  3397. },
  3398. equals: function ( matrix ) {
  3399. var te = this.elements;
  3400. var me = matrix.elements;
  3401. for ( var i = 0; i < 16; i ++ ) {
  3402. if ( te[ i ] !== me[ i ] ) return false;
  3403. }
  3404. return true;
  3405. },
  3406. fromArray: function ( array ) {
  3407. this.elements.set( array );
  3408. return this;
  3409. },
  3410. toArray: function () {
  3411. var te = this.elements;
  3412. return [
  3413. te[ 0 ], te[ 1 ], te[ 2 ], te[ 3 ],
  3414. te[ 4 ], te[ 5 ], te[ 6 ], te[ 7 ],
  3415. te[ 8 ], te[ 9 ], te[ 10 ], te[ 11 ],
  3416. te[ 12 ], te[ 13 ], te[ 14 ], te[ 15 ]
  3417. ];
  3418. }
  3419. };
  3420. // File:src/math/Ray.js
  3421. /**
  3422. * @author bhouston / http://clara.io
  3423. */
  3424. THREE.Ray = function ( origin, direction ) {
  3425. this.origin = ( origin !== undefined ) ? origin : new THREE.Vector3();
  3426. this.direction = ( direction !== undefined ) ? direction : new THREE.Vector3();
  3427. };
  3428. THREE.Ray.prototype = {
  3429. constructor: THREE.Ray,
  3430. set: function ( origin, direction ) {
  3431. this.origin.copy( origin );
  3432. this.direction.copy( direction );
  3433. return this;
  3434. },
  3435. clone: function () {
  3436. return new this.constructor().copy( this );
  3437. },
  3438. copy: function ( ray ) {
  3439. this.origin.copy( ray.origin );
  3440. this.direction.copy( ray.direction );
  3441. return this;
  3442. },
  3443. at: function ( t, optionalTarget ) {
  3444. var result = optionalTarget || new THREE.Vector3();
  3445. return result.copy( this.direction ).multiplyScalar( t ).add( this.origin );
  3446. },
  3447. lookAt: function ( v ) {
  3448. this.direction.copy( v ).sub( this.origin ).normalize();
  3449. },
  3450. recast: function () {
  3451. var v1 = new THREE.Vector3();
  3452. return function ( t ) {
  3453. this.origin.copy( this.at( t, v1 ) );
  3454. return this;
  3455. };
  3456. }(),
  3457. closestPointToPoint: function ( point, optionalTarget ) {
  3458. var result = optionalTarget || new THREE.Vector3();
  3459. result.subVectors( point, this.origin );
  3460. var directionDistance = result.dot( this.direction );
  3461. if ( directionDistance < 0 ) {
  3462. return result.copy( this.origin );
  3463. }
  3464. return result.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  3465. },
  3466. distanceToPoint: function ( point ) {
  3467. return Math.sqrt( this.distanceSqToPoint( point ) );
  3468. },
  3469. distanceSqToPoint: function () {
  3470. var v1 = new THREE.Vector3();
  3471. return function ( point ) {
  3472. var directionDistance = v1.subVectors( point, this.origin ).dot( this.direction );
  3473. // point behind the ray
  3474. if ( directionDistance < 0 ) {
  3475. return this.origin.distanceToSquared( point );
  3476. }
  3477. v1.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  3478. return v1.distanceToSquared( point );
  3479. };
  3480. }(),
  3481. distanceSqToSegment: function () {
  3482. var segCenter = new THREE.Vector3();
  3483. var segDir = new THREE.Vector3();
  3484. var diff = new THREE.Vector3();
  3485. return function ( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  3486. // from http://www.geometrictools.com/LibMathematics/Distance/Wm5DistRay3Segment3.cpp
  3487. // It returns the min distance between the ray and the segment
  3488. // defined by v0 and v1
  3489. // It can also set two optional targets :
  3490. // - The closest point on the ray
  3491. // - The closest point on the segment
  3492. segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  3493. segDir.copy( v1 ).sub( v0 ).normalize();
  3494. diff.copy( this.origin ).sub( segCenter );
  3495. var segExtent = v0.distanceTo( v1 ) * 0.5;
  3496. var a01 = - this.direction.dot( segDir );
  3497. var b0 = diff.dot( this.direction );
  3498. var b1 = - diff.dot( segDir );
  3499. var c = diff.lengthSq();
  3500. var det = Math.abs( 1 - a01 * a01 );
  3501. var s0, s1, sqrDist, extDet;
  3502. if ( det > 0 ) {
  3503. // The ray and segment are not parallel.
  3504. s0 = a01 * b1 - b0;
  3505. s1 = a01 * b0 - b1;
  3506. extDet = segExtent * det;
  3507. if ( s0 >= 0 ) {
  3508. if ( s1 >= - extDet ) {
  3509. if ( s1 <= extDet ) {
  3510. // region 0
  3511. // Minimum at interior points of ray and segment.
  3512. var invDet = 1 / det;
  3513. s0 *= invDet;
  3514. s1 *= invDet;
  3515. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  3516. } else {
  3517. // region 1
  3518. s1 = segExtent;
  3519. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3520. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3521. }
  3522. } else {
  3523. // region 5
  3524. s1 = - segExtent;
  3525. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3526. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3527. }
  3528. } else {
  3529. if ( s1 <= - extDet ) {
  3530. // region 4
  3531. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  3532. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3533. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3534. } else if ( s1 <= extDet ) {
  3535. // region 3
  3536. s0 = 0;
  3537. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3538. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  3539. } else {
  3540. // region 2
  3541. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  3542. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3543. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3544. }
  3545. }
  3546. } else {
  3547. // Ray and segment are parallel.
  3548. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  3549. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3550. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3551. }
  3552. if ( optionalPointOnRay ) {
  3553. optionalPointOnRay.copy( this.direction ).multiplyScalar( s0 ).add( this.origin );
  3554. }
  3555. if ( optionalPointOnSegment ) {
  3556. optionalPointOnSegment.copy( segDir ).multiplyScalar( s1 ).add( segCenter );
  3557. }
  3558. return sqrDist;
  3559. };
  3560. }(),
  3561. intersectSphere: function () {
  3562. var v1 = new THREE.Vector3();
  3563. return function ( sphere, optionalTarget ) {
  3564. v1.subVectors( sphere.center, this.origin );
  3565. var tca = v1.dot( this.direction );
  3566. var d2 = v1.dot( v1 ) - tca * tca;
  3567. var radius2 = sphere.radius * sphere.radius;
  3568. if ( d2 > radius2 ) return null;
  3569. var thc = Math.sqrt( radius2 - d2 );
  3570. // t0 = first intersect point - entrance on front of sphere
  3571. var t0 = tca - thc;
  3572. // t1 = second intersect point - exit point on back of sphere
  3573. var t1 = tca + thc;
  3574. // test to see if both t0 and t1 are behind the ray - if so, return null
  3575. if ( t0 < 0 && t1 < 0 ) return null;
  3576. // test to see if t0 is behind the ray:
  3577. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  3578. // in order to always return an intersect point that is in front of the ray.
  3579. if ( t0 < 0 ) return this.at( t1, optionalTarget );
  3580. // else t0 is in front of the ray, so return the first collision point scaled by t0
  3581. return this.at( t0, optionalTarget );
  3582. }
  3583. }(),
  3584. intersectsSphere: function ( sphere ) {
  3585. return this.distanceToPoint( sphere.center ) <= sphere.radius;
  3586. },
  3587. distanceToPlane: function ( plane ) {
  3588. var denominator = plane.normal.dot( this.direction );
  3589. if ( denominator === 0 ) {
  3590. // line is coplanar, return origin
  3591. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  3592. return 0;
  3593. }
  3594. // Null is preferable to undefined since undefined means.... it is undefined
  3595. return null;
  3596. }
  3597. var t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  3598. // Return if the ray never intersects the plane
  3599. return t >= 0 ? t : null;
  3600. },
  3601. intersectPlane: function ( plane, optionalTarget ) {
  3602. var t = this.distanceToPlane( plane );
  3603. if ( t === null ) {
  3604. return null;
  3605. }
  3606. return this.at( t, optionalTarget );
  3607. },
  3608. intersectsPlane: function ( plane ) {
  3609. // check if the ray lies on the plane first
  3610. var distToPoint = plane.distanceToPoint( this.origin );
  3611. if ( distToPoint === 0 ) {
  3612. return true;
  3613. }
  3614. var denominator = plane.normal.dot( this.direction );
  3615. if ( denominator * distToPoint < 0 ) {
  3616. return true;
  3617. }
  3618. // ray origin is behind the plane (and is pointing behind it)
  3619. return false;
  3620. },
  3621. intersectBox: function ( box, optionalTarget ) {
  3622. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  3623. var invdirx = 1 / this.direction.x,
  3624. invdiry = 1 / this.direction.y,
  3625. invdirz = 1 / this.direction.z;
  3626. var origin = this.origin;
  3627. if ( invdirx >= 0 ) {
  3628. tmin = ( box.min.x - origin.x ) * invdirx;
  3629. tmax = ( box.max.x - origin.x ) * invdirx;
  3630. } else {
  3631. tmin = ( box.max.x - origin.x ) * invdirx;
  3632. tmax = ( box.min.x - origin.x ) * invdirx;
  3633. }
  3634. if ( invdiry >= 0 ) {
  3635. tymin = ( box.min.y - origin.y ) * invdiry;
  3636. tymax = ( box.max.y - origin.y ) * invdiry;
  3637. } else {
  3638. tymin = ( box.max.y - origin.y ) * invdiry;
  3639. tymax = ( box.min.y - origin.y ) * invdiry;
  3640. }
  3641. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  3642. // These lines also handle the case where tmin or tmax is NaN
  3643. // (result of 0 * Infinity). x !== x returns true if x is NaN
  3644. if ( tymin > tmin || tmin !== tmin ) tmin = tymin;
  3645. if ( tymax < tmax || tmax !== tmax ) tmax = tymax;
  3646. if ( invdirz >= 0 ) {
  3647. tzmin = ( box.min.z - origin.z ) * invdirz;
  3648. tzmax = ( box.max.z - origin.z ) * invdirz;
  3649. } else {
  3650. tzmin = ( box.max.z - origin.z ) * invdirz;
  3651. tzmax = ( box.min.z - origin.z ) * invdirz;
  3652. }
  3653. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  3654. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  3655. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  3656. //return point closest to the ray (positive side)
  3657. if ( tmax < 0 ) return null;
  3658. return this.at( tmin >= 0 ? tmin : tmax, optionalTarget );
  3659. },
  3660. intersectsBox: ( function () {
  3661. var v = new THREE.Vector3();
  3662. return function ( box ) {
  3663. return this.intersectBox( box, v ) !== null;
  3664. };
  3665. } )(),
  3666. intersectTriangle: function () {
  3667. // Compute the offset origin, edges, and normal.
  3668. var diff = new THREE.Vector3();
  3669. var edge1 = new THREE.Vector3();
  3670. var edge2 = new THREE.Vector3();
  3671. var normal = new THREE.Vector3();
  3672. return function ( a, b, c, backfaceCulling, optionalTarget ) {
  3673. // from http://www.geometrictools.com/LibMathematics/Intersection/Wm5IntrRay3Triangle3.cpp
  3674. edge1.subVectors( b, a );
  3675. edge2.subVectors( c, a );
  3676. normal.crossVectors( edge1, edge2 );
  3677. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  3678. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  3679. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  3680. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  3681. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  3682. var DdN = this.direction.dot( normal );
  3683. var sign;
  3684. if ( DdN > 0 ) {
  3685. if ( backfaceCulling ) return null;
  3686. sign = 1;
  3687. } else if ( DdN < 0 ) {
  3688. sign = - 1;
  3689. DdN = - DdN;
  3690. } else {
  3691. return null;
  3692. }
  3693. diff.subVectors( this.origin, a );
  3694. var DdQxE2 = sign * this.direction.dot( edge2.crossVectors( diff, edge2 ) );
  3695. // b1 < 0, no intersection
  3696. if ( DdQxE2 < 0 ) {
  3697. return null;
  3698. }
  3699. var DdE1xQ = sign * this.direction.dot( edge1.cross( diff ) );
  3700. // b2 < 0, no intersection
  3701. if ( DdE1xQ < 0 ) {
  3702. return null;
  3703. }
  3704. // b1+b2 > 1, no intersection
  3705. if ( DdQxE2 + DdE1xQ > DdN ) {
  3706. return null;
  3707. }
  3708. // Line intersects triangle, check if ray does.
  3709. var QdN = - sign * diff.dot( normal );
  3710. // t < 0, no intersection
  3711. if ( QdN < 0 ) {
  3712. return null;
  3713. }
  3714. // Ray intersects triangle.
  3715. return this.at( QdN / DdN, optionalTarget );
  3716. };
  3717. }(),
  3718. applyMatrix4: function ( matrix4 ) {
  3719. this.direction.add( this.origin ).applyMatrix4( matrix4 );
  3720. this.origin.applyMatrix4( matrix4 );
  3721. this.direction.sub( this.origin );
  3722. this.direction.normalize();
  3723. return this;
  3724. },
  3725. equals: function ( ray ) {
  3726. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  3727. }
  3728. };
  3729. // File:src/math/Sphere.js
  3730. /**
  3731. * @author bhouston / http://clara.io
  3732. * @author mrdoob / http://mrdoob.com/
  3733. */
  3734. THREE.Sphere = function ( center, radius ) {
  3735. this.center = ( center !== undefined ) ? center : new THREE.Vector3();
  3736. this.radius = ( radius !== undefined ) ? radius : 0;
  3737. };
  3738. THREE.Sphere.prototype = {
  3739. constructor: THREE.Sphere,
  3740. set: function ( center, radius ) {
  3741. this.center.copy( center );
  3742. this.radius = radius;
  3743. return this;
  3744. },
  3745. setFromPoints: function () {
  3746. var box = new THREE.Box3();
  3747. return function ( points, optionalCenter ) {
  3748. var center = this.center;
  3749. if ( optionalCenter !== undefined ) {
  3750. center.copy( optionalCenter );
  3751. } else {
  3752. box.setFromPoints( points ).center( center );
  3753. }
  3754. var maxRadiusSq = 0;
  3755. for ( var i = 0, il = points.length; i < il; i ++ ) {
  3756. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  3757. }
  3758. this.radius = Math.sqrt( maxRadiusSq );
  3759. return this;
  3760. };
  3761. }(),
  3762. clone: function () {
  3763. return new this.constructor().copy( this );
  3764. },
  3765. copy: function ( sphere ) {
  3766. this.center.copy( sphere.center );
  3767. this.radius = sphere.radius;
  3768. return this;
  3769. },
  3770. empty: function () {
  3771. return ( this.radius <= 0 );
  3772. },
  3773. containsPoint: function ( point ) {
  3774. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  3775. },
  3776. distanceToPoint: function ( point ) {
  3777. return ( point.distanceTo( this.center ) - this.radius );
  3778. },
  3779. intersectsSphere: function ( sphere ) {
  3780. var radiusSum = this.radius + sphere.radius;
  3781. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  3782. },
  3783. intersectsBox: function ( box ) {
  3784. return box.intersectsSphere( this );
  3785. },
  3786. intersectsPlane: function ( plane ) {
  3787. // We use the following equation to compute the signed distance from
  3788. // the center of the sphere to the plane.
  3789. //
  3790. // distance = q * n - d
  3791. //
  3792. // If this distance is greater than the radius of the sphere,
  3793. // then there is no intersection.
  3794. return Math.abs( this.center.dot( plane.normal ) - plane.constant ) <= this.radius;
  3795. },
  3796. clampPoint: function ( point, optionalTarget ) {
  3797. var deltaLengthSq = this.center.distanceToSquared( point );
  3798. var result = optionalTarget || new THREE.Vector3();
  3799. result.copy( point );
  3800. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  3801. result.sub( this.center ).normalize();
  3802. result.multiplyScalar( this.radius ).add( this.center );
  3803. }
  3804. return result;
  3805. },
  3806. getBoundingBox: function ( optionalTarget ) {
  3807. var box = optionalTarget || new THREE.Box3();
  3808. box.set( this.center, this.center );
  3809. box.expandByScalar( this.radius );
  3810. return box;
  3811. },
  3812. applyMatrix4: function ( matrix ) {
  3813. this.center.applyMatrix4( matrix );
  3814. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  3815. return this;
  3816. },
  3817. translate: function ( offset ) {
  3818. this.center.add( offset );
  3819. return this;
  3820. },
  3821. equals: function ( sphere ) {
  3822. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  3823. }
  3824. };
  3825. // File:src/math/Frustum.js
  3826. /**
  3827. * @author mrdoob / http://mrdoob.com/
  3828. * @author alteredq / http://alteredqualia.com/
  3829. * @author bhouston / http://clara.io
  3830. */
  3831. THREE.Frustum = function ( p0, p1, p2, p3, p4, p5 ) {
  3832. this.planes = [
  3833. ( p0 !== undefined ) ? p0 : new THREE.Plane(),
  3834. ( p1 !== undefined ) ? p1 : new THREE.Plane(),
  3835. ( p2 !== undefined ) ? p2 : new THREE.Plane(),
  3836. ( p3 !== undefined ) ? p3 : new THREE.Plane(),
  3837. ( p4 !== undefined ) ? p4 : new THREE.Plane(),
  3838. ( p5 !== undefined ) ? p5 : new THREE.Plane()
  3839. ];
  3840. };
  3841. THREE.Frustum.prototype = {
  3842. constructor: THREE.Frustum,
  3843. set: function ( p0, p1, p2, p3, p4, p5 ) {
  3844. var planes = this.planes;
  3845. planes[ 0 ].copy( p0 );
  3846. planes[ 1 ].copy( p1 );
  3847. planes[ 2 ].copy( p2 );
  3848. planes[ 3 ].copy( p3 );
  3849. planes[ 4 ].copy( p4 );
  3850. planes[ 5 ].copy( p5 );
  3851. return this;
  3852. },
  3853. clone: function () {
  3854. return new this.constructor().copy( this );
  3855. },
  3856. copy: function ( frustum ) {
  3857. var planes = this.planes;
  3858. for ( var i = 0; i < 6; i ++ ) {
  3859. planes[ i ].copy( frustum.planes[ i ] );
  3860. }
  3861. return this;
  3862. },
  3863. setFromMatrix: function ( m ) {
  3864. var planes = this.planes;
  3865. var me = m.elements;
  3866. var me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  3867. var me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  3868. var me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  3869. var me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  3870. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  3871. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  3872. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  3873. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  3874. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  3875. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  3876. return this;
  3877. },
  3878. intersectsObject: function () {
  3879. var sphere = new THREE.Sphere();
  3880. return function ( object ) {
  3881. var geometry = object.geometry;
  3882. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  3883. sphere.copy( geometry.boundingSphere );
  3884. sphere.applyMatrix4( object.matrixWorld );
  3885. return this.intersectsSphere( sphere );
  3886. };
  3887. }(),
  3888. intersectsSphere: function ( sphere ) {
  3889. var planes = this.planes;
  3890. var center = sphere.center;
  3891. var negRadius = - sphere.radius;
  3892. for ( var i = 0; i < 6; i ++ ) {
  3893. var distance = planes[ i ].distanceToPoint( center );
  3894. if ( distance < negRadius ) {
  3895. return false;
  3896. }
  3897. }
  3898. return true;
  3899. },
  3900. intersectsBox: function () {
  3901. var p1 = new THREE.Vector3(),
  3902. p2 = new THREE.Vector3();
  3903. return function ( box ) {
  3904. var planes = this.planes;
  3905. for ( var i = 0; i < 6 ; i ++ ) {
  3906. var plane = planes[ i ];
  3907. p1.x = plane.normal.x > 0 ? box.min.x : box.max.x;
  3908. p2.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  3909. p1.y = plane.normal.y > 0 ? box.min.y : box.max.y;
  3910. p2.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  3911. p1.z = plane.normal.z > 0 ? box.min.z : box.max.z;
  3912. p2.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  3913. var d1 = plane.distanceToPoint( p1 );
  3914. var d2 = plane.distanceToPoint( p2 );
  3915. // if both outside plane, no intersection
  3916. if ( d1 < 0 && d2 < 0 ) {
  3917. return false;
  3918. }
  3919. }
  3920. return true;
  3921. };
  3922. }(),
  3923. containsPoint: function ( point ) {
  3924. var planes = this.planes;
  3925. for ( var i = 0; i < 6; i ++ ) {
  3926. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  3927. return false;
  3928. }
  3929. }
  3930. return true;
  3931. }
  3932. };
  3933. // File:src/math/Plane.js
  3934. /**
  3935. * @author bhouston / http://clara.io
  3936. */
  3937. THREE.Plane = function ( normal, constant ) {
  3938. this.normal = ( normal !== undefined ) ? normal : new THREE.Vector3( 1, 0, 0 );
  3939. this.constant = ( constant !== undefined ) ? constant : 0;
  3940. };
  3941. THREE.Plane.prototype = {
  3942. constructor: THREE.Plane,
  3943. set: function ( normal, constant ) {
  3944. this.normal.copy( normal );
  3945. this.constant = constant;
  3946. return this;
  3947. },
  3948. setComponents: function ( x, y, z, w ) {
  3949. this.normal.set( x, y, z );
  3950. this.constant = w;
  3951. return this;
  3952. },
  3953. setFromNormalAndCoplanarPoint: function ( normal, point ) {
  3954. this.normal.copy( normal );
  3955. this.constant = - point.dot( this.normal ); // must be this.normal, not normal, as this.normal is normalized
  3956. return this;
  3957. },
  3958. setFromCoplanarPoints: function () {
  3959. var v1 = new THREE.Vector3();
  3960. var v2 = new THREE.Vector3();
  3961. return function ( a, b, c ) {
  3962. var normal = v1.subVectors( c, b ).cross( v2.subVectors( a, b ) ).normalize();
  3963. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  3964. this.setFromNormalAndCoplanarPoint( normal, a );
  3965. return this;
  3966. };
  3967. }(),
  3968. clone: function () {
  3969. return new this.constructor().copy( this );
  3970. },
  3971. copy: function ( plane ) {
  3972. this.normal.copy( plane.normal );
  3973. this.constant = plane.constant;
  3974. return this;
  3975. },
  3976. normalize: function () {
  3977. // Note: will lead to a divide by zero if the plane is invalid.
  3978. var inverseNormalLength = 1.0 / this.normal.length();
  3979. this.normal.multiplyScalar( inverseNormalLength );
  3980. this.constant *= inverseNormalLength;
  3981. return this;
  3982. },
  3983. negate: function () {
  3984. this.constant *= - 1;
  3985. this.normal.negate();
  3986. return this;
  3987. },
  3988. distanceToPoint: function ( point ) {
  3989. return this.normal.dot( point ) + this.constant;
  3990. },
  3991. distanceToSphere: function ( sphere ) {
  3992. return this.distanceToPoint( sphere.center ) - sphere.radius;
  3993. },
  3994. projectPoint: function ( point, optionalTarget ) {
  3995. return this.orthoPoint( point, optionalTarget ).sub( point ).negate();
  3996. },
  3997. orthoPoint: function ( point, optionalTarget ) {
  3998. var perpendicularMagnitude = this.distanceToPoint( point );
  3999. var result = optionalTarget || new THREE.Vector3();
  4000. return result.copy( this.normal ).multiplyScalar( perpendicularMagnitude );
  4001. },
  4002. intersectLine: function () {
  4003. var v1 = new THREE.Vector3();
  4004. return function ( line, optionalTarget ) {
  4005. var result = optionalTarget || new THREE.Vector3();
  4006. var direction = line.delta( v1 );
  4007. var denominator = this.normal.dot( direction );
  4008. if ( denominator === 0 ) {
  4009. // line is coplanar, return origin
  4010. if ( this.distanceToPoint( line.start ) === 0 ) {
  4011. return result.copy( line.start );
  4012. }
  4013. // Unsure if this is the correct method to handle this case.
  4014. return undefined;
  4015. }
  4016. var t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  4017. if ( t < 0 || t > 1 ) {
  4018. return undefined;
  4019. }
  4020. return result.copy( direction ).multiplyScalar( t ).add( line.start );
  4021. };
  4022. }(),
  4023. intersectsLine: function ( line ) {
  4024. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  4025. var startSign = this.distanceToPoint( line.start );
  4026. var endSign = this.distanceToPoint( line.end );
  4027. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  4028. },
  4029. intersectsBox: function ( box ) {
  4030. return box.intersectsPlane( this );
  4031. },
  4032. intersectsSphere: function ( sphere ) {
  4033. return sphere.intersectsPlane( this );
  4034. },
  4035. coplanarPoint: function ( optionalTarget ) {
  4036. var result = optionalTarget || new THREE.Vector3();
  4037. return result.copy( this.normal ).multiplyScalar( - this.constant );
  4038. },
  4039. applyMatrix4: function () {
  4040. var v1 = new THREE.Vector3();
  4041. var v2 = new THREE.Vector3();
  4042. var m1 = new THREE.Matrix3();
  4043. return function ( matrix, optionalNormalMatrix ) {
  4044. // compute new normal based on theory here:
  4045. // http://www.songho.ca/opengl/gl_normaltransform.html
  4046. var normalMatrix = optionalNormalMatrix || m1.getNormalMatrix( matrix );
  4047. var newNormal = v1.copy( this.normal ).applyMatrix3( normalMatrix );
  4048. var newCoplanarPoint = this.coplanarPoint( v2 );
  4049. newCoplanarPoint.applyMatrix4( matrix );
  4050. this.setFromNormalAndCoplanarPoint( newNormal, newCoplanarPoint );
  4051. return this;
  4052. };
  4053. }(),
  4054. translate: function ( offset ) {
  4055. this.constant = this.constant - offset.dot( this.normal );
  4056. return this;
  4057. },
  4058. equals: function ( plane ) {
  4059. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  4060. }
  4061. };
  4062. // File:src/math/Spherical.js
  4063. /**
  4064. * @author bhouston / http://clara.io
  4065. * @author WestLangley / http://github.com/WestLangley
  4066. *
  4067. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  4068. *
  4069. * The poles (phi) are at the positive and negative y axis.
  4070. * The equator starts at positive z.
  4071. */
  4072. THREE.Spherical = function ( radius, phi, theta ) {
  4073. this.radius = ( radius !== undefined ) ? radius : 1.0;
  4074. this.phi = ( phi !== undefined ) ? phi : 0; // up / down towards top and bottom pole
  4075. this.theta = ( theta !== undefined ) ? theta : 0; // around the equator of the sphere
  4076. return this;
  4077. };
  4078. THREE.Spherical.prototype = {
  4079. constructor: THREE.Spherical,
  4080. set: function ( radius, phi, theta ) {
  4081. this.radius = radius;
  4082. this.phi = phi;
  4083. this.theta = theta;
  4084. },
  4085. clone: function () {
  4086. return new this.constructor().copy( this );
  4087. },
  4088. copy: function ( other ) {
  4089. this.radius.copy( other.radius );
  4090. this.phi.copy( other.phi );
  4091. this.theta.copy( other.theta );
  4092. return this;
  4093. },
  4094. // restrict phi to be betwee EPS and PI-EPS
  4095. makeSafe: function() {
  4096. var EPS = 0.000001;
  4097. this.phi = Math.max( EPS, Math.min( Math.PI - EPS, this.phi ) );
  4098. },
  4099. setFromVector3: function( vec3 ) {
  4100. this.radius = vec3.length();
  4101. if ( this.radius === 0 ) {
  4102. this.theta = 0;
  4103. this.phi = 0;
  4104. } else {
  4105. this.theta = Math.atan2( vec3.x, vec3.z ); // equator angle around y-up axis
  4106. this.phi = Math.acos( THREE.Math.clamp( vec3.y / this.radius, - 1, 1 ) ); // polar angle
  4107. }
  4108. return this;
  4109. },
  4110. };
  4111. // File:src/math/Math.js
  4112. /**
  4113. * @author alteredq / http://alteredqualia.com/
  4114. * @author mrdoob / http://mrdoob.com/
  4115. */
  4116. THREE.Math = {
  4117. generateUUID: function () {
  4118. // http://www.broofa.com/Tools/Math.uuid.htm
  4119. var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split( '' );
  4120. var uuid = new Array( 36 );
  4121. var rnd = 0, r;
  4122. return function () {
  4123. for ( var i = 0; i < 36; i ++ ) {
  4124. if ( i === 8 || i === 13 || i === 18 || i === 23 ) {
  4125. uuid[ i ] = '-';
  4126. } else if ( i === 14 ) {
  4127. uuid[ i ] = '4';
  4128. } else {
  4129. if ( rnd <= 0x02 ) rnd = 0x2000000 + ( Math.random() * 0x1000000 ) | 0;
  4130. r = rnd & 0xf;
  4131. rnd = rnd >> 4;
  4132. uuid[ i ] = chars[ ( i === 19 ) ? ( r & 0x3 ) | 0x8 : r ];
  4133. }
  4134. }
  4135. return uuid.join( '' );
  4136. };
  4137. }(),
  4138. clamp: function ( value, min, max ) {
  4139. return Math.max( min, Math.min( max, value ) );
  4140. },
  4141. // compute euclidian modulo of m % n
  4142. // https://en.wikipedia.org/wiki/Modulo_operation
  4143. euclideanModulo: function ( n, m ) {
  4144. return ( ( n % m ) + m ) % m;
  4145. },
  4146. // Linear mapping from range <a1, a2> to range <b1, b2>
  4147. mapLinear: function ( x, a1, a2, b1, b2 ) {
  4148. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  4149. },
  4150. // http://en.wikipedia.org/wiki/Smoothstep
  4151. smoothstep: function ( x, min, max ) {
  4152. if ( x <= min ) return 0;
  4153. if ( x >= max ) return 1;
  4154. x = ( x - min ) / ( max - min );
  4155. return x * x * ( 3 - 2 * x );
  4156. },
  4157. smootherstep: function ( x, min, max ) {
  4158. if ( x <= min ) return 0;
  4159. if ( x >= max ) return 1;
  4160. x = ( x - min ) / ( max - min );
  4161. return x * x * x * ( x * ( x * 6 - 15 ) + 10 );
  4162. },
  4163. random16: function () {
  4164. console.warn( 'THREE.Math.random16() has been deprecated. Use Math.random() instead.' );
  4165. return Math.random();
  4166. },
  4167. // Random integer from <low, high> interval
  4168. randInt: function ( low, high ) {
  4169. return low + Math.floor( Math.random() * ( high - low + 1 ) );
  4170. },
  4171. // Random float from <low, high> interval
  4172. randFloat: function ( low, high ) {
  4173. return low + Math.random() * ( high - low );
  4174. },
  4175. // Random float from <-range/2, range/2> interval
  4176. randFloatSpread: function ( range ) {
  4177. return range * ( 0.5 - Math.random() );
  4178. },
  4179. degToRad: function () {
  4180. var degreeToRadiansFactor = Math.PI / 180;
  4181. return function ( degrees ) {
  4182. return degrees * degreeToRadiansFactor;
  4183. };
  4184. }(),
  4185. radToDeg: function () {
  4186. var radianToDegreesFactor = 180 / Math.PI;
  4187. return function ( radians ) {
  4188. return radians * radianToDegreesFactor;
  4189. };
  4190. }(),
  4191. isPowerOfTwo: function ( value ) {
  4192. return ( value & ( value - 1 ) ) === 0 && value !== 0;
  4193. },
  4194. nearestPowerOfTwo: function ( value ) {
  4195. return Math.pow( 2, Math.round( Math.log( value ) / Math.LN2 ) );
  4196. },
  4197. nextPowerOfTwo: function ( value ) {
  4198. value --;
  4199. value |= value >> 1;
  4200. value |= value >> 2;
  4201. value |= value >> 4;
  4202. value |= value >> 8;
  4203. value |= value >> 16;
  4204. value ++;
  4205. return value;
  4206. }
  4207. };
  4208. // File:src/math/Spline.js
  4209. /**
  4210. * Spline from Tween.js, slightly optimized (and trashed)
  4211. * http://sole.github.com/tween.js/examples/05_spline.html
  4212. *
  4213. * @author mrdoob / http://mrdoob.com/
  4214. * @author alteredq / http://alteredqualia.com/
  4215. */
  4216. THREE.Spline = function ( points ) {
  4217. this.points = points;
  4218. var c = [], v3 = { x: 0, y: 0, z: 0 },
  4219. point, intPoint, weight, w2, w3,
  4220. pa, pb, pc, pd;
  4221. this.initFromArray = function ( a ) {
  4222. this.points = [];
  4223. for ( var i = 0; i < a.length; i ++ ) {
  4224. this.points[ i ] = { x: a[ i ][ 0 ], y: a[ i ][ 1 ], z: a[ i ][ 2 ] };
  4225. }
  4226. };
  4227. this.getPoint = function ( k ) {
  4228. point = ( this.points.length - 1 ) * k;
  4229. intPoint = Math.floor( point );
  4230. weight = point - intPoint;
  4231. c[ 0 ] = intPoint === 0 ? intPoint : intPoint - 1;
  4232. c[ 1 ] = intPoint;
  4233. c[ 2 ] = intPoint > this.points.length - 2 ? this.points.length - 1 : intPoint + 1;
  4234. c[ 3 ] = intPoint > this.points.length - 3 ? this.points.length - 1 : intPoint + 2;
  4235. pa = this.points[ c[ 0 ] ];
  4236. pb = this.points[ c[ 1 ] ];
  4237. pc = this.points[ c[ 2 ] ];
  4238. pd = this.points[ c[ 3 ] ];
  4239. w2 = weight * weight;
  4240. w3 = weight * w2;
  4241. v3.x = interpolate( pa.x, pb.x, pc.x, pd.x, weight, w2, w3 );
  4242. v3.y = interpolate( pa.y, pb.y, pc.y, pd.y, weight, w2, w3 );
  4243. v3.z = interpolate( pa.z, pb.z, pc.z, pd.z, weight, w2, w3 );
  4244. return v3;
  4245. };
  4246. this.getControlPointsArray = function () {
  4247. var i, p, l = this.points.length,
  4248. coords = [];
  4249. for ( i = 0; i < l; i ++ ) {
  4250. p = this.points[ i ];
  4251. coords[ i ] = [ p.x, p.y, p.z ];
  4252. }
  4253. return coords;
  4254. };
  4255. // approximate length by summing linear segments
  4256. this.getLength = function ( nSubDivisions ) {
  4257. var i, index, nSamples, position,
  4258. point = 0, intPoint = 0, oldIntPoint = 0,
  4259. oldPosition = new THREE.Vector3(),
  4260. tmpVec = new THREE.Vector3(),
  4261. chunkLengths = [],
  4262. totalLength = 0;
  4263. // first point has 0 length
  4264. chunkLengths[ 0 ] = 0;
  4265. if ( ! nSubDivisions ) nSubDivisions = 100;
  4266. nSamples = this.points.length * nSubDivisions;
  4267. oldPosition.copy( this.points[ 0 ] );
  4268. for ( i = 1; i < nSamples; i ++ ) {
  4269. index = i / nSamples;
  4270. position = this.getPoint( index );
  4271. tmpVec.copy( position );
  4272. totalLength += tmpVec.distanceTo( oldPosition );
  4273. oldPosition.copy( position );
  4274. point = ( this.points.length - 1 ) * index;
  4275. intPoint = Math.floor( point );
  4276. if ( intPoint !== oldIntPoint ) {
  4277. chunkLengths[ intPoint ] = totalLength;
  4278. oldIntPoint = intPoint;
  4279. }
  4280. }
  4281. // last point ends with total length
  4282. chunkLengths[ chunkLengths.length ] = totalLength;
  4283. return { chunks: chunkLengths, total: totalLength };
  4284. };
  4285. this.reparametrizeByArcLength = function ( samplingCoef ) {
  4286. var i, j,
  4287. index, indexCurrent, indexNext,
  4288. realDistance,
  4289. sampling, position,
  4290. newpoints = [],
  4291. tmpVec = new THREE.Vector3(),
  4292. sl = this.getLength();
  4293. newpoints.push( tmpVec.copy( this.points[ 0 ] ).clone() );
  4294. for ( i = 1; i < this.points.length; i ++ ) {
  4295. //tmpVec.copy( this.points[ i - 1 ] );
  4296. //linearDistance = tmpVec.distanceTo( this.points[ i ] );
  4297. realDistance = sl.chunks[ i ] - sl.chunks[ i - 1 ];
  4298. sampling = Math.ceil( samplingCoef * realDistance / sl.total );
  4299. indexCurrent = ( i - 1 ) / ( this.points.length - 1 );
  4300. indexNext = i / ( this.points.length - 1 );
  4301. for ( j = 1; j < sampling - 1; j ++ ) {
  4302. index = indexCurrent + j * ( 1 / sampling ) * ( indexNext - indexCurrent );
  4303. position = this.getPoint( index );
  4304. newpoints.push( tmpVec.copy( position ).clone() );
  4305. }
  4306. newpoints.push( tmpVec.copy( this.points[ i ] ).clone() );
  4307. }
  4308. this.points = newpoints;
  4309. };
  4310. // Catmull-Rom
  4311. function interpolate( p0, p1, p2, p3, t, t2, t3 ) {
  4312. var v0 = ( p2 - p0 ) * 0.5,
  4313. v1 = ( p3 - p1 ) * 0.5;
  4314. return ( 2 * ( p1 - p2 ) + v0 + v1 ) * t3 + ( - 3 * ( p1 - p2 ) - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  4315. }
  4316. };
  4317. // File:src/math/Triangle.js
  4318. /**
  4319. * @author bhouston / http://clara.io
  4320. * @author mrdoob / http://mrdoob.com/
  4321. */
  4322. THREE.Triangle = function ( a, b, c ) {
  4323. this.a = ( a !== undefined ) ? a : new THREE.Vector3();
  4324. this.b = ( b !== undefined ) ? b : new THREE.Vector3();
  4325. this.c = ( c !== undefined ) ? c : new THREE.Vector3();
  4326. };
  4327. THREE.Triangle.normal = function () {
  4328. var v0 = new THREE.Vector3();
  4329. return function ( a, b, c, optionalTarget ) {
  4330. var result = optionalTarget || new THREE.Vector3();
  4331. result.subVectors( c, b );
  4332. v0.subVectors( a, b );
  4333. result.cross( v0 );
  4334. var resultLengthSq = result.lengthSq();
  4335. if ( resultLengthSq > 0 ) {
  4336. return result.multiplyScalar( 1 / Math.sqrt( resultLengthSq ) );
  4337. }
  4338. return result.set( 0, 0, 0 );
  4339. };
  4340. }();
  4341. // static/instance method to calculate barycentric coordinates
  4342. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  4343. THREE.Triangle.barycoordFromPoint = function () {
  4344. var v0 = new THREE.Vector3();
  4345. var v1 = new THREE.Vector3();
  4346. var v2 = new THREE.Vector3();
  4347. return function ( point, a, b, c, optionalTarget ) {
  4348. v0.subVectors( c, a );
  4349. v1.subVectors( b, a );
  4350. v2.subVectors( point, a );
  4351. var dot00 = v0.dot( v0 );
  4352. var dot01 = v0.dot( v1 );
  4353. var dot02 = v0.dot( v2 );
  4354. var dot11 = v1.dot( v1 );
  4355. var dot12 = v1.dot( v2 );
  4356. var denom = ( dot00 * dot11 - dot01 * dot01 );
  4357. var result = optionalTarget || new THREE.Vector3();
  4358. // collinear or singular triangle
  4359. if ( denom === 0 ) {
  4360. // arbitrary location outside of triangle?
  4361. // not sure if this is the best idea, maybe should be returning undefined
  4362. return result.set( - 2, - 1, - 1 );
  4363. }
  4364. var invDenom = 1 / denom;
  4365. var u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  4366. var v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  4367. // barycentric coordinates must always sum to 1
  4368. return result.set( 1 - u - v, v, u );
  4369. };
  4370. }();
  4371. THREE.Triangle.containsPoint = function () {
  4372. var v1 = new THREE.Vector3();
  4373. return function ( point, a, b, c ) {
  4374. var result = THREE.Triangle.barycoordFromPoint( point, a, b, c, v1 );
  4375. return ( result.x >= 0 ) && ( result.y >= 0 ) && ( ( result.x + result.y ) <= 1 );
  4376. };
  4377. }();
  4378. THREE.Triangle.prototype = {
  4379. constructor: THREE.Triangle,
  4380. set: function ( a, b, c ) {
  4381. this.a.copy( a );
  4382. this.b.copy( b );
  4383. this.c.copy( c );
  4384. return this;
  4385. },
  4386. setFromPointsAndIndices: function ( points, i0, i1, i2 ) {
  4387. this.a.copy( points[ i0 ] );
  4388. this.b.copy( points[ i1 ] );
  4389. this.c.copy( points[ i2 ] );
  4390. return this;
  4391. },
  4392. clone: function () {
  4393. return new this.constructor().copy( this );
  4394. },
  4395. copy: function ( triangle ) {
  4396. this.a.copy( triangle.a );
  4397. this.b.copy( triangle.b );
  4398. this.c.copy( triangle.c );
  4399. return this;
  4400. },
  4401. area: function () {
  4402. var v0 = new THREE.Vector3();
  4403. var v1 = new THREE.Vector3();
  4404. return function () {
  4405. v0.subVectors( this.c, this.b );
  4406. v1.subVectors( this.a, this.b );
  4407. return v0.cross( v1 ).length() * 0.5;
  4408. };
  4409. }(),
  4410. midpoint: function ( optionalTarget ) {
  4411. var result = optionalTarget || new THREE.Vector3();
  4412. return result.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  4413. },
  4414. normal: function ( optionalTarget ) {
  4415. return THREE.Triangle.normal( this.a, this.b, this.c, optionalTarget );
  4416. },
  4417. plane: function ( optionalTarget ) {
  4418. var result = optionalTarget || new THREE.Plane();
  4419. return result.setFromCoplanarPoints( this.a, this.b, this.c );
  4420. },
  4421. barycoordFromPoint: function ( point, optionalTarget ) {
  4422. return THREE.Triangle.barycoordFromPoint( point, this.a, this.b, this.c, optionalTarget );
  4423. },
  4424. containsPoint: function ( point ) {
  4425. return THREE.Triangle.containsPoint( point, this.a, this.b, this.c );
  4426. },
  4427. equals: function ( triangle ) {
  4428. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  4429. }
  4430. };
  4431. // File:src/math/Interpolant.js
  4432. /**
  4433. * Abstract base class of interpolants over parametric samples.
  4434. *
  4435. * The parameter domain is one dimensional, typically the time or a path
  4436. * along a curve defined by the data.
  4437. *
  4438. * The sample values can have any dimensionality and derived classes may
  4439. * apply special interpretations to the data.
  4440. *
  4441. * This class provides the interval seek in a Template Method, deferring
  4442. * the actual interpolation to derived classes.
  4443. *
  4444. * Time complexity is O(1) for linear access crossing at most two points
  4445. * and O(log N) for random access, where N is the number of positions.
  4446. *
  4447. * References:
  4448. *
  4449. * http://www.oodesign.com/template-method-pattern.html
  4450. *
  4451. * @author tschw
  4452. */
  4453. THREE.Interpolant = function(
  4454. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4455. this.parameterPositions = parameterPositions;
  4456. this._cachedIndex = 0;
  4457. this.resultBuffer = resultBuffer !== undefined ?
  4458. resultBuffer : new sampleValues.constructor( sampleSize );
  4459. this.sampleValues = sampleValues;
  4460. this.valueSize = sampleSize;
  4461. };
  4462. THREE.Interpolant.prototype = {
  4463. constructor: THREE.Interpolant,
  4464. evaluate: function( t ) {
  4465. var pp = this.parameterPositions,
  4466. i1 = this._cachedIndex,
  4467. t1 = pp[ i1 ],
  4468. t0 = pp[ i1 - 1 ];
  4469. validate_interval: {
  4470. seek: {
  4471. var right;
  4472. linear_scan: {
  4473. //- See http://jsperf.com/comparison-to-undefined/3
  4474. //- slower code:
  4475. //-
  4476. //- if ( t >= t1 || t1 === undefined ) {
  4477. forward_scan: if ( ! ( t < t1 ) ) {
  4478. for ( var giveUpAt = i1 + 2; ;) {
  4479. if ( t1 === undefined ) {
  4480. if ( t < t0 ) break forward_scan;
  4481. // after end
  4482. i1 = pp.length;
  4483. this._cachedIndex = i1;
  4484. return this.afterEnd_( i1 - 1, t, t0 );
  4485. }
  4486. if ( i1 === giveUpAt ) break; // this loop
  4487. t0 = t1;
  4488. t1 = pp[ ++ i1 ];
  4489. if ( t < t1 ) {
  4490. // we have arrived at the sought interval
  4491. break seek;
  4492. }
  4493. }
  4494. // prepare binary search on the right side of the index
  4495. right = pp.length;
  4496. break linear_scan;
  4497. }
  4498. //- slower code:
  4499. //- if ( t < t0 || t0 === undefined ) {
  4500. if ( ! ( t >= t0 ) ) {
  4501. // looping?
  4502. var t1global = pp[ 1 ];
  4503. if ( t < t1global ) {
  4504. i1 = 2; // + 1, using the scan for the details
  4505. t0 = t1global;
  4506. }
  4507. // linear reverse scan
  4508. for ( var giveUpAt = i1 - 2; ;) {
  4509. if ( t0 === undefined ) {
  4510. // before start
  4511. this._cachedIndex = 0;
  4512. return this.beforeStart_( 0, t, t1 );
  4513. }
  4514. if ( i1 === giveUpAt ) break; // this loop
  4515. t1 = t0;
  4516. t0 = pp[ -- i1 - 1 ];
  4517. if ( t >= t0 ) {
  4518. // we have arrived at the sought interval
  4519. break seek;
  4520. }
  4521. }
  4522. // prepare binary search on the left side of the index
  4523. right = i1;
  4524. i1 = 0;
  4525. break linear_scan;
  4526. }
  4527. // the interval is valid
  4528. break validate_interval;
  4529. } // linear scan
  4530. // binary search
  4531. while ( i1 < right ) {
  4532. var mid = ( i1 + right ) >>> 1;
  4533. if ( t < pp[ mid ] ) {
  4534. right = mid;
  4535. } else {
  4536. i1 = mid + 1;
  4537. }
  4538. }
  4539. t1 = pp[ i1 ];
  4540. t0 = pp[ i1 - 1 ];
  4541. // check boundary cases, again
  4542. if ( t0 === undefined ) {
  4543. this._cachedIndex = 0;
  4544. return this.beforeStart_( 0, t, t1 );
  4545. }
  4546. if ( t1 === undefined ) {
  4547. i1 = pp.length;
  4548. this._cachedIndex = i1;
  4549. return this.afterEnd_( i1 - 1, t0, t );
  4550. }
  4551. } // seek
  4552. this._cachedIndex = i1;
  4553. this.intervalChanged_( i1, t0, t1 );
  4554. } // validate_interval
  4555. return this.interpolate_( i1, t0, t, t1 );
  4556. },
  4557. settings: null, // optional, subclass-specific settings structure
  4558. // Note: The indirection allows central control of many interpolants.
  4559. // --- Protected interface
  4560. DefaultSettings_: {},
  4561. getSettings_: function() {
  4562. return this.settings || this.DefaultSettings_;
  4563. },
  4564. copySampleValue_: function( index ) {
  4565. // copies a sample value to the result buffer
  4566. var result = this.resultBuffer,
  4567. values = this.sampleValues,
  4568. stride = this.valueSize,
  4569. offset = index * stride;
  4570. for ( var i = 0; i !== stride; ++ i ) {
  4571. result[ i ] = values[ offset + i ];
  4572. }
  4573. return result;
  4574. },
  4575. // Template methods for derived classes:
  4576. interpolate_: function( i1, t0, t, t1 ) {
  4577. throw new Error( "call to abstract method" );
  4578. // implementations shall return this.resultBuffer
  4579. },
  4580. intervalChanged_: function( i1, t0, t1 ) {
  4581. // empty
  4582. }
  4583. };
  4584. Object.assign( THREE.Interpolant.prototype, {
  4585. beforeStart_: //( 0, t, t0 ), returns this.resultBuffer
  4586. THREE.Interpolant.prototype.copySampleValue_,
  4587. afterEnd_: //( N-1, tN-1, t ), returns this.resultBuffer
  4588. THREE.Interpolant.prototype.copySampleValue_
  4589. } );
  4590. // File:src/math/interpolants/CubicInterpolant.js
  4591. /**
  4592. * Fast and simple cubic spline interpolant.
  4593. *
  4594. * It was derived from a Hermitian construction setting the first derivative
  4595. * at each sample position to the linear slope between neighboring positions
  4596. * over their parameter interval.
  4597. *
  4598. * @author tschw
  4599. */
  4600. THREE.CubicInterpolant = function(
  4601. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4602. THREE.Interpolant.call(
  4603. this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  4604. this._weightPrev = -0;
  4605. this._offsetPrev = -0;
  4606. this._weightNext = -0;
  4607. this._offsetNext = -0;
  4608. };
  4609. THREE.CubicInterpolant.prototype =
  4610. Object.assign( Object.create( THREE.Interpolant.prototype ), {
  4611. constructor: THREE.CubicInterpolant,
  4612. DefaultSettings_: {
  4613. endingStart: THREE.ZeroCurvatureEnding,
  4614. endingEnd: THREE.ZeroCurvatureEnding
  4615. },
  4616. intervalChanged_: function( i1, t0, t1 ) {
  4617. var pp = this.parameterPositions,
  4618. iPrev = i1 - 2,
  4619. iNext = i1 + 1,
  4620. tPrev = pp[ iPrev ],
  4621. tNext = pp[ iNext ];
  4622. if ( tPrev === undefined ) {
  4623. switch ( this.getSettings_().endingStart ) {
  4624. case THREE.ZeroSlopeEnding:
  4625. // f'(t0) = 0
  4626. iPrev = i1;
  4627. tPrev = 2 * t0 - t1;
  4628. break;
  4629. case THREE.WrapAroundEnding:
  4630. // use the other end of the curve
  4631. iPrev = pp.length - 2;
  4632. tPrev = t0 + pp[ iPrev ] - pp[ iPrev + 1 ];
  4633. break;
  4634. default: // ZeroCurvatureEnding
  4635. // f''(t0) = 0 a.k.a. Natural Spline
  4636. iPrev = i1;
  4637. tPrev = t1;
  4638. }
  4639. }
  4640. if ( tNext === undefined ) {
  4641. switch ( this.getSettings_().endingEnd ) {
  4642. case THREE.ZeroSlopeEnding:
  4643. // f'(tN) = 0
  4644. iNext = i1;
  4645. tNext = 2 * t1 - t0;
  4646. break;
  4647. case THREE.WrapAroundEnding:
  4648. // use the other end of the curve
  4649. iNext = 1;
  4650. tNext = t1 + pp[ 1 ] - pp[ 0 ];
  4651. break;
  4652. default: // ZeroCurvatureEnding
  4653. // f''(tN) = 0, a.k.a. Natural Spline
  4654. iNext = i1 - 1;
  4655. tNext = t0;
  4656. }
  4657. }
  4658. var halfDt = ( t1 - t0 ) * 0.5,
  4659. stride = this.valueSize;
  4660. this._weightPrev = halfDt / ( t0 - tPrev );
  4661. this._weightNext = halfDt / ( tNext - t1 );
  4662. this._offsetPrev = iPrev * stride;
  4663. this._offsetNext = iNext * stride;
  4664. },
  4665. interpolate_: function( i1, t0, t, t1 ) {
  4666. var result = this.resultBuffer,
  4667. values = this.sampleValues,
  4668. stride = this.valueSize,
  4669. o1 = i1 * stride, o0 = o1 - stride,
  4670. oP = this._offsetPrev, oN = this._offsetNext,
  4671. wP = this._weightPrev, wN = this._weightNext,
  4672. p = ( t - t0 ) / ( t1 - t0 ),
  4673. pp = p * p,
  4674. ppp = pp * p;
  4675. // evaluate polynomials
  4676. var sP = - wP * ppp + 2 * wP * pp - wP * p;
  4677. var s0 = ( 1 + wP ) * ppp + (-1.5 - 2 * wP ) * pp + ( -0.5 + wP ) * p + 1;
  4678. var s1 = (-1 - wN ) * ppp + ( 1.5 + wN ) * pp + 0.5 * p;
  4679. var sN = wN * ppp - wN * pp;
  4680. // combine data linearly
  4681. for ( var i = 0; i !== stride; ++ i ) {
  4682. result[ i ] =
  4683. sP * values[ oP + i ] +
  4684. s0 * values[ o0 + i ] +
  4685. s1 * values[ o1 + i ] +
  4686. sN * values[ oN + i ];
  4687. }
  4688. return result;
  4689. }
  4690. } );
  4691. // File:src/math/interpolants/DiscreteInterpolant.js
  4692. /**
  4693. *
  4694. * Interpolant that evaluates to the sample value at the position preceeding
  4695. * the parameter.
  4696. *
  4697. * @author tschw
  4698. */
  4699. THREE.DiscreteInterpolant = function(
  4700. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4701. THREE.Interpolant.call(
  4702. this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  4703. };
  4704. THREE.DiscreteInterpolant.prototype =
  4705. Object.assign( Object.create( THREE.Interpolant.prototype ), {
  4706. constructor: THREE.DiscreteInterpolant,
  4707. interpolate_: function( i1, t0, t, t1 ) {
  4708. return this.copySampleValue_( i1 - 1 );
  4709. }
  4710. } );
  4711. // File:src/math/interpolants/LinearInterpolant.js
  4712. /**
  4713. * @author tschw
  4714. */
  4715. THREE.LinearInterpolant = function(
  4716. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4717. THREE.Interpolant.call(
  4718. this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  4719. };
  4720. THREE.LinearInterpolant.prototype =
  4721. Object.assign( Object.create( THREE.Interpolant.prototype ), {
  4722. constructor: THREE.LinearInterpolant,
  4723. interpolate_: function( i1, t0, t, t1 ) {
  4724. var result = this.resultBuffer,
  4725. values = this.sampleValues,
  4726. stride = this.valueSize,
  4727. offset1 = i1 * stride,
  4728. offset0 = offset1 - stride,
  4729. weight1 = ( t - t0 ) / ( t1 - t0 ),
  4730. weight0 = 1 - weight1;
  4731. for ( var i = 0; i !== stride; ++ i ) {
  4732. result[ i ] =
  4733. values[ offset0 + i ] * weight0 +
  4734. values[ offset1 + i ] * weight1;
  4735. }
  4736. return result;
  4737. }
  4738. } );
  4739. // File:src/math/interpolants/QuaternionLinearInterpolant.js
  4740. /**
  4741. * Spherical linear unit quaternion interpolant.
  4742. *
  4743. * @author tschw
  4744. */
  4745. THREE.QuaternionLinearInterpolant = function(
  4746. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4747. THREE.Interpolant.call(
  4748. this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  4749. };
  4750. THREE.QuaternionLinearInterpolant.prototype =
  4751. Object.assign( Object.create( THREE.Interpolant.prototype ), {
  4752. constructor: THREE.QuaternionLinearInterpolant,
  4753. interpolate_: function( i1, t0, t, t1 ) {
  4754. var result = this.resultBuffer,
  4755. values = this.sampleValues,
  4756. stride = this.valueSize,
  4757. offset = i1 * stride,
  4758. alpha = ( t - t0 ) / ( t1 - t0 );
  4759. for ( var end = offset + stride; offset !== end; offset += 4 ) {
  4760. THREE.Quaternion.slerpFlat( result, 0,
  4761. values, offset - stride, values, offset, alpha );
  4762. }
  4763. return result;
  4764. }
  4765. } );
  4766. // File:src/core/Clock.js
  4767. /**
  4768. * @author alteredq / http://alteredqualia.com/
  4769. */
  4770. THREE.Clock = function ( autoStart ) {
  4771. this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
  4772. this.startTime = 0;
  4773. this.oldTime = 0;
  4774. this.elapsedTime = 0;
  4775. this.running = false;
  4776. };
  4777. THREE.Clock.prototype = {
  4778. constructor: THREE.Clock,
  4779. start: function () {
  4780. this.startTime = performance.now();
  4781. this.oldTime = this.startTime;
  4782. this.running = true;
  4783. },
  4784. stop: function () {
  4785. this.getElapsedTime();
  4786. this.running = false;
  4787. },
  4788. getElapsedTime: function () {
  4789. this.getDelta();
  4790. return this.elapsedTime;
  4791. },
  4792. getDelta: function () {
  4793. var diff = 0;
  4794. if ( this.autoStart && ! this.running ) {
  4795. this.start();
  4796. }
  4797. if ( this.running ) {
  4798. var newTime = performance.now();
  4799. diff = 0.001 * ( newTime - this.oldTime );
  4800. this.oldTime = newTime;
  4801. this.elapsedTime += diff;
  4802. }
  4803. return diff;
  4804. }
  4805. };
  4806. // File:src/core/EventDispatcher.js
  4807. /**
  4808. * https://github.com/mrdoob/eventdispatcher.js/
  4809. */
  4810. THREE.EventDispatcher = function () {};
  4811. THREE.EventDispatcher.prototype = {
  4812. constructor: THREE.EventDispatcher,
  4813. apply: function ( object ) {
  4814. object.addEventListener = THREE.EventDispatcher.prototype.addEventListener;
  4815. object.hasEventListener = THREE.EventDispatcher.prototype.hasEventListener;
  4816. object.removeEventListener = THREE.EventDispatcher.prototype.removeEventListener;
  4817. object.dispatchEvent = THREE.EventDispatcher.prototype.dispatchEvent;
  4818. },
  4819. addEventListener: function ( type, listener ) {
  4820. if ( this._listeners === undefined ) this._listeners = {};
  4821. var listeners = this._listeners;
  4822. if ( listeners[ type ] === undefined ) {
  4823. listeners[ type ] = [];
  4824. }
  4825. if ( listeners[ type ].indexOf( listener ) === - 1 ) {
  4826. listeners[ type ].push( listener );
  4827. }
  4828. },
  4829. hasEventListener: function ( type, listener ) {
  4830. if ( this._listeners === undefined ) return false;
  4831. var listeners = this._listeners;
  4832. if ( listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1 ) {
  4833. return true;
  4834. }
  4835. return false;
  4836. },
  4837. removeEventListener: function ( type, listener ) {
  4838. if ( this._listeners === undefined ) return;
  4839. var listeners = this._listeners;
  4840. var listenerArray = listeners[ type ];
  4841. if ( listenerArray !== undefined ) {
  4842. var index = listenerArray.indexOf( listener );
  4843. if ( index !== - 1 ) {
  4844. listenerArray.splice( index, 1 );
  4845. }
  4846. }
  4847. },
  4848. dispatchEvent: function ( event ) {
  4849. if ( this._listeners === undefined ) return;
  4850. var listeners = this._listeners;
  4851. var listenerArray = listeners[ event.type ];
  4852. if ( listenerArray !== undefined ) {
  4853. event.target = this;
  4854. var array = [];
  4855. var length = listenerArray.length;
  4856. for ( var i = 0; i < length; i ++ ) {
  4857. array[ i ] = listenerArray[ i ];
  4858. }
  4859. for ( var i = 0; i < length; i ++ ) {
  4860. array[ i ].call( this, event );
  4861. }
  4862. }
  4863. }
  4864. };
  4865. // File:src/core/Layers.js
  4866. /**
  4867. * @author mrdoob / http://mrdoob.com/
  4868. */
  4869. THREE.Layers = function () {
  4870. this.mask = 1;
  4871. };
  4872. THREE.Layers.prototype = {
  4873. constructor: THREE.Layers,
  4874. set: function ( channel ) {
  4875. this.mask = 1 << channel;
  4876. },
  4877. enable: function ( channel ) {
  4878. this.mask |= 1 << channel;
  4879. },
  4880. toggle: function ( channel ) {
  4881. this.mask ^= 1 << channel;
  4882. },
  4883. disable: function ( channel ) {
  4884. this.mask &= ~ ( 1 << channel );
  4885. },
  4886. test: function ( layers ) {
  4887. return ( this.mask & layers.mask ) !== 0;
  4888. }
  4889. };
  4890. // File:src/core/Raycaster.js
  4891. /**
  4892. * @author mrdoob / http://mrdoob.com/
  4893. * @author bhouston / http://clara.io/
  4894. * @author stephomi / http://stephaneginier.com/
  4895. */
  4896. ( function ( THREE ) {
  4897. THREE.Raycaster = function ( origin, direction, near, far ) {
  4898. this.ray = new THREE.Ray( origin, direction );
  4899. // direction is assumed to be normalized (for accurate distance calculations)
  4900. this.near = near || 0;
  4901. this.far = far || Infinity;
  4902. this.params = {
  4903. Mesh: {},
  4904. Line: {},
  4905. LOD: {},
  4906. Points: { threshold: 1 },
  4907. Sprite: {}
  4908. };
  4909. Object.defineProperties( this.params, {
  4910. PointCloud: {
  4911. get: function () {
  4912. console.warn( 'THREE.Raycaster: params.PointCloud has been renamed to params.Points.' );
  4913. return this.Points;
  4914. }
  4915. }
  4916. } );
  4917. };
  4918. function ascSort( a, b ) {
  4919. return a.distance - b.distance;
  4920. }
  4921. function intersectObject( object, raycaster, intersects, recursive ) {
  4922. if ( object.visible === false ) return;
  4923. object.raycast( raycaster, intersects );
  4924. if ( recursive === true ) {
  4925. var children = object.children;
  4926. for ( var i = 0, l = children.length; i < l; i ++ ) {
  4927. intersectObject( children[ i ], raycaster, intersects, true );
  4928. }
  4929. }
  4930. }
  4931. //
  4932. THREE.Raycaster.prototype = {
  4933. constructor: THREE.Raycaster,
  4934. linePrecision: 1,
  4935. set: function ( origin, direction ) {
  4936. // direction is assumed to be normalized (for accurate distance calculations)
  4937. this.ray.set( origin, direction );
  4938. },
  4939. setFromCamera: function ( coords, camera ) {
  4940. if ( camera instanceof THREE.PerspectiveCamera ) {
  4941. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  4942. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  4943. } else if ( camera instanceof THREE.OrthographicCamera ) {
  4944. this.ray.origin.set( coords.x, coords.y, - 1 ).unproject( camera );
  4945. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  4946. } else {
  4947. console.error( 'THREE.Raycaster: Unsupported camera type.' );
  4948. }
  4949. },
  4950. intersectObject: function ( object, recursive ) {
  4951. var intersects = [];
  4952. intersectObject( object, this, intersects, recursive );
  4953. intersects.sort( ascSort );
  4954. return intersects;
  4955. },
  4956. intersectObjects: function ( objects, recursive ) {
  4957. var intersects = [];
  4958. if ( Array.isArray( objects ) === false ) {
  4959. console.warn( 'THREE.Raycaster.intersectObjects: objects is not an Array.' );
  4960. return intersects;
  4961. }
  4962. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  4963. intersectObject( objects[ i ], this, intersects, recursive );
  4964. }
  4965. intersects.sort( ascSort );
  4966. return intersects;
  4967. }
  4968. };
  4969. }( THREE ) );
  4970. // File:src/core/Object3D.js
  4971. /**
  4972. * @author mrdoob / http://mrdoob.com/
  4973. * @author mikael emtinger / http://gomo.se/
  4974. * @author alteredq / http://alteredqualia.com/
  4975. * @author WestLangley / http://github.com/WestLangley
  4976. * @author elephantatwork / www.elephantatwork.ch
  4977. */
  4978. THREE.Object3D = function () {
  4979. Object.defineProperty( this, 'id', { value: THREE.Object3DIdCount ++ } );
  4980. this.uuid = THREE.Math.generateUUID();
  4981. this.name = '';
  4982. this.type = 'Object3D';
  4983. this.parent = null;
  4984. this.children = [];
  4985. this.up = THREE.Object3D.DefaultUp.clone();
  4986. var position = new THREE.Vector3();
  4987. var rotation = new THREE.Euler();
  4988. var quaternion = new THREE.Quaternion();
  4989. var scale = new THREE.Vector3( 1, 1, 1 );
  4990. function onRotationChange() {
  4991. quaternion.setFromEuler( rotation, false );
  4992. }
  4993. function onQuaternionChange() {
  4994. rotation.setFromQuaternion( quaternion, undefined, false );
  4995. }
  4996. rotation.onChange( onRotationChange );
  4997. quaternion.onChange( onQuaternionChange );
  4998. Object.defineProperties( this, {
  4999. position: {
  5000. enumerable: true,
  5001. value: position
  5002. },
  5003. rotation: {
  5004. enumerable: true,
  5005. value: rotation
  5006. },
  5007. quaternion: {
  5008. enumerable: true,
  5009. value: quaternion
  5010. },
  5011. scale: {
  5012. enumerable: true,
  5013. value: scale
  5014. },
  5015. modelViewMatrix: {
  5016. value: new THREE.Matrix4()
  5017. },
  5018. normalMatrix: {
  5019. value: new THREE.Matrix3()
  5020. }
  5021. } );
  5022. this.rotationAutoUpdate = true;
  5023. this.matrix = new THREE.Matrix4();
  5024. this.matrixWorld = new THREE.Matrix4();
  5025. this.matrixAutoUpdate = THREE.Object3D.DefaultMatrixAutoUpdate;
  5026. this.matrixWorldNeedsUpdate = false;
  5027. this.layers = new THREE.Layers();
  5028. this.visible = true;
  5029. this.castShadow = false;
  5030. this.receiveShadow = false;
  5031. this.frustumCulled = true;
  5032. this.renderOrder = 0;
  5033. this.userData = {};
  5034. };
  5035. THREE.Object3D.DefaultUp = new THREE.Vector3( 0, 1, 0 );
  5036. THREE.Object3D.DefaultMatrixAutoUpdate = true;
  5037. THREE.Object3D.prototype = {
  5038. constructor: THREE.Object3D,
  5039. applyMatrix: function ( matrix ) {
  5040. this.matrix.multiplyMatrices( matrix, this.matrix );
  5041. this.matrix.decompose( this.position, this.quaternion, this.scale );
  5042. },
  5043. setRotationFromAxisAngle: function ( axis, angle ) {
  5044. // assumes axis is normalized
  5045. this.quaternion.setFromAxisAngle( axis, angle );
  5046. },
  5047. setRotationFromEuler: function ( euler ) {
  5048. this.quaternion.setFromEuler( euler, true );
  5049. },
  5050. setRotationFromMatrix: function ( m ) {
  5051. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  5052. this.quaternion.setFromRotationMatrix( m );
  5053. },
  5054. setRotationFromQuaternion: function ( q ) {
  5055. // assumes q is normalized
  5056. this.quaternion.copy( q );
  5057. },
  5058. rotateOnAxis: function () {
  5059. // rotate object on axis in object space
  5060. // axis is assumed to be normalized
  5061. var q1 = new THREE.Quaternion();
  5062. return function ( axis, angle ) {
  5063. q1.setFromAxisAngle( axis, angle );
  5064. this.quaternion.multiply( q1 );
  5065. return this;
  5066. };
  5067. }(),
  5068. rotateX: function () {
  5069. var v1 = new THREE.Vector3( 1, 0, 0 );
  5070. return function ( angle ) {
  5071. return this.rotateOnAxis( v1, angle );
  5072. };
  5073. }(),
  5074. rotateY: function () {
  5075. var v1 = new THREE.Vector3( 0, 1, 0 );
  5076. return function ( angle ) {
  5077. return this.rotateOnAxis( v1, angle );
  5078. };
  5079. }(),
  5080. rotateZ: function () {
  5081. var v1 = new THREE.Vector3( 0, 0, 1 );
  5082. return function ( angle ) {
  5083. return this.rotateOnAxis( v1, angle );
  5084. };
  5085. }(),
  5086. translateOnAxis: function () {
  5087. // translate object by distance along axis in object space
  5088. // axis is assumed to be normalized
  5089. var v1 = new THREE.Vector3();
  5090. return function ( axis, distance ) {
  5091. v1.copy( axis ).applyQuaternion( this.quaternion );
  5092. this.position.add( v1.multiplyScalar( distance ) );
  5093. return this;
  5094. };
  5095. }(),
  5096. translateX: function () {
  5097. var v1 = new THREE.Vector3( 1, 0, 0 );
  5098. return function ( distance ) {
  5099. return this.translateOnAxis( v1, distance );
  5100. };
  5101. }(),
  5102. translateY: function () {
  5103. var v1 = new THREE.Vector3( 0, 1, 0 );
  5104. return function ( distance ) {
  5105. return this.translateOnAxis( v1, distance );
  5106. };
  5107. }(),
  5108. translateZ: function () {
  5109. var v1 = new THREE.Vector3( 0, 0, 1 );
  5110. return function ( distance ) {
  5111. return this.translateOnAxis( v1, distance );
  5112. };
  5113. }(),
  5114. localToWorld: function ( vector ) {
  5115. return vector.applyMatrix4( this.matrixWorld );
  5116. },
  5117. worldToLocal: function () {
  5118. var m1 = new THREE.Matrix4();
  5119. return function ( vector ) {
  5120. return vector.applyMatrix4( m1.getInverse( this.matrixWorld ) );
  5121. };
  5122. }(),
  5123. lookAt: function () {
  5124. // This routine does not support objects with rotated and/or translated parent(s)
  5125. var m1 = new THREE.Matrix4();
  5126. return function ( vector ) {
  5127. m1.lookAt( vector, this.position, this.up );
  5128. this.quaternion.setFromRotationMatrix( m1 );
  5129. };
  5130. }(),
  5131. add: function ( object ) {
  5132. if ( arguments.length > 1 ) {
  5133. for ( var i = 0; i < arguments.length; i ++ ) {
  5134. this.add( arguments[ i ] );
  5135. }
  5136. return this;
  5137. }
  5138. if ( object === this ) {
  5139. console.error( "THREE.Object3D.add: object can't be added as a child of itself.", object );
  5140. return this;
  5141. }
  5142. if ( object instanceof THREE.Object3D ) {
  5143. if ( object.parent !== null ) {
  5144. object.parent.remove( object );
  5145. }
  5146. object.parent = this;
  5147. object.dispatchEvent( { type: 'added' } );
  5148. this.children.push( object );
  5149. } else {
  5150. console.error( "THREE.Object3D.add: object not an instance of THREE.Object3D.", object );
  5151. }
  5152. return this;
  5153. },
  5154. remove: function ( object ) {
  5155. if ( arguments.length > 1 ) {
  5156. for ( var i = 0; i < arguments.length; i ++ ) {
  5157. this.remove( arguments[ i ] );
  5158. }
  5159. }
  5160. var index = this.children.indexOf( object );
  5161. if ( index !== - 1 ) {
  5162. object.parent = null;
  5163. object.dispatchEvent( { type: 'removed' } );
  5164. this.children.splice( index, 1 );
  5165. }
  5166. },
  5167. getObjectById: function ( id ) {
  5168. return this.getObjectByProperty( 'id', id );
  5169. },
  5170. getObjectByName: function ( name ) {
  5171. return this.getObjectByProperty( 'name', name );
  5172. },
  5173. getObjectByProperty: function ( name, value ) {
  5174. if ( this[ name ] === value ) return this;
  5175. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  5176. var child = this.children[ i ];
  5177. var object = child.getObjectByProperty( name, value );
  5178. if ( object !== undefined ) {
  5179. return object;
  5180. }
  5181. }
  5182. return undefined;
  5183. },
  5184. getWorldPosition: function ( optionalTarget ) {
  5185. var result = optionalTarget || new THREE.Vector3();
  5186. this.updateMatrixWorld( true );
  5187. return result.setFromMatrixPosition( this.matrixWorld );
  5188. },
  5189. getWorldQuaternion: function () {
  5190. var position = new THREE.Vector3();
  5191. var scale = new THREE.Vector3();
  5192. return function ( optionalTarget ) {
  5193. var result = optionalTarget || new THREE.Quaternion();
  5194. this.updateMatrixWorld( true );
  5195. this.matrixWorld.decompose( position, result, scale );
  5196. return result;
  5197. };
  5198. }(),
  5199. getWorldRotation: function () {
  5200. var quaternion = new THREE.Quaternion();
  5201. return function ( optionalTarget ) {
  5202. var result = optionalTarget || new THREE.Euler();
  5203. this.getWorldQuaternion( quaternion );
  5204. return result.setFromQuaternion( quaternion, this.rotation.order, false );
  5205. };
  5206. }(),
  5207. getWorldScale: function () {
  5208. var position = new THREE.Vector3();
  5209. var quaternion = new THREE.Quaternion();
  5210. return function ( optionalTarget ) {
  5211. var result = optionalTarget || new THREE.Vector3();
  5212. this.updateMatrixWorld( true );
  5213. this.matrixWorld.decompose( position, quaternion, result );
  5214. return result;
  5215. };
  5216. }(),
  5217. getWorldDirection: function () {
  5218. var quaternion = new THREE.Quaternion();
  5219. return function ( optionalTarget ) {
  5220. var result = optionalTarget || new THREE.Vector3();
  5221. this.getWorldQuaternion( quaternion );
  5222. return result.set( 0, 0, 1 ).applyQuaternion( quaternion );
  5223. };
  5224. }(),
  5225. raycast: function () {},
  5226. traverse: function ( callback ) {
  5227. callback( this );
  5228. var children = this.children;
  5229. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5230. children[ i ].traverse( callback );
  5231. }
  5232. },
  5233. traverseVisible: function ( callback ) {
  5234. if ( this.visible === false ) return;
  5235. callback( this );
  5236. var children = this.children;
  5237. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5238. children[ i ].traverseVisible( callback );
  5239. }
  5240. },
  5241. traverseAncestors: function ( callback ) {
  5242. var parent = this.parent;
  5243. if ( parent !== null ) {
  5244. callback( parent );
  5245. parent.traverseAncestors( callback );
  5246. }
  5247. },
  5248. updateMatrix: function () {
  5249. this.matrix.compose( this.position, this.quaternion, this.scale );
  5250. this.matrixWorldNeedsUpdate = true;
  5251. },
  5252. updateMatrixWorld: function ( force ) {
  5253. if ( this.matrixAutoUpdate === true ) this.updateMatrix();
  5254. if ( this.matrixWorldNeedsUpdate === true || force === true ) {
  5255. if ( this.parent === null ) {
  5256. this.matrixWorld.copy( this.matrix );
  5257. } else {
  5258. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  5259. }
  5260. this.matrixWorldNeedsUpdate = false;
  5261. force = true;
  5262. }
  5263. // update children
  5264. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  5265. this.children[ i ].updateMatrixWorld( force );
  5266. }
  5267. },
  5268. toJSON: function ( meta ) {
  5269. var isRootObject = ( meta === undefined );
  5270. var output = {};
  5271. // meta is a hash used to collect geometries, materials.
  5272. // not providing it implies that this is the root object
  5273. // being serialized.
  5274. if ( isRootObject ) {
  5275. // initialize meta obj
  5276. meta = {
  5277. geometries: {},
  5278. materials: {},
  5279. textures: {},
  5280. images: {}
  5281. };
  5282. output.metadata = {
  5283. version: 4.4,
  5284. type: 'Object',
  5285. generator: 'Object3D.toJSON'
  5286. };
  5287. }
  5288. // standard Object3D serialization
  5289. var object = {};
  5290. object.uuid = this.uuid;
  5291. object.type = this.type;
  5292. if ( this.name !== '' ) object.name = this.name;
  5293. if ( JSON.stringify( this.userData ) !== '{}' ) object.userData = this.userData;
  5294. if ( this.castShadow === true ) object.castShadow = true;
  5295. if ( this.receiveShadow === true ) object.receiveShadow = true;
  5296. if ( this.visible === false ) object.visible = false;
  5297. object.matrix = this.matrix.toArray();
  5298. //
  5299. if ( this.geometry !== undefined ) {
  5300. if ( meta.geometries[ this.geometry.uuid ] === undefined ) {
  5301. meta.geometries[ this.geometry.uuid ] = this.geometry.toJSON( meta );
  5302. }
  5303. object.geometry = this.geometry.uuid;
  5304. }
  5305. if ( this.material !== undefined ) {
  5306. if ( meta.materials[ this.material.uuid ] === undefined ) {
  5307. meta.materials[ this.material.uuid ] = this.material.toJSON( meta );
  5308. }
  5309. object.material = this.material.uuid;
  5310. }
  5311. //
  5312. if ( this.children.length > 0 ) {
  5313. object.children = [];
  5314. for ( var i = 0; i < this.children.length; i ++ ) {
  5315. object.children.push( this.children[ i ].toJSON( meta ).object );
  5316. }
  5317. }
  5318. if ( isRootObject ) {
  5319. var geometries = extractFromCache( meta.geometries );
  5320. var materials = extractFromCache( meta.materials );
  5321. var textures = extractFromCache( meta.textures );
  5322. var images = extractFromCache( meta.images );
  5323. if ( geometries.length > 0 ) output.geometries = geometries;
  5324. if ( materials.length > 0 ) output.materials = materials;
  5325. if ( textures.length > 0 ) output.textures = textures;
  5326. if ( images.length > 0 ) output.images = images;
  5327. }
  5328. output.object = object;
  5329. return output;
  5330. // extract data from the cache hash
  5331. // remove metadata on each item
  5332. // and return as array
  5333. function extractFromCache ( cache ) {
  5334. var values = [];
  5335. for ( var key in cache ) {
  5336. var data = cache[ key ];
  5337. delete data.metadata;
  5338. values.push( data );
  5339. }
  5340. return values;
  5341. }
  5342. },
  5343. clone: function ( recursive ) {
  5344. return new this.constructor().copy( this, recursive );
  5345. },
  5346. copy: function ( source, recursive ) {
  5347. if ( recursive === undefined ) recursive = true;
  5348. this.name = source.name;
  5349. this.up.copy( source.up );
  5350. this.position.copy( source.position );
  5351. this.quaternion.copy( source.quaternion );
  5352. this.scale.copy( source.scale );
  5353. this.rotationAutoUpdate = source.rotationAutoUpdate;
  5354. this.matrix.copy( source.matrix );
  5355. this.matrixWorld.copy( source.matrixWorld );
  5356. this.matrixAutoUpdate = source.matrixAutoUpdate;
  5357. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  5358. this.visible = source.visible;
  5359. this.castShadow = source.castShadow;
  5360. this.receiveShadow = source.receiveShadow;
  5361. this.frustumCulled = source.frustumCulled;
  5362. this.renderOrder = source.renderOrder;
  5363. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  5364. if ( recursive === true ) {
  5365. for ( var i = 0; i < source.children.length; i ++ ) {
  5366. var child = source.children[ i ];
  5367. this.add( child.clone() );
  5368. }
  5369. }
  5370. return this;
  5371. }
  5372. };
  5373. THREE.EventDispatcher.prototype.apply( THREE.Object3D.prototype );
  5374. THREE.Object3DIdCount = 0;
  5375. // File:src/core/Face3.js
  5376. /**
  5377. * @author mrdoob / http://mrdoob.com/
  5378. * @author alteredq / http://alteredqualia.com/
  5379. */
  5380. THREE.Face3 = function ( a, b, c, normal, color, materialIndex ) {
  5381. this.a = a;
  5382. this.b = b;
  5383. this.c = c;
  5384. this.normal = normal instanceof THREE.Vector3 ? normal : new THREE.Vector3();
  5385. this.vertexNormals = Array.isArray( normal ) ? normal : [];
  5386. this.color = color instanceof THREE.Color ? color : new THREE.Color();
  5387. this.vertexColors = Array.isArray( color ) ? color : [];
  5388. this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
  5389. };
  5390. THREE.Face3.prototype = {
  5391. constructor: THREE.Face3,
  5392. clone: function () {
  5393. return new this.constructor().copy( this );
  5394. },
  5395. copy: function ( source ) {
  5396. this.a = source.a;
  5397. this.b = source.b;
  5398. this.c = source.c;
  5399. this.normal.copy( source.normal );
  5400. this.color.copy( source.color );
  5401. this.materialIndex = source.materialIndex;
  5402. for ( var i = 0, il = source.vertexNormals.length; i < il; i ++ ) {
  5403. this.vertexNormals[ i ] = source.vertexNormals[ i ].clone();
  5404. }
  5405. for ( var i = 0, il = source.vertexColors.length; i < il; i ++ ) {
  5406. this.vertexColors[ i ] = source.vertexColors[ i ].clone();
  5407. }
  5408. return this;
  5409. }
  5410. };
  5411. // File:src/core/BufferAttribute.js
  5412. /**
  5413. * @author mrdoob / http://mrdoob.com/
  5414. */
  5415. THREE.BufferAttribute = function ( array, itemSize ) {
  5416. this.uuid = THREE.Math.generateUUID();
  5417. this.array = array;
  5418. this.itemSize = itemSize;
  5419. this.dynamic = false;
  5420. this.updateRange = { offset: 0, count: - 1 };
  5421. this.version = 0;
  5422. };
  5423. THREE.BufferAttribute.prototype = {
  5424. constructor: THREE.BufferAttribute,
  5425. get count() {
  5426. return this.array.length / this.itemSize;
  5427. },
  5428. set needsUpdate( value ) {
  5429. if ( value === true ) this.version ++;
  5430. },
  5431. setDynamic: function ( value ) {
  5432. this.dynamic = value;
  5433. return this;
  5434. },
  5435. copy: function ( source ) {
  5436. this.array = new source.array.constructor( source.array );
  5437. this.itemSize = source.itemSize;
  5438. this.dynamic = source.dynamic;
  5439. return this;
  5440. },
  5441. copyAt: function ( index1, attribute, index2 ) {
  5442. index1 *= this.itemSize;
  5443. index2 *= attribute.itemSize;
  5444. for ( var i = 0, l = this.itemSize; i < l; i ++ ) {
  5445. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5446. }
  5447. return this;
  5448. },
  5449. copyArray: function ( array ) {
  5450. this.array.set( array );
  5451. return this;
  5452. },
  5453. copyColorsArray: function ( colors ) {
  5454. var array = this.array, offset = 0;
  5455. for ( var i = 0, l = colors.length; i < l; i ++ ) {
  5456. var color = colors[ i ];
  5457. if ( color === undefined ) {
  5458. console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
  5459. color = new THREE.Color();
  5460. }
  5461. array[ offset ++ ] = color.r;
  5462. array[ offset ++ ] = color.g;
  5463. array[ offset ++ ] = color.b;
  5464. }
  5465. return this;
  5466. },
  5467. copyIndicesArray: function ( indices ) {
  5468. var array = this.array, offset = 0;
  5469. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  5470. var index = indices[ i ];
  5471. array[ offset ++ ] = index.a;
  5472. array[ offset ++ ] = index.b;
  5473. array[ offset ++ ] = index.c;
  5474. }
  5475. return this;
  5476. },
  5477. copyVector2sArray: function ( vectors ) {
  5478. var array = this.array, offset = 0;
  5479. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5480. var vector = vectors[ i ];
  5481. if ( vector === undefined ) {
  5482. console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
  5483. vector = new THREE.Vector2();
  5484. }
  5485. array[ offset ++ ] = vector.x;
  5486. array[ offset ++ ] = vector.y;
  5487. }
  5488. return this;
  5489. },
  5490. copyVector3sArray: function ( vectors ) {
  5491. var array = this.array, offset = 0;
  5492. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5493. var vector = vectors[ i ];
  5494. if ( vector === undefined ) {
  5495. console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
  5496. vector = new THREE.Vector3();
  5497. }
  5498. array[ offset ++ ] = vector.x;
  5499. array[ offset ++ ] = vector.y;
  5500. array[ offset ++ ] = vector.z;
  5501. }
  5502. return this;
  5503. },
  5504. copyVector4sArray: function ( vectors ) {
  5505. var array = this.array, offset = 0;
  5506. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5507. var vector = vectors[ i ];
  5508. if ( vector === undefined ) {
  5509. console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i );
  5510. vector = new THREE.Vector4();
  5511. }
  5512. array[ offset ++ ] = vector.x;
  5513. array[ offset ++ ] = vector.y;
  5514. array[ offset ++ ] = vector.z;
  5515. array[ offset ++ ] = vector.w;
  5516. }
  5517. return this;
  5518. },
  5519. set: function ( value, offset ) {
  5520. if ( offset === undefined ) offset = 0;
  5521. this.array.set( value, offset );
  5522. return this;
  5523. },
  5524. getX: function ( index ) {
  5525. return this.array[ index * this.itemSize ];
  5526. },
  5527. setX: function ( index, x ) {
  5528. this.array[ index * this.itemSize ] = x;
  5529. return this;
  5530. },
  5531. getY: function ( index ) {
  5532. return this.array[ index * this.itemSize + 1 ];
  5533. },
  5534. setY: function ( index, y ) {
  5535. this.array[ index * this.itemSize + 1 ] = y;
  5536. return this;
  5537. },
  5538. getZ: function ( index ) {
  5539. return this.array[ index * this.itemSize + 2 ];
  5540. },
  5541. setZ: function ( index, z ) {
  5542. this.array[ index * this.itemSize + 2 ] = z;
  5543. return this;
  5544. },
  5545. getW: function ( index ) {
  5546. return this.array[ index * this.itemSize + 3 ];
  5547. },
  5548. setW: function ( index, w ) {
  5549. this.array[ index * this.itemSize + 3 ] = w;
  5550. return this;
  5551. },
  5552. setXY: function ( index, x, y ) {
  5553. index *= this.itemSize;
  5554. this.array[ index + 0 ] = x;
  5555. this.array[ index + 1 ] = y;
  5556. return this;
  5557. },
  5558. setXYZ: function ( index, x, y, z ) {
  5559. index *= this.itemSize;
  5560. this.array[ index + 0 ] = x;
  5561. this.array[ index + 1 ] = y;
  5562. this.array[ index + 2 ] = z;
  5563. return this;
  5564. },
  5565. setXYZW: function ( index, x, y, z, w ) {
  5566. index *= this.itemSize;
  5567. this.array[ index + 0 ] = x;
  5568. this.array[ index + 1 ] = y;
  5569. this.array[ index + 2 ] = z;
  5570. this.array[ index + 3 ] = w;
  5571. return this;
  5572. },
  5573. clone: function () {
  5574. return new this.constructor().copy( this );
  5575. }
  5576. };
  5577. //
  5578. THREE.Int8Attribute = function ( array, itemSize ) {
  5579. return new THREE.BufferAttribute( new Int8Array( array ), itemSize );
  5580. };
  5581. THREE.Uint8Attribute = function ( array, itemSize ) {
  5582. return new THREE.BufferAttribute( new Uint8Array( array ), itemSize );
  5583. };
  5584. THREE.Uint8ClampedAttribute = function ( array, itemSize ) {
  5585. return new THREE.BufferAttribute( new Uint8ClampedArray( array ), itemSize );
  5586. };
  5587. THREE.Int16Attribute = function ( array, itemSize ) {
  5588. return new THREE.BufferAttribute( new Int16Array( array ), itemSize );
  5589. };
  5590. THREE.Uint16Attribute = function ( array, itemSize ) {
  5591. return new THREE.BufferAttribute( new Uint16Array( array ), itemSize );
  5592. };
  5593. THREE.Int32Attribute = function ( array, itemSize ) {
  5594. return new THREE.BufferAttribute( new Int32Array( array ), itemSize );
  5595. };
  5596. THREE.Uint32Attribute = function ( array, itemSize ) {
  5597. return new THREE.BufferAttribute( new Uint32Array( array ), itemSize );
  5598. };
  5599. THREE.Float32Attribute = function ( array, itemSize ) {
  5600. return new THREE.BufferAttribute( new Float32Array( array ), itemSize );
  5601. };
  5602. THREE.Float64Attribute = function ( array, itemSize ) {
  5603. return new THREE.BufferAttribute( new Float64Array( array ), itemSize );
  5604. };
  5605. // Deprecated
  5606. THREE.DynamicBufferAttribute = function ( array, itemSize ) {
  5607. console.warn( 'THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setDynamic( true ) instead.' );
  5608. return new THREE.BufferAttribute( array, itemSize ).setDynamic( true );
  5609. };
  5610. // File:src/core/InstancedBufferAttribute.js
  5611. /**
  5612. * @author benaadams / https://twitter.com/ben_a_adams
  5613. */
  5614. THREE.InstancedBufferAttribute = function ( array, itemSize, meshPerAttribute ) {
  5615. THREE.BufferAttribute.call( this, array, itemSize );
  5616. this.meshPerAttribute = meshPerAttribute || 1;
  5617. };
  5618. THREE.InstancedBufferAttribute.prototype = Object.create( THREE.BufferAttribute.prototype );
  5619. THREE.InstancedBufferAttribute.prototype.constructor = THREE.InstancedBufferAttribute;
  5620. THREE.InstancedBufferAttribute.prototype.copy = function ( source ) {
  5621. THREE.BufferAttribute.prototype.copy.call( this, source );
  5622. this.meshPerAttribute = source.meshPerAttribute;
  5623. return this;
  5624. };
  5625. // File:src/core/InterleavedBuffer.js
  5626. /**
  5627. * @author benaadams / https://twitter.com/ben_a_adams
  5628. */
  5629. THREE.InterleavedBuffer = function ( array, stride ) {
  5630. this.uuid = THREE.Math.generateUUID();
  5631. this.array = array;
  5632. this.stride = stride;
  5633. this.dynamic = false;
  5634. this.updateRange = { offset: 0, count: - 1 };
  5635. this.version = 0;
  5636. };
  5637. THREE.InterleavedBuffer.prototype = {
  5638. constructor: THREE.InterleavedBuffer,
  5639. get length () {
  5640. return this.array.length;
  5641. },
  5642. get count () {
  5643. return this.array.length / this.stride;
  5644. },
  5645. set needsUpdate( value ) {
  5646. if ( value === true ) this.version ++;
  5647. },
  5648. setDynamic: function ( value ) {
  5649. this.dynamic = value;
  5650. return this;
  5651. },
  5652. copy: function ( source ) {
  5653. this.array = new source.array.constructor( source.array );
  5654. this.stride = source.stride;
  5655. this.dynamic = source.dynamic;
  5656. return this;
  5657. },
  5658. copyAt: function ( index1, attribute, index2 ) {
  5659. index1 *= this.stride;
  5660. index2 *= attribute.stride;
  5661. for ( var i = 0, l = this.stride; i < l; i ++ ) {
  5662. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5663. }
  5664. return this;
  5665. },
  5666. set: function ( value, offset ) {
  5667. if ( offset === undefined ) offset = 0;
  5668. this.array.set( value, offset );
  5669. return this;
  5670. },
  5671. clone: function () {
  5672. return new this.constructor().copy( this );
  5673. }
  5674. };
  5675. // File:src/core/InstancedInterleavedBuffer.js
  5676. /**
  5677. * @author benaadams / https://twitter.com/ben_a_adams
  5678. */
  5679. THREE.InstancedInterleavedBuffer = function ( array, stride, meshPerAttribute ) {
  5680. THREE.InterleavedBuffer.call( this, array, stride );
  5681. this.meshPerAttribute = meshPerAttribute || 1;
  5682. };
  5683. THREE.InstancedInterleavedBuffer.prototype = Object.create( THREE.InterleavedBuffer.prototype );
  5684. THREE.InstancedInterleavedBuffer.prototype.constructor = THREE.InstancedInterleavedBuffer;
  5685. THREE.InstancedInterleavedBuffer.prototype.copy = function ( source ) {
  5686. THREE.InterleavedBuffer.prototype.copy.call( this, source );
  5687. this.meshPerAttribute = source.meshPerAttribute;
  5688. return this;
  5689. };
  5690. // File:src/core/InterleavedBufferAttribute.js
  5691. /**
  5692. * @author benaadams / https://twitter.com/ben_a_adams
  5693. */
  5694. THREE.InterleavedBufferAttribute = function ( interleavedBuffer, itemSize, offset ) {
  5695. this.uuid = THREE.Math.generateUUID();
  5696. this.data = interleavedBuffer;
  5697. this.itemSize = itemSize;
  5698. this.offset = offset;
  5699. };
  5700. THREE.InterleavedBufferAttribute.prototype = {
  5701. constructor: THREE.InterleavedBufferAttribute,
  5702. get length() {
  5703. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Please use .count.' );
  5704. return this.array.length;
  5705. },
  5706. get count() {
  5707. return this.data.count;
  5708. },
  5709. setX: function ( index, x ) {
  5710. this.data.array[ index * this.data.stride + this.offset ] = x;
  5711. return this;
  5712. },
  5713. setY: function ( index, y ) {
  5714. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  5715. return this;
  5716. },
  5717. setZ: function ( index, z ) {
  5718. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  5719. return this;
  5720. },
  5721. setW: function ( index, w ) {
  5722. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  5723. return this;
  5724. },
  5725. getX: function ( index ) {
  5726. return this.data.array[ index * this.data.stride + this.offset ];
  5727. },
  5728. getY: function ( index ) {
  5729. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  5730. },
  5731. getZ: function ( index ) {
  5732. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  5733. },
  5734. getW: function ( index ) {
  5735. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  5736. },
  5737. setXY: function ( index, x, y ) {
  5738. index = index * this.data.stride + this.offset;
  5739. this.data.array[ index + 0 ] = x;
  5740. this.data.array[ index + 1 ] = y;
  5741. return this;
  5742. },
  5743. setXYZ: function ( index, x, y, z ) {
  5744. index = index * this.data.stride + this.offset;
  5745. this.data.array[ index + 0 ] = x;
  5746. this.data.array[ index + 1 ] = y;
  5747. this.data.array[ index + 2 ] = z;
  5748. return this;
  5749. },
  5750. setXYZW: function ( index, x, y, z, w ) {
  5751. index = index * this.data.stride + this.offset;
  5752. this.data.array[ index + 0 ] = x;
  5753. this.data.array[ index + 1 ] = y;
  5754. this.data.array[ index + 2 ] = z;
  5755. this.data.array[ index + 3 ] = w;
  5756. return this;
  5757. }
  5758. };
  5759. // File:src/core/Geometry.js
  5760. /**
  5761. * @author mrdoob / http://mrdoob.com/
  5762. * @author kile / http://kile.stravaganza.org/
  5763. * @author alteredq / http://alteredqualia.com/
  5764. * @author mikael emtinger / http://gomo.se/
  5765. * @author zz85 / http://www.lab4games.net/zz85/blog
  5766. * @author bhouston / http://clara.io
  5767. */
  5768. THREE.Geometry = function () {
  5769. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  5770. this.uuid = THREE.Math.generateUUID();
  5771. this.name = '';
  5772. this.type = 'Geometry';
  5773. this.vertices = [];
  5774. this.colors = [];
  5775. this.faces = [];
  5776. this.faceVertexUvs = [ [] ];
  5777. this.morphTargets = [];
  5778. this.morphNormals = [];
  5779. this.skinWeights = [];
  5780. this.skinIndices = [];
  5781. this.lineDistances = [];
  5782. this.boundingBox = null;
  5783. this.boundingSphere = null;
  5784. // update flags
  5785. this.verticesNeedUpdate = false;
  5786. this.elementsNeedUpdate = false;
  5787. this.uvsNeedUpdate = false;
  5788. this.normalsNeedUpdate = false;
  5789. this.colorsNeedUpdate = false;
  5790. this.lineDistancesNeedUpdate = false;
  5791. this.groupsNeedUpdate = false;
  5792. };
  5793. THREE.Geometry.prototype = {
  5794. constructor: THREE.Geometry,
  5795. applyMatrix: function ( matrix ) {
  5796. var normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  5797. for ( var i = 0, il = this.vertices.length; i < il; i ++ ) {
  5798. var vertex = this.vertices[ i ];
  5799. vertex.applyMatrix4( matrix );
  5800. }
  5801. for ( var i = 0, il = this.faces.length; i < il; i ++ ) {
  5802. var face = this.faces[ i ];
  5803. face.normal.applyMatrix3( normalMatrix ).normalize();
  5804. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  5805. face.vertexNormals[ j ].applyMatrix3( normalMatrix ).normalize();
  5806. }
  5807. }
  5808. if ( this.boundingBox !== null ) {
  5809. this.computeBoundingBox();
  5810. }
  5811. if ( this.boundingSphere !== null ) {
  5812. this.computeBoundingSphere();
  5813. }
  5814. this.verticesNeedUpdate = true;
  5815. this.normalsNeedUpdate = true;
  5816. return this;
  5817. },
  5818. rotateX: function () {
  5819. // rotate geometry around world x-axis
  5820. var m1;
  5821. return function rotateX( angle ) {
  5822. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5823. m1.makeRotationX( angle );
  5824. this.applyMatrix( m1 );
  5825. return this;
  5826. };
  5827. }(),
  5828. rotateY: function () {
  5829. // rotate geometry around world y-axis
  5830. var m1;
  5831. return function rotateY( angle ) {
  5832. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5833. m1.makeRotationY( angle );
  5834. this.applyMatrix( m1 );
  5835. return this;
  5836. };
  5837. }(),
  5838. rotateZ: function () {
  5839. // rotate geometry around world z-axis
  5840. var m1;
  5841. return function rotateZ( angle ) {
  5842. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5843. m1.makeRotationZ( angle );
  5844. this.applyMatrix( m1 );
  5845. return this;
  5846. };
  5847. }(),
  5848. translate: function () {
  5849. // translate geometry
  5850. var m1;
  5851. return function translate( x, y, z ) {
  5852. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5853. m1.makeTranslation( x, y, z );
  5854. this.applyMatrix( m1 );
  5855. return this;
  5856. };
  5857. }(),
  5858. scale: function () {
  5859. // scale geometry
  5860. var m1;
  5861. return function scale( x, y, z ) {
  5862. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5863. m1.makeScale( x, y, z );
  5864. this.applyMatrix( m1 );
  5865. return this;
  5866. };
  5867. }(),
  5868. lookAt: function () {
  5869. var obj;
  5870. return function lookAt( vector ) {
  5871. if ( obj === undefined ) obj = new THREE.Object3D();
  5872. obj.lookAt( vector );
  5873. obj.updateMatrix();
  5874. this.applyMatrix( obj.matrix );
  5875. };
  5876. }(),
  5877. fromBufferGeometry: function ( geometry ) {
  5878. var scope = this;
  5879. var indices = geometry.index !== null ? geometry.index.array : undefined;
  5880. var attributes = geometry.attributes;
  5881. var positions = attributes.position.array;
  5882. var normals = attributes.normal !== undefined ? attributes.normal.array : undefined;
  5883. var colors = attributes.color !== undefined ? attributes.color.array : undefined;
  5884. var uvs = attributes.uv !== undefined ? attributes.uv.array : undefined;
  5885. var uvs2 = attributes.uv2 !== undefined ? attributes.uv2.array : undefined;
  5886. if ( uvs2 !== undefined ) this.faceVertexUvs[ 1 ] = [];
  5887. var tempNormals = [];
  5888. var tempUVs = [];
  5889. var tempUVs2 = [];
  5890. for ( var i = 0, j = 0; i < positions.length; i += 3, j += 2 ) {
  5891. scope.vertices.push( new THREE.Vector3( positions[ i ], positions[ i + 1 ], positions[ i + 2 ] ) );
  5892. if ( normals !== undefined ) {
  5893. tempNormals.push( new THREE.Vector3( normals[ i ], normals[ i + 1 ], normals[ i + 2 ] ) );
  5894. }
  5895. if ( colors !== undefined ) {
  5896. scope.colors.push( new THREE.Color( colors[ i ], colors[ i + 1 ], colors[ i + 2 ] ) );
  5897. }
  5898. if ( uvs !== undefined ) {
  5899. tempUVs.push( new THREE.Vector2( uvs[ j ], uvs[ j + 1 ] ) );
  5900. }
  5901. if ( uvs2 !== undefined ) {
  5902. tempUVs2.push( new THREE.Vector2( uvs2[ j ], uvs2[ j + 1 ] ) );
  5903. }
  5904. }
  5905. function addFace( a, b, c, materialIndex ) {
  5906. var vertexNormals = normals !== undefined ? [ tempNormals[ a ].clone(), tempNormals[ b ].clone(), tempNormals[ c ].clone() ] : [];
  5907. var vertexColors = colors !== undefined ? [ scope.colors[ a ].clone(), scope.colors[ b ].clone(), scope.colors[ c ].clone() ] : [];
  5908. var face = new THREE.Face3( a, b, c, vertexNormals, vertexColors, materialIndex );
  5909. scope.faces.push( face );
  5910. if ( uvs !== undefined ) {
  5911. scope.faceVertexUvs[ 0 ].push( [ tempUVs[ a ].clone(), tempUVs[ b ].clone(), tempUVs[ c ].clone() ] );
  5912. }
  5913. if ( uvs2 !== undefined ) {
  5914. scope.faceVertexUvs[ 1 ].push( [ tempUVs2[ a ].clone(), tempUVs2[ b ].clone(), tempUVs2[ c ].clone() ] );
  5915. }
  5916. }
  5917. if ( indices !== undefined ) {
  5918. var groups = geometry.groups;
  5919. if ( groups.length > 0 ) {
  5920. for ( var i = 0; i < groups.length; i ++ ) {
  5921. var group = groups[ i ];
  5922. var start = group.start;
  5923. var count = group.count;
  5924. for ( var j = start, jl = start + count; j < jl; j += 3 ) {
  5925. addFace( indices[ j ], indices[ j + 1 ], indices[ j + 2 ], group.materialIndex );
  5926. }
  5927. }
  5928. } else {
  5929. for ( var i = 0; i < indices.length; i += 3 ) {
  5930. addFace( indices[ i ], indices[ i + 1 ], indices[ i + 2 ] );
  5931. }
  5932. }
  5933. } else {
  5934. for ( var i = 0; i < positions.length / 3; i += 3 ) {
  5935. addFace( i, i + 1, i + 2 );
  5936. }
  5937. }
  5938. this.computeFaceNormals();
  5939. if ( geometry.boundingBox !== null ) {
  5940. this.boundingBox = geometry.boundingBox.clone();
  5941. }
  5942. if ( geometry.boundingSphere !== null ) {
  5943. this.boundingSphere = geometry.boundingSphere.clone();
  5944. }
  5945. return this;
  5946. },
  5947. center: function () {
  5948. this.computeBoundingBox();
  5949. var offset = this.boundingBox.center().negate();
  5950. this.translate( offset.x, offset.y, offset.z );
  5951. return offset;
  5952. },
  5953. normalize: function () {
  5954. this.computeBoundingSphere();
  5955. var center = this.boundingSphere.center;
  5956. var radius = this.boundingSphere.radius;
  5957. var s = radius === 0 ? 1 : 1.0 / radius;
  5958. var matrix = new THREE.Matrix4();
  5959. matrix.set(
  5960. s, 0, 0, - s * center.x,
  5961. 0, s, 0, - s * center.y,
  5962. 0, 0, s, - s * center.z,
  5963. 0, 0, 0, 1
  5964. );
  5965. this.applyMatrix( matrix );
  5966. return this;
  5967. },
  5968. computeFaceNormals: function () {
  5969. var cb = new THREE.Vector3(), ab = new THREE.Vector3();
  5970. for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5971. var face = this.faces[ f ];
  5972. var vA = this.vertices[ face.a ];
  5973. var vB = this.vertices[ face.b ];
  5974. var vC = this.vertices[ face.c ];
  5975. cb.subVectors( vC, vB );
  5976. ab.subVectors( vA, vB );
  5977. cb.cross( ab );
  5978. cb.normalize();
  5979. face.normal.copy( cb );
  5980. }
  5981. },
  5982. computeVertexNormals: function ( areaWeighted ) {
  5983. if ( areaWeighted === undefined ) areaWeighted = true;
  5984. var v, vl, f, fl, face, vertices;
  5985. vertices = new Array( this.vertices.length );
  5986. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5987. vertices[ v ] = new THREE.Vector3();
  5988. }
  5989. if ( areaWeighted ) {
  5990. // vertex normals weighted by triangle areas
  5991. // http://www.iquilezles.org/www/articles/normals/normals.htm
  5992. var vA, vB, vC;
  5993. var cb = new THREE.Vector3(), ab = new THREE.Vector3();
  5994. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5995. face = this.faces[ f ];
  5996. vA = this.vertices[ face.a ];
  5997. vB = this.vertices[ face.b ];
  5998. vC = this.vertices[ face.c ];
  5999. cb.subVectors( vC, vB );
  6000. ab.subVectors( vA, vB );
  6001. cb.cross( ab );
  6002. vertices[ face.a ].add( cb );
  6003. vertices[ face.b ].add( cb );
  6004. vertices[ face.c ].add( cb );
  6005. }
  6006. } else {
  6007. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6008. face = this.faces[ f ];
  6009. vertices[ face.a ].add( face.normal );
  6010. vertices[ face.b ].add( face.normal );
  6011. vertices[ face.c ].add( face.normal );
  6012. }
  6013. }
  6014. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  6015. vertices[ v ].normalize();
  6016. }
  6017. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6018. face = this.faces[ f ];
  6019. var vertexNormals = face.vertexNormals;
  6020. if ( vertexNormals.length === 3 ) {
  6021. vertexNormals[ 0 ].copy( vertices[ face.a ] );
  6022. vertexNormals[ 1 ].copy( vertices[ face.b ] );
  6023. vertexNormals[ 2 ].copy( vertices[ face.c ] );
  6024. } else {
  6025. vertexNormals[ 0 ] = vertices[ face.a ].clone();
  6026. vertexNormals[ 1 ] = vertices[ face.b ].clone();
  6027. vertexNormals[ 2 ] = vertices[ face.c ].clone();
  6028. }
  6029. }
  6030. if ( this.faces.length > 0 ) {
  6031. this.normalsNeedUpdate = true;
  6032. }
  6033. },
  6034. computeMorphNormals: function () {
  6035. var i, il, f, fl, face;
  6036. // save original normals
  6037. // - create temp variables on first access
  6038. // otherwise just copy (for faster repeated calls)
  6039. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6040. face = this.faces[ f ];
  6041. if ( ! face.__originalFaceNormal ) {
  6042. face.__originalFaceNormal = face.normal.clone();
  6043. } else {
  6044. face.__originalFaceNormal.copy( face.normal );
  6045. }
  6046. if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
  6047. for ( i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
  6048. if ( ! face.__originalVertexNormals[ i ] ) {
  6049. face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
  6050. } else {
  6051. face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
  6052. }
  6053. }
  6054. }
  6055. // use temp geometry to compute face and vertex normals for each morph
  6056. var tmpGeo = new THREE.Geometry();
  6057. tmpGeo.faces = this.faces;
  6058. for ( i = 0, il = this.morphTargets.length; i < il; i ++ ) {
  6059. // create on first access
  6060. if ( ! this.morphNormals[ i ] ) {
  6061. this.morphNormals[ i ] = {};
  6062. this.morphNormals[ i ].faceNormals = [];
  6063. this.morphNormals[ i ].vertexNormals = [];
  6064. var dstNormalsFace = this.morphNormals[ i ].faceNormals;
  6065. var dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
  6066. var faceNormal, vertexNormals;
  6067. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6068. faceNormal = new THREE.Vector3();
  6069. vertexNormals = { a: new THREE.Vector3(), b: new THREE.Vector3(), c: new THREE.Vector3() };
  6070. dstNormalsFace.push( faceNormal );
  6071. dstNormalsVertex.push( vertexNormals );
  6072. }
  6073. }
  6074. var morphNormals = this.morphNormals[ i ];
  6075. // set vertices to morph target
  6076. tmpGeo.vertices = this.morphTargets[ i ].vertices;
  6077. // compute morph normals
  6078. tmpGeo.computeFaceNormals();
  6079. tmpGeo.computeVertexNormals();
  6080. // store morph normals
  6081. var faceNormal, vertexNormals;
  6082. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6083. face = this.faces[ f ];
  6084. faceNormal = morphNormals.faceNormals[ f ];
  6085. vertexNormals = morphNormals.vertexNormals[ f ];
  6086. faceNormal.copy( face.normal );
  6087. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  6088. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  6089. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  6090. }
  6091. }
  6092. // restore original normals
  6093. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6094. face = this.faces[ f ];
  6095. face.normal = face.__originalFaceNormal;
  6096. face.vertexNormals = face.__originalVertexNormals;
  6097. }
  6098. },
  6099. computeTangents: function () {
  6100. console.warn( 'THREE.Geometry: .computeTangents() has been removed.' );
  6101. },
  6102. computeLineDistances: function () {
  6103. var d = 0;
  6104. var vertices = this.vertices;
  6105. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  6106. if ( i > 0 ) {
  6107. d += vertices[ i ].distanceTo( vertices[ i - 1 ] );
  6108. }
  6109. this.lineDistances[ i ] = d;
  6110. }
  6111. },
  6112. computeBoundingBox: function () {
  6113. if ( this.boundingBox === null ) {
  6114. this.boundingBox = new THREE.Box3();
  6115. }
  6116. this.boundingBox.setFromPoints( this.vertices );
  6117. },
  6118. computeBoundingSphere: function () {
  6119. if ( this.boundingSphere === null ) {
  6120. this.boundingSphere = new THREE.Sphere();
  6121. }
  6122. this.boundingSphere.setFromPoints( this.vertices );
  6123. },
  6124. merge: function ( geometry, matrix, materialIndexOffset ) {
  6125. if ( geometry instanceof THREE.Geometry === false ) {
  6126. console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry );
  6127. return;
  6128. }
  6129. var normalMatrix,
  6130. vertexOffset = this.vertices.length,
  6131. vertices1 = this.vertices,
  6132. vertices2 = geometry.vertices,
  6133. faces1 = this.faces,
  6134. faces2 = geometry.faces,
  6135. uvs1 = this.faceVertexUvs[ 0 ],
  6136. uvs2 = geometry.faceVertexUvs[ 0 ];
  6137. if ( materialIndexOffset === undefined ) materialIndexOffset = 0;
  6138. if ( matrix !== undefined ) {
  6139. normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  6140. }
  6141. // vertices
  6142. for ( var i = 0, il = vertices2.length; i < il; i ++ ) {
  6143. var vertex = vertices2[ i ];
  6144. var vertexCopy = vertex.clone();
  6145. if ( matrix !== undefined ) vertexCopy.applyMatrix4( matrix );
  6146. vertices1.push( vertexCopy );
  6147. }
  6148. // faces
  6149. for ( i = 0, il = faces2.length; i < il; i ++ ) {
  6150. var face = faces2[ i ], faceCopy, normal, color,
  6151. faceVertexNormals = face.vertexNormals,
  6152. faceVertexColors = face.vertexColors;
  6153. faceCopy = new THREE.Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset );
  6154. faceCopy.normal.copy( face.normal );
  6155. if ( normalMatrix !== undefined ) {
  6156. faceCopy.normal.applyMatrix3( normalMatrix ).normalize();
  6157. }
  6158. for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
  6159. normal = faceVertexNormals[ j ].clone();
  6160. if ( normalMatrix !== undefined ) {
  6161. normal.applyMatrix3( normalMatrix ).normalize();
  6162. }
  6163. faceCopy.vertexNormals.push( normal );
  6164. }
  6165. faceCopy.color.copy( face.color );
  6166. for ( var j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
  6167. color = faceVertexColors[ j ];
  6168. faceCopy.vertexColors.push( color.clone() );
  6169. }
  6170. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  6171. faces1.push( faceCopy );
  6172. }
  6173. // uvs
  6174. for ( i = 0, il = uvs2.length; i < il; i ++ ) {
  6175. var uv = uvs2[ i ], uvCopy = [];
  6176. if ( uv === undefined ) {
  6177. continue;
  6178. }
  6179. for ( var j = 0, jl = uv.length; j < jl; j ++ ) {
  6180. uvCopy.push( uv[ j ].clone() );
  6181. }
  6182. uvs1.push( uvCopy );
  6183. }
  6184. },
  6185. mergeMesh: function ( mesh ) {
  6186. if ( mesh instanceof THREE.Mesh === false ) {
  6187. console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh );
  6188. return;
  6189. }
  6190. mesh.matrixAutoUpdate && mesh.updateMatrix();
  6191. this.merge( mesh.geometry, mesh.matrix );
  6192. },
  6193. /*
  6194. * Checks for duplicate vertices with hashmap.
  6195. * Duplicated vertices are removed
  6196. * and faces' vertices are updated.
  6197. */
  6198. mergeVertices: function () {
  6199. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  6200. var unique = [], changes = [];
  6201. var v, key;
  6202. var precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001
  6203. var precision = Math.pow( 10, precisionPoints );
  6204. var i, il, face;
  6205. var indices, j, jl;
  6206. for ( i = 0, il = this.vertices.length; i < il; i ++ ) {
  6207. v = this.vertices[ i ];
  6208. key = Math.round( v.x * precision ) + '_' + Math.round( v.y * precision ) + '_' + Math.round( v.z * precision );
  6209. if ( verticesMap[ key ] === undefined ) {
  6210. verticesMap[ key ] = i;
  6211. unique.push( this.vertices[ i ] );
  6212. changes[ i ] = unique.length - 1;
  6213. } else {
  6214. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  6215. changes[ i ] = changes[ verticesMap[ key ] ];
  6216. }
  6217. }
  6218. // if faces are completely degenerate after merging vertices, we
  6219. // have to remove them from the geometry.
  6220. var faceIndicesToRemove = [];
  6221. for ( i = 0, il = this.faces.length; i < il; i ++ ) {
  6222. face = this.faces[ i ];
  6223. face.a = changes[ face.a ];
  6224. face.b = changes[ face.b ];
  6225. face.c = changes[ face.c ];
  6226. indices = [ face.a, face.b, face.c ];
  6227. var dupIndex = - 1;
  6228. // if any duplicate vertices are found in a Face3
  6229. // we have to remove the face as nothing can be saved
  6230. for ( var n = 0; n < 3; n ++ ) {
  6231. if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) {
  6232. dupIndex = n;
  6233. faceIndicesToRemove.push( i );
  6234. break;
  6235. }
  6236. }
  6237. }
  6238. for ( i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
  6239. var idx = faceIndicesToRemove[ i ];
  6240. this.faces.splice( idx, 1 );
  6241. for ( j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {
  6242. this.faceVertexUvs[ j ].splice( idx, 1 );
  6243. }
  6244. }
  6245. // Use unique set of vertices
  6246. var diff = this.vertices.length - unique.length;
  6247. this.vertices = unique;
  6248. return diff;
  6249. },
  6250. sortFacesByMaterialIndex: function () {
  6251. var faces = this.faces;
  6252. var length = faces.length;
  6253. // tag faces
  6254. for ( var i = 0; i < length; i ++ ) {
  6255. faces[ i ]._id = i;
  6256. }
  6257. // sort faces
  6258. function materialIndexSort( a, b ) {
  6259. return a.materialIndex - b.materialIndex;
  6260. }
  6261. faces.sort( materialIndexSort );
  6262. // sort uvs
  6263. var uvs1 = this.faceVertexUvs[ 0 ];
  6264. var uvs2 = this.faceVertexUvs[ 1 ];
  6265. var newUvs1, newUvs2;
  6266. if ( uvs1 && uvs1.length === length ) newUvs1 = [];
  6267. if ( uvs2 && uvs2.length === length ) newUvs2 = [];
  6268. for ( var i = 0; i < length; i ++ ) {
  6269. var id = faces[ i ]._id;
  6270. if ( newUvs1 ) newUvs1.push( uvs1[ id ] );
  6271. if ( newUvs2 ) newUvs2.push( uvs2[ id ] );
  6272. }
  6273. if ( newUvs1 ) this.faceVertexUvs[ 0 ] = newUvs1;
  6274. if ( newUvs2 ) this.faceVertexUvs[ 1 ] = newUvs2;
  6275. },
  6276. toJSON: function () {
  6277. var data = {
  6278. metadata: {
  6279. version: 4.4,
  6280. type: 'Geometry',
  6281. generator: 'Geometry.toJSON'
  6282. }
  6283. };
  6284. // standard Geometry serialization
  6285. data.uuid = this.uuid;
  6286. data.type = this.type;
  6287. if ( this.name !== '' ) data.name = this.name;
  6288. if ( this.parameters !== undefined ) {
  6289. var parameters = this.parameters;
  6290. for ( var key in parameters ) {
  6291. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  6292. }
  6293. return data;
  6294. }
  6295. var vertices = [];
  6296. for ( var i = 0; i < this.vertices.length; i ++ ) {
  6297. var vertex = this.vertices[ i ];
  6298. vertices.push( vertex.x, vertex.y, vertex.z );
  6299. }
  6300. var faces = [];
  6301. var normals = [];
  6302. var normalsHash = {};
  6303. var colors = [];
  6304. var colorsHash = {};
  6305. var uvs = [];
  6306. var uvsHash = {};
  6307. for ( var i = 0; i < this.faces.length; i ++ ) {
  6308. var face = this.faces[ i ];
  6309. var hasMaterial = true;
  6310. var hasFaceUv = false; // deprecated
  6311. var hasFaceVertexUv = this.faceVertexUvs[ 0 ][ i ] !== undefined;
  6312. var hasFaceNormal = face.normal.length() > 0;
  6313. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  6314. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  6315. var hasFaceVertexColor = face.vertexColors.length > 0;
  6316. var faceType = 0;
  6317. faceType = setBit( faceType, 0, 0 ); // isQuad
  6318. faceType = setBit( faceType, 1, hasMaterial );
  6319. faceType = setBit( faceType, 2, hasFaceUv );
  6320. faceType = setBit( faceType, 3, hasFaceVertexUv );
  6321. faceType = setBit( faceType, 4, hasFaceNormal );
  6322. faceType = setBit( faceType, 5, hasFaceVertexNormal );
  6323. faceType = setBit( faceType, 6, hasFaceColor );
  6324. faceType = setBit( faceType, 7, hasFaceVertexColor );
  6325. faces.push( faceType );
  6326. faces.push( face.a, face.b, face.c );
  6327. faces.push( face.materialIndex );
  6328. if ( hasFaceVertexUv ) {
  6329. var faceVertexUvs = this.faceVertexUvs[ 0 ][ i ];
  6330. faces.push(
  6331. getUvIndex( faceVertexUvs[ 0 ] ),
  6332. getUvIndex( faceVertexUvs[ 1 ] ),
  6333. getUvIndex( faceVertexUvs[ 2 ] )
  6334. );
  6335. }
  6336. if ( hasFaceNormal ) {
  6337. faces.push( getNormalIndex( face.normal ) );
  6338. }
  6339. if ( hasFaceVertexNormal ) {
  6340. var vertexNormals = face.vertexNormals;
  6341. faces.push(
  6342. getNormalIndex( vertexNormals[ 0 ] ),
  6343. getNormalIndex( vertexNormals[ 1 ] ),
  6344. getNormalIndex( vertexNormals[ 2 ] )
  6345. );
  6346. }
  6347. if ( hasFaceColor ) {
  6348. faces.push( getColorIndex( face.color ) );
  6349. }
  6350. if ( hasFaceVertexColor ) {
  6351. var vertexColors = face.vertexColors;
  6352. faces.push(
  6353. getColorIndex( vertexColors[ 0 ] ),
  6354. getColorIndex( vertexColors[ 1 ] ),
  6355. getColorIndex( vertexColors[ 2 ] )
  6356. );
  6357. }
  6358. }
  6359. function setBit( value, position, enabled ) {
  6360. return enabled ? value | ( 1 << position ) : value & ( ~ ( 1 << position ) );
  6361. }
  6362. function getNormalIndex( normal ) {
  6363. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  6364. if ( normalsHash[ hash ] !== undefined ) {
  6365. return normalsHash[ hash ];
  6366. }
  6367. normalsHash[ hash ] = normals.length / 3;
  6368. normals.push( normal.x, normal.y, normal.z );
  6369. return normalsHash[ hash ];
  6370. }
  6371. function getColorIndex( color ) {
  6372. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  6373. if ( colorsHash[ hash ] !== undefined ) {
  6374. return colorsHash[ hash ];
  6375. }
  6376. colorsHash[ hash ] = colors.length;
  6377. colors.push( color.getHex() );
  6378. return colorsHash[ hash ];
  6379. }
  6380. function getUvIndex( uv ) {
  6381. var hash = uv.x.toString() + uv.y.toString();
  6382. if ( uvsHash[ hash ] !== undefined ) {
  6383. return uvsHash[ hash ];
  6384. }
  6385. uvsHash[ hash ] = uvs.length / 2;
  6386. uvs.push( uv.x, uv.y );
  6387. return uvsHash[ hash ];
  6388. }
  6389. data.data = {};
  6390. data.data.vertices = vertices;
  6391. data.data.normals = normals;
  6392. if ( colors.length > 0 ) data.data.colors = colors;
  6393. if ( uvs.length > 0 ) data.data.uvs = [ uvs ]; // temporal backward compatibility
  6394. data.data.faces = faces;
  6395. return data;
  6396. },
  6397. clone: function () {
  6398. /*
  6399. // Handle primitives
  6400. var parameters = this.parameters;
  6401. if ( parameters !== undefined ) {
  6402. var values = [];
  6403. for ( var key in parameters ) {
  6404. values.push( parameters[ key ] );
  6405. }
  6406. var geometry = Object.create( this.constructor.prototype );
  6407. this.constructor.apply( geometry, values );
  6408. return geometry;
  6409. }
  6410. return new this.constructor().copy( this );
  6411. */
  6412. return new THREE.Geometry().copy( this );
  6413. },
  6414. copy: function ( source ) {
  6415. this.vertices = [];
  6416. this.faces = [];
  6417. this.faceVertexUvs = [ [] ];
  6418. var vertices = source.vertices;
  6419. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  6420. this.vertices.push( vertices[ i ].clone() );
  6421. }
  6422. var faces = source.faces;
  6423. for ( var i = 0, il = faces.length; i < il; i ++ ) {
  6424. this.faces.push( faces[ i ].clone() );
  6425. }
  6426. for ( var i = 0, il = source.faceVertexUvs.length; i < il; i ++ ) {
  6427. var faceVertexUvs = source.faceVertexUvs[ i ];
  6428. if ( this.faceVertexUvs[ i ] === undefined ) {
  6429. this.faceVertexUvs[ i ] = [];
  6430. }
  6431. for ( var j = 0, jl = faceVertexUvs.length; j < jl; j ++ ) {
  6432. var uvs = faceVertexUvs[ j ], uvsCopy = [];
  6433. for ( var k = 0, kl = uvs.length; k < kl; k ++ ) {
  6434. var uv = uvs[ k ];
  6435. uvsCopy.push( uv.clone() );
  6436. }
  6437. this.faceVertexUvs[ i ].push( uvsCopy );
  6438. }
  6439. }
  6440. return this;
  6441. },
  6442. dispose: function () {
  6443. this.dispatchEvent( { type: 'dispose' } );
  6444. }
  6445. };
  6446. THREE.EventDispatcher.prototype.apply( THREE.Geometry.prototype );
  6447. THREE.GeometryIdCount = 0;
  6448. // File:src/core/DirectGeometry.js
  6449. /**
  6450. * @author mrdoob / http://mrdoob.com/
  6451. */
  6452. THREE.DirectGeometry = function () {
  6453. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  6454. this.uuid = THREE.Math.generateUUID();
  6455. this.name = '';
  6456. this.type = 'DirectGeometry';
  6457. this.indices = [];
  6458. this.vertices = [];
  6459. this.normals = [];
  6460. this.colors = [];
  6461. this.uvs = [];
  6462. this.uvs2 = [];
  6463. this.groups = [];
  6464. this.morphTargets = {};
  6465. this.skinWeights = [];
  6466. this.skinIndices = [];
  6467. // this.lineDistances = [];
  6468. this.boundingBox = null;
  6469. this.boundingSphere = null;
  6470. // update flags
  6471. this.verticesNeedUpdate = false;
  6472. this.normalsNeedUpdate = false;
  6473. this.colorsNeedUpdate = false;
  6474. this.uvsNeedUpdate = false;
  6475. this.groupsNeedUpdate = false;
  6476. };
  6477. THREE.DirectGeometry.prototype = {
  6478. constructor: THREE.DirectGeometry,
  6479. computeBoundingBox: THREE.Geometry.prototype.computeBoundingBox,
  6480. computeBoundingSphere: THREE.Geometry.prototype.computeBoundingSphere,
  6481. computeFaceNormals: function () {
  6482. console.warn( 'THREE.DirectGeometry: computeFaceNormals() is not a method of this type of geometry.' );
  6483. },
  6484. computeVertexNormals: function () {
  6485. console.warn( 'THREE.DirectGeometry: computeVertexNormals() is not a method of this type of geometry.' );
  6486. },
  6487. computeGroups: function ( geometry ) {
  6488. var group;
  6489. var groups = [];
  6490. var materialIndex;
  6491. var faces = geometry.faces;
  6492. for ( var i = 0; i < faces.length; i ++ ) {
  6493. var face = faces[ i ];
  6494. // materials
  6495. if ( face.materialIndex !== materialIndex ) {
  6496. materialIndex = face.materialIndex;
  6497. if ( group !== undefined ) {
  6498. group.count = ( i * 3 ) - group.start;
  6499. groups.push( group );
  6500. }
  6501. group = {
  6502. start: i * 3,
  6503. materialIndex: materialIndex
  6504. };
  6505. }
  6506. }
  6507. if ( group !== undefined ) {
  6508. group.count = ( i * 3 ) - group.start;
  6509. groups.push( group );
  6510. }
  6511. this.groups = groups;
  6512. },
  6513. fromGeometry: function ( geometry ) {
  6514. var faces = geometry.faces;
  6515. var vertices = geometry.vertices;
  6516. var faceVertexUvs = geometry.faceVertexUvs;
  6517. var hasFaceVertexUv = faceVertexUvs[ 0 ] && faceVertexUvs[ 0 ].length > 0;
  6518. var hasFaceVertexUv2 = faceVertexUvs[ 1 ] && faceVertexUvs[ 1 ].length > 0;
  6519. // morphs
  6520. var morphTargets = geometry.morphTargets;
  6521. var morphTargetsLength = morphTargets.length;
  6522. var morphTargetsPosition;
  6523. if ( morphTargetsLength > 0 ) {
  6524. morphTargetsPosition = [];
  6525. for ( var i = 0; i < morphTargetsLength; i ++ ) {
  6526. morphTargetsPosition[ i ] = [];
  6527. }
  6528. this.morphTargets.position = morphTargetsPosition;
  6529. }
  6530. var morphNormals = geometry.morphNormals;
  6531. var morphNormalsLength = morphNormals.length;
  6532. var morphTargetsNormal;
  6533. if ( morphNormalsLength > 0 ) {
  6534. morphTargetsNormal = [];
  6535. for ( var i = 0; i < morphNormalsLength; i ++ ) {
  6536. morphTargetsNormal[ i ] = [];
  6537. }
  6538. this.morphTargets.normal = morphTargetsNormal;
  6539. }
  6540. // skins
  6541. var skinIndices = geometry.skinIndices;
  6542. var skinWeights = geometry.skinWeights;
  6543. var hasSkinIndices = skinIndices.length === vertices.length;
  6544. var hasSkinWeights = skinWeights.length === vertices.length;
  6545. //
  6546. for ( var i = 0; i < faces.length; i ++ ) {
  6547. var face = faces[ i ];
  6548. this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] );
  6549. var vertexNormals = face.vertexNormals;
  6550. if ( vertexNormals.length === 3 ) {
  6551. this.normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
  6552. } else {
  6553. var normal = face.normal;
  6554. this.normals.push( normal, normal, normal );
  6555. }
  6556. var vertexColors = face.vertexColors;
  6557. if ( vertexColors.length === 3 ) {
  6558. this.colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
  6559. } else {
  6560. var color = face.color;
  6561. this.colors.push( color, color, color );
  6562. }
  6563. if ( hasFaceVertexUv === true ) {
  6564. var vertexUvs = faceVertexUvs[ 0 ][ i ];
  6565. if ( vertexUvs !== undefined ) {
  6566. this.uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6567. } else {
  6568. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', i );
  6569. this.uvs.push( new THREE.Vector2(), new THREE.Vector2(), new THREE.Vector2() );
  6570. }
  6571. }
  6572. if ( hasFaceVertexUv2 === true ) {
  6573. var vertexUvs = faceVertexUvs[ 1 ][ i ];
  6574. if ( vertexUvs !== undefined ) {
  6575. this.uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6576. } else {
  6577. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', i );
  6578. this.uvs2.push( new THREE.Vector2(), new THREE.Vector2(), new THREE.Vector2() );
  6579. }
  6580. }
  6581. // morphs
  6582. for ( var j = 0; j < morphTargetsLength; j ++ ) {
  6583. var morphTarget = morphTargets[ j ].vertices;
  6584. morphTargetsPosition[ j ].push( morphTarget[ face.a ], morphTarget[ face.b ], morphTarget[ face.c ] );
  6585. }
  6586. for ( var j = 0; j < morphNormalsLength; j ++ ) {
  6587. var morphNormal = morphNormals[ j ].vertexNormals[ i ];
  6588. morphTargetsNormal[ j ].push( morphNormal.a, morphNormal.b, morphNormal.c );
  6589. }
  6590. // skins
  6591. if ( hasSkinIndices ) {
  6592. this.skinIndices.push( skinIndices[ face.a ], skinIndices[ face.b ], skinIndices[ face.c ] );
  6593. }
  6594. if ( hasSkinWeights ) {
  6595. this.skinWeights.push( skinWeights[ face.a ], skinWeights[ face.b ], skinWeights[ face.c ] );
  6596. }
  6597. }
  6598. this.computeGroups( geometry );
  6599. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6600. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6601. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6602. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6603. this.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6604. return this;
  6605. },
  6606. dispose: function () {
  6607. this.dispatchEvent( { type: 'dispose' } );
  6608. }
  6609. };
  6610. THREE.EventDispatcher.prototype.apply( THREE.DirectGeometry.prototype );
  6611. // File:src/core/BufferGeometry.js
  6612. /**
  6613. * @author alteredq / http://alteredqualia.com/
  6614. * @author mrdoob / http://mrdoob.com/
  6615. */
  6616. THREE.BufferGeometry = function () {
  6617. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  6618. this.uuid = THREE.Math.generateUUID();
  6619. this.name = '';
  6620. this.type = 'BufferGeometry';
  6621. this.index = null;
  6622. this.attributes = {};
  6623. this.morphAttributes = {};
  6624. this.groups = [];
  6625. this.boundingBox = null;
  6626. this.boundingSphere = null;
  6627. this.drawRange = { start: 0, count: Infinity };
  6628. };
  6629. THREE.BufferGeometry.prototype = {
  6630. constructor: THREE.BufferGeometry,
  6631. getIndex: function () {
  6632. return this.index;
  6633. },
  6634. setIndex: function ( index ) {
  6635. this.index = index;
  6636. },
  6637. addAttribute: function ( name, attribute ) {
  6638. if ( attribute instanceof THREE.BufferAttribute === false && attribute instanceof THREE.InterleavedBufferAttribute === false ) {
  6639. console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
  6640. this.addAttribute( name, new THREE.BufferAttribute( arguments[ 1 ], arguments[ 2 ] ) );
  6641. return;
  6642. }
  6643. if ( name === 'index' ) {
  6644. console.warn( 'THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.' );
  6645. this.setIndex( attribute );
  6646. return;
  6647. }
  6648. this.attributes[ name ] = attribute;
  6649. return this;
  6650. },
  6651. getAttribute: function ( name ) {
  6652. return this.attributes[ name ];
  6653. },
  6654. removeAttribute: function ( name ) {
  6655. delete this.attributes[ name ];
  6656. return this;
  6657. },
  6658. addGroup: function ( start, count, materialIndex ) {
  6659. this.groups.push( {
  6660. start: start,
  6661. count: count,
  6662. materialIndex: materialIndex !== undefined ? materialIndex : 0
  6663. } );
  6664. },
  6665. clearGroups: function () {
  6666. this.groups = [];
  6667. },
  6668. setDrawRange: function ( start, count ) {
  6669. this.drawRange.start = start;
  6670. this.drawRange.count = count;
  6671. },
  6672. applyMatrix: function ( matrix ) {
  6673. var position = this.attributes.position;
  6674. if ( position !== undefined ) {
  6675. matrix.applyToVector3Array( position.array );
  6676. position.needsUpdate = true;
  6677. }
  6678. var normal = this.attributes.normal;
  6679. if ( normal !== undefined ) {
  6680. var normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  6681. normalMatrix.applyToVector3Array( normal.array );
  6682. normal.needsUpdate = true;
  6683. }
  6684. if ( this.boundingBox !== null ) {
  6685. this.computeBoundingBox();
  6686. }
  6687. if ( this.boundingSphere !== null ) {
  6688. this.computeBoundingSphere();
  6689. }
  6690. return this;
  6691. },
  6692. rotateX: function () {
  6693. // rotate geometry around world x-axis
  6694. var m1;
  6695. return function rotateX( angle ) {
  6696. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6697. m1.makeRotationX( angle );
  6698. this.applyMatrix( m1 );
  6699. return this;
  6700. };
  6701. }(),
  6702. rotateY: function () {
  6703. // rotate geometry around world y-axis
  6704. var m1;
  6705. return function rotateY( angle ) {
  6706. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6707. m1.makeRotationY( angle );
  6708. this.applyMatrix( m1 );
  6709. return this;
  6710. };
  6711. }(),
  6712. rotateZ: function () {
  6713. // rotate geometry around world z-axis
  6714. var m1;
  6715. return function rotateZ( angle ) {
  6716. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6717. m1.makeRotationZ( angle );
  6718. this.applyMatrix( m1 );
  6719. return this;
  6720. };
  6721. }(),
  6722. translate: function () {
  6723. // translate geometry
  6724. var m1;
  6725. return function translate( x, y, z ) {
  6726. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6727. m1.makeTranslation( x, y, z );
  6728. this.applyMatrix( m1 );
  6729. return this;
  6730. };
  6731. }(),
  6732. scale: function () {
  6733. // scale geometry
  6734. var m1;
  6735. return function scale( x, y, z ) {
  6736. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6737. m1.makeScale( x, y, z );
  6738. this.applyMatrix( m1 );
  6739. return this;
  6740. };
  6741. }(),
  6742. lookAt: function () {
  6743. var obj;
  6744. return function lookAt( vector ) {
  6745. if ( obj === undefined ) obj = new THREE.Object3D();
  6746. obj.lookAt( vector );
  6747. obj.updateMatrix();
  6748. this.applyMatrix( obj.matrix );
  6749. };
  6750. }(),
  6751. center: function () {
  6752. this.computeBoundingBox();
  6753. var offset = this.boundingBox.center().negate();
  6754. this.translate( offset.x, offset.y, offset.z );
  6755. return offset;
  6756. },
  6757. setFromObject: function ( object ) {
  6758. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  6759. var geometry = object.geometry;
  6760. if ( object instanceof THREE.Points || object instanceof THREE.Line ) {
  6761. var positions = new THREE.Float32Attribute( geometry.vertices.length * 3, 3 );
  6762. var colors = new THREE.Float32Attribute( geometry.colors.length * 3, 3 );
  6763. this.addAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) );
  6764. this.addAttribute( 'color', colors.copyColorsArray( geometry.colors ) );
  6765. if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) {
  6766. var lineDistances = new THREE.Float32Attribute( geometry.lineDistances.length, 1 );
  6767. this.addAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) );
  6768. }
  6769. if ( geometry.boundingSphere !== null ) {
  6770. this.boundingSphere = geometry.boundingSphere.clone();
  6771. }
  6772. if ( geometry.boundingBox !== null ) {
  6773. this.boundingBox = geometry.boundingBox.clone();
  6774. }
  6775. } else if ( object instanceof THREE.Mesh ) {
  6776. if ( geometry instanceof THREE.Geometry ) {
  6777. this.fromGeometry( geometry );
  6778. }
  6779. }
  6780. return this;
  6781. },
  6782. updateFromObject: function ( object ) {
  6783. var geometry = object.geometry;
  6784. if ( object instanceof THREE.Mesh ) {
  6785. var direct = geometry.__directGeometry;
  6786. if ( direct === undefined ) {
  6787. return this.fromGeometry( geometry );
  6788. }
  6789. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6790. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6791. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6792. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6793. direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6794. geometry.verticesNeedUpdate = false;
  6795. geometry.normalsNeedUpdate = false;
  6796. geometry.colorsNeedUpdate = false;
  6797. geometry.uvsNeedUpdate = false;
  6798. geometry.groupsNeedUpdate = false;
  6799. geometry = direct;
  6800. }
  6801. if ( geometry.verticesNeedUpdate === true ) {
  6802. var attribute = this.attributes.position;
  6803. if ( attribute !== undefined ) {
  6804. attribute.copyVector3sArray( geometry.vertices );
  6805. attribute.needsUpdate = true;
  6806. }
  6807. geometry.verticesNeedUpdate = false;
  6808. }
  6809. if ( geometry.normalsNeedUpdate === true ) {
  6810. var attribute = this.attributes.normal;
  6811. if ( attribute !== undefined ) {
  6812. attribute.copyVector3sArray( geometry.normals );
  6813. attribute.needsUpdate = true;
  6814. }
  6815. geometry.normalsNeedUpdate = false;
  6816. }
  6817. if ( geometry.colorsNeedUpdate === true ) {
  6818. var attribute = this.attributes.color;
  6819. if ( attribute !== undefined ) {
  6820. attribute.copyColorsArray( geometry.colors );
  6821. attribute.needsUpdate = true;
  6822. }
  6823. geometry.colorsNeedUpdate = false;
  6824. }
  6825. if ( geometry.uvsNeedUpdate ) {
  6826. var attribute = this.attributes.uv;
  6827. if ( attribute !== undefined ) {
  6828. attribute.copyVector2sArray( geometry.uvs );
  6829. attribute.needsUpdate = true;
  6830. }
  6831. geometry.uvsNeedUpdate = false;
  6832. }
  6833. if ( geometry.lineDistancesNeedUpdate ) {
  6834. var attribute = this.attributes.lineDistance;
  6835. if ( attribute !== undefined ) {
  6836. attribute.copyArray( geometry.lineDistances );
  6837. attribute.needsUpdate = true;
  6838. }
  6839. geometry.lineDistancesNeedUpdate = false;
  6840. }
  6841. if ( geometry.groupsNeedUpdate ) {
  6842. geometry.computeGroups( object.geometry );
  6843. this.groups = geometry.groups;
  6844. geometry.groupsNeedUpdate = false;
  6845. }
  6846. return this;
  6847. },
  6848. fromGeometry: function ( geometry ) {
  6849. geometry.__directGeometry = new THREE.DirectGeometry().fromGeometry( geometry );
  6850. return this.fromDirectGeometry( geometry.__directGeometry );
  6851. },
  6852. fromDirectGeometry: function ( geometry ) {
  6853. var positions = new Float32Array( geometry.vertices.length * 3 );
  6854. this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) );
  6855. if ( geometry.normals.length > 0 ) {
  6856. var normals = new Float32Array( geometry.normals.length * 3 );
  6857. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) );
  6858. }
  6859. if ( geometry.colors.length > 0 ) {
  6860. var colors = new Float32Array( geometry.colors.length * 3 );
  6861. this.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors ) );
  6862. }
  6863. if ( geometry.uvs.length > 0 ) {
  6864. var uvs = new Float32Array( geometry.uvs.length * 2 );
  6865. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs ) );
  6866. }
  6867. if ( geometry.uvs2.length > 0 ) {
  6868. var uvs2 = new Float32Array( geometry.uvs2.length * 2 );
  6869. this.addAttribute( 'uv2', new THREE.BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 ) );
  6870. }
  6871. if ( geometry.indices.length > 0 ) {
  6872. var TypeArray = geometry.vertices.length > 65535 ? Uint32Array : Uint16Array;
  6873. var indices = new TypeArray( geometry.indices.length * 3 );
  6874. this.setIndex( new THREE.BufferAttribute( indices, 1 ).copyIndicesArray( geometry.indices ) );
  6875. }
  6876. // groups
  6877. this.groups = geometry.groups;
  6878. // morphs
  6879. for ( var name in geometry.morphTargets ) {
  6880. var array = [];
  6881. var morphTargets = geometry.morphTargets[ name ];
  6882. for ( var i = 0, l = morphTargets.length; i < l; i ++ ) {
  6883. var morphTarget = morphTargets[ i ];
  6884. var attribute = new THREE.Float32Attribute( morphTarget.length * 3, 3 );
  6885. array.push( attribute.copyVector3sArray( morphTarget ) );
  6886. }
  6887. this.morphAttributes[ name ] = array;
  6888. }
  6889. // skinning
  6890. if ( geometry.skinIndices.length > 0 ) {
  6891. var skinIndices = new THREE.Float32Attribute( geometry.skinIndices.length * 4, 4 );
  6892. this.addAttribute( 'skinIndex', skinIndices.copyVector4sArray( geometry.skinIndices ) );
  6893. }
  6894. if ( geometry.skinWeights.length > 0 ) {
  6895. var skinWeights = new THREE.Float32Attribute( geometry.skinWeights.length * 4, 4 );
  6896. this.addAttribute( 'skinWeight', skinWeights.copyVector4sArray( geometry.skinWeights ) );
  6897. }
  6898. //
  6899. if ( geometry.boundingSphere !== null ) {
  6900. this.boundingSphere = geometry.boundingSphere.clone();
  6901. }
  6902. if ( geometry.boundingBox !== null ) {
  6903. this.boundingBox = geometry.boundingBox.clone();
  6904. }
  6905. return this;
  6906. },
  6907. computeBoundingBox: function () {
  6908. var vector = new THREE.Vector3();
  6909. return function () {
  6910. if ( this.boundingBox === null ) {
  6911. this.boundingBox = new THREE.Box3();
  6912. }
  6913. var positions = this.attributes.position.array;
  6914. if ( positions ) {
  6915. this.boundingBox.setFromArray( positions );
  6916. }
  6917. if ( positions === undefined || positions.length === 0 ) {
  6918. this.boundingBox.min.set( 0, 0, 0 );
  6919. this.boundingBox.max.set( 0, 0, 0 );
  6920. }
  6921. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  6922. console.error( 'THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  6923. }
  6924. };
  6925. }(),
  6926. computeBoundingSphere: function () {
  6927. var box = new THREE.Box3();
  6928. var vector = new THREE.Vector3();
  6929. return function () {
  6930. if ( this.boundingSphere === null ) {
  6931. this.boundingSphere = new THREE.Sphere();
  6932. }
  6933. var positions = this.attributes.position.array;
  6934. if ( positions ) {
  6935. var center = this.boundingSphere.center;
  6936. box.setFromArray( positions );
  6937. box.center( center );
  6938. // hoping to find a boundingSphere with a radius smaller than the
  6939. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  6940. var maxRadiusSq = 0;
  6941. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  6942. vector.fromArray( positions, i );
  6943. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
  6944. }
  6945. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  6946. if ( isNaN( this.boundingSphere.radius ) ) {
  6947. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  6948. }
  6949. }
  6950. };
  6951. }(),
  6952. computeFaceNormals: function () {
  6953. // backwards compatibility
  6954. },
  6955. computeVertexNormals: function () {
  6956. var index = this.index;
  6957. var attributes = this.attributes;
  6958. var groups = this.groups;
  6959. if ( attributes.position ) {
  6960. var positions = attributes.position.array;
  6961. if ( attributes.normal === undefined ) {
  6962. this.addAttribute( 'normal', new THREE.BufferAttribute( new Float32Array( positions.length ), 3 ) );
  6963. } else {
  6964. // reset existing normals to zero
  6965. var array = attributes.normal.array;
  6966. for ( var i = 0, il = array.length; i < il; i ++ ) {
  6967. array[ i ] = 0;
  6968. }
  6969. }
  6970. var normals = attributes.normal.array;
  6971. var vA, vB, vC,
  6972. pA = new THREE.Vector3(),
  6973. pB = new THREE.Vector3(),
  6974. pC = new THREE.Vector3(),
  6975. cb = new THREE.Vector3(),
  6976. ab = new THREE.Vector3();
  6977. // indexed elements
  6978. if ( index ) {
  6979. var indices = index.array;
  6980. if ( groups.length === 0 ) {
  6981. this.addGroup( 0, indices.length );
  6982. }
  6983. for ( var j = 0, jl = groups.length; j < jl; ++ j ) {
  6984. var group = groups[ j ];
  6985. var start = group.start;
  6986. var count = group.count;
  6987. for ( var i = start, il = start + count; i < il; i += 3 ) {
  6988. vA = indices[ i + 0 ] * 3;
  6989. vB = indices[ i + 1 ] * 3;
  6990. vC = indices[ i + 2 ] * 3;
  6991. pA.fromArray( positions, vA );
  6992. pB.fromArray( positions, vB );
  6993. pC.fromArray( positions, vC );
  6994. cb.subVectors( pC, pB );
  6995. ab.subVectors( pA, pB );
  6996. cb.cross( ab );
  6997. normals[ vA ] += cb.x;
  6998. normals[ vA + 1 ] += cb.y;
  6999. normals[ vA + 2 ] += cb.z;
  7000. normals[ vB ] += cb.x;
  7001. normals[ vB + 1 ] += cb.y;
  7002. normals[ vB + 2 ] += cb.z;
  7003. normals[ vC ] += cb.x;
  7004. normals[ vC + 1 ] += cb.y;
  7005. normals[ vC + 2 ] += cb.z;
  7006. }
  7007. }
  7008. } else {
  7009. // non-indexed elements (unconnected triangle soup)
  7010. for ( var i = 0, il = positions.length; i < il; i += 9 ) {
  7011. pA.fromArray( positions, i );
  7012. pB.fromArray( positions, i + 3 );
  7013. pC.fromArray( positions, i + 6 );
  7014. cb.subVectors( pC, pB );
  7015. ab.subVectors( pA, pB );
  7016. cb.cross( ab );
  7017. normals[ i ] = cb.x;
  7018. normals[ i + 1 ] = cb.y;
  7019. normals[ i + 2 ] = cb.z;
  7020. normals[ i + 3 ] = cb.x;
  7021. normals[ i + 4 ] = cb.y;
  7022. normals[ i + 5 ] = cb.z;
  7023. normals[ i + 6 ] = cb.x;
  7024. normals[ i + 7 ] = cb.y;
  7025. normals[ i + 8 ] = cb.z;
  7026. }
  7027. }
  7028. this.normalizeNormals();
  7029. attributes.normal.needsUpdate = true;
  7030. }
  7031. },
  7032. merge: function ( geometry, offset ) {
  7033. if ( geometry instanceof THREE.BufferGeometry === false ) {
  7034. console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
  7035. return;
  7036. }
  7037. if ( offset === undefined ) offset = 0;
  7038. var attributes = this.attributes;
  7039. for ( var key in attributes ) {
  7040. if ( geometry.attributes[ key ] === undefined ) continue;
  7041. var attribute1 = attributes[ key ];
  7042. var attributeArray1 = attribute1.array;
  7043. var attribute2 = geometry.attributes[ key ];
  7044. var attributeArray2 = attribute2.array;
  7045. var attributeSize = attribute2.itemSize;
  7046. for ( var i = 0, j = attributeSize * offset; i < attributeArray2.length; i ++, j ++ ) {
  7047. attributeArray1[ j ] = attributeArray2[ i ];
  7048. }
  7049. }
  7050. return this;
  7051. },
  7052. normalizeNormals: function () {
  7053. var normals = this.attributes.normal.array;
  7054. var x, y, z, n;
  7055. for ( var i = 0, il = normals.length; i < il; i += 3 ) {
  7056. x = normals[ i ];
  7057. y = normals[ i + 1 ];
  7058. z = normals[ i + 2 ];
  7059. n = 1.0 / Math.sqrt( x * x + y * y + z * z );
  7060. normals[ i ] *= n;
  7061. normals[ i + 1 ] *= n;
  7062. normals[ i + 2 ] *= n;
  7063. }
  7064. },
  7065. toNonIndexed: function () {
  7066. if ( this.index === null ) {
  7067. console.warn( 'THREE.BufferGeometry.toNonIndexed(): Geometry is already non-indexed.' );
  7068. return this;
  7069. }
  7070. var geometry2 = new THREE.BufferGeometry();
  7071. var indices = this.index.array;
  7072. var attributes = this.attributes;
  7073. for ( var name in attributes ) {
  7074. var attribute = attributes[ name ];
  7075. var array = attribute.array;
  7076. var itemSize = attribute.itemSize;
  7077. var array2 = new array.constructor( indices.length * itemSize );
  7078. var index = 0, index2 = 0;
  7079. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  7080. index = indices[ i ] * itemSize;
  7081. for ( var j = 0; j < itemSize; j ++ ) {
  7082. array2[ index2 ++ ] = array[ index ++ ];
  7083. }
  7084. }
  7085. geometry2.addAttribute( name, new THREE.BufferAttribute( array2, itemSize ) );
  7086. }
  7087. return geometry2;
  7088. },
  7089. toJSON: function () {
  7090. var data = {
  7091. metadata: {
  7092. version: 4.4,
  7093. type: 'BufferGeometry',
  7094. generator: 'BufferGeometry.toJSON'
  7095. }
  7096. };
  7097. // standard BufferGeometry serialization
  7098. data.uuid = this.uuid;
  7099. data.type = this.type;
  7100. if ( this.name !== '' ) data.name = this.name;
  7101. if ( this.parameters !== undefined ) {
  7102. var parameters = this.parameters;
  7103. for ( var key in parameters ) {
  7104. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  7105. }
  7106. return data;
  7107. }
  7108. data.data = { attributes: {} };
  7109. var index = this.index;
  7110. if ( index !== null ) {
  7111. var array = Array.prototype.slice.call( index.array );
  7112. data.data.index = {
  7113. type: index.array.constructor.name,
  7114. array: array
  7115. };
  7116. }
  7117. var attributes = this.attributes;
  7118. for ( var key in attributes ) {
  7119. var attribute = attributes[ key ];
  7120. var array = Array.prototype.slice.call( attribute.array );
  7121. data.data.attributes[ key ] = {
  7122. itemSize: attribute.itemSize,
  7123. type: attribute.array.constructor.name,
  7124. array: array
  7125. };
  7126. }
  7127. var groups = this.groups;
  7128. if ( groups.length > 0 ) {
  7129. data.data.groups = JSON.parse( JSON.stringify( groups ) );
  7130. }
  7131. var boundingSphere = this.boundingSphere;
  7132. if ( boundingSphere !== null ) {
  7133. data.data.boundingSphere = {
  7134. center: boundingSphere.center.toArray(),
  7135. radius: boundingSphere.radius
  7136. };
  7137. }
  7138. return data;
  7139. },
  7140. clone: function () {
  7141. /*
  7142. // Handle primitives
  7143. var parameters = this.parameters;
  7144. if ( parameters !== undefined ) {
  7145. var values = [];
  7146. for ( var key in parameters ) {
  7147. values.push( parameters[ key ] );
  7148. }
  7149. var geometry = Object.create( this.constructor.prototype );
  7150. this.constructor.apply( geometry, values );
  7151. return geometry;
  7152. }
  7153. return new this.constructor().copy( this );
  7154. */
  7155. return new THREE.BufferGeometry().copy( this );
  7156. },
  7157. copy: function ( source ) {
  7158. var index = source.index;
  7159. if ( index !== null ) {
  7160. this.setIndex( index.clone() );
  7161. }
  7162. var attributes = source.attributes;
  7163. for ( var name in attributes ) {
  7164. var attribute = attributes[ name ];
  7165. this.addAttribute( name, attribute.clone() );
  7166. }
  7167. var groups = source.groups;
  7168. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  7169. var group = groups[ i ];
  7170. this.addGroup( group.start, group.count );
  7171. }
  7172. return this;
  7173. },
  7174. dispose: function () {
  7175. this.dispatchEvent( { type: 'dispose' } );
  7176. }
  7177. };
  7178. THREE.EventDispatcher.prototype.apply( THREE.BufferGeometry.prototype );
  7179. THREE.BufferGeometry.MaxIndex = 65535;
  7180. // File:src/core/InstancedBufferGeometry.js
  7181. /**
  7182. * @author benaadams / https://twitter.com/ben_a_adams
  7183. */
  7184. THREE.InstancedBufferGeometry = function () {
  7185. THREE.BufferGeometry.call( this );
  7186. this.type = 'InstancedBufferGeometry';
  7187. this.maxInstancedCount = undefined;
  7188. };
  7189. THREE.InstancedBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  7190. THREE.InstancedBufferGeometry.prototype.constructor = THREE.InstancedBufferGeometry;
  7191. THREE.InstancedBufferGeometry.prototype.addGroup = function ( start, count, instances ) {
  7192. this.groups.push( {
  7193. start: start,
  7194. count: count,
  7195. instances: instances
  7196. } );
  7197. };
  7198. THREE.InstancedBufferGeometry.prototype.copy = function ( source ) {
  7199. var index = source.index;
  7200. if ( index !== null ) {
  7201. this.setIndex( index.clone() );
  7202. }
  7203. var attributes = source.attributes;
  7204. for ( var name in attributes ) {
  7205. var attribute = attributes[ name ];
  7206. this.addAttribute( name, attribute.clone() );
  7207. }
  7208. var groups = source.groups;
  7209. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  7210. var group = groups[ i ];
  7211. this.addGroup( group.start, group.count, group.instances );
  7212. }
  7213. return this;
  7214. };
  7215. THREE.EventDispatcher.prototype.apply( THREE.InstancedBufferGeometry.prototype );
  7216. // File:src/core/Uniform.js
  7217. /**
  7218. * @author mrdoob / http://mrdoob.com/
  7219. */
  7220. THREE.Uniform = function ( type, value ) {
  7221. this.type = type;
  7222. this.value = value;
  7223. this.dynamic = false;
  7224. };
  7225. THREE.Uniform.prototype = {
  7226. constructor: THREE.Uniform,
  7227. onUpdate: function ( callback ) {
  7228. this.dynamic = true;
  7229. this.onUpdateCallback = callback;
  7230. return this;
  7231. }
  7232. };
  7233. // File:src/animation/AnimationClip.js
  7234. /**
  7235. *
  7236. * Reusable set of Tracks that represent an animation.
  7237. *
  7238. * @author Ben Houston / http://clara.io/
  7239. * @author David Sarno / http://lighthaus.us/
  7240. */
  7241. THREE.AnimationClip = function ( name, duration, tracks ) {
  7242. this.name = name || THREE.Math.generateUUID();
  7243. this.tracks = tracks;
  7244. this.duration = ( duration !== undefined ) ? duration : -1;
  7245. // this means it should figure out its duration by scanning the tracks
  7246. if ( this.duration < 0 ) {
  7247. this.resetDuration();
  7248. }
  7249. // maybe only do these on demand, as doing them here could potentially slow down loading
  7250. // but leaving these here during development as this ensures a lot of testing of these functions
  7251. this.trim();
  7252. this.optimize();
  7253. };
  7254. THREE.AnimationClip.prototype = {
  7255. constructor: THREE.AnimationClip,
  7256. resetDuration: function() {
  7257. var tracks = this.tracks,
  7258. duration = 0;
  7259. for ( var i = 0, n = tracks.length; i !== n; ++ i ) {
  7260. var track = this.tracks[ i ];
  7261. duration = Math.max(
  7262. duration, track.times[ track.times.length - 1 ] );
  7263. }
  7264. this.duration = duration;
  7265. },
  7266. trim: function() {
  7267. for ( var i = 0; i < this.tracks.length; i ++ ) {
  7268. this.tracks[ i ].trim( 0, this.duration );
  7269. }
  7270. return this;
  7271. },
  7272. optimize: function() {
  7273. for ( var i = 0; i < this.tracks.length; i ++ ) {
  7274. this.tracks[ i ].optimize();
  7275. }
  7276. return this;
  7277. }
  7278. };
  7279. // Static methods:
  7280. Object.assign( THREE.AnimationClip, {
  7281. parse: function( json ) {
  7282. var tracks = [],
  7283. jsonTracks = json.tracks,
  7284. frameTime = 1.0 / ( json.fps || 1.0 );
  7285. for ( var i = 0, n = jsonTracks.length; i !== n; ++ i ) {
  7286. tracks.push( THREE.KeyframeTrack.parse( jsonTracks[ i ] ).scale( frameTime ) );
  7287. }
  7288. return new THREE.AnimationClip( json.name, json.duration, tracks );
  7289. },
  7290. toJSON: function( clip ) {
  7291. var tracks = [],
  7292. clipTracks = clip.tracks;
  7293. var json = {
  7294. 'name': clip.name,
  7295. 'duration': clip.duration,
  7296. 'tracks': tracks
  7297. };
  7298. for ( var i = 0, n = clipTracks.length; i !== n; ++ i ) {
  7299. tracks.push( THREE.KeyframeTrack.toJSON( clipTracks[ i ] ) );
  7300. }
  7301. return json;
  7302. },
  7303. CreateFromMorphTargetSequence: function( name, morphTargetSequence, fps ) {
  7304. var numMorphTargets = morphTargetSequence.length;
  7305. var tracks = [];
  7306. for ( var i = 0; i < numMorphTargets; i ++ ) {
  7307. var times = [];
  7308. var values = [];
  7309. times.push(
  7310. ( i + numMorphTargets - 1 ) % numMorphTargets,
  7311. i,
  7312. ( i + 1 ) % numMorphTargets );
  7313. values.push( 0, 1, 0 );
  7314. var order = THREE.AnimationUtils.getKeyframeOrder( times );
  7315. times = THREE.AnimationUtils.sortedArray( times, 1, order );
  7316. values = THREE.AnimationUtils.sortedArray( values, 1, order );
  7317. // if there is a key at the first frame, duplicate it as the
  7318. // last frame as well for perfect loop.
  7319. if ( times[ 0 ] === 0 ) {
  7320. times.push( numMorphTargets );
  7321. values.push( values[ 0 ] );
  7322. }
  7323. tracks.push(
  7324. new THREE.NumberKeyframeTrack(
  7325. '.morphTargetInfluences[' + morphTargetSequence[ i ].name + ']',
  7326. times, values
  7327. ).scale( 1.0 / fps ) );
  7328. }
  7329. return new THREE.AnimationClip( name, -1, tracks );
  7330. },
  7331. findByName: function( clipArray, name ) {
  7332. for ( var i = 0; i < clipArray.length; i ++ ) {
  7333. if ( clipArray[ i ].name === name ) {
  7334. return clipArray[ i ];
  7335. }
  7336. }
  7337. return null;
  7338. },
  7339. CreateClipsFromMorphTargetSequences: function( morphTargets, fps ) {
  7340. var animationToMorphTargets = {};
  7341. // tested with https://regex101.com/ on trick sequences
  7342. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  7343. var pattern = /^([\w-]*?)([\d]+)$/;
  7344. // sort morph target names into animation groups based
  7345. // patterns like Walk_001, Walk_002, Run_001, Run_002
  7346. for ( var i = 0, il = morphTargets.length; i < il; i ++ ) {
  7347. var morphTarget = morphTargets[ i ];
  7348. var parts = morphTarget.name.match( pattern );
  7349. if ( parts && parts.length > 1 ) {
  7350. var name = parts[ 1 ];
  7351. var animationMorphTargets = animationToMorphTargets[ name ];
  7352. if ( ! animationMorphTargets ) {
  7353. animationToMorphTargets[ name ] = animationMorphTargets = [];
  7354. }
  7355. animationMorphTargets.push( morphTarget );
  7356. }
  7357. }
  7358. var clips = [];
  7359. for ( var name in animationToMorphTargets ) {
  7360. clips.push( THREE.AnimationClip.CreateFromMorphTargetSequence( name, animationToMorphTargets[ name ], fps ) );
  7361. }
  7362. return clips;
  7363. },
  7364. // parse the animation.hierarchy format
  7365. parseAnimation: function( animation, bones, nodeName ) {
  7366. if ( ! animation ) {
  7367. console.error( " no animation in JSONLoader data" );
  7368. return null;
  7369. }
  7370. var addNonemptyTrack = function(
  7371. trackType, trackName, animationKeys, propertyName, destTracks ) {
  7372. // only return track if there are actually keys.
  7373. if ( animationKeys.length !== 0 ) {
  7374. var times = [];
  7375. var values = [];
  7376. THREE.AnimationUtils.flattenJSON(
  7377. animationKeys, times, values, propertyName );
  7378. // empty keys are filtered out, so check again
  7379. if ( times.length !== 0 ) {
  7380. destTracks.push( new trackType( trackName, times, values ) );
  7381. }
  7382. }
  7383. };
  7384. var tracks = [];
  7385. var clipName = animation.name || 'default';
  7386. // automatic length determination in AnimationClip.
  7387. var duration = animation.length || -1;
  7388. var fps = animation.fps || 30;
  7389. var hierarchyTracks = animation.hierarchy || [];
  7390. for ( var h = 0; h < hierarchyTracks.length; h ++ ) {
  7391. var animationKeys = hierarchyTracks[ h ].keys;
  7392. // skip empty tracks
  7393. if ( ! animationKeys || animationKeys.length == 0 ) continue;
  7394. // process morph targets in a way exactly compatible
  7395. // with AnimationHandler.init( animation )
  7396. if ( animationKeys[0].morphTargets ) {
  7397. // figure out all morph targets used in this track
  7398. var morphTargetNames = {};
  7399. for ( var k = 0; k < animationKeys.length; k ++ ) {
  7400. if ( animationKeys[k].morphTargets ) {
  7401. for ( var m = 0; m < animationKeys[k].morphTargets.length; m ++ ) {
  7402. morphTargetNames[ animationKeys[k].morphTargets[m] ] = -1;
  7403. }
  7404. }
  7405. }
  7406. // create a track for each morph target with all zero
  7407. // morphTargetInfluences except for the keys in which
  7408. // the morphTarget is named.
  7409. for ( var morphTargetName in morphTargetNames ) {
  7410. var times = [];
  7411. var values = [];
  7412. for ( var m = 0;
  7413. m !== animationKeys[k].morphTargets.length; ++ m ) {
  7414. var animationKey = animationKeys[k];
  7415. times.push( animationKey.time );
  7416. values.push( ( animationKey.morphTarget === morphTargetName ) ? 1 : 0 )
  7417. }
  7418. tracks.push( new THREE.NumberKeyframeTrack(
  7419. '.morphTargetInfluence[' + morphTargetName + ']', times, values ) );
  7420. }
  7421. duration = morphTargetNames.length * ( fps || 1.0 );
  7422. } else {
  7423. // ...assume skeletal animation
  7424. var boneName = '.bones[' + bones[ h ].name + ']';
  7425. addNonemptyTrack(
  7426. THREE.VectorKeyframeTrack, boneName + '.position',
  7427. animationKeys, 'pos', tracks );
  7428. addNonemptyTrack(
  7429. THREE.QuaternionKeyframeTrack, boneName + '.quaternion',
  7430. animationKeys, 'rot', tracks );
  7431. addNonemptyTrack(
  7432. THREE.VectorKeyframeTrack, boneName + '.scale',
  7433. animationKeys, 'scl', tracks );
  7434. }
  7435. }
  7436. if ( tracks.length === 0 ) {
  7437. return null;
  7438. }
  7439. var clip = new THREE.AnimationClip( clipName, duration, tracks );
  7440. return clip;
  7441. }
  7442. } );
  7443. // File:src/animation/AnimationMixer.js
  7444. /**
  7445. *
  7446. * Player for AnimationClips.
  7447. *
  7448. *
  7449. * @author Ben Houston / http://clara.io/
  7450. * @author David Sarno / http://lighthaus.us/
  7451. * @author tschw
  7452. */
  7453. THREE.AnimationMixer = function( root ) {
  7454. this._root = root;
  7455. this._initMemoryManager();
  7456. this._accuIndex = 0;
  7457. this.time = 0;
  7458. this.timeScale = 1.0;
  7459. };
  7460. THREE.AnimationMixer.prototype = {
  7461. constructor: THREE.AnimationMixer,
  7462. // return an action for a clip optionally using a custom root target
  7463. // object (this method allocates a lot of dynamic memory in case a
  7464. // previously unknown clip/root combination is specified)
  7465. clipAction: function( clip, optionalRoot ) {
  7466. var root = optionalRoot || this._root,
  7467. rootUuid = root.uuid,
  7468. clipName = ( typeof clip === 'string' ) ? clip : clip.name,
  7469. clipObject = ( clip !== clipName ) ? clip : null,
  7470. actionsForClip = this._actionsByClip[ clipName ],
  7471. prototypeAction;
  7472. if ( actionsForClip !== undefined ) {
  7473. var existingAction =
  7474. actionsForClip.actionByRoot[ rootUuid ];
  7475. if ( existingAction !== undefined ) {
  7476. return existingAction;
  7477. }
  7478. // we know the clip, so we don't have to parse all
  7479. // the bindings again but can just copy
  7480. prototypeAction = actionsForClip.knownActions[ 0 ];
  7481. // also, take the clip from the prototype action
  7482. clipObject = prototypeAction._clip;
  7483. if ( clip !== clipName && clip !== clipObject ) {
  7484. throw new Error(
  7485. "Different clips with the same name detected!" );
  7486. }
  7487. }
  7488. // clip must be known when specified via string
  7489. if ( clipObject === null ) return null;
  7490. // allocate all resources required to run it
  7491. var newAction = new THREE.
  7492. AnimationMixer._Action( this, clipObject, optionalRoot );
  7493. this._bindAction( newAction, prototypeAction );
  7494. // and make the action known to the memory manager
  7495. this._addInactiveAction( newAction, clipName, rootUuid );
  7496. return newAction;
  7497. },
  7498. // get an existing action
  7499. existingAction: function( clip, optionalRoot ) {
  7500. var root = optionalRoot || this._root,
  7501. rootUuid = root.uuid,
  7502. clipName = ( typeof clip === 'string' ) ? clip : clip.name,
  7503. actionsForClip = this._actionsByClip[ clipName ];
  7504. if ( actionsForClip !== undefined ) {
  7505. return actionsForClip.actionByRoot[ rootUuid ] || null;
  7506. }
  7507. return null;
  7508. },
  7509. // deactivates all previously scheduled actions
  7510. stopAllAction: function() {
  7511. var actions = this._actions,
  7512. nActions = this._nActiveActions,
  7513. bindings = this._bindings,
  7514. nBindings = this._nActiveBindings;
  7515. this._nActiveActions = 0;
  7516. this._nActiveBindings = 0;
  7517. for ( var i = 0; i !== nActions; ++ i ) {
  7518. actions[ i ].reset();
  7519. }
  7520. for ( var i = 0; i !== nBindings; ++ i ) {
  7521. bindings[ i ].useCount = 0;
  7522. }
  7523. return this;
  7524. },
  7525. // advance the time and update apply the animation
  7526. update: function( deltaTime ) {
  7527. deltaTime *= this.timeScale;
  7528. var actions = this._actions,
  7529. nActions = this._nActiveActions,
  7530. time = this.time += deltaTime,
  7531. timeDirection = Math.sign( deltaTime ),
  7532. accuIndex = this._accuIndex ^= 1;
  7533. // run active actions
  7534. for ( var i = 0; i !== nActions; ++ i ) {
  7535. var action = actions[ i ];
  7536. if ( action.enabled ) {
  7537. action._update( time, deltaTime, timeDirection, accuIndex );
  7538. }
  7539. }
  7540. // update scene graph
  7541. var bindings = this._bindings,
  7542. nBindings = this._nActiveBindings;
  7543. for ( var i = 0; i !== nBindings; ++ i ) {
  7544. bindings[ i ].apply( accuIndex );
  7545. }
  7546. return this;
  7547. },
  7548. // return this mixer's root target object
  7549. getRoot: function() {
  7550. return this._root;
  7551. },
  7552. // free all resources specific to a particular clip
  7553. uncacheClip: function( clip ) {
  7554. var actions = this._actions,
  7555. clipName = clip.name,
  7556. actionsByClip = this._actionsByClip,
  7557. actionsForClip = actionsByClip[ clipName ];
  7558. if ( actionsForClip !== undefined ) {
  7559. // note: just calling _removeInactiveAction would mess up the
  7560. // iteration state and also require updating the state we can
  7561. // just throw away
  7562. var actionsToRemove = actionsForClip.knownActions;
  7563. for ( var i = 0, n = actionsToRemove.length; i !== n; ++ i ) {
  7564. var action = actionsToRemove[ i ];
  7565. this._deactivateAction( action );
  7566. var cacheIndex = action._cacheIndex,
  7567. lastInactiveAction = actions[ actions.length - 1 ];
  7568. action._cacheIndex = null;
  7569. action._byClipCacheIndex = null;
  7570. lastInactiveAction._cacheIndex = cacheIndex;
  7571. actions[ cacheIndex ] = lastInactiveAction;
  7572. actions.pop();
  7573. this._removeInactiveBindingsForAction( action );
  7574. }
  7575. delete actionsByClip[ clipName ];
  7576. }
  7577. },
  7578. // free all resources specific to a particular root target object
  7579. uncacheRoot: function( root ) {
  7580. var rootUuid = root.uuid,
  7581. actionsByClip = this._actionsByClip;
  7582. for ( var clipName in actionsByClip ) {
  7583. var actionByRoot = actionsByClip[ clipName ].actionByRoot,
  7584. action = actionByRoot[ rootUuid ];
  7585. if ( action !== undefined ) {
  7586. this._deactivateAction( action );
  7587. this._removeInactiveAction( action );
  7588. }
  7589. }
  7590. var bindingsByRoot = this._bindingsByRootAndName,
  7591. bindingByName = bindingsByRoot[ rootUuid ];
  7592. if ( bindingByName !== undefined ) {
  7593. for ( var trackName in bindingByName ) {
  7594. var binding = bindingByName[ trackName ];
  7595. binding.restoreOriginalState();
  7596. this._removeInactiveBinding( binding );
  7597. }
  7598. }
  7599. },
  7600. // remove a targeted clip from the cache
  7601. uncacheAction: function( clip, optionalRoot ) {
  7602. var action = this.existingAction( clip, optionalRoot );
  7603. if ( action !== null ) {
  7604. this._deactivateAction( action );
  7605. this._removeInactiveAction( action );
  7606. }
  7607. }
  7608. };
  7609. THREE.EventDispatcher.prototype.apply( THREE.AnimationMixer.prototype );
  7610. THREE.AnimationMixer._Action =
  7611. function( mixer, clip, localRoot ) {
  7612. this._mixer = mixer;
  7613. this._clip = clip;
  7614. this._localRoot = localRoot || null;
  7615. var tracks = clip.tracks,
  7616. nTracks = tracks.length,
  7617. interpolants = new Array( nTracks );
  7618. var interpolantSettings = {
  7619. endingStart: THREE.ZeroCurvatureEnding,
  7620. endingEnd: THREE.ZeroCurvatureEnding
  7621. };
  7622. for ( var i = 0; i !== nTracks; ++ i ) {
  7623. var interpolant = tracks[ i ].createInterpolant( null );
  7624. interpolants[ i ] = interpolant;
  7625. interpolant.settings = interpolantSettings
  7626. }
  7627. this._interpolantSettings = interpolantSettings;
  7628. this._interpolants = interpolants; // bound by the mixer
  7629. // inside: PropertyMixer (managed by the mixer)
  7630. this._propertyBindings = new Array( nTracks );
  7631. this._cacheIndex = null; // for the memory manager
  7632. this._byClipCacheIndex = null; // for the memory manager
  7633. this._timeScaleInterpolant = null;
  7634. this._weightInterpolant = null;
  7635. this.loop = THREE.LoopRepeat;
  7636. this._loopCount = -1;
  7637. // global mixer time when the action is to be started
  7638. // it's set back to 'null' upon start of the action
  7639. this._startTime = null;
  7640. // scaled local time of the action
  7641. // gets clamped or wrapped to 0..clip.duration according to loop
  7642. this.time = 0;
  7643. this.timeScale = 1;
  7644. this._effectiveTimeScale = 1;
  7645. this.weight = 1;
  7646. this._effectiveWeight = 1;
  7647. this.repetitions = Infinity; // no. of repetitions when looping
  7648. this.paused = false; // false -> zero effective time scale
  7649. this.enabled = true; // true -> zero effective weight
  7650. this.clampWhenFinished = false; // keep feeding the last frame?
  7651. this.zeroSlopeAtStart = true; // for smooth interpolation w/o separate
  7652. this.zeroSlopeAtEnd = true; // clips for start, loop and end
  7653. };
  7654. THREE.AnimationMixer._Action.prototype = {
  7655. constructor: THREE.AnimationMixer._Action,
  7656. // State & Scheduling
  7657. play: function() {
  7658. this._mixer._activateAction( this );
  7659. return this;
  7660. },
  7661. stop: function() {
  7662. this._mixer._deactivateAction( this );
  7663. return this.reset();
  7664. },
  7665. reset: function() {
  7666. this.paused = false;
  7667. this.enabled = true;
  7668. this.time = 0; // restart clip
  7669. this._loopCount = -1; // forget previous loops
  7670. this._startTime = null; // forget scheduling
  7671. return this.stopFading().stopWarping();
  7672. },
  7673. isRunning: function() {
  7674. var start = this._startTime;
  7675. return this.enabled && ! this.paused && this.timeScale !== 0 &&
  7676. this._startTime === null && this._mixer._isActiveAction( this )
  7677. },
  7678. // return true when play has been called
  7679. isScheduled: function() {
  7680. return this._mixer._isActiveAction( this );
  7681. },
  7682. startAt: function( time ) {
  7683. this._startTime = time;
  7684. return this;
  7685. },
  7686. setLoop: function( mode, repetitions ) {
  7687. this.loop = mode;
  7688. this.repetitions = repetitions;
  7689. return this;
  7690. },
  7691. // Weight
  7692. // set the weight stopping any scheduled fading
  7693. // although .enabled = false yields an effective weight of zero, this
  7694. // method does *not* change .enabled, because it would be confusing
  7695. setEffectiveWeight: function( weight ) {
  7696. this.weight = weight;
  7697. // note: same logic as when updated at runtime
  7698. this._effectiveWeight = this.enabled ? weight : 0;
  7699. return this.stopFading();
  7700. },
  7701. // return the weight considering fading and .enabled
  7702. getEffectiveWeight: function() {
  7703. return this._effectiveWeight;
  7704. },
  7705. fadeIn: function( duration ) {
  7706. return this._scheduleFading( duration, 0, 1 );
  7707. },
  7708. fadeOut: function( duration ) {
  7709. return this._scheduleFading( duration, 1, 0 );
  7710. },
  7711. crossFadeFrom: function( fadeOutAction, duration, warp ) {
  7712. var mixer = this._mixer;
  7713. fadeOutAction.fadeOut( duration );
  7714. this.fadeIn( duration );
  7715. if( warp ) {
  7716. var fadeInDuration = this._clip.duration,
  7717. fadeOutDuration = fadeOutAction._clip.duration,
  7718. startEndRatio = fadeOutDuration / fadeInDuration,
  7719. endStartRatio = fadeInDuration / fadeOutDuration;
  7720. fadeOutAction.warp( 1.0, startEndRatio, duration );
  7721. this.warp( endStartRatio, 1.0, duration );
  7722. }
  7723. return this;
  7724. },
  7725. crossFadeTo: function( fadeInAction, duration, warp ) {
  7726. return fadeInAction.crossFadeFrom( this, duration, warp );
  7727. },
  7728. stopFading: function() {
  7729. var weightInterpolant = this._weightInterpolant;
  7730. if ( weightInterpolant !== null ) {
  7731. this._weightInterpolant = null;
  7732. this._mixer._takeBackControlInterpolant( weightInterpolant );
  7733. }
  7734. return this;
  7735. },
  7736. // Time Scale Control
  7737. // set the weight stopping any scheduled warping
  7738. // although .paused = true yields an effective time scale of zero, this
  7739. // method does *not* change .paused, because it would be confusing
  7740. setEffectiveTimeScale: function( timeScale ) {
  7741. this.timeScale = timeScale;
  7742. this._effectiveTimeScale = this.paused ? 0 :timeScale;
  7743. return this.stopWarping();
  7744. },
  7745. // return the time scale considering warping and .paused
  7746. getEffectiveTimeScale: function() {
  7747. return this._effectiveTimeScale;
  7748. },
  7749. setDuration: function( duration ) {
  7750. this.timeScale = this._clip.duration / duration;
  7751. return this.stopWarping();
  7752. },
  7753. syncWith: function( action ) {
  7754. this.time = action.time;
  7755. this.timeScale = action.timeScale;
  7756. return this.stopWarping();
  7757. },
  7758. halt: function( duration ) {
  7759. return this.warp( this._currentTimeScale, 0, duration );
  7760. },
  7761. warp: function( startTimeScale, endTimeScale, duration ) {
  7762. var mixer = this._mixer, now = mixer.time,
  7763. interpolant = this._timeScaleInterpolant,
  7764. timeScale = this.timeScale;
  7765. if ( interpolant === null ) {
  7766. interpolant = mixer._lendControlInterpolant(),
  7767. this._timeScaleInterpolant = interpolant;
  7768. }
  7769. var times = interpolant.parameterPositions,
  7770. values = interpolant.sampleValues;
  7771. times[ 0 ] = now;
  7772. times[ 1 ] = now + duration;
  7773. values[ 0 ] = startTimeScale / timeScale;
  7774. values[ 1 ] = endTimeScale / timeScale;
  7775. return this;
  7776. },
  7777. stopWarping: function() {
  7778. var timeScaleInterpolant = this._timeScaleInterpolant;
  7779. if ( timeScaleInterpolant !== null ) {
  7780. this._timeScaleInterpolant = null;
  7781. this._mixer._takeBackControlInterpolant( timeScaleInterpolant );
  7782. }
  7783. return this;
  7784. },
  7785. // Object Accessors
  7786. getMixer: function() {
  7787. return this._mixer;
  7788. },
  7789. getClip: function() {
  7790. return this._clip;
  7791. },
  7792. getRoot: function() {
  7793. return this._localRoot || this._mixer._root;
  7794. },
  7795. // Interna
  7796. _update: function( time, deltaTime, timeDirection, accuIndex ) {
  7797. // called by the mixer
  7798. var startTime = this._startTime;
  7799. if ( startTime !== null ) {
  7800. // check for scheduled start of action
  7801. var timeRunning = ( time - startTime ) * timeDirection;
  7802. if ( timeRunning < 0 || timeDirection === 0 ) {
  7803. return; // yet to come / don't decide when delta = 0
  7804. }
  7805. // start
  7806. this._startTime = null; // unschedule
  7807. deltaTime = timeDirection * timeRunning;
  7808. }
  7809. // apply time scale and advance time
  7810. deltaTime *= this._updateTimeScale( time );
  7811. var clipTime = this._updateTime( deltaTime );
  7812. // note: _updateTime may disable the action resulting in
  7813. // an effective weight of 0
  7814. var weight = this._updateWeight( time );
  7815. if ( weight > 0 ) {
  7816. var interpolants = this._interpolants;
  7817. var propertyMixers = this._propertyBindings;
  7818. for ( var j = 0, m = interpolants.length; j !== m; ++ j ) {
  7819. interpolants[ j ].evaluate( clipTime );
  7820. propertyMixers[ j ].accumulate( accuIndex, weight );
  7821. }
  7822. }
  7823. },
  7824. _updateWeight: function( time ) {
  7825. var weight = 0;
  7826. if ( this.enabled ) {
  7827. weight = this.weight;
  7828. var interpolant = this._weightInterpolant;
  7829. if ( interpolant !== null ) {
  7830. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  7831. weight *= interpolantValue;
  7832. if ( time > interpolant.parameterPositions[ 1 ] ) {
  7833. this.stopFading();
  7834. if ( interpolantValue === 0 ) {
  7835. // faded out, disable
  7836. this.enabled = false;
  7837. }
  7838. }
  7839. }
  7840. }
  7841. this._effectiveWeight = weight;
  7842. return weight;
  7843. },
  7844. _updateTimeScale: function( time ) {
  7845. var timeScale = 0;
  7846. if ( ! this.paused ) {
  7847. timeScale = this.timeScale;
  7848. var interpolant = this._timeScaleInterpolant;
  7849. if ( interpolant !== null ) {
  7850. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  7851. timeScale *= interpolantValue;
  7852. if ( time > interpolant.parameterPositions[ 1 ] ) {
  7853. this.stopWarping();
  7854. if ( timeScale === 0 ) {
  7855. // motion has halted, pause
  7856. this.pause = true;
  7857. } else {
  7858. // warp done - apply final time scale
  7859. this.timeScale = timeScale;
  7860. }
  7861. }
  7862. }
  7863. }
  7864. this._effectiveTimeScale = timeScale;
  7865. return timeScale;
  7866. },
  7867. _updateTime: function( deltaTime ) {
  7868. var time = this.time + deltaTime;
  7869. if ( deltaTime === 0 ) return time;
  7870. var duration = this._clip.duration,
  7871. loop = this.loop,
  7872. loopCount = this._loopCount,
  7873. pingPong = false;
  7874. switch ( loop ) {
  7875. case THREE.LoopOnce:
  7876. if ( loopCount === -1 ) {
  7877. // just started
  7878. this.loopCount = 0;
  7879. this._setEndings( true, true, false );
  7880. }
  7881. if ( time >= duration ) {
  7882. time = duration;
  7883. } else if ( time < 0 ) {
  7884. time = 0;
  7885. } else break;
  7886. // reached the end
  7887. if ( this.clampWhenFinished ) this.pause = true;
  7888. else this.enabled = false;
  7889. this._mixer.dispatchEvent( {
  7890. type: 'finished', action: this,
  7891. direction: deltaTime < 0 ? -1 : 1
  7892. } );
  7893. break;
  7894. case THREE.LoopPingPong:
  7895. pingPong = true;
  7896. case THREE.LoopRepeat:
  7897. if ( loopCount === -1 ) {
  7898. // just started
  7899. if ( deltaTime > 0 ) {
  7900. loopCount = 0;
  7901. this._setEndings(
  7902. true, this.repetitions === 0, pingPong );
  7903. } else {
  7904. // when looping in reverse direction, the initial
  7905. // transition through zero counts as a repetition,
  7906. // so leave loopCount at -1
  7907. this._setEndings(
  7908. this.repetitions === 0, true, pingPong );
  7909. }
  7910. }
  7911. if ( time >= duration || time < 0 ) {
  7912. // wrap around
  7913. var loopDelta = Math.floor( time / duration ); // signed
  7914. time -= duration * loopDelta;
  7915. loopCount += Math.abs( loopDelta );
  7916. var pending = this.repetitions - loopCount;
  7917. if ( pending < 0 ) {
  7918. // stop (switch state, clamp time, fire event)
  7919. if ( this.clampWhenFinished ) this.paused = true;
  7920. else this.enabled = false;
  7921. time = deltaTime > 0 ? duration : 0;
  7922. this._mixer.dispatchEvent( {
  7923. type: 'finished', action: this,
  7924. direction: deltaTime > 0 ? 1 : -1
  7925. } );
  7926. break;
  7927. } else if ( pending === 0 ) {
  7928. // transition to last round
  7929. var atStart = deltaTime < 0;
  7930. this._setEndings( atStart, ! atStart, pingPong );
  7931. } else {
  7932. this._setEndings( false, false, pingPong );
  7933. }
  7934. this._loopCount = loopCount;
  7935. this._mixer.dispatchEvent( {
  7936. type: 'loop', action: this, loopDelta: loopDelta
  7937. } );
  7938. }
  7939. if ( loop === THREE.LoopPingPong && ( loopCount & 1 ) === 1 ) {
  7940. // invert time for the "pong round"
  7941. this.time = time;
  7942. return duration - time;
  7943. }
  7944. break;
  7945. }
  7946. this.time = time;
  7947. return time;
  7948. },
  7949. _setEndings: function( atStart, atEnd, pingPong ) {
  7950. var settings = this._interpolantSettings;
  7951. if ( pingPong ) {
  7952. settings.endingStart = THREE.ZeroSlopeEnding;
  7953. settings.endingEnd = THREE.ZeroSlopeEnding;
  7954. } else {
  7955. // assuming for LoopOnce atStart == atEnd == true
  7956. if ( atStart ) {
  7957. settings.endingStart = this.zeroSlopeAtStart ?
  7958. THREE.ZeroSlopeEnding : THREE.ZeroCurvatureEnding;
  7959. } else {
  7960. settings.endingStart = THREE.WrapAroundEnding;
  7961. }
  7962. if ( atEnd ) {
  7963. settings.endingEnd = this.zeroSlopeAtEnd ?
  7964. THREE.ZeroSlopeEnding : THREE.ZeroCurvatureEnding;
  7965. } else {
  7966. settings.endingEnd = THREE.WrapAroundEnding;
  7967. }
  7968. }
  7969. },
  7970. _scheduleFading: function( duration, weightNow, weightThen ) {
  7971. var mixer = this._mixer, now = mixer.time,
  7972. interpolant = this._weightInterpolant;
  7973. if ( interpolant === null ) {
  7974. interpolant = mixer._lendControlInterpolant(),
  7975. this._weightInterpolant = interpolant;
  7976. }
  7977. var times = interpolant.parameterPositions,
  7978. values = interpolant.sampleValues;
  7979. times[ 0 ] = now; values[ 0 ] = weightNow;
  7980. times[ 1 ] = now + duration; values[ 1 ] = weightThen;
  7981. return this;
  7982. }
  7983. };
  7984. // Implementation details:
  7985. Object.assign( THREE.AnimationMixer.prototype, {
  7986. _bindAction: function( action, prototypeAction ) {
  7987. var root = action._localRoot || this._root,
  7988. tracks = action._clip.tracks,
  7989. nTracks = tracks.length,
  7990. bindings = action._propertyBindings,
  7991. interpolants = action._interpolants,
  7992. rootUuid = root.uuid,
  7993. bindingsByRoot = this._bindingsByRootAndName,
  7994. bindingsByName = bindingsByRoot[ rootUuid ];
  7995. if ( bindingsByName === undefined ) {
  7996. bindingsByName = {};
  7997. bindingsByRoot[ rootUuid ] = bindingsByName;
  7998. }
  7999. for ( var i = 0; i !== nTracks; ++ i ) {
  8000. var track = tracks[ i ],
  8001. trackName = track.name,
  8002. binding = bindingsByName[ trackName ];
  8003. if ( binding !== undefined ) {
  8004. bindings[ i ] = binding;
  8005. } else {
  8006. binding = bindings[ i ];
  8007. if ( binding !== undefined ) {
  8008. // existing binding, make sure the cache knows
  8009. if ( binding._cacheIndex === null ) {
  8010. ++ binding.referenceCount;
  8011. this._addInactiveBinding( binding, rootUuid, trackName );
  8012. }
  8013. continue;
  8014. }
  8015. var path = prototypeAction && prototypeAction.
  8016. _propertyBindings[ i ].binding.parsedPath;
  8017. binding = new THREE.PropertyMixer(
  8018. THREE.PropertyBinding.create( root, trackName, path ),
  8019. track.ValueTypeName, track.getValueSize() );
  8020. ++ binding.referenceCount;
  8021. this._addInactiveBinding( binding, rootUuid, trackName );
  8022. bindings[ i ] = binding;
  8023. }
  8024. interpolants[ i ].resultBuffer = binding.buffer;
  8025. }
  8026. },
  8027. _activateAction: function( action ) {
  8028. if ( ! this._isActiveAction( action ) ) {
  8029. if ( action._cacheIndex === null ) {
  8030. // this action has been forgotten by the cache, but the user
  8031. // appears to be still using it -> rebind
  8032. var rootUuid = ( action._localRoot || this._root ).uuid,
  8033. clipName = action._clip.name,
  8034. actionsForClip = this._actionsByClip[ clipName ];
  8035. this._bindAction( action,
  8036. actionsForClip && actionsForClip.knownActions[ 0 ] );
  8037. this._addInactiveAction( action, clipName, rootUuid );
  8038. }
  8039. var bindings = action._propertyBindings;
  8040. // increment reference counts / sort out state
  8041. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  8042. var binding = bindings[ i ];
  8043. if ( binding.useCount ++ === 0 ) {
  8044. this._lendBinding( binding );
  8045. binding.saveOriginalState();
  8046. }
  8047. }
  8048. this._lendAction( action );
  8049. }
  8050. },
  8051. _deactivateAction: function( action ) {
  8052. if ( this._isActiveAction( action ) ) {
  8053. var bindings = action._propertyBindings;
  8054. // decrement reference counts / sort out state
  8055. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  8056. var binding = bindings[ i ];
  8057. if ( -- binding.useCount === 0 ) {
  8058. binding.restoreOriginalState();
  8059. this._takeBackBinding( binding );
  8060. }
  8061. }
  8062. this._takeBackAction( action );
  8063. }
  8064. },
  8065. // Memory manager
  8066. _initMemoryManager: function() {
  8067. this._actions = []; // 'nActiveActions' followed by inactive ones
  8068. this._nActiveActions = 0;
  8069. this._actionsByClip = {};
  8070. // inside:
  8071. // {
  8072. // knownActions: Array< _Action > - used as prototypes
  8073. // actionByRoot: _Action - lookup
  8074. // }
  8075. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  8076. this._nActiveBindings = 0;
  8077. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  8078. this._controlInterpolants = []; // same game as above
  8079. this._nActiveControlInterpolants = 0;
  8080. var scope = this;
  8081. this.stats = {
  8082. actions: {
  8083. get total() { return scope._actions.length; },
  8084. get inUse() { return scope._nActiveActions; }
  8085. },
  8086. bindings: {
  8087. get total() { return scope._bindings.length; },
  8088. get inUse() { return scope._nActiveBindings; }
  8089. },
  8090. controlInterpolants: {
  8091. get total() { return scope._controlInterpolants.length; },
  8092. get inUse() { return scope._nActiveControlInterpolants; }
  8093. }
  8094. };
  8095. },
  8096. // Memory management for _Action objects
  8097. _isActiveAction: function( action ) {
  8098. var index = action._cacheIndex;
  8099. return index !== null && index < this._nActiveActions;
  8100. },
  8101. _addInactiveAction: function( action, clipName, rootUuid ) {
  8102. var actions = this._actions,
  8103. actionsByClip = this._actionsByClip,
  8104. actionsForClip = actionsByClip[ clipName ];
  8105. if ( actionsForClip === undefined ) {
  8106. actionsForClip = {
  8107. knownActions: [ action ],
  8108. actionByRoot: {}
  8109. };
  8110. action._byClipCacheIndex = 0;
  8111. actionsByClip[ clipName ] = actionsForClip;
  8112. } else {
  8113. var knownActions = actionsForClip.knownActions;
  8114. action._byClipCacheIndex = knownActions.length;
  8115. knownActions.push( action );
  8116. }
  8117. action._cacheIndex = actions.length;
  8118. actions.push( action );
  8119. actionsForClip.actionByRoot[ rootUuid ] = action;
  8120. },
  8121. _removeInactiveAction: function( action ) {
  8122. var actions = this._actions,
  8123. lastInactiveAction = actions[ actions.length - 1 ],
  8124. cacheIndex = action._cacheIndex;
  8125. lastInactiveAction._cacheIndex = cacheIndex;
  8126. actions[ cacheIndex ] = lastInactiveAction;
  8127. actions.pop();
  8128. action._cacheIndex = null;
  8129. var clipName = action._clip.name,
  8130. actionsByClip = this._actionsByClip,
  8131. actionsForClip = actionsByClip[ clipName ],
  8132. knownActionsForClip = actionsForClip.knownActions,
  8133. lastKnownAction =
  8134. knownActionsForClip[ knownActionsForClip.length - 1 ],
  8135. byClipCacheIndex = action._byClipCacheIndex;
  8136. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  8137. knownActionsForClip[ byClipCacheIndex ] = lastKnownAction;
  8138. knownActionsForClip.pop();
  8139. action._byClipCacheIndex = null;
  8140. var actionByRoot = actionsForClip.actionByRoot,
  8141. rootUuid = ( actions._localRoot || this._root ).uuid;
  8142. delete actionByRoot[ rootUuid ];
  8143. if ( knownActionsForClip.length === 0 ) {
  8144. delete actionsByClip[ clipName ];
  8145. }
  8146. this._removeInactiveBindingsForAction( action );
  8147. },
  8148. _removeInactiveBindingsForAction: function( action ) {
  8149. var bindings = action._propertyBindings;
  8150. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  8151. var binding = bindings[ i ];
  8152. if ( -- binding.referenceCount === 0 ) {
  8153. this._removeInactiveBinding( binding );
  8154. }
  8155. }
  8156. },
  8157. _lendAction: function( action ) {
  8158. // [ active actions | inactive actions ]
  8159. // [ active actions >| inactive actions ]
  8160. // s a
  8161. // <-swap->
  8162. // a s
  8163. var actions = this._actions,
  8164. prevIndex = action._cacheIndex,
  8165. lastActiveIndex = this._nActiveActions ++,
  8166. firstInactiveAction = actions[ lastActiveIndex ];
  8167. action._cacheIndex = lastActiveIndex;
  8168. actions[ lastActiveIndex ] = action;
  8169. firstInactiveAction._cacheIndex = prevIndex;
  8170. actions[ prevIndex ] = firstInactiveAction;
  8171. },
  8172. _takeBackAction: function( action ) {
  8173. // [ active actions | inactive actions ]
  8174. // [ active actions |< inactive actions ]
  8175. // a s
  8176. // <-swap->
  8177. // s a
  8178. var actions = this._actions,
  8179. prevIndex = action._cacheIndex,
  8180. firstInactiveIndex = -- this._nActiveActions,
  8181. lastActiveAction = actions[ firstInactiveIndex ];
  8182. action._cacheIndex = firstInactiveIndex;
  8183. actions[ firstInactiveIndex ] = action;
  8184. lastActiveAction._cacheIndex = prevIndex;
  8185. actions[ prevIndex ] = lastActiveAction;
  8186. },
  8187. // Memory management for PropertyMixer objects
  8188. _addInactiveBinding: function( binding, rootUuid, trackName ) {
  8189. var bindingsByRoot = this._bindingsByRootAndName,
  8190. bindingByName = bindingsByRoot[ rootUuid ],
  8191. bindings = this._bindings;
  8192. if ( bindingByName === undefined ) {
  8193. bindingByName = {};
  8194. bindingsByRoot[ rootUuid ] = bindingByName;
  8195. }
  8196. bindingByName[ trackName ] = binding;
  8197. binding._cacheIndex = bindings.length;
  8198. bindings.push( binding );
  8199. },
  8200. _removeInactiveBinding: function( binding ) {
  8201. var bindings = this._bindings,
  8202. propBinding = binding.binding,
  8203. rootUuid = propBinding.rootNode.uuid,
  8204. trackName = propBinding.path,
  8205. bindingsByRoot = this._bindingsByRootAndName,
  8206. bindingByName = bindingsByRoot[ rootUuid ],
  8207. lastInactiveBinding = bindings[ bindings.length - 1 ],
  8208. cacheIndex = binding._cacheIndex;
  8209. lastInactiveBinding._cacheIndex = cacheIndex;
  8210. bindings[ cacheIndex ] = lastInactiveBinding;
  8211. bindings.pop();
  8212. delete bindingByName[ trackName ];
  8213. remove_empty_map: {
  8214. for ( var _ in bindingByName ) break remove_empty_map;
  8215. delete bindingsByRoot[ rootUuid ];
  8216. }
  8217. },
  8218. _lendBinding: function( binding ) {
  8219. var bindings = this._bindings,
  8220. prevIndex = binding._cacheIndex,
  8221. lastActiveIndex = this._nActiveBindings ++,
  8222. firstInactiveBinding = bindings[ lastActiveIndex ];
  8223. binding._cacheIndex = lastActiveIndex;
  8224. bindings[ lastActiveIndex ] = binding;
  8225. firstInactiveBinding._cacheIndex = prevIndex;
  8226. bindings[ prevIndex ] = firstInactiveBinding;
  8227. },
  8228. _takeBackBinding: function( binding ) {
  8229. var bindings = this._bindings,
  8230. prevIndex = binding._cacheIndex,
  8231. firstInactiveIndex = -- this._nActiveBindings,
  8232. lastActiveBinding = bindings[ firstInactiveIndex ];
  8233. binding._cacheIndex = firstInactiveIndex;
  8234. bindings[ firstInactiveIndex ] = binding;
  8235. lastActiveBinding._cacheIndex = prevIndex;
  8236. bindings[ prevIndex ] = lastActiveBinding;
  8237. },
  8238. // Memory management of Interpolants for weight and time scale
  8239. _lendControlInterpolant: function() {
  8240. var interpolants = this._controlInterpolants,
  8241. lastActiveIndex = this._nActiveControlInterpolants ++,
  8242. interpolant = interpolants[ lastActiveIndex ];
  8243. if ( interpolant === undefined ) {
  8244. interpolant = new THREE.LinearInterpolant(
  8245. new Float32Array( 2 ), new Float32Array( 2 ),
  8246. 1, this._controlInterpolantsResultBuffer );
  8247. interpolant.__cacheIndex = lastActiveIndex;
  8248. interpolants[ lastActiveIndex ] = interpolant;
  8249. }
  8250. return interpolant;
  8251. },
  8252. _takeBackControlInterpolant: function( interpolant ) {
  8253. var interpolants = this._controlInterpolants,
  8254. prevIndex = interpolant.__cacheIndex,
  8255. firstInactiveIndex = -- this._nActiveControlInterpolants,
  8256. lastActiveInterpolant = interpolants[ firstInactiveIndex ];
  8257. interpolant.__cacheIndex = firstInactiveIndex;
  8258. interpolants[ firstInactiveIndex ] = interpolant;
  8259. lastActiveInterpolant.__cacheIndex = prevIndex;
  8260. interpolants[ prevIndex ] = lastActiveInterpolant;
  8261. },
  8262. _controlInterpolantsResultBuffer: new Float32Array( 1 )
  8263. } );
  8264. // File:src/animation/AnimationObjectGroup.js
  8265. /**
  8266. *
  8267. * A group of objects that receives a shared animation state.
  8268. *
  8269. * Usage:
  8270. *
  8271. * - Add objects you would otherwise pass as 'root' to the
  8272. * constructor or the .clipAction method of AnimationMixer.
  8273. *
  8274. * - Instead pass this object as 'root'.
  8275. *
  8276. * - You can also add and remove objects later when the mixer
  8277. * is running.
  8278. *
  8279. * Note:
  8280. *
  8281. * Objects of this class appear as one object to the mixer,
  8282. * so cache control of the individual objects must be done
  8283. * on the group.
  8284. *
  8285. * Limitation:
  8286. *
  8287. * - The animated properties must be compatible among the
  8288. * all objects in the group.
  8289. *
  8290. * - A single property can either be controlled through a
  8291. * target group or directly, but not both.
  8292. *
  8293. * @author tschw
  8294. */
  8295. THREE.AnimationObjectGroup = function( var_args ) {
  8296. this.uuid = THREE.Math.generateUUID();
  8297. // cached objects followed by the active ones
  8298. this._objects = Array.prototype.slice.call( arguments );
  8299. this.nCachedObjects_ = 0; // threshold
  8300. // note: read by PropertyBinding.Composite
  8301. var indices = {};
  8302. this._indicesByUUID = indices; // for bookkeeping
  8303. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  8304. indices[ arguments[ i ].uuid ] = i;
  8305. }
  8306. this._paths = []; // inside: string
  8307. this._parsedPaths = []; // inside: { we don't care, here }
  8308. this._bindings = []; // inside: Array< PropertyBinding >
  8309. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  8310. var scope = this;
  8311. this.stats = {
  8312. objects: {
  8313. get total() { return scope._objects.length; },
  8314. get inUse() { return this.total - scope.nCachedObjects_; }
  8315. },
  8316. get bindingsPerObject() { return scope._bindings.length; }
  8317. };
  8318. };
  8319. THREE.AnimationObjectGroup.prototype = {
  8320. constructor: THREE.AnimationObjectGroup,
  8321. add: function( var_args ) {
  8322. var objects = this._objects,
  8323. nObjects = objects.length,
  8324. nCachedObjects = this.nCachedObjects_,
  8325. indicesByUUID = this._indicesByUUID,
  8326. paths = this._paths,
  8327. parsedPaths = this._parsedPaths,
  8328. bindings = this._bindings,
  8329. nBindings = bindings.length;
  8330. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  8331. var object = arguments[ i ],
  8332. uuid = object.uuid,
  8333. index = indicesByUUID[ uuid ];
  8334. if ( index === undefined ) {
  8335. // unknown object -> add it to the ACTIVE region
  8336. index = nObjects ++;
  8337. indicesByUUID[ uuid ] = index;
  8338. objects.push( object );
  8339. // accounting is done, now do the same for all bindings
  8340. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8341. bindings[ j ].push(
  8342. new THREE.PropertyBinding(
  8343. object, paths[ j ], parsedPaths[ j ] ) );
  8344. }
  8345. } else if ( index < nCachedObjects ) {
  8346. var knownObject = objects[ index ];
  8347. // move existing object to the ACTIVE region
  8348. var firstActiveIndex = -- nCachedObjects,
  8349. lastCachedObject = objects[ firstActiveIndex ];
  8350. indicesByUUID[ lastCachedObject.uuid ] = index;
  8351. objects[ index ] = lastCachedObject;
  8352. indicesByUUID[ uuid ] = firstActiveIndex;
  8353. objects[ firstActiveIndex ] = object;
  8354. // accounting is done, now do the same for all bindings
  8355. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8356. var bindingsForPath = bindings[ j ],
  8357. lastCached = bindingsForPath[ firstActiveIndex ],
  8358. binding = bindingsForPath[ index ];
  8359. bindingsForPath[ index ] = lastCached;
  8360. if ( binding === undefined ) {
  8361. // since we do not bother to create new bindings
  8362. // for objects that are cached, the binding may
  8363. // or may not exist
  8364. binding = new THREE.PropertyBinding(
  8365. object, paths[ j ], parsedPaths[ j ] );
  8366. }
  8367. bindingsForPath[ firstActiveIndex ] = binding;
  8368. }
  8369. } else if ( objects[ index ] !== knownObject) {
  8370. console.error( "Different objects with the same UUID " +
  8371. "detected. Clean the caches or recreate your " +
  8372. "infrastructure when reloading scenes..." );
  8373. } // else the object is already where we want it to be
  8374. } // for arguments
  8375. this.nCachedObjects_ = nCachedObjects;
  8376. },
  8377. remove: function( var_args ) {
  8378. var objects = this._objects,
  8379. nObjects = objects.length,
  8380. nCachedObjects = this.nCachedObjects_,
  8381. indicesByUUID = this._indicesByUUID,
  8382. bindings = this._bindings,
  8383. nBindings = bindings.length;
  8384. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  8385. var object = arguments[ i ],
  8386. uuid = object.uuid,
  8387. index = indicesByUUID[ uuid ];
  8388. if ( index !== undefined && index >= nCachedObjects ) {
  8389. // move existing object into the CACHED region
  8390. var lastCachedIndex = nCachedObjects ++,
  8391. firstActiveObject = objects[ lastCachedIndex ];
  8392. indicesByUUID[ firstActiveObject.uuid ] = index;
  8393. objects[ index ] = firstActiveObject;
  8394. indicesByUUID[ uuid ] = lastCachedIndex;
  8395. objects[ lastCachedIndex ] = object;
  8396. // accounting is done, now do the same for all bindings
  8397. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8398. var bindingsForPath = bindings[ j ],
  8399. firstActive = bindingsForPath[ lastCachedIndex ],
  8400. binding = bindingsForPath[ index ];
  8401. bindingsForPath[ index ] = firstActive;
  8402. bindingsForPath[ lastCachedIndex ] = binding;
  8403. }
  8404. }
  8405. } // for arguments
  8406. this.nCachedObjects_ = nCachedObjects;
  8407. },
  8408. // remove & forget
  8409. uncache: function( var_args ) {
  8410. var objects = this._objects,
  8411. nObjects = objects.length,
  8412. nCachedObjects = this.nCachedObjects_,
  8413. indicesByUUID = this._indicesByUUID,
  8414. bindings = this._bindings,
  8415. nBindings = bindings.length;
  8416. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  8417. var object = arguments[ i ],
  8418. uuid = object.uuid,
  8419. index = indicesByUUID[ uuid ];
  8420. if ( index !== undefined ) {
  8421. delete indicesByUUID[ uuid ];
  8422. if ( index < nCachedObjects ) {
  8423. // object is cached, shrink the CACHED region
  8424. var firstActiveIndex = -- nCachedObjects,
  8425. lastCachedObject = objects[ firstActiveIndex ],
  8426. lastIndex = -- nObjects,
  8427. lastObject = objects[ lastIndex ];
  8428. // last cached object takes this object's place
  8429. indicesByUUID[ lastCachedObject.uuid ] = index;
  8430. objects[ index ] = lastCachedObject;
  8431. // last object goes to the activated slot and pop
  8432. indicesByUUID[ lastObject.uuid ] = firstActiveIndex;
  8433. objects[ firstActiveIndex ] = lastObject;
  8434. objects.pop();
  8435. // accounting is done, now do the same for all bindings
  8436. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8437. var bindingsForPath = bindings[ j ],
  8438. lastCached = bindingsForPath[ firstActiveIndex ],
  8439. last = bindingsForPath[ lastIndex ];
  8440. bindingsForPath[ index ] = lastCached;
  8441. bindingsForPath[ firstActiveIndex ] = last;
  8442. bindingsForPath.pop();
  8443. }
  8444. } else {
  8445. // object is active, just swap with the last and pop
  8446. var lastIndex = -- nObjects,
  8447. lastObject = objects[ lastIndex ];
  8448. indicesByUUID[ lastObject.uuid ] = index;
  8449. objects[ index ] = lastObject;
  8450. objects.pop();
  8451. // accounting is done, now do the same for all bindings
  8452. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8453. var bindingsForPath = bindings[ j ];
  8454. bindingsForPath[ index ] = bindingsForPath[ lastIndex ];
  8455. bindingsForPath.pop();
  8456. }
  8457. } // cached or active
  8458. } // if object is known
  8459. } // for arguments
  8460. this.nCachedObjects_ = nCachedObjects;
  8461. },
  8462. // Internal interface used by befriended PropertyBinding.Composite:
  8463. subscribe_: function( path, parsedPath ) {
  8464. // returns an array of bindings for the given path that is changed
  8465. // according to the contained objects in the group
  8466. var indicesByPath = this._bindingsIndicesByPath,
  8467. index = indicesByPath[ path ],
  8468. bindings = this._bindings;
  8469. if ( index !== undefined ) return bindings[ index ];
  8470. var paths = this._paths,
  8471. parsedPaths = this._parsedPaths,
  8472. objects = this._objects,
  8473. nObjects = objects.length,
  8474. nCachedObjects = this.nCachedObjects_,
  8475. bindingsForPath = new Array( nObjects );
  8476. index = bindings.length;
  8477. indicesByPath[ path ] = index;
  8478. paths.push( path );
  8479. parsedPaths.push( parsedPath );
  8480. bindings.push( bindingsForPath );
  8481. for ( var i = nCachedObjects,
  8482. n = objects.length; i !== n; ++ i ) {
  8483. var object = objects[ i ];
  8484. bindingsForPath[ i ] =
  8485. new THREE.PropertyBinding( object, path, parsedPath );
  8486. }
  8487. return bindingsForPath;
  8488. },
  8489. unsubscribe_: function( path ) {
  8490. // tells the group to forget about a property path and no longer
  8491. // update the array previously obtained with 'subscribe_'
  8492. var indicesByPath = this._bindingsIndicesByPath,
  8493. index = indicesByPath[ path ];
  8494. if ( index !== undefined ) {
  8495. var paths = this._paths,
  8496. parsedPaths = this._parsedPaths,
  8497. bindings = this._bindings,
  8498. lastBindingsIndex = bindings.length - 1,
  8499. lastBindings = bindings[ lastBindingsIndex ],
  8500. lastBindingsPath = path[ lastBindingsIndex ];
  8501. indicesByPath[ lastBindingsPath ] = index;
  8502. bindings[ index ] = lastBindings;
  8503. bindings.pop();
  8504. parsedPaths[ index ] = parsedPaths[ lastBindingsIndex ];
  8505. parsedPaths.pop();
  8506. paths[ index ] = paths[ lastBindingsIndex ];
  8507. paths.pop();
  8508. }
  8509. }
  8510. };
  8511. // File:src/animation/AnimationUtils.js
  8512. /**
  8513. * @author tschw
  8514. * @author Ben Houston / http://clara.io/
  8515. * @author David Sarno / http://lighthaus.us/
  8516. */
  8517. THREE.AnimationUtils = {
  8518. // same as Array.prototype.slice, but also works on typed arrays
  8519. arraySlice: function( array, from, to ) {
  8520. if ( THREE.AnimationUtils.isTypedArray( array ) ) {
  8521. return new array.constructor( array.subarray( from, to ) );
  8522. }
  8523. return array.slice( from, to );
  8524. },
  8525. // converts an array to a specific type
  8526. convertArray: function( array, type, forceClone ) {
  8527. if ( ! array || // let 'undefined' and 'null' pass
  8528. ! forceClone && array.constructor === type ) return array;
  8529. if ( typeof type.BYTES_PER_ELEMENT === 'number' ) {
  8530. return new type( array ); // create typed array
  8531. }
  8532. return Array.prototype.slice.call( array ); // create Array
  8533. },
  8534. isTypedArray: function( object ) {
  8535. return ArrayBuffer.isView( object ) &&
  8536. ! ( object instanceof DataView );
  8537. },
  8538. // returns an array by which times and values can be sorted
  8539. getKeyframeOrder: function( times ) {
  8540. function compareTime( i, j ) {
  8541. return times[ i ] - times[ j ];
  8542. }
  8543. var n = times.length;
  8544. var result = new Array( n );
  8545. for ( var i = 0; i !== n; ++ i ) result[ i ] = i;
  8546. result.sort( compareTime );
  8547. return result;
  8548. },
  8549. // uses the array previously returned by 'getKeyframeOrder' to sort data
  8550. sortedArray: function( values, stride, order ) {
  8551. var nValues = values.length;
  8552. var result = new values.constructor( nValues );
  8553. for ( var i = 0, dstOffset = 0; dstOffset !== nValues; ++ i ) {
  8554. var srcOffset = order[ i ] * stride;
  8555. for ( var j = 0; j !== stride; ++ j ) {
  8556. result[ dstOffset ++ ] = values[ srcOffset + j ];
  8557. }
  8558. }
  8559. return result;
  8560. },
  8561. // function for parsing AOS keyframe formats
  8562. flattenJSON: function( jsonKeys, times, values, valuePropertyName ) {
  8563. var i = 1, key = jsonKeys[ 0 ];
  8564. while ( key !== undefined && key[ valuePropertyName ] === undefined ) {
  8565. key = jsonKeys[ i ++ ];
  8566. }
  8567. if ( key === undefined ) return; // no data
  8568. var value = key[ valuePropertyName ];
  8569. if ( value === undefined ) return; // no data
  8570. if ( Array.isArray( value ) ) {
  8571. do {
  8572. value = key[ valuePropertyName ];
  8573. if ( value !== undefined ) {
  8574. times.push( key.time );
  8575. values.push.apply( values, value ); // push all elements
  8576. }
  8577. key = jsonKeys[ i ++ ];
  8578. } while ( key !== undefined );
  8579. } else if ( value.toArray !== undefined ) {
  8580. // ...assume THREE.Math-ish
  8581. do {
  8582. value = key[ valuePropertyName ];
  8583. if ( value !== undefined ) {
  8584. times.push( key.time );
  8585. value.toArray( values, values.length );
  8586. }
  8587. key = jsonKeys[ i ++ ];
  8588. } while ( key !== undefined );
  8589. } else {
  8590. // otherwise push as-is
  8591. do {
  8592. value = key[ valuePropertyName ];
  8593. if ( value !== undefined ) {
  8594. times.push( key.time );
  8595. values.push( value );
  8596. }
  8597. key = jsonKeys[ i ++ ];
  8598. } while ( key !== undefined );
  8599. }
  8600. }
  8601. };
  8602. // File:src/animation/KeyframeTrack.js
  8603. /**
  8604. *
  8605. * A timed sequence of keyframes for a specific property.
  8606. *
  8607. *
  8608. * @author Ben Houston / http://clara.io/
  8609. * @author David Sarno / http://lighthaus.us/
  8610. * @author tschw
  8611. */
  8612. THREE.KeyframeTrack = function ( name, times, values, interpolation ) {
  8613. if( name === undefined ) throw new Error( "track name is undefined" );
  8614. if( times === undefined || times.length === 0 ) {
  8615. throw new Error( "no keyframes in track named " + name );
  8616. }
  8617. this.name = name;
  8618. this.times = THREE.AnimationUtils.convertArray( times, this.TimeBufferType );
  8619. this.values = THREE.AnimationUtils.convertArray( values, this.ValueBufferType );
  8620. this.setInterpolation( interpolation || this.DefaultInterpolation );
  8621. this.validate();
  8622. this.optimize();
  8623. };
  8624. THREE.KeyframeTrack.prototype = {
  8625. constructor: THREE.KeyframeTrack,
  8626. TimeBufferType: Float32Array,
  8627. ValueBufferType: Float32Array,
  8628. DefaultInterpolation: THREE.InterpolateLinear,
  8629. InterpolantFactoryMethodDiscrete: function( result ) {
  8630. return new THREE.DiscreteInterpolant(
  8631. this.times, this.values, this.getValueSize(), result );
  8632. },
  8633. InterpolantFactoryMethodLinear: function( result ) {
  8634. return new THREE.LinearInterpolant(
  8635. this.times, this.values, this.getValueSize(), result );
  8636. },
  8637. InterpolantFactoryMethodSmooth: function( result ) {
  8638. return new THREE.CubicInterpolant(
  8639. this.times, this.values, this.getValueSize(), result );
  8640. },
  8641. setInterpolation: function( interpolation ) {
  8642. var factoryMethod = undefined;
  8643. switch ( interpolation ) {
  8644. case THREE.InterpolateDiscrete:
  8645. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  8646. break;
  8647. case THREE.InterpolateLinear:
  8648. factoryMethod = this.InterpolantFactoryMethodLinear;
  8649. break;
  8650. case THREE.InterpolateSmooth:
  8651. factoryMethod = this.InterpolantFactoryMethodSmooth;
  8652. break;
  8653. }
  8654. if ( factoryMethod === undefined ) {
  8655. var message = "unsupported interpolation for " +
  8656. this.ValueTypeName + " keyframe track named " + this.name;
  8657. if ( this.createInterpolant === undefined ) {
  8658. // fall back to default, unless the default itself is messed up
  8659. if ( interpolation !== this.DefaultInterpolation ) {
  8660. this.setInterpolation( this.DefaultInterpolation );
  8661. } else {
  8662. throw new Error( message ); // fatal, in this case
  8663. }
  8664. }
  8665. console.warn( message );
  8666. return;
  8667. }
  8668. this.createInterpolant = factoryMethod;
  8669. },
  8670. getInterpolation: function() {
  8671. switch ( this.createInterpolant ) {
  8672. case this.InterpolantFactoryMethodDiscrete:
  8673. return THREE.InterpolateDiscrete;
  8674. case this.InterpolantFactoryMethodLinear:
  8675. return THREE.InterpolateLinear;
  8676. case this.InterpolantFactoryMethodSmooth:
  8677. return THREE.InterpolateSmooth;
  8678. }
  8679. },
  8680. getValueSize: function() {
  8681. return this.values.length / this.times.length;
  8682. },
  8683. // move all keyframes either forwards or backwards in time
  8684. shift: function( timeOffset ) {
  8685. if( timeOffset !== 0.0 ) {
  8686. var times = this.times;
  8687. for( var i = 0, n = times.length; i !== n; ++ i ) {
  8688. times[ i ] += timeOffset;
  8689. }
  8690. }
  8691. return this;
  8692. },
  8693. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  8694. scale: function( timeScale ) {
  8695. if( timeScale !== 1.0 ) {
  8696. var times = this.times;
  8697. for( var i = 0, n = times.length; i !== n; ++ i ) {
  8698. times[ i ] *= timeScale;
  8699. }
  8700. }
  8701. return this;
  8702. },
  8703. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  8704. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  8705. trim: function( startTime, endTime ) {
  8706. var times = this.times,
  8707. nKeys = times.length,
  8708. from = 0,
  8709. to = nKeys - 1;
  8710. while ( from !== nKeys && times[ from ] < startTime ) ++ from;
  8711. while ( to !== -1 && times[ to ] > endTime ) -- to;
  8712. ++ to; // inclusive -> exclusive bound
  8713. if( from !== 0 || to !== nKeys ) {
  8714. // empty tracks are forbidden, so keep at least one keyframe
  8715. if ( from >= to ) to = Math.max( to , 1 ), from = to - 1;
  8716. var stride = this.getValueSize();
  8717. this.times = THREE.AnimationUtils.arraySlice( times, from, to );
  8718. this.values = THREE.AnimationUtils.
  8719. arraySlice( this.values, from * stride, to * stride );
  8720. }
  8721. return this;
  8722. },
  8723. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  8724. validate: function() {
  8725. var valid = true;
  8726. var valueSize = this.getValueSize();
  8727. if ( valueSize - Math.floor( valueSize ) !== 0 ) {
  8728. console.error( "invalid value size in track", this );
  8729. valid = false;
  8730. }
  8731. var times = this.times,
  8732. values = this.values,
  8733. nKeys = times.length;
  8734. if( nKeys === 0 ) {
  8735. console.error( "track is empty", this );
  8736. valid = false;
  8737. }
  8738. var prevTime = null;
  8739. for( var i = 0; i !== nKeys; i ++ ) {
  8740. var currTime = times[ i ];
  8741. if ( typeof currTime === 'number' && isNaN( currTime ) ) {
  8742. console.error( "time is not a valid number", this, i, currTime );
  8743. valid = false;
  8744. break;
  8745. }
  8746. if( prevTime !== null && prevTime > currTime ) {
  8747. console.error( "out of order keys", this, i, currTime, prevTime );
  8748. valid = false;
  8749. break;
  8750. }
  8751. prevTime = currTime;
  8752. }
  8753. if ( values !== undefined ) {
  8754. if ( THREE.AnimationUtils.isTypedArray( values ) ) {
  8755. for ( var i = 0, n = values.length; i !== n; ++ i ) {
  8756. var value = values[ i ];
  8757. if ( isNaN( value ) ) {
  8758. console.error( "value is not a valid number", this, i, value );
  8759. valid = false;
  8760. break;
  8761. }
  8762. }
  8763. }
  8764. }
  8765. return valid;
  8766. },
  8767. // removes equivalent sequential keys as common in morph target sequences
  8768. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  8769. optimize: function() {
  8770. var times = this.times,
  8771. values = this.values,
  8772. stride = this.getValueSize(),
  8773. writeIndex = 1;
  8774. for( var i = 1, n = times.length - 1; i <= n; ++ i ) {
  8775. var keep = false;
  8776. var time = times[ i ];
  8777. var timeNext = times[ i + 1 ];
  8778. // remove adjacent keyframes scheduled at the same time
  8779. if ( time !== timeNext && ( i !== 1 || time !== time[ 0 ] ) ) {
  8780. // remove unnecessary keyframes same as their neighbors
  8781. var offset = i * stride,
  8782. offsetP = offset - stride,
  8783. offsetN = offset + stride;
  8784. for ( var j = 0; j !== stride; ++ j ) {
  8785. var value = values[ offset + j ];
  8786. if ( value !== values[ offsetP + j ] ||
  8787. value !== values[ offsetN + j ] ) {
  8788. keep = true;
  8789. break;
  8790. }
  8791. }
  8792. }
  8793. // in-place compaction
  8794. if ( keep ) {
  8795. if ( i !== writeIndex ) {
  8796. times[ writeIndex ] = times[ i ];
  8797. var readOffset = i * stride,
  8798. writeOffset = writeIndex * stride;
  8799. for ( var j = 0; j !== stride; ++ j ) {
  8800. values[ writeOffset + j ] = values[ readOffset + j ];
  8801. }
  8802. }
  8803. ++ writeIndex;
  8804. }
  8805. }
  8806. if ( writeIndex !== times.length ) {
  8807. this.times = THREE.AnimationUtils.arraySlice( times, 0, writeIndex );
  8808. this.values = THREE.AnimationUtils.arraySlice( values, 0, writeIndex * stride );
  8809. }
  8810. return this;
  8811. }
  8812. };
  8813. // Static methods:
  8814. Object.assign( THREE.KeyframeTrack, {
  8815. // Serialization (in static context, because of constructor invocation
  8816. // and automatic invocation of .toJSON):
  8817. parse: function( json ) {
  8818. if( json.type === undefined ) {
  8819. throw new Error( "track type undefined, can not parse" );
  8820. }
  8821. var trackType = THREE.KeyframeTrack._getTrackTypeForValueTypeName( json.type );
  8822. if ( json.times === undefined ) {
  8823. console.warn( "legacy JSON format detected, converting" );
  8824. var times = [], values = [];
  8825. THREE.AnimationUtils.flattenJSON( json.keys, times, values, 'value' );
  8826. json.times = times;
  8827. json.values = values;
  8828. }
  8829. // derived classes can define a static parse method
  8830. if ( trackType.parse !== undefined ) {
  8831. return trackType.parse( json );
  8832. } else {
  8833. // by default, we asssume a constructor compatible with the base
  8834. return new trackType(
  8835. json.name, json.times, json.values, json.interpolation );
  8836. }
  8837. },
  8838. toJSON: function( track ) {
  8839. var trackType = track.constructor;
  8840. var json;
  8841. // derived classes can define a static toJSON method
  8842. if ( trackType.toJSON !== undefined ) {
  8843. json = trackType.toJSON( track );
  8844. } else {
  8845. // by default, we assume the data can be serialized as-is
  8846. json = {
  8847. 'name': track.name,
  8848. 'times': THREE.AnimationUtils.convertArray( track.times, Array ),
  8849. 'values': THREE.AnimationUtils.convertArray( track.values, Array )
  8850. };
  8851. var interpolation = track.getInterpolation();
  8852. if ( interpolation !== track.DefaultInterpolation ) {
  8853. json.interpolation = interpolation;
  8854. }
  8855. }
  8856. json.type = track.ValueTypeName; // mandatory
  8857. return json;
  8858. },
  8859. _getTrackTypeForValueTypeName: function( typeName ) {
  8860. switch( typeName.toLowerCase() ) {
  8861. case "scalar":
  8862. case "double":
  8863. case "float":
  8864. case "number":
  8865. case "integer":
  8866. return THREE.NumberKeyframeTrack;
  8867. case "vector":
  8868. case "vector2":
  8869. case "vector3":
  8870. case "vector4":
  8871. return THREE.VectorKeyframeTrack;
  8872. case "color":
  8873. return THREE.ColorKeyframeTrack;
  8874. case "quaternion":
  8875. return THREE.QuaternionKeyframeTrack;
  8876. case "bool":
  8877. case "boolean":
  8878. return THREE.BooleanKeyframeTrack;
  8879. case "string":
  8880. return THREE.StringKeyframeTrack;
  8881. };
  8882. throw new Error( "Unsupported typeName: " + typeName );
  8883. }
  8884. } );
  8885. // File:src/animation/PropertyBinding.js
  8886. /**
  8887. *
  8888. * A reference to a real property in the scene graph.
  8889. *
  8890. *
  8891. * @author Ben Houston / http://clara.io/
  8892. * @author David Sarno / http://lighthaus.us/
  8893. * @author tschw
  8894. */
  8895. THREE.PropertyBinding = function ( rootNode, path, parsedPath ) {
  8896. this.path = path;
  8897. this.parsedPath = parsedPath ||
  8898. THREE.PropertyBinding.parseTrackName( path );
  8899. this.node = THREE.PropertyBinding.findNode(
  8900. rootNode, this.parsedPath.nodeName ) || rootNode;
  8901. this.rootNode = rootNode;
  8902. };
  8903. THREE.PropertyBinding.prototype = {
  8904. constructor: THREE.PropertyBinding,
  8905. getValue: function getValue_unbound( targetArray, offset ) {
  8906. this.bind();
  8907. this.getValue( targetArray, offset );
  8908. // Note: This class uses a State pattern on a per-method basis:
  8909. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  8910. // prototype version of these methods with one that represents
  8911. // the bound state. When the property is not found, the methods
  8912. // become no-ops.
  8913. },
  8914. setValue: function getValue_unbound( sourceArray, offset ) {
  8915. this.bind();
  8916. this.setValue( sourceArray, offset );
  8917. },
  8918. // create getter / setter pair for a property in the scene graph
  8919. bind: function() {
  8920. var targetObject = this.node,
  8921. parsedPath = this.parsedPath,
  8922. objectName = parsedPath.objectName,
  8923. propertyName = parsedPath.propertyName,
  8924. propertyIndex = parsedPath.propertyIndex;
  8925. if ( ! targetObject ) {
  8926. targetObject = THREE.PropertyBinding.findNode(
  8927. this.rootNode, parsedPath.nodeName ) || this.rootNode;
  8928. this.node = targetObject;
  8929. }
  8930. // set fail state so we can just 'return' on error
  8931. this.getValue = this._getValue_unavailable;
  8932. this.setValue = this._setValue_unavailable;
  8933. // ensure there is a value node
  8934. if ( ! targetObject ) {
  8935. console.error( " trying to update node for track: " + this.path + " but it wasn't found." );
  8936. return;
  8937. }
  8938. if( objectName ) {
  8939. var objectIndex = parsedPath.objectIndex;
  8940. // special cases were we need to reach deeper into the hierarchy to get the face materials....
  8941. switch ( objectName ) {
  8942. case 'materials':
  8943. if( ! targetObject.material ) {
  8944. console.error( ' can not bind to material as node does not have a material', this );
  8945. return;
  8946. }
  8947. if( ! targetObject.material.materials ) {
  8948. console.error( ' can not bind to material.materials as node.material does not have a materials array', this );
  8949. return;
  8950. }
  8951. targetObject = targetObject.material.materials;
  8952. break;
  8953. case 'bones':
  8954. if( ! targetObject.skeleton ) {
  8955. console.error( ' can not bind to bones as node does not have a skeleton', this );
  8956. return;
  8957. }
  8958. // potential future optimization: skip this if propertyIndex is already an integer
  8959. // and convert the integer string to a true integer.
  8960. targetObject = targetObject.skeleton.bones;
  8961. // support resolving morphTarget names into indices.
  8962. for ( var i = 0; i < targetObject.length; i ++ ) {
  8963. if ( targetObject[i].name === objectIndex ) {
  8964. objectIndex = i;
  8965. break;
  8966. }
  8967. }
  8968. break;
  8969. default:
  8970. if ( targetObject[ objectName ] === undefined ) {
  8971. console.error( ' can not bind to objectName of node, undefined', this );
  8972. return;
  8973. }
  8974. targetObject = targetObject[ objectName ];
  8975. }
  8976. if ( objectIndex !== undefined ) {
  8977. if( targetObject[ objectIndex ] === undefined ) {
  8978. console.error( " trying to bind to objectIndex of objectName, but is undefined:", this, targetObject );
  8979. return;
  8980. }
  8981. targetObject = targetObject[ objectIndex ];
  8982. }
  8983. }
  8984. // resolve property
  8985. var nodeProperty = targetObject[ propertyName ];
  8986. if ( ! nodeProperty ) {
  8987. var nodeName = parsedPath.nodeName;
  8988. console.error( " trying to update property for track: " + nodeName +
  8989. '.' + propertyName + " but it wasn't found.", targetObject );
  8990. return;
  8991. }
  8992. // determine versioning scheme
  8993. var versioning = this.Versioning.None;
  8994. if ( targetObject.needsUpdate !== undefined ) { // material
  8995. versioning = this.Versioning.NeedsUpdate;
  8996. this.targetObject = targetObject;
  8997. } else if ( targetObject.matrixWorldNeedsUpdate !== undefined ) { // node transform
  8998. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  8999. this.targetObject = targetObject;
  9000. }
  9001. // determine how the property gets bound
  9002. var bindingType = this.BindingType.Direct;
  9003. if ( propertyIndex !== undefined ) {
  9004. // access a sub element of the property array (only primitives are supported right now)
  9005. if ( propertyName === "morphTargetInfluences" ) {
  9006. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  9007. // support resolving morphTarget names into indices.
  9008. if ( ! targetObject.geometry ) {
  9009. console.error( ' can not bind to morphTargetInfluences becasuse node does not have a geometry', this );
  9010. return;
  9011. }
  9012. if ( ! targetObject.geometry.morphTargets ) {
  9013. console.error( ' can not bind to morphTargetInfluences becasuse node does not have a geometry.morphTargets', this );
  9014. return;
  9015. }
  9016. for ( var i = 0; i < this.node.geometry.morphTargets.length; i ++ ) {
  9017. if ( targetObject.geometry.morphTargets[i].name === propertyIndex ) {
  9018. propertyIndex = i;
  9019. break;
  9020. }
  9021. }
  9022. }
  9023. bindingType = this.BindingType.ArrayElement;
  9024. this.resolvedProperty = nodeProperty;
  9025. this.propertyIndex = propertyIndex;
  9026. } else if ( nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined ) {
  9027. // must use copy for Object3D.Euler/Quaternion
  9028. bindingType = this.BindingType.HasFromToArray;
  9029. this.resolvedProperty = nodeProperty;
  9030. } else if ( nodeProperty.length !== undefined ) {
  9031. bindingType = this.BindingType.EntireArray;
  9032. this.resolvedProperty = nodeProperty;
  9033. } else {
  9034. this.propertyName = propertyName;
  9035. }
  9036. // select getter / setter
  9037. this.getValue = this.GetterByBindingType[ bindingType ];
  9038. this.setValue = this.SetterByBindingTypeAndVersioning[ bindingType ][ versioning ];
  9039. },
  9040. unbind: function() {
  9041. this.node = null;
  9042. // back to the prototype version of getValue / setValue
  9043. // note: avoiding to mutate the shape of 'this' via 'delete'
  9044. this.getValue = this._getValue_unbound;
  9045. this.setValue = this._setValue_unbound;
  9046. }
  9047. };
  9048. Object.assign( THREE.PropertyBinding.prototype, { // prototype, continued
  9049. // these are used to "bind" a nonexistent property
  9050. _getValue_unavailable: function() {},
  9051. _setValue_unavailable: function() {},
  9052. // initial state of these methods that calls 'bind'
  9053. _getValue_unbound: THREE.PropertyBinding.prototype.getValue,
  9054. _setValue_unbound: THREE.PropertyBinding.prototype.setValue,
  9055. BindingType: {
  9056. Direct: 0,
  9057. EntireArray: 1,
  9058. ArrayElement: 2,
  9059. HasFromToArray: 3
  9060. },
  9061. Versioning: {
  9062. None: 0,
  9063. NeedsUpdate: 1,
  9064. MatrixWorldNeedsUpdate: 2
  9065. },
  9066. GetterByBindingType: [
  9067. function getValue_direct( buffer, offset ) {
  9068. buffer[ offset ] = this.node[ this.propertyName ];
  9069. },
  9070. function getValue_array( buffer, offset ) {
  9071. var source = this.resolvedProperty;
  9072. for ( var i = 0, n = source.length; i !== n; ++ i ) {
  9073. buffer[ offset ++ ] = source[ i ];
  9074. }
  9075. },
  9076. function getValue_arrayElement( buffer, offset ) {
  9077. buffer[ offset ] = this.resolvedProperty[ this.propertyIndex ];
  9078. },
  9079. function getValue_toArray( buffer, offset ) {
  9080. this.resolvedProperty.toArray( buffer, offset );
  9081. }
  9082. ],
  9083. SetterByBindingTypeAndVersioning: [
  9084. [
  9085. // Direct
  9086. function setValue_direct( buffer, offset ) {
  9087. this.node[ this.propertyName ] = buffer[ offset ];
  9088. },
  9089. function setValue_direct_setNeedsUpdate( buffer, offset ) {
  9090. this.node[ this.propertyName ] = buffer[ offset ];
  9091. this.targetObject.needsUpdate = true;
  9092. },
  9093. function setValue_direct_setMatrixWorldNeedsUpdate( buffer, offset ) {
  9094. this.node[ this.propertyName ] = buffer[ offset ];
  9095. this.targetObject.matrixWorldNeedsUpdate = true;
  9096. }
  9097. ], [
  9098. // EntireArray
  9099. function setValue_array( buffer, offset ) {
  9100. var dest = this.resolvedProperty;
  9101. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  9102. dest[ i ] = buffer[ offset ++ ];
  9103. }
  9104. },
  9105. function setValue_array_setNeedsUpdate( buffer, offset ) {
  9106. var dest = this.resolvedProperty;
  9107. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  9108. dest[ i ] = buffer[ offset ++ ];
  9109. }
  9110. this.targetObject.needsUpdate = true;
  9111. },
  9112. function setValue_array_setMatrixWorldNeedsUpdate( buffer, offset ) {
  9113. var dest = this.resolvedProperty;
  9114. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  9115. dest[ i ] = buffer[ offset ++ ];
  9116. }
  9117. this.targetObject.matrixWorldNeedsUpdate = true;
  9118. }
  9119. ], [
  9120. // ArrayElement
  9121. function setValue_arrayElement( buffer, offset ) {
  9122. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  9123. },
  9124. function setValue_arrayElement_setNeedsUpdate( buffer, offset ) {
  9125. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  9126. this.targetObject.needsUpdate = true;
  9127. },
  9128. function setValue_arrayElement_setMatrixWorldNeedsUpdate( buffer, offset ) {
  9129. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  9130. this.targetObject.matrixWorldNeedsUpdate = true;
  9131. }
  9132. ], [
  9133. // HasToFromArray
  9134. function setValue_fromArray( buffer, offset ) {
  9135. this.resolvedProperty.fromArray( buffer, offset );
  9136. },
  9137. function setValue_fromArray_setNeedsUpdate( buffer, offset ) {
  9138. this.resolvedProperty.fromArray( buffer, offset );
  9139. this.targetObject.needsUpdate = true;
  9140. },
  9141. function setValue_fromArray_setMatrixWorldNeedsUpdate( buffer, offset ) {
  9142. this.resolvedProperty.fromArray( buffer, offset );
  9143. this.targetObject.matrixWorldNeedsUpdate = true;
  9144. }
  9145. ]
  9146. ]
  9147. } );
  9148. THREE.PropertyBinding.Composite =
  9149. function( targetGroup, path, optionalParsedPath ) {
  9150. var parsedPath = optionalParsedPath ||
  9151. THREE.PropertyBinding.parseTrackName( path );
  9152. this._targetGroup = targetGroup;
  9153. this._bindings = targetGroup.subscribe_( path, parsedPath );
  9154. };
  9155. THREE.PropertyBinding.Composite.prototype = {
  9156. constructor: THREE.PropertyBinding.Composite,
  9157. getValue: function( array, offset ) {
  9158. this.bind(); // bind all binding
  9159. var firstValidIndex = this._targetGroup.nCachedObjects_,
  9160. binding = this._bindings[ firstValidIndex ];
  9161. // and only call .getValue on the first
  9162. if ( binding !== undefined ) binding.getValue( array, offset );
  9163. },
  9164. setValue: function( array, offset ) {
  9165. var bindings = this._bindings;
  9166. for ( var i = this._targetGroup.nCachedObjects_,
  9167. n = bindings.length; i !== n; ++ i ) {
  9168. bindings[ i ].setValue( array, offset );
  9169. }
  9170. },
  9171. bind: function() {
  9172. var bindings = this._bindings;
  9173. for ( var i = this._targetGroup.nCachedObjects_,
  9174. n = bindings.length; i !== n; ++ i ) {
  9175. bindings[ i ].bind();
  9176. }
  9177. },
  9178. unbind: function() {
  9179. var bindings = this._bindings;
  9180. for ( var i = this._targetGroup.nCachedObjects_,
  9181. n = bindings.length; i !== n; ++ i ) {
  9182. bindings[ i ].unbind();
  9183. }
  9184. }
  9185. };
  9186. THREE.PropertyBinding.create = function( root, path, parsedPath ) {
  9187. if ( ! ( root instanceof THREE.AnimationObjectGroup ) ) {
  9188. return new THREE.PropertyBinding( root, path, parsedPath );
  9189. } else {
  9190. return new THREE.PropertyBinding.Composite( root, path, parsedPath );
  9191. }
  9192. };
  9193. THREE.PropertyBinding.parseTrackName = function( trackName ) {
  9194. // matches strings in the form of:
  9195. // nodeName.property
  9196. // nodeName.property[accessor]
  9197. // nodeName.material.property[accessor]
  9198. // uuid.property[accessor]
  9199. // uuid.objectName[objectIndex].propertyName[propertyIndex]
  9200. // parentName/nodeName.property
  9201. // parentName/parentName/nodeName.property[index]
  9202. // .bone[Armature.DEF_cog].position
  9203. // created and tested via https://regex101.com/#javascript
  9204. var re = /^(([\w]+\/)*)([\w-\d]+)?(\.([\w]+)(\[([\w\d\[\]\_.:\- ]+)\])?)?(\.([\w.]+)(\[([\w\d\[\]\_. ]+)\])?)$/;
  9205. var matches = re.exec(trackName);
  9206. if( ! matches ) {
  9207. throw new Error( "cannot parse trackName at all: " + trackName );
  9208. }
  9209. if (matches.index === re.lastIndex) {
  9210. re.lastIndex++;
  9211. }
  9212. var results = {
  9213. // directoryName: matches[1], // (tschw) currently unused
  9214. nodeName: matches[3], // allowed to be null, specified root node.
  9215. objectName: matches[5],
  9216. objectIndex: matches[7],
  9217. propertyName: matches[9],
  9218. propertyIndex: matches[11] // allowed to be null, specifies that the whole property is set.
  9219. };
  9220. if( results.propertyName === null || results.propertyName.length === 0 ) {
  9221. throw new Error( "can not parse propertyName from trackName: " + trackName );
  9222. }
  9223. return results;
  9224. };
  9225. THREE.PropertyBinding.findNode = function( root, nodeName ) {
  9226. if( ! nodeName || nodeName === "" || nodeName === "root" || nodeName === "." || nodeName === -1 || nodeName === root.name || nodeName === root.uuid ) {
  9227. return root;
  9228. }
  9229. // search into skeleton bones.
  9230. if( root.skeleton ) {
  9231. var searchSkeleton = function( skeleton ) {
  9232. for( var i = 0; i < skeleton.bones.length; i ++ ) {
  9233. var bone = skeleton.bones[i];
  9234. if( bone.name === nodeName ) {
  9235. return bone;
  9236. }
  9237. }
  9238. return null;
  9239. };
  9240. var bone = searchSkeleton( root.skeleton );
  9241. if( bone ) {
  9242. return bone;
  9243. }
  9244. }
  9245. // search into node subtree.
  9246. if( root.children ) {
  9247. var searchNodeSubtree = function( children ) {
  9248. for( var i = 0; i < children.length; i ++ ) {
  9249. var childNode = children[i];
  9250. if( childNode.name === nodeName || childNode.uuid === nodeName ) {
  9251. return childNode;
  9252. }
  9253. var result = searchNodeSubtree( childNode.children );
  9254. if( result ) return result;
  9255. }
  9256. return null;
  9257. };
  9258. var subTreeNode = searchNodeSubtree( root.children );
  9259. if( subTreeNode ) {
  9260. return subTreeNode;
  9261. }
  9262. }
  9263. return null;
  9264. }
  9265. // File:src/animation/PropertyMixer.js
  9266. /**
  9267. *
  9268. * Buffered scene graph property that allows weighted accumulation.
  9269. *
  9270. *
  9271. * @author Ben Houston / http://clara.io/
  9272. * @author David Sarno / http://lighthaus.us/
  9273. * @author tschw
  9274. */
  9275. THREE.PropertyMixer = function ( binding, typeName, valueSize ) {
  9276. this.binding = binding;
  9277. this.valueSize = valueSize;
  9278. var bufferType = Float64Array,
  9279. mixFunction;
  9280. switch ( typeName ) {
  9281. case 'quaternion': mixFunction = this._slerp; break;
  9282. case 'string':
  9283. case 'bool':
  9284. bufferType = Array, mixFunction = this._select; break;
  9285. default: mixFunction = this._lerp;
  9286. }
  9287. this.buffer = new bufferType( valueSize * 4 );
  9288. // layout: [ incoming | accu0 | accu1 | orig ]
  9289. //
  9290. // interpolators can use .buffer as their .result
  9291. // the data then goes to 'incoming'
  9292. //
  9293. // 'accu0' and 'accu1' are used frame-interleaved for
  9294. // the cumulative result and are compared to detect
  9295. // changes
  9296. //
  9297. // 'orig' stores the original state of the property
  9298. this._mixBufferRegion = mixFunction;
  9299. this.cumulativeWeight = 0;
  9300. this.useCount = 0;
  9301. this.referenceCount = 0;
  9302. };
  9303. THREE.PropertyMixer.prototype = {
  9304. constructor: THREE.PropertyMixer,
  9305. // accumulate data in the 'incoming' region into 'accu<i>'
  9306. accumulate: function( accuIndex, weight ) {
  9307. // note: happily accumulating nothing when weight = 0, the caller knows
  9308. // the weight and shouldn't have made the call in the first place
  9309. var buffer = this.buffer,
  9310. stride = this.valueSize,
  9311. offset = accuIndex * stride + stride,
  9312. currentWeight = this.cumulativeWeight;
  9313. if ( currentWeight === 0 ) {
  9314. // accuN := incoming * weight
  9315. for ( var i = 0; i !== stride; ++ i ) {
  9316. buffer[ offset + i ] = buffer[ i ];
  9317. }
  9318. currentWeight = weight;
  9319. } else {
  9320. // accuN := accuN + incoming * weight
  9321. currentWeight += weight;
  9322. var mix = weight / currentWeight;
  9323. this._mixBufferRegion( buffer, offset, 0, mix, stride );
  9324. }
  9325. this.cumulativeWeight = currentWeight;
  9326. },
  9327. // apply the state of 'accu<i>' to the binding when accus differ
  9328. apply: function( accuIndex ) {
  9329. var stride = this.valueSize,
  9330. buffer = this.buffer,
  9331. offset = accuIndex * stride + stride,
  9332. weight = this.cumulativeWeight,
  9333. binding = this.binding;
  9334. this.cumulativeWeight = 0;
  9335. if ( weight < 1 ) {
  9336. // accuN := accuN + original * ( 1 - cumulativeWeight )
  9337. var originalValueOffset = stride * 3;
  9338. this._mixBufferRegion(
  9339. buffer, offset, originalValueOffset, 1 - weight, stride );
  9340. }
  9341. for ( var i = stride, e = stride + stride; i !== e; ++ i ) {
  9342. if ( buffer[ i ] !== buffer[ i + stride ] ) {
  9343. // value has changed -> update scene graph
  9344. binding.setValue( buffer, offset );
  9345. break;
  9346. }
  9347. }
  9348. },
  9349. // remember the state of the bound property and copy it to both accus
  9350. saveOriginalState: function() {
  9351. var binding = this.binding;
  9352. var buffer = this.buffer,
  9353. stride = this.valueSize,
  9354. originalValueOffset = stride * 3;
  9355. binding.getValue( buffer, originalValueOffset );
  9356. // accu[0..1] := orig -- initially detect changes against the original
  9357. for ( var i = stride, e = originalValueOffset; i !== e; ++ i ) {
  9358. buffer[ i ] = buffer[ originalValueOffset + ( i % stride ) ];
  9359. }
  9360. this.cumulativeWeight = 0;
  9361. },
  9362. // apply the state previously taken via 'saveOriginalState' to the binding
  9363. restoreOriginalState: function() {
  9364. var originalValueOffset = this.valueSize * 3;
  9365. this.binding.setValue( this.buffer, originalValueOffset );
  9366. },
  9367. // mix functions
  9368. _select: function( buffer, dstOffset, srcOffset, t, stride ) {
  9369. if ( t >= 0.5 ) {
  9370. for ( var i = 0; i !== stride; ++ i ) {
  9371. buffer[ dstOffset + i ] = buffer[ srcOffset + i ];
  9372. }
  9373. }
  9374. },
  9375. _slerp: function( buffer, dstOffset, srcOffset, t, stride ) {
  9376. THREE.Quaternion.slerpFlat( buffer, dstOffset,
  9377. buffer, dstOffset, buffer, srcOffset, t );
  9378. },
  9379. _lerp: function( buffer, dstOffset, srcOffset, t, stride ) {
  9380. var s = 1 - t;
  9381. for ( var i = 0; i !== stride; ++ i ) {
  9382. var j = dstOffset + i;
  9383. buffer[ j ] = buffer[ j ] * s + buffer[ srcOffset + i ] * t;
  9384. }
  9385. }
  9386. };
  9387. // File:src/animation/tracks/BooleanKeyframeTrack.js
  9388. /**
  9389. *
  9390. * A Track of Boolean keyframe values.
  9391. *
  9392. *
  9393. * @author Ben Houston / http://clara.io/
  9394. * @author David Sarno / http://lighthaus.us/
  9395. * @author tschw
  9396. */
  9397. THREE.BooleanKeyframeTrack = function ( name, times, values ) {
  9398. THREE.KeyframeTrack.call( this, name, times, values );
  9399. };
  9400. THREE.BooleanKeyframeTrack.prototype =
  9401. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9402. constructor: THREE.BooleanKeyframeTrack,
  9403. ValueTypeName: 'bool',
  9404. ValueBufferType: Array,
  9405. DefaultInterpolation: THREE.IntepolateDiscrete,
  9406. InterpolantFactoryMethodLinear: undefined,
  9407. InterpolantFactoryMethodSmooth: undefined
  9408. // Note: Actually this track could have a optimized / compressed
  9409. // representation of a single value and a custom interpolant that
  9410. // computes "firstValue ^ isOdd( index )".
  9411. } );
  9412. // File:src/animation/tracks/NumberKeyframeTrack.js
  9413. /**
  9414. *
  9415. * A Track of numeric keyframe values.
  9416. *
  9417. * @author Ben Houston / http://clara.io/
  9418. * @author David Sarno / http://lighthaus.us/
  9419. * @author tschw
  9420. */
  9421. THREE.NumberKeyframeTrack = function ( name, times, values, interpolation ) {
  9422. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9423. };
  9424. THREE.NumberKeyframeTrack.prototype =
  9425. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9426. constructor: THREE.NumberKeyframeTrack,
  9427. ValueTypeName: 'number',
  9428. // ValueBufferType is inherited
  9429. // DefaultInterpolation is inherited
  9430. } );
  9431. // File:src/animation/tracks/QuaternionKeyframeTrack.js
  9432. /**
  9433. *
  9434. * A Track of quaternion keyframe values.
  9435. *
  9436. * @author Ben Houston / http://clara.io/
  9437. * @author David Sarno / http://lighthaus.us/
  9438. * @author tschw
  9439. */
  9440. THREE.QuaternionKeyframeTrack = function ( name, times, values, interpolation ) {
  9441. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9442. };
  9443. THREE.QuaternionKeyframeTrack.prototype =
  9444. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9445. constructor: THREE.QuaternionKeyframeTrack,
  9446. ValueTypeName: 'quaternion',
  9447. // ValueBufferType is inherited
  9448. DefaultInterpolation: THREE.InterpolateLinear,
  9449. InterpolantFactoryMethodLinear: function( result ) {
  9450. return new THREE.QuaternionLinearInterpolant(
  9451. this.times, this.values, this.getValueSize(), result );
  9452. },
  9453. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  9454. } );
  9455. // File:src/animation/tracks/StringKeyframeTrack.js
  9456. /**
  9457. *
  9458. * A Track that interpolates Strings
  9459. *
  9460. *
  9461. * @author Ben Houston / http://clara.io/
  9462. * @author David Sarno / http://lighthaus.us/
  9463. * @author tschw
  9464. */
  9465. THREE.StringKeyframeTrack = function ( name, times, values, interpolation ) {
  9466. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9467. };
  9468. THREE.StringKeyframeTrack.prototype =
  9469. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9470. constructor: THREE.StringKeyframeTrack,
  9471. ValueTypeName: 'string',
  9472. ValueBufferType: Array,
  9473. DefaultInterpolation: THREE.IntepolateDiscrete,
  9474. InterpolantFactoryMethodLinear: undefined,
  9475. InterpolantFactoryMethodSmooth: undefined
  9476. } );
  9477. // File:src/animation/tracks/VectorKeyframeTrack.js
  9478. /**
  9479. *
  9480. * A Track of vectored keyframe values.
  9481. *
  9482. *
  9483. * @author Ben Houston / http://clara.io/
  9484. * @author David Sarno / http://lighthaus.us/
  9485. * @author tschw
  9486. */
  9487. THREE.VectorKeyframeTrack = function ( name, times, values, interpolation ) {
  9488. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9489. };
  9490. THREE.VectorKeyframeTrack.prototype =
  9491. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9492. constructor: THREE.VectorKeyframeTrack,
  9493. ValueTypeName: 'vector'
  9494. // ValueBufferType is inherited
  9495. // DefaultInterpolation is inherited
  9496. } );
  9497. // File:src/audio/Audio.js
  9498. /**
  9499. * @author mrdoob / http://mrdoob.com/
  9500. */
  9501. THREE.Audio = function ( listener ) {
  9502. THREE.Object3D.call( this );
  9503. this.type = 'Audio';
  9504. this.context = listener.context;
  9505. this.source = this.context.createBufferSource();
  9506. this.source.onended = this.onEnded.bind( this );
  9507. this.gain = this.context.createGain();
  9508. this.gain.connect( listener.getInput() );
  9509. this.autoplay = false;
  9510. this.startTime = 0;
  9511. this.playbackRate = 1;
  9512. this.isPlaying = false;
  9513. this.hasPlaybackControl = true;
  9514. this.sourceType = 'empty';
  9515. this.filter = null;
  9516. };
  9517. THREE.Audio.prototype = Object.create( THREE.Object3D.prototype );
  9518. THREE.Audio.prototype.constructor = THREE.Audio;
  9519. THREE.Audio.prototype.getOutput = function () {
  9520. return this.gain;
  9521. };
  9522. THREE.Audio.prototype.load = function ( file ) {
  9523. var buffer = new THREE.AudioBuffer( this.context );
  9524. buffer.load( file );
  9525. this.setBuffer( buffer );
  9526. return this;
  9527. };
  9528. THREE.Audio.prototype.setNodeSource = function ( audioNode ) {
  9529. this.hasPlaybackControl = false;
  9530. this.sourceType = 'audioNode';
  9531. this.source = audioNode;
  9532. this.connect();
  9533. return this;
  9534. };
  9535. THREE.Audio.prototype.setBuffer = function ( audioBuffer ) {
  9536. var scope = this;
  9537. audioBuffer.onReady( function( buffer ) {
  9538. scope.source.buffer = buffer;
  9539. scope.sourceType = 'buffer';
  9540. if ( scope.autoplay ) scope.play();
  9541. } );
  9542. return this;
  9543. };
  9544. THREE.Audio.prototype.play = function () {
  9545. if ( this.isPlaying === true ) {
  9546. console.warn( 'THREE.Audio: Audio is already playing.' );
  9547. return;
  9548. }
  9549. if ( this.hasPlaybackControl === false ) {
  9550. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9551. return;
  9552. }
  9553. var source = this.context.createBufferSource();
  9554. source.buffer = this.source.buffer;
  9555. source.loop = this.source.loop;
  9556. source.onended = this.source.onended;
  9557. source.start( 0, this.startTime );
  9558. source.playbackRate.value = this.playbackRate;
  9559. this.isPlaying = true;
  9560. this.source = source;
  9561. this.connect();
  9562. };
  9563. THREE.Audio.prototype.pause = function () {
  9564. if ( this.hasPlaybackControl === false ) {
  9565. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9566. return;
  9567. }
  9568. this.source.stop();
  9569. this.startTime = this.context.currentTime;
  9570. };
  9571. THREE.Audio.prototype.stop = function () {
  9572. if ( this.hasPlaybackControl === false ) {
  9573. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9574. return;
  9575. }
  9576. this.source.stop();
  9577. this.startTime = 0;
  9578. };
  9579. THREE.Audio.prototype.connect = function () {
  9580. if ( this.filter !== null ) {
  9581. this.source.connect( this.filter );
  9582. this.filter.connect( this.getOutput() );
  9583. } else {
  9584. this.source.connect( this.getOutput() );
  9585. }
  9586. };
  9587. THREE.Audio.prototype.disconnect = function () {
  9588. if ( this.filter !== null ) {
  9589. this.source.disconnect( this.filter );
  9590. this.filter.disconnect( this.getOutput() );
  9591. } else {
  9592. this.source.disconnect( this.getOutput() );
  9593. }
  9594. };
  9595. THREE.Audio.prototype.getFilter = function () {
  9596. return this.filter;
  9597. };
  9598. THREE.Audio.prototype.setFilter = function ( value ) {
  9599. if ( value === undefined ) value = null;
  9600. if ( this.isPlaying === true ) {
  9601. this.disconnect();
  9602. this.filter = value;
  9603. this.connect();
  9604. } else {
  9605. this.filter = value;
  9606. }
  9607. };
  9608. THREE.Audio.prototype.setPlaybackRate = function ( value ) {
  9609. if ( this.hasPlaybackControl === false ) {
  9610. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9611. return;
  9612. }
  9613. this.playbackRate = value;
  9614. if ( this.isPlaying === true ) {
  9615. this.source.playbackRate.value = this.playbackRate;
  9616. }
  9617. };
  9618. THREE.Audio.prototype.getPlaybackRate = function () {
  9619. return this.playbackRate;
  9620. };
  9621. THREE.Audio.prototype.onEnded = function() {
  9622. this.isPlaying = false;
  9623. };
  9624. THREE.Audio.prototype.setLoop = function ( value ) {
  9625. if ( this.hasPlaybackControl === false ) {
  9626. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9627. return;
  9628. }
  9629. this.source.loop = value;
  9630. };
  9631. THREE.Audio.prototype.getLoop = function () {
  9632. if ( this.hasPlaybackControl === false ) {
  9633. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9634. return false;
  9635. }
  9636. return this.source.loop;
  9637. };
  9638. THREE.Audio.prototype.setVolume = function ( value ) {
  9639. this.gain.gain.value = value;
  9640. };
  9641. THREE.Audio.prototype.getVolume = function () {
  9642. return this.gain.gain.value;
  9643. };
  9644. // File:src/audio/AudioAnalyser.js
  9645. /**
  9646. * @author mrdoob / http://mrdoob.com/
  9647. */
  9648. THREE.AudioAnalyser = function ( audio, fftSize ) {
  9649. this.analyser = audio.context.createAnalyser();
  9650. this.analyser.fftSize = fftSize !== undefined ? fftSize : 2048;
  9651. this.data = new Uint8Array( this.analyser.frequencyBinCount );
  9652. audio.getOutput().connect( this.analyser );
  9653. };
  9654. THREE.AudioAnalyser.prototype = {
  9655. constructor: THREE.AudioAnalyser,
  9656. getData: function () {
  9657. this.analyser.getByteFrequencyData( this.data );
  9658. return this.data;
  9659. }
  9660. };
  9661. // File:src/audio/AudioBuffer.js
  9662. /**
  9663. * @author mrdoob / http://mrdoob.com/
  9664. */
  9665. THREE.AudioBuffer = function ( context ) {
  9666. this.context = context;
  9667. this.ready = false;
  9668. this.readyCallbacks = [];
  9669. };
  9670. THREE.AudioBuffer.prototype.load = function ( file ) {
  9671. var scope = this;
  9672. var request = new XMLHttpRequest();
  9673. request.open( 'GET', file, true );
  9674. request.responseType = 'arraybuffer';
  9675. request.onload = function ( e ) {
  9676. scope.context.decodeAudioData( this.response, function ( buffer ) {
  9677. scope.buffer = buffer;
  9678. scope.ready = true;
  9679. for ( var i = 0; i < scope.readyCallbacks.length; i ++ ) {
  9680. scope.readyCallbacks[ i ]( scope.buffer );
  9681. }
  9682. scope.readyCallbacks = [];
  9683. } );
  9684. };
  9685. request.send();
  9686. return this;
  9687. };
  9688. THREE.AudioBuffer.prototype.onReady = function ( callback ) {
  9689. if ( this.ready ) {
  9690. callback( this.buffer );
  9691. } else {
  9692. this.readyCallbacks.push( callback );
  9693. }
  9694. };
  9695. // File:src/audio/PositionalAudio.js
  9696. /**
  9697. * @author mrdoob / http://mrdoob.com/
  9698. */
  9699. THREE.PositionalAudio = function ( listener ) {
  9700. THREE.Audio.call( this, listener );
  9701. this.panner = this.context.createPanner();
  9702. this.panner.connect( this.gain );
  9703. };
  9704. THREE.PositionalAudio.prototype = Object.create( THREE.Audio.prototype );
  9705. THREE.PositionalAudio.prototype.constructor = THREE.PositionalAudio;
  9706. THREE.PositionalAudio.prototype.getOutput = function () {
  9707. return this.panner;
  9708. };
  9709. THREE.PositionalAudio.prototype.setRefDistance = function ( value ) {
  9710. this.panner.refDistance = value;
  9711. };
  9712. THREE.PositionalAudio.prototype.getRefDistance = function () {
  9713. return this.panner.refDistance;
  9714. };
  9715. THREE.PositionalAudio.prototype.setRolloffFactor = function ( value ) {
  9716. this.panner.rolloffFactor = value;
  9717. };
  9718. THREE.PositionalAudio.prototype.getRolloffFactor = function () {
  9719. return this.panner.rolloffFactor;
  9720. };
  9721. THREE.PositionalAudio.prototype.setDistanceModel = function ( value ) {
  9722. this.panner.distanceModel = value;
  9723. };
  9724. THREE.PositionalAudio.prototype.getDistanceModel = function () {
  9725. return this.panner.distanceModel;
  9726. };
  9727. THREE.PositionalAudio.prototype.setMaxDistance = function ( value ) {
  9728. this.panner.maxDistance = value;
  9729. };
  9730. THREE.PositionalAudio.prototype.getMaxDistance = function () {
  9731. return this.panner.maxDistance;
  9732. };
  9733. THREE.PositionalAudio.prototype.updateMatrixWorld = ( function () {
  9734. var position = new THREE.Vector3();
  9735. return function updateMatrixWorld( force ) {
  9736. THREE.Object3D.prototype.updateMatrixWorld.call( this, force );
  9737. position.setFromMatrixPosition( this.matrixWorld );
  9738. this.panner.setPosition( position.x, position.y, position.z );
  9739. };
  9740. } )();
  9741. // File:src/audio/AudioListener.js
  9742. /**
  9743. * @author mrdoob / http://mrdoob.com/
  9744. */
  9745. THREE.AudioListener = function () {
  9746. THREE.Object3D.call( this );
  9747. this.type = 'AudioListener';
  9748. this.context = new ( window.AudioContext || window.webkitAudioContext )();
  9749. this.gain = this.context.createGain();
  9750. this.gain.connect( this.context.destination );
  9751. this.filter = null;
  9752. };
  9753. THREE.AudioListener.prototype = Object.create( THREE.Object3D.prototype );
  9754. THREE.AudioListener.prototype.constructor = THREE.AudioListener;
  9755. THREE.AudioListener.prototype.getInput = function () {
  9756. return this.gain;
  9757. };
  9758. THREE.AudioListener.prototype.removeFilter = function ( ) {
  9759. if ( this.filter !== null ) {
  9760. this.gain.disconnect( this.filter );
  9761. this.filter.disconnect( this.context.destination );
  9762. this.gain.connect( this.context.destination );
  9763. this.filter = null;
  9764. }
  9765. };
  9766. THREE.AudioListener.prototype.setFilter = function ( value ) {
  9767. if ( this.filter !== null ) {
  9768. this.gain.disconnect( this.filter );
  9769. this.filter.disconnect( this.context.destination );
  9770. } else {
  9771. this.gain.disconnect( this.context.destination );
  9772. }
  9773. this.filter = value;
  9774. this.gain.connect( this.filter );
  9775. this.filter.connect( this.context.destination );
  9776. };
  9777. THREE.AudioListener.prototype.getFilter = function () {
  9778. return this.filter;
  9779. };
  9780. THREE.AudioListener.prototype.setMasterVolume = function ( value ) {
  9781. this.gain.gain.value = value;
  9782. };
  9783. THREE.AudioListener.prototype.getMasterVolume = function () {
  9784. return this.gain.gain.value;
  9785. };
  9786. THREE.AudioListener.prototype.updateMatrixWorld = ( function () {
  9787. var position = new THREE.Vector3();
  9788. var quaternion = new THREE.Quaternion();
  9789. var scale = new THREE.Vector3();
  9790. var orientation = new THREE.Vector3();
  9791. return function updateMatrixWorld( force ) {
  9792. THREE.Object3D.prototype.updateMatrixWorld.call( this, force );
  9793. var listener = this.context.listener;
  9794. var up = this.up;
  9795. this.matrixWorld.decompose( position, quaternion, scale );
  9796. orientation.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  9797. listener.setPosition( position.x, position.y, position.z );
  9798. listener.setOrientation( orientation.x, orientation.y, orientation.z, up.x, up.y, up.z );
  9799. };
  9800. } )();
  9801. // File:src/cameras/Camera.js
  9802. /**
  9803. * @author mrdoob / http://mrdoob.com/
  9804. * @author mikael emtinger / http://gomo.se/
  9805. * @author WestLangley / http://github.com/WestLangley
  9806. */
  9807. THREE.Camera = function () {
  9808. THREE.Object3D.call( this );
  9809. this.type = 'Camera';
  9810. this.matrixWorldInverse = new THREE.Matrix4();
  9811. this.projectionMatrix = new THREE.Matrix4();
  9812. };
  9813. THREE.Camera.prototype = Object.create( THREE.Object3D.prototype );
  9814. THREE.Camera.prototype.constructor = THREE.Camera;
  9815. THREE.Camera.prototype.getWorldDirection = function () {
  9816. var quaternion = new THREE.Quaternion();
  9817. return function ( optionalTarget ) {
  9818. var result = optionalTarget || new THREE.Vector3();
  9819. this.getWorldQuaternion( quaternion );
  9820. return result.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  9821. };
  9822. }();
  9823. THREE.Camera.prototype.lookAt = function () {
  9824. // This routine does not support cameras with rotated and/or translated parent(s)
  9825. var m1 = new THREE.Matrix4();
  9826. return function ( vector ) {
  9827. m1.lookAt( this.position, vector, this.up );
  9828. this.quaternion.setFromRotationMatrix( m1 );
  9829. };
  9830. }();
  9831. THREE.Camera.prototype.clone = function () {
  9832. return new this.constructor().copy( this );
  9833. };
  9834. THREE.Camera.prototype.copy = function ( source ) {
  9835. THREE.Object3D.prototype.copy.call( this, source );
  9836. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  9837. this.projectionMatrix.copy( source.projectionMatrix );
  9838. return this;
  9839. };
  9840. // File:src/cameras/CubeCamera.js
  9841. /**
  9842. * Camera for rendering cube maps
  9843. * - renders scene into axis-aligned cube
  9844. *
  9845. * @author alteredq / http://alteredqualia.com/
  9846. */
  9847. THREE.CubeCamera = function ( near, far, cubeResolution ) {
  9848. THREE.Object3D.call( this );
  9849. this.type = 'CubeCamera';
  9850. var fov = 90, aspect = 1;
  9851. var cameraPX = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9852. cameraPX.up.set( 0, - 1, 0 );
  9853. cameraPX.lookAt( new THREE.Vector3( 1, 0, 0 ) );
  9854. this.add( cameraPX );
  9855. var cameraNX = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9856. cameraNX.up.set( 0, - 1, 0 );
  9857. cameraNX.lookAt( new THREE.Vector3( - 1, 0, 0 ) );
  9858. this.add( cameraNX );
  9859. var cameraPY = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9860. cameraPY.up.set( 0, 0, 1 );
  9861. cameraPY.lookAt( new THREE.Vector3( 0, 1, 0 ) );
  9862. this.add( cameraPY );
  9863. var cameraNY = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9864. cameraNY.up.set( 0, 0, - 1 );
  9865. cameraNY.lookAt( new THREE.Vector3( 0, - 1, 0 ) );
  9866. this.add( cameraNY );
  9867. var cameraPZ = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9868. cameraPZ.up.set( 0, - 1, 0 );
  9869. cameraPZ.lookAt( new THREE.Vector3( 0, 0, 1 ) );
  9870. this.add( cameraPZ );
  9871. var cameraNZ = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9872. cameraNZ.up.set( 0, - 1, 0 );
  9873. cameraNZ.lookAt( new THREE.Vector3( 0, 0, - 1 ) );
  9874. this.add( cameraNZ );
  9875. var options = { format: THREE.RGBFormat, magFilter: THREE.LinearFilter, minFilter: THREE.LinearFilter };
  9876. this.renderTarget = new THREE.WebGLRenderTargetCube( cubeResolution, cubeResolution, options );
  9877. this.updateCubeMap = function ( renderer, scene ) {
  9878. if ( this.parent === null ) this.updateMatrixWorld();
  9879. var renderTarget = this.renderTarget;
  9880. var generateMipmaps = renderTarget.texture.generateMipmaps;
  9881. renderTarget.texture.generateMipmaps = false;
  9882. renderTarget.activeCubeFace = 0;
  9883. renderer.render( scene, cameraPX, renderTarget );
  9884. renderTarget.activeCubeFace = 1;
  9885. renderer.render( scene, cameraNX, renderTarget );
  9886. renderTarget.activeCubeFace = 2;
  9887. renderer.render( scene, cameraPY, renderTarget );
  9888. renderTarget.activeCubeFace = 3;
  9889. renderer.render( scene, cameraNY, renderTarget );
  9890. renderTarget.activeCubeFace = 4;
  9891. renderer.render( scene, cameraPZ, renderTarget );
  9892. renderTarget.texture.generateMipmaps = generateMipmaps;
  9893. renderTarget.activeCubeFace = 5;
  9894. renderer.render( scene, cameraNZ, renderTarget );
  9895. renderer.setRenderTarget( null );
  9896. };
  9897. };
  9898. THREE.CubeCamera.prototype = Object.create( THREE.Object3D.prototype );
  9899. THREE.CubeCamera.prototype.constructor = THREE.CubeCamera;
  9900. // File:src/cameras/OrthographicCamera.js
  9901. /**
  9902. * @author alteredq / http://alteredqualia.com/
  9903. */
  9904. THREE.OrthographicCamera = function ( left, right, top, bottom, near, far ) {
  9905. THREE.Camera.call( this );
  9906. this.type = 'OrthographicCamera';
  9907. this.zoom = 1;
  9908. this.left = left;
  9909. this.right = right;
  9910. this.top = top;
  9911. this.bottom = bottom;
  9912. this.near = ( near !== undefined ) ? near : 0.1;
  9913. this.far = ( far !== undefined ) ? far : 2000;
  9914. this.updateProjectionMatrix();
  9915. };
  9916. THREE.OrthographicCamera.prototype = Object.create( THREE.Camera.prototype );
  9917. THREE.OrthographicCamera.prototype.constructor = THREE.OrthographicCamera;
  9918. THREE.OrthographicCamera.prototype.updateProjectionMatrix = function () {
  9919. var dx = ( this.right - this.left ) / ( 2 * this.zoom );
  9920. var dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  9921. var cx = ( this.right + this.left ) / 2;
  9922. var cy = ( this.top + this.bottom ) / 2;
  9923. this.projectionMatrix.makeOrthographic( cx - dx, cx + dx, cy + dy, cy - dy, this.near, this.far );
  9924. };
  9925. THREE.OrthographicCamera.prototype.copy = function ( source ) {
  9926. THREE.Camera.prototype.copy.call( this, source );
  9927. this.left = source.left;
  9928. this.right = source.right;
  9929. this.top = source.top;
  9930. this.bottom = source.bottom;
  9931. this.near = source.near;
  9932. this.far = source.far;
  9933. this.zoom = source.zoom;
  9934. return this;
  9935. };
  9936. THREE.OrthographicCamera.prototype.toJSON = function ( meta ) {
  9937. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  9938. data.object.zoom = this.zoom;
  9939. data.object.left = this.left;
  9940. data.object.right = this.right;
  9941. data.object.top = this.top;
  9942. data.object.bottom = this.bottom;
  9943. data.object.near = this.near;
  9944. data.object.far = this.far;
  9945. return data;
  9946. };
  9947. // File:src/cameras/PerspectiveCamera.js
  9948. /**
  9949. * @author mrdoob / http://mrdoob.com/
  9950. * @author greggman / http://games.greggman.com/
  9951. * @author zz85 / http://www.lab4games.net/zz85/blog
  9952. */
  9953. THREE.PerspectiveCamera = function ( fov, aspect, near, far ) {
  9954. THREE.Camera.call( this );
  9955. this.type = 'PerspectiveCamera';
  9956. this.focalLength = 10;
  9957. this.zoom = 1;
  9958. this.fov = fov !== undefined ? fov : 50;
  9959. this.aspect = aspect !== undefined ? aspect : 1;
  9960. this.near = near !== undefined ? near : 0.1;
  9961. this.far = far !== undefined ? far : 2000;
  9962. this.updateProjectionMatrix();
  9963. };
  9964. THREE.PerspectiveCamera.prototype = Object.create( THREE.Camera.prototype );
  9965. THREE.PerspectiveCamera.prototype.constructor = THREE.PerspectiveCamera;
  9966. /**
  9967. * Uses Focal Length (in mm) to estimate and set FOV
  9968. * 35mm (full-frame) camera is used if frame size is not specified;
  9969. * Formula based on http://www.bobatkins.com/photography/technical/field_of_view.html
  9970. */
  9971. THREE.PerspectiveCamera.prototype.setLens = function ( focalLength, frameHeight ) {
  9972. if ( frameHeight === undefined ) frameHeight = 24;
  9973. this.fov = 2 * THREE.Math.radToDeg( Math.atan( frameHeight / ( focalLength * 2 ) ) );
  9974. this.updateProjectionMatrix();
  9975. };
  9976. /**
  9977. * Sets an offset in a larger frustum. This is useful for multi-window or
  9978. * multi-monitor/multi-machine setups.
  9979. *
  9980. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  9981. * the monitors are in grid like this
  9982. *
  9983. * +---+---+---+
  9984. * | A | B | C |
  9985. * +---+---+---+
  9986. * | D | E | F |
  9987. * +---+---+---+
  9988. *
  9989. * then for each monitor you would call it like this
  9990. *
  9991. * var w = 1920;
  9992. * var h = 1080;
  9993. * var fullWidth = w * 3;
  9994. * var fullHeight = h * 2;
  9995. *
  9996. * --A--
  9997. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  9998. * --B--
  9999. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  10000. * --C--
  10001. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  10002. * --D--
  10003. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  10004. * --E--
  10005. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  10006. * --F--
  10007. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  10008. *
  10009. * Note there is no reason monitors have to be the same size or in a grid.
  10010. */
  10011. THREE.PerspectiveCamera.prototype.setViewOffset = function ( fullWidth, fullHeight, x, y, width, height ) {
  10012. this.fullWidth = fullWidth;
  10013. this.fullHeight = fullHeight;
  10014. this.x = x;
  10015. this.y = y;
  10016. this.width = width;
  10017. this.height = height;
  10018. this.updateProjectionMatrix();
  10019. };
  10020. THREE.PerspectiveCamera.prototype.updateProjectionMatrix = function () {
  10021. var fov = THREE.Math.radToDeg( 2 * Math.atan( Math.tan( THREE.Math.degToRad( this.fov ) * 0.5 ) / this.zoom ) );
  10022. if ( this.fullWidth ) {
  10023. var aspect = this.fullWidth / this.fullHeight;
  10024. var top = Math.tan( THREE.Math.degToRad( fov * 0.5 ) ) * this.near;
  10025. var bottom = - top;
  10026. var left = aspect * bottom;
  10027. var right = aspect * top;
  10028. var width = Math.abs( right - left );
  10029. var height = Math.abs( top - bottom );
  10030. this.projectionMatrix.makeFrustum(
  10031. left + this.x * width / this.fullWidth,
  10032. left + ( this.x + this.width ) * width / this.fullWidth,
  10033. top - ( this.y + this.height ) * height / this.fullHeight,
  10034. top - this.y * height / this.fullHeight,
  10035. this.near,
  10036. this.far
  10037. );
  10038. } else {
  10039. this.projectionMatrix.makePerspective( fov, this.aspect, this.near, this.far );
  10040. }
  10041. };
  10042. THREE.PerspectiveCamera.prototype.copy = function ( source ) {
  10043. THREE.Camera.prototype.copy.call( this, source );
  10044. this.focalLength = source.focalLength;
  10045. this.zoom = source.zoom;
  10046. this.fov = source.fov;
  10047. this.aspect = source.aspect;
  10048. this.near = source.near;
  10049. this.far = source.far;
  10050. return this;
  10051. };
  10052. THREE.PerspectiveCamera.prototype.toJSON = function ( meta ) {
  10053. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  10054. data.object.focalLength = this.focalLength;
  10055. data.object.zoom = this.zoom;
  10056. data.object.fov = this.fov;
  10057. data.object.aspect = this.aspect;
  10058. data.object.near = this.near;
  10059. data.object.far = this.far;
  10060. return data;
  10061. };
  10062. // File:src/cameras/StereoCamera.js
  10063. /**
  10064. * @author mrdoob / http://mrdoob.com/
  10065. */
  10066. THREE.StereoCamera = function () {
  10067. this.type = 'StereoCamera';
  10068. this.aspect = 1;
  10069. this.cameraL = new THREE.PerspectiveCamera();
  10070. this.cameraL.layers.enable( 1 );
  10071. this.cameraL.matrixAutoUpdate = false;
  10072. this.cameraR = new THREE.PerspectiveCamera();
  10073. this.cameraR.layers.enable( 2 );
  10074. this.cameraR.matrixAutoUpdate = false;
  10075. };
  10076. THREE.StereoCamera.prototype = {
  10077. constructor: THREE.StereoCamera,
  10078. update: ( function () {
  10079. var focalLength, fov, aspect, near, far;
  10080. var eyeRight = new THREE.Matrix4();
  10081. var eyeLeft = new THREE.Matrix4();
  10082. return function update ( camera ) {
  10083. var needsUpdate = focalLength !== camera.focalLength || fov !== camera.fov ||
  10084. aspect !== camera.aspect * this.aspect || near !== camera.near ||
  10085. far !== camera.far;
  10086. if ( needsUpdate ) {
  10087. focalLength = camera.focalLength;
  10088. fov = camera.fov;
  10089. aspect = camera.aspect * this.aspect;
  10090. near = camera.near;
  10091. far = camera.far;
  10092. // Off-axis stereoscopic effect based on
  10093. // http://paulbourke.net/stereographics/stereorender/
  10094. var projectionMatrix = camera.projectionMatrix.clone();
  10095. var eyeSep = 0.064 / 2;
  10096. var eyeSepOnProjection = eyeSep * near / focalLength;
  10097. var ymax = near * Math.tan( THREE.Math.degToRad( fov * 0.5 ) );
  10098. var xmin, xmax;
  10099. // translate xOffset
  10100. eyeLeft.elements[ 12 ] = - eyeSep;
  10101. eyeRight.elements[ 12 ] = eyeSep;
  10102. // for left eye
  10103. xmin = - ymax * aspect + eyeSepOnProjection;
  10104. xmax = ymax * aspect + eyeSepOnProjection;
  10105. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  10106. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  10107. this.cameraL.projectionMatrix.copy( projectionMatrix );
  10108. // for right eye
  10109. xmin = - ymax * aspect - eyeSepOnProjection;
  10110. xmax = ymax * aspect - eyeSepOnProjection;
  10111. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  10112. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  10113. this.cameraR.projectionMatrix.copy( projectionMatrix );
  10114. }
  10115. this.cameraL.matrixWorld.copy( camera.matrixWorld ).multiply( eyeLeft );
  10116. this.cameraR.matrixWorld.copy( camera.matrixWorld ).multiply( eyeRight );
  10117. };
  10118. } )()
  10119. };
  10120. // File:src/lights/Light.js
  10121. /**
  10122. * @author mrdoob / http://mrdoob.com/
  10123. * @author alteredq / http://alteredqualia.com/
  10124. */
  10125. THREE.Light = function ( color, intensity ) {
  10126. THREE.Object3D.call( this );
  10127. this.type = 'Light';
  10128. this.color = new THREE.Color( color );
  10129. this.intensity = intensity !== undefined ? intensity : 1;
  10130. this.receiveShadow = undefined;
  10131. };
  10132. THREE.Light.prototype = Object.create( THREE.Object3D.prototype );
  10133. THREE.Light.prototype.constructor = THREE.Light;
  10134. THREE.Light.prototype.copy = function ( source ) {
  10135. THREE.Object3D.prototype.copy.call( this, source );
  10136. this.color.copy( source.color );
  10137. this.intensity = source.intensity;
  10138. return this;
  10139. };
  10140. THREE.Light.prototype.toJSON = function ( meta ) {
  10141. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  10142. data.object.color = this.color.getHex();
  10143. data.object.intensity = this.intensity;
  10144. if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();
  10145. if ( this.distance !== undefined ) data.object.distance = this.distance;
  10146. if ( this.angle !== undefined ) data.object.angle = this.angle;
  10147. if ( this.decay !== undefined ) data.object.decay = this.decay;
  10148. if ( this.penumbra !== undefined ) data.object.penumbra = this.penumbra;
  10149. return data;
  10150. };
  10151. // File:src/lights/LightShadow.js
  10152. /**
  10153. * @author mrdoob / http://mrdoob.com/
  10154. */
  10155. THREE.LightShadow = function ( camera ) {
  10156. this.camera = camera;
  10157. this.bias = 0;
  10158. this.radius = 1;
  10159. this.mapSize = new THREE.Vector2( 512, 512 );
  10160. this.map = null;
  10161. this.matrix = new THREE.Matrix4();
  10162. };
  10163. THREE.LightShadow.prototype = {
  10164. constructor: THREE.LightShadow,
  10165. copy: function ( source ) {
  10166. this.camera = source.camera.clone();
  10167. this.bias = source.bias;
  10168. this.radius = source.radius;
  10169. this.mapSize.copy( source.mapSize );
  10170. return this;
  10171. },
  10172. clone: function () {
  10173. return new this.constructor().copy( this );
  10174. }
  10175. };
  10176. // File:src/lights/AmbientLight.js
  10177. /**
  10178. * @author mrdoob / http://mrdoob.com/
  10179. */
  10180. THREE.AmbientLight = function ( color, intensity ) {
  10181. THREE.Light.call( this, color, intensity );
  10182. this.type = 'AmbientLight';
  10183. this.castShadow = undefined;
  10184. };
  10185. THREE.AmbientLight.prototype = Object.create( THREE.Light.prototype );
  10186. THREE.AmbientLight.prototype.constructor = THREE.AmbientLight;
  10187. // File:src/lights/DirectionalLight.js
  10188. /**
  10189. * @author mrdoob / http://mrdoob.com/
  10190. * @author alteredq / http://alteredqualia.com/
  10191. */
  10192. THREE.DirectionalLight = function ( color, intensity ) {
  10193. THREE.Light.call( this, color, intensity );
  10194. this.type = 'DirectionalLight';
  10195. this.position.set( 0, 1, 0 );
  10196. this.updateMatrix();
  10197. this.target = new THREE.Object3D();
  10198. this.shadow = new THREE.LightShadow( new THREE.OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) );
  10199. };
  10200. THREE.DirectionalLight.prototype = Object.create( THREE.Light.prototype );
  10201. THREE.DirectionalLight.prototype.constructor = THREE.DirectionalLight;
  10202. THREE.DirectionalLight.prototype.copy = function ( source ) {
  10203. THREE.Light.prototype.copy.call( this, source );
  10204. this.target = source.target.clone();
  10205. this.shadow = source.shadow.clone();
  10206. return this;
  10207. };
  10208. // File:src/lights/HemisphereLight.js
  10209. /**
  10210. * @author alteredq / http://alteredqualia.com/
  10211. */
  10212. THREE.HemisphereLight = function ( skyColor, groundColor, intensity ) {
  10213. THREE.Light.call( this, skyColor, intensity );
  10214. this.type = 'HemisphereLight';
  10215. this.castShadow = undefined;
  10216. this.position.set( 0, 1, 0 );
  10217. this.updateMatrix();
  10218. this.groundColor = new THREE.Color( groundColor );
  10219. };
  10220. THREE.HemisphereLight.prototype = Object.create( THREE.Light.prototype );
  10221. THREE.HemisphereLight.prototype.constructor = THREE.HemisphereLight;
  10222. THREE.HemisphereLight.prototype.copy = function ( source ) {
  10223. THREE.Light.prototype.copy.call( this, source );
  10224. this.groundColor.copy( source.groundColor );
  10225. return this;
  10226. };
  10227. // File:src/lights/PointLight.js
  10228. /**
  10229. * @author mrdoob / http://mrdoob.com/
  10230. */
  10231. THREE.PointLight = function ( color, intensity, distance, decay ) {
  10232. THREE.Light.call( this, color, intensity );
  10233. this.type = 'PointLight';
  10234. this.distance = ( distance !== undefined ) ? distance : 0;
  10235. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  10236. this.shadow = new THREE.LightShadow( new THREE.PerspectiveCamera( 90, 1, 0.5, 500 ) );
  10237. };
  10238. THREE.PointLight.prototype = Object.create( THREE.Light.prototype );
  10239. THREE.PointLight.prototype.constructor = THREE.PointLight;
  10240. Object.defineProperty( THREE.PointLight.prototype, "power", {
  10241. get: function () {
  10242. // intensity = power per solid angle.
  10243. // ref: equation (15) from http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
  10244. return this.intensity * 4 * Math.PI;
  10245. },
  10246. set: function ( power ) {
  10247. // intensity = power per solid angle.
  10248. // ref: equation (15) from http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
  10249. this.intensity = power / ( 4 * Math.PI );
  10250. }
  10251. } );
  10252. THREE.PointLight.prototype.copy = function ( source ) {
  10253. THREE.Light.prototype.copy.call( this, source );
  10254. this.distance = source.distance;
  10255. this.decay = source.decay;
  10256. this.shadow = source.shadow.clone();
  10257. return this;
  10258. };
  10259. // File:src/lights/SpotLight.js
  10260. /**
  10261. * @author alteredq / http://alteredqualia.com/
  10262. */
  10263. THREE.SpotLight = function ( color, intensity, distance, angle, penumbra, decay ) {
  10264. THREE.Light.call( this, color, intensity );
  10265. this.type = 'SpotLight';
  10266. this.position.set( 0, 1, 0 );
  10267. this.updateMatrix();
  10268. this.target = new THREE.Object3D();
  10269. this.distance = ( distance !== undefined ) ? distance : 0;
  10270. this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
  10271. this.penumbra = ( penumbra !== undefined ) ? penumbra : 0;
  10272. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  10273. this.shadow = new THREE.LightShadow( new THREE.PerspectiveCamera( 50, 1, 0.5, 500 ) );
  10274. };
  10275. THREE.SpotLight.prototype = Object.create( THREE.Light.prototype );
  10276. THREE.SpotLight.prototype.constructor = THREE.SpotLight;
  10277. Object.defineProperty( THREE.SpotLight.prototype, "power", {
  10278. get: function () {
  10279. // intensity = power per solid angle.
  10280. // ref: equation (17) from http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
  10281. return this.intensity * Math.PI;
  10282. },
  10283. set: function ( power ) {
  10284. // intensity = power per solid angle.
  10285. // ref: equation (17) from http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
  10286. this.intensity = power / Math.PI;
  10287. }
  10288. } );
  10289. THREE.SpotLight.prototype.copy = function ( source ) {
  10290. THREE.Light.prototype.copy.call( this, source );
  10291. this.distance = source.distance;
  10292. this.angle = source.angle;
  10293. this.penumbra = source.penumbra;
  10294. this.decay = source.decay;
  10295. this.target = source.target.clone();
  10296. this.shadow = source.shadow.clone();
  10297. return this;
  10298. };
  10299. // File:src/loaders/Cache.js
  10300. /**
  10301. * @author mrdoob / http://mrdoob.com/
  10302. */
  10303. THREE.Cache = {
  10304. enabled: false,
  10305. files: {},
  10306. add: function ( key, file ) {
  10307. if ( this.enabled === false ) return;
  10308. // console.log( 'THREE.Cache', 'Adding key:', key );
  10309. this.files[ key ] = file;
  10310. },
  10311. get: function ( key ) {
  10312. if ( this.enabled === false ) return;
  10313. // console.log( 'THREE.Cache', 'Checking key:', key );
  10314. return this.files[ key ];
  10315. },
  10316. remove: function ( key ) {
  10317. delete this.files[ key ];
  10318. },
  10319. clear: function () {
  10320. this.files = {};
  10321. }
  10322. };
  10323. // File:src/loaders/Loader.js
  10324. /**
  10325. * @author alteredq / http://alteredqualia.com/
  10326. */
  10327. THREE.Loader = function () {
  10328. this.onLoadStart = function () {};
  10329. this.onLoadProgress = function () {};
  10330. this.onLoadComplete = function () {};
  10331. };
  10332. THREE.Loader.prototype = {
  10333. constructor: THREE.Loader,
  10334. crossOrigin: undefined,
  10335. extractUrlBase: function ( url ) {
  10336. var parts = url.split( '/' );
  10337. if ( parts.length === 1 ) return './';
  10338. parts.pop();
  10339. return parts.join( '/' ) + '/';
  10340. },
  10341. initMaterials: function ( materials, texturePath, crossOrigin ) {
  10342. var array = [];
  10343. for ( var i = 0; i < materials.length; ++ i ) {
  10344. array[ i ] = this.createMaterial( materials[ i ], texturePath, crossOrigin );
  10345. }
  10346. return array;
  10347. },
  10348. createMaterial: ( function () {
  10349. var color, textureLoader, materialLoader;
  10350. return function ( m, texturePath, crossOrigin ) {
  10351. if ( color === undefined ) color = new THREE.Color();
  10352. if ( textureLoader === undefined ) textureLoader = new THREE.TextureLoader();
  10353. if ( materialLoader === undefined ) materialLoader = new THREE.MaterialLoader();
  10354. // convert from old material format
  10355. var textures = {};
  10356. function loadTexture( path, repeat, offset, wrap, anisotropy ) {
  10357. var fullPath = texturePath + path;
  10358. var loader = THREE.Loader.Handlers.get( fullPath );
  10359. var texture;
  10360. if ( loader !== null ) {
  10361. texture = loader.load( fullPath );
  10362. } else {
  10363. textureLoader.setCrossOrigin( crossOrigin );
  10364. texture = textureLoader.load( fullPath );
  10365. }
  10366. if ( repeat !== undefined ) {
  10367. texture.repeat.fromArray( repeat );
  10368. if ( repeat[ 0 ] !== 1 ) texture.wrapS = THREE.RepeatWrapping;
  10369. if ( repeat[ 1 ] !== 1 ) texture.wrapT = THREE.RepeatWrapping;
  10370. }
  10371. if ( offset !== undefined ) {
  10372. texture.offset.fromArray( offset );
  10373. }
  10374. if ( wrap !== undefined ) {
  10375. if ( wrap[ 0 ] === 'repeat' ) texture.wrapS = THREE.RepeatWrapping;
  10376. if ( wrap[ 0 ] === 'mirror' ) texture.wrapS = THREE.MirroredRepeatWrapping;
  10377. if ( wrap[ 1 ] === 'repeat' ) texture.wrapT = THREE.RepeatWrapping;
  10378. if ( wrap[ 1 ] === 'mirror' ) texture.wrapT = THREE.MirroredRepeatWrapping;
  10379. }
  10380. if ( anisotropy !== undefined ) {
  10381. texture.anisotropy = anisotropy;
  10382. }
  10383. var uuid = THREE.Math.generateUUID();
  10384. textures[ uuid ] = texture;
  10385. return uuid;
  10386. }
  10387. //
  10388. var json = {
  10389. uuid: THREE.Math.generateUUID(),
  10390. type: 'MeshLambertMaterial'
  10391. };
  10392. for ( var name in m ) {
  10393. var value = m[ name ];
  10394. switch ( name ) {
  10395. case 'DbgColor':
  10396. case 'DbgIndex':
  10397. case 'opticalDensity':
  10398. case 'illumination':
  10399. break;
  10400. case 'DbgName':
  10401. json.name = value;
  10402. break;
  10403. case 'blending':
  10404. json.blending = THREE[ value ];
  10405. break;
  10406. case 'colorAmbient':
  10407. case 'mapAmbient':
  10408. console.warn( 'THREE.Loader.createMaterial:', name, 'is no longer supported.' );
  10409. break;
  10410. case 'colorDiffuse':
  10411. json.color = color.fromArray( value ).getHex();
  10412. break;
  10413. case 'colorSpecular':
  10414. json.specular = color.fromArray( value ).getHex();
  10415. break;
  10416. case 'colorEmissive':
  10417. json.emissive = color.fromArray( value ).getHex();
  10418. break;
  10419. case 'specularCoef':
  10420. json.shininess = value;
  10421. break;
  10422. case 'shading':
  10423. if ( value.toLowerCase() === 'basic' ) json.type = 'MeshBasicMaterial';
  10424. if ( value.toLowerCase() === 'phong' ) json.type = 'MeshPhongMaterial';
  10425. break;
  10426. case 'mapDiffuse':
  10427. json.map = loadTexture( value, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap, m.mapDiffuseAnisotropy );
  10428. break;
  10429. case 'mapDiffuseRepeat':
  10430. case 'mapDiffuseOffset':
  10431. case 'mapDiffuseWrap':
  10432. case 'mapDiffuseAnisotropy':
  10433. break;
  10434. case 'mapLight':
  10435. json.lightMap = loadTexture( value, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap, m.mapLightAnisotropy );
  10436. break;
  10437. case 'mapLightRepeat':
  10438. case 'mapLightOffset':
  10439. case 'mapLightWrap':
  10440. case 'mapLightAnisotropy':
  10441. break;
  10442. case 'mapAO':
  10443. json.aoMap = loadTexture( value, m.mapAORepeat, m.mapAOOffset, m.mapAOWrap, m.mapAOAnisotropy );
  10444. break;
  10445. case 'mapAORepeat':
  10446. case 'mapAOOffset':
  10447. case 'mapAOWrap':
  10448. case 'mapAOAnisotropy':
  10449. break;
  10450. case 'mapBump':
  10451. json.bumpMap = loadTexture( value, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap, m.mapBumpAnisotropy );
  10452. break;
  10453. case 'mapBumpScale':
  10454. json.bumpScale = value;
  10455. break;
  10456. case 'mapBumpRepeat':
  10457. case 'mapBumpOffset':
  10458. case 'mapBumpWrap':
  10459. case 'mapBumpAnisotropy':
  10460. break;
  10461. case 'mapNormal':
  10462. json.normalMap = loadTexture( value, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap, m.mapNormalAnisotropy );
  10463. break;
  10464. case 'mapNormalFactor':
  10465. json.normalScale = [ value, value ];
  10466. break;
  10467. case 'mapNormalRepeat':
  10468. case 'mapNormalOffset':
  10469. case 'mapNormalWrap':
  10470. case 'mapNormalAnisotropy':
  10471. break;
  10472. case 'mapSpecular':
  10473. json.specularMap = loadTexture( value, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap, m.mapSpecularAnisotropy );
  10474. break;
  10475. case 'mapSpecularRepeat':
  10476. case 'mapSpecularOffset':
  10477. case 'mapSpecularWrap':
  10478. case 'mapSpecularAnisotropy':
  10479. break;
  10480. case 'mapAlpha':
  10481. json.alphaMap = loadTexture( value, m.mapAlphaRepeat, m.mapAlphaOffset, m.mapAlphaWrap, m.mapAlphaAnisotropy );
  10482. break;
  10483. case 'mapAlphaRepeat':
  10484. case 'mapAlphaOffset':
  10485. case 'mapAlphaWrap':
  10486. case 'mapAlphaAnisotropy':
  10487. break;
  10488. case 'flipSided':
  10489. json.side = THREE.BackSide;
  10490. break;
  10491. case 'doubleSided':
  10492. json.side = THREE.DoubleSide;
  10493. break;
  10494. case 'transparency':
  10495. console.warn( 'THREE.Loader.createMaterial: transparency has been renamed to opacity' );
  10496. json.opacity = value;
  10497. break;
  10498. case 'depthTest':
  10499. case 'depthWrite':
  10500. case 'colorWrite':
  10501. case 'opacity':
  10502. case 'reflectivity':
  10503. case 'transparent':
  10504. case 'visible':
  10505. case 'wireframe':
  10506. json[ name ] = value;
  10507. break;
  10508. case 'vertexColors':
  10509. if ( value === true ) json.vertexColors = THREE.VertexColors;
  10510. if ( value === 'face' ) json.vertexColors = THREE.FaceColors;
  10511. break;
  10512. default:
  10513. console.error( 'THREE.Loader.createMaterial: Unsupported', name, value );
  10514. break;
  10515. }
  10516. }
  10517. if ( json.type === 'MeshBasicMaterial' ) delete json.emissive;
  10518. if ( json.type !== 'MeshPhongMaterial' ) delete json.specular;
  10519. if ( json.opacity < 1 ) json.transparent = true;
  10520. materialLoader.setTextures( textures );
  10521. return materialLoader.parse( json );
  10522. };
  10523. } )()
  10524. };
  10525. THREE.Loader.Handlers = {
  10526. handlers: [],
  10527. add: function ( regex, loader ) {
  10528. this.handlers.push( regex, loader );
  10529. },
  10530. get: function ( file ) {
  10531. var handlers = this.handlers;
  10532. for ( var i = 0, l = handlers.length; i < l; i += 2 ) {
  10533. var regex = handlers[ i ];
  10534. var loader = handlers[ i + 1 ];
  10535. if ( regex.test( file ) ) {
  10536. return loader;
  10537. }
  10538. }
  10539. return null;
  10540. }
  10541. };
  10542. // File:src/loaders/XHRLoader.js
  10543. /**
  10544. * @author mrdoob / http://mrdoob.com/
  10545. */
  10546. THREE.XHRLoader = function ( manager ) {
  10547. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10548. };
  10549. THREE.XHRLoader.prototype = {
  10550. constructor: THREE.XHRLoader,
  10551. load: function ( url, onLoad, onProgress, onError ) {
  10552. if ( this.path !== undefined ) url = this.path + url;
  10553. var scope = this;
  10554. var cached = THREE.Cache.get( url );
  10555. if ( cached !== undefined ) {
  10556. if ( onLoad ) {
  10557. setTimeout( function () {
  10558. onLoad( cached );
  10559. }, 0 );
  10560. }
  10561. return cached;
  10562. }
  10563. var request = new XMLHttpRequest();
  10564. request.overrideMimeType( 'text/plain' );
  10565. request.open( 'GET', url, true );
  10566. request.addEventListener( 'load', function ( event ) {
  10567. var response = event.target.response;
  10568. THREE.Cache.add( url, response );
  10569. if ( this.status === 200 ) {
  10570. if ( onLoad ) onLoad( response );
  10571. scope.manager.itemEnd( url );
  10572. } else if ( this.status === 0 ) {
  10573. // Some browsers return HTTP Status 0 when using non-http protocol
  10574. // e.g. 'file://' or 'data://'. Handle as success.
  10575. console.warn( 'THREE.XHRLoader: HTTP Status 0 received.' );
  10576. if ( onLoad ) onLoad( response );
  10577. scope.manager.itemEnd( url );
  10578. } else {
  10579. if ( onError ) onError( event );
  10580. scope.manager.itemError( url );
  10581. }
  10582. }, false );
  10583. if ( onProgress !== undefined ) {
  10584. request.addEventListener( 'progress', function ( event ) {
  10585. onProgress( event );
  10586. }, false );
  10587. }
  10588. request.addEventListener( 'error', function ( event ) {
  10589. if ( onError ) onError( event );
  10590. scope.manager.itemError( url );
  10591. }, false );
  10592. if ( this.responseType !== undefined ) request.responseType = this.responseType;
  10593. if ( this.withCredentials !== undefined ) request.withCredentials = this.withCredentials;
  10594. request.send( null );
  10595. scope.manager.itemStart( url );
  10596. return request;
  10597. },
  10598. setPath: function ( value ) {
  10599. this.path = value;
  10600. },
  10601. setResponseType: function ( value ) {
  10602. this.responseType = value;
  10603. },
  10604. setWithCredentials: function ( value ) {
  10605. this.withCredentials = value;
  10606. }
  10607. };
  10608. // File:src/loaders/FontLoader.js
  10609. /**
  10610. * @author mrdoob / http://mrdoob.com/
  10611. */
  10612. THREE.FontLoader = function ( manager ) {
  10613. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10614. };
  10615. THREE.FontLoader.prototype = {
  10616. constructor: THREE.FontLoader,
  10617. load: function ( url, onLoad, onProgress, onError ) {
  10618. var loader = new THREE.XHRLoader( this.manager );
  10619. loader.load( url, function ( text ) {
  10620. onLoad( new THREE.Font( JSON.parse( text.substring( 65, text.length - 2 ) ) ) );
  10621. }, onProgress, onError );
  10622. }
  10623. };
  10624. // File:src/loaders/ImageLoader.js
  10625. /**
  10626. * @author mrdoob / http://mrdoob.com/
  10627. */
  10628. THREE.ImageLoader = function ( manager ) {
  10629. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10630. };
  10631. THREE.ImageLoader.prototype = {
  10632. constructor: THREE.ImageLoader,
  10633. load: function ( url, onLoad, onProgress, onError ) {
  10634. if ( this.path !== undefined ) url = this.path + url;
  10635. var scope = this;
  10636. var cached = THREE.Cache.get( url );
  10637. if ( cached !== undefined ) {
  10638. scope.manager.itemStart( url );
  10639. if ( onLoad ) {
  10640. setTimeout( function () {
  10641. onLoad( cached );
  10642. scope.manager.itemEnd( url );
  10643. }, 0 );
  10644. } else {
  10645. scope.manager.itemEnd( url );
  10646. }
  10647. return cached;
  10648. }
  10649. var image = document.createElement( 'img' );
  10650. image.addEventListener( 'load', function ( event ) {
  10651. THREE.Cache.add( url, this );
  10652. if ( onLoad ) onLoad( this );
  10653. scope.manager.itemEnd( url );
  10654. }, false );
  10655. if ( onProgress !== undefined ) {
  10656. image.addEventListener( 'progress', function ( event ) {
  10657. onProgress( event );
  10658. }, false );
  10659. }
  10660. image.addEventListener( 'error', function ( event ) {
  10661. if ( onError ) onError( event );
  10662. scope.manager.itemError( url );
  10663. }, false );
  10664. if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
  10665. scope.manager.itemStart( url );
  10666. image.src = url;
  10667. return image;
  10668. },
  10669. setCrossOrigin: function ( value ) {
  10670. this.crossOrigin = value;
  10671. },
  10672. setPath: function ( value ) {
  10673. this.path = value;
  10674. }
  10675. };
  10676. // File:src/loaders/JSONLoader.js
  10677. /**
  10678. * @author mrdoob / http://mrdoob.com/
  10679. * @author alteredq / http://alteredqualia.com/
  10680. */
  10681. THREE.JSONLoader = function ( manager ) {
  10682. if ( typeof manager === 'boolean' ) {
  10683. console.warn( 'THREE.JSONLoader: showStatus parameter has been removed from constructor.' );
  10684. manager = undefined;
  10685. }
  10686. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10687. this.withCredentials = false;
  10688. };
  10689. THREE.JSONLoader.prototype = {
  10690. constructor: THREE.JSONLoader,
  10691. // Deprecated
  10692. get statusDomElement () {
  10693. if ( this._statusDomElement === undefined ) {
  10694. this._statusDomElement = document.createElement( 'div' );
  10695. }
  10696. console.warn( 'THREE.JSONLoader: .statusDomElement has been removed.' );
  10697. return this._statusDomElement;
  10698. },
  10699. load: function( url, onLoad, onProgress, onError ) {
  10700. var scope = this;
  10701. var texturePath = this.texturePath && ( typeof this.texturePath === "string" ) ? this.texturePath : THREE.Loader.prototype.extractUrlBase( url );
  10702. var loader = new THREE.XHRLoader( this.manager );
  10703. loader.setWithCredentials( this.withCredentials );
  10704. loader.load( url, function ( text ) {
  10705. var json = JSON.parse( text );
  10706. var metadata = json.metadata;
  10707. if ( metadata !== undefined ) {
  10708. var type = metadata.type;
  10709. if ( type !== undefined ) {
  10710. if ( type.toLowerCase() === 'object' ) {
  10711. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.ObjectLoader instead.' );
  10712. return;
  10713. }
  10714. if ( type.toLowerCase() === 'scene' ) {
  10715. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.SceneLoader instead.' );
  10716. return;
  10717. }
  10718. }
  10719. }
  10720. var object = scope.parse( json, texturePath );
  10721. onLoad( object.geometry, object.materials );
  10722. }, onProgress, onError );
  10723. },
  10724. setTexturePath: function ( value ) {
  10725. this.texturePath = value;
  10726. },
  10727. parse: function ( json, texturePath ) {
  10728. var geometry = new THREE.Geometry(),
  10729. scale = ( json.scale !== undefined ) ? 1.0 / json.scale : 1.0;
  10730. parseModel( scale );
  10731. parseSkin();
  10732. parseMorphing( scale );
  10733. parseAnimations();
  10734. geometry.computeFaceNormals();
  10735. geometry.computeBoundingSphere();
  10736. function parseModel( scale ) {
  10737. function isBitSet( value, position ) {
  10738. return value & ( 1 << position );
  10739. }
  10740. var i, j, fi,
  10741. offset, zLength,
  10742. colorIndex, normalIndex, uvIndex, materialIndex,
  10743. type,
  10744. isQuad,
  10745. hasMaterial,
  10746. hasFaceVertexUv,
  10747. hasFaceNormal, hasFaceVertexNormal,
  10748. hasFaceColor, hasFaceVertexColor,
  10749. vertex, face, faceA, faceB, hex, normal,
  10750. uvLayer, uv, u, v,
  10751. faces = json.faces,
  10752. vertices = json.vertices,
  10753. normals = json.normals,
  10754. colors = json.colors,
  10755. nUvLayers = 0;
  10756. if ( json.uvs !== undefined ) {
  10757. // disregard empty arrays
  10758. for ( i = 0; i < json.uvs.length; i ++ ) {
  10759. if ( json.uvs[ i ].length ) nUvLayers ++;
  10760. }
  10761. for ( i = 0; i < nUvLayers; i ++ ) {
  10762. geometry.faceVertexUvs[ i ] = [];
  10763. }
  10764. }
  10765. offset = 0;
  10766. zLength = vertices.length;
  10767. while ( offset < zLength ) {
  10768. vertex = new THREE.Vector3();
  10769. vertex.x = vertices[ offset ++ ] * scale;
  10770. vertex.y = vertices[ offset ++ ] * scale;
  10771. vertex.z = vertices[ offset ++ ] * scale;
  10772. geometry.vertices.push( vertex );
  10773. }
  10774. offset = 0;
  10775. zLength = faces.length;
  10776. while ( offset < zLength ) {
  10777. type = faces[ offset ++ ];
  10778. isQuad = isBitSet( type, 0 );
  10779. hasMaterial = isBitSet( type, 1 );
  10780. hasFaceVertexUv = isBitSet( type, 3 );
  10781. hasFaceNormal = isBitSet( type, 4 );
  10782. hasFaceVertexNormal = isBitSet( type, 5 );
  10783. hasFaceColor = isBitSet( type, 6 );
  10784. hasFaceVertexColor = isBitSet( type, 7 );
  10785. // console.log("type", type, "bits", isQuad, hasMaterial, hasFaceVertexUv, hasFaceNormal, hasFaceVertexNormal, hasFaceColor, hasFaceVertexColor);
  10786. if ( isQuad ) {
  10787. faceA = new THREE.Face3();
  10788. faceA.a = faces[ offset ];
  10789. faceA.b = faces[ offset + 1 ];
  10790. faceA.c = faces[ offset + 3 ];
  10791. faceB = new THREE.Face3();
  10792. faceB.a = faces[ offset + 1 ];
  10793. faceB.b = faces[ offset + 2 ];
  10794. faceB.c = faces[ offset + 3 ];
  10795. offset += 4;
  10796. if ( hasMaterial ) {
  10797. materialIndex = faces[ offset ++ ];
  10798. faceA.materialIndex = materialIndex;
  10799. faceB.materialIndex = materialIndex;
  10800. }
  10801. // to get face <=> uv index correspondence
  10802. fi = geometry.faces.length;
  10803. if ( hasFaceVertexUv ) {
  10804. for ( i = 0; i < nUvLayers; i ++ ) {
  10805. uvLayer = json.uvs[ i ];
  10806. geometry.faceVertexUvs[ i ][ fi ] = [];
  10807. geometry.faceVertexUvs[ i ][ fi + 1 ] = [];
  10808. for ( j = 0; j < 4; j ++ ) {
  10809. uvIndex = faces[ offset ++ ];
  10810. u = uvLayer[ uvIndex * 2 ];
  10811. v = uvLayer[ uvIndex * 2 + 1 ];
  10812. uv = new THREE.Vector2( u, v );
  10813. if ( j !== 2 ) geometry.faceVertexUvs[ i ][ fi ].push( uv );
  10814. if ( j !== 0 ) geometry.faceVertexUvs[ i ][ fi + 1 ].push( uv );
  10815. }
  10816. }
  10817. }
  10818. if ( hasFaceNormal ) {
  10819. normalIndex = faces[ offset ++ ] * 3;
  10820. faceA.normal.set(
  10821. normals[ normalIndex ++ ],
  10822. normals[ normalIndex ++ ],
  10823. normals[ normalIndex ]
  10824. );
  10825. faceB.normal.copy( faceA.normal );
  10826. }
  10827. if ( hasFaceVertexNormal ) {
  10828. for ( i = 0; i < 4; i ++ ) {
  10829. normalIndex = faces[ offset ++ ] * 3;
  10830. normal = new THREE.Vector3(
  10831. normals[ normalIndex ++ ],
  10832. normals[ normalIndex ++ ],
  10833. normals[ normalIndex ]
  10834. );
  10835. if ( i !== 2 ) faceA.vertexNormals.push( normal );
  10836. if ( i !== 0 ) faceB.vertexNormals.push( normal );
  10837. }
  10838. }
  10839. if ( hasFaceColor ) {
  10840. colorIndex = faces[ offset ++ ];
  10841. hex = colors[ colorIndex ];
  10842. faceA.color.setHex( hex );
  10843. faceB.color.setHex( hex );
  10844. }
  10845. if ( hasFaceVertexColor ) {
  10846. for ( i = 0; i < 4; i ++ ) {
  10847. colorIndex = faces[ offset ++ ];
  10848. hex = colors[ colorIndex ];
  10849. if ( i !== 2 ) faceA.vertexColors.push( new THREE.Color( hex ) );
  10850. if ( i !== 0 ) faceB.vertexColors.push( new THREE.Color( hex ) );
  10851. }
  10852. }
  10853. geometry.faces.push( faceA );
  10854. geometry.faces.push( faceB );
  10855. } else {
  10856. face = new THREE.Face3();
  10857. face.a = faces[ offset ++ ];
  10858. face.b = faces[ offset ++ ];
  10859. face.c = faces[ offset ++ ];
  10860. if ( hasMaterial ) {
  10861. materialIndex = faces[ offset ++ ];
  10862. face.materialIndex = materialIndex;
  10863. }
  10864. // to get face <=> uv index correspondence
  10865. fi = geometry.faces.length;
  10866. if ( hasFaceVertexUv ) {
  10867. for ( i = 0; i < nUvLayers; i ++ ) {
  10868. uvLayer = json.uvs[ i ];
  10869. geometry.faceVertexUvs[ i ][ fi ] = [];
  10870. for ( j = 0; j < 3; j ++ ) {
  10871. uvIndex = faces[ offset ++ ];
  10872. u = uvLayer[ uvIndex * 2 ];
  10873. v = uvLayer[ uvIndex * 2 + 1 ];
  10874. uv = new THREE.Vector2( u, v );
  10875. geometry.faceVertexUvs[ i ][ fi ].push( uv );
  10876. }
  10877. }
  10878. }
  10879. if ( hasFaceNormal ) {
  10880. normalIndex = faces[ offset ++ ] * 3;
  10881. face.normal.set(
  10882. normals[ normalIndex ++ ],
  10883. normals[ normalIndex ++ ],
  10884. normals[ normalIndex ]
  10885. );
  10886. }
  10887. if ( hasFaceVertexNormal ) {
  10888. for ( i = 0; i < 3; i ++ ) {
  10889. normalIndex = faces[ offset ++ ] * 3;
  10890. normal = new THREE.Vector3(
  10891. normals[ normalIndex ++ ],
  10892. normals[ normalIndex ++ ],
  10893. normals[ normalIndex ]
  10894. );
  10895. face.vertexNormals.push( normal );
  10896. }
  10897. }
  10898. if ( hasFaceColor ) {
  10899. colorIndex = faces[ offset ++ ];
  10900. face.color.setHex( colors[ colorIndex ] );
  10901. }
  10902. if ( hasFaceVertexColor ) {
  10903. for ( i = 0; i < 3; i ++ ) {
  10904. colorIndex = faces[ offset ++ ];
  10905. face.vertexColors.push( new THREE.Color( colors[ colorIndex ] ) );
  10906. }
  10907. }
  10908. geometry.faces.push( face );
  10909. }
  10910. }
  10911. };
  10912. function parseSkin() {
  10913. var influencesPerVertex = ( json.influencesPerVertex !== undefined ) ? json.influencesPerVertex : 2;
  10914. if ( json.skinWeights ) {
  10915. for ( var i = 0, l = json.skinWeights.length; i < l; i += influencesPerVertex ) {
  10916. var x = json.skinWeights[ i ];
  10917. var y = ( influencesPerVertex > 1 ) ? json.skinWeights[ i + 1 ] : 0;
  10918. var z = ( influencesPerVertex > 2 ) ? json.skinWeights[ i + 2 ] : 0;
  10919. var w = ( influencesPerVertex > 3 ) ? json.skinWeights[ i + 3 ] : 0;
  10920. geometry.skinWeights.push( new THREE.Vector4( x, y, z, w ) );
  10921. }
  10922. }
  10923. if ( json.skinIndices ) {
  10924. for ( var i = 0, l = json.skinIndices.length; i < l; i += influencesPerVertex ) {
  10925. var a = json.skinIndices[ i ];
  10926. var b = ( influencesPerVertex > 1 ) ? json.skinIndices[ i + 1 ] : 0;
  10927. var c = ( influencesPerVertex > 2 ) ? json.skinIndices[ i + 2 ] : 0;
  10928. var d = ( influencesPerVertex > 3 ) ? json.skinIndices[ i + 3 ] : 0;
  10929. geometry.skinIndices.push( new THREE.Vector4( a, b, c, d ) );
  10930. }
  10931. }
  10932. geometry.bones = json.bones;
  10933. if ( geometry.bones && geometry.bones.length > 0 && ( geometry.skinWeights.length !== geometry.skinIndices.length || geometry.skinIndices.length !== geometry.vertices.length ) ) {
  10934. console.warn( 'When skinning, number of vertices (' + geometry.vertices.length + '), skinIndices (' +
  10935. geometry.skinIndices.length + '), and skinWeights (' + geometry.skinWeights.length + ') should match.' );
  10936. }
  10937. };
  10938. function parseMorphing( scale ) {
  10939. if ( json.morphTargets !== undefined ) {
  10940. for ( var i = 0, l = json.morphTargets.length; i < l; i ++ ) {
  10941. geometry.morphTargets[ i ] = {};
  10942. geometry.morphTargets[ i ].name = json.morphTargets[ i ].name;
  10943. geometry.morphTargets[ i ].vertices = [];
  10944. var dstVertices = geometry.morphTargets[ i ].vertices;
  10945. var srcVertices = json.morphTargets[ i ].vertices;
  10946. for ( var v = 0, vl = srcVertices.length; v < vl; v += 3 ) {
  10947. var vertex = new THREE.Vector3();
  10948. vertex.x = srcVertices[ v ] * scale;
  10949. vertex.y = srcVertices[ v + 1 ] * scale;
  10950. vertex.z = srcVertices[ v + 2 ] * scale;
  10951. dstVertices.push( vertex );
  10952. }
  10953. }
  10954. }
  10955. if ( json.morphColors !== undefined && json.morphColors.length > 0 ) {
  10956. console.warn( 'THREE.JSONLoader: "morphColors" no longer supported. Using them as face colors.' );
  10957. var faces = geometry.faces;
  10958. var morphColors = json.morphColors[ 0 ].colors;
  10959. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  10960. faces[ i ].color.fromArray( morphColors, i * 3 );
  10961. }
  10962. }
  10963. }
  10964. function parseAnimations() {
  10965. var outputAnimations = [];
  10966. // parse old style Bone/Hierarchy animations
  10967. var animations = [];
  10968. if ( json.animation !== undefined ) {
  10969. animations.push( json.animation );
  10970. }
  10971. if ( json.animations !== undefined ) {
  10972. if ( json.animations.length ) {
  10973. animations = animations.concat( json.animations );
  10974. } else {
  10975. animations.push( json.animations );
  10976. }
  10977. }
  10978. for ( var i = 0; i < animations.length; i ++ ) {
  10979. var clip = THREE.AnimationClip.parseAnimation( animations[ i ], geometry.bones );
  10980. if ( clip ) outputAnimations.push( clip );
  10981. }
  10982. // parse implicit morph animations
  10983. if ( geometry.morphTargets ) {
  10984. // TODO: Figure out what an appropraite FPS is for morph target animations -- defaulting to 10, but really it is completely arbitrary.
  10985. var morphAnimationClips = THREE.AnimationClip.CreateClipsFromMorphTargetSequences( geometry.morphTargets, 10 );
  10986. outputAnimations = outputAnimations.concat( morphAnimationClips );
  10987. }
  10988. if ( outputAnimations.length > 0 ) geometry.animations = outputAnimations;
  10989. };
  10990. if ( json.materials === undefined || json.materials.length === 0 ) {
  10991. return { geometry: geometry };
  10992. } else {
  10993. var materials = THREE.Loader.prototype.initMaterials( json.materials, texturePath, this.crossOrigin );
  10994. return { geometry: geometry, materials: materials };
  10995. }
  10996. }
  10997. };
  10998. // File:src/loaders/LoadingManager.js
  10999. /**
  11000. * @author mrdoob / http://mrdoob.com/
  11001. */
  11002. THREE.LoadingManager = function ( onLoad, onProgress, onError ) {
  11003. var scope = this;
  11004. var isLoading = false, itemsLoaded = 0, itemsTotal = 0;
  11005. this.onStart = undefined;
  11006. this.onLoad = onLoad;
  11007. this.onProgress = onProgress;
  11008. this.onError = onError;
  11009. this.itemStart = function ( url ) {
  11010. itemsTotal ++;
  11011. if ( isLoading === false ) {
  11012. if ( scope.onStart !== undefined ) {
  11013. scope.onStart( url, itemsLoaded, itemsTotal );
  11014. }
  11015. }
  11016. isLoading = true;
  11017. };
  11018. this.itemEnd = function ( url ) {
  11019. itemsLoaded ++;
  11020. if ( scope.onProgress !== undefined ) {
  11021. scope.onProgress( url, itemsLoaded, itemsTotal );
  11022. }
  11023. if ( itemsLoaded === itemsTotal ) {
  11024. isLoading = false;
  11025. if ( scope.onLoad !== undefined ) {
  11026. scope.onLoad();
  11027. }
  11028. }
  11029. };
  11030. this.itemError = function ( url ) {
  11031. if ( scope.onError !== undefined ) {
  11032. scope.onError( url );
  11033. }
  11034. };
  11035. };
  11036. THREE.DefaultLoadingManager = new THREE.LoadingManager();
  11037. // File:src/loaders/BufferGeometryLoader.js
  11038. /**
  11039. * @author mrdoob / http://mrdoob.com/
  11040. */
  11041. THREE.BufferGeometryLoader = function ( manager ) {
  11042. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11043. };
  11044. THREE.BufferGeometryLoader.prototype = {
  11045. constructor: THREE.BufferGeometryLoader,
  11046. load: function ( url, onLoad, onProgress, onError ) {
  11047. var scope = this;
  11048. var loader = new THREE.XHRLoader( scope.manager );
  11049. loader.load( url, function ( text ) {
  11050. onLoad( scope.parse( JSON.parse( text ) ) );
  11051. }, onProgress, onError );
  11052. },
  11053. parse: function ( json ) {
  11054. var geometry = new THREE.BufferGeometry();
  11055. var index = json.data.index;
  11056. var TYPED_ARRAYS = {
  11057. 'Int8Array': Int8Array,
  11058. 'Uint8Array': Uint8Array,
  11059. 'Uint8ClampedArray': Uint8ClampedArray,
  11060. 'Int16Array': Int16Array,
  11061. 'Uint16Array': Uint16Array,
  11062. 'Int32Array': Int32Array,
  11063. 'Uint32Array': Uint32Array,
  11064. 'Float32Array': Float32Array,
  11065. 'Float64Array': Float64Array
  11066. };
  11067. if ( index !== undefined ) {
  11068. var typedArray = new TYPED_ARRAYS[ index.type ]( index.array );
  11069. geometry.setIndex( new THREE.BufferAttribute( typedArray, 1 ) );
  11070. }
  11071. var attributes = json.data.attributes;
  11072. for ( var key in attributes ) {
  11073. var attribute = attributes[ key ];
  11074. var typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
  11075. geometry.addAttribute( key, new THREE.BufferAttribute( typedArray, attribute.itemSize ) );
  11076. }
  11077. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  11078. if ( groups !== undefined ) {
  11079. for ( var i = 0, n = groups.length; i !== n; ++ i ) {
  11080. var group = groups[ i ];
  11081. geometry.addGroup( group.start, group.count, group.materialIndex );
  11082. }
  11083. }
  11084. var boundingSphere = json.data.boundingSphere;
  11085. if ( boundingSphere !== undefined ) {
  11086. var center = new THREE.Vector3();
  11087. if ( boundingSphere.center !== undefined ) {
  11088. center.fromArray( boundingSphere.center );
  11089. }
  11090. geometry.boundingSphere = new THREE.Sphere( center, boundingSphere.radius );
  11091. }
  11092. return geometry;
  11093. }
  11094. };
  11095. // File:src/loaders/MaterialLoader.js
  11096. /**
  11097. * @author mrdoob / http://mrdoob.com/
  11098. */
  11099. THREE.MaterialLoader = function ( manager ) {
  11100. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11101. this.textures = {};
  11102. };
  11103. THREE.MaterialLoader.prototype = {
  11104. constructor: THREE.MaterialLoader,
  11105. load: function ( url, onLoad, onProgress, onError ) {
  11106. var scope = this;
  11107. var loader = new THREE.XHRLoader( scope.manager );
  11108. loader.load( url, function ( text ) {
  11109. onLoad( scope.parse( JSON.parse( text ) ) );
  11110. }, onProgress, onError );
  11111. },
  11112. setTextures: function ( value ) {
  11113. this.textures = value;
  11114. },
  11115. getTexture: function ( name ) {
  11116. var textures = this.textures;
  11117. if ( textures[ name ] === undefined ) {
  11118. console.warn( 'THREE.MaterialLoader: Undefined texture', name );
  11119. }
  11120. return textures[ name ];
  11121. },
  11122. parse: function ( json ) {
  11123. var material = new THREE[ json.type ];
  11124. if ( json.uuid !== undefined ) material.uuid = json.uuid;
  11125. if ( json.name !== undefined ) material.name = json.name;
  11126. if ( json.color !== undefined ) material.color.setHex( json.color );
  11127. if ( json.roughness !== undefined ) material.roughness = json.roughness;
  11128. if ( json.metalness !== undefined ) material.metalness = json.metalness;
  11129. if ( json.emissive !== undefined ) material.emissive.setHex( json.emissive );
  11130. if ( json.specular !== undefined ) material.specular.setHex( json.specular );
  11131. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  11132. if ( json.uniforms !== undefined ) material.uniforms = json.uniforms;
  11133. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  11134. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  11135. if ( json.vertexColors !== undefined ) material.vertexColors = json.vertexColors;
  11136. if ( json.shading !== undefined ) material.shading = json.shading;
  11137. if ( json.blending !== undefined ) material.blending = json.blending;
  11138. if ( json.side !== undefined ) material.side = json.side;
  11139. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  11140. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  11141. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  11142. if ( json.depthTest !== undefined ) material.depthTest = json.depthTest;
  11143. if ( json.depthWrite !== undefined ) material.depthWrite = json.depthWrite;
  11144. if ( json.colorWrite !== undefined ) material.colorWrite = json.colorWrite;
  11145. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  11146. if ( json.wireframeLinewidth !== undefined ) material.wireframeLinewidth = json.wireframeLinewidth;
  11147. // for PointsMaterial
  11148. if ( json.size !== undefined ) material.size = json.size;
  11149. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  11150. // maps
  11151. if ( json.map !== undefined ) material.map = this.getTexture( json.map );
  11152. if ( json.alphaMap !== undefined ) {
  11153. material.alphaMap = this.getTexture( json.alphaMap );
  11154. material.transparent = true;
  11155. }
  11156. if ( json.bumpMap !== undefined ) material.bumpMap = this.getTexture( json.bumpMap );
  11157. if ( json.bumpScale !== undefined ) material.bumpScale = json.bumpScale;
  11158. if ( json.normalMap !== undefined ) material.normalMap = this.getTexture( json.normalMap );
  11159. if ( json.normalScale !== undefined ) {
  11160. var normalScale = json.normalScale;
  11161. if ( Array.isArray( normalScale ) === false ) {
  11162. // Blender exporter used to export a scalar. See #7459
  11163. normalScale = [ normalScale, normalScale ];
  11164. }
  11165. material.normalScale = new THREE.Vector2().fromArray( normalScale );
  11166. }
  11167. if ( json.displacementMap !== undefined ) material.displacementMap = this.getTexture( json.displacementMap );
  11168. if ( json.displacementScale !== undefined ) material.displacementScale = json.displacementScale;
  11169. if ( json.displacementBias !== undefined ) material.displacementBias = json.displacementBias;
  11170. if ( json.roughnessMap !== undefined ) material.roughnessMap = this.getTexture( json.roughnessMap );
  11171. if ( json.metalnessMap !== undefined ) material.metalnessMap = this.getTexture( json.metalnessMap );
  11172. if ( json.emissiveMap !== undefined ) material.emissiveMap = this.getTexture( json.emissiveMap );
  11173. if ( json.emissiveIntensity !== undefined ) material.emissiveIntensity = json.emissiveIntensity;
  11174. if ( json.specularMap !== undefined ) material.specularMap = this.getTexture( json.specularMap );
  11175. if ( json.envMap !== undefined ) {
  11176. material.envMap = this.getTexture( json.envMap );
  11177. material.combine = THREE.MultiplyOperation;
  11178. }
  11179. if ( json.reflectivity ) material.reflectivity = json.reflectivity;
  11180. if ( json.lightMap !== undefined ) material.lightMap = this.getTexture( json.lightMap );
  11181. if ( json.lightMapIntensity !== undefined ) material.lightMapIntensity = json.lightMapIntensity;
  11182. if ( json.aoMap !== undefined ) material.aoMap = this.getTexture( json.aoMap );
  11183. if ( json.aoMapIntensity !== undefined ) material.aoMapIntensity = json.aoMapIntensity;
  11184. // MultiMaterial
  11185. if ( json.materials !== undefined ) {
  11186. for ( var i = 0, l = json.materials.length; i < l; i ++ ) {
  11187. material.materials.push( this.parse( json.materials[ i ] ) );
  11188. }
  11189. }
  11190. return material;
  11191. }
  11192. };
  11193. // File:src/loaders/ObjectLoader.js
  11194. /**
  11195. * @author mrdoob / http://mrdoob.com/
  11196. */
  11197. THREE.ObjectLoader = function ( manager ) {
  11198. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11199. this.texturePath = '';
  11200. };
  11201. THREE.ObjectLoader.prototype = {
  11202. constructor: THREE.ObjectLoader,
  11203. load: function ( url, onLoad, onProgress, onError ) {
  11204. if ( this.texturePath === '' ) {
  11205. this.texturePath = url.substring( 0, url.lastIndexOf( '/' ) + 1 );
  11206. }
  11207. var scope = this;
  11208. var loader = new THREE.XHRLoader( scope.manager );
  11209. loader.load( url, function ( text ) {
  11210. scope.parse( JSON.parse( text ), onLoad );
  11211. }, onProgress, onError );
  11212. },
  11213. setTexturePath: function ( value ) {
  11214. this.texturePath = value;
  11215. },
  11216. setCrossOrigin: function ( value ) {
  11217. this.crossOrigin = value;
  11218. },
  11219. parse: function ( json, onLoad ) {
  11220. var geometries = this.parseGeometries( json.geometries );
  11221. var images = this.parseImages( json.images, function () {
  11222. if ( onLoad !== undefined ) onLoad( object );
  11223. } );
  11224. var textures = this.parseTextures( json.textures, images );
  11225. var materials = this.parseMaterials( json.materials, textures );
  11226. var object = this.parseObject( json.object, geometries, materials );
  11227. if ( json.animations ) {
  11228. object.animations = this.parseAnimations( json.animations );
  11229. }
  11230. if ( json.images === undefined || json.images.length === 0 ) {
  11231. if ( onLoad !== undefined ) onLoad( object );
  11232. }
  11233. return object;
  11234. },
  11235. parseGeometries: function ( json ) {
  11236. var geometries = {};
  11237. if ( json !== undefined ) {
  11238. var geometryLoader = new THREE.JSONLoader();
  11239. var bufferGeometryLoader = new THREE.BufferGeometryLoader();
  11240. for ( var i = 0, l = json.length; i < l; i ++ ) {
  11241. var geometry;
  11242. var data = json[ i ];
  11243. switch ( data.type ) {
  11244. case 'PlaneGeometry':
  11245. case 'PlaneBufferGeometry':
  11246. geometry = new THREE[ data.type ](
  11247. data.width,
  11248. data.height,
  11249. data.widthSegments,
  11250. data.heightSegments
  11251. );
  11252. break;
  11253. case 'BoxGeometry':
  11254. case 'BoxBufferGeometry':
  11255. case 'CubeGeometry': // backwards compatible
  11256. geometry = new THREE[ data.type ](
  11257. data.width,
  11258. data.height,
  11259. data.depth,
  11260. data.widthSegments,
  11261. data.heightSegments,
  11262. data.depthSegments
  11263. );
  11264. break;
  11265. case 'CircleGeometry':
  11266. case 'CircleBufferGeometry':
  11267. geometry = new THREE[ data.type ](
  11268. data.radius,
  11269. data.segments,
  11270. data.thetaStart,
  11271. data.thetaLength
  11272. );
  11273. break;
  11274. case 'CylinderGeometry':
  11275. case 'CylinderBufferGeometry':
  11276. geometry = new THREE[ data.type ](
  11277. data.radiusTop,
  11278. data.radiusBottom,
  11279. data.height,
  11280. data.radialSegments,
  11281. data.heightSegments,
  11282. data.openEnded,
  11283. data.thetaStart,
  11284. data.thetaLength
  11285. );
  11286. break;
  11287. case 'SphereGeometry':
  11288. case 'SphereBufferGeometry':
  11289. geometry = new THREE[ data.type ](
  11290. data.radius,
  11291. data.widthSegments,
  11292. data.heightSegments,
  11293. data.phiStart,
  11294. data.phiLength,
  11295. data.thetaStart,
  11296. data.thetaLength
  11297. );
  11298. break;
  11299. case 'DodecahedronGeometry':
  11300. geometry = new THREE.DodecahedronGeometry(
  11301. data.radius,
  11302. data.detail
  11303. );
  11304. break;
  11305. case 'IcosahedronGeometry':
  11306. geometry = new THREE.IcosahedronGeometry(
  11307. data.radius,
  11308. data.detail
  11309. );
  11310. break;
  11311. case 'OctahedronGeometry':
  11312. geometry = new THREE.OctahedronGeometry(
  11313. data.radius,
  11314. data.detail
  11315. );
  11316. break;
  11317. case 'TetrahedronGeometry':
  11318. geometry = new THREE.TetrahedronGeometry(
  11319. data.radius,
  11320. data.detail
  11321. );
  11322. break;
  11323. case 'RingGeometry':
  11324. case 'RingBufferGeometry':
  11325. geometry = new THREE[ data.type ](
  11326. data.innerRadius,
  11327. data.outerRadius,
  11328. data.thetaSegments,
  11329. data.phiSegments,
  11330. data.thetaStart,
  11331. data.thetaLength
  11332. );
  11333. break;
  11334. case 'TorusGeometry':
  11335. case 'TorusBufferGeometry':
  11336. geometry = new THREE[ data.type ](
  11337. data.radius,
  11338. data.tube,
  11339. data.radialSegments,
  11340. data.tubularSegments,
  11341. data.arc
  11342. );
  11343. break;
  11344. case 'TorusKnotGeometry':
  11345. case 'TorusKnotBufferGeometry':
  11346. geometry = new THREE[ data.type ](
  11347. data.radius,
  11348. data.tube,
  11349. data.tubularSegments,
  11350. data.radialSegments,
  11351. data.p,
  11352. data.q
  11353. );
  11354. break;
  11355. case 'LatheGeometry':
  11356. geometry = new THREE.LatheGeometry(
  11357. data.points,
  11358. data.segments,
  11359. data.phiStart,
  11360. data.phiLength
  11361. );
  11362. break;
  11363. case 'BufferGeometry':
  11364. geometry = bufferGeometryLoader.parse( data );
  11365. break;
  11366. case 'Geometry':
  11367. geometry = geometryLoader.parse( data.data, this.texturePath ).geometry;
  11368. break;
  11369. default:
  11370. console.warn( 'THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"' );
  11371. continue;
  11372. }
  11373. geometry.uuid = data.uuid;
  11374. if ( data.name !== undefined ) geometry.name = data.name;
  11375. geometries[ data.uuid ] = geometry;
  11376. }
  11377. }
  11378. return geometries;
  11379. },
  11380. parseMaterials: function ( json, textures ) {
  11381. var materials = {};
  11382. if ( json !== undefined ) {
  11383. var loader = new THREE.MaterialLoader();
  11384. loader.setTextures( textures );
  11385. for ( var i = 0, l = json.length; i < l; i ++ ) {
  11386. var material = loader.parse( json[ i ] );
  11387. materials[ material.uuid ] = material;
  11388. }
  11389. }
  11390. return materials;
  11391. },
  11392. parseAnimations: function ( json ) {
  11393. var animations = [];
  11394. for ( var i = 0; i < json.length; i ++ ) {
  11395. var clip = THREE.AnimationClip.parse( json[ i ] );
  11396. animations.push( clip );
  11397. }
  11398. return animations;
  11399. },
  11400. parseImages: function ( json, onLoad ) {
  11401. var scope = this;
  11402. var images = {};
  11403. function loadImage( url ) {
  11404. scope.manager.itemStart( url );
  11405. return loader.load( url, function () {
  11406. scope.manager.itemEnd( url );
  11407. } );
  11408. }
  11409. if ( json !== undefined && json.length > 0 ) {
  11410. var manager = new THREE.LoadingManager( onLoad );
  11411. var loader = new THREE.ImageLoader( manager );
  11412. loader.setCrossOrigin( this.crossOrigin );
  11413. for ( var i = 0, l = json.length; i < l; i ++ ) {
  11414. var image = json[ i ];
  11415. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( image.url ) ? image.url : scope.texturePath + image.url;
  11416. images[ image.uuid ] = loadImage( path );
  11417. }
  11418. }
  11419. return images;
  11420. },
  11421. parseTextures: function ( json, images ) {
  11422. function parseConstant( value ) {
  11423. if ( typeof( value ) === 'number' ) return value;
  11424. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  11425. return THREE[ value ];
  11426. }
  11427. var textures = {};
  11428. if ( json !== undefined ) {
  11429. for ( var i = 0, l = json.length; i < l; i ++ ) {
  11430. var data = json[ i ];
  11431. if ( data.image === undefined ) {
  11432. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  11433. }
  11434. if ( images[ data.image ] === undefined ) {
  11435. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  11436. }
  11437. var texture = new THREE.Texture( images[ data.image ] );
  11438. texture.needsUpdate = true;
  11439. texture.uuid = data.uuid;
  11440. if ( data.name !== undefined ) texture.name = data.name;
  11441. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping );
  11442. if ( data.offset !== undefined ) texture.offset = new THREE.Vector2( data.offset[ 0 ], data.offset[ 1 ] );
  11443. if ( data.repeat !== undefined ) texture.repeat = new THREE.Vector2( data.repeat[ 0 ], data.repeat[ 1 ] );
  11444. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter );
  11445. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter );
  11446. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  11447. if ( Array.isArray( data.wrap ) ) {
  11448. texture.wrapS = parseConstant( data.wrap[ 0 ] );
  11449. texture.wrapT = parseConstant( data.wrap[ 1 ] );
  11450. }
  11451. textures[ data.uuid ] = texture;
  11452. }
  11453. }
  11454. return textures;
  11455. },
  11456. parseObject: function () {
  11457. var matrix = new THREE.Matrix4();
  11458. return function ( data, geometries, materials ) {
  11459. var object;
  11460. function getGeometry( name ) {
  11461. if ( geometries[ name ] === undefined ) {
  11462. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  11463. }
  11464. return geometries[ name ];
  11465. }
  11466. function getMaterial( name ) {
  11467. if ( name === undefined ) return undefined;
  11468. if ( materials[ name ] === undefined ) {
  11469. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  11470. }
  11471. return materials[ name ];
  11472. }
  11473. switch ( data.type ) {
  11474. case 'Scene':
  11475. object = new THREE.Scene();
  11476. break;
  11477. case 'PerspectiveCamera':
  11478. object = new THREE.PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  11479. break;
  11480. case 'OrthographicCamera':
  11481. object = new THREE.OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  11482. break;
  11483. case 'AmbientLight':
  11484. object = new THREE.AmbientLight( data.color, data.intensity );
  11485. break;
  11486. case 'DirectionalLight':
  11487. object = new THREE.DirectionalLight( data.color, data.intensity );
  11488. break;
  11489. case 'PointLight':
  11490. object = new THREE.PointLight( data.color, data.intensity, data.distance, data.decay );
  11491. break;
  11492. case 'SpotLight':
  11493. object = new THREE.SpotLight( data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay );
  11494. break;
  11495. case 'HemisphereLight':
  11496. object = new THREE.HemisphereLight( data.color, data.groundColor, data.intensity );
  11497. break;
  11498. case 'Mesh':
  11499. var geometry = getGeometry( data.geometry );
  11500. var material = getMaterial( data.material );
  11501. if ( geometry.bones && geometry.bones.length > 0 ) {
  11502. object = new THREE.SkinnedMesh( geometry, material );
  11503. } else {
  11504. object = new THREE.Mesh( geometry, material );
  11505. }
  11506. break;
  11507. case 'LOD':
  11508. object = new THREE.LOD();
  11509. break;
  11510. case 'Line':
  11511. object = new THREE.Line( getGeometry( data.geometry ), getMaterial( data.material ), data.mode );
  11512. break;
  11513. case 'PointCloud':
  11514. case 'Points':
  11515. object = new THREE.Points( getGeometry( data.geometry ), getMaterial( data.material ) );
  11516. break;
  11517. case 'Sprite':
  11518. object = new THREE.Sprite( getMaterial( data.material ) );
  11519. break;
  11520. case 'Group':
  11521. object = new THREE.Group();
  11522. break;
  11523. default:
  11524. object = new THREE.Object3D();
  11525. }
  11526. object.uuid = data.uuid;
  11527. if ( data.name !== undefined ) object.name = data.name;
  11528. if ( data.matrix !== undefined ) {
  11529. matrix.fromArray( data.matrix );
  11530. matrix.decompose( object.position, object.quaternion, object.scale );
  11531. } else {
  11532. if ( data.position !== undefined ) object.position.fromArray( data.position );
  11533. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  11534. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  11535. }
  11536. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  11537. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  11538. if ( data.visible !== undefined ) object.visible = data.visible;
  11539. if ( data.userData !== undefined ) object.userData = data.userData;
  11540. if ( data.children !== undefined ) {
  11541. for ( var child in data.children ) {
  11542. object.add( this.parseObject( data.children[ child ], geometries, materials ) );
  11543. }
  11544. }
  11545. if ( data.type === 'LOD' ) {
  11546. var levels = data.levels;
  11547. for ( var l = 0; l < levels.length; l ++ ) {
  11548. var level = levels[ l ];
  11549. var child = object.getObjectByProperty( 'uuid', level.object );
  11550. if ( child !== undefined ) {
  11551. object.addLevel( child, level.distance );
  11552. }
  11553. }
  11554. }
  11555. return object;
  11556. };
  11557. }()
  11558. };
  11559. // File:src/loaders/TextureLoader.js
  11560. /**
  11561. * @author mrdoob / http://mrdoob.com/
  11562. */
  11563. THREE.TextureLoader = function ( manager ) {
  11564. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11565. };
  11566. THREE.TextureLoader.prototype = {
  11567. constructor: THREE.TextureLoader,
  11568. load: function ( url, onLoad, onProgress, onError ) {
  11569. var texture = new THREE.Texture();
  11570. var loader = new THREE.ImageLoader( this.manager );
  11571. loader.setCrossOrigin( this.crossOrigin );
  11572. loader.setPath( this.path );
  11573. loader.load( url, function ( image ) {
  11574. texture.image = image;
  11575. texture.needsUpdate = true;
  11576. if ( onLoad !== undefined ) {
  11577. onLoad( texture );
  11578. }
  11579. }, onProgress, onError );
  11580. return texture;
  11581. },
  11582. setCrossOrigin: function ( value ) {
  11583. this.crossOrigin = value;
  11584. },
  11585. setPath: function ( value ) {
  11586. this.path = value;
  11587. }
  11588. };
  11589. // File:src/loaders/CubeTextureLoader.js
  11590. /**
  11591. * @author mrdoob / http://mrdoob.com/
  11592. */
  11593. THREE.CubeTextureLoader = function ( manager ) {
  11594. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11595. };
  11596. THREE.CubeTextureLoader.prototype = {
  11597. constructor: THREE.CubeTextureLoader,
  11598. load: function ( urls, onLoad, onProgress, onError ) {
  11599. var texture = new THREE.CubeTexture();
  11600. var loader = new THREE.ImageLoader( this.manager );
  11601. loader.setCrossOrigin( this.crossOrigin );
  11602. loader.setPath( this.path );
  11603. var loaded = 0;
  11604. function loadTexture( i ) {
  11605. loader.load( urls[ i ], function ( image ) {
  11606. texture.images[ i ] = image;
  11607. loaded ++;
  11608. if ( loaded === 6 ) {
  11609. texture.needsUpdate = true;
  11610. if ( onLoad ) onLoad( texture );
  11611. }
  11612. }, undefined, onError );
  11613. }
  11614. for ( var i = 0; i < urls.length; ++ i ) {
  11615. loadTexture( i );
  11616. }
  11617. return texture;
  11618. },
  11619. setCrossOrigin: function ( value ) {
  11620. this.crossOrigin = value;
  11621. },
  11622. setPath: function ( value ) {
  11623. this.path = value;
  11624. }
  11625. };
  11626. // File:src/loaders/BinaryTextureLoader.js
  11627. /**
  11628. * @author Nikos M. / https://github.com/foo123/
  11629. *
  11630. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  11631. */
  11632. THREE.DataTextureLoader = THREE.BinaryTextureLoader = function ( manager ) {
  11633. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11634. // override in sub classes
  11635. this._parser = null;
  11636. };
  11637. THREE.BinaryTextureLoader.prototype = {
  11638. constructor: THREE.BinaryTextureLoader,
  11639. load: function ( url, onLoad, onProgress, onError ) {
  11640. var scope = this;
  11641. var texture = new THREE.DataTexture();
  11642. var loader = new THREE.XHRLoader( this.manager );
  11643. loader.setResponseType( 'arraybuffer' );
  11644. loader.load( url, function ( buffer ) {
  11645. var texData = scope._parser( buffer );
  11646. if ( ! texData ) return;
  11647. if ( undefined !== texData.image ) {
  11648. texture.image = texData.image;
  11649. } else if ( undefined !== texData.data ) {
  11650. texture.image.width = texData.width;
  11651. texture.image.height = texData.height;
  11652. texture.image.data = texData.data;
  11653. }
  11654. texture.wrapS = undefined !== texData.wrapS ? texData.wrapS : THREE.ClampToEdgeWrapping;
  11655. texture.wrapT = undefined !== texData.wrapT ? texData.wrapT : THREE.ClampToEdgeWrapping;
  11656. texture.magFilter = undefined !== texData.magFilter ? texData.magFilter : THREE.LinearFilter;
  11657. texture.minFilter = undefined !== texData.minFilter ? texData.minFilter : THREE.LinearMipMapLinearFilter;
  11658. texture.anisotropy = undefined !== texData.anisotropy ? texData.anisotropy : 1;
  11659. if ( undefined !== texData.format ) {
  11660. texture.format = texData.format;
  11661. }
  11662. if ( undefined !== texData.type ) {
  11663. texture.type = texData.type;
  11664. }
  11665. if ( undefined !== texData.mipmaps ) {
  11666. texture.mipmaps = texData.mipmaps;
  11667. }
  11668. if ( 1 === texData.mipmapCount ) {
  11669. texture.minFilter = THREE.LinearFilter;
  11670. }
  11671. texture.needsUpdate = true;
  11672. if ( onLoad ) onLoad( texture, texData );
  11673. }, onProgress, onError );
  11674. return texture;
  11675. }
  11676. };
  11677. // File:src/loaders/CompressedTextureLoader.js
  11678. /**
  11679. * @author mrdoob / http://mrdoob.com/
  11680. *
  11681. * Abstract Base class to block based textures loader (dds, pvr, ...)
  11682. */
  11683. THREE.CompressedTextureLoader = function ( manager ) {
  11684. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11685. // override in sub classes
  11686. this._parser = null;
  11687. };
  11688. THREE.CompressedTextureLoader.prototype = {
  11689. constructor: THREE.CompressedTextureLoader,
  11690. load: function ( url, onLoad, onProgress, onError ) {
  11691. var scope = this;
  11692. var images = [];
  11693. var texture = new THREE.CompressedTexture();
  11694. texture.image = images;
  11695. var loader = new THREE.XHRLoader( this.manager );
  11696. loader.setPath( this.path );
  11697. loader.setResponseType( 'arraybuffer' );
  11698. function loadTexture( i ) {
  11699. loader.load( url[ i ], function ( buffer ) {
  11700. var texDatas = scope._parser( buffer, true );
  11701. images[ i ] = {
  11702. width: texDatas.width,
  11703. height: texDatas.height,
  11704. format: texDatas.format,
  11705. mipmaps: texDatas.mipmaps
  11706. };
  11707. loaded += 1;
  11708. if ( loaded === 6 ) {
  11709. if ( texDatas.mipmapCount === 1 )
  11710. texture.minFilter = THREE.LinearFilter;
  11711. texture.format = texDatas.format;
  11712. texture.needsUpdate = true;
  11713. if ( onLoad ) onLoad( texture );
  11714. }
  11715. }, onProgress, onError );
  11716. }
  11717. if ( Array.isArray( url ) ) {
  11718. var loaded = 0;
  11719. for ( var i = 0, il = url.length; i < il; ++ i ) {
  11720. loadTexture( i );
  11721. }
  11722. } else {
  11723. // compressed cubemap texture stored in a single DDS file
  11724. loader.load( url, function ( buffer ) {
  11725. var texDatas = scope._parser( buffer, true );
  11726. if ( texDatas.isCubemap ) {
  11727. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  11728. for ( var f = 0; f < faces; f ++ ) {
  11729. images[ f ] = { mipmaps : [] };
  11730. for ( var i = 0; i < texDatas.mipmapCount; i ++ ) {
  11731. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  11732. images[ f ].format = texDatas.format;
  11733. images[ f ].width = texDatas.width;
  11734. images[ f ].height = texDatas.height;
  11735. }
  11736. }
  11737. } else {
  11738. texture.image.width = texDatas.width;
  11739. texture.image.height = texDatas.height;
  11740. texture.mipmaps = texDatas.mipmaps;
  11741. }
  11742. if ( texDatas.mipmapCount === 1 ) {
  11743. texture.minFilter = THREE.LinearFilter;
  11744. }
  11745. texture.format = texDatas.format;
  11746. texture.needsUpdate = true;
  11747. if ( onLoad ) onLoad( texture );
  11748. }, onProgress, onError );
  11749. }
  11750. return texture;
  11751. },
  11752. setPath: function ( value ) {
  11753. this.path = value;
  11754. }
  11755. };
  11756. // File:src/materials/Material.js
  11757. /**
  11758. * @author mrdoob / http://mrdoob.com/
  11759. * @author alteredq / http://alteredqualia.com/
  11760. */
  11761. THREE.Material = function () {
  11762. Object.defineProperty( this, 'id', { value: THREE.MaterialIdCount ++ } );
  11763. this.uuid = THREE.Math.generateUUID();
  11764. this.name = '';
  11765. this.type = 'Material';
  11766. this.side = THREE.FrontSide;
  11767. this.opacity = 1;
  11768. this.transparent = false;
  11769. this.blending = THREE.NormalBlending;
  11770. this.blendSrc = THREE.SrcAlphaFactor;
  11771. this.blendDst = THREE.OneMinusSrcAlphaFactor;
  11772. this.blendEquation = THREE.AddEquation;
  11773. this.blendSrcAlpha = null;
  11774. this.blendDstAlpha = null;
  11775. this.blendEquationAlpha = null;
  11776. this.depthFunc = THREE.LessEqualDepth;
  11777. this.depthTest = true;
  11778. this.depthWrite = true;
  11779. this.colorWrite = true;
  11780. this.precision = null; // override the renderer's default precision for this material
  11781. this.polygonOffset = false;
  11782. this.polygonOffsetFactor = 0;
  11783. this.polygonOffsetUnits = 0;
  11784. this.alphaTest = 0;
  11785. this.overdraw = 0; // Overdrawn pixels (typically between 0 and 1) for fixing antialiasing gaps in CanvasRenderer
  11786. this.visible = true;
  11787. this._needsUpdate = true;
  11788. };
  11789. THREE.Material.prototype = {
  11790. constructor: THREE.Material,
  11791. get needsUpdate () {
  11792. return this._needsUpdate;
  11793. },
  11794. set needsUpdate ( value ) {
  11795. if ( value === true ) this.update();
  11796. this._needsUpdate = value;
  11797. },
  11798. setValues: function ( values ) {
  11799. if ( values === undefined ) return;
  11800. for ( var key in values ) {
  11801. var newValue = values[ key ];
  11802. if ( newValue === undefined ) {
  11803. console.warn( "THREE.Material: '" + key + "' parameter is undefined." );
  11804. continue;
  11805. }
  11806. var currentValue = this[ key ];
  11807. if ( currentValue === undefined ) {
  11808. console.warn( "THREE." + this.type + ": '" + key + "' is not a property of this material." );
  11809. continue;
  11810. }
  11811. if ( currentValue instanceof THREE.Color ) {
  11812. currentValue.set( newValue );
  11813. } else if ( currentValue instanceof THREE.Vector3 && newValue instanceof THREE.Vector3 ) {
  11814. currentValue.copy( newValue );
  11815. } else if ( key === 'overdraw' ) {
  11816. // ensure overdraw is backwards-compatible with legacy boolean type
  11817. this[ key ] = Number( newValue );
  11818. } else {
  11819. this[ key ] = newValue;
  11820. }
  11821. }
  11822. },
  11823. toJSON: function ( meta ) {
  11824. var isRoot = meta === undefined;
  11825. if ( isRoot ) {
  11826. meta = {
  11827. textures: {},
  11828. images: {}
  11829. };
  11830. }
  11831. var data = {
  11832. metadata: {
  11833. version: 4.4,
  11834. type: 'Material',
  11835. generator: 'Material.toJSON'
  11836. }
  11837. };
  11838. // standard Material serialization
  11839. data.uuid = this.uuid;
  11840. data.type = this.type;
  11841. if ( this.name !== '' ) data.name = this.name;
  11842. if ( this.color instanceof THREE.Color ) data.color = this.color.getHex();
  11843. if ( this.roughness !== 0.5 ) data.roughness = this.roughness;
  11844. if ( this.metalness !== 0.5 ) data.metalness = this.metalness;
  11845. if ( this.emissive instanceof THREE.Color ) data.emissive = this.emissive.getHex();
  11846. if ( this.specular instanceof THREE.Color ) data.specular = this.specular.getHex();
  11847. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  11848. if ( this.map instanceof THREE.Texture ) data.map = this.map.toJSON( meta ).uuid;
  11849. if ( this.alphaMap instanceof THREE.Texture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  11850. if ( this.lightMap instanceof THREE.Texture ) data.lightMap = this.lightMap.toJSON( meta ).uuid;
  11851. if ( this.bumpMap instanceof THREE.Texture ) {
  11852. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  11853. data.bumpScale = this.bumpScale;
  11854. }
  11855. if ( this.normalMap instanceof THREE.Texture ) {
  11856. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  11857. data.normalScale = this.normalScale.toArray();
  11858. }
  11859. if ( this.displacementMap instanceof THREE.Texture ) {
  11860. data.displacementMap = this.displacementMap.toJSON( meta ).uuid;
  11861. data.displacementScale = this.displacementScale;
  11862. data.displacementBias = this.displacementBias;
  11863. }
  11864. if ( this.roughnessMap instanceof THREE.Texture ) data.roughnessMap = this.roughnessMap.toJSON( meta ).uuid;
  11865. if ( this.metalnessMap instanceof THREE.Texture ) data.metalnessMap = this.metalnessMap.toJSON( meta ).uuid;
  11866. if ( this.emissiveMap instanceof THREE.Texture ) data.emissiveMap = this.emissiveMap.toJSON( meta ).uuid;
  11867. if ( this.specularMap instanceof THREE.Texture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  11868. if ( this.envMap instanceof THREE.Texture ) {
  11869. data.envMap = this.envMap.toJSON( meta ).uuid;
  11870. data.reflectivity = this.reflectivity; // Scale behind envMap
  11871. }
  11872. if ( this.size !== undefined ) data.size = this.size;
  11873. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  11874. if ( this.vertexColors !== undefined && this.vertexColors !== THREE.NoColors ) data.vertexColors = this.vertexColors;
  11875. if ( this.shading !== undefined && this.shading !== THREE.SmoothShading ) data.shading = this.shading;
  11876. if ( this.blending !== undefined && this.blending !== THREE.NormalBlending ) data.blending = this.blending;
  11877. if ( this.side !== undefined && this.side !== THREE.FrontSide ) data.side = this.side;
  11878. if ( this.opacity < 1 ) data.opacity = this.opacity;
  11879. if ( this.transparent === true ) data.transparent = this.transparent;
  11880. if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
  11881. if ( this.wireframe === true ) data.wireframe = this.wireframe;
  11882. if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;
  11883. // TODO: Copied from Object3D.toJSON
  11884. function extractFromCache ( cache ) {
  11885. var values = [];
  11886. for ( var key in cache ) {
  11887. var data = cache[ key ];
  11888. delete data.metadata;
  11889. values.push( data );
  11890. }
  11891. return values;
  11892. }
  11893. if ( isRoot ) {
  11894. var textures = extractFromCache( meta.textures );
  11895. var images = extractFromCache( meta.images );
  11896. if ( textures.length > 0 ) data.textures = textures;
  11897. if ( images.length > 0 ) data.images = images;
  11898. }
  11899. return data;
  11900. },
  11901. clone: function () {
  11902. return new this.constructor().copy( this );
  11903. },
  11904. copy: function ( source ) {
  11905. this.name = source.name;
  11906. this.side = source.side;
  11907. this.opacity = source.opacity;
  11908. this.transparent = source.transparent;
  11909. this.blending = source.blending;
  11910. this.blendSrc = source.blendSrc;
  11911. this.blendDst = source.blendDst;
  11912. this.blendEquation = source.blendEquation;
  11913. this.blendSrcAlpha = source.blendSrcAlpha;
  11914. this.blendDstAlpha = source.blendDstAlpha;
  11915. this.blendEquationAlpha = source.blendEquationAlpha;
  11916. this.depthFunc = source.depthFunc;
  11917. this.depthTest = source.depthTest;
  11918. this.depthWrite = source.depthWrite;
  11919. this.colorWrite = source.colorWrite;
  11920. this.precision = source.precision;
  11921. this.polygonOffset = source.polygonOffset;
  11922. this.polygonOffsetFactor = source.polygonOffsetFactor;
  11923. this.polygonOffsetUnits = source.polygonOffsetUnits;
  11924. this.alphaTest = source.alphaTest;
  11925. this.overdraw = source.overdraw;
  11926. this.visible = source.visible;
  11927. return this;
  11928. },
  11929. update: function () {
  11930. this.dispatchEvent( { type: 'update' } );
  11931. },
  11932. dispose: function () {
  11933. this.dispatchEvent( { type: 'dispose' } );
  11934. }
  11935. };
  11936. THREE.EventDispatcher.prototype.apply( THREE.Material.prototype );
  11937. THREE.MaterialIdCount = 0;
  11938. // File:src/materials/LineBasicMaterial.js
  11939. /**
  11940. * @author mrdoob / http://mrdoob.com/
  11941. * @author alteredq / http://alteredqualia.com/
  11942. *
  11943. * parameters = {
  11944. * color: <hex>,
  11945. * opacity: <float>,
  11946. *
  11947. * linewidth: <float>,
  11948. * linecap: "round",
  11949. * linejoin: "round",
  11950. *
  11951. * blending: THREE.PremultipliedAlphaBlending,
  11952. * depthTest: <bool>,
  11953. * depthWrite: <bool>,
  11954. *
  11955. * vertexColors: <bool>
  11956. *
  11957. * fog: <bool>
  11958. * }
  11959. */
  11960. THREE.LineBasicMaterial = function ( parameters ) {
  11961. THREE.Material.call( this );
  11962. this.type = 'LineBasicMaterial';
  11963. this.color = new THREE.Color( 0xffffff );
  11964. this.linewidth = 1;
  11965. this.linecap = 'round';
  11966. this.linejoin = 'round';
  11967. this.blending = THREE.PremultipliedAlphaBlending;
  11968. this.vertexColors = THREE.NoColors;
  11969. this.fog = true;
  11970. this.setValues( parameters );
  11971. };
  11972. THREE.LineBasicMaterial.prototype = Object.create( THREE.Material.prototype );
  11973. THREE.LineBasicMaterial.prototype.constructor = THREE.LineBasicMaterial;
  11974. THREE.LineBasicMaterial.prototype.copy = function ( source ) {
  11975. THREE.Material.prototype.copy.call( this, source );
  11976. this.color.copy( source.color );
  11977. this.linewidth = source.linewidth;
  11978. this.linecap = source.linecap;
  11979. this.linejoin = source.linejoin;
  11980. this.vertexColors = source.vertexColors;
  11981. this.fog = source.fog;
  11982. return this;
  11983. };
  11984. // File:src/materials/LineDashedMaterial.js
  11985. /**
  11986. * @author alteredq / http://alteredqualia.com/
  11987. *
  11988. * parameters = {
  11989. * color: <hex>,
  11990. * opacity: <float>,
  11991. *
  11992. * linewidth: <float>,
  11993. *
  11994. * scale: <float>,
  11995. * dashSize: <float>,
  11996. * gapSize: <float>,
  11997. *
  11998. * blending: THREE.PremultipliedAlphaBlending,
  11999. * depthTest: <bool>,
  12000. * depthWrite: <bool>,
  12001. *
  12002. * vertexColors: THREE.NoColors / THREE.FaceColors / THREE.VertexColors
  12003. *
  12004. * fog: <bool>
  12005. * }
  12006. */
  12007. THREE.LineDashedMaterial = function ( parameters ) {
  12008. THREE.Material.call( this );
  12009. this.type = 'LineDashedMaterial';
  12010. this.color = new THREE.Color( 0xffffff );
  12011. this.linewidth = 1;
  12012. this.scale = 1;
  12013. this.dashSize = 3;
  12014. this.gapSize = 1;
  12015. this.blending = THREE.PremultipliedAlphaBlending;
  12016. this.vertexColors = THREE.NoColors;
  12017. this.fog = true;
  12018. this.setValues( parameters );
  12019. };
  12020. THREE.LineDashedMaterial.prototype = Object.create( THREE.Material.prototype );
  12021. THREE.LineDashedMaterial.prototype.constructor = THREE.LineDashedMaterial;
  12022. THREE.LineDashedMaterial.prototype.copy = function ( source ) {
  12023. THREE.Material.prototype.copy.call( this, source );
  12024. this.color.copy( source.color );
  12025. this.linewidth = source.linewidth;
  12026. this.scale = source.scale;
  12027. this.dashSize = source.dashSize;
  12028. this.gapSize = source.gapSize;
  12029. this.vertexColors = source.vertexColors;
  12030. this.fog = source.fog;
  12031. return this;
  12032. };
  12033. // File:src/materials/MeshBasicMaterial.js
  12034. /**
  12035. * @author mrdoob / http://mrdoob.com/
  12036. * @author alteredq / http://alteredqualia.com/
  12037. *
  12038. * parameters = {
  12039. * color: <hex>,
  12040. * opacity: <float>,
  12041. * map: new THREE.Texture( <Image> ),
  12042. *
  12043. * aoMap: new THREE.Texture( <Image> ),
  12044. * aoMapIntensity: <float>
  12045. *
  12046. * specularMap: new THREE.Texture( <Image> ),
  12047. *
  12048. * alphaMap: new THREE.Texture( <Image> ),
  12049. *
  12050. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  12051. * combine: THREE.Multiply,
  12052. * reflectivity: <float>,
  12053. * refractionRatio: <float>,
  12054. *
  12055. * shading: THREE.SmoothShading,
  12056. * blending: THREE.PremultipliedAlphaBlending,
  12057. * depthTest: <bool>,
  12058. * depthWrite: <bool>,
  12059. *
  12060. * wireframe: <boolean>,
  12061. * wireframeLinewidth: <float>,
  12062. *
  12063. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  12064. *
  12065. * skinning: <bool>,
  12066. * morphTargets: <bool>,
  12067. *
  12068. * fog: <bool>
  12069. * }
  12070. */
  12071. THREE.MeshBasicMaterial = function ( parameters ) {
  12072. THREE.Material.call( this );
  12073. this.type = 'MeshBasicMaterial';
  12074. this.color = new THREE.Color( 0xffffff ); // emissive
  12075. this.map = null;
  12076. this.aoMap = null;
  12077. this.aoMapIntensity = 1.0;
  12078. this.specularMap = null;
  12079. this.alphaMap = null;
  12080. this.envMap = null;
  12081. this.combine = THREE.MultiplyOperation;
  12082. this.reflectivity = 1;
  12083. this.refractionRatio = 0.98;
  12084. this.fog = true;
  12085. this.shading = THREE.SmoothShading;
  12086. this.blending = THREE.PremultipliedAlphaBlending;
  12087. this.wireframe = false;
  12088. this.wireframeLinewidth = 1;
  12089. this.wireframeLinecap = 'round';
  12090. this.wireframeLinejoin = 'round';
  12091. this.vertexColors = THREE.NoColors;
  12092. this.skinning = false;
  12093. this.morphTargets = false;
  12094. this.setValues( parameters );
  12095. };
  12096. THREE.MeshBasicMaterial.prototype = Object.create( THREE.Material.prototype );
  12097. THREE.MeshBasicMaterial.prototype.constructor = THREE.MeshBasicMaterial;
  12098. THREE.MeshBasicMaterial.prototype.copy = function ( source ) {
  12099. THREE.Material.prototype.copy.call( this, source );
  12100. this.color.copy( source.color );
  12101. this.map = source.map;
  12102. this.aoMap = source.aoMap;
  12103. this.aoMapIntensity = source.aoMapIntensity;
  12104. this.specularMap = source.specularMap;
  12105. this.alphaMap = source.alphaMap;
  12106. this.envMap = source.envMap;
  12107. this.combine = source.combine;
  12108. this.reflectivity = source.reflectivity;
  12109. this.refractionRatio = source.refractionRatio;
  12110. this.fog = source.fog;
  12111. this.shading = source.shading;
  12112. this.wireframe = source.wireframe;
  12113. this.wireframeLinewidth = source.wireframeLinewidth;
  12114. this.wireframeLinecap = source.wireframeLinecap;
  12115. this.wireframeLinejoin = source.wireframeLinejoin;
  12116. this.vertexColors = source.vertexColors;
  12117. this.skinning = source.skinning;
  12118. this.morphTargets = source.morphTargets;
  12119. return this;
  12120. };
  12121. // File:src/materials/MeshLambertMaterial.js
  12122. /**
  12123. * @author mrdoob / http://mrdoob.com/
  12124. * @author alteredq / http://alteredqualia.com/
  12125. *
  12126. * parameters = {
  12127. * color: <hex>,
  12128. * opacity: <float>,
  12129. *
  12130. * map: new THREE.Texture( <Image> ),
  12131. *
  12132. * lightMap: new THREE.Texture( <Image> ),
  12133. * lightMapIntensity: <float>
  12134. *
  12135. * aoMap: new THREE.Texture( <Image> ),
  12136. * aoMapIntensity: <float>
  12137. *
  12138. * emissive: <hex>,
  12139. * emissiveIntensity: <float>
  12140. * emissiveMap: new THREE.Texture( <Image> ),
  12141. *
  12142. * specularMap: new THREE.Texture( <Image> ),
  12143. *
  12144. * alphaMap: new THREE.Texture( <Image> ),
  12145. *
  12146. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  12147. * combine: THREE.Multiply,
  12148. * reflectivity: <float>,
  12149. * refractionRatio: <float>,
  12150. *
  12151. * blending: THREE.PremultipliedAlphaBlending,
  12152. * depthTest: <bool>,
  12153. * depthWrite: <bool>,
  12154. *
  12155. * wireframe: <boolean>,
  12156. * wireframeLinewidth: <float>,
  12157. *
  12158. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  12159. *
  12160. * skinning: <bool>,
  12161. * morphTargets: <bool>,
  12162. * morphNormals: <bool>,
  12163. *
  12164. * fog: <bool>
  12165. * }
  12166. */
  12167. THREE.MeshLambertMaterial = function ( parameters ) {
  12168. THREE.Material.call( this );
  12169. this.type = 'MeshLambertMaterial';
  12170. this.color = new THREE.Color( 0xffffff ); // diffuse
  12171. this.map = null;
  12172. this.lightMap = null;
  12173. this.lightMapIntensity = 1.0;
  12174. this.aoMap = null;
  12175. this.aoMapIntensity = 1.0;
  12176. this.emissive = new THREE.Color( 0x000000 );
  12177. this.emissiveIntensity = 1.0;
  12178. this.emissiveMap = null;
  12179. this.specularMap = null;
  12180. this.alphaMap = null;
  12181. this.envMap = null;
  12182. this.combine = THREE.MultiplyOperation;
  12183. this.reflectivity = 1;
  12184. this.refractionRatio = 0.98;
  12185. this.fog = true;
  12186. this.blending = THREE.PremultipliedAlphaBlending;
  12187. this.wireframe = false;
  12188. this.wireframeLinewidth = 1;
  12189. this.wireframeLinecap = 'round';
  12190. this.wireframeLinejoin = 'round';
  12191. this.vertexColors = THREE.NoColors;
  12192. this.skinning = false;
  12193. this.morphTargets = false;
  12194. this.morphNormals = false;
  12195. this.setValues( parameters );
  12196. };
  12197. THREE.MeshLambertMaterial.prototype = Object.create( THREE.Material.prototype );
  12198. THREE.MeshLambertMaterial.prototype.constructor = THREE.MeshLambertMaterial;
  12199. THREE.MeshLambertMaterial.prototype.copy = function ( source ) {
  12200. THREE.Material.prototype.copy.call( this, source );
  12201. this.color.copy( source.color );
  12202. this.map = source.map;
  12203. this.lightMap = source.lightMap;
  12204. this.lightMapIntensity = source.lightMapIntensity;
  12205. this.aoMap = source.aoMap;
  12206. this.aoMapIntensity = source.aoMapIntensity;
  12207. this.emissive.copy( source.emissive );
  12208. this.emissiveMap = source.emissiveMap;
  12209. this.emissiveIntensity = source.emissiveIntensity;
  12210. this.specularMap = source.specularMap;
  12211. this.alphaMap = source.alphaMap;
  12212. this.envMap = source.envMap;
  12213. this.combine = source.combine;
  12214. this.reflectivity = source.reflectivity;
  12215. this.refractionRatio = source.refractionRatio;
  12216. this.fog = source.fog;
  12217. this.wireframe = source.wireframe;
  12218. this.wireframeLinewidth = source.wireframeLinewidth;
  12219. this.wireframeLinecap = source.wireframeLinecap;
  12220. this.wireframeLinejoin = source.wireframeLinejoin;
  12221. this.vertexColors = source.vertexColors;
  12222. this.skinning = source.skinning;
  12223. this.morphTargets = source.morphTargets;
  12224. this.morphNormals = source.morphNormals;
  12225. return this;
  12226. };
  12227. // File:src/materials/MeshPhongMaterial.js
  12228. /**
  12229. * @author mrdoob / http://mrdoob.com/
  12230. * @author alteredq / http://alteredqualia.com/
  12231. *
  12232. * parameters = {
  12233. * color: <hex>,
  12234. * specular: <hex>,
  12235. * shininess: <float>,
  12236. * opacity: <float>,
  12237. *
  12238. * map: new THREE.Texture( <Image> ),
  12239. *
  12240. * lightMap: new THREE.Texture( <Image> ),
  12241. * lightMapIntensity: <float>
  12242. *
  12243. * aoMap: new THREE.Texture( <Image> ),
  12244. * aoMapIntensity: <float>
  12245. *
  12246. * emissive: <hex>,
  12247. * emissiveIntensity: <float>
  12248. * emissiveMap: new THREE.Texture( <Image> ),
  12249. *
  12250. * bumpMap: new THREE.Texture( <Image> ),
  12251. * bumpScale: <float>,
  12252. *
  12253. * normalMap: new THREE.Texture( <Image> ),
  12254. * normalScale: <Vector2>,
  12255. *
  12256. * displacementMap: new THREE.Texture( <Image> ),
  12257. * displacementScale: <float>,
  12258. * displacementBias: <float>,
  12259. *
  12260. * specularMap: new THREE.Texture( <Image> ),
  12261. *
  12262. * alphaMap: new THREE.Texture( <Image> ),
  12263. *
  12264. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  12265. * combine: THREE.Multiply,
  12266. * reflectivity: <float>,
  12267. * refractionRatio: <float>,
  12268. *
  12269. * shading: THREE.SmoothShading,
  12270. * blending: THREE.PremultipliedAlphaBlending,
  12271. * depthTest: <bool>,
  12272. * depthWrite: <bool>,
  12273. *
  12274. * wireframe: <boolean>,
  12275. * wireframeLinewidth: <float>,
  12276. *
  12277. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  12278. *
  12279. * skinning: <bool>,
  12280. * morphTargets: <bool>,
  12281. * morphNormals: <bool>,
  12282. *
  12283. * fog: <bool>
  12284. * }
  12285. */
  12286. THREE.MeshPhongMaterial = function ( parameters ) {
  12287. THREE.Material.call( this );
  12288. this.type = 'MeshPhongMaterial';
  12289. this.color = new THREE.Color( 0xffffff ); // diffuse
  12290. this.specular = new THREE.Color( 0x111111 );
  12291. this.shininess = 30;
  12292. this.map = null;
  12293. this.lightMap = null;
  12294. this.lightMapIntensity = 1.0;
  12295. this.aoMap = null;
  12296. this.aoMapIntensity = 1.0;
  12297. this.emissive = new THREE.Color( 0x000000 );
  12298. this.emissiveIntensity = 1.0;
  12299. this.emissiveMap = null;
  12300. this.bumpMap = null;
  12301. this.bumpScale = 1;
  12302. this.normalMap = null;
  12303. this.normalScale = new THREE.Vector2( 1, 1 );
  12304. this.displacementMap = null;
  12305. this.displacementScale = 1;
  12306. this.displacementBias = 0;
  12307. this.specularMap = null;
  12308. this.alphaMap = null;
  12309. this.envMap = null;
  12310. this.combine = THREE.MultiplyOperation;
  12311. this.reflectivity = 1;
  12312. this.refractionRatio = 0.98;
  12313. this.fog = true;
  12314. this.shading = THREE.SmoothShading;
  12315. this.blending = THREE.PremultipliedAlphaBlending;
  12316. this.wireframe = false;
  12317. this.wireframeLinewidth = 1;
  12318. this.wireframeLinecap = 'round';
  12319. this.wireframeLinejoin = 'round';
  12320. this.vertexColors = THREE.NoColors;
  12321. this.skinning = false;
  12322. this.morphTargets = false;
  12323. this.morphNormals = false;
  12324. this.setValues( parameters );
  12325. };
  12326. THREE.MeshPhongMaterial.prototype = Object.create( THREE.Material.prototype );
  12327. THREE.MeshPhongMaterial.prototype.constructor = THREE.MeshPhongMaterial;
  12328. THREE.MeshPhongMaterial.prototype.copy = function ( source ) {
  12329. THREE.Material.prototype.copy.call( this, source );
  12330. this.color.copy( source.color );
  12331. this.specular.copy( source.specular );
  12332. this.shininess = source.shininess;
  12333. this.map = source.map;
  12334. this.lightMap = source.lightMap;
  12335. this.lightMapIntensity = source.lightMapIntensity;
  12336. this.aoMap = source.aoMap;
  12337. this.aoMapIntensity = source.aoMapIntensity;
  12338. this.emissive.copy( source.emissive );
  12339. this.emissiveMap = source.emissiveMap;
  12340. this.emissiveIntensity = source.emissiveIntensity;
  12341. this.bumpMap = source.bumpMap;
  12342. this.bumpScale = source.bumpScale;
  12343. this.normalMap = source.normalMap;
  12344. this.normalScale.copy( source.normalScale );
  12345. this.displacementMap = source.displacementMap;
  12346. this.displacementScale = source.displacementScale;
  12347. this.displacementBias = source.displacementBias;
  12348. this.specularMap = source.specularMap;
  12349. this.alphaMap = source.alphaMap;
  12350. this.envMap = source.envMap;
  12351. this.combine = source.combine;
  12352. this.reflectivity = source.reflectivity;
  12353. this.refractionRatio = source.refractionRatio;
  12354. this.fog = source.fog;
  12355. this.shading = source.shading;
  12356. this.wireframe = source.wireframe;
  12357. this.wireframeLinewidth = source.wireframeLinewidth;
  12358. this.wireframeLinecap = source.wireframeLinecap;
  12359. this.wireframeLinejoin = source.wireframeLinejoin;
  12360. this.vertexColors = source.vertexColors;
  12361. this.skinning = source.skinning;
  12362. this.morphTargets = source.morphTargets;
  12363. this.morphNormals = source.morphNormals;
  12364. return this;
  12365. };
  12366. // File:src/materials/MeshStandardMaterial.js
  12367. /**
  12368. * @author WestLangley / http://github.com/WestLangley
  12369. *
  12370. * parameters = {
  12371. * color: <hex>,
  12372. * roughness: <float>,
  12373. * metalness: <float>,
  12374. * opacity: <float>,
  12375. *
  12376. * map: new THREE.Texture( <Image> ),
  12377. *
  12378. * lightMap: new THREE.Texture( <Image> ),
  12379. * lightMapIntensity: <float>
  12380. *
  12381. * aoMap: new THREE.Texture( <Image> ),
  12382. * aoMapIntensity: <float>
  12383. *
  12384. * emissive: <hex>,
  12385. * emissiveIntensity: <float>
  12386. * emissiveMap: new THREE.Texture( <Image> ),
  12387. *
  12388. * bumpMap: new THREE.Texture( <Image> ),
  12389. * bumpScale: <float>,
  12390. *
  12391. * normalMap: new THREE.Texture( <Image> ),
  12392. * normalScale: <Vector2>,
  12393. *
  12394. * displacementMap: new THREE.Texture( <Image> ),
  12395. * displacementScale: <float>,
  12396. * displacementBias: <float>,
  12397. *
  12398. * roughnessMap: new THREE.Texture( <Image> ),
  12399. *
  12400. * metalnessMap: new THREE.Texture( <Image> ),
  12401. *
  12402. * alphaMap: new THREE.Texture( <Image> ),
  12403. *
  12404. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  12405. * envMapIntensity: <float>
  12406. *
  12407. * refractionRatio: <float>,
  12408. *
  12409. * shading: THREE.SmoothShading,
  12410. * blending: THREE.PremultipliedAlphaBlending,
  12411. * depthTest: <bool>,
  12412. * depthWrite: <bool>,
  12413. *
  12414. * wireframe: <boolean>,
  12415. * wireframeLinewidth: <float>,
  12416. *
  12417. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  12418. *
  12419. * skinning: <bool>,
  12420. * morphTargets: <bool>,
  12421. * morphNormals: <bool>,
  12422. *
  12423. * fog: <bool>
  12424. * }
  12425. */
  12426. THREE.MeshStandardMaterial = function ( parameters ) {
  12427. THREE.Material.call( this );
  12428. this.type = 'MeshStandardMaterial';
  12429. this.color = new THREE.Color( 0xffffff ); // diffuse
  12430. this.roughness = 0.5;
  12431. this.metalness = 0.5;
  12432. this.map = null;
  12433. this.lightMap = null;
  12434. this.lightMapIntensity = 1.0;
  12435. this.aoMap = null;
  12436. this.aoMapIntensity = 1.0;
  12437. this.emissive = new THREE.Color( 0x000000 );
  12438. this.emissiveIntensity = 1.0;
  12439. this.emissiveMap = null;
  12440. this.bumpMap = null;
  12441. this.bumpScale = 1;
  12442. this.normalMap = null;
  12443. this.normalScale = new THREE.Vector2( 1, 1 );
  12444. this.displacementMap = null;
  12445. this.displacementScale = 1;
  12446. this.displacementBias = 0;
  12447. this.roughnessMap = null;
  12448. this.metalnessMap = null;
  12449. this.alphaMap = null;
  12450. this.envMap = null;
  12451. this.envMapIntensity = 1.0;
  12452. this.refractionRatio = 0.98;
  12453. this.fog = true;
  12454. this.shading = THREE.SmoothShading;
  12455. this.blending = THREE.PremultipliedAlphaBlending;
  12456. this.wireframe = false;
  12457. this.wireframeLinewidth = 1;
  12458. this.wireframeLinecap = 'round';
  12459. this.wireframeLinejoin = 'round';
  12460. this.vertexColors = THREE.NoColors;
  12461. this.skinning = false;
  12462. this.morphTargets = false;
  12463. this.morphNormals = false;
  12464. this.setValues( parameters );
  12465. };
  12466. THREE.MeshStandardMaterial.prototype = Object.create( THREE.Material.prototype );
  12467. THREE.MeshStandardMaterial.prototype.constructor = THREE.MeshStandardMaterial;
  12468. THREE.MeshStandardMaterial.prototype.copy = function ( source ) {
  12469. THREE.Material.prototype.copy.call( this, source );
  12470. this.color.copy( source.color );
  12471. this.roughness = source.roughness;
  12472. this.metalness = source.metalness;
  12473. this.map = source.map;
  12474. this.lightMap = source.lightMap;
  12475. this.lightMapIntensity = source.lightMapIntensity;
  12476. this.aoMap = source.aoMap;
  12477. this.aoMapIntensity = source.aoMapIntensity;
  12478. this.emissive.copy( source.emissive );
  12479. this.emissiveMap = source.emissiveMap;
  12480. this.emissiveIntensity = source.emissiveIntensity;
  12481. this.bumpMap = source.bumpMap;
  12482. this.bumpScale = source.bumpScale;
  12483. this.normalMap = source.normalMap;
  12484. this.normalScale.copy( source.normalScale );
  12485. this.displacementMap = source.displacementMap;
  12486. this.displacementScale = source.displacementScale;
  12487. this.displacementBias = source.displacementBias;
  12488. this.roughnessMap = source.roughnessMap;
  12489. this.metalnessMap = source.metalnessMap;
  12490. this.alphaMap = source.alphaMap;
  12491. this.envMap = source.envMap;
  12492. this.envMapIntensity = source.envMapIntensity;
  12493. this.refractionRatio = source.refractionRatio;
  12494. this.fog = source.fog;
  12495. this.shading = source.shading;
  12496. this.wireframe = source.wireframe;
  12497. this.wireframeLinewidth = source.wireframeLinewidth;
  12498. this.wireframeLinecap = source.wireframeLinecap;
  12499. this.wireframeLinejoin = source.wireframeLinejoin;
  12500. this.vertexColors = source.vertexColors;
  12501. this.skinning = source.skinning;
  12502. this.morphTargets = source.morphTargets;
  12503. this.morphNormals = source.morphNormals;
  12504. return this;
  12505. };
  12506. // File:src/materials/MeshDepthMaterial.js
  12507. /**
  12508. * @author mrdoob / http://mrdoob.com/
  12509. * @author alteredq / http://alteredqualia.com/
  12510. *
  12511. * parameters = {
  12512. * opacity: <float>,
  12513. *
  12514. * blending: THREE.NormalBlending,
  12515. * depthTest: <bool>,
  12516. * depthWrite: <bool>,
  12517. *
  12518. * wireframe: <boolean>,
  12519. * wireframeLinewidth: <float>
  12520. * }
  12521. */
  12522. THREE.MeshDepthMaterial = function ( parameters ) {
  12523. THREE.Material.call( this );
  12524. this.type = 'MeshDepthMaterial';
  12525. this.morphTargets = false;
  12526. this.wireframe = false;
  12527. this.wireframeLinewidth = 1;
  12528. this.setValues( parameters );
  12529. };
  12530. THREE.MeshDepthMaterial.prototype = Object.create( THREE.Material.prototype );
  12531. THREE.MeshDepthMaterial.prototype.constructor = THREE.MeshDepthMaterial;
  12532. THREE.MeshDepthMaterial.prototype.copy = function ( source ) {
  12533. THREE.Material.prototype.copy.call( this, source );
  12534. this.wireframe = source.wireframe;
  12535. this.wireframeLinewidth = source.wireframeLinewidth;
  12536. return this;
  12537. };
  12538. // File:src/materials/MeshNormalMaterial.js
  12539. /**
  12540. * @author mrdoob / http://mrdoob.com/
  12541. *
  12542. * parameters = {
  12543. * opacity: <float>,
  12544. *
  12545. * blending: THREE.NormalBlending,
  12546. * depthTest: <bool>,
  12547. * depthWrite: <bool>,
  12548. *
  12549. * wireframe: <boolean>,
  12550. * wireframeLinewidth: <float>
  12551. * }
  12552. */
  12553. THREE.MeshNormalMaterial = function ( parameters ) {
  12554. THREE.Material.call( this, parameters );
  12555. this.type = 'MeshNormalMaterial';
  12556. this.wireframe = false;
  12557. this.wireframeLinewidth = 1;
  12558. this.morphTargets = false;
  12559. this.setValues( parameters );
  12560. };
  12561. THREE.MeshNormalMaterial.prototype = Object.create( THREE.Material.prototype );
  12562. THREE.MeshNormalMaterial.prototype.constructor = THREE.MeshNormalMaterial;
  12563. THREE.MeshNormalMaterial.prototype.copy = function ( source ) {
  12564. THREE.Material.prototype.copy.call( this, source );
  12565. this.wireframe = source.wireframe;
  12566. this.wireframeLinewidth = source.wireframeLinewidth;
  12567. return this;
  12568. };
  12569. // File:src/materials/MultiMaterial.js
  12570. /**
  12571. * @author mrdoob / http://mrdoob.com/
  12572. */
  12573. THREE.MultiMaterial = function ( materials ) {
  12574. this.uuid = THREE.Math.generateUUID();
  12575. this.type = 'MultiMaterial';
  12576. this.materials = materials instanceof Array ? materials : [];
  12577. this.visible = true;
  12578. };
  12579. THREE.MultiMaterial.prototype = {
  12580. constructor: THREE.MultiMaterial,
  12581. toJSON: function ( meta ) {
  12582. var output = {
  12583. metadata: {
  12584. version: 4.2,
  12585. type: 'material',
  12586. generator: 'MaterialExporter'
  12587. },
  12588. uuid: this.uuid,
  12589. type: this.type,
  12590. materials: []
  12591. };
  12592. var materials = this.materials;
  12593. for ( var i = 0, l = materials.length; i < l; i ++ ) {
  12594. var material = materials[ i ].toJSON( meta );
  12595. delete material.metadata;
  12596. output.materials.push( material );
  12597. }
  12598. output.visible = this.visible;
  12599. return output;
  12600. },
  12601. clone: function () {
  12602. var material = new this.constructor();
  12603. for ( var i = 0; i < this.materials.length; i ++ ) {
  12604. material.materials.push( this.materials[ i ].clone() );
  12605. }
  12606. material.visible = this.visible;
  12607. return material;
  12608. }
  12609. };
  12610. // File:src/materials/PointsMaterial.js
  12611. /**
  12612. * @author mrdoob / http://mrdoob.com/
  12613. * @author alteredq / http://alteredqualia.com/
  12614. *
  12615. * parameters = {
  12616. * color: <hex>,
  12617. * opacity: <float>,
  12618. * map: new THREE.Texture( <Image> ),
  12619. *
  12620. * size: <float>,
  12621. * sizeAttenuation: <bool>,
  12622. *
  12623. * blending: THREE.PremultipliedAlphaBlending,
  12624. * depthTest: <bool>,
  12625. * depthWrite: <bool>,
  12626. *
  12627. * vertexColors: <bool>,
  12628. *
  12629. * fog: <bool>
  12630. * }
  12631. */
  12632. THREE.PointsMaterial = function ( parameters ) {
  12633. THREE.Material.call( this );
  12634. this.type = 'PointsMaterial';
  12635. this.color = new THREE.Color( 0xffffff );
  12636. this.map = null;
  12637. this.size = 1;
  12638. this.sizeAttenuation = true;
  12639. this.blending = THREE.PremultipliedAlphaBlending;
  12640. this.vertexColors = THREE.NoColors;
  12641. this.fog = true;
  12642. this.setValues( parameters );
  12643. };
  12644. THREE.PointsMaterial.prototype = Object.create( THREE.Material.prototype );
  12645. THREE.PointsMaterial.prototype.constructor = THREE.PointsMaterial;
  12646. THREE.PointsMaterial.prototype.copy = function ( source ) {
  12647. THREE.Material.prototype.copy.call( this, source );
  12648. this.color.copy( source.color );
  12649. this.map = source.map;
  12650. this.size = source.size;
  12651. this.sizeAttenuation = source.sizeAttenuation;
  12652. this.vertexColors = source.vertexColors;
  12653. this.fog = source.fog;
  12654. return this;
  12655. };
  12656. // File:src/materials/ShaderMaterial.js
  12657. /**
  12658. * @author alteredq / http://alteredqualia.com/
  12659. *
  12660. * parameters = {
  12661. * defines: { "label" : "value" },
  12662. * uniforms: { "parameter1": { type: "f", value: 1.0 }, "parameter2": { type: "i" value2: 2 } },
  12663. *
  12664. * fragmentShader: <string>,
  12665. * vertexShader: <string>,
  12666. *
  12667. * shading: THREE.SmoothShading,
  12668. * blending: THREE.NormalBlending,
  12669. * depthTest: <bool>,
  12670. * depthWrite: <bool>,
  12671. *
  12672. * wireframe: <boolean>,
  12673. * wireframeLinewidth: <float>,
  12674. *
  12675. * lights: <bool>,
  12676. *
  12677. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  12678. *
  12679. * skinning: <bool>,
  12680. * morphTargets: <bool>,
  12681. * morphNormals: <bool>,
  12682. *
  12683. * fog: <bool>
  12684. * }
  12685. */
  12686. THREE.ShaderMaterial = function ( parameters ) {
  12687. THREE.Material.call( this );
  12688. this.type = 'ShaderMaterial';
  12689. this.defines = {};
  12690. this.uniforms = {};
  12691. this.vertexShader = 'void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}';
  12692. this.fragmentShader = 'void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}';
  12693. this.shading = THREE.SmoothShading;
  12694. this.linewidth = 1;
  12695. this.wireframe = false;
  12696. this.wireframeLinewidth = 1;
  12697. this.fog = false; // set to use scene fog
  12698. this.lights = false; // set to use scene lights
  12699. this.vertexColors = THREE.NoColors; // set to use "color" attribute stream
  12700. this.skinning = false; // set to use skinning attribute streams
  12701. this.morphTargets = false; // set to use morph targets
  12702. this.morphNormals = false; // set to use morph normals
  12703. this.extensions = {
  12704. derivatives: false, // set to use derivatives
  12705. fragDepth: false, // set to use fragment depth values
  12706. drawBuffers: false, // set to use draw buffers
  12707. shaderTextureLOD: false // set to use shader texture LOD
  12708. };
  12709. // When rendered geometry doesn't include these attributes but the material does,
  12710. // use these default values in WebGL. This avoids errors when buffer data is missing.
  12711. this.defaultAttributeValues = {
  12712. 'color': [ 1, 1, 1 ],
  12713. 'uv': [ 0, 0 ],
  12714. 'uv2': [ 0, 0 ]
  12715. };
  12716. this.index0AttributeName = undefined;
  12717. if ( parameters !== undefined ) {
  12718. if ( parameters.attributes !== undefined ) {
  12719. console.error( 'THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.' );
  12720. }
  12721. this.setValues( parameters );
  12722. }
  12723. };
  12724. THREE.ShaderMaterial.prototype = Object.create( THREE.Material.prototype );
  12725. THREE.ShaderMaterial.prototype.constructor = THREE.ShaderMaterial;
  12726. THREE.ShaderMaterial.prototype.copy = function ( source ) {
  12727. THREE.Material.prototype.copy.call( this, source );
  12728. this.fragmentShader = source.fragmentShader;
  12729. this.vertexShader = source.vertexShader;
  12730. this.uniforms = THREE.UniformsUtils.clone( source.uniforms );
  12731. this.defines = source.defines;
  12732. this.shading = source.shading;
  12733. this.wireframe = source.wireframe;
  12734. this.wireframeLinewidth = source.wireframeLinewidth;
  12735. this.fog = source.fog;
  12736. this.lights = source.lights;
  12737. this.vertexColors = source.vertexColors;
  12738. this.skinning = source.skinning;
  12739. this.morphTargets = source.morphTargets;
  12740. this.morphNormals = source.morphNormals;
  12741. this.extensions = source.extensions;
  12742. return this;
  12743. };
  12744. THREE.ShaderMaterial.prototype.toJSON = function ( meta ) {
  12745. var data = THREE.Material.prototype.toJSON.call( this, meta );
  12746. data.uniforms = this.uniforms;
  12747. data.vertexShader = this.vertexShader;
  12748. data.fragmentShader = this.fragmentShader;
  12749. return data;
  12750. };
  12751. // File:src/materials/RawShaderMaterial.js
  12752. /**
  12753. * @author mrdoob / http://mrdoob.com/
  12754. */
  12755. THREE.RawShaderMaterial = function ( parameters ) {
  12756. THREE.ShaderMaterial.call( this, parameters );
  12757. this.type = 'RawShaderMaterial';
  12758. };
  12759. THREE.RawShaderMaterial.prototype = Object.create( THREE.ShaderMaterial.prototype );
  12760. THREE.RawShaderMaterial.prototype.constructor = THREE.RawShaderMaterial;
  12761. // File:src/materials/SpriteMaterial.js
  12762. /**
  12763. * @author alteredq / http://alteredqualia.com/
  12764. *
  12765. * parameters = {
  12766. * color: <hex>,
  12767. * opacity: <float>,
  12768. * map: new THREE.Texture( <Image> ),
  12769. *
  12770. * blending: THREE.NormalBlending,
  12771. * depthTest: <bool>,
  12772. * depthWrite: <bool>,
  12773. *
  12774. * uvOffset: new THREE.Vector2(),
  12775. * uvScale: new THREE.Vector2(),
  12776. *
  12777. * fog: <bool>
  12778. * }
  12779. */
  12780. THREE.SpriteMaterial = function ( parameters ) {
  12781. THREE.Material.call( this );
  12782. this.type = 'SpriteMaterial';
  12783. this.color = new THREE.Color( 0xffffff );
  12784. this.map = null;
  12785. this.rotation = 0;
  12786. this.fog = false;
  12787. // set parameters
  12788. this.setValues( parameters );
  12789. };
  12790. THREE.SpriteMaterial.prototype = Object.create( THREE.Material.prototype );
  12791. THREE.SpriteMaterial.prototype.constructor = THREE.SpriteMaterial;
  12792. THREE.SpriteMaterial.prototype.copy = function ( source ) {
  12793. THREE.Material.prototype.copy.call( this, source );
  12794. this.color.copy( source.color );
  12795. this.map = source.map;
  12796. this.rotation = source.rotation;
  12797. this.fog = source.fog;
  12798. return this;
  12799. };
  12800. // File:src/textures/Texture.js
  12801. /**
  12802. * @author mrdoob / http://mrdoob.com/
  12803. * @author alteredq / http://alteredqualia.com/
  12804. * @author szimek / https://github.com/szimek/
  12805. */
  12806. THREE.Texture = function ( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  12807. Object.defineProperty( this, 'id', { value: THREE.TextureIdCount ++ } );
  12808. this.uuid = THREE.Math.generateUUID();
  12809. this.name = '';
  12810. this.sourceFile = '';
  12811. this.image = image !== undefined ? image : THREE.Texture.DEFAULT_IMAGE;
  12812. this.mipmaps = [];
  12813. this.mapping = mapping !== undefined ? mapping : THREE.Texture.DEFAULT_MAPPING;
  12814. this.wrapS = wrapS !== undefined ? wrapS : THREE.ClampToEdgeWrapping;
  12815. this.wrapT = wrapT !== undefined ? wrapT : THREE.ClampToEdgeWrapping;
  12816. this.magFilter = magFilter !== undefined ? magFilter : THREE.LinearFilter;
  12817. this.minFilter = minFilter !== undefined ? minFilter : THREE.LinearMipMapLinearFilter;
  12818. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  12819. this.format = format !== undefined ? format : THREE.RGBAFormat;
  12820. this.type = type !== undefined ? type : THREE.UnsignedByteType;
  12821. this.offset = new THREE.Vector2( 0, 0 );
  12822. this.repeat = new THREE.Vector2( 1, 1 );
  12823. this.generateMipmaps = true;
  12824. this.premultiplyAlpha = false;
  12825. this.flipY = true;
  12826. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  12827. // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
  12828. //
  12829. // Also changing the encoding after already used by a Material will not automatically make the Material
  12830. // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
  12831. this.encoding = THREE.LinearEncoding;
  12832. this.version = 0;
  12833. this.onUpdate = null;
  12834. };
  12835. THREE.Texture.DEFAULT_IMAGE = undefined;
  12836. THREE.Texture.DEFAULT_MAPPING = THREE.UVMapping;
  12837. THREE.Texture.prototype = {
  12838. constructor: THREE.Texture,
  12839. set needsUpdate ( value ) {
  12840. if ( value === true ) this.version ++;
  12841. },
  12842. clone: function () {
  12843. return new this.constructor().copy( this );
  12844. },
  12845. copy: function ( source ) {
  12846. this.image = source.image;
  12847. this.mipmaps = source.mipmaps.slice( 0 );
  12848. this.mapping = source.mapping;
  12849. this.wrapS = source.wrapS;
  12850. this.wrapT = source.wrapT;
  12851. this.magFilter = source.magFilter;
  12852. this.minFilter = source.minFilter;
  12853. this.anisotropy = source.anisotropy;
  12854. this.format = source.format;
  12855. this.type = source.type;
  12856. this.offset.copy( source.offset );
  12857. this.repeat.copy( source.repeat );
  12858. this.generateMipmaps = source.generateMipmaps;
  12859. this.premultiplyAlpha = source.premultiplyAlpha;
  12860. this.flipY = source.flipY;
  12861. this.unpackAlignment = source.unpackAlignment;
  12862. this.encoding = source.encoding;
  12863. return this;
  12864. },
  12865. toJSON: function ( meta ) {
  12866. if ( meta.textures[ this.uuid ] !== undefined ) {
  12867. return meta.textures[ this.uuid ];
  12868. }
  12869. function getDataURL( image ) {
  12870. var canvas;
  12871. if ( image.toDataURL !== undefined ) {
  12872. canvas = image;
  12873. } else {
  12874. canvas = document.createElement( 'canvas' );
  12875. canvas.width = image.width;
  12876. canvas.height = image.height;
  12877. canvas.getContext( '2d' ).drawImage( image, 0, 0, image.width, image.height );
  12878. }
  12879. if ( canvas.width > 2048 || canvas.height > 2048 ) {
  12880. return canvas.toDataURL( 'image/jpeg', 0.6 );
  12881. } else {
  12882. return canvas.toDataURL( 'image/png' );
  12883. }
  12884. }
  12885. var output = {
  12886. metadata: {
  12887. version: 4.4,
  12888. type: 'Texture',
  12889. generator: 'Texture.toJSON'
  12890. },
  12891. uuid: this.uuid,
  12892. name: this.name,
  12893. mapping: this.mapping,
  12894. repeat: [ this.repeat.x, this.repeat.y ],
  12895. offset: [ this.offset.x, this.offset.y ],
  12896. wrap: [ this.wrapS, this.wrapT ],
  12897. minFilter: this.minFilter,
  12898. magFilter: this.magFilter,
  12899. anisotropy: this.anisotropy
  12900. };
  12901. if ( this.image !== undefined ) {
  12902. // TODO: Move to THREE.Image
  12903. var image = this.image;
  12904. if ( image.uuid === undefined ) {
  12905. image.uuid = THREE.Math.generateUUID(); // UGH
  12906. }
  12907. if ( meta.images[ image.uuid ] === undefined ) {
  12908. meta.images[ image.uuid ] = {
  12909. uuid: image.uuid,
  12910. url: getDataURL( image )
  12911. };
  12912. }
  12913. output.image = image.uuid;
  12914. }
  12915. meta.textures[ this.uuid ] = output;
  12916. return output;
  12917. },
  12918. dispose: function () {
  12919. this.dispatchEvent( { type: 'dispose' } );
  12920. },
  12921. transformUv: function ( uv ) {
  12922. if ( this.mapping !== THREE.UVMapping ) return;
  12923. uv.multiply( this.repeat );
  12924. uv.add( this.offset );
  12925. if ( uv.x < 0 || uv.x > 1 ) {
  12926. switch ( this.wrapS ) {
  12927. case THREE.RepeatWrapping:
  12928. uv.x = uv.x - Math.floor( uv.x );
  12929. break;
  12930. case THREE.ClampToEdgeWrapping:
  12931. uv.x = uv.x < 0 ? 0 : 1;
  12932. break;
  12933. case THREE.MirroredRepeatWrapping:
  12934. if ( Math.abs( Math.floor( uv.x ) % 2 ) === 1 ) {
  12935. uv.x = Math.ceil( uv.x ) - uv.x;
  12936. } else {
  12937. uv.x = uv.x - Math.floor( uv.x );
  12938. }
  12939. break;
  12940. }
  12941. }
  12942. if ( uv.y < 0 || uv.y > 1 ) {
  12943. switch ( this.wrapT ) {
  12944. case THREE.RepeatWrapping:
  12945. uv.y = uv.y - Math.floor( uv.y );
  12946. break;
  12947. case THREE.ClampToEdgeWrapping:
  12948. uv.y = uv.y < 0 ? 0 : 1;
  12949. break;
  12950. case THREE.MirroredRepeatWrapping:
  12951. if ( Math.abs( Math.floor( uv.y ) % 2 ) === 1 ) {
  12952. uv.y = Math.ceil( uv.y ) - uv.y;
  12953. } else {
  12954. uv.y = uv.y - Math.floor( uv.y );
  12955. }
  12956. break;
  12957. }
  12958. }
  12959. if ( this.flipY ) {
  12960. uv.y = 1 - uv.y;
  12961. }
  12962. }
  12963. };
  12964. THREE.EventDispatcher.prototype.apply( THREE.Texture.prototype );
  12965. THREE.TextureIdCount = 0;
  12966. // File:src/textures/CanvasTexture.js
  12967. /**
  12968. * @author mrdoob / http://mrdoob.com/
  12969. */
  12970. THREE.CanvasTexture = function ( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  12971. THREE.Texture.call( this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  12972. this.needsUpdate = true;
  12973. };
  12974. THREE.CanvasTexture.prototype = Object.create( THREE.Texture.prototype );
  12975. THREE.CanvasTexture.prototype.constructor = THREE.CanvasTexture;
  12976. // File:src/textures/CubeTexture.js
  12977. /**
  12978. * @author mrdoob / http://mrdoob.com/
  12979. */
  12980. THREE.CubeTexture = function ( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  12981. images = images !== undefined ? images : [];
  12982. mapping = mapping !== undefined ? mapping : THREE.CubeReflectionMapping;
  12983. THREE.Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  12984. this.flipY = false;
  12985. };
  12986. THREE.CubeTexture.prototype = Object.create( THREE.Texture.prototype );
  12987. THREE.CubeTexture.prototype.constructor = THREE.CubeTexture;
  12988. Object.defineProperty( THREE.CubeTexture.prototype, 'images', {
  12989. get: function () {
  12990. return this.image;
  12991. },
  12992. set: function ( value ) {
  12993. this.image = value;
  12994. }
  12995. } );
  12996. // File:src/textures/CompressedTexture.js
  12997. /**
  12998. * @author alteredq / http://alteredqualia.com/
  12999. */
  13000. THREE.CompressedTexture = function ( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy ) {
  13001. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  13002. this.image = { width: width, height: height };
  13003. this.mipmaps = mipmaps;
  13004. // no flipping for cube textures
  13005. // (also flipping doesn't work for compressed textures )
  13006. this.flipY = false;
  13007. // can't generate mipmaps for compressed textures
  13008. // mips must be embedded in DDS files
  13009. this.generateMipmaps = false;
  13010. };
  13011. THREE.CompressedTexture.prototype = Object.create( THREE.Texture.prototype );
  13012. THREE.CompressedTexture.prototype.constructor = THREE.CompressedTexture;
  13013. // File:src/textures/DataTexture.js
  13014. /**
  13015. * @author alteredq / http://alteredqualia.com/
  13016. */
  13017. THREE.DataTexture = function ( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy ) {
  13018. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  13019. this.image = { data: data, width: width, height: height };
  13020. this.magFilter = magFilter !== undefined ? magFilter : THREE.NearestFilter;
  13021. this.minFilter = minFilter !== undefined ? minFilter : THREE.NearestFilter;
  13022. this.flipY = false;
  13023. this.generateMipmaps = false;
  13024. };
  13025. THREE.DataTexture.prototype = Object.create( THREE.Texture.prototype );
  13026. THREE.DataTexture.prototype.constructor = THREE.DataTexture;
  13027. // File:src/textures/VideoTexture.js
  13028. /**
  13029. * @author mrdoob / http://mrdoob.com/
  13030. */
  13031. THREE.VideoTexture = function ( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  13032. THREE.Texture.call( this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  13033. this.generateMipmaps = false;
  13034. var scope = this;
  13035. function update() {
  13036. requestAnimationFrame( update );
  13037. if ( video.readyState === video.HAVE_ENOUGH_DATA ) {
  13038. scope.needsUpdate = true;
  13039. }
  13040. }
  13041. update();
  13042. };
  13043. THREE.VideoTexture.prototype = Object.create( THREE.Texture.prototype );
  13044. THREE.VideoTexture.prototype.constructor = THREE.VideoTexture;
  13045. // File:src/objects/Group.js
  13046. /**
  13047. * @author mrdoob / http://mrdoob.com/
  13048. */
  13049. THREE.Group = function () {
  13050. THREE.Object3D.call( this );
  13051. this.type = 'Group';
  13052. };
  13053. THREE.Group.prototype = Object.create( THREE.Object3D.prototype );
  13054. THREE.Group.prototype.constructor = THREE.Group;
  13055. // File:src/objects/Points.js
  13056. /**
  13057. * @author alteredq / http://alteredqualia.com/
  13058. */
  13059. THREE.Points = function ( geometry, material ) {
  13060. THREE.Object3D.call( this );
  13061. this.type = 'Points';
  13062. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  13063. this.material = material !== undefined ? material : new THREE.PointsMaterial( { color: Math.random() * 0xffffff } );
  13064. };
  13065. THREE.Points.prototype = Object.create( THREE.Object3D.prototype );
  13066. THREE.Points.prototype.constructor = THREE.Points;
  13067. THREE.Points.prototype.raycast = ( function () {
  13068. var inverseMatrix = new THREE.Matrix4();
  13069. var ray = new THREE.Ray();
  13070. var sphere = new THREE.Sphere();
  13071. return function raycast( raycaster, intersects ) {
  13072. var object = this;
  13073. var geometry = this.geometry;
  13074. var matrixWorld = this.matrixWorld;
  13075. var threshold = raycaster.params.Points.threshold;
  13076. // Checking boundingSphere distance to ray
  13077. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  13078. sphere.copy( geometry.boundingSphere );
  13079. sphere.applyMatrix4( matrixWorld );
  13080. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  13081. //
  13082. inverseMatrix.getInverse( matrixWorld );
  13083. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  13084. var localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  13085. var localThresholdSq = localThreshold * localThreshold;
  13086. var position = new THREE.Vector3();
  13087. function testPoint( point, index ) {
  13088. var rayPointDistanceSq = ray.distanceSqToPoint( point );
  13089. if ( rayPointDistanceSq < localThresholdSq ) {
  13090. var intersectPoint = ray.closestPointToPoint( point );
  13091. intersectPoint.applyMatrix4( matrixWorld );
  13092. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  13093. if ( distance < raycaster.near || distance > raycaster.far ) return;
  13094. intersects.push( {
  13095. distance: distance,
  13096. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  13097. point: intersectPoint.clone(),
  13098. index: index,
  13099. face: null,
  13100. object: object
  13101. } );
  13102. }
  13103. }
  13104. if ( geometry instanceof THREE.BufferGeometry ) {
  13105. var index = geometry.index;
  13106. var attributes = geometry.attributes;
  13107. var positions = attributes.position.array;
  13108. if ( index !== null ) {
  13109. var indices = index.array;
  13110. for ( var i = 0, il = indices.length; i < il; i ++ ) {
  13111. var a = indices[ i ];
  13112. position.fromArray( positions, a * 3 );
  13113. testPoint( position, a );
  13114. }
  13115. } else {
  13116. for ( var i = 0, l = positions.length / 3; i < l; i ++ ) {
  13117. position.fromArray( positions, i * 3 );
  13118. testPoint( position, i );
  13119. }
  13120. }
  13121. } else {
  13122. var vertices = geometry.vertices;
  13123. for ( var i = 0, l = vertices.length; i < l; i ++ ) {
  13124. testPoint( vertices[ i ], i );
  13125. }
  13126. }
  13127. };
  13128. }() );
  13129. THREE.Points.prototype.clone = function () {
  13130. return new this.constructor( this.geometry, this.material ).copy( this );
  13131. };
  13132. // File:src/objects/Line.js
  13133. /**
  13134. * @author mrdoob / http://mrdoob.com/
  13135. */
  13136. THREE.Line = function ( geometry, material, mode ) {
  13137. if ( mode === 1 ) {
  13138. console.warn( 'THREE.Line: parameter THREE.LinePieces no longer supported. Created THREE.LineSegments instead.' );
  13139. return new THREE.LineSegments( geometry, material );
  13140. }
  13141. THREE.Object3D.call( this );
  13142. this.type = 'Line';
  13143. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  13144. this.material = material !== undefined ? material : new THREE.LineBasicMaterial( { color: Math.random() * 0xffffff } );
  13145. };
  13146. THREE.Line.prototype = Object.create( THREE.Object3D.prototype );
  13147. THREE.Line.prototype.constructor = THREE.Line;
  13148. THREE.Line.prototype.raycast = ( function () {
  13149. var inverseMatrix = new THREE.Matrix4();
  13150. var ray = new THREE.Ray();
  13151. var sphere = new THREE.Sphere();
  13152. return function raycast( raycaster, intersects ) {
  13153. var precision = raycaster.linePrecision;
  13154. var precisionSq = precision * precision;
  13155. var geometry = this.geometry;
  13156. var matrixWorld = this.matrixWorld;
  13157. // Checking boundingSphere distance to ray
  13158. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  13159. sphere.copy( geometry.boundingSphere );
  13160. sphere.applyMatrix4( matrixWorld );
  13161. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  13162. //
  13163. inverseMatrix.getInverse( matrixWorld );
  13164. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  13165. var vStart = new THREE.Vector3();
  13166. var vEnd = new THREE.Vector3();
  13167. var interSegment = new THREE.Vector3();
  13168. var interRay = new THREE.Vector3();
  13169. var step = this instanceof THREE.LineSegments ? 2 : 1;
  13170. if ( geometry instanceof THREE.BufferGeometry ) {
  13171. var index = geometry.index;
  13172. var attributes = geometry.attributes;
  13173. var positions = attributes.position.array;
  13174. if ( index !== null ) {
  13175. var indices = index.array;
  13176. for ( var i = 0, l = indices.length - 1; i < l; i += step ) {
  13177. var a = indices[ i ];
  13178. var b = indices[ i + 1 ];
  13179. vStart.fromArray( positions, a * 3 );
  13180. vEnd.fromArray( positions, b * 3 );
  13181. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  13182. if ( distSq > precisionSq ) continue;
  13183. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  13184. var distance = raycaster.ray.origin.distanceTo( interRay );
  13185. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  13186. intersects.push( {
  13187. distance: distance,
  13188. // What do we want? intersection point on the ray or on the segment??
  13189. // point: raycaster.ray.at( distance ),
  13190. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  13191. index: i,
  13192. face: null,
  13193. faceIndex: null,
  13194. object: this
  13195. } );
  13196. }
  13197. } else {
  13198. for ( var i = 0, l = positions.length / 3 - 1; i < l; i += step ) {
  13199. vStart.fromArray( positions, 3 * i );
  13200. vEnd.fromArray( positions, 3 * i + 3 );
  13201. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  13202. if ( distSq > precisionSq ) continue;
  13203. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  13204. var distance = raycaster.ray.origin.distanceTo( interRay );
  13205. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  13206. intersects.push( {
  13207. distance: distance,
  13208. // What do we want? intersection point on the ray or on the segment??
  13209. // point: raycaster.ray.at( distance ),
  13210. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  13211. index: i,
  13212. face: null,
  13213. faceIndex: null,
  13214. object: this
  13215. } );
  13216. }
  13217. }
  13218. } else if ( geometry instanceof THREE.Geometry ) {
  13219. var vertices = geometry.vertices;
  13220. var nbVertices = vertices.length;
  13221. for ( var i = 0; i < nbVertices - 1; i += step ) {
  13222. var distSq = ray.distanceSqToSegment( vertices[ i ], vertices[ i + 1 ], interRay, interSegment );
  13223. if ( distSq > precisionSq ) continue;
  13224. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  13225. var distance = raycaster.ray.origin.distanceTo( interRay );
  13226. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  13227. intersects.push( {
  13228. distance: distance,
  13229. // What do we want? intersection point on the ray or on the segment??
  13230. // point: raycaster.ray.at( distance ),
  13231. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  13232. index: i,
  13233. face: null,
  13234. faceIndex: null,
  13235. object: this
  13236. } );
  13237. }
  13238. }
  13239. };
  13240. }() );
  13241. THREE.Line.prototype.clone = function () {
  13242. return new this.constructor( this.geometry, this.material ).copy( this );
  13243. };
  13244. // DEPRECATED
  13245. THREE.LineStrip = 0;
  13246. THREE.LinePieces = 1;
  13247. // File:src/objects/LineSegments.js
  13248. /**
  13249. * @author mrdoob / http://mrdoob.com/
  13250. */
  13251. THREE.LineSegments = function ( geometry, material ) {
  13252. THREE.Line.call( this, geometry, material );
  13253. this.type = 'LineSegments';
  13254. };
  13255. THREE.LineSegments.prototype = Object.create( THREE.Line.prototype );
  13256. THREE.LineSegments.prototype.constructor = THREE.LineSegments;
  13257. // File:src/objects/Mesh.js
  13258. /**
  13259. * @author mrdoob / http://mrdoob.com/
  13260. * @author alteredq / http://alteredqualia.com/
  13261. * @author mikael emtinger / http://gomo.se/
  13262. * @author jonobr1 / http://jonobr1.com/
  13263. */
  13264. THREE.Mesh = function ( geometry, material ) {
  13265. THREE.Object3D.call( this );
  13266. this.type = 'Mesh';
  13267. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  13268. this.material = material !== undefined ? material : new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff } );
  13269. this.drawMode = THREE.TrianglesDrawMode;
  13270. this.updateMorphTargets();
  13271. };
  13272. THREE.Mesh.prototype = Object.create( THREE.Object3D.prototype );
  13273. THREE.Mesh.prototype.constructor = THREE.Mesh;
  13274. THREE.Mesh.prototype.setDrawMode = function ( value ) {
  13275. this.drawMode = value;
  13276. };
  13277. THREE.Mesh.prototype.updateMorphTargets = function () {
  13278. if ( this.geometry.morphTargets !== undefined && this.geometry.morphTargets.length > 0 ) {
  13279. this.morphTargetBase = - 1;
  13280. this.morphTargetInfluences = [];
  13281. this.morphTargetDictionary = {};
  13282. for ( var m = 0, ml = this.geometry.morphTargets.length; m < ml; m ++ ) {
  13283. this.morphTargetInfluences.push( 0 );
  13284. this.morphTargetDictionary[ this.geometry.morphTargets[ m ].name ] = m;
  13285. }
  13286. }
  13287. };
  13288. THREE.Mesh.prototype.getMorphTargetIndexByName = function ( name ) {
  13289. if ( this.morphTargetDictionary[ name ] !== undefined ) {
  13290. return this.morphTargetDictionary[ name ];
  13291. }
  13292. console.warn( 'THREE.Mesh.getMorphTargetIndexByName: morph target ' + name + ' does not exist. Returning 0.' );
  13293. return 0;
  13294. };
  13295. THREE.Mesh.prototype.raycast = ( function () {
  13296. var inverseMatrix = new THREE.Matrix4();
  13297. var ray = new THREE.Ray();
  13298. var sphere = new THREE.Sphere();
  13299. var vA = new THREE.Vector3();
  13300. var vB = new THREE.Vector3();
  13301. var vC = new THREE.Vector3();
  13302. var tempA = new THREE.Vector3();
  13303. var tempB = new THREE.Vector3();
  13304. var tempC = new THREE.Vector3();
  13305. var uvA = new THREE.Vector2();
  13306. var uvB = new THREE.Vector2();
  13307. var uvC = new THREE.Vector2();
  13308. var barycoord = new THREE.Vector3();
  13309. var intersectionPoint = new THREE.Vector3();
  13310. var intersectionPointWorld = new THREE.Vector3();
  13311. function uvIntersection( point, p1, p2, p3, uv1, uv2, uv3 ) {
  13312. THREE.Triangle.barycoordFromPoint( point, p1, p2, p3, barycoord );
  13313. uv1.multiplyScalar( barycoord.x );
  13314. uv2.multiplyScalar( barycoord.y );
  13315. uv3.multiplyScalar( barycoord.z );
  13316. uv1.add( uv2 ).add( uv3 );
  13317. return uv1.clone();
  13318. }
  13319. function checkIntersection( object, raycaster, ray, pA, pB, pC, point ) {
  13320. var intersect;
  13321. var material = object.material;
  13322. if ( material.side === THREE.BackSide ) {
  13323. intersect = ray.intersectTriangle( pC, pB, pA, true, point );
  13324. } else {
  13325. intersect = ray.intersectTriangle( pA, pB, pC, material.side !== THREE.DoubleSide, point );
  13326. }
  13327. if ( intersect === null ) return null;
  13328. intersectionPointWorld.copy( point );
  13329. intersectionPointWorld.applyMatrix4( object.matrixWorld );
  13330. var distance = raycaster.ray.origin.distanceTo( intersectionPointWorld );
  13331. if ( distance < raycaster.near || distance > raycaster.far ) return null;
  13332. return {
  13333. distance: distance,
  13334. point: intersectionPointWorld.clone(),
  13335. object: object
  13336. };
  13337. }
  13338. function checkBufferGeometryIntersection( object, raycaster, ray, positions, uvs, a, b, c ) {
  13339. vA.fromArray( positions, a * 3 );
  13340. vB.fromArray( positions, b * 3 );
  13341. vC.fromArray( positions, c * 3 );
  13342. var intersection = checkIntersection( object, raycaster, ray, vA, vB, vC, intersectionPoint );
  13343. if ( intersection ) {
  13344. if ( uvs ) {
  13345. uvA.fromArray( uvs, a * 2 );
  13346. uvB.fromArray( uvs, b * 2 );
  13347. uvC.fromArray( uvs, c * 2 );
  13348. intersection.uv = uvIntersection( intersectionPoint, vA, vB, vC, uvA, uvB, uvC );
  13349. }
  13350. intersection.face = new THREE.Face3( a, b, c, THREE.Triangle.normal( vA, vB, vC ) );
  13351. intersection.faceIndex = a;
  13352. }
  13353. return intersection;
  13354. }
  13355. return function raycast( raycaster, intersects ) {
  13356. var geometry = this.geometry;
  13357. var material = this.material;
  13358. var matrixWorld = this.matrixWorld;
  13359. if ( material === undefined ) return;
  13360. // Checking boundingSphere distance to ray
  13361. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  13362. sphere.copy( geometry.boundingSphere );
  13363. sphere.applyMatrix4( matrixWorld );
  13364. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  13365. //
  13366. inverseMatrix.getInverse( matrixWorld );
  13367. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  13368. // Check boundingBox before continuing
  13369. if ( geometry.boundingBox !== null ) {
  13370. if ( ray.intersectsBox( geometry.boundingBox ) === false ) return;
  13371. }
  13372. var uvs, intersection;
  13373. if ( geometry instanceof THREE.BufferGeometry ) {
  13374. var a, b, c;
  13375. var index = geometry.index;
  13376. var attributes = geometry.attributes;
  13377. var positions = attributes.position.array;
  13378. if ( attributes.uv !== undefined ) {
  13379. uvs = attributes.uv.array;
  13380. }
  13381. if ( index !== null ) {
  13382. var indices = index.array;
  13383. for ( var i = 0, l = indices.length; i < l; i += 3 ) {
  13384. a = indices[ i ];
  13385. b = indices[ i + 1 ];
  13386. c = indices[ i + 2 ];
  13387. intersection = checkBufferGeometryIntersection( this, raycaster, ray, positions, uvs, a, b, c );
  13388. if ( intersection ) {
  13389. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in indices buffer semantics
  13390. intersects.push( intersection );
  13391. }
  13392. }
  13393. } else {
  13394. for ( var i = 0, l = positions.length; i < l; i += 9 ) {
  13395. a = i / 3;
  13396. b = a + 1;
  13397. c = a + 2;
  13398. intersection = checkBufferGeometryIntersection( this, raycaster, ray, positions, uvs, a, b, c );
  13399. if ( intersection ) {
  13400. intersection.index = a; // triangle number in positions buffer semantics
  13401. intersects.push( intersection );
  13402. }
  13403. }
  13404. }
  13405. } else if ( geometry instanceof THREE.Geometry ) {
  13406. var fvA, fvB, fvC;
  13407. var isFaceMaterial = material instanceof THREE.MultiMaterial;
  13408. var materials = isFaceMaterial === true ? material.materials : null;
  13409. var vertices = geometry.vertices;
  13410. var faces = geometry.faces;
  13411. var faceVertexUvs = geometry.faceVertexUvs[ 0 ];
  13412. if ( faceVertexUvs.length > 0 ) uvs = faceVertexUvs;
  13413. for ( var f = 0, fl = faces.length; f < fl; f ++ ) {
  13414. var face = faces[ f ];
  13415. var faceMaterial = isFaceMaterial === true ? materials[ face.materialIndex ] : material;
  13416. if ( faceMaterial === undefined ) continue;
  13417. fvA = vertices[ face.a ];
  13418. fvB = vertices[ face.b ];
  13419. fvC = vertices[ face.c ];
  13420. if ( faceMaterial.morphTargets === true ) {
  13421. var morphTargets = geometry.morphTargets;
  13422. var morphInfluences = this.morphTargetInfluences;
  13423. vA.set( 0, 0, 0 );
  13424. vB.set( 0, 0, 0 );
  13425. vC.set( 0, 0, 0 );
  13426. for ( var t = 0, tl = morphTargets.length; t < tl; t ++ ) {
  13427. var influence = morphInfluences[ t ];
  13428. if ( influence === 0 ) continue;
  13429. var targets = morphTargets[ t ].vertices;
  13430. vA.addScaledVector( tempA.subVectors( targets[ face.a ], fvA ), influence );
  13431. vB.addScaledVector( tempB.subVectors( targets[ face.b ], fvB ), influence );
  13432. vC.addScaledVector( tempC.subVectors( targets[ face.c ], fvC ), influence );
  13433. }
  13434. vA.add( fvA );
  13435. vB.add( fvB );
  13436. vC.add( fvC );
  13437. fvA = vA;
  13438. fvB = vB;
  13439. fvC = vC;
  13440. }
  13441. intersection = checkIntersection( this, raycaster, ray, fvA, fvB, fvC, intersectionPoint );
  13442. if ( intersection ) {
  13443. if ( uvs ) {
  13444. var uvs_f = uvs[ f ];
  13445. uvA.copy( uvs_f[ 0 ] );
  13446. uvB.copy( uvs_f[ 1 ] );
  13447. uvC.copy( uvs_f[ 2 ] );
  13448. intersection.uv = uvIntersection( intersectionPoint, fvA, fvB, fvC, uvA, uvB, uvC );
  13449. }
  13450. intersection.face = face;
  13451. intersection.faceIndex = f;
  13452. intersects.push( intersection );
  13453. }
  13454. }
  13455. }
  13456. };
  13457. }() );
  13458. THREE.Mesh.prototype.clone = function () {
  13459. return new this.constructor( this.geometry, this.material ).copy( this );
  13460. };
  13461. // File:src/objects/Bone.js
  13462. /**
  13463. * @author mikael emtinger / http://gomo.se/
  13464. * @author alteredq / http://alteredqualia.com/
  13465. * @author ikerr / http://verold.com
  13466. */
  13467. THREE.Bone = function ( skin ) {
  13468. THREE.Object3D.call( this );
  13469. this.type = 'Bone';
  13470. this.skin = skin;
  13471. };
  13472. THREE.Bone.prototype = Object.create( THREE.Object3D.prototype );
  13473. THREE.Bone.prototype.constructor = THREE.Bone;
  13474. THREE.Bone.prototype.copy = function ( source ) {
  13475. THREE.Object3D.prototype.copy.call( this, source );
  13476. this.skin = source.skin;
  13477. return this;
  13478. };
  13479. // File:src/objects/Skeleton.js
  13480. /**
  13481. * @author mikael emtinger / http://gomo.se/
  13482. * @author alteredq / http://alteredqualia.com/
  13483. * @author michael guerrero / http://realitymeltdown.com
  13484. * @author ikerr / http://verold.com
  13485. */
  13486. THREE.Skeleton = function ( bones, boneInverses, useVertexTexture ) {
  13487. this.useVertexTexture = useVertexTexture !== undefined ? useVertexTexture : true;
  13488. this.identityMatrix = new THREE.Matrix4();
  13489. // copy the bone array
  13490. bones = bones || [];
  13491. this.bones = bones.slice( 0 );
  13492. // create a bone texture or an array of floats
  13493. if ( this.useVertexTexture ) {
  13494. // layout (1 matrix = 4 pixels)
  13495. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  13496. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  13497. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  13498. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  13499. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  13500. var size = Math.sqrt( this.bones.length * 4 ); // 4 pixels needed for 1 matrix
  13501. size = THREE.Math.nextPowerOfTwo( Math.ceil( size ) );
  13502. size = Math.max( size, 4 );
  13503. this.boneTextureWidth = size;
  13504. this.boneTextureHeight = size;
  13505. this.boneMatrices = new Float32Array( this.boneTextureWidth * this.boneTextureHeight * 4 ); // 4 floats per RGBA pixel
  13506. this.boneTexture = new THREE.DataTexture( this.boneMatrices, this.boneTextureWidth, this.boneTextureHeight, THREE.RGBAFormat, THREE.FloatType );
  13507. } else {
  13508. this.boneMatrices = new Float32Array( 16 * this.bones.length );
  13509. }
  13510. // use the supplied bone inverses or calculate the inverses
  13511. if ( boneInverses === undefined ) {
  13512. this.calculateInverses();
  13513. } else {
  13514. if ( this.bones.length === boneInverses.length ) {
  13515. this.boneInverses = boneInverses.slice( 0 );
  13516. } else {
  13517. console.warn( 'THREE.Skeleton bonInverses is the wrong length.' );
  13518. this.boneInverses = [];
  13519. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13520. this.boneInverses.push( new THREE.Matrix4() );
  13521. }
  13522. }
  13523. }
  13524. };
  13525. THREE.Skeleton.prototype.calculateInverses = function () {
  13526. this.boneInverses = [];
  13527. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13528. var inverse = new THREE.Matrix4();
  13529. if ( this.bones[ b ] ) {
  13530. inverse.getInverse( this.bones[ b ].matrixWorld );
  13531. }
  13532. this.boneInverses.push( inverse );
  13533. }
  13534. };
  13535. THREE.Skeleton.prototype.pose = function () {
  13536. var bone;
  13537. // recover the bind-time world matrices
  13538. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13539. bone = this.bones[ b ];
  13540. if ( bone ) {
  13541. bone.matrixWorld.getInverse( this.boneInverses[ b ] );
  13542. }
  13543. }
  13544. // compute the local matrices, positions, rotations and scales
  13545. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13546. bone = this.bones[ b ];
  13547. if ( bone ) {
  13548. if ( bone.parent ) {
  13549. bone.matrix.getInverse( bone.parent.matrixWorld );
  13550. bone.matrix.multiply( bone.matrixWorld );
  13551. } else {
  13552. bone.matrix.copy( bone.matrixWorld );
  13553. }
  13554. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  13555. }
  13556. }
  13557. };
  13558. THREE.Skeleton.prototype.update = ( function () {
  13559. var offsetMatrix = new THREE.Matrix4();
  13560. return function update() {
  13561. // flatten bone matrices to array
  13562. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13563. // compute the offset between the current and the original transform
  13564. var matrix = this.bones[ b ] ? this.bones[ b ].matrixWorld : this.identityMatrix;
  13565. offsetMatrix.multiplyMatrices( matrix, this.boneInverses[ b ] );
  13566. offsetMatrix.flattenToArrayOffset( this.boneMatrices, b * 16 );
  13567. }
  13568. if ( this.useVertexTexture ) {
  13569. this.boneTexture.needsUpdate = true;
  13570. }
  13571. };
  13572. } )();
  13573. THREE.Skeleton.prototype.clone = function () {
  13574. return new THREE.Skeleton( this.bones, this.boneInverses, this.useVertexTexture );
  13575. };
  13576. // File:src/objects/SkinnedMesh.js
  13577. /**
  13578. * @author mikael emtinger / http://gomo.se/
  13579. * @author alteredq / http://alteredqualia.com/
  13580. * @author ikerr / http://verold.com
  13581. */
  13582. THREE.SkinnedMesh = function ( geometry, material, useVertexTexture ) {
  13583. THREE.Mesh.call( this, geometry, material );
  13584. this.type = 'SkinnedMesh';
  13585. this.bindMode = "attached";
  13586. this.bindMatrix = new THREE.Matrix4();
  13587. this.bindMatrixInverse = new THREE.Matrix4();
  13588. // init bones
  13589. // TODO: remove bone creation as there is no reason (other than
  13590. // convenience) for THREE.SkinnedMesh to do this.
  13591. var bones = [];
  13592. if ( this.geometry && this.geometry.bones !== undefined ) {
  13593. var bone, gbone;
  13594. for ( var b = 0, bl = this.geometry.bones.length; b < bl; ++ b ) {
  13595. gbone = this.geometry.bones[ b ];
  13596. bone = new THREE.Bone( this );
  13597. bones.push( bone );
  13598. bone.name = gbone.name;
  13599. bone.position.fromArray( gbone.pos );
  13600. bone.quaternion.fromArray( gbone.rotq );
  13601. if ( gbone.scl !== undefined ) bone.scale.fromArray( gbone.scl );
  13602. }
  13603. for ( var b = 0, bl = this.geometry.bones.length; b < bl; ++ b ) {
  13604. gbone = this.geometry.bones[ b ];
  13605. if ( gbone.parent !== - 1 && gbone.parent !== null ) {
  13606. bones[ gbone.parent ].add( bones[ b ] );
  13607. } else {
  13608. this.add( bones[ b ] );
  13609. }
  13610. }
  13611. }
  13612. this.normalizeSkinWeights();
  13613. this.updateMatrixWorld( true );
  13614. this.bind( new THREE.Skeleton( bones, undefined, useVertexTexture ), this.matrixWorld );
  13615. };
  13616. THREE.SkinnedMesh.prototype = Object.create( THREE.Mesh.prototype );
  13617. THREE.SkinnedMesh.prototype.constructor = THREE.SkinnedMesh;
  13618. THREE.SkinnedMesh.prototype.bind = function( skeleton, bindMatrix ) {
  13619. this.skeleton = skeleton;
  13620. if ( bindMatrix === undefined ) {
  13621. this.updateMatrixWorld( true );
  13622. this.skeleton.calculateInverses();
  13623. bindMatrix = this.matrixWorld;
  13624. }
  13625. this.bindMatrix.copy( bindMatrix );
  13626. this.bindMatrixInverse.getInverse( bindMatrix );
  13627. };
  13628. THREE.SkinnedMesh.prototype.pose = function () {
  13629. this.skeleton.pose();
  13630. };
  13631. THREE.SkinnedMesh.prototype.normalizeSkinWeights = function () {
  13632. if ( this.geometry instanceof THREE.Geometry ) {
  13633. for ( var i = 0; i < this.geometry.skinWeights.length; i ++ ) {
  13634. var sw = this.geometry.skinWeights[ i ];
  13635. var scale = 1.0 / sw.lengthManhattan();
  13636. if ( scale !== Infinity ) {
  13637. sw.multiplyScalar( scale );
  13638. } else {
  13639. sw.set( 1, 0, 0, 0 ); // do something reasonable
  13640. }
  13641. }
  13642. } else if ( this.geometry instanceof THREE.BufferGeometry ) {
  13643. var vec = new THREE.Vector4();
  13644. var skinWeight = this.geometry.attributes.skinWeight;
  13645. for ( var i = 0; i < skinWeight.count; i ++ ) {
  13646. vec.x = skinWeight.getX( i );
  13647. vec.y = skinWeight.getY( i );
  13648. vec.z = skinWeight.getZ( i );
  13649. vec.w = skinWeight.getW( i );
  13650. var scale = 1.0 / vec.lengthManhattan();
  13651. if ( scale !== Infinity ) {
  13652. vec.multiplyScalar( scale );
  13653. } else {
  13654. vec.set( 1, 0, 0, 0 ); // do something reasonable
  13655. }
  13656. skinWeight.setXYZW( i, vec.x, vec.y, vec.z, vec.w );
  13657. }
  13658. }
  13659. };
  13660. THREE.SkinnedMesh.prototype.updateMatrixWorld = function( force ) {
  13661. THREE.Mesh.prototype.updateMatrixWorld.call( this, true );
  13662. if ( this.bindMode === "attached" ) {
  13663. this.bindMatrixInverse.getInverse( this.matrixWorld );
  13664. } else if ( this.bindMode === "detached" ) {
  13665. this.bindMatrixInverse.getInverse( this.bindMatrix );
  13666. } else {
  13667. console.warn( 'THREE.SkinnedMesh unrecognized bindMode: ' + this.bindMode );
  13668. }
  13669. };
  13670. THREE.SkinnedMesh.prototype.clone = function() {
  13671. return new this.constructor( this.geometry, this.material, this.useVertexTexture ).copy( this );
  13672. };
  13673. // File:src/objects/LOD.js
  13674. /**
  13675. * @author mikael emtinger / http://gomo.se/
  13676. * @author alteredq / http://alteredqualia.com/
  13677. * @author mrdoob / http://mrdoob.com/
  13678. */
  13679. THREE.LOD = function () {
  13680. THREE.Object3D.call( this );
  13681. this.type = 'LOD';
  13682. Object.defineProperties( this, {
  13683. levels: {
  13684. enumerable: true,
  13685. value: []
  13686. },
  13687. objects: {
  13688. get: function () {
  13689. console.warn( 'THREE.LOD: .objects has been renamed to .levels.' );
  13690. return this.levels;
  13691. }
  13692. }
  13693. } );
  13694. };
  13695. THREE.LOD.prototype = Object.create( THREE.Object3D.prototype );
  13696. THREE.LOD.prototype.constructor = THREE.LOD;
  13697. THREE.LOD.prototype.addLevel = function ( object, distance ) {
  13698. if ( distance === undefined ) distance = 0;
  13699. distance = Math.abs( distance );
  13700. var levels = this.levels;
  13701. for ( var l = 0; l < levels.length; l ++ ) {
  13702. if ( distance < levels[ l ].distance ) {
  13703. break;
  13704. }
  13705. }
  13706. levels.splice( l, 0, { distance: distance, object: object } );
  13707. this.add( object );
  13708. };
  13709. THREE.LOD.prototype.getObjectForDistance = function ( distance ) {
  13710. var levels = this.levels;
  13711. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  13712. if ( distance < levels[ i ].distance ) {
  13713. break;
  13714. }
  13715. }
  13716. return levels[ i - 1 ].object;
  13717. };
  13718. THREE.LOD.prototype.raycast = ( function () {
  13719. var matrixPosition = new THREE.Vector3();
  13720. return function raycast( raycaster, intersects ) {
  13721. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  13722. var distance = raycaster.ray.origin.distanceTo( matrixPosition );
  13723. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  13724. };
  13725. }() );
  13726. THREE.LOD.prototype.update = function () {
  13727. var v1 = new THREE.Vector3();
  13728. var v2 = new THREE.Vector3();
  13729. return function update( camera ) {
  13730. var levels = this.levels;
  13731. if ( levels.length > 1 ) {
  13732. v1.setFromMatrixPosition( camera.matrixWorld );
  13733. v2.setFromMatrixPosition( this.matrixWorld );
  13734. var distance = v1.distanceTo( v2 );
  13735. levels[ 0 ].object.visible = true;
  13736. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  13737. if ( distance >= levels[ i ].distance ) {
  13738. levels[ i - 1 ].object.visible = false;
  13739. levels[ i ].object.visible = true;
  13740. } else {
  13741. break;
  13742. }
  13743. }
  13744. for ( ; i < l; i ++ ) {
  13745. levels[ i ].object.visible = false;
  13746. }
  13747. }
  13748. };
  13749. }();
  13750. THREE.LOD.prototype.copy = function ( source ) {
  13751. THREE.Object3D.prototype.copy.call( this, source, false );
  13752. var levels = source.levels;
  13753. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  13754. var level = levels[ i ];
  13755. this.addLevel( level.object.clone(), level.distance );
  13756. }
  13757. return this;
  13758. };
  13759. THREE.LOD.prototype.toJSON = function ( meta ) {
  13760. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  13761. data.object.levels = [];
  13762. var levels = this.levels;
  13763. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  13764. var level = levels[ i ];
  13765. data.object.levels.push( {
  13766. object: level.object.uuid,
  13767. distance: level.distance
  13768. } );
  13769. }
  13770. return data;
  13771. };
  13772. // File:src/objects/Sprite.js
  13773. /**
  13774. * @author mikael emtinger / http://gomo.se/
  13775. * @author alteredq / http://alteredqualia.com/
  13776. */
  13777. THREE.Sprite = ( function () {
  13778. var indices = new Uint16Array( [ 0, 1, 2, 0, 2, 3 ] );
  13779. var vertices = new Float32Array( [ - 0.5, - 0.5, 0, 0.5, - 0.5, 0, 0.5, 0.5, 0, - 0.5, 0.5, 0 ] );
  13780. var uvs = new Float32Array( [ 0, 0, 1, 0, 1, 1, 0, 1 ] );
  13781. var geometry = new THREE.BufferGeometry();
  13782. geometry.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  13783. geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  13784. geometry.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  13785. return function Sprite( material ) {
  13786. THREE.Object3D.call( this );
  13787. this.type = 'Sprite';
  13788. this.geometry = geometry;
  13789. this.material = ( material !== undefined ) ? material : new THREE.SpriteMaterial();
  13790. };
  13791. } )();
  13792. THREE.Sprite.prototype = Object.create( THREE.Object3D.prototype );
  13793. THREE.Sprite.prototype.constructor = THREE.Sprite;
  13794. THREE.Sprite.prototype.raycast = ( function () {
  13795. var matrixPosition = new THREE.Vector3();
  13796. return function raycast( raycaster, intersects ) {
  13797. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  13798. var distanceSq = raycaster.ray.distanceSqToPoint( matrixPosition );
  13799. var guessSizeSq = this.scale.x * this.scale.y;
  13800. if ( distanceSq > guessSizeSq ) {
  13801. return;
  13802. }
  13803. intersects.push( {
  13804. distance: Math.sqrt( distanceSq ),
  13805. point: this.position,
  13806. face: null,
  13807. object: this
  13808. } );
  13809. };
  13810. }() );
  13811. THREE.Sprite.prototype.clone = function () {
  13812. return new this.constructor( this.material ).copy( this );
  13813. };
  13814. // Backwards compatibility
  13815. THREE.Particle = THREE.Sprite;
  13816. // File:src/objects/LensFlare.js
  13817. /**
  13818. * @author mikael emtinger / http://gomo.se/
  13819. * @author alteredq / http://alteredqualia.com/
  13820. */
  13821. THREE.LensFlare = function ( texture, size, distance, blending, color ) {
  13822. THREE.Object3D.call( this );
  13823. this.lensFlares = [];
  13824. this.positionScreen = new THREE.Vector3();
  13825. this.customUpdateCallback = undefined;
  13826. if ( texture !== undefined ) {
  13827. this.add( texture, size, distance, blending, color );
  13828. }
  13829. };
  13830. THREE.LensFlare.prototype = Object.create( THREE.Object3D.prototype );
  13831. THREE.LensFlare.prototype.constructor = THREE.LensFlare;
  13832. /*
  13833. * Add: adds another flare
  13834. */
  13835. THREE.LensFlare.prototype.add = function ( texture, size, distance, blending, color, opacity ) {
  13836. if ( size === undefined ) size = - 1;
  13837. if ( distance === undefined ) distance = 0;
  13838. if ( opacity === undefined ) opacity = 1;
  13839. if ( color === undefined ) color = new THREE.Color( 0xffffff );
  13840. if ( blending === undefined ) blending = THREE.NormalBlending;
  13841. distance = Math.min( distance, Math.max( 0, distance ) );
  13842. this.lensFlares.push( {
  13843. texture: texture, // THREE.Texture
  13844. size: size, // size in pixels (-1 = use texture.width)
  13845. distance: distance, // distance (0-1) from light source (0=at light source)
  13846. x: 0, y: 0, z: 0, // screen position (-1 => 1) z = 0 is in front z = 1 is back
  13847. scale: 1, // scale
  13848. rotation: 0, // rotation
  13849. opacity: opacity, // opacity
  13850. color: color, // color
  13851. blending: blending // blending
  13852. } );
  13853. };
  13854. /*
  13855. * Update lens flares update positions on all flares based on the screen position
  13856. * Set myLensFlare.customUpdateCallback to alter the flares in your project specific way.
  13857. */
  13858. THREE.LensFlare.prototype.updateLensFlares = function () {
  13859. var f, fl = this.lensFlares.length;
  13860. var flare;
  13861. var vecX = - this.positionScreen.x * 2;
  13862. var vecY = - this.positionScreen.y * 2;
  13863. for ( f = 0; f < fl; f ++ ) {
  13864. flare = this.lensFlares[ f ];
  13865. flare.x = this.positionScreen.x + vecX * flare.distance;
  13866. flare.y = this.positionScreen.y + vecY * flare.distance;
  13867. flare.wantedRotation = flare.x * Math.PI * 0.25;
  13868. flare.rotation += ( flare.wantedRotation - flare.rotation ) * 0.25;
  13869. }
  13870. };
  13871. THREE.LensFlare.prototype.copy = function ( source ) {
  13872. THREE.Object3D.prototype.copy.call( this, source );
  13873. this.positionScreen.copy( source.positionScreen );
  13874. this.customUpdateCallback = source.customUpdateCallback;
  13875. for ( var i = 0, l = source.lensFlares.length; i < l; i ++ ) {
  13876. this.lensFlares.push( source.lensFlares[ i ] );
  13877. }
  13878. return this;
  13879. };
  13880. // File:src/scenes/Scene.js
  13881. /**
  13882. * @author mrdoob / http://mrdoob.com/
  13883. */
  13884. THREE.Scene = function () {
  13885. THREE.Object3D.call( this );
  13886. this.type = 'Scene';
  13887. this.fog = null;
  13888. this.overrideMaterial = null;
  13889. this.autoUpdate = true; // checked by the renderer
  13890. };
  13891. THREE.Scene.prototype = Object.create( THREE.Object3D.prototype );
  13892. THREE.Scene.prototype.constructor = THREE.Scene;
  13893. THREE.Scene.prototype.copy = function ( source, recursive ) {
  13894. THREE.Object3D.prototype.copy.call( this, source, recursive );
  13895. if ( source.fog !== null ) this.fog = source.fog.clone();
  13896. if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
  13897. this.autoUpdate = source.autoUpdate;
  13898. this.matrixAutoUpdate = source.matrixAutoUpdate;
  13899. return this;
  13900. };
  13901. // File:src/scenes/Fog.js
  13902. /**
  13903. * @author mrdoob / http://mrdoob.com/
  13904. * @author alteredq / http://alteredqualia.com/
  13905. */
  13906. THREE.Fog = function ( color, near, far ) {
  13907. this.name = '';
  13908. this.color = new THREE.Color( color );
  13909. this.near = ( near !== undefined ) ? near : 1;
  13910. this.far = ( far !== undefined ) ? far : 1000;
  13911. };
  13912. THREE.Fog.prototype.clone = function () {
  13913. return new THREE.Fog( this.color.getHex(), this.near, this.far );
  13914. };
  13915. // File:src/scenes/FogExp2.js
  13916. /**
  13917. * @author mrdoob / http://mrdoob.com/
  13918. * @author alteredq / http://alteredqualia.com/
  13919. */
  13920. THREE.FogExp2 = function ( color, density ) {
  13921. this.name = '';
  13922. this.color = new THREE.Color( color );
  13923. this.density = ( density !== undefined ) ? density : 0.00025;
  13924. };
  13925. THREE.FogExp2.prototype.clone = function () {
  13926. return new THREE.FogExp2( this.color.getHex(), this.density );
  13927. };
  13928. // File:src/renderers/shaders/ShaderChunk.js
  13929. THREE.ShaderChunk = {};
  13930. // File:src/renderers/shaders/ShaderChunk/alphamap_fragment.glsl
  13931. THREE.ShaderChunk[ 'alphamap_fragment' ] = "#ifdef USE_ALPHAMAP\n diffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif\n";
  13932. // File:src/renderers/shaders/ShaderChunk/alphamap_pars_fragment.glsl
  13933. THREE.ShaderChunk[ 'alphamap_pars_fragment' ] = "#ifdef USE_ALPHAMAP\n uniform sampler2D alphaMap;\n#endif\n";
  13934. // File:src/renderers/shaders/ShaderChunk/alphatest_fragment.glsl
  13935. THREE.ShaderChunk[ 'alphatest_fragment' ] = "#ifdef ALPHATEST\n if ( diffuseColor.a < ALPHATEST ) discard;\n#endif\n";
  13936. // File:src/renderers/shaders/ShaderChunk/aomap_fragment.glsl
  13937. THREE.ShaderChunk[ 'aomap_fragment' ] = "#ifdef USE_AOMAP\n float ambientOcclusion = ( texture2D( aoMap, vUv2 ).r - 1.0 ) * aoMapIntensity + 1.0;\n reflectedLight.indirectDiffuse *= ambientOcclusion;\n #if defined( USE_ENVMAP ) && defined( STANDARD )\n float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n reflectedLight.indirectSpecular *= computeSpecularOcclusion( dotNV, ambientOcclusion, material.specularRoughness );\n #endif\n#endif\n";
  13938. // File:src/renderers/shaders/ShaderChunk/aomap_pars_fragment.glsl
  13939. THREE.ShaderChunk[ 'aomap_pars_fragment' ] = "#ifdef USE_AOMAP\n uniform sampler2D aoMap;\n uniform float aoMapIntensity;\n#endif";
  13940. // File:src/renderers/shaders/ShaderChunk/begin_vertex.glsl
  13941. THREE.ShaderChunk[ 'begin_vertex' ] = "\nvec3 transformed = vec3( position );\n";
  13942. // File:src/renderers/shaders/ShaderChunk/beginnormal_vertex.glsl
  13943. THREE.ShaderChunk[ 'beginnormal_vertex' ] = "\nvec3 objectNormal = vec3( normal );\n";
  13944. // File:src/renderers/shaders/ShaderChunk/bsdfs.glsl
  13945. THREE.ShaderChunk[ 'bsdfs' ] = "bool testLightInRange( const in float lightDistance, const in float cutoffDistance ) {\n return any( bvec2( cutoffDistance == 0.0, lightDistance < cutoffDistance ) );\n}\nfloat punctualLightIntensityToIrradianceFactor( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {\n if( decayExponent > 0.0 ) {\n#if defined ( PHYSICALLY_CORRECT_LIGHTS )\n float distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );\n float maxDistanceCutoffFactor = exp2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) ) ;\n return distanceFalloff * maxDistanceCutoffFactor;\n#else\n return pow( saturate( -lightDistance / cutoffDistance + 1.0 ), decayExponent );\n#endif\n }\n return 1.0;\n}\nvec3 BRDF_Diffuse_Lambert( const in vec3 diffuseColor ) {\n return RECIPROCAL_PI * diffuseColor;\n}\nvec3 F_Schlick( const in vec3 specularColor, const in float dotLH ) {\n float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );\n return ( 1.0 - specularColor ) * fresnel + specularColor;\n}\nfloat G_GGX_Smith( const in float alpha, const in float dotNL, const in float dotNV ) {\n float a2 = alpha * alpha;\n float gl = dotNL + pow( a2 + ( 1.0 - a2 ) * pow2( dotNL ), 0.5 );\n float gv = dotNV + pow( a2 + ( 1.0 - a2 ) * pow2( dotNV ), 0.5 );\n return 1.0 / ( gl * gv );\n}\nfloat D_GGX( const in float alpha, const in float dotNH ) {\n float a2 = pow2( alpha );\n float denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0;\n return RECIPROCAL_PI * a2 / pow2( denom );\n}\nvec3 BRDF_Specular_GGX( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float roughness ) {\n float alpha = roughness * roughness;\n vec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );\n float dotNL = saturate( dot( geometry.normal, incidentLight.direction ) );\n float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n float dotNH = saturate( dot( geometry.normal, halfDir ) );\n float dotLH = saturate( dot( incidentLight.direction, halfDir ) );\n vec3 F = F_Schlick( specularColor, dotLH );\n float G = G_GGX_Smith( alpha, dotNL, dotNV );\n float D = D_GGX( alpha, dotNH );\n return F * ( G * D );\n}\nvec3 BRDF_Specular_GGX_Environment( const in GeometricContext geometry, const in vec3 specularColor, const in float roughness ) {\n float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n const vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );\n const vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );\n vec4 r = roughness * c0 + c1;\n float a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;\n vec2 AB = vec2( -1.04, 1.04 ) * a004 + r.zw;\n return specularColor * AB.x + AB.y;\n}\nfloat G_BlinnPhong_Implicit( ) {\n return 0.25;\n}\nfloat D_BlinnPhong( const in float shininess, const in float dotNH ) {\n return RECIPROCAL_PI * ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );\n}\nvec3 BRDF_Specular_BlinnPhong( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float shininess ) {\n vec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );\n float dotNH = saturate( dot( geometry.normal, halfDir ) );\n float dotLH = saturate( dot( incidentLight.direction, halfDir ) );\n vec3 F = F_Schlick( specularColor, dotLH );\n float G = G_BlinnPhong_Implicit( );\n float D = D_BlinnPhong( shininess, dotNH );\n return F * ( G * D );\n}\nfloat GGXRoughnessToBlinnExponent( const in float ggxRoughness ) {\n return ( 2.0 / pow2( ggxRoughness + 0.0001 ) - 2.0 );\n}\nfloat BlinnExponentToGGXRoughness( const in float blinnExponent ) {\n return sqrt( 2.0 / ( blinnExponent + 2.0 ) );\n}\n";
  13946. // File:src/renderers/shaders/ShaderChunk/bumpmap_pars_fragment.glsl
  13947. 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";
  13948. // File:src/renderers/shaders/ShaderChunk/color_fragment.glsl
  13949. THREE.ShaderChunk[ 'color_fragment' ] = "#ifdef USE_COLOR\n diffuseColor.rgb *= vColor;\n#endif";
  13950. // File:src/renderers/shaders/ShaderChunk/color_pars_fragment.glsl
  13951. THREE.ShaderChunk[ 'color_pars_fragment' ] = "#ifdef USE_COLOR\n varying vec3 vColor;\n#endif\n";
  13952. // File:src/renderers/shaders/ShaderChunk/color_pars_vertex.glsl
  13953. THREE.ShaderChunk[ 'color_pars_vertex' ] = "#ifdef USE_COLOR\n varying vec3 vColor;\n#endif";
  13954. // File:src/renderers/shaders/ShaderChunk/color_vertex.glsl
  13955. THREE.ShaderChunk[ 'color_vertex' ] = "#ifdef USE_COLOR\n vColor.xyz = color.xyz;\n#endif";
  13956. // File:src/renderers/shaders/ShaderChunk/common.glsl
  13957. 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 pow2( const in float x ) { return x*x; }\nfloat pow3( const in float x ) { return x*x*x; }\nfloat pow4( const in float x ) { float x2 = x*x; return x2*x2; }\nfloat average( const in vec3 color ) { return dot( color, vec3( 0.3333 ) ); }\nstruct IncidentLight {\n vec3 color;\n vec3 direction;\n bool visible;\n};\nstruct ReflectedLight {\n vec3 directDiffuse;\n vec3 directSpecular;\n vec3 indirectDiffuse;\n vec3 indirectSpecular;\n};\nstruct GeometricContext {\n vec3 position;\n vec3 normal;\n vec3 viewDir;\n};\nvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n}\nvec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {\n return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );\n}\nvec3 projectOnPlane(in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n float distance = dot( planeNormal, point - pointOnPlane );\n return - distance * planeNormal + point;\n}\nfloat sideOfPlane( in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n return sign( dot( point - pointOnPlane, planeNormal ) );\n}\nvec3 linePlaneIntersect( in vec3 pointOnLine, in vec3 lineDirection, in vec3 pointOnPlane, in vec3 planeNormal ) {\n return lineDirection * ( dot( planeNormal, pointOnPlane - pointOnLine ) / dot( planeNormal, lineDirection ) ) + pointOnLine;\n}\n";
  13958. // File:src/renderers/shaders/ShaderChunk/cube_uv_reflection_fragment.glsl
  13959. THREE.ShaderChunk[ 'cube_uv_reflection_fragment' ] = "#ifdef ENVMAP_TYPE_CUBE_UV\nconst float cubeUV_textureSize = 1024.0;\nint getFaceFromDirection(vec3 direction) {\n vec3 absDirection = abs(direction);\n int face = -1;\n if( absDirection.x > absDirection.z ) {\n if(absDirection.x > absDirection.y )\n face = direction.x > 0.0 ? 0 : 3;\n else\n face = direction.y > 0.0 ? 1 : 4;\n }\n else {\n if(absDirection.z > absDirection.y )\n face = direction.z > 0.0 ? 2 : 5;\n else\n face = direction.y > 0.0 ? 1 : 4;\n }\n return face;\n}\nconst float cubeUV_maxLods1 = log2(cubeUV_textureSize*0.25) - 1.0;\nconst float cubeUV_rangeClamp = exp2((6.0 - 1.0) * 2.0);\nvec2 MipLevelInfo( vec3 vec, float roughnessLevel, float roughness ) {\n float scale = exp2(cubeUV_maxLods1 - roughnessLevel);\n float dxRoughness = dFdx(roughness);\n float dyRoughness = dFdy(roughness);\n vec3 dx = dFdx( vec * scale * dxRoughness );\n vec3 dy = dFdy( vec * scale * dyRoughness );\n float d = max( dot( dx, dx ), dot( dy, dy ) );\n d = clamp(d, 1.0, cubeUV_rangeClamp);\n float mipLevel = 0.5 * log2(d);\n return vec2(floor(mipLevel), fract(mipLevel));\n}\nconst float cubeUV_maxLods2 = log2(cubeUV_textureSize*0.25) - 2.0;\nconst float cubeUV_rcpTextureSize = 1.0 / cubeUV_textureSize;\nvec2 getCubeUV(vec3 direction, float roughnessLevel, float mipLevel) {\n mipLevel = roughnessLevel > cubeUV_maxLods2 - 3.0 ? 0.0 : mipLevel;\n float a = 16.0 * cubeUV_rcpTextureSize;\n vec2 exp2_packed = exp2( vec2( roughnessLevel, mipLevel ) );\n vec2 rcp_exp2_packed = vec2( 1.0 ) / exp2_packed;\n float powScale = exp2_packed.x * exp2_packed.y;\n float scale = rcp_exp2_packed.x * rcp_exp2_packed.y * 0.25;\n float mipOffset = 0.75*(1.0 - rcp_exp2_packed.y) * rcp_exp2_packed.x;\n bool bRes = mipLevel == 0.0;\n scale = bRes && (scale < a) ? a : scale;\n vec3 r;\n vec2 offset;\n int face = getFaceFromDirection(direction);\n float rcpPowScale = 1.0 / powScale;\n if( face == 0) {\n r = vec3(direction.x, -direction.z, direction.y);\n offset = vec2(0.0+mipOffset,0.75 * rcpPowScale);\n offset.y = bRes && (offset.y < 2.0*a) ? a : offset.y;\n }\n else if( face == 1) {\n r = vec3(direction.y, direction.x, direction.z);\n offset = vec2(scale+mipOffset, 0.75 * rcpPowScale);\n offset.y = bRes && (offset.y < 2.0*a) ? a : offset.y;\n }\n else if( face == 2) {\n r = vec3(direction.z, direction.x, direction.y);\n offset = vec2(2.0*scale+mipOffset, 0.75 * rcpPowScale);\n offset.y = bRes && (offset.y < 2.0*a) ? a : offset.y;\n }\n else if( face == 3) {\n r = vec3(direction.x, direction.z, direction.y);\n offset = vec2(0.0+mipOffset,0.5 * rcpPowScale);\n offset.y = bRes && (offset.y < 2.0*a) ? 0.0 : offset.y;\n }\n else if( face == 4) {\n r = vec3(direction.y, direction.x, -direction.z);\n offset = vec2(scale+mipOffset, 0.5 * rcpPowScale);\n offset.y = bRes && (offset.y < 2.0*a) ? 0.0 : offset.y;\n }\n else {\n r = vec3(direction.z, -direction.x, direction.y);\n offset = vec2(2.0*scale+mipOffset, 0.5 * rcpPowScale);\n offset.y = bRes && (offset.y < 2.0*a) ? 0.0 : offset.y;\n }\n r = normalize(r);\n float texelOffset = 0.5 * cubeUV_rcpTextureSize;\n vec2 s = ( r.yz / abs( r.x ) + vec2( 1.0 ) ) * 0.5;\n vec2 base = offset + vec2( texelOffset );\n return base + s * ( scale - 2.0 * texelOffset );\n}\nconst float cubeUV_maxLods3 = log2(cubeUV_textureSize*0.25) - 3.0;\nvec4 textureCubeUV(vec3 reflectedDirection, float roughness ) {\n float roughnessVal = roughness* cubeUV_maxLods3;\n float r1 = floor(roughnessVal);\n float r2 = r1 + 1.0;\n float t = fract(roughnessVal);\n vec2 mipInfo = MipLevelInfo(reflectedDirection, r1, roughness);\n float s = mipInfo.y;\n float level0 = mipInfo.x;\n float level1 = level0 + 1.0;\n level1 = level1 > 5.0 ? 5.0 : level1;\n level0 += min( floor( s + 0.5 ), 5.0 );\n vec2 uv_10 = getCubeUV(reflectedDirection, r1, level0);\n vec4 color10 = envMapTexelToLinear(texture2D(envMap, uv_10));\n vec2 uv_20 = getCubeUV(reflectedDirection, r2, level0);\n vec4 color20 = envMapTexelToLinear(texture2D(envMap, uv_20));\n vec4 result = mix(color10, color20, t);\n return vec4(result.rgb, 1.0);\n}\n#endif\n";
  13960. // File:src/renderers/shaders/ShaderChunk/defaultnormal_vertex.glsl
  13961. THREE.ShaderChunk[ 'defaultnormal_vertex' ] = "#ifdef FLIP_SIDED\n objectNormal = -objectNormal;\n#endif\nvec3 transformedNormal = normalMatrix * objectNormal;\n";
  13962. // File:src/renderers/shaders/ShaderChunk/displacementmap_vertex.glsl
  13963. THREE.ShaderChunk[ 'displacementmap_vertex' ] = "#ifdef USE_DISPLACEMENTMAP\n transformed += normal * ( texture2D( displacementMap, uv ).x * displacementScale + displacementBias );\n#endif\n";
  13964. // File:src/renderers/shaders/ShaderChunk/displacementmap_pars_vertex.glsl
  13965. THREE.ShaderChunk[ 'displacementmap_pars_vertex' ] = "#ifdef USE_DISPLACEMENTMAP\n uniform sampler2D displacementMap;\n uniform float displacementScale;\n uniform float displacementBias;\n#endif\n";
  13966. // File:src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl
  13967. THREE.ShaderChunk[ 'emissivemap_fragment' ] = "#ifdef USE_EMISSIVEMAP\n vec4 emissiveColor = texture2D( emissiveMap, vUv );\n emissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\n totalEmissiveRadiance *= emissiveColor.rgb;\n#endif\n";
  13968. // File:src/renderers/shaders/ShaderChunk/emissivemap_pars_fragment.glsl
  13969. THREE.ShaderChunk[ 'emissivemap_pars_fragment' ] = "#ifdef USE_EMISSIVEMAP\n uniform sampler2D emissiveMap;\n#endif\n";
  13970. // File:src/renderers/shaders/ShaderChunk/encodings_pars_fragment.glsl
  13971. THREE.ShaderChunk[ 'encodings_pars_fragment' ] = "\nvec4 LinearToLinear( in vec4 value ) {\n return value;\n}\nvec4 GammaToLinear( in vec4 value, in float gammaFactor ) {\n return vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );\n}\nvec4 LinearToGamma( in vec4 value, in float gammaFactor ) {\n return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );\n}\nvec4 sRGBToLinear( in vec4 value ) {\n return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.w );\n}\nvec4 LinearTosRGB( in vec4 value ) {\n return vec4( mix( pow( value.rgb, vec3( 0.41666 ) ) - vec3( 0.055 ), value.rgb * 12.92, vec3( lessThanEqual( value.rgb, vec3( 0.0031308 ) ) ) ), value.w );\n}\nvec4 RGBEToLinear( in vec4 value ) {\n return vec4( value.rgb * exp2( value.a * 255.0 - 128.0 ), 1.0 );\n}\nvec4 LinearToRGBE( in vec4 value ) {\n float maxComponent = max( max( value.r, value.g ), value.b );\n float fExp = clamp( ceil( log2( maxComponent ) ), -128.0, 127.0 );\n return vec4( value.rgb / exp2( fExp ), ( fExp + 128.0 ) / 255.0 );\n}\nvec4 RGBMToLinear( in vec4 value, in float maxRange ) {\n return vec4( value.xyz * value.w * maxRange, 1.0 );\n}\nvec4 LinearToRGBM( in vec4 value, in float maxRange ) {\n float maxRGB = max( value.x, max( value.g, value.b ) );\n float M = clamp( maxRGB / maxRange, 0.0, 1.0 );\n M = ceil( M * 255.0 ) / 255.0;\n return vec4( value.rgb / ( M * maxRange ), M );\n}\nvec4 RGBDToLinear( in vec4 value, in float maxRange ) {\n return vec4( value.rgb * ( ( maxRange / 255.0 ) / value.a ), 1.0 );\n}\nvec4 LinearToRGBD( in vec4 value, in float maxRange ) {\n float maxRGB = max( value.x, max( value.g, value.b ) );\n float D = max( maxRange / maxRGB, 1.0 );\n D = min( floor( D ) / 255.0, 1.0 );\n return vec4( value.rgb * ( D * ( 255.0 / maxRange ) ), D );\n}\nconst mat3 cLogLuvM = mat3( 0.2209, 0.3390, 0.4184, 0.1138, 0.6780, 0.7319, 0.0102, 0.1130, 0.2969 );\nvec4 LinearToLogLuv( in vec4 value ) {\n vec3 Xp_Y_XYZp = value.rgb * cLogLuvM;\n Xp_Y_XYZp = max(Xp_Y_XYZp, vec3(1e-6, 1e-6, 1e-6));\n vec4 vResult;\n vResult.xy = Xp_Y_XYZp.xy / Xp_Y_XYZp.z;\n float Le = 2.0 * log2(Xp_Y_XYZp.y) + 127.0;\n vResult.w = fract(Le);\n vResult.z = (Le - (floor(vResult.w*255.0))/255.0)/255.0;\n return vResult;\n}\nconst mat3 cLogLuvInverseM = mat3( 6.0014, -2.7008, -1.7996, -1.3320, 3.1029, -5.7721, 0.3008, -1.0882, 5.6268 );\nvec4 LogLuvToLinear( in vec4 value ) {\n float Le = value.z * 255.0 + value.w;\n vec3 Xp_Y_XYZp;\n Xp_Y_XYZp.y = exp2((Le - 127.0) / 2.0);\n Xp_Y_XYZp.z = Xp_Y_XYZp.y / value.y;\n Xp_Y_XYZp.x = value.x * Xp_Y_XYZp.z;\n vec3 vRGB = Xp_Y_XYZp.rgb * cLogLuvInverseM;\n return vec4( max(vRGB, 0.0), 1.0 );\n}\n";
  13972. // File:src/renderers/shaders/ShaderChunk/encodings_fragment.glsl
  13973. THREE.ShaderChunk[ 'encodings_fragment' ] = " gl_FragColor = linearToOutputTexel( gl_FragColor );\n";
  13974. // File:src/renderers/shaders/ShaderChunk/envmap_fragment.glsl
  13975. 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 = envMapTexelToLinear( envColor );\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";
  13976. // File:src/renderers/shaders/ShaderChunk/envmap_pars_fragment.glsl
  13977. THREE.ShaderChunk[ 'envmap_pars_fragment' ] = "#if defined( USE_ENVMAP ) || defined( STANDARD )\n uniform float reflectivity;\n uniform float envMapIntenstiy;\n#endif\n#ifdef USE_ENVMAP\n #ifdef ENVMAP_TYPE_CUBE\n uniform samplerCube envMap;\n #else\n uniform sampler2D envMap;\n #endif\n uniform float flipEnvMap;\n #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( STANDARD )\n uniform float refractionRatio;\n #else\n varying vec3 vReflect;\n #endif\n#endif\n";
  13978. // File:src/renderers/shaders/ShaderChunk/envmap_pars_vertex.glsl
  13979. THREE.ShaderChunk[ 'envmap_pars_vertex' ] = "#if defined( USE_ENVMAP ) && ! defined( USE_BUMPMAP ) && ! defined( USE_NORMALMAP ) && ! defined( PHONG ) && ! defined( STANDARD )\n varying vec3 vReflect;\n uniform float refractionRatio;\n#endif\n";
  13980. // File:src/renderers/shaders/ShaderChunk/envmap_vertex.glsl
  13981. THREE.ShaderChunk[ 'envmap_vertex' ] = "#if defined( USE_ENVMAP ) && ! defined( USE_BUMPMAP ) && ! defined( USE_NORMALMAP ) && ! defined( PHONG ) && ! defined( STANDARD )\n vec3 cameraToVertex = normalize( worldPosition.xyz - cameraPosition );\n vec3 worldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\n #ifdef ENVMAP_MODE_REFLECTION\n vReflect = reflect( cameraToVertex, worldNormal );\n #else\n vReflect = refract( cameraToVertex, worldNormal, refractionRatio );\n #endif\n#endif\n";
  13982. // File:src/renderers/shaders/ShaderChunk/fog_fragment.glsl
  13983. 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 gl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor );\n#endif\n";
  13984. // File:src/renderers/shaders/ShaderChunk/fog_pars_fragment.glsl
  13985. 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";
  13986. // File:src/renderers/shaders/ShaderChunk/lightmap_fragment.glsl
  13987. THREE.ShaderChunk[ 'lightmap_fragment' ] = "#ifdef USE_LIGHTMAP\n reflectedLight.indirectDiffuse += PI * texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n#endif\n";
  13988. // File:src/renderers/shaders/ShaderChunk/lightmap_pars_fragment.glsl
  13989. THREE.ShaderChunk[ 'lightmap_pars_fragment' ] = "#ifdef USE_LIGHTMAP\n uniform sampler2D lightMap;\n uniform float lightMapIntensity;\n#endif";
  13990. // File:src/renderers/shaders/ShaderChunk/lights_lambert_vertex.glsl
  13991. THREE.ShaderChunk[ 'lights_lambert_vertex' ] = "vec3 diffuse = vec3( 1.0 );\nGeometricContext geometry;\ngeometry.position = mvPosition.xyz;\ngeometry.normal = normalize( transformedNormal );\ngeometry.viewDir = normalize( -mvPosition.xyz );\nGeometricContext backGeometry;\nbackGeometry.position = geometry.position;\nbackGeometry.normal = -geometry.normal;\nbackGeometry.viewDir = geometry.viewDir;\nvLightFront = vec3( 0.0 );\n#ifdef DOUBLE_SIDED\n vLightBack = vec3( 0.0 );\n#endif\nIncidentLight directLight;\nfloat dotNL;\nvec3 directLightColor_Diffuse;\n#if NUM_POINT_LIGHTS > 0\n for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n directLight = getPointDirectLightIrradiance( pointLights[ i ], geometry );\n dotNL = dot( geometry.normal, directLight.direction );\n directLightColor_Diffuse = PI * directLight.color;\n vLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n #ifdef DOUBLE_SIDED\n vLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n #endif\n }\n#endif\n#if NUM_SPOT_LIGHTS > 0\n for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n directLight = getSpotDirectLightIrradiance( spotLights[ i ], geometry );\n dotNL = dot( geometry.normal, directLight.direction );\n directLightColor_Diffuse = PI * directLight.color;\n vLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n #ifdef DOUBLE_SIDED\n vLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n #endif\n }\n#endif\n#if NUM_DIR_LIGHTS > 0\n for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n directLight = getDirectionalDirectLightIrradiance( directionalLights[ i ], geometry );\n dotNL = dot( geometry.normal, directLight.direction );\n directLightColor_Diffuse = PI * directLight.color;\n vLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n #ifdef DOUBLE_SIDED\n vLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n #endif\n }\n#endif\n#if NUM_HEMI_LIGHTS > 0\n for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n vLightFront += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry );\n #ifdef DOUBLE_SIDED\n vLightBack += getHemisphereLightIrradiance( hemisphereLights[ i ], backGeometry );\n #endif\n }\n#endif\n";
  13992. // File:src/renderers/shaders/ShaderChunk/lights_pars.glsl
  13993. THREE.ShaderChunk[ 'lights_pars' ] = "uniform vec3 ambientLightColor;\nvec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {\n vec3 irradiance = ambientLightColor;\n #ifndef PHYSICALLY_CORRECT_LIGHTS\n irradiance *= PI;\n #endif\n return irradiance;\n}\n#if NUM_DIR_LIGHTS > 0\n struct DirectionalLight {\n vec3 direction;\n vec3 color;\n int shadow;\n float shadowBias;\n float shadowRadius;\n vec2 shadowMapSize;\n };\n uniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];\n IncidentLight getDirectionalDirectLightIrradiance( const in DirectionalLight directionalLight, const in GeometricContext geometry ) {\n IncidentLight directLight;\n directLight.color = directionalLight.color;\n directLight.direction = directionalLight.direction;\n directLight.visible = true;\n return directLight;\n }\n#endif\n#if NUM_POINT_LIGHTS > 0\n struct PointLight {\n vec3 position;\n vec3 color;\n float distance;\n float decay;\n int shadow;\n float shadowBias;\n float shadowRadius;\n vec2 shadowMapSize;\n };\n uniform PointLight pointLights[ NUM_POINT_LIGHTS ];\n IncidentLight getPointDirectLightIrradiance( const in PointLight pointLight, const in GeometricContext geometry ) {\n IncidentLight directLight;\n vec3 lVector = pointLight.position - geometry.position;\n directLight.direction = normalize( lVector );\n float lightDistance = length( lVector );\n if ( testLightInRange( lightDistance, pointLight.distance ) ) {\n directLight.color = pointLight.color;\n directLight.color *= punctualLightIntensityToIrradianceFactor( lightDistance, pointLight.distance, pointLight.decay );\n directLight.visible = true;\n } else {\n directLight.color = vec3( 0.0 );\n directLight.visible = false;\n }\n return directLight;\n }\n#endif\n#if NUM_SPOT_LIGHTS > 0\n struct SpotLight {\n vec3 position;\n vec3 direction;\n vec3 color;\n float distance;\n float decay;\n float coneCos;\n float penumbraCos;\n int shadow;\n float shadowBias;\n float shadowRadius;\n vec2 shadowMapSize;\n };\n uniform SpotLight spotLights[ NUM_SPOT_LIGHTS ];\n IncidentLight getSpotDirectLightIrradiance( const in SpotLight spotLight, const in GeometricContext geometry ) {\n IncidentLight directLight;\n vec3 lVector = spotLight.position - geometry.position;\n directLight.direction = normalize( lVector );\n float lightDistance = length( lVector );\n float angleCos = dot( directLight.direction, spotLight.direction );\n if ( all( bvec2( angleCos > spotLight.coneCos, testLightInRange( lightDistance, spotLight.distance ) ) ) ) {\n float spotEffect = smoothstep( spotLight.coneCos, spotLight.penumbraCos, angleCos );\n directLight.color = spotLight.color;\n directLight.color *= spotEffect * punctualLightIntensityToIrradianceFactor( lightDistance, spotLight.distance, spotLight.decay );\n directLight.visible = true;\n } else {\n directLight.color = vec3( 0.0 );\n directLight.visible = false;\n }\n return directLight;\n }\n#endif\n#if NUM_HEMI_LIGHTS > 0\n struct HemisphereLight {\n vec3 direction;\n vec3 skyColor;\n vec3 groundColor;\n };\n uniform HemisphereLight hemisphereLights[ NUM_HEMI_LIGHTS ];\n vec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in GeometricContext geometry ) {\n float dotNL = dot( geometry.normal, hemiLight.direction );\n float hemiDiffuseWeight = 0.5 * dotNL + 0.5;\n vec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );\n #ifndef PHYSICALLY_CORRECT_LIGHTS\n irradiance *= PI;\n #endif\n return irradiance;\n }\n#endif\n#if defined( USE_ENVMAP ) && defined( STANDARD )\n vec3 getLightProbeIndirectIrradiance( const in GeometricContext geometry, const in int maxMIPLevel ) {\n #ifdef DOUBLE_SIDED\n float flipNormal = ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n #else\n float flipNormal = 1.0;\n #endif\n vec3 worldNormal = inverseTransformDirection( geometry.normal, viewMatrix );\n #ifdef ENVMAP_TYPE_CUBE\n vec3 queryVec = flipNormal * vec3( flipEnvMap * worldNormal.x, worldNormal.yz );\n #ifdef TEXTURE_LOD_EXT\n vec4 envMapColor = textureCubeLodEXT( envMap, queryVec, float( maxMIPLevel ) );\n #else\n vec4 envMapColor = textureCube( envMap, queryVec, float( maxMIPLevel ) );\n #endif\n #elif defined( ENVMAP_TYPE_CUBE_UV )\n vec3 queryVec = flipNormal * vec3( flipEnvMap * worldNormal.x, worldNormal.yz );\n vec4 envMapColor = textureCubeUV( queryVec, 1.0 );\n #else\n vec4 envMapColor = vec4( 0.0 );\n #endif\n envMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\n return PI * envMapColor.rgb * envMapIntensity;\n }\n float getSpecularMIPLevel( const in float blinnShininessExponent, const in int maxMIPLevel ) {\n float maxMIPLevelScalar = float( maxMIPLevel );\n float desiredMIPLevel = maxMIPLevelScalar - 0.79248 - 0.5 * log2( pow2( blinnShininessExponent ) + 1.0 );\n return clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );\n }\n vec3 getLightProbeIndirectRadiance( const in GeometricContext geometry, const in float blinnShininessExponent, const in int maxMIPLevel ) {\n #ifdef ENVMAP_MODE_REFLECTION\n vec3 reflectVec = reflect( -geometry.viewDir, geometry.normal );\n #else\n vec3 reflectVec = refract( -geometry.viewDir, geometry.normal, refractionRatio );\n #endif\n #ifdef DOUBLE_SIDED\n float flipNormal = ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n #else\n float flipNormal = 1.0;\n #endif\n reflectVec = inverseTransformDirection( reflectVec, viewMatrix );\n float specularMIPLevel = getSpecularMIPLevel( blinnShininessExponent, maxMIPLevel );\n #ifdef ENVMAP_TYPE_CUBE\n vec3 queryReflectVec = flipNormal * vec3( flipEnvMap * reflectVec.x, reflectVec.yz );\n #ifdef TEXTURE_LOD_EXT\n vec4 envMapColor = textureCubeLodEXT( envMap, queryReflectVec, specularMIPLevel );\n #else\n vec4 envMapColor = textureCube( envMap, queryReflectVec, specularMIPLevel );\n #endif\n #elif defined( ENVMAP_TYPE_CUBE_UV )\n vec3 queryReflectVec = flipNormal * vec3( flipEnvMap * reflectVec.x, reflectVec.yz );\n vec4 envMapColor = textureCubeUV(queryReflectVec, BlinnExponentToGGXRoughness(blinnShininessExponent));\n #elif defined( ENVMAP_TYPE_EQUIREC )\n vec2 sampleUV;\n sampleUV.y = saturate( flipNormal * reflectVec.y * 0.5 + 0.5 );\n sampleUV.x = atan( flipNormal * reflectVec.z, flipNormal * reflectVec.x ) * RECIPROCAL_PI2 + 0.5;\n #ifdef TEXTURE_LOD_EXT\n vec4 envMapColor = texture2DLodEXT( envMap, sampleUV, specularMIPLevel );\n #else\n vec4 envMapColor = texture2D( envMap, sampleUV, specularMIPLevel );\n #endif\n #elif defined( ENVMAP_TYPE_SPHERE )\n vec3 reflectView = flipNormal * normalize((viewMatrix * vec4( reflectVec, 0.0 )).xyz + vec3(0.0,0.0,1.0));\n #ifdef TEXTURE_LOD_EXT\n vec4 envMapColor = texture2DLodEXT( envMap, reflectView.xy * 0.5 + 0.5, specularMIPLevel );\n #else\n vec4 envMapColor = texture2D( envMap, reflectView.xy * 0.5 + 0.5, specularMIPLevel );\n #endif\n #endif\n envMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\n return envMapColor.rgb * envMapIntensity;\n }\n#endif\n";
  13994. // File:src/renderers/shaders/ShaderChunk/lights_phong_fragment.glsl
  13995. THREE.ShaderChunk[ 'lights_phong_fragment' ] = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;\n";
  13996. // File:src/renderers/shaders/ShaderChunk/lights_phong_pars_fragment.glsl
  13997. THREE.ShaderChunk[ 'lights_phong_pars_fragment' ] = "#ifdef USE_ENVMAP\n varying vec3 vWorldPosition;\n#endif\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n varying vec3 vNormal;\n#endif\nstruct BlinnPhongMaterial {\n vec3 diffuseColor;\n vec3 specularColor;\n float specularShininess;\n float specularStrength;\n};\nvoid RE_Direct_BlinnPhong( const in IncidentLight directLight, const in GeometricContext geometry, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n float dotNL = saturate( dot( geometry.normal, directLight.direction ) );\n vec3 irradiance = dotNL * directLight.color;\n #ifndef PHYSICALLY_CORRECT_LIGHTS\n irradiance *= PI;\n #endif\n reflectedLight.directDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n reflectedLight.directSpecular += irradiance * BRDF_Specular_BlinnPhong( directLight, geometry, material.specularColor, material.specularShininess ) * material.specularStrength;\n}\nvoid RE_IndirectDiffuse_BlinnPhong( const in vec3 irradiance, const in GeometricContext geometry, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n reflectedLight.indirectDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n}\n#define RE_Direct RE_Direct_BlinnPhong\n#define RE_IndirectDiffuse RE_IndirectDiffuse_BlinnPhong\n#define Material_LightProbeLOD( material ) (0)\n";
  13998. // File:src/renderers/shaders/ShaderChunk/lights_phong_pars_vertex.glsl
  13999. THREE.ShaderChunk[ 'lights_phong_pars_vertex' ] = "#ifdef USE_ENVMAP\n varying vec3 vWorldPosition;\n#endif\n";
  14000. // File:src/renderers/shaders/ShaderChunk/lights_phong_vertex.glsl
  14001. THREE.ShaderChunk[ 'lights_phong_vertex' ] = "#ifdef USE_ENVMAP\n vWorldPosition = worldPosition.xyz;\n#endif\n";
  14002. // File:src/renderers/shaders/ShaderChunk/lights_standard_fragment.glsl
  14003. THREE.ShaderChunk[ 'lights_standard_fragment' ] = "StandardMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );\nmaterial.specularRoughness = clamp( roughnessFactor, 0.04, 1.0 );\nmaterial.specularColor = mix( vec3( 0.04 ), diffuseColor.rgb, metalnessFactor );\n";
  14004. // File:src/renderers/shaders/ShaderChunk/lights_standard_pars_fragment.glsl
  14005. THREE.ShaderChunk[ 'lights_standard_pars_fragment' ] = "struct StandardMaterial {\n vec3 diffuseColor;\n float specularRoughness;\n vec3 specularColor;\n};\nvoid RE_Direct_Standard( const in IncidentLight directLight, const in GeometricContext geometry, const in StandardMaterial material, inout ReflectedLight reflectedLight ) {\n float dotNL = saturate( dot( geometry.normal, directLight.direction ) );\n vec3 irradiance = dotNL * directLight.color;\n #ifndef PHYSICALLY_CORRECT_LIGHTS\n irradiance *= PI;\n #endif\n reflectedLight.directDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n reflectedLight.directSpecular += irradiance * BRDF_Specular_GGX( directLight, geometry, material.specularColor, material.specularRoughness );\n}\nvoid RE_IndirectDiffuse_Standard( const in vec3 irradiance, const in GeometricContext geometry, const in StandardMaterial material, inout ReflectedLight reflectedLight ) {\n reflectedLight.indirectDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectSpecular_Standard( const in vec3 radiance, const in GeometricContext geometry, const in StandardMaterial material, inout ReflectedLight reflectedLight ) {\n reflectedLight.indirectSpecular += radiance * BRDF_Specular_GGX_Environment( geometry, material.specularColor, material.specularRoughness );\n}\n#define RE_Direct RE_Direct_Standard\n#define RE_IndirectDiffuse RE_IndirectDiffuse_Standard\n#define RE_IndirectSpecular RE_IndirectSpecular_Standard\n#define Material_BlinnShininessExponent( material ) GGXRoughnessToBlinnExponent( material.specularRoughness )\nfloat computeSpecularOcclusion( const in float dotNV, const in float ambientOcclusion, const in float roughness ) {\n return saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion );\n}\n";
  14006. // File:src/renderers/shaders/ShaderChunk/lights_template.glsl
  14007. THREE.ShaderChunk[ 'lights_template' ] = "\nGeometricContext geometry;\ngeometry.position = - vViewPosition;\ngeometry.normal = normal;\ngeometry.viewDir = normalize( vViewPosition );\nIncidentLight directLight;\n#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )\n PointLight pointLight;\n for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n pointLight = pointLights[ i ];\n directLight = getPointDirectLightIrradiance( pointLight, geometry );\n #ifdef USE_SHADOWMAP\n directLight.color *= all( bvec2( pointLight.shadow, directLight.visible ) ) ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ] ) : 1.0;\n #endif\n RE_Direct( directLight, geometry, material, reflectedLight );\n }\n#endif\n#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )\n SpotLight spotLight;\n for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n spotLight = spotLights[ i ];\n directLight = getSpotDirectLightIrradiance( spotLight, geometry );\n #ifdef USE_SHADOWMAP\n directLight.color *= all( bvec2( spotLight.shadow, directLight.visible ) ) ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowBias, spotLight.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\n #endif\n RE_Direct( directLight, geometry, material, reflectedLight );\n }\n#endif\n#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )\n DirectionalLight directionalLight;\n for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n directionalLight = directionalLights[ i ];\n directLight = getDirectionalDirectLightIrradiance( directionalLight, geometry );\n #ifdef USE_SHADOWMAP\n directLight.color *= all( bvec2( directionalLight.shadow, directLight.visible ) ) ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n #endif\n RE_Direct( directLight, geometry, material, reflectedLight );\n }\n#endif\n#if defined( RE_IndirectDiffuse )\n vec3 irradiance = getAmbientLightIrradiance( ambientLightColor );\n #ifdef USE_LIGHTMAP\n vec3 lightMapIrradiance = texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n #ifndef PHYSICALLY_CORRECT_LIGHTS\n lightMapIrradiance *= PI;\n #endif\n irradiance += lightMapIrradiance;\n #endif\n #if ( NUM_HEMI_LIGHTS > 0 )\n for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry );\n }\n #endif\n #if defined( USE_ENVMAP ) && defined( STANDARD ) && defined( ENVMAP_TYPE_CUBE_UV )\n irradiance += getLightProbeIndirectIrradiance( geometry, 8 );\n #endif\n RE_IndirectDiffuse( irradiance, geometry, material, reflectedLight );\n#endif\n#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )\n vec3 radiance = getLightProbeIndirectRadiance( geometry, Material_BlinnShininessExponent( material ), 8 );\n RE_IndirectSpecular( radiance, geometry, material, reflectedLight );\n#endif\n";
  14008. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl
  14009. THREE.ShaderChunk[ 'logdepthbuf_fragment' ] = "#if defined(USE_LOGDEPTHBUF) && defined(USE_LOGDEPTHBUF_EXT)\n gl_FragDepthEXT = log2(vFragDepth) * logDepthBufFC * 0.5;\n#endif";
  14010. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl
  14011. 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";
  14012. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_pars_vertex.glsl
  14013. 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";
  14014. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl
  14015. 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";
  14016. // File:src/renderers/shaders/ShaderChunk/map_fragment.glsl
  14017. THREE.ShaderChunk[ 'map_fragment' ] = "#ifdef USE_MAP\n vec4 texelColor = texture2D( map, vUv );\n texelColor = mapTexelToLinear( texelColor );\n diffuseColor *= texelColor;\n#endif\n";
  14018. // File:src/renderers/shaders/ShaderChunk/map_pars_fragment.glsl
  14019. THREE.ShaderChunk[ 'map_pars_fragment' ] = "#ifdef USE_MAP\n uniform sampler2D map;\n#endif\n";
  14020. // File:src/renderers/shaders/ShaderChunk/map_particle_fragment.glsl
  14021. THREE.ShaderChunk[ 'map_particle_fragment' ] = "#ifdef USE_MAP\n vec4 mapTexel = texture2D( map, vec2( gl_PointCoord.x, 1.0 - gl_PointCoord.y ) * offsetRepeat.zw + offsetRepeat.xy );\n diffuseColor *= mapTexelToLinear( mapTexel );\n#endif\n";
  14022. // File:src/renderers/shaders/ShaderChunk/map_particle_pars_fragment.glsl
  14023. THREE.ShaderChunk[ 'map_particle_pars_fragment' ] = "#ifdef USE_MAP\n uniform vec4 offsetRepeat;\n uniform sampler2D map;\n#endif\n";
  14024. // File:src/renderers/shaders/ShaderChunk/metalnessmap_fragment.glsl
  14025. THREE.ShaderChunk[ 'metalnessmap_fragment' ] = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n vec4 texelMetalness = texture2D( metalnessMap, vUv );\n metalnessFactor *= texelMetalness.r;\n#endif\n";
  14026. // File:src/renderers/shaders/ShaderChunk/metalnessmap_pars_fragment.glsl
  14027. THREE.ShaderChunk[ 'metalnessmap_pars_fragment' ] = "#ifdef USE_METALNESSMAP\n uniform sampler2D metalnessMap;\n#endif";
  14028. // File:src/renderers/shaders/ShaderChunk/morphnormal_vertex.glsl
  14029. 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";
  14030. // File:src/renderers/shaders/ShaderChunk/morphtarget_pars_vertex.glsl
  14031. 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";
  14032. // File:src/renderers/shaders/ShaderChunk/morphtarget_vertex.glsl
  14033. 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";
  14034. // File:src/renderers/shaders/ShaderChunk/normal_fragment.glsl
  14035. THREE.ShaderChunk[ 'normal_fragment' ] = "#ifdef FLAT_SHADED\n vec3 fdx = vec3( dFdx( vViewPosition.x ), dFdx( vViewPosition.y ), dFdx( vViewPosition.z ) );\n vec3 fdy = vec3( dFdy( vViewPosition.x ), dFdy( vViewPosition.y ), dFdy( vViewPosition.z ) );\n vec3 normal = normalize( cross( fdx, fdy ) );\n#else\n vec3 normal = normalize( vNormal );\n #ifdef DOUBLE_SIDED\n normal = normal * ( -1.0 + 2.0 * float( gl_FrontFacing ) );\n #endif\n#endif\n#ifdef USE_NORMALMAP\n normal = perturbNormal2Arb( -vViewPosition, normal );\n#elif defined( USE_BUMPMAP )\n normal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd() );\n#endif\n";
  14036. // File:src/renderers/shaders/ShaderChunk/normalmap_pars_fragment.glsl
  14037. 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";
  14038. // File:src/renderers/shaders/ShaderChunk/premultiplied_alpha_fragment.glsl
  14039. THREE.ShaderChunk[ 'premultiplied_alpha_fragment' ] = "#ifdef PREMULTIPLIED_ALPHA\n gl_FragColor.rgb *= gl_FragColor.a;\n#endif\n";
  14040. // File:src/renderers/shaders/ShaderChunk/project_vertex.glsl
  14041. 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";
  14042. // File:src/renderers/shaders/ShaderChunk/roughnessmap_fragment.glsl
  14043. THREE.ShaderChunk[ 'roughnessmap_fragment' ] = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n vec4 texelRoughness = texture2D( roughnessMap, vUv );\n roughnessFactor *= texelRoughness.r;\n#endif\n";
  14044. // File:src/renderers/shaders/ShaderChunk/roughnessmap_pars_fragment.glsl
  14045. THREE.ShaderChunk[ 'roughnessmap_pars_fragment' ] = "#ifdef USE_ROUGHNESSMAP\n uniform sampler2D roughnessMap;\n#endif";
  14046. // File:src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl
  14047. THREE.ShaderChunk[ 'shadowmap_pars_fragment' ] = "#ifdef USE_SHADOWMAP\n #if NUM_DIR_LIGHTS > 0\n uniform sampler2D directionalShadowMap[ NUM_DIR_LIGHTS ];\n varying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHTS ];\n #endif\n #if NUM_SPOT_LIGHTS > 0\n uniform sampler2D spotShadowMap[ NUM_SPOT_LIGHTS ];\n varying vec4 vSpotShadowCoord[ NUM_SPOT_LIGHTS ];\n #endif\n #if NUM_POINT_LIGHTS > 0\n uniform sampler2D pointShadowMap[ NUM_POINT_LIGHTS ];\n varying vec4 vPointShadowCoord[ NUM_POINT_LIGHTS ];\n #endif\n float unpackDepth( const in vec4 rgba_depth ) {\n const vec4 bit_shift = vec4( 1.0 / ( 256.0 * 256.0 * 256.0 ), 1.0 / ( 256.0 * 256.0 ), 1.0 / 256.0, 1.0 );\n return dot( rgba_depth, bit_shift );\n }\n float texture2DCompare( sampler2D depths, vec2 uv, float compare ) {\n return step( compare, unpackDepth( texture2D( depths, uv ) ) );\n }\n float texture2DShadowLerp( sampler2D depths, vec2 size, vec2 uv, float compare ) {\n const vec2 offset = vec2( 0.0, 1.0 );\n vec2 texelSize = vec2( 1.0 ) / size;\n vec2 centroidUV = floor( uv * size + 0.5 ) / size;\n float lb = texture2DCompare( depths, centroidUV + texelSize * offset.xx, compare );\n float lt = texture2DCompare( depths, centroidUV + texelSize * offset.xy, compare );\n float rb = texture2DCompare( depths, centroidUV + texelSize * offset.yx, compare );\n float rt = texture2DCompare( depths, centroidUV + texelSize * offset.yy, compare );\n vec2 f = fract( uv * size + 0.5 );\n float a = mix( lb, lt, f.y );\n float b = mix( rb, rt, f.y );\n float c = mix( a, b, f.x );\n return c;\n }\n float getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord ) {\n shadowCoord.xyz /= shadowCoord.w;\n shadowCoord.z += shadowBias;\n bvec4 inFrustumVec = bvec4 ( shadowCoord.x >= 0.0, shadowCoord.x <= 1.0, shadowCoord.y >= 0.0, shadowCoord.y <= 1.0 );\n bool inFrustum = all( inFrustumVec );\n bvec2 frustumTestVec = bvec2( inFrustum, shadowCoord.z <= 1.0 );\n bool frustumTest = all( frustumTestVec );\n if ( frustumTest ) {\n #if defined( SHADOWMAP_TYPE_PCF )\n vec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n float dx0 = - texelSize.x * shadowRadius;\n float dy0 = - texelSize.y * shadowRadius;\n float dx1 = + texelSize.x * shadowRadius;\n float dy1 = + texelSize.y * shadowRadius;\n return (\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )\n ) * ( 1.0 / 9.0 );\n #elif defined( SHADOWMAP_TYPE_PCF_SOFT )\n vec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n float dx0 = - texelSize.x * shadowRadius;\n float dy0 = - texelSize.y * shadowRadius;\n float dx1 = + texelSize.x * shadowRadius;\n float dy1 = + texelSize.y * shadowRadius;\n return (\n texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +\n texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +\n texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +\n texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +\n texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy, shadowCoord.z ) +\n texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +\n texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +\n texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +\n texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )\n ) * ( 1.0 / 9.0 );\n #else\n return texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z );\n #endif\n }\n return 1.0;\n }\n vec2 cubeToUV( vec3 v, float texelSizeY ) {\n vec3 absV = abs( v );\n float scaleToCube = 1.0 / max( absV.x, max( absV.y, absV.z ) );\n absV *= scaleToCube;\n v *= scaleToCube * ( 1.0 - 2.0 * texelSizeY );\n vec2 planar = v.xy;\n float almostATexel = 1.5 * texelSizeY;\n float almostOne = 1.0 - almostATexel;\n if ( absV.z >= almostOne ) {\n if ( v.z > 0.0 )\n planar.x = 4.0 - v.x;\n } else if ( absV.x >= almostOne ) {\n float signX = sign( v.x );\n planar.x = v.z * signX + 2.0 * signX;\n } else if ( absV.y >= almostOne ) {\n float signY = sign( v.y );\n planar.x = v.x + 2.0 * signY + 2.0;\n planar.y = v.z * signY - 2.0;\n }\n return vec2( 0.125, 0.25 ) * planar + vec2( 0.375, 0.75 );\n }\n float getPointShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord ) {\n vec2 texelSize = vec2( 1.0 ) / ( shadowMapSize * vec2( 4.0, 2.0 ) );\n vec3 lightToPosition = shadowCoord.xyz;\n vec3 bd3D = normalize( lightToPosition );\n float dp = ( length( lightToPosition ) - shadowBias ) / 1000.0;\n #if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT )\n vec2 offset = vec2( - 1, 1 ) * shadowRadius * texelSize.y;\n return (\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyy, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyy, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyx, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyx, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxy, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxy, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxx, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxx, texelSize.y ), dp )\n ) * ( 1.0 / 9.0 );\n #else\n return texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp );\n #endif\n }\n#endif\n";
  14048. // File:src/renderers/shaders/ShaderChunk/shadowmap_pars_vertex.glsl
  14049. THREE.ShaderChunk[ 'shadowmap_pars_vertex' ] = "#ifdef USE_SHADOWMAP\n #if NUM_DIR_LIGHTS > 0\n uniform mat4 directionalShadowMatrix[ NUM_DIR_LIGHTS ];\n varying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHTS ];\n #endif\n #if NUM_SPOT_LIGHTS > 0\n uniform mat4 spotShadowMatrix[ NUM_SPOT_LIGHTS ];\n varying vec4 vSpotShadowCoord[ NUM_SPOT_LIGHTS ];\n #endif\n #if NUM_POINT_LIGHTS > 0\n uniform mat4 pointShadowMatrix[ NUM_POINT_LIGHTS ];\n varying vec4 vPointShadowCoord[ NUM_POINT_LIGHTS ];\n #endif\n#endif\n";
  14050. // File:src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl
  14051. THREE.ShaderChunk[ 'shadowmap_vertex' ] = "#ifdef USE_SHADOWMAP\n #if NUM_DIR_LIGHTS > 0\n for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n vDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * worldPosition;\n }\n #endif\n #if NUM_SPOT_LIGHTS > 0\n for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n vSpotShadowCoord[ i ] = spotShadowMatrix[ i ] * worldPosition;\n }\n #endif\n #if NUM_POINT_LIGHTS > 0\n for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n vPointShadowCoord[ i ] = pointShadowMatrix[ i ] * worldPosition;\n }\n #endif\n#endif\n";
  14052. // File:src/renderers/shaders/ShaderChunk/shadowmask_pars_fragment.glsl
  14053. THREE.ShaderChunk[ 'shadowmask_pars_fragment' ] = "float getShadowMask() {\n float shadow = 1.0;\n #ifdef USE_SHADOWMAP\n #if NUM_DIR_LIGHTS > 0\n DirectionalLight directionalLight;\n for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n directionalLight = directionalLights[ i ];\n shadow *= bool( directionalLight.shadow ) ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n }\n #endif\n #if NUM_SPOT_LIGHTS > 0\n SpotLight spotLight;\n for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n spotLight = spotLights[ i ];\n shadow *= bool( spotLight.shadow ) ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowBias, spotLight.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\n }\n #endif\n #if NUM_POINT_LIGHTS > 0\n PointLight pointLight;\n for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n pointLight = pointLights[ i ];\n shadow *= bool( pointLight.shadow ) ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ] ) : 1.0;\n }\n #endif\n #endif\n return shadow;\n}\n";
  14054. // File:src/renderers/shaders/ShaderChunk/skinbase_vertex.glsl
  14055. 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";
  14056. // File:src/renderers/shaders/ShaderChunk/skinning_pars_vertex.glsl
  14057. 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";
  14058. // File:src/renderers/shaders/ShaderChunk/skinning_vertex.glsl
  14059. 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";
  14060. // File:src/renderers/shaders/ShaderChunk/skinnormal_vertex.glsl
  14061. 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";
  14062. // File:src/renderers/shaders/ShaderChunk/specularmap_fragment.glsl
  14063. 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";
  14064. // File:src/renderers/shaders/ShaderChunk/specularmap_pars_fragment.glsl
  14065. THREE.ShaderChunk[ 'specularmap_pars_fragment' ] = "#ifdef USE_SPECULARMAP\n uniform sampler2D specularMap;\n#endif";
  14066. // File:src/renderers/shaders/ShaderChunk/tonemapping_fragment.glsl
  14067. THREE.ShaderChunk[ 'tonemapping_fragment' ] = "#if defined( TONE_MAPPING )\n gl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif\n";
  14068. // File:src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl
  14069. THREE.ShaderChunk[ 'tonemapping_pars_fragment' ] = "#define saturate(a) clamp( a, 0.0, 1.0 )\nuniform float toneMappingExposure;\nuniform float toneMappingWhitePoint;\nvec3 LinearToneMapping( vec3 color ) {\n return toneMappingExposure * color;\n}\nvec3 ReinhardToneMapping( vec3 color ) {\n color *= toneMappingExposure;\n return saturate( color / ( vec3( 1.0 ) + color ) );\n}\n#define Uncharted2Helper( x ) max( ( ( x * ( 0.15 * x + 0.10 * 0.50 ) + 0.20 * 0.02 ) / ( x * ( 0.15 * x + 0.50 ) + 0.20 * 0.30 ) ) - 0.02 / 0.30, vec3( 0.0 ) )\nvec3 Uncharted2ToneMapping( vec3 color ) {\n color *= toneMappingExposure;\n return saturate( Uncharted2Helper( color ) / Uncharted2Helper( vec3( toneMappingWhitePoint ) ) );\n}\nvec3 OptimizedCineonToneMapping( vec3 color ) {\n color *= toneMappingExposure;\n color = max( vec3( 0.0 ), color - 0.004 );\n return pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) );\n}\n";
  14070. // File:src/renderers/shaders/ShaderChunk/uv2_pars_fragment.glsl
  14071. THREE.ShaderChunk[ 'uv2_pars_fragment' ] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n varying vec2 vUv2;\n#endif";
  14072. // File:src/renderers/shaders/ShaderChunk/uv2_pars_vertex.glsl
  14073. THREE.ShaderChunk[ 'uv2_pars_vertex' ] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n attribute vec2 uv2;\n varying vec2 vUv2;\n#endif";
  14074. // File:src/renderers/shaders/ShaderChunk/uv2_vertex.glsl
  14075. THREE.ShaderChunk[ 'uv2_vertex' ] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n vUv2 = uv2;\n#endif";
  14076. // File:src/renderers/shaders/ShaderChunk/uv_pars_fragment.glsl
  14077. THREE.ShaderChunk[ 'uv_pars_fragment' ] = "#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP ) || defined( USE_ROUGHNESSMAP ) || defined( USE_METALNESSMAP )\n varying vec2 vUv;\n#endif";
  14078. // File:src/renderers/shaders/ShaderChunk/uv_pars_vertex.glsl
  14079. THREE.ShaderChunk[ 'uv_pars_vertex' ] = "#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP ) || defined( USE_ROUGHNESSMAP ) || defined( USE_METALNESSMAP )\n varying vec2 vUv;\n uniform vec4 offsetRepeat;\n#endif\n";
  14080. // File:src/renderers/shaders/ShaderChunk/uv_vertex.glsl
  14081. THREE.ShaderChunk[ 'uv_vertex' ] = "#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP ) || defined( USE_ROUGHNESSMAP ) || defined( USE_METALNESSMAP )\n vUv = uv * offsetRepeat.zw + offsetRepeat.xy;\n#endif";
  14082. // File:src/renderers/shaders/ShaderChunk/worldpos_vertex.glsl
  14083. THREE.ShaderChunk[ 'worldpos_vertex' ] = "#if defined( USE_ENVMAP ) || defined( PHONG ) || defined( STANDARD ) || defined( LAMBERT ) || defined ( USE_SHADOWMAP )\n #ifdef USE_SKINNING\n vec4 worldPosition = modelMatrix * skinned;\n #else\n vec4 worldPosition = modelMatrix * vec4( transformed, 1.0 );\n #endif\n#endif\n";
  14084. // File:src/renderers/shaders/UniformsUtils.js
  14085. /**
  14086. * Uniform Utilities
  14087. */
  14088. THREE.UniformsUtils = {
  14089. merge: function ( uniforms ) {
  14090. var merged = {};
  14091. for ( var u = 0; u < uniforms.length; u ++ ) {
  14092. var tmp = this.clone( uniforms[ u ] );
  14093. for ( var p in tmp ) {
  14094. merged[ p ] = tmp[ p ];
  14095. }
  14096. }
  14097. return merged;
  14098. },
  14099. clone: function ( uniforms_src ) {
  14100. var uniforms_dst = {};
  14101. for ( var u in uniforms_src ) {
  14102. uniforms_dst[ u ] = {};
  14103. for ( var p in uniforms_src[ u ] ) {
  14104. var parameter_src = uniforms_src[ u ][ p ];
  14105. if ( parameter_src instanceof THREE.Color ||
  14106. parameter_src instanceof THREE.Vector2 ||
  14107. parameter_src instanceof THREE.Vector3 ||
  14108. parameter_src instanceof THREE.Vector4 ||
  14109. parameter_src instanceof THREE.Matrix3 ||
  14110. parameter_src instanceof THREE.Matrix4 ||
  14111. parameter_src instanceof THREE.Texture ) {
  14112. uniforms_dst[ u ][ p ] = parameter_src.clone();
  14113. } else if ( Array.isArray( parameter_src ) ) {
  14114. uniforms_dst[ u ][ p ] = parameter_src.slice();
  14115. } else {
  14116. uniforms_dst[ u ][ p ] = parameter_src;
  14117. }
  14118. }
  14119. }
  14120. return uniforms_dst;
  14121. }
  14122. };
  14123. // File:src/renderers/shaders/UniformsLib.js
  14124. /**
  14125. * Uniforms library for shared webgl shaders
  14126. */
  14127. THREE.UniformsLib = {
  14128. common: {
  14129. "diffuse": { type: "c", value: new THREE.Color( 0xeeeeee ) },
  14130. "opacity": { type: "f", value: 1.0 },
  14131. "map": { type: "t", value: null },
  14132. "offsetRepeat": { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) },
  14133. "specularMap": { type: "t", value: null },
  14134. "alphaMap": { type: "t", value: null },
  14135. "envMap": { type: "t", value: null },
  14136. "flipEnvMap": { type: "f", value: - 1 },
  14137. "reflectivity": { type: "f", value: 1.0 },
  14138. "refractionRatio": { type: "f", value: 0.98 }
  14139. },
  14140. aomap: {
  14141. "aoMap": { type: "t", value: null },
  14142. "aoMapIntensity": { type: "f", value: 1 }
  14143. },
  14144. lightmap: {
  14145. "lightMap": { type: "t", value: null },
  14146. "lightMapIntensity": { type: "f", value: 1 }
  14147. },
  14148. emissivemap: {
  14149. "emissiveMap": { type: "t", value: null }
  14150. },
  14151. bumpmap: {
  14152. "bumpMap": { type: "t", value: null },
  14153. "bumpScale": { type: "f", value: 1 }
  14154. },
  14155. normalmap: {
  14156. "normalMap": { type: "t", value: null },
  14157. "normalScale": { type: "v2", value: new THREE.Vector2( 1, 1 ) }
  14158. },
  14159. displacementmap: {
  14160. "displacementMap": { type: "t", value: null },
  14161. "displacementScale": { type: "f", value: 1 },
  14162. "displacementBias": { type: "f", value: 0 }
  14163. },
  14164. roughnessmap: {
  14165. "roughnessMap": { type: "t", value: null }
  14166. },
  14167. metalnessmap: {
  14168. "metalnessMap": { type: "t", value: null }
  14169. },
  14170. fog: {
  14171. "fogDensity": { type: "f", value: 0.00025 },
  14172. "fogNear": { type: "f", value: 1 },
  14173. "fogFar": { type: "f", value: 2000 },
  14174. "fogColor": { type: "c", value: new THREE.Color( 0xffffff ) }
  14175. },
  14176. lights: {
  14177. "ambientLightColor": { type: "fv", value: [] },
  14178. "directionalLights": { type: "sa", value: [], properties: {
  14179. "direction": { type: "v3" },
  14180. "color": { type: "c" },
  14181. "shadow": { type: "i" },
  14182. "shadowBias": { type: "f" },
  14183. "shadowRadius": { type: "f" },
  14184. "shadowMapSize": { type: "v2" }
  14185. } },
  14186. "directionalShadowMap": { type: "tv", value: [] },
  14187. "directionalShadowMatrix": { type: "m4v", value: [] },
  14188. "spotLights": { type: "sa", value: [], properties: {
  14189. "color": { type: "c" },
  14190. "position": { type: "v3" },
  14191. "direction": { type: "v3" },
  14192. "distance": { type: "f" },
  14193. "coneCos": { type: "f" },
  14194. "penumbraCos": { type: "f" },
  14195. "decay": { type: "f" },
  14196. "shadow": { type: "i" },
  14197. "shadowBias": { type: "f" },
  14198. "shadowRadius": { type: "f" },
  14199. "shadowMapSize": { type: "v2" }
  14200. } },
  14201. "spotShadowMap": { type: "tv", value: [] },
  14202. "spotShadowMatrix": { type: "m4v", value: [] },
  14203. "pointLights": { type: "sa", value: [], properties: {
  14204. "color": { type: "c" },
  14205. "position": { type: "v3" },
  14206. "decay": { type: "f" },
  14207. "distance": { type: "f" },
  14208. "shadow": { type: "i" },
  14209. "shadowBias": { type: "f" },
  14210. "shadowRadius": { type: "f" },
  14211. "shadowMapSize": { type: "v2" }
  14212. } },
  14213. "pointShadowMap": { type: "tv", value: [] },
  14214. "pointShadowMatrix": { type: "m4v", value: [] },
  14215. "hemisphereLights": { type: "sa", value: [], properties: {
  14216. "direction": { type: "v3" },
  14217. "skyColor": { type: "c" },
  14218. "groundColor": { type: "c" }
  14219. } }
  14220. },
  14221. points: {
  14222. "diffuse": { type: "c", value: new THREE.Color( 0xeeeeee ) },
  14223. "opacity": { type: "f", value: 1.0 },
  14224. "size": { type: "f", value: 1.0 },
  14225. "scale": { type: "f", value: 1.0 },
  14226. "map": { type: "t", value: null },
  14227. "offsetRepeat": { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) }
  14228. }
  14229. };
  14230. // File:src/renderers/shaders/ShaderLib/cube_frag.glsl
  14231. THREE.ShaderChunk[ 'cube_frag' ] = "uniform samplerCube tCube;\nuniform float tFlip;\nvarying vec3 vWorldPosition;\n#include <common>\n#include <logdepthbuf_pars_fragment>\nvoid main() {\n gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );\n #include <logdepthbuf_fragment>\n}\n";
  14232. // File:src/renderers/shaders/ShaderLib/cube_vert.glsl
  14233. THREE.ShaderChunk[ 'cube_vert' ] = "varying vec3 vWorldPosition;\n#include <common>\n#include <logdepthbuf_pars_vertex>\nvoid main() {\n vWorldPosition = transformDirection( position, modelMatrix );\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n #include <logdepthbuf_vertex>\n}\n";
  14234. // File:src/renderers/shaders/ShaderLib/depth_frag.glsl
  14235. THREE.ShaderChunk[ 'depth_frag' ] = "uniform float mNear;\nuniform float mFar;\nuniform float opacity;\n#include <common>\n#include <logdepthbuf_pars_fragment>\nvoid main() {\n #include <logdepthbuf_fragment>\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 float color = 1.0 - smoothstep( mNear, mFar, depth );\n gl_FragColor = vec4( vec3( color ), opacity );\n}\n";
  14236. // File:src/renderers/shaders/ShaderLib/depth_vert.glsl
  14237. THREE.ShaderChunk[ 'depth_vert' ] = "#include <common>\n#include <morphtarget_pars_vertex>\n#include <logdepthbuf_pars_vertex>\nvoid main() {\n #include <begin_vertex>\n #include <morphtarget_vertex>\n #include <project_vertex>\n #include <logdepthbuf_vertex>\n}\n";
  14238. // File:src/renderers/shaders/ShaderLib/depthRGBA_frag.glsl
  14239. THREE.ShaderChunk[ 'depthRGBA_frag' ] = "#include <common>\n#include <logdepthbuf_pars_fragment>\nvec4 pack_depth( const in float depth ) {\n const vec4 bit_shift = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );\n const vec4 bit_mask = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );\n vec4 res = mod( depth * bit_shift * vec4( 255 ), vec4( 256 ) ) / vec4( 255 );\n res -= res.xxyz * bit_mask;\n return res;\n}\nvoid main() {\n #include <logdepthbuf_fragment>\n #ifdef USE_LOGDEPTHBUF_EXT\n gl_FragData[ 0 ] = pack_depth( gl_FragDepthEXT );\n #else\n gl_FragData[ 0 ] = pack_depth( gl_FragCoord.z );\n #endif\n}\n";
  14240. // File:src/renderers/shaders/ShaderLib/depthRGBA_vert.glsl
  14241. THREE.ShaderChunk[ 'depthRGBA_vert' ] = "#include <common>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\nvoid main() {\n #include <skinbase_vertex>\n #include <begin_vertex>\n #include <morphtarget_vertex>\n #include <skinning_vertex>\n #include <project_vertex>\n #include <logdepthbuf_vertex>\n}\n";
  14242. // File:src/renderers/shaders/ShaderLib/distanceRGBA_frag.glsl
  14243. THREE.ShaderChunk[ 'distanceRGBA_frag' ] = "uniform vec3 lightPos;\nvarying vec4 vWorldPosition;\n#include <common>\nvec4 pack1K ( float depth ) {\n depth /= 1000.0;\n const vec4 bitSh = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );\n const vec4 bitMsk = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );\n vec4 res = mod( depth * bitSh * vec4( 255 ), vec4( 256 ) ) / vec4( 255 );\n res -= res.xxyz * bitMsk;\n return res;\n}\nfloat unpack1K ( vec4 color ) {\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 return dot( color, bitSh ) * 1000.0;\n}\nvoid main () {\n gl_FragColor = pack1K( length( vWorldPosition.xyz - lightPos.xyz ) );\n}\n";
  14244. // File:src/renderers/shaders/ShaderLib/distanceRGBA_vert.glsl
  14245. THREE.ShaderChunk[ 'distanceRGBA_vert' ] = "varying vec4 vWorldPosition;\n#include <common>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\nvoid main() {\n #include <skinbase_vertex>\n #include <begin_vertex>\n #include <morphtarget_vertex>\n #include <skinning_vertex>\n #include <project_vertex>\n #include <worldpos_vertex>\n vWorldPosition = worldPosition;\n}\n";
  14246. // File:src/renderers/shaders/ShaderLib/equirect_frag.glsl
  14247. THREE.ShaderChunk[ 'equirect_frag' ] = "uniform sampler2D tEquirect;\nuniform float tFlip;\nvarying vec3 vWorldPosition;\n#include <common>\n#include <logdepthbuf_pars_fragment>\nvoid main() {\n vec3 direction = normalize( vWorldPosition );\n vec2 sampleUV;\n sampleUV.y = saturate( tFlip * direction.y * -0.5 + 0.5 );\n sampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;\n gl_FragColor = texture2D( tEquirect, sampleUV );\n #include <logdepthbuf_fragment>\n}\n";
  14248. // File:src/renderers/shaders/ShaderLib/equirect_vert.glsl
  14249. THREE.ShaderChunk[ 'equirect_vert' ] = "varying vec3 vWorldPosition;\n#include <common>\n#include <logdepthbuf_pars_vertex>\nvoid main() {\n vWorldPosition = transformDirection( position, modelMatrix );\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n #include <logdepthbuf_vertex>\n}\n";
  14250. // File:src/renderers/shaders/ShaderLib/linedashed_frag.glsl
  14251. THREE.ShaderChunk[ 'linedashed_frag' ] = "uniform vec3 diffuse;\nuniform float opacity;\nuniform float dashSize;\nuniform float totalSize;\nvarying float vLineDistance;\n#include <common>\n#include <color_pars_fragment>\n#include <fog_pars_fragment>\n#include <logdepthbuf_pars_fragment>\nvoid main() {\n if ( mod( vLineDistance, totalSize ) > dashSize ) {\n discard;\n }\n vec3 outgoingLight = vec3( 0.0 );\n vec4 diffuseColor = vec4( diffuse, opacity );\n #include <logdepthbuf_fragment>\n #include <color_fragment>\n outgoingLight = diffuseColor.rgb;\n gl_FragColor = vec4( outgoingLight, diffuseColor.a );\n #include <premultiplied_alpha_fragment>\n #include <tonemapping_fragment>\n #include <encodings_fragment>\n #include <fog_fragment>\n}\n";
  14252. // File:src/renderers/shaders/ShaderLib/linedashed_vert.glsl
  14253. THREE.ShaderChunk[ 'linedashed_vert' ] = "uniform float scale;\nattribute float lineDistance;\nvarying float vLineDistance;\n#include <common>\n#include <color_pars_vertex>\n#include <logdepthbuf_pars_vertex>\nvoid main() {\n #include <color_vertex>\n vLineDistance = scale * lineDistance;\n vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\n gl_Position = projectionMatrix * mvPosition;\n #include <logdepthbuf_vertex>\n}\n";
  14254. // File:src/renderers/shaders/ShaderLib/meshbasic_frag.glsl
  14255. THREE.ShaderChunk[ 'meshbasic_frag' ] = "uniform vec3 diffuse;\nuniform float opacity;\n#ifndef FLAT_SHADED\n varying vec3 vNormal;\n#endif\n#include <common>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <envmap_pars_fragment>\n#include <fog_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\nvoid main() {\n vec4 diffuseColor = vec4( diffuse, opacity );\n #include <logdepthbuf_fragment>\n #include <map_fragment>\n #include <color_fragment>\n #include <alphamap_fragment>\n #include <alphatest_fragment>\n #include <specularmap_fragment>\n ReflectedLight reflectedLight;\n reflectedLight.directDiffuse = vec3( 0.0 );\n reflectedLight.directSpecular = vec3( 0.0 );\n reflectedLight.indirectDiffuse = diffuseColor.rgb;\n reflectedLight.indirectSpecular = vec3( 0.0 );\n #include <aomap_fragment>\n vec3 outgoingLight = reflectedLight.indirectDiffuse;\n #include <envmap_fragment>\n gl_FragColor = vec4( outgoingLight, diffuseColor.a );\n #include <premultiplied_alpha_fragment>\n #include <tonemapping_fragment>\n #include <encodings_fragment>\n #include <fog_fragment>\n}\n";
  14256. // File:src/renderers/shaders/ShaderLib/meshbasic_vert.glsl
  14257. THREE.ShaderChunk[ 'meshbasic_vert' ] = "#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <envmap_pars_vertex>\n#include <color_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\nvoid main() {\n #include <uv_vertex>\n #include <uv2_vertex>\n #include <color_vertex>\n #include <skinbase_vertex>\n #ifdef USE_ENVMAP\n #include <beginnormal_vertex>\n #include <morphnormal_vertex>\n #include <skinnormal_vertex>\n #include <defaultnormal_vertex>\n #endif\n #include <begin_vertex>\n #include <morphtarget_vertex>\n #include <skinning_vertex>\n #include <project_vertex>\n #include <logdepthbuf_vertex>\n #include <worldpos_vertex>\n #include <envmap_vertex>\n}\n";
  14258. // File:src/renderers/shaders/ShaderLib/meshlambert_frag.glsl
  14259. THREE.ShaderChunk[ 'meshlambert_frag' ] = "uniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\nvarying vec3 vLightFront;\n#ifdef DOUBLE_SIDED\n varying vec3 vLightBack;\n#endif\n#include <common>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <envmap_pars_fragment>\n#include <bsdfs>\n#include <lights_pars>\n#include <fog_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <shadowmask_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\nvoid main() {\n vec4 diffuseColor = vec4( diffuse, opacity );\n ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n vec3 totalEmissiveRadiance = emissive;\n #include <logdepthbuf_fragment>\n #include <map_fragment>\n #include <color_fragment>\n #include <alphamap_fragment>\n #include <alphatest_fragment>\n #include <specularmap_fragment>\n #include <emissivemap_fragment>\n reflectedLight.indirectDiffuse = getAmbientLightIrradiance( ambientLightColor );\n #include <lightmap_fragment>\n reflectedLight.indirectDiffuse *= BRDF_Diffuse_Lambert( diffuseColor.rgb );\n #ifdef DOUBLE_SIDED\n reflectedLight.directDiffuse = ( gl_FrontFacing ) ? vLightFront : vLightBack;\n #else\n reflectedLight.directDiffuse = vLightFront;\n #endif\n reflectedLight.directDiffuse *= BRDF_Diffuse_Lambert( diffuseColor.rgb ) * getShadowMask();\n #include <aomap_fragment>\n vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n #include <envmap_fragment>\n gl_FragColor = vec4( outgoingLight, diffuseColor.a );\n #include <premultiplied_alpha_fragment>\n #include <tonemapping_fragment>\n #include <encodings_fragment>\n #include <fog_fragment>\n}\n";
  14260. // File:src/renderers/shaders/ShaderLib/meshlambert_vert.glsl
  14261. THREE.ShaderChunk[ 'meshlambert_vert' ] = "#define LAMBERT\nvarying vec3 vLightFront;\n#ifdef DOUBLE_SIDED\n varying vec3 vLightBack;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <envmap_pars_vertex>\n#include <bsdfs>\n#include <lights_pars>\n#include <color_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\nvoid main() {\n #include <uv_vertex>\n #include <uv2_vertex>\n #include <color_vertex>\n #include <beginnormal_vertex>\n #include <morphnormal_vertex>\n #include <skinbase_vertex>\n #include <skinnormal_vertex>\n #include <defaultnormal_vertex>\n #include <begin_vertex>\n #include <morphtarget_vertex>\n #include <skinning_vertex>\n #include <project_vertex>\n #include <logdepthbuf_vertex>\n #include <worldpos_vertex>\n #include <envmap_vertex>\n #include <lights_lambert_vertex>\n #include <shadowmap_vertex>\n}\n";
  14262. // File:src/renderers/shaders/ShaderLib/meshphong_frag.glsl
  14263. THREE.ShaderChunk[ 'meshphong_frag' ] = "#define PHONG\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform vec3 specular;\nuniform float shininess;\nuniform float opacity;\n#include <common>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <envmap_pars_fragment>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars>\n#include <lights_phong_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\nvoid main() {\n vec4 diffuseColor = vec4( diffuse, opacity );\n ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n vec3 totalEmissiveRadiance = emissive;\n #include <logdepthbuf_fragment>\n #include <map_fragment>\n #include <color_fragment>\n #include <alphamap_fragment>\n #include <alphatest_fragment>\n #include <specularmap_fragment>\n #include <normal_fragment>\n #include <emissivemap_fragment>\n #include <lights_phong_fragment>\n #include <lights_template>\n #include <aomap_fragment>\n vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\n #include <envmap_fragment>\n gl_FragColor = vec4( outgoingLight, diffuseColor.a );\n #include <premultiplied_alpha_fragment>\n #include <tonemapping_fragment>\n #include <encodings_fragment>\n #include <fog_fragment>\n}\n";
  14264. // File:src/renderers/shaders/ShaderLib/meshphong_vert.glsl
  14265. THREE.ShaderChunk[ 'meshphong_vert' ] = "#define PHONG\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n varying vec3 vNormal;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <envmap_pars_vertex>\n#include <lights_phong_pars_vertex>\n#include <color_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\nvoid main() {\n #include <uv_vertex>\n #include <uv2_vertex>\n #include <color_vertex>\n #include <beginnormal_vertex>\n #include <morphnormal_vertex>\n #include <skinbase_vertex>\n #include <skinnormal_vertex>\n #include <defaultnormal_vertex>\n#ifndef FLAT_SHADED\n vNormal = normalize( transformedNormal );\n#endif\n #include <begin_vertex>\n #include <displacementmap_vertex>\n #include <morphtarget_vertex>\n #include <skinning_vertex>\n #include <project_vertex>\n #include <logdepthbuf_vertex>\n vViewPosition = - mvPosition.xyz;\n #include <worldpos_vertex>\n #include <envmap_vertex>\n #include <lights_phong_vertex>\n #include <shadowmap_vertex>\n}\n";
  14266. // File:src/renderers/shaders/ShaderLib/meshstandard_frag.glsl
  14267. THREE.ShaderChunk[ 'meshstandard_frag' ] = "#define STANDARD\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float roughness;\nuniform float metalness;\nuniform float opacity;\nuniform float envMapIntensity;\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n varying vec3 vNormal;\n#endif\n#include <common>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <envmap_pars_fragment>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <cube_uv_reflection_fragment>\n#include <lights_pars>\n#include <lights_standard_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <roughnessmap_pars_fragment>\n#include <metalnessmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\nvoid main() {\n vec4 diffuseColor = vec4( diffuse, opacity );\n ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n vec3 totalEmissiveRadiance = emissive;\n #include <logdepthbuf_fragment>\n #include <map_fragment>\n #include <color_fragment>\n #include <alphamap_fragment>\n #include <alphatest_fragment>\n #include <specularmap_fragment>\n #include <roughnessmap_fragment>\n #include <metalnessmap_fragment>\n #include <normal_fragment>\n #include <emissivemap_fragment>\n #include <lights_standard_fragment>\n #include <lights_template>\n #include <aomap_fragment>\n vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\n gl_FragColor = vec4( outgoingLight, diffuseColor.a );\n #include <premultiplied_alpha_fragment>\n #include <tonemapping_fragment>\n #include <encodings_fragment>\n #include <fog_fragment>\n}\n";
  14268. // File:src/renderers/shaders/ShaderLib/meshstandard_vert.glsl
  14269. THREE.ShaderChunk[ 'meshstandard_vert' ] = "#define STANDARD\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n varying vec3 vNormal;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <envmap_pars_vertex>\n#include <color_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_vertex>\nvoid main() {\n #include <uv_vertex>\n #include <uv2_vertex>\n #include <color_vertex>\n #include <beginnormal_vertex>\n #include <morphnormal_vertex>\n #include <skinbase_vertex>\n #include <skinnormal_vertex>\n #include <defaultnormal_vertex>\n#ifndef FLAT_SHADED\n vNormal = normalize( transformedNormal );\n#endif\n #include <begin_vertex>\n #include <displacementmap_vertex>\n #include <morphtarget_vertex>\n #include <skinning_vertex>\n #include <project_vertex>\n #include <logdepthbuf_vertex>\n vViewPosition = - mvPosition.xyz;\n #include <worldpos_vertex>\n #include <envmap_vertex>\n #include <shadowmap_vertex>\n}\n";
  14270. // File:src/renderers/shaders/ShaderLib/normal_frag.glsl
  14271. THREE.ShaderChunk[ 'normal_frag' ] = "uniform float opacity;\nvarying vec3 vNormal;\n#include <common>\n#include <logdepthbuf_pars_fragment>\nvoid main() {\n gl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, opacity );\n #include <logdepthbuf_fragment>\n}\n";
  14272. // File:src/renderers/shaders/ShaderLib/normal_vert.glsl
  14273. THREE.ShaderChunk[ 'normal_vert' ] = "varying vec3 vNormal;\n#include <common>\n#include <morphtarget_pars_vertex>\n#include <logdepthbuf_pars_vertex>\nvoid main() {\n vNormal = normalize( normalMatrix * normal );\n #include <begin_vertex>\n #include <morphtarget_vertex>\n #include <project_vertex>\n #include <logdepthbuf_vertex>\n}\n";
  14274. // File:src/renderers/shaders/ShaderLib/points_frag.glsl
  14275. THREE.ShaderChunk[ 'points_frag' ] = "uniform vec3 diffuse;\nuniform float opacity;\n#include <common>\n#include <color_pars_fragment>\n#include <map_particle_pars_fragment>\n#include <fog_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\nvoid main() {\n vec3 outgoingLight = vec3( 0.0 );\n vec4 diffuseColor = vec4( diffuse, opacity );\n #include <logdepthbuf_fragment>\n #include <map_particle_fragment>\n #include <color_fragment>\n #include <alphatest_fragment>\n outgoingLight = diffuseColor.rgb;\n gl_FragColor = vec4( outgoingLight, diffuseColor.a );\n #include <premultiplied_alpha_fragment>\n #include <tonemapping_fragment>\n #include <encodings_fragment>\n #include <fog_fragment>\n}\n";
  14276. // File:src/renderers/shaders/ShaderLib/points_vert.glsl
  14277. THREE.ShaderChunk[ 'points_vert' ] = "uniform float size;\nuniform float scale;\n#include <common>\n#include <color_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\nvoid main() {\n #include <color_vertex>\n #include <begin_vertex>\n #include <project_vertex>\n #ifdef USE_SIZEATTENUATION\n gl_PointSize = size * ( scale / - mvPosition.z );\n #else\n gl_PointSize = size;\n #endif\n #include <logdepthbuf_vertex>\n #include <worldpos_vertex>\n #include <shadowmap_vertex>\n}\n";
  14278. // File:src/renderers/shaders/ShaderLib.js
  14279. /**
  14280. * Webgl Shader Library for three.js
  14281. *
  14282. * @author alteredq / http://alteredqualia.com/
  14283. * @author mrdoob / http://mrdoob.com/
  14284. * @author mikael emtinger / http://gomo.se/
  14285. */
  14286. THREE.ShaderLib = {
  14287. 'basic': {
  14288. uniforms: THREE.UniformsUtils.merge( [
  14289. THREE.UniformsLib[ "common" ],
  14290. THREE.UniformsLib[ "aomap" ],
  14291. THREE.UniformsLib[ "fog" ]
  14292. ] ),
  14293. vertexShader: THREE.ShaderChunk['meshbasic_vert'],
  14294. fragmentShader: THREE.ShaderChunk['meshbasic_frag']
  14295. },
  14296. 'lambert': {
  14297. uniforms: THREE.UniformsUtils.merge( [
  14298. THREE.UniformsLib[ "common" ],
  14299. THREE.UniformsLib[ "aomap" ],
  14300. THREE.UniformsLib[ "lightmap" ],
  14301. THREE.UniformsLib[ "emissivemap" ],
  14302. THREE.UniformsLib[ "fog" ],
  14303. THREE.UniformsLib[ "lights" ],
  14304. {
  14305. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) }
  14306. }
  14307. ] ),
  14308. vertexShader: THREE.ShaderChunk['meshlambert_vert'],
  14309. fragmentShader: THREE.ShaderChunk['meshlambert_frag']
  14310. },
  14311. 'phong': {
  14312. uniforms: THREE.UniformsUtils.merge( [
  14313. THREE.UniformsLib[ "common" ],
  14314. THREE.UniformsLib[ "aomap" ],
  14315. THREE.UniformsLib[ "lightmap" ],
  14316. THREE.UniformsLib[ "emissivemap" ],
  14317. THREE.UniformsLib[ "bumpmap" ],
  14318. THREE.UniformsLib[ "normalmap" ],
  14319. THREE.UniformsLib[ "displacementmap" ],
  14320. THREE.UniformsLib[ "fog" ],
  14321. THREE.UniformsLib[ "lights" ],
  14322. {
  14323. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) },
  14324. "specular" : { type: "c", value: new THREE.Color( 0x111111 ) },
  14325. "shininess": { type: "f", value: 30 }
  14326. }
  14327. ] ),
  14328. vertexShader: THREE.ShaderChunk['meshphong_vert'],
  14329. fragmentShader: THREE.ShaderChunk['meshphong_frag']
  14330. },
  14331. 'standard': {
  14332. uniforms: THREE.UniformsUtils.merge( [
  14333. THREE.UniformsLib[ "common" ],
  14334. THREE.UniformsLib[ "aomap" ],
  14335. THREE.UniformsLib[ "lightmap" ],
  14336. THREE.UniformsLib[ "emissivemap" ],
  14337. THREE.UniformsLib[ "bumpmap" ],
  14338. THREE.UniformsLib[ "normalmap" ],
  14339. THREE.UniformsLib[ "displacementmap" ],
  14340. THREE.UniformsLib[ "roughnessmap" ],
  14341. THREE.UniformsLib[ "metalnessmap" ],
  14342. THREE.UniformsLib[ "fog" ],
  14343. THREE.UniformsLib[ "lights" ],
  14344. {
  14345. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) },
  14346. "roughness": { type: "f", value: 0.5 },
  14347. "metalness": { type: "f", value: 0 },
  14348. "envMapIntensity" : { type: "f", value: 1 } // temporary
  14349. }
  14350. ] ),
  14351. vertexShader: THREE.ShaderChunk['meshstandard_vert'],
  14352. fragmentShader: THREE.ShaderChunk['meshstandard_frag']
  14353. },
  14354. 'points': {
  14355. uniforms: THREE.UniformsUtils.merge( [
  14356. THREE.UniformsLib[ "points" ],
  14357. THREE.UniformsLib[ "fog" ]
  14358. ] ),
  14359. vertexShader: THREE.ShaderChunk['points_vert'],
  14360. fragmentShader: THREE.ShaderChunk['points_frag']
  14361. },
  14362. 'dashed': {
  14363. uniforms: THREE.UniformsUtils.merge( [
  14364. THREE.UniformsLib[ "common" ],
  14365. THREE.UniformsLib[ "fog" ],
  14366. {
  14367. "scale" : { type: "f", value: 1 },
  14368. "dashSize" : { type: "f", value: 1 },
  14369. "totalSize": { type: "f", value: 2 }
  14370. }
  14371. ] ),
  14372. vertexShader: THREE.ShaderChunk['linedashed_vert'],
  14373. fragmentShader: THREE.ShaderChunk['linedashed_frag']
  14374. },
  14375. 'depth': {
  14376. uniforms: {
  14377. "mNear": { type: "f", value: 1.0 },
  14378. "mFar" : { type: "f", value: 2000.0 },
  14379. "opacity" : { type: "f", value: 1.0 }
  14380. },
  14381. vertexShader: THREE.ShaderChunk['depth_vert'],
  14382. fragmentShader: THREE.ShaderChunk['depth_frag']
  14383. },
  14384. 'normal': {
  14385. uniforms: {
  14386. "opacity" : { type: "f", value: 1.0 }
  14387. },
  14388. vertexShader: THREE.ShaderChunk['normal_vert'],
  14389. fragmentShader: THREE.ShaderChunk['normal_frag']
  14390. },
  14391. /* -------------------------------------------------------------------------
  14392. // Cube map shader
  14393. ------------------------------------------------------------------------- */
  14394. 'cube': {
  14395. uniforms: {
  14396. "tCube": { type: "t", value: null },
  14397. "tFlip": { type: "f", value: - 1 }
  14398. },
  14399. vertexShader: THREE.ShaderChunk['cube_vert'],
  14400. fragmentShader: THREE.ShaderChunk['cube_frag']
  14401. },
  14402. /* -------------------------------------------------------------------------
  14403. // Cube map shader
  14404. ------------------------------------------------------------------------- */
  14405. 'equirect': {
  14406. uniforms: {
  14407. "tEquirect": { type: "t", value: null },
  14408. "tFlip": { type: "f", value: - 1 }
  14409. },
  14410. vertexShader: THREE.ShaderChunk['equirect_vert'],
  14411. fragmentShader: THREE.ShaderChunk['equirect_frag']
  14412. },
  14413. /* Depth encoding into RGBA texture
  14414. *
  14415. * based on SpiderGL shadow map example
  14416. * http://spidergl.org/example.php?id=6
  14417. *
  14418. * originally from
  14419. * http://www.gamedev.net/topic/442138-packing-a-float-into-a-a8r8g8b8-texture-shader/page__whichpage__1%25EF%25BF%25BD
  14420. *
  14421. * see also
  14422. * http://aras-p.info/blog/2009/07/30/encoding-floats-to-rgba-the-final/
  14423. */
  14424. 'depthRGBA': {
  14425. uniforms: {},
  14426. vertexShader: THREE.ShaderChunk['depthRGBA_vert'],
  14427. fragmentShader: THREE.ShaderChunk['depthRGBA_frag']
  14428. },
  14429. 'distanceRGBA': {
  14430. uniforms: {
  14431. "lightPos": { type: "v3", value: new THREE.Vector3( 0, 0, 0 ) }
  14432. },
  14433. vertexShader: THREE.ShaderChunk['distanceRGBA_vert'],
  14434. fragmentShader: THREE.ShaderChunk['distanceRGBA_frag']
  14435. }
  14436. };
  14437. // File:src/renderers/WebGLRenderer.js
  14438. /**
  14439. * @author supereggbert / http://www.paulbrunt.co.uk/
  14440. * @author mrdoob / http://mrdoob.com/
  14441. * @author alteredq / http://alteredqualia.com/
  14442. * @author szimek / https://github.com/szimek/
  14443. */
  14444. THREE.WebGLRenderer = function ( parameters ) {
  14445. console.log( 'THREE.WebGLRenderer', THREE.REVISION );
  14446. parameters = parameters || {};
  14447. var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElement( 'canvas' ),
  14448. _context = parameters.context !== undefined ? parameters.context : null,
  14449. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  14450. _depth = parameters.depth !== undefined ? parameters.depth : true,
  14451. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  14452. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  14453. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  14454. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false;
  14455. var lights = [];
  14456. var opaqueObjects = [];
  14457. var opaqueObjectsLastIndex = - 1;
  14458. var transparentObjects = [];
  14459. var transparentObjectsLastIndex = - 1;
  14460. var morphInfluences = new Float32Array( 8 );
  14461. var sprites = [];
  14462. var lensFlares = [];
  14463. // public properties
  14464. this.domElement = _canvas;
  14465. this.context = null;
  14466. // clearing
  14467. this.autoClear = true;
  14468. this.autoClearColor = true;
  14469. this.autoClearDepth = true;
  14470. this.autoClearStencil = true;
  14471. // scene graph
  14472. this.sortObjects = true;
  14473. // physically based shading
  14474. this.gammaFactor = 2.0; // for backwards compatibility
  14475. this.gammaInput = false;
  14476. this.gammaOutput = false;
  14477. // physical lights
  14478. this.physicallyCorrectLights = false;
  14479. // tone mapping
  14480. this.toneMapping = THREE.LinearToneMapping;
  14481. this.toneMappingExposure = 1.0;
  14482. this.toneMappingWhitePoint = 1.0;
  14483. // morphs
  14484. this.maxMorphTargets = 8;
  14485. this.maxMorphNormals = 4;
  14486. // flags
  14487. this.autoScaleCubemaps = true;
  14488. // internal properties
  14489. var _this = this,
  14490. // internal state cache
  14491. _currentProgram = null,
  14492. _currentRenderTarget = null,
  14493. _currentFramebuffer = null,
  14494. _currentMaterialId = - 1,
  14495. _currentGeometryProgram = '',
  14496. _currentCamera = null,
  14497. _currentScissor = new THREE.Vector4(),
  14498. _currentScissorTest = null,
  14499. _currentViewport = new THREE.Vector4(),
  14500. //
  14501. _usedTextureUnits = 0,
  14502. //
  14503. _clearColor = new THREE.Color( 0x000000 ),
  14504. _clearAlpha = 0,
  14505. _width = _canvas.width,
  14506. _height = _canvas.height,
  14507. _pixelRatio = 1,
  14508. _scissor = new THREE.Vector4( 0, 0, _width, _height ),
  14509. _scissorTest = false,
  14510. _viewport = new THREE.Vector4( 0, 0, _width, _height ),
  14511. // frustum
  14512. _frustum = new THREE.Frustum(),
  14513. // camera matrices cache
  14514. _projScreenMatrix = new THREE.Matrix4(),
  14515. _vector3 = new THREE.Vector3(),
  14516. // light arrays cache
  14517. _lights = {
  14518. hash: '',
  14519. ambient: [ 0, 0, 0 ],
  14520. directional: [],
  14521. directionalShadowMap: [],
  14522. directionalShadowMatrix: [],
  14523. spot: [],
  14524. spotShadowMap: [],
  14525. spotShadowMatrix: [],
  14526. point: [],
  14527. pointShadowMap: [],
  14528. pointShadowMatrix: [],
  14529. hemi: [],
  14530. shadows: [],
  14531. shadowsPointLight: 0
  14532. },
  14533. // info
  14534. _infoMemory = {
  14535. geometries: 0,
  14536. textures: 0
  14537. },
  14538. _infoRender = {
  14539. calls: 0,
  14540. vertices: 0,
  14541. faces: 0,
  14542. points: 0
  14543. };
  14544. this.info = {
  14545. render: _infoRender,
  14546. memory: _infoMemory,
  14547. programs: null
  14548. };
  14549. // initialize
  14550. var _gl;
  14551. try {
  14552. var attributes = {
  14553. alpha: _alpha,
  14554. depth: _depth,
  14555. stencil: _stencil,
  14556. antialias: _antialias,
  14557. premultipliedAlpha: _premultipliedAlpha,
  14558. preserveDrawingBuffer: _preserveDrawingBuffer
  14559. };
  14560. _gl = _context || _canvas.getContext( 'webgl', attributes ) || _canvas.getContext( 'experimental-webgl', attributes );
  14561. if ( _gl === null ) {
  14562. if ( _canvas.getContext( 'webgl' ) !== null ) {
  14563. throw 'Error creating WebGL context with your selected attributes.';
  14564. } else {
  14565. throw 'Error creating WebGL context.';
  14566. }
  14567. }
  14568. // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  14569. if ( _gl.getShaderPrecisionFormat === undefined ) {
  14570. _gl.getShaderPrecisionFormat = function () {
  14571. return { 'rangeMin': 1, 'rangeMax': 1, 'precision': 1 };
  14572. };
  14573. }
  14574. _canvas.addEventListener( 'webglcontextlost', onContextLost, false );
  14575. } catch ( error ) {
  14576. console.error( 'THREE.WebGLRenderer: ' + error );
  14577. }
  14578. var extensions = new THREE.WebGLExtensions( _gl );
  14579. extensions.get( 'OES_texture_float' );
  14580. extensions.get( 'OES_texture_float_linear' );
  14581. extensions.get( 'OES_texture_half_float' );
  14582. extensions.get( 'OES_texture_half_float_linear' );
  14583. extensions.get( 'OES_standard_derivatives' );
  14584. extensions.get( 'ANGLE_instanced_arrays' );
  14585. if ( extensions.get( 'OES_element_index_uint' ) ) {
  14586. THREE.BufferGeometry.MaxIndex = 4294967296;
  14587. }
  14588. var capabilities = new THREE.WebGLCapabilities( _gl, extensions, parameters );
  14589. var state = new THREE.WebGLState( _gl, extensions, paramThreeToGL );
  14590. var properties = new THREE.WebGLProperties();
  14591. var objects = new THREE.WebGLObjects( _gl, properties, this.info );
  14592. var programCache = new THREE.WebGLPrograms( this, capabilities );
  14593. var lightCache = new THREE.WebGLLights();
  14594. this.info.programs = programCache.programs;
  14595. var bufferRenderer = new THREE.WebGLBufferRenderer( _gl, extensions, _infoRender );
  14596. var indexedBufferRenderer = new THREE.WebGLIndexedBufferRenderer( _gl, extensions, _infoRender );
  14597. //
  14598. function getTargetPixelRatio() {
  14599. return _currentRenderTarget === null ? _pixelRatio : 1;
  14600. }
  14601. function glClearColor( r, g, b, a ) {
  14602. if ( _premultipliedAlpha === true ) {
  14603. r *= a; g *= a; b *= a;
  14604. }
  14605. state.clearColor( r, g, b, a );
  14606. }
  14607. function setDefaultGLState() {
  14608. state.init();
  14609. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ) );
  14610. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ) );
  14611. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  14612. }
  14613. function resetGLState() {
  14614. _currentProgram = null;
  14615. _currentCamera = null;
  14616. _currentGeometryProgram = '';
  14617. _currentMaterialId = - 1;
  14618. state.reset();
  14619. }
  14620. setDefaultGLState();
  14621. this.context = _gl;
  14622. this.capabilities = capabilities;
  14623. this.extensions = extensions;
  14624. this.properties = properties;
  14625. this.state = state;
  14626. // shadow map
  14627. var shadowMap = new THREE.WebGLShadowMap( this, _lights, objects );
  14628. this.shadowMap = shadowMap;
  14629. // Plugins
  14630. var spritePlugin = new THREE.SpritePlugin( this, sprites );
  14631. var lensFlarePlugin = new THREE.LensFlarePlugin( this, lensFlares );
  14632. // API
  14633. this.getContext = function () {
  14634. return _gl;
  14635. };
  14636. this.getContextAttributes = function () {
  14637. return _gl.getContextAttributes();
  14638. };
  14639. this.forceContextLoss = function () {
  14640. extensions.get( 'WEBGL_lose_context' ).loseContext();
  14641. };
  14642. this.getMaxAnisotropy = ( function () {
  14643. var value;
  14644. return function getMaxAnisotropy() {
  14645. if ( value !== undefined ) return value;
  14646. var extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  14647. if ( extension !== null ) {
  14648. value = _gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );
  14649. } else {
  14650. value = 0;
  14651. }
  14652. return value;
  14653. };
  14654. } )();
  14655. this.getPrecision = function () {
  14656. return capabilities.precision;
  14657. };
  14658. this.getPixelRatio = function () {
  14659. return _pixelRatio;
  14660. };
  14661. this.setPixelRatio = function ( value ) {
  14662. if ( value === undefined ) return;
  14663. _pixelRatio = value;
  14664. this.setSize( _viewport.z, _viewport.w, false );
  14665. };
  14666. this.getSize = function () {
  14667. return {
  14668. width: _width,
  14669. height: _height
  14670. };
  14671. };
  14672. this.setSize = function ( width, height, updateStyle ) {
  14673. _width = width;
  14674. _height = height;
  14675. _canvas.width = width * _pixelRatio;
  14676. _canvas.height = height * _pixelRatio;
  14677. if ( updateStyle !== false ) {
  14678. _canvas.style.width = width + 'px';
  14679. _canvas.style.height = height + 'px';
  14680. }
  14681. this.setViewport( 0, 0, width, height );
  14682. };
  14683. this.setViewport = function ( x, y, width, height ) {
  14684. state.viewport( _viewport.set( x, y, width, height ) );
  14685. };
  14686. this.setScissor = function ( x, y, width, height ) {
  14687. state.scissor( _scissor.set( x, y, width, height ) );
  14688. };
  14689. this.setScissorTest = function ( boolean ) {
  14690. state.setScissorTest( _scissorTest = boolean );
  14691. };
  14692. // Clearing
  14693. this.getClearColor = function () {
  14694. return _clearColor;
  14695. };
  14696. this.setClearColor = function ( color, alpha ) {
  14697. _clearColor.set( color );
  14698. _clearAlpha = alpha !== undefined ? alpha : 1;
  14699. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  14700. };
  14701. this.getClearAlpha = function () {
  14702. return _clearAlpha;
  14703. };
  14704. this.setClearAlpha = function ( alpha ) {
  14705. _clearAlpha = alpha;
  14706. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  14707. };
  14708. this.clear = function ( color, depth, stencil ) {
  14709. var bits = 0;
  14710. if ( color === undefined || color ) bits |= _gl.COLOR_BUFFER_BIT;
  14711. if ( depth === undefined || depth ) bits |= _gl.DEPTH_BUFFER_BIT;
  14712. if ( stencil === undefined || stencil ) bits |= _gl.STENCIL_BUFFER_BIT;
  14713. _gl.clear( bits );
  14714. };
  14715. this.clearColor = function () {
  14716. this.clear( true, false, false );
  14717. };
  14718. this.clearDepth = function () {
  14719. this.clear( false, true, false );
  14720. };
  14721. this.clearStencil = function () {
  14722. this.clear( false, false, true );
  14723. };
  14724. this.clearTarget = function ( renderTarget, color, depth, stencil ) {
  14725. this.setRenderTarget( renderTarget );
  14726. this.clear( color, depth, stencil );
  14727. };
  14728. // Reset
  14729. this.resetGLState = resetGLState;
  14730. this.dispose = function() {
  14731. _canvas.removeEventListener( 'webglcontextlost', onContextLost, false );
  14732. };
  14733. // Events
  14734. function onContextLost( event ) {
  14735. event.preventDefault();
  14736. resetGLState();
  14737. setDefaultGLState();
  14738. properties.clear();
  14739. }
  14740. function onTextureDispose( event ) {
  14741. var texture = event.target;
  14742. texture.removeEventListener( 'dispose', onTextureDispose );
  14743. deallocateTexture( texture );
  14744. _infoMemory.textures --;
  14745. }
  14746. function onRenderTargetDispose( event ) {
  14747. var renderTarget = event.target;
  14748. renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
  14749. deallocateRenderTarget( renderTarget );
  14750. _infoMemory.textures --;
  14751. }
  14752. function onMaterialDispose( event ) {
  14753. var material = event.target;
  14754. material.removeEventListener( 'dispose', onMaterialDispose );
  14755. deallocateMaterial( material );
  14756. }
  14757. // Buffer deallocation
  14758. function deallocateTexture( texture ) {
  14759. var textureProperties = properties.get( texture );
  14760. if ( texture.image && textureProperties.__image__webglTextureCube ) {
  14761. // cube texture
  14762. _gl.deleteTexture( textureProperties.__image__webglTextureCube );
  14763. } else {
  14764. // 2D texture
  14765. if ( textureProperties.__webglInit === undefined ) return;
  14766. _gl.deleteTexture( textureProperties.__webglTexture );
  14767. }
  14768. // remove all webgl properties
  14769. properties.delete( texture );
  14770. }
  14771. function deallocateRenderTarget( renderTarget ) {
  14772. var renderTargetProperties = properties.get( renderTarget );
  14773. var textureProperties = properties.get( renderTarget.texture );
  14774. if ( ! renderTarget || textureProperties.__webglTexture === undefined ) return;
  14775. _gl.deleteTexture( textureProperties.__webglTexture );
  14776. if ( renderTarget instanceof THREE.WebGLRenderTargetCube ) {
  14777. for ( var i = 0; i < 6; i ++ ) {
  14778. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] );
  14779. _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer[ i ] );
  14780. }
  14781. } else {
  14782. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer );
  14783. _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer );
  14784. }
  14785. properties.delete( renderTarget.texture );
  14786. properties.delete( renderTarget );
  14787. }
  14788. function deallocateMaterial( material ) {
  14789. releaseMaterialProgramReference( material );
  14790. properties.delete( material );
  14791. }
  14792. function releaseMaterialProgramReference( material ) {
  14793. var programInfo = properties.get( material ).program;
  14794. material.program = undefined;
  14795. if ( programInfo !== undefined ) {
  14796. programCache.releaseProgram( programInfo );
  14797. }
  14798. }
  14799. // Buffer rendering
  14800. this.renderBufferImmediate = function ( object, program, material ) {
  14801. state.initAttributes();
  14802. var buffers = properties.get( object );
  14803. if ( object.hasPositions && ! buffers.position ) buffers.position = _gl.createBuffer();
  14804. if ( object.hasNormals && ! buffers.normal ) buffers.normal = _gl.createBuffer();
  14805. if ( object.hasUvs && ! buffers.uv ) buffers.uv = _gl.createBuffer();
  14806. if ( object.hasColors && ! buffers.color ) buffers.color = _gl.createBuffer();
  14807. var attributes = program.getAttributes();
  14808. if ( object.hasPositions ) {
  14809. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.position );
  14810. _gl.bufferData( _gl.ARRAY_BUFFER, object.positionArray, _gl.DYNAMIC_DRAW );
  14811. state.enableAttribute( attributes.position );
  14812. _gl.vertexAttribPointer( attributes.position, 3, _gl.FLOAT, false, 0, 0 );
  14813. }
  14814. if ( object.hasNormals ) {
  14815. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.normal );
  14816. if ( material.type !== 'MeshPhongMaterial' && material.type !== 'MeshStandardMaterial' && material.shading === THREE.FlatShading ) {
  14817. for ( var i = 0, l = object.count * 3; i < l; i += 9 ) {
  14818. var array = object.normalArray;
  14819. var nx = ( array[ i + 0 ] + array[ i + 3 ] + array[ i + 6 ] ) / 3;
  14820. var ny = ( array[ i + 1 ] + array[ i + 4 ] + array[ i + 7 ] ) / 3;
  14821. var nz = ( array[ i + 2 ] + array[ i + 5 ] + array[ i + 8 ] ) / 3;
  14822. array[ i + 0 ] = nx;
  14823. array[ i + 1 ] = ny;
  14824. array[ i + 2 ] = nz;
  14825. array[ i + 3 ] = nx;
  14826. array[ i + 4 ] = ny;
  14827. array[ i + 5 ] = nz;
  14828. array[ i + 6 ] = nx;
  14829. array[ i + 7 ] = ny;
  14830. array[ i + 8 ] = nz;
  14831. }
  14832. }
  14833. _gl.bufferData( _gl.ARRAY_BUFFER, object.normalArray, _gl.DYNAMIC_DRAW );
  14834. state.enableAttribute( attributes.normal );
  14835. _gl.vertexAttribPointer( attributes.normal, 3, _gl.FLOAT, false, 0, 0 );
  14836. }
  14837. if ( object.hasUvs && material.map ) {
  14838. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.uv );
  14839. _gl.bufferData( _gl.ARRAY_BUFFER, object.uvArray, _gl.DYNAMIC_DRAW );
  14840. state.enableAttribute( attributes.uv );
  14841. _gl.vertexAttribPointer( attributes.uv, 2, _gl.FLOAT, false, 0, 0 );
  14842. }
  14843. if ( object.hasColors && material.vertexColors !== THREE.NoColors ) {
  14844. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.color );
  14845. _gl.bufferData( _gl.ARRAY_BUFFER, object.colorArray, _gl.DYNAMIC_DRAW );
  14846. state.enableAttribute( attributes.color );
  14847. _gl.vertexAttribPointer( attributes.color, 3, _gl.FLOAT, false, 0, 0 );
  14848. }
  14849. state.disableUnusedAttributes();
  14850. _gl.drawArrays( _gl.TRIANGLES, 0, object.count );
  14851. object.count = 0;
  14852. };
  14853. this.renderBufferDirect = function ( camera, fog, geometry, material, object, group ) {
  14854. setMaterial( material );
  14855. var program = setProgram( camera, fog, material, object );
  14856. var updateBuffers = false;
  14857. var geometryProgram = geometry.id + '_' + program.id + '_' + material.wireframe;
  14858. if ( geometryProgram !== _currentGeometryProgram ) {
  14859. _currentGeometryProgram = geometryProgram;
  14860. updateBuffers = true;
  14861. }
  14862. // morph targets
  14863. var morphTargetInfluences = object.morphTargetInfluences;
  14864. if ( morphTargetInfluences !== undefined ) {
  14865. var activeInfluences = [];
  14866. for ( var i = 0, l = morphTargetInfluences.length; i < l; i ++ ) {
  14867. var influence = morphTargetInfluences[ i ];
  14868. activeInfluences.push( [ influence, i ] );
  14869. }
  14870. activeInfluences.sort( absNumericalSort );
  14871. if ( activeInfluences.length > 8 ) {
  14872. activeInfluences.length = 8;
  14873. }
  14874. var morphAttributes = geometry.morphAttributes;
  14875. for ( var i = 0, l = activeInfluences.length; i < l; i ++ ) {
  14876. var influence = activeInfluences[ i ];
  14877. morphInfluences[ i ] = influence[ 0 ];
  14878. if ( influence[ 0 ] !== 0 ) {
  14879. var index = influence[ 1 ];
  14880. if ( material.morphTargets === true && morphAttributes.position ) geometry.addAttribute( 'morphTarget' + i, morphAttributes.position[ index ] );
  14881. if ( material.morphNormals === true && morphAttributes.normal ) geometry.addAttribute( 'morphNormal' + i, morphAttributes.normal[ index ] );
  14882. } else {
  14883. if ( material.morphTargets === true ) geometry.removeAttribute( 'morphTarget' + i );
  14884. if ( material.morphNormals === true ) geometry.removeAttribute( 'morphNormal' + i );
  14885. }
  14886. }
  14887. var uniforms = program.getUniforms();
  14888. if ( uniforms.morphTargetInfluences !== null ) {
  14889. _gl.uniform1fv( uniforms.morphTargetInfluences, morphInfluences );
  14890. }
  14891. updateBuffers = true;
  14892. }
  14893. //
  14894. var index = geometry.index;
  14895. var position = geometry.attributes.position;
  14896. if ( material.wireframe === true ) {
  14897. index = objects.getWireframeAttribute( geometry );
  14898. }
  14899. var renderer;
  14900. if ( index !== null ) {
  14901. renderer = indexedBufferRenderer;
  14902. renderer.setIndex( index );
  14903. } else {
  14904. renderer = bufferRenderer;
  14905. }
  14906. if ( updateBuffers ) {
  14907. setupVertexAttributes( material, program, geometry );
  14908. if ( index !== null ) {
  14909. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, objects.getAttributeBuffer( index ) );
  14910. }
  14911. }
  14912. //
  14913. var dataStart = 0;
  14914. var dataCount = Infinity;
  14915. if ( index !== null ) {
  14916. dataCount = index.count;
  14917. } else if ( position !== undefined ) {
  14918. dataCount = position.count;
  14919. }
  14920. var rangeStart = geometry.drawRange.start;
  14921. var rangeCount = geometry.drawRange.count;
  14922. var groupStart = group !== null ? group.start : 0;
  14923. var groupCount = group !== null ? group.count : Infinity;
  14924. var drawStart = Math.max( dataStart, rangeStart, groupStart );
  14925. var drawEnd = Math.min( dataStart + dataCount, rangeStart + rangeCount, groupStart + groupCount ) - 1;
  14926. var drawCount = Math.max( 0, drawEnd - drawStart + 1 );
  14927. //
  14928. if ( object instanceof THREE.Mesh ) {
  14929. if ( material.wireframe === true ) {
  14930. state.setLineWidth( material.wireframeLinewidth * getTargetPixelRatio() );
  14931. renderer.setMode( _gl.LINES );
  14932. } else {
  14933. switch ( object.drawMode ) {
  14934. case THREE.TrianglesDrawMode:
  14935. renderer.setMode( _gl.TRIANGLES );
  14936. break;
  14937. case THREE.TriangleStripDrawMode:
  14938. renderer.setMode( _gl.TRIANGLE_STRIP );
  14939. break;
  14940. case THREE.TriangleFanDrawMode:
  14941. renderer.setMode( _gl.TRIANGLE_FAN );
  14942. break;
  14943. }
  14944. }
  14945. } else if ( object instanceof THREE.Line ) {
  14946. var lineWidth = material.linewidth;
  14947. if ( lineWidth === undefined ) lineWidth = 1; // Not using Line*Material
  14948. state.setLineWidth( lineWidth * getTargetPixelRatio() );
  14949. if ( object instanceof THREE.LineSegments ) {
  14950. renderer.setMode( _gl.LINES );
  14951. } else {
  14952. renderer.setMode( _gl.LINE_STRIP );
  14953. }
  14954. } else if ( object instanceof THREE.Points ) {
  14955. renderer.setMode( _gl.POINTS );
  14956. }
  14957. if ( geometry instanceof THREE.InstancedBufferGeometry ) {
  14958. if ( geometry.maxInstancedCount > 0 ) {
  14959. renderer.renderInstances( geometry, drawStart, drawCount );
  14960. }
  14961. } else {
  14962. renderer.render( drawStart, drawCount );
  14963. }
  14964. };
  14965. function setupVertexAttributes( material, program, geometry, startIndex ) {
  14966. var extension;
  14967. if ( geometry instanceof THREE.InstancedBufferGeometry ) {
  14968. extension = extensions.get( 'ANGLE_instanced_arrays' );
  14969. if ( extension === null ) {
  14970. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  14971. return;
  14972. }
  14973. }
  14974. if ( startIndex === undefined ) startIndex = 0;
  14975. state.initAttributes();
  14976. var geometryAttributes = geometry.attributes;
  14977. var programAttributes = program.getAttributes();
  14978. var materialDefaultAttributeValues = material.defaultAttributeValues;
  14979. for ( var name in programAttributes ) {
  14980. var programAttribute = programAttributes[ name ];
  14981. if ( programAttribute >= 0 ) {
  14982. var geometryAttribute = geometryAttributes[ name ];
  14983. if ( geometryAttribute !== undefined ) {
  14984. var size = geometryAttribute.itemSize;
  14985. var buffer = objects.getAttributeBuffer( geometryAttribute );
  14986. if ( geometryAttribute instanceof THREE.InterleavedBufferAttribute ) {
  14987. var data = geometryAttribute.data;
  14988. var stride = data.stride;
  14989. var offset = geometryAttribute.offset;
  14990. if ( data instanceof THREE.InstancedInterleavedBuffer ) {
  14991. state.enableAttributeAndDivisor( programAttribute, data.meshPerAttribute, extension );
  14992. if ( geometry.maxInstancedCount === undefined ) {
  14993. geometry.maxInstancedCount = data.meshPerAttribute * data.count;
  14994. }
  14995. } else {
  14996. state.enableAttribute( programAttribute );
  14997. }
  14998. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  14999. _gl.vertexAttribPointer( programAttribute, size, _gl.FLOAT, false, stride * data.array.BYTES_PER_ELEMENT, ( startIndex * stride + offset ) * data.array.BYTES_PER_ELEMENT );
  15000. } else {
  15001. if ( geometryAttribute instanceof THREE.InstancedBufferAttribute ) {
  15002. state.enableAttributeAndDivisor( programAttribute, geometryAttribute.meshPerAttribute, extension );
  15003. if ( geometry.maxInstancedCount === undefined ) {
  15004. geometry.maxInstancedCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  15005. }
  15006. } else {
  15007. state.enableAttribute( programAttribute );
  15008. }
  15009. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  15010. _gl.vertexAttribPointer( programAttribute, size, _gl.FLOAT, false, 0, startIndex * size * 4 ); // 4 bytes per Float32
  15011. }
  15012. } else if ( materialDefaultAttributeValues !== undefined ) {
  15013. var value = materialDefaultAttributeValues[ name ];
  15014. if ( value !== undefined ) {
  15015. switch ( value.length ) {
  15016. case 2:
  15017. _gl.vertexAttrib2fv( programAttribute, value );
  15018. break;
  15019. case 3:
  15020. _gl.vertexAttrib3fv( programAttribute, value );
  15021. break;
  15022. case 4:
  15023. _gl.vertexAttrib4fv( programAttribute, value );
  15024. break;
  15025. default:
  15026. _gl.vertexAttrib1fv( programAttribute, value );
  15027. }
  15028. }
  15029. }
  15030. }
  15031. }
  15032. state.disableUnusedAttributes();
  15033. }
  15034. // Sorting
  15035. function absNumericalSort( a, b ) {
  15036. return Math.abs( b[ 0 ] ) - Math.abs( a[ 0 ] );
  15037. }
  15038. function painterSortStable ( a, b ) {
  15039. if ( a.object.renderOrder !== b.object.renderOrder ) {
  15040. return a.object.renderOrder - b.object.renderOrder;
  15041. } else if ( a.material.id !== b.material.id ) {
  15042. return a.material.id - b.material.id;
  15043. } else if ( a.z !== b.z ) {
  15044. return a.z - b.z;
  15045. } else {
  15046. return a.id - b.id;
  15047. }
  15048. }
  15049. function reversePainterSortStable ( a, b ) {
  15050. if ( a.object.renderOrder !== b.object.renderOrder ) {
  15051. return a.object.renderOrder - b.object.renderOrder;
  15052. } if ( a.z !== b.z ) {
  15053. return b.z - a.z;
  15054. } else {
  15055. return a.id - b.id;
  15056. }
  15057. }
  15058. // Rendering
  15059. this.render = function ( scene, camera, renderTarget, forceClear ) {
  15060. if ( camera instanceof THREE.Camera === false ) {
  15061. console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
  15062. return;
  15063. }
  15064. var fog = scene.fog;
  15065. // reset caching for this frame
  15066. _currentGeometryProgram = '';
  15067. _currentMaterialId = - 1;
  15068. _currentCamera = null;
  15069. // update scene graph
  15070. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  15071. // update camera matrices and frustum
  15072. if ( camera.parent === null ) camera.updateMatrixWorld();
  15073. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  15074. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  15075. _frustum.setFromMatrix( _projScreenMatrix );
  15076. lights.length = 0;
  15077. opaqueObjectsLastIndex = - 1;
  15078. transparentObjectsLastIndex = - 1;
  15079. sprites.length = 0;
  15080. lensFlares.length = 0;
  15081. projectObject( scene, camera );
  15082. opaqueObjects.length = opaqueObjectsLastIndex + 1;
  15083. transparentObjects.length = transparentObjectsLastIndex + 1;
  15084. if ( _this.sortObjects === true ) {
  15085. opaqueObjects.sort( painterSortStable );
  15086. transparentObjects.sort( reversePainterSortStable );
  15087. }
  15088. setupLights( lights, camera );
  15089. //
  15090. shadowMap.render( scene, camera );
  15091. //
  15092. _infoRender.calls = 0;
  15093. _infoRender.vertices = 0;
  15094. _infoRender.faces = 0;
  15095. _infoRender.points = 0;
  15096. if ( renderTarget === undefined ) {
  15097. renderTarget = null;
  15098. }
  15099. this.setRenderTarget( renderTarget );
  15100. if ( this.autoClear || forceClear ) {
  15101. this.clear( this.autoClearColor, this.autoClearDepth, this.autoClearStencil );
  15102. }
  15103. //
  15104. if ( scene.overrideMaterial ) {
  15105. var overrideMaterial = scene.overrideMaterial;
  15106. renderObjects( opaqueObjects, camera, fog, overrideMaterial );
  15107. renderObjects( transparentObjects, camera, fog, overrideMaterial );
  15108. } else {
  15109. // opaque pass (front-to-back order)
  15110. state.setBlending( THREE.NoBlending );
  15111. renderObjects( opaqueObjects, camera, fog );
  15112. // transparent pass (back-to-front order)
  15113. renderObjects( transparentObjects, camera, fog );
  15114. }
  15115. // custom render plugins (post pass)
  15116. spritePlugin.render( scene, camera );
  15117. lensFlarePlugin.render( scene, camera, _currentViewport );
  15118. // Generate mipmap if we're using any kind of mipmap filtering
  15119. if ( renderTarget ) {
  15120. var texture = renderTarget.texture;
  15121. if ( texture.generateMipmaps && isPowerOfTwo( renderTarget ) &&
  15122. texture.minFilter !== THREE.NearestFilter &&
  15123. texture.minFilter !== THREE.LinearFilter ) {
  15124. updateRenderTargetMipmap( renderTarget );
  15125. }
  15126. }
  15127. // Ensure depth buffer writing is enabled so it can be cleared on next render
  15128. state.setDepthTest( true );
  15129. state.setDepthWrite( true );
  15130. state.setColorWrite( true );
  15131. // _gl.finish();
  15132. };
  15133. function pushRenderItem( object, geometry, material, z, group ) {
  15134. var array, index;
  15135. // allocate the next position in the appropriate array
  15136. if ( material.transparent ) {
  15137. array = transparentObjects;
  15138. index = ++ transparentObjectsLastIndex;
  15139. } else {
  15140. array = opaqueObjects;
  15141. index = ++ opaqueObjectsLastIndex;
  15142. }
  15143. // recycle existing render item or grow the array
  15144. var renderItem = array[ index ];
  15145. if ( renderItem !== undefined ) {
  15146. renderItem.id = object.id;
  15147. renderItem.object = object;
  15148. renderItem.geometry = geometry;
  15149. renderItem.material = material;
  15150. renderItem.z = _vector3.z;
  15151. renderItem.group = group;
  15152. } else {
  15153. renderItem = {
  15154. id: object.id,
  15155. object: object,
  15156. geometry: geometry,
  15157. material: material,
  15158. z: _vector3.z,
  15159. group: group
  15160. };
  15161. // assert( index === array.length );
  15162. array.push( renderItem );
  15163. }
  15164. }
  15165. function projectObject( object, camera ) {
  15166. if ( object.visible === false ) return;
  15167. if ( object.layers.test( camera.layers ) ) {
  15168. if ( object instanceof THREE.Light ) {
  15169. lights.push( object );
  15170. } else if ( object instanceof THREE.Sprite ) {
  15171. if ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) {
  15172. sprites.push( object );
  15173. }
  15174. } else if ( object instanceof THREE.LensFlare ) {
  15175. lensFlares.push( object );
  15176. } else if ( object instanceof THREE.ImmediateRenderObject ) {
  15177. if ( _this.sortObjects === true ) {
  15178. _vector3.setFromMatrixPosition( object.matrixWorld );
  15179. _vector3.applyProjection( _projScreenMatrix );
  15180. }
  15181. pushRenderItem( object, null, object.material, _vector3.z, null );
  15182. } else if ( object instanceof THREE.Mesh || object instanceof THREE.Line || object instanceof THREE.Points ) {
  15183. if ( object instanceof THREE.SkinnedMesh ) {
  15184. object.skeleton.update();
  15185. }
  15186. if ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) {
  15187. var material = object.material;
  15188. if ( material.visible === true ) {
  15189. if ( _this.sortObjects === true ) {
  15190. _vector3.setFromMatrixPosition( object.matrixWorld );
  15191. _vector3.applyProjection( _projScreenMatrix );
  15192. }
  15193. var geometry = objects.update( object );
  15194. if ( material instanceof THREE.MultiMaterial ) {
  15195. var groups = geometry.groups;
  15196. var materials = material.materials;
  15197. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  15198. var group = groups[ i ];
  15199. var groupMaterial = materials[ group.materialIndex ];
  15200. if ( groupMaterial.visible === true ) {
  15201. pushRenderItem( object, geometry, groupMaterial, _vector3.z, group );
  15202. }
  15203. }
  15204. } else {
  15205. pushRenderItem( object, geometry, material, _vector3.z, null );
  15206. }
  15207. }
  15208. }
  15209. }
  15210. }
  15211. var children = object.children;
  15212. for ( var i = 0, l = children.length; i < l; i ++ ) {
  15213. projectObject( children[ i ], camera );
  15214. }
  15215. }
  15216. function renderObjects( renderList, camera, fog, overrideMaterial ) {
  15217. for ( var i = 0, l = renderList.length; i < l; i ++ ) {
  15218. var renderItem = renderList[ i ];
  15219. var object = renderItem.object;
  15220. var geometry = renderItem.geometry;
  15221. var material = overrideMaterial === undefined ? renderItem.material : overrideMaterial;
  15222. var group = renderItem.group;
  15223. object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  15224. object.normalMatrix.getNormalMatrix( object.modelViewMatrix );
  15225. if ( object instanceof THREE.ImmediateRenderObject ) {
  15226. setMaterial( material );
  15227. var program = setProgram( camera, fog, material, object );
  15228. _currentGeometryProgram = '';
  15229. object.render( function ( object ) {
  15230. _this.renderBufferImmediate( object, program, material );
  15231. } );
  15232. } else {
  15233. _this.renderBufferDirect( camera, fog, geometry, material, object, group );
  15234. }
  15235. }
  15236. }
  15237. function initMaterial( material, fog, object ) {
  15238. var materialProperties = properties.get( material );
  15239. var parameters = programCache.getParameters( material, _lights, fog, object );
  15240. var code = programCache.getProgramCode( material, parameters );
  15241. var program = materialProperties.program;
  15242. var programChange = true;
  15243. if ( program === undefined ) {
  15244. // new material
  15245. material.addEventListener( 'dispose', onMaterialDispose );
  15246. } else if ( program.code !== code ) {
  15247. // changed glsl or parameters
  15248. releaseMaterialProgramReference( material );
  15249. } else if ( parameters.shaderID !== undefined ) {
  15250. // same glsl and uniform list
  15251. return;
  15252. } else {
  15253. // only rebuild uniform list
  15254. programChange = false;
  15255. }
  15256. if ( programChange ) {
  15257. if ( parameters.shaderID ) {
  15258. var shader = THREE.ShaderLib[ parameters.shaderID ];
  15259. materialProperties.__webglShader = {
  15260. name: material.type,
  15261. uniforms: THREE.UniformsUtils.clone( shader.uniforms ),
  15262. vertexShader: shader.vertexShader,
  15263. fragmentShader: shader.fragmentShader
  15264. };
  15265. } else {
  15266. materialProperties.__webglShader = {
  15267. name: material.type,
  15268. uniforms: material.uniforms,
  15269. vertexShader: material.vertexShader,
  15270. fragmentShader: material.fragmentShader
  15271. };
  15272. }
  15273. material.__webglShader = materialProperties.__webglShader;
  15274. program = programCache.acquireProgram( material, parameters, code );
  15275. materialProperties.program = program;
  15276. material.program = program;
  15277. }
  15278. var attributes = program.getAttributes();
  15279. if ( material.morphTargets ) {
  15280. material.numSupportedMorphTargets = 0;
  15281. for ( var i = 0; i < _this.maxMorphTargets; i ++ ) {
  15282. if ( attributes[ 'morphTarget' + i ] >= 0 ) {
  15283. material.numSupportedMorphTargets ++;
  15284. }
  15285. }
  15286. }
  15287. if ( material.morphNormals ) {
  15288. material.numSupportedMorphNormals = 0;
  15289. for ( var i = 0; i < _this.maxMorphNormals; i ++ ) {
  15290. if ( attributes[ 'morphNormal' + i ] >= 0 ) {
  15291. material.numSupportedMorphNormals ++;
  15292. }
  15293. }
  15294. }
  15295. materialProperties.uniformsList = [];
  15296. var uniforms = materialProperties.__webglShader.uniforms,
  15297. uniformLocations = materialProperties.program.getUniforms();
  15298. for ( var u in uniforms ) {
  15299. var location = uniformLocations[ u ];
  15300. if ( location ) {
  15301. materialProperties.uniformsList.push( [ materialProperties.__webglShader.uniforms[ u ], location ] );
  15302. }
  15303. }
  15304. if ( material instanceof THREE.MeshPhongMaterial ||
  15305. material instanceof THREE.MeshLambertMaterial ||
  15306. material instanceof THREE.MeshStandardMaterial ||
  15307. material.lights ) {
  15308. // store the light setup it was created for
  15309. materialProperties.lightsHash = _lights.hash;
  15310. // wire up the material to this renderer's lighting state
  15311. uniforms.ambientLightColor.value = _lights.ambient;
  15312. uniforms.directionalLights.value = _lights.directional;
  15313. uniforms.spotLights.value = _lights.spot;
  15314. uniforms.pointLights.value = _lights.point;
  15315. uniforms.hemisphereLights.value = _lights.hemi;
  15316. uniforms.directionalShadowMap.value = _lights.directionalShadowMap;
  15317. uniforms.directionalShadowMatrix.value = _lights.directionalShadowMatrix;
  15318. uniforms.spotShadowMap.value = _lights.spotShadowMap;
  15319. uniforms.spotShadowMatrix.value = _lights.spotShadowMatrix;
  15320. uniforms.pointShadowMap.value = _lights.pointShadowMap;
  15321. uniforms.pointShadowMatrix.value = _lights.pointShadowMatrix;
  15322. }
  15323. // detect dynamic uniforms
  15324. materialProperties.hasDynamicUniforms = false;
  15325. for ( var j = 0, jl = materialProperties.uniformsList.length; j < jl; j ++ ) {
  15326. var uniform = materialProperties.uniformsList[ j ][ 0 ];
  15327. if ( uniform.dynamic === true ) {
  15328. materialProperties.hasDynamicUniforms = true;
  15329. break;
  15330. }
  15331. }
  15332. }
  15333. function setMaterial( material ) {
  15334. setMaterialFaces( material );
  15335. if ( material.transparent === true ) {
  15336. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha );
  15337. } else {
  15338. state.setBlending( THREE.NoBlending );
  15339. }
  15340. state.setDepthFunc( material.depthFunc );
  15341. state.setDepthTest( material.depthTest );
  15342. state.setDepthWrite( material.depthWrite );
  15343. state.setColorWrite( material.colorWrite );
  15344. state.setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  15345. }
  15346. function setMaterialFaces( material ) {
  15347. material.side !== THREE.DoubleSide ? state.enable( _gl.CULL_FACE ) : state.disable( _gl.CULL_FACE );
  15348. state.setFlipSided( material.side === THREE.BackSide );
  15349. }
  15350. function setProgram( camera, fog, material, object ) {
  15351. _usedTextureUnits = 0;
  15352. var materialProperties = properties.get( material );
  15353. if ( materialProperties.program === undefined ) {
  15354. material.needsUpdate = true;
  15355. }
  15356. if ( materialProperties.lightsHash !== undefined &&
  15357. materialProperties.lightsHash !== _lights.hash ) {
  15358. material.needsUpdate = true;
  15359. }
  15360. if ( material.needsUpdate ) {
  15361. initMaterial( material, fog, object );
  15362. material.needsUpdate = false;
  15363. }
  15364. var refreshProgram = false;
  15365. var refreshMaterial = false;
  15366. var refreshLights = false;
  15367. var program = materialProperties.program,
  15368. p_uniforms = program.getUniforms(),
  15369. m_uniforms = materialProperties.__webglShader.uniforms;
  15370. if ( program.id !== _currentProgram ) {
  15371. _gl.useProgram( program.program );
  15372. _currentProgram = program.id;
  15373. refreshProgram = true;
  15374. refreshMaterial = true;
  15375. refreshLights = true;
  15376. }
  15377. if ( material.id !== _currentMaterialId ) {
  15378. _currentMaterialId = material.id;
  15379. refreshMaterial = true;
  15380. }
  15381. if ( refreshProgram || camera !== _currentCamera ) {
  15382. _gl.uniformMatrix4fv( p_uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
  15383. if ( capabilities.logarithmicDepthBuffer ) {
  15384. _gl.uniform1f( p_uniforms.logDepthBufFC, 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
  15385. }
  15386. if ( camera !== _currentCamera ) {
  15387. _currentCamera = camera;
  15388. // lighting uniforms depend on the camera so enforce an update
  15389. // now, in case this material supports lights - or later, when
  15390. // the next material that does gets activated:
  15391. refreshMaterial = true; // set to true on material change
  15392. refreshLights = true; // remains set until update done
  15393. }
  15394. // load material specific uniforms
  15395. // (shader material also gets them for the sake of genericity)
  15396. if ( material instanceof THREE.ShaderMaterial ||
  15397. material instanceof THREE.MeshPhongMaterial ||
  15398. material instanceof THREE.MeshStandardMaterial ||
  15399. material.envMap ) {
  15400. if ( p_uniforms.cameraPosition !== undefined ) {
  15401. _vector3.setFromMatrixPosition( camera.matrixWorld );
  15402. _gl.uniform3f( p_uniforms.cameraPosition, _vector3.x, _vector3.y, _vector3.z );
  15403. }
  15404. }
  15405. if ( material instanceof THREE.MeshPhongMaterial ||
  15406. material instanceof THREE.MeshLambertMaterial ||
  15407. material instanceof THREE.MeshBasicMaterial ||
  15408. material instanceof THREE.MeshStandardMaterial ||
  15409. material instanceof THREE.ShaderMaterial ||
  15410. material.skinning ) {
  15411. if ( p_uniforms.viewMatrix !== undefined ) {
  15412. _gl.uniformMatrix4fv( p_uniforms.viewMatrix, false, camera.matrixWorldInverse.elements );
  15413. }
  15414. }
  15415. if ( p_uniforms.toneMappingExposure !== undefined ) {
  15416. _gl.uniform1f( p_uniforms.toneMappingExposure, _this.toneMappingExposure );
  15417. }
  15418. if ( p_uniforms.toneMappingWhitePoint !== undefined ) {
  15419. _gl.uniform1f( p_uniforms.toneMappingWhitePoint, _this.toneMappingWhitePoint );
  15420. }
  15421. }
  15422. // skinning uniforms must be set even if material didn't change
  15423. // auto-setting of texture unit for bone texture must go before other textures
  15424. // not sure why, but otherwise weird things happen
  15425. if ( material.skinning ) {
  15426. if ( object.bindMatrix && p_uniforms.bindMatrix !== undefined ) {
  15427. _gl.uniformMatrix4fv( p_uniforms.bindMatrix, false, object.bindMatrix.elements );
  15428. }
  15429. if ( object.bindMatrixInverse && p_uniforms.bindMatrixInverse !== undefined ) {
  15430. _gl.uniformMatrix4fv( p_uniforms.bindMatrixInverse, false, object.bindMatrixInverse.elements );
  15431. }
  15432. if ( capabilities.floatVertexTextures && object.skeleton && object.skeleton.useVertexTexture ) {
  15433. if ( p_uniforms.boneTexture !== undefined ) {
  15434. var textureUnit = getTextureUnit();
  15435. _gl.uniform1i( p_uniforms.boneTexture, textureUnit );
  15436. _this.setTexture( object.skeleton.boneTexture, textureUnit );
  15437. }
  15438. if ( p_uniforms.boneTextureWidth !== undefined ) {
  15439. _gl.uniform1i( p_uniforms.boneTextureWidth, object.skeleton.boneTextureWidth );
  15440. }
  15441. if ( p_uniforms.boneTextureHeight !== undefined ) {
  15442. _gl.uniform1i( p_uniforms.boneTextureHeight, object.skeleton.boneTextureHeight );
  15443. }
  15444. } else if ( object.skeleton && object.skeleton.boneMatrices ) {
  15445. if ( p_uniforms.boneGlobalMatrices !== undefined ) {
  15446. _gl.uniformMatrix4fv( p_uniforms.boneGlobalMatrices, false, object.skeleton.boneMatrices );
  15447. }
  15448. }
  15449. }
  15450. if ( refreshMaterial ) {
  15451. if ( material instanceof THREE.MeshPhongMaterial ||
  15452. material instanceof THREE.MeshLambertMaterial ||
  15453. material instanceof THREE.MeshStandardMaterial ||
  15454. material.lights ) {
  15455. // the current material requires lighting info
  15456. // note: all lighting uniforms are always set correctly
  15457. // they simply reference the renderer's state for their
  15458. // values
  15459. //
  15460. // use the current material's .needsUpdate flags to set
  15461. // the GL state when required
  15462. markUniformsLightsNeedsUpdate( m_uniforms, refreshLights );
  15463. }
  15464. // refresh uniforms common to several materials
  15465. if ( fog && material.fog ) {
  15466. refreshUniformsFog( m_uniforms, fog );
  15467. }
  15468. if ( material instanceof THREE.MeshBasicMaterial ||
  15469. material instanceof THREE.MeshLambertMaterial ||
  15470. material instanceof THREE.MeshPhongMaterial ||
  15471. material instanceof THREE.MeshStandardMaterial ) {
  15472. refreshUniformsCommon( m_uniforms, material );
  15473. }
  15474. // refresh single material specific uniforms
  15475. if ( material instanceof THREE.LineBasicMaterial ) {
  15476. refreshUniformsLine( m_uniforms, material );
  15477. } else if ( material instanceof THREE.LineDashedMaterial ) {
  15478. refreshUniformsLine( m_uniforms, material );
  15479. refreshUniformsDash( m_uniforms, material );
  15480. } else if ( material instanceof THREE.PointsMaterial ) {
  15481. refreshUniformsPoints( m_uniforms, material );
  15482. } else if ( material instanceof THREE.MeshLambertMaterial ) {
  15483. refreshUniformsLambert( m_uniforms, material );
  15484. } else if ( material instanceof THREE.MeshPhongMaterial ) {
  15485. refreshUniformsPhong( m_uniforms, material );
  15486. } else if ( material instanceof THREE.MeshStandardMaterial ) {
  15487. refreshUniformsStandard( m_uniforms, material );
  15488. } else if ( material instanceof THREE.MeshDepthMaterial ) {
  15489. m_uniforms.mNear.value = camera.near;
  15490. m_uniforms.mFar.value = camera.far;
  15491. m_uniforms.opacity.value = material.opacity;
  15492. } else if ( material instanceof THREE.MeshNormalMaterial ) {
  15493. m_uniforms.opacity.value = material.opacity;
  15494. }
  15495. // load common uniforms
  15496. loadUniformsGeneric( materialProperties.uniformsList );
  15497. }
  15498. loadUniformsMatrices( p_uniforms, object );
  15499. if ( p_uniforms.modelMatrix !== undefined ) {
  15500. _gl.uniformMatrix4fv( p_uniforms.modelMatrix, false, object.matrixWorld.elements );
  15501. }
  15502. if ( materialProperties.hasDynamicUniforms === true ) {
  15503. updateDynamicUniforms( materialProperties.uniformsList, object, camera );
  15504. }
  15505. return program;
  15506. }
  15507. function updateDynamicUniforms ( uniforms, object, camera ) {
  15508. var dynamicUniforms = [];
  15509. for ( var j = 0, jl = uniforms.length; j < jl; j ++ ) {
  15510. var uniform = uniforms[ j ][ 0 ];
  15511. var onUpdateCallback = uniform.onUpdateCallback;
  15512. if ( onUpdateCallback !== undefined ) {
  15513. onUpdateCallback.bind( uniform )( object, camera );
  15514. dynamicUniforms.push( uniforms[ j ] );
  15515. }
  15516. }
  15517. loadUniformsGeneric( dynamicUniforms );
  15518. }
  15519. // Uniforms (refresh uniforms objects)
  15520. function refreshUniformsCommon ( uniforms, material ) {
  15521. uniforms.opacity.value = material.opacity;
  15522. uniforms.diffuse.value = material.color;
  15523. if ( material.emissive ) {
  15524. uniforms.emissive.value.copy( material.emissive ).multiplyScalar( material.emissiveIntensity );
  15525. }
  15526. uniforms.map.value = material.map;
  15527. uniforms.specularMap.value = material.specularMap;
  15528. uniforms.alphaMap.value = material.alphaMap;
  15529. if ( material.aoMap ) {
  15530. uniforms.aoMap.value = material.aoMap;
  15531. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  15532. }
  15533. // uv repeat and offset setting priorities
  15534. // 1. color map
  15535. // 2. specular map
  15536. // 3. normal map
  15537. // 4. bump map
  15538. // 5. alpha map
  15539. // 6. emissive map
  15540. var uvScaleMap;
  15541. if ( material.map ) {
  15542. uvScaleMap = material.map;
  15543. } else if ( material.specularMap ) {
  15544. uvScaleMap = material.specularMap;
  15545. } else if ( material.displacementMap ) {
  15546. uvScaleMap = material.displacementMap;
  15547. } else if ( material.normalMap ) {
  15548. uvScaleMap = material.normalMap;
  15549. } else if ( material.bumpMap ) {
  15550. uvScaleMap = material.bumpMap;
  15551. } else if ( material.roughnessMap ) {
  15552. uvScaleMap = material.roughnessMap;
  15553. } else if ( material.metalnessMap ) {
  15554. uvScaleMap = material.metalnessMap;
  15555. } else if ( material.alphaMap ) {
  15556. uvScaleMap = material.alphaMap;
  15557. } else if ( material.emissiveMap ) {
  15558. uvScaleMap = material.emissiveMap;
  15559. }
  15560. if ( uvScaleMap !== undefined ) {
  15561. if ( uvScaleMap instanceof THREE.WebGLRenderTarget ) {
  15562. uvScaleMap = uvScaleMap.texture;
  15563. }
  15564. var offset = uvScaleMap.offset;
  15565. var repeat = uvScaleMap.repeat;
  15566. uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
  15567. }
  15568. uniforms.envMap.value = material.envMap;
  15569. uniforms.flipEnvMap.value = ( material.envMap instanceof THREE.WebGLRenderTargetCube ) ? 1 : - 1;
  15570. uniforms.reflectivity.value = material.reflectivity;
  15571. uniforms.refractionRatio.value = material.refractionRatio;
  15572. }
  15573. function refreshUniformsLine ( uniforms, material ) {
  15574. uniforms.diffuse.value = material.color;
  15575. uniforms.opacity.value = material.opacity;
  15576. }
  15577. function refreshUniformsDash ( uniforms, material ) {
  15578. uniforms.dashSize.value = material.dashSize;
  15579. uniforms.totalSize.value = material.dashSize + material.gapSize;
  15580. uniforms.scale.value = material.scale;
  15581. }
  15582. function refreshUniformsPoints ( uniforms, material ) {
  15583. uniforms.diffuse.value = material.color;
  15584. uniforms.opacity.value = material.opacity;
  15585. uniforms.size.value = material.size * _pixelRatio;
  15586. uniforms.scale.value = _canvas.clientHeight / 2.0; // TODO: Cache this.
  15587. uniforms.map.value = material.map;
  15588. if ( material.map !== null ) {
  15589. var offset = material.map.offset;
  15590. var repeat = material.map.repeat;
  15591. uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
  15592. }
  15593. }
  15594. function refreshUniformsFog ( uniforms, fog ) {
  15595. uniforms.fogColor.value = fog.color;
  15596. if ( fog instanceof THREE.Fog ) {
  15597. uniforms.fogNear.value = fog.near;
  15598. uniforms.fogFar.value = fog.far;
  15599. } else if ( fog instanceof THREE.FogExp2 ) {
  15600. uniforms.fogDensity.value = fog.density;
  15601. }
  15602. }
  15603. function refreshUniformsLambert ( uniforms, material ) {
  15604. if ( material.lightMap ) {
  15605. uniforms.lightMap.value = material.lightMap;
  15606. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  15607. }
  15608. if ( material.emissiveMap ) {
  15609. uniforms.emissiveMap.value = material.emissiveMap;
  15610. }
  15611. }
  15612. function refreshUniformsPhong ( uniforms, material ) {
  15613. uniforms.specular.value = material.specular;
  15614. uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 )
  15615. if ( material.lightMap ) {
  15616. uniforms.lightMap.value = material.lightMap;
  15617. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  15618. }
  15619. if ( material.emissiveMap ) {
  15620. uniforms.emissiveMap.value = material.emissiveMap;
  15621. }
  15622. if ( material.bumpMap ) {
  15623. uniforms.bumpMap.value = material.bumpMap;
  15624. uniforms.bumpScale.value = material.bumpScale;
  15625. }
  15626. if ( material.normalMap ) {
  15627. uniforms.normalMap.value = material.normalMap;
  15628. uniforms.normalScale.value.copy( material.normalScale );
  15629. }
  15630. if ( material.displacementMap ) {
  15631. uniforms.displacementMap.value = material.displacementMap;
  15632. uniforms.displacementScale.value = material.displacementScale;
  15633. uniforms.displacementBias.value = material.displacementBias;
  15634. }
  15635. }
  15636. function refreshUniformsStandard ( uniforms, material ) {
  15637. uniforms.roughness.value = material.roughness;
  15638. uniforms.metalness.value = material.metalness;
  15639. if ( material.roughnessMap ) {
  15640. uniforms.roughnessMap.value = material.roughnessMap;
  15641. }
  15642. if ( material.metalnessMap ) {
  15643. uniforms.metalnessMap.value = material.metalnessMap;
  15644. }
  15645. if ( material.lightMap ) {
  15646. uniforms.lightMap.value = material.lightMap;
  15647. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  15648. }
  15649. if ( material.emissiveMap ) {
  15650. uniforms.emissiveMap.value = material.emissiveMap;
  15651. }
  15652. if ( material.bumpMap ) {
  15653. uniforms.bumpMap.value = material.bumpMap;
  15654. uniforms.bumpScale.value = material.bumpScale;
  15655. }
  15656. if ( material.normalMap ) {
  15657. uniforms.normalMap.value = material.normalMap;
  15658. uniforms.normalScale.value.copy( material.normalScale );
  15659. }
  15660. if ( material.displacementMap ) {
  15661. uniforms.displacementMap.value = material.displacementMap;
  15662. uniforms.displacementScale.value = material.displacementScale;
  15663. uniforms.displacementBias.value = material.displacementBias;
  15664. }
  15665. if ( material.envMap ) {
  15666. //uniforms.envMap.value = material.envMap; // part of uniforms common
  15667. uniforms.envMapIntensity.value = material.envMapIntensity;
  15668. }
  15669. }
  15670. // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  15671. function markUniformsLightsNeedsUpdate ( uniforms, value ) {
  15672. uniforms.ambientLightColor.needsUpdate = value;
  15673. uniforms.directionalLights.needsUpdate = value;
  15674. uniforms.pointLights.needsUpdate = value;
  15675. uniforms.spotLights.needsUpdate = value;
  15676. uniforms.hemisphereLights.needsUpdate = value;
  15677. }
  15678. // Uniforms (load to GPU)
  15679. function loadUniformsMatrices ( uniforms, object ) {
  15680. _gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, object.modelViewMatrix.elements );
  15681. if ( uniforms.normalMatrix ) {
  15682. _gl.uniformMatrix3fv( uniforms.normalMatrix, false, object.normalMatrix.elements );
  15683. }
  15684. }
  15685. function getTextureUnit() {
  15686. var textureUnit = _usedTextureUnits;
  15687. if ( textureUnit >= capabilities.maxTextures ) {
  15688. console.warn( 'WebGLRenderer: trying to use ' + textureUnit + ' texture units while this GPU supports only ' + capabilities.maxTextures );
  15689. }
  15690. _usedTextureUnits += 1;
  15691. return textureUnit;
  15692. }
  15693. function loadUniform( uniform, type, location, value ) {
  15694. var texture, textureUnit;
  15695. if ( type === '1i' ) {
  15696. _gl.uniform1i( location, value );
  15697. } else if ( type === '1f' ) {
  15698. _gl.uniform1f( location, value );
  15699. } else if ( type === '2f' ) {
  15700. _gl.uniform2f( location, value[ 0 ], value[ 1 ] );
  15701. } else if ( type === '3f' ) {
  15702. _gl.uniform3f( location, value[ 0 ], value[ 1 ], value[ 2 ] );
  15703. } else if ( type === '4f' ) {
  15704. _gl.uniform4f( location, value[ 0 ], value[ 1 ], value[ 2 ], value[ 3 ] );
  15705. } else if ( type === '1iv' ) {
  15706. _gl.uniform1iv( location, value );
  15707. } else if ( type === '3iv' ) {
  15708. _gl.uniform3iv( location, value );
  15709. } else if ( type === '1fv' ) {
  15710. _gl.uniform1fv( location, value );
  15711. } else if ( type === '2fv' ) {
  15712. _gl.uniform2fv( location, value );
  15713. } else if ( type === '3fv' ) {
  15714. _gl.uniform3fv( location, value );
  15715. } else if ( type === '4fv' ) {
  15716. _gl.uniform4fv( location, value );
  15717. } else if ( type === 'Matrix2fv' ) {
  15718. _gl.uniformMatrix2fv( location, false, value );
  15719. } else if ( type === 'Matrix3fv' ) {
  15720. _gl.uniformMatrix3fv( location, false, value );
  15721. } else if ( type === 'Matrix4fv' ) {
  15722. _gl.uniformMatrix4fv( location, false, value );
  15723. //
  15724. } else if ( type === 'i' ) {
  15725. // single integer
  15726. _gl.uniform1i( location, value );
  15727. } else if ( type === 'f' ) {
  15728. // single float
  15729. _gl.uniform1f( location, value );
  15730. } else if ( type === 'v2' ) {
  15731. // single THREE.Vector2
  15732. _gl.uniform2f( location, value.x, value.y );
  15733. } else if ( type === 'v3' ) {
  15734. // single THREE.Vector3
  15735. _gl.uniform3f( location, value.x, value.y, value.z );
  15736. } else if ( type === 'v4' ) {
  15737. // single THREE.Vector4
  15738. _gl.uniform4f( location, value.x, value.y, value.z, value.w );
  15739. } else if ( type === 'c' ) {
  15740. // single THREE.Color
  15741. _gl.uniform3f( location, value.r, value.g, value.b );
  15742. } else if ( type === 's' ) {
  15743. // TODO: Optimize this
  15744. var properties = uniform.properties;
  15745. for ( var name in properties ) {
  15746. var property = properties[ name ];
  15747. var locationProperty = location[ name ];
  15748. var valueProperty = value[ name ];
  15749. loadUniform( property, property.type, locationProperty, valueProperty );
  15750. }
  15751. } else if ( type === 'sa' ) {
  15752. // TODO: Optimize this
  15753. var properties = uniform.properties;
  15754. for ( var i = 0, l = value.length; i < l; i ++ ) {
  15755. for ( var name in properties ) {
  15756. var property = properties[ name ];
  15757. var locationProperty = location[ i ][ name ];
  15758. var valueProperty = value[ i ][ name ];
  15759. loadUniform( property, property.type, locationProperty, valueProperty );
  15760. }
  15761. }
  15762. } else if ( type === 'iv1' ) {
  15763. // flat array of integers (JS or typed array)
  15764. _gl.uniform1iv( location, value );
  15765. } else if ( type === 'iv' ) {
  15766. // flat array of integers with 3 x N size (JS or typed array)
  15767. _gl.uniform3iv( location, value );
  15768. } else if ( type === 'fv1' ) {
  15769. // flat array of floats (JS or typed array)
  15770. _gl.uniform1fv( location, value );
  15771. } else if ( type === 'fv' ) {
  15772. // flat array of floats with 3 x N size (JS or typed array)
  15773. _gl.uniform3fv( location, value );
  15774. } else if ( type === 'v2v' ) {
  15775. // array of THREE.Vector2
  15776. if ( uniform._array === undefined ) {
  15777. uniform._array = new Float32Array( 2 * value.length );
  15778. }
  15779. for ( var i = 0, i2 = 0, il = value.length; i < il; i ++, i2 += 2 ) {
  15780. uniform._array[ i2 + 0 ] = value[ i ].x;
  15781. uniform._array[ i2 + 1 ] = value[ i ].y;
  15782. }
  15783. _gl.uniform2fv( location, uniform._array );
  15784. } else if ( type === 'v3v' ) {
  15785. // array of THREE.Vector3
  15786. if ( uniform._array === undefined ) {
  15787. uniform._array = new Float32Array( 3 * value.length );
  15788. }
  15789. for ( var i = 0, i3 = 0, il = value.length; i < il; i ++, i3 += 3 ) {
  15790. uniform._array[ i3 + 0 ] = value[ i ].x;
  15791. uniform._array[ i3 + 1 ] = value[ i ].y;
  15792. uniform._array[ i3 + 2 ] = value[ i ].z;
  15793. }
  15794. _gl.uniform3fv( location, uniform._array );
  15795. } else if ( type === 'v4v' ) {
  15796. // array of THREE.Vector4
  15797. if ( uniform._array === undefined ) {
  15798. uniform._array = new Float32Array( 4 * value.length );
  15799. }
  15800. for ( var i = 0, i4 = 0, il = value.length; i < il; i ++, i4 += 4 ) {
  15801. uniform._array[ i4 + 0 ] = value[ i ].x;
  15802. uniform._array[ i4 + 1 ] = value[ i ].y;
  15803. uniform._array[ i4 + 2 ] = value[ i ].z;
  15804. uniform._array[ i4 + 3 ] = value[ i ].w;
  15805. }
  15806. _gl.uniform4fv( location, uniform._array );
  15807. } else if ( type === 'm2' ) {
  15808. // single THREE.Matrix2
  15809. _gl.uniformMatrix2fv( location, false, value.elements );
  15810. } else if ( type === 'm3' ) {
  15811. // single THREE.Matrix3
  15812. _gl.uniformMatrix3fv( location, false, value.elements );
  15813. } else if ( type === 'm3v' ) {
  15814. // array of THREE.Matrix3
  15815. if ( uniform._array === undefined ) {
  15816. uniform._array = new Float32Array( 9 * value.length );
  15817. }
  15818. for ( var i = 0, il = value.length; i < il; i ++ ) {
  15819. value[ i ].flattenToArrayOffset( uniform._array, i * 9 );
  15820. }
  15821. _gl.uniformMatrix3fv( location, false, uniform._array );
  15822. } else if ( type === 'm4' ) {
  15823. // single THREE.Matrix4
  15824. _gl.uniformMatrix4fv( location, false, value.elements );
  15825. } else if ( type === 'm4v' ) {
  15826. // array of THREE.Matrix4
  15827. if ( uniform._array === undefined ) {
  15828. uniform._array = new Float32Array( 16 * value.length );
  15829. }
  15830. for ( var i = 0, il = value.length; i < il; i ++ ) {
  15831. value[ i ].flattenToArrayOffset( uniform._array, i * 16 );
  15832. }
  15833. _gl.uniformMatrix4fv( location, false, uniform._array );
  15834. } else if ( type === 't' ) {
  15835. // single THREE.Texture (2d or cube)
  15836. texture = value;
  15837. textureUnit = getTextureUnit();
  15838. _gl.uniform1i( location, textureUnit );
  15839. if ( ! texture ) return;
  15840. if ( texture instanceof THREE.CubeTexture ||
  15841. ( Array.isArray( texture.image ) && texture.image.length === 6 ) ) {
  15842. // CompressedTexture can have Array in image :/
  15843. setCubeTexture( texture, textureUnit );
  15844. } else if ( texture instanceof THREE.WebGLRenderTargetCube ) {
  15845. setCubeTextureDynamic( texture.texture, textureUnit );
  15846. } else if ( texture instanceof THREE.WebGLRenderTarget ) {
  15847. _this.setTexture( texture.texture, textureUnit );
  15848. } else {
  15849. _this.setTexture( texture, textureUnit );
  15850. }
  15851. } else if ( type === 'tv' ) {
  15852. // array of THREE.Texture (2d or cube)
  15853. if ( uniform._array === undefined ) {
  15854. uniform._array = [];
  15855. }
  15856. for ( var i = 0, il = uniform.value.length; i < il; i ++ ) {
  15857. uniform._array[ i ] = getTextureUnit();
  15858. }
  15859. _gl.uniform1iv( location, uniform._array );
  15860. for ( var i = 0, il = uniform.value.length; i < il; i ++ ) {
  15861. texture = uniform.value[ i ];
  15862. textureUnit = uniform._array[ i ];
  15863. if ( ! texture ) continue;
  15864. if ( texture instanceof THREE.CubeTexture ||
  15865. ( texture.image instanceof Array && texture.image.length === 6 ) ) {
  15866. // CompressedTexture can have Array in image :/
  15867. setCubeTexture( texture, textureUnit );
  15868. } else if ( texture instanceof THREE.WebGLRenderTarget ) {
  15869. _this.setTexture( texture.texture, textureUnit );
  15870. } else if ( texture instanceof THREE.WebGLRenderTargetCube ) {
  15871. setCubeTextureDynamic( texture.texture, textureUnit );
  15872. } else {
  15873. _this.setTexture( texture, textureUnit );
  15874. }
  15875. }
  15876. } else {
  15877. console.warn( 'THREE.WebGLRenderer: Unknown uniform type: ' + type );
  15878. }
  15879. }
  15880. function loadUniformsGeneric( uniforms ) {
  15881. for ( var i = 0, l = uniforms.length; i < l; i ++ ) {
  15882. var uniform = uniforms[ i ][ 0 ];
  15883. // needsUpdate property is not added to all uniforms.
  15884. if ( uniform.needsUpdate === false ) continue;
  15885. var type = uniform.type;
  15886. var location = uniforms[ i ][ 1 ];
  15887. var value = uniform.value;
  15888. loadUniform( uniform, type, location, value );
  15889. }
  15890. }
  15891. function setupLights ( lights, camera ) {
  15892. var l, ll, light,
  15893. r = 0, g = 0, b = 0,
  15894. color,
  15895. intensity,
  15896. distance,
  15897. viewMatrix = camera.matrixWorldInverse,
  15898. directionalLength = 0,
  15899. pointLength = 0,
  15900. spotLength = 0,
  15901. hemiLength = 0,
  15902. shadowsLength = 0;
  15903. _lights.shadowsPointLight = 0;
  15904. for ( l = 0, ll = lights.length; l < ll; l ++ ) {
  15905. light = lights[ l ];
  15906. color = light.color;
  15907. intensity = light.intensity;
  15908. distance = light.distance;
  15909. if ( light instanceof THREE.AmbientLight ) {
  15910. r += color.r * intensity;
  15911. g += color.g * intensity;
  15912. b += color.b * intensity;
  15913. } else if ( light instanceof THREE.DirectionalLight ) {
  15914. var uniforms = lightCache.get( light );
  15915. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  15916. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  15917. _vector3.setFromMatrixPosition( light.target.matrixWorld );
  15918. uniforms.direction.sub( _vector3 );
  15919. uniforms.direction.transformDirection( viewMatrix );
  15920. uniforms.shadow = light.castShadow;
  15921. if ( light.castShadow ) {
  15922. uniforms.shadowBias = light.shadow.bias;
  15923. uniforms.shadowRadius = light.shadow.radius;
  15924. uniforms.shadowMapSize = light.shadow.mapSize;
  15925. _lights.shadows[ shadowsLength ++ ] = light;
  15926. }
  15927. _lights.directionalShadowMap[ directionalLength ] = light.shadow.map;
  15928. _lights.directionalShadowMatrix[ directionalLength ] = light.shadow.matrix;
  15929. _lights.directional[ directionalLength ++ ] = uniforms;
  15930. } else if ( light instanceof THREE.SpotLight ) {
  15931. var uniforms = lightCache.get( light );
  15932. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  15933. uniforms.position.applyMatrix4( viewMatrix );
  15934. uniforms.color.copy( color ).multiplyScalar( intensity );
  15935. uniforms.distance = distance;
  15936. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  15937. _vector3.setFromMatrixPosition( light.target.matrixWorld );
  15938. uniforms.direction.sub( _vector3 );
  15939. uniforms.direction.transformDirection( viewMatrix );
  15940. uniforms.coneCos = Math.cos( light.angle );
  15941. uniforms.penumbraCos = Math.cos( light.angle * ( 1 - light.penumbra ) );
  15942. uniforms.decay = ( light.distance === 0 ) ? 0.0 : light.decay;
  15943. uniforms.shadow = light.castShadow;
  15944. if ( light.castShadow ) {
  15945. uniforms.shadowBias = light.shadow.bias;
  15946. uniforms.shadowRadius = light.shadow.radius;
  15947. uniforms.shadowMapSize = light.shadow.mapSize;
  15948. _lights.shadows[ shadowsLength ++ ] = light;
  15949. }
  15950. _lights.spotShadowMap[ spotLength ] = light.shadow.map;
  15951. _lights.spotShadowMatrix[ spotLength ] = light.shadow.matrix;
  15952. _lights.spot[ spotLength ++ ] = uniforms;
  15953. } else if ( light instanceof THREE.PointLight ) {
  15954. var uniforms = lightCache.get( light );
  15955. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  15956. uniforms.position.applyMatrix4( viewMatrix );
  15957. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  15958. uniforms.distance = light.distance;
  15959. uniforms.decay = ( light.distance === 0 ) ? 0.0 : light.decay;
  15960. uniforms.shadow = light.castShadow;
  15961. if ( light.castShadow ) {
  15962. uniforms.shadowBias = light.shadow.bias;
  15963. uniforms.shadowRadius = light.shadow.radius;
  15964. uniforms.shadowMapSize = light.shadow.mapSize;
  15965. _lights.shadows[ shadowsLength ++ ] = light;
  15966. }
  15967. _lights.pointShadowMap[ pointLength ] = light.shadow.map;
  15968. if ( _lights.pointShadowMatrix[ pointLength ] === undefined ) {
  15969. _lights.pointShadowMatrix[ pointLength ] = new THREE.Matrix4();
  15970. }
  15971. // for point lights we set the shadow matrix to be a translation-only matrix
  15972. // equal to inverse of the light's position
  15973. _vector3.setFromMatrixPosition( light.matrixWorld ).negate();
  15974. _lights.pointShadowMatrix[ pointLength ].identity().setPosition( _vector3 );
  15975. _lights.point[ pointLength ++ ] = uniforms;
  15976. } else if ( light instanceof THREE.HemisphereLight ) {
  15977. var uniforms = lightCache.get( light );
  15978. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  15979. uniforms.direction.transformDirection( viewMatrix );
  15980. uniforms.direction.normalize();
  15981. uniforms.skyColor.copy( light.color ).multiplyScalar( intensity );
  15982. uniforms.groundColor.copy( light.groundColor ).multiplyScalar( intensity );
  15983. _lights.hemi[ hemiLength ++ ] = uniforms;
  15984. }
  15985. }
  15986. _lights.ambient[ 0 ] = r;
  15987. _lights.ambient[ 1 ] = g;
  15988. _lights.ambient[ 2 ] = b;
  15989. _lights.directional.length = directionalLength;
  15990. _lights.spot.length = spotLength;
  15991. _lights.point.length = pointLength;
  15992. _lights.hemi.length = hemiLength;
  15993. _lights.shadows.length = shadowsLength;
  15994. _lights.hash = directionalLength + ',' + pointLength + ',' + spotLength + ',' + hemiLength + ',' + shadowsLength;
  15995. }
  15996. // GL state setting
  15997. this.setFaceCulling = function ( cullFace, frontFaceDirection ) {
  15998. if ( cullFace === THREE.CullFaceNone ) {
  15999. state.disable( _gl.CULL_FACE );
  16000. } else {
  16001. if ( frontFaceDirection === THREE.FrontFaceDirectionCW ) {
  16002. _gl.frontFace( _gl.CW );
  16003. } else {
  16004. _gl.frontFace( _gl.CCW );
  16005. }
  16006. if ( cullFace === THREE.CullFaceBack ) {
  16007. _gl.cullFace( _gl.BACK );
  16008. } else if ( cullFace === THREE.CullFaceFront ) {
  16009. _gl.cullFace( _gl.FRONT );
  16010. } else {
  16011. _gl.cullFace( _gl.FRONT_AND_BACK );
  16012. }
  16013. state.enable( _gl.CULL_FACE );
  16014. }
  16015. };
  16016. // Textures
  16017. function setTextureParameters ( textureType, texture, isPowerOfTwoImage ) {
  16018. var extension;
  16019. if ( isPowerOfTwoImage ) {
  16020. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, paramThreeToGL( texture.wrapS ) );
  16021. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, paramThreeToGL( texture.wrapT ) );
  16022. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, paramThreeToGL( texture.magFilter ) );
  16023. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, paramThreeToGL( texture.minFilter ) );
  16024. } else {
  16025. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, _gl.CLAMP_TO_EDGE );
  16026. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, _gl.CLAMP_TO_EDGE );
  16027. if ( texture.wrapS !== THREE.ClampToEdgeWrapping || texture.wrapT !== THREE.ClampToEdgeWrapping ) {
  16028. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.', texture );
  16029. }
  16030. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, filterFallback( texture.magFilter ) );
  16031. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, filterFallback( texture.minFilter ) );
  16032. if ( texture.minFilter !== THREE.NearestFilter && texture.minFilter !== THREE.LinearFilter ) {
  16033. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.', texture );
  16034. }
  16035. }
  16036. extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  16037. if ( extension ) {
  16038. if ( texture.type === THREE.FloatType && extensions.get( 'OES_texture_float_linear' ) === null ) return;
  16039. if ( texture.type === THREE.HalfFloatType && extensions.get( 'OES_texture_half_float_linear' ) === null ) return;
  16040. if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
  16041. _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, _this.getMaxAnisotropy() ) );
  16042. properties.get( texture ).__currentAnisotropy = texture.anisotropy;
  16043. }
  16044. }
  16045. }
  16046. function uploadTexture( textureProperties, texture, slot ) {
  16047. if ( textureProperties.__webglInit === undefined ) {
  16048. textureProperties.__webglInit = true;
  16049. texture.addEventListener( 'dispose', onTextureDispose );
  16050. textureProperties.__webglTexture = _gl.createTexture();
  16051. _infoMemory.textures ++;
  16052. }
  16053. state.activeTexture( _gl.TEXTURE0 + slot );
  16054. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  16055. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  16056. _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );
  16057. _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
  16058. var image = clampToMaxSize( texture.image, capabilities.maxTextureSize );
  16059. if ( textureNeedsPowerOfTwo( texture ) && isPowerOfTwo( image ) === false ) {
  16060. image = makePowerOfTwo( image );
  16061. }
  16062. var isPowerOfTwoImage = isPowerOfTwo( image ),
  16063. glFormat = paramThreeToGL( texture.format ),
  16064. glType = paramThreeToGL( texture.type );
  16065. setTextureParameters( _gl.TEXTURE_2D, texture, isPowerOfTwoImage );
  16066. var mipmap, mipmaps = texture.mipmaps;
  16067. if ( texture instanceof THREE.DataTexture ) {
  16068. // use manually created mipmaps if available
  16069. // if there are no manual mipmaps
  16070. // set 0 level mipmap and then use GL to generate other mipmap levels
  16071. if ( mipmaps.length > 0 && isPowerOfTwoImage ) {
  16072. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  16073. mipmap = mipmaps[ i ];
  16074. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  16075. }
  16076. texture.generateMipmaps = false;
  16077. } else {
  16078. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, image.width, image.height, 0, glFormat, glType, image.data );
  16079. }
  16080. } else if ( texture instanceof THREE.CompressedTexture ) {
  16081. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  16082. mipmap = mipmaps[ i ];
  16083. if ( texture.format !== THREE.RGBAFormat && texture.format !== THREE.RGBFormat ) {
  16084. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  16085. state.compressedTexImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  16086. } else {
  16087. console.warn( "THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()" );
  16088. }
  16089. } else {
  16090. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  16091. }
  16092. }
  16093. } else {
  16094. // regular Texture (image, video, canvas)
  16095. // use manually created mipmaps if available
  16096. // if there are no manual mipmaps
  16097. // set 0 level mipmap and then use GL to generate other mipmap levels
  16098. if ( mipmaps.length > 0 && isPowerOfTwoImage ) {
  16099. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  16100. mipmap = mipmaps[ i ];
  16101. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, glFormat, glType, mipmap );
  16102. }
  16103. texture.generateMipmaps = false;
  16104. } else {
  16105. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, glFormat, glType, image );
  16106. }
  16107. }
  16108. if ( texture.generateMipmaps && isPowerOfTwoImage ) _gl.generateMipmap( _gl.TEXTURE_2D );
  16109. textureProperties.__version = texture.version;
  16110. if ( texture.onUpdate ) texture.onUpdate( texture );
  16111. }
  16112. this.setTexture = function ( texture, slot ) {
  16113. var textureProperties = properties.get( texture );
  16114. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  16115. var image = texture.image;
  16116. if ( image === undefined ) {
  16117. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is undefined', texture );
  16118. return;
  16119. }
  16120. if ( image.complete === false ) {
  16121. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete', texture );
  16122. return;
  16123. }
  16124. uploadTexture( textureProperties, texture, slot );
  16125. return;
  16126. }
  16127. state.activeTexture( _gl.TEXTURE0 + slot );
  16128. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  16129. };
  16130. function clampToMaxSize ( image, maxSize ) {
  16131. if ( image.width > maxSize || image.height > maxSize ) {
  16132. // Warning: Scaling through the canvas will only work with images that use
  16133. // premultiplied alpha.
  16134. var scale = maxSize / Math.max( image.width, image.height );
  16135. var canvas = document.createElement( 'canvas' );
  16136. canvas.width = Math.floor( image.width * scale );
  16137. canvas.height = Math.floor( image.height * scale );
  16138. var context = canvas.getContext( '2d' );
  16139. context.drawImage( image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height );
  16140. console.warn( 'THREE.WebGLRenderer: image is too big (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
  16141. return canvas;
  16142. }
  16143. return image;
  16144. }
  16145. function isPowerOfTwo( image ) {
  16146. return THREE.Math.isPowerOfTwo( image.width ) && THREE.Math.isPowerOfTwo( image.height );
  16147. }
  16148. function textureNeedsPowerOfTwo( texture ) {
  16149. if ( texture.wrapS !== THREE.ClampToEdgeWrapping || texture.wrapT !== THREE.ClampToEdgeWrapping ) return true;
  16150. if ( texture.minFilter !== THREE.NearestFilter && texture.minFilter !== THREE.LinearFilter ) return true;
  16151. return false;
  16152. }
  16153. function makePowerOfTwo( image ) {
  16154. if ( image instanceof HTMLImageElement || image instanceof HTMLCanvasElement ) {
  16155. var canvas = document.createElement( 'canvas' );
  16156. canvas.width = THREE.Math.nearestPowerOfTwo( image.width );
  16157. canvas.height = THREE.Math.nearestPowerOfTwo( image.height );
  16158. var context = canvas.getContext( '2d' );
  16159. context.drawImage( image, 0, 0, canvas.width, canvas.height );
  16160. console.warn( 'THREE.WebGLRenderer: image is not power of two (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
  16161. return canvas;
  16162. }
  16163. return image;
  16164. }
  16165. function setCubeTexture ( texture, slot ) {
  16166. var textureProperties = properties.get( texture );
  16167. if ( texture.image.length === 6 ) {
  16168. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  16169. if ( ! textureProperties.__image__webglTextureCube ) {
  16170. texture.addEventListener( 'dispose', onTextureDispose );
  16171. textureProperties.__image__webglTextureCube = _gl.createTexture();
  16172. _infoMemory.textures ++;
  16173. }
  16174. state.activeTexture( _gl.TEXTURE0 + slot );
  16175. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  16176. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  16177. var isCompressed = texture instanceof THREE.CompressedTexture;
  16178. var isDataTexture = texture.image[ 0 ] instanceof THREE.DataTexture;
  16179. var cubeImage = [];
  16180. for ( var i = 0; i < 6; i ++ ) {
  16181. if ( _this.autoScaleCubemaps && ! isCompressed && ! isDataTexture ) {
  16182. cubeImage[ i ] = clampToMaxSize( texture.image[ i ], capabilities.maxCubemapSize );
  16183. } else {
  16184. cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
  16185. }
  16186. }
  16187. var image = cubeImage[ 0 ],
  16188. isPowerOfTwoImage = isPowerOfTwo( image ),
  16189. glFormat = paramThreeToGL( texture.format ),
  16190. glType = paramThreeToGL( texture.type );
  16191. setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture, isPowerOfTwoImage );
  16192. for ( var i = 0; i < 6; i ++ ) {
  16193. if ( ! isCompressed ) {
  16194. if ( isDataTexture ) {
  16195. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
  16196. } else {
  16197. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, glFormat, glType, cubeImage[ i ] );
  16198. }
  16199. } else {
  16200. var mipmap, mipmaps = cubeImage[ i ].mipmaps;
  16201. for ( var j = 0, jl = mipmaps.length; j < jl; j ++ ) {
  16202. mipmap = mipmaps[ j ];
  16203. if ( texture.format !== THREE.RGBAFormat && texture.format !== THREE.RGBFormat ) {
  16204. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  16205. state.compressedTexImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  16206. } else {
  16207. console.warn( "THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setCubeTexture()" );
  16208. }
  16209. } else {
  16210. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  16211. }
  16212. }
  16213. }
  16214. }
  16215. if ( texture.generateMipmaps && isPowerOfTwoImage ) {
  16216. _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  16217. }
  16218. textureProperties.__version = texture.version;
  16219. if ( texture.onUpdate ) texture.onUpdate( texture );
  16220. } else {
  16221. state.activeTexture( _gl.TEXTURE0 + slot );
  16222. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  16223. }
  16224. }
  16225. }
  16226. function setCubeTextureDynamic ( texture, slot ) {
  16227. state.activeTexture( _gl.TEXTURE0 + slot );
  16228. state.bindTexture( _gl.TEXTURE_CUBE_MAP, properties.get( texture ).__webglTexture );
  16229. }
  16230. // Render targets
  16231. // Setup storage for target texture and bind it to correct framebuffer
  16232. function setupFrameBufferTexture ( framebuffer, renderTarget, attachment, textureTarget ) {
  16233. var glFormat = paramThreeToGL( renderTarget.texture.format );
  16234. var glType = paramThreeToGL( renderTarget.texture.type );
  16235. state.texImage2D( textureTarget, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  16236. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  16237. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, attachment, textureTarget, properties.get( renderTarget.texture ).__webglTexture, 0 );
  16238. _gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
  16239. }
  16240. // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  16241. function setupRenderBufferStorage ( renderbuffer, renderTarget ) {
  16242. _gl.bindRenderbuffer( _gl.RENDERBUFFER, renderbuffer );
  16243. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  16244. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_COMPONENT16, renderTarget.width, renderTarget.height );
  16245. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  16246. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  16247. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_STENCIL, renderTarget.width, renderTarget.height );
  16248. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  16249. } else {
  16250. // FIXME: We don't support !depth !stencil
  16251. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.RGBA4, renderTarget.width, renderTarget.height );
  16252. }
  16253. _gl.bindRenderbuffer( _gl.RENDERBUFFER, null );
  16254. }
  16255. // Setup GL resources for a non-texture depth buffer
  16256. function setupDepthRenderbuffer( renderTarget ) {
  16257. var renderTargetProperties = properties.get( renderTarget );
  16258. var isCube = ( renderTarget instanceof THREE.WebGLRenderTargetCube );
  16259. if ( isCube ) {
  16260. renderTargetProperties.__webglDepthbuffer = [];
  16261. for ( var i = 0; i < 6; i ++ ) {
  16262. _gl.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer[ i ] );
  16263. renderTargetProperties.__webglDepthbuffer[ i ] = _gl.createRenderbuffer();
  16264. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer[ i ], renderTarget );
  16265. }
  16266. } else {
  16267. _gl.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer );
  16268. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  16269. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer, renderTarget );
  16270. }
  16271. _gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
  16272. }
  16273. // Set up GL resources for the render target
  16274. function setupRenderTarget( renderTarget ) {
  16275. var renderTargetProperties = properties.get( renderTarget );
  16276. var textureProperties = properties.get( renderTarget.texture );
  16277. renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
  16278. textureProperties.__webglTexture = _gl.createTexture();
  16279. _infoMemory.textures ++;
  16280. var isCube = ( renderTarget instanceof THREE.WebGLRenderTargetCube );
  16281. var isTargetPowerOfTwo = THREE.Math.isPowerOfTwo( renderTarget.width ) && THREE.Math.isPowerOfTwo( renderTarget.height );
  16282. // Setup framebuffer
  16283. if ( isCube ) {
  16284. renderTargetProperties.__webglFramebuffer = [];
  16285. for ( var i = 0; i < 6; i ++ ) {
  16286. renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer();
  16287. }
  16288. } else {
  16289. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  16290. }
  16291. // Setup color buffer
  16292. if ( isCube ) {
  16293. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__webglTexture );
  16294. setTextureParameters( _gl.TEXTURE_CUBE_MAP, renderTarget.texture, isTargetPowerOfTwo );
  16295. for ( var i = 0; i < 6; i ++ ) {
  16296. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i );
  16297. }
  16298. if ( renderTarget.texture.generateMipmaps && isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  16299. state.bindTexture( _gl.TEXTURE_CUBE_MAP, null );
  16300. } else {
  16301. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  16302. setTextureParameters( _gl.TEXTURE_2D, renderTarget.texture, isTargetPowerOfTwo );
  16303. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_2D );
  16304. if ( renderTarget.texture.generateMipmaps && isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_2D );
  16305. state.bindTexture( _gl.TEXTURE_2D, null );
  16306. }
  16307. // Setup depth and stencil buffers
  16308. if ( renderTarget.depthBuffer ) {
  16309. setupDepthRenderbuffer( renderTarget );
  16310. }
  16311. }
  16312. this.getCurrentRenderTarget = function() {
  16313. return _currentRenderTarget;
  16314. }
  16315. this.setRenderTarget = function ( renderTarget ) {
  16316. _currentRenderTarget = renderTarget;
  16317. if ( renderTarget && properties.get( renderTarget ).__webglFramebuffer === undefined ) {
  16318. setupRenderTarget( renderTarget );
  16319. }
  16320. var isCube = ( renderTarget instanceof THREE.WebGLRenderTargetCube );
  16321. var framebuffer;
  16322. if ( renderTarget ) {
  16323. var renderTargetProperties = properties.get( renderTarget );
  16324. if ( isCube ) {
  16325. framebuffer = renderTargetProperties.__webglFramebuffer[ renderTarget.activeCubeFace ];
  16326. } else {
  16327. framebuffer = renderTargetProperties.__webglFramebuffer;
  16328. }
  16329. _currentScissor.copy( renderTarget.scissor );
  16330. _currentScissorTest = renderTarget.scissorTest;
  16331. _currentViewport.copy( renderTarget.viewport );
  16332. } else {
  16333. framebuffer = null;
  16334. _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio );
  16335. _currentScissorTest = _scissorTest;
  16336. _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio );
  16337. }
  16338. if ( _currentFramebuffer !== framebuffer ) {
  16339. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  16340. _currentFramebuffer = framebuffer;
  16341. }
  16342. state.scissor( _currentScissor );
  16343. state.setScissorTest( _currentScissorTest );
  16344. state.viewport( _currentViewport );
  16345. if ( isCube ) {
  16346. var textureProperties = properties.get( renderTarget.texture );
  16347. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + renderTarget.activeCubeFace, textureProperties.__webglTexture, 0 );
  16348. }
  16349. };
  16350. this.readRenderTargetPixels = function ( renderTarget, x, y, width, height, buffer ) {
  16351. if ( renderTarget instanceof THREE.WebGLRenderTarget === false ) {
  16352. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
  16353. return;
  16354. }
  16355. var framebuffer = properties.get( renderTarget ).__webglFramebuffer;
  16356. if ( framebuffer ) {
  16357. var restore = false;
  16358. if ( framebuffer !== _currentFramebuffer ) {
  16359. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  16360. restore = true;
  16361. }
  16362. try {
  16363. var texture = renderTarget.texture;
  16364. if ( texture.format !== THREE.RGBAFormat
  16365. && paramThreeToGL( texture.format ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_FORMAT ) ) {
  16366. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
  16367. return;
  16368. }
  16369. if ( texture.type !== THREE.UnsignedByteType
  16370. && paramThreeToGL( texture.type ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_TYPE )
  16371. && ! ( texture.type === THREE.FloatType && extensions.get( 'WEBGL_color_buffer_float' ) )
  16372. && ! ( texture.type === THREE.HalfFloatType && extensions.get( 'EXT_color_buffer_half_float' ) ) ) {
  16373. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' );
  16374. return;
  16375. }
  16376. if ( _gl.checkFramebufferStatus( _gl.FRAMEBUFFER ) === _gl.FRAMEBUFFER_COMPLETE ) {
  16377. _gl.readPixels( x, y, width, height, paramThreeToGL( texture.format ), paramThreeToGL( texture.type ), buffer );
  16378. } else {
  16379. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );
  16380. }
  16381. } finally {
  16382. if ( restore ) {
  16383. _gl.bindFramebuffer( _gl.FRAMEBUFFER, _currentFramebuffer );
  16384. }
  16385. }
  16386. }
  16387. };
  16388. function updateRenderTargetMipmap( renderTarget ) {
  16389. var target = renderTarget instanceof THREE.WebGLRenderTargetCube ? _gl.TEXTURE_CUBE_MAP : _gl.TEXTURE_2D;
  16390. var texture = properties.get( renderTarget.texture ).__webglTexture;
  16391. state.bindTexture( target, texture );
  16392. _gl.generateMipmap( target );
  16393. state.bindTexture( target, null );
  16394. }
  16395. // Fallback filters for non-power-of-2 textures
  16396. function filterFallback ( f ) {
  16397. if ( f === THREE.NearestFilter || f === THREE.NearestMipMapNearestFilter || f === THREE.NearestMipMapLinearFilter ) {
  16398. return _gl.NEAREST;
  16399. }
  16400. return _gl.LINEAR;
  16401. }
  16402. // Map three.js constants to WebGL constants
  16403. function paramThreeToGL ( p ) {
  16404. var extension;
  16405. if ( p === THREE.RepeatWrapping ) return _gl.REPEAT;
  16406. if ( p === THREE.ClampToEdgeWrapping ) return _gl.CLAMP_TO_EDGE;
  16407. if ( p === THREE.MirroredRepeatWrapping ) return _gl.MIRRORED_REPEAT;
  16408. if ( p === THREE.NearestFilter ) return _gl.NEAREST;
  16409. if ( p === THREE.NearestMipMapNearestFilter ) return _gl.NEAREST_MIPMAP_NEAREST;
  16410. if ( p === THREE.NearestMipMapLinearFilter ) return _gl.NEAREST_MIPMAP_LINEAR;
  16411. if ( p === THREE.LinearFilter ) return _gl.LINEAR;
  16412. if ( p === THREE.LinearMipMapNearestFilter ) return _gl.LINEAR_MIPMAP_NEAREST;
  16413. if ( p === THREE.LinearMipMapLinearFilter ) return _gl.LINEAR_MIPMAP_LINEAR;
  16414. if ( p === THREE.UnsignedByteType ) return _gl.UNSIGNED_BYTE;
  16415. if ( p === THREE.UnsignedShort4444Type ) return _gl.UNSIGNED_SHORT_4_4_4_4;
  16416. if ( p === THREE.UnsignedShort5551Type ) return _gl.UNSIGNED_SHORT_5_5_5_1;
  16417. if ( p === THREE.UnsignedShort565Type ) return _gl.UNSIGNED_SHORT_5_6_5;
  16418. if ( p === THREE.ByteType ) return _gl.BYTE;
  16419. if ( p === THREE.ShortType ) return _gl.SHORT;
  16420. if ( p === THREE.UnsignedShortType ) return _gl.UNSIGNED_SHORT;
  16421. if ( p === THREE.IntType ) return _gl.INT;
  16422. if ( p === THREE.UnsignedIntType ) return _gl.UNSIGNED_INT;
  16423. if ( p === THREE.FloatType ) return _gl.FLOAT;
  16424. extension = extensions.get( 'OES_texture_half_float' );
  16425. if ( extension !== null ) {
  16426. if ( p === THREE.HalfFloatType ) return extension.HALF_FLOAT_OES;
  16427. }
  16428. if ( p === THREE.AlphaFormat ) return _gl.ALPHA;
  16429. if ( p === THREE.RGBFormat ) return _gl.RGB;
  16430. if ( p === THREE.RGBAFormat ) return _gl.RGBA;
  16431. if ( p === THREE.LuminanceFormat ) return _gl.LUMINANCE;
  16432. if ( p === THREE.LuminanceAlphaFormat ) return _gl.LUMINANCE_ALPHA;
  16433. if ( p === THREE.AddEquation ) return _gl.FUNC_ADD;
  16434. if ( p === THREE.SubtractEquation ) return _gl.FUNC_SUBTRACT;
  16435. if ( p === THREE.ReverseSubtractEquation ) return _gl.FUNC_REVERSE_SUBTRACT;
  16436. if ( p === THREE.ZeroFactor ) return _gl.ZERO;
  16437. if ( p === THREE.OneFactor ) return _gl.ONE;
  16438. if ( p === THREE.SrcColorFactor ) return _gl.SRC_COLOR;
  16439. if ( p === THREE.OneMinusSrcColorFactor ) return _gl.ONE_MINUS_SRC_COLOR;
  16440. if ( p === THREE.SrcAlphaFactor ) return _gl.SRC_ALPHA;
  16441. if ( p === THREE.OneMinusSrcAlphaFactor ) return _gl.ONE_MINUS_SRC_ALPHA;
  16442. if ( p === THREE.DstAlphaFactor ) return _gl.DST_ALPHA;
  16443. if ( p === THREE.OneMinusDstAlphaFactor ) return _gl.ONE_MINUS_DST_ALPHA;
  16444. if ( p === THREE.DstColorFactor ) return _gl.DST_COLOR;
  16445. if ( p === THREE.OneMinusDstColorFactor ) return _gl.ONE_MINUS_DST_COLOR;
  16446. if ( p === THREE.SrcAlphaSaturateFactor ) return _gl.SRC_ALPHA_SATURATE;
  16447. extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );
  16448. if ( extension !== null ) {
  16449. if ( p === THREE.RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  16450. if ( p === THREE.RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  16451. if ( p === THREE.RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  16452. if ( p === THREE.RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  16453. }
  16454. extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  16455. if ( extension !== null ) {
  16456. if ( p === THREE.RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  16457. if ( p === THREE.RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  16458. if ( p === THREE.RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  16459. if ( p === THREE.RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  16460. }
  16461. extension = extensions.get( 'WEBGL_compressed_texture_etc1' );
  16462. if ( extension !== null ) {
  16463. if ( p === THREE.RGB_ETC1_Format ) return extension.COMPRESSED_RGB_ETC1_WEBGL;
  16464. }
  16465. extension = extensions.get( 'EXT_blend_minmax' );
  16466. if ( extension !== null ) {
  16467. if ( p === THREE.MinEquation ) return extension.MIN_EXT;
  16468. if ( p === THREE.MaxEquation ) return extension.MAX_EXT;
  16469. }
  16470. return 0;
  16471. }
  16472. };
  16473. // File:src/renderers/WebGLRenderTarget.js
  16474. /**
  16475. * @author szimek / https://github.com/szimek/
  16476. * @author alteredq / http://alteredqualia.com/
  16477. * @author Marius Kintel / https://github.com/kintel
  16478. */
  16479. /*
  16480. In options, we can specify:
  16481. * Texture parameters for an auto-generated target texture
  16482. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  16483. */
  16484. THREE.WebGLRenderTarget = function ( width, height, options ) {
  16485. this.uuid = THREE.Math.generateUUID();
  16486. this.width = width;
  16487. this.height = height;
  16488. this.scissor = new THREE.Vector4( 0, 0, width, height );
  16489. this.scissorTest = false;
  16490. this.viewport = new THREE.Vector4( 0, 0, width, height );
  16491. options = options || {};
  16492. if ( options.minFilter === undefined ) options.minFilter = THREE.LinearFilter;
  16493. this.texture = new THREE.Texture( undefined, undefined, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy );
  16494. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  16495. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;
  16496. };
  16497. THREE.WebGLRenderTarget.prototype = {
  16498. constructor: THREE.WebGLRenderTarget,
  16499. setSize: function ( width, height ) {
  16500. if ( this.width !== width || this.height !== height ) {
  16501. this.width = width;
  16502. this.height = height;
  16503. this.dispose();
  16504. }
  16505. this.viewport.set( 0, 0, width, height );
  16506. this.scissor.set( 0, 0, width, height );
  16507. },
  16508. clone: function () {
  16509. return new this.constructor().copy( this );
  16510. },
  16511. copy: function ( source ) {
  16512. this.width = source.width;
  16513. this.height = source.height;
  16514. this.viewport.copy( source.viewport );
  16515. this.texture = source.texture.clone();
  16516. this.depthBuffer = source.depthBuffer;
  16517. this.stencilBuffer = source.stencilBuffer;
  16518. this.shareDepthFrom = source.shareDepthFrom;
  16519. return this;
  16520. },
  16521. dispose: function () {
  16522. this.dispatchEvent( { type: 'dispose' } );
  16523. }
  16524. };
  16525. THREE.EventDispatcher.prototype.apply( THREE.WebGLRenderTarget.prototype );
  16526. // File:src/renderers/WebGLRenderTargetCube.js
  16527. /**
  16528. * @author alteredq / http://alteredqualia.com
  16529. */
  16530. THREE.WebGLRenderTargetCube = function ( width, height, options ) {
  16531. THREE.WebGLRenderTarget.call( this, width, height, options );
  16532. this.activeCubeFace = 0; // PX 0, NX 1, PY 2, NY 3, PZ 4, NZ 5
  16533. };
  16534. THREE.WebGLRenderTargetCube.prototype = Object.create( THREE.WebGLRenderTarget.prototype );
  16535. THREE.WebGLRenderTargetCube.prototype.constructor = THREE.WebGLRenderTargetCube;
  16536. // File:src/renderers/webgl/WebGLBufferRenderer.js
  16537. /**
  16538. * @author mrdoob / http://mrdoob.com/
  16539. */
  16540. THREE.WebGLBufferRenderer = function ( _gl, extensions, _infoRender ) {
  16541. var mode;
  16542. function setMode( value ) {
  16543. mode = value;
  16544. }
  16545. function render( start, count ) {
  16546. _gl.drawArrays( mode, start, count );
  16547. _infoRender.calls ++;
  16548. _infoRender.vertices += count;
  16549. if ( mode === _gl.TRIANGLES ) _infoRender.faces += count / 3;
  16550. }
  16551. function renderInstances( geometry ) {
  16552. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  16553. if ( extension === null ) {
  16554. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  16555. return;
  16556. }
  16557. var position = geometry.attributes.position;
  16558. var count = 0;
  16559. if ( position instanceof THREE.InterleavedBufferAttribute ) {
  16560. count = position.data.count;
  16561. extension.drawArraysInstancedANGLE( mode, 0, count, geometry.maxInstancedCount );
  16562. } else {
  16563. count = position.count;
  16564. extension.drawArraysInstancedANGLE( mode, 0, count, geometry.maxInstancedCount );
  16565. }
  16566. _infoRender.calls ++;
  16567. _infoRender.vertices += count * geometry.maxInstancedCount;
  16568. if ( mode === _gl.TRIANGLES ) _infoRender.faces += geometry.maxInstancedCount * count / 3;
  16569. }
  16570. this.setMode = setMode;
  16571. this.render = render;
  16572. this.renderInstances = renderInstances;
  16573. };
  16574. // File:src/renderers/webgl/WebGLIndexedBufferRenderer.js
  16575. /**
  16576. * @author mrdoob / http://mrdoob.com/
  16577. */
  16578. THREE.WebGLIndexedBufferRenderer = function ( _gl, extensions, _infoRender ) {
  16579. var mode;
  16580. function setMode( value ) {
  16581. mode = value;
  16582. }
  16583. var type, size;
  16584. function setIndex( index ) {
  16585. if ( index.array instanceof Uint32Array && extensions.get( 'OES_element_index_uint' ) ) {
  16586. type = _gl.UNSIGNED_INT;
  16587. size = 4;
  16588. } else {
  16589. type = _gl.UNSIGNED_SHORT;
  16590. size = 2;
  16591. }
  16592. }
  16593. function render( start, count ) {
  16594. _gl.drawElements( mode, count, type, start * size );
  16595. _infoRender.calls ++;
  16596. _infoRender.vertices += count;
  16597. if ( mode === _gl.TRIANGLES ) _infoRender.faces += count / 3;
  16598. }
  16599. function renderInstances( geometry, start, count ) {
  16600. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  16601. if ( extension === null ) {
  16602. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  16603. return;
  16604. }
  16605. extension.drawElementsInstancedANGLE( mode, count, type, start * size, geometry.maxInstancedCount );
  16606. _infoRender.calls ++;
  16607. _infoRender.vertices += count * geometry.maxInstancedCount;
  16608. if ( mode === _gl.TRIANGLES ) _infoRender.faces += geometry.maxInstancedCount * count / 3;
  16609. }
  16610. this.setMode = setMode;
  16611. this.setIndex = setIndex;
  16612. this.render = render;
  16613. this.renderInstances = renderInstances;
  16614. };
  16615. // File:src/renderers/webgl/WebGLExtensions.js
  16616. /**
  16617. * @author mrdoob / http://mrdoob.com/
  16618. */
  16619. THREE.WebGLExtensions = function ( gl ) {
  16620. var extensions = {};
  16621. this.get = function ( name ) {
  16622. if ( extensions[ name ] !== undefined ) {
  16623. return extensions[ name ];
  16624. }
  16625. var extension;
  16626. switch ( name ) {
  16627. case 'EXT_texture_filter_anisotropic':
  16628. extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' );
  16629. break;
  16630. case 'WEBGL_compressed_texture_s3tc':
  16631. extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' );
  16632. break;
  16633. case 'WEBGL_compressed_texture_pvrtc':
  16634. extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' );
  16635. break;
  16636. case 'WEBGL_compressed_texture_etc1':
  16637. extension = gl.getExtension( 'WEBGL_compressed_texture_etc1' );
  16638. break;
  16639. default:
  16640. extension = gl.getExtension( name );
  16641. }
  16642. if ( extension === null ) {
  16643. console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
  16644. }
  16645. extensions[ name ] = extension;
  16646. return extension;
  16647. };
  16648. };
  16649. // File:src/renderers/webgl/WebGLCapabilities.js
  16650. THREE.WebGLCapabilities = function ( gl, extensions, parameters ) {
  16651. function getMaxPrecision( precision ) {
  16652. if ( precision === 'highp' ) {
  16653. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.HIGH_FLOAT ).precision > 0 &&
  16654. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.HIGH_FLOAT ).precision > 0 ) {
  16655. return 'highp';
  16656. }
  16657. precision = 'mediump';
  16658. }
  16659. if ( precision === 'mediump' ) {
  16660. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.MEDIUM_FLOAT ).precision > 0 &&
  16661. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.MEDIUM_FLOAT ).precision > 0 ) {
  16662. return 'mediump';
  16663. }
  16664. }
  16665. return 'lowp';
  16666. }
  16667. this.getMaxPrecision = getMaxPrecision;
  16668. this.precision = parameters.precision !== undefined ? parameters.precision : 'highp',
  16669. this.logarithmicDepthBuffer = parameters.logarithmicDepthBuffer !== undefined ? parameters.logarithmicDepthBuffer : false;
  16670. this.maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
  16671. this.maxVertexTextures = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS );
  16672. this.maxTextureSize = gl.getParameter( gl.MAX_TEXTURE_SIZE );
  16673. this.maxCubemapSize = gl.getParameter( gl.MAX_CUBE_MAP_TEXTURE_SIZE );
  16674. this.maxAttributes = gl.getParameter( gl.MAX_VERTEX_ATTRIBS );
  16675. this.maxVertexUniforms = gl.getParameter( gl.MAX_VERTEX_UNIFORM_VECTORS );
  16676. this.maxVaryings = gl.getParameter( gl.MAX_VARYING_VECTORS );
  16677. this.maxFragmentUniforms = gl.getParameter( gl.MAX_FRAGMENT_UNIFORM_VECTORS );
  16678. this.vertexTextures = this.maxVertexTextures > 0;
  16679. this.floatFragmentTextures = !! extensions.get( 'OES_texture_float' );
  16680. this.floatVertexTextures = this.vertexTextures && this.floatFragmentTextures;
  16681. var _maxPrecision = getMaxPrecision( this.precision );
  16682. if ( _maxPrecision !== this.precision ) {
  16683. console.warn( 'THREE.WebGLRenderer:', this.precision, 'not supported, using', _maxPrecision, 'instead.' );
  16684. this.precision = _maxPrecision;
  16685. }
  16686. if ( this.logarithmicDepthBuffer ) {
  16687. this.logarithmicDepthBuffer = !! extensions.get( 'EXT_frag_depth' );
  16688. }
  16689. };
  16690. // File:src/renderers/webgl/WebGLGeometries.js
  16691. /**
  16692. * @author mrdoob / http://mrdoob.com/
  16693. */
  16694. THREE.WebGLGeometries = function ( gl, properties, info ) {
  16695. var geometries = {};
  16696. function get( object ) {
  16697. var geometry = object.geometry;
  16698. if ( geometries[ geometry.id ] !== undefined ) {
  16699. return geometries[ geometry.id ];
  16700. }
  16701. geometry.addEventListener( 'dispose', onGeometryDispose );
  16702. var buffergeometry;
  16703. if ( geometry instanceof THREE.BufferGeometry ) {
  16704. buffergeometry = geometry;
  16705. } else if ( geometry instanceof THREE.Geometry ) {
  16706. if ( geometry._bufferGeometry === undefined ) {
  16707. geometry._bufferGeometry = new THREE.BufferGeometry().setFromObject( object );
  16708. }
  16709. buffergeometry = geometry._bufferGeometry;
  16710. }
  16711. geometries[ geometry.id ] = buffergeometry;
  16712. info.memory.geometries ++;
  16713. return buffergeometry;
  16714. }
  16715. function onGeometryDispose( event ) {
  16716. var geometry = event.target;
  16717. var buffergeometry = geometries[ geometry.id ];
  16718. if ( buffergeometry.index !== null ) {
  16719. deleteAttribute( buffergeometry.index );
  16720. }
  16721. deleteAttributes( buffergeometry.attributes );
  16722. geometry.removeEventListener( 'dispose', onGeometryDispose );
  16723. delete geometries[ geometry.id ];
  16724. // TODO
  16725. var property = properties.get( geometry );
  16726. if ( property.wireframe ) {
  16727. deleteAttribute( property.wireframe );
  16728. }
  16729. properties.delete( geometry );
  16730. var bufferproperty = properties.get( buffergeometry );
  16731. if ( bufferproperty.wireframe ) {
  16732. deleteAttribute( bufferproperty.wireframe );
  16733. }
  16734. properties.delete( buffergeometry );
  16735. //
  16736. info.memory.geometries --;
  16737. }
  16738. function getAttributeBuffer( attribute ) {
  16739. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  16740. return properties.get( attribute.data ).__webglBuffer;
  16741. }
  16742. return properties.get( attribute ).__webglBuffer;
  16743. }
  16744. function deleteAttribute( attribute ) {
  16745. var buffer = getAttributeBuffer( attribute );
  16746. if ( buffer !== undefined ) {
  16747. gl.deleteBuffer( buffer );
  16748. removeAttributeBuffer( attribute );
  16749. }
  16750. }
  16751. function deleteAttributes( attributes ) {
  16752. for ( var name in attributes ) {
  16753. deleteAttribute( attributes[ name ] );
  16754. }
  16755. }
  16756. function removeAttributeBuffer( attribute ) {
  16757. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  16758. properties.delete( attribute.data );
  16759. } else {
  16760. properties.delete( attribute );
  16761. }
  16762. }
  16763. this.get = get;
  16764. };
  16765. // File:src/renderers/webgl/WebGLLights.js
  16766. /**
  16767. * @author mrdoob / http://mrdoob.com/
  16768. */
  16769. THREE.WebGLLights = function () {
  16770. var lights = {};
  16771. this.get = function ( light ) {
  16772. if ( lights[ light.id ] !== undefined ) {
  16773. return lights[ light.id ];
  16774. }
  16775. var uniforms;
  16776. switch ( light.type ) {
  16777. case 'DirectionalLight':
  16778. uniforms = {
  16779. direction: new THREE.Vector3(),
  16780. color: new THREE.Color(),
  16781. shadow: false,
  16782. shadowBias: 0,
  16783. shadowRadius: 1,
  16784. shadowMapSize: new THREE.Vector2()
  16785. };
  16786. break;
  16787. case 'SpotLight':
  16788. uniforms = {
  16789. position: new THREE.Vector3(),
  16790. direction: new THREE.Vector3(),
  16791. color: new THREE.Color(),
  16792. distance: 0,
  16793. coneCos: 0,
  16794. penumbraCos: 0,
  16795. decay: 0,
  16796. shadow: false,
  16797. shadowBias: 0,
  16798. shadowRadius: 1,
  16799. shadowMapSize: new THREE.Vector2()
  16800. };
  16801. break;
  16802. case 'PointLight':
  16803. uniforms = {
  16804. position: new THREE.Vector3(),
  16805. color: new THREE.Color(),
  16806. distance: 0,
  16807. decay: 0,
  16808. shadow: false,
  16809. shadowBias: 0,
  16810. shadowRadius: 1,
  16811. shadowMapSize: new THREE.Vector2()
  16812. };
  16813. break;
  16814. case 'HemisphereLight':
  16815. uniforms = {
  16816. direction: new THREE.Vector3(),
  16817. skyColor: new THREE.Color(),
  16818. groundColor: new THREE.Color()
  16819. };
  16820. break;
  16821. }
  16822. lights[ light.id ] = uniforms;
  16823. return uniforms;
  16824. };
  16825. };
  16826. // File:src/renderers/webgl/WebGLObjects.js
  16827. /**
  16828. * @author mrdoob / http://mrdoob.com/
  16829. */
  16830. THREE.WebGLObjects = function ( gl, properties, info ) {
  16831. var geometries = new THREE.WebGLGeometries( gl, properties, info );
  16832. //
  16833. function update( object ) {
  16834. // TODO: Avoid updating twice (when using shadowMap). Maybe add frame counter.
  16835. var geometry = geometries.get( object );
  16836. if ( object.geometry instanceof THREE.Geometry ) {
  16837. geometry.updateFromObject( object );
  16838. }
  16839. var index = geometry.index;
  16840. var attributes = geometry.attributes;
  16841. if ( index !== null ) {
  16842. updateAttribute( index, gl.ELEMENT_ARRAY_BUFFER );
  16843. }
  16844. for ( var name in attributes ) {
  16845. updateAttribute( attributes[ name ], gl.ARRAY_BUFFER );
  16846. }
  16847. // morph targets
  16848. var morphAttributes = geometry.morphAttributes;
  16849. for ( var name in morphAttributes ) {
  16850. var array = morphAttributes[ name ];
  16851. for ( var i = 0, l = array.length; i < l; i ++ ) {
  16852. updateAttribute( array[ i ], gl.ARRAY_BUFFER );
  16853. }
  16854. }
  16855. return geometry;
  16856. }
  16857. function updateAttribute( attribute, bufferType ) {
  16858. var data = ( attribute instanceof THREE.InterleavedBufferAttribute ) ? attribute.data : attribute;
  16859. var attributeProperties = properties.get( data );
  16860. if ( attributeProperties.__webglBuffer === undefined ) {
  16861. createBuffer( attributeProperties, data, bufferType );
  16862. } else if ( attributeProperties.version !== data.version ) {
  16863. updateBuffer( attributeProperties, data, bufferType );
  16864. }
  16865. }
  16866. function createBuffer( attributeProperties, data, bufferType ) {
  16867. attributeProperties.__webglBuffer = gl.createBuffer();
  16868. gl.bindBuffer( bufferType, attributeProperties.__webglBuffer );
  16869. var usage = data.dynamic ? gl.DYNAMIC_DRAW : gl.STATIC_DRAW;
  16870. gl.bufferData( bufferType, data.array, usage );
  16871. attributeProperties.version = data.version;
  16872. }
  16873. function updateBuffer( attributeProperties, data, bufferType ) {
  16874. gl.bindBuffer( bufferType, attributeProperties.__webglBuffer );
  16875. if ( data.dynamic === false || data.updateRange.count === - 1 ) {
  16876. // Not using update ranges
  16877. gl.bufferSubData( bufferType, 0, data.array );
  16878. } else if ( data.updateRange.count === 0 ) {
  16879. 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.' );
  16880. } else {
  16881. gl.bufferSubData( bufferType, data.updateRange.offset * data.array.BYTES_PER_ELEMENT,
  16882. data.array.subarray( data.updateRange.offset, data.updateRange.offset + data.updateRange.count ) );
  16883. data.updateRange.count = 0; // reset range
  16884. }
  16885. attributeProperties.version = data.version;
  16886. }
  16887. function getAttributeBuffer( attribute ) {
  16888. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  16889. return properties.get( attribute.data ).__webglBuffer;
  16890. }
  16891. return properties.get( attribute ).__webglBuffer;
  16892. }
  16893. function getWireframeAttribute( geometry ) {
  16894. var property = properties.get( geometry );
  16895. if ( property.wireframe !== undefined ) {
  16896. return property.wireframe;
  16897. }
  16898. var indices = [];
  16899. var index = geometry.index;
  16900. var attributes = geometry.attributes;
  16901. var position = attributes.position;
  16902. // console.time( 'wireframe' );
  16903. if ( index !== null ) {
  16904. var edges = {};
  16905. var array = index.array;
  16906. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  16907. var a = array[ i + 0 ];
  16908. var b = array[ i + 1 ];
  16909. var c = array[ i + 2 ];
  16910. if ( checkEdge( edges, a, b ) ) indices.push( a, b );
  16911. if ( checkEdge( edges, b, c ) ) indices.push( b, c );
  16912. if ( checkEdge( edges, c, a ) ) indices.push( c, a );
  16913. }
  16914. } else {
  16915. var array = attributes.position.array;
  16916. for ( var i = 0, l = ( array.length / 3 ) - 1; i < l; i += 3 ) {
  16917. var a = i + 0;
  16918. var b = i + 1;
  16919. var c = i + 2;
  16920. indices.push( a, b, b, c, c, a );
  16921. }
  16922. }
  16923. // console.timeEnd( 'wireframe' );
  16924. var TypeArray = position.count > 65535 ? Uint32Array : Uint16Array;
  16925. var attribute = new THREE.BufferAttribute( new TypeArray( indices ), 1 );
  16926. updateAttribute( attribute, gl.ELEMENT_ARRAY_BUFFER );
  16927. property.wireframe = attribute;
  16928. return attribute;
  16929. }
  16930. function checkEdge( edges, a, b ) {
  16931. if ( a > b ) {
  16932. var tmp = a;
  16933. a = b;
  16934. b = tmp;
  16935. }
  16936. var list = edges[ a ];
  16937. if ( list === undefined ) {
  16938. edges[ a ] = [ b ];
  16939. return true;
  16940. } else if ( list.indexOf( b ) === -1 ) {
  16941. list.push( b );
  16942. return true;
  16943. }
  16944. return false;
  16945. }
  16946. this.getAttributeBuffer = getAttributeBuffer;
  16947. this.getWireframeAttribute = getWireframeAttribute;
  16948. this.update = update;
  16949. };
  16950. // File:src/renderers/webgl/WebGLProgram.js
  16951. THREE.WebGLProgram = ( function () {
  16952. var programIdCount = 0;
  16953. // TODO: Combine the regex
  16954. var structRe = /^([\w\d_]+)\.([\w\d_]+)$/;
  16955. var arrayStructRe = /^([\w\d_]+)\[(\d+)\]\.([\w\d_]+)$/;
  16956. var arrayRe = /^([\w\d_]+)\[0\]$/;
  16957. function getEncodingComponents( encoding ) {
  16958. switch ( encoding ) {
  16959. case THREE.LinearEncoding:
  16960. return [ 'Linear','( value )' ];
  16961. case THREE.sRGBEncoding:
  16962. return [ 'sRGB','( value )' ];
  16963. case THREE.RGBEEncoding:
  16964. return [ 'RGBE','( value )' ];
  16965. case THREE.RGBM7Encoding:
  16966. return [ 'RGBM','( value, 7.0 )' ];
  16967. case THREE.RGBM16Encoding:
  16968. return [ 'RGBM','( value, 16.0 )' ];
  16969. case THREE.RGBDEncoding:
  16970. return [ 'RGBD','( value, 256.0 )' ];
  16971. case THREE.GammaEncoding:
  16972. return [ 'Gamma','( value, float( GAMMA_FACTOR ) )' ];
  16973. default:
  16974. throw new Error( 'unsupported encoding: ' + encoding );
  16975. }
  16976. }
  16977. function getTexelDecodingFunction( functionName, encoding ) {
  16978. var components = getEncodingComponents( encoding );
  16979. return "vec4 " + functionName + "( vec4 value ) { return " + components[ 0 ] + "ToLinear" + components[ 1 ] + "; }";
  16980. }
  16981. function getTexelEncodingFunction( functionName, encoding ) {
  16982. var components = getEncodingComponents( encoding );
  16983. return "vec4 " + functionName + "( vec4 value ) { return LinearTo" + components[ 0 ] + components[ 1 ] + "; }";
  16984. }
  16985. function getToneMappingFunction( functionName, toneMapping ) {
  16986. var toneMappingName;
  16987. switch ( toneMapping ) {
  16988. case THREE.LinearToneMapping:
  16989. toneMappingName = "Linear";
  16990. break;
  16991. case THREE.ReinhardToneMapping:
  16992. toneMappingName = "Reinhard";
  16993. break;
  16994. case THREE.Uncharted2ToneMapping:
  16995. toneMappingName = "Uncharted2";
  16996. break;
  16997. case THREE.CineonToneMapping:
  16998. toneMappingName = "OptimizedCineon";
  16999. break;
  17000. default:
  17001. throw new Error( 'unsupported toneMapping: ' + toneMapping );
  17002. }
  17003. return "vec3 " + functionName + "( vec3 color ) { return " + toneMappingName + "ToneMapping( color ); }";
  17004. }
  17005. function generateExtensions( extensions, parameters, rendererExtensions ) {
  17006. extensions = extensions || {};
  17007. var chunks = [
  17008. ( extensions.derivatives || parameters.envMapCubeUV || parameters.bumpMap || parameters.normalMap || parameters.flatShading ) ? '#extension GL_OES_standard_derivatives : enable' : '',
  17009. ( extensions.fragDepth || parameters.logarithmicDepthBuffer ) && rendererExtensions.get( 'EXT_frag_depth' ) ? '#extension GL_EXT_frag_depth : enable' : '',
  17010. ( extensions.drawBuffers ) && rendererExtensions.get( 'WEBGL_draw_buffers' ) ? '#extension GL_EXT_draw_buffers : require' : '',
  17011. ( extensions.shaderTextureLOD || parameters.envMap ) && rendererExtensions.get( 'EXT_shader_texture_lod' ) ? '#extension GL_EXT_shader_texture_lod : enable' : '',
  17012. ];
  17013. return chunks.filter( filterEmptyLine ).join( '\n' );
  17014. }
  17015. function generateDefines( defines ) {
  17016. var chunks = [];
  17017. for ( var name in defines ) {
  17018. var value = defines[ name ];
  17019. if ( value === false ) continue;
  17020. chunks.push( '#define ' + name + ' ' + value );
  17021. }
  17022. return chunks.join( '\n' );
  17023. }
  17024. function fetchUniformLocations( gl, program, identifiers ) {
  17025. var uniforms = {};
  17026. var n = gl.getProgramParameter( program, gl.ACTIVE_UNIFORMS );
  17027. for ( var i = 0; i < n; i ++ ) {
  17028. var info = gl.getActiveUniform( program, i );
  17029. var name = info.name;
  17030. var location = gl.getUniformLocation( program, name );
  17031. //console.log("THREE.WebGLProgram: ACTIVE UNIFORM:", name);
  17032. var matches = structRe.exec( name );
  17033. if ( matches ) {
  17034. var structName = matches[ 1 ];
  17035. var structProperty = matches[ 2 ];
  17036. var uniformsStruct = uniforms[ structName ];
  17037. if ( ! uniformsStruct ) {
  17038. uniformsStruct = uniforms[ structName ] = {};
  17039. }
  17040. uniformsStruct[ structProperty ] = location;
  17041. continue;
  17042. }
  17043. matches = arrayStructRe.exec( name );
  17044. if ( matches ) {
  17045. var arrayName = matches[ 1 ];
  17046. var arrayIndex = matches[ 2 ];
  17047. var arrayProperty = matches[ 3 ];
  17048. var uniformsArray = uniforms[ arrayName ];
  17049. if ( ! uniformsArray ) {
  17050. uniformsArray = uniforms[ arrayName ] = [];
  17051. }
  17052. var uniformsArrayIndex = uniformsArray[ arrayIndex ];
  17053. if ( ! uniformsArrayIndex ) {
  17054. uniformsArrayIndex = uniformsArray[ arrayIndex ] = {};
  17055. }
  17056. uniformsArrayIndex[ arrayProperty ] = location;
  17057. continue;
  17058. }
  17059. matches = arrayRe.exec( name );
  17060. if ( matches ) {
  17061. var arrayName = matches[ 1 ];
  17062. uniforms[ arrayName ] = location;
  17063. continue;
  17064. }
  17065. uniforms[ name ] = location;
  17066. }
  17067. return uniforms;
  17068. }
  17069. function fetchAttributeLocations( gl, program, identifiers ) {
  17070. var attributes = {};
  17071. var n = gl.getProgramParameter( program, gl.ACTIVE_ATTRIBUTES );
  17072. for ( var i = 0; i < n; i ++ ) {
  17073. var info = gl.getActiveAttrib( program, i );
  17074. var name = info.name;
  17075. // console.log("THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:", name, i );
  17076. attributes[ name ] = gl.getAttribLocation( program, name );
  17077. }
  17078. return attributes;
  17079. }
  17080. function filterEmptyLine( string ) {
  17081. return string !== '';
  17082. }
  17083. function replaceLightNums( string, parameters ) {
  17084. return string
  17085. .replace( /NUM_DIR_LIGHTS/g, parameters.numDirLights )
  17086. .replace( /NUM_SPOT_LIGHTS/g, parameters.numSpotLights )
  17087. .replace( /NUM_POINT_LIGHTS/g, parameters.numPointLights )
  17088. .replace( /NUM_HEMI_LIGHTS/g, parameters.numHemiLights );
  17089. }
  17090. function parseIncludes( string ) {
  17091. var pattern = /#include +<([\w\d.]+)>/g;
  17092. function replace( match, include ) {
  17093. var replace = THREE.ShaderChunk[ include ];
  17094. if ( replace === undefined ) {
  17095. throw new Error( 'Can not resolve #include <' + include + '>' );
  17096. }
  17097. return parseIncludes( replace );
  17098. }
  17099. return string.replace( pattern, replace );
  17100. }
  17101. function unrollLoops( string ) {
  17102. var pattern = /for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  17103. function replace( match, start, end, snippet ) {
  17104. var unroll = '';
  17105. for ( var i = parseInt( start ); i < parseInt( end ); i ++ ) {
  17106. unroll += snippet.replace( /\[ i \]/g, '[ ' + i + ' ]' );
  17107. }
  17108. return unroll;
  17109. }
  17110. return string.replace( pattern, replace );
  17111. }
  17112. return function WebGLProgram( renderer, code, material, parameters ) {
  17113. var gl = renderer.context;
  17114. var extensions = material.extensions;
  17115. var defines = material.defines;
  17116. var vertexShader = material.__webglShader.vertexShader;
  17117. var fragmentShader = material.__webglShader.fragmentShader;
  17118. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  17119. if ( parameters.shadowMapType === THREE.PCFShadowMap ) {
  17120. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  17121. } else if ( parameters.shadowMapType === THREE.PCFSoftShadowMap ) {
  17122. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  17123. }
  17124. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  17125. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  17126. var envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  17127. if ( parameters.envMap ) {
  17128. switch ( material.envMap.mapping ) {
  17129. case THREE.CubeReflectionMapping:
  17130. case THREE.CubeRefractionMapping:
  17131. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  17132. break;
  17133. case THREE.CubeUVReflectionMapping:
  17134. case THREE.CubeUVRefractionMapping:
  17135. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  17136. break;
  17137. case THREE.EquirectangularReflectionMapping:
  17138. case THREE.EquirectangularRefractionMapping:
  17139. envMapTypeDefine = 'ENVMAP_TYPE_EQUIREC';
  17140. break;
  17141. case THREE.SphericalReflectionMapping:
  17142. envMapTypeDefine = 'ENVMAP_TYPE_SPHERE';
  17143. break;
  17144. }
  17145. switch ( material.envMap.mapping ) {
  17146. case THREE.CubeRefractionMapping:
  17147. case THREE.EquirectangularRefractionMapping:
  17148. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  17149. break;
  17150. }
  17151. switch ( material.combine ) {
  17152. case THREE.MultiplyOperation:
  17153. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  17154. break;
  17155. case THREE.MixOperation:
  17156. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  17157. break;
  17158. case THREE.AddOperation:
  17159. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  17160. break;
  17161. }
  17162. }
  17163. var gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
  17164. // console.log( 'building new program ' );
  17165. //
  17166. var customExtensions = generateExtensions( extensions, parameters, renderer.extensions );
  17167. var customDefines = generateDefines( defines );
  17168. //
  17169. var program = gl.createProgram();
  17170. var prefixVertex, prefixFragment;
  17171. if ( material instanceof THREE.RawShaderMaterial ) {
  17172. prefixVertex = '';
  17173. prefixFragment = '';
  17174. } else {
  17175. prefixVertex = [
  17176. 'precision ' + parameters.precision + ' float;',
  17177. 'precision ' + parameters.precision + ' int;',
  17178. '#define SHADER_NAME ' + material.__webglShader.name,
  17179. customDefines,
  17180. parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '',
  17181. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  17182. '#define MAX_BONES ' + parameters.maxBones,
  17183. parameters.map ? '#define USE_MAP' : '',
  17184. parameters.envMap ? '#define USE_ENVMAP' : '',
  17185. parameters.envMap ? '#define ' + envMapModeDefine : '',
  17186. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  17187. parameters.aoMap ? '#define USE_AOMAP' : '',
  17188. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  17189. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  17190. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  17191. parameters.displacementMap && parameters.supportsVertexTextures ? '#define USE_DISPLACEMENTMAP' : '',
  17192. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  17193. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  17194. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  17195. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  17196. parameters.vertexColors ? '#define USE_COLOR' : '',
  17197. parameters.flatShading ? '#define FLAT_SHADED' : '',
  17198. parameters.skinning ? '#define USE_SKINNING' : '',
  17199. parameters.useVertexTexture ? '#define BONE_TEXTURE' : '',
  17200. parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
  17201. parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '',
  17202. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  17203. parameters.flipSided ? '#define FLIP_SIDED' : '',
  17204. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  17205. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  17206. parameters.pointLightShadows > 0 ? '#define POINT_LIGHT_SHADOWS' : '',
  17207. parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
  17208. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  17209. parameters.logarithmicDepthBuffer && renderer.extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  17210. 'uniform mat4 modelMatrix;',
  17211. 'uniform mat4 modelViewMatrix;',
  17212. 'uniform mat4 projectionMatrix;',
  17213. 'uniform mat4 viewMatrix;',
  17214. 'uniform mat3 normalMatrix;',
  17215. 'uniform vec3 cameraPosition;',
  17216. 'attribute vec3 position;',
  17217. 'attribute vec3 normal;',
  17218. 'attribute vec2 uv;',
  17219. '#ifdef USE_COLOR',
  17220. ' attribute vec3 color;',
  17221. '#endif',
  17222. '#ifdef USE_MORPHTARGETS',
  17223. ' attribute vec3 morphTarget0;',
  17224. ' attribute vec3 morphTarget1;',
  17225. ' attribute vec3 morphTarget2;',
  17226. ' attribute vec3 morphTarget3;',
  17227. ' #ifdef USE_MORPHNORMALS',
  17228. ' attribute vec3 morphNormal0;',
  17229. ' attribute vec3 morphNormal1;',
  17230. ' attribute vec3 morphNormal2;',
  17231. ' attribute vec3 morphNormal3;',
  17232. ' #else',
  17233. ' attribute vec3 morphTarget4;',
  17234. ' attribute vec3 morphTarget5;',
  17235. ' attribute vec3 morphTarget6;',
  17236. ' attribute vec3 morphTarget7;',
  17237. ' #endif',
  17238. '#endif',
  17239. '#ifdef USE_SKINNING',
  17240. ' attribute vec4 skinIndex;',
  17241. ' attribute vec4 skinWeight;',
  17242. '#endif',
  17243. '\n'
  17244. ].filter( filterEmptyLine ).join( '\n' );
  17245. prefixFragment = [
  17246. customExtensions,
  17247. 'precision ' + parameters.precision + ' float;',
  17248. 'precision ' + parameters.precision + ' int;',
  17249. '#define SHADER_NAME ' + material.__webglShader.name,
  17250. customDefines,
  17251. parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest : '',
  17252. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  17253. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  17254. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  17255. parameters.map ? '#define USE_MAP' : '',
  17256. parameters.envMap ? '#define USE_ENVMAP' : '',
  17257. parameters.envMap ? '#define ' + envMapTypeDefine : '',
  17258. parameters.envMap ? '#define ' + envMapModeDefine : '',
  17259. parameters.envMap ? '#define ' + envMapBlendingDefine : '',
  17260. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  17261. parameters.aoMap ? '#define USE_AOMAP' : '',
  17262. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  17263. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  17264. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  17265. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  17266. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  17267. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  17268. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  17269. parameters.vertexColors ? '#define USE_COLOR' : '',
  17270. parameters.flatShading ? '#define FLAT_SHADED' : '',
  17271. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  17272. parameters.flipSided ? '#define FLIP_SIDED' : '',
  17273. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  17274. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  17275. parameters.pointLightShadows > 0 ? '#define POINT_LIGHT_SHADOWS' : '',
  17276. parameters.premultipliedAlpha ? "#define PREMULTIPLIED_ALPHA" : '',
  17277. parameters.physicallyCorrectLights ? "#define PHYSICALLY_CORRECT_LIGHTS" : '',
  17278. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  17279. parameters.logarithmicDepthBuffer && renderer.extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  17280. parameters.envMap && renderer.extensions.get( 'EXT_shader_texture_lod' ) ? '#define TEXTURE_LOD_EXT' : '',
  17281. 'uniform mat4 viewMatrix;',
  17282. 'uniform vec3 cameraPosition;',
  17283. ( parameters.toneMapping !== THREE.NoToneMapping ) ? "#define TONE_MAPPING" : '',
  17284. ( parameters.toneMapping !== THREE.NoToneMapping ) ? THREE.ShaderChunk[ 'tonemapping_pars_fragment' ] : '', // this code is required here because it is used by the toneMapping() function defined below
  17285. ( parameters.toneMapping !== THREE.NoToneMapping ) ? getToneMappingFunction( "toneMapping", parameters.toneMapping ) : '',
  17286. ( parameters.outputEncoding || parameters.mapEncoding || parameters.envMapEncoding || parameters.emissiveMapEncoding ) ? THREE.ShaderChunk[ 'encodings_pars_fragment' ] : '', // this code is required here because it is used by the various encoding/decoding function defined below
  17287. parameters.mapEncoding ? getTexelDecodingFunction( 'mapTexelToLinear', parameters.mapEncoding ) : '',
  17288. parameters.envMapEncoding ? getTexelDecodingFunction( 'envMapTexelToLinear', parameters.envMapEncoding ) : '',
  17289. parameters.emissiveMapEncoding ? getTexelDecodingFunction( 'emissiveMapTexelToLinear', parameters.emissiveMapEncoding ) : '',
  17290. parameters.outputEncoding ? getTexelEncodingFunction( "linearToOutputTexel", parameters.outputEncoding ) : '',
  17291. '\n'
  17292. ].filter( filterEmptyLine ).join( '\n' );
  17293. }
  17294. vertexShader = parseIncludes( vertexShader, parameters );
  17295. vertexShader = replaceLightNums( vertexShader, parameters );
  17296. fragmentShader = parseIncludes( fragmentShader, parameters );
  17297. fragmentShader = replaceLightNums( fragmentShader, parameters );
  17298. if ( material instanceof THREE.ShaderMaterial === false ) {
  17299. vertexShader = unrollLoops( vertexShader );
  17300. fragmentShader = unrollLoops( fragmentShader );
  17301. }
  17302. var vertexGlsl = prefixVertex + vertexShader;
  17303. var fragmentGlsl = prefixFragment + fragmentShader;
  17304. // console.log( '*VERTEX*', vertexGlsl );
  17305. // console.log( '*FRAGMENT*', fragmentGlsl );
  17306. var glVertexShader = THREE.WebGLShader( gl, gl.VERTEX_SHADER, vertexGlsl );
  17307. var glFragmentShader = THREE.WebGLShader( gl, gl.FRAGMENT_SHADER, fragmentGlsl );
  17308. gl.attachShader( program, glVertexShader );
  17309. gl.attachShader( program, glFragmentShader );
  17310. // Force a particular attribute to index 0.
  17311. if ( material.index0AttributeName !== undefined ) {
  17312. gl.bindAttribLocation( program, 0, material.index0AttributeName );
  17313. } else if ( parameters.morphTargets === true ) {
  17314. // programs with morphTargets displace position out of attribute 0
  17315. gl.bindAttribLocation( program, 0, 'position' );
  17316. }
  17317. gl.linkProgram( program );
  17318. var programLog = gl.getProgramInfoLog( program );
  17319. var vertexLog = gl.getShaderInfoLog( glVertexShader );
  17320. var fragmentLog = gl.getShaderInfoLog( glFragmentShader );
  17321. var runnable = true;
  17322. var haveDiagnostics = true;
  17323. // console.log( '**VERTEX**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( glVertexShader ) );
  17324. // console.log( '**FRAGMENT**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( glFragmentShader ) );
  17325. if ( gl.getProgramParameter( program, gl.LINK_STATUS ) === false ) {
  17326. runnable = false;
  17327. console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), 'gl.VALIDATE_STATUS', gl.getProgramParameter( program, gl.VALIDATE_STATUS ), 'gl.getProgramInfoLog', programLog, vertexLog, fragmentLog );
  17328. } else if ( programLog !== '' ) {
  17329. console.warn( 'THREE.WebGLProgram: gl.getProgramInfoLog()', programLog );
  17330. } else if ( vertexLog === '' || fragmentLog === '' ) {
  17331. haveDiagnostics = false;
  17332. }
  17333. if ( haveDiagnostics ) {
  17334. this.diagnostics = {
  17335. runnable: runnable,
  17336. material: material,
  17337. programLog: programLog,
  17338. vertexShader: {
  17339. log: vertexLog,
  17340. prefix: prefixVertex
  17341. },
  17342. fragmentShader: {
  17343. log: fragmentLog,
  17344. prefix: prefixFragment
  17345. }
  17346. };
  17347. }
  17348. // clean up
  17349. gl.deleteShader( glVertexShader );
  17350. gl.deleteShader( glFragmentShader );
  17351. // set up caching for uniform locations
  17352. var cachedUniforms;
  17353. this.getUniforms = function() {
  17354. if ( cachedUniforms === undefined ) {
  17355. cachedUniforms = fetchUniformLocations( gl, program );
  17356. }
  17357. return cachedUniforms;
  17358. };
  17359. // set up caching for attribute locations
  17360. var cachedAttributes;
  17361. this.getAttributes = function() {
  17362. if ( cachedAttributes === undefined ) {
  17363. cachedAttributes = fetchAttributeLocations( gl, program );
  17364. }
  17365. return cachedAttributes;
  17366. };
  17367. // free resource
  17368. this.destroy = function() {
  17369. gl.deleteProgram( program );
  17370. this.program = undefined;
  17371. };
  17372. // DEPRECATED
  17373. Object.defineProperties( this, {
  17374. uniforms: {
  17375. get: function() {
  17376. console.warn( 'THREE.WebGLProgram: .uniforms is now .getUniforms().' );
  17377. return this.getUniforms();
  17378. }
  17379. },
  17380. attributes: {
  17381. get: function() {
  17382. console.warn( 'THREE.WebGLProgram: .attributes is now .getAttributes().' );
  17383. return this.getAttributes();
  17384. }
  17385. }
  17386. } );
  17387. //
  17388. this.id = programIdCount ++;
  17389. this.code = code;
  17390. this.usedTimes = 1;
  17391. this.program = program;
  17392. this.vertexShader = glVertexShader;
  17393. this.fragmentShader = glFragmentShader;
  17394. return this;
  17395. };
  17396. } )();
  17397. // File:src/renderers/webgl/WebGLPrograms.js
  17398. THREE.WebGLPrograms = function ( renderer, capabilities ) {
  17399. var programs = [];
  17400. var shaderIDs = {
  17401. MeshDepthMaterial: 'depth',
  17402. MeshNormalMaterial: 'normal',
  17403. MeshBasicMaterial: 'basic',
  17404. MeshLambertMaterial: 'lambert',
  17405. MeshPhongMaterial: 'phong',
  17406. MeshStandardMaterial: 'standard',
  17407. LineBasicMaterial: 'basic',
  17408. LineDashedMaterial: 'dashed',
  17409. PointsMaterial: 'points'
  17410. };
  17411. var parameterNames = [
  17412. "precision", "supportsVertexTextures", "map", "mapEncoding", "envMap", "envMapMode", "envMapEncoding",
  17413. "lightMap", "aoMap", "emissiveMap", "emissiveMapEncoding", "bumpMap", "normalMap", "displacementMap", "specularMap",
  17414. "roughnessMap", "metalnessMap",
  17415. "alphaMap", "combine", "vertexColors", "fog", "useFog", "fogExp",
  17416. "flatShading", "sizeAttenuation", "logarithmicDepthBuffer", "skinning",
  17417. "maxBones", "useVertexTexture", "morphTargets", "morphNormals",
  17418. "maxMorphTargets", "maxMorphNormals", "premultipliedAlpha",
  17419. "numDirLights", "numPointLights", "numSpotLights", "numHemiLights",
  17420. "shadowMapEnabled", "pointLightShadows", "toneMapping", 'physicallyCorrectLights',
  17421. "shadowMapType",
  17422. "alphaTest", "doubleSided", "flipSided"
  17423. ];
  17424. function allocateBones ( object ) {
  17425. if ( capabilities.floatVertexTextures && object && object.skeleton && object.skeleton.useVertexTexture ) {
  17426. return 1024;
  17427. } else {
  17428. // default for when object is not specified
  17429. // ( for example when prebuilding shader to be used with multiple objects )
  17430. //
  17431. // - leave some extra space for other uniforms
  17432. // - limit here is ANGLE's 254 max uniform vectors
  17433. // (up to 54 should be safe)
  17434. var nVertexUniforms = capabilities.maxVertexUniforms;
  17435. var nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 );
  17436. var maxBones = nVertexMatrices;
  17437. if ( object !== undefined && object instanceof THREE.SkinnedMesh ) {
  17438. maxBones = Math.min( object.skeleton.bones.length, maxBones );
  17439. if ( maxBones < object.skeleton.bones.length ) {
  17440. console.warn( 'WebGLRenderer: too many bones - ' + object.skeleton.bones.length + ', this GPU supports just ' + maxBones + ' (try OpenGL instead of ANGLE)' );
  17441. }
  17442. }
  17443. return maxBones;
  17444. }
  17445. }
  17446. function getTextureEncodingFromMap( map, gammaOverrideLinear ) {
  17447. var encoding;
  17448. if ( ! map ) {
  17449. encoding = THREE.LinearEncoding;
  17450. } else if ( map instanceof THREE.Texture ) {
  17451. encoding = map.encoding;
  17452. } else if ( map instanceof THREE.WebGLRenderTarget ) {
  17453. encoding = map.texture.encoding;
  17454. }
  17455. // add backwards compatibility for WebGLRenderer.gammaInput/gammaOutput parameter, should probably be removed at some point.
  17456. if ( encoding === THREE.LinearEncoding && gammaOverrideLinear ) {
  17457. encoding = THREE.GammaEncoding;
  17458. }
  17459. return encoding;
  17460. }
  17461. this.getParameters = function ( material, lights, fog, object ) {
  17462. var shaderID = shaderIDs[ material.type ];
  17463. // heuristics to create shader parameters according to lights in the scene
  17464. // (not to blow over maxLights budget)
  17465. var maxBones = allocateBones( object );
  17466. var precision = renderer.getPrecision();
  17467. if ( material.precision !== null ) {
  17468. precision = capabilities.getMaxPrecision( material.precision );
  17469. if ( precision !== material.precision ) {
  17470. console.warn( 'THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.' );
  17471. }
  17472. }
  17473. var parameters = {
  17474. shaderID: shaderID,
  17475. precision: precision,
  17476. supportsVertexTextures: capabilities.vertexTextures,
  17477. outputEncoding: getTextureEncodingFromMap( renderer.getCurrentRenderTarget(), renderer.gammaOutput ),
  17478. map: !! material.map,
  17479. mapEncoding: getTextureEncodingFromMap( material.map, renderer.gammaInput ),
  17480. envMap: !! material.envMap,
  17481. envMapMode: material.envMap && material.envMap.mapping,
  17482. envMapEncoding: getTextureEncodingFromMap( material.envMap, renderer.gammaInput ),
  17483. envMapCubeUV: ( !! material.envMap ) && ( ( material.envMap.mapping === THREE.CubeUVReflectionMapping ) || ( material.envMap.mapping === THREE.CubeUVRefractionMapping ) ),
  17484. lightMap: !! material.lightMap,
  17485. aoMap: !! material.aoMap,
  17486. emissiveMap: !! material.emissiveMap,
  17487. emissiveMapEncoding: getTextureEncodingFromMap( material.emissiveMap, renderer.gammaInput ),
  17488. bumpMap: !! material.bumpMap,
  17489. normalMap: !! material.normalMap,
  17490. displacementMap: !! material.displacementMap,
  17491. roughnessMap: !! material.roughnessMap,
  17492. metalnessMap: !! material.metalnessMap,
  17493. specularMap: !! material.specularMap,
  17494. alphaMap: !! material.alphaMap,
  17495. combine: material.combine,
  17496. vertexColors: material.vertexColors,
  17497. fog: fog,
  17498. useFog: material.fog,
  17499. fogExp: fog instanceof THREE.FogExp2,
  17500. flatShading: material.shading === THREE.FlatShading,
  17501. sizeAttenuation: material.sizeAttenuation,
  17502. logarithmicDepthBuffer: capabilities.logarithmicDepthBuffer,
  17503. skinning: material.skinning,
  17504. maxBones: maxBones,
  17505. useVertexTexture: capabilities.floatVertexTextures && object && object.skeleton && object.skeleton.useVertexTexture,
  17506. morphTargets: material.morphTargets,
  17507. morphNormals: material.morphNormals,
  17508. maxMorphTargets: renderer.maxMorphTargets,
  17509. maxMorphNormals: renderer.maxMorphNormals,
  17510. numDirLights: lights.directional.length,
  17511. numPointLights: lights.point.length,
  17512. numSpotLights: lights.spot.length,
  17513. numHemiLights: lights.hemi.length,
  17514. pointLightShadows: lights.shadowsPointLight,
  17515. shadowMapEnabled: renderer.shadowMap.enabled && object.receiveShadow && lights.shadows.length > 0,
  17516. shadowMapType: renderer.shadowMap.type,
  17517. toneMapping: renderer.toneMapping,
  17518. physicallyCorrectLights: renderer.physicallyCorrectLights,
  17519. premultipliedAlpha: ( material.blending === THREE.PremultipliedAlphaBlending ),
  17520. alphaTest: material.alphaTest,
  17521. doubleSided: material.side === THREE.DoubleSide,
  17522. flipSided: material.side === THREE.BackSide
  17523. };
  17524. return parameters;
  17525. };
  17526. this.getProgramCode = function ( material, parameters ) {
  17527. var chunks = [];
  17528. if ( parameters.shaderID ) {
  17529. chunks.push( parameters.shaderID );
  17530. } else {
  17531. chunks.push( material.fragmentShader );
  17532. chunks.push( material.vertexShader );
  17533. }
  17534. if ( material.defines !== undefined ) {
  17535. for ( var name in material.defines ) {
  17536. chunks.push( name );
  17537. chunks.push( material.defines[ name ] );
  17538. }
  17539. }
  17540. for ( var i = 0; i < parameterNames.length; i ++ ) {
  17541. var parameterName = parameterNames[ i ];
  17542. chunks.push( parameterName );
  17543. chunks.push( parameters[ parameterName ] );
  17544. }
  17545. return chunks.join();
  17546. };
  17547. this.acquireProgram = function ( material, parameters, code ) {
  17548. var program;
  17549. // Check if code has been already compiled
  17550. for ( var p = 0, pl = programs.length; p < pl; p ++ ) {
  17551. var programInfo = programs[ p ];
  17552. if ( programInfo.code === code ) {
  17553. program = programInfo;
  17554. ++ program.usedTimes;
  17555. break;
  17556. }
  17557. }
  17558. if ( program === undefined ) {
  17559. program = new THREE.WebGLProgram( renderer, code, material, parameters );
  17560. programs.push( program );
  17561. }
  17562. return program;
  17563. };
  17564. this.releaseProgram = function( program ) {
  17565. if ( -- program.usedTimes === 0 ) {
  17566. // Remove from unordered set
  17567. var i = programs.indexOf( program );
  17568. programs[ i ] = programs[ programs.length - 1 ];
  17569. programs.pop();
  17570. // Free WebGL resources
  17571. program.destroy();
  17572. }
  17573. };
  17574. // Exposed for resource monitoring & error feedback via renderer.info:
  17575. this.programs = programs;
  17576. };
  17577. // File:src/renderers/webgl/WebGLProperties.js
  17578. /**
  17579. * @author fordacious / fordacious.github.io
  17580. */
  17581. THREE.WebGLProperties = function () {
  17582. var properties = {};
  17583. this.get = function ( object ) {
  17584. var uuid = object.uuid;
  17585. var map = properties[ uuid ];
  17586. if ( map === undefined ) {
  17587. map = {};
  17588. properties[ uuid ] = map;
  17589. }
  17590. return map;
  17591. };
  17592. this.delete = function ( object ) {
  17593. delete properties[ object.uuid ];
  17594. };
  17595. this.clear = function () {
  17596. properties = {};
  17597. };
  17598. };
  17599. // File:src/renderers/webgl/WebGLShader.js
  17600. THREE.WebGLShader = ( function () {
  17601. function addLineNumbers( string ) {
  17602. var lines = string.split( '\n' );
  17603. for ( var i = 0; i < lines.length; i ++ ) {
  17604. lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
  17605. }
  17606. return lines.join( '\n' );
  17607. }
  17608. return function WebGLShader( gl, type, string ) {
  17609. var shader = gl.createShader( type );
  17610. gl.shaderSource( shader, string );
  17611. gl.compileShader( shader );
  17612. if ( gl.getShaderParameter( shader, gl.COMPILE_STATUS ) === false ) {
  17613. console.error( 'THREE.WebGLShader: Shader couldn\'t compile.' );
  17614. }
  17615. if ( gl.getShaderInfoLog( shader ) !== '' ) {
  17616. console.warn( 'THREE.WebGLShader: gl.getShaderInfoLog()', type === gl.VERTEX_SHADER ? 'vertex' : 'fragment', gl.getShaderInfoLog( shader ), addLineNumbers( string ) );
  17617. }
  17618. // --enable-privileged-webgl-extension
  17619. // console.log( type, gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  17620. return shader;
  17621. };
  17622. } )();
  17623. // File:src/renderers/webgl/WebGLShadowMap.js
  17624. /**
  17625. * @author alteredq / http://alteredqualia.com/
  17626. * @author mrdoob / http://mrdoob.com/
  17627. */
  17628. THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
  17629. var _gl = _renderer.context,
  17630. _state = _renderer.state,
  17631. _frustum = new THREE.Frustum(),
  17632. _projScreenMatrix = new THREE.Matrix4(),
  17633. _shadowMapSize = new THREE.Vector2(),
  17634. _lookTarget = new THREE.Vector3(),
  17635. _lightPositionWorld = new THREE.Vector3(),
  17636. _renderList = [],
  17637. _MorphingFlag = 1,
  17638. _SkinningFlag = 2,
  17639. _NumberOfMaterialVariants = ( _MorphingFlag | _SkinningFlag ) + 1,
  17640. _depthMaterials = new Array( _NumberOfMaterialVariants ),
  17641. _distanceMaterials = new Array( _NumberOfMaterialVariants );
  17642. var cubeDirections = [
  17643. new THREE.Vector3( 1, 0, 0 ), new THREE.Vector3( - 1, 0, 0 ), new THREE.Vector3( 0, 0, 1 ),
  17644. new THREE.Vector3( 0, 0, - 1 ), new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, - 1, 0 )
  17645. ];
  17646. var cubeUps = [
  17647. new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 1, 0 ),
  17648. new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 0, 1 ), new THREE.Vector3( 0, 0, - 1 )
  17649. ];
  17650. var cube2DViewPorts = [
  17651. new THREE.Vector4(), new THREE.Vector4(), new THREE.Vector4(),
  17652. new THREE.Vector4(), new THREE.Vector4(), new THREE.Vector4()
  17653. ];
  17654. // init
  17655. var depthShader = THREE.ShaderLib[ "depthRGBA" ];
  17656. var depthUniforms = THREE.UniformsUtils.clone( depthShader.uniforms );
  17657. var distanceShader = THREE.ShaderLib[ "distanceRGBA" ];
  17658. var distanceUniforms = THREE.UniformsUtils.clone( distanceShader.uniforms );
  17659. for ( var i = 0; i !== _NumberOfMaterialVariants; ++ i ) {
  17660. var useMorphing = ( i & _MorphingFlag ) !== 0;
  17661. var useSkinning = ( i & _SkinningFlag ) !== 0;
  17662. var depthMaterial = new THREE.ShaderMaterial( {
  17663. uniforms: depthUniforms,
  17664. vertexShader: depthShader.vertexShader,
  17665. fragmentShader: depthShader.fragmentShader,
  17666. morphTargets: useMorphing,
  17667. skinning: useSkinning
  17668. } );
  17669. _depthMaterials[ i ] = depthMaterial;
  17670. var distanceMaterial = new THREE.ShaderMaterial( {
  17671. defines: {
  17672. 'USE_SHADOWMAP': ''
  17673. },
  17674. uniforms: distanceUniforms,
  17675. vertexShader: distanceShader.vertexShader,
  17676. fragmentShader: distanceShader.fragmentShader,
  17677. morphTargets: useMorphing,
  17678. skinning: useSkinning
  17679. } );
  17680. _distanceMaterials[ i ] = distanceMaterial;
  17681. }
  17682. //
  17683. var scope = this;
  17684. this.enabled = false;
  17685. this.autoUpdate = true;
  17686. this.needsUpdate = false;
  17687. this.type = THREE.PCFShadowMap;
  17688. this.cullFace = THREE.CullFaceFront;
  17689. this.render = function ( scene, camera ) {
  17690. var faceCount, isPointLight;
  17691. if ( scope.enabled === false ) return;
  17692. if ( scope.autoUpdate === false && scope.needsUpdate === false ) return;
  17693. // Set GL state for depth map.
  17694. _state.clearColor( 1, 1, 1, 1 );
  17695. _state.disable( _gl.BLEND );
  17696. _state.enable( _gl.CULL_FACE );
  17697. _gl.frontFace( _gl.CCW );
  17698. _gl.cullFace( scope.cullFace === THREE.CullFaceFront ? _gl.FRONT : _gl.BACK );
  17699. _state.setDepthTest( true );
  17700. _state.setScissorTest( false );
  17701. // render depth map
  17702. var shadows = _lights.shadows;
  17703. for ( var i = 0, il = shadows.length; i < il; i ++ ) {
  17704. var light = shadows[ i ];
  17705. var shadow = light.shadow;
  17706. var shadowCamera = shadow.camera;
  17707. _shadowMapSize.copy( shadow.mapSize );
  17708. if ( light instanceof THREE.PointLight ) {
  17709. faceCount = 6;
  17710. isPointLight = true;
  17711. var vpWidth = _shadowMapSize.x;
  17712. var vpHeight = _shadowMapSize.y;
  17713. // These viewports map a cube-map onto a 2D texture with the
  17714. // following orientation:
  17715. //
  17716. // xzXZ
  17717. // y Y
  17718. //
  17719. // X - Positive x direction
  17720. // x - Negative x direction
  17721. // Y - Positive y direction
  17722. // y - Negative y direction
  17723. // Z - Positive z direction
  17724. // z - Negative z direction
  17725. // positive X
  17726. cube2DViewPorts[ 0 ].set( vpWidth * 2, vpHeight, vpWidth, vpHeight );
  17727. // negative X
  17728. cube2DViewPorts[ 1 ].set( 0, vpHeight, vpWidth, vpHeight );
  17729. // positive Z
  17730. cube2DViewPorts[ 2 ].set( vpWidth * 3, vpHeight, vpWidth, vpHeight );
  17731. // negative Z
  17732. cube2DViewPorts[ 3 ].set( vpWidth, vpHeight, vpWidth, vpHeight );
  17733. // positive Y
  17734. cube2DViewPorts[ 4 ].set( vpWidth * 3, 0, vpWidth, vpHeight );
  17735. // negative Y
  17736. cube2DViewPorts[ 5 ].set( vpWidth, 0, vpWidth, vpHeight );
  17737. _shadowMapSize.x *= 4.0;
  17738. _shadowMapSize.y *= 2.0;
  17739. } else {
  17740. faceCount = 1;
  17741. isPointLight = false;
  17742. }
  17743. if ( shadow.map === null ) {
  17744. var pars = { minFilter: THREE.NearestFilter, magFilter: THREE.NearestFilter, format: THREE.RGBAFormat };
  17745. shadow.map = new THREE.WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
  17746. //
  17747. if ( light instanceof THREE.SpotLight ) {
  17748. shadowCamera.aspect = _shadowMapSize.x / _shadowMapSize.y;
  17749. }
  17750. shadowCamera.updateProjectionMatrix();
  17751. }
  17752. var shadowMap = shadow.map;
  17753. var shadowMatrix = shadow.matrix;
  17754. _lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  17755. shadowCamera.position.copy( _lightPositionWorld );
  17756. _renderer.setRenderTarget( shadowMap );
  17757. _renderer.clear();
  17758. // render shadow map for each cube face (if omni-directional) or
  17759. // run a single pass if not
  17760. for ( var face = 0; face < faceCount; face ++ ) {
  17761. if ( isPointLight ) {
  17762. _lookTarget.copy( shadowCamera.position );
  17763. _lookTarget.add( cubeDirections[ face ] );
  17764. shadowCamera.up.copy( cubeUps[ face ] );
  17765. shadowCamera.lookAt( _lookTarget );
  17766. var vpDimensions = cube2DViewPorts[ face ];
  17767. _state.viewport( vpDimensions );
  17768. } else {
  17769. _lookTarget.setFromMatrixPosition( light.target.matrixWorld );
  17770. shadowCamera.lookAt( _lookTarget );
  17771. }
  17772. shadowCamera.updateMatrixWorld();
  17773. shadowCamera.matrixWorldInverse.getInverse( shadowCamera.matrixWorld );
  17774. // compute shadow matrix
  17775. shadowMatrix.set(
  17776. 0.5, 0.0, 0.0, 0.5,
  17777. 0.0, 0.5, 0.0, 0.5,
  17778. 0.0, 0.0, 0.5, 0.5,
  17779. 0.0, 0.0, 0.0, 1.0
  17780. );
  17781. shadowMatrix.multiply( shadowCamera.projectionMatrix );
  17782. shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
  17783. // update camera matrices and frustum
  17784. _projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  17785. _frustum.setFromMatrix( _projScreenMatrix );
  17786. // set object matrices & frustum culling
  17787. _renderList.length = 0;
  17788. projectObject( scene, camera, shadowCamera );
  17789. // render shadow map
  17790. // render regular objects
  17791. for ( var j = 0, jl = _renderList.length; j < jl; j ++ ) {
  17792. var object = _renderList[ j ];
  17793. var geometry = _objects.update( object );
  17794. var material = object.material;
  17795. if ( material instanceof THREE.MultiMaterial ) {
  17796. var groups = geometry.groups;
  17797. var materials = material.materials;
  17798. for ( var k = 0, kl = groups.length; k < kl; k ++ ) {
  17799. var group = groups[ k ];
  17800. var groupMaterial = materials[ group.materialIndex ];
  17801. if ( groupMaterial.visible === true ) {
  17802. var depthMaterial = getDepthMaterial( object, groupMaterial, isPointLight, _lightPositionWorld );
  17803. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, group );
  17804. }
  17805. }
  17806. } else {
  17807. var depthMaterial = getDepthMaterial( object, material, isPointLight, _lightPositionWorld );
  17808. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, null );
  17809. }
  17810. }
  17811. }
  17812. // We must call _renderer.resetGLState() at the end of each iteration of
  17813. // the light loop in order to force material updates for each light.
  17814. _renderer.resetGLState();
  17815. }
  17816. // Restore GL state.
  17817. var clearColor = _renderer.getClearColor(),
  17818. clearAlpha = _renderer.getClearAlpha();
  17819. _renderer.setClearColor( clearColor, clearAlpha );
  17820. _state.enable( _gl.BLEND );
  17821. if ( scope.cullFace === THREE.CullFaceFront ) {
  17822. _gl.cullFace( _gl.BACK );
  17823. }
  17824. _renderer.resetGLState();
  17825. scope.needsUpdate = false;
  17826. };
  17827. function getDepthMaterial( object, material, isPointLight, lightPositionWorld ) {
  17828. var geometry = object.geometry;
  17829. var newMaterial = null;
  17830. var materialVariants = _depthMaterials;
  17831. var customMaterial = object.customDepthMaterial;
  17832. if ( isPointLight ) {
  17833. materialVariants = _distanceMaterials;
  17834. customMaterial = object.customDistanceMaterial;
  17835. }
  17836. if ( ! customMaterial ) {
  17837. var useMorphing = geometry.morphTargets !== undefined &&
  17838. geometry.morphTargets.length > 0 && material.morphTargets;
  17839. var useSkinning = object instanceof THREE.SkinnedMesh && material.skinning;
  17840. var variantIndex = 0;
  17841. if ( useMorphing ) variantIndex |= _MorphingFlag;
  17842. if ( useSkinning ) variantIndex |= _SkinningFlag;
  17843. newMaterial = materialVariants[ variantIndex ];
  17844. } else {
  17845. newMaterial = customMaterial;
  17846. }
  17847. newMaterial.visible = material.visible;
  17848. newMaterial.wireframe = material.wireframe;
  17849. newMaterial.wireframeLinewidth = material.wireframeLinewidth;
  17850. if ( isPointLight && newMaterial.uniforms.lightPos !== undefined ) {
  17851. newMaterial.uniforms.lightPos.value.copy( lightPositionWorld );
  17852. }
  17853. return newMaterial;
  17854. }
  17855. function projectObject( object, camera, shadowCamera ) {
  17856. if ( object.visible === false ) return;
  17857. if ( object.layers.test( camera.layers ) && ( object instanceof THREE.Mesh || object instanceof THREE.Line || object instanceof THREE.Points ) ) {
  17858. if ( object.castShadow && ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) ) {
  17859. var material = object.material;
  17860. if ( material.visible === true ) {
  17861. object.modelViewMatrix.multiplyMatrices( shadowCamera.matrixWorldInverse, object.matrixWorld );
  17862. _renderList.push( object );
  17863. }
  17864. }
  17865. }
  17866. var children = object.children;
  17867. for ( var i = 0, l = children.length; i < l; i ++ ) {
  17868. projectObject( children[ i ], camera, shadowCamera );
  17869. }
  17870. }
  17871. };
  17872. // File:src/renderers/webgl/WebGLState.js
  17873. /**
  17874. * @author mrdoob / http://mrdoob.com/
  17875. */
  17876. THREE.WebGLState = function ( gl, extensions, paramThreeToGL ) {
  17877. var _this = this;
  17878. var color = new THREE.Vector4();
  17879. var newAttributes = new Uint8Array( 16 );
  17880. var enabledAttributes = new Uint8Array( 16 );
  17881. var attributeDivisors = new Uint8Array( 16 );
  17882. var capabilities = {};
  17883. var compressedTextureFormats = null;
  17884. var currentBlending = null;
  17885. var currentBlendEquation = null;
  17886. var currentBlendSrc = null;
  17887. var currentBlendDst = null;
  17888. var currentBlendEquationAlpha = null;
  17889. var currentBlendSrcAlpha = null;
  17890. var currentBlendDstAlpha = null;
  17891. var currentDepthFunc = null;
  17892. var currentDepthWrite = null;
  17893. var currentColorWrite = null;
  17894. var currentStencilWrite = null;
  17895. var currentStencilFunc = null;
  17896. var currentStencilRef = null;
  17897. var currentStencilMask = null;
  17898. var currentStencilFail = null;
  17899. var currentStencilZFail = null;
  17900. var currentStencilZPass = null;
  17901. var currentFlipSided = null;
  17902. var currentLineWidth = null;
  17903. var currentPolygonOffsetFactor = null;
  17904. var currentPolygonOffsetUnits = null;
  17905. var currentScissorTest = null;
  17906. var maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
  17907. var currentTextureSlot = undefined;
  17908. var currentBoundTextures = {};
  17909. var currentClearColor = new THREE.Vector4();
  17910. var currentClearDepth = null;
  17911. var currentClearStencil = null;
  17912. var currentScissor = new THREE.Vector4();
  17913. var currentViewport = new THREE.Vector4();
  17914. var emptyTexture = gl.createTexture();
  17915. gl.bindTexture( gl.TEXTURE_2D, emptyTexture );
  17916. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR );
  17917. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGB, 1, 1, 0, gl.RGB, gl.UNSIGNED_BYTE, new Uint8Array( 3 ) );
  17918. this.init = function () {
  17919. this.clearColor( 0, 0, 0, 1 );
  17920. this.clearDepth( 1 );
  17921. this.clearStencil( 0 );
  17922. this.enable( gl.DEPTH_TEST );
  17923. gl.depthFunc( gl.LEQUAL );
  17924. gl.frontFace( gl.CCW );
  17925. gl.cullFace( gl.BACK );
  17926. this.enable( gl.CULL_FACE );
  17927. this.enable( gl.BLEND );
  17928. gl.blendEquation( gl.FUNC_ADD );
  17929. gl.blendFunc( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA );
  17930. };
  17931. this.initAttributes = function () {
  17932. for ( var i = 0, l = newAttributes.length; i < l; i ++ ) {
  17933. newAttributes[ i ] = 0;
  17934. }
  17935. };
  17936. this.enableAttribute = function ( attribute ) {
  17937. newAttributes[ attribute ] = 1;
  17938. if ( enabledAttributes[ attribute ] === 0 ) {
  17939. gl.enableVertexAttribArray( attribute );
  17940. enabledAttributes[ attribute ] = 1;
  17941. }
  17942. if ( attributeDivisors[ attribute ] !== 0 ) {
  17943. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  17944. extension.vertexAttribDivisorANGLE( attribute, 0 );
  17945. attributeDivisors[ attribute ] = 0;
  17946. }
  17947. };
  17948. this.enableAttributeAndDivisor = function ( attribute, meshPerAttribute, extension ) {
  17949. newAttributes[ attribute ] = 1;
  17950. if ( enabledAttributes[ attribute ] === 0 ) {
  17951. gl.enableVertexAttribArray( attribute );
  17952. enabledAttributes[ attribute ] = 1;
  17953. }
  17954. if ( attributeDivisors[ attribute ] !== meshPerAttribute ) {
  17955. extension.vertexAttribDivisorANGLE( attribute, meshPerAttribute );
  17956. attributeDivisors[ attribute ] = meshPerAttribute;
  17957. }
  17958. };
  17959. this.disableUnusedAttributes = function () {
  17960. for ( var i = 0, l = enabledAttributes.length; i < l; i ++ ) {
  17961. if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
  17962. gl.disableVertexAttribArray( i );
  17963. enabledAttributes[ i ] = 0;
  17964. }
  17965. }
  17966. };
  17967. this.enable = function ( id ) {
  17968. if ( capabilities[ id ] !== true ) {
  17969. gl.enable( id );
  17970. capabilities[ id ] = true;
  17971. }
  17972. };
  17973. this.disable = function ( id ) {
  17974. if ( capabilities[ id ] !== false ) {
  17975. gl.disable( id );
  17976. capabilities[ id ] = false;
  17977. }
  17978. };
  17979. this.getCompressedTextureFormats = function () {
  17980. if ( compressedTextureFormats === null ) {
  17981. compressedTextureFormats = [];
  17982. if ( extensions.get( 'WEBGL_compressed_texture_pvrtc' ) ||
  17983. extensions.get( 'WEBGL_compressed_texture_s3tc' ) ||
  17984. extensions.get( 'WEBGL_compressed_texture_etc1' ) ) {
  17985. var formats = gl.getParameter( gl.COMPRESSED_TEXTURE_FORMATS );
  17986. for ( var i = 0; i < formats.length; i ++ ) {
  17987. compressedTextureFormats.push( formats[ i ] );
  17988. }
  17989. }
  17990. }
  17991. return compressedTextureFormats;
  17992. };
  17993. this.setBlending = function ( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha ) {
  17994. if ( blending === THREE.NoBlending ) {
  17995. this.disable( gl.BLEND );
  17996. } else {
  17997. this.enable( gl.BLEND );
  17998. }
  17999. if ( blending !== currentBlending ) {
  18000. if ( blending === THREE.AdditiveBlending ) {
  18001. gl.blendEquation( gl.FUNC_ADD );
  18002. gl.blendFunc( gl.SRC_ALPHA, gl.ONE );
  18003. } else if ( blending === THREE.SubtractiveBlending ) {
  18004. // TODO: Find blendFuncSeparate() combination
  18005. gl.blendEquation( gl.FUNC_ADD );
  18006. gl.blendFunc( gl.ZERO, gl.ONE_MINUS_SRC_COLOR );
  18007. } else if ( blending === THREE.MultiplyBlending ) {
  18008. // TODO: Find blendFuncSeparate() combination
  18009. gl.blendEquation( gl.FUNC_ADD );
  18010. gl.blendFunc( gl.ZERO, gl.SRC_COLOR );
  18011. } else if ( blending === THREE.PremultipliedAlphaBlending ) {
  18012. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  18013. gl.blendFuncSeparate( gl.ONE, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
  18014. } else {
  18015. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  18016. gl.blendFuncSeparate( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
  18017. }
  18018. currentBlending = blending;
  18019. }
  18020. if ( blending === THREE.CustomBlending ) {
  18021. blendEquationAlpha = blendEquationAlpha || blendEquation;
  18022. blendSrcAlpha = blendSrcAlpha || blendSrc;
  18023. blendDstAlpha = blendDstAlpha || blendDst;
  18024. if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
  18025. gl.blendEquationSeparate( paramThreeToGL( blendEquation ), paramThreeToGL( blendEquationAlpha ) );
  18026. currentBlendEquation = blendEquation;
  18027. currentBlendEquationAlpha = blendEquationAlpha;
  18028. }
  18029. if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
  18030. gl.blendFuncSeparate( paramThreeToGL( blendSrc ), paramThreeToGL( blendDst ), paramThreeToGL( blendSrcAlpha ), paramThreeToGL( blendDstAlpha ) );
  18031. currentBlendSrc = blendSrc;
  18032. currentBlendDst = blendDst;
  18033. currentBlendSrcAlpha = blendSrcAlpha;
  18034. currentBlendDstAlpha = blendDstAlpha;
  18035. }
  18036. } else {
  18037. currentBlendEquation = null;
  18038. currentBlendSrc = null;
  18039. currentBlendDst = null;
  18040. currentBlendEquationAlpha = null;
  18041. currentBlendSrcAlpha = null;
  18042. currentBlendDstAlpha = null;
  18043. }
  18044. };
  18045. this.setDepthFunc = function ( depthFunc ) {
  18046. if ( currentDepthFunc !== depthFunc ) {
  18047. if ( depthFunc ) {
  18048. switch ( depthFunc ) {
  18049. case THREE.NeverDepth:
  18050. gl.depthFunc( gl.NEVER );
  18051. break;
  18052. case THREE.AlwaysDepth:
  18053. gl.depthFunc( gl.ALWAYS );
  18054. break;
  18055. case THREE.LessDepth:
  18056. gl.depthFunc( gl.LESS );
  18057. break;
  18058. case THREE.LessEqualDepth:
  18059. gl.depthFunc( gl.LEQUAL );
  18060. break;
  18061. case THREE.EqualDepth:
  18062. gl.depthFunc( gl.EQUAL );
  18063. break;
  18064. case THREE.GreaterEqualDepth:
  18065. gl.depthFunc( gl.GEQUAL );
  18066. break;
  18067. case THREE.GreaterDepth:
  18068. gl.depthFunc( gl.GREATER );
  18069. break;
  18070. case THREE.NotEqualDepth:
  18071. gl.depthFunc( gl.NOTEQUAL );
  18072. break;
  18073. default:
  18074. gl.depthFunc( gl.LEQUAL );
  18075. }
  18076. } else {
  18077. gl.depthFunc( gl.LEQUAL );
  18078. }
  18079. currentDepthFunc = depthFunc;
  18080. }
  18081. };
  18082. this.setDepthTest = function ( depthTest ) {
  18083. if ( depthTest ) {
  18084. this.enable( gl.DEPTH_TEST );
  18085. } else {
  18086. this.disable( gl.DEPTH_TEST );
  18087. }
  18088. };
  18089. this.setDepthWrite = function ( depthWrite ) {
  18090. // TODO: Rename to setDepthMask
  18091. if ( currentDepthWrite !== depthWrite ) {
  18092. gl.depthMask( depthWrite );
  18093. currentDepthWrite = depthWrite;
  18094. }
  18095. };
  18096. this.setColorWrite = function ( colorWrite ) {
  18097. // TODO: Rename to setColorMask
  18098. if ( currentColorWrite !== colorWrite ) {
  18099. gl.colorMask( colorWrite, colorWrite, colorWrite, colorWrite );
  18100. currentColorWrite = colorWrite;
  18101. }
  18102. };
  18103. this.setStencilFunc = function ( stencilFunc, stencilRef, stencilMask ) {
  18104. if ( currentStencilFunc !== stencilFunc ||
  18105. currentStencilRef !== stencilRef ||
  18106. currentStencilMask !== stencilMask ) {
  18107. gl.stencilFunc( stencilFunc, stencilRef, stencilMask );
  18108. currentStencilFunc = stencilFunc;
  18109. currentStencilRef = stencilRef;
  18110. currentStencilMask = stencilMask;
  18111. }
  18112. };
  18113. this.setStencilOp = function ( stencilFail, stencilZFail, stencilZPass ) {
  18114. if ( currentStencilFail !== stencilFail ||
  18115. currentStencilZFail !== stencilZFail ||
  18116. currentStencilZPass !== stencilZPass ) {
  18117. gl.stencilOp( stencilFail, stencilZFail, stencilZPass );
  18118. currentStencilFail = stencilFail;
  18119. currentStencilZFail = stencilZFail;
  18120. currentStencilZPass = stencilZPass;
  18121. }
  18122. };
  18123. this.setStencilTest = function ( stencilTest ) {
  18124. if ( stencilTest ) {
  18125. this.enable( gl.STENCIL_TEST );
  18126. } else {
  18127. this.disable( gl.STENCIL_TEST );
  18128. }
  18129. };
  18130. this.setStencilWrite = function ( stencilWrite ) {
  18131. // TODO: Rename to setStencilMask
  18132. if ( currentStencilWrite !== stencilWrite ) {
  18133. gl.stencilMask( stencilWrite );
  18134. currentStencilWrite = stencilWrite;
  18135. }
  18136. };
  18137. this.setFlipSided = function ( flipSided ) {
  18138. if ( currentFlipSided !== flipSided ) {
  18139. if ( flipSided ) {
  18140. gl.frontFace( gl.CW );
  18141. } else {
  18142. gl.frontFace( gl.CCW );
  18143. }
  18144. currentFlipSided = flipSided;
  18145. }
  18146. };
  18147. this.setLineWidth = function ( width ) {
  18148. if ( width !== currentLineWidth ) {
  18149. gl.lineWidth( width );
  18150. currentLineWidth = width;
  18151. }
  18152. };
  18153. this.setPolygonOffset = function ( polygonOffset, factor, units ) {
  18154. if ( polygonOffset ) {
  18155. this.enable( gl.POLYGON_OFFSET_FILL );
  18156. } else {
  18157. this.disable( gl.POLYGON_OFFSET_FILL );
  18158. }
  18159. if ( polygonOffset && ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) ) {
  18160. gl.polygonOffset( factor, units );
  18161. currentPolygonOffsetFactor = factor;
  18162. currentPolygonOffsetUnits = units;
  18163. }
  18164. };
  18165. this.getScissorTest = function () {
  18166. return currentScissorTest;
  18167. };
  18168. this.setScissorTest = function ( scissorTest ) {
  18169. currentScissorTest = scissorTest;
  18170. if ( scissorTest ) {
  18171. this.enable( gl.SCISSOR_TEST );
  18172. } else {
  18173. this.disable( gl.SCISSOR_TEST );
  18174. }
  18175. };
  18176. // texture
  18177. this.activeTexture = function ( webglSlot ) {
  18178. if ( webglSlot === undefined ) webglSlot = gl.TEXTURE0 + maxTextures - 1;
  18179. if ( currentTextureSlot !== webglSlot ) {
  18180. gl.activeTexture( webglSlot );
  18181. currentTextureSlot = webglSlot;
  18182. }
  18183. };
  18184. this.bindTexture = function ( webglType, webglTexture ) {
  18185. if ( currentTextureSlot === undefined ) {
  18186. _this.activeTexture();
  18187. }
  18188. var boundTexture = currentBoundTextures[ currentTextureSlot ];
  18189. if ( boundTexture === undefined ) {
  18190. boundTexture = { type: undefined, texture: undefined };
  18191. currentBoundTextures[ currentTextureSlot ] = boundTexture;
  18192. }
  18193. if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
  18194. gl.bindTexture( webglType, webglTexture || emptyTexture );
  18195. boundTexture.type = webglType;
  18196. boundTexture.texture = webglTexture;
  18197. }
  18198. };
  18199. this.compressedTexImage2D = function () {
  18200. try {
  18201. gl.compressedTexImage2D.apply( gl, arguments );
  18202. } catch ( error ) {
  18203. console.error( error );
  18204. }
  18205. };
  18206. this.texImage2D = function () {
  18207. try {
  18208. gl.texImage2D.apply( gl, arguments );
  18209. } catch ( error ) {
  18210. console.error( error );
  18211. }
  18212. };
  18213. // clear values
  18214. this.clearColor = function ( r, g, b, a ) {
  18215. color.set( r, g, b, a );
  18216. if ( currentClearColor.equals( color ) === false ) {
  18217. gl.clearColor( r, g, b, a );
  18218. currentClearColor.copy( color );
  18219. }
  18220. };
  18221. this.clearDepth = function ( depth ) {
  18222. if ( currentClearDepth !== depth ) {
  18223. gl.clearDepth( depth );
  18224. currentClearDepth = depth;
  18225. }
  18226. };
  18227. this.clearStencil = function ( stencil ) {
  18228. if ( currentClearStencil !== stencil ) {
  18229. gl.clearStencil( stencil );
  18230. currentClearStencil = stencil;
  18231. }
  18232. };
  18233. //
  18234. this.scissor = function ( scissor ) {
  18235. if ( currentScissor.equals( scissor ) === false ) {
  18236. gl.scissor( scissor.x, scissor.y, scissor.z, scissor.w );
  18237. currentScissor.copy( scissor );
  18238. }
  18239. };
  18240. this.viewport = function ( viewport ) {
  18241. if ( currentViewport.equals( viewport ) === false ) {
  18242. gl.viewport( viewport.x, viewport.y, viewport.z, viewport.w );
  18243. currentViewport.copy( viewport );
  18244. }
  18245. };
  18246. //
  18247. this.reset = function () {
  18248. for ( var i = 0; i < enabledAttributes.length; i ++ ) {
  18249. if ( enabledAttributes[ i ] === 1 ) {
  18250. gl.disableVertexAttribArray( i );
  18251. enabledAttributes[ i ] = 0;
  18252. }
  18253. }
  18254. capabilities = {};
  18255. compressedTextureFormats = null;
  18256. currentBlending = null;
  18257. currentColorWrite = null;
  18258. currentDepthWrite = null;
  18259. currentStencilWrite = null;
  18260. currentFlipSided = null;
  18261. };
  18262. };
  18263. // File:src/renderers/webgl/plugins/LensFlarePlugin.js
  18264. /**
  18265. * @author mikael emtinger / http://gomo.se/
  18266. * @author alteredq / http://alteredqualia.com/
  18267. */
  18268. THREE.LensFlarePlugin = function ( renderer, flares ) {
  18269. var gl = renderer.context;
  18270. var state = renderer.state;
  18271. var vertexBuffer, elementBuffer;
  18272. var program, attributes, uniforms;
  18273. var hasVertexTexture;
  18274. var tempTexture, occlusionTexture;
  18275. function init() {
  18276. var vertices = new Float32Array( [
  18277. - 1, - 1, 0, 0,
  18278. 1, - 1, 1, 0,
  18279. 1, 1, 1, 1,
  18280. - 1, 1, 0, 1
  18281. ] );
  18282. var faces = new Uint16Array( [
  18283. 0, 1, 2,
  18284. 0, 2, 3
  18285. ] );
  18286. // buffers
  18287. vertexBuffer = gl.createBuffer();
  18288. elementBuffer = gl.createBuffer();
  18289. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  18290. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  18291. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  18292. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  18293. // textures
  18294. tempTexture = gl.createTexture();
  18295. occlusionTexture = gl.createTexture();
  18296. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  18297. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGB, 16, 16, 0, gl.RGB, gl.UNSIGNED_BYTE, null );
  18298. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  18299. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  18300. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  18301. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  18302. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  18303. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGBA, 16, 16, 0, gl.RGBA, gl.UNSIGNED_BYTE, null );
  18304. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  18305. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  18306. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  18307. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  18308. hasVertexTexture = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS ) > 0;
  18309. var shader;
  18310. if ( hasVertexTexture ) {
  18311. shader = {
  18312. vertexShader: [
  18313. "uniform lowp int renderType;",
  18314. "uniform vec3 screenPosition;",
  18315. "uniform vec2 scale;",
  18316. "uniform float rotation;",
  18317. "uniform sampler2D occlusionMap;",
  18318. "attribute vec2 position;",
  18319. "attribute vec2 uv;",
  18320. "varying vec2 vUV;",
  18321. "varying float vVisibility;",
  18322. "void main() {",
  18323. "vUV = uv;",
  18324. "vec2 pos = position;",
  18325. "if ( renderType == 2 ) {",
  18326. "vec4 visibility = texture2D( occlusionMap, vec2( 0.1, 0.1 ) );",
  18327. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.1 ) );",
  18328. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.1 ) );",
  18329. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) );",
  18330. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.9 ) );",
  18331. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) );",
  18332. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.9 ) );",
  18333. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) );",
  18334. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.5 ) );",
  18335. "vVisibility = visibility.r / 9.0;",
  18336. "vVisibility *= 1.0 - visibility.g / 9.0;",
  18337. "vVisibility *= visibility.b / 9.0;",
  18338. "vVisibility *= 1.0 - visibility.a / 9.0;",
  18339. "pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
  18340. "pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
  18341. "}",
  18342. "gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
  18343. "}"
  18344. ].join( "\n" ),
  18345. fragmentShader: [
  18346. "uniform lowp int renderType;",
  18347. "uniform sampler2D map;",
  18348. "uniform float opacity;",
  18349. "uniform vec3 color;",
  18350. "varying vec2 vUV;",
  18351. "varying float vVisibility;",
  18352. "void main() {",
  18353. // pink square
  18354. "if ( renderType == 0 ) {",
  18355. "gl_FragColor = vec4( 1.0, 0.0, 1.0, 0.0 );",
  18356. // restore
  18357. "} else if ( renderType == 1 ) {",
  18358. "gl_FragColor = texture2D( map, vUV );",
  18359. // flare
  18360. "} else {",
  18361. "vec4 texture = texture2D( map, vUV );",
  18362. "texture.a *= opacity * vVisibility;",
  18363. "gl_FragColor = texture;",
  18364. "gl_FragColor.rgb *= color;",
  18365. "}",
  18366. "}"
  18367. ].join( "\n" )
  18368. };
  18369. } else {
  18370. shader = {
  18371. vertexShader: [
  18372. "uniform lowp int renderType;",
  18373. "uniform vec3 screenPosition;",
  18374. "uniform vec2 scale;",
  18375. "uniform float rotation;",
  18376. "attribute vec2 position;",
  18377. "attribute vec2 uv;",
  18378. "varying vec2 vUV;",
  18379. "void main() {",
  18380. "vUV = uv;",
  18381. "vec2 pos = position;",
  18382. "if ( renderType == 2 ) {",
  18383. "pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
  18384. "pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
  18385. "}",
  18386. "gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
  18387. "}"
  18388. ].join( "\n" ),
  18389. fragmentShader: [
  18390. "precision mediump float;",
  18391. "uniform lowp int renderType;",
  18392. "uniform sampler2D map;",
  18393. "uniform sampler2D occlusionMap;",
  18394. "uniform float opacity;",
  18395. "uniform vec3 color;",
  18396. "varying vec2 vUV;",
  18397. "void main() {",
  18398. // pink square
  18399. "if ( renderType == 0 ) {",
  18400. "gl_FragColor = vec4( texture2D( map, vUV ).rgb, 0.0 );",
  18401. // restore
  18402. "} else if ( renderType == 1 ) {",
  18403. "gl_FragColor = texture2D( map, vUV );",
  18404. // flare
  18405. "} else {",
  18406. "float visibility = texture2D( occlusionMap, vec2( 0.5, 0.1 ) ).a;",
  18407. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) ).a;",
  18408. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) ).a;",
  18409. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) ).a;",
  18410. "visibility = ( 1.0 - visibility / 4.0 );",
  18411. "vec4 texture = texture2D( map, vUV );",
  18412. "texture.a *= opacity * visibility;",
  18413. "gl_FragColor = texture;",
  18414. "gl_FragColor.rgb *= color;",
  18415. "}",
  18416. "}"
  18417. ].join( "\n" )
  18418. };
  18419. }
  18420. program = createProgram( shader );
  18421. attributes = {
  18422. vertex: gl.getAttribLocation ( program, "position" ),
  18423. uv: gl.getAttribLocation ( program, "uv" )
  18424. };
  18425. uniforms = {
  18426. renderType: gl.getUniformLocation( program, "renderType" ),
  18427. map: gl.getUniformLocation( program, "map" ),
  18428. occlusionMap: gl.getUniformLocation( program, "occlusionMap" ),
  18429. opacity: gl.getUniformLocation( program, "opacity" ),
  18430. color: gl.getUniformLocation( program, "color" ),
  18431. scale: gl.getUniformLocation( program, "scale" ),
  18432. rotation: gl.getUniformLocation( program, "rotation" ),
  18433. screenPosition: gl.getUniformLocation( program, "screenPosition" )
  18434. };
  18435. }
  18436. /*
  18437. * Render lens flares
  18438. * Method: renders 16x16 0xff00ff-colored points scattered over the light source area,
  18439. * reads these back and calculates occlusion.
  18440. */
  18441. this.render = function ( scene, camera, viewport ) {
  18442. if ( flares.length === 0 ) return;
  18443. var tempPosition = new THREE.Vector3();
  18444. var invAspect = viewport.w / viewport.z,
  18445. halfViewportWidth = viewport.z * 0.5,
  18446. halfViewportHeight = viewport.w * 0.5;
  18447. var size = 16 / viewport.w,
  18448. scale = new THREE.Vector2( size * invAspect, size );
  18449. var screenPosition = new THREE.Vector3( 1, 1, 0 ),
  18450. screenPositionPixels = new THREE.Vector2( 1, 1 );
  18451. if ( program === undefined ) {
  18452. init();
  18453. }
  18454. gl.useProgram( program );
  18455. state.initAttributes();
  18456. state.enableAttribute( attributes.vertex );
  18457. state.enableAttribute( attributes.uv );
  18458. state.disableUnusedAttributes();
  18459. // loop through all lens flares to update their occlusion and positions
  18460. // setup gl and common used attribs/uniforms
  18461. gl.uniform1i( uniforms.occlusionMap, 0 );
  18462. gl.uniform1i( uniforms.map, 1 );
  18463. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  18464. gl.vertexAttribPointer( attributes.vertex, 2, gl.FLOAT, false, 2 * 8, 0 );
  18465. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  18466. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  18467. state.disable( gl.CULL_FACE );
  18468. state.setDepthWrite( false );
  18469. for ( var i = 0, l = flares.length; i < l; i ++ ) {
  18470. size = 16 / viewport.w;
  18471. scale.set( size * invAspect, size );
  18472. // calc object screen position
  18473. var flare = flares[ i ];
  18474. tempPosition.set( flare.matrixWorld.elements[ 12 ], flare.matrixWorld.elements[ 13 ], flare.matrixWorld.elements[ 14 ] );
  18475. tempPosition.applyMatrix4( camera.matrixWorldInverse );
  18476. tempPosition.applyProjection( camera.projectionMatrix );
  18477. // setup arrays for gl programs
  18478. screenPosition.copy( tempPosition );
  18479. screenPositionPixels.x = screenPosition.x * halfViewportWidth + halfViewportWidth;
  18480. screenPositionPixels.y = screenPosition.y * halfViewportHeight + halfViewportHeight;
  18481. // screen cull
  18482. if ( hasVertexTexture || (
  18483. screenPositionPixels.x > 0 &&
  18484. screenPositionPixels.x < viewport.z &&
  18485. screenPositionPixels.y > 0 &&
  18486. screenPositionPixels.y < viewport.w ) ) {
  18487. // save current RGB to temp texture
  18488. state.activeTexture( gl.TEXTURE0 );
  18489. state.bindTexture( gl.TEXTURE_2D, null );
  18490. state.activeTexture( gl.TEXTURE1 );
  18491. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  18492. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGB, viewport.x + screenPositionPixels.x - 8, viewport.y + screenPositionPixels.y - 8, 16, 16, 0 );
  18493. // render pink quad
  18494. gl.uniform1i( uniforms.renderType, 0 );
  18495. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  18496. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  18497. state.disable( gl.BLEND );
  18498. state.enable( gl.DEPTH_TEST );
  18499. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  18500. // copy result to occlusionMap
  18501. state.activeTexture( gl.TEXTURE0 );
  18502. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  18503. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGBA, viewport.x + screenPositionPixels.x - 8, viewport.y + screenPositionPixels.y - 8, 16, 16, 0 );
  18504. // restore graphics
  18505. gl.uniform1i( uniforms.renderType, 1 );
  18506. state.disable( gl.DEPTH_TEST );
  18507. state.activeTexture( gl.TEXTURE1 );
  18508. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  18509. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  18510. // update object positions
  18511. flare.positionScreen.copy( screenPosition );
  18512. if ( flare.customUpdateCallback ) {
  18513. flare.customUpdateCallback( flare );
  18514. } else {
  18515. flare.updateLensFlares();
  18516. }
  18517. // render flares
  18518. gl.uniform1i( uniforms.renderType, 2 );
  18519. state.enable( gl.BLEND );
  18520. for ( var j = 0, jl = flare.lensFlares.length; j < jl; j ++ ) {
  18521. var sprite = flare.lensFlares[ j ];
  18522. if ( sprite.opacity > 0.001 && sprite.scale > 0.001 ) {
  18523. screenPosition.x = sprite.x;
  18524. screenPosition.y = sprite.y;
  18525. screenPosition.z = sprite.z;
  18526. size = sprite.size * sprite.scale / viewport.w;
  18527. scale.x = size * invAspect;
  18528. scale.y = size;
  18529. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  18530. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  18531. gl.uniform1f( uniforms.rotation, sprite.rotation );
  18532. gl.uniform1f( uniforms.opacity, sprite.opacity );
  18533. gl.uniform3f( uniforms.color, sprite.color.r, sprite.color.g, sprite.color.b );
  18534. state.setBlending( sprite.blending, sprite.blendEquation, sprite.blendSrc, sprite.blendDst );
  18535. renderer.setTexture( sprite.texture, 1 );
  18536. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  18537. }
  18538. }
  18539. }
  18540. }
  18541. // restore gl
  18542. state.enable( gl.CULL_FACE );
  18543. state.enable( gl.DEPTH_TEST );
  18544. state.setDepthWrite( true );
  18545. renderer.resetGLState();
  18546. };
  18547. function createProgram ( shader ) {
  18548. var program = gl.createProgram();
  18549. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  18550. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  18551. var prefix = "precision " + renderer.getPrecision() + " float;\n";
  18552. gl.shaderSource( fragmentShader, prefix + shader.fragmentShader );
  18553. gl.shaderSource( vertexShader, prefix + shader.vertexShader );
  18554. gl.compileShader( fragmentShader );
  18555. gl.compileShader( vertexShader );
  18556. gl.attachShader( program, fragmentShader );
  18557. gl.attachShader( program, vertexShader );
  18558. gl.linkProgram( program );
  18559. return program;
  18560. }
  18561. };
  18562. // File:src/renderers/webgl/plugins/SpritePlugin.js
  18563. /**
  18564. * @author mikael emtinger / http://gomo.se/
  18565. * @author alteredq / http://alteredqualia.com/
  18566. */
  18567. THREE.SpritePlugin = function ( renderer, sprites ) {
  18568. var gl = renderer.context;
  18569. var state = renderer.state;
  18570. var vertexBuffer, elementBuffer;
  18571. var program, attributes, uniforms;
  18572. var texture;
  18573. // decompose matrixWorld
  18574. var spritePosition = new THREE.Vector3();
  18575. var spriteRotation = new THREE.Quaternion();
  18576. var spriteScale = new THREE.Vector3();
  18577. function init() {
  18578. var vertices = new Float32Array( [
  18579. - 0.5, - 0.5, 0, 0,
  18580. 0.5, - 0.5, 1, 0,
  18581. 0.5, 0.5, 1, 1,
  18582. - 0.5, 0.5, 0, 1
  18583. ] );
  18584. var faces = new Uint16Array( [
  18585. 0, 1, 2,
  18586. 0, 2, 3
  18587. ] );
  18588. vertexBuffer = gl.createBuffer();
  18589. elementBuffer = gl.createBuffer();
  18590. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  18591. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  18592. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  18593. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  18594. program = createProgram();
  18595. attributes = {
  18596. position: gl.getAttribLocation ( program, 'position' ),
  18597. uv: gl.getAttribLocation ( program, 'uv' )
  18598. };
  18599. uniforms = {
  18600. uvOffset: gl.getUniformLocation( program, 'uvOffset' ),
  18601. uvScale: gl.getUniformLocation( program, 'uvScale' ),
  18602. rotation: gl.getUniformLocation( program, 'rotation' ),
  18603. scale: gl.getUniformLocation( program, 'scale' ),
  18604. color: gl.getUniformLocation( program, 'color' ),
  18605. map: gl.getUniformLocation( program, 'map' ),
  18606. opacity: gl.getUniformLocation( program, 'opacity' ),
  18607. modelViewMatrix: gl.getUniformLocation( program, 'modelViewMatrix' ),
  18608. projectionMatrix: gl.getUniformLocation( program, 'projectionMatrix' ),
  18609. fogType: gl.getUniformLocation( program, 'fogType' ),
  18610. fogDensity: gl.getUniformLocation( program, 'fogDensity' ),
  18611. fogNear: gl.getUniformLocation( program, 'fogNear' ),
  18612. fogFar: gl.getUniformLocation( program, 'fogFar' ),
  18613. fogColor: gl.getUniformLocation( program, 'fogColor' ),
  18614. alphaTest: gl.getUniformLocation( program, 'alphaTest' )
  18615. };
  18616. var canvas = document.createElement( 'canvas' );
  18617. canvas.width = 8;
  18618. canvas.height = 8;
  18619. var context = canvas.getContext( '2d' );
  18620. context.fillStyle = 'white';
  18621. context.fillRect( 0, 0, 8, 8 );
  18622. texture = new THREE.Texture( canvas );
  18623. texture.needsUpdate = true;
  18624. }
  18625. this.render = function ( scene, camera ) {
  18626. if ( sprites.length === 0 ) return;
  18627. // setup gl
  18628. if ( program === undefined ) {
  18629. init();
  18630. }
  18631. gl.useProgram( program );
  18632. state.initAttributes();
  18633. state.enableAttribute( attributes.position );
  18634. state.enableAttribute( attributes.uv );
  18635. state.disableUnusedAttributes();
  18636. state.disable( gl.CULL_FACE );
  18637. state.enable( gl.BLEND );
  18638. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  18639. gl.vertexAttribPointer( attributes.position, 2, gl.FLOAT, false, 2 * 8, 0 );
  18640. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  18641. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  18642. gl.uniformMatrix4fv( uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
  18643. state.activeTexture( gl.TEXTURE0 );
  18644. gl.uniform1i( uniforms.map, 0 );
  18645. var oldFogType = 0;
  18646. var sceneFogType = 0;
  18647. var fog = scene.fog;
  18648. if ( fog ) {
  18649. gl.uniform3f( uniforms.fogColor, fog.color.r, fog.color.g, fog.color.b );
  18650. if ( fog instanceof THREE.Fog ) {
  18651. gl.uniform1f( uniforms.fogNear, fog.near );
  18652. gl.uniform1f( uniforms.fogFar, fog.far );
  18653. gl.uniform1i( uniforms.fogType, 1 );
  18654. oldFogType = 1;
  18655. sceneFogType = 1;
  18656. } else if ( fog instanceof THREE.FogExp2 ) {
  18657. gl.uniform1f( uniforms.fogDensity, fog.density );
  18658. gl.uniform1i( uniforms.fogType, 2 );
  18659. oldFogType = 2;
  18660. sceneFogType = 2;
  18661. }
  18662. } else {
  18663. gl.uniform1i( uniforms.fogType, 0 );
  18664. oldFogType = 0;
  18665. sceneFogType = 0;
  18666. }
  18667. // update positions and sort
  18668. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  18669. var sprite = sprites[ i ];
  18670. sprite.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, sprite.matrixWorld );
  18671. sprite.z = - sprite.modelViewMatrix.elements[ 14 ];
  18672. }
  18673. sprites.sort( painterSortStable );
  18674. // render all sprites
  18675. var scale = [];
  18676. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  18677. var sprite = sprites[ i ];
  18678. var material = sprite.material;
  18679. gl.uniform1f( uniforms.alphaTest, material.alphaTest );
  18680. gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, sprite.modelViewMatrix.elements );
  18681. sprite.matrixWorld.decompose( spritePosition, spriteRotation, spriteScale );
  18682. scale[ 0 ] = spriteScale.x;
  18683. scale[ 1 ] = spriteScale.y;
  18684. var fogType = 0;
  18685. if ( scene.fog && material.fog ) {
  18686. fogType = sceneFogType;
  18687. }
  18688. if ( oldFogType !== fogType ) {
  18689. gl.uniform1i( uniforms.fogType, fogType );
  18690. oldFogType = fogType;
  18691. }
  18692. if ( material.map !== null ) {
  18693. gl.uniform2f( uniforms.uvOffset, material.map.offset.x, material.map.offset.y );
  18694. gl.uniform2f( uniforms.uvScale, material.map.repeat.x, material.map.repeat.y );
  18695. } else {
  18696. gl.uniform2f( uniforms.uvOffset, 0, 0 );
  18697. gl.uniform2f( uniforms.uvScale, 1, 1 );
  18698. }
  18699. gl.uniform1f( uniforms.opacity, material.opacity );
  18700. gl.uniform3f( uniforms.color, material.color.r, material.color.g, material.color.b );
  18701. gl.uniform1f( uniforms.rotation, material.rotation );
  18702. gl.uniform2fv( uniforms.scale, scale );
  18703. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst );
  18704. state.setDepthTest( material.depthTest );
  18705. state.setDepthWrite( material.depthWrite );
  18706. if ( material.map && material.map.image && material.map.image.width ) {
  18707. renderer.setTexture( material.map, 0 );
  18708. } else {
  18709. renderer.setTexture( texture, 0 );
  18710. }
  18711. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  18712. }
  18713. // restore gl
  18714. state.enable( gl.CULL_FACE );
  18715. renderer.resetGLState();
  18716. };
  18717. function createProgram () {
  18718. var program = gl.createProgram();
  18719. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  18720. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  18721. gl.shaderSource( vertexShader, [
  18722. 'precision ' + renderer.getPrecision() + ' float;',
  18723. 'uniform mat4 modelViewMatrix;',
  18724. 'uniform mat4 projectionMatrix;',
  18725. 'uniform float rotation;',
  18726. 'uniform vec2 scale;',
  18727. 'uniform vec2 uvOffset;',
  18728. 'uniform vec2 uvScale;',
  18729. 'attribute vec2 position;',
  18730. 'attribute vec2 uv;',
  18731. 'varying vec2 vUV;',
  18732. 'void main() {',
  18733. 'vUV = uvOffset + uv * uvScale;',
  18734. 'vec2 alignedPosition = position * scale;',
  18735. 'vec2 rotatedPosition;',
  18736. 'rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;',
  18737. 'rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;',
  18738. 'vec4 finalPosition;',
  18739. 'finalPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );',
  18740. 'finalPosition.xy += rotatedPosition;',
  18741. 'finalPosition = projectionMatrix * finalPosition;',
  18742. 'gl_Position = finalPosition;',
  18743. '}'
  18744. ].join( '\n' ) );
  18745. gl.shaderSource( fragmentShader, [
  18746. 'precision ' + renderer.getPrecision() + ' float;',
  18747. 'uniform vec3 color;',
  18748. 'uniform sampler2D map;',
  18749. 'uniform float opacity;',
  18750. 'uniform int fogType;',
  18751. 'uniform vec3 fogColor;',
  18752. 'uniform float fogDensity;',
  18753. 'uniform float fogNear;',
  18754. 'uniform float fogFar;',
  18755. 'uniform float alphaTest;',
  18756. 'varying vec2 vUV;',
  18757. 'void main() {',
  18758. 'vec4 texture = texture2D( map, vUV );',
  18759. 'if ( texture.a < alphaTest ) discard;',
  18760. 'gl_FragColor = vec4( color * texture.xyz, texture.a * opacity );',
  18761. 'if ( fogType > 0 ) {',
  18762. 'float depth = gl_FragCoord.z / gl_FragCoord.w;',
  18763. 'float fogFactor = 0.0;',
  18764. 'if ( fogType == 1 ) {',
  18765. 'fogFactor = smoothstep( fogNear, fogFar, depth );',
  18766. '} else {',
  18767. 'const float LOG2 = 1.442695;',
  18768. 'fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );',
  18769. 'fogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );',
  18770. '}',
  18771. 'gl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );',
  18772. '}',
  18773. '}'
  18774. ].join( '\n' ) );
  18775. gl.compileShader( vertexShader );
  18776. gl.compileShader( fragmentShader );
  18777. gl.attachShader( program, vertexShader );
  18778. gl.attachShader( program, fragmentShader );
  18779. gl.linkProgram( program );
  18780. return program;
  18781. }
  18782. function painterSortStable ( a, b ) {
  18783. if ( a.renderOrder !== b.renderOrder ) {
  18784. return a.renderOrder - b.renderOrder;
  18785. } else if ( a.z !== b.z ) {
  18786. return b.z - a.z;
  18787. } else {
  18788. return b.id - a.id;
  18789. }
  18790. }
  18791. };
  18792. // File:src/Three.Legacy.js
  18793. /**
  18794. * @author mrdoob / http://mrdoob.com/
  18795. */
  18796. Object.defineProperties( THREE.Box2.prototype, {
  18797. empty: {
  18798. value: function () {
  18799. console.warn( 'THREE.Box2: .empty() has been renamed to .isEmpty().' );
  18800. return this.isEmpty();
  18801. }
  18802. },
  18803. isIntersectionBox: {
  18804. value: function ( box ) {
  18805. console.warn( 'THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().' );
  18806. return this.intersectsBox( box );
  18807. }
  18808. }
  18809. } );
  18810. Object.defineProperties( THREE.Box3.prototype, {
  18811. empty: {
  18812. value: function () {
  18813. console.warn( 'THREE.Box3: .empty() has been renamed to .isEmpty().' );
  18814. return this.isEmpty();
  18815. }
  18816. },
  18817. isIntersectionBox: {
  18818. value: function ( box ) {
  18819. console.warn( 'THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().' );
  18820. return this.intersectsBox( box );
  18821. }
  18822. },
  18823. isIntersectionSphere: {
  18824. value: function ( sphere ) {
  18825. console.warn( 'THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  18826. return this.intersectsSphere( sphere );
  18827. }
  18828. }
  18829. } );
  18830. Object.defineProperties( THREE.Matrix3.prototype, {
  18831. multiplyVector3: {
  18832. value: function ( vector ) {
  18833. console.warn( 'THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.' );
  18834. return vector.applyMatrix3( this );
  18835. }
  18836. },
  18837. multiplyVector3Array: {
  18838. value: function ( a ) {
  18839. console.warn( 'THREE.Matrix3: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
  18840. return this.applyToVector3Array( a );
  18841. }
  18842. }
  18843. } );
  18844. Object.defineProperties( THREE.Matrix4.prototype, {
  18845. extractPosition: {
  18846. value: function ( m ) {
  18847. console.warn( 'THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().' );
  18848. return this.copyPosition( m );
  18849. }
  18850. },
  18851. setRotationFromQuaternion: {
  18852. value: function ( q ) {
  18853. console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' );
  18854. return this.makeRotationFromQuaternion( q );
  18855. }
  18856. },
  18857. multiplyVector3: {
  18858. value: function ( vector ) {
  18859. console.warn( 'THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) or vector.applyProjection( matrix ) instead.' );
  18860. return vector.applyProjection( this );
  18861. }
  18862. },
  18863. multiplyVector4: {
  18864. value: function ( vector ) {
  18865. console.warn( 'THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  18866. return vector.applyMatrix4( this );
  18867. }
  18868. },
  18869. multiplyVector3Array: {
  18870. value: function ( a ) {
  18871. console.warn( 'THREE.Matrix4: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
  18872. return this.applyToVector3Array( a );
  18873. }
  18874. },
  18875. rotateAxis: {
  18876. value: function ( v ) {
  18877. console.warn( 'THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.' );
  18878. v.transformDirection( this );
  18879. }
  18880. },
  18881. crossVector: {
  18882. value: function ( vector ) {
  18883. console.warn( 'THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  18884. return vector.applyMatrix4( this );
  18885. }
  18886. },
  18887. translate: {
  18888. value: function ( v ) {
  18889. console.error( 'THREE.Matrix4: .translate() has been removed.' );
  18890. }
  18891. },
  18892. rotateX: {
  18893. value: function ( angle ) {
  18894. console.error( 'THREE.Matrix4: .rotateX() has been removed.' );
  18895. }
  18896. },
  18897. rotateY: {
  18898. value: function ( angle ) {
  18899. console.error( 'THREE.Matrix4: .rotateY() has been removed.' );
  18900. }
  18901. },
  18902. rotateZ: {
  18903. value: function ( angle ) {
  18904. console.error( 'THREE.Matrix4: .rotateZ() has been removed.' );
  18905. }
  18906. },
  18907. rotateByAxis: {
  18908. value: function ( axis, angle ) {
  18909. console.error( 'THREE.Matrix4: .rotateByAxis() has been removed.' );
  18910. }
  18911. }
  18912. } );
  18913. Object.defineProperties( THREE.Plane.prototype, {
  18914. isIntersectionLine: {
  18915. value: function ( line ) {
  18916. console.warn( 'THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().' );
  18917. return this.intersectsLine( line );
  18918. }
  18919. }
  18920. } );
  18921. Object.defineProperties( THREE.Quaternion.prototype, {
  18922. multiplyVector3: {
  18923. value: function ( vector ) {
  18924. console.warn( 'THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.' );
  18925. return vector.applyQuaternion( this );
  18926. }
  18927. }
  18928. } );
  18929. Object.defineProperties( THREE.Ray.prototype, {
  18930. isIntersectionBox: {
  18931. value: function ( box ) {
  18932. console.warn( 'THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().' );
  18933. return this.intersectsBox( box );
  18934. }
  18935. },
  18936. isIntersectionPlane: {
  18937. value: function ( plane ) {
  18938. console.warn( 'THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().' );
  18939. return this.intersectsPlane( plane );
  18940. }
  18941. },
  18942. isIntersectionSphere: {
  18943. value: function ( sphere ) {
  18944. console.warn( 'THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  18945. return this.intersectsSphere( sphere );
  18946. }
  18947. }
  18948. } );
  18949. Object.defineProperties( THREE.Vector3.prototype, {
  18950. setEulerFromRotationMatrix: {
  18951. value: function () {
  18952. console.error( 'THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.' );
  18953. }
  18954. },
  18955. setEulerFromQuaternion: {
  18956. value: function () {
  18957. console.error( 'THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.' );
  18958. }
  18959. },
  18960. getPositionFromMatrix: {
  18961. value: function ( m ) {
  18962. console.warn( 'THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().' );
  18963. return this.setFromMatrixPosition( m );
  18964. }
  18965. },
  18966. getScaleFromMatrix: {
  18967. value: function ( m ) {
  18968. console.warn( 'THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().' );
  18969. return this.setFromMatrixScale( m );
  18970. }
  18971. },
  18972. getColumnFromMatrix: {
  18973. value: function ( index, matrix ) {
  18974. console.warn( 'THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().' );
  18975. return this.setFromMatrixColumn( index, matrix );
  18976. }
  18977. }
  18978. } );
  18979. //
  18980. THREE.Face4 = function ( a, b, c, d, normal, color, materialIndex ) {
  18981. console.warn( 'THREE.Face4 has been removed. A THREE.Face3 will be created instead.' );
  18982. return new THREE.Face3( a, b, c, normal, color, materialIndex );
  18983. };
  18984. THREE.Vertex = function ( x, y, z ) {
  18985. console.warn( 'THREE.Vertex has been removed. Use THREE.Vector3 instead.' );
  18986. return new THREE.Vector3( x, y, z );
  18987. };
  18988. //
  18989. Object.defineProperties( THREE.Object3D.prototype, {
  18990. eulerOrder: {
  18991. get: function () {
  18992. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  18993. return this.rotation.order;
  18994. },
  18995. set: function ( value ) {
  18996. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  18997. this.rotation.order = value;
  18998. }
  18999. },
  19000. getChildByName: {
  19001. value: function ( name ) {
  19002. console.warn( 'THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().' );
  19003. return this.getObjectByName( name );
  19004. }
  19005. },
  19006. renderDepth: {
  19007. set: function ( value ) {
  19008. console.warn( 'THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.' );
  19009. }
  19010. },
  19011. translate: {
  19012. value: function ( distance, axis ) {
  19013. console.warn( 'THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.' );
  19014. return this.translateOnAxis( axis, distance );
  19015. }
  19016. },
  19017. useQuaternion: {
  19018. get: function () {
  19019. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  19020. },
  19021. set: function ( value ) {
  19022. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  19023. }
  19024. }
  19025. } );
  19026. //
  19027. Object.defineProperties( THREE, {
  19028. PointCloud: {
  19029. value: function ( geometry, material ) {
  19030. console.warn( 'THREE.PointCloud has been renamed to THREE.Points.' );
  19031. return new THREE.Points( geometry, material );
  19032. }
  19033. },
  19034. ParticleSystem: {
  19035. value: function ( geometry, material ) {
  19036. console.warn( 'THREE.ParticleSystem has been renamed to THREE.Points.' );
  19037. return new THREE.Points( geometry, material );
  19038. }
  19039. }
  19040. } );
  19041. //
  19042. Object.defineProperties( THREE.Light.prototype, {
  19043. onlyShadow: {
  19044. set: function ( value ) {
  19045. console.warn( 'THREE.Light: .onlyShadow has been removed.' );
  19046. }
  19047. },
  19048. shadowCameraFov: {
  19049. set: function ( value ) {
  19050. console.warn( 'THREE.Light: .shadowCameraFov is now .shadow.camera.fov.' );
  19051. this.shadow.camera.fov = value;
  19052. }
  19053. },
  19054. shadowCameraLeft: {
  19055. set: function ( value ) {
  19056. console.warn( 'THREE.Light: .shadowCameraLeft is now .shadow.camera.left.' );
  19057. this.shadow.camera.left = value;
  19058. }
  19059. },
  19060. shadowCameraRight: {
  19061. set: function ( value ) {
  19062. console.warn( 'THREE.Light: .shadowCameraRight is now .shadow.camera.right.' );
  19063. this.shadow.camera.right = value;
  19064. }
  19065. },
  19066. shadowCameraTop: {
  19067. set: function ( value ) {
  19068. console.warn( 'THREE.Light: .shadowCameraTop is now .shadow.camera.top.' );
  19069. this.shadow.camera.top = value;
  19070. }
  19071. },
  19072. shadowCameraBottom: {
  19073. set: function ( value ) {
  19074. console.warn( 'THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.' );
  19075. this.shadow.camera.bottom = value;
  19076. }
  19077. },
  19078. shadowCameraNear: {
  19079. set: function ( value ) {
  19080. console.warn( 'THREE.Light: .shadowCameraNear is now .shadow.camera.near.' );
  19081. this.shadow.camera.near = value;
  19082. }
  19083. },
  19084. shadowCameraFar: {
  19085. set: function ( value ) {
  19086. console.warn( 'THREE.Light: .shadowCameraFar is now .shadow.camera.far.' );
  19087. this.shadow.camera.far = value;
  19088. }
  19089. },
  19090. shadowCameraVisible: {
  19091. set: function ( value ) {
  19092. console.warn( 'THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.' );
  19093. }
  19094. },
  19095. shadowBias: {
  19096. set: function ( value ) {
  19097. console.warn( 'THREE.Light: .shadowBias is now .shadow.bias.' );
  19098. this.shadow.bias = value;
  19099. }
  19100. },
  19101. shadowDarkness: {
  19102. set: function ( value ) {
  19103. console.warn( 'THREE.Light: .shadowDarkness has been removed.' );
  19104. }
  19105. },
  19106. shadowMapWidth: {
  19107. set: function ( value ) {
  19108. console.warn( 'THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.' );
  19109. this.shadow.mapSize.width = value;
  19110. }
  19111. },
  19112. shadowMapHeight: {
  19113. set: function ( value ) {
  19114. console.warn( 'THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.' );
  19115. this.shadow.mapSize.height = value;
  19116. }
  19117. }
  19118. } );
  19119. //
  19120. Object.defineProperties( THREE.BufferAttribute.prototype, {
  19121. length: {
  19122. get: function () {
  19123. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Please use .count.' );
  19124. return this.array.length;
  19125. }
  19126. }
  19127. } );
  19128. Object.defineProperties( THREE.BufferGeometry.prototype, {
  19129. drawcalls: {
  19130. get: function () {
  19131. console.error( 'THREE.BufferGeometry: .drawcalls has been renamed to .groups.' );
  19132. return this.groups;
  19133. }
  19134. },
  19135. offsets: {
  19136. get: function () {
  19137. console.warn( 'THREE.BufferGeometry: .offsets has been renamed to .groups.' );
  19138. return this.groups;
  19139. }
  19140. },
  19141. addIndex: {
  19142. value: function ( index ) {
  19143. console.warn( 'THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().' );
  19144. this.setIndex( index );
  19145. }
  19146. },
  19147. addDrawCall: {
  19148. value: function ( start, count, indexOffset ) {
  19149. if ( indexOffset !== undefined ) {
  19150. console.warn( 'THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.' );
  19151. }
  19152. console.warn( 'THREE.BufferGeometry: .addDrawCall() is now .addGroup().' );
  19153. this.addGroup( start, count );
  19154. }
  19155. },
  19156. clearDrawCalls: {
  19157. value: function () {
  19158. console.warn( 'THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().' );
  19159. this.clearGroups();
  19160. }
  19161. },
  19162. computeTangents: {
  19163. value: function () {
  19164. console.warn( 'THREE.BufferGeometry: .computeTangents() has been removed.' );
  19165. }
  19166. },
  19167. computeOffsets: {
  19168. value: function () {
  19169. console.warn( 'THREE.BufferGeometry: .computeOffsets() has been removed.' );
  19170. }
  19171. }
  19172. } );
  19173. //
  19174. Object.defineProperties( THREE.Material.prototype, {
  19175. wrapAround: {
  19176. get: function () {
  19177. console.warn( 'THREE.' + this.type + ': .wrapAround has been removed.' );
  19178. },
  19179. set: function ( value ) {
  19180. console.warn( 'THREE.' + this.type + ': .wrapAround has been removed.' );
  19181. }
  19182. },
  19183. wrapRGB: {
  19184. get: function () {
  19185. console.warn( 'THREE.' + this.type + ': .wrapRGB has been removed.' );
  19186. return new THREE.Color();
  19187. }
  19188. }
  19189. } );
  19190. Object.defineProperties( THREE, {
  19191. PointCloudMaterial: {
  19192. value: function ( parameters ) {
  19193. console.warn( 'THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.' );
  19194. return new THREE.PointsMaterial( parameters );
  19195. }
  19196. },
  19197. ParticleBasicMaterial: {
  19198. value: function ( parameters ) {
  19199. console.warn( 'THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.' );
  19200. return new THREE.PointsMaterial( parameters );
  19201. }
  19202. },
  19203. ParticleSystemMaterial:{
  19204. value: function ( parameters ) {
  19205. console.warn( 'THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.' );
  19206. return new THREE.PointsMaterial( parameters );
  19207. }
  19208. }
  19209. } );
  19210. Object.defineProperties( THREE.MeshPhongMaterial.prototype, {
  19211. metal: {
  19212. get: function () {
  19213. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.' );
  19214. return false;
  19215. },
  19216. set: function ( value ) {
  19217. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead' );
  19218. }
  19219. }
  19220. } );
  19221. Object.defineProperties( THREE.ShaderMaterial.prototype, {
  19222. derivatives: {
  19223. get: function () {
  19224. console.warn( 'THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  19225. return this.extensions.derivatives;
  19226. },
  19227. set: function ( value ) {
  19228. console.warn( 'THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  19229. this.extensions.derivatives = value;
  19230. }
  19231. }
  19232. } );
  19233. //
  19234. Object.defineProperties( THREE.WebGLRenderer.prototype, {
  19235. supportsFloatTextures: {
  19236. value: function () {
  19237. console.warn( 'THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).' );
  19238. return this.extensions.get( 'OES_texture_float' );
  19239. }
  19240. },
  19241. supportsHalfFloatTextures: {
  19242. value: function () {
  19243. console.warn( 'THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).' );
  19244. return this.extensions.get( 'OES_texture_half_float' );
  19245. }
  19246. },
  19247. supportsStandardDerivatives: {
  19248. value: function () {
  19249. console.warn( 'THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).' );
  19250. return this.extensions.get( 'OES_standard_derivatives' );
  19251. }
  19252. },
  19253. supportsCompressedTextureS3TC: {
  19254. value: function () {
  19255. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).' );
  19256. return this.extensions.get( 'WEBGL_compressed_texture_s3tc' );
  19257. }
  19258. },
  19259. supportsCompressedTexturePVRTC: {
  19260. value: function () {
  19261. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).' );
  19262. return this.extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  19263. }
  19264. },
  19265. supportsBlendMinMax: {
  19266. value: function () {
  19267. console.warn( 'THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).' );
  19268. return this.extensions.get( 'EXT_blend_minmax' );
  19269. }
  19270. },
  19271. supportsVertexTextures: {
  19272. value: function () {
  19273. return this.capabilities.vertexTextures;
  19274. }
  19275. },
  19276. supportsInstancedArrays: {
  19277. value: function () {
  19278. console.warn( 'THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).' );
  19279. return this.extensions.get( 'ANGLE_instanced_arrays' );
  19280. }
  19281. },
  19282. enableScissorTest: {
  19283. value: function ( boolean ) {
  19284. console.warn( 'THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().' );
  19285. this.setScissorTest( boolean );
  19286. }
  19287. },
  19288. initMaterial: {
  19289. value: function () {
  19290. console.warn( 'THREE.WebGLRenderer: .initMaterial() has been removed.' );
  19291. }
  19292. },
  19293. addPrePlugin: {
  19294. value: function () {
  19295. console.warn( 'THREE.WebGLRenderer: .addPrePlugin() has been removed.' );
  19296. }
  19297. },
  19298. addPostPlugin: {
  19299. value: function () {
  19300. console.warn( 'THREE.WebGLRenderer: .addPostPlugin() has been removed.' );
  19301. }
  19302. },
  19303. updateShadowMap: {
  19304. value: function () {
  19305. console.warn( 'THREE.WebGLRenderer: .updateShadowMap() has been removed.' );
  19306. }
  19307. },
  19308. shadowMapEnabled: {
  19309. get: function () {
  19310. return this.shadowMap.enabled;
  19311. },
  19312. set: function ( value ) {
  19313. console.warn( 'THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.' );
  19314. this.shadowMap.enabled = value;
  19315. }
  19316. },
  19317. shadowMapType: {
  19318. get: function () {
  19319. return this.shadowMap.type;
  19320. },
  19321. set: function ( value ) {
  19322. console.warn( 'THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.' );
  19323. this.shadowMap.type = value;
  19324. }
  19325. },
  19326. shadowMapCullFace: {
  19327. get: function () {
  19328. return this.shadowMap.cullFace;
  19329. },
  19330. set: function ( value ) {
  19331. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace is now .shadowMap.cullFace.' );
  19332. this.shadowMap.cullFace = value;
  19333. }
  19334. }
  19335. } );
  19336. //
  19337. Object.defineProperties( THREE.WebGLRenderTarget.prototype, {
  19338. wrapS: {
  19339. get: function () {
  19340. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  19341. return this.texture.wrapS;
  19342. },
  19343. set: function ( value ) {
  19344. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  19345. this.texture.wrapS = value;
  19346. }
  19347. },
  19348. wrapT: {
  19349. get: function () {
  19350. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  19351. return this.texture.wrapT;
  19352. },
  19353. set: function ( value ) {
  19354. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  19355. this.texture.wrapT = value;
  19356. }
  19357. },
  19358. magFilter: {
  19359. get: function () {
  19360. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  19361. return this.texture.magFilter;
  19362. },
  19363. set: function ( value ) {
  19364. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  19365. this.texture.magFilter = value;
  19366. }
  19367. },
  19368. minFilter: {
  19369. get: function () {
  19370. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  19371. return this.texture.minFilter;
  19372. },
  19373. set: function ( value ) {
  19374. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  19375. this.texture.minFilter = value;
  19376. }
  19377. },
  19378. anisotropy: {
  19379. get: function () {
  19380. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  19381. return this.texture.anisotropy;
  19382. },
  19383. set: function ( value ) {
  19384. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  19385. this.texture.anisotropy = value;
  19386. }
  19387. },
  19388. offset: {
  19389. get: function () {
  19390. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  19391. return this.texture.offset;
  19392. },
  19393. set: function ( value ) {
  19394. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  19395. this.texture.offset = value;
  19396. }
  19397. },
  19398. repeat: {
  19399. get: function () {
  19400. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  19401. return this.texture.repeat;
  19402. },
  19403. set: function ( value ) {
  19404. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  19405. this.texture.repeat = value;
  19406. }
  19407. },
  19408. format: {
  19409. get: function () {
  19410. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  19411. return this.texture.format;
  19412. },
  19413. set: function ( value ) {
  19414. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  19415. this.texture.format = value;
  19416. }
  19417. },
  19418. type: {
  19419. get: function () {
  19420. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  19421. return this.texture.type;
  19422. },
  19423. set: function ( value ) {
  19424. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  19425. this.texture.type = value;
  19426. }
  19427. },
  19428. generateMipmaps: {
  19429. get: function () {
  19430. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  19431. return this.texture.generateMipmaps;
  19432. },
  19433. set: function ( value ) {
  19434. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  19435. this.texture.generateMipmaps = value;
  19436. }
  19437. }
  19438. } );
  19439. //
  19440. THREE.GeometryUtils = {
  19441. merge: function ( geometry1, geometry2, materialIndexOffset ) {
  19442. console.warn( 'THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.' );
  19443. var matrix;
  19444. if ( geometry2 instanceof THREE.Mesh ) {
  19445. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  19446. matrix = geometry2.matrix;
  19447. geometry2 = geometry2.geometry;
  19448. }
  19449. geometry1.merge( geometry2, matrix, materialIndexOffset );
  19450. },
  19451. center: function ( geometry ) {
  19452. console.warn( 'THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.' );
  19453. return geometry.center();
  19454. }
  19455. };
  19456. THREE.ImageUtils = {
  19457. crossOrigin: undefined,
  19458. loadTexture: function ( url, mapping, onLoad, onError ) {
  19459. console.warn( 'THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.' );
  19460. var loader = new THREE.TextureLoader();
  19461. loader.setCrossOrigin( this.crossOrigin );
  19462. var texture = loader.load( url, onLoad, undefined, onError );
  19463. if ( mapping ) texture.mapping = mapping;
  19464. return texture;
  19465. },
  19466. loadTextureCube: function ( urls, mapping, onLoad, onError ) {
  19467. console.warn( 'THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.' );
  19468. var loader = new THREE.CubeTextureLoader();
  19469. loader.setCrossOrigin( this.crossOrigin );
  19470. var texture = loader.load( urls, onLoad, undefined, onError );
  19471. if ( mapping ) texture.mapping = mapping;
  19472. return texture;
  19473. },
  19474. loadCompressedTexture: function () {
  19475. console.error( 'THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.' );
  19476. },
  19477. loadCompressedTextureCube: function () {
  19478. console.error( 'THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.' );
  19479. }
  19480. };
  19481. //
  19482. THREE.Projector = function () {
  19483. console.error( 'THREE.Projector has been moved to /examples/js/renderers/Projector.js.' );
  19484. this.projectVector = function ( vector, camera ) {
  19485. console.warn( 'THREE.Projector: .projectVector() is now vector.project().' );
  19486. vector.project( camera );
  19487. };
  19488. this.unprojectVector = function ( vector, camera ) {
  19489. console.warn( 'THREE.Projector: .unprojectVector() is now vector.unproject().' );
  19490. vector.unproject( camera );
  19491. };
  19492. this.pickingRay = function ( vector, camera ) {
  19493. console.error( 'THREE.Projector: .pickingRay() is now raycaster.setFromCamera().' );
  19494. };
  19495. };
  19496. //
  19497. THREE.CanvasRenderer = function () {
  19498. console.error( 'THREE.CanvasRenderer has been moved to /examples/js/renderers/CanvasRenderer.js' );
  19499. this.domElement = document.createElement( 'canvas' );
  19500. this.clear = function () {};
  19501. this.render = function () {};
  19502. this.setClearColor = function () {};
  19503. this.setSize = function () {};
  19504. };
  19505. //
  19506. THREE.MeshFaceMaterial = THREE.MultiMaterial;
  19507. // File:src/extras/CurveUtils.js
  19508. /**
  19509. * @author zz85 / http://www.lab4games.net/zz85/blog
  19510. */
  19511. THREE.CurveUtils = {
  19512. tangentQuadraticBezier: function ( t, p0, p1, p2 ) {
  19513. return 2 * ( 1 - t ) * ( p1 - p0 ) + 2 * t * ( p2 - p1 );
  19514. },
  19515. // Puay Bing, thanks for helping with this derivative!
  19516. tangentCubicBezier: function ( t, p0, p1, p2, p3 ) {
  19517. return - 3 * p0 * ( 1 - t ) * ( 1 - t ) +
  19518. 3 * p1 * ( 1 - t ) * ( 1 - t ) - 6 * t * p1 * ( 1 - t ) +
  19519. 6 * t * p2 * ( 1 - t ) - 3 * t * t * p2 +
  19520. 3 * t * t * p3;
  19521. },
  19522. tangentSpline: function ( t, p0, p1, p2, p3 ) {
  19523. // To check if my formulas are correct
  19524. var h00 = 6 * t * t - 6 * t; // derived from 2t^3 − 3t^2 + 1
  19525. var h10 = 3 * t * t - 4 * t + 1; // t^3 − 2t^2 + t
  19526. var h01 = - 6 * t * t + 6 * t; // − 2t3 + 3t2
  19527. var h11 = 3 * t * t - 2 * t; // t3 − t2
  19528. return h00 + h10 + h01 + h11;
  19529. },
  19530. // Catmull-Rom
  19531. interpolate: function( p0, p1, p2, p3, t ) {
  19532. var v0 = ( p2 - p0 ) * 0.5;
  19533. var v1 = ( p3 - p1 ) * 0.5;
  19534. var t2 = t * t;
  19535. var t3 = t * t2;
  19536. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  19537. }
  19538. };
  19539. // File:src/extras/SceneUtils.js
  19540. /**
  19541. * @author alteredq / http://alteredqualia.com/
  19542. */
  19543. THREE.SceneUtils = {
  19544. createMultiMaterialObject: function ( geometry, materials ) {
  19545. var group = new THREE.Group();
  19546. for ( var i = 0, l = materials.length; i < l; i ++ ) {
  19547. group.add( new THREE.Mesh( geometry, materials[ i ] ) );
  19548. }
  19549. return group;
  19550. },
  19551. detach: function ( child, parent, scene ) {
  19552. child.applyMatrix( parent.matrixWorld );
  19553. parent.remove( child );
  19554. scene.add( child );
  19555. },
  19556. attach: function ( child, scene, parent ) {
  19557. var matrixWorldInverse = new THREE.Matrix4();
  19558. matrixWorldInverse.getInverse( parent.matrixWorld );
  19559. child.applyMatrix( matrixWorldInverse );
  19560. scene.remove( child );
  19561. parent.add( child );
  19562. }
  19563. };
  19564. // File:src/extras/ShapeUtils.js
  19565. /**
  19566. * @author zz85 / http://www.lab4games.net/zz85/blog
  19567. */
  19568. THREE.ShapeUtils = {
  19569. // calculate area of the contour polygon
  19570. area: function ( contour ) {
  19571. var n = contour.length;
  19572. var a = 0.0;
  19573. for ( var p = n - 1, q = 0; q < n; p = q ++ ) {
  19574. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  19575. }
  19576. return a * 0.5;
  19577. },
  19578. triangulate: ( function () {
  19579. /**
  19580. * This code is a quick port of code written in C++ which was submitted to
  19581. * flipcode.com by John W. Ratcliff // July 22, 2000
  19582. * See original code and more information here:
  19583. * http://www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml
  19584. *
  19585. * ported to actionscript by Zevan Rosser
  19586. * www.actionsnippet.com
  19587. *
  19588. * ported to javascript by Joshua Koo
  19589. * http://www.lab4games.net/zz85/blog
  19590. *
  19591. */
  19592. function snip( contour, u, v, w, n, verts ) {
  19593. var p;
  19594. var ax, ay, bx, by;
  19595. var cx, cy, px, py;
  19596. ax = contour[ verts[ u ] ].x;
  19597. ay = contour[ verts[ u ] ].y;
  19598. bx = contour[ verts[ v ] ].x;
  19599. by = contour[ verts[ v ] ].y;
  19600. cx = contour[ verts[ w ] ].x;
  19601. cy = contour[ verts[ w ] ].y;
  19602. if ( Number.EPSILON > ( ( ( bx - ax ) * ( cy - ay ) ) - ( ( by - ay ) * ( cx - ax ) ) ) ) return false;
  19603. var aX, aY, bX, bY, cX, cY;
  19604. var apx, apy, bpx, bpy, cpx, cpy;
  19605. var cCROSSap, bCROSScp, aCROSSbp;
  19606. aX = cx - bx; aY = cy - by;
  19607. bX = ax - cx; bY = ay - cy;
  19608. cX = bx - ax; cY = by - ay;
  19609. for ( p = 0; p < n; p ++ ) {
  19610. px = contour[ verts[ p ] ].x;
  19611. py = contour[ verts[ p ] ].y;
  19612. if ( ( ( px === ax ) && ( py === ay ) ) ||
  19613. ( ( px === bx ) && ( py === by ) ) ||
  19614. ( ( px === cx ) && ( py === cy ) ) ) continue;
  19615. apx = px - ax; apy = py - ay;
  19616. bpx = px - bx; bpy = py - by;
  19617. cpx = px - cx; cpy = py - cy;
  19618. // see if p is inside triangle abc
  19619. aCROSSbp = aX * bpy - aY * bpx;
  19620. cCROSSap = cX * apy - cY * apx;
  19621. bCROSScp = bX * cpy - bY * cpx;
  19622. if ( ( aCROSSbp >= - Number.EPSILON ) && ( bCROSScp >= - Number.EPSILON ) && ( cCROSSap >= - Number.EPSILON ) ) return false;
  19623. }
  19624. return true;
  19625. }
  19626. // takes in an contour array and returns
  19627. return function ( contour, indices ) {
  19628. var n = contour.length;
  19629. if ( n < 3 ) return null;
  19630. var result = [],
  19631. verts = [],
  19632. vertIndices = [];
  19633. /* we want a counter-clockwise polygon in verts */
  19634. var u, v, w;
  19635. if ( THREE.ShapeUtils.area( contour ) > 0.0 ) {
  19636. for ( v = 0; v < n; v ++ ) verts[ v ] = v;
  19637. } else {
  19638. for ( v = 0; v < n; v ++ ) verts[ v ] = ( n - 1 ) - v;
  19639. }
  19640. var nv = n;
  19641. /* remove nv - 2 vertices, creating 1 triangle every time */
  19642. var count = 2 * nv; /* error detection */
  19643. for ( v = nv - 1; nv > 2; ) {
  19644. /* if we loop, it is probably a non-simple polygon */
  19645. if ( ( count -- ) <= 0 ) {
  19646. //** Triangulate: ERROR - probable bad polygon!
  19647. //throw ( "Warning, unable to triangulate polygon!" );
  19648. //return null;
  19649. // Sometimes warning is fine, especially polygons are triangulated in reverse.
  19650. console.warn( 'THREE.ShapeUtils: Unable to triangulate polygon! in triangulate()' );
  19651. if ( indices ) return vertIndices;
  19652. return result;
  19653. }
  19654. /* three consecutive vertices in current polygon, <u,v,w> */
  19655. u = v; if ( nv <= u ) u = 0; /* previous */
  19656. v = u + 1; if ( nv <= v ) v = 0; /* new v */
  19657. w = v + 1; if ( nv <= w ) w = 0; /* next */
  19658. if ( snip( contour, u, v, w, nv, verts ) ) {
  19659. var a, b, c, s, t;
  19660. /* true names of the vertices */
  19661. a = verts[ u ];
  19662. b = verts[ v ];
  19663. c = verts[ w ];
  19664. /* output Triangle */
  19665. result.push( [ contour[ a ],
  19666. contour[ b ],
  19667. contour[ c ] ] );
  19668. vertIndices.push( [ verts[ u ], verts[ v ], verts[ w ] ] );
  19669. /* remove v from the remaining polygon */
  19670. for ( s = v, t = v + 1; t < nv; s ++, t ++ ) {
  19671. verts[ s ] = verts[ t ];
  19672. }
  19673. nv --;
  19674. /* reset error detection counter */
  19675. count = 2 * nv;
  19676. }
  19677. }
  19678. if ( indices ) return vertIndices;
  19679. return result;
  19680. }
  19681. } )(),
  19682. triangulateShape: function ( contour, holes ) {
  19683. function point_in_segment_2D_colin( inSegPt1, inSegPt2, inOtherPt ) {
  19684. // inOtherPt needs to be collinear to the inSegment
  19685. if ( inSegPt1.x !== inSegPt2.x ) {
  19686. if ( inSegPt1.x < inSegPt2.x ) {
  19687. return ( ( inSegPt1.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt2.x ) );
  19688. } else {
  19689. return ( ( inSegPt2.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt1.x ) );
  19690. }
  19691. } else {
  19692. if ( inSegPt1.y < inSegPt2.y ) {
  19693. return ( ( inSegPt1.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt2.y ) );
  19694. } else {
  19695. return ( ( inSegPt2.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt1.y ) );
  19696. }
  19697. }
  19698. }
  19699. function intersect_segments_2D( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1, inSeg2Pt2, inExcludeAdjacentSegs ) {
  19700. var seg1dx = inSeg1Pt2.x - inSeg1Pt1.x, seg1dy = inSeg1Pt2.y - inSeg1Pt1.y;
  19701. var seg2dx = inSeg2Pt2.x - inSeg2Pt1.x, seg2dy = inSeg2Pt2.y - inSeg2Pt1.y;
  19702. var seg1seg2dx = inSeg1Pt1.x - inSeg2Pt1.x;
  19703. var seg1seg2dy = inSeg1Pt1.y - inSeg2Pt1.y;
  19704. var limit = seg1dy * seg2dx - seg1dx * seg2dy;
  19705. var perpSeg1 = seg1dy * seg1seg2dx - seg1dx * seg1seg2dy;
  19706. if ( Math.abs( limit ) > Number.EPSILON ) {
  19707. // not parallel
  19708. var perpSeg2;
  19709. if ( limit > 0 ) {
  19710. if ( ( perpSeg1 < 0 ) || ( perpSeg1 > limit ) ) return [];
  19711. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  19712. if ( ( perpSeg2 < 0 ) || ( perpSeg2 > limit ) ) return [];
  19713. } else {
  19714. if ( ( perpSeg1 > 0 ) || ( perpSeg1 < limit ) ) return [];
  19715. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  19716. if ( ( perpSeg2 > 0 ) || ( perpSeg2 < limit ) ) return [];
  19717. }
  19718. // i.e. to reduce rounding errors
  19719. // intersection at endpoint of segment#1?
  19720. if ( perpSeg2 === 0 ) {
  19721. if ( ( inExcludeAdjacentSegs ) &&
  19722. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  19723. return [ inSeg1Pt1 ];
  19724. }
  19725. if ( perpSeg2 === limit ) {
  19726. if ( ( inExcludeAdjacentSegs ) &&
  19727. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  19728. return [ inSeg1Pt2 ];
  19729. }
  19730. // intersection at endpoint of segment#2?
  19731. if ( perpSeg1 === 0 ) return [ inSeg2Pt1 ];
  19732. if ( perpSeg1 === limit ) return [ inSeg2Pt2 ];
  19733. // return real intersection point
  19734. var factorSeg1 = perpSeg2 / limit;
  19735. return [ { x: inSeg1Pt1.x + factorSeg1 * seg1dx,
  19736. y: inSeg1Pt1.y + factorSeg1 * seg1dy } ];
  19737. } else {
  19738. // parallel or collinear
  19739. if ( ( perpSeg1 !== 0 ) ||
  19740. ( seg2dy * seg1seg2dx !== seg2dx * seg1seg2dy ) ) return [];
  19741. // they are collinear or degenerate
  19742. var seg1Pt = ( ( seg1dx === 0 ) && ( seg1dy === 0 ) ); // segment1 is just a point?
  19743. var seg2Pt = ( ( seg2dx === 0 ) && ( seg2dy === 0 ) ); // segment2 is just a point?
  19744. // both segments are points
  19745. if ( seg1Pt && seg2Pt ) {
  19746. if ( ( inSeg1Pt1.x !== inSeg2Pt1.x ) ||
  19747. ( inSeg1Pt1.y !== inSeg2Pt1.y ) ) return []; // they are distinct points
  19748. return [ inSeg1Pt1 ]; // they are the same point
  19749. }
  19750. // segment#1 is a single point
  19751. if ( seg1Pt ) {
  19752. if ( ! point_in_segment_2D_colin( inSeg2Pt1, inSeg2Pt2, inSeg1Pt1 ) ) return []; // but not in segment#2
  19753. return [ inSeg1Pt1 ];
  19754. }
  19755. // segment#2 is a single point
  19756. if ( seg2Pt ) {
  19757. if ( ! point_in_segment_2D_colin( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1 ) ) return []; // but not in segment#1
  19758. return [ inSeg2Pt1 ];
  19759. }
  19760. // they are collinear segments, which might overlap
  19761. var seg1min, seg1max, seg1minVal, seg1maxVal;
  19762. var seg2min, seg2max, seg2minVal, seg2maxVal;
  19763. if ( seg1dx !== 0 ) {
  19764. // the segments are NOT on a vertical line
  19765. if ( inSeg1Pt1.x < inSeg1Pt2.x ) {
  19766. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.x;
  19767. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.x;
  19768. } else {
  19769. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.x;
  19770. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.x;
  19771. }
  19772. if ( inSeg2Pt1.x < inSeg2Pt2.x ) {
  19773. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.x;
  19774. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.x;
  19775. } else {
  19776. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.x;
  19777. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.x;
  19778. }
  19779. } else {
  19780. // the segments are on a vertical line
  19781. if ( inSeg1Pt1.y < inSeg1Pt2.y ) {
  19782. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.y;
  19783. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.y;
  19784. } else {
  19785. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.y;
  19786. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.y;
  19787. }
  19788. if ( inSeg2Pt1.y < inSeg2Pt2.y ) {
  19789. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.y;
  19790. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.y;
  19791. } else {
  19792. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.y;
  19793. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.y;
  19794. }
  19795. }
  19796. if ( seg1minVal <= seg2minVal ) {
  19797. if ( seg1maxVal < seg2minVal ) return [];
  19798. if ( seg1maxVal === seg2minVal ) {
  19799. if ( inExcludeAdjacentSegs ) return [];
  19800. return [ seg2min ];
  19801. }
  19802. if ( seg1maxVal <= seg2maxVal ) return [ seg2min, seg1max ];
  19803. return [ seg2min, seg2max ];
  19804. } else {
  19805. if ( seg1minVal > seg2maxVal ) return [];
  19806. if ( seg1minVal === seg2maxVal ) {
  19807. if ( inExcludeAdjacentSegs ) return [];
  19808. return [ seg1min ];
  19809. }
  19810. if ( seg1maxVal <= seg2maxVal ) return [ seg1min, seg1max ];
  19811. return [ seg1min, seg2max ];
  19812. }
  19813. }
  19814. }
  19815. function isPointInsideAngle( inVertex, inLegFromPt, inLegToPt, inOtherPt ) {
  19816. // The order of legs is important
  19817. // translation of all points, so that Vertex is at (0,0)
  19818. var legFromPtX = inLegFromPt.x - inVertex.x, legFromPtY = inLegFromPt.y - inVertex.y;
  19819. var legToPtX = inLegToPt.x - inVertex.x, legToPtY = inLegToPt.y - inVertex.y;
  19820. var otherPtX = inOtherPt.x - inVertex.x, otherPtY = inOtherPt.y - inVertex.y;
  19821. // main angle >0: < 180 deg.; 0: 180 deg.; <0: > 180 deg.
  19822. var from2toAngle = legFromPtX * legToPtY - legFromPtY * legToPtX;
  19823. var from2otherAngle = legFromPtX * otherPtY - legFromPtY * otherPtX;
  19824. if ( Math.abs( from2toAngle ) > Number.EPSILON ) {
  19825. // angle != 180 deg.
  19826. var other2toAngle = otherPtX * legToPtY - otherPtY * legToPtX;
  19827. // console.log( "from2to: " + from2toAngle + ", from2other: " + from2otherAngle + ", other2to: " + other2toAngle );
  19828. if ( from2toAngle > 0 ) {
  19829. // main angle < 180 deg.
  19830. return ( ( from2otherAngle >= 0 ) && ( other2toAngle >= 0 ) );
  19831. } else {
  19832. // main angle > 180 deg.
  19833. return ( ( from2otherAngle >= 0 ) || ( other2toAngle >= 0 ) );
  19834. }
  19835. } else {
  19836. // angle == 180 deg.
  19837. // console.log( "from2to: 180 deg., from2other: " + from2otherAngle );
  19838. return ( from2otherAngle > 0 );
  19839. }
  19840. }
  19841. function removeHoles( contour, holes ) {
  19842. var shape = contour.concat(); // work on this shape
  19843. var hole;
  19844. function isCutLineInsideAngles( inShapeIdx, inHoleIdx ) {
  19845. // Check if hole point lies within angle around shape point
  19846. var lastShapeIdx = shape.length - 1;
  19847. var prevShapeIdx = inShapeIdx - 1;
  19848. if ( prevShapeIdx < 0 ) prevShapeIdx = lastShapeIdx;
  19849. var nextShapeIdx = inShapeIdx + 1;
  19850. if ( nextShapeIdx > lastShapeIdx ) nextShapeIdx = 0;
  19851. var insideAngle = isPointInsideAngle( shape[ inShapeIdx ], shape[ prevShapeIdx ], shape[ nextShapeIdx ], hole[ inHoleIdx ] );
  19852. if ( ! insideAngle ) {
  19853. // console.log( "Vertex (Shape): " + inShapeIdx + ", Point: " + hole[inHoleIdx].x + "/" + hole[inHoleIdx].y );
  19854. return false;
  19855. }
  19856. // Check if shape point lies within angle around hole point
  19857. var lastHoleIdx = hole.length - 1;
  19858. var prevHoleIdx = inHoleIdx - 1;
  19859. if ( prevHoleIdx < 0 ) prevHoleIdx = lastHoleIdx;
  19860. var nextHoleIdx = inHoleIdx + 1;
  19861. if ( nextHoleIdx > lastHoleIdx ) nextHoleIdx = 0;
  19862. insideAngle = isPointInsideAngle( hole[ inHoleIdx ], hole[ prevHoleIdx ], hole[ nextHoleIdx ], shape[ inShapeIdx ] );
  19863. if ( ! insideAngle ) {
  19864. // console.log( "Vertex (Hole): " + inHoleIdx + ", Point: " + shape[inShapeIdx].x + "/" + shape[inShapeIdx].y );
  19865. return false;
  19866. }
  19867. return true;
  19868. }
  19869. function intersectsShapeEdge( inShapePt, inHolePt ) {
  19870. // checks for intersections with shape edges
  19871. var sIdx, nextIdx, intersection;
  19872. for ( sIdx = 0; sIdx < shape.length; sIdx ++ ) {
  19873. nextIdx = sIdx + 1; nextIdx %= shape.length;
  19874. intersection = intersect_segments_2D( inShapePt, inHolePt, shape[ sIdx ], shape[ nextIdx ], true );
  19875. if ( intersection.length > 0 ) return true;
  19876. }
  19877. return false;
  19878. }
  19879. var indepHoles = [];
  19880. function intersectsHoleEdge( inShapePt, inHolePt ) {
  19881. // checks for intersections with hole edges
  19882. var ihIdx, chkHole,
  19883. hIdx, nextIdx, intersection;
  19884. for ( ihIdx = 0; ihIdx < indepHoles.length; ihIdx ++ ) {
  19885. chkHole = holes[ indepHoles[ ihIdx ]];
  19886. for ( hIdx = 0; hIdx < chkHole.length; hIdx ++ ) {
  19887. nextIdx = hIdx + 1; nextIdx %= chkHole.length;
  19888. intersection = intersect_segments_2D( inShapePt, inHolePt, chkHole[ hIdx ], chkHole[ nextIdx ], true );
  19889. if ( intersection.length > 0 ) return true;
  19890. }
  19891. }
  19892. return false;
  19893. }
  19894. var holeIndex, shapeIndex,
  19895. shapePt, holePt,
  19896. holeIdx, cutKey, failedCuts = [],
  19897. tmpShape1, tmpShape2,
  19898. tmpHole1, tmpHole2;
  19899. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  19900. indepHoles.push( h );
  19901. }
  19902. var minShapeIndex = 0;
  19903. var counter = indepHoles.length * 2;
  19904. while ( indepHoles.length > 0 ) {
  19905. counter --;
  19906. if ( counter < 0 ) {
  19907. console.log( "Infinite Loop! Holes left:" + indepHoles.length + ", Probably Hole outside Shape!" );
  19908. break;
  19909. }
  19910. // search for shape-vertex and hole-vertex,
  19911. // which can be connected without intersections
  19912. for ( shapeIndex = minShapeIndex; shapeIndex < shape.length; shapeIndex ++ ) {
  19913. shapePt = shape[ shapeIndex ];
  19914. holeIndex = - 1;
  19915. // search for hole which can be reached without intersections
  19916. for ( var h = 0; h < indepHoles.length; h ++ ) {
  19917. holeIdx = indepHoles[ h ];
  19918. // prevent multiple checks
  19919. cutKey = shapePt.x + ":" + shapePt.y + ":" + holeIdx;
  19920. if ( failedCuts[ cutKey ] !== undefined ) continue;
  19921. hole = holes[ holeIdx ];
  19922. for ( var h2 = 0; h2 < hole.length; h2 ++ ) {
  19923. holePt = hole[ h2 ];
  19924. if ( ! isCutLineInsideAngles( shapeIndex, h2 ) ) continue;
  19925. if ( intersectsShapeEdge( shapePt, holePt ) ) continue;
  19926. if ( intersectsHoleEdge( shapePt, holePt ) ) continue;
  19927. holeIndex = h2;
  19928. indepHoles.splice( h, 1 );
  19929. tmpShape1 = shape.slice( 0, shapeIndex + 1 );
  19930. tmpShape2 = shape.slice( shapeIndex );
  19931. tmpHole1 = hole.slice( holeIndex );
  19932. tmpHole2 = hole.slice( 0, holeIndex + 1 );
  19933. shape = tmpShape1.concat( tmpHole1 ).concat( tmpHole2 ).concat( tmpShape2 );
  19934. minShapeIndex = shapeIndex;
  19935. // Debug only, to show the selected cuts
  19936. // glob_CutLines.push( [ shapePt, holePt ] );
  19937. break;
  19938. }
  19939. if ( holeIndex >= 0 ) break; // hole-vertex found
  19940. failedCuts[ cutKey ] = true; // remember failure
  19941. }
  19942. if ( holeIndex >= 0 ) break; // hole-vertex found
  19943. }
  19944. }
  19945. return shape; /* shape with no holes */
  19946. }
  19947. var i, il, f, face,
  19948. key, index,
  19949. allPointsMap = {};
  19950. // 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.
  19951. var allpoints = contour.concat();
  19952. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  19953. Array.prototype.push.apply( allpoints, holes[ h ] );
  19954. }
  19955. //console.log( "allpoints",allpoints, allpoints.length );
  19956. // prepare all points map
  19957. for ( i = 0, il = allpoints.length; i < il; i ++ ) {
  19958. key = allpoints[ i ].x + ":" + allpoints[ i ].y;
  19959. if ( allPointsMap[ key ] !== undefined ) {
  19960. console.warn( "THREE.Shape: Duplicate point", key );
  19961. }
  19962. allPointsMap[ key ] = i;
  19963. }
  19964. // remove holes by cutting paths to holes and adding them to the shape
  19965. var shapeWithoutHoles = removeHoles( contour, holes );
  19966. var triangles = THREE.ShapeUtils.triangulate( shapeWithoutHoles, false ); // True returns indices for points of spooled shape
  19967. //console.log( "triangles",triangles, triangles.length );
  19968. // check all face vertices against all points map
  19969. for ( i = 0, il = triangles.length; i < il; i ++ ) {
  19970. face = triangles[ i ];
  19971. for ( f = 0; f < 3; f ++ ) {
  19972. key = face[ f ].x + ":" + face[ f ].y;
  19973. index = allPointsMap[ key ];
  19974. if ( index !== undefined ) {
  19975. face[ f ] = index;
  19976. }
  19977. }
  19978. }
  19979. return triangles.concat();
  19980. },
  19981. isClockWise: function ( pts ) {
  19982. return THREE.ShapeUtils.area( pts ) < 0;
  19983. },
  19984. // Bezier Curves formulas obtained from
  19985. // http://en.wikipedia.org/wiki/B%C3%A9zier_curve
  19986. // Quad Bezier Functions
  19987. b2: ( function () {
  19988. function b2p0( t, p ) {
  19989. var k = 1 - t;
  19990. return k * k * p;
  19991. }
  19992. function b2p1( t, p ) {
  19993. return 2 * ( 1 - t ) * t * p;
  19994. }
  19995. function b2p2( t, p ) {
  19996. return t * t * p;
  19997. }
  19998. return function ( t, p0, p1, p2 ) {
  19999. return b2p0( t, p0 ) + b2p1( t, p1 ) + b2p2( t, p2 );
  20000. };
  20001. } )(),
  20002. // Cubic Bezier Functions
  20003. b3: ( function () {
  20004. function b3p0( t, p ) {
  20005. var k = 1 - t;
  20006. return k * k * k * p;
  20007. }
  20008. function b3p1( t, p ) {
  20009. var k = 1 - t;
  20010. return 3 * k * k * t * p;
  20011. }
  20012. function b3p2( t, p ) {
  20013. var k = 1 - t;
  20014. return 3 * k * t * t * p;
  20015. }
  20016. function b3p3( t, p ) {
  20017. return t * t * t * p;
  20018. }
  20019. return function ( t, p0, p1, p2, p3 ) {
  20020. return b3p0( t, p0 ) + b3p1( t, p1 ) + b3p2( t, p2 ) + b3p3( t, p3 );
  20021. };
  20022. } )()
  20023. };
  20024. // File:src/extras/core/Curve.js
  20025. /**
  20026. * @author zz85 / http://www.lab4games.net/zz85/blog
  20027. * Extensible curve object
  20028. *
  20029. * Some common of Curve methods
  20030. * .getPoint(t), getTangent(t)
  20031. * .getPointAt(u), getTagentAt(u)
  20032. * .getPoints(), .getSpacedPoints()
  20033. * .getLength()
  20034. * .updateArcLengths()
  20035. *
  20036. * This following classes subclasses THREE.Curve:
  20037. *
  20038. * -- 2d classes --
  20039. * THREE.LineCurve
  20040. * THREE.QuadraticBezierCurve
  20041. * THREE.CubicBezierCurve
  20042. * THREE.SplineCurve
  20043. * THREE.ArcCurve
  20044. * THREE.EllipseCurve
  20045. *
  20046. * -- 3d classes --
  20047. * THREE.LineCurve3
  20048. * THREE.QuadraticBezierCurve3
  20049. * THREE.CubicBezierCurve3
  20050. * THREE.SplineCurve3
  20051. * THREE.ClosedSplineCurve3
  20052. *
  20053. * A series of curves can be represented as a THREE.CurvePath
  20054. *
  20055. **/
  20056. /**************************************************************
  20057. * Abstract Curve base class
  20058. **************************************************************/
  20059. THREE.Curve = function () {
  20060. };
  20061. THREE.Curve.prototype = {
  20062. constructor: THREE.Curve,
  20063. // Virtual base class method to overwrite and implement in subclasses
  20064. // - t [0 .. 1]
  20065. getPoint: function ( t ) {
  20066. console.warn( "THREE.Curve: Warning, getPoint() not implemented!" );
  20067. return null;
  20068. },
  20069. // Get point at relative position in curve according to arc length
  20070. // - u [0 .. 1]
  20071. getPointAt: function ( u ) {
  20072. var t = this.getUtoTmapping( u );
  20073. return this.getPoint( t );
  20074. },
  20075. // Get sequence of points using getPoint( t )
  20076. getPoints: function ( divisions ) {
  20077. if ( ! divisions ) divisions = 5;
  20078. var d, pts = [];
  20079. for ( d = 0; d <= divisions; d ++ ) {
  20080. pts.push( this.getPoint( d / divisions ) );
  20081. }
  20082. return pts;
  20083. },
  20084. // Get sequence of points using getPointAt( u )
  20085. getSpacedPoints: function ( divisions ) {
  20086. if ( ! divisions ) divisions = 5;
  20087. var d, pts = [];
  20088. for ( d = 0; d <= divisions; d ++ ) {
  20089. pts.push( this.getPointAt( d / divisions ) );
  20090. }
  20091. return pts;
  20092. },
  20093. // Get total curve arc length
  20094. getLength: function () {
  20095. var lengths = this.getLengths();
  20096. return lengths[ lengths.length - 1 ];
  20097. },
  20098. // Get list of cumulative segment lengths
  20099. getLengths: function ( divisions ) {
  20100. if ( ! divisions ) divisions = ( this.__arcLengthDivisions ) ? ( this.__arcLengthDivisions ) : 200;
  20101. if ( this.cacheArcLengths
  20102. && ( this.cacheArcLengths.length === divisions + 1 )
  20103. && ! this.needsUpdate ) {
  20104. //console.log( "cached", this.cacheArcLengths );
  20105. return this.cacheArcLengths;
  20106. }
  20107. this.needsUpdate = false;
  20108. var cache = [];
  20109. var current, last = this.getPoint( 0 );
  20110. var p, sum = 0;
  20111. cache.push( 0 );
  20112. for ( p = 1; p <= divisions; p ++ ) {
  20113. current = this.getPoint ( p / divisions );
  20114. sum += current.distanceTo( last );
  20115. cache.push( sum );
  20116. last = current;
  20117. }
  20118. this.cacheArcLengths = cache;
  20119. return cache; // { sums: cache, sum:sum }; Sum is in the last element.
  20120. },
  20121. updateArcLengths: function() {
  20122. this.needsUpdate = true;
  20123. this.getLengths();
  20124. },
  20125. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  20126. getUtoTmapping: function ( u, distance ) {
  20127. var arcLengths = this.getLengths();
  20128. var i = 0, il = arcLengths.length;
  20129. var targetArcLength; // The targeted u distance value to get
  20130. if ( distance ) {
  20131. targetArcLength = distance;
  20132. } else {
  20133. targetArcLength = u * arcLengths[ il - 1 ];
  20134. }
  20135. //var time = Date.now();
  20136. // binary search for the index with largest value smaller than target u distance
  20137. var low = 0, high = il - 1, comparison;
  20138. while ( low <= high ) {
  20139. 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
  20140. comparison = arcLengths[ i ] - targetArcLength;
  20141. if ( comparison < 0 ) {
  20142. low = i + 1;
  20143. } else if ( comparison > 0 ) {
  20144. high = i - 1;
  20145. } else {
  20146. high = i;
  20147. break;
  20148. // DONE
  20149. }
  20150. }
  20151. i = high;
  20152. //console.log('b' , i, low, high, Date.now()- time);
  20153. if ( arcLengths[ i ] === targetArcLength ) {
  20154. var t = i / ( il - 1 );
  20155. return t;
  20156. }
  20157. // we could get finer grain at lengths, or use simple interpolation between two points
  20158. var lengthBefore = arcLengths[ i ];
  20159. var lengthAfter = arcLengths[ i + 1 ];
  20160. var segmentLength = lengthAfter - lengthBefore;
  20161. // determine where we are between the 'before' and 'after' points
  20162. var segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  20163. // add that fractional amount to t
  20164. var t = ( i + segmentFraction ) / ( il - 1 );
  20165. return t;
  20166. },
  20167. // Returns a unit vector tangent at t
  20168. // In case any sub curve does not implement its tangent derivation,
  20169. // 2 points a small delta apart will be used to find its gradient
  20170. // which seems to give a reasonable approximation
  20171. getTangent: function( t ) {
  20172. var delta = 0.0001;
  20173. var t1 = t - delta;
  20174. var t2 = t + delta;
  20175. // Capping in case of danger
  20176. if ( t1 < 0 ) t1 = 0;
  20177. if ( t2 > 1 ) t2 = 1;
  20178. var pt1 = this.getPoint( t1 );
  20179. var pt2 = this.getPoint( t2 );
  20180. var vec = pt2.clone().sub( pt1 );
  20181. return vec.normalize();
  20182. },
  20183. getTangentAt: function ( u ) {
  20184. var t = this.getUtoTmapping( u );
  20185. return this.getTangent( t );
  20186. }
  20187. };
  20188. // TODO: Transformation for Curves?
  20189. /**************************************************************
  20190. * 3D Curves
  20191. **************************************************************/
  20192. // A Factory method for creating new curve subclasses
  20193. THREE.Curve.create = function ( constructor, getPointFunc ) {
  20194. constructor.prototype = Object.create( THREE.Curve.prototype );
  20195. constructor.prototype.constructor = constructor;
  20196. constructor.prototype.getPoint = getPointFunc;
  20197. return constructor;
  20198. };
  20199. // File:src/extras/core/CurvePath.js
  20200. /**
  20201. * @author zz85 / http://www.lab4games.net/zz85/blog
  20202. *
  20203. **/
  20204. /**************************************************************
  20205. * Curved Path - a curve path is simply a array of connected
  20206. * curves, but retains the api of a curve
  20207. **************************************************************/
  20208. THREE.CurvePath = function () {
  20209. this.curves = [];
  20210. this.autoClose = false; // Automatically closes the path
  20211. };
  20212. THREE.CurvePath.prototype = Object.create( THREE.Curve.prototype );
  20213. THREE.CurvePath.prototype.constructor = THREE.CurvePath;
  20214. THREE.CurvePath.prototype.add = function ( curve ) {
  20215. this.curves.push( curve );
  20216. };
  20217. /*
  20218. THREE.CurvePath.prototype.checkConnection = function() {
  20219. // TODO
  20220. // If the ending of curve is not connected to the starting
  20221. // or the next curve, then, this is not a real path
  20222. };
  20223. */
  20224. THREE.CurvePath.prototype.closePath = function() {
  20225. // TODO Test
  20226. // and verify for vector3 (needs to implement equals)
  20227. // Add a line curve if start and end of lines are not connected
  20228. var startPoint = this.curves[ 0 ].getPoint( 0 );
  20229. var endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
  20230. if ( ! startPoint.equals( endPoint ) ) {
  20231. this.curves.push( new THREE.LineCurve( endPoint, startPoint ) );
  20232. }
  20233. };
  20234. // To get accurate point with reference to
  20235. // entire path distance at time t,
  20236. // following has to be done:
  20237. // 1. Length of each sub path have to be known
  20238. // 2. Locate and identify type of curve
  20239. // 3. Get t for the curve
  20240. // 4. Return curve.getPointAt(t')
  20241. THREE.CurvePath.prototype.getPoint = function( t ) {
  20242. var d = t * this.getLength();
  20243. var curveLengths = this.getCurveLengths();
  20244. var i = 0;
  20245. // To think about boundaries points.
  20246. while ( i < curveLengths.length ) {
  20247. if ( curveLengths[ i ] >= d ) {
  20248. var diff = curveLengths[ i ] - d;
  20249. var curve = this.curves[ i ];
  20250. var u = 1 - diff / curve.getLength();
  20251. return curve.getPointAt( u );
  20252. }
  20253. i ++;
  20254. }
  20255. return null;
  20256. // loop where sum != 0, sum > d , sum+1 <d
  20257. };
  20258. /*
  20259. THREE.CurvePath.prototype.getTangent = function( t ) {
  20260. };
  20261. */
  20262. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  20263. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  20264. // getPoint() depends on getLength
  20265. THREE.CurvePath.prototype.getLength = function() {
  20266. var lens = this.getCurveLengths();
  20267. return lens[ lens.length - 1 ];
  20268. };
  20269. // Compute lengths and cache them
  20270. // We cannot overwrite getLengths() because UtoT mapping uses it.
  20271. THREE.CurvePath.prototype.getCurveLengths = function() {
  20272. // We use cache values if curves and cache array are same length
  20273. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  20274. return this.cacheLengths;
  20275. }
  20276. // Get length of sub-curve
  20277. // Push sums into cached array
  20278. var lengths = [], sums = 0;
  20279. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  20280. sums += this.curves[ i ].getLength();
  20281. lengths.push( sums );
  20282. }
  20283. this.cacheLengths = lengths;
  20284. return lengths;
  20285. };
  20286. /**************************************************************
  20287. * Create Geometries Helpers
  20288. **************************************************************/
  20289. /// Generate geometry from path points (for Line or Points objects)
  20290. THREE.CurvePath.prototype.createPointsGeometry = function( divisions ) {
  20291. var pts = this.getPoints( divisions );
  20292. return this.createGeometry( pts );
  20293. };
  20294. // Generate geometry from equidistant sampling along the path
  20295. THREE.CurvePath.prototype.createSpacedPointsGeometry = function( divisions ) {
  20296. var pts = this.getSpacedPoints( divisions );
  20297. return this.createGeometry( pts );
  20298. };
  20299. THREE.CurvePath.prototype.createGeometry = function( points ) {
  20300. var geometry = new THREE.Geometry();
  20301. for ( var i = 0, l = points.length; i < l; i ++ ) {
  20302. var point = points[ i ];
  20303. geometry.vertices.push( new THREE.Vector3( point.x, point.y, point.z || 0 ) );
  20304. }
  20305. return geometry;
  20306. };
  20307. // File:src/extras/core/Font.js
  20308. /**
  20309. * @author zz85 / http://www.lab4games.net/zz85/blog
  20310. * @author mrdoob / http://mrdoob.com/
  20311. */
  20312. THREE.Font = function ( data ) {
  20313. this.data = data;
  20314. };
  20315. THREE.Font.prototype = {
  20316. constructor: THREE.Font,
  20317. generateShapes: function ( text, size, divisions ) {
  20318. function createPaths( text ) {
  20319. var chars = String( text ).split( '' );
  20320. var scale = size / data.resolution;
  20321. var offset = 0;
  20322. var paths = [];
  20323. for ( var i = 0; i < chars.length; i ++ ) {
  20324. var ret = createPath( chars[ i ], scale, offset );
  20325. offset += ret.offset;
  20326. paths.push( ret.path );
  20327. }
  20328. return paths;
  20329. }
  20330. function createPath( c, scale, offset ) {
  20331. var glyph = data.glyphs[ c ] || data.glyphs[ '?' ];
  20332. if ( ! glyph ) return;
  20333. var path = new THREE.Path();
  20334. var pts = [], b2 = THREE.ShapeUtils.b2, b3 = THREE.ShapeUtils.b3;
  20335. var x, y, cpx, cpy, cpx0, cpy0, cpx1, cpy1, cpx2, cpy2, laste;
  20336. if ( glyph.o ) {
  20337. var outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) );
  20338. for ( var i = 0, l = outline.length; i < l; ) {
  20339. var action = outline[ i ++ ];
  20340. switch ( action ) {
  20341. case 'm': // moveTo
  20342. x = outline[ i ++ ] * scale + offset;
  20343. y = outline[ i ++ ] * scale;
  20344. path.moveTo( x, y );
  20345. break;
  20346. case 'l': // lineTo
  20347. x = outline[ i ++ ] * scale + offset;
  20348. y = outline[ i ++ ] * scale;
  20349. path.lineTo( x, y );
  20350. break;
  20351. case 'q': // quadraticCurveTo
  20352. cpx = outline[ i ++ ] * scale + offset;
  20353. cpy = outline[ i ++ ] * scale;
  20354. cpx1 = outline[ i ++ ] * scale + offset;
  20355. cpy1 = outline[ i ++ ] * scale;
  20356. path.quadraticCurveTo( cpx1, cpy1, cpx, cpy );
  20357. laste = pts[ pts.length - 1 ];
  20358. if ( laste ) {
  20359. cpx0 = laste.x;
  20360. cpy0 = laste.y;
  20361. for ( var i2 = 1; i2 <= divisions; i2 ++ ) {
  20362. var t = i2 / divisions;
  20363. b2( t, cpx0, cpx1, cpx );
  20364. b2( t, cpy0, cpy1, cpy );
  20365. }
  20366. }
  20367. break;
  20368. case 'b': // bezierCurveTo
  20369. cpx = outline[ i ++ ] * scale + offset;
  20370. cpy = outline[ i ++ ] * scale;
  20371. cpx1 = outline[ i ++ ] * scale + offset;
  20372. cpy1 = outline[ i ++ ] * scale;
  20373. cpx2 = outline[ i ++ ] * scale + offset;
  20374. cpy2 = outline[ i ++ ] * scale;
  20375. path.bezierCurveTo( cpx1, cpy1, cpx2, cpy2, cpx, cpy );
  20376. laste = pts[ pts.length - 1 ];
  20377. if ( laste ) {
  20378. cpx0 = laste.x;
  20379. cpy0 = laste.y;
  20380. for ( var i2 = 1; i2 <= divisions; i2 ++ ) {
  20381. var t = i2 / divisions;
  20382. b3( t, cpx0, cpx1, cpx2, cpx );
  20383. b3( t, cpy0, cpy1, cpy2, cpy );
  20384. }
  20385. }
  20386. break;
  20387. }
  20388. }
  20389. }
  20390. return { offset: glyph.ha * scale, path: path };
  20391. }
  20392. //
  20393. if ( size === undefined ) size = 100;
  20394. if ( divisions === undefined ) divisions = 4;
  20395. var data = this.data;
  20396. var paths = createPaths( text );
  20397. var shapes = [];
  20398. for ( var p = 0, pl = paths.length; p < pl; p ++ ) {
  20399. Array.prototype.push.apply( shapes, paths[ p ].toShapes() );
  20400. }
  20401. return shapes;
  20402. }
  20403. };
  20404. // File:src/extras/core/Path.js
  20405. /**
  20406. * @author zz85 / http://www.lab4games.net/zz85/blog
  20407. * Creates free form 2d path using series of points, lines or curves.
  20408. *
  20409. **/
  20410. THREE.Path = function ( points ) {
  20411. THREE.CurvePath.call( this );
  20412. this.actions = [];
  20413. if ( points ) {
  20414. this.fromPoints( points );
  20415. }
  20416. };
  20417. THREE.Path.prototype = Object.create( THREE.CurvePath.prototype );
  20418. THREE.Path.prototype.constructor = THREE.Path;
  20419. // TODO Clean up PATH API
  20420. // Create path using straight lines to connect all points
  20421. // - vectors: array of Vector2
  20422. THREE.Path.prototype.fromPoints = function ( vectors ) {
  20423. this.moveTo( vectors[ 0 ].x, vectors[ 0 ].y );
  20424. for ( var i = 1, l = vectors.length; i < l; i ++ ) {
  20425. this.lineTo( vectors[ i ].x, vectors[ i ].y );
  20426. }
  20427. };
  20428. // startPath() endPath()?
  20429. THREE.Path.prototype.moveTo = function ( x, y ) {
  20430. this.actions.push( { action: 'moveTo', args: [ x, y ] } );
  20431. };
  20432. THREE.Path.prototype.lineTo = function ( x, y ) {
  20433. var lastargs = this.actions[ this.actions.length - 1 ].args;
  20434. var x0 = lastargs[ lastargs.length - 2 ];
  20435. var y0 = lastargs[ lastargs.length - 1 ];
  20436. var curve = new THREE.LineCurve( new THREE.Vector2( x0, y0 ), new THREE.Vector2( x, y ) );
  20437. this.curves.push( curve );
  20438. this.actions.push( { action: 'lineTo', args: [ x, y ] } );
  20439. };
  20440. THREE.Path.prototype.quadraticCurveTo = function( aCPx, aCPy, aX, aY ) {
  20441. var lastargs = this.actions[ this.actions.length - 1 ].args;
  20442. var x0 = lastargs[ lastargs.length - 2 ];
  20443. var y0 = lastargs[ lastargs.length - 1 ];
  20444. var curve = new THREE.QuadraticBezierCurve(
  20445. new THREE.Vector2( x0, y0 ),
  20446. new THREE.Vector2( aCPx, aCPy ),
  20447. new THREE.Vector2( aX, aY )
  20448. );
  20449. this.curves.push( curve );
  20450. this.actions.push( { action: 'quadraticCurveTo', args: [ aCPx, aCPy, aX, aY ] } );
  20451. };
  20452. THREE.Path.prototype.bezierCurveTo = function( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  20453. var lastargs = this.actions[ this.actions.length - 1 ].args;
  20454. var x0 = lastargs[ lastargs.length - 2 ];
  20455. var y0 = lastargs[ lastargs.length - 1 ];
  20456. var curve = new THREE.CubicBezierCurve(
  20457. new THREE.Vector2( x0, y0 ),
  20458. new THREE.Vector2( aCP1x, aCP1y ),
  20459. new THREE.Vector2( aCP2x, aCP2y ),
  20460. new THREE.Vector2( aX, aY )
  20461. );
  20462. this.curves.push( curve );
  20463. this.actions.push( { action: 'bezierCurveTo', args: [ aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ] } );
  20464. };
  20465. THREE.Path.prototype.splineThru = function( pts /*Array of Vector*/ ) {
  20466. var args = Array.prototype.slice.call( arguments );
  20467. var lastargs = this.actions[ this.actions.length - 1 ].args;
  20468. var x0 = lastargs[ lastargs.length - 2 ];
  20469. var y0 = lastargs[ lastargs.length - 1 ];
  20470. var npts = [ new THREE.Vector2( x0, y0 ) ];
  20471. Array.prototype.push.apply( npts, pts );
  20472. var curve = new THREE.SplineCurve( npts );
  20473. this.curves.push( curve );
  20474. this.actions.push( { action: 'splineThru', args: args } );
  20475. };
  20476. // FUTURE: Change the API or follow canvas API?
  20477. THREE.Path.prototype.arc = function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  20478. var lastargs = this.actions[ this.actions.length - 1 ].args;
  20479. var x0 = lastargs[ lastargs.length - 2 ];
  20480. var y0 = lastargs[ lastargs.length - 1 ];
  20481. this.absarc( aX + x0, aY + y0, aRadius,
  20482. aStartAngle, aEndAngle, aClockwise );
  20483. };
  20484. THREE.Path.prototype.absarc = function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  20485. this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  20486. };
  20487. THREE.Path.prototype.ellipse = function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  20488. var lastargs = this.actions[ this.actions.length - 1 ].args;
  20489. var x0 = lastargs[ lastargs.length - 2 ];
  20490. var y0 = lastargs[ lastargs.length - 1 ];
  20491. this.absellipse( aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  20492. };
  20493. THREE.Path.prototype.absellipse = function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  20494. var args = [
  20495. aX, aY,
  20496. xRadius, yRadius,
  20497. aStartAngle, aEndAngle,
  20498. aClockwise,
  20499. aRotation || 0 // aRotation is optional.
  20500. ];
  20501. var curve = new THREE.EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  20502. this.curves.push( curve );
  20503. var lastPoint = curve.getPoint( 1 );
  20504. args.push( lastPoint.x );
  20505. args.push( lastPoint.y );
  20506. this.actions.push( { action: 'ellipse', args: args } );
  20507. };
  20508. THREE.Path.prototype.getSpacedPoints = function ( divisions ) {
  20509. if ( ! divisions ) divisions = 40;
  20510. var points = [];
  20511. for ( var i = 0; i < divisions; i ++ ) {
  20512. points.push( this.getPoint( i / divisions ) );
  20513. //if ( !this.getPoint( i / divisions ) ) throw "DIE";
  20514. }
  20515. if ( this.autoClose ) {
  20516. points.push( points[ 0 ] );
  20517. }
  20518. return points;
  20519. };
  20520. /* Return an array of vectors based on contour of the path */
  20521. THREE.Path.prototype.getPoints = function( divisions ) {
  20522. divisions = divisions || 12;
  20523. var b2 = THREE.ShapeUtils.b2;
  20524. var b3 = THREE.ShapeUtils.b3;
  20525. var points = [];
  20526. var cpx, cpy, cpx2, cpy2, cpx1, cpy1, cpx0, cpy0,
  20527. laste, tx, ty;
  20528. for ( var i = 0, l = this.actions.length; i < l; i ++ ) {
  20529. var item = this.actions[ i ];
  20530. var action = item.action;
  20531. var args = item.args;
  20532. switch ( action ) {
  20533. case 'moveTo':
  20534. points.push( new THREE.Vector2( args[ 0 ], args[ 1 ] ) );
  20535. break;
  20536. case 'lineTo':
  20537. points.push( new THREE.Vector2( args[ 0 ], args[ 1 ] ) );
  20538. break;
  20539. case 'quadraticCurveTo':
  20540. cpx = args[ 2 ];
  20541. cpy = args[ 3 ];
  20542. cpx1 = args[ 0 ];
  20543. cpy1 = args[ 1 ];
  20544. if ( points.length > 0 ) {
  20545. laste = points[ points.length - 1 ];
  20546. cpx0 = laste.x;
  20547. cpy0 = laste.y;
  20548. } else {
  20549. laste = this.actions[ i - 1 ].args;
  20550. cpx0 = laste[ laste.length - 2 ];
  20551. cpy0 = laste[ laste.length - 1 ];
  20552. }
  20553. for ( var j = 1; j <= divisions; j ++ ) {
  20554. var t = j / divisions;
  20555. tx = b2( t, cpx0, cpx1, cpx );
  20556. ty = b2( t, cpy0, cpy1, cpy );
  20557. points.push( new THREE.Vector2( tx, ty ) );
  20558. }
  20559. break;
  20560. case 'bezierCurveTo':
  20561. cpx = args[ 4 ];
  20562. cpy = args[ 5 ];
  20563. cpx1 = args[ 0 ];
  20564. cpy1 = args[ 1 ];
  20565. cpx2 = args[ 2 ];
  20566. cpy2 = args[ 3 ];
  20567. if ( points.length > 0 ) {
  20568. laste = points[ points.length - 1 ];
  20569. cpx0 = laste.x;
  20570. cpy0 = laste.y;
  20571. } else {
  20572. laste = this.actions[ i - 1 ].args;
  20573. cpx0 = laste[ laste.length - 2 ];
  20574. cpy0 = laste[ laste.length - 1 ];
  20575. }
  20576. for ( var j = 1; j <= divisions; j ++ ) {
  20577. var t = j / divisions;
  20578. tx = b3( t, cpx0, cpx1, cpx2, cpx );
  20579. ty = b3( t, cpy0, cpy1, cpy2, cpy );
  20580. points.push( new THREE.Vector2( tx, ty ) );
  20581. }
  20582. break;
  20583. case 'splineThru':
  20584. laste = this.actions[ i - 1 ].args;
  20585. var last = new THREE.Vector2( laste[ laste.length - 2 ], laste[ laste.length - 1 ] );
  20586. var spts = [ last ];
  20587. var n = divisions * args[ 0 ].length;
  20588. spts = spts.concat( args[ 0 ] );
  20589. var spline = new THREE.SplineCurve( spts );
  20590. for ( var j = 1; j <= n; j ++ ) {
  20591. points.push( spline.getPointAt( j / n ) );
  20592. }
  20593. break;
  20594. case 'arc':
  20595. var aX = args[ 0 ], aY = args[ 1 ],
  20596. aRadius = args[ 2 ],
  20597. aStartAngle = args[ 3 ], aEndAngle = args[ 4 ],
  20598. aClockwise = !! args[ 5 ];
  20599. var deltaAngle = aEndAngle - aStartAngle;
  20600. var angle;
  20601. var tdivisions = divisions * 2;
  20602. for ( var j = 1; j <= tdivisions; j ++ ) {
  20603. var t = j / tdivisions;
  20604. if ( ! aClockwise ) {
  20605. t = 1 - t;
  20606. }
  20607. angle = aStartAngle + t * deltaAngle;
  20608. tx = aX + aRadius * Math.cos( angle );
  20609. ty = aY + aRadius * Math.sin( angle );
  20610. //console.log('t', t, 'angle', angle, 'tx', tx, 'ty', ty);
  20611. points.push( new THREE.Vector2( tx, ty ) );
  20612. }
  20613. //console.log(points);
  20614. break;
  20615. case 'ellipse':
  20616. var aX = args[ 0 ], aY = args[ 1 ],
  20617. xRadius = args[ 2 ],
  20618. yRadius = args[ 3 ],
  20619. aStartAngle = args[ 4 ], aEndAngle = args[ 5 ],
  20620. aClockwise = !! args[ 6 ],
  20621. aRotation = args[ 7 ];
  20622. var deltaAngle = aEndAngle - aStartAngle;
  20623. var angle;
  20624. var tdivisions = divisions * 2;
  20625. var cos, sin;
  20626. if ( aRotation !== 0 ) {
  20627. cos = Math.cos( aRotation );
  20628. sin = Math.sin( aRotation );
  20629. }
  20630. for ( var j = 1; j <= tdivisions; j ++ ) {
  20631. var t = j / tdivisions;
  20632. if ( ! aClockwise ) {
  20633. t = 1 - t;
  20634. }
  20635. angle = aStartAngle + t * deltaAngle;
  20636. tx = aX + xRadius * Math.cos( angle );
  20637. ty = aY + yRadius * Math.sin( angle );
  20638. if ( aRotation !== 0 ) {
  20639. var x = tx, y = ty;
  20640. // Rotate the point about the center of the ellipse.
  20641. tx = ( x - aX ) * cos - ( y - aY ) * sin + aX;
  20642. ty = ( x - aX ) * sin + ( y - aY ) * cos + aY;
  20643. }
  20644. //console.log('t', t, 'angle', angle, 'tx', tx, 'ty', ty);
  20645. points.push( new THREE.Vector2( tx, ty ) );
  20646. }
  20647. //console.log(points);
  20648. break;
  20649. } // end switch
  20650. }
  20651. // Normalize to remove the closing point by default.
  20652. var lastPoint = points[ points.length - 1 ];
  20653. if ( Math.abs( lastPoint.x - points[ 0 ].x ) < Number.EPSILON &&
  20654. Math.abs( lastPoint.y - points[ 0 ].y ) < Number.EPSILON )
  20655. points.splice( points.length - 1, 1 );
  20656. if ( this.autoClose ) {
  20657. points.push( points[ 0 ] );
  20658. }
  20659. return points;
  20660. };
  20661. //
  20662. // Breaks path into shapes
  20663. //
  20664. // Assumptions (if parameter isCCW==true the opposite holds):
  20665. // - solid shapes are defined clockwise (CW)
  20666. // - holes are defined counterclockwise (CCW)
  20667. //
  20668. // If parameter noHoles==true:
  20669. // - all subPaths are regarded as solid shapes
  20670. // - definition order CW/CCW has no relevance
  20671. //
  20672. THREE.Path.prototype.toShapes = function( isCCW, noHoles ) {
  20673. function extractSubpaths( inActions ) {
  20674. var subPaths = [], lastPath = new THREE.Path();
  20675. for ( var i = 0, l = inActions.length; i < l; i ++ ) {
  20676. var item = inActions[ i ];
  20677. var args = item.args;
  20678. var action = item.action;
  20679. if ( action === 'moveTo' ) {
  20680. if ( lastPath.actions.length !== 0 ) {
  20681. subPaths.push( lastPath );
  20682. lastPath = new THREE.Path();
  20683. }
  20684. }
  20685. lastPath[ action ].apply( lastPath, args );
  20686. }
  20687. if ( lastPath.actions.length !== 0 ) {
  20688. subPaths.push( lastPath );
  20689. }
  20690. // console.log(subPaths);
  20691. return subPaths;
  20692. }
  20693. function toShapesNoHoles( inSubpaths ) {
  20694. var shapes = [];
  20695. for ( var i = 0, l = inSubpaths.length; i < l; i ++ ) {
  20696. var tmpPath = inSubpaths[ i ];
  20697. var tmpShape = new THREE.Shape();
  20698. tmpShape.actions = tmpPath.actions;
  20699. tmpShape.curves = tmpPath.curves;
  20700. shapes.push( tmpShape );
  20701. }
  20702. //console.log("shape", shapes);
  20703. return shapes;
  20704. }
  20705. function isPointInsidePolygon( inPt, inPolygon ) {
  20706. var polyLen = inPolygon.length;
  20707. // inPt on polygon contour => immediate success or
  20708. // toggling of inside/outside at every single! intersection point of an edge
  20709. // with the horizontal line through inPt, left of inPt
  20710. // not counting lowerY endpoints of edges and whole edges on that line
  20711. var inside = false;
  20712. for ( var p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  20713. var edgeLowPt = inPolygon[ p ];
  20714. var edgeHighPt = inPolygon[ q ];
  20715. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  20716. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  20717. if ( Math.abs( edgeDy ) > Number.EPSILON ) {
  20718. // not parallel
  20719. if ( edgeDy < 0 ) {
  20720. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  20721. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  20722. }
  20723. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  20724. if ( inPt.y === edgeLowPt.y ) {
  20725. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  20726. // continue; // no intersection or edgeLowPt => doesn't count !!!
  20727. } else {
  20728. var perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y );
  20729. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  20730. if ( perpEdge < 0 ) continue;
  20731. inside = ! inside; // true intersection left of inPt
  20732. }
  20733. } else {
  20734. // parallel or collinear
  20735. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  20736. // edge lies on the same horizontal line as inPt
  20737. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  20738. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  20739. // continue;
  20740. }
  20741. }
  20742. return inside;
  20743. }
  20744. var isClockWise = THREE.ShapeUtils.isClockWise;
  20745. var subPaths = extractSubpaths( this.actions );
  20746. if ( subPaths.length === 0 ) return [];
  20747. if ( noHoles === true ) return toShapesNoHoles( subPaths );
  20748. var solid, tmpPath, tmpShape, shapes = [];
  20749. if ( subPaths.length === 1 ) {
  20750. tmpPath = subPaths[ 0 ];
  20751. tmpShape = new THREE.Shape();
  20752. tmpShape.actions = tmpPath.actions;
  20753. tmpShape.curves = tmpPath.curves;
  20754. shapes.push( tmpShape );
  20755. return shapes;
  20756. }
  20757. var holesFirst = ! isClockWise( subPaths[ 0 ].getPoints() );
  20758. holesFirst = isCCW ? ! holesFirst : holesFirst;
  20759. // console.log("Holes first", holesFirst);
  20760. var betterShapeHoles = [];
  20761. var newShapes = [];
  20762. var newShapeHoles = [];
  20763. var mainIdx = 0;
  20764. var tmpPoints;
  20765. newShapes[ mainIdx ] = undefined;
  20766. newShapeHoles[ mainIdx ] = [];
  20767. for ( var i = 0, l = subPaths.length; i < l; i ++ ) {
  20768. tmpPath = subPaths[ i ];
  20769. tmpPoints = tmpPath.getPoints();
  20770. solid = isClockWise( tmpPoints );
  20771. solid = isCCW ? ! solid : solid;
  20772. if ( solid ) {
  20773. if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) mainIdx ++;
  20774. newShapes[ mainIdx ] = { s: new THREE.Shape(), p: tmpPoints };
  20775. newShapes[ mainIdx ].s.actions = tmpPath.actions;
  20776. newShapes[ mainIdx ].s.curves = tmpPath.curves;
  20777. if ( holesFirst ) mainIdx ++;
  20778. newShapeHoles[ mainIdx ] = [];
  20779. //console.log('cw', i);
  20780. } else {
  20781. newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } );
  20782. //console.log('ccw', i);
  20783. }
  20784. }
  20785. // only Holes? -> probably all Shapes with wrong orientation
  20786. if ( ! newShapes[ 0 ] ) return toShapesNoHoles( subPaths );
  20787. if ( newShapes.length > 1 ) {
  20788. var ambiguous = false;
  20789. var toChange = [];
  20790. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  20791. betterShapeHoles[ sIdx ] = [];
  20792. }
  20793. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  20794. var sho = newShapeHoles[ sIdx ];
  20795. for ( var hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  20796. var ho = sho[ hIdx ];
  20797. var hole_unassigned = true;
  20798. for ( var s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  20799. if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
  20800. if ( sIdx !== s2Idx ) toChange.push( { froms: sIdx, tos: s2Idx, hole: hIdx } );
  20801. if ( hole_unassigned ) {
  20802. hole_unassigned = false;
  20803. betterShapeHoles[ s2Idx ].push( ho );
  20804. } else {
  20805. ambiguous = true;
  20806. }
  20807. }
  20808. }
  20809. if ( hole_unassigned ) {
  20810. betterShapeHoles[ sIdx ].push( ho );
  20811. }
  20812. }
  20813. }
  20814. // console.log("ambiguous: ", ambiguous);
  20815. if ( toChange.length > 0 ) {
  20816. // console.log("to change: ", toChange);
  20817. if ( ! ambiguous ) newShapeHoles = betterShapeHoles;
  20818. }
  20819. }
  20820. var tmpHoles;
  20821. for ( var i = 0, il = newShapes.length; i < il; i ++ ) {
  20822. tmpShape = newShapes[ i ].s;
  20823. shapes.push( tmpShape );
  20824. tmpHoles = newShapeHoles[ i ];
  20825. for ( var j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  20826. tmpShape.holes.push( tmpHoles[ j ].h );
  20827. }
  20828. }
  20829. //console.log("shape", shapes);
  20830. return shapes;
  20831. };
  20832. // File:src/extras/core/Shape.js
  20833. /**
  20834. * @author zz85 / http://www.lab4games.net/zz85/blog
  20835. * Defines a 2d shape plane using paths.
  20836. **/
  20837. // STEP 1 Create a path.
  20838. // STEP 2 Turn path into shape.
  20839. // STEP 3 ExtrudeGeometry takes in Shape/Shapes
  20840. // STEP 3a - Extract points from each shape, turn to vertices
  20841. // STEP 3b - Triangulate each shape, add faces.
  20842. THREE.Shape = function () {
  20843. THREE.Path.apply( this, arguments );
  20844. this.holes = [];
  20845. };
  20846. THREE.Shape.prototype = Object.create( THREE.Path.prototype );
  20847. THREE.Shape.prototype.constructor = THREE.Shape;
  20848. // Convenience method to return ExtrudeGeometry
  20849. THREE.Shape.prototype.extrude = function ( options ) {
  20850. return new THREE.ExtrudeGeometry( this, options );
  20851. };
  20852. // Convenience method to return ShapeGeometry
  20853. THREE.Shape.prototype.makeGeometry = function ( options ) {
  20854. return new THREE.ShapeGeometry( this, options );
  20855. };
  20856. // Get points of holes
  20857. THREE.Shape.prototype.getPointsHoles = function ( divisions ) {
  20858. var holesPts = [];
  20859. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  20860. holesPts[ i ] = this.holes[ i ].getPoints( divisions );
  20861. }
  20862. return holesPts;
  20863. };
  20864. // Get points of shape and holes (keypoints based on segments parameter)
  20865. THREE.Shape.prototype.extractAllPoints = function ( divisions ) {
  20866. return {
  20867. shape: this.getPoints( divisions ),
  20868. holes: this.getPointsHoles( divisions )
  20869. };
  20870. };
  20871. THREE.Shape.prototype.extractPoints = function ( divisions ) {
  20872. return this.extractAllPoints( divisions );
  20873. };
  20874. // File:src/extras/curves/LineCurve.js
  20875. /**************************************************************
  20876. * Line
  20877. **************************************************************/
  20878. THREE.LineCurve = function ( v1, v2 ) {
  20879. this.v1 = v1;
  20880. this.v2 = v2;
  20881. };
  20882. THREE.LineCurve.prototype = Object.create( THREE.Curve.prototype );
  20883. THREE.LineCurve.prototype.constructor = THREE.LineCurve;
  20884. THREE.LineCurve.prototype.getPoint = function ( t ) {
  20885. var point = this.v2.clone().sub( this.v1 );
  20886. point.multiplyScalar( t ).add( this.v1 );
  20887. return point;
  20888. };
  20889. // Line curve is linear, so we can overwrite default getPointAt
  20890. THREE.LineCurve.prototype.getPointAt = function ( u ) {
  20891. return this.getPoint( u );
  20892. };
  20893. THREE.LineCurve.prototype.getTangent = function( t ) {
  20894. var tangent = this.v2.clone().sub( this.v1 );
  20895. return tangent.normalize();
  20896. };
  20897. // File:src/extras/curves/QuadraticBezierCurve.js
  20898. /**************************************************************
  20899. * Quadratic Bezier curve
  20900. **************************************************************/
  20901. THREE.QuadraticBezierCurve = function ( v0, v1, v2 ) {
  20902. this.v0 = v0;
  20903. this.v1 = v1;
  20904. this.v2 = v2;
  20905. };
  20906. THREE.QuadraticBezierCurve.prototype = Object.create( THREE.Curve.prototype );
  20907. THREE.QuadraticBezierCurve.prototype.constructor = THREE.QuadraticBezierCurve;
  20908. THREE.QuadraticBezierCurve.prototype.getPoint = function ( t ) {
  20909. var b2 = THREE.ShapeUtils.b2;
  20910. return new THREE.Vector2(
  20911. b2( t, this.v0.x, this.v1.x, this.v2.x ),
  20912. b2( t, this.v0.y, this.v1.y, this.v2.y )
  20913. );
  20914. };
  20915. THREE.QuadraticBezierCurve.prototype.getTangent = function( t ) {
  20916. var tangentQuadraticBezier = THREE.CurveUtils.tangentQuadraticBezier;
  20917. return new THREE.Vector2(
  20918. tangentQuadraticBezier( t, this.v0.x, this.v1.x, this.v2.x ),
  20919. tangentQuadraticBezier( t, this.v0.y, this.v1.y, this.v2.y )
  20920. ).normalize();
  20921. };
  20922. // File:src/extras/curves/CubicBezierCurve.js
  20923. /**************************************************************
  20924. * Cubic Bezier curve
  20925. **************************************************************/
  20926. THREE.CubicBezierCurve = function ( v0, v1, v2, v3 ) {
  20927. this.v0 = v0;
  20928. this.v1 = v1;
  20929. this.v2 = v2;
  20930. this.v3 = v3;
  20931. };
  20932. THREE.CubicBezierCurve.prototype = Object.create( THREE.Curve.prototype );
  20933. THREE.CubicBezierCurve.prototype.constructor = THREE.CubicBezierCurve;
  20934. THREE.CubicBezierCurve.prototype.getPoint = function ( t ) {
  20935. var b3 = THREE.ShapeUtils.b3;
  20936. return new THREE.Vector2(
  20937. b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x ),
  20938. b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y )
  20939. );
  20940. };
  20941. THREE.CubicBezierCurve.prototype.getTangent = function( t ) {
  20942. var tangentCubicBezier = THREE.CurveUtils.tangentCubicBezier;
  20943. return new THREE.Vector2(
  20944. tangentCubicBezier( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x ),
  20945. tangentCubicBezier( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y )
  20946. ).normalize();
  20947. };
  20948. // File:src/extras/curves/SplineCurve.js
  20949. /**************************************************************
  20950. * Spline curve
  20951. **************************************************************/
  20952. THREE.SplineCurve = function ( points /* array of Vector2 */ ) {
  20953. this.points = ( points == undefined ) ? [] : points;
  20954. };
  20955. THREE.SplineCurve.prototype = Object.create( THREE.Curve.prototype );
  20956. THREE.SplineCurve.prototype.constructor = THREE.SplineCurve;
  20957. THREE.SplineCurve.prototype.getPoint = function ( t ) {
  20958. var points = this.points;
  20959. var point = ( points.length - 1 ) * t;
  20960. var intPoint = Math.floor( point );
  20961. var weight = point - intPoint;
  20962. var point0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  20963. var point1 = points[ intPoint ];
  20964. var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  20965. var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  20966. var interpolate = THREE.CurveUtils.interpolate;
  20967. return new THREE.Vector2(
  20968. interpolate( point0.x, point1.x, point2.x, point3.x, weight ),
  20969. interpolate( point0.y, point1.y, point2.y, point3.y, weight )
  20970. );
  20971. };
  20972. // File:src/extras/curves/EllipseCurve.js
  20973. /**************************************************************
  20974. * Ellipse curve
  20975. **************************************************************/
  20976. THREE.EllipseCurve = function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  20977. this.aX = aX;
  20978. this.aY = aY;
  20979. this.xRadius = xRadius;
  20980. this.yRadius = yRadius;
  20981. this.aStartAngle = aStartAngle;
  20982. this.aEndAngle = aEndAngle;
  20983. this.aClockwise = aClockwise;
  20984. this.aRotation = aRotation || 0;
  20985. };
  20986. THREE.EllipseCurve.prototype = Object.create( THREE.Curve.prototype );
  20987. THREE.EllipseCurve.prototype.constructor = THREE.EllipseCurve;
  20988. THREE.EllipseCurve.prototype.getPoint = function ( t ) {
  20989. var deltaAngle = this.aEndAngle - this.aStartAngle;
  20990. if ( deltaAngle < 0 ) deltaAngle += Math.PI * 2;
  20991. if ( deltaAngle > Math.PI * 2 ) deltaAngle -= Math.PI * 2;
  20992. var angle;
  20993. if ( this.aClockwise === true ) {
  20994. angle = this.aEndAngle + ( 1 - t ) * ( Math.PI * 2 - deltaAngle );
  20995. } else {
  20996. angle = this.aStartAngle + t * deltaAngle;
  20997. }
  20998. var x = this.aX + this.xRadius * Math.cos( angle );
  20999. var y = this.aY + this.yRadius * Math.sin( angle );
  21000. if ( this.aRotation !== 0 ) {
  21001. var cos = Math.cos( this.aRotation );
  21002. var sin = Math.sin( this.aRotation );
  21003. var tx = x, ty = y;
  21004. // Rotate the point about the center of the ellipse.
  21005. x = ( tx - this.aX ) * cos - ( ty - this.aY ) * sin + this.aX;
  21006. y = ( tx - this.aX ) * sin + ( ty - this.aY ) * cos + this.aY;
  21007. }
  21008. return new THREE.Vector2( x, y );
  21009. };
  21010. // File:src/extras/curves/ArcCurve.js
  21011. /**************************************************************
  21012. * Arc curve
  21013. **************************************************************/
  21014. THREE.ArcCurve = function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  21015. THREE.EllipseCurve.call( this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  21016. };
  21017. THREE.ArcCurve.prototype = Object.create( THREE.EllipseCurve.prototype );
  21018. THREE.ArcCurve.prototype.constructor = THREE.ArcCurve;
  21019. // File:src/extras/curves/LineCurve3.js
  21020. /**************************************************************
  21021. * Line3D
  21022. **************************************************************/
  21023. THREE.LineCurve3 = THREE.Curve.create(
  21024. function ( v1, v2 ) {
  21025. this.v1 = v1;
  21026. this.v2 = v2;
  21027. },
  21028. function ( t ) {
  21029. var vector = new THREE.Vector3();
  21030. vector.subVectors( this.v2, this.v1 ); // diff
  21031. vector.multiplyScalar( t );
  21032. vector.add( this.v1 );
  21033. return vector;
  21034. }
  21035. );
  21036. // File:src/extras/curves/QuadraticBezierCurve3.js
  21037. /**************************************************************
  21038. * Quadratic Bezier 3D curve
  21039. **************************************************************/
  21040. THREE.QuadraticBezierCurve3 = THREE.Curve.create(
  21041. function ( v0, v1, v2 ) {
  21042. this.v0 = v0;
  21043. this.v1 = v1;
  21044. this.v2 = v2;
  21045. },
  21046. function ( t ) {
  21047. var b2 = THREE.ShapeUtils.b2;
  21048. return new THREE.Vector3(
  21049. b2( t, this.v0.x, this.v1.x, this.v2.x ),
  21050. b2( t, this.v0.y, this.v1.y, this.v2.y ),
  21051. b2( t, this.v0.z, this.v1.z, this.v2.z )
  21052. );
  21053. }
  21054. );
  21055. // File:src/extras/curves/CubicBezierCurve3.js
  21056. /**************************************************************
  21057. * Cubic Bezier 3D curve
  21058. **************************************************************/
  21059. THREE.CubicBezierCurve3 = THREE.Curve.create(
  21060. function ( v0, v1, v2, v3 ) {
  21061. this.v0 = v0;
  21062. this.v1 = v1;
  21063. this.v2 = v2;
  21064. this.v3 = v3;
  21065. },
  21066. function ( t ) {
  21067. var b3 = THREE.ShapeUtils.b3;
  21068. return new THREE.Vector3(
  21069. b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x ),
  21070. b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y ),
  21071. b3( t, this.v0.z, this.v1.z, this.v2.z, this.v3.z )
  21072. );
  21073. }
  21074. );
  21075. // File:src/extras/curves/SplineCurve3.js
  21076. /**************************************************************
  21077. * Spline 3D curve
  21078. **************************************************************/
  21079. THREE.SplineCurve3 = THREE.Curve.create(
  21080. function ( points /* array of Vector3 */ ) {
  21081. console.warn( 'THREE.SplineCurve3 will be deprecated. Please use THREE.CatmullRomCurve3' );
  21082. this.points = ( points == undefined ) ? [] : points;
  21083. },
  21084. function ( t ) {
  21085. var points = this.points;
  21086. var point = ( points.length - 1 ) * t;
  21087. var intPoint = Math.floor( point );
  21088. var weight = point - intPoint;
  21089. var point0 = points[ intPoint == 0 ? intPoint : intPoint - 1 ];
  21090. var point1 = points[ intPoint ];
  21091. var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  21092. var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  21093. var interpolate = THREE.CurveUtils.interpolate;
  21094. return new THREE.Vector3(
  21095. interpolate( point0.x, point1.x, point2.x, point3.x, weight ),
  21096. interpolate( point0.y, point1.y, point2.y, point3.y, weight ),
  21097. interpolate( point0.z, point1.z, point2.z, point3.z, weight )
  21098. );
  21099. }
  21100. );
  21101. // File:src/extras/curves/CatmullRomCurve3.js
  21102. /**
  21103. * @author zz85 https://github.com/zz85
  21104. *
  21105. * Centripetal CatmullRom Curve - which is useful for avoiding
  21106. * cusps and self-intersections in non-uniform catmull rom curves.
  21107. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  21108. *
  21109. * curve.type accepts centripetal(default), chordal and catmullrom
  21110. * curve.tension is used for catmullrom which defaults to 0.5
  21111. */
  21112. THREE.CatmullRomCurve3 = ( function() {
  21113. var
  21114. tmp = new THREE.Vector3(),
  21115. px = new CubicPoly(),
  21116. py = new CubicPoly(),
  21117. pz = new CubicPoly();
  21118. /*
  21119. Based on an optimized c++ solution in
  21120. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  21121. - http://ideone.com/NoEbVM
  21122. This CubicPoly class could be used for reusing some variables and calculations,
  21123. but for three.js curve use, it could be possible inlined and flatten into a single function call
  21124. which can be placed in CurveUtils.
  21125. */
  21126. function CubicPoly() {
  21127. }
  21128. /*
  21129. * Compute coefficients for a cubic polynomial
  21130. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  21131. * such that
  21132. * p(0) = x0, p(1) = x1
  21133. * and
  21134. * p'(0) = t0, p'(1) = t1.
  21135. */
  21136. CubicPoly.prototype.init = function( x0, x1, t0, t1 ) {
  21137. this.c0 = x0;
  21138. this.c1 = t0;
  21139. this.c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  21140. this.c3 = 2 * x0 - 2 * x1 + t0 + t1;
  21141. };
  21142. CubicPoly.prototype.initNonuniformCatmullRom = function( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  21143. // compute tangents when parameterized in [t1,t2]
  21144. var t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  21145. var t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  21146. // rescale tangents for parametrization in [0,1]
  21147. t1 *= dt1;
  21148. t2 *= dt1;
  21149. // initCubicPoly
  21150. this.init( x1, x2, t1, t2 );
  21151. };
  21152. // standard Catmull-Rom spline: interpolate between x1 and x2 with previous/following points x1/x4
  21153. CubicPoly.prototype.initCatmullRom = function( x0, x1, x2, x3, tension ) {
  21154. this.init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  21155. };
  21156. CubicPoly.prototype.calc = function( t ) {
  21157. var t2 = t * t;
  21158. var t3 = t2 * t;
  21159. return this.c0 + this.c1 * t + this.c2 * t2 + this.c3 * t3;
  21160. };
  21161. // Subclass Three.js curve
  21162. return THREE.Curve.create(
  21163. function ( p /* array of Vector3 */ ) {
  21164. this.points = p || [];
  21165. this.closed = false;
  21166. },
  21167. function ( t ) {
  21168. var points = this.points,
  21169. point, intPoint, weight, l;
  21170. l = points.length;
  21171. if ( l < 2 ) console.log( 'duh, you need at least 2 points' );
  21172. point = ( l - ( this.closed ? 0 : 1 ) ) * t;
  21173. intPoint = Math.floor( point );
  21174. weight = point - intPoint;
  21175. if ( this.closed ) {
  21176. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / points.length ) + 1 ) * points.length;
  21177. } else if ( weight === 0 && intPoint === l - 1 ) {
  21178. intPoint = l - 2;
  21179. weight = 1;
  21180. }
  21181. var p0, p1, p2, p3; // 4 points
  21182. if ( this.closed || intPoint > 0 ) {
  21183. p0 = points[ ( intPoint - 1 ) % l ];
  21184. } else {
  21185. // extrapolate first point
  21186. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  21187. p0 = tmp;
  21188. }
  21189. p1 = points[ intPoint % l ];
  21190. p2 = points[ ( intPoint + 1 ) % l ];
  21191. if ( this.closed || intPoint + 2 < l ) {
  21192. p3 = points[ ( intPoint + 2 ) % l ];
  21193. } else {
  21194. // extrapolate last point
  21195. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 1 ] );
  21196. p3 = tmp;
  21197. }
  21198. if ( this.type === undefined || this.type === 'centripetal' || this.type === 'chordal' ) {
  21199. // init Centripetal / Chordal Catmull-Rom
  21200. var pow = this.type === 'chordal' ? 0.5 : 0.25;
  21201. var dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  21202. var dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  21203. var dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  21204. // safety check for repeated points
  21205. if ( dt1 < 1e-4 ) dt1 = 1.0;
  21206. if ( dt0 < 1e-4 ) dt0 = dt1;
  21207. if ( dt2 < 1e-4 ) dt2 = dt1;
  21208. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  21209. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  21210. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  21211. } else if ( this.type === 'catmullrom' ) {
  21212. var tension = this.tension !== undefined ? this.tension : 0.5;
  21213. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, tension );
  21214. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, tension );
  21215. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, tension );
  21216. }
  21217. var v = new THREE.Vector3(
  21218. px.calc( weight ),
  21219. py.calc( weight ),
  21220. pz.calc( weight )
  21221. );
  21222. return v;
  21223. }
  21224. );
  21225. } )();
  21226. // File:src/extras/curves/ClosedSplineCurve3.js
  21227. /**************************************************************
  21228. * Closed Spline 3D curve
  21229. **************************************************************/
  21230. THREE.ClosedSplineCurve3 = function ( points ) {
  21231. console.warn( 'THREE.ClosedSplineCurve3 has been deprecated. Please use THREE.CatmullRomCurve3.' );
  21232. THREE.CatmullRomCurve3.call( this, points );
  21233. this.type = 'catmullrom';
  21234. this.closed = true;
  21235. };
  21236. THREE.ClosedSplineCurve3.prototype = Object.create( THREE.CatmullRomCurve3.prototype );
  21237. // File:src/extras/geometries/BoxGeometry.js
  21238. /**
  21239. * @author mrdoob / http://mrdoob.com/
  21240. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Cube.as
  21241. */
  21242. THREE.BoxGeometry = function ( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  21243. THREE.Geometry.call( this );
  21244. this.type = 'BoxGeometry';
  21245. this.parameters = {
  21246. width: width,
  21247. height: height,
  21248. depth: depth,
  21249. widthSegments: widthSegments,
  21250. heightSegments: heightSegments,
  21251. depthSegments: depthSegments
  21252. };
  21253. this.fromBufferGeometry( new THREE.BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) );
  21254. this.mergeVertices();
  21255. };
  21256. THREE.BoxGeometry.prototype = Object.create( THREE.Geometry.prototype );
  21257. THREE.BoxGeometry.prototype.constructor = THREE.BoxGeometry;
  21258. THREE.CubeGeometry = THREE.BoxGeometry;
  21259. // File:src/extras/geometries/BoxBufferGeometry.js
  21260. /**
  21261. * @author Mugen87 / https://github.com/Mugen87
  21262. */
  21263. THREE.BoxBufferGeometry = function ( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  21264. THREE.BufferGeometry.call( this );
  21265. this.type = 'BoxBufferGeometry';
  21266. this.parameters = {
  21267. width: width,
  21268. height: height,
  21269. depth: depth,
  21270. widthSegments: widthSegments,
  21271. heightSegments: heightSegments,
  21272. depthSegments: depthSegments
  21273. };
  21274. var scope = this;
  21275. // segments
  21276. widthSegments = Math.floor( widthSegments ) || 1;
  21277. heightSegments = Math.floor( heightSegments ) || 1;
  21278. depthSegments = Math.floor( depthSegments ) || 1;
  21279. // these are used to calculate buffer length
  21280. var vertexCount = calculateVertexCount( widthSegments, heightSegments, depthSegments );
  21281. var indexCount = ( vertexCount / 4 ) * 6;
  21282. // buffers
  21283. var indices = new ( indexCount > 65535 ? Uint32Array : Uint16Array )( indexCount );
  21284. var vertices = new Float32Array( vertexCount * 3 );
  21285. var normals = new Float32Array( vertexCount * 3 );
  21286. var uvs = new Float32Array( vertexCount * 2 );
  21287. // offset variables
  21288. var vertexBufferOffset = 0;
  21289. var uvBufferOffset = 0;
  21290. var indexBufferOffset = 0;
  21291. var numberOfVertices = 0;
  21292. // group variables
  21293. var groupStart = 0;
  21294. // build each side of the box geometry
  21295. buildPlane( 'z', 'y', 'x', - 1, - 1, depth, height, width, depthSegments, heightSegments, 0 ); // px
  21296. buildPlane( 'z', 'y', 'x', 1, - 1, depth, height, - width, depthSegments, heightSegments, 1 ); // nx
  21297. buildPlane( 'x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2 ); // py
  21298. buildPlane( 'x', 'z', 'y', 1, - 1, width, depth, - height, widthSegments, depthSegments, 3 ); // ny
  21299. buildPlane( 'x', 'y', 'z', 1, - 1, width, height, depth, widthSegments, heightSegments, 4 ); // pz
  21300. buildPlane( 'x', 'y', 'z', - 1, - 1, width, height, - depth, widthSegments, heightSegments, 5 ); // nz
  21301. // build geometry
  21302. this.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  21303. this.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  21304. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  21305. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  21306. // helper functions
  21307. function calculateVertexCount ( w, h, d ) {
  21308. var segments = 0;
  21309. // calculate the amount of segments for each side
  21310. segments += w * h * 2; // xy
  21311. segments += w * d * 2; // xz
  21312. segments += d * h * 2; // zy
  21313. return segments * 4; // four vertices per segments
  21314. }
  21315. function buildPlane ( u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex ) {
  21316. var segmentWidth = width / gridX;
  21317. var segmentHeight = height / gridY;
  21318. var widthHalf = width / 2;
  21319. var heightHalf = height / 2;
  21320. var depthHalf = depth / 2;
  21321. var gridX1 = gridX + 1;
  21322. var gridY1 = gridY + 1;
  21323. var vertexCounter = 0;
  21324. var groupCount = 0;
  21325. var vector = new THREE.Vector3();
  21326. // generate vertices, normals and uvs
  21327. for ( var iy = 0; iy < gridY1; iy ++ ) {
  21328. var y = iy * segmentHeight - heightHalf;
  21329. for ( var ix = 0; ix < gridX1; ix ++ ) {
  21330. var x = ix * segmentWidth - widthHalf;
  21331. // set values to correct vector component
  21332. vector[ u ] = x * udir;
  21333. vector[ v ] = y * vdir;
  21334. vector[ w ] = depthHalf;
  21335. // now apply vector to vertex buffer
  21336. vertices[ vertexBufferOffset ] = vector.x;
  21337. vertices[ vertexBufferOffset + 1 ] = vector.y;
  21338. vertices[ vertexBufferOffset + 2 ] = vector.z;
  21339. // set values to correct vector component
  21340. vector[ u ] = 0;
  21341. vector[ v ] = 0;
  21342. vector[ w ] = depth > 0 ? 1 : - 1;
  21343. // now apply vector to normal buffer
  21344. normals[ vertexBufferOffset ] = vector.x;
  21345. normals[ vertexBufferOffset + 1 ] = vector.y;
  21346. normals[ vertexBufferOffset + 2 ] = vector.z;
  21347. // uvs
  21348. uvs[ uvBufferOffset ] = ix / gridX;
  21349. uvs[ uvBufferOffset + 1 ] = 1 - ( iy / gridY );
  21350. // update offsets and counters
  21351. vertexBufferOffset += 3;
  21352. uvBufferOffset += 2;
  21353. vertexCounter += 1;
  21354. }
  21355. }
  21356. // 1. you need three indices to draw a single face
  21357. // 2. a single segment consists of two faces
  21358. // 3. so we need to generate six (2*3) indices per segment
  21359. for ( iy = 0; iy < gridY; iy ++ ) {
  21360. for ( ix = 0; ix < gridX; ix ++ ) {
  21361. // indices
  21362. var a = numberOfVertices + ix + gridX1 * iy;
  21363. var b = numberOfVertices + ix + gridX1 * ( iy + 1 );
  21364. var c = numberOfVertices + ( ix + 1 ) + gridX1 * ( iy + 1 );
  21365. var d = numberOfVertices + ( ix + 1 ) + gridX1 * iy;
  21366. // face one
  21367. indices[ indexBufferOffset ] = a;
  21368. indices[ indexBufferOffset + 1 ] = b;
  21369. indices[ indexBufferOffset + 2 ] = d;
  21370. // face two
  21371. indices[ indexBufferOffset + 3 ] = b;
  21372. indices[ indexBufferOffset + 4 ] = c;
  21373. indices[ indexBufferOffset + 5 ] = d;
  21374. // update offsets and counters
  21375. indexBufferOffset += 6;
  21376. groupCount += 6;
  21377. }
  21378. }
  21379. // add a group to the geometry. this will ensure multi material support
  21380. scope.addGroup( groupStart, groupCount, materialIndex );
  21381. // calculate new start value for groups
  21382. groupStart += groupCount;
  21383. // update total number of vertices
  21384. numberOfVertices += vertexCounter;
  21385. }
  21386. };
  21387. THREE.BoxBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  21388. THREE.BoxBufferGeometry.prototype.constructor = THREE.BoxBufferGeometry;
  21389. // File:src/extras/geometries/CircleGeometry.js
  21390. /**
  21391. * @author hughes
  21392. */
  21393. THREE.CircleGeometry = function ( radius, segments, thetaStart, thetaLength ) {
  21394. THREE.Geometry.call( this );
  21395. this.type = 'CircleGeometry';
  21396. this.parameters = {
  21397. radius: radius,
  21398. segments: segments,
  21399. thetaStart: thetaStart,
  21400. thetaLength: thetaLength
  21401. };
  21402. this.fromBufferGeometry( new THREE.CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) );
  21403. };
  21404. THREE.CircleGeometry.prototype = Object.create( THREE.Geometry.prototype );
  21405. THREE.CircleGeometry.prototype.constructor = THREE.CircleGeometry;
  21406. // File:src/extras/geometries/CircleBufferGeometry.js
  21407. /**
  21408. * @author benaadams / https://twitter.com/ben_a_adams
  21409. */
  21410. THREE.CircleBufferGeometry = function ( radius, segments, thetaStart, thetaLength ) {
  21411. THREE.BufferGeometry.call( this );
  21412. this.type = 'CircleBufferGeometry';
  21413. this.parameters = {
  21414. radius: radius,
  21415. segments: segments,
  21416. thetaStart: thetaStart,
  21417. thetaLength: thetaLength
  21418. };
  21419. radius = radius || 50;
  21420. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  21421. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  21422. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  21423. var vertices = segments + 2;
  21424. var positions = new Float32Array( vertices * 3 );
  21425. var normals = new Float32Array( vertices * 3 );
  21426. var uvs = new Float32Array( vertices * 2 );
  21427. // center data is already zero, but need to set a few extras
  21428. normals[ 2 ] = 1.0;
  21429. uvs[ 0 ] = 0.5;
  21430. uvs[ 1 ] = 0.5;
  21431. for ( var s = 0, i = 3, ii = 2 ; s <= segments; s ++, i += 3, ii += 2 ) {
  21432. var segment = thetaStart + s / segments * thetaLength;
  21433. positions[ i ] = radius * Math.cos( segment );
  21434. positions[ i + 1 ] = radius * Math.sin( segment );
  21435. normals[ i + 2 ] = 1; // normal z
  21436. uvs[ ii ] = ( positions[ i ] / radius + 1 ) / 2;
  21437. uvs[ ii + 1 ] = ( positions[ i + 1 ] / radius + 1 ) / 2;
  21438. }
  21439. var indices = [];
  21440. for ( var i = 1; i <= segments; i ++ ) {
  21441. indices.push( i, i + 1, 0 );
  21442. }
  21443. this.setIndex( new THREE.BufferAttribute( new Uint16Array( indices ), 1 ) );
  21444. this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
  21445. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  21446. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  21447. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  21448. };
  21449. THREE.CircleBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  21450. THREE.CircleBufferGeometry.prototype.constructor = THREE.CircleBufferGeometry;
  21451. // File:src/extras/geometries/CylinderBufferGeometry.js
  21452. /**
  21453. * @author Mugen87 / https://github.com/Mugen87
  21454. */
  21455. THREE.CylinderBufferGeometry = function ( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  21456. THREE.BufferGeometry.call( this );
  21457. this.type = 'CylinderBufferGeometry';
  21458. this.parameters = {
  21459. radiusTop: radiusTop,
  21460. radiusBottom: radiusBottom,
  21461. height: height,
  21462. radialSegments: radialSegments,
  21463. heightSegments: heightSegments,
  21464. openEnded: openEnded,
  21465. thetaStart: thetaStart,
  21466. thetaLength: thetaLength
  21467. };
  21468. radiusTop = radiusTop !== undefined ? radiusTop : 20;
  21469. radiusBottom = radiusBottom !== undefined ? radiusBottom : 20;
  21470. height = height !== undefined ? height : 100;
  21471. radialSegments = Math.floor( radialSegments ) || 8;
  21472. heightSegments = Math.floor( heightSegments ) || 1;
  21473. openEnded = openEnded !== undefined ? openEnded : false;
  21474. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  21475. thetaLength = thetaLength !== undefined ? thetaLength : 2 * Math.PI;
  21476. // used to calculate buffer length
  21477. var vertexCount = calculateVertexCount();
  21478. var indexCount = calculateIndexCount();
  21479. // buffers
  21480. var indices = new THREE.BufferAttribute( new ( indexCount > 65535 ? Uint32Array : Uint16Array )( indexCount ) , 1 );
  21481. var vertices = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  21482. var normals = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  21483. var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
  21484. // helper variables
  21485. var index = 0, indexOffset = 0, indexArray = [], halfHeight = height / 2;
  21486. // generate geometry
  21487. generateTorso();
  21488. if( openEnded === false ) {
  21489. if( radiusTop > 0 ) {
  21490. generateCap( true );
  21491. }
  21492. if( radiusBottom > 0 ) {
  21493. generateCap( false );
  21494. }
  21495. }
  21496. // build geometry
  21497. this.setIndex( indices );
  21498. this.addAttribute( 'position', vertices );
  21499. this.addAttribute( 'normal', normals );
  21500. this.addAttribute( 'uv', uvs );
  21501. // helper functions
  21502. function calculateVertexCount () {
  21503. var count = ( radialSegments + 1 ) * ( heightSegments + 1 );
  21504. if ( openEnded === false ) {
  21505. count += ( ( radialSegments + 1 ) * 2 ) + ( radialSegments * 2 );
  21506. }
  21507. return count;
  21508. }
  21509. function calculateIndexCount () {
  21510. var count = radialSegments * heightSegments * 2 * 3;
  21511. if ( openEnded === false ) {
  21512. count += radialSegments * 2 * 3;
  21513. }
  21514. return count;
  21515. }
  21516. function generateTorso () {
  21517. var x, y;
  21518. var normal = new THREE.Vector3();
  21519. var vertex = new THREE.Vector3();
  21520. // this will be used to calculate the normal
  21521. var tanTheta = ( radiusBottom - radiusTop ) / height;
  21522. // generate vertices, normals and uvs
  21523. for ( y = 0; y <= heightSegments; y ++ ) {
  21524. var indexRow = [];
  21525. var v = y / heightSegments;
  21526. // calculate the radius of the current row
  21527. var radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  21528. for ( x = 0; x <= radialSegments; x ++ ) {
  21529. var u = x / radialSegments;
  21530. // vertex
  21531. vertex.x = radius * Math.sin( u * thetaLength + thetaStart );
  21532. vertex.y = - v * height + halfHeight;
  21533. vertex.z = radius * Math.cos( u * thetaLength + thetaStart );
  21534. vertices.setXYZ( index, vertex.x, vertex.y, vertex.z );
  21535. // normal
  21536. normal.copy( vertex );
  21537. // handle special case if radiusTop/radiusBottom is zero
  21538. if( ( radiusTop === 0 && y === 0 ) || ( radiusBottom === 0 && y === heightSegments ) ) {
  21539. normal.x = Math.sin( u * thetaLength + thetaStart );
  21540. normal.z = Math.cos( u * thetaLength + thetaStart );
  21541. }
  21542. normal.setY( Math.sqrt( normal.x * normal.x + normal.z * normal.z ) * tanTheta ).normalize();
  21543. normals.setXYZ( index, normal.x, normal.y, normal.z );
  21544. // uv
  21545. uvs.setXY( index, u, 1 - v );
  21546. // save index of vertex in respective row
  21547. indexRow.push( index );
  21548. // increase index
  21549. index ++;
  21550. }
  21551. // now save vertices of the row in our index array
  21552. indexArray.push( indexRow );
  21553. }
  21554. // generate indices
  21555. for ( x = 0; x < radialSegments; x ++ ) {
  21556. for ( y = 0; y < heightSegments; y ++ ) {
  21557. // we use the index array to access the correct indices
  21558. var i1 = indexArray[ y ][ x ];
  21559. var i2 = indexArray[ y + 1 ][ x ];
  21560. var i3 = indexArray[ y + 1 ][ x + 1 ];
  21561. var i4 = indexArray[ y ][ x + 1 ];
  21562. // face one
  21563. indices.setX( indexOffset, i1 ); indexOffset++;
  21564. indices.setX( indexOffset, i2 ); indexOffset++;
  21565. indices.setX( indexOffset, i4 ); indexOffset++;
  21566. // face two
  21567. indices.setX( indexOffset, i2 ); indexOffset++;
  21568. indices.setX( indexOffset, i3 ); indexOffset++;
  21569. indices.setX( indexOffset, i4 ); indexOffset++;
  21570. }
  21571. }
  21572. }
  21573. function generateCap ( top ) {
  21574. var x, centerIndexStart, centerIndexEnd;
  21575. var uv = new THREE.Vector2();
  21576. var vertex = new THREE.Vector3();
  21577. var radius = ( top === true ) ? radiusTop : radiusBottom;
  21578. var sign = ( top === true ) ? 1 : - 1;
  21579. // save the index of the first center vertex
  21580. centerIndexStart = index;
  21581. // first we generate the center vertex data of the cap.
  21582. // because the geometry needs one set of uvs per face,
  21583. // we must generate a center vertex per face/segment
  21584. for ( x = 1; x <= radialSegments; x ++ ) {
  21585. // vertex
  21586. vertices.setXYZ( index, 0, halfHeight * sign, 0 );
  21587. // normal
  21588. normals.setXYZ( index, 0, sign, 0 );
  21589. // uv
  21590. if( top === true ) {
  21591. uv.x = x / radialSegments;
  21592. uv.y = 0;
  21593. } else {
  21594. uv.x = ( x - 1 ) / radialSegments;
  21595. uv.y = 1;
  21596. }
  21597. uvs.setXY( index, uv.x, uv.y );
  21598. // increase index
  21599. index++;
  21600. }
  21601. // save the index of the last center vertex
  21602. centerIndexEnd = index;
  21603. // now we generate the surrounding vertices, normals and uvs
  21604. for ( x = 0; x <= radialSegments; x ++ ) {
  21605. var u = x / radialSegments;
  21606. // vertex
  21607. vertex.x = radius * Math.sin( u * thetaLength + thetaStart );
  21608. vertex.y = halfHeight * sign;
  21609. vertex.z = radius * Math.cos( u * thetaLength + thetaStart );
  21610. vertices.setXYZ( index, vertex.x, vertex.y, vertex.z );
  21611. // normal
  21612. normals.setXYZ( index, 0, sign, 0 );
  21613. // uv
  21614. uvs.setXY( index, u, ( top === true ) ? 1 : 0 );
  21615. // increase index
  21616. index ++;
  21617. }
  21618. // generate indices
  21619. for ( x = 0; x < radialSegments; x ++ ) {
  21620. var c = centerIndexStart + x;
  21621. var i = centerIndexEnd + x;
  21622. if( top === true ) {
  21623. // face top
  21624. indices.setX( indexOffset, i ); indexOffset++;
  21625. indices.setX( indexOffset, i + 1 ); indexOffset++;
  21626. indices.setX( indexOffset, c ); indexOffset++;
  21627. } else {
  21628. // face bottom
  21629. indices.setX( indexOffset, i + 1); indexOffset++;
  21630. indices.setX( indexOffset, i ); indexOffset++;
  21631. indices.setX( indexOffset, c ); indexOffset++;
  21632. }
  21633. }
  21634. }
  21635. };
  21636. THREE.CylinderBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  21637. THREE.CylinderBufferGeometry.prototype.constructor = THREE.CylinderBufferGeometry;
  21638. // File:src/extras/geometries/CylinderGeometry.js
  21639. /**
  21640. * @author mrdoob / http://mrdoob.com/
  21641. */
  21642. THREE.CylinderGeometry = function ( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  21643. THREE.Geometry.call( this );
  21644. this.type = 'CylinderGeometry';
  21645. this.parameters = {
  21646. radiusTop: radiusTop,
  21647. radiusBottom: radiusBottom,
  21648. height: height,
  21649. radialSegments: radialSegments,
  21650. heightSegments: heightSegments,
  21651. openEnded: openEnded,
  21652. thetaStart: thetaStart,
  21653. thetaLength: thetaLength
  21654. };
  21655. this.fromBufferGeometry( new THREE.CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) );
  21656. this.mergeVertices();
  21657. };
  21658. THREE.CylinderGeometry.prototype = Object.create( THREE.Geometry.prototype );
  21659. THREE.CylinderGeometry.prototype.constructor = THREE.CylinderGeometry;
  21660. // File:src/extras/geometries/EdgesGeometry.js
  21661. /**
  21662. * @author WestLangley / http://github.com/WestLangley
  21663. */
  21664. THREE.EdgesGeometry = function ( geometry, thresholdAngle ) {
  21665. THREE.BufferGeometry.call( this );
  21666. thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
  21667. var thresholdDot = Math.cos( THREE.Math.degToRad( thresholdAngle ) );
  21668. var edge = [ 0, 0 ], hash = {};
  21669. function sortFunction( a, b ) {
  21670. return a - b;
  21671. }
  21672. var keys = [ 'a', 'b', 'c' ];
  21673. var geometry2;
  21674. if ( geometry instanceof THREE.BufferGeometry ) {
  21675. geometry2 = new THREE.Geometry();
  21676. geometry2.fromBufferGeometry( geometry );
  21677. } else {
  21678. geometry2 = geometry.clone();
  21679. }
  21680. geometry2.mergeVertices();
  21681. geometry2.computeFaceNormals();
  21682. var vertices = geometry2.vertices;
  21683. var faces = geometry2.faces;
  21684. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  21685. var face = faces[ i ];
  21686. for ( var j = 0; j < 3; j ++ ) {
  21687. edge[ 0 ] = face[ keys[ j ] ];
  21688. edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
  21689. edge.sort( sortFunction );
  21690. var key = edge.toString();
  21691. if ( hash[ key ] === undefined ) {
  21692. hash[ key ] = { vert1: edge[ 0 ], vert2: edge[ 1 ], face1: i, face2: undefined };
  21693. } else {
  21694. hash[ key ].face2 = i;
  21695. }
  21696. }
  21697. }
  21698. var coords = [];
  21699. for ( var key in hash ) {
  21700. var h = hash[ key ];
  21701. if ( h.face2 === undefined || faces[ h.face1 ].normal.dot( faces[ h.face2 ].normal ) <= thresholdDot ) {
  21702. var vertex = vertices[ h.vert1 ];
  21703. coords.push( vertex.x );
  21704. coords.push( vertex.y );
  21705. coords.push( vertex.z );
  21706. vertex = vertices[ h.vert2 ];
  21707. coords.push( vertex.x );
  21708. coords.push( vertex.y );
  21709. coords.push( vertex.z );
  21710. }
  21711. }
  21712. this.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array( coords ), 3 ) );
  21713. };
  21714. THREE.EdgesGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  21715. THREE.EdgesGeometry.prototype.constructor = THREE.EdgesGeometry;
  21716. // File:src/extras/geometries/ExtrudeGeometry.js
  21717. /**
  21718. * @author zz85 / http://www.lab4games.net/zz85/blog
  21719. *
  21720. * Creates extruded geometry from a path shape.
  21721. *
  21722. * parameters = {
  21723. *
  21724. * curveSegments: <int>, // number of points on the curves
  21725. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  21726. * amount: <int>, // Depth to extrude the shape
  21727. *
  21728. * bevelEnabled: <bool>, // turn on bevel
  21729. * bevelThickness: <float>, // how deep into the original shape bevel goes
  21730. * bevelSize: <float>, // how far from shape outline is bevel
  21731. * bevelSegments: <int>, // number of bevel layers
  21732. *
  21733. * extrudePath: <THREE.CurvePath> // 3d spline path to extrude shape along. (creates Frames if .frames aren't defined)
  21734. * frames: <THREE.TubeGeometry.FrenetFrames> // containing arrays of tangents, normals, binormals
  21735. *
  21736. * uvGenerator: <Object> // object that provides UV generator functions
  21737. *
  21738. * }
  21739. **/
  21740. THREE.ExtrudeGeometry = function ( shapes, options ) {
  21741. if ( typeof( shapes ) === "undefined" ) {
  21742. shapes = [];
  21743. return;
  21744. }
  21745. THREE.Geometry.call( this );
  21746. this.type = 'ExtrudeGeometry';
  21747. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  21748. this.addShapeList( shapes, options );
  21749. this.computeFaceNormals();
  21750. // can't really use automatic vertex normals
  21751. // as then front and back sides get smoothed too
  21752. // should do separate smoothing just for sides
  21753. //this.computeVertexNormals();
  21754. //console.log( "took", ( Date.now() - startTime ) );
  21755. };
  21756. THREE.ExtrudeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  21757. THREE.ExtrudeGeometry.prototype.constructor = THREE.ExtrudeGeometry;
  21758. THREE.ExtrudeGeometry.prototype.addShapeList = function ( shapes, options ) {
  21759. var sl = shapes.length;
  21760. for ( var s = 0; s < sl; s ++ ) {
  21761. var shape = shapes[ s ];
  21762. this.addShape( shape, options );
  21763. }
  21764. };
  21765. THREE.ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
  21766. var amount = options.amount !== undefined ? options.amount : 100;
  21767. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6; // 10
  21768. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2; // 8
  21769. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  21770. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true; // false
  21771. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  21772. var steps = options.steps !== undefined ? options.steps : 1;
  21773. var extrudePath = options.extrudePath;
  21774. var extrudePts, extrudeByPath = false;
  21775. // Use default WorldUVGenerator if no UV generators are specified.
  21776. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : THREE.ExtrudeGeometry.WorldUVGenerator;
  21777. var splineTube, binormal, normal, position2;
  21778. if ( extrudePath ) {
  21779. extrudePts = extrudePath.getSpacedPoints( steps );
  21780. extrudeByPath = true;
  21781. bevelEnabled = false; // bevels not supported for path extrusion
  21782. // SETUP TNB variables
  21783. // Reuse TNB from TubeGeomtry for now.
  21784. // TODO1 - have a .isClosed in spline?
  21785. splineTube = options.frames !== undefined ? options.frames : new THREE.TubeGeometry.FrenetFrames( extrudePath, steps, false );
  21786. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  21787. binormal = new THREE.Vector3();
  21788. normal = new THREE.Vector3();
  21789. position2 = new THREE.Vector3();
  21790. }
  21791. // Safeguards if bevels are not enabled
  21792. if ( ! bevelEnabled ) {
  21793. bevelSegments = 0;
  21794. bevelThickness = 0;
  21795. bevelSize = 0;
  21796. }
  21797. // Variables initialization
  21798. var ahole, h, hl; // looping of holes
  21799. var scope = this;
  21800. var shapesOffset = this.vertices.length;
  21801. var shapePoints = shape.extractPoints( curveSegments );
  21802. var vertices = shapePoints.shape;
  21803. var holes = shapePoints.holes;
  21804. var reverse = ! THREE.ShapeUtils.isClockWise( vertices );
  21805. if ( reverse ) {
  21806. vertices = vertices.reverse();
  21807. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  21808. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  21809. ahole = holes[ h ];
  21810. if ( THREE.ShapeUtils.isClockWise( ahole ) ) {
  21811. holes[ h ] = ahole.reverse();
  21812. }
  21813. }
  21814. reverse = false; // If vertices are in order now, we shouldn't need to worry about them again (hopefully)!
  21815. }
  21816. var faces = THREE.ShapeUtils.triangulateShape( vertices, holes );
  21817. /* Vertices */
  21818. var contour = vertices; // vertices has all points but contour has only points of circumference
  21819. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  21820. ahole = holes[ h ];
  21821. vertices = vertices.concat( ahole );
  21822. }
  21823. function scalePt2 ( pt, vec, size ) {
  21824. if ( ! vec ) console.error( "THREE.ExtrudeGeometry: vec does not exist" );
  21825. return vec.clone().multiplyScalar( size ).add( pt );
  21826. }
  21827. var b, bs, t, z,
  21828. vert, vlen = vertices.length,
  21829. face, flen = faces.length;
  21830. // Find directions for point movement
  21831. function getBevelVec( inPt, inPrev, inNext ) {
  21832. // computes for inPt the corresponding point inPt' on a new contour
  21833. // shifted by 1 unit (length of normalized vector) to the left
  21834. // if we walk along contour clockwise, this new contour is outside the old one
  21835. //
  21836. // inPt' is the intersection of the two lines parallel to the two
  21837. // adjacent edges of inPt at a distance of 1 unit on the left side.
  21838. var v_trans_x, v_trans_y, shrink_by = 1; // resulting translation vector for inPt
  21839. // good reading for geometry algorithms (here: line-line intersection)
  21840. // http://geomalgorithms.com/a05-_intersect-1.html
  21841. var v_prev_x = inPt.x - inPrev.x, v_prev_y = inPt.y - inPrev.y;
  21842. var v_next_x = inNext.x - inPt.x, v_next_y = inNext.y - inPt.y;
  21843. var v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  21844. // check for collinear edges
  21845. var collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  21846. if ( Math.abs( collinear0 ) > Number.EPSILON ) {
  21847. // not collinear
  21848. // length of vectors for normalizing
  21849. var v_prev_len = Math.sqrt( v_prev_lensq );
  21850. var v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  21851. // shift adjacent points by unit vectors to the left
  21852. var ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  21853. var ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  21854. var ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  21855. var ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  21856. // scaling factor for v_prev to intersection point
  21857. var sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  21858. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  21859. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  21860. // vector from inPt to intersection point
  21861. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  21862. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  21863. // Don't normalize!, otherwise sharp corners become ugly
  21864. // but prevent crazy spikes
  21865. var v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  21866. if ( v_trans_lensq <= 2 ) {
  21867. return new THREE.Vector2( v_trans_x, v_trans_y );
  21868. } else {
  21869. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  21870. }
  21871. } else {
  21872. // handle special case of collinear edges
  21873. var direction_eq = false; // assumes: opposite
  21874. if ( v_prev_x > Number.EPSILON ) {
  21875. if ( v_next_x > Number.EPSILON ) {
  21876. direction_eq = true;
  21877. }
  21878. } else {
  21879. if ( v_prev_x < - Number.EPSILON ) {
  21880. if ( v_next_x < - Number.EPSILON ) {
  21881. direction_eq = true;
  21882. }
  21883. } else {
  21884. if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
  21885. direction_eq = true;
  21886. }
  21887. }
  21888. }
  21889. if ( direction_eq ) {
  21890. // console.log("Warning: lines are a straight sequence");
  21891. v_trans_x = - v_prev_y;
  21892. v_trans_y = v_prev_x;
  21893. shrink_by = Math.sqrt( v_prev_lensq );
  21894. } else {
  21895. // console.log("Warning: lines are a straight spike");
  21896. v_trans_x = v_prev_x;
  21897. v_trans_y = v_prev_y;
  21898. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  21899. }
  21900. }
  21901. return new THREE.Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  21902. }
  21903. var contourMovements = [];
  21904. for ( var i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  21905. if ( j === il ) j = 0;
  21906. if ( k === il ) k = 0;
  21907. // (j)---(i)---(k)
  21908. // console.log('i,j,k', i, j , k)
  21909. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  21910. }
  21911. var holesMovements = [], oneHoleMovements, verticesMovements = contourMovements.concat();
  21912. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  21913. ahole = holes[ h ];
  21914. oneHoleMovements = [];
  21915. for ( i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  21916. if ( j === il ) j = 0;
  21917. if ( k === il ) k = 0;
  21918. // (j)---(i)---(k)
  21919. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  21920. }
  21921. holesMovements.push( oneHoleMovements );
  21922. verticesMovements = verticesMovements.concat( oneHoleMovements );
  21923. }
  21924. // Loop bevelSegments, 1 for the front, 1 for the back
  21925. for ( b = 0; b < bevelSegments; b ++ ) {
  21926. //for ( b = bevelSegments; b > 0; b -- ) {
  21927. t = b / bevelSegments;
  21928. z = bevelThickness * ( 1 - t );
  21929. //z = bevelThickness * t;
  21930. bs = bevelSize * ( Math.sin ( t * Math.PI / 2 ) ); // curved
  21931. //bs = bevelSize * t; // linear
  21932. // contract shape
  21933. for ( i = 0, il = contour.length; i < il; i ++ ) {
  21934. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  21935. v( vert.x, vert.y, - z );
  21936. }
  21937. // expand holes
  21938. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  21939. ahole = holes[ h ];
  21940. oneHoleMovements = holesMovements[ h ];
  21941. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  21942. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  21943. v( vert.x, vert.y, - z );
  21944. }
  21945. }
  21946. }
  21947. bs = bevelSize;
  21948. // Back facing vertices
  21949. for ( i = 0; i < vlen; i ++ ) {
  21950. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  21951. if ( ! extrudeByPath ) {
  21952. v( vert.x, vert.y, 0 );
  21953. } else {
  21954. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  21955. normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x );
  21956. binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y );
  21957. position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
  21958. v( position2.x, position2.y, position2.z );
  21959. }
  21960. }
  21961. // Add stepped vertices...
  21962. // Including front facing vertices
  21963. var s;
  21964. for ( s = 1; s <= steps; s ++ ) {
  21965. for ( i = 0; i < vlen; i ++ ) {
  21966. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  21967. if ( ! extrudeByPath ) {
  21968. v( vert.x, vert.y, amount / steps * s );
  21969. } else {
  21970. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  21971. normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x );
  21972. binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y );
  21973. position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
  21974. v( position2.x, position2.y, position2.z );
  21975. }
  21976. }
  21977. }
  21978. // Add bevel segments planes
  21979. //for ( b = 1; b <= bevelSegments; b ++ ) {
  21980. for ( b = bevelSegments - 1; b >= 0; b -- ) {
  21981. t = b / bevelSegments;
  21982. z = bevelThickness * ( 1 - t );
  21983. //bs = bevelSize * ( 1-Math.sin ( ( 1 - t ) * Math.PI/2 ) );
  21984. bs = bevelSize * Math.sin ( t * Math.PI / 2 );
  21985. // contract shape
  21986. for ( i = 0, il = contour.length; i < il; i ++ ) {
  21987. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  21988. v( vert.x, vert.y, amount + z );
  21989. }
  21990. // expand holes
  21991. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  21992. ahole = holes[ h ];
  21993. oneHoleMovements = holesMovements[ h ];
  21994. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  21995. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  21996. if ( ! extrudeByPath ) {
  21997. v( vert.x, vert.y, amount + z );
  21998. } else {
  21999. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  22000. }
  22001. }
  22002. }
  22003. }
  22004. /* Faces */
  22005. // Top and bottom faces
  22006. buildLidFaces();
  22007. // Sides faces
  22008. buildSideFaces();
  22009. ///// Internal functions
  22010. function buildLidFaces() {
  22011. if ( bevelEnabled ) {
  22012. var layer = 0; // steps + 1
  22013. var offset = vlen * layer;
  22014. // Bottom faces
  22015. for ( i = 0; i < flen; i ++ ) {
  22016. face = faces[ i ];
  22017. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  22018. }
  22019. layer = steps + bevelSegments * 2;
  22020. offset = vlen * layer;
  22021. // Top faces
  22022. for ( i = 0; i < flen; i ++ ) {
  22023. face = faces[ i ];
  22024. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  22025. }
  22026. } else {
  22027. // Bottom faces
  22028. for ( i = 0; i < flen; i ++ ) {
  22029. face = faces[ i ];
  22030. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  22031. }
  22032. // Top faces
  22033. for ( i = 0; i < flen; i ++ ) {
  22034. face = faces[ i ];
  22035. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  22036. }
  22037. }
  22038. }
  22039. // Create faces for the z-sides of the shape
  22040. function buildSideFaces() {
  22041. var layeroffset = 0;
  22042. sidewalls( contour, layeroffset );
  22043. layeroffset += contour.length;
  22044. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  22045. ahole = holes[ h ];
  22046. sidewalls( ahole, layeroffset );
  22047. //, true
  22048. layeroffset += ahole.length;
  22049. }
  22050. }
  22051. function sidewalls( contour, layeroffset ) {
  22052. var j, k;
  22053. i = contour.length;
  22054. while ( -- i >= 0 ) {
  22055. j = i;
  22056. k = i - 1;
  22057. if ( k < 0 ) k = contour.length - 1;
  22058. //console.log('b', i,j, i-1, k,vertices.length);
  22059. var s = 0, sl = steps + bevelSegments * 2;
  22060. for ( s = 0; s < sl; s ++ ) {
  22061. var slen1 = vlen * s;
  22062. var slen2 = vlen * ( s + 1 );
  22063. var a = layeroffset + j + slen1,
  22064. b = layeroffset + k + slen1,
  22065. c = layeroffset + k + slen2,
  22066. d = layeroffset + j + slen2;
  22067. f4( a, b, c, d, contour, s, sl, j, k );
  22068. }
  22069. }
  22070. }
  22071. function v( x, y, z ) {
  22072. scope.vertices.push( new THREE.Vector3( x, y, z ) );
  22073. }
  22074. function f3( a, b, c ) {
  22075. a += shapesOffset;
  22076. b += shapesOffset;
  22077. c += shapesOffset;
  22078. scope.faces.push( new THREE.Face3( a, b, c, null, null, 0 ) );
  22079. var uvs = uvgen.generateTopUV( scope, a, b, c );
  22080. scope.faceVertexUvs[ 0 ].push( uvs );
  22081. }
  22082. function f4( a, b, c, d, wallContour, stepIndex, stepsLength, contourIndex1, contourIndex2 ) {
  22083. a += shapesOffset;
  22084. b += shapesOffset;
  22085. c += shapesOffset;
  22086. d += shapesOffset;
  22087. scope.faces.push( new THREE.Face3( a, b, d, null, null, 1 ) );
  22088. scope.faces.push( new THREE.Face3( b, c, d, null, null, 1 ) );
  22089. var uvs = uvgen.generateSideWallUV( scope, a, b, c, d );
  22090. scope.faceVertexUvs[ 0 ].push( [ uvs[ 0 ], uvs[ 1 ], uvs[ 3 ] ] );
  22091. scope.faceVertexUvs[ 0 ].push( [ uvs[ 1 ], uvs[ 2 ], uvs[ 3 ] ] );
  22092. }
  22093. };
  22094. THREE.ExtrudeGeometry.WorldUVGenerator = {
  22095. generateTopUV: function ( geometry, indexA, indexB, indexC ) {
  22096. var vertices = geometry.vertices;
  22097. var a = vertices[ indexA ];
  22098. var b = vertices[ indexB ];
  22099. var c = vertices[ indexC ];
  22100. return [
  22101. new THREE.Vector2( a.x, a.y ),
  22102. new THREE.Vector2( b.x, b.y ),
  22103. new THREE.Vector2( c.x, c.y )
  22104. ];
  22105. },
  22106. generateSideWallUV: function ( geometry, indexA, indexB, indexC, indexD ) {
  22107. var vertices = geometry.vertices;
  22108. var a = vertices[ indexA ];
  22109. var b = vertices[ indexB ];
  22110. var c = vertices[ indexC ];
  22111. var d = vertices[ indexD ];
  22112. if ( Math.abs( a.y - b.y ) < 0.01 ) {
  22113. return [
  22114. new THREE.Vector2( a.x, 1 - a.z ),
  22115. new THREE.Vector2( b.x, 1 - b.z ),
  22116. new THREE.Vector2( c.x, 1 - c.z ),
  22117. new THREE.Vector2( d.x, 1 - d.z )
  22118. ];
  22119. } else {
  22120. return [
  22121. new THREE.Vector2( a.y, 1 - a.z ),
  22122. new THREE.Vector2( b.y, 1 - b.z ),
  22123. new THREE.Vector2( c.y, 1 - c.z ),
  22124. new THREE.Vector2( d.y, 1 - d.z )
  22125. ];
  22126. }
  22127. }
  22128. };
  22129. // File:src/extras/geometries/ShapeGeometry.js
  22130. /**
  22131. * @author jonobr1 / http://jonobr1.com
  22132. *
  22133. * Creates a one-sided polygonal geometry from a path shape. Similar to
  22134. * ExtrudeGeometry.
  22135. *
  22136. * parameters = {
  22137. *
  22138. * curveSegments: <int>, // number of points on the curves. NOT USED AT THE MOMENT.
  22139. *
  22140. * material: <int> // material index for front and back faces
  22141. * uvGenerator: <Object> // object that provides UV generator functions
  22142. *
  22143. * }
  22144. **/
  22145. THREE.ShapeGeometry = function ( shapes, options ) {
  22146. THREE.Geometry.call( this );
  22147. this.type = 'ShapeGeometry';
  22148. if ( Array.isArray( shapes ) === false ) shapes = [ shapes ];
  22149. this.addShapeList( shapes, options );
  22150. this.computeFaceNormals();
  22151. };
  22152. THREE.ShapeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22153. THREE.ShapeGeometry.prototype.constructor = THREE.ShapeGeometry;
  22154. /**
  22155. * Add an array of shapes to THREE.ShapeGeometry.
  22156. */
  22157. THREE.ShapeGeometry.prototype.addShapeList = function ( shapes, options ) {
  22158. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  22159. this.addShape( shapes[ i ], options );
  22160. }
  22161. return this;
  22162. };
  22163. /**
  22164. * Adds a shape to THREE.ShapeGeometry, based on THREE.ExtrudeGeometry.
  22165. */
  22166. THREE.ShapeGeometry.prototype.addShape = function ( shape, options ) {
  22167. if ( options === undefined ) options = {};
  22168. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  22169. var material = options.material;
  22170. var uvgen = options.UVGenerator === undefined ? THREE.ExtrudeGeometry.WorldUVGenerator : options.UVGenerator;
  22171. //
  22172. var i, l, hole;
  22173. var shapesOffset = this.vertices.length;
  22174. var shapePoints = shape.extractPoints( curveSegments );
  22175. var vertices = shapePoints.shape;
  22176. var holes = shapePoints.holes;
  22177. var reverse = ! THREE.ShapeUtils.isClockWise( vertices );
  22178. if ( reverse ) {
  22179. vertices = vertices.reverse();
  22180. // Maybe we should also check if holes are in the opposite direction, just to be safe...
  22181. for ( i = 0, l = holes.length; i < l; i ++ ) {
  22182. hole = holes[ i ];
  22183. if ( THREE.ShapeUtils.isClockWise( hole ) ) {
  22184. holes[ i ] = hole.reverse();
  22185. }
  22186. }
  22187. reverse = false;
  22188. }
  22189. var faces = THREE.ShapeUtils.triangulateShape( vertices, holes );
  22190. // Vertices
  22191. for ( i = 0, l = holes.length; i < l; i ++ ) {
  22192. hole = holes[ i ];
  22193. vertices = vertices.concat( hole );
  22194. }
  22195. //
  22196. var vert, vlen = vertices.length;
  22197. var face, flen = faces.length;
  22198. for ( i = 0; i < vlen; i ++ ) {
  22199. vert = vertices[ i ];
  22200. this.vertices.push( new THREE.Vector3( vert.x, vert.y, 0 ) );
  22201. }
  22202. for ( i = 0; i < flen; i ++ ) {
  22203. face = faces[ i ];
  22204. var a = face[ 0 ] + shapesOffset;
  22205. var b = face[ 1 ] + shapesOffset;
  22206. var c = face[ 2 ] + shapesOffset;
  22207. this.faces.push( new THREE.Face3( a, b, c, null, null, material ) );
  22208. this.faceVertexUvs[ 0 ].push( uvgen.generateTopUV( this, a, b, c ) );
  22209. }
  22210. };
  22211. // File:src/extras/geometries/LatheGeometry.js
  22212. /**
  22213. * @author astrodud / http://astrodud.isgreat.org/
  22214. * @author zz85 / https://github.com/zz85
  22215. * @author bhouston / http://clara.io
  22216. */
  22217. // points - to create a closed torus, one must use a set of points
  22218. // like so: [ a, b, c, d, a ], see first is the same as last.
  22219. // segments - the number of circumference segments to create
  22220. // phiStart - the starting radian
  22221. // phiLength - the radian (0 to 2*PI) range of the lathed section
  22222. // 2*pi is a closed lathe, less than 2PI is a portion.
  22223. THREE.LatheGeometry = function ( points, segments, phiStart, phiLength ) {
  22224. THREE.Geometry.call( this );
  22225. this.type = 'LatheGeometry';
  22226. this.parameters = {
  22227. points: points,
  22228. segments: segments,
  22229. phiStart: phiStart,
  22230. phiLength: phiLength
  22231. };
  22232. segments = segments || 12;
  22233. phiStart = phiStart || 0;
  22234. phiLength = phiLength || 2 * Math.PI;
  22235. var inversePointLength = 1.0 / ( points.length - 1 );
  22236. var inverseSegments = 1.0 / segments;
  22237. for ( var i = 0, il = segments; i <= il; i ++ ) {
  22238. var phi = phiStart + i * inverseSegments * phiLength;
  22239. var sin = Math.sin( phi );
  22240. var cos = Math.cos( phi );
  22241. for ( var j = 0, jl = points.length; j < jl; j ++ ) {
  22242. var point = points[ j ];
  22243. var vertex = new THREE.Vector3();
  22244. vertex.x = point.x * sin;
  22245. vertex.y = point.y;
  22246. vertex.z = point.x * cos;
  22247. this.vertices.push( vertex );
  22248. }
  22249. }
  22250. var np = points.length;
  22251. for ( var i = 0, il = segments; i < il; i ++ ) {
  22252. for ( var j = 0, jl = points.length - 1; j < jl; j ++ ) {
  22253. var base = j + np * i;
  22254. var a = base;
  22255. var b = base + np;
  22256. var c = base + 1 + np;
  22257. var d = base + 1;
  22258. var u0 = i * inverseSegments;
  22259. var v0 = j * inversePointLength;
  22260. var u1 = u0 + inverseSegments;
  22261. var v1 = v0 + inversePointLength;
  22262. this.faces.push( new THREE.Face3( a, b, d ) );
  22263. this.faceVertexUvs[ 0 ].push( [
  22264. new THREE.Vector2( u0, v0 ),
  22265. new THREE.Vector2( u1, v0 ),
  22266. new THREE.Vector2( u0, v1 )
  22267. ] );
  22268. this.faces.push( new THREE.Face3( b, c, d ) );
  22269. this.faceVertexUvs[ 0 ].push( [
  22270. new THREE.Vector2( u1, v0 ),
  22271. new THREE.Vector2( u1, v1 ),
  22272. new THREE.Vector2( u0, v1 )
  22273. ] );
  22274. }
  22275. }
  22276. this.mergeVertices();
  22277. this.computeFaceNormals();
  22278. this.computeVertexNormals();
  22279. };
  22280. THREE.LatheGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22281. THREE.LatheGeometry.prototype.constructor = THREE.LatheGeometry;
  22282. // File:src/extras/geometries/PlaneGeometry.js
  22283. /**
  22284. * @author mrdoob / http://mrdoob.com/
  22285. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
  22286. */
  22287. THREE.PlaneGeometry = function ( width, height, widthSegments, heightSegments ) {
  22288. THREE.Geometry.call( this );
  22289. this.type = 'PlaneGeometry';
  22290. this.parameters = {
  22291. width: width,
  22292. height: height,
  22293. widthSegments: widthSegments,
  22294. heightSegments: heightSegments
  22295. };
  22296. this.fromBufferGeometry( new THREE.PlaneBufferGeometry( width, height, widthSegments, heightSegments ) );
  22297. };
  22298. THREE.PlaneGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22299. THREE.PlaneGeometry.prototype.constructor = THREE.PlaneGeometry;
  22300. // File:src/extras/geometries/PlaneBufferGeometry.js
  22301. /**
  22302. * @author mrdoob / http://mrdoob.com/
  22303. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
  22304. */
  22305. THREE.PlaneBufferGeometry = function ( width, height, widthSegments, heightSegments ) {
  22306. THREE.BufferGeometry.call( this );
  22307. this.type = 'PlaneBufferGeometry';
  22308. this.parameters = {
  22309. width: width,
  22310. height: height,
  22311. widthSegments: widthSegments,
  22312. heightSegments: heightSegments
  22313. };
  22314. var width_half = width / 2;
  22315. var height_half = height / 2;
  22316. var gridX = Math.floor( widthSegments ) || 1;
  22317. var gridY = Math.floor( heightSegments ) || 1;
  22318. var gridX1 = gridX + 1;
  22319. var gridY1 = gridY + 1;
  22320. var segment_width = width / gridX;
  22321. var segment_height = height / gridY;
  22322. var vertices = new Float32Array( gridX1 * gridY1 * 3 );
  22323. var normals = new Float32Array( gridX1 * gridY1 * 3 );
  22324. var uvs = new Float32Array( gridX1 * gridY1 * 2 );
  22325. var offset = 0;
  22326. var offset2 = 0;
  22327. for ( var iy = 0; iy < gridY1; iy ++ ) {
  22328. var y = iy * segment_height - height_half;
  22329. for ( var ix = 0; ix < gridX1; ix ++ ) {
  22330. var x = ix * segment_width - width_half;
  22331. vertices[ offset ] = x;
  22332. vertices[ offset + 1 ] = - y;
  22333. normals[ offset + 2 ] = 1;
  22334. uvs[ offset2 ] = ix / gridX;
  22335. uvs[ offset2 + 1 ] = 1 - ( iy / gridY );
  22336. offset += 3;
  22337. offset2 += 2;
  22338. }
  22339. }
  22340. offset = 0;
  22341. var indices = new ( ( vertices.length / 3 ) > 65535 ? Uint32Array : Uint16Array )( gridX * gridY * 6 );
  22342. for ( var iy = 0; iy < gridY; iy ++ ) {
  22343. for ( var ix = 0; ix < gridX; ix ++ ) {
  22344. var a = ix + gridX1 * iy;
  22345. var b = ix + gridX1 * ( iy + 1 );
  22346. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  22347. var d = ( ix + 1 ) + gridX1 * iy;
  22348. indices[ offset ] = a;
  22349. indices[ offset + 1 ] = b;
  22350. indices[ offset + 2 ] = d;
  22351. indices[ offset + 3 ] = b;
  22352. indices[ offset + 4 ] = c;
  22353. indices[ offset + 5 ] = d;
  22354. offset += 6;
  22355. }
  22356. }
  22357. this.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  22358. this.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  22359. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  22360. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  22361. };
  22362. THREE.PlaneBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  22363. THREE.PlaneBufferGeometry.prototype.constructor = THREE.PlaneBufferGeometry;
  22364. // File:src/extras/geometries/RingBufferGeometry.js
  22365. /**
  22366. * @author Mugen87 / https://github.com/Mugen87
  22367. */
  22368. THREE.RingBufferGeometry = function ( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  22369. THREE.BufferGeometry.call( this );
  22370. this.type = 'RingBufferGeometry';
  22371. this.parameters = {
  22372. innerRadius: innerRadius,
  22373. outerRadius: outerRadius,
  22374. thetaSegments: thetaSegments,
  22375. phiSegments: phiSegments,
  22376. thetaStart: thetaStart,
  22377. thetaLength: thetaLength
  22378. };
  22379. innerRadius = innerRadius || 20;
  22380. outerRadius = outerRadius || 50;
  22381. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  22382. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  22383. thetaSegments = thetaSegments !== undefined ? Math.max( 3, thetaSegments ) : 8;
  22384. phiSegments = phiSegments !== undefined ? Math.max( 1, phiSegments ) : 1;
  22385. // these are used to calculate buffer length
  22386. var vertexCount = ( thetaSegments + 1 ) * ( phiSegments + 1 );
  22387. var indexCount = thetaSegments * phiSegments * 2 * 3;
  22388. // buffers
  22389. var indices = new THREE.BufferAttribute( new ( indexCount > 65535 ? Uint32Array : Uint16Array )( indexCount ) , 1 );
  22390. var vertices = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  22391. var normals = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  22392. var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
  22393. // some helper variables
  22394. var index = 0, indexOffset = 0, segment;
  22395. var radius = innerRadius;
  22396. var radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  22397. var vertex = new THREE.Vector3();
  22398. var uv = new THREE.Vector2();
  22399. var j, i;
  22400. // generate vertices, normals and uvs
  22401. // values are generate from the inside of the ring to the outside
  22402. for ( j = 0; j <= phiSegments; j ++ ) {
  22403. for ( i = 0; i <= thetaSegments; i ++ ) {
  22404. segment = thetaStart + i / thetaSegments * thetaLength;
  22405. // vertex
  22406. vertex.x = radius * Math.cos( segment );
  22407. vertex.y = radius * Math.sin( segment );
  22408. vertices.setXYZ( index, vertex.x, vertex.y, vertex.z );
  22409. // normal
  22410. normals.setXYZ( index, 0, 0, 1 );
  22411. // uv
  22412. uv.x = ( vertex.x / outerRadius + 1 ) / 2;
  22413. uv.y = ( vertex.y / outerRadius + 1 ) / 2;
  22414. uvs.setXY( index, uv.x, uv.y );
  22415. // increase index
  22416. index++;
  22417. }
  22418. // increase the radius for next row of vertices
  22419. radius += radiusStep;
  22420. }
  22421. // generate indices
  22422. for ( j = 0; j < phiSegments; j ++ ) {
  22423. var thetaSegmentLevel = j * ( thetaSegments + 1 );
  22424. for ( i = 0; i < thetaSegments; i ++ ) {
  22425. segment = i + thetaSegmentLevel;
  22426. // indices
  22427. var a = segment;
  22428. var b = segment + thetaSegments + 1;
  22429. var c = segment + thetaSegments + 2;
  22430. var d = segment + 1;
  22431. // face one
  22432. indices.setX( indexOffset, a ); indexOffset++;
  22433. indices.setX( indexOffset, b ); indexOffset++;
  22434. indices.setX( indexOffset, c ); indexOffset++;
  22435. // face two
  22436. indices.setX( indexOffset, a ); indexOffset++;
  22437. indices.setX( indexOffset, c ); indexOffset++;
  22438. indices.setX( indexOffset, d ); indexOffset++;
  22439. }
  22440. }
  22441. // build geometry
  22442. this.setIndex( indices );
  22443. this.addAttribute( 'position', vertices );
  22444. this.addAttribute( 'normal', normals );
  22445. this.addAttribute( 'uv', uvs );
  22446. };
  22447. THREE.RingBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  22448. THREE.RingBufferGeometry.prototype.constructor = THREE.RingBufferGeometry;
  22449. // File:src/extras/geometries/RingGeometry.js
  22450. /**
  22451. * @author Kaleb Murphy
  22452. */
  22453. THREE.RingGeometry = function ( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  22454. THREE.Geometry.call( this );
  22455. this.type = 'RingGeometry';
  22456. this.parameters = {
  22457. innerRadius: innerRadius,
  22458. outerRadius: outerRadius,
  22459. thetaSegments: thetaSegments,
  22460. phiSegments: phiSegments,
  22461. thetaStart: thetaStart,
  22462. thetaLength: thetaLength
  22463. };
  22464. this.fromBufferGeometry( new THREE.RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) );
  22465. };
  22466. THREE.RingGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22467. THREE.RingGeometry.prototype.constructor = THREE.RingGeometry;
  22468. // File:src/extras/geometries/SphereGeometry.js
  22469. /**
  22470. * @author mrdoob / http://mrdoob.com/
  22471. */
  22472. THREE.SphereGeometry = function ( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  22473. THREE.Geometry.call( this );
  22474. this.type = 'SphereGeometry';
  22475. this.parameters = {
  22476. radius: radius,
  22477. widthSegments: widthSegments,
  22478. heightSegments: heightSegments,
  22479. phiStart: phiStart,
  22480. phiLength: phiLength,
  22481. thetaStart: thetaStart,
  22482. thetaLength: thetaLength
  22483. };
  22484. this.fromBufferGeometry( new THREE.SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) );
  22485. };
  22486. THREE.SphereGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22487. THREE.SphereGeometry.prototype.constructor = THREE.SphereGeometry;
  22488. // File:src/extras/geometries/SphereBufferGeometry.js
  22489. /**
  22490. * @author benaadams / https://twitter.com/ben_a_adams
  22491. * based on THREE.SphereGeometry
  22492. */
  22493. THREE.SphereBufferGeometry = function ( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  22494. THREE.BufferGeometry.call( this );
  22495. this.type = 'SphereBufferGeometry';
  22496. this.parameters = {
  22497. radius: radius,
  22498. widthSegments: widthSegments,
  22499. heightSegments: heightSegments,
  22500. phiStart: phiStart,
  22501. phiLength: phiLength,
  22502. thetaStart: thetaStart,
  22503. thetaLength: thetaLength
  22504. };
  22505. radius = radius || 50;
  22506. widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
  22507. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  22508. phiStart = phiStart !== undefined ? phiStart : 0;
  22509. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  22510. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  22511. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  22512. var thetaEnd = thetaStart + thetaLength;
  22513. var vertexCount = ( ( widthSegments + 1 ) * ( heightSegments + 1 ) );
  22514. var positions = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  22515. var normals = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  22516. var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
  22517. var index = 0, vertices = [], normal = new THREE.Vector3();
  22518. for ( var y = 0; y <= heightSegments; y ++ ) {
  22519. var verticesRow = [];
  22520. var v = y / heightSegments;
  22521. for ( var x = 0; x <= widthSegments; x ++ ) {
  22522. var u = x / widthSegments;
  22523. var px = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  22524. var py = radius * Math.cos( thetaStart + v * thetaLength );
  22525. var pz = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  22526. normal.set( px, py, pz ).normalize();
  22527. positions.setXYZ( index, px, py, pz );
  22528. normals.setXYZ( index, normal.x, normal.y, normal.z );
  22529. uvs.setXY( index, u, 1 - v );
  22530. verticesRow.push( index );
  22531. index ++;
  22532. }
  22533. vertices.push( verticesRow );
  22534. }
  22535. var indices = [];
  22536. for ( var y = 0; y < heightSegments; y ++ ) {
  22537. for ( var x = 0; x < widthSegments; x ++ ) {
  22538. var v1 = vertices[ y ][ x + 1 ];
  22539. var v2 = vertices[ y ][ x ];
  22540. var v3 = vertices[ y + 1 ][ x ];
  22541. var v4 = vertices[ y + 1 ][ x + 1 ];
  22542. if ( y !== 0 || thetaStart > 0 ) indices.push( v1, v2, v4 );
  22543. if ( y !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( v2, v3, v4 );
  22544. }
  22545. }
  22546. this.setIndex( new ( positions.count > 65535 ? THREE.Uint32Attribute : THREE.Uint16Attribute )( indices, 1 ) );
  22547. this.addAttribute( 'position', positions );
  22548. this.addAttribute( 'normal', normals );
  22549. this.addAttribute( 'uv', uvs );
  22550. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  22551. };
  22552. THREE.SphereBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  22553. THREE.SphereBufferGeometry.prototype.constructor = THREE.SphereBufferGeometry;
  22554. // File:src/extras/geometries/TextGeometry.js
  22555. /**
  22556. * @author zz85 / http://www.lab4games.net/zz85/blog
  22557. * @author alteredq / http://alteredqualia.com/
  22558. *
  22559. * Text = 3D Text
  22560. *
  22561. * parameters = {
  22562. * font: <THREE.Font>, // font
  22563. *
  22564. * size: <float>, // size of the text
  22565. * height: <float>, // thickness to extrude text
  22566. * curveSegments: <int>, // number of points on the curves
  22567. *
  22568. * bevelEnabled: <bool>, // turn on bevel
  22569. * bevelThickness: <float>, // how deep into text bevel goes
  22570. * bevelSize: <float> // how far from text outline is bevel
  22571. * }
  22572. */
  22573. THREE.TextGeometry = function ( text, parameters ) {
  22574. parameters = parameters || {};
  22575. var font = parameters.font;
  22576. if ( font instanceof THREE.Font === false ) {
  22577. console.error( 'THREE.TextGeometry: font parameter is not an instance of THREE.Font.' );
  22578. return new THREE.Geometry();
  22579. }
  22580. var shapes = font.generateShapes( text, parameters.size, parameters.curveSegments );
  22581. // translate parameters to ExtrudeGeometry API
  22582. parameters.amount = parameters.height !== undefined ? parameters.height : 50;
  22583. // defaults
  22584. if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
  22585. if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
  22586. if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
  22587. THREE.ExtrudeGeometry.call( this, shapes, parameters );
  22588. this.type = 'TextGeometry';
  22589. };
  22590. THREE.TextGeometry.prototype = Object.create( THREE.ExtrudeGeometry.prototype );
  22591. THREE.TextGeometry.prototype.constructor = THREE.TextGeometry;
  22592. // File:src/extras/geometries/TorusBufferGeometry.js
  22593. /**
  22594. * @author Mugen87 / https://github.com/Mugen87
  22595. */
  22596. THREE.TorusBufferGeometry = function ( radius, tube, radialSegments, tubularSegments, arc ) {
  22597. THREE.BufferGeometry.call( this );
  22598. this.type = 'TorusBufferGeometry';
  22599. this.parameters = {
  22600. radius: radius,
  22601. tube: tube,
  22602. radialSegments: radialSegments,
  22603. tubularSegments: tubularSegments,
  22604. arc: arc
  22605. };
  22606. radius = radius || 100;
  22607. tube = tube || 40;
  22608. radialSegments = Math.floor( radialSegments ) || 8;
  22609. tubularSegments = Math.floor( tubularSegments ) || 6;
  22610. arc = arc || Math.PI * 2;
  22611. // used to calculate buffer length
  22612. var vertexCount = ( ( radialSegments + 1 ) * ( tubularSegments + 1 ) );
  22613. var indexCount = radialSegments * tubularSegments * 2 * 3;
  22614. // buffers
  22615. var indices = new ( indexCount > 65535 ? Uint32Array : Uint16Array )( indexCount );
  22616. var vertices = new Float32Array( vertexCount * 3 );
  22617. var normals = new Float32Array( vertexCount * 3 );
  22618. var uvs = new Float32Array( vertexCount * 2 );
  22619. // offset variables
  22620. var vertexBufferOffset = 0;
  22621. var uvBufferOffset = 0;
  22622. var indexBufferOffset = 0;
  22623. // helper variables
  22624. var center = new THREE.Vector3();
  22625. var vertex = new THREE.Vector3();
  22626. var normal = new THREE.Vector3();
  22627. var j, i;
  22628. // generate vertices, normals and uvs
  22629. for ( j = 0; j <= radialSegments; j ++ ) {
  22630. for ( i = 0; i <= tubularSegments; i ++ ) {
  22631. var u = i / tubularSegments * arc;
  22632. var v = j / radialSegments * Math.PI * 2;
  22633. // vertex
  22634. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  22635. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  22636. vertex.z = tube * Math.sin( v );
  22637. vertices[ vertexBufferOffset ] = vertex.x;
  22638. vertices[ vertexBufferOffset + 1 ] = vertex.y;
  22639. vertices[ vertexBufferOffset + 2 ] = vertex.z;
  22640. // this vector is used to calculate the normal
  22641. center.x = radius * Math.cos( u );
  22642. center.y = radius * Math.sin( u );
  22643. // normal
  22644. normal.subVectors( vertex, center ).normalize();
  22645. normals[ vertexBufferOffset ] = normal.x;
  22646. normals[ vertexBufferOffset + 1 ] = normal.y;
  22647. normals[ vertexBufferOffset + 2 ] = normal.z;
  22648. // uv
  22649. uvs[ uvBufferOffset ] = i / tubularSegments;
  22650. uvs[ uvBufferOffset + 1 ] = j / radialSegments;
  22651. // update offsets
  22652. vertexBufferOffset += 3;
  22653. uvBufferOffset += 2;
  22654. }
  22655. }
  22656. // generate indices
  22657. for ( j = 1; j <= radialSegments; j ++ ) {
  22658. for ( i = 1; i <= tubularSegments; i ++ ) {
  22659. // indices
  22660. var a = ( tubularSegments + 1 ) * j + i - 1;
  22661. var b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  22662. var c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  22663. var d = ( tubularSegments + 1 ) * j + i;
  22664. // face one
  22665. indices[ indexBufferOffset ] = a;
  22666. indices[ indexBufferOffset + 1 ] = b;
  22667. indices[ indexBufferOffset + 2 ] = d;
  22668. // face two
  22669. indices[ indexBufferOffset + 3 ] = b;
  22670. indices[ indexBufferOffset + 4 ] = c;
  22671. indices[ indexBufferOffset + 5 ] = d;
  22672. // update offset
  22673. indexBufferOffset += 6;
  22674. }
  22675. }
  22676. // build geometry
  22677. this.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  22678. this.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  22679. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  22680. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  22681. };
  22682. THREE.TorusBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  22683. THREE.TorusBufferGeometry.prototype.constructor = THREE.TorusBufferGeometry;
  22684. // File:src/extras/geometries/TorusGeometry.js
  22685. /**
  22686. * @author oosmoxiecode
  22687. * @author mrdoob / http://mrdoob.com/
  22688. * based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3DLite/src/away3dlite/primitives/Torus.as?r=2888
  22689. */
  22690. THREE.TorusGeometry = function ( radius, tube, radialSegments, tubularSegments, arc ) {
  22691. THREE.Geometry.call( this );
  22692. this.type = 'TorusGeometry';
  22693. this.parameters = {
  22694. radius: radius,
  22695. tube: tube,
  22696. radialSegments: radialSegments,
  22697. tubularSegments: tubularSegments,
  22698. arc: arc
  22699. };
  22700. this.fromBufferGeometry( new THREE.TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) );
  22701. };
  22702. THREE.TorusGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22703. THREE.TorusGeometry.prototype.constructor = THREE.TorusGeometry;
  22704. // File:src/extras/geometries/TorusKnotBufferGeometry.js
  22705. /**
  22706. * @author Mugen87 / https://github.com/Mugen87
  22707. *
  22708. * see: http://www.blackpawn.com/texts/pqtorus/
  22709. */
  22710. THREE.TorusKnotBufferGeometry = function ( radius, tube, tubularSegments, radialSegments, p, q ) {
  22711. THREE.BufferGeometry.call( this );
  22712. this.type = 'TorusKnotBufferGeometry';
  22713. this.parameters = {
  22714. radius: radius,
  22715. tube: tube,
  22716. tubularSegments: tubularSegments,
  22717. radialSegments: radialSegments,
  22718. p: p,
  22719. q: q
  22720. };
  22721. radius = radius || 100;
  22722. tube = tube || 40;
  22723. tubularSegments = Math.floor( tubularSegments ) || 64;
  22724. radialSegments = Math.floor( radialSegments ) || 8;
  22725. p = p || 2;
  22726. q = q || 3;
  22727. // used to calculate buffer length
  22728. var vertexCount = ( ( radialSegments + 1 ) * ( tubularSegments + 1 ) );
  22729. var indexCount = radialSegments * tubularSegments * 2 * 3;
  22730. // buffers
  22731. var indices = new THREE.BufferAttribute( new ( indexCount > 65535 ? Uint32Array : Uint16Array )( indexCount ) , 1 );
  22732. var vertices = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  22733. var normals = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  22734. var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
  22735. // helper variables
  22736. var i, j, index = 0, indexOffset = 0;
  22737. var vertex = new THREE.Vector3();
  22738. var normal = new THREE.Vector3();
  22739. var uv = new THREE.Vector2();
  22740. var P1 = new THREE.Vector3();
  22741. var P2 = new THREE.Vector3();
  22742. var B = new THREE.Vector3();
  22743. var T = new THREE.Vector3();
  22744. var N = new THREE.Vector3();
  22745. // generate vertices, normals and uvs
  22746. for ( i = 0; i <= tubularSegments; ++ i ) {
  22747. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  22748. var u = i / tubularSegments * p * Math.PI * 2;
  22749. // now we calculate two points. P1 is our current position on the curve, P2 is a little farther ahead.
  22750. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  22751. calculatePositionOnCurve( u, p, q, radius, P1 );
  22752. calculatePositionOnCurve( u + 0.01, p, q, radius, P2 );
  22753. // calculate orthonormal basis
  22754. T.subVectors( P2, P1 );
  22755. N.addVectors( P2, P1 );
  22756. B.crossVectors( T, N );
  22757. N.crossVectors( B, T );
  22758. // normalize B, N. T can be ignored, we don't use it
  22759. B.normalize();
  22760. N.normalize();
  22761. for ( j = 0; j <= radialSegments; ++ j ) {
  22762. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  22763. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  22764. var v = j / radialSegments * Math.PI * 2;
  22765. var cx = - tube * Math.cos( v );
  22766. var cy = tube * Math.sin( v );
  22767. // now calculate the final vertex position.
  22768. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  22769. vertex.x = P1.x + ( cx * N.x + cy * B.x );
  22770. vertex.y = P1.y + ( cx * N.y + cy * B.y );
  22771. vertex.z = P1.z + ( cx * N.z + cy * B.z );
  22772. // vertex
  22773. vertices.setXYZ( index, vertex.x, vertex.y, vertex.z );
  22774. // normal (P1 is always the center/origin of the extrusion, thus we can use it to calculate the normal)
  22775. normal.subVectors( vertex, P1 ).normalize();
  22776. normals.setXYZ( index, normal.x, normal.y, normal.z );
  22777. // uv
  22778. uv.x = i / tubularSegments;
  22779. uv.y = j / radialSegments;
  22780. uvs.setXY( index, uv.x, uv.y );
  22781. // increase index
  22782. index ++;
  22783. }
  22784. }
  22785. // generate indices
  22786. for ( j = 1; j <= tubularSegments; j ++ ) {
  22787. for ( i = 1; i <= radialSegments; i ++ ) {
  22788. // indices
  22789. var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  22790. var b = ( radialSegments + 1 ) * j + ( i - 1 );
  22791. var c = ( radialSegments + 1 ) * j + i;
  22792. var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  22793. // face one
  22794. indices.setX( indexOffset, a ); indexOffset++;
  22795. indices.setX( indexOffset, b ); indexOffset++;
  22796. indices.setX( indexOffset, d ); indexOffset++;
  22797. // face two
  22798. indices.setX( indexOffset, b ); indexOffset++;
  22799. indices.setX( indexOffset, c ); indexOffset++;
  22800. indices.setX( indexOffset, d ); indexOffset++;
  22801. }
  22802. }
  22803. // build geometry
  22804. this.setIndex( indices );
  22805. this.addAttribute( 'position', vertices );
  22806. this.addAttribute( 'normal', normals );
  22807. this.addAttribute( 'uv', uvs );
  22808. // this function calculates the current position on the torus curve
  22809. function calculatePositionOnCurve( u, p, q, radius, position ) {
  22810. var cu = Math.cos( u );
  22811. var su = Math.sin( u );
  22812. var quOverP = q / p * u;
  22813. var cs = Math.cos( quOverP );
  22814. position.x = radius * ( 2 + cs ) * 0.5 * cu;
  22815. position.y = radius * ( 2 + cs ) * su * 0.5;
  22816. position.z = radius * Math.sin( quOverP ) * 0.5;
  22817. }
  22818. };
  22819. THREE.TorusKnotBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  22820. THREE.TorusKnotBufferGeometry.prototype.constructor = THREE.TorusKnotBufferGeometry;
  22821. // File:src/extras/geometries/TorusKnotGeometry.js
  22822. /**
  22823. * @author oosmoxiecode
  22824. */
  22825. THREE.TorusKnotGeometry = function ( radius, tube, tubularSegments, radialSegments, p, q, heightScale ) {
  22826. THREE.Geometry.call( this );
  22827. this.type = 'TorusKnotGeometry';
  22828. this.parameters = {
  22829. radius: radius,
  22830. tube: tube,
  22831. tubularSegments: tubularSegments,
  22832. radialSegments: radialSegments,
  22833. p: p,
  22834. q: q
  22835. };
  22836. if( heightScale !== undefined ) console.warn( 'THREE.TorusKnotGeometry: heightScale has been deprecated. Use .scale( x, y, z ) instead.' );
  22837. this.fromBufferGeometry( new THREE.TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) );
  22838. this.mergeVertices();
  22839. };
  22840. THREE.TorusKnotGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22841. THREE.TorusKnotGeometry.prototype.constructor = THREE.TorusKnotGeometry;
  22842. // File:src/extras/geometries/TubeGeometry.js
  22843. /**
  22844. * @author WestLangley / https://github.com/WestLangley
  22845. * @author zz85 / https://github.com/zz85
  22846. * @author miningold / https://github.com/miningold
  22847. * @author jonobr1 / https://github.com/jonobr1
  22848. *
  22849. * Modified from the TorusKnotGeometry by @oosmoxiecode
  22850. *
  22851. * Creates a tube which extrudes along a 3d spline
  22852. *
  22853. * Uses parallel transport frames as described in
  22854. * http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  22855. */
  22856. THREE.TubeGeometry = function ( path, segments, radius, radialSegments, closed, taper ) {
  22857. THREE.Geometry.call( this );
  22858. this.type = 'TubeGeometry';
  22859. this.parameters = {
  22860. path: path,
  22861. segments: segments,
  22862. radius: radius,
  22863. radialSegments: radialSegments,
  22864. closed: closed,
  22865. taper: taper
  22866. };
  22867. segments = segments || 64;
  22868. radius = radius || 1;
  22869. radialSegments = radialSegments || 8;
  22870. closed = closed || false;
  22871. taper = taper || THREE.TubeGeometry.NoTaper;
  22872. var grid = [];
  22873. var scope = this,
  22874. tangent,
  22875. normal,
  22876. binormal,
  22877. numpoints = segments + 1,
  22878. u, v, r,
  22879. cx, cy,
  22880. pos, pos2 = new THREE.Vector3(),
  22881. i, j,
  22882. ip, jp,
  22883. a, b, c, d,
  22884. uva, uvb, uvc, uvd;
  22885. var frames = new THREE.TubeGeometry.FrenetFrames( path, segments, closed ),
  22886. tangents = frames.tangents,
  22887. normals = frames.normals,
  22888. binormals = frames.binormals;
  22889. // proxy internals
  22890. this.tangents = tangents;
  22891. this.normals = normals;
  22892. this.binormals = binormals;
  22893. function vert( x, y, z ) {
  22894. return scope.vertices.push( new THREE.Vector3( x, y, z ) ) - 1;
  22895. }
  22896. // construct the grid
  22897. for ( i = 0; i < numpoints; i ++ ) {
  22898. grid[ i ] = [];
  22899. u = i / ( numpoints - 1 );
  22900. pos = path.getPointAt( u );
  22901. tangent = tangents[ i ];
  22902. normal = normals[ i ];
  22903. binormal = binormals[ i ];
  22904. r = radius * taper( u );
  22905. for ( j = 0; j < radialSegments; j ++ ) {
  22906. v = j / radialSegments * 2 * Math.PI;
  22907. cx = - r * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
  22908. cy = r * Math.sin( v );
  22909. pos2.copy( pos );
  22910. pos2.x += cx * normal.x + cy * binormal.x;
  22911. pos2.y += cx * normal.y + cy * binormal.y;
  22912. pos2.z += cx * normal.z + cy * binormal.z;
  22913. grid[ i ][ j ] = vert( pos2.x, pos2.y, pos2.z );
  22914. }
  22915. }
  22916. // construct the mesh
  22917. for ( i = 0; i < segments; i ++ ) {
  22918. for ( j = 0; j < radialSegments; j ++ ) {
  22919. ip = ( closed ) ? ( i + 1 ) % segments : i + 1;
  22920. jp = ( j + 1 ) % radialSegments;
  22921. a = grid[ i ][ j ]; // *** NOT NECESSARILY PLANAR ! ***
  22922. b = grid[ ip ][ j ];
  22923. c = grid[ ip ][ jp ];
  22924. d = grid[ i ][ jp ];
  22925. uva = new THREE.Vector2( i / segments, j / radialSegments );
  22926. uvb = new THREE.Vector2( ( i + 1 ) / segments, j / radialSegments );
  22927. uvc = new THREE.Vector2( ( i + 1 ) / segments, ( j + 1 ) / radialSegments );
  22928. uvd = new THREE.Vector2( i / segments, ( j + 1 ) / radialSegments );
  22929. this.faces.push( new THREE.Face3( a, b, d ) );
  22930. this.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  22931. this.faces.push( new THREE.Face3( b, c, d ) );
  22932. this.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  22933. }
  22934. }
  22935. this.computeFaceNormals();
  22936. this.computeVertexNormals();
  22937. };
  22938. THREE.TubeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22939. THREE.TubeGeometry.prototype.constructor = THREE.TubeGeometry;
  22940. THREE.TubeGeometry.NoTaper = function ( u ) {
  22941. return 1;
  22942. };
  22943. THREE.TubeGeometry.SinusoidalTaper = function ( u ) {
  22944. return Math.sin( Math.PI * u );
  22945. };
  22946. // For computing of Frenet frames, exposing the tangents, normals and binormals the spline
  22947. THREE.TubeGeometry.FrenetFrames = function ( path, segments, closed ) {
  22948. var normal = new THREE.Vector3(),
  22949. tangents = [],
  22950. normals = [],
  22951. binormals = [],
  22952. vec = new THREE.Vector3(),
  22953. mat = new THREE.Matrix4(),
  22954. numpoints = segments + 1,
  22955. theta,
  22956. smallest,
  22957. tx, ty, tz,
  22958. i, u;
  22959. // expose internals
  22960. this.tangents = tangents;
  22961. this.normals = normals;
  22962. this.binormals = binormals;
  22963. // compute the tangent vectors for each segment on the path
  22964. for ( i = 0; i < numpoints; i ++ ) {
  22965. u = i / ( numpoints - 1 );
  22966. tangents[ i ] = path.getTangentAt( u );
  22967. tangents[ i ].normalize();
  22968. }
  22969. initialNormal3();
  22970. /*
  22971. function initialNormal1(lastBinormal) {
  22972. // fixed start binormal. Has dangers of 0 vectors
  22973. normals[ 0 ] = new THREE.Vector3();
  22974. binormals[ 0 ] = new THREE.Vector3();
  22975. if (lastBinormal===undefined) lastBinormal = new THREE.Vector3( 0, 0, 1 );
  22976. normals[ 0 ].crossVectors( lastBinormal, tangents[ 0 ] ).normalize();
  22977. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] ).normalize();
  22978. }
  22979. function initialNormal2() {
  22980. // This uses the Frenet-Serret formula for deriving binormal
  22981. var t2 = path.getTangentAt( epsilon );
  22982. normals[ 0 ] = new THREE.Vector3().subVectors( t2, tangents[ 0 ] ).normalize();
  22983. binormals[ 0 ] = new THREE.Vector3().crossVectors( tangents[ 0 ], normals[ 0 ] );
  22984. normals[ 0 ].crossVectors( binormals[ 0 ], tangents[ 0 ] ).normalize(); // last binormal x tangent
  22985. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] ).normalize();
  22986. }
  22987. */
  22988. function initialNormal3() {
  22989. // select an initial normal vector perpendicular to the first tangent vector,
  22990. // and in the direction of the smallest tangent xyz component
  22991. normals[ 0 ] = new THREE.Vector3();
  22992. binormals[ 0 ] = new THREE.Vector3();
  22993. smallest = Number.MAX_VALUE;
  22994. tx = Math.abs( tangents[ 0 ].x );
  22995. ty = Math.abs( tangents[ 0 ].y );
  22996. tz = Math.abs( tangents[ 0 ].z );
  22997. if ( tx <= smallest ) {
  22998. smallest = tx;
  22999. normal.set( 1, 0, 0 );
  23000. }
  23001. if ( ty <= smallest ) {
  23002. smallest = ty;
  23003. normal.set( 0, 1, 0 );
  23004. }
  23005. if ( tz <= smallest ) {
  23006. normal.set( 0, 0, 1 );
  23007. }
  23008. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  23009. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  23010. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  23011. }
  23012. // compute the slowly-varying normal and binormal vectors for each segment on the path
  23013. for ( i = 1; i < numpoints; i ++ ) {
  23014. normals[ i ] = normals[ i - 1 ].clone();
  23015. binormals[ i ] = binormals[ i - 1 ].clone();
  23016. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  23017. if ( vec.length() > Number.EPSILON ) {
  23018. vec.normalize();
  23019. theta = Math.acos( THREE.Math.clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  23020. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  23021. }
  23022. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  23023. }
  23024. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  23025. if ( closed ) {
  23026. theta = Math.acos( THREE.Math.clamp( normals[ 0 ].dot( normals[ numpoints - 1 ] ), - 1, 1 ) );
  23027. theta /= ( numpoints - 1 );
  23028. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ numpoints - 1 ] ) ) > 0 ) {
  23029. theta = - theta;
  23030. }
  23031. for ( i = 1; i < numpoints; i ++ ) {
  23032. // twist a little...
  23033. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  23034. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  23035. }
  23036. }
  23037. };
  23038. // File:src/extras/geometries/PolyhedronGeometry.js
  23039. /**
  23040. * @author clockworkgeek / https://github.com/clockworkgeek
  23041. * @author timothypratley / https://github.com/timothypratley
  23042. * @author WestLangley / http://github.com/WestLangley
  23043. */
  23044. THREE.PolyhedronGeometry = function ( vertices, indices, radius, detail ) {
  23045. THREE.Geometry.call( this );
  23046. this.type = 'PolyhedronGeometry';
  23047. this.parameters = {
  23048. vertices: vertices,
  23049. indices: indices,
  23050. radius: radius,
  23051. detail: detail
  23052. };
  23053. radius = radius || 1;
  23054. detail = detail || 0;
  23055. var that = this;
  23056. for ( var i = 0, l = vertices.length; i < l; i += 3 ) {
  23057. prepare( new THREE.Vector3( vertices[ i ], vertices[ i + 1 ], vertices[ i + 2 ] ) );
  23058. }
  23059. var p = this.vertices;
  23060. var faces = [];
  23061. for ( var i = 0, j = 0, l = indices.length; i < l; i += 3, j ++ ) {
  23062. var v1 = p[ indices[ i ] ];
  23063. var v2 = p[ indices[ i + 1 ] ];
  23064. var v3 = p[ indices[ i + 2 ] ];
  23065. faces[ j ] = new THREE.Face3( v1.index, v2.index, v3.index, [ v1.clone(), v2.clone(), v3.clone() ], undefined, j );
  23066. }
  23067. var centroid = new THREE.Vector3();
  23068. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  23069. subdivide( faces[ i ], detail );
  23070. }
  23071. // Handle case when face straddles the seam
  23072. for ( var i = 0, l = this.faceVertexUvs[ 0 ].length; i < l; i ++ ) {
  23073. var uvs = this.faceVertexUvs[ 0 ][ i ];
  23074. var x0 = uvs[ 0 ].x;
  23075. var x1 = uvs[ 1 ].x;
  23076. var x2 = uvs[ 2 ].x;
  23077. var max = Math.max( x0, x1, x2 );
  23078. var min = Math.min( x0, x1, x2 );
  23079. if ( max > 0.9 && min < 0.1 ) {
  23080. // 0.9 is somewhat arbitrary
  23081. if ( x0 < 0.2 ) uvs[ 0 ].x += 1;
  23082. if ( x1 < 0.2 ) uvs[ 1 ].x += 1;
  23083. if ( x2 < 0.2 ) uvs[ 2 ].x += 1;
  23084. }
  23085. }
  23086. // Apply radius
  23087. for ( var i = 0, l = this.vertices.length; i < l; i ++ ) {
  23088. this.vertices[ i ].multiplyScalar( radius );
  23089. }
  23090. // Merge vertices
  23091. this.mergeVertices();
  23092. this.computeFaceNormals();
  23093. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  23094. // Project vector onto sphere's surface
  23095. function prepare( vector ) {
  23096. var vertex = vector.normalize().clone();
  23097. vertex.index = that.vertices.push( vertex ) - 1;
  23098. // Texture coords are equivalent to map coords, calculate angle and convert to fraction of a circle.
  23099. var u = azimuth( vector ) / 2 / Math.PI + 0.5;
  23100. var v = inclination( vector ) / Math.PI + 0.5;
  23101. vertex.uv = new THREE.Vector2( u, 1 - v );
  23102. return vertex;
  23103. }
  23104. // Approximate a curved face with recursively sub-divided triangles.
  23105. function make( v1, v2, v3, materialIndex ) {
  23106. var face = new THREE.Face3( v1.index, v2.index, v3.index, [ v1.clone(), v2.clone(), v3.clone() ], undefined, materialIndex );
  23107. that.faces.push( face );
  23108. centroid.copy( v1 ).add( v2 ).add( v3 ).divideScalar( 3 );
  23109. var azi = azimuth( centroid );
  23110. that.faceVertexUvs[ 0 ].push( [
  23111. correctUV( v1.uv, v1, azi ),
  23112. correctUV( v2.uv, v2, azi ),
  23113. correctUV( v3.uv, v3, azi )
  23114. ] );
  23115. }
  23116. // Analytically subdivide a face to the required detail level.
  23117. function subdivide( face, detail ) {
  23118. var cols = Math.pow( 2, detail );
  23119. var a = prepare( that.vertices[ face.a ] );
  23120. var b = prepare( that.vertices[ face.b ] );
  23121. var c = prepare( that.vertices[ face.c ] );
  23122. var v = [];
  23123. var materialIndex = face.materialIndex;
  23124. // Construct all of the vertices for this subdivision.
  23125. for ( var i = 0 ; i <= cols; i ++ ) {
  23126. v[ i ] = [];
  23127. var aj = prepare( a.clone().lerp( c, i / cols ) );
  23128. var bj = prepare( b.clone().lerp( c, i / cols ) );
  23129. var rows = cols - i;
  23130. for ( var j = 0; j <= rows; j ++ ) {
  23131. if ( j === 0 && i === cols ) {
  23132. v[ i ][ j ] = aj;
  23133. } else {
  23134. v[ i ][ j ] = prepare( aj.clone().lerp( bj, j / rows ) );
  23135. }
  23136. }
  23137. }
  23138. // Construct all of the faces.
  23139. for ( var i = 0; i < cols ; i ++ ) {
  23140. for ( var j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
  23141. var k = Math.floor( j / 2 );
  23142. if ( j % 2 === 0 ) {
  23143. make(
  23144. v[ i ][ k + 1 ],
  23145. v[ i + 1 ][ k ],
  23146. v[ i ][ k ],
  23147. materialIndex
  23148. );
  23149. } else {
  23150. make(
  23151. v[ i ][ k + 1 ],
  23152. v[ i + 1 ][ k + 1 ],
  23153. v[ i + 1 ][ k ],
  23154. materialIndex
  23155. );
  23156. }
  23157. }
  23158. }
  23159. }
  23160. // Angle around the Y axis, counter-clockwise when looking from above.
  23161. function azimuth( vector ) {
  23162. return Math.atan2( vector.z, - vector.x );
  23163. }
  23164. // Angle above the XZ plane.
  23165. function inclination( vector ) {
  23166. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  23167. }
  23168. // Texture fixing helper. Spheres have some odd behaviours.
  23169. function correctUV( uv, vector, azimuth ) {
  23170. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) uv = new THREE.Vector2( uv.x - 1, uv.y );
  23171. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) uv = new THREE.Vector2( azimuth / 2 / Math.PI + 0.5, uv.y );
  23172. return uv.clone();
  23173. }
  23174. };
  23175. THREE.PolyhedronGeometry.prototype = Object.create( THREE.Geometry.prototype );
  23176. THREE.PolyhedronGeometry.prototype.constructor = THREE.PolyhedronGeometry;
  23177. // File:src/extras/geometries/DodecahedronGeometry.js
  23178. /**
  23179. * @author Abe Pazos / https://hamoid.com
  23180. */
  23181. THREE.DodecahedronGeometry = function ( radius, detail ) {
  23182. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  23183. var r = 1 / t;
  23184. var vertices = [
  23185. // (±1, ±1, ±1)
  23186. - 1, - 1, - 1, - 1, - 1, 1,
  23187. - 1, 1, - 1, - 1, 1, 1,
  23188. 1, - 1, - 1, 1, - 1, 1,
  23189. 1, 1, - 1, 1, 1, 1,
  23190. // (0, ±1/φ, ±φ)
  23191. 0, - r, - t, 0, - r, t,
  23192. 0, r, - t, 0, r, t,
  23193. // (±1/φ, ±φ, 0)
  23194. - r, - t, 0, - r, t, 0,
  23195. r, - t, 0, r, t, 0,
  23196. // (±φ, 0, ±1/φ)
  23197. - t, 0, - r, t, 0, - r,
  23198. - t, 0, r, t, 0, r
  23199. ];
  23200. var indices = [
  23201. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  23202. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  23203. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  23204. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  23205. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  23206. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  23207. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  23208. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  23209. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  23210. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  23211. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  23212. 1, 12, 14, 1, 14, 5, 1, 5, 9
  23213. ];
  23214. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  23215. this.type = 'DodecahedronGeometry';
  23216. this.parameters = {
  23217. radius: radius,
  23218. detail: detail
  23219. };
  23220. };
  23221. THREE.DodecahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  23222. THREE.DodecahedronGeometry.prototype.constructor = THREE.DodecahedronGeometry;
  23223. // File:src/extras/geometries/IcosahedronGeometry.js
  23224. /**
  23225. * @author timothypratley / https://github.com/timothypratley
  23226. */
  23227. THREE.IcosahedronGeometry = function ( radius, detail ) {
  23228. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  23229. var vertices = [
  23230. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  23231. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  23232. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  23233. ];
  23234. var indices = [
  23235. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  23236. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  23237. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  23238. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  23239. ];
  23240. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  23241. this.type = 'IcosahedronGeometry';
  23242. this.parameters = {
  23243. radius: radius,
  23244. detail: detail
  23245. };
  23246. };
  23247. THREE.IcosahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  23248. THREE.IcosahedronGeometry.prototype.constructor = THREE.IcosahedronGeometry;
  23249. // File:src/extras/geometries/OctahedronGeometry.js
  23250. /**
  23251. * @author timothypratley / https://github.com/timothypratley
  23252. */
  23253. THREE.OctahedronGeometry = function ( radius, detail ) {
  23254. var vertices = [
  23255. 1, 0, 0, - 1, 0, 0, 0, 1, 0, 0, - 1, 0, 0, 0, 1, 0, 0, - 1
  23256. ];
  23257. var indices = [
  23258. 0, 2, 4, 0, 4, 3, 0, 3, 5, 0, 5, 2, 1, 2, 5, 1, 5, 3, 1, 3, 4, 1, 4, 2
  23259. ];
  23260. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  23261. this.type = 'OctahedronGeometry';
  23262. this.parameters = {
  23263. radius: radius,
  23264. detail: detail
  23265. };
  23266. };
  23267. THREE.OctahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  23268. THREE.OctahedronGeometry.prototype.constructor = THREE.OctahedronGeometry;
  23269. // File:src/extras/geometries/TetrahedronGeometry.js
  23270. /**
  23271. * @author timothypratley / https://github.com/timothypratley
  23272. */
  23273. THREE.TetrahedronGeometry = function ( radius, detail ) {
  23274. var vertices = [
  23275. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  23276. ];
  23277. var indices = [
  23278. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  23279. ];
  23280. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  23281. this.type = 'TetrahedronGeometry';
  23282. this.parameters = {
  23283. radius: radius,
  23284. detail: detail
  23285. };
  23286. };
  23287. THREE.TetrahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  23288. THREE.TetrahedronGeometry.prototype.constructor = THREE.TetrahedronGeometry;
  23289. // File:src/extras/geometries/ParametricGeometry.js
  23290. /**
  23291. * @author zz85 / https://github.com/zz85
  23292. * Parametric Surfaces Geometry
  23293. * based on the brilliant article by @prideout http://prideout.net/blog/?p=44
  23294. *
  23295. * new THREE.ParametricGeometry( parametricFunction, uSegments, ySegements );
  23296. *
  23297. */
  23298. THREE.ParametricGeometry = function ( func, slices, stacks ) {
  23299. THREE.Geometry.call( this );
  23300. this.type = 'ParametricGeometry';
  23301. this.parameters = {
  23302. func: func,
  23303. slices: slices,
  23304. stacks: stacks
  23305. };
  23306. var verts = this.vertices;
  23307. var faces = this.faces;
  23308. var uvs = this.faceVertexUvs[ 0 ];
  23309. var i, j, p;
  23310. var u, v;
  23311. var sliceCount = slices + 1;
  23312. for ( i = 0; i <= stacks; i ++ ) {
  23313. v = i / stacks;
  23314. for ( j = 0; j <= slices; j ++ ) {
  23315. u = j / slices;
  23316. p = func( u, v );
  23317. verts.push( p );
  23318. }
  23319. }
  23320. var a, b, c, d;
  23321. var uva, uvb, uvc, uvd;
  23322. for ( i = 0; i < stacks; i ++ ) {
  23323. for ( j = 0; j < slices; j ++ ) {
  23324. a = i * sliceCount + j;
  23325. b = i * sliceCount + j + 1;
  23326. c = ( i + 1 ) * sliceCount + j + 1;
  23327. d = ( i + 1 ) * sliceCount + j;
  23328. uva = new THREE.Vector2( j / slices, i / stacks );
  23329. uvb = new THREE.Vector2( ( j + 1 ) / slices, i / stacks );
  23330. uvc = new THREE.Vector2( ( j + 1 ) / slices, ( i + 1 ) / stacks );
  23331. uvd = new THREE.Vector2( j / slices, ( i + 1 ) / stacks );
  23332. faces.push( new THREE.Face3( a, b, d ) );
  23333. uvs.push( [ uva, uvb, uvd ] );
  23334. faces.push( new THREE.Face3( b, c, d ) );
  23335. uvs.push( [ uvb.clone(), uvc, uvd.clone() ] );
  23336. }
  23337. }
  23338. // console.log(this);
  23339. // magic bullet
  23340. // var diff = this.mergeVertices();
  23341. // console.log('removed ', diff, ' vertices by merging');
  23342. this.computeFaceNormals();
  23343. this.computeVertexNormals();
  23344. };
  23345. THREE.ParametricGeometry.prototype = Object.create( THREE.Geometry.prototype );
  23346. THREE.ParametricGeometry.prototype.constructor = THREE.ParametricGeometry;
  23347. // File:src/extras/geometries/WireframeGeometry.js
  23348. /**
  23349. * @author mrdoob / http://mrdoob.com/
  23350. */
  23351. THREE.WireframeGeometry = function ( geometry ) {
  23352. THREE.BufferGeometry.call( this );
  23353. var edge = [ 0, 0 ], hash = {};
  23354. function sortFunction( a, b ) {
  23355. return a - b;
  23356. }
  23357. var keys = [ 'a', 'b', 'c' ];
  23358. if ( geometry instanceof THREE.Geometry ) {
  23359. var vertices = geometry.vertices;
  23360. var faces = geometry.faces;
  23361. var numEdges = 0;
  23362. // allocate maximal size
  23363. var edges = new Uint32Array( 6 * faces.length );
  23364. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  23365. var face = faces[ i ];
  23366. for ( var j = 0; j < 3; j ++ ) {
  23367. edge[ 0 ] = face[ keys[ j ] ];
  23368. edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
  23369. edge.sort( sortFunction );
  23370. var key = edge.toString();
  23371. if ( hash[ key ] === undefined ) {
  23372. edges[ 2 * numEdges ] = edge[ 0 ];
  23373. edges[ 2 * numEdges + 1 ] = edge[ 1 ];
  23374. hash[ key ] = true;
  23375. numEdges ++;
  23376. }
  23377. }
  23378. }
  23379. var coords = new Float32Array( numEdges * 2 * 3 );
  23380. for ( var i = 0, l = numEdges; i < l; i ++ ) {
  23381. for ( var j = 0; j < 2; j ++ ) {
  23382. var vertex = vertices[ edges [ 2 * i + j ] ];
  23383. var index = 6 * i + 3 * j;
  23384. coords[ index + 0 ] = vertex.x;
  23385. coords[ index + 1 ] = vertex.y;
  23386. coords[ index + 2 ] = vertex.z;
  23387. }
  23388. }
  23389. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  23390. } else if ( geometry instanceof THREE.BufferGeometry ) {
  23391. if ( geometry.index !== null ) {
  23392. // Indexed BufferGeometry
  23393. var indices = geometry.index.array;
  23394. var vertices = geometry.attributes.position;
  23395. var groups = geometry.groups;
  23396. var numEdges = 0;
  23397. if ( groups.length === 0 ) {
  23398. geometry.addGroup( 0, indices.length );
  23399. }
  23400. // allocate maximal size
  23401. var edges = new Uint32Array( 2 * indices.length );
  23402. for ( var o = 0, ol = groups.length; o < ol; ++ o ) {
  23403. var group = groups[ o ];
  23404. var start = group.start;
  23405. var count = group.count;
  23406. for ( var i = start, il = start + count; i < il; i += 3 ) {
  23407. for ( var j = 0; j < 3; j ++ ) {
  23408. edge[ 0 ] = indices[ i + j ];
  23409. edge[ 1 ] = indices[ i + ( j + 1 ) % 3 ];
  23410. edge.sort( sortFunction );
  23411. var key = edge.toString();
  23412. if ( hash[ key ] === undefined ) {
  23413. edges[ 2 * numEdges ] = edge[ 0 ];
  23414. edges[ 2 * numEdges + 1 ] = edge[ 1 ];
  23415. hash[ key ] = true;
  23416. numEdges ++;
  23417. }
  23418. }
  23419. }
  23420. }
  23421. var coords = new Float32Array( numEdges * 2 * 3 );
  23422. for ( var i = 0, l = numEdges; i < l; i ++ ) {
  23423. for ( var j = 0; j < 2; j ++ ) {
  23424. var index = 6 * i + 3 * j;
  23425. var index2 = edges[ 2 * i + j ];
  23426. coords[ index + 0 ] = vertices.getX( index2 );
  23427. coords[ index + 1 ] = vertices.getY( index2 );
  23428. coords[ index + 2 ] = vertices.getZ( index2 );
  23429. }
  23430. }
  23431. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  23432. } else {
  23433. // non-indexed BufferGeometry
  23434. var vertices = geometry.attributes.position.array;
  23435. var numEdges = vertices.length / 3;
  23436. var numTris = numEdges / 3;
  23437. var coords = new Float32Array( numEdges * 2 * 3 );
  23438. for ( var i = 0, l = numTris; i < l; i ++ ) {
  23439. for ( var j = 0; j < 3; j ++ ) {
  23440. var index = 18 * i + 6 * j;
  23441. var index1 = 9 * i + 3 * j;
  23442. coords[ index + 0 ] = vertices[ index1 ];
  23443. coords[ index + 1 ] = vertices[ index1 + 1 ];
  23444. coords[ index + 2 ] = vertices[ index1 + 2 ];
  23445. var index2 = 9 * i + 3 * ( ( j + 1 ) % 3 );
  23446. coords[ index + 3 ] = vertices[ index2 ];
  23447. coords[ index + 4 ] = vertices[ index2 + 1 ];
  23448. coords[ index + 5 ] = vertices[ index2 + 2 ];
  23449. }
  23450. }
  23451. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  23452. }
  23453. }
  23454. };
  23455. THREE.WireframeGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  23456. THREE.WireframeGeometry.prototype.constructor = THREE.WireframeGeometry;
  23457. // File:src/extras/helpers/AxisHelper.js
  23458. /**
  23459. * @author sroucheray / http://sroucheray.org/
  23460. * @author mrdoob / http://mrdoob.com/
  23461. */
  23462. THREE.AxisHelper = function ( size ) {
  23463. size = size || 1;
  23464. var vertices = new Float32Array( [
  23465. 0, 0, 0, size, 0, 0,
  23466. 0, 0, 0, 0, size, 0,
  23467. 0, 0, 0, 0, 0, size
  23468. ] );
  23469. var colors = new Float32Array( [
  23470. 1, 0, 0, 1, 0.6, 0,
  23471. 0, 1, 0, 0.6, 1, 0,
  23472. 0, 0, 1, 0, 0.6, 1
  23473. ] );
  23474. var geometry = new THREE.BufferGeometry();
  23475. geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  23476. geometry.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ) );
  23477. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
  23478. THREE.LineSegments.call( this, geometry, material );
  23479. };
  23480. THREE.AxisHelper.prototype = Object.create( THREE.LineSegments.prototype );
  23481. THREE.AxisHelper.prototype.constructor = THREE.AxisHelper;
  23482. // File:src/extras/helpers/ArrowHelper.js
  23483. /**
  23484. * @author WestLangley / http://github.com/WestLangley
  23485. * @author zz85 / http://github.com/zz85
  23486. * @author bhouston / http://clara.io
  23487. *
  23488. * Creates an arrow for visualizing directions
  23489. *
  23490. * Parameters:
  23491. * dir - Vector3
  23492. * origin - Vector3
  23493. * length - Number
  23494. * color - color in hex value
  23495. * headLength - Number
  23496. * headWidth - Number
  23497. */
  23498. THREE.ArrowHelper = ( function () {
  23499. var lineGeometry = new THREE.Geometry();
  23500. lineGeometry.vertices.push( new THREE.Vector3( 0, 0, 0 ), new THREE.Vector3( 0, 1, 0 ) );
  23501. var coneGeometry = new THREE.CylinderGeometry( 0, 0.5, 1, 5, 1 );
  23502. coneGeometry.translate( 0, - 0.5, 0 );
  23503. return function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
  23504. // dir is assumed to be normalized
  23505. THREE.Object3D.call( this );
  23506. if ( color === undefined ) color = 0xffff00;
  23507. if ( length === undefined ) length = 1;
  23508. if ( headLength === undefined ) headLength = 0.2 * length;
  23509. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  23510. this.position.copy( origin );
  23511. this.line = new THREE.Line( lineGeometry, new THREE.LineBasicMaterial( { color: color } ) );
  23512. this.line.matrixAutoUpdate = false;
  23513. this.add( this.line );
  23514. this.cone = new THREE.Mesh( coneGeometry, new THREE.MeshBasicMaterial( { color: color } ) );
  23515. this.cone.matrixAutoUpdate = false;
  23516. this.add( this.cone );
  23517. this.setDirection( dir );
  23518. this.setLength( length, headLength, headWidth );
  23519. }
  23520. }() );
  23521. THREE.ArrowHelper.prototype = Object.create( THREE.Object3D.prototype );
  23522. THREE.ArrowHelper.prototype.constructor = THREE.ArrowHelper;
  23523. THREE.ArrowHelper.prototype.setDirection = ( function () {
  23524. var axis = new THREE.Vector3();
  23525. var radians;
  23526. return function setDirection( dir ) {
  23527. // dir is assumed to be normalized
  23528. if ( dir.y > 0.99999 ) {
  23529. this.quaternion.set( 0, 0, 0, 1 );
  23530. } else if ( dir.y < - 0.99999 ) {
  23531. this.quaternion.set( 1, 0, 0, 0 );
  23532. } else {
  23533. axis.set( dir.z, 0, - dir.x ).normalize();
  23534. radians = Math.acos( dir.y );
  23535. this.quaternion.setFromAxisAngle( axis, radians );
  23536. }
  23537. };
  23538. }() );
  23539. THREE.ArrowHelper.prototype.setLength = function ( length, headLength, headWidth ) {
  23540. if ( headLength === undefined ) headLength = 0.2 * length;
  23541. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  23542. this.line.scale.set( 1, Math.max( 0, length - headLength ), 1 );
  23543. this.line.updateMatrix();
  23544. this.cone.scale.set( headWidth, headLength, headWidth );
  23545. this.cone.position.y = length;
  23546. this.cone.updateMatrix();
  23547. };
  23548. THREE.ArrowHelper.prototype.setColor = function ( color ) {
  23549. this.line.material.color.set( color );
  23550. this.cone.material.color.set( color );
  23551. };
  23552. // File:src/extras/helpers/BoxHelper.js
  23553. /**
  23554. * @author mrdoob / http://mrdoob.com/
  23555. */
  23556. THREE.BoxHelper = function ( object ) {
  23557. 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 ] );
  23558. var positions = new Float32Array( 8 * 3 );
  23559. var geometry = new THREE.BufferGeometry();
  23560. geometry.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  23561. geometry.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
  23562. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: 0xffff00 } ) );
  23563. if ( object !== undefined ) {
  23564. this.update( object );
  23565. }
  23566. };
  23567. THREE.BoxHelper.prototype = Object.create( THREE.LineSegments.prototype );
  23568. THREE.BoxHelper.prototype.constructor = THREE.BoxHelper;
  23569. THREE.BoxHelper.prototype.update = ( function () {
  23570. var box = new THREE.Box3();
  23571. return function ( object ) {
  23572. box.setFromObject( object );
  23573. if ( box.isEmpty() ) return;
  23574. var min = box.min;
  23575. var max = box.max;
  23576. /*
  23577. 5____4
  23578. 1/___0/|
  23579. | 6__|_7
  23580. 2/___3/
  23581. 0: max.x, max.y, max.z
  23582. 1: min.x, max.y, max.z
  23583. 2: min.x, min.y, max.z
  23584. 3: max.x, min.y, max.z
  23585. 4: max.x, max.y, min.z
  23586. 5: min.x, max.y, min.z
  23587. 6: min.x, min.y, min.z
  23588. 7: max.x, min.y, min.z
  23589. */
  23590. var position = this.geometry.attributes.position;
  23591. var array = position.array;
  23592. array[ 0 ] = max.x; array[ 1 ] = max.y; array[ 2 ] = max.z;
  23593. array[ 3 ] = min.x; array[ 4 ] = max.y; array[ 5 ] = max.z;
  23594. array[ 6 ] = min.x; array[ 7 ] = min.y; array[ 8 ] = max.z;
  23595. array[ 9 ] = max.x; array[ 10 ] = min.y; array[ 11 ] = max.z;
  23596. array[ 12 ] = max.x; array[ 13 ] = max.y; array[ 14 ] = min.z;
  23597. array[ 15 ] = min.x; array[ 16 ] = max.y; array[ 17 ] = min.z;
  23598. array[ 18 ] = min.x; array[ 19 ] = min.y; array[ 20 ] = min.z;
  23599. array[ 21 ] = max.x; array[ 22 ] = min.y; array[ 23 ] = min.z;
  23600. position.needsUpdate = true;
  23601. this.geometry.computeBoundingSphere();
  23602. };
  23603. } )();
  23604. // File:src/extras/helpers/BoundingBoxHelper.js
  23605. /**
  23606. * @author WestLangley / http://github.com/WestLangley
  23607. */
  23608. // a helper to show the world-axis-aligned bounding box for an object
  23609. THREE.BoundingBoxHelper = function ( object, hex ) {
  23610. var color = ( hex !== undefined ) ? hex : 0x888888;
  23611. this.object = object;
  23612. this.box = new THREE.Box3();
  23613. THREE.Mesh.call( this, new THREE.BoxGeometry( 1, 1, 1 ), new THREE.MeshBasicMaterial( { color: color, wireframe: true } ) );
  23614. };
  23615. THREE.BoundingBoxHelper.prototype = Object.create( THREE.Mesh.prototype );
  23616. THREE.BoundingBoxHelper.prototype.constructor = THREE.BoundingBoxHelper;
  23617. THREE.BoundingBoxHelper.prototype.update = function () {
  23618. this.box.setFromObject( this.object );
  23619. this.box.size( this.scale );
  23620. this.box.center( this.position );
  23621. };
  23622. // File:src/extras/helpers/CameraHelper.js
  23623. /**
  23624. * @author alteredq / http://alteredqualia.com/
  23625. *
  23626. * - shows frustum, line of sight and up of the camera
  23627. * - suitable for fast updates
  23628. * - based on frustum visualization in lightgl.js shadowmap example
  23629. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  23630. */
  23631. THREE.CameraHelper = function ( camera ) {
  23632. var geometry = new THREE.Geometry();
  23633. var material = new THREE.LineBasicMaterial( { color: 0xffffff, vertexColors: THREE.FaceColors } );
  23634. var pointMap = {};
  23635. // colors
  23636. var hexFrustum = 0xffaa00;
  23637. var hexCone = 0xff0000;
  23638. var hexUp = 0x00aaff;
  23639. var hexTarget = 0xffffff;
  23640. var hexCross = 0x333333;
  23641. // near
  23642. addLine( "n1", "n2", hexFrustum );
  23643. addLine( "n2", "n4", hexFrustum );
  23644. addLine( "n4", "n3", hexFrustum );
  23645. addLine( "n3", "n1", hexFrustum );
  23646. // far
  23647. addLine( "f1", "f2", hexFrustum );
  23648. addLine( "f2", "f4", hexFrustum );
  23649. addLine( "f4", "f3", hexFrustum );
  23650. addLine( "f3", "f1", hexFrustum );
  23651. // sides
  23652. addLine( "n1", "f1", hexFrustum );
  23653. addLine( "n2", "f2", hexFrustum );
  23654. addLine( "n3", "f3", hexFrustum );
  23655. addLine( "n4", "f4", hexFrustum );
  23656. // cone
  23657. addLine( "p", "n1", hexCone );
  23658. addLine( "p", "n2", hexCone );
  23659. addLine( "p", "n3", hexCone );
  23660. addLine( "p", "n4", hexCone );
  23661. // up
  23662. addLine( "u1", "u2", hexUp );
  23663. addLine( "u2", "u3", hexUp );
  23664. addLine( "u3", "u1", hexUp );
  23665. // target
  23666. addLine( "c", "t", hexTarget );
  23667. addLine( "p", "c", hexCross );
  23668. // cross
  23669. addLine( "cn1", "cn2", hexCross );
  23670. addLine( "cn3", "cn4", hexCross );
  23671. addLine( "cf1", "cf2", hexCross );
  23672. addLine( "cf3", "cf4", hexCross );
  23673. function addLine( a, b, hex ) {
  23674. addPoint( a, hex );
  23675. addPoint( b, hex );
  23676. }
  23677. function addPoint( id, hex ) {
  23678. geometry.vertices.push( new THREE.Vector3() );
  23679. geometry.colors.push( new THREE.Color( hex ) );
  23680. if ( pointMap[ id ] === undefined ) {
  23681. pointMap[ id ] = [];
  23682. }
  23683. pointMap[ id ].push( geometry.vertices.length - 1 );
  23684. }
  23685. THREE.LineSegments.call( this, geometry, material );
  23686. this.camera = camera;
  23687. this.camera.updateProjectionMatrix();
  23688. this.matrix = camera.matrixWorld;
  23689. this.matrixAutoUpdate = false;
  23690. this.pointMap = pointMap;
  23691. this.update();
  23692. };
  23693. THREE.CameraHelper.prototype = Object.create( THREE.LineSegments.prototype );
  23694. THREE.CameraHelper.prototype.constructor = THREE.CameraHelper;
  23695. THREE.CameraHelper.prototype.update = function () {
  23696. var geometry, pointMap;
  23697. var vector = new THREE.Vector3();
  23698. var camera = new THREE.Camera();
  23699. function setPoint( point, x, y, z ) {
  23700. vector.set( x, y, z ).unproject( camera );
  23701. var points = pointMap[ point ];
  23702. if ( points !== undefined ) {
  23703. for ( var i = 0, il = points.length; i < il; i ++ ) {
  23704. geometry.vertices[ points[ i ] ].copy( vector );
  23705. }
  23706. }
  23707. }
  23708. return function () {
  23709. geometry = this.geometry;
  23710. pointMap = this.pointMap;
  23711. var w = 1, h = 1;
  23712. // we need just camera projection matrix
  23713. // world matrix must be identity
  23714. camera.projectionMatrix.copy( this.camera.projectionMatrix );
  23715. // center / target
  23716. setPoint( "c", 0, 0, - 1 );
  23717. setPoint( "t", 0, 0, 1 );
  23718. // near
  23719. setPoint( "n1", - w, - h, - 1 );
  23720. setPoint( "n2", w, - h, - 1 );
  23721. setPoint( "n3", - w, h, - 1 );
  23722. setPoint( "n4", w, h, - 1 );
  23723. // far
  23724. setPoint( "f1", - w, - h, 1 );
  23725. setPoint( "f2", w, - h, 1 );
  23726. setPoint( "f3", - w, h, 1 );
  23727. setPoint( "f4", w, h, 1 );
  23728. // up
  23729. setPoint( "u1", w * 0.7, h * 1.1, - 1 );
  23730. setPoint( "u2", - w * 0.7, h * 1.1, - 1 );
  23731. setPoint( "u3", 0, h * 2, - 1 );
  23732. // cross
  23733. setPoint( "cf1", - w, 0, 1 );
  23734. setPoint( "cf2", w, 0, 1 );
  23735. setPoint( "cf3", 0, - h, 1 );
  23736. setPoint( "cf4", 0, h, 1 );
  23737. setPoint( "cn1", - w, 0, - 1 );
  23738. setPoint( "cn2", w, 0, - 1 );
  23739. setPoint( "cn3", 0, - h, - 1 );
  23740. setPoint( "cn4", 0, h, - 1 );
  23741. geometry.verticesNeedUpdate = true;
  23742. };
  23743. }();
  23744. // File:src/extras/helpers/DirectionalLightHelper.js
  23745. /**
  23746. * @author alteredq / http://alteredqualia.com/
  23747. * @author mrdoob / http://mrdoob.com/
  23748. * @author WestLangley / http://github.com/WestLangley
  23749. */
  23750. THREE.DirectionalLightHelper = function ( light, size ) {
  23751. THREE.Object3D.call( this );
  23752. this.light = light;
  23753. this.light.updateMatrixWorld();
  23754. this.matrix = light.matrixWorld;
  23755. this.matrixAutoUpdate = false;
  23756. size = size || 1;
  23757. var geometry = new THREE.Geometry();
  23758. geometry.vertices.push(
  23759. new THREE.Vector3( - size, size, 0 ),
  23760. new THREE.Vector3( size, size, 0 ),
  23761. new THREE.Vector3( size, - size, 0 ),
  23762. new THREE.Vector3( - size, - size, 0 ),
  23763. new THREE.Vector3( - size, size, 0 )
  23764. );
  23765. var material = new THREE.LineBasicMaterial( { fog: false } );
  23766. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  23767. this.lightPlane = new THREE.Line( geometry, material );
  23768. this.add( this.lightPlane );
  23769. geometry = new THREE.Geometry();
  23770. geometry.vertices.push(
  23771. new THREE.Vector3(),
  23772. new THREE.Vector3()
  23773. );
  23774. material = new THREE.LineBasicMaterial( { fog: false } );
  23775. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  23776. this.targetLine = new THREE.Line( geometry, material );
  23777. this.add( this.targetLine );
  23778. this.update();
  23779. };
  23780. THREE.DirectionalLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  23781. THREE.DirectionalLightHelper.prototype.constructor = THREE.DirectionalLightHelper;
  23782. THREE.DirectionalLightHelper.prototype.dispose = function () {
  23783. this.lightPlane.geometry.dispose();
  23784. this.lightPlane.material.dispose();
  23785. this.targetLine.geometry.dispose();
  23786. this.targetLine.material.dispose();
  23787. };
  23788. THREE.DirectionalLightHelper.prototype.update = function () {
  23789. var v1 = new THREE.Vector3();
  23790. var v2 = new THREE.Vector3();
  23791. var v3 = new THREE.Vector3();
  23792. return function () {
  23793. v1.setFromMatrixPosition( this.light.matrixWorld );
  23794. v2.setFromMatrixPosition( this.light.target.matrixWorld );
  23795. v3.subVectors( v2, v1 );
  23796. this.lightPlane.lookAt( v3 );
  23797. this.lightPlane.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  23798. this.targetLine.geometry.vertices[ 1 ].copy( v3 );
  23799. this.targetLine.geometry.verticesNeedUpdate = true;
  23800. this.targetLine.material.color.copy( this.lightPlane.material.color );
  23801. };
  23802. }();
  23803. // File:src/extras/helpers/EdgesHelper.js
  23804. /**
  23805. * @author WestLangley / http://github.com/WestLangley
  23806. * @param object THREE.Mesh whose geometry will be used
  23807. * @param hex line color
  23808. * @param thresholdAngle the minimum angle (in degrees),
  23809. * between the face normals of adjacent faces,
  23810. * that is required to render an edge. A value of 10 means
  23811. * an edge is only rendered if the angle is at least 10 degrees.
  23812. */
  23813. THREE.EdgesHelper = function ( object, hex, thresholdAngle ) {
  23814. var color = ( hex !== undefined ) ? hex : 0xffffff;
  23815. THREE.LineSegments.call( this, new THREE.EdgesGeometry( object.geometry, thresholdAngle ), new THREE.LineBasicMaterial( { color: color } ) );
  23816. this.matrix = object.matrixWorld;
  23817. this.matrixAutoUpdate = false;
  23818. };
  23819. THREE.EdgesHelper.prototype = Object.create( THREE.LineSegments.prototype );
  23820. THREE.EdgesHelper.prototype.constructor = THREE.EdgesHelper;
  23821. // File:src/extras/helpers/FaceNormalsHelper.js
  23822. /**
  23823. * @author mrdoob / http://mrdoob.com/
  23824. * @author WestLangley / http://github.com/WestLangley
  23825. */
  23826. THREE.FaceNormalsHelper = function ( object, size, hex, linewidth ) {
  23827. // FaceNormalsHelper only supports THREE.Geometry
  23828. this.object = object;
  23829. this.size = ( size !== undefined ) ? size : 1;
  23830. var color = ( hex !== undefined ) ? hex : 0xffff00;
  23831. var width = ( linewidth !== undefined ) ? linewidth : 1;
  23832. //
  23833. var nNormals = 0;
  23834. var objGeometry = this.object.geometry;
  23835. if ( objGeometry instanceof THREE.Geometry ) {
  23836. nNormals = objGeometry.faces.length;
  23837. } else {
  23838. console.warn( 'THREE.FaceNormalsHelper: only THREE.Geometry is supported. Use THREE.VertexNormalsHelper, instead.' );
  23839. }
  23840. //
  23841. var geometry = new THREE.BufferGeometry();
  23842. var positions = new THREE.Float32Attribute( nNormals * 2 * 3, 3 );
  23843. geometry.addAttribute( 'position', positions );
  23844. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  23845. //
  23846. this.matrixAutoUpdate = false;
  23847. this.update();
  23848. };
  23849. THREE.FaceNormalsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  23850. THREE.FaceNormalsHelper.prototype.constructor = THREE.FaceNormalsHelper;
  23851. THREE.FaceNormalsHelper.prototype.update = ( function () {
  23852. var v1 = new THREE.Vector3();
  23853. var v2 = new THREE.Vector3();
  23854. var normalMatrix = new THREE.Matrix3();
  23855. return function update() {
  23856. this.object.updateMatrixWorld( true );
  23857. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  23858. var matrixWorld = this.object.matrixWorld;
  23859. var position = this.geometry.attributes.position;
  23860. //
  23861. var objGeometry = this.object.geometry;
  23862. var vertices = objGeometry.vertices;
  23863. var faces = objGeometry.faces;
  23864. var idx = 0;
  23865. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  23866. var face = faces[ i ];
  23867. var normal = face.normal;
  23868. v1.copy( vertices[ face.a ] )
  23869. .add( vertices[ face.b ] )
  23870. .add( vertices[ face.c ] )
  23871. .divideScalar( 3 )
  23872. .applyMatrix4( matrixWorld );
  23873. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  23874. position.setXYZ( idx, v1.x, v1.y, v1.z );
  23875. idx = idx + 1;
  23876. position.setXYZ( idx, v2.x, v2.y, v2.z );
  23877. idx = idx + 1;
  23878. }
  23879. position.needsUpdate = true;
  23880. return this;
  23881. }
  23882. }() );
  23883. // File:src/extras/helpers/GridHelper.js
  23884. /**
  23885. * @author mrdoob / http://mrdoob.com/
  23886. */
  23887. THREE.GridHelper = function ( size, step ) {
  23888. var geometry = new THREE.Geometry();
  23889. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
  23890. this.color1 = new THREE.Color( 0x444444 );
  23891. this.color2 = new THREE.Color( 0x888888 );
  23892. for ( var i = - size; i <= size; i += step ) {
  23893. geometry.vertices.push(
  23894. new THREE.Vector3( - size, 0, i ), new THREE.Vector3( size, 0, i ),
  23895. new THREE.Vector3( i, 0, - size ), new THREE.Vector3( i, 0, size )
  23896. );
  23897. var color = i === 0 ? this.color1 : this.color2;
  23898. geometry.colors.push( color, color, color, color );
  23899. }
  23900. THREE.LineSegments.call( this, geometry, material );
  23901. };
  23902. THREE.GridHelper.prototype = Object.create( THREE.LineSegments.prototype );
  23903. THREE.GridHelper.prototype.constructor = THREE.GridHelper;
  23904. THREE.GridHelper.prototype.setColors = function( colorCenterLine, colorGrid ) {
  23905. this.color1.set( colorCenterLine );
  23906. this.color2.set( colorGrid );
  23907. this.geometry.colorsNeedUpdate = true;
  23908. };
  23909. // File:src/extras/helpers/HemisphereLightHelper.js
  23910. /**
  23911. * @author alteredq / http://alteredqualia.com/
  23912. * @author mrdoob / http://mrdoob.com/
  23913. */
  23914. THREE.HemisphereLightHelper = function ( light, sphereSize ) {
  23915. THREE.Object3D.call( this );
  23916. this.light = light;
  23917. this.light.updateMatrixWorld();
  23918. this.matrix = light.matrixWorld;
  23919. this.matrixAutoUpdate = false;
  23920. this.colors = [ new THREE.Color(), new THREE.Color() ];
  23921. var geometry = new THREE.SphereGeometry( sphereSize, 4, 2 );
  23922. geometry.rotateX( - Math.PI / 2 );
  23923. for ( var i = 0, il = 8; i < il; i ++ ) {
  23924. geometry.faces[ i ].color = this.colors[ i < 4 ? 0 : 1 ];
  23925. }
  23926. var material = new THREE.MeshBasicMaterial( { vertexColors: THREE.FaceColors, wireframe: true } );
  23927. this.lightSphere = new THREE.Mesh( geometry, material );
  23928. this.add( this.lightSphere );
  23929. this.update();
  23930. };
  23931. THREE.HemisphereLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  23932. THREE.HemisphereLightHelper.prototype.constructor = THREE.HemisphereLightHelper;
  23933. THREE.HemisphereLightHelper.prototype.dispose = function () {
  23934. this.lightSphere.geometry.dispose();
  23935. this.lightSphere.material.dispose();
  23936. };
  23937. THREE.HemisphereLightHelper.prototype.update = function () {
  23938. var vector = new THREE.Vector3();
  23939. return function () {
  23940. this.colors[ 0 ].copy( this.light.color ).multiplyScalar( this.light.intensity );
  23941. this.colors[ 1 ].copy( this.light.groundColor ).multiplyScalar( this.light.intensity );
  23942. this.lightSphere.lookAt( vector.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  23943. this.lightSphere.geometry.colorsNeedUpdate = true;
  23944. }
  23945. }();
  23946. // File:src/extras/helpers/PointLightHelper.js
  23947. /**
  23948. * @author alteredq / http://alteredqualia.com/
  23949. * @author mrdoob / http://mrdoob.com/
  23950. */
  23951. THREE.PointLightHelper = function ( light, sphereSize ) {
  23952. this.light = light;
  23953. this.light.updateMatrixWorld();
  23954. var geometry = new THREE.SphereGeometry( sphereSize, 4, 2 );
  23955. var material = new THREE.MeshBasicMaterial( { wireframe: true, fog: false } );
  23956. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  23957. THREE.Mesh.call( this, geometry, material );
  23958. this.matrix = this.light.matrixWorld;
  23959. this.matrixAutoUpdate = false;
  23960. /*
  23961. var distanceGeometry = new THREE.IcosahedronGeometry( 1, 2 );
  23962. var distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  23963. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  23964. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  23965. var d = light.distance;
  23966. if ( d === 0.0 ) {
  23967. this.lightDistance.visible = false;
  23968. } else {
  23969. this.lightDistance.scale.set( d, d, d );
  23970. }
  23971. this.add( this.lightDistance );
  23972. */
  23973. };
  23974. THREE.PointLightHelper.prototype = Object.create( THREE.Mesh.prototype );
  23975. THREE.PointLightHelper.prototype.constructor = THREE.PointLightHelper;
  23976. THREE.PointLightHelper.prototype.dispose = function () {
  23977. this.geometry.dispose();
  23978. this.material.dispose();
  23979. };
  23980. THREE.PointLightHelper.prototype.update = function () {
  23981. this.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  23982. /*
  23983. var d = this.light.distance;
  23984. if ( d === 0.0 ) {
  23985. this.lightDistance.visible = false;
  23986. } else {
  23987. this.lightDistance.visible = true;
  23988. this.lightDistance.scale.set( d, d, d );
  23989. }
  23990. */
  23991. };
  23992. // File:src/extras/helpers/SkeletonHelper.js
  23993. /**
  23994. * @author Sean Griffin / http://twitter.com/sgrif
  23995. * @author Michael Guerrero / http://realitymeltdown.com
  23996. * @author mrdoob / http://mrdoob.com/
  23997. * @author ikerr / http://verold.com
  23998. */
  23999. THREE.SkeletonHelper = function ( object ) {
  24000. this.bones = this.getBoneList( object );
  24001. var geometry = new THREE.Geometry();
  24002. for ( var i = 0; i < this.bones.length; i ++ ) {
  24003. var bone = this.bones[ i ];
  24004. if ( bone.parent instanceof THREE.Bone ) {
  24005. geometry.vertices.push( new THREE.Vector3() );
  24006. geometry.vertices.push( new THREE.Vector3() );
  24007. geometry.colors.push( new THREE.Color( 0, 0, 1 ) );
  24008. geometry.colors.push( new THREE.Color( 0, 1, 0 ) );
  24009. }
  24010. }
  24011. geometry.dynamic = true;
  24012. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors, depthTest: false, depthWrite: false, transparent: true } );
  24013. THREE.LineSegments.call( this, geometry, material );
  24014. this.root = object;
  24015. this.matrix = object.matrixWorld;
  24016. this.matrixAutoUpdate = false;
  24017. this.update();
  24018. };
  24019. THREE.SkeletonHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24020. THREE.SkeletonHelper.prototype.constructor = THREE.SkeletonHelper;
  24021. THREE.SkeletonHelper.prototype.getBoneList = function( object ) {
  24022. var boneList = [];
  24023. if ( object instanceof THREE.Bone ) {
  24024. boneList.push( object );
  24025. }
  24026. for ( var i = 0; i < object.children.length; i ++ ) {
  24027. boneList.push.apply( boneList, this.getBoneList( object.children[ i ] ) );
  24028. }
  24029. return boneList;
  24030. };
  24031. THREE.SkeletonHelper.prototype.update = function () {
  24032. var geometry = this.geometry;
  24033. var matrixWorldInv = new THREE.Matrix4().getInverse( this.root.matrixWorld );
  24034. var boneMatrix = new THREE.Matrix4();
  24035. var j = 0;
  24036. for ( var i = 0; i < this.bones.length; i ++ ) {
  24037. var bone = this.bones[ i ];
  24038. if ( bone.parent instanceof THREE.Bone ) {
  24039. boneMatrix.multiplyMatrices( matrixWorldInv, bone.matrixWorld );
  24040. geometry.vertices[ j ].setFromMatrixPosition( boneMatrix );
  24041. boneMatrix.multiplyMatrices( matrixWorldInv, bone.parent.matrixWorld );
  24042. geometry.vertices[ j + 1 ].setFromMatrixPosition( boneMatrix );
  24043. j += 2;
  24044. }
  24045. }
  24046. geometry.verticesNeedUpdate = true;
  24047. geometry.computeBoundingSphere();
  24048. };
  24049. // File:src/extras/helpers/SpotLightHelper.js
  24050. /**
  24051. * @author alteredq / http://alteredqualia.com/
  24052. * @author mrdoob / http://mrdoob.com/
  24053. * @author WestLangley / http://github.com/WestLangley
  24054. */
  24055. THREE.SpotLightHelper = function ( light ) {
  24056. THREE.Object3D.call( this );
  24057. this.light = light;
  24058. this.light.updateMatrixWorld();
  24059. this.matrix = light.matrixWorld;
  24060. this.matrixAutoUpdate = false;
  24061. var geometry = new THREE.CylinderGeometry( 0, 1, 1, 8, 1, true );
  24062. geometry.translate( 0, - 0.5, 0 );
  24063. geometry.rotateX( - Math.PI / 2 );
  24064. var material = new THREE.MeshBasicMaterial( { wireframe: true, fog: false } );
  24065. this.cone = new THREE.Mesh( geometry, material );
  24066. this.add( this.cone );
  24067. this.update();
  24068. };
  24069. THREE.SpotLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  24070. THREE.SpotLightHelper.prototype.constructor = THREE.SpotLightHelper;
  24071. THREE.SpotLightHelper.prototype.dispose = function () {
  24072. this.cone.geometry.dispose();
  24073. this.cone.material.dispose();
  24074. };
  24075. THREE.SpotLightHelper.prototype.update = function () {
  24076. var vector = new THREE.Vector3();
  24077. var vector2 = new THREE.Vector3();
  24078. return function () {
  24079. var coneLength = this.light.distance ? this.light.distance : 10000;
  24080. var coneWidth = coneLength * Math.tan( this.light.angle );
  24081. this.cone.scale.set( coneWidth, coneWidth, coneLength );
  24082. vector.setFromMatrixPosition( this.light.matrixWorld );
  24083. vector2.setFromMatrixPosition( this.light.target.matrixWorld );
  24084. this.cone.lookAt( vector2.sub( vector ) );
  24085. this.cone.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  24086. };
  24087. }();
  24088. // File:src/extras/helpers/VertexNormalsHelper.js
  24089. /**
  24090. * @author mrdoob / http://mrdoob.com/
  24091. * @author WestLangley / http://github.com/WestLangley
  24092. */
  24093. THREE.VertexNormalsHelper = function ( object, size, hex, linewidth ) {
  24094. this.object = object;
  24095. this.size = ( size !== undefined ) ? size : 1;
  24096. var color = ( hex !== undefined ) ? hex : 0xff0000;
  24097. var width = ( linewidth !== undefined ) ? linewidth : 1;
  24098. //
  24099. var nNormals = 0;
  24100. var objGeometry = this.object.geometry;
  24101. if ( objGeometry instanceof THREE.Geometry ) {
  24102. nNormals = objGeometry.faces.length * 3;
  24103. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  24104. nNormals = objGeometry.attributes.normal.count
  24105. }
  24106. //
  24107. var geometry = new THREE.BufferGeometry();
  24108. var positions = new THREE.Float32Attribute( nNormals * 2 * 3, 3 );
  24109. geometry.addAttribute( 'position', positions );
  24110. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  24111. //
  24112. this.matrixAutoUpdate = false;
  24113. this.update();
  24114. };
  24115. THREE.VertexNormalsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24116. THREE.VertexNormalsHelper.prototype.constructor = THREE.VertexNormalsHelper;
  24117. THREE.VertexNormalsHelper.prototype.update = ( function () {
  24118. var v1 = new THREE.Vector3();
  24119. var v2 = new THREE.Vector3();
  24120. var normalMatrix = new THREE.Matrix3();
  24121. return function update() {
  24122. var keys = [ 'a', 'b', 'c' ];
  24123. this.object.updateMatrixWorld( true );
  24124. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  24125. var matrixWorld = this.object.matrixWorld;
  24126. var position = this.geometry.attributes.position;
  24127. //
  24128. var objGeometry = this.object.geometry;
  24129. if ( objGeometry instanceof THREE.Geometry ) {
  24130. var vertices = objGeometry.vertices;
  24131. var faces = objGeometry.faces;
  24132. var idx = 0;
  24133. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  24134. var face = faces[ i ];
  24135. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  24136. var vertex = vertices[ face[ keys[ j ] ] ];
  24137. var normal = face.vertexNormals[ j ];
  24138. v1.copy( vertex ).applyMatrix4( matrixWorld );
  24139. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  24140. position.setXYZ( idx, v1.x, v1.y, v1.z );
  24141. idx = idx + 1;
  24142. position.setXYZ( idx, v2.x, v2.y, v2.z );
  24143. idx = idx + 1;
  24144. }
  24145. }
  24146. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  24147. var objPos = objGeometry.attributes.position;
  24148. var objNorm = objGeometry.attributes.normal;
  24149. var idx = 0;
  24150. // for simplicity, ignore index and drawcalls, and render every normal
  24151. for ( var j = 0, jl = objPos.count; j < jl; j ++ ) {
  24152. v1.set( objPos.getX( j ), objPos.getY( j ), objPos.getZ( j ) ).applyMatrix4( matrixWorld );
  24153. v2.set( objNorm.getX( j ), objNorm.getY( j ), objNorm.getZ( j ) );
  24154. v2.applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  24155. position.setXYZ( idx, v1.x, v1.y, v1.z );
  24156. idx = idx + 1;
  24157. position.setXYZ( idx, v2.x, v2.y, v2.z );
  24158. idx = idx + 1;
  24159. }
  24160. }
  24161. position.needsUpdate = true;
  24162. return this;
  24163. }
  24164. }() );
  24165. // File:src/extras/helpers/WireframeHelper.js
  24166. /**
  24167. * @author mrdoob / http://mrdoob.com/
  24168. */
  24169. THREE.WireframeHelper = function ( object, hex ) {
  24170. var color = ( hex !== undefined ) ? hex : 0xffffff;
  24171. THREE.LineSegments.call( this, new THREE.WireframeGeometry( object.geometry ), new THREE.LineBasicMaterial( { color: color } ) );
  24172. this.matrix = object.matrixWorld;
  24173. this.matrixAutoUpdate = false;
  24174. };
  24175. THREE.WireframeHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24176. THREE.WireframeHelper.prototype.constructor = THREE.WireframeHelper;
  24177. // File:src/extras/objects/ImmediateRenderObject.js
  24178. /**
  24179. * @author alteredq / http://alteredqualia.com/
  24180. */
  24181. THREE.ImmediateRenderObject = function ( material ) {
  24182. THREE.Object3D.call( this );
  24183. this.material = material;
  24184. this.render = function ( renderCallback ) {};
  24185. };
  24186. THREE.ImmediateRenderObject.prototype = Object.create( THREE.Object3D.prototype );
  24187. THREE.ImmediateRenderObject.prototype.constructor = THREE.ImmediateRenderObject;
  24188. // File:src/extras/objects/MorphBlendMesh.js
  24189. /**
  24190. * @author alteredq / http://alteredqualia.com/
  24191. */
  24192. THREE.MorphBlendMesh = function( geometry, material ) {
  24193. THREE.Mesh.call( this, geometry, material );
  24194. this.animationsMap = {};
  24195. this.animationsList = [];
  24196. // prepare default animation
  24197. // (all frames played together in 1 second)
  24198. var numFrames = this.geometry.morphTargets.length;
  24199. var name = "__default";
  24200. var startFrame = 0;
  24201. var endFrame = numFrames - 1;
  24202. var fps = numFrames / 1;
  24203. this.createAnimation( name, startFrame, endFrame, fps );
  24204. this.setAnimationWeight( name, 1 );
  24205. };
  24206. THREE.MorphBlendMesh.prototype = Object.create( THREE.Mesh.prototype );
  24207. THREE.MorphBlendMesh.prototype.constructor = THREE.MorphBlendMesh;
  24208. THREE.MorphBlendMesh.prototype.createAnimation = function ( name, start, end, fps ) {
  24209. var animation = {
  24210. start: start,
  24211. end: end,
  24212. length: end - start + 1,
  24213. fps: fps,
  24214. duration: ( end - start ) / fps,
  24215. lastFrame: 0,
  24216. currentFrame: 0,
  24217. active: false,
  24218. time: 0,
  24219. direction: 1,
  24220. weight: 1,
  24221. directionBackwards: false,
  24222. mirroredLoop: false
  24223. };
  24224. this.animationsMap[ name ] = animation;
  24225. this.animationsList.push( animation );
  24226. };
  24227. THREE.MorphBlendMesh.prototype.autoCreateAnimations = function ( fps ) {
  24228. var pattern = /([a-z]+)_?(\d+)/i;
  24229. var firstAnimation, frameRanges = {};
  24230. var geometry = this.geometry;
  24231. for ( var i = 0, il = geometry.morphTargets.length; i < il; i ++ ) {
  24232. var morph = geometry.morphTargets[ i ];
  24233. var chunks = morph.name.match( pattern );
  24234. if ( chunks && chunks.length > 1 ) {
  24235. var name = chunks[ 1 ];
  24236. if ( ! frameRanges[ name ] ) frameRanges[ name ] = { start: Infinity, end: - Infinity };
  24237. var range = frameRanges[ name ];
  24238. if ( i < range.start ) range.start = i;
  24239. if ( i > range.end ) range.end = i;
  24240. if ( ! firstAnimation ) firstAnimation = name;
  24241. }
  24242. }
  24243. for ( var name in frameRanges ) {
  24244. var range = frameRanges[ name ];
  24245. this.createAnimation( name, range.start, range.end, fps );
  24246. }
  24247. this.firstAnimation = firstAnimation;
  24248. };
  24249. THREE.MorphBlendMesh.prototype.setAnimationDirectionForward = function ( name ) {
  24250. var animation = this.animationsMap[ name ];
  24251. if ( animation ) {
  24252. animation.direction = 1;
  24253. animation.directionBackwards = false;
  24254. }
  24255. };
  24256. THREE.MorphBlendMesh.prototype.setAnimationDirectionBackward = function ( name ) {
  24257. var animation = this.animationsMap[ name ];
  24258. if ( animation ) {
  24259. animation.direction = - 1;
  24260. animation.directionBackwards = true;
  24261. }
  24262. };
  24263. THREE.MorphBlendMesh.prototype.setAnimationFPS = function ( name, fps ) {
  24264. var animation = this.animationsMap[ name ];
  24265. if ( animation ) {
  24266. animation.fps = fps;
  24267. animation.duration = ( animation.end - animation.start ) / animation.fps;
  24268. }
  24269. };
  24270. THREE.MorphBlendMesh.prototype.setAnimationDuration = function ( name, duration ) {
  24271. var animation = this.animationsMap[ name ];
  24272. if ( animation ) {
  24273. animation.duration = duration;
  24274. animation.fps = ( animation.end - animation.start ) / animation.duration;
  24275. }
  24276. };
  24277. THREE.MorphBlendMesh.prototype.setAnimationWeight = function ( name, weight ) {
  24278. var animation = this.animationsMap[ name ];
  24279. if ( animation ) {
  24280. animation.weight = weight;
  24281. }
  24282. };
  24283. THREE.MorphBlendMesh.prototype.setAnimationTime = function ( name, time ) {
  24284. var animation = this.animationsMap[ name ];
  24285. if ( animation ) {
  24286. animation.time = time;
  24287. }
  24288. };
  24289. THREE.MorphBlendMesh.prototype.getAnimationTime = function ( name ) {
  24290. var time = 0;
  24291. var animation = this.animationsMap[ name ];
  24292. if ( animation ) {
  24293. time = animation.time;
  24294. }
  24295. return time;
  24296. };
  24297. THREE.MorphBlendMesh.prototype.getAnimationDuration = function ( name ) {
  24298. var duration = - 1;
  24299. var animation = this.animationsMap[ name ];
  24300. if ( animation ) {
  24301. duration = animation.duration;
  24302. }
  24303. return duration;
  24304. };
  24305. THREE.MorphBlendMesh.prototype.playAnimation = function ( name ) {
  24306. var animation = this.animationsMap[ name ];
  24307. if ( animation ) {
  24308. animation.time = 0;
  24309. animation.active = true;
  24310. } else {
  24311. console.warn( "THREE.MorphBlendMesh: animation[" + name + "] undefined in .playAnimation()" );
  24312. }
  24313. };
  24314. THREE.MorphBlendMesh.prototype.stopAnimation = function ( name ) {
  24315. var animation = this.animationsMap[ name ];
  24316. if ( animation ) {
  24317. animation.active = false;
  24318. }
  24319. };
  24320. THREE.MorphBlendMesh.prototype.update = function ( delta ) {
  24321. for ( var i = 0, il = this.animationsList.length; i < il; i ++ ) {
  24322. var animation = this.animationsList[ i ];
  24323. if ( ! animation.active ) continue;
  24324. var frameTime = animation.duration / animation.length;
  24325. animation.time += animation.direction * delta;
  24326. if ( animation.mirroredLoop ) {
  24327. if ( animation.time > animation.duration || animation.time < 0 ) {
  24328. animation.direction *= - 1;
  24329. if ( animation.time > animation.duration ) {
  24330. animation.time = animation.duration;
  24331. animation.directionBackwards = true;
  24332. }
  24333. if ( animation.time < 0 ) {
  24334. animation.time = 0;
  24335. animation.directionBackwards = false;
  24336. }
  24337. }
  24338. } else {
  24339. animation.time = animation.time % animation.duration;
  24340. if ( animation.time < 0 ) animation.time += animation.duration;
  24341. }
  24342. var keyframe = animation.start + THREE.Math.clamp( Math.floor( animation.time / frameTime ), 0, animation.length - 1 );
  24343. var weight = animation.weight;
  24344. if ( keyframe !== animation.currentFrame ) {
  24345. this.morphTargetInfluences[ animation.lastFrame ] = 0;
  24346. this.morphTargetInfluences[ animation.currentFrame ] = 1 * weight;
  24347. this.morphTargetInfluences[ keyframe ] = 0;
  24348. animation.lastFrame = animation.currentFrame;
  24349. animation.currentFrame = keyframe;
  24350. }
  24351. var mix = ( animation.time % frameTime ) / frameTime;
  24352. if ( animation.directionBackwards ) mix = 1 - mix;
  24353. if ( animation.currentFrame !== animation.lastFrame ) {
  24354. this.morphTargetInfluences[ animation.currentFrame ] = mix * weight;
  24355. this.morphTargetInfluences[ animation.lastFrame ] = ( 1 - mix ) * weight;
  24356. } else {
  24357. this.morphTargetInfluences[ animation.currentFrame ] = weight;
  24358. }
  24359. }
  24360. };
粤ICP备19079148号