three.js 865 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368
  1. // File:src/Three.js
  2. /**
  3. * @author mrdoob / http://mrdoob.com/
  4. */
  5. var THREE = { REVISION: '74dev' };
  6. //
  7. if ( typeof define === 'function' && define.amd ) {
  8. define( 'three', THREE );
  9. } else if ( 'undefined' !== typeof exports && 'undefined' !== typeof module ) {
  10. module.exports = THREE;
  11. }
  12. // polyfills
  13. if ( self.requestAnimationFrame === undefined || self.cancelAnimationFrame === undefined ) {
  14. // Missing in Android stock browser.
  15. ( function () {
  16. var lastTime = 0;
  17. var vendors = [ 'ms', 'moz', 'webkit', 'o' ];
  18. for ( var x = 0; x < vendors.length && ! self.requestAnimationFrame; ++ x ) {
  19. self.requestAnimationFrame = self[ vendors[ x ] + 'RequestAnimationFrame' ];
  20. self.cancelAnimationFrame = self[ vendors[ x ] + 'CancelAnimationFrame' ] || self[ vendors[ x ] + 'CancelRequestAnimationFrame' ];
  21. }
  22. if ( self.requestAnimationFrame === undefined && self.setTimeout !== undefined ) {
  23. self.requestAnimationFrame = function ( callback ) {
  24. var currTime = Date.now(), timeToCall = Math.max( 0, 16 - ( currTime - lastTime ) );
  25. var id = self.setTimeout( function () {
  26. callback( currTime + timeToCall );
  27. }, timeToCall );
  28. lastTime = currTime + timeToCall;
  29. return id;
  30. };
  31. }
  32. if ( self.cancelAnimationFrame === undefined && self.clearTimeout !== undefined ) {
  33. self.cancelAnimationFrame = function ( id ) {
  34. self.clearTimeout( id );
  35. };
  36. }
  37. } )();
  38. }
  39. //
  40. if ( self.performance === undefined ) {
  41. self.performance = {};
  42. }
  43. if ( self.performance.now === undefined ) {
  44. ( function () {
  45. var start = Date.now();
  46. self.performance.now = function () {
  47. return Date.now() - start;
  48. }
  49. } )();
  50. }
  51. //
  52. if ( Number.EPSILON === undefined ) {
  53. Number.EPSILON = Math.pow( 2, -52 );
  54. }
  55. //
  56. if ( Math.sign === undefined ) {
  57. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
  58. Math.sign = function ( x ) {
  59. return ( x < 0 ) ? - 1 : ( x > 0 ) ? 1 : + x;
  60. };
  61. }
  62. if ( Function.prototype.name === undefined && Object.defineProperty !== undefined ) {
  63. // Missing in IE9-11.
  64. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
  65. Object.defineProperty( Function.prototype, 'name', {
  66. get: function () {
  67. return this.toString().match( /^\s*function\s*(\S*)\s*\(/ )[ 1 ];
  68. }
  69. } );
  70. }
  71. if ( Object.assign === undefined ) {
  72. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
  73. Object.defineProperty( Object, 'assign', {
  74. writable: true,
  75. configurable: true,
  76. value: function(target) {
  77. 'use strict';
  78. if ( target === undefined || target === null ) {
  79. throw new TypeError( "Cannot convert first argument to object" );
  80. }
  81. var to = Object( target );
  82. for ( var i = 1, n = arguments.length; i !== n; ++ i ) {
  83. var nextSource = arguments[ i ];
  84. if ( nextSource === undefined || nextSource === null ) continue;
  85. nextSource = Object( nextSource );
  86. var keysArray = Object.keys( nextSource );
  87. for ( var nextIndex = 0, len = keysArray.length; nextIndex !== len; ++ nextIndex ) {
  88. var nextKey = keysArray[ nextIndex ];
  89. var desc = Object.getOwnPropertyDescriptor( nextSource, nextKey );
  90. if ( desc !== undefined && desc.enumerable ) {
  91. to[ nextKey ] = nextSource[ nextKey ];
  92. }
  93. }
  94. }
  95. return to;
  96. }
  97. } );
  98. }
  99. // https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent.button
  100. THREE.MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2 };
  101. // GL STATE CONSTANTS
  102. THREE.CullFaceNone = 0;
  103. THREE.CullFaceBack = 1;
  104. THREE.CullFaceFront = 2;
  105. THREE.CullFaceFrontBack = 3;
  106. THREE.FrontFaceDirectionCW = 0;
  107. THREE.FrontFaceDirectionCCW = 1;
  108. // SHADOWING TYPES
  109. THREE.BasicShadowMap = 0;
  110. THREE.PCFShadowMap = 1;
  111. THREE.PCFSoftShadowMap = 2;
  112. // MATERIAL CONSTANTS
  113. // side
  114. THREE.FrontSide = 0;
  115. THREE.BackSide = 1;
  116. THREE.DoubleSide = 2;
  117. // shading
  118. THREE.FlatShading = 1;
  119. THREE.SmoothShading = 2;
  120. // colors
  121. THREE.NoColors = 0;
  122. THREE.FaceColors = 1;
  123. THREE.VertexColors = 2;
  124. // blending modes
  125. THREE.NoBlending = 0;
  126. THREE.NormalBlending = 1;
  127. THREE.AdditiveBlending = 2;
  128. THREE.SubtractiveBlending = 3;
  129. THREE.MultiplyBlending = 4;
  130. THREE.CustomBlending = 5;
  131. // custom blending equations
  132. // (numbers start from 100 not to clash with other
  133. // mappings to OpenGL constants defined in Texture.js)
  134. THREE.AddEquation = 100;
  135. THREE.SubtractEquation = 101;
  136. THREE.ReverseSubtractEquation = 102;
  137. THREE.MinEquation = 103;
  138. THREE.MaxEquation = 104;
  139. // custom blending destination factors
  140. THREE.ZeroFactor = 200;
  141. THREE.OneFactor = 201;
  142. THREE.SrcColorFactor = 202;
  143. THREE.OneMinusSrcColorFactor = 203;
  144. THREE.SrcAlphaFactor = 204;
  145. THREE.OneMinusSrcAlphaFactor = 205;
  146. THREE.DstAlphaFactor = 206;
  147. THREE.OneMinusDstAlphaFactor = 207;
  148. // custom blending source factors
  149. //THREE.ZeroFactor = 200;
  150. //THREE.OneFactor = 201;
  151. //THREE.SrcAlphaFactor = 204;
  152. //THREE.OneMinusSrcAlphaFactor = 205;
  153. //THREE.DstAlphaFactor = 206;
  154. //THREE.OneMinusDstAlphaFactor = 207;
  155. THREE.DstColorFactor = 208;
  156. THREE.OneMinusDstColorFactor = 209;
  157. THREE.SrcAlphaSaturateFactor = 210;
  158. // depth modes
  159. THREE.NeverDepth = 0;
  160. THREE.AlwaysDepth = 1;
  161. THREE.LessDepth = 2;
  162. THREE.LessEqualDepth = 3;
  163. THREE.EqualDepth = 4;
  164. THREE.GreaterEqualDepth = 5;
  165. THREE.GreaterDepth = 6;
  166. THREE.NotEqualDepth = 7;
  167. // TEXTURE CONSTANTS
  168. THREE.MultiplyOperation = 0;
  169. THREE.MixOperation = 1;
  170. THREE.AddOperation = 2;
  171. // Mapping modes
  172. THREE.UVMapping = 300;
  173. THREE.CubeReflectionMapping = 301;
  174. THREE.CubeRefractionMapping = 302;
  175. THREE.EquirectangularReflectionMapping = 303;
  176. THREE.EquirectangularRefractionMapping = 304;
  177. THREE.SphericalReflectionMapping = 305;
  178. // Wrapping modes
  179. THREE.RepeatWrapping = 1000;
  180. THREE.ClampToEdgeWrapping = 1001;
  181. THREE.MirroredRepeatWrapping = 1002;
  182. // Filters
  183. THREE.NearestFilter = 1003;
  184. THREE.NearestMipMapNearestFilter = 1004;
  185. THREE.NearestMipMapLinearFilter = 1005;
  186. THREE.LinearFilter = 1006;
  187. THREE.LinearMipMapNearestFilter = 1007;
  188. THREE.LinearMipMapLinearFilter = 1008;
  189. // Data types
  190. THREE.UnsignedByteType = 1009;
  191. THREE.ByteType = 1010;
  192. THREE.ShortType = 1011;
  193. THREE.UnsignedShortType = 1012;
  194. THREE.IntType = 1013;
  195. THREE.UnsignedIntType = 1014;
  196. THREE.FloatType = 1015;
  197. THREE.HalfFloatType = 1025;
  198. // Pixel types
  199. //THREE.UnsignedByteType = 1009;
  200. THREE.UnsignedShort4444Type = 1016;
  201. THREE.UnsignedShort5551Type = 1017;
  202. THREE.UnsignedShort565Type = 1018;
  203. // Pixel formats
  204. THREE.AlphaFormat = 1019;
  205. THREE.RGBFormat = 1020;
  206. THREE.RGBAFormat = 1021;
  207. THREE.LuminanceFormat = 1022;
  208. THREE.LuminanceAlphaFormat = 1023;
  209. // THREE.RGBEFormat handled as THREE.RGBAFormat in shaders
  210. THREE.RGBEFormat = THREE.RGBAFormat; //1024;
  211. // DDS / ST3C Compressed texture formats
  212. THREE.RGB_S3TC_DXT1_Format = 2001;
  213. THREE.RGBA_S3TC_DXT1_Format = 2002;
  214. THREE.RGBA_S3TC_DXT3_Format = 2003;
  215. THREE.RGBA_S3TC_DXT5_Format = 2004;
  216. // PVRTC compressed texture formats
  217. THREE.RGB_PVRTC_4BPPV1_Format = 2100;
  218. THREE.RGB_PVRTC_2BPPV1_Format = 2101;
  219. THREE.RGBA_PVRTC_4BPPV1_Format = 2102;
  220. THREE.RGBA_PVRTC_2BPPV1_Format = 2103;
  221. // Loop styles for AnimationAction
  222. THREE.LoopOnce = 2200;
  223. THREE.LoopRepeat = 2201;
  224. THREE.LoopPingPong = 2202;
  225. // Interpolation
  226. THREE.InterpolateDiscrete = 2300;
  227. THREE.InterpolateLinear = 2301;
  228. THREE.InterpolateSmooth = 2302;
  229. // Interpolant ending modes
  230. THREE.ZeroCurvatureEnding = 2400;
  231. THREE.ZeroSlopeEnding = 2401;
  232. THREE.WrapAroundEnding = 2402;
  233. // Triangle Draw modes
  234. THREE.TrianglesDrawMode = 0;
  235. THREE.TriangleStripDrawMode = 1;
  236. THREE.TriangleFanDrawMode = 2;
  237. // File:src/math/Color.js
  238. /**
  239. * @author mrdoob / http://mrdoob.com/
  240. */
  241. THREE.Color = function ( color ) {
  242. if ( arguments.length === 3 ) {
  243. return this.fromArray( arguments );
  244. }
  245. return this.set( color );
  246. };
  247. THREE.Color.prototype = {
  248. constructor: THREE.Color,
  249. r: 1, g: 1, b: 1,
  250. set: function ( value ) {
  251. if ( value instanceof THREE.Color ) {
  252. this.copy( value );
  253. } else if ( typeof value === 'number' ) {
  254. this.setHex( value );
  255. } else if ( typeof value === 'string' ) {
  256. this.setStyle( value );
  257. }
  258. return this;
  259. },
  260. setHex: function ( hex ) {
  261. hex = Math.floor( hex );
  262. this.r = ( hex >> 16 & 255 ) / 255;
  263. this.g = ( hex >> 8 & 255 ) / 255;
  264. this.b = ( hex & 255 ) / 255;
  265. return this;
  266. },
  267. setRGB: function ( r, g, b ) {
  268. this.r = r;
  269. this.g = g;
  270. this.b = b;
  271. return this;
  272. },
  273. setHSL: function () {
  274. function hue2rgb( p, q, t ) {
  275. if ( t < 0 ) t += 1;
  276. if ( t > 1 ) t -= 1;
  277. if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
  278. if ( t < 1 / 2 ) return q;
  279. if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
  280. return p;
  281. }
  282. return function ( h, s, l ) {
  283. // h,s,l ranges are in 0.0 - 1.0
  284. h = THREE.Math.euclideanModulo( h, 1 );
  285. s = THREE.Math.clamp( s, 0, 1 );
  286. l = THREE.Math.clamp( l, 0, 1 );
  287. if ( s === 0 ) {
  288. this.r = this.g = this.b = l;
  289. } else {
  290. var p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  291. var q = ( 2 * l ) - p;
  292. this.r = hue2rgb( q, p, h + 1 / 3 );
  293. this.g = hue2rgb( q, p, h );
  294. this.b = hue2rgb( q, p, h - 1 / 3 );
  295. }
  296. return this;
  297. };
  298. }(),
  299. setStyle: function ( style ) {
  300. function handleAlpha( string ) {
  301. if ( string === undefined ) return;
  302. if ( parseFloat( string ) < 1 ) {
  303. console.warn( 'THREE.Color: Alpha component of ' + style + ' will be ignored.' );
  304. }
  305. }
  306. var m;
  307. if ( m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec( style ) ) {
  308. // rgb / hsl
  309. var color;
  310. var name = m[ 1 ];
  311. var components = m[ 2 ];
  312. switch ( name ) {
  313. case 'rgb':
  314. case 'rgba':
  315. if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  316. // rgb(255,0,0) rgba(255,0,0,0.5)
  317. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  318. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  319. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  320. handleAlpha( color[ 5 ] );
  321. return this;
  322. }
  323. if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  324. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  325. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  326. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  327. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  328. handleAlpha( color[ 5 ] );
  329. return this;
  330. }
  331. break;
  332. case 'hsl':
  333. case 'hsla':
  334. if ( color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  335. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  336. var h = parseFloat( color[ 1 ] ) / 360;
  337. var s = parseInt( color[ 2 ], 10 ) / 100;
  338. var l = parseInt( color[ 3 ], 10 ) / 100;
  339. handleAlpha( color[ 5 ] );
  340. return this.setHSL( h, s, l );
  341. }
  342. break;
  343. }
  344. } else if ( m = /^\#([A-Fa-f0-9]+)$/.exec( style ) ) {
  345. // hex color
  346. var hex = m[ 1 ];
  347. var size = hex.length;
  348. if ( size === 3 ) {
  349. // #ff0
  350. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 0 ), 16 ) / 255;
  351. this.g = parseInt( hex.charAt( 1 ) + hex.charAt( 1 ), 16 ) / 255;
  352. this.b = parseInt( hex.charAt( 2 ) + hex.charAt( 2 ), 16 ) / 255;
  353. return this;
  354. } else if ( size === 6 ) {
  355. // #ff0000
  356. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 1 ), 16 ) / 255;
  357. this.g = parseInt( hex.charAt( 2 ) + hex.charAt( 3 ), 16 ) / 255;
  358. this.b = parseInt( hex.charAt( 4 ) + hex.charAt( 5 ), 16 ) / 255;
  359. return this;
  360. }
  361. }
  362. if ( style && style.length > 0 ) {
  363. // color keywords
  364. var hex = THREE.ColorKeywords[ style ];
  365. if ( hex !== undefined ) {
  366. // red
  367. this.setHex( hex );
  368. } else {
  369. // unknown color
  370. console.warn( 'THREE.Color: Unknown color ' + style );
  371. }
  372. }
  373. return this;
  374. },
  375. clone: function () {
  376. return new this.constructor( this.r, this.g, this.b );
  377. },
  378. copy: function ( color ) {
  379. this.r = color.r;
  380. this.g = color.g;
  381. this.b = color.b;
  382. return this;
  383. },
  384. copyGammaToLinear: function ( color, gammaFactor ) {
  385. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  386. this.r = Math.pow( color.r, gammaFactor );
  387. this.g = Math.pow( color.g, gammaFactor );
  388. this.b = Math.pow( color.b, gammaFactor );
  389. return this;
  390. },
  391. copyLinearToGamma: function ( color, gammaFactor ) {
  392. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  393. var safeInverse = ( gammaFactor > 0 ) ? ( 1.0 / gammaFactor ) : 1.0;
  394. this.r = Math.pow( color.r, safeInverse );
  395. this.g = Math.pow( color.g, safeInverse );
  396. this.b = Math.pow( color.b, safeInverse );
  397. return this;
  398. },
  399. convertGammaToLinear: function () {
  400. var r = this.r, g = this.g, b = this.b;
  401. this.r = r * r;
  402. this.g = g * g;
  403. this.b = b * b;
  404. return this;
  405. },
  406. convertLinearToGamma: function () {
  407. this.r = Math.sqrt( this.r );
  408. this.g = Math.sqrt( this.g );
  409. this.b = Math.sqrt( this.b );
  410. return this;
  411. },
  412. getHex: function () {
  413. return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
  414. },
  415. getHexString: function () {
  416. return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
  417. },
  418. getHSL: function ( optionalTarget ) {
  419. // h,s,l ranges are in 0.0 - 1.0
  420. var hsl = optionalTarget || { h: 0, s: 0, l: 0 };
  421. var r = this.r, g = this.g, b = this.b;
  422. var max = Math.max( r, g, b );
  423. var min = Math.min( r, g, b );
  424. var hue, saturation;
  425. var lightness = ( min + max ) / 2.0;
  426. if ( min === max ) {
  427. hue = 0;
  428. saturation = 0;
  429. } else {
  430. var delta = max - min;
  431. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  432. switch ( max ) {
  433. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  434. case g: hue = ( b - r ) / delta + 2; break;
  435. case b: hue = ( r - g ) / delta + 4; break;
  436. }
  437. hue /= 6;
  438. }
  439. hsl.h = hue;
  440. hsl.s = saturation;
  441. hsl.l = lightness;
  442. return hsl;
  443. },
  444. getStyle: function () {
  445. return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
  446. },
  447. offsetHSL: function ( h, s, l ) {
  448. var hsl = this.getHSL();
  449. hsl.h += h; hsl.s += s; hsl.l += l;
  450. this.setHSL( hsl.h, hsl.s, hsl.l );
  451. return this;
  452. },
  453. add: function ( color ) {
  454. this.r += color.r;
  455. this.g += color.g;
  456. this.b += color.b;
  457. return this;
  458. },
  459. addColors: function ( color1, color2 ) {
  460. this.r = color1.r + color2.r;
  461. this.g = color1.g + color2.g;
  462. this.b = color1.b + color2.b;
  463. return this;
  464. },
  465. addScalar: function ( s ) {
  466. this.r += s;
  467. this.g += s;
  468. this.b += s;
  469. return this;
  470. },
  471. multiply: function ( color ) {
  472. this.r *= color.r;
  473. this.g *= color.g;
  474. this.b *= color.b;
  475. return this;
  476. },
  477. multiplyScalar: function ( s ) {
  478. this.r *= s;
  479. this.g *= s;
  480. this.b *= s;
  481. return this;
  482. },
  483. lerp: function ( color, alpha ) {
  484. this.r += ( color.r - this.r ) * alpha;
  485. this.g += ( color.g - this.g ) * alpha;
  486. this.b += ( color.b - this.b ) * alpha;
  487. return this;
  488. },
  489. equals: function ( c ) {
  490. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  491. },
  492. fromArray: function ( array, offset ) {
  493. if ( offset === undefined ) offset = 0;
  494. this.r = array[ offset ];
  495. this.g = array[ offset + 1 ];
  496. this.b = array[ offset + 2 ];
  497. return this;
  498. },
  499. toArray: function ( array, offset ) {
  500. if ( array === undefined ) array = [];
  501. if ( offset === undefined ) offset = 0;
  502. array[ offset ] = this.r;
  503. array[ offset + 1 ] = this.g;
  504. array[ offset + 2 ] = this.b;
  505. return array;
  506. }
  507. };
  508. THREE.ColorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  509. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  510. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  511. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  512. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  513. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  514. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  515. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  516. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  517. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  518. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  519. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  520. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  521. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  522. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  523. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  524. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  525. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  526. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  527. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  528. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  529. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  530. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  531. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  532. // File:src/math/Quaternion.js
  533. /**
  534. * @author mikael emtinger / http://gomo.se/
  535. * @author alteredq / http://alteredqualia.com/
  536. * @author WestLangley / http://github.com/WestLangley
  537. * @author bhouston / http://clara.io
  538. */
  539. THREE.Quaternion = function ( x, y, z, w ) {
  540. this._x = x || 0;
  541. this._y = y || 0;
  542. this._z = z || 0;
  543. this._w = ( w !== undefined ) ? w : 1;
  544. };
  545. THREE.Quaternion.prototype = {
  546. constructor: THREE.Quaternion,
  547. get x () {
  548. return this._x;
  549. },
  550. set x ( value ) {
  551. this._x = value;
  552. this.onChangeCallback();
  553. },
  554. get y () {
  555. return this._y;
  556. },
  557. set y ( value ) {
  558. this._y = value;
  559. this.onChangeCallback();
  560. },
  561. get z () {
  562. return this._z;
  563. },
  564. set z ( value ) {
  565. this._z = value;
  566. this.onChangeCallback();
  567. },
  568. get w () {
  569. return this._w;
  570. },
  571. set w ( value ) {
  572. this._w = value;
  573. this.onChangeCallback();
  574. },
  575. set: function ( x, y, z, w ) {
  576. this._x = x;
  577. this._y = y;
  578. this._z = z;
  579. this._w = w;
  580. this.onChangeCallback();
  581. return this;
  582. },
  583. clone: function () {
  584. return new this.constructor( this._x, this._y, this._z, this._w );
  585. },
  586. copy: function ( quaternion ) {
  587. this._x = quaternion.x;
  588. this._y = quaternion.y;
  589. this._z = quaternion.z;
  590. this._w = quaternion.w;
  591. this.onChangeCallback();
  592. return this;
  593. },
  594. setFromEuler: function ( euler, update ) {
  595. if ( euler instanceof THREE.Euler === false ) {
  596. throw new Error( 'THREE.Quaternion: .setFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  597. }
  598. // http://www.mathworks.com/matlabcentral/fileexchange/
  599. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  600. // content/SpinCalc.m
  601. var c1 = Math.cos( euler._x / 2 );
  602. var c2 = Math.cos( euler._y / 2 );
  603. var c3 = Math.cos( euler._z / 2 );
  604. var s1 = Math.sin( euler._x / 2 );
  605. var s2 = Math.sin( euler._y / 2 );
  606. var s3 = Math.sin( euler._z / 2 );
  607. var order = euler.order;
  608. if ( order === 'XYZ' ) {
  609. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  610. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  611. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  612. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  613. } else if ( order === 'YXZ' ) {
  614. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  615. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  616. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  617. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  618. } else if ( order === 'ZXY' ) {
  619. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  620. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  621. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  622. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  623. } else if ( order === 'ZYX' ) {
  624. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  625. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  626. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  627. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  628. } else if ( order === 'YZX' ) {
  629. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  630. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  631. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  632. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  633. } else if ( order === 'XZY' ) {
  634. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  635. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  636. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  637. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  638. }
  639. if ( update !== false ) this.onChangeCallback();
  640. return this;
  641. },
  642. setFromAxisAngle: function ( axis, angle ) {
  643. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  644. // assumes axis is normalized
  645. var halfAngle = angle / 2, s = Math.sin( halfAngle );
  646. this._x = axis.x * s;
  647. this._y = axis.y * s;
  648. this._z = axis.z * s;
  649. this._w = Math.cos( halfAngle );
  650. this.onChangeCallback();
  651. return this;
  652. },
  653. setFromRotationMatrix: function ( m ) {
  654. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  655. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  656. var te = m.elements,
  657. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  658. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  659. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ],
  660. trace = m11 + m22 + m33,
  661. s;
  662. if ( trace > 0 ) {
  663. s = 0.5 / Math.sqrt( trace + 1.0 );
  664. this._w = 0.25 / s;
  665. this._x = ( m32 - m23 ) * s;
  666. this._y = ( m13 - m31 ) * s;
  667. this._z = ( m21 - m12 ) * s;
  668. } else if ( m11 > m22 && m11 > m33 ) {
  669. s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );
  670. this._w = ( m32 - m23 ) / s;
  671. this._x = 0.25 * s;
  672. this._y = ( m12 + m21 ) / s;
  673. this._z = ( m13 + m31 ) / s;
  674. } else if ( m22 > m33 ) {
  675. s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );
  676. this._w = ( m13 - m31 ) / s;
  677. this._x = ( m12 + m21 ) / s;
  678. this._y = 0.25 * s;
  679. this._z = ( m23 + m32 ) / s;
  680. } else {
  681. s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );
  682. this._w = ( m21 - m12 ) / s;
  683. this._x = ( m13 + m31 ) / s;
  684. this._y = ( m23 + m32 ) / s;
  685. this._z = 0.25 * s;
  686. }
  687. this.onChangeCallback();
  688. return this;
  689. },
  690. setFromUnitVectors: function () {
  691. // http://lolengine.net/blog/2014/02/24/quaternion-from-two-vectors-final
  692. // assumes direction vectors vFrom and vTo are normalized
  693. var v1, r;
  694. var EPS = 0.000001;
  695. return function ( vFrom, vTo ) {
  696. if ( v1 === undefined ) v1 = new THREE.Vector3();
  697. r = vFrom.dot( vTo ) + 1;
  698. if ( r < EPS ) {
  699. r = 0;
  700. if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) {
  701. v1.set( - vFrom.y, vFrom.x, 0 );
  702. } else {
  703. v1.set( 0, - vFrom.z, vFrom.y );
  704. }
  705. } else {
  706. v1.crossVectors( vFrom, vTo );
  707. }
  708. this._x = v1.x;
  709. this._y = v1.y;
  710. this._z = v1.z;
  711. this._w = r;
  712. this.normalize();
  713. return this;
  714. }
  715. }(),
  716. inverse: function () {
  717. this.conjugate().normalize();
  718. return this;
  719. },
  720. conjugate: function () {
  721. this._x *= - 1;
  722. this._y *= - 1;
  723. this._z *= - 1;
  724. this.onChangeCallback();
  725. return this;
  726. },
  727. dot: function ( v ) {
  728. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  729. },
  730. lengthSq: function () {
  731. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  732. },
  733. length: function () {
  734. return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );
  735. },
  736. normalize: function () {
  737. var l = this.length();
  738. if ( l === 0 ) {
  739. this._x = 0;
  740. this._y = 0;
  741. this._z = 0;
  742. this._w = 1;
  743. } else {
  744. l = 1 / l;
  745. this._x = this._x * l;
  746. this._y = this._y * l;
  747. this._z = this._z * l;
  748. this._w = this._w * l;
  749. }
  750. this.onChangeCallback();
  751. return this;
  752. },
  753. multiply: function ( q, p ) {
  754. if ( p !== undefined ) {
  755. console.warn( 'THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.' );
  756. return this.multiplyQuaternions( q, p );
  757. }
  758. return this.multiplyQuaternions( this, q );
  759. },
  760. multiplyQuaternions: function ( a, b ) {
  761. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  762. var qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
  763. var qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
  764. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  765. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  766. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  767. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  768. this.onChangeCallback();
  769. return this;
  770. },
  771. slerp: function ( qb, t ) {
  772. if ( t === 0 ) return this;
  773. if ( t === 1 ) return this.copy( qb );
  774. var x = this._x, y = this._y, z = this._z, w = this._w;
  775. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  776. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  777. if ( cosHalfTheta < 0 ) {
  778. this._w = - qb._w;
  779. this._x = - qb._x;
  780. this._y = - qb._y;
  781. this._z = - qb._z;
  782. cosHalfTheta = - cosHalfTheta;
  783. } else {
  784. this.copy( qb );
  785. }
  786. if ( cosHalfTheta >= 1.0 ) {
  787. this._w = w;
  788. this._x = x;
  789. this._y = y;
  790. this._z = z;
  791. return this;
  792. }
  793. var sinHalfTheta = Math.sqrt( 1.0 - cosHalfTheta * cosHalfTheta );
  794. if ( Math.abs( sinHalfTheta ) < 0.001 ) {
  795. this._w = 0.5 * ( w + this._w );
  796. this._x = 0.5 * ( x + this._x );
  797. this._y = 0.5 * ( y + this._y );
  798. this._z = 0.5 * ( z + this._z );
  799. return this;
  800. }
  801. var halfTheta = Math.atan2( sinHalfTheta, cosHalfTheta );
  802. var ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  803. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  804. this._w = ( w * ratioA + this._w * ratioB );
  805. this._x = ( x * ratioA + this._x * ratioB );
  806. this._y = ( y * ratioA + this._y * ratioB );
  807. this._z = ( z * ratioA + this._z * ratioB );
  808. this.onChangeCallback();
  809. return this;
  810. },
  811. equals: function ( quaternion ) {
  812. return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
  813. },
  814. fromArray: function ( array, offset ) {
  815. if ( offset === undefined ) offset = 0;
  816. this._x = array[ offset ];
  817. this._y = array[ offset + 1 ];
  818. this._z = array[ offset + 2 ];
  819. this._w = array[ offset + 3 ];
  820. this.onChangeCallback();
  821. return this;
  822. },
  823. toArray: function ( array, offset ) {
  824. if ( array === undefined ) array = [];
  825. if ( offset === undefined ) offset = 0;
  826. array[ offset ] = this._x;
  827. array[ offset + 1 ] = this._y;
  828. array[ offset + 2 ] = this._z;
  829. array[ offset + 3 ] = this._w;
  830. return array;
  831. },
  832. onChange: function ( callback ) {
  833. this.onChangeCallback = callback;
  834. return this;
  835. },
  836. onChangeCallback: function () {}
  837. };
  838. Object.assign( THREE.Quaternion, {
  839. slerp: function( qa, qb, qm, t ) {
  840. return qm.copy( qa ).slerp( qb, t );
  841. },
  842. slerpFlat: function(
  843. dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t ) {
  844. // fuzz-free, array-based Quaternion SLERP operation
  845. var x0 = src0[ srcOffset0 ],
  846. y0 = src0[ srcOffset0 + 1 ],
  847. z0 = src0[ srcOffset0 + 2 ],
  848. w0 = src0[ srcOffset0 + 3 ],
  849. x1 = src1[ srcOffset1 ],
  850. y1 = src1[ srcOffset1 + 1 ],
  851. z1 = src1[ srcOffset1 + 2 ],
  852. w1 = src1[ srcOffset1 + 3 ];
  853. if ( w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1 ) {
  854. var s = 1 - t,
  855. cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  856. dir = ( cos >= 0 ? 1 : -1 ),
  857. sqrSin = 1 - cos * cos;
  858. // Skip the Slerp for tiny steps to avoid numeric problems:
  859. if ( sqrSin > Number.EPSILON ) {
  860. var sin = Math.sqrt( sqrSin ),
  861. len = Math.atan2( sin, cos * dir );
  862. s = Math.sin( s * len ) / sin;
  863. t = Math.sin( t * len ) / sin;
  864. }
  865. var tDir = t * dir;
  866. x0 = x0 * s + x1 * tDir;
  867. y0 = y0 * s + y1 * tDir;
  868. z0 = z0 * s + z1 * tDir;
  869. w0 = w0 * s + w1 * tDir;
  870. // Normalize in case we just did a lerp:
  871. if ( s === 1 - t ) {
  872. var f = 1 / Math.sqrt( x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0 );
  873. x0 *= f;
  874. y0 *= f;
  875. z0 *= f;
  876. w0 *= f;
  877. }
  878. }
  879. dst[ dstOffset ] = x0;
  880. dst[ dstOffset + 1 ] = y0;
  881. dst[ dstOffset + 2 ] = z0;
  882. dst[ dstOffset + 3 ] = w0;
  883. }
  884. } );
  885. // File:src/math/Vector2.js
  886. /**
  887. * @author mrdoob / http://mrdoob.com/
  888. * @author philogb / http://blog.thejit.org/
  889. * @author egraether / http://egraether.com/
  890. * @author zz85 / http://www.lab4games.net/zz85/blog
  891. */
  892. THREE.Vector2 = function ( x, y ) {
  893. this.x = x || 0;
  894. this.y = y || 0;
  895. };
  896. THREE.Vector2.prototype = {
  897. constructor: THREE.Vector2,
  898. get width() { return this.x },
  899. set width( value ) { this.x = value },
  900. get height() { return this.y },
  901. set height( value ) { this.y = value },
  902. //
  903. set: function ( x, y ) {
  904. this.x = x;
  905. this.y = y;
  906. return this;
  907. },
  908. setX: function ( x ) {
  909. this.x = x;
  910. return this;
  911. },
  912. setY: function ( y ) {
  913. this.y = y;
  914. return this;
  915. },
  916. setComponent: function ( index, value ) {
  917. switch ( index ) {
  918. case 0: this.x = value; break;
  919. case 1: this.y = value; break;
  920. default: throw new Error( 'index is out of range: ' + index );
  921. }
  922. },
  923. getComponent: function ( index ) {
  924. switch ( index ) {
  925. case 0: return this.x;
  926. case 1: return this.y;
  927. default: throw new Error( 'index is out of range: ' + index );
  928. }
  929. },
  930. clone: function () {
  931. return new this.constructor( this.x, this.y );
  932. },
  933. copy: function ( v ) {
  934. this.x = v.x;
  935. this.y = v.y;
  936. return this;
  937. },
  938. add: function ( v, w ) {
  939. if ( w !== undefined ) {
  940. console.warn( 'THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  941. return this.addVectors( v, w );
  942. }
  943. this.x += v.x;
  944. this.y += v.y;
  945. return this;
  946. },
  947. addScalar: function ( s ) {
  948. this.x += s;
  949. this.y += s;
  950. return this;
  951. },
  952. addVectors: function ( a, b ) {
  953. this.x = a.x + b.x;
  954. this.y = a.y + b.y;
  955. return this;
  956. },
  957. addScaledVector: function ( v, s ) {
  958. this.x += v.x * s;
  959. this.y += v.y * s;
  960. return this;
  961. },
  962. sub: function ( v, w ) {
  963. if ( w !== undefined ) {
  964. console.warn( 'THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  965. return this.subVectors( v, w );
  966. }
  967. this.x -= v.x;
  968. this.y -= v.y;
  969. return this;
  970. },
  971. subScalar: function ( s ) {
  972. this.x -= s;
  973. this.y -= s;
  974. return this;
  975. },
  976. subVectors: function ( a, b ) {
  977. this.x = a.x - b.x;
  978. this.y = a.y - b.y;
  979. return this;
  980. },
  981. multiply: function ( v ) {
  982. this.x *= v.x;
  983. this.y *= v.y;
  984. return this;
  985. },
  986. multiplyScalar: function ( scalar ) {
  987. if ( isFinite( scalar ) ) {
  988. this.x *= scalar;
  989. this.y *= scalar;
  990. } else {
  991. this.x = 0;
  992. this.y = 0;
  993. }
  994. return this;
  995. },
  996. divide: function ( v ) {
  997. this.x /= v.x;
  998. this.y /= v.y;
  999. return this;
  1000. },
  1001. divideScalar: function ( scalar ) {
  1002. return this.multiplyScalar( 1 / scalar );
  1003. },
  1004. min: function ( v ) {
  1005. this.x = Math.min( this.x, v.x );
  1006. this.y = Math.min( this.y, v.y );
  1007. return this;
  1008. },
  1009. max: function ( v ) {
  1010. this.x = Math.max( this.x, v.x );
  1011. this.y = Math.max( this.y, v.y );
  1012. return this;
  1013. },
  1014. clamp: function ( min, max ) {
  1015. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1016. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1017. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1018. return this;
  1019. },
  1020. clampScalar: function () {
  1021. var min, max;
  1022. return function clampScalar( minVal, maxVal ) {
  1023. if ( min === undefined ) {
  1024. min = new THREE.Vector2();
  1025. max = new THREE.Vector2();
  1026. }
  1027. min.set( minVal, minVal );
  1028. max.set( maxVal, maxVal );
  1029. return this.clamp( min, max );
  1030. };
  1031. }(),
  1032. clampLength: function ( min, max ) {
  1033. var length = this.length();
  1034. this.multiplyScalar( Math.max( min, Math.min( max, length ) ) / length );
  1035. return this;
  1036. },
  1037. floor: function () {
  1038. this.x = Math.floor( this.x );
  1039. this.y = Math.floor( this.y );
  1040. return this;
  1041. },
  1042. ceil: function () {
  1043. this.x = Math.ceil( this.x );
  1044. this.y = Math.ceil( this.y );
  1045. return this;
  1046. },
  1047. round: function () {
  1048. this.x = Math.round( this.x );
  1049. this.y = Math.round( this.y );
  1050. return this;
  1051. },
  1052. roundToZero: function () {
  1053. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1054. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1055. return this;
  1056. },
  1057. negate: function () {
  1058. this.x = - this.x;
  1059. this.y = - this.y;
  1060. return this;
  1061. },
  1062. dot: function ( v ) {
  1063. return this.x * v.x + this.y * v.y;
  1064. },
  1065. lengthSq: function () {
  1066. return this.x * this.x + this.y * this.y;
  1067. },
  1068. length: function () {
  1069. return Math.sqrt( this.x * this.x + this.y * this.y );
  1070. },
  1071. lengthManhattan: function() {
  1072. return Math.abs( this.x ) + Math.abs( this.y );
  1073. },
  1074. normalize: function () {
  1075. return this.divideScalar( this.length() );
  1076. },
  1077. distanceTo: function ( v ) {
  1078. return Math.sqrt( this.distanceToSquared( v ) );
  1079. },
  1080. distanceToSquared: function ( v ) {
  1081. var dx = this.x - v.x, dy = this.y - v.y;
  1082. return dx * dx + dy * dy;
  1083. },
  1084. setLength: function ( length ) {
  1085. return this.multiplyScalar( length / this.length() );
  1086. },
  1087. lerp: function ( v, alpha ) {
  1088. this.x += ( v.x - this.x ) * alpha;
  1089. this.y += ( v.y - this.y ) * alpha;
  1090. return this;
  1091. },
  1092. lerpVectors: function ( v1, v2, alpha ) {
  1093. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1094. return this;
  1095. },
  1096. equals: function ( v ) {
  1097. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  1098. },
  1099. fromArray: function ( array, offset ) {
  1100. if ( offset === undefined ) offset = 0;
  1101. this.x = array[ offset ];
  1102. this.y = array[ offset + 1 ];
  1103. return this;
  1104. },
  1105. toArray: function ( array, offset ) {
  1106. if ( array === undefined ) array = [];
  1107. if ( offset === undefined ) offset = 0;
  1108. array[ offset ] = this.x;
  1109. array[ offset + 1 ] = this.y;
  1110. return array;
  1111. },
  1112. fromAttribute: function ( attribute, index, offset ) {
  1113. if ( offset === undefined ) offset = 0;
  1114. index = index * attribute.itemSize + offset;
  1115. this.x = attribute.array[ index ];
  1116. this.y = attribute.array[ index + 1 ];
  1117. return this;
  1118. },
  1119. rotateAround: function ( center, angle ) {
  1120. var c = Math.cos( angle ), s = Math.sin( angle );
  1121. var x = this.x - center.x;
  1122. var y = this.y - center.y;
  1123. this.x = x * c - y * s + center.x;
  1124. this.y = x * s + y * c + center.y;
  1125. return this;
  1126. }
  1127. };
  1128. // File:src/math/Vector3.js
  1129. /**
  1130. * @author mrdoob / http://mrdoob.com/
  1131. * @author *kile / http://kile.stravaganza.org/
  1132. * @author philogb / http://blog.thejit.org/
  1133. * @author mikael emtinger / http://gomo.se/
  1134. * @author egraether / http://egraether.com/
  1135. * @author WestLangley / http://github.com/WestLangley
  1136. */
  1137. THREE.Vector3 = function ( x, y, z ) {
  1138. this.x = x || 0;
  1139. this.y = y || 0;
  1140. this.z = z || 0;
  1141. };
  1142. THREE.Vector3.prototype = {
  1143. constructor: THREE.Vector3,
  1144. set: function ( x, y, z ) {
  1145. this.x = x;
  1146. this.y = y;
  1147. this.z = z;
  1148. return this;
  1149. },
  1150. setX: function ( x ) {
  1151. this.x = x;
  1152. return this;
  1153. },
  1154. setY: function ( y ) {
  1155. this.y = y;
  1156. return this;
  1157. },
  1158. setZ: function ( z ) {
  1159. this.z = z;
  1160. return this;
  1161. },
  1162. setComponent: function ( index, value ) {
  1163. switch ( index ) {
  1164. case 0: this.x = value; break;
  1165. case 1: this.y = value; break;
  1166. case 2: this.z = value; break;
  1167. default: throw new Error( 'index is out of range: ' + index );
  1168. }
  1169. },
  1170. getComponent: function ( index ) {
  1171. switch ( index ) {
  1172. case 0: return this.x;
  1173. case 1: return this.y;
  1174. case 2: return this.z;
  1175. default: throw new Error( 'index is out of range: ' + index );
  1176. }
  1177. },
  1178. clone: function () {
  1179. return new this.constructor( this.x, this.y, this.z );
  1180. },
  1181. copy: function ( v ) {
  1182. this.x = v.x;
  1183. this.y = v.y;
  1184. this.z = v.z;
  1185. return this;
  1186. },
  1187. add: function ( v, w ) {
  1188. if ( w !== undefined ) {
  1189. console.warn( 'THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1190. return this.addVectors( v, w );
  1191. }
  1192. this.x += v.x;
  1193. this.y += v.y;
  1194. this.z += v.z;
  1195. return this;
  1196. },
  1197. addScalar: function ( s ) {
  1198. this.x += s;
  1199. this.y += s;
  1200. this.z += s;
  1201. return this;
  1202. },
  1203. addVectors: function ( a, b ) {
  1204. this.x = a.x + b.x;
  1205. this.y = a.y + b.y;
  1206. this.z = a.z + b.z;
  1207. return this;
  1208. },
  1209. addScaledVector: function ( v, s ) {
  1210. this.x += v.x * s;
  1211. this.y += v.y * s;
  1212. this.z += v.z * s;
  1213. return this;
  1214. },
  1215. sub: function ( v, w ) {
  1216. if ( w !== undefined ) {
  1217. console.warn( 'THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1218. return this.subVectors( v, w );
  1219. }
  1220. this.x -= v.x;
  1221. this.y -= v.y;
  1222. this.z -= v.z;
  1223. return this;
  1224. },
  1225. subScalar: function ( s ) {
  1226. this.x -= s;
  1227. this.y -= s;
  1228. this.z -= s;
  1229. return this;
  1230. },
  1231. subVectors: function ( a, b ) {
  1232. this.x = a.x - b.x;
  1233. this.y = a.y - b.y;
  1234. this.z = a.z - b.z;
  1235. return this;
  1236. },
  1237. multiply: function ( v, w ) {
  1238. if ( w !== undefined ) {
  1239. console.warn( 'THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.' );
  1240. return this.multiplyVectors( v, w );
  1241. }
  1242. this.x *= v.x;
  1243. this.y *= v.y;
  1244. this.z *= v.z;
  1245. return this;
  1246. },
  1247. multiplyScalar: function ( scalar ) {
  1248. if ( isFinite( scalar ) ) {
  1249. this.x *= scalar;
  1250. this.y *= scalar;
  1251. this.z *= scalar;
  1252. } else {
  1253. this.x = 0;
  1254. this.y = 0;
  1255. this.z = 0;
  1256. }
  1257. return this;
  1258. },
  1259. multiplyVectors: function ( a, b ) {
  1260. this.x = a.x * b.x;
  1261. this.y = a.y * b.y;
  1262. this.z = a.z * b.z;
  1263. return this;
  1264. },
  1265. applyEuler: function () {
  1266. var quaternion;
  1267. return function applyEuler( euler ) {
  1268. if ( euler instanceof THREE.Euler === false ) {
  1269. console.error( 'THREE.Vector3: .applyEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  1270. }
  1271. if ( quaternion === undefined ) quaternion = new THREE.Quaternion();
  1272. this.applyQuaternion( quaternion.setFromEuler( euler ) );
  1273. return this;
  1274. };
  1275. }(),
  1276. applyAxisAngle: function () {
  1277. var quaternion;
  1278. return function applyAxisAngle( axis, angle ) {
  1279. if ( quaternion === undefined ) quaternion = new THREE.Quaternion();
  1280. this.applyQuaternion( quaternion.setFromAxisAngle( axis, angle ) );
  1281. return this;
  1282. };
  1283. }(),
  1284. applyMatrix3: function ( m ) {
  1285. var x = this.x;
  1286. var y = this.y;
  1287. var z = this.z;
  1288. var e = m.elements;
  1289. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
  1290. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
  1291. this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
  1292. return this;
  1293. },
  1294. applyMatrix4: function ( m ) {
  1295. // input: THREE.Matrix4 affine matrix
  1296. var x = this.x, y = this.y, z = this.z;
  1297. var e = m.elements;
  1298. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ];
  1299. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ];
  1300. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ];
  1301. return this;
  1302. },
  1303. applyProjection: function ( m ) {
  1304. // input: THREE.Matrix4 projection matrix
  1305. var x = this.x, y = this.y, z = this.z;
  1306. var e = m.elements;
  1307. var d = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] ); // perspective divide
  1308. this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * d;
  1309. this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * d;
  1310. this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * d;
  1311. return this;
  1312. },
  1313. applyQuaternion: function ( q ) {
  1314. var x = this.x;
  1315. var y = this.y;
  1316. var z = this.z;
  1317. var qx = q.x;
  1318. var qy = q.y;
  1319. var qz = q.z;
  1320. var qw = q.w;
  1321. // calculate quat * vector
  1322. var ix = qw * x + qy * z - qz * y;
  1323. var iy = qw * y + qz * x - qx * z;
  1324. var iz = qw * z + qx * y - qy * x;
  1325. var iw = - qx * x - qy * y - qz * z;
  1326. // calculate result * inverse quat
  1327. this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
  1328. this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
  1329. this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
  1330. return this;
  1331. },
  1332. project: function () {
  1333. var matrix;
  1334. return function project( camera ) {
  1335. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  1336. matrix.multiplyMatrices( camera.projectionMatrix, matrix.getInverse( camera.matrixWorld ) );
  1337. return this.applyProjection( matrix );
  1338. };
  1339. }(),
  1340. unproject: function () {
  1341. var matrix;
  1342. return function unproject( camera ) {
  1343. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  1344. matrix.multiplyMatrices( camera.matrixWorld, matrix.getInverse( camera.projectionMatrix ) );
  1345. return this.applyProjection( matrix );
  1346. };
  1347. }(),
  1348. transformDirection: function ( m ) {
  1349. // input: THREE.Matrix4 affine matrix
  1350. // vector interpreted as a direction
  1351. var x = this.x, y = this.y, z = this.z;
  1352. var e = m.elements;
  1353. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
  1354. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
  1355. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
  1356. this.normalize();
  1357. return this;
  1358. },
  1359. divide: function ( v ) {
  1360. this.x /= v.x;
  1361. this.y /= v.y;
  1362. this.z /= v.z;
  1363. return this;
  1364. },
  1365. divideScalar: function ( scalar ) {
  1366. return this.multiplyScalar( 1 / scalar );
  1367. },
  1368. min: function ( v ) {
  1369. this.x = Math.min( this.x, v.x );
  1370. this.y = Math.min( this.y, v.y );
  1371. this.z = Math.min( this.z, v.z );
  1372. return this;
  1373. },
  1374. max: function ( v ) {
  1375. this.x = Math.max( this.x, v.x );
  1376. this.y = Math.max( this.y, v.y );
  1377. this.z = Math.max( this.z, v.z );
  1378. return this;
  1379. },
  1380. clamp: function ( min, max ) {
  1381. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1382. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1383. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1384. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  1385. return this;
  1386. },
  1387. clampScalar: function () {
  1388. var min, max;
  1389. return function clampScalar( minVal, maxVal ) {
  1390. if ( min === undefined ) {
  1391. min = new THREE.Vector3();
  1392. max = new THREE.Vector3();
  1393. }
  1394. min.set( minVal, minVal, minVal );
  1395. max.set( maxVal, maxVal, maxVal );
  1396. return this.clamp( min, max );
  1397. };
  1398. }(),
  1399. clampLength: function ( min, max ) {
  1400. var length = this.length();
  1401. this.multiplyScalar( Math.max( min, Math.min( max, length ) ) / length );
  1402. return this;
  1403. },
  1404. floor: function () {
  1405. this.x = Math.floor( this.x );
  1406. this.y = Math.floor( this.y );
  1407. this.z = Math.floor( this.z );
  1408. return this;
  1409. },
  1410. ceil: function () {
  1411. this.x = Math.ceil( this.x );
  1412. this.y = Math.ceil( this.y );
  1413. this.z = Math.ceil( this.z );
  1414. return this;
  1415. },
  1416. round: function () {
  1417. this.x = Math.round( this.x );
  1418. this.y = Math.round( this.y );
  1419. this.z = Math.round( this.z );
  1420. return this;
  1421. },
  1422. roundToZero: function () {
  1423. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1424. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1425. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1426. return this;
  1427. },
  1428. negate: function () {
  1429. this.x = - this.x;
  1430. this.y = - this.y;
  1431. this.z = - this.z;
  1432. return this;
  1433. },
  1434. dot: function ( v ) {
  1435. return this.x * v.x + this.y * v.y + this.z * v.z;
  1436. },
  1437. lengthSq: function () {
  1438. return this.x * this.x + this.y * this.y + this.z * this.z;
  1439. },
  1440. length: function () {
  1441. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
  1442. },
  1443. lengthManhattan: function () {
  1444. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  1445. },
  1446. normalize: function () {
  1447. return this.divideScalar( this.length() );
  1448. },
  1449. setLength: function ( length ) {
  1450. return this.multiplyScalar( length / this.length() );
  1451. },
  1452. lerp: function ( v, alpha ) {
  1453. this.x += ( v.x - this.x ) * alpha;
  1454. this.y += ( v.y - this.y ) * alpha;
  1455. this.z += ( v.z - this.z ) * alpha;
  1456. return this;
  1457. },
  1458. lerpVectors: function ( v1, v2, alpha ) {
  1459. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1460. return this;
  1461. },
  1462. cross: function ( v, w ) {
  1463. if ( w !== undefined ) {
  1464. console.warn( 'THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.' );
  1465. return this.crossVectors( v, w );
  1466. }
  1467. var x = this.x, y = this.y, z = this.z;
  1468. this.x = y * v.z - z * v.y;
  1469. this.y = z * v.x - x * v.z;
  1470. this.z = x * v.y - y * v.x;
  1471. return this;
  1472. },
  1473. crossVectors: function ( a, b ) {
  1474. var ax = a.x, ay = a.y, az = a.z;
  1475. var bx = b.x, by = b.y, bz = b.z;
  1476. this.x = ay * bz - az * by;
  1477. this.y = az * bx - ax * bz;
  1478. this.z = ax * by - ay * bx;
  1479. return this;
  1480. },
  1481. projectOnVector: function () {
  1482. var v1, dot;
  1483. return function projectOnVector( vector ) {
  1484. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1485. v1.copy( vector ).normalize();
  1486. dot = this.dot( v1 );
  1487. return this.copy( v1 ).multiplyScalar( dot );
  1488. };
  1489. }(),
  1490. projectOnPlane: function () {
  1491. var v1;
  1492. return function projectOnPlane( planeNormal ) {
  1493. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1494. v1.copy( this ).projectOnVector( planeNormal );
  1495. return this.sub( v1 );
  1496. }
  1497. }(),
  1498. reflect: function () {
  1499. // reflect incident vector off plane orthogonal to normal
  1500. // normal is assumed to have unit length
  1501. var v1;
  1502. return function reflect( normal ) {
  1503. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1504. return this.sub( v1.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
  1505. }
  1506. }(),
  1507. angleTo: function ( v ) {
  1508. var theta = this.dot( v ) / ( Math.sqrt( this.lengthSq() * v.lengthSq() ) );
  1509. // clamp, to handle numerical problems
  1510. return Math.acos( THREE.Math.clamp( theta, - 1, 1 ) );
  1511. },
  1512. distanceTo: function ( v ) {
  1513. return Math.sqrt( this.distanceToSquared( v ) );
  1514. },
  1515. distanceToSquared: function ( v ) {
  1516. var dx = this.x - v.x;
  1517. var dy = this.y - v.y;
  1518. var dz = this.z - v.z;
  1519. return dx * dx + dy * dy + dz * dz;
  1520. },
  1521. setFromMatrixPosition: function ( m ) {
  1522. this.x = m.elements[ 12 ];
  1523. this.y = m.elements[ 13 ];
  1524. this.z = m.elements[ 14 ];
  1525. return this;
  1526. },
  1527. setFromMatrixScale: function ( m ) {
  1528. var sx = this.set( m.elements[ 0 ], m.elements[ 1 ], m.elements[ 2 ] ).length();
  1529. var sy = this.set( m.elements[ 4 ], m.elements[ 5 ], m.elements[ 6 ] ).length();
  1530. var sz = this.set( m.elements[ 8 ], m.elements[ 9 ], m.elements[ 10 ] ).length();
  1531. this.x = sx;
  1532. this.y = sy;
  1533. this.z = sz;
  1534. return this;
  1535. },
  1536. setFromMatrixColumn: function ( index, matrix ) {
  1537. var offset = index * 4;
  1538. var me = matrix.elements;
  1539. this.x = me[ offset ];
  1540. this.y = me[ offset + 1 ];
  1541. this.z = me[ offset + 2 ];
  1542. return this;
  1543. },
  1544. equals: function ( v ) {
  1545. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  1546. },
  1547. fromArray: function ( array, offset ) {
  1548. if ( offset === undefined ) offset = 0;
  1549. this.x = array[ offset ];
  1550. this.y = array[ offset + 1 ];
  1551. this.z = array[ offset + 2 ];
  1552. return this;
  1553. },
  1554. toArray: function ( array, offset ) {
  1555. if ( array === undefined ) array = [];
  1556. if ( offset === undefined ) offset = 0;
  1557. array[ offset ] = this.x;
  1558. array[ offset + 1 ] = this.y;
  1559. array[ offset + 2 ] = this.z;
  1560. return array;
  1561. },
  1562. fromAttribute: function ( attribute, index, offset ) {
  1563. if ( offset === undefined ) offset = 0;
  1564. index = index * attribute.itemSize + offset;
  1565. this.x = attribute.array[ index ];
  1566. this.y = attribute.array[ index + 1 ];
  1567. this.z = attribute.array[ index + 2 ];
  1568. return this;
  1569. }
  1570. };
  1571. // File:src/math/Vector4.js
  1572. /**
  1573. * @author supereggbert / http://www.paulbrunt.co.uk/
  1574. * @author philogb / http://blog.thejit.org/
  1575. * @author mikael emtinger / http://gomo.se/
  1576. * @author egraether / http://egraether.com/
  1577. * @author WestLangley / http://github.com/WestLangley
  1578. */
  1579. THREE.Vector4 = function ( x, y, z, w ) {
  1580. this.x = x || 0;
  1581. this.y = y || 0;
  1582. this.z = z || 0;
  1583. this.w = ( w !== undefined ) ? w : 1;
  1584. };
  1585. THREE.Vector4.prototype = {
  1586. constructor: THREE.Vector4,
  1587. set: function ( x, y, z, w ) {
  1588. this.x = x;
  1589. this.y = y;
  1590. this.z = z;
  1591. this.w = w;
  1592. return this;
  1593. },
  1594. setX: function ( x ) {
  1595. this.x = x;
  1596. return this;
  1597. },
  1598. setY: function ( y ) {
  1599. this.y = y;
  1600. return this;
  1601. },
  1602. setZ: function ( z ) {
  1603. this.z = z;
  1604. return this;
  1605. },
  1606. setW: function ( w ) {
  1607. this.w = w;
  1608. return this;
  1609. },
  1610. setComponent: function ( index, value ) {
  1611. switch ( index ) {
  1612. case 0: this.x = value; break;
  1613. case 1: this.y = value; break;
  1614. case 2: this.z = value; break;
  1615. case 3: this.w = value; break;
  1616. default: throw new Error( 'index is out of range: ' + index );
  1617. }
  1618. },
  1619. getComponent: function ( index ) {
  1620. switch ( index ) {
  1621. case 0: return this.x;
  1622. case 1: return this.y;
  1623. case 2: return this.z;
  1624. case 3: return this.w;
  1625. default: throw new Error( 'index is out of range: ' + index );
  1626. }
  1627. },
  1628. clone: function () {
  1629. return new this.constructor( this.x, this.y, this.z, this.w );
  1630. },
  1631. copy: function ( v ) {
  1632. this.x = v.x;
  1633. this.y = v.y;
  1634. this.z = v.z;
  1635. this.w = ( v.w !== undefined ) ? v.w : 1;
  1636. return this;
  1637. },
  1638. add: function ( v, w ) {
  1639. if ( w !== undefined ) {
  1640. console.warn( 'THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1641. return this.addVectors( v, w );
  1642. }
  1643. this.x += v.x;
  1644. this.y += v.y;
  1645. this.z += v.z;
  1646. this.w += v.w;
  1647. return this;
  1648. },
  1649. addScalar: function ( s ) {
  1650. this.x += s;
  1651. this.y += s;
  1652. this.z += s;
  1653. this.w += s;
  1654. return this;
  1655. },
  1656. addVectors: function ( a, b ) {
  1657. this.x = a.x + b.x;
  1658. this.y = a.y + b.y;
  1659. this.z = a.z + b.z;
  1660. this.w = a.w + b.w;
  1661. return this;
  1662. },
  1663. addScaledVector: function ( v, s ) {
  1664. this.x += v.x * s;
  1665. this.y += v.y * s;
  1666. this.z += v.z * s;
  1667. this.w += v.w * s;
  1668. return this;
  1669. },
  1670. sub: function ( v, w ) {
  1671. if ( w !== undefined ) {
  1672. console.warn( 'THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1673. return this.subVectors( v, w );
  1674. }
  1675. this.x -= v.x;
  1676. this.y -= v.y;
  1677. this.z -= v.z;
  1678. this.w -= v.w;
  1679. return this;
  1680. },
  1681. subScalar: function ( s ) {
  1682. this.x -= s;
  1683. this.y -= s;
  1684. this.z -= s;
  1685. this.w -= s;
  1686. return this;
  1687. },
  1688. subVectors: function ( a, b ) {
  1689. this.x = a.x - b.x;
  1690. this.y = a.y - b.y;
  1691. this.z = a.z - b.z;
  1692. this.w = a.w - b.w;
  1693. return this;
  1694. },
  1695. multiplyScalar: function ( scalar ) {
  1696. if ( isFinite( scalar ) ) {
  1697. this.x *= scalar;
  1698. this.y *= scalar;
  1699. this.z *= scalar;
  1700. this.w *= scalar;
  1701. } else {
  1702. this.x = 0;
  1703. this.y = 0;
  1704. this.z = 0;
  1705. this.w = 0;
  1706. }
  1707. return this;
  1708. },
  1709. applyMatrix4: function ( m ) {
  1710. var x = this.x;
  1711. var y = this.y;
  1712. var z = this.z;
  1713. var w = this.w;
  1714. var e = m.elements;
  1715. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  1716. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  1717. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  1718. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  1719. return this;
  1720. },
  1721. divideScalar: function ( scalar ) {
  1722. return this.multiplyScalar( 1 / scalar );
  1723. },
  1724. setAxisAngleFromQuaternion: function ( q ) {
  1725. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  1726. // q is assumed to be normalized
  1727. this.w = 2 * Math.acos( q.w );
  1728. var s = Math.sqrt( 1 - q.w * q.w );
  1729. if ( s < 0.0001 ) {
  1730. this.x = 1;
  1731. this.y = 0;
  1732. this.z = 0;
  1733. } else {
  1734. this.x = q.x / s;
  1735. this.y = q.y / s;
  1736. this.z = q.z / s;
  1737. }
  1738. return this;
  1739. },
  1740. setAxisAngleFromRotationMatrix: function ( m ) {
  1741. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  1742. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1743. var angle, x, y, z, // variables for result
  1744. epsilon = 0.01, // margin to allow for rounding errors
  1745. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  1746. te = m.elements,
  1747. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  1748. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  1749. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  1750. if ( ( Math.abs( m12 - m21 ) < epsilon )
  1751. && ( Math.abs( m13 - m31 ) < epsilon )
  1752. && ( Math.abs( m23 - m32 ) < epsilon ) ) {
  1753. // singularity found
  1754. // first check for identity matrix which must have +1 for all terms
  1755. // in leading diagonal and zero in other terms
  1756. if ( ( Math.abs( m12 + m21 ) < epsilon2 )
  1757. && ( Math.abs( m13 + m31 ) < epsilon2 )
  1758. && ( Math.abs( m23 + m32 ) < epsilon2 )
  1759. && ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  1760. // this singularity is identity matrix so angle = 0
  1761. this.set( 1, 0, 0, 0 );
  1762. return this; // zero angle, arbitrary axis
  1763. }
  1764. // otherwise this singularity is angle = 180
  1765. angle = Math.PI;
  1766. var xx = ( m11 + 1 ) / 2;
  1767. var yy = ( m22 + 1 ) / 2;
  1768. var zz = ( m33 + 1 ) / 2;
  1769. var xy = ( m12 + m21 ) / 4;
  1770. var xz = ( m13 + m31 ) / 4;
  1771. var yz = ( m23 + m32 ) / 4;
  1772. if ( ( xx > yy ) && ( xx > zz ) ) {
  1773. // m11 is the largest diagonal term
  1774. if ( xx < epsilon ) {
  1775. x = 0;
  1776. y = 0.707106781;
  1777. z = 0.707106781;
  1778. } else {
  1779. x = Math.sqrt( xx );
  1780. y = xy / x;
  1781. z = xz / x;
  1782. }
  1783. } else if ( yy > zz ) {
  1784. // m22 is the largest diagonal term
  1785. if ( yy < epsilon ) {
  1786. x = 0.707106781;
  1787. y = 0;
  1788. z = 0.707106781;
  1789. } else {
  1790. y = Math.sqrt( yy );
  1791. x = xy / y;
  1792. z = yz / y;
  1793. }
  1794. } else {
  1795. // m33 is the largest diagonal term so base result on this
  1796. if ( zz < epsilon ) {
  1797. x = 0.707106781;
  1798. y = 0.707106781;
  1799. z = 0;
  1800. } else {
  1801. z = Math.sqrt( zz );
  1802. x = xz / z;
  1803. y = yz / z;
  1804. }
  1805. }
  1806. this.set( x, y, z, angle );
  1807. return this; // return 180 deg rotation
  1808. }
  1809. // as we have reached here there are no singularities so we can handle normally
  1810. var s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 )
  1811. + ( m13 - m31 ) * ( m13 - m31 )
  1812. + ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  1813. if ( Math.abs( s ) < 0.001 ) s = 1;
  1814. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  1815. // caught by singularity test above, but I've left it in just in case
  1816. this.x = ( m32 - m23 ) / s;
  1817. this.y = ( m13 - m31 ) / s;
  1818. this.z = ( m21 - m12 ) / s;
  1819. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  1820. return this;
  1821. },
  1822. min: function ( v ) {
  1823. this.x = Math.min( this.x, v.x );
  1824. this.y = Math.min( this.y, v.y );
  1825. this.z = Math.min( this.z, v.z );
  1826. this.w = Math.min( this.w, v.w );
  1827. return this;
  1828. },
  1829. max: function ( v ) {
  1830. this.x = Math.max( this.x, v.x );
  1831. this.y = Math.max( this.y, v.y );
  1832. this.z = Math.max( this.z, v.z );
  1833. this.w = Math.max( this.w, v.w );
  1834. return this;
  1835. },
  1836. clamp: function ( min, max ) {
  1837. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1838. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1839. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1840. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  1841. this.w = Math.max( min.w, Math.min( max.w, this.w ) );
  1842. return this;
  1843. },
  1844. clampScalar: function () {
  1845. var min, max;
  1846. return function clampScalar( minVal, maxVal ) {
  1847. if ( min === undefined ) {
  1848. min = new THREE.Vector4();
  1849. max = new THREE.Vector4();
  1850. }
  1851. min.set( minVal, minVal, minVal, minVal );
  1852. max.set( maxVal, maxVal, maxVal, maxVal );
  1853. return this.clamp( min, max );
  1854. };
  1855. }(),
  1856. floor: function () {
  1857. this.x = Math.floor( this.x );
  1858. this.y = Math.floor( this.y );
  1859. this.z = Math.floor( this.z );
  1860. this.w = Math.floor( this.w );
  1861. return this;
  1862. },
  1863. ceil: function () {
  1864. this.x = Math.ceil( this.x );
  1865. this.y = Math.ceil( this.y );
  1866. this.z = Math.ceil( this.z );
  1867. this.w = Math.ceil( this.w );
  1868. return this;
  1869. },
  1870. round: function () {
  1871. this.x = Math.round( this.x );
  1872. this.y = Math.round( this.y );
  1873. this.z = Math.round( this.z );
  1874. this.w = Math.round( this.w );
  1875. return this;
  1876. },
  1877. roundToZero: function () {
  1878. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1879. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1880. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1881. this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
  1882. return this;
  1883. },
  1884. negate: function () {
  1885. this.x = - this.x;
  1886. this.y = - this.y;
  1887. this.z = - this.z;
  1888. this.w = - this.w;
  1889. return this;
  1890. },
  1891. dot: function ( v ) {
  1892. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  1893. },
  1894. lengthSq: function () {
  1895. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  1896. },
  1897. length: function () {
  1898. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  1899. },
  1900. lengthManhattan: function () {
  1901. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  1902. },
  1903. normalize: function () {
  1904. return this.divideScalar( this.length() );
  1905. },
  1906. setLength: function ( length ) {
  1907. return this.multiplyScalar( length / this.length() );
  1908. },
  1909. lerp: function ( v, alpha ) {
  1910. this.x += ( v.x - this.x ) * alpha;
  1911. this.y += ( v.y - this.y ) * alpha;
  1912. this.z += ( v.z - this.z ) * alpha;
  1913. this.w += ( v.w - this.w ) * alpha;
  1914. return this;
  1915. },
  1916. lerpVectors: function ( v1, v2, alpha ) {
  1917. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1918. return this;
  1919. },
  1920. equals: function ( v ) {
  1921. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  1922. },
  1923. fromArray: function ( array, offset ) {
  1924. if ( offset === undefined ) offset = 0;
  1925. this.x = array[ offset ];
  1926. this.y = array[ offset + 1 ];
  1927. this.z = array[ offset + 2 ];
  1928. this.w = array[ offset + 3 ];
  1929. return this;
  1930. },
  1931. toArray: function ( array, offset ) {
  1932. if ( array === undefined ) array = [];
  1933. if ( offset === undefined ) offset = 0;
  1934. array[ offset ] = this.x;
  1935. array[ offset + 1 ] = this.y;
  1936. array[ offset + 2 ] = this.z;
  1937. array[ offset + 3 ] = this.w;
  1938. return array;
  1939. },
  1940. fromAttribute: function ( attribute, index, offset ) {
  1941. if ( offset === undefined ) offset = 0;
  1942. index = index * attribute.itemSize + offset;
  1943. this.x = attribute.array[ index ];
  1944. this.y = attribute.array[ index + 1 ];
  1945. this.z = attribute.array[ index + 2 ];
  1946. this.w = attribute.array[ index + 3 ];
  1947. return this;
  1948. }
  1949. };
  1950. // File:src/math/Euler.js
  1951. /**
  1952. * @author mrdoob / http://mrdoob.com/
  1953. * @author WestLangley / http://github.com/WestLangley
  1954. * @author bhouston / http://clara.io
  1955. */
  1956. THREE.Euler = function ( x, y, z, order ) {
  1957. this._x = x || 0;
  1958. this._y = y || 0;
  1959. this._z = z || 0;
  1960. this._order = order || THREE.Euler.DefaultOrder;
  1961. };
  1962. THREE.Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
  1963. THREE.Euler.DefaultOrder = 'XYZ';
  1964. THREE.Euler.prototype = {
  1965. constructor: THREE.Euler,
  1966. get x () {
  1967. return this._x;
  1968. },
  1969. set x ( value ) {
  1970. this._x = value;
  1971. this.onChangeCallback();
  1972. },
  1973. get y () {
  1974. return this._y;
  1975. },
  1976. set y ( value ) {
  1977. this._y = value;
  1978. this.onChangeCallback();
  1979. },
  1980. get z () {
  1981. return this._z;
  1982. },
  1983. set z ( value ) {
  1984. this._z = value;
  1985. this.onChangeCallback();
  1986. },
  1987. get order () {
  1988. return this._order;
  1989. },
  1990. set order ( value ) {
  1991. this._order = value;
  1992. this.onChangeCallback();
  1993. },
  1994. set: function ( x, y, z, order ) {
  1995. this._x = x;
  1996. this._y = y;
  1997. this._z = z;
  1998. this._order = order || this._order;
  1999. this.onChangeCallback();
  2000. return this;
  2001. },
  2002. clone: function () {
  2003. return new this.constructor( this._x, this._y, this._z, this._order);
  2004. },
  2005. copy: function ( euler ) {
  2006. this._x = euler._x;
  2007. this._y = euler._y;
  2008. this._z = euler._z;
  2009. this._order = euler._order;
  2010. this.onChangeCallback();
  2011. return this;
  2012. },
  2013. setFromRotationMatrix: function ( m, order, update ) {
  2014. var clamp = THREE.Math.clamp;
  2015. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2016. var te = m.elements;
  2017. var m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  2018. var m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  2019. var m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  2020. order = order || this._order;
  2021. if ( order === 'XYZ' ) {
  2022. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  2023. if ( Math.abs( m13 ) < 0.99999 ) {
  2024. this._x = Math.atan2( - m23, m33 );
  2025. this._z = Math.atan2( - m12, m11 );
  2026. } else {
  2027. this._x = Math.atan2( m32, m22 );
  2028. this._z = 0;
  2029. }
  2030. } else if ( order === 'YXZ' ) {
  2031. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  2032. if ( Math.abs( m23 ) < 0.99999 ) {
  2033. this._y = Math.atan2( m13, m33 );
  2034. this._z = Math.atan2( m21, m22 );
  2035. } else {
  2036. this._y = Math.atan2( - m31, m11 );
  2037. this._z = 0;
  2038. }
  2039. } else if ( order === 'ZXY' ) {
  2040. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  2041. if ( Math.abs( m32 ) < 0.99999 ) {
  2042. this._y = Math.atan2( - m31, m33 );
  2043. this._z = Math.atan2( - m12, m22 );
  2044. } else {
  2045. this._y = 0;
  2046. this._z = Math.atan2( m21, m11 );
  2047. }
  2048. } else if ( order === 'ZYX' ) {
  2049. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  2050. if ( Math.abs( m31 ) < 0.99999 ) {
  2051. this._x = Math.atan2( m32, m33 );
  2052. this._z = Math.atan2( m21, m11 );
  2053. } else {
  2054. this._x = 0;
  2055. this._z = Math.atan2( - m12, m22 );
  2056. }
  2057. } else if ( order === 'YZX' ) {
  2058. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  2059. if ( Math.abs( m21 ) < 0.99999 ) {
  2060. this._x = Math.atan2( - m23, m22 );
  2061. this._y = Math.atan2( - m31, m11 );
  2062. } else {
  2063. this._x = 0;
  2064. this._y = Math.atan2( m13, m33 );
  2065. }
  2066. } else if ( order === 'XZY' ) {
  2067. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  2068. if ( Math.abs( m12 ) < 0.99999 ) {
  2069. this._x = Math.atan2( m32, m22 );
  2070. this._y = Math.atan2( m13, m11 );
  2071. } else {
  2072. this._x = Math.atan2( - m23, m33 );
  2073. this._y = 0;
  2074. }
  2075. } else {
  2076. console.warn( 'THREE.Euler: .setFromRotationMatrix() given unsupported order: ' + order )
  2077. }
  2078. this._order = order;
  2079. if ( update !== false ) this.onChangeCallback();
  2080. return this;
  2081. },
  2082. setFromQuaternion: function () {
  2083. var matrix;
  2084. return function ( q, order, update ) {
  2085. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  2086. matrix.makeRotationFromQuaternion( q );
  2087. this.setFromRotationMatrix( matrix, order, update );
  2088. return this;
  2089. };
  2090. }(),
  2091. setFromVector3: function ( v, order ) {
  2092. return this.set( v.x, v.y, v.z, order || this._order );
  2093. },
  2094. reorder: function () {
  2095. // WARNING: this discards revolution information -bhouston
  2096. var q = new THREE.Quaternion();
  2097. return function ( newOrder ) {
  2098. q.setFromEuler( this );
  2099. this.setFromQuaternion( q, newOrder );
  2100. };
  2101. }(),
  2102. equals: function ( euler ) {
  2103. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  2104. },
  2105. fromArray: function ( array ) {
  2106. this._x = array[ 0 ];
  2107. this._y = array[ 1 ];
  2108. this._z = array[ 2 ];
  2109. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  2110. this.onChangeCallback();
  2111. return this;
  2112. },
  2113. toArray: function ( array, offset ) {
  2114. if ( array === undefined ) array = [];
  2115. if ( offset === undefined ) offset = 0;
  2116. array[ offset ] = this._x;
  2117. array[ offset + 1 ] = this._y;
  2118. array[ offset + 2 ] = this._z;
  2119. array[ offset + 3 ] = this._order;
  2120. return array;
  2121. },
  2122. toVector3: function ( optionalResult ) {
  2123. if ( optionalResult ) {
  2124. return optionalResult.set( this._x, this._y, this._z );
  2125. } else {
  2126. return new THREE.Vector3( this._x, this._y, this._z );
  2127. }
  2128. },
  2129. onChange: function ( callback ) {
  2130. this.onChangeCallback = callback;
  2131. return this;
  2132. },
  2133. onChangeCallback: function () {}
  2134. };
  2135. // File:src/math/Line3.js
  2136. /**
  2137. * @author bhouston / http://clara.io
  2138. */
  2139. THREE.Line3 = function ( start, end ) {
  2140. this.start = ( start !== undefined ) ? start : new THREE.Vector3();
  2141. this.end = ( end !== undefined ) ? end : new THREE.Vector3();
  2142. };
  2143. THREE.Line3.prototype = {
  2144. constructor: THREE.Line3,
  2145. set: function ( start, end ) {
  2146. this.start.copy( start );
  2147. this.end.copy( end );
  2148. return this;
  2149. },
  2150. clone: function () {
  2151. return new this.constructor().copy( this );
  2152. },
  2153. copy: function ( line ) {
  2154. this.start.copy( line.start );
  2155. this.end.copy( line.end );
  2156. return this;
  2157. },
  2158. center: function ( optionalTarget ) {
  2159. var result = optionalTarget || new THREE.Vector3();
  2160. return result.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  2161. },
  2162. delta: function ( optionalTarget ) {
  2163. var result = optionalTarget || new THREE.Vector3();
  2164. return result.subVectors( this.end, this.start );
  2165. },
  2166. distanceSq: function () {
  2167. return this.start.distanceToSquared( this.end );
  2168. },
  2169. distance: function () {
  2170. return this.start.distanceTo( this.end );
  2171. },
  2172. at: function ( t, optionalTarget ) {
  2173. var result = optionalTarget || new THREE.Vector3();
  2174. return this.delta( result ).multiplyScalar( t ).add( this.start );
  2175. },
  2176. closestPointToPointParameter: function () {
  2177. var startP = new THREE.Vector3();
  2178. var startEnd = new THREE.Vector3();
  2179. return function ( point, clampToLine ) {
  2180. startP.subVectors( point, this.start );
  2181. startEnd.subVectors( this.end, this.start );
  2182. var startEnd2 = startEnd.dot( startEnd );
  2183. var startEnd_startP = startEnd.dot( startP );
  2184. var t = startEnd_startP / startEnd2;
  2185. if ( clampToLine ) {
  2186. t = THREE.Math.clamp( t, 0, 1 );
  2187. }
  2188. return t;
  2189. };
  2190. }(),
  2191. closestPointToPoint: function ( point, clampToLine, optionalTarget ) {
  2192. var t = this.closestPointToPointParameter( point, clampToLine );
  2193. var result = optionalTarget || new THREE.Vector3();
  2194. return this.delta( result ).multiplyScalar( t ).add( this.start );
  2195. },
  2196. applyMatrix4: function ( matrix ) {
  2197. this.start.applyMatrix4( matrix );
  2198. this.end.applyMatrix4( matrix );
  2199. return this;
  2200. },
  2201. equals: function ( line ) {
  2202. return line.start.equals( this.start ) && line.end.equals( this.end );
  2203. }
  2204. };
  2205. // File:src/math/Box2.js
  2206. /**
  2207. * @author bhouston / http://clara.io
  2208. */
  2209. THREE.Box2 = function ( min, max ) {
  2210. this.min = ( min !== undefined ) ? min : new THREE.Vector2( Infinity, Infinity );
  2211. this.max = ( max !== undefined ) ? max : new THREE.Vector2( - Infinity, - Infinity );
  2212. };
  2213. THREE.Box2.prototype = {
  2214. constructor: THREE.Box2,
  2215. set: function ( min, max ) {
  2216. this.min.copy( min );
  2217. this.max.copy( max );
  2218. return this;
  2219. },
  2220. setFromPoints: function ( points ) {
  2221. this.makeEmpty();
  2222. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2223. this.expandByPoint( points[ i ] )
  2224. }
  2225. return this;
  2226. },
  2227. setFromCenterAndSize: function () {
  2228. var v1 = new THREE.Vector2();
  2229. return function ( center, size ) {
  2230. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2231. this.min.copy( center ).sub( halfSize );
  2232. this.max.copy( center ).add( halfSize );
  2233. return this;
  2234. };
  2235. }(),
  2236. clone: function () {
  2237. return new this.constructor().copy( this );
  2238. },
  2239. copy: function ( box ) {
  2240. this.min.copy( box.min );
  2241. this.max.copy( box.max );
  2242. return this;
  2243. },
  2244. makeEmpty: function () {
  2245. this.min.x = this.min.y = Infinity;
  2246. this.max.x = this.max.y = - Infinity;
  2247. return this;
  2248. },
  2249. empty: function () {
  2250. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2251. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  2252. },
  2253. center: function ( optionalTarget ) {
  2254. var result = optionalTarget || new THREE.Vector2();
  2255. return result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2256. },
  2257. size: function ( optionalTarget ) {
  2258. var result = optionalTarget || new THREE.Vector2();
  2259. return result.subVectors( this.max, this.min );
  2260. },
  2261. expandByPoint: function ( point ) {
  2262. this.min.min( point );
  2263. this.max.max( point );
  2264. return this;
  2265. },
  2266. expandByVector: function ( vector ) {
  2267. this.min.sub( vector );
  2268. this.max.add( vector );
  2269. return this;
  2270. },
  2271. expandByScalar: function ( scalar ) {
  2272. this.min.addScalar( - scalar );
  2273. this.max.addScalar( scalar );
  2274. return this;
  2275. },
  2276. containsPoint: function ( point ) {
  2277. if ( point.x < this.min.x || point.x > this.max.x ||
  2278. point.y < this.min.y || point.y > this.max.y ) {
  2279. return false;
  2280. }
  2281. return true;
  2282. },
  2283. containsBox: function ( box ) {
  2284. if ( ( this.min.x <= box.min.x ) && ( box.max.x <= this.max.x ) &&
  2285. ( this.min.y <= box.min.y ) && ( box.max.y <= this.max.y ) ) {
  2286. return true;
  2287. }
  2288. return false;
  2289. },
  2290. getParameter: function ( point, optionalTarget ) {
  2291. // This can potentially have a divide by zero if the box
  2292. // has a size dimension of 0.
  2293. var result = optionalTarget || new THREE.Vector2();
  2294. return result.set(
  2295. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2296. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  2297. );
  2298. },
  2299. intersectsBox: function ( box ) {
  2300. // using 6 splitting planes to rule out intersections.
  2301. if ( box.max.x < this.min.x || box.min.x > this.max.x ||
  2302. box.max.y < this.min.y || box.min.y > this.max.y ) {
  2303. return false;
  2304. }
  2305. return true;
  2306. },
  2307. clampPoint: function ( point, optionalTarget ) {
  2308. var result = optionalTarget || new THREE.Vector2();
  2309. return result.copy( point ).clamp( this.min, this.max );
  2310. },
  2311. distanceToPoint: function () {
  2312. var v1 = new THREE.Vector2();
  2313. return function ( point ) {
  2314. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  2315. return clampedPoint.sub( point ).length();
  2316. };
  2317. }(),
  2318. intersect: function ( box ) {
  2319. this.min.max( box.min );
  2320. this.max.min( box.max );
  2321. return this;
  2322. },
  2323. union: function ( box ) {
  2324. this.min.min( box.min );
  2325. this.max.max( box.max );
  2326. return this;
  2327. },
  2328. translate: function ( offset ) {
  2329. this.min.add( offset );
  2330. this.max.add( offset );
  2331. return this;
  2332. },
  2333. equals: function ( box ) {
  2334. return box.min.equals( this.min ) && box.max.equals( this.max );
  2335. }
  2336. };
  2337. // File:src/math/Box3.js
  2338. /**
  2339. * @author bhouston / http://clara.io
  2340. * @author WestLangley / http://github.com/WestLangley
  2341. */
  2342. THREE.Box3 = function ( min, max ) {
  2343. this.min = ( min !== undefined ) ? min : new THREE.Vector3( Infinity, Infinity, Infinity );
  2344. this.max = ( max !== undefined ) ? max : new THREE.Vector3( - Infinity, - Infinity, - Infinity );
  2345. };
  2346. THREE.Box3.prototype = {
  2347. constructor: THREE.Box3,
  2348. set: function ( min, max ) {
  2349. this.min.copy( min );
  2350. this.max.copy( max );
  2351. return this;
  2352. },
  2353. setFromPoints: function ( points ) {
  2354. this.makeEmpty();
  2355. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2356. this.expandByPoint( points[ i ] );
  2357. }
  2358. return this;
  2359. },
  2360. setFromCenterAndSize: function () {
  2361. var v1 = new THREE.Vector3();
  2362. return function ( center, size ) {
  2363. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2364. this.min.copy( center ).sub( halfSize );
  2365. this.max.copy( center ).add( halfSize );
  2366. return this;
  2367. };
  2368. }(),
  2369. setFromObject: function () {
  2370. // Computes the world-axis-aligned bounding box of an object (including its children),
  2371. // accounting for both the object's, and children's, world transforms
  2372. var box;
  2373. return function ( object ) {
  2374. if ( box === undefined ) box = new THREE.Box3();
  2375. var scope = this;
  2376. this.makeEmpty();
  2377. object.updateMatrixWorld( true );
  2378. object.traverse( function ( node ) {
  2379. var geometry = node.geometry;
  2380. if ( geometry !== undefined ) {
  2381. if ( geometry.boundingBox === null ) {
  2382. geometry.computeBoundingBox();
  2383. }
  2384. box.copy( geometry.boundingBox );
  2385. box.applyMatrix4( node.matrixWorld );
  2386. scope.union( box );
  2387. }
  2388. } );
  2389. return this;
  2390. };
  2391. }(),
  2392. clone: function () {
  2393. return new this.constructor().copy( this );
  2394. },
  2395. copy: function ( box ) {
  2396. this.min.copy( box.min );
  2397. this.max.copy( box.max );
  2398. return this;
  2399. },
  2400. makeEmpty: function () {
  2401. this.min.x = this.min.y = this.min.z = Infinity;
  2402. this.max.x = this.max.y = this.max.z = - Infinity;
  2403. return this;
  2404. },
  2405. empty: function () {
  2406. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2407. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  2408. },
  2409. center: function ( optionalTarget ) {
  2410. var result = optionalTarget || new THREE.Vector3();
  2411. return result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2412. },
  2413. size: function ( optionalTarget ) {
  2414. var result = optionalTarget || new THREE.Vector3();
  2415. return result.subVectors( this.max, this.min );
  2416. },
  2417. expandByPoint: function ( point ) {
  2418. this.min.min( point );
  2419. this.max.max( point );
  2420. return this;
  2421. },
  2422. expandByVector: function ( vector ) {
  2423. this.min.sub( vector );
  2424. this.max.add( vector );
  2425. return this;
  2426. },
  2427. expandByScalar: function ( scalar ) {
  2428. this.min.addScalar( - scalar );
  2429. this.max.addScalar( scalar );
  2430. return this;
  2431. },
  2432. containsPoint: function ( point ) {
  2433. if ( point.x < this.min.x || point.x > this.max.x ||
  2434. point.y < this.min.y || point.y > this.max.y ||
  2435. point.z < this.min.z || point.z > this.max.z ) {
  2436. return false;
  2437. }
  2438. return true;
  2439. },
  2440. containsBox: function ( box ) {
  2441. if ( ( this.min.x <= box.min.x ) && ( box.max.x <= this.max.x ) &&
  2442. ( this.min.y <= box.min.y ) && ( box.max.y <= this.max.y ) &&
  2443. ( this.min.z <= box.min.z ) && ( box.max.z <= this.max.z ) ) {
  2444. return true;
  2445. }
  2446. return false;
  2447. },
  2448. getParameter: function ( point, optionalTarget ) {
  2449. // This can potentially have a divide by zero if the box
  2450. // has a size dimension of 0.
  2451. var result = optionalTarget || new THREE.Vector3();
  2452. return result.set(
  2453. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2454. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  2455. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  2456. );
  2457. },
  2458. intersectsBox: function ( box ) {
  2459. // using 6 splitting planes to rule out intersections.
  2460. if ( box.max.x < this.min.x || box.min.x > this.max.x ||
  2461. box.max.y < this.min.y || box.min.y > this.max.y ||
  2462. box.max.z < this.min.z || box.min.z > this.max.z ) {
  2463. return false;
  2464. }
  2465. return true;
  2466. },
  2467. intersectsSphere: ( function () {
  2468. var closestPoint;
  2469. return function intersectsSphere( sphere ) {
  2470. if ( closestPoint === undefined ) closestPoint = new THREE.Vector3();
  2471. // Find the point on the AABB closest to the sphere center.
  2472. this.clampPoint( sphere.center, closestPoint );
  2473. // If that point is inside the sphere, the AABB and sphere intersect.
  2474. return closestPoint.distanceToSquared( sphere.center ) <= ( sphere.radius * sphere.radius );
  2475. };
  2476. } )(),
  2477. intersectsPlane: function ( plane ) {
  2478. // We compute the minimum and maximum dot product values. If those values
  2479. // are on the same side (back or front) of the plane, then there is no intersection.
  2480. var min, max;
  2481. if( plane.normal.x > 0 ) {
  2482. min = plane.normal.x * this.min.x;
  2483. max = plane.normal.x * this.max.x;
  2484. } else {
  2485. min = plane.normal.x * this.max.x;
  2486. max = plane.normal.x * this.min.x;
  2487. }
  2488. if( plane.normal.y > 0 ) {
  2489. min += plane.normal.y * this.min.y;
  2490. max += plane.normal.y * this.max.y;
  2491. } else {
  2492. min += plane.normal.y * this.max.y;
  2493. max += plane.normal.y * this.min.y;
  2494. }
  2495. if( plane.normal.z > 0 ) {
  2496. min += plane.normal.z * this.min.z;
  2497. max += plane.normal.z * this.max.z;
  2498. } else {
  2499. min += plane.normal.z * this.max.z;
  2500. max += plane.normal.z * this.min.z;
  2501. }
  2502. return ( min <= plane.constant && max >= plane.constant );
  2503. },
  2504. clampPoint: function ( point, optionalTarget ) {
  2505. var result = optionalTarget || new THREE.Vector3();
  2506. return result.copy( point ).clamp( this.min, this.max );
  2507. },
  2508. distanceToPoint: function () {
  2509. var v1 = new THREE.Vector3();
  2510. return function ( point ) {
  2511. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  2512. return clampedPoint.sub( point ).length();
  2513. };
  2514. }(),
  2515. getBoundingSphere: function () {
  2516. var v1 = new THREE.Vector3();
  2517. return function ( optionalTarget ) {
  2518. var result = optionalTarget || new THREE.Sphere();
  2519. result.center = this.center();
  2520. result.radius = this.size( v1 ).length() * 0.5;
  2521. return result;
  2522. };
  2523. }(),
  2524. intersect: function ( box ) {
  2525. this.min.max( box.min );
  2526. this.max.min( box.max );
  2527. return this;
  2528. },
  2529. union: function ( box ) {
  2530. this.min.min( box.min );
  2531. this.max.max( box.max );
  2532. return this;
  2533. },
  2534. applyMatrix4: function () {
  2535. var points = [
  2536. new THREE.Vector3(),
  2537. new THREE.Vector3(),
  2538. new THREE.Vector3(),
  2539. new THREE.Vector3(),
  2540. new THREE.Vector3(),
  2541. new THREE.Vector3(),
  2542. new THREE.Vector3(),
  2543. new THREE.Vector3()
  2544. ];
  2545. return function ( matrix ) {
  2546. // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  2547. points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
  2548. points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
  2549. points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
  2550. points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
  2551. points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
  2552. points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
  2553. points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
  2554. points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
  2555. this.makeEmpty();
  2556. this.setFromPoints( points );
  2557. return this;
  2558. };
  2559. }(),
  2560. translate: function ( offset ) {
  2561. this.min.add( offset );
  2562. this.max.add( offset );
  2563. return this;
  2564. },
  2565. equals: function ( box ) {
  2566. return box.min.equals( this.min ) && box.max.equals( this.max );
  2567. }
  2568. };
  2569. // File:src/math/Matrix3.js
  2570. /**
  2571. * @author alteredq / http://alteredqualia.com/
  2572. * @author WestLangley / http://github.com/WestLangley
  2573. * @author bhouston / http://clara.io
  2574. */
  2575. THREE.Matrix3 = function () {
  2576. this.elements = new Float32Array( [
  2577. 1, 0, 0,
  2578. 0, 1, 0,
  2579. 0, 0, 1
  2580. ] );
  2581. if ( arguments.length > 0 ) {
  2582. console.error( 'THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.' );
  2583. }
  2584. };
  2585. THREE.Matrix3.prototype = {
  2586. constructor: THREE.Matrix3,
  2587. set: function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  2588. var te = this.elements;
  2589. te[ 0 ] = n11; te[ 3 ] = n12; te[ 6 ] = n13;
  2590. te[ 1 ] = n21; te[ 4 ] = n22; te[ 7 ] = n23;
  2591. te[ 2 ] = n31; te[ 5 ] = n32; te[ 8 ] = n33;
  2592. return this;
  2593. },
  2594. identity: function () {
  2595. this.set(
  2596. 1, 0, 0,
  2597. 0, 1, 0,
  2598. 0, 0, 1
  2599. );
  2600. return this;
  2601. },
  2602. clone: function () {
  2603. return new this.constructor().fromArray( this.elements );
  2604. },
  2605. copy: function ( m ) {
  2606. var me = m.elements;
  2607. this.set(
  2608. me[ 0 ], me[ 3 ], me[ 6 ],
  2609. me[ 1 ], me[ 4 ], me[ 7 ],
  2610. me[ 2 ], me[ 5 ], me[ 8 ]
  2611. );
  2612. return this;
  2613. },
  2614. applyToVector3Array: function () {
  2615. var v1;
  2616. return function ( array, offset, length ) {
  2617. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2618. if ( offset === undefined ) offset = 0;
  2619. if ( length === undefined ) length = array.length;
  2620. for ( var i = 0, j = offset; i < length; i += 3, j += 3 ) {
  2621. v1.fromArray( array, j );
  2622. v1.applyMatrix3( this );
  2623. v1.toArray( array, j );
  2624. }
  2625. return array;
  2626. };
  2627. }(),
  2628. applyToBuffer: function () {
  2629. var v1;
  2630. return function applyToBuffer( buffer, offset, length ) {
  2631. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2632. if ( offset === undefined ) offset = 0;
  2633. if ( length === undefined ) length = buffer.length / buffer.itemSize;
  2634. for ( var i = 0, j = offset; i < length; i ++, j ++ ) {
  2635. v1.x = buffer.getX( j );
  2636. v1.y = buffer.getY( j );
  2637. v1.z = buffer.getZ( j );
  2638. v1.applyMatrix3( this );
  2639. buffer.setXYZ( v1.x, v1.y, v1.z );
  2640. }
  2641. return buffer;
  2642. };
  2643. }(),
  2644. multiplyScalar: function ( s ) {
  2645. var te = this.elements;
  2646. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  2647. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  2648. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  2649. return this;
  2650. },
  2651. determinant: function () {
  2652. var te = this.elements;
  2653. var a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  2654. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  2655. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  2656. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  2657. },
  2658. getInverse: function ( matrix, throwOnInvertible ) {
  2659. // input: THREE.Matrix4
  2660. // ( based on http://code.google.com/p/webgl-mjs/ )
  2661. var me = matrix.elements;
  2662. var te = this.elements;
  2663. te[ 0 ] = me[ 10 ] * me[ 5 ] - me[ 6 ] * me[ 9 ];
  2664. te[ 1 ] = - me[ 10 ] * me[ 1 ] + me[ 2 ] * me[ 9 ];
  2665. te[ 2 ] = me[ 6 ] * me[ 1 ] - me[ 2 ] * me[ 5 ];
  2666. te[ 3 ] = - me[ 10 ] * me[ 4 ] + me[ 6 ] * me[ 8 ];
  2667. te[ 4 ] = me[ 10 ] * me[ 0 ] - me[ 2 ] * me[ 8 ];
  2668. te[ 5 ] = - me[ 6 ] * me[ 0 ] + me[ 2 ] * me[ 4 ];
  2669. te[ 6 ] = me[ 9 ] * me[ 4 ] - me[ 5 ] * me[ 8 ];
  2670. te[ 7 ] = - me[ 9 ] * me[ 0 ] + me[ 1 ] * me[ 8 ];
  2671. te[ 8 ] = me[ 5 ] * me[ 0 ] - me[ 1 ] * me[ 4 ];
  2672. var det = me[ 0 ] * te[ 0 ] + me[ 1 ] * te[ 3 ] + me[ 2 ] * te[ 6 ];
  2673. // no inverse
  2674. if ( det === 0 ) {
  2675. var msg = "THREE.Matrix3.getInverse(): can't invert matrix, determinant is 0";
  2676. if ( throwOnInvertible || false ) {
  2677. throw new Error( msg );
  2678. } else {
  2679. console.warn( msg );
  2680. }
  2681. this.identity();
  2682. return this;
  2683. }
  2684. this.multiplyScalar( 1.0 / det );
  2685. return this;
  2686. },
  2687. transpose: function () {
  2688. var tmp, m = this.elements;
  2689. tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
  2690. tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
  2691. tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
  2692. return this;
  2693. },
  2694. flattenToArrayOffset: function ( array, offset ) {
  2695. var te = this.elements;
  2696. array[ offset ] = te[ 0 ];
  2697. array[ offset + 1 ] = te[ 1 ];
  2698. array[ offset + 2 ] = te[ 2 ];
  2699. array[ offset + 3 ] = te[ 3 ];
  2700. array[ offset + 4 ] = te[ 4 ];
  2701. array[ offset + 5 ] = te[ 5 ];
  2702. array[ offset + 6 ] = te[ 6 ];
  2703. array[ offset + 7 ] = te[ 7 ];
  2704. array[ offset + 8 ] = te[ 8 ];
  2705. return array;
  2706. },
  2707. getNormalMatrix: function ( m ) {
  2708. // input: THREE.Matrix4
  2709. this.getInverse( m ).transpose();
  2710. return this;
  2711. },
  2712. transposeIntoArray: function ( r ) {
  2713. var m = this.elements;
  2714. r[ 0 ] = m[ 0 ];
  2715. r[ 1 ] = m[ 3 ];
  2716. r[ 2 ] = m[ 6 ];
  2717. r[ 3 ] = m[ 1 ];
  2718. r[ 4 ] = m[ 4 ];
  2719. r[ 5 ] = m[ 7 ];
  2720. r[ 6 ] = m[ 2 ];
  2721. r[ 7 ] = m[ 5 ];
  2722. r[ 8 ] = m[ 8 ];
  2723. return this;
  2724. },
  2725. fromArray: function ( array ) {
  2726. this.elements.set( array );
  2727. return this;
  2728. },
  2729. toArray: function () {
  2730. var te = this.elements;
  2731. return [
  2732. te[ 0 ], te[ 1 ], te[ 2 ],
  2733. te[ 3 ], te[ 4 ], te[ 5 ],
  2734. te[ 6 ], te[ 7 ], te[ 8 ]
  2735. ];
  2736. }
  2737. };
  2738. // File:src/math/Matrix4.js
  2739. /**
  2740. * @author mrdoob / http://mrdoob.com/
  2741. * @author supereggbert / http://www.paulbrunt.co.uk/
  2742. * @author philogb / http://blog.thejit.org/
  2743. * @author jordi_ros / http://plattsoft.com
  2744. * @author D1plo1d / http://github.com/D1plo1d
  2745. * @author alteredq / http://alteredqualia.com/
  2746. * @author mikael emtinger / http://gomo.se/
  2747. * @author timknip / http://www.floorplanner.com/
  2748. * @author bhouston / http://clara.io
  2749. * @author WestLangley / http://github.com/WestLangley
  2750. */
  2751. THREE.Matrix4 = function () {
  2752. this.elements = new Float32Array( [
  2753. 1, 0, 0, 0,
  2754. 0, 1, 0, 0,
  2755. 0, 0, 1, 0,
  2756. 0, 0, 0, 1
  2757. ] );
  2758. if ( arguments.length > 0 ) {
  2759. console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' );
  2760. }
  2761. };
  2762. THREE.Matrix4.prototype = {
  2763. constructor: THREE.Matrix4,
  2764. set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  2765. var te = this.elements;
  2766. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  2767. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  2768. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  2769. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  2770. return this;
  2771. },
  2772. identity: function () {
  2773. this.set(
  2774. 1, 0, 0, 0,
  2775. 0, 1, 0, 0,
  2776. 0, 0, 1, 0,
  2777. 0, 0, 0, 1
  2778. );
  2779. return this;
  2780. },
  2781. clone: function () {
  2782. return new THREE.Matrix4().fromArray( this.elements );
  2783. },
  2784. copy: function ( m ) {
  2785. this.elements.set( m.elements );
  2786. return this;
  2787. },
  2788. copyPosition: function ( m ) {
  2789. var te = this.elements;
  2790. var me = m.elements;
  2791. te[ 12 ] = me[ 12 ];
  2792. te[ 13 ] = me[ 13 ];
  2793. te[ 14 ] = me[ 14 ];
  2794. return this;
  2795. },
  2796. extractBasis: function ( xAxis, yAxis, zAxis ) {
  2797. var te = this.elements;
  2798. xAxis.set( te[ 0 ], te[ 1 ], te[ 2 ] );
  2799. yAxis.set( te[ 4 ], te[ 5 ], te[ 6 ] );
  2800. zAxis.set( te[ 8 ], te[ 9 ], te[ 10 ] );
  2801. return this;
  2802. },
  2803. makeBasis: function ( xAxis, yAxis, zAxis ) {
  2804. this.set(
  2805. xAxis.x, yAxis.x, zAxis.x, 0,
  2806. xAxis.y, yAxis.y, zAxis.y, 0,
  2807. xAxis.z, yAxis.z, zAxis.z, 0,
  2808. 0, 0, 0, 1
  2809. );
  2810. return this;
  2811. },
  2812. extractRotation: function () {
  2813. var v1;
  2814. return function ( m ) {
  2815. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2816. var te = this.elements;
  2817. var me = m.elements;
  2818. var scaleX = 1 / v1.set( me[ 0 ], me[ 1 ], me[ 2 ] ).length();
  2819. var scaleY = 1 / v1.set( me[ 4 ], me[ 5 ], me[ 6 ] ).length();
  2820. var scaleZ = 1 / v1.set( me[ 8 ], me[ 9 ], me[ 10 ] ).length();
  2821. te[ 0 ] = me[ 0 ] * scaleX;
  2822. te[ 1 ] = me[ 1 ] * scaleX;
  2823. te[ 2 ] = me[ 2 ] * scaleX;
  2824. te[ 4 ] = me[ 4 ] * scaleY;
  2825. te[ 5 ] = me[ 5 ] * scaleY;
  2826. te[ 6 ] = me[ 6 ] * scaleY;
  2827. te[ 8 ] = me[ 8 ] * scaleZ;
  2828. te[ 9 ] = me[ 9 ] * scaleZ;
  2829. te[ 10 ] = me[ 10 ] * scaleZ;
  2830. return this;
  2831. };
  2832. }(),
  2833. makeRotationFromEuler: function ( euler ) {
  2834. if ( euler instanceof THREE.Euler === false ) {
  2835. console.error( 'THREE.Matrix: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  2836. }
  2837. var te = this.elements;
  2838. var x = euler.x, y = euler.y, z = euler.z;
  2839. var a = Math.cos( x ), b = Math.sin( x );
  2840. var c = Math.cos( y ), d = Math.sin( y );
  2841. var e = Math.cos( z ), f = Math.sin( z );
  2842. if ( euler.order === 'XYZ' ) {
  2843. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2844. te[ 0 ] = c * e;
  2845. te[ 4 ] = - c * f;
  2846. te[ 8 ] = d;
  2847. te[ 1 ] = af + be * d;
  2848. te[ 5 ] = ae - bf * d;
  2849. te[ 9 ] = - b * c;
  2850. te[ 2 ] = bf - ae * d;
  2851. te[ 6 ] = be + af * d;
  2852. te[ 10 ] = a * c;
  2853. } else if ( euler.order === 'YXZ' ) {
  2854. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2855. te[ 0 ] = ce + df * b;
  2856. te[ 4 ] = de * b - cf;
  2857. te[ 8 ] = a * d;
  2858. te[ 1 ] = a * f;
  2859. te[ 5 ] = a * e;
  2860. te[ 9 ] = - b;
  2861. te[ 2 ] = cf * b - de;
  2862. te[ 6 ] = df + ce * b;
  2863. te[ 10 ] = a * c;
  2864. } else if ( euler.order === 'ZXY' ) {
  2865. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2866. te[ 0 ] = ce - df * b;
  2867. te[ 4 ] = - a * f;
  2868. te[ 8 ] = de + cf * b;
  2869. te[ 1 ] = cf + de * b;
  2870. te[ 5 ] = a * e;
  2871. te[ 9 ] = df - ce * b;
  2872. te[ 2 ] = - a * d;
  2873. te[ 6 ] = b;
  2874. te[ 10 ] = a * c;
  2875. } else if ( euler.order === 'ZYX' ) {
  2876. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2877. te[ 0 ] = c * e;
  2878. te[ 4 ] = be * d - af;
  2879. te[ 8 ] = ae * d + bf;
  2880. te[ 1 ] = c * f;
  2881. te[ 5 ] = bf * d + ae;
  2882. te[ 9 ] = af * d - be;
  2883. te[ 2 ] = - d;
  2884. te[ 6 ] = b * c;
  2885. te[ 10 ] = a * c;
  2886. } else if ( euler.order === 'YZX' ) {
  2887. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2888. te[ 0 ] = c * e;
  2889. te[ 4 ] = bd - ac * f;
  2890. te[ 8 ] = bc * f + ad;
  2891. te[ 1 ] = f;
  2892. te[ 5 ] = a * e;
  2893. te[ 9 ] = - b * e;
  2894. te[ 2 ] = - d * e;
  2895. te[ 6 ] = ad * f + bc;
  2896. te[ 10 ] = ac - bd * f;
  2897. } else if ( euler.order === 'XZY' ) {
  2898. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2899. te[ 0 ] = c * e;
  2900. te[ 4 ] = - f;
  2901. te[ 8 ] = d * e;
  2902. te[ 1 ] = ac * f + bd;
  2903. te[ 5 ] = a * e;
  2904. te[ 9 ] = ad * f - bc;
  2905. te[ 2 ] = bc * f - ad;
  2906. te[ 6 ] = b * e;
  2907. te[ 10 ] = bd * f + ac;
  2908. }
  2909. // last column
  2910. te[ 3 ] = 0;
  2911. te[ 7 ] = 0;
  2912. te[ 11 ] = 0;
  2913. // bottom row
  2914. te[ 12 ] = 0;
  2915. te[ 13 ] = 0;
  2916. te[ 14 ] = 0;
  2917. te[ 15 ] = 1;
  2918. return this;
  2919. },
  2920. makeRotationFromQuaternion: function ( q ) {
  2921. var te = this.elements;
  2922. var x = q.x, y = q.y, z = q.z, w = q.w;
  2923. var x2 = x + x, y2 = y + y, z2 = z + z;
  2924. var xx = x * x2, xy = x * y2, xz = x * z2;
  2925. var yy = y * y2, yz = y * z2, zz = z * z2;
  2926. var wx = w * x2, wy = w * y2, wz = w * z2;
  2927. te[ 0 ] = 1 - ( yy + zz );
  2928. te[ 4 ] = xy - wz;
  2929. te[ 8 ] = xz + wy;
  2930. te[ 1 ] = xy + wz;
  2931. te[ 5 ] = 1 - ( xx + zz );
  2932. te[ 9 ] = yz - wx;
  2933. te[ 2 ] = xz - wy;
  2934. te[ 6 ] = yz + wx;
  2935. te[ 10 ] = 1 - ( xx + yy );
  2936. // last column
  2937. te[ 3 ] = 0;
  2938. te[ 7 ] = 0;
  2939. te[ 11 ] = 0;
  2940. // bottom row
  2941. te[ 12 ] = 0;
  2942. te[ 13 ] = 0;
  2943. te[ 14 ] = 0;
  2944. te[ 15 ] = 1;
  2945. return this;
  2946. },
  2947. lookAt: function () {
  2948. var x, y, z;
  2949. return function ( eye, target, up ) {
  2950. if ( x === undefined ) x = new THREE.Vector3();
  2951. if ( y === undefined ) y = new THREE.Vector3();
  2952. if ( z === undefined ) z = new THREE.Vector3();
  2953. var te = this.elements;
  2954. z.subVectors( eye, target ).normalize();
  2955. if ( z.lengthSq() === 0 ) {
  2956. z.z = 1;
  2957. }
  2958. x.crossVectors( up, z ).normalize();
  2959. if ( x.lengthSq() === 0 ) {
  2960. z.x += 0.0001;
  2961. x.crossVectors( up, z ).normalize();
  2962. }
  2963. y.crossVectors( z, x );
  2964. te[ 0 ] = x.x; te[ 4 ] = y.x; te[ 8 ] = z.x;
  2965. te[ 1 ] = x.y; te[ 5 ] = y.y; te[ 9 ] = z.y;
  2966. te[ 2 ] = x.z; te[ 6 ] = y.z; te[ 10 ] = z.z;
  2967. return this;
  2968. };
  2969. }(),
  2970. multiply: function ( m, n ) {
  2971. if ( n !== undefined ) {
  2972. console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' );
  2973. return this.multiplyMatrices( m, n );
  2974. }
  2975. return this.multiplyMatrices( this, m );
  2976. },
  2977. multiplyMatrices: function ( a, b ) {
  2978. var ae = a.elements;
  2979. var be = b.elements;
  2980. var te = this.elements;
  2981. var a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  2982. var a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  2983. var a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  2984. var a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  2985. var b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  2986. var b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  2987. var b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  2988. var b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  2989. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  2990. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  2991. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  2992. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  2993. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  2994. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  2995. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  2996. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  2997. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  2998. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  2999. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  3000. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  3001. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  3002. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  3003. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  3004. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  3005. return this;
  3006. },
  3007. multiplyToArray: function ( a, b, r ) {
  3008. var te = this.elements;
  3009. this.multiplyMatrices( a, b );
  3010. r[ 0 ] = te[ 0 ]; r[ 1 ] = te[ 1 ]; r[ 2 ] = te[ 2 ]; r[ 3 ] = te[ 3 ];
  3011. r[ 4 ] = te[ 4 ]; r[ 5 ] = te[ 5 ]; r[ 6 ] = te[ 6 ]; r[ 7 ] = te[ 7 ];
  3012. r[ 8 ] = te[ 8 ]; r[ 9 ] = te[ 9 ]; r[ 10 ] = te[ 10 ]; r[ 11 ] = te[ 11 ];
  3013. r[ 12 ] = te[ 12 ]; r[ 13 ] = te[ 13 ]; r[ 14 ] = te[ 14 ]; r[ 15 ] = te[ 15 ];
  3014. return this;
  3015. },
  3016. multiplyScalar: function ( s ) {
  3017. var te = this.elements;
  3018. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  3019. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  3020. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  3021. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  3022. return this;
  3023. },
  3024. applyToVector3Array: function () {
  3025. var v1;
  3026. return function ( array, offset, length ) {
  3027. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3028. if ( offset === undefined ) offset = 0;
  3029. if ( length === undefined ) length = array.length;
  3030. for ( var i = 0, j = offset; i < length; i += 3, j += 3 ) {
  3031. v1.fromArray( array, j );
  3032. v1.applyMatrix4( this );
  3033. v1.toArray( array, j );
  3034. }
  3035. return array;
  3036. };
  3037. }(),
  3038. applyToBuffer: function () {
  3039. var v1;
  3040. return function applyToBuffer( buffer, offset, length ) {
  3041. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3042. if ( offset === undefined ) offset = 0;
  3043. if ( length === undefined ) length = buffer.length / buffer.itemSize;
  3044. for ( var i = 0, j = offset; i < length; i ++, j ++ ) {
  3045. v1.x = buffer.getX( j );
  3046. v1.y = buffer.getY( j );
  3047. v1.z = buffer.getZ( j );
  3048. v1.applyMatrix4( this );
  3049. buffer.setXYZ( v1.x, v1.y, v1.z );
  3050. }
  3051. return buffer;
  3052. };
  3053. }(),
  3054. determinant: function () {
  3055. var te = this.elements;
  3056. var n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  3057. var n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  3058. var n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  3059. var n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  3060. //TODO: make this more efficient
  3061. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  3062. return (
  3063. n41 * (
  3064. + n14 * n23 * n32
  3065. - n13 * n24 * n32
  3066. - n14 * n22 * n33
  3067. + n12 * n24 * n33
  3068. + n13 * n22 * n34
  3069. - n12 * n23 * n34
  3070. ) +
  3071. n42 * (
  3072. + n11 * n23 * n34
  3073. - n11 * n24 * n33
  3074. + n14 * n21 * n33
  3075. - n13 * n21 * n34
  3076. + n13 * n24 * n31
  3077. - n14 * n23 * n31
  3078. ) +
  3079. n43 * (
  3080. + n11 * n24 * n32
  3081. - n11 * n22 * n34
  3082. - n14 * n21 * n32
  3083. + n12 * n21 * n34
  3084. + n14 * n22 * n31
  3085. - n12 * n24 * n31
  3086. ) +
  3087. n44 * (
  3088. - n13 * n22 * n31
  3089. - n11 * n23 * n32
  3090. + n11 * n22 * n33
  3091. + n13 * n21 * n32
  3092. - n12 * n21 * n33
  3093. + n12 * n23 * n31
  3094. )
  3095. );
  3096. },
  3097. transpose: function () {
  3098. var te = this.elements;
  3099. var tmp;
  3100. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  3101. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  3102. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  3103. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  3104. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  3105. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  3106. return this;
  3107. },
  3108. flattenToArrayOffset: function ( array, offset ) {
  3109. var te = this.elements;
  3110. array[ offset ] = te[ 0 ];
  3111. array[ offset + 1 ] = te[ 1 ];
  3112. array[ offset + 2 ] = te[ 2 ];
  3113. array[ offset + 3 ] = te[ 3 ];
  3114. array[ offset + 4 ] = te[ 4 ];
  3115. array[ offset + 5 ] = te[ 5 ];
  3116. array[ offset + 6 ] = te[ 6 ];
  3117. array[ offset + 7 ] = te[ 7 ];
  3118. array[ offset + 8 ] = te[ 8 ];
  3119. array[ offset + 9 ] = te[ 9 ];
  3120. array[ offset + 10 ] = te[ 10 ];
  3121. array[ offset + 11 ] = te[ 11 ];
  3122. array[ offset + 12 ] = te[ 12 ];
  3123. array[ offset + 13 ] = te[ 13 ];
  3124. array[ offset + 14 ] = te[ 14 ];
  3125. array[ offset + 15 ] = te[ 15 ];
  3126. return array;
  3127. },
  3128. getPosition: function () {
  3129. var v1;
  3130. return function () {
  3131. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3132. console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
  3133. var te = this.elements;
  3134. return v1.set( te[ 12 ], te[ 13 ], te[ 14 ] );
  3135. };
  3136. }(),
  3137. setPosition: function ( v ) {
  3138. var te = this.elements;
  3139. te[ 12 ] = v.x;
  3140. te[ 13 ] = v.y;
  3141. te[ 14 ] = v.z;
  3142. return this;
  3143. },
  3144. getInverse: function ( m, throwOnInvertible ) {
  3145. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  3146. var te = this.elements;
  3147. var me = m.elements;
  3148. var n11 = me[ 0 ], n12 = me[ 4 ], n13 = me[ 8 ], n14 = me[ 12 ];
  3149. var n21 = me[ 1 ], n22 = me[ 5 ], n23 = me[ 9 ], n24 = me[ 13 ];
  3150. var n31 = me[ 2 ], n32 = me[ 6 ], n33 = me[ 10 ], n34 = me[ 14 ];
  3151. var n41 = me[ 3 ], n42 = me[ 7 ], n43 = me[ 11 ], n44 = me[ 15 ];
  3152. te[ 0 ] = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44;
  3153. te[ 4 ] = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44;
  3154. te[ 8 ] = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44;
  3155. te[ 12 ] = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  3156. te[ 1 ] = n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44;
  3157. te[ 5 ] = n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44;
  3158. te[ 9 ] = n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44;
  3159. te[ 13 ] = n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34;
  3160. te[ 2 ] = n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44;
  3161. te[ 6 ] = n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44;
  3162. te[ 10 ] = n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44;
  3163. te[ 14 ] = n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34;
  3164. te[ 3 ] = n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43;
  3165. te[ 7 ] = n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43;
  3166. te[ 11 ] = n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43;
  3167. te[ 15 ] = n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33;
  3168. var det = n11 * te[ 0 ] + n21 * te[ 4 ] + n31 * te[ 8 ] + n41 * te[ 12 ];
  3169. if ( det === 0 ) {
  3170. var msg = "THREE.Matrix4.getInverse(): can't invert matrix, determinant is 0";
  3171. if ( throwOnInvertible || false ) {
  3172. throw new Error( msg );
  3173. } else {
  3174. console.warn( msg );
  3175. }
  3176. this.identity();
  3177. return this;
  3178. }
  3179. this.multiplyScalar( 1 / det );
  3180. return this;
  3181. },
  3182. scale: function ( v ) {
  3183. var te = this.elements;
  3184. var x = v.x, y = v.y, z = v.z;
  3185. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  3186. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  3187. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  3188. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  3189. return this;
  3190. },
  3191. getMaxScaleOnAxis: function () {
  3192. var te = this.elements;
  3193. var scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  3194. var scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  3195. var scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  3196. return Math.sqrt( Math.max( scaleXSq, scaleYSq, scaleZSq ) );
  3197. },
  3198. makeTranslation: function ( x, y, z ) {
  3199. this.set(
  3200. 1, 0, 0, x,
  3201. 0, 1, 0, y,
  3202. 0, 0, 1, z,
  3203. 0, 0, 0, 1
  3204. );
  3205. return this;
  3206. },
  3207. makeRotationX: function ( theta ) {
  3208. var c = Math.cos( theta ), s = Math.sin( theta );
  3209. this.set(
  3210. 1, 0, 0, 0,
  3211. 0, c, - s, 0,
  3212. 0, s, c, 0,
  3213. 0, 0, 0, 1
  3214. );
  3215. return this;
  3216. },
  3217. makeRotationY: function ( theta ) {
  3218. var c = Math.cos( theta ), s = Math.sin( theta );
  3219. this.set(
  3220. c, 0, s, 0,
  3221. 0, 1, 0, 0,
  3222. - s, 0, c, 0,
  3223. 0, 0, 0, 1
  3224. );
  3225. return this;
  3226. },
  3227. makeRotationZ: function ( theta ) {
  3228. var c = Math.cos( theta ), s = Math.sin( theta );
  3229. this.set(
  3230. c, - s, 0, 0,
  3231. s, c, 0, 0,
  3232. 0, 0, 1, 0,
  3233. 0, 0, 0, 1
  3234. );
  3235. return this;
  3236. },
  3237. makeRotationAxis: function ( axis, angle ) {
  3238. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  3239. var c = Math.cos( angle );
  3240. var s = Math.sin( angle );
  3241. var t = 1 - c;
  3242. var x = axis.x, y = axis.y, z = axis.z;
  3243. var tx = t * x, ty = t * y;
  3244. this.set(
  3245. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  3246. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  3247. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  3248. 0, 0, 0, 1
  3249. );
  3250. return this;
  3251. },
  3252. makeScale: function ( x, y, z ) {
  3253. this.set(
  3254. x, 0, 0, 0,
  3255. 0, y, 0, 0,
  3256. 0, 0, z, 0,
  3257. 0, 0, 0, 1
  3258. );
  3259. return this;
  3260. },
  3261. compose: function ( position, quaternion, scale ) {
  3262. this.makeRotationFromQuaternion( quaternion );
  3263. this.scale( scale );
  3264. this.setPosition( position );
  3265. return this;
  3266. },
  3267. decompose: function () {
  3268. var vector, matrix;
  3269. return function ( position, quaternion, scale ) {
  3270. if ( vector === undefined ) vector = new THREE.Vector3();
  3271. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  3272. var te = this.elements;
  3273. var sx = vector.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  3274. var sy = vector.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  3275. var sz = vector.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  3276. // if determine is negative, we need to invert one scale
  3277. var det = this.determinant();
  3278. if ( det < 0 ) {
  3279. sx = - sx;
  3280. }
  3281. position.x = te[ 12 ];
  3282. position.y = te[ 13 ];
  3283. position.z = te[ 14 ];
  3284. // scale the rotation part
  3285. matrix.elements.set( this.elements ); // at this point matrix is incomplete so we can't use .copy()
  3286. var invSX = 1 / sx;
  3287. var invSY = 1 / sy;
  3288. var invSZ = 1 / sz;
  3289. matrix.elements[ 0 ] *= invSX;
  3290. matrix.elements[ 1 ] *= invSX;
  3291. matrix.elements[ 2 ] *= invSX;
  3292. matrix.elements[ 4 ] *= invSY;
  3293. matrix.elements[ 5 ] *= invSY;
  3294. matrix.elements[ 6 ] *= invSY;
  3295. matrix.elements[ 8 ] *= invSZ;
  3296. matrix.elements[ 9 ] *= invSZ;
  3297. matrix.elements[ 10 ] *= invSZ;
  3298. quaternion.setFromRotationMatrix( matrix );
  3299. scale.x = sx;
  3300. scale.y = sy;
  3301. scale.z = sz;
  3302. return this;
  3303. };
  3304. }(),
  3305. makeFrustum: function ( left, right, bottom, top, near, far ) {
  3306. var te = this.elements;
  3307. var x = 2 * near / ( right - left );
  3308. var y = 2 * near / ( top - bottom );
  3309. var a = ( right + left ) / ( right - left );
  3310. var b = ( top + bottom ) / ( top - bottom );
  3311. var c = - ( far + near ) / ( far - near );
  3312. var d = - 2 * far * near / ( far - near );
  3313. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  3314. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  3315. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  3316. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  3317. return this;
  3318. },
  3319. makePerspective: function ( fov, aspect, near, far ) {
  3320. var ymax = near * Math.tan( THREE.Math.degToRad( fov * 0.5 ) );
  3321. var ymin = - ymax;
  3322. var xmin = ymin * aspect;
  3323. var xmax = ymax * aspect;
  3324. return this.makeFrustum( xmin, xmax, ymin, ymax, near, far );
  3325. },
  3326. makeOrthographic: function ( left, right, top, bottom, near, far ) {
  3327. var te = this.elements;
  3328. var w = right - left;
  3329. var h = top - bottom;
  3330. var p = far - near;
  3331. var x = ( right + left ) / w;
  3332. var y = ( top + bottom ) / h;
  3333. var z = ( far + near ) / p;
  3334. te[ 0 ] = 2 / w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  3335. te[ 1 ] = 0; te[ 5 ] = 2 / h; te[ 9 ] = 0; te[ 13 ] = - y;
  3336. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 / p; te[ 14 ] = - z;
  3337. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  3338. return this;
  3339. },
  3340. equals: function ( matrix ) {
  3341. var te = this.elements;
  3342. var me = matrix.elements;
  3343. for ( var i = 0; i < 16; i ++ ) {
  3344. if ( te[ i ] !== me[ i ] ) return false;
  3345. }
  3346. return true;
  3347. },
  3348. fromArray: function ( array ) {
  3349. this.elements.set( array );
  3350. return this;
  3351. },
  3352. toArray: function () {
  3353. var te = this.elements;
  3354. return [
  3355. te[ 0 ], te[ 1 ], te[ 2 ], te[ 3 ],
  3356. te[ 4 ], te[ 5 ], te[ 6 ], te[ 7 ],
  3357. te[ 8 ], te[ 9 ], te[ 10 ], te[ 11 ],
  3358. te[ 12 ], te[ 13 ], te[ 14 ], te[ 15 ]
  3359. ];
  3360. }
  3361. };
  3362. // File:src/math/Ray.js
  3363. /**
  3364. * @author bhouston / http://clara.io
  3365. */
  3366. THREE.Ray = function ( origin, direction ) {
  3367. this.origin = ( origin !== undefined ) ? origin : new THREE.Vector3();
  3368. this.direction = ( direction !== undefined ) ? direction : new THREE.Vector3();
  3369. };
  3370. THREE.Ray.prototype = {
  3371. constructor: THREE.Ray,
  3372. set: function ( origin, direction ) {
  3373. this.origin.copy( origin );
  3374. this.direction.copy( direction );
  3375. return this;
  3376. },
  3377. clone: function () {
  3378. return new this.constructor().copy( this );
  3379. },
  3380. copy: function ( ray ) {
  3381. this.origin.copy( ray.origin );
  3382. this.direction.copy( ray.direction );
  3383. return this;
  3384. },
  3385. at: function ( t, optionalTarget ) {
  3386. var result = optionalTarget || new THREE.Vector3();
  3387. return result.copy( this.direction ).multiplyScalar( t ).add( this.origin );
  3388. },
  3389. recast: function () {
  3390. var v1 = new THREE.Vector3();
  3391. return function ( t ) {
  3392. this.origin.copy( this.at( t, v1 ) );
  3393. return this;
  3394. };
  3395. }(),
  3396. closestPointToPoint: function ( point, optionalTarget ) {
  3397. var result = optionalTarget || new THREE.Vector3();
  3398. result.subVectors( point, this.origin );
  3399. var directionDistance = result.dot( this.direction );
  3400. if ( directionDistance < 0 ) {
  3401. return result.copy( this.origin );
  3402. }
  3403. return result.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  3404. },
  3405. distanceToPoint: function ( point ) {
  3406. return Math.sqrt( this.distanceSqToPoint( point ) );
  3407. },
  3408. distanceSqToPoint: function () {
  3409. var v1 = new THREE.Vector3();
  3410. return function ( point ) {
  3411. var directionDistance = v1.subVectors( point, this.origin ).dot( this.direction );
  3412. // point behind the ray
  3413. if ( directionDistance < 0 ) {
  3414. return this.origin.distanceToSquared( point );
  3415. }
  3416. v1.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  3417. return v1.distanceToSquared( point );
  3418. };
  3419. }(),
  3420. distanceSqToSegment: function () {
  3421. var segCenter = new THREE.Vector3();
  3422. var segDir = new THREE.Vector3();
  3423. var diff = new THREE.Vector3();
  3424. return function ( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  3425. // from http://www.geometrictools.com/LibMathematics/Distance/Wm5DistRay3Segment3.cpp
  3426. // It returns the min distance between the ray and the segment
  3427. // defined by v0 and v1
  3428. // It can also set two optional targets :
  3429. // - The closest point on the ray
  3430. // - The closest point on the segment
  3431. segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  3432. segDir.copy( v1 ).sub( v0 ).normalize();
  3433. diff.copy( this.origin ).sub( segCenter );
  3434. var segExtent = v0.distanceTo( v1 ) * 0.5;
  3435. var a01 = - this.direction.dot( segDir );
  3436. var b0 = diff.dot( this.direction );
  3437. var b1 = - diff.dot( segDir );
  3438. var c = diff.lengthSq();
  3439. var det = Math.abs( 1 - a01 * a01 );
  3440. var s0, s1, sqrDist, extDet;
  3441. if ( det > 0 ) {
  3442. // The ray and segment are not parallel.
  3443. s0 = a01 * b1 - b0;
  3444. s1 = a01 * b0 - b1;
  3445. extDet = segExtent * det;
  3446. if ( s0 >= 0 ) {
  3447. if ( s1 >= - extDet ) {
  3448. if ( s1 <= extDet ) {
  3449. // region 0
  3450. // Minimum at interior points of ray and segment.
  3451. var invDet = 1 / det;
  3452. s0 *= invDet;
  3453. s1 *= invDet;
  3454. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  3455. } else {
  3456. // region 1
  3457. s1 = segExtent;
  3458. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3459. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3460. }
  3461. } else {
  3462. // region 5
  3463. s1 = - segExtent;
  3464. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3465. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3466. }
  3467. } else {
  3468. if ( s1 <= - extDet ) {
  3469. // region 4
  3470. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  3471. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3472. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3473. } else if ( s1 <= extDet ) {
  3474. // region 3
  3475. s0 = 0;
  3476. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3477. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  3478. } else {
  3479. // region 2
  3480. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  3481. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3482. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3483. }
  3484. }
  3485. } else {
  3486. // Ray and segment are parallel.
  3487. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  3488. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3489. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3490. }
  3491. if ( optionalPointOnRay ) {
  3492. optionalPointOnRay.copy( this.direction ).multiplyScalar( s0 ).add( this.origin );
  3493. }
  3494. if ( optionalPointOnSegment ) {
  3495. optionalPointOnSegment.copy( segDir ).multiplyScalar( s1 ).add( segCenter );
  3496. }
  3497. return sqrDist;
  3498. };
  3499. }(),
  3500. intersectSphere: function () {
  3501. // from http://www.scratchapixel.com/lessons/3d-basic-lessons/lesson-7-intersecting-simple-shapes/ray-sphere-intersection/
  3502. var v1 = new THREE.Vector3();
  3503. return function ( sphere, optionalTarget ) {
  3504. v1.subVectors( sphere.center, this.origin );
  3505. var tca = v1.dot( this.direction );
  3506. var d2 = v1.dot( v1 ) - tca * tca;
  3507. var radius2 = sphere.radius * sphere.radius;
  3508. if ( d2 > radius2 ) return null;
  3509. var thc = Math.sqrt( radius2 - d2 );
  3510. // t0 = first intersect point - entrance on front of sphere
  3511. var t0 = tca - thc;
  3512. // t1 = second intersect point - exit point on back of sphere
  3513. var t1 = tca + thc;
  3514. // test to see if both t0 and t1 are behind the ray - if so, return null
  3515. if ( t0 < 0 && t1 < 0 ) return null;
  3516. // test to see if t0 is behind the ray:
  3517. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  3518. // in order to always return an intersect point that is in front of the ray.
  3519. if ( t0 < 0 ) return this.at( t1, optionalTarget );
  3520. // else t0 is in front of the ray, so return the first collision point scaled by t0
  3521. return this.at( t0, optionalTarget );
  3522. }
  3523. }(),
  3524. intersectsSphere: function ( sphere ) {
  3525. return this.distanceToPoint( sphere.center ) <= sphere.radius;
  3526. },
  3527. distanceToPlane: function ( plane ) {
  3528. var denominator = plane.normal.dot( this.direction );
  3529. if ( denominator === 0 ) {
  3530. // line is coplanar, return origin
  3531. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  3532. return 0;
  3533. }
  3534. // Null is preferable to undefined since undefined means.... it is undefined
  3535. return null;
  3536. }
  3537. var t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  3538. // Return if the ray never intersects the plane
  3539. return t >= 0 ? t : null;
  3540. },
  3541. intersectPlane: function ( plane, optionalTarget ) {
  3542. var t = this.distanceToPlane( plane );
  3543. if ( t === null ) {
  3544. return null;
  3545. }
  3546. return this.at( t, optionalTarget );
  3547. },
  3548. intersectsPlane: function ( plane ) {
  3549. // check if the ray lies on the plane first
  3550. var distToPoint = plane.distanceToPoint( this.origin );
  3551. if ( distToPoint === 0 ) {
  3552. return true;
  3553. }
  3554. var denominator = plane.normal.dot( this.direction );
  3555. if ( denominator * distToPoint < 0 ) {
  3556. return true;
  3557. }
  3558. // ray origin is behind the plane (and is pointing behind it)
  3559. return false;
  3560. },
  3561. intersectBox: function ( box, optionalTarget ) {
  3562. // http://www.scratchapixel.com/lessons/3d-basic-lessons/lesson-7-intersecting-simple-shapes/ray-box-intersection/
  3563. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  3564. var invdirx = 1 / this.direction.x,
  3565. invdiry = 1 / this.direction.y,
  3566. invdirz = 1 / this.direction.z;
  3567. var origin = this.origin;
  3568. if ( invdirx >= 0 ) {
  3569. tmin = ( box.min.x - origin.x ) * invdirx;
  3570. tmax = ( box.max.x - origin.x ) * invdirx;
  3571. } else {
  3572. tmin = ( box.max.x - origin.x ) * invdirx;
  3573. tmax = ( box.min.x - origin.x ) * invdirx;
  3574. }
  3575. if ( invdiry >= 0 ) {
  3576. tymin = ( box.min.y - origin.y ) * invdiry;
  3577. tymax = ( box.max.y - origin.y ) * invdiry;
  3578. } else {
  3579. tymin = ( box.max.y - origin.y ) * invdiry;
  3580. tymax = ( box.min.y - origin.y ) * invdiry;
  3581. }
  3582. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  3583. // These lines also handle the case where tmin or tmax is NaN
  3584. // (result of 0 * Infinity). x !== x returns true if x is NaN
  3585. if ( tymin > tmin || tmin !== tmin ) tmin = tymin;
  3586. if ( tymax < tmax || tmax !== tmax ) tmax = tymax;
  3587. if ( invdirz >= 0 ) {
  3588. tzmin = ( box.min.z - origin.z ) * invdirz;
  3589. tzmax = ( box.max.z - origin.z ) * invdirz;
  3590. } else {
  3591. tzmin = ( box.max.z - origin.z ) * invdirz;
  3592. tzmax = ( box.min.z - origin.z ) * invdirz;
  3593. }
  3594. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  3595. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  3596. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  3597. //return point closest to the ray (positive side)
  3598. if ( tmax < 0 ) return null;
  3599. return this.at( tmin >= 0 ? tmin : tmax, optionalTarget );
  3600. },
  3601. intersectsBox: ( function () {
  3602. var v = new THREE.Vector3();
  3603. return function ( box ) {
  3604. return this.intersectBox( box, v ) !== null;
  3605. };
  3606. } )(),
  3607. intersectTriangle: function () {
  3608. // Compute the offset origin, edges, and normal.
  3609. var diff = new THREE.Vector3();
  3610. var edge1 = new THREE.Vector3();
  3611. var edge2 = new THREE.Vector3();
  3612. var normal = new THREE.Vector3();
  3613. return function ( a, b, c, backfaceCulling, optionalTarget ) {
  3614. // from http://www.geometrictools.com/LibMathematics/Intersection/Wm5IntrRay3Triangle3.cpp
  3615. edge1.subVectors( b, a );
  3616. edge2.subVectors( c, a );
  3617. normal.crossVectors( edge1, edge2 );
  3618. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  3619. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  3620. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  3621. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  3622. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  3623. var DdN = this.direction.dot( normal );
  3624. var sign;
  3625. if ( DdN > 0 ) {
  3626. if ( backfaceCulling ) return null;
  3627. sign = 1;
  3628. } else if ( DdN < 0 ) {
  3629. sign = - 1;
  3630. DdN = - DdN;
  3631. } else {
  3632. return null;
  3633. }
  3634. diff.subVectors( this.origin, a );
  3635. var DdQxE2 = sign * this.direction.dot( edge2.crossVectors( diff, edge2 ) );
  3636. // b1 < 0, no intersection
  3637. if ( DdQxE2 < 0 ) {
  3638. return null;
  3639. }
  3640. var DdE1xQ = sign * this.direction.dot( edge1.cross( diff ) );
  3641. // b2 < 0, no intersection
  3642. if ( DdE1xQ < 0 ) {
  3643. return null;
  3644. }
  3645. // b1+b2 > 1, no intersection
  3646. if ( DdQxE2 + DdE1xQ > DdN ) {
  3647. return null;
  3648. }
  3649. // Line intersects triangle, check if ray does.
  3650. var QdN = - sign * diff.dot( normal );
  3651. // t < 0, no intersection
  3652. if ( QdN < 0 ) {
  3653. return null;
  3654. }
  3655. // Ray intersects triangle.
  3656. return this.at( QdN / DdN, optionalTarget );
  3657. };
  3658. }(),
  3659. applyMatrix4: function ( matrix4 ) {
  3660. this.direction.add( this.origin ).applyMatrix4( matrix4 );
  3661. this.origin.applyMatrix4( matrix4 );
  3662. this.direction.sub( this.origin );
  3663. this.direction.normalize();
  3664. return this;
  3665. },
  3666. equals: function ( ray ) {
  3667. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  3668. }
  3669. };
  3670. // File:src/math/Sphere.js
  3671. /**
  3672. * @author bhouston / http://clara.io
  3673. * @author mrdoob / http://mrdoob.com/
  3674. */
  3675. THREE.Sphere = function ( center, radius ) {
  3676. this.center = ( center !== undefined ) ? center : new THREE.Vector3();
  3677. this.radius = ( radius !== undefined ) ? radius : 0;
  3678. };
  3679. THREE.Sphere.prototype = {
  3680. constructor: THREE.Sphere,
  3681. set: function ( center, radius ) {
  3682. this.center.copy( center );
  3683. this.radius = radius;
  3684. return this;
  3685. },
  3686. setFromPoints: function () {
  3687. var box = new THREE.Box3();
  3688. return function ( points, optionalCenter ) {
  3689. var center = this.center;
  3690. if ( optionalCenter !== undefined ) {
  3691. center.copy( optionalCenter );
  3692. } else {
  3693. box.setFromPoints( points ).center( center );
  3694. }
  3695. var maxRadiusSq = 0;
  3696. for ( var i = 0, il = points.length; i < il; i ++ ) {
  3697. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  3698. }
  3699. this.radius = Math.sqrt( maxRadiusSq );
  3700. return this;
  3701. };
  3702. }(),
  3703. clone: function () {
  3704. return new this.constructor().copy( this );
  3705. },
  3706. copy: function ( sphere ) {
  3707. this.center.copy( sphere.center );
  3708. this.radius = sphere.radius;
  3709. return this;
  3710. },
  3711. empty: function () {
  3712. return ( this.radius <= 0 );
  3713. },
  3714. containsPoint: function ( point ) {
  3715. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  3716. },
  3717. distanceToPoint: function ( point ) {
  3718. return ( point.distanceTo( this.center ) - this.radius );
  3719. },
  3720. intersectsSphere: function ( sphere ) {
  3721. var radiusSum = this.radius + sphere.radius;
  3722. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  3723. },
  3724. intersectsBox: function ( box ) {
  3725. return box.intersectsSphere( this );
  3726. },
  3727. intersectsPlane: function ( plane ) {
  3728. // We use the following equation to compute the signed distance from
  3729. // the center of the sphere to the plane.
  3730. //
  3731. // distance = q * n - d
  3732. //
  3733. // If this distance is greater than the radius of the sphere,
  3734. // then there is no intersection.
  3735. return Math.abs( this.center.dot( plane.normal ) - plane.constant ) <= this.radius;
  3736. },
  3737. clampPoint: function ( point, optionalTarget ) {
  3738. var deltaLengthSq = this.center.distanceToSquared( point );
  3739. var result = optionalTarget || new THREE.Vector3();
  3740. result.copy( point );
  3741. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  3742. result.sub( this.center ).normalize();
  3743. result.multiplyScalar( this.radius ).add( this.center );
  3744. }
  3745. return result;
  3746. },
  3747. getBoundingBox: function ( optionalTarget ) {
  3748. var box = optionalTarget || new THREE.Box3();
  3749. box.set( this.center, this.center );
  3750. box.expandByScalar( this.radius );
  3751. return box;
  3752. },
  3753. applyMatrix4: function ( matrix ) {
  3754. this.center.applyMatrix4( matrix );
  3755. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  3756. return this;
  3757. },
  3758. translate: function ( offset ) {
  3759. this.center.add( offset );
  3760. return this;
  3761. },
  3762. equals: function ( sphere ) {
  3763. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  3764. }
  3765. };
  3766. // File:src/math/Frustum.js
  3767. /**
  3768. * @author mrdoob / http://mrdoob.com/
  3769. * @author alteredq / http://alteredqualia.com/
  3770. * @author bhouston / http://clara.io
  3771. */
  3772. THREE.Frustum = function ( p0, p1, p2, p3, p4, p5 ) {
  3773. this.planes = [
  3774. ( p0 !== undefined ) ? p0 : new THREE.Plane(),
  3775. ( p1 !== undefined ) ? p1 : new THREE.Plane(),
  3776. ( p2 !== undefined ) ? p2 : new THREE.Plane(),
  3777. ( p3 !== undefined ) ? p3 : new THREE.Plane(),
  3778. ( p4 !== undefined ) ? p4 : new THREE.Plane(),
  3779. ( p5 !== undefined ) ? p5 : new THREE.Plane()
  3780. ];
  3781. };
  3782. THREE.Frustum.prototype = {
  3783. constructor: THREE.Frustum,
  3784. set: function ( p0, p1, p2, p3, p4, p5 ) {
  3785. var planes = this.planes;
  3786. planes[ 0 ].copy( p0 );
  3787. planes[ 1 ].copy( p1 );
  3788. planes[ 2 ].copy( p2 );
  3789. planes[ 3 ].copy( p3 );
  3790. planes[ 4 ].copy( p4 );
  3791. planes[ 5 ].copy( p5 );
  3792. return this;
  3793. },
  3794. clone: function () {
  3795. return new this.constructor().copy( this );
  3796. },
  3797. copy: function ( frustum ) {
  3798. var planes = this.planes;
  3799. for ( var i = 0; i < 6; i ++ ) {
  3800. planes[ i ].copy( frustum.planes[ i ] );
  3801. }
  3802. return this;
  3803. },
  3804. setFromMatrix: function ( m ) {
  3805. var planes = this.planes;
  3806. var me = m.elements;
  3807. var me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  3808. var me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  3809. var me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  3810. var me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  3811. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  3812. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  3813. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  3814. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  3815. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  3816. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  3817. return this;
  3818. },
  3819. intersectsObject: function () {
  3820. var sphere = new THREE.Sphere();
  3821. return function ( object ) {
  3822. var geometry = object.geometry;
  3823. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  3824. sphere.copy( geometry.boundingSphere );
  3825. sphere.applyMatrix4( object.matrixWorld );
  3826. return this.intersectsSphere( sphere );
  3827. };
  3828. }(),
  3829. intersectsSphere: function ( sphere ) {
  3830. var planes = this.planes;
  3831. var center = sphere.center;
  3832. var negRadius = - sphere.radius;
  3833. for ( var i = 0; i < 6; i ++ ) {
  3834. var distance = planes[ i ].distanceToPoint( center );
  3835. if ( distance < negRadius ) {
  3836. return false;
  3837. }
  3838. }
  3839. return true;
  3840. },
  3841. intersectsBox: function () {
  3842. var p1 = new THREE.Vector3(),
  3843. p2 = new THREE.Vector3();
  3844. return function ( box ) {
  3845. var planes = this.planes;
  3846. for ( var i = 0; i < 6 ; i ++ ) {
  3847. var plane = planes[ i ];
  3848. p1.x = plane.normal.x > 0 ? box.min.x : box.max.x;
  3849. p2.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  3850. p1.y = plane.normal.y > 0 ? box.min.y : box.max.y;
  3851. p2.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  3852. p1.z = plane.normal.z > 0 ? box.min.z : box.max.z;
  3853. p2.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  3854. var d1 = plane.distanceToPoint( p1 );
  3855. var d2 = plane.distanceToPoint( p2 );
  3856. // if both outside plane, no intersection
  3857. if ( d1 < 0 && d2 < 0 ) {
  3858. return false;
  3859. }
  3860. }
  3861. return true;
  3862. };
  3863. }(),
  3864. containsPoint: function ( point ) {
  3865. var planes = this.planes;
  3866. for ( var i = 0; i < 6; i ++ ) {
  3867. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  3868. return false;
  3869. }
  3870. }
  3871. return true;
  3872. }
  3873. };
  3874. // File:src/math/Plane.js
  3875. /**
  3876. * @author bhouston / http://clara.io
  3877. */
  3878. THREE.Plane = function ( normal, constant ) {
  3879. this.normal = ( normal !== undefined ) ? normal : new THREE.Vector3( 1, 0, 0 );
  3880. this.constant = ( constant !== undefined ) ? constant : 0;
  3881. };
  3882. THREE.Plane.prototype = {
  3883. constructor: THREE.Plane,
  3884. set: function ( normal, constant ) {
  3885. this.normal.copy( normal );
  3886. this.constant = constant;
  3887. return this;
  3888. },
  3889. setComponents: function ( x, y, z, w ) {
  3890. this.normal.set( x, y, z );
  3891. this.constant = w;
  3892. return this;
  3893. },
  3894. setFromNormalAndCoplanarPoint: function ( normal, point ) {
  3895. this.normal.copy( normal );
  3896. this.constant = - point.dot( this.normal ); // must be this.normal, not normal, as this.normal is normalized
  3897. return this;
  3898. },
  3899. setFromCoplanarPoints: function () {
  3900. var v1 = new THREE.Vector3();
  3901. var v2 = new THREE.Vector3();
  3902. return function ( a, b, c ) {
  3903. var normal = v1.subVectors( c, b ).cross( v2.subVectors( a, b ) ).normalize();
  3904. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  3905. this.setFromNormalAndCoplanarPoint( normal, a );
  3906. return this;
  3907. };
  3908. }(),
  3909. clone: function () {
  3910. return new this.constructor().copy( this );
  3911. },
  3912. copy: function ( plane ) {
  3913. this.normal.copy( plane.normal );
  3914. this.constant = plane.constant;
  3915. return this;
  3916. },
  3917. normalize: function () {
  3918. // Note: will lead to a divide by zero if the plane is invalid.
  3919. var inverseNormalLength = 1.0 / this.normal.length();
  3920. this.normal.multiplyScalar( inverseNormalLength );
  3921. this.constant *= inverseNormalLength;
  3922. return this;
  3923. },
  3924. negate: function () {
  3925. this.constant *= - 1;
  3926. this.normal.negate();
  3927. return this;
  3928. },
  3929. distanceToPoint: function ( point ) {
  3930. return this.normal.dot( point ) + this.constant;
  3931. },
  3932. distanceToSphere: function ( sphere ) {
  3933. return this.distanceToPoint( sphere.center ) - sphere.radius;
  3934. },
  3935. projectPoint: function ( point, optionalTarget ) {
  3936. return this.orthoPoint( point, optionalTarget ).sub( point ).negate();
  3937. },
  3938. orthoPoint: function ( point, optionalTarget ) {
  3939. var perpendicularMagnitude = this.distanceToPoint( point );
  3940. var result = optionalTarget || new THREE.Vector3();
  3941. return result.copy( this.normal ).multiplyScalar( perpendicularMagnitude );
  3942. },
  3943. intersectLine: function () {
  3944. var v1 = new THREE.Vector3();
  3945. return function ( line, optionalTarget ) {
  3946. var result = optionalTarget || new THREE.Vector3();
  3947. var direction = line.delta( v1 );
  3948. var denominator = this.normal.dot( direction );
  3949. if ( denominator === 0 ) {
  3950. // line is coplanar, return origin
  3951. if ( this.distanceToPoint( line.start ) === 0 ) {
  3952. return result.copy( line.start );
  3953. }
  3954. // Unsure if this is the correct method to handle this case.
  3955. return undefined;
  3956. }
  3957. var t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  3958. if ( t < 0 || t > 1 ) {
  3959. return undefined;
  3960. }
  3961. return result.copy( direction ).multiplyScalar( t ).add( line.start );
  3962. };
  3963. }(),
  3964. intersectsLine: function ( line ) {
  3965. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  3966. var startSign = this.distanceToPoint( line.start );
  3967. var endSign = this.distanceToPoint( line.end );
  3968. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  3969. },
  3970. intersectsBox: function ( box ) {
  3971. return box.intersectsPlane( this );
  3972. },
  3973. intersectsSphere: function ( sphere ) {
  3974. return sphere.intersectsPlane( this );
  3975. },
  3976. coplanarPoint: function ( optionalTarget ) {
  3977. var result = optionalTarget || new THREE.Vector3();
  3978. return result.copy( this.normal ).multiplyScalar( - this.constant );
  3979. },
  3980. applyMatrix4: function () {
  3981. var v1 = new THREE.Vector3();
  3982. var v2 = new THREE.Vector3();
  3983. var m1 = new THREE.Matrix3();
  3984. return function ( matrix, optionalNormalMatrix ) {
  3985. // compute new normal based on theory here:
  3986. // http://www.songho.ca/opengl/gl_normaltransform.html
  3987. var normalMatrix = optionalNormalMatrix || m1.getNormalMatrix( matrix );
  3988. var newNormal = v1.copy( this.normal ).applyMatrix3( normalMatrix );
  3989. var newCoplanarPoint = this.coplanarPoint( v2 );
  3990. newCoplanarPoint.applyMatrix4( matrix );
  3991. this.setFromNormalAndCoplanarPoint( newNormal, newCoplanarPoint );
  3992. return this;
  3993. };
  3994. }(),
  3995. translate: function ( offset ) {
  3996. this.constant = this.constant - offset.dot( this.normal );
  3997. return this;
  3998. },
  3999. equals: function ( plane ) {
  4000. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  4001. }
  4002. };
  4003. // File:src/math/Math.js
  4004. /**
  4005. * @author alteredq / http://alteredqualia.com/
  4006. * @author mrdoob / http://mrdoob.com/
  4007. */
  4008. THREE.Math = {
  4009. generateUUID: function () {
  4010. // http://www.broofa.com/Tools/Math.uuid.htm
  4011. var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split( '' );
  4012. var uuid = new Array( 36 );
  4013. var rnd = 0, r;
  4014. return function () {
  4015. for ( var i = 0; i < 36; i ++ ) {
  4016. if ( i === 8 || i === 13 || i === 18 || i === 23 ) {
  4017. uuid[ i ] = '-';
  4018. } else if ( i === 14 ) {
  4019. uuid[ i ] = '4';
  4020. } else {
  4021. if ( rnd <= 0x02 ) rnd = 0x2000000 + ( Math.random() * 0x1000000 ) | 0;
  4022. r = rnd & 0xf;
  4023. rnd = rnd >> 4;
  4024. uuid[ i ] = chars[ ( i === 19 ) ? ( r & 0x3 ) | 0x8 : r ];
  4025. }
  4026. }
  4027. return uuid.join( '' );
  4028. };
  4029. }(),
  4030. clamp: function ( value, min, max ) {
  4031. return Math.max( min, Math.min( max, value ) );
  4032. },
  4033. // compute euclidian modulo of m % n
  4034. // https://en.wikipedia.org/wiki/Modulo_operation
  4035. euclideanModulo: function ( n, m ) {
  4036. return ( ( n % m ) + m ) % m;
  4037. },
  4038. // Linear mapping from range <a1, a2> to range <b1, b2>
  4039. mapLinear: function ( x, a1, a2, b1, b2 ) {
  4040. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  4041. },
  4042. // http://en.wikipedia.org/wiki/Smoothstep
  4043. smoothstep: function ( x, min, max ) {
  4044. if ( x <= min ) return 0;
  4045. if ( x >= max ) return 1;
  4046. x = ( x - min ) / ( max - min );
  4047. return x * x * ( 3 - 2 * x );
  4048. },
  4049. smootherstep: function ( x, min, max ) {
  4050. if ( x <= min ) return 0;
  4051. if ( x >= max ) return 1;
  4052. x = ( x - min ) / ( max - min );
  4053. return x * x * x * ( x * ( x * 6 - 15 ) + 10 );
  4054. },
  4055. // Random float from <0, 1> with 16 bits of randomness
  4056. // (standard Math.random() creates repetitive patterns when applied over larger space)
  4057. random16: function () {
  4058. return ( 65280 * Math.random() + 255 * Math.random() ) / 65535;
  4059. },
  4060. // Random integer from <low, high> interval
  4061. randInt: function ( low, high ) {
  4062. return low + Math.floor( Math.random() * ( high - low + 1 ) );
  4063. },
  4064. // Random float from <low, high> interval
  4065. randFloat: function ( low, high ) {
  4066. return low + Math.random() * ( high - low );
  4067. },
  4068. // Random float from <-range/2, range/2> interval
  4069. randFloatSpread: function ( range ) {
  4070. return range * ( 0.5 - Math.random() );
  4071. },
  4072. degToRad: function () {
  4073. var degreeToRadiansFactor = Math.PI / 180;
  4074. return function ( degrees ) {
  4075. return degrees * degreeToRadiansFactor;
  4076. };
  4077. }(),
  4078. radToDeg: function () {
  4079. var radianToDegreesFactor = 180 / Math.PI;
  4080. return function ( radians ) {
  4081. return radians * radianToDegreesFactor;
  4082. };
  4083. }(),
  4084. isPowerOfTwo: function ( value ) {
  4085. return ( value & ( value - 1 ) ) === 0 && value !== 0;
  4086. },
  4087. nearestPowerOfTwo: function ( value ) {
  4088. return Math.pow( 2, Math.round( Math.log( value ) / Math.LN2 ) );
  4089. },
  4090. nextPowerOfTwo: function ( value ) {
  4091. value --;
  4092. value |= value >> 1;
  4093. value |= value >> 2;
  4094. value |= value >> 4;
  4095. value |= value >> 8;
  4096. value |= value >> 16;
  4097. value ++;
  4098. return value;
  4099. }
  4100. };
  4101. // File:src/math/Spline.js
  4102. /**
  4103. * Spline from Tween.js, slightly optimized (and trashed)
  4104. * http://sole.github.com/tween.js/examples/05_spline.html
  4105. *
  4106. * @author mrdoob / http://mrdoob.com/
  4107. * @author alteredq / http://alteredqualia.com/
  4108. */
  4109. THREE.Spline = function ( points ) {
  4110. this.points = points;
  4111. var c = [], v3 = { x: 0, y: 0, z: 0 },
  4112. point, intPoint, weight, w2, w3,
  4113. pa, pb, pc, pd;
  4114. this.initFromArray = function ( a ) {
  4115. this.points = [];
  4116. for ( var i = 0; i < a.length; i ++ ) {
  4117. this.points[ i ] = { x: a[ i ][ 0 ], y: a[ i ][ 1 ], z: a[ i ][ 2 ] };
  4118. }
  4119. };
  4120. this.getPoint = function ( k ) {
  4121. point = ( this.points.length - 1 ) * k;
  4122. intPoint = Math.floor( point );
  4123. weight = point - intPoint;
  4124. c[ 0 ] = intPoint === 0 ? intPoint : intPoint - 1;
  4125. c[ 1 ] = intPoint;
  4126. c[ 2 ] = intPoint > this.points.length - 2 ? this.points.length - 1 : intPoint + 1;
  4127. c[ 3 ] = intPoint > this.points.length - 3 ? this.points.length - 1 : intPoint + 2;
  4128. pa = this.points[ c[ 0 ] ];
  4129. pb = this.points[ c[ 1 ] ];
  4130. pc = this.points[ c[ 2 ] ];
  4131. pd = this.points[ c[ 3 ] ];
  4132. w2 = weight * weight;
  4133. w3 = weight * w2;
  4134. v3.x = interpolate( pa.x, pb.x, pc.x, pd.x, weight, w2, w3 );
  4135. v3.y = interpolate( pa.y, pb.y, pc.y, pd.y, weight, w2, w3 );
  4136. v3.z = interpolate( pa.z, pb.z, pc.z, pd.z, weight, w2, w3 );
  4137. return v3;
  4138. };
  4139. this.getControlPointsArray = function () {
  4140. var i, p, l = this.points.length,
  4141. coords = [];
  4142. for ( i = 0; i < l; i ++ ) {
  4143. p = this.points[ i ];
  4144. coords[ i ] = [ p.x, p.y, p.z ];
  4145. }
  4146. return coords;
  4147. };
  4148. // approximate length by summing linear segments
  4149. this.getLength = function ( nSubDivisions ) {
  4150. var i, index, nSamples, position,
  4151. point = 0, intPoint = 0, oldIntPoint = 0,
  4152. oldPosition = new THREE.Vector3(),
  4153. tmpVec = new THREE.Vector3(),
  4154. chunkLengths = [],
  4155. totalLength = 0;
  4156. // first point has 0 length
  4157. chunkLengths[ 0 ] = 0;
  4158. if ( ! nSubDivisions ) nSubDivisions = 100;
  4159. nSamples = this.points.length * nSubDivisions;
  4160. oldPosition.copy( this.points[ 0 ] );
  4161. for ( i = 1; i < nSamples; i ++ ) {
  4162. index = i / nSamples;
  4163. position = this.getPoint( index );
  4164. tmpVec.copy( position );
  4165. totalLength += tmpVec.distanceTo( oldPosition );
  4166. oldPosition.copy( position );
  4167. point = ( this.points.length - 1 ) * index;
  4168. intPoint = Math.floor( point );
  4169. if ( intPoint !== oldIntPoint ) {
  4170. chunkLengths[ intPoint ] = totalLength;
  4171. oldIntPoint = intPoint;
  4172. }
  4173. }
  4174. // last point ends with total length
  4175. chunkLengths[ chunkLengths.length ] = totalLength;
  4176. return { chunks: chunkLengths, total: totalLength };
  4177. };
  4178. this.reparametrizeByArcLength = function ( samplingCoef ) {
  4179. var i, j,
  4180. index, indexCurrent, indexNext,
  4181. realDistance,
  4182. sampling, position,
  4183. newpoints = [],
  4184. tmpVec = new THREE.Vector3(),
  4185. sl = this.getLength();
  4186. newpoints.push( tmpVec.copy( this.points[ 0 ] ).clone() );
  4187. for ( i = 1; i < this.points.length; i ++ ) {
  4188. //tmpVec.copy( this.points[ i - 1 ] );
  4189. //linearDistance = tmpVec.distanceTo( this.points[ i ] );
  4190. realDistance = sl.chunks[ i ] - sl.chunks[ i - 1 ];
  4191. sampling = Math.ceil( samplingCoef * realDistance / sl.total );
  4192. indexCurrent = ( i - 1 ) / ( this.points.length - 1 );
  4193. indexNext = i / ( this.points.length - 1 );
  4194. for ( j = 1; j < sampling - 1; j ++ ) {
  4195. index = indexCurrent + j * ( 1 / sampling ) * ( indexNext - indexCurrent );
  4196. position = this.getPoint( index );
  4197. newpoints.push( tmpVec.copy( position ).clone() );
  4198. }
  4199. newpoints.push( tmpVec.copy( this.points[ i ] ).clone() );
  4200. }
  4201. this.points = newpoints;
  4202. };
  4203. // Catmull-Rom
  4204. function interpolate( p0, p1, p2, p3, t, t2, t3 ) {
  4205. var v0 = ( p2 - p0 ) * 0.5,
  4206. v1 = ( p3 - p1 ) * 0.5;
  4207. return ( 2 * ( p1 - p2 ) + v0 + v1 ) * t3 + ( - 3 * ( p1 - p2 ) - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  4208. }
  4209. };
  4210. // File:src/math/Triangle.js
  4211. /**
  4212. * @author bhouston / http://clara.io
  4213. * @author mrdoob / http://mrdoob.com/
  4214. */
  4215. THREE.Triangle = function ( a, b, c ) {
  4216. this.a = ( a !== undefined ) ? a : new THREE.Vector3();
  4217. this.b = ( b !== undefined ) ? b : new THREE.Vector3();
  4218. this.c = ( c !== undefined ) ? c : new THREE.Vector3();
  4219. };
  4220. THREE.Triangle.normal = function () {
  4221. var v0 = new THREE.Vector3();
  4222. return function ( a, b, c, optionalTarget ) {
  4223. var result = optionalTarget || new THREE.Vector3();
  4224. result.subVectors( c, b );
  4225. v0.subVectors( a, b );
  4226. result.cross( v0 );
  4227. var resultLengthSq = result.lengthSq();
  4228. if ( resultLengthSq > 0 ) {
  4229. return result.multiplyScalar( 1 / Math.sqrt( resultLengthSq ) );
  4230. }
  4231. return result.set( 0, 0, 0 );
  4232. };
  4233. }();
  4234. // static/instance method to calculate barycentric coordinates
  4235. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  4236. THREE.Triangle.barycoordFromPoint = function () {
  4237. var v0 = new THREE.Vector3();
  4238. var v1 = new THREE.Vector3();
  4239. var v2 = new THREE.Vector3();
  4240. return function ( point, a, b, c, optionalTarget ) {
  4241. v0.subVectors( c, a );
  4242. v1.subVectors( b, a );
  4243. v2.subVectors( point, a );
  4244. var dot00 = v0.dot( v0 );
  4245. var dot01 = v0.dot( v1 );
  4246. var dot02 = v0.dot( v2 );
  4247. var dot11 = v1.dot( v1 );
  4248. var dot12 = v1.dot( v2 );
  4249. var denom = ( dot00 * dot11 - dot01 * dot01 );
  4250. var result = optionalTarget || new THREE.Vector3();
  4251. // collinear or singular triangle
  4252. if ( denom === 0 ) {
  4253. // arbitrary location outside of triangle?
  4254. // not sure if this is the best idea, maybe should be returning undefined
  4255. return result.set( - 2, - 1, - 1 );
  4256. }
  4257. var invDenom = 1 / denom;
  4258. var u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  4259. var v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  4260. // barycentric coordinates must always sum to 1
  4261. return result.set( 1 - u - v, v, u );
  4262. };
  4263. }();
  4264. THREE.Triangle.containsPoint = function () {
  4265. var v1 = new THREE.Vector3();
  4266. return function ( point, a, b, c ) {
  4267. var result = THREE.Triangle.barycoordFromPoint( point, a, b, c, v1 );
  4268. return ( result.x >= 0 ) && ( result.y >= 0 ) && ( ( result.x + result.y ) <= 1 );
  4269. };
  4270. }();
  4271. THREE.Triangle.prototype = {
  4272. constructor: THREE.Triangle,
  4273. set: function ( a, b, c ) {
  4274. this.a.copy( a );
  4275. this.b.copy( b );
  4276. this.c.copy( c );
  4277. return this;
  4278. },
  4279. setFromPointsAndIndices: function ( points, i0, i1, i2 ) {
  4280. this.a.copy( points[ i0 ] );
  4281. this.b.copy( points[ i1 ] );
  4282. this.c.copy( points[ i2 ] );
  4283. return this;
  4284. },
  4285. clone: function () {
  4286. return new this.constructor().copy( this );
  4287. },
  4288. copy: function ( triangle ) {
  4289. this.a.copy( triangle.a );
  4290. this.b.copy( triangle.b );
  4291. this.c.copy( triangle.c );
  4292. return this;
  4293. },
  4294. area: function () {
  4295. var v0 = new THREE.Vector3();
  4296. var v1 = new THREE.Vector3();
  4297. return function () {
  4298. v0.subVectors( this.c, this.b );
  4299. v1.subVectors( this.a, this.b );
  4300. return v0.cross( v1 ).length() * 0.5;
  4301. };
  4302. }(),
  4303. midpoint: function ( optionalTarget ) {
  4304. var result = optionalTarget || new THREE.Vector3();
  4305. return result.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  4306. },
  4307. normal: function ( optionalTarget ) {
  4308. return THREE.Triangle.normal( this.a, this.b, this.c, optionalTarget );
  4309. },
  4310. plane: function ( optionalTarget ) {
  4311. var result = optionalTarget || new THREE.Plane();
  4312. return result.setFromCoplanarPoints( this.a, this.b, this.c );
  4313. },
  4314. barycoordFromPoint: function ( point, optionalTarget ) {
  4315. return THREE.Triangle.barycoordFromPoint( point, this.a, this.b, this.c, optionalTarget );
  4316. },
  4317. containsPoint: function ( point ) {
  4318. return THREE.Triangle.containsPoint( point, this.a, this.b, this.c );
  4319. },
  4320. equals: function ( triangle ) {
  4321. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  4322. }
  4323. };
  4324. // File:src/math/Interpolant.js
  4325. /**
  4326. * Abstract base class of interpolants over parametric samples.
  4327. *
  4328. * The parameter domain is one dimensional, typically the time or a path
  4329. * along a curve defined by the data.
  4330. *
  4331. * The sample values can have any dimensionality and derived classes may
  4332. * apply special interpretations to the data.
  4333. *
  4334. * This class provides the interval seek in a Template Method, deferring
  4335. * the actual interpolation to derived classes.
  4336. *
  4337. * Time complexity is O(1) for linear access crossing at most two points
  4338. * and O(log N) for random access, where N is the number of positions.
  4339. *
  4340. * References:
  4341. *
  4342. * http://www.oodesign.com/template-method-pattern.html
  4343. *
  4344. * @author tschw
  4345. */
  4346. THREE.Interpolant = function(
  4347. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4348. this.parameterPositions = parameterPositions;
  4349. this._cachedIndex = 0;
  4350. this.resultBuffer = resultBuffer !== undefined ?
  4351. resultBuffer : new sampleValues.constructor( sampleSize );
  4352. this.sampleValues = sampleValues;
  4353. this.valueSize = sampleSize;
  4354. };
  4355. THREE.Interpolant.prototype = {
  4356. constructor: THREE.Intepolant,
  4357. evaluate: function( t ) {
  4358. var pp = this.parameterPositions,
  4359. i1 = this._cachedIndex,
  4360. t1 = pp[ i1 ],
  4361. t0 = pp[ i1 - 1 ];
  4362. validate_interval: {
  4363. seek: {
  4364. var right;
  4365. linear_scan: {
  4366. //- See http://jsperf.com/comparison-to-undefined/3
  4367. //- slower code:
  4368. //-
  4369. //- if ( t >= t1 || t1 === undefined ) {
  4370. forward_scan: if ( ! ( t < t1 ) ) {
  4371. for ( var giveUpAt = i1 + 2; ;) {
  4372. if ( t1 === undefined ) {
  4373. if ( t < t0 ) break forward_scan;
  4374. // after end
  4375. i1 = pp.length;
  4376. this._cachedIndex = i1;
  4377. return this.afterEnd_( i1 - 1, t, t0 );
  4378. }
  4379. if ( i1 === giveUpAt ) break; // this loop
  4380. t0 = t1;
  4381. t1 = pp[ ++ i1 ];
  4382. if ( t < t1 ) {
  4383. // we have arrived at the sought interval
  4384. break seek;
  4385. }
  4386. }
  4387. // prepare binary search on the right side of the index
  4388. right = pp.length;
  4389. break linear_scan;
  4390. }
  4391. //- slower code:
  4392. //- if ( t < t0 || t0 === undefined ) {
  4393. if ( ! ( t >= t0 ) ) {
  4394. // looping?
  4395. var t1global = pp[ 1 ];
  4396. if ( t < t1global ) {
  4397. i1 = 2; // + 1, using the scan for the details
  4398. t0 = t1global;
  4399. }
  4400. // linear reverse scan
  4401. for ( var giveUpAt = i1 - 2; ;) {
  4402. if ( t0 === undefined ) {
  4403. // before start
  4404. this._cachedIndex = 0;
  4405. return this.beforeStart_( 0, t, t1 );
  4406. }
  4407. if ( i1 === giveUpAt ) break; // this loop
  4408. t1 = t0;
  4409. t0 = pp[ -- i1 - 1 ];
  4410. if ( t >= t0 ) {
  4411. // we have arrived at the sought interval
  4412. break seek;
  4413. }
  4414. }
  4415. // prepare binary search on the left side of the index
  4416. right = i1;
  4417. i1 = 0;
  4418. break linear_scan;
  4419. }
  4420. // the interval is valid
  4421. break validate_interval;
  4422. } // linear scan
  4423. // binary search
  4424. while ( i1 < right ) {
  4425. var mid = ( i1 + right ) >>> 1;
  4426. if ( t < pp[ mid ] ) {
  4427. right = mid;
  4428. } else {
  4429. i1 = mid + 1;
  4430. }
  4431. }
  4432. t1 = pp[ i1 ];
  4433. t0 = pp[ i1 - 1 ];
  4434. // check boundary cases, again
  4435. if ( t0 === undefined ) {
  4436. this._cachedIndex = 0;
  4437. return this.beforeStart_( 0, t, t1 );
  4438. }
  4439. if ( t1 === undefined ) {
  4440. i1 = pp.length;
  4441. this._cachedIndex = i1;
  4442. return this.afterEnd_( i1 - 1, t0, t );
  4443. }
  4444. } // seek
  4445. this._cachedIndex = i1;
  4446. this.intervalChanged_( i1, t0, t1 );
  4447. } // validate_interval
  4448. return this.interpolate_( i1, t0, t, t1 );
  4449. },
  4450. settings: null, // optional, subclass-specific settings structure
  4451. // Note: The indirection allows central control of many interpolants.
  4452. // --- Protected interface
  4453. DefaultSettings_: {},
  4454. getSettings_: function() {
  4455. return this.settings || this.DefaultSettings_;
  4456. },
  4457. copySampleValue_: function( index ) {
  4458. // copies a sample value to the result buffer
  4459. var result = this.resultBuffer,
  4460. values = this.sampleValues,
  4461. stride = this.valueSize,
  4462. offset = index * stride;
  4463. for ( var i = 0; i !== stride; ++ i ) {
  4464. result[ i ] = values[ offset + i ];
  4465. }
  4466. return result;
  4467. },
  4468. // Template methods for derived classes:
  4469. interpolate_: function( i1, t0, t, t1 ) {
  4470. throw new Error( "call to abstract method" );
  4471. // implementations shall return this.resultBuffer
  4472. },
  4473. intervalChanged_: function( i1, t0, t1 ) {
  4474. // empty
  4475. }
  4476. };
  4477. Object.assign( THREE.Interpolant.prototype, {
  4478. beforeStart_: //( 0, t, t0 ), returns this.resultBuffer
  4479. THREE.Interpolant.prototype.copySampleValue_,
  4480. afterEnd_: //( N-1, tN-1, t ), returns this.resultBuffer
  4481. THREE.Interpolant.prototype.copySampleValue_
  4482. } );
  4483. // File:src/math/interpolants/CubicInterpolant.js
  4484. /**
  4485. * Fast and simple cubic spline interpolant.
  4486. *
  4487. * It was derived from a Hermitian construction setting the first derivative
  4488. * at each sample position to the linear slope between neighboring positions
  4489. * over their parameter interval.
  4490. *
  4491. * @author tschw
  4492. */
  4493. THREE.CubicInterpolant = function(
  4494. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4495. THREE.Interpolant.call(
  4496. this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  4497. this._weightPrev = -0;
  4498. this._offsetPrev = -0;
  4499. this._weightNext = -0;
  4500. this._offsetNext = -0;
  4501. };
  4502. THREE.CubicInterpolant.prototype =
  4503. Object.assign( Object.create( THREE.Interpolant.prototype ), {
  4504. constructor: THREE.CubicInterpolant,
  4505. DefaultSettings_: {
  4506. endingStart: THREE.ZeroCurvatureEnding,
  4507. endingEnd: THREE.ZeroCurvatureEnding
  4508. },
  4509. intervalChanged_: function( i1, t0, t1 ) {
  4510. var pp = this.parameterPositions,
  4511. iPrev = i1 - 2,
  4512. iNext = i1 + 1,
  4513. tPrev = pp[ iPrev ],
  4514. tNext = pp[ iNext ];
  4515. if ( tPrev === undefined ) {
  4516. switch ( this.getSettings_().endingStart ) {
  4517. case THREE.ZeroSlopeEnding:
  4518. // f'(t0) = 0
  4519. iPrev = i1;
  4520. tPrev = 2 * t0 - t1;
  4521. break;
  4522. case THREE.WrapAroundEnding:
  4523. // use the other end of the curve
  4524. iPrev = pp.length - 2;
  4525. tPrev = t0 + pp[ iPrev ] - pp[ iPrev + 1 ];
  4526. break;
  4527. default: // ZeroCurvatureEnding
  4528. // f''(t0) = 0 a.k.a. Natural Spline
  4529. iPrev = i1;
  4530. tPrev = t1;
  4531. }
  4532. }
  4533. if ( tNext === undefined ) {
  4534. switch ( this.getSettings_().endingEnd ) {
  4535. case THREE.ZeroSlopeEnding:
  4536. // f'(tN) = 0
  4537. iNext = i1;
  4538. tNext = 2 * t1 - t0;
  4539. break;
  4540. case THREE.WrapAroundEnding:
  4541. // use the other end of the curve
  4542. iNext = 1;
  4543. tNext = t1 + pp[ 1 ] - pp[ 0 ];
  4544. break;
  4545. default: // ZeroCurvatureEnding
  4546. // f''(tN) = 0, a.k.a. Natural Spline
  4547. iNext = i1 - 1;
  4548. tNext = t0;
  4549. }
  4550. }
  4551. var halfDt = ( t1 - t0 ) * 0.5,
  4552. stride = this.valueSize;
  4553. this._weightPrev = halfDt / ( t0 - tPrev );
  4554. this._weightNext = halfDt / ( tNext - t1 );
  4555. this._offsetPrev = iPrev * stride;
  4556. this._offsetNext = iNext * stride;
  4557. },
  4558. interpolate_: function( i1, t0, t, t1 ) {
  4559. var result = this.resultBuffer,
  4560. values = this.sampleValues,
  4561. stride = this.valueSize,
  4562. o1 = i1 * stride, o0 = o1 - stride,
  4563. oP = this._offsetPrev, oN = this._offsetNext,
  4564. wP = this._weightPrev, wN = this._weightNext,
  4565. p = ( t - t0 ) / ( t1 - t0 ),
  4566. pp = p * p,
  4567. ppp = pp * p;
  4568. // evaluate polynomials
  4569. var sP = - wP * ppp + 2 * wP * pp - wP * p;
  4570. var s0 = ( 1 + wP ) * ppp + (-1.5 - 2 * wP ) * pp + ( -0.5 + wP ) * p + 1;
  4571. var s1 = (-1 - wN ) * ppp + ( 1.5 + wN ) * pp + 0.5 * p;
  4572. var sN = wN * ppp - wN * pp;
  4573. // combine data linearly
  4574. for ( var i = 0; i !== stride; ++ i ) {
  4575. result[ i ] =
  4576. sP * values[ oP + i ] +
  4577. s0 * values[ o0 + i ] +
  4578. s1 * values[ o1 + i ] +
  4579. sN * values[ oN + i ];
  4580. }
  4581. return result;
  4582. }
  4583. } );
  4584. // File:src/math/interpolants/DiscreteInterpolant.js
  4585. /**
  4586. *
  4587. * Interpolant that evaluates to the sample value at the position preceeding
  4588. * the parameter.
  4589. *
  4590. * @author tschw
  4591. */
  4592. THREE.DiscreteInterpolant = function(
  4593. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4594. THREE.Interpolant.call(
  4595. this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  4596. };
  4597. THREE.DiscreteInterpolant.prototype =
  4598. Object.assign( Object.create( THREE.Interpolant.prototype ), {
  4599. constructor: THREE.DiscreteInterpolant,
  4600. interpolate_: function( i1, t0, t, t1 ) {
  4601. return this.copySampleValue_( i1 - 1 );
  4602. }
  4603. } );
  4604. // File:src/math/interpolants/LinearInterpolant.js
  4605. /**
  4606. * @author tschw
  4607. */
  4608. THREE.LinearInterpolant = function(
  4609. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4610. THREE.Interpolant.call(
  4611. this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  4612. };
  4613. THREE.LinearInterpolant.prototype =
  4614. Object.assign( Object.create( THREE.Interpolant.prototype ), {
  4615. constructor: THREE.LinearInterpolant,
  4616. interpolate_: function( i1, t0, t, t1 ) {
  4617. var result = this.resultBuffer,
  4618. values = this.sampleValues,
  4619. stride = this.valueSize,
  4620. offset1 = i1 * stride,
  4621. offset0 = offset1 - stride,
  4622. weight1 = ( t - t0 ) / ( t1 - t0 ),
  4623. weight0 = 1 - weight1;
  4624. for ( var i = 0; i !== stride; ++ i ) {
  4625. result[ i ] =
  4626. values[ offset0 + i ] * weight0 +
  4627. values[ offset1 + i ] * weight1;
  4628. }
  4629. return result;
  4630. }
  4631. } );
  4632. // File:src/math/interpolants/QuaternionLinearInterpolant.js
  4633. /**
  4634. * Spherical linear unit quaternion interpolant.
  4635. *
  4636. * @author tschw
  4637. */
  4638. THREE.QuaternionLinearInterpolant = function(
  4639. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4640. THREE.Interpolant.call(
  4641. this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  4642. };
  4643. THREE.QuaternionLinearInterpolant.prototype =
  4644. Object.assign( Object.create( THREE.Interpolant.prototype ), {
  4645. constructor: THREE.QuaternionLinearInterpolant,
  4646. interpolate_: function( i1, t0, t, t1 ) {
  4647. var result = this.resultBuffer,
  4648. values = this.sampleValues,
  4649. stride = this.valueSize,
  4650. offset = i1 * stride,
  4651. alpha = ( t - t0 ) / ( t1 - t0 );
  4652. for ( var end = offset + stride; offset !== end; offset += 4 ) {
  4653. THREE.Quaternion.slerpFlat( result, 0,
  4654. values, offset - stride, values, offset, alpha );
  4655. }
  4656. return result;
  4657. }
  4658. } );
  4659. // File:src/core/Clock.js
  4660. /**
  4661. * @author alteredq / http://alteredqualia.com/
  4662. */
  4663. THREE.Clock = function ( autoStart ) {
  4664. this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
  4665. this.startTime = 0;
  4666. this.oldTime = 0;
  4667. this.elapsedTime = 0;
  4668. this.running = false;
  4669. };
  4670. THREE.Clock.prototype = {
  4671. constructor: THREE.Clock,
  4672. start: function () {
  4673. this.startTime = self.performance.now();
  4674. this.oldTime = this.startTime;
  4675. this.running = true;
  4676. },
  4677. stop: function () {
  4678. this.getElapsedTime();
  4679. this.running = false;
  4680. },
  4681. getElapsedTime: function () {
  4682. this.getDelta();
  4683. return this.elapsedTime;
  4684. },
  4685. getDelta: function () {
  4686. var diff = 0;
  4687. if ( this.autoStart && ! this.running ) {
  4688. this.start();
  4689. }
  4690. if ( this.running ) {
  4691. var newTime = self.performance.now();
  4692. diff = 0.001 * ( newTime - this.oldTime );
  4693. this.oldTime = newTime;
  4694. this.elapsedTime += diff;
  4695. }
  4696. return diff;
  4697. }
  4698. };
  4699. // File:src/core/EventDispatcher.js
  4700. /**
  4701. * https://github.com/mrdoob/eventdispatcher.js/
  4702. */
  4703. THREE.EventDispatcher = function () {};
  4704. THREE.EventDispatcher.prototype = {
  4705. constructor: THREE.EventDispatcher,
  4706. apply: function ( object ) {
  4707. object.addEventListener = THREE.EventDispatcher.prototype.addEventListener;
  4708. object.hasEventListener = THREE.EventDispatcher.prototype.hasEventListener;
  4709. object.removeEventListener = THREE.EventDispatcher.prototype.removeEventListener;
  4710. object.dispatchEvent = THREE.EventDispatcher.prototype.dispatchEvent;
  4711. },
  4712. addEventListener: function ( type, listener ) {
  4713. if ( this._listeners === undefined ) this._listeners = {};
  4714. var listeners = this._listeners;
  4715. if ( listeners[ type ] === undefined ) {
  4716. listeners[ type ] = [];
  4717. }
  4718. if ( listeners[ type ].indexOf( listener ) === - 1 ) {
  4719. listeners[ type ].push( listener );
  4720. }
  4721. },
  4722. hasEventListener: function ( type, listener ) {
  4723. if ( this._listeners === undefined ) return false;
  4724. var listeners = this._listeners;
  4725. if ( listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1 ) {
  4726. return true;
  4727. }
  4728. return false;
  4729. },
  4730. removeEventListener: function ( type, listener ) {
  4731. if ( this._listeners === undefined ) return;
  4732. var listeners = this._listeners;
  4733. var listenerArray = listeners[ type ];
  4734. if ( listenerArray !== undefined ) {
  4735. var index = listenerArray.indexOf( listener );
  4736. if ( index !== - 1 ) {
  4737. listenerArray.splice( index, 1 );
  4738. }
  4739. }
  4740. },
  4741. dispatchEvent: function ( event ) {
  4742. if ( this._listeners === undefined ) return;
  4743. var listeners = this._listeners;
  4744. var listenerArray = listeners[ event.type ];
  4745. if ( listenerArray !== undefined ) {
  4746. event.target = this;
  4747. var array = [];
  4748. var length = listenerArray.length;
  4749. for ( var i = 0; i < length; i ++ ) {
  4750. array[ i ] = listenerArray[ i ];
  4751. }
  4752. for ( var i = 0; i < length; i ++ ) {
  4753. array[ i ].call( this, event );
  4754. }
  4755. }
  4756. }
  4757. };
  4758. // File:src/core/Layers.js
  4759. /**
  4760. * @author mrdoob / http://mrdoob.com/
  4761. */
  4762. THREE.Layers = function () {
  4763. this.mask = 1;
  4764. };
  4765. THREE.Layers.prototype = {
  4766. constructor: THREE.Layers,
  4767. set: function ( channel ) {
  4768. this.mask = 1 << channel;
  4769. },
  4770. enable: function ( channel ) {
  4771. this.mask |= 1 << channel;
  4772. },
  4773. toggle: function ( channel ) {
  4774. this.mask ^= 1 << channel;
  4775. },
  4776. disable: function ( channel ) {
  4777. this.mask &= ~ ( 1 << channel );
  4778. },
  4779. test: function ( layers ) {
  4780. return ( this.mask & layers.mask ) !== 0;
  4781. }
  4782. };
  4783. // File:src/core/Raycaster.js
  4784. /**
  4785. * @author mrdoob / http://mrdoob.com/
  4786. * @author bhouston / http://clara.io/
  4787. * @author stephomi / http://stephaneginier.com/
  4788. */
  4789. ( function ( THREE ) {
  4790. THREE.Raycaster = function ( origin, direction, near, far ) {
  4791. this.ray = new THREE.Ray( origin, direction );
  4792. // direction is assumed to be normalized (for accurate distance calculations)
  4793. this.near = near || 0;
  4794. this.far = far || Infinity;
  4795. this.params = {
  4796. Mesh: {},
  4797. Line: {},
  4798. LOD: {},
  4799. Points: { threshold: 1 },
  4800. Sprite: {}
  4801. };
  4802. Object.defineProperties( this.params, {
  4803. PointCloud: {
  4804. get: function () {
  4805. console.warn( 'THREE.Raycaster: params.PointCloud has been renamed to params.Points.' );
  4806. return this.Points;
  4807. }
  4808. }
  4809. } );
  4810. };
  4811. function descSort( a, b ) {
  4812. return a.distance - b.distance;
  4813. }
  4814. function intersectObject( object, raycaster, intersects, recursive ) {
  4815. if ( object.visible === false ) return;
  4816. object.raycast( raycaster, intersects );
  4817. if ( recursive === true ) {
  4818. var children = object.children;
  4819. for ( var i = 0, l = children.length; i < l; i ++ ) {
  4820. intersectObject( children[ i ], raycaster, intersects, true );
  4821. }
  4822. }
  4823. }
  4824. //
  4825. THREE.Raycaster.prototype = {
  4826. constructor: THREE.Raycaster,
  4827. linePrecision: 1,
  4828. set: function ( origin, direction ) {
  4829. // direction is assumed to be normalized (for accurate distance calculations)
  4830. this.ray.set( origin, direction );
  4831. },
  4832. setFromCamera: function ( coords, camera ) {
  4833. if ( camera instanceof THREE.PerspectiveCamera ) {
  4834. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  4835. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  4836. } else if ( camera instanceof THREE.OrthographicCamera ) {
  4837. this.ray.origin.set( coords.x, coords.y, - 1 ).unproject( camera );
  4838. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  4839. } else {
  4840. console.error( 'THREE.Raycaster: Unsupported camera type.' );
  4841. }
  4842. },
  4843. intersectObject: function ( object, recursive ) {
  4844. var intersects = [];
  4845. intersectObject( object, this, intersects, recursive );
  4846. intersects.sort( descSort );
  4847. return intersects;
  4848. },
  4849. intersectObjects: function ( objects, recursive ) {
  4850. var intersects = [];
  4851. if ( Array.isArray( objects ) === false ) {
  4852. console.warn( 'THREE.Raycaster.intersectObjects: objects is not an Array.' );
  4853. return intersects;
  4854. }
  4855. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  4856. intersectObject( objects[ i ], this, intersects, recursive );
  4857. }
  4858. intersects.sort( descSort );
  4859. return intersects;
  4860. }
  4861. };
  4862. }( THREE ) );
  4863. // File:src/core/Object3D.js
  4864. /**
  4865. * @author mrdoob / http://mrdoob.com/
  4866. * @author mikael emtinger / http://gomo.se/
  4867. * @author alteredq / http://alteredqualia.com/
  4868. * @author WestLangley / http://github.com/WestLangley
  4869. * @author elephantatwork / www.elephantatwork.ch
  4870. */
  4871. THREE.Object3D = function () {
  4872. Object.defineProperty( this, 'id', { value: THREE.Object3DIdCount ++ } );
  4873. this.uuid = THREE.Math.generateUUID();
  4874. this.name = '';
  4875. this.type = 'Object3D';
  4876. this.parent = null;
  4877. this.children = [];
  4878. this.up = THREE.Object3D.DefaultUp.clone();
  4879. var position = new THREE.Vector3();
  4880. var rotation = new THREE.Euler();
  4881. var quaternion = new THREE.Quaternion();
  4882. var scale = new THREE.Vector3( 1, 1, 1 );
  4883. function onRotationChange() {
  4884. quaternion.setFromEuler( rotation, false );
  4885. }
  4886. function onQuaternionChange() {
  4887. rotation.setFromQuaternion( quaternion, undefined, false );
  4888. }
  4889. rotation.onChange( onRotationChange );
  4890. quaternion.onChange( onQuaternionChange );
  4891. Object.defineProperties( this, {
  4892. position: {
  4893. enumerable: true,
  4894. value: position
  4895. },
  4896. rotation: {
  4897. enumerable: true,
  4898. value: rotation
  4899. },
  4900. quaternion: {
  4901. enumerable: true,
  4902. value: quaternion
  4903. },
  4904. scale: {
  4905. enumerable: true,
  4906. value: scale
  4907. },
  4908. modelViewMatrix: {
  4909. value: new THREE.Matrix4()
  4910. },
  4911. normalMatrix: {
  4912. value: new THREE.Matrix3()
  4913. }
  4914. } );
  4915. this.rotationAutoUpdate = true;
  4916. this.matrix = new THREE.Matrix4();
  4917. this.matrixWorld = new THREE.Matrix4();
  4918. this.matrixAutoUpdate = THREE.Object3D.DefaultMatrixAutoUpdate;
  4919. this.matrixWorldNeedsUpdate = false;
  4920. this.layers = new THREE.Layers();
  4921. this.visible = true;
  4922. this.castShadow = false;
  4923. this.receiveShadow = false;
  4924. this.frustumCulled = true;
  4925. this.renderOrder = 0;
  4926. this.userData = {};
  4927. };
  4928. THREE.Object3D.DefaultUp = new THREE.Vector3( 0, 1, 0 );
  4929. THREE.Object3D.DefaultMatrixAutoUpdate = true;
  4930. THREE.Object3D.prototype = {
  4931. constructor: THREE.Object3D,
  4932. applyMatrix: function ( matrix ) {
  4933. this.matrix.multiplyMatrices( matrix, this.matrix );
  4934. this.matrix.decompose( this.position, this.quaternion, this.scale );
  4935. },
  4936. setRotationFromAxisAngle: function ( axis, angle ) {
  4937. // assumes axis is normalized
  4938. this.quaternion.setFromAxisAngle( axis, angle );
  4939. },
  4940. setRotationFromEuler: function ( euler ) {
  4941. this.quaternion.setFromEuler( euler, true );
  4942. },
  4943. setRotationFromMatrix: function ( m ) {
  4944. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4945. this.quaternion.setFromRotationMatrix( m );
  4946. },
  4947. setRotationFromQuaternion: function ( q ) {
  4948. // assumes q is normalized
  4949. this.quaternion.copy( q );
  4950. },
  4951. rotateOnAxis: function () {
  4952. // rotate object on axis in object space
  4953. // axis is assumed to be normalized
  4954. var q1 = new THREE.Quaternion();
  4955. return function ( axis, angle ) {
  4956. q1.setFromAxisAngle( axis, angle );
  4957. this.quaternion.multiply( q1 );
  4958. return this;
  4959. };
  4960. }(),
  4961. rotateX: function () {
  4962. var v1 = new THREE.Vector3( 1, 0, 0 );
  4963. return function ( angle ) {
  4964. return this.rotateOnAxis( v1, angle );
  4965. };
  4966. }(),
  4967. rotateY: function () {
  4968. var v1 = new THREE.Vector3( 0, 1, 0 );
  4969. return function ( angle ) {
  4970. return this.rotateOnAxis( v1, angle );
  4971. };
  4972. }(),
  4973. rotateZ: function () {
  4974. var v1 = new THREE.Vector3( 0, 0, 1 );
  4975. return function ( angle ) {
  4976. return this.rotateOnAxis( v1, angle );
  4977. };
  4978. }(),
  4979. translateOnAxis: function () {
  4980. // translate object by distance along axis in object space
  4981. // axis is assumed to be normalized
  4982. var v1 = new THREE.Vector3();
  4983. return function ( axis, distance ) {
  4984. v1.copy( axis ).applyQuaternion( this.quaternion );
  4985. this.position.add( v1.multiplyScalar( distance ) );
  4986. return this;
  4987. };
  4988. }(),
  4989. translateX: function () {
  4990. var v1 = new THREE.Vector3( 1, 0, 0 );
  4991. return function ( distance ) {
  4992. return this.translateOnAxis( v1, distance );
  4993. };
  4994. }(),
  4995. translateY: function () {
  4996. var v1 = new THREE.Vector3( 0, 1, 0 );
  4997. return function ( distance ) {
  4998. return this.translateOnAxis( v1, distance );
  4999. };
  5000. }(),
  5001. translateZ: function () {
  5002. var v1 = new THREE.Vector3( 0, 0, 1 );
  5003. return function ( distance ) {
  5004. return this.translateOnAxis( v1, distance );
  5005. };
  5006. }(),
  5007. localToWorld: function ( vector ) {
  5008. return vector.applyMatrix4( this.matrixWorld );
  5009. },
  5010. worldToLocal: function () {
  5011. var m1 = new THREE.Matrix4();
  5012. return function ( vector ) {
  5013. return vector.applyMatrix4( m1.getInverse( this.matrixWorld ) );
  5014. };
  5015. }(),
  5016. lookAt: function () {
  5017. // This routine does not support objects with rotated and/or translated parent(s)
  5018. var m1 = new THREE.Matrix4();
  5019. return function ( vector ) {
  5020. m1.lookAt( vector, this.position, this.up );
  5021. this.quaternion.setFromRotationMatrix( m1 );
  5022. };
  5023. }(),
  5024. add: function ( object ) {
  5025. if ( arguments.length > 1 ) {
  5026. for ( var i = 0; i < arguments.length; i ++ ) {
  5027. this.add( arguments[ i ] );
  5028. }
  5029. return this;
  5030. }
  5031. if ( object === this ) {
  5032. console.error( "THREE.Object3D.add: object can't be added as a child of itself.", object );
  5033. return this;
  5034. }
  5035. if ( object instanceof THREE.Object3D ) {
  5036. if ( object.parent !== null ) {
  5037. object.parent.remove( object );
  5038. }
  5039. object.parent = this;
  5040. object.dispatchEvent( { type: 'added' } );
  5041. this.children.push( object );
  5042. } else {
  5043. console.error( "THREE.Object3D.add: object not an instance of THREE.Object3D.", object );
  5044. }
  5045. return this;
  5046. },
  5047. remove: function ( object ) {
  5048. if ( arguments.length > 1 ) {
  5049. for ( var i = 0; i < arguments.length; i ++ ) {
  5050. this.remove( arguments[ i ] );
  5051. }
  5052. }
  5053. var index = this.children.indexOf( object );
  5054. if ( index !== - 1 ) {
  5055. object.parent = null;
  5056. object.dispatchEvent( { type: 'removed' } );
  5057. this.children.splice( index, 1 );
  5058. }
  5059. },
  5060. getObjectById: function ( id ) {
  5061. return this.getObjectByProperty( 'id', id );
  5062. },
  5063. getObjectByName: function ( name ) {
  5064. return this.getObjectByProperty( 'name', name );
  5065. },
  5066. getObjectByProperty: function ( name, value ) {
  5067. if ( this[ name ] === value ) return this;
  5068. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  5069. var child = this.children[ i ];
  5070. var object = child.getObjectByProperty( name, value );
  5071. if ( object !== undefined ) {
  5072. return object;
  5073. }
  5074. }
  5075. return undefined;
  5076. },
  5077. getWorldPosition: function ( optionalTarget ) {
  5078. var result = optionalTarget || new THREE.Vector3();
  5079. this.updateMatrixWorld( true );
  5080. return result.setFromMatrixPosition( this.matrixWorld );
  5081. },
  5082. getWorldQuaternion: function () {
  5083. var position = new THREE.Vector3();
  5084. var scale = new THREE.Vector3();
  5085. return function ( optionalTarget ) {
  5086. var result = optionalTarget || new THREE.Quaternion();
  5087. this.updateMatrixWorld( true );
  5088. this.matrixWorld.decompose( position, result, scale );
  5089. return result;
  5090. };
  5091. }(),
  5092. getWorldRotation: function () {
  5093. var quaternion = new THREE.Quaternion();
  5094. return function ( optionalTarget ) {
  5095. var result = optionalTarget || new THREE.Euler();
  5096. this.getWorldQuaternion( quaternion );
  5097. return result.setFromQuaternion( quaternion, this.rotation.order, false );
  5098. };
  5099. }(),
  5100. getWorldScale: function () {
  5101. var position = new THREE.Vector3();
  5102. var quaternion = new THREE.Quaternion();
  5103. return function ( optionalTarget ) {
  5104. var result = optionalTarget || new THREE.Vector3();
  5105. this.updateMatrixWorld( true );
  5106. this.matrixWorld.decompose( position, quaternion, result );
  5107. return result;
  5108. };
  5109. }(),
  5110. getWorldDirection: function () {
  5111. var quaternion = new THREE.Quaternion();
  5112. return function ( optionalTarget ) {
  5113. var result = optionalTarget || new THREE.Vector3();
  5114. this.getWorldQuaternion( quaternion );
  5115. return result.set( 0, 0, 1 ).applyQuaternion( quaternion );
  5116. };
  5117. }(),
  5118. raycast: function () {},
  5119. traverse: function ( callback ) {
  5120. callback( this );
  5121. var children = this.children;
  5122. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5123. children[ i ].traverse( callback );
  5124. }
  5125. },
  5126. traverseVisible: function ( callback ) {
  5127. if ( this.visible === false ) return;
  5128. callback( this );
  5129. var children = this.children;
  5130. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5131. children[ i ].traverseVisible( callback );
  5132. }
  5133. },
  5134. traverseAncestors: function ( callback ) {
  5135. var parent = this.parent;
  5136. if ( parent !== null ) {
  5137. callback( parent );
  5138. parent.traverseAncestors( callback );
  5139. }
  5140. },
  5141. updateMatrix: function () {
  5142. this.matrix.compose( this.position, this.quaternion, this.scale );
  5143. this.matrixWorldNeedsUpdate = true;
  5144. },
  5145. updateMatrixWorld: function ( force ) {
  5146. if ( this.matrixAutoUpdate === true ) this.updateMatrix();
  5147. if ( this.matrixWorldNeedsUpdate === true || force === true ) {
  5148. if ( this.parent === null ) {
  5149. this.matrixWorld.copy( this.matrix );
  5150. } else {
  5151. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  5152. }
  5153. this.matrixWorldNeedsUpdate = false;
  5154. force = true;
  5155. }
  5156. // update children
  5157. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  5158. this.children[ i ].updateMatrixWorld( force );
  5159. }
  5160. },
  5161. toJSON: function ( meta ) {
  5162. var isRootObject = ( meta === undefined );
  5163. var output = {};
  5164. // meta is a hash used to collect geometries, materials.
  5165. // not providing it implies that this is the root object
  5166. // being serialized.
  5167. if ( isRootObject ) {
  5168. // initialize meta obj
  5169. meta = {
  5170. geometries: {},
  5171. materials: {},
  5172. textures: {},
  5173. images: {}
  5174. };
  5175. output.metadata = {
  5176. version: 4.4,
  5177. type: 'Object',
  5178. generator: 'Object3D.toJSON'
  5179. };
  5180. }
  5181. // standard Object3D serialization
  5182. var object = {};
  5183. object.uuid = this.uuid;
  5184. object.type = this.type;
  5185. if ( this.name !== '' ) object.name = this.name;
  5186. if ( JSON.stringify( this.userData ) !== '{}' ) object.userData = this.userData;
  5187. if ( this.castShadow === true ) object.castShadow = true;
  5188. if ( this.receiveShadow === true ) object.receiveShadow = true;
  5189. if ( this.visible === false ) object.visible = false;
  5190. object.matrix = this.matrix.toArray();
  5191. //
  5192. if ( this.geometry !== undefined ) {
  5193. if ( meta.geometries[ this.geometry.uuid ] === undefined ) {
  5194. meta.geometries[ this.geometry.uuid ] = this.geometry.toJSON( meta );
  5195. }
  5196. object.geometry = this.geometry.uuid;
  5197. }
  5198. if ( this.material !== undefined ) {
  5199. if ( meta.materials[ this.material.uuid ] === undefined ) {
  5200. meta.materials[ this.material.uuid ] = this.material.toJSON( meta );
  5201. }
  5202. object.material = this.material.uuid;
  5203. }
  5204. //
  5205. if ( this.children.length > 0 ) {
  5206. object.children = [];
  5207. for ( var i = 0; i < this.children.length; i ++ ) {
  5208. object.children.push( this.children[ i ].toJSON( meta ).object );
  5209. }
  5210. }
  5211. if ( isRootObject ) {
  5212. var geometries = extractFromCache( meta.geometries );
  5213. var materials = extractFromCache( meta.materials );
  5214. var textures = extractFromCache( meta.textures );
  5215. var images = extractFromCache( meta.images );
  5216. if ( geometries.length > 0 ) output.geometries = geometries;
  5217. if ( materials.length > 0 ) output.materials = materials;
  5218. if ( textures.length > 0 ) output.textures = textures;
  5219. if ( images.length > 0 ) output.images = images;
  5220. }
  5221. output.object = object;
  5222. return output;
  5223. // extract data from the cache hash
  5224. // remove metadata on each item
  5225. // and return as array
  5226. function extractFromCache ( cache ) {
  5227. var values = [];
  5228. for ( var key in cache ) {
  5229. var data = cache[ key ];
  5230. delete data.metadata;
  5231. values.push( data );
  5232. }
  5233. return values;
  5234. }
  5235. },
  5236. clone: function ( recursive ) {
  5237. return new this.constructor().copy( this, recursive );
  5238. },
  5239. copy: function ( source, recursive ) {
  5240. if ( recursive === undefined ) recursive = true;
  5241. this.name = source.name;
  5242. this.up.copy( source.up );
  5243. this.position.copy( source.position );
  5244. this.quaternion.copy( source.quaternion );
  5245. this.scale.copy( source.scale );
  5246. this.rotationAutoUpdate = source.rotationAutoUpdate;
  5247. this.matrix.copy( source.matrix );
  5248. this.matrixWorld.copy( source.matrixWorld );
  5249. this.matrixAutoUpdate = source.matrixAutoUpdate;
  5250. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  5251. this.visible = source.visible;
  5252. this.castShadow = source.castShadow;
  5253. this.receiveShadow = source.receiveShadow;
  5254. this.frustumCulled = source.frustumCulled;
  5255. this.renderOrder = source.renderOrder;
  5256. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  5257. if ( recursive === true ) {
  5258. for ( var i = 0; i < source.children.length; i ++ ) {
  5259. var child = source.children[ i ];
  5260. this.add( child.clone() );
  5261. }
  5262. }
  5263. return this;
  5264. }
  5265. };
  5266. THREE.EventDispatcher.prototype.apply( THREE.Object3D.prototype );
  5267. THREE.Object3DIdCount = 0;
  5268. // File:src/core/Face3.js
  5269. /**
  5270. * @author mrdoob / http://mrdoob.com/
  5271. * @author alteredq / http://alteredqualia.com/
  5272. */
  5273. THREE.Face3 = function ( a, b, c, normal, color, materialIndex ) {
  5274. this.a = a;
  5275. this.b = b;
  5276. this.c = c;
  5277. this.normal = normal instanceof THREE.Vector3 ? normal : new THREE.Vector3();
  5278. this.vertexNormals = Array.isArray( normal ) ? normal : [];
  5279. this.color = color instanceof THREE.Color ? color : new THREE.Color();
  5280. this.vertexColors = Array.isArray( color ) ? color : [];
  5281. this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
  5282. };
  5283. THREE.Face3.prototype = {
  5284. constructor: THREE.Face3,
  5285. clone: function () {
  5286. return new this.constructor().copy( this );
  5287. },
  5288. copy: function ( source ) {
  5289. this.a = source.a;
  5290. this.b = source.b;
  5291. this.c = source.c;
  5292. this.normal.copy( source.normal );
  5293. this.color.copy( source.color );
  5294. this.materialIndex = source.materialIndex;
  5295. for ( var i = 0, il = source.vertexNormals.length; i < il; i ++ ) {
  5296. this.vertexNormals[ i ] = source.vertexNormals[ i ].clone();
  5297. }
  5298. for ( var i = 0, il = source.vertexColors.length; i < il; i ++ ) {
  5299. this.vertexColors[ i ] = source.vertexColors[ i ].clone();
  5300. }
  5301. return this;
  5302. }
  5303. };
  5304. // File:src/core/Face4.js
  5305. /**
  5306. * @author mrdoob / http://mrdoob.com/
  5307. */
  5308. THREE.Face4 = function ( a, b, c, d, normal, color, materialIndex ) {
  5309. console.warn( 'THREE.Face4 has been removed. A THREE.Face3 will be created instead.' );
  5310. return new THREE.Face3( a, b, c, normal, color, materialIndex );
  5311. };
  5312. // File:src/core/BufferAttribute.js
  5313. /**
  5314. * @author mrdoob / http://mrdoob.com/
  5315. */
  5316. THREE.BufferAttribute = function ( array, itemSize ) {
  5317. this.uuid = THREE.Math.generateUUID();
  5318. this.array = array;
  5319. this.itemSize = itemSize;
  5320. this.dynamic = false;
  5321. this.updateRange = { offset: 0, count: - 1 };
  5322. this.version = 0;
  5323. };
  5324. THREE.BufferAttribute.prototype = {
  5325. constructor: THREE.BufferAttribute,
  5326. get length() {
  5327. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Please use .count.' );
  5328. return this.array.length;
  5329. },
  5330. get count() {
  5331. return this.array.length / this.itemSize;
  5332. },
  5333. set needsUpdate( value ) {
  5334. if ( value === true ) this.version ++;
  5335. },
  5336. setDynamic: function ( value ) {
  5337. this.dynamic = value;
  5338. return this;
  5339. },
  5340. copy: function ( source ) {
  5341. this.array = new source.array.constructor( source.array );
  5342. this.itemSize = source.itemSize;
  5343. this.dynamic = source.dynamic;
  5344. return this;
  5345. },
  5346. copyAt: function ( index1, attribute, index2 ) {
  5347. index1 *= this.itemSize;
  5348. index2 *= attribute.itemSize;
  5349. for ( var i = 0, l = this.itemSize; i < l; i ++ ) {
  5350. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5351. }
  5352. return this;
  5353. },
  5354. copyArray: function ( array ) {
  5355. this.array.set( array );
  5356. return this;
  5357. },
  5358. copyColorsArray: function ( colors ) {
  5359. var array = this.array, offset = 0;
  5360. for ( var i = 0, l = colors.length; i < l; i ++ ) {
  5361. var color = colors[ i ];
  5362. if ( color === undefined ) {
  5363. console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
  5364. color = new THREE.Color();
  5365. }
  5366. array[ offset ++ ] = color.r;
  5367. array[ offset ++ ] = color.g;
  5368. array[ offset ++ ] = color.b;
  5369. }
  5370. return this;
  5371. },
  5372. copyIndicesArray: function ( indices ) {
  5373. var array = this.array, offset = 0;
  5374. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  5375. var index = indices[ i ];
  5376. array[ offset ++ ] = index.a;
  5377. array[ offset ++ ] = index.b;
  5378. array[ offset ++ ] = index.c;
  5379. }
  5380. return this;
  5381. },
  5382. copyVector2sArray: function ( vectors ) {
  5383. var array = this.array, offset = 0;
  5384. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5385. var vector = vectors[ i ];
  5386. if ( vector === undefined ) {
  5387. console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
  5388. vector = new THREE.Vector2();
  5389. }
  5390. array[ offset ++ ] = vector.x;
  5391. array[ offset ++ ] = vector.y;
  5392. }
  5393. return this;
  5394. },
  5395. copyVector3sArray: function ( vectors ) {
  5396. var array = this.array, offset = 0;
  5397. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5398. var vector = vectors[ i ];
  5399. if ( vector === undefined ) {
  5400. console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
  5401. vector = new THREE.Vector3();
  5402. }
  5403. array[ offset ++ ] = vector.x;
  5404. array[ offset ++ ] = vector.y;
  5405. array[ offset ++ ] = vector.z;
  5406. }
  5407. return this;
  5408. },
  5409. copyVector4sArray: function ( vectors ) {
  5410. var array = this.array, offset = 0;
  5411. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5412. var vector = vectors[ i ];
  5413. if ( vector === undefined ) {
  5414. console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i );
  5415. vector = new THREE.Vector4();
  5416. }
  5417. array[ offset ++ ] = vector.x;
  5418. array[ offset ++ ] = vector.y;
  5419. array[ offset ++ ] = vector.z;
  5420. array[ offset ++ ] = vector.w;
  5421. }
  5422. return this;
  5423. },
  5424. set: function ( value, offset ) {
  5425. if ( offset === undefined ) offset = 0;
  5426. this.array.set( value, offset );
  5427. return this;
  5428. },
  5429. getX: function ( index ) {
  5430. return this.array[ index * this.itemSize ];
  5431. },
  5432. setX: function ( index, x ) {
  5433. this.array[ index * this.itemSize ] = x;
  5434. return this;
  5435. },
  5436. getY: function ( index ) {
  5437. return this.array[ index * this.itemSize + 1 ];
  5438. },
  5439. setY: function ( index, y ) {
  5440. this.array[ index * this.itemSize + 1 ] = y;
  5441. return this;
  5442. },
  5443. getZ: function ( index ) {
  5444. return this.array[ index * this.itemSize + 2 ];
  5445. },
  5446. setZ: function ( index, z ) {
  5447. this.array[ index * this.itemSize + 2 ] = z;
  5448. return this;
  5449. },
  5450. getW: function ( index ) {
  5451. return this.array[ index * this.itemSize + 3 ];
  5452. },
  5453. setW: function ( index, w ) {
  5454. this.array[ index * this.itemSize + 3 ] = w;
  5455. return this;
  5456. },
  5457. setXY: function ( index, x, y ) {
  5458. index *= this.itemSize;
  5459. this.array[ index + 0 ] = x;
  5460. this.array[ index + 1 ] = y;
  5461. return this;
  5462. },
  5463. setXYZ: function ( index, x, y, z ) {
  5464. index *= this.itemSize;
  5465. this.array[ index + 0 ] = x;
  5466. this.array[ index + 1 ] = y;
  5467. this.array[ index + 2 ] = z;
  5468. return this;
  5469. },
  5470. setXYZW: function ( index, x, y, z, w ) {
  5471. index *= this.itemSize;
  5472. this.array[ index + 0 ] = x;
  5473. this.array[ index + 1 ] = y;
  5474. this.array[ index + 2 ] = z;
  5475. this.array[ index + 3 ] = w;
  5476. return this;
  5477. },
  5478. clone: function () {
  5479. return new this.constructor().copy( this );
  5480. }
  5481. };
  5482. //
  5483. THREE.Int8Attribute = function ( array, itemSize ) {
  5484. return new THREE.BufferAttribute( new Int8Array( array ), itemSize );
  5485. };
  5486. THREE.Uint8Attribute = function ( array, itemSize ) {
  5487. return new THREE.BufferAttribute( new Uint8Array( array ), itemSize );
  5488. };
  5489. THREE.Uint8ClampedAttribute = function ( array, itemSize ) {
  5490. return new THREE.BufferAttribute( new Uint8ClampedArray( array ), itemSize );
  5491. };
  5492. THREE.Int16Attribute = function ( array, itemSize ) {
  5493. return new THREE.BufferAttribute( new Int16Array( array ), itemSize );
  5494. };
  5495. THREE.Uint16Attribute = function ( array, itemSize ) {
  5496. return new THREE.BufferAttribute( new Uint16Array( array ), itemSize );
  5497. };
  5498. THREE.Int32Attribute = function ( array, itemSize ) {
  5499. return new THREE.BufferAttribute( new Int32Array( array ), itemSize );
  5500. };
  5501. THREE.Uint32Attribute = function ( array, itemSize ) {
  5502. return new THREE.BufferAttribute( new Uint32Array( array ), itemSize );
  5503. };
  5504. THREE.Float32Attribute = function ( array, itemSize ) {
  5505. return new THREE.BufferAttribute( new Float32Array( array ), itemSize );
  5506. };
  5507. THREE.Float64Attribute = function ( array, itemSize ) {
  5508. return new THREE.BufferAttribute( new Float64Array( array ), itemSize );
  5509. };
  5510. // Deprecated
  5511. THREE.DynamicBufferAttribute = function ( array, itemSize ) {
  5512. console.warn( 'THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setDynamic( true ) instead.' );
  5513. return new THREE.BufferAttribute( array, itemSize ).setDynamic( true );
  5514. };
  5515. // File:src/core/InstancedBufferAttribute.js
  5516. /**
  5517. * @author benaadams / https://twitter.com/ben_a_adams
  5518. */
  5519. THREE.InstancedBufferAttribute = function ( array, itemSize, meshPerAttribute ) {
  5520. THREE.BufferAttribute.call( this, array, itemSize );
  5521. this.meshPerAttribute = meshPerAttribute || 1;
  5522. };
  5523. THREE.InstancedBufferAttribute.prototype = Object.create( THREE.BufferAttribute.prototype );
  5524. THREE.InstancedBufferAttribute.prototype.constructor = THREE.InstancedBufferAttribute;
  5525. THREE.InstancedBufferAttribute.prototype.copy = function ( source ) {
  5526. THREE.BufferAttribute.prototype.copy.call( this, source );
  5527. this.meshPerAttribute = source.meshPerAttribute;
  5528. return this;
  5529. };
  5530. // File:src/core/InterleavedBuffer.js
  5531. /**
  5532. * @author benaadams / https://twitter.com/ben_a_adams
  5533. */
  5534. THREE.InterleavedBuffer = function ( array, stride ) {
  5535. this.uuid = THREE.Math.generateUUID();
  5536. this.array = array;
  5537. this.stride = stride;
  5538. this.dynamic = false;
  5539. this.updateRange = { offset: 0, count: - 1 };
  5540. this.version = 0;
  5541. };
  5542. THREE.InterleavedBuffer.prototype = {
  5543. constructor: THREE.InterleavedBuffer,
  5544. get length () {
  5545. return this.array.length;
  5546. },
  5547. get count () {
  5548. return this.array.length / this.stride;
  5549. },
  5550. set needsUpdate( value ) {
  5551. if ( value === true ) this.version ++;
  5552. },
  5553. setDynamic: function ( value ) {
  5554. this.dynamic = value;
  5555. return this;
  5556. },
  5557. copy: function ( source ) {
  5558. this.array = new source.array.constructor( source.array );
  5559. this.stride = source.stride;
  5560. this.dynamic = source.dynamic;
  5561. },
  5562. copyAt: function ( index1, attribute, index2 ) {
  5563. index1 *= this.stride;
  5564. index2 *= attribute.stride;
  5565. for ( var i = 0, l = this.stride; i < l; i ++ ) {
  5566. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5567. }
  5568. return this;
  5569. },
  5570. set: function ( value, offset ) {
  5571. if ( offset === undefined ) offset = 0;
  5572. this.array.set( value, offset );
  5573. return this;
  5574. },
  5575. clone: function () {
  5576. return new this.constructor().copy( this );
  5577. }
  5578. };
  5579. // File:src/core/InstancedInterleavedBuffer.js
  5580. /**
  5581. * @author benaadams / https://twitter.com/ben_a_adams
  5582. */
  5583. THREE.InstancedInterleavedBuffer = function ( array, stride, meshPerAttribute ) {
  5584. THREE.InterleavedBuffer.call( this, array, stride );
  5585. this.meshPerAttribute = meshPerAttribute || 1;
  5586. };
  5587. THREE.InstancedInterleavedBuffer.prototype = Object.create( THREE.InterleavedBuffer.prototype );
  5588. THREE.InstancedInterleavedBuffer.prototype.constructor = THREE.InstancedInterleavedBuffer;
  5589. THREE.InstancedInterleavedBuffer.prototype.copy = function ( source ) {
  5590. THREE.InterleavedBuffer.prototype.copy.call( this, source );
  5591. this.meshPerAttribute = source.meshPerAttribute;
  5592. return this;
  5593. };
  5594. // File:src/core/InterleavedBufferAttribute.js
  5595. /**
  5596. * @author benaadams / https://twitter.com/ben_a_adams
  5597. */
  5598. THREE.InterleavedBufferAttribute = function ( interleavedBuffer, itemSize, offset ) {
  5599. this.uuid = THREE.Math.generateUUID();
  5600. this.data = interleavedBuffer;
  5601. this.itemSize = itemSize;
  5602. this.offset = offset;
  5603. };
  5604. THREE.InterleavedBufferAttribute.prototype = {
  5605. constructor: THREE.InterleavedBufferAttribute,
  5606. get length() {
  5607. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Please use .count.' );
  5608. return this.array.length;
  5609. },
  5610. get count() {
  5611. return this.data.array.length / this.data.stride;
  5612. },
  5613. setX: function ( index, x ) {
  5614. this.data.array[ index * this.data.stride + this.offset ] = x;
  5615. return this;
  5616. },
  5617. setY: function ( index, y ) {
  5618. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  5619. return this;
  5620. },
  5621. setZ: function ( index, z ) {
  5622. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  5623. return this;
  5624. },
  5625. setW: function ( index, w ) {
  5626. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  5627. return this;
  5628. },
  5629. getX: function ( index ) {
  5630. return this.data.array[ index * this.data.stride + this.offset ];
  5631. },
  5632. getY: function ( index ) {
  5633. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  5634. },
  5635. getZ: function ( index ) {
  5636. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  5637. },
  5638. getW: function ( index ) {
  5639. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  5640. },
  5641. setXY: function ( index, x, y ) {
  5642. index = index * this.data.stride + this.offset;
  5643. this.data.array[ index + 0 ] = x;
  5644. this.data.array[ index + 1 ] = y;
  5645. return this;
  5646. },
  5647. setXYZ: function ( index, x, y, z ) {
  5648. index = index * this.data.stride + this.offset;
  5649. this.data.array[ index + 0 ] = x;
  5650. this.data.array[ index + 1 ] = y;
  5651. this.data.array[ index + 2 ] = z;
  5652. return this;
  5653. },
  5654. setXYZW: function ( index, x, y, z, w ) {
  5655. index = index * this.data.stride + this.offset;
  5656. this.data.array[ index + 0 ] = x;
  5657. this.data.array[ index + 1 ] = y;
  5658. this.data.array[ index + 2 ] = z;
  5659. this.data.array[ index + 3 ] = w;
  5660. return this;
  5661. }
  5662. };
  5663. // File:src/core/Geometry.js
  5664. /**
  5665. * @author mrdoob / http://mrdoob.com/
  5666. * @author kile / http://kile.stravaganza.org/
  5667. * @author alteredq / http://alteredqualia.com/
  5668. * @author mikael emtinger / http://gomo.se/
  5669. * @author zz85 / http://www.lab4games.net/zz85/blog
  5670. * @author bhouston / http://clara.io
  5671. */
  5672. THREE.Geometry = function () {
  5673. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  5674. this.uuid = THREE.Math.generateUUID();
  5675. this.name = '';
  5676. this.type = 'Geometry';
  5677. this.vertices = [];
  5678. this.colors = [];
  5679. this.faces = [];
  5680. this.faceVertexUvs = [ [] ];
  5681. this.morphTargets = [];
  5682. this.morphNormals = [];
  5683. this.skinWeights = [];
  5684. this.skinIndices = [];
  5685. this.lineDistances = [];
  5686. this.boundingBox = null;
  5687. this.boundingSphere = null;
  5688. // update flags
  5689. this.verticesNeedUpdate = false;
  5690. this.elementsNeedUpdate = false;
  5691. this.uvsNeedUpdate = false;
  5692. this.normalsNeedUpdate = false;
  5693. this.colorsNeedUpdate = false;
  5694. this.lineDistancesNeedUpdate = false;
  5695. this.groupsNeedUpdate = false;
  5696. };
  5697. THREE.Geometry.prototype = {
  5698. constructor: THREE.Geometry,
  5699. applyMatrix: function ( matrix ) {
  5700. var normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  5701. for ( var i = 0, il = this.vertices.length; i < il; i ++ ) {
  5702. var vertex = this.vertices[ i ];
  5703. vertex.applyMatrix4( matrix );
  5704. }
  5705. for ( var i = 0, il = this.faces.length; i < il; i ++ ) {
  5706. var face = this.faces[ i ];
  5707. face.normal.applyMatrix3( normalMatrix ).normalize();
  5708. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  5709. face.vertexNormals[ j ].applyMatrix3( normalMatrix ).normalize();
  5710. }
  5711. }
  5712. if ( this.boundingBox !== null ) {
  5713. this.computeBoundingBox();
  5714. }
  5715. if ( this.boundingSphere !== null ) {
  5716. this.computeBoundingSphere();
  5717. }
  5718. this.verticesNeedUpdate = true;
  5719. this.normalsNeedUpdate = true;
  5720. },
  5721. rotateX: function () {
  5722. // rotate geometry around world x-axis
  5723. var m1;
  5724. return function rotateX( angle ) {
  5725. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5726. m1.makeRotationX( angle );
  5727. this.applyMatrix( m1 );
  5728. return this;
  5729. };
  5730. }(),
  5731. rotateY: function () {
  5732. // rotate geometry around world y-axis
  5733. var m1;
  5734. return function rotateY( angle ) {
  5735. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5736. m1.makeRotationY( angle );
  5737. this.applyMatrix( m1 );
  5738. return this;
  5739. };
  5740. }(),
  5741. rotateZ: function () {
  5742. // rotate geometry around world z-axis
  5743. var m1;
  5744. return function rotateZ( angle ) {
  5745. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5746. m1.makeRotationZ( angle );
  5747. this.applyMatrix( m1 );
  5748. return this;
  5749. };
  5750. }(),
  5751. translate: function () {
  5752. // translate geometry
  5753. var m1;
  5754. return function translate( x, y, z ) {
  5755. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5756. m1.makeTranslation( x, y, z );
  5757. this.applyMatrix( m1 );
  5758. return this;
  5759. };
  5760. }(),
  5761. scale: function () {
  5762. // scale geometry
  5763. var m1;
  5764. return function scale( x, y, z ) {
  5765. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5766. m1.makeScale( x, y, z );
  5767. this.applyMatrix( m1 );
  5768. return this;
  5769. };
  5770. }(),
  5771. lookAt: function () {
  5772. var obj;
  5773. return function lookAt( vector ) {
  5774. if ( obj === undefined ) obj = new THREE.Object3D();
  5775. obj.lookAt( vector );
  5776. obj.updateMatrix();
  5777. this.applyMatrix( obj.matrix );
  5778. };
  5779. }(),
  5780. fromBufferGeometry: function ( geometry ) {
  5781. var scope = this;
  5782. var indices = geometry.index !== null ? geometry.index.array : undefined;
  5783. var attributes = geometry.attributes;
  5784. var vertices = attributes.position.array;
  5785. var normals = attributes.normal !== undefined ? attributes.normal.array : undefined;
  5786. var colors = attributes.color !== undefined ? attributes.color.array : undefined;
  5787. var uvs = attributes.uv !== undefined ? attributes.uv.array : undefined;
  5788. var uvs2 = attributes.uv2 !== undefined ? attributes.uv2.array : undefined;
  5789. if ( uvs2 !== undefined ) this.faceVertexUvs[ 1 ] = [];
  5790. var tempNormals = [];
  5791. var tempUVs = [];
  5792. var tempUVs2 = [];
  5793. for ( var i = 0, j = 0, k = 0; i < vertices.length; i += 3, j += 2, k += 4 ) {
  5794. scope.vertices.push( new THREE.Vector3( vertices[ i ], vertices[ i + 1 ], vertices[ i + 2 ] ) );
  5795. if ( normals !== undefined ) {
  5796. tempNormals.push( new THREE.Vector3( normals[ i ], normals[ i + 1 ], normals[ i + 2 ] ) );
  5797. }
  5798. if ( colors !== undefined ) {
  5799. scope.colors.push( new THREE.Color( colors[ i ], colors[ i + 1 ], colors[ i + 2 ] ) );
  5800. }
  5801. if ( uvs !== undefined ) {
  5802. tempUVs.push( new THREE.Vector2( uvs[ j ], uvs[ j + 1 ] ) );
  5803. }
  5804. if ( uvs2 !== undefined ) {
  5805. tempUVs2.push( new THREE.Vector2( uvs2[ j ], uvs2[ j + 1 ] ) );
  5806. }
  5807. }
  5808. function addFace( a, b, c ) {
  5809. var vertexNormals = normals !== undefined ? [ tempNormals[ a ].clone(), tempNormals[ b ].clone(), tempNormals[ c ].clone() ] : [];
  5810. var vertexColors = colors !== undefined ? [ scope.colors[ a ].clone(), scope.colors[ b ].clone(), scope.colors[ c ].clone() ] : [];
  5811. var face = new THREE.Face3( a, b, c, vertexNormals, vertexColors );
  5812. scope.faces.push( face );
  5813. if ( uvs !== undefined ) {
  5814. scope.faceVertexUvs[ 0 ].push( [ tempUVs[ a ].clone(), tempUVs[ b ].clone(), tempUVs[ c ].clone() ] );
  5815. }
  5816. if ( uvs2 !== undefined ) {
  5817. scope.faceVertexUvs[ 1 ].push( [ tempUVs2[ a ].clone(), tempUVs2[ b ].clone(), tempUVs2[ c ].clone() ] );
  5818. }
  5819. };
  5820. if ( indices !== undefined ) {
  5821. var groups = geometry.groups;
  5822. if ( groups.length > 0 ) {
  5823. for ( var i = 0; i < groups.length; i ++ ) {
  5824. var group = groups[ i ];
  5825. var start = group.start;
  5826. var count = group.count;
  5827. for ( var j = start, jl = start + count; j < jl; j += 3 ) {
  5828. addFace( indices[ j ], indices[ j + 1 ], indices[ j + 2 ] );
  5829. }
  5830. }
  5831. } else {
  5832. for ( var i = 0; i < indices.length; i += 3 ) {
  5833. addFace( indices[ i ], indices[ i + 1 ], indices[ i + 2 ] );
  5834. }
  5835. }
  5836. } else {
  5837. for ( var i = 0; i < vertices.length / 3; i += 3 ) {
  5838. addFace( i, i + 1, i + 2 );
  5839. }
  5840. }
  5841. this.computeFaceNormals();
  5842. if ( geometry.boundingBox !== null ) {
  5843. this.boundingBox = geometry.boundingBox.clone();
  5844. }
  5845. if ( geometry.boundingSphere !== null ) {
  5846. this.boundingSphere = geometry.boundingSphere.clone();
  5847. }
  5848. return this;
  5849. },
  5850. center: function () {
  5851. this.computeBoundingBox();
  5852. var offset = this.boundingBox.center().negate();
  5853. this.translate( offset.x, offset.y, offset.z );
  5854. return offset;
  5855. },
  5856. normalize: function () {
  5857. this.computeBoundingSphere();
  5858. var center = this.boundingSphere.center;
  5859. var radius = this.boundingSphere.radius;
  5860. var s = radius === 0 ? 1 : 1.0 / radius;
  5861. var matrix = new THREE.Matrix4();
  5862. matrix.set(
  5863. s, 0, 0, - s * center.x,
  5864. 0, s, 0, - s * center.y,
  5865. 0, 0, s, - s * center.z,
  5866. 0, 0, 0, 1
  5867. );
  5868. this.applyMatrix( matrix );
  5869. return this;
  5870. },
  5871. computeFaceNormals: function () {
  5872. var cb = new THREE.Vector3(), ab = new THREE.Vector3();
  5873. for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5874. var face = this.faces[ f ];
  5875. var vA = this.vertices[ face.a ];
  5876. var vB = this.vertices[ face.b ];
  5877. var vC = this.vertices[ face.c ];
  5878. cb.subVectors( vC, vB );
  5879. ab.subVectors( vA, vB );
  5880. cb.cross( ab );
  5881. cb.normalize();
  5882. face.normal.copy( cb );
  5883. }
  5884. },
  5885. computeVertexNormals: function ( areaWeighted ) {
  5886. var v, vl, f, fl, face, vertices;
  5887. vertices = new Array( this.vertices.length );
  5888. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5889. vertices[ v ] = new THREE.Vector3();
  5890. }
  5891. if ( areaWeighted ) {
  5892. // vertex normals weighted by triangle areas
  5893. // http://www.iquilezles.org/www/articles/normals/normals.htm
  5894. var vA, vB, vC;
  5895. var cb = new THREE.Vector3(), ab = new THREE.Vector3();
  5896. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5897. face = this.faces[ f ];
  5898. vA = this.vertices[ face.a ];
  5899. vB = this.vertices[ face.b ];
  5900. vC = this.vertices[ face.c ];
  5901. cb.subVectors( vC, vB );
  5902. ab.subVectors( vA, vB );
  5903. cb.cross( ab );
  5904. vertices[ face.a ].add( cb );
  5905. vertices[ face.b ].add( cb );
  5906. vertices[ face.c ].add( cb );
  5907. }
  5908. } else {
  5909. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5910. face = this.faces[ f ];
  5911. vertices[ face.a ].add( face.normal );
  5912. vertices[ face.b ].add( face.normal );
  5913. vertices[ face.c ].add( face.normal );
  5914. }
  5915. }
  5916. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5917. vertices[ v ].normalize();
  5918. }
  5919. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5920. face = this.faces[ f ];
  5921. var vertexNormals = face.vertexNormals;
  5922. if ( vertexNormals.length === 3 ) {
  5923. vertexNormals[ 0 ].copy( vertices[ face.a ] );
  5924. vertexNormals[ 1 ].copy( vertices[ face.b ] );
  5925. vertexNormals[ 2 ].copy( vertices[ face.c ] );
  5926. } else {
  5927. vertexNormals[ 0 ] = vertices[ face.a ].clone();
  5928. vertexNormals[ 1 ] = vertices[ face.b ].clone();
  5929. vertexNormals[ 2 ] = vertices[ face.c ].clone();
  5930. }
  5931. }
  5932. },
  5933. computeMorphNormals: function () {
  5934. var i, il, f, fl, face;
  5935. // save original normals
  5936. // - create temp variables on first access
  5937. // otherwise just copy (for faster repeated calls)
  5938. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5939. face = this.faces[ f ];
  5940. if ( ! face.__originalFaceNormal ) {
  5941. face.__originalFaceNormal = face.normal.clone();
  5942. } else {
  5943. face.__originalFaceNormal.copy( face.normal );
  5944. }
  5945. if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
  5946. for ( i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
  5947. if ( ! face.__originalVertexNormals[ i ] ) {
  5948. face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
  5949. } else {
  5950. face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
  5951. }
  5952. }
  5953. }
  5954. // use temp geometry to compute face and vertex normals for each morph
  5955. var tmpGeo = new THREE.Geometry();
  5956. tmpGeo.faces = this.faces;
  5957. for ( i = 0, il = this.morphTargets.length; i < il; i ++ ) {
  5958. // create on first access
  5959. if ( ! this.morphNormals[ i ] ) {
  5960. this.morphNormals[ i ] = {};
  5961. this.morphNormals[ i ].faceNormals = [];
  5962. this.morphNormals[ i ].vertexNormals = [];
  5963. var dstNormalsFace = this.morphNormals[ i ].faceNormals;
  5964. var dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
  5965. var faceNormal, vertexNormals;
  5966. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5967. faceNormal = new THREE.Vector3();
  5968. vertexNormals = { a: new THREE.Vector3(), b: new THREE.Vector3(), c: new THREE.Vector3() };
  5969. dstNormalsFace.push( faceNormal );
  5970. dstNormalsVertex.push( vertexNormals );
  5971. }
  5972. }
  5973. var morphNormals = this.morphNormals[ i ];
  5974. // set vertices to morph target
  5975. tmpGeo.vertices = this.morphTargets[ i ].vertices;
  5976. // compute morph normals
  5977. tmpGeo.computeFaceNormals();
  5978. tmpGeo.computeVertexNormals();
  5979. // store morph normals
  5980. var faceNormal, vertexNormals;
  5981. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5982. face = this.faces[ f ];
  5983. faceNormal = morphNormals.faceNormals[ f ];
  5984. vertexNormals = morphNormals.vertexNormals[ f ];
  5985. faceNormal.copy( face.normal );
  5986. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  5987. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  5988. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  5989. }
  5990. }
  5991. // restore original normals
  5992. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5993. face = this.faces[ f ];
  5994. face.normal = face.__originalFaceNormal;
  5995. face.vertexNormals = face.__originalVertexNormals;
  5996. }
  5997. },
  5998. computeTangents: function () {
  5999. console.warn( 'THREE.Geometry: .computeTangents() has been removed.' );
  6000. },
  6001. computeLineDistances: function () {
  6002. var d = 0;
  6003. var vertices = this.vertices;
  6004. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  6005. if ( i > 0 ) {
  6006. d += vertices[ i ].distanceTo( vertices[ i - 1 ] );
  6007. }
  6008. this.lineDistances[ i ] = d;
  6009. }
  6010. },
  6011. computeBoundingBox: function () {
  6012. if ( this.boundingBox === null ) {
  6013. this.boundingBox = new THREE.Box3();
  6014. }
  6015. this.boundingBox.setFromPoints( this.vertices );
  6016. },
  6017. computeBoundingSphere: function () {
  6018. if ( this.boundingSphere === null ) {
  6019. this.boundingSphere = new THREE.Sphere();
  6020. }
  6021. this.boundingSphere.setFromPoints( this.vertices );
  6022. },
  6023. merge: function ( geometry, matrix, materialIndexOffset ) {
  6024. if ( geometry instanceof THREE.Geometry === false ) {
  6025. console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry );
  6026. return;
  6027. }
  6028. var normalMatrix,
  6029. vertexOffset = this.vertices.length,
  6030. vertices1 = this.vertices,
  6031. vertices2 = geometry.vertices,
  6032. faces1 = this.faces,
  6033. faces2 = geometry.faces,
  6034. uvs1 = this.faceVertexUvs[ 0 ],
  6035. uvs2 = geometry.faceVertexUvs[ 0 ];
  6036. if ( materialIndexOffset === undefined ) materialIndexOffset = 0;
  6037. if ( matrix !== undefined ) {
  6038. normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  6039. }
  6040. // vertices
  6041. for ( var i = 0, il = vertices2.length; i < il; i ++ ) {
  6042. var vertex = vertices2[ i ];
  6043. var vertexCopy = vertex.clone();
  6044. if ( matrix !== undefined ) vertexCopy.applyMatrix4( matrix );
  6045. vertices1.push( vertexCopy );
  6046. }
  6047. // faces
  6048. for ( i = 0, il = faces2.length; i < il; i ++ ) {
  6049. var face = faces2[ i ], faceCopy, normal, color,
  6050. faceVertexNormals = face.vertexNormals,
  6051. faceVertexColors = face.vertexColors;
  6052. faceCopy = new THREE.Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset );
  6053. faceCopy.normal.copy( face.normal );
  6054. if ( normalMatrix !== undefined ) {
  6055. faceCopy.normal.applyMatrix3( normalMatrix ).normalize();
  6056. }
  6057. for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
  6058. normal = faceVertexNormals[ j ].clone();
  6059. if ( normalMatrix !== undefined ) {
  6060. normal.applyMatrix3( normalMatrix ).normalize();
  6061. }
  6062. faceCopy.vertexNormals.push( normal );
  6063. }
  6064. faceCopy.color.copy( face.color );
  6065. for ( var j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
  6066. color = faceVertexColors[ j ];
  6067. faceCopy.vertexColors.push( color.clone() );
  6068. }
  6069. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  6070. faces1.push( faceCopy );
  6071. }
  6072. // uvs
  6073. for ( i = 0, il = uvs2.length; i < il; i ++ ) {
  6074. var uv = uvs2[ i ], uvCopy = [];
  6075. if ( uv === undefined ) {
  6076. continue;
  6077. }
  6078. for ( var j = 0, jl = uv.length; j < jl; j ++ ) {
  6079. uvCopy.push( uv[ j ].clone() );
  6080. }
  6081. uvs1.push( uvCopy );
  6082. }
  6083. },
  6084. mergeMesh: function ( mesh ) {
  6085. if ( mesh instanceof THREE.Mesh === false ) {
  6086. console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh );
  6087. return;
  6088. }
  6089. mesh.matrixAutoUpdate && mesh.updateMatrix();
  6090. this.merge( mesh.geometry, mesh.matrix );
  6091. },
  6092. /*
  6093. * Checks for duplicate vertices with hashmap.
  6094. * Duplicated vertices are removed
  6095. * and faces' vertices are updated.
  6096. */
  6097. mergeVertices: function () {
  6098. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  6099. var unique = [], changes = [];
  6100. var v, key;
  6101. var precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001
  6102. var precision = Math.pow( 10, precisionPoints );
  6103. var i, il, face;
  6104. var indices, j, jl;
  6105. for ( i = 0, il = this.vertices.length; i < il; i ++ ) {
  6106. v = this.vertices[ i ];
  6107. key = Math.round( v.x * precision ) + '_' + Math.round( v.y * precision ) + '_' + Math.round( v.z * precision );
  6108. if ( verticesMap[ key ] === undefined ) {
  6109. verticesMap[ key ] = i;
  6110. unique.push( this.vertices[ i ] );
  6111. changes[ i ] = unique.length - 1;
  6112. } else {
  6113. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  6114. changes[ i ] = changes[ verticesMap[ key ] ];
  6115. }
  6116. }
  6117. // if faces are completely degenerate after merging vertices, we
  6118. // have to remove them from the geometry.
  6119. var faceIndicesToRemove = [];
  6120. for ( i = 0, il = this.faces.length; i < il; i ++ ) {
  6121. face = this.faces[ i ];
  6122. face.a = changes[ face.a ];
  6123. face.b = changes[ face.b ];
  6124. face.c = changes[ face.c ];
  6125. indices = [ face.a, face.b, face.c ];
  6126. var dupIndex = - 1;
  6127. // if any duplicate vertices are found in a Face3
  6128. // we have to remove the face as nothing can be saved
  6129. for ( var n = 0; n < 3; n ++ ) {
  6130. if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) {
  6131. dupIndex = n;
  6132. faceIndicesToRemove.push( i );
  6133. break;
  6134. }
  6135. }
  6136. }
  6137. for ( i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
  6138. var idx = faceIndicesToRemove[ i ];
  6139. this.faces.splice( idx, 1 );
  6140. for ( j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {
  6141. this.faceVertexUvs[ j ].splice( idx, 1 );
  6142. }
  6143. }
  6144. // Use unique set of vertices
  6145. var diff = this.vertices.length - unique.length;
  6146. this.vertices = unique;
  6147. return diff;
  6148. },
  6149. sortFacesByMaterialIndex: function () {
  6150. var faces = this.faces;
  6151. var length = faces.length;
  6152. // tag faces
  6153. for ( var i = 0; i < length; i ++ ) {
  6154. faces[ i ]._id = i;
  6155. }
  6156. // sort faces
  6157. function materialIndexSort( a, b ) {
  6158. return a.materialIndex - b.materialIndex;
  6159. }
  6160. faces.sort( materialIndexSort );
  6161. // sort uvs
  6162. var uvs1 = this.faceVertexUvs[ 0 ];
  6163. var uvs2 = this.faceVertexUvs[ 1 ];
  6164. var newUvs1, newUvs2;
  6165. if ( uvs1 && uvs1.length === length ) newUvs1 = [];
  6166. if ( uvs2 && uvs2.length === length ) newUvs2 = [];
  6167. for ( var i = 0; i < length; i ++ ) {
  6168. var id = faces[ i ]._id;
  6169. if ( newUvs1 ) newUvs1.push( uvs1[ id ] );
  6170. if ( newUvs2 ) newUvs2.push( uvs2[ id ] );
  6171. }
  6172. if ( newUvs1 ) this.faceVertexUvs[ 0 ] = newUvs1;
  6173. if ( newUvs2 ) this.faceVertexUvs[ 1 ] = newUvs2;
  6174. },
  6175. toJSON: function () {
  6176. var data = {
  6177. metadata: {
  6178. version: 4.4,
  6179. type: 'Geometry',
  6180. generator: 'Geometry.toJSON'
  6181. }
  6182. };
  6183. // standard Geometry serialization
  6184. data.uuid = this.uuid;
  6185. data.type = this.type;
  6186. if ( this.name !== '' ) data.name = this.name;
  6187. if ( this.parameters !== undefined ) {
  6188. var parameters = this.parameters;
  6189. for ( var key in parameters ) {
  6190. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  6191. }
  6192. return data;
  6193. }
  6194. var vertices = [];
  6195. for ( var i = 0; i < this.vertices.length; i ++ ) {
  6196. var vertex = this.vertices[ i ];
  6197. vertices.push( vertex.x, vertex.y, vertex.z );
  6198. }
  6199. var faces = [];
  6200. var normals = [];
  6201. var normalsHash = {};
  6202. var colors = [];
  6203. var colorsHash = {};
  6204. var uvs = [];
  6205. var uvsHash = {};
  6206. for ( var i = 0; i < this.faces.length; i ++ ) {
  6207. var face = this.faces[ i ];
  6208. var hasMaterial = true;
  6209. var hasFaceUv = false; // deprecated
  6210. var hasFaceVertexUv = this.faceVertexUvs[ 0 ][ i ] !== undefined;
  6211. var hasFaceNormal = face.normal.length() > 0;
  6212. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  6213. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  6214. var hasFaceVertexColor = face.vertexColors.length > 0;
  6215. var faceType = 0;
  6216. faceType = setBit( faceType, 0, 0 ); // isQuad
  6217. faceType = setBit( faceType, 1, hasMaterial );
  6218. faceType = setBit( faceType, 2, hasFaceUv );
  6219. faceType = setBit( faceType, 3, hasFaceVertexUv );
  6220. faceType = setBit( faceType, 4, hasFaceNormal );
  6221. faceType = setBit( faceType, 5, hasFaceVertexNormal );
  6222. faceType = setBit( faceType, 6, hasFaceColor );
  6223. faceType = setBit( faceType, 7, hasFaceVertexColor );
  6224. faces.push( faceType );
  6225. faces.push( face.a, face.b, face.c );
  6226. faces.push( face.materialIndex );
  6227. if ( hasFaceVertexUv ) {
  6228. var faceVertexUvs = this.faceVertexUvs[ 0 ][ i ];
  6229. faces.push(
  6230. getUvIndex( faceVertexUvs[ 0 ] ),
  6231. getUvIndex( faceVertexUvs[ 1 ] ),
  6232. getUvIndex( faceVertexUvs[ 2 ] )
  6233. );
  6234. }
  6235. if ( hasFaceNormal ) {
  6236. faces.push( getNormalIndex( face.normal ) );
  6237. }
  6238. if ( hasFaceVertexNormal ) {
  6239. var vertexNormals = face.vertexNormals;
  6240. faces.push(
  6241. getNormalIndex( vertexNormals[ 0 ] ),
  6242. getNormalIndex( vertexNormals[ 1 ] ),
  6243. getNormalIndex( vertexNormals[ 2 ] )
  6244. );
  6245. }
  6246. if ( hasFaceColor ) {
  6247. faces.push( getColorIndex( face.color ) );
  6248. }
  6249. if ( hasFaceVertexColor ) {
  6250. var vertexColors = face.vertexColors;
  6251. faces.push(
  6252. getColorIndex( vertexColors[ 0 ] ),
  6253. getColorIndex( vertexColors[ 1 ] ),
  6254. getColorIndex( vertexColors[ 2 ] )
  6255. );
  6256. }
  6257. }
  6258. function setBit( value, position, enabled ) {
  6259. return enabled ? value | ( 1 << position ) : value & ( ~ ( 1 << position ) );
  6260. }
  6261. function getNormalIndex( normal ) {
  6262. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  6263. if ( normalsHash[ hash ] !== undefined ) {
  6264. return normalsHash[ hash ];
  6265. }
  6266. normalsHash[ hash ] = normals.length / 3;
  6267. normals.push( normal.x, normal.y, normal.z );
  6268. return normalsHash[ hash ];
  6269. }
  6270. function getColorIndex( color ) {
  6271. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  6272. if ( colorsHash[ hash ] !== undefined ) {
  6273. return colorsHash[ hash ];
  6274. }
  6275. colorsHash[ hash ] = colors.length;
  6276. colors.push( color.getHex() );
  6277. return colorsHash[ hash ];
  6278. }
  6279. function getUvIndex( uv ) {
  6280. var hash = uv.x.toString() + uv.y.toString();
  6281. if ( uvsHash[ hash ] !== undefined ) {
  6282. return uvsHash[ hash ];
  6283. }
  6284. uvsHash[ hash ] = uvs.length / 2;
  6285. uvs.push( uv.x, uv.y );
  6286. return uvsHash[ hash ];
  6287. }
  6288. data.data = {};
  6289. data.data.vertices = vertices;
  6290. data.data.normals = normals;
  6291. if ( colors.length > 0 ) data.data.colors = colors;
  6292. if ( uvs.length > 0 ) data.data.uvs = [ uvs ]; // temporal backward compatibility
  6293. data.data.faces = faces;
  6294. return data;
  6295. },
  6296. clone: function () {
  6297. // Handle primitives
  6298. var parameters = this.parameters;
  6299. if ( parameters !== undefined ) {
  6300. var values = [];
  6301. for ( var key in parameters ) {
  6302. values.push( parameters[ key ] );
  6303. }
  6304. var geometry = Object.create( this.constructor.prototype );
  6305. this.constructor.apply( geometry, values );
  6306. return geometry;
  6307. }
  6308. return new this.constructor().copy( this );
  6309. },
  6310. copy: function ( source ) {
  6311. this.vertices = [];
  6312. this.faces = [];
  6313. this.faceVertexUvs = [ [] ];
  6314. var vertices = source.vertices;
  6315. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  6316. this.vertices.push( vertices[ i ].clone() );
  6317. }
  6318. var faces = source.faces;
  6319. for ( var i = 0, il = faces.length; i < il; i ++ ) {
  6320. this.faces.push( faces[ i ].clone() );
  6321. }
  6322. for ( var i = 0, il = source.faceVertexUvs.length; i < il; i ++ ) {
  6323. var faceVertexUvs = source.faceVertexUvs[ i ];
  6324. if ( this.faceVertexUvs[ i ] === undefined ) {
  6325. this.faceVertexUvs[ i ] = [];
  6326. }
  6327. for ( var j = 0, jl = faceVertexUvs.length; j < jl; j ++ ) {
  6328. var uvs = faceVertexUvs[ j ], uvsCopy = [];
  6329. for ( var k = 0, kl = uvs.length; k < kl; k ++ ) {
  6330. var uv = uvs[ k ];
  6331. uvsCopy.push( uv.clone() );
  6332. }
  6333. this.faceVertexUvs[ i ].push( uvsCopy );
  6334. }
  6335. }
  6336. return this;
  6337. },
  6338. dispose: function () {
  6339. this.dispatchEvent( { type: 'dispose' } );
  6340. }
  6341. };
  6342. THREE.EventDispatcher.prototype.apply( THREE.Geometry.prototype );
  6343. THREE.GeometryIdCount = 0;
  6344. // File:src/core/DirectGeometry.js
  6345. /**
  6346. * @author mrdoob / http://mrdoob.com/
  6347. */
  6348. THREE.DirectGeometry = function () {
  6349. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  6350. this.uuid = THREE.Math.generateUUID();
  6351. this.name = '';
  6352. this.type = 'DirectGeometry';
  6353. this.indices = [];
  6354. this.vertices = [];
  6355. this.normals = [];
  6356. this.colors = [];
  6357. this.uvs = [];
  6358. this.uvs2 = [];
  6359. this.groups = [];
  6360. this.morphTargets = {};
  6361. this.skinWeights = [];
  6362. this.skinIndices = [];
  6363. // this.lineDistances = [];
  6364. this.boundingBox = null;
  6365. this.boundingSphere = null;
  6366. // update flags
  6367. this.verticesNeedUpdate = false;
  6368. this.normalsNeedUpdate = false;
  6369. this.colorsNeedUpdate = false;
  6370. this.uvsNeedUpdate = false;
  6371. this.groupsNeedUpdate = false;
  6372. };
  6373. THREE.DirectGeometry.prototype = {
  6374. constructor: THREE.DirectGeometry,
  6375. computeBoundingBox: THREE.Geometry.prototype.computeBoundingBox,
  6376. computeBoundingSphere: THREE.Geometry.prototype.computeBoundingSphere,
  6377. computeFaceNormals: function () {
  6378. console.warn( 'THREE.DirectGeometry: computeFaceNormals() is not a method of this type of geometry.' );
  6379. },
  6380. computeVertexNormals: function () {
  6381. console.warn( 'THREE.DirectGeometry: computeVertexNormals() is not a method of this type of geometry.' );
  6382. },
  6383. computeGroups: function ( geometry ) {
  6384. var group;
  6385. var groups = [];
  6386. var materialIndex;
  6387. var faces = geometry.faces;
  6388. for ( var i = 0; i < faces.length; i ++ ) {
  6389. var face = faces[ i ];
  6390. // materials
  6391. if ( face.materialIndex !== materialIndex ) {
  6392. materialIndex = face.materialIndex;
  6393. if ( group !== undefined ) {
  6394. group.count = ( i * 3 ) - group.start;
  6395. groups.push( group );
  6396. }
  6397. group = {
  6398. start: i * 3,
  6399. materialIndex: materialIndex
  6400. };
  6401. }
  6402. }
  6403. if ( group !== undefined ) {
  6404. group.count = ( i * 3 ) - group.start;
  6405. groups.push( group );
  6406. }
  6407. this.groups = groups;
  6408. },
  6409. fromGeometry: function ( geometry ) {
  6410. var faces = geometry.faces;
  6411. var vertices = geometry.vertices;
  6412. var faceVertexUvs = geometry.faceVertexUvs;
  6413. var hasFaceVertexUv = faceVertexUvs[ 0 ] && faceVertexUvs[ 0 ].length > 0;
  6414. var hasFaceVertexUv2 = faceVertexUvs[ 1 ] && faceVertexUvs[ 1 ].length > 0;
  6415. // morphs
  6416. var morphTargets = geometry.morphTargets;
  6417. var morphTargetsLength = morphTargets.length;
  6418. if ( morphTargetsLength > 0 ) {
  6419. var morphTargetsPosition = [];
  6420. for ( var i = 0; i < morphTargetsLength; i ++ ) {
  6421. morphTargetsPosition[ i ] = [];
  6422. }
  6423. this.morphTargets.position = morphTargetsPosition;
  6424. }
  6425. var morphNormals = geometry.morphNormals;
  6426. var morphNormalsLength = morphNormals.length;
  6427. if ( morphNormalsLength > 0 ) {
  6428. var morphTargetsNormal = [];
  6429. for ( var i = 0; i < morphNormalsLength; i ++ ) {
  6430. morphTargetsNormal[ i ] = [];
  6431. }
  6432. this.morphTargets.normal = morphTargetsNormal;
  6433. }
  6434. // skins
  6435. var skinIndices = geometry.skinIndices;
  6436. var skinWeights = geometry.skinWeights;
  6437. var hasSkinIndices = skinIndices.length === vertices.length;
  6438. var hasSkinWeights = skinWeights.length === vertices.length;
  6439. //
  6440. for ( var i = 0; i < faces.length; i ++ ) {
  6441. var face = faces[ i ];
  6442. this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] );
  6443. var vertexNormals = face.vertexNormals;
  6444. if ( vertexNormals.length === 3 ) {
  6445. this.normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
  6446. } else {
  6447. var normal = face.normal;
  6448. this.normals.push( normal, normal, normal );
  6449. }
  6450. var vertexColors = face.vertexColors;
  6451. if ( vertexColors.length === 3 ) {
  6452. this.colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
  6453. } else {
  6454. var color = face.color;
  6455. this.colors.push( color, color, color );
  6456. }
  6457. if ( hasFaceVertexUv === true ) {
  6458. var vertexUvs = faceVertexUvs[ 0 ][ i ];
  6459. if ( vertexUvs !== undefined ) {
  6460. this.uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6461. } else {
  6462. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', i );
  6463. this.uvs.push( new THREE.Vector2(), new THREE.Vector2(), new THREE.Vector2() );
  6464. }
  6465. }
  6466. if ( hasFaceVertexUv2 === true ) {
  6467. var vertexUvs = faceVertexUvs[ 1 ][ i ];
  6468. if ( vertexUvs !== undefined ) {
  6469. this.uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6470. } else {
  6471. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', i );
  6472. this.uvs2.push( new THREE.Vector2(), new THREE.Vector2(), new THREE.Vector2() );
  6473. }
  6474. }
  6475. // morphs
  6476. for ( var j = 0; j < morphTargetsLength; j ++ ) {
  6477. var morphTarget = morphTargets[ j ].vertices;
  6478. morphTargetsPosition[ j ].push( morphTarget[ face.a ], morphTarget[ face.b ], morphTarget[ face.c ] );
  6479. }
  6480. for ( var j = 0; j < morphNormalsLength; j ++ ) {
  6481. var morphNormal = morphNormals[ j ].vertexNormals[ i ];
  6482. morphTargetsNormal[ j ].push( morphNormal.a, morphNormal.b, morphNormal.c );
  6483. }
  6484. // skins
  6485. if ( hasSkinIndices ) {
  6486. this.skinIndices.push( skinIndices[ face.a ], skinIndices[ face.b ], skinIndices[ face.c ] );
  6487. }
  6488. if ( hasSkinWeights ) {
  6489. this.skinWeights.push( skinWeights[ face.a ], skinWeights[ face.b ], skinWeights[ face.c ] );
  6490. }
  6491. }
  6492. this.computeGroups( geometry );
  6493. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6494. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6495. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6496. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6497. this.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6498. return this;
  6499. },
  6500. dispose: function () {
  6501. this.dispatchEvent( { type: 'dispose' } );
  6502. }
  6503. };
  6504. THREE.EventDispatcher.prototype.apply( THREE.DirectGeometry.prototype );
  6505. // File:src/core/BufferGeometry.js
  6506. /**
  6507. * @author alteredq / http://alteredqualia.com/
  6508. * @author mrdoob / http://mrdoob.com/
  6509. */
  6510. THREE.BufferGeometry = function () {
  6511. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  6512. this.uuid = THREE.Math.generateUUID();
  6513. this.name = '';
  6514. this.type = 'BufferGeometry';
  6515. this.index = null;
  6516. this.attributes = {};
  6517. this.morphAttributes = {};
  6518. this.groups = [];
  6519. this.boundingBox = null;
  6520. this.boundingSphere = null;
  6521. this.drawRange = { start: 0, count: Infinity };
  6522. };
  6523. THREE.BufferGeometry.prototype = {
  6524. constructor: THREE.BufferGeometry,
  6525. addIndex: function ( index ) {
  6526. console.warn( 'THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().' );
  6527. this.setIndex( index );
  6528. },
  6529. getIndex: function () {
  6530. return this.index;
  6531. },
  6532. setIndex: function ( index ) {
  6533. this.index = index;
  6534. },
  6535. addAttribute: function ( name, attribute ) {
  6536. if ( attribute instanceof THREE.BufferAttribute === false && attribute instanceof THREE.InterleavedBufferAttribute === false ) {
  6537. console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
  6538. this.addAttribute( name, new THREE.BufferAttribute( arguments[ 1 ], arguments[ 2 ] ) );
  6539. return;
  6540. }
  6541. if ( name === 'index' ) {
  6542. console.warn( 'THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.' );
  6543. this.setIndex( attribute );
  6544. return;
  6545. }
  6546. this.attributes[ name ] = attribute;
  6547. },
  6548. getAttribute: function ( name ) {
  6549. return this.attributes[ name ];
  6550. },
  6551. removeAttribute: function ( name ) {
  6552. delete this.attributes[ name ];
  6553. },
  6554. get drawcalls() {
  6555. console.error( 'THREE.BufferGeometry: .drawcalls has been renamed to .groups.' );
  6556. return this.groups;
  6557. },
  6558. get offsets() {
  6559. console.warn( 'THREE.BufferGeometry: .offsets has been renamed to .groups.' );
  6560. return this.groups;
  6561. },
  6562. addDrawCall: function ( start, count, indexOffset ) {
  6563. if ( indexOffset !== undefined ) {
  6564. console.warn( 'THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.' );
  6565. }
  6566. console.warn( 'THREE.BufferGeometry: .addDrawCall() is now .addGroup().' );
  6567. this.addGroup( start, count );
  6568. },
  6569. clearDrawCalls: function () {
  6570. console.warn( 'THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().' );
  6571. this.clearGroups();
  6572. },
  6573. addGroup: function ( start, count, materialIndex ) {
  6574. this.groups.push( {
  6575. start: start,
  6576. count: count,
  6577. materialIndex: materialIndex !== undefined ? materialIndex : 0
  6578. } );
  6579. },
  6580. clearGroups: function () {
  6581. this.groups = [];
  6582. },
  6583. setDrawRange: function ( start, count ) {
  6584. this.drawRange.start = start;
  6585. this.drawRange.count = count;
  6586. },
  6587. applyMatrix: function ( matrix ) {
  6588. var position = this.attributes.position;
  6589. if ( position !== undefined ) {
  6590. matrix.applyToVector3Array( position.array );
  6591. position.needsUpdate = true;
  6592. }
  6593. var normal = this.attributes.normal;
  6594. if ( normal !== undefined ) {
  6595. var normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  6596. normalMatrix.applyToVector3Array( normal.array );
  6597. normal.needsUpdate = true;
  6598. }
  6599. if ( this.boundingBox !== null ) {
  6600. this.computeBoundingBox();
  6601. }
  6602. if ( this.boundingSphere !== null ) {
  6603. this.computeBoundingSphere();
  6604. }
  6605. },
  6606. rotateX: function () {
  6607. // rotate geometry around world x-axis
  6608. var m1;
  6609. return function rotateX( angle ) {
  6610. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6611. m1.makeRotationX( angle );
  6612. this.applyMatrix( m1 );
  6613. return this;
  6614. };
  6615. }(),
  6616. rotateY: function () {
  6617. // rotate geometry around world y-axis
  6618. var m1;
  6619. return function rotateY( angle ) {
  6620. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6621. m1.makeRotationY( angle );
  6622. this.applyMatrix( m1 );
  6623. return this;
  6624. };
  6625. }(),
  6626. rotateZ: function () {
  6627. // rotate geometry around world z-axis
  6628. var m1;
  6629. return function rotateZ( angle ) {
  6630. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6631. m1.makeRotationZ( angle );
  6632. this.applyMatrix( m1 );
  6633. return this;
  6634. };
  6635. }(),
  6636. translate: function () {
  6637. // translate geometry
  6638. var m1;
  6639. return function translate( x, y, z ) {
  6640. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6641. m1.makeTranslation( x, y, z );
  6642. this.applyMatrix( m1 );
  6643. return this;
  6644. };
  6645. }(),
  6646. scale: function () {
  6647. // scale geometry
  6648. var m1;
  6649. return function scale( x, y, z ) {
  6650. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6651. m1.makeScale( x, y, z );
  6652. this.applyMatrix( m1 );
  6653. return this;
  6654. };
  6655. }(),
  6656. lookAt: function () {
  6657. var obj;
  6658. return function lookAt( vector ) {
  6659. if ( obj === undefined ) obj = new THREE.Object3D();
  6660. obj.lookAt( vector );
  6661. obj.updateMatrix();
  6662. this.applyMatrix( obj.matrix );
  6663. };
  6664. }(),
  6665. center: function () {
  6666. this.computeBoundingBox();
  6667. var offset = this.boundingBox.center().negate();
  6668. this.translate( offset.x, offset.y, offset.z );
  6669. return offset;
  6670. },
  6671. setFromObject: function ( object ) {
  6672. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  6673. var geometry = object.geometry;
  6674. if ( object instanceof THREE.Points || object instanceof THREE.Line ) {
  6675. var positions = new THREE.Float32Attribute( geometry.vertices.length * 3, 3 );
  6676. var colors = new THREE.Float32Attribute( geometry.colors.length * 3, 3 );
  6677. this.addAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) );
  6678. this.addAttribute( 'color', colors.copyColorsArray( geometry.colors ) );
  6679. if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) {
  6680. var lineDistances = new THREE.Float32Attribute( geometry.lineDistances.length, 1 );
  6681. this.addAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) );
  6682. }
  6683. if ( geometry.boundingSphere !== null ) {
  6684. this.boundingSphere = geometry.boundingSphere.clone();
  6685. }
  6686. if ( geometry.boundingBox !== null ) {
  6687. this.boundingBox = geometry.boundingBox.clone();
  6688. }
  6689. } else if ( object instanceof THREE.Mesh ) {
  6690. if ( geometry instanceof THREE.Geometry ) {
  6691. this.fromGeometry( geometry );
  6692. }
  6693. }
  6694. return this;
  6695. },
  6696. updateFromObject: function ( object ) {
  6697. var geometry = object.geometry;
  6698. if ( object instanceof THREE.Mesh ) {
  6699. var direct = geometry.__directGeometry;
  6700. if ( direct === undefined ) {
  6701. return this.fromGeometry( geometry );
  6702. }
  6703. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6704. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6705. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6706. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6707. direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6708. geometry.verticesNeedUpdate = false;
  6709. geometry.normalsNeedUpdate = false;
  6710. geometry.colorsNeedUpdate = false;
  6711. geometry.uvsNeedUpdate = false;
  6712. geometry.groupsNeedUpdate = false;
  6713. geometry = direct;
  6714. }
  6715. if ( geometry.verticesNeedUpdate === true ) {
  6716. var attribute = this.attributes.position;
  6717. if ( attribute !== undefined ) {
  6718. attribute.copyVector3sArray( geometry.vertices );
  6719. attribute.needsUpdate = true;
  6720. }
  6721. geometry.verticesNeedUpdate = false;
  6722. }
  6723. if ( geometry.normalsNeedUpdate === true ) {
  6724. var attribute = this.attributes.normal;
  6725. if ( attribute !== undefined ) {
  6726. attribute.copyVector3sArray( geometry.normals );
  6727. attribute.needsUpdate = true;
  6728. }
  6729. geometry.normalsNeedUpdate = false;
  6730. }
  6731. if ( geometry.colorsNeedUpdate === true ) {
  6732. var attribute = this.attributes.color;
  6733. if ( attribute !== undefined ) {
  6734. attribute.copyColorsArray( geometry.colors );
  6735. attribute.needsUpdate = true;
  6736. }
  6737. geometry.colorsNeedUpdate = false;
  6738. }
  6739. if ( geometry.uvsNeedUpdate ) {
  6740. var attribute = this.attributes.uv;
  6741. if ( attribute !== undefined ) {
  6742. attribute.copyVector2sArray( geometry.uvs );
  6743. attribute.needsUpdate = true;
  6744. }
  6745. geometry.uvsNeedUpdate = false;
  6746. }
  6747. if ( geometry.lineDistancesNeedUpdate ) {
  6748. var attribute = this.attributes.lineDistance;
  6749. if ( attribute !== undefined ) {
  6750. attribute.copyArray( geometry.lineDistances );
  6751. attribute.needsUpdate = true;
  6752. }
  6753. geometry.lineDistancesNeedUpdate = false;
  6754. }
  6755. if ( geometry.groupsNeedUpdate ) {
  6756. geometry.computeGroups( object.geometry );
  6757. this.groups = geometry.groups;
  6758. geometry.groupsNeedUpdate = false;
  6759. }
  6760. return this;
  6761. },
  6762. fromGeometry: function ( geometry ) {
  6763. geometry.__directGeometry = new THREE.DirectGeometry().fromGeometry( geometry );
  6764. return this.fromDirectGeometry( geometry.__directGeometry );
  6765. },
  6766. fromDirectGeometry: function ( geometry ) {
  6767. var positions = new Float32Array( geometry.vertices.length * 3 );
  6768. this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) );
  6769. if ( geometry.normals.length > 0 ) {
  6770. var normals = new Float32Array( geometry.normals.length * 3 );
  6771. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) );
  6772. }
  6773. if ( geometry.colors.length > 0 ) {
  6774. var colors = new Float32Array( geometry.colors.length * 3 );
  6775. this.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors ) );
  6776. }
  6777. if ( geometry.uvs.length > 0 ) {
  6778. var uvs = new Float32Array( geometry.uvs.length * 2 );
  6779. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs ) );
  6780. }
  6781. if ( geometry.uvs2.length > 0 ) {
  6782. var uvs2 = new Float32Array( geometry.uvs2.length * 2 );
  6783. this.addAttribute( 'uv2', new THREE.BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 ) );
  6784. }
  6785. if ( geometry.indices.length > 0 ) {
  6786. var TypeArray = geometry.vertices.length > 65535 ? Uint32Array : Uint16Array;
  6787. var indices = new TypeArray( geometry.indices.length * 3 );
  6788. this.setIndex( new THREE.BufferAttribute( indices, 1 ).copyIndicesArray( geometry.indices ) );
  6789. }
  6790. // groups
  6791. this.groups = geometry.groups;
  6792. // morphs
  6793. for ( var name in geometry.morphTargets ) {
  6794. var array = [];
  6795. var morphTargets = geometry.morphTargets[ name ];
  6796. for ( var i = 0, l = morphTargets.length; i < l; i ++ ) {
  6797. var morphTarget = morphTargets[ i ];
  6798. var attribute = new THREE.Float32Attribute( morphTarget.length * 3, 3 );
  6799. array.push( attribute.copyVector3sArray( morphTarget ) );
  6800. }
  6801. this.morphAttributes[ name ] = array;
  6802. }
  6803. // skinning
  6804. if ( geometry.skinIndices.length > 0 ) {
  6805. var skinIndices = new THREE.Float32Attribute( geometry.skinIndices.length * 4, 4 );
  6806. this.addAttribute( 'skinIndex', skinIndices.copyVector4sArray( geometry.skinIndices ) );
  6807. }
  6808. if ( geometry.skinWeights.length > 0 ) {
  6809. var skinWeights = new THREE.Float32Attribute( geometry.skinWeights.length * 4, 4 );
  6810. this.addAttribute( 'skinWeight', skinWeights.copyVector4sArray( geometry.skinWeights ) );
  6811. }
  6812. //
  6813. if ( geometry.boundingSphere !== null ) {
  6814. this.boundingSphere = geometry.boundingSphere.clone();
  6815. }
  6816. if ( geometry.boundingBox !== null ) {
  6817. this.boundingBox = geometry.boundingBox.clone();
  6818. }
  6819. return this;
  6820. },
  6821. computeBoundingBox: function () {
  6822. var vector = new THREE.Vector3();
  6823. return function () {
  6824. if ( this.boundingBox === null ) {
  6825. this.boundingBox = new THREE.Box3();
  6826. }
  6827. var positions = this.attributes.position.array;
  6828. if ( positions ) {
  6829. var bb = this.boundingBox;
  6830. bb.makeEmpty();
  6831. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  6832. vector.fromArray( positions, i );
  6833. bb.expandByPoint( vector );
  6834. }
  6835. }
  6836. if ( positions === undefined || positions.length === 0 ) {
  6837. this.boundingBox.min.set( 0, 0, 0 );
  6838. this.boundingBox.max.set( 0, 0, 0 );
  6839. }
  6840. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  6841. console.error( 'THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  6842. }
  6843. };
  6844. }(),
  6845. computeBoundingSphere: function () {
  6846. var box = new THREE.Box3();
  6847. var vector = new THREE.Vector3();
  6848. return function () {
  6849. if ( this.boundingSphere === null ) {
  6850. this.boundingSphere = new THREE.Sphere();
  6851. }
  6852. var positions = this.attributes.position.array;
  6853. if ( positions ) {
  6854. box.makeEmpty();
  6855. var center = this.boundingSphere.center;
  6856. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  6857. vector.fromArray( positions, i );
  6858. box.expandByPoint( vector );
  6859. }
  6860. box.center( center );
  6861. // hoping to find a boundingSphere with a radius smaller than the
  6862. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  6863. var maxRadiusSq = 0;
  6864. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  6865. vector.fromArray( positions, i );
  6866. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
  6867. }
  6868. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  6869. if ( isNaN( this.boundingSphere.radius ) ) {
  6870. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  6871. }
  6872. }
  6873. };
  6874. }(),
  6875. computeFaceNormals: function () {
  6876. // backwards compatibility
  6877. },
  6878. computeVertexNormals: function () {
  6879. var index = this.index;
  6880. var attributes = this.attributes;
  6881. var groups = this.groups;
  6882. if ( attributes.position ) {
  6883. var positions = attributes.position.array;
  6884. if ( attributes.normal === undefined ) {
  6885. this.addAttribute( 'normal', new THREE.BufferAttribute( new Float32Array( positions.length ), 3 ) );
  6886. } else {
  6887. // reset existing normals to zero
  6888. var normals = attributes.normal.array;
  6889. for ( var i = 0, il = normals.length; i < il; i ++ ) {
  6890. normals[ i ] = 0;
  6891. }
  6892. }
  6893. var normals = attributes.normal.array;
  6894. var vA, vB, vC,
  6895. pA = new THREE.Vector3(),
  6896. pB = new THREE.Vector3(),
  6897. pC = new THREE.Vector3(),
  6898. cb = new THREE.Vector3(),
  6899. ab = new THREE.Vector3();
  6900. // indexed elements
  6901. if ( index ) {
  6902. var indices = index.array;
  6903. if ( groups.length === 0 ) {
  6904. this.addGroup( 0, indices.length );
  6905. }
  6906. for ( var j = 0, jl = groups.length; j < jl; ++ j ) {
  6907. var group = groups[ j ];
  6908. var start = group.start;
  6909. var count = group.count;
  6910. for ( var i = start, il = start + count; i < il; i += 3 ) {
  6911. vA = indices[ i + 0 ] * 3;
  6912. vB = indices[ i + 1 ] * 3;
  6913. vC = indices[ i + 2 ] * 3;
  6914. pA.fromArray( positions, vA );
  6915. pB.fromArray( positions, vB );
  6916. pC.fromArray( positions, vC );
  6917. cb.subVectors( pC, pB );
  6918. ab.subVectors( pA, pB );
  6919. cb.cross( ab );
  6920. normals[ vA ] += cb.x;
  6921. normals[ vA + 1 ] += cb.y;
  6922. normals[ vA + 2 ] += cb.z;
  6923. normals[ vB ] += cb.x;
  6924. normals[ vB + 1 ] += cb.y;
  6925. normals[ vB + 2 ] += cb.z;
  6926. normals[ vC ] += cb.x;
  6927. normals[ vC + 1 ] += cb.y;
  6928. normals[ vC + 2 ] += cb.z;
  6929. }
  6930. }
  6931. } else {
  6932. // non-indexed elements (unconnected triangle soup)
  6933. for ( var i = 0, il = positions.length; i < il; i += 9 ) {
  6934. pA.fromArray( positions, i );
  6935. pB.fromArray( positions, i + 3 );
  6936. pC.fromArray( positions, i + 6 );
  6937. cb.subVectors( pC, pB );
  6938. ab.subVectors( pA, pB );
  6939. cb.cross( ab );
  6940. normals[ i ] = cb.x;
  6941. normals[ i + 1 ] = cb.y;
  6942. normals[ i + 2 ] = cb.z;
  6943. normals[ i + 3 ] = cb.x;
  6944. normals[ i + 4 ] = cb.y;
  6945. normals[ i + 5 ] = cb.z;
  6946. normals[ i + 6 ] = cb.x;
  6947. normals[ i + 7 ] = cb.y;
  6948. normals[ i + 8 ] = cb.z;
  6949. }
  6950. }
  6951. this.normalizeNormals();
  6952. attributes.normal.needsUpdate = true;
  6953. }
  6954. },
  6955. computeTangents: function () {
  6956. console.warn( 'THREE.BufferGeometry: .computeTangents() has been removed.' );
  6957. },
  6958. computeOffsets: function ( size ) {
  6959. console.warn( 'THREE.BufferGeometry: .computeOffsets() has been removed.');
  6960. },
  6961. merge: function ( geometry, offset ) {
  6962. if ( geometry instanceof THREE.BufferGeometry === false ) {
  6963. console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
  6964. return;
  6965. }
  6966. if ( offset === undefined ) offset = 0;
  6967. var attributes = this.attributes;
  6968. for ( var key in attributes ) {
  6969. if ( geometry.attributes[ key ] === undefined ) continue;
  6970. var attribute1 = attributes[ key ];
  6971. var attributeArray1 = attribute1.array;
  6972. var attribute2 = geometry.attributes[ key ];
  6973. var attributeArray2 = attribute2.array;
  6974. var attributeSize = attribute2.itemSize;
  6975. for ( var i = 0, j = attributeSize * offset; i < attributeArray2.length; i ++, j ++ ) {
  6976. attributeArray1[ j ] = attributeArray2[ i ];
  6977. }
  6978. }
  6979. return this;
  6980. },
  6981. normalizeNormals: function () {
  6982. var normals = this.attributes.normal.array;
  6983. var x, y, z, n;
  6984. for ( var i = 0, il = normals.length; i < il; i += 3 ) {
  6985. x = normals[ i ];
  6986. y = normals[ i + 1 ];
  6987. z = normals[ i + 2 ];
  6988. n = 1.0 / Math.sqrt( x * x + y * y + z * z );
  6989. normals[ i ] *= n;
  6990. normals[ i + 1 ] *= n;
  6991. normals[ i + 2 ] *= n;
  6992. }
  6993. },
  6994. toJSON: function () {
  6995. var data = {
  6996. metadata: {
  6997. version: 4.4,
  6998. type: 'BufferGeometry',
  6999. generator: 'BufferGeometry.toJSON'
  7000. }
  7001. };
  7002. // standard BufferGeometry serialization
  7003. data.uuid = this.uuid;
  7004. data.type = this.type;
  7005. if ( this.name !== '' ) data.name = this.name;
  7006. if ( this.parameters !== undefined ) {
  7007. var parameters = this.parameters;
  7008. for ( var key in parameters ) {
  7009. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  7010. }
  7011. return data;
  7012. }
  7013. data.data = { attributes: {} };
  7014. var index = this.index;
  7015. if ( index !== null ) {
  7016. var array = Array.prototype.slice.call( index.array );
  7017. data.data.index = {
  7018. type: index.array.constructor.name,
  7019. array: array
  7020. };
  7021. }
  7022. var attributes = this.attributes;
  7023. for ( var key in attributes ) {
  7024. var attribute = attributes[ key ];
  7025. var array = Array.prototype.slice.call( attribute.array );
  7026. data.data.attributes[ key ] = {
  7027. itemSize: attribute.itemSize,
  7028. type: attribute.array.constructor.name,
  7029. array: array
  7030. };
  7031. }
  7032. var groups = this.groups;
  7033. if ( groups.length > 0 ) {
  7034. data.data.groups = JSON.parse( JSON.stringify( groups ) );
  7035. }
  7036. var boundingSphere = this.boundingSphere;
  7037. if ( boundingSphere !== null ) {
  7038. data.data.boundingSphere = {
  7039. center: boundingSphere.center.toArray(),
  7040. radius: boundingSphere.radius
  7041. };
  7042. }
  7043. return data;
  7044. },
  7045. clone: function () {
  7046. // Handle primitives
  7047. var parameters = this.parameters;
  7048. if ( parameters !== undefined ) {
  7049. var values = [];
  7050. for ( var key in parameters ) {
  7051. values.push( parameters[ key ] );
  7052. }
  7053. var geometry = Object.create( this.constructor.prototype );
  7054. this.constructor.apply( geometry, values );
  7055. return geometry;
  7056. }
  7057. return new this.constructor().copy( this );
  7058. },
  7059. copy: function ( source ) {
  7060. var index = source.index;
  7061. if ( index !== null ) {
  7062. this.setIndex( index.clone() );
  7063. }
  7064. var attributes = source.attributes;
  7065. for ( var name in attributes ) {
  7066. var attribute = attributes[ name ];
  7067. this.addAttribute( name, attribute.clone() );
  7068. }
  7069. var groups = source.groups;
  7070. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  7071. var group = groups[ i ];
  7072. this.addGroup( group.start, group.count );
  7073. }
  7074. return this;
  7075. },
  7076. dispose: function () {
  7077. this.dispatchEvent( { type: 'dispose' } );
  7078. }
  7079. };
  7080. THREE.EventDispatcher.prototype.apply( THREE.BufferGeometry.prototype );
  7081. THREE.BufferGeometry.MaxIndex = 65535;
  7082. // File:src/core/InstancedBufferGeometry.js
  7083. /**
  7084. * @author benaadams / https://twitter.com/ben_a_adams
  7085. */
  7086. THREE.InstancedBufferGeometry = function () {
  7087. THREE.BufferGeometry.call( this );
  7088. this.type = 'InstancedBufferGeometry';
  7089. this.maxInstancedCount = undefined;
  7090. };
  7091. THREE.InstancedBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  7092. THREE.InstancedBufferGeometry.prototype.constructor = THREE.InstancedBufferGeometry;
  7093. THREE.InstancedBufferGeometry.prototype.addGroup = function ( start, count, instances ) {
  7094. this.groups.push( {
  7095. start: start,
  7096. count: count,
  7097. instances: instances
  7098. } );
  7099. };
  7100. THREE.InstancedBufferGeometry.prototype.copy = function ( source ) {
  7101. var index = source.index;
  7102. if ( index !== null ) {
  7103. this.setIndex( index.clone() );
  7104. }
  7105. var attributes = source.attributes;
  7106. for ( var name in attributes ) {
  7107. var attribute = attributes[ name ];
  7108. this.addAttribute( name, attribute.clone() );
  7109. }
  7110. var groups = source.groups;
  7111. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  7112. var group = groups[ i ];
  7113. this.addGroup( group.start, group.count, group.instances );
  7114. }
  7115. return this;
  7116. };
  7117. THREE.EventDispatcher.prototype.apply( THREE.InstancedBufferGeometry.prototype );
  7118. // File:src/animation/AnimationClip.js
  7119. /**
  7120. *
  7121. * Reusable set of Tracks that represent an animation.
  7122. *
  7123. * @author Ben Houston / http://clara.io/
  7124. * @author David Sarno / http://lighthaus.us/
  7125. */
  7126. THREE.AnimationClip = function ( name, duration, tracks ) {
  7127. this.name = name || THREE.Math.generateUUID();
  7128. this.tracks = tracks;
  7129. this.duration = ( duration !== undefined ) ? duration : -1;
  7130. // this means it should figure out its duration by scanning the tracks
  7131. if ( this.duration < 0 ) {
  7132. this.resetDuration();
  7133. }
  7134. // maybe only do these on demand, as doing them here could potentially slow down loading
  7135. // but leaving these here during development as this ensures a lot of testing of these functions
  7136. this.trim();
  7137. this.optimize();
  7138. };
  7139. THREE.AnimationClip.prototype = {
  7140. constructor: THREE.AnimationClip,
  7141. resetDuration: function() {
  7142. var tracks = this.tracks,
  7143. duration = 0;
  7144. for ( var i = 0, n = tracks.length; i !== n; ++ i ) {
  7145. var track = this.tracks[ i ];
  7146. duration = Math.max(
  7147. duration, track.times[ track.times.length - 1 ] );
  7148. }
  7149. this.duration = duration;
  7150. },
  7151. trim: function() {
  7152. for ( var i = 0; i < this.tracks.length; i ++ ) {
  7153. this.tracks[ i ].trim( 0, this.duration );
  7154. }
  7155. return this;
  7156. },
  7157. optimize: function() {
  7158. for ( var i = 0; i < this.tracks.length; i ++ ) {
  7159. this.tracks[ i ].optimize();
  7160. }
  7161. return this;
  7162. }
  7163. };
  7164. // Static methods:
  7165. Object.assign( THREE.AnimationClip, {
  7166. parse: function( json ) {
  7167. var tracks = [],
  7168. jsonTracks = json.tracks,
  7169. frameTime = 1.0 / ( json.fps || 1.0 );
  7170. for ( var i = 0, n = jsonTracks.length; i !== n; ++ i ) {
  7171. tracks.push( THREE.KeyframeTrack.parse( jsonTracks[ i ] ).scale( frameTime ) );
  7172. }
  7173. return new THREE.AnimationClip( json.name, json.duration, tracks );
  7174. },
  7175. toJSON: function( clip ) {
  7176. var tracks = [],
  7177. clipTracks = clip.tracks;
  7178. var json = {
  7179. 'name': clip.name,
  7180. 'duration': clip.duration,
  7181. 'tracks': tracks
  7182. };
  7183. for ( var i = 0, n = clipTracks.length; i !== n; ++ i ) {
  7184. tracks.push( THREE.KeyframeTrack.toJSON( clipTracks[ i ] ) );
  7185. }
  7186. return json;
  7187. },
  7188. CreateFromMorphTargetSequence: function( name, morphTargetSequence, fps ) {
  7189. var numMorphTargets = morphTargetSequence.length;
  7190. var tracks = [];
  7191. for ( var i = 0; i < numMorphTargets; i ++ ) {
  7192. var times = [];
  7193. var values = [];
  7194. times.push(
  7195. ( i + numMorphTargets - 1 ) % numMorphTargets,
  7196. i,
  7197. ( i + 1 ) % numMorphTargets );
  7198. values.push( 0, 1, 0 );
  7199. var order = THREE.AnimationUtils.getKeyframeOrder( times );
  7200. times = THREE.AnimationUtils.sortedArray( times, 1, order );
  7201. values = THREE.AnimationUtils.sortedArray( values, 1, order );
  7202. // if there is a key at the first frame, duplicate it as the
  7203. // last frame as well for perfect loop.
  7204. if ( times[ 0 ] === 0 ) {
  7205. times.push( numMorphTargets );
  7206. values.push( values[ 0 ] );
  7207. }
  7208. tracks.push(
  7209. new THREE.NumberKeyframeTrack(
  7210. '.morphTargetInfluences[' + morphTargetSequence[ i ].name + ']',
  7211. times, values
  7212. ).scale( 1.0 / fps ) );
  7213. }
  7214. return new THREE.AnimationClip( name, -1, tracks );
  7215. },
  7216. findByName: function( clipArray, name ) {
  7217. for ( var i = 0; i < clipArray.length; i ++ ) {
  7218. if ( clipArray[ i ].name === name ) {
  7219. return clipArray[ i ];
  7220. }
  7221. }
  7222. return null;
  7223. },
  7224. CreateClipsFromMorphTargetSequences: function( morphTargets, fps ) {
  7225. var animationToMorphTargets = {};
  7226. // tested with https://regex101.com/ on trick sequences
  7227. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  7228. var pattern = /^([\w-]*?)([\d]+)$/;
  7229. // sort morph target names into animation groups based
  7230. // patterns like Walk_001, Walk_002, Run_001, Run_002
  7231. for ( var i = 0, il = morphTargets.length; i < il; i ++ ) {
  7232. var morphTarget = morphTargets[ i ];
  7233. var parts = morphTarget.name.match( pattern );
  7234. if ( parts && parts.length > 1 ) {
  7235. var name = parts[ 1 ];
  7236. var animationMorphTargets = animationToMorphTargets[ name ];
  7237. if ( ! animationMorphTargets ) {
  7238. animationToMorphTargets[ name ] = animationMorphTargets = [];
  7239. }
  7240. animationMorphTargets.push( morphTarget );
  7241. }
  7242. }
  7243. var clips = [];
  7244. for ( var name in animationToMorphTargets ) {
  7245. clips.push( THREE.AnimationClip.CreateFromMorphTargetSequence( name, animationToMorphTargets[ name ], fps ) );
  7246. }
  7247. return clips;
  7248. },
  7249. // parse the animation.hierarchy format
  7250. parseAnimation: function( animation, bones, nodeName ) {
  7251. if ( ! animation ) {
  7252. console.error( " no animation in JSONLoader data" );
  7253. return null;
  7254. }
  7255. var addNonemptyTrack = function(
  7256. trackType, trackName, animationKeys, propertyName, destTracks ) {
  7257. // only return track if there are actually keys.
  7258. if ( animationKeys.length !== 0 ) {
  7259. var times = [];
  7260. var values = [];
  7261. THREE.AnimationUtils.flattenJSON(
  7262. animationKeys, times, values, propertyName );
  7263. // empty keys are filtered out, so check again
  7264. if ( times.length !== 0 ) {
  7265. destTracks.push( new trackType( trackName, times, values ) );
  7266. }
  7267. }
  7268. };
  7269. var tracks = [];
  7270. var clipName = animation.name || 'default';
  7271. // automatic length determination in AnimationClip.
  7272. var duration = animation.length || -1;
  7273. var fps = animation.fps || 30;
  7274. var hierarchyTracks = animation.hierarchy || [];
  7275. for ( var h = 0; h < hierarchyTracks.length; h ++ ) {
  7276. var animationKeys = hierarchyTracks[ h ].keys;
  7277. // skip empty tracks
  7278. if ( ! animationKeys || animationKeys.length == 0 ) continue;
  7279. // process morph targets in a way exactly compatible
  7280. // with AnimationHandler.init( animation )
  7281. if ( animationKeys[0].morphTargets ) {
  7282. // figure out all morph targets used in this track
  7283. var morphTargetNames = {};
  7284. for ( var k = 0; k < animationKeys.length; k ++ ) {
  7285. if ( animationKeys[k].morphTargets ) {
  7286. for ( var m = 0; m < animationKeys[k].morphTargets.length; m ++ ) {
  7287. morphTargetNames[ animationKeys[k].morphTargets[m] ] = -1;
  7288. }
  7289. }
  7290. }
  7291. // create a track for each morph target with all zero
  7292. // morphTargetInfluences except for the keys in which
  7293. // the morphTarget is named.
  7294. for ( var morphTargetName in morphTargetNames ) {
  7295. var times = [];
  7296. var values = [];
  7297. for ( var m = 0;
  7298. m !== animationKeys[k].morphTargets.length; ++ m ) {
  7299. var animationKey = animationKeys[k];
  7300. times.push( animationKey.time );
  7301. values.push( ( animationKey.morphTarget === morphTargetName ) ? 1 : 0 )
  7302. }
  7303. tracks.push( new THREE.NumberKeyframeTrack(
  7304. '.morphTargetInfluence[' + morphTargetName + ']', times, values ) );
  7305. }
  7306. duration = morphTargetNames.length * ( fps || 1.0 );
  7307. } else {
  7308. // ...assume skeletal animation
  7309. var boneName = '.bones[' + bones[ h ].name + ']';
  7310. addNonemptyTrack(
  7311. THREE.VectorKeyframeTrack, boneName + '.position',
  7312. animationKeys, 'pos', tracks );
  7313. addNonemptyTrack(
  7314. THREE.QuaternionKeyframeTrack, boneName + '.quaternion',
  7315. animationKeys, 'rot', tracks );
  7316. addNonemptyTrack(
  7317. THREE.VectorKeyframeTrack, boneName + '.scale',
  7318. animationKeys, 'scl', tracks );
  7319. }
  7320. }
  7321. if ( tracks.length === 0 ) {
  7322. return null;
  7323. }
  7324. var clip = new THREE.AnimationClip( clipName, duration, tracks );
  7325. return clip;
  7326. }
  7327. } );
  7328. // File:src/animation/AnimationMixer.js
  7329. /**
  7330. *
  7331. * Player for AnimationClips.
  7332. *
  7333. *
  7334. * @author Ben Houston / http://clara.io/
  7335. * @author David Sarno / http://lighthaus.us/
  7336. * @author tschw
  7337. */
  7338. THREE.AnimationMixer = function( root ) {
  7339. this._root = root;
  7340. this._initMemoryManager();
  7341. this._accuIndex = 0;
  7342. this.time = 0;
  7343. this.timeScale = 1.0;
  7344. };
  7345. THREE.AnimationMixer.prototype = {
  7346. constructor: THREE.AnimationMixer,
  7347. // return an action for a clip optionally using a custom root target
  7348. // object (this method allocates a lot of dynamic memory in case a
  7349. // previously unknown clip/root combination is specified)
  7350. clipAction: function( clip, optionalRoot ) {
  7351. var root = optionalRoot || this._root,
  7352. rootUuid = root.uuid,
  7353. clipName = ( typeof clip === 'string' ) ? clip : clip.name,
  7354. clipObject = ( clip !== clipName ) ? clip : null,
  7355. actionsForClip = this._actionsByClip[ clipName ],
  7356. prototypeAction;
  7357. if ( actionsForClip !== undefined ) {
  7358. var existingAction =
  7359. actionsForClip.actionByRoot[ rootUuid ];
  7360. if ( existingAction !== undefined ) {
  7361. return existingAction;
  7362. }
  7363. // we know the clip, so we don't have to parse all
  7364. // the bindings again but can just copy
  7365. prototypeAction = actionsForClip.knownActions[ 0 ];
  7366. // also, take the clip from the prototype action
  7367. clipObject = prototypeAction._clip;
  7368. if ( clip !== clipName && clip !== clipObject ) {
  7369. throw new Error(
  7370. "Different clips with the same name detected!" );
  7371. }
  7372. }
  7373. // clip must be known when specified via string
  7374. if ( clipObject === null ) return null;
  7375. // allocate all resources required to run it
  7376. var newAction = new THREE.
  7377. AnimationMixer._Action( this, clipObject, optionalRoot );
  7378. this._bindAction( newAction, prototypeAction );
  7379. // and make the action known to the memory manager
  7380. this._addInactiveAction( newAction, clipName, rootUuid );
  7381. return newAction;
  7382. },
  7383. // get an existing action
  7384. existingAction: function( clip, optionalRoot ) {
  7385. var root = optionalRoot || this._root,
  7386. rootUuid = root.uuid,
  7387. clipName = ( typeof clip === 'string' ) ? clip : clip.name,
  7388. actionsForClip = this._actionsByClip[ clipName ];
  7389. if ( actionsForClip !== undefined ) {
  7390. return actionsForClip.actionByRoot[ rootUuid ] || null;
  7391. }
  7392. return null;
  7393. },
  7394. // deactivates all previously scheduled actions
  7395. stopAllAction: function() {
  7396. var actions = this._actions,
  7397. nActions = this._nActiveActions,
  7398. bindings = this._bindings,
  7399. nBindings = this._nActiveBindings;
  7400. this._nActiveActions = 0;
  7401. this._nActiveBindings = 0;
  7402. for ( var i = 0; i !== nActions; ++ i ) {
  7403. actions[ i ].reset();
  7404. }
  7405. for ( var i = 0; i !== nBindings; ++ i ) {
  7406. bindings[ i ].useCount = 0;
  7407. }
  7408. return this;
  7409. },
  7410. // advance the time and update apply the animation
  7411. update: function( deltaTime ) {
  7412. deltaTime *= this.timeScale;
  7413. var actions = this._actions,
  7414. nActions = this._nActiveActions,
  7415. time = this.time += deltaTime,
  7416. timeDirection = Math.sign( deltaTime ),
  7417. accuIndex = this._accuIndex ^= 1;
  7418. // run active actions
  7419. for ( var i = 0; i !== nActions; ++ i ) {
  7420. var action = actions[ i ];
  7421. if ( action.enabled ) {
  7422. action._update( time, deltaTime, timeDirection, accuIndex );
  7423. }
  7424. }
  7425. // update scene graph
  7426. var bindings = this._bindings,
  7427. nBindings = this._nActiveBindings;
  7428. for ( var i = 0; i !== nBindings; ++ i ) {
  7429. bindings[ i ].apply( accuIndex );
  7430. }
  7431. return this;
  7432. },
  7433. // return this mixer's root target object
  7434. getRoot: function() {
  7435. return this._root;
  7436. },
  7437. // free all resources specific to a particular clip
  7438. uncacheClip: function( clip ) {
  7439. var actions = this._actions,
  7440. clipName = clip.name,
  7441. actionsByClip = this._actionsByClip,
  7442. actionsForClip = actionsByClip[ clipName ];
  7443. if ( actionsForClip !== undefined ) {
  7444. // note: just calling _removeInactiveAction would mess up the
  7445. // iteration state and also require updating the state we can
  7446. // just throw away
  7447. var actionsToRemove = actionsForClip.knownActions;
  7448. for ( var i = 0, n = actionsToRemove.length; i !== n; ++ i ) {
  7449. var action = actionsToRemove[ i ];
  7450. this._deactivateAction( action );
  7451. var cacheIndex = action._cacheIndex,
  7452. lastInactiveAction = actions[ actions.length - 1 ];
  7453. action._cacheIndex = null;
  7454. action._byClipCacheIndex = null;
  7455. lastInactiveAction._cacheIndex = cacheIndex;
  7456. actions[ cacheIndex ] = lastInactiveAction;
  7457. actions.pop();
  7458. this._removeInactiveBindingsForAction( action );
  7459. }
  7460. delete actionsByClip[ clipName ];
  7461. }
  7462. },
  7463. // free all resources specific to a particular root target object
  7464. uncacheRoot: function( root ) {
  7465. var rootUuid = root.uuid,
  7466. actionsByClip = this._actionsByClip;
  7467. for ( var clipName in actionsByClip ) {
  7468. var actionByRoot = actionsByClip[ clipName ].actionByRoot,
  7469. action = actionByRoot[ rootUuid ];
  7470. if ( action !== undefined ) {
  7471. this._deactivateAction( action );
  7472. this._removeInactiveAction( action );
  7473. }
  7474. }
  7475. var bindingsByRoot = this._bindingsByRootAndName,
  7476. bindingByName = bindingsByRoot[ rootUuid ];
  7477. if ( bindingByName !== undefined ) {
  7478. for ( var trackName in bindingByName ) {
  7479. var binding = bindingByName[ trackName ];
  7480. binding.restoreOriginalState();
  7481. this._removeInactiveBinding( binding );
  7482. }
  7483. }
  7484. },
  7485. // remove a targeted clip from the cache
  7486. uncacheAction: function( clip, optionalRoot ) {
  7487. var action = this.existingAction( clip, optionalRoot );
  7488. if ( action !== null ) {
  7489. this._deactivateAction( action );
  7490. this._removeInactiveAction( action );
  7491. }
  7492. }
  7493. };
  7494. THREE.EventDispatcher.prototype.apply( THREE.AnimationMixer.prototype );
  7495. THREE.AnimationMixer._Action =
  7496. function( mixer, clip, localRoot ) {
  7497. this._mixer = mixer;
  7498. this._clip = clip;
  7499. this._localRoot = localRoot || null;
  7500. var tracks = clip.tracks,
  7501. nTracks = tracks.length,
  7502. interpolants = new Array( nTracks );
  7503. var interpolantSettings = {
  7504. endingStart: THREE.ZeroCurvatureEnding,
  7505. endingEnd: THREE.ZeroCurvatureEnding
  7506. };
  7507. for ( var i = 0; i !== nTracks; ++ i ) {
  7508. var interpolant = tracks[ i ].createInterpolant( null );
  7509. interpolants[ i ] = interpolant;
  7510. interpolant.settings = interpolantSettings
  7511. }
  7512. this._interpolantSettings = interpolantSettings;
  7513. this._interpolants = interpolants; // bound by the mixer
  7514. // inside: PropertyMixer (managed by the mixer)
  7515. this._propertyBindings = new Array( nTracks );
  7516. this._cacheIndex = null; // for the memory manager
  7517. this._byClipCacheIndex = null; // for the memory manager
  7518. this._timeScaleInterpolant = null;
  7519. this._weightInterpolant = null;
  7520. this.loop = THREE.LoopRepeat;
  7521. this._loopCount = -1;
  7522. // global mixer time when the action is to be started
  7523. // it's set back to 'null' upon start of the action
  7524. this._startTime = null;
  7525. // scaled local time of the action
  7526. // gets clamped or wrapped to 0..clip.duration according to loop
  7527. this.time = 0;
  7528. this.timeScale = 1;
  7529. this._effectiveTimeScale = 1;
  7530. this.weight = 1;
  7531. this._effectiveWeight = 1;
  7532. this.repetitions = Infinity; // no. of repetitions when looping
  7533. this.paused = false; // false -> zero effective time scale
  7534. this.enabled = true; // true -> zero effective weight
  7535. this.clampWhenFinished = false; // keep feeding the last frame?
  7536. this.zeroSlopeAtStart = true; // for smooth interpolation w/o separate
  7537. this.zeroSlopeAtEnd = true; // clips for start, loop and end
  7538. };
  7539. THREE.AnimationMixer._Action.prototype = {
  7540. constructor: THREE.AnimationMixer._Action,
  7541. // State & Scheduling
  7542. play: function() {
  7543. this._mixer._activateAction( this );
  7544. return this;
  7545. },
  7546. stop: function() {
  7547. this._mixer._deactivateAction( this );
  7548. return this.reset();
  7549. },
  7550. reset: function() {
  7551. this.paused = false;
  7552. this.enabled = true;
  7553. this.time = 0; // restart clip
  7554. this._loopCount = -1; // forget previous loops
  7555. this._startTime = null; // forget scheduling
  7556. return this.stopFading().stopWarping();
  7557. },
  7558. isRunning: function() {
  7559. var start = this._startTime;
  7560. return this.enabled && ! this.paused && this.timeScale !== 0 &&
  7561. this._startTime === null && this._mixer._isActiveAction( this )
  7562. },
  7563. // return true when play has been called
  7564. isScheduled: function() {
  7565. return this._mixer._isActiveAction( this );
  7566. },
  7567. startAt: function( time ) {
  7568. this._startTime = time;
  7569. return this;
  7570. },
  7571. setLoop: function( mode, repetitions ) {
  7572. this.loop = mode;
  7573. this.repetitions = repetitions;
  7574. return this;
  7575. },
  7576. // Weight
  7577. // set the weight stopping any scheduled fading
  7578. // although .enabled = false yields an effective weight of zero, this
  7579. // method does *not* change .enabled, because it would be confusing
  7580. setEffectiveWeight: function( weight ) {
  7581. this.weight = weight;
  7582. // note: same logic as when updated at runtime
  7583. this._effectiveWeight = this.enabled ? weight : 0;
  7584. return this.stopFading();
  7585. },
  7586. // return the weight considering fading and .enabled
  7587. getEffectiveWeight: function() {
  7588. return this._effectiveWeight;
  7589. },
  7590. fadeIn: function( duration ) {
  7591. return this._scheduleFading( duration, 0, 1 );
  7592. },
  7593. fadeOut: function( duration ) {
  7594. return this._scheduleFading( duration, 1, 0 );
  7595. },
  7596. crossFadeFrom: function( fadeOutAction, duration, warp ) {
  7597. var mixer = this._mixer;
  7598. fadeOutAction.fadeOut( duration );
  7599. this.fadeIn( duration );
  7600. if( warp ) {
  7601. var fadeInDuration = this._clip.duration,
  7602. fadeOutDuration = fadeOutAction._clip.duration,
  7603. startEndRatio = fadeOutDuration / fadeInDuration,
  7604. endStartRatio = fadeInDuration / fadeOutDuration;
  7605. fadeOutAction.warp( 1.0, startEndRatio, duration );
  7606. this.warp( endStartRatio, 1.0, duration );
  7607. }
  7608. return this;
  7609. },
  7610. crossFadeTo: function( fadeInAction, duration, warp ) {
  7611. return fadeInAction.crossFadeFrom( this, duration, warp );
  7612. },
  7613. stopFading: function() {
  7614. var weightInterpolant = this._weightInterpolant;
  7615. if ( weightInterpolant !== null ) {
  7616. this._weightInterpolant = null;
  7617. this._mixer._takeBackControlInterpolant( weightInterpolant );
  7618. }
  7619. return this;
  7620. },
  7621. // Time Scale Control
  7622. // set the weight stopping any scheduled warping
  7623. // although .paused = true yields an effective time scale of zero, this
  7624. // method does *not* change .paused, because it would be confusing
  7625. setEffectiveTimeScale: function( timeScale ) {
  7626. this.timeScale = timeScale;
  7627. this._effectiveTimeScale = this.paused ? 0 :timeScale;
  7628. return this.stopWarping();
  7629. },
  7630. // return the time scale considering warping and .paused
  7631. getEffectiveTimeScale: function() {
  7632. return this._effectiveTimeScale;
  7633. },
  7634. setDuration: function( duration ) {
  7635. this.timeScale = this._clip.duration / duration;
  7636. return this.stopWarping();
  7637. },
  7638. syncWith: function( action ) {
  7639. this.time = action.time;
  7640. this.timeScale = action.timeScale;
  7641. return this.stopWarping();
  7642. },
  7643. halt: function( duration ) {
  7644. return this.warp( this._currentTimeScale, 0, duration );
  7645. },
  7646. warp: function( startTimeScale, endTimeScale, duration ) {
  7647. var mixer = this._mixer, now = mixer.time,
  7648. interpolant = this._timeScaleInterpolant,
  7649. timeScale = this.timeScale;
  7650. if ( interpolant === null ) {
  7651. interpolant = mixer._lendControlInterpolant(),
  7652. this._timeScaleInterpolant = interpolant;
  7653. }
  7654. var times = interpolant.parameterPositions,
  7655. values = interpolant.sampleValues;
  7656. times[ 0 ] = now;
  7657. times[ 1 ] = now + duration;
  7658. values[ 0 ] = startTimeScale / timeScale;
  7659. values[ 1 ] = endTimeScale / timeScale;
  7660. return this;
  7661. },
  7662. stopWarping: function() {
  7663. var timeScaleInterpolant = this._timeScaleInterpolant;
  7664. if ( timeScaleInterpolant !== null ) {
  7665. this._timeScaleInterpolant = null;
  7666. this._mixer._takeBackControlInterpolant( timeScaleInterpolant );
  7667. }
  7668. return this;
  7669. },
  7670. // Object Accessors
  7671. getMixer: function() {
  7672. return this._mixer;
  7673. },
  7674. getClip: function() {
  7675. return this._clip;
  7676. },
  7677. getRoot: function() {
  7678. return this._localRoot || this._mixer._root;
  7679. },
  7680. // Interna
  7681. _update: function( time, deltaTime, timeDirection, accuIndex ) {
  7682. // called by the mixer
  7683. var startTime = this._startTime;
  7684. if ( startTime !== null ) {
  7685. // check for scheduled start of action
  7686. var timeRunning = ( time - startTime ) * timeDirection;
  7687. if ( timeRunning < 0 || timeDirection === 0 ) {
  7688. return; // yet to come / don't decide when delta = 0
  7689. }
  7690. // start
  7691. this._startTime = null; // unschedule
  7692. deltaTime = timeDirection * timeRunning;
  7693. }
  7694. // apply time scale and advance time
  7695. deltaTime *= this._updateTimeScale( time );
  7696. var clipTime = this._updateTime( deltaTime );
  7697. // note: _updateTime may disable the action resulting in
  7698. // an effective weight of 0
  7699. var weight = this._updateWeight( time );
  7700. if ( weight > 0 ) {
  7701. var interpolants = this._interpolants;
  7702. var propertyMixers = this._propertyBindings;
  7703. for ( var j = 0, m = interpolants.length; j !== m; ++ j ) {
  7704. interpolants[ j ].evaluate( clipTime );
  7705. propertyMixers[ j ].accumulate( accuIndex, weight );
  7706. }
  7707. }
  7708. },
  7709. _updateWeight: function( time ) {
  7710. var weight = 0;
  7711. if ( this.enabled ) {
  7712. weight = this.weight;
  7713. var interpolant = this._weightInterpolant;
  7714. if ( interpolant !== null ) {
  7715. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  7716. weight *= interpolantValue;
  7717. if ( time > interpolant.parameterPositions[ 1 ] ) {
  7718. this.stopFading();
  7719. if ( interpolantValue === 0 ) {
  7720. // faded out, disable
  7721. this.enabled = false;
  7722. }
  7723. }
  7724. }
  7725. }
  7726. this._effectiveWeight = weight;
  7727. return weight;
  7728. },
  7729. _updateTimeScale: function( time ) {
  7730. var timeScale = 0;
  7731. if ( ! this.paused ) {
  7732. timeScale = this.timeScale;
  7733. var interpolant = this._timeScaleInterpolant;
  7734. if ( interpolant !== null ) {
  7735. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  7736. timeScale *= interpolantValue;
  7737. if ( time > interpolant.parameterPositions[ 1 ] ) {
  7738. this.stopWarping();
  7739. if ( timeScale === 0 ) {
  7740. // motion has halted, pause
  7741. this.pause = true;
  7742. } else {
  7743. // warp done - apply final time scale
  7744. this.timeScale = timeScale;
  7745. }
  7746. }
  7747. }
  7748. }
  7749. this._effectiveTimeScale = timeScale;
  7750. return timeScale;
  7751. },
  7752. _updateTime: function( deltaTime ) {
  7753. var time = this.time + deltaTime;
  7754. if ( deltaTime === 0 ) return time;
  7755. var duration = this._clip.duration,
  7756. loop = this.loop,
  7757. loopCount = this._loopCount,
  7758. pingPong = false;
  7759. switch ( loop ) {
  7760. case THREE.LoopOnce:
  7761. case THREE.LoopOnceClamp:
  7762. if ( loopCount === -1 ) {
  7763. // just started
  7764. this.loopCount = 0;
  7765. this._setEndings( true, true, false );
  7766. }
  7767. if ( time >= duration ) {
  7768. time = duration;
  7769. } else if ( time < 0 ) {
  7770. time = 0;
  7771. } else break;
  7772. // reached the end
  7773. if ( this.clampWhenFinished ) this.pause = true;
  7774. else this.enabled = false;
  7775. this._mixer.dispatchEvent( {
  7776. type: 'finished', action: this,
  7777. direction: deltaTime < 0 ? -1 : 1
  7778. } );
  7779. break;
  7780. case THREE.LoopPingPong:
  7781. pingPong = true;
  7782. case THREE.LoopRepeat:
  7783. if ( loopCount === -1 ) {
  7784. // just started
  7785. if ( deltaTime > 0 ) {
  7786. loopCount = 0;
  7787. this._setEndings(
  7788. true, this.repetitions === 0, pingPong );
  7789. } else {
  7790. // when looping in reverse direction, the initial
  7791. // transition through zero counts as a repetition,
  7792. // so leave loopCount at -1
  7793. this._setEndings(
  7794. this.repetitions === 0, true, pingPong );
  7795. }
  7796. }
  7797. if ( time >= duration || time < 0 ) {
  7798. // wrap around
  7799. var loopDelta = Math.floor( time / duration ); // signed
  7800. time -= duration * loopDelta;
  7801. loopCount += Math.abs( loopDelta );
  7802. var pending = this.repetitions - loopCount;
  7803. if ( pending < 0 ) {
  7804. // stop (switch state, clamp time, fire event)
  7805. if ( this.clampWhenFinished ) this.paused = true;
  7806. else this.enabled = false;
  7807. time = deltaTime > 0 ? duration : 0;
  7808. this._mixer.dispatchEvent( {
  7809. type: 'finished', action: this,
  7810. direction: deltaTime > 0 ? 1 : -1
  7811. } );
  7812. break;
  7813. } else if ( pending === 0 ) {
  7814. // transition to last round
  7815. var atStart = deltaTime < 0;
  7816. this._setEndings( atStart, ! atStart, pingPong );
  7817. } else {
  7818. this._setEndings( false, false, pingPong );
  7819. }
  7820. this._loopCount = loopCount;
  7821. this._mixer.dispatchEvent( {
  7822. type: 'loop', action: this, loopDelta: loopDelta
  7823. } );
  7824. }
  7825. if ( loop === THREE.LoopPingPong && ( loopCount & 1 ) === 1 ) {
  7826. // invert time for the "pong round"
  7827. this.time = time;
  7828. return duration - time;
  7829. }
  7830. break;
  7831. }
  7832. this.time = time;
  7833. return time;
  7834. },
  7835. _setEndings: function( atStart, atEnd, pingPong ) {
  7836. var settings = this._interpolantSettings;
  7837. if ( pingPong ) {
  7838. settings.endingStart = THREE.ZeroSlopeEnding;
  7839. settings.endingEnd = THREE.ZeroSlopeEnding;
  7840. } else {
  7841. // assuming for LoopOnce atStart == atEnd == true
  7842. if ( atStart ) {
  7843. settings.endingStart = this.zeroSlopeAtStart ?
  7844. THREE.ZeroSlopeEnding : THREE.ZeroCurvatureEnding;
  7845. } else {
  7846. settings.endingStart = THREE.WrapAroundEnding;
  7847. }
  7848. if ( atEnd ) {
  7849. settings.endingEnd = this.zeroSlopeAtEnd ?
  7850. THREE.ZeroSlopeEnding : THREE.ZeroCurvatureEnding;
  7851. } else {
  7852. settings.endingEnd = THREE.WrapAroundEnding;
  7853. }
  7854. }
  7855. },
  7856. _scheduleFading: function( duration, weightNow, weightThen ) {
  7857. var mixer = this._mixer, now = mixer.time,
  7858. interpolant = this._weightInterpolant;
  7859. if ( interpolant === null ) {
  7860. interpolant = mixer._lendControlInterpolant(),
  7861. this._weightInterpolant = interpolant;
  7862. }
  7863. var times = interpolant.parameterPositions,
  7864. values = interpolant.sampleValues;
  7865. times[ 0 ] = now; values[ 0 ] = weightNow;
  7866. times[ 1 ] = now + duration; values[ 1 ] = weightThen;
  7867. return this;
  7868. }
  7869. };
  7870. // Implementation details:
  7871. Object.assign( THREE.AnimationMixer.prototype, {
  7872. _bindAction: function( action, prototypeAction ) {
  7873. var root = action._localRoot || this._root,
  7874. tracks = action._clip.tracks,
  7875. nTracks = tracks.length,
  7876. bindings = action._propertyBindings,
  7877. interpolants = action._interpolants,
  7878. rootUuid = root.uuid,
  7879. bindingsByRoot = this._bindingsByRootAndName,
  7880. bindingsByName = bindingsByRoot[ rootUuid ];
  7881. if ( bindingsByName === undefined ) {
  7882. bindingsByName = {};
  7883. bindingsByRoot[ rootUuid ] = bindingsByName;
  7884. }
  7885. for ( var i = 0; i !== nTracks; ++ i ) {
  7886. var track = tracks[ i ],
  7887. trackName = track.name,
  7888. binding = bindingsByName[ trackName ];
  7889. if ( binding !== undefined ) {
  7890. bindings[ i ] = binding;
  7891. } else {
  7892. binding = bindings[ i ];
  7893. if ( binding !== undefined ) {
  7894. // existing binding, make sure the cache knows
  7895. if ( binding._cacheIndex === null ) {
  7896. ++ binding.referenceCount;
  7897. this._addInactiveBinding( binding, rootUuid, trackName );
  7898. }
  7899. continue;
  7900. }
  7901. var path = prototypeAction && prototypeAction.
  7902. _propertyBindings[ i ].binding.parsedPath;
  7903. binding = new THREE.PropertyMixer(
  7904. THREE.PropertyBinding.create( root, trackName, path ),
  7905. track.ValueTypeName, track.getValueSize() );
  7906. ++ binding.referenceCount;
  7907. this._addInactiveBinding( binding, rootUuid, trackName );
  7908. bindings[ i ] = binding;
  7909. }
  7910. interpolants[ i ].resultBuffer = binding.buffer;
  7911. }
  7912. },
  7913. _activateAction: function( action ) {
  7914. if ( ! this._isActiveAction( action ) ) {
  7915. if ( action._cacheIndex === null ) {
  7916. // this action has been forgotten by the cache, but the user
  7917. // appears to be still using it -> rebind
  7918. var rootUuid = ( action._localRoot || this._root ).uuid,
  7919. clipName = action._clip.name,
  7920. actionsForClip = this._actionsByClip[ clipName ];
  7921. this._bindAction( action,
  7922. actionsForClip && actionsForClip.knownActions[ 0 ] );
  7923. this._addInactiveAction( action, clipName, rootUuid );
  7924. }
  7925. var bindings = action._propertyBindings;
  7926. // increment reference counts / sort out state
  7927. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  7928. var binding = bindings[ i ];
  7929. if ( binding.useCount ++ === 0 ) {
  7930. this._lendBinding( binding );
  7931. binding.saveOriginalState();
  7932. }
  7933. }
  7934. this._lendAction( action );
  7935. }
  7936. },
  7937. _deactivateAction: function( action ) {
  7938. if ( this._isActiveAction( action ) ) {
  7939. var bindings = action._propertyBindings;
  7940. // decrement reference counts / sort out state
  7941. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  7942. var binding = bindings[ i ];
  7943. if ( -- binding.useCount === 0 ) {
  7944. binding.restoreOriginalState();
  7945. this._takeBackBinding( binding );
  7946. }
  7947. }
  7948. this._takeBackAction( action );
  7949. }
  7950. },
  7951. // Memory manager
  7952. _initMemoryManager: function() {
  7953. this._actions = []; // 'nActiveActions' followed by inactive ones
  7954. this._nActiveActions = 0;
  7955. this._actionsByClip = {};
  7956. // inside:
  7957. // {
  7958. // knownActions: Array< _Action > - used as prototypes
  7959. // actionByRoot: _Action - lookup
  7960. // }
  7961. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  7962. this._nActiveBindings = 0;
  7963. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  7964. this._controlInterpolants = []; // same game as above
  7965. this._nActiveControlInterpolants = 0;
  7966. var scope = this;
  7967. this.stats = {
  7968. actions: {
  7969. get total() { return scope._actions.length; },
  7970. get inUse() { return scope._nActiveActions; }
  7971. },
  7972. bindings: {
  7973. get total() { return scope._bindings.length; },
  7974. get inUse() { return scope._nActiveBindings; }
  7975. },
  7976. controlInterpolants: {
  7977. get total() { return scope._controlInterpolants.length; },
  7978. get inUse() { return scope._nActiveControlInterpolants; }
  7979. }
  7980. };
  7981. },
  7982. // Memory management for _Action objects
  7983. _isActiveAction: function( action ) {
  7984. var index = action._cacheIndex;
  7985. return index !== null && index < this._nActiveActions;
  7986. },
  7987. _addInactiveAction: function( action, clipName, rootUuid ) {
  7988. var actions = this._actions,
  7989. actionsByClip = this._actionsByClip,
  7990. actionsForClip = actionsByClip[ clipName ];
  7991. if ( actionsForClip === undefined ) {
  7992. actionsForClip = {
  7993. knownActions: [ action ],
  7994. actionByRoot: {}
  7995. };
  7996. action._byClipCacheIndex = 0;
  7997. actionsByClip[ clipName ] = actionsForClip;
  7998. } else {
  7999. var knownActions = actionsForClip.knownActions;
  8000. action._byClipCacheIndex = knownActions.length;
  8001. knownActions.push( action );
  8002. }
  8003. action._cacheIndex = actions.length;
  8004. actions.push( action );
  8005. actionsForClip.actionByRoot[ rootUuid ] = action;
  8006. },
  8007. _removeInactiveAction: function( action ) {
  8008. var actions = this._actions,
  8009. lastInactiveAction = actions[ actions.length - 1 ],
  8010. cacheIndex = action._cacheIndex;
  8011. lastInactiveAction._cacheIndex = cacheIndex;
  8012. actions[ cacheIndex ] = lastInactiveAction;
  8013. actions.pop();
  8014. action._cacheIndex = null;
  8015. var clipName = action._clip.name,
  8016. actionsByClip = this._actionsByClip,
  8017. actionsForClip = actionsByClip[ clipName ],
  8018. knownActionsForClip = actionsForClip.knownActions,
  8019. lastKnownAction =
  8020. knownActionsForClip[ knownActionsForClip.length - 1 ],
  8021. byClipCacheIndex = action._byClipCacheIndex;
  8022. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  8023. knownActionsForClip[ byClipCacheIndex ] = lastKnownAction;
  8024. knownActionsForClip.pop();
  8025. action._byClipCacheIndex = null;
  8026. var actionByRoot = actionsForClip.actionByRoot,
  8027. rootUuid = ( actions._localRoot || this._root ).uuid;
  8028. delete actionByRoot[ rootUuid ];
  8029. if ( knownActionsForClip.length === 0 ) {
  8030. delete actionsByClip[ clipName ];
  8031. }
  8032. this._removeInactiveBindingsForAction( action );
  8033. },
  8034. _removeInactiveBindingsForAction: function( action ) {
  8035. var bindings = action._propertyBindings;
  8036. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  8037. var binding = bindings[ i ];
  8038. if ( -- binding.referenceCount === 0 ) {
  8039. this._removeInactiveBinding( binding );
  8040. }
  8041. }
  8042. },
  8043. _lendAction: function( action ) {
  8044. // [ active actions | inactive actions ]
  8045. // [ active actions >| inactive actions ]
  8046. // s a
  8047. // <-swap->
  8048. // a s
  8049. var actions = this._actions,
  8050. prevIndex = action._cacheIndex,
  8051. lastActiveIndex = this._nActiveActions ++,
  8052. firstInactiveAction = actions[ lastActiveIndex ];
  8053. action._cacheIndex = lastActiveIndex;
  8054. actions[ lastActiveIndex ] = action;
  8055. firstInactiveAction._cacheIndex = prevIndex;
  8056. actions[ prevIndex ] = firstInactiveAction;
  8057. },
  8058. _takeBackAction: function( action ) {
  8059. // [ active actions | inactive actions ]
  8060. // [ active actions |< inactive actions ]
  8061. // a s
  8062. // <-swap->
  8063. // s a
  8064. var actions = this._actions,
  8065. prevIndex = action._cacheIndex,
  8066. firstInactiveIndex = -- this._nActiveActions,
  8067. lastActiveAction = actions[ firstInactiveIndex ];
  8068. action._cacheIndex = firstInactiveIndex;
  8069. actions[ firstInactiveIndex ] = action;
  8070. lastActiveAction._cacheIndex = prevIndex;
  8071. actions[ prevIndex ] = lastActiveAction;
  8072. },
  8073. // Memory management for PropertyMixer objects
  8074. _addInactiveBinding: function( binding, rootUuid, trackName ) {
  8075. var bindingsByRoot = this._bindingsByRootAndName,
  8076. bindingByName = bindingsByRoot[ rootUuid ],
  8077. bindings = this._bindings;
  8078. if ( bindingByName === undefined ) {
  8079. bindingByName = {};
  8080. bindingsByRoot[ rootUuid ] = bindingByName;
  8081. }
  8082. bindingByName[ trackName ] = binding;
  8083. binding._cacheIndex = bindings.length;
  8084. bindings.push( binding );
  8085. },
  8086. _removeInactiveBinding: function( binding ) {
  8087. var bindings = this._bindings,
  8088. propBinding = binding.binding,
  8089. rootUuid = propBinding.rootNode.uuid,
  8090. trackName = propBinding.path,
  8091. bindingsByRoot = this._bindingsByRootAndName,
  8092. bindingByName = bindingsByRoot[ rootUuid ],
  8093. lastInactiveBinding = bindings[ bindings.length - 1 ],
  8094. cacheIndex = binding._cacheIndex;
  8095. lastInactiveBinding._cacheIndex = cacheIndex;
  8096. bindings[ cacheIndex ] = lastInactiveBinding;
  8097. bindings.pop();
  8098. delete bindingByName[ trackName ];
  8099. remove_empty_map: {
  8100. for ( var _ in bindingByName ) break remove_empty_map;
  8101. delete bindingsByRoot[ rootUuid ];
  8102. }
  8103. },
  8104. _lendBinding: function( binding ) {
  8105. var bindings = this._bindings,
  8106. prevIndex = binding._cacheIndex,
  8107. lastActiveIndex = this._nActiveBindings ++,
  8108. firstInactiveBinding = bindings[ lastActiveIndex ];
  8109. binding._cacheIndex = lastActiveIndex;
  8110. bindings[ lastActiveIndex ] = binding;
  8111. firstInactiveBinding._cacheIndex = prevIndex;
  8112. bindings[ prevIndex ] = firstInactiveBinding;
  8113. },
  8114. _takeBackBinding: function( binding ) {
  8115. var bindings = this._bindings,
  8116. prevIndex = binding._cacheIndex,
  8117. firstInactiveIndex = -- this._nActiveBindings,
  8118. lastActiveBinding = bindings[ firstInactiveIndex ];
  8119. binding._cacheIndex = firstInactiveIndex;
  8120. bindings[ firstInactiveIndex ] = binding;
  8121. lastActiveBinding._cacheIndex = prevIndex;
  8122. bindings[ prevIndex ] = lastActiveBinding;
  8123. },
  8124. // Memory management of Interpolants for weight and time scale
  8125. _lendControlInterpolant: function() {
  8126. var interpolants = this._controlInterpolants,
  8127. lastActiveIndex = this._nActiveControlInterpolants ++,
  8128. interpolant = interpolants[ lastActiveIndex ];
  8129. if ( interpolant === undefined ) {
  8130. interpolant = new THREE.LinearInterpolant(
  8131. new Float32Array( 2 ), new Float32Array( 2 ),
  8132. 1, this._controlInterpolantsResultBuffer );
  8133. interpolant.__cacheIndex = lastActiveIndex;
  8134. interpolants[ lastActiveIndex ] = interpolant;
  8135. }
  8136. return interpolant;
  8137. },
  8138. _takeBackControlInterpolant: function( interpolant ) {
  8139. var interpolants = this._controlInterpolants,
  8140. prevIndex = interpolant.__cacheIndex,
  8141. firstInactiveIndex = -- this._nActiveControlInterpolants,
  8142. lastActiveInterpolant = interpolants[ firstInactiveIndex ];
  8143. interpolant.__cacheIndex = firstInactiveIndex;
  8144. interpolants[ firstInactiveIndex ] = interpolant;
  8145. lastActiveInterpolant.__cacheIndex = prevIndex;
  8146. interpolants[ prevIndex ] = lastActiveInterpolant;
  8147. },
  8148. _controlInterpolantsResultBuffer: new Float32Array( 1 )
  8149. } );
  8150. // File:src/animation/AnimationObjectGroup.js
  8151. /**
  8152. *
  8153. * A group of objects that receives a shared animation state.
  8154. *
  8155. * Usage:
  8156. *
  8157. * - Add objects you would otherwise pass as 'root' to the
  8158. * constructor or the .clipAction method of AnimationMixer.
  8159. *
  8160. * - Instead pass this object as 'root'.
  8161. *
  8162. * - You can also add and remove objects later when the mixer
  8163. * is running.
  8164. *
  8165. * Note:
  8166. *
  8167. * Objects of this class appear as one object to the mixer,
  8168. * so cache control of the individual objects must be done
  8169. * on the group.
  8170. *
  8171. * Limitation:
  8172. *
  8173. * - The animated properties must be compatible among the
  8174. * all objects in the group.
  8175. *
  8176. * - A single property can either be controlled through a
  8177. * target group or directly, but not both.
  8178. *
  8179. * @author tschw
  8180. */
  8181. THREE.AnimationObjectGroup = function( var_args ) {
  8182. this.uuid = THREE.Math.generateUUID();
  8183. // cached objects followed by the active ones
  8184. this._objects = Array.prototype.slice.call( arguments );
  8185. this.nCachedObjects_ = 0; // threshold
  8186. // note: read by PropertyBinding.Composite
  8187. var indices = {};
  8188. this._indicesByUUID = indices; // for bookkeeping
  8189. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  8190. indices[ arguments[ i ].uuid ] = i;
  8191. }
  8192. this._paths = []; // inside: string
  8193. this._parsedPaths = []; // inside: { we don't care, here }
  8194. this._bindings = []; // inside: Array< PropertyBinding >
  8195. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  8196. var scope = this;
  8197. this.stats = {
  8198. objects: {
  8199. get total() { return scope._objects.length; },
  8200. get inUse() { return this.total - scope.nCachedObjects_; }
  8201. },
  8202. get bindingsPerObject() { return scope._bindings.length; }
  8203. };
  8204. };
  8205. THREE.AnimationObjectGroup.prototype = {
  8206. constructor: THREE.AnimationObjectGroup,
  8207. add: function( var_args ) {
  8208. var objects = this._objects,
  8209. nObjects = objects.length,
  8210. nCachedObjects = this.nCachedObjects_,
  8211. indicesByUUID = this._indicesByUUID,
  8212. paths = this._paths,
  8213. parsedPaths = this._parsedPaths,
  8214. bindings = this._bindings,
  8215. nBindings = bindings.length;
  8216. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  8217. var object = arguments[ i ],
  8218. uuid = object.uuid,
  8219. index = indicesByUUID[ uuid ];
  8220. if ( index === undefined ) {
  8221. // unknown object -> add it to the ACTIVE region
  8222. index = nObjects ++;
  8223. indicesByUUID[ uuid ] = index;
  8224. objects.push( object );
  8225. // accounting is done, now do the same for all bindings
  8226. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8227. bindings[ j ].push(
  8228. new THREE.PropertyBinding(
  8229. object, paths[ j ], parsedPaths[ j ] ) );
  8230. }
  8231. } else if ( index < nCachedObjects ) {
  8232. var knownObject = objects[ index ];
  8233. // move existing object to the ACTIVE region
  8234. var firstActiveIndex = -- nCachedObjects,
  8235. lastCachedObject = objects[ firstActiveIndex ];
  8236. indicesByUUID[ lastCachedObject.uuid ] = index;
  8237. objects[ index ] = lastCachedObject;
  8238. indicesByUUID[ uuid ] = firstActiveIndex;
  8239. objects[ firstActiveIndex ] = object;
  8240. // accounting is done, now do the same for all bindings
  8241. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8242. var bindingsForPath = bindings[ j ],
  8243. lastCached = bindingsForPath[ firstActiveIndex ],
  8244. binding = bindingsForPath[ index ];
  8245. bindingsForPath[ index ] = lastCached;
  8246. if ( binding === undefined ) {
  8247. // since we do not bother to create new bindings
  8248. // for objects that are cached, the binding may
  8249. // or may not exist
  8250. binding = new THREE.PropertyBinding(
  8251. object, paths[ j ], parsedPaths[ j ] );
  8252. }
  8253. bindingsForPath[ firstActiveIndex ] = binding;
  8254. }
  8255. } else if ( objects[ index ] !== knownObject) {
  8256. console.error( "Different objects with the same UUID " +
  8257. "detected. Clean the caches or recreate your " +
  8258. "infrastructure when reloading scenes..." );
  8259. } // else the object is already where we want it to be
  8260. } // for arguments
  8261. this.nCachedObjects_ = nCachedObjects;
  8262. },
  8263. remove: function( var_args ) {
  8264. var objects = this._objects,
  8265. nObjects = objects.length,
  8266. nCachedObjects = this.nCachedObjects_,
  8267. indicesByUUID = this._indicesByUUID,
  8268. bindings = this._bindings,
  8269. nBindings = bindings.length;
  8270. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  8271. var object = arguments[ i ],
  8272. uuid = object.uuid,
  8273. index = indicesByUUID[ uuid ];
  8274. if ( index !== undefined && index >= nCachedObjects ) {
  8275. // move existing object into the CACHED region
  8276. var lastCachedIndex = nCachedObjects ++,
  8277. firstActiveObject = objects[ lastCachedIndex ];
  8278. indicesByUUID[ firstActiveObject.uuid ] = index;
  8279. objects[ index ] = firstActiveObject;
  8280. indicesByUUID[ uuid ] = lastCachedIndex;
  8281. objects[ lastCachedIndex ] = object;
  8282. // accounting is done, now do the same for all bindings
  8283. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8284. var bindingsForPath = bindings[ j ],
  8285. firstActive = bindingsForPath[ lastCachedIndex ],
  8286. binding = bindingsForPath[ index ];
  8287. bindingsForPath[ index ] = firstActive;
  8288. bindingsForPath[ lastCachedIndex ] = binding;
  8289. }
  8290. }
  8291. } // for arguments
  8292. this.nCachedObjects_ = nCachedObjects;
  8293. },
  8294. // remove & forget
  8295. uncache: function( var_args ) {
  8296. var objects = this._objects,
  8297. nObjects = objects.length,
  8298. nCachedObjects = this.nCachedObjects_,
  8299. indicesByUUID = this._indicesByUUID,
  8300. bindings = this._bindings,
  8301. nBindings = bindings.length;
  8302. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  8303. var object = arguments[ i ],
  8304. uuid = object.uuid,
  8305. index = indicesByUUID[ uuid ];
  8306. if ( index !== undefined ) {
  8307. delete indicesByUUID[ uuid ];
  8308. if ( index < nCachedObjects ) {
  8309. // object is cached, shrink the CACHED region
  8310. var firstActiveIndex = -- nCachedObjects,
  8311. lastCachedObject = objects[ firstActiveIndex ],
  8312. lastIndex = -- nObjects,
  8313. lastObject = objects[ lastIndex ];
  8314. // last cached object takes this object's place
  8315. indicesByUUID[ lastCachedObject.uuid ] = index;
  8316. objects[ index ] = lastCachedObject;
  8317. // last object goes to the activated slot and pop
  8318. indicesByUUID[ lastObject.uuid ] = firstActiveIndex;
  8319. objects[ firstActiveIndex ] = lastObject;
  8320. objects.pop();
  8321. // accounting is done, now do the same for all bindings
  8322. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8323. var bindingsForPath = bindings[ j ],
  8324. lastCached = bindingsForPath[ firstActiveIndex ],
  8325. last = bindingsForPath[ lastIndex ];
  8326. bindingsForPath[ index ] = lastCached;
  8327. bindingsForPath[ firstActiveIndex ] = last;
  8328. bindingsForPath.pop();
  8329. }
  8330. } else {
  8331. // object is active, just swap with the last and pop
  8332. var lastIndex = -- nObjects,
  8333. lastObject = objects[ lastIndex ];
  8334. indicesByUUID[ lastObject.uuid ] = index;
  8335. objects[ index ] = lastObject;
  8336. objects.pop();
  8337. // accounting is done, now do the same for all bindings
  8338. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8339. var bindingsForPath = bindings[ j ];
  8340. bindingsForPath[ index ] = bindingsForPath[ lastIndex ];
  8341. bindingsForPath.pop();
  8342. }
  8343. } // cached or active
  8344. } // if object is known
  8345. } // for arguments
  8346. this.nCachedObjects_ = nCachedObjects;
  8347. },
  8348. // Internal interface used by befriended PropertyBinding.Composite:
  8349. subscribe_: function( path, parsedPath ) {
  8350. // returns an array of bindings for the given path that is changed
  8351. // according to the contained objects in the group
  8352. var indicesByPath = this._bindingsIndicesByPath,
  8353. index = indicesByPath[ path ],
  8354. bindings = this._bindings;
  8355. if ( index !== undefined ) return bindings[ index ];
  8356. var paths = this._paths,
  8357. parsedPaths = this._parsedPaths,
  8358. objects = this._objects,
  8359. nObjects = objects.length,
  8360. nCachedObjects = this.nCachedObjects_,
  8361. bindingsForPath = new Array( nObjects );
  8362. index = bindings.length;
  8363. indicesByPath[ path ] = index;
  8364. paths.push( path );
  8365. parsedPaths.push( parsedPath );
  8366. bindings.push( bindingsForPath );
  8367. for ( var i = nCachedObjects,
  8368. n = objects.length; i !== n; ++ i ) {
  8369. var object = objects[ i ];
  8370. bindingsForPath[ i ] =
  8371. new THREE.PropertyBinding( object, path, parsedPath );
  8372. }
  8373. return bindingsForPath;
  8374. },
  8375. unsubscribe_: function( path ) {
  8376. // tells the group to forget about a property path and no longer
  8377. // update the array previously obtained with 'subscribe_'
  8378. var indicesByPath = this._bindingsIndicesByPath,
  8379. index = indicesByPath[ path ];
  8380. if ( index !== undefined ) {
  8381. var paths = this._paths,
  8382. parsedPaths = this._parsedPaths,
  8383. bindings = this._bindings,
  8384. lastBindingsIndex = bindings.length - 1,
  8385. lastBindings = bindings[ lastBindingsIndex ],
  8386. lastBindingsPath = path[ lastBindingsIndex ];
  8387. indicesByPath[ lastBindingsPath ] = index;
  8388. bindings[ index ] = lastBindings;
  8389. bindings.pop();
  8390. parsedPaths[ index ] = parsedPaths[ lastBindingsIndex ];
  8391. parsedPaths.pop();
  8392. paths[ index ] = paths[ lastBindingsIndex ];
  8393. paths.pop();
  8394. }
  8395. }
  8396. };
  8397. // File:src/animation/AnimationUtils.js
  8398. /**
  8399. * @author tschw
  8400. * @author Ben Houston / http://clara.io/
  8401. * @author David Sarno / http://lighthaus.us/
  8402. */
  8403. THREE.AnimationUtils = {
  8404. // same as Array.prototype.slice, but also works on typed arrays
  8405. arraySlice: function( array, from, to ) {
  8406. if ( THREE.AnimationUtils.isTypedArray( array ) ) {
  8407. return new array.constructor( array.subarray( from, to ) );
  8408. }
  8409. return array.slice( from, to );
  8410. },
  8411. // converts an array to a specific type
  8412. convertArray: function( array, type, forceClone ) {
  8413. if ( ! array || // let 'undefined' and 'null' pass
  8414. ! forceClone && array.constructor === type ) return array;
  8415. if ( typeof type.BYTES_PER_ELEMENT === 'number' ) {
  8416. return new type( array ); // create typed array
  8417. }
  8418. return Array.prototype.slice.call( array ); // create Array
  8419. },
  8420. isTypedArray: function( object ) {
  8421. return ArrayBuffer.isView( object ) &&
  8422. ! ( object instanceof DataView );
  8423. },
  8424. // returns an array by which times and values can be sorted
  8425. getKeyframeOrder: function( times ) {
  8426. function compareTime( i, j ) {
  8427. return times[ i ] - times[ j ];
  8428. }
  8429. var n = times.length;
  8430. var result = new Array( n );
  8431. for ( var i = 0; i !== n; ++ i ) result[ i ] = i;
  8432. result.sort( compareTime );
  8433. return result;
  8434. },
  8435. // uses the array previously returned by 'getKeyframeOrder' to sort data
  8436. sortedArray: function( values, stride, order ) {
  8437. var nValues = values.length;
  8438. var result = new values.constructor( nValues );
  8439. for ( var i = 0, dstOffset = 0; dstOffset !== nValues; ++ i ) {
  8440. var srcOffset = order[ i ] * stride;
  8441. for ( var j = 0; j !== stride; ++ j ) {
  8442. result[ dstOffset ++ ] = values[ srcOffset + j ];
  8443. }
  8444. }
  8445. return result;
  8446. },
  8447. // function for parsing AOS keyframe formats
  8448. flattenJSON: function( jsonKeys, times, values, valuePropertyName ) {
  8449. var i = 1, key = jsonKeys[ 0 ];
  8450. while ( key !== undefined && key[ valuePropertyName ] === undefined ) {
  8451. key = jsonKeys[ i ++ ];
  8452. }
  8453. if ( key === undefined ) return; // no data
  8454. var value = key[ valuePropertyName ];
  8455. if ( value === undefined ) return; // no data
  8456. if ( Array.isArray( value ) ) {
  8457. do {
  8458. value = key[ valuePropertyName ];
  8459. if ( value !== undefined ) {
  8460. times.push( key.time );
  8461. values.push.apply( values, value ); // push all elements
  8462. }
  8463. key = jsonKeys[ i ++ ];
  8464. } while ( key !== undefined );
  8465. } else if ( value.toArray !== undefined ) {
  8466. // ...assume THREE.Math-ish
  8467. do {
  8468. value = key[ valuePropertyName ];
  8469. if ( value !== undefined ) {
  8470. times.push( key.time );
  8471. value.toArray( values, values.length );
  8472. }
  8473. key = jsonKeys[ i ++ ];
  8474. } while ( key !== undefined );
  8475. } else {
  8476. // otherwise push as-is
  8477. do {
  8478. value = key[ valuePropertyName ];
  8479. if ( value !== undefined ) {
  8480. times.push( key.time );
  8481. values.push( value );
  8482. }
  8483. key = jsonKeys[ i ++ ];
  8484. } while ( key !== undefined );
  8485. }
  8486. }
  8487. };
  8488. // File:src/animation/KeyframeTrack.js
  8489. /**
  8490. *
  8491. * A timed sequence of keyframes for a specific property.
  8492. *
  8493. *
  8494. * @author Ben Houston / http://clara.io/
  8495. * @author David Sarno / http://lighthaus.us/
  8496. * @author tschw
  8497. */
  8498. THREE.KeyframeTrack = function ( name, times, values, interpolation ) {
  8499. if( name === undefined ) throw new Error( "track name is undefined" );
  8500. if( times === undefined || times.length === 0 ) {
  8501. throw new Error( "no keyframes in track named " + name );
  8502. }
  8503. this.name = name;
  8504. this.times = THREE.AnimationUtils.convertArray( times, this.TimeBufferType );
  8505. this.values = THREE.AnimationUtils.convertArray( values, this.ValueBufferType );
  8506. this.setInterpolation( interpolation || this.DefaultInterpolation );
  8507. this.validate();
  8508. this.optimize();
  8509. };
  8510. THREE.KeyframeTrack.prototype = {
  8511. constructor: THREE.KeyframeTrack,
  8512. TimeBufferType: Float32Array,
  8513. ValueBufferType: Float32Array,
  8514. DefaultInterpolation: THREE.InterpolateLinear,
  8515. InterpolantFactoryMethodDiscrete: function( result ) {
  8516. return new THREE.DiscreteInterpolant(
  8517. this.times, this.values, this.getValueSize(), result );
  8518. },
  8519. InterpolantFactoryMethodLinear: function( result ) {
  8520. return new THREE.LinearInterpolant(
  8521. this.times, this.values, this.getValueSize(), result );
  8522. },
  8523. InterpolantFactoryMethodSmooth: function( result ) {
  8524. return new THREE.CubicInterpolant(
  8525. this.times, this.values, this.getValueSize(), result );
  8526. },
  8527. setInterpolation: function( interpolation ) {
  8528. var factoryMethod = undefined;
  8529. switch ( interpolation ) {
  8530. case THREE.InterpolateDiscrete:
  8531. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  8532. break;
  8533. case THREE.InterpolateLinear:
  8534. factoryMethod = this.InterpolantFactoryMethodLinear;
  8535. break;
  8536. case THREE.InterpolateSmooth:
  8537. factoryMethod = this.InterpolantFactoryMethodSmooth;
  8538. break;
  8539. }
  8540. if ( factoryMethod === undefined ) {
  8541. var message = "unsupported interpolation for " +
  8542. this.ValueTypeName + " keyframe track named " + this.name;
  8543. if ( this.createInterpolant === undefined ) {
  8544. // fall back to default, unless the default itself is messed up
  8545. if ( interpolation !== this.DefaultInterpolation ) {
  8546. this.setInterpolation( this.DefaultInterpolation );
  8547. } else {
  8548. throw new Error( message ); // fatal, in this case
  8549. }
  8550. }
  8551. console.warn( message );
  8552. return;
  8553. }
  8554. this.createInterpolant = factoryMethod;
  8555. },
  8556. getInterpolation: function() {
  8557. switch ( this.createInterpolant ) {
  8558. case this.InterpolantFactoryMethodDiscrete:
  8559. return THREE.InterpolateDiscrete;
  8560. case this.InterpolantFactoryMethodLinear:
  8561. return THREE.InterpolateLinear;
  8562. case this.InterpolantFactoryMethodSmooth:
  8563. return THREE.InterpolateSmooth;
  8564. }
  8565. },
  8566. getValueSize: function() {
  8567. return this.values.length / this.times.length;
  8568. },
  8569. // move all keyframes either forwards or backwards in time
  8570. shift: function( timeOffset ) {
  8571. if( timeOffset !== 0.0 ) {
  8572. var times = this.times;
  8573. for( var i = 0, n = times.length; i !== n; ++ i ) {
  8574. times[ i ] += timeOffset;
  8575. }
  8576. }
  8577. return this;
  8578. },
  8579. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  8580. scale: function( timeScale ) {
  8581. if( timeScale !== 1.0 ) {
  8582. var times = this.times;
  8583. for( var i = 0, n = times.length; i !== n; ++ i ) {
  8584. times[ i ] *= timeScale;
  8585. }
  8586. }
  8587. return this;
  8588. },
  8589. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  8590. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  8591. trim: function( startTime, endTime ) {
  8592. var times = this.times;
  8593. var nKeys = times.length;
  8594. var firstKeysToRemove = 0;
  8595. for ( var i = 1; i !== nKeys; ++ i ) {
  8596. if ( times[i] <= startTime ) ++ firstKeysToRemove;
  8597. }
  8598. var lastKeysToRemove = 0;
  8599. for ( var i = nKeys - 2; i !== 0; -- i ) {
  8600. if ( times[i] >= endTime ) ++ lastKeysToRemove;
  8601. else break;
  8602. }
  8603. // remove last keys first because it doesn't affect the position of the first keys (the otherway around doesn't work as easily)
  8604. if( ( firstKeysToRemove + lastKeysToRemove ) !== 0 ) {
  8605. var from = firstKeysToRemove;
  8606. var to = nKeys - lastKeysToRemove - firstKeysToRemove;
  8607. this.times = THREE.AnimationUtils.arraySlice( times, from, to );
  8608. var values = this.values;
  8609. var stride = this.getValueSize();
  8610. this.values = THREE.AnimationUtils.arraySlice( values, from * stride, to * stride );
  8611. }
  8612. return this;
  8613. },
  8614. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  8615. validate: function() {
  8616. var valid = true;
  8617. var valueSize = this.getValueSize();
  8618. if ( valueSize - Math.floor( valueSize ) !== 0 ) {
  8619. console.error( "invalid value size in track", this );
  8620. valid = false;
  8621. }
  8622. var times = this.times,
  8623. values = this.values,
  8624. nKeys = times.length;
  8625. if( nKeys === 0 ) {
  8626. console.error( "track is empty", this );
  8627. valid = false;
  8628. }
  8629. var prevTime = null;
  8630. for( var i = 0; i !== nKeys; i ++ ) {
  8631. var currTime = times[ i ];
  8632. if ( typeof currTime === 'number' && isNaN( currTime ) ) {
  8633. console.error( "time is not a valid number", this, i, currTime );
  8634. valid = false;
  8635. break;
  8636. }
  8637. if( prevTime !== null && prevTime > currTime ) {
  8638. console.error( "out of order keys", this, i, currTime, prevTime );
  8639. valid = false;
  8640. break;
  8641. }
  8642. prevTime = currTime;
  8643. }
  8644. if ( values !== undefined ) {
  8645. if ( THREE.AnimationUtils.isTypedArray( values ) ) {
  8646. for ( var i = 0, n = values.length; i !== n; ++ i ) {
  8647. var value = values[ i ];
  8648. if ( isNaN( value ) ) {
  8649. console.error( "value is not a valid number", this, i, value );
  8650. valid = false;
  8651. break;
  8652. }
  8653. }
  8654. }
  8655. }
  8656. return valid;
  8657. },
  8658. // removes equivalent sequential keys as common in morph target sequences
  8659. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  8660. optimize: function() {
  8661. var times = this.times,
  8662. values = this.values,
  8663. stride = this.getValueSize(),
  8664. writeIndex = 1;
  8665. for( var i = 1, n = times.length - 1; i <= n; ++ i ) {
  8666. var keep = false;
  8667. var time = times[ i ];
  8668. var timeNext = times[ i + 1 ];
  8669. // remove adjacent keyframes scheduled at the same time
  8670. if ( time !== timeNext && ( i !== 1 || time !== time[ 0 ] ) ) {
  8671. // remove unnecessary keyframes same as their neighbors
  8672. var offset = i * stride,
  8673. offsetP = offset - stride,
  8674. offsetN = offset + stride;
  8675. for ( var j = 0; j !== stride; ++ j ) {
  8676. var value = values[ offset + j ];
  8677. if ( value !== values[ offsetP + j ] ||
  8678. value !== values[ offsetN + j ] ) {
  8679. keep = true;
  8680. break;
  8681. }
  8682. }
  8683. }
  8684. // in-place compaction
  8685. if ( keep ) {
  8686. if ( i !== writeIndex ) {
  8687. times[ writeIndex ] = times[ i ];
  8688. var readOffset = i * stride,
  8689. writeOffset = writeIndex * stride;
  8690. for ( var j = 0; j !== stride; ++ j ) {
  8691. values[ writeOffset + j ] = values[ readOffset + j ];
  8692. }
  8693. }
  8694. ++ writeIndex;
  8695. }
  8696. }
  8697. if ( writeIndex !== times.length ) {
  8698. this.times = THREE.AnimationUtils.arraySlice( times, 0, writeIndex );
  8699. this.values = THREE.AnimationUtils.arraySlice( values, 0, writeIndex * stride );
  8700. }
  8701. return this;
  8702. }
  8703. };
  8704. // Static methods:
  8705. Object.assign( THREE.KeyframeTrack, {
  8706. // Serialization (in static context, because of constructor invocation
  8707. // and automatic invocation of .toJSON):
  8708. parse: function( json ) {
  8709. if( json.type === undefined ) {
  8710. throw new Error( "track type undefined, can not parse" );
  8711. }
  8712. var trackType = THREE.KeyframeTrack._getTrackTypeForValueTypeName( json.type );
  8713. if ( json.times === undefined ) {
  8714. console.warn( "legacy JSON format detected, converting" );
  8715. var times = [], values = [];
  8716. THREE.AnimationUtils.flattenJSON( json.keys, times, values, 'value' );
  8717. json.times = times;
  8718. json.values = values;
  8719. }
  8720. // derived classes can define a static parse method
  8721. if ( trackType.parse !== undefined ) {
  8722. return trackType.parse( json );
  8723. } else {
  8724. // by default, we asssume a constructor compatible with the base
  8725. return new trackType(
  8726. json.name, json.times, json.values, json.interpolation );
  8727. }
  8728. },
  8729. toJSON: function( track ) {
  8730. var trackType = track.constructor;
  8731. var json;
  8732. // derived classes can define a static toJSON method
  8733. if ( trackType.toJSON !== undefined ) {
  8734. json = trackType.toJSON( track );
  8735. } else {
  8736. // by default, we assume the data can be serialized as-is
  8737. json = {
  8738. 'name': track.name,
  8739. 'times': THREE.AnimationUtils.convertArray( track.times, Array ),
  8740. 'values': THREE.AnimationUtils.convertArray( track.values, Array )
  8741. };
  8742. var interpolation = track.getInterpolation();
  8743. if ( interpolation !== track.DefaultInterpolation ) {
  8744. json.interpolation = interpolation;
  8745. }
  8746. }
  8747. json.type = track.ValueTypeName; // mandatory
  8748. return json;
  8749. },
  8750. _getTrackTypeForValueTypeName: function( typeName ) {
  8751. switch( typeName.toLowerCase() ) {
  8752. case "scalar":
  8753. case "double":
  8754. case "float":
  8755. case "number":
  8756. case "integer":
  8757. return THREE.NumberKeyframeTrack;
  8758. case "vector":
  8759. case "vector2":
  8760. case "vector3":
  8761. case "vector4":
  8762. return THREE.VectorKeyframeTrack;
  8763. case "color":
  8764. return THREE.ColorKeyframeTrack;
  8765. case "quaternion":
  8766. return THREE.QuaternionKeyframeTrack;
  8767. case "bool":
  8768. case "boolean":
  8769. return THREE.BooleanKeyframeTrack;
  8770. case "string":
  8771. return THREE.StringKeyframeTrack;
  8772. };
  8773. throw new Error( "Unsupported typeName: " + typeName );
  8774. }
  8775. } );
  8776. // File:src/animation/PropertyBinding.js
  8777. /**
  8778. *
  8779. * A reference to a real property in the scene graph.
  8780. *
  8781. *
  8782. * @author Ben Houston / http://clara.io/
  8783. * @author David Sarno / http://lighthaus.us/
  8784. * @author tschw
  8785. */
  8786. THREE.PropertyBinding = function ( rootNode, path, parsedPath ) {
  8787. this.path = path;
  8788. this.parsedPath = parsedPath ||
  8789. THREE.PropertyBinding.parseTrackName( path );
  8790. this.node = THREE.PropertyBinding.findNode(
  8791. rootNode, this.parsedPath.nodeName ) || rootNode;
  8792. this.rootNode = rootNode;
  8793. };
  8794. THREE.PropertyBinding.prototype = {
  8795. constructor: THREE.PropertyBinding,
  8796. getValue: function getValue_unbound( targetArray, offset ) {
  8797. this.bind();
  8798. this.getValue( targetArray, offset );
  8799. // Note: This class uses a State pattern on a per-method basis:
  8800. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  8801. // prototype version of these methods with one that represents
  8802. // the bound state. When the property is not found, the methods
  8803. // become no-ops.
  8804. },
  8805. setValue: function getValue_unbound( sourceArray, offset ) {
  8806. this.bind();
  8807. this.setValue( sourceArray, offset );
  8808. },
  8809. // create getter / setter pair for a property in the scene graph
  8810. bind: function() {
  8811. var targetObject = this.node,
  8812. parsedPath = this.parsedPath,
  8813. objectName = parsedPath.objectName,
  8814. propertyName = parsedPath.propertyName,
  8815. propertyIndex = parsedPath.propertyIndex;
  8816. if ( ! targetObject ) {
  8817. targetObject = THREE.PropertyBinding.findNode(
  8818. this.rootNode, parsedPath.nodeName ) || this.rootNode;
  8819. this.node = targetObject;
  8820. }
  8821. // set fail state so we can just 'return' on error
  8822. this.getValue = this._getValue_unavailable;
  8823. this.setValue = this._setValue_unavailable;
  8824. // ensure there is a value node
  8825. if ( ! targetObject ) {
  8826. console.error( " trying to update node for track: " + this.path + " but it wasn't found." );
  8827. return;
  8828. }
  8829. if( objectName ) {
  8830. var objectIndex = parsedPath.objectIndex;
  8831. // special cases were we need to reach deeper into the hierarchy to get the face materials....
  8832. switch ( objectName ) {
  8833. case 'materials':
  8834. if( ! targetObject.material ) {
  8835. console.error( ' can not bind to material as node does not have a material', this );
  8836. return;
  8837. }
  8838. if( ! targetObject.material.materials ) {
  8839. console.error( ' can not bind to material.materials as node.material does not have a materials array', this );
  8840. return;
  8841. }
  8842. targetObject = targetObject.material.materials;
  8843. break;
  8844. case 'bones':
  8845. if( ! targetObject.skeleton ) {
  8846. console.error( ' can not bind to bones as node does not have a skeleton', this );
  8847. return;
  8848. }
  8849. // potential future optimization: skip this if propertyIndex is already an integer
  8850. // and convert the integer string to a true integer.
  8851. targetObject = targetObject.skeleton.bones;
  8852. // support resolving morphTarget names into indices.
  8853. for ( var i = 0; i < targetObject.length; i ++ ) {
  8854. if ( targetObject[i].name === objectIndex ) {
  8855. objectIndex = i;
  8856. break;
  8857. }
  8858. }
  8859. break;
  8860. default:
  8861. if ( targetObject[ objectName ] === undefined ) {
  8862. console.error( ' can not bind to objectName of node, undefined', this );
  8863. return;
  8864. }
  8865. targetObject = targetObject[ objectName ];
  8866. }
  8867. if ( objectIndex !== undefined ) {
  8868. if( targetObject[ objectIndex ] === undefined ) {
  8869. console.error( " trying to bind to objectIndex of objectName, but is undefined:", this, targetObject );
  8870. return;
  8871. }
  8872. targetObject = targetObject[ objectIndex ];
  8873. }
  8874. }
  8875. // resolve property
  8876. var nodeProperty = targetObject[ propertyName ];
  8877. if ( ! nodeProperty ) {
  8878. var nodeName = parsedPath.nodeName;
  8879. console.error( " trying to update property for track: " + nodeName +
  8880. '.' + propertyName + " but it wasn't found.", targetObject );
  8881. return;
  8882. }
  8883. // determine versioning scheme
  8884. var versioning = this.Versioning.None;
  8885. if ( targetObject.needsUpdate !== undefined ) { // material
  8886. versioning = this.Versioning.NeedsUpdate;
  8887. this.targetObject = targetObject;
  8888. } else if ( targetObject.matrixWorldNeedsUpdate !== undefined ) { // node transform
  8889. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  8890. this.targetObject = targetObject;
  8891. }
  8892. // determine how the property gets bound
  8893. var bindingType = this.BindingType.Direct;
  8894. if ( propertyIndex !== undefined ) {
  8895. // access a sub element of the property array (only primitives are supported right now)
  8896. if ( propertyName === "morphTargetInfluences" ) {
  8897. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  8898. // support resolving morphTarget names into indices.
  8899. if ( ! targetObject.geometry ) {
  8900. console.error( ' can not bind to morphTargetInfluences becasuse node does not have a geometry', this );
  8901. return;
  8902. }
  8903. if ( ! targetObject.geometry.morphTargets ) {
  8904. console.error( ' can not bind to morphTargetInfluences becasuse node does not have a geometry.morphTargets', this );
  8905. return;
  8906. }
  8907. for ( var i = 0; i < this.node.geometry.morphTargets.length; i ++ ) {
  8908. if ( targetObject.geometry.morphTargets[i].name === propertyIndex ) {
  8909. propertyIndex = i;
  8910. break;
  8911. }
  8912. }
  8913. }
  8914. bindingType = this.BindingType.ArrayElement;
  8915. this.resolvedProperty = nodeProperty;
  8916. this.propertyIndex = propertyIndex;
  8917. } else if ( nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined ) {
  8918. // must use copy for Object3D.Euler/Quaternion
  8919. bindingType = this.BindingType.HasFromToArray;
  8920. this.resolvedProperty = nodeProperty;
  8921. } else if ( nodeProperty.length !== undefined ) {
  8922. bindingType = this.BindingType.EntireArray;
  8923. this.resolvedProperty = nodeProperty;
  8924. } else {
  8925. this.propertyName = propertyName;
  8926. }
  8927. // select getter / setter
  8928. this.getValue = this.GetterByBindingType[ bindingType ];
  8929. this.setValue = this.SetterByBindingTypeAndVersioning[ bindingType ][ versioning ];
  8930. },
  8931. unbind: function() {
  8932. this.node = null;
  8933. // back to the prototype version of getValue / setValue
  8934. // note: avoiding to mutate the shape of 'this' via 'delete'
  8935. this.getValue = this._getValue_unbound;
  8936. this.setValue = this._setValue_unbound;
  8937. }
  8938. };
  8939. Object.assign( THREE.PropertyBinding.prototype, { // prototype, continued
  8940. // these are used to "bind" a nonexistent property
  8941. _getValue_unavailable: function() {},
  8942. _setValue_unavailable: function() {},
  8943. // initial state of these methods that calls 'bind'
  8944. _getValue_unbound: THREE.PropertyBinding.prototype.getValue,
  8945. _setValue_unbound: THREE.PropertyBinding.prototype.setValue,
  8946. BindingType: {
  8947. Direct: 0,
  8948. EntireArray: 1,
  8949. ArrayElement: 2,
  8950. HasFromToArray: 3
  8951. },
  8952. Versioning: {
  8953. None: 0,
  8954. NeedsUpdate: 1,
  8955. MatrixWorldNeedsUpdate: 2
  8956. },
  8957. GetterByBindingType: [
  8958. function getValue_direct( buffer, offset ) {
  8959. buffer[ offset ] = this.node[ this.propertyName ];
  8960. },
  8961. function getValue_array( buffer, offset ) {
  8962. var source = this.resolvedProperty;
  8963. for ( var i = 0, n = source.length; i !== n; ++ i ) {
  8964. buffer[ offset ++ ] = source[ i ];
  8965. }
  8966. },
  8967. function getValue_arrayElement( buffer, offset ) {
  8968. buffer[ offset ] = this.resolvedProperty[ this.propertyIndex ];
  8969. },
  8970. function getValue_toArray( buffer, offset ) {
  8971. this.resolvedProperty.toArray( buffer, offset );
  8972. }
  8973. ],
  8974. SetterByBindingTypeAndVersioning: [
  8975. [
  8976. // Direct
  8977. function setValue_direct( buffer, offset ) {
  8978. this.node[ this.propertyName ] = buffer[ offset ];
  8979. },
  8980. function setValue_direct_setNeedsUpdate( buffer, offset ) {
  8981. this.node[ this.propertyName ] = buffer[ offset ];
  8982. this.targetObject.needsUpdate = true;
  8983. },
  8984. function setValue_direct_setMatrixWorldNeedsUpdate( buffer, offset ) {
  8985. this.node[ this.propertyName ] = buffer[ offset ];
  8986. this.targetObject.matrixWorldNeedsUpdate = true;
  8987. }
  8988. ], [
  8989. // EntireArray
  8990. function setValue_array( buffer, offset ) {
  8991. var dest = this.resolvedProperty;
  8992. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  8993. dest[ i ] = buffer[ offset ++ ];
  8994. }
  8995. },
  8996. function setValue_array_setNeedsUpdate( buffer, offset ) {
  8997. var dest = this.resolvedProperty;
  8998. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  8999. dest[ i ] = buffer[ offset ++ ];
  9000. }
  9001. this.targetObject.needsUpdate = true;
  9002. },
  9003. function setValue_array_setMatrixWorldNeedsUpdate( buffer, offset ) {
  9004. var dest = this.resolvedProperty;
  9005. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  9006. dest[ i ] = buffer[ offset ++ ];
  9007. }
  9008. this.targetObject.matrixWorldNeedsUpdate = true;
  9009. }
  9010. ], [
  9011. // ArrayElement
  9012. function setValue_arrayElement( buffer, offset ) {
  9013. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  9014. },
  9015. function setValue_arrayElement_setNeedsUpdate( buffer, offset ) {
  9016. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  9017. this.targetObject.needsUpdate = true;
  9018. },
  9019. function setValue_arrayElement_setMatrixWorldNeedsUpdate( buffer, offset ) {
  9020. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  9021. this.targetObject.matrixWorldNeedsUpdate = true;
  9022. }
  9023. ], [
  9024. // HasToFromArray
  9025. function setValue_fromArray( buffer, offset ) {
  9026. this.resolvedProperty.fromArray( buffer, offset );
  9027. },
  9028. function setValue_fromArray_setNeedsUpdate( buffer, offset ) {
  9029. this.resolvedProperty.fromArray( buffer, offset );
  9030. this.targetObject.needsUpdate = true;
  9031. },
  9032. function setValue_fromArray_setMatrixWorldNeedsUpdate( buffer, offset ) {
  9033. this.resolvedProperty.fromArray( buffer, offset );
  9034. this.targetObject.matrixWorldNeedsUpdate = true;
  9035. }
  9036. ]
  9037. ]
  9038. } );
  9039. THREE.PropertyBinding.Composite =
  9040. function( targetGroup, path, optionalParsedPath ) {
  9041. var parsedPath = optionalParsedPath ||
  9042. THREE.PropertyBinding.parseTrackName( path );
  9043. this._targetGroup = targetGroup;
  9044. this._bindings = targetGroup.subscribe_( path, parsedPath );
  9045. };
  9046. THREE.PropertyBinding.Composite.prototype = {
  9047. constructor: THREE.PropertyBinding.Composite,
  9048. getValue: function( array, offset ) {
  9049. this.bind(); // bind all binding
  9050. var firstValidIndex = this._targetGroup.nCachedObjects_,
  9051. binding = this._bindings[ firstValidIndex ];
  9052. // and only call .getValue on the first
  9053. if ( binding !== undefined ) binding.getValue( array, offset );
  9054. },
  9055. setValue: function( array, offset ) {
  9056. var bindings = this._bindings;
  9057. for ( var i = this._targetGroup.nCachedObjects_,
  9058. n = bindings.length; i !== n; ++ i ) {
  9059. bindings[ i ].setValue( array, offset );
  9060. }
  9061. },
  9062. bind: function() {
  9063. var bindings = this._bindings;
  9064. for ( var i = this._targetGroup.nCachedObjects_,
  9065. n = bindings.length; i !== n; ++ i ) {
  9066. bindings[ i ].bind();
  9067. }
  9068. },
  9069. unbind: function() {
  9070. var bindings = this._bindings;
  9071. for ( var i = this._targetGroup.nCachedObjects_,
  9072. n = bindings.length; i !== n; ++ i ) {
  9073. bindings[ i ].unbind();
  9074. }
  9075. }
  9076. };
  9077. THREE.PropertyBinding.create = function( root, path, parsedPath ) {
  9078. if ( ! ( root instanceof THREE.AnimationObjectGroup ) ) {
  9079. return new THREE.PropertyBinding( root, path, parsedPath );
  9080. } else {
  9081. return new THREE.PropertyBinding.Composite( root, path, parsedPath );
  9082. }
  9083. };
  9084. THREE.PropertyBinding.parseTrackName = function( trackName ) {
  9085. // matches strings in the form of:
  9086. // nodeName.property
  9087. // nodeName.property[accessor]
  9088. // nodeName.material.property[accessor]
  9089. // uuid.property[accessor]
  9090. // uuid.objectName[objectIndex].propertyName[propertyIndex]
  9091. // parentName/nodeName.property
  9092. // parentName/parentName/nodeName.property[index]
  9093. // .bone[Armature.DEF_cog].position
  9094. // created and tested via https://regex101.com/#javascript
  9095. var re = /^(([\w]+\/)*)([\w-\d]+)?(\.([\w]+)(\[([\w\d\[\]\_. ]+)\])?)?(\.([\w.]+)(\[([\w\d\[\]\_. ]+)\])?)$/;
  9096. var matches = re.exec(trackName);
  9097. if( ! matches ) {
  9098. throw new Error( "cannot parse trackName at all: " + trackName );
  9099. }
  9100. if (matches.index === re.lastIndex) {
  9101. re.lastIndex++;
  9102. }
  9103. var results = {
  9104. // directoryName: matches[1], // (tschw) currently unused
  9105. nodeName: matches[3], // allowed to be null, specified root node.
  9106. objectName: matches[5],
  9107. objectIndex: matches[7],
  9108. propertyName: matches[9],
  9109. propertyIndex: matches[11] // allowed to be null, specifies that the whole property is set.
  9110. };
  9111. if( results.propertyName === null || results.propertyName.length === 0 ) {
  9112. throw new Error( "can not parse propertyName from trackName: " + trackName );
  9113. }
  9114. return results;
  9115. };
  9116. THREE.PropertyBinding.findNode = function( root, nodeName ) {
  9117. if( ! nodeName || nodeName === "" || nodeName === "root" || nodeName === "." || nodeName === -1 || nodeName === root.name || nodeName === root.uuid ) {
  9118. return root;
  9119. }
  9120. // search into skeleton bones.
  9121. if( root.skeleton ) {
  9122. var searchSkeleton = function( skeleton ) {
  9123. for( var i = 0; i < skeleton.bones.length; i ++ ) {
  9124. var bone = skeleton.bones[i];
  9125. if( bone.name === nodeName ) {
  9126. return bone;
  9127. }
  9128. }
  9129. return null;
  9130. };
  9131. var bone = searchSkeleton( root.skeleton );
  9132. if( bone ) {
  9133. return bone;
  9134. }
  9135. }
  9136. // search into node subtree.
  9137. if( root.children ) {
  9138. var searchNodeSubtree = function( children ) {
  9139. for( var i = 0; i < children.length; i ++ ) {
  9140. var childNode = children[i];
  9141. if( childNode.name === nodeName || childNode.uuid === nodeName ) {
  9142. return childNode;
  9143. }
  9144. var result = searchNodeSubtree( childNode.children );
  9145. if( result ) return result;
  9146. }
  9147. return null;
  9148. };
  9149. var subTreeNode = searchNodeSubtree( root.children );
  9150. if( subTreeNode ) {
  9151. return subTreeNode;
  9152. }
  9153. }
  9154. return null;
  9155. }
  9156. // File:src/animation/PropertyMixer.js
  9157. /**
  9158. *
  9159. * Buffered scene graph property that allows weighted accumulation.
  9160. *
  9161. *
  9162. * @author Ben Houston / http://clara.io/
  9163. * @author David Sarno / http://lighthaus.us/
  9164. * @author tschw
  9165. */
  9166. THREE.PropertyMixer = function ( binding, typeName, valueSize ) {
  9167. this.binding = binding;
  9168. this.valueSize = valueSize;
  9169. var bufferType = Float64Array,
  9170. mixFunction;
  9171. switch ( typeName ) {
  9172. case 'quaternion': mixFunction = this._slerp; break;
  9173. case 'string':
  9174. case 'bool':
  9175. bufferType = Array, mixFunction = this._select; break;
  9176. default: mixFunction = this._lerp;
  9177. }
  9178. this.buffer = new bufferType( valueSize * 4 );
  9179. // layout: [ incoming | accu0 | accu1 | orig ]
  9180. //
  9181. // interpolators can use .buffer as their .result
  9182. // the data then goes to 'incoming'
  9183. //
  9184. // 'accu0' and 'accu1' are used frame-interleaved for
  9185. // the cumulative result and are compared to detect
  9186. // changes
  9187. //
  9188. // 'orig' stores the original state of the property
  9189. this._mixBufferRegion = mixFunction;
  9190. this.cumulativeWeight = 0;
  9191. this.useCount = 0;
  9192. this.referenceCount = 0;
  9193. };
  9194. THREE.PropertyMixer.prototype = {
  9195. constructor: THREE.PropertyMixer,
  9196. // accumulate data in the 'incoming' region into 'accu<i>'
  9197. accumulate: function( accuIndex, weight ) {
  9198. // note: happily accumulating nothing when weight = 0, the caller knows
  9199. // the weight and shouldn't have made the call in the first place
  9200. var buffer = this.buffer,
  9201. stride = this.valueSize,
  9202. offset = accuIndex * stride + stride,
  9203. currentWeight = this.cumulativeWeight;
  9204. if ( currentWeight === 0 ) {
  9205. // accuN := incoming * weight
  9206. for ( var i = 0; i !== stride; ++ i ) {
  9207. buffer[ offset + i ] = buffer[ i ];
  9208. }
  9209. currentWeight = weight;
  9210. } else {
  9211. // accuN := accuN + incoming * weight
  9212. currentWeight += weight;
  9213. var mix = weight / currentWeight;
  9214. this._mixBufferRegion( buffer, offset, 0, mix, stride );
  9215. }
  9216. this.cumulativeWeight = currentWeight;
  9217. },
  9218. // apply the state of 'accu<i>' to the binding when accus differ
  9219. apply: function( accuIndex ) {
  9220. var stride = this.valueSize,
  9221. buffer = this.buffer,
  9222. offset = accuIndex * stride + stride,
  9223. weight = this.cumulativeWeight,
  9224. binding = this.binding;
  9225. this.cumulativeWeight = 0;
  9226. if ( weight < 1 ) {
  9227. // accuN := accuN + original * ( 1 - cumulativeWeight )
  9228. var originalValueOffset = stride * 3;
  9229. this._mixBufferRegion(
  9230. buffer, offset, originalValueOffset, 1 - weight, stride );
  9231. }
  9232. for ( var i = stride, e = stride + stride; i !== e; ++ i ) {
  9233. if ( buffer[ i ] !== buffer[ i + stride ] ) {
  9234. // value has changed -> update scene graph
  9235. binding.setValue( buffer, offset );
  9236. break;
  9237. }
  9238. }
  9239. },
  9240. // remember the state of the bound property and copy it to both accus
  9241. saveOriginalState: function() {
  9242. var binding = this.binding;
  9243. var buffer = this.buffer,
  9244. stride = this.valueSize,
  9245. originalValueOffset = stride * 3;
  9246. binding.getValue( buffer, originalValueOffset );
  9247. // accu[0..1] := orig -- initially detect changes against the original
  9248. for ( var i = stride, e = originalValueOffset; i !== e; ++ i ) {
  9249. buffer[ i ] = buffer[ originalValueOffset + ( i % stride ) ];
  9250. }
  9251. this.cumulativeWeight = 0;
  9252. },
  9253. // apply the state previously taken via 'saveOriginalState' to the binding
  9254. restoreOriginalState: function() {
  9255. var originalValueOffset = this.valueSize * 3;
  9256. this.binding.setValue( this.buffer, originalValueOffset );
  9257. },
  9258. // mix functions
  9259. _select: function( buffer, dstOffset, srcOffset, t, stride ) {
  9260. if ( t >= 0.5 ) {
  9261. for ( var i = 0; i !== stride; ++ i ) {
  9262. buffer[ dstOffset + i ] = buffer[ srcOffset + i ];
  9263. }
  9264. }
  9265. },
  9266. _slerp: function( buffer, dstOffset, srcOffset, t, stride ) {
  9267. THREE.Quaternion.slerpFlat( buffer, dstOffset,
  9268. buffer, dstOffset, buffer, srcOffset, t );
  9269. },
  9270. _lerp: function( buffer, dstOffset, srcOffset, t, stride ) {
  9271. var s = 1 - t;
  9272. for ( var i = 0; i !== stride; ++ i ) {
  9273. var j = dstOffset + i;
  9274. buffer[ j ] = buffer[ j ] * s + buffer[ srcOffset + i ] * t;
  9275. }
  9276. }
  9277. };
  9278. // File:src/animation/tracks/BooleanKeyframeTrack.js
  9279. /**
  9280. *
  9281. * A Track of Boolean keyframe values.
  9282. *
  9283. *
  9284. * @author Ben Houston / http://clara.io/
  9285. * @author David Sarno / http://lighthaus.us/
  9286. * @author tschw
  9287. */
  9288. THREE.BooleanKeyframeTrack = function ( name, times, values ) {
  9289. THREE.KeyframeTrack.call( this, name, times, values );
  9290. };
  9291. THREE.BooleanKeyframeTrack.prototype =
  9292. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9293. constructor: THREE.BooleanKeyframeTrack,
  9294. ValueTypeName: 'bool',
  9295. ValueBufferType: Array,
  9296. DefaultInterpolation: THREE.IntepolateDiscrete,
  9297. InterpolantFactoryMethodLinear: undefined,
  9298. InterpolantFactoryMethodSmooth: undefined
  9299. // Note: Actually this track could have a optimized / compressed
  9300. // representation of a single value and a custom interpolant that
  9301. // computes "firstValue ^ isOdd( index )".
  9302. } );
  9303. // File:src/animation/tracks/NumberKeyframeTrack.js
  9304. /**
  9305. *
  9306. * A Track of numeric keyframe values.
  9307. *
  9308. * @author Ben Houston / http://clara.io/
  9309. * @author David Sarno / http://lighthaus.us/
  9310. * @author tschw
  9311. */
  9312. THREE.NumberKeyframeTrack = function ( name, times, values, interpolation ) {
  9313. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9314. };
  9315. THREE.NumberKeyframeTrack.prototype =
  9316. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9317. constructor: THREE.NumberKeyframeTrack,
  9318. ValueTypeName: 'number',
  9319. // ValueBufferType is inherited
  9320. // DefaultInterpolation is inherited
  9321. } );
  9322. // File:src/animation/tracks/QuaternionKeyframeTrack.js
  9323. /**
  9324. *
  9325. * A Track of quaternion keyframe values.
  9326. *
  9327. * @author Ben Houston / http://clara.io/
  9328. * @author David Sarno / http://lighthaus.us/
  9329. * @author tschw
  9330. */
  9331. THREE.QuaternionKeyframeTrack = function ( name, times, values, interpolation ) {
  9332. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9333. };
  9334. THREE.QuaternionKeyframeTrack.prototype =
  9335. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9336. constructor: THREE.QuaternionKeyframeTrack,
  9337. ValueTypeName: 'quaternion',
  9338. // ValueBufferType is inherited
  9339. DefaultInterpolation: THREE.InterpolateLinear,
  9340. InterpolantFactoryMethodLinear: function( result ) {
  9341. return new THREE.QuaternionLinearInterpolant(
  9342. this.times, this.values, this.getValueSize(), result );
  9343. },
  9344. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  9345. } );
  9346. // File:src/animation/tracks/StringKeyframeTrack.js
  9347. /**
  9348. *
  9349. * A Track that interpolates Strings
  9350. *
  9351. *
  9352. * @author Ben Houston / http://clara.io/
  9353. * @author David Sarno / http://lighthaus.us/
  9354. * @author tschw
  9355. */
  9356. THREE.StringKeyframeTrack = function ( name, times, values, interpolation ) {
  9357. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9358. };
  9359. THREE.StringKeyframeTrack.prototype =
  9360. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9361. constructor: THREE.StringKeyframeTrack,
  9362. ValueTypeName: 'string',
  9363. ValueBufferType: Array,
  9364. DefaultInterpolation: THREE.IntepolateDiscrete,
  9365. InterpolantFactoryMethodLinear: undefined,
  9366. InterpolantFactoryMethodSmooth: undefined
  9367. } );
  9368. // File:src/animation/tracks/VectorKeyframeTrack.js
  9369. /**
  9370. *
  9371. * A Track of vectored keyframe values.
  9372. *
  9373. *
  9374. * @author Ben Houston / http://clara.io/
  9375. * @author David Sarno / http://lighthaus.us/
  9376. * @author tschw
  9377. */
  9378. THREE.VectorKeyframeTrack = function ( name, times, values, interpolation ) {
  9379. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9380. };
  9381. THREE.VectorKeyframeTrack.prototype =
  9382. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9383. constructor: THREE.VectorKeyframeTrack,
  9384. ValueTypeName: 'vector'
  9385. // ValueBufferType is inherited
  9386. // DefaultInterpolation is inherited
  9387. } );
  9388. // File:src/audio/Audio.js
  9389. /**
  9390. * @author mrdoob / http://mrdoob.com/
  9391. */
  9392. THREE.Audio = function ( listener ) {
  9393. THREE.Object3D.call( this );
  9394. this.type = 'Audio';
  9395. this.context = listener.context;
  9396. this.source = this.context.createBufferSource();
  9397. this.source.onended = this.onEnded.bind( this );
  9398. this.gain = this.context.createGain();
  9399. this.gain.connect( this.context.destination );
  9400. this.panner = this.context.createPanner();
  9401. this.panner.connect( this.gain );
  9402. this.autoplay = false;
  9403. this.startTime = 0;
  9404. this.playbackRate = 1;
  9405. this.isPlaying = false;
  9406. };
  9407. THREE.Audio.prototype = Object.create( THREE.Object3D.prototype );
  9408. THREE.Audio.prototype.constructor = THREE.Audio;
  9409. THREE.Audio.prototype.load = function ( file ) {
  9410. var scope = this;
  9411. var request = new XMLHttpRequest();
  9412. request.open( 'GET', file, true );
  9413. request.responseType = 'arraybuffer';
  9414. request.onload = function ( e ) {
  9415. scope.context.decodeAudioData( this.response, function ( buffer ) {
  9416. scope.source.buffer = buffer;
  9417. if ( scope.autoplay ) scope.play();
  9418. } );
  9419. };
  9420. request.send();
  9421. return this;
  9422. };
  9423. THREE.Audio.prototype.play = function () {
  9424. if ( this.isPlaying === true ) {
  9425. console.warn( 'THREE.Audio: Audio is already playing.' );
  9426. return;
  9427. }
  9428. var source = this.context.createBufferSource();
  9429. source.buffer = this.source.buffer;
  9430. source.loop = this.source.loop;
  9431. source.onended = this.source.onended;
  9432. source.start( 0, this.startTime );
  9433. source.playbackRate.value = this.playbackRate;
  9434. this.isPlaying = true;
  9435. this.source = source;
  9436. this.connect();
  9437. };
  9438. THREE.Audio.prototype.pause = function () {
  9439. this.source.stop();
  9440. this.startTime = this.context.currentTime;
  9441. };
  9442. THREE.Audio.prototype.stop = function () {
  9443. this.source.stop();
  9444. this.startTime = 0;
  9445. };
  9446. THREE.Audio.prototype.connect = function () {
  9447. if ( this.filter !== undefined ) {
  9448. this.source.connect( this.filter );
  9449. this.filter.connect( this.panner );
  9450. } else {
  9451. this.source.connect( this.panner );
  9452. }
  9453. };
  9454. THREE.Audio.prototype.disconnect = function () {
  9455. if ( this.filter !== undefined ) {
  9456. this.source.disconnect( this.filter );
  9457. this.filter.disconnect( this.panner );
  9458. } else {
  9459. this.source.disconnect( this.panner );
  9460. }
  9461. };
  9462. THREE.Audio.prototype.setFilter = function ( value ) {
  9463. if ( this.isPlaying === true ) {
  9464. this.disconnect();
  9465. this.filter = value;
  9466. this.connect();
  9467. } else {
  9468. this.filter = value;
  9469. }
  9470. };
  9471. THREE.Audio.prototype.getFilter = function () {
  9472. return this.filter;
  9473. };
  9474. THREE.Audio.prototype.setPlaybackRate = function ( value ) {
  9475. this.playbackRate = value;
  9476. if ( this.isPlaying === true ) {
  9477. this.source.playbackRate.value = this.playbackRate;
  9478. }
  9479. };
  9480. THREE.Audio.prototype.getPlaybackRate = function () {
  9481. return this.playbackRate;
  9482. };
  9483. THREE.Audio.prototype.onEnded = function() {
  9484. this.isPlaying = false;
  9485. };
  9486. THREE.Audio.prototype.setLoop = function ( value ) {
  9487. this.source.loop = value;
  9488. };
  9489. THREE.Audio.prototype.getLoop = function () {
  9490. return this.source.loop;
  9491. };
  9492. THREE.Audio.prototype.setRefDistance = function ( value ) {
  9493. this.panner.refDistance = value;
  9494. };
  9495. THREE.Audio.prototype.getRefDistance = function () {
  9496. return this.panner.refDistance;
  9497. };
  9498. THREE.Audio.prototype.setRolloffFactor = function ( value ) {
  9499. this.panner.rolloffFactor = value;
  9500. };
  9501. THREE.Audio.prototype.getRolloffFactor = function () {
  9502. return this.panner.rolloffFactor;
  9503. };
  9504. THREE.Audio.prototype.setVolume = function ( value ) {
  9505. this.gain.gain.value = value;
  9506. };
  9507. THREE.Audio.prototype.getVolume = function () {
  9508. return this.gain.gain.value;
  9509. };
  9510. THREE.Audio.prototype.updateMatrixWorld = ( function () {
  9511. var position = new THREE.Vector3();
  9512. return function updateMatrixWorld( force ) {
  9513. THREE.Object3D.prototype.updateMatrixWorld.call( this, force );
  9514. position.setFromMatrixPosition( this.matrixWorld );
  9515. this.panner.setPosition( position.x, position.y, position.z );
  9516. };
  9517. } )();
  9518. // File:src/audio/AudioListener.js
  9519. /**
  9520. * @author mrdoob / http://mrdoob.com/
  9521. */
  9522. THREE.AudioListener = function () {
  9523. THREE.Object3D.call( this );
  9524. this.type = 'AudioListener';
  9525. this.context = new ( window.AudioContext || window.webkitAudioContext )();
  9526. };
  9527. THREE.AudioListener.prototype = Object.create( THREE.Object3D.prototype );
  9528. THREE.AudioListener.prototype.constructor = THREE.AudioListener;
  9529. THREE.AudioListener.prototype.updateMatrixWorld = ( function () {
  9530. var position = new THREE.Vector3();
  9531. var quaternion = new THREE.Quaternion();
  9532. var scale = new THREE.Vector3();
  9533. var orientation = new THREE.Vector3();
  9534. return function updateMatrixWorld( force ) {
  9535. THREE.Object3D.prototype.updateMatrixWorld.call( this, force );
  9536. var listener = this.context.listener;
  9537. var up = this.up;
  9538. this.matrixWorld.decompose( position, quaternion, scale );
  9539. orientation.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  9540. listener.setPosition( position.x, position.y, position.z );
  9541. listener.setOrientation( orientation.x, orientation.y, orientation.z, up.x, up.y, up.z );
  9542. };
  9543. } )();
  9544. // File:src/cameras/Camera.js
  9545. /**
  9546. * @author mrdoob / http://mrdoob.com/
  9547. * @author mikael emtinger / http://gomo.se/
  9548. * @author WestLangley / http://github.com/WestLangley
  9549. */
  9550. THREE.Camera = function () {
  9551. THREE.Object3D.call( this );
  9552. this.type = 'Camera';
  9553. this.matrixWorldInverse = new THREE.Matrix4();
  9554. this.projectionMatrix = new THREE.Matrix4();
  9555. };
  9556. THREE.Camera.prototype = Object.create( THREE.Object3D.prototype );
  9557. THREE.Camera.prototype.constructor = THREE.Camera;
  9558. THREE.Camera.prototype.getWorldDirection = function () {
  9559. var quaternion = new THREE.Quaternion();
  9560. return function ( optionalTarget ) {
  9561. var result = optionalTarget || new THREE.Vector3();
  9562. this.getWorldQuaternion( quaternion );
  9563. return result.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  9564. };
  9565. }();
  9566. THREE.Camera.prototype.lookAt = function () {
  9567. // This routine does not support cameras with rotated and/or translated parent(s)
  9568. var m1 = new THREE.Matrix4();
  9569. return function ( vector ) {
  9570. m1.lookAt( this.position, vector, this.up );
  9571. this.quaternion.setFromRotationMatrix( m1 );
  9572. };
  9573. }();
  9574. THREE.Camera.prototype.clone = function () {
  9575. return new this.constructor().copy( this );
  9576. };
  9577. THREE.Camera.prototype.copy = function ( source ) {
  9578. THREE.Object3D.prototype.copy.call( this, source );
  9579. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  9580. this.projectionMatrix.copy( source.projectionMatrix );
  9581. return this;
  9582. };
  9583. // File:src/cameras/CubeCamera.js
  9584. /**
  9585. * Camera for rendering cube maps
  9586. * - renders scene into axis-aligned cube
  9587. *
  9588. * @author alteredq / http://alteredqualia.com/
  9589. */
  9590. THREE.CubeCamera = function ( near, far, cubeResolution ) {
  9591. THREE.Object3D.call( this );
  9592. this.type = 'CubeCamera';
  9593. var fov = 90, aspect = 1;
  9594. var cameraPX = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9595. cameraPX.up.set( 0, - 1, 0 );
  9596. cameraPX.lookAt( new THREE.Vector3( 1, 0, 0 ) );
  9597. this.add( cameraPX );
  9598. var cameraNX = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9599. cameraNX.up.set( 0, - 1, 0 );
  9600. cameraNX.lookAt( new THREE.Vector3( - 1, 0, 0 ) );
  9601. this.add( cameraNX );
  9602. var cameraPY = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9603. cameraPY.up.set( 0, 0, 1 );
  9604. cameraPY.lookAt( new THREE.Vector3( 0, 1, 0 ) );
  9605. this.add( cameraPY );
  9606. var cameraNY = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9607. cameraNY.up.set( 0, 0, - 1 );
  9608. cameraNY.lookAt( new THREE.Vector3( 0, - 1, 0 ) );
  9609. this.add( cameraNY );
  9610. var cameraPZ = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9611. cameraPZ.up.set( 0, - 1, 0 );
  9612. cameraPZ.lookAt( new THREE.Vector3( 0, 0, 1 ) );
  9613. this.add( cameraPZ );
  9614. var cameraNZ = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9615. cameraNZ.up.set( 0, - 1, 0 );
  9616. cameraNZ.lookAt( new THREE.Vector3( 0, 0, - 1 ) );
  9617. this.add( cameraNZ );
  9618. this.renderTarget = new THREE.WebGLRenderTargetCube( cubeResolution, cubeResolution, { format: THREE.RGBFormat, magFilter: THREE.LinearFilter, minFilter: THREE.LinearFilter } );
  9619. this.updateCubeMap = function ( renderer, scene ) {
  9620. if ( this.parent === null ) this.updateMatrixWorld();
  9621. var renderTarget = this.renderTarget;
  9622. var generateMipmaps = renderTarget.texture.generateMipmaps;
  9623. renderTarget.texture.generateMipmaps = false;
  9624. renderTarget.activeCubeFace = 0;
  9625. renderer.render( scene, cameraPX, renderTarget );
  9626. renderTarget.activeCubeFace = 1;
  9627. renderer.render( scene, cameraNX, renderTarget );
  9628. renderTarget.activeCubeFace = 2;
  9629. renderer.render( scene, cameraPY, renderTarget );
  9630. renderTarget.activeCubeFace = 3;
  9631. renderer.render( scene, cameraNY, renderTarget );
  9632. renderTarget.activeCubeFace = 4;
  9633. renderer.render( scene, cameraPZ, renderTarget );
  9634. renderTarget.texture.generateMipmaps = generateMipmaps;
  9635. renderTarget.activeCubeFace = 5;
  9636. renderer.render( scene, cameraNZ, renderTarget );
  9637. renderer.setRenderTarget( null );
  9638. };
  9639. };
  9640. THREE.CubeCamera.prototype = Object.create( THREE.Object3D.prototype );
  9641. THREE.CubeCamera.prototype.constructor = THREE.CubeCamera;
  9642. // File:src/cameras/OrthographicCamera.js
  9643. /**
  9644. * @author alteredq / http://alteredqualia.com/
  9645. */
  9646. THREE.OrthographicCamera = function ( left, right, top, bottom, near, far ) {
  9647. THREE.Camera.call( this );
  9648. this.type = 'OrthographicCamera';
  9649. this.zoom = 1;
  9650. this.left = left;
  9651. this.right = right;
  9652. this.top = top;
  9653. this.bottom = bottom;
  9654. this.near = ( near !== undefined ) ? near : 0.1;
  9655. this.far = ( far !== undefined ) ? far : 2000;
  9656. this.updateProjectionMatrix();
  9657. };
  9658. THREE.OrthographicCamera.prototype = Object.create( THREE.Camera.prototype );
  9659. THREE.OrthographicCamera.prototype.constructor = THREE.OrthographicCamera;
  9660. THREE.OrthographicCamera.prototype.updateProjectionMatrix = function () {
  9661. var dx = ( this.right - this.left ) / ( 2 * this.zoom );
  9662. var dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  9663. var cx = ( this.right + this.left ) / 2;
  9664. var cy = ( this.top + this.bottom ) / 2;
  9665. this.projectionMatrix.makeOrthographic( cx - dx, cx + dx, cy + dy, cy - dy, this.near, this.far );
  9666. };
  9667. THREE.OrthographicCamera.prototype.copy = function ( source ) {
  9668. THREE.Camera.prototype.copy.call( this, source );
  9669. this.left = source.left;
  9670. this.right = source.right;
  9671. this.top = source.top;
  9672. this.bottom = source.bottom;
  9673. this.near = source.near;
  9674. this.far = source.far;
  9675. this.zoom = source.zoom;
  9676. return this;
  9677. };
  9678. THREE.OrthographicCamera.prototype.toJSON = function ( meta ) {
  9679. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  9680. data.object.zoom = this.zoom;
  9681. data.object.left = this.left;
  9682. data.object.right = this.right;
  9683. data.object.top = this.top;
  9684. data.object.bottom = this.bottom;
  9685. data.object.near = this.near;
  9686. data.object.far = this.far;
  9687. return data;
  9688. };
  9689. // File:src/cameras/PerspectiveCamera.js
  9690. /**
  9691. * @author mrdoob / http://mrdoob.com/
  9692. * @author greggman / http://games.greggman.com/
  9693. * @author zz85 / http://www.lab4games.net/zz85/blog
  9694. */
  9695. THREE.PerspectiveCamera = function ( fov, aspect, near, far ) {
  9696. THREE.Camera.call( this );
  9697. this.type = 'PerspectiveCamera';
  9698. this.zoom = 1;
  9699. this.fov = fov !== undefined ? fov : 50;
  9700. this.aspect = aspect !== undefined ? aspect : 1;
  9701. this.near = near !== undefined ? near : 0.1;
  9702. this.far = far !== undefined ? far : 2000;
  9703. this.updateProjectionMatrix();
  9704. };
  9705. THREE.PerspectiveCamera.prototype = Object.create( THREE.Camera.prototype );
  9706. THREE.PerspectiveCamera.prototype.constructor = THREE.PerspectiveCamera;
  9707. /**
  9708. * Uses Focal Length (in mm) to estimate and set FOV
  9709. * 35mm (full-frame) camera is used if frame size is not specified;
  9710. * Formula based on http://www.bobatkins.com/photography/technical/field_of_view.html
  9711. */
  9712. THREE.PerspectiveCamera.prototype.setLens = function ( focalLength, frameHeight ) {
  9713. if ( frameHeight === undefined ) frameHeight = 24;
  9714. this.fov = 2 * THREE.Math.radToDeg( Math.atan( frameHeight / ( focalLength * 2 ) ) );
  9715. this.updateProjectionMatrix();
  9716. };
  9717. /**
  9718. * Sets an offset in a larger frustum. This is useful for multi-window or
  9719. * multi-monitor/multi-machine setups.
  9720. *
  9721. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  9722. * the monitors are in grid like this
  9723. *
  9724. * +---+---+---+
  9725. * | A | B | C |
  9726. * +---+---+---+
  9727. * | D | E | F |
  9728. * +---+---+---+
  9729. *
  9730. * then for each monitor you would call it like this
  9731. *
  9732. * var w = 1920;
  9733. * var h = 1080;
  9734. * var fullWidth = w * 3;
  9735. * var fullHeight = h * 2;
  9736. *
  9737. * --A--
  9738. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  9739. * --B--
  9740. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  9741. * --C--
  9742. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  9743. * --D--
  9744. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  9745. * --E--
  9746. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  9747. * --F--
  9748. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  9749. *
  9750. * Note there is no reason monitors have to be the same size or in a grid.
  9751. */
  9752. THREE.PerspectiveCamera.prototype.setViewOffset = function ( fullWidth, fullHeight, x, y, width, height ) {
  9753. this.fullWidth = fullWidth;
  9754. this.fullHeight = fullHeight;
  9755. this.x = x;
  9756. this.y = y;
  9757. this.width = width;
  9758. this.height = height;
  9759. this.updateProjectionMatrix();
  9760. };
  9761. THREE.PerspectiveCamera.prototype.updateProjectionMatrix = function () {
  9762. var fov = THREE.Math.radToDeg( 2 * Math.atan( Math.tan( THREE.Math.degToRad( this.fov ) * 0.5 ) / this.zoom ) );
  9763. if ( this.fullWidth ) {
  9764. var aspect = this.fullWidth / this.fullHeight;
  9765. var top = Math.tan( THREE.Math.degToRad( fov * 0.5 ) ) * this.near;
  9766. var bottom = - top;
  9767. var left = aspect * bottom;
  9768. var right = aspect * top;
  9769. var width = Math.abs( right - left );
  9770. var height = Math.abs( top - bottom );
  9771. this.projectionMatrix.makeFrustum(
  9772. left + this.x * width / this.fullWidth,
  9773. left + ( this.x + this.width ) * width / this.fullWidth,
  9774. top - ( this.y + this.height ) * height / this.fullHeight,
  9775. top - this.y * height / this.fullHeight,
  9776. this.near,
  9777. this.far
  9778. );
  9779. } else {
  9780. this.projectionMatrix.makePerspective( fov, this.aspect, this.near, this.far );
  9781. }
  9782. };
  9783. THREE.PerspectiveCamera.prototype.copy = function ( source ) {
  9784. THREE.Camera.prototype.copy.call( this, source );
  9785. this.fov = source.fov;
  9786. this.aspect = source.aspect;
  9787. this.near = source.near;
  9788. this.far = source.far;
  9789. this.zoom = source.zoom;
  9790. return this;
  9791. };
  9792. THREE.PerspectiveCamera.prototype.toJSON = function ( meta ) {
  9793. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  9794. data.object.zoom = this.zoom;
  9795. data.object.fov = this.fov;
  9796. data.object.aspect = this.aspect;
  9797. data.object.near = this.near;
  9798. data.object.far = this.far;
  9799. return data;
  9800. };
  9801. // File:src/lights/Light.js
  9802. /**
  9803. * @author mrdoob / http://mrdoob.com/
  9804. * @author alteredq / http://alteredqualia.com/
  9805. */
  9806. THREE.Light = function ( color ) {
  9807. THREE.Object3D.call( this );
  9808. this.type = 'Light';
  9809. this.color = new THREE.Color( color );
  9810. this.receiveShadow = undefined;
  9811. };
  9812. THREE.Light.prototype = Object.create( THREE.Object3D.prototype );
  9813. THREE.Light.prototype.constructor = THREE.Light;
  9814. THREE.Light.prototype.copy = function ( source ) {
  9815. THREE.Object3D.prototype.copy.call( this, source );
  9816. this.color.copy( source.color );
  9817. return this;
  9818. };
  9819. THREE.Light.prototype.toJSON = function ( meta ) {
  9820. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  9821. data.object.color = this.color.getHex();
  9822. if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();
  9823. if ( this.intensity !== undefined ) data.object.intensity = this.intensity;
  9824. if ( this.distance !== undefined ) data.object.distance = this.distance;
  9825. if ( this.angle !== undefined ) data.object.angle = this.angle;
  9826. if ( this.decay !== undefined ) data.object.decay = this.decay;
  9827. if ( this.exponent !== undefined ) data.object.exponent = this.exponent;
  9828. return data;
  9829. };
  9830. // File:src/lights/LightShadow.js
  9831. /**
  9832. * @author mrdoob / http://mrdoob.com/
  9833. */
  9834. THREE.LightShadow = function ( camera ) {
  9835. this.camera = camera;
  9836. this.bias = 0;
  9837. this.darkness = 1;
  9838. this.mapSize = new THREE.Vector2( 512, 512 );
  9839. this.map = null;
  9840. this.matrix = null;
  9841. };
  9842. THREE.LightShadow.prototype = {
  9843. constructor: THREE.LightShadow,
  9844. copy: function ( source ) {
  9845. this.camera = source.camera.clone();
  9846. this.bias = source.bias;
  9847. this.darkness = source.darkness;
  9848. this.mapSize.copy( source.mapSize );
  9849. return this;
  9850. },
  9851. clone: function () {
  9852. return new this.constructor().copy( this );
  9853. }
  9854. };
  9855. // File:src/lights/AmbientLight.js
  9856. /**
  9857. * @author mrdoob / http://mrdoob.com/
  9858. */
  9859. THREE.AmbientLight = function ( color ) {
  9860. THREE.Light.call( this, color );
  9861. this.type = 'AmbientLight';
  9862. this.castShadow = undefined;
  9863. };
  9864. THREE.AmbientLight.prototype = Object.create( THREE.Light.prototype );
  9865. THREE.AmbientLight.prototype.constructor = THREE.AmbientLight;
  9866. // File:src/lights/DirectionalLight.js
  9867. /**
  9868. * @author mrdoob / http://mrdoob.com/
  9869. * @author alteredq / http://alteredqualia.com/
  9870. */
  9871. THREE.DirectionalLight = function ( color, intensity ) {
  9872. THREE.Light.call( this, color );
  9873. this.type = 'DirectionalLight';
  9874. this.position.set( 0, 1, 0 );
  9875. this.updateMatrix();
  9876. this.target = new THREE.Object3D();
  9877. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  9878. this.shadow = new THREE.LightShadow( new THREE.OrthographicCamera( - 500, 500, 500, - 500, 50, 5000 ) );
  9879. };
  9880. THREE.DirectionalLight.prototype = Object.create( THREE.Light.prototype );
  9881. THREE.DirectionalLight.prototype.constructor = THREE.DirectionalLight;
  9882. THREE.DirectionalLight.prototype.copy = function ( source ) {
  9883. THREE.Light.prototype.copy.call( this, source );
  9884. this.intensity = source.intensity;
  9885. this.target = source.target.clone();
  9886. this.shadow = source.shadow.clone();
  9887. return this;
  9888. };
  9889. // File:src/lights/HemisphereLight.js
  9890. /**
  9891. * @author alteredq / http://alteredqualia.com/
  9892. */
  9893. THREE.HemisphereLight = function ( skyColor, groundColor, intensity ) {
  9894. THREE.Light.call( this, skyColor );
  9895. this.type = 'HemisphereLight';
  9896. this.castShadow = undefined;
  9897. this.position.set( 0, 1, 0 );
  9898. this.updateMatrix();
  9899. this.groundColor = new THREE.Color( groundColor );
  9900. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  9901. };
  9902. THREE.HemisphereLight.prototype = Object.create( THREE.Light.prototype );
  9903. THREE.HemisphereLight.prototype.constructor = THREE.HemisphereLight;
  9904. THREE.HemisphereLight.prototype.copy = function ( source ) {
  9905. THREE.Light.prototype.copy.call( this, source );
  9906. this.groundColor.copy( source.groundColor );
  9907. this.intensity = source.intensity;
  9908. return this;
  9909. };
  9910. // File:src/lights/PointLight.js
  9911. /**
  9912. * @author mrdoob / http://mrdoob.com/
  9913. */
  9914. THREE.PointLight = function ( color, intensity, distance, decay ) {
  9915. THREE.Light.call( this, color );
  9916. this.type = 'PointLight';
  9917. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  9918. this.distance = ( distance !== undefined ) ? distance : 0;
  9919. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  9920. this.shadow = new THREE.LightShadow( new THREE.PerspectiveCamera( 90, 1, 1, 500 ) );
  9921. };
  9922. THREE.PointLight.prototype = Object.create( THREE.Light.prototype );
  9923. THREE.PointLight.prototype.constructor = THREE.PointLight;
  9924. THREE.PointLight.prototype.copy = function ( source ) {
  9925. THREE.Light.prototype.copy.call( this, source );
  9926. this.intensity = source.intensity;
  9927. this.distance = source.distance;
  9928. this.decay = source.decay;
  9929. this.shadow = source.shadow.clone();
  9930. return this;
  9931. };
  9932. // File:src/lights/SpotLight.js
  9933. /**
  9934. * @author alteredq / http://alteredqualia.com/
  9935. */
  9936. THREE.SpotLight = function ( color, intensity, distance, angle, exponent, decay ) {
  9937. THREE.Light.call( this, color );
  9938. this.type = 'SpotLight';
  9939. this.position.set( 0, 1, 0 );
  9940. this.updateMatrix();
  9941. this.target = new THREE.Object3D();
  9942. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  9943. this.distance = ( distance !== undefined ) ? distance : 0;
  9944. this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
  9945. this.exponent = ( exponent !== undefined ) ? exponent : 10;
  9946. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  9947. this.shadow = new THREE.LightShadow( new THREE.PerspectiveCamera( 50, 1, 50, 5000 ) );
  9948. };
  9949. THREE.SpotLight.prototype = Object.create( THREE.Light.prototype );
  9950. THREE.SpotLight.prototype.constructor = THREE.SpotLight;
  9951. THREE.SpotLight.prototype.copy = function ( source ) {
  9952. THREE.Light.prototype.copy.call( this, source );
  9953. this.intensity = source.intensity;
  9954. this.distance = source.distance;
  9955. this.angle = source.angle;
  9956. this.exponent = source.exponent;
  9957. this.decay = source.decay;
  9958. this.target = source.target.clone();
  9959. this.shadow = source.shadow.clone();
  9960. return this;
  9961. };
  9962. // File:src/loaders/Cache.js
  9963. /**
  9964. * @author mrdoob / http://mrdoob.com/
  9965. */
  9966. THREE.Cache = {
  9967. enabled: false,
  9968. files: {},
  9969. add: function ( key, file ) {
  9970. if ( this.enabled === false ) return;
  9971. // console.log( 'THREE.Cache', 'Adding key:', key );
  9972. this.files[ key ] = file;
  9973. },
  9974. get: function ( key ) {
  9975. if ( this.enabled === false ) return;
  9976. // console.log( 'THREE.Cache', 'Checking key:', key );
  9977. return this.files[ key ];
  9978. },
  9979. remove: function ( key ) {
  9980. delete this.files[ key ];
  9981. },
  9982. clear: function () {
  9983. this.files = {};
  9984. }
  9985. };
  9986. // File:src/loaders/Loader.js
  9987. /**
  9988. * @author alteredq / http://alteredqualia.com/
  9989. */
  9990. THREE.Loader = function () {
  9991. this.onLoadStart = function () {};
  9992. this.onLoadProgress = function () {};
  9993. this.onLoadComplete = function () {};
  9994. };
  9995. THREE.Loader.prototype = {
  9996. constructor: THREE.Loader,
  9997. crossOrigin: undefined,
  9998. extractUrlBase: function ( url ) {
  9999. var parts = url.split( '/' );
  10000. if ( parts.length === 1 ) return './';
  10001. parts.pop();
  10002. return parts.join( '/' ) + '/';
  10003. },
  10004. initMaterials: function ( materials, texturePath, crossOrigin ) {
  10005. var array = [];
  10006. for ( var i = 0; i < materials.length; ++ i ) {
  10007. array[ i ] = this.createMaterial( materials[ i ], texturePath, crossOrigin );
  10008. }
  10009. return array;
  10010. },
  10011. createMaterial: ( function () {
  10012. var color, textureLoader, materialLoader;
  10013. return function ( m, texturePath, crossOrigin ) {
  10014. if ( color === undefined ) color = new THREE.Color();
  10015. if ( textureLoader === undefined ) textureLoader = new THREE.TextureLoader();
  10016. if ( materialLoader === undefined ) materialLoader = new THREE.MaterialLoader();
  10017. // convert from old material format
  10018. var textures = {};
  10019. function loadTexture( path, repeat, offset, wrap, anisotropy ) {
  10020. var fullPath = texturePath + path;
  10021. var loader = THREE.Loader.Handlers.get( fullPath );
  10022. var texture;
  10023. if ( loader !== null ) {
  10024. texture = loader.load( fullPath );
  10025. } else {
  10026. textureLoader.setCrossOrigin( crossOrigin );
  10027. texture = textureLoader.load( fullPath );
  10028. }
  10029. if ( repeat !== undefined ) {
  10030. texture.repeat.fromArray( repeat );
  10031. if ( repeat[ 0 ] !== 1 ) texture.wrapS = THREE.RepeatWrapping;
  10032. if ( repeat[ 1 ] !== 1 ) texture.wrapT = THREE.RepeatWrapping;
  10033. }
  10034. if ( offset !== undefined ) {
  10035. texture.offset.fromArray( offset );
  10036. }
  10037. if ( wrap !== undefined ) {
  10038. if ( wrap[ 0 ] === 'repeat' ) texture.wrapS = THREE.RepeatWrapping;
  10039. if ( wrap[ 0 ] === 'mirror' ) texture.wrapS = THREE.MirroredRepeatWrapping;
  10040. if ( wrap[ 1 ] === 'repeat' ) texture.wrapT = THREE.RepeatWrapping;
  10041. if ( wrap[ 1 ] === 'mirror' ) texture.wrapT = THREE.MirroredRepeatWrapping;
  10042. }
  10043. if ( anisotropy !== undefined ) {
  10044. texture.anisotropy = anisotropy;
  10045. }
  10046. var uuid = THREE.Math.generateUUID();
  10047. textures[ uuid ] = texture;
  10048. return uuid;
  10049. }
  10050. //
  10051. var json = {
  10052. uuid: THREE.Math.generateUUID(),
  10053. type: 'MeshLambertMaterial'
  10054. };
  10055. for ( var name in m ) {
  10056. var value = m[ name ];
  10057. switch ( name ) {
  10058. case 'DbgColor':
  10059. case 'DbgIndex':
  10060. case 'opticalDensity':
  10061. case 'illumination':
  10062. break;
  10063. case 'DbgName':
  10064. json.name = value;
  10065. break;
  10066. case 'blending':
  10067. json.blending = THREE[ value ];
  10068. break;
  10069. case 'colorAmbient':
  10070. console.warn( 'THREE.Loader.createMaterial: colorAmbient is no longer supported' );
  10071. break;
  10072. case 'colorDiffuse':
  10073. json.color = color.fromArray( value ).getHex();
  10074. break;
  10075. case 'colorSpecular':
  10076. json.specular = color.fromArray( value ).getHex();
  10077. break;
  10078. case 'colorEmissive':
  10079. json.emissive = color.fromArray( value ).getHex();
  10080. break;
  10081. case 'specularCoef':
  10082. json.shininess = value;
  10083. break;
  10084. case 'shading':
  10085. if ( value.toLowerCase() === 'basic' ) json.type = 'MeshBasicMaterial';
  10086. if ( value.toLowerCase() === 'phong' ) json.type = 'MeshPhongMaterial';
  10087. break;
  10088. case 'mapDiffuse':
  10089. json.map = loadTexture( value, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap, m.mapDiffuseAnisotropy );
  10090. break;
  10091. case 'mapDiffuseRepeat':
  10092. case 'mapDiffuseOffset':
  10093. case 'mapDiffuseWrap':
  10094. case 'mapDiffuseAnisotropy':
  10095. break;
  10096. case 'mapLight':
  10097. json.lightMap = loadTexture( value, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap, m.mapLightAnisotropy );
  10098. break;
  10099. case 'mapLightRepeat':
  10100. case 'mapLightOffset':
  10101. case 'mapLightWrap':
  10102. case 'mapLightAnisotropy':
  10103. break;
  10104. case 'mapAO':
  10105. json.aoMap = loadTexture( value, m.mapAORepeat, m.mapAOOffset, m.mapAOWrap, m.mapAOAnisotropy );
  10106. break;
  10107. case 'mapAORepeat':
  10108. case 'mapAOOffset':
  10109. case 'mapAOWrap':
  10110. case 'mapAOAnisotropy':
  10111. break;
  10112. case 'mapBump':
  10113. json.bumpMap = loadTexture( value, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap, m.mapBumpAnisotropy );
  10114. break;
  10115. case 'mapBumpScale':
  10116. json.bumpScale = value;
  10117. break;
  10118. case 'mapBumpRepeat':
  10119. case 'mapBumpOffset':
  10120. case 'mapBumpWrap':
  10121. case 'mapBumpAnisotropy':
  10122. break;
  10123. case 'mapNormal':
  10124. json.normalMap = loadTexture( value, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap, m.mapNormalAnisotropy );
  10125. break;
  10126. case 'mapNormalFactor':
  10127. json.normalScale = [ value, value ];
  10128. break;
  10129. case 'mapNormalRepeat':
  10130. case 'mapNormalOffset':
  10131. case 'mapNormalWrap':
  10132. case 'mapNormalAnisotropy':
  10133. break;
  10134. case 'mapSpecular':
  10135. json.specularMap = loadTexture( value, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap, m.mapSpecularAnisotropy );
  10136. break;
  10137. case 'mapSpecularRepeat':
  10138. case 'mapSpecularOffset':
  10139. case 'mapSpecularWrap':
  10140. case 'mapSpecularAnisotropy':
  10141. break;
  10142. case 'mapAlpha':
  10143. json.alphaMap = loadTexture( value, m.mapAlphaRepeat, m.mapAlphaOffset, m.mapAlphaWrap, m.mapAlphaAnisotropy );
  10144. break;
  10145. case 'mapAlphaRepeat':
  10146. case 'mapAlphaOffset':
  10147. case 'mapAlphaWrap':
  10148. case 'mapAlphaAnisotropy':
  10149. break;
  10150. case 'flipSided':
  10151. json.side = THREE.BackSide;
  10152. break;
  10153. case 'doubleSided':
  10154. json.side = THREE.DoubleSide;
  10155. break;
  10156. case 'transparency':
  10157. console.warn( 'THREE.Loader.createMaterial: transparency has been renamed to opacity' );
  10158. json.opacity = value;
  10159. break;
  10160. case 'opacity':
  10161. case 'transparent':
  10162. case 'depthTest':
  10163. case 'depthWrite':
  10164. case 'transparent':
  10165. case 'visible':
  10166. case 'wireframe':
  10167. json[ name ] = value;
  10168. break;
  10169. case 'vertexColors':
  10170. if ( value === true ) json.vertexColors = THREE.VertexColors;
  10171. if ( value === 'face' ) json.vertexColors = THREE.FaceColors;
  10172. break;
  10173. default:
  10174. console.error( 'THREE.Loader.createMaterial: Unsupported', name, value );
  10175. break;
  10176. }
  10177. }
  10178. if ( json.type !== 'MeshPhongMaterial' ) delete json.specular;
  10179. if ( json.opacity < 1 ) json.transparent = true;
  10180. materialLoader.setTextures( textures );
  10181. return materialLoader.parse( json );
  10182. };
  10183. } )()
  10184. };
  10185. THREE.Loader.Handlers = {
  10186. handlers: [],
  10187. add: function ( regex, loader ) {
  10188. this.handlers.push( regex, loader );
  10189. },
  10190. get: function ( file ) {
  10191. var handlers = this.handlers;
  10192. for ( var i = 0, l = handlers.length; i < l; i += 2 ) {
  10193. var regex = handlers[ i ];
  10194. var loader = handlers[ i + 1 ];
  10195. if ( regex.test( file ) ) {
  10196. return loader;
  10197. }
  10198. }
  10199. return null;
  10200. }
  10201. };
  10202. // File:src/loaders/XHRLoader.js
  10203. /**
  10204. * @author mrdoob / http://mrdoob.com/
  10205. */
  10206. THREE.XHRLoader = function ( manager ) {
  10207. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10208. };
  10209. THREE.XHRLoader.prototype = {
  10210. constructor: THREE.XHRLoader,
  10211. load: function ( url, onLoad, onProgress, onError ) {
  10212. if ( this.path !== undefined ) url = this.path + url;
  10213. var scope = this;
  10214. var cached = THREE.Cache.get( url );
  10215. if ( cached !== undefined ) {
  10216. if ( onLoad ) {
  10217. setTimeout( function () {
  10218. onLoad( cached );
  10219. }, 0 );
  10220. }
  10221. return cached;
  10222. }
  10223. var request = new XMLHttpRequest();
  10224. request.open( 'GET', url, true );
  10225. request.addEventListener( 'load', function ( event ) {
  10226. var response = event.target.response;
  10227. THREE.Cache.add( url, response );
  10228. if ( this.status == 200 && this.readyState == 4 ) {
  10229. if ( onLoad ) onLoad( response );
  10230. } else {
  10231. if ( onError ) onError( event );
  10232. }
  10233. scope.manager.itemEnd( url );
  10234. }, false );
  10235. if ( onProgress !== undefined ) {
  10236. request.addEventListener( 'progress', function ( event ) {
  10237. onProgress( event );
  10238. }, false );
  10239. }
  10240. request.addEventListener( 'error', function ( event ) {
  10241. if ( onError ) onError( event );
  10242. scope.manager.itemError( url );
  10243. }, false );
  10244. if ( this.crossOrigin !== undefined ) request.crossOrigin = this.crossOrigin;
  10245. if ( this.responseType !== undefined ) request.responseType = this.responseType;
  10246. if ( this.withCredentials !== undefined ) request.withCredentials = this.withCredentials;
  10247. request.send( null );
  10248. scope.manager.itemStart( url );
  10249. return request;
  10250. },
  10251. setCrossOrigin: function ( value ) {
  10252. this.crossOrigin = value;
  10253. },
  10254. setResponseType: function ( value ) {
  10255. this.responseType = value;
  10256. },
  10257. setPath: function ( value ) {
  10258. this.path = value;
  10259. },
  10260. setWithCredentials: function ( value ) {
  10261. this.withCredentials = value;
  10262. }
  10263. };
  10264. // File:src/loaders/ImageLoader.js
  10265. /**
  10266. * @author mrdoob / http://mrdoob.com/
  10267. */
  10268. THREE.ImageLoader = function ( manager ) {
  10269. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10270. };
  10271. THREE.ImageLoader.prototype = {
  10272. constructor: THREE.ImageLoader,
  10273. load: function ( url, onLoad, onProgress, onError ) {
  10274. if ( this.path !== undefined ) url = this.path + url;
  10275. var scope = this;
  10276. var cached = THREE.Cache.get( url );
  10277. if ( cached !== undefined ) {
  10278. scope.manager.itemStart( url );
  10279. if ( onLoad ) {
  10280. setTimeout( function () {
  10281. onLoad( cached );
  10282. scope.manager.itemEnd( url );
  10283. }, 0 );
  10284. } else {
  10285. scope.manager.itemEnd( url );
  10286. }
  10287. return cached;
  10288. }
  10289. var image = document.createElement( 'img' );
  10290. image.addEventListener( 'load', function ( event ) {
  10291. THREE.Cache.add( url, this );
  10292. if ( onLoad ) onLoad( this );
  10293. scope.manager.itemEnd( url );
  10294. }, false );
  10295. if ( onProgress !== undefined ) {
  10296. image.addEventListener( 'progress', function ( event ) {
  10297. onProgress( event );
  10298. }, false );
  10299. }
  10300. image.addEventListener( 'error', function ( event ) {
  10301. if ( onError ) onError( event );
  10302. scope.manager.itemError( url );
  10303. }, false );
  10304. if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
  10305. scope.manager.itemStart( url );
  10306. image.src = url;
  10307. return image;
  10308. },
  10309. setCrossOrigin: function ( value ) {
  10310. this.crossOrigin = value;
  10311. },
  10312. setPath: function ( value ) {
  10313. this.path = value;
  10314. }
  10315. };
  10316. // File:src/loaders/JSONLoader.js
  10317. /**
  10318. * @author mrdoob / http://mrdoob.com/
  10319. * @author alteredq / http://alteredqualia.com/
  10320. */
  10321. THREE.JSONLoader = function ( manager ) {
  10322. if ( typeof manager === 'boolean' ) {
  10323. console.warn( 'THREE.JSONLoader: showStatus parameter has been removed from constructor.' );
  10324. manager = undefined;
  10325. }
  10326. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10327. this.withCredentials = false;
  10328. };
  10329. THREE.JSONLoader.prototype = {
  10330. constructor: THREE.JSONLoader,
  10331. // Deprecated
  10332. get statusDomElement () {
  10333. if ( this._statusDomElement === undefined ) {
  10334. this._statusDomElement = document.createElement( 'div' );
  10335. }
  10336. console.warn( 'THREE.JSONLoader: .statusDomElement has been removed.' );
  10337. return this._statusDomElement;
  10338. },
  10339. load: function( url, onLoad, onProgress, onError ) {
  10340. var scope = this;
  10341. var texturePath = this.texturePath && ( typeof this.texturePath === "string" ) ? this.texturePath : THREE.Loader.prototype.extractUrlBase( url );
  10342. var loader = new THREE.XHRLoader( this.manager );
  10343. loader.setCrossOrigin( this.crossOrigin );
  10344. loader.setWithCredentials( this.withCredentials );
  10345. loader.load( url, function ( text ) {
  10346. var json = JSON.parse( text );
  10347. var metadata = json.metadata;
  10348. if ( metadata !== undefined ) {
  10349. var type = metadata.type;
  10350. if ( type !== undefined ) {
  10351. if ( type.toLowerCase() === 'object' ) {
  10352. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.ObjectLoader instead.' );
  10353. return;
  10354. }
  10355. if ( type.toLowerCase() === 'scene' ) {
  10356. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.SceneLoader instead.' );
  10357. return;
  10358. }
  10359. }
  10360. }
  10361. var object = scope.parse( json, texturePath );
  10362. onLoad( object.geometry, object.materials );
  10363. } );
  10364. },
  10365. setCrossOrigin: function ( value ) {
  10366. this.crossOrigin = value;
  10367. },
  10368. setTexturePath: function ( value ) {
  10369. this.texturePath = value;
  10370. },
  10371. parse: function ( json, texturePath ) {
  10372. var geometry = new THREE.Geometry(),
  10373. scale = ( json.scale !== undefined ) ? 1.0 / json.scale : 1.0;
  10374. parseModel( scale );
  10375. parseSkin();
  10376. parseMorphing( scale );
  10377. parseAnimations();
  10378. geometry.computeFaceNormals();
  10379. geometry.computeBoundingSphere();
  10380. function parseModel( scale ) {
  10381. function isBitSet( value, position ) {
  10382. return value & ( 1 << position );
  10383. }
  10384. var i, j, fi,
  10385. offset, zLength,
  10386. colorIndex, normalIndex, uvIndex, materialIndex,
  10387. type,
  10388. isQuad,
  10389. hasMaterial,
  10390. hasFaceVertexUv,
  10391. hasFaceNormal, hasFaceVertexNormal,
  10392. hasFaceColor, hasFaceVertexColor,
  10393. vertex, face, faceA, faceB, hex, normal,
  10394. uvLayer, uv, u, v,
  10395. faces = json.faces,
  10396. vertices = json.vertices,
  10397. normals = json.normals,
  10398. colors = json.colors,
  10399. nUvLayers = 0;
  10400. if ( json.uvs !== undefined ) {
  10401. // disregard empty arrays
  10402. for ( i = 0; i < json.uvs.length; i ++ ) {
  10403. if ( json.uvs[ i ].length ) nUvLayers ++;
  10404. }
  10405. for ( i = 0; i < nUvLayers; i ++ ) {
  10406. geometry.faceVertexUvs[ i ] = [];
  10407. }
  10408. }
  10409. offset = 0;
  10410. zLength = vertices.length;
  10411. while ( offset < zLength ) {
  10412. vertex = new THREE.Vector3();
  10413. vertex.x = vertices[ offset ++ ] * scale;
  10414. vertex.y = vertices[ offset ++ ] * scale;
  10415. vertex.z = vertices[ offset ++ ] * scale;
  10416. geometry.vertices.push( vertex );
  10417. }
  10418. offset = 0;
  10419. zLength = faces.length;
  10420. while ( offset < zLength ) {
  10421. type = faces[ offset ++ ];
  10422. isQuad = isBitSet( type, 0 );
  10423. hasMaterial = isBitSet( type, 1 );
  10424. hasFaceVertexUv = isBitSet( type, 3 );
  10425. hasFaceNormal = isBitSet( type, 4 );
  10426. hasFaceVertexNormal = isBitSet( type, 5 );
  10427. hasFaceColor = isBitSet( type, 6 );
  10428. hasFaceVertexColor = isBitSet( type, 7 );
  10429. // console.log("type", type, "bits", isQuad, hasMaterial, hasFaceVertexUv, hasFaceNormal, hasFaceVertexNormal, hasFaceColor, hasFaceVertexColor);
  10430. if ( isQuad ) {
  10431. faceA = new THREE.Face3();
  10432. faceA.a = faces[ offset ];
  10433. faceA.b = faces[ offset + 1 ];
  10434. faceA.c = faces[ offset + 3 ];
  10435. faceB = new THREE.Face3();
  10436. faceB.a = faces[ offset + 1 ];
  10437. faceB.b = faces[ offset + 2 ];
  10438. faceB.c = faces[ offset + 3 ];
  10439. offset += 4;
  10440. if ( hasMaterial ) {
  10441. materialIndex = faces[ offset ++ ];
  10442. faceA.materialIndex = materialIndex;
  10443. faceB.materialIndex = materialIndex;
  10444. }
  10445. // to get face <=> uv index correspondence
  10446. fi = geometry.faces.length;
  10447. if ( hasFaceVertexUv ) {
  10448. for ( i = 0; i < nUvLayers; i ++ ) {
  10449. uvLayer = json.uvs[ i ];
  10450. geometry.faceVertexUvs[ i ][ fi ] = [];
  10451. geometry.faceVertexUvs[ i ][ fi + 1 ] = [];
  10452. for ( j = 0; j < 4; j ++ ) {
  10453. uvIndex = faces[ offset ++ ];
  10454. u = uvLayer[ uvIndex * 2 ];
  10455. v = uvLayer[ uvIndex * 2 + 1 ];
  10456. uv = new THREE.Vector2( u, v );
  10457. if ( j !== 2 ) geometry.faceVertexUvs[ i ][ fi ].push( uv );
  10458. if ( j !== 0 ) geometry.faceVertexUvs[ i ][ fi + 1 ].push( uv );
  10459. }
  10460. }
  10461. }
  10462. if ( hasFaceNormal ) {
  10463. normalIndex = faces[ offset ++ ] * 3;
  10464. faceA.normal.set(
  10465. normals[ normalIndex ++ ],
  10466. normals[ normalIndex ++ ],
  10467. normals[ normalIndex ]
  10468. );
  10469. faceB.normal.copy( faceA.normal );
  10470. }
  10471. if ( hasFaceVertexNormal ) {
  10472. for ( i = 0; i < 4; i ++ ) {
  10473. normalIndex = faces[ offset ++ ] * 3;
  10474. normal = new THREE.Vector3(
  10475. normals[ normalIndex ++ ],
  10476. normals[ normalIndex ++ ],
  10477. normals[ normalIndex ]
  10478. );
  10479. if ( i !== 2 ) faceA.vertexNormals.push( normal );
  10480. if ( i !== 0 ) faceB.vertexNormals.push( normal );
  10481. }
  10482. }
  10483. if ( hasFaceColor ) {
  10484. colorIndex = faces[ offset ++ ];
  10485. hex = colors[ colorIndex ];
  10486. faceA.color.setHex( hex );
  10487. faceB.color.setHex( hex );
  10488. }
  10489. if ( hasFaceVertexColor ) {
  10490. for ( i = 0; i < 4; i ++ ) {
  10491. colorIndex = faces[ offset ++ ];
  10492. hex = colors[ colorIndex ];
  10493. if ( i !== 2 ) faceA.vertexColors.push( new THREE.Color( hex ) );
  10494. if ( i !== 0 ) faceB.vertexColors.push( new THREE.Color( hex ) );
  10495. }
  10496. }
  10497. geometry.faces.push( faceA );
  10498. geometry.faces.push( faceB );
  10499. } else {
  10500. face = new THREE.Face3();
  10501. face.a = faces[ offset ++ ];
  10502. face.b = faces[ offset ++ ];
  10503. face.c = faces[ offset ++ ];
  10504. if ( hasMaterial ) {
  10505. materialIndex = faces[ offset ++ ];
  10506. face.materialIndex = materialIndex;
  10507. }
  10508. // to get face <=> uv index correspondence
  10509. fi = geometry.faces.length;
  10510. if ( hasFaceVertexUv ) {
  10511. for ( i = 0; i < nUvLayers; i ++ ) {
  10512. uvLayer = json.uvs[ i ];
  10513. geometry.faceVertexUvs[ i ][ fi ] = [];
  10514. for ( j = 0; j < 3; j ++ ) {
  10515. uvIndex = faces[ offset ++ ];
  10516. u = uvLayer[ uvIndex * 2 ];
  10517. v = uvLayer[ uvIndex * 2 + 1 ];
  10518. uv = new THREE.Vector2( u, v );
  10519. geometry.faceVertexUvs[ i ][ fi ].push( uv );
  10520. }
  10521. }
  10522. }
  10523. if ( hasFaceNormal ) {
  10524. normalIndex = faces[ offset ++ ] * 3;
  10525. face.normal.set(
  10526. normals[ normalIndex ++ ],
  10527. normals[ normalIndex ++ ],
  10528. normals[ normalIndex ]
  10529. );
  10530. }
  10531. if ( hasFaceVertexNormal ) {
  10532. for ( i = 0; i < 3; i ++ ) {
  10533. normalIndex = faces[ offset ++ ] * 3;
  10534. normal = new THREE.Vector3(
  10535. normals[ normalIndex ++ ],
  10536. normals[ normalIndex ++ ],
  10537. normals[ normalIndex ]
  10538. );
  10539. face.vertexNormals.push( normal );
  10540. }
  10541. }
  10542. if ( hasFaceColor ) {
  10543. colorIndex = faces[ offset ++ ];
  10544. face.color.setHex( colors[ colorIndex ] );
  10545. }
  10546. if ( hasFaceVertexColor ) {
  10547. for ( i = 0; i < 3; i ++ ) {
  10548. colorIndex = faces[ offset ++ ];
  10549. face.vertexColors.push( new THREE.Color( colors[ colorIndex ] ) );
  10550. }
  10551. }
  10552. geometry.faces.push( face );
  10553. }
  10554. }
  10555. };
  10556. function parseSkin() {
  10557. var influencesPerVertex = ( json.influencesPerVertex !== undefined ) ? json.influencesPerVertex : 2;
  10558. if ( json.skinWeights ) {
  10559. for ( var i = 0, l = json.skinWeights.length; i < l; i += influencesPerVertex ) {
  10560. var x = json.skinWeights[ i ];
  10561. var y = ( influencesPerVertex > 1 ) ? json.skinWeights[ i + 1 ] : 0;
  10562. var z = ( influencesPerVertex > 2 ) ? json.skinWeights[ i + 2 ] : 0;
  10563. var w = ( influencesPerVertex > 3 ) ? json.skinWeights[ i + 3 ] : 0;
  10564. geometry.skinWeights.push( new THREE.Vector4( x, y, z, w ) );
  10565. }
  10566. }
  10567. if ( json.skinIndices ) {
  10568. for ( var i = 0, l = json.skinIndices.length; i < l; i += influencesPerVertex ) {
  10569. var a = json.skinIndices[ i ];
  10570. var b = ( influencesPerVertex > 1 ) ? json.skinIndices[ i + 1 ] : 0;
  10571. var c = ( influencesPerVertex > 2 ) ? json.skinIndices[ i + 2 ] : 0;
  10572. var d = ( influencesPerVertex > 3 ) ? json.skinIndices[ i + 3 ] : 0;
  10573. geometry.skinIndices.push( new THREE.Vector4( a, b, c, d ) );
  10574. }
  10575. }
  10576. geometry.bones = json.bones;
  10577. if ( geometry.bones && geometry.bones.length > 0 && ( geometry.skinWeights.length !== geometry.skinIndices.length || geometry.skinIndices.length !== geometry.vertices.length ) ) {
  10578. console.warn( 'When skinning, number of vertices (' + geometry.vertices.length + '), skinIndices (' +
  10579. geometry.skinIndices.length + '), and skinWeights (' + geometry.skinWeights.length + ') should match.' );
  10580. }
  10581. };
  10582. function parseMorphing( scale ) {
  10583. if ( json.morphTargets !== undefined ) {
  10584. for ( var i = 0, l = json.morphTargets.length; i < l; i ++ ) {
  10585. geometry.morphTargets[ i ] = {};
  10586. geometry.morphTargets[ i ].name = json.morphTargets[ i ].name;
  10587. geometry.morphTargets[ i ].vertices = [];
  10588. var dstVertices = geometry.morphTargets[ i ].vertices;
  10589. var srcVertices = json.morphTargets[ i ].vertices;
  10590. for ( var v = 0, vl = srcVertices.length; v < vl; v += 3 ) {
  10591. var vertex = new THREE.Vector3();
  10592. vertex.x = srcVertices[ v ] * scale;
  10593. vertex.y = srcVertices[ v + 1 ] * scale;
  10594. vertex.z = srcVertices[ v + 2 ] * scale;
  10595. dstVertices.push( vertex );
  10596. }
  10597. }
  10598. }
  10599. if ( json.morphColors !== undefined && json.morphColors.length > 0 ) {
  10600. console.warn( 'THREE.JSONLoader: "morphColors" no longer supported. Using them as face colors.' );
  10601. var faces = geometry.faces;
  10602. var morphColors = json.morphColors[ 0 ].colors;
  10603. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  10604. faces[ i ].color.fromArray( morphColors, i * 3 );
  10605. }
  10606. }
  10607. }
  10608. function parseAnimations() {
  10609. var outputAnimations = [];
  10610. // parse old style Bone/Hierarchy animations
  10611. var animations = [];
  10612. if ( json.animation !== undefined ) {
  10613. animations.push( json.animation );
  10614. }
  10615. if ( json.animations !== undefined ) {
  10616. if ( json.animations.length ) {
  10617. animations = animations.concat( json.animations );
  10618. } else {
  10619. animations.push( json.animations );
  10620. }
  10621. }
  10622. for ( var i = 0; i < animations.length; i ++ ) {
  10623. var clip = THREE.AnimationClip.parseAnimation( animations[i], geometry.bones );
  10624. if ( clip ) outputAnimations.push( clip );
  10625. }
  10626. // parse implicit morph animations
  10627. if ( geometry.morphTargets ) {
  10628. // TODO: Figure out what an appropraite FPS is for morph target animations -- defaulting to 10, but really it is completely arbitrary.
  10629. var morphAnimationClips = THREE.AnimationClip.CreateClipsFromMorphTargetSequences( geometry.morphTargets, 10 );
  10630. outputAnimations = outputAnimations.concat( morphAnimationClips );
  10631. }
  10632. if ( outputAnimations.length > 0 ) geometry.animations = outputAnimations;
  10633. };
  10634. if ( json.materials === undefined || json.materials.length === 0 ) {
  10635. return { geometry: geometry };
  10636. } else {
  10637. var materials = THREE.Loader.prototype.initMaterials( json.materials, texturePath, this.crossOrigin );
  10638. return { geometry: geometry, materials: materials };
  10639. }
  10640. }
  10641. };
  10642. // File:src/loaders/LoadingManager.js
  10643. /**
  10644. * @author mrdoob / http://mrdoob.com/
  10645. */
  10646. THREE.LoadingManager = function ( onLoad, onProgress, onError ) {
  10647. var scope = this;
  10648. var isLoading = false, itemsLoaded = 0, itemsTotal = 0;
  10649. this.onStart = undefined;
  10650. this.onLoad = onLoad;
  10651. this.onProgress = onProgress;
  10652. this.onError = onError;
  10653. this.itemStart = function ( url ) {
  10654. itemsTotal ++;
  10655. if ( isLoading === false ) {
  10656. if ( scope.onStart !== undefined ) {
  10657. scope.onStart( url, itemsLoaded, itemsTotal );
  10658. }
  10659. }
  10660. isLoading = true;
  10661. };
  10662. this.itemEnd = function ( url ) {
  10663. itemsLoaded ++;
  10664. if ( scope.onProgress !== undefined ) {
  10665. scope.onProgress( url, itemsLoaded, itemsTotal );
  10666. }
  10667. if ( itemsLoaded === itemsTotal ) {
  10668. isLoading = false;
  10669. if ( scope.onLoad !== undefined ) {
  10670. scope.onLoad();
  10671. }
  10672. }
  10673. };
  10674. this.itemError = function ( url ) {
  10675. if ( scope.onError !== undefined ) {
  10676. scope.onError( url );
  10677. }
  10678. };
  10679. };
  10680. THREE.DefaultLoadingManager = new THREE.LoadingManager();
  10681. // File:src/loaders/BufferGeometryLoader.js
  10682. /**
  10683. * @author mrdoob / http://mrdoob.com/
  10684. */
  10685. THREE.BufferGeometryLoader = function ( manager ) {
  10686. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10687. };
  10688. THREE.BufferGeometryLoader.prototype = {
  10689. constructor: THREE.BufferGeometryLoader,
  10690. load: function ( url, onLoad, onProgress, onError ) {
  10691. var scope = this;
  10692. var loader = new THREE.XHRLoader( scope.manager );
  10693. loader.setCrossOrigin( this.crossOrigin );
  10694. loader.load( url, function ( text ) {
  10695. onLoad( scope.parse( JSON.parse( text ) ) );
  10696. }, onProgress, onError );
  10697. },
  10698. setCrossOrigin: function ( value ) {
  10699. this.crossOrigin = value;
  10700. },
  10701. parse: function ( json ) {
  10702. var geometry = new THREE.BufferGeometry();
  10703. var index = json.data.index;
  10704. if ( index !== undefined ) {
  10705. var typedArray = new self[ index.type ]( index.array );
  10706. geometry.setIndex( new THREE.BufferAttribute( typedArray, 1 ) );
  10707. }
  10708. var attributes = json.data.attributes;
  10709. for ( var key in attributes ) {
  10710. var attribute = attributes[ key ];
  10711. var typedArray = new self[ attribute.type ]( attribute.array );
  10712. geometry.addAttribute( key, new THREE.BufferAttribute( typedArray, attribute.itemSize ) );
  10713. }
  10714. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  10715. if ( groups !== undefined ) {
  10716. for ( var i = 0, n = groups.length; i !== n; ++ i ) {
  10717. var group = groups[ i ];
  10718. geometry.addGroup( group.start, group.count );
  10719. }
  10720. }
  10721. var boundingSphere = json.data.boundingSphere;
  10722. if ( boundingSphere !== undefined ) {
  10723. var center = new THREE.Vector3();
  10724. if ( boundingSphere.center !== undefined ) {
  10725. center.fromArray( boundingSphere.center );
  10726. }
  10727. geometry.boundingSphere = new THREE.Sphere( center, boundingSphere.radius );
  10728. }
  10729. return geometry;
  10730. }
  10731. };
  10732. // File:src/loaders/MaterialLoader.js
  10733. /**
  10734. * @author mrdoob / http://mrdoob.com/
  10735. */
  10736. THREE.MaterialLoader = function ( manager ) {
  10737. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10738. this.textures = {};
  10739. };
  10740. THREE.MaterialLoader.prototype = {
  10741. constructor: THREE.MaterialLoader,
  10742. load: function ( url, onLoad, onProgress, onError ) {
  10743. var scope = this;
  10744. var loader = new THREE.XHRLoader( scope.manager );
  10745. loader.setCrossOrigin( this.crossOrigin );
  10746. loader.load( url, function ( text ) {
  10747. onLoad( scope.parse( JSON.parse( text ) ) );
  10748. }, onProgress, onError );
  10749. },
  10750. setCrossOrigin: function ( value ) {
  10751. this.crossOrigin = value;
  10752. },
  10753. setTextures: function ( value ) {
  10754. this.textures = value;
  10755. },
  10756. getTexture: function ( name ) {
  10757. var textures = this.textures;
  10758. if ( textures[ name ] === undefined ) {
  10759. console.warn( 'THREE.MaterialLoader: Undefined texture', name );
  10760. }
  10761. return textures[ name ];
  10762. },
  10763. parse: function ( json ) {
  10764. var material = new THREE[ json.type ];
  10765. material.uuid = json.uuid;
  10766. if ( json.name !== undefined ) material.name = json.name;
  10767. if ( json.color !== undefined ) material.color.setHex( json.color );
  10768. if ( json.roughness !== undefined ) material.roughness = json.roughness;
  10769. if ( json.metalness !== undefined ) material.metalness = json.metalness;
  10770. if ( json.emissive !== undefined ) material.emissive.setHex( json.emissive );
  10771. if ( json.specular !== undefined ) material.specular.setHex( json.specular );
  10772. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  10773. if ( json.uniforms !== undefined ) material.uniforms = json.uniforms;
  10774. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  10775. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  10776. if ( json.vertexColors !== undefined ) material.vertexColors = json.vertexColors;
  10777. if ( json.shading !== undefined ) material.shading = json.shading;
  10778. if ( json.blending !== undefined ) material.blending = json.blending;
  10779. if ( json.side !== undefined ) material.side = json.side;
  10780. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  10781. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  10782. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  10783. if ( json.depthTest !== undefined ) material.depthTest = json.depthTest;
  10784. if ( json.depthWrite !== undefined ) material.depthWrite = json.depthWrite;
  10785. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  10786. if ( json.wireframeLinewidth !== undefined ) material.wireframeLinewidth = json.wireframeLinewidth;
  10787. // for PointsMaterial
  10788. if ( json.size !== undefined ) material.size = json.size;
  10789. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  10790. // maps
  10791. if ( json.map !== undefined ) material.map = this.getTexture( json.map );
  10792. if ( json.alphaMap !== undefined ) {
  10793. material.alphaMap = this.getTexture( json.alphaMap );
  10794. material.transparent = true;
  10795. }
  10796. if ( json.bumpMap !== undefined ) material.bumpMap = this.getTexture( json.bumpMap );
  10797. if ( json.bumpScale !== undefined ) material.bumpScale = json.bumpScale;
  10798. if ( json.normalMap !== undefined ) material.normalMap = this.getTexture( json.normalMap );
  10799. if ( json.normalScale !== undefined ) {
  10800. var normalScale = json.normalScale;
  10801. if ( Array.isArray( normalScale ) === false ) {
  10802. // Blender exporter used to export a scalar. See #7459
  10803. normalScale = [ normalScale, normalScale ];
  10804. }
  10805. material.normalScale = new THREE.Vector2().fromArray( normalScale );
  10806. }
  10807. if ( json.displacementMap !== undefined ) material.displacementMap = this.getTexture( json.displacementMap );
  10808. if ( json.displacementScale !== undefined ) material.displacementScale = json.displacementScale;
  10809. if ( json.displacementBias !== undefined ) material.displacementBias = json.displacementBias;
  10810. if ( json.roughnessMap !== undefined ) material.roughnessMap = this.getTexture( json.roughnessMap );
  10811. if ( json.metalnessMap !== undefined ) material.metalnessMap = this.getTexture( json.metalnessMap );
  10812. if ( json.specularMap !== undefined ) material.specularMap = this.getTexture( json.specularMap );
  10813. if ( json.envMap !== undefined ) {
  10814. material.envMap = this.getTexture( json.envMap );
  10815. material.combine = THREE.MultiplyOperation;
  10816. }
  10817. if ( json.reflectivity ) material.reflectivity = json.reflectivity;
  10818. if ( json.lightMap !== undefined ) material.lightMap = this.getTexture( json.lightMap );
  10819. if ( json.lightMapIntensity !== undefined ) material.lightMapIntensity = json.lightMapIntensity;
  10820. if ( json.aoMap !== undefined ) material.aoMap = this.getTexture( json.aoMap );
  10821. if ( json.aoMapIntensity !== undefined ) material.aoMapIntensity = json.aoMapIntensity;
  10822. // MeshFaceMaterial
  10823. if ( json.materials !== undefined ) {
  10824. for ( var i = 0, l = json.materials.length; i < l; i ++ ) {
  10825. material.materials.push( this.parse( json.materials[ i ] ) );
  10826. }
  10827. }
  10828. return material;
  10829. }
  10830. };
  10831. // File:src/loaders/ObjectLoader.js
  10832. /**
  10833. * @author mrdoob / http://mrdoob.com/
  10834. */
  10835. THREE.ObjectLoader = function ( manager ) {
  10836. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10837. this.texturePath = '';
  10838. };
  10839. THREE.ObjectLoader.prototype = {
  10840. constructor: THREE.ObjectLoader,
  10841. load: function ( url, onLoad, onProgress, onError ) {
  10842. if ( this.texturePath === '' ) {
  10843. this.texturePath = url.substring( 0, url.lastIndexOf( '/' ) + 1 );
  10844. }
  10845. var scope = this;
  10846. var loader = new THREE.XHRLoader( scope.manager );
  10847. loader.setCrossOrigin( this.crossOrigin );
  10848. loader.load( url, function ( text ) {
  10849. scope.parse( JSON.parse( text ), onLoad );
  10850. }, onProgress, onError );
  10851. },
  10852. setTexturePath: function ( value ) {
  10853. this.texturePath = value;
  10854. },
  10855. setCrossOrigin: function ( value ) {
  10856. this.crossOrigin = value;
  10857. },
  10858. parse: function ( json, onLoad ) {
  10859. var geometries = this.parseGeometries( json.geometries );
  10860. var images = this.parseImages( json.images, function () {
  10861. if ( onLoad !== undefined ) onLoad( object );
  10862. } );
  10863. var textures = this.parseTextures( json.textures, images );
  10864. var materials = this.parseMaterials( json.materials, textures );
  10865. var object = this.parseObject( json.object, geometries, materials );
  10866. if ( json.animations ) {
  10867. object.animations = this.parseAnimations( json.animations );
  10868. }
  10869. if ( json.images === undefined || json.images.length === 0 ) {
  10870. if ( onLoad !== undefined ) onLoad( object );
  10871. }
  10872. return object;
  10873. },
  10874. parseGeometries: function ( json ) {
  10875. var geometries = {};
  10876. if ( json !== undefined ) {
  10877. var geometryLoader = new THREE.JSONLoader();
  10878. var bufferGeometryLoader = new THREE.BufferGeometryLoader();
  10879. for ( var i = 0, l = json.length; i < l; i ++ ) {
  10880. var geometry;
  10881. var data = json[ i ];
  10882. switch ( data.type ) {
  10883. case 'PlaneGeometry':
  10884. case 'PlaneBufferGeometry':
  10885. geometry = new THREE[ data.type ](
  10886. data.width,
  10887. data.height,
  10888. data.widthSegments,
  10889. data.heightSegments
  10890. );
  10891. break;
  10892. case 'BoxGeometry':
  10893. case 'CubeGeometry': // backwards compatible
  10894. geometry = new THREE.BoxGeometry(
  10895. data.width,
  10896. data.height,
  10897. data.depth,
  10898. data.widthSegments,
  10899. data.heightSegments,
  10900. data.depthSegments
  10901. );
  10902. break;
  10903. case 'CircleBufferGeometry':
  10904. geometry = new THREE.CircleBufferGeometry(
  10905. data.radius,
  10906. data.segments,
  10907. data.thetaStart,
  10908. data.thetaLength
  10909. );
  10910. break;
  10911. case 'CircleGeometry':
  10912. geometry = new THREE.CircleGeometry(
  10913. data.radius,
  10914. data.segments,
  10915. data.thetaStart,
  10916. data.thetaLength
  10917. );
  10918. break;
  10919. case 'CylinderGeometry':
  10920. geometry = new THREE.CylinderGeometry(
  10921. data.radiusTop,
  10922. data.radiusBottom,
  10923. data.height,
  10924. data.radialSegments,
  10925. data.heightSegments,
  10926. data.openEnded,
  10927. data.thetaStart,
  10928. data.thetaLength
  10929. );
  10930. break;
  10931. case 'SphereGeometry':
  10932. geometry = new THREE.SphereGeometry(
  10933. data.radius,
  10934. data.widthSegments,
  10935. data.heightSegments,
  10936. data.phiStart,
  10937. data.phiLength,
  10938. data.thetaStart,
  10939. data.thetaLength
  10940. );
  10941. break;
  10942. case 'SphereBufferGeometry':
  10943. geometry = new THREE.SphereBufferGeometry(
  10944. data.radius,
  10945. data.widthSegments,
  10946. data.heightSegments,
  10947. data.phiStart,
  10948. data.phiLength,
  10949. data.thetaStart,
  10950. data.thetaLength
  10951. );
  10952. break;
  10953. case 'DodecahedronGeometry':
  10954. geometry = new THREE.DodecahedronGeometry(
  10955. data.radius,
  10956. data.detail
  10957. );
  10958. break;
  10959. case 'IcosahedronGeometry':
  10960. geometry = new THREE.IcosahedronGeometry(
  10961. data.radius,
  10962. data.detail
  10963. );
  10964. break;
  10965. case 'OctahedronGeometry':
  10966. geometry = new THREE.OctahedronGeometry(
  10967. data.radius,
  10968. data.detail
  10969. );
  10970. break;
  10971. case 'TetrahedronGeometry':
  10972. geometry = new THREE.TetrahedronGeometry(
  10973. data.radius,
  10974. data.detail
  10975. );
  10976. break;
  10977. case 'RingGeometry':
  10978. geometry = new THREE.RingGeometry(
  10979. data.innerRadius,
  10980. data.outerRadius,
  10981. data.thetaSegments,
  10982. data.phiSegments,
  10983. data.thetaStart,
  10984. data.thetaLength
  10985. );
  10986. break;
  10987. case 'TorusGeometry':
  10988. geometry = new THREE.TorusGeometry(
  10989. data.radius,
  10990. data.tube,
  10991. data.radialSegments,
  10992. data.tubularSegments,
  10993. data.arc
  10994. );
  10995. break;
  10996. case 'TorusKnotGeometry':
  10997. geometry = new THREE.TorusKnotGeometry(
  10998. data.radius,
  10999. data.tube,
  11000. data.radialSegments,
  11001. data.tubularSegments,
  11002. data.p,
  11003. data.q,
  11004. data.heightScale
  11005. );
  11006. break;
  11007. case 'BufferGeometry':
  11008. geometry = bufferGeometryLoader.parse( data );
  11009. break;
  11010. case 'Geometry':
  11011. geometry = geometryLoader.parse( data.data, this.texturePath ).geometry;
  11012. break;
  11013. default:
  11014. console.warn( 'THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"' );
  11015. continue;
  11016. }
  11017. geometry.uuid = data.uuid;
  11018. if ( data.name !== undefined ) geometry.name = data.name;
  11019. geometries[ data.uuid ] = geometry;
  11020. }
  11021. }
  11022. return geometries;
  11023. },
  11024. parseMaterials: function ( json, textures ) {
  11025. var materials = {};
  11026. if ( json !== undefined ) {
  11027. var loader = new THREE.MaterialLoader();
  11028. loader.setTextures( textures );
  11029. for ( var i = 0, l = json.length; i < l; i ++ ) {
  11030. var material = loader.parse( json[ i ] );
  11031. materials[ material.uuid ] = material;
  11032. }
  11033. }
  11034. return materials;
  11035. },
  11036. parseAnimations: function ( json ) {
  11037. var animations = [];
  11038. for ( var i = 0; i < json.length; i ++ ) {
  11039. var clip = THREE.AnimationClip.parse( json[i] );
  11040. animations.push( clip );
  11041. }
  11042. return animations;
  11043. },
  11044. parseImages: function ( json, onLoad ) {
  11045. var scope = this;
  11046. var images = {};
  11047. function loadImage( url ) {
  11048. scope.manager.itemStart( url );
  11049. return loader.load( url, function () {
  11050. scope.manager.itemEnd( url );
  11051. } );
  11052. }
  11053. if ( json !== undefined && json.length > 0 ) {
  11054. var manager = new THREE.LoadingManager( onLoad );
  11055. var loader = new THREE.ImageLoader( manager );
  11056. loader.setCrossOrigin( this.crossOrigin );
  11057. for ( var i = 0, l = json.length; i < l; i ++ ) {
  11058. var image = json[ i ];
  11059. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( image.url ) ? image.url : scope.texturePath + image.url;
  11060. images[ image.uuid ] = loadImage( path );
  11061. }
  11062. }
  11063. return images;
  11064. },
  11065. parseTextures: function ( json, images ) {
  11066. function parseConstant( value ) {
  11067. if ( typeof( value ) === 'number' ) return value;
  11068. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  11069. return THREE[ value ];
  11070. }
  11071. var textures = {};
  11072. if ( json !== undefined ) {
  11073. for ( var i = 0, l = json.length; i < l; i ++ ) {
  11074. var data = json[ i ];
  11075. if ( data.image === undefined ) {
  11076. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  11077. }
  11078. if ( images[ data.image ] === undefined ) {
  11079. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  11080. }
  11081. var texture = new THREE.Texture( images[ data.image ] );
  11082. texture.needsUpdate = true;
  11083. texture.uuid = data.uuid;
  11084. if ( data.name !== undefined ) texture.name = data.name;
  11085. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping );
  11086. if ( data.offset !== undefined ) texture.offset = new THREE.Vector2( data.offset[ 0 ], data.offset[ 1 ] );
  11087. if ( data.repeat !== undefined ) texture.repeat = new THREE.Vector2( data.repeat[ 0 ], data.repeat[ 1 ] );
  11088. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter );
  11089. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter );
  11090. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  11091. if ( Array.isArray( data.wrap ) ) {
  11092. texture.wrapS = parseConstant( data.wrap[ 0 ] );
  11093. texture.wrapT = parseConstant( data.wrap[ 1 ] );
  11094. }
  11095. textures[ data.uuid ] = texture;
  11096. }
  11097. }
  11098. return textures;
  11099. },
  11100. parseObject: function () {
  11101. var matrix = new THREE.Matrix4();
  11102. return function ( data, geometries, materials ) {
  11103. var object;
  11104. function getGeometry( name ) {
  11105. if ( geometries[ name ] === undefined ) {
  11106. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  11107. }
  11108. return geometries[ name ];
  11109. }
  11110. function getMaterial( name ) {
  11111. if ( name === undefined ) return undefined;
  11112. if ( materials[ name ] === undefined ) {
  11113. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  11114. }
  11115. return materials[ name ];
  11116. }
  11117. switch ( data.type ) {
  11118. case 'Scene':
  11119. object = new THREE.Scene();
  11120. break;
  11121. case 'PerspectiveCamera':
  11122. object = new THREE.PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  11123. break;
  11124. case 'OrthographicCamera':
  11125. object = new THREE.OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  11126. break;
  11127. case 'AmbientLight':
  11128. object = new THREE.AmbientLight( data.color );
  11129. break;
  11130. case 'DirectionalLight':
  11131. object = new THREE.DirectionalLight( data.color, data.intensity );
  11132. break;
  11133. case 'PointLight':
  11134. object = new THREE.PointLight( data.color, data.intensity, data.distance, data.decay );
  11135. break;
  11136. case 'SpotLight':
  11137. object = new THREE.SpotLight( data.color, data.intensity, data.distance, data.angle, data.exponent, data.decay );
  11138. break;
  11139. case 'HemisphereLight':
  11140. object = new THREE.HemisphereLight( data.color, data.groundColor, data.intensity );
  11141. break;
  11142. case 'Mesh':
  11143. var geometry = getGeometry( data.geometry );
  11144. var material = getMaterial( data.material );
  11145. if ( geometry.bones && geometry.bones.length > 0 ) {
  11146. object = new THREE.SkinnedMesh( geometry, material );
  11147. } else {
  11148. object = new THREE.Mesh( geometry, material );
  11149. }
  11150. break;
  11151. case 'LOD':
  11152. object = new THREE.LOD();
  11153. break;
  11154. case 'Line':
  11155. object = new THREE.Line( getGeometry( data.geometry ), getMaterial( data.material ), data.mode );
  11156. break;
  11157. case 'PointCloud':
  11158. case 'Points':
  11159. object = new THREE.Points( getGeometry( data.geometry ), getMaterial( data.material ) );
  11160. break;
  11161. case 'Sprite':
  11162. object = new THREE.Sprite( getMaterial( data.material ) );
  11163. break;
  11164. case 'Group':
  11165. object = new THREE.Group();
  11166. break;
  11167. default:
  11168. object = new THREE.Object3D();
  11169. }
  11170. object.uuid = data.uuid;
  11171. if ( data.name !== undefined ) object.name = data.name;
  11172. if ( data.matrix !== undefined ) {
  11173. matrix.fromArray( data.matrix );
  11174. matrix.decompose( object.position, object.quaternion, object.scale );
  11175. } else {
  11176. if ( data.position !== undefined ) object.position.fromArray( data.position );
  11177. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  11178. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  11179. }
  11180. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  11181. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  11182. if ( data.visible !== undefined ) object.visible = data.visible;
  11183. if ( data.userData !== undefined ) object.userData = data.userData;
  11184. if ( data.children !== undefined ) {
  11185. for ( var child in data.children ) {
  11186. object.add( this.parseObject( data.children[ child ], geometries, materials ) );
  11187. }
  11188. }
  11189. if ( data.type === 'LOD' ) {
  11190. var levels = data.levels;
  11191. for ( var l = 0; l < levels.length; l ++ ) {
  11192. var level = levels[ l ];
  11193. var child = object.getObjectByProperty( 'uuid', level.object );
  11194. if ( child !== undefined ) {
  11195. object.addLevel( child, level.distance );
  11196. }
  11197. }
  11198. }
  11199. return object;
  11200. }
  11201. }()
  11202. };
  11203. // File:src/loaders/TextureLoader.js
  11204. /**
  11205. * @author mrdoob / http://mrdoob.com/
  11206. */
  11207. THREE.TextureLoader = function ( manager ) {
  11208. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11209. };
  11210. THREE.TextureLoader.prototype = {
  11211. constructor: THREE.TextureLoader,
  11212. load: function ( url, onLoad, onProgress, onError ) {
  11213. var texture = new THREE.Texture();
  11214. var loader = new THREE.ImageLoader( this.manager );
  11215. loader.setCrossOrigin( this.crossOrigin );
  11216. loader.setPath( this.path );
  11217. loader.load( url, function ( image ) {
  11218. texture.image = image;
  11219. texture.needsUpdate = true;
  11220. if ( onLoad !== undefined ) {
  11221. onLoad( texture );
  11222. }
  11223. }, onProgress, onError );
  11224. return texture;
  11225. },
  11226. setCrossOrigin: function ( value ) {
  11227. this.crossOrigin = value;
  11228. },
  11229. setPath: function ( value ) {
  11230. this.path = value;
  11231. }
  11232. };
  11233. // File:src/loaders/CubeTextureLoader.js
  11234. /**
  11235. * @author mrdoob / http://mrdoob.com/
  11236. */
  11237. THREE.CubeTextureLoader = function ( manager ) {
  11238. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11239. };
  11240. THREE.CubeTextureLoader.prototype = {
  11241. constructor: THREE.CubeTextureLoader,
  11242. load: function ( urls, onLoad, onProgress, onError ) {
  11243. var texture = new THREE.CubeTexture( [] );
  11244. var loader = new THREE.ImageLoader();
  11245. loader.setCrossOrigin( this.crossOrigin );
  11246. loader.setPath( this.path );
  11247. var loaded = 0;
  11248. function loadTexture( i ) {
  11249. loader.load( urls[ i ], function ( image ) {
  11250. texture.images[ i ] = image;
  11251. loaded ++;
  11252. if ( loaded === 6 ) {
  11253. texture.needsUpdate = true;
  11254. if ( onLoad ) onLoad( texture );
  11255. }
  11256. }, undefined, onError );
  11257. }
  11258. for ( var i = 0; i < urls.length; ++ i ) {
  11259. loadTexture( i );
  11260. }
  11261. return texture;
  11262. },
  11263. setCrossOrigin: function ( value ) {
  11264. this.crossOrigin = value;
  11265. },
  11266. setPath: function ( value ) {
  11267. this.path = value;
  11268. }
  11269. };
  11270. // File:src/loaders/BinaryTextureLoader.js
  11271. /**
  11272. * @author Nikos M. / https://github.com/foo123/
  11273. *
  11274. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  11275. */
  11276. THREE.DataTextureLoader = THREE.BinaryTextureLoader = function ( manager ) {
  11277. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11278. // override in sub classes
  11279. this._parser = null;
  11280. };
  11281. THREE.BinaryTextureLoader.prototype = {
  11282. constructor: THREE.BinaryTextureLoader,
  11283. load: function ( url, onLoad, onProgress, onError ) {
  11284. var scope = this;
  11285. var texture = new THREE.DataTexture();
  11286. var loader = new THREE.XHRLoader( this.manager );
  11287. loader.setCrossOrigin( this.crossOrigin );
  11288. loader.setResponseType( 'arraybuffer' );
  11289. loader.load( url, function ( buffer ) {
  11290. var texData = scope._parser( buffer );
  11291. if ( ! texData ) return;
  11292. if ( undefined !== texData.image ) {
  11293. texture.image = texData.image;
  11294. } else if ( undefined !== texData.data ) {
  11295. texture.image.width = texData.width;
  11296. texture.image.height = texData.height;
  11297. texture.image.data = texData.data;
  11298. }
  11299. texture.wrapS = undefined !== texData.wrapS ? texData.wrapS : THREE.ClampToEdgeWrapping;
  11300. texture.wrapT = undefined !== texData.wrapT ? texData.wrapT : THREE.ClampToEdgeWrapping;
  11301. texture.magFilter = undefined !== texData.magFilter ? texData.magFilter : THREE.LinearFilter;
  11302. texture.minFilter = undefined !== texData.minFilter ? texData.minFilter : THREE.LinearMipMapLinearFilter;
  11303. texture.anisotropy = undefined !== texData.anisotropy ? texData.anisotropy : 1;
  11304. if ( undefined !== texData.format ) {
  11305. texture.format = texData.format;
  11306. }
  11307. if ( undefined !== texData.type ) {
  11308. texture.type = texData.type;
  11309. }
  11310. if ( undefined !== texData.mipmaps ) {
  11311. texture.mipmaps = texData.mipmaps;
  11312. }
  11313. if ( 1 === texData.mipmapCount ) {
  11314. texture.minFilter = THREE.LinearFilter;
  11315. }
  11316. texture.needsUpdate = true;
  11317. if ( onLoad ) onLoad( texture, texData );
  11318. }, onProgress, onError );
  11319. return texture;
  11320. },
  11321. setCrossOrigin: function ( value ) {
  11322. this.crossOrigin = value;
  11323. }
  11324. };
  11325. // File:src/loaders/CompressedTextureLoader.js
  11326. /**
  11327. * @author mrdoob / http://mrdoob.com/
  11328. *
  11329. * Abstract Base class to block based textures loader (dds, pvr, ...)
  11330. */
  11331. THREE.CompressedTextureLoader = function ( manager ) {
  11332. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11333. // override in sub classes
  11334. this._parser = null;
  11335. };
  11336. THREE.CompressedTextureLoader.prototype = {
  11337. constructor: THREE.CompressedTextureLoader,
  11338. load: function ( url, onLoad, onProgress, onError ) {
  11339. var scope = this;
  11340. var images = [];
  11341. var texture = new THREE.CompressedTexture();
  11342. texture.image = images;
  11343. var loader = new THREE.XHRLoader( this.manager );
  11344. loader.setCrossOrigin( this.crossOrigin );
  11345. loader.setPath( this.path );
  11346. loader.setResponseType( 'arraybuffer' );
  11347. function loadTexture( i ) {
  11348. loader.load( url[ i ], function ( buffer ) {
  11349. var texDatas = scope._parser( buffer, true );
  11350. images[ i ] = {
  11351. width: texDatas.width,
  11352. height: texDatas.height,
  11353. format: texDatas.format,
  11354. mipmaps: texDatas.mipmaps
  11355. };
  11356. loaded += 1;
  11357. if ( loaded === 6 ) {
  11358. if ( texDatas.mipmapCount === 1 )
  11359. texture.minFilter = THREE.LinearFilter;
  11360. texture.format = texDatas.format;
  11361. texture.needsUpdate = true;
  11362. if ( onLoad ) onLoad( texture );
  11363. }
  11364. }, onProgress, onError );
  11365. }
  11366. if ( Array.isArray( url ) ) {
  11367. var loaded = 0;
  11368. for ( var i = 0, il = url.length; i < il; ++ i ) {
  11369. loadTexture( i );
  11370. }
  11371. } else {
  11372. // compressed cubemap texture stored in a single DDS file
  11373. loader.load( url, function ( buffer ) {
  11374. var texDatas = scope._parser( buffer, true );
  11375. if ( texDatas.isCubemap ) {
  11376. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  11377. for ( var f = 0; f < faces; f ++ ) {
  11378. images[ f ] = { mipmaps : [] };
  11379. for ( var i = 0; i < texDatas.mipmapCount; i ++ ) {
  11380. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  11381. images[ f ].format = texDatas.format;
  11382. images[ f ].width = texDatas.width;
  11383. images[ f ].height = texDatas.height;
  11384. }
  11385. }
  11386. } else {
  11387. texture.image.width = texDatas.width;
  11388. texture.image.height = texDatas.height;
  11389. texture.mipmaps = texDatas.mipmaps;
  11390. }
  11391. if ( texDatas.mipmapCount === 1 ) {
  11392. texture.minFilter = THREE.LinearFilter;
  11393. }
  11394. texture.format = texDatas.format;
  11395. texture.needsUpdate = true;
  11396. if ( onLoad ) onLoad( texture );
  11397. }, onProgress, onError );
  11398. }
  11399. return texture;
  11400. },
  11401. setCrossOrigin: function ( value ) {
  11402. this.crossOrigin = value;
  11403. },
  11404. setPath: function ( value ) {
  11405. this.path = value;
  11406. }
  11407. };
  11408. // File:src/materials/Material.js
  11409. /**
  11410. * @author mrdoob / http://mrdoob.com/
  11411. * @author alteredq / http://alteredqualia.com/
  11412. */
  11413. THREE.Material = function () {
  11414. Object.defineProperty( this, 'id', { value: THREE.MaterialIdCount ++ } );
  11415. this.uuid = THREE.Math.generateUUID();
  11416. this.name = '';
  11417. this.type = 'Material';
  11418. this.side = THREE.FrontSide;
  11419. this.opacity = 1;
  11420. this.transparent = false;
  11421. this.blending = THREE.NormalBlending;
  11422. this.blendSrc = THREE.SrcAlphaFactor;
  11423. this.blendDst = THREE.OneMinusSrcAlphaFactor;
  11424. this.blendEquation = THREE.AddEquation;
  11425. this.blendSrcAlpha = null;
  11426. this.blendDstAlpha = null;
  11427. this.blendEquationAlpha = null;
  11428. this.depthFunc = THREE.LessEqualDepth;
  11429. this.depthTest = true;
  11430. this.depthWrite = true;
  11431. this.colorWrite = true;
  11432. this.precision = null; // override the renderer's default precision for this material
  11433. this.polygonOffset = false;
  11434. this.polygonOffsetFactor = 0;
  11435. this.polygonOffsetUnits = 0;
  11436. this.alphaTest = 0;
  11437. this.overdraw = 0; // Overdrawn pixels (typically between 0 and 1) for fixing antialiasing gaps in CanvasRenderer
  11438. this.visible = true;
  11439. this._needsUpdate = true;
  11440. };
  11441. THREE.Material.prototype = {
  11442. constructor: THREE.Material,
  11443. get needsUpdate () {
  11444. return this._needsUpdate;
  11445. },
  11446. set needsUpdate ( value ) {
  11447. if ( value === true ) this.update();
  11448. this._needsUpdate = value;
  11449. },
  11450. setValues: function ( values ) {
  11451. if ( values === undefined ) return;
  11452. for ( var key in values ) {
  11453. var newValue = values[ key ];
  11454. if ( newValue === undefined ) {
  11455. console.warn( "THREE.Material: '" + key + "' parameter is undefined." );
  11456. continue;
  11457. }
  11458. var currentValue = this[ key ];
  11459. if ( currentValue === undefined ) {
  11460. console.warn( "THREE." + this.type + ": '" + key + "' is not a property of this material." );
  11461. continue;
  11462. }
  11463. if ( currentValue instanceof THREE.Color ) {
  11464. currentValue.set( newValue );
  11465. } else if ( currentValue instanceof THREE.Vector3 && newValue instanceof THREE.Vector3 ) {
  11466. currentValue.copy( newValue );
  11467. } else if ( key === 'overdraw' ) {
  11468. // ensure overdraw is backwards-compatible with legacy boolean type
  11469. this[ key ] = Number( newValue );
  11470. } else {
  11471. this[ key ] = newValue;
  11472. }
  11473. }
  11474. },
  11475. toJSON: function ( meta ) {
  11476. var isRoot = meta === undefined;
  11477. if ( isRoot ) {
  11478. meta = {
  11479. textures: {},
  11480. images: {}
  11481. };
  11482. }
  11483. var data = {
  11484. metadata: {
  11485. version: 4.4,
  11486. type: 'Material',
  11487. generator: 'Material.toJSON'
  11488. }
  11489. };
  11490. // standard Material serialization
  11491. data.uuid = this.uuid;
  11492. data.type = this.type;
  11493. if ( this.name !== '' ) data.name = this.name;
  11494. if ( this.color instanceof THREE.Color ) data.color = this.color.getHex();
  11495. if ( this.roughness !== 0.5 ) data.roughness = this.roughness;
  11496. if ( this.metalness > 0 ) data.metalness = this.metalness;
  11497. if ( this.emissive instanceof THREE.Color ) data.emissive = this.emissive.getHex();
  11498. if ( this.specular instanceof THREE.Color ) data.specular = this.specular.getHex();
  11499. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  11500. if ( this.map instanceof THREE.Texture ) data.map = this.map.toJSON( meta ).uuid;
  11501. if ( this.alphaMap instanceof THREE.Texture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  11502. if ( this.lightMap instanceof THREE.Texture ) data.lightMap = this.lightMap.toJSON( meta ).uuid;
  11503. if ( this.bumpMap instanceof THREE.Texture ) {
  11504. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  11505. data.bumpScale = this.bumpScale;
  11506. }
  11507. if ( this.normalMap instanceof THREE.Texture ) {
  11508. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  11509. data.normalScale = this.normalScale.toArray();
  11510. }
  11511. if ( this.displacementMap instanceof THREE.Texture ) {
  11512. data.displacementMap = this.displacementMap.toJSON( meta ).uuid;
  11513. data.displacementScale = this.displacementScale;
  11514. data.displacementBias = this.displacementBias;
  11515. }
  11516. if ( this.roughnessMap instanceof THREE.Texture ) data.roughnessMap = this.roughnessMap.toJSON( meta ).uuid;
  11517. if ( this.metalnessMap instanceof THREE.Texture ) data.metalnessMap = this.metalnessMap.toJSON( meta ).uuid;
  11518. if ( this.specularMap instanceof THREE.Texture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  11519. if ( this.envMap instanceof THREE.Texture ) {
  11520. data.envMap = this.envMap.toJSON( meta ).uuid;
  11521. data.reflectivity = this.reflectivity; // Scale behind envMap
  11522. }
  11523. if ( this.size !== undefined ) data.size = this.size;
  11524. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  11525. if ( this.vertexColors !== undefined && this.vertexColors !== THREE.NoColors ) data.vertexColors = this.vertexColors;
  11526. if ( this.shading !== undefined && this.shading !== THREE.SmoothShading ) data.shading = this.shading;
  11527. if ( this.blending !== undefined && this.blending !== THREE.NormalBlending ) data.blending = this.blending;
  11528. if ( this.side !== undefined && this.side !== THREE.FrontSide ) data.side = this.side;
  11529. if ( this.opacity < 1 ) data.opacity = this.opacity;
  11530. if ( this.transparent === true ) data.transparent = this.transparent;
  11531. if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
  11532. if ( this.wireframe === true ) data.wireframe = this.wireframe;
  11533. if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;
  11534. // TODO: Copied from Object3D.toJSON
  11535. function extractFromCache ( cache ) {
  11536. var values = [];
  11537. for ( var key in cache ) {
  11538. var data = cache[ key ];
  11539. delete data.metadata;
  11540. values.push( data );
  11541. }
  11542. return values;
  11543. }
  11544. if ( isRoot ) {
  11545. var textures = extractFromCache( meta.textures );
  11546. var images = extractFromCache( meta.images );
  11547. if ( textures.length > 0 ) data.textures = textures;
  11548. if ( images.length > 0 ) data.images = images;
  11549. }
  11550. return data;
  11551. },
  11552. clone: function () {
  11553. return new this.constructor().copy( this );
  11554. },
  11555. copy: function ( source ) {
  11556. this.name = source.name;
  11557. this.side = source.side;
  11558. this.opacity = source.opacity;
  11559. this.transparent = source.transparent;
  11560. this.blending = source.blending;
  11561. this.blendSrc = source.blendSrc;
  11562. this.blendDst = source.blendDst;
  11563. this.blendEquation = source.blendEquation;
  11564. this.blendSrcAlpha = source.blendSrcAlpha;
  11565. this.blendDstAlpha = source.blendDstAlpha;
  11566. this.blendEquationAlpha = source.blendEquationAlpha;
  11567. this.depthFunc = source.depthFunc;
  11568. this.depthTest = source.depthTest;
  11569. this.depthWrite = source.depthWrite;
  11570. this.precision = source.precision;
  11571. this.polygonOffset = source.polygonOffset;
  11572. this.polygonOffsetFactor = source.polygonOffsetFactor;
  11573. this.polygonOffsetUnits = source.polygonOffsetUnits;
  11574. this.alphaTest = source.alphaTest;
  11575. this.overdraw = source.overdraw;
  11576. this.visible = source.visible;
  11577. return this;
  11578. },
  11579. update: function () {
  11580. this.dispatchEvent( { type: 'update' } );
  11581. },
  11582. dispose: function () {
  11583. this.dispatchEvent( { type: 'dispose' } );
  11584. }
  11585. };
  11586. THREE.EventDispatcher.prototype.apply( THREE.Material.prototype );
  11587. THREE.MaterialIdCount = 0;
  11588. // File:src/materials/LineBasicMaterial.js
  11589. /**
  11590. * @author mrdoob / http://mrdoob.com/
  11591. * @author alteredq / http://alteredqualia.com/
  11592. *
  11593. * parameters = {
  11594. * color: <hex>,
  11595. * opacity: <float>,
  11596. *
  11597. * blending: THREE.NormalBlending,
  11598. * depthTest: <bool>,
  11599. * depthWrite: <bool>,
  11600. *
  11601. * linewidth: <float>,
  11602. * linecap: "round",
  11603. * linejoin: "round",
  11604. *
  11605. * vertexColors: <bool>
  11606. *
  11607. * fog: <bool>
  11608. * }
  11609. */
  11610. THREE.LineBasicMaterial = function ( parameters ) {
  11611. THREE.Material.call( this );
  11612. this.type = 'LineBasicMaterial';
  11613. this.color = new THREE.Color( 0xffffff );
  11614. this.linewidth = 1;
  11615. this.linecap = 'round';
  11616. this.linejoin = 'round';
  11617. this.vertexColors = THREE.NoColors;
  11618. this.fog = true;
  11619. this.setValues( parameters );
  11620. };
  11621. THREE.LineBasicMaterial.prototype = Object.create( THREE.Material.prototype );
  11622. THREE.LineBasicMaterial.prototype.constructor = THREE.LineBasicMaterial;
  11623. THREE.LineBasicMaterial.prototype.copy = function ( source ) {
  11624. THREE.Material.prototype.copy.call( this, source );
  11625. this.color.copy( source.color );
  11626. this.linewidth = source.linewidth;
  11627. this.linecap = source.linecap;
  11628. this.linejoin = source.linejoin;
  11629. this.vertexColors = source.vertexColors;
  11630. this.fog = source.fog;
  11631. return this;
  11632. };
  11633. // File:src/materials/LineDashedMaterial.js
  11634. /**
  11635. * @author alteredq / http://alteredqualia.com/
  11636. *
  11637. * parameters = {
  11638. * color: <hex>,
  11639. * opacity: <float>,
  11640. *
  11641. * blending: THREE.NormalBlending,
  11642. * depthTest: <bool>,
  11643. * depthWrite: <bool>,
  11644. *
  11645. * linewidth: <float>,
  11646. *
  11647. * scale: <float>,
  11648. * dashSize: <float>,
  11649. * gapSize: <float>,
  11650. *
  11651. * vertexColors: THREE.NoColors / THREE.FaceColors / THREE.VertexColors
  11652. *
  11653. * fog: <bool>
  11654. * }
  11655. */
  11656. THREE.LineDashedMaterial = function ( parameters ) {
  11657. THREE.Material.call( this );
  11658. this.type = 'LineDashedMaterial';
  11659. this.color = new THREE.Color( 0xffffff );
  11660. this.linewidth = 1;
  11661. this.scale = 1;
  11662. this.dashSize = 3;
  11663. this.gapSize = 1;
  11664. this.vertexColors = THREE.NoColors;
  11665. this.fog = true;
  11666. this.setValues( parameters );
  11667. };
  11668. THREE.LineDashedMaterial.prototype = Object.create( THREE.Material.prototype );
  11669. THREE.LineDashedMaterial.prototype.constructor = THREE.LineDashedMaterial;
  11670. THREE.LineDashedMaterial.prototype.copy = function ( source ) {
  11671. THREE.Material.prototype.copy.call( this, source );
  11672. this.color.copy( source.color );
  11673. this.linewidth = source.linewidth;
  11674. this.scale = source.scale;
  11675. this.dashSize = source.dashSize;
  11676. this.gapSize = source.gapSize;
  11677. this.vertexColors = source.vertexColors;
  11678. this.fog = source.fog;
  11679. return this;
  11680. };
  11681. // File:src/materials/MeshBasicMaterial.js
  11682. /**
  11683. * @author mrdoob / http://mrdoob.com/
  11684. * @author alteredq / http://alteredqualia.com/
  11685. *
  11686. * parameters = {
  11687. * color: <hex>,
  11688. * opacity: <float>,
  11689. * map: new THREE.Texture( <Image> ),
  11690. *
  11691. * aoMap: new THREE.Texture( <Image> ),
  11692. * aoMapIntensity: <float>
  11693. *
  11694. * specularMap: new THREE.Texture( <Image> ),
  11695. *
  11696. * alphaMap: new THREE.Texture( <Image> ),
  11697. *
  11698. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  11699. * combine: THREE.Multiply,
  11700. * reflectivity: <float>,
  11701. * refractionRatio: <float>,
  11702. *
  11703. * shading: THREE.SmoothShading,
  11704. * blending: THREE.NormalBlending,
  11705. * depthTest: <bool>,
  11706. * depthWrite: <bool>,
  11707. *
  11708. * wireframe: <boolean>,
  11709. * wireframeLinewidth: <float>,
  11710. *
  11711. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  11712. *
  11713. * skinning: <bool>,
  11714. * morphTargets: <bool>,
  11715. *
  11716. * fog: <bool>
  11717. * }
  11718. */
  11719. THREE.MeshBasicMaterial = function ( parameters ) {
  11720. THREE.Material.call( this );
  11721. this.type = 'MeshBasicMaterial';
  11722. this.color = new THREE.Color( 0xffffff ); // emissive
  11723. this.map = null;
  11724. this.aoMap = null;
  11725. this.aoMapIntensity = 1.0;
  11726. this.specularMap = null;
  11727. this.alphaMap = null;
  11728. this.envMap = null;
  11729. this.combine = THREE.MultiplyOperation;
  11730. this.reflectivity = 1;
  11731. this.refractionRatio = 0.98;
  11732. this.fog = true;
  11733. this.shading = THREE.SmoothShading;
  11734. this.wireframe = false;
  11735. this.wireframeLinewidth = 1;
  11736. this.wireframeLinecap = 'round';
  11737. this.wireframeLinejoin = 'round';
  11738. this.vertexColors = THREE.NoColors;
  11739. this.skinning = false;
  11740. this.morphTargets = false;
  11741. this.setValues( parameters );
  11742. };
  11743. THREE.MeshBasicMaterial.prototype = Object.create( THREE.Material.prototype );
  11744. THREE.MeshBasicMaterial.prototype.constructor = THREE.MeshBasicMaterial;
  11745. THREE.MeshBasicMaterial.prototype.copy = function ( source ) {
  11746. THREE.Material.prototype.copy.call( this, source );
  11747. this.color.copy( source.color );
  11748. this.map = source.map;
  11749. this.aoMap = source.aoMap;
  11750. this.aoMapIntensity = source.aoMapIntensity;
  11751. this.specularMap = source.specularMap;
  11752. this.alphaMap = source.alphaMap;
  11753. this.envMap = source.envMap;
  11754. this.combine = source.combine;
  11755. this.reflectivity = source.reflectivity;
  11756. this.refractionRatio = source.refractionRatio;
  11757. this.fog = source.fog;
  11758. this.shading = source.shading;
  11759. this.wireframe = source.wireframe;
  11760. this.wireframeLinewidth = source.wireframeLinewidth;
  11761. this.wireframeLinecap = source.wireframeLinecap;
  11762. this.wireframeLinejoin = source.wireframeLinejoin;
  11763. this.vertexColors = source.vertexColors;
  11764. this.skinning = source.skinning;
  11765. this.morphTargets = source.morphTargets;
  11766. return this;
  11767. };
  11768. // File:src/materials/MeshLambertMaterial.js
  11769. /**
  11770. * @author mrdoob / http://mrdoob.com/
  11771. * @author alteredq / http://alteredqualia.com/
  11772. *
  11773. * parameters = {
  11774. * color: <hex>,
  11775. * emissive: <hex>,
  11776. * opacity: <float>,
  11777. *
  11778. * map: new THREE.Texture( <Image> ),
  11779. *
  11780. * specularMap: new THREE.Texture( <Image> ),
  11781. *
  11782. * alphaMap: new THREE.Texture( <Image> ),
  11783. *
  11784. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  11785. * combine: THREE.Multiply,
  11786. * reflectivity: <float>,
  11787. * refractionRatio: <float>,
  11788. *
  11789. * blending: THREE.NormalBlending,
  11790. * depthTest: <bool>,
  11791. * depthWrite: <bool>,
  11792. *
  11793. * wireframe: <boolean>,
  11794. * wireframeLinewidth: <float>,
  11795. *
  11796. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  11797. *
  11798. * skinning: <bool>,
  11799. * morphTargets: <bool>,
  11800. * morphNormals: <bool>,
  11801. *
  11802. * fog: <bool>
  11803. * }
  11804. */
  11805. THREE.MeshLambertMaterial = function ( parameters ) {
  11806. THREE.Material.call( this );
  11807. this.type = 'MeshLambertMaterial';
  11808. this.color = new THREE.Color( 0xffffff ); // diffuse
  11809. this.emissive = new THREE.Color( 0x000000 );
  11810. this.map = null;
  11811. this.specularMap = null;
  11812. this.alphaMap = null;
  11813. this.envMap = null;
  11814. this.combine = THREE.MultiplyOperation;
  11815. this.reflectivity = 1;
  11816. this.refractionRatio = 0.98;
  11817. this.fog = true;
  11818. this.wireframe = false;
  11819. this.wireframeLinewidth = 1;
  11820. this.wireframeLinecap = 'round';
  11821. this.wireframeLinejoin = 'round';
  11822. this.vertexColors = THREE.NoColors;
  11823. this.skinning = false;
  11824. this.morphTargets = false;
  11825. this.morphNormals = false;
  11826. this.setValues( parameters );
  11827. };
  11828. THREE.MeshLambertMaterial.prototype = Object.create( THREE.Material.prototype );
  11829. THREE.MeshLambertMaterial.prototype.constructor = THREE.MeshLambertMaterial;
  11830. THREE.MeshLambertMaterial.prototype.copy = function ( source ) {
  11831. THREE.Material.prototype.copy.call( this, source );
  11832. this.color.copy( source.color );
  11833. this.emissive.copy( source.emissive );
  11834. this.map = source.map;
  11835. this.specularMap = source.specularMap;
  11836. this.alphaMap = source.alphaMap;
  11837. this.envMap = source.envMap;
  11838. this.combine = source.combine;
  11839. this.reflectivity = source.reflectivity;
  11840. this.refractionRatio = source.refractionRatio;
  11841. this.fog = source.fog;
  11842. this.wireframe = source.wireframe;
  11843. this.wireframeLinewidth = source.wireframeLinewidth;
  11844. this.wireframeLinecap = source.wireframeLinecap;
  11845. this.wireframeLinejoin = source.wireframeLinejoin;
  11846. this.vertexColors = source.vertexColors;
  11847. this.skinning = source.skinning;
  11848. this.morphTargets = source.morphTargets;
  11849. this.morphNormals = source.morphNormals;
  11850. return this;
  11851. };
  11852. // File:src/materials/MeshPhongMaterial.js
  11853. /**
  11854. * @author mrdoob / http://mrdoob.com/
  11855. * @author alteredq / http://alteredqualia.com/
  11856. *
  11857. * parameters = {
  11858. * color: <hex>,
  11859. * emissive: <hex>,
  11860. * specular: <hex>,
  11861. * shininess: <float>,
  11862. * opacity: <float>,
  11863. *
  11864. * map: new THREE.Texture( <Image> ),
  11865. *
  11866. * lightMap: new THREE.Texture( <Image> ),
  11867. * lightMapIntensity: <float>
  11868. *
  11869. * aoMap: new THREE.Texture( <Image> ),
  11870. * aoMapIntensity: <float>
  11871. *
  11872. * emissiveMap: new THREE.Texture( <Image> ),
  11873. *
  11874. * bumpMap: new THREE.Texture( <Image> ),
  11875. * bumpScale: <float>,
  11876. *
  11877. * normalMap: new THREE.Texture( <Image> ),
  11878. * normalScale: <Vector2>,
  11879. *
  11880. * displacementMap: new THREE.Texture( <Image> ),
  11881. * displacementScale: <float>,
  11882. * displacementBias: <float>,
  11883. *
  11884. * specularMap: new THREE.Texture( <Image> ),
  11885. *
  11886. * alphaMap: new THREE.Texture( <Image> ),
  11887. *
  11888. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  11889. * combine: THREE.Multiply,
  11890. * reflectivity: <float>,
  11891. * refractionRatio: <float>,
  11892. *
  11893. * shading: THREE.SmoothShading,
  11894. * blending: THREE.NormalBlending,
  11895. * depthTest: <bool>,
  11896. * depthWrite: <bool>,
  11897. *
  11898. * wireframe: <boolean>,
  11899. * wireframeLinewidth: <float>,
  11900. *
  11901. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  11902. *
  11903. * skinning: <bool>,
  11904. * morphTargets: <bool>,
  11905. * morphNormals: <bool>,
  11906. *
  11907. * fog: <bool>
  11908. * }
  11909. */
  11910. THREE.MeshPhongMaterial = function ( parameters ) {
  11911. THREE.Material.call( this );
  11912. this.type = 'MeshPhongMaterial';
  11913. this.color = new THREE.Color( 0xffffff ); // diffuse
  11914. this.emissive = new THREE.Color( 0x000000 );
  11915. this.specular = new THREE.Color( 0x111111 );
  11916. this.shininess = 30;
  11917. this.map = null;
  11918. this.lightMap = null;
  11919. this.lightMapIntensity = 1.0;
  11920. this.aoMap = null;
  11921. this.aoMapIntensity = 1.0;
  11922. this.emissiveMap = null;
  11923. this.bumpMap = null;
  11924. this.bumpScale = 1;
  11925. this.normalMap = null;
  11926. this.normalScale = new THREE.Vector2( 1, 1 );
  11927. this.displacementMap = null;
  11928. this.displacementScale = 1;
  11929. this.displacementBias = 0;
  11930. this.specularMap = null;
  11931. this.alphaMap = null;
  11932. this.envMap = null;
  11933. this.combine = THREE.MultiplyOperation;
  11934. this.reflectivity = 1;
  11935. this.refractionRatio = 0.98;
  11936. this.fog = true;
  11937. this.shading = THREE.SmoothShading;
  11938. this.wireframe = false;
  11939. this.wireframeLinewidth = 1;
  11940. this.wireframeLinecap = 'round';
  11941. this.wireframeLinejoin = 'round';
  11942. this.vertexColors = THREE.NoColors;
  11943. this.skinning = false;
  11944. this.morphTargets = false;
  11945. this.morphNormals = false;
  11946. this.setValues( parameters );
  11947. };
  11948. THREE.MeshPhongMaterial.prototype = Object.create( THREE.Material.prototype );
  11949. THREE.MeshPhongMaterial.prototype.constructor = THREE.MeshPhongMaterial;
  11950. THREE.MeshPhongMaterial.prototype.copy = function ( source ) {
  11951. THREE.Material.prototype.copy.call( this, source );
  11952. this.color.copy( source.color );
  11953. this.emissive.copy( source.emissive );
  11954. this.specular.copy( source.specular );
  11955. this.shininess = source.shininess;
  11956. this.map = source.map;
  11957. this.lightMap = source.lightMap;
  11958. this.lightMapIntensity = source.lightMapIntensity;
  11959. this.aoMap = source.aoMap;
  11960. this.aoMapIntensity = source.aoMapIntensity;
  11961. this.emissiveMap = source.emissiveMap;
  11962. this.bumpMap = source.bumpMap;
  11963. this.bumpScale = source.bumpScale;
  11964. this.normalMap = source.normalMap;
  11965. this.normalScale.copy( source.normalScale );
  11966. this.displacementMap = source.displacementMap;
  11967. this.displacementScale = source.displacementScale;
  11968. this.displacementBias = source.displacementBias;
  11969. this.specularMap = source.specularMap;
  11970. this.alphaMap = source.alphaMap;
  11971. this.envMap = source.envMap;
  11972. this.combine = source.combine;
  11973. this.reflectivity = source.reflectivity;
  11974. this.refractionRatio = source.refractionRatio;
  11975. this.fog = source.fog;
  11976. this.shading = source.shading;
  11977. this.wireframe = source.wireframe;
  11978. this.wireframeLinewidth = source.wireframeLinewidth;
  11979. this.wireframeLinecap = source.wireframeLinecap;
  11980. this.wireframeLinejoin = source.wireframeLinejoin;
  11981. this.vertexColors = source.vertexColors;
  11982. this.skinning = source.skinning;
  11983. this.morphTargets = source.morphTargets;
  11984. this.morphNormals = source.morphNormals;
  11985. return this;
  11986. };
  11987. // File:src/materials/MeshPhysicalMaterial.js
  11988. /**
  11989. * @author WestLangley / http://github.com/WestLangley
  11990. *
  11991. * parameters = {
  11992. * color: <hex>,
  11993. * roughness: <float>,
  11994. * reflectivity: <float>,
  11995. * metalness: <float>,
  11996. * emissive: <hex>,
  11997. * opacity: <float>,
  11998. *
  11999. * map: new THREE.Texture( <Image> ),
  12000. *
  12001. * lightMap: new THREE.Texture( <Image> ),
  12002. * lightMapIntensity: <float>
  12003. *
  12004. * aoMap: new THREE.Texture( <Image> ),
  12005. * aoMapIntensity: <float>
  12006. *
  12007. * emissiveMap: new THREE.Texture( <Image> ),
  12008. *
  12009. * bumpMap: new THREE.Texture( <Image> ),
  12010. * bumpScale: <float>,
  12011. *
  12012. * normalMap: new THREE.Texture( <Image> ),
  12013. * normalScale: <Vector2>,
  12014. *
  12015. * displacementMap: new THREE.Texture( <Image> ),
  12016. * displacementScale: <float>,
  12017. * displacementBias: <float>,
  12018. *
  12019. * roughnessMap: new THREE.Texture( <Image> ),
  12020. *
  12021. * reflectivityMap: new THREE.Texture( <Image> ),
  12022. *
  12023. * metalnessMap: new THREE.Texture( <Image> ),
  12024. *
  12025. * alphaMap: new THREE.Texture( <Image> ),
  12026. *
  12027. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  12028. * refractionRatio: <float>,
  12029. *
  12030. * shading: THREE.SmoothShading,
  12031. * blending: THREE.NormalBlending,
  12032. * depthTest: <bool>,
  12033. * depthWrite: <bool>,
  12034. *
  12035. * wireframe: <boolean>,
  12036. * wireframeLinewidth: <float>,
  12037. *
  12038. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  12039. *
  12040. * skinning: <bool>,
  12041. * morphTargets: <bool>,
  12042. * morphNormals: <bool>,
  12043. *
  12044. * fog: <bool>
  12045. * }
  12046. */
  12047. THREE.MeshPhysicalMaterial = function ( parameters ) {
  12048. THREE.Material.call( this );
  12049. this.type = 'MeshPhysicalMaterial';
  12050. this.color = new THREE.Color( 0xffffff ); // diffuse
  12051. this.roughness = 0.5;
  12052. this.reflectivity = 1;
  12053. this.metalness = 0;
  12054. this.emissive = new THREE.Color( 0x000000 );
  12055. this.map = null;
  12056. this.lightMap = null;
  12057. this.lightMapIntensity = 1.0;
  12058. this.aoMap = null;
  12059. this.aoMapIntensity = 1.0;
  12060. this.emissiveMap = null;
  12061. this.bumpMap = null;
  12062. this.bumpScale = 1;
  12063. this.normalMap = null;
  12064. this.normalScale = new THREE.Vector2( 1, 1 );
  12065. this.displacementMap = null;
  12066. this.displacementScale = 1;
  12067. this.displacementBias = 0;
  12068. this.roughnessMap = null;
  12069. this.reflectivityMap = null;
  12070. this.metalnessMap = null;
  12071. this.alphaMap = null;
  12072. this.envMap = null;
  12073. this.envMapIntensity = 1.0;
  12074. this.refractionRatio = 0.98;
  12075. this.fog = true;
  12076. this.shading = THREE.SmoothShading;
  12077. this.wireframe = false;
  12078. this.wireframeLinewidth = 1;
  12079. this.wireframeLinecap = 'round';
  12080. this.wireframeLinejoin = 'round';
  12081. this.vertexColors = THREE.NoColors;
  12082. this.skinning = false;
  12083. this.morphTargets = false;
  12084. this.morphNormals = false;
  12085. this.setValues( parameters );
  12086. };
  12087. THREE.MeshPhysicalMaterial.prototype = Object.create( THREE.Material.prototype );
  12088. THREE.MeshPhysicalMaterial.prototype.constructor = THREE.MeshPhysicalMaterial;
  12089. THREE.MeshPhysicalMaterial.prototype.copy = function ( source ) {
  12090. THREE.Material.prototype.copy.call( this, source );
  12091. this.color.copy( source.color );
  12092. this.roughness = source.roughness;
  12093. this.reflectivity = source.reflectivity;
  12094. this.metalness = source.metalness;
  12095. this.emissive.copy( source.emissive );
  12096. this.map = source.map;
  12097. this.lightMap = source.lightMap;
  12098. this.lightMapIntensity = source.lightMapIntensity;
  12099. this.aoMap = source.aoMap;
  12100. this.aoMapIntensity = source.aoMapIntensity;
  12101. this.emissiveMap = source.emissiveMap;
  12102. this.bumpMap = source.bumpMap;
  12103. this.bumpScale = source.bumpScale;
  12104. this.normalMap = source.normalMap;
  12105. this.normalScale.copy( source.normalScale );
  12106. this.displacementMap = source.displacementMap;
  12107. this.displacementScale = source.displacementScale;
  12108. this.displacementBias = source.displacementBias;
  12109. this.roughnessMap = source.roughnessMap;
  12110. this.reflectivityMap = source.reflectivityMap;
  12111. this.metalnessMap = source.metalnessMap;
  12112. this.alphaMap = source.alphaMap;
  12113. this.envMap = source.envMap;
  12114. this.envMapIntensity = source.envMapIntensity;
  12115. this.refractionRatio = source.refractionRatio;
  12116. this.fog = source.fog;
  12117. this.shading = source.shading;
  12118. this.wireframe = source.wireframe;
  12119. this.wireframeLinewidth = source.wireframeLinewidth;
  12120. this.wireframeLinecap = source.wireframeLinecap;
  12121. this.wireframeLinejoin = source.wireframeLinejoin;
  12122. this.vertexColors = source.vertexColors;
  12123. this.skinning = source.skinning;
  12124. this.morphTargets = source.morphTargets;
  12125. this.morphNormals = source.morphNormals;
  12126. return this;
  12127. };
  12128. // File:src/materials/MeshDepthMaterial.js
  12129. /**
  12130. * @author mrdoob / http://mrdoob.com/
  12131. * @author alteredq / http://alteredqualia.com/
  12132. *
  12133. * parameters = {
  12134. * opacity: <float>,
  12135. *
  12136. * blending: THREE.NormalBlending,
  12137. * depthTest: <bool>,
  12138. * depthWrite: <bool>,
  12139. *
  12140. * wireframe: <boolean>,
  12141. * wireframeLinewidth: <float>
  12142. * }
  12143. */
  12144. THREE.MeshDepthMaterial = function ( parameters ) {
  12145. THREE.Material.call( this );
  12146. this.type = 'MeshDepthMaterial';
  12147. this.morphTargets = false;
  12148. this.wireframe = false;
  12149. this.wireframeLinewidth = 1;
  12150. this.setValues( parameters );
  12151. };
  12152. THREE.MeshDepthMaterial.prototype = Object.create( THREE.Material.prototype );
  12153. THREE.MeshDepthMaterial.prototype.constructor = THREE.MeshDepthMaterial;
  12154. THREE.MeshDepthMaterial.prototype.copy = function ( source ) {
  12155. THREE.Material.prototype.copy.call( this, source );
  12156. this.wireframe = source.wireframe;
  12157. this.wireframeLinewidth = source.wireframeLinewidth;
  12158. return this;
  12159. };
  12160. // File:src/materials/MeshNormalMaterial.js
  12161. /**
  12162. * @author mrdoob / http://mrdoob.com/
  12163. *
  12164. * parameters = {
  12165. * opacity: <float>,
  12166. *
  12167. * shading: THREE.FlatShading,
  12168. * blending: THREE.NormalBlending,
  12169. * depthTest: <bool>,
  12170. * depthWrite: <bool>,
  12171. *
  12172. * wireframe: <boolean>,
  12173. * wireframeLinewidth: <float>
  12174. * }
  12175. */
  12176. THREE.MeshNormalMaterial = function ( parameters ) {
  12177. THREE.Material.call( this, parameters );
  12178. this.type = 'MeshNormalMaterial';
  12179. this.wireframe = false;
  12180. this.wireframeLinewidth = 1;
  12181. this.morphTargets = false;
  12182. this.setValues( parameters );
  12183. };
  12184. THREE.MeshNormalMaterial.prototype = Object.create( THREE.Material.prototype );
  12185. THREE.MeshNormalMaterial.prototype.constructor = THREE.MeshNormalMaterial;
  12186. THREE.MeshNormalMaterial.prototype.copy = function ( source ) {
  12187. THREE.Material.prototype.copy.call( this, source );
  12188. this.wireframe = source.wireframe;
  12189. this.wireframeLinewidth = source.wireframeLinewidth;
  12190. return this;
  12191. };
  12192. // File:src/materials/MultiMaterial.js
  12193. /**
  12194. * @author mrdoob / http://mrdoob.com/
  12195. */
  12196. THREE.MultiMaterial = function ( materials ) {
  12197. this.uuid = THREE.Math.generateUUID();
  12198. this.type = 'MultiMaterial';
  12199. this.materials = materials instanceof Array ? materials : [];
  12200. this.visible = true;
  12201. };
  12202. THREE.MultiMaterial.prototype = {
  12203. constructor: THREE.MultiMaterial,
  12204. toJSON: function ( meta ) {
  12205. var output = {
  12206. metadata: {
  12207. version: 4.2,
  12208. type: 'material',
  12209. generator: 'MaterialExporter'
  12210. },
  12211. uuid: this.uuid,
  12212. type: this.type,
  12213. materials: []
  12214. };
  12215. var materials = this.materials;
  12216. for ( var i = 0, l = materials.length; i < l; i ++ ) {
  12217. var material = materials[ i ].toJSON( meta );
  12218. delete material.metadata;
  12219. output.materials.push( material );
  12220. }
  12221. output.visible = this.visible;
  12222. return output;
  12223. },
  12224. clone: function () {
  12225. var material = new this.constructor();
  12226. for ( var i = 0; i < this.materials.length; i ++ ) {
  12227. material.materials.push( this.materials[ i ].clone() );
  12228. }
  12229. material.visible = this.visible;
  12230. return material;
  12231. }
  12232. };
  12233. // backwards compatibility
  12234. THREE.MeshFaceMaterial = THREE.MultiMaterial;
  12235. // File:src/materials/PointsMaterial.js
  12236. /**
  12237. * @author mrdoob / http://mrdoob.com/
  12238. * @author alteredq / http://alteredqualia.com/
  12239. *
  12240. * parameters = {
  12241. * color: <hex>,
  12242. * opacity: <float>,
  12243. * map: new THREE.Texture( <Image> ),
  12244. *
  12245. * size: <float>,
  12246. * sizeAttenuation: <bool>,
  12247. *
  12248. * blending: THREE.NormalBlending,
  12249. * depthTest: <bool>,
  12250. * depthWrite: <bool>,
  12251. *
  12252. * vertexColors: <bool>,
  12253. *
  12254. * fog: <bool>
  12255. * }
  12256. */
  12257. THREE.PointsMaterial = function ( parameters ) {
  12258. THREE.Material.call( this );
  12259. this.type = 'PointsMaterial';
  12260. this.color = new THREE.Color( 0xffffff );
  12261. this.map = null;
  12262. this.size = 1;
  12263. this.sizeAttenuation = true;
  12264. this.vertexColors = THREE.NoColors;
  12265. this.fog = true;
  12266. this.setValues( parameters );
  12267. };
  12268. THREE.PointsMaterial.prototype = Object.create( THREE.Material.prototype );
  12269. THREE.PointsMaterial.prototype.constructor = THREE.PointsMaterial;
  12270. THREE.PointsMaterial.prototype.copy = function ( source ) {
  12271. THREE.Material.prototype.copy.call( this, source );
  12272. this.color.copy( source.color );
  12273. this.map = source.map;
  12274. this.size = source.size;
  12275. this.sizeAttenuation = source.sizeAttenuation;
  12276. this.vertexColors = source.vertexColors;
  12277. this.fog = source.fog;
  12278. return this;
  12279. };
  12280. // File:src/materials/ShaderMaterial.js
  12281. /**
  12282. * @author alteredq / http://alteredqualia.com/
  12283. *
  12284. * parameters = {
  12285. * defines: { "label" : "value" },
  12286. * uniforms: { "parameter1": { type: "f", value: 1.0 }, "parameter2": { type: "i" value2: 2 } },
  12287. *
  12288. * fragmentShader: <string>,
  12289. * vertexShader: <string>,
  12290. *
  12291. * shading: THREE.SmoothShading,
  12292. * blending: THREE.NormalBlending,
  12293. * depthTest: <bool>,
  12294. * depthWrite: <bool>,
  12295. *
  12296. * wireframe: <boolean>,
  12297. * wireframeLinewidth: <float>,
  12298. *
  12299. * lights: <bool>,
  12300. *
  12301. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  12302. *
  12303. * skinning: <bool>,
  12304. * morphTargets: <bool>,
  12305. * morphNormals: <bool>,
  12306. *
  12307. * fog: <bool>
  12308. * }
  12309. */
  12310. THREE.ShaderMaterial = function ( parameters ) {
  12311. THREE.Material.call( this );
  12312. this.type = 'ShaderMaterial';
  12313. this.defines = {};
  12314. this.uniforms = {};
  12315. this.vertexShader = 'void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}';
  12316. this.fragmentShader = 'void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}';
  12317. this.shading = THREE.SmoothShading;
  12318. this.linewidth = 1;
  12319. this.wireframe = false;
  12320. this.wireframeLinewidth = 1;
  12321. this.fog = false; // set to use scene fog
  12322. this.lights = false; // set to use scene lights
  12323. this.vertexColors = THREE.NoColors; // set to use "color" attribute stream
  12324. this.skinning = false; // set to use skinning attribute streams
  12325. this.morphTargets = false; // set to use morph targets
  12326. this.morphNormals = false; // set to use morph normals
  12327. this.extensions = {
  12328. derivatives: false, // set to use derivatives
  12329. fragDepth: false, // set to use fragment depth values
  12330. drawBuffers: false, // set to use draw buffers
  12331. shaderTextureLOD: false // set to use shader texture LOD
  12332. };
  12333. // When rendered geometry doesn't include these attributes but the material does,
  12334. // use these default values in WebGL. This avoids errors when buffer data is missing.
  12335. this.defaultAttributeValues = {
  12336. 'color': [ 1, 1, 1 ],
  12337. 'uv': [ 0, 0 ],
  12338. 'uv2': [ 0, 0 ]
  12339. };
  12340. this.index0AttributeName = undefined;
  12341. if ( parameters !== undefined ) {
  12342. if ( parameters.attributes !== undefined ) {
  12343. console.error( 'THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.' );
  12344. }
  12345. this.setValues( parameters );
  12346. }
  12347. };
  12348. THREE.ShaderMaterial.prototype = Object.create( THREE.Material.prototype );
  12349. THREE.ShaderMaterial.prototype.constructor = THREE.ShaderMaterial;
  12350. THREE.ShaderMaterial.prototype.copy = function ( source ) {
  12351. THREE.Material.prototype.copy.call( this, source );
  12352. this.fragmentShader = source.fragmentShader;
  12353. this.vertexShader = source.vertexShader;
  12354. this.uniforms = THREE.UniformsUtils.clone( source.uniforms );
  12355. this.attributes = source.attributes;
  12356. this.defines = source.defines;
  12357. this.shading = source.shading;
  12358. this.wireframe = source.wireframe;
  12359. this.wireframeLinewidth = source.wireframeLinewidth;
  12360. this.fog = source.fog;
  12361. this.lights = source.lights;
  12362. this.vertexColors = source.vertexColors;
  12363. this.skinning = source.skinning;
  12364. this.morphTargets = source.morphTargets;
  12365. this.morphNormals = source.morphNormals;
  12366. this.extensions = source.extensions;
  12367. return this;
  12368. };
  12369. THREE.ShaderMaterial.prototype.toJSON = function ( meta ) {
  12370. var data = THREE.Material.prototype.toJSON.call( this, meta );
  12371. data.uniforms = this.uniforms;
  12372. data.attributes = this.attributes;
  12373. data.vertexShader = this.vertexShader;
  12374. data.fragmentShader = this.fragmentShader;
  12375. return data;
  12376. };
  12377. // File:src/materials/RawShaderMaterial.js
  12378. /**
  12379. * @author mrdoob / http://mrdoob.com/
  12380. */
  12381. THREE.RawShaderMaterial = function ( parameters ) {
  12382. THREE.ShaderMaterial.call( this, parameters );
  12383. this.type = 'RawShaderMaterial';
  12384. };
  12385. THREE.RawShaderMaterial.prototype = Object.create( THREE.ShaderMaterial.prototype );
  12386. THREE.RawShaderMaterial.prototype.constructor = THREE.RawShaderMaterial;
  12387. // File:src/materials/SpriteMaterial.js
  12388. /**
  12389. * @author alteredq / http://alteredqualia.com/
  12390. *
  12391. * parameters = {
  12392. * color: <hex>,
  12393. * opacity: <float>,
  12394. * map: new THREE.Texture( <Image> ),
  12395. *
  12396. * blending: THREE.NormalBlending,
  12397. * depthTest: <bool>,
  12398. * depthWrite: <bool>,
  12399. *
  12400. * uvOffset: new THREE.Vector2(),
  12401. * uvScale: new THREE.Vector2(),
  12402. *
  12403. * fog: <bool>
  12404. * }
  12405. */
  12406. THREE.SpriteMaterial = function ( parameters ) {
  12407. THREE.Material.call( this );
  12408. this.type = 'SpriteMaterial';
  12409. this.color = new THREE.Color( 0xffffff );
  12410. this.map = null;
  12411. this.rotation = 0;
  12412. this.fog = false;
  12413. // set parameters
  12414. this.setValues( parameters );
  12415. };
  12416. THREE.SpriteMaterial.prototype = Object.create( THREE.Material.prototype );
  12417. THREE.SpriteMaterial.prototype.constructor = THREE.SpriteMaterial;
  12418. THREE.SpriteMaterial.prototype.copy = function ( source ) {
  12419. THREE.Material.prototype.copy.call( this, source );
  12420. this.color.copy( source.color );
  12421. this.map = source.map;
  12422. this.rotation = source.rotation;
  12423. this.fog = source.fog;
  12424. return this;
  12425. };
  12426. // File:src/textures/Texture.js
  12427. /**
  12428. * @author mrdoob / http://mrdoob.com/
  12429. * @author alteredq / http://alteredqualia.com/
  12430. * @author szimek / https://github.com/szimek/
  12431. */
  12432. THREE.Texture = function ( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  12433. Object.defineProperty( this, 'id', { value: THREE.TextureIdCount ++ } );
  12434. this.uuid = THREE.Math.generateUUID();
  12435. this.name = '';
  12436. this.sourceFile = '';
  12437. this.image = image !== undefined ? image : THREE.Texture.DEFAULT_IMAGE;
  12438. this.mipmaps = [];
  12439. this.mapping = mapping !== undefined ? mapping : THREE.Texture.DEFAULT_MAPPING;
  12440. this.wrapS = wrapS !== undefined ? wrapS : THREE.ClampToEdgeWrapping;
  12441. this.wrapT = wrapT !== undefined ? wrapT : THREE.ClampToEdgeWrapping;
  12442. this.magFilter = magFilter !== undefined ? magFilter : THREE.LinearFilter;
  12443. this.minFilter = minFilter !== undefined ? minFilter : THREE.LinearMipMapLinearFilter;
  12444. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  12445. this.format = format !== undefined ? format : THREE.RGBAFormat;
  12446. this.type = type !== undefined ? type : THREE.UnsignedByteType;
  12447. this.offset = new THREE.Vector2( 0, 0 );
  12448. this.repeat = new THREE.Vector2( 1, 1 );
  12449. this.generateMipmaps = true;
  12450. this.premultiplyAlpha = false;
  12451. this.flipY = true;
  12452. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  12453. this.version = 0;
  12454. this.onUpdate = null;
  12455. };
  12456. THREE.Texture.DEFAULT_IMAGE = undefined;
  12457. THREE.Texture.DEFAULT_MAPPING = THREE.UVMapping;
  12458. THREE.Texture.prototype = {
  12459. constructor: THREE.Texture,
  12460. set needsUpdate ( value ) {
  12461. if ( value === true ) this.version ++;
  12462. },
  12463. clone: function () {
  12464. return new this.constructor().copy( this );
  12465. },
  12466. copy: function ( source ) {
  12467. this.image = source.image;
  12468. this.mipmaps = source.mipmaps.slice( 0 );
  12469. this.mapping = source.mapping;
  12470. this.wrapS = source.wrapS;
  12471. this.wrapT = source.wrapT;
  12472. this.magFilter = source.magFilter;
  12473. this.minFilter = source.minFilter;
  12474. this.anisotropy = source.anisotropy;
  12475. this.format = source.format;
  12476. this.type = source.type;
  12477. this.offset.copy( source.offset );
  12478. this.repeat.copy( source.repeat );
  12479. this.generateMipmaps = source.generateMipmaps;
  12480. this.premultiplyAlpha = source.premultiplyAlpha;
  12481. this.flipY = source.flipY;
  12482. this.unpackAlignment = source.unpackAlignment;
  12483. return this;
  12484. },
  12485. toJSON: function ( meta ) {
  12486. if ( meta.textures[ this.uuid ] !== undefined ) {
  12487. return meta.textures[ this.uuid ];
  12488. }
  12489. function getDataURL( image ) {
  12490. var canvas;
  12491. if ( image.toDataURL !== undefined ) {
  12492. canvas = image;
  12493. } else {
  12494. canvas = document.createElement( 'canvas' );
  12495. canvas.width = image.width;
  12496. canvas.height = image.height;
  12497. canvas.getContext( '2d' ).drawImage( image, 0, 0, image.width, image.height );
  12498. }
  12499. if ( canvas.width > 2048 || canvas.height > 2048 ) {
  12500. return canvas.toDataURL( 'image/jpeg', 0.6 );
  12501. } else {
  12502. return canvas.toDataURL( 'image/png' );
  12503. }
  12504. }
  12505. var output = {
  12506. metadata: {
  12507. version: 4.4,
  12508. type: 'Texture',
  12509. generator: 'Texture.toJSON'
  12510. },
  12511. uuid: this.uuid,
  12512. name: this.name,
  12513. mapping: this.mapping,
  12514. repeat: [ this.repeat.x, this.repeat.y ],
  12515. offset: [ this.offset.x, this.offset.y ],
  12516. wrap: [ this.wrapS, this.wrapT ],
  12517. minFilter: this.minFilter,
  12518. magFilter: this.magFilter,
  12519. anisotropy: this.anisotropy
  12520. };
  12521. if ( this.image !== undefined ) {
  12522. // TODO: Move to THREE.Image
  12523. var image = this.image;
  12524. if ( image.uuid === undefined ) {
  12525. image.uuid = THREE.Math.generateUUID(); // UGH
  12526. }
  12527. if ( meta.images[ image.uuid ] === undefined ) {
  12528. meta.images[ image.uuid ] = {
  12529. uuid: image.uuid,
  12530. url: getDataURL( image )
  12531. };
  12532. }
  12533. output.image = image.uuid;
  12534. }
  12535. meta.textures[ this.uuid ] = output;
  12536. return output;
  12537. },
  12538. dispose: function () {
  12539. this.dispatchEvent( { type: 'dispose' } );
  12540. },
  12541. transformUv: function ( uv ) {
  12542. if ( this.mapping !== THREE.UVMapping ) return;
  12543. uv.multiply( this.repeat );
  12544. uv.add( this.offset );
  12545. if ( uv.x < 0 || uv.x > 1 ) {
  12546. switch ( this.wrapS ) {
  12547. case THREE.RepeatWrapping:
  12548. uv.x = uv.x - Math.floor( uv.x );
  12549. break;
  12550. case THREE.ClampToEdgeWrapping:
  12551. uv.x = uv.x < 0 ? 0 : 1;
  12552. break;
  12553. case THREE.MirroredRepeatWrapping:
  12554. if ( Math.abs( Math.floor( uv.x ) % 2 ) === 1 ) {
  12555. uv.x = Math.ceil( uv.x ) - uv.x;
  12556. } else {
  12557. uv.x = uv.x - Math.floor( uv.x );
  12558. }
  12559. break;
  12560. }
  12561. }
  12562. if ( uv.y < 0 || uv.y > 1 ) {
  12563. switch ( this.wrapT ) {
  12564. case THREE.RepeatWrapping:
  12565. uv.y = uv.y - Math.floor( uv.y );
  12566. break;
  12567. case THREE.ClampToEdgeWrapping:
  12568. uv.y = uv.y < 0 ? 0 : 1;
  12569. break;
  12570. case THREE.MirroredRepeatWrapping:
  12571. if ( Math.abs( Math.floor( uv.y ) % 2 ) === 1 ) {
  12572. uv.y = Math.ceil( uv.y ) - uv.y;
  12573. } else {
  12574. uv.y = uv.y - Math.floor( uv.y );
  12575. }
  12576. break;
  12577. }
  12578. }
  12579. if ( this.flipY ) {
  12580. uv.y = 1 - uv.y;
  12581. }
  12582. }
  12583. };
  12584. THREE.EventDispatcher.prototype.apply( THREE.Texture.prototype );
  12585. THREE.TextureIdCount = 0;
  12586. // File:src/textures/CanvasTexture.js
  12587. /**
  12588. * @author mrdoob / http://mrdoob.com/
  12589. */
  12590. THREE.CanvasTexture = function ( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  12591. THREE.Texture.call( this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  12592. this.needsUpdate = true;
  12593. };
  12594. THREE.CanvasTexture.prototype = Object.create( THREE.Texture.prototype );
  12595. THREE.CanvasTexture.prototype.constructor = THREE.CanvasTexture;
  12596. // File:src/textures/CubeTexture.js
  12597. /**
  12598. * @author mrdoob / http://mrdoob.com/
  12599. */
  12600. THREE.CubeTexture = function ( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  12601. mapping = mapping !== undefined ? mapping : THREE.CubeReflectionMapping;
  12602. THREE.Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  12603. this.images = images;
  12604. this.flipY = false;
  12605. };
  12606. THREE.CubeTexture.prototype = Object.create( THREE.Texture.prototype );
  12607. THREE.CubeTexture.prototype.constructor = THREE.CubeTexture;
  12608. THREE.CubeTexture.prototype.copy = function ( source ) {
  12609. THREE.Texture.prototype.copy.call( this, source );
  12610. this.images = source.images;
  12611. return this;
  12612. };
  12613. // File:src/textures/CompressedTexture.js
  12614. /**
  12615. * @author alteredq / http://alteredqualia.com/
  12616. */
  12617. THREE.CompressedTexture = function ( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy ) {
  12618. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  12619. this.image = { width: width, height: height };
  12620. this.mipmaps = mipmaps;
  12621. // no flipping for cube textures
  12622. // (also flipping doesn't work for compressed textures )
  12623. this.flipY = false;
  12624. // can't generate mipmaps for compressed textures
  12625. // mips must be embedded in DDS files
  12626. this.generateMipmaps = false;
  12627. };
  12628. THREE.CompressedTexture.prototype = Object.create( THREE.Texture.prototype );
  12629. THREE.CompressedTexture.prototype.constructor = THREE.CompressedTexture;
  12630. // File:src/textures/DataTexture.js
  12631. /**
  12632. * @author alteredq / http://alteredqualia.com/
  12633. */
  12634. THREE.DataTexture = function ( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy ) {
  12635. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  12636. this.image = { data: data, width: width, height: height };
  12637. this.magFilter = magFilter !== undefined ? magFilter : THREE.NearestFilter;
  12638. this.minFilter = minFilter !== undefined ? minFilter : THREE.NearestFilter;
  12639. this.flipY = false;
  12640. this.generateMipmaps = false;
  12641. };
  12642. THREE.DataTexture.prototype = Object.create( THREE.Texture.prototype );
  12643. THREE.DataTexture.prototype.constructor = THREE.DataTexture;
  12644. // File:src/textures/VideoTexture.js
  12645. /**
  12646. * @author mrdoob / http://mrdoob.com/
  12647. */
  12648. THREE.VideoTexture = function ( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  12649. THREE.Texture.call( this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  12650. this.generateMipmaps = false;
  12651. var scope = this;
  12652. function update() {
  12653. requestAnimationFrame( update );
  12654. if ( video.readyState === video.HAVE_ENOUGH_DATA ) {
  12655. scope.needsUpdate = true;
  12656. }
  12657. }
  12658. update();
  12659. };
  12660. THREE.VideoTexture.prototype = Object.create( THREE.Texture.prototype );
  12661. THREE.VideoTexture.prototype.constructor = THREE.VideoTexture;
  12662. // File:src/objects/Group.js
  12663. /**
  12664. * @author mrdoob / http://mrdoob.com/
  12665. */
  12666. THREE.Group = function () {
  12667. THREE.Object3D.call( this );
  12668. this.type = 'Group';
  12669. };
  12670. THREE.Group.prototype = Object.create( THREE.Object3D.prototype );
  12671. THREE.Group.prototype.constructor = THREE.Group;
  12672. // File:src/objects/Points.js
  12673. /**
  12674. * @author alteredq / http://alteredqualia.com/
  12675. */
  12676. THREE.Points = function ( geometry, material ) {
  12677. THREE.Object3D.call( this );
  12678. this.type = 'Points';
  12679. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  12680. this.material = material !== undefined ? material : new THREE.PointsMaterial( { color: Math.random() * 0xffffff } );
  12681. };
  12682. THREE.Points.prototype = Object.create( THREE.Object3D.prototype );
  12683. THREE.Points.prototype.constructor = THREE.Points;
  12684. THREE.Points.prototype.raycast = ( function () {
  12685. var inverseMatrix = new THREE.Matrix4();
  12686. var ray = new THREE.Ray();
  12687. return function raycast( raycaster, intersects ) {
  12688. var object = this;
  12689. var geometry = object.geometry;
  12690. var threshold = raycaster.params.Points.threshold;
  12691. inverseMatrix.getInverse( this.matrixWorld );
  12692. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  12693. if ( geometry.boundingBox !== null ) {
  12694. if ( ray.intersectsBox( geometry.boundingBox ) === false ) return;
  12695. }
  12696. var localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  12697. var localThresholdSq = localThreshold * localThreshold;
  12698. var position = new THREE.Vector3();
  12699. function testPoint( point, index ) {
  12700. var rayPointDistanceSq = ray.distanceSqToPoint( point );
  12701. if ( rayPointDistanceSq < localThresholdSq ) {
  12702. var intersectPoint = ray.closestPointToPoint( point );
  12703. intersectPoint.applyMatrix4( object.matrixWorld );
  12704. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  12705. if ( distance < raycaster.near || distance > raycaster.far ) return;
  12706. intersects.push( {
  12707. distance: distance,
  12708. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  12709. point: intersectPoint.clone(),
  12710. index: index,
  12711. face: null,
  12712. object: object
  12713. } );
  12714. }
  12715. }
  12716. if ( geometry instanceof THREE.BufferGeometry ) {
  12717. var index = geometry.index;
  12718. var attributes = geometry.attributes;
  12719. var positions = attributes.position.array;
  12720. if ( index !== null ) {
  12721. var indices = index.array;
  12722. for ( var i = 0, il = indices.length; i < il; i ++ ) {
  12723. var a = indices[ i ];
  12724. position.fromArray( positions, a * 3 );
  12725. testPoint( position, a );
  12726. }
  12727. } else {
  12728. for ( var i = 0, l = positions.length / 3; i < l; i ++ ) {
  12729. position.fromArray( positions, i * 3 );
  12730. testPoint( position, i );
  12731. }
  12732. }
  12733. } else {
  12734. var vertices = geometry.vertices;
  12735. for ( var i = 0, l = vertices.length; i < l; i ++ ) {
  12736. testPoint( vertices[ i ], i );
  12737. }
  12738. }
  12739. };
  12740. }() );
  12741. THREE.Points.prototype.clone = function () {
  12742. return new this.constructor( this.geometry, this.material ).copy( this );
  12743. };
  12744. // File:src/objects/Line.js
  12745. /**
  12746. * @author mrdoob / http://mrdoob.com/
  12747. */
  12748. THREE.Line = function ( geometry, material, mode ) {
  12749. if ( mode === 1 ) {
  12750. console.warn( 'THREE.Line: parameter THREE.LinePieces no longer supported. Created THREE.LineSegments instead.' );
  12751. return new THREE.LineSegments( geometry, material );
  12752. }
  12753. THREE.Object3D.call( this );
  12754. this.type = 'Line';
  12755. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  12756. this.material = material !== undefined ? material : new THREE.LineBasicMaterial( { color: Math.random() * 0xffffff } );
  12757. };
  12758. THREE.Line.prototype = Object.create( THREE.Object3D.prototype );
  12759. THREE.Line.prototype.constructor = THREE.Line;
  12760. THREE.Line.prototype.raycast = ( function () {
  12761. var inverseMatrix = new THREE.Matrix4();
  12762. var ray = new THREE.Ray();
  12763. var sphere = new THREE.Sphere();
  12764. return function raycast( raycaster, intersects ) {
  12765. var precision = raycaster.linePrecision;
  12766. var precisionSq = precision * precision;
  12767. var geometry = this.geometry;
  12768. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  12769. // Checking boundingSphere distance to ray
  12770. sphere.copy( geometry.boundingSphere );
  12771. sphere.applyMatrix4( this.matrixWorld );
  12772. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  12773. inverseMatrix.getInverse( this.matrixWorld );
  12774. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  12775. var vStart = new THREE.Vector3();
  12776. var vEnd = new THREE.Vector3();
  12777. var interSegment = new THREE.Vector3();
  12778. var interRay = new THREE.Vector3();
  12779. var step = this instanceof THREE.LineSegments ? 2 : 1;
  12780. if ( geometry instanceof THREE.BufferGeometry ) {
  12781. var index = geometry.index;
  12782. var attributes = geometry.attributes;
  12783. if ( index !== null ) {
  12784. var indices = index.array;
  12785. var positions = attributes.position.array;
  12786. for ( var i = 0, l = indices.length - 1; i < l; i += step ) {
  12787. var a = indices[ i ];
  12788. var b = indices[ i + 1 ];
  12789. vStart.fromArray( positions, a * 3 );
  12790. vEnd.fromArray( positions, b * 3 );
  12791. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  12792. if ( distSq > precisionSq ) continue;
  12793. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  12794. var distance = raycaster.ray.origin.distanceTo( interRay );
  12795. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  12796. intersects.push( {
  12797. distance: distance,
  12798. // What do we want? intersection point on the ray or on the segment??
  12799. // point: raycaster.ray.at( distance ),
  12800. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  12801. index: i,
  12802. face: null,
  12803. faceIndex: null,
  12804. object: this
  12805. } );
  12806. }
  12807. } else {
  12808. var positions = attributes.position.array;
  12809. for ( var i = 0, l = positions.length / 3 - 1; i < l; i += step ) {
  12810. vStart.fromArray( positions, 3 * i );
  12811. vEnd.fromArray( positions, 3 * i + 3 );
  12812. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  12813. if ( distSq > precisionSq ) continue;
  12814. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  12815. var distance = raycaster.ray.origin.distanceTo( interRay );
  12816. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  12817. intersects.push( {
  12818. distance: distance,
  12819. // What do we want? intersection point on the ray or on the segment??
  12820. // point: raycaster.ray.at( distance ),
  12821. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  12822. index: i,
  12823. face: null,
  12824. faceIndex: null,
  12825. object: this
  12826. } );
  12827. }
  12828. }
  12829. } else if ( geometry instanceof THREE.Geometry ) {
  12830. var vertices = geometry.vertices;
  12831. var nbVertices = vertices.length;
  12832. for ( var i = 0; i < nbVertices - 1; i += step ) {
  12833. var distSq = ray.distanceSqToSegment( vertices[ i ], vertices[ i + 1 ], interRay, interSegment );
  12834. if ( distSq > precisionSq ) continue;
  12835. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  12836. var distance = raycaster.ray.origin.distanceTo( interRay );
  12837. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  12838. intersects.push( {
  12839. distance: distance,
  12840. // What do we want? intersection point on the ray or on the segment??
  12841. // point: raycaster.ray.at( distance ),
  12842. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  12843. index: i,
  12844. face: null,
  12845. faceIndex: null,
  12846. object: this
  12847. } );
  12848. }
  12849. }
  12850. };
  12851. }() );
  12852. THREE.Line.prototype.clone = function () {
  12853. return new this.constructor( this.geometry, this.material ).copy( this );
  12854. };
  12855. // DEPRECATED
  12856. THREE.LineStrip = 0;
  12857. THREE.LinePieces = 1;
  12858. // File:src/objects/LineSegments.js
  12859. /**
  12860. * @author mrdoob / http://mrdoob.com/
  12861. */
  12862. THREE.LineSegments = function ( geometry, material ) {
  12863. THREE.Line.call( this, geometry, material );
  12864. this.type = 'LineSegments';
  12865. };
  12866. THREE.LineSegments.prototype = Object.create( THREE.Line.prototype );
  12867. THREE.LineSegments.prototype.constructor = THREE.LineSegments;
  12868. // File:src/objects/Mesh.js
  12869. /**
  12870. * @author mrdoob / http://mrdoob.com/
  12871. * @author alteredq / http://alteredqualia.com/
  12872. * @author mikael emtinger / http://gomo.se/
  12873. * @author jonobr1 / http://jonobr1.com/
  12874. */
  12875. THREE.Mesh = function ( geometry, material ) {
  12876. THREE.Object3D.call( this );
  12877. this.type = 'Mesh';
  12878. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  12879. this.material = material !== undefined ? material : new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff } );
  12880. this.drawMode = THREE.TrianglesDrawMode;
  12881. this.updateMorphTargets();
  12882. };
  12883. THREE.Mesh.prototype = Object.create( THREE.Object3D.prototype );
  12884. THREE.Mesh.prototype.constructor = THREE.Mesh;
  12885. THREE.Mesh.prototype.setDrawMode = function ( value ) {
  12886. this.drawMode = value;
  12887. };
  12888. THREE.Mesh.prototype.updateMorphTargets = function () {
  12889. if ( this.geometry.morphTargets !== undefined && this.geometry.morphTargets.length > 0 ) {
  12890. this.morphTargetBase = - 1;
  12891. this.morphTargetInfluences = [];
  12892. this.morphTargetDictionary = {};
  12893. for ( var m = 0, ml = this.geometry.morphTargets.length; m < ml; m ++ ) {
  12894. this.morphTargetInfluences.push( 0 );
  12895. this.morphTargetDictionary[ this.geometry.morphTargets[ m ].name ] = m;
  12896. }
  12897. }
  12898. };
  12899. THREE.Mesh.prototype.getMorphTargetIndexByName = function ( name ) {
  12900. if ( this.morphTargetDictionary[ name ] !== undefined ) {
  12901. return this.morphTargetDictionary[ name ];
  12902. }
  12903. console.warn( 'THREE.Mesh.getMorphTargetIndexByName: morph target ' + name + ' does not exist. Returning 0.' );
  12904. return 0;
  12905. };
  12906. THREE.Mesh.prototype.raycast = ( function () {
  12907. var inverseMatrix = new THREE.Matrix4();
  12908. var ray = new THREE.Ray();
  12909. var sphere = new THREE.Sphere();
  12910. var vA = new THREE.Vector3();
  12911. var vB = new THREE.Vector3();
  12912. var vC = new THREE.Vector3();
  12913. var tempA = new THREE.Vector3();
  12914. var tempB = new THREE.Vector3();
  12915. var tempC = new THREE.Vector3();
  12916. var uvA = new THREE.Vector2();
  12917. var uvB = new THREE.Vector2();
  12918. var uvC = new THREE.Vector2();
  12919. var barycoord = new THREE.Vector3();
  12920. var intersectionPoint = new THREE.Vector3();
  12921. var intersectionPointWorld = new THREE.Vector3();
  12922. function uvIntersection( point, p1, p2, p3, uv1, uv2, uv3 ) {
  12923. THREE.Triangle.barycoordFromPoint( point, p1, p2, p3, barycoord );
  12924. uv1.multiplyScalar( barycoord.x );
  12925. uv2.multiplyScalar( barycoord.y );
  12926. uv3.multiplyScalar( barycoord.z );
  12927. uv1.add( uv2 ).add( uv3 );
  12928. return uv1.clone();
  12929. }
  12930. function checkIntersection( object, raycaster, ray, pA, pB, pC, point ){
  12931. var intersect;
  12932. var material = object.material;
  12933. if ( material.side === THREE.BackSide ) {
  12934. intersect = ray.intersectTriangle( pC, pB, pA, true, point );
  12935. } else {
  12936. intersect = ray.intersectTriangle( pA, pB, pC, material.side !== THREE.DoubleSide, point );
  12937. }
  12938. if ( intersect === null ) return null;
  12939. intersectionPointWorld.copy( point );
  12940. intersectionPointWorld.applyMatrix4( object.matrixWorld );
  12941. var distance = raycaster.ray.origin.distanceTo( intersectionPointWorld );
  12942. if ( distance < raycaster.near || distance > raycaster.far ) return null;
  12943. return {
  12944. distance: distance,
  12945. point: intersectionPointWorld.clone(),
  12946. object: object
  12947. };
  12948. }
  12949. function checkBufferGeometryIntersection( object, raycaster, ray, positions, uvs, a, b, c ) {
  12950. vA.fromArray( positions, a * 3 );
  12951. vB.fromArray( positions, b * 3 );
  12952. vC.fromArray( positions, c * 3 );
  12953. var intersection = checkIntersection( object, raycaster, ray, vA, vB, vC, intersectionPoint );
  12954. if ( intersection ) {
  12955. if ( uvs ) {
  12956. uvA.fromArray( uvs, a * 2 );
  12957. uvB.fromArray( uvs, b * 2 );
  12958. uvC.fromArray( uvs, c * 2 );
  12959. intersection.uv = uvIntersection( intersectionPoint, vA, vB, vC, uvA, uvB, uvC );
  12960. }
  12961. intersection.face = new THREE.Face3( a, b, c, THREE.Triangle.normal( vA, vB, vC ) );
  12962. intersection.faceIndex = a;
  12963. }
  12964. return intersection;
  12965. }
  12966. return function raycast( raycaster, intersects ) {
  12967. var geometry = this.geometry;
  12968. var material = this.material;
  12969. if ( material === undefined ) return;
  12970. // Checking boundingSphere distance to ray
  12971. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  12972. var matrixWorld = this.matrixWorld;
  12973. sphere.copy( geometry.boundingSphere );
  12974. sphere.applyMatrix4( matrixWorld );
  12975. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  12976. // Check boundingBox before continuing
  12977. inverseMatrix.getInverse( matrixWorld );
  12978. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  12979. if ( geometry.boundingBox !== null ) {
  12980. if ( ray.intersectsBox( geometry.boundingBox ) === false ) return;
  12981. }
  12982. var uvs, intersection;
  12983. if ( geometry instanceof THREE.BufferGeometry ) {
  12984. var a, b, c;
  12985. var index = geometry.index;
  12986. var attributes = geometry.attributes;
  12987. var positions = attributes.position.array;
  12988. if ( attributes.uv !== undefined ){
  12989. uvs = attributes.uv.array;
  12990. }
  12991. if ( index !== null ) {
  12992. var indices = index.array;
  12993. for ( var i = 0, l = indices.length; i < l; i += 3 ) {
  12994. a = indices[ i ];
  12995. b = indices[ i + 1 ];
  12996. c = indices[ i + 2 ];
  12997. intersection = checkBufferGeometryIntersection( this, raycaster, ray, positions, uvs, a, b, c );
  12998. if ( intersection ) {
  12999. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in indices buffer semantics
  13000. intersects.push( intersection );
  13001. }
  13002. }
  13003. } else {
  13004. for ( var i = 0, l = positions.length; i < l; i += 9 ) {
  13005. a = i / 3;
  13006. b = a + 1;
  13007. c = a + 2;
  13008. intersection = checkBufferGeometryIntersection( this, raycaster, ray, positions, uvs, a, b, c );
  13009. if ( intersection ) {
  13010. intersection.index = a; // triangle number in positions buffer semantics
  13011. intersects.push( intersection );
  13012. }
  13013. }
  13014. }
  13015. } else if ( geometry instanceof THREE.Geometry ) {
  13016. var fvA, fvB, fvC;
  13017. var isFaceMaterial = material instanceof THREE.MeshFaceMaterial;
  13018. var materials = isFaceMaterial === true ? material.materials : null;
  13019. var vertices = geometry.vertices;
  13020. var faces = geometry.faces;
  13021. var faceVertexUvs = geometry.faceVertexUvs[ 0 ];
  13022. if ( faceVertexUvs.length > 0 ) uvs = faceVertexUvs;
  13023. for ( var f = 0, fl = faces.length; f < fl; f ++ ) {
  13024. var face = faces[ f ];
  13025. var faceMaterial = isFaceMaterial === true ? materials[ face.materialIndex ] : material;
  13026. if ( faceMaterial === undefined ) continue;
  13027. fvA = vertices[ face.a ];
  13028. fvB = vertices[ face.b ];
  13029. fvC = vertices[ face.c ];
  13030. if ( faceMaterial.morphTargets === true ) {
  13031. var morphTargets = geometry.morphTargets;
  13032. var morphInfluences = this.morphTargetInfluences;
  13033. vA.set( 0, 0, 0 );
  13034. vB.set( 0, 0, 0 );
  13035. vC.set( 0, 0, 0 );
  13036. for ( var t = 0, tl = morphTargets.length; t < tl; t ++ ) {
  13037. var influence = morphInfluences[ t ];
  13038. if ( influence === 0 ) continue;
  13039. var targets = morphTargets[ t ].vertices;
  13040. vA.addScaledVector( tempA.subVectors( targets[ face.a ], fvA ), influence );
  13041. vB.addScaledVector( tempB.subVectors( targets[ face.b ], fvB ), influence );
  13042. vC.addScaledVector( tempC.subVectors( targets[ face.c ], fvC ), influence );
  13043. }
  13044. vA.add( fvA );
  13045. vB.add( fvB );
  13046. vC.add( fvC );
  13047. fvA = vA;
  13048. fvB = vB;
  13049. fvC = vC;
  13050. }
  13051. intersection = checkIntersection( this, raycaster, ray, fvA, fvB, fvC, intersectionPoint );
  13052. if ( intersection ) {
  13053. if ( uvs ) {
  13054. var uvs_f = uvs[ f ];
  13055. uvA.copy( uvs_f[ 0 ] );
  13056. uvB.copy( uvs_f[ 1 ] );
  13057. uvC.copy( uvs_f[ 2 ] );
  13058. intersection.uv = uvIntersection( intersectionPoint, fvA, fvB, fvC, uvA, uvB, uvC );
  13059. }
  13060. intersection.face = face;
  13061. intersection.faceIndex = f;
  13062. intersects.push( intersection );
  13063. }
  13064. }
  13065. }
  13066. };
  13067. }() );
  13068. THREE.Mesh.prototype.clone = function () {
  13069. return new this.constructor( this.geometry, this.material ).copy( this );
  13070. };
  13071. // File:src/objects/Bone.js
  13072. /**
  13073. * @author mikael emtinger / http://gomo.se/
  13074. * @author alteredq / http://alteredqualia.com/
  13075. * @author ikerr / http://verold.com
  13076. */
  13077. THREE.Bone = function ( skin ) {
  13078. THREE.Object3D.call( this );
  13079. this.type = 'Bone';
  13080. this.skin = skin;
  13081. };
  13082. THREE.Bone.prototype = Object.create( THREE.Object3D.prototype );
  13083. THREE.Bone.prototype.constructor = THREE.Bone;
  13084. THREE.Bone.prototype.copy = function ( source ) {
  13085. THREE.Object3D.prototype.copy.call( this, source );
  13086. this.skin = source.skin;
  13087. return this;
  13088. };
  13089. // File:src/objects/Skeleton.js
  13090. /**
  13091. * @author mikael emtinger / http://gomo.se/
  13092. * @author alteredq / http://alteredqualia.com/
  13093. * @author michael guerrero / http://realitymeltdown.com
  13094. * @author ikerr / http://verold.com
  13095. */
  13096. THREE.Skeleton = function ( bones, boneInverses, useVertexTexture ) {
  13097. this.useVertexTexture = useVertexTexture !== undefined ? useVertexTexture : true;
  13098. this.identityMatrix = new THREE.Matrix4();
  13099. // copy the bone array
  13100. bones = bones || [];
  13101. this.bones = bones.slice( 0 );
  13102. // create a bone texture or an array of floats
  13103. if ( this.useVertexTexture ) {
  13104. // layout (1 matrix = 4 pixels)
  13105. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  13106. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  13107. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  13108. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  13109. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  13110. var size = Math.sqrt( this.bones.length * 4 ); // 4 pixels needed for 1 matrix
  13111. size = THREE.Math.nextPowerOfTwo( Math.ceil( size ) );
  13112. size = Math.max( size, 4 );
  13113. this.boneTextureWidth = size;
  13114. this.boneTextureHeight = size;
  13115. this.boneMatrices = new Float32Array( this.boneTextureWidth * this.boneTextureHeight * 4 ); // 4 floats per RGBA pixel
  13116. this.boneTexture = new THREE.DataTexture( this.boneMatrices, this.boneTextureWidth, this.boneTextureHeight, THREE.RGBAFormat, THREE.FloatType );
  13117. } else {
  13118. this.boneMatrices = new Float32Array( 16 * this.bones.length );
  13119. }
  13120. // use the supplied bone inverses or calculate the inverses
  13121. if ( boneInverses === undefined ) {
  13122. this.calculateInverses();
  13123. } else {
  13124. if ( this.bones.length === boneInverses.length ) {
  13125. this.boneInverses = boneInverses.slice( 0 );
  13126. } else {
  13127. console.warn( 'THREE.Skeleton bonInverses is the wrong length.' );
  13128. this.boneInverses = [];
  13129. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13130. this.boneInverses.push( new THREE.Matrix4() );
  13131. }
  13132. }
  13133. }
  13134. };
  13135. THREE.Skeleton.prototype.calculateInverses = function () {
  13136. this.boneInverses = [];
  13137. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13138. var inverse = new THREE.Matrix4();
  13139. if ( this.bones[ b ] ) {
  13140. inverse.getInverse( this.bones[ b ].matrixWorld );
  13141. }
  13142. this.boneInverses.push( inverse );
  13143. }
  13144. };
  13145. THREE.Skeleton.prototype.pose = function () {
  13146. var bone;
  13147. // recover the bind-time world matrices
  13148. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13149. bone = this.bones[ b ];
  13150. if ( bone ) {
  13151. bone.matrixWorld.getInverse( this.boneInverses[ b ] );
  13152. }
  13153. }
  13154. // compute the local matrices, positions, rotations and scales
  13155. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13156. bone = this.bones[ b ];
  13157. if ( bone ) {
  13158. if ( bone.parent ) {
  13159. bone.matrix.getInverse( bone.parent.matrixWorld );
  13160. bone.matrix.multiply( bone.matrixWorld );
  13161. } else {
  13162. bone.matrix.copy( bone.matrixWorld );
  13163. }
  13164. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  13165. }
  13166. }
  13167. };
  13168. THREE.Skeleton.prototype.update = ( function () {
  13169. var offsetMatrix = new THREE.Matrix4();
  13170. return function update() {
  13171. // flatten bone matrices to array
  13172. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13173. // compute the offset between the current and the original transform
  13174. var matrix = this.bones[ b ] ? this.bones[ b ].matrixWorld : this.identityMatrix;
  13175. offsetMatrix.multiplyMatrices( matrix, this.boneInverses[ b ] );
  13176. offsetMatrix.flattenToArrayOffset( this.boneMatrices, b * 16 );
  13177. }
  13178. if ( this.useVertexTexture ) {
  13179. this.boneTexture.needsUpdate = true;
  13180. }
  13181. };
  13182. } )();
  13183. THREE.Skeleton.prototype.clone = function () {
  13184. return new THREE.Skeleton( this.bones, this.boneInverses, this.useVertexTexture );
  13185. };
  13186. // File:src/objects/SkinnedMesh.js
  13187. /**
  13188. * @author mikael emtinger / http://gomo.se/
  13189. * @author alteredq / http://alteredqualia.com/
  13190. * @author ikerr / http://verold.com
  13191. */
  13192. THREE.SkinnedMesh = function ( geometry, material, useVertexTexture ) {
  13193. THREE.Mesh.call( this, geometry, material );
  13194. this.type = 'SkinnedMesh';
  13195. this.bindMode = "attached";
  13196. this.bindMatrix = new THREE.Matrix4();
  13197. this.bindMatrixInverse = new THREE.Matrix4();
  13198. // init bones
  13199. // TODO: remove bone creation as there is no reason (other than
  13200. // convenience) for THREE.SkinnedMesh to do this.
  13201. var bones = [];
  13202. if ( this.geometry && this.geometry.bones !== undefined ) {
  13203. var bone, gbone;
  13204. for ( var b = 0, bl = this.geometry.bones.length; b < bl; ++ b ) {
  13205. gbone = this.geometry.bones[ b ];
  13206. bone = new THREE.Bone( this );
  13207. bones.push( bone );
  13208. bone.name = gbone.name;
  13209. bone.position.fromArray( gbone.pos );
  13210. bone.quaternion.fromArray( gbone.rotq );
  13211. if ( gbone.scl !== undefined ) bone.scale.fromArray( gbone.scl );
  13212. }
  13213. for ( var b = 0, bl = this.geometry.bones.length; b < bl; ++ b ) {
  13214. gbone = this.geometry.bones[ b ];
  13215. if ( gbone.parent !== - 1 && gbone.parent !== null) {
  13216. bones[ gbone.parent ].add( bones[ b ] );
  13217. } else {
  13218. this.add( bones[ b ] );
  13219. }
  13220. }
  13221. }
  13222. this.normalizeSkinWeights();
  13223. this.updateMatrixWorld( true );
  13224. this.bind( new THREE.Skeleton( bones, undefined, useVertexTexture ), this.matrixWorld );
  13225. };
  13226. THREE.SkinnedMesh.prototype = Object.create( THREE.Mesh.prototype );
  13227. THREE.SkinnedMesh.prototype.constructor = THREE.SkinnedMesh;
  13228. THREE.SkinnedMesh.prototype.bind = function( skeleton, bindMatrix ) {
  13229. this.skeleton = skeleton;
  13230. if ( bindMatrix === undefined ) {
  13231. this.updateMatrixWorld( true );
  13232. this.skeleton.calculateInverses();
  13233. bindMatrix = this.matrixWorld;
  13234. }
  13235. this.bindMatrix.copy( bindMatrix );
  13236. this.bindMatrixInverse.getInverse( bindMatrix );
  13237. };
  13238. THREE.SkinnedMesh.prototype.pose = function () {
  13239. this.skeleton.pose();
  13240. };
  13241. THREE.SkinnedMesh.prototype.normalizeSkinWeights = function () {
  13242. if ( this.geometry instanceof THREE.Geometry ) {
  13243. for ( var i = 0; i < this.geometry.skinIndices.length; i ++ ) {
  13244. var sw = this.geometry.skinWeights[ i ];
  13245. var scale = 1.0 / sw.lengthManhattan();
  13246. if ( scale !== Infinity ) {
  13247. sw.multiplyScalar( scale );
  13248. } else {
  13249. sw.set( 1 ); // this will be normalized by the shader anyway
  13250. }
  13251. }
  13252. } else {
  13253. // skinning weights assumed to be normalized for THREE.BufferGeometry
  13254. }
  13255. };
  13256. THREE.SkinnedMesh.prototype.updateMatrixWorld = function( force ) {
  13257. THREE.Mesh.prototype.updateMatrixWorld.call( this, true );
  13258. if ( this.bindMode === "attached" ) {
  13259. this.bindMatrixInverse.getInverse( this.matrixWorld );
  13260. } else if ( this.bindMode === "detached" ) {
  13261. this.bindMatrixInverse.getInverse( this.bindMatrix );
  13262. } else {
  13263. console.warn( 'THREE.SkinnedMesh unrecognized bindMode: ' + this.bindMode );
  13264. }
  13265. };
  13266. THREE.SkinnedMesh.prototype.clone = function() {
  13267. return new this.constructor( this.geometry, this.material, this.useVertexTexture ).copy( this );
  13268. };
  13269. // File:src/objects/LOD.js
  13270. /**
  13271. * @author mikael emtinger / http://gomo.se/
  13272. * @author alteredq / http://alteredqualia.com/
  13273. * @author mrdoob / http://mrdoob.com/
  13274. */
  13275. THREE.LOD = function () {
  13276. THREE.Object3D.call( this );
  13277. this.type = 'LOD';
  13278. Object.defineProperties( this, {
  13279. levels: {
  13280. enumerable: true,
  13281. value: []
  13282. },
  13283. objects: {
  13284. get: function () {
  13285. console.warn( 'THREE.LOD: .objects has been renamed to .levels.' );
  13286. return this.levels;
  13287. }
  13288. }
  13289. } );
  13290. };
  13291. THREE.LOD.prototype = Object.create( THREE.Object3D.prototype );
  13292. THREE.LOD.prototype.constructor = THREE.LOD;
  13293. THREE.LOD.prototype.addLevel = function ( object, distance ) {
  13294. if ( distance === undefined ) distance = 0;
  13295. distance = Math.abs( distance );
  13296. var levels = this.levels;
  13297. for ( var l = 0; l < levels.length; l ++ ) {
  13298. if ( distance < levels[ l ].distance ) {
  13299. break;
  13300. }
  13301. }
  13302. levels.splice( l, 0, { distance: distance, object: object } );
  13303. this.add( object );
  13304. };
  13305. THREE.LOD.prototype.getObjectForDistance = function ( distance ) {
  13306. var levels = this.levels;
  13307. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  13308. if ( distance < levels[ i ].distance ) {
  13309. break;
  13310. }
  13311. }
  13312. return levels[ i - 1 ].object;
  13313. };
  13314. THREE.LOD.prototype.raycast = ( function () {
  13315. var matrixPosition = new THREE.Vector3();
  13316. return function raycast( raycaster, intersects ) {
  13317. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  13318. var distance = raycaster.ray.origin.distanceTo( matrixPosition );
  13319. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  13320. };
  13321. }() );
  13322. THREE.LOD.prototype.update = function () {
  13323. var v1 = new THREE.Vector3();
  13324. var v2 = new THREE.Vector3();
  13325. return function update( camera ) {
  13326. var levels = this.levels;
  13327. if ( levels.length > 1 ) {
  13328. v1.setFromMatrixPosition( camera.matrixWorld );
  13329. v2.setFromMatrixPosition( this.matrixWorld );
  13330. var distance = v1.distanceTo( v2 );
  13331. levels[ 0 ].object.visible = true;
  13332. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  13333. if ( distance >= levels[ i ].distance ) {
  13334. levels[ i - 1 ].object.visible = false;
  13335. levels[ i ].object.visible = true;
  13336. } else {
  13337. break;
  13338. }
  13339. }
  13340. for ( ; i < l; i ++ ) {
  13341. levels[ i ].object.visible = false;
  13342. }
  13343. }
  13344. };
  13345. }();
  13346. THREE.LOD.prototype.copy = function ( source ) {
  13347. THREE.Object3D.prototype.copy.call( this, source, false );
  13348. var levels = source.levels;
  13349. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  13350. var level = levels[ i ];
  13351. this.addLevel( level.object.clone(), level.distance );
  13352. }
  13353. return this;
  13354. };
  13355. THREE.LOD.prototype.toJSON = function ( meta ) {
  13356. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  13357. data.object.levels = [];
  13358. var levels = this.levels;
  13359. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  13360. var level = levels[ i ];
  13361. data.object.levels.push( {
  13362. object: level.object.uuid,
  13363. distance: level.distance
  13364. } );
  13365. }
  13366. return data;
  13367. };
  13368. // File:src/objects/Sprite.js
  13369. /**
  13370. * @author mikael emtinger / http://gomo.se/
  13371. * @author alteredq / http://alteredqualia.com/
  13372. */
  13373. THREE.Sprite = ( function () {
  13374. var indices = new Uint16Array( [ 0, 1, 2, 0, 2, 3 ] );
  13375. var vertices = new Float32Array( [ - 0.5, - 0.5, 0, 0.5, - 0.5, 0, 0.5, 0.5, 0, - 0.5, 0.5, 0 ] );
  13376. var uvs = new Float32Array( [ 0, 0, 1, 0, 1, 1, 0, 1 ] );
  13377. var geometry = new THREE.BufferGeometry();
  13378. geometry.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  13379. geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  13380. geometry.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  13381. return function Sprite( material ) {
  13382. THREE.Object3D.call( this );
  13383. this.type = 'Sprite';
  13384. this.geometry = geometry;
  13385. this.material = ( material !== undefined ) ? material : new THREE.SpriteMaterial();
  13386. };
  13387. } )();
  13388. THREE.Sprite.prototype = Object.create( THREE.Object3D.prototype );
  13389. THREE.Sprite.prototype.constructor = THREE.Sprite;
  13390. THREE.Sprite.prototype.raycast = ( function () {
  13391. var matrixPosition = new THREE.Vector3();
  13392. return function raycast( raycaster, intersects ) {
  13393. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  13394. var distanceSq = raycaster.ray.distanceSqToPoint( matrixPosition );
  13395. var guessSizeSq = this.scale.x * this.scale.y;
  13396. if ( distanceSq > guessSizeSq ) {
  13397. return;
  13398. }
  13399. intersects.push( {
  13400. distance: Math.sqrt( distanceSq ),
  13401. point: this.position,
  13402. face: null,
  13403. object: this
  13404. } );
  13405. };
  13406. }() );
  13407. THREE.Sprite.prototype.clone = function () {
  13408. return new this.constructor( this.material ).copy( this );
  13409. };
  13410. // Backwards compatibility
  13411. THREE.Particle = THREE.Sprite;
  13412. // File:src/objects/LensFlare.js
  13413. /**
  13414. * @author mikael emtinger / http://gomo.se/
  13415. * @author alteredq / http://alteredqualia.com/
  13416. */
  13417. THREE.LensFlare = function ( texture, size, distance, blending, color ) {
  13418. THREE.Object3D.call( this );
  13419. this.lensFlares = [];
  13420. this.positionScreen = new THREE.Vector3();
  13421. this.customUpdateCallback = undefined;
  13422. if ( texture !== undefined ) {
  13423. this.add( texture, size, distance, blending, color );
  13424. }
  13425. };
  13426. THREE.LensFlare.prototype = Object.create( THREE.Object3D.prototype );
  13427. THREE.LensFlare.prototype.constructor = THREE.LensFlare;
  13428. /*
  13429. * Add: adds another flare
  13430. */
  13431. THREE.LensFlare.prototype.add = function ( texture, size, distance, blending, color, opacity ) {
  13432. if ( size === undefined ) size = - 1;
  13433. if ( distance === undefined ) distance = 0;
  13434. if ( opacity === undefined ) opacity = 1;
  13435. if ( color === undefined ) color = new THREE.Color( 0xffffff );
  13436. if ( blending === undefined ) blending = THREE.NormalBlending;
  13437. distance = Math.min( distance, Math.max( 0, distance ) );
  13438. this.lensFlares.push( {
  13439. texture: texture, // THREE.Texture
  13440. size: size, // size in pixels (-1 = use texture.width)
  13441. distance: distance, // distance (0-1) from light source (0=at light source)
  13442. x: 0, y: 0, z: 0, // screen position (-1 => 1) z = 0 is in front z = 1 is back
  13443. scale: 1, // scale
  13444. rotation: 0, // rotation
  13445. opacity: opacity, // opacity
  13446. color: color, // color
  13447. blending: blending // blending
  13448. } );
  13449. };
  13450. /*
  13451. * Update lens flares update positions on all flares based on the screen position
  13452. * Set myLensFlare.customUpdateCallback to alter the flares in your project specific way.
  13453. */
  13454. THREE.LensFlare.prototype.updateLensFlares = function () {
  13455. var f, fl = this.lensFlares.length;
  13456. var flare;
  13457. var vecX = - this.positionScreen.x * 2;
  13458. var vecY = - this.positionScreen.y * 2;
  13459. for ( f = 0; f < fl; f ++ ) {
  13460. flare = this.lensFlares[ f ];
  13461. flare.x = this.positionScreen.x + vecX * flare.distance;
  13462. flare.y = this.positionScreen.y + vecY * flare.distance;
  13463. flare.wantedRotation = flare.x * Math.PI * 0.25;
  13464. flare.rotation += ( flare.wantedRotation - flare.rotation ) * 0.25;
  13465. }
  13466. };
  13467. THREE.LensFlare.prototype.copy = function ( source ) {
  13468. THREE.Object3D.prototype.copy.call( this, source );
  13469. this.positionScreen.copy( source.positionScreen );
  13470. this.customUpdateCallback = source.customUpdateCallback;
  13471. for ( var i = 0, l = source.lensFlares.length; i < l; i ++ ) {
  13472. this.lensFlares.push( source.lensFlares[ i ] );
  13473. }
  13474. return this;
  13475. };
  13476. // File:src/scenes/Scene.js
  13477. /**
  13478. * @author mrdoob / http://mrdoob.com/
  13479. */
  13480. THREE.Scene = function () {
  13481. THREE.Object3D.call( this );
  13482. this.type = 'Scene';
  13483. this.fog = null;
  13484. this.overrideMaterial = null;
  13485. this.autoUpdate = true; // checked by the renderer
  13486. };
  13487. THREE.Scene.prototype = Object.create( THREE.Object3D.prototype );
  13488. THREE.Scene.prototype.constructor = THREE.Scene;
  13489. THREE.Scene.prototype.copy = function ( source ) {
  13490. THREE.Object3D.prototype.copy.call( this, source );
  13491. if ( source.fog !== null ) this.fog = source.fog.clone();
  13492. if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
  13493. this.autoUpdate = source.autoUpdate;
  13494. this.matrixAutoUpdate = source.matrixAutoUpdate;
  13495. return this;
  13496. };
  13497. // File:src/scenes/Fog.js
  13498. /**
  13499. * @author mrdoob / http://mrdoob.com/
  13500. * @author alteredq / http://alteredqualia.com/
  13501. */
  13502. THREE.Fog = function ( color, near, far ) {
  13503. this.name = '';
  13504. this.color = new THREE.Color( color );
  13505. this.near = ( near !== undefined ) ? near : 1;
  13506. this.far = ( far !== undefined ) ? far : 1000;
  13507. };
  13508. THREE.Fog.prototype.clone = function () {
  13509. return new THREE.Fog( this.color.getHex(), this.near, this.far );
  13510. };
  13511. // File:src/scenes/FogExp2.js
  13512. /**
  13513. * @author mrdoob / http://mrdoob.com/
  13514. * @author alteredq / http://alteredqualia.com/
  13515. */
  13516. THREE.FogExp2 = function ( color, density ) {
  13517. this.name = '';
  13518. this.color = new THREE.Color( color );
  13519. this.density = ( density !== undefined ) ? density : 0.00025;
  13520. };
  13521. THREE.FogExp2.prototype.clone = function () {
  13522. return new THREE.FogExp2( this.color.getHex(), this.density );
  13523. };
  13524. // File:src/renderers/shaders/ShaderChunk.js
  13525. THREE.ShaderChunk = {};
  13526. // File:src/renderers/shaders/ShaderChunk/alphamap_fragment.glsl
  13527. THREE.ShaderChunk[ 'alphamap_fragment'] = "#ifdef USE_ALPHAMAP\n diffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif\n";
  13528. // File:src/renderers/shaders/ShaderChunk/alphamap_pars_fragment.glsl
  13529. THREE.ShaderChunk[ 'alphamap_pars_fragment'] = "#ifdef USE_ALPHAMAP\n uniform sampler2D alphaMap;\n#endif\n";
  13530. // File:src/renderers/shaders/ShaderChunk/alphatest_fragment.glsl
  13531. THREE.ShaderChunk[ 'alphatest_fragment'] = "#ifdef ALPHATEST\n if ( diffuseColor.a < ALPHATEST ) discard;\n#endif\n";
  13532. // File:src/renderers/shaders/ShaderChunk/aomap_fragment.glsl
  13533. THREE.ShaderChunk[ 'aomap_fragment'] = "#ifdef USE_AOMAP\n reflectedLight.indirectDiffuse *= ( texture2D( aoMap, vUv2 ).r - 1.0 ) * aoMapIntensity + 1.0;\n#endif\n";
  13534. // File:src/renderers/shaders/ShaderChunk/aomap_pars_fragment.glsl
  13535. THREE.ShaderChunk[ 'aomap_pars_fragment'] = "#ifdef USE_AOMAP\n uniform sampler2D aoMap;\n uniform float aoMapIntensity;\n#endif";
  13536. // File:src/renderers/shaders/ShaderChunk/begin_vertex.glsl
  13537. THREE.ShaderChunk[ 'begin_vertex'] = "\nvec3 transformed = vec3( position );\n";
  13538. // File:src/renderers/shaders/ShaderChunk/beginnormal_vertex.glsl
  13539. THREE.ShaderChunk[ 'beginnormal_vertex'] = "\nvec3 objectNormal = vec3( normal );\n";
  13540. // File:src/renderers/shaders/ShaderChunk/bsdfs.glsl
  13541. THREE.ShaderChunk[ 'bsdfs'] = "float calcLightAttenuation( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {\n if ( decayExponent > 0.0 ) {\n return pow( saturate( -lightDistance / cutoffDistance + 1.0 ), decayExponent );\n }\n return 1.0;\n}\nvec3 BRDF_Diffuse_Lambert( const in vec3 diffuseColor ) {\n return diffuseColor;\n}\nvec3 F_Schlick( const in vec3 specularColor, const in float dotLH ) {\n float fresnel = exp2( ( -5.55437 * dotLH - 6.98316 ) * dotLH );\n return ( 1.0 - specularColor ) * fresnel + specularColor;\n}\nfloat G_GGX_Smith( const in float alpha, const in float dotNL, const in float dotNV ) {\n float a2 = alpha * alpha;\n float gl = dotNL + pow( a2 + ( 1.0 - a2 ) * dotNL * dotNL, 0.5 );\n float gv = dotNV + pow( a2 + ( 1.0 - a2 ) * dotNV * dotNV, 0.5 );\n return 1.0 / ( gl * gv );\n}\nfloat D_GGX( const in float alpha, const in float dotNH ) {\n float a2 = alpha * alpha;\n float denom = dotNH * dotNH * ( a2 - 1.0 ) + 1.0;\n return a2 / ( denom * denom );\n}\nvec3 BRDF_Specular_GGX( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float roughness ) {\n \n float alpha = roughness * roughness;\n vec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );\n float dotNL = saturate( dot( geometry.normal, incidentLight.direction ) );\n float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n float dotNH = saturate( dot( geometry.normal, halfDir ) );\n float dotLH = saturate( dot( incidentLight.direction, halfDir ) );\n vec3 F = F_Schlick( specularColor, dotLH );\n float G = G_GGX_Smith( alpha, dotNL, dotNV );\n float D = D_GGX( alpha, dotNH );\n return F * ( G * D );\n}\nvec3 BRDF_Specular_GGX_Environment( const in GeometricContext geometry, 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 ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );\n}\nvec3 BRDF_Specular_BlinnPhong( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float shininess ) {\n vec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );\n float dotNH = saturate( dot( geometry.normal, halfDir ) );\n float dotLH = saturate( dot( incidentLight.direction, halfDir ) );\n vec3 F = F_Schlick( specularColor, dotLH );\n float G = G_BlinnPhong_Implicit( );\n float D = D_BlinnPhong( shininess, dotNH );\n return F * ( G * D );\n}\nfloat GGXRoughnessToBlinnExponent( const in float ggxRoughness ) {\n return ( 2.0 / square( ggxRoughness + 0.0001 ) - 2.0 );\n}";
  13542. // File:src/renderers/shaders/ShaderChunk/bumpmap_pars_fragment.glsl
  13543. 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";
  13544. // File:src/renderers/shaders/ShaderChunk/color_fragment.glsl
  13545. THREE.ShaderChunk[ 'color_fragment'] = "#ifdef USE_COLOR\n diffuseColor.rgb *= vColor;\n#endif";
  13546. // File:src/renderers/shaders/ShaderChunk/color_pars_fragment.glsl
  13547. THREE.ShaderChunk[ 'color_pars_fragment'] = "#ifdef USE_COLOR\n varying vec3 vColor;\n#endif\n";
  13548. // File:src/renderers/shaders/ShaderChunk/color_pars_vertex.glsl
  13549. THREE.ShaderChunk[ 'color_pars_vertex'] = "#ifdef USE_COLOR\n varying vec3 vColor;\n#endif";
  13550. // File:src/renderers/shaders/ShaderChunk/color_vertex.glsl
  13551. THREE.ShaderChunk[ 'color_vertex'] = "#ifdef USE_COLOR\n vColor.xyz = color.xyz;\n#endif";
  13552. // File:src/renderers/shaders/ShaderChunk/common.glsl
  13553. THREE.ShaderChunk[ 'common'] = "#define PI 3.14159\n#define PI2 6.28318\n#define RECIPROCAL_PI 0.31830988618\n#define RECIPROCAL_PI2 0.15915494\n#define LOG2 1.442695\n#define EPSILON 1e-6\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#define whiteCompliment(a) ( 1.0 - saturate( a ) )\nfloat square( const in float x ) { return x*x; }\nfloat average( const in vec3 color ) { return dot( color, vec3( 0.3333 ) ); }\nstruct IncidentLight {\n vec3 color;\n vec3 direction;\n};\nstruct ReflectedLight {\n vec3 directDiffuse;\n vec3 directSpecular;\n vec3 indirectDiffuse;\n vec3 indirectSpecular;\n};\nstruct GeometricContext {\n vec3 position;\n vec3 normal;\n vec3 viewDir;\n};\nvec3 transformDirection( in vec3 normal, in mat4 matrix ) {\n return normalize( ( matrix * vec4( normal, 0.0 ) ).xyz );\n}\nvec3 inverseTransformDirection( in vec3 normal, in mat4 matrix ) {\n return normalize( ( vec4( normal, 0.0 ) * matrix ).xyz );\n}\nvec3 projectOnPlane(in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n float distance = dot( planeNormal, point - pointOnPlane );\n return - distance * planeNormal + point;\n}\nfloat sideOfPlane( in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n return sign( dot( point - pointOnPlane, planeNormal ) );\n}\nvec3 linePlaneIntersect( in vec3 pointOnLine, in vec3 lineDirection, in vec3 pointOnPlane, in vec3 planeNormal ) {\n return lineDirection * ( dot( planeNormal, pointOnPlane - pointOnLine ) / dot( planeNormal, lineDirection ) ) + pointOnLine;\n}\nvec3 inputToLinear( in vec3 a ) {\n #ifdef GAMMA_INPUT\n return pow( a, vec3( float( GAMMA_FACTOR ) ) );\n #else\n return a;\n #endif\n}\nvec3 linearToOutput( in vec3 a ) {\n #ifdef GAMMA_OUTPUT\n return pow( a, vec3( 1.0 / float( GAMMA_FACTOR ) ) );\n #else\n return a;\n #endif\n}\n";
  13554. // File:src/renderers/shaders/ShaderChunk/defaultnormal_vertex.glsl
  13555. THREE.ShaderChunk[ 'defaultnormal_vertex'] = "#ifdef FLIP_SIDED\n objectNormal = -objectNormal;\n#endif\nvec3 transformedNormal = normalMatrix * objectNormal;\n";
  13556. // File:src/renderers/shaders/ShaderChunk/displacementmap_vertex.glsl
  13557. THREE.ShaderChunk[ 'displacementmap_vertex'] = "#ifdef USE_DISPLACEMENTMAP\n transformed += normal * ( texture2D( displacementMap, uv ).x * displacementScale + displacementBias );\n#endif\n";
  13558. // File:src/renderers/shaders/ShaderChunk/displacementmap_pars_vertex.glsl
  13559. THREE.ShaderChunk[ 'displacementmap_pars_vertex'] = "#ifdef USE_DISPLACEMENTMAP\n uniform sampler2D displacementMap;\n uniform float displacementScale;\n uniform float displacementBias;\n#endif\n";
  13560. // File:src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl
  13561. THREE.ShaderChunk[ 'emissivemap_fragment'] = "#ifdef USE_EMISSIVEMAP\n vec4 emissiveColor = texture2D( emissiveMap, vUv );\n emissiveColor.rgb = inputToLinear( emissiveColor.rgb );\n totalEmissiveLight *= emissiveColor.rgb;\n#endif\n";
  13562. // File:src/renderers/shaders/ShaderChunk/emissivemap_pars_fragment.glsl
  13563. THREE.ShaderChunk[ 'emissivemap_pars_fragment'] = "#ifdef USE_EMISSIVEMAP\n uniform sampler2D emissiveMap;\n#endif\n";
  13564. // File:src/renderers/shaders/ShaderChunk/envmap_fragment.glsl
  13565. THREE.ShaderChunk[ 'envmap_fragment'] = "#ifdef USE_ENVMAP\n #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )\n vec3 cameraToVertex = normalize( vWorldPosition - cameraPosition );\n vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n #ifdef ENVMAP_MODE_REFLECTION\n vec3 reflectVec = reflect( cameraToVertex, worldNormal );\n #else\n vec3 reflectVec = refract( cameraToVertex, worldNormal, refractionRatio );\n #endif\n #else\n vec3 reflectVec = vReflect;\n #endif\n #ifdef DOUBLE_SIDED\n float flipNormal = ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n #else\n float flipNormal = 1.0;\n #endif\n #ifdef ENVMAP_TYPE_CUBE\n vec4 envColor = textureCube( envMap, flipNormal * vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );\n #elif defined( ENVMAP_TYPE_EQUIREC )\n vec2 sampleUV;\n sampleUV.y = saturate( flipNormal * reflectVec.y * 0.5 + 0.5 );\n sampleUV.x = atan( flipNormal * reflectVec.z, flipNormal * reflectVec.x ) * RECIPROCAL_PI2 + 0.5;\n vec4 envColor = texture2D( envMap, sampleUV );\n #elif defined( ENVMAP_TYPE_SPHERE )\n vec3 reflectView = flipNormal * normalize((viewMatrix * vec4( reflectVec, 0.0 )).xyz + vec3(0.0,0.0,1.0));\n vec4 envColor = texture2D( envMap, reflectView.xy * 0.5 + 0.5 );\n #endif\n envColor.xyz = inputToLinear( envColor.xyz );\n #ifdef ENVMAP_BLENDING_MULTIPLY\n outgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity );\n #elif defined( ENVMAP_BLENDING_MIX )\n outgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity );\n #elif defined( ENVMAP_BLENDING_ADD )\n outgoingLight += envColor.xyz * specularStrength * reflectivity;\n #endif\n#endif\n";
  13566. // File:src/renderers/shaders/ShaderChunk/envmap_pars_fragment.glsl
  13567. THREE.ShaderChunk[ 'envmap_pars_fragment'] = "#if defined( USE_ENVMAP ) || defined( PHYSICAL )\n uniform float reflectivity;\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( PHYSICAL )\n uniform float refractionRatio;\n #else\n varying vec3 vReflect;\n #endif\n#endif\n";
  13568. // File:src/renderers/shaders/ShaderChunk/envmap_pars_vertex.glsl
  13569. THREE.ShaderChunk[ 'envmap_pars_vertex'] = "#if defined( USE_ENVMAP ) && ! defined( USE_BUMPMAP ) && ! defined( USE_NORMALMAP ) && ! defined( PHONG ) && ! defined( PHYSICAL )\n varying vec3 vReflect;\n uniform float refractionRatio;\n#endif\n";
  13570. // File:src/renderers/shaders/ShaderChunk/envmap_vertex.glsl
  13571. THREE.ShaderChunk[ 'envmap_vertex'] = "#if defined( USE_ENVMAP ) && ! defined( USE_BUMPMAP ) && ! defined( USE_NORMALMAP ) && ! defined( PHONG ) && ! defined( PHYSICAL )\n vec3 cameraToVertex = normalize( worldPosition.xyz - cameraPosition );\n vec3 worldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\n #ifdef ENVMAP_MODE_REFLECTION\n vReflect = reflect( cameraToVertex, worldNormal );\n #else\n vReflect = refract( cameraToVertex, worldNormal, refractionRatio );\n #endif\n#endif\n";
  13572. // File:src/renderers/shaders/ShaderChunk/fog_fragment.glsl
  13573. THREE.ShaderChunk[ 'fog_fragment'] = "#ifdef USE_FOG\n #ifdef USE_LOGDEPTHBUF_EXT\n float depth = gl_FragDepthEXT / gl_FragCoord.w;\n #else\n float depth = gl_FragCoord.z / gl_FragCoord.w;\n #endif\n #ifdef FOG_EXP2\n float fogFactor = whiteCompliment( exp2( - fogDensity * fogDensity * depth * depth * LOG2 ) );\n #else\n float fogFactor = smoothstep( fogNear, fogFar, depth );\n #endif\n \n outgoingLight = mix( outgoingLight, fogColor, fogFactor );\n#endif";
  13574. // File:src/renderers/shaders/ShaderChunk/fog_pars_fragment.glsl
  13575. 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";
  13576. // File:src/renderers/shaders/ShaderChunk/lights_pars.glsl
  13577. THREE.ShaderChunk[ 'lights_pars'] = "uniform vec3 ambientLightColor;\n#if MAX_DIR_LIGHTS > 0\n struct DirectionalLight {\n vec3 direction;\n vec3 color;\n };\n uniform DirectionalLight directionalLights[ MAX_DIR_LIGHTS ];\n IncidentLight getDirectionalDirectLight( const in DirectionalLight directionalLight, const in GeometricContext geometry ) { \n IncidentLight directLight;\n \n directLight.color = directionalLight.color;\n directLight.direction = directionalLight.direction; \n return directLight;\n }\n#endif\n#if MAX_POINT_LIGHTS > 0\n struct PointLight {\n vec3 position;\n vec3 color;\n float distance;\n float decay;\n };\n uniform PointLight pointLights[ MAX_POINT_LIGHTS ];\n IncidentLight getPointDirectLight( const in PointLight pointLight, const in GeometricContext geometry ) { \n \n IncidentLight directLight;\n \n vec3 lVector = pointLight.position - geometry.position; \n directLight.direction = normalize( lVector ); \n \n directLight.color = pointLight.color; \n directLight.color *= calcLightAttenuation( length( lVector ), pointLight.distance, pointLight.decay ); \n \n return directLight;\n }\n#endif\n#if MAX_SPOT_LIGHTS > 0\n struct SpotLight {\n vec3 position;\n vec3 direction;\n vec3 color;\n float distance;\n float decay;\n float angleCos;\n float exponent;\n };\n uniform SpotLight spotLights[ MAX_SPOT_LIGHTS ];\n IncidentLight getSpotDirectLight( const in SpotLight spotLight, const in GeometricContext geometry ) {\n \n IncidentLight directLight;\n vec3 lVector = spotLight.position - geometry.position;\n directLight.direction = normalize( lVector );\n \n float spotEffect = dot( directLight.direction, spotLight.direction );\n if ( spotEffect > spotLight.angleCos ) {\n float spotEffect = dot( spotLight.direction, directLight.direction );\n spotEffect = saturate( pow( saturate( spotEffect ), spotLight.exponent ) );\n \n directLight.color = spotLight.color;\n directLight.color *= ( spotEffect * calcLightAttenuation( length( lVector ), spotLight.distance, spotLight.decay ) );\n }\n else {\n directLight.color = vec3( 0.0 );\n }\n return directLight;\n }\n#endif\n#if MAX_HEMI_LIGHTS > 0\n struct HemisphereLight {\n vec3 direction;\n vec3 skyColor;\n vec3 groundColor;\n };\n uniform HemisphereLight hemisphereLights[ MAX_HEMI_LIGHTS ];\n vec3 getHemisphereIndirectLightColor( const in HemisphereLight hemiLight, const in GeometricContext geometry ) { \n \n float dotNL = dot( geometry.normal, hemiLight.direction );\n float hemiDiffuseWeight = 0.5 * dotNL + 0.5;\n return mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );\n }\n#endif\n#if defined( USE_ENVMAP ) && defined( PHYSICAL )\n vec3 getDiffuseLightProbeIndirectLightColor( 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 #if defined( TEXTURE_CUBE_LOD_EXT ) \n vec4 envMapColor = textureCubeLodEXT( envMap, queryVec, float( maxMIPLevel ) );\n #else\n vec4 envMapColor = textureCube( envMap, queryVec, float( maxMIPLevel ) );\n #endif\n #else\n vec4 envMapColor = vec3( 0.0 );\n #endif\n envMapColor.rgb = inputToLinear( envMapColor.rgb );\n return envMapColor.rgb;\n }\n float getSpecularMIPLevel( const in float blinnShininessExponent, const in int maxMIPLevel ) {\n float maxMIPLevelScalar = float( maxMIPLevel );\n float desiredMIPLevel = maxMIPLevelScalar - 0.79248 - 0.5 * log2( square( blinnShininessExponent ) + 1.0 );\n \n return clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );\n }\n vec3 getSpecularLightProbeIndirectLightColor( const in GeometricContext geometry, const in float blinnShininessExponent, const in int maxMIPLevel ) { \n \n #ifdef ENVMAP_MODE_REFLECTION\n vec3 reflectVec = reflect( -geometry.viewDir, geometry.normal );\n #else\n vec3 reflectVec = refract( -geometry.viewDir, geometry.normal, refractionRatio );\n #endif\n #ifdef DOUBLE_SIDED\n float flipNormal = ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n #else\n float flipNormal = 1.0;\n #endif\n reflectVec = inverseTransformDirection( reflectVec, viewMatrix );\n #ifdef ENVMAP_TYPE_CUBE\n vec3 queryReflectVec = flipNormal * vec3( flipEnvMap * reflectVec.x, reflectVec.yz );\n #if defined( TEXTURE_CUBE_LOD_EXT ) \n float specularMIPLevel = getSpecularMIPLevel( blinnShininessExponent, maxMIPLevel );\n vec4 envMapColor = textureCubeLodEXT( envMap, queryReflectVec, specularMIPLevel );\n #else\n vec4 envMapColor = textureCube( envMap, queryReflectVec );\n #endif\n \n #elif defined( ENVMAP_TYPE_EQUIREC )\n vec2 sampleUV;\n sampleUV.y = saturate( flipNormal * reflectVec.y * 0.5 + 0.5 );\n sampleUV.x = atan( flipNormal * reflectVec.z, flipNormal * reflectVec.x ) * RECIPROCAL_PI2 + 0.5;\n vec4 envMapColor = texture2D( envMap, sampleUV );\n #elif defined( ENVMAP_TYPE_SPHERE )\n vec3 reflectView = flipNormal * normalize((viewMatrix * vec4( reflectVec, 0.0 )).xyz + vec3(0.0,0.0,1.0));\n vec4 envMapColor = texture2D( envMap, reflectView.xy * 0.5 + 0.5 );\n #endif\n envMapColor.rgb = inputToLinear( envMapColor.rgb );\n return envMapColor.rgb;\n }\n#endif\n";
  13578. // File:src/renderers/shaders/ShaderChunk/lightmap_pars_fragment.glsl
  13579. THREE.ShaderChunk[ 'lightmap_pars_fragment'] = "#ifdef USE_LIGHTMAP\n uniform sampler2D lightMap;\n uniform float lightMapIntensity;\n#endif";
  13580. // File:src/renderers/shaders/ShaderChunk/lights_lambert_vertex.glsl
  13581. THREE.ShaderChunk[ 'lights_lambert_vertex'] = "vec3 diffuse = vec3( 1.0 );\nGeometricContext geometry = GeometricContext( mvPosition.xyz, normalize( transformedNormal ), normalize( -mvPosition.xyz ) );\nGeometricContext backGeometry = GeometricContext( geometry.position, -geometry.normal, geometry.viewDir );\nvLightFront = vec3( 0.0 );\n#ifdef DOUBLE_SIDED\n vLightBack = vec3( 0.0 );\n#endif\n#if MAX_POINT_LIGHTS > 0\n for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {\n IncidentLight directLight = getPointDirectLight( pointLights[ i ], geometry );\n float dotNL = dot( geometry.normal, directLight.direction );\n vec3 directLightColor_Diffuse = directLight.color * BRDF_Diffuse_Lambert( diffuse );\n vLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n #ifdef DOUBLE_SIDED\n vLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n #endif\n }\n#endif\n#if MAX_SPOT_LIGHTS > 0\n for ( int i = 0; i < MAX_SPOT_LIGHTS; i ++ ) {\n IncidentLight directLight = getSpotDirectLight( spotLights[ i ], geometry );\n float dotNL = dot( geometry.normal, directLight.direction );\n vec3 directLightColor_Diffuse = directLight.color * BRDF_Diffuse_Lambert( diffuse );\n vLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n #ifdef DOUBLE_SIDED\n vLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n #endif\n }\n#endif\n#if MAX_DIR_LIGHTS > 0\n for ( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {\n IncidentLight directLight = getDirectionalDirectLight( directionalLights[ i ], geometry );\n float dotNL = dot( geometry.normal, directLight.direction );\n vec3 directLightColor_Diffuse = directLight.color * BRDF_Diffuse_Lambert( diffuse );\n vLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n #ifdef DOUBLE_SIDED\n vLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n #endif\n }\n#endif\n {\n vLightFront += ambientLightColor;\n #ifdef DOUBLE_SIDED\n vLightBack += ambientLightColor;\n #endif\n #if MAX_HEMI_LIGHTS > 0\n for ( int i = 0; i < MAX_HEMI_LIGHTS; i ++ ) {\n vLightFront += getHemisphereIndirectLightColor( hemisphereLights[ i ], geometry );\n #ifdef DOUBLE_SIDED\n vLightBack += getHemisphereIndirectLightColor( hemisphereLights[ i ], backGeometry );\n #endif\n }\n #endif\n }\n";
  13582. // File:src/renderers/shaders/ShaderChunk/lights_phong_fragment.glsl
  13583. THREE.ShaderChunk[ 'lights_phong_fragment'] = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;\n#ifdef METAL\n material.diffuseColor = vec3( 0.0 );\n#endif\n";
  13584. // File:src/renderers/shaders/ShaderChunk/lights_phong_pars_fragment.glsl
  13585. THREE.ShaderChunk[ 'lights_phong_pars_fragment'] = "#ifdef USE_ENVMAP\n varying vec3 vWorldPosition;\n#endif\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n varying vec3 vNormal;\n#endif\nstruct BlinnPhongMaterial {\n vec3 diffuseColor;\n vec3 specularColor;\n float specularShininess;\n float specularStrength;\n};\nvoid BlinnPhongMaterial_RE_DirectLight( const in IncidentLight directLight, const in GeometricContext geometry, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n float dotNL = saturate( dot( geometry.normal, directLight.direction ) );\n reflectedLight.directDiffuse += dotNL * directLight.color * BRDF_Diffuse_Lambert( material.diffuseColor );\n reflectedLight.directSpecular += dotNL * directLight.color * BRDF_Specular_BlinnPhong( directLight, geometry, material.specularColor, material.specularShininess ) * material.specularStrength;\n}\n#define Material_RE_DirectLight BlinnPhongMaterial_RE_DirectLight\nvoid BlinnPhongMaterial_RE_IndirectDiffuseLight( const in vec3 indirectDiffuseColor, const in GeometricContext geometry, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n reflectedLight.indirectDiffuse += indirectDiffuseColor * BRDF_Diffuse_Lambert( material.diffuseColor );\n}\n#define Material_RE_IndirectDiffuseLight BlinnPhongMaterial_RE_IndirectDiffuseLight\n#define Material_LightProbeLOD( material ) (0)\n";
  13586. // File:src/renderers/shaders/ShaderChunk/lights_phong_pars_vertex.glsl
  13587. THREE.ShaderChunk[ 'lights_phong_pars_vertex'] = "#ifdef USE_ENVMAP\n varying vec3 vWorldPosition;\n#endif\n#if MAX_POINT_LIGHTS > 0\n uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];\n#endif\n";
  13588. // File:src/renderers/shaders/ShaderChunk/lights_phong_vertex.glsl
  13589. THREE.ShaderChunk[ 'lights_phong_vertex'] = "#ifdef USE_ENVMAP\n vWorldPosition = worldPosition.xyz;\n#endif\n";
  13590. // File:src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl
  13591. THREE.ShaderChunk[ 'lights_physical_fragment'] = "PhysicalMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );\nmaterial.specularRoughness = roughnessFactor * 0.5 + 0.5;material.specularColor = mix( vec3( 0.08 ) * reflectivity, diffuseColor.rgb, metalnessFactor );\n";
  13592. // File:src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl
  13593. THREE.ShaderChunk[ 'lights_physical_pars_fragment'] = "struct PhysicalMaterial {\n vec3 diffuseColor;\n float specularRoughness;\n vec3 specularColor;\n float clearCoatWeight;\n float clearCoatRoughness;\n};\nvoid PhysicalMaterial_RE_DirectLight( const in IncidentLight directLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n float dotNL = saturate( dot( geometry.normal, directLight.direction ) );\n reflectedLight.directDiffuse += dotNL * directLight.color * BRDF_Diffuse_Lambert( material.diffuseColor );\n reflectedLight.directSpecular += dotNL * directLight.color * BRDF_Specular_GGX( directLight, geometry, material.specularColor, material.specularRoughness );\n \n}\n#define Material_RE_DirectLight PhysicalMaterial_RE_DirectLight\nvoid PhysicalMaterial_RE_DiffuseIndirectLight( const in vec3 indirectDiffuseColor, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n reflectedLight.indirectDiffuse += indirectDiffuseColor * BRDF_Diffuse_Lambert( material.diffuseColor );\n}\n#define Material_RE_IndirectDiffuseLight PhysicalMaterial_RE_DiffuseIndirectLight\nvoid PhysicalMaterial_RE_SpecularIndirectLight( const in vec3 indirectSpecularColor, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n reflectedLight.indirectSpecular += indirectSpecularColor * BRDF_Specular_GGX_Environment( geometry, material.specularColor, material.specularRoughness );\n}\n#define Material_BlinnShininessExponent( material ) GGXRoughnessToBlinnExponent( material.specularRoughness )\n#define Material_RE_IndirectSpecularLight PhysicalMaterial_RE_SpecularIndirectLight\n";
  13594. // File:src/renderers/shaders/ShaderChunk/lights_template.glsl
  13595. THREE.ShaderChunk[ 'lights_template'] = "\nGeometricContext geometry = GeometricContext( -vViewPosition, normalize( normal ), normalize(vViewPosition ) );\n#if ( MAX_POINT_LIGHTS > 0 ) && defined( Material_RE_DirectLight )\n for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {\n IncidentLight directLight = getPointDirectLight( pointLights[ i ], geometry );\n Material_RE_DirectLight( directLight, geometry, material, reflectedLight );\n }\n#endif\n#if ( MAX_SPOT_LIGHTS > 0 ) && defined( Material_RE_DirectLight )\n for ( int i = 0; i < MAX_SPOT_LIGHTS; i ++ ) {\n IncidentLight directLight = getSpotDirectLight( spotLights[ i ], geometry );\n Material_RE_DirectLight( directLight, geometry, material, reflectedLight );\n }\n#endif\n#if ( MAX_DIR_LIGHTS > 0 ) && defined( Material_RE_DirectLight )\n for ( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {\n IncidentLight directLight = getDirectionalDirectLight( directionalLights[ i ], geometry );\n Material_RE_DirectLight( directLight, geometry, material, reflectedLight );\n \n }\n#endif\n#if defined( Material_RE_IndirectDiffuseLight )\n {\n \n vec3 indirectDiffuseColor = ambientLightColor;\n#ifdef USE_LIGHTMAP\n indirectDiffuseColor += texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n#endif\n#if ( MAX_HEMI_LIGHTS > 0 )\n for ( int i = 0; i < MAX_HEMI_LIGHTS; i ++ ) {\n indirectDiffuseColor += getHemisphereIndirectLightColor( hemisphereLights[ i ], geometry );\n }\n#endif\n#if defined( USE_ENVMAP ) && defined( PHYSICAL )\n indirectDiffuseColor += getDiffuseLightProbeIndirectLightColor( geometry, 8 );\n#endif\n Material_RE_IndirectDiffuseLight( indirectDiffuseColor, geometry, material, reflectedLight );\n }\n#endif\n#if defined( USE_ENVMAP ) && defined( Material_RE_IndirectSpecularLight )\n {\n vec3 indirectSpecularColor = getSpecularLightProbeIndirectLightColor( geometry, Material_BlinnShininessExponent( material ), 8 );\n Material_RE_IndirectSpecularLight( indirectSpecularColor, geometry, material, reflectedLight );\n }\n#endif";
  13596. // File:src/renderers/shaders/ShaderChunk/linear_to_gamma_fragment.glsl
  13597. THREE.ShaderChunk[ 'linear_to_gamma_fragment'] = "\n outgoingLight = linearToOutput( outgoingLight );\n";
  13598. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl
  13599. THREE.ShaderChunk[ 'logdepthbuf_fragment'] = "#if defined(USE_LOGDEPTHBUF) && defined(USE_LOGDEPTHBUF_EXT)\n gl_FragDepthEXT = log2(vFragDepth) * logDepthBufFC * 0.5;\n#endif";
  13600. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl
  13601. 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";
  13602. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_pars_vertex.glsl
  13603. 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";
  13604. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl
  13605. 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";
  13606. // File:src/renderers/shaders/ShaderChunk/map_fragment.glsl
  13607. THREE.ShaderChunk[ 'map_fragment'] = "#ifdef USE_MAP\n vec4 texelColor = texture2D( map, vUv );\n texelColor.xyz = inputToLinear( texelColor.xyz );\n diffuseColor *= texelColor;\n#endif\n";
  13608. // File:src/renderers/shaders/ShaderChunk/map_pars_fragment.glsl
  13609. THREE.ShaderChunk[ 'map_pars_fragment'] = "#ifdef USE_MAP\n uniform sampler2D map;\n#endif";
  13610. // File:src/renderers/shaders/ShaderChunk/map_particle_fragment.glsl
  13611. THREE.ShaderChunk[ 'map_particle_fragment'] = "#ifdef USE_MAP\n diffuseColor *= texture2D( map, vec2( gl_PointCoord.x, 1.0 - gl_PointCoord.y ) * offsetRepeat.zw + offsetRepeat.xy );\n#endif\n";
  13612. // File:src/renderers/shaders/ShaderChunk/map_particle_pars_fragment.glsl
  13613. THREE.ShaderChunk[ 'map_particle_pars_fragment'] = "#ifdef USE_MAP\n uniform vec4 offsetRepeat;\n uniform sampler2D map;\n#endif\n";
  13614. // File:src/renderers/shaders/ShaderChunk/metalnessmap_fragment.glsl
  13615. THREE.ShaderChunk[ 'metalnessmap_fragment'] = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n vec4 texelMetalness = texture2D( metalnessMap, vUv );\n metalnessFactor = texelMetalness.r;\n#endif\n";
  13616. // File:src/renderers/shaders/ShaderChunk/metalnessmap_pars_fragment.glsl
  13617. THREE.ShaderChunk[ 'metalnessmap_pars_fragment'] = "#ifdef USE_METALNESSMAP\n uniform sampler2D metalnessMap;\n#endif";
  13618. // File:src/renderers/shaders/ShaderChunk/morphnormal_vertex.glsl
  13619. 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";
  13620. // File:src/renderers/shaders/ShaderChunk/morphtarget_pars_vertex.glsl
  13621. 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";
  13622. // File:src/renderers/shaders/ShaderChunk/morphtarget_vertex.glsl
  13623. 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";
  13624. // File:src/renderers/shaders/ShaderChunk/normal_phong_fragment.glsl
  13625. THREE.ShaderChunk[ 'normal_phong_fragment'] = "#ifndef FLAT_SHADED\n vec3 normal = normalize( vNormal );\n #ifdef DOUBLE_SIDED\n normal = normal * ( -1.0 + 2.0 * float( gl_FrontFacing ) );\n #endif\n#else\n vec3 fdx = dFdx( vViewPosition );\n vec3 fdy = dFdy( vViewPosition );\n vec3 normal = normalize( cross( fdx, fdy ) );\n#endif\n#ifdef USE_NORMALMAP\n normal = perturbNormal2Arb( -vViewPosition, normal );\n#elif defined( USE_BUMPMAP )\n normal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd() );\n#endif\n";
  13626. // File:src/renderers/shaders/ShaderChunk/normalmap_pars_fragment.glsl
  13627. 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";
  13628. // File:src/renderers/shaders/ShaderChunk/project_vertex.glsl
  13629. 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";
  13630. // File:src/renderers/shaders/ShaderChunk/roughnessmap_fragment.glsl
  13631. THREE.ShaderChunk[ 'roughnessmap_fragment'] = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n vec4 texelRoughness = texture2D( roughnessMap, vUv );\n roughnessFactor *= texelRoughness.r;\n#endif\n";
  13632. // File:src/renderers/shaders/ShaderChunk/roughnessmap_pars_fragment.glsl
  13633. THREE.ShaderChunk[ 'roughnessmap_pars_fragment'] = "#ifdef USE_ROUGHNESSMAP\n uniform sampler2D roughnessMap;\n#endif";
  13634. // File:src/renderers/shaders/ShaderChunk/shadowmap_fragment.glsl
  13635. THREE.ShaderChunk[ 'shadowmap_fragment'] = "#ifdef USE_SHADOWMAP\n for ( int i = 0; i < MAX_SHADOWS; i ++ ) {\n float texelSizeY = 1.0 / shadowMapSize[ i ].y;\n float shadow = 0.0;\n#if defined( POINT_LIGHT_SHADOWS )\n bool isPointLight = shadowDarkness[ i ] < 0.0;\n if ( isPointLight ) {\n float realShadowDarkness = abs( shadowDarkness[ i ] );\n vec3 lightToPosition = vShadowCoord[ i ].xyz;\n #if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT )\n vec3 bd3D = normalize( lightToPosition );\n float dp = length( lightToPosition );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D, texelSizeY ) ), shadowBias[ i ], shadow );\n #if defined( SHADOWMAP_TYPE_PCF )\n const float Dr = 1.25;\n #elif defined( SHADOWMAP_TYPE_PCF_SOFT )\n const float Dr = 2.25;\n #endif\n float os = Dr * 2.0 * texelSizeY;\n const vec3 Gsd = vec3( - 1, 0, 1 );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.zzz * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.zxz * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.xxz * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.xzz * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.zzx * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.zxx * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.xxx * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.xzx * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.zzy * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.zxy * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.xxy * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.xzy * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.zyz * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.xyz * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.zyx * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.xyx * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.yzz * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.yxz * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.yxx * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.yzx * os, texelSizeY ) ), shadowBias[ i ], shadow );\n shadow *= realShadowDarkness * ( 1.0 / 21.0 );\n #else\n vec3 bd3D = normalize( lightToPosition );\n float dp = length( lightToPosition );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D, texelSizeY ) ), shadowBias[ i ], shadow );\n shadow *= realShadowDarkness;\n #endif\n } else {\n#endif\n float texelSizeX = 1.0 / shadowMapSize[ i ].x;\n vec3 shadowCoord = vShadowCoord[ i ].xyz / vShadowCoord[ i ].w;\n bvec4 inFrustumVec = bvec4 ( shadowCoord.x >= 0.0, shadowCoord.x <= 1.0, shadowCoord.y >= 0.0, shadowCoord.y <= 1.0 );\n bool inFrustum = all( inFrustumVec );\n bvec2 frustumTestVec = bvec2( inFrustum, shadowCoord.z <= 1.0 );\n bool frustumTest = all( frustumTestVec );\n if ( frustumTest ) {\n #if defined( SHADOWMAP_TYPE_PCF )\n shadowCoord.z += shadowBias[ i ];\n const float ShadowDelta = 1.0 / 9.0;\n float xPixelOffset = texelSizeX;\n float yPixelOffset = texelSizeY;\n float dx0 = - 1.25 * xPixelOffset;\n float dy0 = - 1.25 * yPixelOffset;\n float dx1 = 1.25 * xPixelOffset;\n float dy1 = 1.25 * yPixelOffset;\n float fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy0 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += ShadowDelta;\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy0 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += ShadowDelta;\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy0 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += ShadowDelta;\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, 0.0 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += ShadowDelta;\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy ) );\n if ( fDepth < shadowCoord.z ) shadow += ShadowDelta;\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, 0.0 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += ShadowDelta;\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy1 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += ShadowDelta;\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy1 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += ShadowDelta;\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy1 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += ShadowDelta;\n shadow *= shadowDarkness[ i ];\n #elif defined( SHADOWMAP_TYPE_PCF_SOFT )\n shadowCoord.z += shadowBias[ i ];\n float xPixelOffset = texelSizeX;\n float yPixelOffset = texelSizeY;\n float dx0 = - 1.0 * xPixelOffset;\n float dy0 = - 1.0 * yPixelOffset;\n float dx1 = 1.0 * xPixelOffset;\n float dy1 = 1.0 * yPixelOffset;\n mat3 shadowKernel;\n mat3 depthKernel;\n depthKernel[ 0 ][ 0 ] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy0 ) ) );\n depthKernel[ 0 ][ 1 ] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, 0.0 ) ) );\n depthKernel[ 0 ][ 2 ] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy1 ) ) );\n depthKernel[ 1 ][ 0 ] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy0 ) ) );\n depthKernel[ 1 ][ 1 ] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy ) );\n depthKernel[ 1 ][ 2 ] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy1 ) ) );\n depthKernel[ 2 ][ 0 ] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy0 ) ) );\n depthKernel[ 2 ][ 1 ] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, 0.0 ) ) );\n depthKernel[ 2 ][ 2 ] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy1 ) ) );\n vec3 shadowZ = vec3( shadowCoord.z );\n shadowKernel[ 0 ] = vec3( lessThan( depthKernel[ 0 ], shadowZ ) );\n shadowKernel[ 0 ] *= vec3( 0.25 );\n shadowKernel[ 1 ] = vec3( lessThan( depthKernel[ 1 ], shadowZ ) );\n shadowKernel[ 1 ] *= vec3( 0.25 );\n shadowKernel[ 2 ] = vec3( lessThan( depthKernel[ 2 ], shadowZ ) );\n shadowKernel[ 2 ] *= vec3( 0.25 );\n vec2 fractionalCoord = 1.0 - fract( shadowCoord.xy * shadowMapSize[ i ].xy );\n shadowKernel[ 0 ] = mix( shadowKernel[ 1 ], shadowKernel[ 0 ], fractionalCoord.x );\n shadowKernel[ 1 ] = mix( shadowKernel[ 2 ], shadowKernel[ 1 ], fractionalCoord.x );\n vec4 shadowValues;\n shadowValues.x = mix( shadowKernel[ 0 ][ 1 ], shadowKernel[ 0 ][ 0 ], fractionalCoord.y );\n shadowValues.y = mix( shadowKernel[ 0 ][ 2 ], shadowKernel[ 0 ][ 1 ], fractionalCoord.y );\n shadowValues.z = mix( shadowKernel[ 1 ][ 1 ], shadowKernel[ 1 ][ 0 ], fractionalCoord.y );\n shadowValues.w = mix( shadowKernel[ 1 ][ 2 ], shadowKernel[ 1 ][ 1 ], fractionalCoord.y );\n shadow = dot( shadowValues, vec4( 1.0 ) ) * shadowDarkness[ i ];\n #else\n shadowCoord.z += shadowBias[ i ];\n vec4 rgbaDepth = texture2D( shadowMap[ i ], shadowCoord.xy );\n float fDepth = unpackDepth( rgbaDepth );\n if ( fDepth < shadowCoord.z )\n shadow = shadowDarkness[ i ];\n #endif\n }\n#ifdef SHADOWMAP_DEBUG\n if ( inFrustum ) {\n if ( i == 0 ) {\n outgoingLight *= vec3( 1.0, 0.5, 0.0 );\n } else if ( i == 1 ) {\n outgoingLight *= vec3( 0.0, 1.0, 0.8 );\n } else {\n outgoingLight *= vec3( 0.0, 0.5, 1.0 );\n }\n }\n#endif\n#if defined( POINT_LIGHT_SHADOWS )\n }\n#endif\n shadowMask = shadowMask * vec3( 1.0 - shadow );\n }\n#endif\n";
  13636. // File:src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl
  13637. THREE.ShaderChunk[ 'shadowmap_pars_fragment'] = "#ifdef USE_SHADOWMAP\n uniform sampler2D shadowMap[ MAX_SHADOWS ];\n uniform vec2 shadowMapSize[ MAX_SHADOWS ];\n uniform float shadowDarkness[ MAX_SHADOWS ];\n uniform float shadowBias[ MAX_SHADOWS ];\n varying vec4 vShadowCoord[ MAX_SHADOWS ];\n float unpackDepth( const in vec4 rgba_depth ) {\n const vec4 bit_shift = vec4( 1.0 / ( 256.0 * 256.0 * 256.0 ), 1.0 / ( 256.0 * 256.0 ), 1.0 / 256.0, 1.0 );\n float depth = dot( rgba_depth, bit_shift );\n return depth;\n }\n #if defined(POINT_LIGHT_SHADOWS)\n void adjustShadowValue1K( const float testDepth, const vec4 textureData, const float bias, inout float shadowValue ) {\n const vec4 bitSh = vec4( 1.0 / ( 256.0 * 256.0 * 256.0 ), 1.0 / ( 256.0 * 256.0 ), 1.0 / 256.0, 1.0 );\n if ( testDepth >= dot( textureData, bitSh ) * 1000.0 + bias )\n shadowValue += 1.0;\n }\n vec2 cubeToUV( vec3 v, float texelSizeY ) {\n vec3 absV = abs( v );\n float scaleToCube = 1.0 / max( absV.x, max( absV.y, absV.z ) );\n absV *= scaleToCube;\n v *= scaleToCube * ( 1.0 - 2.0 * texelSizeY );\n vec2 planar = v.xy;\n float almostATexel = 1.5 * texelSizeY;\n float almostOne = 1.0 - almostATexel;\n if ( absV.z >= almostOne ) {\n if ( v.z > 0.0 )\n planar.x = 4.0 - v.x;\n } else if ( absV.x >= almostOne ) {\n float signX = sign( v.x );\n planar.x = v.z * signX + 2.0 * signX;\n } else if ( absV.y >= almostOne ) {\n float signY = sign( v.y );\n planar.x = v.x + 2.0 * signY + 2.0;\n planar.y = v.z * signY - 2.0;\n }\n return vec2( 0.125, 0.25 ) * planar + vec2( 0.375, 0.75 );\n }\n #endif\n#endif\n";
  13638. // File:src/renderers/shaders/ShaderChunk/shadowmap_pars_vertex.glsl
  13639. THREE.ShaderChunk[ 'shadowmap_pars_vertex'] = "#ifdef USE_SHADOWMAP\n uniform float shadowDarkness[ MAX_SHADOWS ];\n uniform mat4 shadowMatrix[ MAX_SHADOWS ];\n varying vec4 vShadowCoord[ MAX_SHADOWS ];\n#endif";
  13640. // File:src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl
  13641. THREE.ShaderChunk[ 'shadowmap_vertex'] = "#ifdef USE_SHADOWMAP\n for ( int i = 0; i < MAX_SHADOWS; i ++ ) {\n vShadowCoord[ i ] = shadowMatrix[ i ] * worldPosition;\n }\n#endif";
  13642. // File:src/renderers/shaders/ShaderChunk/skinbase_vertex.glsl
  13643. 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";
  13644. // File:src/renderers/shaders/ShaderChunk/skinning_pars_vertex.glsl
  13645. 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";
  13646. // File:src/renderers/shaders/ShaderChunk/skinning_vertex.glsl
  13647. 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";
  13648. // File:src/renderers/shaders/ShaderChunk/skinnormal_vertex.glsl
  13649. 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";
  13650. // File:src/renderers/shaders/ShaderChunk/specularmap_fragment.glsl
  13651. 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";
  13652. // File:src/renderers/shaders/ShaderChunk/specularmap_pars_fragment.glsl
  13653. THREE.ShaderChunk[ 'specularmap_pars_fragment'] = "#ifdef USE_SPECULARMAP\n uniform sampler2D specularMap;\n#endif";
  13654. // File:src/renderers/shaders/ShaderChunk/uv2_pars_fragment.glsl
  13655. THREE.ShaderChunk[ 'uv2_pars_fragment'] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n varying vec2 vUv2;\n#endif";
  13656. // File:src/renderers/shaders/ShaderChunk/uv2_pars_vertex.glsl
  13657. THREE.ShaderChunk[ 'uv2_pars_vertex'] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n attribute vec2 uv2;\n varying vec2 vUv2;\n#endif";
  13658. // File:src/renderers/shaders/ShaderChunk/uv2_vertex.glsl
  13659. THREE.ShaderChunk[ 'uv2_vertex'] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n vUv2 = uv2;\n#endif";
  13660. // File:src/renderers/shaders/ShaderChunk/uv_pars_fragment.glsl
  13661. THREE.ShaderChunk[ 'uv_pars_fragment'] = "#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP ) || defined( USE_ROUGHNESSMAP ) || defined( USE_REFLECTIVITYMAP ) || defined( USE_METALNESSMAP )\n varying vec2 vUv;\n#endif";
  13662. // File:src/renderers/shaders/ShaderChunk/uv_pars_vertex.glsl
  13663. THREE.ShaderChunk[ 'uv_pars_vertex'] = "#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP ) || defined( USE_ROUGHNESSMAP ) || defined( USE_REFLECTIVITYMAP ) || defined( USE_METALNESSMAP )\n varying vec2 vUv;\n uniform vec4 offsetRepeat;\n#endif\n";
  13664. // File:src/renderers/shaders/ShaderChunk/uv_vertex.glsl
  13665. THREE.ShaderChunk[ 'uv_vertex'] = "#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP ) || defined( USE_ROUGHNESSMAP ) || defined( USE_REFLECTIVITYMAP ) || defined( USE_METALNESSMAP )\n vUv = uv * offsetRepeat.zw + offsetRepeat.xy;\n#endif";
  13666. // File:src/renderers/shaders/ShaderChunk/worldpos_vertex.glsl
  13667. THREE.ShaderChunk[ 'worldpos_vertex'] = "#if defined( USE_ENVMAP ) || defined( PHONG ) || defined( PHYSICAL ) || defined( LAMBERT ) || defined ( USE_SHADOWMAP )\n #ifdef USE_SKINNING\n vec4 worldPosition = modelMatrix * skinned;\n #else\n vec4 worldPosition = modelMatrix * vec4( transformed, 1.0 );\n #endif\n#endif\n";
  13668. // File:src/renderers/shaders/UniformsUtils.js
  13669. /**
  13670. * Uniform Utilities
  13671. */
  13672. THREE.UniformsUtils = {
  13673. merge: function ( uniforms ) {
  13674. var merged = {};
  13675. for ( var u = 0; u < uniforms.length; u ++ ) {
  13676. var tmp = this.clone( uniforms[ u ] );
  13677. for ( var p in tmp ) {
  13678. merged[ p ] = tmp[ p ];
  13679. }
  13680. }
  13681. return merged;
  13682. },
  13683. clone: function ( uniforms_src ) {
  13684. var uniforms_dst = {};
  13685. for ( var u in uniforms_src ) {
  13686. uniforms_dst[ u ] = {};
  13687. for ( var p in uniforms_src[ u ] ) {
  13688. var parameter_src = uniforms_src[ u ][ p ];
  13689. if ( parameter_src instanceof THREE.Color ||
  13690. parameter_src instanceof THREE.Vector2 ||
  13691. parameter_src instanceof THREE.Vector3 ||
  13692. parameter_src instanceof THREE.Vector4 ||
  13693. parameter_src instanceof THREE.Matrix3 ||
  13694. parameter_src instanceof THREE.Matrix4 ||
  13695. parameter_src instanceof THREE.Texture ) {
  13696. uniforms_dst[ u ][ p ] = parameter_src.clone();
  13697. } else if ( Array.isArray( parameter_src ) ) {
  13698. uniforms_dst[ u ][ p ] = parameter_src.slice();
  13699. } else {
  13700. uniforms_dst[ u ][ p ] = parameter_src;
  13701. }
  13702. }
  13703. }
  13704. return uniforms_dst;
  13705. }
  13706. };
  13707. // File:src/renderers/shaders/UniformsLib.js
  13708. /**
  13709. * Uniforms library for shared webgl shaders
  13710. */
  13711. THREE.UniformsLib = {
  13712. common: {
  13713. "diffuse" : { type: "c", value: new THREE.Color( 0xeeeeee ) },
  13714. "opacity" : { type: "f", value: 1.0 },
  13715. "map" : { type: "t", value: null },
  13716. "offsetRepeat" : { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) },
  13717. "specularMap" : { type: "t", value: null },
  13718. "alphaMap" : { type: "t", value: null },
  13719. "envMap" : { type: "t", value: null },
  13720. "flipEnvMap" : { type: "f", value: - 1 },
  13721. "reflectivity" : { type: "f", value: 1.0 },
  13722. "refractionRatio" : { type: "f", value: 0.98 }
  13723. },
  13724. aomap: {
  13725. "aoMap" : { type: "t", value: null },
  13726. "aoMapIntensity" : { type: "f", value: 1 },
  13727. },
  13728. lightmap: {
  13729. "lightMap" : { type: "t", value: null },
  13730. "lightMapIntensity" : { type: "f", value: 1 },
  13731. },
  13732. emissivemap: {
  13733. "emissiveMap" : { type: "t", value: null },
  13734. },
  13735. bumpmap: {
  13736. "bumpMap" : { type: "t", value: null },
  13737. "bumpScale" : { type: "f", value: 1 }
  13738. },
  13739. normalmap: {
  13740. "normalMap" : { type: "t", value: null },
  13741. "normalScale" : { type: "v2", value: new THREE.Vector2( 1, 1 ) }
  13742. },
  13743. displacementmap: {
  13744. "displacementMap" : { type: "t", value: null },
  13745. "displacementScale" : { type: "f", value: 1 },
  13746. "displacementBias" : { type: "f", value: 0 }
  13747. },
  13748. roughnessmap: {
  13749. "roughnessMap" : { type: "t", value: null }
  13750. },
  13751. reflectivitymap: {
  13752. "reflectivityMap" : { type: "t", value: null }
  13753. },
  13754. metalnessmap: {
  13755. "metalnessMap" : { type: "t", value: null }
  13756. },
  13757. fog : {
  13758. "fogDensity" : { type: "f", value: 0.00025 },
  13759. "fogNear" : { type: "f", value: 1 },
  13760. "fogFar" : { type: "f", value: 2000 },
  13761. "fogColor" : { type: "c", value: new THREE.Color( 0xffffff ) }
  13762. },
  13763. lights: {
  13764. "ambientLightColor" : { type: "fv", value: [] },
  13765. "directionalLights" : { type: "sa", value: [], properties: {
  13766. "direction": { type: "v3" },
  13767. "color": { type: "c" }
  13768. } },
  13769. "hemisphereLights" : { type: "sa", value: [], properties: {
  13770. "direction": { type: "v3" },
  13771. "skyColor": { type: "c" },
  13772. "groundColor": { type: "c" }
  13773. } },
  13774. "pointLights" : { type: "sa", value: [], properties: {
  13775. "color": { type: "c" },
  13776. "position": { type: "v3" },
  13777. "decay": { type: "f" },
  13778. "distance": { type: "f" }
  13779. } },
  13780. "spotLights" : { type: "sa", value: [], properties: {
  13781. "color": { type: "c" },
  13782. "position": { type: "v3" },
  13783. "direction": { type: "v3" },
  13784. "distance": { type: "f" },
  13785. "angleCos": { type: "f" },
  13786. "exponent": { type: "f" },
  13787. "decay": { type: "f" }
  13788. } }
  13789. },
  13790. points: {
  13791. "psColor" : { type: "c", value: new THREE.Color( 0xeeeeee ) },
  13792. "opacity" : { type: "f", value: 1.0 },
  13793. "size" : { type: "f", value: 1.0 },
  13794. "scale" : { type: "f", value: 1.0 },
  13795. "map" : { type: "t", value: null },
  13796. "offsetRepeat" : { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) },
  13797. "fogDensity" : { type: "f", value: 0.00025 },
  13798. "fogNear" : { type: "f", value: 1 },
  13799. "fogFar" : { type: "f", value: 2000 },
  13800. "fogColor" : { type: "c", value: new THREE.Color( 0xffffff ) }
  13801. },
  13802. shadowmap: {
  13803. "shadowMap": { type: "tv", value: [] },
  13804. "shadowMapSize": { type: "v2v", value: [] },
  13805. "shadowBias" : { type: "fv1", value: [] },
  13806. "shadowDarkness": { type: "fv1", value: [] },
  13807. "shadowMatrix" : { type: "m4v", value: [] }
  13808. }
  13809. };
  13810. // File:src/renderers/shaders/ShaderLib.js
  13811. /**
  13812. * Webgl Shader Library for three.js
  13813. *
  13814. * @author alteredq / http://alteredqualia.com/
  13815. * @author mrdoob / http://mrdoob.com/
  13816. * @author mikael emtinger / http://gomo.se/
  13817. */
  13818. THREE.ShaderLib = {
  13819. 'basic': {
  13820. uniforms: THREE.UniformsUtils.merge( [
  13821. THREE.UniformsLib[ "common" ],
  13822. THREE.UniformsLib[ "aomap" ],
  13823. THREE.UniformsLib[ "fog" ],
  13824. THREE.UniformsLib[ "shadowmap" ]
  13825. ] ),
  13826. vertexShader: [
  13827. THREE.ShaderChunk[ "common" ],
  13828. THREE.ShaderChunk[ "uv_pars_vertex" ],
  13829. THREE.ShaderChunk[ "uv2_pars_vertex" ],
  13830. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  13831. THREE.ShaderChunk[ "color_pars_vertex" ],
  13832. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  13833. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  13834. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  13835. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  13836. "void main() {",
  13837. THREE.ShaderChunk[ "uv_vertex" ],
  13838. THREE.ShaderChunk[ "uv2_vertex" ],
  13839. THREE.ShaderChunk[ "color_vertex" ],
  13840. THREE.ShaderChunk[ "skinbase_vertex" ],
  13841. " #ifdef USE_ENVMAP",
  13842. THREE.ShaderChunk[ "beginnormal_vertex" ],
  13843. THREE.ShaderChunk[ "morphnormal_vertex" ],
  13844. THREE.ShaderChunk[ "skinnormal_vertex" ],
  13845. THREE.ShaderChunk[ "defaultnormal_vertex" ],
  13846. " #endif",
  13847. THREE.ShaderChunk[ "begin_vertex" ],
  13848. THREE.ShaderChunk[ "morphtarget_vertex" ],
  13849. THREE.ShaderChunk[ "skinning_vertex" ],
  13850. THREE.ShaderChunk[ "project_vertex" ],
  13851. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  13852. THREE.ShaderChunk[ "worldpos_vertex" ],
  13853. THREE.ShaderChunk[ "envmap_vertex" ],
  13854. THREE.ShaderChunk[ "shadowmap_vertex" ],
  13855. "}"
  13856. ].join( "\n" ),
  13857. fragmentShader: [
  13858. "uniform vec3 diffuse;",
  13859. "uniform float opacity;",
  13860. "#ifndef FLAT_SHADED",
  13861. " varying vec3 vNormal;",
  13862. "#endif",
  13863. THREE.ShaderChunk[ "common" ],
  13864. THREE.ShaderChunk[ "color_pars_fragment" ],
  13865. THREE.ShaderChunk[ "uv_pars_fragment" ],
  13866. THREE.ShaderChunk[ "uv2_pars_fragment" ],
  13867. THREE.ShaderChunk[ "map_pars_fragment" ],
  13868. THREE.ShaderChunk[ "alphamap_pars_fragment" ],
  13869. THREE.ShaderChunk[ "aomap_pars_fragment" ],
  13870. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  13871. THREE.ShaderChunk[ "fog_pars_fragment" ],
  13872. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  13873. THREE.ShaderChunk[ "specularmap_pars_fragment" ],
  13874. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  13875. "void main() {",
  13876. " vec4 diffuseColor = vec4( diffuse, opacity );",
  13877. " vec3 shadowMask = vec3( 1.0 );",
  13878. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  13879. THREE.ShaderChunk[ "map_fragment" ],
  13880. THREE.ShaderChunk[ "color_fragment" ],
  13881. THREE.ShaderChunk[ "alphamap_fragment" ],
  13882. THREE.ShaderChunk[ "alphatest_fragment" ],
  13883. THREE.ShaderChunk[ "specularmap_fragment" ],
  13884. " ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), diffuseColor.rgb, vec3( 0.0 ) );",
  13885. THREE.ShaderChunk[ "aomap_fragment" ],
  13886. THREE.ShaderChunk[ "shadowmap_fragment" ],
  13887. "reflectedLight.indirectDiffuse *= shadowMask;",
  13888. "vec3 outgoingLight = reflectedLight.indirectDiffuse;",
  13889. THREE.ShaderChunk[ "envmap_fragment" ],
  13890. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  13891. THREE.ShaderChunk[ "fog_fragment" ],
  13892. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  13893. "}"
  13894. ].join( "\n" )
  13895. },
  13896. 'lambert': {
  13897. uniforms: THREE.UniformsUtils.merge( [
  13898. THREE.UniformsLib[ "common" ],
  13899. THREE.UniformsLib[ "fog" ],
  13900. THREE.UniformsLib[ "lights" ],
  13901. THREE.UniformsLib[ "shadowmap" ],
  13902. {
  13903. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) }
  13904. }
  13905. ] ),
  13906. vertexShader: [
  13907. "#define LAMBERT",
  13908. "varying vec3 vLightFront;",
  13909. "#ifdef DOUBLE_SIDED",
  13910. " varying vec3 vLightBack;",
  13911. "#endif",
  13912. THREE.ShaderChunk[ "common" ],
  13913. THREE.ShaderChunk[ "uv_pars_vertex" ],
  13914. THREE.ShaderChunk[ "uv2_pars_vertex" ],
  13915. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  13916. THREE.ShaderChunk[ "bsdfs" ],
  13917. THREE.ShaderChunk[ "lights_pars" ],
  13918. THREE.ShaderChunk[ "color_pars_vertex" ],
  13919. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  13920. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  13921. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  13922. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  13923. "void main() {",
  13924. THREE.ShaderChunk[ "uv_vertex" ],
  13925. THREE.ShaderChunk[ "uv2_vertex" ],
  13926. THREE.ShaderChunk[ "color_vertex" ],
  13927. THREE.ShaderChunk[ "beginnormal_vertex" ],
  13928. THREE.ShaderChunk[ "morphnormal_vertex" ],
  13929. THREE.ShaderChunk[ "skinbase_vertex" ],
  13930. THREE.ShaderChunk[ "skinnormal_vertex" ],
  13931. THREE.ShaderChunk[ "defaultnormal_vertex" ],
  13932. THREE.ShaderChunk[ "begin_vertex" ],
  13933. THREE.ShaderChunk[ "morphtarget_vertex" ],
  13934. THREE.ShaderChunk[ "skinning_vertex" ],
  13935. THREE.ShaderChunk[ "project_vertex" ],
  13936. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  13937. THREE.ShaderChunk[ "worldpos_vertex" ],
  13938. THREE.ShaderChunk[ "envmap_vertex" ],
  13939. THREE.ShaderChunk[ "lights_lambert_vertex" ],
  13940. THREE.ShaderChunk[ "shadowmap_vertex" ],
  13941. "}"
  13942. ].join( "\n" ),
  13943. fragmentShader: [
  13944. "uniform vec3 diffuse;",
  13945. "uniform vec3 emissive;",
  13946. "uniform float opacity;",
  13947. "uniform vec3 ambientLightColor;",
  13948. "varying vec3 vLightFront;",
  13949. "#ifdef DOUBLE_SIDED",
  13950. " varying vec3 vLightBack;",
  13951. "#endif",
  13952. THREE.ShaderChunk[ "common" ],
  13953. THREE.ShaderChunk[ "color_pars_fragment" ],
  13954. THREE.ShaderChunk[ "uv_pars_fragment" ],
  13955. THREE.ShaderChunk[ "uv2_pars_fragment" ],
  13956. THREE.ShaderChunk[ "map_pars_fragment" ],
  13957. THREE.ShaderChunk[ "alphamap_pars_fragment" ],
  13958. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  13959. THREE.ShaderChunk[ "fog_pars_fragment" ],
  13960. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  13961. THREE.ShaderChunk[ "specularmap_pars_fragment" ],
  13962. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  13963. "void main() {",
  13964. " vec3 outgoingLight = vec3( 0.0 );", // outgoing light does not have an alpha, the surface does
  13965. " vec4 diffuseColor = vec4( diffuse, opacity );",
  13966. " vec3 totalAmbientLight = ambientLightColor;",
  13967. " vec3 shadowMask = vec3( 1.0 );",
  13968. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  13969. THREE.ShaderChunk[ "map_fragment" ],
  13970. THREE.ShaderChunk[ "color_fragment" ],
  13971. THREE.ShaderChunk[ "alphamap_fragment" ],
  13972. THREE.ShaderChunk[ "alphatest_fragment" ],
  13973. THREE.ShaderChunk[ "specularmap_fragment" ],
  13974. THREE.ShaderChunk[ "shadowmap_fragment" ],
  13975. " #ifdef DOUBLE_SIDED",
  13976. " if ( gl_FrontFacing )",
  13977. " outgoingLight += diffuseColor.rgb * ( vLightFront * shadowMask ) + emissive;",
  13978. " else",
  13979. " outgoingLight += diffuseColor.rgb * ( vLightBack * shadowMask ) + emissive;",
  13980. " #else",
  13981. " outgoingLight += diffuseColor.rgb * ( vLightFront * shadowMask ) + emissive;",
  13982. " #endif",
  13983. THREE.ShaderChunk[ "envmap_fragment" ],
  13984. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  13985. THREE.ShaderChunk[ "fog_fragment" ],
  13986. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  13987. "}"
  13988. ].join( "\n" )
  13989. },
  13990. 'phong': {
  13991. uniforms: THREE.UniformsUtils.merge( [
  13992. THREE.UniformsLib[ "common" ],
  13993. THREE.UniformsLib[ "aomap" ],
  13994. THREE.UniformsLib[ "lightmap" ],
  13995. THREE.UniformsLib[ "emissivemap" ],
  13996. THREE.UniformsLib[ "bumpmap" ],
  13997. THREE.UniformsLib[ "normalmap" ],
  13998. THREE.UniformsLib[ "displacementmap" ],
  13999. THREE.UniformsLib[ "fog" ],
  14000. THREE.UniformsLib[ "lights" ],
  14001. THREE.UniformsLib[ "shadowmap" ],
  14002. {
  14003. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) },
  14004. "specular" : { type: "c", value: new THREE.Color( 0x111111 ) },
  14005. "shininess": { type: "f", value: 30 }
  14006. }
  14007. ] ),
  14008. vertexShader: [
  14009. "#define PHONG",
  14010. "varying vec3 vViewPosition;",
  14011. "#ifndef FLAT_SHADED",
  14012. " varying vec3 vNormal;",
  14013. "#endif",
  14014. THREE.ShaderChunk[ "common" ],
  14015. THREE.ShaderChunk[ "uv_pars_vertex" ],
  14016. THREE.ShaderChunk[ "uv2_pars_vertex" ],
  14017. THREE.ShaderChunk[ "displacementmap_pars_vertex" ],
  14018. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  14019. THREE.ShaderChunk[ "lights_phong_pars_vertex" ],
  14020. THREE.ShaderChunk[ "color_pars_vertex" ],
  14021. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  14022. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  14023. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  14024. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  14025. "void main() {",
  14026. THREE.ShaderChunk[ "uv_vertex" ],
  14027. THREE.ShaderChunk[ "uv2_vertex" ],
  14028. THREE.ShaderChunk[ "color_vertex" ],
  14029. THREE.ShaderChunk[ "beginnormal_vertex" ],
  14030. THREE.ShaderChunk[ "morphnormal_vertex" ],
  14031. THREE.ShaderChunk[ "skinbase_vertex" ],
  14032. THREE.ShaderChunk[ "skinnormal_vertex" ],
  14033. THREE.ShaderChunk[ "defaultnormal_vertex" ],
  14034. "#ifndef FLAT_SHADED", // Normal computed with derivatives when FLAT_SHADED
  14035. " vNormal = normalize( transformedNormal );",
  14036. "#endif",
  14037. THREE.ShaderChunk[ "begin_vertex" ],
  14038. THREE.ShaderChunk[ "displacementmap_vertex" ],
  14039. THREE.ShaderChunk[ "morphtarget_vertex" ],
  14040. THREE.ShaderChunk[ "skinning_vertex" ],
  14041. THREE.ShaderChunk[ "project_vertex" ],
  14042. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  14043. " vViewPosition = - mvPosition.xyz;",
  14044. THREE.ShaderChunk[ "worldpos_vertex" ],
  14045. THREE.ShaderChunk[ "envmap_vertex" ],
  14046. THREE.ShaderChunk[ "lights_phong_vertex" ],
  14047. THREE.ShaderChunk[ "shadowmap_vertex" ],
  14048. "}"
  14049. ].join( "\n" ),
  14050. fragmentShader: [
  14051. "#define PHONG",
  14052. "uniform vec3 diffuse;",
  14053. "uniform vec3 emissive;",
  14054. "uniform vec3 specular;",
  14055. "uniform float shininess;",
  14056. "uniform float opacity;",
  14057. THREE.ShaderChunk[ "common" ],
  14058. THREE.ShaderChunk[ "color_pars_fragment" ],
  14059. THREE.ShaderChunk[ "uv_pars_fragment" ],
  14060. THREE.ShaderChunk[ "uv2_pars_fragment" ],
  14061. THREE.ShaderChunk[ "map_pars_fragment" ],
  14062. THREE.ShaderChunk[ "alphamap_pars_fragment" ],
  14063. THREE.ShaderChunk[ "aomap_pars_fragment" ],
  14064. THREE.ShaderChunk[ "lightmap_pars_fragment" ],
  14065. THREE.ShaderChunk[ "emissivemap_pars_fragment" ],
  14066. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  14067. THREE.ShaderChunk[ "fog_pars_fragment" ],
  14068. THREE.ShaderChunk[ "bsdfs" ],
  14069. THREE.ShaderChunk[ "lights_pars" ],
  14070. THREE.ShaderChunk[ "lights_phong_pars_fragment" ],
  14071. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  14072. THREE.ShaderChunk[ "bumpmap_pars_fragment" ],
  14073. THREE.ShaderChunk[ "normalmap_pars_fragment" ],
  14074. THREE.ShaderChunk[ "specularmap_pars_fragment" ],
  14075. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  14076. "void main() {",
  14077. " vec4 diffuseColor = vec4( diffuse, opacity );",
  14078. " ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );",
  14079. " vec3 totalEmissiveLight = emissive;",
  14080. " vec3 shadowMask = vec3( 1.0 );",
  14081. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  14082. THREE.ShaderChunk[ "map_fragment" ],
  14083. THREE.ShaderChunk[ "color_fragment" ],
  14084. THREE.ShaderChunk[ "alphamap_fragment" ],
  14085. THREE.ShaderChunk[ "alphatest_fragment" ],
  14086. THREE.ShaderChunk[ "specularmap_fragment" ],
  14087. THREE.ShaderChunk[ "normal_phong_fragment" ],
  14088. THREE.ShaderChunk[ "emissivemap_fragment" ],
  14089. // accumulation
  14090. THREE.ShaderChunk[ "lights_phong_fragment" ],
  14091. THREE.ShaderChunk[ "lights_template" ],
  14092. THREE.ShaderChunk[ "lightmap_fragment" ],
  14093. // modulation
  14094. THREE.ShaderChunk[ "aomap_fragment" ],
  14095. THREE.ShaderChunk[ "shadowmap_fragment" ],
  14096. "reflectedLight.directDiffuse *= shadowMask;",
  14097. "reflectedLight.directSpecular *= shadowMask;",
  14098. "vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveLight;",
  14099. THREE.ShaderChunk[ "envmap_fragment" ],
  14100. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  14101. THREE.ShaderChunk[ "fog_fragment" ],
  14102. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  14103. "}"
  14104. ].join( "\n" )
  14105. },
  14106. 'physical': {
  14107. uniforms: THREE.UniformsUtils.merge( [
  14108. THREE.UniformsLib[ "common" ],
  14109. THREE.UniformsLib[ "aomap" ],
  14110. THREE.UniformsLib[ "lightmap" ],
  14111. THREE.UniformsLib[ "emissivemap" ],
  14112. THREE.UniformsLib[ "bumpmap" ],
  14113. THREE.UniformsLib[ "normalmap" ],
  14114. THREE.UniformsLib[ "displacementmap" ],
  14115. THREE.UniformsLib[ "roughnessmap" ],
  14116. THREE.UniformsLib[ "reflectivitymap" ],
  14117. THREE.UniformsLib[ "metalnessmap" ],
  14118. THREE.UniformsLib[ "fog" ],
  14119. THREE.UniformsLib[ "lights" ],
  14120. THREE.UniformsLib[ "shadowmap" ],
  14121. {
  14122. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) },
  14123. "roughness": { type: "f", value: 0.5 },
  14124. "metalness": { type: "f", value: 0 },
  14125. "envMapIntensity" : { type: "f", value: 1 } // temporary
  14126. }
  14127. ] ),
  14128. vertexShader: [
  14129. "#define PHYSICAL",
  14130. "varying vec3 vViewPosition;",
  14131. "#ifndef FLAT_SHADED",
  14132. " varying vec3 vNormal;",
  14133. "#endif",
  14134. THREE.ShaderChunk[ "common" ],
  14135. THREE.ShaderChunk[ "uv_pars_vertex" ],
  14136. THREE.ShaderChunk[ "uv2_pars_vertex" ],
  14137. THREE.ShaderChunk[ "displacementmap_pars_vertex" ],
  14138. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  14139. THREE.ShaderChunk[ "lights_phong_pars_vertex" ], // use phong chunk for now
  14140. THREE.ShaderChunk[ "color_pars_vertex" ],
  14141. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  14142. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  14143. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  14144. THREE.ShaderChunk[ "specularmap_pars_fragment" ],
  14145. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  14146. "void main() {", // PHYSICAL
  14147. THREE.ShaderChunk[ "uv_vertex" ],
  14148. THREE.ShaderChunk[ "uv2_vertex" ],
  14149. THREE.ShaderChunk[ "color_vertex" ],
  14150. THREE.ShaderChunk[ "beginnormal_vertex" ],
  14151. THREE.ShaderChunk[ "morphnormal_vertex" ],
  14152. THREE.ShaderChunk[ "skinbase_vertex" ],
  14153. THREE.ShaderChunk[ "skinnormal_vertex" ],
  14154. THREE.ShaderChunk[ "defaultnormal_vertex" ],
  14155. "#ifndef FLAT_SHADED", // Normal computed with derivatives when FLAT_SHADED
  14156. " vNormal = normalize( transformedNormal );",
  14157. "#endif",
  14158. THREE.ShaderChunk[ "begin_vertex" ],
  14159. THREE.ShaderChunk[ "displacementmap_vertex" ],
  14160. THREE.ShaderChunk[ "morphtarget_vertex" ],
  14161. THREE.ShaderChunk[ "skinning_vertex" ],
  14162. THREE.ShaderChunk[ "project_vertex" ],
  14163. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  14164. " vViewPosition = - mvPosition.xyz;",
  14165. THREE.ShaderChunk[ "worldpos_vertex" ],
  14166. THREE.ShaderChunk[ "envmap_vertex" ],
  14167. THREE.ShaderChunk[ "lights_phong_vertex" ], // use phong chunk for now
  14168. THREE.ShaderChunk[ "shadowmap_vertex" ],
  14169. "}"
  14170. ].join( "\n" ),
  14171. fragmentShader: [
  14172. "#define PHYSICAL",
  14173. "uniform vec3 diffuse;",
  14174. "uniform vec3 emissive;",
  14175. "uniform float roughness;",
  14176. "uniform float metalness;",
  14177. "uniform float opacity;",
  14178. "uniform float envMapIntensity;", // temporary
  14179. "varying vec3 vViewPosition;",
  14180. "#ifndef FLAT_SHADED",
  14181. " varying vec3 vNormal;",
  14182. "#endif",
  14183. THREE.ShaderChunk[ "common" ],
  14184. THREE.ShaderChunk[ "color_pars_fragment" ],
  14185. THREE.ShaderChunk[ "uv_pars_fragment" ],
  14186. THREE.ShaderChunk[ "uv2_pars_fragment" ],
  14187. THREE.ShaderChunk[ "map_pars_fragment" ],
  14188. THREE.ShaderChunk[ "alphamap_pars_fragment" ],
  14189. THREE.ShaderChunk[ "aomap_pars_fragment" ],
  14190. THREE.ShaderChunk[ "lightmap_pars_fragment" ],
  14191. THREE.ShaderChunk[ "emissivemap_pars_fragment" ],
  14192. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  14193. THREE.ShaderChunk[ "fog_pars_fragment" ],
  14194. THREE.ShaderChunk[ "bsdfs" ],
  14195. THREE.ShaderChunk[ "lights_pars" ],
  14196. THREE.ShaderChunk[ "lights_physical_pars_fragment" ],
  14197. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  14198. THREE.ShaderChunk[ "bumpmap_pars_fragment" ],
  14199. THREE.ShaderChunk[ "normalmap_pars_fragment" ],
  14200. THREE.ShaderChunk[ "roughnessmap_pars_fragment" ],
  14201. //THREE.ShaderChunk[ "reflectivitymap_pars_fragment" ],
  14202. THREE.ShaderChunk[ "metalnessmap_pars_fragment" ],
  14203. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  14204. "void main() {",
  14205. " vec4 diffuseColor = vec4( diffuse, opacity );",
  14206. " ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );",
  14207. " vec3 totalEmissiveLight = emissive;",
  14208. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  14209. THREE.ShaderChunk[ "map_fragment" ],
  14210. THREE.ShaderChunk[ "color_fragment" ],
  14211. THREE.ShaderChunk[ "alphamap_fragment" ],
  14212. THREE.ShaderChunk[ "alphatest_fragment" ],
  14213. THREE.ShaderChunk[ "specularmap_fragment" ],
  14214. THREE.ShaderChunk[ "roughnessmap_fragment" ],
  14215. //THREE.ShaderChunk[ "reflectivitymap_fragment" ],
  14216. THREE.ShaderChunk[ "metalnessmap_fragment" ],
  14217. THREE.ShaderChunk[ "normal_phong_fragment" ], // use phong chunk for now
  14218. THREE.ShaderChunk[ "emissivemap_fragment" ],
  14219. // accumulation
  14220. THREE.ShaderChunk[ "lights_physical_fragment" ],
  14221. THREE.ShaderChunk[ "lights_template" ],
  14222. THREE.ShaderChunk[ "lightmap_fragment" ],
  14223. // modulation
  14224. THREE.ShaderChunk[ "aomap_fragment" ],
  14225. "vec3 shadowMask = vec3( 1.0 );",
  14226. THREE.ShaderChunk[ "shadowmap_fragment" ],
  14227. "reflectedLight.directDiffuse *= shadowMask;",
  14228. "reflectedLight.directSpecular *= shadowMask;",
  14229. "vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveLight;",
  14230. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  14231. THREE.ShaderChunk[ "fog_fragment" ],
  14232. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  14233. "}"
  14234. ].join( "\n" )
  14235. },
  14236. 'points': {
  14237. uniforms: THREE.UniformsUtils.merge( [
  14238. THREE.UniformsLib[ "points" ],
  14239. THREE.UniformsLib[ "shadowmap" ]
  14240. ] ),
  14241. vertexShader: [
  14242. "uniform float size;",
  14243. "uniform float scale;",
  14244. THREE.ShaderChunk[ "common" ],
  14245. THREE.ShaderChunk[ "color_pars_vertex" ],
  14246. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  14247. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  14248. "void main() {",
  14249. THREE.ShaderChunk[ "color_vertex" ],
  14250. " vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
  14251. " #ifdef USE_SIZEATTENUATION",
  14252. " gl_PointSize = size * ( scale / -mvPosition.z );",
  14253. " #else",
  14254. " gl_PointSize = size;",
  14255. " #endif",
  14256. " gl_Position = projectionMatrix * mvPosition;",
  14257. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  14258. THREE.ShaderChunk[ "worldpos_vertex" ],
  14259. THREE.ShaderChunk[ "shadowmap_vertex" ],
  14260. "}"
  14261. ].join( "\n" ),
  14262. fragmentShader: [
  14263. "uniform vec3 psColor;",
  14264. "uniform float opacity;",
  14265. THREE.ShaderChunk[ "common" ],
  14266. THREE.ShaderChunk[ "color_pars_fragment" ],
  14267. THREE.ShaderChunk[ "map_particle_pars_fragment" ],
  14268. THREE.ShaderChunk[ "fog_pars_fragment" ],
  14269. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  14270. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  14271. "void main() {",
  14272. " vec3 outgoingLight = vec3( 0.0 );",
  14273. " vec4 diffuseColor = vec4( psColor, opacity );",
  14274. " vec3 shadowMask = vec3( 1.0 );",
  14275. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  14276. THREE.ShaderChunk[ "map_particle_fragment" ],
  14277. THREE.ShaderChunk[ "color_fragment" ],
  14278. THREE.ShaderChunk[ "alphatest_fragment" ],
  14279. THREE.ShaderChunk[ "shadowmap_fragment" ],
  14280. " outgoingLight = diffuseColor.rgb * shadowMask;",
  14281. THREE.ShaderChunk[ "fog_fragment" ],
  14282. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  14283. "}"
  14284. ].join( "\n" )
  14285. },
  14286. 'dashed': {
  14287. uniforms: THREE.UniformsUtils.merge( [
  14288. THREE.UniformsLib[ "common" ],
  14289. THREE.UniformsLib[ "fog" ],
  14290. {
  14291. "scale" : { type: "f", value: 1 },
  14292. "dashSize" : { type: "f", value: 1 },
  14293. "totalSize": { type: "f", value: 2 }
  14294. }
  14295. ] ),
  14296. vertexShader: [
  14297. "uniform float scale;",
  14298. "attribute float lineDistance;",
  14299. "varying float vLineDistance;",
  14300. THREE.ShaderChunk[ "common" ],
  14301. THREE.ShaderChunk[ "color_pars_vertex" ],
  14302. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  14303. "void main() {",
  14304. THREE.ShaderChunk[ "color_vertex" ],
  14305. " vLineDistance = scale * lineDistance;",
  14306. " vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
  14307. " gl_Position = projectionMatrix * mvPosition;",
  14308. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  14309. "}"
  14310. ].join( "\n" ),
  14311. fragmentShader: [
  14312. "uniform vec3 diffuse;",
  14313. "uniform float opacity;",
  14314. "uniform float dashSize;",
  14315. "uniform float totalSize;",
  14316. "varying float vLineDistance;",
  14317. THREE.ShaderChunk[ "common" ],
  14318. THREE.ShaderChunk[ "color_pars_fragment" ],
  14319. THREE.ShaderChunk[ "fog_pars_fragment" ],
  14320. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  14321. "void main() {",
  14322. " if ( mod( vLineDistance, totalSize ) > dashSize ) {",
  14323. " discard;",
  14324. " }",
  14325. " vec3 outgoingLight = vec3( 0.0 );",
  14326. " vec4 diffuseColor = vec4( diffuse, opacity );",
  14327. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  14328. THREE.ShaderChunk[ "color_fragment" ],
  14329. " outgoingLight = diffuseColor.rgb;", // simple shader
  14330. THREE.ShaderChunk[ "fog_fragment" ],
  14331. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  14332. "}"
  14333. ].join( "\n" )
  14334. },
  14335. 'depth': {
  14336. uniforms: {
  14337. "mNear": { type: "f", value: 1.0 },
  14338. "mFar" : { type: "f", value: 2000.0 },
  14339. "opacity" : { type: "f", value: 1.0 }
  14340. },
  14341. vertexShader: [
  14342. THREE.ShaderChunk[ "common" ],
  14343. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  14344. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  14345. "void main() {",
  14346. THREE.ShaderChunk[ "begin_vertex" ],
  14347. THREE.ShaderChunk[ "morphtarget_vertex" ],
  14348. THREE.ShaderChunk[ "project_vertex" ],
  14349. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  14350. "}"
  14351. ].join( "\n" ),
  14352. fragmentShader: [
  14353. "uniform float mNear;",
  14354. "uniform float mFar;",
  14355. "uniform float opacity;",
  14356. THREE.ShaderChunk[ "common" ],
  14357. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  14358. "void main() {",
  14359. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  14360. " #ifdef USE_LOGDEPTHBUF_EXT",
  14361. " float depth = gl_FragDepthEXT / gl_FragCoord.w;",
  14362. " #else",
  14363. " float depth = gl_FragCoord.z / gl_FragCoord.w;",
  14364. " #endif",
  14365. " float color = 1.0 - smoothstep( mNear, mFar, depth );",
  14366. " gl_FragColor = vec4( vec3( color ), opacity );",
  14367. "}"
  14368. ].join( "\n" )
  14369. },
  14370. 'normal': {
  14371. uniforms: {
  14372. "opacity" : { type: "f", value: 1.0 }
  14373. },
  14374. vertexShader: [
  14375. "varying vec3 vNormal;",
  14376. THREE.ShaderChunk[ "common" ],
  14377. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  14378. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  14379. "void main() {",
  14380. " vNormal = normalize( normalMatrix * normal );",
  14381. THREE.ShaderChunk[ "begin_vertex" ],
  14382. THREE.ShaderChunk[ "morphtarget_vertex" ],
  14383. THREE.ShaderChunk[ "project_vertex" ],
  14384. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  14385. "}"
  14386. ].join( "\n" ),
  14387. fragmentShader: [
  14388. "uniform float opacity;",
  14389. "varying vec3 vNormal;",
  14390. THREE.ShaderChunk[ "common" ],
  14391. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  14392. "void main() {",
  14393. " gl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, opacity );",
  14394. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  14395. "}"
  14396. ].join( "\n" )
  14397. },
  14398. /* -------------------------------------------------------------------------
  14399. // Cube map shader
  14400. ------------------------------------------------------------------------- */
  14401. 'cube': {
  14402. uniforms: { "tCube": { type: "t", value: null },
  14403. "tFlip": { type: "f", value: - 1 } },
  14404. vertexShader: [
  14405. "varying vec3 vWorldPosition;",
  14406. THREE.ShaderChunk[ "common" ],
  14407. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  14408. "void main() {",
  14409. " vWorldPosition = transformDirection( position, modelMatrix );",
  14410. " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  14411. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  14412. "}"
  14413. ].join( "\n" ),
  14414. fragmentShader: [
  14415. "uniform samplerCube tCube;",
  14416. "uniform float tFlip;",
  14417. "varying vec3 vWorldPosition;",
  14418. THREE.ShaderChunk[ "common" ],
  14419. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  14420. "void main() {",
  14421. " gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );",
  14422. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  14423. "}"
  14424. ].join( "\n" )
  14425. },
  14426. /* -------------------------------------------------------------------------
  14427. // Cube map shader
  14428. ------------------------------------------------------------------------- */
  14429. 'equirect': {
  14430. uniforms: { "tEquirect": { type: "t", value: null },
  14431. "tFlip": { type: "f", value: - 1 } },
  14432. vertexShader: [
  14433. "varying vec3 vWorldPosition;",
  14434. THREE.ShaderChunk[ "common" ],
  14435. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  14436. "void main() {",
  14437. " vWorldPosition = transformDirection( position, modelMatrix );",
  14438. " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  14439. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  14440. "}"
  14441. ].join( "\n" ),
  14442. fragmentShader: [
  14443. "uniform sampler2D tEquirect;",
  14444. "uniform float tFlip;",
  14445. "varying vec3 vWorldPosition;",
  14446. THREE.ShaderChunk[ "common" ],
  14447. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  14448. "void main() {",
  14449. // " gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );",
  14450. "vec3 direction = normalize( vWorldPosition );",
  14451. "vec2 sampleUV;",
  14452. "sampleUV.y = saturate( tFlip * direction.y * -0.5 + 0.5 );",
  14453. "sampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;",
  14454. "gl_FragColor = texture2D( tEquirect, sampleUV );",
  14455. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  14456. "}"
  14457. ].join( "\n" )
  14458. },
  14459. /* Depth encoding into RGBA texture
  14460. *
  14461. * based on SpiderGL shadow map example
  14462. * http://spidergl.org/example.php?id=6
  14463. *
  14464. * originally from
  14465. * http://www.gamedev.net/topic/442138-packing-a-float-into-a-a8r8g8b8-texture-shader/page__whichpage__1%25EF%25BF%25BD
  14466. *
  14467. * see also
  14468. * http://aras-p.info/blog/2009/07/30/encoding-floats-to-rgba-the-final/
  14469. */
  14470. 'depthRGBA': {
  14471. uniforms: {},
  14472. vertexShader: [
  14473. THREE.ShaderChunk[ "common" ],
  14474. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  14475. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  14476. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  14477. "void main() {",
  14478. THREE.ShaderChunk[ "skinbase_vertex" ],
  14479. THREE.ShaderChunk[ "begin_vertex" ],
  14480. THREE.ShaderChunk[ "morphtarget_vertex" ],
  14481. THREE.ShaderChunk[ "skinning_vertex" ],
  14482. THREE.ShaderChunk[ "project_vertex" ],
  14483. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  14484. "}"
  14485. ].join( "\n" ),
  14486. fragmentShader: [
  14487. THREE.ShaderChunk[ "common" ],
  14488. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  14489. "vec4 pack_depth( const in float depth ) {",
  14490. " const vec4 bit_shift = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );",
  14491. " const vec4 bit_mask = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );",
  14492. " vec4 res = mod( depth * bit_shift * vec4( 255 ), vec4( 256 ) ) / vec4( 255 );", // " vec4 res = fract( depth * bit_shift );",
  14493. " res -= res.xxyz * bit_mask;",
  14494. " return res;",
  14495. "}",
  14496. "void main() {",
  14497. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  14498. " #ifdef USE_LOGDEPTHBUF_EXT",
  14499. " gl_FragData[ 0 ] = pack_depth( gl_FragDepthEXT );",
  14500. " #else",
  14501. " gl_FragData[ 0 ] = pack_depth( gl_FragCoord.z );",
  14502. " #endif",
  14503. //"gl_FragData[ 0 ] = pack_depth( gl_FragCoord.z / gl_FragCoord.w );",
  14504. //"float z = ( ( gl_FragCoord.z / gl_FragCoord.w ) - 3.0 ) / ( 4000.0 - 3.0 );",
  14505. //"gl_FragData[ 0 ] = pack_depth( z );",
  14506. //"gl_FragData[ 0 ] = vec4( z, z, z, 1.0 );",
  14507. "}"
  14508. ].join( "\n" )
  14509. },
  14510. 'distanceRGBA': {
  14511. uniforms: {
  14512. "lightPos": { type: "v3", value: new THREE.Vector3( 0, 0, 0 ) }
  14513. },
  14514. vertexShader: [
  14515. "varying vec4 vWorldPosition;",
  14516. THREE.ShaderChunk[ "common" ],
  14517. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  14518. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  14519. "void main() {",
  14520. THREE.ShaderChunk[ "skinbase_vertex" ],
  14521. THREE.ShaderChunk[ "begin_vertex" ],
  14522. THREE.ShaderChunk[ "morphtarget_vertex" ],
  14523. THREE.ShaderChunk[ "skinning_vertex" ],
  14524. THREE.ShaderChunk[ "project_vertex" ],
  14525. THREE.ShaderChunk[ "worldpos_vertex" ],
  14526. "vWorldPosition = worldPosition;",
  14527. "}"
  14528. ].join( "\n" ),
  14529. fragmentShader: [
  14530. "uniform vec3 lightPos;",
  14531. "varying vec4 vWorldPosition;",
  14532. THREE.ShaderChunk[ "common" ],
  14533. "vec4 pack1K ( float depth ) {",
  14534. " depth /= 1000.0;",
  14535. " const vec4 bitSh = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );",
  14536. " const vec4 bitMsk = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );",
  14537. " vec4 res = fract( depth * bitSh );",
  14538. " res -= res.xxyz * bitMsk;",
  14539. " return res; ",
  14540. "}",
  14541. "float unpack1K ( vec4 color ) {",
  14542. " const vec4 bitSh = vec4( 1.0 / ( 256.0 * 256.0 * 256.0 ), 1.0 / ( 256.0 * 256.0 ), 1.0 / 256.0, 1.0 );",
  14543. " return dot( color, bitSh ) * 1000.0;",
  14544. "}",
  14545. "void main () {",
  14546. " gl_FragColor = pack1K( length( vWorldPosition.xyz - lightPos.xyz ) );",
  14547. "}"
  14548. ].join( "\n" )
  14549. }
  14550. };
  14551. // File:src/renderers/WebGLRenderer.js
  14552. /**
  14553. * @author supereggbert / http://www.paulbrunt.co.uk/
  14554. * @author mrdoob / http://mrdoob.com/
  14555. * @author alteredq / http://alteredqualia.com/
  14556. * @author szimek / https://github.com/szimek/
  14557. */
  14558. THREE.WebGLRenderer = function ( parameters ) {
  14559. console.log( 'THREE.WebGLRenderer', THREE.REVISION );
  14560. parameters = parameters || {};
  14561. var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElement( 'canvas' ),
  14562. _context = parameters.context !== undefined ? parameters.context : null,
  14563. _width = _canvas.width,
  14564. _height = _canvas.height,
  14565. pixelRatio = 1,
  14566. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  14567. _depth = parameters.depth !== undefined ? parameters.depth : true,
  14568. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  14569. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  14570. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  14571. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  14572. _clearColor = new THREE.Color( 0x000000 ),
  14573. _clearAlpha = 0;
  14574. var lights = [];
  14575. var opaqueObjects = [];
  14576. var opaqueObjectsLastIndex = - 1;
  14577. var transparentObjects = [];
  14578. var transparentObjectsLastIndex = - 1;
  14579. var morphInfluences = new Float32Array( 8 );
  14580. var sprites = [];
  14581. var lensFlares = [];
  14582. // public properties
  14583. this.domElement = _canvas;
  14584. this.context = null;
  14585. // clearing
  14586. this.autoClear = true;
  14587. this.autoClearColor = true;
  14588. this.autoClearDepth = true;
  14589. this.autoClearStencil = true;
  14590. // scene graph
  14591. this.sortObjects = true;
  14592. // physically based shading
  14593. this.gammaFactor = 2.0; // for backwards compatibility
  14594. this.gammaInput = false;
  14595. this.gammaOutput = false;
  14596. // morphs
  14597. this.maxMorphTargets = 8;
  14598. this.maxMorphNormals = 4;
  14599. // flags
  14600. this.autoScaleCubemaps = true;
  14601. // internal properties
  14602. var _this = this,
  14603. // internal state cache
  14604. _currentProgram = null,
  14605. _currentFramebuffer = null,
  14606. _currentMaterialId = - 1,
  14607. _currentGeometryProgram = '',
  14608. _currentCamera = null,
  14609. _usedTextureUnits = 0,
  14610. _viewportX = 0,
  14611. _viewportY = 0,
  14612. _viewportWidth = _canvas.width,
  14613. _viewportHeight = _canvas.height,
  14614. _currentWidth = 0,
  14615. _currentHeight = 0,
  14616. // frustum
  14617. _frustum = new THREE.Frustum(),
  14618. // camera matrices cache
  14619. _projScreenMatrix = new THREE.Matrix4(),
  14620. _vector3 = new THREE.Vector3(),
  14621. // light arrays cache
  14622. _lights = {
  14623. hash: '',
  14624. ambient: [ 0, 0, 0 ],
  14625. directional: [],
  14626. point: [],
  14627. spot: [],
  14628. hemi: [],
  14629. shadows: 0,
  14630. shadowsPointLight: 0
  14631. },
  14632. // info
  14633. _infoMemory = {
  14634. geometries: 0,
  14635. textures: 0
  14636. },
  14637. _infoRender = {
  14638. calls: 0,
  14639. vertices: 0,
  14640. faces: 0,
  14641. points: 0
  14642. };
  14643. this.info = {
  14644. render: _infoRender,
  14645. memory: _infoMemory,
  14646. programs: null
  14647. };
  14648. // initialize
  14649. var _gl;
  14650. try {
  14651. var attributes = {
  14652. alpha: _alpha,
  14653. depth: _depth,
  14654. stencil: _stencil,
  14655. antialias: _antialias,
  14656. premultipliedAlpha: _premultipliedAlpha,
  14657. preserveDrawingBuffer: _preserveDrawingBuffer
  14658. };
  14659. _gl = _context || _canvas.getContext( 'webgl', attributes ) || _canvas.getContext( 'experimental-webgl', attributes );
  14660. if ( _gl === null ) {
  14661. if ( _canvas.getContext( 'webgl' ) !== null ) {
  14662. throw 'Error creating WebGL context with your selected attributes.';
  14663. } else {
  14664. throw 'Error creating WebGL context.';
  14665. }
  14666. }
  14667. _canvas.addEventListener( 'webglcontextlost', onContextLost, false );
  14668. } catch ( error ) {
  14669. console.error( 'THREE.WebGLRenderer: ' + error );
  14670. }
  14671. var extensions = new THREE.WebGLExtensions( _gl );
  14672. extensions.get( 'OES_texture_float' );
  14673. extensions.get( 'OES_texture_float_linear' );
  14674. extensions.get( 'OES_texture_half_float' );
  14675. extensions.get( 'OES_texture_half_float_linear' );
  14676. extensions.get( 'OES_standard_derivatives' );
  14677. extensions.get( 'ANGLE_instanced_arrays' );
  14678. if ( extensions.get( 'OES_element_index_uint' ) ) {
  14679. THREE.BufferGeometry.MaxIndex = 4294967296;
  14680. }
  14681. var capabilities = new THREE.WebGLCapabilities( _gl, extensions, parameters );
  14682. var state = new THREE.WebGLState( _gl, extensions, paramThreeToGL );
  14683. var properties = new THREE.WebGLProperties();
  14684. var objects = new THREE.WebGLObjects( _gl, properties, this.info );
  14685. var programCache = new THREE.WebGLPrograms( this, capabilities );
  14686. this.info.programs = programCache.programs;
  14687. var bufferRenderer = new THREE.WebGLBufferRenderer( _gl, extensions, _infoRender );
  14688. var indexedBufferRenderer = new THREE.WebGLIndexedBufferRenderer( _gl, extensions, _infoRender );
  14689. //
  14690. function glClearColor( r, g, b, a ) {
  14691. if ( _premultipliedAlpha === true ) {
  14692. r *= a; g *= a; b *= a;
  14693. }
  14694. _gl.clearColor( r, g, b, a );
  14695. }
  14696. function setDefaultGLState() {
  14697. state.init();
  14698. _gl.viewport( _viewportX, _viewportY, _viewportWidth, _viewportHeight );
  14699. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  14700. }
  14701. function resetGLState() {
  14702. _currentProgram = null;
  14703. _currentCamera = null;
  14704. _currentGeometryProgram = '';
  14705. _currentMaterialId = - 1;
  14706. state.reset();
  14707. }
  14708. setDefaultGLState();
  14709. this.context = _gl;
  14710. this.capabilities = capabilities;
  14711. this.extensions = extensions;
  14712. this.state = state;
  14713. // shadow map
  14714. var shadowMap = new THREE.WebGLShadowMap( this, lights, objects );
  14715. this.shadowMap = shadowMap;
  14716. // Plugins
  14717. var spritePlugin = new THREE.SpritePlugin( this, sprites );
  14718. var lensFlarePlugin = new THREE.LensFlarePlugin( this, lensFlares );
  14719. // API
  14720. this.getContext = function () {
  14721. return _gl;
  14722. };
  14723. this.getContextAttributes = function () {
  14724. return _gl.getContextAttributes();
  14725. };
  14726. this.forceContextLoss = function () {
  14727. extensions.get( 'WEBGL_lose_context' ).loseContext();
  14728. };
  14729. this.getMaxAnisotropy = ( function () {
  14730. var value;
  14731. return function getMaxAnisotropy() {
  14732. if ( value !== undefined ) return value;
  14733. var extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  14734. if ( extension !== null ) {
  14735. value = _gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );
  14736. } else {
  14737. value = 0;
  14738. }
  14739. return value;
  14740. }
  14741. } )();
  14742. this.getPrecision = function () {
  14743. return capabilities.precision;
  14744. };
  14745. this.getPixelRatio = function () {
  14746. return pixelRatio;
  14747. };
  14748. this.setPixelRatio = function ( value ) {
  14749. if ( value !== undefined ) pixelRatio = value;
  14750. };
  14751. this.getSize = function () {
  14752. return {
  14753. width: _width,
  14754. height: _height
  14755. };
  14756. };
  14757. this.setSize = function ( width, height, updateStyle ) {
  14758. _width = width;
  14759. _height = height;
  14760. _canvas.width = width * pixelRatio;
  14761. _canvas.height = height * pixelRatio;
  14762. if ( updateStyle !== false ) {
  14763. _canvas.style.width = width + 'px';
  14764. _canvas.style.height = height + 'px';
  14765. }
  14766. this.setViewport( 0, 0, width, height );
  14767. };
  14768. this.setViewport = function ( x, y, width, height ) {
  14769. _viewportX = x * pixelRatio;
  14770. _viewportY = y * pixelRatio;
  14771. _viewportWidth = width * pixelRatio;
  14772. _viewportHeight = height * pixelRatio;
  14773. _gl.viewport( _viewportX, _viewportY, _viewportWidth, _viewportHeight );
  14774. };
  14775. this.getViewport = function ( dimensions ) {
  14776. dimensions.x = _viewportX / pixelRatio;
  14777. dimensions.y = _viewportY / pixelRatio;
  14778. dimensions.z = _viewportWidth / pixelRatio;
  14779. dimensions.w = _viewportHeight / pixelRatio;
  14780. };
  14781. this.setScissor = function ( x, y, width, height ) {
  14782. _gl.scissor(
  14783. x * pixelRatio,
  14784. y * pixelRatio,
  14785. width * pixelRatio,
  14786. height * pixelRatio
  14787. );
  14788. };
  14789. this.enableScissorTest = function ( boolean ) {
  14790. state.setScissorTest( boolean );
  14791. };
  14792. // Clearing
  14793. this.getClearColor = function () {
  14794. return _clearColor;
  14795. };
  14796. this.setClearColor = function ( color, alpha ) {
  14797. _clearColor.set( color );
  14798. _clearAlpha = alpha !== undefined ? alpha : 1;
  14799. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  14800. };
  14801. this.getClearAlpha = function () {
  14802. return _clearAlpha;
  14803. };
  14804. this.setClearAlpha = function ( alpha ) {
  14805. _clearAlpha = alpha;
  14806. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  14807. };
  14808. this.clear = function ( color, depth, stencil ) {
  14809. var bits = 0;
  14810. if ( color === undefined || color ) bits |= _gl.COLOR_BUFFER_BIT;
  14811. if ( depth === undefined || depth ) bits |= _gl.DEPTH_BUFFER_BIT;
  14812. if ( stencil === undefined || stencil ) bits |= _gl.STENCIL_BUFFER_BIT;
  14813. _gl.clear( bits );
  14814. };
  14815. this.clearColor = function () {
  14816. _gl.clear( _gl.COLOR_BUFFER_BIT );
  14817. };
  14818. this.clearDepth = function () {
  14819. _gl.clear( _gl.DEPTH_BUFFER_BIT );
  14820. };
  14821. this.clearStencil = function () {
  14822. _gl.clear( _gl.STENCIL_BUFFER_BIT );
  14823. };
  14824. this.clearTarget = function ( renderTarget, color, depth, stencil ) {
  14825. this.setRenderTarget( renderTarget );
  14826. this.clear( color, depth, stencil );
  14827. };
  14828. // Reset
  14829. this.resetGLState = resetGLState;
  14830. this.dispose = function() {
  14831. _canvas.removeEventListener( 'webglcontextlost', onContextLost, false );
  14832. };
  14833. // Events
  14834. function onContextLost( event ) {
  14835. event.preventDefault();
  14836. resetGLState();
  14837. setDefaultGLState();
  14838. properties.clear();
  14839. };
  14840. function onTextureDispose( event ) {
  14841. var texture = event.target;
  14842. texture.removeEventListener( 'dispose', onTextureDispose );
  14843. deallocateTexture( texture );
  14844. _infoMemory.textures --;
  14845. }
  14846. function onRenderTargetDispose( event ) {
  14847. var renderTarget = event.target;
  14848. renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
  14849. deallocateRenderTarget( renderTarget );
  14850. _infoMemory.textures --;
  14851. }
  14852. function onMaterialDispose( event ) {
  14853. var material = event.target;
  14854. material.removeEventListener( 'dispose', onMaterialDispose );
  14855. deallocateMaterial( material );
  14856. }
  14857. // Buffer deallocation
  14858. function deallocateTexture( texture ) {
  14859. var textureProperties = properties.get( texture );
  14860. if ( texture.image && textureProperties.__image__webglTextureCube ) {
  14861. // cube texture
  14862. _gl.deleteTexture( textureProperties.__image__webglTextureCube );
  14863. } else {
  14864. // 2D texture
  14865. if ( textureProperties.__webglInit === undefined ) return;
  14866. _gl.deleteTexture( textureProperties.__webglTexture );
  14867. }
  14868. // remove all webgl properties
  14869. properties.delete( texture );
  14870. }
  14871. function deallocateRenderTarget( renderTarget ) {
  14872. var renderTargetProperties = properties.get( renderTarget );
  14873. var textureProperties = properties.get( renderTarget.texture );
  14874. if ( ! renderTarget || textureProperties.__webglTexture === undefined ) return;
  14875. _gl.deleteTexture( textureProperties.__webglTexture );
  14876. if ( renderTarget instanceof THREE.WebGLRenderTargetCube ) {
  14877. for ( var i = 0; i < 6; i ++ ) {
  14878. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] );
  14879. _gl.deleteRenderbuffer( renderTargetProperties.__webglRenderbuffer[ i ] );
  14880. }
  14881. } else {
  14882. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer );
  14883. _gl.deleteRenderbuffer( renderTargetProperties.__webglRenderbuffer );
  14884. }
  14885. properties.delete( renderTarget.texture );
  14886. properties.delete( renderTarget );
  14887. }
  14888. function deallocateMaterial( material ) {
  14889. releaseMaterialProgramReference( material );
  14890. properties.delete( material );
  14891. }
  14892. function releaseMaterialProgramReference( material ) {
  14893. var programInfo = properties.get( material ).program;
  14894. material.program = undefined;
  14895. if ( programInfo !== undefined ) {
  14896. programCache.releaseProgram( programInfo );
  14897. }
  14898. }
  14899. // Buffer rendering
  14900. this.renderBufferImmediate = function ( object, program, material ) {
  14901. state.initAttributes();
  14902. var buffers = properties.get( object );
  14903. if ( object.hasPositions && ! buffers.position ) buffers.position = _gl.createBuffer();
  14904. if ( object.hasNormals && ! buffers.normal ) buffers.normal = _gl.createBuffer();
  14905. if ( object.hasUvs && ! buffers.uv ) buffers.uv = _gl.createBuffer();
  14906. if ( object.hasColors && ! buffers.color ) buffers.color = _gl.createBuffer();
  14907. var attributes = program.getAttributes();
  14908. if ( object.hasPositions ) {
  14909. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.position );
  14910. _gl.bufferData( _gl.ARRAY_BUFFER, object.positionArray, _gl.DYNAMIC_DRAW );
  14911. state.enableAttribute( attributes.position );
  14912. _gl.vertexAttribPointer( attributes.position, 3, _gl.FLOAT, false, 0, 0 );
  14913. }
  14914. if ( object.hasNormals ) {
  14915. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.normal );
  14916. if ( material.type !== 'MeshPhongMaterial' && material.type !== 'MeshPhysicalMaterial' && material.shading === THREE.FlatShading ) {
  14917. for ( var i = 0, l = object.count * 3; i < l; i += 9 ) {
  14918. var array = object.normalArray;
  14919. var nx = ( array[ i + 0 ] + array[ i + 3 ] + array[ i + 6 ] ) / 3;
  14920. var ny = ( array[ i + 1 ] + array[ i + 4 ] + array[ i + 7 ] ) / 3;
  14921. var nz = ( array[ i + 2 ] + array[ i + 5 ] + array[ i + 8 ] ) / 3;
  14922. array[ i + 0 ] = nx;
  14923. array[ i + 1 ] = ny;
  14924. array[ i + 2 ] = nz;
  14925. array[ i + 3 ] = nx;
  14926. array[ i + 4 ] = ny;
  14927. array[ i + 5 ] = nz;
  14928. array[ i + 6 ] = nx;
  14929. array[ i + 7 ] = ny;
  14930. array[ i + 8 ] = nz;
  14931. }
  14932. }
  14933. _gl.bufferData( _gl.ARRAY_BUFFER, object.normalArray, _gl.DYNAMIC_DRAW );
  14934. state.enableAttribute( attributes.normal );
  14935. _gl.vertexAttribPointer( attributes.normal, 3, _gl.FLOAT, false, 0, 0 );
  14936. }
  14937. if ( object.hasUvs && material.map ) {
  14938. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.uv );
  14939. _gl.bufferData( _gl.ARRAY_BUFFER, object.uvArray, _gl.DYNAMIC_DRAW );
  14940. state.enableAttribute( attributes.uv );
  14941. _gl.vertexAttribPointer( attributes.uv, 2, _gl.FLOAT, false, 0, 0 );
  14942. }
  14943. if ( object.hasColors && material.vertexColors !== THREE.NoColors ) {
  14944. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.color );
  14945. _gl.bufferData( _gl.ARRAY_BUFFER, object.colorArray, _gl.DYNAMIC_DRAW );
  14946. state.enableAttribute( attributes.color );
  14947. _gl.vertexAttribPointer( attributes.color, 3, _gl.FLOAT, false, 0, 0 );
  14948. }
  14949. state.disableUnusedAttributes();
  14950. _gl.drawArrays( _gl.TRIANGLES, 0, object.count );
  14951. object.count = 0;
  14952. };
  14953. this.renderBufferDirect = function ( camera, lights, fog, geometry, material, object, group ) {
  14954. setMaterial( material );
  14955. var program = setProgram( camera, lights, fog, material, object );
  14956. var updateBuffers = false;
  14957. var geometryProgram = geometry.id + '_' + program.id + '_' + material.wireframe;
  14958. if ( geometryProgram !== _currentGeometryProgram ) {
  14959. _currentGeometryProgram = geometryProgram;
  14960. updateBuffers = true;
  14961. }
  14962. // morph targets
  14963. var morphTargetInfluences = object.morphTargetInfluences;
  14964. if ( morphTargetInfluences !== undefined ) {
  14965. var activeInfluences = [];
  14966. for ( var i = 0, l = morphTargetInfluences.length; i < l; i ++ ) {
  14967. var influence = morphTargetInfluences[ i ];
  14968. activeInfluences.push( [ influence, i ] );
  14969. }
  14970. activeInfluences.sort( numericalSort );
  14971. if ( activeInfluences.length > 8 ) {
  14972. activeInfluences.length = 8;
  14973. }
  14974. var morphAttributes = geometry.morphAttributes;
  14975. for ( var i = 0, l = activeInfluences.length; i < l; i ++ ) {
  14976. var influence = activeInfluences[ i ];
  14977. morphInfluences[ i ] = influence[ 0 ];
  14978. if ( influence[ 0 ] !== 0 ) {
  14979. var index = influence[ 1 ];
  14980. if ( material.morphTargets === true && morphAttributes.position ) geometry.addAttribute( 'morphTarget' + i, morphAttributes.position[ index ] );
  14981. if ( material.morphNormals === true && morphAttributes.normal ) geometry.addAttribute( 'morphNormal' + i, morphAttributes.normal[ index ] );
  14982. } else {
  14983. if ( material.morphTargets === true ) geometry.removeAttribute( 'morphTarget' + i );
  14984. if ( material.morphNormals === true ) geometry.removeAttribute( 'morphNormal' + i );
  14985. }
  14986. }
  14987. var uniforms = program.getUniforms();
  14988. if ( uniforms.morphTargetInfluences !== null ) {
  14989. _gl.uniform1fv( uniforms.morphTargetInfluences, morphInfluences );
  14990. }
  14991. updateBuffers = true;
  14992. }
  14993. //
  14994. var index = geometry.index;
  14995. var position = geometry.attributes.position;
  14996. if ( material.wireframe === true ) {
  14997. index = objects.getWireframeAttribute( geometry );
  14998. }
  14999. var renderer;
  15000. if ( index !== null ) {
  15001. renderer = indexedBufferRenderer;
  15002. renderer.setIndex( index );
  15003. } else {
  15004. renderer = bufferRenderer;
  15005. }
  15006. if ( updateBuffers ) {
  15007. setupVertexAttributes( material, program, geometry );
  15008. if ( index !== null ) {
  15009. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, objects.getAttributeBuffer( index ) );
  15010. }
  15011. }
  15012. //
  15013. var dataStart = 0;
  15014. var dataCount = Infinity;
  15015. if ( index !== null ) {
  15016. dataCount = index.count
  15017. } else if ( position !== undefined ) {
  15018. dataCount = position.count;
  15019. }
  15020. var rangeStart = geometry.drawRange.start;
  15021. var rangeCount = geometry.drawRange.count;
  15022. var groupStart = group !== null ? group.start : 0;
  15023. var groupCount = group !== null ? group.count : Infinity;
  15024. var drawStart = Math.max( dataStart, rangeStart, groupStart );
  15025. var drawEnd = Math.min( dataStart + dataCount, rangeStart + rangeCount, groupStart + groupCount ) - 1;
  15026. var drawCount = Math.max( 0, drawEnd - drawStart + 1 );
  15027. //
  15028. if ( object instanceof THREE.Mesh ) {
  15029. if ( material.wireframe === true ) {
  15030. state.setLineWidth( material.wireframeLinewidth * pixelRatio );
  15031. renderer.setMode( _gl.LINES );
  15032. } else {
  15033. switch ( object.drawMode ) {
  15034. case THREE.TrianglesDrawMode:
  15035. renderer.setMode( _gl.TRIANGLES );
  15036. break;
  15037. case THREE.TriangleStripDrawMode:
  15038. renderer.setMode( _gl.TRIANGLE_STRIP );
  15039. break;
  15040. case THREE.TriangleFanDrawMode:
  15041. renderer.setMode( _gl.TRIANGLE_FAN );
  15042. break;
  15043. }
  15044. }
  15045. if ( geometry instanceof THREE.InstancedBufferGeometry && geometry.maxInstancedCount > 0 ) {
  15046. renderer.renderInstances( geometry );
  15047. } else {
  15048. renderer.render( drawStart, drawCount );
  15049. }
  15050. } else if ( object instanceof THREE.Line ) {
  15051. var lineWidth = material.linewidth;
  15052. if ( lineWidth === undefined ) lineWidth = 1; // Not using Line*Material
  15053. state.setLineWidth( lineWidth * pixelRatio );
  15054. if ( object instanceof THREE.LineSegments ) {
  15055. renderer.setMode( _gl.LINES );
  15056. } else {
  15057. renderer.setMode( _gl.LINE_STRIP );
  15058. }
  15059. renderer.render( drawStart, drawCount );
  15060. } else if ( object instanceof THREE.Points ) {
  15061. renderer.setMode( _gl.POINTS );
  15062. renderer.render( drawStart, drawCount );
  15063. }
  15064. };
  15065. function setupVertexAttributes( material, program, geometry, startIndex ) {
  15066. var extension;
  15067. if ( geometry instanceof THREE.InstancedBufferGeometry ) {
  15068. extension = extensions.get( 'ANGLE_instanced_arrays' );
  15069. if ( extension === null ) {
  15070. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  15071. return;
  15072. }
  15073. }
  15074. if ( startIndex === undefined ) startIndex = 0;
  15075. state.initAttributes();
  15076. var geometryAttributes = geometry.attributes;
  15077. var programAttributes = program.getAttributes();
  15078. var materialDefaultAttributeValues = material.defaultAttributeValues;
  15079. for ( var name in programAttributes ) {
  15080. var programAttribute = programAttributes[ name ];
  15081. if ( programAttribute >= 0 ) {
  15082. var geometryAttribute = geometryAttributes[ name ];
  15083. if ( geometryAttribute !== undefined ) {
  15084. var size = geometryAttribute.itemSize;
  15085. var buffer = objects.getAttributeBuffer( geometryAttribute );
  15086. if ( geometryAttribute instanceof THREE.InterleavedBufferAttribute ) {
  15087. var data = geometryAttribute.data;
  15088. var stride = data.stride;
  15089. var offset = geometryAttribute.offset;
  15090. if ( data instanceof THREE.InstancedInterleavedBuffer ) {
  15091. state.enableAttributeAndDivisor( programAttribute, data.meshPerAttribute, extension );
  15092. if ( geometry.maxInstancedCount === undefined ) {
  15093. geometry.maxInstancedCount = data.meshPerAttribute * data.count;
  15094. }
  15095. } else {
  15096. state.enableAttribute( programAttribute );
  15097. }
  15098. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  15099. _gl.vertexAttribPointer( programAttribute, size, _gl.FLOAT, false, stride * data.array.BYTES_PER_ELEMENT, ( startIndex * stride + offset ) * data.array.BYTES_PER_ELEMENT );
  15100. } else {
  15101. if ( geometryAttribute instanceof THREE.InstancedBufferAttribute ) {
  15102. state.enableAttributeAndDivisor( programAttribute, geometryAttribute.meshPerAttribute, extension );
  15103. if ( geometry.maxInstancedCount === undefined ) {
  15104. geometry.maxInstancedCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  15105. }
  15106. } else {
  15107. state.enableAttribute( programAttribute );
  15108. }
  15109. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  15110. _gl.vertexAttribPointer( programAttribute, size, _gl.FLOAT, false, 0, startIndex * size * 4 ); // 4 bytes per Float32
  15111. }
  15112. } else if ( materialDefaultAttributeValues !== undefined ) {
  15113. var value = materialDefaultAttributeValues[ name ];
  15114. if ( value !== undefined ) {
  15115. switch ( value.length ) {
  15116. case 2:
  15117. _gl.vertexAttrib2fv( programAttribute, value );
  15118. break;
  15119. case 3:
  15120. _gl.vertexAttrib3fv( programAttribute, value );
  15121. break;
  15122. case 4:
  15123. _gl.vertexAttrib4fv( programAttribute, value );
  15124. break;
  15125. default:
  15126. _gl.vertexAttrib1fv( programAttribute, value );
  15127. }
  15128. }
  15129. }
  15130. }
  15131. }
  15132. state.disableUnusedAttributes();
  15133. }
  15134. // Sorting
  15135. function numericalSort ( a, b ) {
  15136. return b[ 0 ] - a[ 0 ];
  15137. }
  15138. function painterSortStable ( a, b ) {
  15139. if ( a.object.renderOrder !== b.object.renderOrder ) {
  15140. return a.object.renderOrder - b.object.renderOrder;
  15141. } else if ( a.material.id !== b.material.id ) {
  15142. return a.material.id - b.material.id;
  15143. } else if ( a.z !== b.z ) {
  15144. return a.z - b.z;
  15145. } else {
  15146. return a.id - b.id;
  15147. }
  15148. }
  15149. function reversePainterSortStable ( a, b ) {
  15150. if ( a.object.renderOrder !== b.object.renderOrder ) {
  15151. return a.object.renderOrder - b.object.renderOrder;
  15152. } if ( a.z !== b.z ) {
  15153. return b.z - a.z;
  15154. } else {
  15155. return a.id - b.id;
  15156. }
  15157. }
  15158. // Rendering
  15159. this.render = function ( scene, camera, renderTarget, forceClear ) {
  15160. if ( camera instanceof THREE.Camera === false ) {
  15161. console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
  15162. return;
  15163. }
  15164. var fog = scene.fog;
  15165. // reset caching for this frame
  15166. _currentGeometryProgram = '';
  15167. _currentMaterialId = - 1;
  15168. _currentCamera = null;
  15169. // update scene graph
  15170. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  15171. // update camera matrices and frustum
  15172. if ( camera.parent === null ) camera.updateMatrixWorld();
  15173. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  15174. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  15175. _frustum.setFromMatrix( _projScreenMatrix );
  15176. lights.length = 0;
  15177. opaqueObjectsLastIndex = - 1;
  15178. transparentObjectsLastIndex = - 1;
  15179. sprites.length = 0;
  15180. lensFlares.length = 0;
  15181. projectObject( scene, camera );
  15182. opaqueObjects.length = opaqueObjectsLastIndex + 1;
  15183. transparentObjects.length = transparentObjectsLastIndex + 1;
  15184. if ( _this.sortObjects === true ) {
  15185. opaqueObjects.sort( painterSortStable );
  15186. transparentObjects.sort( reversePainterSortStable );
  15187. }
  15188. setupLights( lights, camera );
  15189. //
  15190. shadowMap.render( scene, camera );
  15191. //
  15192. _infoRender.calls = 0;
  15193. _infoRender.vertices = 0;
  15194. _infoRender.faces = 0;
  15195. _infoRender.points = 0;
  15196. this.setRenderTarget( renderTarget );
  15197. if ( this.autoClear || forceClear ) {
  15198. this.clear( this.autoClearColor, this.autoClearDepth, this.autoClearStencil );
  15199. }
  15200. //
  15201. if ( scene.overrideMaterial ) {
  15202. var overrideMaterial = scene.overrideMaterial;
  15203. renderObjects( opaqueObjects, camera, lights, fog, overrideMaterial );
  15204. renderObjects( transparentObjects, camera, lights, fog, overrideMaterial );
  15205. } else {
  15206. // opaque pass (front-to-back order)
  15207. state.setBlending( THREE.NoBlending );
  15208. renderObjects( opaqueObjects, camera, lights, fog );
  15209. // transparent pass (back-to-front order)
  15210. renderObjects( transparentObjects, camera, lights, fog );
  15211. }
  15212. // custom render plugins (post pass)
  15213. spritePlugin.render( scene, camera );
  15214. lensFlarePlugin.render( scene, camera, _currentWidth, _currentHeight );
  15215. // Generate mipmap if we're using any kind of mipmap filtering
  15216. if ( renderTarget ) {
  15217. var texture = renderTarget.texture;
  15218. if ( texture.generateMipmaps && isPowerOfTwo( renderTarget ) &&
  15219. texture.minFilter !== THREE.NearestFilter &&
  15220. texture.minFilter !== THREE.LinearFilter ) {
  15221. updateRenderTargetMipmap( renderTarget );
  15222. }
  15223. }
  15224. // Ensure depth buffer writing is enabled so it can be cleared on next render
  15225. state.setDepthTest( true );
  15226. state.setDepthWrite( true );
  15227. state.setColorWrite( true );
  15228. // _gl.finish();
  15229. };
  15230. function pushRenderItem( object, geometry, material, z, group ) {
  15231. var array, index;
  15232. // allocate the next position in the appropriate array
  15233. if ( material.transparent ) {
  15234. array = transparentObjects;
  15235. index = ++ transparentObjectsLastIndex;
  15236. } else {
  15237. array = opaqueObjects;
  15238. index = ++ opaqueObjectsLastIndex;
  15239. }
  15240. // recycle existing render item or grow the array
  15241. var renderItem = array[ index ];
  15242. if ( renderItem !== undefined ) {
  15243. renderItem.id = object.id;
  15244. renderItem.object = object;
  15245. renderItem.geometry = geometry;
  15246. renderItem.material = material;
  15247. renderItem.z = _vector3.z;
  15248. renderItem.group = group;
  15249. } else {
  15250. renderItem = {
  15251. id: object.id,
  15252. object: object,
  15253. geometry: geometry,
  15254. material: material,
  15255. z: _vector3.z,
  15256. group: group
  15257. };
  15258. // assert( index === array.length );
  15259. array.push( renderItem );
  15260. }
  15261. }
  15262. function projectObject( object, camera ) {
  15263. if ( object.visible === false ) return;
  15264. if ( object.layers.test( camera.layers ) ) {
  15265. if ( object instanceof THREE.Light ) {
  15266. lights.push( object );
  15267. } else if ( object instanceof THREE.Sprite ) {
  15268. if ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) {
  15269. sprites.push( object );
  15270. }
  15271. } else if ( object instanceof THREE.LensFlare ) {
  15272. lensFlares.push( object );
  15273. } else if ( object instanceof THREE.ImmediateRenderObject ) {
  15274. if ( _this.sortObjects === true ) {
  15275. _vector3.setFromMatrixPosition( object.matrixWorld );
  15276. _vector3.applyProjection( _projScreenMatrix );
  15277. }
  15278. pushRenderItem( object, null, object.material, _vector3.z, null );
  15279. } else if ( object instanceof THREE.Mesh || object instanceof THREE.Line || object instanceof THREE.Points ) {
  15280. if ( object instanceof THREE.SkinnedMesh ) {
  15281. object.skeleton.update();
  15282. }
  15283. if ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) {
  15284. var material = object.material;
  15285. if ( material.visible === true ) {
  15286. if ( _this.sortObjects === true ) {
  15287. _vector3.setFromMatrixPosition( object.matrixWorld );
  15288. _vector3.applyProjection( _projScreenMatrix );
  15289. }
  15290. var geometry = objects.update( object );
  15291. if ( material instanceof THREE.MeshFaceMaterial ) {
  15292. var groups = geometry.groups;
  15293. var materials = material.materials;
  15294. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  15295. var group = groups[ i ];
  15296. var groupMaterial = materials[ group.materialIndex ];
  15297. if ( groupMaterial.visible === true ) {
  15298. pushRenderItem( object, geometry, groupMaterial, _vector3.z, group );
  15299. }
  15300. }
  15301. } else {
  15302. pushRenderItem( object, geometry, material, _vector3.z, null );
  15303. }
  15304. }
  15305. }
  15306. }
  15307. }
  15308. var children = object.children;
  15309. for ( var i = 0, l = children.length; i < l; i ++ ) {
  15310. projectObject( children[ i ], camera );
  15311. }
  15312. }
  15313. function renderObjects( renderList, camera, lights, fog, overrideMaterial ) {
  15314. for ( var i = 0, l = renderList.length; i < l; i ++ ) {
  15315. var renderItem = renderList[ i ];
  15316. var object = renderItem.object;
  15317. var geometry = renderItem.geometry;
  15318. var material = overrideMaterial === undefined ? renderItem.material : overrideMaterial;
  15319. var group = renderItem.group;
  15320. object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  15321. object.normalMatrix.getNormalMatrix( object.modelViewMatrix );
  15322. if ( object instanceof THREE.ImmediateRenderObject ) {
  15323. setMaterial( material );
  15324. var program = setProgram( camera, lights, fog, material, object );
  15325. _currentGeometryProgram = '';
  15326. object.render( function ( object ) {
  15327. _this.renderBufferImmediate( object, program, material );
  15328. } );
  15329. } else {
  15330. _this.renderBufferDirect( camera, lights, fog, geometry, material, object, group );
  15331. }
  15332. }
  15333. }
  15334. function initMaterial( material, lights, fog, object ) {
  15335. var materialProperties = properties.get( material );
  15336. var parameters = programCache.getParameters( material, _lights, fog, object );
  15337. var code = programCache.getProgramCode( material, parameters );
  15338. var program = materialProperties.program;
  15339. var programChange = true;
  15340. if ( program === undefined ) {
  15341. // new material
  15342. material.addEventListener( 'dispose', onMaterialDispose );
  15343. } else if ( program.code !== code ) {
  15344. // changed glsl or parameters
  15345. releaseMaterialProgramReference( material );
  15346. } else if ( parameters.shaderID !== undefined ) {
  15347. // same glsl and uniform list
  15348. return;
  15349. } else {
  15350. // only rebuild uniform list
  15351. programChange = false;
  15352. }
  15353. if ( programChange ) {
  15354. if ( parameters.shaderID ) {
  15355. var shader = THREE.ShaderLib[ parameters.shaderID ];
  15356. materialProperties.__webglShader = {
  15357. name: material.type,
  15358. uniforms: THREE.UniformsUtils.clone( shader.uniforms ),
  15359. vertexShader: shader.vertexShader,
  15360. fragmentShader: shader.fragmentShader
  15361. };
  15362. } else {
  15363. materialProperties.__webglShader = {
  15364. name: material.type,
  15365. uniforms: material.uniforms,
  15366. vertexShader: material.vertexShader,
  15367. fragmentShader: material.fragmentShader
  15368. };
  15369. }
  15370. material.__webglShader = materialProperties.__webglShader;
  15371. program = programCache.acquireProgram( material, parameters, code );
  15372. materialProperties.program = program;
  15373. material.program = program;
  15374. }
  15375. var attributes = program.getAttributes();
  15376. if ( material.morphTargets ) {
  15377. material.numSupportedMorphTargets = 0;
  15378. for ( var i = 0; i < _this.maxMorphTargets; i ++ ) {
  15379. if ( attributes[ 'morphTarget' + i ] >= 0 ) {
  15380. material.numSupportedMorphTargets ++;
  15381. }
  15382. }
  15383. }
  15384. if ( material.morphNormals ) {
  15385. material.numSupportedMorphNormals = 0;
  15386. for ( i = 0; i < _this.maxMorphNormals; i ++ ) {
  15387. if ( attributes[ 'morphNormal' + i ] >= 0 ) {
  15388. material.numSupportedMorphNormals ++;
  15389. }
  15390. }
  15391. }
  15392. materialProperties.uniformsList = [];
  15393. var uniforms = materialProperties.__webglShader.uniforms,
  15394. uniformLocations = materialProperties.program.getUniforms();
  15395. for ( var u in uniforms ) {
  15396. var location = uniformLocations[ u ];
  15397. if ( location ) {
  15398. materialProperties.uniformsList.push( [ materialProperties.__webglShader.uniforms[ u ], location ] );
  15399. }
  15400. }
  15401. if ( material instanceof THREE.MeshPhongMaterial ||
  15402. material instanceof THREE.MeshLambertMaterial ||
  15403. material instanceof THREE.MeshPhysicalMaterial ||
  15404. material.lights ) {
  15405. // store the light setup it was created for
  15406. materialProperties.lightsHash = _lights.hash;
  15407. // wire up the material to this renderer's lighting state
  15408. uniforms.ambientLightColor.value = _lights.ambient;
  15409. uniforms.directionalLights.value = _lights.directional;
  15410. uniforms.pointLights.value = _lights.point;
  15411. uniforms.spotLights.value = _lights.spot;
  15412. uniforms.hemisphereLights.value = _lights.hemi;
  15413. }
  15414. }
  15415. function setMaterial( material ) {
  15416. setMaterialFaces( material );
  15417. if ( material.transparent === true ) {
  15418. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha );
  15419. } else {
  15420. state.setBlending( THREE.NoBlending );
  15421. }
  15422. state.setDepthFunc( material.depthFunc );
  15423. state.setDepthTest( material.depthTest );
  15424. state.setDepthWrite( material.depthWrite );
  15425. state.setColorWrite( material.colorWrite );
  15426. state.setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  15427. }
  15428. function setMaterialFaces( material ) {
  15429. material.side !== THREE.DoubleSide ? state.enable( _gl.CULL_FACE ) : state.disable( _gl.CULL_FACE );
  15430. state.setFlipSided( material.side === THREE.BackSide );
  15431. }
  15432. function setProgram( camera, lights, fog, material, object ) {
  15433. _usedTextureUnits = 0;
  15434. var materialProperties = properties.get( material );
  15435. if ( materialProperties.program === undefined ) {
  15436. material.needsUpdate = true;
  15437. }
  15438. if ( materialProperties.lightsHash !== undefined &&
  15439. materialProperties.lightsHash !== _lights.hash ) {
  15440. material.needsUpdate = true;
  15441. }
  15442. if ( material.needsUpdate ) {
  15443. initMaterial( material, lights, fog, object );
  15444. material.needsUpdate = false;
  15445. }
  15446. var refreshProgram = false;
  15447. var refreshMaterial = false;
  15448. var refreshLights = false;
  15449. var program = materialProperties.program,
  15450. p_uniforms = program.getUniforms(),
  15451. m_uniforms = materialProperties.__webglShader.uniforms;
  15452. if ( program.id !== _currentProgram ) {
  15453. _gl.useProgram( program.program );
  15454. _currentProgram = program.id;
  15455. refreshProgram = true;
  15456. refreshMaterial = true;
  15457. refreshLights = true;
  15458. }
  15459. if ( material.id !== _currentMaterialId ) {
  15460. _currentMaterialId = material.id;
  15461. refreshMaterial = true;
  15462. }
  15463. if ( refreshProgram || camera !== _currentCamera ) {
  15464. _gl.uniformMatrix4fv( p_uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
  15465. if ( capabilities.logarithmicDepthBuffer ) {
  15466. _gl.uniform1f( p_uniforms.logDepthBufFC, 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
  15467. }
  15468. if ( camera !== _currentCamera ) {
  15469. _currentCamera = camera;
  15470. // lighting uniforms depend on the camera so enforce an update
  15471. // now, in case this material supports lights - or later, when
  15472. // the next material that does gets activated:
  15473. refreshMaterial = true; // set to true on material change
  15474. refreshLights = true; // remains set until update done
  15475. }
  15476. // load material specific uniforms
  15477. // (shader material also gets them for the sake of genericity)
  15478. if ( material instanceof THREE.ShaderMaterial ||
  15479. material instanceof THREE.MeshPhongMaterial ||
  15480. material instanceof THREE.MeshPhysicalMaterial ||
  15481. material.envMap ) {
  15482. if ( p_uniforms.cameraPosition !== undefined ) {
  15483. _vector3.setFromMatrixPosition( camera.matrixWorld );
  15484. _gl.uniform3f( p_uniforms.cameraPosition, _vector3.x, _vector3.y, _vector3.z );
  15485. }
  15486. }
  15487. if ( material instanceof THREE.MeshPhongMaterial ||
  15488. material instanceof THREE.MeshLambertMaterial ||
  15489. material instanceof THREE.MeshBasicMaterial ||
  15490. material instanceof THREE.MeshPhysicalMaterial ||
  15491. material instanceof THREE.ShaderMaterial ||
  15492. material.skinning ) {
  15493. if ( p_uniforms.viewMatrix !== undefined ) {
  15494. _gl.uniformMatrix4fv( p_uniforms.viewMatrix, false, camera.matrixWorldInverse.elements );
  15495. }
  15496. }
  15497. }
  15498. // skinning uniforms must be set even if material didn't change
  15499. // auto-setting of texture unit for bone texture must go before other textures
  15500. // not sure why, but otherwise weird things happen
  15501. if ( material.skinning ) {
  15502. if ( object.bindMatrix && p_uniforms.bindMatrix !== undefined ) {
  15503. _gl.uniformMatrix4fv( p_uniforms.bindMatrix, false, object.bindMatrix.elements );
  15504. }
  15505. if ( object.bindMatrixInverse && p_uniforms.bindMatrixInverse !== undefined ) {
  15506. _gl.uniformMatrix4fv( p_uniforms.bindMatrixInverse, false, object.bindMatrixInverse.elements );
  15507. }
  15508. if ( capabilities.floatVertexTextures && object.skeleton && object.skeleton.useVertexTexture ) {
  15509. if ( p_uniforms.boneTexture !== undefined ) {
  15510. var textureUnit = getTextureUnit();
  15511. _gl.uniform1i( p_uniforms.boneTexture, textureUnit );
  15512. _this.setTexture( object.skeleton.boneTexture, textureUnit );
  15513. }
  15514. if ( p_uniforms.boneTextureWidth !== undefined ) {
  15515. _gl.uniform1i( p_uniforms.boneTextureWidth, object.skeleton.boneTextureWidth );
  15516. }
  15517. if ( p_uniforms.boneTextureHeight !== undefined ) {
  15518. _gl.uniform1i( p_uniforms.boneTextureHeight, object.skeleton.boneTextureHeight );
  15519. }
  15520. } else if ( object.skeleton && object.skeleton.boneMatrices ) {
  15521. if ( p_uniforms.boneGlobalMatrices !== undefined ) {
  15522. _gl.uniformMatrix4fv( p_uniforms.boneGlobalMatrices, false, object.skeleton.boneMatrices );
  15523. }
  15524. }
  15525. }
  15526. if ( refreshMaterial ) {
  15527. if ( material instanceof THREE.MeshPhongMaterial ||
  15528. material instanceof THREE.MeshLambertMaterial ||
  15529. material instanceof THREE.MeshPhysicalMaterial ||
  15530. material.lights ) {
  15531. // the current material requires lighting info
  15532. // note: all lighting uniforms are always set correctly
  15533. // they simply reference the renderer's state for their
  15534. // values
  15535. //
  15536. // use the current material's .needsUpdate flags to set
  15537. // the GL state when required
  15538. markUniformsLightsNeedsUpdate( m_uniforms, refreshLights );
  15539. }
  15540. // refresh uniforms common to several materials
  15541. if ( fog && material.fog ) {
  15542. refreshUniformsFog( m_uniforms, fog );
  15543. }
  15544. if ( material instanceof THREE.MeshBasicMaterial ||
  15545. material instanceof THREE.MeshLambertMaterial ||
  15546. material instanceof THREE.MeshPhongMaterial ||
  15547. material instanceof THREE.MeshPhysicalMaterial ) {
  15548. refreshUniformsCommon( m_uniforms, material );
  15549. }
  15550. // refresh single material specific uniforms
  15551. if ( material instanceof THREE.LineBasicMaterial ) {
  15552. refreshUniformsLine( m_uniforms, material );
  15553. } else if ( material instanceof THREE.LineDashedMaterial ) {
  15554. refreshUniformsLine( m_uniforms, material );
  15555. refreshUniformsDash( m_uniforms, material );
  15556. } else if ( material instanceof THREE.PointsMaterial ) {
  15557. refreshUniformsPoints( m_uniforms, material );
  15558. } else if ( material instanceof THREE.MeshPhongMaterial ) {
  15559. refreshUniformsPhong( m_uniforms, material );
  15560. } else if ( material instanceof THREE.MeshPhysicalMaterial ) {
  15561. refreshUniformsPhysical( m_uniforms, material );
  15562. } else if ( material instanceof THREE.MeshDepthMaterial ) {
  15563. m_uniforms.mNear.value = camera.near;
  15564. m_uniforms.mFar.value = camera.far;
  15565. m_uniforms.opacity.value = material.opacity;
  15566. } else if ( material instanceof THREE.MeshNormalMaterial ) {
  15567. m_uniforms.opacity.value = material.opacity;
  15568. }
  15569. if ( shadowMap.enabled ) {
  15570. if ( object.receiveShadow && ! material._shadowPass ) {
  15571. refreshUniformsShadow( m_uniforms, lights, camera );
  15572. }
  15573. }
  15574. // load common uniforms
  15575. loadUniformsGeneric( materialProperties.uniformsList );
  15576. }
  15577. loadUniformsMatrices( p_uniforms, object );
  15578. if ( p_uniforms.modelMatrix !== undefined ) {
  15579. _gl.uniformMatrix4fv( p_uniforms.modelMatrix, false, object.matrixWorld.elements );
  15580. }
  15581. return program;
  15582. }
  15583. // Uniforms (refresh uniforms objects)
  15584. function refreshUniformsCommon ( uniforms, material ) {
  15585. uniforms.opacity.value = material.opacity;
  15586. uniforms.diffuse.value = material.color;
  15587. if ( material.emissive ) {
  15588. uniforms.emissive.value = material.emissive;
  15589. }
  15590. uniforms.map.value = material.map;
  15591. uniforms.specularMap.value = material.specularMap;
  15592. uniforms.alphaMap.value = material.alphaMap;
  15593. if ( material.aoMap ) {
  15594. uniforms.aoMap.value = material.aoMap;
  15595. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  15596. }
  15597. // uv repeat and offset setting priorities
  15598. // 1. color map
  15599. // 2. specular map
  15600. // 3. normal map
  15601. // 4. bump map
  15602. // 5. alpha map
  15603. // 6. emissive map
  15604. var uvScaleMap;
  15605. if ( material.map ) {
  15606. uvScaleMap = material.map;
  15607. } else if ( material.specularMap ) {
  15608. uvScaleMap = material.specularMap;
  15609. } else if ( material.displacementMap ) {
  15610. uvScaleMap = material.displacementMap;
  15611. } else if ( material.normalMap ) {
  15612. uvScaleMap = material.normalMap;
  15613. } else if ( material.bumpMap ) {
  15614. uvScaleMap = material.bumpMap;
  15615. } else if ( material.alphaMap ) {
  15616. uvScaleMap = material.alphaMap;
  15617. } else if ( material.emissiveMap ) {
  15618. uvScaleMap = material.emissiveMap;
  15619. }
  15620. if ( uvScaleMap !== undefined ) {
  15621. if ( uvScaleMap instanceof THREE.WebGLRenderTarget ) uvScaleMap = uvScaleMap.texture;
  15622. var offset = uvScaleMap.offset;
  15623. var repeat = uvScaleMap.repeat;
  15624. uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
  15625. }
  15626. uniforms.envMap.value = material.envMap;
  15627. uniforms.flipEnvMap.value = ( material.envMap instanceof THREE.WebGLRenderTargetCube ) ? 1 : - 1;
  15628. uniforms.reflectivity.value = material.reflectivity;
  15629. uniforms.refractionRatio.value = material.refractionRatio;
  15630. }
  15631. function refreshUniformsLine ( uniforms, material ) {
  15632. uniforms.diffuse.value = material.color;
  15633. uniforms.opacity.value = material.opacity;
  15634. }
  15635. function refreshUniformsDash ( uniforms, material ) {
  15636. uniforms.dashSize.value = material.dashSize;
  15637. uniforms.totalSize.value = material.dashSize + material.gapSize;
  15638. uniforms.scale.value = material.scale;
  15639. }
  15640. function refreshUniformsPoints ( uniforms, material ) {
  15641. uniforms.psColor.value = material.color;
  15642. uniforms.opacity.value = material.opacity;
  15643. uniforms.size.value = material.size * pixelRatio;
  15644. uniforms.scale.value = _canvas.height / 2.0; // TODO: Cache this.
  15645. uniforms.map.value = material.map;
  15646. if ( material.map !== null ) {
  15647. var offset = material.map.offset;
  15648. var repeat = material.map.repeat;
  15649. uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
  15650. }
  15651. }
  15652. function refreshUniformsFog ( uniforms, fog ) {
  15653. uniforms.fogColor.value = fog.color;
  15654. if ( fog instanceof THREE.Fog ) {
  15655. uniforms.fogNear.value = fog.near;
  15656. uniforms.fogFar.value = fog.far;
  15657. } else if ( fog instanceof THREE.FogExp2 ) {
  15658. uniforms.fogDensity.value = fog.density;
  15659. }
  15660. }
  15661. function refreshUniformsPhong ( uniforms, material ) {
  15662. uniforms.specular.value = material.specular;
  15663. uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 )
  15664. if ( material.lightMap ) {
  15665. uniforms.lightMap.value = material.lightMap;
  15666. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  15667. }
  15668. if ( material.emissiveMap ) {
  15669. uniforms.emissiveMap.value = material.emissiveMap;
  15670. }
  15671. if ( material.bumpMap ) {
  15672. uniforms.bumpMap.value = material.bumpMap;
  15673. uniforms.bumpScale.value = material.bumpScale;
  15674. }
  15675. if ( material.normalMap ) {
  15676. uniforms.normalMap.value = material.normalMap;
  15677. uniforms.normalScale.value.copy( material.normalScale );
  15678. }
  15679. if ( material.displacementMap ) {
  15680. uniforms.displacementMap.value = material.displacementMap;
  15681. uniforms.displacementScale.value = material.displacementScale;
  15682. uniforms.displacementBias.value = material.displacementBias;
  15683. }
  15684. }
  15685. function refreshUniformsPhysical ( uniforms, material ) {
  15686. uniforms.roughness.value = material.roughness;
  15687. //uniforms.reflectivity.value = material.reflectivity; // part of uniforms common
  15688. uniforms.metalness.value = material.metalness;
  15689. if ( material.roughnessMap ) {
  15690. uniforms.roughnessMap.value = material.roughnessMap;
  15691. }
  15692. if ( material.reflectivityMap ) {
  15693. uniforms.reflectivityMap.value = material.reflectivityMap;
  15694. }
  15695. if ( material.metalnessMap ) {
  15696. uniforms.metalnessMap.value = material.metalnessMap;
  15697. }
  15698. if ( material.lightMap ) {
  15699. uniforms.lightMap.value = material.lightMap;
  15700. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  15701. }
  15702. if ( material.emissiveMap ) {
  15703. uniforms.emissiveMap.value = material.emissiveMap;
  15704. }
  15705. if ( material.bumpMap ) {
  15706. uniforms.bumpMap.value = material.bumpMap;
  15707. uniforms.bumpScale.value = material.bumpScale;
  15708. }
  15709. if ( material.normalMap ) {
  15710. uniforms.normalMap.value = material.normalMap;
  15711. uniforms.normalScale.value.copy( material.normalScale );
  15712. }
  15713. if ( material.displacementMap ) {
  15714. uniforms.displacementMap.value = material.displacementMap;
  15715. uniforms.displacementScale.value = material.displacementScale;
  15716. uniforms.displacementBias.value = material.displacementBias;
  15717. }
  15718. if ( material.envMap ) {
  15719. //uniforms.envMap.value = material.envMap; // part of uniforms common
  15720. uniforms.envMapIntensity.value = material.envMapIntensity;
  15721. }
  15722. }
  15723. // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  15724. function markUniformsLightsNeedsUpdate ( uniforms, value ) {
  15725. uniforms.ambientLightColor.needsUpdate = value;
  15726. uniforms.directionalLights.needsUpdate = value;
  15727. uniforms.pointLights.needsUpdate = value;
  15728. uniforms.spotLights.needsUpdate = value;
  15729. uniforms.hemisphereLights.needsUpdate = value;
  15730. }
  15731. function refreshUniformsShadow ( uniforms, lights, camera ) {
  15732. if ( uniforms.shadowMatrix ) {
  15733. var j = 0;
  15734. for ( var i = 0, il = lights.length; i < il; i ++ ) {
  15735. var light = lights[ i ];
  15736. if ( light.castShadow === true ) {
  15737. if ( light instanceof THREE.PointLight || light instanceof THREE.SpotLight || light instanceof THREE.DirectionalLight ) {
  15738. var shadow = light.shadow;
  15739. if ( light instanceof THREE.PointLight ) {
  15740. // for point lights we set the shadow matrix to be a translation-only matrix
  15741. // equal to inverse of the light's position
  15742. _vector3.setFromMatrixPosition( light.matrixWorld ).negate();
  15743. shadow.matrix.identity().setPosition( _vector3 );
  15744. // for point lights we set the sign of the shadowDarkness uniform to be negative
  15745. uniforms.shadowDarkness.value[ j ] = - shadow.darkness;
  15746. } else {
  15747. uniforms.shadowDarkness.value[ j ] = shadow.darkness;
  15748. }
  15749. uniforms.shadowMatrix.value[ j ] = shadow.matrix;
  15750. uniforms.shadowMap.value[ j ] = shadow.map;
  15751. uniforms.shadowMapSize.value[ j ] = shadow.mapSize;
  15752. uniforms.shadowBias.value[ j ] = shadow.bias;
  15753. j ++;
  15754. }
  15755. }
  15756. }
  15757. }
  15758. }
  15759. // Uniforms (load to GPU)
  15760. function loadUniformsMatrices ( uniforms, object ) {
  15761. _gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, object.modelViewMatrix.elements );
  15762. if ( uniforms.normalMatrix ) {
  15763. _gl.uniformMatrix3fv( uniforms.normalMatrix, false, object.normalMatrix.elements );
  15764. }
  15765. }
  15766. function getTextureUnit() {
  15767. var textureUnit = _usedTextureUnits;
  15768. if ( textureUnit >= capabilities.maxTextures ) {
  15769. console.warn( 'WebGLRenderer: trying to use ' + textureUnit + ' texture units while this GPU supports only ' + capabilities.maxTextures );
  15770. }
  15771. _usedTextureUnits += 1;
  15772. return textureUnit;
  15773. }
  15774. function loadUniformsGeneric ( uniforms ) {
  15775. var texture, textureUnit;
  15776. for ( var j = 0, jl = uniforms.length; j < jl; j ++ ) {
  15777. var uniform = uniforms[ j ][ 0 ];
  15778. // needsUpdate property is not added to all uniforms.
  15779. if ( uniform.needsUpdate === false ) continue;
  15780. var type = uniform.type;
  15781. var value = uniform.value;
  15782. var location = uniforms[ j ][ 1 ];
  15783. switch ( type ) {
  15784. case '1i':
  15785. _gl.uniform1i( location, value );
  15786. break;
  15787. case '1f':
  15788. _gl.uniform1f( location, value );
  15789. break;
  15790. case '2f':
  15791. _gl.uniform2f( location, value[ 0 ], value[ 1 ] );
  15792. break;
  15793. case '3f':
  15794. _gl.uniform3f( location, value[ 0 ], value[ 1 ], value[ 2 ] );
  15795. break;
  15796. case '4f':
  15797. _gl.uniform4f( location, value[ 0 ], value[ 1 ], value[ 2 ], value[ 3 ] );
  15798. break;
  15799. case '1iv':
  15800. _gl.uniform1iv( location, value );
  15801. break;
  15802. case '3iv':
  15803. _gl.uniform3iv( location, value );
  15804. break;
  15805. case '1fv':
  15806. _gl.uniform1fv( location, value );
  15807. break;
  15808. case '2fv':
  15809. _gl.uniform2fv( location, value );
  15810. break;
  15811. case '3fv':
  15812. _gl.uniform3fv( location, value );
  15813. break;
  15814. case '4fv':
  15815. _gl.uniform4fv( location, value );
  15816. break;
  15817. case 'Matrix3fv':
  15818. _gl.uniformMatrix3fv( location, false, value );
  15819. break;
  15820. case 'Matrix4fv':
  15821. _gl.uniformMatrix4fv( location, false, value );
  15822. break;
  15823. //
  15824. case 'i':
  15825. // single integer
  15826. _gl.uniform1i( location, value );
  15827. break;
  15828. case 'f':
  15829. // single float
  15830. _gl.uniform1f( location, value );
  15831. break;
  15832. case 'v2':
  15833. // single THREE.Vector2
  15834. _gl.uniform2f( location, value.x, value.y );
  15835. break;
  15836. case 'v3':
  15837. // single THREE.Vector3
  15838. _gl.uniform3f( location, value.x, value.y, value.z );
  15839. break;
  15840. case 'v4':
  15841. // single THREE.Vector4
  15842. _gl.uniform4f( location, value.x, value.y, value.z, value.w );
  15843. break;
  15844. case 'c':
  15845. // single THREE.Color
  15846. _gl.uniform3f( location, value.r, value.g, value.b );
  15847. break;
  15848. case 's':
  15849. // TODO: Optimize this.
  15850. for( var propertyName in uniform.properties ) {
  15851. var property = uniform.properties[ propertyName ];
  15852. var locationProperty = location[ propertyName ];
  15853. var valueProperty = value[ propertyName ];
  15854. switch( property.type ) {
  15855. case 'f':
  15856. _gl.uniform1f( locationProperty, valueProperty );
  15857. break;
  15858. case 'v2':
  15859. _gl.uniform2f( locationProperty, valueProperty.x, valueProperty.y );
  15860. break;
  15861. case 'v3':
  15862. _gl.uniform3f( locationProperty, valueProperty.x, valueProperty.y, valueProperty.z );
  15863. break;
  15864. case 'v4':
  15865. _gl.uniform4f( locationProperty, valueProperty.x, valueProperty.y, valueProperty.z, valueProperty.w );
  15866. break;
  15867. case 'c':
  15868. _gl.uniform3f( locationProperty, valueProperty.r, valueProperty.g, valueProperty.b );
  15869. break;
  15870. };
  15871. }
  15872. break;
  15873. case 'sa':
  15874. // TODO: Optimize this.
  15875. for( var i = 0; i < value.length; i ++ ) {
  15876. for( var propertyName in uniform.properties ) {
  15877. var property = uniform.properties[ propertyName ];
  15878. var locationProperty = location[ i ][ propertyName ];
  15879. var valueProperty = value[i][ propertyName ];
  15880. switch( property.type ) {
  15881. case 'f':
  15882. _gl.uniform1f( locationProperty, valueProperty );
  15883. break;
  15884. case 'v2':
  15885. _gl.uniform2f( locationProperty, valueProperty.x, valueProperty.y );
  15886. break;
  15887. case 'v3':
  15888. _gl.uniform3f( locationProperty, valueProperty.x, valueProperty.y, valueProperty.z );
  15889. break;
  15890. case 'v4':
  15891. _gl.uniform4f( locationProperty, valueProperty.x, valueProperty.y, valueProperty.z, valueProperty.w );
  15892. break;
  15893. case 'c':
  15894. _gl.uniform3f( locationProperty, valueProperty.r, valueProperty.g, valueProperty.b );
  15895. break;
  15896. };
  15897. }
  15898. }
  15899. break;
  15900. case 'iv1':
  15901. // flat array of integers (JS or typed array)
  15902. _gl.uniform1iv( location, value );
  15903. break;
  15904. case 'iv':
  15905. // flat array of integers with 3 x N size (JS or typed array)
  15906. _gl.uniform3iv( location, value );
  15907. break;
  15908. case 'fv1':
  15909. // flat array of floats (JS or typed array)
  15910. _gl.uniform1fv( location, value );
  15911. break;
  15912. case 'fv':
  15913. // flat array of floats with 3 x N size (JS or typed array)
  15914. _gl.uniform3fv( location, value );
  15915. break;
  15916. case 'v2v':
  15917. // array of THREE.Vector2
  15918. if ( uniform._array === undefined ) {
  15919. uniform._array = new Float32Array( 2 * value.length );
  15920. }
  15921. for ( var i = 0, i2 = 0, il = value.length; i < il; i ++, i2 += 2 ) {
  15922. uniform._array[ i2 + 0 ] = value[ i ].x;
  15923. uniform._array[ i2 + 1 ] = value[ i ].y;
  15924. }
  15925. _gl.uniform2fv( location, uniform._array );
  15926. break;
  15927. case 'v3v':
  15928. // array of THREE.Vector3
  15929. if ( uniform._array === undefined ) {
  15930. uniform._array = new Float32Array( 3 * value.length );
  15931. }
  15932. for ( var i = 0, i3 = 0, il = value.length; i < il; i ++, i3 += 3 ) {
  15933. uniform._array[ i3 + 0 ] = value[ i ].x;
  15934. uniform._array[ i3 + 1 ] = value[ i ].y;
  15935. uniform._array[ i3 + 2 ] = value[ i ].z;
  15936. }
  15937. _gl.uniform3fv( location, uniform._array );
  15938. break;
  15939. case 'v4v':
  15940. // array of THREE.Vector4
  15941. if ( uniform._array === undefined ) {
  15942. uniform._array = new Float32Array( 4 * value.length );
  15943. }
  15944. for ( var i = 0, i4 = 0, il = value.length; i < il; i ++, i4 += 4 ) {
  15945. uniform._array[ i4 + 0 ] = value[ i ].x;
  15946. uniform._array[ i4 + 1 ] = value[ i ].y;
  15947. uniform._array[ i4 + 2 ] = value[ i ].z;
  15948. uniform._array[ i4 + 3 ] = value[ i ].w;
  15949. }
  15950. _gl.uniform4fv( location, uniform._array );
  15951. break;
  15952. case 'm3':
  15953. // single THREE.Matrix3
  15954. _gl.uniformMatrix3fv( location, false, value.elements );
  15955. break;
  15956. case 'm3v':
  15957. // array of THREE.Matrix3
  15958. if ( uniform._array === undefined ) {
  15959. uniform._array = new Float32Array( 9 * value.length );
  15960. }
  15961. for ( var i = 0, il = value.length; i < il; i ++ ) {
  15962. value[ i ].flattenToArrayOffset( uniform._array, i * 9 );
  15963. }
  15964. _gl.uniformMatrix3fv( location, false, uniform._array );
  15965. break;
  15966. case 'm4':
  15967. // single THREE.Matrix4
  15968. _gl.uniformMatrix4fv( location, false, value.elements );
  15969. break;
  15970. case 'm4v':
  15971. // array of THREE.Matrix4
  15972. if ( uniform._array === undefined ) {
  15973. uniform._array = new Float32Array( 16 * value.length );
  15974. }
  15975. for ( var i = 0, il = value.length; i < il; i ++ ) {
  15976. value[ i ].flattenToArrayOffset( uniform._array, i * 16 );
  15977. }
  15978. _gl.uniformMatrix4fv( location, false, uniform._array );
  15979. break;
  15980. case 't':
  15981. // single THREE.Texture (2d or cube)
  15982. texture = value;
  15983. textureUnit = getTextureUnit();
  15984. _gl.uniform1i( location, textureUnit );
  15985. if ( ! texture ) continue;
  15986. if ( texture instanceof THREE.CubeTexture ||
  15987. ( Array.isArray( texture.image ) && texture.image.length === 6 ) ) {
  15988. // CompressedTexture can have Array in image :/
  15989. setCubeTexture( texture, textureUnit );
  15990. } else if ( texture instanceof THREE.WebGLRenderTargetCube ) {
  15991. setCubeTextureDynamic( texture.texture, textureUnit );
  15992. } else if ( texture instanceof THREE.WebGLRenderTarget ) {
  15993. _this.setTexture( texture.texture, textureUnit );
  15994. } else {
  15995. _this.setTexture( texture, textureUnit );
  15996. }
  15997. break;
  15998. case 'tv':
  15999. // array of THREE.Texture (2d or cube)
  16000. if ( uniform._array === undefined ) {
  16001. uniform._array = [];
  16002. }
  16003. for ( var i = 0, il = uniform.value.length; i < il; i ++ ) {
  16004. uniform._array[ i ] = getTextureUnit();
  16005. }
  16006. _gl.uniform1iv( location, uniform._array );
  16007. for ( var i = 0, il = uniform.value.length; i < il; i ++ ) {
  16008. texture = uniform.value[ i ];
  16009. textureUnit = uniform._array[ i ];
  16010. if ( ! texture ) continue;
  16011. if ( texture instanceof THREE.CubeTexture ||
  16012. ( texture.image instanceof Array && texture.image.length === 6 ) ) {
  16013. // CompressedTexture can have Array in image :/
  16014. setCubeTexture( texture, textureUnit );
  16015. } else if ( texture instanceof THREE.WebGLRenderTarget ) {
  16016. _this.setTexture( texture.texture, textureUnit );
  16017. } else if ( texture instanceof THREE.WebGLRenderTargetCube ) {
  16018. setCubeTextureDynamic( texture.texture, textureUnit );
  16019. } else {
  16020. _this.setTexture( texture, textureUnit );
  16021. }
  16022. }
  16023. break;
  16024. default:
  16025. console.warn( 'THREE.WebGLRenderer: Unknown uniform type: ' + type );
  16026. }
  16027. }
  16028. }
  16029. function setupLights ( lights, camera ) {
  16030. var l, ll, light,
  16031. r = 0, g = 0, b = 0,
  16032. color,
  16033. intensity,
  16034. distance,
  16035. viewMatrix = camera.matrixWorldInverse,
  16036. directionalLength = 0,
  16037. pointLength = 0,
  16038. spotLength = 0,
  16039. hemiLength = 0;
  16040. _lights.shadows = 0;
  16041. _lights.shadowsPointLight = 0;
  16042. for ( l = 0, ll = lights.length; l < ll; l ++ ) {
  16043. light = lights[ l ];
  16044. color = light.color;
  16045. intensity = light.intensity;
  16046. distance = light.distance;
  16047. if ( light instanceof THREE.AmbientLight ) {
  16048. r += color.r;
  16049. g += color.g;
  16050. b += color.b;
  16051. } else if ( light instanceof THREE.DirectionalLight ) {
  16052. if( ! light.__webglUniforms ) {
  16053. light.__webglUniforms = {
  16054. direction: new THREE.Vector3(),
  16055. color: new THREE.Color()
  16056. }
  16057. }
  16058. var uniforms = light.__webglUniforms;
  16059. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  16060. _vector3.setFromMatrixPosition( light.target.matrixWorld );
  16061. uniforms.direction.sub( _vector3 );
  16062. uniforms.direction.transformDirection( viewMatrix );
  16063. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  16064. _lights.directional[ directionalLength ++ ] = uniforms;
  16065. if ( light.castShadow ) _lights.shadows ++;
  16066. } else if ( light instanceof THREE.PointLight ) {
  16067. if( ! light.__webglUniforms ) {
  16068. light.__webglUniforms = {
  16069. position: new THREE.Vector3(),
  16070. color: new THREE.Color(),
  16071. distance: 0,
  16072. decay: 0
  16073. }
  16074. }
  16075. var uniforms = light.__webglUniforms;
  16076. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  16077. uniforms.position.applyMatrix4( viewMatrix );
  16078. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  16079. uniforms.distance = light.distance;
  16080. uniforms.decay = ( light.distance === 0 ) ? 0.0 : light.decay;
  16081. _lights.point[ pointLength ++ ] = uniforms;
  16082. if ( light.castShadow ) {
  16083. _lights.shadows ++;
  16084. _lights.shadowsPointLight ++;
  16085. }
  16086. } else if ( light instanceof THREE.SpotLight ) {
  16087. if( ! light.__webglUniforms ) {
  16088. light.__webglUniforms = {
  16089. position: new THREE.Vector3(),
  16090. direction: new THREE.Vector3(),
  16091. color: new THREE.Color(),
  16092. distance: 0,
  16093. decay: 0,
  16094. angleCos: 0
  16095. }
  16096. }
  16097. var uniforms = light.__webglUniforms;
  16098. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  16099. uniforms.position.applyMatrix4( viewMatrix );
  16100. uniforms.color.copy( color ).multiplyScalar( intensity );
  16101. uniforms.distance = distance;
  16102. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  16103. _vector3.setFromMatrixPosition( light.target.matrixWorld );
  16104. uniforms.direction.sub( _vector3 );
  16105. uniforms.direction.transformDirection( viewMatrix );
  16106. uniforms.angleCos = Math.cos( light.angle );
  16107. uniforms.exponent = light.exponent;
  16108. uniforms.decay = ( light.distance === 0 ) ? 0.0 : light.decay;
  16109. _lights.spot[ spotLength ++ ] = uniforms;
  16110. if ( light.castShadow ) _lights.shadows ++;
  16111. } else if ( light instanceof THREE.HemisphereLight ) {
  16112. if( ! light.__webglUniforms ) {
  16113. light.__webglUniforms = {
  16114. direction: new THREE.Vector3(),
  16115. skyColor: new THREE.Color(),
  16116. groundColor: new THREE.Color()
  16117. }
  16118. }
  16119. var uniforms = light.__webglUniforms;
  16120. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  16121. uniforms.direction.transformDirection( viewMatrix );
  16122. uniforms.direction.normalize();
  16123. uniforms.skyColor.copy( light.color ).multiplyScalar( intensity );
  16124. uniforms.groundColor.copy( light.groundColor ).multiplyScalar( intensity );
  16125. _lights.hemi[ hemiLength ++ ] = uniforms;
  16126. }
  16127. }
  16128. _lights.ambient[ 0 ] = r;
  16129. _lights.ambient[ 1 ] = g;
  16130. _lights.ambient[ 2 ] = b;
  16131. _lights.directional.length = directionalLength;
  16132. _lights.point.length = pointLength;
  16133. _lights.spot.length = spotLength;
  16134. _lights.hemi.length = hemiLength;
  16135. _lights.hash = directionalLength + ',' + pointLength + ',' + spotLength + ',' + hemiLength;
  16136. }
  16137. // GL state setting
  16138. this.setFaceCulling = function ( cullFace, frontFaceDirection ) {
  16139. if ( cullFace === THREE.CullFaceNone ) {
  16140. state.disable( _gl.CULL_FACE );
  16141. } else {
  16142. if ( frontFaceDirection === THREE.FrontFaceDirectionCW ) {
  16143. _gl.frontFace( _gl.CW );
  16144. } else {
  16145. _gl.frontFace( _gl.CCW );
  16146. }
  16147. if ( cullFace === THREE.CullFaceBack ) {
  16148. _gl.cullFace( _gl.BACK );
  16149. } else if ( cullFace === THREE.CullFaceFront ) {
  16150. _gl.cullFace( _gl.FRONT );
  16151. } else {
  16152. _gl.cullFace( _gl.FRONT_AND_BACK );
  16153. }
  16154. state.enable( _gl.CULL_FACE );
  16155. }
  16156. };
  16157. // Textures
  16158. function setTextureParameters ( textureType, texture, isImagePowerOfTwo ) {
  16159. var extension;
  16160. if ( isImagePowerOfTwo ) {
  16161. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, paramThreeToGL( texture.wrapS ) );
  16162. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, paramThreeToGL( texture.wrapT ) );
  16163. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, paramThreeToGL( texture.magFilter ) );
  16164. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, paramThreeToGL( texture.minFilter ) );
  16165. } else {
  16166. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, _gl.CLAMP_TO_EDGE );
  16167. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, _gl.CLAMP_TO_EDGE );
  16168. if ( texture.wrapS !== THREE.ClampToEdgeWrapping || texture.wrapT !== THREE.ClampToEdgeWrapping ) {
  16169. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.', texture );
  16170. }
  16171. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, filterFallback( texture.magFilter ) );
  16172. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, filterFallback( texture.minFilter ) );
  16173. if ( texture.minFilter !== THREE.NearestFilter && texture.minFilter !== THREE.LinearFilter ) {
  16174. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.', texture );
  16175. }
  16176. }
  16177. extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  16178. if ( extension ) {
  16179. if ( texture.type === THREE.FloatType && extensions.get( 'OES_texture_float_linear' ) === null ) return;
  16180. if ( texture.type === THREE.HalfFloatType && extensions.get( 'OES_texture_half_float_linear' ) === null ) return;
  16181. if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
  16182. _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, _this.getMaxAnisotropy() ) );
  16183. properties.get( texture ).__currentAnisotropy = texture.anisotropy;
  16184. }
  16185. }
  16186. }
  16187. function uploadTexture( textureProperties, texture, slot ) {
  16188. if ( textureProperties.__webglInit === undefined ) {
  16189. textureProperties.__webglInit = true;
  16190. texture.addEventListener( 'dispose', onTextureDispose );
  16191. textureProperties.__webglTexture = _gl.createTexture();
  16192. _infoMemory.textures ++;
  16193. }
  16194. state.activeTexture( _gl.TEXTURE0 + slot );
  16195. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  16196. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  16197. _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );
  16198. _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
  16199. texture.image = clampToMaxSize( texture.image, capabilities.maxTextureSize );
  16200. if ( textureNeedsPowerOfTwo( texture ) && isPowerOfTwo( texture.image ) === false ) {
  16201. texture.image = makePowerOfTwo( texture.image );
  16202. }
  16203. var image = texture.image,
  16204. isImagePowerOfTwo = isPowerOfTwo( image ),
  16205. glFormat = paramThreeToGL( texture.format ),
  16206. glType = paramThreeToGL( texture.type );
  16207. setTextureParameters( _gl.TEXTURE_2D, texture, isImagePowerOfTwo );
  16208. var mipmap, mipmaps = texture.mipmaps;
  16209. if ( texture instanceof THREE.DataTexture ) {
  16210. // use manually created mipmaps if available
  16211. // if there are no manual mipmaps
  16212. // set 0 level mipmap and then use GL to generate other mipmap levels
  16213. if ( mipmaps.length > 0 && isImagePowerOfTwo ) {
  16214. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  16215. mipmap = mipmaps[ i ];
  16216. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  16217. }
  16218. texture.generateMipmaps = false;
  16219. } else {
  16220. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, image.width, image.height, 0, glFormat, glType, image.data );
  16221. }
  16222. } else if ( texture instanceof THREE.CompressedTexture ) {
  16223. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  16224. mipmap = mipmaps[ i ];
  16225. if ( texture.format !== THREE.RGBAFormat && texture.format !== THREE.RGBFormat ) {
  16226. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  16227. state.compressedTexImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  16228. } else {
  16229. console.warn( "THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()" );
  16230. }
  16231. } else {
  16232. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  16233. }
  16234. }
  16235. } else {
  16236. // regular Texture (image, video, canvas)
  16237. // use manually created mipmaps if available
  16238. // if there are no manual mipmaps
  16239. // set 0 level mipmap and then use GL to generate other mipmap levels
  16240. if ( mipmaps.length > 0 && isImagePowerOfTwo ) {
  16241. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  16242. mipmap = mipmaps[ i ];
  16243. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, glFormat, glType, mipmap );
  16244. }
  16245. texture.generateMipmaps = false;
  16246. } else {
  16247. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, glFormat, glType, texture.image );
  16248. }
  16249. }
  16250. if ( texture.generateMipmaps && isImagePowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_2D );
  16251. textureProperties.__version = texture.version;
  16252. if ( texture.onUpdate ) texture.onUpdate( texture );
  16253. }
  16254. this.setTexture = function ( texture, slot ) {
  16255. var textureProperties = properties.get( texture );
  16256. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  16257. var image = texture.image;
  16258. if ( image === undefined ) {
  16259. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is undefined', texture );
  16260. return;
  16261. }
  16262. if ( image.complete === false ) {
  16263. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete', texture );
  16264. return;
  16265. }
  16266. uploadTexture( textureProperties, texture, slot );
  16267. return;
  16268. }
  16269. state.activeTexture( _gl.TEXTURE0 + slot );
  16270. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  16271. };
  16272. function clampToMaxSize ( image, maxSize ) {
  16273. if ( image.width > maxSize || image.height > maxSize ) {
  16274. // Warning: Scaling through the canvas will only work with images that use
  16275. // premultiplied alpha.
  16276. var scale = maxSize / Math.max( image.width, image.height );
  16277. var canvas = document.createElement( 'canvas' );
  16278. canvas.width = Math.floor( image.width * scale );
  16279. canvas.height = Math.floor( image.height * scale );
  16280. var context = canvas.getContext( '2d' );
  16281. context.drawImage( image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height );
  16282. console.warn( 'THREE.WebGLRenderer: image is too big (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
  16283. return canvas;
  16284. }
  16285. return image;
  16286. }
  16287. function isPowerOfTwo( image ) {
  16288. return THREE.Math.isPowerOfTwo( image.width ) && THREE.Math.isPowerOfTwo( image.height );
  16289. }
  16290. function textureNeedsPowerOfTwo( texture ) {
  16291. if ( texture.wrapS !== THREE.ClampToEdgeWrapping || texture.wrapT !== THREE.ClampToEdgeWrapping ) return true;
  16292. if ( texture.minFilter !== THREE.NearestFilter && texture.minFilter !== THREE.LinearFilter ) return true;
  16293. return false;
  16294. }
  16295. function makePowerOfTwo( image ) {
  16296. if ( image instanceof HTMLImageElement || image instanceof HTMLCanvasElement ) {
  16297. var canvas = document.createElement( 'canvas' );
  16298. canvas.width = THREE.Math.nearestPowerOfTwo( image.width );
  16299. canvas.height = THREE.Math.nearestPowerOfTwo( image.height );
  16300. var context = canvas.getContext( '2d' );
  16301. context.drawImage( image, 0, 0, canvas.width, canvas.height );
  16302. console.warn( 'THREE.WebGLRenderer: image is not power of two (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
  16303. return canvas;
  16304. }
  16305. return image;
  16306. }
  16307. function setCubeTexture ( texture, slot ) {
  16308. var textureProperties = properties.get( texture );
  16309. if ( texture.image.length === 6 ) {
  16310. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  16311. if ( ! textureProperties.__image__webglTextureCube ) {
  16312. texture.addEventListener( 'dispose', onTextureDispose );
  16313. textureProperties.__image__webglTextureCube = _gl.createTexture();
  16314. _infoMemory.textures ++;
  16315. }
  16316. state.activeTexture( _gl.TEXTURE0 + slot );
  16317. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  16318. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  16319. var isCompressed = texture instanceof THREE.CompressedTexture;
  16320. var isDataTexture = texture.image[ 0 ] instanceof THREE.DataTexture;
  16321. var cubeImage = [];
  16322. for ( var i = 0; i < 6; i ++ ) {
  16323. if ( _this.autoScaleCubemaps && ! isCompressed && ! isDataTexture ) {
  16324. cubeImage[ i ] = clampToMaxSize( texture.image[ i ], capabilities.maxCubemapSize );
  16325. } else {
  16326. cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
  16327. }
  16328. }
  16329. var image = cubeImage[ 0 ],
  16330. isImagePowerOfTwo = isPowerOfTwo( image ),
  16331. glFormat = paramThreeToGL( texture.format ),
  16332. glType = paramThreeToGL( texture.type );
  16333. setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture, isImagePowerOfTwo );
  16334. for ( var i = 0; i < 6; i ++ ) {
  16335. if ( ! isCompressed ) {
  16336. if ( isDataTexture ) {
  16337. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
  16338. } else {
  16339. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, glFormat, glType, cubeImage[ i ] );
  16340. }
  16341. } else {
  16342. var mipmap, mipmaps = cubeImage[ i ].mipmaps;
  16343. for ( var j = 0, jl = mipmaps.length; j < jl; j ++ ) {
  16344. mipmap = mipmaps[ j ];
  16345. if ( texture.format !== THREE.RGBAFormat && texture.format !== THREE.RGBFormat ) {
  16346. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  16347. state.compressedTexImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  16348. } else {
  16349. console.warn( "THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setCubeTexture()" );
  16350. }
  16351. } else {
  16352. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  16353. }
  16354. }
  16355. }
  16356. }
  16357. if ( texture.generateMipmaps && isImagePowerOfTwo ) {
  16358. _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  16359. }
  16360. textureProperties.__version = texture.version;
  16361. if ( texture.onUpdate ) texture.onUpdate( texture );
  16362. } else {
  16363. state.activeTexture( _gl.TEXTURE0 + slot );
  16364. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  16365. }
  16366. }
  16367. }
  16368. function setCubeTextureDynamic ( texture, slot ) {
  16369. state.activeTexture( _gl.TEXTURE0 + slot );
  16370. state.bindTexture( _gl.TEXTURE_CUBE_MAP, properties.get( texture ).__webglTexture );
  16371. }
  16372. // Render targets
  16373. function setupFrameBuffer ( framebuffer, renderTarget, textureTarget ) {
  16374. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  16375. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, textureTarget, properties.get( renderTarget.texture ).__webglTexture, 0 );
  16376. }
  16377. function setupRenderBuffer ( renderbuffer, renderTarget ) {
  16378. _gl.bindRenderbuffer( _gl.RENDERBUFFER, renderbuffer );
  16379. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  16380. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_COMPONENT16, renderTarget.width, renderTarget.height );
  16381. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  16382. /* For some reason this is not working. Defaulting to RGBA4.
  16383. } else if ( ! renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  16384. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.STENCIL_INDEX8, renderTarget.width, renderTarget.height );
  16385. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  16386. */
  16387. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  16388. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_STENCIL, renderTarget.width, renderTarget.height );
  16389. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  16390. } else {
  16391. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.RGBA4, renderTarget.width, renderTarget.height );
  16392. }
  16393. }
  16394. this.setRenderTarget = function ( renderTarget ) {
  16395. var isCube = ( renderTarget instanceof THREE.WebGLRenderTargetCube );
  16396. if ( renderTarget && properties.get( renderTarget ).__webglFramebuffer === undefined ) {
  16397. var renderTargetProperties = properties.get( renderTarget );
  16398. var textureProperties = properties.get( renderTarget.texture );
  16399. if ( renderTarget.depthBuffer === undefined ) renderTarget.depthBuffer = true;
  16400. if ( renderTarget.stencilBuffer === undefined ) renderTarget.stencilBuffer = true;
  16401. renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
  16402. textureProperties.__webglTexture = _gl.createTexture();
  16403. _infoMemory.textures ++;
  16404. // Setup texture, create render and frame buffers
  16405. var isTargetPowerOfTwo = isPowerOfTwo( renderTarget ),
  16406. glFormat = paramThreeToGL( renderTarget.texture.format ),
  16407. glType = paramThreeToGL( renderTarget.texture.type );
  16408. if ( isCube ) {
  16409. renderTargetProperties.__webglFramebuffer = [];
  16410. renderTargetProperties.__webglRenderbuffer = [];
  16411. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__webglTexture );
  16412. setTextureParameters( _gl.TEXTURE_CUBE_MAP, renderTarget.texture, isTargetPowerOfTwo );
  16413. for ( var i = 0; i < 6; i ++ ) {
  16414. renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer();
  16415. renderTargetProperties.__webglRenderbuffer[ i ] = _gl.createRenderbuffer();
  16416. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  16417. setupFrameBuffer( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i );
  16418. setupRenderBuffer( renderTargetProperties.__webglRenderbuffer[ i ], renderTarget );
  16419. }
  16420. if ( renderTarget.texture.generateMipmaps && isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  16421. } else {
  16422. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  16423. if ( renderTarget.shareDepthFrom ) {
  16424. renderTargetProperties.__webglRenderbuffer = renderTarget.shareDepthFrom.__webglRenderbuffer;
  16425. } else {
  16426. renderTargetProperties.__webglRenderbuffer = _gl.createRenderbuffer();
  16427. }
  16428. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  16429. setTextureParameters( _gl.TEXTURE_2D, renderTarget.texture, isTargetPowerOfTwo );
  16430. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  16431. setupFrameBuffer( renderTargetProperties.__webglFramebuffer, renderTarget, _gl.TEXTURE_2D );
  16432. if ( renderTarget.shareDepthFrom ) {
  16433. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  16434. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderTargetProperties.__webglRenderbuffer );
  16435. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  16436. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderTargetProperties.__webglRenderbuffer );
  16437. }
  16438. } else {
  16439. setupRenderBuffer( renderTargetProperties.__webglRenderbuffer, renderTarget );
  16440. }
  16441. if ( renderTarget.texture.generateMipmaps && isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_2D );
  16442. }
  16443. // Release everything
  16444. if ( isCube ) {
  16445. state.bindTexture( _gl.TEXTURE_CUBE_MAP, null );
  16446. } else {
  16447. state.bindTexture( _gl.TEXTURE_2D, null );
  16448. }
  16449. _gl.bindRenderbuffer( _gl.RENDERBUFFER, null );
  16450. _gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
  16451. }
  16452. var framebuffer, width, height, vx, vy;
  16453. if ( renderTarget ) {
  16454. var renderTargetProperties = properties.get( renderTarget );
  16455. if ( isCube ) {
  16456. framebuffer = renderTargetProperties.__webglFramebuffer[ renderTarget.activeCubeFace ];
  16457. } else {
  16458. framebuffer = renderTargetProperties.__webglFramebuffer;
  16459. }
  16460. width = renderTarget.width;
  16461. height = renderTarget.height;
  16462. vx = 0;
  16463. vy = 0;
  16464. } else {
  16465. framebuffer = null;
  16466. width = _viewportWidth;
  16467. height = _viewportHeight;
  16468. vx = _viewportX;
  16469. vy = _viewportY;
  16470. }
  16471. if ( framebuffer !== _currentFramebuffer ) {
  16472. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  16473. _gl.viewport( vx, vy, width, height );
  16474. _currentFramebuffer = framebuffer;
  16475. }
  16476. if ( isCube ) {
  16477. var textureProperties = properties.get( renderTarget.texture );
  16478. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + renderTarget.activeCubeFace, textureProperties.__webglTexture, 0 );
  16479. }
  16480. _currentWidth = width;
  16481. _currentHeight = height;
  16482. };
  16483. this.readRenderTargetPixels = function ( renderTarget, x, y, width, height, buffer ) {
  16484. if ( renderTarget instanceof THREE.WebGLRenderTarget === false ) {
  16485. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
  16486. return;
  16487. }
  16488. var framebuffer = properties.get( renderTarget ).__webglFramebuffer;
  16489. if ( framebuffer ) {
  16490. var restore = false;
  16491. if ( framebuffer !== _currentFramebuffer ) {
  16492. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  16493. restore = true;
  16494. }
  16495. try {
  16496. var texture = renderTarget.texture;
  16497. if ( texture.format !== THREE.RGBAFormat
  16498. && paramThreeToGL( texture.format ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_FORMAT ) ) {
  16499. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
  16500. return;
  16501. }
  16502. if ( texture.type !== THREE.UnsignedByteType
  16503. && paramThreeToGL( texture.type ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_TYPE )
  16504. && ! ( texture.type === THREE.FloatType && extensions.get( 'WEBGL_color_buffer_float' ) )
  16505. && ! ( texture.type === THREE.HalfFloatType && extensions.get( 'EXT_color_buffer_half_float' ) ) ) {
  16506. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' );
  16507. return;
  16508. }
  16509. if ( _gl.checkFramebufferStatus( _gl.FRAMEBUFFER ) === _gl.FRAMEBUFFER_COMPLETE ) {
  16510. _gl.readPixels( x, y, width, height, paramThreeToGL( texture.format ), paramThreeToGL( texture.type ), buffer );
  16511. } else {
  16512. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );
  16513. }
  16514. } finally {
  16515. if ( restore ) {
  16516. _gl.bindFramebuffer( _gl.FRAMEBUFFER, _currentFramebuffer );
  16517. }
  16518. }
  16519. }
  16520. };
  16521. function updateRenderTargetMipmap( renderTarget ) {
  16522. var target = renderTarget instanceof THREE.WebGLRenderTargetCube ? _gl.TEXTURE_CUBE_MAP : _gl.TEXTURE_2D;
  16523. var texture = properties.get( renderTarget.texture ).__webglTexture;
  16524. state.bindTexture( target, texture );
  16525. _gl.generateMipmap( target );
  16526. state.bindTexture( target, null );
  16527. }
  16528. // Fallback filters for non-power-of-2 textures
  16529. function filterFallback ( f ) {
  16530. if ( f === THREE.NearestFilter || f === THREE.NearestMipMapNearestFilter || f === THREE.NearestMipMapLinearFilter ) {
  16531. return _gl.NEAREST;
  16532. }
  16533. return _gl.LINEAR;
  16534. }
  16535. // Map three.js constants to WebGL constants
  16536. function paramThreeToGL ( p ) {
  16537. var extension;
  16538. if ( p === THREE.RepeatWrapping ) return _gl.REPEAT;
  16539. if ( p === THREE.ClampToEdgeWrapping ) return _gl.CLAMP_TO_EDGE;
  16540. if ( p === THREE.MirroredRepeatWrapping ) return _gl.MIRRORED_REPEAT;
  16541. if ( p === THREE.NearestFilter ) return _gl.NEAREST;
  16542. if ( p === THREE.NearestMipMapNearestFilter ) return _gl.NEAREST_MIPMAP_NEAREST;
  16543. if ( p === THREE.NearestMipMapLinearFilter ) return _gl.NEAREST_MIPMAP_LINEAR;
  16544. if ( p === THREE.LinearFilter ) return _gl.LINEAR;
  16545. if ( p === THREE.LinearMipMapNearestFilter ) return _gl.LINEAR_MIPMAP_NEAREST;
  16546. if ( p === THREE.LinearMipMapLinearFilter ) return _gl.LINEAR_MIPMAP_LINEAR;
  16547. if ( p === THREE.UnsignedByteType ) return _gl.UNSIGNED_BYTE;
  16548. if ( p === THREE.UnsignedShort4444Type ) return _gl.UNSIGNED_SHORT_4_4_4_4;
  16549. if ( p === THREE.UnsignedShort5551Type ) return _gl.UNSIGNED_SHORT_5_5_5_1;
  16550. if ( p === THREE.UnsignedShort565Type ) return _gl.UNSIGNED_SHORT_5_6_5;
  16551. if ( p === THREE.ByteType ) return _gl.BYTE;
  16552. if ( p === THREE.ShortType ) return _gl.SHORT;
  16553. if ( p === THREE.UnsignedShortType ) return _gl.UNSIGNED_SHORT;
  16554. if ( p === THREE.IntType ) return _gl.INT;
  16555. if ( p === THREE.UnsignedIntType ) return _gl.UNSIGNED_INT;
  16556. if ( p === THREE.FloatType ) return _gl.FLOAT;
  16557. extension = extensions.get( 'OES_texture_half_float' );
  16558. if ( extension !== null ) {
  16559. if ( p === THREE.HalfFloatType ) return extension.HALF_FLOAT_OES;
  16560. }
  16561. if ( p === THREE.AlphaFormat ) return _gl.ALPHA;
  16562. if ( p === THREE.RGBFormat ) return _gl.RGB;
  16563. if ( p === THREE.RGBAFormat ) return _gl.RGBA;
  16564. if ( p === THREE.LuminanceFormat ) return _gl.LUMINANCE;
  16565. if ( p === THREE.LuminanceAlphaFormat ) return _gl.LUMINANCE_ALPHA;
  16566. if ( p === THREE.AddEquation ) return _gl.FUNC_ADD;
  16567. if ( p === THREE.SubtractEquation ) return _gl.FUNC_SUBTRACT;
  16568. if ( p === THREE.ReverseSubtractEquation ) return _gl.FUNC_REVERSE_SUBTRACT;
  16569. if ( p === THREE.ZeroFactor ) return _gl.ZERO;
  16570. if ( p === THREE.OneFactor ) return _gl.ONE;
  16571. if ( p === THREE.SrcColorFactor ) return _gl.SRC_COLOR;
  16572. if ( p === THREE.OneMinusSrcColorFactor ) return _gl.ONE_MINUS_SRC_COLOR;
  16573. if ( p === THREE.SrcAlphaFactor ) return _gl.SRC_ALPHA;
  16574. if ( p === THREE.OneMinusSrcAlphaFactor ) return _gl.ONE_MINUS_SRC_ALPHA;
  16575. if ( p === THREE.DstAlphaFactor ) return _gl.DST_ALPHA;
  16576. if ( p === THREE.OneMinusDstAlphaFactor ) return _gl.ONE_MINUS_DST_ALPHA;
  16577. if ( p === THREE.DstColorFactor ) return _gl.DST_COLOR;
  16578. if ( p === THREE.OneMinusDstColorFactor ) return _gl.ONE_MINUS_DST_COLOR;
  16579. if ( p === THREE.SrcAlphaSaturateFactor ) return _gl.SRC_ALPHA_SATURATE;
  16580. extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );
  16581. if ( extension !== null ) {
  16582. if ( p === THREE.RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  16583. if ( p === THREE.RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  16584. if ( p === THREE.RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  16585. if ( p === THREE.RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  16586. }
  16587. extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  16588. if ( extension !== null ) {
  16589. if ( p === THREE.RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  16590. if ( p === THREE.RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  16591. if ( p === THREE.RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  16592. if ( p === THREE.RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  16593. }
  16594. extension = extensions.get( 'EXT_blend_minmax' );
  16595. if ( extension !== null ) {
  16596. if ( p === THREE.MinEquation ) return extension.MIN_EXT;
  16597. if ( p === THREE.MaxEquation ) return extension.MAX_EXT;
  16598. }
  16599. return 0;
  16600. }
  16601. };
  16602. // File:src/renderers/WebGLRenderTarget.js
  16603. /**
  16604. * @author szimek / https://github.com/szimek/
  16605. * @author alteredq / http://alteredqualia.com/
  16606. */
  16607. THREE.WebGLRenderTarget = function ( width, height, options ) {
  16608. this.uuid = THREE.Math.generateUUID();
  16609. this.width = width;
  16610. this.height = height;
  16611. options = options || {};
  16612. if ( options.minFilter === undefined ) options.minFilter = THREE.LinearFilter;
  16613. this.texture = new THREE.Texture( undefined, undefined, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy );
  16614. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  16615. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;
  16616. this.shareDepthFrom = options.shareDepthFrom !== undefined ? options.shareDepthFrom : null;
  16617. };
  16618. THREE.WebGLRenderTarget.prototype = {
  16619. constructor: THREE.WebGLRenderTarget,
  16620. setSize: function ( width, height ) {
  16621. if ( this.width !== width || this.height !== height ) {
  16622. this.width = width;
  16623. this.height = height;
  16624. this.dispose();
  16625. }
  16626. },
  16627. clone: function () {
  16628. return new this.constructor().copy( this );
  16629. },
  16630. copy: function ( source ) {
  16631. this.width = source.width;
  16632. this.height = source.height;
  16633. this.texture = source.texture.clone();
  16634. this.depthBuffer = source.depthBuffer;
  16635. this.stencilBuffer = source.stencilBuffer;
  16636. this.shareDepthFrom = source.shareDepthFrom;
  16637. return this;
  16638. },
  16639. dispose: function () {
  16640. this.dispatchEvent( { type: 'dispose' } );
  16641. }
  16642. };
  16643. THREE.EventDispatcher.prototype.apply( THREE.WebGLRenderTarget.prototype );
  16644. // File:src/renderers/WebGLRenderTargetCube.js
  16645. /**
  16646. * @author alteredq / http://alteredqualia.com
  16647. */
  16648. THREE.WebGLRenderTargetCube = function ( width, height, options ) {
  16649. THREE.WebGLRenderTarget.call( this, width, height, options );
  16650. this.activeCubeFace = 0; // PX 0, NX 1, PY 2, NY 3, PZ 4, NZ 5
  16651. };
  16652. THREE.WebGLRenderTargetCube.prototype = Object.create( THREE.WebGLRenderTarget.prototype );
  16653. THREE.WebGLRenderTargetCube.prototype.constructor = THREE.WebGLRenderTargetCube;
  16654. // File:src/renderers/webgl/WebGLBufferRenderer.js
  16655. /**
  16656. * @author mrdoob / http://mrdoob.com/
  16657. */
  16658. THREE.WebGLBufferRenderer = function ( _gl, extensions, _infoRender ) {
  16659. var mode;
  16660. function setMode( value ) {
  16661. mode = value;
  16662. }
  16663. function render( start, count ) {
  16664. _gl.drawArrays( mode, start, count );
  16665. _infoRender.calls ++;
  16666. _infoRender.vertices += count;
  16667. if ( mode === _gl.TRIANGLES ) _infoRender.faces += count / 3;
  16668. }
  16669. function renderInstances( geometry ) {
  16670. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  16671. if ( extension === null ) {
  16672. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  16673. return;
  16674. }
  16675. var position = geometry.attributes.position;
  16676. if ( position instanceof THREE.InterleavedBufferAttribute ) {
  16677. extension.drawArraysInstancedANGLE( mode, 0, position.data.count, geometry.maxInstancedCount );
  16678. } else {
  16679. extension.drawArraysInstancedANGLE( mode, 0, position.count, geometry.maxInstancedCount );
  16680. }
  16681. }
  16682. this.setMode = setMode;
  16683. this.render = render;
  16684. this.renderInstances = renderInstances;
  16685. };
  16686. // File:src/renderers/webgl/WebGLIndexedBufferRenderer.js
  16687. /**
  16688. * @author mrdoob / http://mrdoob.com/
  16689. */
  16690. THREE.WebGLIndexedBufferRenderer = function ( _gl, extensions, _infoRender ) {
  16691. var mode;
  16692. function setMode( value ) {
  16693. mode = value;
  16694. }
  16695. var type, size;
  16696. function setIndex( index ) {
  16697. if ( index.array instanceof Uint32Array && extensions.get( 'OES_element_index_uint' ) ) {
  16698. type = _gl.UNSIGNED_INT;
  16699. size = 4;
  16700. } else {
  16701. type = _gl.UNSIGNED_SHORT;
  16702. size = 2;
  16703. }
  16704. }
  16705. function render( start, count ) {
  16706. _gl.drawElements( mode, count, type, start * size );
  16707. _infoRender.calls ++;
  16708. _infoRender.vertices += count;
  16709. if ( mode === _gl.TRIANGLES ) _infoRender.faces += count / 3;
  16710. }
  16711. function renderInstances( geometry ) {
  16712. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  16713. if ( extension === null ) {
  16714. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  16715. return;
  16716. }
  16717. var index = geometry.index;
  16718. extension.drawElementsInstancedANGLE( mode, index.array.length, type, 0, geometry.maxInstancedCount );
  16719. }
  16720. this.setMode = setMode;
  16721. this.setIndex = setIndex;
  16722. this.render = render;
  16723. this.renderInstances = renderInstances;
  16724. };
  16725. // File:src/renderers/webgl/WebGLExtensions.js
  16726. /**
  16727. * @author mrdoob / http://mrdoob.com/
  16728. */
  16729. THREE.WebGLExtensions = function ( gl ) {
  16730. var extensions = {};
  16731. this.get = function ( name ) {
  16732. if ( extensions[ name ] !== undefined ) {
  16733. return extensions[ name ];
  16734. }
  16735. var extension;
  16736. switch ( name ) {
  16737. case 'EXT_texture_filter_anisotropic':
  16738. extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' );
  16739. break;
  16740. case 'WEBGL_compressed_texture_s3tc':
  16741. extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' );
  16742. break;
  16743. case 'WEBGL_compressed_texture_pvrtc':
  16744. extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' );
  16745. break;
  16746. default:
  16747. extension = gl.getExtension( name );
  16748. }
  16749. if ( extension === null ) {
  16750. console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
  16751. }
  16752. extensions[ name ] = extension;
  16753. return extension;
  16754. };
  16755. };
  16756. // File:src/renderers/webgl/WebGLCapabilities.js
  16757. THREE.WebGLCapabilities = function ( gl, extensions, parameters ) {
  16758. function getMaxPrecision( precision ) {
  16759. if ( precision === 'highp' ) {
  16760. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.HIGH_FLOAT ).precision > 0 &&
  16761. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.HIGH_FLOAT ).precision > 0 ) {
  16762. return 'highp';
  16763. }
  16764. precision = 'mediump';
  16765. }
  16766. if ( precision === 'mediump' ) {
  16767. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.MEDIUM_FLOAT ).precision > 0 &&
  16768. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.MEDIUM_FLOAT ).precision > 0 ) {
  16769. return 'mediump';
  16770. }
  16771. }
  16772. return 'lowp';
  16773. }
  16774. this.getMaxPrecision = getMaxPrecision;
  16775. this.precision = parameters.precision !== undefined ? parameters.precision : 'highp',
  16776. this.logarithmicDepthBuffer = parameters.logarithmicDepthBuffer !== undefined ? parameters.logarithmicDepthBuffer : false;
  16777. this.maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
  16778. this.maxVertexTextures = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS );
  16779. this.maxTextureSize = gl.getParameter( gl.MAX_TEXTURE_SIZE );
  16780. this.maxCubemapSize = gl.getParameter( gl.MAX_CUBE_MAP_TEXTURE_SIZE );
  16781. this.maxAttributes = gl.getParameter( gl.MAX_VERTEX_ATTRIBS );
  16782. this.maxVertexUniforms = gl.getParameter( gl.MAX_VERTEX_UNIFORM_VECTORS );
  16783. this.maxVaryings = gl.getParameter( gl.MAX_VARYING_VECTORS );
  16784. this.maxFragmentUniforms = gl.getParameter( gl.MAX_FRAGMENT_UNIFORM_VECTORS );
  16785. this.vertexTextures = this.maxVertexTextures > 0;
  16786. this.floatFragmentTextures = !! extensions.get( 'OES_texture_float' );
  16787. this.floatVertexTextures = this.vertexTextures && this.floatFragmentTextures;
  16788. var _maxPrecision = getMaxPrecision( this.precision );
  16789. if ( _maxPrecision !== this.precision ) {
  16790. console.warn( 'THREE.WebGLRenderer:', this.precision, 'not supported, using', _maxPrecision, 'instead.' );
  16791. this.precision = _maxPrecision;
  16792. }
  16793. if ( this.logarithmicDepthBuffer ) {
  16794. this.logarithmicDepthBuffer = !! extensions.get( 'EXT_frag_depth' );
  16795. }
  16796. };
  16797. // File:src/renderers/webgl/WebGLGeometries.js
  16798. /**
  16799. * @author mrdoob / http://mrdoob.com/
  16800. */
  16801. THREE.WebGLGeometries = function ( gl, properties, info ) {
  16802. var geometries = {};
  16803. function get( object ) {
  16804. var geometry = object.geometry;
  16805. if ( geometries[ geometry.id ] !== undefined ) {
  16806. return geometries[ geometry.id ];
  16807. }
  16808. geometry.addEventListener( 'dispose', onGeometryDispose );
  16809. var buffergeometry;
  16810. if ( geometry instanceof THREE.BufferGeometry ) {
  16811. buffergeometry = geometry;
  16812. } else if ( geometry instanceof THREE.Geometry ) {
  16813. if ( geometry._bufferGeometry === undefined ) {
  16814. geometry._bufferGeometry = new THREE.BufferGeometry().setFromObject( object );
  16815. }
  16816. buffergeometry = geometry._bufferGeometry;
  16817. }
  16818. geometries[ geometry.id ] = buffergeometry;
  16819. info.memory.geometries ++;
  16820. return buffergeometry;
  16821. }
  16822. function onGeometryDispose( event ) {
  16823. var geometry = event.target;
  16824. var buffergeometry = geometries[ geometry.id ];
  16825. if ( buffergeometry.index !== null ) {
  16826. deleteAttribute( buffergeometry.index );
  16827. }
  16828. deleteAttributes( buffergeometry.attributes );
  16829. geometry.removeEventListener( 'dispose', onGeometryDispose );
  16830. delete geometries[ geometry.id ];
  16831. var property = properties.get( geometry );
  16832. if ( property.wireframe ) deleteAttribute( property.wireframe );
  16833. properties.delete( geometry );
  16834. info.memory.geometries --;
  16835. }
  16836. function getAttributeBuffer( attribute ) {
  16837. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  16838. return properties.get( attribute.data ).__webglBuffer;
  16839. }
  16840. return properties.get( attribute ).__webglBuffer;
  16841. }
  16842. function deleteAttribute( attribute ) {
  16843. var buffer = getAttributeBuffer( attribute );
  16844. if ( buffer !== undefined ) {
  16845. gl.deleteBuffer( buffer );
  16846. removeAttributeBuffer( attribute );
  16847. }
  16848. }
  16849. function deleteAttributes( attributes ) {
  16850. for ( var name in attributes ) {
  16851. deleteAttribute( attributes[ name ] );
  16852. }
  16853. }
  16854. function removeAttributeBuffer( attribute ) {
  16855. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  16856. properties.delete( attribute.data );
  16857. } else {
  16858. properties.delete( attribute );
  16859. }
  16860. }
  16861. this.get = get;
  16862. };
  16863. // File:src/renderers/webgl/WebGLObjects.js
  16864. /**
  16865. * @author mrdoob / http://mrdoob.com/
  16866. */
  16867. THREE.WebGLObjects = function ( gl, properties, info ) {
  16868. var geometries = new THREE.WebGLGeometries( gl, properties, info );
  16869. //
  16870. function update( object ) {
  16871. // TODO: Avoid updating twice (when using shadowMap). Maybe add frame counter.
  16872. var geometry = geometries.get( object );
  16873. if ( object.geometry instanceof THREE.Geometry ) {
  16874. geometry.updateFromObject( object );
  16875. }
  16876. var index = geometry.index;
  16877. var attributes = geometry.attributes;
  16878. if ( index !== null ) {
  16879. updateAttribute( index, gl.ELEMENT_ARRAY_BUFFER );
  16880. }
  16881. for ( var name in attributes ) {
  16882. updateAttribute( attributes[ name ], gl.ARRAY_BUFFER );
  16883. }
  16884. // morph targets
  16885. var morphAttributes = geometry.morphAttributes;
  16886. for ( var name in morphAttributes ) {
  16887. var array = morphAttributes[ name ];
  16888. for ( var i = 0, l = array.length; i < l; i ++ ) {
  16889. updateAttribute( array[ i ], gl.ARRAY_BUFFER );
  16890. }
  16891. }
  16892. return geometry;
  16893. }
  16894. function updateAttribute( attribute, bufferType ) {
  16895. var data = ( attribute instanceof THREE.InterleavedBufferAttribute ) ? attribute.data : attribute;
  16896. var attributeProperties = properties.get( data );
  16897. if ( attributeProperties.__webglBuffer === undefined ) {
  16898. createBuffer( attributeProperties, data, bufferType );
  16899. } else if ( attributeProperties.version !== data.version ) {
  16900. updateBuffer( attributeProperties, data, bufferType );
  16901. }
  16902. }
  16903. function createBuffer( attributeProperties, data, bufferType ) {
  16904. attributeProperties.__webglBuffer = gl.createBuffer();
  16905. gl.bindBuffer( bufferType, attributeProperties.__webglBuffer );
  16906. var usage = data.dynamic ? gl.DYNAMIC_DRAW : gl.STATIC_DRAW;
  16907. gl.bufferData( bufferType, data.array, usage );
  16908. attributeProperties.version = data.version;
  16909. }
  16910. function updateBuffer( attributeProperties, data, bufferType ) {
  16911. gl.bindBuffer( bufferType, attributeProperties.__webglBuffer );
  16912. if ( data.dynamic === false || data.updateRange.count === - 1 ) {
  16913. // Not using update ranges
  16914. gl.bufferSubData( bufferType, 0, data.array );
  16915. } else if ( data.updateRange.count === 0 ) {
  16916. 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.' );
  16917. } else {
  16918. gl.bufferSubData( bufferType, data.updateRange.offset * data.array.BYTES_PER_ELEMENT,
  16919. data.array.subarray( data.updateRange.offset, data.updateRange.offset + data.updateRange.count ) );
  16920. data.updateRange.count = 0; // reset range
  16921. }
  16922. attributeProperties.version = data.version;
  16923. }
  16924. function getAttributeBuffer( attribute ) {
  16925. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  16926. return properties.get( attribute.data ).__webglBuffer;
  16927. }
  16928. return properties.get( attribute ).__webglBuffer;
  16929. }
  16930. function getWireframeAttribute( geometry ) {
  16931. var property = properties.get( geometry );
  16932. if ( property.wireframe !== undefined ) {
  16933. return property.wireframe;
  16934. }
  16935. var indices = [];
  16936. var index = geometry.index;
  16937. var attributes = geometry.attributes;
  16938. var position = attributes.position;
  16939. // console.time( 'wireframe' );
  16940. if ( index !== null ) {
  16941. var edges = {};
  16942. var array = index.array;
  16943. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  16944. var a = array[ i + 0 ];
  16945. var b = array[ i + 1 ];
  16946. var c = array[ i + 2 ];
  16947. if ( checkEdge( edges, a, b ) ) indices.push( a, b );
  16948. if ( checkEdge( edges, b, c ) ) indices.push( b, c );
  16949. if ( checkEdge( edges, c, a ) ) indices.push( c, a );
  16950. }
  16951. } else {
  16952. var array = attributes.position.array;
  16953. for ( var i = 0, l = ( array.length / 3 ) - 1; i < l; i += 3 ) {
  16954. var a = i + 0;
  16955. var b = i + 1;
  16956. var c = i + 2;
  16957. indices.push( a, b, b, c, c, a );
  16958. }
  16959. }
  16960. // console.timeEnd( 'wireframe' );
  16961. var TypeArray = position.count > 65535 ? Uint32Array : Uint16Array;
  16962. var attribute = new THREE.BufferAttribute( new TypeArray( indices ), 1 );
  16963. updateAttribute( attribute, gl.ELEMENT_ARRAY_BUFFER );
  16964. property.wireframe = attribute;
  16965. return attribute;
  16966. }
  16967. function checkEdge( edges, a, b ) {
  16968. if ( a > b ) {
  16969. var tmp = a;
  16970. a = b;
  16971. b = tmp;
  16972. }
  16973. var list = edges[ a ];
  16974. if ( list === undefined ) {
  16975. edges[ a ] = [ b ];
  16976. return true;
  16977. } else if ( list.indexOf( b ) === -1 ) {
  16978. list.push( b );
  16979. return true;
  16980. }
  16981. return false;
  16982. }
  16983. this.getAttributeBuffer = getAttributeBuffer;
  16984. this.getWireframeAttribute = getWireframeAttribute;
  16985. this.update = update;
  16986. };
  16987. // File:src/renderers/webgl/WebGLProgram.js
  16988. THREE.WebGLProgram = ( function () {
  16989. var programIdCount = 0;
  16990. // TODO: Combine the regex
  16991. var structRe = /^([\w\d_]+)\.([\w\d_]+)$/;
  16992. var arrayStructRe = /^([\w\d_]+)\[(\d+)\]\.([\w\d_]+)$/;
  16993. var arrayRe = /^([\w\d_]+)\[0\]$/;
  16994. function generateExtensions( extensions, parameters, rendererExtensions ) {
  16995. extensions = extensions || {};
  16996. var chunks = [
  16997. ( extensions.derivatives || parameters.bumpMap || parameters.normalMap || parameters.flatShading ) ? '#extension GL_OES_standard_derivatives : enable' : '',
  16998. ( extensions.fragDepth || parameters.logarithmicDepthBuffer ) && rendererExtensions.get( 'EXT_frag_depth' ) ? '#extension GL_EXT_frag_depth : enable' : '',
  16999. ( extensions.drawBuffers ) && rendererExtensions.get( 'WEBGL_draw_buffers' ) ? '#extension GL_EXT_draw_buffers : require' : '',
  17000. ( extensions.shaderTextureLOD || parameters.envMap ) && rendererExtensions.get( 'EXT_shader_texture_lod' ) ? '#extension GL_EXT_shader_texture_lod : enable' : '',
  17001. ];
  17002. return chunks.filter( filterEmptyLine ).join( '\n' );
  17003. }
  17004. function generateDefines( defines ) {
  17005. var chunks = [];
  17006. for ( var name in defines ) {
  17007. var value = defines[ name ];
  17008. if ( value === false ) continue;
  17009. chunks.push( '#define ' + name + ' ' + value );
  17010. }
  17011. return chunks.join( '\n' );
  17012. }
  17013. function fetchUniformLocations( gl, program, identifiers ) {
  17014. var uniforms = {};
  17015. var n = gl.getProgramParameter( program, gl.ACTIVE_UNIFORMS );
  17016. for ( var i = 0; i < n; i ++ ) {
  17017. var info = gl.getActiveUniform( program, i );
  17018. var name = info.name;
  17019. var location = gl.getUniformLocation( program, name );
  17020. //console.log("THREE.WebGLProgram: ACTIVE UNIFORM:", name);
  17021. var matches = structRe.exec(name);
  17022. if( matches ) {
  17023. var structName = matches[1];
  17024. var structProperty = matches[2];
  17025. var uniformsStruct = uniforms[ structName ];
  17026. if( ! uniformsStruct ) {
  17027. uniformsStruct = uniforms[ structName ] = {};
  17028. }
  17029. uniformsStruct[ structProperty ] = location;
  17030. continue;
  17031. }
  17032. matches = arrayStructRe.exec(name);
  17033. if( matches ) {
  17034. var arrayName = matches[1];
  17035. var arrayIndex = matches[2];
  17036. var arrayProperty = matches[3];
  17037. var uniformsArray = uniforms[ arrayName ];
  17038. if( ! uniformsArray ) {
  17039. uniformsArray = uniforms[ arrayName ] = [];
  17040. }
  17041. var uniformsArrayIndex = uniformsArray[ arrayIndex ];
  17042. if( ! uniformsArrayIndex ) {
  17043. uniformsArrayIndex = uniformsArray[ arrayIndex ] = {};
  17044. }
  17045. uniformsArrayIndex[ arrayProperty ] = location;
  17046. continue;
  17047. }
  17048. matches = arrayRe.exec(name)
  17049. if( matches ) {
  17050. var arrayName = matches[1];
  17051. uniforms[ arrayName ] = location;
  17052. continue;
  17053. }
  17054. uniforms[ name ] = location;
  17055. }
  17056. return uniforms;
  17057. }
  17058. function fetchAttributeLocations( gl, program, identifiers ) {
  17059. var attributes = {};
  17060. var n = gl.getProgramParameter( program, gl.ACTIVE_ATTRIBUTES );
  17061. for ( var i = 0; i < n; i ++ ) {
  17062. var info = gl.getActiveAttrib( program, i );
  17063. var name = info.name;
  17064. // console.log("THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:", name, i );
  17065. attributes[ name ] = gl.getAttribLocation( program, name );
  17066. }
  17067. return attributes;
  17068. }
  17069. function filterEmptyLine( string ) {
  17070. return string !== '';
  17071. }
  17072. return function WebGLProgram( renderer, code, material, parameters ) {
  17073. var gl = renderer.context;
  17074. var extensions = material.extensions;
  17075. var defines = material.defines;
  17076. var vertexShader = material.__webglShader.vertexShader;
  17077. var fragmentShader = material.__webglShader.fragmentShader;
  17078. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  17079. if ( parameters.shadowMapType === THREE.PCFShadowMap ) {
  17080. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  17081. } else if ( parameters.shadowMapType === THREE.PCFSoftShadowMap ) {
  17082. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  17083. }
  17084. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  17085. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  17086. var envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  17087. if ( parameters.envMap ) {
  17088. switch ( material.envMap.mapping ) {
  17089. case THREE.CubeReflectionMapping:
  17090. case THREE.CubeRefractionMapping:
  17091. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  17092. break;
  17093. case THREE.EquirectangularReflectionMapping:
  17094. case THREE.EquirectangularRefractionMapping:
  17095. envMapTypeDefine = 'ENVMAP_TYPE_EQUIREC';
  17096. break;
  17097. case THREE.SphericalReflectionMapping:
  17098. envMapTypeDefine = 'ENVMAP_TYPE_SPHERE';
  17099. break;
  17100. }
  17101. switch ( material.envMap.mapping ) {
  17102. case THREE.CubeRefractionMapping:
  17103. case THREE.EquirectangularRefractionMapping:
  17104. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  17105. break;
  17106. }
  17107. switch ( material.combine ) {
  17108. case THREE.MultiplyOperation:
  17109. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  17110. break;
  17111. case THREE.MixOperation:
  17112. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  17113. break;
  17114. case THREE.AddOperation:
  17115. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  17116. break;
  17117. }
  17118. }
  17119. var gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
  17120. // console.log( 'building new program ' );
  17121. //
  17122. var customExtensions = generateExtensions( extensions, parameters, renderer.extensions );
  17123. var customDefines = generateDefines( defines );
  17124. //
  17125. var program = gl.createProgram();
  17126. var prefixVertex, prefixFragment;
  17127. if ( material instanceof THREE.RawShaderMaterial ) {
  17128. prefixVertex = '';
  17129. prefixFragment = '';
  17130. } else {
  17131. prefixVertex = [
  17132. 'precision ' + parameters.precision + ' float;',
  17133. 'precision ' + parameters.precision + ' int;',
  17134. '#define SHADER_NAME ' + material.__webglShader.name,
  17135. customDefines,
  17136. parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '',
  17137. renderer.gammaInput ? '#define GAMMA_INPUT' : '',
  17138. renderer.gammaOutput ? '#define GAMMA_OUTPUT' : '',
  17139. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  17140. '#define MAX_DIR_LIGHTS ' + parameters.maxDirLights,
  17141. '#define MAX_POINT_LIGHTS ' + parameters.maxPointLights,
  17142. '#define MAX_SPOT_LIGHTS ' + parameters.maxSpotLights,
  17143. '#define MAX_HEMI_LIGHTS ' + parameters.maxHemiLights,
  17144. '#define MAX_SHADOWS ' + parameters.maxShadows,
  17145. '#define MAX_BONES ' + parameters.maxBones,
  17146. parameters.map ? '#define USE_MAP' : '',
  17147. parameters.envMap ? '#define USE_ENVMAP' : '',
  17148. parameters.envMap ? '#define ' + envMapModeDefine : '',
  17149. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  17150. parameters.aoMap ? '#define USE_AOMAP' : '',
  17151. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  17152. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  17153. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  17154. parameters.displacementMap && parameters.supportsVertexTextures ? '#define USE_DISPLACEMENTMAP' : '',
  17155. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  17156. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  17157. parameters.reflectivityMap ? '#define USE_REFLECTIVITYMAP' : '',
  17158. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  17159. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  17160. parameters.vertexColors ? '#define USE_COLOR' : '',
  17161. parameters.flatShading ? '#define FLAT_SHADED' : '',
  17162. parameters.skinning ? '#define USE_SKINNING' : '',
  17163. parameters.useVertexTexture ? '#define BONE_TEXTURE' : '',
  17164. parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
  17165. parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '',
  17166. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  17167. parameters.flipSided ? '#define FLIP_SIDED' : '',
  17168. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  17169. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  17170. parameters.shadowMapDebug ? '#define SHADOWMAP_DEBUG' : '',
  17171. parameters.pointLightShadows > 0 ? '#define POINT_LIGHT_SHADOWS' : '',
  17172. parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
  17173. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  17174. parameters.logarithmicDepthBuffer && renderer.extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  17175. 'uniform mat4 modelMatrix;',
  17176. 'uniform mat4 modelViewMatrix;',
  17177. 'uniform mat4 projectionMatrix;',
  17178. 'uniform mat4 viewMatrix;',
  17179. 'uniform mat3 normalMatrix;',
  17180. 'uniform vec3 cameraPosition;',
  17181. 'attribute vec3 position;',
  17182. 'attribute vec3 normal;',
  17183. 'attribute vec2 uv;',
  17184. '#ifdef USE_COLOR',
  17185. ' attribute vec3 color;',
  17186. '#endif',
  17187. '#ifdef USE_MORPHTARGETS',
  17188. ' attribute vec3 morphTarget0;',
  17189. ' attribute vec3 morphTarget1;',
  17190. ' attribute vec3 morphTarget2;',
  17191. ' attribute vec3 morphTarget3;',
  17192. ' #ifdef USE_MORPHNORMALS',
  17193. ' attribute vec3 morphNormal0;',
  17194. ' attribute vec3 morphNormal1;',
  17195. ' attribute vec3 morphNormal2;',
  17196. ' attribute vec3 morphNormal3;',
  17197. ' #else',
  17198. ' attribute vec3 morphTarget4;',
  17199. ' attribute vec3 morphTarget5;',
  17200. ' attribute vec3 morphTarget6;',
  17201. ' attribute vec3 morphTarget7;',
  17202. ' #endif',
  17203. '#endif',
  17204. '#ifdef USE_SKINNING',
  17205. ' attribute vec4 skinIndex;',
  17206. ' attribute vec4 skinWeight;',
  17207. '#endif',
  17208. '\n'
  17209. ].filter( filterEmptyLine ).join( '\n' );
  17210. prefixFragment = [
  17211. customExtensions,
  17212. 'precision ' + parameters.precision + ' float;',
  17213. 'precision ' + parameters.precision + ' int;',
  17214. '#define SHADER_NAME ' + material.__webglShader.name,
  17215. customDefines,
  17216. '#define MAX_DIR_LIGHTS ' + parameters.maxDirLights,
  17217. '#define MAX_POINT_LIGHTS ' + parameters.maxPointLights,
  17218. '#define MAX_SPOT_LIGHTS ' + parameters.maxSpotLights,
  17219. '#define MAX_HEMI_LIGHTS ' + parameters.maxHemiLights,
  17220. '#define MAX_SHADOWS ' + parameters.maxShadows,
  17221. parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest : '',
  17222. renderer.gammaInput ? '#define GAMMA_INPUT' : '',
  17223. renderer.gammaOutput ? '#define GAMMA_OUTPUT' : '',
  17224. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  17225. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  17226. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  17227. parameters.map ? '#define USE_MAP' : '',
  17228. parameters.envMap ? '#define USE_ENVMAP' : '',
  17229. parameters.envMap ? '#define ' + envMapTypeDefine : '',
  17230. parameters.envMap ? '#define ' + envMapModeDefine : '',
  17231. parameters.envMap ? '#define ' + envMapBlendingDefine : '',
  17232. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  17233. parameters.aoMap ? '#define USE_AOMAP' : '',
  17234. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  17235. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  17236. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  17237. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  17238. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  17239. parameters.reflectivityMap ? '#define USE_REFLECTIVITYMAP' : '',
  17240. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  17241. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  17242. parameters.vertexColors ? '#define USE_COLOR' : '',
  17243. parameters.flatShading ? '#define FLAT_SHADED' : '',
  17244. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  17245. parameters.flipSided ? '#define FLIP_SIDED' : '',
  17246. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  17247. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  17248. parameters.shadowMapDebug ? '#define SHADOWMAP_DEBUG' : '',
  17249. parameters.pointLightShadows > 0 ? '#define POINT_LIGHT_SHADOWS' : '',
  17250. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  17251. parameters.logarithmicDepthBuffer && renderer.extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  17252. parameters.envMap && renderer.extensions.get( 'EXT_shader_texture_lod' ) ? '#define TEXTURE_CUBE_LOD_EXT' : '',
  17253. 'uniform mat4 viewMatrix;',
  17254. 'uniform vec3 cameraPosition;',
  17255. '\n'
  17256. ].filter( filterEmptyLine ).join( '\n' );
  17257. }
  17258. var vertexGlsl = prefixVertex + vertexShader;
  17259. var fragmentGlsl = prefixFragment + fragmentShader;
  17260. var glVertexShader = THREE.WebGLShader( gl, gl.VERTEX_SHADER, vertexGlsl );
  17261. var glFragmentShader = THREE.WebGLShader( gl, gl.FRAGMENT_SHADER, fragmentGlsl );
  17262. gl.attachShader( program, glVertexShader );
  17263. gl.attachShader( program, glFragmentShader );
  17264. // Force a particular attribute to index 0.
  17265. if ( material.index0AttributeName !== undefined ) {
  17266. gl.bindAttribLocation( program, 0, material.index0AttributeName );
  17267. } else if ( parameters.morphTargets === true ) {
  17268. // programs with morphTargets displace position out of attribute 0
  17269. gl.bindAttribLocation( program, 0, 'position' );
  17270. }
  17271. gl.linkProgram( program );
  17272. var programLog = gl.getProgramInfoLog( program );
  17273. var vertexLog = gl.getShaderInfoLog( glVertexShader );
  17274. var fragmentLog = gl.getShaderInfoLog( glFragmentShader );
  17275. var runnable = true;
  17276. var haveDiagnostics = true;
  17277. if ( gl.getProgramParameter( program, gl.LINK_STATUS ) === false ) {
  17278. runnable = false;
  17279. console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), 'gl.VALIDATE_STATUS', gl.getProgramParameter( program, gl.VALIDATE_STATUS ), 'gl.getProgramInfoLog', programLog, vertexLog, fragmentLog );
  17280. } else if ( programLog !== '' ) {
  17281. console.warn( 'THREE.WebGLProgram: gl.getProgramInfoLog()', programLog );
  17282. } else if ( vertexLog === '' || fragmentLog === '' ) {
  17283. haveDiagnostics = false;
  17284. }
  17285. if ( haveDiagnostics ) {
  17286. this.diagnostics = {
  17287. runnable: runnable,
  17288. material: material,
  17289. programLog: programLog,
  17290. vertexShader: {
  17291. log: vertexLog,
  17292. prefix: prefixVertex
  17293. },
  17294. fragmentShader: {
  17295. log: fragmentLog,
  17296. prefix: prefixFragment
  17297. }
  17298. };
  17299. }
  17300. // clean up
  17301. gl.deleteShader( glVertexShader );
  17302. gl.deleteShader( glFragmentShader );
  17303. // set up caching for uniform locations
  17304. var cachedUniforms;
  17305. this.getUniforms = function() {
  17306. if ( cachedUniforms === undefined ) {
  17307. cachedUniforms = fetchUniformLocations( gl, program );
  17308. }
  17309. return cachedUniforms;
  17310. };
  17311. // set up caching for attribute locations
  17312. var cachedAttributes;
  17313. this.getAttributes = function() {
  17314. if ( cachedAttributes === undefined ) {
  17315. cachedAttributes = fetchAttributeLocations( gl, program );
  17316. }
  17317. return cachedAttributes;
  17318. };
  17319. // free resource
  17320. this.destroy = function() {
  17321. gl.deleteProgram( program );
  17322. this.program = undefined;
  17323. };
  17324. // DEPRECATED
  17325. Object.defineProperties( this, {
  17326. uniforms: {
  17327. get: function() {
  17328. console.warn( 'THREE.WebGLProgram: .uniforms is now .getUniforms().' );
  17329. return this.getUniforms();
  17330. }
  17331. },
  17332. attributes: {
  17333. get: function() {
  17334. console.warn( 'THREE.WebGLProgram: .attributes is now .getAttributes().' );
  17335. return this.getAttributes();
  17336. }
  17337. }
  17338. } );
  17339. //
  17340. this.id = programIdCount ++;
  17341. this.code = code;
  17342. this.usedTimes = 1;
  17343. this.program = program;
  17344. this.vertexShader = glVertexShader;
  17345. this.fragmentShader = glFragmentShader;
  17346. return this;
  17347. };
  17348. } )();
  17349. // File:src/renderers/webgl/WebGLPrograms.js
  17350. THREE.WebGLPrograms = function ( renderer, capabilities ) {
  17351. var programs = [];
  17352. var shaderIDs = {
  17353. MeshDepthMaterial: 'depth',
  17354. MeshNormalMaterial: 'normal',
  17355. MeshBasicMaterial: 'basic',
  17356. MeshLambertMaterial: 'lambert',
  17357. MeshPhongMaterial: 'phong',
  17358. MeshPhysicalMaterial: 'physical',
  17359. LineBasicMaterial: 'basic',
  17360. LineDashedMaterial: 'dashed',
  17361. PointsMaterial: 'points'
  17362. };
  17363. var parameterNames = [
  17364. "precision", "supportsVertexTextures", "map", "envMap", "envMapMode",
  17365. "lightMap", "aoMap", "emissiveMap", "bumpMap", "normalMap", "displacementMap", "specularMap",
  17366. "roughnessMap", "reflectivityMap", "metalnessMap",
  17367. "alphaMap", "combine", "vertexColors", "fog", "useFog", "fogExp",
  17368. "flatShading", "sizeAttenuation", "logarithmicDepthBuffer", "skinning",
  17369. "maxBones", "useVertexTexture", "morphTargets", "morphNormals",
  17370. "maxMorphTargets", "maxMorphNormals", "maxDirLights", "maxPointLights",
  17371. "maxSpotLights", "maxHemiLights", "maxShadows", "shadowMapEnabled", "pointLightShadows",
  17372. "shadowMapType", "shadowMapDebug", "alphaTest", "doubleSided",
  17373. "flipSided"
  17374. ];
  17375. function allocateBones ( object ) {
  17376. if ( capabilities.floatVertexTextures && object && object.skeleton && object.skeleton.useVertexTexture ) {
  17377. return 1024;
  17378. } else {
  17379. // default for when object is not specified
  17380. // ( for example when prebuilding shader to be used with multiple objects )
  17381. //
  17382. // - leave some extra space for other uniforms
  17383. // - limit here is ANGLE's 254 max uniform vectors
  17384. // (up to 54 should be safe)
  17385. var nVertexUniforms = capabilities.maxVertexUniforms;
  17386. var nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 );
  17387. var maxBones = nVertexMatrices;
  17388. if ( object !== undefined && object instanceof THREE.SkinnedMesh ) {
  17389. maxBones = Math.min( object.skeleton.bones.length, maxBones );
  17390. if ( maxBones < object.skeleton.bones.length ) {
  17391. console.warn( 'WebGLRenderer: too many bones - ' + object.skeleton.bones.length + ', this GPU supports just ' + maxBones + ' (try OpenGL instead of ANGLE)' );
  17392. }
  17393. }
  17394. return maxBones;
  17395. }
  17396. }
  17397. this.getParameters = function ( material, lights, fog, object ) {
  17398. var shaderID = shaderIDs[ material.type ];
  17399. // heuristics to create shader parameters according to lights in the scene
  17400. // (not to blow over maxLights budget)
  17401. var maxBones = allocateBones( object );
  17402. var precision = renderer.getPrecision();
  17403. if ( material.precision !== null ) {
  17404. precision = capabilities.getMaxPrecision( material.precision );
  17405. if ( precision !== material.precision ) {
  17406. console.warn( 'THREE.WebGLRenderer.initMaterial:', material.precision, 'not supported, using', precision, 'instead.' );
  17407. }
  17408. }
  17409. var parameters = {
  17410. shaderID: shaderID,
  17411. precision: precision,
  17412. supportsVertexTextures: capabilities.vertexTextures,
  17413. map: !! material.map,
  17414. envMap: !! material.envMap,
  17415. envMapMode: material.envMap && material.envMap.mapping,
  17416. lightMap: !! material.lightMap,
  17417. aoMap: !! material.aoMap,
  17418. emissiveMap: !! material.emissiveMap,
  17419. bumpMap: !! material.bumpMap,
  17420. normalMap: !! material.normalMap,
  17421. displacementMap: !! material.displacementMap,
  17422. roughnessMap: !! material.roughnessMap,
  17423. reflectivityMap: !! material.reflectivityMap,
  17424. metalnessMap: !! material.metalnessMap,
  17425. specularMap: !! material.specularMap,
  17426. alphaMap: !! material.alphaMap,
  17427. combine: material.combine,
  17428. vertexColors: material.vertexColors,
  17429. fog: fog,
  17430. useFog: material.fog,
  17431. fogExp: fog instanceof THREE.FogExp2,
  17432. flatShading: material.shading === THREE.FlatShading,
  17433. sizeAttenuation: material.sizeAttenuation,
  17434. logarithmicDepthBuffer: capabilities.logarithmicDepthBuffer,
  17435. skinning: material.skinning,
  17436. maxBones: maxBones,
  17437. useVertexTexture: capabilities.floatVertexTextures && object && object.skeleton && object.skeleton.useVertexTexture,
  17438. morphTargets: material.morphTargets,
  17439. morphNormals: material.morphNormals,
  17440. maxMorphTargets: renderer.maxMorphTargets,
  17441. maxMorphNormals: renderer.maxMorphNormals,
  17442. maxDirLights: lights.directional.length,
  17443. maxPointLights: lights.point.length,
  17444. maxSpotLights: lights.spot.length,
  17445. maxHemiLights: lights.hemi.length,
  17446. maxShadows: lights.shadows,
  17447. pointLightShadows: lights.shadowsPointLight,
  17448. shadowMapEnabled: renderer.shadowMap.enabled && object.receiveShadow && lights.shadows > 0,
  17449. shadowMapType: renderer.shadowMap.type,
  17450. shadowMapDebug: renderer.shadowMap.debug,
  17451. alphaTest: material.alphaTest,
  17452. doubleSided: material.side === THREE.DoubleSide,
  17453. flipSided: material.side === THREE.BackSide
  17454. };
  17455. return parameters;
  17456. };
  17457. this.getProgramCode = function ( material, parameters ) {
  17458. var chunks = [];
  17459. if ( parameters.shaderID ) {
  17460. chunks.push( parameters.shaderID );
  17461. } else {
  17462. chunks.push( material.fragmentShader );
  17463. chunks.push( material.vertexShader );
  17464. }
  17465. if ( material.defines !== undefined ) {
  17466. for ( var name in material.defines ) {
  17467. chunks.push( name );
  17468. chunks.push( material.defines[ name ] );
  17469. }
  17470. }
  17471. for ( var i = 0; i < parameterNames.length; i ++ ) {
  17472. var parameterName = parameterNames[ i ];
  17473. chunks.push( parameterName );
  17474. chunks.push( parameters[ parameterName ] );
  17475. }
  17476. return chunks.join();
  17477. };
  17478. this.acquireProgram = function ( material, parameters, code ) {
  17479. var program;
  17480. // Check if code has been already compiled
  17481. for ( var p = 0, pl = programs.length; p < pl; p ++ ) {
  17482. var programInfo = programs[ p ];
  17483. if ( programInfo.code === code ) {
  17484. program = programInfo;
  17485. ++ program.usedTimes;
  17486. break;
  17487. }
  17488. }
  17489. if ( program === undefined ) {
  17490. program = new THREE.WebGLProgram( renderer, code, material, parameters );
  17491. programs.push( program );
  17492. }
  17493. return program;
  17494. };
  17495. this.releaseProgram = function( program ) {
  17496. if ( -- program.usedTimes === 0 ) {
  17497. // Remove from unordered set
  17498. var i = programs.indexOf( program );
  17499. programs[ i ] = programs[ programs.length - 1 ];
  17500. programs.pop();
  17501. // Free WebGL resources
  17502. program.destroy();
  17503. }
  17504. };
  17505. // Exposed for resource monitoring & error feedback via renderer.info:
  17506. this.programs = programs;
  17507. };
  17508. // File:src/renderers/webgl/WebGLProperties.js
  17509. /**
  17510. * @author fordacious / fordacious.github.io
  17511. */
  17512. THREE.WebGLProperties = function () {
  17513. var properties = {};
  17514. this.get = function ( object ) {
  17515. var uuid = object.uuid;
  17516. var map = properties[ uuid ];
  17517. if ( map === undefined ) {
  17518. map = {};
  17519. properties[ uuid ] = map;
  17520. }
  17521. return map;
  17522. };
  17523. this.delete = function ( object ) {
  17524. delete properties[ object.uuid ];
  17525. };
  17526. this.clear = function () {
  17527. properties = {};
  17528. };
  17529. };
  17530. // File:src/renderers/webgl/WebGLShader.js
  17531. THREE.WebGLShader = ( function () {
  17532. function addLineNumbers( string ) {
  17533. var lines = string.split( '\n' );
  17534. for ( var i = 0; i < lines.length; i ++ ) {
  17535. lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
  17536. }
  17537. return lines.join( '\n' );
  17538. }
  17539. return function WebGLShader( gl, type, string ) {
  17540. var shader = gl.createShader( type );
  17541. gl.shaderSource( shader, string );
  17542. gl.compileShader( shader );
  17543. if ( gl.getShaderParameter( shader, gl.COMPILE_STATUS ) === false ) {
  17544. console.error( 'THREE.WebGLShader: Shader couldn\'t compile.' );
  17545. }
  17546. if ( gl.getShaderInfoLog( shader ) !== '' ) {
  17547. console.warn( 'THREE.WebGLShader: gl.getShaderInfoLog()', type === gl.VERTEX_SHADER ? 'vertex' : 'fragment', gl.getShaderInfoLog( shader ), addLineNumbers( string ) );
  17548. }
  17549. // --enable-privileged-webgl-extension
  17550. // console.log( type, gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  17551. return shader;
  17552. };
  17553. } )();
  17554. // File:src/renderers/webgl/WebGLShadowMap.js
  17555. /**
  17556. * @author alteredq / http://alteredqualia.com/
  17557. * @author mrdoob / http://mrdoob.com/
  17558. */
  17559. THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
  17560. var _gl = _renderer.context,
  17561. _state = _renderer.state,
  17562. _frustum = new THREE.Frustum(),
  17563. _projScreenMatrix = new THREE.Matrix4(),
  17564. _min = new THREE.Vector3(),
  17565. _max = new THREE.Vector3(),
  17566. _lookTarget = new THREE.Vector3(),
  17567. _lightPositionWorld = new THREE.Vector3(),
  17568. _renderList = [],
  17569. _MorphingFlag = 1,
  17570. _SkinningFlag = 2,
  17571. _NumberOfMaterialVariants = ( _MorphingFlag | _SkinningFlag ) + 1,
  17572. _depthMaterials = new Array( _NumberOfMaterialVariants ),
  17573. _distanceMaterials = new Array( _NumberOfMaterialVariants );
  17574. var cubeDirections = [
  17575. new THREE.Vector3( 1, 0, 0 ), new THREE.Vector3( - 1, 0, 0 ), new THREE.Vector3( 0, 0, 1 ),
  17576. new THREE.Vector3( 0, 0, - 1 ), new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, - 1, 0 )
  17577. ];
  17578. var cubeUps = [
  17579. new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 1, 0 ),
  17580. new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 0, 1 ), new THREE.Vector3( 0, 0, - 1 )
  17581. ];
  17582. var cube2DViewPorts = [
  17583. new THREE.Vector4(), new THREE.Vector4(), new THREE.Vector4(),
  17584. new THREE.Vector4(), new THREE.Vector4(), new THREE.Vector4()
  17585. ];
  17586. var _vector4 = new THREE.Vector4();
  17587. // init
  17588. var depthShader = THREE.ShaderLib[ "depthRGBA" ];
  17589. var depthUniforms = THREE.UniformsUtils.clone( depthShader.uniforms );
  17590. var distanceShader = THREE.ShaderLib[ "distanceRGBA" ];
  17591. var distanceUniforms = THREE.UniformsUtils.clone( distanceShader.uniforms );
  17592. for ( var i = 0; i !== _NumberOfMaterialVariants; ++ i ) {
  17593. var useMorphing = ( i & _MorphingFlag ) !== 0;
  17594. var useSkinning = ( i & _SkinningFlag ) !== 0;
  17595. var depthMaterial = new THREE.ShaderMaterial( {
  17596. uniforms: depthUniforms,
  17597. vertexShader: depthShader.vertexShader,
  17598. fragmentShader: depthShader.fragmentShader,
  17599. morphTargets: useMorphing,
  17600. skinning: useSkinning
  17601. } );
  17602. depthMaterial._shadowPass = true;
  17603. _depthMaterials[ i ] = depthMaterial;
  17604. var distanceMaterial = new THREE.ShaderMaterial( {
  17605. uniforms: distanceUniforms,
  17606. vertexShader: distanceShader.vertexShader,
  17607. fragmentShader: distanceShader.fragmentShader,
  17608. morphTargets: useMorphing,
  17609. skinning: useSkinning
  17610. } );
  17611. distanceMaterial._shadowPass = true;
  17612. _distanceMaterials[ i ] = distanceMaterial;
  17613. }
  17614. //
  17615. var scope = this;
  17616. this.enabled = false;
  17617. this.autoUpdate = true;
  17618. this.needsUpdate = false;
  17619. this.type = THREE.PCFShadowMap;
  17620. this.cullFace = THREE.CullFaceFront;
  17621. this.render = function ( scene, camera ) {
  17622. var faceCount, isPointLight;
  17623. if ( scope.enabled === false ) return;
  17624. if ( scope.autoUpdate === false && scope.needsUpdate === false ) return;
  17625. // Set GL state for depth map.
  17626. _gl.clearColor( 1, 1, 1, 1 );
  17627. _state.disable( _gl.BLEND );
  17628. _state.enable( _gl.CULL_FACE );
  17629. _gl.frontFace( _gl.CCW );
  17630. _gl.cullFace( scope.cullFace === THREE.CullFaceFront ? _gl.FRONT : _gl.BACK );
  17631. _state.setDepthTest( true );
  17632. // save the existing viewport so it can be restored later
  17633. _renderer.getViewport( _vector4 );
  17634. // render depth map
  17635. for ( var i = 0, il = _lights.length; i < il; i ++ ) {
  17636. var light = _lights[ i ];
  17637. if ( light.castShadow === true ) {
  17638. var shadow = light.shadow;
  17639. var shadowCamera = shadow.camera;
  17640. var shadowMapSize = shadow.mapSize;
  17641. if ( light instanceof THREE.PointLight ) {
  17642. faceCount = 6;
  17643. isPointLight = true;
  17644. var vpWidth = shadowMapSize.x / 4.0;
  17645. var vpHeight = shadowMapSize.y / 2.0;
  17646. // These viewports map a cube-map onto a 2D texture with the
  17647. // following orientation:
  17648. //
  17649. // xzXZ
  17650. // y Y
  17651. //
  17652. // X - Positive x direction
  17653. // x - Negative x direction
  17654. // Y - Positive y direction
  17655. // y - Negative y direction
  17656. // Z - Positive z direction
  17657. // z - Negative z direction
  17658. // positive X
  17659. cube2DViewPorts[ 0 ].set( vpWidth * 2, vpHeight, vpWidth, vpHeight );
  17660. // negative X
  17661. cube2DViewPorts[ 1 ].set( 0, vpHeight, vpWidth, vpHeight );
  17662. // positive Z
  17663. cube2DViewPorts[ 2 ].set( vpWidth * 3, vpHeight, vpWidth, vpHeight );
  17664. // negative Z
  17665. cube2DViewPorts[ 3 ].set( vpWidth, vpHeight, vpWidth, vpHeight );
  17666. // positive Y
  17667. cube2DViewPorts[ 4 ].set( vpWidth * 3, 0, vpWidth, vpHeight );
  17668. // negative Y
  17669. cube2DViewPorts[ 5 ].set( vpWidth, 0, vpWidth, vpHeight );
  17670. } else {
  17671. faceCount = 1;
  17672. isPointLight = false;
  17673. }
  17674. if ( shadow.map === null ) {
  17675. var shadowFilter = THREE.LinearFilter;
  17676. if ( scope.type === THREE.PCFSoftShadowMap ) {
  17677. shadowFilter = THREE.NearestFilter;
  17678. }
  17679. var pars = { minFilter: shadowFilter, magFilter: shadowFilter, format: THREE.RGBAFormat };
  17680. shadow.map = new THREE.WebGLRenderTarget( shadowMapSize.x, shadowMapSize.y, pars );
  17681. shadow.matrix = new THREE.Matrix4();
  17682. //
  17683. if ( light instanceof THREE.SpotLight ) {
  17684. shadowCamera.aspect = shadowMapSize.x / shadowMapSize.y;
  17685. }
  17686. shadowCamera.updateProjectionMatrix();
  17687. }
  17688. var shadowMap = shadow.map;
  17689. var shadowMatrix = shadow.matrix;
  17690. _lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  17691. shadowCamera.position.copy( _lightPositionWorld );
  17692. _renderer.setRenderTarget( shadowMap );
  17693. _renderer.clear();
  17694. // render shadow map for each cube face (if omni-directional) or
  17695. // run a single pass if not
  17696. for ( var face = 0; face < faceCount; face ++ ) {
  17697. if ( isPointLight ) {
  17698. _lookTarget.copy( shadowCamera.position );
  17699. _lookTarget.add( cubeDirections[ face ] );
  17700. shadowCamera.up.copy( cubeUps[ face ] );
  17701. shadowCamera.lookAt( _lookTarget );
  17702. var vpDimensions = cube2DViewPorts[ face ];
  17703. _renderer.setViewport( vpDimensions.x, vpDimensions.y, vpDimensions.z, vpDimensions.w );
  17704. } else {
  17705. _lookTarget.setFromMatrixPosition( light.target.matrixWorld );
  17706. shadowCamera.lookAt( _lookTarget );
  17707. }
  17708. shadowCamera.updateMatrixWorld();
  17709. shadowCamera.matrixWorldInverse.getInverse( shadowCamera.matrixWorld );
  17710. // compute shadow matrix
  17711. shadowMatrix.set(
  17712. 0.5, 0.0, 0.0, 0.5,
  17713. 0.0, 0.5, 0.0, 0.5,
  17714. 0.0, 0.0, 0.5, 0.5,
  17715. 0.0, 0.0, 0.0, 1.0
  17716. );
  17717. shadowMatrix.multiply( shadowCamera.projectionMatrix );
  17718. shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
  17719. // update camera matrices and frustum
  17720. _projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  17721. _frustum.setFromMatrix( _projScreenMatrix );
  17722. // set object matrices & frustum culling
  17723. _renderList.length = 0;
  17724. projectObject( scene, camera, shadowCamera );
  17725. // render shadow map
  17726. // render regular objects
  17727. for ( var j = 0, jl = _renderList.length; j < jl; j ++ ) {
  17728. var object = _renderList[ j ];
  17729. var geometry = _objects.update( object );
  17730. var material = object.material;
  17731. if ( material instanceof THREE.MeshFaceMaterial ) {
  17732. var groups = geometry.groups;
  17733. var materials = material.materials;
  17734. for ( var k = 0, kl = groups.length; k < kl; k ++ ) {
  17735. var group = groups[ k ];
  17736. var groupMaterial = materials[ group.materialIndex ];
  17737. if ( groupMaterial.visible === true ) {
  17738. var depthMaterial = getDepthMaterial( object, groupMaterial, isPointLight, _lightPositionWorld );
  17739. _renderer.renderBufferDirect( shadowCamera, _lights, null, geometry, depthMaterial, object, group );
  17740. }
  17741. }
  17742. } else {
  17743. var depthMaterial = getDepthMaterial( object, material, isPointLight, _lightPositionWorld );
  17744. _renderer.renderBufferDirect( shadowCamera, _lights, null, geometry, depthMaterial, object, null );
  17745. }
  17746. }
  17747. }
  17748. // We must call _renderer.resetGLState() at the end of each iteration of
  17749. // the light loop in order to force material updates for each light.
  17750. _renderer.resetGLState();
  17751. }
  17752. }
  17753. _renderer.setViewport( _vector4.x, _vector4.y, _vector4.z, _vector4.w );
  17754. // Restore GL state.
  17755. var clearColor = _renderer.getClearColor(),
  17756. clearAlpha = _renderer.getClearAlpha();
  17757. _renderer.setClearColor( clearColor, clearAlpha );
  17758. _state.enable( _gl.BLEND );
  17759. if ( scope.cullFace === THREE.CullFaceFront ) {
  17760. _gl.cullFace( _gl.BACK );
  17761. }
  17762. _renderer.resetGLState();
  17763. scope.needsUpdate = false;
  17764. };
  17765. function getDepthMaterial( object, material, isPointLight, lightPositionWorld ) {
  17766. var geometry = object.geometry;
  17767. var newMaterial = null;
  17768. var materialVariants = _depthMaterials;
  17769. var customMaterial = object.customDepthMaterial;
  17770. if ( isPointLight ) {
  17771. materialVariants = _distanceMaterials;
  17772. customMaterial = object.customDistanceMaterial;
  17773. }
  17774. if ( ! customMaterial ) {
  17775. var useMorphing = geometry.morphTargets !== undefined &&
  17776. geometry.morphTargets.length > 0 && material.morphTargets;
  17777. var useSkinning = object instanceof THREE.SkinnedMesh && material.skinning;
  17778. var variantIndex = 0;
  17779. if ( useMorphing ) variantIndex |= _MorphingFlag;
  17780. if ( useSkinning ) variantIndex |= _SkinningFlag;
  17781. newMaterial = materialVariants[ variantIndex ];
  17782. } else {
  17783. newMaterial = customMaterial;
  17784. }
  17785. newMaterial.visible = material.visible;
  17786. newMaterial.wireframe = material.wireframe;
  17787. newMaterial.wireframeLinewidth = material.wireframeLinewidth;
  17788. if ( isPointLight && newMaterial.uniforms.lightPos !== undefined ) {
  17789. newMaterial.uniforms.lightPos.value.copy( lightPositionWorld );
  17790. }
  17791. return newMaterial;
  17792. }
  17793. function projectObject( object, camera, shadowCamera ) {
  17794. if ( object.visible === false ) return;
  17795. if ( object.layers.test( camera.layers ) && ( object instanceof THREE.Mesh || object instanceof THREE.Line || object instanceof THREE.Points ) ) {
  17796. if ( object.castShadow && ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) ) {
  17797. var material = object.material;
  17798. if ( material.visible === true ) {
  17799. object.modelViewMatrix.multiplyMatrices( shadowCamera.matrixWorldInverse, object.matrixWorld );
  17800. _renderList.push( object );
  17801. }
  17802. }
  17803. }
  17804. var children = object.children;
  17805. for ( var i = 0, l = children.length; i < l; i ++ ) {
  17806. projectObject( children[ i ], camera, shadowCamera );
  17807. }
  17808. }
  17809. };
  17810. // File:src/renderers/webgl/WebGLState.js
  17811. /**
  17812. * @author mrdoob / http://mrdoob.com/
  17813. */
  17814. THREE.WebGLState = function ( gl, extensions, paramThreeToGL ) {
  17815. var _this = this;
  17816. var newAttributes = new Uint8Array( 16 );
  17817. var enabledAttributes = new Uint8Array( 16 );
  17818. var attributeDivisors = new Uint8Array( 16 );
  17819. var capabilities = {};
  17820. var compressedTextureFormats = null;
  17821. var currentBlending = null;
  17822. var currentBlendEquation = null;
  17823. var currentBlendSrc = null;
  17824. var currentBlendDst = null;
  17825. var currentBlendEquationAlpha = null;
  17826. var currentBlendSrcAlpha = null;
  17827. var currentBlendDstAlpha = null;
  17828. var currentDepthFunc = null;
  17829. var currentDepthWrite = null;
  17830. var currentColorWrite = null;
  17831. var currentFlipSided = null;
  17832. var currentLineWidth = null;
  17833. var currentPolygonOffsetFactor = null;
  17834. var currentPolygonOffsetUnits = null;
  17835. var maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
  17836. var currentTextureSlot = undefined;
  17837. var currentBoundTextures = {};
  17838. this.init = function () {
  17839. gl.clearColor( 0, 0, 0, 1 );
  17840. gl.clearDepth( 1 );
  17841. gl.clearStencil( 0 );
  17842. this.enable( gl.DEPTH_TEST );
  17843. gl.depthFunc( gl.LEQUAL );
  17844. gl.frontFace( gl.CCW );
  17845. gl.cullFace( gl.BACK );
  17846. this.enable( gl.CULL_FACE );
  17847. this.enable( gl.BLEND );
  17848. gl.blendEquation( gl.FUNC_ADD );
  17849. gl.blendFunc( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA );
  17850. };
  17851. this.initAttributes = function () {
  17852. for ( var i = 0, l = newAttributes.length; i < l; i ++ ) {
  17853. newAttributes[ i ] = 0;
  17854. }
  17855. };
  17856. this.enableAttribute = function ( attribute ) {
  17857. newAttributes[ attribute ] = 1;
  17858. if ( enabledAttributes[ attribute ] === 0 ) {
  17859. gl.enableVertexAttribArray( attribute );
  17860. enabledAttributes[ attribute ] = 1;
  17861. }
  17862. if ( attributeDivisors[ attribute ] !== 0 ) {
  17863. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  17864. extension.vertexAttribDivisorANGLE( attribute, 0 );
  17865. attributeDivisors[ attribute ] = 0;
  17866. }
  17867. };
  17868. this.enableAttributeAndDivisor = function ( attribute, meshPerAttribute, extension ) {
  17869. newAttributes[ attribute ] = 1;
  17870. if ( enabledAttributes[ attribute ] === 0 ) {
  17871. gl.enableVertexAttribArray( attribute );
  17872. enabledAttributes[ attribute ] = 1;
  17873. }
  17874. if ( attributeDivisors[ attribute ] !== meshPerAttribute ) {
  17875. extension.vertexAttribDivisorANGLE( attribute, meshPerAttribute );
  17876. attributeDivisors[ attribute ] = meshPerAttribute;
  17877. }
  17878. };
  17879. this.disableUnusedAttributes = function () {
  17880. for ( var i = 0, l = enabledAttributes.length; i < l; i ++ ) {
  17881. if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
  17882. gl.disableVertexAttribArray( i );
  17883. enabledAttributes[ i ] = 0;
  17884. }
  17885. }
  17886. };
  17887. this.enable = function ( id ) {
  17888. if ( capabilities[ id ] !== true ) {
  17889. gl.enable( id );
  17890. capabilities[ id ] = true;
  17891. }
  17892. };
  17893. this.disable = function ( id ) {
  17894. if ( capabilities[ id ] !== false ) {
  17895. gl.disable( id );
  17896. capabilities[ id ] = false;
  17897. }
  17898. };
  17899. this.getCompressedTextureFormats = function () {
  17900. if ( compressedTextureFormats === null ) {
  17901. compressedTextureFormats = [];
  17902. if ( extensions.get( 'WEBGL_compressed_texture_pvrtc' ) ||
  17903. extensions.get( 'WEBGL_compressed_texture_s3tc' ) ) {
  17904. var formats = gl.getParameter( gl.COMPRESSED_TEXTURE_FORMATS );
  17905. for ( var i = 0; i < formats.length; i ++ ) {
  17906. compressedTextureFormats.push( formats[ i ] );
  17907. }
  17908. }
  17909. }
  17910. return compressedTextureFormats;
  17911. };
  17912. this.setBlending = function ( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha ) {
  17913. if ( blending !== currentBlending ) {
  17914. if ( blending === THREE.NoBlending ) {
  17915. this.disable( gl.BLEND );
  17916. } else if ( blending === THREE.AdditiveBlending ) {
  17917. this.enable( gl.BLEND );
  17918. gl.blendEquation( gl.FUNC_ADD );
  17919. gl.blendFunc( gl.SRC_ALPHA, gl.ONE );
  17920. } else if ( blending === THREE.SubtractiveBlending ) {
  17921. // TODO: Find blendFuncSeparate() combination
  17922. this.enable( gl.BLEND );
  17923. gl.blendEquation( gl.FUNC_ADD );
  17924. gl.blendFunc( gl.ZERO, gl.ONE_MINUS_SRC_COLOR );
  17925. } else if ( blending === THREE.MultiplyBlending ) {
  17926. // TODO: Find blendFuncSeparate() combination
  17927. this.enable( gl.BLEND );
  17928. gl.blendEquation( gl.FUNC_ADD );
  17929. gl.blendFunc( gl.ZERO, gl.SRC_COLOR );
  17930. } else if ( blending === THREE.CustomBlending ) {
  17931. this.enable( gl.BLEND );
  17932. } else {
  17933. this.enable( gl.BLEND );
  17934. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  17935. gl.blendFuncSeparate( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
  17936. }
  17937. currentBlending = blending;
  17938. }
  17939. if ( blending === THREE.CustomBlending ) {
  17940. blendEquationAlpha = blendEquationAlpha || blendEquation;
  17941. blendSrcAlpha = blendSrcAlpha || blendSrc;
  17942. blendDstAlpha = blendDstAlpha || blendDst;
  17943. if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
  17944. gl.blendEquationSeparate( paramThreeToGL( blendEquation ), paramThreeToGL( blendEquationAlpha ) );
  17945. currentBlendEquation = blendEquation;
  17946. currentBlendEquationAlpha = blendEquationAlpha;
  17947. }
  17948. if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
  17949. gl.blendFuncSeparate( paramThreeToGL( blendSrc ), paramThreeToGL( blendDst ), paramThreeToGL( blendSrcAlpha ), paramThreeToGL( blendDstAlpha ) );
  17950. currentBlendSrc = blendSrc;
  17951. currentBlendDst = blendDst;
  17952. currentBlendSrcAlpha = blendSrcAlpha;
  17953. currentBlendDstAlpha = blendDstAlpha;
  17954. }
  17955. } else {
  17956. currentBlendEquation = null;
  17957. currentBlendSrc = null;
  17958. currentBlendDst = null;
  17959. currentBlendEquationAlpha = null;
  17960. currentBlendSrcAlpha = null;
  17961. currentBlendDstAlpha = null;
  17962. }
  17963. };
  17964. this.setDepthFunc = function ( depthFunc ) {
  17965. if ( currentDepthFunc !== depthFunc ) {
  17966. if ( depthFunc ) {
  17967. switch ( depthFunc ) {
  17968. case THREE.NeverDepth:
  17969. gl.depthFunc( gl.NEVER );
  17970. break;
  17971. case THREE.AlwaysDepth:
  17972. gl.depthFunc( gl.ALWAYS );
  17973. break;
  17974. case THREE.LessDepth:
  17975. gl.depthFunc( gl.LESS );
  17976. break;
  17977. case THREE.LessEqualDepth:
  17978. gl.depthFunc( gl.LEQUAL );
  17979. break;
  17980. case THREE.EqualDepth:
  17981. gl.depthFunc( gl.EQUAL );
  17982. break;
  17983. case THREE.GreaterEqualDepth:
  17984. gl.depthFunc( gl.GEQUAL );
  17985. break;
  17986. case THREE.GreaterDepth:
  17987. gl.depthFunc( gl.GREATER );
  17988. break;
  17989. case THREE.NotEqualDepth:
  17990. gl.depthFunc( gl.NOTEQUAL );
  17991. break;
  17992. default:
  17993. gl.depthFunc( gl.LEQUAL );
  17994. }
  17995. } else {
  17996. gl.depthFunc( gl.LEQUAL );
  17997. }
  17998. currentDepthFunc = depthFunc;
  17999. }
  18000. };
  18001. this.setDepthTest = function ( depthTest ) {
  18002. if ( depthTest ) {
  18003. this.enable( gl.DEPTH_TEST );
  18004. } else {
  18005. this.disable( gl.DEPTH_TEST );
  18006. }
  18007. };
  18008. this.setDepthWrite = function ( depthWrite ) {
  18009. if ( currentDepthWrite !== depthWrite ) {
  18010. gl.depthMask( depthWrite );
  18011. currentDepthWrite = depthWrite;
  18012. }
  18013. };
  18014. this.setColorWrite = function ( colorWrite ) {
  18015. if ( currentColorWrite !== colorWrite ) {
  18016. gl.colorMask( colorWrite, colorWrite, colorWrite, colorWrite );
  18017. currentColorWrite = colorWrite;
  18018. }
  18019. };
  18020. this.setFlipSided = function ( flipSided ) {
  18021. if ( currentFlipSided !== flipSided ) {
  18022. if ( flipSided ) {
  18023. gl.frontFace( gl.CW );
  18024. } else {
  18025. gl.frontFace( gl.CCW );
  18026. }
  18027. currentFlipSided = flipSided;
  18028. }
  18029. };
  18030. this.setLineWidth = function ( width ) {
  18031. if ( width !== currentLineWidth ) {
  18032. gl.lineWidth( width );
  18033. currentLineWidth = width;
  18034. }
  18035. };
  18036. this.setPolygonOffset = function ( polygonOffset, factor, units ) {
  18037. if ( polygonOffset ) {
  18038. this.enable( gl.POLYGON_OFFSET_FILL );
  18039. } else {
  18040. this.disable( gl.POLYGON_OFFSET_FILL );
  18041. }
  18042. if ( polygonOffset && ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) ) {
  18043. gl.polygonOffset( factor, units );
  18044. currentPolygonOffsetFactor = factor;
  18045. currentPolygonOffsetUnits = units;
  18046. }
  18047. };
  18048. this.setScissorTest = function ( scissorTest ) {
  18049. if ( scissorTest ) {
  18050. this.enable( gl.SCISSOR_TEST );
  18051. } else {
  18052. this.disable( gl.SCISSOR_TEST );
  18053. }
  18054. };
  18055. // texture
  18056. this.activeTexture = function ( webglSlot ) {
  18057. if ( webglSlot === undefined ) webglSlot = gl.TEXTURE0 + maxTextures - 1;
  18058. if ( currentTextureSlot !== webglSlot ) {
  18059. gl.activeTexture( webglSlot );
  18060. currentTextureSlot = webglSlot;
  18061. }
  18062. }
  18063. this.bindTexture = function ( webglType, webglTexture ) {
  18064. if ( currentTextureSlot === undefined ) {
  18065. _this.activeTexture();
  18066. }
  18067. var boundTexture = currentBoundTextures[ currentTextureSlot ];
  18068. if ( boundTexture === undefined ) {
  18069. boundTexture = { type: undefined, texture: undefined };
  18070. currentBoundTextures[ currentTextureSlot ] = boundTexture;
  18071. }
  18072. if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
  18073. gl.bindTexture( webglType, webglTexture );
  18074. boundTexture.type = webglType;
  18075. boundTexture.texture = webglTexture;
  18076. }
  18077. };
  18078. this.compressedTexImage2D = function () {
  18079. try {
  18080. gl.compressedTexImage2D.apply( gl, arguments );
  18081. } catch ( error ) {
  18082. console.error( error );
  18083. }
  18084. };
  18085. this.texImage2D = function () {
  18086. try {
  18087. gl.texImage2D.apply( gl, arguments );
  18088. } catch ( error ) {
  18089. console.error( error );
  18090. }
  18091. };
  18092. //
  18093. this.reset = function () {
  18094. for ( var i = 0; i < enabledAttributes.length; i ++ ) {
  18095. if ( enabledAttributes[ i ] === 1 ) {
  18096. gl.disableVertexAttribArray( i );
  18097. enabledAttributes[ i ] = 0;
  18098. }
  18099. }
  18100. capabilities = {};
  18101. compressedTextureFormats = null;
  18102. currentBlending = null;
  18103. currentDepthWrite = null;
  18104. currentColorWrite = null;
  18105. currentFlipSided = null;
  18106. };
  18107. };
  18108. // File:src/renderers/webgl/plugins/LensFlarePlugin.js
  18109. /**
  18110. * @author mikael emtinger / http://gomo.se/
  18111. * @author alteredq / http://alteredqualia.com/
  18112. */
  18113. THREE.LensFlarePlugin = function ( renderer, flares ) {
  18114. var gl = renderer.context;
  18115. var state = renderer.state;
  18116. var vertexBuffer, elementBuffer;
  18117. var program, attributes, uniforms;
  18118. var hasVertexTexture;
  18119. var tempTexture, occlusionTexture;
  18120. function init() {
  18121. var vertices = new Float32Array( [
  18122. - 1, - 1, 0, 0,
  18123. 1, - 1, 1, 0,
  18124. 1, 1, 1, 1,
  18125. - 1, 1, 0, 1
  18126. ] );
  18127. var faces = new Uint16Array( [
  18128. 0, 1, 2,
  18129. 0, 2, 3
  18130. ] );
  18131. // buffers
  18132. vertexBuffer = gl.createBuffer();
  18133. elementBuffer = gl.createBuffer();
  18134. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  18135. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  18136. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  18137. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  18138. // textures
  18139. tempTexture = gl.createTexture();
  18140. occlusionTexture = gl.createTexture();
  18141. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  18142. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGB, 16, 16, 0, gl.RGB, gl.UNSIGNED_BYTE, null );
  18143. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  18144. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  18145. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  18146. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  18147. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  18148. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGBA, 16, 16, 0, gl.RGBA, gl.UNSIGNED_BYTE, null );
  18149. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  18150. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  18151. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  18152. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  18153. hasVertexTexture = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS ) > 0;
  18154. var shader;
  18155. if ( hasVertexTexture ) {
  18156. shader = {
  18157. vertexShader: [
  18158. "uniform lowp int renderType;",
  18159. "uniform vec3 screenPosition;",
  18160. "uniform vec2 scale;",
  18161. "uniform float rotation;",
  18162. "uniform sampler2D occlusionMap;",
  18163. "attribute vec2 position;",
  18164. "attribute vec2 uv;",
  18165. "varying vec2 vUV;",
  18166. "varying float vVisibility;",
  18167. "void main() {",
  18168. "vUV = uv;",
  18169. "vec2 pos = position;",
  18170. "if ( renderType == 2 ) {",
  18171. "vec4 visibility = texture2D( occlusionMap, vec2( 0.1, 0.1 ) );",
  18172. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.1 ) );",
  18173. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.1 ) );",
  18174. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) );",
  18175. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.9 ) );",
  18176. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) );",
  18177. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.9 ) );",
  18178. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) );",
  18179. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.5 ) );",
  18180. "vVisibility = visibility.r / 9.0;",
  18181. "vVisibility *= 1.0 - visibility.g / 9.0;",
  18182. "vVisibility *= visibility.b / 9.0;",
  18183. "vVisibility *= 1.0 - visibility.a / 9.0;",
  18184. "pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
  18185. "pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
  18186. "}",
  18187. "gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
  18188. "}"
  18189. ].join( "\n" ),
  18190. fragmentShader: [
  18191. "uniform lowp int renderType;",
  18192. "uniform sampler2D map;",
  18193. "uniform float opacity;",
  18194. "uniform vec3 color;",
  18195. "varying vec2 vUV;",
  18196. "varying float vVisibility;",
  18197. "void main() {",
  18198. // pink square
  18199. "if ( renderType == 0 ) {",
  18200. "gl_FragColor = vec4( 1.0, 0.0, 1.0, 0.0 );",
  18201. // restore
  18202. "} else if ( renderType == 1 ) {",
  18203. "gl_FragColor = texture2D( map, vUV );",
  18204. // flare
  18205. "} else {",
  18206. "vec4 texture = texture2D( map, vUV );",
  18207. "texture.a *= opacity * vVisibility;",
  18208. "gl_FragColor = texture;",
  18209. "gl_FragColor.rgb *= color;",
  18210. "}",
  18211. "}"
  18212. ].join( "\n" )
  18213. };
  18214. } else {
  18215. shader = {
  18216. vertexShader: [
  18217. "uniform lowp int renderType;",
  18218. "uniform vec3 screenPosition;",
  18219. "uniform vec2 scale;",
  18220. "uniform float rotation;",
  18221. "attribute vec2 position;",
  18222. "attribute vec2 uv;",
  18223. "varying vec2 vUV;",
  18224. "void main() {",
  18225. "vUV = uv;",
  18226. "vec2 pos = position;",
  18227. "if ( renderType == 2 ) {",
  18228. "pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
  18229. "pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
  18230. "}",
  18231. "gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
  18232. "}"
  18233. ].join( "\n" ),
  18234. fragmentShader: [
  18235. "precision mediump float;",
  18236. "uniform lowp int renderType;",
  18237. "uniform sampler2D map;",
  18238. "uniform sampler2D occlusionMap;",
  18239. "uniform float opacity;",
  18240. "uniform vec3 color;",
  18241. "varying vec2 vUV;",
  18242. "void main() {",
  18243. // pink square
  18244. "if ( renderType == 0 ) {",
  18245. "gl_FragColor = vec4( texture2D( map, vUV ).rgb, 0.0 );",
  18246. // restore
  18247. "} else if ( renderType == 1 ) {",
  18248. "gl_FragColor = texture2D( map, vUV );",
  18249. // flare
  18250. "} else {",
  18251. "float visibility = texture2D( occlusionMap, vec2( 0.5, 0.1 ) ).a;",
  18252. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) ).a;",
  18253. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) ).a;",
  18254. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) ).a;",
  18255. "visibility = ( 1.0 - visibility / 4.0 );",
  18256. "vec4 texture = texture2D( map, vUV );",
  18257. "texture.a *= opacity * visibility;",
  18258. "gl_FragColor = texture;",
  18259. "gl_FragColor.rgb *= color;",
  18260. "}",
  18261. "}"
  18262. ].join( "\n" )
  18263. };
  18264. }
  18265. program = createProgram( shader );
  18266. attributes = {
  18267. vertex: gl.getAttribLocation ( program, "position" ),
  18268. uv: gl.getAttribLocation ( program, "uv" )
  18269. };
  18270. uniforms = {
  18271. renderType: gl.getUniformLocation( program, "renderType" ),
  18272. map: gl.getUniformLocation( program, "map" ),
  18273. occlusionMap: gl.getUniformLocation( program, "occlusionMap" ),
  18274. opacity: gl.getUniformLocation( program, "opacity" ),
  18275. color: gl.getUniformLocation( program, "color" ),
  18276. scale: gl.getUniformLocation( program, "scale" ),
  18277. rotation: gl.getUniformLocation( program, "rotation" ),
  18278. screenPosition: gl.getUniformLocation( program, "screenPosition" )
  18279. };
  18280. }
  18281. /*
  18282. * Render lens flares
  18283. * Method: renders 16x16 0xff00ff-colored points scattered over the light source area,
  18284. * reads these back and calculates occlusion.
  18285. */
  18286. this.render = function ( scene, camera, viewportWidth, viewportHeight ) {
  18287. if ( flares.length === 0 ) return;
  18288. var tempPosition = new THREE.Vector3();
  18289. var invAspect = viewportHeight / viewportWidth,
  18290. halfViewportWidth = viewportWidth * 0.5,
  18291. halfViewportHeight = viewportHeight * 0.5;
  18292. var size = 16 / viewportHeight,
  18293. scale = new THREE.Vector2( size * invAspect, size );
  18294. var screenPosition = new THREE.Vector3( 1, 1, 0 ),
  18295. screenPositionPixels = new THREE.Vector2( 1, 1 );
  18296. if ( program === undefined ) {
  18297. init();
  18298. }
  18299. gl.useProgram( program );
  18300. state.initAttributes();
  18301. state.enableAttribute( attributes.vertex );
  18302. state.enableAttribute( attributes.uv );
  18303. state.disableUnusedAttributes();
  18304. // loop through all lens flares to update their occlusion and positions
  18305. // setup gl and common used attribs/uniforms
  18306. gl.uniform1i( uniforms.occlusionMap, 0 );
  18307. gl.uniform1i( uniforms.map, 1 );
  18308. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  18309. gl.vertexAttribPointer( attributes.vertex, 2, gl.FLOAT, false, 2 * 8, 0 );
  18310. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  18311. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  18312. state.disable( gl.CULL_FACE );
  18313. gl.depthMask( false );
  18314. for ( var i = 0, l = flares.length; i < l; i ++ ) {
  18315. size = 16 / viewportHeight;
  18316. scale.set( size * invAspect, size );
  18317. // calc object screen position
  18318. var flare = flares[ i ];
  18319. tempPosition.set( flare.matrixWorld.elements[ 12 ], flare.matrixWorld.elements[ 13 ], flare.matrixWorld.elements[ 14 ] );
  18320. tempPosition.applyMatrix4( camera.matrixWorldInverse );
  18321. tempPosition.applyProjection( camera.projectionMatrix );
  18322. // setup arrays for gl programs
  18323. screenPosition.copy( tempPosition );
  18324. screenPositionPixels.x = screenPosition.x * halfViewportWidth + halfViewportWidth;
  18325. screenPositionPixels.y = screenPosition.y * halfViewportHeight + halfViewportHeight;
  18326. // screen cull
  18327. if ( hasVertexTexture || (
  18328. screenPositionPixels.x > 0 &&
  18329. screenPositionPixels.x < viewportWidth &&
  18330. screenPositionPixels.y > 0 &&
  18331. screenPositionPixels.y < viewportHeight ) ) {
  18332. // save current RGB to temp texture
  18333. state.activeTexture( gl.TEXTURE0 );
  18334. state.bindTexture( gl.TEXTURE_2D, null );
  18335. state.activeTexture( gl.TEXTURE1 );
  18336. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  18337. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGB, screenPositionPixels.x - 8, screenPositionPixels.y - 8, 16, 16, 0 );
  18338. // render pink quad
  18339. gl.uniform1i( uniforms.renderType, 0 );
  18340. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  18341. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  18342. state.disable( gl.BLEND );
  18343. state.enable( gl.DEPTH_TEST );
  18344. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  18345. // copy result to occlusionMap
  18346. state.activeTexture( gl.TEXTURE0 );
  18347. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  18348. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGBA, screenPositionPixels.x - 8, screenPositionPixels.y - 8, 16, 16, 0 );
  18349. // restore graphics
  18350. gl.uniform1i( uniforms.renderType, 1 );
  18351. state.disable( gl.DEPTH_TEST );
  18352. state.activeTexture( gl.TEXTURE1 );
  18353. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  18354. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  18355. // update object positions
  18356. flare.positionScreen.copy( screenPosition );
  18357. if ( flare.customUpdateCallback ) {
  18358. flare.customUpdateCallback( flare );
  18359. } else {
  18360. flare.updateLensFlares();
  18361. }
  18362. // render flares
  18363. gl.uniform1i( uniforms.renderType, 2 );
  18364. state.enable( gl.BLEND );
  18365. for ( var j = 0, jl = flare.lensFlares.length; j < jl; j ++ ) {
  18366. var sprite = flare.lensFlares[ j ];
  18367. if ( sprite.opacity > 0.001 && sprite.scale > 0.001 ) {
  18368. screenPosition.x = sprite.x;
  18369. screenPosition.y = sprite.y;
  18370. screenPosition.z = sprite.z;
  18371. size = sprite.size * sprite.scale / viewportHeight;
  18372. scale.x = size * invAspect;
  18373. scale.y = size;
  18374. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  18375. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  18376. gl.uniform1f( uniforms.rotation, sprite.rotation );
  18377. gl.uniform1f( uniforms.opacity, sprite.opacity );
  18378. gl.uniform3f( uniforms.color, sprite.color.r, sprite.color.g, sprite.color.b );
  18379. state.setBlending( sprite.blending, sprite.blendEquation, sprite.blendSrc, sprite.blendDst );
  18380. renderer.setTexture( sprite.texture, 1 );
  18381. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  18382. }
  18383. }
  18384. }
  18385. }
  18386. // restore gl
  18387. state.enable( gl.CULL_FACE );
  18388. state.enable( gl.DEPTH_TEST );
  18389. gl.depthMask( true );
  18390. renderer.resetGLState();
  18391. };
  18392. function createProgram ( shader ) {
  18393. var program = gl.createProgram();
  18394. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  18395. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  18396. var prefix = "precision " + renderer.getPrecision() + " float;\n";
  18397. gl.shaderSource( fragmentShader, prefix + shader.fragmentShader );
  18398. gl.shaderSource( vertexShader, prefix + shader.vertexShader );
  18399. gl.compileShader( fragmentShader );
  18400. gl.compileShader( vertexShader );
  18401. gl.attachShader( program, fragmentShader );
  18402. gl.attachShader( program, vertexShader );
  18403. gl.linkProgram( program );
  18404. return program;
  18405. }
  18406. };
  18407. // File:src/renderers/webgl/plugins/SpritePlugin.js
  18408. /**
  18409. * @author mikael emtinger / http://gomo.se/
  18410. * @author alteredq / http://alteredqualia.com/
  18411. */
  18412. THREE.SpritePlugin = function ( renderer, sprites ) {
  18413. var gl = renderer.context;
  18414. var state = renderer.state;
  18415. var vertexBuffer, elementBuffer;
  18416. var program, attributes, uniforms;
  18417. var texture;
  18418. // decompose matrixWorld
  18419. var spritePosition = new THREE.Vector3();
  18420. var spriteRotation = new THREE.Quaternion();
  18421. var spriteScale = new THREE.Vector3();
  18422. function init() {
  18423. var vertices = new Float32Array( [
  18424. - 0.5, - 0.5, 0, 0,
  18425. 0.5, - 0.5, 1, 0,
  18426. 0.5, 0.5, 1, 1,
  18427. - 0.5, 0.5, 0, 1
  18428. ] );
  18429. var faces = new Uint16Array( [
  18430. 0, 1, 2,
  18431. 0, 2, 3
  18432. ] );
  18433. vertexBuffer = gl.createBuffer();
  18434. elementBuffer = gl.createBuffer();
  18435. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  18436. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  18437. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  18438. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  18439. program = createProgram();
  18440. attributes = {
  18441. position: gl.getAttribLocation ( program, 'position' ),
  18442. uv: gl.getAttribLocation ( program, 'uv' )
  18443. };
  18444. uniforms = {
  18445. uvOffset: gl.getUniformLocation( program, 'uvOffset' ),
  18446. uvScale: gl.getUniformLocation( program, 'uvScale' ),
  18447. rotation: gl.getUniformLocation( program, 'rotation' ),
  18448. scale: gl.getUniformLocation( program, 'scale' ),
  18449. color: gl.getUniformLocation( program, 'color' ),
  18450. map: gl.getUniformLocation( program, 'map' ),
  18451. opacity: gl.getUniformLocation( program, 'opacity' ),
  18452. modelViewMatrix: gl.getUniformLocation( program, 'modelViewMatrix' ),
  18453. projectionMatrix: gl.getUniformLocation( program, 'projectionMatrix' ),
  18454. fogType: gl.getUniformLocation( program, 'fogType' ),
  18455. fogDensity: gl.getUniformLocation( program, 'fogDensity' ),
  18456. fogNear: gl.getUniformLocation( program, 'fogNear' ),
  18457. fogFar: gl.getUniformLocation( program, 'fogFar' ),
  18458. fogColor: gl.getUniformLocation( program, 'fogColor' ),
  18459. alphaTest: gl.getUniformLocation( program, 'alphaTest' )
  18460. };
  18461. var canvas = document.createElement( 'canvas' );
  18462. canvas.width = 8;
  18463. canvas.height = 8;
  18464. var context = canvas.getContext( '2d' );
  18465. context.fillStyle = 'white';
  18466. context.fillRect( 0, 0, 8, 8 );
  18467. texture = new THREE.Texture( canvas );
  18468. texture.needsUpdate = true;
  18469. }
  18470. this.render = function ( scene, camera ) {
  18471. if ( sprites.length === 0 ) return;
  18472. // setup gl
  18473. if ( program === undefined ) {
  18474. init();
  18475. }
  18476. gl.useProgram( program );
  18477. state.initAttributes();
  18478. state.enableAttribute( attributes.position );
  18479. state.enableAttribute( attributes.uv );
  18480. state.disableUnusedAttributes();
  18481. state.disable( gl.CULL_FACE );
  18482. state.enable( gl.BLEND );
  18483. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  18484. gl.vertexAttribPointer( attributes.position, 2, gl.FLOAT, false, 2 * 8, 0 );
  18485. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  18486. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  18487. gl.uniformMatrix4fv( uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
  18488. state.activeTexture( gl.TEXTURE0 );
  18489. gl.uniform1i( uniforms.map, 0 );
  18490. var oldFogType = 0;
  18491. var sceneFogType = 0;
  18492. var fog = scene.fog;
  18493. if ( fog ) {
  18494. gl.uniform3f( uniforms.fogColor, fog.color.r, fog.color.g, fog.color.b );
  18495. if ( fog instanceof THREE.Fog ) {
  18496. gl.uniform1f( uniforms.fogNear, fog.near );
  18497. gl.uniform1f( uniforms.fogFar, fog.far );
  18498. gl.uniform1i( uniforms.fogType, 1 );
  18499. oldFogType = 1;
  18500. sceneFogType = 1;
  18501. } else if ( fog instanceof THREE.FogExp2 ) {
  18502. gl.uniform1f( uniforms.fogDensity, fog.density );
  18503. gl.uniform1i( uniforms.fogType, 2 );
  18504. oldFogType = 2;
  18505. sceneFogType = 2;
  18506. }
  18507. } else {
  18508. gl.uniform1i( uniforms.fogType, 0 );
  18509. oldFogType = 0;
  18510. sceneFogType = 0;
  18511. }
  18512. // update positions and sort
  18513. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  18514. var sprite = sprites[ i ];
  18515. sprite.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, sprite.matrixWorld );
  18516. sprite.z = - sprite.modelViewMatrix.elements[ 14 ];
  18517. }
  18518. sprites.sort( painterSortStable );
  18519. // render all sprites
  18520. var scale = [];
  18521. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  18522. var sprite = sprites[ i ];
  18523. var material = sprite.material;
  18524. gl.uniform1f( uniforms.alphaTest, material.alphaTest );
  18525. gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, sprite.modelViewMatrix.elements );
  18526. sprite.matrixWorld.decompose( spritePosition, spriteRotation, spriteScale );
  18527. scale[ 0 ] = spriteScale.x;
  18528. scale[ 1 ] = spriteScale.y;
  18529. var fogType = 0;
  18530. if ( scene.fog && material.fog ) {
  18531. fogType = sceneFogType;
  18532. }
  18533. if ( oldFogType !== fogType ) {
  18534. gl.uniform1i( uniforms.fogType, fogType );
  18535. oldFogType = fogType;
  18536. }
  18537. if ( material.map !== null ) {
  18538. gl.uniform2f( uniforms.uvOffset, material.map.offset.x, material.map.offset.y );
  18539. gl.uniform2f( uniforms.uvScale, material.map.repeat.x, material.map.repeat.y );
  18540. } else {
  18541. gl.uniform2f( uniforms.uvOffset, 0, 0 );
  18542. gl.uniform2f( uniforms.uvScale, 1, 1 );
  18543. }
  18544. gl.uniform1f( uniforms.opacity, material.opacity );
  18545. gl.uniform3f( uniforms.color, material.color.r, material.color.g, material.color.b );
  18546. gl.uniform1f( uniforms.rotation, material.rotation );
  18547. gl.uniform2fv( uniforms.scale, scale );
  18548. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst );
  18549. state.setDepthTest( material.depthTest );
  18550. state.setDepthWrite( material.depthWrite );
  18551. if ( material.map && material.map.image && material.map.image.width ) {
  18552. renderer.setTexture( material.map, 0 );
  18553. } else {
  18554. renderer.setTexture( texture, 0 );
  18555. }
  18556. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  18557. }
  18558. // restore gl
  18559. state.enable( gl.CULL_FACE );
  18560. renderer.resetGLState();
  18561. };
  18562. function createProgram () {
  18563. var program = gl.createProgram();
  18564. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  18565. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  18566. gl.shaderSource( vertexShader, [
  18567. 'precision ' + renderer.getPrecision() + ' float;',
  18568. 'uniform mat4 modelViewMatrix;',
  18569. 'uniform mat4 projectionMatrix;',
  18570. 'uniform float rotation;',
  18571. 'uniform vec2 scale;',
  18572. 'uniform vec2 uvOffset;',
  18573. 'uniform vec2 uvScale;',
  18574. 'attribute vec2 position;',
  18575. 'attribute vec2 uv;',
  18576. 'varying vec2 vUV;',
  18577. 'void main() {',
  18578. 'vUV = uvOffset + uv * uvScale;',
  18579. 'vec2 alignedPosition = position * scale;',
  18580. 'vec2 rotatedPosition;',
  18581. 'rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;',
  18582. 'rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;',
  18583. 'vec4 finalPosition;',
  18584. 'finalPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );',
  18585. 'finalPosition.xy += rotatedPosition;',
  18586. 'finalPosition = projectionMatrix * finalPosition;',
  18587. 'gl_Position = finalPosition;',
  18588. '}'
  18589. ].join( '\n' ) );
  18590. gl.shaderSource( fragmentShader, [
  18591. 'precision ' + renderer.getPrecision() + ' float;',
  18592. 'uniform vec3 color;',
  18593. 'uniform sampler2D map;',
  18594. 'uniform float opacity;',
  18595. 'uniform int fogType;',
  18596. 'uniform vec3 fogColor;',
  18597. 'uniform float fogDensity;',
  18598. 'uniform float fogNear;',
  18599. 'uniform float fogFar;',
  18600. 'uniform float alphaTest;',
  18601. 'varying vec2 vUV;',
  18602. 'void main() {',
  18603. 'vec4 texture = texture2D( map, vUV );',
  18604. 'if ( texture.a < alphaTest ) discard;',
  18605. 'gl_FragColor = vec4( color * texture.xyz, texture.a * opacity );',
  18606. 'if ( fogType > 0 ) {',
  18607. 'float depth = gl_FragCoord.z / gl_FragCoord.w;',
  18608. 'float fogFactor = 0.0;',
  18609. 'if ( fogType == 1 ) {',
  18610. 'fogFactor = smoothstep( fogNear, fogFar, depth );',
  18611. '} else {',
  18612. 'const float LOG2 = 1.442695;',
  18613. 'fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );',
  18614. 'fogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );',
  18615. '}',
  18616. 'gl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );',
  18617. '}',
  18618. '}'
  18619. ].join( '\n' ) );
  18620. gl.compileShader( vertexShader );
  18621. gl.compileShader( fragmentShader );
  18622. gl.attachShader( program, vertexShader );
  18623. gl.attachShader( program, fragmentShader );
  18624. gl.linkProgram( program );
  18625. return program;
  18626. }
  18627. function painterSortStable ( a, b ) {
  18628. if ( a.z !== b.z ) {
  18629. return b.z - a.z;
  18630. } else {
  18631. return b.id - a.id;
  18632. }
  18633. }
  18634. };
  18635. // File:src/Three.Legacy.js
  18636. /**
  18637. * @author mrdoob / http://mrdoob.com/
  18638. */
  18639. Object.defineProperties( THREE.Box2.prototype, {
  18640. isIntersectionBox: {
  18641. value: function ( box ) {
  18642. console.warn( 'THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().' );
  18643. return this.intersectsBox( box );
  18644. }
  18645. }
  18646. } );
  18647. Object.defineProperties( THREE.Box3.prototype, {
  18648. isIntersectionBox: {
  18649. value: function ( box ) {
  18650. console.warn( 'THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().' );
  18651. return this.intersectsBox( box );
  18652. }
  18653. },
  18654. isIntersectionSphere: {
  18655. value: function ( sphere ) {
  18656. console.warn( 'THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  18657. return this.intersectsSphere( sphere );
  18658. }
  18659. }
  18660. } );
  18661. Object.defineProperties( THREE.Matrix3.prototype, {
  18662. multiplyVector3: {
  18663. value: function ( vector ) {
  18664. console.warn( 'THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.' );
  18665. return vector.applyMatrix3( this );
  18666. }
  18667. },
  18668. multiplyVector3Array: {
  18669. value: function ( a ) {
  18670. console.warn( 'THREE.Matrix3: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
  18671. return this.applyToVector3Array( a );
  18672. }
  18673. }
  18674. } );
  18675. Object.defineProperties( THREE.Matrix4.prototype, {
  18676. extractPosition: {
  18677. value: function ( m ) {
  18678. console.warn( 'THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().' );
  18679. return this.copyPosition( m );
  18680. }
  18681. },
  18682. setRotationFromQuaternion: {
  18683. value: function ( q ) {
  18684. console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' );
  18685. return this.makeRotationFromQuaternion( q );
  18686. }
  18687. },
  18688. multiplyVector3: {
  18689. value: function ( vector ) {
  18690. console.warn( 'THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) or vector.applyProjection( matrix ) instead.' );
  18691. return vector.applyProjection( this );
  18692. }
  18693. },
  18694. multiplyVector4: {
  18695. value: function ( vector ) {
  18696. console.warn( 'THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  18697. return vector.applyMatrix4( this );
  18698. }
  18699. },
  18700. multiplyVector3Array: {
  18701. value: function ( a ) {
  18702. console.warn( 'THREE.Matrix4: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
  18703. return this.applyToVector3Array( a );
  18704. }
  18705. },
  18706. rotateAxis: {
  18707. value: function ( v ) {
  18708. console.warn( 'THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.' );
  18709. v.transformDirection( this );
  18710. }
  18711. },
  18712. crossVector: {
  18713. value: function ( vector ) {
  18714. console.warn( 'THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  18715. return vector.applyMatrix4( this );
  18716. }
  18717. },
  18718. translate: {
  18719. value: function ( v ) {
  18720. console.error( 'THREE.Matrix4: .translate() has been removed.' );
  18721. }
  18722. },
  18723. rotateX: {
  18724. value: function ( angle ) {
  18725. console.error( 'THREE.Matrix4: .rotateX() has been removed.' );
  18726. }
  18727. },
  18728. rotateY: {
  18729. value: function ( angle ) {
  18730. console.error( 'THREE.Matrix4: .rotateY() has been removed.' );
  18731. }
  18732. },
  18733. rotateZ: {
  18734. value: function ( angle ) {
  18735. console.error( 'THREE.Matrix4: .rotateZ() has been removed.' );
  18736. }
  18737. },
  18738. rotateByAxis: {
  18739. value: function ( axis, angle ) {
  18740. console.error( 'THREE.Matrix4: .rotateByAxis() has been removed.' );
  18741. }
  18742. }
  18743. } );
  18744. Object.defineProperties( THREE.Plane.prototype, {
  18745. isIntersectionLine: {
  18746. value: function ( line ) {
  18747. console.warn( 'THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().' );
  18748. return this.intersectsLine( line );
  18749. }
  18750. }
  18751. } );
  18752. Object.defineProperties( THREE.Quaternion.prototype, {
  18753. multiplyVector3: {
  18754. value: function ( vector ) {
  18755. console.warn( 'THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.' );
  18756. return vector.applyQuaternion( this );
  18757. }
  18758. }
  18759. } );
  18760. Object.defineProperties( THREE.Ray.prototype, {
  18761. isIntersectionBox: {
  18762. value: function ( box ) {
  18763. console.warn( 'THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().' );
  18764. return this.intersectsBox( box );
  18765. }
  18766. },
  18767. isIntersectionPlane: {
  18768. value: function ( plane ) {
  18769. console.warn( 'THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().' );
  18770. return this.intersectsPlane( plane );
  18771. }
  18772. },
  18773. isIntersectionSphere: {
  18774. value: function ( sphere ) {
  18775. console.warn( 'THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  18776. return this.intersectsSphere( sphere );
  18777. }
  18778. }
  18779. } );
  18780. Object.defineProperties( THREE.Vector3.prototype, {
  18781. setEulerFromRotationMatrix: {
  18782. value: function () {
  18783. console.error( 'THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.' );
  18784. }
  18785. },
  18786. setEulerFromQuaternion: {
  18787. value: function () {
  18788. console.error( 'THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.' );
  18789. }
  18790. },
  18791. getPositionFromMatrix: {
  18792. value: function ( m ) {
  18793. console.warn( 'THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().' );
  18794. return this.setFromMatrixPosition( m );
  18795. }
  18796. },
  18797. getScaleFromMatrix: {
  18798. value: function ( m ) {
  18799. console.warn( 'THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().' );
  18800. return this.setFromMatrixScale( m );
  18801. }
  18802. },
  18803. getColumnFromMatrix: {
  18804. value: function ( index, matrix ) {
  18805. console.warn( 'THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().' );
  18806. return this.setFromMatrixColumn( index, matrix );
  18807. }
  18808. }
  18809. } );
  18810. //
  18811. Object.defineProperties( THREE.Object3D.prototype, {
  18812. eulerOrder: {
  18813. get: function () {
  18814. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  18815. return this.rotation.order;
  18816. },
  18817. set: function ( value ) {
  18818. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  18819. this.rotation.order = value;
  18820. }
  18821. },
  18822. getChildByName: {
  18823. value: function ( name ) {
  18824. console.warn( 'THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().' );
  18825. return this.getObjectByName( name );
  18826. }
  18827. },
  18828. renderDepth: {
  18829. set: function ( value ) {
  18830. console.warn( 'THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.' );
  18831. }
  18832. },
  18833. translate: {
  18834. value: function ( distance, axis ) {
  18835. console.warn( 'THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.' );
  18836. return this.translateOnAxis( axis, distance );
  18837. }
  18838. },
  18839. useQuaternion: {
  18840. get: function () {
  18841. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  18842. },
  18843. set: function ( value ) {
  18844. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  18845. }
  18846. }
  18847. } );
  18848. //
  18849. Object.defineProperties( THREE, {
  18850. PointCloud: {
  18851. value: function ( geometry, material ) {
  18852. console.warn( 'THREE.PointCloud has been renamed to THREE.Points.' );
  18853. return new THREE.Points( geometry, material );
  18854. }
  18855. },
  18856. ParticleSystem: {
  18857. value: function ( geometry, material ) {
  18858. console.warn( 'THREE.ParticleSystem has been renamed to THREE.Points.' );
  18859. return new THREE.Points( geometry, material );
  18860. }
  18861. }
  18862. } );
  18863. //
  18864. Object.defineProperties( THREE.Light.prototype, {
  18865. onlyShadow: {
  18866. set: function ( value ) {
  18867. console.warn( 'THREE.Light: .onlyShadow has been removed.' );
  18868. }
  18869. },
  18870. shadowCameraFov: {
  18871. set: function ( value ) {
  18872. this.shadow.camera.fov = value;
  18873. }
  18874. },
  18875. shadowCameraLeft: {
  18876. set: function ( value ) {
  18877. this.shadow.camera.left = value;
  18878. }
  18879. },
  18880. shadowCameraRight: {
  18881. set: function ( value ) {
  18882. this.shadow.camera.right = value;
  18883. }
  18884. },
  18885. shadowCameraTop: {
  18886. set: function ( value ) {
  18887. this.shadow.camera.top = value;
  18888. }
  18889. },
  18890. shadowCameraBottom: {
  18891. set: function ( value ) {
  18892. this.shadow.camera.bottom = value;
  18893. }
  18894. },
  18895. shadowCameraNear: {
  18896. set: function ( value ) {
  18897. this.shadow.camera.near = value;
  18898. }
  18899. },
  18900. shadowCameraFar: {
  18901. set: function ( value ) {
  18902. this.shadow.camera.far = value;
  18903. }
  18904. },
  18905. shadowCameraVisible: {
  18906. set: function ( value ) {
  18907. console.warn( 'THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.' );
  18908. }
  18909. },
  18910. shadowBias: {
  18911. set: function ( value ) {
  18912. this.shadow.bias = value;
  18913. }
  18914. },
  18915. shadowDarkness: {
  18916. set: function ( value ) {
  18917. this.shadow.darkness = value;
  18918. }
  18919. },
  18920. shadowMapWidth: {
  18921. set: function ( value ) {
  18922. this.shadow.mapSize.width = value;
  18923. }
  18924. },
  18925. shadowMapHeight: {
  18926. set: function ( value ) {
  18927. this.shadow.mapSize.height = value;
  18928. }
  18929. }
  18930. } );
  18931. //
  18932. Object.defineProperties( THREE.Material.prototype, {
  18933. wrapAround: {
  18934. get: function () {
  18935. console.warn( 'THREE.' + this.type + ': .wrapAround has been removed.' );
  18936. },
  18937. set: function ( value ) {
  18938. console.warn( 'THREE.' + this.type + ': .wrapAround has been removed.' );
  18939. }
  18940. },
  18941. wrapRGB: {
  18942. get: function () {
  18943. console.warn( 'THREE.' + this.type + ': .wrapRGB has been removed.' );
  18944. return new THREE.Color();
  18945. }
  18946. }
  18947. } );
  18948. Object.defineProperties( THREE, {
  18949. PointCloudMaterial: {
  18950. value: function ( parameters ) {
  18951. console.warn( 'THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.' );
  18952. return new THREE.PointsMaterial( parameters );
  18953. }
  18954. },
  18955. ParticleBasicMaterial: {
  18956. value: function ( parameters ) {
  18957. console.warn( 'THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.' );
  18958. return new THREE.PointsMaterial( parameters );
  18959. }
  18960. },
  18961. ParticleSystemMaterial:{
  18962. value: function ( parameters ) {
  18963. console.warn( 'THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.' );
  18964. return new THREE.PointsMaterial( parameters );
  18965. }
  18966. }
  18967. } );
  18968. Object.defineProperties( THREE.MeshPhongMaterial.prototype, {
  18969. metal: {
  18970. get: function () {
  18971. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshPhysicalMaterial instead.' );
  18972. return false;
  18973. },
  18974. set: function ( value ) {
  18975. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshPhysicalMaterial instead' );
  18976. }
  18977. }
  18978. } );
  18979. Object.defineProperties( THREE.ShaderMaterial.prototype, {
  18980. derivatives: {
  18981. get: function () {
  18982. console.warn( 'THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  18983. return this.extensions.derivatives;
  18984. },
  18985. set: function ( value ) {
  18986. console.warn( 'THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  18987. this.extensions.derivatives = value;
  18988. }
  18989. }
  18990. } );
  18991. //
  18992. Object.defineProperties( THREE.WebGLRenderer.prototype, {
  18993. supportsFloatTextures: {
  18994. value: function () {
  18995. console.warn( 'THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).' );
  18996. return this.extensions.get( 'OES_texture_float' );
  18997. }
  18998. },
  18999. supportsHalfFloatTextures: {
  19000. value: function () {
  19001. console.warn( 'THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).' );
  19002. return this.extensions.get( 'OES_texture_half_float' );
  19003. }
  19004. },
  19005. supportsStandardDerivatives: {
  19006. value: function () {
  19007. console.warn( 'THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).' );
  19008. return this.extensions.get( 'OES_standard_derivatives' );
  19009. }
  19010. },
  19011. supportsCompressedTextureS3TC: {
  19012. value: function () {
  19013. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).' );
  19014. return this.extensions.get( 'WEBGL_compressed_texture_s3tc' );
  19015. }
  19016. },
  19017. supportsCompressedTexturePVRTC: {
  19018. value: function () {
  19019. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).' );
  19020. return this.extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  19021. }
  19022. },
  19023. supportsBlendMinMax: {
  19024. value: function () {
  19025. console.warn( 'THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).' );
  19026. return this.extensions.get( 'EXT_blend_minmax' );
  19027. }
  19028. },
  19029. supportsVertexTextures: {
  19030. value: function () {
  19031. return this.capabilities.vertexTextures;
  19032. }
  19033. },
  19034. supportsInstancedArrays: {
  19035. value: function () {
  19036. console.warn( 'THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).' );
  19037. return this.extensions.get( 'ANGLE_instanced_arrays' );
  19038. }
  19039. },
  19040. initMaterial: {
  19041. value: function () {
  19042. console.warn( 'THREE.WebGLRenderer: .initMaterial() has been removed.' );
  19043. }
  19044. },
  19045. addPrePlugin: {
  19046. value: function () {
  19047. console.warn( 'THREE.WebGLRenderer: .addPrePlugin() has been removed.' );
  19048. }
  19049. },
  19050. addPostPlugin: {
  19051. value: function () {
  19052. console.warn( 'THREE.WebGLRenderer: .addPostPlugin() has been removed.' );
  19053. }
  19054. },
  19055. updateShadowMap: {
  19056. value: function () {
  19057. console.warn( 'THREE.WebGLRenderer: .updateShadowMap() has been removed.' );
  19058. }
  19059. },
  19060. shadowMapEnabled: {
  19061. get: function () {
  19062. return this.shadowMap.enabled;
  19063. },
  19064. set: function ( value ) {
  19065. console.warn( 'THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.' );
  19066. this.shadowMap.enabled = value;
  19067. }
  19068. },
  19069. shadowMapType: {
  19070. get: function () {
  19071. return this.shadowMap.type;
  19072. },
  19073. set: function ( value ) {
  19074. console.warn( 'THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.' );
  19075. this.shadowMap.type = value;
  19076. }
  19077. },
  19078. shadowMapCullFace: {
  19079. get: function () {
  19080. return this.shadowMap.cullFace;
  19081. },
  19082. set: function ( value ) {
  19083. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace is now .shadowMap.cullFace.' );
  19084. this.shadowMap.cullFace = value;
  19085. }
  19086. },
  19087. shadowMapDebug: {
  19088. get: function () {
  19089. return this.shadowMap.debug;
  19090. },
  19091. set: function ( value ) {
  19092. console.warn( 'THREE.WebGLRenderer: .shadowMapDebug is now .shadowMap.debug.' );
  19093. this.shadowMap.debug = value;
  19094. }
  19095. }
  19096. } );
  19097. //
  19098. Object.defineProperties( THREE.WebGLRenderTarget.prototype, {
  19099. wrapS: {
  19100. get: function () {
  19101. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  19102. return this.texture.wrapS;
  19103. },
  19104. set: function ( value ) {
  19105. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  19106. this.texture.wrapS = value;
  19107. }
  19108. },
  19109. wrapT: {
  19110. get: function () {
  19111. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  19112. return this.texture.wrapT;
  19113. },
  19114. set: function ( value ) {
  19115. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  19116. this.texture.wrapT = value;
  19117. }
  19118. },
  19119. magFilter: {
  19120. get: function () {
  19121. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  19122. return this.texture.magFilter;
  19123. },
  19124. set: function ( value ) {
  19125. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  19126. this.texture.magFilter = value;
  19127. }
  19128. },
  19129. minFilter: {
  19130. get: function () {
  19131. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  19132. return this.texture.minFilter;
  19133. },
  19134. set: function ( value ) {
  19135. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  19136. this.texture.minFilter = value;
  19137. }
  19138. },
  19139. anisotropy: {
  19140. get: function () {
  19141. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  19142. return this.texture.anisotropy;
  19143. },
  19144. set: function ( value ) {
  19145. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  19146. this.texture.anisotropy = value;
  19147. }
  19148. },
  19149. offset: {
  19150. get: function () {
  19151. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  19152. return this.texture.offset;
  19153. },
  19154. set: function ( value ) {
  19155. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  19156. this.texture.offset = value;
  19157. }
  19158. },
  19159. repeat: {
  19160. get: function () {
  19161. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  19162. return this.texture.repeat;
  19163. },
  19164. set: function ( value ) {
  19165. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  19166. this.texture.repeat = value;
  19167. }
  19168. },
  19169. format: {
  19170. get: function () {
  19171. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  19172. return this.texture.format;
  19173. },
  19174. set: function ( value ) {
  19175. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  19176. this.texture.format = value;
  19177. }
  19178. },
  19179. type: {
  19180. get: function () {
  19181. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  19182. return this.texture.type;
  19183. },
  19184. set: function ( value ) {
  19185. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  19186. this.texture.type = value;
  19187. }
  19188. },
  19189. generateMipmaps: {
  19190. get: function () {
  19191. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  19192. return this.texture.generateMipmaps;
  19193. },
  19194. set: function ( value ) {
  19195. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  19196. this.texture.generateMipmaps = value;
  19197. }
  19198. }
  19199. } );
  19200. //
  19201. THREE.GeometryUtils = {
  19202. merge: function ( geometry1, geometry2, materialIndexOffset ) {
  19203. console.warn( 'THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.' );
  19204. var matrix;
  19205. if ( geometry2 instanceof THREE.Mesh ) {
  19206. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  19207. matrix = geometry2.matrix;
  19208. geometry2 = geometry2.geometry;
  19209. }
  19210. geometry1.merge( geometry2, matrix, materialIndexOffset );
  19211. },
  19212. center: function ( geometry ) {
  19213. console.warn( 'THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.' );
  19214. return geometry.center();
  19215. }
  19216. };
  19217. THREE.ImageUtils = {
  19218. crossOrigin: undefined,
  19219. loadTexture: function ( url, mapping, onLoad, onError ) {
  19220. console.warn( 'THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.' );
  19221. var loader = new THREE.TextureLoader();
  19222. loader.setCrossOrigin( this.crossOrigin );
  19223. var texture = loader.load( url, onLoad, undefined, onError );
  19224. if ( mapping ) texture.mapping = mapping;
  19225. return texture;
  19226. },
  19227. loadTextureCube: function ( urls, mapping, onLoad, onError ) {
  19228. console.warn( 'THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.' );
  19229. var loader = new THREE.CubeTextureLoader();
  19230. loader.setCrossOrigin( this.crossOrigin );
  19231. var texture = loader.load( urls, onLoad, undefined, onError );
  19232. if ( mapping ) texture.mapping = mapping;
  19233. return texture;
  19234. },
  19235. loadCompressedTexture: function () {
  19236. console.error( 'THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.' )
  19237. },
  19238. loadCompressedTextureCube: function () {
  19239. console.error( 'THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.' )
  19240. }
  19241. };
  19242. //
  19243. THREE.Projector = function () {
  19244. console.error( 'THREE.Projector has been moved to /examples/js/renderers/Projector.js.' );
  19245. this.projectVector = function ( vector, camera ) {
  19246. console.warn( 'THREE.Projector: .projectVector() is now vector.project().' );
  19247. vector.project( camera );
  19248. };
  19249. this.unprojectVector = function ( vector, camera ) {
  19250. console.warn( 'THREE.Projector: .unprojectVector() is now vector.unproject().' );
  19251. vector.unproject( camera );
  19252. };
  19253. this.pickingRay = function ( vector, camera ) {
  19254. console.error( 'THREE.Projector: .pickingRay() is now raycaster.setFromCamera().' );
  19255. };
  19256. };
  19257. //
  19258. THREE.CanvasRenderer = function () {
  19259. console.error( 'THREE.CanvasRenderer has been moved to /examples/js/renderers/CanvasRenderer.js' );
  19260. this.domElement = document.createElement( 'canvas' );
  19261. this.clear = function () {};
  19262. this.render = function () {};
  19263. this.setClearColor = function () {};
  19264. this.setSize = function () {};
  19265. };
  19266. //
  19267. THREE.TextGeometry = function () {
  19268. console.error( 'THREE.TextGeometry has been moved to /examples/js/geometries/TextGeometry.js' );
  19269. console.error( 'THREE.FontUtils has been moved to /examples/js/utils/FontUtils.js' );
  19270. };
  19271. // File:src/extras/CurveUtils.js
  19272. /**
  19273. * @author zz85 / http://www.lab4games.net/zz85/blog
  19274. */
  19275. THREE.CurveUtils = {
  19276. tangentQuadraticBezier: function ( t, p0, p1, p2 ) {
  19277. return 2 * ( 1 - t ) * ( p1 - p0 ) + 2 * t * ( p2 - p1 );
  19278. },
  19279. // Puay Bing, thanks for helping with this derivative!
  19280. tangentCubicBezier: function ( t, p0, p1, p2, p3 ) {
  19281. return - 3 * p0 * ( 1 - t ) * ( 1 - t ) +
  19282. 3 * p1 * ( 1 - t ) * ( 1 - t ) - 6 * t * p1 * ( 1 - t ) +
  19283. 6 * t * p2 * ( 1 - t ) - 3 * t * t * p2 +
  19284. 3 * t * t * p3;
  19285. },
  19286. tangentSpline: function ( t, p0, p1, p2, p3 ) {
  19287. // To check if my formulas are correct
  19288. var h00 = 6 * t * t - 6 * t; // derived from 2t^3 − 3t^2 + 1
  19289. var h10 = 3 * t * t - 4 * t + 1; // t^3 − 2t^2 + t
  19290. var h01 = - 6 * t * t + 6 * t; // − 2t3 + 3t2
  19291. var h11 = 3 * t * t - 2 * t; // t3 − t2
  19292. return h00 + h10 + h01 + h11;
  19293. },
  19294. // Catmull-Rom
  19295. interpolate: function( p0, p1, p2, p3, t ) {
  19296. var v0 = ( p2 - p0 ) * 0.5;
  19297. var v1 = ( p3 - p1 ) * 0.5;
  19298. var t2 = t * t;
  19299. var t3 = t * t2;
  19300. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  19301. }
  19302. };
  19303. // File:src/extras/SceneUtils.js
  19304. /**
  19305. * @author alteredq / http://alteredqualia.com/
  19306. */
  19307. THREE.SceneUtils = {
  19308. createMultiMaterialObject: function ( geometry, materials ) {
  19309. var group = new THREE.Group();
  19310. for ( var i = 0, l = materials.length; i < l; i ++ ) {
  19311. group.add( new THREE.Mesh( geometry, materials[ i ] ) );
  19312. }
  19313. return group;
  19314. },
  19315. detach: function ( child, parent, scene ) {
  19316. child.applyMatrix( parent.matrixWorld );
  19317. parent.remove( child );
  19318. scene.add( child );
  19319. },
  19320. attach: function ( child, scene, parent ) {
  19321. var matrixWorldInverse = new THREE.Matrix4();
  19322. matrixWorldInverse.getInverse( parent.matrixWorld );
  19323. child.applyMatrix( matrixWorldInverse );
  19324. scene.remove( child );
  19325. parent.add( child );
  19326. }
  19327. };
  19328. // File:src/extras/ShapeUtils.js
  19329. /**
  19330. * @author zz85 / http://www.lab4games.net/zz85/blog
  19331. */
  19332. THREE.ShapeUtils = {
  19333. // calculate area of the contour polygon
  19334. area: function ( contour ) {
  19335. var n = contour.length;
  19336. var a = 0.0;
  19337. for ( var p = n - 1, q = 0; q < n; p = q ++ ) {
  19338. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  19339. }
  19340. return a * 0.5;
  19341. },
  19342. triangulate: ( function () {
  19343. /**
  19344. * This code is a quick port of code written in C++ which was submitted to
  19345. * flipcode.com by John W. Ratcliff // July 22, 2000
  19346. * See original code and more information here:
  19347. * http://www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml
  19348. *
  19349. * ported to actionscript by Zevan Rosser
  19350. * www.actionsnippet.com
  19351. *
  19352. * ported to javascript by Joshua Koo
  19353. * http://www.lab4games.net/zz85/blog
  19354. *
  19355. */
  19356. function snip( contour, u, v, w, n, verts ) {
  19357. var p;
  19358. var ax, ay, bx, by;
  19359. var cx, cy, px, py;
  19360. ax = contour[ verts[ u ] ].x;
  19361. ay = contour[ verts[ u ] ].y;
  19362. bx = contour[ verts[ v ] ].x;
  19363. by = contour[ verts[ v ] ].y;
  19364. cx = contour[ verts[ w ] ].x;
  19365. cy = contour[ verts[ w ] ].y;
  19366. if ( Number.EPSILON > ( ( ( bx - ax ) * ( cy - ay ) ) - ( ( by - ay ) * ( cx - ax ) ) ) ) return false;
  19367. var aX, aY, bX, bY, cX, cY;
  19368. var apx, apy, bpx, bpy, cpx, cpy;
  19369. var cCROSSap, bCROSScp, aCROSSbp;
  19370. aX = cx - bx; aY = cy - by;
  19371. bX = ax - cx; bY = ay - cy;
  19372. cX = bx - ax; cY = by - ay;
  19373. for ( p = 0; p < n; p ++ ) {
  19374. px = contour[ verts[ p ] ].x;
  19375. py = contour[ verts[ p ] ].y;
  19376. if ( ( ( px === ax ) && ( py === ay ) ) ||
  19377. ( ( px === bx ) && ( py === by ) ) ||
  19378. ( ( px === cx ) && ( py === cy ) ) ) continue;
  19379. apx = px - ax; apy = py - ay;
  19380. bpx = px - bx; bpy = py - by;
  19381. cpx = px - cx; cpy = py - cy;
  19382. // see if p is inside triangle abc
  19383. aCROSSbp = aX * bpy - aY * bpx;
  19384. cCROSSap = cX * apy - cY * apx;
  19385. bCROSScp = bX * cpy - bY * cpx;
  19386. if ( ( aCROSSbp >= - Number.EPSILON ) && ( bCROSScp >= - Number.EPSILON ) && ( cCROSSap >= - Number.EPSILON ) ) return false;
  19387. }
  19388. return true;
  19389. }
  19390. // takes in an contour array and returns
  19391. return function ( contour, indices ) {
  19392. var n = contour.length;
  19393. if ( n < 3 ) return null;
  19394. var result = [],
  19395. verts = [],
  19396. vertIndices = [];
  19397. /* we want a counter-clockwise polygon in verts */
  19398. var u, v, w;
  19399. if ( THREE.ShapeUtils.area( contour ) > 0.0 ) {
  19400. for ( v = 0; v < n; v ++ ) verts[ v ] = v;
  19401. } else {
  19402. for ( v = 0; v < n; v ++ ) verts[ v ] = ( n - 1 ) - v;
  19403. }
  19404. var nv = n;
  19405. /* remove nv - 2 vertices, creating 1 triangle every time */
  19406. var count = 2 * nv; /* error detection */
  19407. for ( v = nv - 1; nv > 2; ) {
  19408. /* if we loop, it is probably a non-simple polygon */
  19409. if ( ( count -- ) <= 0 ) {
  19410. //** Triangulate: ERROR - probable bad polygon!
  19411. //throw ( "Warning, unable to triangulate polygon!" );
  19412. //return null;
  19413. // Sometimes warning is fine, especially polygons are triangulated in reverse.
  19414. console.warn( 'THREE.ShapeUtils: Unable to triangulate polygon! in triangulate()' );
  19415. if ( indices ) return vertIndices;
  19416. return result;
  19417. }
  19418. /* three consecutive vertices in current polygon, <u,v,w> */
  19419. u = v; if ( nv <= u ) u = 0; /* previous */
  19420. v = u + 1; if ( nv <= v ) v = 0; /* new v */
  19421. w = v + 1; if ( nv <= w ) w = 0; /* next */
  19422. if ( snip( contour, u, v, w, nv, verts ) ) {
  19423. var a, b, c, s, t;
  19424. /* true names of the vertices */
  19425. a = verts[ u ];
  19426. b = verts[ v ];
  19427. c = verts[ w ];
  19428. /* output Triangle */
  19429. result.push( [ contour[ a ],
  19430. contour[ b ],
  19431. contour[ c ] ] );
  19432. vertIndices.push( [ verts[ u ], verts[ v ], verts[ w ] ] );
  19433. /* remove v from the remaining polygon */
  19434. for ( s = v, t = v + 1; t < nv; s ++, t ++ ) {
  19435. verts[ s ] = verts[ t ];
  19436. }
  19437. nv --;
  19438. /* reset error detection counter */
  19439. count = 2 * nv;
  19440. }
  19441. }
  19442. if ( indices ) return vertIndices;
  19443. return result;
  19444. }
  19445. } )(),
  19446. triangulateShape: function ( contour, holes ) {
  19447. function point_in_segment_2D_colin( inSegPt1, inSegPt2, inOtherPt ) {
  19448. // inOtherPt needs to be collinear to the inSegment
  19449. if ( inSegPt1.x !== inSegPt2.x ) {
  19450. if ( inSegPt1.x < inSegPt2.x ) {
  19451. return ( ( inSegPt1.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt2.x ) );
  19452. } else {
  19453. return ( ( inSegPt2.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt1.x ) );
  19454. }
  19455. } else {
  19456. if ( inSegPt1.y < inSegPt2.y ) {
  19457. return ( ( inSegPt1.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt2.y ) );
  19458. } else {
  19459. return ( ( inSegPt2.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt1.y ) );
  19460. }
  19461. }
  19462. }
  19463. function intersect_segments_2D( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1, inSeg2Pt2, inExcludeAdjacentSegs ) {
  19464. var seg1dx = inSeg1Pt2.x - inSeg1Pt1.x, seg1dy = inSeg1Pt2.y - inSeg1Pt1.y;
  19465. var seg2dx = inSeg2Pt2.x - inSeg2Pt1.x, seg2dy = inSeg2Pt2.y - inSeg2Pt1.y;
  19466. var seg1seg2dx = inSeg1Pt1.x - inSeg2Pt1.x;
  19467. var seg1seg2dy = inSeg1Pt1.y - inSeg2Pt1.y;
  19468. var limit = seg1dy * seg2dx - seg1dx * seg2dy;
  19469. var perpSeg1 = seg1dy * seg1seg2dx - seg1dx * seg1seg2dy;
  19470. if ( Math.abs( limit ) > Number.EPSILON ) {
  19471. // not parallel
  19472. var perpSeg2;
  19473. if ( limit > 0 ) {
  19474. if ( ( perpSeg1 < 0 ) || ( perpSeg1 > limit ) ) return [];
  19475. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  19476. if ( ( perpSeg2 < 0 ) || ( perpSeg2 > limit ) ) return [];
  19477. } else {
  19478. if ( ( perpSeg1 > 0 ) || ( perpSeg1 < limit ) ) return [];
  19479. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  19480. if ( ( perpSeg2 > 0 ) || ( perpSeg2 < limit ) ) return [];
  19481. }
  19482. // i.e. to reduce rounding errors
  19483. // intersection at endpoint of segment#1?
  19484. if ( perpSeg2 === 0 ) {
  19485. if ( ( inExcludeAdjacentSegs ) &&
  19486. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  19487. return [ inSeg1Pt1 ];
  19488. }
  19489. if ( perpSeg2 === limit ) {
  19490. if ( ( inExcludeAdjacentSegs ) &&
  19491. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  19492. return [ inSeg1Pt2 ];
  19493. }
  19494. // intersection at endpoint of segment#2?
  19495. if ( perpSeg1 === 0 ) return [ inSeg2Pt1 ];
  19496. if ( perpSeg1 === limit ) return [ inSeg2Pt2 ];
  19497. // return real intersection point
  19498. var factorSeg1 = perpSeg2 / limit;
  19499. return [ { x: inSeg1Pt1.x + factorSeg1 * seg1dx,
  19500. y: inSeg1Pt1.y + factorSeg1 * seg1dy } ];
  19501. } else {
  19502. // parallel or collinear
  19503. if ( ( perpSeg1 !== 0 ) ||
  19504. ( seg2dy * seg1seg2dx !== seg2dx * seg1seg2dy ) ) return [];
  19505. // they are collinear or degenerate
  19506. var seg1Pt = ( ( seg1dx === 0 ) && ( seg1dy === 0 ) ); // segment1 is just a point?
  19507. var seg2Pt = ( ( seg2dx === 0 ) && ( seg2dy === 0 ) ); // segment2 is just a point?
  19508. // both segments are points
  19509. if ( seg1Pt && seg2Pt ) {
  19510. if ( ( inSeg1Pt1.x !== inSeg2Pt1.x ) ||
  19511. ( inSeg1Pt1.y !== inSeg2Pt1.y ) ) return []; // they are distinct points
  19512. return [ inSeg1Pt1 ]; // they are the same point
  19513. }
  19514. // segment#1 is a single point
  19515. if ( seg1Pt ) {
  19516. if ( ! point_in_segment_2D_colin( inSeg2Pt1, inSeg2Pt2, inSeg1Pt1 ) ) return []; // but not in segment#2
  19517. return [ inSeg1Pt1 ];
  19518. }
  19519. // segment#2 is a single point
  19520. if ( seg2Pt ) {
  19521. if ( ! point_in_segment_2D_colin( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1 ) ) return []; // but not in segment#1
  19522. return [ inSeg2Pt1 ];
  19523. }
  19524. // they are collinear segments, which might overlap
  19525. var seg1min, seg1max, seg1minVal, seg1maxVal;
  19526. var seg2min, seg2max, seg2minVal, seg2maxVal;
  19527. if ( seg1dx !== 0 ) {
  19528. // the segments are NOT on a vertical line
  19529. if ( inSeg1Pt1.x < inSeg1Pt2.x ) {
  19530. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.x;
  19531. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.x;
  19532. } else {
  19533. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.x;
  19534. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.x;
  19535. }
  19536. if ( inSeg2Pt1.x < inSeg2Pt2.x ) {
  19537. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.x;
  19538. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.x;
  19539. } else {
  19540. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.x;
  19541. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.x;
  19542. }
  19543. } else {
  19544. // the segments are on a vertical line
  19545. if ( inSeg1Pt1.y < inSeg1Pt2.y ) {
  19546. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.y;
  19547. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.y;
  19548. } else {
  19549. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.y;
  19550. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.y;
  19551. }
  19552. if ( inSeg2Pt1.y < inSeg2Pt2.y ) {
  19553. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.y;
  19554. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.y;
  19555. } else {
  19556. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.y;
  19557. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.y;
  19558. }
  19559. }
  19560. if ( seg1minVal <= seg2minVal ) {
  19561. if ( seg1maxVal < seg2minVal ) return [];
  19562. if ( seg1maxVal === seg2minVal ) {
  19563. if ( inExcludeAdjacentSegs ) return [];
  19564. return [ seg2min ];
  19565. }
  19566. if ( seg1maxVal <= seg2maxVal ) return [ seg2min, seg1max ];
  19567. return [ seg2min, seg2max ];
  19568. } else {
  19569. if ( seg1minVal > seg2maxVal ) return [];
  19570. if ( seg1minVal === seg2maxVal ) {
  19571. if ( inExcludeAdjacentSegs ) return [];
  19572. return [ seg1min ];
  19573. }
  19574. if ( seg1maxVal <= seg2maxVal ) return [ seg1min, seg1max ];
  19575. return [ seg1min, seg2max ];
  19576. }
  19577. }
  19578. }
  19579. function isPointInsideAngle( inVertex, inLegFromPt, inLegToPt, inOtherPt ) {
  19580. // The order of legs is important
  19581. // translation of all points, so that Vertex is at (0,0)
  19582. var legFromPtX = inLegFromPt.x - inVertex.x, legFromPtY = inLegFromPt.y - inVertex.y;
  19583. var legToPtX = inLegToPt.x - inVertex.x, legToPtY = inLegToPt.y - inVertex.y;
  19584. var otherPtX = inOtherPt.x - inVertex.x, otherPtY = inOtherPt.y - inVertex.y;
  19585. // main angle >0: < 180 deg.; 0: 180 deg.; <0: > 180 deg.
  19586. var from2toAngle = legFromPtX * legToPtY - legFromPtY * legToPtX;
  19587. var from2otherAngle = legFromPtX * otherPtY - legFromPtY * otherPtX;
  19588. if ( Math.abs( from2toAngle ) > Number.EPSILON ) {
  19589. // angle != 180 deg.
  19590. var other2toAngle = otherPtX * legToPtY - otherPtY * legToPtX;
  19591. // console.log( "from2to: " + from2toAngle + ", from2other: " + from2otherAngle + ", other2to: " + other2toAngle );
  19592. if ( from2toAngle > 0 ) {
  19593. // main angle < 180 deg.
  19594. return ( ( from2otherAngle >= 0 ) && ( other2toAngle >= 0 ) );
  19595. } else {
  19596. // main angle > 180 deg.
  19597. return ( ( from2otherAngle >= 0 ) || ( other2toAngle >= 0 ) );
  19598. }
  19599. } else {
  19600. // angle == 180 deg.
  19601. // console.log( "from2to: 180 deg., from2other: " + from2otherAngle );
  19602. return ( from2otherAngle > 0 );
  19603. }
  19604. }
  19605. function removeHoles( contour, holes ) {
  19606. var shape = contour.concat(); // work on this shape
  19607. var hole;
  19608. function isCutLineInsideAngles( inShapeIdx, inHoleIdx ) {
  19609. // Check if hole point lies within angle around shape point
  19610. var lastShapeIdx = shape.length - 1;
  19611. var prevShapeIdx = inShapeIdx - 1;
  19612. if ( prevShapeIdx < 0 ) prevShapeIdx = lastShapeIdx;
  19613. var nextShapeIdx = inShapeIdx + 1;
  19614. if ( nextShapeIdx > lastShapeIdx ) nextShapeIdx = 0;
  19615. var insideAngle = isPointInsideAngle( shape[ inShapeIdx ], shape[ prevShapeIdx ], shape[ nextShapeIdx ], hole[ inHoleIdx ] );
  19616. if ( ! insideAngle ) {
  19617. // console.log( "Vertex (Shape): " + inShapeIdx + ", Point: " + hole[inHoleIdx].x + "/" + hole[inHoleIdx].y );
  19618. return false;
  19619. }
  19620. // Check if shape point lies within angle around hole point
  19621. var lastHoleIdx = hole.length - 1;
  19622. var prevHoleIdx = inHoleIdx - 1;
  19623. if ( prevHoleIdx < 0 ) prevHoleIdx = lastHoleIdx;
  19624. var nextHoleIdx = inHoleIdx + 1;
  19625. if ( nextHoleIdx > lastHoleIdx ) nextHoleIdx = 0;
  19626. insideAngle = isPointInsideAngle( hole[ inHoleIdx ], hole[ prevHoleIdx ], hole[ nextHoleIdx ], shape[ inShapeIdx ] );
  19627. if ( ! insideAngle ) {
  19628. // console.log( "Vertex (Hole): " + inHoleIdx + ", Point: " + shape[inShapeIdx].x + "/" + shape[inShapeIdx].y );
  19629. return false;
  19630. }
  19631. return true;
  19632. }
  19633. function intersectsShapeEdge( inShapePt, inHolePt ) {
  19634. // checks for intersections with shape edges
  19635. var sIdx, nextIdx, intersection;
  19636. for ( sIdx = 0; sIdx < shape.length; sIdx ++ ) {
  19637. nextIdx = sIdx + 1; nextIdx %= shape.length;
  19638. intersection = intersect_segments_2D( inShapePt, inHolePt, shape[ sIdx ], shape[ nextIdx ], true );
  19639. if ( intersection.length > 0 ) return true;
  19640. }
  19641. return false;
  19642. }
  19643. var indepHoles = [];
  19644. function intersectsHoleEdge( inShapePt, inHolePt ) {
  19645. // checks for intersections with hole edges
  19646. var ihIdx, chkHole,
  19647. hIdx, nextIdx, intersection;
  19648. for ( ihIdx = 0; ihIdx < indepHoles.length; ihIdx ++ ) {
  19649. chkHole = holes[ indepHoles[ ihIdx ]];
  19650. for ( hIdx = 0; hIdx < chkHole.length; hIdx ++ ) {
  19651. nextIdx = hIdx + 1; nextIdx %= chkHole.length;
  19652. intersection = intersect_segments_2D( inShapePt, inHolePt, chkHole[ hIdx ], chkHole[ nextIdx ], true );
  19653. if ( intersection.length > 0 ) return true;
  19654. }
  19655. }
  19656. return false;
  19657. }
  19658. var holeIndex, shapeIndex,
  19659. shapePt, holePt,
  19660. holeIdx, cutKey, failedCuts = [],
  19661. tmpShape1, tmpShape2,
  19662. tmpHole1, tmpHole2;
  19663. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  19664. indepHoles.push( h );
  19665. }
  19666. var minShapeIndex = 0;
  19667. var counter = indepHoles.length * 2;
  19668. while ( indepHoles.length > 0 ) {
  19669. counter --;
  19670. if ( counter < 0 ) {
  19671. console.log( "Infinite Loop! Holes left:" + indepHoles.length + ", Probably Hole outside Shape!" );
  19672. break;
  19673. }
  19674. // search for shape-vertex and hole-vertex,
  19675. // which can be connected without intersections
  19676. for ( shapeIndex = minShapeIndex; shapeIndex < shape.length; shapeIndex ++ ) {
  19677. shapePt = shape[ shapeIndex ];
  19678. holeIndex = - 1;
  19679. // search for hole which can be reached without intersections
  19680. for ( var h = 0; h < indepHoles.length; h ++ ) {
  19681. holeIdx = indepHoles[ h ];
  19682. // prevent multiple checks
  19683. cutKey = shapePt.x + ":" + shapePt.y + ":" + holeIdx;
  19684. if ( failedCuts[ cutKey ] !== undefined ) continue;
  19685. hole = holes[ holeIdx ];
  19686. for ( var h2 = 0; h2 < hole.length; h2 ++ ) {
  19687. holePt = hole[ h2 ];
  19688. if ( ! isCutLineInsideAngles( shapeIndex, h2 ) ) continue;
  19689. if ( intersectsShapeEdge( shapePt, holePt ) ) continue;
  19690. if ( intersectsHoleEdge( shapePt, holePt ) ) continue;
  19691. holeIndex = h2;
  19692. indepHoles.splice( h, 1 );
  19693. tmpShape1 = shape.slice( 0, shapeIndex + 1 );
  19694. tmpShape2 = shape.slice( shapeIndex );
  19695. tmpHole1 = hole.slice( holeIndex );
  19696. tmpHole2 = hole.slice( 0, holeIndex + 1 );
  19697. shape = tmpShape1.concat( tmpHole1 ).concat( tmpHole2 ).concat( tmpShape2 );
  19698. minShapeIndex = shapeIndex;
  19699. // Debug only, to show the selected cuts
  19700. // glob_CutLines.push( [ shapePt, holePt ] );
  19701. break;
  19702. }
  19703. if ( holeIndex >= 0 ) break; // hole-vertex found
  19704. failedCuts[ cutKey ] = true; // remember failure
  19705. }
  19706. if ( holeIndex >= 0 ) break; // hole-vertex found
  19707. }
  19708. }
  19709. return shape; /* shape with no holes */
  19710. }
  19711. var i, il, f, face,
  19712. key, index,
  19713. allPointsMap = {};
  19714. // 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.
  19715. var allpoints = contour.concat();
  19716. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  19717. Array.prototype.push.apply( allpoints, holes[ h ] );
  19718. }
  19719. //console.log( "allpoints",allpoints, allpoints.length );
  19720. // prepare all points map
  19721. for ( i = 0, il = allpoints.length; i < il; i ++ ) {
  19722. key = allpoints[ i ].x + ":" + allpoints[ i ].y;
  19723. if ( allPointsMap[ key ] !== undefined ) {
  19724. console.warn( "THREE.Shape: Duplicate point", key );
  19725. }
  19726. allPointsMap[ key ] = i;
  19727. }
  19728. // remove holes by cutting paths to holes and adding them to the shape
  19729. var shapeWithoutHoles = removeHoles( contour, holes );
  19730. var triangles = THREE.ShapeUtils.triangulate( shapeWithoutHoles, false ); // True returns indices for points of spooled shape
  19731. //console.log( "triangles",triangles, triangles.length );
  19732. // check all face vertices against all points map
  19733. for ( i = 0, il = triangles.length; i < il; i ++ ) {
  19734. face = triangles[ i ];
  19735. for ( f = 0; f < 3; f ++ ) {
  19736. key = face[ f ].x + ":" + face[ f ].y;
  19737. index = allPointsMap[ key ];
  19738. if ( index !== undefined ) {
  19739. face[ f ] = index;
  19740. }
  19741. }
  19742. }
  19743. return triangles.concat();
  19744. },
  19745. isClockWise: function ( pts ) {
  19746. return THREE.ShapeUtils.area( pts ) < 0;
  19747. },
  19748. // Bezier Curves formulas obtained from
  19749. // http://en.wikipedia.org/wiki/B%C3%A9zier_curve
  19750. // Quad Bezier Functions
  19751. b2: ( function () {
  19752. function b2p0( t, p ) {
  19753. var k = 1 - t;
  19754. return k * k * p;
  19755. }
  19756. function b2p1( t, p ) {
  19757. return 2 * ( 1 - t ) * t * p;
  19758. }
  19759. function b2p2( t, p ) {
  19760. return t * t * p;
  19761. }
  19762. return function ( t, p0, p1, p2 ) {
  19763. return b2p0( t, p0 ) + b2p1( t, p1 ) + b2p2( t, p2 );
  19764. };
  19765. } )(),
  19766. // Cubic Bezier Functions
  19767. b3: ( function () {
  19768. function b3p0( t, p ) {
  19769. var k = 1 - t;
  19770. return k * k * k * p;
  19771. }
  19772. function b3p1( t, p ) {
  19773. var k = 1 - t;
  19774. return 3 * k * k * t * p;
  19775. }
  19776. function b3p2( t, p ) {
  19777. var k = 1 - t;
  19778. return 3 * k * t * t * p;
  19779. }
  19780. function b3p3( t, p ) {
  19781. return t * t * t * p;
  19782. }
  19783. return function ( t, p0, p1, p2, p3 ) {
  19784. return b3p0( t, p0 ) + b3p1( t, p1 ) + b3p2( t, p2 ) + b3p3( t, p3 );
  19785. };
  19786. } )()
  19787. };
  19788. // File:src/extras/core/Curve.js
  19789. /**
  19790. * @author zz85 / http://www.lab4games.net/zz85/blog
  19791. * Extensible curve object
  19792. *
  19793. * Some common of Curve methods
  19794. * .getPoint(t), getTangent(t)
  19795. * .getPointAt(u), getTagentAt(u)
  19796. * .getPoints(), .getSpacedPoints()
  19797. * .getLength()
  19798. * .updateArcLengths()
  19799. *
  19800. * This following classes subclasses THREE.Curve:
  19801. *
  19802. * -- 2d classes --
  19803. * THREE.LineCurve
  19804. * THREE.QuadraticBezierCurve
  19805. * THREE.CubicBezierCurve
  19806. * THREE.SplineCurve
  19807. * THREE.ArcCurve
  19808. * THREE.EllipseCurve
  19809. *
  19810. * -- 3d classes --
  19811. * THREE.LineCurve3
  19812. * THREE.QuadraticBezierCurve3
  19813. * THREE.CubicBezierCurve3
  19814. * THREE.SplineCurve3
  19815. * THREE.ClosedSplineCurve3
  19816. *
  19817. * A series of curves can be represented as a THREE.CurvePath
  19818. *
  19819. **/
  19820. /**************************************************************
  19821. * Abstract Curve base class
  19822. **************************************************************/
  19823. THREE.Curve = function () {
  19824. };
  19825. THREE.Curve.prototype = {
  19826. constructor: THREE.Curve,
  19827. // Virtual base class method to overwrite and implement in subclasses
  19828. // - t [0 .. 1]
  19829. getPoint: function ( t ) {
  19830. console.warn( "THREE.Curve: Warning, getPoint() not implemented!" );
  19831. return null;
  19832. },
  19833. // Get point at relative position in curve according to arc length
  19834. // - u [0 .. 1]
  19835. getPointAt: function ( u ) {
  19836. var t = this.getUtoTmapping( u );
  19837. return this.getPoint( t );
  19838. },
  19839. // Get sequence of points using getPoint( t )
  19840. getPoints: function ( divisions ) {
  19841. if ( ! divisions ) divisions = 5;
  19842. var d, pts = [];
  19843. for ( d = 0; d <= divisions; d ++ ) {
  19844. pts.push( this.getPoint( d / divisions ) );
  19845. }
  19846. return pts;
  19847. },
  19848. // Get sequence of points using getPointAt( u )
  19849. getSpacedPoints: function ( divisions ) {
  19850. if ( ! divisions ) divisions = 5;
  19851. var d, pts = [];
  19852. for ( d = 0; d <= divisions; d ++ ) {
  19853. pts.push( this.getPointAt( d / divisions ) );
  19854. }
  19855. return pts;
  19856. },
  19857. // Get total curve arc length
  19858. getLength: function () {
  19859. var lengths = this.getLengths();
  19860. return lengths[ lengths.length - 1 ];
  19861. },
  19862. // Get list of cumulative segment lengths
  19863. getLengths: function ( divisions ) {
  19864. if ( ! divisions ) divisions = ( this.__arcLengthDivisions ) ? ( this.__arcLengthDivisions ) : 200;
  19865. if ( this.cacheArcLengths
  19866. && ( this.cacheArcLengths.length === divisions + 1 )
  19867. && ! this.needsUpdate ) {
  19868. //console.log( "cached", this.cacheArcLengths );
  19869. return this.cacheArcLengths;
  19870. }
  19871. this.needsUpdate = false;
  19872. var cache = [];
  19873. var current, last = this.getPoint( 0 );
  19874. var p, sum = 0;
  19875. cache.push( 0 );
  19876. for ( p = 1; p <= divisions; p ++ ) {
  19877. current = this.getPoint ( p / divisions );
  19878. sum += current.distanceTo( last );
  19879. cache.push( sum );
  19880. last = current;
  19881. }
  19882. this.cacheArcLengths = cache;
  19883. return cache; // { sums: cache, sum:sum }; Sum is in the last element.
  19884. },
  19885. updateArcLengths: function() {
  19886. this.needsUpdate = true;
  19887. this.getLengths();
  19888. },
  19889. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  19890. getUtoTmapping: function ( u, distance ) {
  19891. var arcLengths = this.getLengths();
  19892. var i = 0, il = arcLengths.length;
  19893. var targetArcLength; // The targeted u distance value to get
  19894. if ( distance ) {
  19895. targetArcLength = distance;
  19896. } else {
  19897. targetArcLength = u * arcLengths[ il - 1 ];
  19898. }
  19899. //var time = Date.now();
  19900. // binary search for the index with largest value smaller than target u distance
  19901. var low = 0, high = il - 1, comparison;
  19902. while ( low <= high ) {
  19903. 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
  19904. comparison = arcLengths[ i ] - targetArcLength;
  19905. if ( comparison < 0 ) {
  19906. low = i + 1;
  19907. } else if ( comparison > 0 ) {
  19908. high = i - 1;
  19909. } else {
  19910. high = i;
  19911. break;
  19912. // DONE
  19913. }
  19914. }
  19915. i = high;
  19916. //console.log('b' , i, low, high, Date.now()- time);
  19917. if ( arcLengths[ i ] === targetArcLength ) {
  19918. var t = i / ( il - 1 );
  19919. return t;
  19920. }
  19921. // we could get finer grain at lengths, or use simple interpolation between two points
  19922. var lengthBefore = arcLengths[ i ];
  19923. var lengthAfter = arcLengths[ i + 1 ];
  19924. var segmentLength = lengthAfter - lengthBefore;
  19925. // determine where we are between the 'before' and 'after' points
  19926. var segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  19927. // add that fractional amount to t
  19928. var t = ( i + segmentFraction ) / ( il - 1 );
  19929. return t;
  19930. },
  19931. // Returns a unit vector tangent at t
  19932. // In case any sub curve does not implement its tangent derivation,
  19933. // 2 points a small delta apart will be used to find its gradient
  19934. // which seems to give a reasonable approximation
  19935. getTangent: function( t ) {
  19936. var delta = 0.0001;
  19937. var t1 = t - delta;
  19938. var t2 = t + delta;
  19939. // Capping in case of danger
  19940. if ( t1 < 0 ) t1 = 0;
  19941. if ( t2 > 1 ) t2 = 1;
  19942. var pt1 = this.getPoint( t1 );
  19943. var pt2 = this.getPoint( t2 );
  19944. var vec = pt2.clone().sub( pt1 );
  19945. return vec.normalize();
  19946. },
  19947. getTangentAt: function ( u ) {
  19948. var t = this.getUtoTmapping( u );
  19949. return this.getTangent( t );
  19950. }
  19951. }
  19952. THREE.Curve.Utils = THREE.CurveUtils; // backwards compatibility
  19953. // TODO: Transformation for Curves?
  19954. /**************************************************************
  19955. * 3D Curves
  19956. **************************************************************/
  19957. // A Factory method for creating new curve subclasses
  19958. THREE.Curve.create = function ( constructor, getPointFunc ) {
  19959. constructor.prototype = Object.create( THREE.Curve.prototype );
  19960. constructor.prototype.constructor = constructor;
  19961. constructor.prototype.getPoint = getPointFunc;
  19962. return constructor;
  19963. };
  19964. // File:src/extras/core/CurvePath.js
  19965. /**
  19966. * @author zz85 / http://www.lab4games.net/zz85/blog
  19967. *
  19968. **/
  19969. /**************************************************************
  19970. * Curved Path - a curve path is simply a array of connected
  19971. * curves, but retains the api of a curve
  19972. **************************************************************/
  19973. THREE.CurvePath = function () {
  19974. this.curves = [];
  19975. this.autoClose = false; // Automatically closes the path
  19976. };
  19977. THREE.CurvePath.prototype = Object.create( THREE.Curve.prototype );
  19978. THREE.CurvePath.prototype.constructor = THREE.CurvePath;
  19979. THREE.CurvePath.prototype.add = function ( curve ) {
  19980. this.curves.push( curve );
  19981. };
  19982. /*
  19983. THREE.CurvePath.prototype.checkConnection = function() {
  19984. // TODO
  19985. // If the ending of curve is not connected to the starting
  19986. // or the next curve, then, this is not a real path
  19987. };
  19988. */
  19989. THREE.CurvePath.prototype.closePath = function() {
  19990. // TODO Test
  19991. // and verify for vector3 (needs to implement equals)
  19992. // Add a line curve if start and end of lines are not connected
  19993. var startPoint = this.curves[ 0 ].getPoint( 0 );
  19994. var endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
  19995. if ( ! startPoint.equals( endPoint ) ) {
  19996. this.curves.push( new THREE.LineCurve( endPoint, startPoint ) );
  19997. }
  19998. };
  19999. // To get accurate point with reference to
  20000. // entire path distance at time t,
  20001. // following has to be done:
  20002. // 1. Length of each sub path have to be known
  20003. // 2. Locate and identify type of curve
  20004. // 3. Get t for the curve
  20005. // 4. Return curve.getPointAt(t')
  20006. THREE.CurvePath.prototype.getPoint = function( t ) {
  20007. var d = t * this.getLength();
  20008. var curveLengths = this.getCurveLengths();
  20009. var i = 0;
  20010. // To think about boundaries points.
  20011. while ( i < curveLengths.length ) {
  20012. if ( curveLengths[ i ] >= d ) {
  20013. var diff = curveLengths[ i ] - d;
  20014. var curve = this.curves[ i ];
  20015. var u = 1 - diff / curve.getLength();
  20016. return curve.getPointAt( u );
  20017. }
  20018. i ++;
  20019. }
  20020. return null;
  20021. // loop where sum != 0, sum > d , sum+1 <d
  20022. };
  20023. /*
  20024. THREE.CurvePath.prototype.getTangent = function( t ) {
  20025. };
  20026. */
  20027. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  20028. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  20029. // getPoint() depends on getLength
  20030. THREE.CurvePath.prototype.getLength = function() {
  20031. var lens = this.getCurveLengths();
  20032. return lens[ lens.length - 1 ];
  20033. };
  20034. // Compute lengths and cache them
  20035. // We cannot overwrite getLengths() because UtoT mapping uses it.
  20036. THREE.CurvePath.prototype.getCurveLengths = function() {
  20037. // We use cache values if curves and cache array are same length
  20038. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  20039. return this.cacheLengths;
  20040. }
  20041. // Get length of sub-curve
  20042. // Push sums into cached array
  20043. var lengths = [], sums = 0;
  20044. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  20045. sums += this.curves[ i ].getLength();
  20046. lengths.push( sums );
  20047. }
  20048. this.cacheLengths = lengths;
  20049. return lengths;
  20050. };
  20051. /**************************************************************
  20052. * Create Geometries Helpers
  20053. **************************************************************/
  20054. /// Generate geometry from path points (for Line or Points objects)
  20055. THREE.CurvePath.prototype.createPointsGeometry = function( divisions ) {
  20056. var pts = this.getPoints( divisions, true );
  20057. return this.createGeometry( pts );
  20058. };
  20059. // Generate geometry from equidistant sampling along the path
  20060. THREE.CurvePath.prototype.createSpacedPointsGeometry = function( divisions ) {
  20061. var pts = this.getSpacedPoints( divisions, true );
  20062. return this.createGeometry( pts );
  20063. };
  20064. THREE.CurvePath.prototype.createGeometry = function( points ) {
  20065. var geometry = new THREE.Geometry();
  20066. for ( var i = 0, l = points.length; i < l; i ++ ) {
  20067. var point = points[ i ];
  20068. geometry.vertices.push( new THREE.Vector3( point.x, point.y, point.z || 0 ) );
  20069. }
  20070. return geometry;
  20071. };
  20072. // File:src/extras/core/Path.js
  20073. /**
  20074. * @author zz85 / http://www.lab4games.net/zz85/blog
  20075. * Creates free form 2d path using series of points, lines or curves.
  20076. *
  20077. **/
  20078. THREE.Path = function ( points ) {
  20079. THREE.CurvePath.call( this );
  20080. this.actions = [];
  20081. if ( points ) {
  20082. this.fromPoints( points );
  20083. }
  20084. };
  20085. THREE.Path.prototype = Object.create( THREE.CurvePath.prototype );
  20086. THREE.Path.prototype.constructor = THREE.Path;
  20087. // TODO Clean up PATH API
  20088. // Create path using straight lines to connect all points
  20089. // - vectors: array of Vector2
  20090. THREE.Path.prototype.fromPoints = function ( vectors ) {
  20091. this.moveTo( vectors[ 0 ].x, vectors[ 0 ].y );
  20092. for ( var i = 1, l = vectors.length; i < l; i ++ ) {
  20093. this.lineTo( vectors[ i ].x, vectors[ i ].y );
  20094. }
  20095. };
  20096. // startPath() endPath()?
  20097. THREE.Path.prototype.moveTo = function ( x, y ) {
  20098. this.actions.push( { action: 'moveTo', args: [ x, y ] } );
  20099. };
  20100. THREE.Path.prototype.lineTo = function ( x, y ) {
  20101. var lastargs = this.actions[ this.actions.length - 1 ].args;
  20102. var x0 = lastargs[ lastargs.length - 2 ];
  20103. var y0 = lastargs[ lastargs.length - 1 ];
  20104. var curve = new THREE.LineCurve( new THREE.Vector2( x0, y0 ), new THREE.Vector2( x, y ) );
  20105. this.curves.push( curve );
  20106. this.actions.push( { action: 'lineTo', args: [ x, y ] } );
  20107. };
  20108. THREE.Path.prototype.quadraticCurveTo = function( aCPx, aCPy, aX, aY ) {
  20109. var lastargs = this.actions[ this.actions.length - 1 ].args;
  20110. var x0 = lastargs[ lastargs.length - 2 ];
  20111. var y0 = lastargs[ lastargs.length - 1 ];
  20112. var curve = new THREE.QuadraticBezierCurve(
  20113. new THREE.Vector2( x0, y0 ),
  20114. new THREE.Vector2( aCPx, aCPy ),
  20115. new THREE.Vector2( aX, aY )
  20116. );
  20117. this.curves.push( curve );
  20118. this.actions.push( { action: 'quadraticCurveTo', args: [ aCPx, aCPy, aX, aY ] } );
  20119. };
  20120. THREE.Path.prototype.bezierCurveTo = function( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  20121. var lastargs = this.actions[ this.actions.length - 1 ].args;
  20122. var x0 = lastargs[ lastargs.length - 2 ];
  20123. var y0 = lastargs[ lastargs.length - 1 ];
  20124. var curve = new THREE.CubicBezierCurve(
  20125. new THREE.Vector2( x0, y0 ),
  20126. new THREE.Vector2( aCP1x, aCP1y ),
  20127. new THREE.Vector2( aCP2x, aCP2y ),
  20128. new THREE.Vector2( aX, aY )
  20129. );
  20130. this.curves.push( curve );
  20131. this.actions.push( { action: 'bezierCurveTo', args: [ aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ] } );
  20132. };
  20133. THREE.Path.prototype.splineThru = function( pts /*Array of Vector*/ ) {
  20134. var args = Array.prototype.slice.call( arguments );
  20135. var lastargs = this.actions[ this.actions.length - 1 ].args;
  20136. var x0 = lastargs[ lastargs.length - 2 ];
  20137. var y0 = lastargs[ lastargs.length - 1 ];
  20138. var npts = [ new THREE.Vector2( x0, y0 ) ];
  20139. Array.prototype.push.apply( npts, pts );
  20140. var curve = new THREE.SplineCurve( npts );
  20141. this.curves.push( curve );
  20142. this.actions.push( { action: 'splineThru', args: args } );
  20143. };
  20144. // FUTURE: Change the API or follow canvas API?
  20145. THREE.Path.prototype.arc = function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  20146. var lastargs = this.actions[ this.actions.length - 1 ].args;
  20147. var x0 = lastargs[ lastargs.length - 2 ];
  20148. var y0 = lastargs[ lastargs.length - 1 ];
  20149. this.absarc( aX + x0, aY + y0, aRadius,
  20150. aStartAngle, aEndAngle, aClockwise );
  20151. };
  20152. THREE.Path.prototype.absarc = function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  20153. this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  20154. };
  20155. THREE.Path.prototype.ellipse = function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  20156. var lastargs = this.actions[ this.actions.length - 1 ].args;
  20157. var x0 = lastargs[ lastargs.length - 2 ];
  20158. var y0 = lastargs[ lastargs.length - 1 ];
  20159. this.absellipse( aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  20160. };
  20161. THREE.Path.prototype.absellipse = function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  20162. var args = [
  20163. aX, aY,
  20164. xRadius, yRadius,
  20165. aStartAngle, aEndAngle,
  20166. aClockwise,
  20167. aRotation || 0 // aRotation is optional.
  20168. ];
  20169. var curve = new THREE.EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  20170. this.curves.push( curve );
  20171. var lastPoint = curve.getPoint( 1 );
  20172. args.push( lastPoint.x );
  20173. args.push( lastPoint.y );
  20174. this.actions.push( { action: 'ellipse', args: args } );
  20175. };
  20176. THREE.Path.prototype.getSpacedPoints = function ( divisions, closedPath ) {
  20177. if ( ! divisions ) divisions = 40;
  20178. var points = [];
  20179. for ( var i = 0; i < divisions; i ++ ) {
  20180. points.push( this.getPoint( i / divisions ) );
  20181. //if ( !this.getPoint( i / divisions ) ) throw "DIE";
  20182. }
  20183. // if ( closedPath ) {
  20184. //
  20185. // points.push( points[ 0 ] );
  20186. //
  20187. // }
  20188. return points;
  20189. };
  20190. /* Return an array of vectors based on contour of the path */
  20191. THREE.Path.prototype.getPoints = function( divisions, closedPath ) {
  20192. divisions = divisions || 12;
  20193. var b2 = THREE.ShapeUtils.b2;
  20194. var b3 = THREE.ShapeUtils.b3;
  20195. var points = [];
  20196. var cpx, cpy, cpx2, cpy2, cpx1, cpy1, cpx0, cpy0,
  20197. laste, tx, ty;
  20198. for ( var i = 0, l = this.actions.length; i < l; i ++ ) {
  20199. var item = this.actions[ i ];
  20200. var action = item.action;
  20201. var args = item.args;
  20202. switch ( action ) {
  20203. case 'moveTo':
  20204. points.push( new THREE.Vector2( args[ 0 ], args[ 1 ] ) );
  20205. break;
  20206. case 'lineTo':
  20207. points.push( new THREE.Vector2( args[ 0 ], args[ 1 ] ) );
  20208. break;
  20209. case 'quadraticCurveTo':
  20210. cpx = args[ 2 ];
  20211. cpy = args[ 3 ];
  20212. cpx1 = args[ 0 ];
  20213. cpy1 = args[ 1 ];
  20214. if ( points.length > 0 ) {
  20215. laste = points[ points.length - 1 ];
  20216. cpx0 = laste.x;
  20217. cpy0 = laste.y;
  20218. } else {
  20219. laste = this.actions[ i - 1 ].args;
  20220. cpx0 = laste[ laste.length - 2 ];
  20221. cpy0 = laste[ laste.length - 1 ];
  20222. }
  20223. for ( var j = 1; j <= divisions; j ++ ) {
  20224. var t = j / divisions;
  20225. tx = b2( t, cpx0, cpx1, cpx );
  20226. ty = b2( t, cpy0, cpy1, cpy );
  20227. points.push( new THREE.Vector2( tx, ty ) );
  20228. }
  20229. break;
  20230. case 'bezierCurveTo':
  20231. cpx = args[ 4 ];
  20232. cpy = args[ 5 ];
  20233. cpx1 = args[ 0 ];
  20234. cpy1 = args[ 1 ];
  20235. cpx2 = args[ 2 ];
  20236. cpy2 = args[ 3 ];
  20237. if ( points.length > 0 ) {
  20238. laste = points[ points.length - 1 ];
  20239. cpx0 = laste.x;
  20240. cpy0 = laste.y;
  20241. } else {
  20242. laste = this.actions[ i - 1 ].args;
  20243. cpx0 = laste[ laste.length - 2 ];
  20244. cpy0 = laste[ laste.length - 1 ];
  20245. }
  20246. for ( var j = 1; j <= divisions; j ++ ) {
  20247. var t = j / divisions;
  20248. tx = b3( t, cpx0, cpx1, cpx2, cpx );
  20249. ty = b3( t, cpy0, cpy1, cpy2, cpy );
  20250. points.push( new THREE.Vector2( tx, ty ) );
  20251. }
  20252. break;
  20253. case 'splineThru':
  20254. laste = this.actions[ i - 1 ].args;
  20255. var last = new THREE.Vector2( laste[ laste.length - 2 ], laste[ laste.length - 1 ] );
  20256. var spts = [ last ];
  20257. var n = divisions * args[ 0 ].length;
  20258. spts = spts.concat( args[ 0 ] );
  20259. var spline = new THREE.SplineCurve( spts );
  20260. for ( var j = 1; j <= n; j ++ ) {
  20261. points.push( spline.getPointAt( j / n ) );
  20262. }
  20263. break;
  20264. case 'arc':
  20265. var aX = args[ 0 ], aY = args[ 1 ],
  20266. aRadius = args[ 2 ],
  20267. aStartAngle = args[ 3 ], aEndAngle = args[ 4 ],
  20268. aClockwise = !! args[ 5 ];
  20269. var deltaAngle = aEndAngle - aStartAngle;
  20270. var angle;
  20271. var tdivisions = divisions * 2;
  20272. for ( var j = 1; j <= tdivisions; j ++ ) {
  20273. var t = j / tdivisions;
  20274. if ( ! aClockwise ) {
  20275. t = 1 - t;
  20276. }
  20277. angle = aStartAngle + t * deltaAngle;
  20278. tx = aX + aRadius * Math.cos( angle );
  20279. ty = aY + aRadius * Math.sin( angle );
  20280. //console.log('t', t, 'angle', angle, 'tx', tx, 'ty', ty);
  20281. points.push( new THREE.Vector2( tx, ty ) );
  20282. }
  20283. //console.log(points);
  20284. break;
  20285. case 'ellipse':
  20286. var aX = args[ 0 ], aY = args[ 1 ],
  20287. xRadius = args[ 2 ],
  20288. yRadius = args[ 3 ],
  20289. aStartAngle = args[ 4 ], aEndAngle = args[ 5 ],
  20290. aClockwise = !! args[ 6 ],
  20291. aRotation = args[ 7 ];
  20292. var deltaAngle = aEndAngle - aStartAngle;
  20293. var angle;
  20294. var tdivisions = divisions * 2;
  20295. var cos, sin;
  20296. if ( aRotation !== 0 ) {
  20297. cos = Math.cos( aRotation );
  20298. sin = Math.sin( aRotation );
  20299. }
  20300. for ( var j = 1; j <= tdivisions; j ++ ) {
  20301. var t = j / tdivisions;
  20302. if ( ! aClockwise ) {
  20303. t = 1 - t;
  20304. }
  20305. angle = aStartAngle + t * deltaAngle;
  20306. tx = aX + xRadius * Math.cos( angle );
  20307. ty = aY + yRadius * Math.sin( angle );
  20308. if ( aRotation !== 0 ) {
  20309. var x = tx, y = ty;
  20310. // Rotate the point about the center of the ellipse.
  20311. tx = ( x - aX ) * cos - ( y - aY ) * sin + aX;
  20312. ty = ( x - aX ) * sin + ( y - aY ) * cos + aY;
  20313. }
  20314. //console.log('t', t, 'angle', angle, 'tx', tx, 'ty', ty);
  20315. points.push( new THREE.Vector2( tx, ty ) );
  20316. }
  20317. //console.log(points);
  20318. break;
  20319. } // end switch
  20320. }
  20321. // Normalize to remove the closing point by default.
  20322. var lastPoint = points[ points.length - 1 ];
  20323. if ( Math.abs( lastPoint.x - points[ 0 ].x ) < Number.EPSILON &&
  20324. Math.abs( lastPoint.y - points[ 0 ].y ) < Number.EPSILON )
  20325. points.splice( points.length - 1, 1 );
  20326. if ( closedPath ) {
  20327. points.push( points[ 0 ] );
  20328. }
  20329. return points;
  20330. };
  20331. //
  20332. // Breaks path into shapes
  20333. //
  20334. // Assumptions (if parameter isCCW==true the opposite holds):
  20335. // - solid shapes are defined clockwise (CW)
  20336. // - holes are defined counterclockwise (CCW)
  20337. //
  20338. // If parameter noHoles==true:
  20339. // - all subPaths are regarded as solid shapes
  20340. // - definition order CW/CCW has no relevance
  20341. //
  20342. THREE.Path.prototype.toShapes = function( isCCW, noHoles ) {
  20343. function extractSubpaths( inActions ) {
  20344. var subPaths = [], lastPath = new THREE.Path();
  20345. for ( var i = 0, l = inActions.length; i < l; i ++ ) {
  20346. var item = inActions[ i ];
  20347. var args = item.args;
  20348. var action = item.action;
  20349. if ( action === 'moveTo' ) {
  20350. if ( lastPath.actions.length !== 0 ) {
  20351. subPaths.push( lastPath );
  20352. lastPath = new THREE.Path();
  20353. }
  20354. }
  20355. lastPath[ action ].apply( lastPath, args );
  20356. }
  20357. if ( lastPath.actions.length !== 0 ) {
  20358. subPaths.push( lastPath );
  20359. }
  20360. // console.log(subPaths);
  20361. return subPaths;
  20362. }
  20363. function toShapesNoHoles( inSubpaths ) {
  20364. var shapes = [];
  20365. for ( var i = 0, l = inSubpaths.length; i < l; i ++ ) {
  20366. var tmpPath = inSubpaths[ i ];
  20367. var tmpShape = new THREE.Shape();
  20368. tmpShape.actions = tmpPath.actions;
  20369. tmpShape.curves = tmpPath.curves;
  20370. shapes.push( tmpShape );
  20371. }
  20372. //console.log("shape", shapes);
  20373. return shapes;
  20374. }
  20375. function isPointInsidePolygon( inPt, inPolygon ) {
  20376. var polyLen = inPolygon.length;
  20377. // inPt on polygon contour => immediate success or
  20378. // toggling of inside/outside at every single! intersection point of an edge
  20379. // with the horizontal line through inPt, left of inPt
  20380. // not counting lowerY endpoints of edges and whole edges on that line
  20381. var inside = false;
  20382. for ( var p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  20383. var edgeLowPt = inPolygon[ p ];
  20384. var edgeHighPt = inPolygon[ q ];
  20385. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  20386. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  20387. if ( Math.abs( edgeDy ) > Number.EPSILON ) {
  20388. // not parallel
  20389. if ( edgeDy < 0 ) {
  20390. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  20391. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  20392. }
  20393. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  20394. if ( inPt.y === edgeLowPt.y ) {
  20395. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  20396. // continue; // no intersection or edgeLowPt => doesn't count !!!
  20397. } else {
  20398. var perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y );
  20399. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  20400. if ( perpEdge < 0 ) continue;
  20401. inside = ! inside; // true intersection left of inPt
  20402. }
  20403. } else {
  20404. // parallel or collinear
  20405. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  20406. // edge lies on the same horizontal line as inPt
  20407. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  20408. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  20409. // continue;
  20410. }
  20411. }
  20412. return inside;
  20413. }
  20414. var isClockWise = THREE.ShapeUtils.isClockWise;
  20415. var subPaths = extractSubpaths( this.actions );
  20416. if ( subPaths.length === 0 ) return [];
  20417. if ( noHoles === true ) return toShapesNoHoles( subPaths );
  20418. var solid, tmpPath, tmpShape, shapes = [];
  20419. if ( subPaths.length === 1 ) {
  20420. tmpPath = subPaths[ 0 ];
  20421. tmpShape = new THREE.Shape();
  20422. tmpShape.actions = tmpPath.actions;
  20423. tmpShape.curves = tmpPath.curves;
  20424. shapes.push( tmpShape );
  20425. return shapes;
  20426. }
  20427. var holesFirst = ! isClockWise( subPaths[ 0 ].getPoints() );
  20428. holesFirst = isCCW ? ! holesFirst : holesFirst;
  20429. // console.log("Holes first", holesFirst);
  20430. var betterShapeHoles = [];
  20431. var newShapes = [];
  20432. var newShapeHoles = [];
  20433. var mainIdx = 0;
  20434. var tmpPoints;
  20435. newShapes[ mainIdx ] = undefined;
  20436. newShapeHoles[ mainIdx ] = [];
  20437. for ( var i = 0, l = subPaths.length; i < l; i ++ ) {
  20438. tmpPath = subPaths[ i ];
  20439. tmpPoints = tmpPath.getPoints();
  20440. solid = isClockWise( tmpPoints );
  20441. solid = isCCW ? ! solid : solid;
  20442. if ( solid ) {
  20443. if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) mainIdx ++;
  20444. newShapes[ mainIdx ] = { s: new THREE.Shape(), p: tmpPoints };
  20445. newShapes[ mainIdx ].s.actions = tmpPath.actions;
  20446. newShapes[ mainIdx ].s.curves = tmpPath.curves;
  20447. if ( holesFirst ) mainIdx ++;
  20448. newShapeHoles[ mainIdx ] = [];
  20449. //console.log('cw', i);
  20450. } else {
  20451. newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } );
  20452. //console.log('ccw', i);
  20453. }
  20454. }
  20455. // only Holes? -> probably all Shapes with wrong orientation
  20456. if ( ! newShapes[ 0 ] ) return toShapesNoHoles( subPaths );
  20457. if ( newShapes.length > 1 ) {
  20458. var ambiguous = false;
  20459. var toChange = [];
  20460. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  20461. betterShapeHoles[ sIdx ] = [];
  20462. }
  20463. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  20464. var sho = newShapeHoles[ sIdx ];
  20465. for ( var hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  20466. var ho = sho[ hIdx ];
  20467. var hole_unassigned = true;
  20468. for ( var s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  20469. if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
  20470. if ( sIdx !== s2Idx ) toChange.push( { froms: sIdx, tos: s2Idx, hole: hIdx } );
  20471. if ( hole_unassigned ) {
  20472. hole_unassigned = false;
  20473. betterShapeHoles[ s2Idx ].push( ho );
  20474. } else {
  20475. ambiguous = true;
  20476. }
  20477. }
  20478. }
  20479. if ( hole_unassigned ) {
  20480. betterShapeHoles[ sIdx ].push( ho );
  20481. }
  20482. }
  20483. }
  20484. // console.log("ambiguous: ", ambiguous);
  20485. if ( toChange.length > 0 ) {
  20486. // console.log("to change: ", toChange);
  20487. if ( ! ambiguous ) newShapeHoles = betterShapeHoles;
  20488. }
  20489. }
  20490. var tmpHoles;
  20491. for ( var i = 0, il = newShapes.length; i < il; i ++ ) {
  20492. tmpShape = newShapes[ i ].s;
  20493. shapes.push( tmpShape );
  20494. tmpHoles = newShapeHoles[ i ];
  20495. for ( var j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  20496. tmpShape.holes.push( tmpHoles[ j ].h );
  20497. }
  20498. }
  20499. //console.log("shape", shapes);
  20500. return shapes;
  20501. };
  20502. // File:src/extras/core/Shape.js
  20503. /**
  20504. * @author zz85 / http://www.lab4games.net/zz85/blog
  20505. * Defines a 2d shape plane using paths.
  20506. **/
  20507. // STEP 1 Create a path.
  20508. // STEP 2 Turn path into shape.
  20509. // STEP 3 ExtrudeGeometry takes in Shape/Shapes
  20510. // STEP 3a - Extract points from each shape, turn to vertices
  20511. // STEP 3b - Triangulate each shape, add faces.
  20512. THREE.Shape = function () {
  20513. THREE.Path.apply( this, arguments );
  20514. this.holes = [];
  20515. };
  20516. THREE.Shape.prototype = Object.create( THREE.Path.prototype );
  20517. THREE.Shape.prototype.constructor = THREE.Shape;
  20518. // Convenience method to return ExtrudeGeometry
  20519. THREE.Shape.prototype.extrude = function ( options ) {
  20520. return new THREE.ExtrudeGeometry( this, options );
  20521. };
  20522. // Convenience method to return ShapeGeometry
  20523. THREE.Shape.prototype.makeGeometry = function ( options ) {
  20524. return new THREE.ShapeGeometry( this, options );
  20525. };
  20526. // Get points of holes
  20527. THREE.Shape.prototype.getPointsHoles = function ( divisions ) {
  20528. var holesPts = [];
  20529. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  20530. holesPts[ i ] = this.holes[ i ].getPoints( divisions );
  20531. }
  20532. return holesPts;
  20533. };
  20534. // Get points of shape and holes (keypoints based on segments parameter)
  20535. THREE.Shape.prototype.extractAllPoints = function ( divisions ) {
  20536. return {
  20537. shape: this.getPoints( divisions ),
  20538. holes: this.getPointsHoles( divisions )
  20539. };
  20540. };
  20541. THREE.Shape.prototype.extractPoints = function ( divisions ) {
  20542. return this.extractAllPoints( divisions );
  20543. };
  20544. THREE.Shape.Utils = THREE.ShapeUtils; // backwards compatibility
  20545. // File:src/extras/curves/LineCurve.js
  20546. /**************************************************************
  20547. * Line
  20548. **************************************************************/
  20549. THREE.LineCurve = function ( v1, v2 ) {
  20550. this.v1 = v1;
  20551. this.v2 = v2;
  20552. };
  20553. THREE.LineCurve.prototype = Object.create( THREE.Curve.prototype );
  20554. THREE.LineCurve.prototype.constructor = THREE.LineCurve;
  20555. THREE.LineCurve.prototype.getPoint = function ( t ) {
  20556. var point = this.v2.clone().sub( this.v1 );
  20557. point.multiplyScalar( t ).add( this.v1 );
  20558. return point;
  20559. };
  20560. // Line curve is linear, so we can overwrite default getPointAt
  20561. THREE.LineCurve.prototype.getPointAt = function ( u ) {
  20562. return this.getPoint( u );
  20563. };
  20564. THREE.LineCurve.prototype.getTangent = function( t ) {
  20565. var tangent = this.v2.clone().sub( this.v1 );
  20566. return tangent.normalize();
  20567. };
  20568. // File:src/extras/curves/QuadraticBezierCurve.js
  20569. /**************************************************************
  20570. * Quadratic Bezier curve
  20571. **************************************************************/
  20572. THREE.QuadraticBezierCurve = function ( v0, v1, v2 ) {
  20573. this.v0 = v0;
  20574. this.v1 = v1;
  20575. this.v2 = v2;
  20576. };
  20577. THREE.QuadraticBezierCurve.prototype = Object.create( THREE.Curve.prototype );
  20578. THREE.QuadraticBezierCurve.prototype.constructor = THREE.QuadraticBezierCurve;
  20579. THREE.QuadraticBezierCurve.prototype.getPoint = function ( t ) {
  20580. var b2 = THREE.ShapeUtils.b2;
  20581. return new THREE.Vector2(
  20582. b2( t, this.v0.x, this.v1.x, this.v2.x ),
  20583. b2( t, this.v0.y, this.v1.y, this.v2.y )
  20584. );
  20585. };
  20586. THREE.QuadraticBezierCurve.prototype.getTangent = function( t ) {
  20587. var tangentQuadraticBezier = THREE.CurveUtils.tangentQuadraticBezier;
  20588. return new THREE.Vector2(
  20589. tangentQuadraticBezier( t, this.v0.x, this.v1.x, this.v2.x ),
  20590. tangentQuadraticBezier( t, this.v0.y, this.v1.y, this.v2.y )
  20591. ).normalize();
  20592. };
  20593. // File:src/extras/curves/CubicBezierCurve.js
  20594. /**************************************************************
  20595. * Cubic Bezier curve
  20596. **************************************************************/
  20597. THREE.CubicBezierCurve = function ( v0, v1, v2, v3 ) {
  20598. this.v0 = v0;
  20599. this.v1 = v1;
  20600. this.v2 = v2;
  20601. this.v3 = v3;
  20602. };
  20603. THREE.CubicBezierCurve.prototype = Object.create( THREE.Curve.prototype );
  20604. THREE.CubicBezierCurve.prototype.constructor = THREE.CubicBezierCurve;
  20605. THREE.CubicBezierCurve.prototype.getPoint = function ( t ) {
  20606. var b3 = THREE.ShapeUtils.b3;
  20607. return new THREE.Vector2(
  20608. b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x ),
  20609. b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y )
  20610. );
  20611. };
  20612. THREE.CubicBezierCurve.prototype.getTangent = function( t ) {
  20613. var tangentCubicBezier = THREE.CurveUtils.tangentCubicBezier;
  20614. return new THREE.Vector2(
  20615. tangentCubicBezier( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x ),
  20616. tangentCubicBezier( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y )
  20617. ).normalize();
  20618. };
  20619. // File:src/extras/curves/SplineCurve.js
  20620. /**************************************************************
  20621. * Spline curve
  20622. **************************************************************/
  20623. THREE.SplineCurve = function ( points /* array of Vector2 */ ) {
  20624. this.points = ( points == undefined ) ? [] : points;
  20625. };
  20626. THREE.SplineCurve.prototype = Object.create( THREE.Curve.prototype );
  20627. THREE.SplineCurve.prototype.constructor = THREE.SplineCurve;
  20628. THREE.SplineCurve.prototype.getPoint = function ( t ) {
  20629. var points = this.points;
  20630. var point = ( points.length - 1 ) * t;
  20631. var intPoint = Math.floor( point );
  20632. var weight = point - intPoint;
  20633. var point0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  20634. var point1 = points[ intPoint ];
  20635. var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  20636. var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  20637. var interpolate = THREE.CurveUtils.interpolate;
  20638. return new THREE.Vector2(
  20639. interpolate( point0.x, point1.x, point2.x, point3.x, weight ),
  20640. interpolate( point0.y, point1.y, point2.y, point3.y, weight )
  20641. );
  20642. };
  20643. // File:src/extras/curves/EllipseCurve.js
  20644. /**************************************************************
  20645. * Ellipse curve
  20646. **************************************************************/
  20647. THREE.EllipseCurve = function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  20648. this.aX = aX;
  20649. this.aY = aY;
  20650. this.xRadius = xRadius;
  20651. this.yRadius = yRadius;
  20652. this.aStartAngle = aStartAngle;
  20653. this.aEndAngle = aEndAngle;
  20654. this.aClockwise = aClockwise;
  20655. this.aRotation = aRotation || 0;
  20656. };
  20657. THREE.EllipseCurve.prototype = Object.create( THREE.Curve.prototype );
  20658. THREE.EllipseCurve.prototype.constructor = THREE.EllipseCurve;
  20659. THREE.EllipseCurve.prototype.getPoint = function ( t ) {
  20660. var deltaAngle = this.aEndAngle - this.aStartAngle;
  20661. if ( deltaAngle < 0 ) deltaAngle += Math.PI * 2;
  20662. if ( deltaAngle > Math.PI * 2 ) deltaAngle -= Math.PI * 2;
  20663. var angle;
  20664. if ( this.aClockwise === true ) {
  20665. angle = this.aEndAngle + ( 1 - t ) * ( Math.PI * 2 - deltaAngle );
  20666. } else {
  20667. angle = this.aStartAngle + t * deltaAngle;
  20668. }
  20669. var x = this.aX + this.xRadius * Math.cos( angle );
  20670. var y = this.aY + this.yRadius * Math.sin( angle );
  20671. if ( this.aRotation !== 0 ) {
  20672. var cos = Math.cos( this.aRotation );
  20673. var sin = Math.sin( this.aRotation );
  20674. var tx = x, ty = y;
  20675. // Rotate the point about the center of the ellipse.
  20676. x = ( tx - this.aX ) * cos - ( ty - this.aY ) * sin + this.aX;
  20677. y = ( tx - this.aX ) * sin + ( ty - this.aY ) * cos + this.aY;
  20678. }
  20679. return new THREE.Vector2( x, y );
  20680. };
  20681. // File:src/extras/curves/ArcCurve.js
  20682. /**************************************************************
  20683. * Arc curve
  20684. **************************************************************/
  20685. THREE.ArcCurve = function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  20686. THREE.EllipseCurve.call( this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  20687. };
  20688. THREE.ArcCurve.prototype = Object.create( THREE.EllipseCurve.prototype );
  20689. THREE.ArcCurve.prototype.constructor = THREE.ArcCurve;
  20690. // File:src/extras/curves/LineCurve3.js
  20691. /**************************************************************
  20692. * Line3D
  20693. **************************************************************/
  20694. THREE.LineCurve3 = THREE.Curve.create(
  20695. function ( v1, v2 ) {
  20696. this.v1 = v1;
  20697. this.v2 = v2;
  20698. },
  20699. function ( t ) {
  20700. var vector = new THREE.Vector3();
  20701. vector.subVectors( this.v2, this.v1 ); // diff
  20702. vector.multiplyScalar( t );
  20703. vector.add( this.v1 );
  20704. return vector;
  20705. }
  20706. );
  20707. // File:src/extras/curves/QuadraticBezierCurve3.js
  20708. /**************************************************************
  20709. * Quadratic Bezier 3D curve
  20710. **************************************************************/
  20711. THREE.QuadraticBezierCurve3 = THREE.Curve.create(
  20712. function ( v0, v1, v2 ) {
  20713. this.v0 = v0;
  20714. this.v1 = v1;
  20715. this.v2 = v2;
  20716. },
  20717. function ( t ) {
  20718. var b2 = THREE.ShapeUtils.b2;
  20719. return new THREE.Vector3(
  20720. b2( t, this.v0.x, this.v1.x, this.v2.x ),
  20721. b2( t, this.v0.y, this.v1.y, this.v2.y ),
  20722. b2( t, this.v0.z, this.v1.z, this.v2.z )
  20723. );
  20724. }
  20725. );
  20726. // File:src/extras/curves/CubicBezierCurve3.js
  20727. /**************************************************************
  20728. * Cubic Bezier 3D curve
  20729. **************************************************************/
  20730. THREE.CubicBezierCurve3 = THREE.Curve.create(
  20731. function ( v0, v1, v2, v3 ) {
  20732. this.v0 = v0;
  20733. this.v1 = v1;
  20734. this.v2 = v2;
  20735. this.v3 = v3;
  20736. },
  20737. function ( t ) {
  20738. var b3 = THREE.ShapeUtils.b3;
  20739. return new THREE.Vector3(
  20740. b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x ),
  20741. b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y ),
  20742. b3( t, this.v0.z, this.v1.z, this.v2.z, this.v3.z )
  20743. );
  20744. }
  20745. );
  20746. // File:src/extras/curves/SplineCurve3.js
  20747. /**************************************************************
  20748. * Spline 3D curve
  20749. **************************************************************/
  20750. THREE.SplineCurve3 = THREE.Curve.create(
  20751. function ( points /* array of Vector3 */ ) {
  20752. console.warn( 'THREE.SplineCurve3 will be deprecated. Please use THREE.CatmullRomCurve3' );
  20753. this.points = ( points == undefined ) ? [] : points;
  20754. },
  20755. function ( t ) {
  20756. var points = this.points;
  20757. var point = ( points.length - 1 ) * t;
  20758. var intPoint = Math.floor( point );
  20759. var weight = point - intPoint;
  20760. var point0 = points[ intPoint == 0 ? intPoint : intPoint - 1 ];
  20761. var point1 = points[ intPoint ];
  20762. var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  20763. var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  20764. var interpolate = THREE.CurveUtils.interpolate;
  20765. return new THREE.Vector3(
  20766. interpolate( point0.x, point1.x, point2.x, point3.x, weight ),
  20767. interpolate( point0.y, point1.y, point2.y, point3.y, weight ),
  20768. interpolate( point0.z, point1.z, point2.z, point3.z, weight )
  20769. );
  20770. }
  20771. );
  20772. // File:src/extras/curves/CatmullRomCurve3.js
  20773. /**
  20774. * @author zz85 https://github.com/zz85
  20775. *
  20776. * Centripetal CatmullRom Curve - which is useful for avoiding
  20777. * cusps and self-intersections in non-uniform catmull rom curves.
  20778. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  20779. *
  20780. * curve.type accepts centripetal(default), chordal and catmullrom
  20781. * curve.tension is used for catmullrom which defaults to 0.5
  20782. */
  20783. THREE.CatmullRomCurve3 = ( function() {
  20784. var
  20785. tmp = new THREE.Vector3(),
  20786. px = new CubicPoly(),
  20787. py = new CubicPoly(),
  20788. pz = new CubicPoly();
  20789. /*
  20790. Based on an optimized c++ solution in
  20791. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  20792. - http://ideone.com/NoEbVM
  20793. This CubicPoly class could be used for reusing some variables and calculations,
  20794. but for three.js curve use, it could be possible inlined and flatten into a single function call
  20795. which can be placed in CurveUtils.
  20796. */
  20797. function CubicPoly() {
  20798. }
  20799. /*
  20800. * Compute coefficients for a cubic polynomial
  20801. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  20802. * such that
  20803. * p(0) = x0, p(1) = x1
  20804. * and
  20805. * p'(0) = t0, p'(1) = t1.
  20806. */
  20807. CubicPoly.prototype.init = function( x0, x1, t0, t1 ) {
  20808. this.c0 = x0;
  20809. this.c1 = t0;
  20810. this.c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  20811. this.c3 = 2 * x0 - 2 * x1 + t0 + t1;
  20812. };
  20813. CubicPoly.prototype.initNonuniformCatmullRom = function( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  20814. // compute tangents when parameterized in [t1,t2]
  20815. var t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  20816. var t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  20817. // rescale tangents for parametrization in [0,1]
  20818. t1 *= dt1;
  20819. t2 *= dt1;
  20820. // initCubicPoly
  20821. this.init( x1, x2, t1, t2 );
  20822. };
  20823. // standard Catmull-Rom spline: interpolate between x1 and x2 with previous/following points x1/x4
  20824. CubicPoly.prototype.initCatmullRom = function( x0, x1, x2, x3, tension ) {
  20825. this.init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  20826. };
  20827. CubicPoly.prototype.calc = function( t ) {
  20828. var t2 = t * t;
  20829. var t3 = t2 * t;
  20830. return this.c0 + this.c1 * t + this.c2 * t2 + this.c3 * t3;
  20831. };
  20832. // Subclass Three.js curve
  20833. return THREE.Curve.create(
  20834. function ( p /* array of Vector3 */ ) {
  20835. this.points = p || [];
  20836. },
  20837. function ( t ) {
  20838. var points = this.points,
  20839. point, intPoint, weight, l;
  20840. l = points.length;
  20841. if ( l < 2 ) console.log( 'duh, you need at least 2 points' );
  20842. point = ( l - 1 ) * t;
  20843. intPoint = Math.floor( point );
  20844. weight = point - intPoint;
  20845. if ( weight === 0 && intPoint === l - 1 ) {
  20846. intPoint = l - 2;
  20847. weight = 1;
  20848. }
  20849. var p0, p1, p2, p3;
  20850. if ( intPoint === 0 ) {
  20851. // extrapolate first point
  20852. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  20853. p0 = tmp;
  20854. } else {
  20855. p0 = points[ intPoint - 1 ];
  20856. }
  20857. p1 = points[ intPoint ];
  20858. p2 = points[ intPoint + 1 ];
  20859. if ( intPoint + 2 < l ) {
  20860. p3 = points[ intPoint + 2 ]
  20861. } else {
  20862. // extrapolate last point
  20863. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 2 ] );
  20864. p3 = tmp;
  20865. }
  20866. if ( this.type === undefined || this.type === 'centripetal' || this.type === 'chordal' ) {
  20867. // init Centripetal / Chordal Catmull-Rom
  20868. var pow = this.type === 'chordal' ? 0.5 : 0.25;
  20869. var dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  20870. var dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  20871. var dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  20872. // safety check for repeated points
  20873. if ( dt1 < 1e-4 ) dt1 = 1.0;
  20874. if ( dt0 < 1e-4 ) dt0 = dt1;
  20875. if ( dt2 < 1e-4 ) dt2 = dt1;
  20876. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  20877. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  20878. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  20879. } else if ( this.type === 'catmullrom' ) {
  20880. var tension = this.tension !== undefined ? this.tension : 0.5;
  20881. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, tension );
  20882. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, tension );
  20883. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, tension );
  20884. }
  20885. var v = new THREE.Vector3(
  20886. px.calc( weight ),
  20887. py.calc( weight ),
  20888. pz.calc( weight )
  20889. );
  20890. return v;
  20891. }
  20892. );
  20893. } )();
  20894. // File:src/extras/curves/ClosedSplineCurve3.js
  20895. /**************************************************************
  20896. * Closed Spline 3D curve
  20897. **************************************************************/
  20898. THREE.ClosedSplineCurve3 = THREE.Curve.create(
  20899. function ( points /* array of Vector3 */ ) {
  20900. this.points = ( points == undefined ) ? [] : points;
  20901. },
  20902. function ( t ) {
  20903. var points = this.points;
  20904. var point = ( points.length - 0 ) * t; // This needs to be from 0-length +1
  20905. var intPoint = Math.floor( point );
  20906. var weight = point - intPoint;
  20907. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / points.length ) + 1 ) * points.length;
  20908. var point0 = points[ ( intPoint - 1 ) % points.length ];
  20909. var point1 = points[ ( intPoint ) % points.length ];
  20910. var point2 = points[ ( intPoint + 1 ) % points.length ];
  20911. var point3 = points[ ( intPoint + 2 ) % points.length ];
  20912. var interpolate = THREE.CurveUtils.interpolate;
  20913. return new THREE.Vector3(
  20914. interpolate( point0.x, point1.x, point2.x, point3.x, weight ),
  20915. interpolate( point0.y, point1.y, point2.y, point3.y, weight ),
  20916. interpolate( point0.z, point1.z, point2.z, point3.z, weight )
  20917. );
  20918. }
  20919. );
  20920. // File:src/extras/geometries/BoxGeometry.js
  20921. /**
  20922. * @author mrdoob / http://mrdoob.com/
  20923. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Cube.as
  20924. */
  20925. THREE.BoxGeometry = function ( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  20926. THREE.Geometry.call( this );
  20927. this.type = 'BoxGeometry';
  20928. this.parameters = {
  20929. width: width,
  20930. height: height,
  20931. depth: depth,
  20932. widthSegments: widthSegments,
  20933. heightSegments: heightSegments,
  20934. depthSegments: depthSegments
  20935. };
  20936. this.widthSegments = widthSegments || 1;
  20937. this.heightSegments = heightSegments || 1;
  20938. this.depthSegments = depthSegments || 1;
  20939. var scope = this;
  20940. var width_half = width / 2;
  20941. var height_half = height / 2;
  20942. var depth_half = depth / 2;
  20943. buildPlane( 'z', 'y', - 1, - 1, depth, height, width_half, 0 ); // px
  20944. buildPlane( 'z', 'y', 1, - 1, depth, height, - width_half, 1 ); // nx
  20945. buildPlane( 'x', 'z', 1, 1, width, depth, height_half, 2 ); // py
  20946. buildPlane( 'x', 'z', 1, - 1, width, depth, - height_half, 3 ); // ny
  20947. buildPlane( 'x', 'y', 1, - 1, width, height, depth_half, 4 ); // pz
  20948. buildPlane( 'x', 'y', - 1, - 1, width, height, - depth_half, 5 ); // nz
  20949. function buildPlane( u, v, udir, vdir, width, height, depth, materialIndex ) {
  20950. var w, ix, iy,
  20951. gridX = scope.widthSegments,
  20952. gridY = scope.heightSegments,
  20953. width_half = width / 2,
  20954. height_half = height / 2,
  20955. offset = scope.vertices.length;
  20956. if ( ( u === 'x' && v === 'y' ) || ( u === 'y' && v === 'x' ) ) {
  20957. w = 'z';
  20958. } else if ( ( u === 'x' && v === 'z' ) || ( u === 'z' && v === 'x' ) ) {
  20959. w = 'y';
  20960. gridY = scope.depthSegments;
  20961. } else if ( ( u === 'z' && v === 'y' ) || ( u === 'y' && v === 'z' ) ) {
  20962. w = 'x';
  20963. gridX = scope.depthSegments;
  20964. }
  20965. var gridX1 = gridX + 1,
  20966. gridY1 = gridY + 1,
  20967. segment_width = width / gridX,
  20968. segment_height = height / gridY,
  20969. normal = new THREE.Vector3();
  20970. normal[ w ] = depth > 0 ? 1 : - 1;
  20971. for ( iy = 0; iy < gridY1; iy ++ ) {
  20972. for ( ix = 0; ix < gridX1; ix ++ ) {
  20973. var vector = new THREE.Vector3();
  20974. vector[ u ] = ( ix * segment_width - width_half ) * udir;
  20975. vector[ v ] = ( iy * segment_height - height_half ) * vdir;
  20976. vector[ w ] = depth;
  20977. scope.vertices.push( vector );
  20978. }
  20979. }
  20980. for ( iy = 0; iy < gridY; iy ++ ) {
  20981. for ( ix = 0; ix < gridX; ix ++ ) {
  20982. var a = ix + gridX1 * iy;
  20983. var b = ix + gridX1 * ( iy + 1 );
  20984. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  20985. var d = ( ix + 1 ) + gridX1 * iy;
  20986. var uva = new THREE.Vector2( ix / gridX, 1 - iy / gridY );
  20987. var uvb = new THREE.Vector2( ix / gridX, 1 - ( iy + 1 ) / gridY );
  20988. var uvc = new THREE.Vector2( ( ix + 1 ) / gridX, 1 - ( iy + 1 ) / gridY );
  20989. var uvd = new THREE.Vector2( ( ix + 1 ) / gridX, 1 - iy / gridY );
  20990. var face = new THREE.Face3( a + offset, b + offset, d + offset );
  20991. face.normal.copy( normal );
  20992. face.vertexNormals.push( normal.clone(), normal.clone(), normal.clone() );
  20993. face.materialIndex = materialIndex;
  20994. scope.faces.push( face );
  20995. scope.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  20996. face = new THREE.Face3( b + offset, c + offset, d + offset );
  20997. face.normal.copy( normal );
  20998. face.vertexNormals.push( normal.clone(), normal.clone(), normal.clone() );
  20999. face.materialIndex = materialIndex;
  21000. scope.faces.push( face );
  21001. scope.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  21002. }
  21003. }
  21004. }
  21005. this.mergeVertices();
  21006. };
  21007. THREE.BoxGeometry.prototype = Object.create( THREE.Geometry.prototype );
  21008. THREE.BoxGeometry.prototype.constructor = THREE.BoxGeometry;
  21009. THREE.CubeGeometry = THREE.BoxGeometry; // backwards compatibility
  21010. // File:src/extras/geometries/CircleGeometry.js
  21011. /**
  21012. * @author hughes
  21013. */
  21014. THREE.CircleGeometry = function ( radius, segments, thetaStart, thetaLength ) {
  21015. THREE.Geometry.call( this );
  21016. this.type = 'CircleGeometry';
  21017. this.parameters = {
  21018. radius: radius,
  21019. segments: segments,
  21020. thetaStart: thetaStart,
  21021. thetaLength: thetaLength
  21022. };
  21023. this.fromBufferGeometry( new THREE.CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) );
  21024. };
  21025. THREE.CircleGeometry.prototype = Object.create( THREE.Geometry.prototype );
  21026. THREE.CircleGeometry.prototype.constructor = THREE.CircleGeometry;
  21027. // File:src/extras/geometries/CircleBufferGeometry.js
  21028. /**
  21029. * @author benaadams / https://twitter.com/ben_a_adams
  21030. */
  21031. THREE.CircleBufferGeometry = function ( radius, segments, thetaStart, thetaLength ) {
  21032. THREE.BufferGeometry.call( this );
  21033. this.type = 'CircleBufferGeometry';
  21034. this.parameters = {
  21035. radius: radius,
  21036. segments: segments,
  21037. thetaStart: thetaStart,
  21038. thetaLength: thetaLength
  21039. };
  21040. radius = radius || 50;
  21041. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  21042. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  21043. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  21044. var vertices = segments + 2;
  21045. var positions = new Float32Array( vertices * 3 );
  21046. var normals = new Float32Array( vertices * 3 );
  21047. var uvs = new Float32Array( vertices * 2 );
  21048. // center data is already zero, but need to set a few extras
  21049. normals[ 2 ] = 1.0;
  21050. uvs[ 0 ] = 0.5;
  21051. uvs[ 1 ] = 0.5;
  21052. for ( var s = 0, i = 3, ii = 2 ; s <= segments; s ++, i += 3, ii += 2 ) {
  21053. var segment = thetaStart + s / segments * thetaLength;
  21054. positions[ i ] = radius * Math.cos( segment );
  21055. positions[ i + 1 ] = radius * Math.sin( segment );
  21056. normals[ i + 2 ] = 1; // normal z
  21057. uvs[ ii ] = ( positions[ i ] / radius + 1 ) / 2;
  21058. uvs[ ii + 1 ] = ( positions[ i + 1 ] / radius + 1 ) / 2;
  21059. }
  21060. var indices = [];
  21061. for ( var i = 1; i <= segments; i ++ ) {
  21062. indices.push( i, i + 1, 0 );
  21063. }
  21064. this.setIndex( new THREE.BufferAttribute( new Uint16Array( indices ), 1 ) );
  21065. this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
  21066. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  21067. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  21068. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  21069. };
  21070. THREE.CircleBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  21071. THREE.CircleBufferGeometry.prototype.constructor = THREE.CircleBufferGeometry;
  21072. // File:src/extras/geometries/CylinderGeometry.js
  21073. /**
  21074. * @author mrdoob / http://mrdoob.com/
  21075. */
  21076. THREE.CylinderGeometry = function ( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  21077. THREE.Geometry.call( this );
  21078. this.type = 'CylinderGeometry';
  21079. this.parameters = {
  21080. radiusTop: radiusTop,
  21081. radiusBottom: radiusBottom,
  21082. height: height,
  21083. radialSegments: radialSegments,
  21084. heightSegments: heightSegments,
  21085. openEnded: openEnded,
  21086. thetaStart: thetaStart,
  21087. thetaLength: thetaLength
  21088. };
  21089. radiusTop = radiusTop !== undefined ? radiusTop : 20;
  21090. radiusBottom = radiusBottom !== undefined ? radiusBottom : 20;
  21091. height = height !== undefined ? height : 100;
  21092. radialSegments = radialSegments || 8;
  21093. heightSegments = heightSegments || 1;
  21094. openEnded = openEnded !== undefined ? openEnded : false;
  21095. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  21096. thetaLength = thetaLength !== undefined ? thetaLength : 2 * Math.PI;
  21097. var heightHalf = height / 2;
  21098. var x, y, vertices = [], uvs = [];
  21099. for ( y = 0; y <= heightSegments; y ++ ) {
  21100. var verticesRow = [];
  21101. var uvsRow = [];
  21102. var v = y / heightSegments;
  21103. var radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  21104. for ( x = 0; x <= radialSegments; x ++ ) {
  21105. var u = x / radialSegments;
  21106. var vertex = new THREE.Vector3();
  21107. vertex.x = radius * Math.sin( u * thetaLength + thetaStart );
  21108. vertex.y = - v * height + heightHalf;
  21109. vertex.z = radius * Math.cos( u * thetaLength + thetaStart );
  21110. this.vertices.push( vertex );
  21111. verticesRow.push( this.vertices.length - 1 );
  21112. uvsRow.push( new THREE.Vector2( u, 1 - v ) );
  21113. }
  21114. vertices.push( verticesRow );
  21115. uvs.push( uvsRow );
  21116. }
  21117. var tanTheta = ( radiusBottom - radiusTop ) / height;
  21118. var na, nb;
  21119. for ( x = 0; x < radialSegments; x ++ ) {
  21120. if ( radiusTop !== 0 ) {
  21121. na = this.vertices[ vertices[ 0 ][ x ] ].clone();
  21122. nb = this.vertices[ vertices[ 0 ][ x + 1 ] ].clone();
  21123. } else {
  21124. na = this.vertices[ vertices[ 1 ][ x ] ].clone();
  21125. nb = this.vertices[ vertices[ 1 ][ x + 1 ] ].clone();
  21126. }
  21127. na.setY( Math.sqrt( na.x * na.x + na.z * na.z ) * tanTheta ).normalize();
  21128. nb.setY( Math.sqrt( nb.x * nb.x + nb.z * nb.z ) * tanTheta ).normalize();
  21129. for ( y = 0; y < heightSegments; y ++ ) {
  21130. var v1 = vertices[ y ][ x ];
  21131. var v2 = vertices[ y + 1 ][ x ];
  21132. var v3 = vertices[ y + 1 ][ x + 1 ];
  21133. var v4 = vertices[ y ][ x + 1 ];
  21134. var n1 = na.clone();
  21135. var n2 = na.clone();
  21136. var n3 = nb.clone();
  21137. var n4 = nb.clone();
  21138. var uv1 = uvs[ y ][ x ].clone();
  21139. var uv2 = uvs[ y + 1 ][ x ].clone();
  21140. var uv3 = uvs[ y + 1 ][ x + 1 ].clone();
  21141. var uv4 = uvs[ y ][ x + 1 ].clone();
  21142. this.faces.push( new THREE.Face3( v1, v2, v4, [ n1, n2, n4 ] ) );
  21143. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv4 ] );
  21144. this.faces.push( new THREE.Face3( v2, v3, v4, [ n2.clone(), n3, n4.clone() ] ) );
  21145. this.faceVertexUvs[ 0 ].push( [ uv2.clone(), uv3, uv4.clone() ] );
  21146. }
  21147. }
  21148. // top cap
  21149. if ( openEnded === false && radiusTop > 0 ) {
  21150. this.vertices.push( new THREE.Vector3( 0, heightHalf, 0 ) );
  21151. for ( x = 0; x < radialSegments; x ++ ) {
  21152. var v1 = vertices[ 0 ][ x ];
  21153. var v2 = vertices[ 0 ][ x + 1 ];
  21154. var v3 = this.vertices.length - 1;
  21155. var n1 = new THREE.Vector3( 0, 1, 0 );
  21156. var n2 = new THREE.Vector3( 0, 1, 0 );
  21157. var n3 = new THREE.Vector3( 0, 1, 0 );
  21158. var uv1 = uvs[ 0 ][ x ].clone();
  21159. var uv2 = uvs[ 0 ][ x + 1 ].clone();
  21160. var uv3 = new THREE.Vector2( uv2.x, 0 );
  21161. this.faces.push( new THREE.Face3( v1, v2, v3, [ n1, n2, n3 ], undefined, 1 ) );
  21162. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3 ] );
  21163. }
  21164. }
  21165. // bottom cap
  21166. if ( openEnded === false && radiusBottom > 0 ) {
  21167. this.vertices.push( new THREE.Vector3( 0, - heightHalf, 0 ) );
  21168. for ( x = 0; x < radialSegments; x ++ ) {
  21169. var v1 = vertices[ heightSegments ][ x + 1 ];
  21170. var v2 = vertices[ heightSegments ][ x ];
  21171. var v3 = this.vertices.length - 1;
  21172. var n1 = new THREE.Vector3( 0, - 1, 0 );
  21173. var n2 = new THREE.Vector3( 0, - 1, 0 );
  21174. var n3 = new THREE.Vector3( 0, - 1, 0 );
  21175. var uv1 = uvs[ heightSegments ][ x + 1 ].clone();
  21176. var uv2 = uvs[ heightSegments ][ x ].clone();
  21177. var uv3 = new THREE.Vector2( uv2.x, 1 );
  21178. this.faces.push( new THREE.Face3( v1, v2, v3, [ n1, n2, n3 ], undefined, 2 ) );
  21179. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3 ] );
  21180. }
  21181. }
  21182. this.computeFaceNormals();
  21183. };
  21184. THREE.CylinderGeometry.prototype = Object.create( THREE.Geometry.prototype );
  21185. THREE.CylinderGeometry.prototype.constructor = THREE.CylinderGeometry;
  21186. // File:src/extras/geometries/EdgesGeometry.js
  21187. /**
  21188. * @author WestLangley / http://github.com/WestLangley
  21189. */
  21190. THREE.EdgesGeometry = function ( geometry, thresholdAngle ) {
  21191. THREE.BufferGeometry.call( this );
  21192. thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
  21193. var thresholdDot = Math.cos( THREE.Math.degToRad( thresholdAngle ) );
  21194. var edge = [ 0, 0 ], hash = {};
  21195. function sortFunction( a, b ) {
  21196. return a - b;
  21197. }
  21198. var keys = [ 'a', 'b', 'c' ];
  21199. var geometry2;
  21200. if ( geometry instanceof THREE.BufferGeometry ) {
  21201. geometry2 = new THREE.Geometry();
  21202. geometry2.fromBufferGeometry( geometry );
  21203. } else {
  21204. geometry2 = geometry.clone();
  21205. }
  21206. geometry2.mergeVertices();
  21207. geometry2.computeFaceNormals();
  21208. var vertices = geometry2.vertices;
  21209. var faces = geometry2.faces;
  21210. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  21211. var face = faces[ i ];
  21212. for ( var j = 0; j < 3; j ++ ) {
  21213. edge[ 0 ] = face[ keys[ j ] ];
  21214. edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
  21215. edge.sort( sortFunction );
  21216. var key = edge.toString();
  21217. if ( hash[ key ] === undefined ) {
  21218. hash[ key ] = { vert1: edge[ 0 ], vert2: edge[ 1 ], face1: i, face2: undefined };
  21219. } else {
  21220. hash[ key ].face2 = i;
  21221. }
  21222. }
  21223. }
  21224. var coords = [];
  21225. for ( var key in hash ) {
  21226. var h = hash[ key ];
  21227. if ( h.face2 === undefined || faces[ h.face1 ].normal.dot( faces[ h.face2 ].normal ) <= thresholdDot ) {
  21228. var vertex = vertices[ h.vert1 ];
  21229. coords.push( vertex.x );
  21230. coords.push( vertex.y );
  21231. coords.push( vertex.z );
  21232. vertex = vertices[ h.vert2 ];
  21233. coords.push( vertex.x );
  21234. coords.push( vertex.y );
  21235. coords.push( vertex.z );
  21236. }
  21237. }
  21238. this.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array( coords ), 3 ) );
  21239. };
  21240. THREE.EdgesGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  21241. THREE.EdgesGeometry.prototype.constructor = THREE.EdgesGeometry;
  21242. // File:src/extras/geometries/ExtrudeGeometry.js
  21243. /**
  21244. * @author zz85 / http://www.lab4games.net/zz85/blog
  21245. *
  21246. * Creates extruded geometry from a path shape.
  21247. *
  21248. * parameters = {
  21249. *
  21250. * curveSegments: <int>, // number of points on the curves
  21251. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  21252. * amount: <int>, // Depth to extrude the shape
  21253. *
  21254. * bevelEnabled: <bool>, // turn on bevel
  21255. * bevelThickness: <float>, // how deep into the original shape bevel goes
  21256. * bevelSize: <float>, // how far from shape outline is bevel
  21257. * bevelSegments: <int>, // number of bevel layers
  21258. *
  21259. * extrudePath: <THREE.CurvePath> // 3d spline path to extrude shape along. (creates Frames if .frames aren't defined)
  21260. * frames: <THREE.TubeGeometry.FrenetFrames> // containing arrays of tangents, normals, binormals
  21261. *
  21262. * uvGenerator: <Object> // object that provides UV generator functions
  21263. *
  21264. * }
  21265. **/
  21266. THREE.ExtrudeGeometry = function ( shapes, options ) {
  21267. if ( typeof( shapes ) === "undefined" ) {
  21268. shapes = [];
  21269. return;
  21270. }
  21271. THREE.Geometry.call( this );
  21272. this.type = 'ExtrudeGeometry';
  21273. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  21274. this.addShapeList( shapes, options );
  21275. this.computeFaceNormals();
  21276. // can't really use automatic vertex normals
  21277. // as then front and back sides get smoothed too
  21278. // should do separate smoothing just for sides
  21279. //this.computeVertexNormals();
  21280. //console.log( "took", ( Date.now() - startTime ) );
  21281. };
  21282. THREE.ExtrudeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  21283. THREE.ExtrudeGeometry.prototype.constructor = THREE.ExtrudeGeometry;
  21284. THREE.ExtrudeGeometry.prototype.addShapeList = function ( shapes, options ) {
  21285. var sl = shapes.length;
  21286. for ( var s = 0; s < sl; s ++ ) {
  21287. var shape = shapes[ s ];
  21288. this.addShape( shape, options );
  21289. }
  21290. };
  21291. THREE.ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
  21292. var amount = options.amount !== undefined ? options.amount : 100;
  21293. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6; // 10
  21294. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2; // 8
  21295. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  21296. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true; // false
  21297. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  21298. var steps = options.steps !== undefined ? options.steps : 1;
  21299. var extrudePath = options.extrudePath;
  21300. var extrudePts, extrudeByPath = false;
  21301. // Use default WorldUVGenerator if no UV generators are specified.
  21302. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : THREE.ExtrudeGeometry.WorldUVGenerator;
  21303. var splineTube, binormal, normal, position2;
  21304. if ( extrudePath ) {
  21305. extrudePts = extrudePath.getSpacedPoints( steps );
  21306. extrudeByPath = true;
  21307. bevelEnabled = false; // bevels not supported for path extrusion
  21308. // SETUP TNB variables
  21309. // Reuse TNB from TubeGeomtry for now.
  21310. // TODO1 - have a .isClosed in spline?
  21311. splineTube = options.frames !== undefined ? options.frames : new THREE.TubeGeometry.FrenetFrames( extrudePath, steps, false );
  21312. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  21313. binormal = new THREE.Vector3();
  21314. normal = new THREE.Vector3();
  21315. position2 = new THREE.Vector3();
  21316. }
  21317. // Safeguards if bevels are not enabled
  21318. if ( ! bevelEnabled ) {
  21319. bevelSegments = 0;
  21320. bevelThickness = 0;
  21321. bevelSize = 0;
  21322. }
  21323. // Variables initialization
  21324. var ahole, h, hl; // looping of holes
  21325. var scope = this;
  21326. var shapesOffset = this.vertices.length;
  21327. var shapePoints = shape.extractPoints( curveSegments );
  21328. var vertices = shapePoints.shape;
  21329. var holes = shapePoints.holes;
  21330. var reverse = ! THREE.ShapeUtils.isClockWise( vertices );
  21331. if ( reverse ) {
  21332. vertices = vertices.reverse();
  21333. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  21334. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  21335. ahole = holes[ h ];
  21336. if ( THREE.ShapeUtils.isClockWise( ahole ) ) {
  21337. holes[ h ] = ahole.reverse();
  21338. }
  21339. }
  21340. reverse = false; // If vertices are in order now, we shouldn't need to worry about them again (hopefully)!
  21341. }
  21342. var faces = THREE.ShapeUtils.triangulateShape( vertices, holes );
  21343. /* Vertices */
  21344. var contour = vertices; // vertices has all points but contour has only points of circumference
  21345. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  21346. ahole = holes[ h ];
  21347. vertices = vertices.concat( ahole );
  21348. }
  21349. function scalePt2 ( pt, vec, size ) {
  21350. if ( ! vec ) console.error( "THREE.ExtrudeGeometry: vec does not exist" );
  21351. return vec.clone().multiplyScalar( size ).add( pt );
  21352. }
  21353. var b, bs, t, z,
  21354. vert, vlen = vertices.length,
  21355. face, flen = faces.length;
  21356. // Find directions for point movement
  21357. function getBevelVec( inPt, inPrev, inNext ) {
  21358. // computes for inPt the corresponding point inPt' on a new contour
  21359. // shifted by 1 unit (length of normalized vector) to the left
  21360. // if we walk along contour clockwise, this new contour is outside the old one
  21361. //
  21362. // inPt' is the intersection of the two lines parallel to the two
  21363. // adjacent edges of inPt at a distance of 1 unit on the left side.
  21364. var v_trans_x, v_trans_y, shrink_by = 1; // resulting translation vector for inPt
  21365. // good reading for geometry algorithms (here: line-line intersection)
  21366. // http://geomalgorithms.com/a05-_intersect-1.html
  21367. var v_prev_x = inPt.x - inPrev.x, v_prev_y = inPt.y - inPrev.y;
  21368. var v_next_x = inNext.x - inPt.x, v_next_y = inNext.y - inPt.y;
  21369. var v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  21370. // check for collinear edges
  21371. var collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  21372. if ( Math.abs( collinear0 ) > Number.EPSILON ) {
  21373. // not collinear
  21374. // length of vectors for normalizing
  21375. var v_prev_len = Math.sqrt( v_prev_lensq );
  21376. var v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  21377. // shift adjacent points by unit vectors to the left
  21378. var ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  21379. var ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  21380. var ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  21381. var ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  21382. // scaling factor for v_prev to intersection point
  21383. var sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  21384. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  21385. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  21386. // vector from inPt to intersection point
  21387. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  21388. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  21389. // Don't normalize!, otherwise sharp corners become ugly
  21390. // but prevent crazy spikes
  21391. var v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  21392. if ( v_trans_lensq <= 2 ) {
  21393. return new THREE.Vector2( v_trans_x, v_trans_y );
  21394. } else {
  21395. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  21396. }
  21397. } else {
  21398. // handle special case of collinear edges
  21399. var direction_eq = false; // assumes: opposite
  21400. if ( v_prev_x > Number.EPSILON ) {
  21401. if ( v_next_x > Number.EPSILON ) {
  21402. direction_eq = true;
  21403. }
  21404. } else {
  21405. if ( v_prev_x < - Number.EPSILON ) {
  21406. if ( v_next_x < - Number.EPSILON ) {
  21407. direction_eq = true;
  21408. }
  21409. } else {
  21410. if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
  21411. direction_eq = true;
  21412. }
  21413. }
  21414. }
  21415. if ( direction_eq ) {
  21416. // console.log("Warning: lines are a straight sequence");
  21417. v_trans_x = - v_prev_y;
  21418. v_trans_y = v_prev_x;
  21419. shrink_by = Math.sqrt( v_prev_lensq );
  21420. } else {
  21421. // console.log("Warning: lines are a straight spike");
  21422. v_trans_x = v_prev_x;
  21423. v_trans_y = v_prev_y;
  21424. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  21425. }
  21426. }
  21427. return new THREE.Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  21428. }
  21429. var contourMovements = [];
  21430. for ( var i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  21431. if ( j === il ) j = 0;
  21432. if ( k === il ) k = 0;
  21433. // (j)---(i)---(k)
  21434. // console.log('i,j,k', i, j , k)
  21435. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  21436. }
  21437. var holesMovements = [], oneHoleMovements, verticesMovements = contourMovements.concat();
  21438. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  21439. ahole = holes[ h ];
  21440. oneHoleMovements = [];
  21441. for ( i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  21442. if ( j === il ) j = 0;
  21443. if ( k === il ) k = 0;
  21444. // (j)---(i)---(k)
  21445. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  21446. }
  21447. holesMovements.push( oneHoleMovements );
  21448. verticesMovements = verticesMovements.concat( oneHoleMovements );
  21449. }
  21450. // Loop bevelSegments, 1 for the front, 1 for the back
  21451. for ( b = 0; b < bevelSegments; b ++ ) {
  21452. //for ( b = bevelSegments; b > 0; b -- ) {
  21453. t = b / bevelSegments;
  21454. z = bevelThickness * ( 1 - t );
  21455. //z = bevelThickness * t;
  21456. bs = bevelSize * ( Math.sin ( t * Math.PI / 2 ) ); // curved
  21457. //bs = bevelSize * t; // linear
  21458. // contract shape
  21459. for ( i = 0, il = contour.length; i < il; i ++ ) {
  21460. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  21461. v( vert.x, vert.y, - z );
  21462. }
  21463. // expand holes
  21464. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  21465. ahole = holes[ h ];
  21466. oneHoleMovements = holesMovements[ h ];
  21467. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  21468. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  21469. v( vert.x, vert.y, - z );
  21470. }
  21471. }
  21472. }
  21473. bs = bevelSize;
  21474. // Back facing vertices
  21475. for ( i = 0; i < vlen; i ++ ) {
  21476. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  21477. if ( ! extrudeByPath ) {
  21478. v( vert.x, vert.y, 0 );
  21479. } else {
  21480. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  21481. normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x );
  21482. binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y );
  21483. position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
  21484. v( position2.x, position2.y, position2.z );
  21485. }
  21486. }
  21487. // Add stepped vertices...
  21488. // Including front facing vertices
  21489. var s;
  21490. for ( s = 1; s <= steps; s ++ ) {
  21491. for ( i = 0; i < vlen; i ++ ) {
  21492. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  21493. if ( ! extrudeByPath ) {
  21494. v( vert.x, vert.y, amount / steps * s );
  21495. } else {
  21496. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  21497. normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x );
  21498. binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y );
  21499. position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
  21500. v( position2.x, position2.y, position2.z );
  21501. }
  21502. }
  21503. }
  21504. // Add bevel segments planes
  21505. //for ( b = 1; b <= bevelSegments; b ++ ) {
  21506. for ( b = bevelSegments - 1; b >= 0; b -- ) {
  21507. t = b / bevelSegments;
  21508. z = bevelThickness * ( 1 - t );
  21509. //bs = bevelSize * ( 1-Math.sin ( ( 1 - t ) * Math.PI/2 ) );
  21510. bs = bevelSize * Math.sin ( t * Math.PI / 2 );
  21511. // contract shape
  21512. for ( i = 0, il = contour.length; i < il; i ++ ) {
  21513. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  21514. v( vert.x, vert.y, amount + z );
  21515. }
  21516. // expand holes
  21517. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  21518. ahole = holes[ h ];
  21519. oneHoleMovements = holesMovements[ h ];
  21520. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  21521. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  21522. if ( ! extrudeByPath ) {
  21523. v( vert.x, vert.y, amount + z );
  21524. } else {
  21525. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  21526. }
  21527. }
  21528. }
  21529. }
  21530. /* Faces */
  21531. // Top and bottom faces
  21532. buildLidFaces();
  21533. // Sides faces
  21534. buildSideFaces();
  21535. ///// Internal functions
  21536. function buildLidFaces() {
  21537. if ( bevelEnabled ) {
  21538. var layer = 0; // steps + 1
  21539. var offset = vlen * layer;
  21540. // Bottom faces
  21541. for ( i = 0; i < flen; i ++ ) {
  21542. face = faces[ i ];
  21543. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  21544. }
  21545. layer = steps + bevelSegments * 2;
  21546. offset = vlen * layer;
  21547. // Top faces
  21548. for ( i = 0; i < flen; i ++ ) {
  21549. face = faces[ i ];
  21550. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  21551. }
  21552. } else {
  21553. // Bottom faces
  21554. for ( i = 0; i < flen; i ++ ) {
  21555. face = faces[ i ];
  21556. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  21557. }
  21558. // Top faces
  21559. for ( i = 0; i < flen; i ++ ) {
  21560. face = faces[ i ];
  21561. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  21562. }
  21563. }
  21564. }
  21565. // Create faces for the z-sides of the shape
  21566. function buildSideFaces() {
  21567. var layeroffset = 0;
  21568. sidewalls( contour, layeroffset );
  21569. layeroffset += contour.length;
  21570. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  21571. ahole = holes[ h ];
  21572. sidewalls( ahole, layeroffset );
  21573. //, true
  21574. layeroffset += ahole.length;
  21575. }
  21576. }
  21577. function sidewalls( contour, layeroffset ) {
  21578. var j, k;
  21579. i = contour.length;
  21580. while ( -- i >= 0 ) {
  21581. j = i;
  21582. k = i - 1;
  21583. if ( k < 0 ) k = contour.length - 1;
  21584. //console.log('b', i,j, i-1, k,vertices.length);
  21585. var s = 0, sl = steps + bevelSegments * 2;
  21586. for ( s = 0; s < sl; s ++ ) {
  21587. var slen1 = vlen * s;
  21588. var slen2 = vlen * ( s + 1 );
  21589. var a = layeroffset + j + slen1,
  21590. b = layeroffset + k + slen1,
  21591. c = layeroffset + k + slen2,
  21592. d = layeroffset + j + slen2;
  21593. f4( a, b, c, d, contour, s, sl, j, k );
  21594. }
  21595. }
  21596. }
  21597. function v( x, y, z ) {
  21598. scope.vertices.push( new THREE.Vector3( x, y, z ) );
  21599. }
  21600. function f3( a, b, c ) {
  21601. a += shapesOffset;
  21602. b += shapesOffset;
  21603. c += shapesOffset;
  21604. scope.faces.push( new THREE.Face3( a, b, c, null, null, 0 ) );
  21605. var uvs = uvgen.generateTopUV( scope, a, b, c );
  21606. scope.faceVertexUvs[ 0 ].push( uvs );
  21607. }
  21608. function f4( a, b, c, d, wallContour, stepIndex, stepsLength, contourIndex1, contourIndex2 ) {
  21609. a += shapesOffset;
  21610. b += shapesOffset;
  21611. c += shapesOffset;
  21612. d += shapesOffset;
  21613. scope.faces.push( new THREE.Face3( a, b, d, null, null, 1 ) );
  21614. scope.faces.push( new THREE.Face3( b, c, d, null, null, 1 ) );
  21615. var uvs = uvgen.generateSideWallUV( scope, a, b, c, d );
  21616. scope.faceVertexUvs[ 0 ].push( [ uvs[ 0 ], uvs[ 1 ], uvs[ 3 ] ] );
  21617. scope.faceVertexUvs[ 0 ].push( [ uvs[ 1 ], uvs[ 2 ], uvs[ 3 ] ] );
  21618. }
  21619. };
  21620. THREE.ExtrudeGeometry.WorldUVGenerator = {
  21621. generateTopUV: function ( geometry, indexA, indexB, indexC ) {
  21622. var vertices = geometry.vertices;
  21623. var a = vertices[ indexA ];
  21624. var b = vertices[ indexB ];
  21625. var c = vertices[ indexC ];
  21626. return [
  21627. new THREE.Vector2( a.x, a.y ),
  21628. new THREE.Vector2( b.x, b.y ),
  21629. new THREE.Vector2( c.x, c.y )
  21630. ];
  21631. },
  21632. generateSideWallUV: function ( geometry, indexA, indexB, indexC, indexD ) {
  21633. var vertices = geometry.vertices;
  21634. var a = vertices[ indexA ];
  21635. var b = vertices[ indexB ];
  21636. var c = vertices[ indexC ];
  21637. var d = vertices[ indexD ];
  21638. if ( Math.abs( a.y - b.y ) < 0.01 ) {
  21639. return [
  21640. new THREE.Vector2( a.x, 1 - a.z ),
  21641. new THREE.Vector2( b.x, 1 - b.z ),
  21642. new THREE.Vector2( c.x, 1 - c.z ),
  21643. new THREE.Vector2( d.x, 1 - d.z )
  21644. ];
  21645. } else {
  21646. return [
  21647. new THREE.Vector2( a.y, 1 - a.z ),
  21648. new THREE.Vector2( b.y, 1 - b.z ),
  21649. new THREE.Vector2( c.y, 1 - c.z ),
  21650. new THREE.Vector2( d.y, 1 - d.z )
  21651. ];
  21652. }
  21653. }
  21654. };
  21655. // File:src/extras/geometries/ShapeGeometry.js
  21656. /**
  21657. * @author jonobr1 / http://jonobr1.com
  21658. *
  21659. * Creates a one-sided polygonal geometry from a path shape. Similar to
  21660. * ExtrudeGeometry.
  21661. *
  21662. * parameters = {
  21663. *
  21664. * curveSegments: <int>, // number of points on the curves. NOT USED AT THE MOMENT.
  21665. *
  21666. * material: <int> // material index for front and back faces
  21667. * uvGenerator: <Object> // object that provides UV generator functions
  21668. *
  21669. * }
  21670. **/
  21671. THREE.ShapeGeometry = function ( shapes, options ) {
  21672. THREE.Geometry.call( this );
  21673. this.type = 'ShapeGeometry';
  21674. if ( Array.isArray( shapes ) === false ) shapes = [ shapes ];
  21675. this.addShapeList( shapes, options );
  21676. this.computeFaceNormals();
  21677. };
  21678. THREE.ShapeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  21679. THREE.ShapeGeometry.prototype.constructor = THREE.ShapeGeometry;
  21680. /**
  21681. * Add an array of shapes to THREE.ShapeGeometry.
  21682. */
  21683. THREE.ShapeGeometry.prototype.addShapeList = function ( shapes, options ) {
  21684. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  21685. this.addShape( shapes[ i ], options );
  21686. }
  21687. return this;
  21688. };
  21689. /**
  21690. * Adds a shape to THREE.ShapeGeometry, based on THREE.ExtrudeGeometry.
  21691. */
  21692. THREE.ShapeGeometry.prototype.addShape = function ( shape, options ) {
  21693. if ( options === undefined ) options = {};
  21694. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  21695. var material = options.material;
  21696. var uvgen = options.UVGenerator === undefined ? THREE.ExtrudeGeometry.WorldUVGenerator : options.UVGenerator;
  21697. //
  21698. var i, l, hole;
  21699. var shapesOffset = this.vertices.length;
  21700. var shapePoints = shape.extractPoints( curveSegments );
  21701. var vertices = shapePoints.shape;
  21702. var holes = shapePoints.holes;
  21703. var reverse = ! THREE.ShapeUtils.isClockWise( vertices );
  21704. if ( reverse ) {
  21705. vertices = vertices.reverse();
  21706. // Maybe we should also check if holes are in the opposite direction, just to be safe...
  21707. for ( i = 0, l = holes.length; i < l; i ++ ) {
  21708. hole = holes[ i ];
  21709. if ( THREE.ShapeUtils.isClockWise( hole ) ) {
  21710. holes[ i ] = hole.reverse();
  21711. }
  21712. }
  21713. reverse = false;
  21714. }
  21715. var faces = THREE.ShapeUtils.triangulateShape( vertices, holes );
  21716. // Vertices
  21717. for ( i = 0, l = holes.length; i < l; i ++ ) {
  21718. hole = holes[ i ];
  21719. vertices = vertices.concat( hole );
  21720. }
  21721. //
  21722. var vert, vlen = vertices.length;
  21723. var face, flen = faces.length;
  21724. for ( i = 0; i < vlen; i ++ ) {
  21725. vert = vertices[ i ];
  21726. this.vertices.push( new THREE.Vector3( vert.x, vert.y, 0 ) );
  21727. }
  21728. for ( i = 0; i < flen; i ++ ) {
  21729. face = faces[ i ];
  21730. var a = face[ 0 ] + shapesOffset;
  21731. var b = face[ 1 ] + shapesOffset;
  21732. var c = face[ 2 ] + shapesOffset;
  21733. this.faces.push( new THREE.Face3( a, b, c, null, null, material ) );
  21734. this.faceVertexUvs[ 0 ].push( uvgen.generateTopUV( this, a, b, c ) );
  21735. }
  21736. };
  21737. // File:src/extras/geometries/LatheGeometry.js
  21738. /**
  21739. * @author astrodud / http://astrodud.isgreat.org/
  21740. * @author zz85 / https://github.com/zz85
  21741. * @author bhouston / http://clara.io
  21742. */
  21743. // points - to create a closed torus, one must use a set of points
  21744. // like so: [ a, b, c, d, a ], see first is the same as last.
  21745. // segments - the number of circumference segments to create
  21746. // phiStart - the starting radian
  21747. // phiLength - the radian (0 to 2*PI) range of the lathed section
  21748. // 2*pi is a closed lathe, less than 2PI is a portion.
  21749. THREE.LatheGeometry = function ( points, segments, phiStart, phiLength ) {
  21750. THREE.Geometry.call( this );
  21751. this.type = 'LatheGeometry';
  21752. this.parameters = {
  21753. points: points,
  21754. segments: segments,
  21755. phiStart: phiStart,
  21756. phiLength: phiLength
  21757. };
  21758. segments = segments || 12;
  21759. phiStart = phiStart || 0;
  21760. phiLength = phiLength || 2 * Math.PI;
  21761. var inversePointLength = 1.0 / ( points.length - 1 );
  21762. var inverseSegments = 1.0 / segments;
  21763. for ( var i = 0, il = segments; i <= il; i ++ ) {
  21764. var phi = phiStart + i * inverseSegments * phiLength;
  21765. var c = Math.cos( phi ),
  21766. s = Math.sin( phi );
  21767. for ( var j = 0, jl = points.length; j < jl; j ++ ) {
  21768. var pt = points[ j ];
  21769. var vertex = new THREE.Vector3();
  21770. vertex.x = c * pt.x - s * pt.y;
  21771. vertex.y = s * pt.x + c * pt.y;
  21772. vertex.z = pt.z;
  21773. this.vertices.push( vertex );
  21774. }
  21775. }
  21776. var np = points.length;
  21777. for ( var i = 0, il = segments; i < il; i ++ ) {
  21778. for ( var j = 0, jl = points.length - 1; j < jl; j ++ ) {
  21779. var base = j + np * i;
  21780. var a = base;
  21781. var b = base + np;
  21782. var c = base + 1 + np;
  21783. var d = base + 1;
  21784. var u0 = i * inverseSegments;
  21785. var v0 = j * inversePointLength;
  21786. var u1 = u0 + inverseSegments;
  21787. var v1 = v0 + inversePointLength;
  21788. this.faces.push( new THREE.Face3( a, b, d ) );
  21789. this.faceVertexUvs[ 0 ].push( [
  21790. new THREE.Vector2( u0, v0 ),
  21791. new THREE.Vector2( u1, v0 ),
  21792. new THREE.Vector2( u0, v1 )
  21793. ] );
  21794. this.faces.push( new THREE.Face3( b, c, d ) );
  21795. this.faceVertexUvs[ 0 ].push( [
  21796. new THREE.Vector2( u1, v0 ),
  21797. new THREE.Vector2( u1, v1 ),
  21798. new THREE.Vector2( u0, v1 )
  21799. ] );
  21800. }
  21801. }
  21802. this.mergeVertices();
  21803. this.computeFaceNormals();
  21804. this.computeVertexNormals();
  21805. };
  21806. THREE.LatheGeometry.prototype = Object.create( THREE.Geometry.prototype );
  21807. THREE.LatheGeometry.prototype.constructor = THREE.LatheGeometry;
  21808. // File:src/extras/geometries/PlaneGeometry.js
  21809. /**
  21810. * @author mrdoob / http://mrdoob.com/
  21811. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
  21812. */
  21813. THREE.PlaneGeometry = function ( width, height, widthSegments, heightSegments ) {
  21814. THREE.Geometry.call( this );
  21815. this.type = 'PlaneGeometry';
  21816. this.parameters = {
  21817. width: width,
  21818. height: height,
  21819. widthSegments: widthSegments,
  21820. heightSegments: heightSegments
  21821. };
  21822. this.fromBufferGeometry( new THREE.PlaneBufferGeometry( width, height, widthSegments, heightSegments ) );
  21823. };
  21824. THREE.PlaneGeometry.prototype = Object.create( THREE.Geometry.prototype );
  21825. THREE.PlaneGeometry.prototype.constructor = THREE.PlaneGeometry;
  21826. // File:src/extras/geometries/PlaneBufferGeometry.js
  21827. /**
  21828. * @author mrdoob / http://mrdoob.com/
  21829. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
  21830. */
  21831. THREE.PlaneBufferGeometry = function ( width, height, widthSegments, heightSegments ) {
  21832. THREE.BufferGeometry.call( this );
  21833. this.type = 'PlaneBufferGeometry';
  21834. this.parameters = {
  21835. width: width,
  21836. height: height,
  21837. widthSegments: widthSegments,
  21838. heightSegments: heightSegments
  21839. };
  21840. var width_half = width / 2;
  21841. var height_half = height / 2;
  21842. var gridX = Math.floor( widthSegments ) || 1;
  21843. var gridY = Math.floor( heightSegments ) || 1;
  21844. var gridX1 = gridX + 1;
  21845. var gridY1 = gridY + 1;
  21846. var segment_width = width / gridX;
  21847. var segment_height = height / gridY;
  21848. var vertices = new Float32Array( gridX1 * gridY1 * 3 );
  21849. var normals = new Float32Array( gridX1 * gridY1 * 3 );
  21850. var uvs = new Float32Array( gridX1 * gridY1 * 2 );
  21851. var offset = 0;
  21852. var offset2 = 0;
  21853. for ( var iy = 0; iy < gridY1; iy ++ ) {
  21854. var y = iy * segment_height - height_half;
  21855. for ( var ix = 0; ix < gridX1; ix ++ ) {
  21856. var x = ix * segment_width - width_half;
  21857. vertices[ offset ] = x;
  21858. vertices[ offset + 1 ] = - y;
  21859. normals[ offset + 2 ] = 1;
  21860. uvs[ offset2 ] = ix / gridX;
  21861. uvs[ offset2 + 1 ] = 1 - ( iy / gridY );
  21862. offset += 3;
  21863. offset2 += 2;
  21864. }
  21865. }
  21866. offset = 0;
  21867. var indices = new ( ( vertices.length / 3 ) > 65535 ? Uint32Array : Uint16Array )( gridX * gridY * 6 );
  21868. for ( var iy = 0; iy < gridY; iy ++ ) {
  21869. for ( var ix = 0; ix < gridX; ix ++ ) {
  21870. var a = ix + gridX1 * iy;
  21871. var b = ix + gridX1 * ( iy + 1 );
  21872. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  21873. var d = ( ix + 1 ) + gridX1 * iy;
  21874. indices[ offset ] = a;
  21875. indices[ offset + 1 ] = b;
  21876. indices[ offset + 2 ] = d;
  21877. indices[ offset + 3 ] = b;
  21878. indices[ offset + 4 ] = c;
  21879. indices[ offset + 5 ] = d;
  21880. offset += 6;
  21881. }
  21882. }
  21883. this.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  21884. this.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  21885. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  21886. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  21887. };
  21888. THREE.PlaneBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  21889. THREE.PlaneBufferGeometry.prototype.constructor = THREE.PlaneBufferGeometry;
  21890. // File:src/extras/geometries/RingGeometry.js
  21891. /**
  21892. * @author Kaleb Murphy
  21893. */
  21894. THREE.RingGeometry = function ( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  21895. THREE.Geometry.call( this );
  21896. this.type = 'RingGeometry';
  21897. this.parameters = {
  21898. innerRadius: innerRadius,
  21899. outerRadius: outerRadius,
  21900. thetaSegments: thetaSegments,
  21901. phiSegments: phiSegments,
  21902. thetaStart: thetaStart,
  21903. thetaLength: thetaLength
  21904. };
  21905. innerRadius = innerRadius || 0;
  21906. outerRadius = outerRadius || 50;
  21907. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  21908. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  21909. thetaSegments = thetaSegments !== undefined ? Math.max( 3, thetaSegments ) : 8;
  21910. phiSegments = phiSegments !== undefined ? Math.max( 1, phiSegments ) : 8;
  21911. var i, o, uvs = [], radius = innerRadius, radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  21912. for ( i = 0; i < phiSegments + 1; i ++ ) {
  21913. // concentric circles inside ring
  21914. for ( o = 0; o < thetaSegments + 1; o ++ ) {
  21915. // number of segments per circle
  21916. var vertex = new THREE.Vector3();
  21917. var segment = thetaStart + o / thetaSegments * thetaLength;
  21918. vertex.x = radius * Math.cos( segment );
  21919. vertex.y = radius * Math.sin( segment );
  21920. this.vertices.push( vertex );
  21921. uvs.push( new THREE.Vector2( ( vertex.x / outerRadius + 1 ) / 2, ( vertex.y / outerRadius + 1 ) / 2 ) );
  21922. }
  21923. radius += radiusStep;
  21924. }
  21925. var n = new THREE.Vector3( 0, 0, 1 );
  21926. for ( i = 0; i < phiSegments; i ++ ) {
  21927. // concentric circles inside ring
  21928. var thetaSegment = i * ( thetaSegments + 1 );
  21929. for ( o = 0; o < thetaSegments ; o ++ ) {
  21930. // number of segments per circle
  21931. var segment = o + thetaSegment;
  21932. var v1 = segment;
  21933. var v2 = segment + thetaSegments + 1;
  21934. var v3 = segment + thetaSegments + 2;
  21935. this.faces.push( new THREE.Face3( v1, v2, v3, [ n.clone(), n.clone(), n.clone() ] ) );
  21936. this.faceVertexUvs[ 0 ].push( [ uvs[ v1 ].clone(), uvs[ v2 ].clone(), uvs[ v3 ].clone() ] );
  21937. v1 = segment;
  21938. v2 = segment + thetaSegments + 2;
  21939. v3 = segment + 1;
  21940. this.faces.push( new THREE.Face3( v1, v2, v3, [ n.clone(), n.clone(), n.clone() ] ) );
  21941. this.faceVertexUvs[ 0 ].push( [ uvs[ v1 ].clone(), uvs[ v2 ].clone(), uvs[ v3 ].clone() ] );
  21942. }
  21943. }
  21944. this.computeFaceNormals();
  21945. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  21946. };
  21947. THREE.RingGeometry.prototype = Object.create( THREE.Geometry.prototype );
  21948. THREE.RingGeometry.prototype.constructor = THREE.RingGeometry;
  21949. // File:src/extras/geometries/SphereGeometry.js
  21950. /**
  21951. * @author mrdoob / http://mrdoob.com/
  21952. */
  21953. THREE.SphereGeometry = function ( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  21954. THREE.Geometry.call( this );
  21955. this.type = 'SphereGeometry';
  21956. this.parameters = {
  21957. radius: radius,
  21958. widthSegments: widthSegments,
  21959. heightSegments: heightSegments,
  21960. phiStart: phiStart,
  21961. phiLength: phiLength,
  21962. thetaStart: thetaStart,
  21963. thetaLength: thetaLength
  21964. };
  21965. this.fromBufferGeometry( new THREE.SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) );
  21966. };
  21967. THREE.SphereGeometry.prototype = Object.create( THREE.Geometry.prototype );
  21968. THREE.SphereGeometry.prototype.constructor = THREE.SphereGeometry;
  21969. // File:src/extras/geometries/SphereBufferGeometry.js
  21970. /**
  21971. * @author benaadams / https://twitter.com/ben_a_adams
  21972. * based on THREE.SphereGeometry
  21973. */
  21974. THREE.SphereBufferGeometry = function ( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  21975. THREE.BufferGeometry.call( this );
  21976. this.type = 'SphereBufferGeometry';
  21977. this.parameters = {
  21978. radius: radius,
  21979. widthSegments: widthSegments,
  21980. heightSegments: heightSegments,
  21981. phiStart: phiStart,
  21982. phiLength: phiLength,
  21983. thetaStart: thetaStart,
  21984. thetaLength: thetaLength
  21985. };
  21986. radius = radius || 50;
  21987. widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
  21988. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  21989. phiStart = phiStart !== undefined ? phiStart : 0;
  21990. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  21991. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  21992. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  21993. var thetaEnd = thetaStart + thetaLength;
  21994. var vertexCount = ( ( widthSegments + 1 ) * ( heightSegments + 1 ) );
  21995. var positions = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  21996. var normals = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  21997. var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
  21998. var index = 0, vertices = [], normal = new THREE.Vector3();
  21999. for ( var y = 0; y <= heightSegments; y ++ ) {
  22000. var verticesRow = [];
  22001. var v = y / heightSegments;
  22002. for ( var x = 0; x <= widthSegments; x ++ ) {
  22003. var u = x / widthSegments;
  22004. var px = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  22005. var py = radius * Math.cos( thetaStart + v * thetaLength );
  22006. var pz = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  22007. normal.set( px, py, pz ).normalize();
  22008. positions.setXYZ( index, px, py, pz );
  22009. normals.setXYZ( index, normal.x, normal.y, normal.z );
  22010. uvs.setXY( index, u, 1 - v );
  22011. verticesRow.push( index );
  22012. index ++;
  22013. }
  22014. vertices.push( verticesRow );
  22015. }
  22016. var indices = [];
  22017. for ( var y = 0; y < heightSegments; y ++ ) {
  22018. for ( var x = 0; x < widthSegments; x ++ ) {
  22019. var v1 = vertices[ y ][ x + 1 ];
  22020. var v2 = vertices[ y ][ x ];
  22021. var v3 = vertices[ y + 1 ][ x ];
  22022. var v4 = vertices[ y + 1 ][ x + 1 ];
  22023. if ( y !== 0 || thetaStart > 0 ) indices.push( v1, v2, v4 );
  22024. if ( y !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( v2, v3, v4 );
  22025. }
  22026. }
  22027. this.setIndex( new ( positions.count > 65535 ? THREE.Uint32Attribute : THREE.Uint16Attribute )( indices, 1 ) );
  22028. this.addAttribute( 'position', positions );
  22029. this.addAttribute( 'normal', normals );
  22030. this.addAttribute( 'uv', uvs );
  22031. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  22032. };
  22033. THREE.SphereBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  22034. THREE.SphereBufferGeometry.prototype.constructor = THREE.SphereBufferGeometry;
  22035. // File:src/extras/geometries/TorusGeometry.js
  22036. /**
  22037. * @author oosmoxiecode
  22038. * @author mrdoob / http://mrdoob.com/
  22039. * based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3DLite/src/away3dlite/primitives/Torus.as?r=2888
  22040. */
  22041. THREE.TorusGeometry = function ( radius, tube, radialSegments, tubularSegments, arc ) {
  22042. THREE.Geometry.call( this );
  22043. this.type = 'TorusGeometry';
  22044. this.parameters = {
  22045. radius: radius,
  22046. tube: tube,
  22047. radialSegments: radialSegments,
  22048. tubularSegments: tubularSegments,
  22049. arc: arc
  22050. };
  22051. radius = radius || 100;
  22052. tube = tube || 40;
  22053. radialSegments = radialSegments || 8;
  22054. tubularSegments = tubularSegments || 6;
  22055. arc = arc || Math.PI * 2;
  22056. var center = new THREE.Vector3(), uvs = [], normals = [];
  22057. for ( var j = 0; j <= radialSegments; j ++ ) {
  22058. for ( var i = 0; i <= tubularSegments; i ++ ) {
  22059. var u = i / tubularSegments * arc;
  22060. var v = j / radialSegments * Math.PI * 2;
  22061. center.x = radius * Math.cos( u );
  22062. center.y = radius * Math.sin( u );
  22063. var vertex = new THREE.Vector3();
  22064. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  22065. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  22066. vertex.z = tube * Math.sin( v );
  22067. this.vertices.push( vertex );
  22068. uvs.push( new THREE.Vector2( i / tubularSegments, j / radialSegments ) );
  22069. normals.push( vertex.clone().sub( center ).normalize() );
  22070. }
  22071. }
  22072. for ( var j = 1; j <= radialSegments; j ++ ) {
  22073. for ( var i = 1; i <= tubularSegments; i ++ ) {
  22074. var a = ( tubularSegments + 1 ) * j + i - 1;
  22075. var b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  22076. var c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  22077. var d = ( tubularSegments + 1 ) * j + i;
  22078. var face = new THREE.Face3( a, b, d, [ normals[ a ].clone(), normals[ b ].clone(), normals[ d ].clone() ] );
  22079. this.faces.push( face );
  22080. this.faceVertexUvs[ 0 ].push( [ uvs[ a ].clone(), uvs[ b ].clone(), uvs[ d ].clone() ] );
  22081. face = new THREE.Face3( b, c, d, [ normals[ b ].clone(), normals[ c ].clone(), normals[ d ].clone() ] );
  22082. this.faces.push( face );
  22083. this.faceVertexUvs[ 0 ].push( [ uvs[ b ].clone(), uvs[ c ].clone(), uvs[ d ].clone() ] );
  22084. }
  22085. }
  22086. this.computeFaceNormals();
  22087. };
  22088. THREE.TorusGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22089. THREE.TorusGeometry.prototype.constructor = THREE.TorusGeometry;
  22090. // File:src/extras/geometries/TorusKnotGeometry.js
  22091. /**
  22092. * @author oosmoxiecode
  22093. * based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3D/src/away3d/primitives/TorusKnot.as?spec=svn2473&r=2473
  22094. */
  22095. THREE.TorusKnotGeometry = function ( radius, tube, radialSegments, tubularSegments, p, q, heightScale ) {
  22096. THREE.Geometry.call( this );
  22097. this.type = 'TorusKnotGeometry';
  22098. this.parameters = {
  22099. radius: radius,
  22100. tube: tube,
  22101. radialSegments: radialSegments,
  22102. tubularSegments: tubularSegments,
  22103. p: p,
  22104. q: q,
  22105. heightScale: heightScale
  22106. };
  22107. radius = radius || 100;
  22108. tube = tube || 40;
  22109. radialSegments = radialSegments || 64;
  22110. tubularSegments = tubularSegments || 8;
  22111. p = p || 2;
  22112. q = q || 3;
  22113. heightScale = heightScale || 1;
  22114. var grid = new Array( radialSegments );
  22115. var tang = new THREE.Vector3();
  22116. var n = new THREE.Vector3();
  22117. var bitan = new THREE.Vector3();
  22118. for ( var i = 0; i < radialSegments; ++ i ) {
  22119. grid[ i ] = new Array( tubularSegments );
  22120. var u = i / radialSegments * 2 * p * Math.PI;
  22121. var p1 = getPos( u, q, p, radius, heightScale );
  22122. var p2 = getPos( u + 0.01, q, p, radius, heightScale );
  22123. tang.subVectors( p2, p1 );
  22124. n.addVectors( p2, p1 );
  22125. bitan.crossVectors( tang, n );
  22126. n.crossVectors( bitan, tang );
  22127. bitan.normalize();
  22128. n.normalize();
  22129. for ( var j = 0; j < tubularSegments; ++ j ) {
  22130. var v = j / tubularSegments * 2 * Math.PI;
  22131. var cx = - tube * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
  22132. var cy = tube * Math.sin( v );
  22133. var pos = new THREE.Vector3();
  22134. pos.x = p1.x + cx * n.x + cy * bitan.x;
  22135. pos.y = p1.y + cx * n.y + cy * bitan.y;
  22136. pos.z = p1.z + cx * n.z + cy * bitan.z;
  22137. grid[ i ][ j ] = this.vertices.push( pos ) - 1;
  22138. }
  22139. }
  22140. for ( var i = 0; i < radialSegments; ++ i ) {
  22141. for ( var j = 0; j < tubularSegments; ++ j ) {
  22142. var ip = ( i + 1 ) % radialSegments;
  22143. var jp = ( j + 1 ) % tubularSegments;
  22144. var a = grid[ i ][ j ];
  22145. var b = grid[ ip ][ j ];
  22146. var c = grid[ ip ][ jp ];
  22147. var d = grid[ i ][ jp ];
  22148. var uva = new THREE.Vector2( i / radialSegments, j / tubularSegments );
  22149. var uvb = new THREE.Vector2( ( i + 1 ) / radialSegments, j / tubularSegments );
  22150. var uvc = new THREE.Vector2( ( i + 1 ) / radialSegments, ( j + 1 ) / tubularSegments );
  22151. var uvd = new THREE.Vector2( i / radialSegments, ( j + 1 ) / tubularSegments );
  22152. this.faces.push( new THREE.Face3( a, b, d ) );
  22153. this.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  22154. this.faces.push( new THREE.Face3( b, c, d ) );
  22155. this.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  22156. }
  22157. }
  22158. this.computeFaceNormals();
  22159. this.computeVertexNormals();
  22160. function getPos( u, in_q, in_p, radius, heightScale ) {
  22161. var cu = Math.cos( u );
  22162. var su = Math.sin( u );
  22163. var quOverP = in_q / in_p * u;
  22164. var cs = Math.cos( quOverP );
  22165. var tx = radius * ( 2 + cs ) * 0.5 * cu;
  22166. var ty = radius * ( 2 + cs ) * su * 0.5;
  22167. var tz = heightScale * radius * Math.sin( quOverP ) * 0.5;
  22168. return new THREE.Vector3( tx, ty, tz );
  22169. }
  22170. };
  22171. THREE.TorusKnotGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22172. THREE.TorusKnotGeometry.prototype.constructor = THREE.TorusKnotGeometry;
  22173. // File:src/extras/geometries/TubeGeometry.js
  22174. /**
  22175. * @author WestLangley / https://github.com/WestLangley
  22176. * @author zz85 / https://github.com/zz85
  22177. * @author miningold / https://github.com/miningold
  22178. * @author jonobr1 / https://github.com/jonobr1
  22179. *
  22180. * Modified from the TorusKnotGeometry by @oosmoxiecode
  22181. *
  22182. * Creates a tube which extrudes along a 3d spline
  22183. *
  22184. * Uses parallel transport frames as described in
  22185. * http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  22186. */
  22187. THREE.TubeGeometry = function ( path, segments, radius, radialSegments, closed, taper ) {
  22188. THREE.Geometry.call( this );
  22189. this.type = 'TubeGeometry';
  22190. this.parameters = {
  22191. path: path,
  22192. segments: segments,
  22193. radius: radius,
  22194. radialSegments: radialSegments,
  22195. closed: closed,
  22196. taper: taper
  22197. };
  22198. segments = segments || 64;
  22199. radius = radius || 1;
  22200. radialSegments = radialSegments || 8;
  22201. closed = closed || false;
  22202. taper = taper || THREE.TubeGeometry.NoTaper;
  22203. var grid = [];
  22204. var scope = this,
  22205. tangent,
  22206. normal,
  22207. binormal,
  22208. numpoints = segments + 1,
  22209. u, v, r,
  22210. cx, cy,
  22211. pos, pos2 = new THREE.Vector3(),
  22212. i, j,
  22213. ip, jp,
  22214. a, b, c, d,
  22215. uva, uvb, uvc, uvd;
  22216. var frames = new THREE.TubeGeometry.FrenetFrames( path, segments, closed ),
  22217. tangents = frames.tangents,
  22218. normals = frames.normals,
  22219. binormals = frames.binormals;
  22220. // proxy internals
  22221. this.tangents = tangents;
  22222. this.normals = normals;
  22223. this.binormals = binormals;
  22224. function vert( x, y, z ) {
  22225. return scope.vertices.push( new THREE.Vector3( x, y, z ) ) - 1;
  22226. }
  22227. // construct the grid
  22228. for ( i = 0; i < numpoints; i ++ ) {
  22229. grid[ i ] = [];
  22230. u = i / ( numpoints - 1 );
  22231. pos = path.getPointAt( u );
  22232. tangent = tangents[ i ];
  22233. normal = normals[ i ];
  22234. binormal = binormals[ i ];
  22235. r = radius * taper( u );
  22236. for ( j = 0; j < radialSegments; j ++ ) {
  22237. v = j / radialSegments * 2 * Math.PI;
  22238. cx = - r * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
  22239. cy = r * Math.sin( v );
  22240. pos2.copy( pos );
  22241. pos2.x += cx * normal.x + cy * binormal.x;
  22242. pos2.y += cx * normal.y + cy * binormal.y;
  22243. pos2.z += cx * normal.z + cy * binormal.z;
  22244. grid[ i ][ j ] = vert( pos2.x, pos2.y, pos2.z );
  22245. }
  22246. }
  22247. // construct the mesh
  22248. for ( i = 0; i < segments; i ++ ) {
  22249. for ( j = 0; j < radialSegments; j ++ ) {
  22250. ip = ( closed ) ? ( i + 1 ) % segments : i + 1;
  22251. jp = ( j + 1 ) % radialSegments;
  22252. a = grid[ i ][ j ]; // *** NOT NECESSARILY PLANAR ! ***
  22253. b = grid[ ip ][ j ];
  22254. c = grid[ ip ][ jp ];
  22255. d = grid[ i ][ jp ];
  22256. uva = new THREE.Vector2( i / segments, j / radialSegments );
  22257. uvb = new THREE.Vector2( ( i + 1 ) / segments, j / radialSegments );
  22258. uvc = new THREE.Vector2( ( i + 1 ) / segments, ( j + 1 ) / radialSegments );
  22259. uvd = new THREE.Vector2( i / segments, ( j + 1 ) / radialSegments );
  22260. this.faces.push( new THREE.Face3( a, b, d ) );
  22261. this.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  22262. this.faces.push( new THREE.Face3( b, c, d ) );
  22263. this.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  22264. }
  22265. }
  22266. this.computeFaceNormals();
  22267. this.computeVertexNormals();
  22268. };
  22269. THREE.TubeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22270. THREE.TubeGeometry.prototype.constructor = THREE.TubeGeometry;
  22271. THREE.TubeGeometry.NoTaper = function ( u ) {
  22272. return 1;
  22273. };
  22274. THREE.TubeGeometry.SinusoidalTaper = function ( u ) {
  22275. return Math.sin( Math.PI * u );
  22276. };
  22277. // For computing of Frenet frames, exposing the tangents, normals and binormals the spline
  22278. THREE.TubeGeometry.FrenetFrames = function ( path, segments, closed ) {
  22279. var normal = new THREE.Vector3(),
  22280. tangents = [],
  22281. normals = [],
  22282. binormals = [],
  22283. vec = new THREE.Vector3(),
  22284. mat = new THREE.Matrix4(),
  22285. numpoints = segments + 1,
  22286. theta,
  22287. smallest,
  22288. tx, ty, tz,
  22289. i, u;
  22290. // expose internals
  22291. this.tangents = tangents;
  22292. this.normals = normals;
  22293. this.binormals = binormals;
  22294. // compute the tangent vectors for each segment on the path
  22295. for ( i = 0; i < numpoints; i ++ ) {
  22296. u = i / ( numpoints - 1 );
  22297. tangents[ i ] = path.getTangentAt( u );
  22298. tangents[ i ].normalize();
  22299. }
  22300. initialNormal3();
  22301. /*
  22302. function initialNormal1(lastBinormal) {
  22303. // fixed start binormal. Has dangers of 0 vectors
  22304. normals[ 0 ] = new THREE.Vector3();
  22305. binormals[ 0 ] = new THREE.Vector3();
  22306. if (lastBinormal===undefined) lastBinormal = new THREE.Vector3( 0, 0, 1 );
  22307. normals[ 0 ].crossVectors( lastBinormal, tangents[ 0 ] ).normalize();
  22308. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] ).normalize();
  22309. }
  22310. function initialNormal2() {
  22311. // This uses the Frenet-Serret formula for deriving binormal
  22312. var t2 = path.getTangentAt( epsilon );
  22313. normals[ 0 ] = new THREE.Vector3().subVectors( t2, tangents[ 0 ] ).normalize();
  22314. binormals[ 0 ] = new THREE.Vector3().crossVectors( tangents[ 0 ], normals[ 0 ] );
  22315. normals[ 0 ].crossVectors( binormals[ 0 ], tangents[ 0 ] ).normalize(); // last binormal x tangent
  22316. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] ).normalize();
  22317. }
  22318. */
  22319. function initialNormal3() {
  22320. // select an initial normal vector perpendicular to the first tangent vector,
  22321. // and in the direction of the smallest tangent xyz component
  22322. normals[ 0 ] = new THREE.Vector3();
  22323. binormals[ 0 ] = new THREE.Vector3();
  22324. smallest = Number.MAX_VALUE;
  22325. tx = Math.abs( tangents[ 0 ].x );
  22326. ty = Math.abs( tangents[ 0 ].y );
  22327. tz = Math.abs( tangents[ 0 ].z );
  22328. if ( tx <= smallest ) {
  22329. smallest = tx;
  22330. normal.set( 1, 0, 0 );
  22331. }
  22332. if ( ty <= smallest ) {
  22333. smallest = ty;
  22334. normal.set( 0, 1, 0 );
  22335. }
  22336. if ( tz <= smallest ) {
  22337. normal.set( 0, 0, 1 );
  22338. }
  22339. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  22340. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  22341. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  22342. }
  22343. // compute the slowly-varying normal and binormal vectors for each segment on the path
  22344. for ( i = 1; i < numpoints; i ++ ) {
  22345. normals[ i ] = normals[ i - 1 ].clone();
  22346. binormals[ i ] = binormals[ i - 1 ].clone();
  22347. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  22348. if ( vec.length() > Number.EPSILON ) {
  22349. vec.normalize();
  22350. theta = Math.acos( THREE.Math.clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  22351. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  22352. }
  22353. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  22354. }
  22355. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  22356. if ( closed ) {
  22357. theta = Math.acos( THREE.Math.clamp( normals[ 0 ].dot( normals[ numpoints - 1 ] ), - 1, 1 ) );
  22358. theta /= ( numpoints - 1 );
  22359. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ numpoints - 1 ] ) ) > 0 ) {
  22360. theta = - theta;
  22361. }
  22362. for ( i = 1; i < numpoints; i ++ ) {
  22363. // twist a little...
  22364. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  22365. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  22366. }
  22367. }
  22368. };
  22369. // File:src/extras/geometries/PolyhedronGeometry.js
  22370. /**
  22371. * @author clockworkgeek / https://github.com/clockworkgeek
  22372. * @author timothypratley / https://github.com/timothypratley
  22373. * @author WestLangley / http://github.com/WestLangley
  22374. */
  22375. THREE.PolyhedronGeometry = function ( vertices, indices, radius, detail ) {
  22376. THREE.Geometry.call( this );
  22377. this.type = 'PolyhedronGeometry';
  22378. this.parameters = {
  22379. vertices: vertices,
  22380. indices: indices,
  22381. radius: radius,
  22382. detail: detail
  22383. };
  22384. radius = radius || 1;
  22385. detail = detail || 0;
  22386. var that = this;
  22387. for ( var i = 0, l = vertices.length; i < l; i += 3 ) {
  22388. prepare( new THREE.Vector3( vertices[ i ], vertices[ i + 1 ], vertices[ i + 2 ] ) );
  22389. }
  22390. var p = this.vertices;
  22391. var faces = [];
  22392. for ( var i = 0, j = 0, l = indices.length; i < l; i += 3, j ++ ) {
  22393. var v1 = p[ indices[ i ] ];
  22394. var v2 = p[ indices[ i + 1 ] ];
  22395. var v3 = p[ indices[ i + 2 ] ];
  22396. faces[ j ] = new THREE.Face3( v1.index, v2.index, v3.index, [ v1.clone(), v2.clone(), v3.clone() ], undefined, j );
  22397. }
  22398. var centroid = new THREE.Vector3();
  22399. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  22400. subdivide( faces[ i ], detail );
  22401. }
  22402. // Handle case when face straddles the seam
  22403. for ( var i = 0, l = this.faceVertexUvs[ 0 ].length; i < l; i ++ ) {
  22404. var uvs = this.faceVertexUvs[ 0 ][ i ];
  22405. var x0 = uvs[ 0 ].x;
  22406. var x1 = uvs[ 1 ].x;
  22407. var x2 = uvs[ 2 ].x;
  22408. var max = Math.max( x0, x1, x2 );
  22409. var min = Math.min( x0, x1, x2 );
  22410. if ( max > 0.9 && min < 0.1 ) {
  22411. // 0.9 is somewhat arbitrary
  22412. if ( x0 < 0.2 ) uvs[ 0 ].x += 1;
  22413. if ( x1 < 0.2 ) uvs[ 1 ].x += 1;
  22414. if ( x2 < 0.2 ) uvs[ 2 ].x += 1;
  22415. }
  22416. }
  22417. // Apply radius
  22418. for ( var i = 0, l = this.vertices.length; i < l; i ++ ) {
  22419. this.vertices[ i ].multiplyScalar( radius );
  22420. }
  22421. // Merge vertices
  22422. this.mergeVertices();
  22423. this.computeFaceNormals();
  22424. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  22425. // Project vector onto sphere's surface
  22426. function prepare( vector ) {
  22427. var vertex = vector.normalize().clone();
  22428. vertex.index = that.vertices.push( vertex ) - 1;
  22429. // Texture coords are equivalent to map coords, calculate angle and convert to fraction of a circle.
  22430. var u = azimuth( vector ) / 2 / Math.PI + 0.5;
  22431. var v = inclination( vector ) / Math.PI + 0.5;
  22432. vertex.uv = new THREE.Vector2( u, 1 - v );
  22433. return vertex;
  22434. }
  22435. // Approximate a curved face with recursively sub-divided triangles.
  22436. function make( v1, v2, v3, materialIndex ) {
  22437. var face = new THREE.Face3( v1.index, v2.index, v3.index, [ v1.clone(), v2.clone(), v3.clone() ], undefined, materialIndex );
  22438. that.faces.push( face );
  22439. centroid.copy( v1 ).add( v2 ).add( v3 ).divideScalar( 3 );
  22440. var azi = azimuth( centroid );
  22441. that.faceVertexUvs[ 0 ].push( [
  22442. correctUV( v1.uv, v1, azi ),
  22443. correctUV( v2.uv, v2, azi ),
  22444. correctUV( v3.uv, v3, azi )
  22445. ] );
  22446. }
  22447. // Analytically subdivide a face to the required detail level.
  22448. function subdivide( face, detail ) {
  22449. var cols = Math.pow( 2, detail );
  22450. var a = prepare( that.vertices[ face.a ] );
  22451. var b = prepare( that.vertices[ face.b ] );
  22452. var c = prepare( that.vertices[ face.c ] );
  22453. var v = [];
  22454. var materialIndex = face.materialIndex;
  22455. // Construct all of the vertices for this subdivision.
  22456. for ( var i = 0 ; i <= cols; i ++ ) {
  22457. v[ i ] = [];
  22458. var aj = prepare( a.clone().lerp( c, i / cols ) );
  22459. var bj = prepare( b.clone().lerp( c, i / cols ) );
  22460. var rows = cols - i;
  22461. for ( var j = 0; j <= rows; j ++ ) {
  22462. if ( j === 0 && i === cols ) {
  22463. v[ i ][ j ] = aj;
  22464. } else {
  22465. v[ i ][ j ] = prepare( aj.clone().lerp( bj, j / rows ) );
  22466. }
  22467. }
  22468. }
  22469. // Construct all of the faces.
  22470. for ( var i = 0; i < cols ; i ++ ) {
  22471. for ( var j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
  22472. var k = Math.floor( j / 2 );
  22473. if ( j % 2 === 0 ) {
  22474. make(
  22475. v[ i ][ k + 1 ],
  22476. v[ i + 1 ][ k ],
  22477. v[ i ][ k ],
  22478. materialIndex
  22479. );
  22480. } else {
  22481. make(
  22482. v[ i ][ k + 1 ],
  22483. v[ i + 1 ][ k + 1 ],
  22484. v[ i + 1 ][ k ],
  22485. materialIndex
  22486. );
  22487. }
  22488. }
  22489. }
  22490. }
  22491. // Angle around the Y axis, counter-clockwise when looking from above.
  22492. function azimuth( vector ) {
  22493. return Math.atan2( vector.z, - vector.x );
  22494. }
  22495. // Angle above the XZ plane.
  22496. function inclination( vector ) {
  22497. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  22498. }
  22499. // Texture fixing helper. Spheres have some odd behaviours.
  22500. function correctUV( uv, vector, azimuth ) {
  22501. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) uv = new THREE.Vector2( uv.x - 1, uv.y );
  22502. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) uv = new THREE.Vector2( azimuth / 2 / Math.PI + 0.5, uv.y );
  22503. return uv.clone();
  22504. }
  22505. };
  22506. THREE.PolyhedronGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22507. THREE.PolyhedronGeometry.prototype.constructor = THREE.PolyhedronGeometry;
  22508. // File:src/extras/geometries/DodecahedronGeometry.js
  22509. /**
  22510. * @author Abe Pazos / https://hamoid.com
  22511. */
  22512. THREE.DodecahedronGeometry = function ( radius, detail ) {
  22513. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  22514. var r = 1 / t;
  22515. var vertices = [
  22516. // (±1, ±1, ±1)
  22517. - 1, - 1, - 1, - 1, - 1, 1,
  22518. - 1, 1, - 1, - 1, 1, 1,
  22519. 1, - 1, - 1, 1, - 1, 1,
  22520. 1, 1, - 1, 1, 1, 1,
  22521. // (0, ±1/φ, ±φ)
  22522. 0, - r, - t, 0, - r, t,
  22523. 0, r, - t, 0, r, t,
  22524. // (±1/φ, ±φ, 0)
  22525. - r, - t, 0, - r, t, 0,
  22526. r, - t, 0, r, t, 0,
  22527. // (±φ, 0, ±1/φ)
  22528. - t, 0, - r, t, 0, - r,
  22529. - t, 0, r, t, 0, r
  22530. ];
  22531. var indices = [
  22532. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  22533. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  22534. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  22535. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  22536. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  22537. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  22538. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  22539. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  22540. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  22541. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  22542. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  22543. 1, 12, 14, 1, 14, 5, 1, 5, 9
  22544. ];
  22545. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  22546. this.type = 'DodecahedronGeometry';
  22547. this.parameters = {
  22548. radius: radius,
  22549. detail: detail
  22550. };
  22551. };
  22552. THREE.DodecahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  22553. THREE.DodecahedronGeometry.prototype.constructor = THREE.DodecahedronGeometry;
  22554. // File:src/extras/geometries/IcosahedronGeometry.js
  22555. /**
  22556. * @author timothypratley / https://github.com/timothypratley
  22557. */
  22558. THREE.IcosahedronGeometry = function ( radius, detail ) {
  22559. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  22560. var vertices = [
  22561. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  22562. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  22563. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  22564. ];
  22565. var indices = [
  22566. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  22567. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  22568. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  22569. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  22570. ];
  22571. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  22572. this.type = 'IcosahedronGeometry';
  22573. this.parameters = {
  22574. radius: radius,
  22575. detail: detail
  22576. };
  22577. };
  22578. THREE.IcosahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  22579. THREE.IcosahedronGeometry.prototype.constructor = THREE.IcosahedronGeometry;
  22580. // File:src/extras/geometries/OctahedronGeometry.js
  22581. /**
  22582. * @author timothypratley / https://github.com/timothypratley
  22583. */
  22584. THREE.OctahedronGeometry = function ( radius, detail ) {
  22585. var vertices = [
  22586. 1, 0, 0, - 1, 0, 0, 0, 1, 0, 0, - 1, 0, 0, 0, 1, 0, 0, - 1
  22587. ];
  22588. var indices = [
  22589. 0, 2, 4, 0, 4, 3, 0, 3, 5, 0, 5, 2, 1, 2, 5, 1, 5, 3, 1, 3, 4, 1, 4, 2
  22590. ];
  22591. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  22592. this.type = 'OctahedronGeometry';
  22593. this.parameters = {
  22594. radius: radius,
  22595. detail: detail
  22596. };
  22597. };
  22598. THREE.OctahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  22599. THREE.OctahedronGeometry.prototype.constructor = THREE.OctahedronGeometry;
  22600. // File:src/extras/geometries/TetrahedronGeometry.js
  22601. /**
  22602. * @author timothypratley / https://github.com/timothypratley
  22603. */
  22604. THREE.TetrahedronGeometry = function ( radius, detail ) {
  22605. var vertices = [
  22606. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  22607. ];
  22608. var indices = [
  22609. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  22610. ];
  22611. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  22612. this.type = 'TetrahedronGeometry';
  22613. this.parameters = {
  22614. radius: radius,
  22615. detail: detail
  22616. };
  22617. };
  22618. THREE.TetrahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  22619. THREE.TetrahedronGeometry.prototype.constructor = THREE.TetrahedronGeometry;
  22620. // File:src/extras/geometries/ParametricGeometry.js
  22621. /**
  22622. * @author zz85 / https://github.com/zz85
  22623. * Parametric Surfaces Geometry
  22624. * based on the brilliant article by @prideout http://prideout.net/blog/?p=44
  22625. *
  22626. * new THREE.ParametricGeometry( parametricFunction, uSegments, ySegements );
  22627. *
  22628. */
  22629. THREE.ParametricGeometry = function ( func, slices, stacks ) {
  22630. THREE.Geometry.call( this );
  22631. this.type = 'ParametricGeometry';
  22632. this.parameters = {
  22633. func: func,
  22634. slices: slices,
  22635. stacks: stacks
  22636. };
  22637. var verts = this.vertices;
  22638. var faces = this.faces;
  22639. var uvs = this.faceVertexUvs[ 0 ];
  22640. var i, j, p;
  22641. var u, v;
  22642. var sliceCount = slices + 1;
  22643. for ( i = 0; i <= stacks; i ++ ) {
  22644. v = i / stacks;
  22645. for ( j = 0; j <= slices; j ++ ) {
  22646. u = j / slices;
  22647. p = func( u, v );
  22648. verts.push( p );
  22649. }
  22650. }
  22651. var a, b, c, d;
  22652. var uva, uvb, uvc, uvd;
  22653. for ( i = 0; i < stacks; i ++ ) {
  22654. for ( j = 0; j < slices; j ++ ) {
  22655. a = i * sliceCount + j;
  22656. b = i * sliceCount + j + 1;
  22657. c = ( i + 1 ) * sliceCount + j + 1;
  22658. d = ( i + 1 ) * sliceCount + j;
  22659. uva = new THREE.Vector2( j / slices, i / stacks );
  22660. uvb = new THREE.Vector2( ( j + 1 ) / slices, i / stacks );
  22661. uvc = new THREE.Vector2( ( j + 1 ) / slices, ( i + 1 ) / stacks );
  22662. uvd = new THREE.Vector2( j / slices, ( i + 1 ) / stacks );
  22663. faces.push( new THREE.Face3( a, b, d ) );
  22664. uvs.push( [ uva, uvb, uvd ] );
  22665. faces.push( new THREE.Face3( b, c, d ) );
  22666. uvs.push( [ uvb.clone(), uvc, uvd.clone() ] );
  22667. }
  22668. }
  22669. // console.log(this);
  22670. // magic bullet
  22671. // var diff = this.mergeVertices();
  22672. // console.log('removed ', diff, ' vertices by merging');
  22673. this.computeFaceNormals();
  22674. this.computeVertexNormals();
  22675. };
  22676. THREE.ParametricGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22677. THREE.ParametricGeometry.prototype.constructor = THREE.ParametricGeometry;
  22678. // File:src/extras/geometries/WireframeGeometry.js
  22679. /**
  22680. * @author mrdoob / http://mrdoob.com/
  22681. */
  22682. THREE.WireframeGeometry = function ( geometry ) {
  22683. THREE.BufferGeometry.call( this );
  22684. var edge = [ 0, 0 ], hash = {};
  22685. function sortFunction( a, b ) {
  22686. return a - b;
  22687. }
  22688. var keys = [ 'a', 'b', 'c' ];
  22689. if ( geometry instanceof THREE.Geometry ) {
  22690. var vertices = geometry.vertices;
  22691. var faces = geometry.faces;
  22692. var numEdges = 0;
  22693. // allocate maximal size
  22694. var edges = new Uint32Array( 6 * faces.length );
  22695. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  22696. var face = faces[ i ];
  22697. for ( var j = 0; j < 3; j ++ ) {
  22698. edge[ 0 ] = face[ keys[ j ] ];
  22699. edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
  22700. edge.sort( sortFunction );
  22701. var key = edge.toString();
  22702. if ( hash[ key ] === undefined ) {
  22703. edges[ 2 * numEdges ] = edge[ 0 ];
  22704. edges[ 2 * numEdges + 1 ] = edge[ 1 ];
  22705. hash[ key ] = true;
  22706. numEdges ++;
  22707. }
  22708. }
  22709. }
  22710. var coords = new Float32Array( numEdges * 2 * 3 );
  22711. for ( var i = 0, l = numEdges; i < l; i ++ ) {
  22712. for ( var j = 0; j < 2; j ++ ) {
  22713. var vertex = vertices[ edges [ 2 * i + j ] ];
  22714. var index = 6 * i + 3 * j;
  22715. coords[ index + 0 ] = vertex.x;
  22716. coords[ index + 1 ] = vertex.y;
  22717. coords[ index + 2 ] = vertex.z;
  22718. }
  22719. }
  22720. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  22721. } else if ( geometry instanceof THREE.BufferGeometry ) {
  22722. if ( geometry.index !== null ) {
  22723. // Indexed BufferGeometry
  22724. var indices = geometry.index.array;
  22725. var vertices = geometry.attributes.position;
  22726. var drawcalls = geometry.drawcalls;
  22727. var numEdges = 0;
  22728. if ( drawcalls.length === 0 ) {
  22729. geometry.addGroup( 0, indices.length );
  22730. }
  22731. // allocate maximal size
  22732. var edges = new Uint32Array( 2 * indices.length );
  22733. for ( var o = 0, ol = drawcalls.length; o < ol; ++ o ) {
  22734. var drawcall = drawcalls[ o ];
  22735. var start = drawcall.start;
  22736. var count = drawcall.count;
  22737. for ( var i = start, il = start + count; i < il; i += 3 ) {
  22738. for ( var j = 0; j < 3; j ++ ) {
  22739. edge[ 0 ] = indices[ i + j ];
  22740. edge[ 1 ] = indices[ i + ( j + 1 ) % 3 ];
  22741. edge.sort( sortFunction );
  22742. var key = edge.toString();
  22743. if ( hash[ key ] === undefined ) {
  22744. edges[ 2 * numEdges ] = edge[ 0 ];
  22745. edges[ 2 * numEdges + 1 ] = edge[ 1 ];
  22746. hash[ key ] = true;
  22747. numEdges ++;
  22748. }
  22749. }
  22750. }
  22751. }
  22752. var coords = new Float32Array( numEdges * 2 * 3 );
  22753. for ( var i = 0, l = numEdges; i < l; i ++ ) {
  22754. for ( var j = 0; j < 2; j ++ ) {
  22755. var index = 6 * i + 3 * j;
  22756. var index2 = edges[ 2 * i + j ];
  22757. coords[ index + 0 ] = vertices.getX( index2 );
  22758. coords[ index + 1 ] = vertices.getY( index2 );
  22759. coords[ index + 2 ] = vertices.getZ( index2 );
  22760. }
  22761. }
  22762. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  22763. } else {
  22764. // non-indexed BufferGeometry
  22765. var vertices = geometry.attributes.position.array;
  22766. var numEdges = vertices.length / 3;
  22767. var numTris = numEdges / 3;
  22768. var coords = new Float32Array( numEdges * 2 * 3 );
  22769. for ( var i = 0, l = numTris; i < l; i ++ ) {
  22770. for ( var j = 0; j < 3; j ++ ) {
  22771. var index = 18 * i + 6 * j;
  22772. var index1 = 9 * i + 3 * j;
  22773. coords[ index + 0 ] = vertices[ index1 ];
  22774. coords[ index + 1 ] = vertices[ index1 + 1 ];
  22775. coords[ index + 2 ] = vertices[ index1 + 2 ];
  22776. var index2 = 9 * i + 3 * ( ( j + 1 ) % 3 );
  22777. coords[ index + 3 ] = vertices[ index2 ];
  22778. coords[ index + 4 ] = vertices[ index2 + 1 ];
  22779. coords[ index + 5 ] = vertices[ index2 + 2 ];
  22780. }
  22781. }
  22782. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  22783. }
  22784. }
  22785. };
  22786. THREE.WireframeGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  22787. THREE.WireframeGeometry.prototype.constructor = THREE.WireframeGeometry;
  22788. // File:src/extras/helpers/AxisHelper.js
  22789. /**
  22790. * @author sroucheray / http://sroucheray.org/
  22791. * @author mrdoob / http://mrdoob.com/
  22792. */
  22793. THREE.AxisHelper = function ( size ) {
  22794. size = size || 1;
  22795. var vertices = new Float32Array( [
  22796. 0, 0, 0, size, 0, 0,
  22797. 0, 0, 0, 0, size, 0,
  22798. 0, 0, 0, 0, 0, size
  22799. ] );
  22800. var colors = new Float32Array( [
  22801. 1, 0, 0, 1, 0.6, 0,
  22802. 0, 1, 0, 0.6, 1, 0,
  22803. 0, 0, 1, 0, 0.6, 1
  22804. ] );
  22805. var geometry = new THREE.BufferGeometry();
  22806. geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  22807. geometry.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ) );
  22808. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
  22809. THREE.LineSegments.call( this, geometry, material );
  22810. };
  22811. THREE.AxisHelper.prototype = Object.create( THREE.LineSegments.prototype );
  22812. THREE.AxisHelper.prototype.constructor = THREE.AxisHelper;
  22813. // File:src/extras/helpers/ArrowHelper.js
  22814. /**
  22815. * @author WestLangley / http://github.com/WestLangley
  22816. * @author zz85 / http://github.com/zz85
  22817. * @author bhouston / http://clara.io
  22818. *
  22819. * Creates an arrow for visualizing directions
  22820. *
  22821. * Parameters:
  22822. * dir - Vector3
  22823. * origin - Vector3
  22824. * length - Number
  22825. * color - color in hex value
  22826. * headLength - Number
  22827. * headWidth - Number
  22828. */
  22829. THREE.ArrowHelper = ( function () {
  22830. var lineGeometry = new THREE.Geometry();
  22831. lineGeometry.vertices.push( new THREE.Vector3( 0, 0, 0 ), new THREE.Vector3( 0, 1, 0 ) );
  22832. var coneGeometry = new THREE.CylinderGeometry( 0, 0.5, 1, 5, 1 );
  22833. coneGeometry.translate( 0, - 0.5, 0 );
  22834. return function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
  22835. // dir is assumed to be normalized
  22836. THREE.Object3D.call( this );
  22837. if ( color === undefined ) color = 0xffff00;
  22838. if ( length === undefined ) length = 1;
  22839. if ( headLength === undefined ) headLength = 0.2 * length;
  22840. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  22841. this.position.copy( origin );
  22842. this.line = new THREE.Line( lineGeometry, new THREE.LineBasicMaterial( { color: color } ) );
  22843. this.line.matrixAutoUpdate = false;
  22844. this.add( this.line );
  22845. this.cone = new THREE.Mesh( coneGeometry, new THREE.MeshBasicMaterial( { color: color } ) );
  22846. this.cone.matrixAutoUpdate = false;
  22847. this.add( this.cone );
  22848. this.setDirection( dir );
  22849. this.setLength( length, headLength, headWidth );
  22850. }
  22851. }() );
  22852. THREE.ArrowHelper.prototype = Object.create( THREE.Object3D.prototype );
  22853. THREE.ArrowHelper.prototype.constructor = THREE.ArrowHelper;
  22854. THREE.ArrowHelper.prototype.setDirection = ( function () {
  22855. var axis = new THREE.Vector3();
  22856. var radians;
  22857. return function setDirection( dir ) {
  22858. // dir is assumed to be normalized
  22859. if ( dir.y > 0.99999 ) {
  22860. this.quaternion.set( 0, 0, 0, 1 );
  22861. } else if ( dir.y < - 0.99999 ) {
  22862. this.quaternion.set( 1, 0, 0, 0 );
  22863. } else {
  22864. axis.set( dir.z, 0, - dir.x ).normalize();
  22865. radians = Math.acos( dir.y );
  22866. this.quaternion.setFromAxisAngle( axis, radians );
  22867. }
  22868. };
  22869. }() );
  22870. THREE.ArrowHelper.prototype.setLength = function ( length, headLength, headWidth ) {
  22871. if ( headLength === undefined ) headLength = 0.2 * length;
  22872. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  22873. this.line.scale.set( 1, Math.max( 0, length - headLength ), 1 );
  22874. this.line.updateMatrix();
  22875. this.cone.scale.set( headWidth, headLength, headWidth );
  22876. this.cone.position.y = length;
  22877. this.cone.updateMatrix();
  22878. };
  22879. THREE.ArrowHelper.prototype.setColor = function ( color ) {
  22880. this.line.material.color.set( color );
  22881. this.cone.material.color.set( color );
  22882. };
  22883. // File:src/extras/helpers/BoxHelper.js
  22884. /**
  22885. * @author mrdoob / http://mrdoob.com/
  22886. */
  22887. THREE.BoxHelper = function ( object ) {
  22888. 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 ] );
  22889. var positions = new Float32Array( 8 * 3 );
  22890. var geometry = new THREE.BufferGeometry();
  22891. geometry.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  22892. geometry.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
  22893. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: 0xffff00 } ) );
  22894. if ( object !== undefined ) {
  22895. this.update( object );
  22896. }
  22897. };
  22898. THREE.BoxHelper.prototype = Object.create( THREE.LineSegments.prototype );
  22899. THREE.BoxHelper.prototype.constructor = THREE.BoxHelper;
  22900. THREE.BoxHelper.prototype.update = ( function () {
  22901. var box = new THREE.Box3();
  22902. return function ( object ) {
  22903. box.setFromObject( object );
  22904. if ( box.empty() ) return;
  22905. var min = box.min;
  22906. var max = box.max;
  22907. /*
  22908. 5____4
  22909. 1/___0/|
  22910. | 6__|_7
  22911. 2/___3/
  22912. 0: max.x, max.y, max.z
  22913. 1: min.x, max.y, max.z
  22914. 2: min.x, min.y, max.z
  22915. 3: max.x, min.y, max.z
  22916. 4: max.x, max.y, min.z
  22917. 5: min.x, max.y, min.z
  22918. 6: min.x, min.y, min.z
  22919. 7: max.x, min.y, min.z
  22920. */
  22921. var position = this.geometry.attributes.position;
  22922. var array = position.array;
  22923. array[ 0 ] = max.x; array[ 1 ] = max.y; array[ 2 ] = max.z;
  22924. array[ 3 ] = min.x; array[ 4 ] = max.y; array[ 5 ] = max.z;
  22925. array[ 6 ] = min.x; array[ 7 ] = min.y; array[ 8 ] = max.z;
  22926. array[ 9 ] = max.x; array[ 10 ] = min.y; array[ 11 ] = max.z;
  22927. array[ 12 ] = max.x; array[ 13 ] = max.y; array[ 14 ] = min.z;
  22928. array[ 15 ] = min.x; array[ 16 ] = max.y; array[ 17 ] = min.z;
  22929. array[ 18 ] = min.x; array[ 19 ] = min.y; array[ 20 ] = min.z;
  22930. array[ 21 ] = max.x; array[ 22 ] = min.y; array[ 23 ] = min.z;
  22931. position.needsUpdate = true;
  22932. this.geometry.computeBoundingSphere();
  22933. }
  22934. } )();
  22935. // File:src/extras/helpers/BoundingBoxHelper.js
  22936. /**
  22937. * @author WestLangley / http://github.com/WestLangley
  22938. */
  22939. // a helper to show the world-axis-aligned bounding box for an object
  22940. THREE.BoundingBoxHelper = function ( object, hex ) {
  22941. var color = ( hex !== undefined ) ? hex : 0x888888;
  22942. this.object = object;
  22943. this.box = new THREE.Box3();
  22944. THREE.Mesh.call( this, new THREE.BoxGeometry( 1, 1, 1 ), new THREE.MeshBasicMaterial( { color: color, wireframe: true } ) );
  22945. };
  22946. THREE.BoundingBoxHelper.prototype = Object.create( THREE.Mesh.prototype );
  22947. THREE.BoundingBoxHelper.prototype.constructor = THREE.BoundingBoxHelper;
  22948. THREE.BoundingBoxHelper.prototype.update = function () {
  22949. this.box.setFromObject( this.object );
  22950. this.box.size( this.scale );
  22951. this.box.center( this.position );
  22952. };
  22953. // File:src/extras/helpers/CameraHelper.js
  22954. /**
  22955. * @author alteredq / http://alteredqualia.com/
  22956. *
  22957. * - shows frustum, line of sight and up of the camera
  22958. * - suitable for fast updates
  22959. * - based on frustum visualization in lightgl.js shadowmap example
  22960. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  22961. */
  22962. THREE.CameraHelper = function ( camera ) {
  22963. var geometry = new THREE.Geometry();
  22964. var material = new THREE.LineBasicMaterial( { color: 0xffffff, vertexColors: THREE.FaceColors } );
  22965. var pointMap = {};
  22966. // colors
  22967. var hexFrustum = 0xffaa00;
  22968. var hexCone = 0xff0000;
  22969. var hexUp = 0x00aaff;
  22970. var hexTarget = 0xffffff;
  22971. var hexCross = 0x333333;
  22972. // near
  22973. addLine( "n1", "n2", hexFrustum );
  22974. addLine( "n2", "n4", hexFrustum );
  22975. addLine( "n4", "n3", hexFrustum );
  22976. addLine( "n3", "n1", hexFrustum );
  22977. // far
  22978. addLine( "f1", "f2", hexFrustum );
  22979. addLine( "f2", "f4", hexFrustum );
  22980. addLine( "f4", "f3", hexFrustum );
  22981. addLine( "f3", "f1", hexFrustum );
  22982. // sides
  22983. addLine( "n1", "f1", hexFrustum );
  22984. addLine( "n2", "f2", hexFrustum );
  22985. addLine( "n3", "f3", hexFrustum );
  22986. addLine( "n4", "f4", hexFrustum );
  22987. // cone
  22988. addLine( "p", "n1", hexCone );
  22989. addLine( "p", "n2", hexCone );
  22990. addLine( "p", "n3", hexCone );
  22991. addLine( "p", "n4", hexCone );
  22992. // up
  22993. addLine( "u1", "u2", hexUp );
  22994. addLine( "u2", "u3", hexUp );
  22995. addLine( "u3", "u1", hexUp );
  22996. // target
  22997. addLine( "c", "t", hexTarget );
  22998. addLine( "p", "c", hexCross );
  22999. // cross
  23000. addLine( "cn1", "cn2", hexCross );
  23001. addLine( "cn3", "cn4", hexCross );
  23002. addLine( "cf1", "cf2", hexCross );
  23003. addLine( "cf3", "cf4", hexCross );
  23004. function addLine( a, b, hex ) {
  23005. addPoint( a, hex );
  23006. addPoint( b, hex );
  23007. }
  23008. function addPoint( id, hex ) {
  23009. geometry.vertices.push( new THREE.Vector3() );
  23010. geometry.colors.push( new THREE.Color( hex ) );
  23011. if ( pointMap[ id ] === undefined ) {
  23012. pointMap[ id ] = [];
  23013. }
  23014. pointMap[ id ].push( geometry.vertices.length - 1 );
  23015. }
  23016. THREE.LineSegments.call( this, geometry, material );
  23017. this.camera = camera;
  23018. this.camera.updateProjectionMatrix();
  23019. this.matrix = camera.matrixWorld;
  23020. this.matrixAutoUpdate = false;
  23021. this.pointMap = pointMap;
  23022. this.update();
  23023. };
  23024. THREE.CameraHelper.prototype = Object.create( THREE.LineSegments.prototype );
  23025. THREE.CameraHelper.prototype.constructor = THREE.CameraHelper;
  23026. THREE.CameraHelper.prototype.update = function () {
  23027. var geometry, pointMap;
  23028. var vector = new THREE.Vector3();
  23029. var camera = new THREE.Camera();
  23030. function setPoint( point, x, y, z ) {
  23031. vector.set( x, y, z ).unproject( camera );
  23032. var points = pointMap[ point ];
  23033. if ( points !== undefined ) {
  23034. for ( var i = 0, il = points.length; i < il; i ++ ) {
  23035. geometry.vertices[ points[ i ] ].copy( vector );
  23036. }
  23037. }
  23038. }
  23039. return function () {
  23040. geometry = this.geometry;
  23041. pointMap = this.pointMap;
  23042. var w = 1, h = 1;
  23043. // we need just camera projection matrix
  23044. // world matrix must be identity
  23045. camera.projectionMatrix.copy( this.camera.projectionMatrix );
  23046. // center / target
  23047. setPoint( "c", 0, 0, - 1 );
  23048. setPoint( "t", 0, 0, 1 );
  23049. // near
  23050. setPoint( "n1", - w, - h, - 1 );
  23051. setPoint( "n2", w, - h, - 1 );
  23052. setPoint( "n3", - w, h, - 1 );
  23053. setPoint( "n4", w, h, - 1 );
  23054. // far
  23055. setPoint( "f1", - w, - h, 1 );
  23056. setPoint( "f2", w, - h, 1 );
  23057. setPoint( "f3", - w, h, 1 );
  23058. setPoint( "f4", w, h, 1 );
  23059. // up
  23060. setPoint( "u1", w * 0.7, h * 1.1, - 1 );
  23061. setPoint( "u2", - w * 0.7, h * 1.1, - 1 );
  23062. setPoint( "u3", 0, h * 2, - 1 );
  23063. // cross
  23064. setPoint( "cf1", - w, 0, 1 );
  23065. setPoint( "cf2", w, 0, 1 );
  23066. setPoint( "cf3", 0, - h, 1 );
  23067. setPoint( "cf4", 0, h, 1 );
  23068. setPoint( "cn1", - w, 0, - 1 );
  23069. setPoint( "cn2", w, 0, - 1 );
  23070. setPoint( "cn3", 0, - h, - 1 );
  23071. setPoint( "cn4", 0, h, - 1 );
  23072. geometry.verticesNeedUpdate = true;
  23073. };
  23074. }();
  23075. // File:src/extras/helpers/DirectionalLightHelper.js
  23076. /**
  23077. * @author alteredq / http://alteredqualia.com/
  23078. * @author mrdoob / http://mrdoob.com/
  23079. * @author WestLangley / http://github.com/WestLangley
  23080. */
  23081. THREE.DirectionalLightHelper = function ( light, size ) {
  23082. THREE.Object3D.call( this );
  23083. this.light = light;
  23084. this.light.updateMatrixWorld();
  23085. this.matrix = light.matrixWorld;
  23086. this.matrixAutoUpdate = false;
  23087. size = size || 1;
  23088. var geometry = new THREE.Geometry();
  23089. geometry.vertices.push(
  23090. new THREE.Vector3( - size, size, 0 ),
  23091. new THREE.Vector3( size, size, 0 ),
  23092. new THREE.Vector3( size, - size, 0 ),
  23093. new THREE.Vector3( - size, - size, 0 ),
  23094. new THREE.Vector3( - size, size, 0 )
  23095. );
  23096. var material = new THREE.LineBasicMaterial( { fog: false } );
  23097. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  23098. this.lightPlane = new THREE.Line( geometry, material );
  23099. this.add( this.lightPlane );
  23100. geometry = new THREE.Geometry();
  23101. geometry.vertices.push(
  23102. new THREE.Vector3(),
  23103. new THREE.Vector3()
  23104. );
  23105. material = new THREE.LineBasicMaterial( { fog: false } );
  23106. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  23107. this.targetLine = new THREE.Line( geometry, material );
  23108. this.add( this.targetLine );
  23109. this.update();
  23110. };
  23111. THREE.DirectionalLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  23112. THREE.DirectionalLightHelper.prototype.constructor = THREE.DirectionalLightHelper;
  23113. THREE.DirectionalLightHelper.prototype.dispose = function () {
  23114. this.lightPlane.geometry.dispose();
  23115. this.lightPlane.material.dispose();
  23116. this.targetLine.geometry.dispose();
  23117. this.targetLine.material.dispose();
  23118. };
  23119. THREE.DirectionalLightHelper.prototype.update = function () {
  23120. var v1 = new THREE.Vector3();
  23121. var v2 = new THREE.Vector3();
  23122. var v3 = new THREE.Vector3();
  23123. return function () {
  23124. v1.setFromMatrixPosition( this.light.matrixWorld );
  23125. v2.setFromMatrixPosition( this.light.target.matrixWorld );
  23126. v3.subVectors( v2, v1 );
  23127. this.lightPlane.lookAt( v3 );
  23128. this.lightPlane.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  23129. this.targetLine.geometry.vertices[ 1 ].copy( v3 );
  23130. this.targetLine.geometry.verticesNeedUpdate = true;
  23131. this.targetLine.material.color.copy( this.lightPlane.material.color );
  23132. };
  23133. }();
  23134. // File:src/extras/helpers/EdgesHelper.js
  23135. /**
  23136. * @author WestLangley / http://github.com/WestLangley
  23137. * @param object THREE.Mesh whose geometry will be used
  23138. * @param hex line color
  23139. * @param thresholdAngle the minimum angle (in degrees),
  23140. * between the face normals of adjacent faces,
  23141. * that is required to render an edge. A value of 10 means
  23142. * an edge is only rendered if the angle is at least 10 degrees.
  23143. */
  23144. THREE.EdgesHelper = function ( object, hex, thresholdAngle ) {
  23145. var color = ( hex !== undefined ) ? hex : 0xffffff;
  23146. THREE.LineSegments.call( this, new THREE.EdgesGeometry( object.geometry, thresholdAngle ), new THREE.LineBasicMaterial( { color: color } ) );
  23147. this.matrix = object.matrixWorld;
  23148. this.matrixAutoUpdate = false;
  23149. };
  23150. THREE.EdgesHelper.prototype = Object.create( THREE.LineSegments.prototype );
  23151. THREE.EdgesHelper.prototype.constructor = THREE.EdgesHelper;
  23152. // File:src/extras/helpers/FaceNormalsHelper.js
  23153. /**
  23154. * @author mrdoob / http://mrdoob.com/
  23155. * @author WestLangley / http://github.com/WestLangley
  23156. */
  23157. THREE.FaceNormalsHelper = function ( object, size, hex, linewidth ) {
  23158. // FaceNormalsHelper only supports THREE.Geometry
  23159. this.object = object;
  23160. this.size = ( size !== undefined ) ? size : 1;
  23161. var color = ( hex !== undefined ) ? hex : 0xffff00;
  23162. var width = ( linewidth !== undefined ) ? linewidth : 1;
  23163. //
  23164. var nNormals = 0;
  23165. var objGeometry = this.object.geometry;
  23166. if ( objGeometry instanceof THREE.Geometry ) {
  23167. nNormals = objGeometry.faces.length;
  23168. } else {
  23169. console.warn( 'THREE.FaceNormalsHelper: only THREE.Geometry is supported. Use THREE.VertexNormalsHelper, instead.' );
  23170. }
  23171. //
  23172. var geometry = new THREE.BufferGeometry();
  23173. var positions = new THREE.Float32Attribute( nNormals * 2 * 3, 3 );
  23174. geometry.addAttribute( 'position', positions );
  23175. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  23176. //
  23177. this.matrixAutoUpdate = false;
  23178. this.update();
  23179. };
  23180. THREE.FaceNormalsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  23181. THREE.FaceNormalsHelper.prototype.constructor = THREE.FaceNormalsHelper;
  23182. THREE.FaceNormalsHelper.prototype.update = ( function () {
  23183. var v1 = new THREE.Vector3();
  23184. var v2 = new THREE.Vector3();
  23185. var normalMatrix = new THREE.Matrix3();
  23186. return function update() {
  23187. this.object.updateMatrixWorld( true );
  23188. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  23189. var matrixWorld = this.object.matrixWorld;
  23190. var position = this.geometry.attributes.position;
  23191. //
  23192. var objGeometry = this.object.geometry;
  23193. var vertices = objGeometry.vertices;
  23194. var faces = objGeometry.faces;
  23195. var idx = 0;
  23196. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  23197. var face = faces[ i ];
  23198. var normal = face.normal;
  23199. v1.copy( vertices[ face.a ] )
  23200. .add( vertices[ face.b ] )
  23201. .add( vertices[ face.c ] )
  23202. .divideScalar( 3 )
  23203. .applyMatrix4( matrixWorld );
  23204. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  23205. position.setXYZ( idx, v1.x, v1.y, v1.z );
  23206. idx = idx + 1;
  23207. position.setXYZ( idx, v2.x, v2.y, v2.z );
  23208. idx = idx + 1;
  23209. }
  23210. position.needsUpdate = true;
  23211. return this;
  23212. }
  23213. }() );
  23214. // File:src/extras/helpers/GridHelper.js
  23215. /**
  23216. * @author mrdoob / http://mrdoob.com/
  23217. */
  23218. THREE.GridHelper = function ( size, step ) {
  23219. var geometry = new THREE.Geometry();
  23220. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
  23221. this.color1 = new THREE.Color( 0x444444 );
  23222. this.color2 = new THREE.Color( 0x888888 );
  23223. for ( var i = - size; i <= size; i += step ) {
  23224. geometry.vertices.push(
  23225. new THREE.Vector3( - size, 0, i ), new THREE.Vector3( size, 0, i ),
  23226. new THREE.Vector3( i, 0, - size ), new THREE.Vector3( i, 0, size )
  23227. );
  23228. var color = i === 0 ? this.color1 : this.color2;
  23229. geometry.colors.push( color, color, color, color );
  23230. }
  23231. THREE.LineSegments.call( this, geometry, material );
  23232. };
  23233. THREE.GridHelper.prototype = Object.create( THREE.LineSegments.prototype );
  23234. THREE.GridHelper.prototype.constructor = THREE.GridHelper;
  23235. THREE.GridHelper.prototype.setColors = function( colorCenterLine, colorGrid ) {
  23236. this.color1.set( colorCenterLine );
  23237. this.color2.set( colorGrid );
  23238. this.geometry.colorsNeedUpdate = true;
  23239. };
  23240. // File:src/extras/helpers/HemisphereLightHelper.js
  23241. /**
  23242. * @author alteredq / http://alteredqualia.com/
  23243. * @author mrdoob / http://mrdoob.com/
  23244. */
  23245. THREE.HemisphereLightHelper = function ( light, sphereSize ) {
  23246. THREE.Object3D.call( this );
  23247. this.light = light;
  23248. this.light.updateMatrixWorld();
  23249. this.matrix = light.matrixWorld;
  23250. this.matrixAutoUpdate = false;
  23251. this.colors = [ new THREE.Color(), new THREE.Color() ];
  23252. var geometry = new THREE.SphereGeometry( sphereSize, 4, 2 );
  23253. geometry.rotateX( - Math.PI / 2 );
  23254. for ( var i = 0, il = 8; i < il; i ++ ) {
  23255. geometry.faces[ i ].color = this.colors[ i < 4 ? 0 : 1 ];
  23256. }
  23257. var material = new THREE.MeshBasicMaterial( { vertexColors: THREE.FaceColors, wireframe: true } );
  23258. this.lightSphere = new THREE.Mesh( geometry, material );
  23259. this.add( this.lightSphere );
  23260. this.update();
  23261. };
  23262. THREE.HemisphereLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  23263. THREE.HemisphereLightHelper.prototype.constructor = THREE.HemisphereLightHelper;
  23264. THREE.HemisphereLightHelper.prototype.dispose = function () {
  23265. this.lightSphere.geometry.dispose();
  23266. this.lightSphere.material.dispose();
  23267. };
  23268. THREE.HemisphereLightHelper.prototype.update = function () {
  23269. var vector = new THREE.Vector3();
  23270. return function () {
  23271. this.colors[ 0 ].copy( this.light.color ).multiplyScalar( this.light.intensity );
  23272. this.colors[ 1 ].copy( this.light.groundColor ).multiplyScalar( this.light.intensity );
  23273. this.lightSphere.lookAt( vector.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  23274. this.lightSphere.geometry.colorsNeedUpdate = true;
  23275. }
  23276. }();
  23277. // File:src/extras/helpers/PointLightHelper.js
  23278. /**
  23279. * @author alteredq / http://alteredqualia.com/
  23280. * @author mrdoob / http://mrdoob.com/
  23281. */
  23282. THREE.PointLightHelper = function ( light, sphereSize ) {
  23283. this.light = light;
  23284. this.light.updateMatrixWorld();
  23285. var geometry = new THREE.SphereGeometry( sphereSize, 4, 2 );
  23286. var material = new THREE.MeshBasicMaterial( { wireframe: true, fog: false } );
  23287. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  23288. THREE.Mesh.call( this, geometry, material );
  23289. this.matrix = this.light.matrixWorld;
  23290. this.matrixAutoUpdate = false;
  23291. /*
  23292. var distanceGeometry = new THREE.IcosahedronGeometry( 1, 2 );
  23293. var distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  23294. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  23295. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  23296. var d = light.distance;
  23297. if ( d === 0.0 ) {
  23298. this.lightDistance.visible = false;
  23299. } else {
  23300. this.lightDistance.scale.set( d, d, d );
  23301. }
  23302. this.add( this.lightDistance );
  23303. */
  23304. };
  23305. THREE.PointLightHelper.prototype = Object.create( THREE.Mesh.prototype );
  23306. THREE.PointLightHelper.prototype.constructor = THREE.PointLightHelper;
  23307. THREE.PointLightHelper.prototype.dispose = function () {
  23308. this.geometry.dispose();
  23309. this.material.dispose();
  23310. };
  23311. THREE.PointLightHelper.prototype.update = function () {
  23312. this.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  23313. /*
  23314. var d = this.light.distance;
  23315. if ( d === 0.0 ) {
  23316. this.lightDistance.visible = false;
  23317. } else {
  23318. this.lightDistance.visible = true;
  23319. this.lightDistance.scale.set( d, d, d );
  23320. }
  23321. */
  23322. };
  23323. // File:src/extras/helpers/SkeletonHelper.js
  23324. /**
  23325. * @author Sean Griffin / http://twitter.com/sgrif
  23326. * @author Michael Guerrero / http://realitymeltdown.com
  23327. * @author mrdoob / http://mrdoob.com/
  23328. * @author ikerr / http://verold.com
  23329. */
  23330. THREE.SkeletonHelper = function ( object ) {
  23331. this.bones = this.getBoneList( object );
  23332. var geometry = new THREE.Geometry();
  23333. for ( var i = 0; i < this.bones.length; i ++ ) {
  23334. var bone = this.bones[ i ];
  23335. if ( bone.parent instanceof THREE.Bone ) {
  23336. geometry.vertices.push( new THREE.Vector3() );
  23337. geometry.vertices.push( new THREE.Vector3() );
  23338. geometry.colors.push( new THREE.Color( 0, 0, 1 ) );
  23339. geometry.colors.push( new THREE.Color( 0, 1, 0 ) );
  23340. }
  23341. }
  23342. geometry.dynamic = true;
  23343. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors, depthTest: false, depthWrite: false, transparent: true } );
  23344. THREE.LineSegments.call( this, geometry, material );
  23345. this.root = object;
  23346. this.matrix = object.matrixWorld;
  23347. this.matrixAutoUpdate = false;
  23348. this.update();
  23349. };
  23350. THREE.SkeletonHelper.prototype = Object.create( THREE.LineSegments.prototype );
  23351. THREE.SkeletonHelper.prototype.constructor = THREE.SkeletonHelper;
  23352. THREE.SkeletonHelper.prototype.getBoneList = function( object ) {
  23353. var boneList = [];
  23354. if ( object instanceof THREE.Bone ) {
  23355. boneList.push( object );
  23356. }
  23357. for ( var i = 0; i < object.children.length; i ++ ) {
  23358. boneList.push.apply( boneList, this.getBoneList( object.children[ i ] ) );
  23359. }
  23360. return boneList;
  23361. };
  23362. THREE.SkeletonHelper.prototype.update = function () {
  23363. var geometry = this.geometry;
  23364. var matrixWorldInv = new THREE.Matrix4().getInverse( this.root.matrixWorld );
  23365. var boneMatrix = new THREE.Matrix4();
  23366. var j = 0;
  23367. for ( var i = 0; i < this.bones.length; i ++ ) {
  23368. var bone = this.bones[ i ];
  23369. if ( bone.parent instanceof THREE.Bone ) {
  23370. boneMatrix.multiplyMatrices( matrixWorldInv, bone.matrixWorld );
  23371. geometry.vertices[ j ].setFromMatrixPosition( boneMatrix );
  23372. boneMatrix.multiplyMatrices( matrixWorldInv, bone.parent.matrixWorld );
  23373. geometry.vertices[ j + 1 ].setFromMatrixPosition( boneMatrix );
  23374. j += 2;
  23375. }
  23376. }
  23377. geometry.verticesNeedUpdate = true;
  23378. geometry.computeBoundingSphere();
  23379. };
  23380. // File:src/extras/helpers/SpotLightHelper.js
  23381. /**
  23382. * @author alteredq / http://alteredqualia.com/
  23383. * @author mrdoob / http://mrdoob.com/
  23384. * @author WestLangley / http://github.com/WestLangley
  23385. */
  23386. THREE.SpotLightHelper = function ( light ) {
  23387. THREE.Object3D.call( this );
  23388. this.light = light;
  23389. this.light.updateMatrixWorld();
  23390. this.matrix = light.matrixWorld;
  23391. this.matrixAutoUpdate = false;
  23392. var geometry = new THREE.CylinderGeometry( 0, 1, 1, 8, 1, true );
  23393. geometry.translate( 0, - 0.5, 0 );
  23394. geometry.rotateX( - Math.PI / 2 );
  23395. var material = new THREE.MeshBasicMaterial( { wireframe: true, fog: false } );
  23396. this.cone = new THREE.Mesh( geometry, material );
  23397. this.add( this.cone );
  23398. this.update();
  23399. };
  23400. THREE.SpotLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  23401. THREE.SpotLightHelper.prototype.constructor = THREE.SpotLightHelper;
  23402. THREE.SpotLightHelper.prototype.dispose = function () {
  23403. this.cone.geometry.dispose();
  23404. this.cone.material.dispose();
  23405. };
  23406. THREE.SpotLightHelper.prototype.update = function () {
  23407. var vector = new THREE.Vector3();
  23408. var vector2 = new THREE.Vector3();
  23409. return function () {
  23410. var coneLength = this.light.distance ? this.light.distance : 10000;
  23411. var coneWidth = coneLength * Math.tan( this.light.angle );
  23412. this.cone.scale.set( coneWidth, coneWidth, coneLength );
  23413. vector.setFromMatrixPosition( this.light.matrixWorld );
  23414. vector2.setFromMatrixPosition( this.light.target.matrixWorld );
  23415. this.cone.lookAt( vector2.sub( vector ) );
  23416. this.cone.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  23417. };
  23418. }();
  23419. // File:src/extras/helpers/VertexNormalsHelper.js
  23420. /**
  23421. * @author mrdoob / http://mrdoob.com/
  23422. * @author WestLangley / http://github.com/WestLangley
  23423. */
  23424. THREE.VertexNormalsHelper = function ( object, size, hex, linewidth ) {
  23425. this.object = object;
  23426. this.size = ( size !== undefined ) ? size : 1;
  23427. var color = ( hex !== undefined ) ? hex : 0xff0000;
  23428. var width = ( linewidth !== undefined ) ? linewidth : 1;
  23429. //
  23430. var nNormals = 0;
  23431. var objGeometry = this.object.geometry;
  23432. if ( objGeometry instanceof THREE.Geometry ) {
  23433. nNormals = objGeometry.faces.length * 3;
  23434. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  23435. nNormals = objGeometry.attributes.normal.count
  23436. }
  23437. //
  23438. var geometry = new THREE.BufferGeometry();
  23439. var positions = new THREE.Float32Attribute( nNormals * 2 * 3, 3 );
  23440. geometry.addAttribute( 'position', positions );
  23441. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  23442. //
  23443. this.matrixAutoUpdate = false;
  23444. this.update();
  23445. };
  23446. THREE.VertexNormalsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  23447. THREE.VertexNormalsHelper.prototype.constructor = THREE.VertexNormalsHelper;
  23448. THREE.VertexNormalsHelper.prototype.update = ( function () {
  23449. var v1 = new THREE.Vector3();
  23450. var v2 = new THREE.Vector3();
  23451. var normalMatrix = new THREE.Matrix3();
  23452. return function update() {
  23453. var keys = [ 'a', 'b', 'c' ];
  23454. this.object.updateMatrixWorld( true );
  23455. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  23456. var matrixWorld = this.object.matrixWorld;
  23457. var position = this.geometry.attributes.position;
  23458. //
  23459. var objGeometry = this.object.geometry;
  23460. if ( objGeometry instanceof THREE.Geometry ) {
  23461. var vertices = objGeometry.vertices;
  23462. var faces = objGeometry.faces;
  23463. var idx = 0;
  23464. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  23465. var face = faces[ i ];
  23466. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  23467. var vertex = vertices[ face[ keys[ j ] ] ];
  23468. var normal = face.vertexNormals[ j ];
  23469. v1.copy( vertex ).applyMatrix4( matrixWorld );
  23470. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  23471. position.setXYZ( idx, v1.x, v1.y, v1.z );
  23472. idx = idx + 1;
  23473. position.setXYZ( idx, v2.x, v2.y, v2.z );
  23474. idx = idx + 1;
  23475. }
  23476. }
  23477. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  23478. var objPos = objGeometry.attributes.position;
  23479. var objNorm = objGeometry.attributes.normal;
  23480. var idx = 0;
  23481. // for simplicity, ignore index and drawcalls, and render every normal
  23482. for ( var j = 0, jl = objPos.count; j < jl; j ++ ) {
  23483. v1.set( objPos.getX( j ), objPos.getY( j ), objPos.getZ( j ) ).applyMatrix4( matrixWorld );
  23484. v2.set( objNorm.getX( j ), objNorm.getY( j ), objNorm.getZ( j ) );
  23485. v2.applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  23486. position.setXYZ( idx, v1.x, v1.y, v1.z );
  23487. idx = idx + 1;
  23488. position.setXYZ( idx, v2.x, v2.y, v2.z );
  23489. idx = idx + 1;
  23490. }
  23491. }
  23492. position.needsUpdate = true;
  23493. return this;
  23494. }
  23495. }() );
  23496. // File:src/extras/helpers/WireframeHelper.js
  23497. /**
  23498. * @author mrdoob / http://mrdoob.com/
  23499. */
  23500. THREE.WireframeHelper = function ( object, hex ) {
  23501. var color = ( hex !== undefined ) ? hex : 0xffffff;
  23502. THREE.LineSegments.call( this, new THREE.WireframeGeometry( object.geometry ), new THREE.LineBasicMaterial( { color: color } ) );
  23503. this.matrix = object.matrixWorld;
  23504. this.matrixAutoUpdate = false;
  23505. };
  23506. THREE.WireframeHelper.prototype = Object.create( THREE.LineSegments.prototype );
  23507. THREE.WireframeHelper.prototype.constructor = THREE.WireframeHelper;
  23508. // File:src/extras/objects/ImmediateRenderObject.js
  23509. /**
  23510. * @author alteredq / http://alteredqualia.com/
  23511. */
  23512. THREE.ImmediateRenderObject = function ( material ) {
  23513. THREE.Object3D.call( this );
  23514. this.material = material;
  23515. this.render = function ( renderCallback ) {};
  23516. };
  23517. THREE.ImmediateRenderObject.prototype = Object.create( THREE.Object3D.prototype );
  23518. THREE.ImmediateRenderObject.prototype.constructor = THREE.ImmediateRenderObject;
  23519. // File:src/extras/objects/MorphBlendMesh.js
  23520. /**
  23521. * @author alteredq / http://alteredqualia.com/
  23522. */
  23523. THREE.MorphBlendMesh = function( geometry, material ) {
  23524. THREE.Mesh.call( this, geometry, material );
  23525. this.animationsMap = {};
  23526. this.animationsList = [];
  23527. // prepare default animation
  23528. // (all frames played together in 1 second)
  23529. var numFrames = this.geometry.morphTargets.length;
  23530. var name = "__default";
  23531. var startFrame = 0;
  23532. var endFrame = numFrames - 1;
  23533. var fps = numFrames / 1;
  23534. this.createAnimation( name, startFrame, endFrame, fps );
  23535. this.setAnimationWeight( name, 1 );
  23536. };
  23537. THREE.MorphBlendMesh.prototype = Object.create( THREE.Mesh.prototype );
  23538. THREE.MorphBlendMesh.prototype.constructor = THREE.MorphBlendMesh;
  23539. THREE.MorphBlendMesh.prototype.createAnimation = function ( name, start, end, fps ) {
  23540. var animation = {
  23541. start: start,
  23542. end: end,
  23543. length: end - start + 1,
  23544. fps: fps,
  23545. duration: ( end - start ) / fps,
  23546. lastFrame: 0,
  23547. currentFrame: 0,
  23548. active: false,
  23549. time: 0,
  23550. direction: 1,
  23551. weight: 1,
  23552. directionBackwards: false,
  23553. mirroredLoop: false
  23554. };
  23555. this.animationsMap[ name ] = animation;
  23556. this.animationsList.push( animation );
  23557. };
  23558. THREE.MorphBlendMesh.prototype.autoCreateAnimations = function ( fps ) {
  23559. var pattern = /([a-z]+)_?(\d+)/;
  23560. var firstAnimation, frameRanges = {};
  23561. var geometry = this.geometry;
  23562. for ( var i = 0, il = geometry.morphTargets.length; i < il; i ++ ) {
  23563. var morph = geometry.morphTargets[ i ];
  23564. var chunks = morph.name.match( pattern );
  23565. if ( chunks && chunks.length > 1 ) {
  23566. var name = chunks[ 1 ];
  23567. if ( ! frameRanges[ name ] ) frameRanges[ name ] = { start: Infinity, end: - Infinity };
  23568. var range = frameRanges[ name ];
  23569. if ( i < range.start ) range.start = i;
  23570. if ( i > range.end ) range.end = i;
  23571. if ( ! firstAnimation ) firstAnimation = name;
  23572. }
  23573. }
  23574. for ( var name in frameRanges ) {
  23575. var range = frameRanges[ name ];
  23576. this.createAnimation( name, range.start, range.end, fps );
  23577. }
  23578. this.firstAnimation = firstAnimation;
  23579. };
  23580. THREE.MorphBlendMesh.prototype.setAnimationDirectionForward = function ( name ) {
  23581. var animation = this.animationsMap[ name ];
  23582. if ( animation ) {
  23583. animation.direction = 1;
  23584. animation.directionBackwards = false;
  23585. }
  23586. };
  23587. THREE.MorphBlendMesh.prototype.setAnimationDirectionBackward = function ( name ) {
  23588. var animation = this.animationsMap[ name ];
  23589. if ( animation ) {
  23590. animation.direction = - 1;
  23591. animation.directionBackwards = true;
  23592. }
  23593. };
  23594. THREE.MorphBlendMesh.prototype.setAnimationFPS = function ( name, fps ) {
  23595. var animation = this.animationsMap[ name ];
  23596. if ( animation ) {
  23597. animation.fps = fps;
  23598. animation.duration = ( animation.end - animation.start ) / animation.fps;
  23599. }
  23600. };
  23601. THREE.MorphBlendMesh.prototype.setAnimationDuration = function ( name, duration ) {
  23602. var animation = this.animationsMap[ name ];
  23603. if ( animation ) {
  23604. animation.duration = duration;
  23605. animation.fps = ( animation.end - animation.start ) / animation.duration;
  23606. }
  23607. };
  23608. THREE.MorphBlendMesh.prototype.setAnimationWeight = function ( name, weight ) {
  23609. var animation = this.animationsMap[ name ];
  23610. if ( animation ) {
  23611. animation.weight = weight;
  23612. }
  23613. };
  23614. THREE.MorphBlendMesh.prototype.setAnimationTime = function ( name, time ) {
  23615. var animation = this.animationsMap[ name ];
  23616. if ( animation ) {
  23617. animation.time = time;
  23618. }
  23619. };
  23620. THREE.MorphBlendMesh.prototype.getAnimationTime = function ( name ) {
  23621. var time = 0;
  23622. var animation = this.animationsMap[ name ];
  23623. if ( animation ) {
  23624. time = animation.time;
  23625. }
  23626. return time;
  23627. };
  23628. THREE.MorphBlendMesh.prototype.getAnimationDuration = function ( name ) {
  23629. var duration = - 1;
  23630. var animation = this.animationsMap[ name ];
  23631. if ( animation ) {
  23632. duration = animation.duration;
  23633. }
  23634. return duration;
  23635. };
  23636. THREE.MorphBlendMesh.prototype.playAnimation = function ( name ) {
  23637. var animation = this.animationsMap[ name ];
  23638. if ( animation ) {
  23639. animation.time = 0;
  23640. animation.active = true;
  23641. } else {
  23642. console.warn( "THREE.MorphBlendMesh: animation[" + name + "] undefined in .playAnimation()" );
  23643. }
  23644. };
  23645. THREE.MorphBlendMesh.prototype.stopAnimation = function ( name ) {
  23646. var animation = this.animationsMap[ name ];
  23647. if ( animation ) {
  23648. animation.active = false;
  23649. }
  23650. };
  23651. THREE.MorphBlendMesh.prototype.update = function ( delta ) {
  23652. for ( var i = 0, il = this.animationsList.length; i < il; i ++ ) {
  23653. var animation = this.animationsList[ i ];
  23654. if ( ! animation.active ) continue;
  23655. var frameTime = animation.duration / animation.length;
  23656. animation.time += animation.direction * delta;
  23657. if ( animation.mirroredLoop ) {
  23658. if ( animation.time > animation.duration || animation.time < 0 ) {
  23659. animation.direction *= - 1;
  23660. if ( animation.time > animation.duration ) {
  23661. animation.time = animation.duration;
  23662. animation.directionBackwards = true;
  23663. }
  23664. if ( animation.time < 0 ) {
  23665. animation.time = 0;
  23666. animation.directionBackwards = false;
  23667. }
  23668. }
  23669. } else {
  23670. animation.time = animation.time % animation.duration;
  23671. if ( animation.time < 0 ) animation.time += animation.duration;
  23672. }
  23673. var keyframe = animation.start + THREE.Math.clamp( Math.floor( animation.time / frameTime ), 0, animation.length - 1 );
  23674. var weight = animation.weight;
  23675. if ( keyframe !== animation.currentFrame ) {
  23676. this.morphTargetInfluences[ animation.lastFrame ] = 0;
  23677. this.morphTargetInfluences[ animation.currentFrame ] = 1 * weight;
  23678. this.morphTargetInfluences[ keyframe ] = 0;
  23679. animation.lastFrame = animation.currentFrame;
  23680. animation.currentFrame = keyframe;
  23681. }
  23682. var mix = ( animation.time % frameTime ) / frameTime;
  23683. if ( animation.directionBackwards ) mix = 1 - mix;
  23684. if ( animation.currentFrame !== animation.lastFrame ) {
  23685. this.morphTargetInfluences[ animation.currentFrame ] = mix * weight;
  23686. this.morphTargetInfluences[ animation.lastFrame ] = ( 1 - mix ) * weight;
  23687. } else {
  23688. this.morphTargetInfluences[ animation.currentFrame ] = weight;
  23689. }
  23690. }
  23691. };
粤ICP备19079148号