three.js 944 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744
  1. // File:src/Three.js
  2. /**
  3. * @author mrdoob / http://mrdoob.com/
  4. */
  5. var THREE = { REVISION: '77' };
  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 ( Number.EPSILON === undefined ) {
  14. Number.EPSILON = Math.pow( 2, - 52 );
  15. }
  16. //
  17. if ( Math.sign === undefined ) {
  18. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
  19. Math.sign = function ( x ) {
  20. return ( x < 0 ) ? - 1 : ( x > 0 ) ? 1 : + x;
  21. };
  22. }
  23. if ( Function.prototype.name === undefined ) {
  24. // Missing in IE9-11.
  25. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
  26. Object.defineProperty( Function.prototype, 'name', {
  27. get: function () {
  28. return this.toString().match( /^\s*function\s*(\S*)\s*\(/ )[ 1 ];
  29. }
  30. } );
  31. }
  32. if ( Object.assign === undefined ) {
  33. // Missing in IE.
  34. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
  35. ( function () {
  36. Object.assign = function ( target ) {
  37. 'use strict';
  38. if ( target === undefined || target === null ) {
  39. throw new TypeError( 'Cannot convert undefined or null to object' );
  40. }
  41. var output = Object( target );
  42. for ( var index = 1; index < arguments.length; index ++ ) {
  43. var source = arguments[ index ];
  44. if ( source !== undefined && source !== null ) {
  45. for ( var nextKey in source ) {
  46. if ( Object.prototype.hasOwnProperty.call( source, nextKey ) ) {
  47. output[ nextKey ] = source[ nextKey ];
  48. }
  49. }
  50. }
  51. }
  52. return output;
  53. };
  54. } )();
  55. }
  56. //
  57. Object.assign( THREE, {
  58. // https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent.button
  59. MOUSE: { LEFT: 0, MIDDLE: 1, RIGHT: 2 },
  60. // GL STATE CONSTANTS
  61. CullFaceNone: 0,
  62. CullFaceBack: 1,
  63. CullFaceFront: 2,
  64. CullFaceFrontBack: 3,
  65. FrontFaceDirectionCW: 0,
  66. FrontFaceDirectionCCW: 1,
  67. // SHADOWING TYPES
  68. BasicShadowMap: 0,
  69. PCFShadowMap: 1,
  70. PCFSoftShadowMap: 2,
  71. // MATERIAL CONSTANTS
  72. // side
  73. FrontSide: 0,
  74. BackSide: 1,
  75. DoubleSide: 2,
  76. // shading
  77. FlatShading: 1,
  78. SmoothShading: 2,
  79. // colors
  80. NoColors: 0,
  81. FaceColors: 1,
  82. VertexColors: 2,
  83. // blending modes
  84. NoBlending: 0,
  85. NormalBlending: 1,
  86. AdditiveBlending: 2,
  87. SubtractiveBlending: 3,
  88. MultiplyBlending: 4,
  89. CustomBlending: 5,
  90. // custom blending equations
  91. // (numbers start from 100 not to clash with other
  92. // mappings to OpenGL constants defined in Texture.js)
  93. AddEquation: 100,
  94. SubtractEquation: 101,
  95. ReverseSubtractEquation: 102,
  96. MinEquation: 103,
  97. MaxEquation: 104,
  98. // custom blending destination factors
  99. ZeroFactor: 200,
  100. OneFactor: 201,
  101. SrcColorFactor: 202,
  102. OneMinusSrcColorFactor: 203,
  103. SrcAlphaFactor: 204,
  104. OneMinusSrcAlphaFactor: 205,
  105. DstAlphaFactor: 206,
  106. OneMinusDstAlphaFactor: 207,
  107. // custom blending source factors
  108. //ZeroFactor: 200,
  109. //OneFactor: 201,
  110. //SrcAlphaFactor: 204,
  111. //OneMinusSrcAlphaFactor: 205,
  112. //DstAlphaFactor: 206,
  113. //OneMinusDstAlphaFactor: 207,
  114. DstColorFactor: 208,
  115. OneMinusDstColorFactor: 209,
  116. SrcAlphaSaturateFactor: 210,
  117. // depth modes
  118. NeverDepth: 0,
  119. AlwaysDepth: 1,
  120. LessDepth: 2,
  121. LessEqualDepth: 3,
  122. EqualDepth: 4,
  123. GreaterEqualDepth: 5,
  124. GreaterDepth: 6,
  125. NotEqualDepth: 7,
  126. // TEXTURE CONSTANTS
  127. MultiplyOperation: 0,
  128. MixOperation: 1,
  129. AddOperation: 2,
  130. // Tone Mapping modes
  131. NoToneMapping: 0, // do not do any tone mapping, not even exposure (required for special purpose passes.)
  132. LinearToneMapping: 1, // only apply exposure.
  133. ReinhardToneMapping: 2,
  134. Uncharted2ToneMapping: 3, // John Hable
  135. CineonToneMapping: 4, // optimized filmic operator by Jim Hejl and Richard Burgess-Dawson
  136. // Mapping modes
  137. UVMapping: 300,
  138. CubeReflectionMapping: 301,
  139. CubeRefractionMapping: 302,
  140. EquirectangularReflectionMapping: 303,
  141. EquirectangularRefractionMapping: 304,
  142. SphericalReflectionMapping: 305,
  143. CubeUVReflectionMapping: 306,
  144. CubeUVRefractionMapping: 307,
  145. // Wrapping modes
  146. RepeatWrapping: 1000,
  147. ClampToEdgeWrapping: 1001,
  148. MirroredRepeatWrapping: 1002,
  149. // Filters
  150. NearestFilter: 1003,
  151. NearestMipMapNearestFilter: 1004,
  152. NearestMipMapLinearFilter: 1005,
  153. LinearFilter: 1006,
  154. LinearMipMapNearestFilter: 1007,
  155. LinearMipMapLinearFilter: 1008,
  156. // Data types
  157. UnsignedByteType: 1009,
  158. ByteType: 1010,
  159. ShortType: 1011,
  160. UnsignedShortType: 1012,
  161. IntType: 1013,
  162. UnsignedIntType: 1014,
  163. FloatType: 1015,
  164. HalfFloatType: 1025,
  165. // Pixel types
  166. //UnsignedByteType: 1009,
  167. UnsignedShort4444Type: 1016,
  168. UnsignedShort5551Type: 1017,
  169. UnsignedShort565Type: 1018,
  170. // Pixel formats
  171. AlphaFormat: 1019,
  172. RGBFormat: 1020,
  173. RGBAFormat: 1021,
  174. LuminanceFormat: 1022,
  175. LuminanceAlphaFormat: 1023,
  176. // THREE.RGBEFormat handled as THREE.RGBAFormat in shaders
  177. RGBEFormat: THREE.RGBAFormat, //1024;
  178. DepthFormat: 1026,
  179. // DDS / ST3C Compressed texture formats
  180. RGB_S3TC_DXT1_Format: 2001,
  181. RGBA_S3TC_DXT1_Format: 2002,
  182. RGBA_S3TC_DXT3_Format: 2003,
  183. RGBA_S3TC_DXT5_Format: 2004,
  184. // PVRTC compressed texture formats
  185. RGB_PVRTC_4BPPV1_Format: 2100,
  186. RGB_PVRTC_2BPPV1_Format: 2101,
  187. RGBA_PVRTC_4BPPV1_Format: 2102,
  188. RGBA_PVRTC_2BPPV1_Format: 2103,
  189. // ETC compressed texture formats
  190. RGB_ETC1_Format: 2151,
  191. // Loop styles for AnimationAction
  192. LoopOnce: 2200,
  193. LoopRepeat: 2201,
  194. LoopPingPong: 2202,
  195. // Interpolation
  196. InterpolateDiscrete: 2300,
  197. InterpolateLinear: 2301,
  198. InterpolateSmooth: 2302,
  199. // Interpolant ending modes
  200. ZeroCurvatureEnding: 2400,
  201. ZeroSlopeEnding: 2401,
  202. WrapAroundEnding: 2402,
  203. // Triangle Draw modes
  204. TrianglesDrawMode: 0,
  205. TriangleStripDrawMode: 1,
  206. TriangleFanDrawMode: 2,
  207. // Texture Encodings
  208. LinearEncoding: 3000, // No encoding at all.
  209. sRGBEncoding: 3001,
  210. GammaEncoding: 3007, // uses GAMMA_FACTOR, for backwards compatibility with WebGLRenderer.gammaInput/gammaOutput
  211. // The following Texture Encodings are for RGB-only (no alpha) HDR light emission sources.
  212. // These encodings should not specified as output encodings except in rare situations.
  213. RGBEEncoding: 3002, // AKA Radiance.
  214. LogLuvEncoding: 3003,
  215. RGBM7Encoding: 3004,
  216. RGBM16Encoding: 3005,
  217. RGBDEncoding: 3006, // MaxRange is 256.
  218. // Depth packing strategies
  219. BasicDepthPacking: 3200, // for writing to float textures for high precision or for visualizing results in RGB buffers
  220. RGBADepthPacking: 3201 // for packing into RGBA buffers.
  221. } );
  222. // File:src/math/Color.js
  223. /**
  224. * @author mrdoob / http://mrdoob.com/
  225. */
  226. THREE.Color = function ( r, g, b ) {
  227. if ( g === undefined && b === undefined ) {
  228. // r is THREE.Color, hex or string
  229. return this.set( r );
  230. }
  231. return this.setRGB( r, g, b );
  232. };
  233. THREE.Color.prototype = {
  234. constructor: THREE.Color,
  235. r: 1, g: 1, b: 1,
  236. set: function ( value ) {
  237. if ( value instanceof THREE.Color ) {
  238. this.copy( value );
  239. } else if ( typeof value === 'number' ) {
  240. this.setHex( value );
  241. } else if ( typeof value === 'string' ) {
  242. this.setStyle( value );
  243. }
  244. return this;
  245. },
  246. setScalar: function ( scalar ) {
  247. this.r = scalar;
  248. this.g = scalar;
  249. this.b = scalar;
  250. },
  251. setHex: function ( hex ) {
  252. hex = Math.floor( hex );
  253. this.r = ( hex >> 16 & 255 ) / 255;
  254. this.g = ( hex >> 8 & 255 ) / 255;
  255. this.b = ( hex & 255 ) / 255;
  256. return this;
  257. },
  258. setRGB: function ( r, g, b ) {
  259. this.r = r;
  260. this.g = g;
  261. this.b = b;
  262. return this;
  263. },
  264. setHSL: function () {
  265. function hue2rgb( p, q, t ) {
  266. if ( t < 0 ) t += 1;
  267. if ( t > 1 ) t -= 1;
  268. if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
  269. if ( t < 1 / 2 ) return q;
  270. if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
  271. return p;
  272. }
  273. return function ( h, s, l ) {
  274. // h,s,l ranges are in 0.0 - 1.0
  275. h = THREE.Math.euclideanModulo( h, 1 );
  276. s = THREE.Math.clamp( s, 0, 1 );
  277. l = THREE.Math.clamp( l, 0, 1 );
  278. if ( s === 0 ) {
  279. this.r = this.g = this.b = l;
  280. } else {
  281. var p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  282. var q = ( 2 * l ) - p;
  283. this.r = hue2rgb( q, p, h + 1 / 3 );
  284. this.g = hue2rgb( q, p, h );
  285. this.b = hue2rgb( q, p, h - 1 / 3 );
  286. }
  287. return this;
  288. };
  289. }(),
  290. setStyle: function ( style ) {
  291. function handleAlpha( string ) {
  292. if ( string === undefined ) return;
  293. if ( parseFloat( string ) < 1 ) {
  294. console.warn( 'THREE.Color: Alpha component of ' + style + ' will be ignored.' );
  295. }
  296. }
  297. var m;
  298. if ( m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec( style ) ) {
  299. // rgb / hsl
  300. var color;
  301. var name = m[ 1 ];
  302. var components = m[ 2 ];
  303. switch ( name ) {
  304. case 'rgb':
  305. case 'rgba':
  306. if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  307. // rgb(255,0,0) rgba(255,0,0,0.5)
  308. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  309. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  310. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  311. handleAlpha( color[ 5 ] );
  312. return this;
  313. }
  314. if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  315. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  316. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  317. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  318. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  319. handleAlpha( color[ 5 ] );
  320. return this;
  321. }
  322. break;
  323. case 'hsl':
  324. case 'hsla':
  325. if ( color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  326. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  327. var h = parseFloat( color[ 1 ] ) / 360;
  328. var s = parseInt( color[ 2 ], 10 ) / 100;
  329. var l = parseInt( color[ 3 ], 10 ) / 100;
  330. handleAlpha( color[ 5 ] );
  331. return this.setHSL( h, s, l );
  332. }
  333. break;
  334. }
  335. } else if ( m = /^\#([A-Fa-f0-9]+)$/.exec( style ) ) {
  336. // hex color
  337. var hex = m[ 1 ];
  338. var size = hex.length;
  339. if ( size === 3 ) {
  340. // #ff0
  341. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 0 ), 16 ) / 255;
  342. this.g = parseInt( hex.charAt( 1 ) + hex.charAt( 1 ), 16 ) / 255;
  343. this.b = parseInt( hex.charAt( 2 ) + hex.charAt( 2 ), 16 ) / 255;
  344. return this;
  345. } else if ( size === 6 ) {
  346. // #ff0000
  347. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 1 ), 16 ) / 255;
  348. this.g = parseInt( hex.charAt( 2 ) + hex.charAt( 3 ), 16 ) / 255;
  349. this.b = parseInt( hex.charAt( 4 ) + hex.charAt( 5 ), 16 ) / 255;
  350. return this;
  351. }
  352. }
  353. if ( style && style.length > 0 ) {
  354. // color keywords
  355. var hex = THREE.ColorKeywords[ style ];
  356. if ( hex !== undefined ) {
  357. // red
  358. this.setHex( hex );
  359. } else {
  360. // unknown color
  361. console.warn( 'THREE.Color: Unknown color ' + style );
  362. }
  363. }
  364. return this;
  365. },
  366. clone: function () {
  367. return new this.constructor( this.r, this.g, this.b );
  368. },
  369. copy: function ( color ) {
  370. this.r = color.r;
  371. this.g = color.g;
  372. this.b = color.b;
  373. return this;
  374. },
  375. copyGammaToLinear: function ( color, gammaFactor ) {
  376. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  377. this.r = Math.pow( color.r, gammaFactor );
  378. this.g = Math.pow( color.g, gammaFactor );
  379. this.b = Math.pow( color.b, gammaFactor );
  380. return this;
  381. },
  382. copyLinearToGamma: function ( color, gammaFactor ) {
  383. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  384. var safeInverse = ( gammaFactor > 0 ) ? ( 1.0 / gammaFactor ) : 1.0;
  385. this.r = Math.pow( color.r, safeInverse );
  386. this.g = Math.pow( color.g, safeInverse );
  387. this.b = Math.pow( color.b, safeInverse );
  388. return this;
  389. },
  390. convertGammaToLinear: function () {
  391. var r = this.r, g = this.g, b = this.b;
  392. this.r = r * r;
  393. this.g = g * g;
  394. this.b = b * b;
  395. return this;
  396. },
  397. convertLinearToGamma: function () {
  398. this.r = Math.sqrt( this.r );
  399. this.g = Math.sqrt( this.g );
  400. this.b = Math.sqrt( this.b );
  401. return this;
  402. },
  403. getHex: function () {
  404. return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
  405. },
  406. getHexString: function () {
  407. return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
  408. },
  409. getHSL: function ( optionalTarget ) {
  410. // h,s,l ranges are in 0.0 - 1.0
  411. var hsl = optionalTarget || { h: 0, s: 0, l: 0 };
  412. var r = this.r, g = this.g, b = this.b;
  413. var max = Math.max( r, g, b );
  414. var min = Math.min( r, g, b );
  415. var hue, saturation;
  416. var lightness = ( min + max ) / 2.0;
  417. if ( min === max ) {
  418. hue = 0;
  419. saturation = 0;
  420. } else {
  421. var delta = max - min;
  422. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  423. switch ( max ) {
  424. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  425. case g: hue = ( b - r ) / delta + 2; break;
  426. case b: hue = ( r - g ) / delta + 4; break;
  427. }
  428. hue /= 6;
  429. }
  430. hsl.h = hue;
  431. hsl.s = saturation;
  432. hsl.l = lightness;
  433. return hsl;
  434. },
  435. getStyle: function () {
  436. return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
  437. },
  438. offsetHSL: function ( h, s, l ) {
  439. var hsl = this.getHSL();
  440. hsl.h += h; hsl.s += s; hsl.l += l;
  441. this.setHSL( hsl.h, hsl.s, hsl.l );
  442. return this;
  443. },
  444. add: function ( color ) {
  445. this.r += color.r;
  446. this.g += color.g;
  447. this.b += color.b;
  448. return this;
  449. },
  450. addColors: function ( color1, color2 ) {
  451. this.r = color1.r + color2.r;
  452. this.g = color1.g + color2.g;
  453. this.b = color1.b + color2.b;
  454. return this;
  455. },
  456. addScalar: function ( s ) {
  457. this.r += s;
  458. this.g += s;
  459. this.b += s;
  460. return this;
  461. },
  462. multiply: function ( color ) {
  463. this.r *= color.r;
  464. this.g *= color.g;
  465. this.b *= color.b;
  466. return this;
  467. },
  468. multiplyScalar: function ( s ) {
  469. this.r *= s;
  470. this.g *= s;
  471. this.b *= s;
  472. return this;
  473. },
  474. lerp: function ( color, alpha ) {
  475. this.r += ( color.r - this.r ) * alpha;
  476. this.g += ( color.g - this.g ) * alpha;
  477. this.b += ( color.b - this.b ) * alpha;
  478. return this;
  479. },
  480. equals: function ( c ) {
  481. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  482. },
  483. fromArray: function ( array, offset ) {
  484. if ( offset === undefined ) offset = 0;
  485. this.r = array[ offset ];
  486. this.g = array[ offset + 1 ];
  487. this.b = array[ offset + 2 ];
  488. return this;
  489. },
  490. toArray: function ( array, offset ) {
  491. if ( array === undefined ) array = [];
  492. if ( offset === undefined ) offset = 0;
  493. array[ offset ] = this.r;
  494. array[ offset + 1 ] = this.g;
  495. array[ offset + 2 ] = this.b;
  496. return array;
  497. }
  498. };
  499. THREE.ColorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  500. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  501. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  502. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  503. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  504. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  505. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  506. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  507. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  508. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  509. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  510. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  511. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  512. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  513. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  514. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  515. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  516. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  517. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  518. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  519. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  520. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  521. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  522. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  523. // File:src/math/Quaternion.js
  524. /**
  525. * @author mikael emtinger / http://gomo.se/
  526. * @author alteredq / http://alteredqualia.com/
  527. * @author WestLangley / http://github.com/WestLangley
  528. * @author bhouston / http://clara.io
  529. */
  530. THREE.Quaternion = function ( x, y, z, w ) {
  531. this._x = x || 0;
  532. this._y = y || 0;
  533. this._z = z || 0;
  534. this._w = ( w !== undefined ) ? w : 1;
  535. };
  536. THREE.Quaternion.prototype = {
  537. constructor: THREE.Quaternion,
  538. get x () {
  539. return this._x;
  540. },
  541. set x ( value ) {
  542. this._x = value;
  543. this.onChangeCallback();
  544. },
  545. get y () {
  546. return this._y;
  547. },
  548. set y ( value ) {
  549. this._y = value;
  550. this.onChangeCallback();
  551. },
  552. get z () {
  553. return this._z;
  554. },
  555. set z ( value ) {
  556. this._z = value;
  557. this.onChangeCallback();
  558. },
  559. get w () {
  560. return this._w;
  561. },
  562. set w ( value ) {
  563. this._w = value;
  564. this.onChangeCallback();
  565. },
  566. set: function ( x, y, z, w ) {
  567. this._x = x;
  568. this._y = y;
  569. this._z = z;
  570. this._w = w;
  571. this.onChangeCallback();
  572. return this;
  573. },
  574. clone: function () {
  575. return new this.constructor( this._x, this._y, this._z, this._w );
  576. },
  577. copy: function ( quaternion ) {
  578. this._x = quaternion.x;
  579. this._y = quaternion.y;
  580. this._z = quaternion.z;
  581. this._w = quaternion.w;
  582. this.onChangeCallback();
  583. return this;
  584. },
  585. setFromEuler: function ( euler, update ) {
  586. if ( euler instanceof THREE.Euler === false ) {
  587. throw new Error( 'THREE.Quaternion: .setFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  588. }
  589. // http://www.mathworks.com/matlabcentral/fileexchange/
  590. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  591. // content/SpinCalc.m
  592. var c1 = Math.cos( euler._x / 2 );
  593. var c2 = Math.cos( euler._y / 2 );
  594. var c3 = Math.cos( euler._z / 2 );
  595. var s1 = Math.sin( euler._x / 2 );
  596. var s2 = Math.sin( euler._y / 2 );
  597. var s3 = Math.sin( euler._z / 2 );
  598. var order = euler.order;
  599. if ( order === 'XYZ' ) {
  600. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  601. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  602. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  603. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  604. } else if ( order === 'YXZ' ) {
  605. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  606. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  607. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  608. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  609. } else if ( order === 'ZXY' ) {
  610. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  611. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  612. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  613. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  614. } else if ( order === 'ZYX' ) {
  615. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  616. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  617. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  618. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  619. } else if ( order === 'YZX' ) {
  620. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  621. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  622. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  623. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  624. } else if ( order === 'XZY' ) {
  625. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  626. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  627. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  628. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  629. }
  630. if ( update !== false ) this.onChangeCallback();
  631. return this;
  632. },
  633. setFromAxisAngle: function ( axis, angle ) {
  634. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  635. // assumes axis is normalized
  636. var halfAngle = angle / 2, s = Math.sin( halfAngle );
  637. this._x = axis.x * s;
  638. this._y = axis.y * s;
  639. this._z = axis.z * s;
  640. this._w = Math.cos( halfAngle );
  641. this.onChangeCallback();
  642. return this;
  643. },
  644. setFromRotationMatrix: function ( m ) {
  645. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  646. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  647. var te = m.elements,
  648. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  649. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  650. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ],
  651. trace = m11 + m22 + m33,
  652. s;
  653. if ( trace > 0 ) {
  654. s = 0.5 / Math.sqrt( trace + 1.0 );
  655. this._w = 0.25 / s;
  656. this._x = ( m32 - m23 ) * s;
  657. this._y = ( m13 - m31 ) * s;
  658. this._z = ( m21 - m12 ) * s;
  659. } else if ( m11 > m22 && m11 > m33 ) {
  660. s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );
  661. this._w = ( m32 - m23 ) / s;
  662. this._x = 0.25 * s;
  663. this._y = ( m12 + m21 ) / s;
  664. this._z = ( m13 + m31 ) / s;
  665. } else if ( m22 > m33 ) {
  666. s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );
  667. this._w = ( m13 - m31 ) / s;
  668. this._x = ( m12 + m21 ) / s;
  669. this._y = 0.25 * s;
  670. this._z = ( m23 + m32 ) / s;
  671. } else {
  672. s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );
  673. this._w = ( m21 - m12 ) / s;
  674. this._x = ( m13 + m31 ) / s;
  675. this._y = ( m23 + m32 ) / s;
  676. this._z = 0.25 * s;
  677. }
  678. this.onChangeCallback();
  679. return this;
  680. },
  681. setFromUnitVectors: function () {
  682. // http://lolengine.net/blog/2014/02/24/quaternion-from-two-vectors-final
  683. // assumes direction vectors vFrom and vTo are normalized
  684. var v1, r;
  685. var EPS = 0.000001;
  686. return function ( vFrom, vTo ) {
  687. if ( v1 === undefined ) v1 = new THREE.Vector3();
  688. r = vFrom.dot( vTo ) + 1;
  689. if ( r < EPS ) {
  690. r = 0;
  691. if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) {
  692. v1.set( - vFrom.y, vFrom.x, 0 );
  693. } else {
  694. v1.set( 0, - vFrom.z, vFrom.y );
  695. }
  696. } else {
  697. v1.crossVectors( vFrom, vTo );
  698. }
  699. this._x = v1.x;
  700. this._y = v1.y;
  701. this._z = v1.z;
  702. this._w = r;
  703. return this.normalize();
  704. };
  705. }(),
  706. inverse: function () {
  707. return this.conjugate().normalize();
  708. },
  709. conjugate: function () {
  710. this._x *= - 1;
  711. this._y *= - 1;
  712. this._z *= - 1;
  713. this.onChangeCallback();
  714. return this;
  715. },
  716. dot: function ( v ) {
  717. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  718. },
  719. lengthSq: function () {
  720. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  721. },
  722. length: function () {
  723. return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );
  724. },
  725. normalize: function () {
  726. var l = this.length();
  727. if ( l === 0 ) {
  728. this._x = 0;
  729. this._y = 0;
  730. this._z = 0;
  731. this._w = 1;
  732. } else {
  733. l = 1 / l;
  734. this._x = this._x * l;
  735. this._y = this._y * l;
  736. this._z = this._z * l;
  737. this._w = this._w * l;
  738. }
  739. this.onChangeCallback();
  740. return this;
  741. },
  742. multiply: function ( q, p ) {
  743. if ( p !== undefined ) {
  744. console.warn( 'THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.' );
  745. return this.multiplyQuaternions( q, p );
  746. }
  747. return this.multiplyQuaternions( this, q );
  748. },
  749. premultiply: function ( q ) {
  750. return this.multiplyQuaternions( q, this );
  751. },
  752. multiplyQuaternions: function ( a, b ) {
  753. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  754. var qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
  755. var qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
  756. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  757. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  758. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  759. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  760. this.onChangeCallback();
  761. return this;
  762. },
  763. slerp: function ( qb, t ) {
  764. if ( t === 0 ) return this;
  765. if ( t === 1 ) return this.copy( qb );
  766. var x = this._x, y = this._y, z = this._z, w = this._w;
  767. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  768. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  769. if ( cosHalfTheta < 0 ) {
  770. this._w = - qb._w;
  771. this._x = - qb._x;
  772. this._y = - qb._y;
  773. this._z = - qb._z;
  774. cosHalfTheta = - cosHalfTheta;
  775. } else {
  776. this.copy( qb );
  777. }
  778. if ( cosHalfTheta >= 1.0 ) {
  779. this._w = w;
  780. this._x = x;
  781. this._y = y;
  782. this._z = z;
  783. return this;
  784. }
  785. var sinHalfTheta = Math.sqrt( 1.0 - cosHalfTheta * cosHalfTheta );
  786. if ( Math.abs( sinHalfTheta ) < 0.001 ) {
  787. this._w = 0.5 * ( w + this._w );
  788. this._x = 0.5 * ( x + this._x );
  789. this._y = 0.5 * ( y + this._y );
  790. this._z = 0.5 * ( z + this._z );
  791. return this;
  792. }
  793. var halfTheta = Math.atan2( sinHalfTheta, cosHalfTheta );
  794. var ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  795. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  796. this._w = ( w * ratioA + this._w * ratioB );
  797. this._x = ( x * ratioA + this._x * ratioB );
  798. this._y = ( y * ratioA + this._y * ratioB );
  799. this._z = ( z * ratioA + this._z * ratioB );
  800. this.onChangeCallback();
  801. return this;
  802. },
  803. equals: function ( quaternion ) {
  804. return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
  805. },
  806. fromArray: function ( array, offset ) {
  807. if ( offset === undefined ) offset = 0;
  808. this._x = array[ offset ];
  809. this._y = array[ offset + 1 ];
  810. this._z = array[ offset + 2 ];
  811. this._w = array[ offset + 3 ];
  812. this.onChangeCallback();
  813. return this;
  814. },
  815. toArray: function ( array, offset ) {
  816. if ( array === undefined ) array = [];
  817. if ( offset === undefined ) offset = 0;
  818. array[ offset ] = this._x;
  819. array[ offset + 1 ] = this._y;
  820. array[ offset + 2 ] = this._z;
  821. array[ offset + 3 ] = this._w;
  822. return array;
  823. },
  824. onChange: function ( callback ) {
  825. this.onChangeCallback = callback;
  826. return this;
  827. },
  828. onChangeCallback: function () {}
  829. };
  830. Object.assign( THREE.Quaternion, {
  831. slerp: function( qa, qb, qm, t ) {
  832. return qm.copy( qa ).slerp( qb, t );
  833. },
  834. slerpFlat: function(
  835. dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t ) {
  836. // fuzz-free, array-based Quaternion SLERP operation
  837. var x0 = src0[ srcOffset0 + 0 ],
  838. y0 = src0[ srcOffset0 + 1 ],
  839. z0 = src0[ srcOffset0 + 2 ],
  840. w0 = src0[ srcOffset0 + 3 ],
  841. x1 = src1[ srcOffset1 + 0 ],
  842. y1 = src1[ srcOffset1 + 1 ],
  843. z1 = src1[ srcOffset1 + 2 ],
  844. w1 = src1[ srcOffset1 + 3 ];
  845. if ( w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1 ) {
  846. var s = 1 - t,
  847. cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  848. dir = ( cos >= 0 ? 1 : - 1 ),
  849. sqrSin = 1 - cos * cos;
  850. // Skip the Slerp for tiny steps to avoid numeric problems:
  851. if ( sqrSin > Number.EPSILON ) {
  852. var sin = Math.sqrt( sqrSin ),
  853. len = Math.atan2( sin, cos * dir );
  854. s = Math.sin( s * len ) / sin;
  855. t = Math.sin( t * len ) / sin;
  856. }
  857. var tDir = t * dir;
  858. x0 = x0 * s + x1 * tDir;
  859. y0 = y0 * s + y1 * tDir;
  860. z0 = z0 * s + z1 * tDir;
  861. w0 = w0 * s + w1 * tDir;
  862. // Normalize in case we just did a lerp:
  863. if ( s === 1 - t ) {
  864. var f = 1 / Math.sqrt( x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0 );
  865. x0 *= f;
  866. y0 *= f;
  867. z0 *= f;
  868. w0 *= f;
  869. }
  870. }
  871. dst[ dstOffset ] = x0;
  872. dst[ dstOffset + 1 ] = y0;
  873. dst[ dstOffset + 2 ] = z0;
  874. dst[ dstOffset + 3 ] = w0;
  875. }
  876. } );
  877. // File:src/math/Vector2.js
  878. /**
  879. * @author mrdoob / http://mrdoob.com/
  880. * @author philogb / http://blog.thejit.org/
  881. * @author egraether / http://egraether.com/
  882. * @author zz85 / http://www.lab4games.net/zz85/blog
  883. */
  884. THREE.Vector2 = function ( x, y ) {
  885. this.x = x || 0;
  886. this.y = y || 0;
  887. };
  888. THREE.Vector2.prototype = {
  889. constructor: THREE.Vector2,
  890. get width() {
  891. return this.x;
  892. },
  893. set width( value ) {
  894. this.x = value;
  895. },
  896. get height() {
  897. return this.y;
  898. },
  899. set height( value ) {
  900. this.y = value;
  901. },
  902. //
  903. set: function ( x, y ) {
  904. this.x = x;
  905. this.y = y;
  906. return this;
  907. },
  908. setScalar: function ( scalar ) {
  909. this.x = scalar;
  910. this.y = scalar;
  911. return this;
  912. },
  913. setX: function ( x ) {
  914. this.x = x;
  915. return this;
  916. },
  917. setY: function ( y ) {
  918. this.y = y;
  919. return this;
  920. },
  921. setComponent: function ( index, value ) {
  922. switch ( index ) {
  923. case 0: this.x = value; break;
  924. case 1: this.y = value; break;
  925. default: throw new Error( 'index is out of range: ' + index );
  926. }
  927. },
  928. getComponent: function ( index ) {
  929. switch ( index ) {
  930. case 0: return this.x;
  931. case 1: return this.y;
  932. default: throw new Error( 'index is out of range: ' + index );
  933. }
  934. },
  935. clone: function () {
  936. return new this.constructor( this.x, this.y );
  937. },
  938. copy: function ( v ) {
  939. this.x = v.x;
  940. this.y = v.y;
  941. return this;
  942. },
  943. add: function ( v, w ) {
  944. if ( w !== undefined ) {
  945. console.warn( 'THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  946. return this.addVectors( v, w );
  947. }
  948. this.x += v.x;
  949. this.y += v.y;
  950. return this;
  951. },
  952. addScalar: function ( s ) {
  953. this.x += s;
  954. this.y += s;
  955. return this;
  956. },
  957. addVectors: function ( a, b ) {
  958. this.x = a.x + b.x;
  959. this.y = a.y + b.y;
  960. return this;
  961. },
  962. addScaledVector: function ( v, s ) {
  963. this.x += v.x * s;
  964. this.y += v.y * s;
  965. return this;
  966. },
  967. sub: function ( v, w ) {
  968. if ( w !== undefined ) {
  969. console.warn( 'THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  970. return this.subVectors( v, w );
  971. }
  972. this.x -= v.x;
  973. this.y -= v.y;
  974. return this;
  975. },
  976. subScalar: function ( s ) {
  977. this.x -= s;
  978. this.y -= s;
  979. return this;
  980. },
  981. subVectors: function ( a, b ) {
  982. this.x = a.x - b.x;
  983. this.y = a.y - b.y;
  984. return this;
  985. },
  986. multiply: function ( v ) {
  987. this.x *= v.x;
  988. this.y *= v.y;
  989. return this;
  990. },
  991. multiplyScalar: function ( scalar ) {
  992. if ( isFinite( scalar ) ) {
  993. this.x *= scalar;
  994. this.y *= scalar;
  995. } else {
  996. this.x = 0;
  997. this.y = 0;
  998. }
  999. return this;
  1000. },
  1001. divide: function ( v ) {
  1002. this.x /= v.x;
  1003. this.y /= v.y;
  1004. return this;
  1005. },
  1006. divideScalar: function ( scalar ) {
  1007. return this.multiplyScalar( 1 / scalar );
  1008. },
  1009. min: function ( v ) {
  1010. this.x = Math.min( this.x, v.x );
  1011. this.y = Math.min( this.y, v.y );
  1012. return this;
  1013. },
  1014. max: function ( v ) {
  1015. this.x = Math.max( this.x, v.x );
  1016. this.y = Math.max( this.y, v.y );
  1017. return this;
  1018. },
  1019. clamp: function ( min, max ) {
  1020. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1021. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1022. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1023. return this;
  1024. },
  1025. clampScalar: function () {
  1026. var min, max;
  1027. return function clampScalar( minVal, maxVal ) {
  1028. if ( min === undefined ) {
  1029. min = new THREE.Vector2();
  1030. max = new THREE.Vector2();
  1031. }
  1032. min.set( minVal, minVal );
  1033. max.set( maxVal, maxVal );
  1034. return this.clamp( min, max );
  1035. };
  1036. }(),
  1037. clampLength: function ( min, max ) {
  1038. var length = this.length();
  1039. return this.multiplyScalar( Math.max( min, Math.min( max, length ) ) / length );
  1040. },
  1041. floor: function () {
  1042. this.x = Math.floor( this.x );
  1043. this.y = Math.floor( this.y );
  1044. return this;
  1045. },
  1046. ceil: function () {
  1047. this.x = Math.ceil( this.x );
  1048. this.y = Math.ceil( this.y );
  1049. return this;
  1050. },
  1051. round: function () {
  1052. this.x = Math.round( this.x );
  1053. this.y = Math.round( this.y );
  1054. return this;
  1055. },
  1056. roundToZero: function () {
  1057. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1058. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1059. return this;
  1060. },
  1061. negate: function () {
  1062. this.x = - this.x;
  1063. this.y = - this.y;
  1064. return this;
  1065. },
  1066. dot: function ( v ) {
  1067. return this.x * v.x + this.y * v.y;
  1068. },
  1069. lengthSq: function () {
  1070. return this.x * this.x + this.y * this.y;
  1071. },
  1072. length: function () {
  1073. return Math.sqrt( this.x * this.x + this.y * this.y );
  1074. },
  1075. lengthManhattan: function() {
  1076. return Math.abs( this.x ) + Math.abs( this.y );
  1077. },
  1078. normalize: function () {
  1079. return this.divideScalar( this.length() );
  1080. },
  1081. angle: function () {
  1082. // computes the angle in radians with respect to the positive x-axis
  1083. var angle = Math.atan2( this.y, this.x );
  1084. if ( angle < 0 ) angle += 2 * Math.PI;
  1085. return angle;
  1086. },
  1087. distanceTo: function ( v ) {
  1088. return Math.sqrt( this.distanceToSquared( v ) );
  1089. },
  1090. distanceToSquared: function ( v ) {
  1091. var dx = this.x - v.x, dy = this.y - v.y;
  1092. return dx * dx + dy * dy;
  1093. },
  1094. setLength: function ( length ) {
  1095. return this.multiplyScalar( length / this.length() );
  1096. },
  1097. lerp: function ( v, alpha ) {
  1098. this.x += ( v.x - this.x ) * alpha;
  1099. this.y += ( v.y - this.y ) * alpha;
  1100. return this;
  1101. },
  1102. lerpVectors: function ( v1, v2, alpha ) {
  1103. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1104. },
  1105. equals: function ( v ) {
  1106. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  1107. },
  1108. fromArray: function ( array, offset ) {
  1109. if ( offset === undefined ) offset = 0;
  1110. this.x = array[ offset ];
  1111. this.y = array[ offset + 1 ];
  1112. return this;
  1113. },
  1114. toArray: function ( array, offset ) {
  1115. if ( array === undefined ) array = [];
  1116. if ( offset === undefined ) offset = 0;
  1117. array[ offset ] = this.x;
  1118. array[ offset + 1 ] = this.y;
  1119. return array;
  1120. },
  1121. fromAttribute: function ( attribute, index, offset ) {
  1122. if ( offset === undefined ) offset = 0;
  1123. index = index * attribute.itemSize + offset;
  1124. this.x = attribute.array[ index ];
  1125. this.y = attribute.array[ index + 1 ];
  1126. return this;
  1127. },
  1128. rotateAround: function ( center, angle ) {
  1129. var c = Math.cos( angle ), s = Math.sin( angle );
  1130. var x = this.x - center.x;
  1131. var y = this.y - center.y;
  1132. this.x = x * c - y * s + center.x;
  1133. this.y = x * s + y * c + center.y;
  1134. return this;
  1135. }
  1136. };
  1137. // File:src/math/Vector3.js
  1138. /**
  1139. * @author mrdoob / http://mrdoob.com/
  1140. * @author *kile / http://kile.stravaganza.org/
  1141. * @author philogb / http://blog.thejit.org/
  1142. * @author mikael emtinger / http://gomo.se/
  1143. * @author egraether / http://egraether.com/
  1144. * @author WestLangley / http://github.com/WestLangley
  1145. */
  1146. THREE.Vector3 = function ( x, y, z ) {
  1147. this.x = x || 0;
  1148. this.y = y || 0;
  1149. this.z = z || 0;
  1150. };
  1151. THREE.Vector3.prototype = {
  1152. constructor: THREE.Vector3,
  1153. set: function ( x, y, z ) {
  1154. this.x = x;
  1155. this.y = y;
  1156. this.z = z;
  1157. return this;
  1158. },
  1159. setScalar: function ( scalar ) {
  1160. this.x = scalar;
  1161. this.y = scalar;
  1162. this.z = scalar;
  1163. return this;
  1164. },
  1165. setX: function ( x ) {
  1166. this.x = x;
  1167. return this;
  1168. },
  1169. setY: function ( y ) {
  1170. this.y = y;
  1171. return this;
  1172. },
  1173. setZ: function ( z ) {
  1174. this.z = z;
  1175. return this;
  1176. },
  1177. setComponent: function ( index, value ) {
  1178. switch ( index ) {
  1179. case 0: this.x = value; break;
  1180. case 1: this.y = value; break;
  1181. case 2: this.z = value; break;
  1182. default: throw new Error( 'index is out of range: ' + index );
  1183. }
  1184. },
  1185. getComponent: function ( index ) {
  1186. switch ( index ) {
  1187. case 0: return this.x;
  1188. case 1: return this.y;
  1189. case 2: return this.z;
  1190. default: throw new Error( 'index is out of range: ' + index );
  1191. }
  1192. },
  1193. clone: function () {
  1194. return new this.constructor( this.x, this.y, this.z );
  1195. },
  1196. copy: function ( v ) {
  1197. this.x = v.x;
  1198. this.y = v.y;
  1199. this.z = v.z;
  1200. return this;
  1201. },
  1202. add: function ( v, w ) {
  1203. if ( w !== undefined ) {
  1204. console.warn( 'THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1205. return this.addVectors( v, w );
  1206. }
  1207. this.x += v.x;
  1208. this.y += v.y;
  1209. this.z += v.z;
  1210. return this;
  1211. },
  1212. addScalar: function ( s ) {
  1213. this.x += s;
  1214. this.y += s;
  1215. this.z += s;
  1216. return this;
  1217. },
  1218. addVectors: function ( a, b ) {
  1219. this.x = a.x + b.x;
  1220. this.y = a.y + b.y;
  1221. this.z = a.z + b.z;
  1222. return this;
  1223. },
  1224. addScaledVector: function ( v, s ) {
  1225. this.x += v.x * s;
  1226. this.y += v.y * s;
  1227. this.z += v.z * s;
  1228. return this;
  1229. },
  1230. sub: function ( v, w ) {
  1231. if ( w !== undefined ) {
  1232. console.warn( 'THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1233. return this.subVectors( v, w );
  1234. }
  1235. this.x -= v.x;
  1236. this.y -= v.y;
  1237. this.z -= v.z;
  1238. return this;
  1239. },
  1240. subScalar: function ( s ) {
  1241. this.x -= s;
  1242. this.y -= s;
  1243. this.z -= s;
  1244. return this;
  1245. },
  1246. subVectors: function ( a, b ) {
  1247. this.x = a.x - b.x;
  1248. this.y = a.y - b.y;
  1249. this.z = a.z - b.z;
  1250. return this;
  1251. },
  1252. multiply: function ( v, w ) {
  1253. if ( w !== undefined ) {
  1254. console.warn( 'THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.' );
  1255. return this.multiplyVectors( v, w );
  1256. }
  1257. this.x *= v.x;
  1258. this.y *= v.y;
  1259. this.z *= v.z;
  1260. return this;
  1261. },
  1262. multiplyScalar: function ( scalar ) {
  1263. if ( isFinite( scalar ) ) {
  1264. this.x *= scalar;
  1265. this.y *= scalar;
  1266. this.z *= scalar;
  1267. } else {
  1268. this.x = 0;
  1269. this.y = 0;
  1270. this.z = 0;
  1271. }
  1272. return this;
  1273. },
  1274. multiplyVectors: function ( a, b ) {
  1275. this.x = a.x * b.x;
  1276. this.y = a.y * b.y;
  1277. this.z = a.z * b.z;
  1278. return this;
  1279. },
  1280. applyEuler: function () {
  1281. var quaternion;
  1282. return function applyEuler( euler ) {
  1283. if ( euler instanceof THREE.Euler === false ) {
  1284. console.error( 'THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  1285. }
  1286. if ( quaternion === undefined ) quaternion = new THREE.Quaternion();
  1287. return this.applyQuaternion( quaternion.setFromEuler( euler ) );
  1288. };
  1289. }(),
  1290. applyAxisAngle: function () {
  1291. var quaternion;
  1292. return function applyAxisAngle( axis, angle ) {
  1293. if ( quaternion === undefined ) quaternion = new THREE.Quaternion();
  1294. return this.applyQuaternion( quaternion.setFromAxisAngle( axis, angle ) );
  1295. };
  1296. }(),
  1297. applyMatrix3: function ( m ) {
  1298. var x = this.x, y = this.y, z = this.z;
  1299. var e = m.elements;
  1300. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
  1301. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
  1302. this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
  1303. return this;
  1304. },
  1305. applyMatrix4: function ( m ) {
  1306. // input: THREE.Matrix4 affine matrix
  1307. var x = this.x, y = this.y, z = this.z;
  1308. var e = m.elements;
  1309. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ];
  1310. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ];
  1311. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ];
  1312. return this;
  1313. },
  1314. applyProjection: function ( m ) {
  1315. // input: THREE.Matrix4 projection matrix
  1316. var x = this.x, y = this.y, z = this.z;
  1317. var e = m.elements;
  1318. var d = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] ); // perspective divide
  1319. this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * d;
  1320. this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * d;
  1321. this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * d;
  1322. return this;
  1323. },
  1324. applyQuaternion: function ( q ) {
  1325. var x = this.x, y = this.y, z = this.z;
  1326. var qx = q.x, qy = q.y, qz = q.z, qw = q.w;
  1327. // calculate quat * vector
  1328. var ix = qw * x + qy * z - qz * y;
  1329. var iy = qw * y + qz * x - qx * z;
  1330. var iz = qw * z + qx * y - qy * x;
  1331. var iw = - qx * x - qy * y - qz * z;
  1332. // calculate result * inverse quat
  1333. this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
  1334. this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
  1335. this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
  1336. return this;
  1337. },
  1338. project: function () {
  1339. var matrix;
  1340. return function project( camera ) {
  1341. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  1342. matrix.multiplyMatrices( camera.projectionMatrix, matrix.getInverse( camera.matrixWorld ) );
  1343. return this.applyProjection( matrix );
  1344. };
  1345. }(),
  1346. unproject: function () {
  1347. var matrix;
  1348. return function unproject( camera ) {
  1349. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  1350. matrix.multiplyMatrices( camera.matrixWorld, matrix.getInverse( camera.projectionMatrix ) );
  1351. return this.applyProjection( matrix );
  1352. };
  1353. }(),
  1354. transformDirection: function ( m ) {
  1355. // input: THREE.Matrix4 affine matrix
  1356. // vector interpreted as a direction
  1357. var x = this.x, y = this.y, z = this.z;
  1358. var e = m.elements;
  1359. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
  1360. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
  1361. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
  1362. return this.normalize();
  1363. },
  1364. divide: function ( v ) {
  1365. this.x /= v.x;
  1366. this.y /= v.y;
  1367. this.z /= v.z;
  1368. return this;
  1369. },
  1370. divideScalar: function ( scalar ) {
  1371. return this.multiplyScalar( 1 / scalar );
  1372. },
  1373. min: function ( v ) {
  1374. this.x = Math.min( this.x, v.x );
  1375. this.y = Math.min( this.y, v.y );
  1376. this.z = Math.min( this.z, v.z );
  1377. return this;
  1378. },
  1379. max: function ( v ) {
  1380. this.x = Math.max( this.x, v.x );
  1381. this.y = Math.max( this.y, v.y );
  1382. this.z = Math.max( this.z, v.z );
  1383. return this;
  1384. },
  1385. clamp: function ( min, max ) {
  1386. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1387. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1388. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1389. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  1390. return this;
  1391. },
  1392. clampScalar: function () {
  1393. var min, max;
  1394. return function clampScalar( minVal, maxVal ) {
  1395. if ( min === undefined ) {
  1396. min = new THREE.Vector3();
  1397. max = new THREE.Vector3();
  1398. }
  1399. min.set( minVal, minVal, minVal );
  1400. max.set( maxVal, maxVal, maxVal );
  1401. return this.clamp( min, max );
  1402. };
  1403. }(),
  1404. clampLength: function ( min, max ) {
  1405. var length = this.length();
  1406. return this.multiplyScalar( Math.max( min, Math.min( max, length ) ) / length );
  1407. },
  1408. floor: function () {
  1409. this.x = Math.floor( this.x );
  1410. this.y = Math.floor( this.y );
  1411. this.z = Math.floor( this.z );
  1412. return this;
  1413. },
  1414. ceil: function () {
  1415. this.x = Math.ceil( this.x );
  1416. this.y = Math.ceil( this.y );
  1417. this.z = Math.ceil( this.z );
  1418. return this;
  1419. },
  1420. round: function () {
  1421. this.x = Math.round( this.x );
  1422. this.y = Math.round( this.y );
  1423. this.z = Math.round( this.z );
  1424. return this;
  1425. },
  1426. roundToZero: function () {
  1427. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1428. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1429. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1430. return this;
  1431. },
  1432. negate: function () {
  1433. this.x = - this.x;
  1434. this.y = - this.y;
  1435. this.z = - this.z;
  1436. return this;
  1437. },
  1438. dot: function ( v ) {
  1439. return this.x * v.x + this.y * v.y + this.z * v.z;
  1440. },
  1441. lengthSq: function () {
  1442. return this.x * this.x + this.y * this.y + this.z * this.z;
  1443. },
  1444. length: function () {
  1445. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
  1446. },
  1447. lengthManhattan: function () {
  1448. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  1449. },
  1450. normalize: function () {
  1451. return this.divideScalar( this.length() );
  1452. },
  1453. setLength: function ( length ) {
  1454. return this.multiplyScalar( length / this.length() );
  1455. },
  1456. lerp: function ( v, alpha ) {
  1457. this.x += ( v.x - this.x ) * alpha;
  1458. this.y += ( v.y - this.y ) * alpha;
  1459. this.z += ( v.z - this.z ) * alpha;
  1460. return this;
  1461. },
  1462. lerpVectors: function ( v1, v2, alpha ) {
  1463. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1464. },
  1465. cross: function ( v, w ) {
  1466. if ( w !== undefined ) {
  1467. console.warn( 'THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.' );
  1468. return this.crossVectors( v, w );
  1469. }
  1470. var x = this.x, y = this.y, z = this.z;
  1471. this.x = y * v.z - z * v.y;
  1472. this.y = z * v.x - x * v.z;
  1473. this.z = x * v.y - y * v.x;
  1474. return this;
  1475. },
  1476. crossVectors: function ( a, b ) {
  1477. var ax = a.x, ay = a.y, az = a.z;
  1478. var bx = b.x, by = b.y, bz = b.z;
  1479. this.x = ay * bz - az * by;
  1480. this.y = az * bx - ax * bz;
  1481. this.z = ax * by - ay * bx;
  1482. return this;
  1483. },
  1484. projectOnVector: function () {
  1485. var v1, dot;
  1486. return function projectOnVector( vector ) {
  1487. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1488. v1.copy( vector ).normalize();
  1489. dot = this.dot( v1 );
  1490. return this.copy( v1 ).multiplyScalar( dot );
  1491. };
  1492. }(),
  1493. projectOnPlane: function () {
  1494. var v1;
  1495. return function projectOnPlane( planeNormal ) {
  1496. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1497. v1.copy( this ).projectOnVector( planeNormal );
  1498. return this.sub( v1 );
  1499. };
  1500. }(),
  1501. reflect: function () {
  1502. // reflect incident vector off plane orthogonal to normal
  1503. // normal is assumed to have unit length
  1504. var v1;
  1505. return function reflect( normal ) {
  1506. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1507. return this.sub( v1.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
  1508. };
  1509. }(),
  1510. angleTo: function ( v ) {
  1511. var theta = this.dot( v ) / ( Math.sqrt( this.lengthSq() * v.lengthSq() ) );
  1512. // clamp, to handle numerical problems
  1513. return Math.acos( THREE.Math.clamp( theta, - 1, 1 ) );
  1514. },
  1515. distanceTo: function ( v ) {
  1516. return Math.sqrt( this.distanceToSquared( v ) );
  1517. },
  1518. distanceToSquared: function ( v ) {
  1519. var dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;
  1520. return dx * dx + dy * dy + dz * dz;
  1521. },
  1522. setFromSpherical: function( s ) {
  1523. var sinPhiRadius = Math.sin( s.phi ) * s.radius;
  1524. this.x = sinPhiRadius * Math.sin( s.theta );
  1525. this.y = Math.cos( s.phi ) * s.radius;
  1526. this.z = sinPhiRadius * Math.cos( s.theta );
  1527. return this;
  1528. },
  1529. setFromMatrixPosition: function ( m ) {
  1530. return this.setFromMatrixColumn( m, 3 );
  1531. },
  1532. setFromMatrixScale: function ( m ) {
  1533. var sx = this.setFromMatrixColumn( m, 0 ).length();
  1534. var sy = this.setFromMatrixColumn( m, 1 ).length();
  1535. var sz = this.setFromMatrixColumn( m, 2 ).length();
  1536. this.x = sx;
  1537. this.y = sy;
  1538. this.z = sz;
  1539. return this;
  1540. },
  1541. setFromMatrixColumn: function ( m, index ) {
  1542. if ( typeof m === 'number' ) {
  1543. console.warn( 'THREE.Vector3: setFromMatrixColumn now expects ( matrix, index ).' );
  1544. var temp = m
  1545. m = index;
  1546. index = temp;
  1547. }
  1548. return this.fromArray( m.elements, index * 4 );
  1549. },
  1550. equals: function ( v ) {
  1551. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  1552. },
  1553. fromArray: function ( array, offset ) {
  1554. if ( offset === undefined ) offset = 0;
  1555. this.x = array[ offset ];
  1556. this.y = array[ offset + 1 ];
  1557. this.z = array[ offset + 2 ];
  1558. return this;
  1559. },
  1560. toArray: function ( array, offset ) {
  1561. if ( array === undefined ) array = [];
  1562. if ( offset === undefined ) offset = 0;
  1563. array[ offset ] = this.x;
  1564. array[ offset + 1 ] = this.y;
  1565. array[ offset + 2 ] = this.z;
  1566. return array;
  1567. },
  1568. fromAttribute: function ( attribute, index, offset ) {
  1569. if ( offset === undefined ) offset = 0;
  1570. index = index * attribute.itemSize + offset;
  1571. this.x = attribute.array[ index ];
  1572. this.y = attribute.array[ index + 1 ];
  1573. this.z = attribute.array[ index + 2 ];
  1574. return this;
  1575. }
  1576. };
  1577. // File:src/math/Vector4.js
  1578. /**
  1579. * @author supereggbert / http://www.paulbrunt.co.uk/
  1580. * @author philogb / http://blog.thejit.org/
  1581. * @author mikael emtinger / http://gomo.se/
  1582. * @author egraether / http://egraether.com/
  1583. * @author WestLangley / http://github.com/WestLangley
  1584. */
  1585. THREE.Vector4 = function ( x, y, z, w ) {
  1586. this.x = x || 0;
  1587. this.y = y || 0;
  1588. this.z = z || 0;
  1589. this.w = ( w !== undefined ) ? w : 1;
  1590. };
  1591. THREE.Vector4.prototype = {
  1592. constructor: THREE.Vector4,
  1593. set: function ( x, y, z, w ) {
  1594. this.x = x;
  1595. this.y = y;
  1596. this.z = z;
  1597. this.w = w;
  1598. return this;
  1599. },
  1600. setScalar: function ( scalar ) {
  1601. this.x = scalar;
  1602. this.y = scalar;
  1603. this.z = scalar;
  1604. this.w = scalar;
  1605. return this;
  1606. },
  1607. setX: function ( x ) {
  1608. this.x = x;
  1609. return this;
  1610. },
  1611. setY: function ( y ) {
  1612. this.y = y;
  1613. return this;
  1614. },
  1615. setZ: function ( z ) {
  1616. this.z = z;
  1617. return this;
  1618. },
  1619. setW: function ( w ) {
  1620. this.w = w;
  1621. return this;
  1622. },
  1623. setComponent: function ( index, value ) {
  1624. switch ( index ) {
  1625. case 0: this.x = value; break;
  1626. case 1: this.y = value; break;
  1627. case 2: this.z = value; break;
  1628. case 3: this.w = value; break;
  1629. default: throw new Error( 'index is out of range: ' + index );
  1630. }
  1631. },
  1632. getComponent: function ( index ) {
  1633. switch ( index ) {
  1634. case 0: return this.x;
  1635. case 1: return this.y;
  1636. case 2: return this.z;
  1637. case 3: return this.w;
  1638. default: throw new Error( 'index is out of range: ' + index );
  1639. }
  1640. },
  1641. clone: function () {
  1642. return new this.constructor( this.x, this.y, this.z, this.w );
  1643. },
  1644. copy: function ( v ) {
  1645. this.x = v.x;
  1646. this.y = v.y;
  1647. this.z = v.z;
  1648. this.w = ( v.w !== undefined ) ? v.w : 1;
  1649. return this;
  1650. },
  1651. add: function ( v, w ) {
  1652. if ( w !== undefined ) {
  1653. console.warn( 'THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1654. return this.addVectors( v, w );
  1655. }
  1656. this.x += v.x;
  1657. this.y += v.y;
  1658. this.z += v.z;
  1659. this.w += v.w;
  1660. return this;
  1661. },
  1662. addScalar: function ( s ) {
  1663. this.x += s;
  1664. this.y += s;
  1665. this.z += s;
  1666. this.w += s;
  1667. return this;
  1668. },
  1669. addVectors: function ( a, b ) {
  1670. this.x = a.x + b.x;
  1671. this.y = a.y + b.y;
  1672. this.z = a.z + b.z;
  1673. this.w = a.w + b.w;
  1674. return this;
  1675. },
  1676. addScaledVector: function ( v, s ) {
  1677. this.x += v.x * s;
  1678. this.y += v.y * s;
  1679. this.z += v.z * s;
  1680. this.w += v.w * s;
  1681. return this;
  1682. },
  1683. sub: function ( v, w ) {
  1684. if ( w !== undefined ) {
  1685. console.warn( 'THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1686. return this.subVectors( v, w );
  1687. }
  1688. this.x -= v.x;
  1689. this.y -= v.y;
  1690. this.z -= v.z;
  1691. this.w -= v.w;
  1692. return this;
  1693. },
  1694. subScalar: function ( s ) {
  1695. this.x -= s;
  1696. this.y -= s;
  1697. this.z -= s;
  1698. this.w -= s;
  1699. return this;
  1700. },
  1701. subVectors: function ( a, b ) {
  1702. this.x = a.x - b.x;
  1703. this.y = a.y - b.y;
  1704. this.z = a.z - b.z;
  1705. this.w = a.w - b.w;
  1706. return this;
  1707. },
  1708. multiplyScalar: function ( scalar ) {
  1709. if ( isFinite( scalar ) ) {
  1710. this.x *= scalar;
  1711. this.y *= scalar;
  1712. this.z *= scalar;
  1713. this.w *= scalar;
  1714. } else {
  1715. this.x = 0;
  1716. this.y = 0;
  1717. this.z = 0;
  1718. this.w = 0;
  1719. }
  1720. return this;
  1721. },
  1722. applyMatrix4: function ( m ) {
  1723. var x = this.x, y = this.y, z = this.z, w = this.w;
  1724. var e = m.elements;
  1725. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  1726. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  1727. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  1728. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  1729. return this;
  1730. },
  1731. divideScalar: function ( scalar ) {
  1732. return this.multiplyScalar( 1 / scalar );
  1733. },
  1734. setAxisAngleFromQuaternion: function ( q ) {
  1735. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  1736. // q is assumed to be normalized
  1737. this.w = 2 * Math.acos( q.w );
  1738. var s = Math.sqrt( 1 - q.w * q.w );
  1739. if ( s < 0.0001 ) {
  1740. this.x = 1;
  1741. this.y = 0;
  1742. this.z = 0;
  1743. } else {
  1744. this.x = q.x / s;
  1745. this.y = q.y / s;
  1746. this.z = q.z / s;
  1747. }
  1748. return this;
  1749. },
  1750. setAxisAngleFromRotationMatrix: function ( m ) {
  1751. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  1752. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1753. var angle, x, y, z, // variables for result
  1754. epsilon = 0.01, // margin to allow for rounding errors
  1755. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  1756. te = m.elements,
  1757. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  1758. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  1759. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  1760. if ( ( Math.abs( m12 - m21 ) < epsilon ) &&
  1761. ( Math.abs( m13 - m31 ) < epsilon ) &&
  1762. ( Math.abs( m23 - m32 ) < epsilon ) ) {
  1763. // singularity found
  1764. // first check for identity matrix which must have +1 for all terms
  1765. // in leading diagonal and zero in other terms
  1766. if ( ( Math.abs( m12 + m21 ) < epsilon2 ) &&
  1767. ( Math.abs( m13 + m31 ) < epsilon2 ) &&
  1768. ( Math.abs( m23 + m32 ) < epsilon2 ) &&
  1769. ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  1770. // this singularity is identity matrix so angle = 0
  1771. this.set( 1, 0, 0, 0 );
  1772. return this; // zero angle, arbitrary axis
  1773. }
  1774. // otherwise this singularity is angle = 180
  1775. angle = Math.PI;
  1776. var xx = ( m11 + 1 ) / 2;
  1777. var yy = ( m22 + 1 ) / 2;
  1778. var zz = ( m33 + 1 ) / 2;
  1779. var xy = ( m12 + m21 ) / 4;
  1780. var xz = ( m13 + m31 ) / 4;
  1781. var yz = ( m23 + m32 ) / 4;
  1782. if ( ( xx > yy ) && ( xx > zz ) ) {
  1783. // m11 is the largest diagonal term
  1784. if ( xx < epsilon ) {
  1785. x = 0;
  1786. y = 0.707106781;
  1787. z = 0.707106781;
  1788. } else {
  1789. x = Math.sqrt( xx );
  1790. y = xy / x;
  1791. z = xz / x;
  1792. }
  1793. } else if ( yy > zz ) {
  1794. // m22 is the largest diagonal term
  1795. if ( yy < epsilon ) {
  1796. x = 0.707106781;
  1797. y = 0;
  1798. z = 0.707106781;
  1799. } else {
  1800. y = Math.sqrt( yy );
  1801. x = xy / y;
  1802. z = yz / y;
  1803. }
  1804. } else {
  1805. // m33 is the largest diagonal term so base result on this
  1806. if ( zz < epsilon ) {
  1807. x = 0.707106781;
  1808. y = 0.707106781;
  1809. z = 0;
  1810. } else {
  1811. z = Math.sqrt( zz );
  1812. x = xz / z;
  1813. y = yz / z;
  1814. }
  1815. }
  1816. this.set( x, y, z, angle );
  1817. return this; // return 180 deg rotation
  1818. }
  1819. // as we have reached here there are no singularities so we can handle normally
  1820. var s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 ) +
  1821. ( m13 - m31 ) * ( m13 - m31 ) +
  1822. ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  1823. if ( Math.abs( s ) < 0.001 ) s = 1;
  1824. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  1825. // caught by singularity test above, but I've left it in just in case
  1826. this.x = ( m32 - m23 ) / s;
  1827. this.y = ( m13 - m31 ) / s;
  1828. this.z = ( m21 - m12 ) / s;
  1829. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  1830. return this;
  1831. },
  1832. min: function ( v ) {
  1833. this.x = Math.min( this.x, v.x );
  1834. this.y = Math.min( this.y, v.y );
  1835. this.z = Math.min( this.z, v.z );
  1836. this.w = Math.min( this.w, v.w );
  1837. return this;
  1838. },
  1839. max: function ( v ) {
  1840. this.x = Math.max( this.x, v.x );
  1841. this.y = Math.max( this.y, v.y );
  1842. this.z = Math.max( this.z, v.z );
  1843. this.w = Math.max( this.w, v.w );
  1844. return this;
  1845. },
  1846. clamp: function ( min, max ) {
  1847. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1848. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1849. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1850. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  1851. this.w = Math.max( min.w, Math.min( max.w, this.w ) );
  1852. return this;
  1853. },
  1854. clampScalar: function () {
  1855. var min, max;
  1856. return function clampScalar( minVal, maxVal ) {
  1857. if ( min === undefined ) {
  1858. min = new THREE.Vector4();
  1859. max = new THREE.Vector4();
  1860. }
  1861. min.set( minVal, minVal, minVal, minVal );
  1862. max.set( maxVal, maxVal, maxVal, maxVal );
  1863. return this.clamp( min, max );
  1864. };
  1865. }(),
  1866. floor: function () {
  1867. this.x = Math.floor( this.x );
  1868. this.y = Math.floor( this.y );
  1869. this.z = Math.floor( this.z );
  1870. this.w = Math.floor( this.w );
  1871. return this;
  1872. },
  1873. ceil: function () {
  1874. this.x = Math.ceil( this.x );
  1875. this.y = Math.ceil( this.y );
  1876. this.z = Math.ceil( this.z );
  1877. this.w = Math.ceil( this.w );
  1878. return this;
  1879. },
  1880. round: function () {
  1881. this.x = Math.round( this.x );
  1882. this.y = Math.round( this.y );
  1883. this.z = Math.round( this.z );
  1884. this.w = Math.round( this.w );
  1885. return this;
  1886. },
  1887. roundToZero: function () {
  1888. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1889. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1890. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1891. this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
  1892. return this;
  1893. },
  1894. negate: function () {
  1895. this.x = - this.x;
  1896. this.y = - this.y;
  1897. this.z = - this.z;
  1898. this.w = - this.w;
  1899. return this;
  1900. },
  1901. dot: function ( v ) {
  1902. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  1903. },
  1904. lengthSq: function () {
  1905. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  1906. },
  1907. length: function () {
  1908. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  1909. },
  1910. lengthManhattan: function () {
  1911. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  1912. },
  1913. normalize: function () {
  1914. return this.divideScalar( this.length() );
  1915. },
  1916. setLength: function ( length ) {
  1917. return this.multiplyScalar( length / this.length() );
  1918. },
  1919. lerp: function ( v, alpha ) {
  1920. this.x += ( v.x - this.x ) * alpha;
  1921. this.y += ( v.y - this.y ) * alpha;
  1922. this.z += ( v.z - this.z ) * alpha;
  1923. this.w += ( v.w - this.w ) * alpha;
  1924. return this;
  1925. },
  1926. lerpVectors: function ( v1, v2, alpha ) {
  1927. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1928. },
  1929. equals: function ( v ) {
  1930. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  1931. },
  1932. fromArray: function ( array, offset ) {
  1933. if ( offset === undefined ) offset = 0;
  1934. this.x = array[ offset ];
  1935. this.y = array[ offset + 1 ];
  1936. this.z = array[ offset + 2 ];
  1937. this.w = array[ offset + 3 ];
  1938. return this;
  1939. },
  1940. toArray: function ( array, offset ) {
  1941. if ( array === undefined ) array = [];
  1942. if ( offset === undefined ) offset = 0;
  1943. array[ offset ] = this.x;
  1944. array[ offset + 1 ] = this.y;
  1945. array[ offset + 2 ] = this.z;
  1946. array[ offset + 3 ] = this.w;
  1947. return array;
  1948. },
  1949. fromAttribute: function ( attribute, index, offset ) {
  1950. if ( offset === undefined ) offset = 0;
  1951. index = index * attribute.itemSize + offset;
  1952. this.x = attribute.array[ index ];
  1953. this.y = attribute.array[ index + 1 ];
  1954. this.z = attribute.array[ index + 2 ];
  1955. this.w = attribute.array[ index + 3 ];
  1956. return this;
  1957. }
  1958. };
  1959. // File:src/math/Euler.js
  1960. /**
  1961. * @author mrdoob / http://mrdoob.com/
  1962. * @author WestLangley / http://github.com/WestLangley
  1963. * @author bhouston / http://clara.io
  1964. */
  1965. THREE.Euler = function ( x, y, z, order ) {
  1966. this._x = x || 0;
  1967. this._y = y || 0;
  1968. this._z = z || 0;
  1969. this._order = order || THREE.Euler.DefaultOrder;
  1970. };
  1971. THREE.Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
  1972. THREE.Euler.DefaultOrder = 'XYZ';
  1973. THREE.Euler.prototype = {
  1974. constructor: THREE.Euler,
  1975. get x () {
  1976. return this._x;
  1977. },
  1978. set x ( value ) {
  1979. this._x = value;
  1980. this.onChangeCallback();
  1981. },
  1982. get y () {
  1983. return this._y;
  1984. },
  1985. set y ( value ) {
  1986. this._y = value;
  1987. this.onChangeCallback();
  1988. },
  1989. get z () {
  1990. return this._z;
  1991. },
  1992. set z ( value ) {
  1993. this._z = value;
  1994. this.onChangeCallback();
  1995. },
  1996. get order () {
  1997. return this._order;
  1998. },
  1999. set order ( value ) {
  2000. this._order = value;
  2001. this.onChangeCallback();
  2002. },
  2003. set: function ( x, y, z, order ) {
  2004. this._x = x;
  2005. this._y = y;
  2006. this._z = z;
  2007. this._order = order || this._order;
  2008. this.onChangeCallback();
  2009. return this;
  2010. },
  2011. clone: function () {
  2012. return new this.constructor( this._x, this._y, this._z, this._order );
  2013. },
  2014. copy: function ( euler ) {
  2015. this._x = euler._x;
  2016. this._y = euler._y;
  2017. this._z = euler._z;
  2018. this._order = euler._order;
  2019. this.onChangeCallback();
  2020. return this;
  2021. },
  2022. setFromRotationMatrix: function ( m, order, update ) {
  2023. var clamp = THREE.Math.clamp;
  2024. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2025. var te = m.elements;
  2026. var m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  2027. var m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  2028. var m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  2029. order = order || this._order;
  2030. if ( order === 'XYZ' ) {
  2031. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  2032. if ( Math.abs( m13 ) < 0.99999 ) {
  2033. this._x = Math.atan2( - m23, m33 );
  2034. this._z = Math.atan2( - m12, m11 );
  2035. } else {
  2036. this._x = Math.atan2( m32, m22 );
  2037. this._z = 0;
  2038. }
  2039. } else if ( order === 'YXZ' ) {
  2040. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  2041. if ( Math.abs( m23 ) < 0.99999 ) {
  2042. this._y = Math.atan2( m13, m33 );
  2043. this._z = Math.atan2( m21, m22 );
  2044. } else {
  2045. this._y = Math.atan2( - m31, m11 );
  2046. this._z = 0;
  2047. }
  2048. } else if ( order === 'ZXY' ) {
  2049. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  2050. if ( Math.abs( m32 ) < 0.99999 ) {
  2051. this._y = Math.atan2( - m31, m33 );
  2052. this._z = Math.atan2( - m12, m22 );
  2053. } else {
  2054. this._y = 0;
  2055. this._z = Math.atan2( m21, m11 );
  2056. }
  2057. } else if ( order === 'ZYX' ) {
  2058. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  2059. if ( Math.abs( m31 ) < 0.99999 ) {
  2060. this._x = Math.atan2( m32, m33 );
  2061. this._z = Math.atan2( m21, m11 );
  2062. } else {
  2063. this._x = 0;
  2064. this._z = Math.atan2( - m12, m22 );
  2065. }
  2066. } else if ( order === 'YZX' ) {
  2067. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  2068. if ( Math.abs( m21 ) < 0.99999 ) {
  2069. this._x = Math.atan2( - m23, m22 );
  2070. this._y = Math.atan2( - m31, m11 );
  2071. } else {
  2072. this._x = 0;
  2073. this._y = Math.atan2( m13, m33 );
  2074. }
  2075. } else if ( order === 'XZY' ) {
  2076. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  2077. if ( Math.abs( m12 ) < 0.99999 ) {
  2078. this._x = Math.atan2( m32, m22 );
  2079. this._y = Math.atan2( m13, m11 );
  2080. } else {
  2081. this._x = Math.atan2( - m23, m33 );
  2082. this._y = 0;
  2083. }
  2084. } else {
  2085. console.warn( 'THREE.Euler: .setFromRotationMatrix() given unsupported order: ' + order );
  2086. }
  2087. this._order = order;
  2088. if ( update !== false ) this.onChangeCallback();
  2089. return this;
  2090. },
  2091. setFromQuaternion: function () {
  2092. var matrix;
  2093. return function ( q, order, update ) {
  2094. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  2095. matrix.makeRotationFromQuaternion( q );
  2096. return this.setFromRotationMatrix( matrix, order, update );
  2097. };
  2098. }(),
  2099. setFromVector3: function ( v, order ) {
  2100. return this.set( v.x, v.y, v.z, order || this._order );
  2101. },
  2102. reorder: function () {
  2103. // WARNING: this discards revolution information -bhouston
  2104. var q = new THREE.Quaternion();
  2105. return function ( newOrder ) {
  2106. q.setFromEuler( this );
  2107. return this.setFromQuaternion( q, newOrder );
  2108. };
  2109. }(),
  2110. equals: function ( euler ) {
  2111. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  2112. },
  2113. fromArray: function ( array ) {
  2114. this._x = array[ 0 ];
  2115. this._y = array[ 1 ];
  2116. this._z = array[ 2 ];
  2117. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  2118. this.onChangeCallback();
  2119. return this;
  2120. },
  2121. toArray: function ( array, offset ) {
  2122. if ( array === undefined ) array = [];
  2123. if ( offset === undefined ) offset = 0;
  2124. array[ offset ] = this._x;
  2125. array[ offset + 1 ] = this._y;
  2126. array[ offset + 2 ] = this._z;
  2127. array[ offset + 3 ] = this._order;
  2128. return array;
  2129. },
  2130. toVector3: function ( optionalResult ) {
  2131. if ( optionalResult ) {
  2132. return optionalResult.set( this._x, this._y, this._z );
  2133. } else {
  2134. return new THREE.Vector3( this._x, this._y, this._z );
  2135. }
  2136. },
  2137. onChange: function ( callback ) {
  2138. this.onChangeCallback = callback;
  2139. return this;
  2140. },
  2141. onChangeCallback: function () {}
  2142. };
  2143. // File:src/math/Line3.js
  2144. /**
  2145. * @author bhouston / http://clara.io
  2146. */
  2147. THREE.Line3 = function ( start, end ) {
  2148. this.start = ( start !== undefined ) ? start : new THREE.Vector3();
  2149. this.end = ( end !== undefined ) ? end : new THREE.Vector3();
  2150. };
  2151. THREE.Line3.prototype = {
  2152. constructor: THREE.Line3,
  2153. set: function ( start, end ) {
  2154. this.start.copy( start );
  2155. this.end.copy( end );
  2156. return this;
  2157. },
  2158. clone: function () {
  2159. return new this.constructor().copy( this );
  2160. },
  2161. copy: function ( line ) {
  2162. this.start.copy( line.start );
  2163. this.end.copy( line.end );
  2164. return this;
  2165. },
  2166. center: function ( optionalTarget ) {
  2167. var result = optionalTarget || new THREE.Vector3();
  2168. return result.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  2169. },
  2170. delta: function ( optionalTarget ) {
  2171. var result = optionalTarget || new THREE.Vector3();
  2172. return result.subVectors( this.end, this.start );
  2173. },
  2174. distanceSq: function () {
  2175. return this.start.distanceToSquared( this.end );
  2176. },
  2177. distance: function () {
  2178. return this.start.distanceTo( this.end );
  2179. },
  2180. at: function ( t, optionalTarget ) {
  2181. var result = optionalTarget || new THREE.Vector3();
  2182. return this.delta( result ).multiplyScalar( t ).add( this.start );
  2183. },
  2184. closestPointToPointParameter: function () {
  2185. var startP = new THREE.Vector3();
  2186. var startEnd = new THREE.Vector3();
  2187. return function ( point, clampToLine ) {
  2188. startP.subVectors( point, this.start );
  2189. startEnd.subVectors( this.end, this.start );
  2190. var startEnd2 = startEnd.dot( startEnd );
  2191. var startEnd_startP = startEnd.dot( startP );
  2192. var t = startEnd_startP / startEnd2;
  2193. if ( clampToLine ) {
  2194. t = THREE.Math.clamp( t, 0, 1 );
  2195. }
  2196. return t;
  2197. };
  2198. }(),
  2199. closestPointToPoint: function ( point, clampToLine, optionalTarget ) {
  2200. var t = this.closestPointToPointParameter( point, clampToLine );
  2201. var result = optionalTarget || new THREE.Vector3();
  2202. return this.delta( result ).multiplyScalar( t ).add( this.start );
  2203. },
  2204. applyMatrix4: function ( matrix ) {
  2205. this.start.applyMatrix4( matrix );
  2206. this.end.applyMatrix4( matrix );
  2207. return this;
  2208. },
  2209. equals: function ( line ) {
  2210. return line.start.equals( this.start ) && line.end.equals( this.end );
  2211. }
  2212. };
  2213. // File:src/math/Box2.js
  2214. /**
  2215. * @author bhouston / http://clara.io
  2216. */
  2217. THREE.Box2 = function ( min, max ) {
  2218. this.min = ( min !== undefined ) ? min : new THREE.Vector2( + Infinity, + Infinity );
  2219. this.max = ( max !== undefined ) ? max : new THREE.Vector2( - Infinity, - Infinity );
  2220. };
  2221. THREE.Box2.prototype = {
  2222. constructor: THREE.Box2,
  2223. set: function ( min, max ) {
  2224. this.min.copy( min );
  2225. this.max.copy( max );
  2226. return this;
  2227. },
  2228. setFromPoints: function ( points ) {
  2229. this.makeEmpty();
  2230. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2231. this.expandByPoint( points[ i ] );
  2232. }
  2233. return this;
  2234. },
  2235. setFromCenterAndSize: function () {
  2236. var v1 = new THREE.Vector2();
  2237. return function ( center, size ) {
  2238. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2239. this.min.copy( center ).sub( halfSize );
  2240. this.max.copy( center ).add( halfSize );
  2241. return this;
  2242. };
  2243. }(),
  2244. clone: function () {
  2245. return new this.constructor().copy( this );
  2246. },
  2247. copy: function ( box ) {
  2248. this.min.copy( box.min );
  2249. this.max.copy( box.max );
  2250. return this;
  2251. },
  2252. makeEmpty: function () {
  2253. this.min.x = this.min.y = + Infinity;
  2254. this.max.x = this.max.y = - Infinity;
  2255. return this;
  2256. },
  2257. isEmpty: function () {
  2258. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2259. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  2260. },
  2261. center: function ( optionalTarget ) {
  2262. var result = optionalTarget || new THREE.Vector2();
  2263. return result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2264. },
  2265. size: function ( optionalTarget ) {
  2266. var result = optionalTarget || new THREE.Vector2();
  2267. return result.subVectors( this.max, this.min );
  2268. },
  2269. expandByPoint: function ( point ) {
  2270. this.min.min( point );
  2271. this.max.max( point );
  2272. return this;
  2273. },
  2274. expandByVector: function ( vector ) {
  2275. this.min.sub( vector );
  2276. this.max.add( vector );
  2277. return this;
  2278. },
  2279. expandByScalar: function ( scalar ) {
  2280. this.min.addScalar( - scalar );
  2281. this.max.addScalar( scalar );
  2282. return this;
  2283. },
  2284. containsPoint: function ( point ) {
  2285. if ( point.x < this.min.x || point.x > this.max.x ||
  2286. point.y < this.min.y || point.y > this.max.y ) {
  2287. return false;
  2288. }
  2289. return true;
  2290. },
  2291. containsBox: function ( box ) {
  2292. if ( ( this.min.x <= box.min.x ) && ( box.max.x <= this.max.x ) &&
  2293. ( this.min.y <= box.min.y ) && ( box.max.y <= this.max.y ) ) {
  2294. return true;
  2295. }
  2296. return false;
  2297. },
  2298. getParameter: function ( point, optionalTarget ) {
  2299. // This can potentially have a divide by zero if the box
  2300. // has a size dimension of 0.
  2301. var result = optionalTarget || new THREE.Vector2();
  2302. return result.set(
  2303. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2304. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  2305. );
  2306. },
  2307. intersectsBox: function ( box ) {
  2308. // using 6 splitting planes to rule out intersections.
  2309. if ( box.max.x < this.min.x || box.min.x > this.max.x ||
  2310. box.max.y < this.min.y || box.min.y > this.max.y ) {
  2311. return false;
  2312. }
  2313. return true;
  2314. },
  2315. clampPoint: function ( point, optionalTarget ) {
  2316. var result = optionalTarget || new THREE.Vector2();
  2317. return result.copy( point ).clamp( this.min, this.max );
  2318. },
  2319. distanceToPoint: function () {
  2320. var v1 = new THREE.Vector2();
  2321. return function ( point ) {
  2322. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  2323. return clampedPoint.sub( point ).length();
  2324. };
  2325. }(),
  2326. intersect: function ( box ) {
  2327. this.min.max( box.min );
  2328. this.max.min( box.max );
  2329. return this;
  2330. },
  2331. union: function ( box ) {
  2332. this.min.min( box.min );
  2333. this.max.max( box.max );
  2334. return this;
  2335. },
  2336. translate: function ( offset ) {
  2337. this.min.add( offset );
  2338. this.max.add( offset );
  2339. return this;
  2340. },
  2341. equals: function ( box ) {
  2342. return box.min.equals( this.min ) && box.max.equals( this.max );
  2343. }
  2344. };
  2345. // File:src/math/Box3.js
  2346. /**
  2347. * @author bhouston / http://clara.io
  2348. * @author WestLangley / http://github.com/WestLangley
  2349. */
  2350. THREE.Box3 = function ( min, max ) {
  2351. this.min = ( min !== undefined ) ? min : new THREE.Vector3( + Infinity, + Infinity, + Infinity );
  2352. this.max = ( max !== undefined ) ? max : new THREE.Vector3( - Infinity, - Infinity, - Infinity );
  2353. };
  2354. THREE.Box3.prototype = {
  2355. constructor: THREE.Box3,
  2356. set: function ( min, max ) {
  2357. this.min.copy( min );
  2358. this.max.copy( max );
  2359. return this;
  2360. },
  2361. setFromArray: function ( array ) {
  2362. var minX = + Infinity;
  2363. var minY = + Infinity;
  2364. var minZ = + Infinity;
  2365. var maxX = - Infinity;
  2366. var maxY = - Infinity;
  2367. var maxZ = - Infinity;
  2368. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  2369. var x = array[ i ];
  2370. var y = array[ i + 1 ];
  2371. var z = array[ i + 2 ];
  2372. if ( x < minX ) minX = x;
  2373. if ( y < minY ) minY = y;
  2374. if ( z < minZ ) minZ = z;
  2375. if ( x > maxX ) maxX = x;
  2376. if ( y > maxY ) maxY = y;
  2377. if ( z > maxZ ) maxZ = z;
  2378. }
  2379. this.min.set( minX, minY, minZ );
  2380. this.max.set( maxX, maxY, maxZ );
  2381. },
  2382. setFromPoints: function ( points ) {
  2383. this.makeEmpty();
  2384. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2385. this.expandByPoint( points[ i ] );
  2386. }
  2387. return this;
  2388. },
  2389. setFromCenterAndSize: function () {
  2390. var v1 = new THREE.Vector3();
  2391. return function ( center, size ) {
  2392. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2393. this.min.copy( center ).sub( halfSize );
  2394. this.max.copy( center ).add( halfSize );
  2395. return this;
  2396. };
  2397. }(),
  2398. setFromObject: function () {
  2399. // Computes the world-axis-aligned bounding box of an object (including its children),
  2400. // accounting for both the object's, and children's, world transforms
  2401. var v1 = new THREE.Vector3();
  2402. return function ( object ) {
  2403. var scope = this;
  2404. object.updateMatrixWorld( true );
  2405. this.makeEmpty();
  2406. object.traverse( function ( node ) {
  2407. var geometry = node.geometry;
  2408. if ( geometry !== undefined ) {
  2409. if ( geometry instanceof THREE.Geometry ) {
  2410. var vertices = geometry.vertices;
  2411. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  2412. v1.copy( vertices[ i ] );
  2413. v1.applyMatrix4( node.matrixWorld );
  2414. scope.expandByPoint( v1 );
  2415. }
  2416. } else if ( geometry instanceof THREE.BufferGeometry && geometry.attributes[ 'position' ] !== undefined ) {
  2417. var positions = geometry.attributes[ 'position' ].array;
  2418. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  2419. v1.fromArray( positions, i );
  2420. v1.applyMatrix4( node.matrixWorld );
  2421. scope.expandByPoint( v1 );
  2422. }
  2423. }
  2424. }
  2425. } );
  2426. return this;
  2427. };
  2428. }(),
  2429. clone: function () {
  2430. return new this.constructor().copy( this );
  2431. },
  2432. copy: function ( box ) {
  2433. this.min.copy( box.min );
  2434. this.max.copy( box.max );
  2435. return this;
  2436. },
  2437. makeEmpty: function () {
  2438. this.min.x = this.min.y = this.min.z = + Infinity;
  2439. this.max.x = this.max.y = this.max.z = - Infinity;
  2440. return this;
  2441. },
  2442. isEmpty: function () {
  2443. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2444. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  2445. },
  2446. center: function ( optionalTarget ) {
  2447. var result = optionalTarget || new THREE.Vector3();
  2448. return result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2449. },
  2450. size: function ( optionalTarget ) {
  2451. var result = optionalTarget || new THREE.Vector3();
  2452. return result.subVectors( this.max, this.min );
  2453. },
  2454. expandByPoint: function ( point ) {
  2455. this.min.min( point );
  2456. this.max.max( point );
  2457. return this;
  2458. },
  2459. expandByVector: function ( vector ) {
  2460. this.min.sub( vector );
  2461. this.max.add( vector );
  2462. return this;
  2463. },
  2464. expandByScalar: function ( scalar ) {
  2465. this.min.addScalar( - scalar );
  2466. this.max.addScalar( scalar );
  2467. return this;
  2468. },
  2469. containsPoint: function ( point ) {
  2470. if ( point.x < this.min.x || point.x > this.max.x ||
  2471. point.y < this.min.y || point.y > this.max.y ||
  2472. point.z < this.min.z || point.z > this.max.z ) {
  2473. return false;
  2474. }
  2475. return true;
  2476. },
  2477. containsBox: function ( box ) {
  2478. if ( ( this.min.x <= box.min.x ) && ( box.max.x <= this.max.x ) &&
  2479. ( this.min.y <= box.min.y ) && ( box.max.y <= this.max.y ) &&
  2480. ( this.min.z <= box.min.z ) && ( box.max.z <= this.max.z ) ) {
  2481. return true;
  2482. }
  2483. return false;
  2484. },
  2485. getParameter: function ( point, optionalTarget ) {
  2486. // This can potentially have a divide by zero if the box
  2487. // has a size dimension of 0.
  2488. var result = optionalTarget || new THREE.Vector3();
  2489. return result.set(
  2490. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2491. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  2492. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  2493. );
  2494. },
  2495. intersectsBox: function ( box ) {
  2496. // using 6 splitting planes to rule out intersections.
  2497. if ( box.max.x < this.min.x || box.min.x > this.max.x ||
  2498. box.max.y < this.min.y || box.min.y > this.max.y ||
  2499. box.max.z < this.min.z || box.min.z > this.max.z ) {
  2500. return false;
  2501. }
  2502. return true;
  2503. },
  2504. intersectsSphere: ( function () {
  2505. var closestPoint;
  2506. return function intersectsSphere( sphere ) {
  2507. if ( closestPoint === undefined ) closestPoint = new THREE.Vector3();
  2508. // Find the point on the AABB closest to the sphere center.
  2509. this.clampPoint( sphere.center, closestPoint );
  2510. // If that point is inside the sphere, the AABB and sphere intersect.
  2511. return closestPoint.distanceToSquared( sphere.center ) <= ( sphere.radius * sphere.radius );
  2512. };
  2513. } )(),
  2514. intersectsPlane: function ( plane ) {
  2515. // We compute the minimum and maximum dot product values. If those values
  2516. // are on the same side (back or front) of the plane, then there is no intersection.
  2517. var min, max;
  2518. if ( plane.normal.x > 0 ) {
  2519. min = plane.normal.x * this.min.x;
  2520. max = plane.normal.x * this.max.x;
  2521. } else {
  2522. min = plane.normal.x * this.max.x;
  2523. max = plane.normal.x * this.min.x;
  2524. }
  2525. if ( plane.normal.y > 0 ) {
  2526. min += plane.normal.y * this.min.y;
  2527. max += plane.normal.y * this.max.y;
  2528. } else {
  2529. min += plane.normal.y * this.max.y;
  2530. max += plane.normal.y * this.min.y;
  2531. }
  2532. if ( plane.normal.z > 0 ) {
  2533. min += plane.normal.z * this.min.z;
  2534. max += plane.normal.z * this.max.z;
  2535. } else {
  2536. min += plane.normal.z * this.max.z;
  2537. max += plane.normal.z * this.min.z;
  2538. }
  2539. return ( min <= plane.constant && max >= plane.constant );
  2540. },
  2541. clampPoint: function ( point, optionalTarget ) {
  2542. var result = optionalTarget || new THREE.Vector3();
  2543. return result.copy( point ).clamp( this.min, this.max );
  2544. },
  2545. distanceToPoint: function () {
  2546. var v1 = new THREE.Vector3();
  2547. return function ( point ) {
  2548. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  2549. return clampedPoint.sub( point ).length();
  2550. };
  2551. }(),
  2552. getBoundingSphere: function () {
  2553. var v1 = new THREE.Vector3();
  2554. return function ( optionalTarget ) {
  2555. var result = optionalTarget || new THREE.Sphere();
  2556. result.center = this.center();
  2557. result.radius = this.size( v1 ).length() * 0.5;
  2558. return result;
  2559. };
  2560. }(),
  2561. intersect: function ( box ) {
  2562. this.min.max( box.min );
  2563. this.max.min( box.max );
  2564. // ensure that if there is no overlap, the result is fully empty, not slightly empty with non-inf/+inf values that will cause subsequence intersects to erroneously return valid values.
  2565. if( this.isEmpty() ) this.makeEmpty();
  2566. return this;
  2567. },
  2568. union: function ( box ) {
  2569. this.min.min( box.min );
  2570. this.max.max( box.max );
  2571. return this;
  2572. },
  2573. applyMatrix4: function () {
  2574. var points = [
  2575. new THREE.Vector3(),
  2576. new THREE.Vector3(),
  2577. new THREE.Vector3(),
  2578. new THREE.Vector3(),
  2579. new THREE.Vector3(),
  2580. new THREE.Vector3(),
  2581. new THREE.Vector3(),
  2582. new THREE.Vector3()
  2583. ];
  2584. return function ( matrix ) {
  2585. // transform of empty box is an empty box.
  2586. if( this.isEmpty() ) return this;
  2587. // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  2588. points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
  2589. points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
  2590. points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
  2591. points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
  2592. points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
  2593. points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
  2594. points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
  2595. points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
  2596. this.setFromPoints( points );
  2597. return this;
  2598. };
  2599. }(),
  2600. translate: function ( offset ) {
  2601. this.min.add( offset );
  2602. this.max.add( offset );
  2603. return this;
  2604. },
  2605. equals: function ( box ) {
  2606. return box.min.equals( this.min ) && box.max.equals( this.max );
  2607. }
  2608. };
  2609. // File:src/math/Matrix3.js
  2610. /**
  2611. * @author alteredq / http://alteredqualia.com/
  2612. * @author WestLangley / http://github.com/WestLangley
  2613. * @author bhouston / http://clara.io
  2614. * @author tschw
  2615. */
  2616. THREE.Matrix3 = function () {
  2617. this.elements = new Float32Array( [
  2618. 1, 0, 0,
  2619. 0, 1, 0,
  2620. 0, 0, 1
  2621. ] );
  2622. if ( arguments.length > 0 ) {
  2623. console.error( 'THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.' );
  2624. }
  2625. };
  2626. THREE.Matrix3.prototype = {
  2627. constructor: THREE.Matrix3,
  2628. set: function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  2629. var te = this.elements;
  2630. te[ 0 ] = n11; te[ 1 ] = n21; te[ 2 ] = n31;
  2631. te[ 3 ] = n12; te[ 4 ] = n22; te[ 5 ] = n32;
  2632. te[ 6 ] = n13; te[ 7 ] = n23; te[ 8 ] = n33;
  2633. return this;
  2634. },
  2635. identity: function () {
  2636. this.set(
  2637. 1, 0, 0,
  2638. 0, 1, 0,
  2639. 0, 0, 1
  2640. );
  2641. return this;
  2642. },
  2643. clone: function () {
  2644. return new this.constructor().fromArray( this.elements );
  2645. },
  2646. copy: function ( m ) {
  2647. var me = m.elements;
  2648. this.set(
  2649. me[ 0 ], me[ 3 ], me[ 6 ],
  2650. me[ 1 ], me[ 4 ], me[ 7 ],
  2651. me[ 2 ], me[ 5 ], me[ 8 ]
  2652. );
  2653. return this;
  2654. },
  2655. setFromMatrix4: function( m ) {
  2656. var me = m.elements;
  2657. this.set(
  2658. me[ 0 ], me[ 4 ], me[ 8 ],
  2659. me[ 1 ], me[ 5 ], me[ 9 ],
  2660. me[ 2 ], me[ 6 ], me[ 10 ]
  2661. );
  2662. return this;
  2663. },
  2664. applyToVector3Array: function () {
  2665. var v1;
  2666. return function ( array, offset, length ) {
  2667. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2668. if ( offset === undefined ) offset = 0;
  2669. if ( length === undefined ) length = array.length;
  2670. for ( var i = 0, j = offset; i < length; i += 3, j += 3 ) {
  2671. v1.fromArray( array, j );
  2672. v1.applyMatrix3( this );
  2673. v1.toArray( array, j );
  2674. }
  2675. return array;
  2676. };
  2677. }(),
  2678. applyToBuffer: function () {
  2679. var v1;
  2680. return function applyToBuffer( buffer, offset, length ) {
  2681. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2682. if ( offset === undefined ) offset = 0;
  2683. if ( length === undefined ) length = buffer.length / buffer.itemSize;
  2684. for ( var i = 0, j = offset; i < length; i ++, j ++ ) {
  2685. v1.x = buffer.getX( j );
  2686. v1.y = buffer.getY( j );
  2687. v1.z = buffer.getZ( j );
  2688. v1.applyMatrix3( this );
  2689. buffer.setXYZ( v1.x, v1.y, v1.z );
  2690. }
  2691. return buffer;
  2692. };
  2693. }(),
  2694. multiplyScalar: function ( s ) {
  2695. var te = this.elements;
  2696. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  2697. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  2698. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  2699. return this;
  2700. },
  2701. determinant: function () {
  2702. var te = this.elements;
  2703. var a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  2704. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  2705. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  2706. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  2707. },
  2708. getInverse: function ( matrix, throwOnDegenerate ) {
  2709. if ( matrix instanceof THREE.Matrix4 ) {
  2710. console.error( "THREE.Matrix3.getInverse no longer takes a Matrix4 argument." );
  2711. }
  2712. var me = matrix.elements,
  2713. te = this.elements,
  2714. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ],
  2715. n12 = me[ 3 ], n22 = me[ 4 ], n32 = me[ 5 ],
  2716. n13 = me[ 6 ], n23 = me[ 7 ], n33 = me[ 8 ],
  2717. t11 = n33 * n22 - n32 * n23,
  2718. t12 = n32 * n13 - n33 * n12,
  2719. t13 = n23 * n12 - n22 * n13,
  2720. det = n11 * t11 + n21 * t12 + n31 * t13;
  2721. if ( det === 0 ) {
  2722. var msg = "THREE.Matrix3.getInverse(): can't invert matrix, determinant is 0";
  2723. if ( throwOnDegenerate || false ) {
  2724. throw new Error( msg );
  2725. } else {
  2726. console.warn( msg );
  2727. }
  2728. return this.identity();
  2729. }
  2730. var detInv = 1 / det;
  2731. te[ 0 ] = t11 * detInv;
  2732. te[ 1 ] = ( n31 * n23 - n33 * n21 ) * detInv;
  2733. te[ 2 ] = ( n32 * n21 - n31 * n22 ) * detInv;
  2734. te[ 3 ] = t12 * detInv;
  2735. te[ 4 ] = ( n33 * n11 - n31 * n13 ) * detInv;
  2736. te[ 5 ] = ( n31 * n12 - n32 * n11 ) * detInv;
  2737. te[ 6 ] = t13 * detInv;
  2738. te[ 7 ] = ( n21 * n13 - n23 * n11 ) * detInv;
  2739. te[ 8 ] = ( n22 * n11 - n21 * n12 ) * detInv;
  2740. return this;
  2741. },
  2742. transpose: function () {
  2743. var tmp, m = this.elements;
  2744. tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
  2745. tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
  2746. tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
  2747. return this;
  2748. },
  2749. flattenToArrayOffset: function ( array, offset ) {
  2750. console.warn( "THREE.Matrix3: .flattenToArrayOffset is deprecated " +
  2751. "- just use .toArray instead." );
  2752. return this.toArray( array, offset );
  2753. },
  2754. getNormalMatrix: function ( matrix4 ) {
  2755. return this.setFromMatrix4( matrix4 ).getInverse( this ).transpose();
  2756. },
  2757. transposeIntoArray: function ( r ) {
  2758. var m = this.elements;
  2759. r[ 0 ] = m[ 0 ];
  2760. r[ 1 ] = m[ 3 ];
  2761. r[ 2 ] = m[ 6 ];
  2762. r[ 3 ] = m[ 1 ];
  2763. r[ 4 ] = m[ 4 ];
  2764. r[ 5 ] = m[ 7 ];
  2765. r[ 6 ] = m[ 2 ];
  2766. r[ 7 ] = m[ 5 ];
  2767. r[ 8 ] = m[ 8 ];
  2768. return this;
  2769. },
  2770. fromArray: function ( array ) {
  2771. this.elements.set( array );
  2772. return this;
  2773. },
  2774. toArray: function ( array, offset ) {
  2775. if ( array === undefined ) array = [];
  2776. if ( offset === undefined ) offset = 0;
  2777. var te = this.elements;
  2778. array[ offset ] = te[ 0 ];
  2779. array[ offset + 1 ] = te[ 1 ];
  2780. array[ offset + 2 ] = te[ 2 ];
  2781. array[ offset + 3 ] = te[ 3 ];
  2782. array[ offset + 4 ] = te[ 4 ];
  2783. array[ offset + 5 ] = te[ 5 ];
  2784. array[ offset + 6 ] = te[ 6 ];
  2785. array[ offset + 7 ] = te[ 7 ];
  2786. array[ offset + 8 ] = te[ 8 ];
  2787. return array;
  2788. }
  2789. };
  2790. // File:src/math/Matrix4.js
  2791. /**
  2792. * @author mrdoob / http://mrdoob.com/
  2793. * @author supereggbert / http://www.paulbrunt.co.uk/
  2794. * @author philogb / http://blog.thejit.org/
  2795. * @author jordi_ros / http://plattsoft.com
  2796. * @author D1plo1d / http://github.com/D1plo1d
  2797. * @author alteredq / http://alteredqualia.com/
  2798. * @author mikael emtinger / http://gomo.se/
  2799. * @author timknip / http://www.floorplanner.com/
  2800. * @author bhouston / http://clara.io
  2801. * @author WestLangley / http://github.com/WestLangley
  2802. */
  2803. THREE.Matrix4 = function () {
  2804. this.elements = new Float32Array( [
  2805. 1, 0, 0, 0,
  2806. 0, 1, 0, 0,
  2807. 0, 0, 1, 0,
  2808. 0, 0, 0, 1
  2809. ] );
  2810. if ( arguments.length > 0 ) {
  2811. console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' );
  2812. }
  2813. };
  2814. THREE.Matrix4.prototype = {
  2815. constructor: THREE.Matrix4,
  2816. set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  2817. var te = this.elements;
  2818. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  2819. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  2820. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  2821. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  2822. return this;
  2823. },
  2824. identity: function () {
  2825. this.set(
  2826. 1, 0, 0, 0,
  2827. 0, 1, 0, 0,
  2828. 0, 0, 1, 0,
  2829. 0, 0, 0, 1
  2830. );
  2831. return this;
  2832. },
  2833. clone: function () {
  2834. return new THREE.Matrix4().fromArray( this.elements );
  2835. },
  2836. copy: function ( m ) {
  2837. this.elements.set( m.elements );
  2838. return this;
  2839. },
  2840. copyPosition: function ( m ) {
  2841. var te = this.elements;
  2842. var me = m.elements;
  2843. te[ 12 ] = me[ 12 ];
  2844. te[ 13 ] = me[ 13 ];
  2845. te[ 14 ] = me[ 14 ];
  2846. return this;
  2847. },
  2848. extractBasis: function ( xAxis, yAxis, zAxis ) {
  2849. xAxis.setFromMatrixColumn( this, 0 );
  2850. yAxis.setFromMatrixColumn( this, 1 );
  2851. zAxis.setFromMatrixColumn( this, 2 );
  2852. return this;
  2853. },
  2854. makeBasis: function ( xAxis, yAxis, zAxis ) {
  2855. this.set(
  2856. xAxis.x, yAxis.x, zAxis.x, 0,
  2857. xAxis.y, yAxis.y, zAxis.y, 0,
  2858. xAxis.z, yAxis.z, zAxis.z, 0,
  2859. 0, 0, 0, 1
  2860. );
  2861. return this;
  2862. },
  2863. extractRotation: function () {
  2864. var v1;
  2865. return function ( m ) {
  2866. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2867. var te = this.elements;
  2868. var me = m.elements;
  2869. var scaleX = 1 / v1.setFromMatrixColumn( m, 0 ).length();
  2870. var scaleY = 1 / v1.setFromMatrixColumn( m, 1 ).length();
  2871. var scaleZ = 1 / v1.setFromMatrixColumn( m, 2 ).length();
  2872. te[ 0 ] = me[ 0 ] * scaleX;
  2873. te[ 1 ] = me[ 1 ] * scaleX;
  2874. te[ 2 ] = me[ 2 ] * scaleX;
  2875. te[ 4 ] = me[ 4 ] * scaleY;
  2876. te[ 5 ] = me[ 5 ] * scaleY;
  2877. te[ 6 ] = me[ 6 ] * scaleY;
  2878. te[ 8 ] = me[ 8 ] * scaleZ;
  2879. te[ 9 ] = me[ 9 ] * scaleZ;
  2880. te[ 10 ] = me[ 10 ] * scaleZ;
  2881. return this;
  2882. };
  2883. }(),
  2884. makeRotationFromEuler: function ( euler ) {
  2885. if ( euler instanceof THREE.Euler === false ) {
  2886. console.error( 'THREE.Matrix: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  2887. }
  2888. var te = this.elements;
  2889. var x = euler.x, y = euler.y, z = euler.z;
  2890. var a = Math.cos( x ), b = Math.sin( x );
  2891. var c = Math.cos( y ), d = Math.sin( y );
  2892. var e = Math.cos( z ), f = Math.sin( z );
  2893. if ( euler.order === 'XYZ' ) {
  2894. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2895. te[ 0 ] = c * e;
  2896. te[ 4 ] = - c * f;
  2897. te[ 8 ] = d;
  2898. te[ 1 ] = af + be * d;
  2899. te[ 5 ] = ae - bf * d;
  2900. te[ 9 ] = - b * c;
  2901. te[ 2 ] = bf - ae * d;
  2902. te[ 6 ] = be + af * d;
  2903. te[ 10 ] = a * c;
  2904. } else if ( euler.order === 'YXZ' ) {
  2905. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2906. te[ 0 ] = ce + df * b;
  2907. te[ 4 ] = de * b - cf;
  2908. te[ 8 ] = a * d;
  2909. te[ 1 ] = a * f;
  2910. te[ 5 ] = a * e;
  2911. te[ 9 ] = - b;
  2912. te[ 2 ] = cf * b - de;
  2913. te[ 6 ] = df + ce * b;
  2914. te[ 10 ] = a * c;
  2915. } else if ( euler.order === 'ZXY' ) {
  2916. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2917. te[ 0 ] = ce - df * b;
  2918. te[ 4 ] = - a * f;
  2919. te[ 8 ] = de + cf * b;
  2920. te[ 1 ] = cf + de * b;
  2921. te[ 5 ] = a * e;
  2922. te[ 9 ] = df - ce * b;
  2923. te[ 2 ] = - a * d;
  2924. te[ 6 ] = b;
  2925. te[ 10 ] = a * c;
  2926. } else if ( euler.order === 'ZYX' ) {
  2927. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2928. te[ 0 ] = c * e;
  2929. te[ 4 ] = be * d - af;
  2930. te[ 8 ] = ae * d + bf;
  2931. te[ 1 ] = c * f;
  2932. te[ 5 ] = bf * d + ae;
  2933. te[ 9 ] = af * d - be;
  2934. te[ 2 ] = - d;
  2935. te[ 6 ] = b * c;
  2936. te[ 10 ] = a * c;
  2937. } else if ( euler.order === 'YZX' ) {
  2938. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2939. te[ 0 ] = c * e;
  2940. te[ 4 ] = bd - ac * f;
  2941. te[ 8 ] = bc * f + ad;
  2942. te[ 1 ] = f;
  2943. te[ 5 ] = a * e;
  2944. te[ 9 ] = - b * e;
  2945. te[ 2 ] = - d * e;
  2946. te[ 6 ] = ad * f + bc;
  2947. te[ 10 ] = ac - bd * f;
  2948. } else if ( euler.order === 'XZY' ) {
  2949. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2950. te[ 0 ] = c * e;
  2951. te[ 4 ] = - f;
  2952. te[ 8 ] = d * e;
  2953. te[ 1 ] = ac * f + bd;
  2954. te[ 5 ] = a * e;
  2955. te[ 9 ] = ad * f - bc;
  2956. te[ 2 ] = bc * f - ad;
  2957. te[ 6 ] = b * e;
  2958. te[ 10 ] = bd * f + ac;
  2959. }
  2960. // last column
  2961. te[ 3 ] = 0;
  2962. te[ 7 ] = 0;
  2963. te[ 11 ] = 0;
  2964. // bottom row
  2965. te[ 12 ] = 0;
  2966. te[ 13 ] = 0;
  2967. te[ 14 ] = 0;
  2968. te[ 15 ] = 1;
  2969. return this;
  2970. },
  2971. makeRotationFromQuaternion: function ( q ) {
  2972. var te = this.elements;
  2973. var x = q.x, y = q.y, z = q.z, w = q.w;
  2974. var x2 = x + x, y2 = y + y, z2 = z + z;
  2975. var xx = x * x2, xy = x * y2, xz = x * z2;
  2976. var yy = y * y2, yz = y * z2, zz = z * z2;
  2977. var wx = w * x2, wy = w * y2, wz = w * z2;
  2978. te[ 0 ] = 1 - ( yy + zz );
  2979. te[ 4 ] = xy - wz;
  2980. te[ 8 ] = xz + wy;
  2981. te[ 1 ] = xy + wz;
  2982. te[ 5 ] = 1 - ( xx + zz );
  2983. te[ 9 ] = yz - wx;
  2984. te[ 2 ] = xz - wy;
  2985. te[ 6 ] = yz + wx;
  2986. te[ 10 ] = 1 - ( xx + yy );
  2987. // last column
  2988. te[ 3 ] = 0;
  2989. te[ 7 ] = 0;
  2990. te[ 11 ] = 0;
  2991. // bottom row
  2992. te[ 12 ] = 0;
  2993. te[ 13 ] = 0;
  2994. te[ 14 ] = 0;
  2995. te[ 15 ] = 1;
  2996. return this;
  2997. },
  2998. lookAt: function () {
  2999. var x, y, z;
  3000. return function ( eye, target, up ) {
  3001. if ( x === undefined ) {
  3002. x = new THREE.Vector3();
  3003. y = new THREE.Vector3();
  3004. z = new THREE.Vector3();
  3005. }
  3006. var te = this.elements;
  3007. z.subVectors( eye, target ).normalize();
  3008. if ( z.lengthSq() === 0 ) {
  3009. z.z = 1;
  3010. }
  3011. x.crossVectors( up, z ).normalize();
  3012. if ( x.lengthSq() === 0 ) {
  3013. z.z += 0.0001;
  3014. x.crossVectors( up, z ).normalize();
  3015. }
  3016. y.crossVectors( z, x );
  3017. te[ 0 ] = x.x; te[ 4 ] = y.x; te[ 8 ] = z.x;
  3018. te[ 1 ] = x.y; te[ 5 ] = y.y; te[ 9 ] = z.y;
  3019. te[ 2 ] = x.z; te[ 6 ] = y.z; te[ 10 ] = z.z;
  3020. return this;
  3021. };
  3022. }(),
  3023. multiply: function ( m, n ) {
  3024. if ( n !== undefined ) {
  3025. console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' );
  3026. return this.multiplyMatrices( m, n );
  3027. }
  3028. return this.multiplyMatrices( this, m );
  3029. },
  3030. premultiply: function ( m ) {
  3031. return this.multiplyMatrices( m, this );
  3032. },
  3033. multiplyMatrices: function ( a, b ) {
  3034. var ae = a.elements;
  3035. var be = b.elements;
  3036. var te = this.elements;
  3037. var a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  3038. var a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  3039. var a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  3040. var a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  3041. var b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  3042. var b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  3043. var b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  3044. var b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  3045. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  3046. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  3047. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  3048. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  3049. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  3050. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  3051. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  3052. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  3053. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  3054. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  3055. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  3056. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  3057. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  3058. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  3059. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  3060. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  3061. return this;
  3062. },
  3063. multiplyToArray: function ( a, b, r ) {
  3064. var te = this.elements;
  3065. this.multiplyMatrices( a, b );
  3066. r[ 0 ] = te[ 0 ]; r[ 1 ] = te[ 1 ]; r[ 2 ] = te[ 2 ]; r[ 3 ] = te[ 3 ];
  3067. r[ 4 ] = te[ 4 ]; r[ 5 ] = te[ 5 ]; r[ 6 ] = te[ 6 ]; r[ 7 ] = te[ 7 ];
  3068. r[ 8 ] = te[ 8 ]; r[ 9 ] = te[ 9 ]; r[ 10 ] = te[ 10 ]; r[ 11 ] = te[ 11 ];
  3069. r[ 12 ] = te[ 12 ]; r[ 13 ] = te[ 13 ]; r[ 14 ] = te[ 14 ]; r[ 15 ] = te[ 15 ];
  3070. return this;
  3071. },
  3072. multiplyScalar: function ( s ) {
  3073. var te = this.elements;
  3074. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  3075. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  3076. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  3077. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  3078. return this;
  3079. },
  3080. applyToVector3Array: function () {
  3081. var v1;
  3082. return function ( array, offset, length ) {
  3083. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3084. if ( offset === undefined ) offset = 0;
  3085. if ( length === undefined ) length = array.length;
  3086. for ( var i = 0, j = offset; i < length; i += 3, j += 3 ) {
  3087. v1.fromArray( array, j );
  3088. v1.applyMatrix4( this );
  3089. v1.toArray( array, j );
  3090. }
  3091. return array;
  3092. };
  3093. }(),
  3094. applyToBuffer: function () {
  3095. var v1;
  3096. return function applyToBuffer( buffer, offset, length ) {
  3097. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3098. if ( offset === undefined ) offset = 0;
  3099. if ( length === undefined ) length = buffer.length / buffer.itemSize;
  3100. for ( var i = 0, j = offset; i < length; i ++, j ++ ) {
  3101. v1.x = buffer.getX( j );
  3102. v1.y = buffer.getY( j );
  3103. v1.z = buffer.getZ( j );
  3104. v1.applyMatrix4( this );
  3105. buffer.setXYZ( v1.x, v1.y, v1.z );
  3106. }
  3107. return buffer;
  3108. };
  3109. }(),
  3110. determinant: function () {
  3111. var te = this.elements;
  3112. var n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  3113. var n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  3114. var n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  3115. var n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  3116. //TODO: make this more efficient
  3117. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  3118. return (
  3119. n41 * (
  3120. + n14 * n23 * n32
  3121. - n13 * n24 * n32
  3122. - n14 * n22 * n33
  3123. + n12 * n24 * n33
  3124. + n13 * n22 * n34
  3125. - n12 * n23 * n34
  3126. ) +
  3127. n42 * (
  3128. + n11 * n23 * n34
  3129. - n11 * n24 * n33
  3130. + n14 * n21 * n33
  3131. - n13 * n21 * n34
  3132. + n13 * n24 * n31
  3133. - n14 * n23 * n31
  3134. ) +
  3135. n43 * (
  3136. + n11 * n24 * n32
  3137. - n11 * n22 * n34
  3138. - n14 * n21 * n32
  3139. + n12 * n21 * n34
  3140. + n14 * n22 * n31
  3141. - n12 * n24 * n31
  3142. ) +
  3143. n44 * (
  3144. - n13 * n22 * n31
  3145. - n11 * n23 * n32
  3146. + n11 * n22 * n33
  3147. + n13 * n21 * n32
  3148. - n12 * n21 * n33
  3149. + n12 * n23 * n31
  3150. )
  3151. );
  3152. },
  3153. transpose: function () {
  3154. var te = this.elements;
  3155. var tmp;
  3156. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  3157. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  3158. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  3159. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  3160. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  3161. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  3162. return this;
  3163. },
  3164. flattenToArrayOffset: function ( array, offset ) {
  3165. console.warn( "THREE.Matrix3: .flattenToArrayOffset is deprecated " +
  3166. "- just use .toArray instead." );
  3167. return this.toArray( array, offset );
  3168. },
  3169. getPosition: function () {
  3170. var v1;
  3171. return function () {
  3172. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3173. console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
  3174. return v1.setFromMatrixColumn( this, 3 );
  3175. };
  3176. }(),
  3177. setPosition: function ( v ) {
  3178. var te = this.elements;
  3179. te[ 12 ] = v.x;
  3180. te[ 13 ] = v.y;
  3181. te[ 14 ] = v.z;
  3182. return this;
  3183. },
  3184. getInverse: function ( m, throwOnDegenerate ) {
  3185. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  3186. var te = this.elements,
  3187. me = m.elements,
  3188. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ], n41 = me[ 3 ],
  3189. n12 = me[ 4 ], n22 = me[ 5 ], n32 = me[ 6 ], n42 = me[ 7 ],
  3190. n13 = me[ 8 ], n23 = me[ 9 ], n33 = me[ 10 ], n43 = me[ 11 ],
  3191. n14 = me[ 12 ], n24 = me[ 13 ], n34 = me[ 14 ], n44 = me[ 15 ],
  3192. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  3193. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  3194. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  3195. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  3196. var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  3197. if ( det === 0 ) {
  3198. var msg = "THREE.Matrix4.getInverse(): can't invert matrix, determinant is 0";
  3199. if ( throwOnDegenerate || false ) {
  3200. throw new Error( msg );
  3201. } else {
  3202. console.warn( msg );
  3203. }
  3204. return this.identity();
  3205. }
  3206. var detInv = 1 / det;
  3207. te[ 0 ] = t11 * detInv;
  3208. te[ 1 ] = ( n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44 ) * detInv;
  3209. te[ 2 ] = ( n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44 ) * detInv;
  3210. te[ 3 ] = ( n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43 ) * detInv;
  3211. te[ 4 ] = t12 * detInv;
  3212. te[ 5 ] = ( n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44 ) * detInv;
  3213. te[ 6 ] = ( n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44 ) * detInv;
  3214. te[ 7 ] = ( n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43 ) * detInv;
  3215. te[ 8 ] = t13 * detInv;
  3216. te[ 9 ] = ( n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44 ) * detInv;
  3217. te[ 10 ] = ( n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44 ) * detInv;
  3218. te[ 11 ] = ( n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43 ) * detInv;
  3219. te[ 12 ] = t14 * detInv;
  3220. te[ 13 ] = ( n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34 ) * detInv;
  3221. te[ 14 ] = ( n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34 ) * detInv;
  3222. te[ 15 ] = ( n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33 ) * detInv;
  3223. return this;
  3224. },
  3225. scale: function ( v ) {
  3226. var te = this.elements;
  3227. var x = v.x, y = v.y, z = v.z;
  3228. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  3229. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  3230. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  3231. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  3232. return this;
  3233. },
  3234. getMaxScaleOnAxis: function () {
  3235. var te = this.elements;
  3236. var scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  3237. var scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  3238. var scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  3239. return Math.sqrt( Math.max( scaleXSq, scaleYSq, scaleZSq ) );
  3240. },
  3241. makeTranslation: function ( x, y, z ) {
  3242. this.set(
  3243. 1, 0, 0, x,
  3244. 0, 1, 0, y,
  3245. 0, 0, 1, z,
  3246. 0, 0, 0, 1
  3247. );
  3248. return this;
  3249. },
  3250. makeRotationX: function ( theta ) {
  3251. var c = Math.cos( theta ), s = Math.sin( theta );
  3252. this.set(
  3253. 1, 0, 0, 0,
  3254. 0, c, - s, 0,
  3255. 0, s, c, 0,
  3256. 0, 0, 0, 1
  3257. );
  3258. return this;
  3259. },
  3260. makeRotationY: function ( theta ) {
  3261. var c = Math.cos( theta ), s = Math.sin( theta );
  3262. this.set(
  3263. c, 0, s, 0,
  3264. 0, 1, 0, 0,
  3265. - s, 0, c, 0,
  3266. 0, 0, 0, 1
  3267. );
  3268. return this;
  3269. },
  3270. makeRotationZ: function ( theta ) {
  3271. var c = Math.cos( theta ), s = Math.sin( theta );
  3272. this.set(
  3273. c, - s, 0, 0,
  3274. s, c, 0, 0,
  3275. 0, 0, 1, 0,
  3276. 0, 0, 0, 1
  3277. );
  3278. return this;
  3279. },
  3280. makeRotationAxis: function ( axis, angle ) {
  3281. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  3282. var c = Math.cos( angle );
  3283. var s = Math.sin( angle );
  3284. var t = 1 - c;
  3285. var x = axis.x, y = axis.y, z = axis.z;
  3286. var tx = t * x, ty = t * y;
  3287. this.set(
  3288. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  3289. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  3290. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  3291. 0, 0, 0, 1
  3292. );
  3293. return this;
  3294. },
  3295. makeScale: function ( x, y, z ) {
  3296. this.set(
  3297. x, 0, 0, 0,
  3298. 0, y, 0, 0,
  3299. 0, 0, z, 0,
  3300. 0, 0, 0, 1
  3301. );
  3302. return this;
  3303. },
  3304. compose: function ( position, quaternion, scale ) {
  3305. this.makeRotationFromQuaternion( quaternion );
  3306. this.scale( scale );
  3307. this.setPosition( position );
  3308. return this;
  3309. },
  3310. decompose: function () {
  3311. var vector, matrix;
  3312. return function ( position, quaternion, scale ) {
  3313. if ( vector === undefined ) {
  3314. vector = new THREE.Vector3();
  3315. matrix = new THREE.Matrix4();
  3316. }
  3317. var te = this.elements;
  3318. var sx = vector.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  3319. var sy = vector.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  3320. var sz = vector.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  3321. // if determine is negative, we need to invert one scale
  3322. var det = this.determinant();
  3323. if ( det < 0 ) {
  3324. sx = - sx;
  3325. }
  3326. position.x = te[ 12 ];
  3327. position.y = te[ 13 ];
  3328. position.z = te[ 14 ];
  3329. // scale the rotation part
  3330. matrix.elements.set( this.elements ); // at this point matrix is incomplete so we can't use .copy()
  3331. var invSX = 1 / sx;
  3332. var invSY = 1 / sy;
  3333. var invSZ = 1 / sz;
  3334. matrix.elements[ 0 ] *= invSX;
  3335. matrix.elements[ 1 ] *= invSX;
  3336. matrix.elements[ 2 ] *= invSX;
  3337. matrix.elements[ 4 ] *= invSY;
  3338. matrix.elements[ 5 ] *= invSY;
  3339. matrix.elements[ 6 ] *= invSY;
  3340. matrix.elements[ 8 ] *= invSZ;
  3341. matrix.elements[ 9 ] *= invSZ;
  3342. matrix.elements[ 10 ] *= invSZ;
  3343. quaternion.setFromRotationMatrix( matrix );
  3344. scale.x = sx;
  3345. scale.y = sy;
  3346. scale.z = sz;
  3347. return this;
  3348. };
  3349. }(),
  3350. makeFrustum: function ( left, right, bottom, top, near, far ) {
  3351. var te = this.elements;
  3352. var x = 2 * near / ( right - left );
  3353. var y = 2 * near / ( top - bottom );
  3354. var a = ( right + left ) / ( right - left );
  3355. var b = ( top + bottom ) / ( top - bottom );
  3356. var c = - ( far + near ) / ( far - near );
  3357. var d = - 2 * far * near / ( far - near );
  3358. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  3359. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  3360. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  3361. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  3362. return this;
  3363. },
  3364. makePerspective: function ( fov, aspect, near, far ) {
  3365. var ymax = near * Math.tan( THREE.Math.DEG2RAD * fov * 0.5 );
  3366. var ymin = - ymax;
  3367. var xmin = ymin * aspect;
  3368. var xmax = ymax * aspect;
  3369. return this.makeFrustum( xmin, xmax, ymin, ymax, near, far );
  3370. },
  3371. makeOrthographic: function ( left, right, top, bottom, near, far ) {
  3372. var te = this.elements;
  3373. var w = 1.0 / ( right - left );
  3374. var h = 1.0 / ( top - bottom );
  3375. var p = 1.0 / ( far - near );
  3376. var x = ( right + left ) * w;
  3377. var y = ( top + bottom ) * h;
  3378. var z = ( far + near ) * p;
  3379. te[ 0 ] = 2 * w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  3380. te[ 1 ] = 0; te[ 5 ] = 2 * h; te[ 9 ] = 0; te[ 13 ] = - y;
  3381. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 * p; te[ 14 ] = - z;
  3382. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  3383. return this;
  3384. },
  3385. equals: function ( matrix ) {
  3386. var te = this.elements;
  3387. var me = matrix.elements;
  3388. for ( var i = 0; i < 16; i ++ ) {
  3389. if ( te[ i ] !== me[ i ] ) return false;
  3390. }
  3391. return true;
  3392. },
  3393. fromArray: function ( array ) {
  3394. this.elements.set( array );
  3395. return this;
  3396. },
  3397. toArray: function ( array, offset ) {
  3398. if ( array === undefined ) array = [];
  3399. if ( offset === undefined ) offset = 0;
  3400. var te = this.elements;
  3401. array[ offset ] = te[ 0 ];
  3402. array[ offset + 1 ] = te[ 1 ];
  3403. array[ offset + 2 ] = te[ 2 ];
  3404. array[ offset + 3 ] = te[ 3 ];
  3405. array[ offset + 4 ] = te[ 4 ];
  3406. array[ offset + 5 ] = te[ 5 ];
  3407. array[ offset + 6 ] = te[ 6 ];
  3408. array[ offset + 7 ] = te[ 7 ];
  3409. array[ offset + 8 ] = te[ 8 ];
  3410. array[ offset + 9 ] = te[ 9 ];
  3411. array[ offset + 10 ] = te[ 10 ];
  3412. array[ offset + 11 ] = te[ 11 ];
  3413. array[ offset + 12 ] = te[ 12 ];
  3414. array[ offset + 13 ] = te[ 13 ];
  3415. array[ offset + 14 ] = te[ 14 ];
  3416. array[ offset + 15 ] = te[ 15 ];
  3417. return array;
  3418. }
  3419. };
  3420. // File:src/math/Ray.js
  3421. /**
  3422. * @author bhouston / http://clara.io
  3423. */
  3424. THREE.Ray = function ( origin, direction ) {
  3425. this.origin = ( origin !== undefined ) ? origin : new THREE.Vector3();
  3426. this.direction = ( direction !== undefined ) ? direction : new THREE.Vector3();
  3427. };
  3428. THREE.Ray.prototype = {
  3429. constructor: THREE.Ray,
  3430. set: function ( origin, direction ) {
  3431. this.origin.copy( origin );
  3432. this.direction.copy( direction );
  3433. return this;
  3434. },
  3435. clone: function () {
  3436. return new this.constructor().copy( this );
  3437. },
  3438. copy: function ( ray ) {
  3439. this.origin.copy( ray.origin );
  3440. this.direction.copy( ray.direction );
  3441. return this;
  3442. },
  3443. at: function ( t, optionalTarget ) {
  3444. var result = optionalTarget || new THREE.Vector3();
  3445. return result.copy( this.direction ).multiplyScalar( t ).add( this.origin );
  3446. },
  3447. lookAt: function ( v ) {
  3448. this.direction.copy( v ).sub( this.origin ).normalize();
  3449. return this;
  3450. },
  3451. recast: function () {
  3452. var v1 = new THREE.Vector3();
  3453. return function ( t ) {
  3454. this.origin.copy( this.at( t, v1 ) );
  3455. return this;
  3456. };
  3457. }(),
  3458. closestPointToPoint: function ( point, optionalTarget ) {
  3459. var result = optionalTarget || new THREE.Vector3();
  3460. result.subVectors( point, this.origin );
  3461. var directionDistance = result.dot( this.direction );
  3462. if ( directionDistance < 0 ) {
  3463. return result.copy( this.origin );
  3464. }
  3465. return result.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  3466. },
  3467. distanceToPoint: function ( point ) {
  3468. return Math.sqrt( this.distanceSqToPoint( point ) );
  3469. },
  3470. distanceSqToPoint: function () {
  3471. var v1 = new THREE.Vector3();
  3472. return function ( point ) {
  3473. var directionDistance = v1.subVectors( point, this.origin ).dot( this.direction );
  3474. // point behind the ray
  3475. if ( directionDistance < 0 ) {
  3476. return this.origin.distanceToSquared( point );
  3477. }
  3478. v1.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  3479. return v1.distanceToSquared( point );
  3480. };
  3481. }(),
  3482. distanceSqToSegment: function () {
  3483. var segCenter = new THREE.Vector3();
  3484. var segDir = new THREE.Vector3();
  3485. var diff = new THREE.Vector3();
  3486. return function ( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  3487. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h
  3488. // It returns the min distance between the ray and the segment
  3489. // defined by v0 and v1
  3490. // It can also set two optional targets :
  3491. // - The closest point on the ray
  3492. // - The closest point on the segment
  3493. segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  3494. segDir.copy( v1 ).sub( v0 ).normalize();
  3495. diff.copy( this.origin ).sub( segCenter );
  3496. var segExtent = v0.distanceTo( v1 ) * 0.5;
  3497. var a01 = - this.direction.dot( segDir );
  3498. var b0 = diff.dot( this.direction );
  3499. var b1 = - diff.dot( segDir );
  3500. var c = diff.lengthSq();
  3501. var det = Math.abs( 1 - a01 * a01 );
  3502. var s0, s1, sqrDist, extDet;
  3503. if ( det > 0 ) {
  3504. // The ray and segment are not parallel.
  3505. s0 = a01 * b1 - b0;
  3506. s1 = a01 * b0 - b1;
  3507. extDet = segExtent * det;
  3508. if ( s0 >= 0 ) {
  3509. if ( s1 >= - extDet ) {
  3510. if ( s1 <= extDet ) {
  3511. // region 0
  3512. // Minimum at interior points of ray and segment.
  3513. var invDet = 1 / det;
  3514. s0 *= invDet;
  3515. s1 *= invDet;
  3516. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  3517. } else {
  3518. // region 1
  3519. s1 = segExtent;
  3520. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3521. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3522. }
  3523. } else {
  3524. // region 5
  3525. s1 = - segExtent;
  3526. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3527. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3528. }
  3529. } else {
  3530. if ( s1 <= - extDet ) {
  3531. // region 4
  3532. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  3533. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3534. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3535. } else if ( s1 <= extDet ) {
  3536. // region 3
  3537. s0 = 0;
  3538. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3539. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  3540. } else {
  3541. // region 2
  3542. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  3543. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3544. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3545. }
  3546. }
  3547. } else {
  3548. // Ray and segment are parallel.
  3549. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  3550. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3551. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3552. }
  3553. if ( optionalPointOnRay ) {
  3554. optionalPointOnRay.copy( this.direction ).multiplyScalar( s0 ).add( this.origin );
  3555. }
  3556. if ( optionalPointOnSegment ) {
  3557. optionalPointOnSegment.copy( segDir ).multiplyScalar( s1 ).add( segCenter );
  3558. }
  3559. return sqrDist;
  3560. };
  3561. }(),
  3562. intersectSphere: function () {
  3563. var v1 = new THREE.Vector3();
  3564. return function ( sphere, optionalTarget ) {
  3565. v1.subVectors( sphere.center, this.origin );
  3566. var tca = v1.dot( this.direction );
  3567. var d2 = v1.dot( v1 ) - tca * tca;
  3568. var radius2 = sphere.radius * sphere.radius;
  3569. if ( d2 > radius2 ) return null;
  3570. var thc = Math.sqrt( radius2 - d2 );
  3571. // t0 = first intersect point - entrance on front of sphere
  3572. var t0 = tca - thc;
  3573. // t1 = second intersect point - exit point on back of sphere
  3574. var t1 = tca + thc;
  3575. // test to see if both t0 and t1 are behind the ray - if so, return null
  3576. if ( t0 < 0 && t1 < 0 ) return null;
  3577. // test to see if t0 is behind the ray:
  3578. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  3579. // in order to always return an intersect point that is in front of the ray.
  3580. if ( t0 < 0 ) return this.at( t1, optionalTarget );
  3581. // else t0 is in front of the ray, so return the first collision point scaled by t0
  3582. return this.at( t0, optionalTarget );
  3583. };
  3584. }(),
  3585. intersectsSphere: function ( sphere ) {
  3586. return this.distanceToPoint( sphere.center ) <= sphere.radius;
  3587. },
  3588. distanceToPlane: function ( plane ) {
  3589. var denominator = plane.normal.dot( this.direction );
  3590. if ( denominator === 0 ) {
  3591. // line is coplanar, return origin
  3592. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  3593. return 0;
  3594. }
  3595. // Null is preferable to undefined since undefined means.... it is undefined
  3596. return null;
  3597. }
  3598. var t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  3599. // Return if the ray never intersects the plane
  3600. return t >= 0 ? t : null;
  3601. },
  3602. intersectPlane: function ( plane, optionalTarget ) {
  3603. var t = this.distanceToPlane( plane );
  3604. if ( t === null ) {
  3605. return null;
  3606. }
  3607. return this.at( t, optionalTarget );
  3608. },
  3609. intersectsPlane: function ( plane ) {
  3610. // check if the ray lies on the plane first
  3611. var distToPoint = plane.distanceToPoint( this.origin );
  3612. if ( distToPoint === 0 ) {
  3613. return true;
  3614. }
  3615. var denominator = plane.normal.dot( this.direction );
  3616. if ( denominator * distToPoint < 0 ) {
  3617. return true;
  3618. }
  3619. // ray origin is behind the plane (and is pointing behind it)
  3620. return false;
  3621. },
  3622. intersectBox: function ( box, optionalTarget ) {
  3623. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  3624. var invdirx = 1 / this.direction.x,
  3625. invdiry = 1 / this.direction.y,
  3626. invdirz = 1 / this.direction.z;
  3627. var origin = this.origin;
  3628. if ( invdirx >= 0 ) {
  3629. tmin = ( box.min.x - origin.x ) * invdirx;
  3630. tmax = ( box.max.x - origin.x ) * invdirx;
  3631. } else {
  3632. tmin = ( box.max.x - origin.x ) * invdirx;
  3633. tmax = ( box.min.x - origin.x ) * invdirx;
  3634. }
  3635. if ( invdiry >= 0 ) {
  3636. tymin = ( box.min.y - origin.y ) * invdiry;
  3637. tymax = ( box.max.y - origin.y ) * invdiry;
  3638. } else {
  3639. tymin = ( box.max.y - origin.y ) * invdiry;
  3640. tymax = ( box.min.y - origin.y ) * invdiry;
  3641. }
  3642. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  3643. // These lines also handle the case where tmin or tmax is NaN
  3644. // (result of 0 * Infinity). x !== x returns true if x is NaN
  3645. if ( tymin > tmin || tmin !== tmin ) tmin = tymin;
  3646. if ( tymax < tmax || tmax !== tmax ) tmax = tymax;
  3647. if ( invdirz >= 0 ) {
  3648. tzmin = ( box.min.z - origin.z ) * invdirz;
  3649. tzmax = ( box.max.z - origin.z ) * invdirz;
  3650. } else {
  3651. tzmin = ( box.max.z - origin.z ) * invdirz;
  3652. tzmax = ( box.min.z - origin.z ) * invdirz;
  3653. }
  3654. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  3655. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  3656. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  3657. //return point closest to the ray (positive side)
  3658. if ( tmax < 0 ) return null;
  3659. return this.at( tmin >= 0 ? tmin : tmax, optionalTarget );
  3660. },
  3661. intersectsBox: ( function () {
  3662. var v = new THREE.Vector3();
  3663. return function ( box ) {
  3664. return this.intersectBox( box, v ) !== null;
  3665. };
  3666. } )(),
  3667. intersectTriangle: function () {
  3668. // Compute the offset origin, edges, and normal.
  3669. var diff = new THREE.Vector3();
  3670. var edge1 = new THREE.Vector3();
  3671. var edge2 = new THREE.Vector3();
  3672. var normal = new THREE.Vector3();
  3673. return function ( a, b, c, backfaceCulling, optionalTarget ) {
  3674. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  3675. edge1.subVectors( b, a );
  3676. edge2.subVectors( c, a );
  3677. normal.crossVectors( edge1, edge2 );
  3678. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  3679. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  3680. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  3681. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  3682. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  3683. var DdN = this.direction.dot( normal );
  3684. var sign;
  3685. if ( DdN > 0 ) {
  3686. if ( backfaceCulling ) return null;
  3687. sign = 1;
  3688. } else if ( DdN < 0 ) {
  3689. sign = - 1;
  3690. DdN = - DdN;
  3691. } else {
  3692. return null;
  3693. }
  3694. diff.subVectors( this.origin, a );
  3695. var DdQxE2 = sign * this.direction.dot( edge2.crossVectors( diff, edge2 ) );
  3696. // b1 < 0, no intersection
  3697. if ( DdQxE2 < 0 ) {
  3698. return null;
  3699. }
  3700. var DdE1xQ = sign * this.direction.dot( edge1.cross( diff ) );
  3701. // b2 < 0, no intersection
  3702. if ( DdE1xQ < 0 ) {
  3703. return null;
  3704. }
  3705. // b1+b2 > 1, no intersection
  3706. if ( DdQxE2 + DdE1xQ > DdN ) {
  3707. return null;
  3708. }
  3709. // Line intersects triangle, check if ray does.
  3710. var QdN = - sign * diff.dot( normal );
  3711. // t < 0, no intersection
  3712. if ( QdN < 0 ) {
  3713. return null;
  3714. }
  3715. // Ray intersects triangle.
  3716. return this.at( QdN / DdN, optionalTarget );
  3717. };
  3718. }(),
  3719. applyMatrix4: function ( matrix4 ) {
  3720. this.direction.add( this.origin ).applyMatrix4( matrix4 );
  3721. this.origin.applyMatrix4( matrix4 );
  3722. this.direction.sub( this.origin );
  3723. this.direction.normalize();
  3724. return this;
  3725. },
  3726. equals: function ( ray ) {
  3727. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  3728. }
  3729. };
  3730. // File:src/math/Sphere.js
  3731. /**
  3732. * @author bhouston / http://clara.io
  3733. * @author mrdoob / http://mrdoob.com/
  3734. */
  3735. THREE.Sphere = function ( center, radius ) {
  3736. this.center = ( center !== undefined ) ? center : new THREE.Vector3();
  3737. this.radius = ( radius !== undefined ) ? radius : 0;
  3738. };
  3739. THREE.Sphere.prototype = {
  3740. constructor: THREE.Sphere,
  3741. set: function ( center, radius ) {
  3742. this.center.copy( center );
  3743. this.radius = radius;
  3744. return this;
  3745. },
  3746. setFromPoints: function () {
  3747. var box = new THREE.Box3();
  3748. return function ( points, optionalCenter ) {
  3749. var center = this.center;
  3750. if ( optionalCenter !== undefined ) {
  3751. center.copy( optionalCenter );
  3752. } else {
  3753. box.setFromPoints( points ).center( center );
  3754. }
  3755. var maxRadiusSq = 0;
  3756. for ( var i = 0, il = points.length; i < il; i ++ ) {
  3757. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  3758. }
  3759. this.radius = Math.sqrt( maxRadiusSq );
  3760. return this;
  3761. };
  3762. }(),
  3763. clone: function () {
  3764. return new this.constructor().copy( this );
  3765. },
  3766. copy: function ( sphere ) {
  3767. this.center.copy( sphere.center );
  3768. this.radius = sphere.radius;
  3769. return this;
  3770. },
  3771. empty: function () {
  3772. return ( this.radius <= 0 );
  3773. },
  3774. containsPoint: function ( point ) {
  3775. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  3776. },
  3777. distanceToPoint: function ( point ) {
  3778. return ( point.distanceTo( this.center ) - this.radius );
  3779. },
  3780. intersectsSphere: function ( sphere ) {
  3781. var radiusSum = this.radius + sphere.radius;
  3782. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  3783. },
  3784. intersectsBox: function ( box ) {
  3785. return box.intersectsSphere( this );
  3786. },
  3787. intersectsPlane: function ( plane ) {
  3788. // We use the following equation to compute the signed distance from
  3789. // the center of the sphere to the plane.
  3790. //
  3791. // distance = q * n - d
  3792. //
  3793. // If this distance is greater than the radius of the sphere,
  3794. // then there is no intersection.
  3795. return Math.abs( this.center.dot( plane.normal ) - plane.constant ) <= this.radius;
  3796. },
  3797. clampPoint: function ( point, optionalTarget ) {
  3798. var deltaLengthSq = this.center.distanceToSquared( point );
  3799. var result = optionalTarget || new THREE.Vector3();
  3800. result.copy( point );
  3801. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  3802. result.sub( this.center ).normalize();
  3803. result.multiplyScalar( this.radius ).add( this.center );
  3804. }
  3805. return result;
  3806. },
  3807. getBoundingBox: function ( optionalTarget ) {
  3808. var box = optionalTarget || new THREE.Box3();
  3809. box.set( this.center, this.center );
  3810. box.expandByScalar( this.radius );
  3811. return box;
  3812. },
  3813. applyMatrix4: function ( matrix ) {
  3814. this.center.applyMatrix4( matrix );
  3815. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  3816. return this;
  3817. },
  3818. translate: function ( offset ) {
  3819. this.center.add( offset );
  3820. return this;
  3821. },
  3822. equals: function ( sphere ) {
  3823. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  3824. }
  3825. };
  3826. // File:src/math/Frustum.js
  3827. /**
  3828. * @author mrdoob / http://mrdoob.com/
  3829. * @author alteredq / http://alteredqualia.com/
  3830. * @author bhouston / http://clara.io
  3831. */
  3832. THREE.Frustum = function ( p0, p1, p2, p3, p4, p5 ) {
  3833. this.planes = [
  3834. ( p0 !== undefined ) ? p0 : new THREE.Plane(),
  3835. ( p1 !== undefined ) ? p1 : new THREE.Plane(),
  3836. ( p2 !== undefined ) ? p2 : new THREE.Plane(),
  3837. ( p3 !== undefined ) ? p3 : new THREE.Plane(),
  3838. ( p4 !== undefined ) ? p4 : new THREE.Plane(),
  3839. ( p5 !== undefined ) ? p5 : new THREE.Plane()
  3840. ];
  3841. };
  3842. THREE.Frustum.prototype = {
  3843. constructor: THREE.Frustum,
  3844. set: function ( p0, p1, p2, p3, p4, p5 ) {
  3845. var planes = this.planes;
  3846. planes[ 0 ].copy( p0 );
  3847. planes[ 1 ].copy( p1 );
  3848. planes[ 2 ].copy( p2 );
  3849. planes[ 3 ].copy( p3 );
  3850. planes[ 4 ].copy( p4 );
  3851. planes[ 5 ].copy( p5 );
  3852. return this;
  3853. },
  3854. clone: function () {
  3855. return new this.constructor().copy( this );
  3856. },
  3857. copy: function ( frustum ) {
  3858. var planes = this.planes;
  3859. for ( var i = 0; i < 6; i ++ ) {
  3860. planes[ i ].copy( frustum.planes[ i ] );
  3861. }
  3862. return this;
  3863. },
  3864. setFromMatrix: function ( m ) {
  3865. var planes = this.planes;
  3866. var me = m.elements;
  3867. var me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  3868. var me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  3869. var me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  3870. var me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  3871. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  3872. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  3873. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  3874. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  3875. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  3876. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  3877. return this;
  3878. },
  3879. intersectsObject: function () {
  3880. var sphere = new THREE.Sphere();
  3881. return function ( object ) {
  3882. var geometry = object.geometry;
  3883. if ( geometry.boundingSphere === null )
  3884. geometry.computeBoundingSphere();
  3885. sphere.copy( geometry.boundingSphere )
  3886. .applyMatrix4( object.matrixWorld );
  3887. return this.intersectsSphere( sphere );
  3888. };
  3889. }(),
  3890. intersectsSprite: function () {
  3891. var sphere = new THREE.Sphere();
  3892. return function ( sprite ) {
  3893. sphere.center.set( 0, 0, 0 );
  3894. sphere.radius = 0.7071067811865476;
  3895. sphere.applyMatrix4( sprite.matrixWorld );
  3896. return this.intersectsSphere( sphere );
  3897. };
  3898. }(),
  3899. intersectsSphere: function ( sphere ) {
  3900. var planes = this.planes;
  3901. var center = sphere.center;
  3902. var negRadius = - sphere.radius;
  3903. for ( var i = 0; i < 6; i ++ ) {
  3904. var distance = planes[ i ].distanceToPoint( center );
  3905. if ( distance < negRadius ) {
  3906. return false;
  3907. }
  3908. }
  3909. return true;
  3910. },
  3911. intersectsBox: function () {
  3912. var p1 = new THREE.Vector3(),
  3913. p2 = new THREE.Vector3();
  3914. return function ( box ) {
  3915. var planes = this.planes;
  3916. for ( var i = 0; i < 6 ; i ++ ) {
  3917. var plane = planes[ i ];
  3918. p1.x = plane.normal.x > 0 ? box.min.x : box.max.x;
  3919. p2.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  3920. p1.y = plane.normal.y > 0 ? box.min.y : box.max.y;
  3921. p2.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  3922. p1.z = plane.normal.z > 0 ? box.min.z : box.max.z;
  3923. p2.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  3924. var d1 = plane.distanceToPoint( p1 );
  3925. var d2 = plane.distanceToPoint( p2 );
  3926. // if both outside plane, no intersection
  3927. if ( d1 < 0 && d2 < 0 ) {
  3928. return false;
  3929. }
  3930. }
  3931. return true;
  3932. };
  3933. }(),
  3934. containsPoint: function ( point ) {
  3935. var planes = this.planes;
  3936. for ( var i = 0; i < 6; i ++ ) {
  3937. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  3938. return false;
  3939. }
  3940. }
  3941. return true;
  3942. }
  3943. };
  3944. // File:src/math/Plane.js
  3945. /**
  3946. * @author bhouston / http://clara.io
  3947. */
  3948. THREE.Plane = function ( normal, constant ) {
  3949. this.normal = ( normal !== undefined ) ? normal : new THREE.Vector3( 1, 0, 0 );
  3950. this.constant = ( constant !== undefined ) ? constant : 0;
  3951. };
  3952. THREE.Plane.prototype = {
  3953. constructor: THREE.Plane,
  3954. set: function ( normal, constant ) {
  3955. this.normal.copy( normal );
  3956. this.constant = constant;
  3957. return this;
  3958. },
  3959. setComponents: function ( x, y, z, w ) {
  3960. this.normal.set( x, y, z );
  3961. this.constant = w;
  3962. return this;
  3963. },
  3964. setFromNormalAndCoplanarPoint: function ( normal, point ) {
  3965. this.normal.copy( normal );
  3966. this.constant = - point.dot( this.normal ); // must be this.normal, not normal, as this.normal is normalized
  3967. return this;
  3968. },
  3969. setFromCoplanarPoints: function () {
  3970. var v1 = new THREE.Vector3();
  3971. var v2 = new THREE.Vector3();
  3972. return function ( a, b, c ) {
  3973. var normal = v1.subVectors( c, b ).cross( v2.subVectors( a, b ) ).normalize();
  3974. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  3975. this.setFromNormalAndCoplanarPoint( normal, a );
  3976. return this;
  3977. };
  3978. }(),
  3979. clone: function () {
  3980. return new this.constructor().copy( this );
  3981. },
  3982. copy: function ( plane ) {
  3983. this.normal.copy( plane.normal );
  3984. this.constant = plane.constant;
  3985. return this;
  3986. },
  3987. normalize: function () {
  3988. // Note: will lead to a divide by zero if the plane is invalid.
  3989. var inverseNormalLength = 1.0 / this.normal.length();
  3990. this.normal.multiplyScalar( inverseNormalLength );
  3991. this.constant *= inverseNormalLength;
  3992. return this;
  3993. },
  3994. negate: function () {
  3995. this.constant *= - 1;
  3996. this.normal.negate();
  3997. return this;
  3998. },
  3999. distanceToPoint: function ( point ) {
  4000. return this.normal.dot( point ) + this.constant;
  4001. },
  4002. distanceToSphere: function ( sphere ) {
  4003. return this.distanceToPoint( sphere.center ) - sphere.radius;
  4004. },
  4005. projectPoint: function ( point, optionalTarget ) {
  4006. return this.orthoPoint( point, optionalTarget ).sub( point ).negate();
  4007. },
  4008. orthoPoint: function ( point, optionalTarget ) {
  4009. var perpendicularMagnitude = this.distanceToPoint( point );
  4010. var result = optionalTarget || new THREE.Vector3();
  4011. return result.copy( this.normal ).multiplyScalar( perpendicularMagnitude );
  4012. },
  4013. intersectLine: function () {
  4014. var v1 = new THREE.Vector3();
  4015. return function ( line, optionalTarget ) {
  4016. var result = optionalTarget || new THREE.Vector3();
  4017. var direction = line.delta( v1 );
  4018. var denominator = this.normal.dot( direction );
  4019. if ( denominator === 0 ) {
  4020. // line is coplanar, return origin
  4021. if ( this.distanceToPoint( line.start ) === 0 ) {
  4022. return result.copy( line.start );
  4023. }
  4024. // Unsure if this is the correct method to handle this case.
  4025. return undefined;
  4026. }
  4027. var t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  4028. if ( t < 0 || t > 1 ) {
  4029. return undefined;
  4030. }
  4031. return result.copy( direction ).multiplyScalar( t ).add( line.start );
  4032. };
  4033. }(),
  4034. intersectsLine: function ( line ) {
  4035. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  4036. var startSign = this.distanceToPoint( line.start );
  4037. var endSign = this.distanceToPoint( line.end );
  4038. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  4039. },
  4040. intersectsBox: function ( box ) {
  4041. return box.intersectsPlane( this );
  4042. },
  4043. intersectsSphere: function ( sphere ) {
  4044. return sphere.intersectsPlane( this );
  4045. },
  4046. coplanarPoint: function ( optionalTarget ) {
  4047. var result = optionalTarget || new THREE.Vector3();
  4048. return result.copy( this.normal ).multiplyScalar( - this.constant );
  4049. },
  4050. applyMatrix4: function () {
  4051. var v1 = new THREE.Vector3();
  4052. var m1 = new THREE.Matrix3();
  4053. return function ( matrix, optionalNormalMatrix ) {
  4054. var referencePoint = this.coplanarPoint( v1 ).applyMatrix4( matrix );
  4055. // transform normal based on theory here:
  4056. // http://www.songho.ca/opengl/gl_normaltransform.html
  4057. var normalMatrix = optionalNormalMatrix || m1.getNormalMatrix( matrix );
  4058. var normal = this.normal.applyMatrix3( normalMatrix ).normalize();
  4059. // recalculate constant (like in setFromNormalAndCoplanarPoint)
  4060. this.constant = - referencePoint.dot( normal );
  4061. return this;
  4062. };
  4063. }(),
  4064. translate: function ( offset ) {
  4065. this.constant = this.constant - offset.dot( this.normal );
  4066. return this;
  4067. },
  4068. equals: function ( plane ) {
  4069. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  4070. }
  4071. };
  4072. // File:src/math/Spherical.js
  4073. /**
  4074. * @author bhouston / http://clara.io
  4075. * @author WestLangley / http://github.com/WestLangley
  4076. *
  4077. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  4078. *
  4079. * The poles (phi) are at the positive and negative y axis.
  4080. * The equator starts at positive z.
  4081. */
  4082. THREE.Spherical = function ( radius, phi, theta ) {
  4083. this.radius = ( radius !== undefined ) ? radius : 1.0;
  4084. this.phi = ( phi !== undefined ) ? phi : 0; // up / down towards top and bottom pole
  4085. this.theta = ( theta !== undefined ) ? theta : 0; // around the equator of the sphere
  4086. return this;
  4087. };
  4088. THREE.Spherical.prototype = {
  4089. constructor: THREE.Spherical,
  4090. set: function ( radius, phi, theta ) {
  4091. this.radius = radius;
  4092. this.phi = phi;
  4093. this.theta = theta;
  4094. return this;
  4095. },
  4096. clone: function () {
  4097. return new this.constructor().copy( this );
  4098. },
  4099. copy: function ( other ) {
  4100. this.radius.copy( other.radius );
  4101. this.phi.copy( other.phi );
  4102. this.theta.copy( other.theta );
  4103. return this;
  4104. },
  4105. // restrict phi to be betwee EPS and PI-EPS
  4106. makeSafe: function() {
  4107. var EPS = 0.000001;
  4108. this.phi = Math.max( EPS, Math.min( Math.PI - EPS, this.phi ) );
  4109. return this;
  4110. },
  4111. setFromVector3: function( vec3 ) {
  4112. this.radius = vec3.length();
  4113. if ( this.radius === 0 ) {
  4114. this.theta = 0;
  4115. this.phi = 0;
  4116. } else {
  4117. this.theta = Math.atan2( vec3.x, vec3.z ); // equator angle around y-up axis
  4118. this.phi = Math.acos( THREE.Math.clamp( vec3.y / this.radius, - 1, 1 ) ); // polar angle
  4119. }
  4120. return this;
  4121. },
  4122. };
  4123. // File:src/math/Math.js
  4124. /**
  4125. * @author alteredq / http://alteredqualia.com/
  4126. * @author mrdoob / http://mrdoob.com/
  4127. */
  4128. THREE.Math = {
  4129. DEG2RAD: Math.PI / 180,
  4130. RAD2DEG: 180 / Math.PI,
  4131. generateUUID: function () {
  4132. // http://www.broofa.com/Tools/Math.uuid.htm
  4133. var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split( '' );
  4134. var uuid = new Array( 36 );
  4135. var rnd = 0, r;
  4136. return function () {
  4137. for ( var i = 0; i < 36; i ++ ) {
  4138. if ( i === 8 || i === 13 || i === 18 || i === 23 ) {
  4139. uuid[ i ] = '-';
  4140. } else if ( i === 14 ) {
  4141. uuid[ i ] = '4';
  4142. } else {
  4143. if ( rnd <= 0x02 ) rnd = 0x2000000 + ( Math.random() * 0x1000000 ) | 0;
  4144. r = rnd & 0xf;
  4145. rnd = rnd >> 4;
  4146. uuid[ i ] = chars[ ( i === 19 ) ? ( r & 0x3 ) | 0x8 : r ];
  4147. }
  4148. }
  4149. return uuid.join( '' );
  4150. };
  4151. }(),
  4152. clamp: function ( value, min, max ) {
  4153. return Math.max( min, Math.min( max, value ) );
  4154. },
  4155. // compute euclidian modulo of m % n
  4156. // https://en.wikipedia.org/wiki/Modulo_operation
  4157. euclideanModulo: function ( n, m ) {
  4158. return ( ( n % m ) + m ) % m;
  4159. },
  4160. // Linear mapping from range <a1, a2> to range <b1, b2>
  4161. mapLinear: function ( x, a1, a2, b1, b2 ) {
  4162. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  4163. },
  4164. // http://en.wikipedia.org/wiki/Smoothstep
  4165. smoothstep: function ( x, min, max ) {
  4166. if ( x <= min ) return 0;
  4167. if ( x >= max ) return 1;
  4168. x = ( x - min ) / ( max - min );
  4169. return x * x * ( 3 - 2 * x );
  4170. },
  4171. smootherstep: function ( x, min, max ) {
  4172. if ( x <= min ) return 0;
  4173. if ( x >= max ) return 1;
  4174. x = ( x - min ) / ( max - min );
  4175. return x * x * x * ( x * ( x * 6 - 15 ) + 10 );
  4176. },
  4177. random16: function () {
  4178. console.warn( 'THREE.Math.random16() has been deprecated. Use Math.random() instead.' );
  4179. return Math.random();
  4180. },
  4181. // Random integer from <low, high> interval
  4182. randInt: function ( low, high ) {
  4183. return low + Math.floor( Math.random() * ( high - low + 1 ) );
  4184. },
  4185. // Random float from <low, high> interval
  4186. randFloat: function ( low, high ) {
  4187. return low + Math.random() * ( high - low );
  4188. },
  4189. // Random float from <-range/2, range/2> interval
  4190. randFloatSpread: function ( range ) {
  4191. return range * ( 0.5 - Math.random() );
  4192. },
  4193. degToRad: function ( degrees ) {
  4194. return degrees * THREE.Math.DEG2RAD;
  4195. },
  4196. radToDeg: function ( radians ) {
  4197. return radians * THREE.Math.RAD2DEG;
  4198. },
  4199. isPowerOfTwo: function ( value ) {
  4200. return ( value & ( value - 1 ) ) === 0 && value !== 0;
  4201. },
  4202. nearestPowerOfTwo: function ( value ) {
  4203. return Math.pow( 2, Math.round( Math.log( value ) / Math.LN2 ) );
  4204. },
  4205. nextPowerOfTwo: function ( value ) {
  4206. value --;
  4207. value |= value >> 1;
  4208. value |= value >> 2;
  4209. value |= value >> 4;
  4210. value |= value >> 8;
  4211. value |= value >> 16;
  4212. value ++;
  4213. return value;
  4214. }
  4215. };
  4216. // File:src/math/Spline.js
  4217. /**
  4218. * Spline from Tween.js, slightly optimized (and trashed)
  4219. * http://sole.github.com/tween.js/examples/05_spline.html
  4220. *
  4221. * @author mrdoob / http://mrdoob.com/
  4222. * @author alteredq / http://alteredqualia.com/
  4223. */
  4224. THREE.Spline = function ( points ) {
  4225. this.points = points;
  4226. var c = [], v3 = { x: 0, y: 0, z: 0 },
  4227. point, intPoint, weight, w2, w3,
  4228. pa, pb, pc, pd;
  4229. this.initFromArray = function ( a ) {
  4230. this.points = [];
  4231. for ( var i = 0; i < a.length; i ++ ) {
  4232. this.points[ i ] = { x: a[ i ][ 0 ], y: a[ i ][ 1 ], z: a[ i ][ 2 ] };
  4233. }
  4234. };
  4235. this.getPoint = function ( k ) {
  4236. point = ( this.points.length - 1 ) * k;
  4237. intPoint = Math.floor( point );
  4238. weight = point - intPoint;
  4239. c[ 0 ] = intPoint === 0 ? intPoint : intPoint - 1;
  4240. c[ 1 ] = intPoint;
  4241. c[ 2 ] = intPoint > this.points.length - 2 ? this.points.length - 1 : intPoint + 1;
  4242. c[ 3 ] = intPoint > this.points.length - 3 ? this.points.length - 1 : intPoint + 2;
  4243. pa = this.points[ c[ 0 ] ];
  4244. pb = this.points[ c[ 1 ] ];
  4245. pc = this.points[ c[ 2 ] ];
  4246. pd = this.points[ c[ 3 ] ];
  4247. w2 = weight * weight;
  4248. w3 = weight * w2;
  4249. v3.x = interpolate( pa.x, pb.x, pc.x, pd.x, weight, w2, w3 );
  4250. v3.y = interpolate( pa.y, pb.y, pc.y, pd.y, weight, w2, w3 );
  4251. v3.z = interpolate( pa.z, pb.z, pc.z, pd.z, weight, w2, w3 );
  4252. return v3;
  4253. };
  4254. this.getControlPointsArray = function () {
  4255. var i, p, l = this.points.length,
  4256. coords = [];
  4257. for ( i = 0; i < l; i ++ ) {
  4258. p = this.points[ i ];
  4259. coords[ i ] = [ p.x, p.y, p.z ];
  4260. }
  4261. return coords;
  4262. };
  4263. // approximate length by summing linear segments
  4264. this.getLength = function ( nSubDivisions ) {
  4265. var i, index, nSamples, position,
  4266. point = 0, intPoint = 0, oldIntPoint = 0,
  4267. oldPosition = new THREE.Vector3(),
  4268. tmpVec = new THREE.Vector3(),
  4269. chunkLengths = [],
  4270. totalLength = 0;
  4271. // first point has 0 length
  4272. chunkLengths[ 0 ] = 0;
  4273. if ( ! nSubDivisions ) nSubDivisions = 100;
  4274. nSamples = this.points.length * nSubDivisions;
  4275. oldPosition.copy( this.points[ 0 ] );
  4276. for ( i = 1; i < nSamples; i ++ ) {
  4277. index = i / nSamples;
  4278. position = this.getPoint( index );
  4279. tmpVec.copy( position );
  4280. totalLength += tmpVec.distanceTo( oldPosition );
  4281. oldPosition.copy( position );
  4282. point = ( this.points.length - 1 ) * index;
  4283. intPoint = Math.floor( point );
  4284. if ( intPoint !== oldIntPoint ) {
  4285. chunkLengths[ intPoint ] = totalLength;
  4286. oldIntPoint = intPoint;
  4287. }
  4288. }
  4289. // last point ends with total length
  4290. chunkLengths[ chunkLengths.length ] = totalLength;
  4291. return { chunks: chunkLengths, total: totalLength };
  4292. };
  4293. this.reparametrizeByArcLength = function ( samplingCoef ) {
  4294. var i, j,
  4295. index, indexCurrent, indexNext,
  4296. realDistance,
  4297. sampling, position,
  4298. newpoints = [],
  4299. tmpVec = new THREE.Vector3(),
  4300. sl = this.getLength();
  4301. newpoints.push( tmpVec.copy( this.points[ 0 ] ).clone() );
  4302. for ( i = 1; i < this.points.length; i ++ ) {
  4303. //tmpVec.copy( this.points[ i - 1 ] );
  4304. //linearDistance = tmpVec.distanceTo( this.points[ i ] );
  4305. realDistance = sl.chunks[ i ] - sl.chunks[ i - 1 ];
  4306. sampling = Math.ceil( samplingCoef * realDistance / sl.total );
  4307. indexCurrent = ( i - 1 ) / ( this.points.length - 1 );
  4308. indexNext = i / ( this.points.length - 1 );
  4309. for ( j = 1; j < sampling - 1; j ++ ) {
  4310. index = indexCurrent + j * ( 1 / sampling ) * ( indexNext - indexCurrent );
  4311. position = this.getPoint( index );
  4312. newpoints.push( tmpVec.copy( position ).clone() );
  4313. }
  4314. newpoints.push( tmpVec.copy( this.points[ i ] ).clone() );
  4315. }
  4316. this.points = newpoints;
  4317. };
  4318. // Catmull-Rom
  4319. function interpolate( p0, p1, p2, p3, t, t2, t3 ) {
  4320. var v0 = ( p2 - p0 ) * 0.5,
  4321. v1 = ( p3 - p1 ) * 0.5;
  4322. return ( 2 * ( p1 - p2 ) + v0 + v1 ) * t3 + ( - 3 * ( p1 - p2 ) - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  4323. }
  4324. };
  4325. // File:src/math/Triangle.js
  4326. /**
  4327. * @author bhouston / http://clara.io
  4328. * @author mrdoob / http://mrdoob.com/
  4329. */
  4330. THREE.Triangle = function ( a, b, c ) {
  4331. this.a = ( a !== undefined ) ? a : new THREE.Vector3();
  4332. this.b = ( b !== undefined ) ? b : new THREE.Vector3();
  4333. this.c = ( c !== undefined ) ? c : new THREE.Vector3();
  4334. };
  4335. THREE.Triangle.normal = function () {
  4336. var v0 = new THREE.Vector3();
  4337. return function ( a, b, c, optionalTarget ) {
  4338. var result = optionalTarget || new THREE.Vector3();
  4339. result.subVectors( c, b );
  4340. v0.subVectors( a, b );
  4341. result.cross( v0 );
  4342. var resultLengthSq = result.lengthSq();
  4343. if ( resultLengthSq > 0 ) {
  4344. return result.multiplyScalar( 1 / Math.sqrt( resultLengthSq ) );
  4345. }
  4346. return result.set( 0, 0, 0 );
  4347. };
  4348. }();
  4349. // static/instance method to calculate barycentric coordinates
  4350. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  4351. THREE.Triangle.barycoordFromPoint = function () {
  4352. var v0 = new THREE.Vector3();
  4353. var v1 = new THREE.Vector3();
  4354. var v2 = new THREE.Vector3();
  4355. return function ( point, a, b, c, optionalTarget ) {
  4356. v0.subVectors( c, a );
  4357. v1.subVectors( b, a );
  4358. v2.subVectors( point, a );
  4359. var dot00 = v0.dot( v0 );
  4360. var dot01 = v0.dot( v1 );
  4361. var dot02 = v0.dot( v2 );
  4362. var dot11 = v1.dot( v1 );
  4363. var dot12 = v1.dot( v2 );
  4364. var denom = ( dot00 * dot11 - dot01 * dot01 );
  4365. var result = optionalTarget || new THREE.Vector3();
  4366. // collinear or singular triangle
  4367. if ( denom === 0 ) {
  4368. // arbitrary location outside of triangle?
  4369. // not sure if this is the best idea, maybe should be returning undefined
  4370. return result.set( - 2, - 1, - 1 );
  4371. }
  4372. var invDenom = 1 / denom;
  4373. var u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  4374. var v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  4375. // barycentric coordinates must always sum to 1
  4376. return result.set( 1 - u - v, v, u );
  4377. };
  4378. }();
  4379. THREE.Triangle.containsPoint = function () {
  4380. var v1 = new THREE.Vector3();
  4381. return function ( point, a, b, c ) {
  4382. var result = THREE.Triangle.barycoordFromPoint( point, a, b, c, v1 );
  4383. return ( result.x >= 0 ) && ( result.y >= 0 ) && ( ( result.x + result.y ) <= 1 );
  4384. };
  4385. }();
  4386. THREE.Triangle.prototype = {
  4387. constructor: THREE.Triangle,
  4388. set: function ( a, b, c ) {
  4389. this.a.copy( a );
  4390. this.b.copy( b );
  4391. this.c.copy( c );
  4392. return this;
  4393. },
  4394. setFromPointsAndIndices: function ( points, i0, i1, i2 ) {
  4395. this.a.copy( points[ i0 ] );
  4396. this.b.copy( points[ i1 ] );
  4397. this.c.copy( points[ i2 ] );
  4398. return this;
  4399. },
  4400. clone: function () {
  4401. return new this.constructor().copy( this );
  4402. },
  4403. copy: function ( triangle ) {
  4404. this.a.copy( triangle.a );
  4405. this.b.copy( triangle.b );
  4406. this.c.copy( triangle.c );
  4407. return this;
  4408. },
  4409. area: function () {
  4410. var v0 = new THREE.Vector3();
  4411. var v1 = new THREE.Vector3();
  4412. return function () {
  4413. v0.subVectors( this.c, this.b );
  4414. v1.subVectors( this.a, this.b );
  4415. return v0.cross( v1 ).length() * 0.5;
  4416. };
  4417. }(),
  4418. midpoint: function ( optionalTarget ) {
  4419. var result = optionalTarget || new THREE.Vector3();
  4420. return result.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  4421. },
  4422. normal: function ( optionalTarget ) {
  4423. return THREE.Triangle.normal( this.a, this.b, this.c, optionalTarget );
  4424. },
  4425. plane: function ( optionalTarget ) {
  4426. var result = optionalTarget || new THREE.Plane();
  4427. return result.setFromCoplanarPoints( this.a, this.b, this.c );
  4428. },
  4429. barycoordFromPoint: function ( point, optionalTarget ) {
  4430. return THREE.Triangle.barycoordFromPoint( point, this.a, this.b, this.c, optionalTarget );
  4431. },
  4432. containsPoint: function ( point ) {
  4433. return THREE.Triangle.containsPoint( point, this.a, this.b, this.c );
  4434. },
  4435. closestPointToPoint: function () {
  4436. var plane, edgeList, projectedPoint, closestPoint;
  4437. return function closestPointToPoint( point, optionalTarget ) {
  4438. if ( plane === undefined ) {
  4439. plane = new THREE.Plane();
  4440. edgeList = [ new THREE.Line3(), new THREE.Line3(), new THREE.Line3() ];
  4441. projectedPoint = new THREE.Vector3();
  4442. closestPoint = new THREE.Vector3();
  4443. }
  4444. var result = optionalTarget || new THREE.Vector3();
  4445. var minDistance = Infinity;
  4446. // project the point onto the plane of the triangle
  4447. plane.setFromCoplanarPoints( this.a, this.b, this.c );
  4448. plane.projectPoint( point, projectedPoint );
  4449. // check if the projection lies within the triangle
  4450. if( this.containsPoint( projectedPoint ) === true ) {
  4451. // if so, this is the closest point
  4452. result.copy( projectedPoint );
  4453. } else {
  4454. // if not, the point falls outside the triangle. the result is the closest point to the triangle's edges or vertices
  4455. edgeList[ 0 ].set( this.a, this.b );
  4456. edgeList[ 1 ].set( this.b, this.c );
  4457. edgeList[ 2 ].set( this.c, this.a );
  4458. for( var i = 0; i < edgeList.length; i ++ ) {
  4459. edgeList[ i ].closestPointToPoint( projectedPoint, true, closestPoint );
  4460. var distance = projectedPoint.distanceToSquared( closestPoint );
  4461. if( distance < minDistance ) {
  4462. minDistance = distance;
  4463. result.copy( closestPoint );
  4464. }
  4465. }
  4466. }
  4467. return result;
  4468. };
  4469. }(),
  4470. equals: function ( triangle ) {
  4471. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  4472. }
  4473. };
  4474. // File:src/math/Interpolant.js
  4475. /**
  4476. * Abstract base class of interpolants over parametric samples.
  4477. *
  4478. * The parameter domain is one dimensional, typically the time or a path
  4479. * along a curve defined by the data.
  4480. *
  4481. * The sample values can have any dimensionality and derived classes may
  4482. * apply special interpretations to the data.
  4483. *
  4484. * This class provides the interval seek in a Template Method, deferring
  4485. * the actual interpolation to derived classes.
  4486. *
  4487. * Time complexity is O(1) for linear access crossing at most two points
  4488. * and O(log N) for random access, where N is the number of positions.
  4489. *
  4490. * References:
  4491. *
  4492. * http://www.oodesign.com/template-method-pattern.html
  4493. *
  4494. * @author tschw
  4495. */
  4496. THREE.Interpolant = function(
  4497. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4498. this.parameterPositions = parameterPositions;
  4499. this._cachedIndex = 0;
  4500. this.resultBuffer = resultBuffer !== undefined ?
  4501. resultBuffer : new sampleValues.constructor( sampleSize );
  4502. this.sampleValues = sampleValues;
  4503. this.valueSize = sampleSize;
  4504. };
  4505. THREE.Interpolant.prototype = {
  4506. constructor: THREE.Interpolant,
  4507. evaluate: function( t ) {
  4508. var pp = this.parameterPositions,
  4509. i1 = this._cachedIndex,
  4510. t1 = pp[ i1 ],
  4511. t0 = pp[ i1 - 1 ];
  4512. validate_interval: {
  4513. seek: {
  4514. var right;
  4515. linear_scan: {
  4516. //- See http://jsperf.com/comparison-to-undefined/3
  4517. //- slower code:
  4518. //-
  4519. //- if ( t >= t1 || t1 === undefined ) {
  4520. forward_scan: if ( ! ( t < t1 ) ) {
  4521. for ( var giveUpAt = i1 + 2; ;) {
  4522. if ( t1 === undefined ) {
  4523. if ( t < t0 ) break forward_scan;
  4524. // after end
  4525. i1 = pp.length;
  4526. this._cachedIndex = i1;
  4527. return this.afterEnd_( i1 - 1, t, t0 );
  4528. }
  4529. if ( i1 === giveUpAt ) break; // this loop
  4530. t0 = t1;
  4531. t1 = pp[ ++ i1 ];
  4532. if ( t < t1 ) {
  4533. // we have arrived at the sought interval
  4534. break seek;
  4535. }
  4536. }
  4537. // prepare binary search on the right side of the index
  4538. right = pp.length;
  4539. break linear_scan;
  4540. }
  4541. //- slower code:
  4542. //- if ( t < t0 || t0 === undefined ) {
  4543. if ( ! ( t >= t0 ) ) {
  4544. // looping?
  4545. var t1global = pp[ 1 ];
  4546. if ( t < t1global ) {
  4547. i1 = 2; // + 1, using the scan for the details
  4548. t0 = t1global;
  4549. }
  4550. // linear reverse scan
  4551. for ( var giveUpAt = i1 - 2; ;) {
  4552. if ( t0 === undefined ) {
  4553. // before start
  4554. this._cachedIndex = 0;
  4555. return this.beforeStart_( 0, t, t1 );
  4556. }
  4557. if ( i1 === giveUpAt ) break; // this loop
  4558. t1 = t0;
  4559. t0 = pp[ -- i1 - 1 ];
  4560. if ( t >= t0 ) {
  4561. // we have arrived at the sought interval
  4562. break seek;
  4563. }
  4564. }
  4565. // prepare binary search on the left side of the index
  4566. right = i1;
  4567. i1 = 0;
  4568. break linear_scan;
  4569. }
  4570. // the interval is valid
  4571. break validate_interval;
  4572. } // linear scan
  4573. // binary search
  4574. while ( i1 < right ) {
  4575. var mid = ( i1 + right ) >>> 1;
  4576. if ( t < pp[ mid ] ) {
  4577. right = mid;
  4578. } else {
  4579. i1 = mid + 1;
  4580. }
  4581. }
  4582. t1 = pp[ i1 ];
  4583. t0 = pp[ i1 - 1 ];
  4584. // check boundary cases, again
  4585. if ( t0 === undefined ) {
  4586. this._cachedIndex = 0;
  4587. return this.beforeStart_( 0, t, t1 );
  4588. }
  4589. if ( t1 === undefined ) {
  4590. i1 = pp.length;
  4591. this._cachedIndex = i1;
  4592. return this.afterEnd_( i1 - 1, t0, t );
  4593. }
  4594. } // seek
  4595. this._cachedIndex = i1;
  4596. this.intervalChanged_( i1, t0, t1 );
  4597. } // validate_interval
  4598. return this.interpolate_( i1, t0, t, t1 );
  4599. },
  4600. settings: null, // optional, subclass-specific settings structure
  4601. // Note: The indirection allows central control of many interpolants.
  4602. // --- Protected interface
  4603. DefaultSettings_: {},
  4604. getSettings_: function() {
  4605. return this.settings || this.DefaultSettings_;
  4606. },
  4607. copySampleValue_: function( index ) {
  4608. // copies a sample value to the result buffer
  4609. var result = this.resultBuffer,
  4610. values = this.sampleValues,
  4611. stride = this.valueSize,
  4612. offset = index * stride;
  4613. for ( var i = 0; i !== stride; ++ i ) {
  4614. result[ i ] = values[ offset + i ];
  4615. }
  4616. return result;
  4617. },
  4618. // Template methods for derived classes:
  4619. interpolate_: function( i1, t0, t, t1 ) {
  4620. throw new Error( "call to abstract method" );
  4621. // implementations shall return this.resultBuffer
  4622. },
  4623. intervalChanged_: function( i1, t0, t1 ) {
  4624. // empty
  4625. }
  4626. };
  4627. Object.assign( THREE.Interpolant.prototype, {
  4628. beforeStart_: //( 0, t, t0 ), returns this.resultBuffer
  4629. THREE.Interpolant.prototype.copySampleValue_,
  4630. afterEnd_: //( N-1, tN-1, t ), returns this.resultBuffer
  4631. THREE.Interpolant.prototype.copySampleValue_
  4632. } );
  4633. // File:src/math/interpolants/CubicInterpolant.js
  4634. /**
  4635. * Fast and simple cubic spline interpolant.
  4636. *
  4637. * It was derived from a Hermitian construction setting the first derivative
  4638. * at each sample position to the linear slope between neighboring positions
  4639. * over their parameter interval.
  4640. *
  4641. * @author tschw
  4642. */
  4643. THREE.CubicInterpolant = function(
  4644. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4645. THREE.Interpolant.call(
  4646. this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  4647. this._weightPrev = -0;
  4648. this._offsetPrev = -0;
  4649. this._weightNext = -0;
  4650. this._offsetNext = -0;
  4651. };
  4652. THREE.CubicInterpolant.prototype =
  4653. Object.assign( Object.create( THREE.Interpolant.prototype ), {
  4654. constructor: THREE.CubicInterpolant,
  4655. DefaultSettings_: {
  4656. endingStart: THREE.ZeroCurvatureEnding,
  4657. endingEnd: THREE.ZeroCurvatureEnding
  4658. },
  4659. intervalChanged_: function( i1, t0, t1 ) {
  4660. var pp = this.parameterPositions,
  4661. iPrev = i1 - 2,
  4662. iNext = i1 + 1,
  4663. tPrev = pp[ iPrev ],
  4664. tNext = pp[ iNext ];
  4665. if ( tPrev === undefined ) {
  4666. switch ( this.getSettings_().endingStart ) {
  4667. case THREE.ZeroSlopeEnding:
  4668. // f'(t0) = 0
  4669. iPrev = i1;
  4670. tPrev = 2 * t0 - t1;
  4671. break;
  4672. case THREE.WrapAroundEnding:
  4673. // use the other end of the curve
  4674. iPrev = pp.length - 2;
  4675. tPrev = t0 + pp[ iPrev ] - pp[ iPrev + 1 ];
  4676. break;
  4677. default: // ZeroCurvatureEnding
  4678. // f''(t0) = 0 a.k.a. Natural Spline
  4679. iPrev = i1;
  4680. tPrev = t1;
  4681. }
  4682. }
  4683. if ( tNext === undefined ) {
  4684. switch ( this.getSettings_().endingEnd ) {
  4685. case THREE.ZeroSlopeEnding:
  4686. // f'(tN) = 0
  4687. iNext = i1;
  4688. tNext = 2 * t1 - t0;
  4689. break;
  4690. case THREE.WrapAroundEnding:
  4691. // use the other end of the curve
  4692. iNext = 1;
  4693. tNext = t1 + pp[ 1 ] - pp[ 0 ];
  4694. break;
  4695. default: // ZeroCurvatureEnding
  4696. // f''(tN) = 0, a.k.a. Natural Spline
  4697. iNext = i1 - 1;
  4698. tNext = t0;
  4699. }
  4700. }
  4701. var halfDt = ( t1 - t0 ) * 0.5,
  4702. stride = this.valueSize;
  4703. this._weightPrev = halfDt / ( t0 - tPrev );
  4704. this._weightNext = halfDt / ( tNext - t1 );
  4705. this._offsetPrev = iPrev * stride;
  4706. this._offsetNext = iNext * stride;
  4707. },
  4708. interpolate_: function( i1, t0, t, t1 ) {
  4709. var result = this.resultBuffer,
  4710. values = this.sampleValues,
  4711. stride = this.valueSize,
  4712. o1 = i1 * stride, o0 = o1 - stride,
  4713. oP = this._offsetPrev, oN = this._offsetNext,
  4714. wP = this._weightPrev, wN = this._weightNext,
  4715. p = ( t - t0 ) / ( t1 - t0 ),
  4716. pp = p * p,
  4717. ppp = pp * p;
  4718. // evaluate polynomials
  4719. var sP = - wP * ppp + 2 * wP * pp - wP * p;
  4720. var s0 = ( 1 + wP ) * ppp + (-1.5 - 2 * wP ) * pp + ( -0.5 + wP ) * p + 1;
  4721. var s1 = (-1 - wN ) * ppp + ( 1.5 + wN ) * pp + 0.5 * p;
  4722. var sN = wN * ppp - wN * pp;
  4723. // combine data linearly
  4724. for ( var i = 0; i !== stride; ++ i ) {
  4725. result[ i ] =
  4726. sP * values[ oP + i ] +
  4727. s0 * values[ o0 + i ] +
  4728. s1 * values[ o1 + i ] +
  4729. sN * values[ oN + i ];
  4730. }
  4731. return result;
  4732. }
  4733. } );
  4734. // File:src/math/interpolants/DiscreteInterpolant.js
  4735. /**
  4736. *
  4737. * Interpolant that evaluates to the sample value at the position preceeding
  4738. * the parameter.
  4739. *
  4740. * @author tschw
  4741. */
  4742. THREE.DiscreteInterpolant = function(
  4743. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4744. THREE.Interpolant.call(
  4745. this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  4746. };
  4747. THREE.DiscreteInterpolant.prototype =
  4748. Object.assign( Object.create( THREE.Interpolant.prototype ), {
  4749. constructor: THREE.DiscreteInterpolant,
  4750. interpolate_: function( i1, t0, t, t1 ) {
  4751. return this.copySampleValue_( i1 - 1 );
  4752. }
  4753. } );
  4754. // File:src/math/interpolants/LinearInterpolant.js
  4755. /**
  4756. * @author tschw
  4757. */
  4758. THREE.LinearInterpolant = function(
  4759. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4760. THREE.Interpolant.call(
  4761. this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  4762. };
  4763. THREE.LinearInterpolant.prototype =
  4764. Object.assign( Object.create( THREE.Interpolant.prototype ), {
  4765. constructor: THREE.LinearInterpolant,
  4766. interpolate_: function( i1, t0, t, t1 ) {
  4767. var result = this.resultBuffer,
  4768. values = this.sampleValues,
  4769. stride = this.valueSize,
  4770. offset1 = i1 * stride,
  4771. offset0 = offset1 - stride,
  4772. weight1 = ( t - t0 ) / ( t1 - t0 ),
  4773. weight0 = 1 - weight1;
  4774. for ( var i = 0; i !== stride; ++ i ) {
  4775. result[ i ] =
  4776. values[ offset0 + i ] * weight0 +
  4777. values[ offset1 + i ] * weight1;
  4778. }
  4779. return result;
  4780. }
  4781. } );
  4782. // File:src/math/interpolants/QuaternionLinearInterpolant.js
  4783. /**
  4784. * Spherical linear unit quaternion interpolant.
  4785. *
  4786. * @author tschw
  4787. */
  4788. THREE.QuaternionLinearInterpolant = function(
  4789. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4790. THREE.Interpolant.call(
  4791. this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  4792. };
  4793. THREE.QuaternionLinearInterpolant.prototype =
  4794. Object.assign( Object.create( THREE.Interpolant.prototype ), {
  4795. constructor: THREE.QuaternionLinearInterpolant,
  4796. interpolate_: function( i1, t0, t, t1 ) {
  4797. var result = this.resultBuffer,
  4798. values = this.sampleValues,
  4799. stride = this.valueSize,
  4800. offset = i1 * stride,
  4801. alpha = ( t - t0 ) / ( t1 - t0 );
  4802. for ( var end = offset + stride; offset !== end; offset += 4 ) {
  4803. THREE.Quaternion.slerpFlat( result, 0,
  4804. values, offset - stride, values, offset, alpha );
  4805. }
  4806. return result;
  4807. }
  4808. } );
  4809. // File:src/core/Clock.js
  4810. /**
  4811. * @author alteredq / http://alteredqualia.com/
  4812. */
  4813. THREE.Clock = function ( autoStart ) {
  4814. this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
  4815. this.startTime = 0;
  4816. this.oldTime = 0;
  4817. this.elapsedTime = 0;
  4818. this.running = false;
  4819. };
  4820. THREE.Clock.prototype = {
  4821. constructor: THREE.Clock,
  4822. start: function () {
  4823. this.startTime = ( performance || Date ).now();
  4824. this.oldTime = this.startTime;
  4825. this.running = true;
  4826. },
  4827. stop: function () {
  4828. this.getElapsedTime();
  4829. this.running = false;
  4830. },
  4831. getElapsedTime: function () {
  4832. this.getDelta();
  4833. return this.elapsedTime;
  4834. },
  4835. getDelta: function () {
  4836. var diff = 0;
  4837. if ( this.autoStart && ! this.running ) {
  4838. this.start();
  4839. }
  4840. if ( this.running ) {
  4841. var newTime = ( performance || Date ).now();
  4842. diff = ( newTime - this.oldTime ) / 1000;
  4843. this.oldTime = newTime;
  4844. this.elapsedTime += diff;
  4845. }
  4846. return diff;
  4847. }
  4848. };
  4849. // File:src/core/EventDispatcher.js
  4850. /**
  4851. * https://github.com/mrdoob/eventdispatcher.js/
  4852. */
  4853. THREE.EventDispatcher = function () {};
  4854. Object.assign( THREE.EventDispatcher.prototype, {
  4855. addEventListener: function ( type, listener ) {
  4856. if ( this._listeners === undefined ) this._listeners = {};
  4857. var listeners = this._listeners;
  4858. if ( listeners[ type ] === undefined ) {
  4859. listeners[ type ] = [];
  4860. }
  4861. if ( listeners[ type ].indexOf( listener ) === - 1 ) {
  4862. listeners[ type ].push( listener );
  4863. }
  4864. },
  4865. hasEventListener: function ( type, listener ) {
  4866. if ( this._listeners === undefined ) return false;
  4867. var listeners = this._listeners;
  4868. if ( listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1 ) {
  4869. return true;
  4870. }
  4871. return false;
  4872. },
  4873. removeEventListener: function ( type, listener ) {
  4874. if ( this._listeners === undefined ) return;
  4875. var listeners = this._listeners;
  4876. var listenerArray = listeners[ type ];
  4877. if ( listenerArray !== undefined ) {
  4878. var index = listenerArray.indexOf( listener );
  4879. if ( index !== - 1 ) {
  4880. listenerArray.splice( index, 1 );
  4881. }
  4882. }
  4883. },
  4884. dispatchEvent: function ( event ) {
  4885. if ( this._listeners === undefined ) return;
  4886. var listeners = this._listeners;
  4887. var listenerArray = listeners[ event.type ];
  4888. if ( listenerArray !== undefined ) {
  4889. event.target = this;
  4890. var array = [], i = 0;
  4891. var length = listenerArray.length;
  4892. for ( i = 0; i < length; i ++ ) {
  4893. array[ i ] = listenerArray[ i ];
  4894. }
  4895. for ( i = 0; i < length; i ++ ) {
  4896. array[ i ].call( this, event );
  4897. }
  4898. }
  4899. }
  4900. } );
  4901. // File:src/core/Layers.js
  4902. /**
  4903. * @author mrdoob / http://mrdoob.com/
  4904. */
  4905. THREE.Layers = function () {
  4906. this.mask = 1;
  4907. };
  4908. THREE.Layers.prototype = {
  4909. constructor: THREE.Layers,
  4910. set: function ( channel ) {
  4911. this.mask = 1 << channel;
  4912. },
  4913. enable: function ( channel ) {
  4914. this.mask |= 1 << channel;
  4915. },
  4916. toggle: function ( channel ) {
  4917. this.mask ^= 1 << channel;
  4918. },
  4919. disable: function ( channel ) {
  4920. this.mask &= ~ ( 1 << channel );
  4921. },
  4922. test: function ( layers ) {
  4923. return ( this.mask & layers.mask ) !== 0;
  4924. }
  4925. };
  4926. // File:src/core/Raycaster.js
  4927. /**
  4928. * @author mrdoob / http://mrdoob.com/
  4929. * @author bhouston / http://clara.io/
  4930. * @author stephomi / http://stephaneginier.com/
  4931. */
  4932. ( function ( THREE ) {
  4933. THREE.Raycaster = function ( origin, direction, near, far ) {
  4934. this.ray = new THREE.Ray( origin, direction );
  4935. // direction is assumed to be normalized (for accurate distance calculations)
  4936. this.near = near || 0;
  4937. this.far = far || Infinity;
  4938. this.params = {
  4939. Mesh: {},
  4940. Line: {},
  4941. LOD: {},
  4942. Points: { threshold: 1 },
  4943. Sprite: {}
  4944. };
  4945. Object.defineProperties( this.params, {
  4946. PointCloud: {
  4947. get: function () {
  4948. console.warn( 'THREE.Raycaster: params.PointCloud has been renamed to params.Points.' );
  4949. return this.Points;
  4950. }
  4951. }
  4952. } );
  4953. };
  4954. function ascSort( a, b ) {
  4955. return a.distance - b.distance;
  4956. }
  4957. function intersectObject( object, raycaster, intersects, recursive ) {
  4958. if ( object.visible === false ) return;
  4959. object.raycast( raycaster, intersects );
  4960. if ( recursive === true ) {
  4961. var children = object.children;
  4962. for ( var i = 0, l = children.length; i < l; i ++ ) {
  4963. intersectObject( children[ i ], raycaster, intersects, true );
  4964. }
  4965. }
  4966. }
  4967. //
  4968. THREE.Raycaster.prototype = {
  4969. constructor: THREE.Raycaster,
  4970. linePrecision: 1,
  4971. set: function ( origin, direction ) {
  4972. // direction is assumed to be normalized (for accurate distance calculations)
  4973. this.ray.set( origin, direction );
  4974. },
  4975. setFromCamera: function ( coords, camera ) {
  4976. if ( camera instanceof THREE.PerspectiveCamera ) {
  4977. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  4978. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  4979. } else if ( camera instanceof THREE.OrthographicCamera ) {
  4980. this.ray.origin.set( coords.x, coords.y, - 1 ).unproject( camera );
  4981. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  4982. } else {
  4983. console.error( 'THREE.Raycaster: Unsupported camera type.' );
  4984. }
  4985. },
  4986. intersectObject: function ( object, recursive ) {
  4987. var intersects = [];
  4988. intersectObject( object, this, intersects, recursive );
  4989. intersects.sort( ascSort );
  4990. return intersects;
  4991. },
  4992. intersectObjects: function ( objects, recursive ) {
  4993. var intersects = [];
  4994. if ( Array.isArray( objects ) === false ) {
  4995. console.warn( 'THREE.Raycaster.intersectObjects: objects is not an Array.' );
  4996. return intersects;
  4997. }
  4998. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  4999. intersectObject( objects[ i ], this, intersects, recursive );
  5000. }
  5001. intersects.sort( ascSort );
  5002. return intersects;
  5003. }
  5004. };
  5005. }( THREE ) );
  5006. // File:src/core/Object3D.js
  5007. /**
  5008. * @author mrdoob / http://mrdoob.com/
  5009. * @author mikael emtinger / http://gomo.se/
  5010. * @author alteredq / http://alteredqualia.com/
  5011. * @author WestLangley / http://github.com/WestLangley
  5012. * @author elephantatwork / www.elephantatwork.ch
  5013. */
  5014. THREE.Object3D = function () {
  5015. Object.defineProperty( this, 'id', { value: THREE.Object3DIdCount ++ } );
  5016. this.uuid = THREE.Math.generateUUID();
  5017. this.name = '';
  5018. this.type = 'Object3D';
  5019. this.parent = null;
  5020. this.children = [];
  5021. this.up = THREE.Object3D.DefaultUp.clone();
  5022. var position = new THREE.Vector3();
  5023. var rotation = new THREE.Euler();
  5024. var quaternion = new THREE.Quaternion();
  5025. var scale = new THREE.Vector3( 1, 1, 1 );
  5026. function onRotationChange() {
  5027. quaternion.setFromEuler( rotation, false );
  5028. }
  5029. function onQuaternionChange() {
  5030. rotation.setFromQuaternion( quaternion, undefined, false );
  5031. }
  5032. rotation.onChange( onRotationChange );
  5033. quaternion.onChange( onQuaternionChange );
  5034. Object.defineProperties( this, {
  5035. position: {
  5036. enumerable: true,
  5037. value: position
  5038. },
  5039. rotation: {
  5040. enumerable: true,
  5041. value: rotation
  5042. },
  5043. quaternion: {
  5044. enumerable: true,
  5045. value: quaternion
  5046. },
  5047. scale: {
  5048. enumerable: true,
  5049. value: scale
  5050. },
  5051. modelViewMatrix: {
  5052. value: new THREE.Matrix4()
  5053. },
  5054. normalMatrix: {
  5055. value: new THREE.Matrix3()
  5056. }
  5057. } );
  5058. this.matrix = new THREE.Matrix4();
  5059. this.matrixWorld = new THREE.Matrix4();
  5060. this.matrixAutoUpdate = THREE.Object3D.DefaultMatrixAutoUpdate;
  5061. this.matrixWorldNeedsUpdate = false;
  5062. this.layers = new THREE.Layers();
  5063. this.visible = true;
  5064. this.castShadow = false;
  5065. this.receiveShadow = false;
  5066. this.frustumCulled = true;
  5067. this.renderOrder = 0;
  5068. this.userData = {};
  5069. };
  5070. THREE.Object3D.DefaultUp = new THREE.Vector3( 0, 1, 0 );
  5071. THREE.Object3D.DefaultMatrixAutoUpdate = true;
  5072. Object.assign( THREE.Object3D.prototype, THREE.EventDispatcher.prototype, {
  5073. applyMatrix: function ( matrix ) {
  5074. this.matrix.multiplyMatrices( matrix, this.matrix );
  5075. this.matrix.decompose( this.position, this.quaternion, this.scale );
  5076. },
  5077. setRotationFromAxisAngle: function ( axis, angle ) {
  5078. // assumes axis is normalized
  5079. this.quaternion.setFromAxisAngle( axis, angle );
  5080. },
  5081. setRotationFromEuler: function ( euler ) {
  5082. this.quaternion.setFromEuler( euler, true );
  5083. },
  5084. setRotationFromMatrix: function ( m ) {
  5085. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  5086. this.quaternion.setFromRotationMatrix( m );
  5087. },
  5088. setRotationFromQuaternion: function ( q ) {
  5089. // assumes q is normalized
  5090. this.quaternion.copy( q );
  5091. },
  5092. rotateOnAxis: function () {
  5093. // rotate object on axis in object space
  5094. // axis is assumed to be normalized
  5095. var q1 = new THREE.Quaternion();
  5096. return function ( axis, angle ) {
  5097. q1.setFromAxisAngle( axis, angle );
  5098. this.quaternion.multiply( q1 );
  5099. return this;
  5100. };
  5101. }(),
  5102. rotateX: function () {
  5103. var v1 = new THREE.Vector3( 1, 0, 0 );
  5104. return function ( angle ) {
  5105. return this.rotateOnAxis( v1, angle );
  5106. };
  5107. }(),
  5108. rotateY: function () {
  5109. var v1 = new THREE.Vector3( 0, 1, 0 );
  5110. return function ( angle ) {
  5111. return this.rotateOnAxis( v1, angle );
  5112. };
  5113. }(),
  5114. rotateZ: function () {
  5115. var v1 = new THREE.Vector3( 0, 0, 1 );
  5116. return function ( angle ) {
  5117. return this.rotateOnAxis( v1, angle );
  5118. };
  5119. }(),
  5120. translateOnAxis: function () {
  5121. // translate object by distance along axis in object space
  5122. // axis is assumed to be normalized
  5123. var v1 = new THREE.Vector3();
  5124. return function ( axis, distance ) {
  5125. v1.copy( axis ).applyQuaternion( this.quaternion );
  5126. this.position.add( v1.multiplyScalar( distance ) );
  5127. return this;
  5128. };
  5129. }(),
  5130. translateX: function () {
  5131. var v1 = new THREE.Vector3( 1, 0, 0 );
  5132. return function ( distance ) {
  5133. return this.translateOnAxis( v1, distance );
  5134. };
  5135. }(),
  5136. translateY: function () {
  5137. var v1 = new THREE.Vector3( 0, 1, 0 );
  5138. return function ( distance ) {
  5139. return this.translateOnAxis( v1, distance );
  5140. };
  5141. }(),
  5142. translateZ: function () {
  5143. var v1 = new THREE.Vector3( 0, 0, 1 );
  5144. return function ( distance ) {
  5145. return this.translateOnAxis( v1, distance );
  5146. };
  5147. }(),
  5148. localToWorld: function ( vector ) {
  5149. return vector.applyMatrix4( this.matrixWorld );
  5150. },
  5151. worldToLocal: function () {
  5152. var m1 = new THREE.Matrix4();
  5153. return function ( vector ) {
  5154. return vector.applyMatrix4( m1.getInverse( this.matrixWorld ) );
  5155. };
  5156. }(),
  5157. lookAt: function () {
  5158. // This routine does not support objects with rotated and/or translated parent(s)
  5159. var m1 = new THREE.Matrix4();
  5160. return function ( vector ) {
  5161. m1.lookAt( vector, this.position, this.up );
  5162. this.quaternion.setFromRotationMatrix( m1 );
  5163. };
  5164. }(),
  5165. add: function ( object ) {
  5166. if ( arguments.length > 1 ) {
  5167. for ( var i = 0; i < arguments.length; i ++ ) {
  5168. this.add( arguments[ i ] );
  5169. }
  5170. return this;
  5171. }
  5172. if ( object === this ) {
  5173. console.error( "THREE.Object3D.add: object can't be added as a child of itself.", object );
  5174. return this;
  5175. }
  5176. if ( object instanceof THREE.Object3D ) {
  5177. if ( object.parent !== null ) {
  5178. object.parent.remove( object );
  5179. }
  5180. object.parent = this;
  5181. object.dispatchEvent( { type: 'added' } );
  5182. this.children.push( object );
  5183. } else {
  5184. console.error( "THREE.Object3D.add: object not an instance of THREE.Object3D.", object );
  5185. }
  5186. return this;
  5187. },
  5188. remove: function ( object ) {
  5189. if ( arguments.length > 1 ) {
  5190. for ( var i = 0; i < arguments.length; i ++ ) {
  5191. this.remove( arguments[ i ] );
  5192. }
  5193. }
  5194. var index = this.children.indexOf( object );
  5195. if ( index !== - 1 ) {
  5196. object.parent = null;
  5197. object.dispatchEvent( { type: 'removed' } );
  5198. this.children.splice( index, 1 );
  5199. }
  5200. },
  5201. getObjectById: function ( id ) {
  5202. return this.getObjectByProperty( 'id', id );
  5203. },
  5204. getObjectByName: function ( name ) {
  5205. return this.getObjectByProperty( 'name', name );
  5206. },
  5207. getObjectByProperty: function ( name, value ) {
  5208. if ( this[ name ] === value ) return this;
  5209. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  5210. var child = this.children[ i ];
  5211. var object = child.getObjectByProperty( name, value );
  5212. if ( object !== undefined ) {
  5213. return object;
  5214. }
  5215. }
  5216. return undefined;
  5217. },
  5218. getWorldPosition: function ( optionalTarget ) {
  5219. var result = optionalTarget || new THREE.Vector3();
  5220. this.updateMatrixWorld( true );
  5221. return result.setFromMatrixPosition( this.matrixWorld );
  5222. },
  5223. getWorldQuaternion: function () {
  5224. var position = new THREE.Vector3();
  5225. var scale = new THREE.Vector3();
  5226. return function ( optionalTarget ) {
  5227. var result = optionalTarget || new THREE.Quaternion();
  5228. this.updateMatrixWorld( true );
  5229. this.matrixWorld.decompose( position, result, scale );
  5230. return result;
  5231. };
  5232. }(),
  5233. getWorldRotation: function () {
  5234. var quaternion = new THREE.Quaternion();
  5235. return function ( optionalTarget ) {
  5236. var result = optionalTarget || new THREE.Euler();
  5237. this.getWorldQuaternion( quaternion );
  5238. return result.setFromQuaternion( quaternion, this.rotation.order, false );
  5239. };
  5240. }(),
  5241. getWorldScale: function () {
  5242. var position = new THREE.Vector3();
  5243. var quaternion = new THREE.Quaternion();
  5244. return function ( optionalTarget ) {
  5245. var result = optionalTarget || new THREE.Vector3();
  5246. this.updateMatrixWorld( true );
  5247. this.matrixWorld.decompose( position, quaternion, result );
  5248. return result;
  5249. };
  5250. }(),
  5251. getWorldDirection: function () {
  5252. var quaternion = new THREE.Quaternion();
  5253. return function ( optionalTarget ) {
  5254. var result = optionalTarget || new THREE.Vector3();
  5255. this.getWorldQuaternion( quaternion );
  5256. return result.set( 0, 0, 1 ).applyQuaternion( quaternion );
  5257. };
  5258. }(),
  5259. raycast: function () {},
  5260. traverse: function ( callback ) {
  5261. callback( this );
  5262. var children = this.children;
  5263. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5264. children[ i ].traverse( callback );
  5265. }
  5266. },
  5267. traverseVisible: function ( callback ) {
  5268. if ( this.visible === false ) return;
  5269. callback( this );
  5270. var children = this.children;
  5271. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5272. children[ i ].traverseVisible( callback );
  5273. }
  5274. },
  5275. traverseAncestors: function ( callback ) {
  5276. var parent = this.parent;
  5277. if ( parent !== null ) {
  5278. callback( parent );
  5279. parent.traverseAncestors( callback );
  5280. }
  5281. },
  5282. updateMatrix: function () {
  5283. this.matrix.compose( this.position, this.quaternion, this.scale );
  5284. this.matrixWorldNeedsUpdate = true;
  5285. },
  5286. updateMatrixWorld: function ( force ) {
  5287. if ( this.matrixAutoUpdate === true ) this.updateMatrix();
  5288. if ( this.matrixWorldNeedsUpdate === true || force === true ) {
  5289. if ( this.parent === null ) {
  5290. this.matrixWorld.copy( this.matrix );
  5291. } else {
  5292. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  5293. }
  5294. this.matrixWorldNeedsUpdate = false;
  5295. force = true;
  5296. }
  5297. // update children
  5298. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  5299. this.children[ i ].updateMatrixWorld( force );
  5300. }
  5301. },
  5302. toJSON: function ( meta ) {
  5303. // meta is '' when called from JSON.stringify
  5304. var isRootObject = ( meta === undefined || meta === '' );
  5305. var output = {};
  5306. // meta is a hash used to collect geometries, materials.
  5307. // not providing it implies that this is the root object
  5308. // being serialized.
  5309. if ( isRootObject ) {
  5310. // initialize meta obj
  5311. meta = {
  5312. geometries: {},
  5313. materials: {},
  5314. textures: {},
  5315. images: {}
  5316. };
  5317. output.metadata = {
  5318. version: 4.4,
  5319. type: 'Object',
  5320. generator: 'Object3D.toJSON'
  5321. };
  5322. }
  5323. // standard Object3D serialization
  5324. var object = {};
  5325. object.uuid = this.uuid;
  5326. object.type = this.type;
  5327. if ( this.name !== '' ) object.name = this.name;
  5328. if ( JSON.stringify( this.userData ) !== '{}' ) object.userData = this.userData;
  5329. if ( this.castShadow === true ) object.castShadow = true;
  5330. if ( this.receiveShadow === true ) object.receiveShadow = true;
  5331. if ( this.visible === false ) object.visible = false;
  5332. object.matrix = this.matrix.toArray();
  5333. //
  5334. if ( this.geometry !== undefined ) {
  5335. if ( meta.geometries[ this.geometry.uuid ] === undefined ) {
  5336. meta.geometries[ this.geometry.uuid ] = this.geometry.toJSON( meta );
  5337. }
  5338. object.geometry = this.geometry.uuid;
  5339. }
  5340. if ( this.material !== undefined ) {
  5341. if ( meta.materials[ this.material.uuid ] === undefined ) {
  5342. meta.materials[ this.material.uuid ] = this.material.toJSON( meta );
  5343. }
  5344. object.material = this.material.uuid;
  5345. }
  5346. //
  5347. if ( this.children.length > 0 ) {
  5348. object.children = [];
  5349. for ( var i = 0; i < this.children.length; i ++ ) {
  5350. object.children.push( this.children[ i ].toJSON( meta ).object );
  5351. }
  5352. }
  5353. if ( isRootObject ) {
  5354. var geometries = extractFromCache( meta.geometries );
  5355. var materials = extractFromCache( meta.materials );
  5356. var textures = extractFromCache( meta.textures );
  5357. var images = extractFromCache( meta.images );
  5358. if ( geometries.length > 0 ) output.geometries = geometries;
  5359. if ( materials.length > 0 ) output.materials = materials;
  5360. if ( textures.length > 0 ) output.textures = textures;
  5361. if ( images.length > 0 ) output.images = images;
  5362. }
  5363. output.object = object;
  5364. return output;
  5365. // extract data from the cache hash
  5366. // remove metadata on each item
  5367. // and return as array
  5368. function extractFromCache ( cache ) {
  5369. var values = [];
  5370. for ( var key in cache ) {
  5371. var data = cache[ key ];
  5372. delete data.metadata;
  5373. values.push( data );
  5374. }
  5375. return values;
  5376. }
  5377. },
  5378. clone: function ( recursive ) {
  5379. return new this.constructor().copy( this, recursive );
  5380. },
  5381. copy: function ( source, recursive ) {
  5382. if ( recursive === undefined ) recursive = true;
  5383. this.name = source.name;
  5384. this.up.copy( source.up );
  5385. this.position.copy( source.position );
  5386. this.quaternion.copy( source.quaternion );
  5387. this.scale.copy( source.scale );
  5388. this.matrix.copy( source.matrix );
  5389. this.matrixWorld.copy( source.matrixWorld );
  5390. this.matrixAutoUpdate = source.matrixAutoUpdate;
  5391. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  5392. this.visible = source.visible;
  5393. this.castShadow = source.castShadow;
  5394. this.receiveShadow = source.receiveShadow;
  5395. this.frustumCulled = source.frustumCulled;
  5396. this.renderOrder = source.renderOrder;
  5397. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  5398. if ( recursive === true ) {
  5399. for ( var i = 0; i < source.children.length; i ++ ) {
  5400. var child = source.children[ i ];
  5401. this.add( child.clone() );
  5402. }
  5403. }
  5404. return this;
  5405. }
  5406. } );
  5407. THREE.Object3DIdCount = 0;
  5408. // File:src/core/Face3.js
  5409. /**
  5410. * @author mrdoob / http://mrdoob.com/
  5411. * @author alteredq / http://alteredqualia.com/
  5412. */
  5413. THREE.Face3 = function ( a, b, c, normal, color, materialIndex ) {
  5414. this.a = a;
  5415. this.b = b;
  5416. this.c = c;
  5417. this.normal = normal instanceof THREE.Vector3 ? normal : new THREE.Vector3();
  5418. this.vertexNormals = Array.isArray( normal ) ? normal : [];
  5419. this.color = color instanceof THREE.Color ? color : new THREE.Color();
  5420. this.vertexColors = Array.isArray( color ) ? color : [];
  5421. this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
  5422. };
  5423. THREE.Face3.prototype = {
  5424. constructor: THREE.Face3,
  5425. clone: function () {
  5426. return new this.constructor().copy( this );
  5427. },
  5428. copy: function ( source ) {
  5429. this.a = source.a;
  5430. this.b = source.b;
  5431. this.c = source.c;
  5432. this.normal.copy( source.normal );
  5433. this.color.copy( source.color );
  5434. this.materialIndex = source.materialIndex;
  5435. for ( var i = 0, il = source.vertexNormals.length; i < il; i ++ ) {
  5436. this.vertexNormals[ i ] = source.vertexNormals[ i ].clone();
  5437. }
  5438. for ( var i = 0, il = source.vertexColors.length; i < il; i ++ ) {
  5439. this.vertexColors[ i ] = source.vertexColors[ i ].clone();
  5440. }
  5441. return this;
  5442. }
  5443. };
  5444. // File:src/core/BufferAttribute.js
  5445. /**
  5446. * @author mrdoob / http://mrdoob.com/
  5447. */
  5448. THREE.BufferAttribute = function ( array, itemSize, normalized ) {
  5449. this.uuid = THREE.Math.generateUUID();
  5450. this.array = array;
  5451. this.itemSize = itemSize;
  5452. this.dynamic = false;
  5453. this.updateRange = { offset: 0, count: - 1 };
  5454. this.version = 0;
  5455. this.normalized = normalized === true;
  5456. };
  5457. THREE.BufferAttribute.prototype = {
  5458. constructor: THREE.BufferAttribute,
  5459. get count() {
  5460. return this.array.length / this.itemSize;
  5461. },
  5462. set needsUpdate( value ) {
  5463. if ( value === true ) this.version ++;
  5464. },
  5465. setDynamic: function ( value ) {
  5466. this.dynamic = value;
  5467. return this;
  5468. },
  5469. copy: function ( source ) {
  5470. this.array = new source.array.constructor( source.array );
  5471. this.itemSize = source.itemSize;
  5472. this.dynamic = source.dynamic;
  5473. return this;
  5474. },
  5475. copyAt: function ( index1, attribute, index2 ) {
  5476. index1 *= this.itemSize;
  5477. index2 *= attribute.itemSize;
  5478. for ( var i = 0, l = this.itemSize; i < l; i ++ ) {
  5479. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5480. }
  5481. return this;
  5482. },
  5483. copyArray: function ( array ) {
  5484. this.array.set( array );
  5485. return this;
  5486. },
  5487. copyColorsArray: function ( colors ) {
  5488. var array = this.array, offset = 0;
  5489. for ( var i = 0, l = colors.length; i < l; i ++ ) {
  5490. var color = colors[ i ];
  5491. if ( color === undefined ) {
  5492. console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
  5493. color = new THREE.Color();
  5494. }
  5495. array[ offset ++ ] = color.r;
  5496. array[ offset ++ ] = color.g;
  5497. array[ offset ++ ] = color.b;
  5498. }
  5499. return this;
  5500. },
  5501. copyIndicesArray: function ( indices ) {
  5502. var array = this.array, offset = 0;
  5503. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  5504. var index = indices[ i ];
  5505. array[ offset ++ ] = index.a;
  5506. array[ offset ++ ] = index.b;
  5507. array[ offset ++ ] = index.c;
  5508. }
  5509. return this;
  5510. },
  5511. copyVector2sArray: function ( vectors ) {
  5512. var array = this.array, offset = 0;
  5513. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5514. var vector = vectors[ i ];
  5515. if ( vector === undefined ) {
  5516. console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
  5517. vector = new THREE.Vector2();
  5518. }
  5519. array[ offset ++ ] = vector.x;
  5520. array[ offset ++ ] = vector.y;
  5521. }
  5522. return this;
  5523. },
  5524. copyVector3sArray: function ( vectors ) {
  5525. var array = this.array, offset = 0;
  5526. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5527. var vector = vectors[ i ];
  5528. if ( vector === undefined ) {
  5529. console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
  5530. vector = new THREE.Vector3();
  5531. }
  5532. array[ offset ++ ] = vector.x;
  5533. array[ offset ++ ] = vector.y;
  5534. array[ offset ++ ] = vector.z;
  5535. }
  5536. return this;
  5537. },
  5538. copyVector4sArray: function ( vectors ) {
  5539. var array = this.array, offset = 0;
  5540. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5541. var vector = vectors[ i ];
  5542. if ( vector === undefined ) {
  5543. console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i );
  5544. vector = new THREE.Vector4();
  5545. }
  5546. array[ offset ++ ] = vector.x;
  5547. array[ offset ++ ] = vector.y;
  5548. array[ offset ++ ] = vector.z;
  5549. array[ offset ++ ] = vector.w;
  5550. }
  5551. return this;
  5552. },
  5553. set: function ( value, offset ) {
  5554. if ( offset === undefined ) offset = 0;
  5555. this.array.set( value, offset );
  5556. return this;
  5557. },
  5558. getX: function ( index ) {
  5559. return this.array[ index * this.itemSize ];
  5560. },
  5561. setX: function ( index, x ) {
  5562. this.array[ index * this.itemSize ] = x;
  5563. return this;
  5564. },
  5565. getY: function ( index ) {
  5566. return this.array[ index * this.itemSize + 1 ];
  5567. },
  5568. setY: function ( index, y ) {
  5569. this.array[ index * this.itemSize + 1 ] = y;
  5570. return this;
  5571. },
  5572. getZ: function ( index ) {
  5573. return this.array[ index * this.itemSize + 2 ];
  5574. },
  5575. setZ: function ( index, z ) {
  5576. this.array[ index * this.itemSize + 2 ] = z;
  5577. return this;
  5578. },
  5579. getW: function ( index ) {
  5580. return this.array[ index * this.itemSize + 3 ];
  5581. },
  5582. setW: function ( index, w ) {
  5583. this.array[ index * this.itemSize + 3 ] = w;
  5584. return this;
  5585. },
  5586. setXY: function ( index, x, y ) {
  5587. index *= this.itemSize;
  5588. this.array[ index + 0 ] = x;
  5589. this.array[ index + 1 ] = y;
  5590. return this;
  5591. },
  5592. setXYZ: function ( index, x, y, z ) {
  5593. index *= this.itemSize;
  5594. this.array[ index + 0 ] = x;
  5595. this.array[ index + 1 ] = y;
  5596. this.array[ index + 2 ] = z;
  5597. return this;
  5598. },
  5599. setXYZW: function ( index, x, y, z, w ) {
  5600. index *= this.itemSize;
  5601. this.array[ index + 0 ] = x;
  5602. this.array[ index + 1 ] = y;
  5603. this.array[ index + 2 ] = z;
  5604. this.array[ index + 3 ] = w;
  5605. return this;
  5606. },
  5607. clone: function () {
  5608. return new this.constructor().copy( this );
  5609. }
  5610. };
  5611. //
  5612. THREE.Int8Attribute = function ( array, itemSize ) {
  5613. return new THREE.BufferAttribute( new Int8Array( array ), itemSize );
  5614. };
  5615. THREE.Uint8Attribute = function ( array, itemSize ) {
  5616. return new THREE.BufferAttribute( new Uint8Array( array ), itemSize );
  5617. };
  5618. THREE.Uint8ClampedAttribute = function ( array, itemSize ) {
  5619. return new THREE.BufferAttribute( new Uint8ClampedArray( array ), itemSize );
  5620. };
  5621. THREE.Int16Attribute = function ( array, itemSize ) {
  5622. return new THREE.BufferAttribute( new Int16Array( array ), itemSize );
  5623. };
  5624. THREE.Uint16Attribute = function ( array, itemSize ) {
  5625. return new THREE.BufferAttribute( new Uint16Array( array ), itemSize );
  5626. };
  5627. THREE.Int32Attribute = function ( array, itemSize ) {
  5628. return new THREE.BufferAttribute( new Int32Array( array ), itemSize );
  5629. };
  5630. THREE.Uint32Attribute = function ( array, itemSize ) {
  5631. return new THREE.BufferAttribute( new Uint32Array( array ), itemSize );
  5632. };
  5633. THREE.Float32Attribute = function ( array, itemSize ) {
  5634. return new THREE.BufferAttribute( new Float32Array( array ), itemSize );
  5635. };
  5636. THREE.Float64Attribute = function ( array, itemSize ) {
  5637. return new THREE.BufferAttribute( new Float64Array( array ), itemSize );
  5638. };
  5639. // Deprecated
  5640. THREE.DynamicBufferAttribute = function ( array, itemSize ) {
  5641. console.warn( 'THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setDynamic( true ) instead.' );
  5642. return new THREE.BufferAttribute( array, itemSize ).setDynamic( true );
  5643. };
  5644. // File:src/core/InstancedBufferAttribute.js
  5645. /**
  5646. * @author benaadams / https://twitter.com/ben_a_adams
  5647. */
  5648. THREE.InstancedBufferAttribute = function ( array, itemSize, meshPerAttribute ) {
  5649. THREE.BufferAttribute.call( this, array, itemSize );
  5650. this.meshPerAttribute = meshPerAttribute || 1;
  5651. };
  5652. THREE.InstancedBufferAttribute.prototype = Object.create( THREE.BufferAttribute.prototype );
  5653. THREE.InstancedBufferAttribute.prototype.constructor = THREE.InstancedBufferAttribute;
  5654. THREE.InstancedBufferAttribute.prototype.copy = function ( source ) {
  5655. THREE.BufferAttribute.prototype.copy.call( this, source );
  5656. this.meshPerAttribute = source.meshPerAttribute;
  5657. return this;
  5658. };
  5659. // File:src/core/InterleavedBuffer.js
  5660. /**
  5661. * @author benaadams / https://twitter.com/ben_a_adams
  5662. */
  5663. THREE.InterleavedBuffer = function ( array, stride ) {
  5664. this.uuid = THREE.Math.generateUUID();
  5665. this.array = array;
  5666. this.stride = stride;
  5667. this.dynamic = false;
  5668. this.updateRange = { offset: 0, count: - 1 };
  5669. this.version = 0;
  5670. };
  5671. THREE.InterleavedBuffer.prototype = {
  5672. constructor: THREE.InterleavedBuffer,
  5673. get length () {
  5674. return this.array.length;
  5675. },
  5676. get count () {
  5677. return this.array.length / this.stride;
  5678. },
  5679. set needsUpdate( value ) {
  5680. if ( value === true ) this.version ++;
  5681. },
  5682. setDynamic: function ( value ) {
  5683. this.dynamic = value;
  5684. return this;
  5685. },
  5686. copy: function ( source ) {
  5687. this.array = new source.array.constructor( source.array );
  5688. this.stride = source.stride;
  5689. this.dynamic = source.dynamic;
  5690. return this;
  5691. },
  5692. copyAt: function ( index1, attribute, index2 ) {
  5693. index1 *= this.stride;
  5694. index2 *= attribute.stride;
  5695. for ( var i = 0, l = this.stride; i < l; i ++ ) {
  5696. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5697. }
  5698. return this;
  5699. },
  5700. set: function ( value, offset ) {
  5701. if ( offset === undefined ) offset = 0;
  5702. this.array.set( value, offset );
  5703. return this;
  5704. },
  5705. clone: function () {
  5706. return new this.constructor().copy( this );
  5707. }
  5708. };
  5709. // File:src/core/InstancedInterleavedBuffer.js
  5710. /**
  5711. * @author benaadams / https://twitter.com/ben_a_adams
  5712. */
  5713. THREE.InstancedInterleavedBuffer = function ( array, stride, meshPerAttribute ) {
  5714. THREE.InterleavedBuffer.call( this, array, stride );
  5715. this.meshPerAttribute = meshPerAttribute || 1;
  5716. };
  5717. THREE.InstancedInterleavedBuffer.prototype = Object.create( THREE.InterleavedBuffer.prototype );
  5718. THREE.InstancedInterleavedBuffer.prototype.constructor = THREE.InstancedInterleavedBuffer;
  5719. THREE.InstancedInterleavedBuffer.prototype.copy = function ( source ) {
  5720. THREE.InterleavedBuffer.prototype.copy.call( this, source );
  5721. this.meshPerAttribute = source.meshPerAttribute;
  5722. return this;
  5723. };
  5724. // File:src/core/InterleavedBufferAttribute.js
  5725. /**
  5726. * @author benaadams / https://twitter.com/ben_a_adams
  5727. */
  5728. THREE.InterleavedBufferAttribute = function ( interleavedBuffer, itemSize, offset ) {
  5729. this.uuid = THREE.Math.generateUUID();
  5730. this.data = interleavedBuffer;
  5731. this.itemSize = itemSize;
  5732. this.offset = offset;
  5733. };
  5734. THREE.InterleavedBufferAttribute.prototype = {
  5735. constructor: THREE.InterleavedBufferAttribute,
  5736. get length() {
  5737. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Please use .count.' );
  5738. return this.array.length;
  5739. },
  5740. get count() {
  5741. return this.data.count;
  5742. },
  5743. setX: function ( index, x ) {
  5744. this.data.array[ index * this.data.stride + this.offset ] = x;
  5745. return this;
  5746. },
  5747. setY: function ( index, y ) {
  5748. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  5749. return this;
  5750. },
  5751. setZ: function ( index, z ) {
  5752. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  5753. return this;
  5754. },
  5755. setW: function ( index, w ) {
  5756. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  5757. return this;
  5758. },
  5759. getX: function ( index ) {
  5760. return this.data.array[ index * this.data.stride + this.offset ];
  5761. },
  5762. getY: function ( index ) {
  5763. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  5764. },
  5765. getZ: function ( index ) {
  5766. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  5767. },
  5768. getW: function ( index ) {
  5769. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  5770. },
  5771. setXY: function ( index, x, y ) {
  5772. index = index * this.data.stride + this.offset;
  5773. this.data.array[ index + 0 ] = x;
  5774. this.data.array[ index + 1 ] = y;
  5775. return this;
  5776. },
  5777. setXYZ: function ( index, x, y, z ) {
  5778. index = index * this.data.stride + this.offset;
  5779. this.data.array[ index + 0 ] = x;
  5780. this.data.array[ index + 1 ] = y;
  5781. this.data.array[ index + 2 ] = z;
  5782. return this;
  5783. },
  5784. setXYZW: function ( index, x, y, z, w ) {
  5785. index = index * this.data.stride + this.offset;
  5786. this.data.array[ index + 0 ] = x;
  5787. this.data.array[ index + 1 ] = y;
  5788. this.data.array[ index + 2 ] = z;
  5789. this.data.array[ index + 3 ] = w;
  5790. return this;
  5791. }
  5792. };
  5793. // File:src/core/Geometry.js
  5794. /**
  5795. * @author mrdoob / http://mrdoob.com/
  5796. * @author kile / http://kile.stravaganza.org/
  5797. * @author alteredq / http://alteredqualia.com/
  5798. * @author mikael emtinger / http://gomo.se/
  5799. * @author zz85 / http://www.lab4games.net/zz85/blog
  5800. * @author bhouston / http://clara.io
  5801. */
  5802. THREE.Geometry = function () {
  5803. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  5804. this.uuid = THREE.Math.generateUUID();
  5805. this.name = '';
  5806. this.type = 'Geometry';
  5807. this.vertices = [];
  5808. this.colors = [];
  5809. this.faces = [];
  5810. this.faceVertexUvs = [ [] ];
  5811. this.morphTargets = [];
  5812. this.morphNormals = [];
  5813. this.skinWeights = [];
  5814. this.skinIndices = [];
  5815. this.lineDistances = [];
  5816. this.boundingBox = null;
  5817. this.boundingSphere = null;
  5818. // update flags
  5819. this.verticesNeedUpdate = false;
  5820. this.elementsNeedUpdate = false;
  5821. this.uvsNeedUpdate = false;
  5822. this.normalsNeedUpdate = false;
  5823. this.colorsNeedUpdate = false;
  5824. this.lineDistancesNeedUpdate = false;
  5825. this.groupsNeedUpdate = false;
  5826. };
  5827. Object.assign( THREE.Geometry.prototype, THREE.EventDispatcher.prototype, {
  5828. applyMatrix: function ( matrix ) {
  5829. var normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  5830. for ( var i = 0, il = this.vertices.length; i < il; i ++ ) {
  5831. var vertex = this.vertices[ i ];
  5832. vertex.applyMatrix4( matrix );
  5833. }
  5834. for ( var i = 0, il = this.faces.length; i < il; i ++ ) {
  5835. var face = this.faces[ i ];
  5836. face.normal.applyMatrix3( normalMatrix ).normalize();
  5837. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  5838. face.vertexNormals[ j ].applyMatrix3( normalMatrix ).normalize();
  5839. }
  5840. }
  5841. if ( this.boundingBox !== null ) {
  5842. this.computeBoundingBox();
  5843. }
  5844. if ( this.boundingSphere !== null ) {
  5845. this.computeBoundingSphere();
  5846. }
  5847. this.verticesNeedUpdate = true;
  5848. this.normalsNeedUpdate = true;
  5849. return this;
  5850. },
  5851. rotateX: function () {
  5852. // rotate geometry around world x-axis
  5853. var m1;
  5854. return function rotateX( angle ) {
  5855. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5856. m1.makeRotationX( angle );
  5857. this.applyMatrix( m1 );
  5858. return this;
  5859. };
  5860. }(),
  5861. rotateY: function () {
  5862. // rotate geometry around world y-axis
  5863. var m1;
  5864. return function rotateY( angle ) {
  5865. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5866. m1.makeRotationY( angle );
  5867. this.applyMatrix( m1 );
  5868. return this;
  5869. };
  5870. }(),
  5871. rotateZ: function () {
  5872. // rotate geometry around world z-axis
  5873. var m1;
  5874. return function rotateZ( angle ) {
  5875. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5876. m1.makeRotationZ( angle );
  5877. this.applyMatrix( m1 );
  5878. return this;
  5879. };
  5880. }(),
  5881. translate: function () {
  5882. // translate geometry
  5883. var m1;
  5884. return function translate( x, y, z ) {
  5885. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5886. m1.makeTranslation( x, y, z );
  5887. this.applyMatrix( m1 );
  5888. return this;
  5889. };
  5890. }(),
  5891. scale: function () {
  5892. // scale geometry
  5893. var m1;
  5894. return function scale( x, y, z ) {
  5895. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5896. m1.makeScale( x, y, z );
  5897. this.applyMatrix( m1 );
  5898. return this;
  5899. };
  5900. }(),
  5901. lookAt: function () {
  5902. var obj;
  5903. return function lookAt( vector ) {
  5904. if ( obj === undefined ) obj = new THREE.Object3D();
  5905. obj.lookAt( vector );
  5906. obj.updateMatrix();
  5907. this.applyMatrix( obj.matrix );
  5908. };
  5909. }(),
  5910. fromBufferGeometry: function ( geometry ) {
  5911. var scope = this;
  5912. var indices = geometry.index !== null ? geometry.index.array : undefined;
  5913. var attributes = geometry.attributes;
  5914. var positions = attributes.position.array;
  5915. var normals = attributes.normal !== undefined ? attributes.normal.array : undefined;
  5916. var colors = attributes.color !== undefined ? attributes.color.array : undefined;
  5917. var uvs = attributes.uv !== undefined ? attributes.uv.array : undefined;
  5918. var uvs2 = attributes.uv2 !== undefined ? attributes.uv2.array : undefined;
  5919. if ( uvs2 !== undefined ) this.faceVertexUvs[ 1 ] = [];
  5920. var tempNormals = [];
  5921. var tempUVs = [];
  5922. var tempUVs2 = [];
  5923. for ( var i = 0, j = 0; i < positions.length; i += 3, j += 2 ) {
  5924. scope.vertices.push( new THREE.Vector3( positions[ i ], positions[ i + 1 ], positions[ i + 2 ] ) );
  5925. if ( normals !== undefined ) {
  5926. tempNormals.push( new THREE.Vector3( normals[ i ], normals[ i + 1 ], normals[ i + 2 ] ) );
  5927. }
  5928. if ( colors !== undefined ) {
  5929. scope.colors.push( new THREE.Color( colors[ i ], colors[ i + 1 ], colors[ i + 2 ] ) );
  5930. }
  5931. if ( uvs !== undefined ) {
  5932. tempUVs.push( new THREE.Vector2( uvs[ j ], uvs[ j + 1 ] ) );
  5933. }
  5934. if ( uvs2 !== undefined ) {
  5935. tempUVs2.push( new THREE.Vector2( uvs2[ j ], uvs2[ j + 1 ] ) );
  5936. }
  5937. }
  5938. function addFace( a, b, c, materialIndex ) {
  5939. var vertexNormals = normals !== undefined ? [ tempNormals[ a ].clone(), tempNormals[ b ].clone(), tempNormals[ c ].clone() ] : [];
  5940. var vertexColors = colors !== undefined ? [ scope.colors[ a ].clone(), scope.colors[ b ].clone(), scope.colors[ c ].clone() ] : [];
  5941. var face = new THREE.Face3( a, b, c, vertexNormals, vertexColors, materialIndex );
  5942. scope.faces.push( face );
  5943. if ( uvs !== undefined ) {
  5944. scope.faceVertexUvs[ 0 ].push( [ tempUVs[ a ].clone(), tempUVs[ b ].clone(), tempUVs[ c ].clone() ] );
  5945. }
  5946. if ( uvs2 !== undefined ) {
  5947. scope.faceVertexUvs[ 1 ].push( [ tempUVs2[ a ].clone(), tempUVs2[ b ].clone(), tempUVs2[ c ].clone() ] );
  5948. }
  5949. }
  5950. if ( indices !== undefined ) {
  5951. var groups = geometry.groups;
  5952. if ( groups.length > 0 ) {
  5953. for ( var i = 0; i < groups.length; i ++ ) {
  5954. var group = groups[ i ];
  5955. var start = group.start;
  5956. var count = group.count;
  5957. for ( var j = start, jl = start + count; j < jl; j += 3 ) {
  5958. addFace( indices[ j ], indices[ j + 1 ], indices[ j + 2 ], group.materialIndex );
  5959. }
  5960. }
  5961. } else {
  5962. for ( var i = 0; i < indices.length; i += 3 ) {
  5963. addFace( indices[ i ], indices[ i + 1 ], indices[ i + 2 ] );
  5964. }
  5965. }
  5966. } else {
  5967. for ( var i = 0; i < positions.length / 3; i += 3 ) {
  5968. addFace( i, i + 1, i + 2 );
  5969. }
  5970. }
  5971. this.computeFaceNormals();
  5972. if ( geometry.boundingBox !== null ) {
  5973. this.boundingBox = geometry.boundingBox.clone();
  5974. }
  5975. if ( geometry.boundingSphere !== null ) {
  5976. this.boundingSphere = geometry.boundingSphere.clone();
  5977. }
  5978. return this;
  5979. },
  5980. center: function () {
  5981. this.computeBoundingBox();
  5982. var offset = this.boundingBox.center().negate();
  5983. this.translate( offset.x, offset.y, offset.z );
  5984. return offset;
  5985. },
  5986. normalize: function () {
  5987. this.computeBoundingSphere();
  5988. var center = this.boundingSphere.center;
  5989. var radius = this.boundingSphere.radius;
  5990. var s = radius === 0 ? 1 : 1.0 / radius;
  5991. var matrix = new THREE.Matrix4();
  5992. matrix.set(
  5993. s, 0, 0, - s * center.x,
  5994. 0, s, 0, - s * center.y,
  5995. 0, 0, s, - s * center.z,
  5996. 0, 0, 0, 1
  5997. );
  5998. this.applyMatrix( matrix );
  5999. return this;
  6000. },
  6001. computeFaceNormals: function () {
  6002. var cb = new THREE.Vector3(), ab = new THREE.Vector3();
  6003. for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6004. var face = this.faces[ f ];
  6005. var vA = this.vertices[ face.a ];
  6006. var vB = this.vertices[ face.b ];
  6007. var vC = this.vertices[ face.c ];
  6008. cb.subVectors( vC, vB );
  6009. ab.subVectors( vA, vB );
  6010. cb.cross( ab );
  6011. cb.normalize();
  6012. face.normal.copy( cb );
  6013. }
  6014. },
  6015. computeVertexNormals: function ( areaWeighted ) {
  6016. if ( areaWeighted === undefined ) areaWeighted = true;
  6017. var v, vl, f, fl, face, vertices;
  6018. vertices = new Array( this.vertices.length );
  6019. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  6020. vertices[ v ] = new THREE.Vector3();
  6021. }
  6022. if ( areaWeighted ) {
  6023. // vertex normals weighted by triangle areas
  6024. // http://www.iquilezles.org/www/articles/normals/normals.htm
  6025. var vA, vB, vC;
  6026. var cb = new THREE.Vector3(), ab = new THREE.Vector3();
  6027. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6028. face = this.faces[ f ];
  6029. vA = this.vertices[ face.a ];
  6030. vB = this.vertices[ face.b ];
  6031. vC = this.vertices[ face.c ];
  6032. cb.subVectors( vC, vB );
  6033. ab.subVectors( vA, vB );
  6034. cb.cross( ab );
  6035. vertices[ face.a ].add( cb );
  6036. vertices[ face.b ].add( cb );
  6037. vertices[ face.c ].add( cb );
  6038. }
  6039. } else {
  6040. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6041. face = this.faces[ f ];
  6042. vertices[ face.a ].add( face.normal );
  6043. vertices[ face.b ].add( face.normal );
  6044. vertices[ face.c ].add( face.normal );
  6045. }
  6046. }
  6047. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  6048. vertices[ v ].normalize();
  6049. }
  6050. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6051. face = this.faces[ f ];
  6052. var vertexNormals = face.vertexNormals;
  6053. if ( vertexNormals.length === 3 ) {
  6054. vertexNormals[ 0 ].copy( vertices[ face.a ] );
  6055. vertexNormals[ 1 ].copy( vertices[ face.b ] );
  6056. vertexNormals[ 2 ].copy( vertices[ face.c ] );
  6057. } else {
  6058. vertexNormals[ 0 ] = vertices[ face.a ].clone();
  6059. vertexNormals[ 1 ] = vertices[ face.b ].clone();
  6060. vertexNormals[ 2 ] = vertices[ face.c ].clone();
  6061. }
  6062. }
  6063. if ( this.faces.length > 0 ) {
  6064. this.normalsNeedUpdate = true;
  6065. }
  6066. },
  6067. computeMorphNormals: function () {
  6068. var i, il, f, fl, face;
  6069. // save original normals
  6070. // - create temp variables on first access
  6071. // otherwise just copy (for faster repeated calls)
  6072. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6073. face = this.faces[ f ];
  6074. if ( ! face.__originalFaceNormal ) {
  6075. face.__originalFaceNormal = face.normal.clone();
  6076. } else {
  6077. face.__originalFaceNormal.copy( face.normal );
  6078. }
  6079. if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
  6080. for ( i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
  6081. if ( ! face.__originalVertexNormals[ i ] ) {
  6082. face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
  6083. } else {
  6084. face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
  6085. }
  6086. }
  6087. }
  6088. // use temp geometry to compute face and vertex normals for each morph
  6089. var tmpGeo = new THREE.Geometry();
  6090. tmpGeo.faces = this.faces;
  6091. for ( i = 0, il = this.morphTargets.length; i < il; i ++ ) {
  6092. // create on first access
  6093. if ( ! this.morphNormals[ i ] ) {
  6094. this.morphNormals[ i ] = {};
  6095. this.morphNormals[ i ].faceNormals = [];
  6096. this.morphNormals[ i ].vertexNormals = [];
  6097. var dstNormalsFace = this.morphNormals[ i ].faceNormals;
  6098. var dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
  6099. var faceNormal, vertexNormals;
  6100. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6101. faceNormal = new THREE.Vector3();
  6102. vertexNormals = { a: new THREE.Vector3(), b: new THREE.Vector3(), c: new THREE.Vector3() };
  6103. dstNormalsFace.push( faceNormal );
  6104. dstNormalsVertex.push( vertexNormals );
  6105. }
  6106. }
  6107. var morphNormals = this.morphNormals[ i ];
  6108. // set vertices to morph target
  6109. tmpGeo.vertices = this.morphTargets[ i ].vertices;
  6110. // compute morph normals
  6111. tmpGeo.computeFaceNormals();
  6112. tmpGeo.computeVertexNormals();
  6113. // store morph normals
  6114. var faceNormal, vertexNormals;
  6115. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6116. face = this.faces[ f ];
  6117. faceNormal = morphNormals.faceNormals[ f ];
  6118. vertexNormals = morphNormals.vertexNormals[ f ];
  6119. faceNormal.copy( face.normal );
  6120. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  6121. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  6122. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  6123. }
  6124. }
  6125. // restore original normals
  6126. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6127. face = this.faces[ f ];
  6128. face.normal = face.__originalFaceNormal;
  6129. face.vertexNormals = face.__originalVertexNormals;
  6130. }
  6131. },
  6132. computeTangents: function () {
  6133. console.warn( 'THREE.Geometry: .computeTangents() has been removed.' );
  6134. },
  6135. computeLineDistances: function () {
  6136. var d = 0;
  6137. var vertices = this.vertices;
  6138. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  6139. if ( i > 0 ) {
  6140. d += vertices[ i ].distanceTo( vertices[ i - 1 ] );
  6141. }
  6142. this.lineDistances[ i ] = d;
  6143. }
  6144. },
  6145. computeBoundingBox: function () {
  6146. if ( this.boundingBox === null ) {
  6147. this.boundingBox = new THREE.Box3();
  6148. }
  6149. this.boundingBox.setFromPoints( this.vertices );
  6150. },
  6151. computeBoundingSphere: function () {
  6152. if ( this.boundingSphere === null ) {
  6153. this.boundingSphere = new THREE.Sphere();
  6154. }
  6155. this.boundingSphere.setFromPoints( this.vertices );
  6156. },
  6157. merge: function ( geometry, matrix, materialIndexOffset ) {
  6158. if ( geometry instanceof THREE.Geometry === false ) {
  6159. console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry );
  6160. return;
  6161. }
  6162. var normalMatrix,
  6163. vertexOffset = this.vertices.length,
  6164. vertices1 = this.vertices,
  6165. vertices2 = geometry.vertices,
  6166. faces1 = this.faces,
  6167. faces2 = geometry.faces,
  6168. uvs1 = this.faceVertexUvs[ 0 ],
  6169. uvs2 = geometry.faceVertexUvs[ 0 ];
  6170. if ( materialIndexOffset === undefined ) materialIndexOffset = 0;
  6171. if ( matrix !== undefined ) {
  6172. normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  6173. }
  6174. // vertices
  6175. for ( var i = 0, il = vertices2.length; i < il; i ++ ) {
  6176. var vertex = vertices2[ i ];
  6177. var vertexCopy = vertex.clone();
  6178. if ( matrix !== undefined ) vertexCopy.applyMatrix4( matrix );
  6179. vertices1.push( vertexCopy );
  6180. }
  6181. // faces
  6182. for ( i = 0, il = faces2.length; i < il; i ++ ) {
  6183. var face = faces2[ i ], faceCopy, normal, color,
  6184. faceVertexNormals = face.vertexNormals,
  6185. faceVertexColors = face.vertexColors;
  6186. faceCopy = new THREE.Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset );
  6187. faceCopy.normal.copy( face.normal );
  6188. if ( normalMatrix !== undefined ) {
  6189. faceCopy.normal.applyMatrix3( normalMatrix ).normalize();
  6190. }
  6191. for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
  6192. normal = faceVertexNormals[ j ].clone();
  6193. if ( normalMatrix !== undefined ) {
  6194. normal.applyMatrix3( normalMatrix ).normalize();
  6195. }
  6196. faceCopy.vertexNormals.push( normal );
  6197. }
  6198. faceCopy.color.copy( face.color );
  6199. for ( var j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
  6200. color = faceVertexColors[ j ];
  6201. faceCopy.vertexColors.push( color.clone() );
  6202. }
  6203. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  6204. faces1.push( faceCopy );
  6205. }
  6206. // uvs
  6207. for ( i = 0, il = uvs2.length; i < il; i ++ ) {
  6208. var uv = uvs2[ i ], uvCopy = [];
  6209. if ( uv === undefined ) {
  6210. continue;
  6211. }
  6212. for ( var j = 0, jl = uv.length; j < jl; j ++ ) {
  6213. uvCopy.push( uv[ j ].clone() );
  6214. }
  6215. uvs1.push( uvCopy );
  6216. }
  6217. },
  6218. mergeMesh: function ( mesh ) {
  6219. if ( mesh instanceof THREE.Mesh === false ) {
  6220. console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh );
  6221. return;
  6222. }
  6223. mesh.matrixAutoUpdate && mesh.updateMatrix();
  6224. this.merge( mesh.geometry, mesh.matrix );
  6225. },
  6226. /*
  6227. * Checks for duplicate vertices with hashmap.
  6228. * Duplicated vertices are removed
  6229. * and faces' vertices are updated.
  6230. */
  6231. mergeVertices: function () {
  6232. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  6233. var unique = [], changes = [];
  6234. var v, key;
  6235. var precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001
  6236. var precision = Math.pow( 10, precisionPoints );
  6237. var i, il, face;
  6238. var indices, j, jl;
  6239. for ( i = 0, il = this.vertices.length; i < il; i ++ ) {
  6240. v = this.vertices[ i ];
  6241. key = Math.round( v.x * precision ) + '_' + Math.round( v.y * precision ) + '_' + Math.round( v.z * precision );
  6242. if ( verticesMap[ key ] === undefined ) {
  6243. verticesMap[ key ] = i;
  6244. unique.push( this.vertices[ i ] );
  6245. changes[ i ] = unique.length - 1;
  6246. } else {
  6247. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  6248. changes[ i ] = changes[ verticesMap[ key ] ];
  6249. }
  6250. }
  6251. // if faces are completely degenerate after merging vertices, we
  6252. // have to remove them from the geometry.
  6253. var faceIndicesToRemove = [];
  6254. for ( i = 0, il = this.faces.length; i < il; i ++ ) {
  6255. face = this.faces[ i ];
  6256. face.a = changes[ face.a ];
  6257. face.b = changes[ face.b ];
  6258. face.c = changes[ face.c ];
  6259. indices = [ face.a, face.b, face.c ];
  6260. var dupIndex = - 1;
  6261. // if any duplicate vertices are found in a Face3
  6262. // we have to remove the face as nothing can be saved
  6263. for ( var n = 0; n < 3; n ++ ) {
  6264. if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) {
  6265. dupIndex = n;
  6266. faceIndicesToRemove.push( i );
  6267. break;
  6268. }
  6269. }
  6270. }
  6271. for ( i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
  6272. var idx = faceIndicesToRemove[ i ];
  6273. this.faces.splice( idx, 1 );
  6274. for ( j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {
  6275. this.faceVertexUvs[ j ].splice( idx, 1 );
  6276. }
  6277. }
  6278. // Use unique set of vertices
  6279. var diff = this.vertices.length - unique.length;
  6280. this.vertices = unique;
  6281. return diff;
  6282. },
  6283. sortFacesByMaterialIndex: function () {
  6284. var faces = this.faces;
  6285. var length = faces.length;
  6286. // tag faces
  6287. for ( var i = 0; i < length; i ++ ) {
  6288. faces[ i ]._id = i;
  6289. }
  6290. // sort faces
  6291. function materialIndexSort( a, b ) {
  6292. return a.materialIndex - b.materialIndex;
  6293. }
  6294. faces.sort( materialIndexSort );
  6295. // sort uvs
  6296. var uvs1 = this.faceVertexUvs[ 0 ];
  6297. var uvs2 = this.faceVertexUvs[ 1 ];
  6298. var newUvs1, newUvs2;
  6299. if ( uvs1 && uvs1.length === length ) newUvs1 = [];
  6300. if ( uvs2 && uvs2.length === length ) newUvs2 = [];
  6301. for ( var i = 0; i < length; i ++ ) {
  6302. var id = faces[ i ]._id;
  6303. if ( newUvs1 ) newUvs1.push( uvs1[ id ] );
  6304. if ( newUvs2 ) newUvs2.push( uvs2[ id ] );
  6305. }
  6306. if ( newUvs1 ) this.faceVertexUvs[ 0 ] = newUvs1;
  6307. if ( newUvs2 ) this.faceVertexUvs[ 1 ] = newUvs2;
  6308. },
  6309. toJSON: function () {
  6310. var data = {
  6311. metadata: {
  6312. version: 4.4,
  6313. type: 'Geometry',
  6314. generator: 'Geometry.toJSON'
  6315. }
  6316. };
  6317. // standard Geometry serialization
  6318. data.uuid = this.uuid;
  6319. data.type = this.type;
  6320. if ( this.name !== '' ) data.name = this.name;
  6321. if ( this.parameters !== undefined ) {
  6322. var parameters = this.parameters;
  6323. for ( var key in parameters ) {
  6324. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  6325. }
  6326. return data;
  6327. }
  6328. var vertices = [];
  6329. for ( var i = 0; i < this.vertices.length; i ++ ) {
  6330. var vertex = this.vertices[ i ];
  6331. vertices.push( vertex.x, vertex.y, vertex.z );
  6332. }
  6333. var faces = [];
  6334. var normals = [];
  6335. var normalsHash = {};
  6336. var colors = [];
  6337. var colorsHash = {};
  6338. var uvs = [];
  6339. var uvsHash = {};
  6340. for ( var i = 0; i < this.faces.length; i ++ ) {
  6341. var face = this.faces[ i ];
  6342. var hasMaterial = true;
  6343. var hasFaceUv = false; // deprecated
  6344. var hasFaceVertexUv = this.faceVertexUvs[ 0 ][ i ] !== undefined;
  6345. var hasFaceNormal = face.normal.length() > 0;
  6346. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  6347. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  6348. var hasFaceVertexColor = face.vertexColors.length > 0;
  6349. var faceType = 0;
  6350. faceType = setBit( faceType, 0, 0 ); // isQuad
  6351. faceType = setBit( faceType, 1, hasMaterial );
  6352. faceType = setBit( faceType, 2, hasFaceUv );
  6353. faceType = setBit( faceType, 3, hasFaceVertexUv );
  6354. faceType = setBit( faceType, 4, hasFaceNormal );
  6355. faceType = setBit( faceType, 5, hasFaceVertexNormal );
  6356. faceType = setBit( faceType, 6, hasFaceColor );
  6357. faceType = setBit( faceType, 7, hasFaceVertexColor );
  6358. faces.push( faceType );
  6359. faces.push( face.a, face.b, face.c );
  6360. faces.push( face.materialIndex );
  6361. if ( hasFaceVertexUv ) {
  6362. var faceVertexUvs = this.faceVertexUvs[ 0 ][ i ];
  6363. faces.push(
  6364. getUvIndex( faceVertexUvs[ 0 ] ),
  6365. getUvIndex( faceVertexUvs[ 1 ] ),
  6366. getUvIndex( faceVertexUvs[ 2 ] )
  6367. );
  6368. }
  6369. if ( hasFaceNormal ) {
  6370. faces.push( getNormalIndex( face.normal ) );
  6371. }
  6372. if ( hasFaceVertexNormal ) {
  6373. var vertexNormals = face.vertexNormals;
  6374. faces.push(
  6375. getNormalIndex( vertexNormals[ 0 ] ),
  6376. getNormalIndex( vertexNormals[ 1 ] ),
  6377. getNormalIndex( vertexNormals[ 2 ] )
  6378. );
  6379. }
  6380. if ( hasFaceColor ) {
  6381. faces.push( getColorIndex( face.color ) );
  6382. }
  6383. if ( hasFaceVertexColor ) {
  6384. var vertexColors = face.vertexColors;
  6385. faces.push(
  6386. getColorIndex( vertexColors[ 0 ] ),
  6387. getColorIndex( vertexColors[ 1 ] ),
  6388. getColorIndex( vertexColors[ 2 ] )
  6389. );
  6390. }
  6391. }
  6392. function setBit( value, position, enabled ) {
  6393. return enabled ? value | ( 1 << position ) : value & ( ~ ( 1 << position ) );
  6394. }
  6395. function getNormalIndex( normal ) {
  6396. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  6397. if ( normalsHash[ hash ] !== undefined ) {
  6398. return normalsHash[ hash ];
  6399. }
  6400. normalsHash[ hash ] = normals.length / 3;
  6401. normals.push( normal.x, normal.y, normal.z );
  6402. return normalsHash[ hash ];
  6403. }
  6404. function getColorIndex( color ) {
  6405. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  6406. if ( colorsHash[ hash ] !== undefined ) {
  6407. return colorsHash[ hash ];
  6408. }
  6409. colorsHash[ hash ] = colors.length;
  6410. colors.push( color.getHex() );
  6411. return colorsHash[ hash ];
  6412. }
  6413. function getUvIndex( uv ) {
  6414. var hash = uv.x.toString() + uv.y.toString();
  6415. if ( uvsHash[ hash ] !== undefined ) {
  6416. return uvsHash[ hash ];
  6417. }
  6418. uvsHash[ hash ] = uvs.length / 2;
  6419. uvs.push( uv.x, uv.y );
  6420. return uvsHash[ hash ];
  6421. }
  6422. data.data = {};
  6423. data.data.vertices = vertices;
  6424. data.data.normals = normals;
  6425. if ( colors.length > 0 ) data.data.colors = colors;
  6426. if ( uvs.length > 0 ) data.data.uvs = [ uvs ]; // temporal backward compatibility
  6427. data.data.faces = faces;
  6428. return data;
  6429. },
  6430. clone: function () {
  6431. /*
  6432. // Handle primitives
  6433. var parameters = this.parameters;
  6434. if ( parameters !== undefined ) {
  6435. var values = [];
  6436. for ( var key in parameters ) {
  6437. values.push( parameters[ key ] );
  6438. }
  6439. var geometry = Object.create( this.constructor.prototype );
  6440. this.constructor.apply( geometry, values );
  6441. return geometry;
  6442. }
  6443. return new this.constructor().copy( this );
  6444. */
  6445. return new THREE.Geometry().copy( this );
  6446. },
  6447. copy: function ( source ) {
  6448. this.vertices = [];
  6449. this.faces = [];
  6450. this.faceVertexUvs = [ [] ];
  6451. var vertices = source.vertices;
  6452. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  6453. this.vertices.push( vertices[ i ].clone() );
  6454. }
  6455. var faces = source.faces;
  6456. for ( var i = 0, il = faces.length; i < il; i ++ ) {
  6457. this.faces.push( faces[ i ].clone() );
  6458. }
  6459. for ( var i = 0, il = source.faceVertexUvs.length; i < il; i ++ ) {
  6460. var faceVertexUvs = source.faceVertexUvs[ i ];
  6461. if ( this.faceVertexUvs[ i ] === undefined ) {
  6462. this.faceVertexUvs[ i ] = [];
  6463. }
  6464. for ( var j = 0, jl = faceVertexUvs.length; j < jl; j ++ ) {
  6465. var uvs = faceVertexUvs[ j ], uvsCopy = [];
  6466. for ( var k = 0, kl = uvs.length; k < kl; k ++ ) {
  6467. var uv = uvs[ k ];
  6468. uvsCopy.push( uv.clone() );
  6469. }
  6470. this.faceVertexUvs[ i ].push( uvsCopy );
  6471. }
  6472. }
  6473. return this;
  6474. },
  6475. dispose: function () {
  6476. this.dispatchEvent( { type: 'dispose' } );
  6477. }
  6478. } );
  6479. THREE.GeometryIdCount = 0;
  6480. // File:src/core/DirectGeometry.js
  6481. /**
  6482. * @author mrdoob / http://mrdoob.com/
  6483. */
  6484. THREE.DirectGeometry = function () {
  6485. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  6486. this.uuid = THREE.Math.generateUUID();
  6487. this.name = '';
  6488. this.type = 'DirectGeometry';
  6489. this.indices = [];
  6490. this.vertices = [];
  6491. this.normals = [];
  6492. this.colors = [];
  6493. this.uvs = [];
  6494. this.uvs2 = [];
  6495. this.groups = [];
  6496. this.morphTargets = {};
  6497. this.skinWeights = [];
  6498. this.skinIndices = [];
  6499. // this.lineDistances = [];
  6500. this.boundingBox = null;
  6501. this.boundingSphere = null;
  6502. // update flags
  6503. this.verticesNeedUpdate = false;
  6504. this.normalsNeedUpdate = false;
  6505. this.colorsNeedUpdate = false;
  6506. this.uvsNeedUpdate = false;
  6507. this.groupsNeedUpdate = false;
  6508. };
  6509. Object.assign( THREE.DirectGeometry.prototype, THREE.EventDispatcher.prototype, {
  6510. computeBoundingBox: THREE.Geometry.prototype.computeBoundingBox,
  6511. computeBoundingSphere: THREE.Geometry.prototype.computeBoundingSphere,
  6512. computeFaceNormals: function () {
  6513. console.warn( 'THREE.DirectGeometry: computeFaceNormals() is not a method of this type of geometry.' );
  6514. },
  6515. computeVertexNormals: function () {
  6516. console.warn( 'THREE.DirectGeometry: computeVertexNormals() is not a method of this type of geometry.' );
  6517. },
  6518. computeGroups: function ( geometry ) {
  6519. var group;
  6520. var groups = [];
  6521. var materialIndex;
  6522. var faces = geometry.faces;
  6523. for ( var i = 0; i < faces.length; i ++ ) {
  6524. var face = faces[ i ];
  6525. // materials
  6526. if ( face.materialIndex !== materialIndex ) {
  6527. materialIndex = face.materialIndex;
  6528. if ( group !== undefined ) {
  6529. group.count = ( i * 3 ) - group.start;
  6530. groups.push( group );
  6531. }
  6532. group = {
  6533. start: i * 3,
  6534. materialIndex: materialIndex
  6535. };
  6536. }
  6537. }
  6538. if ( group !== undefined ) {
  6539. group.count = ( i * 3 ) - group.start;
  6540. groups.push( group );
  6541. }
  6542. this.groups = groups;
  6543. },
  6544. fromGeometry: function ( geometry ) {
  6545. var faces = geometry.faces;
  6546. var vertices = geometry.vertices;
  6547. var faceVertexUvs = geometry.faceVertexUvs;
  6548. var hasFaceVertexUv = faceVertexUvs[ 0 ] && faceVertexUvs[ 0 ].length > 0;
  6549. var hasFaceVertexUv2 = faceVertexUvs[ 1 ] && faceVertexUvs[ 1 ].length > 0;
  6550. // morphs
  6551. var morphTargets = geometry.morphTargets;
  6552. var morphTargetsLength = morphTargets.length;
  6553. var morphTargetsPosition;
  6554. if ( morphTargetsLength > 0 ) {
  6555. morphTargetsPosition = [];
  6556. for ( var i = 0; i < morphTargetsLength; i ++ ) {
  6557. morphTargetsPosition[ i ] = [];
  6558. }
  6559. this.morphTargets.position = morphTargetsPosition;
  6560. }
  6561. var morphNormals = geometry.morphNormals;
  6562. var morphNormalsLength = morphNormals.length;
  6563. var morphTargetsNormal;
  6564. if ( morphNormalsLength > 0 ) {
  6565. morphTargetsNormal = [];
  6566. for ( var i = 0; i < morphNormalsLength; i ++ ) {
  6567. morphTargetsNormal[ i ] = [];
  6568. }
  6569. this.morphTargets.normal = morphTargetsNormal;
  6570. }
  6571. // skins
  6572. var skinIndices = geometry.skinIndices;
  6573. var skinWeights = geometry.skinWeights;
  6574. var hasSkinIndices = skinIndices.length === vertices.length;
  6575. var hasSkinWeights = skinWeights.length === vertices.length;
  6576. //
  6577. for ( var i = 0; i < faces.length; i ++ ) {
  6578. var face = faces[ i ];
  6579. this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] );
  6580. var vertexNormals = face.vertexNormals;
  6581. if ( vertexNormals.length === 3 ) {
  6582. this.normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
  6583. } else {
  6584. var normal = face.normal;
  6585. this.normals.push( normal, normal, normal );
  6586. }
  6587. var vertexColors = face.vertexColors;
  6588. if ( vertexColors.length === 3 ) {
  6589. this.colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
  6590. } else {
  6591. var color = face.color;
  6592. this.colors.push( color, color, color );
  6593. }
  6594. if ( hasFaceVertexUv === true ) {
  6595. var vertexUvs = faceVertexUvs[ 0 ][ i ];
  6596. if ( vertexUvs !== undefined ) {
  6597. this.uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6598. } else {
  6599. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', i );
  6600. this.uvs.push( new THREE.Vector2(), new THREE.Vector2(), new THREE.Vector2() );
  6601. }
  6602. }
  6603. if ( hasFaceVertexUv2 === true ) {
  6604. var vertexUvs = faceVertexUvs[ 1 ][ i ];
  6605. if ( vertexUvs !== undefined ) {
  6606. this.uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6607. } else {
  6608. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', i );
  6609. this.uvs2.push( new THREE.Vector2(), new THREE.Vector2(), new THREE.Vector2() );
  6610. }
  6611. }
  6612. // morphs
  6613. for ( var j = 0; j < morphTargetsLength; j ++ ) {
  6614. var morphTarget = morphTargets[ j ].vertices;
  6615. morphTargetsPosition[ j ].push( morphTarget[ face.a ], morphTarget[ face.b ], morphTarget[ face.c ] );
  6616. }
  6617. for ( var j = 0; j < morphNormalsLength; j ++ ) {
  6618. var morphNormal = morphNormals[ j ].vertexNormals[ i ];
  6619. morphTargetsNormal[ j ].push( morphNormal.a, morphNormal.b, morphNormal.c );
  6620. }
  6621. // skins
  6622. if ( hasSkinIndices ) {
  6623. this.skinIndices.push( skinIndices[ face.a ], skinIndices[ face.b ], skinIndices[ face.c ] );
  6624. }
  6625. if ( hasSkinWeights ) {
  6626. this.skinWeights.push( skinWeights[ face.a ], skinWeights[ face.b ], skinWeights[ face.c ] );
  6627. }
  6628. }
  6629. this.computeGroups( geometry );
  6630. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6631. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6632. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6633. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6634. this.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6635. return this;
  6636. },
  6637. dispose: function () {
  6638. this.dispatchEvent( { type: 'dispose' } );
  6639. }
  6640. } );
  6641. // File:src/core/BufferGeometry.js
  6642. /**
  6643. * @author alteredq / http://alteredqualia.com/
  6644. * @author mrdoob / http://mrdoob.com/
  6645. */
  6646. THREE.BufferGeometry = function () {
  6647. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  6648. this.uuid = THREE.Math.generateUUID();
  6649. this.name = '';
  6650. this.type = 'BufferGeometry';
  6651. this.index = null;
  6652. this.attributes = {};
  6653. this.morphAttributes = {};
  6654. this.groups = [];
  6655. this.boundingBox = null;
  6656. this.boundingSphere = null;
  6657. this.drawRange = { start: 0, count: Infinity };
  6658. };
  6659. Object.assign( THREE.BufferGeometry.prototype, THREE.EventDispatcher.prototype, {
  6660. getIndex: function () {
  6661. return this.index;
  6662. },
  6663. setIndex: function ( index ) {
  6664. this.index = index;
  6665. },
  6666. addAttribute: function ( name, attribute ) {
  6667. if ( attribute instanceof THREE.BufferAttribute === false && attribute instanceof THREE.InterleavedBufferAttribute === false ) {
  6668. console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
  6669. this.addAttribute( name, new THREE.BufferAttribute( arguments[ 1 ], arguments[ 2 ] ) );
  6670. return;
  6671. }
  6672. if ( name === 'index' ) {
  6673. console.warn( 'THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.' );
  6674. this.setIndex( attribute );
  6675. return;
  6676. }
  6677. this.attributes[ name ] = attribute;
  6678. return this;
  6679. },
  6680. getAttribute: function ( name ) {
  6681. return this.attributes[ name ];
  6682. },
  6683. removeAttribute: function ( name ) {
  6684. delete this.attributes[ name ];
  6685. return this;
  6686. },
  6687. addGroup: function ( start, count, materialIndex ) {
  6688. this.groups.push( {
  6689. start: start,
  6690. count: count,
  6691. materialIndex: materialIndex !== undefined ? materialIndex : 0
  6692. } );
  6693. },
  6694. clearGroups: function () {
  6695. this.groups = [];
  6696. },
  6697. setDrawRange: function ( start, count ) {
  6698. this.drawRange.start = start;
  6699. this.drawRange.count = count;
  6700. },
  6701. applyMatrix: function ( matrix ) {
  6702. var position = this.attributes.position;
  6703. if ( position !== undefined ) {
  6704. matrix.applyToVector3Array( position.array );
  6705. position.needsUpdate = true;
  6706. }
  6707. var normal = this.attributes.normal;
  6708. if ( normal !== undefined ) {
  6709. var normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  6710. normalMatrix.applyToVector3Array( normal.array );
  6711. normal.needsUpdate = true;
  6712. }
  6713. if ( this.boundingBox !== null ) {
  6714. this.computeBoundingBox();
  6715. }
  6716. if ( this.boundingSphere !== null ) {
  6717. this.computeBoundingSphere();
  6718. }
  6719. return this;
  6720. },
  6721. rotateX: function () {
  6722. // rotate geometry around world x-axis
  6723. var m1;
  6724. return function rotateX( angle ) {
  6725. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6726. m1.makeRotationX( angle );
  6727. this.applyMatrix( m1 );
  6728. return this;
  6729. };
  6730. }(),
  6731. rotateY: function () {
  6732. // rotate geometry around world y-axis
  6733. var m1;
  6734. return function rotateY( angle ) {
  6735. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6736. m1.makeRotationY( angle );
  6737. this.applyMatrix( m1 );
  6738. return this;
  6739. };
  6740. }(),
  6741. rotateZ: function () {
  6742. // rotate geometry around world z-axis
  6743. var m1;
  6744. return function rotateZ( angle ) {
  6745. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6746. m1.makeRotationZ( angle );
  6747. this.applyMatrix( m1 );
  6748. return this;
  6749. };
  6750. }(),
  6751. translate: function () {
  6752. // translate geometry
  6753. var m1;
  6754. return function translate( x, y, z ) {
  6755. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6756. m1.makeTranslation( x, y, z );
  6757. this.applyMatrix( m1 );
  6758. return this;
  6759. };
  6760. }(),
  6761. scale: function () {
  6762. // scale geometry
  6763. var m1;
  6764. return function scale( x, y, z ) {
  6765. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6766. m1.makeScale( x, y, z );
  6767. this.applyMatrix( m1 );
  6768. return this;
  6769. };
  6770. }(),
  6771. lookAt: function () {
  6772. var obj;
  6773. return function lookAt( vector ) {
  6774. if ( obj === undefined ) obj = new THREE.Object3D();
  6775. obj.lookAt( vector );
  6776. obj.updateMatrix();
  6777. this.applyMatrix( obj.matrix );
  6778. };
  6779. }(),
  6780. center: function () {
  6781. this.computeBoundingBox();
  6782. var offset = this.boundingBox.center().negate();
  6783. this.translate( offset.x, offset.y, offset.z );
  6784. return offset;
  6785. },
  6786. setFromObject: function ( object ) {
  6787. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  6788. var geometry = object.geometry;
  6789. if ( object instanceof THREE.Points || object instanceof THREE.Line ) {
  6790. var positions = new THREE.Float32Attribute( geometry.vertices.length * 3, 3 );
  6791. var colors = new THREE.Float32Attribute( geometry.colors.length * 3, 3 );
  6792. this.addAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) );
  6793. this.addAttribute( 'color', colors.copyColorsArray( geometry.colors ) );
  6794. if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) {
  6795. var lineDistances = new THREE.Float32Attribute( geometry.lineDistances.length, 1 );
  6796. this.addAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) );
  6797. }
  6798. if ( geometry.boundingSphere !== null ) {
  6799. this.boundingSphere = geometry.boundingSphere.clone();
  6800. }
  6801. if ( geometry.boundingBox !== null ) {
  6802. this.boundingBox = geometry.boundingBox.clone();
  6803. }
  6804. } else if ( object instanceof THREE.Mesh ) {
  6805. if ( geometry instanceof THREE.Geometry ) {
  6806. this.fromGeometry( geometry );
  6807. }
  6808. }
  6809. return this;
  6810. },
  6811. updateFromObject: function ( object ) {
  6812. var geometry = object.geometry;
  6813. if ( object instanceof THREE.Mesh ) {
  6814. var direct = geometry.__directGeometry;
  6815. if ( direct === undefined ) {
  6816. return this.fromGeometry( geometry );
  6817. }
  6818. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6819. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6820. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6821. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6822. direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6823. geometry.verticesNeedUpdate = false;
  6824. geometry.normalsNeedUpdate = false;
  6825. geometry.colorsNeedUpdate = false;
  6826. geometry.uvsNeedUpdate = false;
  6827. geometry.groupsNeedUpdate = false;
  6828. geometry = direct;
  6829. }
  6830. if ( geometry.verticesNeedUpdate === true ) {
  6831. var attribute = this.attributes.position;
  6832. if ( attribute !== undefined ) {
  6833. attribute.copyVector3sArray( geometry.vertices );
  6834. attribute.needsUpdate = true;
  6835. }
  6836. geometry.verticesNeedUpdate = false;
  6837. }
  6838. if ( geometry.normalsNeedUpdate === true ) {
  6839. var attribute = this.attributes.normal;
  6840. if ( attribute !== undefined ) {
  6841. attribute.copyVector3sArray( geometry.normals );
  6842. attribute.needsUpdate = true;
  6843. }
  6844. geometry.normalsNeedUpdate = false;
  6845. }
  6846. if ( geometry.colorsNeedUpdate === true ) {
  6847. var attribute = this.attributes.color;
  6848. if ( attribute !== undefined ) {
  6849. attribute.copyColorsArray( geometry.colors );
  6850. attribute.needsUpdate = true;
  6851. }
  6852. geometry.colorsNeedUpdate = false;
  6853. }
  6854. if ( geometry.uvsNeedUpdate ) {
  6855. var attribute = this.attributes.uv;
  6856. if ( attribute !== undefined ) {
  6857. attribute.copyVector2sArray( geometry.uvs );
  6858. attribute.needsUpdate = true;
  6859. }
  6860. geometry.uvsNeedUpdate = false;
  6861. }
  6862. if ( geometry.lineDistancesNeedUpdate ) {
  6863. var attribute = this.attributes.lineDistance;
  6864. if ( attribute !== undefined ) {
  6865. attribute.copyArray( geometry.lineDistances );
  6866. attribute.needsUpdate = true;
  6867. }
  6868. geometry.lineDistancesNeedUpdate = false;
  6869. }
  6870. if ( geometry.groupsNeedUpdate ) {
  6871. geometry.computeGroups( object.geometry );
  6872. this.groups = geometry.groups;
  6873. geometry.groupsNeedUpdate = false;
  6874. }
  6875. return this;
  6876. },
  6877. fromGeometry: function ( geometry ) {
  6878. geometry.__directGeometry = new THREE.DirectGeometry().fromGeometry( geometry );
  6879. return this.fromDirectGeometry( geometry.__directGeometry );
  6880. },
  6881. fromDirectGeometry: function ( geometry ) {
  6882. var positions = new Float32Array( geometry.vertices.length * 3 );
  6883. this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) );
  6884. if ( geometry.normals.length > 0 ) {
  6885. var normals = new Float32Array( geometry.normals.length * 3 );
  6886. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) );
  6887. }
  6888. if ( geometry.colors.length > 0 ) {
  6889. var colors = new Float32Array( geometry.colors.length * 3 );
  6890. this.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors ) );
  6891. }
  6892. if ( geometry.uvs.length > 0 ) {
  6893. var uvs = new Float32Array( geometry.uvs.length * 2 );
  6894. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs ) );
  6895. }
  6896. if ( geometry.uvs2.length > 0 ) {
  6897. var uvs2 = new Float32Array( geometry.uvs2.length * 2 );
  6898. this.addAttribute( 'uv2', new THREE.BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 ) );
  6899. }
  6900. if ( geometry.indices.length > 0 ) {
  6901. var TypeArray = geometry.vertices.length > 65535 ? Uint32Array : Uint16Array;
  6902. var indices = new TypeArray( geometry.indices.length * 3 );
  6903. this.setIndex( new THREE.BufferAttribute( indices, 1 ).copyIndicesArray( geometry.indices ) );
  6904. }
  6905. // groups
  6906. this.groups = geometry.groups;
  6907. // morphs
  6908. for ( var name in geometry.morphTargets ) {
  6909. var array = [];
  6910. var morphTargets = geometry.morphTargets[ name ];
  6911. for ( var i = 0, l = morphTargets.length; i < l; i ++ ) {
  6912. var morphTarget = morphTargets[ i ];
  6913. var attribute = new THREE.Float32Attribute( morphTarget.length * 3, 3 );
  6914. array.push( attribute.copyVector3sArray( morphTarget ) );
  6915. }
  6916. this.morphAttributes[ name ] = array;
  6917. }
  6918. // skinning
  6919. if ( geometry.skinIndices.length > 0 ) {
  6920. var skinIndices = new THREE.Float32Attribute( geometry.skinIndices.length * 4, 4 );
  6921. this.addAttribute( 'skinIndex', skinIndices.copyVector4sArray( geometry.skinIndices ) );
  6922. }
  6923. if ( geometry.skinWeights.length > 0 ) {
  6924. var skinWeights = new THREE.Float32Attribute( geometry.skinWeights.length * 4, 4 );
  6925. this.addAttribute( 'skinWeight', skinWeights.copyVector4sArray( geometry.skinWeights ) );
  6926. }
  6927. //
  6928. if ( geometry.boundingSphere !== null ) {
  6929. this.boundingSphere = geometry.boundingSphere.clone();
  6930. }
  6931. if ( geometry.boundingBox !== null ) {
  6932. this.boundingBox = geometry.boundingBox.clone();
  6933. }
  6934. return this;
  6935. },
  6936. computeBoundingBox: function () {
  6937. if ( this.boundingBox === null ) {
  6938. this.boundingBox = new THREE.Box3();
  6939. }
  6940. var positions = this.attributes.position.array;
  6941. if ( positions !== undefined ) {
  6942. this.boundingBox.setFromArray( positions );
  6943. } else {
  6944. this.boundingBox.makeEmpty();
  6945. }
  6946. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  6947. console.error( 'THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  6948. }
  6949. },
  6950. computeBoundingSphere: function () {
  6951. var box = new THREE.Box3();
  6952. var vector = new THREE.Vector3();
  6953. return function computeBoundingSphere() {
  6954. if ( this.boundingSphere === null ) {
  6955. this.boundingSphere = new THREE.Sphere();
  6956. }
  6957. var positions = this.attributes.position.array;
  6958. if ( positions ) {
  6959. var center = this.boundingSphere.center;
  6960. box.setFromArray( positions );
  6961. box.center( center );
  6962. // hoping to find a boundingSphere with a radius smaller than the
  6963. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  6964. var maxRadiusSq = 0;
  6965. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  6966. vector.fromArray( positions, i );
  6967. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
  6968. }
  6969. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  6970. if ( isNaN( this.boundingSphere.radius ) ) {
  6971. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  6972. }
  6973. }
  6974. };
  6975. }(),
  6976. computeFaceNormals: function () {
  6977. // backwards compatibility
  6978. },
  6979. computeVertexNormals: function () {
  6980. var index = this.index;
  6981. var attributes = this.attributes;
  6982. var groups = this.groups;
  6983. if ( attributes.position ) {
  6984. var positions = attributes.position.array;
  6985. if ( attributes.normal === undefined ) {
  6986. this.addAttribute( 'normal', new THREE.BufferAttribute( new Float32Array( positions.length ), 3 ) );
  6987. } else {
  6988. // reset existing normals to zero
  6989. var array = attributes.normal.array;
  6990. for ( var i = 0, il = array.length; i < il; i ++ ) {
  6991. array[ i ] = 0;
  6992. }
  6993. }
  6994. var normals = attributes.normal.array;
  6995. var vA, vB, vC,
  6996. pA = new THREE.Vector3(),
  6997. pB = new THREE.Vector3(),
  6998. pC = new THREE.Vector3(),
  6999. cb = new THREE.Vector3(),
  7000. ab = new THREE.Vector3();
  7001. // indexed elements
  7002. if ( index ) {
  7003. var indices = index.array;
  7004. if ( groups.length === 0 ) {
  7005. this.addGroup( 0, indices.length );
  7006. }
  7007. for ( var j = 0, jl = groups.length; j < jl; ++ j ) {
  7008. var group = groups[ j ];
  7009. var start = group.start;
  7010. var count = group.count;
  7011. for ( var i = start, il = start + count; i < il; i += 3 ) {
  7012. vA = indices[ i + 0 ] * 3;
  7013. vB = indices[ i + 1 ] * 3;
  7014. vC = indices[ i + 2 ] * 3;
  7015. pA.fromArray( positions, vA );
  7016. pB.fromArray( positions, vB );
  7017. pC.fromArray( positions, vC );
  7018. cb.subVectors( pC, pB );
  7019. ab.subVectors( pA, pB );
  7020. cb.cross( ab );
  7021. normals[ vA ] += cb.x;
  7022. normals[ vA + 1 ] += cb.y;
  7023. normals[ vA + 2 ] += cb.z;
  7024. normals[ vB ] += cb.x;
  7025. normals[ vB + 1 ] += cb.y;
  7026. normals[ vB + 2 ] += cb.z;
  7027. normals[ vC ] += cb.x;
  7028. normals[ vC + 1 ] += cb.y;
  7029. normals[ vC + 2 ] += cb.z;
  7030. }
  7031. }
  7032. } else {
  7033. // non-indexed elements (unconnected triangle soup)
  7034. for ( var i = 0, il = positions.length; i < il; i += 9 ) {
  7035. pA.fromArray( positions, i );
  7036. pB.fromArray( positions, i + 3 );
  7037. pC.fromArray( positions, i + 6 );
  7038. cb.subVectors( pC, pB );
  7039. ab.subVectors( pA, pB );
  7040. cb.cross( ab );
  7041. normals[ i ] = cb.x;
  7042. normals[ i + 1 ] = cb.y;
  7043. normals[ i + 2 ] = cb.z;
  7044. normals[ i + 3 ] = cb.x;
  7045. normals[ i + 4 ] = cb.y;
  7046. normals[ i + 5 ] = cb.z;
  7047. normals[ i + 6 ] = cb.x;
  7048. normals[ i + 7 ] = cb.y;
  7049. normals[ i + 8 ] = cb.z;
  7050. }
  7051. }
  7052. this.normalizeNormals();
  7053. attributes.normal.needsUpdate = true;
  7054. }
  7055. },
  7056. merge: function ( geometry, offset ) {
  7057. if ( geometry instanceof THREE.BufferGeometry === false ) {
  7058. console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
  7059. return;
  7060. }
  7061. if ( offset === undefined ) offset = 0;
  7062. var attributes = this.attributes;
  7063. for ( var key in attributes ) {
  7064. if ( geometry.attributes[ key ] === undefined ) continue;
  7065. var attribute1 = attributes[ key ];
  7066. var attributeArray1 = attribute1.array;
  7067. var attribute2 = geometry.attributes[ key ];
  7068. var attributeArray2 = attribute2.array;
  7069. var attributeSize = attribute2.itemSize;
  7070. for ( var i = 0, j = attributeSize * offset; i < attributeArray2.length; i ++, j ++ ) {
  7071. attributeArray1[ j ] = attributeArray2[ i ];
  7072. }
  7073. }
  7074. return this;
  7075. },
  7076. normalizeNormals: function () {
  7077. var normals = this.attributes.normal.array;
  7078. var x, y, z, n;
  7079. for ( var i = 0, il = normals.length; i < il; i += 3 ) {
  7080. x = normals[ i ];
  7081. y = normals[ i + 1 ];
  7082. z = normals[ i + 2 ];
  7083. n = 1.0 / Math.sqrt( x * x + y * y + z * z );
  7084. normals[ i ] *= n;
  7085. normals[ i + 1 ] *= n;
  7086. normals[ i + 2 ] *= n;
  7087. }
  7088. },
  7089. toNonIndexed: function () {
  7090. if ( this.index === null ) {
  7091. console.warn( 'THREE.BufferGeometry.toNonIndexed(): Geometry is already non-indexed.' );
  7092. return this;
  7093. }
  7094. var geometry2 = new THREE.BufferGeometry();
  7095. var indices = this.index.array;
  7096. var attributes = this.attributes;
  7097. for ( var name in attributes ) {
  7098. var attribute = attributes[ name ];
  7099. var array = attribute.array;
  7100. var itemSize = attribute.itemSize;
  7101. var array2 = new array.constructor( indices.length * itemSize );
  7102. var index = 0, index2 = 0;
  7103. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  7104. index = indices[ i ] * itemSize;
  7105. for ( var j = 0; j < itemSize; j ++ ) {
  7106. array2[ index2 ++ ] = array[ index ++ ];
  7107. }
  7108. }
  7109. geometry2.addAttribute( name, new THREE.BufferAttribute( array2, itemSize ) );
  7110. }
  7111. return geometry2;
  7112. },
  7113. toJSON: function () {
  7114. var data = {
  7115. metadata: {
  7116. version: 4.4,
  7117. type: 'BufferGeometry',
  7118. generator: 'BufferGeometry.toJSON'
  7119. }
  7120. };
  7121. // standard BufferGeometry serialization
  7122. data.uuid = this.uuid;
  7123. data.type = this.type;
  7124. if ( this.name !== '' ) data.name = this.name;
  7125. if ( this.parameters !== undefined ) {
  7126. var parameters = this.parameters;
  7127. for ( var key in parameters ) {
  7128. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  7129. }
  7130. return data;
  7131. }
  7132. data.data = { attributes: {} };
  7133. var index = this.index;
  7134. if ( index !== null ) {
  7135. var array = Array.prototype.slice.call( index.array );
  7136. data.data.index = {
  7137. type: index.array.constructor.name,
  7138. array: array
  7139. };
  7140. }
  7141. var attributes = this.attributes;
  7142. for ( var key in attributes ) {
  7143. var attribute = attributes[ key ];
  7144. var array = Array.prototype.slice.call( attribute.array );
  7145. data.data.attributes[ key ] = {
  7146. itemSize: attribute.itemSize,
  7147. type: attribute.array.constructor.name,
  7148. array: array,
  7149. normalized: attribute.normalized
  7150. };
  7151. }
  7152. var groups = this.groups;
  7153. if ( groups.length > 0 ) {
  7154. data.data.groups = JSON.parse( JSON.stringify( groups ) );
  7155. }
  7156. var boundingSphere = this.boundingSphere;
  7157. if ( boundingSphere !== null ) {
  7158. data.data.boundingSphere = {
  7159. center: boundingSphere.center.toArray(),
  7160. radius: boundingSphere.radius
  7161. };
  7162. }
  7163. return data;
  7164. },
  7165. clone: function () {
  7166. /*
  7167. // Handle primitives
  7168. var parameters = this.parameters;
  7169. if ( parameters !== undefined ) {
  7170. var values = [];
  7171. for ( var key in parameters ) {
  7172. values.push( parameters[ key ] );
  7173. }
  7174. var geometry = Object.create( this.constructor.prototype );
  7175. this.constructor.apply( geometry, values );
  7176. return geometry;
  7177. }
  7178. return new this.constructor().copy( this );
  7179. */
  7180. return new THREE.BufferGeometry().copy( this );
  7181. },
  7182. copy: function ( source ) {
  7183. var index = source.index;
  7184. if ( index !== null ) {
  7185. this.setIndex( index.clone() );
  7186. }
  7187. var attributes = source.attributes;
  7188. for ( var name in attributes ) {
  7189. var attribute = attributes[ name ];
  7190. this.addAttribute( name, attribute.clone() );
  7191. }
  7192. var groups = source.groups;
  7193. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  7194. var group = groups[ i ];
  7195. this.addGroup( group.start, group.count, group.materialIndex );
  7196. }
  7197. return this;
  7198. },
  7199. dispose: function () {
  7200. this.dispatchEvent( { type: 'dispose' } );
  7201. }
  7202. } );
  7203. THREE.BufferGeometry.MaxIndex = 65535;
  7204. // File:src/core/InstancedBufferGeometry.js
  7205. /**
  7206. * @author benaadams / https://twitter.com/ben_a_adams
  7207. */
  7208. THREE.InstancedBufferGeometry = function () {
  7209. THREE.BufferGeometry.call( this );
  7210. this.type = 'InstancedBufferGeometry';
  7211. this.maxInstancedCount = undefined;
  7212. };
  7213. THREE.InstancedBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  7214. THREE.InstancedBufferGeometry.prototype.constructor = THREE.InstancedBufferGeometry;
  7215. THREE.InstancedBufferGeometry.prototype.addGroup = function ( start, count, instances ) {
  7216. this.groups.push( {
  7217. start: start,
  7218. count: count,
  7219. instances: instances
  7220. } );
  7221. };
  7222. THREE.InstancedBufferGeometry.prototype.copy = function ( source ) {
  7223. var index = source.index;
  7224. if ( index !== null ) {
  7225. this.setIndex( index.clone() );
  7226. }
  7227. var attributes = source.attributes;
  7228. for ( var name in attributes ) {
  7229. var attribute = attributes[ name ];
  7230. this.addAttribute( name, attribute.clone() );
  7231. }
  7232. var groups = source.groups;
  7233. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  7234. var group = groups[ i ];
  7235. this.addGroup( group.start, group.count, group.instances );
  7236. }
  7237. return this;
  7238. };
  7239. // File:src/core/Uniform.js
  7240. /**
  7241. * @author mrdoob / http://mrdoob.com/
  7242. */
  7243. THREE.Uniform = function ( value ) {
  7244. if ( typeof value === 'string' ) {
  7245. console.warn( 'THREE.Uniform: Type parameter is no longer needed.' );
  7246. value = arguments[ 1 ];
  7247. }
  7248. this.value = value;
  7249. this.dynamic = false;
  7250. };
  7251. THREE.Uniform.prototype = {
  7252. constructor: THREE.Uniform,
  7253. onUpdate: function ( callback ) {
  7254. this.dynamic = true;
  7255. this.onUpdateCallback = callback;
  7256. return this;
  7257. }
  7258. };
  7259. // File:src/animation/AnimationAction.js
  7260. /**
  7261. *
  7262. * Action provided by AnimationMixer for scheduling clip playback on specific
  7263. * objects.
  7264. *
  7265. * @author Ben Houston / http://clara.io/
  7266. * @author David Sarno / http://lighthaus.us/
  7267. * @author tschw
  7268. *
  7269. */
  7270. THREE.AnimationAction = function() {
  7271. throw new Error( "THREE.AnimationAction: " +
  7272. "Use mixer.clipAction for construction." );
  7273. };
  7274. THREE.AnimationAction._new =
  7275. function AnimationAction( mixer, clip, localRoot ) {
  7276. this._mixer = mixer;
  7277. this._clip = clip;
  7278. this._localRoot = localRoot || null;
  7279. var tracks = clip.tracks,
  7280. nTracks = tracks.length,
  7281. interpolants = new Array( nTracks );
  7282. var interpolantSettings = {
  7283. endingStart: THREE.ZeroCurvatureEnding,
  7284. endingEnd: THREE.ZeroCurvatureEnding
  7285. };
  7286. for ( var i = 0; i !== nTracks; ++ i ) {
  7287. var interpolant = tracks[ i ].createInterpolant( null );
  7288. interpolants[ i ] = interpolant;
  7289. interpolant.settings = interpolantSettings;
  7290. }
  7291. this._interpolantSettings = interpolantSettings;
  7292. this._interpolants = interpolants; // bound by the mixer
  7293. // inside: PropertyMixer (managed by the mixer)
  7294. this._propertyBindings = new Array( nTracks );
  7295. this._cacheIndex = null; // for the memory manager
  7296. this._byClipCacheIndex = null; // for the memory manager
  7297. this._timeScaleInterpolant = null;
  7298. this._weightInterpolant = null;
  7299. this.loop = THREE.LoopRepeat;
  7300. this._loopCount = -1;
  7301. // global mixer time when the action is to be started
  7302. // it's set back to 'null' upon start of the action
  7303. this._startTime = null;
  7304. // scaled local time of the action
  7305. // gets clamped or wrapped to 0..clip.duration according to loop
  7306. this.time = 0;
  7307. this.timeScale = 1;
  7308. this._effectiveTimeScale = 1;
  7309. this.weight = 1;
  7310. this._effectiveWeight = 1;
  7311. this.repetitions = Infinity; // no. of repetitions when looping
  7312. this.paused = false; // false -> zero effective time scale
  7313. this.enabled = true; // true -> zero effective weight
  7314. this.clampWhenFinished = false; // keep feeding the last frame?
  7315. this.zeroSlopeAtStart = true; // for smooth interpolation w/o separate
  7316. this.zeroSlopeAtEnd = true; // clips for start, loop and end
  7317. };
  7318. THREE.AnimationAction._new.prototype = {
  7319. constructor: THREE.AnimationAction._new,
  7320. // State & Scheduling
  7321. play: function() {
  7322. this._mixer._activateAction( this );
  7323. return this;
  7324. },
  7325. stop: function() {
  7326. this._mixer._deactivateAction( this );
  7327. return this.reset();
  7328. },
  7329. reset: function() {
  7330. this.paused = false;
  7331. this.enabled = true;
  7332. this.time = 0; // restart clip
  7333. this._loopCount = -1; // forget previous loops
  7334. this._startTime = null; // forget scheduling
  7335. return this.stopFading().stopWarping();
  7336. },
  7337. isRunning: function() {
  7338. var start = this._startTime;
  7339. return this.enabled && ! this.paused && this.timeScale !== 0 &&
  7340. this._startTime === null && this._mixer._isActiveAction( this );
  7341. },
  7342. // return true when play has been called
  7343. isScheduled: function() {
  7344. return this._mixer._isActiveAction( this );
  7345. },
  7346. startAt: function( time ) {
  7347. this._startTime = time;
  7348. return this;
  7349. },
  7350. setLoop: function( mode, repetitions ) {
  7351. this.loop = mode;
  7352. this.repetitions = repetitions;
  7353. return this;
  7354. },
  7355. // Weight
  7356. // set the weight stopping any scheduled fading
  7357. // although .enabled = false yields an effective weight of zero, this
  7358. // method does *not* change .enabled, because it would be confusing
  7359. setEffectiveWeight: function( weight ) {
  7360. this.weight = weight;
  7361. // note: same logic as when updated at runtime
  7362. this._effectiveWeight = this.enabled ? weight : 0;
  7363. return this.stopFading();
  7364. },
  7365. // return the weight considering fading and .enabled
  7366. getEffectiveWeight: function() {
  7367. return this._effectiveWeight;
  7368. },
  7369. fadeIn: function( duration ) {
  7370. return this._scheduleFading( duration, 0, 1 );
  7371. },
  7372. fadeOut: function( duration ) {
  7373. return this._scheduleFading( duration, 1, 0 );
  7374. },
  7375. crossFadeFrom: function( fadeOutAction, duration, warp ) {
  7376. var mixer = this._mixer;
  7377. fadeOutAction.fadeOut( duration );
  7378. this.fadeIn( duration );
  7379. if( warp ) {
  7380. var fadeInDuration = this._clip.duration,
  7381. fadeOutDuration = fadeOutAction._clip.duration,
  7382. startEndRatio = fadeOutDuration / fadeInDuration,
  7383. endStartRatio = fadeInDuration / fadeOutDuration;
  7384. fadeOutAction.warp( 1.0, startEndRatio, duration );
  7385. this.warp( endStartRatio, 1.0, duration );
  7386. }
  7387. return this;
  7388. },
  7389. crossFadeTo: function( fadeInAction, duration, warp ) {
  7390. return fadeInAction.crossFadeFrom( this, duration, warp );
  7391. },
  7392. stopFading: function() {
  7393. var weightInterpolant = this._weightInterpolant;
  7394. if ( weightInterpolant !== null ) {
  7395. this._weightInterpolant = null;
  7396. this._mixer._takeBackControlInterpolant( weightInterpolant );
  7397. }
  7398. return this;
  7399. },
  7400. // Time Scale Control
  7401. // set the weight stopping any scheduled warping
  7402. // although .paused = true yields an effective time scale of zero, this
  7403. // method does *not* change .paused, because it would be confusing
  7404. setEffectiveTimeScale: function( timeScale ) {
  7405. this.timeScale = timeScale;
  7406. this._effectiveTimeScale = this.paused ? 0 :timeScale;
  7407. return this.stopWarping();
  7408. },
  7409. // return the time scale considering warping and .paused
  7410. getEffectiveTimeScale: function() {
  7411. return this._effectiveTimeScale;
  7412. },
  7413. setDuration: function( duration ) {
  7414. this.timeScale = this._clip.duration / duration;
  7415. return this.stopWarping();
  7416. },
  7417. syncWith: function( action ) {
  7418. this.time = action.time;
  7419. this.timeScale = action.timeScale;
  7420. return this.stopWarping();
  7421. },
  7422. halt: function( duration ) {
  7423. return this.warp( this._effectiveTimeScale, 0, duration );
  7424. },
  7425. warp: function( startTimeScale, endTimeScale, duration ) {
  7426. var mixer = this._mixer, now = mixer.time,
  7427. interpolant = this._timeScaleInterpolant,
  7428. timeScale = this.timeScale;
  7429. if ( interpolant === null ) {
  7430. interpolant = mixer._lendControlInterpolant(),
  7431. this._timeScaleInterpolant = interpolant;
  7432. }
  7433. var times = interpolant.parameterPositions,
  7434. values = interpolant.sampleValues;
  7435. times[ 0 ] = now;
  7436. times[ 1 ] = now + duration;
  7437. values[ 0 ] = startTimeScale / timeScale;
  7438. values[ 1 ] = endTimeScale / timeScale;
  7439. return this;
  7440. },
  7441. stopWarping: function() {
  7442. var timeScaleInterpolant = this._timeScaleInterpolant;
  7443. if ( timeScaleInterpolant !== null ) {
  7444. this._timeScaleInterpolant = null;
  7445. this._mixer._takeBackControlInterpolant( timeScaleInterpolant );
  7446. }
  7447. return this;
  7448. },
  7449. // Object Accessors
  7450. getMixer: function() {
  7451. return this._mixer;
  7452. },
  7453. getClip: function() {
  7454. return this._clip;
  7455. },
  7456. getRoot: function() {
  7457. return this._localRoot || this._mixer._root;
  7458. },
  7459. // Interna
  7460. _update: function( time, deltaTime, timeDirection, accuIndex ) {
  7461. // called by the mixer
  7462. var startTime = this._startTime;
  7463. if ( startTime !== null ) {
  7464. // check for scheduled start of action
  7465. var timeRunning = ( time - startTime ) * timeDirection;
  7466. if ( timeRunning < 0 || timeDirection === 0 ) {
  7467. return; // yet to come / don't decide when delta = 0
  7468. }
  7469. // start
  7470. this._startTime = null; // unschedule
  7471. deltaTime = timeDirection * timeRunning;
  7472. }
  7473. // apply time scale and advance time
  7474. deltaTime *= this._updateTimeScale( time );
  7475. var clipTime = this._updateTime( deltaTime );
  7476. // note: _updateTime may disable the action resulting in
  7477. // an effective weight of 0
  7478. var weight = this._updateWeight( time );
  7479. if ( weight > 0 ) {
  7480. var interpolants = this._interpolants;
  7481. var propertyMixers = this._propertyBindings;
  7482. for ( var j = 0, m = interpolants.length; j !== m; ++ j ) {
  7483. interpolants[ j ].evaluate( clipTime );
  7484. propertyMixers[ j ].accumulate( accuIndex, weight );
  7485. }
  7486. }
  7487. },
  7488. _updateWeight: function( time ) {
  7489. var weight = 0;
  7490. if ( this.enabled ) {
  7491. weight = this.weight;
  7492. var interpolant = this._weightInterpolant;
  7493. if ( interpolant !== null ) {
  7494. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  7495. weight *= interpolantValue;
  7496. if ( time > interpolant.parameterPositions[ 1 ] ) {
  7497. this.stopFading();
  7498. if ( interpolantValue === 0 ) {
  7499. // faded out, disable
  7500. this.enabled = false;
  7501. }
  7502. }
  7503. }
  7504. }
  7505. this._effectiveWeight = weight;
  7506. return weight;
  7507. },
  7508. _updateTimeScale: function( time ) {
  7509. var timeScale = 0;
  7510. if ( ! this.paused ) {
  7511. timeScale = this.timeScale;
  7512. var interpolant = this._timeScaleInterpolant;
  7513. if ( interpolant !== null ) {
  7514. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  7515. timeScale *= interpolantValue;
  7516. if ( time > interpolant.parameterPositions[ 1 ] ) {
  7517. this.stopWarping();
  7518. if ( timeScale === 0 ) {
  7519. // motion has halted, pause
  7520. this.paused = true;
  7521. } else {
  7522. // warp done - apply final time scale
  7523. this.timeScale = timeScale;
  7524. }
  7525. }
  7526. }
  7527. }
  7528. this._effectiveTimeScale = timeScale;
  7529. return timeScale;
  7530. },
  7531. _updateTime: function( deltaTime ) {
  7532. var time = this.time + deltaTime;
  7533. if ( deltaTime === 0 ) return time;
  7534. var duration = this._clip.duration,
  7535. loop = this.loop,
  7536. loopCount = this._loopCount;
  7537. if ( loop === THREE.LoopOnce ) {
  7538. if ( loopCount === -1 ) {
  7539. // just started
  7540. this.loopCount = 0;
  7541. this._setEndings( true, true, false );
  7542. }
  7543. handle_stop: {
  7544. if ( time >= duration ) {
  7545. time = duration;
  7546. } else if ( time < 0 ) {
  7547. time = 0;
  7548. } else break handle_stop;
  7549. if ( this.clampWhenFinished ) this.paused = true;
  7550. else this.enabled = false;
  7551. this._mixer.dispatchEvent( {
  7552. type: 'finished', action: this,
  7553. direction: deltaTime < 0 ? -1 : 1
  7554. } );
  7555. }
  7556. } else { // repetitive Repeat or PingPong
  7557. var pingPong = ( loop === THREE.LoopPingPong );
  7558. if ( loopCount === -1 ) {
  7559. // just started
  7560. if ( deltaTime >= 0 ) {
  7561. loopCount = 0;
  7562. this._setEndings(
  7563. true, this.repetitions === 0, pingPong );
  7564. } else {
  7565. // when looping in reverse direction, the initial
  7566. // transition through zero counts as a repetition,
  7567. // so leave loopCount at -1
  7568. this._setEndings(
  7569. this.repetitions === 0, true, pingPong );
  7570. }
  7571. }
  7572. if ( time >= duration || time < 0 ) {
  7573. // wrap around
  7574. var loopDelta = Math.floor( time / duration ); // signed
  7575. time -= duration * loopDelta;
  7576. loopCount += Math.abs( loopDelta );
  7577. var pending = this.repetitions - loopCount;
  7578. if ( pending < 0 ) {
  7579. // have to stop (switch state, clamp time, fire event)
  7580. if ( this.clampWhenFinished ) this.paused = true;
  7581. else this.enabled = false;
  7582. time = deltaTime > 0 ? duration : 0;
  7583. this._mixer.dispatchEvent( {
  7584. type: 'finished', action: this,
  7585. direction: deltaTime > 0 ? 1 : -1
  7586. } );
  7587. } else {
  7588. // keep running
  7589. if ( pending === 0 ) {
  7590. // entering the last round
  7591. var atStart = deltaTime < 0;
  7592. this._setEndings( atStart, ! atStart, pingPong );
  7593. } else {
  7594. this._setEndings( false, false, pingPong );
  7595. }
  7596. this._loopCount = loopCount;
  7597. this._mixer.dispatchEvent( {
  7598. type: 'loop', action: this, loopDelta: loopDelta
  7599. } );
  7600. }
  7601. }
  7602. if ( pingPong && ( loopCount & 1 ) === 1 ) {
  7603. // invert time for the "pong round"
  7604. this.time = time;
  7605. return duration - time;
  7606. }
  7607. }
  7608. this.time = time;
  7609. return time;
  7610. },
  7611. _setEndings: function( atStart, atEnd, pingPong ) {
  7612. var settings = this._interpolantSettings;
  7613. if ( pingPong ) {
  7614. settings.endingStart = THREE.ZeroSlopeEnding;
  7615. settings.endingEnd = THREE.ZeroSlopeEnding;
  7616. } else {
  7617. // assuming for LoopOnce atStart == atEnd == true
  7618. if ( atStart ) {
  7619. settings.endingStart = this.zeroSlopeAtStart ?
  7620. THREE.ZeroSlopeEnding : THREE.ZeroCurvatureEnding;
  7621. } else {
  7622. settings.endingStart = THREE.WrapAroundEnding;
  7623. }
  7624. if ( atEnd ) {
  7625. settings.endingEnd = this.zeroSlopeAtEnd ?
  7626. THREE.ZeroSlopeEnding : THREE.ZeroCurvatureEnding;
  7627. } else {
  7628. settings.endingEnd = THREE.WrapAroundEnding;
  7629. }
  7630. }
  7631. },
  7632. _scheduleFading: function( duration, weightNow, weightThen ) {
  7633. var mixer = this._mixer, now = mixer.time,
  7634. interpolant = this._weightInterpolant;
  7635. if ( interpolant === null ) {
  7636. interpolant = mixer._lendControlInterpolant(),
  7637. this._weightInterpolant = interpolant;
  7638. }
  7639. var times = interpolant.parameterPositions,
  7640. values = interpolant.sampleValues;
  7641. times[ 0 ] = now; values[ 0 ] = weightNow;
  7642. times[ 1 ] = now + duration; values[ 1 ] = weightThen;
  7643. return this;
  7644. }
  7645. };
  7646. // File:src/animation/AnimationClip.js
  7647. /**
  7648. *
  7649. * Reusable set of Tracks that represent an animation.
  7650. *
  7651. * @author Ben Houston / http://clara.io/
  7652. * @author David Sarno / http://lighthaus.us/
  7653. */
  7654. THREE.AnimationClip = function ( name, duration, tracks ) {
  7655. this.name = name;
  7656. this.tracks = tracks;
  7657. this.duration = ( duration !== undefined ) ? duration : -1;
  7658. this.uuid = THREE.Math.generateUUID();
  7659. // this means it should figure out its duration by scanning the tracks
  7660. if ( this.duration < 0 ) {
  7661. this.resetDuration();
  7662. }
  7663. // maybe only do these on demand, as doing them here could potentially slow down loading
  7664. // but leaving these here during development as this ensures a lot of testing of these functions
  7665. this.trim();
  7666. this.optimize();
  7667. };
  7668. THREE.AnimationClip.prototype = {
  7669. constructor: THREE.AnimationClip,
  7670. resetDuration: function() {
  7671. var tracks = this.tracks,
  7672. duration = 0;
  7673. for ( var i = 0, n = tracks.length; i !== n; ++ i ) {
  7674. var track = this.tracks[ i ];
  7675. duration = Math.max(
  7676. duration, track.times[ track.times.length - 1 ] );
  7677. }
  7678. this.duration = duration;
  7679. },
  7680. trim: function() {
  7681. for ( var i = 0; i < this.tracks.length; i ++ ) {
  7682. this.tracks[ i ].trim( 0, this.duration );
  7683. }
  7684. return this;
  7685. },
  7686. optimize: function() {
  7687. for ( var i = 0; i < this.tracks.length; i ++ ) {
  7688. this.tracks[ i ].optimize();
  7689. }
  7690. return this;
  7691. }
  7692. };
  7693. // Static methods:
  7694. Object.assign( THREE.AnimationClip, {
  7695. parse: function( json ) {
  7696. var tracks = [],
  7697. jsonTracks = json.tracks,
  7698. frameTime = 1.0 / ( json.fps || 1.0 );
  7699. for ( var i = 0, n = jsonTracks.length; i !== n; ++ i ) {
  7700. tracks.push( THREE.KeyframeTrack.parse( jsonTracks[ i ] ).scale( frameTime ) );
  7701. }
  7702. return new THREE.AnimationClip( json.name, json.duration, tracks );
  7703. },
  7704. toJSON: function( clip ) {
  7705. var tracks = [],
  7706. clipTracks = clip.tracks;
  7707. var json = {
  7708. 'name': clip.name,
  7709. 'duration': clip.duration,
  7710. 'tracks': tracks
  7711. };
  7712. for ( var i = 0, n = clipTracks.length; i !== n; ++ i ) {
  7713. tracks.push( THREE.KeyframeTrack.toJSON( clipTracks[ i ] ) );
  7714. }
  7715. return json;
  7716. },
  7717. CreateFromMorphTargetSequence: function( name, morphTargetSequence, fps, noLoop ) {
  7718. var numMorphTargets = morphTargetSequence.length;
  7719. var tracks = [];
  7720. for ( var i = 0; i < numMorphTargets; i ++ ) {
  7721. var times = [];
  7722. var values = [];
  7723. times.push(
  7724. ( i + numMorphTargets - 1 ) % numMorphTargets,
  7725. i,
  7726. ( i + 1 ) % numMorphTargets );
  7727. values.push( 0, 1, 0 );
  7728. var order = THREE.AnimationUtils.getKeyframeOrder( times );
  7729. times = THREE.AnimationUtils.sortedArray( times, 1, order );
  7730. values = THREE.AnimationUtils.sortedArray( values, 1, order );
  7731. // if there is a key at the first frame, duplicate it as the
  7732. // last frame as well for perfect loop.
  7733. if ( ! noLoop && times[ 0 ] === 0 ) {
  7734. times.push( numMorphTargets );
  7735. values.push( values[ 0 ] );
  7736. }
  7737. tracks.push(
  7738. new THREE.NumberKeyframeTrack(
  7739. '.morphTargetInfluences[' + morphTargetSequence[ i ].name + ']',
  7740. times, values
  7741. ).scale( 1.0 / fps ) );
  7742. }
  7743. return new THREE.AnimationClip( name, -1, tracks );
  7744. },
  7745. findByName: function( objectOrClipArray, name ) {
  7746. var clipArray = objectOrClipArray;
  7747. if ( ! Array.isArray( objectOrClipArray ) ) {
  7748. var o = objectOrClipArray;
  7749. clipArray = o.geometry && o.geometry.animations || o.animations;
  7750. }
  7751. for ( var i = 0; i < clipArray.length; i ++ ) {
  7752. if ( clipArray[ i ].name === name ) {
  7753. return clipArray[ i ];
  7754. }
  7755. }
  7756. return null;
  7757. },
  7758. CreateClipsFromMorphTargetSequences: function( morphTargets, fps, noLoop ) {
  7759. var animationToMorphTargets = {};
  7760. // tested with https://regex101.com/ on trick sequences
  7761. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  7762. var pattern = /^([\w-]*?)([\d]+)$/;
  7763. // sort morph target names into animation groups based
  7764. // patterns like Walk_001, Walk_002, Run_001, Run_002
  7765. for ( var i = 0, il = morphTargets.length; i < il; i ++ ) {
  7766. var morphTarget = morphTargets[ i ];
  7767. var parts = morphTarget.name.match( pattern );
  7768. if ( parts && parts.length > 1 ) {
  7769. var name = parts[ 1 ];
  7770. var animationMorphTargets = animationToMorphTargets[ name ];
  7771. if ( ! animationMorphTargets ) {
  7772. animationToMorphTargets[ name ] = animationMorphTargets = [];
  7773. }
  7774. animationMorphTargets.push( morphTarget );
  7775. }
  7776. }
  7777. var clips = [];
  7778. for ( var name in animationToMorphTargets ) {
  7779. clips.push( THREE.AnimationClip.CreateFromMorphTargetSequence( name, animationToMorphTargets[ name ], fps, noLoop ) );
  7780. }
  7781. return clips;
  7782. },
  7783. // parse the animation.hierarchy format
  7784. parseAnimation: function( animation, bones, nodeName ) {
  7785. if ( ! animation ) {
  7786. console.error( " no animation in JSONLoader data" );
  7787. return null;
  7788. }
  7789. var addNonemptyTrack = function(
  7790. trackType, trackName, animationKeys, propertyName, destTracks ) {
  7791. // only return track if there are actually keys.
  7792. if ( animationKeys.length !== 0 ) {
  7793. var times = [];
  7794. var values = [];
  7795. THREE.AnimationUtils.flattenJSON(
  7796. animationKeys, times, values, propertyName );
  7797. // empty keys are filtered out, so check again
  7798. if ( times.length !== 0 ) {
  7799. destTracks.push( new trackType( trackName, times, values ) );
  7800. }
  7801. }
  7802. };
  7803. var tracks = [];
  7804. var clipName = animation.name || 'default';
  7805. // automatic length determination in AnimationClip.
  7806. var duration = animation.length || -1;
  7807. var fps = animation.fps || 30;
  7808. var hierarchyTracks = animation.hierarchy || [];
  7809. for ( var h = 0; h < hierarchyTracks.length; h ++ ) {
  7810. var animationKeys = hierarchyTracks[ h ].keys;
  7811. // skip empty tracks
  7812. if ( ! animationKeys || animationKeys.length === 0 ) continue;
  7813. // process morph targets in a way exactly compatible
  7814. // with AnimationHandler.init( animation )
  7815. if ( animationKeys[0].morphTargets ) {
  7816. // figure out all morph targets used in this track
  7817. var morphTargetNames = {};
  7818. for ( var k = 0; k < animationKeys.length; k ++ ) {
  7819. if ( animationKeys[k].morphTargets ) {
  7820. for ( var m = 0; m < animationKeys[k].morphTargets.length; m ++ ) {
  7821. morphTargetNames[ animationKeys[k].morphTargets[m] ] = -1;
  7822. }
  7823. }
  7824. }
  7825. // create a track for each morph target with all zero
  7826. // morphTargetInfluences except for the keys in which
  7827. // the morphTarget is named.
  7828. for ( var morphTargetName in morphTargetNames ) {
  7829. var times = [];
  7830. var values = [];
  7831. for ( var m = 0;
  7832. m !== animationKeys[k].morphTargets.length; ++ m ) {
  7833. var animationKey = animationKeys[k];
  7834. times.push( animationKey.time );
  7835. values.push( ( animationKey.morphTarget === morphTargetName ) ? 1 : 0 );
  7836. }
  7837. tracks.push( new THREE.NumberKeyframeTrack(
  7838. '.morphTargetInfluence[' + morphTargetName + ']', times, values ) );
  7839. }
  7840. duration = morphTargetNames.length * ( fps || 1.0 );
  7841. } else {
  7842. // ...assume skeletal animation
  7843. var boneName = '.bones[' + bones[ h ].name + ']';
  7844. addNonemptyTrack(
  7845. THREE.VectorKeyframeTrack, boneName + '.position',
  7846. animationKeys, 'pos', tracks );
  7847. addNonemptyTrack(
  7848. THREE.QuaternionKeyframeTrack, boneName + '.quaternion',
  7849. animationKeys, 'rot', tracks );
  7850. addNonemptyTrack(
  7851. THREE.VectorKeyframeTrack, boneName + '.scale',
  7852. animationKeys, 'scl', tracks );
  7853. }
  7854. }
  7855. if ( tracks.length === 0 ) {
  7856. return null;
  7857. }
  7858. var clip = new THREE.AnimationClip( clipName, duration, tracks );
  7859. return clip;
  7860. }
  7861. } );
  7862. // File:src/animation/AnimationMixer.js
  7863. /**
  7864. *
  7865. * Player for AnimationClips.
  7866. *
  7867. *
  7868. * @author Ben Houston / http://clara.io/
  7869. * @author David Sarno / http://lighthaus.us/
  7870. * @author tschw
  7871. */
  7872. THREE.AnimationMixer = function( root ) {
  7873. this._root = root;
  7874. this._initMemoryManager();
  7875. this._accuIndex = 0;
  7876. this.time = 0;
  7877. this.timeScale = 1.0;
  7878. };
  7879. Object.assign( THREE.AnimationMixer.prototype, THREE.EventDispatcher.prototype, {
  7880. // return an action for a clip optionally using a custom root target
  7881. // object (this method allocates a lot of dynamic memory in case a
  7882. // previously unknown clip/root combination is specified)
  7883. clipAction: function( clip, optionalRoot ) {
  7884. var root = optionalRoot || this._root,
  7885. rootUuid = root.uuid,
  7886. clipObject = typeof clip === 'string' ?
  7887. THREE.AnimationClip.findByName( root, clip ) : clip,
  7888. clipUuid = clipObject !== null ? clipObject.uuid : clip,
  7889. actionsForClip = this._actionsByClip[ clipUuid ],
  7890. prototypeAction = null;
  7891. if ( actionsForClip !== undefined ) {
  7892. var existingAction =
  7893. actionsForClip.actionByRoot[ rootUuid ];
  7894. if ( existingAction !== undefined ) {
  7895. return existingAction;
  7896. }
  7897. // we know the clip, so we don't have to parse all
  7898. // the bindings again but can just copy
  7899. prototypeAction = actionsForClip.knownActions[ 0 ];
  7900. // also, take the clip from the prototype action
  7901. if ( clipObject === null )
  7902. clipObject = prototypeAction._clip;
  7903. }
  7904. // clip must be known when specified via string
  7905. if ( clipObject === null ) return null;
  7906. // allocate all resources required to run it
  7907. var newAction = new THREE.
  7908. AnimationMixer._Action( this, clipObject, optionalRoot );
  7909. this._bindAction( newAction, prototypeAction );
  7910. // and make the action known to the memory manager
  7911. this._addInactiveAction( newAction, clipUuid, rootUuid );
  7912. return newAction;
  7913. },
  7914. // get an existing action
  7915. existingAction: function( clip, optionalRoot ) {
  7916. var root = optionalRoot || this._root,
  7917. rootUuid = root.uuid,
  7918. clipObject = typeof clip === 'string' ?
  7919. THREE.AnimationClip.findByName( root, clip ) : clip,
  7920. clipUuid = clipObject ? clipObject.uuid : clip,
  7921. actionsForClip = this._actionsByClip[ clipUuid ];
  7922. if ( actionsForClip !== undefined ) {
  7923. return actionsForClip.actionByRoot[ rootUuid ] || null;
  7924. }
  7925. return null;
  7926. },
  7927. // deactivates all previously scheduled actions
  7928. stopAllAction: function() {
  7929. var actions = this._actions,
  7930. nActions = this._nActiveActions,
  7931. bindings = this._bindings,
  7932. nBindings = this._nActiveBindings;
  7933. this._nActiveActions = 0;
  7934. this._nActiveBindings = 0;
  7935. for ( var i = 0; i !== nActions; ++ i ) {
  7936. actions[ i ].reset();
  7937. }
  7938. for ( var i = 0; i !== nBindings; ++ i ) {
  7939. bindings[ i ].useCount = 0;
  7940. }
  7941. return this;
  7942. },
  7943. // advance the time and update apply the animation
  7944. update: function( deltaTime ) {
  7945. deltaTime *= this.timeScale;
  7946. var actions = this._actions,
  7947. nActions = this._nActiveActions,
  7948. time = this.time += deltaTime,
  7949. timeDirection = Math.sign( deltaTime ),
  7950. accuIndex = this._accuIndex ^= 1;
  7951. // run active actions
  7952. for ( var i = 0; i !== nActions; ++ i ) {
  7953. var action = actions[ i ];
  7954. if ( action.enabled ) {
  7955. action._update( time, deltaTime, timeDirection, accuIndex );
  7956. }
  7957. }
  7958. // update scene graph
  7959. var bindings = this._bindings,
  7960. nBindings = this._nActiveBindings;
  7961. for ( var i = 0; i !== nBindings; ++ i ) {
  7962. bindings[ i ].apply( accuIndex );
  7963. }
  7964. return this;
  7965. },
  7966. // return this mixer's root target object
  7967. getRoot: function() {
  7968. return this._root;
  7969. },
  7970. // free all resources specific to a particular clip
  7971. uncacheClip: function( clip ) {
  7972. var actions = this._actions,
  7973. clipUuid = clip.uuid,
  7974. actionsByClip = this._actionsByClip,
  7975. actionsForClip = actionsByClip[ clipUuid ];
  7976. if ( actionsForClip !== undefined ) {
  7977. // note: just calling _removeInactiveAction would mess up the
  7978. // iteration state and also require updating the state we can
  7979. // just throw away
  7980. var actionsToRemove = actionsForClip.knownActions;
  7981. for ( var i = 0, n = actionsToRemove.length; i !== n; ++ i ) {
  7982. var action = actionsToRemove[ i ];
  7983. this._deactivateAction( action );
  7984. var cacheIndex = action._cacheIndex,
  7985. lastInactiveAction = actions[ actions.length - 1 ];
  7986. action._cacheIndex = null;
  7987. action._byClipCacheIndex = null;
  7988. lastInactiveAction._cacheIndex = cacheIndex;
  7989. actions[ cacheIndex ] = lastInactiveAction;
  7990. actions.pop();
  7991. this._removeInactiveBindingsForAction( action );
  7992. }
  7993. delete actionsByClip[ clipUuid ];
  7994. }
  7995. },
  7996. // free all resources specific to a particular root target object
  7997. uncacheRoot: function( root ) {
  7998. var rootUuid = root.uuid,
  7999. actionsByClip = this._actionsByClip;
  8000. for ( var clipUuid in actionsByClip ) {
  8001. var actionByRoot = actionsByClip[ clipUuid ].actionByRoot,
  8002. action = actionByRoot[ rootUuid ];
  8003. if ( action !== undefined ) {
  8004. this._deactivateAction( action );
  8005. this._removeInactiveAction( action );
  8006. }
  8007. }
  8008. var bindingsByRoot = this._bindingsByRootAndName,
  8009. bindingByName = bindingsByRoot[ rootUuid ];
  8010. if ( bindingByName !== undefined ) {
  8011. for ( var trackName in bindingByName ) {
  8012. var binding = bindingByName[ trackName ];
  8013. binding.restoreOriginalState();
  8014. this._removeInactiveBinding( binding );
  8015. }
  8016. }
  8017. },
  8018. // remove a targeted clip from the cache
  8019. uncacheAction: function( clip, optionalRoot ) {
  8020. var action = this.existingAction( clip, optionalRoot );
  8021. if ( action !== null ) {
  8022. this._deactivateAction( action );
  8023. this._removeInactiveAction( action );
  8024. }
  8025. }
  8026. } );
  8027. THREE.AnimationMixer._Action = THREE.AnimationAction._new;
  8028. // Implementation details:
  8029. Object.assign( THREE.AnimationMixer.prototype, {
  8030. _bindAction: function( action, prototypeAction ) {
  8031. var root = action._localRoot || this._root,
  8032. tracks = action._clip.tracks,
  8033. nTracks = tracks.length,
  8034. bindings = action._propertyBindings,
  8035. interpolants = action._interpolants,
  8036. rootUuid = root.uuid,
  8037. bindingsByRoot = this._bindingsByRootAndName,
  8038. bindingsByName = bindingsByRoot[ rootUuid ];
  8039. if ( bindingsByName === undefined ) {
  8040. bindingsByName = {};
  8041. bindingsByRoot[ rootUuid ] = bindingsByName;
  8042. }
  8043. for ( var i = 0; i !== nTracks; ++ i ) {
  8044. var track = tracks[ i ],
  8045. trackName = track.name,
  8046. binding = bindingsByName[ trackName ];
  8047. if ( binding !== undefined ) {
  8048. bindings[ i ] = binding;
  8049. } else {
  8050. binding = bindings[ i ];
  8051. if ( binding !== undefined ) {
  8052. // existing binding, make sure the cache knows
  8053. if ( binding._cacheIndex === null ) {
  8054. ++ binding.referenceCount;
  8055. this._addInactiveBinding( binding, rootUuid, trackName );
  8056. }
  8057. continue;
  8058. }
  8059. var path = prototypeAction && prototypeAction.
  8060. _propertyBindings[ i ].binding.parsedPath;
  8061. binding = new THREE.PropertyMixer(
  8062. THREE.PropertyBinding.create( root, trackName, path ),
  8063. track.ValueTypeName, track.getValueSize() );
  8064. ++ binding.referenceCount;
  8065. this._addInactiveBinding( binding, rootUuid, trackName );
  8066. bindings[ i ] = binding;
  8067. }
  8068. interpolants[ i ].resultBuffer = binding.buffer;
  8069. }
  8070. },
  8071. _activateAction: function( action ) {
  8072. if ( ! this._isActiveAction( action ) ) {
  8073. if ( action._cacheIndex === null ) {
  8074. // this action has been forgotten by the cache, but the user
  8075. // appears to be still using it -> rebind
  8076. var rootUuid = ( action._localRoot || this._root ).uuid,
  8077. clipUuid = action._clip.uuid,
  8078. actionsForClip = this._actionsByClip[ clipUuid ];
  8079. this._bindAction( action,
  8080. actionsForClip && actionsForClip.knownActions[ 0 ] );
  8081. this._addInactiveAction( action, clipUuid, rootUuid );
  8082. }
  8083. var bindings = action._propertyBindings;
  8084. // increment reference counts / sort out state
  8085. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  8086. var binding = bindings[ i ];
  8087. if ( binding.useCount ++ === 0 ) {
  8088. this._lendBinding( binding );
  8089. binding.saveOriginalState();
  8090. }
  8091. }
  8092. this._lendAction( action );
  8093. }
  8094. },
  8095. _deactivateAction: function( action ) {
  8096. if ( this._isActiveAction( action ) ) {
  8097. var bindings = action._propertyBindings;
  8098. // decrement reference counts / sort out state
  8099. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  8100. var binding = bindings[ i ];
  8101. if ( -- binding.useCount === 0 ) {
  8102. binding.restoreOriginalState();
  8103. this._takeBackBinding( binding );
  8104. }
  8105. }
  8106. this._takeBackAction( action );
  8107. }
  8108. },
  8109. // Memory manager
  8110. _initMemoryManager: function() {
  8111. this._actions = []; // 'nActiveActions' followed by inactive ones
  8112. this._nActiveActions = 0;
  8113. this._actionsByClip = {};
  8114. // inside:
  8115. // {
  8116. // knownActions: Array< _Action > - used as prototypes
  8117. // actionByRoot: _Action - lookup
  8118. // }
  8119. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  8120. this._nActiveBindings = 0;
  8121. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  8122. this._controlInterpolants = []; // same game as above
  8123. this._nActiveControlInterpolants = 0;
  8124. var scope = this;
  8125. this.stats = {
  8126. actions: {
  8127. get total() { return scope._actions.length; },
  8128. get inUse() { return scope._nActiveActions; }
  8129. },
  8130. bindings: {
  8131. get total() { return scope._bindings.length; },
  8132. get inUse() { return scope._nActiveBindings; }
  8133. },
  8134. controlInterpolants: {
  8135. get total() { return scope._controlInterpolants.length; },
  8136. get inUse() { return scope._nActiveControlInterpolants; }
  8137. }
  8138. };
  8139. },
  8140. // Memory management for _Action objects
  8141. _isActiveAction: function( action ) {
  8142. var index = action._cacheIndex;
  8143. return index !== null && index < this._nActiveActions;
  8144. },
  8145. _addInactiveAction: function( action, clipUuid, rootUuid ) {
  8146. var actions = this._actions,
  8147. actionsByClip = this._actionsByClip,
  8148. actionsForClip = actionsByClip[ clipUuid ];
  8149. if ( actionsForClip === undefined ) {
  8150. actionsForClip = {
  8151. knownActions: [ action ],
  8152. actionByRoot: {}
  8153. };
  8154. action._byClipCacheIndex = 0;
  8155. actionsByClip[ clipUuid ] = actionsForClip;
  8156. } else {
  8157. var knownActions = actionsForClip.knownActions;
  8158. action._byClipCacheIndex = knownActions.length;
  8159. knownActions.push( action );
  8160. }
  8161. action._cacheIndex = actions.length;
  8162. actions.push( action );
  8163. actionsForClip.actionByRoot[ rootUuid ] = action;
  8164. },
  8165. _removeInactiveAction: function( action ) {
  8166. var actions = this._actions,
  8167. lastInactiveAction = actions[ actions.length - 1 ],
  8168. cacheIndex = action._cacheIndex;
  8169. lastInactiveAction._cacheIndex = cacheIndex;
  8170. actions[ cacheIndex ] = lastInactiveAction;
  8171. actions.pop();
  8172. action._cacheIndex = null;
  8173. var clipUuid = action._clip.uuid,
  8174. actionsByClip = this._actionsByClip,
  8175. actionsForClip = actionsByClip[ clipUuid ],
  8176. knownActionsForClip = actionsForClip.knownActions,
  8177. lastKnownAction =
  8178. knownActionsForClip[ knownActionsForClip.length - 1 ],
  8179. byClipCacheIndex = action._byClipCacheIndex;
  8180. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  8181. knownActionsForClip[ byClipCacheIndex ] = lastKnownAction;
  8182. knownActionsForClip.pop();
  8183. action._byClipCacheIndex = null;
  8184. var actionByRoot = actionsForClip.actionByRoot,
  8185. rootUuid = ( actions._localRoot || this._root ).uuid;
  8186. delete actionByRoot[ rootUuid ];
  8187. if ( knownActionsForClip.length === 0 ) {
  8188. delete actionsByClip[ clipUuid ];
  8189. }
  8190. this._removeInactiveBindingsForAction( action );
  8191. },
  8192. _removeInactiveBindingsForAction: function( action ) {
  8193. var bindings = action._propertyBindings;
  8194. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  8195. var binding = bindings[ i ];
  8196. if ( -- binding.referenceCount === 0 ) {
  8197. this._removeInactiveBinding( binding );
  8198. }
  8199. }
  8200. },
  8201. _lendAction: function( action ) {
  8202. // [ active actions | inactive actions ]
  8203. // [ active actions >| inactive actions ]
  8204. // s a
  8205. // <-swap->
  8206. // a s
  8207. var actions = this._actions,
  8208. prevIndex = action._cacheIndex,
  8209. lastActiveIndex = this._nActiveActions ++,
  8210. firstInactiveAction = actions[ lastActiveIndex ];
  8211. action._cacheIndex = lastActiveIndex;
  8212. actions[ lastActiveIndex ] = action;
  8213. firstInactiveAction._cacheIndex = prevIndex;
  8214. actions[ prevIndex ] = firstInactiveAction;
  8215. },
  8216. _takeBackAction: function( action ) {
  8217. // [ active actions | inactive actions ]
  8218. // [ active actions |< inactive actions ]
  8219. // a s
  8220. // <-swap->
  8221. // s a
  8222. var actions = this._actions,
  8223. prevIndex = action._cacheIndex,
  8224. firstInactiveIndex = -- this._nActiveActions,
  8225. lastActiveAction = actions[ firstInactiveIndex ];
  8226. action._cacheIndex = firstInactiveIndex;
  8227. actions[ firstInactiveIndex ] = action;
  8228. lastActiveAction._cacheIndex = prevIndex;
  8229. actions[ prevIndex ] = lastActiveAction;
  8230. },
  8231. // Memory management for PropertyMixer objects
  8232. _addInactiveBinding: function( binding, rootUuid, trackName ) {
  8233. var bindingsByRoot = this._bindingsByRootAndName,
  8234. bindingByName = bindingsByRoot[ rootUuid ],
  8235. bindings = this._bindings;
  8236. if ( bindingByName === undefined ) {
  8237. bindingByName = {};
  8238. bindingsByRoot[ rootUuid ] = bindingByName;
  8239. }
  8240. bindingByName[ trackName ] = binding;
  8241. binding._cacheIndex = bindings.length;
  8242. bindings.push( binding );
  8243. },
  8244. _removeInactiveBinding: function( binding ) {
  8245. var bindings = this._bindings,
  8246. propBinding = binding.binding,
  8247. rootUuid = propBinding.rootNode.uuid,
  8248. trackName = propBinding.path,
  8249. bindingsByRoot = this._bindingsByRootAndName,
  8250. bindingByName = bindingsByRoot[ rootUuid ],
  8251. lastInactiveBinding = bindings[ bindings.length - 1 ],
  8252. cacheIndex = binding._cacheIndex;
  8253. lastInactiveBinding._cacheIndex = cacheIndex;
  8254. bindings[ cacheIndex ] = lastInactiveBinding;
  8255. bindings.pop();
  8256. delete bindingByName[ trackName ];
  8257. remove_empty_map: {
  8258. for ( var _ in bindingByName ) break remove_empty_map;
  8259. delete bindingsByRoot[ rootUuid ];
  8260. }
  8261. },
  8262. _lendBinding: function( binding ) {
  8263. var bindings = this._bindings,
  8264. prevIndex = binding._cacheIndex,
  8265. lastActiveIndex = this._nActiveBindings ++,
  8266. firstInactiveBinding = bindings[ lastActiveIndex ];
  8267. binding._cacheIndex = lastActiveIndex;
  8268. bindings[ lastActiveIndex ] = binding;
  8269. firstInactiveBinding._cacheIndex = prevIndex;
  8270. bindings[ prevIndex ] = firstInactiveBinding;
  8271. },
  8272. _takeBackBinding: function( binding ) {
  8273. var bindings = this._bindings,
  8274. prevIndex = binding._cacheIndex,
  8275. firstInactiveIndex = -- this._nActiveBindings,
  8276. lastActiveBinding = bindings[ firstInactiveIndex ];
  8277. binding._cacheIndex = firstInactiveIndex;
  8278. bindings[ firstInactiveIndex ] = binding;
  8279. lastActiveBinding._cacheIndex = prevIndex;
  8280. bindings[ prevIndex ] = lastActiveBinding;
  8281. },
  8282. // Memory management of Interpolants for weight and time scale
  8283. _lendControlInterpolant: function() {
  8284. var interpolants = this._controlInterpolants,
  8285. lastActiveIndex = this._nActiveControlInterpolants ++,
  8286. interpolant = interpolants[ lastActiveIndex ];
  8287. if ( interpolant === undefined ) {
  8288. interpolant = new THREE.LinearInterpolant(
  8289. new Float32Array( 2 ), new Float32Array( 2 ),
  8290. 1, this._controlInterpolantsResultBuffer );
  8291. interpolant.__cacheIndex = lastActiveIndex;
  8292. interpolants[ lastActiveIndex ] = interpolant;
  8293. }
  8294. return interpolant;
  8295. },
  8296. _takeBackControlInterpolant: function( interpolant ) {
  8297. var interpolants = this._controlInterpolants,
  8298. prevIndex = interpolant.__cacheIndex,
  8299. firstInactiveIndex = -- this._nActiveControlInterpolants,
  8300. lastActiveInterpolant = interpolants[ firstInactiveIndex ];
  8301. interpolant.__cacheIndex = firstInactiveIndex;
  8302. interpolants[ firstInactiveIndex ] = interpolant;
  8303. lastActiveInterpolant.__cacheIndex = prevIndex;
  8304. interpolants[ prevIndex ] = lastActiveInterpolant;
  8305. },
  8306. _controlInterpolantsResultBuffer: new Float32Array( 1 )
  8307. } );
  8308. // File:src/animation/AnimationObjectGroup.js
  8309. /**
  8310. *
  8311. * A group of objects that receives a shared animation state.
  8312. *
  8313. * Usage:
  8314. *
  8315. * - Add objects you would otherwise pass as 'root' to the
  8316. * constructor or the .clipAction method of AnimationMixer.
  8317. *
  8318. * - Instead pass this object as 'root'.
  8319. *
  8320. * - You can also add and remove objects later when the mixer
  8321. * is running.
  8322. *
  8323. * Note:
  8324. *
  8325. * Objects of this class appear as one object to the mixer,
  8326. * so cache control of the individual objects must be done
  8327. * on the group.
  8328. *
  8329. * Limitation:
  8330. *
  8331. * - The animated properties must be compatible among the
  8332. * all objects in the group.
  8333. *
  8334. * - A single property can either be controlled through a
  8335. * target group or directly, but not both.
  8336. *
  8337. * @author tschw
  8338. */
  8339. THREE.AnimationObjectGroup = function( var_args ) {
  8340. this.uuid = THREE.Math.generateUUID();
  8341. // cached objects followed by the active ones
  8342. this._objects = Array.prototype.slice.call( arguments );
  8343. this.nCachedObjects_ = 0; // threshold
  8344. // note: read by PropertyBinding.Composite
  8345. var indices = {};
  8346. this._indicesByUUID = indices; // for bookkeeping
  8347. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  8348. indices[ arguments[ i ].uuid ] = i;
  8349. }
  8350. this._paths = []; // inside: string
  8351. this._parsedPaths = []; // inside: { we don't care, here }
  8352. this._bindings = []; // inside: Array< PropertyBinding >
  8353. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  8354. var scope = this;
  8355. this.stats = {
  8356. objects: {
  8357. get total() { return scope._objects.length; },
  8358. get inUse() { return this.total - scope.nCachedObjects_; }
  8359. },
  8360. get bindingsPerObject() { return scope._bindings.length; }
  8361. };
  8362. };
  8363. THREE.AnimationObjectGroup.prototype = {
  8364. constructor: THREE.AnimationObjectGroup,
  8365. add: function( var_args ) {
  8366. var objects = this._objects,
  8367. nObjects = objects.length,
  8368. nCachedObjects = this.nCachedObjects_,
  8369. indicesByUUID = this._indicesByUUID,
  8370. paths = this._paths,
  8371. parsedPaths = this._parsedPaths,
  8372. bindings = this._bindings,
  8373. nBindings = bindings.length;
  8374. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  8375. var object = arguments[ i ],
  8376. uuid = object.uuid,
  8377. index = indicesByUUID[ uuid ];
  8378. if ( index === undefined ) {
  8379. // unknown object -> add it to the ACTIVE region
  8380. index = nObjects ++;
  8381. indicesByUUID[ uuid ] = index;
  8382. objects.push( object );
  8383. // accounting is done, now do the same for all bindings
  8384. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8385. bindings[ j ].push(
  8386. new THREE.PropertyBinding(
  8387. object, paths[ j ], parsedPaths[ j ] ) );
  8388. }
  8389. } else if ( index < nCachedObjects ) {
  8390. var knownObject = objects[ index ];
  8391. // move existing object to the ACTIVE region
  8392. var firstActiveIndex = -- nCachedObjects,
  8393. lastCachedObject = objects[ firstActiveIndex ];
  8394. indicesByUUID[ lastCachedObject.uuid ] = index;
  8395. objects[ index ] = lastCachedObject;
  8396. indicesByUUID[ uuid ] = firstActiveIndex;
  8397. objects[ firstActiveIndex ] = object;
  8398. // accounting is done, now do the same for all bindings
  8399. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8400. var bindingsForPath = bindings[ j ],
  8401. lastCached = bindingsForPath[ firstActiveIndex ],
  8402. binding = bindingsForPath[ index ];
  8403. bindingsForPath[ index ] = lastCached;
  8404. if ( binding === undefined ) {
  8405. // since we do not bother to create new bindings
  8406. // for objects that are cached, the binding may
  8407. // or may not exist
  8408. binding = new THREE.PropertyBinding(
  8409. object, paths[ j ], parsedPaths[ j ] );
  8410. }
  8411. bindingsForPath[ firstActiveIndex ] = binding;
  8412. }
  8413. } else if ( objects[ index ] !== knownObject) {
  8414. console.error( "Different objects with the same UUID " +
  8415. "detected. Clean the caches or recreate your " +
  8416. "infrastructure when reloading scenes..." );
  8417. } // else the object is already where we want it to be
  8418. } // for arguments
  8419. this.nCachedObjects_ = nCachedObjects;
  8420. },
  8421. remove: function( var_args ) {
  8422. var objects = this._objects,
  8423. nObjects = objects.length,
  8424. nCachedObjects = this.nCachedObjects_,
  8425. indicesByUUID = this._indicesByUUID,
  8426. bindings = this._bindings,
  8427. nBindings = bindings.length;
  8428. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  8429. var object = arguments[ i ],
  8430. uuid = object.uuid,
  8431. index = indicesByUUID[ uuid ];
  8432. if ( index !== undefined && index >= nCachedObjects ) {
  8433. // move existing object into the CACHED region
  8434. var lastCachedIndex = nCachedObjects ++,
  8435. firstActiveObject = objects[ lastCachedIndex ];
  8436. indicesByUUID[ firstActiveObject.uuid ] = index;
  8437. objects[ index ] = firstActiveObject;
  8438. indicesByUUID[ uuid ] = lastCachedIndex;
  8439. objects[ lastCachedIndex ] = object;
  8440. // accounting is done, now do the same for all bindings
  8441. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8442. var bindingsForPath = bindings[ j ],
  8443. firstActive = bindingsForPath[ lastCachedIndex ],
  8444. binding = bindingsForPath[ index ];
  8445. bindingsForPath[ index ] = firstActive;
  8446. bindingsForPath[ lastCachedIndex ] = binding;
  8447. }
  8448. }
  8449. } // for arguments
  8450. this.nCachedObjects_ = nCachedObjects;
  8451. },
  8452. // remove & forget
  8453. uncache: function( var_args ) {
  8454. var objects = this._objects,
  8455. nObjects = objects.length,
  8456. nCachedObjects = this.nCachedObjects_,
  8457. indicesByUUID = this._indicesByUUID,
  8458. bindings = this._bindings,
  8459. nBindings = bindings.length;
  8460. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  8461. var object = arguments[ i ],
  8462. uuid = object.uuid,
  8463. index = indicesByUUID[ uuid ];
  8464. if ( index !== undefined ) {
  8465. delete indicesByUUID[ uuid ];
  8466. if ( index < nCachedObjects ) {
  8467. // object is cached, shrink the CACHED region
  8468. var firstActiveIndex = -- nCachedObjects,
  8469. lastCachedObject = objects[ firstActiveIndex ],
  8470. lastIndex = -- nObjects,
  8471. lastObject = objects[ lastIndex ];
  8472. // last cached object takes this object's place
  8473. indicesByUUID[ lastCachedObject.uuid ] = index;
  8474. objects[ index ] = lastCachedObject;
  8475. // last object goes to the activated slot and pop
  8476. indicesByUUID[ lastObject.uuid ] = firstActiveIndex;
  8477. objects[ firstActiveIndex ] = lastObject;
  8478. objects.pop();
  8479. // accounting is done, now do the same for all bindings
  8480. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8481. var bindingsForPath = bindings[ j ],
  8482. lastCached = bindingsForPath[ firstActiveIndex ],
  8483. last = bindingsForPath[ lastIndex ];
  8484. bindingsForPath[ index ] = lastCached;
  8485. bindingsForPath[ firstActiveIndex ] = last;
  8486. bindingsForPath.pop();
  8487. }
  8488. } else {
  8489. // object is active, just swap with the last and pop
  8490. var lastIndex = -- nObjects,
  8491. lastObject = objects[ lastIndex ];
  8492. indicesByUUID[ lastObject.uuid ] = index;
  8493. objects[ index ] = lastObject;
  8494. objects.pop();
  8495. // accounting is done, now do the same for all bindings
  8496. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8497. var bindingsForPath = bindings[ j ];
  8498. bindingsForPath[ index ] = bindingsForPath[ lastIndex ];
  8499. bindingsForPath.pop();
  8500. }
  8501. } // cached or active
  8502. } // if object is known
  8503. } // for arguments
  8504. this.nCachedObjects_ = nCachedObjects;
  8505. },
  8506. // Internal interface used by befriended PropertyBinding.Composite:
  8507. subscribe_: function( path, parsedPath ) {
  8508. // returns an array of bindings for the given path that is changed
  8509. // according to the contained objects in the group
  8510. var indicesByPath = this._bindingsIndicesByPath,
  8511. index = indicesByPath[ path ],
  8512. bindings = this._bindings;
  8513. if ( index !== undefined ) return bindings[ index ];
  8514. var paths = this._paths,
  8515. parsedPaths = this._parsedPaths,
  8516. objects = this._objects,
  8517. nObjects = objects.length,
  8518. nCachedObjects = this.nCachedObjects_,
  8519. bindingsForPath = new Array( nObjects );
  8520. index = bindings.length;
  8521. indicesByPath[ path ] = index;
  8522. paths.push( path );
  8523. parsedPaths.push( parsedPath );
  8524. bindings.push( bindingsForPath );
  8525. for ( var i = nCachedObjects,
  8526. n = objects.length; i !== n; ++ i ) {
  8527. var object = objects[ i ];
  8528. bindingsForPath[ i ] =
  8529. new THREE.PropertyBinding( object, path, parsedPath );
  8530. }
  8531. return bindingsForPath;
  8532. },
  8533. unsubscribe_: function( path ) {
  8534. // tells the group to forget about a property path and no longer
  8535. // update the array previously obtained with 'subscribe_'
  8536. var indicesByPath = this._bindingsIndicesByPath,
  8537. index = indicesByPath[ path ];
  8538. if ( index !== undefined ) {
  8539. var paths = this._paths,
  8540. parsedPaths = this._parsedPaths,
  8541. bindings = this._bindings,
  8542. lastBindingsIndex = bindings.length - 1,
  8543. lastBindings = bindings[ lastBindingsIndex ],
  8544. lastBindingsPath = path[ lastBindingsIndex ];
  8545. indicesByPath[ lastBindingsPath ] = index;
  8546. bindings[ index ] = lastBindings;
  8547. bindings.pop();
  8548. parsedPaths[ index ] = parsedPaths[ lastBindingsIndex ];
  8549. parsedPaths.pop();
  8550. paths[ index ] = paths[ lastBindingsIndex ];
  8551. paths.pop();
  8552. }
  8553. }
  8554. };
  8555. // File:src/animation/AnimationUtils.js
  8556. /**
  8557. * @author tschw
  8558. * @author Ben Houston / http://clara.io/
  8559. * @author David Sarno / http://lighthaus.us/
  8560. */
  8561. THREE.AnimationUtils = {
  8562. // same as Array.prototype.slice, but also works on typed arrays
  8563. arraySlice: function( array, from, to ) {
  8564. if ( THREE.AnimationUtils.isTypedArray( array ) ) {
  8565. return new array.constructor( array.subarray( from, to ) );
  8566. }
  8567. return array.slice( from, to );
  8568. },
  8569. // converts an array to a specific type
  8570. convertArray: function( array, type, forceClone ) {
  8571. if ( ! array || // let 'undefined' and 'null' pass
  8572. ! forceClone && array.constructor === type ) return array;
  8573. if ( typeof type.BYTES_PER_ELEMENT === 'number' ) {
  8574. return new type( array ); // create typed array
  8575. }
  8576. return Array.prototype.slice.call( array ); // create Array
  8577. },
  8578. isTypedArray: function( object ) {
  8579. return ArrayBuffer.isView( object ) &&
  8580. ! ( object instanceof DataView );
  8581. },
  8582. // returns an array by which times and values can be sorted
  8583. getKeyframeOrder: function( times ) {
  8584. function compareTime( i, j ) {
  8585. return times[ i ] - times[ j ];
  8586. }
  8587. var n = times.length;
  8588. var result = new Array( n );
  8589. for ( var i = 0; i !== n; ++ i ) result[ i ] = i;
  8590. result.sort( compareTime );
  8591. return result;
  8592. },
  8593. // uses the array previously returned by 'getKeyframeOrder' to sort data
  8594. sortedArray: function( values, stride, order ) {
  8595. var nValues = values.length;
  8596. var result = new values.constructor( nValues );
  8597. for ( var i = 0, dstOffset = 0; dstOffset !== nValues; ++ i ) {
  8598. var srcOffset = order[ i ] * stride;
  8599. for ( var j = 0; j !== stride; ++ j ) {
  8600. result[ dstOffset ++ ] = values[ srcOffset + j ];
  8601. }
  8602. }
  8603. return result;
  8604. },
  8605. // function for parsing AOS keyframe formats
  8606. flattenJSON: function( jsonKeys, times, values, valuePropertyName ) {
  8607. var i = 1, key = jsonKeys[ 0 ];
  8608. while ( key !== undefined && key[ valuePropertyName ] === undefined ) {
  8609. key = jsonKeys[ i ++ ];
  8610. }
  8611. if ( key === undefined ) return; // no data
  8612. var value = key[ valuePropertyName ];
  8613. if ( value === undefined ) return; // no data
  8614. if ( Array.isArray( value ) ) {
  8615. do {
  8616. value = key[ valuePropertyName ];
  8617. if ( value !== undefined ) {
  8618. times.push( key.time );
  8619. values.push.apply( values, value ); // push all elements
  8620. }
  8621. key = jsonKeys[ i ++ ];
  8622. } while ( key !== undefined );
  8623. } else if ( value.toArray !== undefined ) {
  8624. // ...assume THREE.Math-ish
  8625. do {
  8626. value = key[ valuePropertyName ];
  8627. if ( value !== undefined ) {
  8628. times.push( key.time );
  8629. value.toArray( values, values.length );
  8630. }
  8631. key = jsonKeys[ i ++ ];
  8632. } while ( key !== undefined );
  8633. } else {
  8634. // otherwise push as-is
  8635. do {
  8636. value = key[ valuePropertyName ];
  8637. if ( value !== undefined ) {
  8638. times.push( key.time );
  8639. values.push( value );
  8640. }
  8641. key = jsonKeys[ i ++ ];
  8642. } while ( key !== undefined );
  8643. }
  8644. }
  8645. };
  8646. // File:src/animation/KeyframeTrack.js
  8647. /**
  8648. *
  8649. * A timed sequence of keyframes for a specific property.
  8650. *
  8651. *
  8652. * @author Ben Houston / http://clara.io/
  8653. * @author David Sarno / http://lighthaus.us/
  8654. * @author tschw
  8655. */
  8656. THREE.KeyframeTrack = function ( name, times, values, interpolation ) {
  8657. if( name === undefined ) throw new Error( "track name is undefined" );
  8658. if( times === undefined || times.length === 0 ) {
  8659. throw new Error( "no keyframes in track named " + name );
  8660. }
  8661. this.name = name;
  8662. this.times = THREE.AnimationUtils.convertArray( times, this.TimeBufferType );
  8663. this.values = THREE.AnimationUtils.convertArray( values, this.ValueBufferType );
  8664. this.setInterpolation( interpolation || this.DefaultInterpolation );
  8665. this.validate();
  8666. this.optimize();
  8667. };
  8668. THREE.KeyframeTrack.prototype = {
  8669. constructor: THREE.KeyframeTrack,
  8670. TimeBufferType: Float32Array,
  8671. ValueBufferType: Float32Array,
  8672. DefaultInterpolation: THREE.InterpolateLinear,
  8673. InterpolantFactoryMethodDiscrete: function( result ) {
  8674. return new THREE.DiscreteInterpolant(
  8675. this.times, this.values, this.getValueSize(), result );
  8676. },
  8677. InterpolantFactoryMethodLinear: function( result ) {
  8678. return new THREE.LinearInterpolant(
  8679. this.times, this.values, this.getValueSize(), result );
  8680. },
  8681. InterpolantFactoryMethodSmooth: function( result ) {
  8682. return new THREE.CubicInterpolant(
  8683. this.times, this.values, this.getValueSize(), result );
  8684. },
  8685. setInterpolation: function( interpolation ) {
  8686. var factoryMethod;
  8687. switch ( interpolation ) {
  8688. case THREE.InterpolateDiscrete:
  8689. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  8690. break;
  8691. case THREE.InterpolateLinear:
  8692. factoryMethod = this.InterpolantFactoryMethodLinear;
  8693. break;
  8694. case THREE.InterpolateSmooth:
  8695. factoryMethod = this.InterpolantFactoryMethodSmooth;
  8696. break;
  8697. }
  8698. if ( factoryMethod === undefined ) {
  8699. var message = "unsupported interpolation for " +
  8700. this.ValueTypeName + " keyframe track named " + this.name;
  8701. if ( this.createInterpolant === undefined ) {
  8702. // fall back to default, unless the default itself is messed up
  8703. if ( interpolation !== this.DefaultInterpolation ) {
  8704. this.setInterpolation( this.DefaultInterpolation );
  8705. } else {
  8706. throw new Error( message ); // fatal, in this case
  8707. }
  8708. }
  8709. console.warn( message );
  8710. return;
  8711. }
  8712. this.createInterpolant = factoryMethod;
  8713. },
  8714. getInterpolation: function() {
  8715. switch ( this.createInterpolant ) {
  8716. case this.InterpolantFactoryMethodDiscrete:
  8717. return THREE.InterpolateDiscrete;
  8718. case this.InterpolantFactoryMethodLinear:
  8719. return THREE.InterpolateLinear;
  8720. case this.InterpolantFactoryMethodSmooth:
  8721. return THREE.InterpolateSmooth;
  8722. }
  8723. },
  8724. getValueSize: function() {
  8725. return this.values.length / this.times.length;
  8726. },
  8727. // move all keyframes either forwards or backwards in time
  8728. shift: function( timeOffset ) {
  8729. if( timeOffset !== 0.0 ) {
  8730. var times = this.times;
  8731. for( var i = 0, n = times.length; i !== n; ++ i ) {
  8732. times[ i ] += timeOffset;
  8733. }
  8734. }
  8735. return this;
  8736. },
  8737. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  8738. scale: function( timeScale ) {
  8739. if( timeScale !== 1.0 ) {
  8740. var times = this.times;
  8741. for( var i = 0, n = times.length; i !== n; ++ i ) {
  8742. times[ i ] *= timeScale;
  8743. }
  8744. }
  8745. return this;
  8746. },
  8747. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  8748. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  8749. trim: function( startTime, endTime ) {
  8750. var times = this.times,
  8751. nKeys = times.length,
  8752. from = 0,
  8753. to = nKeys - 1;
  8754. while ( from !== nKeys && times[ from ] < startTime ) ++ from;
  8755. while ( to !== -1 && times[ to ] > endTime ) -- to;
  8756. ++ to; // inclusive -> exclusive bound
  8757. if( from !== 0 || to !== nKeys ) {
  8758. // empty tracks are forbidden, so keep at least one keyframe
  8759. if ( from >= to ) to = Math.max( to , 1 ), from = to - 1;
  8760. var stride = this.getValueSize();
  8761. this.times = THREE.AnimationUtils.arraySlice( times, from, to );
  8762. this.values = THREE.AnimationUtils.
  8763. arraySlice( this.values, from * stride, to * stride );
  8764. }
  8765. return this;
  8766. },
  8767. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  8768. validate: function() {
  8769. var valid = true;
  8770. var valueSize = this.getValueSize();
  8771. if ( valueSize - Math.floor( valueSize ) !== 0 ) {
  8772. console.error( "invalid value size in track", this );
  8773. valid = false;
  8774. }
  8775. var times = this.times,
  8776. values = this.values,
  8777. nKeys = times.length;
  8778. if( nKeys === 0 ) {
  8779. console.error( "track is empty", this );
  8780. valid = false;
  8781. }
  8782. var prevTime = null;
  8783. for( var i = 0; i !== nKeys; i ++ ) {
  8784. var currTime = times[ i ];
  8785. if ( typeof currTime === 'number' && isNaN( currTime ) ) {
  8786. console.error( "time is not a valid number", this, i, currTime );
  8787. valid = false;
  8788. break;
  8789. }
  8790. if( prevTime !== null && prevTime > currTime ) {
  8791. console.error( "out of order keys", this, i, currTime, prevTime );
  8792. valid = false;
  8793. break;
  8794. }
  8795. prevTime = currTime;
  8796. }
  8797. if ( values !== undefined ) {
  8798. if ( THREE.AnimationUtils.isTypedArray( values ) ) {
  8799. for ( var i = 0, n = values.length; i !== n; ++ i ) {
  8800. var value = values[ i ];
  8801. if ( isNaN( value ) ) {
  8802. console.error( "value is not a valid number", this, i, value );
  8803. valid = false;
  8804. break;
  8805. }
  8806. }
  8807. }
  8808. }
  8809. return valid;
  8810. },
  8811. // removes equivalent sequential keys as common in morph target sequences
  8812. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  8813. optimize: function() {
  8814. var times = this.times,
  8815. values = this.values,
  8816. stride = this.getValueSize(),
  8817. writeIndex = 1;
  8818. for( var i = 1, n = times.length - 1; i <= n; ++ i ) {
  8819. var keep = false;
  8820. var time = times[ i ];
  8821. var timeNext = times[ i + 1 ];
  8822. // remove adjacent keyframes scheduled at the same time
  8823. if ( time !== timeNext && ( i !== 1 || time !== time[ 0 ] ) ) {
  8824. // remove unnecessary keyframes same as their neighbors
  8825. var offset = i * stride,
  8826. offsetP = offset - stride,
  8827. offsetN = offset + stride;
  8828. for ( var j = 0; j !== stride; ++ j ) {
  8829. var value = values[ offset + j ];
  8830. if ( value !== values[ offsetP + j ] ||
  8831. value !== values[ offsetN + j ] ) {
  8832. keep = true;
  8833. break;
  8834. }
  8835. }
  8836. }
  8837. // in-place compaction
  8838. if ( keep ) {
  8839. if ( i !== writeIndex ) {
  8840. times[ writeIndex ] = times[ i ];
  8841. var readOffset = i * stride,
  8842. writeOffset = writeIndex * stride;
  8843. for ( var j = 0; j !== stride; ++ j ) {
  8844. values[ writeOffset + j ] = values[ readOffset + j ];
  8845. }
  8846. }
  8847. ++ writeIndex;
  8848. }
  8849. }
  8850. if ( writeIndex !== times.length ) {
  8851. this.times = THREE.AnimationUtils.arraySlice( times, 0, writeIndex );
  8852. this.values = THREE.AnimationUtils.arraySlice( values, 0, writeIndex * stride );
  8853. }
  8854. return this;
  8855. }
  8856. };
  8857. // Static methods:
  8858. Object.assign( THREE.KeyframeTrack, {
  8859. // Serialization (in static context, because of constructor invocation
  8860. // and automatic invocation of .toJSON):
  8861. parse: function( json ) {
  8862. if( json.type === undefined ) {
  8863. throw new Error( "track type undefined, can not parse" );
  8864. }
  8865. var trackType = THREE.KeyframeTrack._getTrackTypeForValueTypeName( json.type );
  8866. if ( json.times === undefined ) {
  8867. var times = [], values = [];
  8868. THREE.AnimationUtils.flattenJSON( json.keys, times, values, 'value' );
  8869. json.times = times;
  8870. json.values = values;
  8871. }
  8872. // derived classes can define a static parse method
  8873. if ( trackType.parse !== undefined ) {
  8874. return trackType.parse( json );
  8875. } else {
  8876. // by default, we asssume a constructor compatible with the base
  8877. return new trackType(
  8878. json.name, json.times, json.values, json.interpolation );
  8879. }
  8880. },
  8881. toJSON: function( track ) {
  8882. var trackType = track.constructor;
  8883. var json;
  8884. // derived classes can define a static toJSON method
  8885. if ( trackType.toJSON !== undefined ) {
  8886. json = trackType.toJSON( track );
  8887. } else {
  8888. // by default, we assume the data can be serialized as-is
  8889. json = {
  8890. 'name': track.name,
  8891. 'times': THREE.AnimationUtils.convertArray( track.times, Array ),
  8892. 'values': THREE.AnimationUtils.convertArray( track.values, Array )
  8893. };
  8894. var interpolation = track.getInterpolation();
  8895. if ( interpolation !== track.DefaultInterpolation ) {
  8896. json.interpolation = interpolation;
  8897. }
  8898. }
  8899. json.type = track.ValueTypeName; // mandatory
  8900. return json;
  8901. },
  8902. _getTrackTypeForValueTypeName: function( typeName ) {
  8903. switch( typeName.toLowerCase() ) {
  8904. case "scalar":
  8905. case "double":
  8906. case "float":
  8907. case "number":
  8908. case "integer":
  8909. return THREE.NumberKeyframeTrack;
  8910. case "vector":
  8911. case "vector2":
  8912. case "vector3":
  8913. case "vector4":
  8914. return THREE.VectorKeyframeTrack;
  8915. case "color":
  8916. return THREE.ColorKeyframeTrack;
  8917. case "quaternion":
  8918. return THREE.QuaternionKeyframeTrack;
  8919. case "bool":
  8920. case "boolean":
  8921. return THREE.BooleanKeyframeTrack;
  8922. case "string":
  8923. return THREE.StringKeyframeTrack;
  8924. }
  8925. throw new Error( "Unsupported typeName: " + typeName );
  8926. }
  8927. } );
  8928. // File:src/animation/PropertyBinding.js
  8929. /**
  8930. *
  8931. * A reference to a real property in the scene graph.
  8932. *
  8933. *
  8934. * @author Ben Houston / http://clara.io/
  8935. * @author David Sarno / http://lighthaus.us/
  8936. * @author tschw
  8937. */
  8938. THREE.PropertyBinding = function ( rootNode, path, parsedPath ) {
  8939. this.path = path;
  8940. this.parsedPath = parsedPath ||
  8941. THREE.PropertyBinding.parseTrackName( path );
  8942. this.node = THREE.PropertyBinding.findNode(
  8943. rootNode, this.parsedPath.nodeName ) || rootNode;
  8944. this.rootNode = rootNode;
  8945. };
  8946. THREE.PropertyBinding.prototype = {
  8947. constructor: THREE.PropertyBinding,
  8948. getValue: function getValue_unbound( targetArray, offset ) {
  8949. this.bind();
  8950. this.getValue( targetArray, offset );
  8951. // Note: This class uses a State pattern on a per-method basis:
  8952. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  8953. // prototype version of these methods with one that represents
  8954. // the bound state. When the property is not found, the methods
  8955. // become no-ops.
  8956. },
  8957. setValue: function getValue_unbound( sourceArray, offset ) {
  8958. this.bind();
  8959. this.setValue( sourceArray, offset );
  8960. },
  8961. // create getter / setter pair for a property in the scene graph
  8962. bind: function() {
  8963. var targetObject = this.node,
  8964. parsedPath = this.parsedPath,
  8965. objectName = parsedPath.objectName,
  8966. propertyName = parsedPath.propertyName,
  8967. propertyIndex = parsedPath.propertyIndex;
  8968. if ( ! targetObject ) {
  8969. targetObject = THREE.PropertyBinding.findNode(
  8970. this.rootNode, parsedPath.nodeName ) || this.rootNode;
  8971. this.node = targetObject;
  8972. }
  8973. // set fail state so we can just 'return' on error
  8974. this.getValue = this._getValue_unavailable;
  8975. this.setValue = this._setValue_unavailable;
  8976. // ensure there is a value node
  8977. if ( ! targetObject ) {
  8978. console.error( " trying to update node for track: " + this.path + " but it wasn't found." );
  8979. return;
  8980. }
  8981. if( objectName ) {
  8982. var objectIndex = parsedPath.objectIndex;
  8983. // special cases were we need to reach deeper into the hierarchy to get the face materials....
  8984. switch ( objectName ) {
  8985. case 'materials':
  8986. if( ! targetObject.material ) {
  8987. console.error( ' can not bind to material as node does not have a material', this );
  8988. return;
  8989. }
  8990. if( ! targetObject.material.materials ) {
  8991. console.error( ' can not bind to material.materials as node.material does not have a materials array', this );
  8992. return;
  8993. }
  8994. targetObject = targetObject.material.materials;
  8995. break;
  8996. case 'bones':
  8997. if( ! targetObject.skeleton ) {
  8998. console.error( ' can not bind to bones as node does not have a skeleton', this );
  8999. return;
  9000. }
  9001. // potential future optimization: skip this if propertyIndex is already an integer
  9002. // and convert the integer string to a true integer.
  9003. targetObject = targetObject.skeleton.bones;
  9004. // support resolving morphTarget names into indices.
  9005. for ( var i = 0; i < targetObject.length; i ++ ) {
  9006. if ( targetObject[i].name === objectIndex ) {
  9007. objectIndex = i;
  9008. break;
  9009. }
  9010. }
  9011. break;
  9012. default:
  9013. if ( targetObject[ objectName ] === undefined ) {
  9014. console.error( ' can not bind to objectName of node, undefined', this );
  9015. return;
  9016. }
  9017. targetObject = targetObject[ objectName ];
  9018. }
  9019. if ( objectIndex !== undefined ) {
  9020. if( targetObject[ objectIndex ] === undefined ) {
  9021. console.error( " trying to bind to objectIndex of objectName, but is undefined:", this, targetObject );
  9022. return;
  9023. }
  9024. targetObject = targetObject[ objectIndex ];
  9025. }
  9026. }
  9027. // resolve property
  9028. var nodeProperty = targetObject[ propertyName ];
  9029. if ( ! nodeProperty ) {
  9030. var nodeName = parsedPath.nodeName;
  9031. console.error( " trying to update property for track: " + nodeName +
  9032. '.' + propertyName + " but it wasn't found.", targetObject );
  9033. return;
  9034. }
  9035. // determine versioning scheme
  9036. var versioning = this.Versioning.None;
  9037. if ( targetObject.needsUpdate !== undefined ) { // material
  9038. versioning = this.Versioning.NeedsUpdate;
  9039. this.targetObject = targetObject;
  9040. } else if ( targetObject.matrixWorldNeedsUpdate !== undefined ) { // node transform
  9041. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  9042. this.targetObject = targetObject;
  9043. }
  9044. // determine how the property gets bound
  9045. var bindingType = this.BindingType.Direct;
  9046. if ( propertyIndex !== undefined ) {
  9047. // access a sub element of the property array (only primitives are supported right now)
  9048. if ( propertyName === "morphTargetInfluences" ) {
  9049. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  9050. // support resolving morphTarget names into indices.
  9051. if ( ! targetObject.geometry ) {
  9052. console.error( ' can not bind to morphTargetInfluences becasuse node does not have a geometry', this );
  9053. return;
  9054. }
  9055. if ( ! targetObject.geometry.morphTargets ) {
  9056. console.error( ' can not bind to morphTargetInfluences becasuse node does not have a geometry.morphTargets', this );
  9057. return;
  9058. }
  9059. for ( var i = 0; i < this.node.geometry.morphTargets.length; i ++ ) {
  9060. if ( targetObject.geometry.morphTargets[i].name === propertyIndex ) {
  9061. propertyIndex = i;
  9062. break;
  9063. }
  9064. }
  9065. }
  9066. bindingType = this.BindingType.ArrayElement;
  9067. this.resolvedProperty = nodeProperty;
  9068. this.propertyIndex = propertyIndex;
  9069. } else if ( nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined ) {
  9070. // must use copy for Object3D.Euler/Quaternion
  9071. bindingType = this.BindingType.HasFromToArray;
  9072. this.resolvedProperty = nodeProperty;
  9073. } else if ( nodeProperty.length !== undefined ) {
  9074. bindingType = this.BindingType.EntireArray;
  9075. this.resolvedProperty = nodeProperty;
  9076. } else {
  9077. this.propertyName = propertyName;
  9078. }
  9079. // select getter / setter
  9080. this.getValue = this.GetterByBindingType[ bindingType ];
  9081. this.setValue = this.SetterByBindingTypeAndVersioning[ bindingType ][ versioning ];
  9082. },
  9083. unbind: function() {
  9084. this.node = null;
  9085. // back to the prototype version of getValue / setValue
  9086. // note: avoiding to mutate the shape of 'this' via 'delete'
  9087. this.getValue = this._getValue_unbound;
  9088. this.setValue = this._setValue_unbound;
  9089. }
  9090. };
  9091. Object.assign( THREE.PropertyBinding.prototype, { // prototype, continued
  9092. // these are used to "bind" a nonexistent property
  9093. _getValue_unavailable: function() {},
  9094. _setValue_unavailable: function() {},
  9095. // initial state of these methods that calls 'bind'
  9096. _getValue_unbound: THREE.PropertyBinding.prototype.getValue,
  9097. _setValue_unbound: THREE.PropertyBinding.prototype.setValue,
  9098. BindingType: {
  9099. Direct: 0,
  9100. EntireArray: 1,
  9101. ArrayElement: 2,
  9102. HasFromToArray: 3
  9103. },
  9104. Versioning: {
  9105. None: 0,
  9106. NeedsUpdate: 1,
  9107. MatrixWorldNeedsUpdate: 2
  9108. },
  9109. GetterByBindingType: [
  9110. function getValue_direct( buffer, offset ) {
  9111. buffer[ offset ] = this.node[ this.propertyName ];
  9112. },
  9113. function getValue_array( buffer, offset ) {
  9114. var source = this.resolvedProperty;
  9115. for ( var i = 0, n = source.length; i !== n; ++ i ) {
  9116. buffer[ offset ++ ] = source[ i ];
  9117. }
  9118. },
  9119. function getValue_arrayElement( buffer, offset ) {
  9120. buffer[ offset ] = this.resolvedProperty[ this.propertyIndex ];
  9121. },
  9122. function getValue_toArray( buffer, offset ) {
  9123. this.resolvedProperty.toArray( buffer, offset );
  9124. }
  9125. ],
  9126. SetterByBindingTypeAndVersioning: [
  9127. [
  9128. // Direct
  9129. function setValue_direct( buffer, offset ) {
  9130. this.node[ this.propertyName ] = buffer[ offset ];
  9131. },
  9132. function setValue_direct_setNeedsUpdate( buffer, offset ) {
  9133. this.node[ this.propertyName ] = buffer[ offset ];
  9134. this.targetObject.needsUpdate = true;
  9135. },
  9136. function setValue_direct_setMatrixWorldNeedsUpdate( buffer, offset ) {
  9137. this.node[ this.propertyName ] = buffer[ offset ];
  9138. this.targetObject.matrixWorldNeedsUpdate = true;
  9139. }
  9140. ], [
  9141. // EntireArray
  9142. function setValue_array( buffer, offset ) {
  9143. var dest = this.resolvedProperty;
  9144. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  9145. dest[ i ] = buffer[ offset ++ ];
  9146. }
  9147. },
  9148. function setValue_array_setNeedsUpdate( buffer, offset ) {
  9149. var dest = this.resolvedProperty;
  9150. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  9151. dest[ i ] = buffer[ offset ++ ];
  9152. }
  9153. this.targetObject.needsUpdate = true;
  9154. },
  9155. function setValue_array_setMatrixWorldNeedsUpdate( buffer, offset ) {
  9156. var dest = this.resolvedProperty;
  9157. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  9158. dest[ i ] = buffer[ offset ++ ];
  9159. }
  9160. this.targetObject.matrixWorldNeedsUpdate = true;
  9161. }
  9162. ], [
  9163. // ArrayElement
  9164. function setValue_arrayElement( buffer, offset ) {
  9165. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  9166. },
  9167. function setValue_arrayElement_setNeedsUpdate( buffer, offset ) {
  9168. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  9169. this.targetObject.needsUpdate = true;
  9170. },
  9171. function setValue_arrayElement_setMatrixWorldNeedsUpdate( buffer, offset ) {
  9172. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  9173. this.targetObject.matrixWorldNeedsUpdate = true;
  9174. }
  9175. ], [
  9176. // HasToFromArray
  9177. function setValue_fromArray( buffer, offset ) {
  9178. this.resolvedProperty.fromArray( buffer, offset );
  9179. },
  9180. function setValue_fromArray_setNeedsUpdate( buffer, offset ) {
  9181. this.resolvedProperty.fromArray( buffer, offset );
  9182. this.targetObject.needsUpdate = true;
  9183. },
  9184. function setValue_fromArray_setMatrixWorldNeedsUpdate( buffer, offset ) {
  9185. this.resolvedProperty.fromArray( buffer, offset );
  9186. this.targetObject.matrixWorldNeedsUpdate = true;
  9187. }
  9188. ]
  9189. ]
  9190. } );
  9191. THREE.PropertyBinding.Composite =
  9192. function( targetGroup, path, optionalParsedPath ) {
  9193. var parsedPath = optionalParsedPath ||
  9194. THREE.PropertyBinding.parseTrackName( path );
  9195. this._targetGroup = targetGroup;
  9196. this._bindings = targetGroup.subscribe_( path, parsedPath );
  9197. };
  9198. THREE.PropertyBinding.Composite.prototype = {
  9199. constructor: THREE.PropertyBinding.Composite,
  9200. getValue: function( array, offset ) {
  9201. this.bind(); // bind all binding
  9202. var firstValidIndex = this._targetGroup.nCachedObjects_,
  9203. binding = this._bindings[ firstValidIndex ];
  9204. // and only call .getValue on the first
  9205. if ( binding !== undefined ) binding.getValue( array, offset );
  9206. },
  9207. setValue: function( array, offset ) {
  9208. var bindings = this._bindings;
  9209. for ( var i = this._targetGroup.nCachedObjects_,
  9210. n = bindings.length; i !== n; ++ i ) {
  9211. bindings[ i ].setValue( array, offset );
  9212. }
  9213. },
  9214. bind: function() {
  9215. var bindings = this._bindings;
  9216. for ( var i = this._targetGroup.nCachedObjects_,
  9217. n = bindings.length; i !== n; ++ i ) {
  9218. bindings[ i ].bind();
  9219. }
  9220. },
  9221. unbind: function() {
  9222. var bindings = this._bindings;
  9223. for ( var i = this._targetGroup.nCachedObjects_,
  9224. n = bindings.length; i !== n; ++ i ) {
  9225. bindings[ i ].unbind();
  9226. }
  9227. }
  9228. };
  9229. THREE.PropertyBinding.create = function( root, path, parsedPath ) {
  9230. if ( ! ( root instanceof THREE.AnimationObjectGroup ) ) {
  9231. return new THREE.PropertyBinding( root, path, parsedPath );
  9232. } else {
  9233. return new THREE.PropertyBinding.Composite( root, path, parsedPath );
  9234. }
  9235. };
  9236. THREE.PropertyBinding.parseTrackName = function( trackName ) {
  9237. // matches strings in the form of:
  9238. // nodeName.property
  9239. // nodeName.property[accessor]
  9240. // nodeName.material.property[accessor]
  9241. // uuid.property[accessor]
  9242. // uuid.objectName[objectIndex].propertyName[propertyIndex]
  9243. // parentName/nodeName.property
  9244. // parentName/parentName/nodeName.property[index]
  9245. // .bone[Armature.DEF_cog].position
  9246. // created and tested via https://regex101.com/#javascript
  9247. var re = /^(([\w]+\/)*)([\w-\d]+)?(\.([\w]+)(\[([\w\d\[\]\_.:\- ]+)\])?)?(\.([\w.]+)(\[([\w\d\[\]\_. ]+)\])?)$/;
  9248. var matches = re.exec(trackName);
  9249. if( ! matches ) {
  9250. throw new Error( "cannot parse trackName at all: " + trackName );
  9251. }
  9252. if (matches.index === re.lastIndex) {
  9253. re.lastIndex++;
  9254. }
  9255. var results = {
  9256. // directoryName: matches[1], // (tschw) currently unused
  9257. nodeName: matches[3], // allowed to be null, specified root node.
  9258. objectName: matches[5],
  9259. objectIndex: matches[7],
  9260. propertyName: matches[9],
  9261. propertyIndex: matches[11] // allowed to be null, specifies that the whole property is set.
  9262. };
  9263. if( results.propertyName === null || results.propertyName.length === 0 ) {
  9264. throw new Error( "can not parse propertyName from trackName: " + trackName );
  9265. }
  9266. return results;
  9267. };
  9268. THREE.PropertyBinding.findNode = function( root, nodeName ) {
  9269. if( ! nodeName || nodeName === "" || nodeName === "root" || nodeName === "." || nodeName === -1 || nodeName === root.name || nodeName === root.uuid ) {
  9270. return root;
  9271. }
  9272. // search into skeleton bones.
  9273. if( root.skeleton ) {
  9274. var searchSkeleton = function( skeleton ) {
  9275. for( var i = 0; i < skeleton.bones.length; i ++ ) {
  9276. var bone = skeleton.bones[i];
  9277. if( bone.name === nodeName ) {
  9278. return bone;
  9279. }
  9280. }
  9281. return null;
  9282. };
  9283. var bone = searchSkeleton( root.skeleton );
  9284. if( bone ) {
  9285. return bone;
  9286. }
  9287. }
  9288. // search into node subtree.
  9289. if( root.children ) {
  9290. var searchNodeSubtree = function( children ) {
  9291. for( var i = 0; i < children.length; i ++ ) {
  9292. var childNode = children[i];
  9293. if( childNode.name === nodeName || childNode.uuid === nodeName ) {
  9294. return childNode;
  9295. }
  9296. var result = searchNodeSubtree( childNode.children );
  9297. if( result ) return result;
  9298. }
  9299. return null;
  9300. };
  9301. var subTreeNode = searchNodeSubtree( root.children );
  9302. if( subTreeNode ) {
  9303. return subTreeNode;
  9304. }
  9305. }
  9306. return null;
  9307. };
  9308. // File:src/animation/PropertyMixer.js
  9309. /**
  9310. *
  9311. * Buffered scene graph property that allows weighted accumulation.
  9312. *
  9313. *
  9314. * @author Ben Houston / http://clara.io/
  9315. * @author David Sarno / http://lighthaus.us/
  9316. * @author tschw
  9317. */
  9318. THREE.PropertyMixer = function ( binding, typeName, valueSize ) {
  9319. this.binding = binding;
  9320. this.valueSize = valueSize;
  9321. var bufferType = Float64Array,
  9322. mixFunction;
  9323. switch ( typeName ) {
  9324. case 'quaternion': mixFunction = this._slerp; break;
  9325. case 'string':
  9326. case 'bool':
  9327. bufferType = Array, mixFunction = this._select; break;
  9328. default: mixFunction = this._lerp;
  9329. }
  9330. this.buffer = new bufferType( valueSize * 4 );
  9331. // layout: [ incoming | accu0 | accu1 | orig ]
  9332. //
  9333. // interpolators can use .buffer as their .result
  9334. // the data then goes to 'incoming'
  9335. //
  9336. // 'accu0' and 'accu1' are used frame-interleaved for
  9337. // the cumulative result and are compared to detect
  9338. // changes
  9339. //
  9340. // 'orig' stores the original state of the property
  9341. this._mixBufferRegion = mixFunction;
  9342. this.cumulativeWeight = 0;
  9343. this.useCount = 0;
  9344. this.referenceCount = 0;
  9345. };
  9346. THREE.PropertyMixer.prototype = {
  9347. constructor: THREE.PropertyMixer,
  9348. // accumulate data in the 'incoming' region into 'accu<i>'
  9349. accumulate: function( accuIndex, weight ) {
  9350. // note: happily accumulating nothing when weight = 0, the caller knows
  9351. // the weight and shouldn't have made the call in the first place
  9352. var buffer = this.buffer,
  9353. stride = this.valueSize,
  9354. offset = accuIndex * stride + stride,
  9355. currentWeight = this.cumulativeWeight;
  9356. if ( currentWeight === 0 ) {
  9357. // accuN := incoming * weight
  9358. for ( var i = 0; i !== stride; ++ i ) {
  9359. buffer[ offset + i ] = buffer[ i ];
  9360. }
  9361. currentWeight = weight;
  9362. } else {
  9363. // accuN := accuN + incoming * weight
  9364. currentWeight += weight;
  9365. var mix = weight / currentWeight;
  9366. this._mixBufferRegion( buffer, offset, 0, mix, stride );
  9367. }
  9368. this.cumulativeWeight = currentWeight;
  9369. },
  9370. // apply the state of 'accu<i>' to the binding when accus differ
  9371. apply: function( accuIndex ) {
  9372. var stride = this.valueSize,
  9373. buffer = this.buffer,
  9374. offset = accuIndex * stride + stride,
  9375. weight = this.cumulativeWeight,
  9376. binding = this.binding;
  9377. this.cumulativeWeight = 0;
  9378. if ( weight < 1 ) {
  9379. // accuN := accuN + original * ( 1 - cumulativeWeight )
  9380. var originalValueOffset = stride * 3;
  9381. this._mixBufferRegion(
  9382. buffer, offset, originalValueOffset, 1 - weight, stride );
  9383. }
  9384. for ( var i = stride, e = stride + stride; i !== e; ++ i ) {
  9385. if ( buffer[ i ] !== buffer[ i + stride ] ) {
  9386. // value has changed -> update scene graph
  9387. binding.setValue( buffer, offset );
  9388. break;
  9389. }
  9390. }
  9391. },
  9392. // remember the state of the bound property and copy it to both accus
  9393. saveOriginalState: function() {
  9394. var binding = this.binding;
  9395. var buffer = this.buffer,
  9396. stride = this.valueSize,
  9397. originalValueOffset = stride * 3;
  9398. binding.getValue( buffer, originalValueOffset );
  9399. // accu[0..1] := orig -- initially detect changes against the original
  9400. for ( var i = stride, e = originalValueOffset; i !== e; ++ i ) {
  9401. buffer[ i ] = buffer[ originalValueOffset + ( i % stride ) ];
  9402. }
  9403. this.cumulativeWeight = 0;
  9404. },
  9405. // apply the state previously taken via 'saveOriginalState' to the binding
  9406. restoreOriginalState: function() {
  9407. var originalValueOffset = this.valueSize * 3;
  9408. this.binding.setValue( this.buffer, originalValueOffset );
  9409. },
  9410. // mix functions
  9411. _select: function( buffer, dstOffset, srcOffset, t, stride ) {
  9412. if ( t >= 0.5 ) {
  9413. for ( var i = 0; i !== stride; ++ i ) {
  9414. buffer[ dstOffset + i ] = buffer[ srcOffset + i ];
  9415. }
  9416. }
  9417. },
  9418. _slerp: function( buffer, dstOffset, srcOffset, t, stride ) {
  9419. THREE.Quaternion.slerpFlat( buffer, dstOffset,
  9420. buffer, dstOffset, buffer, srcOffset, t );
  9421. },
  9422. _lerp: function( buffer, dstOffset, srcOffset, t, stride ) {
  9423. var s = 1 - t;
  9424. for ( var i = 0; i !== stride; ++ i ) {
  9425. var j = dstOffset + i;
  9426. buffer[ j ] = buffer[ j ] * s + buffer[ srcOffset + i ] * t;
  9427. }
  9428. }
  9429. };
  9430. // File:src/animation/tracks/BooleanKeyframeTrack.js
  9431. /**
  9432. *
  9433. * A Track of Boolean keyframe values.
  9434. *
  9435. *
  9436. * @author Ben Houston / http://clara.io/
  9437. * @author David Sarno / http://lighthaus.us/
  9438. * @author tschw
  9439. */
  9440. THREE.BooleanKeyframeTrack = function ( name, times, values ) {
  9441. THREE.KeyframeTrack.call( this, name, times, values );
  9442. };
  9443. THREE.BooleanKeyframeTrack.prototype =
  9444. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9445. constructor: THREE.BooleanKeyframeTrack,
  9446. ValueTypeName: 'bool',
  9447. ValueBufferType: Array,
  9448. DefaultInterpolation: THREE.InterpolateDiscrete,
  9449. InterpolantFactoryMethodLinear: undefined,
  9450. InterpolantFactoryMethodSmooth: undefined
  9451. // Note: Actually this track could have a optimized / compressed
  9452. // representation of a single value and a custom interpolant that
  9453. // computes "firstValue ^ isOdd( index )".
  9454. } );
  9455. // File:src/animation/tracks/ColorKeyframeTrack.js
  9456. /**
  9457. *
  9458. * A Track of keyframe values that represent color.
  9459. *
  9460. *
  9461. * @author Ben Houston / http://clara.io/
  9462. * @author David Sarno / http://lighthaus.us/
  9463. * @author tschw
  9464. */
  9465. THREE.ColorKeyframeTrack = function ( name, times, values, interpolation ) {
  9466. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9467. };
  9468. THREE.ColorKeyframeTrack.prototype =
  9469. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9470. constructor: THREE.ColorKeyframeTrack,
  9471. ValueTypeName: 'color'
  9472. // ValueBufferType is inherited
  9473. // DefaultInterpolation is inherited
  9474. // Note: Very basic implementation and nothing special yet.
  9475. // However, this is the place for color space parameterization.
  9476. } );
  9477. // File:src/animation/tracks/NumberKeyframeTrack.js
  9478. /**
  9479. *
  9480. * A Track of numeric keyframe values.
  9481. *
  9482. * @author Ben Houston / http://clara.io/
  9483. * @author David Sarno / http://lighthaus.us/
  9484. * @author tschw
  9485. */
  9486. THREE.NumberKeyframeTrack = function ( name, times, values, interpolation ) {
  9487. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9488. };
  9489. THREE.NumberKeyframeTrack.prototype =
  9490. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9491. constructor: THREE.NumberKeyframeTrack,
  9492. ValueTypeName: 'number',
  9493. // ValueBufferType is inherited
  9494. // DefaultInterpolation is inherited
  9495. } );
  9496. // File:src/animation/tracks/QuaternionKeyframeTrack.js
  9497. /**
  9498. *
  9499. * A Track of quaternion keyframe values.
  9500. *
  9501. * @author Ben Houston / http://clara.io/
  9502. * @author David Sarno / http://lighthaus.us/
  9503. * @author tschw
  9504. */
  9505. THREE.QuaternionKeyframeTrack = function ( name, times, values, interpolation ) {
  9506. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9507. };
  9508. THREE.QuaternionKeyframeTrack.prototype =
  9509. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9510. constructor: THREE.QuaternionKeyframeTrack,
  9511. ValueTypeName: 'quaternion',
  9512. // ValueBufferType is inherited
  9513. DefaultInterpolation: THREE.InterpolateLinear,
  9514. InterpolantFactoryMethodLinear: function( result ) {
  9515. return new THREE.QuaternionLinearInterpolant(
  9516. this.times, this.values, this.getValueSize(), result );
  9517. },
  9518. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  9519. } );
  9520. // File:src/animation/tracks/StringKeyframeTrack.js
  9521. /**
  9522. *
  9523. * A Track that interpolates Strings
  9524. *
  9525. *
  9526. * @author Ben Houston / http://clara.io/
  9527. * @author David Sarno / http://lighthaus.us/
  9528. * @author tschw
  9529. */
  9530. THREE.StringKeyframeTrack = function ( name, times, values, interpolation ) {
  9531. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9532. };
  9533. THREE.StringKeyframeTrack.prototype =
  9534. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9535. constructor: THREE.StringKeyframeTrack,
  9536. ValueTypeName: 'string',
  9537. ValueBufferType: Array,
  9538. DefaultInterpolation: THREE.InterpolateDiscrete,
  9539. InterpolantFactoryMethodLinear: undefined,
  9540. InterpolantFactoryMethodSmooth: undefined
  9541. } );
  9542. // File:src/animation/tracks/VectorKeyframeTrack.js
  9543. /**
  9544. *
  9545. * A Track of vectored keyframe values.
  9546. *
  9547. *
  9548. * @author Ben Houston / http://clara.io/
  9549. * @author David Sarno / http://lighthaus.us/
  9550. * @author tschw
  9551. */
  9552. THREE.VectorKeyframeTrack = function ( name, times, values, interpolation ) {
  9553. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9554. };
  9555. THREE.VectorKeyframeTrack.prototype =
  9556. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9557. constructor: THREE.VectorKeyframeTrack,
  9558. ValueTypeName: 'vector'
  9559. // ValueBufferType is inherited
  9560. // DefaultInterpolation is inherited
  9561. } );
  9562. // File:src/audio/Audio.js
  9563. /**
  9564. * @author mrdoob / http://mrdoob.com/
  9565. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  9566. */
  9567. THREE.Audio = function ( listener ) {
  9568. THREE.Object3D.call( this );
  9569. this.type = 'Audio';
  9570. this.context = listener.context;
  9571. this.source = this.context.createBufferSource();
  9572. this.source.onended = this.onEnded.bind( this );
  9573. this.gain = this.context.createGain();
  9574. this.gain.connect( listener.getInput() );
  9575. this.autoplay = false;
  9576. this.startTime = 0;
  9577. this.playbackRate = 1;
  9578. this.isPlaying = false;
  9579. this.hasPlaybackControl = true;
  9580. this.sourceType = 'empty';
  9581. this.filters = [];
  9582. };
  9583. THREE.Audio.prototype = Object.assign( Object.create( THREE.Object3D.prototype ), {
  9584. constructor: THREE.Audio,
  9585. getOutput: function () {
  9586. return this.gain;
  9587. },
  9588. setNodeSource: function ( audioNode ) {
  9589. this.hasPlaybackControl = false;
  9590. this.sourceType = 'audioNode';
  9591. this.source = audioNode;
  9592. this.connect();
  9593. return this;
  9594. },
  9595. setBuffer: function ( audioBuffer ) {
  9596. this.source.buffer = audioBuffer;
  9597. this.sourceType = 'buffer';
  9598. if ( this.autoplay ) this.play();
  9599. return this;
  9600. },
  9601. play: function () {
  9602. if ( this.isPlaying === true ) {
  9603. console.warn( 'THREE.Audio: Audio is already playing.' );
  9604. return;
  9605. }
  9606. if ( this.hasPlaybackControl === false ) {
  9607. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9608. return;
  9609. }
  9610. var source = this.context.createBufferSource();
  9611. source.buffer = this.source.buffer;
  9612. source.loop = this.source.loop;
  9613. source.onended = this.source.onended;
  9614. source.start( 0, this.startTime );
  9615. source.playbackRate.value = this.playbackRate;
  9616. this.isPlaying = true;
  9617. this.source = source;
  9618. return this.connect();
  9619. },
  9620. pause: function () {
  9621. if ( this.hasPlaybackControl === false ) {
  9622. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9623. return;
  9624. }
  9625. this.source.stop();
  9626. this.startTime = this.context.currentTime;
  9627. return this;
  9628. },
  9629. stop: function () {
  9630. if ( this.hasPlaybackControl === false ) {
  9631. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9632. return;
  9633. }
  9634. this.source.stop();
  9635. this.startTime = 0;
  9636. return this;
  9637. },
  9638. connect: function () {
  9639. if ( this.filters.length > 0 ) {
  9640. this.source.connect( this.filters[ 0 ] );
  9641. for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
  9642. this.filters[ i - 1 ].connect( this.filters[ i ] );
  9643. }
  9644. this.filters[ this.filters.length - 1 ].connect( this.getOutput() );
  9645. } else {
  9646. this.source.connect( this.getOutput() );
  9647. }
  9648. return this;
  9649. },
  9650. disconnect: function () {
  9651. if ( this.filters.length > 0 ) {
  9652. this.source.disconnect( this.filters[ 0 ] );
  9653. for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
  9654. this.filters[ i - 1 ].disconnect( this.filters[ i ] );
  9655. }
  9656. this.filters[ this.filters.length - 1 ].disconnect( this.getOutput() );
  9657. } else {
  9658. this.source.disconnect( this.getOutput() );
  9659. }
  9660. return this;
  9661. },
  9662. getFilters: function () {
  9663. return this.filters;
  9664. },
  9665. setFilters: function ( value ) {
  9666. if ( ! value ) value = [];
  9667. if ( this.isPlaying === true ) {
  9668. this.disconnect();
  9669. this.filters = value;
  9670. this.connect();
  9671. } else {
  9672. this.filters = value;
  9673. }
  9674. return this;
  9675. },
  9676. getFilter: function () {
  9677. return this.getFilters()[ 0 ];
  9678. },
  9679. setFilter: function ( filter ) {
  9680. return this.setFilters( filter ? [ filter ] : [] );
  9681. },
  9682. setPlaybackRate: function ( value ) {
  9683. if ( this.hasPlaybackControl === false ) {
  9684. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9685. return;
  9686. }
  9687. this.playbackRate = value;
  9688. if ( this.isPlaying === true ) {
  9689. this.source.playbackRate.value = this.playbackRate;
  9690. }
  9691. return this;
  9692. },
  9693. getPlaybackRate: function () {
  9694. return this.playbackRate;
  9695. },
  9696. onEnded: function () {
  9697. this.isPlaying = false;
  9698. },
  9699. getLoop: function () {
  9700. if ( this.hasPlaybackControl === false ) {
  9701. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9702. return false;
  9703. }
  9704. return this.source.loop;
  9705. },
  9706. setLoop: function ( value ) {
  9707. if ( this.hasPlaybackControl === false ) {
  9708. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9709. return;
  9710. }
  9711. this.source.loop = value;
  9712. },
  9713. getVolume: function () {
  9714. return this.gain.gain.value;
  9715. },
  9716. setVolume: function ( value ) {
  9717. this.gain.gain.value = value;
  9718. return this;
  9719. }
  9720. } );
  9721. // File:src/audio/AudioAnalyser.js
  9722. /**
  9723. * @author mrdoob / http://mrdoob.com/
  9724. */
  9725. THREE.AudioAnalyser = function ( audio, fftSize ) {
  9726. this.analyser = audio.context.createAnalyser();
  9727. this.analyser.fftSize = fftSize !== undefined ? fftSize : 2048;
  9728. this.data = new Uint8Array( this.analyser.frequencyBinCount );
  9729. audio.getOutput().connect( this.analyser );
  9730. };
  9731. Object.assign( THREE.AudioAnalyser.prototype, {
  9732. getFrequencyData: function () {
  9733. this.analyser.getByteFrequencyData( this.data );
  9734. return this.data;
  9735. },
  9736. getAverageFrequency: function () {
  9737. var value = 0, data = this.getFrequencyData();
  9738. for ( var i = 0; i < data.length; i ++ ) {
  9739. value += data[ i ];
  9740. }
  9741. return value / data.length;
  9742. }
  9743. } );
  9744. // File:src/audio/AudioContext.js
  9745. /**
  9746. * @author mrdoob / http://mrdoob.com/
  9747. */
  9748. Object.defineProperty( THREE, 'AudioContext', {
  9749. get: ( function () {
  9750. var context;
  9751. return function () {
  9752. if ( context === undefined ) {
  9753. context = new ( window.AudioContext || window.webkitAudioContext )();
  9754. }
  9755. return context;
  9756. };
  9757. } )()
  9758. } );
  9759. // File:src/audio/PositionalAudio.js
  9760. /**
  9761. * @author mrdoob / http://mrdoob.com/
  9762. */
  9763. THREE.PositionalAudio = function ( listener ) {
  9764. THREE.Audio.call( this, listener );
  9765. this.panner = this.context.createPanner();
  9766. this.panner.connect( this.gain );
  9767. };
  9768. THREE.PositionalAudio.prototype = Object.assign( Object.create( THREE.Audio.prototype ), {
  9769. constructor: THREE.PositionalAudio,
  9770. getOutput: function () {
  9771. return this.panner;
  9772. },
  9773. getRefDistance: function () {
  9774. return this.panner.refDistance;
  9775. },
  9776. setRefDistance: function ( value ) {
  9777. this.panner.refDistance = value;
  9778. },
  9779. getRolloffFactor: function () {
  9780. return this.panner.rolloffFactor;
  9781. },
  9782. setRolloffFactor: function ( value ) {
  9783. this.panner.rolloffFactor = value;
  9784. },
  9785. getDistanceModel: function () {
  9786. return this.panner.distanceModel;
  9787. },
  9788. setDistanceModel: function ( value ) {
  9789. this.panner.distanceModel = value;
  9790. },
  9791. getMaxDistance: function () {
  9792. return this.panner.maxDistance;
  9793. },
  9794. setMaxDistance: function ( value ) {
  9795. this.panner.maxDistance = value;
  9796. },
  9797. updateMatrixWorld: ( function () {
  9798. var position = new THREE.Vector3();
  9799. return function updateMatrixWorld( force ) {
  9800. THREE.Object3D.prototype.updateMatrixWorld.call( this, force );
  9801. position.setFromMatrixPosition( this.matrixWorld );
  9802. this.panner.setPosition( position.x, position.y, position.z );
  9803. };
  9804. } )()
  9805. } );
  9806. // File:src/audio/AudioListener.js
  9807. /**
  9808. * @author mrdoob / http://mrdoob.com/
  9809. */
  9810. THREE.AudioListener = function () {
  9811. THREE.Object3D.call( this );
  9812. this.type = 'AudioListener';
  9813. this.context = THREE.AudioContext;
  9814. this.gain = this.context.createGain();
  9815. this.gain.connect( this.context.destination );
  9816. this.filter = null;
  9817. };
  9818. THREE.AudioListener.prototype = Object.assign( Object.create( THREE.Object3D.prototype ), {
  9819. constructor: THREE.AudioListener,
  9820. getInput: function () {
  9821. return this.gain;
  9822. },
  9823. removeFilter: function ( ) {
  9824. if ( this.filter !== null ) {
  9825. this.gain.disconnect( this.filter );
  9826. this.filter.disconnect( this.context.destination );
  9827. this.gain.connect( this.context.destination );
  9828. this.filter = null;
  9829. }
  9830. },
  9831. getFilter: function () {
  9832. return this.filter;
  9833. },
  9834. setFilter: function ( value ) {
  9835. if ( this.filter !== null ) {
  9836. this.gain.disconnect( this.filter );
  9837. this.filter.disconnect( this.context.destination );
  9838. } else {
  9839. this.gain.disconnect( this.context.destination );
  9840. }
  9841. this.filter = value;
  9842. this.gain.connect( this.filter );
  9843. this.filter.connect( this.context.destination );
  9844. },
  9845. getMasterVolume: function () {
  9846. return this.gain.gain.value;
  9847. },
  9848. setMasterVolume: function ( value ) {
  9849. this.gain.gain.value = value;
  9850. },
  9851. updateMatrixWorld: ( function () {
  9852. var position = new THREE.Vector3();
  9853. var quaternion = new THREE.Quaternion();
  9854. var scale = new THREE.Vector3();
  9855. var orientation = new THREE.Vector3();
  9856. return function updateMatrixWorld( force ) {
  9857. THREE.Object3D.prototype.updateMatrixWorld.call( this, force );
  9858. var listener = this.context.listener;
  9859. var up = this.up;
  9860. this.matrixWorld.decompose( position, quaternion, scale );
  9861. orientation.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  9862. listener.setPosition( position.x, position.y, position.z );
  9863. listener.setOrientation( orientation.x, orientation.y, orientation.z, up.x, up.y, up.z );
  9864. };
  9865. } )()
  9866. } );
  9867. // File:src/cameras/Camera.js
  9868. /**
  9869. * @author mrdoob / http://mrdoob.com/
  9870. * @author mikael emtinger / http://gomo.se/
  9871. * @author WestLangley / http://github.com/WestLangley
  9872. */
  9873. THREE.Camera = function () {
  9874. THREE.Object3D.call( this );
  9875. this.type = 'Camera';
  9876. this.matrixWorldInverse = new THREE.Matrix4();
  9877. this.projectionMatrix = new THREE.Matrix4();
  9878. };
  9879. THREE.Camera.prototype = Object.create( THREE.Object3D.prototype );
  9880. THREE.Camera.prototype.constructor = THREE.Camera;
  9881. THREE.Camera.prototype.getWorldDirection = function () {
  9882. var quaternion = new THREE.Quaternion();
  9883. return function ( optionalTarget ) {
  9884. var result = optionalTarget || new THREE.Vector3();
  9885. this.getWorldQuaternion( quaternion );
  9886. return result.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  9887. };
  9888. }();
  9889. THREE.Camera.prototype.lookAt = function () {
  9890. // This routine does not support cameras with rotated and/or translated parent(s)
  9891. var m1 = new THREE.Matrix4();
  9892. return function ( vector ) {
  9893. m1.lookAt( this.position, vector, this.up );
  9894. this.quaternion.setFromRotationMatrix( m1 );
  9895. };
  9896. }();
  9897. THREE.Camera.prototype.clone = function () {
  9898. return new this.constructor().copy( this );
  9899. };
  9900. THREE.Camera.prototype.copy = function ( source ) {
  9901. THREE.Object3D.prototype.copy.call( this, source );
  9902. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  9903. this.projectionMatrix.copy( source.projectionMatrix );
  9904. return this;
  9905. };
  9906. // File:src/cameras/CubeCamera.js
  9907. /**
  9908. * Camera for rendering cube maps
  9909. * - renders scene into axis-aligned cube
  9910. *
  9911. * @author alteredq / http://alteredqualia.com/
  9912. */
  9913. THREE.CubeCamera = function ( near, far, cubeResolution ) {
  9914. THREE.Object3D.call( this );
  9915. this.type = 'CubeCamera';
  9916. var fov = 90, aspect = 1;
  9917. var cameraPX = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9918. cameraPX.up.set( 0, - 1, 0 );
  9919. cameraPX.lookAt( new THREE.Vector3( 1, 0, 0 ) );
  9920. this.add( cameraPX );
  9921. var cameraNX = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9922. cameraNX.up.set( 0, - 1, 0 );
  9923. cameraNX.lookAt( new THREE.Vector3( - 1, 0, 0 ) );
  9924. this.add( cameraNX );
  9925. var cameraPY = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9926. cameraPY.up.set( 0, 0, 1 );
  9927. cameraPY.lookAt( new THREE.Vector3( 0, 1, 0 ) );
  9928. this.add( cameraPY );
  9929. var cameraNY = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9930. cameraNY.up.set( 0, 0, - 1 );
  9931. cameraNY.lookAt( new THREE.Vector3( 0, - 1, 0 ) );
  9932. this.add( cameraNY );
  9933. var cameraPZ = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9934. cameraPZ.up.set( 0, - 1, 0 );
  9935. cameraPZ.lookAt( new THREE.Vector3( 0, 0, 1 ) );
  9936. this.add( cameraPZ );
  9937. var cameraNZ = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9938. cameraNZ.up.set( 0, - 1, 0 );
  9939. cameraNZ.lookAt( new THREE.Vector3( 0, 0, - 1 ) );
  9940. this.add( cameraNZ );
  9941. var options = { format: THREE.RGBFormat, magFilter: THREE.LinearFilter, minFilter: THREE.LinearFilter };
  9942. this.renderTarget = new THREE.WebGLRenderTargetCube( cubeResolution, cubeResolution, options );
  9943. this.updateCubeMap = function ( renderer, scene ) {
  9944. if ( this.parent === null ) this.updateMatrixWorld();
  9945. var renderTarget = this.renderTarget;
  9946. var generateMipmaps = renderTarget.texture.generateMipmaps;
  9947. renderTarget.texture.generateMipmaps = false;
  9948. renderTarget.activeCubeFace = 0;
  9949. renderer.render( scene, cameraPX, renderTarget );
  9950. renderTarget.activeCubeFace = 1;
  9951. renderer.render( scene, cameraNX, renderTarget );
  9952. renderTarget.activeCubeFace = 2;
  9953. renderer.render( scene, cameraPY, renderTarget );
  9954. renderTarget.activeCubeFace = 3;
  9955. renderer.render( scene, cameraNY, renderTarget );
  9956. renderTarget.activeCubeFace = 4;
  9957. renderer.render( scene, cameraPZ, renderTarget );
  9958. renderTarget.texture.generateMipmaps = generateMipmaps;
  9959. renderTarget.activeCubeFace = 5;
  9960. renderer.render( scene, cameraNZ, renderTarget );
  9961. renderer.setRenderTarget( null );
  9962. };
  9963. };
  9964. THREE.CubeCamera.prototype = Object.create( THREE.Object3D.prototype );
  9965. THREE.CubeCamera.prototype.constructor = THREE.CubeCamera;
  9966. // File:src/cameras/OrthographicCamera.js
  9967. /**
  9968. * @author alteredq / http://alteredqualia.com/
  9969. */
  9970. THREE.OrthographicCamera = function ( left, right, top, bottom, near, far ) {
  9971. THREE.Camera.call( this );
  9972. this.type = 'OrthographicCamera';
  9973. this.zoom = 1;
  9974. this.left = left;
  9975. this.right = right;
  9976. this.top = top;
  9977. this.bottom = bottom;
  9978. this.near = ( near !== undefined ) ? near : 0.1;
  9979. this.far = ( far !== undefined ) ? far : 2000;
  9980. this.updateProjectionMatrix();
  9981. };
  9982. THREE.OrthographicCamera.prototype = Object.assign( Object.create( THREE.Camera.prototype ), {
  9983. constructor: THREE.OrthographicCamera,
  9984. copy: function ( source ) {
  9985. THREE.Camera.prototype.copy.call( this, source );
  9986. this.left = source.left;
  9987. this.right = source.right;
  9988. this.top = source.top;
  9989. this.bottom = source.bottom;
  9990. this.near = source.near;
  9991. this.far = source.far;
  9992. this.zoom = source.zoom;
  9993. return this;
  9994. },
  9995. updateProjectionMatrix: function () {
  9996. var dx = ( this.right - this.left ) / ( 2 * this.zoom );
  9997. var dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  9998. var cx = ( this.right + this.left ) / 2;
  9999. var cy = ( this.top + this.bottom ) / 2;
  10000. this.projectionMatrix.makeOrthographic( cx - dx, cx + dx, cy + dy, cy - dy, this.near, this.far );
  10001. },
  10002. toJSON: function ( meta ) {
  10003. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  10004. data.object.zoom = this.zoom;
  10005. data.object.left = this.left;
  10006. data.object.right = this.right;
  10007. data.object.top = this.top;
  10008. data.object.bottom = this.bottom;
  10009. data.object.near = this.near;
  10010. data.object.far = this.far;
  10011. return data;
  10012. }
  10013. } );
  10014. // File:src/cameras/PerspectiveCamera.js
  10015. /**
  10016. * @author mrdoob / http://mrdoob.com/
  10017. * @author greggman / http://games.greggman.com/
  10018. * @author zz85 / http://www.lab4games.net/zz85/blog
  10019. * @author tschw
  10020. */
  10021. THREE.PerspectiveCamera = function( fov, aspect, near, far ) {
  10022. THREE.Camera.call( this );
  10023. this.type = 'PerspectiveCamera';
  10024. this.fov = fov !== undefined ? fov : 50;
  10025. this.zoom = 1;
  10026. this.near = near !== undefined ? near : 0.1;
  10027. this.far = far !== undefined ? far : 2000;
  10028. this.focus = 10;
  10029. this.aspect = aspect !== undefined ? aspect : 1;
  10030. this.view = null;
  10031. this.filmGauge = 35; // width of the film (default in millimeters)
  10032. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  10033. this.updateProjectionMatrix();
  10034. };
  10035. THREE.PerspectiveCamera.prototype = Object.assign( Object.create( THREE.Camera.prototype ), {
  10036. constructor: THREE.PerspectiveCamera,
  10037. copy: function ( source ) {
  10038. THREE.Camera.prototype.copy.call( this, source );
  10039. this.fov = source.fov;
  10040. this.zoom = source.zoom;
  10041. this.near = source.near;
  10042. this.far = source.far;
  10043. this.focus = source.focus;
  10044. this.aspect = source.aspect;
  10045. this.view = source.view === null ? null : Object.assign( {}, source.view );
  10046. this.filmGauge = source.filmGauge;
  10047. this.filmOffset = source.filmOffset;
  10048. return this;
  10049. },
  10050. /**
  10051. * Sets the FOV by focal length in respect to the current .filmGauge.
  10052. *
  10053. * The default film gauge is 35, so that the focal length can be specified for
  10054. * a 35mm (full frame) camera.
  10055. *
  10056. * Values for focal length and film gauge must have the same unit.
  10057. */
  10058. setFocalLength: function ( focalLength ) {
  10059. // see http://www.bobatkins.com/photography/technical/field_of_view.html
  10060. var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  10061. this.fov = THREE.Math.RAD2DEG * 2 * Math.atan( vExtentSlope );
  10062. this.updateProjectionMatrix();
  10063. },
  10064. /**
  10065. * Calculates the focal length from the current .fov and .filmGauge.
  10066. */
  10067. getFocalLength: function () {
  10068. var vExtentSlope = Math.tan( THREE.Math.DEG2RAD * 0.5 * this.fov );
  10069. return 0.5 * this.getFilmHeight() / vExtentSlope;
  10070. },
  10071. getEffectiveFOV: function () {
  10072. return THREE.Math.RAD2DEG * 2 * Math.atan(
  10073. Math.tan( THREE.Math.DEG2RAD * 0.5 * this.fov ) / this.zoom );
  10074. },
  10075. getFilmWidth: function () {
  10076. // film not completely covered in portrait format (aspect < 1)
  10077. return this.filmGauge * Math.min( this.aspect, 1 );
  10078. },
  10079. getFilmHeight: function () {
  10080. // film not completely covered in landscape format (aspect > 1)
  10081. return this.filmGauge / Math.max( this.aspect, 1 );
  10082. },
  10083. /**
  10084. * Sets an offset in a larger frustum. This is useful for multi-window or
  10085. * multi-monitor/multi-machine setups.
  10086. *
  10087. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  10088. * the monitors are in grid like this
  10089. *
  10090. * +---+---+---+
  10091. * | A | B | C |
  10092. * +---+---+---+
  10093. * | D | E | F |
  10094. * +---+---+---+
  10095. *
  10096. * then for each monitor you would call it like this
  10097. *
  10098. * var w = 1920;
  10099. * var h = 1080;
  10100. * var fullWidth = w * 3;
  10101. * var fullHeight = h * 2;
  10102. *
  10103. * --A--
  10104. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  10105. * --B--
  10106. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  10107. * --C--
  10108. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  10109. * --D--
  10110. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  10111. * --E--
  10112. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  10113. * --F--
  10114. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  10115. *
  10116. * Note there is no reason monitors have to be the same size or in a grid.
  10117. */
  10118. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  10119. this.aspect = fullWidth / fullHeight;
  10120. this.view = {
  10121. fullWidth: fullWidth,
  10122. fullHeight: fullHeight,
  10123. offsetX: x,
  10124. offsetY: y,
  10125. width: width,
  10126. height: height
  10127. };
  10128. this.updateProjectionMatrix();
  10129. },
  10130. clearViewOffset: function() {
  10131. this.view = null;
  10132. this.updateProjectionMatrix();
  10133. },
  10134. updateProjectionMatrix: function () {
  10135. var near = this.near,
  10136. top = near * Math.tan(
  10137. THREE.Math.DEG2RAD * 0.5 * this.fov ) / this.zoom,
  10138. height = 2 * top,
  10139. width = this.aspect * height,
  10140. left = - 0.5 * width,
  10141. view = this.view;
  10142. if ( view !== null ) {
  10143. var fullWidth = view.fullWidth,
  10144. fullHeight = view.fullHeight;
  10145. left += view.offsetX * width / fullWidth;
  10146. top -= view.offsetY * height / fullHeight;
  10147. width *= view.width / fullWidth;
  10148. height *= view.height / fullHeight;
  10149. }
  10150. var skew = this.filmOffset;
  10151. if ( skew !== 0 ) left += near * skew / this.getFilmWidth();
  10152. this.projectionMatrix.makeFrustum(
  10153. left, left + width, top - height, top, near, this.far );
  10154. },
  10155. toJSON: function ( meta ) {
  10156. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  10157. data.object.fov = this.fov;
  10158. data.object.zoom = this.zoom;
  10159. data.object.near = this.near;
  10160. data.object.far = this.far;
  10161. data.object.focus = this.focus;
  10162. data.object.aspect = this.aspect;
  10163. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  10164. data.object.filmGauge = this.filmGauge;
  10165. data.object.filmOffset = this.filmOffset;
  10166. return data;
  10167. }
  10168. } );
  10169. // File:src/cameras/StereoCamera.js
  10170. /**
  10171. * @author mrdoob / http://mrdoob.com/
  10172. */
  10173. THREE.StereoCamera = function () {
  10174. this.type = 'StereoCamera';
  10175. this.aspect = 1;
  10176. this.cameraL = new THREE.PerspectiveCamera();
  10177. this.cameraL.layers.enable( 1 );
  10178. this.cameraL.matrixAutoUpdate = false;
  10179. this.cameraR = new THREE.PerspectiveCamera();
  10180. this.cameraR.layers.enable( 2 );
  10181. this.cameraR.matrixAutoUpdate = false;
  10182. };
  10183. Object.assign( THREE.StereoCamera.prototype, {
  10184. update: ( function () {
  10185. var focus, fov, aspect, near, far;
  10186. var eyeRight = new THREE.Matrix4();
  10187. var eyeLeft = new THREE.Matrix4();
  10188. return function update ( camera ) {
  10189. var needsUpdate = focus !== camera.focus || fov !== camera.fov ||
  10190. aspect !== camera.aspect * this.aspect || near !== camera.near ||
  10191. far !== camera.far;
  10192. if ( needsUpdate ) {
  10193. focus = camera.focus;
  10194. fov = camera.fov;
  10195. aspect = camera.aspect * this.aspect;
  10196. near = camera.near;
  10197. far = camera.far;
  10198. // Off-axis stereoscopic effect based on
  10199. // http://paulbourke.net/stereographics/stereorender/
  10200. var projectionMatrix = camera.projectionMatrix.clone();
  10201. var eyeSep = 0.064 / 2;
  10202. var eyeSepOnProjection = eyeSep * near / focus;
  10203. var ymax = near * Math.tan( THREE.Math.DEG2RAD * fov * 0.5 );
  10204. var xmin, xmax;
  10205. // translate xOffset
  10206. eyeLeft.elements[ 12 ] = - eyeSep;
  10207. eyeRight.elements[ 12 ] = eyeSep;
  10208. // for left eye
  10209. xmin = - ymax * aspect + eyeSepOnProjection;
  10210. xmax = ymax * aspect + eyeSepOnProjection;
  10211. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  10212. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  10213. this.cameraL.projectionMatrix.copy( projectionMatrix );
  10214. // for right eye
  10215. xmin = - ymax * aspect - eyeSepOnProjection;
  10216. xmax = ymax * aspect - eyeSepOnProjection;
  10217. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  10218. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  10219. this.cameraR.projectionMatrix.copy( projectionMatrix );
  10220. }
  10221. this.cameraL.matrixWorld.copy( camera.matrixWorld ).multiply( eyeLeft );
  10222. this.cameraR.matrixWorld.copy( camera.matrixWorld ).multiply( eyeRight );
  10223. };
  10224. } )()
  10225. } );
  10226. // File:src/lights/Light.js
  10227. /**
  10228. * @author mrdoob / http://mrdoob.com/
  10229. * @author alteredq / http://alteredqualia.com/
  10230. */
  10231. THREE.Light = function ( color, intensity ) {
  10232. THREE.Object3D.call( this );
  10233. this.type = 'Light';
  10234. this.color = new THREE.Color( color );
  10235. this.intensity = intensity !== undefined ? intensity : 1;
  10236. this.receiveShadow = undefined;
  10237. };
  10238. THREE.Light.prototype = Object.assign( Object.create( THREE.Object3D.prototype ), {
  10239. constructor: THREE.Light,
  10240. copy: function ( source ) {
  10241. THREE.Object3D.prototype.copy.call( this, source );
  10242. this.color.copy( source.color );
  10243. this.intensity = source.intensity;
  10244. return this;
  10245. },
  10246. toJSON: function ( meta ) {
  10247. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  10248. data.object.color = this.color.getHex();
  10249. data.object.intensity = this.intensity;
  10250. if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();
  10251. if ( this.distance !== undefined ) data.object.distance = this.distance;
  10252. if ( this.angle !== undefined ) data.object.angle = this.angle;
  10253. if ( this.decay !== undefined ) data.object.decay = this.decay;
  10254. if ( this.penumbra !== undefined ) data.object.penumbra = this.penumbra;
  10255. return data;
  10256. }
  10257. } );
  10258. // File:src/lights/LightShadow.js
  10259. /**
  10260. * @author mrdoob / http://mrdoob.com/
  10261. */
  10262. THREE.LightShadow = function ( camera ) {
  10263. this.camera = camera;
  10264. this.bias = 0;
  10265. this.radius = 1;
  10266. this.mapSize = new THREE.Vector2( 512, 512 );
  10267. this.map = null;
  10268. this.matrix = new THREE.Matrix4();
  10269. };
  10270. Object.assign( THREE.LightShadow.prototype, {
  10271. copy: function ( source ) {
  10272. this.camera = source.camera.clone();
  10273. this.bias = source.bias;
  10274. this.radius = source.radius;
  10275. this.mapSize.copy( source.mapSize );
  10276. return this;
  10277. },
  10278. clone: function () {
  10279. return new this.constructor().copy( this );
  10280. }
  10281. } );
  10282. // File:src/lights/AmbientLight.js
  10283. /**
  10284. * @author mrdoob / http://mrdoob.com/
  10285. */
  10286. THREE.AmbientLight = function ( color, intensity ) {
  10287. THREE.Light.call( this, color, intensity );
  10288. this.type = 'AmbientLight';
  10289. this.castShadow = undefined;
  10290. };
  10291. THREE.AmbientLight.prototype = Object.assign( Object.create( THREE.Light.prototype ), {
  10292. constructor: THREE.AmbientLight
  10293. } );
  10294. // File:src/lights/DirectionalLight.js
  10295. /**
  10296. * @author mrdoob / http://mrdoob.com/
  10297. * @author alteredq / http://alteredqualia.com/
  10298. */
  10299. THREE.DirectionalLight = function ( color, intensity ) {
  10300. THREE.Light.call( this, color, intensity );
  10301. this.type = 'DirectionalLight';
  10302. this.position.set( 0, 1, 0 );
  10303. this.updateMatrix();
  10304. this.target = new THREE.Object3D();
  10305. this.shadow = new THREE.DirectionalLightShadow();
  10306. };
  10307. THREE.DirectionalLight.prototype = Object.assign( Object.create( THREE.Light.prototype ), {
  10308. constructor: THREE.DirectionalLight,
  10309. copy: function ( source ) {
  10310. THREE.Light.prototype.copy.call( this, source );
  10311. this.target = source.target.clone();
  10312. this.shadow = source.shadow.clone();
  10313. return this;
  10314. }
  10315. } );
  10316. // File:src/lights/DirectionalLightShadow.js
  10317. /**
  10318. * @author mrdoob / http://mrdoob.com/
  10319. */
  10320. THREE.DirectionalLightShadow = function ( light ) {
  10321. THREE.LightShadow.call( this, new THREE.OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) );
  10322. };
  10323. THREE.DirectionalLightShadow.prototype = Object.assign( Object.create( THREE.LightShadow.prototype ), {
  10324. constructor: THREE.DirectionalLightShadow
  10325. } );
  10326. // File:src/lights/HemisphereLight.js
  10327. /**
  10328. * @author alteredq / http://alteredqualia.com/
  10329. */
  10330. THREE.HemisphereLight = function ( skyColor, groundColor, intensity ) {
  10331. THREE.Light.call( this, skyColor, intensity );
  10332. this.type = 'HemisphereLight';
  10333. this.castShadow = undefined;
  10334. this.position.set( 0, 1, 0 );
  10335. this.updateMatrix();
  10336. this.groundColor = new THREE.Color( groundColor );
  10337. };
  10338. THREE.HemisphereLight.prototype = Object.assign( Object.create( THREE.Light.prototype ), {
  10339. constructor: THREE.HemisphereLight,
  10340. copy: function ( source ) {
  10341. THREE.Light.prototype.copy.call( this, source );
  10342. this.groundColor.copy( source.groundColor );
  10343. return this;
  10344. }
  10345. } );
  10346. // File:src/lights/PointLight.js
  10347. /**
  10348. * @author mrdoob / http://mrdoob.com/
  10349. */
  10350. THREE.PointLight = function ( color, intensity, distance, decay ) {
  10351. THREE.Light.call( this, color, intensity );
  10352. this.type = 'PointLight';
  10353. Object.defineProperty( this, 'power', {
  10354. get: function () {
  10355. // intensity = power per solid angle.
  10356. // ref: equation (15) from http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
  10357. return this.intensity * 4 * Math.PI;
  10358. },
  10359. set: function ( power ) {
  10360. // intensity = power per solid angle.
  10361. // ref: equation (15) from http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
  10362. this.intensity = power / ( 4 * Math.PI );
  10363. }
  10364. } );
  10365. this.distance = ( distance !== undefined ) ? distance : 0;
  10366. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  10367. this.shadow = new THREE.LightShadow( new THREE.PerspectiveCamera( 90, 1, 0.5, 500 ) );
  10368. };
  10369. THREE.PointLight.prototype = Object.assign( Object.create( THREE.Light.prototype ), {
  10370. constructor: THREE.PointLight,
  10371. copy: function ( source ) {
  10372. THREE.Light.prototype.copy.call( this, source );
  10373. this.distance = source.distance;
  10374. this.decay = source.decay;
  10375. this.shadow = source.shadow.clone();
  10376. return this;
  10377. }
  10378. } );
  10379. // File:src/lights/SpotLight.js
  10380. /**
  10381. * @author alteredq / http://alteredqualia.com/
  10382. */
  10383. THREE.SpotLight = function ( color, intensity, distance, angle, penumbra, decay ) {
  10384. THREE.Light.call( this, color, intensity );
  10385. this.type = 'SpotLight';
  10386. this.position.set( 0, 1, 0 );
  10387. this.updateMatrix();
  10388. this.target = new THREE.Object3D();
  10389. Object.defineProperty( this, 'power', {
  10390. get: function () {
  10391. // intensity = power per solid angle.
  10392. // ref: equation (17) from http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
  10393. return this.intensity * Math.PI;
  10394. },
  10395. set: function ( power ) {
  10396. // intensity = power per solid angle.
  10397. // ref: equation (17) from http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
  10398. this.intensity = power / Math.PI;
  10399. }
  10400. } );
  10401. this.distance = ( distance !== undefined ) ? distance : 0;
  10402. this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
  10403. this.penumbra = ( penumbra !== undefined ) ? penumbra : 0;
  10404. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  10405. this.shadow = new THREE.SpotLightShadow();
  10406. };
  10407. THREE.SpotLight.prototype = Object.assign( Object.create( THREE.Light.prototype ), {
  10408. constructor: THREE.SpotLight,
  10409. copy: function ( source ) {
  10410. THREE.Light.prototype.copy.call( this, source );
  10411. this.distance = source.distance;
  10412. this.angle = source.angle;
  10413. this.penumbra = source.penumbra;
  10414. this.decay = source.decay;
  10415. this.target = source.target.clone();
  10416. this.shadow = source.shadow.clone();
  10417. return this;
  10418. }
  10419. } );
  10420. // File:src/lights/SpotLightShadow.js
  10421. /**
  10422. * @author mrdoob / http://mrdoob.com/
  10423. */
  10424. THREE.SpotLightShadow = function () {
  10425. THREE.LightShadow.call( this, new THREE.PerspectiveCamera( 50, 1, 0.5, 500 ) );
  10426. };
  10427. THREE.SpotLightShadow.prototype = Object.assign( Object.create( THREE.LightShadow.prototype ), {
  10428. constructor: THREE.SpotLightShadow,
  10429. update: function ( light ) {
  10430. var fov = THREE.Math.RAD2DEG * 2 * light.angle;
  10431. var aspect = this.mapSize.width / this.mapSize.height;
  10432. var far = light.distance || 500;
  10433. var camera = this.camera;
  10434. if ( fov !== camera.fov || aspect !== camera.aspect || far !== camera.far ) {
  10435. camera.fov = fov;
  10436. camera.aspect = aspect;
  10437. camera.far = far;
  10438. camera.updateProjectionMatrix();
  10439. }
  10440. }
  10441. } );
  10442. // File:src/loaders/AudioLoader.js
  10443. /**
  10444. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  10445. */
  10446. THREE.AudioLoader = function ( manager ) {
  10447. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10448. };
  10449. THREE.AudioLoader.prototype = {
  10450. constructor: THREE.AudioLoader,
  10451. load: function ( url, onLoad, onProgress, onError ) {
  10452. var loader = new THREE.XHRLoader( this.manager );
  10453. loader.setResponseType( 'arraybuffer' );
  10454. loader.load( url, function ( buffer ) {
  10455. var context = THREE.AudioContext;
  10456. context.decodeAudioData( buffer, function ( audioBuffer ) {
  10457. onLoad( audioBuffer );
  10458. } );
  10459. }, onProgress, onError );
  10460. }
  10461. };
  10462. // File:src/loaders/Cache.js
  10463. /**
  10464. * @author mrdoob / http://mrdoob.com/
  10465. */
  10466. THREE.Cache = {
  10467. enabled: false,
  10468. files: {},
  10469. add: function ( key, file ) {
  10470. if ( this.enabled === false ) return;
  10471. // console.log( 'THREE.Cache', 'Adding key:', key );
  10472. this.files[ key ] = file;
  10473. },
  10474. get: function ( key ) {
  10475. if ( this.enabled === false ) return;
  10476. // console.log( 'THREE.Cache', 'Checking key:', key );
  10477. return this.files[ key ];
  10478. },
  10479. remove: function ( key ) {
  10480. delete this.files[ key ];
  10481. },
  10482. clear: function () {
  10483. this.files = {};
  10484. }
  10485. };
  10486. // File:src/loaders/Loader.js
  10487. /**
  10488. * @author alteredq / http://alteredqualia.com/
  10489. */
  10490. THREE.Loader = function () {
  10491. this.onLoadStart = function () {};
  10492. this.onLoadProgress = function () {};
  10493. this.onLoadComplete = function () {};
  10494. };
  10495. THREE.Loader.prototype = {
  10496. constructor: THREE.Loader,
  10497. crossOrigin: undefined,
  10498. extractUrlBase: function ( url ) {
  10499. var parts = url.split( '/' );
  10500. if ( parts.length === 1 ) return './';
  10501. parts.pop();
  10502. return parts.join( '/' ) + '/';
  10503. },
  10504. initMaterials: function ( materials, texturePath, crossOrigin ) {
  10505. var array = [];
  10506. for ( var i = 0; i < materials.length; ++ i ) {
  10507. array[ i ] = this.createMaterial( materials[ i ], texturePath, crossOrigin );
  10508. }
  10509. return array;
  10510. },
  10511. createMaterial: ( function () {
  10512. var color, textureLoader, materialLoader;
  10513. return function ( m, texturePath, crossOrigin ) {
  10514. if ( color === undefined ) color = new THREE.Color();
  10515. if ( textureLoader === undefined ) textureLoader = new THREE.TextureLoader();
  10516. if ( materialLoader === undefined ) materialLoader = new THREE.MaterialLoader();
  10517. // convert from old material format
  10518. var textures = {};
  10519. function loadTexture( path, repeat, offset, wrap, anisotropy ) {
  10520. var fullPath = texturePath + path;
  10521. var loader = THREE.Loader.Handlers.get( fullPath );
  10522. var texture;
  10523. if ( loader !== null ) {
  10524. texture = loader.load( fullPath );
  10525. } else {
  10526. textureLoader.setCrossOrigin( crossOrigin );
  10527. texture = textureLoader.load( fullPath );
  10528. }
  10529. if ( repeat !== undefined ) {
  10530. texture.repeat.fromArray( repeat );
  10531. if ( repeat[ 0 ] !== 1 ) texture.wrapS = THREE.RepeatWrapping;
  10532. if ( repeat[ 1 ] !== 1 ) texture.wrapT = THREE.RepeatWrapping;
  10533. }
  10534. if ( offset !== undefined ) {
  10535. texture.offset.fromArray( offset );
  10536. }
  10537. if ( wrap !== undefined ) {
  10538. if ( wrap[ 0 ] === 'repeat' ) texture.wrapS = THREE.RepeatWrapping;
  10539. if ( wrap[ 0 ] === 'mirror' ) texture.wrapS = THREE.MirroredRepeatWrapping;
  10540. if ( wrap[ 1 ] === 'repeat' ) texture.wrapT = THREE.RepeatWrapping;
  10541. if ( wrap[ 1 ] === 'mirror' ) texture.wrapT = THREE.MirroredRepeatWrapping;
  10542. }
  10543. if ( anisotropy !== undefined ) {
  10544. texture.anisotropy = anisotropy;
  10545. }
  10546. var uuid = THREE.Math.generateUUID();
  10547. textures[ uuid ] = texture;
  10548. return uuid;
  10549. }
  10550. //
  10551. var json = {
  10552. uuid: THREE.Math.generateUUID(),
  10553. type: 'MeshLambertMaterial'
  10554. };
  10555. for ( var name in m ) {
  10556. var value = m[ name ];
  10557. switch ( name ) {
  10558. case 'DbgColor':
  10559. case 'DbgIndex':
  10560. case 'opticalDensity':
  10561. case 'illumination':
  10562. break;
  10563. case 'DbgName':
  10564. json.name = value;
  10565. break;
  10566. case 'blending':
  10567. json.blending = THREE[ value ];
  10568. break;
  10569. case 'colorAmbient':
  10570. case 'mapAmbient':
  10571. console.warn( 'THREE.Loader.createMaterial:', name, 'is no longer supported.' );
  10572. break;
  10573. case 'colorDiffuse':
  10574. json.color = color.fromArray( value ).getHex();
  10575. break;
  10576. case 'colorSpecular':
  10577. json.specular = color.fromArray( value ).getHex();
  10578. break;
  10579. case 'colorEmissive':
  10580. json.emissive = color.fromArray( value ).getHex();
  10581. break;
  10582. case 'specularCoef':
  10583. json.shininess = value;
  10584. break;
  10585. case 'shading':
  10586. if ( value.toLowerCase() === 'basic' ) json.type = 'MeshBasicMaterial';
  10587. if ( value.toLowerCase() === 'phong' ) json.type = 'MeshPhongMaterial';
  10588. break;
  10589. case 'mapDiffuse':
  10590. json.map = loadTexture( value, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap, m.mapDiffuseAnisotropy );
  10591. break;
  10592. case 'mapDiffuseRepeat':
  10593. case 'mapDiffuseOffset':
  10594. case 'mapDiffuseWrap':
  10595. case 'mapDiffuseAnisotropy':
  10596. break;
  10597. case 'mapLight':
  10598. json.lightMap = loadTexture( value, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap, m.mapLightAnisotropy );
  10599. break;
  10600. case 'mapLightRepeat':
  10601. case 'mapLightOffset':
  10602. case 'mapLightWrap':
  10603. case 'mapLightAnisotropy':
  10604. break;
  10605. case 'mapAO':
  10606. json.aoMap = loadTexture( value, m.mapAORepeat, m.mapAOOffset, m.mapAOWrap, m.mapAOAnisotropy );
  10607. break;
  10608. case 'mapAORepeat':
  10609. case 'mapAOOffset':
  10610. case 'mapAOWrap':
  10611. case 'mapAOAnisotropy':
  10612. break;
  10613. case 'mapBump':
  10614. json.bumpMap = loadTexture( value, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap, m.mapBumpAnisotropy );
  10615. break;
  10616. case 'mapBumpScale':
  10617. json.bumpScale = value;
  10618. break;
  10619. case 'mapBumpRepeat':
  10620. case 'mapBumpOffset':
  10621. case 'mapBumpWrap':
  10622. case 'mapBumpAnisotropy':
  10623. break;
  10624. case 'mapNormal':
  10625. json.normalMap = loadTexture( value, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap, m.mapNormalAnisotropy );
  10626. break;
  10627. case 'mapNormalFactor':
  10628. json.normalScale = [ value, value ];
  10629. break;
  10630. case 'mapNormalRepeat':
  10631. case 'mapNormalOffset':
  10632. case 'mapNormalWrap':
  10633. case 'mapNormalAnisotropy':
  10634. break;
  10635. case 'mapSpecular':
  10636. json.specularMap = loadTexture( value, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap, m.mapSpecularAnisotropy );
  10637. break;
  10638. case 'mapSpecularRepeat':
  10639. case 'mapSpecularOffset':
  10640. case 'mapSpecularWrap':
  10641. case 'mapSpecularAnisotropy':
  10642. break;
  10643. case 'mapAlpha':
  10644. json.alphaMap = loadTexture( value, m.mapAlphaRepeat, m.mapAlphaOffset, m.mapAlphaWrap, m.mapAlphaAnisotropy );
  10645. break;
  10646. case 'mapAlphaRepeat':
  10647. case 'mapAlphaOffset':
  10648. case 'mapAlphaWrap':
  10649. case 'mapAlphaAnisotropy':
  10650. break;
  10651. case 'flipSided':
  10652. json.side = THREE.BackSide;
  10653. break;
  10654. case 'doubleSided':
  10655. json.side = THREE.DoubleSide;
  10656. break;
  10657. case 'transparency':
  10658. console.warn( 'THREE.Loader.createMaterial: transparency has been renamed to opacity' );
  10659. json.opacity = value;
  10660. break;
  10661. case 'depthTest':
  10662. case 'depthWrite':
  10663. case 'colorWrite':
  10664. case 'opacity':
  10665. case 'reflectivity':
  10666. case 'transparent':
  10667. case 'visible':
  10668. case 'wireframe':
  10669. json[ name ] = value;
  10670. break;
  10671. case 'vertexColors':
  10672. if ( value === true ) json.vertexColors = THREE.VertexColors;
  10673. if ( value === 'face' ) json.vertexColors = THREE.FaceColors;
  10674. break;
  10675. default:
  10676. console.error( 'THREE.Loader.createMaterial: Unsupported', name, value );
  10677. break;
  10678. }
  10679. }
  10680. if ( json.type === 'MeshBasicMaterial' ) delete json.emissive;
  10681. if ( json.type !== 'MeshPhongMaterial' ) delete json.specular;
  10682. if ( json.opacity < 1 ) json.transparent = true;
  10683. materialLoader.setTextures( textures );
  10684. return materialLoader.parse( json );
  10685. };
  10686. } )()
  10687. };
  10688. THREE.Loader.Handlers = {
  10689. handlers: [],
  10690. add: function ( regex, loader ) {
  10691. this.handlers.push( regex, loader );
  10692. },
  10693. get: function ( file ) {
  10694. var handlers = this.handlers;
  10695. for ( var i = 0, l = handlers.length; i < l; i += 2 ) {
  10696. var regex = handlers[ i ];
  10697. var loader = handlers[ i + 1 ];
  10698. if ( regex.test( file ) ) {
  10699. return loader;
  10700. }
  10701. }
  10702. return null;
  10703. }
  10704. };
  10705. // File:src/loaders/XHRLoader.js
  10706. /**
  10707. * @author mrdoob / http://mrdoob.com/
  10708. */
  10709. THREE.XHRLoader = function ( manager ) {
  10710. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10711. };
  10712. THREE.XHRLoader.prototype = {
  10713. constructor: THREE.XHRLoader,
  10714. load: function ( url, onLoad, onProgress, onError ) {
  10715. if ( this.path !== undefined ) url = this.path + url;
  10716. var scope = this;
  10717. var cached = THREE.Cache.get( url );
  10718. if ( cached !== undefined ) {
  10719. if ( onLoad ) {
  10720. setTimeout( function () {
  10721. onLoad( cached );
  10722. }, 0 );
  10723. }
  10724. return cached;
  10725. }
  10726. var request = new XMLHttpRequest();
  10727. request.overrideMimeType( 'text/plain' );
  10728. request.open( 'GET', url, true );
  10729. request.addEventListener( 'load', function ( event ) {
  10730. var response = event.target.response;
  10731. THREE.Cache.add( url, response );
  10732. if ( this.status === 200 ) {
  10733. if ( onLoad ) onLoad( response );
  10734. scope.manager.itemEnd( url );
  10735. } else if ( this.status === 0 ) {
  10736. // Some browsers return HTTP Status 0 when using non-http protocol
  10737. // e.g. 'file://' or 'data://'. Handle as success.
  10738. console.warn( 'THREE.XHRLoader: HTTP Status 0 received.' );
  10739. if ( onLoad ) onLoad( response );
  10740. scope.manager.itemEnd( url );
  10741. } else {
  10742. if ( onError ) onError( event );
  10743. scope.manager.itemError( url );
  10744. }
  10745. }, false );
  10746. if ( onProgress !== undefined ) {
  10747. request.addEventListener( 'progress', function ( event ) {
  10748. onProgress( event );
  10749. }, false );
  10750. }
  10751. request.addEventListener( 'error', function ( event ) {
  10752. if ( onError ) onError( event );
  10753. scope.manager.itemError( url );
  10754. }, false );
  10755. if ( this.responseType !== undefined ) request.responseType = this.responseType;
  10756. if ( this.withCredentials !== undefined ) request.withCredentials = this.withCredentials;
  10757. request.send( null );
  10758. scope.manager.itemStart( url );
  10759. return request;
  10760. },
  10761. setPath: function ( value ) {
  10762. this.path = value;
  10763. },
  10764. setResponseType: function ( value ) {
  10765. this.responseType = value;
  10766. },
  10767. setWithCredentials: function ( value ) {
  10768. this.withCredentials = value;
  10769. }
  10770. };
  10771. // File:src/loaders/FontLoader.js
  10772. /**
  10773. * @author mrdoob / http://mrdoob.com/
  10774. */
  10775. THREE.FontLoader = function ( manager ) {
  10776. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10777. };
  10778. THREE.FontLoader.prototype = {
  10779. constructor: THREE.FontLoader,
  10780. load: function ( url, onLoad, onProgress, onError ) {
  10781. var scope = this;
  10782. var loader = new THREE.XHRLoader( this.manager );
  10783. loader.load( url, function ( text ) {
  10784. var json;
  10785. try {
  10786. json = JSON.parse( text );
  10787. } catch ( e ) {
  10788. console.warn( 'THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.' );
  10789. json = JSON.parse( text.substring( 65, text.length - 2 ) );
  10790. }
  10791. var font = scope.parse( json );
  10792. if ( onLoad ) onLoad( font );
  10793. }, onProgress, onError );
  10794. },
  10795. parse: function ( json ) {
  10796. return new THREE.Font( json );
  10797. }
  10798. };
  10799. // File:src/loaders/ImageLoader.js
  10800. /**
  10801. * @author mrdoob / http://mrdoob.com/
  10802. */
  10803. THREE.ImageLoader = function ( manager ) {
  10804. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10805. };
  10806. THREE.ImageLoader.prototype = {
  10807. constructor: THREE.ImageLoader,
  10808. load: function ( url, onLoad, onProgress, onError ) {
  10809. if ( this.path !== undefined ) url = this.path + url;
  10810. var scope = this;
  10811. var cached = THREE.Cache.get( url );
  10812. if ( cached !== undefined ) {
  10813. scope.manager.itemStart( url );
  10814. if ( onLoad ) {
  10815. setTimeout( function () {
  10816. onLoad( cached );
  10817. scope.manager.itemEnd( url );
  10818. }, 0 );
  10819. } else {
  10820. scope.manager.itemEnd( url );
  10821. }
  10822. return cached;
  10823. }
  10824. var image = document.createElement( 'img' );
  10825. image.addEventListener( 'load', function ( event ) {
  10826. THREE.Cache.add( url, this );
  10827. if ( onLoad ) onLoad( this );
  10828. scope.manager.itemEnd( url );
  10829. }, false );
  10830. if ( onProgress !== undefined ) {
  10831. image.addEventListener( 'progress', function ( event ) {
  10832. onProgress( event );
  10833. }, false );
  10834. }
  10835. image.addEventListener( 'error', function ( event ) {
  10836. if ( onError ) onError( event );
  10837. scope.manager.itemError( url );
  10838. }, false );
  10839. if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
  10840. scope.manager.itemStart( url );
  10841. image.src = url;
  10842. return image;
  10843. },
  10844. setCrossOrigin: function ( value ) {
  10845. this.crossOrigin = value;
  10846. },
  10847. setPath: function ( value ) {
  10848. this.path = value;
  10849. }
  10850. };
  10851. // File:src/loaders/JSONLoader.js
  10852. /**
  10853. * @author mrdoob / http://mrdoob.com/
  10854. * @author alteredq / http://alteredqualia.com/
  10855. */
  10856. THREE.JSONLoader = function ( manager ) {
  10857. if ( typeof manager === 'boolean' ) {
  10858. console.warn( 'THREE.JSONLoader: showStatus parameter has been removed from constructor.' );
  10859. manager = undefined;
  10860. }
  10861. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10862. this.withCredentials = false;
  10863. };
  10864. THREE.JSONLoader.prototype = {
  10865. constructor: THREE.JSONLoader,
  10866. // Deprecated
  10867. get statusDomElement () {
  10868. if ( this._statusDomElement === undefined ) {
  10869. this._statusDomElement = document.createElement( 'div' );
  10870. }
  10871. console.warn( 'THREE.JSONLoader: .statusDomElement has been removed.' );
  10872. return this._statusDomElement;
  10873. },
  10874. load: function( url, onLoad, onProgress, onError ) {
  10875. var scope = this;
  10876. var texturePath = this.texturePath && ( typeof this.texturePath === "string" ) ? this.texturePath : THREE.Loader.prototype.extractUrlBase( url );
  10877. var loader = new THREE.XHRLoader( this.manager );
  10878. loader.setWithCredentials( this.withCredentials );
  10879. loader.load( url, function ( text ) {
  10880. var json = JSON.parse( text );
  10881. var metadata = json.metadata;
  10882. if ( metadata !== undefined ) {
  10883. var type = metadata.type;
  10884. if ( type !== undefined ) {
  10885. if ( type.toLowerCase() === 'object' ) {
  10886. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.ObjectLoader instead.' );
  10887. return;
  10888. }
  10889. if ( type.toLowerCase() === 'scene' ) {
  10890. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.SceneLoader instead.' );
  10891. return;
  10892. }
  10893. }
  10894. }
  10895. var object = scope.parse( json, texturePath );
  10896. onLoad( object.geometry, object.materials );
  10897. }, onProgress, onError );
  10898. },
  10899. setTexturePath: function ( value ) {
  10900. this.texturePath = value;
  10901. },
  10902. parse: function ( json, texturePath ) {
  10903. var geometry = new THREE.Geometry(),
  10904. scale = ( json.scale !== undefined ) ? 1.0 / json.scale : 1.0;
  10905. parseModel( scale );
  10906. parseSkin();
  10907. parseMorphing( scale );
  10908. parseAnimations();
  10909. geometry.computeFaceNormals();
  10910. geometry.computeBoundingSphere();
  10911. function parseModel( scale ) {
  10912. function isBitSet( value, position ) {
  10913. return value & ( 1 << position );
  10914. }
  10915. var i, j, fi,
  10916. offset, zLength,
  10917. colorIndex, normalIndex, uvIndex, materialIndex,
  10918. type,
  10919. isQuad,
  10920. hasMaterial,
  10921. hasFaceVertexUv,
  10922. hasFaceNormal, hasFaceVertexNormal,
  10923. hasFaceColor, hasFaceVertexColor,
  10924. vertex, face, faceA, faceB, hex, normal,
  10925. uvLayer, uv, u, v,
  10926. faces = json.faces,
  10927. vertices = json.vertices,
  10928. normals = json.normals,
  10929. colors = json.colors,
  10930. nUvLayers = 0;
  10931. if ( json.uvs !== undefined ) {
  10932. // disregard empty arrays
  10933. for ( i = 0; i < json.uvs.length; i ++ ) {
  10934. if ( json.uvs[ i ].length ) nUvLayers ++;
  10935. }
  10936. for ( i = 0; i < nUvLayers; i ++ ) {
  10937. geometry.faceVertexUvs[ i ] = [];
  10938. }
  10939. }
  10940. offset = 0;
  10941. zLength = vertices.length;
  10942. while ( offset < zLength ) {
  10943. vertex = new THREE.Vector3();
  10944. vertex.x = vertices[ offset ++ ] * scale;
  10945. vertex.y = vertices[ offset ++ ] * scale;
  10946. vertex.z = vertices[ offset ++ ] * scale;
  10947. geometry.vertices.push( vertex );
  10948. }
  10949. offset = 0;
  10950. zLength = faces.length;
  10951. while ( offset < zLength ) {
  10952. type = faces[ offset ++ ];
  10953. isQuad = isBitSet( type, 0 );
  10954. hasMaterial = isBitSet( type, 1 );
  10955. hasFaceVertexUv = isBitSet( type, 3 );
  10956. hasFaceNormal = isBitSet( type, 4 );
  10957. hasFaceVertexNormal = isBitSet( type, 5 );
  10958. hasFaceColor = isBitSet( type, 6 );
  10959. hasFaceVertexColor = isBitSet( type, 7 );
  10960. // console.log("type", type, "bits", isQuad, hasMaterial, hasFaceVertexUv, hasFaceNormal, hasFaceVertexNormal, hasFaceColor, hasFaceVertexColor);
  10961. if ( isQuad ) {
  10962. faceA = new THREE.Face3();
  10963. faceA.a = faces[ offset ];
  10964. faceA.b = faces[ offset + 1 ];
  10965. faceA.c = faces[ offset + 3 ];
  10966. faceB = new THREE.Face3();
  10967. faceB.a = faces[ offset + 1 ];
  10968. faceB.b = faces[ offset + 2 ];
  10969. faceB.c = faces[ offset + 3 ];
  10970. offset += 4;
  10971. if ( hasMaterial ) {
  10972. materialIndex = faces[ offset ++ ];
  10973. faceA.materialIndex = materialIndex;
  10974. faceB.materialIndex = materialIndex;
  10975. }
  10976. // to get face <=> uv index correspondence
  10977. fi = geometry.faces.length;
  10978. if ( hasFaceVertexUv ) {
  10979. for ( i = 0; i < nUvLayers; i ++ ) {
  10980. uvLayer = json.uvs[ i ];
  10981. geometry.faceVertexUvs[ i ][ fi ] = [];
  10982. geometry.faceVertexUvs[ i ][ fi + 1 ] = [];
  10983. for ( j = 0; j < 4; j ++ ) {
  10984. uvIndex = faces[ offset ++ ];
  10985. u = uvLayer[ uvIndex * 2 ];
  10986. v = uvLayer[ uvIndex * 2 + 1 ];
  10987. uv = new THREE.Vector2( u, v );
  10988. if ( j !== 2 ) geometry.faceVertexUvs[ i ][ fi ].push( uv );
  10989. if ( j !== 0 ) geometry.faceVertexUvs[ i ][ fi + 1 ].push( uv );
  10990. }
  10991. }
  10992. }
  10993. if ( hasFaceNormal ) {
  10994. normalIndex = faces[ offset ++ ] * 3;
  10995. faceA.normal.set(
  10996. normals[ normalIndex ++ ],
  10997. normals[ normalIndex ++ ],
  10998. normals[ normalIndex ]
  10999. );
  11000. faceB.normal.copy( faceA.normal );
  11001. }
  11002. if ( hasFaceVertexNormal ) {
  11003. for ( i = 0; i < 4; i ++ ) {
  11004. normalIndex = faces[ offset ++ ] * 3;
  11005. normal = new THREE.Vector3(
  11006. normals[ normalIndex ++ ],
  11007. normals[ normalIndex ++ ],
  11008. normals[ normalIndex ]
  11009. );
  11010. if ( i !== 2 ) faceA.vertexNormals.push( normal );
  11011. if ( i !== 0 ) faceB.vertexNormals.push( normal );
  11012. }
  11013. }
  11014. if ( hasFaceColor ) {
  11015. colorIndex = faces[ offset ++ ];
  11016. hex = colors[ colorIndex ];
  11017. faceA.color.setHex( hex );
  11018. faceB.color.setHex( hex );
  11019. }
  11020. if ( hasFaceVertexColor ) {
  11021. for ( i = 0; i < 4; i ++ ) {
  11022. colorIndex = faces[ offset ++ ];
  11023. hex = colors[ colorIndex ];
  11024. if ( i !== 2 ) faceA.vertexColors.push( new THREE.Color( hex ) );
  11025. if ( i !== 0 ) faceB.vertexColors.push( new THREE.Color( hex ) );
  11026. }
  11027. }
  11028. geometry.faces.push( faceA );
  11029. geometry.faces.push( faceB );
  11030. } else {
  11031. face = new THREE.Face3();
  11032. face.a = faces[ offset ++ ];
  11033. face.b = faces[ offset ++ ];
  11034. face.c = faces[ offset ++ ];
  11035. if ( hasMaterial ) {
  11036. materialIndex = faces[ offset ++ ];
  11037. face.materialIndex = materialIndex;
  11038. }
  11039. // to get face <=> uv index correspondence
  11040. fi = geometry.faces.length;
  11041. if ( hasFaceVertexUv ) {
  11042. for ( i = 0; i < nUvLayers; i ++ ) {
  11043. uvLayer = json.uvs[ i ];
  11044. geometry.faceVertexUvs[ i ][ fi ] = [];
  11045. for ( j = 0; j < 3; j ++ ) {
  11046. uvIndex = faces[ offset ++ ];
  11047. u = uvLayer[ uvIndex * 2 ];
  11048. v = uvLayer[ uvIndex * 2 + 1 ];
  11049. uv = new THREE.Vector2( u, v );
  11050. geometry.faceVertexUvs[ i ][ fi ].push( uv );
  11051. }
  11052. }
  11053. }
  11054. if ( hasFaceNormal ) {
  11055. normalIndex = faces[ offset ++ ] * 3;
  11056. face.normal.set(
  11057. normals[ normalIndex ++ ],
  11058. normals[ normalIndex ++ ],
  11059. normals[ normalIndex ]
  11060. );
  11061. }
  11062. if ( hasFaceVertexNormal ) {
  11063. for ( i = 0; i < 3; i ++ ) {
  11064. normalIndex = faces[ offset ++ ] * 3;
  11065. normal = new THREE.Vector3(
  11066. normals[ normalIndex ++ ],
  11067. normals[ normalIndex ++ ],
  11068. normals[ normalIndex ]
  11069. );
  11070. face.vertexNormals.push( normal );
  11071. }
  11072. }
  11073. if ( hasFaceColor ) {
  11074. colorIndex = faces[ offset ++ ];
  11075. face.color.setHex( colors[ colorIndex ] );
  11076. }
  11077. if ( hasFaceVertexColor ) {
  11078. for ( i = 0; i < 3; i ++ ) {
  11079. colorIndex = faces[ offset ++ ];
  11080. face.vertexColors.push( new THREE.Color( colors[ colorIndex ] ) );
  11081. }
  11082. }
  11083. geometry.faces.push( face );
  11084. }
  11085. }
  11086. }
  11087. function parseSkin() {
  11088. var influencesPerVertex = ( json.influencesPerVertex !== undefined ) ? json.influencesPerVertex : 2;
  11089. if ( json.skinWeights ) {
  11090. for ( var i = 0, l = json.skinWeights.length; i < l; i += influencesPerVertex ) {
  11091. var x = json.skinWeights[ i ];
  11092. var y = ( influencesPerVertex > 1 ) ? json.skinWeights[ i + 1 ] : 0;
  11093. var z = ( influencesPerVertex > 2 ) ? json.skinWeights[ i + 2 ] : 0;
  11094. var w = ( influencesPerVertex > 3 ) ? json.skinWeights[ i + 3 ] : 0;
  11095. geometry.skinWeights.push( new THREE.Vector4( x, y, z, w ) );
  11096. }
  11097. }
  11098. if ( json.skinIndices ) {
  11099. for ( var i = 0, l = json.skinIndices.length; i < l; i += influencesPerVertex ) {
  11100. var a = json.skinIndices[ i ];
  11101. var b = ( influencesPerVertex > 1 ) ? json.skinIndices[ i + 1 ] : 0;
  11102. var c = ( influencesPerVertex > 2 ) ? json.skinIndices[ i + 2 ] : 0;
  11103. var d = ( influencesPerVertex > 3 ) ? json.skinIndices[ i + 3 ] : 0;
  11104. geometry.skinIndices.push( new THREE.Vector4( a, b, c, d ) );
  11105. }
  11106. }
  11107. geometry.bones = json.bones;
  11108. if ( geometry.bones && geometry.bones.length > 0 && ( geometry.skinWeights.length !== geometry.skinIndices.length || geometry.skinIndices.length !== geometry.vertices.length ) ) {
  11109. console.warn( 'When skinning, number of vertices (' + geometry.vertices.length + '), skinIndices (' +
  11110. geometry.skinIndices.length + '), and skinWeights (' + geometry.skinWeights.length + ') should match.' );
  11111. }
  11112. }
  11113. function parseMorphing( scale ) {
  11114. if ( json.morphTargets !== undefined ) {
  11115. for ( var i = 0, l = json.morphTargets.length; i < l; i ++ ) {
  11116. geometry.morphTargets[ i ] = {};
  11117. geometry.morphTargets[ i ].name = json.morphTargets[ i ].name;
  11118. geometry.morphTargets[ i ].vertices = [];
  11119. var dstVertices = geometry.morphTargets[ i ].vertices;
  11120. var srcVertices = json.morphTargets[ i ].vertices;
  11121. for ( var v = 0, vl = srcVertices.length; v < vl; v += 3 ) {
  11122. var vertex = new THREE.Vector3();
  11123. vertex.x = srcVertices[ v ] * scale;
  11124. vertex.y = srcVertices[ v + 1 ] * scale;
  11125. vertex.z = srcVertices[ v + 2 ] * scale;
  11126. dstVertices.push( vertex );
  11127. }
  11128. }
  11129. }
  11130. if ( json.morphColors !== undefined && json.morphColors.length > 0 ) {
  11131. console.warn( 'THREE.JSONLoader: "morphColors" no longer supported. Using them as face colors.' );
  11132. var faces = geometry.faces;
  11133. var morphColors = json.morphColors[ 0 ].colors;
  11134. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  11135. faces[ i ].color.fromArray( morphColors, i * 3 );
  11136. }
  11137. }
  11138. }
  11139. function parseAnimations() {
  11140. var outputAnimations = [];
  11141. // parse old style Bone/Hierarchy animations
  11142. var animations = [];
  11143. if ( json.animation !== undefined ) {
  11144. animations.push( json.animation );
  11145. }
  11146. if ( json.animations !== undefined ) {
  11147. if ( json.animations.length ) {
  11148. animations = animations.concat( json.animations );
  11149. } else {
  11150. animations.push( json.animations );
  11151. }
  11152. }
  11153. for ( var i = 0; i < animations.length; i ++ ) {
  11154. var clip = THREE.AnimationClip.parseAnimation( animations[ i ], geometry.bones );
  11155. if ( clip ) outputAnimations.push( clip );
  11156. }
  11157. // parse implicit morph animations
  11158. if ( geometry.morphTargets ) {
  11159. // TODO: Figure out what an appropraite FPS is for morph target animations -- defaulting to 10, but really it is completely arbitrary.
  11160. var morphAnimationClips = THREE.AnimationClip.CreateClipsFromMorphTargetSequences( geometry.morphTargets, 10 );
  11161. outputAnimations = outputAnimations.concat( morphAnimationClips );
  11162. }
  11163. if ( outputAnimations.length > 0 ) geometry.animations = outputAnimations;
  11164. }
  11165. if ( json.materials === undefined || json.materials.length === 0 ) {
  11166. return { geometry: geometry };
  11167. } else {
  11168. var materials = THREE.Loader.prototype.initMaterials( json.materials, texturePath, this.crossOrigin );
  11169. return { geometry: geometry, materials: materials };
  11170. }
  11171. }
  11172. };
  11173. // File:src/loaders/LoadingManager.js
  11174. /**
  11175. * @author mrdoob / http://mrdoob.com/
  11176. */
  11177. THREE.LoadingManager = function ( onLoad, onProgress, onError ) {
  11178. var scope = this;
  11179. var isLoading = false, itemsLoaded = 0, itemsTotal = 0;
  11180. this.onStart = undefined;
  11181. this.onLoad = onLoad;
  11182. this.onProgress = onProgress;
  11183. this.onError = onError;
  11184. this.itemStart = function ( url ) {
  11185. itemsTotal ++;
  11186. if ( isLoading === false ) {
  11187. if ( scope.onStart !== undefined ) {
  11188. scope.onStart( url, itemsLoaded, itemsTotal );
  11189. }
  11190. }
  11191. isLoading = true;
  11192. };
  11193. this.itemEnd = function ( url ) {
  11194. itemsLoaded ++;
  11195. if ( scope.onProgress !== undefined ) {
  11196. scope.onProgress( url, itemsLoaded, itemsTotal );
  11197. }
  11198. if ( itemsLoaded === itemsTotal ) {
  11199. isLoading = false;
  11200. if ( scope.onLoad !== undefined ) {
  11201. scope.onLoad();
  11202. }
  11203. }
  11204. };
  11205. this.itemError = function ( url ) {
  11206. if ( scope.onError !== undefined ) {
  11207. scope.onError( url );
  11208. }
  11209. };
  11210. };
  11211. THREE.DefaultLoadingManager = new THREE.LoadingManager();
  11212. // File:src/loaders/BufferGeometryLoader.js
  11213. /**
  11214. * @author mrdoob / http://mrdoob.com/
  11215. */
  11216. THREE.BufferGeometryLoader = function ( manager ) {
  11217. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11218. };
  11219. THREE.BufferGeometryLoader.prototype = {
  11220. constructor: THREE.BufferGeometryLoader,
  11221. load: function ( url, onLoad, onProgress, onError ) {
  11222. var scope = this;
  11223. var loader = new THREE.XHRLoader( scope.manager );
  11224. loader.load( url, function ( text ) {
  11225. onLoad( scope.parse( JSON.parse( text ) ) );
  11226. }, onProgress, onError );
  11227. },
  11228. parse: function ( json ) {
  11229. var geometry = new THREE.BufferGeometry();
  11230. var index = json.data.index;
  11231. var TYPED_ARRAYS = {
  11232. 'Int8Array': Int8Array,
  11233. 'Uint8Array': Uint8Array,
  11234. 'Uint8ClampedArray': Uint8ClampedArray,
  11235. 'Int16Array': Int16Array,
  11236. 'Uint16Array': Uint16Array,
  11237. 'Int32Array': Int32Array,
  11238. 'Uint32Array': Uint32Array,
  11239. 'Float32Array': Float32Array,
  11240. 'Float64Array': Float64Array
  11241. };
  11242. if ( index !== undefined ) {
  11243. var typedArray = new TYPED_ARRAYS[ index.type ]( index.array );
  11244. geometry.setIndex( new THREE.BufferAttribute( typedArray, 1 ) );
  11245. }
  11246. var attributes = json.data.attributes;
  11247. for ( var key in attributes ) {
  11248. var attribute = attributes[ key ];
  11249. var typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
  11250. geometry.addAttribute( key, new THREE.BufferAttribute( typedArray, attribute.itemSize, attribute.normalized ) );
  11251. }
  11252. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  11253. if ( groups !== undefined ) {
  11254. for ( var i = 0, n = groups.length; i !== n; ++ i ) {
  11255. var group = groups[ i ];
  11256. geometry.addGroup( group.start, group.count, group.materialIndex );
  11257. }
  11258. }
  11259. var boundingSphere = json.data.boundingSphere;
  11260. if ( boundingSphere !== undefined ) {
  11261. var center = new THREE.Vector3();
  11262. if ( boundingSphere.center !== undefined ) {
  11263. center.fromArray( boundingSphere.center );
  11264. }
  11265. geometry.boundingSphere = new THREE.Sphere( center, boundingSphere.radius );
  11266. }
  11267. return geometry;
  11268. }
  11269. };
  11270. // File:src/loaders/MaterialLoader.js
  11271. /**
  11272. * @author mrdoob / http://mrdoob.com/
  11273. */
  11274. THREE.MaterialLoader = function ( manager ) {
  11275. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11276. this.textures = {};
  11277. };
  11278. THREE.MaterialLoader.prototype = {
  11279. constructor: THREE.MaterialLoader,
  11280. load: function ( url, onLoad, onProgress, onError ) {
  11281. var scope = this;
  11282. var loader = new THREE.XHRLoader( scope.manager );
  11283. loader.load( url, function ( text ) {
  11284. onLoad( scope.parse( JSON.parse( text ) ) );
  11285. }, onProgress, onError );
  11286. },
  11287. setTextures: function ( value ) {
  11288. this.textures = value;
  11289. },
  11290. getTexture: function ( name ) {
  11291. var textures = this.textures;
  11292. if ( textures[ name ] === undefined ) {
  11293. console.warn( 'THREE.MaterialLoader: Undefined texture', name );
  11294. }
  11295. return textures[ name ];
  11296. },
  11297. parse: function ( json ) {
  11298. var material = new THREE[ json.type ];
  11299. if ( json.uuid !== undefined ) material.uuid = json.uuid;
  11300. if ( json.name !== undefined ) material.name = json.name;
  11301. if ( json.color !== undefined ) material.color.setHex( json.color );
  11302. if ( json.roughness !== undefined ) material.roughness = json.roughness;
  11303. if ( json.metalness !== undefined ) material.metalness = json.metalness;
  11304. if ( json.emissive !== undefined ) material.emissive.setHex( json.emissive );
  11305. if ( json.specular !== undefined ) material.specular.setHex( json.specular );
  11306. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  11307. if ( json.uniforms !== undefined ) material.uniforms = json.uniforms;
  11308. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  11309. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  11310. if ( json.vertexColors !== undefined ) material.vertexColors = json.vertexColors;
  11311. if ( json.shading !== undefined ) material.shading = json.shading;
  11312. if ( json.blending !== undefined ) material.blending = json.blending;
  11313. if ( json.side !== undefined ) material.side = json.side;
  11314. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  11315. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  11316. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  11317. if ( json.depthTest !== undefined ) material.depthTest = json.depthTest;
  11318. if ( json.depthWrite !== undefined ) material.depthWrite = json.depthWrite;
  11319. if ( json.colorWrite !== undefined ) material.colorWrite = json.colorWrite;
  11320. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  11321. if ( json.wireframeLinewidth !== undefined ) material.wireframeLinewidth = json.wireframeLinewidth;
  11322. // for PointsMaterial
  11323. if ( json.size !== undefined ) material.size = json.size;
  11324. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  11325. // maps
  11326. if ( json.map !== undefined ) material.map = this.getTexture( json.map );
  11327. if ( json.alphaMap !== undefined ) {
  11328. material.alphaMap = this.getTexture( json.alphaMap );
  11329. material.transparent = true;
  11330. }
  11331. if ( json.bumpMap !== undefined ) material.bumpMap = this.getTexture( json.bumpMap );
  11332. if ( json.bumpScale !== undefined ) material.bumpScale = json.bumpScale;
  11333. if ( json.normalMap !== undefined ) material.normalMap = this.getTexture( json.normalMap );
  11334. if ( json.normalScale !== undefined ) {
  11335. var normalScale = json.normalScale;
  11336. if ( Array.isArray( normalScale ) === false ) {
  11337. // Blender exporter used to export a scalar. See #7459
  11338. normalScale = [ normalScale, normalScale ];
  11339. }
  11340. material.normalScale = new THREE.Vector2().fromArray( normalScale );
  11341. }
  11342. if ( json.displacementMap !== undefined ) material.displacementMap = this.getTexture( json.displacementMap );
  11343. if ( json.displacementScale !== undefined ) material.displacementScale = json.displacementScale;
  11344. if ( json.displacementBias !== undefined ) material.displacementBias = json.displacementBias;
  11345. if ( json.roughnessMap !== undefined ) material.roughnessMap = this.getTexture( json.roughnessMap );
  11346. if ( json.metalnessMap !== undefined ) material.metalnessMap = this.getTexture( json.metalnessMap );
  11347. if ( json.emissiveMap !== undefined ) material.emissiveMap = this.getTexture( json.emissiveMap );
  11348. if ( json.emissiveIntensity !== undefined ) material.emissiveIntensity = json.emissiveIntensity;
  11349. if ( json.specularMap !== undefined ) material.specularMap = this.getTexture( json.specularMap );
  11350. if ( json.envMap !== undefined ) {
  11351. material.envMap = this.getTexture( json.envMap );
  11352. material.combine = THREE.MultiplyOperation;
  11353. }
  11354. if ( json.reflectivity ) material.reflectivity = json.reflectivity;
  11355. if ( json.lightMap !== undefined ) material.lightMap = this.getTexture( json.lightMap );
  11356. if ( json.lightMapIntensity !== undefined ) material.lightMapIntensity = json.lightMapIntensity;
  11357. if ( json.aoMap !== undefined ) material.aoMap = this.getTexture( json.aoMap );
  11358. if ( json.aoMapIntensity !== undefined ) material.aoMapIntensity = json.aoMapIntensity;
  11359. // MultiMaterial
  11360. if ( json.materials !== undefined ) {
  11361. for ( var i = 0, l = json.materials.length; i < l; i ++ ) {
  11362. material.materials.push( this.parse( json.materials[ i ] ) );
  11363. }
  11364. }
  11365. return material;
  11366. }
  11367. };
  11368. // File:src/loaders/ObjectLoader.js
  11369. /**
  11370. * @author mrdoob / http://mrdoob.com/
  11371. */
  11372. THREE.ObjectLoader = function ( manager ) {
  11373. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11374. this.texturePath = '';
  11375. };
  11376. THREE.ObjectLoader.prototype = {
  11377. constructor: THREE.ObjectLoader,
  11378. load: function ( url, onLoad, onProgress, onError ) {
  11379. if ( this.texturePath === '' ) {
  11380. this.texturePath = url.substring( 0, url.lastIndexOf( '/' ) + 1 );
  11381. }
  11382. var scope = this;
  11383. var loader = new THREE.XHRLoader( scope.manager );
  11384. loader.load( url, function ( text ) {
  11385. scope.parse( JSON.parse( text ), onLoad );
  11386. }, onProgress, onError );
  11387. },
  11388. setTexturePath: function ( value ) {
  11389. this.texturePath = value;
  11390. },
  11391. setCrossOrigin: function ( value ) {
  11392. this.crossOrigin = value;
  11393. },
  11394. parse: function ( json, onLoad ) {
  11395. var geometries = this.parseGeometries( json.geometries );
  11396. var images = this.parseImages( json.images, function () {
  11397. if ( onLoad !== undefined ) onLoad( object );
  11398. } );
  11399. var textures = this.parseTextures( json.textures, images );
  11400. var materials = this.parseMaterials( json.materials, textures );
  11401. var object = this.parseObject( json.object, geometries, materials );
  11402. if ( json.animations ) {
  11403. object.animations = this.parseAnimations( json.animations );
  11404. }
  11405. if ( json.images === undefined || json.images.length === 0 ) {
  11406. if ( onLoad !== undefined ) onLoad( object );
  11407. }
  11408. return object;
  11409. },
  11410. parseGeometries: function ( json ) {
  11411. var geometries = {};
  11412. if ( json !== undefined ) {
  11413. var geometryLoader = new THREE.JSONLoader();
  11414. var bufferGeometryLoader = new THREE.BufferGeometryLoader();
  11415. for ( var i = 0, l = json.length; i < l; i ++ ) {
  11416. var geometry;
  11417. var data = json[ i ];
  11418. switch ( data.type ) {
  11419. case 'PlaneGeometry':
  11420. case 'PlaneBufferGeometry':
  11421. geometry = new THREE[ data.type ](
  11422. data.width,
  11423. data.height,
  11424. data.widthSegments,
  11425. data.heightSegments
  11426. );
  11427. break;
  11428. case 'BoxGeometry':
  11429. case 'BoxBufferGeometry':
  11430. case 'CubeGeometry': // backwards compatible
  11431. geometry = new THREE[ data.type ](
  11432. data.width,
  11433. data.height,
  11434. data.depth,
  11435. data.widthSegments,
  11436. data.heightSegments,
  11437. data.depthSegments
  11438. );
  11439. break;
  11440. case 'CircleGeometry':
  11441. case 'CircleBufferGeometry':
  11442. geometry = new THREE[ data.type ](
  11443. data.radius,
  11444. data.segments,
  11445. data.thetaStart,
  11446. data.thetaLength
  11447. );
  11448. break;
  11449. case 'CylinderGeometry':
  11450. case 'CylinderBufferGeometry':
  11451. geometry = new THREE[ data.type ](
  11452. data.radiusTop,
  11453. data.radiusBottom,
  11454. data.height,
  11455. data.radialSegments,
  11456. data.heightSegments,
  11457. data.openEnded,
  11458. data.thetaStart,
  11459. data.thetaLength
  11460. );
  11461. break;
  11462. case 'ConeGeometry':
  11463. case 'ConeBufferGeometry':
  11464. geometry = new THREE [ data.type ](
  11465. data.radius,
  11466. data.height,
  11467. data.radialSegments,
  11468. data.heightSegments,
  11469. data.openEnded,
  11470. data.thetaStart,
  11471. data.thetaLength
  11472. );
  11473. break;
  11474. case 'SphereGeometry':
  11475. case 'SphereBufferGeometry':
  11476. geometry = new THREE[ data.type ](
  11477. data.radius,
  11478. data.widthSegments,
  11479. data.heightSegments,
  11480. data.phiStart,
  11481. data.phiLength,
  11482. data.thetaStart,
  11483. data.thetaLength
  11484. );
  11485. break;
  11486. case 'DodecahedronGeometry':
  11487. case 'IcosahedronGeometry':
  11488. case 'OctahedronGeometry':
  11489. case 'TetrahedronGeometry':
  11490. geometry = new THREE[ data.type ](
  11491. data.radius,
  11492. data.detail
  11493. );
  11494. break;
  11495. case 'RingGeometry':
  11496. case 'RingBufferGeometry':
  11497. geometry = new THREE[ data.type ](
  11498. data.innerRadius,
  11499. data.outerRadius,
  11500. data.thetaSegments,
  11501. data.phiSegments,
  11502. data.thetaStart,
  11503. data.thetaLength
  11504. );
  11505. break;
  11506. case 'TorusGeometry':
  11507. case 'TorusBufferGeometry':
  11508. geometry = new THREE[ data.type ](
  11509. data.radius,
  11510. data.tube,
  11511. data.radialSegments,
  11512. data.tubularSegments,
  11513. data.arc
  11514. );
  11515. break;
  11516. case 'TorusKnotGeometry':
  11517. case 'TorusKnotBufferGeometry':
  11518. geometry = new THREE[ data.type ](
  11519. data.radius,
  11520. data.tube,
  11521. data.tubularSegments,
  11522. data.radialSegments,
  11523. data.p,
  11524. data.q
  11525. );
  11526. break;
  11527. case 'LatheGeometry':
  11528. case 'LatheBufferGeometry':
  11529. geometry = new THREE[ data.type ](
  11530. data.points,
  11531. data.segments,
  11532. data.phiStart,
  11533. data.phiLength
  11534. );
  11535. break;
  11536. case 'BufferGeometry':
  11537. geometry = bufferGeometryLoader.parse( data );
  11538. break;
  11539. case 'Geometry':
  11540. geometry = geometryLoader.parse( data.data, this.texturePath ).geometry;
  11541. break;
  11542. default:
  11543. console.warn( 'THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"' );
  11544. continue;
  11545. }
  11546. geometry.uuid = data.uuid;
  11547. if ( data.name !== undefined ) geometry.name = data.name;
  11548. geometries[ data.uuid ] = geometry;
  11549. }
  11550. }
  11551. return geometries;
  11552. },
  11553. parseMaterials: function ( json, textures ) {
  11554. var materials = {};
  11555. if ( json !== undefined ) {
  11556. var loader = new THREE.MaterialLoader();
  11557. loader.setTextures( textures );
  11558. for ( var i = 0, l = json.length; i < l; i ++ ) {
  11559. var material = loader.parse( json[ i ] );
  11560. materials[ material.uuid ] = material;
  11561. }
  11562. }
  11563. return materials;
  11564. },
  11565. parseAnimations: function ( json ) {
  11566. var animations = [];
  11567. for ( var i = 0; i < json.length; i ++ ) {
  11568. var clip = THREE.AnimationClip.parse( json[ i ] );
  11569. animations.push( clip );
  11570. }
  11571. return animations;
  11572. },
  11573. parseImages: function ( json, onLoad ) {
  11574. var scope = this;
  11575. var images = {};
  11576. function loadImage( url ) {
  11577. scope.manager.itemStart( url );
  11578. return loader.load( url, function () {
  11579. scope.manager.itemEnd( url );
  11580. } );
  11581. }
  11582. if ( json !== undefined && json.length > 0 ) {
  11583. var manager = new THREE.LoadingManager( onLoad );
  11584. var loader = new THREE.ImageLoader( manager );
  11585. loader.setCrossOrigin( this.crossOrigin );
  11586. for ( var i = 0, l = json.length; i < l; i ++ ) {
  11587. var image = json[ i ];
  11588. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( image.url ) ? image.url : scope.texturePath + image.url;
  11589. images[ image.uuid ] = loadImage( path );
  11590. }
  11591. }
  11592. return images;
  11593. },
  11594. parseTextures: function ( json, images ) {
  11595. function parseConstant( value ) {
  11596. if ( typeof( value ) === 'number' ) return value;
  11597. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  11598. return THREE[ value ];
  11599. }
  11600. var textures = {};
  11601. if ( json !== undefined ) {
  11602. for ( var i = 0, l = json.length; i < l; i ++ ) {
  11603. var data = json[ i ];
  11604. if ( data.image === undefined ) {
  11605. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  11606. }
  11607. if ( images[ data.image ] === undefined ) {
  11608. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  11609. }
  11610. var texture = new THREE.Texture( images[ data.image ] );
  11611. texture.needsUpdate = true;
  11612. texture.uuid = data.uuid;
  11613. if ( data.name !== undefined ) texture.name = data.name;
  11614. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping );
  11615. if ( data.offset !== undefined ) texture.offset = new THREE.Vector2( data.offset[ 0 ], data.offset[ 1 ] );
  11616. if ( data.repeat !== undefined ) texture.repeat = new THREE.Vector2( data.repeat[ 0 ], data.repeat[ 1 ] );
  11617. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter );
  11618. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter );
  11619. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  11620. if ( Array.isArray( data.wrap ) ) {
  11621. texture.wrapS = parseConstant( data.wrap[ 0 ] );
  11622. texture.wrapT = parseConstant( data.wrap[ 1 ] );
  11623. }
  11624. textures[ data.uuid ] = texture;
  11625. }
  11626. }
  11627. return textures;
  11628. },
  11629. parseObject: function () {
  11630. var matrix = new THREE.Matrix4();
  11631. return function ( data, geometries, materials ) {
  11632. var object;
  11633. function getGeometry( name ) {
  11634. if ( geometries[ name ] === undefined ) {
  11635. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  11636. }
  11637. return geometries[ name ];
  11638. }
  11639. function getMaterial( name ) {
  11640. if ( name === undefined ) return undefined;
  11641. if ( materials[ name ] === undefined ) {
  11642. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  11643. }
  11644. return materials[ name ];
  11645. }
  11646. switch ( data.type ) {
  11647. case 'Scene':
  11648. object = new THREE.Scene();
  11649. break;
  11650. case 'PerspectiveCamera':
  11651. object = new THREE.PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  11652. if ( data.focus !== undefined ) object.focus = data.focus;
  11653. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  11654. if ( data.filmGauge !== undefined ) object.filmGauge = data.filmGauge;
  11655. if ( data.filmOffset !== undefined ) object.filmOffset = data.filmOffset;
  11656. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  11657. break;
  11658. case 'OrthographicCamera':
  11659. object = new THREE.OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  11660. break;
  11661. case 'AmbientLight':
  11662. object = new THREE.AmbientLight( data.color, data.intensity );
  11663. break;
  11664. case 'DirectionalLight':
  11665. object = new THREE.DirectionalLight( data.color, data.intensity );
  11666. break;
  11667. case 'PointLight':
  11668. object = new THREE.PointLight( data.color, data.intensity, data.distance, data.decay );
  11669. break;
  11670. case 'SpotLight':
  11671. object = new THREE.SpotLight( data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay );
  11672. break;
  11673. case 'HemisphereLight':
  11674. object = new THREE.HemisphereLight( data.color, data.groundColor, data.intensity );
  11675. break;
  11676. case 'Mesh':
  11677. var geometry = getGeometry( data.geometry );
  11678. var material = getMaterial( data.material );
  11679. if ( geometry.bones && geometry.bones.length > 0 ) {
  11680. object = new THREE.SkinnedMesh( geometry, material );
  11681. } else {
  11682. object = new THREE.Mesh( geometry, material );
  11683. }
  11684. break;
  11685. case 'LOD':
  11686. object = new THREE.LOD();
  11687. break;
  11688. case 'Line':
  11689. object = new THREE.Line( getGeometry( data.geometry ), getMaterial( data.material ), data.mode );
  11690. break;
  11691. case 'PointCloud':
  11692. case 'Points':
  11693. object = new THREE.Points( getGeometry( data.geometry ), getMaterial( data.material ) );
  11694. break;
  11695. case 'Sprite':
  11696. object = new THREE.Sprite( getMaterial( data.material ) );
  11697. break;
  11698. case 'Group':
  11699. object = new THREE.Group();
  11700. break;
  11701. default:
  11702. object = new THREE.Object3D();
  11703. }
  11704. object.uuid = data.uuid;
  11705. if ( data.name !== undefined ) object.name = data.name;
  11706. if ( data.matrix !== undefined ) {
  11707. matrix.fromArray( data.matrix );
  11708. matrix.decompose( object.position, object.quaternion, object.scale );
  11709. } else {
  11710. if ( data.position !== undefined ) object.position.fromArray( data.position );
  11711. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  11712. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  11713. }
  11714. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  11715. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  11716. if ( data.visible !== undefined ) object.visible = data.visible;
  11717. if ( data.userData !== undefined ) object.userData = data.userData;
  11718. if ( data.children !== undefined ) {
  11719. for ( var child in data.children ) {
  11720. object.add( this.parseObject( data.children[ child ], geometries, materials ) );
  11721. }
  11722. }
  11723. if ( data.type === 'LOD' ) {
  11724. var levels = data.levels;
  11725. for ( var l = 0; l < levels.length; l ++ ) {
  11726. var level = levels[ l ];
  11727. var child = object.getObjectByProperty( 'uuid', level.object );
  11728. if ( child !== undefined ) {
  11729. object.addLevel( child, level.distance );
  11730. }
  11731. }
  11732. }
  11733. return object;
  11734. };
  11735. }()
  11736. };
  11737. // File:src/loaders/TextureLoader.js
  11738. /**
  11739. * @author mrdoob / http://mrdoob.com/
  11740. */
  11741. THREE.TextureLoader = function ( manager ) {
  11742. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11743. };
  11744. THREE.TextureLoader.prototype = {
  11745. constructor: THREE.TextureLoader,
  11746. load: function ( url, onLoad, onProgress, onError ) {
  11747. var texture = new THREE.Texture();
  11748. var loader = new THREE.ImageLoader( this.manager );
  11749. loader.setCrossOrigin( this.crossOrigin );
  11750. loader.setPath( this.path );
  11751. loader.load( url, function ( image ) {
  11752. texture.image = image;
  11753. texture.needsUpdate = true;
  11754. if ( onLoad !== undefined ) {
  11755. onLoad( texture );
  11756. }
  11757. }, onProgress, onError );
  11758. return texture;
  11759. },
  11760. setCrossOrigin: function ( value ) {
  11761. this.crossOrigin = value;
  11762. },
  11763. setPath: function ( value ) {
  11764. this.path = value;
  11765. }
  11766. };
  11767. // File:src/loaders/CubeTextureLoader.js
  11768. /**
  11769. * @author mrdoob / http://mrdoob.com/
  11770. */
  11771. THREE.CubeTextureLoader = function ( manager ) {
  11772. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11773. };
  11774. THREE.CubeTextureLoader.prototype = {
  11775. constructor: THREE.CubeTextureLoader,
  11776. load: function ( urls, onLoad, onProgress, onError ) {
  11777. var texture = new THREE.CubeTexture();
  11778. var loader = new THREE.ImageLoader( this.manager );
  11779. loader.setCrossOrigin( this.crossOrigin );
  11780. loader.setPath( this.path );
  11781. var loaded = 0;
  11782. function loadTexture( i ) {
  11783. loader.load( urls[ i ], function ( image ) {
  11784. texture.images[ i ] = image;
  11785. loaded ++;
  11786. if ( loaded === 6 ) {
  11787. texture.needsUpdate = true;
  11788. if ( onLoad ) onLoad( texture );
  11789. }
  11790. }, undefined, onError );
  11791. }
  11792. for ( var i = 0; i < urls.length; ++ i ) {
  11793. loadTexture( i );
  11794. }
  11795. return texture;
  11796. },
  11797. setCrossOrigin: function ( value ) {
  11798. this.crossOrigin = value;
  11799. },
  11800. setPath: function ( value ) {
  11801. this.path = value;
  11802. }
  11803. };
  11804. // File:src/loaders/BinaryTextureLoader.js
  11805. /**
  11806. * @author Nikos M. / https://github.com/foo123/
  11807. *
  11808. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  11809. */
  11810. THREE.DataTextureLoader = THREE.BinaryTextureLoader = function ( manager ) {
  11811. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11812. // override in sub classes
  11813. this._parser = null;
  11814. };
  11815. THREE.BinaryTextureLoader.prototype = {
  11816. constructor: THREE.BinaryTextureLoader,
  11817. load: function ( url, onLoad, onProgress, onError ) {
  11818. var scope = this;
  11819. var texture = new THREE.DataTexture();
  11820. var loader = new THREE.XHRLoader( this.manager );
  11821. loader.setResponseType( 'arraybuffer' );
  11822. loader.load( url, function ( buffer ) {
  11823. var texData = scope._parser( buffer );
  11824. if ( ! texData ) return;
  11825. if ( undefined !== texData.image ) {
  11826. texture.image = texData.image;
  11827. } else if ( undefined !== texData.data ) {
  11828. texture.image.width = texData.width;
  11829. texture.image.height = texData.height;
  11830. texture.image.data = texData.data;
  11831. }
  11832. texture.wrapS = undefined !== texData.wrapS ? texData.wrapS : THREE.ClampToEdgeWrapping;
  11833. texture.wrapT = undefined !== texData.wrapT ? texData.wrapT : THREE.ClampToEdgeWrapping;
  11834. texture.magFilter = undefined !== texData.magFilter ? texData.magFilter : THREE.LinearFilter;
  11835. texture.minFilter = undefined !== texData.minFilter ? texData.minFilter : THREE.LinearMipMapLinearFilter;
  11836. texture.anisotropy = undefined !== texData.anisotropy ? texData.anisotropy : 1;
  11837. if ( undefined !== texData.format ) {
  11838. texture.format = texData.format;
  11839. }
  11840. if ( undefined !== texData.type ) {
  11841. texture.type = texData.type;
  11842. }
  11843. if ( undefined !== texData.mipmaps ) {
  11844. texture.mipmaps = texData.mipmaps;
  11845. }
  11846. if ( 1 === texData.mipmapCount ) {
  11847. texture.minFilter = THREE.LinearFilter;
  11848. }
  11849. texture.needsUpdate = true;
  11850. if ( onLoad ) onLoad( texture, texData );
  11851. }, onProgress, onError );
  11852. return texture;
  11853. }
  11854. };
  11855. // File:src/loaders/CompressedTextureLoader.js
  11856. /**
  11857. * @author mrdoob / http://mrdoob.com/
  11858. *
  11859. * Abstract Base class to block based textures loader (dds, pvr, ...)
  11860. */
  11861. THREE.CompressedTextureLoader = function ( manager ) {
  11862. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11863. // override in sub classes
  11864. this._parser = null;
  11865. };
  11866. THREE.CompressedTextureLoader.prototype = {
  11867. constructor: THREE.CompressedTextureLoader,
  11868. load: function ( url, onLoad, onProgress, onError ) {
  11869. var scope = this;
  11870. var images = [];
  11871. var texture = new THREE.CompressedTexture();
  11872. texture.image = images;
  11873. var loader = new THREE.XHRLoader( this.manager );
  11874. loader.setPath( this.path );
  11875. loader.setResponseType( 'arraybuffer' );
  11876. function loadTexture( i ) {
  11877. loader.load( url[ i ], function ( buffer ) {
  11878. var texDatas = scope._parser( buffer, true );
  11879. images[ i ] = {
  11880. width: texDatas.width,
  11881. height: texDatas.height,
  11882. format: texDatas.format,
  11883. mipmaps: texDatas.mipmaps
  11884. };
  11885. loaded += 1;
  11886. if ( loaded === 6 ) {
  11887. if ( texDatas.mipmapCount === 1 )
  11888. texture.minFilter = THREE.LinearFilter;
  11889. texture.format = texDatas.format;
  11890. texture.needsUpdate = true;
  11891. if ( onLoad ) onLoad( texture );
  11892. }
  11893. }, onProgress, onError );
  11894. }
  11895. if ( Array.isArray( url ) ) {
  11896. var loaded = 0;
  11897. for ( var i = 0, il = url.length; i < il; ++ i ) {
  11898. loadTexture( i );
  11899. }
  11900. } else {
  11901. // compressed cubemap texture stored in a single DDS file
  11902. loader.load( url, function ( buffer ) {
  11903. var texDatas = scope._parser( buffer, true );
  11904. if ( texDatas.isCubemap ) {
  11905. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  11906. for ( var f = 0; f < faces; f ++ ) {
  11907. images[ f ] = { mipmaps : [] };
  11908. for ( var i = 0; i < texDatas.mipmapCount; i ++ ) {
  11909. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  11910. images[ f ].format = texDatas.format;
  11911. images[ f ].width = texDatas.width;
  11912. images[ f ].height = texDatas.height;
  11913. }
  11914. }
  11915. } else {
  11916. texture.image.width = texDatas.width;
  11917. texture.image.height = texDatas.height;
  11918. texture.mipmaps = texDatas.mipmaps;
  11919. }
  11920. if ( texDatas.mipmapCount === 1 ) {
  11921. texture.minFilter = THREE.LinearFilter;
  11922. }
  11923. texture.format = texDatas.format;
  11924. texture.needsUpdate = true;
  11925. if ( onLoad ) onLoad( texture );
  11926. }, onProgress, onError );
  11927. }
  11928. return texture;
  11929. },
  11930. setPath: function ( value ) {
  11931. this.path = value;
  11932. }
  11933. };
  11934. // File:src/materials/Material.js
  11935. /**
  11936. * @author mrdoob / http://mrdoob.com/
  11937. * @author alteredq / http://alteredqualia.com/
  11938. */
  11939. THREE.Material = function () {
  11940. Object.defineProperty( this, 'id', { value: THREE.MaterialIdCount ++ } );
  11941. this.uuid = THREE.Math.generateUUID();
  11942. this.name = '';
  11943. this.type = 'Material';
  11944. this.fog = true;
  11945. this.lights = true;
  11946. this.blending = THREE.NormalBlending;
  11947. this.side = THREE.FrontSide;
  11948. this.shading = THREE.SmoothShading; // THREE.FlatShading, THREE.SmoothShading
  11949. this.vertexColors = THREE.NoColors; // THREE.NoColors, THREE.VertexColors, THREE.FaceColors
  11950. this.opacity = 1;
  11951. this.transparent = false;
  11952. this.blendSrc = THREE.SrcAlphaFactor;
  11953. this.blendDst = THREE.OneMinusSrcAlphaFactor;
  11954. this.blendEquation = THREE.AddEquation;
  11955. this.blendSrcAlpha = null;
  11956. this.blendDstAlpha = null;
  11957. this.blendEquationAlpha = null;
  11958. this.depthFunc = THREE.LessEqualDepth;
  11959. this.depthTest = true;
  11960. this.depthWrite = true;
  11961. this.clippingPlanes = null;
  11962. this.clipShadows = false;
  11963. this.colorWrite = true;
  11964. this.precision = null; // override the renderer's default precision for this material
  11965. this.polygonOffset = false;
  11966. this.polygonOffsetFactor = 0;
  11967. this.polygonOffsetUnits = 0;
  11968. this.alphaTest = 0;
  11969. this.premultipliedAlpha = false;
  11970. this.overdraw = 0; // Overdrawn pixels (typically between 0 and 1) for fixing antialiasing gaps in CanvasRenderer
  11971. this.visible = true;
  11972. this._needsUpdate = true;
  11973. };
  11974. THREE.Material.prototype = {
  11975. constructor: THREE.Material,
  11976. get needsUpdate() {
  11977. return this._needsUpdate;
  11978. },
  11979. set needsUpdate( value ) {
  11980. if ( value === true ) this.update();
  11981. this._needsUpdate = value;
  11982. },
  11983. setValues: function ( values ) {
  11984. if ( values === undefined ) return;
  11985. for ( var key in values ) {
  11986. var newValue = values[ key ];
  11987. if ( newValue === undefined ) {
  11988. console.warn( "THREE.Material: '" + key + "' parameter is undefined." );
  11989. continue;
  11990. }
  11991. var currentValue = this[ key ];
  11992. if ( currentValue === undefined ) {
  11993. console.warn( "THREE." + this.type + ": '" + key + "' is not a property of this material." );
  11994. continue;
  11995. }
  11996. if ( currentValue instanceof THREE.Color ) {
  11997. currentValue.set( newValue );
  11998. } else if ( currentValue instanceof THREE.Vector3 && newValue instanceof THREE.Vector3 ) {
  11999. currentValue.copy( newValue );
  12000. } else if ( key === 'overdraw' ) {
  12001. // ensure overdraw is backwards-compatible with legacy boolean type
  12002. this[ key ] = Number( newValue );
  12003. } else {
  12004. this[ key ] = newValue;
  12005. }
  12006. }
  12007. },
  12008. toJSON: function ( meta ) {
  12009. var isRoot = meta === undefined;
  12010. if ( isRoot ) {
  12011. meta = {
  12012. textures: {},
  12013. images: {}
  12014. };
  12015. }
  12016. var data = {
  12017. metadata: {
  12018. version: 4.4,
  12019. type: 'Material',
  12020. generator: 'Material.toJSON'
  12021. }
  12022. };
  12023. // standard Material serialization
  12024. data.uuid = this.uuid;
  12025. data.type = this.type;
  12026. if ( this.name !== '' ) data.name = this.name;
  12027. if ( this.color instanceof THREE.Color ) data.color = this.color.getHex();
  12028. if ( this.roughness !== 0.5 ) data.roughness = this.roughness;
  12029. if ( this.metalness !== 0.5 ) data.metalness = this.metalness;
  12030. if ( this.emissive instanceof THREE.Color ) data.emissive = this.emissive.getHex();
  12031. if ( this.specular instanceof THREE.Color ) data.specular = this.specular.getHex();
  12032. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  12033. if ( this.map instanceof THREE.Texture ) data.map = this.map.toJSON( meta ).uuid;
  12034. if ( this.alphaMap instanceof THREE.Texture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  12035. if ( this.lightMap instanceof THREE.Texture ) data.lightMap = this.lightMap.toJSON( meta ).uuid;
  12036. if ( this.bumpMap instanceof THREE.Texture ) {
  12037. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  12038. data.bumpScale = this.bumpScale;
  12039. }
  12040. if ( this.normalMap instanceof THREE.Texture ) {
  12041. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  12042. data.normalScale = this.normalScale.toArray();
  12043. }
  12044. if ( this.displacementMap instanceof THREE.Texture ) {
  12045. data.displacementMap = this.displacementMap.toJSON( meta ).uuid;
  12046. data.displacementScale = this.displacementScale;
  12047. data.displacementBias = this.displacementBias;
  12048. }
  12049. if ( this.roughnessMap instanceof THREE.Texture ) data.roughnessMap = this.roughnessMap.toJSON( meta ).uuid;
  12050. if ( this.metalnessMap instanceof THREE.Texture ) data.metalnessMap = this.metalnessMap.toJSON( meta ).uuid;
  12051. if ( this.emissiveMap instanceof THREE.Texture ) data.emissiveMap = this.emissiveMap.toJSON( meta ).uuid;
  12052. if ( this.specularMap instanceof THREE.Texture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  12053. if ( this.envMap instanceof THREE.Texture ) {
  12054. data.envMap = this.envMap.toJSON( meta ).uuid;
  12055. data.reflectivity = this.reflectivity; // Scale behind envMap
  12056. }
  12057. if ( this.size !== undefined ) data.size = this.size;
  12058. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  12059. if ( this.blending !== THREE.NormalBlending ) data.blending = this.blending;
  12060. if ( this.shading !== THREE.SmoothShading ) data.shading = this.shading;
  12061. if ( this.side !== THREE.FrontSide ) data.side = this.side;
  12062. if ( this.vertexColors !== THREE.NoColors ) data.vertexColors = this.vertexColors;
  12063. if ( this.opacity < 1 ) data.opacity = this.opacity;
  12064. if ( this.transparent === true ) data.transparent = this.transparent;
  12065. if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
  12066. if ( this.premultipliedAlpha === true ) data.premultipliedAlpha = this.premultipliedAlpha;
  12067. if ( this.wireframe === true ) data.wireframe = this.wireframe;
  12068. if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;
  12069. // TODO: Copied from Object3D.toJSON
  12070. function extractFromCache ( cache ) {
  12071. var values = [];
  12072. for ( var key in cache ) {
  12073. var data = cache[ key ];
  12074. delete data.metadata;
  12075. values.push( data );
  12076. }
  12077. return values;
  12078. }
  12079. if ( isRoot ) {
  12080. var textures = extractFromCache( meta.textures );
  12081. var images = extractFromCache( meta.images );
  12082. if ( textures.length > 0 ) data.textures = textures;
  12083. if ( images.length > 0 ) data.images = images;
  12084. }
  12085. return data;
  12086. },
  12087. clone: function () {
  12088. return new this.constructor().copy( this );
  12089. },
  12090. copy: function ( source ) {
  12091. this.name = source.name;
  12092. this.fog = source.fog;
  12093. this.lights = source.lights;
  12094. this.blending = source.blending;
  12095. this.side = source.side;
  12096. this.vertexColors = source.vertexColors;
  12097. this.opacity = source.opacity;
  12098. this.transparent = source.transparent;
  12099. this.blendSrc = source.blendSrc;
  12100. this.blendDst = source.blendDst;
  12101. this.blendEquation = source.blendEquation;
  12102. this.blendSrcAlpha = source.blendSrcAlpha;
  12103. this.blendDstAlpha = source.blendDstAlpha;
  12104. this.blendEquationAlpha = source.blendEquationAlpha;
  12105. this.depthFunc = source.depthFunc;
  12106. this.depthTest = source.depthTest;
  12107. this.depthWrite = source.depthWrite;
  12108. this.colorWrite = source.colorWrite;
  12109. this.precision = source.precision;
  12110. this.polygonOffset = source.polygonOffset;
  12111. this.polygonOffsetFactor = source.polygonOffsetFactor;
  12112. this.polygonOffsetUnits = source.polygonOffsetUnits;
  12113. this.alphaTest = source.alphaTest;
  12114. this.premultipliedAlpha = source.premultipliedAlpha;
  12115. this.overdraw = source.overdraw;
  12116. this.visible = source.visible;
  12117. this.clipShadows = source.clipShadows;
  12118. var srcPlanes = source.clippingPlanes,
  12119. dstPlanes = null;
  12120. if ( srcPlanes !== null ) {
  12121. var n = srcPlanes.length;
  12122. dstPlanes = new Array( n );
  12123. for ( var i = 0; i !== n; ++ i )
  12124. dstPlanes[ i ] = srcPlanes[ i ].clone();
  12125. }
  12126. this.clippingPlanes = dstPlanes;
  12127. return this;
  12128. },
  12129. update: function () {
  12130. this.dispatchEvent( { type: 'update' } );
  12131. },
  12132. dispose: function () {
  12133. this.dispatchEvent( { type: 'dispose' } );
  12134. }
  12135. };
  12136. Object.assign( THREE.Material.prototype, THREE.EventDispatcher.prototype );
  12137. THREE.MaterialIdCount = 0;
  12138. // File:src/materials/LineBasicMaterial.js
  12139. /**
  12140. * @author mrdoob / http://mrdoob.com/
  12141. * @author alteredq / http://alteredqualia.com/
  12142. *
  12143. * parameters = {
  12144. * color: <hex>,
  12145. * opacity: <float>,
  12146. *
  12147. * linewidth: <float>,
  12148. * linecap: "round",
  12149. * linejoin: "round"
  12150. * }
  12151. */
  12152. THREE.LineBasicMaterial = function ( parameters ) {
  12153. THREE.Material.call( this );
  12154. this.type = 'LineBasicMaterial';
  12155. this.color = new THREE.Color( 0xffffff );
  12156. this.linewidth = 1;
  12157. this.linecap = 'round';
  12158. this.linejoin = 'round';
  12159. this.lights = false;
  12160. this.setValues( parameters );
  12161. };
  12162. THREE.LineBasicMaterial.prototype = Object.create( THREE.Material.prototype );
  12163. THREE.LineBasicMaterial.prototype.constructor = THREE.LineBasicMaterial;
  12164. THREE.LineBasicMaterial.prototype.copy = function ( source ) {
  12165. THREE.Material.prototype.copy.call( this, source );
  12166. this.color.copy( source.color );
  12167. this.linewidth = source.linewidth;
  12168. this.linecap = source.linecap;
  12169. this.linejoin = source.linejoin;
  12170. return this;
  12171. };
  12172. // File:src/materials/LineDashedMaterial.js
  12173. /**
  12174. * @author alteredq / http://alteredqualia.com/
  12175. *
  12176. * parameters = {
  12177. * color: <hex>,
  12178. * opacity: <float>,
  12179. *
  12180. * linewidth: <float>,
  12181. *
  12182. * scale: <float>,
  12183. * dashSize: <float>,
  12184. * gapSize: <float>
  12185. * }
  12186. */
  12187. THREE.LineDashedMaterial = function ( parameters ) {
  12188. THREE.Material.call( this );
  12189. this.type = 'LineDashedMaterial';
  12190. this.color = new THREE.Color( 0xffffff );
  12191. this.linewidth = 1;
  12192. this.scale = 1;
  12193. this.dashSize = 3;
  12194. this.gapSize = 1;
  12195. this.lights = false;
  12196. this.setValues( parameters );
  12197. };
  12198. THREE.LineDashedMaterial.prototype = Object.create( THREE.Material.prototype );
  12199. THREE.LineDashedMaterial.prototype.constructor = THREE.LineDashedMaterial;
  12200. THREE.LineDashedMaterial.prototype.copy = function ( source ) {
  12201. THREE.Material.prototype.copy.call( this, source );
  12202. this.color.copy( source.color );
  12203. this.linewidth = source.linewidth;
  12204. this.scale = source.scale;
  12205. this.dashSize = source.dashSize;
  12206. this.gapSize = source.gapSize;
  12207. return this;
  12208. };
  12209. // File:src/materials/MeshBasicMaterial.js
  12210. /**
  12211. * @author mrdoob / http://mrdoob.com/
  12212. * @author alteredq / http://alteredqualia.com/
  12213. *
  12214. * parameters = {
  12215. * color: <hex>,
  12216. * opacity: <float>,
  12217. * map: new THREE.Texture( <Image> ),
  12218. *
  12219. * aoMap: new THREE.Texture( <Image> ),
  12220. * aoMapIntensity: <float>
  12221. *
  12222. * specularMap: new THREE.Texture( <Image> ),
  12223. *
  12224. * alphaMap: new THREE.Texture( <Image> ),
  12225. *
  12226. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  12227. * combine: THREE.Multiply,
  12228. * reflectivity: <float>,
  12229. * refractionRatio: <float>,
  12230. *
  12231. * shading: THREE.SmoothShading,
  12232. * depthTest: <bool>,
  12233. * depthWrite: <bool>,
  12234. *
  12235. * wireframe: <boolean>,
  12236. * wireframeLinewidth: <float>,
  12237. *
  12238. * skinning: <bool>,
  12239. * morphTargets: <bool>
  12240. * }
  12241. */
  12242. THREE.MeshBasicMaterial = function ( parameters ) {
  12243. THREE.Material.call( this );
  12244. this.type = 'MeshBasicMaterial';
  12245. this.color = new THREE.Color( 0xffffff ); // emissive
  12246. this.map = null;
  12247. this.aoMap = null;
  12248. this.aoMapIntensity = 1.0;
  12249. this.specularMap = null;
  12250. this.alphaMap = null;
  12251. this.envMap = null;
  12252. this.combine = THREE.MultiplyOperation;
  12253. this.reflectivity = 1;
  12254. this.refractionRatio = 0.98;
  12255. this.wireframe = false;
  12256. this.wireframeLinewidth = 1;
  12257. this.wireframeLinecap = 'round';
  12258. this.wireframeLinejoin = 'round';
  12259. this.skinning = false;
  12260. this.morphTargets = false;
  12261. this.lights = false;
  12262. this.setValues( parameters );
  12263. };
  12264. THREE.MeshBasicMaterial.prototype = Object.create( THREE.Material.prototype );
  12265. THREE.MeshBasicMaterial.prototype.constructor = THREE.MeshBasicMaterial;
  12266. THREE.MeshBasicMaterial.prototype.copy = function ( source ) {
  12267. THREE.Material.prototype.copy.call( this, source );
  12268. this.color.copy( source.color );
  12269. this.map = source.map;
  12270. this.aoMap = source.aoMap;
  12271. this.aoMapIntensity = source.aoMapIntensity;
  12272. this.specularMap = source.specularMap;
  12273. this.alphaMap = source.alphaMap;
  12274. this.envMap = source.envMap;
  12275. this.combine = source.combine;
  12276. this.reflectivity = source.reflectivity;
  12277. this.refractionRatio = source.refractionRatio;
  12278. this.wireframe = source.wireframe;
  12279. this.wireframeLinewidth = source.wireframeLinewidth;
  12280. this.wireframeLinecap = source.wireframeLinecap;
  12281. this.wireframeLinejoin = source.wireframeLinejoin;
  12282. this.skinning = source.skinning;
  12283. this.morphTargets = source.morphTargets;
  12284. return this;
  12285. };
  12286. // File:src/materials/MeshDepthMaterial.js
  12287. /**
  12288. * @author mrdoob / http://mrdoob.com/
  12289. * @author alteredq / http://alteredqualia.com/
  12290. * @author bhouston / https://clara.io
  12291. * @author WestLangley / http://github.com/WestLangley
  12292. *
  12293. * parameters = {
  12294. *
  12295. * opacity: <float>,
  12296. *
  12297. * map: new THREE.Texture( <Image> ),
  12298. *
  12299. * alphaMap: new THREE.Texture( <Image> ),
  12300. *
  12301. * displacementMap: new THREE.Texture( <Image> ),
  12302. * displacementScale: <float>,
  12303. * displacementBias: <float>,
  12304. *
  12305. * wireframe: <boolean>,
  12306. * wireframeLinewidth: <float>
  12307. * }
  12308. */
  12309. THREE.MeshDepthMaterial = function ( parameters ) {
  12310. THREE.Material.call( this );
  12311. this.type = 'MeshDepthMaterial';
  12312. this.depthPacking = THREE.BasicDepthPacking;
  12313. this.skinning = false;
  12314. this.morphTargets = false;
  12315. this.map = null;
  12316. this.alphaMap = null;
  12317. this.displacementMap = null;
  12318. this.displacementScale = 1;
  12319. this.displacementBias = 0;
  12320. this.wireframe = false;
  12321. this.wireframeLinewidth = 1;
  12322. this.fog = false;
  12323. this.lights = false;
  12324. this.setValues( parameters );
  12325. };
  12326. THREE.MeshDepthMaterial.prototype = Object.create( THREE.Material.prototype );
  12327. THREE.MeshDepthMaterial.prototype.constructor = THREE.MeshDepthMaterial;
  12328. THREE.MeshDepthMaterial.prototype.copy = function ( source ) {
  12329. THREE.Material.prototype.copy.call( this, source );
  12330. this.depthPacking = source.depthPacking;
  12331. this.skinning = source.skinning;
  12332. this.morphTargets = source.morphTargets;
  12333. this.map = source.map;
  12334. this.alphaMap = source.alphaMap;
  12335. this.displacementMap = source.displacementMap;
  12336. this.displacementScale = source.displacementScale;
  12337. this.displacementBias = source.displacementBias;
  12338. this.wireframe = source.wireframe;
  12339. this.wireframeLinewidth = source.wireframeLinewidth;
  12340. return this;
  12341. };
  12342. // File:src/materials/MeshLambertMaterial.js
  12343. /**
  12344. * @author mrdoob / http://mrdoob.com/
  12345. * @author alteredq / http://alteredqualia.com/
  12346. *
  12347. * parameters = {
  12348. * color: <hex>,
  12349. * opacity: <float>,
  12350. *
  12351. * map: new THREE.Texture( <Image> ),
  12352. *
  12353. * lightMap: new THREE.Texture( <Image> ),
  12354. * lightMapIntensity: <float>
  12355. *
  12356. * aoMap: new THREE.Texture( <Image> ),
  12357. * aoMapIntensity: <float>
  12358. *
  12359. * emissive: <hex>,
  12360. * emissiveIntensity: <float>
  12361. * emissiveMap: new THREE.Texture( <Image> ),
  12362. *
  12363. * specularMap: new THREE.Texture( <Image> ),
  12364. *
  12365. * alphaMap: new THREE.Texture( <Image> ),
  12366. *
  12367. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  12368. * combine: THREE.Multiply,
  12369. * reflectivity: <float>,
  12370. * refractionRatio: <float>,
  12371. *
  12372. * wireframe: <boolean>,
  12373. * wireframeLinewidth: <float>,
  12374. *
  12375. * skinning: <bool>,
  12376. * morphTargets: <bool>,
  12377. * morphNormals: <bool>
  12378. * }
  12379. */
  12380. THREE.MeshLambertMaterial = function ( parameters ) {
  12381. THREE.Material.call( this );
  12382. this.type = 'MeshLambertMaterial';
  12383. this.color = new THREE.Color( 0xffffff ); // diffuse
  12384. this.map = null;
  12385. this.lightMap = null;
  12386. this.lightMapIntensity = 1.0;
  12387. this.aoMap = null;
  12388. this.aoMapIntensity = 1.0;
  12389. this.emissive = new THREE.Color( 0x000000 );
  12390. this.emissiveIntensity = 1.0;
  12391. this.emissiveMap = null;
  12392. this.specularMap = null;
  12393. this.alphaMap = null;
  12394. this.envMap = null;
  12395. this.combine = THREE.MultiplyOperation;
  12396. this.reflectivity = 1;
  12397. this.refractionRatio = 0.98;
  12398. this.wireframe = false;
  12399. this.wireframeLinewidth = 1;
  12400. this.wireframeLinecap = 'round';
  12401. this.wireframeLinejoin = 'round';
  12402. this.skinning = false;
  12403. this.morphTargets = false;
  12404. this.morphNormals = false;
  12405. this.setValues( parameters );
  12406. };
  12407. THREE.MeshLambertMaterial.prototype = Object.create( THREE.Material.prototype );
  12408. THREE.MeshLambertMaterial.prototype.constructor = THREE.MeshLambertMaterial;
  12409. THREE.MeshLambertMaterial.prototype.copy = function ( source ) {
  12410. THREE.Material.prototype.copy.call( this, source );
  12411. this.color.copy( source.color );
  12412. this.map = source.map;
  12413. this.lightMap = source.lightMap;
  12414. this.lightMapIntensity = source.lightMapIntensity;
  12415. this.aoMap = source.aoMap;
  12416. this.aoMapIntensity = source.aoMapIntensity;
  12417. this.emissive.copy( source.emissive );
  12418. this.emissiveMap = source.emissiveMap;
  12419. this.emissiveIntensity = source.emissiveIntensity;
  12420. this.specularMap = source.specularMap;
  12421. this.alphaMap = source.alphaMap;
  12422. this.envMap = source.envMap;
  12423. this.combine = source.combine;
  12424. this.reflectivity = source.reflectivity;
  12425. this.refractionRatio = source.refractionRatio;
  12426. this.wireframe = source.wireframe;
  12427. this.wireframeLinewidth = source.wireframeLinewidth;
  12428. this.wireframeLinecap = source.wireframeLinecap;
  12429. this.wireframeLinejoin = source.wireframeLinejoin;
  12430. this.skinning = source.skinning;
  12431. this.morphTargets = source.morphTargets;
  12432. this.morphNormals = source.morphNormals;
  12433. return this;
  12434. };
  12435. // File:src/materials/MeshNormalMaterial.js
  12436. /**
  12437. * @author mrdoob / http://mrdoob.com/
  12438. *
  12439. * parameters = {
  12440. * opacity: <float>,
  12441. *
  12442. * wireframe: <boolean>,
  12443. * wireframeLinewidth: <float>
  12444. * }
  12445. */
  12446. THREE.MeshNormalMaterial = function ( parameters ) {
  12447. THREE.Material.call( this, parameters );
  12448. this.type = 'MeshNormalMaterial';
  12449. this.wireframe = false;
  12450. this.wireframeLinewidth = 1;
  12451. this.fog = false;
  12452. this.lights = false;
  12453. this.morphTargets = false;
  12454. this.setValues( parameters );
  12455. };
  12456. THREE.MeshNormalMaterial.prototype = Object.create( THREE.Material.prototype );
  12457. THREE.MeshNormalMaterial.prototype.constructor = THREE.MeshNormalMaterial;
  12458. THREE.MeshNormalMaterial.prototype.copy = function ( source ) {
  12459. THREE.Material.prototype.copy.call( this, source );
  12460. this.wireframe = source.wireframe;
  12461. this.wireframeLinewidth = source.wireframeLinewidth;
  12462. return this;
  12463. };
  12464. // File:src/materials/MeshPhongMaterial.js
  12465. /**
  12466. * @author mrdoob / http://mrdoob.com/
  12467. * @author alteredq / http://alteredqualia.com/
  12468. *
  12469. * parameters = {
  12470. * color: <hex>,
  12471. * specular: <hex>,
  12472. * shininess: <float>,
  12473. * opacity: <float>,
  12474. *
  12475. * map: new THREE.Texture( <Image> ),
  12476. *
  12477. * lightMap: new THREE.Texture( <Image> ),
  12478. * lightMapIntensity: <float>
  12479. *
  12480. * aoMap: new THREE.Texture( <Image> ),
  12481. * aoMapIntensity: <float>
  12482. *
  12483. * emissive: <hex>,
  12484. * emissiveIntensity: <float>
  12485. * emissiveMap: new THREE.Texture( <Image> ),
  12486. *
  12487. * bumpMap: new THREE.Texture( <Image> ),
  12488. * bumpScale: <float>,
  12489. *
  12490. * normalMap: new THREE.Texture( <Image> ),
  12491. * normalScale: <Vector2>,
  12492. *
  12493. * displacementMap: new THREE.Texture( <Image> ),
  12494. * displacementScale: <float>,
  12495. * displacementBias: <float>,
  12496. *
  12497. * specularMap: new THREE.Texture( <Image> ),
  12498. *
  12499. * alphaMap: new THREE.Texture( <Image> ),
  12500. *
  12501. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  12502. * combine: THREE.Multiply,
  12503. * reflectivity: <float>,
  12504. * refractionRatio: <float>,
  12505. *
  12506. * wireframe: <boolean>,
  12507. * wireframeLinewidth: <float>,
  12508. *
  12509. * skinning: <bool>,
  12510. * morphTargets: <bool>,
  12511. * morphNormals: <bool>
  12512. * }
  12513. */
  12514. THREE.MeshPhongMaterial = function ( parameters ) {
  12515. THREE.Material.call( this );
  12516. this.type = 'MeshPhongMaterial';
  12517. this.color = new THREE.Color( 0xffffff ); // diffuse
  12518. this.specular = new THREE.Color( 0x111111 );
  12519. this.shininess = 30;
  12520. this.map = null;
  12521. this.lightMap = null;
  12522. this.lightMapIntensity = 1.0;
  12523. this.aoMap = null;
  12524. this.aoMapIntensity = 1.0;
  12525. this.emissive = new THREE.Color( 0x000000 );
  12526. this.emissiveIntensity = 1.0;
  12527. this.emissiveMap = null;
  12528. this.bumpMap = null;
  12529. this.bumpScale = 1;
  12530. this.normalMap = null;
  12531. this.normalScale = new THREE.Vector2( 1, 1 );
  12532. this.displacementMap = null;
  12533. this.displacementScale = 1;
  12534. this.displacementBias = 0;
  12535. this.specularMap = null;
  12536. this.alphaMap = null;
  12537. this.envMap = null;
  12538. this.combine = THREE.MultiplyOperation;
  12539. this.reflectivity = 1;
  12540. this.refractionRatio = 0.98;
  12541. this.wireframe = false;
  12542. this.wireframeLinewidth = 1;
  12543. this.wireframeLinecap = 'round';
  12544. this.wireframeLinejoin = 'round';
  12545. this.skinning = false;
  12546. this.morphTargets = false;
  12547. this.morphNormals = false;
  12548. this.setValues( parameters );
  12549. };
  12550. THREE.MeshPhongMaterial.prototype = Object.create( THREE.Material.prototype );
  12551. THREE.MeshPhongMaterial.prototype.constructor = THREE.MeshPhongMaterial;
  12552. THREE.MeshPhongMaterial.prototype.copy = function ( source ) {
  12553. THREE.Material.prototype.copy.call( this, source );
  12554. this.color.copy( source.color );
  12555. this.specular.copy( source.specular );
  12556. this.shininess = source.shininess;
  12557. this.map = source.map;
  12558. this.lightMap = source.lightMap;
  12559. this.lightMapIntensity = source.lightMapIntensity;
  12560. this.aoMap = source.aoMap;
  12561. this.aoMapIntensity = source.aoMapIntensity;
  12562. this.emissive.copy( source.emissive );
  12563. this.emissiveMap = source.emissiveMap;
  12564. this.emissiveIntensity = source.emissiveIntensity;
  12565. this.bumpMap = source.bumpMap;
  12566. this.bumpScale = source.bumpScale;
  12567. this.normalMap = source.normalMap;
  12568. this.normalScale.copy( source.normalScale );
  12569. this.displacementMap = source.displacementMap;
  12570. this.displacementScale = source.displacementScale;
  12571. this.displacementBias = source.displacementBias;
  12572. this.specularMap = source.specularMap;
  12573. this.alphaMap = source.alphaMap;
  12574. this.envMap = source.envMap;
  12575. this.combine = source.combine;
  12576. this.reflectivity = source.reflectivity;
  12577. this.refractionRatio = source.refractionRatio;
  12578. this.wireframe = source.wireframe;
  12579. this.wireframeLinewidth = source.wireframeLinewidth;
  12580. this.wireframeLinecap = source.wireframeLinecap;
  12581. this.wireframeLinejoin = source.wireframeLinejoin;
  12582. this.skinning = source.skinning;
  12583. this.morphTargets = source.morphTargets;
  12584. this.morphNormals = source.morphNormals;
  12585. return this;
  12586. };
  12587. // File:src/materials/MeshStandardMaterial.js
  12588. /**
  12589. * @author WestLangley / http://github.com/WestLangley
  12590. *
  12591. * parameters = {
  12592. * color: <hex>,
  12593. * roughness: <float>,
  12594. * metalness: <float>,
  12595. * opacity: <float>,
  12596. *
  12597. * map: new THREE.Texture( <Image> ),
  12598. *
  12599. * lightMap: new THREE.Texture( <Image> ),
  12600. * lightMapIntensity: <float>
  12601. *
  12602. * aoMap: new THREE.Texture( <Image> ),
  12603. * aoMapIntensity: <float>
  12604. *
  12605. * emissive: <hex>,
  12606. * emissiveIntensity: <float>
  12607. * emissiveMap: new THREE.Texture( <Image> ),
  12608. *
  12609. * bumpMap: new THREE.Texture( <Image> ),
  12610. * bumpScale: <float>,
  12611. *
  12612. * normalMap: new THREE.Texture( <Image> ),
  12613. * normalScale: <Vector2>,
  12614. *
  12615. * displacementMap: new THREE.Texture( <Image> ),
  12616. * displacementScale: <float>,
  12617. * displacementBias: <float>,
  12618. *
  12619. * roughnessMap: new THREE.Texture( <Image> ),
  12620. *
  12621. * metalnessMap: new THREE.Texture( <Image> ),
  12622. *
  12623. * alphaMap: new THREE.Texture( <Image> ),
  12624. *
  12625. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  12626. * envMapIntensity: <float>
  12627. *
  12628. * refractionRatio: <float>,
  12629. *
  12630. * wireframe: <boolean>,
  12631. * wireframeLinewidth: <float>,
  12632. *
  12633. * skinning: <bool>,
  12634. * morphTargets: <bool>,
  12635. * morphNormals: <bool>
  12636. * }
  12637. */
  12638. THREE.MeshStandardMaterial = function ( parameters ) {
  12639. THREE.Material.call( this );
  12640. this.defines = { 'STANDARD': '' };
  12641. this.type = 'MeshStandardMaterial';
  12642. this.color = new THREE.Color( 0xffffff ); // diffuse
  12643. this.roughness = 0.5;
  12644. this.metalness = 0.5;
  12645. this.map = null;
  12646. this.lightMap = null;
  12647. this.lightMapIntensity = 1.0;
  12648. this.aoMap = null;
  12649. this.aoMapIntensity = 1.0;
  12650. this.emissive = new THREE.Color( 0x000000 );
  12651. this.emissiveIntensity = 1.0;
  12652. this.emissiveMap = null;
  12653. this.bumpMap = null;
  12654. this.bumpScale = 1;
  12655. this.normalMap = null;
  12656. this.normalScale = new THREE.Vector2( 1, 1 );
  12657. this.displacementMap = null;
  12658. this.displacementScale = 1;
  12659. this.displacementBias = 0;
  12660. this.roughnessMap = null;
  12661. this.metalnessMap = null;
  12662. this.alphaMap = null;
  12663. this.envMap = null;
  12664. this.envMapIntensity = 1.0;
  12665. this.refractionRatio = 0.98;
  12666. this.wireframe = false;
  12667. this.wireframeLinewidth = 1;
  12668. this.wireframeLinecap = 'round';
  12669. this.wireframeLinejoin = 'round';
  12670. this.skinning = false;
  12671. this.morphTargets = false;
  12672. this.morphNormals = false;
  12673. this.setValues( parameters );
  12674. };
  12675. THREE.MeshStandardMaterial.prototype = Object.create( THREE.Material.prototype );
  12676. THREE.MeshStandardMaterial.prototype.constructor = THREE.MeshStandardMaterial;
  12677. THREE.MeshStandardMaterial.prototype.copy = function ( source ) {
  12678. THREE.Material.prototype.copy.call( this, source );
  12679. this.defines = { 'STANDARD': '' };
  12680. this.color.copy( source.color );
  12681. this.roughness = source.roughness;
  12682. this.metalness = source.metalness;
  12683. this.map = source.map;
  12684. this.lightMap = source.lightMap;
  12685. this.lightMapIntensity = source.lightMapIntensity;
  12686. this.aoMap = source.aoMap;
  12687. this.aoMapIntensity = source.aoMapIntensity;
  12688. this.emissive.copy( source.emissive );
  12689. this.emissiveMap = source.emissiveMap;
  12690. this.emissiveIntensity = source.emissiveIntensity;
  12691. this.bumpMap = source.bumpMap;
  12692. this.bumpScale = source.bumpScale;
  12693. this.normalMap = source.normalMap;
  12694. this.normalScale.copy( source.normalScale );
  12695. this.displacementMap = source.displacementMap;
  12696. this.displacementScale = source.displacementScale;
  12697. this.displacementBias = source.displacementBias;
  12698. this.roughnessMap = source.roughnessMap;
  12699. this.metalnessMap = source.metalnessMap;
  12700. this.alphaMap = source.alphaMap;
  12701. this.envMap = source.envMap;
  12702. this.envMapIntensity = source.envMapIntensity;
  12703. this.refractionRatio = source.refractionRatio;
  12704. this.wireframe = source.wireframe;
  12705. this.wireframeLinewidth = source.wireframeLinewidth;
  12706. this.wireframeLinecap = source.wireframeLinecap;
  12707. this.wireframeLinejoin = source.wireframeLinejoin;
  12708. this.skinning = source.skinning;
  12709. this.morphTargets = source.morphTargets;
  12710. this.morphNormals = source.morphNormals;
  12711. return this;
  12712. };
  12713. // File:src/materials/MeshPhysicalMaterial.js
  12714. /**
  12715. * @author WestLangley / http://github.com/WestLangley
  12716. *
  12717. * parameters = {
  12718. * reflectivity: <float>
  12719. * }
  12720. */
  12721. THREE.MeshPhysicalMaterial = function ( parameters ) {
  12722. THREE.MeshStandardMaterial.call( this );
  12723. this.defines = { 'PHYSICAL': '' };
  12724. this.type = 'MeshPhysicalMaterial';
  12725. this.reflectivity = 0.5; // maps to F0 = 0.04
  12726. this.setValues( parameters );
  12727. };
  12728. THREE.MeshPhysicalMaterial.prototype = Object.create( THREE.MeshStandardMaterial.prototype );
  12729. THREE.MeshPhysicalMaterial.prototype.constructor = THREE.MeshPhysicalMaterial;
  12730. THREE.MeshPhysicalMaterial.prototype.copy = function ( source ) {
  12731. THREE.MeshStandardMaterial.prototype.copy.call( this, source );
  12732. this.defines = { 'PHYSICAL': '' };
  12733. this.reflectivity = source.reflectivity;
  12734. return this;
  12735. };
  12736. // File:src/materials/MultiMaterial.js
  12737. /**
  12738. * @author mrdoob / http://mrdoob.com/
  12739. */
  12740. THREE.MultiMaterial = function ( materials ) {
  12741. this.uuid = THREE.Math.generateUUID();
  12742. this.type = 'MultiMaterial';
  12743. this.materials = materials instanceof Array ? materials : [];
  12744. this.visible = true;
  12745. };
  12746. THREE.MultiMaterial.prototype = {
  12747. constructor: THREE.MultiMaterial,
  12748. toJSON: function ( meta ) {
  12749. var output = {
  12750. metadata: {
  12751. version: 4.2,
  12752. type: 'material',
  12753. generator: 'MaterialExporter'
  12754. },
  12755. uuid: this.uuid,
  12756. type: this.type,
  12757. materials: []
  12758. };
  12759. var materials = this.materials;
  12760. for ( var i = 0, l = materials.length; i < l; i ++ ) {
  12761. var material = materials[ i ].toJSON( meta );
  12762. delete material.metadata;
  12763. output.materials.push( material );
  12764. }
  12765. output.visible = this.visible;
  12766. return output;
  12767. },
  12768. clone: function () {
  12769. var material = new this.constructor();
  12770. for ( var i = 0; i < this.materials.length; i ++ ) {
  12771. material.materials.push( this.materials[ i ].clone() );
  12772. }
  12773. material.visible = this.visible;
  12774. return material;
  12775. }
  12776. };
  12777. // File:src/materials/PointsMaterial.js
  12778. /**
  12779. * @author mrdoob / http://mrdoob.com/
  12780. * @author alteredq / http://alteredqualia.com/
  12781. *
  12782. * parameters = {
  12783. * color: <hex>,
  12784. * opacity: <float>,
  12785. * map: new THREE.Texture( <Image> ),
  12786. *
  12787. * size: <float>,
  12788. * sizeAttenuation: <bool>
  12789. * }
  12790. */
  12791. THREE.PointsMaterial = function ( parameters ) {
  12792. THREE.Material.call( this );
  12793. this.type = 'PointsMaterial';
  12794. this.color = new THREE.Color( 0xffffff );
  12795. this.map = null;
  12796. this.size = 1;
  12797. this.sizeAttenuation = true;
  12798. this.lights = false;
  12799. this.setValues( parameters );
  12800. };
  12801. THREE.PointsMaterial.prototype = Object.create( THREE.Material.prototype );
  12802. THREE.PointsMaterial.prototype.constructor = THREE.PointsMaterial;
  12803. THREE.PointsMaterial.prototype.copy = function ( source ) {
  12804. THREE.Material.prototype.copy.call( this, source );
  12805. this.color.copy( source.color );
  12806. this.map = source.map;
  12807. this.size = source.size;
  12808. this.sizeAttenuation = source.sizeAttenuation;
  12809. return this;
  12810. };
  12811. // File:src/materials/ShaderMaterial.js
  12812. /**
  12813. * @author alteredq / http://alteredqualia.com/
  12814. *
  12815. * parameters = {
  12816. * defines: { "label" : "value" },
  12817. * uniforms: { "parameter1": { type: "1f", value: 1.0 }, "parameter2": { type: "1i" value2: 2 } },
  12818. *
  12819. * fragmentShader: <string>,
  12820. * vertexShader: <string>,
  12821. *
  12822. * wireframe: <boolean>,
  12823. * wireframeLinewidth: <float>,
  12824. *
  12825. * lights: <bool>,
  12826. *
  12827. * skinning: <bool>,
  12828. * morphTargets: <bool>,
  12829. * morphNormals: <bool>
  12830. * }
  12831. */
  12832. THREE.ShaderMaterial = function ( parameters ) {
  12833. THREE.Material.call( this );
  12834. this.type = 'ShaderMaterial';
  12835. this.defines = {};
  12836. this.uniforms = {};
  12837. this.vertexShader = 'void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}';
  12838. this.fragmentShader = 'void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}';
  12839. this.linewidth = 1;
  12840. this.wireframe = false;
  12841. this.wireframeLinewidth = 1;
  12842. this.fog = false; // set to use scene fog
  12843. this.lights = false; // set to use scene lights
  12844. this.clipping = false; // set to use user-defined clipping planes
  12845. this.skinning = false; // set to use skinning attribute streams
  12846. this.morphTargets = false; // set to use morph targets
  12847. this.morphNormals = false; // set to use morph normals
  12848. this.extensions = {
  12849. derivatives: false, // set to use derivatives
  12850. fragDepth: false, // set to use fragment depth values
  12851. drawBuffers: false, // set to use draw buffers
  12852. shaderTextureLOD: false // set to use shader texture LOD
  12853. };
  12854. // When rendered geometry doesn't include these attributes but the material does,
  12855. // use these default values in WebGL. This avoids errors when buffer data is missing.
  12856. this.defaultAttributeValues = {
  12857. 'color': [ 1, 1, 1 ],
  12858. 'uv': [ 0, 0 ],
  12859. 'uv2': [ 0, 0 ]
  12860. };
  12861. this.index0AttributeName = undefined;
  12862. if ( parameters !== undefined ) {
  12863. if ( parameters.attributes !== undefined ) {
  12864. console.error( 'THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.' );
  12865. }
  12866. this.setValues( parameters );
  12867. }
  12868. };
  12869. THREE.ShaderMaterial.prototype = Object.create( THREE.Material.prototype );
  12870. THREE.ShaderMaterial.prototype.constructor = THREE.ShaderMaterial;
  12871. THREE.ShaderMaterial.prototype.copy = function ( source ) {
  12872. THREE.Material.prototype.copy.call( this, source );
  12873. this.fragmentShader = source.fragmentShader;
  12874. this.vertexShader = source.vertexShader;
  12875. this.uniforms = THREE.UniformsUtils.clone( source.uniforms );
  12876. this.defines = source.defines;
  12877. this.wireframe = source.wireframe;
  12878. this.wireframeLinewidth = source.wireframeLinewidth;
  12879. this.lights = source.lights;
  12880. this.clipping = source.clipping;
  12881. this.skinning = source.skinning;
  12882. this.morphTargets = source.morphTargets;
  12883. this.morphNormals = source.morphNormals;
  12884. this.extensions = source.extensions;
  12885. return this;
  12886. };
  12887. THREE.ShaderMaterial.prototype.toJSON = function ( meta ) {
  12888. var data = THREE.Material.prototype.toJSON.call( this, meta );
  12889. data.uniforms = this.uniforms;
  12890. data.vertexShader = this.vertexShader;
  12891. data.fragmentShader = this.fragmentShader;
  12892. return data;
  12893. };
  12894. // File:src/materials/RawShaderMaterial.js
  12895. /**
  12896. * @author mrdoob / http://mrdoob.com/
  12897. */
  12898. THREE.RawShaderMaterial = function ( parameters ) {
  12899. THREE.ShaderMaterial.call( this, parameters );
  12900. this.type = 'RawShaderMaterial';
  12901. };
  12902. THREE.RawShaderMaterial.prototype = Object.create( THREE.ShaderMaterial.prototype );
  12903. THREE.RawShaderMaterial.prototype.constructor = THREE.RawShaderMaterial;
  12904. // File:src/materials/SpriteMaterial.js
  12905. /**
  12906. * @author alteredq / http://alteredqualia.com/
  12907. *
  12908. * parameters = {
  12909. * color: <hex>,
  12910. * opacity: <float>,
  12911. * map: new THREE.Texture( <Image> ),
  12912. *
  12913. * uvOffset: new THREE.Vector2(),
  12914. * uvScale: new THREE.Vector2()
  12915. * }
  12916. */
  12917. THREE.SpriteMaterial = function ( parameters ) {
  12918. THREE.Material.call( this );
  12919. this.type = 'SpriteMaterial';
  12920. this.color = new THREE.Color( 0xffffff );
  12921. this.map = null;
  12922. this.rotation = 0;
  12923. this.fog = false;
  12924. this.lights = false;
  12925. this.setValues( parameters );
  12926. };
  12927. THREE.SpriteMaterial.prototype = Object.create( THREE.Material.prototype );
  12928. THREE.SpriteMaterial.prototype.constructor = THREE.SpriteMaterial;
  12929. THREE.SpriteMaterial.prototype.copy = function ( source ) {
  12930. THREE.Material.prototype.copy.call( this, source );
  12931. this.color.copy( source.color );
  12932. this.map = source.map;
  12933. this.rotation = source.rotation;
  12934. return this;
  12935. };
  12936. // File:src/materials/ShadowMaterial.js
  12937. /**
  12938. * @author mrdoob / http://mrdoob.com/
  12939. */
  12940. THREE.ShadowMaterial = function () {
  12941. THREE.ShaderMaterial.call( this, {
  12942. uniforms: THREE.UniformsUtils.merge( [
  12943. THREE.UniformsLib[ "lights" ],
  12944. {
  12945. opacity: { value: 1.0 }
  12946. }
  12947. ] ),
  12948. vertexShader: THREE.ShaderChunk[ 'shadow_vert' ],
  12949. fragmentShader: THREE.ShaderChunk[ 'shadow_frag' ]
  12950. } );
  12951. this.lights = true;
  12952. this.transparent = true;
  12953. Object.defineProperties( this, {
  12954. opacity: {
  12955. enumerable: true,
  12956. get: function () {
  12957. return this.uniforms.opacity.value;
  12958. },
  12959. set: function ( value ) {
  12960. this.uniforms.opacity.value = value;
  12961. }
  12962. }
  12963. } );
  12964. };
  12965. THREE.ShadowMaterial.prototype = Object.create( THREE.ShaderMaterial.prototype );
  12966. THREE.ShadowMaterial.prototype.constructor = THREE.ShadowMaterial;
  12967. // File:src/textures/Texture.js
  12968. /**
  12969. * @author mrdoob / http://mrdoob.com/
  12970. * @author alteredq / http://alteredqualia.com/
  12971. * @author szimek / https://github.com/szimek/
  12972. */
  12973. THREE.Texture = function ( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  12974. Object.defineProperty( this, 'id', { value: THREE.TextureIdCount ++ } );
  12975. this.uuid = THREE.Math.generateUUID();
  12976. this.name = '';
  12977. this.sourceFile = '';
  12978. this.image = image !== undefined ? image : THREE.Texture.DEFAULT_IMAGE;
  12979. this.mipmaps = [];
  12980. this.mapping = mapping !== undefined ? mapping : THREE.Texture.DEFAULT_MAPPING;
  12981. this.wrapS = wrapS !== undefined ? wrapS : THREE.ClampToEdgeWrapping;
  12982. this.wrapT = wrapT !== undefined ? wrapT : THREE.ClampToEdgeWrapping;
  12983. this.magFilter = magFilter !== undefined ? magFilter : THREE.LinearFilter;
  12984. this.minFilter = minFilter !== undefined ? minFilter : THREE.LinearMipMapLinearFilter;
  12985. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  12986. this.format = format !== undefined ? format : THREE.RGBAFormat;
  12987. this.type = type !== undefined ? type : THREE.UnsignedByteType;
  12988. this.offset = new THREE.Vector2( 0, 0 );
  12989. this.repeat = new THREE.Vector2( 1, 1 );
  12990. this.generateMipmaps = true;
  12991. this.premultiplyAlpha = false;
  12992. this.flipY = true;
  12993. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  12994. // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
  12995. //
  12996. // Also changing the encoding after already used by a Material will not automatically make the Material
  12997. // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
  12998. this.encoding = encoding !== undefined ? encoding : THREE.LinearEncoding;
  12999. this.version = 0;
  13000. this.onUpdate = null;
  13001. };
  13002. THREE.Texture.DEFAULT_IMAGE = undefined;
  13003. THREE.Texture.DEFAULT_MAPPING = THREE.UVMapping;
  13004. THREE.Texture.prototype = {
  13005. constructor: THREE.Texture,
  13006. set needsUpdate( value ) {
  13007. if ( value === true ) this.version ++;
  13008. },
  13009. clone: function () {
  13010. return new this.constructor().copy( this );
  13011. },
  13012. copy: function ( source ) {
  13013. this.image = source.image;
  13014. this.mipmaps = source.mipmaps.slice( 0 );
  13015. this.mapping = source.mapping;
  13016. this.wrapS = source.wrapS;
  13017. this.wrapT = source.wrapT;
  13018. this.magFilter = source.magFilter;
  13019. this.minFilter = source.minFilter;
  13020. this.anisotropy = source.anisotropy;
  13021. this.format = source.format;
  13022. this.type = source.type;
  13023. this.offset.copy( source.offset );
  13024. this.repeat.copy( source.repeat );
  13025. this.generateMipmaps = source.generateMipmaps;
  13026. this.premultiplyAlpha = source.premultiplyAlpha;
  13027. this.flipY = source.flipY;
  13028. this.unpackAlignment = source.unpackAlignment;
  13029. this.encoding = source.encoding;
  13030. return this;
  13031. },
  13032. toJSON: function ( meta ) {
  13033. if ( meta.textures[ this.uuid ] !== undefined ) {
  13034. return meta.textures[ this.uuid ];
  13035. }
  13036. function getDataURL( image ) {
  13037. var canvas;
  13038. if ( image.toDataURL !== undefined ) {
  13039. canvas = image;
  13040. } else {
  13041. canvas = document.createElement( 'canvas' );
  13042. canvas.width = image.width;
  13043. canvas.height = image.height;
  13044. canvas.getContext( '2d' ).drawImage( image, 0, 0, image.width, image.height );
  13045. }
  13046. if ( canvas.width > 2048 || canvas.height > 2048 ) {
  13047. return canvas.toDataURL( 'image/jpeg', 0.6 );
  13048. } else {
  13049. return canvas.toDataURL( 'image/png' );
  13050. }
  13051. }
  13052. var output = {
  13053. metadata: {
  13054. version: 4.4,
  13055. type: 'Texture',
  13056. generator: 'Texture.toJSON'
  13057. },
  13058. uuid: this.uuid,
  13059. name: this.name,
  13060. mapping: this.mapping,
  13061. repeat: [ this.repeat.x, this.repeat.y ],
  13062. offset: [ this.offset.x, this.offset.y ],
  13063. wrap: [ this.wrapS, this.wrapT ],
  13064. minFilter: this.minFilter,
  13065. magFilter: this.magFilter,
  13066. anisotropy: this.anisotropy
  13067. };
  13068. if ( this.image !== undefined ) {
  13069. // TODO: Move to THREE.Image
  13070. var image = this.image;
  13071. if ( image.uuid === undefined ) {
  13072. image.uuid = THREE.Math.generateUUID(); // UGH
  13073. }
  13074. if ( meta.images[ image.uuid ] === undefined ) {
  13075. meta.images[ image.uuid ] = {
  13076. uuid: image.uuid,
  13077. url: getDataURL( image )
  13078. };
  13079. }
  13080. output.image = image.uuid;
  13081. }
  13082. meta.textures[ this.uuid ] = output;
  13083. return output;
  13084. },
  13085. dispose: function () {
  13086. this.dispatchEvent( { type: 'dispose' } );
  13087. },
  13088. transformUv: function ( uv ) {
  13089. if ( this.mapping !== THREE.UVMapping ) return;
  13090. uv.multiply( this.repeat );
  13091. uv.add( this.offset );
  13092. if ( uv.x < 0 || uv.x > 1 ) {
  13093. switch ( this.wrapS ) {
  13094. case THREE.RepeatWrapping:
  13095. uv.x = uv.x - Math.floor( uv.x );
  13096. break;
  13097. case THREE.ClampToEdgeWrapping:
  13098. uv.x = uv.x < 0 ? 0 : 1;
  13099. break;
  13100. case THREE.MirroredRepeatWrapping:
  13101. if ( Math.abs( Math.floor( uv.x ) % 2 ) === 1 ) {
  13102. uv.x = Math.ceil( uv.x ) - uv.x;
  13103. } else {
  13104. uv.x = uv.x - Math.floor( uv.x );
  13105. }
  13106. break;
  13107. }
  13108. }
  13109. if ( uv.y < 0 || uv.y > 1 ) {
  13110. switch ( this.wrapT ) {
  13111. case THREE.RepeatWrapping:
  13112. uv.y = uv.y - Math.floor( uv.y );
  13113. break;
  13114. case THREE.ClampToEdgeWrapping:
  13115. uv.y = uv.y < 0 ? 0 : 1;
  13116. break;
  13117. case THREE.MirroredRepeatWrapping:
  13118. if ( Math.abs( Math.floor( uv.y ) % 2 ) === 1 ) {
  13119. uv.y = Math.ceil( uv.y ) - uv.y;
  13120. } else {
  13121. uv.y = uv.y - Math.floor( uv.y );
  13122. }
  13123. break;
  13124. }
  13125. }
  13126. if ( this.flipY ) {
  13127. uv.y = 1 - uv.y;
  13128. }
  13129. }
  13130. };
  13131. Object.assign( THREE.Texture.prototype, THREE.EventDispatcher.prototype );
  13132. THREE.TextureIdCount = 0;
  13133. // File:src/textures/DepthTexture.js
  13134. /**
  13135. * @author Matt DesLauriers / @mattdesl
  13136. */
  13137. THREE.DepthTexture = function ( width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy ) {
  13138. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, THREE.DepthFormat, type, anisotropy );
  13139. this.image = { width: width, height: height };
  13140. this.type = type !== undefined ? type : THREE.UnsignedShortType;
  13141. this.magFilter = magFilter !== undefined ? magFilter : THREE.NearestFilter;
  13142. this.minFilter = minFilter !== undefined ? minFilter : THREE.NearestFilter;
  13143. this.flipY = false;
  13144. this.generateMipmaps = false;
  13145. };
  13146. THREE.DepthTexture.prototype = Object.create( THREE.Texture.prototype );
  13147. THREE.DepthTexture.prototype.constructor = THREE.DepthTexture;
  13148. // File:src/textures/CanvasTexture.js
  13149. /**
  13150. * @author mrdoob / http://mrdoob.com/
  13151. */
  13152. THREE.CanvasTexture = function ( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  13153. THREE.Texture.call( this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  13154. this.needsUpdate = true;
  13155. };
  13156. THREE.CanvasTexture.prototype = Object.create( THREE.Texture.prototype );
  13157. THREE.CanvasTexture.prototype.constructor = THREE.CanvasTexture;
  13158. // File:src/textures/CubeTexture.js
  13159. /**
  13160. * @author mrdoob / http://mrdoob.com/
  13161. */
  13162. THREE.CubeTexture = function ( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  13163. images = images !== undefined ? images : [];
  13164. mapping = mapping !== undefined ? mapping : THREE.CubeReflectionMapping;
  13165. THREE.Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  13166. this.flipY = false;
  13167. };
  13168. THREE.CubeTexture.prototype = Object.create( THREE.Texture.prototype );
  13169. THREE.CubeTexture.prototype.constructor = THREE.CubeTexture;
  13170. Object.defineProperty( THREE.CubeTexture.prototype, 'images', {
  13171. get: function () {
  13172. return this.image;
  13173. },
  13174. set: function ( value ) {
  13175. this.image = value;
  13176. }
  13177. } );
  13178. // File:src/textures/CompressedTexture.js
  13179. /**
  13180. * @author alteredq / http://alteredqualia.com/
  13181. */
  13182. THREE.CompressedTexture = function ( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  13183. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  13184. this.image = { width: width, height: height };
  13185. this.mipmaps = mipmaps;
  13186. // no flipping for cube textures
  13187. // (also flipping doesn't work for compressed textures )
  13188. this.flipY = false;
  13189. // can't generate mipmaps for compressed textures
  13190. // mips must be embedded in DDS files
  13191. this.generateMipmaps = false;
  13192. };
  13193. THREE.CompressedTexture.prototype = Object.create( THREE.Texture.prototype );
  13194. THREE.CompressedTexture.prototype.constructor = THREE.CompressedTexture;
  13195. // File:src/textures/DataTexture.js
  13196. /**
  13197. * @author alteredq / http://alteredqualia.com/
  13198. */
  13199. THREE.DataTexture = function ( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  13200. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  13201. this.image = { data: data, width: width, height: height };
  13202. this.magFilter = magFilter !== undefined ? magFilter : THREE.NearestFilter;
  13203. this.minFilter = minFilter !== undefined ? minFilter : THREE.NearestFilter;
  13204. this.flipY = false;
  13205. this.generateMipmaps = false;
  13206. };
  13207. THREE.DataTexture.prototype = Object.create( THREE.Texture.prototype );
  13208. THREE.DataTexture.prototype.constructor = THREE.DataTexture;
  13209. // File:src/textures/VideoTexture.js
  13210. /**
  13211. * @author mrdoob / http://mrdoob.com/
  13212. */
  13213. THREE.VideoTexture = function ( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  13214. THREE.Texture.call( this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  13215. this.generateMipmaps = false;
  13216. var scope = this;
  13217. function update() {
  13218. requestAnimationFrame( update );
  13219. if ( video.readyState >= video.HAVE_CURRENT_DATA ) {
  13220. scope.needsUpdate = true;
  13221. }
  13222. }
  13223. update();
  13224. };
  13225. THREE.VideoTexture.prototype = Object.create( THREE.Texture.prototype );
  13226. THREE.VideoTexture.prototype.constructor = THREE.VideoTexture;
  13227. // File:src/objects/Group.js
  13228. /**
  13229. * @author mrdoob / http://mrdoob.com/
  13230. */
  13231. THREE.Group = function () {
  13232. THREE.Object3D.call( this );
  13233. this.type = 'Group';
  13234. };
  13235. THREE.Group.prototype = Object.assign( Object.create( THREE.Object3D.prototype ), {
  13236. constructor: THREE.Group
  13237. } );
  13238. // File:src/objects/Points.js
  13239. /**
  13240. * @author alteredq / http://alteredqualia.com/
  13241. */
  13242. THREE.Points = function ( geometry, material ) {
  13243. THREE.Object3D.call( this );
  13244. this.type = 'Points';
  13245. this.geometry = geometry !== undefined ? geometry : new THREE.BufferGeometry();
  13246. this.material = material !== undefined ? material : new THREE.PointsMaterial( { color: Math.random() * 0xffffff } );
  13247. };
  13248. THREE.Points.prototype = Object.assign( Object.create( THREE.Object3D.prototype ), {
  13249. constructor: THREE.Points,
  13250. raycast: ( function () {
  13251. var inverseMatrix = new THREE.Matrix4();
  13252. var ray = new THREE.Ray();
  13253. var sphere = new THREE.Sphere();
  13254. return function raycast( raycaster, intersects ) {
  13255. var object = this;
  13256. var geometry = this.geometry;
  13257. var matrixWorld = this.matrixWorld;
  13258. var threshold = raycaster.params.Points.threshold;
  13259. // Checking boundingSphere distance to ray
  13260. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  13261. sphere.copy( geometry.boundingSphere );
  13262. sphere.applyMatrix4( matrixWorld );
  13263. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  13264. //
  13265. inverseMatrix.getInverse( matrixWorld );
  13266. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  13267. var localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  13268. var localThresholdSq = localThreshold * localThreshold;
  13269. var position = new THREE.Vector3();
  13270. function testPoint( point, index ) {
  13271. var rayPointDistanceSq = ray.distanceSqToPoint( point );
  13272. if ( rayPointDistanceSq < localThresholdSq ) {
  13273. var intersectPoint = ray.closestPointToPoint( point );
  13274. intersectPoint.applyMatrix4( matrixWorld );
  13275. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  13276. if ( distance < raycaster.near || distance > raycaster.far ) return;
  13277. intersects.push( {
  13278. distance: distance,
  13279. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  13280. point: intersectPoint.clone(),
  13281. index: index,
  13282. face: null,
  13283. object: object
  13284. } );
  13285. }
  13286. }
  13287. if ( geometry instanceof THREE.BufferGeometry ) {
  13288. var index = geometry.index;
  13289. var attributes = geometry.attributes;
  13290. var positions = attributes.position.array;
  13291. if ( index !== null ) {
  13292. var indices = index.array;
  13293. for ( var i = 0, il = indices.length; i < il; i ++ ) {
  13294. var a = indices[ i ];
  13295. position.fromArray( positions, a * 3 );
  13296. testPoint( position, a );
  13297. }
  13298. } else {
  13299. for ( var i = 0, l = positions.length / 3; i < l; i ++ ) {
  13300. position.fromArray( positions, i * 3 );
  13301. testPoint( position, i );
  13302. }
  13303. }
  13304. } else {
  13305. var vertices = geometry.vertices;
  13306. for ( var i = 0, l = vertices.length; i < l; i ++ ) {
  13307. testPoint( vertices[ i ], i );
  13308. }
  13309. }
  13310. };
  13311. }() ),
  13312. clone: function () {
  13313. return new this.constructor( this.geometry, this.material ).copy( this );
  13314. }
  13315. } );
  13316. // File:src/objects/Line.js
  13317. /**
  13318. * @author mrdoob / http://mrdoob.com/
  13319. */
  13320. THREE.Line = function ( geometry, material, mode ) {
  13321. if ( mode === 1 ) {
  13322. console.warn( 'THREE.Line: parameter THREE.LinePieces no longer supported. Created THREE.LineSegments instead.' );
  13323. return new THREE.LineSegments( geometry, material );
  13324. }
  13325. THREE.Object3D.call( this );
  13326. this.type = 'Line';
  13327. this.geometry = geometry !== undefined ? geometry : new THREE.BufferGeometry();
  13328. this.material = material !== undefined ? material : new THREE.LineBasicMaterial( { color: Math.random() * 0xffffff } );
  13329. };
  13330. THREE.Line.prototype = Object.assign( Object.create( THREE.Object3D.prototype ), {
  13331. constructor: THREE.Line,
  13332. raycast: ( function () {
  13333. var inverseMatrix = new THREE.Matrix4();
  13334. var ray = new THREE.Ray();
  13335. var sphere = new THREE.Sphere();
  13336. return function raycast( raycaster, intersects ) {
  13337. var precision = raycaster.linePrecision;
  13338. var precisionSq = precision * precision;
  13339. var geometry = this.geometry;
  13340. var matrixWorld = this.matrixWorld;
  13341. // Checking boundingSphere distance to ray
  13342. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  13343. sphere.copy( geometry.boundingSphere );
  13344. sphere.applyMatrix4( matrixWorld );
  13345. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  13346. //
  13347. inverseMatrix.getInverse( matrixWorld );
  13348. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  13349. var vStart = new THREE.Vector3();
  13350. var vEnd = new THREE.Vector3();
  13351. var interSegment = new THREE.Vector3();
  13352. var interRay = new THREE.Vector3();
  13353. var step = this instanceof THREE.LineSegments ? 2 : 1;
  13354. if ( geometry instanceof THREE.BufferGeometry ) {
  13355. var index = geometry.index;
  13356. var attributes = geometry.attributes;
  13357. var positions = attributes.position.array;
  13358. if ( index !== null ) {
  13359. var indices = index.array;
  13360. for ( var i = 0, l = indices.length - 1; i < l; i += step ) {
  13361. var a = indices[ i ];
  13362. var b = indices[ i + 1 ];
  13363. vStart.fromArray( positions, a * 3 );
  13364. vEnd.fromArray( positions, b * 3 );
  13365. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  13366. if ( distSq > precisionSq ) continue;
  13367. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  13368. var distance = raycaster.ray.origin.distanceTo( interRay );
  13369. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  13370. intersects.push( {
  13371. distance: distance,
  13372. // What do we want? intersection point on the ray or on the segment??
  13373. // point: raycaster.ray.at( distance ),
  13374. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  13375. index: i,
  13376. face: null,
  13377. faceIndex: null,
  13378. object: this
  13379. } );
  13380. }
  13381. } else {
  13382. for ( var i = 0, l = positions.length / 3 - 1; i < l; i += step ) {
  13383. vStart.fromArray( positions, 3 * i );
  13384. vEnd.fromArray( positions, 3 * i + 3 );
  13385. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  13386. if ( distSq > precisionSq ) continue;
  13387. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  13388. var distance = raycaster.ray.origin.distanceTo( interRay );
  13389. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  13390. intersects.push( {
  13391. distance: distance,
  13392. // What do we want? intersection point on the ray or on the segment??
  13393. // point: raycaster.ray.at( distance ),
  13394. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  13395. index: i,
  13396. face: null,
  13397. faceIndex: null,
  13398. object: this
  13399. } );
  13400. }
  13401. }
  13402. } else if ( geometry instanceof THREE.Geometry ) {
  13403. var vertices = geometry.vertices;
  13404. var nbVertices = vertices.length;
  13405. for ( var i = 0; i < nbVertices - 1; i += step ) {
  13406. var distSq = ray.distanceSqToSegment( vertices[ i ], vertices[ i + 1 ], interRay, interSegment );
  13407. if ( distSq > precisionSq ) continue;
  13408. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  13409. var distance = raycaster.ray.origin.distanceTo( interRay );
  13410. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  13411. intersects.push( {
  13412. distance: distance,
  13413. // What do we want? intersection point on the ray or on the segment??
  13414. // point: raycaster.ray.at( distance ),
  13415. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  13416. index: i,
  13417. face: null,
  13418. faceIndex: null,
  13419. object: this
  13420. } );
  13421. }
  13422. }
  13423. };
  13424. }() ),
  13425. clone: function () {
  13426. return new this.constructor( this.geometry, this.material ).copy( this );
  13427. }
  13428. } );
  13429. // File:src/objects/LineSegments.js
  13430. /**
  13431. * @author mrdoob / http://mrdoob.com/
  13432. */
  13433. THREE.LineSegments = function ( geometry, material ) {
  13434. THREE.Line.call( this, geometry, material );
  13435. this.type = 'LineSegments';
  13436. };
  13437. THREE.LineSegments.prototype = Object.assign( Object.create( THREE.Line.prototype ), {
  13438. constructor: THREE.LineSegments
  13439. } );
  13440. // File:src/objects/Mesh.js
  13441. /**
  13442. * @author mrdoob / http://mrdoob.com/
  13443. * @author alteredq / http://alteredqualia.com/
  13444. * @author mikael emtinger / http://gomo.se/
  13445. * @author jonobr1 / http://jonobr1.com/
  13446. */
  13447. THREE.Mesh = function ( geometry, material ) {
  13448. THREE.Object3D.call( this );
  13449. this.type = 'Mesh';
  13450. this.geometry = geometry !== undefined ? geometry : new THREE.BufferGeometry();
  13451. this.material = material !== undefined ? material : new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff } );
  13452. this.drawMode = THREE.TrianglesDrawMode;
  13453. this.updateMorphTargets();
  13454. };
  13455. THREE.Mesh.prototype = Object.assign( Object.create( THREE.Object3D.prototype ), {
  13456. constructor: THREE.Mesh,
  13457. setDrawMode: function ( value ) {
  13458. this.drawMode = value;
  13459. },
  13460. updateMorphTargets: function () {
  13461. if ( this.geometry.morphTargets !== undefined && this.geometry.morphTargets.length > 0 ) {
  13462. this.morphTargetBase = - 1;
  13463. this.morphTargetInfluences = [];
  13464. this.morphTargetDictionary = {};
  13465. for ( var m = 0, ml = this.geometry.morphTargets.length; m < ml; m ++ ) {
  13466. this.morphTargetInfluences.push( 0 );
  13467. this.morphTargetDictionary[ this.geometry.morphTargets[ m ].name ] = m;
  13468. }
  13469. }
  13470. },
  13471. getMorphTargetIndexByName: function ( name ) {
  13472. if ( this.morphTargetDictionary[ name ] !== undefined ) {
  13473. return this.morphTargetDictionary[ name ];
  13474. }
  13475. console.warn( 'THREE.Mesh.getMorphTargetIndexByName: morph target ' + name + ' does not exist. Returning 0.' );
  13476. return 0;
  13477. },
  13478. raycast: ( function () {
  13479. var inverseMatrix = new THREE.Matrix4();
  13480. var ray = new THREE.Ray();
  13481. var sphere = new THREE.Sphere();
  13482. var vA = new THREE.Vector3();
  13483. var vB = new THREE.Vector3();
  13484. var vC = new THREE.Vector3();
  13485. var tempA = new THREE.Vector3();
  13486. var tempB = new THREE.Vector3();
  13487. var tempC = new THREE.Vector3();
  13488. var uvA = new THREE.Vector2();
  13489. var uvB = new THREE.Vector2();
  13490. var uvC = new THREE.Vector2();
  13491. var barycoord = new THREE.Vector3();
  13492. var intersectionPoint = new THREE.Vector3();
  13493. var intersectionPointWorld = new THREE.Vector3();
  13494. function uvIntersection( point, p1, p2, p3, uv1, uv2, uv3 ) {
  13495. THREE.Triangle.barycoordFromPoint( point, p1, p2, p3, barycoord );
  13496. uv1.multiplyScalar( barycoord.x );
  13497. uv2.multiplyScalar( barycoord.y );
  13498. uv3.multiplyScalar( barycoord.z );
  13499. uv1.add( uv2 ).add( uv3 );
  13500. return uv1.clone();
  13501. }
  13502. function checkIntersection( object, raycaster, ray, pA, pB, pC, point ) {
  13503. var intersect;
  13504. var material = object.material;
  13505. if ( material.side === THREE.BackSide ) {
  13506. intersect = ray.intersectTriangle( pC, pB, pA, true, point );
  13507. } else {
  13508. intersect = ray.intersectTriangle( pA, pB, pC, material.side !== THREE.DoubleSide, point );
  13509. }
  13510. if ( intersect === null ) return null;
  13511. intersectionPointWorld.copy( point );
  13512. intersectionPointWorld.applyMatrix4( object.matrixWorld );
  13513. var distance = raycaster.ray.origin.distanceTo( intersectionPointWorld );
  13514. if ( distance < raycaster.near || distance > raycaster.far ) return null;
  13515. return {
  13516. distance: distance,
  13517. point: intersectionPointWorld.clone(),
  13518. object: object
  13519. };
  13520. }
  13521. function checkBufferGeometryIntersection( object, raycaster, ray, positions, uvs, a, b, c ) {
  13522. vA.fromArray( positions, a * 3 );
  13523. vB.fromArray( positions, b * 3 );
  13524. vC.fromArray( positions, c * 3 );
  13525. var intersection = checkIntersection( object, raycaster, ray, vA, vB, vC, intersectionPoint );
  13526. if ( intersection ) {
  13527. if ( uvs ) {
  13528. uvA.fromArray( uvs, a * 2 );
  13529. uvB.fromArray( uvs, b * 2 );
  13530. uvC.fromArray( uvs, c * 2 );
  13531. intersection.uv = uvIntersection( intersectionPoint, vA, vB, vC, uvA, uvB, uvC );
  13532. }
  13533. intersection.face = new THREE.Face3( a, b, c, THREE.Triangle.normal( vA, vB, vC ) );
  13534. intersection.faceIndex = a;
  13535. }
  13536. return intersection;
  13537. }
  13538. return function raycast( raycaster, intersects ) {
  13539. var geometry = this.geometry;
  13540. var material = this.material;
  13541. var matrixWorld = this.matrixWorld;
  13542. if ( material === undefined ) return;
  13543. // Checking boundingSphere distance to ray
  13544. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  13545. sphere.copy( geometry.boundingSphere );
  13546. sphere.applyMatrix4( matrixWorld );
  13547. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  13548. //
  13549. inverseMatrix.getInverse( matrixWorld );
  13550. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  13551. // Check boundingBox before continuing
  13552. if ( geometry.boundingBox !== null ) {
  13553. if ( ray.intersectsBox( geometry.boundingBox ) === false ) return;
  13554. }
  13555. var uvs, intersection;
  13556. if ( geometry instanceof THREE.BufferGeometry ) {
  13557. var a, b, c;
  13558. var index = geometry.index;
  13559. var attributes = geometry.attributes;
  13560. var positions = attributes.position.array;
  13561. if ( attributes.uv !== undefined ) {
  13562. uvs = attributes.uv.array;
  13563. }
  13564. if ( index !== null ) {
  13565. var indices = index.array;
  13566. for ( var i = 0, l = indices.length; i < l; i += 3 ) {
  13567. a = indices[ i ];
  13568. b = indices[ i + 1 ];
  13569. c = indices[ i + 2 ];
  13570. intersection = checkBufferGeometryIntersection( this, raycaster, ray, positions, uvs, a, b, c );
  13571. if ( intersection ) {
  13572. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in indices buffer semantics
  13573. intersects.push( intersection );
  13574. }
  13575. }
  13576. } else {
  13577. for ( var i = 0, l = positions.length; i < l; i += 9 ) {
  13578. a = i / 3;
  13579. b = a + 1;
  13580. c = a + 2;
  13581. intersection = checkBufferGeometryIntersection( this, raycaster, ray, positions, uvs, a, b, c );
  13582. if ( intersection ) {
  13583. intersection.index = a; // triangle number in positions buffer semantics
  13584. intersects.push( intersection );
  13585. }
  13586. }
  13587. }
  13588. } else if ( geometry instanceof THREE.Geometry ) {
  13589. var fvA, fvB, fvC;
  13590. var isFaceMaterial = material instanceof THREE.MultiMaterial;
  13591. var materials = isFaceMaterial === true ? material.materials : null;
  13592. var vertices = geometry.vertices;
  13593. var faces = geometry.faces;
  13594. var faceVertexUvs = geometry.faceVertexUvs[ 0 ];
  13595. if ( faceVertexUvs.length > 0 ) uvs = faceVertexUvs;
  13596. for ( var f = 0, fl = faces.length; f < fl; f ++ ) {
  13597. var face = faces[ f ];
  13598. var faceMaterial = isFaceMaterial === true ? materials[ face.materialIndex ] : material;
  13599. if ( faceMaterial === undefined ) continue;
  13600. fvA = vertices[ face.a ];
  13601. fvB = vertices[ face.b ];
  13602. fvC = vertices[ face.c ];
  13603. if ( faceMaterial.morphTargets === true ) {
  13604. var morphTargets = geometry.morphTargets;
  13605. var morphInfluences = this.morphTargetInfluences;
  13606. vA.set( 0, 0, 0 );
  13607. vB.set( 0, 0, 0 );
  13608. vC.set( 0, 0, 0 );
  13609. for ( var t = 0, tl = morphTargets.length; t < tl; t ++ ) {
  13610. var influence = morphInfluences[ t ];
  13611. if ( influence === 0 ) continue;
  13612. var targets = morphTargets[ t ].vertices;
  13613. vA.addScaledVector( tempA.subVectors( targets[ face.a ], fvA ), influence );
  13614. vB.addScaledVector( tempB.subVectors( targets[ face.b ], fvB ), influence );
  13615. vC.addScaledVector( tempC.subVectors( targets[ face.c ], fvC ), influence );
  13616. }
  13617. vA.add( fvA );
  13618. vB.add( fvB );
  13619. vC.add( fvC );
  13620. fvA = vA;
  13621. fvB = vB;
  13622. fvC = vC;
  13623. }
  13624. intersection = checkIntersection( this, raycaster, ray, fvA, fvB, fvC, intersectionPoint );
  13625. if ( intersection ) {
  13626. if ( uvs ) {
  13627. var uvs_f = uvs[ f ];
  13628. uvA.copy( uvs_f[ 0 ] );
  13629. uvB.copy( uvs_f[ 1 ] );
  13630. uvC.copy( uvs_f[ 2 ] );
  13631. intersection.uv = uvIntersection( intersectionPoint, fvA, fvB, fvC, uvA, uvB, uvC );
  13632. }
  13633. intersection.face = face;
  13634. intersection.faceIndex = f;
  13635. intersects.push( intersection );
  13636. }
  13637. }
  13638. }
  13639. };
  13640. }() ),
  13641. clone: function () {
  13642. return new this.constructor( this.geometry, this.material ).copy( this );
  13643. }
  13644. } );
  13645. // File:src/objects/Bone.js
  13646. /**
  13647. * @author mikael emtinger / http://gomo.se/
  13648. * @author alteredq / http://alteredqualia.com/
  13649. * @author ikerr / http://verold.com
  13650. */
  13651. THREE.Bone = function ( skin ) {
  13652. THREE.Object3D.call( this );
  13653. this.type = 'Bone';
  13654. this.skin = skin;
  13655. };
  13656. THREE.Bone.prototype = Object.assign( Object.create( THREE.Object3D.prototype ), {
  13657. constructor: THREE.Bone,
  13658. copy: function ( source ) {
  13659. THREE.Object3D.prototype.copy.call( this, source );
  13660. this.skin = source.skin;
  13661. return this;
  13662. }
  13663. } );
  13664. // File:src/objects/Skeleton.js
  13665. /**
  13666. * @author mikael emtinger / http://gomo.se/
  13667. * @author alteredq / http://alteredqualia.com/
  13668. * @author michael guerrero / http://realitymeltdown.com
  13669. * @author ikerr / http://verold.com
  13670. */
  13671. THREE.Skeleton = function ( bones, boneInverses, useVertexTexture ) {
  13672. this.useVertexTexture = useVertexTexture !== undefined ? useVertexTexture : true;
  13673. this.identityMatrix = new THREE.Matrix4();
  13674. // copy the bone array
  13675. bones = bones || [];
  13676. this.bones = bones.slice( 0 );
  13677. // create a bone texture or an array of floats
  13678. if ( this.useVertexTexture ) {
  13679. // layout (1 matrix = 4 pixels)
  13680. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  13681. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  13682. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  13683. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  13684. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  13685. var size = Math.sqrt( this.bones.length * 4 ); // 4 pixels needed for 1 matrix
  13686. size = THREE.Math.nextPowerOfTwo( Math.ceil( size ) );
  13687. size = Math.max( size, 4 );
  13688. this.boneTextureWidth = size;
  13689. this.boneTextureHeight = size;
  13690. this.boneMatrices = new Float32Array( this.boneTextureWidth * this.boneTextureHeight * 4 ); // 4 floats per RGBA pixel
  13691. this.boneTexture = new THREE.DataTexture( this.boneMatrices, this.boneTextureWidth, this.boneTextureHeight, THREE.RGBAFormat, THREE.FloatType );
  13692. } else {
  13693. this.boneMatrices = new Float32Array( 16 * this.bones.length );
  13694. }
  13695. // use the supplied bone inverses or calculate the inverses
  13696. if ( boneInverses === undefined ) {
  13697. this.calculateInverses();
  13698. } else {
  13699. if ( this.bones.length === boneInverses.length ) {
  13700. this.boneInverses = boneInverses.slice( 0 );
  13701. } else {
  13702. console.warn( 'THREE.Skeleton bonInverses is the wrong length.' );
  13703. this.boneInverses = [];
  13704. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13705. this.boneInverses.push( new THREE.Matrix4() );
  13706. }
  13707. }
  13708. }
  13709. };
  13710. Object.assign( THREE.Skeleton.prototype, {
  13711. calculateInverses: function () {
  13712. this.boneInverses = [];
  13713. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13714. var inverse = new THREE.Matrix4();
  13715. if ( this.bones[ b ] ) {
  13716. inverse.getInverse( this.bones[ b ].matrixWorld );
  13717. }
  13718. this.boneInverses.push( inverse );
  13719. }
  13720. },
  13721. pose: function () {
  13722. var bone;
  13723. // recover the bind-time world matrices
  13724. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13725. bone = this.bones[ b ];
  13726. if ( bone ) {
  13727. bone.matrixWorld.getInverse( this.boneInverses[ b ] );
  13728. }
  13729. }
  13730. // compute the local matrices, positions, rotations and scales
  13731. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13732. bone = this.bones[ b ];
  13733. if ( bone ) {
  13734. if ( bone.parent ) {
  13735. bone.matrix.getInverse( bone.parent.matrixWorld );
  13736. bone.matrix.multiply( bone.matrixWorld );
  13737. } else {
  13738. bone.matrix.copy( bone.matrixWorld );
  13739. }
  13740. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  13741. }
  13742. }
  13743. },
  13744. update: ( function () {
  13745. var offsetMatrix = new THREE.Matrix4();
  13746. return function update() {
  13747. // flatten bone matrices to array
  13748. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13749. // compute the offset between the current and the original transform
  13750. var matrix = this.bones[ b ] ? this.bones[ b ].matrixWorld : this.identityMatrix;
  13751. offsetMatrix.multiplyMatrices( matrix, this.boneInverses[ b ] );
  13752. offsetMatrix.toArray( this.boneMatrices, b * 16 );
  13753. }
  13754. if ( this.useVertexTexture ) {
  13755. this.boneTexture.needsUpdate = true;
  13756. }
  13757. };
  13758. } )(),
  13759. clone: function () {
  13760. return new THREE.Skeleton( this.bones, this.boneInverses, this.useVertexTexture );
  13761. }
  13762. } );
  13763. // File:src/objects/SkinnedMesh.js
  13764. /**
  13765. * @author mikael emtinger / http://gomo.se/
  13766. * @author alteredq / http://alteredqualia.com/
  13767. * @author ikerr / http://verold.com
  13768. */
  13769. THREE.SkinnedMesh = function ( geometry, material, useVertexTexture ) {
  13770. THREE.Mesh.call( this, geometry, material );
  13771. this.type = 'SkinnedMesh';
  13772. this.bindMode = "attached";
  13773. this.bindMatrix = new THREE.Matrix4();
  13774. this.bindMatrixInverse = new THREE.Matrix4();
  13775. // init bones
  13776. // TODO: remove bone creation as there is no reason (other than
  13777. // convenience) for THREE.SkinnedMesh to do this.
  13778. var bones = [];
  13779. if ( this.geometry && this.geometry.bones !== undefined ) {
  13780. var bone, gbone;
  13781. for ( var b = 0, bl = this.geometry.bones.length; b < bl; ++ b ) {
  13782. gbone = this.geometry.bones[ b ];
  13783. bone = new THREE.Bone( this );
  13784. bones.push( bone );
  13785. bone.name = gbone.name;
  13786. bone.position.fromArray( gbone.pos );
  13787. bone.quaternion.fromArray( gbone.rotq );
  13788. if ( gbone.scl !== undefined ) bone.scale.fromArray( gbone.scl );
  13789. }
  13790. for ( var b = 0, bl = this.geometry.bones.length; b < bl; ++ b ) {
  13791. gbone = this.geometry.bones[ b ];
  13792. if ( gbone.parent !== - 1 && gbone.parent !== null &&
  13793. bones[ gbone.parent ] !== undefined ) {
  13794. bones[ gbone.parent ].add( bones[ b ] );
  13795. } else {
  13796. this.add( bones[ b ] );
  13797. }
  13798. }
  13799. }
  13800. this.normalizeSkinWeights();
  13801. this.updateMatrixWorld( true );
  13802. this.bind( new THREE.Skeleton( bones, undefined, useVertexTexture ), this.matrixWorld );
  13803. };
  13804. THREE.SkinnedMesh.prototype = Object.assign( Object.create( THREE.Mesh.prototype ), {
  13805. constructor: THREE.SkinnedMesh,
  13806. bind: function( skeleton, bindMatrix ) {
  13807. this.skeleton = skeleton;
  13808. if ( bindMatrix === undefined ) {
  13809. this.updateMatrixWorld( true );
  13810. this.skeleton.calculateInverses();
  13811. bindMatrix = this.matrixWorld;
  13812. }
  13813. this.bindMatrix.copy( bindMatrix );
  13814. this.bindMatrixInverse.getInverse( bindMatrix );
  13815. },
  13816. pose: function () {
  13817. this.skeleton.pose();
  13818. },
  13819. normalizeSkinWeights: function () {
  13820. if ( this.geometry instanceof THREE.Geometry ) {
  13821. for ( var i = 0; i < this.geometry.skinWeights.length; i ++ ) {
  13822. var sw = this.geometry.skinWeights[ i ];
  13823. var scale = 1.0 / sw.lengthManhattan();
  13824. if ( scale !== Infinity ) {
  13825. sw.multiplyScalar( scale );
  13826. } else {
  13827. sw.set( 1, 0, 0, 0 ); // do something reasonable
  13828. }
  13829. }
  13830. } else if ( this.geometry instanceof THREE.BufferGeometry ) {
  13831. var vec = new THREE.Vector4();
  13832. var skinWeight = this.geometry.attributes.skinWeight;
  13833. for ( var i = 0; i < skinWeight.count; i ++ ) {
  13834. vec.x = skinWeight.getX( i );
  13835. vec.y = skinWeight.getY( i );
  13836. vec.z = skinWeight.getZ( i );
  13837. vec.w = skinWeight.getW( i );
  13838. var scale = 1.0 / vec.lengthManhattan();
  13839. if ( scale !== Infinity ) {
  13840. vec.multiplyScalar( scale );
  13841. } else {
  13842. vec.set( 1, 0, 0, 0 ); // do something reasonable
  13843. }
  13844. skinWeight.setXYZW( i, vec.x, vec.y, vec.z, vec.w );
  13845. }
  13846. }
  13847. },
  13848. updateMatrixWorld: function( force ) {
  13849. THREE.Mesh.prototype.updateMatrixWorld.call( this, true );
  13850. if ( this.bindMode === "attached" ) {
  13851. this.bindMatrixInverse.getInverse( this.matrixWorld );
  13852. } else if ( this.bindMode === "detached" ) {
  13853. this.bindMatrixInverse.getInverse( this.bindMatrix );
  13854. } else {
  13855. console.warn( 'THREE.SkinnedMesh unrecognized bindMode: ' + this.bindMode );
  13856. }
  13857. },
  13858. clone: function() {
  13859. return new this.constructor( this.geometry, this.material, this.useVertexTexture ).copy( this );
  13860. }
  13861. } );
  13862. // File:src/objects/LOD.js
  13863. /**
  13864. * @author mikael emtinger / http://gomo.se/
  13865. * @author alteredq / http://alteredqualia.com/
  13866. * @author mrdoob / http://mrdoob.com/
  13867. */
  13868. THREE.LOD = function () {
  13869. THREE.Object3D.call( this );
  13870. this.type = 'LOD';
  13871. Object.defineProperties( this, {
  13872. levels: {
  13873. enumerable: true,
  13874. value: []
  13875. }
  13876. } );
  13877. };
  13878. THREE.LOD.prototype = Object.assign( Object.create( THREE.Object3D.prototype ), {
  13879. constructor: THREE.LOD,
  13880. copy: function ( source ) {
  13881. THREE.Object3D.prototype.copy.call( this, source, false );
  13882. var levels = source.levels;
  13883. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  13884. var level = levels[ i ];
  13885. this.addLevel( level.object.clone(), level.distance );
  13886. }
  13887. return this;
  13888. },
  13889. addLevel: function ( object, distance ) {
  13890. if ( distance === undefined ) distance = 0;
  13891. distance = Math.abs( distance );
  13892. var levels = this.levels;
  13893. for ( var l = 0; l < levels.length; l ++ ) {
  13894. if ( distance < levels[ l ].distance ) {
  13895. break;
  13896. }
  13897. }
  13898. levels.splice( l, 0, { distance: distance, object: object } );
  13899. this.add( object );
  13900. },
  13901. getObjectForDistance: function ( distance ) {
  13902. var levels = this.levels;
  13903. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  13904. if ( distance < levels[ i ].distance ) {
  13905. break;
  13906. }
  13907. }
  13908. return levels[ i - 1 ].object;
  13909. },
  13910. raycast: ( function () {
  13911. var matrixPosition = new THREE.Vector3();
  13912. return function raycast( raycaster, intersects ) {
  13913. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  13914. var distance = raycaster.ray.origin.distanceTo( matrixPosition );
  13915. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  13916. };
  13917. }() ),
  13918. update: function () {
  13919. var v1 = new THREE.Vector3();
  13920. var v2 = new THREE.Vector3();
  13921. return function update( camera ) {
  13922. var levels = this.levels;
  13923. if ( levels.length > 1 ) {
  13924. v1.setFromMatrixPosition( camera.matrixWorld );
  13925. v2.setFromMatrixPosition( this.matrixWorld );
  13926. var distance = v1.distanceTo( v2 );
  13927. levels[ 0 ].object.visible = true;
  13928. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  13929. if ( distance >= levels[ i ].distance ) {
  13930. levels[ i - 1 ].object.visible = false;
  13931. levels[ i ].object.visible = true;
  13932. } else {
  13933. break;
  13934. }
  13935. }
  13936. for ( ; i < l; i ++ ) {
  13937. levels[ i ].object.visible = false;
  13938. }
  13939. }
  13940. };
  13941. }(),
  13942. toJSON: function ( meta ) {
  13943. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  13944. data.object.levels = [];
  13945. var levels = this.levels;
  13946. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  13947. var level = levels[ i ];
  13948. data.object.levels.push( {
  13949. object: level.object.uuid,
  13950. distance: level.distance
  13951. } );
  13952. }
  13953. return data;
  13954. }
  13955. } );
  13956. // File:src/objects/Sprite.js
  13957. /**
  13958. * @author mikael emtinger / http://gomo.se/
  13959. * @author alteredq / http://alteredqualia.com/
  13960. */
  13961. THREE.Sprite = function ( material ) {
  13962. THREE.Object3D.call( this );
  13963. this.type = 'Sprite';
  13964. this.material = ( material !== undefined ) ? material : new THREE.SpriteMaterial();
  13965. };
  13966. THREE.Sprite.prototype = Object.assign( Object.create( THREE.Object3D.prototype ), {
  13967. constructor: THREE.Sprite,
  13968. raycast: ( function () {
  13969. var matrixPosition = new THREE.Vector3();
  13970. return function raycast( raycaster, intersects ) {
  13971. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  13972. var distanceSq = raycaster.ray.distanceSqToPoint( matrixPosition );
  13973. var guessSizeSq = this.scale.x * this.scale.y / 4;
  13974. if ( distanceSq > guessSizeSq ) {
  13975. return;
  13976. }
  13977. intersects.push( {
  13978. distance: Math.sqrt( distanceSq ),
  13979. point: this.position,
  13980. face: null,
  13981. object: this
  13982. } );
  13983. };
  13984. }() ),
  13985. clone: function () {
  13986. return new this.constructor( this.material ).copy( this );
  13987. }
  13988. } );
  13989. // File:src/objects/LensFlare.js
  13990. /**
  13991. * @author mikael emtinger / http://gomo.se/
  13992. * @author alteredq / http://alteredqualia.com/
  13993. */
  13994. THREE.LensFlare = function ( texture, size, distance, blending, color ) {
  13995. THREE.Object3D.call( this );
  13996. this.lensFlares = [];
  13997. this.positionScreen = new THREE.Vector3();
  13998. this.customUpdateCallback = undefined;
  13999. if ( texture !== undefined ) {
  14000. this.add( texture, size, distance, blending, color );
  14001. }
  14002. };
  14003. THREE.LensFlare.prototype = Object.assign( Object.create( THREE.Object3D.prototype ), {
  14004. constructor: THREE.LensFlare,
  14005. copy: function ( source ) {
  14006. THREE.Object3D.prototype.copy.call( this, source );
  14007. this.positionScreen.copy( source.positionScreen );
  14008. this.customUpdateCallback = source.customUpdateCallback;
  14009. for ( var i = 0, l = source.lensFlares.length; i < l; i ++ ) {
  14010. this.lensFlares.push( source.lensFlares[ i ] );
  14011. }
  14012. return this;
  14013. },
  14014. add: function ( texture, size, distance, blending, color, opacity ) {
  14015. if ( size === undefined ) size = - 1;
  14016. if ( distance === undefined ) distance = 0;
  14017. if ( opacity === undefined ) opacity = 1;
  14018. if ( color === undefined ) color = new THREE.Color( 0xffffff );
  14019. if ( blending === undefined ) blending = THREE.NormalBlending;
  14020. distance = Math.min( distance, Math.max( 0, distance ) );
  14021. this.lensFlares.push( {
  14022. texture: texture, // THREE.Texture
  14023. size: size, // size in pixels (-1 = use texture.width)
  14024. distance: distance, // distance (0-1) from light source (0=at light source)
  14025. x: 0, y: 0, z: 0, // screen position (-1 => 1) z = 0 is in front z = 1 is back
  14026. scale: 1, // scale
  14027. rotation: 0, // rotation
  14028. opacity: opacity, // opacity
  14029. color: color, // color
  14030. blending: blending // blending
  14031. } );
  14032. },
  14033. /*
  14034. * Update lens flares update positions on all flares based on the screen position
  14035. * Set myLensFlare.customUpdateCallback to alter the flares in your project specific way.
  14036. */
  14037. updateLensFlares: function () {
  14038. var f, fl = this.lensFlares.length;
  14039. var flare;
  14040. var vecX = - this.positionScreen.x * 2;
  14041. var vecY = - this.positionScreen.y * 2;
  14042. for ( f = 0; f < fl; f ++ ) {
  14043. flare = this.lensFlares[ f ];
  14044. flare.x = this.positionScreen.x + vecX * flare.distance;
  14045. flare.y = this.positionScreen.y + vecY * flare.distance;
  14046. flare.wantedRotation = flare.x * Math.PI * 0.25;
  14047. flare.rotation += ( flare.wantedRotation - flare.rotation ) * 0.25;
  14048. }
  14049. }
  14050. } );
  14051. // File:src/scenes/Scene.js
  14052. /**
  14053. * @author mrdoob / http://mrdoob.com/
  14054. */
  14055. THREE.Scene = function () {
  14056. THREE.Object3D.call( this );
  14057. this.type = 'Scene';
  14058. this.fog = null;
  14059. this.overrideMaterial = null;
  14060. this.autoUpdate = true; // checked by the renderer
  14061. };
  14062. THREE.Scene.prototype = Object.create( THREE.Object3D.prototype );
  14063. THREE.Scene.prototype.constructor = THREE.Scene;
  14064. THREE.Scene.prototype.copy = function ( source, recursive ) {
  14065. THREE.Object3D.prototype.copy.call( this, source, recursive );
  14066. if ( source.fog !== null ) this.fog = source.fog.clone();
  14067. if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
  14068. this.autoUpdate = source.autoUpdate;
  14069. this.matrixAutoUpdate = source.matrixAutoUpdate;
  14070. return this;
  14071. };
  14072. // File:src/scenes/Fog.js
  14073. /**
  14074. * @author mrdoob / http://mrdoob.com/
  14075. * @author alteredq / http://alteredqualia.com/
  14076. */
  14077. THREE.Fog = function ( color, near, far ) {
  14078. this.name = '';
  14079. this.color = new THREE.Color( color );
  14080. this.near = ( near !== undefined ) ? near : 1;
  14081. this.far = ( far !== undefined ) ? far : 1000;
  14082. };
  14083. THREE.Fog.prototype.clone = function () {
  14084. return new THREE.Fog( this.color.getHex(), this.near, this.far );
  14085. };
  14086. // File:src/scenes/FogExp2.js
  14087. /**
  14088. * @author mrdoob / http://mrdoob.com/
  14089. * @author alteredq / http://alteredqualia.com/
  14090. */
  14091. THREE.FogExp2 = function ( color, density ) {
  14092. this.name = '';
  14093. this.color = new THREE.Color( color );
  14094. this.density = ( density !== undefined ) ? density : 0.00025;
  14095. };
  14096. THREE.FogExp2.prototype.clone = function () {
  14097. return new THREE.FogExp2( this.color.getHex(), this.density );
  14098. };
  14099. // File:src/renderers/shaders/ShaderChunk.js
  14100. THREE.ShaderChunk = {};
  14101. // File:src/renderers/shaders/ShaderChunk/alphamap_fragment.glsl
  14102. THREE.ShaderChunk[ 'alphamap_fragment' ] = "#ifdef USE_ALPHAMAP\n diffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif\n";
  14103. // File:src/renderers/shaders/ShaderChunk/alphamap_pars_fragment.glsl
  14104. THREE.ShaderChunk[ 'alphamap_pars_fragment' ] = "#ifdef USE_ALPHAMAP\n uniform sampler2D alphaMap;\n#endif\n";
  14105. // File:src/renderers/shaders/ShaderChunk/alphatest_fragment.glsl
  14106. THREE.ShaderChunk[ 'alphatest_fragment' ] = "#ifdef ALPHATEST\n if ( diffuseColor.a < ALPHATEST ) discard;\n#endif\n";
  14107. // File:src/renderers/shaders/ShaderChunk/aomap_fragment.glsl
  14108. THREE.ShaderChunk[ 'aomap_fragment' ] = "#ifdef USE_AOMAP\n float ambientOcclusion = ( texture2D( aoMap, vUv2 ).r - 1.0 ) * aoMapIntensity + 1.0;\n reflectedLight.indirectDiffuse *= ambientOcclusion;\n #if defined( USE_ENVMAP ) && defined( PHYSICAL )\n float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n reflectedLight.indirectSpecular *= computeSpecularOcclusion( dotNV, ambientOcclusion, material.specularRoughness );\n #endif\n#endif\n";
  14109. // File:src/renderers/shaders/ShaderChunk/aomap_pars_fragment.glsl
  14110. THREE.ShaderChunk[ 'aomap_pars_fragment' ] = "#ifdef USE_AOMAP\n uniform sampler2D aoMap;\n uniform float aoMapIntensity;\n#endif";
  14111. // File:src/renderers/shaders/ShaderChunk/begin_vertex.glsl
  14112. THREE.ShaderChunk[ 'begin_vertex' ] = "\nvec3 transformed = vec3( position );\n";
  14113. // File:src/renderers/shaders/ShaderChunk/beginnormal_vertex.glsl
  14114. THREE.ShaderChunk[ 'beginnormal_vertex' ] = "\nvec3 objectNormal = vec3( normal );\n";
  14115. // File:src/renderers/shaders/ShaderChunk/bsdfs.glsl
  14116. THREE.ShaderChunk[ 'bsdfs' ] = "bool testLightInRange( const in float lightDistance, const in float cutoffDistance ) {\n return any( bvec2( cutoffDistance == 0.0, lightDistance < cutoffDistance ) );\n}\nfloat punctualLightIntensityToIrradianceFactor( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {\n if( decayExponent > 0.0 ) {\n#if defined ( PHYSICALLY_CORRECT_LIGHTS )\n float distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );\n float maxDistanceCutoffFactor = pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );\n return distanceFalloff * maxDistanceCutoffFactor;\n#else\n return pow( saturate( -lightDistance / cutoffDistance + 1.0 ), decayExponent );\n#endif\n }\n return 1.0;\n}\nvec3 BRDF_Diffuse_Lambert( const in vec3 diffuseColor ) {\n return RECIPROCAL_PI * diffuseColor;\n}\nvec3 F_Schlick( const in vec3 specularColor, const in float dotLH ) {\n float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );\n return ( 1.0 - specularColor ) * fresnel + specularColor;\n}\nfloat G_GGX_Smith( const in float alpha, const in float dotNL, const in float dotNV ) {\n float a2 = pow2( alpha );\n float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n return 1.0 / ( gl * gv );\n}\nfloat G_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {\n float a2 = pow2( alpha );\n float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n return 0.5 / max( gv + gl, EPSILON );\n}\nfloat D_GGX( const in float alpha, const in float dotNH ) {\n float a2 = pow2( alpha );\n float denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0;\n return RECIPROCAL_PI * a2 / pow2( denom );\n}\nvec3 BRDF_Specular_GGX( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float roughness ) {\n float alpha = pow2( 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_SmithCorrelated( alpha, dotNL, dotNV );\n float D = D_GGX( alpha, dotNH );\n return F * ( G * D );\n}\nvec3 BRDF_Specular_GGX_Environment( const in GeometricContext geometry, const in vec3 specularColor, const in float roughness ) {\n float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n const vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );\n const vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );\n vec4 r = roughness * c0 + c1;\n float a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;\n vec2 AB = vec2( -1.04, 1.04 ) * a004 + r.zw;\n return specularColor * AB.x + AB.y;\n}\nfloat G_BlinnPhong_Implicit( ) {\n return 0.25;\n}\nfloat D_BlinnPhong( const in float shininess, const in float dotNH ) {\n return RECIPROCAL_PI * ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );\n}\nvec3 BRDF_Specular_BlinnPhong( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float shininess ) {\n vec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );\n float dotNH = saturate( dot( geometry.normal, halfDir ) );\n float dotLH = saturate( dot( incidentLight.direction, halfDir ) );\n vec3 F = F_Schlick( specularColor, dotLH );\n float G = G_BlinnPhong_Implicit( );\n float D = D_BlinnPhong( shininess, dotNH );\n return F * ( G * D );\n}\nfloat GGXRoughnessToBlinnExponent( const in float ggxRoughness ) {\n return ( 2.0 / pow2( ggxRoughness + 0.0001 ) - 2.0 );\n}\nfloat BlinnExponentToGGXRoughness( const in float blinnExponent ) {\n return sqrt( 2.0 / ( blinnExponent + 2.0 ) );\n}\n";
  14117. // File:src/renderers/shaders/ShaderChunk/bumpmap_pars_fragment.glsl
  14118. 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";
  14119. // File:src/renderers/shaders/ShaderChunk/clipping_planes_fragment.glsl
  14120. THREE.ShaderChunk[ 'clipping_planes_fragment' ] = "#if NUM_CLIPPING_PLANES > 0\n for ( int i = 0; i < NUM_CLIPPING_PLANES; ++ i ) {\n vec4 plane = clippingPlanes[ i ];\n if ( dot( vViewPosition, plane.xyz ) > plane.w ) discard;\n }\n#endif\n";
  14121. // File:src/renderers/shaders/ShaderChunk/clipping_planes_pars_fragment.glsl
  14122. THREE.ShaderChunk[ 'clipping_planes_pars_fragment' ] = "#if NUM_CLIPPING_PLANES > 0\n #if ! defined( PHYSICAL ) && ! defined( PHONG )\n varying vec3 vViewPosition;\n #endif\n uniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\n#endif\n";
  14123. // File:src/renderers/shaders/ShaderChunk/clipping_planes_pars_vertex.glsl
  14124. THREE.ShaderChunk[ 'clipping_planes_pars_vertex' ] = "#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG )\n varying vec3 vViewPosition;\n#endif\n";
  14125. // File:src/renderers/shaders/ShaderChunk/clipping_planes_vertex.glsl
  14126. THREE.ShaderChunk[ 'clipping_planes_vertex' ] = "#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG )\n vViewPosition = - mvPosition.xyz;\n#endif\n";
  14127. // File:src/renderers/shaders/ShaderChunk/color_fragment.glsl
  14128. THREE.ShaderChunk[ 'color_fragment' ] = "#ifdef USE_COLOR\n diffuseColor.rgb *= vColor;\n#endif";
  14129. // File:src/renderers/shaders/ShaderChunk/color_pars_fragment.glsl
  14130. THREE.ShaderChunk[ 'color_pars_fragment' ] = "#ifdef USE_COLOR\n varying vec3 vColor;\n#endif\n";
  14131. // File:src/renderers/shaders/ShaderChunk/color_pars_vertex.glsl
  14132. THREE.ShaderChunk[ 'color_pars_vertex' ] = "#ifdef USE_COLOR\n varying vec3 vColor;\n#endif";
  14133. // File:src/renderers/shaders/ShaderChunk/color_vertex.glsl
  14134. THREE.ShaderChunk[ 'color_vertex' ] = "#ifdef USE_COLOR\n vColor.xyz = color.xyz;\n#endif";
  14135. // File:src/renderers/shaders/ShaderChunk/common.glsl
  14136. THREE.ShaderChunk[ 'common' ] = "#define PI 3.14159265359\n#define PI2 6.28318530718\n#define RECIPROCAL_PI 0.31830988618\n#define RECIPROCAL_PI2 0.15915494\n#define LOG2 1.442695\n#define EPSILON 1e-6\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#define whiteCompliment(a) ( 1.0 - saturate( a ) )\nfloat pow2( const in float x ) { return x*x; }\nfloat pow3( const in float x ) { return x*x*x; }\nfloat pow4( const in float x ) { float x2 = x*x; return x2*x2; }\nfloat average( const in vec3 color ) { return dot( color, vec3( 0.3333 ) ); }\nhighp float rand( const in vec2 uv ) {\n const highp float a = 12.9898, b = 78.233, c = 43758.5453;\n highp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );\n return fract(sin(sn) * c);\n}\nstruct IncidentLight {\n vec3 color;\n vec3 direction;\n bool visible;\n};\nstruct ReflectedLight {\n vec3 directDiffuse;\n vec3 directSpecular;\n vec3 indirectDiffuse;\n vec3 indirectSpecular;\n};\nstruct GeometricContext {\n vec3 position;\n vec3 normal;\n vec3 viewDir;\n};\nvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n}\nvec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {\n return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );\n}\nvec3 projectOnPlane(in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n float distance = dot( planeNormal, point - pointOnPlane );\n return - distance * planeNormal + point;\n}\nfloat sideOfPlane( in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n return sign( dot( point - pointOnPlane, planeNormal ) );\n}\nvec3 linePlaneIntersect( in vec3 pointOnLine, in vec3 lineDirection, in vec3 pointOnPlane, in vec3 planeNormal ) {\n return lineDirection * ( dot( planeNormal, pointOnPlane - pointOnLine ) / dot( planeNormal, lineDirection ) ) + pointOnLine;\n}\n";
  14137. // File:src/renderers/shaders/ShaderChunk/cube_uv_reflection_fragment.glsl
  14138. THREE.ShaderChunk[ 'cube_uv_reflection_fragment' ] = "#ifdef ENVMAP_TYPE_CUBE_UV\n#define cubeUV_textureSize (1024.0)\nint getFaceFromDirection(vec3 direction) {\n vec3 absDirection = abs(direction);\n int face = -1;\n if( absDirection.x > absDirection.z ) {\n if(absDirection.x > absDirection.y )\n face = direction.x > 0.0 ? 0 : 3;\n else\n face = direction.y > 0.0 ? 1 : 4;\n }\n else {\n if(absDirection.z > absDirection.y )\n face = direction.z > 0.0 ? 2 : 5;\n else\n face = direction.y > 0.0 ? 1 : 4;\n }\n return face;\n}\n#define cubeUV_maxLods1 (log2(cubeUV_textureSize*0.25) - 1.0)\n#define cubeUV_rangeClamp (exp2((6.0 - 1.0) * 2.0))\nvec2 MipLevelInfo( vec3 vec, float roughnessLevel, float roughness ) {\n float scale = exp2(cubeUV_maxLods1 - roughnessLevel);\n float dxRoughness = dFdx(roughness);\n float dyRoughness = dFdy(roughness);\n vec3 dx = dFdx( vec * scale * dxRoughness );\n vec3 dy = dFdy( vec * scale * dyRoughness );\n float d = max( dot( dx, dx ), dot( dy, dy ) );\n d = clamp(d, 1.0, cubeUV_rangeClamp);\n float mipLevel = 0.5 * log2(d);\n return vec2(floor(mipLevel), fract(mipLevel));\n}\n#define cubeUV_maxLods2 (log2(cubeUV_textureSize*0.25) - 2.0)\n#define cubeUV_rcpTextureSize (1.0 / cubeUV_textureSize)\nvec2 getCubeUV(vec3 direction, float roughnessLevel, float mipLevel) {\n mipLevel = roughnessLevel > cubeUV_maxLods2 - 3.0 ? 0.0 : mipLevel;\n float a = 16.0 * cubeUV_rcpTextureSize;\n vec2 exp2_packed = exp2( vec2( roughnessLevel, mipLevel ) );\n vec2 rcp_exp2_packed = vec2( 1.0 ) / exp2_packed;\n float powScale = exp2_packed.x * exp2_packed.y;\n float scale = rcp_exp2_packed.x * rcp_exp2_packed.y * 0.25;\n float mipOffset = 0.75*(1.0 - rcp_exp2_packed.y) * rcp_exp2_packed.x;\n bool bRes = mipLevel == 0.0;\n scale = bRes && (scale < a) ? a : scale;\n vec3 r;\n vec2 offset;\n int face = getFaceFromDirection(direction);\n float rcpPowScale = 1.0 / powScale;\n if( face == 0) {\n r = vec3(direction.x, -direction.z, direction.y);\n offset = vec2(0.0+mipOffset,0.75 * rcpPowScale);\n offset.y = bRes && (offset.y < 2.0*a) ? a : offset.y;\n }\n else if( face == 1) {\n r = vec3(direction.y, direction.x, direction.z);\n offset = vec2(scale+mipOffset, 0.75 * rcpPowScale);\n offset.y = bRes && (offset.y < 2.0*a) ? a : offset.y;\n }\n else if( face == 2) {\n r = vec3(direction.z, direction.x, direction.y);\n offset = vec2(2.0*scale+mipOffset, 0.75 * rcpPowScale);\n offset.y = bRes && (offset.y < 2.0*a) ? a : offset.y;\n }\n else if( face == 3) {\n r = vec3(direction.x, direction.z, direction.y);\n offset = vec2(0.0+mipOffset,0.5 * rcpPowScale);\n offset.y = bRes && (offset.y < 2.0*a) ? 0.0 : offset.y;\n }\n else if( face == 4) {\n r = vec3(direction.y, direction.x, -direction.z);\n offset = vec2(scale+mipOffset, 0.5 * rcpPowScale);\n offset.y = bRes && (offset.y < 2.0*a) ? 0.0 : offset.y;\n }\n else {\n r = vec3(direction.z, -direction.x, direction.y);\n offset = vec2(2.0*scale+mipOffset, 0.5 * rcpPowScale);\n offset.y = bRes && (offset.y < 2.0*a) ? 0.0 : offset.y;\n }\n r = normalize(r);\n float texelOffset = 0.5 * cubeUV_rcpTextureSize;\n vec2 s = ( r.yz / abs( r.x ) + vec2( 1.0 ) ) * 0.5;\n vec2 base = offset + vec2( texelOffset );\n return base + s * ( scale - 2.0 * texelOffset );\n}\n#define cubeUV_maxLods3 (log2(cubeUV_textureSize*0.25) - 3.0)\nvec4 textureCubeUV(vec3 reflectedDirection, float roughness ) {\n float roughnessVal = roughness* cubeUV_maxLods3;\n float r1 = floor(roughnessVal);\n float r2 = r1 + 1.0;\n float t = fract(roughnessVal);\n vec2 mipInfo = MipLevelInfo(reflectedDirection, r1, roughness);\n float s = mipInfo.y;\n float level0 = mipInfo.x;\n float level1 = level0 + 1.0;\n level1 = level1 > 5.0 ? 5.0 : level1;\n level0 += min( floor( s + 0.5 ), 5.0 );\n vec2 uv_10 = getCubeUV(reflectedDirection, r1, level0);\n vec4 color10 = envMapTexelToLinear(texture2D(envMap, uv_10));\n vec2 uv_20 = getCubeUV(reflectedDirection, r2, level0);\n vec4 color20 = envMapTexelToLinear(texture2D(envMap, uv_20));\n vec4 result = mix(color10, color20, t);\n return vec4(result.rgb, 1.0);\n}\n#endif\n";
  14139. // File:src/renderers/shaders/ShaderChunk/defaultnormal_vertex.glsl
  14140. THREE.ShaderChunk[ 'defaultnormal_vertex' ] = "#ifdef FLIP_SIDED\n objectNormal = -objectNormal;\n#endif\nvec3 transformedNormal = normalMatrix * objectNormal;\n";
  14141. // File:src/renderers/shaders/ShaderChunk/displacementmap_vertex.glsl
  14142. THREE.ShaderChunk[ 'displacementmap_vertex' ] = "#ifdef USE_DISPLACEMENTMAP\n transformed += normal * ( texture2D( displacementMap, uv ).x * displacementScale + displacementBias );\n#endif\n";
  14143. // File:src/renderers/shaders/ShaderChunk/displacementmap_pars_vertex.glsl
  14144. THREE.ShaderChunk[ 'displacementmap_pars_vertex' ] = "#ifdef USE_DISPLACEMENTMAP\n uniform sampler2D displacementMap;\n uniform float displacementScale;\n uniform float displacementBias;\n#endif\n";
  14145. // File:src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl
  14146. THREE.ShaderChunk[ 'emissivemap_fragment' ] = "#ifdef USE_EMISSIVEMAP\n vec4 emissiveColor = texture2D( emissiveMap, vUv );\n emissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\n totalEmissiveRadiance *= emissiveColor.rgb;\n#endif\n";
  14147. // File:src/renderers/shaders/ShaderChunk/emissivemap_pars_fragment.glsl
  14148. THREE.ShaderChunk[ 'emissivemap_pars_fragment' ] = "#ifdef USE_EMISSIVEMAP\n uniform sampler2D emissiveMap;\n#endif\n";
  14149. // File:src/renderers/shaders/ShaderChunk/encodings_pars_fragment.glsl
  14150. THREE.ShaderChunk[ 'encodings_pars_fragment' ] = "\nvec4 LinearToLinear( in vec4 value ) {\n return value;\n}\nvec4 GammaToLinear( in vec4 value, in float gammaFactor ) {\n return vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );\n}\nvec4 LinearToGamma( in vec4 value, in float gammaFactor ) {\n return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );\n}\nvec4 sRGBToLinear( in vec4 value ) {\n return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.w );\n}\nvec4 LinearTosRGB( in vec4 value ) {\n return vec4( mix( pow( value.rgb, vec3( 0.41666 ) ) * 1.055 - vec3( 0.055 ), value.rgb * 12.92, vec3( lessThanEqual( value.rgb, vec3( 0.0031308 ) ) ) ), value.w );\n}\nvec4 RGBEToLinear( in vec4 value ) {\n return vec4( value.rgb * exp2( value.a * 255.0 - 128.0 ), 1.0 );\n}\nvec4 LinearToRGBE( in vec4 value ) {\n float maxComponent = max( max( value.r, value.g ), value.b );\n float fExp = clamp( ceil( log2( maxComponent ) ), -128.0, 127.0 );\n return vec4( value.rgb / exp2( fExp ), ( fExp + 128.0 ) / 255.0 );\n}\nvec4 RGBMToLinear( in vec4 value, in float maxRange ) {\n return vec4( value.xyz * value.w * maxRange, 1.0 );\n}\nvec4 LinearToRGBM( in vec4 value, in float maxRange ) {\n float maxRGB = max( value.x, max( value.g, value.b ) );\n float M = clamp( maxRGB / maxRange, 0.0, 1.0 );\n M = ceil( M * 255.0 ) / 255.0;\n return vec4( value.rgb / ( M * maxRange ), M );\n}\nvec4 RGBDToLinear( in vec4 value, in float maxRange ) {\n return vec4( value.rgb * ( ( maxRange / 255.0 ) / value.a ), 1.0 );\n}\nvec4 LinearToRGBD( in vec4 value, in float maxRange ) {\n float maxRGB = max( value.x, max( value.g, value.b ) );\n float D = max( maxRange / maxRGB, 1.0 );\n D = min( floor( D ) / 255.0, 1.0 );\n return vec4( value.rgb * ( D * ( 255.0 / maxRange ) ), D );\n}\nconst mat3 cLogLuvM = mat3( 0.2209, 0.3390, 0.4184, 0.1138, 0.6780, 0.7319, 0.0102, 0.1130, 0.2969 );\nvec4 LinearToLogLuv( in vec4 value ) {\n vec3 Xp_Y_XYZp = value.rgb * cLogLuvM;\n Xp_Y_XYZp = max(Xp_Y_XYZp, vec3(1e-6, 1e-6, 1e-6));\n vec4 vResult;\n vResult.xy = Xp_Y_XYZp.xy / Xp_Y_XYZp.z;\n float Le = 2.0 * log2(Xp_Y_XYZp.y) + 127.0;\n vResult.w = fract(Le);\n vResult.z = (Le - (floor(vResult.w*255.0))/255.0)/255.0;\n return vResult;\n}\nconst mat3 cLogLuvInverseM = mat3( 6.0014, -2.7008, -1.7996, -1.3320, 3.1029, -5.7721, 0.3008, -1.0882, 5.6268 );\nvec4 LogLuvToLinear( in vec4 value ) {\n float Le = value.z * 255.0 + value.w;\n vec3 Xp_Y_XYZp;\n Xp_Y_XYZp.y = exp2((Le - 127.0) / 2.0);\n Xp_Y_XYZp.z = Xp_Y_XYZp.y / value.y;\n Xp_Y_XYZp.x = value.x * Xp_Y_XYZp.z;\n vec3 vRGB = Xp_Y_XYZp.rgb * cLogLuvInverseM;\n return vec4( max(vRGB, 0.0), 1.0 );\n}\n";
  14151. // File:src/renderers/shaders/ShaderChunk/encodings_fragment.glsl
  14152. THREE.ShaderChunk[ 'encodings_fragment' ] = " gl_FragColor = linearToOutputTexel( gl_FragColor );\n";
  14153. // File:src/renderers/shaders/ShaderChunk/envmap_fragment.glsl
  14154. THREE.ShaderChunk[ 'envmap_fragment' ] = "#ifdef USE_ENVMAP\n #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )\n vec3 cameraToVertex = normalize( vWorldPosition - cameraPosition );\n vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n #ifdef ENVMAP_MODE_REFLECTION\n vec3 reflectVec = reflect( cameraToVertex, worldNormal );\n #else\n vec3 reflectVec = refract( cameraToVertex, worldNormal, refractionRatio );\n #endif\n #else\n vec3 reflectVec = vReflect;\n #endif\n #ifdef DOUBLE_SIDED\n float flipNormal = ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n #else\n float flipNormal = 1.0;\n #endif\n #ifdef ENVMAP_TYPE_CUBE\n vec4 envColor = textureCube( envMap, flipNormal * vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );\n #elif defined( ENVMAP_TYPE_EQUIREC )\n vec2 sampleUV;\n sampleUV.y = saturate( flipNormal * reflectVec.y * 0.5 + 0.5 );\n sampleUV.x = atan( flipNormal * reflectVec.z, flipNormal * reflectVec.x ) * RECIPROCAL_PI2 + 0.5;\n vec4 envColor = texture2D( envMap, sampleUV );\n #elif defined( ENVMAP_TYPE_SPHERE )\n vec3 reflectView = flipNormal * normalize((viewMatrix * vec4( reflectVec, 0.0 )).xyz + vec3(0.0,0.0,1.0));\n vec4 envColor = texture2D( envMap, reflectView.xy * 0.5 + 0.5 );\n #endif\n envColor = envMapTexelToLinear( envColor );\n #ifdef ENVMAP_BLENDING_MULTIPLY\n outgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity );\n #elif defined( ENVMAP_BLENDING_MIX )\n outgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity );\n #elif defined( ENVMAP_BLENDING_ADD )\n outgoingLight += envColor.xyz * specularStrength * reflectivity;\n #endif\n#endif\n";
  14155. // File:src/renderers/shaders/ShaderChunk/envmap_pars_fragment.glsl
  14156. THREE.ShaderChunk[ 'envmap_pars_fragment' ] = "#if defined( USE_ENVMAP ) || defined( PHYSICAL )\n uniform float reflectivity;\n uniform float envMapIntenstiy;\n#endif\n#ifdef USE_ENVMAP\n #if ! defined( PHYSICAL ) && ( defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) )\n varying vec3 vWorldPosition;\n #endif\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";
  14157. // File:src/renderers/shaders/ShaderChunk/envmap_pars_vertex.glsl
  14158. THREE.ShaderChunk[ 'envmap_pars_vertex' ] = "#ifdef USE_ENVMAP\n #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )\n varying vec3 vWorldPosition;\n #else\n varying vec3 vReflect;\n uniform float refractionRatio;\n #endif\n#endif\n";
  14159. // File:src/renderers/shaders/ShaderChunk/envmap_vertex.glsl
  14160. THREE.ShaderChunk[ 'envmap_vertex' ] = "#ifdef USE_ENVMAP\n #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )\n vWorldPosition = worldPosition.xyz;\n #else\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#endif\n";
  14161. // File:src/renderers/shaders/ShaderChunk/fog_fragment.glsl
  14162. THREE.ShaderChunk[ 'fog_fragment' ] = "#ifdef USE_FOG\n #ifdef USE_LOGDEPTHBUF_EXT\n float depth = gl_FragDepthEXT / gl_FragCoord.w;\n #else\n float depth = gl_FragCoord.z / gl_FragCoord.w;\n #endif\n #ifdef FOG_EXP2\n float fogFactor = whiteCompliment( exp2( - fogDensity * fogDensity * depth * depth * LOG2 ) );\n #else\n float fogFactor = smoothstep( fogNear, fogFar, depth );\n #endif\n gl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor );\n#endif\n";
  14163. // File:src/renderers/shaders/ShaderChunk/fog_pars_fragment.glsl
  14164. 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";
  14165. // File:src/renderers/shaders/ShaderChunk/lightmap_fragment.glsl
  14166. THREE.ShaderChunk[ 'lightmap_fragment' ] = "#ifdef USE_LIGHTMAP\n reflectedLight.indirectDiffuse += PI * texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n#endif\n";
  14167. // File:src/renderers/shaders/ShaderChunk/lightmap_pars_fragment.glsl
  14168. THREE.ShaderChunk[ 'lightmap_pars_fragment' ] = "#ifdef USE_LIGHTMAP\n uniform sampler2D lightMap;\n uniform float lightMapIntensity;\n#endif";
  14169. // File:src/renderers/shaders/ShaderChunk/lights_lambert_vertex.glsl
  14170. THREE.ShaderChunk[ 'lights_lambert_vertex' ] = "vec3 diffuse = vec3( 1.0 );\nGeometricContext geometry;\ngeometry.position = mvPosition.xyz;\ngeometry.normal = normalize( transformedNormal );\ngeometry.viewDir = normalize( -mvPosition.xyz );\nGeometricContext backGeometry;\nbackGeometry.position = geometry.position;\nbackGeometry.normal = -geometry.normal;\nbackGeometry.viewDir = geometry.viewDir;\nvLightFront = vec3( 0.0 );\n#ifdef DOUBLE_SIDED\n vLightBack = vec3( 0.0 );\n#endif\nIncidentLight directLight;\nfloat dotNL;\nvec3 directLightColor_Diffuse;\n#if NUM_POINT_LIGHTS > 0\n for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n getPointDirectLightIrradiance( pointLights[ i ], geometry, directLight );\n dotNL = dot( geometry.normal, directLight.direction );\n directLightColor_Diffuse = PI * directLight.color;\n vLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n #ifdef DOUBLE_SIDED\n vLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n #endif\n }\n#endif\n#if NUM_SPOT_LIGHTS > 0\n for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n getSpotDirectLightIrradiance( spotLights[ i ], geometry, directLight );\n dotNL = dot( geometry.normal, directLight.direction );\n directLightColor_Diffuse = PI * directLight.color;\n vLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n #ifdef DOUBLE_SIDED\n vLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n #endif\n }\n#endif\n#if NUM_DIR_LIGHTS > 0\n for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n getDirectionalDirectLightIrradiance( directionalLights[ i ], geometry, directLight );\n dotNL = dot( geometry.normal, directLight.direction );\n directLightColor_Diffuse = PI * directLight.color;\n vLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n #ifdef DOUBLE_SIDED\n vLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n #endif\n }\n#endif\n#if NUM_HEMI_LIGHTS > 0\n for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n vLightFront += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry );\n #ifdef DOUBLE_SIDED\n vLightBack += getHemisphereLightIrradiance( hemisphereLights[ i ], backGeometry );\n #endif\n }\n#endif\n";
  14171. // File:src/renderers/shaders/ShaderChunk/lights_pars.glsl
  14172. THREE.ShaderChunk[ 'lights_pars' ] = "uniform vec3 ambientLightColor;\nvec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {\n vec3 irradiance = ambientLightColor;\n #ifndef PHYSICALLY_CORRECT_LIGHTS\n irradiance *= PI;\n #endif\n return irradiance;\n}\n#if NUM_DIR_LIGHTS > 0\n struct DirectionalLight {\n vec3 direction;\n vec3 color;\n int shadow;\n float shadowBias;\n float shadowRadius;\n vec2 shadowMapSize;\n };\n uniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];\n void getDirectionalDirectLightIrradiance( const in DirectionalLight directionalLight, const in GeometricContext geometry, out IncidentLight directLight ) {\n directLight.color = directionalLight.color;\n directLight.direction = directionalLight.direction;\n directLight.visible = true;\n }\n#endif\n#if NUM_POINT_LIGHTS > 0\n struct PointLight {\n vec3 position;\n vec3 color;\n float distance;\n float decay;\n int shadow;\n float shadowBias;\n float shadowRadius;\n vec2 shadowMapSize;\n };\n uniform PointLight pointLights[ NUM_POINT_LIGHTS ];\n void getPointDirectLightIrradiance( const in PointLight pointLight, const in GeometricContext geometry, out IncidentLight directLight ) {\n vec3 lVector = pointLight.position - geometry.position;\n directLight.direction = normalize( lVector );\n float lightDistance = length( lVector );\n if ( testLightInRange( lightDistance, pointLight.distance ) ) {\n directLight.color = pointLight.color;\n directLight.color *= punctualLightIntensityToIrradianceFactor( lightDistance, pointLight.distance, pointLight.decay );\n directLight.visible = true;\n } else {\n directLight.color = vec3( 0.0 );\n directLight.visible = false;\n }\n }\n#endif\n#if NUM_SPOT_LIGHTS > 0\n struct SpotLight {\n vec3 position;\n vec3 direction;\n vec3 color;\n float distance;\n float decay;\n float coneCos;\n float penumbraCos;\n int shadow;\n float shadowBias;\n float shadowRadius;\n vec2 shadowMapSize;\n };\n uniform SpotLight spotLights[ NUM_SPOT_LIGHTS ];\n void getSpotDirectLightIrradiance( const in SpotLight spotLight, const in GeometricContext geometry, out IncidentLight directLight ) {\n vec3 lVector = spotLight.position - geometry.position;\n directLight.direction = normalize( lVector );\n float lightDistance = length( lVector );\n float angleCos = dot( directLight.direction, spotLight.direction );\n if ( all( bvec2( angleCos > spotLight.coneCos, testLightInRange( lightDistance, spotLight.distance ) ) ) ) {\n float spotEffect = smoothstep( spotLight.coneCos, spotLight.penumbraCos, angleCos );\n directLight.color = spotLight.color;\n directLight.color *= spotEffect * punctualLightIntensityToIrradianceFactor( lightDistance, spotLight.distance, spotLight.decay );\n directLight.visible = true;\n } else {\n directLight.color = vec3( 0.0 );\n directLight.visible = false;\n }\n }\n#endif\n#if NUM_HEMI_LIGHTS > 0\n struct HemisphereLight {\n vec3 direction;\n vec3 skyColor;\n vec3 groundColor;\n };\n uniform HemisphereLight hemisphereLights[ NUM_HEMI_LIGHTS ];\n vec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in GeometricContext geometry ) {\n float dotNL = dot( geometry.normal, hemiLight.direction );\n float hemiDiffuseWeight = 0.5 * dotNL + 0.5;\n vec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );\n #ifndef PHYSICALLY_CORRECT_LIGHTS\n irradiance *= PI;\n #endif\n return irradiance;\n }\n#endif\n#if defined( USE_ENVMAP ) && defined( PHYSICAL )\n vec3 getLightProbeIndirectIrradiance( const in GeometricContext geometry, const in int maxMIPLevel ) {\n #ifdef DOUBLE_SIDED\n float flipNormal = ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n #else\n float flipNormal = 1.0;\n #endif\n vec3 worldNormal = inverseTransformDirection( geometry.normal, viewMatrix );\n #ifdef ENVMAP_TYPE_CUBE\n vec3 queryVec = flipNormal * vec3( flipEnvMap * worldNormal.x, worldNormal.yz );\n #ifdef TEXTURE_LOD_EXT\n vec4 envMapColor = textureCubeLodEXT( envMap, queryVec, float( maxMIPLevel ) );\n #else\n vec4 envMapColor = textureCube( envMap, queryVec, float( maxMIPLevel ) );\n #endif\n envMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\n #elif defined( ENVMAP_TYPE_CUBE_UV )\n vec3 queryVec = flipNormal * vec3( flipEnvMap * worldNormal.x, worldNormal.yz );\n vec4 envMapColor = textureCubeUV( queryVec, 1.0 );\n #else\n vec4 envMapColor = vec4( 0.0 );\n #endif\n return PI * envMapColor.rgb * envMapIntensity;\n }\n float getSpecularMIPLevel( const in float blinnShininessExponent, const in int maxMIPLevel ) {\n float maxMIPLevelScalar = float( maxMIPLevel );\n float desiredMIPLevel = maxMIPLevelScalar - 0.79248 - 0.5 * log2( pow2( blinnShininessExponent ) + 1.0 );\n return clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );\n }\n vec3 getLightProbeIndirectRadiance( const in GeometricContext geometry, const in float blinnShininessExponent, const in int maxMIPLevel ) {\n #ifdef ENVMAP_MODE_REFLECTION\n vec3 reflectVec = reflect( -geometry.viewDir, geometry.normal );\n #else\n vec3 reflectVec = refract( -geometry.viewDir, geometry.normal, refractionRatio );\n #endif\n #ifdef DOUBLE_SIDED\n float flipNormal = ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n #else\n float flipNormal = 1.0;\n #endif\n reflectVec = inverseTransformDirection( reflectVec, viewMatrix );\n float specularMIPLevel = getSpecularMIPLevel( blinnShininessExponent, maxMIPLevel );\n #ifdef ENVMAP_TYPE_CUBE\n vec3 queryReflectVec = flipNormal * vec3( flipEnvMap * reflectVec.x, reflectVec.yz );\n #ifdef TEXTURE_LOD_EXT\n vec4 envMapColor = textureCubeLodEXT( envMap, queryReflectVec, specularMIPLevel );\n #else\n vec4 envMapColor = textureCube( envMap, queryReflectVec, specularMIPLevel );\n #endif\n envMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\n #elif defined( ENVMAP_TYPE_CUBE_UV )\n vec3 queryReflectVec = flipNormal * vec3( flipEnvMap * reflectVec.x, reflectVec.yz );\n vec4 envMapColor = textureCubeUV(queryReflectVec, BlinnExponentToGGXRoughness(blinnShininessExponent));\n #elif defined( ENVMAP_TYPE_EQUIREC )\n vec2 sampleUV;\n sampleUV.y = saturate( flipNormal * reflectVec.y * 0.5 + 0.5 );\n sampleUV.x = atan( flipNormal * reflectVec.z, flipNormal * reflectVec.x ) * RECIPROCAL_PI2 + 0.5;\n #ifdef TEXTURE_LOD_EXT\n vec4 envMapColor = texture2DLodEXT( envMap, sampleUV, specularMIPLevel );\n #else\n vec4 envMapColor = texture2D( envMap, sampleUV, specularMIPLevel );\n #endif\n envMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\n #elif defined( ENVMAP_TYPE_SPHERE )\n vec3 reflectView = flipNormal * normalize((viewMatrix * vec4( reflectVec, 0.0 )).xyz + vec3(0.0,0.0,1.0));\n #ifdef TEXTURE_LOD_EXT\n vec4 envMapColor = texture2DLodEXT( envMap, reflectView.xy * 0.5 + 0.5, specularMIPLevel );\n #else\n vec4 envMapColor = texture2D( envMap, reflectView.xy * 0.5 + 0.5, specularMIPLevel );\n #endif\n envMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\n #endif\n return envMapColor.rgb * envMapIntensity;\n }\n#endif\n";
  14173. // File:src/renderers/shaders/ShaderChunk/lights_phong_fragment.glsl
  14174. THREE.ShaderChunk[ 'lights_phong_fragment' ] = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;\n";
  14175. // File:src/renderers/shaders/ShaderChunk/lights_phong_pars_fragment.glsl
  14176. THREE.ShaderChunk[ 'lights_phong_pars_fragment' ] = "varying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n varying vec3 vNormal;\n#endif\nstruct BlinnPhongMaterial {\n vec3 diffuseColor;\n vec3 specularColor;\n float specularShininess;\n float specularStrength;\n};\nvoid RE_Direct_BlinnPhong( const in IncidentLight directLight, const in GeometricContext geometry, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n float dotNL = saturate( dot( geometry.normal, directLight.direction ) );\n vec3 irradiance = dotNL * directLight.color;\n #ifndef PHYSICALLY_CORRECT_LIGHTS\n irradiance *= PI;\n #endif\n reflectedLight.directDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n reflectedLight.directSpecular += irradiance * BRDF_Specular_BlinnPhong( directLight, geometry, material.specularColor, material.specularShininess ) * material.specularStrength;\n}\nvoid RE_IndirectDiffuse_BlinnPhong( const in vec3 irradiance, const in GeometricContext geometry, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n reflectedLight.indirectDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n}\n#define RE_Direct RE_Direct_BlinnPhong\n#define RE_IndirectDiffuse RE_IndirectDiffuse_BlinnPhong\n#define Material_LightProbeLOD( material ) (0)\n";
  14177. // File:src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl
  14178. THREE.ShaderChunk[ 'lights_physical_fragment' ] = "PhysicalMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );\nmaterial.specularRoughness = clamp( roughnessFactor, 0.04, 1.0 );\n#ifdef STANDARD\n material.specularColor = mix( vec3( 0.04 ), diffuseColor.rgb, metalnessFactor );\n#else\n material.specularColor = mix( vec3( 0.16 * pow2( reflectivity ) ), diffuseColor.rgb, metalnessFactor );\n#endif\n";
  14179. // File:src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl
  14180. THREE.ShaderChunk[ 'lights_physical_pars_fragment' ] = "struct PhysicalMaterial {\n vec3 diffuseColor;\n float specularRoughness;\n vec3 specularColor;\n #ifndef STANDARD\n #endif\n};\nvoid RE_Direct_Physical( 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 vec3 irradiance = dotNL * directLight.color;\n #ifndef PHYSICALLY_CORRECT_LIGHTS\n irradiance *= PI;\n #endif\n reflectedLight.directDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n reflectedLight.directSpecular += irradiance * BRDF_Specular_GGX( directLight, geometry, material.specularColor, material.specularRoughness );\n}\nvoid RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n reflectedLight.indirectDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectSpecular_Physical( const in vec3 radiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n reflectedLight.indirectSpecular += radiance * BRDF_Specular_GGX_Environment( geometry, material.specularColor, material.specularRoughness );\n}\n#define RE_Direct RE_Direct_Physical\n#define RE_IndirectDiffuse RE_IndirectDiffuse_Physical\n#define RE_IndirectSpecular RE_IndirectSpecular_Physical\n#define Material_BlinnShininessExponent( material ) GGXRoughnessToBlinnExponent( material.specularRoughness )\nfloat computeSpecularOcclusion( const in float dotNV, const in float ambientOcclusion, const in float roughness ) {\n return saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion );\n}\n";
  14181. // File:src/renderers/shaders/ShaderChunk/lights_template.glsl
  14182. THREE.ShaderChunk[ 'lights_template' ] = "\nGeometricContext geometry;\ngeometry.position = - vViewPosition;\ngeometry.normal = normal;\ngeometry.viewDir = normalize( vViewPosition );\nIncidentLight directLight;\n#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )\n PointLight pointLight;\n for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n pointLight = pointLights[ i ];\n getPointDirectLightIrradiance( pointLight, geometry, directLight );\n #ifdef USE_SHADOWMAP\n directLight.color *= all( bvec2( pointLight.shadow, directLight.visible ) ) ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ] ) : 1.0;\n #endif\n RE_Direct( directLight, geometry, material, reflectedLight );\n }\n#endif\n#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )\n SpotLight spotLight;\n for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n spotLight = spotLights[ i ];\n getSpotDirectLightIrradiance( spotLight, geometry, directLight );\n #ifdef USE_SHADOWMAP\n directLight.color *= all( bvec2( spotLight.shadow, directLight.visible ) ) ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowBias, spotLight.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\n #endif\n RE_Direct( directLight, geometry, material, reflectedLight );\n }\n#endif\n#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )\n DirectionalLight directionalLight;\n for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n directionalLight = directionalLights[ i ];\n getDirectionalDirectLightIrradiance( directionalLight, geometry, directLight );\n #ifdef USE_SHADOWMAP\n directLight.color *= all( bvec2( directionalLight.shadow, directLight.visible ) ) ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n #endif\n RE_Direct( directLight, geometry, material, reflectedLight );\n }\n#endif\n#if defined( RE_IndirectDiffuse )\n vec3 irradiance = getAmbientLightIrradiance( ambientLightColor );\n #ifdef USE_LIGHTMAP\n vec3 lightMapIrradiance = texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n #ifndef PHYSICALLY_CORRECT_LIGHTS\n lightMapIrradiance *= PI;\n #endif\n irradiance += lightMapIrradiance;\n #endif\n #if ( NUM_HEMI_LIGHTS > 0 )\n for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry );\n }\n #endif\n #if defined( USE_ENVMAP ) && defined( PHYSICAL ) && defined( ENVMAP_TYPE_CUBE_UV )\n irradiance += getLightProbeIndirectIrradiance( geometry, 8 );\n #endif\n RE_IndirectDiffuse( irradiance, geometry, material, reflectedLight );\n#endif\n#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )\n vec3 radiance = getLightProbeIndirectRadiance( geometry, Material_BlinnShininessExponent( material ), 8 );\n RE_IndirectSpecular( radiance, geometry, material, reflectedLight );\n#endif\n";
  14183. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl
  14184. THREE.ShaderChunk[ 'logdepthbuf_fragment' ] = "#if defined(USE_LOGDEPTHBUF) && defined(USE_LOGDEPTHBUF_EXT)\n gl_FragDepthEXT = log2(vFragDepth) * logDepthBufFC * 0.5;\n#endif";
  14185. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl
  14186. 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";
  14187. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_pars_vertex.glsl
  14188. 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";
  14189. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl
  14190. 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";
  14191. // File:src/renderers/shaders/ShaderChunk/map_fragment.glsl
  14192. THREE.ShaderChunk[ 'map_fragment' ] = "#ifdef USE_MAP\n vec4 texelColor = texture2D( map, vUv );\n texelColor = mapTexelToLinear( texelColor );\n diffuseColor *= texelColor;\n#endif\n";
  14193. // File:src/renderers/shaders/ShaderChunk/map_pars_fragment.glsl
  14194. THREE.ShaderChunk[ 'map_pars_fragment' ] = "#ifdef USE_MAP\n uniform sampler2D map;\n#endif\n";
  14195. // File:src/renderers/shaders/ShaderChunk/map_particle_fragment.glsl
  14196. THREE.ShaderChunk[ 'map_particle_fragment' ] = "#ifdef USE_MAP\n vec4 mapTexel = texture2D( map, vec2( gl_PointCoord.x, 1.0 - gl_PointCoord.y ) * offsetRepeat.zw + offsetRepeat.xy );\n diffuseColor *= mapTexelToLinear( mapTexel );\n#endif\n";
  14197. // File:src/renderers/shaders/ShaderChunk/map_particle_pars_fragment.glsl
  14198. THREE.ShaderChunk[ 'map_particle_pars_fragment' ] = "#ifdef USE_MAP\n uniform vec4 offsetRepeat;\n uniform sampler2D map;\n#endif\n";
  14199. // File:src/renderers/shaders/ShaderChunk/metalnessmap_fragment.glsl
  14200. THREE.ShaderChunk[ 'metalnessmap_fragment' ] = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n vec4 texelMetalness = texture2D( metalnessMap, vUv );\n metalnessFactor *= texelMetalness.r;\n#endif\n";
  14201. // File:src/renderers/shaders/ShaderChunk/metalnessmap_pars_fragment.glsl
  14202. THREE.ShaderChunk[ 'metalnessmap_pars_fragment' ] = "#ifdef USE_METALNESSMAP\n uniform sampler2D metalnessMap;\n#endif";
  14203. // File:src/renderers/shaders/ShaderChunk/morphnormal_vertex.glsl
  14204. 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";
  14205. // File:src/renderers/shaders/ShaderChunk/morphtarget_pars_vertex.glsl
  14206. 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";
  14207. // File:src/renderers/shaders/ShaderChunk/morphtarget_vertex.glsl
  14208. 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";
  14209. // File:src/renderers/shaders/ShaderChunk/normal_fragment.glsl
  14210. THREE.ShaderChunk[ 'normal_fragment' ] = "#ifdef FLAT_SHADED\n vec3 fdx = vec3( dFdx( vViewPosition.x ), dFdx( vViewPosition.y ), dFdx( vViewPosition.z ) );\n vec3 fdy = vec3( dFdy( vViewPosition.x ), dFdy( vViewPosition.y ), dFdy( vViewPosition.z ) );\n vec3 normal = normalize( cross( fdx, fdy ) );\n#else\n vec3 normal = normalize( vNormal );\n #ifdef DOUBLE_SIDED\n normal = normal * ( -1.0 + 2.0 * float( gl_FrontFacing ) );\n #endif\n#endif\n#ifdef USE_NORMALMAP\n normal = perturbNormal2Arb( -vViewPosition, normal );\n#elif defined( USE_BUMPMAP )\n normal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd() );\n#endif\n";
  14211. // File:src/renderers/shaders/ShaderChunk/normalmap_pars_fragment.glsl
  14212. 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";
  14213. // File:src/renderers/shaders/ShaderChunk/packing.glsl
  14214. THREE.ShaderChunk[ 'packing' ] = "vec3 packNormalToRGB( const in vec3 normal ) {\n return normalize( normal ) * 0.5 + 0.5;\n}\nvec3 unpackRGBToNormal( const in vec3 rgb ) {\n return 1.0 - 2.0 * rgb.xyz;\n}\nconst float PackUpscale = 256. / 255.;const float UnpackDownscale = 255. / 256.;\nconst vec3 PackFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );\nconst vec4 UnpackFactors = UnpackDownscale / vec4( PackFactors, 1. );\nconst float ShiftRight8 = 1. / 256.;\nvec4 packDepthToRGBA( const in float v ) {\n vec4 r = vec4( fract( v * PackFactors ), v );\n r.yzw -= r.xyz * ShiftRight8; return r * PackUpscale;\n}\nfloat unpackRGBAToDepth( const in vec4 v ) {\n return dot( v, UnpackFactors );\n}\nfloat viewZToOrthoDepth( const in float viewZ, const in float near, const in float far ) {\n return ( viewZ + near ) / ( near - far );\n}\nfloat OrthoDepthToViewZ( const in float linearClipZ, const in float near, const in float far ) {\n return linearClipZ * ( near - far ) - near;\n}\nfloat viewZToPerspectiveDepth( const in float viewZ, const in float near, const in float far ) {\n return (( near + viewZ ) * far ) / (( far - near ) * viewZ );\n}\nfloat perspectiveDepthToViewZ( const in float invClipZ, const in float near, const in float far ) {\n return ( near * far ) / ( ( far - near ) * invClipZ - far );\n}\n";
  14215. // File:src/renderers/shaders/ShaderChunk/premultiplied_alpha_fragment.glsl
  14216. THREE.ShaderChunk[ 'premultiplied_alpha_fragment' ] = "#ifdef PREMULTIPLIED_ALPHA\n gl_FragColor.rgb *= gl_FragColor.a;\n#endif\n";
  14217. // File:src/renderers/shaders/ShaderChunk/project_vertex.glsl
  14218. 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";
  14219. // File:src/renderers/shaders/ShaderChunk/roughnessmap_fragment.glsl
  14220. THREE.ShaderChunk[ 'roughnessmap_fragment' ] = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n vec4 texelRoughness = texture2D( roughnessMap, vUv );\n roughnessFactor *= texelRoughness.r;\n#endif\n";
  14221. // File:src/renderers/shaders/ShaderChunk/roughnessmap_pars_fragment.glsl
  14222. THREE.ShaderChunk[ 'roughnessmap_pars_fragment' ] = "#ifdef USE_ROUGHNESSMAP\n uniform sampler2D roughnessMap;\n#endif";
  14223. // File:src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl
  14224. THREE.ShaderChunk[ 'shadowmap_pars_fragment' ] = "#ifdef USE_SHADOWMAP\n #if NUM_DIR_LIGHTS > 0\n uniform sampler2D directionalShadowMap[ NUM_DIR_LIGHTS ];\n varying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHTS ];\n #endif\n #if NUM_SPOT_LIGHTS > 0\n uniform sampler2D spotShadowMap[ NUM_SPOT_LIGHTS ];\n varying vec4 vSpotShadowCoord[ NUM_SPOT_LIGHTS ];\n #endif\n #if NUM_POINT_LIGHTS > 0\n uniform sampler2D pointShadowMap[ NUM_POINT_LIGHTS ];\n varying vec4 vPointShadowCoord[ NUM_POINT_LIGHTS ];\n #endif\n float texture2DCompare( sampler2D depths, vec2 uv, float compare ) {\n return step( compare, unpackRGBAToDepth( texture2D( depths, uv ) ) );\n }\n float texture2DShadowLerp( sampler2D depths, vec2 size, vec2 uv, float compare ) {\n const vec2 offset = vec2( 0.0, 1.0 );\n vec2 texelSize = vec2( 1.0 ) / size;\n vec2 centroidUV = floor( uv * size + 0.5 ) / size;\n float lb = texture2DCompare( depths, centroidUV + texelSize * offset.xx, compare );\n float lt = texture2DCompare( depths, centroidUV + texelSize * offset.xy, compare );\n float rb = texture2DCompare( depths, centroidUV + texelSize * offset.yx, compare );\n float rt = texture2DCompare( depths, centroidUV + texelSize * offset.yy, compare );\n vec2 f = fract( uv * size + 0.5 );\n float a = mix( lb, lt, f.y );\n float b = mix( rb, rt, f.y );\n float c = mix( a, b, f.x );\n return c;\n }\n float getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord ) {\n shadowCoord.xyz /= shadowCoord.w;\n shadowCoord.z += shadowBias;\n bvec4 inFrustumVec = bvec4 ( shadowCoord.x >= 0.0, shadowCoord.x <= 1.0, shadowCoord.y >= 0.0, shadowCoord.y <= 1.0 );\n bool inFrustum = all( inFrustumVec );\n bvec2 frustumTestVec = bvec2( inFrustum, shadowCoord.z <= 1.0 );\n bool frustumTest = all( frustumTestVec );\n if ( frustumTest ) {\n #if defined( SHADOWMAP_TYPE_PCF )\n vec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n float dx0 = - texelSize.x * shadowRadius;\n float dy0 = - texelSize.y * shadowRadius;\n float dx1 = + texelSize.x * shadowRadius;\n float dy1 = + texelSize.y * shadowRadius;\n return (\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )\n ) * ( 1.0 / 9.0 );\n #elif defined( SHADOWMAP_TYPE_PCF_SOFT )\n vec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n float dx0 = - texelSize.x * shadowRadius;\n float dy0 = - texelSize.y * shadowRadius;\n float dx1 = + texelSize.x * shadowRadius;\n float dy1 = + texelSize.y * shadowRadius;\n return (\n texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +\n texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +\n texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +\n texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +\n texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy, shadowCoord.z ) +\n texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +\n texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +\n texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +\n texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )\n ) * ( 1.0 / 9.0 );\n #else\n return texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z );\n #endif\n }\n return 1.0;\n }\n vec2 cubeToUV( vec3 v, float texelSizeY ) {\n vec3 absV = abs( v );\n float scaleToCube = 1.0 / max( absV.x, max( absV.y, absV.z ) );\n absV *= scaleToCube;\n v *= scaleToCube * ( 1.0 - 2.0 * texelSizeY );\n vec2 planar = v.xy;\n float almostATexel = 1.5 * texelSizeY;\n float almostOne = 1.0 - almostATexel;\n if ( absV.z >= almostOne ) {\n if ( v.z > 0.0 )\n planar.x = 4.0 - v.x;\n } else if ( absV.x >= almostOne ) {\n float signX = sign( v.x );\n planar.x = v.z * signX + 2.0 * signX;\n } else if ( absV.y >= almostOne ) {\n float signY = sign( v.y );\n planar.x = v.x + 2.0 * signY + 2.0;\n planar.y = v.z * signY - 2.0;\n }\n return vec2( 0.125, 0.25 ) * planar + vec2( 0.375, 0.75 );\n }\n float getPointShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord ) {\n vec2 texelSize = vec2( 1.0 ) / ( shadowMapSize * vec2( 4.0, 2.0 ) );\n vec3 lightToPosition = shadowCoord.xyz;\n vec3 bd3D = normalize( lightToPosition );\n float dp = ( length( lightToPosition ) - shadowBias ) / 1000.0;\n #if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT )\n vec2 offset = vec2( - 1, 1 ) * shadowRadius * texelSize.y;\n return (\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyy, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyy, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyx, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyx, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxy, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxy, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxx, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxx, texelSize.y ), dp )\n ) * ( 1.0 / 9.0 );\n #else\n return texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp );\n #endif\n }\n#endif\n";
  14225. // File:src/renderers/shaders/ShaderChunk/shadowmap_pars_vertex.glsl
  14226. THREE.ShaderChunk[ 'shadowmap_pars_vertex' ] = "#ifdef USE_SHADOWMAP\n #if NUM_DIR_LIGHTS > 0\n uniform mat4 directionalShadowMatrix[ NUM_DIR_LIGHTS ];\n varying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHTS ];\n #endif\n #if NUM_SPOT_LIGHTS > 0\n uniform mat4 spotShadowMatrix[ NUM_SPOT_LIGHTS ];\n varying vec4 vSpotShadowCoord[ NUM_SPOT_LIGHTS ];\n #endif\n #if NUM_POINT_LIGHTS > 0\n uniform mat4 pointShadowMatrix[ NUM_POINT_LIGHTS ];\n varying vec4 vPointShadowCoord[ NUM_POINT_LIGHTS ];\n #endif\n#endif\n";
  14227. // File:src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl
  14228. THREE.ShaderChunk[ 'shadowmap_vertex' ] = "#ifdef USE_SHADOWMAP\n #if NUM_DIR_LIGHTS > 0\n for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n vDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * worldPosition;\n }\n #endif\n #if NUM_SPOT_LIGHTS > 0\n for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n vSpotShadowCoord[ i ] = spotShadowMatrix[ i ] * worldPosition;\n }\n #endif\n #if NUM_POINT_LIGHTS > 0\n for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n vPointShadowCoord[ i ] = pointShadowMatrix[ i ] * worldPosition;\n }\n #endif\n#endif\n";
  14229. // File:src/renderers/shaders/ShaderChunk/shadowmask_pars_fragment.glsl
  14230. THREE.ShaderChunk[ 'shadowmask_pars_fragment' ] = "float getShadowMask() {\n float shadow = 1.0;\n #ifdef USE_SHADOWMAP\n #if NUM_DIR_LIGHTS > 0\n DirectionalLight directionalLight;\n for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n directionalLight = directionalLights[ i ];\n shadow *= bool( directionalLight.shadow ) ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n }\n #endif\n #if NUM_SPOT_LIGHTS > 0\n SpotLight spotLight;\n for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n spotLight = spotLights[ i ];\n shadow *= bool( spotLight.shadow ) ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowBias, spotLight.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\n }\n #endif\n #if NUM_POINT_LIGHTS > 0\n PointLight pointLight;\n for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n pointLight = pointLights[ i ];\n shadow *= bool( pointLight.shadow ) ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ] ) : 1.0;\n }\n #endif\n #endif\n return shadow;\n}\n";
  14231. // File:src/renderers/shaders/ShaderChunk/skinbase_vertex.glsl
  14232. 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";
  14233. // File:src/renderers/shaders/ShaderChunk/skinning_pars_vertex.glsl
  14234. 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 boneMatrices[ MAX_BONES ];\n mat4 getBoneMatrix( const in float i ) {\n mat4 bone = boneMatrices[ int(i) ];\n return bone;\n }\n #endif\n#endif\n";
  14235. // File:src/renderers/shaders/ShaderChunk/skinning_vertex.glsl
  14236. 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";
  14237. // File:src/renderers/shaders/ShaderChunk/skinnormal_vertex.glsl
  14238. 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";
  14239. // File:src/renderers/shaders/ShaderChunk/specularmap_fragment.glsl
  14240. 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";
  14241. // File:src/renderers/shaders/ShaderChunk/specularmap_pars_fragment.glsl
  14242. THREE.ShaderChunk[ 'specularmap_pars_fragment' ] = "#ifdef USE_SPECULARMAP\n uniform sampler2D specularMap;\n#endif";
  14243. // File:src/renderers/shaders/ShaderChunk/tonemapping_fragment.glsl
  14244. THREE.ShaderChunk[ 'tonemapping_fragment' ] = "#if defined( TONE_MAPPING )\n gl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif\n";
  14245. // File:src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl
  14246. THREE.ShaderChunk[ 'tonemapping_pars_fragment' ] = "#define saturate(a) clamp( a, 0.0, 1.0 )\nuniform float toneMappingExposure;\nuniform float toneMappingWhitePoint;\nvec3 LinearToneMapping( vec3 color ) {\n return toneMappingExposure * color;\n}\nvec3 ReinhardToneMapping( vec3 color ) {\n color *= toneMappingExposure;\n return saturate( color / ( vec3( 1.0 ) + color ) );\n}\n#define Uncharted2Helper( x ) max( ( ( x * ( 0.15 * x + 0.10 * 0.50 ) + 0.20 * 0.02 ) / ( x * ( 0.15 * x + 0.50 ) + 0.20 * 0.30 ) ) - 0.02 / 0.30, vec3( 0.0 ) )\nvec3 Uncharted2ToneMapping( vec3 color ) {\n color *= toneMappingExposure;\n return saturate( Uncharted2Helper( color ) / Uncharted2Helper( vec3( toneMappingWhitePoint ) ) );\n}\nvec3 OptimizedCineonToneMapping( vec3 color ) {\n color *= toneMappingExposure;\n color = max( vec3( 0.0 ), color - 0.004 );\n return pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) );\n}\n";
  14247. // File:src/renderers/shaders/ShaderChunk/uv2_pars_fragment.glsl
  14248. THREE.ShaderChunk[ 'uv2_pars_fragment' ] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n varying vec2 vUv2;\n#endif";
  14249. // File:src/renderers/shaders/ShaderChunk/uv2_pars_vertex.glsl
  14250. THREE.ShaderChunk[ 'uv2_pars_vertex' ] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n attribute vec2 uv2;\n varying vec2 vUv2;\n#endif";
  14251. // File:src/renderers/shaders/ShaderChunk/uv2_vertex.glsl
  14252. THREE.ShaderChunk[ 'uv2_vertex' ] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n vUv2 = uv2;\n#endif";
  14253. // File:src/renderers/shaders/ShaderChunk/uv_pars_fragment.glsl
  14254. THREE.ShaderChunk[ 'uv_pars_fragment' ] = "#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP ) || defined( USE_ROUGHNESSMAP ) || defined( USE_METALNESSMAP )\n varying vec2 vUv;\n#endif";
  14255. // File:src/renderers/shaders/ShaderChunk/uv_pars_vertex.glsl
  14256. THREE.ShaderChunk[ 'uv_pars_vertex' ] = "#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP ) || defined( USE_ROUGHNESSMAP ) || defined( USE_METALNESSMAP )\n varying vec2 vUv;\n uniform vec4 offsetRepeat;\n#endif\n";
  14257. // File:src/renderers/shaders/ShaderChunk/uv_vertex.glsl
  14258. THREE.ShaderChunk[ 'uv_vertex' ] = "#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP ) || defined( USE_ROUGHNESSMAP ) || defined( USE_METALNESSMAP )\n vUv = uv * offsetRepeat.zw + offsetRepeat.xy;\n#endif";
  14259. // File:src/renderers/shaders/ShaderChunk/worldpos_vertex.glsl
  14260. 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";
  14261. // File:src/renderers/shaders/UniformsUtils.js
  14262. /**
  14263. * Uniform Utilities
  14264. */
  14265. THREE.UniformsUtils = {
  14266. merge: function ( uniforms ) {
  14267. var merged = {};
  14268. for ( var u = 0; u < uniforms.length; u ++ ) {
  14269. var tmp = this.clone( uniforms[ u ] );
  14270. for ( var p in tmp ) {
  14271. merged[ p ] = tmp[ p ];
  14272. }
  14273. }
  14274. return merged;
  14275. },
  14276. clone: function ( uniforms_src ) {
  14277. var uniforms_dst = {};
  14278. for ( var u in uniforms_src ) {
  14279. uniforms_dst[ u ] = {};
  14280. for ( var p in uniforms_src[ u ] ) {
  14281. var parameter_src = uniforms_src[ u ][ p ];
  14282. if ( parameter_src instanceof THREE.Color ||
  14283. parameter_src instanceof THREE.Vector2 ||
  14284. parameter_src instanceof THREE.Vector3 ||
  14285. parameter_src instanceof THREE.Vector4 ||
  14286. parameter_src instanceof THREE.Matrix3 ||
  14287. parameter_src instanceof THREE.Matrix4 ||
  14288. parameter_src instanceof THREE.Texture ) {
  14289. uniforms_dst[ u ][ p ] = parameter_src.clone();
  14290. } else if ( Array.isArray( parameter_src ) ) {
  14291. uniforms_dst[ u ][ p ] = parameter_src.slice();
  14292. } else {
  14293. uniforms_dst[ u ][ p ] = parameter_src;
  14294. }
  14295. }
  14296. }
  14297. return uniforms_dst;
  14298. }
  14299. };
  14300. // File:src/renderers/shaders/UniformsLib.js
  14301. /**
  14302. * Uniforms library for shared webgl shaders
  14303. */
  14304. THREE.UniformsLib = {
  14305. common: {
  14306. "diffuse": { type: "c", value: new THREE.Color( 0xeeeeee ) },
  14307. "opacity": { type: "1f", value: 1.0 },
  14308. "map": { type: "t", value: null },
  14309. "offsetRepeat": { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) },
  14310. "specularMap": { type: "t", value: null },
  14311. "alphaMap": { type: "t", value: null },
  14312. "envMap": { type: "t", value: null },
  14313. "flipEnvMap": { type: "1f", value: - 1 },
  14314. "reflectivity": { type: "1f", value: 1.0 },
  14315. "refractionRatio": { type: "1f", value: 0.98 }
  14316. },
  14317. aomap: {
  14318. "aoMap": { type: "t", value: null },
  14319. "aoMapIntensity": { type: "1f", value: 1 }
  14320. },
  14321. lightmap: {
  14322. "lightMap": { type: "t", value: null },
  14323. "lightMapIntensity": { type: "1f", value: 1 }
  14324. },
  14325. emissivemap: {
  14326. "emissiveMap": { type: "t", value: null }
  14327. },
  14328. bumpmap: {
  14329. "bumpMap": { type: "t", value: null },
  14330. "bumpScale": { type: "1f", value: 1 }
  14331. },
  14332. normalmap: {
  14333. "normalMap": { type: "t", value: null },
  14334. "normalScale": { type: "v2", value: new THREE.Vector2( 1, 1 ) }
  14335. },
  14336. displacementmap: {
  14337. "displacementMap": { type: "t", value: null },
  14338. "displacementScale": { type: "1f", value: 1 },
  14339. "displacementBias": { type: "1f", value: 0 }
  14340. },
  14341. roughnessmap: {
  14342. "roughnessMap": { type: "t", value: null }
  14343. },
  14344. metalnessmap: {
  14345. "metalnessMap": { type: "t", value: null }
  14346. },
  14347. fog: {
  14348. "fogDensity": { type: "1f", value: 0.00025 },
  14349. "fogNear": { type: "1f", value: 1 },
  14350. "fogFar": { type: "1f", value: 2000 },
  14351. "fogColor": { type: "c", value: new THREE.Color( 0xffffff ) }
  14352. },
  14353. lights: {
  14354. "ambientLightColor": { type: "3fv", value: [] },
  14355. "directionalLights": { type: "sa", value: [], properties: {
  14356. "direction": { type: "v3" },
  14357. "color": { type: "c" },
  14358. "shadow": { type: "1i" },
  14359. "shadowBias": { type: "1f" },
  14360. "shadowRadius": { type: "1f" },
  14361. "shadowMapSize": { type: "v2" }
  14362. } },
  14363. "directionalShadowMap": { type: "tv", value: [] },
  14364. "directionalShadowMatrix": { type: "m4v", value: [] },
  14365. "spotLights": { type: "sa", value: [], properties: {
  14366. "color": { type: "c" },
  14367. "position": { type: "v3" },
  14368. "direction": { type: "v3" },
  14369. "distance": { type: "1f" },
  14370. "coneCos": { type: "1f" },
  14371. "penumbraCos": { type: "1f" },
  14372. "decay": { type: "1f" },
  14373. "shadow": { type: "1i" },
  14374. "shadowBias": { type: "1f" },
  14375. "shadowRadius": { type: "1f" },
  14376. "shadowMapSize": { type: "v2" }
  14377. } },
  14378. "spotShadowMap": { type: "tv", value: [] },
  14379. "spotShadowMatrix": { type: "m4v", value: [] },
  14380. "pointLights": { type: "sa", value: [], properties: {
  14381. "color": { type: "c" },
  14382. "position": { type: "v3" },
  14383. "decay": { type: "1f" },
  14384. "distance": { type: "1f" },
  14385. "shadow": { type: "1i" },
  14386. "shadowBias": { type: "1f" },
  14387. "shadowRadius": { type: "1f" },
  14388. "shadowMapSize": { type: "v2" }
  14389. } },
  14390. "pointShadowMap": { type: "tv", value: [] },
  14391. "pointShadowMatrix": { type: "m4v", value: [] },
  14392. "hemisphereLights": { type: "sa", value: [], properties: {
  14393. "direction": { type: "v3" },
  14394. "skyColor": { type: "c" },
  14395. "groundColor": { type: "c" }
  14396. } }
  14397. },
  14398. points: {
  14399. "diffuse": { type: "c", value: new THREE.Color( 0xeeeeee ) },
  14400. "opacity": { type: "1f", value: 1.0 },
  14401. "size": { type: "1f", value: 1.0 },
  14402. "scale": { type: "1f", value: 1.0 },
  14403. "map": { type: "t", value: null },
  14404. "offsetRepeat": { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) }
  14405. }
  14406. };
  14407. // File:src/renderers/shaders/ShaderLib/cube_frag.glsl
  14408. THREE.ShaderChunk[ 'cube_frag' ] = "uniform samplerCube tCube;\nuniform float tFlip;\nvarying vec3 vWorldPosition;\n#include <common>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n #include <clipping_planes_fragment>\n gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );\n #include <logdepthbuf_fragment>\n}\n";
  14409. // File:src/renderers/shaders/ShaderLib/cube_vert.glsl
  14410. THREE.ShaderChunk[ 'cube_vert' ] = "varying vec3 vWorldPosition;\n#include <common>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n vWorldPosition = transformDirection( position, modelMatrix );\n #include <begin_vertex>\n #include <project_vertex>\n #include <logdepthbuf_vertex>\n #include <clipping_planes_vertex>\n}\n";
  14411. // File:src/renderers/shaders/ShaderLib/depth_frag.glsl
  14412. THREE.ShaderChunk[ 'depth_frag' ] = "#if DEPTH_PACKING == 3200\n uniform float opacity;\n#endif\n#include <common>\n#include <packing>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n #include <clipping_planes_fragment>\n vec4 diffuseColor = vec4( 1.0 );\n #if DEPTH_PACKING == 3200\n diffuseColor.a = opacity;\n #endif\n #include <map_fragment>\n #include <alphamap_fragment>\n #include <alphatest_fragment>\n #include <logdepthbuf_fragment>\n #if DEPTH_PACKING == 3200\n gl_FragColor = vec4( vec3( gl_FragCoord.z ), opacity );\n #elif DEPTH_PACKING == 3201\n gl_FragColor = packDepthToRGBA( gl_FragCoord.z );\n #endif\n}\n";
  14413. // File:src/renderers/shaders/ShaderLib/depth_vert.glsl
  14414. THREE.ShaderChunk[ 'depth_vert' ] = "#include <common>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n #include <uv_vertex>\n #include <skinbase_vertex>\n #include <begin_vertex>\n #include <displacementmap_vertex>\n #include <morphtarget_vertex>\n #include <skinning_vertex>\n #include <project_vertex>\n #include <logdepthbuf_vertex>\n #include <clipping_planes_vertex>\n}\n";
  14415. // File:src/renderers/shaders/ShaderLib/distanceRGBA_frag.glsl
  14416. THREE.ShaderChunk[ 'distanceRGBA_frag' ] = "uniform vec3 lightPos;\nvarying vec4 vWorldPosition;\n#include <common>\n#include <packing>\n#include <clipping_planes_pars_fragment>\nvoid main () {\n #include <clipping_planes_fragment>\n gl_FragColor = packDepthToRGBA( length( vWorldPosition.xyz - lightPos.xyz ) / 1000.0 );\n}\n";
  14417. // File:src/renderers/shaders/ShaderLib/distanceRGBA_vert.glsl
  14418. THREE.ShaderChunk[ 'distanceRGBA_vert' ] = "varying vec4 vWorldPosition;\n#include <common>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n #include <skinbase_vertex>\n #include <begin_vertex>\n #include <morphtarget_vertex>\n #include <skinning_vertex>\n #include <project_vertex>\n #include <worldpos_vertex>\n #include <clipping_planes_vertex>\n vWorldPosition = worldPosition;\n}\n";
  14419. // File:src/renderers/shaders/ShaderLib/equirect_frag.glsl
  14420. THREE.ShaderChunk[ 'equirect_frag' ] = "uniform sampler2D tEquirect;\nuniform float tFlip;\nvarying vec3 vWorldPosition;\n#include <common>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n #include <clipping_planes_fragment>\n vec3 direction = normalize( vWorldPosition );\n vec2 sampleUV;\n sampleUV.y = saturate( tFlip * direction.y * -0.5 + 0.5 );\n sampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;\n gl_FragColor = texture2D( tEquirect, sampleUV );\n #include <logdepthbuf_fragment>\n}\n";
  14421. // File:src/renderers/shaders/ShaderLib/equirect_vert.glsl
  14422. THREE.ShaderChunk[ 'equirect_vert' ] = "varying vec3 vWorldPosition;\n#include <common>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n vWorldPosition = transformDirection( position, modelMatrix );\n #include <begin_vertex>\n #include <project_vertex>\n #include <logdepthbuf_vertex>\n #include <clipping_planes_vertex>\n}\n";
  14423. // File:src/renderers/shaders/ShaderLib/linedashed_frag.glsl
  14424. THREE.ShaderChunk[ 'linedashed_frag' ] = "uniform vec3 diffuse;\nuniform float opacity;\nuniform float dashSize;\nuniform float totalSize;\nvarying float vLineDistance;\n#include <common>\n#include <color_pars_fragment>\n#include <fog_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n #include <clipping_planes_fragment>\n if ( mod( vLineDistance, totalSize ) > dashSize ) {\n discard;\n }\n vec3 outgoingLight = vec3( 0.0 );\n vec4 diffuseColor = vec4( diffuse, opacity );\n #include <logdepthbuf_fragment>\n #include <color_fragment>\n outgoingLight = diffuseColor.rgb;\n gl_FragColor = vec4( outgoingLight, diffuseColor.a );\n #include <premultiplied_alpha_fragment>\n #include <tonemapping_fragment>\n #include <encodings_fragment>\n #include <fog_fragment>\n}\n";
  14425. // File:src/renderers/shaders/ShaderLib/linedashed_vert.glsl
  14426. THREE.ShaderChunk[ 'linedashed_vert' ] = "uniform float scale;\nattribute float lineDistance;\nvarying float vLineDistance;\n#include <common>\n#include <color_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n #include <color_vertex>\n vLineDistance = scale * lineDistance;\n vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\n gl_Position = projectionMatrix * mvPosition;\n #include <logdepthbuf_vertex>\n #include <clipping_planes_vertex>\n}\n";
  14427. // File:src/renderers/shaders/ShaderLib/meshbasic_frag.glsl
  14428. THREE.ShaderChunk[ 'meshbasic_frag' ] = "uniform vec3 diffuse;\nuniform float opacity;\n#ifndef FLAT_SHADED\n varying vec3 vNormal;\n#endif\n#include <common>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <envmap_pars_fragment>\n#include <fog_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n #include <clipping_planes_fragment>\n vec4 diffuseColor = vec4( diffuse, opacity );\n #include <logdepthbuf_fragment>\n #include <map_fragment>\n #include <color_fragment>\n #include <alphamap_fragment>\n #include <alphatest_fragment>\n #include <specularmap_fragment>\n ReflectedLight reflectedLight;\n reflectedLight.directDiffuse = vec3( 0.0 );\n reflectedLight.directSpecular = vec3( 0.0 );\n reflectedLight.indirectDiffuse = diffuseColor.rgb;\n reflectedLight.indirectSpecular = vec3( 0.0 );\n #include <aomap_fragment>\n vec3 outgoingLight = reflectedLight.indirectDiffuse;\n #include <envmap_fragment>\n gl_FragColor = vec4( outgoingLight, diffuseColor.a );\n #include <premultiplied_alpha_fragment>\n #include <tonemapping_fragment>\n #include <encodings_fragment>\n #include <fog_fragment>\n}\n";
  14429. // File:src/renderers/shaders/ShaderLib/meshbasic_vert.glsl
  14430. THREE.ShaderChunk[ 'meshbasic_vert' ] = "#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <envmap_pars_vertex>\n#include <color_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n #include <uv_vertex>\n #include <uv2_vertex>\n #include <color_vertex>\n #include <skinbase_vertex>\n #ifdef USE_ENVMAP\n #include <beginnormal_vertex>\n #include <morphnormal_vertex>\n #include <skinnormal_vertex>\n #include <defaultnormal_vertex>\n #endif\n #include <begin_vertex>\n #include <morphtarget_vertex>\n #include <skinning_vertex>\n #include <project_vertex>\n #include <logdepthbuf_vertex>\n #include <worldpos_vertex>\n #include <clipping_planes_vertex>\n #include <envmap_vertex>\n}\n";
  14431. // File:src/renderers/shaders/ShaderLib/meshlambert_frag.glsl
  14432. THREE.ShaderChunk[ 'meshlambert_frag' ] = "uniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\nvarying vec3 vLightFront;\n#ifdef DOUBLE_SIDED\n varying vec3 vLightBack;\n#endif\n#include <common>\n#include <packing>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <envmap_pars_fragment>\n#include <bsdfs>\n#include <lights_pars>\n#include <fog_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <shadowmask_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n #include <clipping_planes_fragment>\n vec4 diffuseColor = vec4( diffuse, opacity );\n ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n vec3 totalEmissiveRadiance = emissive;\n #include <logdepthbuf_fragment>\n #include <map_fragment>\n #include <color_fragment>\n #include <alphamap_fragment>\n #include <alphatest_fragment>\n #include <specularmap_fragment>\n #include <emissivemap_fragment>\n reflectedLight.indirectDiffuse = getAmbientLightIrradiance( ambientLightColor );\n #include <lightmap_fragment>\n reflectedLight.indirectDiffuse *= BRDF_Diffuse_Lambert( diffuseColor.rgb );\n #ifdef DOUBLE_SIDED\n reflectedLight.directDiffuse = ( gl_FrontFacing ) ? vLightFront : vLightBack;\n #else\n reflectedLight.directDiffuse = vLightFront;\n #endif\n reflectedLight.directDiffuse *= BRDF_Diffuse_Lambert( diffuseColor.rgb ) * getShadowMask();\n #include <aomap_fragment>\n vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n #include <envmap_fragment>\n gl_FragColor = vec4( outgoingLight, diffuseColor.a );\n #include <premultiplied_alpha_fragment>\n #include <tonemapping_fragment>\n #include <encodings_fragment>\n #include <fog_fragment>\n}\n";
  14433. // File:src/renderers/shaders/ShaderLib/meshlambert_vert.glsl
  14434. THREE.ShaderChunk[ 'meshlambert_vert' ] = "#define LAMBERT\nvarying vec3 vLightFront;\n#ifdef DOUBLE_SIDED\n varying vec3 vLightBack;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <envmap_pars_vertex>\n#include <bsdfs>\n#include <lights_pars>\n#include <color_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n #include <uv_vertex>\n #include <uv2_vertex>\n #include <color_vertex>\n #include <beginnormal_vertex>\n #include <morphnormal_vertex>\n #include <skinbase_vertex>\n #include <skinnormal_vertex>\n #include <defaultnormal_vertex>\n #include <begin_vertex>\n #include <morphtarget_vertex>\n #include <skinning_vertex>\n #include <project_vertex>\n #include <logdepthbuf_vertex>\n #include <clipping_planes_vertex>\n #include <worldpos_vertex>\n #include <envmap_vertex>\n #include <lights_lambert_vertex>\n #include <shadowmap_vertex>\n}\n";
  14435. // File:src/renderers/shaders/ShaderLib/meshphong_frag.glsl
  14436. THREE.ShaderChunk[ 'meshphong_frag' ] = "#define PHONG\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform vec3 specular;\nuniform float shininess;\nuniform float opacity;\n#include <common>\n#include <packing>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <envmap_pars_fragment>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars>\n#include <lights_phong_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n #include <clipping_planes_fragment>\n vec4 diffuseColor = vec4( diffuse, opacity );\n ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n vec3 totalEmissiveRadiance = emissive;\n #include <logdepthbuf_fragment>\n #include <map_fragment>\n #include <color_fragment>\n #include <alphamap_fragment>\n #include <alphatest_fragment>\n #include <specularmap_fragment>\n #include <normal_fragment>\n #include <emissivemap_fragment>\n #include <lights_phong_fragment>\n #include <lights_template>\n #include <aomap_fragment>\n vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\n #include <envmap_fragment>\n gl_FragColor = vec4( outgoingLight, diffuseColor.a );\n #include <premultiplied_alpha_fragment>\n #include <tonemapping_fragment>\n #include <encodings_fragment>\n #include <fog_fragment>\n}\n";
  14437. // File:src/renderers/shaders/ShaderLib/meshphong_vert.glsl
  14438. THREE.ShaderChunk[ 'meshphong_vert' ] = "#define PHONG\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n varying vec3 vNormal;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <envmap_pars_vertex>\n#include <color_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n #include <uv_vertex>\n #include <uv2_vertex>\n #include <color_vertex>\n #include <beginnormal_vertex>\n #include <morphnormal_vertex>\n #include <skinbase_vertex>\n #include <skinnormal_vertex>\n #include <defaultnormal_vertex>\n#ifndef FLAT_SHADED\n vNormal = normalize( transformedNormal );\n#endif\n #include <begin_vertex>\n #include <displacementmap_vertex>\n #include <morphtarget_vertex>\n #include <skinning_vertex>\n #include <project_vertex>\n #include <logdepthbuf_vertex>\n #include <clipping_planes_vertex>\n vViewPosition = - mvPosition.xyz;\n #include <worldpos_vertex>\n #include <envmap_vertex>\n #include <shadowmap_vertex>\n}\n";
  14439. // File:src/renderers/shaders/ShaderLib/meshphysical_frag.glsl
  14440. THREE.ShaderChunk[ 'meshphysical_frag' ] = "#define PHYSICAL\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float roughness;\nuniform float metalness;\nuniform float opacity;\nuniform float envMapIntensity;\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n varying vec3 vNormal;\n#endif\n#include <common>\n#include <packing>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <envmap_pars_fragment>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <cube_uv_reflection_fragment>\n#include <lights_pars>\n#include <lights_physical_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <roughnessmap_pars_fragment>\n#include <metalnessmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n #include <clipping_planes_fragment>\n vec4 diffuseColor = vec4( diffuse, opacity );\n ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n vec3 totalEmissiveRadiance = emissive;\n #include <logdepthbuf_fragment>\n #include <map_fragment>\n #include <color_fragment>\n #include <alphamap_fragment>\n #include <alphatest_fragment>\n #include <specularmap_fragment>\n #include <roughnessmap_fragment>\n #include <metalnessmap_fragment>\n #include <normal_fragment>\n #include <emissivemap_fragment>\n #include <lights_physical_fragment>\n #include <lights_template>\n #include <aomap_fragment>\n vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\n gl_FragColor = vec4( outgoingLight, diffuseColor.a );\n #include <premultiplied_alpha_fragment>\n #include <tonemapping_fragment>\n #include <encodings_fragment>\n #include <fog_fragment>\n}\n";
  14441. // File:src/renderers/shaders/ShaderLib/meshphysical_vert.glsl
  14442. THREE.ShaderChunk[ 'meshphysical_vert' ] = "#define PHYSICAL\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n varying vec3 vNormal;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <color_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n #include <uv_vertex>\n #include <uv2_vertex>\n #include <color_vertex>\n #include <beginnormal_vertex>\n #include <morphnormal_vertex>\n #include <skinbase_vertex>\n #include <skinnormal_vertex>\n #include <defaultnormal_vertex>\n#ifndef FLAT_SHADED\n vNormal = normalize( transformedNormal );\n#endif\n #include <begin_vertex>\n #include <displacementmap_vertex>\n #include <morphtarget_vertex>\n #include <skinning_vertex>\n #include <project_vertex>\n #include <logdepthbuf_vertex>\n #include <clipping_planes_vertex>\n vViewPosition = - mvPosition.xyz;\n #include <worldpos_vertex>\n #include <shadowmap_vertex>\n}\n";
  14443. // File:src/renderers/shaders/ShaderLib/normal_frag.glsl
  14444. THREE.ShaderChunk[ 'normal_frag' ] = "uniform float opacity;\nvarying vec3 vNormal;\n#include <common>\n#include <packing>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n #include <clipping_planes_fragment>\n gl_FragColor = vec4( packNormalToRGB( vNormal ), opacity );\n #include <logdepthbuf_fragment>\n}\n";
  14445. // File:src/renderers/shaders/ShaderLib/normal_vert.glsl
  14446. THREE.ShaderChunk[ 'normal_vert' ] = "varying vec3 vNormal;\n#include <common>\n#include <morphtarget_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n vNormal = normalize( normalMatrix * normal );\n #include <begin_vertex>\n #include <morphtarget_vertex>\n #include <project_vertex>\n #include <logdepthbuf_vertex>\n #include <clipping_planes_vertex>\n}\n";
  14447. // File:src/renderers/shaders/ShaderLib/points_frag.glsl
  14448. THREE.ShaderChunk[ 'points_frag' ] = "uniform vec3 diffuse;\nuniform float opacity;\n#include <common>\n#include <color_pars_fragment>\n#include <map_particle_pars_fragment>\n#include <fog_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n #include <clipping_planes_fragment>\n vec3 outgoingLight = vec3( 0.0 );\n vec4 diffuseColor = vec4( diffuse, opacity );\n #include <logdepthbuf_fragment>\n #include <map_particle_fragment>\n #include <color_fragment>\n #include <alphatest_fragment>\n outgoingLight = diffuseColor.rgb;\n gl_FragColor = vec4( outgoingLight, diffuseColor.a );\n #include <premultiplied_alpha_fragment>\n #include <tonemapping_fragment>\n #include <encodings_fragment>\n #include <fog_fragment>\n}\n";
  14449. // File:src/renderers/shaders/ShaderLib/points_vert.glsl
  14450. THREE.ShaderChunk[ 'points_vert' ] = "uniform float size;\nuniform float scale;\n#include <common>\n#include <color_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n #include <color_vertex>\n #include <begin_vertex>\n #include <project_vertex>\n #ifdef USE_SIZEATTENUATION\n gl_PointSize = size * ( scale / - mvPosition.z );\n #else\n gl_PointSize = size;\n #endif\n #include <logdepthbuf_vertex>\n #include <clipping_planes_vertex>\n #include <worldpos_vertex>\n #include <shadowmap_vertex>\n}\n";
  14451. // File:src/renderers/shaders/ShaderLib/shadow_frag.glsl
  14452. THREE.ShaderChunk[ 'shadow_frag' ] = "uniform float opacity;\n#include <common>\n#include <packing>\n#include <bsdfs>\n#include <lights_pars>\n#include <shadowmap_pars_fragment>\n#include <shadowmask_pars_fragment>\nvoid main() {\n gl_FragColor = vec4( 0.0, 0.0, 0.0, opacity * ( 1.0 - getShadowMask() ) );\n}\n";
  14453. // File:src/renderers/shaders/ShaderLib/shadow_vert.glsl
  14454. THREE.ShaderChunk[ 'shadow_vert' ] = "#include <shadowmap_pars_vertex>\nvoid main() {\n #include <begin_vertex>\n #include <project_vertex>\n #include <worldpos_vertex>\n #include <shadowmap_vertex>\n}\n";
  14455. // File:src/renderers/shaders/ShaderLib.js
  14456. /**
  14457. * Webgl Shader Library for three.js
  14458. *
  14459. * @author alteredq / http://alteredqualia.com/
  14460. * @author mrdoob / http://mrdoob.com/
  14461. * @author mikael emtinger / http://gomo.se/
  14462. */
  14463. THREE.ShaderLib = {
  14464. 'basic': {
  14465. uniforms: THREE.UniformsUtils.merge( [
  14466. THREE.UniformsLib[ 'common' ],
  14467. THREE.UniformsLib[ 'aomap' ],
  14468. THREE.UniformsLib[ 'fog' ]
  14469. ] ),
  14470. vertexShader: THREE.ShaderChunk[ 'meshbasic_vert' ],
  14471. fragmentShader: THREE.ShaderChunk[ 'meshbasic_frag' ]
  14472. },
  14473. 'lambert': {
  14474. uniforms: THREE.UniformsUtils.merge( [
  14475. THREE.UniformsLib[ 'common' ],
  14476. THREE.UniformsLib[ 'aomap' ],
  14477. THREE.UniformsLib[ 'lightmap' ],
  14478. THREE.UniformsLib[ 'emissivemap' ],
  14479. THREE.UniformsLib[ 'fog' ],
  14480. THREE.UniformsLib[ 'lights' ],
  14481. {
  14482. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) }
  14483. }
  14484. ] ),
  14485. vertexShader: THREE.ShaderChunk[ 'meshlambert_vert' ],
  14486. fragmentShader: THREE.ShaderChunk[ 'meshlambert_frag' ]
  14487. },
  14488. 'phong': {
  14489. uniforms: THREE.UniformsUtils.merge( [
  14490. THREE.UniformsLib[ 'common' ],
  14491. THREE.UniformsLib[ 'aomap' ],
  14492. THREE.UniformsLib[ 'lightmap' ],
  14493. THREE.UniformsLib[ 'emissivemap' ],
  14494. THREE.UniformsLib[ 'bumpmap' ],
  14495. THREE.UniformsLib[ 'normalmap' ],
  14496. THREE.UniformsLib[ 'displacementmap' ],
  14497. THREE.UniformsLib[ 'fog' ],
  14498. THREE.UniformsLib[ 'lights' ],
  14499. {
  14500. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) },
  14501. "specular" : { type: "c", value: new THREE.Color( 0x111111 ) },
  14502. "shininess": { type: "1f", value: 30 }
  14503. }
  14504. ] ),
  14505. vertexShader: THREE.ShaderChunk[ 'meshphong_vert' ],
  14506. fragmentShader: THREE.ShaderChunk[ 'meshphong_frag' ]
  14507. },
  14508. 'standard': {
  14509. uniforms: THREE.UniformsUtils.merge( [
  14510. THREE.UniformsLib[ 'common' ],
  14511. THREE.UniformsLib[ 'aomap' ],
  14512. THREE.UniformsLib[ 'lightmap' ],
  14513. THREE.UniformsLib[ 'emissivemap' ],
  14514. THREE.UniformsLib[ 'bumpmap' ],
  14515. THREE.UniformsLib[ 'normalmap' ],
  14516. THREE.UniformsLib[ 'displacementmap' ],
  14517. THREE.UniformsLib[ 'roughnessmap' ],
  14518. THREE.UniformsLib[ 'metalnessmap' ],
  14519. THREE.UniformsLib[ 'fog' ],
  14520. THREE.UniformsLib[ 'lights' ],
  14521. {
  14522. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) },
  14523. "roughness": { type: "1f", value: 0.5 },
  14524. "metalness": { type: "1f", value: 0 },
  14525. "envMapIntensity" : { type: "1f", value: 1 } // temporary
  14526. }
  14527. ] ),
  14528. vertexShader: THREE.ShaderChunk[ 'meshphysical_vert' ],
  14529. fragmentShader: THREE.ShaderChunk[ 'meshphysical_frag' ]
  14530. },
  14531. 'points': {
  14532. uniforms: THREE.UniformsUtils.merge( [
  14533. THREE.UniformsLib[ 'points' ],
  14534. THREE.UniformsLib[ 'fog' ]
  14535. ] ),
  14536. vertexShader: THREE.ShaderChunk[ 'points_vert' ],
  14537. fragmentShader: THREE.ShaderChunk[ 'points_frag' ]
  14538. },
  14539. 'dashed': {
  14540. uniforms: THREE.UniformsUtils.merge( [
  14541. THREE.UniformsLib[ 'common' ],
  14542. THREE.UniformsLib[ 'fog' ],
  14543. {
  14544. "scale" : { type: "1f", value: 1 },
  14545. "dashSize" : { type: "1f", value: 1 },
  14546. "totalSize": { type: "1f", value: 2 }
  14547. }
  14548. ] ),
  14549. vertexShader: THREE.ShaderChunk[ 'linedashed_vert' ],
  14550. fragmentShader: THREE.ShaderChunk[ 'linedashed_frag' ]
  14551. },
  14552. 'depth': {
  14553. uniforms: THREE.UniformsUtils.merge( [
  14554. THREE.UniformsLib[ 'common' ],
  14555. THREE.UniformsLib[ 'displacementmap' ]
  14556. ] ),
  14557. vertexShader: THREE.ShaderChunk[ 'depth_vert' ],
  14558. fragmentShader: THREE.ShaderChunk[ 'depth_frag' ]
  14559. },
  14560. 'normal': {
  14561. uniforms: {
  14562. "opacity" : { type: "1f", value: 1.0 }
  14563. },
  14564. vertexShader: THREE.ShaderChunk[ 'normal_vert' ],
  14565. fragmentShader: THREE.ShaderChunk[ 'normal_frag' ]
  14566. },
  14567. /* -------------------------------------------------------------------------
  14568. // Cube map shader
  14569. ------------------------------------------------------------------------- */
  14570. 'cube': {
  14571. uniforms: {
  14572. "tCube": { type: "t", value: null },
  14573. "tFlip": { type: "1f", value: - 1 }
  14574. },
  14575. vertexShader: THREE.ShaderChunk[ 'cube_vert' ],
  14576. fragmentShader: THREE.ShaderChunk[ 'cube_frag' ]
  14577. },
  14578. /* -------------------------------------------------------------------------
  14579. // Cube map shader
  14580. ------------------------------------------------------------------------- */
  14581. 'equirect': {
  14582. uniforms: {
  14583. "tEquirect": { type: "t", value: null },
  14584. "tFlip": { type: "1f", value: - 1 }
  14585. },
  14586. vertexShader: THREE.ShaderChunk[ 'equirect_vert' ],
  14587. fragmentShader: THREE.ShaderChunk[ 'equirect_frag' ]
  14588. },
  14589. 'distanceRGBA': {
  14590. uniforms: {
  14591. "lightPos": { type: "v3", value: new THREE.Vector3() }
  14592. },
  14593. vertexShader: THREE.ShaderChunk[ 'distanceRGBA_vert' ],
  14594. fragmentShader: THREE.ShaderChunk[ 'distanceRGBA_frag' ]
  14595. }
  14596. };
  14597. THREE.ShaderLib[ 'physical' ] = {
  14598. uniforms: THREE.UniformsUtils.merge( [
  14599. THREE.ShaderLib[ 'standard' ].uniforms,
  14600. {
  14601. // future
  14602. }
  14603. ] ),
  14604. vertexShader: THREE.ShaderChunk[ 'meshphysical_vert' ],
  14605. fragmentShader: THREE.ShaderChunk[ 'meshphysical_frag' ]
  14606. };
  14607. // File:src/renderers/WebGLRenderer.js
  14608. /**
  14609. * @author supereggbert / http://www.paulbrunt.co.uk/
  14610. * @author mrdoob / http://mrdoob.com/
  14611. * @author alteredq / http://alteredqualia.com/
  14612. * @author szimek / https://github.com/szimek/
  14613. * @author tschw
  14614. */
  14615. THREE.WebGLRenderer = function ( parameters ) {
  14616. console.log( 'THREE.WebGLRenderer', THREE.REVISION );
  14617. parameters = parameters || {};
  14618. var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElement( 'canvas' ),
  14619. _context = parameters.context !== undefined ? parameters.context : null,
  14620. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  14621. _depth = parameters.depth !== undefined ? parameters.depth : true,
  14622. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  14623. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  14624. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  14625. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false;
  14626. var lights = [];
  14627. var opaqueObjects = [];
  14628. var opaqueObjectsLastIndex = - 1;
  14629. var transparentObjects = [];
  14630. var transparentObjectsLastIndex = - 1;
  14631. var morphInfluences = new Float32Array( 8 );
  14632. var sprites = [];
  14633. var lensFlares = [];
  14634. // public properties
  14635. this.domElement = _canvas;
  14636. this.context = null;
  14637. // clearing
  14638. this.autoClear = true;
  14639. this.autoClearColor = true;
  14640. this.autoClearDepth = true;
  14641. this.autoClearStencil = true;
  14642. // scene graph
  14643. this.sortObjects = true;
  14644. // user-defined clipping
  14645. this.clippingPlanes = [];
  14646. this.localClippingEnabled = false;
  14647. // physically based shading
  14648. this.gammaFactor = 2.0; // for backwards compatibility
  14649. this.gammaInput = false;
  14650. this.gammaOutput = false;
  14651. // physical lights
  14652. this.physicallyCorrectLights = false;
  14653. // tone mapping
  14654. this.toneMapping = THREE.LinearToneMapping;
  14655. this.toneMappingExposure = 1.0;
  14656. this.toneMappingWhitePoint = 1.0;
  14657. // morphs
  14658. this.maxMorphTargets = 8;
  14659. this.maxMorphNormals = 4;
  14660. // flags
  14661. this.autoScaleCubemaps = true;
  14662. // internal properties
  14663. var _this = this,
  14664. // internal state cache
  14665. _currentProgram = null,
  14666. _currentRenderTarget = null,
  14667. _currentFramebuffer = null,
  14668. _currentMaterialId = - 1,
  14669. _currentGeometryProgram = '',
  14670. _currentCamera = null,
  14671. _currentScissor = new THREE.Vector4(),
  14672. _currentScissorTest = null,
  14673. _currentViewport = new THREE.Vector4(),
  14674. //
  14675. _usedTextureUnits = 0,
  14676. //
  14677. _clearColor = new THREE.Color( 0x000000 ),
  14678. _clearAlpha = 0,
  14679. _width = _canvas.width,
  14680. _height = _canvas.height,
  14681. _pixelRatio = 1,
  14682. _scissor = new THREE.Vector4( 0, 0, _width, _height ),
  14683. _scissorTest = false,
  14684. _viewport = new THREE.Vector4( 0, 0, _width, _height ),
  14685. // frustum
  14686. _frustum = new THREE.Frustum(),
  14687. // clipping
  14688. _clipping = new THREE.WebGLClipping(),
  14689. _clippingEnabled = false,
  14690. _localClippingEnabled = false,
  14691. _sphere = new THREE.Sphere(),
  14692. // camera matrices cache
  14693. _projScreenMatrix = new THREE.Matrix4(),
  14694. _vector3 = new THREE.Vector3(),
  14695. // light arrays cache
  14696. _lights = {
  14697. hash: '',
  14698. ambient: [ 0, 0, 0 ],
  14699. directional: [],
  14700. directionalShadowMap: [],
  14701. directionalShadowMatrix: [],
  14702. spot: [],
  14703. spotShadowMap: [],
  14704. spotShadowMatrix: [],
  14705. point: [],
  14706. pointShadowMap: [],
  14707. pointShadowMatrix: [],
  14708. hemi: [],
  14709. shadows: []
  14710. },
  14711. // info
  14712. _infoMemory = {
  14713. geometries: 0,
  14714. textures: 0
  14715. },
  14716. _infoRender = {
  14717. calls: 0,
  14718. vertices: 0,
  14719. faces: 0,
  14720. points: 0
  14721. };
  14722. this.info = {
  14723. render: _infoRender,
  14724. memory: _infoMemory,
  14725. programs: null
  14726. };
  14727. // initialize
  14728. var _gl;
  14729. try {
  14730. var attributes = {
  14731. alpha: _alpha,
  14732. depth: _depth,
  14733. stencil: _stencil,
  14734. antialias: _antialias,
  14735. premultipliedAlpha: _premultipliedAlpha,
  14736. preserveDrawingBuffer: _preserveDrawingBuffer
  14737. };
  14738. _gl = _context || _canvas.getContext( 'webgl', attributes ) || _canvas.getContext( 'experimental-webgl', attributes );
  14739. if ( _gl === null ) {
  14740. if ( _canvas.getContext( 'webgl' ) !== null ) {
  14741. throw 'Error creating WebGL context with your selected attributes.';
  14742. } else {
  14743. throw 'Error creating WebGL context.';
  14744. }
  14745. }
  14746. // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  14747. if ( _gl.getShaderPrecisionFormat === undefined ) {
  14748. _gl.getShaderPrecisionFormat = function () {
  14749. return { 'rangeMin': 1, 'rangeMax': 1, 'precision': 1 };
  14750. };
  14751. }
  14752. _canvas.addEventListener( 'webglcontextlost', onContextLost, false );
  14753. } catch ( error ) {
  14754. console.error( 'THREE.WebGLRenderer: ' + error );
  14755. }
  14756. var _isWebGL2 = (typeof WebGL2RenderingContext !== 'undefined' && _gl instanceof WebGL2RenderingContext);
  14757. var extensions = new THREE.WebGLExtensions( _gl );
  14758. extensions.get( 'WEBGL_depth_texture' );
  14759. extensions.get( 'OES_texture_float' );
  14760. extensions.get( 'OES_texture_float_linear' );
  14761. extensions.get( 'OES_texture_half_float' );
  14762. extensions.get( 'OES_texture_half_float_linear' );
  14763. extensions.get( 'OES_standard_derivatives' );
  14764. extensions.get( 'ANGLE_instanced_arrays' );
  14765. if ( extensions.get( 'OES_element_index_uint' ) ) {
  14766. THREE.BufferGeometry.MaxIndex = 4294967296;
  14767. }
  14768. var capabilities = new THREE.WebGLCapabilities( _gl, extensions, parameters );
  14769. var state = new THREE.WebGLState( _gl, extensions, paramThreeToGL );
  14770. var properties = new THREE.WebGLProperties();
  14771. var objects = new THREE.WebGLObjects( _gl, properties, this.info );
  14772. var programCache = new THREE.WebGLPrograms( this, capabilities );
  14773. var lightCache = new THREE.WebGLLights();
  14774. this.info.programs = programCache.programs;
  14775. var bufferRenderer = new THREE.WebGLBufferRenderer( _gl, extensions, _infoRender );
  14776. var indexedBufferRenderer = new THREE.WebGLIndexedBufferRenderer( _gl, extensions, _infoRender );
  14777. //
  14778. function getTargetPixelRatio() {
  14779. return _currentRenderTarget === null ? _pixelRatio : 1;
  14780. }
  14781. function glClearColor( r, g, b, a ) {
  14782. if ( _premultipliedAlpha === true ) {
  14783. r *= a; g *= a; b *= a;
  14784. }
  14785. state.clearColor( r, g, b, a );
  14786. }
  14787. function setDefaultGLState() {
  14788. state.init();
  14789. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ) );
  14790. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ) );
  14791. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  14792. }
  14793. function resetGLState() {
  14794. _currentProgram = null;
  14795. _currentCamera = null;
  14796. _currentGeometryProgram = '';
  14797. _currentMaterialId = - 1;
  14798. state.reset();
  14799. }
  14800. setDefaultGLState();
  14801. this.context = _gl;
  14802. this.capabilities = capabilities;
  14803. this.extensions = extensions;
  14804. this.properties = properties;
  14805. this.state = state;
  14806. // shadow map
  14807. var shadowMap = new THREE.WebGLShadowMap( this, _lights, objects );
  14808. this.shadowMap = shadowMap;
  14809. // Plugins
  14810. var spritePlugin = new THREE.SpritePlugin( this, sprites );
  14811. var lensFlarePlugin = new THREE.LensFlarePlugin( this, lensFlares );
  14812. // API
  14813. this.getContext = function () {
  14814. return _gl;
  14815. };
  14816. this.getContextAttributes = function () {
  14817. return _gl.getContextAttributes();
  14818. };
  14819. this.forceContextLoss = function () {
  14820. extensions.get( 'WEBGL_lose_context' ).loseContext();
  14821. };
  14822. this.getMaxAnisotropy = ( function () {
  14823. var value;
  14824. return function getMaxAnisotropy() {
  14825. if ( value !== undefined ) return value;
  14826. var extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  14827. if ( extension !== null ) {
  14828. value = _gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );
  14829. } else {
  14830. value = 0;
  14831. }
  14832. return value;
  14833. };
  14834. } )();
  14835. this.getPrecision = function () {
  14836. return capabilities.precision;
  14837. };
  14838. this.getPixelRatio = function () {
  14839. return _pixelRatio;
  14840. };
  14841. this.setPixelRatio = function ( value ) {
  14842. if ( value === undefined ) return;
  14843. _pixelRatio = value;
  14844. this.setSize( _viewport.z, _viewport.w, false );
  14845. };
  14846. this.getSize = function () {
  14847. return {
  14848. width: _width,
  14849. height: _height
  14850. };
  14851. };
  14852. this.setSize = function ( width, height, updateStyle ) {
  14853. _width = width;
  14854. _height = height;
  14855. _canvas.width = width * _pixelRatio;
  14856. _canvas.height = height * _pixelRatio;
  14857. if ( updateStyle !== false ) {
  14858. _canvas.style.width = width + 'px';
  14859. _canvas.style.height = height + 'px';
  14860. }
  14861. this.setViewport( 0, 0, width, height );
  14862. };
  14863. this.setViewport = function ( x, y, width, height ) {
  14864. state.viewport( _viewport.set( x, y, width, height ) );
  14865. };
  14866. this.setScissor = function ( x, y, width, height ) {
  14867. state.scissor( _scissor.set( x, y, width, height ) );
  14868. };
  14869. this.setScissorTest = function ( boolean ) {
  14870. state.setScissorTest( _scissorTest = boolean );
  14871. };
  14872. // Clearing
  14873. this.getClearColor = function () {
  14874. return _clearColor;
  14875. };
  14876. this.setClearColor = function ( color, alpha ) {
  14877. _clearColor.set( color );
  14878. _clearAlpha = alpha !== undefined ? alpha : 1;
  14879. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  14880. };
  14881. this.getClearAlpha = function () {
  14882. return _clearAlpha;
  14883. };
  14884. this.setClearAlpha = function ( alpha ) {
  14885. _clearAlpha = alpha;
  14886. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  14887. };
  14888. this.clear = function ( color, depth, stencil ) {
  14889. var bits = 0;
  14890. if ( color === undefined || color ) bits |= _gl.COLOR_BUFFER_BIT;
  14891. if ( depth === undefined || depth ) bits |= _gl.DEPTH_BUFFER_BIT;
  14892. if ( stencil === undefined || stencil ) bits |= _gl.STENCIL_BUFFER_BIT;
  14893. _gl.clear( bits );
  14894. };
  14895. this.clearColor = function () {
  14896. this.clear( true, false, false );
  14897. };
  14898. this.clearDepth = function () {
  14899. this.clear( false, true, false );
  14900. };
  14901. this.clearStencil = function () {
  14902. this.clear( false, false, true );
  14903. };
  14904. this.clearTarget = function ( renderTarget, color, depth, stencil ) {
  14905. this.setRenderTarget( renderTarget );
  14906. this.clear( color, depth, stencil );
  14907. };
  14908. // Reset
  14909. this.resetGLState = resetGLState;
  14910. this.dispose = function() {
  14911. _canvas.removeEventListener( 'webglcontextlost', onContextLost, false );
  14912. };
  14913. // Events
  14914. function onContextLost( event ) {
  14915. event.preventDefault();
  14916. resetGLState();
  14917. setDefaultGLState();
  14918. properties.clear();
  14919. }
  14920. function onTextureDispose( event ) {
  14921. var texture = event.target;
  14922. texture.removeEventListener( 'dispose', onTextureDispose );
  14923. deallocateTexture( texture );
  14924. _infoMemory.textures --;
  14925. }
  14926. function onRenderTargetDispose( event ) {
  14927. var renderTarget = event.target;
  14928. renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
  14929. deallocateRenderTarget( renderTarget );
  14930. _infoMemory.textures --;
  14931. }
  14932. function onMaterialDispose( event ) {
  14933. var material = event.target;
  14934. material.removeEventListener( 'dispose', onMaterialDispose );
  14935. deallocateMaterial( material );
  14936. }
  14937. // Buffer deallocation
  14938. function deallocateTexture( texture ) {
  14939. var textureProperties = properties.get( texture );
  14940. if ( texture.image && textureProperties.__image__webglTextureCube ) {
  14941. // cube texture
  14942. _gl.deleteTexture( textureProperties.__image__webglTextureCube );
  14943. } else {
  14944. // 2D texture
  14945. if ( textureProperties.__webglInit === undefined ) return;
  14946. _gl.deleteTexture( textureProperties.__webglTexture );
  14947. }
  14948. // remove all webgl properties
  14949. properties.delete( texture );
  14950. }
  14951. function deallocateRenderTarget( renderTarget ) {
  14952. var renderTargetProperties = properties.get( renderTarget );
  14953. var textureProperties = properties.get( renderTarget.texture );
  14954. if ( ! renderTarget ) return;
  14955. if ( textureProperties.__webglTexture !== undefined ) {
  14956. _gl.deleteTexture( textureProperties.__webglTexture );
  14957. }
  14958. if ( renderTarget.depthTexture ) {
  14959. renderTarget.depthTexture.dispose();
  14960. }
  14961. if ( renderTarget instanceof THREE.WebGLRenderTargetCube ) {
  14962. for ( var i = 0; i < 6; i ++ ) {
  14963. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] );
  14964. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer[ i ] );
  14965. }
  14966. } else {
  14967. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer );
  14968. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer );
  14969. }
  14970. properties.delete( renderTarget.texture );
  14971. properties.delete( renderTarget );
  14972. }
  14973. function deallocateMaterial( material ) {
  14974. releaseMaterialProgramReference( material );
  14975. properties.delete( material );
  14976. }
  14977. function releaseMaterialProgramReference( material ) {
  14978. var programInfo = properties.get( material ).program;
  14979. material.program = undefined;
  14980. if ( programInfo !== undefined ) {
  14981. programCache.releaseProgram( programInfo );
  14982. }
  14983. }
  14984. // Buffer rendering
  14985. this.renderBufferImmediate = function ( object, program, material ) {
  14986. state.initAttributes();
  14987. var buffers = properties.get( object );
  14988. if ( object.hasPositions && ! buffers.position ) buffers.position = _gl.createBuffer();
  14989. if ( object.hasNormals && ! buffers.normal ) buffers.normal = _gl.createBuffer();
  14990. if ( object.hasUvs && ! buffers.uv ) buffers.uv = _gl.createBuffer();
  14991. if ( object.hasColors && ! buffers.color ) buffers.color = _gl.createBuffer();
  14992. var attributes = program.getAttributes();
  14993. if ( object.hasPositions ) {
  14994. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.position );
  14995. _gl.bufferData( _gl.ARRAY_BUFFER, object.positionArray, _gl.DYNAMIC_DRAW );
  14996. state.enableAttribute( attributes.position );
  14997. _gl.vertexAttribPointer( attributes.position, 3, _gl.FLOAT, false, 0, 0 );
  14998. }
  14999. if ( object.hasNormals ) {
  15000. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.normal );
  15001. if ( material.type !== 'MeshPhongMaterial' && material.type !== 'MeshStandardMaterial' && material.type !== 'MeshPhysicalMaterial' && material.shading === THREE.FlatShading ) {
  15002. for ( var i = 0, l = object.count * 3; i < l; i += 9 ) {
  15003. var array = object.normalArray;
  15004. var nx = ( array[ i + 0 ] + array[ i + 3 ] + array[ i + 6 ] ) / 3;
  15005. var ny = ( array[ i + 1 ] + array[ i + 4 ] + array[ i + 7 ] ) / 3;
  15006. var nz = ( array[ i + 2 ] + array[ i + 5 ] + array[ i + 8 ] ) / 3;
  15007. array[ i + 0 ] = nx;
  15008. array[ i + 1 ] = ny;
  15009. array[ i + 2 ] = nz;
  15010. array[ i + 3 ] = nx;
  15011. array[ i + 4 ] = ny;
  15012. array[ i + 5 ] = nz;
  15013. array[ i + 6 ] = nx;
  15014. array[ i + 7 ] = ny;
  15015. array[ i + 8 ] = nz;
  15016. }
  15017. }
  15018. _gl.bufferData( _gl.ARRAY_BUFFER, object.normalArray, _gl.DYNAMIC_DRAW );
  15019. state.enableAttribute( attributes.normal );
  15020. _gl.vertexAttribPointer( attributes.normal, 3, _gl.FLOAT, false, 0, 0 );
  15021. }
  15022. if ( object.hasUvs && material.map ) {
  15023. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.uv );
  15024. _gl.bufferData( _gl.ARRAY_BUFFER, object.uvArray, _gl.DYNAMIC_DRAW );
  15025. state.enableAttribute( attributes.uv );
  15026. _gl.vertexAttribPointer( attributes.uv, 2, _gl.FLOAT, false, 0, 0 );
  15027. }
  15028. if ( object.hasColors && material.vertexColors !== THREE.NoColors ) {
  15029. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.color );
  15030. _gl.bufferData( _gl.ARRAY_BUFFER, object.colorArray, _gl.DYNAMIC_DRAW );
  15031. state.enableAttribute( attributes.color );
  15032. _gl.vertexAttribPointer( attributes.color, 3, _gl.FLOAT, false, 0, 0 );
  15033. }
  15034. state.disableUnusedAttributes();
  15035. _gl.drawArrays( _gl.TRIANGLES, 0, object.count );
  15036. object.count = 0;
  15037. };
  15038. this.renderBufferDirect = function ( camera, fog, geometry, material, object, group ) {
  15039. setMaterial( material );
  15040. var program = setProgram( camera, fog, material, object );
  15041. var updateBuffers = false;
  15042. var geometryProgram = geometry.id + '_' + program.id + '_' + material.wireframe;
  15043. if ( geometryProgram !== _currentGeometryProgram ) {
  15044. _currentGeometryProgram = geometryProgram;
  15045. updateBuffers = true;
  15046. }
  15047. // morph targets
  15048. var morphTargetInfluences = object.morphTargetInfluences;
  15049. if ( morphTargetInfluences !== undefined ) {
  15050. var activeInfluences = [];
  15051. for ( var i = 0, l = morphTargetInfluences.length; i < l; i ++ ) {
  15052. var influence = morphTargetInfluences[ i ];
  15053. activeInfluences.push( [ influence, i ] );
  15054. }
  15055. activeInfluences.sort( absNumericalSort );
  15056. if ( activeInfluences.length > 8 ) {
  15057. activeInfluences.length = 8;
  15058. }
  15059. var morphAttributes = geometry.morphAttributes;
  15060. for ( var i = 0, l = activeInfluences.length; i < l; i ++ ) {
  15061. var influence = activeInfluences[ i ];
  15062. morphInfluences[ i ] = influence[ 0 ];
  15063. if ( influence[ 0 ] !== 0 ) {
  15064. var index = influence[ 1 ];
  15065. if ( material.morphTargets === true && morphAttributes.position ) geometry.addAttribute( 'morphTarget' + i, morphAttributes.position[ index ] );
  15066. if ( material.morphNormals === true && morphAttributes.normal ) geometry.addAttribute( 'morphNormal' + i, morphAttributes.normal[ index ] );
  15067. } else {
  15068. if ( material.morphTargets === true ) geometry.removeAttribute( 'morphTarget' + i );
  15069. if ( material.morphNormals === true ) geometry.removeAttribute( 'morphNormal' + i );
  15070. }
  15071. }
  15072. program.getUniforms().setValue(
  15073. _gl, 'morphTargetInfluences', morphInfluences );
  15074. updateBuffers = true;
  15075. }
  15076. //
  15077. var index = geometry.index;
  15078. var position = geometry.attributes.position;
  15079. if ( material.wireframe === true ) {
  15080. index = objects.getWireframeAttribute( geometry );
  15081. }
  15082. var renderer;
  15083. if ( index !== null ) {
  15084. renderer = indexedBufferRenderer;
  15085. renderer.setIndex( index );
  15086. } else {
  15087. renderer = bufferRenderer;
  15088. }
  15089. if ( updateBuffers ) {
  15090. setupVertexAttributes( material, program, geometry );
  15091. if ( index !== null ) {
  15092. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, objects.getAttributeBuffer( index ) );
  15093. }
  15094. }
  15095. //
  15096. var dataStart = 0;
  15097. var dataCount = Infinity;
  15098. if ( index !== null ) {
  15099. dataCount = index.count;
  15100. } else if ( position !== undefined ) {
  15101. dataCount = position.count;
  15102. }
  15103. var rangeStart = geometry.drawRange.start;
  15104. var rangeCount = geometry.drawRange.count;
  15105. var groupStart = group !== null ? group.start : 0;
  15106. var groupCount = group !== null ? group.count : Infinity;
  15107. var drawStart = Math.max( dataStart, rangeStart, groupStart );
  15108. var drawEnd = Math.min( dataStart + dataCount, rangeStart + rangeCount, groupStart + groupCount ) - 1;
  15109. var drawCount = Math.max( 0, drawEnd - drawStart + 1 );
  15110. //
  15111. if ( object instanceof THREE.Mesh ) {
  15112. if ( material.wireframe === true ) {
  15113. state.setLineWidth( material.wireframeLinewidth * getTargetPixelRatio() );
  15114. renderer.setMode( _gl.LINES );
  15115. } else {
  15116. switch ( object.drawMode ) {
  15117. case THREE.TrianglesDrawMode:
  15118. renderer.setMode( _gl.TRIANGLES );
  15119. break;
  15120. case THREE.TriangleStripDrawMode:
  15121. renderer.setMode( _gl.TRIANGLE_STRIP );
  15122. break;
  15123. case THREE.TriangleFanDrawMode:
  15124. renderer.setMode( _gl.TRIANGLE_FAN );
  15125. break;
  15126. }
  15127. }
  15128. } else if ( object instanceof THREE.Line ) {
  15129. var lineWidth = material.linewidth;
  15130. if ( lineWidth === undefined ) lineWidth = 1; // Not using Line*Material
  15131. state.setLineWidth( lineWidth * getTargetPixelRatio() );
  15132. if ( object instanceof THREE.LineSegments ) {
  15133. renderer.setMode( _gl.LINES );
  15134. } else {
  15135. renderer.setMode( _gl.LINE_STRIP );
  15136. }
  15137. } else if ( object instanceof THREE.Points ) {
  15138. renderer.setMode( _gl.POINTS );
  15139. }
  15140. if ( geometry instanceof THREE.InstancedBufferGeometry ) {
  15141. if ( geometry.maxInstancedCount > 0 ) {
  15142. renderer.renderInstances( geometry, drawStart, drawCount );
  15143. }
  15144. } else {
  15145. renderer.render( drawStart, drawCount );
  15146. }
  15147. };
  15148. function setupVertexAttributes( material, program, geometry, startIndex ) {
  15149. var extension;
  15150. if ( geometry instanceof THREE.InstancedBufferGeometry ) {
  15151. extension = extensions.get( 'ANGLE_instanced_arrays' );
  15152. if ( extension === null ) {
  15153. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  15154. return;
  15155. }
  15156. }
  15157. if ( startIndex === undefined ) startIndex = 0;
  15158. state.initAttributes();
  15159. var geometryAttributes = geometry.attributes;
  15160. var programAttributes = program.getAttributes();
  15161. var materialDefaultAttributeValues = material.defaultAttributeValues;
  15162. for ( var name in programAttributes ) {
  15163. var programAttribute = programAttributes[ name ];
  15164. if ( programAttribute >= 0 ) {
  15165. var geometryAttribute = geometryAttributes[ name ];
  15166. if ( geometryAttribute !== undefined ) {
  15167. var type = _gl.FLOAT;
  15168. var array = geometryAttribute.array;
  15169. var normalized = geometryAttribute.normalized;
  15170. if ( array instanceof Float32Array ) {
  15171. type = _gl.FLOAT;
  15172. } else if ( array instanceof Float64Array ) {
  15173. console.warn("Unsupported data buffer format: Float64Array");
  15174. } else if ( array instanceof Uint16Array ) {
  15175. type = _gl.UNSIGNED_SHORT;
  15176. } else if ( array instanceof Int16Array ) {
  15177. type = _gl.SHORT;
  15178. } else if ( array instanceof Uint32Array ) {
  15179. type = _gl.UNSIGNED_INT;
  15180. } else if ( array instanceof Int32Array ) {
  15181. type = _gl.INT;
  15182. } else if ( array instanceof Int8Array ) {
  15183. type = _gl.BYTE;
  15184. } else if ( array instanceof Uint8Array ) {
  15185. type = _gl.UNSIGNED_BYTE;
  15186. }
  15187. var size = geometryAttribute.itemSize;
  15188. var buffer = objects.getAttributeBuffer( geometryAttribute );
  15189. if ( geometryAttribute instanceof THREE.InterleavedBufferAttribute ) {
  15190. var data = geometryAttribute.data;
  15191. var stride = data.stride;
  15192. var offset = geometryAttribute.offset;
  15193. if ( data instanceof THREE.InstancedInterleavedBuffer ) {
  15194. state.enableAttributeAndDivisor( programAttribute, data.meshPerAttribute, extension );
  15195. if ( geometry.maxInstancedCount === undefined ) {
  15196. geometry.maxInstancedCount = data.meshPerAttribute * data.count;
  15197. }
  15198. } else {
  15199. state.enableAttribute( programAttribute );
  15200. }
  15201. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  15202. _gl.vertexAttribPointer( programAttribute, size, type, normalized, stride * data.array.BYTES_PER_ELEMENT, ( startIndex * stride + offset ) * data.array.BYTES_PER_ELEMENT );
  15203. } else {
  15204. if ( geometryAttribute instanceof THREE.InstancedBufferAttribute ) {
  15205. state.enableAttributeAndDivisor( programAttribute, geometryAttribute.meshPerAttribute, extension );
  15206. if ( geometry.maxInstancedCount === undefined ) {
  15207. geometry.maxInstancedCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  15208. }
  15209. } else {
  15210. state.enableAttribute( programAttribute );
  15211. }
  15212. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  15213. _gl.vertexAttribPointer( programAttribute, size, type, normalized, 0, startIndex * size * geometryAttribute.array.BYTES_PER_ELEMENT );
  15214. }
  15215. } else if ( materialDefaultAttributeValues !== undefined ) {
  15216. var value = materialDefaultAttributeValues[ name ];
  15217. if ( value !== undefined ) {
  15218. switch ( value.length ) {
  15219. case 2:
  15220. _gl.vertexAttrib2fv( programAttribute, value );
  15221. break;
  15222. case 3:
  15223. _gl.vertexAttrib3fv( programAttribute, value );
  15224. break;
  15225. case 4:
  15226. _gl.vertexAttrib4fv( programAttribute, value );
  15227. break;
  15228. default:
  15229. _gl.vertexAttrib1fv( programAttribute, value );
  15230. }
  15231. }
  15232. }
  15233. }
  15234. }
  15235. state.disableUnusedAttributes();
  15236. }
  15237. // Sorting
  15238. function absNumericalSort( a, b ) {
  15239. return Math.abs( b[ 0 ] ) - Math.abs( a[ 0 ] );
  15240. }
  15241. function painterSortStable ( a, b ) {
  15242. if ( a.object.renderOrder !== b.object.renderOrder ) {
  15243. return a.object.renderOrder - b.object.renderOrder;
  15244. } else if ( a.material.id !== b.material.id ) {
  15245. return a.material.id - b.material.id;
  15246. } else if ( a.z !== b.z ) {
  15247. return a.z - b.z;
  15248. } else {
  15249. return a.id - b.id;
  15250. }
  15251. }
  15252. function reversePainterSortStable ( a, b ) {
  15253. if ( a.object.renderOrder !== b.object.renderOrder ) {
  15254. return a.object.renderOrder - b.object.renderOrder;
  15255. } if ( a.z !== b.z ) {
  15256. return b.z - a.z;
  15257. } else {
  15258. return a.id - b.id;
  15259. }
  15260. }
  15261. // Rendering
  15262. this.render = function ( scene, camera, renderTarget, forceClear ) {
  15263. if ( camera instanceof THREE.Camera === false ) {
  15264. console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
  15265. return;
  15266. }
  15267. var fog = scene.fog;
  15268. // reset caching for this frame
  15269. _currentGeometryProgram = '';
  15270. _currentMaterialId = - 1;
  15271. _currentCamera = null;
  15272. // update scene graph
  15273. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  15274. // update camera matrices and frustum
  15275. if ( camera.parent === null ) camera.updateMatrixWorld();
  15276. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  15277. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  15278. _frustum.setFromMatrix( _projScreenMatrix );
  15279. lights.length = 0;
  15280. opaqueObjectsLastIndex = - 1;
  15281. transparentObjectsLastIndex = - 1;
  15282. sprites.length = 0;
  15283. lensFlares.length = 0;
  15284. _localClippingEnabled = this.localClippingEnabled;
  15285. _clippingEnabled = _clipping.init(
  15286. this.clippingPlanes, _localClippingEnabled, camera );
  15287. projectObject( scene, camera );
  15288. opaqueObjects.length = opaqueObjectsLastIndex + 1;
  15289. transparentObjects.length = transparentObjectsLastIndex + 1;
  15290. if ( _this.sortObjects === true ) {
  15291. opaqueObjects.sort( painterSortStable );
  15292. transparentObjects.sort( reversePainterSortStable );
  15293. }
  15294. //
  15295. if ( _clippingEnabled ) _clipping.beginShadows();
  15296. setupShadows( lights );
  15297. shadowMap.render( scene, camera );
  15298. setupLights( lights, camera );
  15299. if ( _clippingEnabled ) _clipping.endShadows();
  15300. //
  15301. _infoRender.calls = 0;
  15302. _infoRender.vertices = 0;
  15303. _infoRender.faces = 0;
  15304. _infoRender.points = 0;
  15305. if ( renderTarget === undefined ) {
  15306. renderTarget = null;
  15307. }
  15308. this.setRenderTarget( renderTarget );
  15309. if ( this.autoClear || forceClear ) {
  15310. this.clear( this.autoClearColor, this.autoClearDepth, this.autoClearStencil );
  15311. }
  15312. //
  15313. if ( scene.overrideMaterial ) {
  15314. var overrideMaterial = scene.overrideMaterial;
  15315. renderObjects( opaqueObjects, camera, fog, overrideMaterial );
  15316. renderObjects( transparentObjects, camera, fog, overrideMaterial );
  15317. } else {
  15318. // opaque pass (front-to-back order)
  15319. state.setBlending( THREE.NoBlending );
  15320. renderObjects( opaqueObjects, camera, fog );
  15321. // transparent pass (back-to-front order)
  15322. renderObjects( transparentObjects, camera, fog );
  15323. }
  15324. // custom render plugins (post pass)
  15325. spritePlugin.render( scene, camera );
  15326. lensFlarePlugin.render( scene, camera, _currentViewport );
  15327. // Generate mipmap if we're using any kind of mipmap filtering
  15328. if ( renderTarget ) {
  15329. var texture = renderTarget.texture;
  15330. if ( texture.generateMipmaps && isPowerOfTwo( renderTarget ) &&
  15331. texture.minFilter !== THREE.NearestFilter &&
  15332. texture.minFilter !== THREE.LinearFilter ) {
  15333. updateRenderTargetMipmap( renderTarget );
  15334. }
  15335. }
  15336. // Ensure depth buffer writing is enabled so it can be cleared on next render
  15337. state.setDepthTest( true );
  15338. state.setDepthWrite( true );
  15339. state.setColorWrite( true );
  15340. // _gl.finish();
  15341. };
  15342. function pushRenderItem( object, geometry, material, z, group ) {
  15343. var array, index;
  15344. // allocate the next position in the appropriate array
  15345. if ( material.transparent ) {
  15346. array = transparentObjects;
  15347. index = ++ transparentObjectsLastIndex;
  15348. } else {
  15349. array = opaqueObjects;
  15350. index = ++ opaqueObjectsLastIndex;
  15351. }
  15352. // recycle existing render item or grow the array
  15353. var renderItem = array[ index ];
  15354. if ( renderItem !== undefined ) {
  15355. renderItem.id = object.id;
  15356. renderItem.object = object;
  15357. renderItem.geometry = geometry;
  15358. renderItem.material = material;
  15359. renderItem.z = _vector3.z;
  15360. renderItem.group = group;
  15361. } else {
  15362. renderItem = {
  15363. id: object.id,
  15364. object: object,
  15365. geometry: geometry,
  15366. material: material,
  15367. z: _vector3.z,
  15368. group: group
  15369. };
  15370. // assert( index === array.length );
  15371. array.push( renderItem );
  15372. }
  15373. }
  15374. // TODO Duplicated code (Frustum)
  15375. function isObjectViewable( object ) {
  15376. var geometry = object.geometry;
  15377. if ( geometry.boundingSphere === null )
  15378. geometry.computeBoundingSphere();
  15379. _sphere.copy( geometry.boundingSphere ).
  15380. applyMatrix4( object.matrixWorld );
  15381. return isSphereViewable( _sphere );
  15382. }
  15383. function isSpriteViewable( sprite ) {
  15384. _sphere.center.set( 0, 0, 0 );
  15385. _sphere.radius = 0.7071067811865476;
  15386. _sphere.applyMatrix4( sprite.matrixWorld );
  15387. return isSphereViewable( _sphere );
  15388. }
  15389. function isSphereViewable( sphere ) {
  15390. if ( ! _frustum.intersectsSphere( sphere ) ) return false;
  15391. var numPlanes = _clipping.numPlanes;
  15392. if ( numPlanes === 0 ) return true;
  15393. var planes = _this.clippingPlanes,
  15394. center = sphere.center,
  15395. negRad = - sphere.radius,
  15396. i = 0;
  15397. do {
  15398. // out when deeper than radius in the negative halfspace
  15399. if ( planes[ i ].distanceToPoint( center ) < negRad ) return false;
  15400. } while ( ++ i !== numPlanes );
  15401. return true;
  15402. }
  15403. function projectObject( object, camera ) {
  15404. if ( object.visible === false ) return;
  15405. if ( object.layers.test( camera.layers ) ) {
  15406. if ( object instanceof THREE.Light ) {
  15407. lights.push( object );
  15408. } else if ( object instanceof THREE.Sprite ) {
  15409. if ( object.frustumCulled === false || isSpriteViewable( object ) === true ) {
  15410. sprites.push( object );
  15411. }
  15412. } else if ( object instanceof THREE.LensFlare ) {
  15413. lensFlares.push( object );
  15414. } else if ( object instanceof THREE.ImmediateRenderObject ) {
  15415. if ( _this.sortObjects === true ) {
  15416. _vector3.setFromMatrixPosition( object.matrixWorld );
  15417. _vector3.applyProjection( _projScreenMatrix );
  15418. }
  15419. pushRenderItem( object, null, object.material, _vector3.z, null );
  15420. } else if ( object instanceof THREE.Mesh || object instanceof THREE.Line || object instanceof THREE.Points ) {
  15421. if ( object instanceof THREE.SkinnedMesh ) {
  15422. object.skeleton.update();
  15423. }
  15424. if ( object.frustumCulled === false || isObjectViewable( object ) === true ) {
  15425. var material = object.material;
  15426. if ( material.visible === true ) {
  15427. if ( _this.sortObjects === true ) {
  15428. _vector3.setFromMatrixPosition( object.matrixWorld );
  15429. _vector3.applyProjection( _projScreenMatrix );
  15430. }
  15431. var geometry = objects.update( object );
  15432. if ( material instanceof THREE.MultiMaterial ) {
  15433. var groups = geometry.groups;
  15434. var materials = material.materials;
  15435. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  15436. var group = groups[ i ];
  15437. var groupMaterial = materials[ group.materialIndex ];
  15438. if ( groupMaterial.visible === true ) {
  15439. pushRenderItem( object, geometry, groupMaterial, _vector3.z, group );
  15440. }
  15441. }
  15442. } else {
  15443. pushRenderItem( object, geometry, material, _vector3.z, null );
  15444. }
  15445. }
  15446. }
  15447. }
  15448. }
  15449. var children = object.children;
  15450. for ( var i = 0, l = children.length; i < l; i ++ ) {
  15451. projectObject( children[ i ], camera );
  15452. }
  15453. }
  15454. function renderObjects( renderList, camera, fog, overrideMaterial ) {
  15455. for ( var i = 0, l = renderList.length; i < l; i ++ ) {
  15456. var renderItem = renderList[ i ];
  15457. var object = renderItem.object;
  15458. var geometry = renderItem.geometry;
  15459. var material = overrideMaterial === undefined ? renderItem.material : overrideMaterial;
  15460. var group = renderItem.group;
  15461. object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  15462. object.normalMatrix.getNormalMatrix( object.modelViewMatrix );
  15463. if ( object instanceof THREE.ImmediateRenderObject ) {
  15464. setMaterial( material );
  15465. var program = setProgram( camera, fog, material, object );
  15466. _currentGeometryProgram = '';
  15467. object.render( function ( object ) {
  15468. _this.renderBufferImmediate( object, program, material );
  15469. } );
  15470. } else {
  15471. _this.renderBufferDirect( camera, fog, geometry, material, object, group );
  15472. }
  15473. }
  15474. }
  15475. function initMaterial( material, fog, object ) {
  15476. var materialProperties = properties.get( material );
  15477. var parameters = programCache.getParameters(
  15478. material, _lights, fog, _clipping.numPlanes, object );
  15479. var code = programCache.getProgramCode( material, parameters );
  15480. var program = materialProperties.program;
  15481. var programChange = true;
  15482. if ( program === undefined ) {
  15483. // new material
  15484. material.addEventListener( 'dispose', onMaterialDispose );
  15485. } else if ( program.code !== code ) {
  15486. // changed glsl or parameters
  15487. releaseMaterialProgramReference( material );
  15488. } else if ( parameters.shaderID !== undefined ) {
  15489. // same glsl and uniform list
  15490. return;
  15491. } else {
  15492. // only rebuild uniform list
  15493. programChange = false;
  15494. }
  15495. if ( programChange ) {
  15496. if ( parameters.shaderID ) {
  15497. var shader = THREE.ShaderLib[ parameters.shaderID ];
  15498. materialProperties.__webglShader = {
  15499. name: material.type,
  15500. uniforms: THREE.UniformsUtils.clone( shader.uniforms ),
  15501. vertexShader: shader.vertexShader,
  15502. fragmentShader: shader.fragmentShader
  15503. };
  15504. } else {
  15505. materialProperties.__webglShader = {
  15506. name: material.type,
  15507. uniforms: material.uniforms,
  15508. vertexShader: material.vertexShader,
  15509. fragmentShader: material.fragmentShader
  15510. };
  15511. }
  15512. material.__webglShader = materialProperties.__webglShader;
  15513. program = programCache.acquireProgram( material, parameters, code );
  15514. materialProperties.program = program;
  15515. material.program = program;
  15516. }
  15517. var attributes = program.getAttributes();
  15518. if ( material.morphTargets ) {
  15519. material.numSupportedMorphTargets = 0;
  15520. for ( var i = 0; i < _this.maxMorphTargets; i ++ ) {
  15521. if ( attributes[ 'morphTarget' + i ] >= 0 ) {
  15522. material.numSupportedMorphTargets ++;
  15523. }
  15524. }
  15525. }
  15526. if ( material.morphNormals ) {
  15527. material.numSupportedMorphNormals = 0;
  15528. for ( var i = 0; i < _this.maxMorphNormals; i ++ ) {
  15529. if ( attributes[ 'morphNormal' + i ] >= 0 ) {
  15530. material.numSupportedMorphNormals ++;
  15531. }
  15532. }
  15533. }
  15534. var uniforms = materialProperties.__webglShader.uniforms;
  15535. if ( ! ( material instanceof THREE.ShaderMaterial ) &&
  15536. ! ( material instanceof THREE.RawShaderMaterial ) ||
  15537. material.clipping === true ) {
  15538. materialProperties.numClippingPlanes = _clipping.numPlanes;
  15539. uniforms.clippingPlanes = _clipping.uniform;
  15540. }
  15541. if ( material.lights ) {
  15542. // store the light setup it was created for
  15543. materialProperties.lightsHash = _lights.hash;
  15544. // wire up the material to this renderer's lighting state
  15545. uniforms.ambientLightColor.value = _lights.ambient;
  15546. uniforms.directionalLights.value = _lights.directional;
  15547. uniforms.spotLights.value = _lights.spot;
  15548. uniforms.pointLights.value = _lights.point;
  15549. uniforms.hemisphereLights.value = _lights.hemi;
  15550. uniforms.directionalShadowMap.value = _lights.directionalShadowMap;
  15551. uniforms.directionalShadowMatrix.value = _lights.directionalShadowMatrix;
  15552. uniforms.spotShadowMap.value = _lights.spotShadowMap;
  15553. uniforms.spotShadowMatrix.value = _lights.spotShadowMatrix;
  15554. uniforms.pointShadowMap.value = _lights.pointShadowMap;
  15555. uniforms.pointShadowMatrix.value = _lights.pointShadowMatrix;
  15556. }
  15557. var progUniforms = materialProperties.program.getUniforms(),
  15558. uniformsList =
  15559. THREE.WebGLUniforms.seqWithValue( progUniforms.seq, uniforms );
  15560. materialProperties.uniformsList = uniformsList;
  15561. materialProperties.dynamicUniforms =
  15562. THREE.WebGLUniforms.splitDynamic( uniformsList, uniforms );
  15563. }
  15564. function setMaterial( material ) {
  15565. if ( material.side !== THREE.DoubleSide )
  15566. state.enable( _gl.CULL_FACE );
  15567. else
  15568. state.disable( _gl.CULL_FACE );
  15569. state.setFlipSided( material.side === THREE.BackSide );
  15570. if ( material.transparent === true ) {
  15571. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.premultipliedAlpha );
  15572. } else {
  15573. state.setBlending( THREE.NoBlending );
  15574. }
  15575. state.setDepthFunc( material.depthFunc );
  15576. state.setDepthTest( material.depthTest );
  15577. state.setDepthWrite( material.depthWrite );
  15578. state.setColorWrite( material.colorWrite );
  15579. state.setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  15580. }
  15581. function setProgram( camera, fog, material, object ) {
  15582. _usedTextureUnits = 0;
  15583. var materialProperties = properties.get( material );
  15584. if ( _clippingEnabled ) {
  15585. if ( _localClippingEnabled || camera !== _currentCamera ) {
  15586. var useCache =
  15587. camera === _currentCamera &&
  15588. material.id === _currentMaterialId;
  15589. // we might want to call this function with some ClippingGroup
  15590. // object instead of the material, once it becomes feasible
  15591. // (#8465, #8379)
  15592. _clipping.setState(
  15593. material.clippingPlanes, material.clipShadows,
  15594. camera, materialProperties, useCache );
  15595. }
  15596. if ( materialProperties.numClippingPlanes !== undefined &&
  15597. materialProperties.numClippingPlanes !== _clipping.numPlanes ) {
  15598. material.needsUpdate = true;
  15599. }
  15600. }
  15601. if ( materialProperties.program === undefined ) {
  15602. material.needsUpdate = true;
  15603. }
  15604. if ( materialProperties.lightsHash !== undefined &&
  15605. materialProperties.lightsHash !== _lights.hash ) {
  15606. material.needsUpdate = true;
  15607. }
  15608. if ( material.needsUpdate ) {
  15609. initMaterial( material, fog, object );
  15610. material.needsUpdate = false;
  15611. }
  15612. var refreshProgram = false;
  15613. var refreshMaterial = false;
  15614. var refreshLights = false;
  15615. var program = materialProperties.program,
  15616. p_uniforms = program.getUniforms(),
  15617. m_uniforms = materialProperties.__webglShader.uniforms;
  15618. if ( program.id !== _currentProgram ) {
  15619. _gl.useProgram( program.program );
  15620. _currentProgram = program.id;
  15621. refreshProgram = true;
  15622. refreshMaterial = true;
  15623. refreshLights = true;
  15624. }
  15625. if ( material.id !== _currentMaterialId ) {
  15626. _currentMaterialId = material.id;
  15627. refreshMaterial = true;
  15628. }
  15629. if ( refreshProgram || camera !== _currentCamera ) {
  15630. p_uniforms.set( _gl, camera, 'projectionMatrix' );
  15631. if ( capabilities.logarithmicDepthBuffer ) {
  15632. p_uniforms.setValue( _gl, 'logDepthBufFC',
  15633. 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
  15634. }
  15635. if ( camera !== _currentCamera ) {
  15636. _currentCamera = camera;
  15637. // lighting uniforms depend on the camera so enforce an update
  15638. // now, in case this material supports lights - or later, when
  15639. // the next material that does gets activated:
  15640. refreshMaterial = true; // set to true on material change
  15641. refreshLights = true; // remains set until update done
  15642. }
  15643. // load material specific uniforms
  15644. // (shader material also gets them for the sake of genericity)
  15645. if ( material instanceof THREE.ShaderMaterial ||
  15646. material instanceof THREE.MeshPhongMaterial ||
  15647. material instanceof THREE.MeshStandardMaterial ||
  15648. material.envMap ) {
  15649. var uCamPos = p_uniforms.map.cameraPosition;
  15650. if ( uCamPos !== undefined ) {
  15651. uCamPos.setValue( _gl,
  15652. _vector3.setFromMatrixPosition( camera.matrixWorld ) );
  15653. }
  15654. }
  15655. if ( material instanceof THREE.MeshPhongMaterial ||
  15656. material instanceof THREE.MeshLambertMaterial ||
  15657. material instanceof THREE.MeshBasicMaterial ||
  15658. material instanceof THREE.MeshStandardMaterial ||
  15659. material instanceof THREE.ShaderMaterial ||
  15660. material.skinning ) {
  15661. p_uniforms.setValue( _gl, 'viewMatrix', camera.matrixWorldInverse );
  15662. }
  15663. p_uniforms.set( _gl, _this, 'toneMappingExposure' );
  15664. p_uniforms.set( _gl, _this, 'toneMappingWhitePoint' );
  15665. }
  15666. // skinning uniforms must be set even if material didn't change
  15667. // auto-setting of texture unit for bone texture must go before other textures
  15668. // not sure why, but otherwise weird things happen
  15669. if ( material.skinning ) {
  15670. p_uniforms.setOptional( _gl, object, 'bindMatrix' );
  15671. p_uniforms.setOptional( _gl, object, 'bindMatrixInverse' );
  15672. var skeleton = object.skeleton;
  15673. if ( skeleton ) {
  15674. if ( capabilities.floatVertexTextures && skeleton.useVertexTexture ) {
  15675. p_uniforms.set( _gl, skeleton, 'boneTexture' );
  15676. p_uniforms.set( _gl, skeleton, 'boneTextureWidth' );
  15677. p_uniforms.set( _gl, skeleton, 'boneTextureHeight' );
  15678. } else {
  15679. p_uniforms.setOptional( _gl, skeleton, 'boneMatrices' );
  15680. }
  15681. }
  15682. }
  15683. if ( refreshMaterial ) {
  15684. if ( material.lights ) {
  15685. // the current material requires lighting info
  15686. // note: all lighting uniforms are always set correctly
  15687. // they simply reference the renderer's state for their
  15688. // values
  15689. //
  15690. // use the current material's .needsUpdate flags to set
  15691. // the GL state when required
  15692. markUniformsLightsNeedsUpdate( m_uniforms, refreshLights );
  15693. }
  15694. // refresh uniforms common to several materials
  15695. if ( fog && material.fog ) {
  15696. refreshUniformsFog( m_uniforms, fog );
  15697. }
  15698. if ( material instanceof THREE.MeshBasicMaterial ||
  15699. material instanceof THREE.MeshLambertMaterial ||
  15700. material instanceof THREE.MeshPhongMaterial ||
  15701. material instanceof THREE.MeshStandardMaterial ||
  15702. material instanceof THREE.MeshDepthMaterial ) {
  15703. refreshUniformsCommon( m_uniforms, material );
  15704. }
  15705. // refresh single material specific uniforms
  15706. if ( material instanceof THREE.LineBasicMaterial ) {
  15707. refreshUniformsLine( m_uniforms, material );
  15708. } else if ( material instanceof THREE.LineDashedMaterial ) {
  15709. refreshUniformsLine( m_uniforms, material );
  15710. refreshUniformsDash( m_uniforms, material );
  15711. } else if ( material instanceof THREE.PointsMaterial ) {
  15712. refreshUniformsPoints( m_uniforms, material );
  15713. } else if ( material instanceof THREE.MeshLambertMaterial ) {
  15714. refreshUniformsLambert( m_uniforms, material );
  15715. } else if ( material instanceof THREE.MeshPhongMaterial ) {
  15716. refreshUniformsPhong( m_uniforms, material );
  15717. } else if ( material instanceof THREE.MeshPhysicalMaterial ) {
  15718. refreshUniformsPhysical( m_uniforms, material );
  15719. } else if ( material instanceof THREE.MeshStandardMaterial ) {
  15720. refreshUniformsStandard( m_uniforms, material );
  15721. } else if ( material instanceof THREE.MeshDepthMaterial ) {
  15722. if ( material.displacementMap ) {
  15723. m_uniforms.displacementMap.value = material.displacementMap;
  15724. m_uniforms.displacementScale.value = material.displacementScale;
  15725. m_uniforms.displacementBias.value = material.displacementBias;
  15726. }
  15727. } else if ( material instanceof THREE.MeshNormalMaterial ) {
  15728. m_uniforms.opacity.value = material.opacity;
  15729. }
  15730. THREE.WebGLUniforms.upload(
  15731. _gl, materialProperties.uniformsList, m_uniforms, _this );
  15732. }
  15733. // common matrices
  15734. p_uniforms.set( _gl, object, 'modelViewMatrix' );
  15735. p_uniforms.set( _gl, object, 'normalMatrix' );
  15736. p_uniforms.setValue( _gl, 'modelMatrix', object.matrixWorld );
  15737. // dynamic uniforms
  15738. var dynUniforms = materialProperties.dynamicUniforms;
  15739. if ( dynUniforms !== null ) {
  15740. THREE.WebGLUniforms.evalDynamic(
  15741. dynUniforms, m_uniforms, object, camera );
  15742. THREE.WebGLUniforms.upload( _gl, dynUniforms, m_uniforms, _this );
  15743. }
  15744. return program;
  15745. }
  15746. // Uniforms (refresh uniforms objects)
  15747. function refreshUniformsCommon ( uniforms, material ) {
  15748. uniforms.opacity.value = material.opacity;
  15749. uniforms.diffuse.value = material.color;
  15750. if ( material.emissive ) {
  15751. uniforms.emissive.value.copy( material.emissive ).multiplyScalar( material.emissiveIntensity );
  15752. }
  15753. uniforms.map.value = material.map;
  15754. uniforms.specularMap.value = material.specularMap;
  15755. uniforms.alphaMap.value = material.alphaMap;
  15756. if ( material.aoMap ) {
  15757. uniforms.aoMap.value = material.aoMap;
  15758. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  15759. }
  15760. // uv repeat and offset setting priorities
  15761. // 1. color map
  15762. // 2. specular map
  15763. // 3. normal map
  15764. // 4. bump map
  15765. // 5. alpha map
  15766. // 6. emissive map
  15767. var uvScaleMap;
  15768. if ( material.map ) {
  15769. uvScaleMap = material.map;
  15770. } else if ( material.specularMap ) {
  15771. uvScaleMap = material.specularMap;
  15772. } else if ( material.displacementMap ) {
  15773. uvScaleMap = material.displacementMap;
  15774. } else if ( material.normalMap ) {
  15775. uvScaleMap = material.normalMap;
  15776. } else if ( material.bumpMap ) {
  15777. uvScaleMap = material.bumpMap;
  15778. } else if ( material.roughnessMap ) {
  15779. uvScaleMap = material.roughnessMap;
  15780. } else if ( material.metalnessMap ) {
  15781. uvScaleMap = material.metalnessMap;
  15782. } else if ( material.alphaMap ) {
  15783. uvScaleMap = material.alphaMap;
  15784. } else if ( material.emissiveMap ) {
  15785. uvScaleMap = material.emissiveMap;
  15786. }
  15787. if ( uvScaleMap !== undefined ) {
  15788. // backwards compatibility
  15789. if ( uvScaleMap instanceof THREE.WebGLRenderTarget ) {
  15790. uvScaleMap = uvScaleMap.texture;
  15791. }
  15792. var offset = uvScaleMap.offset;
  15793. var repeat = uvScaleMap.repeat;
  15794. uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
  15795. }
  15796. uniforms.envMap.value = material.envMap;
  15797. // don't flip CubeTexture envMaps, flip everything else:
  15798. // WebGLRenderTargetCube will be flipped for backwards compatibility
  15799. // WebGLRenderTargetCube.texture will be flipped because it's a Texture and NOT a CubeTexture
  15800. // this check must be handled differently, or removed entirely, if WebGLRenderTargetCube uses a CubeTexture in the future
  15801. uniforms.flipEnvMap.value = ( ! ( material.envMap instanceof THREE.CubeTexture ) ) ? 1 : - 1;
  15802. uniforms.reflectivity.value = material.reflectivity;
  15803. uniforms.refractionRatio.value = material.refractionRatio;
  15804. }
  15805. function refreshUniformsLine ( uniforms, material ) {
  15806. uniforms.diffuse.value = material.color;
  15807. uniforms.opacity.value = material.opacity;
  15808. }
  15809. function refreshUniformsDash ( uniforms, material ) {
  15810. uniforms.dashSize.value = material.dashSize;
  15811. uniforms.totalSize.value = material.dashSize + material.gapSize;
  15812. uniforms.scale.value = material.scale;
  15813. }
  15814. function refreshUniformsPoints ( uniforms, material ) {
  15815. uniforms.diffuse.value = material.color;
  15816. uniforms.opacity.value = material.opacity;
  15817. uniforms.size.value = material.size * _pixelRatio;
  15818. uniforms.scale.value = _canvas.clientHeight * 0.5;
  15819. uniforms.map.value = material.map;
  15820. if ( material.map !== null ) {
  15821. var offset = material.map.offset;
  15822. var repeat = material.map.repeat;
  15823. uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
  15824. }
  15825. }
  15826. function refreshUniformsFog ( uniforms, fog ) {
  15827. uniforms.fogColor.value = fog.color;
  15828. if ( fog instanceof THREE.Fog ) {
  15829. uniforms.fogNear.value = fog.near;
  15830. uniforms.fogFar.value = fog.far;
  15831. } else if ( fog instanceof THREE.FogExp2 ) {
  15832. uniforms.fogDensity.value = fog.density;
  15833. }
  15834. }
  15835. function refreshUniformsLambert ( uniforms, material ) {
  15836. if ( material.lightMap ) {
  15837. uniforms.lightMap.value = material.lightMap;
  15838. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  15839. }
  15840. if ( material.emissiveMap ) {
  15841. uniforms.emissiveMap.value = material.emissiveMap;
  15842. }
  15843. }
  15844. function refreshUniformsPhong ( uniforms, material ) {
  15845. uniforms.specular.value = material.specular;
  15846. uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 )
  15847. if ( material.lightMap ) {
  15848. uniforms.lightMap.value = material.lightMap;
  15849. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  15850. }
  15851. if ( material.emissiveMap ) {
  15852. uniforms.emissiveMap.value = material.emissiveMap;
  15853. }
  15854. if ( material.bumpMap ) {
  15855. uniforms.bumpMap.value = material.bumpMap;
  15856. uniforms.bumpScale.value = material.bumpScale;
  15857. }
  15858. if ( material.normalMap ) {
  15859. uniforms.normalMap.value = material.normalMap;
  15860. uniforms.normalScale.value.copy( material.normalScale );
  15861. }
  15862. if ( material.displacementMap ) {
  15863. uniforms.displacementMap.value = material.displacementMap;
  15864. uniforms.displacementScale.value = material.displacementScale;
  15865. uniforms.displacementBias.value = material.displacementBias;
  15866. }
  15867. }
  15868. function refreshUniformsStandard ( uniforms, material ) {
  15869. uniforms.roughness.value = material.roughness;
  15870. uniforms.metalness.value = material.metalness;
  15871. if ( material.roughnessMap ) {
  15872. uniforms.roughnessMap.value = material.roughnessMap;
  15873. }
  15874. if ( material.metalnessMap ) {
  15875. uniforms.metalnessMap.value = material.metalnessMap;
  15876. }
  15877. if ( material.lightMap ) {
  15878. uniforms.lightMap.value = material.lightMap;
  15879. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  15880. }
  15881. if ( material.emissiveMap ) {
  15882. uniforms.emissiveMap.value = material.emissiveMap;
  15883. }
  15884. if ( material.bumpMap ) {
  15885. uniforms.bumpMap.value = material.bumpMap;
  15886. uniforms.bumpScale.value = material.bumpScale;
  15887. }
  15888. if ( material.normalMap ) {
  15889. uniforms.normalMap.value = material.normalMap;
  15890. uniforms.normalScale.value.copy( material.normalScale );
  15891. }
  15892. if ( material.displacementMap ) {
  15893. uniforms.displacementMap.value = material.displacementMap;
  15894. uniforms.displacementScale.value = material.displacementScale;
  15895. uniforms.displacementBias.value = material.displacementBias;
  15896. }
  15897. if ( material.envMap ) {
  15898. //uniforms.envMap.value = material.envMap; // part of uniforms common
  15899. uniforms.envMapIntensity.value = material.envMapIntensity;
  15900. }
  15901. }
  15902. function refreshUniformsPhysical ( uniforms, material ) {
  15903. refreshUniformsStandard( uniforms, material );
  15904. }
  15905. // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  15906. function markUniformsLightsNeedsUpdate ( uniforms, value ) {
  15907. uniforms.ambientLightColor.needsUpdate = value;
  15908. uniforms.directionalLights.needsUpdate = value;
  15909. uniforms.pointLights.needsUpdate = value;
  15910. uniforms.spotLights.needsUpdate = value;
  15911. uniforms.hemisphereLights.needsUpdate = value;
  15912. }
  15913. // Lighting
  15914. function setupShadows ( lights ) {
  15915. var lightShadowsLength = 0;
  15916. for ( var i = 0, l = lights.length; i < l; i ++ ) {
  15917. var light = lights[ i ];
  15918. if ( light.castShadow ) {
  15919. _lights.shadows[ lightShadowsLength ++ ] = light;
  15920. }
  15921. }
  15922. _lights.shadows.length = lightShadowsLength;
  15923. }
  15924. function setupLights ( lights, camera ) {
  15925. var l, ll, light,
  15926. r = 0, g = 0, b = 0,
  15927. color,
  15928. intensity,
  15929. distance,
  15930. shadowMap,
  15931. viewMatrix = camera.matrixWorldInverse,
  15932. directionalLength = 0,
  15933. pointLength = 0,
  15934. spotLength = 0,
  15935. hemiLength = 0;
  15936. for ( l = 0, ll = lights.length; l < ll; l ++ ) {
  15937. light = lights[ l ];
  15938. color = light.color;
  15939. intensity = light.intensity;
  15940. distance = light.distance;
  15941. shadowMap = ( light.shadow && light.shadow.map ) ? light.shadow.map.texture : null;
  15942. if ( light instanceof THREE.AmbientLight ) {
  15943. r += color.r * intensity;
  15944. g += color.g * intensity;
  15945. b += color.b * intensity;
  15946. } else if ( light instanceof THREE.DirectionalLight ) {
  15947. var uniforms = lightCache.get( light );
  15948. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  15949. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  15950. _vector3.setFromMatrixPosition( light.target.matrixWorld );
  15951. uniforms.direction.sub( _vector3 );
  15952. uniforms.direction.transformDirection( viewMatrix );
  15953. uniforms.shadow = light.castShadow;
  15954. if ( light.castShadow ) {
  15955. uniforms.shadowBias = light.shadow.bias;
  15956. uniforms.shadowRadius = light.shadow.radius;
  15957. uniforms.shadowMapSize = light.shadow.mapSize;
  15958. }
  15959. _lights.directionalShadowMap[ directionalLength ] = shadowMap;
  15960. _lights.directionalShadowMatrix[ directionalLength ] = light.shadow.matrix;
  15961. _lights.directional[ directionalLength ++ ] = uniforms;
  15962. } else if ( light instanceof THREE.SpotLight ) {
  15963. var uniforms = lightCache.get( light );
  15964. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  15965. uniforms.position.applyMatrix4( viewMatrix );
  15966. uniforms.color.copy( color ).multiplyScalar( intensity );
  15967. uniforms.distance = distance;
  15968. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  15969. _vector3.setFromMatrixPosition( light.target.matrixWorld );
  15970. uniforms.direction.sub( _vector3 );
  15971. uniforms.direction.transformDirection( viewMatrix );
  15972. uniforms.coneCos = Math.cos( light.angle );
  15973. uniforms.penumbraCos = Math.cos( light.angle * ( 1 - light.penumbra ) );
  15974. uniforms.decay = ( light.distance === 0 ) ? 0.0 : light.decay;
  15975. uniforms.shadow = light.castShadow;
  15976. if ( light.castShadow ) {
  15977. uniforms.shadowBias = light.shadow.bias;
  15978. uniforms.shadowRadius = light.shadow.radius;
  15979. uniforms.shadowMapSize = light.shadow.mapSize;
  15980. }
  15981. _lights.spotShadowMap[ spotLength ] = shadowMap;
  15982. _lights.spotShadowMatrix[ spotLength ] = light.shadow.matrix;
  15983. _lights.spot[ spotLength ++ ] = uniforms;
  15984. } else if ( light instanceof THREE.PointLight ) {
  15985. var uniforms = lightCache.get( light );
  15986. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  15987. uniforms.position.applyMatrix4( viewMatrix );
  15988. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  15989. uniforms.distance = light.distance;
  15990. uniforms.decay = ( light.distance === 0 ) ? 0.0 : light.decay;
  15991. uniforms.shadow = light.castShadow;
  15992. if ( light.castShadow ) {
  15993. uniforms.shadowBias = light.shadow.bias;
  15994. uniforms.shadowRadius = light.shadow.radius;
  15995. uniforms.shadowMapSize = light.shadow.mapSize;
  15996. }
  15997. _lights.pointShadowMap[ pointLength ] = shadowMap;
  15998. if ( _lights.pointShadowMatrix[ pointLength ] === undefined ) {
  15999. _lights.pointShadowMatrix[ pointLength ] = new THREE.Matrix4();
  16000. }
  16001. // for point lights we set the shadow matrix to be a translation-only matrix
  16002. // equal to inverse of the light's position
  16003. _vector3.setFromMatrixPosition( light.matrixWorld ).negate();
  16004. _lights.pointShadowMatrix[ pointLength ].identity().setPosition( _vector3 );
  16005. _lights.point[ pointLength ++ ] = uniforms;
  16006. } else if ( light instanceof THREE.HemisphereLight ) {
  16007. var uniforms = lightCache.get( light );
  16008. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  16009. uniforms.direction.transformDirection( viewMatrix );
  16010. uniforms.direction.normalize();
  16011. uniforms.skyColor.copy( light.color ).multiplyScalar( intensity );
  16012. uniforms.groundColor.copy( light.groundColor ).multiplyScalar( intensity );
  16013. _lights.hemi[ hemiLength ++ ] = uniforms;
  16014. }
  16015. }
  16016. _lights.ambient[ 0 ] = r;
  16017. _lights.ambient[ 1 ] = g;
  16018. _lights.ambient[ 2 ] = b;
  16019. _lights.directional.length = directionalLength;
  16020. _lights.spot.length = spotLength;
  16021. _lights.point.length = pointLength;
  16022. _lights.hemi.length = hemiLength;
  16023. _lights.hash = directionalLength + ',' + pointLength + ',' + spotLength + ',' + hemiLength + ',' + _lights.shadows.length;
  16024. }
  16025. // GL state setting
  16026. this.setFaceCulling = function ( cullFace, frontFaceDirection ) {
  16027. state.setCullFace( cullFace );
  16028. state.setFlipSided( frontFaceDirection === THREE.FrontFaceDirectionCW );
  16029. };
  16030. // Textures
  16031. function allocTextureUnit() {
  16032. var textureUnit = _usedTextureUnits;
  16033. if ( textureUnit >= capabilities.maxTextures ) {
  16034. console.warn( 'WebGLRenderer: trying to use ' + textureUnit + ' texture units while this GPU supports only ' + capabilities.maxTextures );
  16035. }
  16036. _usedTextureUnits += 1;
  16037. return textureUnit;
  16038. }
  16039. function setTextureParameters ( textureType, texture, isPowerOfTwoImage ) {
  16040. var extension;
  16041. if ( isPowerOfTwoImage ) {
  16042. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, paramThreeToGL( texture.wrapS ) );
  16043. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, paramThreeToGL( texture.wrapT ) );
  16044. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, paramThreeToGL( texture.magFilter ) );
  16045. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, paramThreeToGL( texture.minFilter ) );
  16046. } else {
  16047. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, _gl.CLAMP_TO_EDGE );
  16048. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, _gl.CLAMP_TO_EDGE );
  16049. if ( texture.wrapS !== THREE.ClampToEdgeWrapping || texture.wrapT !== THREE.ClampToEdgeWrapping ) {
  16050. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.', texture );
  16051. }
  16052. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, filterFallback( texture.magFilter ) );
  16053. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, filterFallback( texture.minFilter ) );
  16054. if ( texture.minFilter !== THREE.NearestFilter && texture.minFilter !== THREE.LinearFilter ) {
  16055. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.', texture );
  16056. }
  16057. }
  16058. extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  16059. if ( extension ) {
  16060. if ( texture.type === THREE.FloatType && extensions.get( 'OES_texture_float_linear' ) === null ) return;
  16061. if ( texture.type === THREE.HalfFloatType && extensions.get( 'OES_texture_half_float_linear' ) === null ) return;
  16062. if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
  16063. _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, _this.getMaxAnisotropy() ) );
  16064. properties.get( texture ).__currentAnisotropy = texture.anisotropy;
  16065. }
  16066. }
  16067. }
  16068. function uploadTexture( textureProperties, texture, slot ) {
  16069. if ( textureProperties.__webglInit === undefined ) {
  16070. textureProperties.__webglInit = true;
  16071. texture.addEventListener( 'dispose', onTextureDispose );
  16072. textureProperties.__webglTexture = _gl.createTexture();
  16073. _infoMemory.textures ++;
  16074. }
  16075. state.activeTexture( _gl.TEXTURE0 + slot );
  16076. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  16077. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  16078. _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );
  16079. _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
  16080. var image = clampToMaxSize( texture.image, capabilities.maxTextureSize );
  16081. if ( textureNeedsPowerOfTwo( texture ) && isPowerOfTwo( image ) === false ) {
  16082. image = makePowerOfTwo( image );
  16083. }
  16084. var isPowerOfTwoImage = isPowerOfTwo( image ),
  16085. glFormat = paramThreeToGL( texture.format ),
  16086. glType = paramThreeToGL( texture.type );
  16087. setTextureParameters( _gl.TEXTURE_2D, texture, isPowerOfTwoImage );
  16088. var mipmap, mipmaps = texture.mipmaps;
  16089. if ( texture instanceof THREE.DepthTexture ) {
  16090. // populate depth texture with dummy data
  16091. var internalFormat = _gl.DEPTH_COMPONENT;
  16092. if ( texture.type === THREE.FloatType ) {
  16093. if ( !_isWebGL2 ) throw new Error('Float Depth Texture only supported in WebGL2.0');
  16094. internalFormat = _gl.DEPTH_COMPONENT32F;
  16095. } else if ( _isWebGL2 ) {
  16096. // WebGL 2.0 requires signed internalformat for glTexImage2D
  16097. internalFormat = _gl.DEPTH_COMPONENT16;
  16098. }
  16099. state.texImage2D( _gl.TEXTURE_2D, 0, internalFormat, image.width, image.height, 0, glFormat, glType, null );
  16100. } else if ( texture instanceof THREE.DataTexture ) {
  16101. // use manually created mipmaps if available
  16102. // if there are no manual mipmaps
  16103. // set 0 level mipmap and then use GL to generate other mipmap levels
  16104. if ( mipmaps.length > 0 && isPowerOfTwoImage ) {
  16105. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  16106. mipmap = mipmaps[ i ];
  16107. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  16108. }
  16109. texture.generateMipmaps = false;
  16110. } else {
  16111. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, image.width, image.height, 0, glFormat, glType, image.data );
  16112. }
  16113. } else if ( texture instanceof THREE.CompressedTexture ) {
  16114. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  16115. mipmap = mipmaps[ i ];
  16116. if ( texture.format !== THREE.RGBAFormat && texture.format !== THREE.RGBFormat ) {
  16117. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  16118. state.compressedTexImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  16119. } else {
  16120. console.warn( "THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()" );
  16121. }
  16122. } else {
  16123. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  16124. }
  16125. }
  16126. } else {
  16127. // regular Texture (image, video, canvas)
  16128. // use manually created mipmaps if available
  16129. // if there are no manual mipmaps
  16130. // set 0 level mipmap and then use GL to generate other mipmap levels
  16131. if ( mipmaps.length > 0 && isPowerOfTwoImage ) {
  16132. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  16133. mipmap = mipmaps[ i ];
  16134. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, glFormat, glType, mipmap );
  16135. }
  16136. texture.generateMipmaps = false;
  16137. } else {
  16138. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, glFormat, glType, image );
  16139. }
  16140. }
  16141. if ( texture.generateMipmaps && isPowerOfTwoImage ) _gl.generateMipmap( _gl.TEXTURE_2D );
  16142. textureProperties.__version = texture.version;
  16143. if ( texture.onUpdate ) texture.onUpdate( texture );
  16144. }
  16145. function setTexture2D( texture, slot ) {
  16146. var textureProperties = properties.get( texture );
  16147. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  16148. var image = texture.image;
  16149. if ( image === undefined ) {
  16150. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is undefined', texture );
  16151. return;
  16152. }
  16153. if ( image.complete === false ) {
  16154. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete', texture );
  16155. return;
  16156. }
  16157. uploadTexture( textureProperties, texture, slot );
  16158. return;
  16159. }
  16160. state.activeTexture( _gl.TEXTURE0 + slot );
  16161. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  16162. }
  16163. function clampToMaxSize ( image, maxSize ) {
  16164. if ( image.width > maxSize || image.height > maxSize ) {
  16165. // Warning: Scaling through the canvas will only work with images that use
  16166. // premultiplied alpha.
  16167. var scale = maxSize / Math.max( image.width, image.height );
  16168. var canvas = document.createElement( 'canvas' );
  16169. canvas.width = Math.floor( image.width * scale );
  16170. canvas.height = Math.floor( image.height * scale );
  16171. var context = canvas.getContext( '2d' );
  16172. context.drawImage( image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height );
  16173. console.warn( 'THREE.WebGLRenderer: image is too big (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
  16174. return canvas;
  16175. }
  16176. return image;
  16177. }
  16178. function isPowerOfTwo( image ) {
  16179. return THREE.Math.isPowerOfTwo( image.width ) && THREE.Math.isPowerOfTwo( image.height );
  16180. }
  16181. function textureNeedsPowerOfTwo( texture ) {
  16182. if ( texture.wrapS !== THREE.ClampToEdgeWrapping || texture.wrapT !== THREE.ClampToEdgeWrapping ) return true;
  16183. if ( texture.minFilter !== THREE.NearestFilter && texture.minFilter !== THREE.LinearFilter ) return true;
  16184. return false;
  16185. }
  16186. function makePowerOfTwo( image ) {
  16187. if ( image instanceof HTMLImageElement || image instanceof HTMLCanvasElement ) {
  16188. var canvas = document.createElement( 'canvas' );
  16189. canvas.width = THREE.Math.nearestPowerOfTwo( image.width );
  16190. canvas.height = THREE.Math.nearestPowerOfTwo( image.height );
  16191. var context = canvas.getContext( '2d' );
  16192. context.drawImage( image, 0, 0, canvas.width, canvas.height );
  16193. console.warn( 'THREE.WebGLRenderer: image is not power of two (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
  16194. return canvas;
  16195. }
  16196. return image;
  16197. }
  16198. function setTextureCube ( texture, slot ) {
  16199. var textureProperties = properties.get( texture );
  16200. if ( texture.image.length === 6 ) {
  16201. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  16202. if ( ! textureProperties.__image__webglTextureCube ) {
  16203. texture.addEventListener( 'dispose', onTextureDispose );
  16204. textureProperties.__image__webglTextureCube = _gl.createTexture();
  16205. _infoMemory.textures ++;
  16206. }
  16207. state.activeTexture( _gl.TEXTURE0 + slot );
  16208. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  16209. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  16210. var isCompressed = texture instanceof THREE.CompressedTexture;
  16211. var isDataTexture = texture.image[ 0 ] instanceof THREE.DataTexture;
  16212. var cubeImage = [];
  16213. for ( var i = 0; i < 6; i ++ ) {
  16214. if ( _this.autoScaleCubemaps && ! isCompressed && ! isDataTexture ) {
  16215. cubeImage[ i ] = clampToMaxSize( texture.image[ i ], capabilities.maxCubemapSize );
  16216. } else {
  16217. cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
  16218. }
  16219. }
  16220. var image = cubeImage[ 0 ],
  16221. isPowerOfTwoImage = isPowerOfTwo( image ),
  16222. glFormat = paramThreeToGL( texture.format ),
  16223. glType = paramThreeToGL( texture.type );
  16224. setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture, isPowerOfTwoImage );
  16225. for ( var i = 0; i < 6; i ++ ) {
  16226. if ( ! isCompressed ) {
  16227. if ( isDataTexture ) {
  16228. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
  16229. } else {
  16230. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, glFormat, glType, cubeImage[ i ] );
  16231. }
  16232. } else {
  16233. var mipmap, mipmaps = cubeImage[ i ].mipmaps;
  16234. for ( var j = 0, jl = mipmaps.length; j < jl; j ++ ) {
  16235. mipmap = mipmaps[ j ];
  16236. if ( texture.format !== THREE.RGBAFormat && texture.format !== THREE.RGBFormat ) {
  16237. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  16238. state.compressedTexImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  16239. } else {
  16240. console.warn( "THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()" );
  16241. }
  16242. } else {
  16243. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  16244. }
  16245. }
  16246. }
  16247. }
  16248. if ( texture.generateMipmaps && isPowerOfTwoImage ) {
  16249. _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  16250. }
  16251. textureProperties.__version = texture.version;
  16252. if ( texture.onUpdate ) texture.onUpdate( texture );
  16253. } else {
  16254. state.activeTexture( _gl.TEXTURE0 + slot );
  16255. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  16256. }
  16257. }
  16258. }
  16259. function setTextureCubeDynamic ( texture, slot ) {
  16260. state.activeTexture( _gl.TEXTURE0 + slot );
  16261. state.bindTexture( _gl.TEXTURE_CUBE_MAP, properties.get( texture ).__webglTexture );
  16262. }
  16263. this.allocTextureUnit = allocTextureUnit;
  16264. //this.setTexture2D = setTexture2D;
  16265. this.setTexture2D = ( function() {
  16266. var warned = false;
  16267. // backwards compatibility: peel texture.texture
  16268. return function( texture, slot ) {
  16269. if ( texture instanceof THREE.WebGLRenderTarget ) {
  16270. if ( ! warned ) {
  16271. console.warn( "THREE.WebGLRenderer.setTexture2D: don't use render targets as textures. Use their .texture property instead." );
  16272. warned = true;
  16273. }
  16274. texture = texture.texture;
  16275. }
  16276. setTexture2D( texture, slot );
  16277. };
  16278. }() );
  16279. this.setTexture = ( function() {
  16280. var warned = false;
  16281. return function( texture, slot ) {
  16282. if ( ! warned ) {
  16283. console.warn( "THREE.WebGLRenderer: .setTexture is deprecated, use setTexture2D instead." );
  16284. warned = true;
  16285. }
  16286. _this.setTexture2D( texture, slot );
  16287. };
  16288. }() );
  16289. this.setTextureCube = ( function() {
  16290. var warned = false;
  16291. return function( texture, slot ) {
  16292. // backwards compatibility: peel texture.texture
  16293. if ( texture instanceof THREE.WebGLRenderTargetCube ) {
  16294. if ( ! warned ) {
  16295. console.warn( "THREE.WebGLRenderer.setTextureCube: don't use cube render targets as textures. Use their .texture property instead." );
  16296. warned = true;
  16297. }
  16298. texture = texture.texture;
  16299. }
  16300. // currently relying on the fact that WebGLRenderTargetCube.texture is a Texture and NOT a CubeTexture
  16301. // TODO: unify these code paths
  16302. if ( texture instanceof THREE.CubeTexture ||
  16303. ( Array.isArray( texture.image ) && texture.image.length === 6 ) ) {
  16304. // CompressedTexture can have Array in image :/
  16305. // this function alone should take care of cube textures
  16306. setTextureCube( texture, slot );
  16307. } else {
  16308. // assumed: texture property of THREE.WebGLRenderTargetCube
  16309. setTextureCubeDynamic( texture, slot );
  16310. }
  16311. };
  16312. }() );
  16313. // Render targets
  16314. // Setup storage for target texture and bind it to correct framebuffer
  16315. function setupFrameBufferTexture ( framebuffer, renderTarget, attachment, textureTarget ) {
  16316. var glFormat = paramThreeToGL( renderTarget.texture.format );
  16317. var glType = paramThreeToGL( renderTarget.texture.type );
  16318. state.texImage2D( textureTarget, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  16319. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  16320. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, attachment, textureTarget, properties.get( renderTarget.texture ).__webglTexture, 0 );
  16321. _gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
  16322. }
  16323. // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  16324. function setupRenderBufferStorage ( renderbuffer, renderTarget ) {
  16325. _gl.bindRenderbuffer( _gl.RENDERBUFFER, renderbuffer );
  16326. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  16327. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_COMPONENT16, renderTarget.width, renderTarget.height );
  16328. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  16329. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  16330. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_STENCIL, renderTarget.width, renderTarget.height );
  16331. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  16332. } else {
  16333. // FIXME: We don't support !depth !stencil
  16334. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.RGBA4, renderTarget.width, renderTarget.height );
  16335. }
  16336. _gl.bindRenderbuffer( _gl.RENDERBUFFER, null );
  16337. }
  16338. // Setup resources for a Depth Texture for a FBO (needs an extension)
  16339. function setupDepthTexture ( framebuffer, renderTarget ) {
  16340. var isCube = ( renderTarget instanceof THREE.WebGLRenderTargetCube );
  16341. if ( isCube ) throw new Error('Depth Texture with cube render targets is not supported!');
  16342. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  16343. if ( !( renderTarget.depthTexture instanceof THREE.DepthTexture ) ) {
  16344. throw new Error('renderTarget.depthTexture must be an instance of THREE.DepthTexture');
  16345. }
  16346. // upload an empty depth texture with framebuffer size
  16347. if ( !properties.get( renderTarget.depthTexture ).__webglTexture ||
  16348. renderTarget.depthTexture.image.width !== renderTarget.width ||
  16349. renderTarget.depthTexture.image.height !== renderTarget.height ) {
  16350. renderTarget.depthTexture.image.width = renderTarget.width;
  16351. renderTarget.depthTexture.image.height = renderTarget.height;
  16352. renderTarget.depthTexture.needsUpdate = true;
  16353. }
  16354. _this.setTexture2D( renderTarget.depthTexture, 0 );
  16355. var webglDepthTexture = properties.get( renderTarget.depthTexture ).__webglTexture;
  16356. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0 );
  16357. }
  16358. // Setup GL resources for a non-texture depth buffer
  16359. function setupDepthRenderbuffer( renderTarget ) {
  16360. var renderTargetProperties = properties.get( renderTarget );
  16361. var isCube = ( renderTarget instanceof THREE.WebGLRenderTargetCube );
  16362. if ( renderTarget.depthTexture ) {
  16363. if ( isCube ) throw new Error('target.depthTexture not supported in Cube render targets');
  16364. setupDepthTexture( renderTargetProperties.__webglFramebuffer, renderTarget );
  16365. } else {
  16366. if ( isCube ) {
  16367. renderTargetProperties.__webglDepthbuffer = [];
  16368. for ( var i = 0; i < 6; i ++ ) {
  16369. _gl.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer[ i ] );
  16370. renderTargetProperties.__webglDepthbuffer[ i ] = _gl.createRenderbuffer();
  16371. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer[ i ], renderTarget );
  16372. }
  16373. } else {
  16374. _gl.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer );
  16375. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  16376. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer, renderTarget );
  16377. }
  16378. }
  16379. _gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
  16380. }
  16381. // Set up GL resources for the render target
  16382. function setupRenderTarget( renderTarget ) {
  16383. var renderTargetProperties = properties.get( renderTarget );
  16384. var textureProperties = properties.get( renderTarget.texture );
  16385. renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
  16386. textureProperties.__webglTexture = _gl.createTexture();
  16387. _infoMemory.textures ++;
  16388. var isCube = ( renderTarget instanceof THREE.WebGLRenderTargetCube );
  16389. var isTargetPowerOfTwo = THREE.Math.isPowerOfTwo( renderTarget.width ) && THREE.Math.isPowerOfTwo( renderTarget.height );
  16390. // Setup framebuffer
  16391. if ( isCube ) {
  16392. renderTargetProperties.__webglFramebuffer = [];
  16393. for ( var i = 0; i < 6; i ++ ) {
  16394. renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer();
  16395. }
  16396. } else {
  16397. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  16398. }
  16399. // Setup color buffer
  16400. if ( isCube ) {
  16401. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__webglTexture );
  16402. setTextureParameters( _gl.TEXTURE_CUBE_MAP, renderTarget.texture, isTargetPowerOfTwo );
  16403. for ( var i = 0; i < 6; i ++ ) {
  16404. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i );
  16405. }
  16406. if ( renderTarget.texture.generateMipmaps && isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  16407. state.bindTexture( _gl.TEXTURE_CUBE_MAP, null );
  16408. } else {
  16409. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  16410. setTextureParameters( _gl.TEXTURE_2D, renderTarget.texture, isTargetPowerOfTwo );
  16411. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_2D );
  16412. if ( renderTarget.texture.generateMipmaps && isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_2D );
  16413. state.bindTexture( _gl.TEXTURE_2D, null );
  16414. }
  16415. // Setup depth and stencil buffers
  16416. if ( renderTarget.depthBuffer ) {
  16417. setupDepthRenderbuffer( renderTarget );
  16418. }
  16419. }
  16420. this.getCurrentRenderTarget = function() {
  16421. return _currentRenderTarget;
  16422. };
  16423. this.setRenderTarget = function ( renderTarget ) {
  16424. _currentRenderTarget = renderTarget;
  16425. if ( renderTarget && properties.get( renderTarget ).__webglFramebuffer === undefined ) {
  16426. setupRenderTarget( renderTarget );
  16427. }
  16428. var isCube = ( renderTarget instanceof THREE.WebGLRenderTargetCube );
  16429. var framebuffer;
  16430. if ( renderTarget ) {
  16431. var renderTargetProperties = properties.get( renderTarget );
  16432. if ( isCube ) {
  16433. framebuffer = renderTargetProperties.__webglFramebuffer[ renderTarget.activeCubeFace ];
  16434. } else {
  16435. framebuffer = renderTargetProperties.__webglFramebuffer;
  16436. }
  16437. _currentScissor.copy( renderTarget.scissor );
  16438. _currentScissorTest = renderTarget.scissorTest;
  16439. _currentViewport.copy( renderTarget.viewport );
  16440. } else {
  16441. framebuffer = null;
  16442. _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio );
  16443. _currentScissorTest = _scissorTest;
  16444. _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio );
  16445. }
  16446. if ( _currentFramebuffer !== framebuffer ) {
  16447. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  16448. _currentFramebuffer = framebuffer;
  16449. }
  16450. state.scissor( _currentScissor );
  16451. state.setScissorTest( _currentScissorTest );
  16452. state.viewport( _currentViewport );
  16453. if ( isCube ) {
  16454. var textureProperties = properties.get( renderTarget.texture );
  16455. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + renderTarget.activeCubeFace, textureProperties.__webglTexture, renderTarget.activeMipMapLevel );
  16456. }
  16457. };
  16458. this.readRenderTargetPixels = function ( renderTarget, x, y, width, height, buffer ) {
  16459. if ( renderTarget instanceof THREE.WebGLRenderTarget === false ) {
  16460. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
  16461. return;
  16462. }
  16463. var framebuffer = properties.get( renderTarget ).__webglFramebuffer;
  16464. if ( framebuffer ) {
  16465. var restore = false;
  16466. if ( framebuffer !== _currentFramebuffer ) {
  16467. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  16468. restore = true;
  16469. }
  16470. try {
  16471. var texture = renderTarget.texture;
  16472. if ( texture.format !== THREE.RGBAFormat && paramThreeToGL( texture.format ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_FORMAT ) ) {
  16473. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
  16474. return;
  16475. }
  16476. if ( texture.type !== THREE.UnsignedByteType &&
  16477. paramThreeToGL( texture.type ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_TYPE ) &&
  16478. ! ( texture.type === THREE.FloatType && extensions.get( 'WEBGL_color_buffer_float' ) ) &&
  16479. ! ( texture.type === THREE.HalfFloatType && extensions.get( 'EXT_color_buffer_half_float' ) ) ) {
  16480. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' );
  16481. return;
  16482. }
  16483. if ( _gl.checkFramebufferStatus( _gl.FRAMEBUFFER ) === _gl.FRAMEBUFFER_COMPLETE ) {
  16484. // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
  16485. if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {
  16486. _gl.readPixels( x, y, width, height, paramThreeToGL( texture.format ), paramThreeToGL( texture.type ), buffer );
  16487. }
  16488. } else {
  16489. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );
  16490. }
  16491. } finally {
  16492. if ( restore ) {
  16493. _gl.bindFramebuffer( _gl.FRAMEBUFFER, _currentFramebuffer );
  16494. }
  16495. }
  16496. }
  16497. };
  16498. function updateRenderTargetMipmap( renderTarget ) {
  16499. var target = renderTarget instanceof THREE.WebGLRenderTargetCube ? _gl.TEXTURE_CUBE_MAP : _gl.TEXTURE_2D;
  16500. var texture = properties.get( renderTarget.texture ).__webglTexture;
  16501. state.bindTexture( target, texture );
  16502. _gl.generateMipmap( target );
  16503. state.bindTexture( target, null );
  16504. }
  16505. // Fallback filters for non-power-of-2 textures
  16506. function filterFallback ( f ) {
  16507. if ( f === THREE.NearestFilter || f === THREE.NearestMipMapNearestFilter || f === THREE.NearestMipMapLinearFilter ) {
  16508. return _gl.NEAREST;
  16509. }
  16510. return _gl.LINEAR;
  16511. }
  16512. // Map three.js constants to WebGL constants
  16513. function paramThreeToGL ( p ) {
  16514. var extension;
  16515. if ( p === THREE.RepeatWrapping ) return _gl.REPEAT;
  16516. if ( p === THREE.ClampToEdgeWrapping ) return _gl.CLAMP_TO_EDGE;
  16517. if ( p === THREE.MirroredRepeatWrapping ) return _gl.MIRRORED_REPEAT;
  16518. if ( p === THREE.NearestFilter ) return _gl.NEAREST;
  16519. if ( p === THREE.NearestMipMapNearestFilter ) return _gl.NEAREST_MIPMAP_NEAREST;
  16520. if ( p === THREE.NearestMipMapLinearFilter ) return _gl.NEAREST_MIPMAP_LINEAR;
  16521. if ( p === THREE.LinearFilter ) return _gl.LINEAR;
  16522. if ( p === THREE.LinearMipMapNearestFilter ) return _gl.LINEAR_MIPMAP_NEAREST;
  16523. if ( p === THREE.LinearMipMapLinearFilter ) return _gl.LINEAR_MIPMAP_LINEAR;
  16524. if ( p === THREE.UnsignedByteType ) return _gl.UNSIGNED_BYTE;
  16525. if ( p === THREE.UnsignedShort4444Type ) return _gl.UNSIGNED_SHORT_4_4_4_4;
  16526. if ( p === THREE.UnsignedShort5551Type ) return _gl.UNSIGNED_SHORT_5_5_5_1;
  16527. if ( p === THREE.UnsignedShort565Type ) return _gl.UNSIGNED_SHORT_5_6_5;
  16528. if ( p === THREE.ByteType ) return _gl.BYTE;
  16529. if ( p === THREE.ShortType ) return _gl.SHORT;
  16530. if ( p === THREE.UnsignedShortType ) return _gl.UNSIGNED_SHORT;
  16531. if ( p === THREE.IntType ) return _gl.INT;
  16532. if ( p === THREE.UnsignedIntType ) return _gl.UNSIGNED_INT;
  16533. if ( p === THREE.FloatType ) return _gl.FLOAT;
  16534. extension = extensions.get( 'OES_texture_half_float' );
  16535. if ( extension !== null ) {
  16536. if ( p === THREE.HalfFloatType ) return extension.HALF_FLOAT_OES;
  16537. }
  16538. if ( p === THREE.AlphaFormat ) return _gl.ALPHA;
  16539. if ( p === THREE.RGBFormat ) return _gl.RGB;
  16540. if ( p === THREE.RGBAFormat ) return _gl.RGBA;
  16541. if ( p === THREE.LuminanceFormat ) return _gl.LUMINANCE;
  16542. if ( p === THREE.LuminanceAlphaFormat ) return _gl.LUMINANCE_ALPHA;
  16543. if ( p === THREE.DepthFormat ) return _gl.DEPTH_COMPONENT;
  16544. if ( p === THREE.AddEquation ) return _gl.FUNC_ADD;
  16545. if ( p === THREE.SubtractEquation ) return _gl.FUNC_SUBTRACT;
  16546. if ( p === THREE.ReverseSubtractEquation ) return _gl.FUNC_REVERSE_SUBTRACT;
  16547. if ( p === THREE.ZeroFactor ) return _gl.ZERO;
  16548. if ( p === THREE.OneFactor ) return _gl.ONE;
  16549. if ( p === THREE.SrcColorFactor ) return _gl.SRC_COLOR;
  16550. if ( p === THREE.OneMinusSrcColorFactor ) return _gl.ONE_MINUS_SRC_COLOR;
  16551. if ( p === THREE.SrcAlphaFactor ) return _gl.SRC_ALPHA;
  16552. if ( p === THREE.OneMinusSrcAlphaFactor ) return _gl.ONE_MINUS_SRC_ALPHA;
  16553. if ( p === THREE.DstAlphaFactor ) return _gl.DST_ALPHA;
  16554. if ( p === THREE.OneMinusDstAlphaFactor ) return _gl.ONE_MINUS_DST_ALPHA;
  16555. if ( p === THREE.DstColorFactor ) return _gl.DST_COLOR;
  16556. if ( p === THREE.OneMinusDstColorFactor ) return _gl.ONE_MINUS_DST_COLOR;
  16557. if ( p === THREE.SrcAlphaSaturateFactor ) return _gl.SRC_ALPHA_SATURATE;
  16558. extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );
  16559. if ( extension !== null ) {
  16560. if ( p === THREE.RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  16561. if ( p === THREE.RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  16562. if ( p === THREE.RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  16563. if ( p === THREE.RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  16564. }
  16565. extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  16566. if ( extension !== null ) {
  16567. if ( p === THREE.RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  16568. if ( p === THREE.RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  16569. if ( p === THREE.RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  16570. if ( p === THREE.RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  16571. }
  16572. extension = extensions.get( 'WEBGL_compressed_texture_etc1' );
  16573. if ( extension !== null ) {
  16574. if ( p === THREE.RGB_ETC1_Format ) return extension.COMPRESSED_RGB_ETC1_WEBGL;
  16575. }
  16576. extension = extensions.get( 'EXT_blend_minmax' );
  16577. if ( extension !== null ) {
  16578. if ( p === THREE.MinEquation ) return extension.MIN_EXT;
  16579. if ( p === THREE.MaxEquation ) return extension.MAX_EXT;
  16580. }
  16581. return 0;
  16582. }
  16583. };
  16584. // File:src/renderers/WebGLRenderTarget.js
  16585. /**
  16586. * @author szimek / https://github.com/szimek/
  16587. * @author alteredq / http://alteredqualia.com/
  16588. * @author Marius Kintel / https://github.com/kintel
  16589. */
  16590. /*
  16591. In options, we can specify:
  16592. * Texture parameters for an auto-generated target texture
  16593. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  16594. */
  16595. THREE.WebGLRenderTarget = function ( width, height, options ) {
  16596. this.uuid = THREE.Math.generateUUID();
  16597. this.width = width;
  16598. this.height = height;
  16599. this.scissor = new THREE.Vector4( 0, 0, width, height );
  16600. this.scissorTest = false;
  16601. this.viewport = new THREE.Vector4( 0, 0, width, height );
  16602. options = options || {};
  16603. if ( options.minFilter === undefined ) options.minFilter = THREE.LinearFilter;
  16604. this.texture = new THREE.Texture( undefined, undefined, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding );
  16605. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  16606. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;
  16607. this.depthTexture = null;
  16608. };
  16609. Object.assign( THREE.WebGLRenderTarget.prototype, THREE.EventDispatcher.prototype, {
  16610. setSize: function ( width, height ) {
  16611. if ( this.width !== width || this.height !== height ) {
  16612. this.width = width;
  16613. this.height = height;
  16614. this.dispose();
  16615. }
  16616. this.viewport.set( 0, 0, width, height );
  16617. this.scissor.set( 0, 0, width, height );
  16618. },
  16619. clone: function () {
  16620. return new this.constructor().copy( this );
  16621. },
  16622. copy: function ( source ) {
  16623. this.width = source.width;
  16624. this.height = source.height;
  16625. this.viewport.copy( source.viewport );
  16626. this.texture = source.texture.clone();
  16627. this.depthBuffer = source.depthBuffer;
  16628. this.stencilBuffer = source.stencilBuffer;
  16629. this.depthTexture = source.depthTexture;
  16630. return this;
  16631. },
  16632. dispose: function () {
  16633. this.dispatchEvent( { type: 'dispose' } );
  16634. }
  16635. } );
  16636. // File:src/renderers/WebGLRenderTargetCube.js
  16637. /**
  16638. * @author alteredq / http://alteredqualia.com
  16639. */
  16640. THREE.WebGLRenderTargetCube = function ( width, height, options ) {
  16641. THREE.WebGLRenderTarget.call( this, width, height, options );
  16642. this.activeCubeFace = 0; // PX 0, NX 1, PY 2, NY 3, PZ 4, NZ 5
  16643. this.activeMipMapLevel = 0;
  16644. };
  16645. THREE.WebGLRenderTargetCube.prototype = Object.create( THREE.WebGLRenderTarget.prototype );
  16646. THREE.WebGLRenderTargetCube.prototype.constructor = THREE.WebGLRenderTargetCube;
  16647. // File:src/renderers/webgl/WebGLBufferRenderer.js
  16648. /**
  16649. * @author mrdoob / http://mrdoob.com/
  16650. */
  16651. THREE.WebGLBufferRenderer = function ( _gl, extensions, _infoRender ) {
  16652. var mode;
  16653. function setMode( value ) {
  16654. mode = value;
  16655. }
  16656. function render( start, count ) {
  16657. _gl.drawArrays( mode, start, count );
  16658. _infoRender.calls ++;
  16659. _infoRender.vertices += count;
  16660. if ( mode === _gl.TRIANGLES ) _infoRender.faces += count / 3;
  16661. }
  16662. function renderInstances( geometry ) {
  16663. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  16664. if ( extension === null ) {
  16665. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  16666. return;
  16667. }
  16668. var position = geometry.attributes.position;
  16669. var count = 0;
  16670. if ( position instanceof THREE.InterleavedBufferAttribute ) {
  16671. count = position.data.count;
  16672. extension.drawArraysInstancedANGLE( mode, 0, count, geometry.maxInstancedCount );
  16673. } else {
  16674. count = position.count;
  16675. extension.drawArraysInstancedANGLE( mode, 0, count, geometry.maxInstancedCount );
  16676. }
  16677. _infoRender.calls ++;
  16678. _infoRender.vertices += count * geometry.maxInstancedCount;
  16679. if ( mode === _gl.TRIANGLES ) _infoRender.faces += geometry.maxInstancedCount * count / 3;
  16680. }
  16681. this.setMode = setMode;
  16682. this.render = render;
  16683. this.renderInstances = renderInstances;
  16684. };
  16685. // File:src/renderers/webgl/WebGLClipping.js
  16686. THREE.WebGLClipping = function() {
  16687. var scope = this,
  16688. globalState = null,
  16689. numGlobalPlanes = 0,
  16690. localClippingEnabled = false,
  16691. renderingShadows = false,
  16692. plane = new THREE.Plane(),
  16693. viewNormalMatrix = new THREE.Matrix3(),
  16694. uniform = { value: null, needsUpdate: false };
  16695. this.uniform = uniform;
  16696. this.numPlanes = 0;
  16697. this.init = function( planes, enableLocalClipping, camera ) {
  16698. var enabled =
  16699. planes.length !== 0 ||
  16700. enableLocalClipping ||
  16701. // enable state of previous frame - the clipping code has to
  16702. // run another frame in order to reset the state:
  16703. numGlobalPlanes !== 0 ||
  16704. localClippingEnabled;
  16705. localClippingEnabled = enableLocalClipping;
  16706. globalState = projectPlanes( planes, camera, 0 );
  16707. numGlobalPlanes = planes.length;
  16708. return enabled;
  16709. };
  16710. this.beginShadows = function() {
  16711. renderingShadows = true;
  16712. projectPlanes( null );
  16713. };
  16714. this.endShadows = function() {
  16715. renderingShadows = false;
  16716. resetGlobalState();
  16717. };
  16718. this.setState = function( planes, clipShadows, camera, cache, fromCache ) {
  16719. if ( ! localClippingEnabled ||
  16720. planes === null || planes.length === 0 ||
  16721. renderingShadows && ! clipShadows ) {
  16722. // there's no local clipping
  16723. if ( renderingShadows ) {
  16724. // there's no global clipping
  16725. projectPlanes( null );
  16726. } else {
  16727. resetGlobalState();
  16728. }
  16729. } else {
  16730. var nGlobal = renderingShadows ? 0 : numGlobalPlanes,
  16731. lGlobal = nGlobal * 4,
  16732. dstArray = cache.clippingState || null;
  16733. uniform.value = dstArray; // ensure unique state
  16734. dstArray = projectPlanes( planes, camera, lGlobal, fromCache );
  16735. for ( var i = 0; i !== lGlobal; ++ i ) {
  16736. dstArray[ i ] = globalState[ i ];
  16737. }
  16738. cache.clippingState = dstArray;
  16739. this.numPlanes += nGlobal;
  16740. }
  16741. };
  16742. function resetGlobalState() {
  16743. if ( uniform.value !== globalState ) {
  16744. uniform.value = globalState;
  16745. uniform.needsUpdate = numGlobalPlanes > 0;
  16746. }
  16747. scope.numPlanes = numGlobalPlanes;
  16748. }
  16749. function projectPlanes( planes, camera, dstOffset, skipTransform ) {
  16750. var nPlanes = planes !== null ? planes.length : 0,
  16751. dstArray = null;
  16752. if ( nPlanes !== 0 ) {
  16753. dstArray = uniform.value;
  16754. if ( skipTransform !== true || dstArray === null ) {
  16755. var flatSize = dstOffset + nPlanes * 4,
  16756. viewMatrix = camera.matrixWorldInverse;
  16757. viewNormalMatrix.getNormalMatrix( viewMatrix );
  16758. if ( dstArray === null || dstArray.length < flatSize ) {
  16759. dstArray = new Float32Array( flatSize );
  16760. }
  16761. for ( var i = 0, i4 = dstOffset;
  16762. i !== nPlanes; ++ i, i4 += 4 ) {
  16763. plane.copy( planes[ i ] ).
  16764. applyMatrix4( viewMatrix, viewNormalMatrix );
  16765. plane.normal.toArray( dstArray, i4 );
  16766. dstArray[ i4 + 3 ] = plane.constant;
  16767. }
  16768. }
  16769. uniform.value = dstArray;
  16770. uniform.needsUpdate = true;
  16771. }
  16772. scope.numPlanes = nPlanes;
  16773. return dstArray;
  16774. }
  16775. };
  16776. // File:src/renderers/webgl/WebGLIndexedBufferRenderer.js
  16777. /**
  16778. * @author mrdoob / http://mrdoob.com/
  16779. */
  16780. THREE.WebGLIndexedBufferRenderer = function ( _gl, extensions, _infoRender ) {
  16781. var mode;
  16782. function setMode( value ) {
  16783. mode = value;
  16784. }
  16785. var type, size;
  16786. function setIndex( index ) {
  16787. if ( index.array instanceof Uint32Array && extensions.get( 'OES_element_index_uint' ) ) {
  16788. type = _gl.UNSIGNED_INT;
  16789. size = 4;
  16790. } else {
  16791. type = _gl.UNSIGNED_SHORT;
  16792. size = 2;
  16793. }
  16794. }
  16795. function render( start, count ) {
  16796. _gl.drawElements( mode, count, type, start * size );
  16797. _infoRender.calls ++;
  16798. _infoRender.vertices += count;
  16799. if ( mode === _gl.TRIANGLES ) _infoRender.faces += count / 3;
  16800. }
  16801. function renderInstances( geometry, start, count ) {
  16802. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  16803. if ( extension === null ) {
  16804. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  16805. return;
  16806. }
  16807. extension.drawElementsInstancedANGLE( mode, count, type, start * size, geometry.maxInstancedCount );
  16808. _infoRender.calls ++;
  16809. _infoRender.vertices += count * geometry.maxInstancedCount;
  16810. if ( mode === _gl.TRIANGLES ) _infoRender.faces += geometry.maxInstancedCount * count / 3;
  16811. }
  16812. this.setMode = setMode;
  16813. this.setIndex = setIndex;
  16814. this.render = render;
  16815. this.renderInstances = renderInstances;
  16816. };
  16817. // File:src/renderers/webgl/WebGLExtensions.js
  16818. /**
  16819. * @author mrdoob / http://mrdoob.com/
  16820. */
  16821. THREE.WebGLExtensions = function ( gl ) {
  16822. var extensions = {};
  16823. this.get = function ( name ) {
  16824. if ( extensions[ name ] !== undefined ) {
  16825. return extensions[ name ];
  16826. }
  16827. var extension;
  16828. switch ( name ) {
  16829. case 'WEBGL_depth_texture':
  16830. extension = gl.getExtension( 'WEBGL_depth_texture' ) || gl.getExtension( 'MOZ_WEBGL_depth_texture' ) || gl.getExtension( 'WEBKIT_WEBGL_depth_texture' );
  16831. break;
  16832. case 'EXT_texture_filter_anisotropic':
  16833. extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' );
  16834. break;
  16835. case 'WEBGL_compressed_texture_s3tc':
  16836. extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' );
  16837. break;
  16838. case 'WEBGL_compressed_texture_pvrtc':
  16839. extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' );
  16840. break;
  16841. case 'WEBGL_compressed_texture_etc1':
  16842. extension = gl.getExtension( 'WEBGL_compressed_texture_etc1' );
  16843. break;
  16844. default:
  16845. extension = gl.getExtension( name );
  16846. }
  16847. if ( extension === null ) {
  16848. console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
  16849. }
  16850. extensions[ name ] = extension;
  16851. return extension;
  16852. };
  16853. };
  16854. // File:src/renderers/webgl/WebGLCapabilities.js
  16855. THREE.WebGLCapabilities = function ( gl, extensions, parameters ) {
  16856. function getMaxPrecision( precision ) {
  16857. if ( precision === 'highp' ) {
  16858. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.HIGH_FLOAT ).precision > 0 &&
  16859. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.HIGH_FLOAT ).precision > 0 ) {
  16860. return 'highp';
  16861. }
  16862. precision = 'mediump';
  16863. }
  16864. if ( precision === 'mediump' ) {
  16865. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.MEDIUM_FLOAT ).precision > 0 &&
  16866. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.MEDIUM_FLOAT ).precision > 0 ) {
  16867. return 'mediump';
  16868. }
  16869. }
  16870. return 'lowp';
  16871. }
  16872. this.getMaxPrecision = getMaxPrecision;
  16873. this.precision = parameters.precision !== undefined ? parameters.precision : 'highp';
  16874. this.logarithmicDepthBuffer = parameters.logarithmicDepthBuffer !== undefined ? parameters.logarithmicDepthBuffer : false;
  16875. this.maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
  16876. this.maxVertexTextures = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS );
  16877. this.maxTextureSize = gl.getParameter( gl.MAX_TEXTURE_SIZE );
  16878. this.maxCubemapSize = gl.getParameter( gl.MAX_CUBE_MAP_TEXTURE_SIZE );
  16879. this.maxAttributes = gl.getParameter( gl.MAX_VERTEX_ATTRIBS );
  16880. this.maxVertexUniforms = gl.getParameter( gl.MAX_VERTEX_UNIFORM_VECTORS );
  16881. this.maxVaryings = gl.getParameter( gl.MAX_VARYING_VECTORS );
  16882. this.maxFragmentUniforms = gl.getParameter( gl.MAX_FRAGMENT_UNIFORM_VECTORS );
  16883. this.vertexTextures = this.maxVertexTextures > 0;
  16884. this.floatFragmentTextures = !! extensions.get( 'OES_texture_float' );
  16885. this.floatVertexTextures = this.vertexTextures && this.floatFragmentTextures;
  16886. var _maxPrecision = getMaxPrecision( this.precision );
  16887. if ( _maxPrecision !== this.precision ) {
  16888. console.warn( 'THREE.WebGLRenderer:', this.precision, 'not supported, using', _maxPrecision, 'instead.' );
  16889. this.precision = _maxPrecision;
  16890. }
  16891. if ( this.logarithmicDepthBuffer ) {
  16892. this.logarithmicDepthBuffer = !! extensions.get( 'EXT_frag_depth' );
  16893. }
  16894. };
  16895. // File:src/renderers/webgl/WebGLGeometries.js
  16896. /**
  16897. * @author mrdoob / http://mrdoob.com/
  16898. */
  16899. THREE.WebGLGeometries = function ( gl, properties, info ) {
  16900. var geometries = {};
  16901. function get( object ) {
  16902. var geometry = object.geometry;
  16903. if ( geometries[ geometry.id ] !== undefined ) {
  16904. return geometries[ geometry.id ];
  16905. }
  16906. geometry.addEventListener( 'dispose', onGeometryDispose );
  16907. var buffergeometry;
  16908. if ( geometry instanceof THREE.BufferGeometry ) {
  16909. buffergeometry = geometry;
  16910. } else if ( geometry instanceof THREE.Geometry ) {
  16911. if ( geometry._bufferGeometry === undefined ) {
  16912. geometry._bufferGeometry = new THREE.BufferGeometry().setFromObject( object );
  16913. }
  16914. buffergeometry = geometry._bufferGeometry;
  16915. }
  16916. geometries[ geometry.id ] = buffergeometry;
  16917. info.memory.geometries ++;
  16918. return buffergeometry;
  16919. }
  16920. function onGeometryDispose( event ) {
  16921. var geometry = event.target;
  16922. var buffergeometry = geometries[ geometry.id ];
  16923. if ( buffergeometry.index !== null ) {
  16924. deleteAttribute( buffergeometry.index );
  16925. }
  16926. deleteAttributes( buffergeometry.attributes );
  16927. geometry.removeEventListener( 'dispose', onGeometryDispose );
  16928. delete geometries[ geometry.id ];
  16929. // TODO
  16930. var property = properties.get( geometry );
  16931. if ( property.wireframe ) {
  16932. deleteAttribute( property.wireframe );
  16933. }
  16934. properties.delete( geometry );
  16935. var bufferproperty = properties.get( buffergeometry );
  16936. if ( bufferproperty.wireframe ) {
  16937. deleteAttribute( bufferproperty.wireframe );
  16938. }
  16939. properties.delete( buffergeometry );
  16940. //
  16941. info.memory.geometries --;
  16942. }
  16943. function getAttributeBuffer( attribute ) {
  16944. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  16945. return properties.get( attribute.data ).__webglBuffer;
  16946. }
  16947. return properties.get( attribute ).__webglBuffer;
  16948. }
  16949. function deleteAttribute( attribute ) {
  16950. var buffer = getAttributeBuffer( attribute );
  16951. if ( buffer !== undefined ) {
  16952. gl.deleteBuffer( buffer );
  16953. removeAttributeBuffer( attribute );
  16954. }
  16955. }
  16956. function deleteAttributes( attributes ) {
  16957. for ( var name in attributes ) {
  16958. deleteAttribute( attributes[ name ] );
  16959. }
  16960. }
  16961. function removeAttributeBuffer( attribute ) {
  16962. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  16963. properties.delete( attribute.data );
  16964. } else {
  16965. properties.delete( attribute );
  16966. }
  16967. }
  16968. this.get = get;
  16969. };
  16970. // File:src/renderers/webgl/WebGLLights.js
  16971. /**
  16972. * @author mrdoob / http://mrdoob.com/
  16973. */
  16974. THREE.WebGLLights = function () {
  16975. var lights = {};
  16976. this.get = function ( light ) {
  16977. if ( lights[ light.id ] !== undefined ) {
  16978. return lights[ light.id ];
  16979. }
  16980. var uniforms;
  16981. switch ( light.type ) {
  16982. case 'DirectionalLight':
  16983. uniforms = {
  16984. direction: new THREE.Vector3(),
  16985. color: new THREE.Color(),
  16986. shadow: false,
  16987. shadowBias: 0,
  16988. shadowRadius: 1,
  16989. shadowMapSize: new THREE.Vector2()
  16990. };
  16991. break;
  16992. case 'SpotLight':
  16993. uniforms = {
  16994. position: new THREE.Vector3(),
  16995. direction: new THREE.Vector3(),
  16996. color: new THREE.Color(),
  16997. distance: 0,
  16998. coneCos: 0,
  16999. penumbraCos: 0,
  17000. decay: 0,
  17001. shadow: false,
  17002. shadowBias: 0,
  17003. shadowRadius: 1,
  17004. shadowMapSize: new THREE.Vector2()
  17005. };
  17006. break;
  17007. case 'PointLight':
  17008. uniforms = {
  17009. position: new THREE.Vector3(),
  17010. color: new THREE.Color(),
  17011. distance: 0,
  17012. decay: 0,
  17013. shadow: false,
  17014. shadowBias: 0,
  17015. shadowRadius: 1,
  17016. shadowMapSize: new THREE.Vector2()
  17017. };
  17018. break;
  17019. case 'HemisphereLight':
  17020. uniforms = {
  17021. direction: new THREE.Vector3(),
  17022. skyColor: new THREE.Color(),
  17023. groundColor: new THREE.Color()
  17024. };
  17025. break;
  17026. }
  17027. lights[ light.id ] = uniforms;
  17028. return uniforms;
  17029. };
  17030. };
  17031. // File:src/renderers/webgl/WebGLObjects.js
  17032. /**
  17033. * @author mrdoob / http://mrdoob.com/
  17034. */
  17035. THREE.WebGLObjects = function ( gl, properties, info ) {
  17036. var geometries = new THREE.WebGLGeometries( gl, properties, info );
  17037. //
  17038. function update( object ) {
  17039. // TODO: Avoid updating twice (when using shadowMap). Maybe add frame counter.
  17040. var geometry = geometries.get( object );
  17041. if ( object.geometry instanceof THREE.Geometry ) {
  17042. geometry.updateFromObject( object );
  17043. }
  17044. var index = geometry.index;
  17045. var attributes = geometry.attributes;
  17046. if ( index !== null ) {
  17047. updateAttribute( index, gl.ELEMENT_ARRAY_BUFFER );
  17048. }
  17049. for ( var name in attributes ) {
  17050. updateAttribute( attributes[ name ], gl.ARRAY_BUFFER );
  17051. }
  17052. // morph targets
  17053. var morphAttributes = geometry.morphAttributes;
  17054. for ( var name in morphAttributes ) {
  17055. var array = morphAttributes[ name ];
  17056. for ( var i = 0, l = array.length; i < l; i ++ ) {
  17057. updateAttribute( array[ i ], gl.ARRAY_BUFFER );
  17058. }
  17059. }
  17060. return geometry;
  17061. }
  17062. function updateAttribute( attribute, bufferType ) {
  17063. var data = ( attribute instanceof THREE.InterleavedBufferAttribute ) ? attribute.data : attribute;
  17064. var attributeProperties = properties.get( data );
  17065. if ( attributeProperties.__webglBuffer === undefined ) {
  17066. createBuffer( attributeProperties, data, bufferType );
  17067. } else if ( attributeProperties.version !== data.version ) {
  17068. updateBuffer( attributeProperties, data, bufferType );
  17069. }
  17070. }
  17071. function createBuffer( attributeProperties, data, bufferType ) {
  17072. attributeProperties.__webglBuffer = gl.createBuffer();
  17073. gl.bindBuffer( bufferType, attributeProperties.__webglBuffer );
  17074. var usage = data.dynamic ? gl.DYNAMIC_DRAW : gl.STATIC_DRAW;
  17075. gl.bufferData( bufferType, data.array, usage );
  17076. attributeProperties.version = data.version;
  17077. }
  17078. function updateBuffer( attributeProperties, data, bufferType ) {
  17079. gl.bindBuffer( bufferType, attributeProperties.__webglBuffer );
  17080. if ( data.dynamic === false || data.updateRange.count === - 1 ) {
  17081. // Not using update ranges
  17082. gl.bufferSubData( bufferType, 0, data.array );
  17083. } else if ( data.updateRange.count === 0 ) {
  17084. 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.' );
  17085. } else {
  17086. gl.bufferSubData( bufferType, data.updateRange.offset * data.array.BYTES_PER_ELEMENT,
  17087. data.array.subarray( data.updateRange.offset, data.updateRange.offset + data.updateRange.count ) );
  17088. data.updateRange.count = 0; // reset range
  17089. }
  17090. attributeProperties.version = data.version;
  17091. }
  17092. function getAttributeBuffer( attribute ) {
  17093. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  17094. return properties.get( attribute.data ).__webglBuffer;
  17095. }
  17096. return properties.get( attribute ).__webglBuffer;
  17097. }
  17098. function getWireframeAttribute( geometry ) {
  17099. var property = properties.get( geometry );
  17100. if ( property.wireframe !== undefined ) {
  17101. return property.wireframe;
  17102. }
  17103. var indices = [];
  17104. var index = geometry.index;
  17105. var attributes = geometry.attributes;
  17106. var position = attributes.position;
  17107. // console.time( 'wireframe' );
  17108. if ( index !== null ) {
  17109. var edges = {};
  17110. var array = index.array;
  17111. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  17112. var a = array[ i + 0 ];
  17113. var b = array[ i + 1 ];
  17114. var c = array[ i + 2 ];
  17115. if ( checkEdge( edges, a, b ) ) indices.push( a, b );
  17116. if ( checkEdge( edges, b, c ) ) indices.push( b, c );
  17117. if ( checkEdge( edges, c, a ) ) indices.push( c, a );
  17118. }
  17119. } else {
  17120. var array = attributes.position.array;
  17121. for ( var i = 0, l = ( array.length / 3 ) - 1; i < l; i += 3 ) {
  17122. var a = i + 0;
  17123. var b = i + 1;
  17124. var c = i + 2;
  17125. indices.push( a, b, b, c, c, a );
  17126. }
  17127. }
  17128. // console.timeEnd( 'wireframe' );
  17129. var TypeArray = position.count > 65535 ? Uint32Array : Uint16Array;
  17130. var attribute = new THREE.BufferAttribute( new TypeArray( indices ), 1 );
  17131. updateAttribute( attribute, gl.ELEMENT_ARRAY_BUFFER );
  17132. property.wireframe = attribute;
  17133. return attribute;
  17134. }
  17135. function checkEdge( edges, a, b ) {
  17136. if ( a > b ) {
  17137. var tmp = a;
  17138. a = b;
  17139. b = tmp;
  17140. }
  17141. var list = edges[ a ];
  17142. if ( list === undefined ) {
  17143. edges[ a ] = [ b ];
  17144. return true;
  17145. } else if ( list.indexOf( b ) === -1 ) {
  17146. list.push( b );
  17147. return true;
  17148. }
  17149. return false;
  17150. }
  17151. this.getAttributeBuffer = getAttributeBuffer;
  17152. this.getWireframeAttribute = getWireframeAttribute;
  17153. this.update = update;
  17154. };
  17155. // File:src/renderers/webgl/WebGLProgram.js
  17156. THREE.WebGLProgram = ( function () {
  17157. var programIdCount = 0;
  17158. function getEncodingComponents( encoding ) {
  17159. switch ( encoding ) {
  17160. case THREE.LinearEncoding:
  17161. return [ 'Linear','( value )' ];
  17162. case THREE.sRGBEncoding:
  17163. return [ 'sRGB','( value )' ];
  17164. case THREE.RGBEEncoding:
  17165. return [ 'RGBE','( value )' ];
  17166. case THREE.RGBM7Encoding:
  17167. return [ 'RGBM','( value, 7.0 )' ];
  17168. case THREE.RGBM16Encoding:
  17169. return [ 'RGBM','( value, 16.0 )' ];
  17170. case THREE.RGBDEncoding:
  17171. return [ 'RGBD','( value, 256.0 )' ];
  17172. case THREE.GammaEncoding:
  17173. return [ 'Gamma','( value, float( GAMMA_FACTOR ) )' ];
  17174. default:
  17175. throw new Error( 'unsupported encoding: ' + encoding );
  17176. }
  17177. }
  17178. function getTexelDecodingFunction( functionName, encoding ) {
  17179. var components = getEncodingComponents( encoding );
  17180. return "vec4 " + functionName + "( vec4 value ) { return " + components[ 0 ] + "ToLinear" + components[ 1 ] + "; }";
  17181. }
  17182. function getTexelEncodingFunction( functionName, encoding ) {
  17183. var components = getEncodingComponents( encoding );
  17184. return "vec4 " + functionName + "( vec4 value ) { return LinearTo" + components[ 0 ] + components[ 1 ] + "; }";
  17185. }
  17186. function getToneMappingFunction( functionName, toneMapping ) {
  17187. var toneMappingName;
  17188. switch ( toneMapping ) {
  17189. case THREE.LinearToneMapping:
  17190. toneMappingName = "Linear";
  17191. break;
  17192. case THREE.ReinhardToneMapping:
  17193. toneMappingName = "Reinhard";
  17194. break;
  17195. case THREE.Uncharted2ToneMapping:
  17196. toneMappingName = "Uncharted2";
  17197. break;
  17198. case THREE.CineonToneMapping:
  17199. toneMappingName = "OptimizedCineon";
  17200. break;
  17201. default:
  17202. throw new Error( 'unsupported toneMapping: ' + toneMapping );
  17203. }
  17204. return "vec3 " + functionName + "( vec3 color ) { return " + toneMappingName + "ToneMapping( color ); }";
  17205. }
  17206. function generateExtensions( extensions, parameters, rendererExtensions ) {
  17207. extensions = extensions || {};
  17208. var chunks = [
  17209. ( extensions.derivatives || parameters.envMapCubeUV || parameters.bumpMap || parameters.normalMap || parameters.flatShading ) ? '#extension GL_OES_standard_derivatives : enable' : '',
  17210. ( extensions.fragDepth || parameters.logarithmicDepthBuffer ) && rendererExtensions.get( 'EXT_frag_depth' ) ? '#extension GL_EXT_frag_depth : enable' : '',
  17211. ( extensions.drawBuffers ) && rendererExtensions.get( 'WEBGL_draw_buffers' ) ? '#extension GL_EXT_draw_buffers : require' : '',
  17212. ( extensions.shaderTextureLOD || parameters.envMap ) && rendererExtensions.get( 'EXT_shader_texture_lod' ) ? '#extension GL_EXT_shader_texture_lod : enable' : '',
  17213. ];
  17214. return chunks.filter( filterEmptyLine ).join( '\n' );
  17215. }
  17216. function generateDefines( defines ) {
  17217. var chunks = [];
  17218. for ( var name in defines ) {
  17219. var value = defines[ name ];
  17220. if ( value === false ) continue;
  17221. chunks.push( '#define ' + name + ' ' + value );
  17222. }
  17223. return chunks.join( '\n' );
  17224. }
  17225. function fetchAttributeLocations( gl, program, identifiers ) {
  17226. var attributes = {};
  17227. var n = gl.getProgramParameter( program, gl.ACTIVE_ATTRIBUTES );
  17228. for ( var i = 0; i < n; i ++ ) {
  17229. var info = gl.getActiveAttrib( program, i );
  17230. var name = info.name;
  17231. // console.log("THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:", name, i );
  17232. attributes[ name ] = gl.getAttribLocation( program, name );
  17233. }
  17234. return attributes;
  17235. }
  17236. function filterEmptyLine( string ) {
  17237. return string !== '';
  17238. }
  17239. function replaceLightNums( string, parameters ) {
  17240. return string
  17241. .replace( /NUM_DIR_LIGHTS/g, parameters.numDirLights )
  17242. .replace( /NUM_SPOT_LIGHTS/g, parameters.numSpotLights )
  17243. .replace( /NUM_POINT_LIGHTS/g, parameters.numPointLights )
  17244. .replace( /NUM_HEMI_LIGHTS/g, parameters.numHemiLights );
  17245. }
  17246. function parseIncludes( string ) {
  17247. var pattern = /#include +<([\w\d.]+)>/g;
  17248. function replace( match, include ) {
  17249. var replace = THREE.ShaderChunk[ include ];
  17250. if ( replace === undefined ) {
  17251. throw new Error( 'Can not resolve #include <' + include + '>' );
  17252. }
  17253. return parseIncludes( replace );
  17254. }
  17255. return string.replace( pattern, replace );
  17256. }
  17257. function unrollLoops( string ) {
  17258. var pattern = /for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  17259. function replace( match, start, end, snippet ) {
  17260. var unroll = '';
  17261. for ( var i = parseInt( start ); i < parseInt( end ); i ++ ) {
  17262. unroll += snippet.replace( /\[ i \]/g, '[ ' + i + ' ]' );
  17263. }
  17264. return unroll;
  17265. }
  17266. return string.replace( pattern, replace );
  17267. }
  17268. return function WebGLProgram( renderer, code, material, parameters ) {
  17269. var gl = renderer.context;
  17270. var extensions = material.extensions;
  17271. var defines = material.defines;
  17272. var vertexShader = material.__webglShader.vertexShader;
  17273. var fragmentShader = material.__webglShader.fragmentShader;
  17274. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  17275. if ( parameters.shadowMapType === THREE.PCFShadowMap ) {
  17276. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  17277. } else if ( parameters.shadowMapType === THREE.PCFSoftShadowMap ) {
  17278. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  17279. }
  17280. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  17281. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  17282. var envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  17283. if ( parameters.envMap ) {
  17284. switch ( material.envMap.mapping ) {
  17285. case THREE.CubeReflectionMapping:
  17286. case THREE.CubeRefractionMapping:
  17287. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  17288. break;
  17289. case THREE.CubeUVReflectionMapping:
  17290. case THREE.CubeUVRefractionMapping:
  17291. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  17292. break;
  17293. case THREE.EquirectangularReflectionMapping:
  17294. case THREE.EquirectangularRefractionMapping:
  17295. envMapTypeDefine = 'ENVMAP_TYPE_EQUIREC';
  17296. break;
  17297. case THREE.SphericalReflectionMapping:
  17298. envMapTypeDefine = 'ENVMAP_TYPE_SPHERE';
  17299. break;
  17300. }
  17301. switch ( material.envMap.mapping ) {
  17302. case THREE.CubeRefractionMapping:
  17303. case THREE.EquirectangularRefractionMapping:
  17304. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  17305. break;
  17306. }
  17307. switch ( material.combine ) {
  17308. case THREE.MultiplyOperation:
  17309. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  17310. break;
  17311. case THREE.MixOperation:
  17312. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  17313. break;
  17314. case THREE.AddOperation:
  17315. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  17316. break;
  17317. }
  17318. }
  17319. var gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
  17320. // console.log( 'building new program ' );
  17321. //
  17322. var customExtensions = generateExtensions( extensions, parameters, renderer.extensions );
  17323. var customDefines = generateDefines( defines );
  17324. //
  17325. var program = gl.createProgram();
  17326. var prefixVertex, prefixFragment;
  17327. if ( material instanceof THREE.RawShaderMaterial ) {
  17328. prefixVertex = '';
  17329. prefixFragment = '';
  17330. } else {
  17331. prefixVertex = [
  17332. 'precision ' + parameters.precision + ' float;',
  17333. 'precision ' + parameters.precision + ' int;',
  17334. '#define SHADER_NAME ' + material.__webglShader.name,
  17335. customDefines,
  17336. parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '',
  17337. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  17338. '#define MAX_BONES ' + parameters.maxBones,
  17339. parameters.map ? '#define USE_MAP' : '',
  17340. parameters.envMap ? '#define USE_ENVMAP' : '',
  17341. parameters.envMap ? '#define ' + envMapModeDefine : '',
  17342. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  17343. parameters.aoMap ? '#define USE_AOMAP' : '',
  17344. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  17345. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  17346. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  17347. parameters.displacementMap && parameters.supportsVertexTextures ? '#define USE_DISPLACEMENTMAP' : '',
  17348. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  17349. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  17350. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  17351. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  17352. parameters.vertexColors ? '#define USE_COLOR' : '',
  17353. parameters.flatShading ? '#define FLAT_SHADED' : '',
  17354. parameters.skinning ? '#define USE_SKINNING' : '',
  17355. parameters.useVertexTexture ? '#define BONE_TEXTURE' : '',
  17356. parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
  17357. parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '',
  17358. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  17359. parameters.flipSided ? '#define FLIP_SIDED' : '',
  17360. '#define NUM_CLIPPING_PLANES ' + parameters.numClippingPlanes,
  17361. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  17362. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  17363. parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
  17364. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  17365. parameters.logarithmicDepthBuffer && renderer.extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  17366. 'uniform mat4 modelMatrix;',
  17367. 'uniform mat4 modelViewMatrix;',
  17368. 'uniform mat4 projectionMatrix;',
  17369. 'uniform mat4 viewMatrix;',
  17370. 'uniform mat3 normalMatrix;',
  17371. 'uniform vec3 cameraPosition;',
  17372. 'attribute vec3 position;',
  17373. 'attribute vec3 normal;',
  17374. 'attribute vec2 uv;',
  17375. '#ifdef USE_COLOR',
  17376. ' attribute vec3 color;',
  17377. '#endif',
  17378. '#ifdef USE_MORPHTARGETS',
  17379. ' attribute vec3 morphTarget0;',
  17380. ' attribute vec3 morphTarget1;',
  17381. ' attribute vec3 morphTarget2;',
  17382. ' attribute vec3 morphTarget3;',
  17383. ' #ifdef USE_MORPHNORMALS',
  17384. ' attribute vec3 morphNormal0;',
  17385. ' attribute vec3 morphNormal1;',
  17386. ' attribute vec3 morphNormal2;',
  17387. ' attribute vec3 morphNormal3;',
  17388. ' #else',
  17389. ' attribute vec3 morphTarget4;',
  17390. ' attribute vec3 morphTarget5;',
  17391. ' attribute vec3 morphTarget6;',
  17392. ' attribute vec3 morphTarget7;',
  17393. ' #endif',
  17394. '#endif',
  17395. '#ifdef USE_SKINNING',
  17396. ' attribute vec4 skinIndex;',
  17397. ' attribute vec4 skinWeight;',
  17398. '#endif',
  17399. '\n'
  17400. ].filter( filterEmptyLine ).join( '\n' );
  17401. prefixFragment = [
  17402. customExtensions,
  17403. 'precision ' + parameters.precision + ' float;',
  17404. 'precision ' + parameters.precision + ' int;',
  17405. '#define SHADER_NAME ' + material.__webglShader.name,
  17406. customDefines,
  17407. parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest : '',
  17408. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  17409. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  17410. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  17411. parameters.map ? '#define USE_MAP' : '',
  17412. parameters.envMap ? '#define USE_ENVMAP' : '',
  17413. parameters.envMap ? '#define ' + envMapTypeDefine : '',
  17414. parameters.envMap ? '#define ' + envMapModeDefine : '',
  17415. parameters.envMap ? '#define ' + envMapBlendingDefine : '',
  17416. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  17417. parameters.aoMap ? '#define USE_AOMAP' : '',
  17418. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  17419. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  17420. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  17421. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  17422. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  17423. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  17424. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  17425. parameters.vertexColors ? '#define USE_COLOR' : '',
  17426. parameters.flatShading ? '#define FLAT_SHADED' : '',
  17427. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  17428. parameters.flipSided ? '#define FLIP_SIDED' : '',
  17429. '#define NUM_CLIPPING_PLANES ' + parameters.numClippingPlanes,
  17430. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  17431. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  17432. parameters.premultipliedAlpha ? "#define PREMULTIPLIED_ALPHA" : '',
  17433. parameters.physicallyCorrectLights ? "#define PHYSICALLY_CORRECT_LIGHTS" : '',
  17434. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  17435. parameters.logarithmicDepthBuffer && renderer.extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  17436. parameters.envMap && renderer.extensions.get( 'EXT_shader_texture_lod' ) ? '#define TEXTURE_LOD_EXT' : '',
  17437. 'uniform mat4 viewMatrix;',
  17438. 'uniform vec3 cameraPosition;',
  17439. ( parameters.toneMapping !== THREE.NoToneMapping ) ? "#define TONE_MAPPING" : '',
  17440. ( parameters.toneMapping !== THREE.NoToneMapping ) ? THREE.ShaderChunk[ 'tonemapping_pars_fragment' ] : '', // this code is required here because it is used by the toneMapping() function defined below
  17441. ( parameters.toneMapping !== THREE.NoToneMapping ) ? getToneMappingFunction( "toneMapping", parameters.toneMapping ) : '',
  17442. ( parameters.outputEncoding || parameters.mapEncoding || parameters.envMapEncoding || parameters.emissiveMapEncoding ) ? THREE.ShaderChunk[ 'encodings_pars_fragment' ] : '', // this code is required here because it is used by the various encoding/decoding function defined below
  17443. parameters.mapEncoding ? getTexelDecodingFunction( 'mapTexelToLinear', parameters.mapEncoding ) : '',
  17444. parameters.envMapEncoding ? getTexelDecodingFunction( 'envMapTexelToLinear', parameters.envMapEncoding ) : '',
  17445. parameters.emissiveMapEncoding ? getTexelDecodingFunction( 'emissiveMapTexelToLinear', parameters.emissiveMapEncoding ) : '',
  17446. parameters.outputEncoding ? getTexelEncodingFunction( "linearToOutputTexel", parameters.outputEncoding ) : '',
  17447. parameters.depthPacking ? "#define DEPTH_PACKING " + material.depthPacking : '',
  17448. '\n'
  17449. ].filter( filterEmptyLine ).join( '\n' );
  17450. }
  17451. vertexShader = parseIncludes( vertexShader, parameters );
  17452. vertexShader = replaceLightNums( vertexShader, parameters );
  17453. fragmentShader = parseIncludes( fragmentShader, parameters );
  17454. fragmentShader = replaceLightNums( fragmentShader, parameters );
  17455. if ( material instanceof THREE.ShaderMaterial === false ) {
  17456. vertexShader = unrollLoops( vertexShader );
  17457. fragmentShader = unrollLoops( fragmentShader );
  17458. }
  17459. var vertexGlsl = prefixVertex + vertexShader;
  17460. var fragmentGlsl = prefixFragment + fragmentShader;
  17461. // console.log( '*VERTEX*', vertexGlsl );
  17462. // console.log( '*FRAGMENT*', fragmentGlsl );
  17463. var glVertexShader = THREE.WebGLShader( gl, gl.VERTEX_SHADER, vertexGlsl );
  17464. var glFragmentShader = THREE.WebGLShader( gl, gl.FRAGMENT_SHADER, fragmentGlsl );
  17465. gl.attachShader( program, glVertexShader );
  17466. gl.attachShader( program, glFragmentShader );
  17467. // Force a particular attribute to index 0.
  17468. if ( material.index0AttributeName !== undefined ) {
  17469. gl.bindAttribLocation( program, 0, material.index0AttributeName );
  17470. } else if ( parameters.morphTargets === true ) {
  17471. // programs with morphTargets displace position out of attribute 0
  17472. gl.bindAttribLocation( program, 0, 'position' );
  17473. }
  17474. gl.linkProgram( program );
  17475. var programLog = gl.getProgramInfoLog( program );
  17476. var vertexLog = gl.getShaderInfoLog( glVertexShader );
  17477. var fragmentLog = gl.getShaderInfoLog( glFragmentShader );
  17478. var runnable = true;
  17479. var haveDiagnostics = true;
  17480. // console.log( '**VERTEX**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( glVertexShader ) );
  17481. // console.log( '**FRAGMENT**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( glFragmentShader ) );
  17482. if ( gl.getProgramParameter( program, gl.LINK_STATUS ) === false ) {
  17483. runnable = false;
  17484. console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), 'gl.VALIDATE_STATUS', gl.getProgramParameter( program, gl.VALIDATE_STATUS ), 'gl.getProgramInfoLog', programLog, vertexLog, fragmentLog );
  17485. } else if ( programLog !== '' ) {
  17486. console.warn( 'THREE.WebGLProgram: gl.getProgramInfoLog()', programLog );
  17487. } else if ( vertexLog === '' || fragmentLog === '' ) {
  17488. haveDiagnostics = false;
  17489. }
  17490. if ( haveDiagnostics ) {
  17491. this.diagnostics = {
  17492. runnable: runnable,
  17493. material: material,
  17494. programLog: programLog,
  17495. vertexShader: {
  17496. log: vertexLog,
  17497. prefix: prefixVertex
  17498. },
  17499. fragmentShader: {
  17500. log: fragmentLog,
  17501. prefix: prefixFragment
  17502. }
  17503. };
  17504. }
  17505. // clean up
  17506. gl.deleteShader( glVertexShader );
  17507. gl.deleteShader( glFragmentShader );
  17508. // set up caching for uniform locations
  17509. var cachedUniforms;
  17510. this.getUniforms = function() {
  17511. if ( cachedUniforms === undefined ) {
  17512. cachedUniforms =
  17513. new THREE.WebGLUniforms( gl, program, renderer );
  17514. }
  17515. return cachedUniforms;
  17516. };
  17517. // set up caching for attribute locations
  17518. var cachedAttributes;
  17519. this.getAttributes = function() {
  17520. if ( cachedAttributes === undefined ) {
  17521. cachedAttributes = fetchAttributeLocations( gl, program );
  17522. }
  17523. return cachedAttributes;
  17524. };
  17525. // free resource
  17526. this.destroy = function() {
  17527. gl.deleteProgram( program );
  17528. this.program = undefined;
  17529. };
  17530. // DEPRECATED
  17531. Object.defineProperties( this, {
  17532. uniforms: {
  17533. get: function() {
  17534. console.warn( 'THREE.WebGLProgram: .uniforms is now .getUniforms().' );
  17535. return this.getUniforms();
  17536. }
  17537. },
  17538. attributes: {
  17539. get: function() {
  17540. console.warn( 'THREE.WebGLProgram: .attributes is now .getAttributes().' );
  17541. return this.getAttributes();
  17542. }
  17543. }
  17544. } );
  17545. //
  17546. this.id = programIdCount ++;
  17547. this.code = code;
  17548. this.usedTimes = 1;
  17549. this.program = program;
  17550. this.vertexShader = glVertexShader;
  17551. this.fragmentShader = glFragmentShader;
  17552. return this;
  17553. };
  17554. } )();
  17555. // File:src/renderers/webgl/WebGLPrograms.js
  17556. THREE.WebGLPrograms = function ( renderer, capabilities ) {
  17557. var programs = [];
  17558. var shaderIDs = {
  17559. MeshDepthMaterial: 'depth',
  17560. MeshNormalMaterial: 'normal',
  17561. MeshBasicMaterial: 'basic',
  17562. MeshLambertMaterial: 'lambert',
  17563. MeshPhongMaterial: 'phong',
  17564. MeshStandardMaterial: 'physical',
  17565. MeshPhysicalMaterial: 'physical',
  17566. LineBasicMaterial: 'basic',
  17567. LineDashedMaterial: 'dashed',
  17568. PointsMaterial: 'points'
  17569. };
  17570. var parameterNames = [
  17571. "precision", "supportsVertexTextures", "map", "mapEncoding", "envMap", "envMapMode", "envMapEncoding",
  17572. "lightMap", "aoMap", "emissiveMap", "emissiveMapEncoding", "bumpMap", "normalMap", "displacementMap", "specularMap",
  17573. "roughnessMap", "metalnessMap",
  17574. "alphaMap", "combine", "vertexColors", "fog", "useFog", "fogExp",
  17575. "flatShading", "sizeAttenuation", "logarithmicDepthBuffer", "skinning",
  17576. "maxBones", "useVertexTexture", "morphTargets", "morphNormals",
  17577. "maxMorphTargets", "maxMorphNormals", "premultipliedAlpha",
  17578. "numDirLights", "numPointLights", "numSpotLights", "numHemiLights",
  17579. "shadowMapEnabled", "shadowMapType", "toneMapping", 'physicallyCorrectLights',
  17580. "alphaTest", "doubleSided", "flipSided", "numClippingPlanes", "depthPacking"
  17581. ];
  17582. function allocateBones ( object ) {
  17583. if ( capabilities.floatVertexTextures && object && object.skeleton && object.skeleton.useVertexTexture ) {
  17584. return 1024;
  17585. } else {
  17586. // default for when object is not specified
  17587. // ( for example when prebuilding shader to be used with multiple objects )
  17588. //
  17589. // - leave some extra space for other uniforms
  17590. // - limit here is ANGLE's 254 max uniform vectors
  17591. // (up to 54 should be safe)
  17592. var nVertexUniforms = capabilities.maxVertexUniforms;
  17593. var nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 );
  17594. var maxBones = nVertexMatrices;
  17595. if ( object !== undefined && object instanceof THREE.SkinnedMesh ) {
  17596. maxBones = Math.min( object.skeleton.bones.length, maxBones );
  17597. if ( maxBones < object.skeleton.bones.length ) {
  17598. console.warn( 'WebGLRenderer: too many bones - ' + object.skeleton.bones.length + ', this GPU supports just ' + maxBones + ' (try OpenGL instead of ANGLE)' );
  17599. }
  17600. }
  17601. return maxBones;
  17602. }
  17603. }
  17604. function getTextureEncodingFromMap( map, gammaOverrideLinear ) {
  17605. var encoding;
  17606. if ( ! map ) {
  17607. encoding = THREE.LinearEncoding;
  17608. } else if ( map instanceof THREE.Texture ) {
  17609. encoding = map.encoding;
  17610. } else if ( map instanceof THREE.WebGLRenderTarget ) {
  17611. console.warn( "THREE.WebGLPrograms.getTextureEncodingFromMap: don't use render targets as textures. Use their .texture property instead." );
  17612. encoding = map.texture.encoding;
  17613. }
  17614. // add backwards compatibility for WebGLRenderer.gammaInput/gammaOutput parameter, should probably be removed at some point.
  17615. if ( encoding === THREE.LinearEncoding && gammaOverrideLinear ) {
  17616. encoding = THREE.GammaEncoding;
  17617. }
  17618. return encoding;
  17619. }
  17620. this.getParameters = function ( material, lights, fog, nClipPlanes, object ) {
  17621. var shaderID = shaderIDs[ material.type ];
  17622. // heuristics to create shader parameters according to lights in the scene
  17623. // (not to blow over maxLights budget)
  17624. var maxBones = allocateBones( object );
  17625. var precision = renderer.getPrecision();
  17626. if ( material.precision !== null ) {
  17627. precision = capabilities.getMaxPrecision( material.precision );
  17628. if ( precision !== material.precision ) {
  17629. console.warn( 'THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.' );
  17630. }
  17631. }
  17632. var currentRenderTarget = renderer.getCurrentRenderTarget();
  17633. var parameters = {
  17634. shaderID: shaderID,
  17635. precision: precision,
  17636. supportsVertexTextures: capabilities.vertexTextures,
  17637. outputEncoding: getTextureEncodingFromMap( ( ! currentRenderTarget ) ? null : currentRenderTarget.texture, renderer.gammaOutput ),
  17638. map: !! material.map,
  17639. mapEncoding: getTextureEncodingFromMap( material.map, renderer.gammaInput ),
  17640. envMap: !! material.envMap,
  17641. envMapMode: material.envMap && material.envMap.mapping,
  17642. envMapEncoding: getTextureEncodingFromMap( material.envMap, renderer.gammaInput ),
  17643. envMapCubeUV: ( !! material.envMap ) && ( ( material.envMap.mapping === THREE.CubeUVReflectionMapping ) || ( material.envMap.mapping === THREE.CubeUVRefractionMapping ) ),
  17644. lightMap: !! material.lightMap,
  17645. aoMap: !! material.aoMap,
  17646. emissiveMap: !! material.emissiveMap,
  17647. emissiveMapEncoding: getTextureEncodingFromMap( material.emissiveMap, renderer.gammaInput ),
  17648. bumpMap: !! material.bumpMap,
  17649. normalMap: !! material.normalMap,
  17650. displacementMap: !! material.displacementMap,
  17651. roughnessMap: !! material.roughnessMap,
  17652. metalnessMap: !! material.metalnessMap,
  17653. specularMap: !! material.specularMap,
  17654. alphaMap: !! material.alphaMap,
  17655. combine: material.combine,
  17656. vertexColors: material.vertexColors,
  17657. fog: fog,
  17658. useFog: material.fog,
  17659. fogExp: fog instanceof THREE.FogExp2,
  17660. flatShading: material.shading === THREE.FlatShading,
  17661. sizeAttenuation: material.sizeAttenuation,
  17662. logarithmicDepthBuffer: capabilities.logarithmicDepthBuffer,
  17663. skinning: material.skinning,
  17664. maxBones: maxBones,
  17665. useVertexTexture: capabilities.floatVertexTextures && object && object.skeleton && object.skeleton.useVertexTexture,
  17666. morphTargets: material.morphTargets,
  17667. morphNormals: material.morphNormals,
  17668. maxMorphTargets: renderer.maxMorphTargets,
  17669. maxMorphNormals: renderer.maxMorphNormals,
  17670. numDirLights: lights.directional.length,
  17671. numPointLights: lights.point.length,
  17672. numSpotLights: lights.spot.length,
  17673. numHemiLights: lights.hemi.length,
  17674. numClippingPlanes: nClipPlanes,
  17675. shadowMapEnabled: renderer.shadowMap.enabled && object.receiveShadow && lights.shadows.length > 0,
  17676. shadowMapType: renderer.shadowMap.type,
  17677. toneMapping: renderer.toneMapping,
  17678. physicallyCorrectLights: renderer.physicallyCorrectLights,
  17679. premultipliedAlpha: material.premultipliedAlpha,
  17680. alphaTest: material.alphaTest,
  17681. doubleSided: material.side === THREE.DoubleSide,
  17682. flipSided: material.side === THREE.BackSide,
  17683. depthPacking: ( material.depthPacking !== undefined ) ? material.depthPacking : false
  17684. };
  17685. return parameters;
  17686. };
  17687. this.getProgramCode = function ( material, parameters ) {
  17688. var array = [];
  17689. if ( parameters.shaderID ) {
  17690. array.push( parameters.shaderID );
  17691. } else {
  17692. array.push( material.fragmentShader );
  17693. array.push( material.vertexShader );
  17694. }
  17695. if ( material.defines !== undefined ) {
  17696. for ( var name in material.defines ) {
  17697. array.push( name );
  17698. array.push( material.defines[ name ] );
  17699. }
  17700. }
  17701. for ( var i = 0; i < parameterNames.length; i ++ ) {
  17702. array.push( parameters[ parameterNames[ i ] ] );
  17703. }
  17704. return array.join();
  17705. };
  17706. this.acquireProgram = function ( material, parameters, code ) {
  17707. var program;
  17708. // Check if code has been already compiled
  17709. for ( var p = 0, pl = programs.length; p < pl; p ++ ) {
  17710. var programInfo = programs[ p ];
  17711. if ( programInfo.code === code ) {
  17712. program = programInfo;
  17713. ++ program.usedTimes;
  17714. break;
  17715. }
  17716. }
  17717. if ( program === undefined ) {
  17718. program = new THREE.WebGLProgram( renderer, code, material, parameters );
  17719. programs.push( program );
  17720. }
  17721. return program;
  17722. };
  17723. this.releaseProgram = function( program ) {
  17724. if ( -- program.usedTimes === 0 ) {
  17725. // Remove from unordered set
  17726. var i = programs.indexOf( program );
  17727. programs[ i ] = programs[ programs.length - 1 ];
  17728. programs.pop();
  17729. // Free WebGL resources
  17730. program.destroy();
  17731. }
  17732. };
  17733. // Exposed for resource monitoring & error feedback via renderer.info:
  17734. this.programs = programs;
  17735. };
  17736. // File:src/renderers/webgl/WebGLProperties.js
  17737. /**
  17738. * @author fordacious / fordacious.github.io
  17739. */
  17740. THREE.WebGLProperties = function () {
  17741. var properties = {};
  17742. this.get = function ( object ) {
  17743. var uuid = object.uuid;
  17744. var map = properties[ uuid ];
  17745. if ( map === undefined ) {
  17746. map = {};
  17747. properties[ uuid ] = map;
  17748. }
  17749. return map;
  17750. };
  17751. this.delete = function ( object ) {
  17752. delete properties[ object.uuid ];
  17753. };
  17754. this.clear = function () {
  17755. properties = {};
  17756. };
  17757. };
  17758. // File:src/renderers/webgl/WebGLShader.js
  17759. THREE.WebGLShader = ( function () {
  17760. function addLineNumbers( string ) {
  17761. var lines = string.split( '\n' );
  17762. for ( var i = 0; i < lines.length; i ++ ) {
  17763. lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
  17764. }
  17765. return lines.join( '\n' );
  17766. }
  17767. return function WebGLShader( gl, type, string ) {
  17768. var shader = gl.createShader( type );
  17769. gl.shaderSource( shader, string );
  17770. gl.compileShader( shader );
  17771. if ( gl.getShaderParameter( shader, gl.COMPILE_STATUS ) === false ) {
  17772. console.error( 'THREE.WebGLShader: Shader couldn\'t compile.' );
  17773. }
  17774. if ( gl.getShaderInfoLog( shader ) !== '' ) {
  17775. console.warn( 'THREE.WebGLShader: gl.getShaderInfoLog()', type === gl.VERTEX_SHADER ? 'vertex' : 'fragment', gl.getShaderInfoLog( shader ), addLineNumbers( string ) );
  17776. }
  17777. // --enable-privileged-webgl-extension
  17778. // console.log( type, gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  17779. return shader;
  17780. };
  17781. } )();
  17782. // File:src/renderers/webgl/WebGLShadowMap.js
  17783. /**
  17784. * @author alteredq / http://alteredqualia.com/
  17785. * @author mrdoob / http://mrdoob.com/
  17786. */
  17787. THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
  17788. var _gl = _renderer.context,
  17789. _state = _renderer.state,
  17790. _frustum = new THREE.Frustum(),
  17791. _projScreenMatrix = new THREE.Matrix4(),
  17792. _lightShadows = _lights.shadows,
  17793. _shadowMapSize = new THREE.Vector2(),
  17794. _lookTarget = new THREE.Vector3(),
  17795. _lightPositionWorld = new THREE.Vector3(),
  17796. _renderList = [],
  17797. _MorphingFlag = 1,
  17798. _SkinningFlag = 2,
  17799. _NumberOfMaterialVariants = ( _MorphingFlag | _SkinningFlag ) + 1,
  17800. _depthMaterials = new Array( _NumberOfMaterialVariants ),
  17801. _distanceMaterials = new Array( _NumberOfMaterialVariants ),
  17802. _materialCache = {};
  17803. var cubeDirections = [
  17804. new THREE.Vector3( 1, 0, 0 ), new THREE.Vector3( - 1, 0, 0 ), new THREE.Vector3( 0, 0, 1 ),
  17805. new THREE.Vector3( 0, 0, - 1 ), new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, - 1, 0 )
  17806. ];
  17807. var cubeUps = [
  17808. new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 1, 0 ),
  17809. new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 0, 1 ), new THREE.Vector3( 0, 0, - 1 )
  17810. ];
  17811. var cube2DViewPorts = [
  17812. new THREE.Vector4(), new THREE.Vector4(), new THREE.Vector4(),
  17813. new THREE.Vector4(), new THREE.Vector4(), new THREE.Vector4()
  17814. ];
  17815. // init
  17816. var depthMaterialTemplate = new THREE.MeshDepthMaterial();
  17817. depthMaterialTemplate.depthPacking = THREE.RGBADepthPacking;
  17818. depthMaterialTemplate.clipping = true;
  17819. var distanceShader = THREE.ShaderLib[ "distanceRGBA" ];
  17820. var distanceUniforms = THREE.UniformsUtils.clone( distanceShader.uniforms );
  17821. for ( var i = 0; i !== _NumberOfMaterialVariants; ++ i ) {
  17822. var useMorphing = ( i & _MorphingFlag ) !== 0;
  17823. var useSkinning = ( i & _SkinningFlag ) !== 0;
  17824. var depthMaterial = depthMaterialTemplate.clone();
  17825. depthMaterial.morphTargets = useMorphing;
  17826. depthMaterial.skinning = useSkinning;
  17827. _depthMaterials[ i ] = depthMaterial;
  17828. var distanceMaterial = new THREE.ShaderMaterial( {
  17829. defines: {
  17830. 'USE_SHADOWMAP': ''
  17831. },
  17832. uniforms: distanceUniforms,
  17833. vertexShader: distanceShader.vertexShader,
  17834. fragmentShader: distanceShader.fragmentShader,
  17835. morphTargets: useMorphing,
  17836. skinning: useSkinning,
  17837. clipping: true
  17838. } );
  17839. _distanceMaterials[ i ] = distanceMaterial;
  17840. }
  17841. //
  17842. var scope = this;
  17843. this.enabled = false;
  17844. this.autoUpdate = true;
  17845. this.needsUpdate = false;
  17846. this.type = THREE.PCFShadowMap;
  17847. this.renderReverseSided = true;
  17848. this.renderSingleSided = true;
  17849. this.render = function ( scene, camera ) {
  17850. if ( scope.enabled === false ) return;
  17851. if ( scope.autoUpdate === false && scope.needsUpdate === false ) return;
  17852. if ( _lightShadows.length === 0 ) return;
  17853. // Set GL state for depth map.
  17854. _state.clearColor( 1, 1, 1, 1 );
  17855. _state.disable( _gl.BLEND );
  17856. _state.setDepthTest( true );
  17857. _state.setScissorTest( false );
  17858. // render depth map
  17859. var faceCount, isPointLight;
  17860. for ( var i = 0, il = _lightShadows.length; i < il; i ++ ) {
  17861. var light = _lightShadows[ i ];
  17862. var shadow = light.shadow;
  17863. if ( shadow === undefined ) {
  17864. console.warn( 'THREE.WebGLShadowMap:', light, 'has no shadow.' );
  17865. continue;
  17866. }
  17867. var shadowCamera = shadow.camera;
  17868. _shadowMapSize.copy( shadow.mapSize );
  17869. if ( light instanceof THREE.PointLight ) {
  17870. faceCount = 6;
  17871. isPointLight = true;
  17872. var vpWidth = _shadowMapSize.x;
  17873. var vpHeight = _shadowMapSize.y;
  17874. // These viewports map a cube-map onto a 2D texture with the
  17875. // following orientation:
  17876. //
  17877. // xzXZ
  17878. // y Y
  17879. //
  17880. // X - Positive x direction
  17881. // x - Negative x direction
  17882. // Y - Positive y direction
  17883. // y - Negative y direction
  17884. // Z - Positive z direction
  17885. // z - Negative z direction
  17886. // positive X
  17887. cube2DViewPorts[ 0 ].set( vpWidth * 2, vpHeight, vpWidth, vpHeight );
  17888. // negative X
  17889. cube2DViewPorts[ 1 ].set( 0, vpHeight, vpWidth, vpHeight );
  17890. // positive Z
  17891. cube2DViewPorts[ 2 ].set( vpWidth * 3, vpHeight, vpWidth, vpHeight );
  17892. // negative Z
  17893. cube2DViewPorts[ 3 ].set( vpWidth, vpHeight, vpWidth, vpHeight );
  17894. // positive Y
  17895. cube2DViewPorts[ 4 ].set( vpWidth * 3, 0, vpWidth, vpHeight );
  17896. // negative Y
  17897. cube2DViewPorts[ 5 ].set( vpWidth, 0, vpWidth, vpHeight );
  17898. _shadowMapSize.x *= 4.0;
  17899. _shadowMapSize.y *= 2.0;
  17900. } else {
  17901. faceCount = 1;
  17902. isPointLight = false;
  17903. }
  17904. if ( shadow.map === null ) {
  17905. var pars = { minFilter: THREE.NearestFilter, magFilter: THREE.NearestFilter, format: THREE.RGBAFormat };
  17906. shadow.map = new THREE.WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
  17907. shadowCamera.updateProjectionMatrix();
  17908. }
  17909. if ( shadow instanceof THREE.SpotLightShadow ) {
  17910. shadow.update( light );
  17911. }
  17912. var shadowMap = shadow.map;
  17913. var shadowMatrix = shadow.matrix;
  17914. _lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  17915. shadowCamera.position.copy( _lightPositionWorld );
  17916. _renderer.setRenderTarget( shadowMap );
  17917. _renderer.clear();
  17918. // render shadow map for each cube face (if omni-directional) or
  17919. // run a single pass if not
  17920. for ( var face = 0; face < faceCount; face ++ ) {
  17921. if ( isPointLight ) {
  17922. _lookTarget.copy( shadowCamera.position );
  17923. _lookTarget.add( cubeDirections[ face ] );
  17924. shadowCamera.up.copy( cubeUps[ face ] );
  17925. shadowCamera.lookAt( _lookTarget );
  17926. var vpDimensions = cube2DViewPorts[ face ];
  17927. _state.viewport( vpDimensions );
  17928. } else {
  17929. _lookTarget.setFromMatrixPosition( light.target.matrixWorld );
  17930. shadowCamera.lookAt( _lookTarget );
  17931. }
  17932. shadowCamera.updateMatrixWorld();
  17933. shadowCamera.matrixWorldInverse.getInverse( shadowCamera.matrixWorld );
  17934. // compute shadow matrix
  17935. shadowMatrix.set(
  17936. 0.5, 0.0, 0.0, 0.5,
  17937. 0.0, 0.5, 0.0, 0.5,
  17938. 0.0, 0.0, 0.5, 0.5,
  17939. 0.0, 0.0, 0.0, 1.0
  17940. );
  17941. shadowMatrix.multiply( shadowCamera.projectionMatrix );
  17942. shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
  17943. // update camera matrices and frustum
  17944. _projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  17945. _frustum.setFromMatrix( _projScreenMatrix );
  17946. // set object matrices & frustum culling
  17947. _renderList.length = 0;
  17948. projectObject( scene, camera, shadowCamera );
  17949. // render shadow map
  17950. // render regular objects
  17951. for ( var j = 0, jl = _renderList.length; j < jl; j ++ ) {
  17952. var object = _renderList[ j ];
  17953. var geometry = _objects.update( object );
  17954. var material = object.material;
  17955. if ( material instanceof THREE.MultiMaterial ) {
  17956. var groups = geometry.groups;
  17957. var materials = material.materials;
  17958. for ( var k = 0, kl = groups.length; k < kl; k ++ ) {
  17959. var group = groups[ k ];
  17960. var groupMaterial = materials[ group.materialIndex ];
  17961. if ( groupMaterial.visible === true ) {
  17962. var depthMaterial = getDepthMaterial( object, groupMaterial, isPointLight, _lightPositionWorld );
  17963. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, group );
  17964. }
  17965. }
  17966. } else {
  17967. var depthMaterial = getDepthMaterial( object, material, isPointLight, _lightPositionWorld );
  17968. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, null );
  17969. }
  17970. }
  17971. }
  17972. }
  17973. // Restore GL state.
  17974. var clearColor = _renderer.getClearColor(),
  17975. clearAlpha = _renderer.getClearAlpha();
  17976. _renderer.setClearColor( clearColor, clearAlpha );
  17977. scope.needsUpdate = false;
  17978. };
  17979. function getDepthMaterial( object, material, isPointLight, lightPositionWorld ) {
  17980. var geometry = object.geometry;
  17981. var result = null;
  17982. var materialVariants = _depthMaterials;
  17983. var customMaterial = object.customDepthMaterial;
  17984. if ( isPointLight ) {
  17985. materialVariants = _distanceMaterials;
  17986. customMaterial = object.customDistanceMaterial;
  17987. }
  17988. if ( ! customMaterial ) {
  17989. var useMorphing = geometry.morphTargets !== undefined &&
  17990. geometry.morphTargets.length > 0 && material.morphTargets;
  17991. var useSkinning = object instanceof THREE.SkinnedMesh && material.skinning;
  17992. var variantIndex = 0;
  17993. if ( useMorphing ) variantIndex |= _MorphingFlag;
  17994. if ( useSkinning ) variantIndex |= _SkinningFlag;
  17995. result = materialVariants[ variantIndex ];
  17996. } else {
  17997. result = customMaterial;
  17998. }
  17999. if ( _renderer.localClippingEnabled &&
  18000. material.clipShadows === true &&
  18001. material.clippingPlanes.length !== 0 ) {
  18002. // in this case we need a unique material instance reflecting the
  18003. // appropriate state
  18004. var keyA = result.uuid, keyB = material.uuid;
  18005. var materialsForVariant = _materialCache[ keyA ];
  18006. if ( materialsForVariant === undefined ) {
  18007. materialsForVariant = {};
  18008. _materialCache[ keyA ] = materialsForVariant;
  18009. }
  18010. var cachedMaterial = materialsForVariant[ keyB ];
  18011. if ( cachedMaterial === undefined ) {
  18012. cachedMaterial = result.clone();
  18013. materialsForVariant[ keyB ] = cachedMaterial;
  18014. }
  18015. result = cachedMaterial;
  18016. }
  18017. result.visible = material.visible;
  18018. result.wireframe = material.wireframe;
  18019. var side = material.side;
  18020. if ( scope.renderSingleSided && side == THREE.DoubleSide ) {
  18021. side = THREE.FrontSide;
  18022. }
  18023. if ( scope.renderReverseSided ) {
  18024. if ( side === THREE.FrontSide ) side = THREE.BackSide;
  18025. else if ( side === THREE.BackSide ) side = THREE.FrontSide;
  18026. }
  18027. result.side = side;
  18028. result.clipShadows = material.clipShadows;
  18029. result.clippingPlanes = material.clippingPlanes;
  18030. result.wireframeLinewidth = material.wireframeLinewidth;
  18031. result.linewidth = material.linewidth;
  18032. if ( isPointLight && result.uniforms.lightPos !== undefined ) {
  18033. result.uniforms.lightPos.value.copy( lightPositionWorld );
  18034. }
  18035. return result;
  18036. }
  18037. function projectObject( object, camera, shadowCamera ) {
  18038. if ( object.visible === false ) return;
  18039. if ( object.layers.test( camera.layers ) && ( object instanceof THREE.Mesh || object instanceof THREE.Line || object instanceof THREE.Points ) ) {
  18040. if ( object.castShadow && ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) ) {
  18041. var material = object.material;
  18042. if ( material.visible === true ) {
  18043. object.modelViewMatrix.multiplyMatrices( shadowCamera.matrixWorldInverse, object.matrixWorld );
  18044. _renderList.push( object );
  18045. }
  18046. }
  18047. }
  18048. var children = object.children;
  18049. for ( var i = 0, l = children.length; i < l; i ++ ) {
  18050. projectObject( children[ i ], camera, shadowCamera );
  18051. }
  18052. }
  18053. };
  18054. // File:src/renderers/webgl/WebGLState.js
  18055. /**
  18056. * @author mrdoob / http://mrdoob.com/
  18057. */
  18058. THREE.WebGLState = function ( gl, extensions, paramThreeToGL ) {
  18059. var _this = this;
  18060. this.buffers = {
  18061. color: new THREE.WebGLColorBuffer( gl, this ),
  18062. depth: new THREE.WebGLDepthBuffer( gl, this ),
  18063. stencil: new THREE.WebGLStencilBuffer( gl, this )
  18064. };
  18065. var maxVertexAttributes = gl.getParameter( gl.MAX_VERTEX_ATTRIBS );
  18066. var newAttributes = new Uint8Array( maxVertexAttributes );
  18067. var enabledAttributes = new Uint8Array( maxVertexAttributes );
  18068. var attributeDivisors = new Uint8Array( maxVertexAttributes );
  18069. var capabilities = {};
  18070. var compressedTextureFormats = null;
  18071. var currentBlending = null;
  18072. var currentBlendEquation = null;
  18073. var currentBlendSrc = null;
  18074. var currentBlendDst = null;
  18075. var currentBlendEquationAlpha = null;
  18076. var currentBlendSrcAlpha = null;
  18077. var currentBlendDstAlpha = null;
  18078. var currentPremultipledAlpha = false;
  18079. var currentFlipSided = null;
  18080. var currentCullFace = null;
  18081. var currentLineWidth = null;
  18082. var currentPolygonOffsetFactor = null;
  18083. var currentPolygonOffsetUnits = null;
  18084. var currentScissorTest = null;
  18085. var maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
  18086. var currentTextureSlot = null;
  18087. var currentBoundTextures = {};
  18088. var currentScissor = new THREE.Vector4();
  18089. var currentViewport = new THREE.Vector4();
  18090. function createTexture( type, target, count ) {
  18091. var data = new Uint8Array( 3 );
  18092. var texture = gl.createTexture();
  18093. gl.bindTexture( type, texture );
  18094. gl.texParameteri( type, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  18095. gl.texParameteri( type, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  18096. for ( var i = 0; i < count; i ++ ) {
  18097. gl.texImage2D( target + i, 0, gl.RGB, 1, 1, 0, gl.RGB, gl.UNSIGNED_BYTE, data );
  18098. }
  18099. return texture;
  18100. }
  18101. var emptyTextures = {};
  18102. emptyTextures[ gl.TEXTURE_2D ] = createTexture( gl.TEXTURE_2D, gl.TEXTURE_2D, 1 );
  18103. emptyTextures[ gl.TEXTURE_CUBE_MAP ] = createTexture( gl.TEXTURE_CUBE_MAP, gl.TEXTURE_CUBE_MAP_POSITIVE_X, 6 );
  18104. //
  18105. this.init = function () {
  18106. this.clearColor( 0, 0, 0, 1 );
  18107. this.clearDepth( 1 );
  18108. this.clearStencil( 0 );
  18109. this.enable( gl.DEPTH_TEST );
  18110. this.setDepthFunc( THREE.LessEqualDepth );
  18111. this.setFlipSided( false );
  18112. this.setCullFace( THREE.CullFaceBack );
  18113. this.enable( gl.CULL_FACE );
  18114. this.enable( gl.BLEND );
  18115. this.setBlending( THREE.NormalBlending );
  18116. };
  18117. this.initAttributes = function () {
  18118. for ( var i = 0, l = newAttributes.length; i < l; i ++ ) {
  18119. newAttributes[ i ] = 0;
  18120. }
  18121. };
  18122. this.enableAttribute = function ( attribute ) {
  18123. newAttributes[ attribute ] = 1;
  18124. if ( enabledAttributes[ attribute ] === 0 ) {
  18125. gl.enableVertexAttribArray( attribute );
  18126. enabledAttributes[ attribute ] = 1;
  18127. }
  18128. if ( attributeDivisors[ attribute ] !== 0 ) {
  18129. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  18130. extension.vertexAttribDivisorANGLE( attribute, 0 );
  18131. attributeDivisors[ attribute ] = 0;
  18132. }
  18133. };
  18134. this.enableAttributeAndDivisor = function ( attribute, meshPerAttribute, extension ) {
  18135. newAttributes[ attribute ] = 1;
  18136. if ( enabledAttributes[ attribute ] === 0 ) {
  18137. gl.enableVertexAttribArray( attribute );
  18138. enabledAttributes[ attribute ] = 1;
  18139. }
  18140. if ( attributeDivisors[ attribute ] !== meshPerAttribute ) {
  18141. extension.vertexAttribDivisorANGLE( attribute, meshPerAttribute );
  18142. attributeDivisors[ attribute ] = meshPerAttribute;
  18143. }
  18144. };
  18145. this.disableUnusedAttributes = function () {
  18146. for ( var i = 0, l = enabledAttributes.length; i !== l; ++ i ) {
  18147. if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
  18148. gl.disableVertexAttribArray( i );
  18149. enabledAttributes[ i ] = 0;
  18150. }
  18151. }
  18152. };
  18153. this.enable = function ( id ) {
  18154. if ( capabilities[ id ] !== true ) {
  18155. gl.enable( id );
  18156. capabilities[ id ] = true;
  18157. }
  18158. };
  18159. this.disable = function ( id ) {
  18160. if ( capabilities[ id ] !== false ) {
  18161. gl.disable( id );
  18162. capabilities[ id ] = false;
  18163. }
  18164. };
  18165. this.getCompressedTextureFormats = function () {
  18166. if ( compressedTextureFormats === null ) {
  18167. compressedTextureFormats = [];
  18168. if ( extensions.get( 'WEBGL_compressed_texture_pvrtc' ) ||
  18169. extensions.get( 'WEBGL_compressed_texture_s3tc' ) ||
  18170. extensions.get( 'WEBGL_compressed_texture_etc1' ) ) {
  18171. var formats = gl.getParameter( gl.COMPRESSED_TEXTURE_FORMATS );
  18172. for ( var i = 0; i < formats.length; i ++ ) {
  18173. compressedTextureFormats.push( formats[ i ] );
  18174. }
  18175. }
  18176. }
  18177. return compressedTextureFormats;
  18178. };
  18179. this.setBlending = function ( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha ) {
  18180. if ( blending !== THREE.NoBlending ) {
  18181. this.enable( gl.BLEND );
  18182. } else {
  18183. this.disable( gl.BLEND );
  18184. currentBlending = blending; // no blending, that is
  18185. return;
  18186. }
  18187. if ( blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha ) {
  18188. if ( blending === THREE.AdditiveBlending ) {
  18189. if ( premultipliedAlpha ) {
  18190. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  18191. gl.blendFuncSeparate( gl.ONE, gl.ONE, gl.ONE, gl.ONE );
  18192. } else {
  18193. gl.blendEquation( gl.FUNC_ADD );
  18194. gl.blendFunc( gl.SRC_ALPHA, gl.ONE );
  18195. }
  18196. } else if ( blending === THREE.SubtractiveBlending ) {
  18197. if ( premultipliedAlpha ) {
  18198. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  18199. gl.blendFuncSeparate( gl.ZERO, gl.ZERO, gl.ONE_MINUS_SRC_COLOR, gl.ONE_MINUS_SRC_ALPHA );
  18200. } else {
  18201. gl.blendEquation( gl.FUNC_ADD );
  18202. gl.blendFunc( gl.ZERO, gl.ONE_MINUS_SRC_COLOR );
  18203. }
  18204. } else if ( blending === THREE.MultiplyBlending ) {
  18205. if ( premultipliedAlpha ) {
  18206. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  18207. gl.blendFuncSeparate( gl.ZERO, gl.SRC_COLOR, gl.ZERO, gl.SRC_ALPHA );
  18208. } else {
  18209. gl.blendEquation( gl.FUNC_ADD );
  18210. gl.blendFunc( gl.ZERO, gl.SRC_COLOR );
  18211. }
  18212. } else {
  18213. if ( premultipliedAlpha ) {
  18214. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  18215. gl.blendFuncSeparate( gl.ONE, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
  18216. } else {
  18217. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  18218. gl.blendFuncSeparate( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
  18219. }
  18220. }
  18221. currentBlending = blending;
  18222. currentPremultipledAlpha = premultipliedAlpha;
  18223. }
  18224. if ( blending === THREE.CustomBlending ) {
  18225. blendEquationAlpha = blendEquationAlpha || blendEquation;
  18226. blendSrcAlpha = blendSrcAlpha || blendSrc;
  18227. blendDstAlpha = blendDstAlpha || blendDst;
  18228. if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
  18229. gl.blendEquationSeparate( paramThreeToGL( blendEquation ), paramThreeToGL( blendEquationAlpha ) );
  18230. currentBlendEquation = blendEquation;
  18231. currentBlendEquationAlpha = blendEquationAlpha;
  18232. }
  18233. if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
  18234. gl.blendFuncSeparate( paramThreeToGL( blendSrc ), paramThreeToGL( blendDst ), paramThreeToGL( blendSrcAlpha ), paramThreeToGL( blendDstAlpha ) );
  18235. currentBlendSrc = blendSrc;
  18236. currentBlendDst = blendDst;
  18237. currentBlendSrcAlpha = blendSrcAlpha;
  18238. currentBlendDstAlpha = blendDstAlpha;
  18239. }
  18240. } else {
  18241. currentBlendEquation = null;
  18242. currentBlendSrc = null;
  18243. currentBlendDst = null;
  18244. currentBlendEquationAlpha = null;
  18245. currentBlendSrcAlpha = null;
  18246. currentBlendDstAlpha = null;
  18247. }
  18248. };
  18249. // TODO Deprecate
  18250. this.setColorWrite = function ( colorWrite ) {
  18251. this.buffers.color.setMask( colorWrite );
  18252. };
  18253. this.setDepthTest = function ( depthTest ) {
  18254. this.buffers.depth.setTest( depthTest );
  18255. };
  18256. this.setDepthWrite = function ( depthWrite ) {
  18257. this.buffers.depth.setMask( depthWrite );
  18258. };
  18259. this.setDepthFunc = function ( depthFunc ) {
  18260. this.buffers.depth.setFunc( depthFunc );
  18261. };
  18262. this.setStencilTest = function ( stencilTest ) {
  18263. this.buffers.stencil.setTest( stencilTest );
  18264. };
  18265. this.setStencilWrite = function ( stencilWrite ) {
  18266. this.buffers.stencil.setMask( stencilWrite );
  18267. };
  18268. this.setStencilFunc = function ( stencilFunc, stencilRef, stencilMask ) {
  18269. this.buffers.stencil.setFunc( stencilFunc, stencilRef, stencilMask );
  18270. };
  18271. this.setStencilOp = function ( stencilFail, stencilZFail, stencilZPass ) {
  18272. this.buffers.stencil.setOp( stencilFail, stencilZFail, stencilZPass );
  18273. };
  18274. //
  18275. this.setFlipSided = function ( flipSided ) {
  18276. if ( currentFlipSided !== flipSided ) {
  18277. if ( flipSided ) {
  18278. gl.frontFace( gl.CW );
  18279. } else {
  18280. gl.frontFace( gl.CCW );
  18281. }
  18282. currentFlipSided = flipSided;
  18283. }
  18284. };
  18285. this.setCullFace = function ( cullFace ) {
  18286. if ( cullFace !== THREE.CullFaceNone ) {
  18287. this.enable( gl.CULL_FACE );
  18288. if ( cullFace !== currentCullFace ) {
  18289. if ( cullFace === THREE.CullFaceBack ) {
  18290. gl.cullFace( gl.BACK );
  18291. } else if ( cullFace === THREE.CullFaceFront ) {
  18292. gl.cullFace( gl.FRONT );
  18293. } else {
  18294. gl.cullFace( gl.FRONT_AND_BACK );
  18295. }
  18296. }
  18297. } else {
  18298. this.disable( gl.CULL_FACE );
  18299. }
  18300. currentCullFace = cullFace;
  18301. };
  18302. this.setLineWidth = function ( width ) {
  18303. if ( width !== currentLineWidth ) {
  18304. gl.lineWidth( width );
  18305. currentLineWidth = width;
  18306. }
  18307. };
  18308. this.setPolygonOffset = function ( polygonOffset, factor, units ) {
  18309. if ( polygonOffset ) {
  18310. this.enable( gl.POLYGON_OFFSET_FILL );
  18311. if ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) {
  18312. gl.polygonOffset( factor, units );
  18313. currentPolygonOffsetFactor = factor;
  18314. currentPolygonOffsetUnits = units;
  18315. }
  18316. } else {
  18317. this.disable( gl.POLYGON_OFFSET_FILL );
  18318. }
  18319. };
  18320. this.getScissorTest = function () {
  18321. return currentScissorTest;
  18322. };
  18323. this.setScissorTest = function ( scissorTest ) {
  18324. currentScissorTest = scissorTest;
  18325. if ( scissorTest ) {
  18326. this.enable( gl.SCISSOR_TEST );
  18327. } else {
  18328. this.disable( gl.SCISSOR_TEST );
  18329. }
  18330. };
  18331. // texture
  18332. this.activeTexture = function ( webglSlot ) {
  18333. if ( webglSlot === undefined ) webglSlot = gl.TEXTURE0 + maxTextures - 1;
  18334. if ( currentTextureSlot !== webglSlot ) {
  18335. gl.activeTexture( webglSlot );
  18336. currentTextureSlot = webglSlot;
  18337. }
  18338. };
  18339. this.bindTexture = function ( webglType, webglTexture ) {
  18340. if ( currentTextureSlot === null ) {
  18341. _this.activeTexture();
  18342. }
  18343. var boundTexture = currentBoundTextures[ currentTextureSlot ];
  18344. if ( boundTexture === undefined ) {
  18345. boundTexture = { type: undefined, texture: undefined };
  18346. currentBoundTextures[ currentTextureSlot ] = boundTexture;
  18347. }
  18348. if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
  18349. gl.bindTexture( webglType, webglTexture || emptyTextures[ webglType ] );
  18350. boundTexture.type = webglType;
  18351. boundTexture.texture = webglTexture;
  18352. }
  18353. };
  18354. this.compressedTexImage2D = function () {
  18355. try {
  18356. gl.compressedTexImage2D.apply( gl, arguments );
  18357. } catch ( error ) {
  18358. console.error( error );
  18359. }
  18360. };
  18361. this.texImage2D = function () {
  18362. try {
  18363. gl.texImage2D.apply( gl, arguments );
  18364. } catch ( error ) {
  18365. console.error( error );
  18366. }
  18367. };
  18368. // TODO Deprecate
  18369. this.clearColor = function ( r, g, b, a ) {
  18370. this.buffers.color.setClear( r, g, b, a );
  18371. };
  18372. this.clearDepth = function ( depth ) {
  18373. this.buffers.depth.setClear( depth );
  18374. };
  18375. this.clearStencil = function ( stencil ) {
  18376. this.buffers.stencil.setClear( stencil );
  18377. };
  18378. //
  18379. this.scissor = function ( scissor ) {
  18380. if ( currentScissor.equals( scissor ) === false ) {
  18381. gl.scissor( scissor.x, scissor.y, scissor.z, scissor.w );
  18382. currentScissor.copy( scissor );
  18383. }
  18384. };
  18385. this.viewport = function ( viewport ) {
  18386. if ( currentViewport.equals( viewport ) === false ) {
  18387. gl.viewport( viewport.x, viewport.y, viewport.z, viewport.w );
  18388. currentViewport.copy( viewport );
  18389. }
  18390. };
  18391. //
  18392. this.reset = function () {
  18393. for ( var i = 0; i < enabledAttributes.length; i ++ ) {
  18394. if ( enabledAttributes[ i ] === 1 ) {
  18395. gl.disableVertexAttribArray( i );
  18396. enabledAttributes[ i ] = 0;
  18397. }
  18398. }
  18399. capabilities = {};
  18400. compressedTextureFormats = null;
  18401. currentTextureSlot = null;
  18402. currentBoundTextures = {};
  18403. currentBlending = null;
  18404. currentFlipSided = null;
  18405. currentCullFace = null;
  18406. this.buffers.color.reset();
  18407. this.buffers.depth.reset();
  18408. this.buffers.stencil.reset();
  18409. };
  18410. };
  18411. THREE.WebGLColorBuffer = function ( gl, state ) {
  18412. var locked = false;
  18413. var color = new THREE.Vector4();
  18414. var currentColorMask = null;
  18415. var currentColorClear = new THREE.Vector4();
  18416. this.setMask = function ( colorMask ) {
  18417. if ( currentColorMask !== colorMask && ! locked ) {
  18418. gl.colorMask( colorMask, colorMask, colorMask, colorMask );
  18419. currentColorMask = colorMask;
  18420. }
  18421. };
  18422. this.setLocked = function ( lock ) {
  18423. locked = lock;
  18424. };
  18425. this.setClear = function ( r, g, b, a ) {
  18426. color.set( r, g, b, a );
  18427. if ( currentColorClear.equals( color ) === false ) {
  18428. gl.clearColor( r, g, b, a );
  18429. currentColorClear.copy( color );
  18430. }
  18431. };
  18432. this.reset = function () {
  18433. locked = false;
  18434. currentColorMask = null;
  18435. currentColorClear = new THREE.Vector4();
  18436. };
  18437. };
  18438. THREE.WebGLDepthBuffer = function( gl, state ) {
  18439. var locked = false;
  18440. var currentDepthMask = null;
  18441. var currentDepthFunc = null;
  18442. var currentDepthClear = null;
  18443. this.setTest = function ( depthTest ) {
  18444. if ( depthTest ) {
  18445. state.enable( gl.DEPTH_TEST );
  18446. } else {
  18447. state.disable( gl.DEPTH_TEST );
  18448. }
  18449. };
  18450. this.setMask = function( depthMask ){
  18451. if ( currentDepthMask !== depthMask && ! locked ) {
  18452. gl.depthMask( depthMask );
  18453. currentDepthMask = depthMask;
  18454. }
  18455. };
  18456. this.setFunc = function ( depthFunc ) {
  18457. if ( currentDepthFunc !== depthFunc ) {
  18458. if ( depthFunc ) {
  18459. switch ( depthFunc ) {
  18460. case THREE.NeverDepth:
  18461. gl.depthFunc( gl.NEVER );
  18462. break;
  18463. case THREE.AlwaysDepth:
  18464. gl.depthFunc( gl.ALWAYS );
  18465. break;
  18466. case THREE.LessDepth:
  18467. gl.depthFunc( gl.LESS );
  18468. break;
  18469. case THREE.LessEqualDepth:
  18470. gl.depthFunc( gl.LEQUAL );
  18471. break;
  18472. case THREE.EqualDepth:
  18473. gl.depthFunc( gl.EQUAL );
  18474. break;
  18475. case THREE.GreaterEqualDepth:
  18476. gl.depthFunc( gl.GEQUAL );
  18477. break;
  18478. case THREE.GreaterDepth:
  18479. gl.depthFunc( gl.GREATER );
  18480. break;
  18481. case THREE.NotEqualDepth:
  18482. gl.depthFunc( gl.NOTEQUAL );
  18483. break;
  18484. default:
  18485. gl.depthFunc( gl.LEQUAL );
  18486. }
  18487. } else {
  18488. gl.depthFunc( gl.LEQUAL );
  18489. }
  18490. currentDepthFunc = depthFunc;
  18491. }
  18492. };
  18493. this.setLocked = function ( lock ) {
  18494. locked = lock;
  18495. };
  18496. this.setClear = function ( depth ) {
  18497. if ( currentDepthClear !== depth ) {
  18498. gl.clearDepth( depth );
  18499. currentDepthClear = depth;
  18500. }
  18501. };
  18502. this.reset = function () {
  18503. locked = false;
  18504. currentDepthMask = null;
  18505. currentDepthFunc = null;
  18506. currentDepthClear = null;
  18507. };
  18508. };
  18509. THREE.WebGLStencilBuffer = function ( gl, state ) {
  18510. var locked = false;
  18511. var currentStencilMask = null;
  18512. var currentStencilFunc = null;
  18513. var currentStencilRef = null;
  18514. var currentStencilFuncMask = null;
  18515. var currentStencilFail = null;
  18516. var currentStencilZFail = null;
  18517. var currentStencilZPass = null;
  18518. var currentStencilClear = null;
  18519. this.setTest = function ( stencilTest ) {
  18520. if ( stencilTest ) {
  18521. state.enable( gl.STENCIL_TEST );
  18522. } else {
  18523. state.disable( gl.STENCIL_TEST );
  18524. }
  18525. };
  18526. this.setMask = function ( stencilMask ) {
  18527. if ( currentStencilMask !== stencilMask && ! locked ) {
  18528. gl.stencilMask( stencilMask );
  18529. currentStencilMask = stencilMask;
  18530. }
  18531. };
  18532. this.setFunc = function ( stencilFunc, stencilRef, stencilMask ) {
  18533. if ( currentStencilFunc !== stencilFunc ||
  18534. currentStencilRef !== stencilRef ||
  18535. currentStencilFuncMask !== stencilMask ) {
  18536. gl.stencilFunc( stencilFunc, stencilRef, stencilMask );
  18537. currentStencilFunc = stencilFunc;
  18538. currentStencilRef = stencilRef;
  18539. currentStencilFuncMask = stencilMask;
  18540. }
  18541. };
  18542. this.setOp = function ( stencilFail, stencilZFail, stencilZPass ) {
  18543. if ( currentStencilFail !== stencilFail ||
  18544. currentStencilZFail !== stencilZFail ||
  18545. currentStencilZPass !== stencilZPass ) {
  18546. gl.stencilOp( stencilFail, stencilZFail, stencilZPass );
  18547. currentStencilFail = stencilFail;
  18548. currentStencilZFail = stencilZFail;
  18549. currentStencilZPass = stencilZPass;
  18550. }
  18551. };
  18552. this.setLocked = function ( lock ) {
  18553. locked = lock;
  18554. };
  18555. this.setClear = function ( stencil ) {
  18556. if ( currentStencilClear !== stencil ) {
  18557. gl.clearStencil( stencil );
  18558. currentStencilClear = stencil;
  18559. }
  18560. };
  18561. this.reset = function () {
  18562. locked = false;
  18563. currentStencilMask = null;
  18564. currentStencilFunc = null;
  18565. currentStencilRef = null;
  18566. currentStencilFuncMask = null;
  18567. currentStencilFail = null;
  18568. currentStencilZFail = null;
  18569. currentStencilZPass = null;
  18570. currentStencilClear = null;
  18571. };
  18572. };
  18573. // File:src/renderers/webgl/WebGLUniforms.js
  18574. /**
  18575. *
  18576. * Uniforms of a program.
  18577. * Those form a tree structure with a special top-level container for the root,
  18578. * which you get by calling 'new WebGLUniforms( gl, program, renderer )'.
  18579. *
  18580. *
  18581. * Properties of inner nodes including the top-level container:
  18582. *
  18583. * .seq - array of nested uniforms
  18584. * .map - nested uniforms by name
  18585. *
  18586. *
  18587. * Methods of all nodes except the top-level container:
  18588. *
  18589. * .setValue( gl, value, [renderer] )
  18590. *
  18591. * uploads a uniform value(s)
  18592. * the 'renderer' parameter is needed for sampler uniforms
  18593. *
  18594. *
  18595. * Static methods of the top-level container (renderer factorizations):
  18596. *
  18597. * .upload( gl, seq, values, renderer )
  18598. *
  18599. * sets uniforms in 'seq' to 'values[id].value'
  18600. *
  18601. * .seqWithValue( seq, values ) : filteredSeq
  18602. *
  18603. * filters 'seq' entries with corresponding entry in values
  18604. *
  18605. * .splitDynamic( seq, values ) : filteredSeq
  18606. *
  18607. * filters 'seq' entries with dynamic entry and removes them from 'seq'
  18608. *
  18609. *
  18610. * Methods of the top-level container (renderer factorizations):
  18611. *
  18612. * .setValue( gl, name, value )
  18613. *
  18614. * sets uniform with name 'name' to 'value'
  18615. *
  18616. * .set( gl, obj, prop )
  18617. *
  18618. * sets uniform from object and property with same name than uniform
  18619. *
  18620. * .setOptional( gl, obj, prop )
  18621. *
  18622. * like .set for an optional property of the object
  18623. *
  18624. *
  18625. * @author tschw
  18626. *
  18627. */
  18628. THREE.WebGLUniforms = ( function() { // scope
  18629. // --- Base for inner nodes (including the root) ---
  18630. var UniformContainer = function() {
  18631. this.seq = [];
  18632. this.map = {};
  18633. },
  18634. // --- Utilities ---
  18635. // Array Caches (provide typed arrays for temporary by size)
  18636. arrayCacheF32 = [],
  18637. arrayCacheI32 = [],
  18638. uncacheTemporaryArrays = function() {
  18639. arrayCacheF32.length = 0;
  18640. arrayCacheI32.length = 0;
  18641. },
  18642. // Flattening for arrays of vectors and matrices
  18643. flatten = function( array, nBlocks, blockSize ) {
  18644. var firstElem = array[ 0 ];
  18645. if ( firstElem <= 0 || firstElem > 0 ) return array;
  18646. // unoptimized: ! isNaN( firstElem )
  18647. // see http://jacksondunstan.com/articles/983
  18648. var n = nBlocks * blockSize,
  18649. r = arrayCacheF32[ n ];
  18650. if ( r === undefined ) {
  18651. r = new Float32Array( n );
  18652. arrayCacheF32[ n ] = r;
  18653. }
  18654. if ( nBlocks !== 0 ) {
  18655. firstElem.toArray( r, 0 );
  18656. for ( var i = 1, offset = 0; i !== nBlocks; ++ i ) {
  18657. offset += blockSize;
  18658. array[ i ].toArray( r, offset );
  18659. }
  18660. }
  18661. return r;
  18662. },
  18663. // Texture unit allocation
  18664. allocTexUnits = function( renderer, n ) {
  18665. var r = arrayCacheI32[ n ];
  18666. if ( r === undefined ) {
  18667. r = new Int32Array( n );
  18668. arrayCacheI32[ n ] = r;
  18669. }
  18670. for ( var i = 0; i !== n; ++ i )
  18671. r[ i ] = renderer.allocTextureUnit();
  18672. return r;
  18673. },
  18674. // --- Setters ---
  18675. // Note: Defining these methods externally, because they come in a bunch
  18676. // and this way their names minify.
  18677. // Single scalar
  18678. setValue1f = function( gl, v ) { gl.uniform1f( this.addr, v ); },
  18679. setValue1i = function( gl, v ) { gl.uniform1i( this.addr, v ); },
  18680. // Single float vector (from flat array or THREE.VectorN)
  18681. setValue2fv = function( gl, v ) {
  18682. if ( v.x === undefined ) gl.uniform2fv( this.addr, v );
  18683. else gl.uniform2f( this.addr, v.x, v.y );
  18684. },
  18685. setValue3fv = function( gl, v ) {
  18686. if ( v.x !== undefined )
  18687. gl.uniform3f( this.addr, v.x, v.y, v.z );
  18688. else if ( v.r !== undefined )
  18689. gl.uniform3f( this.addr, v.r, v.g, v.b );
  18690. else
  18691. gl.uniform3fv( this.addr, v );
  18692. },
  18693. setValue4fv = function( gl, v ) {
  18694. if ( v.x === undefined ) gl.uniform4fv( this.addr, v );
  18695. else gl.uniform4f( this.addr, v.x, v.y, v.z, v.w );
  18696. },
  18697. // Single matrix (from flat array or MatrixN)
  18698. setValue2fm = function( gl, v ) {
  18699. gl.uniformMatrix2fv( this.addr, false, v.elements || v );
  18700. },
  18701. setValue3fm = function( gl, v ) {
  18702. gl.uniformMatrix3fv( this.addr, false, v.elements || v );
  18703. },
  18704. setValue4fm = function( gl, v ) {
  18705. gl.uniformMatrix4fv( this.addr, false, v.elements || v );
  18706. },
  18707. // Single texture (2D / Cube)
  18708. setValueT1 = function( gl, v, renderer ) {
  18709. var unit = renderer.allocTextureUnit();
  18710. gl.uniform1i( this.addr, unit );
  18711. if ( v ) renderer.setTexture2D( v, unit );
  18712. },
  18713. setValueT6 = function( gl, v, renderer ) {
  18714. var unit = renderer.allocTextureUnit();
  18715. gl.uniform1i( this.addr, unit );
  18716. if ( v ) renderer.setTextureCube( v, unit );
  18717. },
  18718. // Integer / Boolean vectors or arrays thereof (always flat arrays)
  18719. setValue2iv = function( gl, v ) { gl.uniform2iv( this.addr, v ); },
  18720. setValue3iv = function( gl, v ) { gl.uniform3iv( this.addr, v ); },
  18721. setValue4iv = function( gl, v ) { gl.uniform4iv( this.addr, v ); },
  18722. // Helper to pick the right setter for the singular case
  18723. getSingularSetter = function( type ) {
  18724. switch ( type ) {
  18725. case 0x1406: return setValue1f; // FLOAT
  18726. case 0x8b50: return setValue2fv; // _VEC2
  18727. case 0x8b51: return setValue3fv; // _VEC3
  18728. case 0x8b52: return setValue4fv; // _VEC4
  18729. case 0x8b5a: return setValue2fm; // _MAT2
  18730. case 0x8b5b: return setValue3fm; // _MAT3
  18731. case 0x8b5c: return setValue4fm; // _MAT4
  18732. case 0x8b5e: return setValueT1; // SAMPLER_2D
  18733. case 0x8b60: return setValueT6; // SAMPLER_CUBE
  18734. case 0x1404: case 0x8b56: return setValue1i; // INT, BOOL
  18735. case 0x8b53: case 0x8b57: return setValue2iv; // _VEC2
  18736. case 0x8b54: case 0x8b58: return setValue3iv; // _VEC3
  18737. case 0x8b55: case 0x8b59: return setValue4iv; // _VEC4
  18738. }
  18739. },
  18740. // Array of scalars
  18741. setValue1fv = function( gl, v ) { gl.uniform1fv( this.addr, v ); },
  18742. setValue1iv = function( gl, v ) { gl.uniform1iv( this.addr, v ); },
  18743. // Array of vectors (flat or from THREE classes)
  18744. setValueV2a = function( gl, v ) {
  18745. gl.uniform2fv( this.addr, flatten( v, this.size, 2 ) );
  18746. },
  18747. setValueV3a = function( gl, v ) {
  18748. gl.uniform3fv( this.addr, flatten( v, this.size, 3 ) );
  18749. },
  18750. setValueV4a = function( gl, v ) {
  18751. gl.uniform4fv( this.addr, flatten( v, this.size, 4 ) );
  18752. },
  18753. // Array of matrices (flat or from THREE clases)
  18754. setValueM2a = function( gl, v ) {
  18755. gl.uniformMatrix2fv( this.addr, false, flatten( v, this.size, 4 ) );
  18756. },
  18757. setValueM3a = function( gl, v ) {
  18758. gl.uniformMatrix3fv( this.addr, false, flatten( v, this.size, 9 ) );
  18759. },
  18760. setValueM4a = function( gl, v ) {
  18761. gl.uniformMatrix4fv( this.addr, false, flatten( v, this.size, 16 ) );
  18762. },
  18763. // Array of textures (2D / Cube)
  18764. setValueT1a = function( gl, v, renderer ) {
  18765. var n = v.length,
  18766. units = allocTexUnits( renderer, n );
  18767. gl.uniform1iv( this.addr, units );
  18768. for ( var i = 0; i !== n; ++ i ) {
  18769. var tex = v[ i ];
  18770. if ( tex ) renderer.setTexture2D( tex, units[ i ] );
  18771. }
  18772. },
  18773. setValueT6a = function( gl, v, renderer ) {
  18774. var n = v.length,
  18775. units = allocTexUnits( renderer, n );
  18776. gl.uniform1iv( this.addr, units );
  18777. for ( var i = 0; i !== n; ++ i ) {
  18778. var tex = v[ i ];
  18779. if ( tex ) renderer.setTextureCube( tex, units[ i ] );
  18780. }
  18781. },
  18782. // Helper to pick the right setter for a pure (bottom-level) array
  18783. getPureArraySetter = function( type ) {
  18784. switch ( type ) {
  18785. case 0x1406: return setValue1fv; // FLOAT
  18786. case 0x8b50: return setValueV2a; // _VEC2
  18787. case 0x8b51: return setValueV3a; // _VEC3
  18788. case 0x8b52: return setValueV4a; // _VEC4
  18789. case 0x8b5a: return setValueM2a; // _MAT2
  18790. case 0x8b5b: return setValueM3a; // _MAT3
  18791. case 0x8b5c: return setValueM4a; // _MAT4
  18792. case 0x8b5e: return setValueT1a; // SAMPLER_2D
  18793. case 0x8b60: return setValueT6a; // SAMPLER_CUBE
  18794. case 0x1404: case 0x8b56: return setValue1iv; // INT, BOOL
  18795. case 0x8b53: case 0x8b57: return setValue2iv; // _VEC2
  18796. case 0x8b54: case 0x8b58: return setValue3iv; // _VEC3
  18797. case 0x8b55: case 0x8b59: return setValue4iv; // _VEC4
  18798. }
  18799. },
  18800. // --- Uniform Classes ---
  18801. SingleUniform = function SingleUniform( id, activeInfo, addr ) {
  18802. this.id = id;
  18803. this.addr = addr;
  18804. this.setValue = getSingularSetter( activeInfo.type );
  18805. // this.path = activeInfo.name; // DEBUG
  18806. },
  18807. PureArrayUniform = function( id, activeInfo, addr ) {
  18808. this.id = id;
  18809. this.addr = addr;
  18810. this.size = activeInfo.size;
  18811. this.setValue = getPureArraySetter( activeInfo.type );
  18812. // this.path = activeInfo.name; // DEBUG
  18813. },
  18814. StructuredUniform = function( id ) {
  18815. this.id = id;
  18816. UniformContainer.call( this ); // mix-in
  18817. };
  18818. StructuredUniform.prototype.setValue = function( gl, value ) {
  18819. // Note: Don't need an extra 'renderer' parameter, since samplers
  18820. // are not allowed in structured uniforms.
  18821. var seq = this.seq;
  18822. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  18823. var u = seq[ i ];
  18824. u.setValue( gl, value[ u.id ] );
  18825. }
  18826. };
  18827. // --- Top-level ---
  18828. // Parser - builds up the property tree from the path strings
  18829. var RePathPart = /([\w\d_]+)(\])?(\[|\.)?/g,
  18830. // extracts
  18831. // - the identifier (member name or array index)
  18832. // - followed by an optional right bracket (found when array index)
  18833. // - followed by an optional left bracket or dot (type of subscript)
  18834. //
  18835. // Note: These portions can be read in a non-overlapping fashion and
  18836. // allow straightforward parsing of the hierarchy that WebGL encodes
  18837. // in the uniform names.
  18838. addUniform = function( container, uniformObject ) {
  18839. container.seq.push( uniformObject );
  18840. container.map[ uniformObject.id ] = uniformObject;
  18841. },
  18842. parseUniform = function( activeInfo, addr, container ) {
  18843. var path = activeInfo.name,
  18844. pathLength = path.length;
  18845. // reset RegExp object, because of the early exit of a previous run
  18846. RePathPart.lastIndex = 0;
  18847. for (; ;) {
  18848. var match = RePathPart.exec( path ),
  18849. matchEnd = RePathPart.lastIndex,
  18850. id = match[ 1 ],
  18851. idIsIndex = match[ 2 ] === ']',
  18852. subscript = match[ 3 ];
  18853. if ( idIsIndex ) id = id | 0; // convert to integer
  18854. if ( subscript === undefined ||
  18855. subscript === '[' && matchEnd + 2 === pathLength ) {
  18856. // bare name or "pure" bottom-level array "[0]" suffix
  18857. addUniform( container, subscript === undefined ?
  18858. new SingleUniform( id, activeInfo, addr ) :
  18859. new PureArrayUniform( id, activeInfo, addr ) );
  18860. break;
  18861. } else {
  18862. // step into inner node / create it in case it doesn't exist
  18863. var map = container.map,
  18864. next = map[ id ];
  18865. if ( next === undefined ) {
  18866. next = new StructuredUniform( id );
  18867. addUniform( container, next );
  18868. }
  18869. container = next;
  18870. }
  18871. }
  18872. },
  18873. // Root Container
  18874. WebGLUniforms = function WebGLUniforms( gl, program, renderer ) {
  18875. UniformContainer.call( this );
  18876. this.renderer = renderer;
  18877. var n = gl.getProgramParameter( program, gl.ACTIVE_UNIFORMS );
  18878. for ( var i = 0; i !== n; ++ i ) {
  18879. var info = gl.getActiveUniform( program, i ),
  18880. path = info.name,
  18881. addr = gl.getUniformLocation( program, path );
  18882. parseUniform( info, addr, this );
  18883. }
  18884. };
  18885. WebGLUniforms.prototype.setValue = function( gl, name, value ) {
  18886. var u = this.map[ name ];
  18887. if ( u !== undefined ) u.setValue( gl, value, this.renderer );
  18888. };
  18889. WebGLUniforms.prototype.set = function( gl, object, name ) {
  18890. var u = this.map[ name ];
  18891. if ( u !== undefined ) u.setValue( gl, object[ name ], this.renderer );
  18892. };
  18893. WebGLUniforms.prototype.setOptional = function( gl, object, name ) {
  18894. var v = object[ name ];
  18895. if ( v !== undefined ) this.setValue( gl, name, v );
  18896. };
  18897. // Static interface
  18898. WebGLUniforms.upload = function( gl, seq, values, renderer ) {
  18899. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  18900. var u = seq[ i ],
  18901. v = values[ u.id ];
  18902. if ( v.needsUpdate !== false ) {
  18903. // note: always updating when .needsUpdate is undefined
  18904. u.setValue( gl, v.value, renderer );
  18905. }
  18906. }
  18907. };
  18908. WebGLUniforms.seqWithValue = function( seq, values ) {
  18909. var r = [];
  18910. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  18911. var u = seq[ i ];
  18912. if ( u.id in values ) r.push( u );
  18913. }
  18914. return r;
  18915. };
  18916. WebGLUniforms.splitDynamic = function( seq, values ) {
  18917. var r = null,
  18918. n = seq.length,
  18919. w = 0;
  18920. for ( var i = 0; i !== n; ++ i ) {
  18921. var u = seq[ i ],
  18922. v = values[ u.id ];
  18923. if ( v && v.dynamic === true ) {
  18924. if ( r === null ) r = [];
  18925. r.push( u );
  18926. } else {
  18927. // in-place compact 'seq', removing the matches
  18928. if ( w < i ) seq[ w ] = u;
  18929. ++ w;
  18930. }
  18931. }
  18932. if ( w < n ) seq.length = w;
  18933. return r;
  18934. };
  18935. WebGLUniforms.evalDynamic = function( seq, values, object, camera ) {
  18936. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  18937. var v = values[ seq[ i ].id ],
  18938. f = v.onUpdateCallback;
  18939. if ( f !== undefined ) f.call( v, object, camera );
  18940. }
  18941. };
  18942. return WebGLUniforms;
  18943. } )();
  18944. // File:src/renderers/webgl/plugins/LensFlarePlugin.js
  18945. /**
  18946. * @author mikael emtinger / http://gomo.se/
  18947. * @author alteredq / http://alteredqualia.com/
  18948. */
  18949. THREE.LensFlarePlugin = function ( renderer, flares ) {
  18950. var gl = renderer.context;
  18951. var state = renderer.state;
  18952. var vertexBuffer, elementBuffer;
  18953. var shader, program, attributes, uniforms;
  18954. var tempTexture, occlusionTexture;
  18955. function init() {
  18956. var vertices = new Float32Array( [
  18957. - 1, - 1, 0, 0,
  18958. 1, - 1, 1, 0,
  18959. 1, 1, 1, 1,
  18960. - 1, 1, 0, 1
  18961. ] );
  18962. var faces = new Uint16Array( [
  18963. 0, 1, 2,
  18964. 0, 2, 3
  18965. ] );
  18966. // buffers
  18967. vertexBuffer = gl.createBuffer();
  18968. elementBuffer = gl.createBuffer();
  18969. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  18970. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  18971. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  18972. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  18973. // textures
  18974. tempTexture = gl.createTexture();
  18975. occlusionTexture = gl.createTexture();
  18976. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  18977. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGB, 16, 16, 0, gl.RGB, gl.UNSIGNED_BYTE, null );
  18978. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  18979. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  18980. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  18981. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  18982. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  18983. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGBA, 16, 16, 0, gl.RGBA, gl.UNSIGNED_BYTE, null );
  18984. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  18985. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  18986. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  18987. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  18988. shader = {
  18989. vertexShader: [
  18990. "uniform lowp int renderType;",
  18991. "uniform vec3 screenPosition;",
  18992. "uniform vec2 scale;",
  18993. "uniform float rotation;",
  18994. "uniform sampler2D occlusionMap;",
  18995. "attribute vec2 position;",
  18996. "attribute vec2 uv;",
  18997. "varying vec2 vUV;",
  18998. "varying float vVisibility;",
  18999. "void main() {",
  19000. "vUV = uv;",
  19001. "vec2 pos = position;",
  19002. "if ( renderType == 2 ) {",
  19003. "vec4 visibility = texture2D( occlusionMap, vec2( 0.1, 0.1 ) );",
  19004. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.1 ) );",
  19005. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.1 ) );",
  19006. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) );",
  19007. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.9 ) );",
  19008. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) );",
  19009. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.9 ) );",
  19010. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) );",
  19011. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.5 ) );",
  19012. "vVisibility = visibility.r / 9.0;",
  19013. "vVisibility *= 1.0 - visibility.g / 9.0;",
  19014. "vVisibility *= visibility.b / 9.0;",
  19015. "vVisibility *= 1.0 - visibility.a / 9.0;",
  19016. "pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
  19017. "pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
  19018. "}",
  19019. "gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
  19020. "}"
  19021. ].join( "\n" ),
  19022. fragmentShader: [
  19023. "uniform lowp int renderType;",
  19024. "uniform sampler2D map;",
  19025. "uniform float opacity;",
  19026. "uniform vec3 color;",
  19027. "varying vec2 vUV;",
  19028. "varying float vVisibility;",
  19029. "void main() {",
  19030. // pink square
  19031. "if ( renderType == 0 ) {",
  19032. "gl_FragColor = vec4( 1.0, 0.0, 1.0, 0.0 );",
  19033. // restore
  19034. "} else if ( renderType == 1 ) {",
  19035. "gl_FragColor = texture2D( map, vUV );",
  19036. // flare
  19037. "} else {",
  19038. "vec4 texture = texture2D( map, vUV );",
  19039. "texture.a *= opacity * vVisibility;",
  19040. "gl_FragColor = texture;",
  19041. "gl_FragColor.rgb *= color;",
  19042. "}",
  19043. "}"
  19044. ].join( "\n" )
  19045. };
  19046. program = createProgram( shader );
  19047. attributes = {
  19048. vertex: gl.getAttribLocation ( program, "position" ),
  19049. uv: gl.getAttribLocation ( program, "uv" )
  19050. };
  19051. uniforms = {
  19052. renderType: gl.getUniformLocation( program, "renderType" ),
  19053. map: gl.getUniformLocation( program, "map" ),
  19054. occlusionMap: gl.getUniformLocation( program, "occlusionMap" ),
  19055. opacity: gl.getUniformLocation( program, "opacity" ),
  19056. color: gl.getUniformLocation( program, "color" ),
  19057. scale: gl.getUniformLocation( program, "scale" ),
  19058. rotation: gl.getUniformLocation( program, "rotation" ),
  19059. screenPosition: gl.getUniformLocation( program, "screenPosition" )
  19060. };
  19061. }
  19062. /*
  19063. * Render lens flares
  19064. * Method: renders 16x16 0xff00ff-colored points scattered over the light source area,
  19065. * reads these back and calculates occlusion.
  19066. */
  19067. this.render = function ( scene, camera, viewport ) {
  19068. if ( flares.length === 0 ) return;
  19069. var tempPosition = new THREE.Vector3();
  19070. var invAspect = viewport.w / viewport.z,
  19071. halfViewportWidth = viewport.z * 0.5,
  19072. halfViewportHeight = viewport.w * 0.5;
  19073. var size = 16 / viewport.w,
  19074. scale = new THREE.Vector2( size * invAspect, size );
  19075. var screenPosition = new THREE.Vector3( 1, 1, 0 ),
  19076. screenPositionPixels = new THREE.Vector2( 1, 1 );
  19077. var validArea = new THREE.Box2();
  19078. validArea.min.set( 0, 0 );
  19079. validArea.max.set( viewport.z - 16, viewport.w - 16 );
  19080. if ( program === undefined ) {
  19081. init();
  19082. }
  19083. gl.useProgram( program );
  19084. state.initAttributes();
  19085. state.enableAttribute( attributes.vertex );
  19086. state.enableAttribute( attributes.uv );
  19087. state.disableUnusedAttributes();
  19088. // loop through all lens flares to update their occlusion and positions
  19089. // setup gl and common used attribs/uniforms
  19090. gl.uniform1i( uniforms.occlusionMap, 0 );
  19091. gl.uniform1i( uniforms.map, 1 );
  19092. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  19093. gl.vertexAttribPointer( attributes.vertex, 2, gl.FLOAT, false, 2 * 8, 0 );
  19094. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  19095. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  19096. state.disable( gl.CULL_FACE );
  19097. state.setDepthWrite( false );
  19098. for ( var i = 0, l = flares.length; i < l; i ++ ) {
  19099. size = 16 / viewport.w;
  19100. scale.set( size * invAspect, size );
  19101. // calc object screen position
  19102. var flare = flares[ i ];
  19103. tempPosition.set( flare.matrixWorld.elements[ 12 ], flare.matrixWorld.elements[ 13 ], flare.matrixWorld.elements[ 14 ] );
  19104. tempPosition.applyMatrix4( camera.matrixWorldInverse );
  19105. tempPosition.applyProjection( camera.projectionMatrix );
  19106. // setup arrays for gl programs
  19107. screenPosition.copy( tempPosition );
  19108. // horizontal and vertical coordinate of the lower left corner of the pixels to copy
  19109. screenPositionPixels.x = viewport.x + ( screenPosition.x * halfViewportWidth ) + halfViewportWidth - 8;
  19110. screenPositionPixels.y = viewport.y + ( screenPosition.y * halfViewportHeight ) + halfViewportHeight - 8;
  19111. // screen cull
  19112. if ( validArea.containsPoint( screenPositionPixels ) === true ) {
  19113. // save current RGB to temp texture
  19114. state.activeTexture( gl.TEXTURE0 );
  19115. state.bindTexture( gl.TEXTURE_2D, null );
  19116. state.activeTexture( gl.TEXTURE1 );
  19117. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  19118. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGB, screenPositionPixels.x, screenPositionPixels.y, 16, 16, 0 );
  19119. // render pink quad
  19120. gl.uniform1i( uniforms.renderType, 0 );
  19121. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  19122. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  19123. state.disable( gl.BLEND );
  19124. state.enable( gl.DEPTH_TEST );
  19125. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  19126. // copy result to occlusionMap
  19127. state.activeTexture( gl.TEXTURE0 );
  19128. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  19129. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGBA, screenPositionPixels.x, screenPositionPixels.y, 16, 16, 0 );
  19130. // restore graphics
  19131. gl.uniform1i( uniforms.renderType, 1 );
  19132. state.disable( gl.DEPTH_TEST );
  19133. state.activeTexture( gl.TEXTURE1 );
  19134. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  19135. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  19136. // update object positions
  19137. flare.positionScreen.copy( screenPosition );
  19138. if ( flare.customUpdateCallback ) {
  19139. flare.customUpdateCallback( flare );
  19140. } else {
  19141. flare.updateLensFlares();
  19142. }
  19143. // render flares
  19144. gl.uniform1i( uniforms.renderType, 2 );
  19145. state.enable( gl.BLEND );
  19146. for ( var j = 0, jl = flare.lensFlares.length; j < jl; j ++ ) {
  19147. var sprite = flare.lensFlares[ j ];
  19148. if ( sprite.opacity > 0.001 && sprite.scale > 0.001 ) {
  19149. screenPosition.x = sprite.x;
  19150. screenPosition.y = sprite.y;
  19151. screenPosition.z = sprite.z;
  19152. size = sprite.size * sprite.scale / viewport.w;
  19153. scale.x = size * invAspect;
  19154. scale.y = size;
  19155. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  19156. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  19157. gl.uniform1f( uniforms.rotation, sprite.rotation );
  19158. gl.uniform1f( uniforms.opacity, sprite.opacity );
  19159. gl.uniform3f( uniforms.color, sprite.color.r, sprite.color.g, sprite.color.b );
  19160. state.setBlending( sprite.blending, sprite.blendEquation, sprite.blendSrc, sprite.blendDst );
  19161. renderer.setTexture2D( sprite.texture, 1 );
  19162. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  19163. }
  19164. }
  19165. }
  19166. }
  19167. // restore gl
  19168. state.enable( gl.CULL_FACE );
  19169. state.enable( gl.DEPTH_TEST );
  19170. state.setDepthWrite( true );
  19171. renderer.resetGLState();
  19172. };
  19173. function createProgram ( shader ) {
  19174. var program = gl.createProgram();
  19175. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  19176. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  19177. var prefix = "precision " + renderer.getPrecision() + " float;\n";
  19178. gl.shaderSource( fragmentShader, prefix + shader.fragmentShader );
  19179. gl.shaderSource( vertexShader, prefix + shader.vertexShader );
  19180. gl.compileShader( fragmentShader );
  19181. gl.compileShader( vertexShader );
  19182. gl.attachShader( program, fragmentShader );
  19183. gl.attachShader( program, vertexShader );
  19184. gl.linkProgram( program );
  19185. return program;
  19186. }
  19187. };
  19188. // File:src/renderers/webgl/plugins/SpritePlugin.js
  19189. /**
  19190. * @author mikael emtinger / http://gomo.se/
  19191. * @author alteredq / http://alteredqualia.com/
  19192. */
  19193. THREE.SpritePlugin = function ( renderer, sprites ) {
  19194. var gl = renderer.context;
  19195. var state = renderer.state;
  19196. var vertexBuffer, elementBuffer;
  19197. var program, attributes, uniforms;
  19198. var texture;
  19199. // decompose matrixWorld
  19200. var spritePosition = new THREE.Vector3();
  19201. var spriteRotation = new THREE.Quaternion();
  19202. var spriteScale = new THREE.Vector3();
  19203. function init() {
  19204. var vertices = new Float32Array( [
  19205. - 0.5, - 0.5, 0, 0,
  19206. 0.5, - 0.5, 1, 0,
  19207. 0.5, 0.5, 1, 1,
  19208. - 0.5, 0.5, 0, 1
  19209. ] );
  19210. var faces = new Uint16Array( [
  19211. 0, 1, 2,
  19212. 0, 2, 3
  19213. ] );
  19214. vertexBuffer = gl.createBuffer();
  19215. elementBuffer = gl.createBuffer();
  19216. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  19217. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  19218. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  19219. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  19220. program = createProgram();
  19221. attributes = {
  19222. position: gl.getAttribLocation ( program, 'position' ),
  19223. uv: gl.getAttribLocation ( program, 'uv' )
  19224. };
  19225. uniforms = {
  19226. uvOffset: gl.getUniformLocation( program, 'uvOffset' ),
  19227. uvScale: gl.getUniformLocation( program, 'uvScale' ),
  19228. rotation: gl.getUniformLocation( program, 'rotation' ),
  19229. scale: gl.getUniformLocation( program, 'scale' ),
  19230. color: gl.getUniformLocation( program, 'color' ),
  19231. map: gl.getUniformLocation( program, 'map' ),
  19232. opacity: gl.getUniformLocation( program, 'opacity' ),
  19233. modelViewMatrix: gl.getUniformLocation( program, 'modelViewMatrix' ),
  19234. projectionMatrix: gl.getUniformLocation( program, 'projectionMatrix' ),
  19235. fogType: gl.getUniformLocation( program, 'fogType' ),
  19236. fogDensity: gl.getUniformLocation( program, 'fogDensity' ),
  19237. fogNear: gl.getUniformLocation( program, 'fogNear' ),
  19238. fogFar: gl.getUniformLocation( program, 'fogFar' ),
  19239. fogColor: gl.getUniformLocation( program, 'fogColor' ),
  19240. alphaTest: gl.getUniformLocation( program, 'alphaTest' )
  19241. };
  19242. var canvas = document.createElement( 'canvas' );
  19243. canvas.width = 8;
  19244. canvas.height = 8;
  19245. var context = canvas.getContext( '2d' );
  19246. context.fillStyle = 'white';
  19247. context.fillRect( 0, 0, 8, 8 );
  19248. texture = new THREE.Texture( canvas );
  19249. texture.needsUpdate = true;
  19250. }
  19251. this.render = function ( scene, camera ) {
  19252. if ( sprites.length === 0 ) return;
  19253. // setup gl
  19254. if ( program === undefined ) {
  19255. init();
  19256. }
  19257. gl.useProgram( program );
  19258. state.initAttributes();
  19259. state.enableAttribute( attributes.position );
  19260. state.enableAttribute( attributes.uv );
  19261. state.disableUnusedAttributes();
  19262. state.disable( gl.CULL_FACE );
  19263. state.enable( gl.BLEND );
  19264. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  19265. gl.vertexAttribPointer( attributes.position, 2, gl.FLOAT, false, 2 * 8, 0 );
  19266. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  19267. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  19268. gl.uniformMatrix4fv( uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
  19269. state.activeTexture( gl.TEXTURE0 );
  19270. gl.uniform1i( uniforms.map, 0 );
  19271. var oldFogType = 0;
  19272. var sceneFogType = 0;
  19273. var fog = scene.fog;
  19274. if ( fog ) {
  19275. gl.uniform3f( uniforms.fogColor, fog.color.r, fog.color.g, fog.color.b );
  19276. if ( fog instanceof THREE.Fog ) {
  19277. gl.uniform1f( uniforms.fogNear, fog.near );
  19278. gl.uniform1f( uniforms.fogFar, fog.far );
  19279. gl.uniform1i( uniforms.fogType, 1 );
  19280. oldFogType = 1;
  19281. sceneFogType = 1;
  19282. } else if ( fog instanceof THREE.FogExp2 ) {
  19283. gl.uniform1f( uniforms.fogDensity, fog.density );
  19284. gl.uniform1i( uniforms.fogType, 2 );
  19285. oldFogType = 2;
  19286. sceneFogType = 2;
  19287. }
  19288. } else {
  19289. gl.uniform1i( uniforms.fogType, 0 );
  19290. oldFogType = 0;
  19291. sceneFogType = 0;
  19292. }
  19293. // update positions and sort
  19294. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  19295. var sprite = sprites[ i ];
  19296. sprite.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, sprite.matrixWorld );
  19297. sprite.z = - sprite.modelViewMatrix.elements[ 14 ];
  19298. }
  19299. sprites.sort( painterSortStable );
  19300. // render all sprites
  19301. var scale = [];
  19302. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  19303. var sprite = sprites[ i ];
  19304. var material = sprite.material;
  19305. gl.uniform1f( uniforms.alphaTest, material.alphaTest );
  19306. gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, sprite.modelViewMatrix.elements );
  19307. sprite.matrixWorld.decompose( spritePosition, spriteRotation, spriteScale );
  19308. scale[ 0 ] = spriteScale.x;
  19309. scale[ 1 ] = spriteScale.y;
  19310. var fogType = 0;
  19311. if ( scene.fog && material.fog ) {
  19312. fogType = sceneFogType;
  19313. }
  19314. if ( oldFogType !== fogType ) {
  19315. gl.uniform1i( uniforms.fogType, fogType );
  19316. oldFogType = fogType;
  19317. }
  19318. if ( material.map !== null ) {
  19319. gl.uniform2f( uniforms.uvOffset, material.map.offset.x, material.map.offset.y );
  19320. gl.uniform2f( uniforms.uvScale, material.map.repeat.x, material.map.repeat.y );
  19321. } else {
  19322. gl.uniform2f( uniforms.uvOffset, 0, 0 );
  19323. gl.uniform2f( uniforms.uvScale, 1, 1 );
  19324. }
  19325. gl.uniform1f( uniforms.opacity, material.opacity );
  19326. gl.uniform3f( uniforms.color, material.color.r, material.color.g, material.color.b );
  19327. gl.uniform1f( uniforms.rotation, material.rotation );
  19328. gl.uniform2fv( uniforms.scale, scale );
  19329. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst );
  19330. state.setDepthTest( material.depthTest );
  19331. state.setDepthWrite( material.depthWrite );
  19332. if ( material.map ) {
  19333. renderer.setTexture2D( material.map, 0 );
  19334. } else {
  19335. renderer.setTexture2D( texture, 0 );
  19336. }
  19337. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  19338. }
  19339. // restore gl
  19340. state.enable( gl.CULL_FACE );
  19341. renderer.resetGLState();
  19342. };
  19343. function createProgram () {
  19344. var program = gl.createProgram();
  19345. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  19346. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  19347. gl.shaderSource( vertexShader, [
  19348. 'precision ' + renderer.getPrecision() + ' float;',
  19349. 'uniform mat4 modelViewMatrix;',
  19350. 'uniform mat4 projectionMatrix;',
  19351. 'uniform float rotation;',
  19352. 'uniform vec2 scale;',
  19353. 'uniform vec2 uvOffset;',
  19354. 'uniform vec2 uvScale;',
  19355. 'attribute vec2 position;',
  19356. 'attribute vec2 uv;',
  19357. 'varying vec2 vUV;',
  19358. 'void main() {',
  19359. 'vUV = uvOffset + uv * uvScale;',
  19360. 'vec2 alignedPosition = position * scale;',
  19361. 'vec2 rotatedPosition;',
  19362. 'rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;',
  19363. 'rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;',
  19364. 'vec4 finalPosition;',
  19365. 'finalPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );',
  19366. 'finalPosition.xy += rotatedPosition;',
  19367. 'finalPosition = projectionMatrix * finalPosition;',
  19368. 'gl_Position = finalPosition;',
  19369. '}'
  19370. ].join( '\n' ) );
  19371. gl.shaderSource( fragmentShader, [
  19372. 'precision ' + renderer.getPrecision() + ' float;',
  19373. 'uniform vec3 color;',
  19374. 'uniform sampler2D map;',
  19375. 'uniform float opacity;',
  19376. 'uniform int fogType;',
  19377. 'uniform vec3 fogColor;',
  19378. 'uniform float fogDensity;',
  19379. 'uniform float fogNear;',
  19380. 'uniform float fogFar;',
  19381. 'uniform float alphaTest;',
  19382. 'varying vec2 vUV;',
  19383. 'void main() {',
  19384. 'vec4 texture = texture2D( map, vUV );',
  19385. 'if ( texture.a < alphaTest ) discard;',
  19386. 'gl_FragColor = vec4( color * texture.xyz, texture.a * opacity );',
  19387. 'if ( fogType > 0 ) {',
  19388. 'float depth = gl_FragCoord.z / gl_FragCoord.w;',
  19389. 'float fogFactor = 0.0;',
  19390. 'if ( fogType == 1 ) {',
  19391. 'fogFactor = smoothstep( fogNear, fogFar, depth );',
  19392. '} else {',
  19393. 'const float LOG2 = 1.442695;',
  19394. 'fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );',
  19395. 'fogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );',
  19396. '}',
  19397. 'gl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );',
  19398. '}',
  19399. '}'
  19400. ].join( '\n' ) );
  19401. gl.compileShader( vertexShader );
  19402. gl.compileShader( fragmentShader );
  19403. gl.attachShader( program, vertexShader );
  19404. gl.attachShader( program, fragmentShader );
  19405. gl.linkProgram( program );
  19406. return program;
  19407. }
  19408. function painterSortStable ( a, b ) {
  19409. if ( a.renderOrder !== b.renderOrder ) {
  19410. return a.renderOrder - b.renderOrder;
  19411. } else if ( a.z !== b.z ) {
  19412. return b.z - a.z;
  19413. } else {
  19414. return b.id - a.id;
  19415. }
  19416. }
  19417. };
  19418. // File:src/Three.Legacy.js
  19419. /**
  19420. * @author mrdoob / http://mrdoob.com/
  19421. */
  19422. Object.assign( THREE, {
  19423. Face4: function ( a, b, c, d, normal, color, materialIndex ) {
  19424. console.warn( 'THREE.Face4 has been removed. A THREE.Face3 will be created instead.' );
  19425. return new THREE.Face3( a, b, c, normal, color, materialIndex );
  19426. },
  19427. LineStrip: 0,
  19428. LinePieces: 1,
  19429. MeshFaceMaterial: THREE.MultiMaterial,
  19430. PointCloud: function ( geometry, material ) {
  19431. console.warn( 'THREE.PointCloud has been renamed to THREE.Points.' );
  19432. return new THREE.Points( geometry, material );
  19433. },
  19434. Particle: THREE.Sprite,
  19435. ParticleSystem: function ( geometry, material ) {
  19436. console.warn( 'THREE.ParticleSystem has been renamed to THREE.Points.' );
  19437. return new THREE.Points( geometry, material );
  19438. },
  19439. PointCloudMaterial: function ( parameters ) {
  19440. console.warn( 'THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.' );
  19441. return new THREE.PointsMaterial( parameters );
  19442. },
  19443. ParticleBasicMaterial: function ( parameters ) {
  19444. console.warn( 'THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.' );
  19445. return new THREE.PointsMaterial( parameters );
  19446. },
  19447. ParticleSystemMaterial: function ( parameters ) {
  19448. console.warn( 'THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.' );
  19449. return new THREE.PointsMaterial( parameters );
  19450. },
  19451. Vertex: function ( x, y, z ) {
  19452. console.warn( 'THREE.Vertex has been removed. Use THREE.Vector3 instead.' );
  19453. return new THREE.Vector3( x, y, z );
  19454. }
  19455. } );
  19456. //
  19457. Object.assign( THREE.Box2.prototype, {
  19458. empty: function () {
  19459. console.warn( 'THREE.Box2: .empty() has been renamed to .isEmpty().' );
  19460. return this.isEmpty();
  19461. },
  19462. isIntersectionBox: function ( box ) {
  19463. console.warn( 'THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().' );
  19464. return this.intersectsBox( box );
  19465. }
  19466. } );
  19467. Object.assign( THREE.Box3.prototype, {
  19468. empty: function () {
  19469. console.warn( 'THREE.Box3: .empty() has been renamed to .isEmpty().' );
  19470. return this.isEmpty();
  19471. },
  19472. isIntersectionBox: function ( box ) {
  19473. console.warn( 'THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().' );
  19474. return this.intersectsBox( box );
  19475. },
  19476. isIntersectionSphere: function ( sphere ) {
  19477. console.warn( 'THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  19478. return this.intersectsSphere( sphere );
  19479. }
  19480. } );
  19481. Object.assign( THREE.Matrix3.prototype, {
  19482. multiplyVector3: function ( vector ) {
  19483. console.warn( 'THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.' );
  19484. return vector.applyMatrix3( this );
  19485. },
  19486. multiplyVector3Array: function ( a ) {
  19487. console.warn( 'THREE.Matrix3: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
  19488. return this.applyToVector3Array( a );
  19489. }
  19490. } );
  19491. Object.assign( THREE.Matrix4.prototype, {
  19492. extractPosition: function ( m ) {
  19493. console.warn( 'THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().' );
  19494. return this.copyPosition( m );
  19495. },
  19496. setRotationFromQuaternion: function ( q ) {
  19497. console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' );
  19498. return this.makeRotationFromQuaternion( q );
  19499. },
  19500. multiplyVector3: function ( vector ) {
  19501. console.warn( 'THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) or vector.applyProjection( matrix ) instead.' );
  19502. return vector.applyProjection( this );
  19503. },
  19504. multiplyVector4: function ( vector ) {
  19505. console.warn( 'THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  19506. return vector.applyMatrix4( this );
  19507. },
  19508. multiplyVector3Array: function ( a ) {
  19509. console.warn( 'THREE.Matrix4: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
  19510. return this.applyToVector3Array( a );
  19511. },
  19512. rotateAxis: function ( v ) {
  19513. console.warn( 'THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.' );
  19514. v.transformDirection( this );
  19515. },
  19516. crossVector: function ( vector ) {
  19517. console.warn( 'THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  19518. return vector.applyMatrix4( this );
  19519. },
  19520. translate: function ( v ) {
  19521. console.error( 'THREE.Matrix4: .translate() has been removed.' );
  19522. },
  19523. rotateX: function ( angle ) {
  19524. console.error( 'THREE.Matrix4: .rotateX() has been removed.' );
  19525. },
  19526. rotateY: function ( angle ) {
  19527. console.error( 'THREE.Matrix4: .rotateY() has been removed.' );
  19528. },
  19529. rotateZ: function ( angle ) {
  19530. console.error( 'THREE.Matrix4: .rotateZ() has been removed.' );
  19531. },
  19532. rotateByAxis: function ( axis, angle ) {
  19533. console.error( 'THREE.Matrix4: .rotateByAxis() has been removed.' );
  19534. }
  19535. } );
  19536. Object.assign( THREE.Plane.prototype, {
  19537. isIntersectionLine: function ( line ) {
  19538. console.warn( 'THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().' );
  19539. return this.intersectsLine( line );
  19540. }
  19541. } );
  19542. Object.assign( THREE.Quaternion.prototype, {
  19543. multiplyVector3: function ( vector ) {
  19544. console.warn( 'THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.' );
  19545. return vector.applyQuaternion( this );
  19546. }
  19547. } );
  19548. Object.assign( THREE.Ray.prototype, {
  19549. isIntersectionBox: function ( box ) {
  19550. console.warn( 'THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().' );
  19551. return this.intersectsBox( box );
  19552. },
  19553. isIntersectionPlane: function ( plane ) {
  19554. console.warn( 'THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().' );
  19555. return this.intersectsPlane( plane );
  19556. },
  19557. isIntersectionSphere: function ( sphere ) {
  19558. console.warn( 'THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  19559. return this.intersectsSphere( sphere );
  19560. }
  19561. } );
  19562. Object.assign( THREE.Vector3.prototype, {
  19563. setEulerFromRotationMatrix: function () {
  19564. console.error( 'THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.' );
  19565. },
  19566. setEulerFromQuaternion: function () {
  19567. console.error( 'THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.' );
  19568. },
  19569. getPositionFromMatrix: function ( m ) {
  19570. console.warn( 'THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().' );
  19571. return this.setFromMatrixPosition( m );
  19572. },
  19573. getScaleFromMatrix: function ( m ) {
  19574. console.warn( 'THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().' );
  19575. return this.setFromMatrixScale( m );
  19576. },
  19577. getColumnFromMatrix: function ( index, matrix ) {
  19578. console.warn( 'THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().' );
  19579. return this.setFromMatrixColumn( matrix, index );
  19580. }
  19581. } );
  19582. //
  19583. Object.assign( THREE.Object3D.prototype, {
  19584. getChildByName: function ( name ) {
  19585. console.warn( 'THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().' );
  19586. return this.getObjectByName( name );
  19587. },
  19588. renderDepth: function ( value ) {
  19589. console.warn( 'THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.' );
  19590. },
  19591. translate: function ( distance, axis ) {
  19592. console.warn( 'THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.' );
  19593. return this.translateOnAxis( axis, distance );
  19594. }
  19595. } );
  19596. Object.defineProperties( THREE.Object3D.prototype, {
  19597. eulerOrder: {
  19598. get: function () {
  19599. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  19600. return this.rotation.order;
  19601. },
  19602. set: function ( value ) {
  19603. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  19604. this.rotation.order = value;
  19605. }
  19606. },
  19607. useQuaternion: {
  19608. get: function () {
  19609. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  19610. },
  19611. set: function ( value ) {
  19612. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  19613. }
  19614. }
  19615. } );
  19616. Object.defineProperties( THREE.LOD.prototype, {
  19617. objects: {
  19618. get: function () {
  19619. console.warn( 'THREE.LOD: .objects has been renamed to .levels.' );
  19620. return this.levels;
  19621. }
  19622. }
  19623. } );
  19624. //
  19625. THREE.PerspectiveCamera.prototype.setLens = function ( focalLength, filmGauge ) {
  19626. console.warn( "THREE.PerspectiveCamera.setLens is deprecated. " +
  19627. "Use .setFocalLength and .filmGauge for a photographic setup." );
  19628. if ( filmGauge !== undefined ) this.filmGauge = filmGauge;
  19629. this.setFocalLength( focalLength );
  19630. };
  19631. //
  19632. Object.defineProperties( THREE.Light.prototype, {
  19633. onlyShadow: {
  19634. set: function ( value ) {
  19635. console.warn( 'THREE.Light: .onlyShadow has been removed.' );
  19636. }
  19637. },
  19638. shadowCameraFov: {
  19639. set: function ( value ) {
  19640. console.warn( 'THREE.Light: .shadowCameraFov is now .shadow.camera.fov.' );
  19641. this.shadow.camera.fov = value;
  19642. }
  19643. },
  19644. shadowCameraLeft: {
  19645. set: function ( value ) {
  19646. console.warn( 'THREE.Light: .shadowCameraLeft is now .shadow.camera.left.' );
  19647. this.shadow.camera.left = value;
  19648. }
  19649. },
  19650. shadowCameraRight: {
  19651. set: function ( value ) {
  19652. console.warn( 'THREE.Light: .shadowCameraRight is now .shadow.camera.right.' );
  19653. this.shadow.camera.right = value;
  19654. }
  19655. },
  19656. shadowCameraTop: {
  19657. set: function ( value ) {
  19658. console.warn( 'THREE.Light: .shadowCameraTop is now .shadow.camera.top.' );
  19659. this.shadow.camera.top = value;
  19660. }
  19661. },
  19662. shadowCameraBottom: {
  19663. set: function ( value ) {
  19664. console.warn( 'THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.' );
  19665. this.shadow.camera.bottom = value;
  19666. }
  19667. },
  19668. shadowCameraNear: {
  19669. set: function ( value ) {
  19670. console.warn( 'THREE.Light: .shadowCameraNear is now .shadow.camera.near.' );
  19671. this.shadow.camera.near = value;
  19672. }
  19673. },
  19674. shadowCameraFar: {
  19675. set: function ( value ) {
  19676. console.warn( 'THREE.Light: .shadowCameraFar is now .shadow.camera.far.' );
  19677. this.shadow.camera.far = value;
  19678. }
  19679. },
  19680. shadowCameraVisible: {
  19681. set: function ( value ) {
  19682. console.warn( 'THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.' );
  19683. }
  19684. },
  19685. shadowBias: {
  19686. set: function ( value ) {
  19687. console.warn( 'THREE.Light: .shadowBias is now .shadow.bias.' );
  19688. this.shadow.bias = value;
  19689. }
  19690. },
  19691. shadowDarkness: {
  19692. set: function ( value ) {
  19693. console.warn( 'THREE.Light: .shadowDarkness has been removed.' );
  19694. }
  19695. },
  19696. shadowMapWidth: {
  19697. set: function ( value ) {
  19698. console.warn( 'THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.' );
  19699. this.shadow.mapSize.width = value;
  19700. }
  19701. },
  19702. shadowMapHeight: {
  19703. set: function ( value ) {
  19704. console.warn( 'THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.' );
  19705. this.shadow.mapSize.height = value;
  19706. }
  19707. }
  19708. } );
  19709. //
  19710. Object.defineProperties( THREE.BufferAttribute.prototype, {
  19711. length: {
  19712. get: function () {
  19713. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Please use .count.' );
  19714. return this.array.length;
  19715. }
  19716. }
  19717. } );
  19718. Object.assign( THREE.BufferGeometry.prototype, {
  19719. addIndex: function ( index ) {
  19720. console.warn( 'THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().' );
  19721. this.setIndex( index );
  19722. },
  19723. addDrawCall: function ( start, count, indexOffset ) {
  19724. if ( indexOffset !== undefined ) {
  19725. console.warn( 'THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.' );
  19726. }
  19727. console.warn( 'THREE.BufferGeometry: .addDrawCall() is now .addGroup().' );
  19728. this.addGroup( start, count );
  19729. },
  19730. clearDrawCalls: function () {
  19731. console.warn( 'THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().' );
  19732. this.clearGroups();
  19733. },
  19734. computeTangents: function () {
  19735. console.warn( 'THREE.BufferGeometry: .computeTangents() has been removed.' );
  19736. },
  19737. computeOffsets: function () {
  19738. console.warn( 'THREE.BufferGeometry: .computeOffsets() has been removed.' );
  19739. }
  19740. } );
  19741. Object.defineProperties( THREE.BufferGeometry.prototype, {
  19742. drawcalls: {
  19743. get: function () {
  19744. console.error( 'THREE.BufferGeometry: .drawcalls has been renamed to .groups.' );
  19745. return this.groups;
  19746. }
  19747. },
  19748. offsets: {
  19749. get: function () {
  19750. console.warn( 'THREE.BufferGeometry: .offsets has been renamed to .groups.' );
  19751. return this.groups;
  19752. }
  19753. }
  19754. } );
  19755. //
  19756. Object.defineProperties( THREE.Material.prototype, {
  19757. wrapAround: {
  19758. get: function () {
  19759. console.warn( 'THREE.' + this.type + ': .wrapAround has been removed.' );
  19760. },
  19761. set: function ( value ) {
  19762. console.warn( 'THREE.' + this.type + ': .wrapAround has been removed.' );
  19763. }
  19764. },
  19765. wrapRGB: {
  19766. get: function () {
  19767. console.warn( 'THREE.' + this.type + ': .wrapRGB has been removed.' );
  19768. return new THREE.Color();
  19769. }
  19770. }
  19771. } );
  19772. Object.defineProperties( THREE.MeshPhongMaterial.prototype, {
  19773. metal: {
  19774. get: function () {
  19775. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.' );
  19776. return false;
  19777. },
  19778. set: function ( value ) {
  19779. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead' );
  19780. }
  19781. }
  19782. } );
  19783. Object.defineProperties( THREE.ShaderMaterial.prototype, {
  19784. derivatives: {
  19785. get: function () {
  19786. console.warn( 'THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  19787. return this.extensions.derivatives;
  19788. },
  19789. set: function ( value ) {
  19790. console.warn( 'THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  19791. this.extensions.derivatives = value;
  19792. }
  19793. }
  19794. } );
  19795. //
  19796. THREE.EventDispatcher.prototype = Object.assign( Object.create( {
  19797. // Note: Extra base ensures these properties are not 'assign'ed.
  19798. constructor: THREE.EventDispatcher,
  19799. apply: function ( target ) {
  19800. console.warn( "THREE.EventDispatcher: .apply is deprecated, " +
  19801. "just inherit or Object.assign the prototype to mix-in." );
  19802. Object.assign( target, this );
  19803. }
  19804. } ), THREE.EventDispatcher.prototype );
  19805. //
  19806. Object.assign( THREE.WebGLRenderer.prototype, {
  19807. supportsFloatTextures: function () {
  19808. console.warn( 'THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).' );
  19809. return this.extensions.get( 'OES_texture_float' );
  19810. },
  19811. supportsHalfFloatTextures: function () {
  19812. console.warn( 'THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).' );
  19813. return this.extensions.get( 'OES_texture_half_float' );
  19814. },
  19815. supportsStandardDerivatives: function () {
  19816. console.warn( 'THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).' );
  19817. return this.extensions.get( 'OES_standard_derivatives' );
  19818. },
  19819. supportsCompressedTextureS3TC: function () {
  19820. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).' );
  19821. return this.extensions.get( 'WEBGL_compressed_texture_s3tc' );
  19822. },
  19823. supportsCompressedTexturePVRTC: function () {
  19824. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).' );
  19825. return this.extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  19826. },
  19827. supportsBlendMinMax: function () {
  19828. console.warn( 'THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).' );
  19829. return this.extensions.get( 'EXT_blend_minmax' );
  19830. },
  19831. supportsVertexTextures: function () {
  19832. return this.capabilities.vertexTextures;
  19833. },
  19834. supportsInstancedArrays: function () {
  19835. console.warn( 'THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).' );
  19836. return this.extensions.get( 'ANGLE_instanced_arrays' );
  19837. },
  19838. enableScissorTest: function ( boolean ) {
  19839. console.warn( 'THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().' );
  19840. this.setScissorTest( boolean );
  19841. },
  19842. initMaterial: function () {
  19843. console.warn( 'THREE.WebGLRenderer: .initMaterial() has been removed.' );
  19844. },
  19845. addPrePlugin: function () {
  19846. console.warn( 'THREE.WebGLRenderer: .addPrePlugin() has been removed.' );
  19847. },
  19848. addPostPlugin: function () {
  19849. console.warn( 'THREE.WebGLRenderer: .addPostPlugin() has been removed.' );
  19850. },
  19851. updateShadowMap: function () {
  19852. console.warn( 'THREE.WebGLRenderer: .updateShadowMap() has been removed.' );
  19853. }
  19854. } );
  19855. Object.defineProperties( THREE.WebGLRenderer.prototype, {
  19856. shadowMapEnabled: {
  19857. get: function () {
  19858. return this.shadowMap.enabled;
  19859. },
  19860. set: function ( value ) {
  19861. console.warn( 'THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.' );
  19862. this.shadowMap.enabled = value;
  19863. }
  19864. },
  19865. shadowMapType: {
  19866. get: function () {
  19867. return this.shadowMap.type;
  19868. },
  19869. set: function ( value ) {
  19870. console.warn( 'THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.' );
  19871. this.shadowMap.type = value;
  19872. }
  19873. },
  19874. shadowMapCullFace: {
  19875. get: function () {
  19876. return this.shadowMap.cullFace;
  19877. },
  19878. set: function ( value ) {
  19879. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace is now .shadowMap.cullFace.' );
  19880. this.shadowMap.cullFace = value;
  19881. }
  19882. }
  19883. } );
  19884. Object.defineProperties( THREE.WebGLShadowMap.prototype, {
  19885. cullFace: {
  19886. get: function () {
  19887. return this.renderReverseSided ? THREE.CullFaceFront : THREE.CullFaceBack;
  19888. },
  19889. set: function ( cullFace ) {
  19890. var value = ( cullFace !== THREE.CullFaceBack );
  19891. console.warn( "WebGLRenderer: .shadowMap.cullFace is deprecated. Set .shadowMap.renderReverseSided to " + value + "." );
  19892. this.renderReverseSided = value;
  19893. }
  19894. }
  19895. } );
  19896. //
  19897. Object.defineProperties( THREE.WebGLRenderTarget.prototype, {
  19898. wrapS: {
  19899. get: function () {
  19900. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  19901. return this.texture.wrapS;
  19902. },
  19903. set: function ( value ) {
  19904. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  19905. this.texture.wrapS = value;
  19906. }
  19907. },
  19908. wrapT: {
  19909. get: function () {
  19910. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  19911. return this.texture.wrapT;
  19912. },
  19913. set: function ( value ) {
  19914. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  19915. this.texture.wrapT = value;
  19916. }
  19917. },
  19918. magFilter: {
  19919. get: function () {
  19920. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  19921. return this.texture.magFilter;
  19922. },
  19923. set: function ( value ) {
  19924. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  19925. this.texture.magFilter = value;
  19926. }
  19927. },
  19928. minFilter: {
  19929. get: function () {
  19930. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  19931. return this.texture.minFilter;
  19932. },
  19933. set: function ( value ) {
  19934. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  19935. this.texture.minFilter = value;
  19936. }
  19937. },
  19938. anisotropy: {
  19939. get: function () {
  19940. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  19941. return this.texture.anisotropy;
  19942. },
  19943. set: function ( value ) {
  19944. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  19945. this.texture.anisotropy = value;
  19946. }
  19947. },
  19948. offset: {
  19949. get: function () {
  19950. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  19951. return this.texture.offset;
  19952. },
  19953. set: function ( value ) {
  19954. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  19955. this.texture.offset = value;
  19956. }
  19957. },
  19958. repeat: {
  19959. get: function () {
  19960. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  19961. return this.texture.repeat;
  19962. },
  19963. set: function ( value ) {
  19964. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  19965. this.texture.repeat = value;
  19966. }
  19967. },
  19968. format: {
  19969. get: function () {
  19970. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  19971. return this.texture.format;
  19972. },
  19973. set: function ( value ) {
  19974. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  19975. this.texture.format = value;
  19976. }
  19977. },
  19978. type: {
  19979. get: function () {
  19980. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  19981. return this.texture.type;
  19982. },
  19983. set: function ( value ) {
  19984. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  19985. this.texture.type = value;
  19986. }
  19987. },
  19988. generateMipmaps: {
  19989. get: function () {
  19990. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  19991. return this.texture.generateMipmaps;
  19992. },
  19993. set: function ( value ) {
  19994. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  19995. this.texture.generateMipmaps = value;
  19996. }
  19997. }
  19998. } );
  19999. //
  20000. Object.assign( THREE.Audio.prototype, {
  20001. load: function ( file ) {
  20002. console.warn( 'THREE.Audio: .load has been deprecated. Please use THREE.AudioLoader.' );
  20003. var scope = this;
  20004. var audioLoader = new THREE.AudioLoader();
  20005. audioLoader.load( file, function ( buffer ) {
  20006. scope.setBuffer( buffer );
  20007. } );
  20008. return this;
  20009. }
  20010. } );
  20011. Object.assign( THREE.AudioAnalyser.prototype, {
  20012. getData: function ( file ) {
  20013. console.warn( 'THREE.AudioAnalyser: .getData() is now .getFrequencyData().' );
  20014. return this.getFrequencyData();
  20015. }
  20016. } );
  20017. //
  20018. THREE.GeometryUtils = {
  20019. merge: function ( geometry1, geometry2, materialIndexOffset ) {
  20020. console.warn( 'THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.' );
  20021. var matrix;
  20022. if ( geometry2 instanceof THREE.Mesh ) {
  20023. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  20024. matrix = geometry2.matrix;
  20025. geometry2 = geometry2.geometry;
  20026. }
  20027. geometry1.merge( geometry2, matrix, materialIndexOffset );
  20028. },
  20029. center: function ( geometry ) {
  20030. console.warn( 'THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.' );
  20031. return geometry.center();
  20032. }
  20033. };
  20034. THREE.ImageUtils = {
  20035. crossOrigin: undefined,
  20036. loadTexture: function ( url, mapping, onLoad, onError ) {
  20037. console.warn( 'THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.' );
  20038. var loader = new THREE.TextureLoader();
  20039. loader.setCrossOrigin( this.crossOrigin );
  20040. var texture = loader.load( url, onLoad, undefined, onError );
  20041. if ( mapping ) texture.mapping = mapping;
  20042. return texture;
  20043. },
  20044. loadTextureCube: function ( urls, mapping, onLoad, onError ) {
  20045. console.warn( 'THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.' );
  20046. var loader = new THREE.CubeTextureLoader();
  20047. loader.setCrossOrigin( this.crossOrigin );
  20048. var texture = loader.load( urls, onLoad, undefined, onError );
  20049. if ( mapping ) texture.mapping = mapping;
  20050. return texture;
  20051. },
  20052. loadCompressedTexture: function () {
  20053. console.error( 'THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.' );
  20054. },
  20055. loadCompressedTextureCube: function () {
  20056. console.error( 'THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.' );
  20057. }
  20058. };
  20059. //
  20060. THREE.Projector = function () {
  20061. console.error( 'THREE.Projector has been moved to /examples/js/renderers/Projector.js.' );
  20062. this.projectVector = function ( vector, camera ) {
  20063. console.warn( 'THREE.Projector: .projectVector() is now vector.project().' );
  20064. vector.project( camera );
  20065. };
  20066. this.unprojectVector = function ( vector, camera ) {
  20067. console.warn( 'THREE.Projector: .unprojectVector() is now vector.unproject().' );
  20068. vector.unproject( camera );
  20069. };
  20070. this.pickingRay = function ( vector, camera ) {
  20071. console.error( 'THREE.Projector: .pickingRay() is now raycaster.setFromCamera().' );
  20072. };
  20073. };
  20074. //
  20075. THREE.CanvasRenderer = function () {
  20076. console.error( 'THREE.CanvasRenderer has been moved to /examples/js/renderers/CanvasRenderer.js' );
  20077. this.domElement = document.createElement( 'canvas' );
  20078. this.clear = function () {};
  20079. this.render = function () {};
  20080. this.setClearColor = function () {};
  20081. this.setSize = function () {};
  20082. };
  20083. // File:src/extras/CurveUtils.js
  20084. /**
  20085. * @author zz85 / http://www.lab4games.net/zz85/blog
  20086. */
  20087. THREE.CurveUtils = {
  20088. tangentQuadraticBezier: function ( t, p0, p1, p2 ) {
  20089. return 2 * ( 1 - t ) * ( p1 - p0 ) + 2 * t * ( p2 - p1 );
  20090. },
  20091. // Puay Bing, thanks for helping with this derivative!
  20092. tangentCubicBezier: function ( t, p0, p1, p2, p3 ) {
  20093. return - 3 * p0 * ( 1 - t ) * ( 1 - t ) +
  20094. 3 * p1 * ( 1 - t ) * ( 1 - t ) - 6 * t * p1 * ( 1 - t ) +
  20095. 6 * t * p2 * ( 1 - t ) - 3 * t * t * p2 +
  20096. 3 * t * t * p3;
  20097. },
  20098. tangentSpline: function ( t, p0, p1, p2, p3 ) {
  20099. // To check if my formulas are correct
  20100. var h00 = 6 * t * t - 6 * t; // derived from 2t^3 − 3t^2 + 1
  20101. var h10 = 3 * t * t - 4 * t + 1; // t^3 − 2t^2 + t
  20102. var h01 = - 6 * t * t + 6 * t; // − 2t3 + 3t2
  20103. var h11 = 3 * t * t - 2 * t; // t3 − t2
  20104. return h00 + h10 + h01 + h11;
  20105. },
  20106. // Catmull-Rom
  20107. interpolate: function( p0, p1, p2, p3, t ) {
  20108. var v0 = ( p2 - p0 ) * 0.5;
  20109. var v1 = ( p3 - p1 ) * 0.5;
  20110. var t2 = t * t;
  20111. var t3 = t * t2;
  20112. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  20113. }
  20114. };
  20115. // File:src/extras/SceneUtils.js
  20116. /**
  20117. * @author alteredq / http://alteredqualia.com/
  20118. */
  20119. THREE.SceneUtils = {
  20120. createMultiMaterialObject: function ( geometry, materials ) {
  20121. var group = new THREE.Group();
  20122. for ( var i = 0, l = materials.length; i < l; i ++ ) {
  20123. group.add( new THREE.Mesh( geometry, materials[ i ] ) );
  20124. }
  20125. return group;
  20126. },
  20127. detach: function ( child, parent, scene ) {
  20128. child.applyMatrix( parent.matrixWorld );
  20129. parent.remove( child );
  20130. scene.add( child );
  20131. },
  20132. attach: function ( child, scene, parent ) {
  20133. var matrixWorldInverse = new THREE.Matrix4();
  20134. matrixWorldInverse.getInverse( parent.matrixWorld );
  20135. child.applyMatrix( matrixWorldInverse );
  20136. scene.remove( child );
  20137. parent.add( child );
  20138. }
  20139. };
  20140. // File:src/extras/ShapeUtils.js
  20141. /**
  20142. * @author zz85 / http://www.lab4games.net/zz85/blog
  20143. */
  20144. THREE.ShapeUtils = {
  20145. // calculate area of the contour polygon
  20146. area: function ( contour ) {
  20147. var n = contour.length;
  20148. var a = 0.0;
  20149. for ( var p = n - 1, q = 0; q < n; p = q ++ ) {
  20150. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  20151. }
  20152. return a * 0.5;
  20153. },
  20154. triangulate: ( function () {
  20155. /**
  20156. * This code is a quick port of code written in C++ which was submitted to
  20157. * flipcode.com by John W. Ratcliff // July 22, 2000
  20158. * See original code and more information here:
  20159. * http://www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml
  20160. *
  20161. * ported to actionscript by Zevan Rosser
  20162. * www.actionsnippet.com
  20163. *
  20164. * ported to javascript by Joshua Koo
  20165. * http://www.lab4games.net/zz85/blog
  20166. *
  20167. */
  20168. function snip( contour, u, v, w, n, verts ) {
  20169. var p;
  20170. var ax, ay, bx, by;
  20171. var cx, cy, px, py;
  20172. ax = contour[ verts[ u ] ].x;
  20173. ay = contour[ verts[ u ] ].y;
  20174. bx = contour[ verts[ v ] ].x;
  20175. by = contour[ verts[ v ] ].y;
  20176. cx = contour[ verts[ w ] ].x;
  20177. cy = contour[ verts[ w ] ].y;
  20178. if ( Number.EPSILON > ( ( ( bx - ax ) * ( cy - ay ) ) - ( ( by - ay ) * ( cx - ax ) ) ) ) return false;
  20179. var aX, aY, bX, bY, cX, cY;
  20180. var apx, apy, bpx, bpy, cpx, cpy;
  20181. var cCROSSap, bCROSScp, aCROSSbp;
  20182. aX = cx - bx; aY = cy - by;
  20183. bX = ax - cx; bY = ay - cy;
  20184. cX = bx - ax; cY = by - ay;
  20185. for ( p = 0; p < n; p ++ ) {
  20186. px = contour[ verts[ p ] ].x;
  20187. py = contour[ verts[ p ] ].y;
  20188. if ( ( ( px === ax ) && ( py === ay ) ) ||
  20189. ( ( px === bx ) && ( py === by ) ) ||
  20190. ( ( px === cx ) && ( py === cy ) ) ) continue;
  20191. apx = px - ax; apy = py - ay;
  20192. bpx = px - bx; bpy = py - by;
  20193. cpx = px - cx; cpy = py - cy;
  20194. // see if p is inside triangle abc
  20195. aCROSSbp = aX * bpy - aY * bpx;
  20196. cCROSSap = cX * apy - cY * apx;
  20197. bCROSScp = bX * cpy - bY * cpx;
  20198. if ( ( aCROSSbp >= - Number.EPSILON ) && ( bCROSScp >= - Number.EPSILON ) && ( cCROSSap >= - Number.EPSILON ) ) return false;
  20199. }
  20200. return true;
  20201. }
  20202. // takes in an contour array and returns
  20203. return function ( contour, indices ) {
  20204. var n = contour.length;
  20205. if ( n < 3 ) return null;
  20206. var result = [],
  20207. verts = [],
  20208. vertIndices = [];
  20209. /* we want a counter-clockwise polygon in verts */
  20210. var u, v, w;
  20211. if ( THREE.ShapeUtils.area( contour ) > 0.0 ) {
  20212. for ( v = 0; v < n; v ++ ) verts[ v ] = v;
  20213. } else {
  20214. for ( v = 0; v < n; v ++ ) verts[ v ] = ( n - 1 ) - v;
  20215. }
  20216. var nv = n;
  20217. /* remove nv - 2 vertices, creating 1 triangle every time */
  20218. var count = 2 * nv; /* error detection */
  20219. for ( v = nv - 1; nv > 2; ) {
  20220. /* if we loop, it is probably a non-simple polygon */
  20221. if ( ( count -- ) <= 0 ) {
  20222. //** Triangulate: ERROR - probable bad polygon!
  20223. //throw ( "Warning, unable to triangulate polygon!" );
  20224. //return null;
  20225. // Sometimes warning is fine, especially polygons are triangulated in reverse.
  20226. console.warn( 'THREE.ShapeUtils: Unable to triangulate polygon! in triangulate()' );
  20227. if ( indices ) return vertIndices;
  20228. return result;
  20229. }
  20230. /* three consecutive vertices in current polygon, <u,v,w> */
  20231. u = v; if ( nv <= u ) u = 0; /* previous */
  20232. v = u + 1; if ( nv <= v ) v = 0; /* new v */
  20233. w = v + 1; if ( nv <= w ) w = 0; /* next */
  20234. if ( snip( contour, u, v, w, nv, verts ) ) {
  20235. var a, b, c, s, t;
  20236. /* true names of the vertices */
  20237. a = verts[ u ];
  20238. b = verts[ v ];
  20239. c = verts[ w ];
  20240. /* output Triangle */
  20241. result.push( [ contour[ a ],
  20242. contour[ b ],
  20243. contour[ c ] ] );
  20244. vertIndices.push( [ verts[ u ], verts[ v ], verts[ w ] ] );
  20245. /* remove v from the remaining polygon */
  20246. for ( s = v, t = v + 1; t < nv; s ++, t ++ ) {
  20247. verts[ s ] = verts[ t ];
  20248. }
  20249. nv --;
  20250. /* reset error detection counter */
  20251. count = 2 * nv;
  20252. }
  20253. }
  20254. if ( indices ) return vertIndices;
  20255. return result;
  20256. }
  20257. } )(),
  20258. triangulateShape: function ( contour, holes ) {
  20259. function point_in_segment_2D_colin( inSegPt1, inSegPt2, inOtherPt ) {
  20260. // inOtherPt needs to be collinear to the inSegment
  20261. if ( inSegPt1.x !== inSegPt2.x ) {
  20262. if ( inSegPt1.x < inSegPt2.x ) {
  20263. return ( ( inSegPt1.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt2.x ) );
  20264. } else {
  20265. return ( ( inSegPt2.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt1.x ) );
  20266. }
  20267. } else {
  20268. if ( inSegPt1.y < inSegPt2.y ) {
  20269. return ( ( inSegPt1.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt2.y ) );
  20270. } else {
  20271. return ( ( inSegPt2.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt1.y ) );
  20272. }
  20273. }
  20274. }
  20275. function intersect_segments_2D( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1, inSeg2Pt2, inExcludeAdjacentSegs ) {
  20276. var seg1dx = inSeg1Pt2.x - inSeg1Pt1.x, seg1dy = inSeg1Pt2.y - inSeg1Pt1.y;
  20277. var seg2dx = inSeg2Pt2.x - inSeg2Pt1.x, seg2dy = inSeg2Pt2.y - inSeg2Pt1.y;
  20278. var seg1seg2dx = inSeg1Pt1.x - inSeg2Pt1.x;
  20279. var seg1seg2dy = inSeg1Pt1.y - inSeg2Pt1.y;
  20280. var limit = seg1dy * seg2dx - seg1dx * seg2dy;
  20281. var perpSeg1 = seg1dy * seg1seg2dx - seg1dx * seg1seg2dy;
  20282. if ( Math.abs( limit ) > Number.EPSILON ) {
  20283. // not parallel
  20284. var perpSeg2;
  20285. if ( limit > 0 ) {
  20286. if ( ( perpSeg1 < 0 ) || ( perpSeg1 > limit ) ) return [];
  20287. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  20288. if ( ( perpSeg2 < 0 ) || ( perpSeg2 > limit ) ) return [];
  20289. } else {
  20290. if ( ( perpSeg1 > 0 ) || ( perpSeg1 < limit ) ) return [];
  20291. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  20292. if ( ( perpSeg2 > 0 ) || ( perpSeg2 < limit ) ) return [];
  20293. }
  20294. // i.e. to reduce rounding errors
  20295. // intersection at endpoint of segment#1?
  20296. if ( perpSeg2 === 0 ) {
  20297. if ( ( inExcludeAdjacentSegs ) &&
  20298. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  20299. return [ inSeg1Pt1 ];
  20300. }
  20301. if ( perpSeg2 === limit ) {
  20302. if ( ( inExcludeAdjacentSegs ) &&
  20303. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  20304. return [ inSeg1Pt2 ];
  20305. }
  20306. // intersection at endpoint of segment#2?
  20307. if ( perpSeg1 === 0 ) return [ inSeg2Pt1 ];
  20308. if ( perpSeg1 === limit ) return [ inSeg2Pt2 ];
  20309. // return real intersection point
  20310. var factorSeg1 = perpSeg2 / limit;
  20311. return [ { x: inSeg1Pt1.x + factorSeg1 * seg1dx,
  20312. y: inSeg1Pt1.y + factorSeg1 * seg1dy } ];
  20313. } else {
  20314. // parallel or collinear
  20315. if ( ( perpSeg1 !== 0 ) ||
  20316. ( seg2dy * seg1seg2dx !== seg2dx * seg1seg2dy ) ) return [];
  20317. // they are collinear or degenerate
  20318. var seg1Pt = ( ( seg1dx === 0 ) && ( seg1dy === 0 ) ); // segment1 is just a point?
  20319. var seg2Pt = ( ( seg2dx === 0 ) && ( seg2dy === 0 ) ); // segment2 is just a point?
  20320. // both segments are points
  20321. if ( seg1Pt && seg2Pt ) {
  20322. if ( ( inSeg1Pt1.x !== inSeg2Pt1.x ) ||
  20323. ( inSeg1Pt1.y !== inSeg2Pt1.y ) ) return []; // they are distinct points
  20324. return [ inSeg1Pt1 ]; // they are the same point
  20325. }
  20326. // segment#1 is a single point
  20327. if ( seg1Pt ) {
  20328. if ( ! point_in_segment_2D_colin( inSeg2Pt1, inSeg2Pt2, inSeg1Pt1 ) ) return []; // but not in segment#2
  20329. return [ inSeg1Pt1 ];
  20330. }
  20331. // segment#2 is a single point
  20332. if ( seg2Pt ) {
  20333. if ( ! point_in_segment_2D_colin( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1 ) ) return []; // but not in segment#1
  20334. return [ inSeg2Pt1 ];
  20335. }
  20336. // they are collinear segments, which might overlap
  20337. var seg1min, seg1max, seg1minVal, seg1maxVal;
  20338. var seg2min, seg2max, seg2minVal, seg2maxVal;
  20339. if ( seg1dx !== 0 ) {
  20340. // the segments are NOT on a vertical line
  20341. if ( inSeg1Pt1.x < inSeg1Pt2.x ) {
  20342. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.x;
  20343. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.x;
  20344. } else {
  20345. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.x;
  20346. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.x;
  20347. }
  20348. if ( inSeg2Pt1.x < inSeg2Pt2.x ) {
  20349. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.x;
  20350. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.x;
  20351. } else {
  20352. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.x;
  20353. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.x;
  20354. }
  20355. } else {
  20356. // the segments are on a vertical line
  20357. if ( inSeg1Pt1.y < inSeg1Pt2.y ) {
  20358. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.y;
  20359. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.y;
  20360. } else {
  20361. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.y;
  20362. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.y;
  20363. }
  20364. if ( inSeg2Pt1.y < inSeg2Pt2.y ) {
  20365. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.y;
  20366. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.y;
  20367. } else {
  20368. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.y;
  20369. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.y;
  20370. }
  20371. }
  20372. if ( seg1minVal <= seg2minVal ) {
  20373. if ( seg1maxVal < seg2minVal ) return [];
  20374. if ( seg1maxVal === seg2minVal ) {
  20375. if ( inExcludeAdjacentSegs ) return [];
  20376. return [ seg2min ];
  20377. }
  20378. if ( seg1maxVal <= seg2maxVal ) return [ seg2min, seg1max ];
  20379. return [ seg2min, seg2max ];
  20380. } else {
  20381. if ( seg1minVal > seg2maxVal ) return [];
  20382. if ( seg1minVal === seg2maxVal ) {
  20383. if ( inExcludeAdjacentSegs ) return [];
  20384. return [ seg1min ];
  20385. }
  20386. if ( seg1maxVal <= seg2maxVal ) return [ seg1min, seg1max ];
  20387. return [ seg1min, seg2max ];
  20388. }
  20389. }
  20390. }
  20391. function isPointInsideAngle( inVertex, inLegFromPt, inLegToPt, inOtherPt ) {
  20392. // The order of legs is important
  20393. // translation of all points, so that Vertex is at (0,0)
  20394. var legFromPtX = inLegFromPt.x - inVertex.x, legFromPtY = inLegFromPt.y - inVertex.y;
  20395. var legToPtX = inLegToPt.x - inVertex.x, legToPtY = inLegToPt.y - inVertex.y;
  20396. var otherPtX = inOtherPt.x - inVertex.x, otherPtY = inOtherPt.y - inVertex.y;
  20397. // main angle >0: < 180 deg.; 0: 180 deg.; <0: > 180 deg.
  20398. var from2toAngle = legFromPtX * legToPtY - legFromPtY * legToPtX;
  20399. var from2otherAngle = legFromPtX * otherPtY - legFromPtY * otherPtX;
  20400. if ( Math.abs( from2toAngle ) > Number.EPSILON ) {
  20401. // angle != 180 deg.
  20402. var other2toAngle = otherPtX * legToPtY - otherPtY * legToPtX;
  20403. // console.log( "from2to: " + from2toAngle + ", from2other: " + from2otherAngle + ", other2to: " + other2toAngle );
  20404. if ( from2toAngle > 0 ) {
  20405. // main angle < 180 deg.
  20406. return ( ( from2otherAngle >= 0 ) && ( other2toAngle >= 0 ) );
  20407. } else {
  20408. // main angle > 180 deg.
  20409. return ( ( from2otherAngle >= 0 ) || ( other2toAngle >= 0 ) );
  20410. }
  20411. } else {
  20412. // angle == 180 deg.
  20413. // console.log( "from2to: 180 deg., from2other: " + from2otherAngle );
  20414. return ( from2otherAngle > 0 );
  20415. }
  20416. }
  20417. function removeHoles( contour, holes ) {
  20418. var shape = contour.concat(); // work on this shape
  20419. var hole;
  20420. function isCutLineInsideAngles( inShapeIdx, inHoleIdx ) {
  20421. // Check if hole point lies within angle around shape point
  20422. var lastShapeIdx = shape.length - 1;
  20423. var prevShapeIdx = inShapeIdx - 1;
  20424. if ( prevShapeIdx < 0 ) prevShapeIdx = lastShapeIdx;
  20425. var nextShapeIdx = inShapeIdx + 1;
  20426. if ( nextShapeIdx > lastShapeIdx ) nextShapeIdx = 0;
  20427. var insideAngle = isPointInsideAngle( shape[ inShapeIdx ], shape[ prevShapeIdx ], shape[ nextShapeIdx ], hole[ inHoleIdx ] );
  20428. if ( ! insideAngle ) {
  20429. // console.log( "Vertex (Shape): " + inShapeIdx + ", Point: " + hole[inHoleIdx].x + "/" + hole[inHoleIdx].y );
  20430. return false;
  20431. }
  20432. // Check if shape point lies within angle around hole point
  20433. var lastHoleIdx = hole.length - 1;
  20434. var prevHoleIdx = inHoleIdx - 1;
  20435. if ( prevHoleIdx < 0 ) prevHoleIdx = lastHoleIdx;
  20436. var nextHoleIdx = inHoleIdx + 1;
  20437. if ( nextHoleIdx > lastHoleIdx ) nextHoleIdx = 0;
  20438. insideAngle = isPointInsideAngle( hole[ inHoleIdx ], hole[ prevHoleIdx ], hole[ nextHoleIdx ], shape[ inShapeIdx ] );
  20439. if ( ! insideAngle ) {
  20440. // console.log( "Vertex (Hole): " + inHoleIdx + ", Point: " + shape[inShapeIdx].x + "/" + shape[inShapeIdx].y );
  20441. return false;
  20442. }
  20443. return true;
  20444. }
  20445. function intersectsShapeEdge( inShapePt, inHolePt ) {
  20446. // checks for intersections with shape edges
  20447. var sIdx, nextIdx, intersection;
  20448. for ( sIdx = 0; sIdx < shape.length; sIdx ++ ) {
  20449. nextIdx = sIdx + 1; nextIdx %= shape.length;
  20450. intersection = intersect_segments_2D( inShapePt, inHolePt, shape[ sIdx ], shape[ nextIdx ], true );
  20451. if ( intersection.length > 0 ) return true;
  20452. }
  20453. return false;
  20454. }
  20455. var indepHoles = [];
  20456. function intersectsHoleEdge( inShapePt, inHolePt ) {
  20457. // checks for intersections with hole edges
  20458. var ihIdx, chkHole,
  20459. hIdx, nextIdx, intersection;
  20460. for ( ihIdx = 0; ihIdx < indepHoles.length; ihIdx ++ ) {
  20461. chkHole = holes[ indepHoles[ ihIdx ]];
  20462. for ( hIdx = 0; hIdx < chkHole.length; hIdx ++ ) {
  20463. nextIdx = hIdx + 1; nextIdx %= chkHole.length;
  20464. intersection = intersect_segments_2D( inShapePt, inHolePt, chkHole[ hIdx ], chkHole[ nextIdx ], true );
  20465. if ( intersection.length > 0 ) return true;
  20466. }
  20467. }
  20468. return false;
  20469. }
  20470. var holeIndex, shapeIndex,
  20471. shapePt, holePt,
  20472. holeIdx, cutKey, failedCuts = [],
  20473. tmpShape1, tmpShape2,
  20474. tmpHole1, tmpHole2;
  20475. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  20476. indepHoles.push( h );
  20477. }
  20478. var minShapeIndex = 0;
  20479. var counter = indepHoles.length * 2;
  20480. while ( indepHoles.length > 0 ) {
  20481. counter --;
  20482. if ( counter < 0 ) {
  20483. console.log( "Infinite Loop! Holes left:" + indepHoles.length + ", Probably Hole outside Shape!" );
  20484. break;
  20485. }
  20486. // search for shape-vertex and hole-vertex,
  20487. // which can be connected without intersections
  20488. for ( shapeIndex = minShapeIndex; shapeIndex < shape.length; shapeIndex ++ ) {
  20489. shapePt = shape[ shapeIndex ];
  20490. holeIndex = - 1;
  20491. // search for hole which can be reached without intersections
  20492. for ( var h = 0; h < indepHoles.length; h ++ ) {
  20493. holeIdx = indepHoles[ h ];
  20494. // prevent multiple checks
  20495. cutKey = shapePt.x + ":" + shapePt.y + ":" + holeIdx;
  20496. if ( failedCuts[ cutKey ] !== undefined ) continue;
  20497. hole = holes[ holeIdx ];
  20498. for ( var h2 = 0; h2 < hole.length; h2 ++ ) {
  20499. holePt = hole[ h2 ];
  20500. if ( ! isCutLineInsideAngles( shapeIndex, h2 ) ) continue;
  20501. if ( intersectsShapeEdge( shapePt, holePt ) ) continue;
  20502. if ( intersectsHoleEdge( shapePt, holePt ) ) continue;
  20503. holeIndex = h2;
  20504. indepHoles.splice( h, 1 );
  20505. tmpShape1 = shape.slice( 0, shapeIndex + 1 );
  20506. tmpShape2 = shape.slice( shapeIndex );
  20507. tmpHole1 = hole.slice( holeIndex );
  20508. tmpHole2 = hole.slice( 0, holeIndex + 1 );
  20509. shape = tmpShape1.concat( tmpHole1 ).concat( tmpHole2 ).concat( tmpShape2 );
  20510. minShapeIndex = shapeIndex;
  20511. // Debug only, to show the selected cuts
  20512. // glob_CutLines.push( [ shapePt, holePt ] );
  20513. break;
  20514. }
  20515. if ( holeIndex >= 0 ) break; // hole-vertex found
  20516. failedCuts[ cutKey ] = true; // remember failure
  20517. }
  20518. if ( holeIndex >= 0 ) break; // hole-vertex found
  20519. }
  20520. }
  20521. return shape; /* shape with no holes */
  20522. }
  20523. var i, il, f, face,
  20524. key, index,
  20525. allPointsMap = {};
  20526. // 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.
  20527. var allpoints = contour.concat();
  20528. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  20529. Array.prototype.push.apply( allpoints, holes[ h ] );
  20530. }
  20531. //console.log( "allpoints",allpoints, allpoints.length );
  20532. // prepare all points map
  20533. for ( i = 0, il = allpoints.length; i < il; i ++ ) {
  20534. key = allpoints[ i ].x + ":" + allpoints[ i ].y;
  20535. if ( allPointsMap[ key ] !== undefined ) {
  20536. console.warn( "THREE.Shape: Duplicate point", key );
  20537. }
  20538. allPointsMap[ key ] = i;
  20539. }
  20540. // remove holes by cutting paths to holes and adding them to the shape
  20541. var shapeWithoutHoles = removeHoles( contour, holes );
  20542. var triangles = THREE.ShapeUtils.triangulate( shapeWithoutHoles, false ); // True returns indices for points of spooled shape
  20543. //console.log( "triangles",triangles, triangles.length );
  20544. // check all face vertices against all points map
  20545. for ( i = 0, il = triangles.length; i < il; i ++ ) {
  20546. face = triangles[ i ];
  20547. for ( f = 0; f < 3; f ++ ) {
  20548. key = face[ f ].x + ":" + face[ f ].y;
  20549. index = allPointsMap[ key ];
  20550. if ( index !== undefined ) {
  20551. face[ f ] = index;
  20552. }
  20553. }
  20554. }
  20555. return triangles.concat();
  20556. },
  20557. isClockWise: function ( pts ) {
  20558. return THREE.ShapeUtils.area( pts ) < 0;
  20559. },
  20560. // Bezier Curves formulas obtained from
  20561. // http://en.wikipedia.org/wiki/B%C3%A9zier_curve
  20562. // Quad Bezier Functions
  20563. b2: ( function () {
  20564. function b2p0( t, p ) {
  20565. var k = 1 - t;
  20566. return k * k * p;
  20567. }
  20568. function b2p1( t, p ) {
  20569. return 2 * ( 1 - t ) * t * p;
  20570. }
  20571. function b2p2( t, p ) {
  20572. return t * t * p;
  20573. }
  20574. return function ( t, p0, p1, p2 ) {
  20575. return b2p0( t, p0 ) + b2p1( t, p1 ) + b2p2( t, p2 );
  20576. };
  20577. } )(),
  20578. // Cubic Bezier Functions
  20579. b3: ( function () {
  20580. function b3p0( t, p ) {
  20581. var k = 1 - t;
  20582. return k * k * k * p;
  20583. }
  20584. function b3p1( t, p ) {
  20585. var k = 1 - t;
  20586. return 3 * k * k * t * p;
  20587. }
  20588. function b3p2( t, p ) {
  20589. var k = 1 - t;
  20590. return 3 * k * t * t * p;
  20591. }
  20592. function b3p3( t, p ) {
  20593. return t * t * t * p;
  20594. }
  20595. return function ( t, p0, p1, p2, p3 ) {
  20596. return b3p0( t, p0 ) + b3p1( t, p1 ) + b3p2( t, p2 ) + b3p3( t, p3 );
  20597. };
  20598. } )()
  20599. };
  20600. // File:src/extras/core/Curve.js
  20601. /**
  20602. * @author zz85 / http://www.lab4games.net/zz85/blog
  20603. * Extensible curve object
  20604. *
  20605. * Some common of Curve methods
  20606. * .getPoint(t), getTangent(t)
  20607. * .getPointAt(u), getTagentAt(u)
  20608. * .getPoints(), .getSpacedPoints()
  20609. * .getLength()
  20610. * .updateArcLengths()
  20611. *
  20612. * This following classes subclasses THREE.Curve:
  20613. *
  20614. * -- 2d classes --
  20615. * THREE.LineCurve
  20616. * THREE.QuadraticBezierCurve
  20617. * THREE.CubicBezierCurve
  20618. * THREE.SplineCurve
  20619. * THREE.ArcCurve
  20620. * THREE.EllipseCurve
  20621. *
  20622. * -- 3d classes --
  20623. * THREE.LineCurve3
  20624. * THREE.QuadraticBezierCurve3
  20625. * THREE.CubicBezierCurve3
  20626. * THREE.SplineCurve3
  20627. *
  20628. * A series of curves can be represented as a THREE.CurvePath
  20629. *
  20630. **/
  20631. /**************************************************************
  20632. * Abstract Curve base class
  20633. **************************************************************/
  20634. THREE.Curve = function () {
  20635. };
  20636. THREE.Curve.prototype = {
  20637. constructor: THREE.Curve,
  20638. // Virtual base class method to overwrite and implement in subclasses
  20639. // - t [0 .. 1]
  20640. getPoint: function ( t ) {
  20641. console.warn( "THREE.Curve: Warning, getPoint() not implemented!" );
  20642. return null;
  20643. },
  20644. // Get point at relative position in curve according to arc length
  20645. // - u [0 .. 1]
  20646. getPointAt: function ( u ) {
  20647. var t = this.getUtoTmapping( u );
  20648. return this.getPoint( t );
  20649. },
  20650. // Get sequence of points using getPoint( t )
  20651. getPoints: function ( divisions ) {
  20652. if ( ! divisions ) divisions = 5;
  20653. var d, pts = [];
  20654. for ( d = 0; d <= divisions; d ++ ) {
  20655. pts.push( this.getPoint( d / divisions ) );
  20656. }
  20657. return pts;
  20658. },
  20659. // Get sequence of points using getPointAt( u )
  20660. getSpacedPoints: function ( divisions ) {
  20661. if ( ! divisions ) divisions = 5;
  20662. var d, pts = [];
  20663. for ( d = 0; d <= divisions; d ++ ) {
  20664. pts.push( this.getPointAt( d / divisions ) );
  20665. }
  20666. return pts;
  20667. },
  20668. // Get total curve arc length
  20669. getLength: function () {
  20670. var lengths = this.getLengths();
  20671. return lengths[ lengths.length - 1 ];
  20672. },
  20673. // Get list of cumulative segment lengths
  20674. getLengths: function ( divisions ) {
  20675. if ( ! divisions ) divisions = ( this.__arcLengthDivisions ) ? ( this.__arcLengthDivisions ) : 200;
  20676. if ( this.cacheArcLengths
  20677. && ( this.cacheArcLengths.length === divisions + 1 )
  20678. && ! this.needsUpdate ) {
  20679. //console.log( "cached", this.cacheArcLengths );
  20680. return this.cacheArcLengths;
  20681. }
  20682. this.needsUpdate = false;
  20683. var cache = [];
  20684. var current, last = this.getPoint( 0 );
  20685. var p, sum = 0;
  20686. cache.push( 0 );
  20687. for ( p = 1; p <= divisions; p ++ ) {
  20688. current = this.getPoint ( p / divisions );
  20689. sum += current.distanceTo( last );
  20690. cache.push( sum );
  20691. last = current;
  20692. }
  20693. this.cacheArcLengths = cache;
  20694. return cache; // { sums: cache, sum:sum }; Sum is in the last element.
  20695. },
  20696. updateArcLengths: function() {
  20697. this.needsUpdate = true;
  20698. this.getLengths();
  20699. },
  20700. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  20701. getUtoTmapping: function ( u, distance ) {
  20702. var arcLengths = this.getLengths();
  20703. var i = 0, il = arcLengths.length;
  20704. var targetArcLength; // The targeted u distance value to get
  20705. if ( distance ) {
  20706. targetArcLength = distance;
  20707. } else {
  20708. targetArcLength = u * arcLengths[ il - 1 ];
  20709. }
  20710. //var time = Date.now();
  20711. // binary search for the index with largest value smaller than target u distance
  20712. var low = 0, high = il - 1, comparison;
  20713. while ( low <= high ) {
  20714. 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
  20715. comparison = arcLengths[ i ] - targetArcLength;
  20716. if ( comparison < 0 ) {
  20717. low = i + 1;
  20718. } else if ( comparison > 0 ) {
  20719. high = i - 1;
  20720. } else {
  20721. high = i;
  20722. break;
  20723. // DONE
  20724. }
  20725. }
  20726. i = high;
  20727. //console.log('b' , i, low, high, Date.now()- time);
  20728. if ( arcLengths[ i ] === targetArcLength ) {
  20729. var t = i / ( il - 1 );
  20730. return t;
  20731. }
  20732. // we could get finer grain at lengths, or use simple interpolation between two points
  20733. var lengthBefore = arcLengths[ i ];
  20734. var lengthAfter = arcLengths[ i + 1 ];
  20735. var segmentLength = lengthAfter - lengthBefore;
  20736. // determine where we are between the 'before' and 'after' points
  20737. var segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  20738. // add that fractional amount to t
  20739. var t = ( i + segmentFraction ) / ( il - 1 );
  20740. return t;
  20741. },
  20742. // Returns a unit vector tangent at t
  20743. // In case any sub curve does not implement its tangent derivation,
  20744. // 2 points a small delta apart will be used to find its gradient
  20745. // which seems to give a reasonable approximation
  20746. getTangent: function( t ) {
  20747. var delta = 0.0001;
  20748. var t1 = t - delta;
  20749. var t2 = t + delta;
  20750. // Capping in case of danger
  20751. if ( t1 < 0 ) t1 = 0;
  20752. if ( t2 > 1 ) t2 = 1;
  20753. var pt1 = this.getPoint( t1 );
  20754. var pt2 = this.getPoint( t2 );
  20755. var vec = pt2.clone().sub( pt1 );
  20756. return vec.normalize();
  20757. },
  20758. getTangentAt: function ( u ) {
  20759. var t = this.getUtoTmapping( u );
  20760. return this.getTangent( t );
  20761. }
  20762. };
  20763. // TODO: Transformation for Curves?
  20764. /**************************************************************
  20765. * 3D Curves
  20766. **************************************************************/
  20767. // A Factory method for creating new curve subclasses
  20768. THREE.Curve.create = function ( constructor, getPointFunc ) {
  20769. constructor.prototype = Object.create( THREE.Curve.prototype );
  20770. constructor.prototype.constructor = constructor;
  20771. constructor.prototype.getPoint = getPointFunc;
  20772. return constructor;
  20773. };
  20774. // File:src/extras/core/CurvePath.js
  20775. /**
  20776. * @author zz85 / http://www.lab4games.net/zz85/blog
  20777. *
  20778. **/
  20779. /**************************************************************
  20780. * Curved Path - a curve path is simply a array of connected
  20781. * curves, but retains the api of a curve
  20782. **************************************************************/
  20783. THREE.CurvePath = function () {
  20784. this.curves = [];
  20785. this.autoClose = false; // Automatically closes the path
  20786. };
  20787. THREE.CurvePath.prototype = Object.assign( Object.create( THREE.Curve.prototype ), {
  20788. constructor: THREE.CurvePath,
  20789. add: function ( curve ) {
  20790. this.curves.push( curve );
  20791. },
  20792. closePath: function () {
  20793. // TODO Test
  20794. // and verify for vector3 (needs to implement equals)
  20795. // Add a line curve if start and end of lines are not connected
  20796. var startPoint = this.curves[ 0 ].getPoint( 0 );
  20797. var endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
  20798. if ( ! startPoint.equals( endPoint ) ) {
  20799. this.curves.push( new THREE.LineCurve( endPoint, startPoint ) );
  20800. }
  20801. },
  20802. // To get accurate point with reference to
  20803. // entire path distance at time t,
  20804. // following has to be done:
  20805. // 1. Length of each sub path have to be known
  20806. // 2. Locate and identify type of curve
  20807. // 3. Get t for the curve
  20808. // 4. Return curve.getPointAt(t')
  20809. getPoint: function ( t ) {
  20810. var d = t * this.getLength();
  20811. var curveLengths = this.getCurveLengths();
  20812. var i = 0;
  20813. // To think about boundaries points.
  20814. while ( i < curveLengths.length ) {
  20815. if ( curveLengths[ i ] >= d ) {
  20816. var diff = curveLengths[ i ] - d;
  20817. var curve = this.curves[ i ];
  20818. var u = 1 - diff / curve.getLength();
  20819. return curve.getPointAt( u );
  20820. }
  20821. i ++;
  20822. }
  20823. return null;
  20824. // loop where sum != 0, sum > d , sum+1 <d
  20825. },
  20826. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  20827. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  20828. // getPoint() depends on getLength
  20829. getLength: function () {
  20830. var lens = this.getCurveLengths();
  20831. return lens[ lens.length - 1 ];
  20832. },
  20833. // Compute lengths and cache them
  20834. // We cannot overwrite getLengths() because UtoT mapping uses it.
  20835. getCurveLengths: function () {
  20836. // We use cache values if curves and cache array are same length
  20837. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  20838. return this.cacheLengths;
  20839. }
  20840. // Get length of sub-curve
  20841. // Push sums into cached array
  20842. var lengths = [], sums = 0;
  20843. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  20844. sums += this.curves[ i ].getLength();
  20845. lengths.push( sums );
  20846. }
  20847. this.cacheLengths = lengths;
  20848. return lengths;
  20849. },
  20850. /**************************************************************
  20851. * Create Geometries Helpers
  20852. **************************************************************/
  20853. /// Generate geometry from path points (for Line or Points objects)
  20854. createPointsGeometry: function ( divisions ) {
  20855. var pts = this.getPoints( divisions );
  20856. return this.createGeometry( pts );
  20857. },
  20858. // Generate geometry from equidistant sampling along the path
  20859. createSpacedPointsGeometry: function ( divisions ) {
  20860. var pts = this.getSpacedPoints( divisions );
  20861. return this.createGeometry( pts );
  20862. },
  20863. createGeometry: function ( points ) {
  20864. var geometry = new THREE.Geometry();
  20865. for ( var i = 0, l = points.length; i < l; i ++ ) {
  20866. var point = points[ i ];
  20867. geometry.vertices.push( new THREE.Vector3( point.x, point.y, point.z || 0 ) );
  20868. }
  20869. return geometry;
  20870. }
  20871. } );
  20872. // File:src/extras/core/Font.js
  20873. /**
  20874. * @author zz85 / http://www.lab4games.net/zz85/blog
  20875. * @author mrdoob / http://mrdoob.com/
  20876. */
  20877. THREE.Font = function ( data ) {
  20878. this.data = data;
  20879. };
  20880. Object.assign( THREE.Font.prototype, {
  20881. generateShapes: function ( text, size, divisions ) {
  20882. function createPaths( text ) {
  20883. var chars = String( text ).split( '' );
  20884. var scale = size / data.resolution;
  20885. var offset = 0;
  20886. var paths = [];
  20887. for ( var i = 0; i < chars.length; i ++ ) {
  20888. var ret = createPath( chars[ i ], scale, offset );
  20889. offset += ret.offset;
  20890. paths.push( ret.path );
  20891. }
  20892. return paths;
  20893. }
  20894. function createPath( c, scale, offset ) {
  20895. var glyph = data.glyphs[ c ] || data.glyphs[ '?' ];
  20896. if ( ! glyph ) return;
  20897. var path = new THREE.Path();
  20898. var pts = [], b2 = THREE.ShapeUtils.b2, b3 = THREE.ShapeUtils.b3;
  20899. var x, y, cpx, cpy, cpx0, cpy0, cpx1, cpy1, cpx2, cpy2, laste;
  20900. if ( glyph.o ) {
  20901. var outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) );
  20902. for ( var i = 0, l = outline.length; i < l; ) {
  20903. var action = outline[ i ++ ];
  20904. switch ( action ) {
  20905. case 'm': // moveTo
  20906. x = outline[ i ++ ] * scale + offset;
  20907. y = outline[ i ++ ] * scale;
  20908. path.moveTo( x, y );
  20909. break;
  20910. case 'l': // lineTo
  20911. x = outline[ i ++ ] * scale + offset;
  20912. y = outline[ i ++ ] * scale;
  20913. path.lineTo( x, y );
  20914. break;
  20915. case 'q': // quadraticCurveTo
  20916. cpx = outline[ i ++ ] * scale + offset;
  20917. cpy = outline[ i ++ ] * scale;
  20918. cpx1 = outline[ i ++ ] * scale + offset;
  20919. cpy1 = outline[ i ++ ] * scale;
  20920. path.quadraticCurveTo( cpx1, cpy1, cpx, cpy );
  20921. laste = pts[ pts.length - 1 ];
  20922. if ( laste ) {
  20923. cpx0 = laste.x;
  20924. cpy0 = laste.y;
  20925. for ( var i2 = 1; i2 <= divisions; i2 ++ ) {
  20926. var t = i2 / divisions;
  20927. b2( t, cpx0, cpx1, cpx );
  20928. b2( t, cpy0, cpy1, cpy );
  20929. }
  20930. }
  20931. break;
  20932. case 'b': // bezierCurveTo
  20933. cpx = outline[ i ++ ] * scale + offset;
  20934. cpy = outline[ i ++ ] * scale;
  20935. cpx1 = outline[ i ++ ] * scale + offset;
  20936. cpy1 = outline[ i ++ ] * scale;
  20937. cpx2 = outline[ i ++ ] * scale + offset;
  20938. cpy2 = outline[ i ++ ] * scale;
  20939. path.bezierCurveTo( cpx1, cpy1, cpx2, cpy2, cpx, cpy );
  20940. laste = pts[ pts.length - 1 ];
  20941. if ( laste ) {
  20942. cpx0 = laste.x;
  20943. cpy0 = laste.y;
  20944. for ( var i2 = 1; i2 <= divisions; i2 ++ ) {
  20945. var t = i2 / divisions;
  20946. b3( t, cpx0, cpx1, cpx2, cpx );
  20947. b3( t, cpy0, cpy1, cpy2, cpy );
  20948. }
  20949. }
  20950. break;
  20951. }
  20952. }
  20953. }
  20954. return { offset: glyph.ha * scale, path: path };
  20955. }
  20956. //
  20957. if ( size === undefined ) size = 100;
  20958. if ( divisions === undefined ) divisions = 4;
  20959. var data = this.data;
  20960. var paths = createPaths( text );
  20961. var shapes = [];
  20962. for ( var p = 0, pl = paths.length; p < pl; p ++ ) {
  20963. Array.prototype.push.apply( shapes, paths[ p ].toShapes() );
  20964. }
  20965. return shapes;
  20966. }
  20967. } );
  20968. // File:src/extras/core/Path.js
  20969. /**
  20970. * @author zz85 / http://www.lab4games.net/zz85/blog
  20971. * Creates free form 2d path using series of points, lines or curves.
  20972. *
  20973. **/
  20974. THREE.Path = function ( points ) {
  20975. THREE.CurvePath.call( this );
  20976. this.actions = [];
  20977. if ( points ) {
  20978. this.fromPoints( points );
  20979. }
  20980. };
  20981. THREE.Path.prototype = Object.assign( Object.create( THREE.CurvePath.prototype ), {
  20982. constructor: THREE.Path,
  20983. // TODO Clean up PATH API
  20984. // Create path using straight lines to connect all points
  20985. // - vectors: array of Vector2
  20986. fromPoints: function ( vectors ) {
  20987. this.moveTo( vectors[ 0 ].x, vectors[ 0 ].y );
  20988. for ( var i = 1, l = vectors.length; i < l; i ++ ) {
  20989. this.lineTo( vectors[ i ].x, vectors[ i ].y );
  20990. }
  20991. },
  20992. moveTo: function ( x, y ) {
  20993. this.actions.push( { action: 'moveTo', args: [ x, y ] } );
  20994. },
  20995. lineTo: function ( x, y ) {
  20996. var lastargs = this.actions[ this.actions.length - 1 ].args;
  20997. var x0 = lastargs[ lastargs.length - 2 ];
  20998. var y0 = lastargs[ lastargs.length - 1 ];
  20999. var curve = new THREE.LineCurve( new THREE.Vector2( x0, y0 ), new THREE.Vector2( x, y ) );
  21000. this.curves.push( curve );
  21001. this.actions.push( { action: 'lineTo', args: [ x, y ] } );
  21002. },
  21003. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  21004. var lastargs = this.actions[ this.actions.length - 1 ].args;
  21005. var x0 = lastargs[ lastargs.length - 2 ];
  21006. var y0 = lastargs[ lastargs.length - 1 ];
  21007. var curve = new THREE.QuadraticBezierCurve(
  21008. new THREE.Vector2( x0, y0 ),
  21009. new THREE.Vector2( aCPx, aCPy ),
  21010. new THREE.Vector2( aX, aY )
  21011. );
  21012. this.curves.push( curve );
  21013. this.actions.push( { action: 'quadraticCurveTo', args: [ aCPx, aCPy, aX, aY ] } );
  21014. },
  21015. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  21016. var lastargs = this.actions[ this.actions.length - 1 ].args;
  21017. var x0 = lastargs[ lastargs.length - 2 ];
  21018. var y0 = lastargs[ lastargs.length - 1 ];
  21019. var curve = new THREE.CubicBezierCurve(
  21020. new THREE.Vector2( x0, y0 ),
  21021. new THREE.Vector2( aCP1x, aCP1y ),
  21022. new THREE.Vector2( aCP2x, aCP2y ),
  21023. new THREE.Vector2( aX, aY )
  21024. );
  21025. this.curves.push( curve );
  21026. this.actions.push( { action: 'bezierCurveTo', args: [ aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ] } );
  21027. },
  21028. splineThru: function ( pts /*Array of Vector*/ ) {
  21029. var args = Array.prototype.slice.call( arguments );
  21030. var lastargs = this.actions[ this.actions.length - 1 ].args;
  21031. var x0 = lastargs[ lastargs.length - 2 ];
  21032. var y0 = lastargs[ lastargs.length - 1 ];
  21033. var npts = [ new THREE.Vector2( x0, y0 ) ];
  21034. Array.prototype.push.apply( npts, pts );
  21035. var curve = new THREE.SplineCurve( npts );
  21036. this.curves.push( curve );
  21037. this.actions.push( { action: 'splineThru', args: args } );
  21038. },
  21039. arc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  21040. var lastargs = this.actions[ this.actions.length - 1 ].args;
  21041. var x0 = lastargs[ lastargs.length - 2 ];
  21042. var y0 = lastargs[ lastargs.length - 1 ];
  21043. this.absarc( aX + x0, aY + y0, aRadius,
  21044. aStartAngle, aEndAngle, aClockwise );
  21045. },
  21046. absarc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  21047. this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  21048. },
  21049. ellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  21050. var lastargs = this.actions[ this.actions.length - 1 ].args;
  21051. var x0 = lastargs[ lastargs.length - 2 ];
  21052. var y0 = lastargs[ lastargs.length - 1 ];
  21053. this.absellipse( aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  21054. },
  21055. absellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  21056. var args = [
  21057. aX, aY,
  21058. xRadius, yRadius,
  21059. aStartAngle, aEndAngle,
  21060. aClockwise,
  21061. aRotation || 0 // aRotation is optional.
  21062. ];
  21063. var curve = new THREE.EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  21064. this.curves.push( curve );
  21065. var lastPoint = curve.getPoint( 1 );
  21066. args.push( lastPoint.x );
  21067. args.push( lastPoint.y );
  21068. this.actions.push( { action: 'ellipse', args: args } );
  21069. },
  21070. getSpacedPoints: function ( divisions ) {
  21071. if ( ! divisions ) divisions = 40;
  21072. var points = [];
  21073. for ( var i = 0; i < divisions; i ++ ) {
  21074. points.push( this.getPoint( i / divisions ) );
  21075. //if ( !this.getPoint( i / divisions ) ) throw "DIE";
  21076. }
  21077. if ( this.autoClose ) {
  21078. points.push( points[ 0 ] );
  21079. }
  21080. return points;
  21081. },
  21082. getPoints: function ( divisions ) {
  21083. divisions = divisions || 12;
  21084. var b2 = THREE.ShapeUtils.b2;
  21085. var b3 = THREE.ShapeUtils.b3;
  21086. var points = [];
  21087. var cpx, cpy, cpx2, cpy2, cpx1, cpy1, cpx0, cpy0,
  21088. laste, tx, ty;
  21089. for ( var i = 0, l = this.actions.length; i < l; i ++ ) {
  21090. var item = this.actions[ i ];
  21091. var action = item.action;
  21092. var args = item.args;
  21093. switch ( action ) {
  21094. case 'moveTo':
  21095. points.push( new THREE.Vector2( args[ 0 ], args[ 1 ] ) );
  21096. break;
  21097. case 'lineTo':
  21098. points.push( new THREE.Vector2( args[ 0 ], args[ 1 ] ) );
  21099. break;
  21100. case 'quadraticCurveTo':
  21101. cpx = args[ 2 ];
  21102. cpy = args[ 3 ];
  21103. cpx1 = args[ 0 ];
  21104. cpy1 = args[ 1 ];
  21105. if ( points.length > 0 ) {
  21106. laste = points[ points.length - 1 ];
  21107. cpx0 = laste.x;
  21108. cpy0 = laste.y;
  21109. } else {
  21110. laste = this.actions[ i - 1 ].args;
  21111. cpx0 = laste[ laste.length - 2 ];
  21112. cpy0 = laste[ laste.length - 1 ];
  21113. }
  21114. for ( var j = 1; j <= divisions; j ++ ) {
  21115. var t = j / divisions;
  21116. tx = b2( t, cpx0, cpx1, cpx );
  21117. ty = b2( t, cpy0, cpy1, cpy );
  21118. points.push( new THREE.Vector2( tx, ty ) );
  21119. }
  21120. break;
  21121. case 'bezierCurveTo':
  21122. cpx = args[ 4 ];
  21123. cpy = args[ 5 ];
  21124. cpx1 = args[ 0 ];
  21125. cpy1 = args[ 1 ];
  21126. cpx2 = args[ 2 ];
  21127. cpy2 = args[ 3 ];
  21128. if ( points.length > 0 ) {
  21129. laste = points[ points.length - 1 ];
  21130. cpx0 = laste.x;
  21131. cpy0 = laste.y;
  21132. } else {
  21133. laste = this.actions[ i - 1 ].args;
  21134. cpx0 = laste[ laste.length - 2 ];
  21135. cpy0 = laste[ laste.length - 1 ];
  21136. }
  21137. for ( var j = 1; j <= divisions; j ++ ) {
  21138. var t = j / divisions;
  21139. tx = b3( t, cpx0, cpx1, cpx2, cpx );
  21140. ty = b3( t, cpy0, cpy1, cpy2, cpy );
  21141. points.push( new THREE.Vector2( tx, ty ) );
  21142. }
  21143. break;
  21144. case 'splineThru':
  21145. laste = this.actions[ i - 1 ].args;
  21146. var last = new THREE.Vector2( laste[ laste.length - 2 ], laste[ laste.length - 1 ] );
  21147. var spts = [ last ];
  21148. var n = divisions * args[ 0 ].length;
  21149. spts = spts.concat( args[ 0 ] );
  21150. var spline = new THREE.SplineCurve( spts );
  21151. for ( var j = 1; j <= n; j ++ ) {
  21152. points.push( spline.getPointAt( j / n ) );
  21153. }
  21154. break;
  21155. case 'arc':
  21156. var aX = args[ 0 ], aY = args[ 1 ],
  21157. aRadius = args[ 2 ],
  21158. aStartAngle = args[ 3 ], aEndAngle = args[ 4 ],
  21159. aClockwise = !! args[ 5 ];
  21160. var deltaAngle = aEndAngle - aStartAngle;
  21161. var angle;
  21162. var tdivisions = divisions * 2;
  21163. for ( var j = 1; j <= tdivisions; j ++ ) {
  21164. var t = j / tdivisions;
  21165. if ( ! aClockwise ) {
  21166. t = 1 - t;
  21167. }
  21168. angle = aStartAngle + t * deltaAngle;
  21169. tx = aX + aRadius * Math.cos( angle );
  21170. ty = aY + aRadius * Math.sin( angle );
  21171. //console.log('t', t, 'angle', angle, 'tx', tx, 'ty', ty);
  21172. points.push( new THREE.Vector2( tx, ty ) );
  21173. }
  21174. //console.log(points);
  21175. break;
  21176. case 'ellipse':
  21177. var aX = args[ 0 ], aY = args[ 1 ],
  21178. xRadius = args[ 2 ],
  21179. yRadius = args[ 3 ],
  21180. aStartAngle = args[ 4 ], aEndAngle = args[ 5 ],
  21181. aClockwise = !! args[ 6 ],
  21182. aRotation = args[ 7 ];
  21183. var deltaAngle = aEndAngle - aStartAngle;
  21184. var angle;
  21185. var tdivisions = divisions * 2;
  21186. var cos, sin;
  21187. if ( aRotation !== 0 ) {
  21188. cos = Math.cos( aRotation );
  21189. sin = Math.sin( aRotation );
  21190. }
  21191. for ( var j = 1; j <= tdivisions; j ++ ) {
  21192. var t = j / tdivisions;
  21193. if ( ! aClockwise ) {
  21194. t = 1 - t;
  21195. }
  21196. angle = aStartAngle + t * deltaAngle;
  21197. tx = aX + xRadius * Math.cos( angle );
  21198. ty = aY + yRadius * Math.sin( angle );
  21199. if ( aRotation !== 0 ) {
  21200. var x = tx, y = ty;
  21201. // Rotate the point about the center of the ellipse.
  21202. tx = ( x - aX ) * cos - ( y - aY ) * sin + aX;
  21203. ty = ( x - aX ) * sin + ( y - aY ) * cos + aY;
  21204. }
  21205. //console.log('t', t, 'angle', angle, 'tx', tx, 'ty', ty);
  21206. points.push( new THREE.Vector2( tx, ty ) );
  21207. }
  21208. //console.log(points);
  21209. break;
  21210. } // end switch
  21211. }
  21212. // Normalize to remove the closing point by default.
  21213. var lastPoint = points[ points.length - 1 ];
  21214. if ( Math.abs( lastPoint.x - points[ 0 ].x ) < Number.EPSILON &&
  21215. Math.abs( lastPoint.y - points[ 0 ].y ) < Number.EPSILON )
  21216. points.splice( points.length - 1, 1 );
  21217. if ( this.autoClose ) {
  21218. points.push( points[ 0 ] );
  21219. }
  21220. return points;
  21221. },
  21222. toShapes: function ( isCCW, noHoles ) {
  21223. function extractSubpaths( inActions ) {
  21224. var subPaths = [], lastPath = new THREE.Path();
  21225. for ( var i = 0, l = inActions.length; i < l; i ++ ) {
  21226. var item = inActions[ i ];
  21227. var args = item.args;
  21228. var action = item.action;
  21229. if ( action === 'moveTo' ) {
  21230. if ( lastPath.actions.length !== 0 ) {
  21231. subPaths.push( lastPath );
  21232. lastPath = new THREE.Path();
  21233. }
  21234. }
  21235. lastPath[ action ].apply( lastPath, args );
  21236. }
  21237. if ( lastPath.actions.length !== 0 ) {
  21238. subPaths.push( lastPath );
  21239. }
  21240. // console.log(subPaths);
  21241. return subPaths;
  21242. }
  21243. function toShapesNoHoles( inSubpaths ) {
  21244. var shapes = [];
  21245. for ( var i = 0, l = inSubpaths.length; i < l; i ++ ) {
  21246. var tmpPath = inSubpaths[ i ];
  21247. var tmpShape = new THREE.Shape();
  21248. tmpShape.actions = tmpPath.actions;
  21249. tmpShape.curves = tmpPath.curves;
  21250. shapes.push( tmpShape );
  21251. }
  21252. //console.log("shape", shapes);
  21253. return shapes;
  21254. }
  21255. function isPointInsidePolygon( inPt, inPolygon ) {
  21256. var polyLen = inPolygon.length;
  21257. // inPt on polygon contour => immediate success or
  21258. // toggling of inside/outside at every single! intersection point of an edge
  21259. // with the horizontal line through inPt, left of inPt
  21260. // not counting lowerY endpoints of edges and whole edges on that line
  21261. var inside = false;
  21262. for ( var p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  21263. var edgeLowPt = inPolygon[ p ];
  21264. var edgeHighPt = inPolygon[ q ];
  21265. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  21266. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  21267. if ( Math.abs( edgeDy ) > Number.EPSILON ) {
  21268. // not parallel
  21269. if ( edgeDy < 0 ) {
  21270. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  21271. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  21272. }
  21273. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  21274. if ( inPt.y === edgeLowPt.y ) {
  21275. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  21276. // continue; // no intersection or edgeLowPt => doesn't count !!!
  21277. } else {
  21278. var perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y );
  21279. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  21280. if ( perpEdge < 0 ) continue;
  21281. inside = ! inside; // true intersection left of inPt
  21282. }
  21283. } else {
  21284. // parallel or collinear
  21285. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  21286. // edge lies on the same horizontal line as inPt
  21287. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  21288. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  21289. // continue;
  21290. }
  21291. }
  21292. return inside;
  21293. }
  21294. var isClockWise = THREE.ShapeUtils.isClockWise;
  21295. var subPaths = extractSubpaths( this.actions );
  21296. if ( subPaths.length === 0 ) return [];
  21297. if ( noHoles === true ) return toShapesNoHoles( subPaths );
  21298. var solid, tmpPath, tmpShape, shapes = [];
  21299. if ( subPaths.length === 1 ) {
  21300. tmpPath = subPaths[ 0 ];
  21301. tmpShape = new THREE.Shape();
  21302. tmpShape.actions = tmpPath.actions;
  21303. tmpShape.curves = tmpPath.curves;
  21304. shapes.push( tmpShape );
  21305. return shapes;
  21306. }
  21307. var holesFirst = ! isClockWise( subPaths[ 0 ].getPoints() );
  21308. holesFirst = isCCW ? ! holesFirst : holesFirst;
  21309. // console.log("Holes first", holesFirst);
  21310. var betterShapeHoles = [];
  21311. var newShapes = [];
  21312. var newShapeHoles = [];
  21313. var mainIdx = 0;
  21314. var tmpPoints;
  21315. newShapes[ mainIdx ] = undefined;
  21316. newShapeHoles[ mainIdx ] = [];
  21317. for ( var i = 0, l = subPaths.length; i < l; i ++ ) {
  21318. tmpPath = subPaths[ i ];
  21319. tmpPoints = tmpPath.getPoints();
  21320. solid = isClockWise( tmpPoints );
  21321. solid = isCCW ? ! solid : solid;
  21322. if ( solid ) {
  21323. if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) mainIdx ++;
  21324. newShapes[ mainIdx ] = { s: new THREE.Shape(), p: tmpPoints };
  21325. newShapes[ mainIdx ].s.actions = tmpPath.actions;
  21326. newShapes[ mainIdx ].s.curves = tmpPath.curves;
  21327. if ( holesFirst ) mainIdx ++;
  21328. newShapeHoles[ mainIdx ] = [];
  21329. //console.log('cw', i);
  21330. } else {
  21331. newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } );
  21332. //console.log('ccw', i);
  21333. }
  21334. }
  21335. // only Holes? -> probably all Shapes with wrong orientation
  21336. if ( ! newShapes[ 0 ] ) return toShapesNoHoles( subPaths );
  21337. if ( newShapes.length > 1 ) {
  21338. var ambiguous = false;
  21339. var toChange = [];
  21340. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  21341. betterShapeHoles[ sIdx ] = [];
  21342. }
  21343. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  21344. var sho = newShapeHoles[ sIdx ];
  21345. for ( var hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  21346. var ho = sho[ hIdx ];
  21347. var hole_unassigned = true;
  21348. for ( var s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  21349. if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
  21350. if ( sIdx !== s2Idx ) toChange.push( { froms: sIdx, tos: s2Idx, hole: hIdx } );
  21351. if ( hole_unassigned ) {
  21352. hole_unassigned = false;
  21353. betterShapeHoles[ s2Idx ].push( ho );
  21354. } else {
  21355. ambiguous = true;
  21356. }
  21357. }
  21358. }
  21359. if ( hole_unassigned ) {
  21360. betterShapeHoles[ sIdx ].push( ho );
  21361. }
  21362. }
  21363. }
  21364. // console.log("ambiguous: ", ambiguous);
  21365. if ( toChange.length > 0 ) {
  21366. // console.log("to change: ", toChange);
  21367. if ( ! ambiguous ) newShapeHoles = betterShapeHoles;
  21368. }
  21369. }
  21370. var tmpHoles;
  21371. for ( var i = 0, il = newShapes.length; i < il; i ++ ) {
  21372. tmpShape = newShapes[ i ].s;
  21373. shapes.push( tmpShape );
  21374. tmpHoles = newShapeHoles[ i ];
  21375. for ( var j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  21376. tmpShape.holes.push( tmpHoles[ j ].h );
  21377. }
  21378. }
  21379. //console.log("shape", shapes);
  21380. return shapes;
  21381. }
  21382. } );
  21383. // File:src/extras/core/Shape.js
  21384. /**
  21385. * @author zz85 / http://www.lab4games.net/zz85/blog
  21386. * Defines a 2d shape plane using paths.
  21387. **/
  21388. // STEP 1 Create a path.
  21389. // STEP 2 Turn path into shape.
  21390. // STEP 3 ExtrudeGeometry takes in Shape/Shapes
  21391. // STEP 3a - Extract points from each shape, turn to vertices
  21392. // STEP 3b - Triangulate each shape, add faces.
  21393. THREE.Shape = function () {
  21394. THREE.Path.apply( this, arguments );
  21395. this.holes = [];
  21396. };
  21397. THREE.Shape.prototype = Object.assign( Object.create( THREE.Path.prototype ), {
  21398. constructor: THREE.Shape,
  21399. // Convenience method to return ExtrudeGeometry
  21400. extrude: function ( options ) {
  21401. return new THREE.ExtrudeGeometry( this, options );
  21402. },
  21403. // Convenience method to return ShapeGeometry
  21404. makeGeometry: function ( options ) {
  21405. return new THREE.ShapeGeometry( this, options );
  21406. },
  21407. getPointsHoles: function ( divisions ) {
  21408. var holesPts = [];
  21409. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  21410. holesPts[ i ] = this.holes[ i ].getPoints( divisions );
  21411. }
  21412. return holesPts;
  21413. },
  21414. // Get points of shape and holes (keypoints based on segments parameter)
  21415. extractAllPoints: function ( divisions ) {
  21416. return {
  21417. shape: this.getPoints( divisions ),
  21418. holes: this.getPointsHoles( divisions )
  21419. };
  21420. },
  21421. extractPoints: function ( divisions ) {
  21422. return this.extractAllPoints( divisions );
  21423. }
  21424. } );
  21425. // File:src/extras/curves/LineCurve.js
  21426. /**************************************************************
  21427. * Line
  21428. **************************************************************/
  21429. THREE.LineCurve = function ( v1, v2 ) {
  21430. this.v1 = v1;
  21431. this.v2 = v2;
  21432. };
  21433. THREE.LineCurve.prototype = Object.create( THREE.Curve.prototype );
  21434. THREE.LineCurve.prototype.constructor = THREE.LineCurve;
  21435. THREE.LineCurve.prototype.getPoint = function ( t ) {
  21436. var point = this.v2.clone().sub( this.v1 );
  21437. point.multiplyScalar( t ).add( this.v1 );
  21438. return point;
  21439. };
  21440. // Line curve is linear, so we can overwrite default getPointAt
  21441. THREE.LineCurve.prototype.getPointAt = function ( u ) {
  21442. return this.getPoint( u );
  21443. };
  21444. THREE.LineCurve.prototype.getTangent = function( t ) {
  21445. var tangent = this.v2.clone().sub( this.v1 );
  21446. return tangent.normalize();
  21447. };
  21448. // File:src/extras/curves/QuadraticBezierCurve.js
  21449. /**************************************************************
  21450. * Quadratic Bezier curve
  21451. **************************************************************/
  21452. THREE.QuadraticBezierCurve = function ( v0, v1, v2 ) {
  21453. this.v0 = v0;
  21454. this.v1 = v1;
  21455. this.v2 = v2;
  21456. };
  21457. THREE.QuadraticBezierCurve.prototype = Object.create( THREE.Curve.prototype );
  21458. THREE.QuadraticBezierCurve.prototype.constructor = THREE.QuadraticBezierCurve;
  21459. THREE.QuadraticBezierCurve.prototype.getPoint = function ( t ) {
  21460. var b2 = THREE.ShapeUtils.b2;
  21461. return new THREE.Vector2(
  21462. b2( t, this.v0.x, this.v1.x, this.v2.x ),
  21463. b2( t, this.v0.y, this.v1.y, this.v2.y )
  21464. );
  21465. };
  21466. THREE.QuadraticBezierCurve.prototype.getTangent = function( t ) {
  21467. var tangentQuadraticBezier = THREE.CurveUtils.tangentQuadraticBezier;
  21468. return new THREE.Vector2(
  21469. tangentQuadraticBezier( t, this.v0.x, this.v1.x, this.v2.x ),
  21470. tangentQuadraticBezier( t, this.v0.y, this.v1.y, this.v2.y )
  21471. ).normalize();
  21472. };
  21473. // File:src/extras/curves/CubicBezierCurve.js
  21474. /**************************************************************
  21475. * Cubic Bezier curve
  21476. **************************************************************/
  21477. THREE.CubicBezierCurve = function ( v0, v1, v2, v3 ) {
  21478. this.v0 = v0;
  21479. this.v1 = v1;
  21480. this.v2 = v2;
  21481. this.v3 = v3;
  21482. };
  21483. THREE.CubicBezierCurve.prototype = Object.create( THREE.Curve.prototype );
  21484. THREE.CubicBezierCurve.prototype.constructor = THREE.CubicBezierCurve;
  21485. THREE.CubicBezierCurve.prototype.getPoint = function ( t ) {
  21486. var b3 = THREE.ShapeUtils.b3;
  21487. return new THREE.Vector2(
  21488. b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x ),
  21489. b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y )
  21490. );
  21491. };
  21492. THREE.CubicBezierCurve.prototype.getTangent = function( t ) {
  21493. var tangentCubicBezier = THREE.CurveUtils.tangentCubicBezier;
  21494. return new THREE.Vector2(
  21495. tangentCubicBezier( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x ),
  21496. tangentCubicBezier( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y )
  21497. ).normalize();
  21498. };
  21499. // File:src/extras/curves/SplineCurve.js
  21500. /**************************************************************
  21501. * Spline curve
  21502. **************************************************************/
  21503. THREE.SplineCurve = function ( points /* array of Vector2 */ ) {
  21504. this.points = ( points == undefined ) ? [] : points;
  21505. };
  21506. THREE.SplineCurve.prototype = Object.create( THREE.Curve.prototype );
  21507. THREE.SplineCurve.prototype.constructor = THREE.SplineCurve;
  21508. THREE.SplineCurve.prototype.getPoint = function ( t ) {
  21509. var points = this.points;
  21510. var point = ( points.length - 1 ) * t;
  21511. var intPoint = Math.floor( point );
  21512. var weight = point - intPoint;
  21513. var point0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  21514. var point1 = points[ intPoint ];
  21515. var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  21516. var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  21517. var interpolate = THREE.CurveUtils.interpolate;
  21518. return new THREE.Vector2(
  21519. interpolate( point0.x, point1.x, point2.x, point3.x, weight ),
  21520. interpolate( point0.y, point1.y, point2.y, point3.y, weight )
  21521. );
  21522. };
  21523. // File:src/extras/curves/EllipseCurve.js
  21524. /**************************************************************
  21525. * Ellipse curve
  21526. **************************************************************/
  21527. THREE.EllipseCurve = function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  21528. this.aX = aX;
  21529. this.aY = aY;
  21530. this.xRadius = xRadius;
  21531. this.yRadius = yRadius;
  21532. this.aStartAngle = aStartAngle;
  21533. this.aEndAngle = aEndAngle;
  21534. this.aClockwise = aClockwise;
  21535. this.aRotation = aRotation || 0;
  21536. };
  21537. THREE.EllipseCurve.prototype = Object.create( THREE.Curve.prototype );
  21538. THREE.EllipseCurve.prototype.constructor = THREE.EllipseCurve;
  21539. THREE.EllipseCurve.prototype.getPoint = function ( t ) {
  21540. var deltaAngle = this.aEndAngle - this.aStartAngle;
  21541. if ( deltaAngle < 0 ) deltaAngle += Math.PI * 2;
  21542. if ( deltaAngle > Math.PI * 2 ) deltaAngle -= Math.PI * 2;
  21543. var angle;
  21544. if ( this.aClockwise === true ) {
  21545. angle = this.aEndAngle + ( 1 - t ) * ( Math.PI * 2 - deltaAngle );
  21546. } else {
  21547. angle = this.aStartAngle + t * deltaAngle;
  21548. }
  21549. var x = this.aX + this.xRadius * Math.cos( angle );
  21550. var y = this.aY + this.yRadius * Math.sin( angle );
  21551. if ( this.aRotation !== 0 ) {
  21552. var cos = Math.cos( this.aRotation );
  21553. var sin = Math.sin( this.aRotation );
  21554. var tx = x, ty = y;
  21555. // Rotate the point about the center of the ellipse.
  21556. x = ( tx - this.aX ) * cos - ( ty - this.aY ) * sin + this.aX;
  21557. y = ( tx - this.aX ) * sin + ( ty - this.aY ) * cos + this.aY;
  21558. }
  21559. return new THREE.Vector2( x, y );
  21560. };
  21561. // File:src/extras/curves/ArcCurve.js
  21562. /**************************************************************
  21563. * Arc curve
  21564. **************************************************************/
  21565. THREE.ArcCurve = function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  21566. THREE.EllipseCurve.call( this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  21567. };
  21568. THREE.ArcCurve.prototype = Object.create( THREE.EllipseCurve.prototype );
  21569. THREE.ArcCurve.prototype.constructor = THREE.ArcCurve;
  21570. // File:src/extras/curves/LineCurve3.js
  21571. /**************************************************************
  21572. * Line3D
  21573. **************************************************************/
  21574. THREE.LineCurve3 = THREE.Curve.create(
  21575. function ( v1, v2 ) {
  21576. this.v1 = v1;
  21577. this.v2 = v2;
  21578. },
  21579. function ( t ) {
  21580. var vector = new THREE.Vector3();
  21581. vector.subVectors( this.v2, this.v1 ); // diff
  21582. vector.multiplyScalar( t );
  21583. vector.add( this.v1 );
  21584. return vector;
  21585. }
  21586. );
  21587. // File:src/extras/curves/QuadraticBezierCurve3.js
  21588. /**************************************************************
  21589. * Quadratic Bezier 3D curve
  21590. **************************************************************/
  21591. THREE.QuadraticBezierCurve3 = THREE.Curve.create(
  21592. function ( v0, v1, v2 ) {
  21593. this.v0 = v0;
  21594. this.v1 = v1;
  21595. this.v2 = v2;
  21596. },
  21597. function ( t ) {
  21598. var b2 = THREE.ShapeUtils.b2;
  21599. return new THREE.Vector3(
  21600. b2( t, this.v0.x, this.v1.x, this.v2.x ),
  21601. b2( t, this.v0.y, this.v1.y, this.v2.y ),
  21602. b2( t, this.v0.z, this.v1.z, this.v2.z )
  21603. );
  21604. }
  21605. );
  21606. // File:src/extras/curves/CubicBezierCurve3.js
  21607. /**************************************************************
  21608. * Cubic Bezier 3D curve
  21609. **************************************************************/
  21610. THREE.CubicBezierCurve3 = THREE.Curve.create(
  21611. function ( v0, v1, v2, v3 ) {
  21612. this.v0 = v0;
  21613. this.v1 = v1;
  21614. this.v2 = v2;
  21615. this.v3 = v3;
  21616. },
  21617. function ( t ) {
  21618. var b3 = THREE.ShapeUtils.b3;
  21619. return new THREE.Vector3(
  21620. b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x ),
  21621. b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y ),
  21622. b3( t, this.v0.z, this.v1.z, this.v2.z, this.v3.z )
  21623. );
  21624. }
  21625. );
  21626. // File:src/extras/curves/SplineCurve3.js
  21627. /**************************************************************
  21628. * Spline 3D curve
  21629. **************************************************************/
  21630. THREE.SplineCurve3 = THREE.Curve.create(
  21631. function ( points /* array of Vector3 */ ) {
  21632. console.warn( 'THREE.SplineCurve3 will be deprecated. Please use THREE.CatmullRomCurve3' );
  21633. this.points = ( points == undefined ) ? [] : points;
  21634. },
  21635. function ( t ) {
  21636. var points = this.points;
  21637. var point = ( points.length - 1 ) * t;
  21638. var intPoint = Math.floor( point );
  21639. var weight = point - intPoint;
  21640. var point0 = points[ intPoint == 0 ? intPoint : intPoint - 1 ];
  21641. var point1 = points[ intPoint ];
  21642. var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  21643. var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  21644. var interpolate = THREE.CurveUtils.interpolate;
  21645. return new THREE.Vector3(
  21646. interpolate( point0.x, point1.x, point2.x, point3.x, weight ),
  21647. interpolate( point0.y, point1.y, point2.y, point3.y, weight ),
  21648. interpolate( point0.z, point1.z, point2.z, point3.z, weight )
  21649. );
  21650. }
  21651. );
  21652. // File:src/extras/curves/CatmullRomCurve3.js
  21653. /**
  21654. * @author zz85 https://github.com/zz85
  21655. *
  21656. * Centripetal CatmullRom Curve - which is useful for avoiding
  21657. * cusps and self-intersections in non-uniform catmull rom curves.
  21658. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  21659. *
  21660. * curve.type accepts centripetal(default), chordal and catmullrom
  21661. * curve.tension is used for catmullrom which defaults to 0.5
  21662. */
  21663. THREE.CatmullRomCurve3 = ( function() {
  21664. var
  21665. tmp = new THREE.Vector3(),
  21666. px = new CubicPoly(),
  21667. py = new CubicPoly(),
  21668. pz = new CubicPoly();
  21669. /*
  21670. Based on an optimized c++ solution in
  21671. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  21672. - http://ideone.com/NoEbVM
  21673. This CubicPoly class could be used for reusing some variables and calculations,
  21674. but for three.js curve use, it could be possible inlined and flatten into a single function call
  21675. which can be placed in CurveUtils.
  21676. */
  21677. function CubicPoly() {
  21678. }
  21679. /*
  21680. * Compute coefficients for a cubic polynomial
  21681. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  21682. * such that
  21683. * p(0) = x0, p(1) = x1
  21684. * and
  21685. * p'(0) = t0, p'(1) = t1.
  21686. */
  21687. CubicPoly.prototype.init = function( x0, x1, t0, t1 ) {
  21688. this.c0 = x0;
  21689. this.c1 = t0;
  21690. this.c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  21691. this.c3 = 2 * x0 - 2 * x1 + t0 + t1;
  21692. };
  21693. CubicPoly.prototype.initNonuniformCatmullRom = function( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  21694. // compute tangents when parameterized in [t1,t2]
  21695. var t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  21696. var t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  21697. // rescale tangents for parametrization in [0,1]
  21698. t1 *= dt1;
  21699. t2 *= dt1;
  21700. // initCubicPoly
  21701. this.init( x1, x2, t1, t2 );
  21702. };
  21703. // standard Catmull-Rom spline: interpolate between x1 and x2 with previous/following points x1/x4
  21704. CubicPoly.prototype.initCatmullRom = function( x0, x1, x2, x3, tension ) {
  21705. this.init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  21706. };
  21707. CubicPoly.prototype.calc = function( t ) {
  21708. var t2 = t * t;
  21709. var t3 = t2 * t;
  21710. return this.c0 + this.c1 * t + this.c2 * t2 + this.c3 * t3;
  21711. };
  21712. // Subclass Three.js curve
  21713. return THREE.Curve.create(
  21714. function ( p /* array of Vector3 */ ) {
  21715. this.points = p || [];
  21716. this.closed = false;
  21717. },
  21718. function ( t ) {
  21719. var points = this.points,
  21720. point, intPoint, weight, l;
  21721. l = points.length;
  21722. if ( l < 2 ) console.log( 'duh, you need at least 2 points' );
  21723. point = ( l - ( this.closed ? 0 : 1 ) ) * t;
  21724. intPoint = Math.floor( point );
  21725. weight = point - intPoint;
  21726. if ( this.closed ) {
  21727. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / points.length ) + 1 ) * points.length;
  21728. } else if ( weight === 0 && intPoint === l - 1 ) {
  21729. intPoint = l - 2;
  21730. weight = 1;
  21731. }
  21732. var p0, p1, p2, p3; // 4 points
  21733. if ( this.closed || intPoint > 0 ) {
  21734. p0 = points[ ( intPoint - 1 ) % l ];
  21735. } else {
  21736. // extrapolate first point
  21737. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  21738. p0 = tmp;
  21739. }
  21740. p1 = points[ intPoint % l ];
  21741. p2 = points[ ( intPoint + 1 ) % l ];
  21742. if ( this.closed || intPoint + 2 < l ) {
  21743. p3 = points[ ( intPoint + 2 ) % l ];
  21744. } else {
  21745. // extrapolate last point
  21746. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 1 ] );
  21747. p3 = tmp;
  21748. }
  21749. if ( this.type === undefined || this.type === 'centripetal' || this.type === 'chordal' ) {
  21750. // init Centripetal / Chordal Catmull-Rom
  21751. var pow = this.type === 'chordal' ? 0.5 : 0.25;
  21752. var dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  21753. var dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  21754. var dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  21755. // safety check for repeated points
  21756. if ( dt1 < 1e-4 ) dt1 = 1.0;
  21757. if ( dt0 < 1e-4 ) dt0 = dt1;
  21758. if ( dt2 < 1e-4 ) dt2 = dt1;
  21759. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  21760. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  21761. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  21762. } else if ( this.type === 'catmullrom' ) {
  21763. var tension = this.tension !== undefined ? this.tension : 0.5;
  21764. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, tension );
  21765. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, tension );
  21766. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, tension );
  21767. }
  21768. var v = new THREE.Vector3(
  21769. px.calc( weight ),
  21770. py.calc( weight ),
  21771. pz.calc( weight )
  21772. );
  21773. return v;
  21774. }
  21775. );
  21776. } )();
  21777. // File:src/extras/curves/ClosedSplineCurve3.js
  21778. /**************************************************************
  21779. * Closed Spline 3D curve
  21780. **************************************************************/
  21781. THREE.ClosedSplineCurve3 = function ( points ) {
  21782. console.warn( 'THREE.ClosedSplineCurve3 has been deprecated. Please use THREE.CatmullRomCurve3.' );
  21783. THREE.CatmullRomCurve3.call( this, points );
  21784. this.type = 'catmullrom';
  21785. this.closed = true;
  21786. };
  21787. THREE.ClosedSplineCurve3.prototype = Object.create( THREE.CatmullRomCurve3.prototype );
  21788. // File:src/extras/geometries/BoxGeometry.js
  21789. /**
  21790. * @author mrdoob / http://mrdoob.com/
  21791. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Cube.as
  21792. */
  21793. THREE.BoxGeometry = function ( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  21794. THREE.Geometry.call( this );
  21795. this.type = 'BoxGeometry';
  21796. this.parameters = {
  21797. width: width,
  21798. height: height,
  21799. depth: depth,
  21800. widthSegments: widthSegments,
  21801. heightSegments: heightSegments,
  21802. depthSegments: depthSegments
  21803. };
  21804. this.fromBufferGeometry( new THREE.BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) );
  21805. this.mergeVertices();
  21806. };
  21807. THREE.BoxGeometry.prototype = Object.create( THREE.Geometry.prototype );
  21808. THREE.BoxGeometry.prototype.constructor = THREE.BoxGeometry;
  21809. THREE.CubeGeometry = THREE.BoxGeometry;
  21810. // File:src/extras/geometries/BoxBufferGeometry.js
  21811. /**
  21812. * @author Mugen87 / https://github.com/Mugen87
  21813. */
  21814. THREE.BoxBufferGeometry = function ( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  21815. THREE.BufferGeometry.call( this );
  21816. this.type = 'BoxBufferGeometry';
  21817. this.parameters = {
  21818. width: width,
  21819. height: height,
  21820. depth: depth,
  21821. widthSegments: widthSegments,
  21822. heightSegments: heightSegments,
  21823. depthSegments: depthSegments
  21824. };
  21825. var scope = this;
  21826. // segments
  21827. widthSegments = Math.floor( widthSegments ) || 1;
  21828. heightSegments = Math.floor( heightSegments ) || 1;
  21829. depthSegments = Math.floor( depthSegments ) || 1;
  21830. // these are used to calculate buffer length
  21831. var vertexCount = calculateVertexCount( widthSegments, heightSegments, depthSegments );
  21832. var indexCount = calculateIndexCount( widthSegments, heightSegments, depthSegments );
  21833. // buffers
  21834. var indices = new ( indexCount > 65535 ? Uint32Array : Uint16Array )( indexCount );
  21835. var vertices = new Float32Array( vertexCount * 3 );
  21836. var normals = new Float32Array( vertexCount * 3 );
  21837. var uvs = new Float32Array( vertexCount * 2 );
  21838. // offset variables
  21839. var vertexBufferOffset = 0;
  21840. var uvBufferOffset = 0;
  21841. var indexBufferOffset = 0;
  21842. var numberOfVertices = 0;
  21843. // group variables
  21844. var groupStart = 0;
  21845. // build each side of the box geometry
  21846. buildPlane( 'z', 'y', 'x', - 1, - 1, depth, height, width, depthSegments, heightSegments, 0 ); // px
  21847. buildPlane( 'z', 'y', 'x', 1, - 1, depth, height, - width, depthSegments, heightSegments, 1 ); // nx
  21848. buildPlane( 'x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2 ); // py
  21849. buildPlane( 'x', 'z', 'y', 1, - 1, width, depth, - height, widthSegments, depthSegments, 3 ); // ny
  21850. buildPlane( 'x', 'y', 'z', 1, - 1, width, height, depth, widthSegments, heightSegments, 4 ); // pz
  21851. buildPlane( 'x', 'y', 'z', - 1, - 1, width, height, - depth, widthSegments, heightSegments, 5 ); // nz
  21852. // build geometry
  21853. this.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  21854. this.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  21855. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  21856. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  21857. // helper functions
  21858. function calculateVertexCount ( w, h, d ) {
  21859. var vertices = 0;
  21860. // calculate the amount of vertices for each side (plane)
  21861. vertices += (w + 1) * (h + 1) * 2; // xy
  21862. vertices += (w + 1) * (d + 1) * 2; // xz
  21863. vertices += (d + 1) * (h + 1) * 2; // zy
  21864. return vertices;
  21865. }
  21866. function calculateIndexCount ( w, h, d ) {
  21867. var index = 0;
  21868. // calculate the amount of squares for each side
  21869. index += w * h * 2; // xy
  21870. index += w * d * 2; // xz
  21871. index += d * h * 2; // zy
  21872. return index * 6; // two triangles per square => six vertices per square
  21873. }
  21874. function buildPlane ( u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex ) {
  21875. var segmentWidth = width / gridX;
  21876. var segmentHeight = height / gridY;
  21877. var widthHalf = width / 2;
  21878. var heightHalf = height / 2;
  21879. var depthHalf = depth / 2;
  21880. var gridX1 = gridX + 1;
  21881. var gridY1 = gridY + 1;
  21882. var vertexCounter = 0;
  21883. var groupCount = 0;
  21884. var vector = new THREE.Vector3();
  21885. // generate vertices, normals and uvs
  21886. for ( var iy = 0; iy < gridY1; iy ++ ) {
  21887. var y = iy * segmentHeight - heightHalf;
  21888. for ( var ix = 0; ix < gridX1; ix ++ ) {
  21889. var x = ix * segmentWidth - widthHalf;
  21890. // set values to correct vector component
  21891. vector[ u ] = x * udir;
  21892. vector[ v ] = y * vdir;
  21893. vector[ w ] = depthHalf;
  21894. // now apply vector to vertex buffer
  21895. vertices[ vertexBufferOffset ] = vector.x;
  21896. vertices[ vertexBufferOffset + 1 ] = vector.y;
  21897. vertices[ vertexBufferOffset + 2 ] = vector.z;
  21898. // set values to correct vector component
  21899. vector[ u ] = 0;
  21900. vector[ v ] = 0;
  21901. vector[ w ] = depth > 0 ? 1 : - 1;
  21902. // now apply vector to normal buffer
  21903. normals[ vertexBufferOffset ] = vector.x;
  21904. normals[ vertexBufferOffset + 1 ] = vector.y;
  21905. normals[ vertexBufferOffset + 2 ] = vector.z;
  21906. // uvs
  21907. uvs[ uvBufferOffset ] = ix / gridX;
  21908. uvs[ uvBufferOffset + 1 ] = 1 - ( iy / gridY );
  21909. // update offsets and counters
  21910. vertexBufferOffset += 3;
  21911. uvBufferOffset += 2;
  21912. vertexCounter += 1;
  21913. }
  21914. }
  21915. // 1. you need three indices to draw a single face
  21916. // 2. a single segment consists of two faces
  21917. // 3. so we need to generate six (2*3) indices per segment
  21918. for ( iy = 0; iy < gridY; iy ++ ) {
  21919. for ( ix = 0; ix < gridX; ix ++ ) {
  21920. // indices
  21921. var a = numberOfVertices + ix + gridX1 * iy;
  21922. var b = numberOfVertices + ix + gridX1 * ( iy + 1 );
  21923. var c = numberOfVertices + ( ix + 1 ) + gridX1 * ( iy + 1 );
  21924. var d = numberOfVertices + ( ix + 1 ) + gridX1 * iy;
  21925. // face one
  21926. indices[ indexBufferOffset ] = a;
  21927. indices[ indexBufferOffset + 1 ] = b;
  21928. indices[ indexBufferOffset + 2 ] = d;
  21929. // face two
  21930. indices[ indexBufferOffset + 3 ] = b;
  21931. indices[ indexBufferOffset + 4 ] = c;
  21932. indices[ indexBufferOffset + 5 ] = d;
  21933. // update offsets and counters
  21934. indexBufferOffset += 6;
  21935. groupCount += 6;
  21936. }
  21937. }
  21938. // add a group to the geometry. this will ensure multi material support
  21939. scope.addGroup( groupStart, groupCount, materialIndex );
  21940. // calculate new start value for groups
  21941. groupStart += groupCount;
  21942. // update total number of vertices
  21943. numberOfVertices += vertexCounter;
  21944. }
  21945. };
  21946. THREE.BoxBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  21947. THREE.BoxBufferGeometry.prototype.constructor = THREE.BoxBufferGeometry;
  21948. // File:src/extras/geometries/CircleGeometry.js
  21949. /**
  21950. * @author hughes
  21951. */
  21952. THREE.CircleGeometry = function ( radius, segments, thetaStart, thetaLength ) {
  21953. THREE.Geometry.call( this );
  21954. this.type = 'CircleGeometry';
  21955. this.parameters = {
  21956. radius: radius,
  21957. segments: segments,
  21958. thetaStart: thetaStart,
  21959. thetaLength: thetaLength
  21960. };
  21961. this.fromBufferGeometry( new THREE.CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) );
  21962. };
  21963. THREE.CircleGeometry.prototype = Object.create( THREE.Geometry.prototype );
  21964. THREE.CircleGeometry.prototype.constructor = THREE.CircleGeometry;
  21965. // File:src/extras/geometries/CircleBufferGeometry.js
  21966. /**
  21967. * @author benaadams / https://twitter.com/ben_a_adams
  21968. */
  21969. THREE.CircleBufferGeometry = function ( radius, segments, thetaStart, thetaLength ) {
  21970. THREE.BufferGeometry.call( this );
  21971. this.type = 'CircleBufferGeometry';
  21972. this.parameters = {
  21973. radius: radius,
  21974. segments: segments,
  21975. thetaStart: thetaStart,
  21976. thetaLength: thetaLength
  21977. };
  21978. radius = radius || 50;
  21979. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  21980. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  21981. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  21982. var vertices = segments + 2;
  21983. var positions = new Float32Array( vertices * 3 );
  21984. var normals = new Float32Array( vertices * 3 );
  21985. var uvs = new Float32Array( vertices * 2 );
  21986. // center data is already zero, but need to set a few extras
  21987. normals[ 2 ] = 1.0;
  21988. uvs[ 0 ] = 0.5;
  21989. uvs[ 1 ] = 0.5;
  21990. for ( var s = 0, i = 3, ii = 2 ; s <= segments; s ++, i += 3, ii += 2 ) {
  21991. var segment = thetaStart + s / segments * thetaLength;
  21992. positions[ i ] = radius * Math.cos( segment );
  21993. positions[ i + 1 ] = radius * Math.sin( segment );
  21994. normals[ i + 2 ] = 1; // normal z
  21995. uvs[ ii ] = ( positions[ i ] / radius + 1 ) / 2;
  21996. uvs[ ii + 1 ] = ( positions[ i + 1 ] / radius + 1 ) / 2;
  21997. }
  21998. var indices = [];
  21999. for ( var i = 1; i <= segments; i ++ ) {
  22000. indices.push( i, i + 1, 0 );
  22001. }
  22002. this.setIndex( new THREE.BufferAttribute( new Uint16Array( indices ), 1 ) );
  22003. this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
  22004. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  22005. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  22006. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  22007. };
  22008. THREE.CircleBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  22009. THREE.CircleBufferGeometry.prototype.constructor = THREE.CircleBufferGeometry;
  22010. // File:src/extras/geometries/CylinderBufferGeometry.js
  22011. /**
  22012. * @author Mugen87 / https://github.com/Mugen87
  22013. */
  22014. THREE.CylinderBufferGeometry = function( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  22015. THREE.BufferGeometry.call( this );
  22016. this.type = 'CylinderBufferGeometry';
  22017. this.parameters = {
  22018. radiusTop: radiusTop,
  22019. radiusBottom: radiusBottom,
  22020. height: height,
  22021. radialSegments: radialSegments,
  22022. heightSegments: heightSegments,
  22023. openEnded: openEnded,
  22024. thetaStart: thetaStart,
  22025. thetaLength: thetaLength
  22026. };
  22027. var scope = this;
  22028. radiusTop = radiusTop !== undefined ? radiusTop : 20;
  22029. radiusBottom = radiusBottom !== undefined ? radiusBottom : 20;
  22030. height = height !== undefined ? height : 100;
  22031. radialSegments = Math.floor( radialSegments ) || 8;
  22032. heightSegments = Math.floor( heightSegments ) || 1;
  22033. openEnded = openEnded !== undefined ? openEnded : false;
  22034. thetaStart = thetaStart !== undefined ? thetaStart : 0.0;
  22035. thetaLength = thetaLength !== undefined ? thetaLength : 2.0 * Math.PI;
  22036. // used to calculate buffer length
  22037. var nbCap = 0;
  22038. if ( openEnded === false ) {
  22039. if ( radiusTop > 0 ) nbCap ++;
  22040. if ( radiusBottom > 0 ) nbCap ++;
  22041. }
  22042. var vertexCount = calculateVertexCount();
  22043. var indexCount = calculateIndexCount();
  22044. // buffers
  22045. var indices = new THREE.BufferAttribute( new ( indexCount > 65535 ? Uint32Array : Uint16Array )( indexCount ), 1 );
  22046. var vertices = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  22047. var normals = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  22048. var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
  22049. // helper variables
  22050. var index = 0,
  22051. indexOffset = 0,
  22052. indexArray = [],
  22053. halfHeight = height / 2;
  22054. // group variables
  22055. var groupStart = 0;
  22056. // generate geometry
  22057. generateTorso();
  22058. if ( openEnded === false ) {
  22059. if ( radiusTop > 0 ) generateCap( true );
  22060. if ( radiusBottom > 0 ) generateCap( false );
  22061. }
  22062. // build geometry
  22063. this.setIndex( indices );
  22064. this.addAttribute( 'position', vertices );
  22065. this.addAttribute( 'normal', normals );
  22066. this.addAttribute( 'uv', uvs );
  22067. // helper functions
  22068. function calculateVertexCount() {
  22069. var count = ( radialSegments + 1 ) * ( heightSegments + 1 );
  22070. if ( openEnded === false ) {
  22071. count += ( ( radialSegments + 1 ) * nbCap ) + ( radialSegments * nbCap );
  22072. }
  22073. return count;
  22074. }
  22075. function calculateIndexCount() {
  22076. var count = radialSegments * heightSegments * 2 * 3;
  22077. if ( openEnded === false ) {
  22078. count += radialSegments * nbCap * 3;
  22079. }
  22080. return count;
  22081. }
  22082. function generateTorso() {
  22083. var x, y;
  22084. var normal = new THREE.Vector3();
  22085. var vertex = new THREE.Vector3();
  22086. var groupCount = 0;
  22087. // this will be used to calculate the normal
  22088. var tanTheta = ( radiusBottom - radiusTop ) / height;
  22089. // generate vertices, normals and uvs
  22090. for ( y = 0; y <= heightSegments; y ++ ) {
  22091. var indexRow = [];
  22092. var v = y / heightSegments;
  22093. // calculate the radius of the current row
  22094. var radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  22095. for ( x = 0; x <= radialSegments; x ++ ) {
  22096. var u = x / radialSegments;
  22097. // vertex
  22098. vertex.x = radius * Math.sin( u * thetaLength + thetaStart );
  22099. vertex.y = - v * height + halfHeight;
  22100. vertex.z = radius * Math.cos( u * thetaLength + thetaStart );
  22101. vertices.setXYZ( index, vertex.x, vertex.y, vertex.z );
  22102. // normal
  22103. normal.copy( vertex );
  22104. // handle special case if radiusTop/radiusBottom is zero
  22105. if ( ( radiusTop === 0 && y === 0 ) || ( radiusBottom === 0 && y === heightSegments ) ) {
  22106. normal.x = Math.sin( u * thetaLength + thetaStart );
  22107. normal.z = Math.cos( u * thetaLength + thetaStart );
  22108. }
  22109. normal.setY( Math.sqrt( normal.x * normal.x + normal.z * normal.z ) * tanTheta ).normalize();
  22110. normals.setXYZ( index, normal.x, normal.y, normal.z );
  22111. // uv
  22112. uvs.setXY( index, u, 1 - v );
  22113. // save index of vertex in respective row
  22114. indexRow.push( index );
  22115. // increase index
  22116. index ++;
  22117. }
  22118. // now save vertices of the row in our index array
  22119. indexArray.push( indexRow );
  22120. }
  22121. // generate indices
  22122. for ( x = 0; x < radialSegments; x ++ ) {
  22123. for ( y = 0; y < heightSegments; y ++ ) {
  22124. // we use the index array to access the correct indices
  22125. var i1 = indexArray[ y ][ x ];
  22126. var i2 = indexArray[ y + 1 ][ x ];
  22127. var i3 = indexArray[ y + 1 ][ x + 1 ];
  22128. var i4 = indexArray[ y ][ x + 1 ];
  22129. // face one
  22130. indices.setX( indexOffset, i1 ); indexOffset ++;
  22131. indices.setX( indexOffset, i2 ); indexOffset ++;
  22132. indices.setX( indexOffset, i4 ); indexOffset ++;
  22133. // face two
  22134. indices.setX( indexOffset, i2 ); indexOffset ++;
  22135. indices.setX( indexOffset, i3 ); indexOffset ++;
  22136. indices.setX( indexOffset, i4 ); indexOffset ++;
  22137. // update counters
  22138. groupCount += 6;
  22139. }
  22140. }
  22141. // add a group to the geometry. this will ensure multi material support
  22142. scope.addGroup( groupStart, groupCount, 0 );
  22143. // calculate new start value for groups
  22144. groupStart += groupCount;
  22145. }
  22146. function generateCap( top ) {
  22147. var x, centerIndexStart, centerIndexEnd;
  22148. var uv = new THREE.Vector2();
  22149. var vertex = new THREE.Vector3();
  22150. var groupCount = 0;
  22151. var radius = ( top === true ) ? radiusTop : radiusBottom;
  22152. var sign = ( top === true ) ? 1 : - 1;
  22153. // save the index of the first center vertex
  22154. centerIndexStart = index;
  22155. // first we generate the center vertex data of the cap.
  22156. // because the geometry needs one set of uvs per face,
  22157. // we must generate a center vertex per face/segment
  22158. for ( x = 1; x <= radialSegments; x ++ ) {
  22159. // vertex
  22160. vertices.setXYZ( index, 0, halfHeight * sign, 0 );
  22161. // normal
  22162. normals.setXYZ( index, 0, sign, 0 );
  22163. // uv
  22164. uv.x = 0.5;
  22165. uv.y = 0.5;
  22166. uvs.setXY( index, uv.x, uv.y );
  22167. // increase index
  22168. index ++;
  22169. }
  22170. // save the index of the last center vertex
  22171. centerIndexEnd = index;
  22172. // now we generate the surrounding vertices, normals and uvs
  22173. for ( x = 0; x <= radialSegments; x ++ ) {
  22174. var u = x / radialSegments;
  22175. var theta = u * thetaLength + thetaStart;
  22176. var cosTheta = Math.cos( theta );
  22177. var sinTheta = Math.sin( theta );
  22178. // vertex
  22179. vertex.x = radius * sinTheta;
  22180. vertex.y = halfHeight * sign;
  22181. vertex.z = radius * cosTheta;
  22182. vertices.setXYZ( index, vertex.x, vertex.y, vertex.z );
  22183. // normal
  22184. normals.setXYZ( index, 0, sign, 0 );
  22185. // uv
  22186. uv.x = ( cosTheta * 0.5 ) + 0.5;
  22187. uv.y = ( sinTheta * 0.5 * sign ) + 0.5;
  22188. uvs.setXY( index, uv.x, uv.y );
  22189. // increase index
  22190. index ++;
  22191. }
  22192. // generate indices
  22193. for ( x = 0; x < radialSegments; x ++ ) {
  22194. var c = centerIndexStart + x;
  22195. var i = centerIndexEnd + x;
  22196. if ( top === true ) {
  22197. // face top
  22198. indices.setX( indexOffset, i ); indexOffset ++;
  22199. indices.setX( indexOffset, i + 1 ); indexOffset ++;
  22200. indices.setX( indexOffset, c ); indexOffset ++;
  22201. } else {
  22202. // face bottom
  22203. indices.setX( indexOffset, i + 1 ); indexOffset ++;
  22204. indices.setX( indexOffset, i ); indexOffset ++;
  22205. indices.setX( indexOffset, c ); indexOffset ++;
  22206. }
  22207. // update counters
  22208. groupCount += 3;
  22209. }
  22210. // add a group to the geometry. this will ensure multi material support
  22211. scope.addGroup( groupStart, groupCount, top === true ? 1 : 2 );
  22212. // calculate new start value for groups
  22213. groupStart += groupCount;
  22214. }
  22215. };
  22216. THREE.CylinderBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  22217. THREE.CylinderBufferGeometry.prototype.constructor = THREE.CylinderBufferGeometry;
  22218. // File:src/extras/geometries/CylinderGeometry.js
  22219. /**
  22220. * @author mrdoob / http://mrdoob.com/
  22221. */
  22222. THREE.CylinderGeometry = function ( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  22223. THREE.Geometry.call( this );
  22224. this.type = 'CylinderGeometry';
  22225. this.parameters = {
  22226. radiusTop: radiusTop,
  22227. radiusBottom: radiusBottom,
  22228. height: height,
  22229. radialSegments: radialSegments,
  22230. heightSegments: heightSegments,
  22231. openEnded: openEnded,
  22232. thetaStart: thetaStart,
  22233. thetaLength: thetaLength
  22234. };
  22235. this.fromBufferGeometry( new THREE.CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) );
  22236. this.mergeVertices();
  22237. };
  22238. THREE.CylinderGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22239. THREE.CylinderGeometry.prototype.constructor = THREE.CylinderGeometry;
  22240. // File:src/extras/geometries/ConeBufferGeometry.js
  22241. /*
  22242. * @author: abelnation / http://github.com/abelnation
  22243. */
  22244. THREE.ConeBufferGeometry = function (
  22245. radius, height,
  22246. radialSegments, heightSegments,
  22247. openEnded, thetaStart, thetaLength ) {
  22248. THREE.CylinderBufferGeometry.call( this,
  22249. 0, radius, height,
  22250. radialSegments, heightSegments,
  22251. openEnded, thetaStart, thetaLength );
  22252. this.type = 'ConeBufferGeometry';
  22253. this.parameters = {
  22254. radius: radius,
  22255. height: height,
  22256. radialSegments: radialSegments,
  22257. heightSegments: heightSegments,
  22258. thetaStart: thetaStart,
  22259. thetaLength: thetaLength
  22260. };
  22261. };
  22262. THREE.ConeBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  22263. THREE.ConeBufferGeometry.prototype.constructor = THREE.ConeBufferGeometry;
  22264. // File:src/extras/geometries/ConeGeometry.js
  22265. /**
  22266. * @author abelnation / http://github.com/abelnation
  22267. */
  22268. THREE.ConeGeometry = function (
  22269. radius, height,
  22270. radialSegments, heightSegments,
  22271. openEnded, thetaStart, thetaLength ) {
  22272. THREE.CylinderGeometry.call( this,
  22273. 0, radius, height,
  22274. radialSegments, heightSegments,
  22275. openEnded, thetaStart, thetaLength );
  22276. this.type = 'ConeGeometry';
  22277. this.parameters = {
  22278. radius: radius,
  22279. height: height,
  22280. radialSegments: radialSegments,
  22281. heightSegments: heightSegments,
  22282. openEnded: openEnded,
  22283. thetaStart: thetaStart,
  22284. thetaLength: thetaLength
  22285. };
  22286. };
  22287. THREE.ConeGeometry.prototype = Object.create( THREE.CylinderGeometry.prototype );
  22288. THREE.ConeGeometry.prototype.constructor = THREE.ConeGeometry;
  22289. // File:src/extras/geometries/EdgesGeometry.js
  22290. /**
  22291. * @author WestLangley / http://github.com/WestLangley
  22292. */
  22293. THREE.EdgesGeometry = function ( geometry, thresholdAngle ) {
  22294. THREE.BufferGeometry.call( this );
  22295. thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
  22296. var thresholdDot = Math.cos( THREE.Math.DEG2RAD * thresholdAngle );
  22297. var edge = [ 0, 0 ], hash = {};
  22298. function sortFunction( a, b ) {
  22299. return a - b;
  22300. }
  22301. var keys = [ 'a', 'b', 'c' ];
  22302. var geometry2;
  22303. if ( geometry instanceof THREE.BufferGeometry ) {
  22304. geometry2 = new THREE.Geometry();
  22305. geometry2.fromBufferGeometry( geometry );
  22306. } else {
  22307. geometry2 = geometry.clone();
  22308. }
  22309. geometry2.mergeVertices();
  22310. geometry2.computeFaceNormals();
  22311. var vertices = geometry2.vertices;
  22312. var faces = geometry2.faces;
  22313. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  22314. var face = faces[ i ];
  22315. for ( var j = 0; j < 3; j ++ ) {
  22316. edge[ 0 ] = face[ keys[ j ] ];
  22317. edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
  22318. edge.sort( sortFunction );
  22319. var key = edge.toString();
  22320. if ( hash[ key ] === undefined ) {
  22321. hash[ key ] = { vert1: edge[ 0 ], vert2: edge[ 1 ], face1: i, face2: undefined };
  22322. } else {
  22323. hash[ key ].face2 = i;
  22324. }
  22325. }
  22326. }
  22327. var coords = [];
  22328. for ( var key in hash ) {
  22329. var h = hash[ key ];
  22330. if ( h.face2 === undefined || faces[ h.face1 ].normal.dot( faces[ h.face2 ].normal ) <= thresholdDot ) {
  22331. var vertex = vertices[ h.vert1 ];
  22332. coords.push( vertex.x );
  22333. coords.push( vertex.y );
  22334. coords.push( vertex.z );
  22335. vertex = vertices[ h.vert2 ];
  22336. coords.push( vertex.x );
  22337. coords.push( vertex.y );
  22338. coords.push( vertex.z );
  22339. }
  22340. }
  22341. this.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array( coords ), 3 ) );
  22342. };
  22343. THREE.EdgesGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  22344. THREE.EdgesGeometry.prototype.constructor = THREE.EdgesGeometry;
  22345. // File:src/extras/geometries/ExtrudeGeometry.js
  22346. /**
  22347. * @author zz85 / http://www.lab4games.net/zz85/blog
  22348. *
  22349. * Creates extruded geometry from a path shape.
  22350. *
  22351. * parameters = {
  22352. *
  22353. * curveSegments: <int>, // number of points on the curves
  22354. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  22355. * amount: <int>, // Depth to extrude the shape
  22356. *
  22357. * bevelEnabled: <bool>, // turn on bevel
  22358. * bevelThickness: <float>, // how deep into the original shape bevel goes
  22359. * bevelSize: <float>, // how far from shape outline is bevel
  22360. * bevelSegments: <int>, // number of bevel layers
  22361. *
  22362. * extrudePath: <THREE.CurvePath> // 3d spline path to extrude shape along. (creates Frames if .frames aren't defined)
  22363. * frames: <THREE.TubeGeometry.FrenetFrames> // containing arrays of tangents, normals, binormals
  22364. *
  22365. * uvGenerator: <Object> // object that provides UV generator functions
  22366. *
  22367. * }
  22368. **/
  22369. THREE.ExtrudeGeometry = function ( shapes, options ) {
  22370. if ( typeof( shapes ) === "undefined" ) {
  22371. shapes = [];
  22372. return;
  22373. }
  22374. THREE.Geometry.call( this );
  22375. this.type = 'ExtrudeGeometry';
  22376. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  22377. this.addShapeList( shapes, options );
  22378. this.computeFaceNormals();
  22379. // can't really use automatic vertex normals
  22380. // as then front and back sides get smoothed too
  22381. // should do separate smoothing just for sides
  22382. //this.computeVertexNormals();
  22383. //console.log( "took", ( Date.now() - startTime ) );
  22384. };
  22385. THREE.ExtrudeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22386. THREE.ExtrudeGeometry.prototype.constructor = THREE.ExtrudeGeometry;
  22387. THREE.ExtrudeGeometry.prototype.addShapeList = function ( shapes, options ) {
  22388. var sl = shapes.length;
  22389. for ( var s = 0; s < sl; s ++ ) {
  22390. var shape = shapes[ s ];
  22391. this.addShape( shape, options );
  22392. }
  22393. };
  22394. THREE.ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
  22395. var amount = options.amount !== undefined ? options.amount : 100;
  22396. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6; // 10
  22397. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2; // 8
  22398. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  22399. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true; // false
  22400. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  22401. var steps = options.steps !== undefined ? options.steps : 1;
  22402. var extrudePath = options.extrudePath;
  22403. var extrudePts, extrudeByPath = false;
  22404. // Use default WorldUVGenerator if no UV generators are specified.
  22405. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : THREE.ExtrudeGeometry.WorldUVGenerator;
  22406. var splineTube, binormal, normal, position2;
  22407. if ( extrudePath ) {
  22408. extrudePts = extrudePath.getSpacedPoints( steps );
  22409. extrudeByPath = true;
  22410. bevelEnabled = false; // bevels not supported for path extrusion
  22411. // SETUP TNB variables
  22412. // Reuse TNB from TubeGeomtry for now.
  22413. // TODO1 - have a .isClosed in spline?
  22414. splineTube = options.frames !== undefined ? options.frames : new THREE.TubeGeometry.FrenetFrames( extrudePath, steps, false );
  22415. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  22416. binormal = new THREE.Vector3();
  22417. normal = new THREE.Vector3();
  22418. position2 = new THREE.Vector3();
  22419. }
  22420. // Safeguards if bevels are not enabled
  22421. if ( ! bevelEnabled ) {
  22422. bevelSegments = 0;
  22423. bevelThickness = 0;
  22424. bevelSize = 0;
  22425. }
  22426. // Variables initialization
  22427. var ahole, h, hl; // looping of holes
  22428. var scope = this;
  22429. var shapesOffset = this.vertices.length;
  22430. var shapePoints = shape.extractPoints( curveSegments );
  22431. var vertices = shapePoints.shape;
  22432. var holes = shapePoints.holes;
  22433. var reverse = ! THREE.ShapeUtils.isClockWise( vertices );
  22434. if ( reverse ) {
  22435. vertices = vertices.reverse();
  22436. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  22437. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  22438. ahole = holes[ h ];
  22439. if ( THREE.ShapeUtils.isClockWise( ahole ) ) {
  22440. holes[ h ] = ahole.reverse();
  22441. }
  22442. }
  22443. reverse = false; // If vertices are in order now, we shouldn't need to worry about them again (hopefully)!
  22444. }
  22445. var faces = THREE.ShapeUtils.triangulateShape( vertices, holes );
  22446. /* Vertices */
  22447. var contour = vertices; // vertices has all points but contour has only points of circumference
  22448. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  22449. ahole = holes[ h ];
  22450. vertices = vertices.concat( ahole );
  22451. }
  22452. function scalePt2 ( pt, vec, size ) {
  22453. if ( ! vec ) console.error( "THREE.ExtrudeGeometry: vec does not exist" );
  22454. return vec.clone().multiplyScalar( size ).add( pt );
  22455. }
  22456. var b, bs, t, z,
  22457. vert, vlen = vertices.length,
  22458. face, flen = faces.length;
  22459. // Find directions for point movement
  22460. function getBevelVec( inPt, inPrev, inNext ) {
  22461. // computes for inPt the corresponding point inPt' on a new contour
  22462. // shifted by 1 unit (length of normalized vector) to the left
  22463. // if we walk along contour clockwise, this new contour is outside the old one
  22464. //
  22465. // inPt' is the intersection of the two lines parallel to the two
  22466. // adjacent edges of inPt at a distance of 1 unit on the left side.
  22467. var v_trans_x, v_trans_y, shrink_by = 1; // resulting translation vector for inPt
  22468. // good reading for geometry algorithms (here: line-line intersection)
  22469. // http://geomalgorithms.com/a05-_intersect-1.html
  22470. var v_prev_x = inPt.x - inPrev.x, v_prev_y = inPt.y - inPrev.y;
  22471. var v_next_x = inNext.x - inPt.x, v_next_y = inNext.y - inPt.y;
  22472. var v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  22473. // check for collinear edges
  22474. var collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  22475. if ( Math.abs( collinear0 ) > Number.EPSILON ) {
  22476. // not collinear
  22477. // length of vectors for normalizing
  22478. var v_prev_len = Math.sqrt( v_prev_lensq );
  22479. var v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  22480. // shift adjacent points by unit vectors to the left
  22481. var ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  22482. var ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  22483. var ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  22484. var ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  22485. // scaling factor for v_prev to intersection point
  22486. var sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  22487. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  22488. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  22489. // vector from inPt to intersection point
  22490. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  22491. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  22492. // Don't normalize!, otherwise sharp corners become ugly
  22493. // but prevent crazy spikes
  22494. var v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  22495. if ( v_trans_lensq <= 2 ) {
  22496. return new THREE.Vector2( v_trans_x, v_trans_y );
  22497. } else {
  22498. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  22499. }
  22500. } else {
  22501. // handle special case of collinear edges
  22502. var direction_eq = false; // assumes: opposite
  22503. if ( v_prev_x > Number.EPSILON ) {
  22504. if ( v_next_x > Number.EPSILON ) {
  22505. direction_eq = true;
  22506. }
  22507. } else {
  22508. if ( v_prev_x < - Number.EPSILON ) {
  22509. if ( v_next_x < - Number.EPSILON ) {
  22510. direction_eq = true;
  22511. }
  22512. } else {
  22513. if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
  22514. direction_eq = true;
  22515. }
  22516. }
  22517. }
  22518. if ( direction_eq ) {
  22519. // console.log("Warning: lines are a straight sequence");
  22520. v_trans_x = - v_prev_y;
  22521. v_trans_y = v_prev_x;
  22522. shrink_by = Math.sqrt( v_prev_lensq );
  22523. } else {
  22524. // console.log("Warning: lines are a straight spike");
  22525. v_trans_x = v_prev_x;
  22526. v_trans_y = v_prev_y;
  22527. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  22528. }
  22529. }
  22530. return new THREE.Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  22531. }
  22532. var contourMovements = [];
  22533. for ( var i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  22534. if ( j === il ) j = 0;
  22535. if ( k === il ) k = 0;
  22536. // (j)---(i)---(k)
  22537. // console.log('i,j,k', i, j , k)
  22538. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  22539. }
  22540. var holesMovements = [], oneHoleMovements, verticesMovements = contourMovements.concat();
  22541. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  22542. ahole = holes[ h ];
  22543. oneHoleMovements = [];
  22544. for ( i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  22545. if ( j === il ) j = 0;
  22546. if ( k === il ) k = 0;
  22547. // (j)---(i)---(k)
  22548. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  22549. }
  22550. holesMovements.push( oneHoleMovements );
  22551. verticesMovements = verticesMovements.concat( oneHoleMovements );
  22552. }
  22553. // Loop bevelSegments, 1 for the front, 1 for the back
  22554. for ( b = 0; b < bevelSegments; b ++ ) {
  22555. //for ( b = bevelSegments; b > 0; b -- ) {
  22556. t = b / bevelSegments;
  22557. z = bevelThickness * ( 1 - t );
  22558. //z = bevelThickness * t;
  22559. bs = bevelSize * ( Math.sin ( t * Math.PI / 2 ) ); // curved
  22560. //bs = bevelSize * t; // linear
  22561. // contract shape
  22562. for ( i = 0, il = contour.length; i < il; i ++ ) {
  22563. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  22564. v( vert.x, vert.y, - z );
  22565. }
  22566. // expand holes
  22567. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  22568. ahole = holes[ h ];
  22569. oneHoleMovements = holesMovements[ h ];
  22570. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  22571. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  22572. v( vert.x, vert.y, - z );
  22573. }
  22574. }
  22575. }
  22576. bs = bevelSize;
  22577. // Back facing vertices
  22578. for ( i = 0; i < vlen; i ++ ) {
  22579. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  22580. if ( ! extrudeByPath ) {
  22581. v( vert.x, vert.y, 0 );
  22582. } else {
  22583. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  22584. normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x );
  22585. binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y );
  22586. position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
  22587. v( position2.x, position2.y, position2.z );
  22588. }
  22589. }
  22590. // Add stepped vertices...
  22591. // Including front facing vertices
  22592. var s;
  22593. for ( s = 1; s <= steps; s ++ ) {
  22594. for ( i = 0; i < vlen; i ++ ) {
  22595. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  22596. if ( ! extrudeByPath ) {
  22597. v( vert.x, vert.y, amount / steps * s );
  22598. } else {
  22599. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  22600. normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x );
  22601. binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y );
  22602. position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
  22603. v( position2.x, position2.y, position2.z );
  22604. }
  22605. }
  22606. }
  22607. // Add bevel segments planes
  22608. //for ( b = 1; b <= bevelSegments; b ++ ) {
  22609. for ( b = bevelSegments - 1; b >= 0; b -- ) {
  22610. t = b / bevelSegments;
  22611. z = bevelThickness * ( 1 - t );
  22612. //bs = bevelSize * ( 1-Math.sin ( ( 1 - t ) * Math.PI/2 ) );
  22613. bs = bevelSize * Math.sin ( t * Math.PI / 2 );
  22614. // contract shape
  22615. for ( i = 0, il = contour.length; i < il; i ++ ) {
  22616. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  22617. v( vert.x, vert.y, amount + z );
  22618. }
  22619. // expand holes
  22620. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  22621. ahole = holes[ h ];
  22622. oneHoleMovements = holesMovements[ h ];
  22623. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  22624. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  22625. if ( ! extrudeByPath ) {
  22626. v( vert.x, vert.y, amount + z );
  22627. } else {
  22628. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  22629. }
  22630. }
  22631. }
  22632. }
  22633. /* Faces */
  22634. // Top and bottom faces
  22635. buildLidFaces();
  22636. // Sides faces
  22637. buildSideFaces();
  22638. ///// Internal functions
  22639. function buildLidFaces() {
  22640. if ( bevelEnabled ) {
  22641. var layer = 0; // steps + 1
  22642. var offset = vlen * layer;
  22643. // Bottom faces
  22644. for ( i = 0; i < flen; i ++ ) {
  22645. face = faces[ i ];
  22646. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  22647. }
  22648. layer = steps + bevelSegments * 2;
  22649. offset = vlen * layer;
  22650. // Top faces
  22651. for ( i = 0; i < flen; i ++ ) {
  22652. face = faces[ i ];
  22653. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  22654. }
  22655. } else {
  22656. // Bottom faces
  22657. for ( i = 0; i < flen; i ++ ) {
  22658. face = faces[ i ];
  22659. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  22660. }
  22661. // Top faces
  22662. for ( i = 0; i < flen; i ++ ) {
  22663. face = faces[ i ];
  22664. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  22665. }
  22666. }
  22667. }
  22668. // Create faces for the z-sides of the shape
  22669. function buildSideFaces() {
  22670. var layeroffset = 0;
  22671. sidewalls( contour, layeroffset );
  22672. layeroffset += contour.length;
  22673. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  22674. ahole = holes[ h ];
  22675. sidewalls( ahole, layeroffset );
  22676. //, true
  22677. layeroffset += ahole.length;
  22678. }
  22679. }
  22680. function sidewalls( contour, layeroffset ) {
  22681. var j, k;
  22682. i = contour.length;
  22683. while ( -- i >= 0 ) {
  22684. j = i;
  22685. k = i - 1;
  22686. if ( k < 0 ) k = contour.length - 1;
  22687. //console.log('b', i,j, i-1, k,vertices.length);
  22688. var s = 0, sl = steps + bevelSegments * 2;
  22689. for ( s = 0; s < sl; s ++ ) {
  22690. var slen1 = vlen * s;
  22691. var slen2 = vlen * ( s + 1 );
  22692. var a = layeroffset + j + slen1,
  22693. b = layeroffset + k + slen1,
  22694. c = layeroffset + k + slen2,
  22695. d = layeroffset + j + slen2;
  22696. f4( a, b, c, d, contour, s, sl, j, k );
  22697. }
  22698. }
  22699. }
  22700. function v( x, y, z ) {
  22701. scope.vertices.push( new THREE.Vector3( x, y, z ) );
  22702. }
  22703. function f3( a, b, c ) {
  22704. a += shapesOffset;
  22705. b += shapesOffset;
  22706. c += shapesOffset;
  22707. scope.faces.push( new THREE.Face3( a, b, c, null, null, 0 ) );
  22708. var uvs = uvgen.generateTopUV( scope, a, b, c );
  22709. scope.faceVertexUvs[ 0 ].push( uvs );
  22710. }
  22711. function f4( a, b, c, d, wallContour, stepIndex, stepsLength, contourIndex1, contourIndex2 ) {
  22712. a += shapesOffset;
  22713. b += shapesOffset;
  22714. c += shapesOffset;
  22715. d += shapesOffset;
  22716. scope.faces.push( new THREE.Face3( a, b, d, null, null, 1 ) );
  22717. scope.faces.push( new THREE.Face3( b, c, d, null, null, 1 ) );
  22718. var uvs = uvgen.generateSideWallUV( scope, a, b, c, d );
  22719. scope.faceVertexUvs[ 0 ].push( [ uvs[ 0 ], uvs[ 1 ], uvs[ 3 ] ] );
  22720. scope.faceVertexUvs[ 0 ].push( [ uvs[ 1 ], uvs[ 2 ], uvs[ 3 ] ] );
  22721. }
  22722. };
  22723. THREE.ExtrudeGeometry.WorldUVGenerator = {
  22724. generateTopUV: function ( geometry, indexA, indexB, indexC ) {
  22725. var vertices = geometry.vertices;
  22726. var a = vertices[ indexA ];
  22727. var b = vertices[ indexB ];
  22728. var c = vertices[ indexC ];
  22729. return [
  22730. new THREE.Vector2( a.x, a.y ),
  22731. new THREE.Vector2( b.x, b.y ),
  22732. new THREE.Vector2( c.x, c.y )
  22733. ];
  22734. },
  22735. generateSideWallUV: function ( geometry, indexA, indexB, indexC, indexD ) {
  22736. var vertices = geometry.vertices;
  22737. var a = vertices[ indexA ];
  22738. var b = vertices[ indexB ];
  22739. var c = vertices[ indexC ];
  22740. var d = vertices[ indexD ];
  22741. if ( Math.abs( a.y - b.y ) < 0.01 ) {
  22742. return [
  22743. new THREE.Vector2( a.x, 1 - a.z ),
  22744. new THREE.Vector2( b.x, 1 - b.z ),
  22745. new THREE.Vector2( c.x, 1 - c.z ),
  22746. new THREE.Vector2( d.x, 1 - d.z )
  22747. ];
  22748. } else {
  22749. return [
  22750. new THREE.Vector2( a.y, 1 - a.z ),
  22751. new THREE.Vector2( b.y, 1 - b.z ),
  22752. new THREE.Vector2( c.y, 1 - c.z ),
  22753. new THREE.Vector2( d.y, 1 - d.z )
  22754. ];
  22755. }
  22756. }
  22757. };
  22758. // File:src/extras/geometries/ShapeGeometry.js
  22759. /**
  22760. * @author jonobr1 / http://jonobr1.com
  22761. *
  22762. * Creates a one-sided polygonal geometry from a path shape. Similar to
  22763. * ExtrudeGeometry.
  22764. *
  22765. * parameters = {
  22766. *
  22767. * curveSegments: <int>, // number of points on the curves. NOT USED AT THE MOMENT.
  22768. *
  22769. * material: <int> // material index for front and back faces
  22770. * uvGenerator: <Object> // object that provides UV generator functions
  22771. *
  22772. * }
  22773. **/
  22774. THREE.ShapeGeometry = function ( shapes, options ) {
  22775. THREE.Geometry.call( this );
  22776. this.type = 'ShapeGeometry';
  22777. if ( Array.isArray( shapes ) === false ) shapes = [ shapes ];
  22778. this.addShapeList( shapes, options );
  22779. this.computeFaceNormals();
  22780. };
  22781. THREE.ShapeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22782. THREE.ShapeGeometry.prototype.constructor = THREE.ShapeGeometry;
  22783. /**
  22784. * Add an array of shapes to THREE.ShapeGeometry.
  22785. */
  22786. THREE.ShapeGeometry.prototype.addShapeList = function ( shapes, options ) {
  22787. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  22788. this.addShape( shapes[ i ], options );
  22789. }
  22790. return this;
  22791. };
  22792. /**
  22793. * Adds a shape to THREE.ShapeGeometry, based on THREE.ExtrudeGeometry.
  22794. */
  22795. THREE.ShapeGeometry.prototype.addShape = function ( shape, options ) {
  22796. if ( options === undefined ) options = {};
  22797. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  22798. var material = options.material;
  22799. var uvgen = options.UVGenerator === undefined ? THREE.ExtrudeGeometry.WorldUVGenerator : options.UVGenerator;
  22800. //
  22801. var i, l, hole;
  22802. var shapesOffset = this.vertices.length;
  22803. var shapePoints = shape.extractPoints( curveSegments );
  22804. var vertices = shapePoints.shape;
  22805. var holes = shapePoints.holes;
  22806. var reverse = ! THREE.ShapeUtils.isClockWise( vertices );
  22807. if ( reverse ) {
  22808. vertices = vertices.reverse();
  22809. // Maybe we should also check if holes are in the opposite direction, just to be safe...
  22810. for ( i = 0, l = holes.length; i < l; i ++ ) {
  22811. hole = holes[ i ];
  22812. if ( THREE.ShapeUtils.isClockWise( hole ) ) {
  22813. holes[ i ] = hole.reverse();
  22814. }
  22815. }
  22816. reverse = false;
  22817. }
  22818. var faces = THREE.ShapeUtils.triangulateShape( vertices, holes );
  22819. // Vertices
  22820. for ( i = 0, l = holes.length; i < l; i ++ ) {
  22821. hole = holes[ i ];
  22822. vertices = vertices.concat( hole );
  22823. }
  22824. //
  22825. var vert, vlen = vertices.length;
  22826. var face, flen = faces.length;
  22827. for ( i = 0; i < vlen; i ++ ) {
  22828. vert = vertices[ i ];
  22829. this.vertices.push( new THREE.Vector3( vert.x, vert.y, 0 ) );
  22830. }
  22831. for ( i = 0; i < flen; i ++ ) {
  22832. face = faces[ i ];
  22833. var a = face[ 0 ] + shapesOffset;
  22834. var b = face[ 1 ] + shapesOffset;
  22835. var c = face[ 2 ] + shapesOffset;
  22836. this.faces.push( new THREE.Face3( a, b, c, null, null, material ) );
  22837. this.faceVertexUvs[ 0 ].push( uvgen.generateTopUV( this, a, b, c ) );
  22838. }
  22839. };
  22840. // File:src/extras/geometries/LatheBufferGeometry.js
  22841. /**
  22842. * @author Mugen87 / https://github.com/Mugen87
  22843. */
  22844. // points - to create a closed torus, one must use a set of points
  22845. // like so: [ a, b, c, d, a ], see first is the same as last.
  22846. // segments - the number of circumference segments to create
  22847. // phiStart - the starting radian
  22848. // phiLength - the radian (0 to 2PI) range of the lathed section
  22849. // 2PI is a closed lathe, less than 2PI is a portion.
  22850. THREE.LatheBufferGeometry = function ( points, segments, phiStart, phiLength ) {
  22851. THREE.BufferGeometry.call( this );
  22852. this.type = 'LatheBufferGeometry';
  22853. this.parameters = {
  22854. points: points,
  22855. segments: segments,
  22856. phiStart: phiStart,
  22857. phiLength: phiLength
  22858. };
  22859. segments = Math.floor( segments ) || 12;
  22860. phiStart = phiStart || 0;
  22861. phiLength = phiLength || Math.PI * 2;
  22862. // clamp phiLength so it's in range of [ 0, 2PI ]
  22863. phiLength = THREE.Math.clamp( phiLength, 0, Math.PI * 2 );
  22864. // these are used to calculate buffer length
  22865. var vertexCount = ( segments + 1 ) * points.length;
  22866. var indexCount = segments * points.length * 2 * 3;
  22867. // buffers
  22868. var indices = new THREE.BufferAttribute( new ( indexCount > 65535 ? Uint32Array : Uint16Array )( indexCount ) , 1 );
  22869. var vertices = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  22870. var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
  22871. // helper variables
  22872. var index = 0, indexOffset = 0, base;
  22873. var inversePointLength = 1.0 / ( points.length - 1 );
  22874. var inverseSegments = 1.0 / segments;
  22875. var vertex = new THREE.Vector3();
  22876. var uv = new THREE.Vector2();
  22877. var i, j;
  22878. // generate vertices and uvs
  22879. for ( i = 0; i <= segments; i ++ ) {
  22880. var phi = phiStart + i * inverseSegments * phiLength;
  22881. var sin = Math.sin( phi );
  22882. var cos = Math.cos( phi );
  22883. for ( j = 0; j <= ( points.length - 1 ); j ++ ) {
  22884. // vertex
  22885. vertex.x = points[ j ].x * sin;
  22886. vertex.y = points[ j ].y;
  22887. vertex.z = points[ j ].x * cos;
  22888. vertices.setXYZ( index, vertex.x, vertex.y, vertex.z );
  22889. // uv
  22890. uv.x = i / segments;
  22891. uv.y = j / ( points.length - 1 );
  22892. uvs.setXY( index, uv.x, uv.y );
  22893. // increase index
  22894. index ++;
  22895. }
  22896. }
  22897. // generate indices
  22898. for ( i = 0; i < segments; i ++ ) {
  22899. for ( j = 0; j < ( points.length - 1 ); j ++ ) {
  22900. base = j + i * points.length;
  22901. // indices
  22902. var a = base;
  22903. var b = base + points.length;
  22904. var c = base + points.length + 1;
  22905. var d = base + 1;
  22906. // face one
  22907. indices.setX( indexOffset, a ); indexOffset++;
  22908. indices.setX( indexOffset, b ); indexOffset++;
  22909. indices.setX( indexOffset, d ); indexOffset++;
  22910. // face two
  22911. indices.setX( indexOffset, b ); indexOffset++;
  22912. indices.setX( indexOffset, c ); indexOffset++;
  22913. indices.setX( indexOffset, d ); indexOffset++;
  22914. }
  22915. }
  22916. // build geometry
  22917. this.setIndex( indices );
  22918. this.addAttribute( 'position', vertices );
  22919. this.addAttribute( 'uv', uvs );
  22920. // generate normals
  22921. this.computeVertexNormals();
  22922. // if the geometry is closed, we need to average the normals along the seam.
  22923. // because the corresponding vertices are identical (but still have different UVs).
  22924. if( phiLength === Math.PI * 2 ) {
  22925. var normals = this.attributes.normal.array;
  22926. var n1 = new THREE.Vector3();
  22927. var n2 = new THREE.Vector3();
  22928. var n = new THREE.Vector3();
  22929. // this is the buffer offset for the last line of vertices
  22930. base = segments * points.length * 3;
  22931. for( i = 0, j = 0; i < points.length; i ++, j += 3 ) {
  22932. // select the normal of the vertex in the first line
  22933. n1.x = normals[ j + 0 ];
  22934. n1.y = normals[ j + 1 ];
  22935. n1.z = normals[ j + 2 ];
  22936. // select the normal of the vertex in the last line
  22937. n2.x = normals[ base + j + 0 ];
  22938. n2.y = normals[ base + j + 1 ];
  22939. n2.z = normals[ base + j + 2 ];
  22940. // average normals
  22941. n.addVectors( n1, n2 ).normalize();
  22942. // assign the new values to both normals
  22943. normals[ j + 0 ] = normals[ base + j + 0 ] = n.x;
  22944. normals[ j + 1 ] = normals[ base + j + 1 ] = n.y;
  22945. normals[ j + 2 ] = normals[ base + j + 2 ] = n.z;
  22946. } // next row
  22947. }
  22948. };
  22949. THREE.LatheBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  22950. THREE.LatheBufferGeometry.prototype.constructor = THREE.LatheBufferGeometry;
  22951. // File:src/extras/geometries/LatheGeometry.js
  22952. /**
  22953. * @author astrodud / http://astrodud.isgreat.org/
  22954. * @author zz85 / https://github.com/zz85
  22955. * @author bhouston / http://clara.io
  22956. */
  22957. // points - to create a closed torus, one must use a set of points
  22958. // like so: [ a, b, c, d, a ], see first is the same as last.
  22959. // segments - the number of circumference segments to create
  22960. // phiStart - the starting radian
  22961. // phiLength - the radian (0 to 2PI) range of the lathed section
  22962. // 2PI is a closed lathe, less than 2PI is a portion.
  22963. THREE.LatheGeometry = function ( points, segments, phiStart, phiLength ) {
  22964. THREE.Geometry.call( this );
  22965. this.type = 'LatheGeometry';
  22966. this.parameters = {
  22967. points: points,
  22968. segments: segments,
  22969. phiStart: phiStart,
  22970. phiLength: phiLength
  22971. };
  22972. this.fromBufferGeometry( new THREE.LatheBufferGeometry( points, segments, phiStart, phiLength ) );
  22973. this.mergeVertices();
  22974. };
  22975. THREE.LatheGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22976. THREE.LatheGeometry.prototype.constructor = THREE.LatheGeometry;
  22977. // File:src/extras/geometries/PlaneGeometry.js
  22978. /**
  22979. * @author mrdoob / http://mrdoob.com/
  22980. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
  22981. */
  22982. THREE.PlaneGeometry = function ( width, height, widthSegments, heightSegments ) {
  22983. THREE.Geometry.call( this );
  22984. this.type = 'PlaneGeometry';
  22985. this.parameters = {
  22986. width: width,
  22987. height: height,
  22988. widthSegments: widthSegments,
  22989. heightSegments: heightSegments
  22990. };
  22991. this.fromBufferGeometry( new THREE.PlaneBufferGeometry( width, height, widthSegments, heightSegments ) );
  22992. };
  22993. THREE.PlaneGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22994. THREE.PlaneGeometry.prototype.constructor = THREE.PlaneGeometry;
  22995. // File:src/extras/geometries/PlaneBufferGeometry.js
  22996. /**
  22997. * @author mrdoob / http://mrdoob.com/
  22998. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
  22999. */
  23000. THREE.PlaneBufferGeometry = function ( width, height, widthSegments, heightSegments ) {
  23001. THREE.BufferGeometry.call( this );
  23002. this.type = 'PlaneBufferGeometry';
  23003. this.parameters = {
  23004. width: width,
  23005. height: height,
  23006. widthSegments: widthSegments,
  23007. heightSegments: heightSegments
  23008. };
  23009. var width_half = width / 2;
  23010. var height_half = height / 2;
  23011. var gridX = Math.floor( widthSegments ) || 1;
  23012. var gridY = Math.floor( heightSegments ) || 1;
  23013. var gridX1 = gridX + 1;
  23014. var gridY1 = gridY + 1;
  23015. var segment_width = width / gridX;
  23016. var segment_height = height / gridY;
  23017. var vertices = new Float32Array( gridX1 * gridY1 * 3 );
  23018. var normals = new Float32Array( gridX1 * gridY1 * 3 );
  23019. var uvs = new Float32Array( gridX1 * gridY1 * 2 );
  23020. var offset = 0;
  23021. var offset2 = 0;
  23022. for ( var iy = 0; iy < gridY1; iy ++ ) {
  23023. var y = iy * segment_height - height_half;
  23024. for ( var ix = 0; ix < gridX1; ix ++ ) {
  23025. var x = ix * segment_width - width_half;
  23026. vertices[ offset ] = x;
  23027. vertices[ offset + 1 ] = - y;
  23028. normals[ offset + 2 ] = 1;
  23029. uvs[ offset2 ] = ix / gridX;
  23030. uvs[ offset2 + 1 ] = 1 - ( iy / gridY );
  23031. offset += 3;
  23032. offset2 += 2;
  23033. }
  23034. }
  23035. offset = 0;
  23036. var indices = new ( ( vertices.length / 3 ) > 65535 ? Uint32Array : Uint16Array )( gridX * gridY * 6 );
  23037. for ( var iy = 0; iy < gridY; iy ++ ) {
  23038. for ( var ix = 0; ix < gridX; ix ++ ) {
  23039. var a = ix + gridX1 * iy;
  23040. var b = ix + gridX1 * ( iy + 1 );
  23041. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  23042. var d = ( ix + 1 ) + gridX1 * iy;
  23043. indices[ offset ] = a;
  23044. indices[ offset + 1 ] = b;
  23045. indices[ offset + 2 ] = d;
  23046. indices[ offset + 3 ] = b;
  23047. indices[ offset + 4 ] = c;
  23048. indices[ offset + 5 ] = d;
  23049. offset += 6;
  23050. }
  23051. }
  23052. this.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  23053. this.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  23054. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  23055. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  23056. };
  23057. THREE.PlaneBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  23058. THREE.PlaneBufferGeometry.prototype.constructor = THREE.PlaneBufferGeometry;
  23059. // File:src/extras/geometries/RingBufferGeometry.js
  23060. /**
  23061. * @author Mugen87 / https://github.com/Mugen87
  23062. */
  23063. THREE.RingBufferGeometry = function ( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  23064. THREE.BufferGeometry.call( this );
  23065. this.type = 'RingBufferGeometry';
  23066. this.parameters = {
  23067. innerRadius: innerRadius,
  23068. outerRadius: outerRadius,
  23069. thetaSegments: thetaSegments,
  23070. phiSegments: phiSegments,
  23071. thetaStart: thetaStart,
  23072. thetaLength: thetaLength
  23073. };
  23074. innerRadius = innerRadius || 20;
  23075. outerRadius = outerRadius || 50;
  23076. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  23077. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  23078. thetaSegments = thetaSegments !== undefined ? Math.max( 3, thetaSegments ) : 8;
  23079. phiSegments = phiSegments !== undefined ? Math.max( 1, phiSegments ) : 1;
  23080. // these are used to calculate buffer length
  23081. var vertexCount = ( thetaSegments + 1 ) * ( phiSegments + 1 );
  23082. var indexCount = thetaSegments * phiSegments * 2 * 3;
  23083. // buffers
  23084. var indices = new THREE.BufferAttribute( new ( indexCount > 65535 ? Uint32Array : Uint16Array )( indexCount ) , 1 );
  23085. var vertices = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  23086. var normals = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  23087. var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
  23088. // some helper variables
  23089. var index = 0, indexOffset = 0, segment;
  23090. var radius = innerRadius;
  23091. var radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  23092. var vertex = new THREE.Vector3();
  23093. var uv = new THREE.Vector2();
  23094. var j, i;
  23095. // generate vertices, normals and uvs
  23096. // values are generate from the inside of the ring to the outside
  23097. for ( j = 0; j <= phiSegments; j ++ ) {
  23098. for ( i = 0; i <= thetaSegments; i ++ ) {
  23099. segment = thetaStart + i / thetaSegments * thetaLength;
  23100. // vertex
  23101. vertex.x = radius * Math.cos( segment );
  23102. vertex.y = radius * Math.sin( segment );
  23103. vertices.setXYZ( index, vertex.x, vertex.y, vertex.z );
  23104. // normal
  23105. normals.setXYZ( index, 0, 0, 1 );
  23106. // uv
  23107. uv.x = ( vertex.x / outerRadius + 1 ) / 2;
  23108. uv.y = ( vertex.y / outerRadius + 1 ) / 2;
  23109. uvs.setXY( index, uv.x, uv.y );
  23110. // increase index
  23111. index++;
  23112. }
  23113. // increase the radius for next row of vertices
  23114. radius += radiusStep;
  23115. }
  23116. // generate indices
  23117. for ( j = 0; j < phiSegments; j ++ ) {
  23118. var thetaSegmentLevel = j * ( thetaSegments + 1 );
  23119. for ( i = 0; i < thetaSegments; i ++ ) {
  23120. segment = i + thetaSegmentLevel;
  23121. // indices
  23122. var a = segment;
  23123. var b = segment + thetaSegments + 1;
  23124. var c = segment + thetaSegments + 2;
  23125. var d = segment + 1;
  23126. // face one
  23127. indices.setX( indexOffset, a ); indexOffset++;
  23128. indices.setX( indexOffset, b ); indexOffset++;
  23129. indices.setX( indexOffset, c ); indexOffset++;
  23130. // face two
  23131. indices.setX( indexOffset, a ); indexOffset++;
  23132. indices.setX( indexOffset, c ); indexOffset++;
  23133. indices.setX( indexOffset, d ); indexOffset++;
  23134. }
  23135. }
  23136. // build geometry
  23137. this.setIndex( indices );
  23138. this.addAttribute( 'position', vertices );
  23139. this.addAttribute( 'normal', normals );
  23140. this.addAttribute( 'uv', uvs );
  23141. };
  23142. THREE.RingBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  23143. THREE.RingBufferGeometry.prototype.constructor = THREE.RingBufferGeometry;
  23144. // File:src/extras/geometries/RingGeometry.js
  23145. /**
  23146. * @author Kaleb Murphy
  23147. */
  23148. THREE.RingGeometry = function ( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  23149. THREE.Geometry.call( this );
  23150. this.type = 'RingGeometry';
  23151. this.parameters = {
  23152. innerRadius: innerRadius,
  23153. outerRadius: outerRadius,
  23154. thetaSegments: thetaSegments,
  23155. phiSegments: phiSegments,
  23156. thetaStart: thetaStart,
  23157. thetaLength: thetaLength
  23158. };
  23159. this.fromBufferGeometry( new THREE.RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) );
  23160. };
  23161. THREE.RingGeometry.prototype = Object.create( THREE.Geometry.prototype );
  23162. THREE.RingGeometry.prototype.constructor = THREE.RingGeometry;
  23163. // File:src/extras/geometries/SphereGeometry.js
  23164. /**
  23165. * @author mrdoob / http://mrdoob.com/
  23166. */
  23167. THREE.SphereGeometry = function ( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  23168. THREE.Geometry.call( this );
  23169. this.type = 'SphereGeometry';
  23170. this.parameters = {
  23171. radius: radius,
  23172. widthSegments: widthSegments,
  23173. heightSegments: heightSegments,
  23174. phiStart: phiStart,
  23175. phiLength: phiLength,
  23176. thetaStart: thetaStart,
  23177. thetaLength: thetaLength
  23178. };
  23179. this.fromBufferGeometry( new THREE.SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) );
  23180. };
  23181. THREE.SphereGeometry.prototype = Object.create( THREE.Geometry.prototype );
  23182. THREE.SphereGeometry.prototype.constructor = THREE.SphereGeometry;
  23183. // File:src/extras/geometries/SphereBufferGeometry.js
  23184. /**
  23185. * @author benaadams / https://twitter.com/ben_a_adams
  23186. * based on THREE.SphereGeometry
  23187. */
  23188. THREE.SphereBufferGeometry = function ( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  23189. THREE.BufferGeometry.call( this );
  23190. this.type = 'SphereBufferGeometry';
  23191. this.parameters = {
  23192. radius: radius,
  23193. widthSegments: widthSegments,
  23194. heightSegments: heightSegments,
  23195. phiStart: phiStart,
  23196. phiLength: phiLength,
  23197. thetaStart: thetaStart,
  23198. thetaLength: thetaLength
  23199. };
  23200. radius = radius || 50;
  23201. widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
  23202. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  23203. phiStart = phiStart !== undefined ? phiStart : 0;
  23204. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  23205. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  23206. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  23207. var thetaEnd = thetaStart + thetaLength;
  23208. var vertexCount = ( ( widthSegments + 1 ) * ( heightSegments + 1 ) );
  23209. var positions = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  23210. var normals = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  23211. var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
  23212. var index = 0, vertices = [], normal = new THREE.Vector3();
  23213. for ( var y = 0; y <= heightSegments; y ++ ) {
  23214. var verticesRow = [];
  23215. var v = y / heightSegments;
  23216. for ( var x = 0; x <= widthSegments; x ++ ) {
  23217. var u = x / widthSegments;
  23218. var px = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  23219. var py = radius * Math.cos( thetaStart + v * thetaLength );
  23220. var pz = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  23221. normal.set( px, py, pz ).normalize();
  23222. positions.setXYZ( index, px, py, pz );
  23223. normals.setXYZ( index, normal.x, normal.y, normal.z );
  23224. uvs.setXY( index, u, 1 - v );
  23225. verticesRow.push( index );
  23226. index ++;
  23227. }
  23228. vertices.push( verticesRow );
  23229. }
  23230. var indices = [];
  23231. for ( var y = 0; y < heightSegments; y ++ ) {
  23232. for ( var x = 0; x < widthSegments; x ++ ) {
  23233. var v1 = vertices[ y ][ x + 1 ];
  23234. var v2 = vertices[ y ][ x ];
  23235. var v3 = vertices[ y + 1 ][ x ];
  23236. var v4 = vertices[ y + 1 ][ x + 1 ];
  23237. if ( y !== 0 || thetaStart > 0 ) indices.push( v1, v2, v4 );
  23238. if ( y !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( v2, v3, v4 );
  23239. }
  23240. }
  23241. this.setIndex( new ( positions.count > 65535 ? THREE.Uint32Attribute : THREE.Uint16Attribute )( indices, 1 ) );
  23242. this.addAttribute( 'position', positions );
  23243. this.addAttribute( 'normal', normals );
  23244. this.addAttribute( 'uv', uvs );
  23245. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  23246. };
  23247. THREE.SphereBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  23248. THREE.SphereBufferGeometry.prototype.constructor = THREE.SphereBufferGeometry;
  23249. // File:src/extras/geometries/TextGeometry.js
  23250. /**
  23251. * @author zz85 / http://www.lab4games.net/zz85/blog
  23252. * @author alteredq / http://alteredqualia.com/
  23253. *
  23254. * Text = 3D Text
  23255. *
  23256. * parameters = {
  23257. * font: <THREE.Font>, // font
  23258. *
  23259. * size: <float>, // size of the text
  23260. * height: <float>, // thickness to extrude text
  23261. * curveSegments: <int>, // number of points on the curves
  23262. *
  23263. * bevelEnabled: <bool>, // turn on bevel
  23264. * bevelThickness: <float>, // how deep into text bevel goes
  23265. * bevelSize: <float> // how far from text outline is bevel
  23266. * }
  23267. */
  23268. THREE.TextGeometry = function ( text, parameters ) {
  23269. parameters = parameters || {};
  23270. var font = parameters.font;
  23271. if ( font instanceof THREE.Font === false ) {
  23272. console.error( 'THREE.TextGeometry: font parameter is not an instance of THREE.Font.' );
  23273. return new THREE.Geometry();
  23274. }
  23275. var shapes = font.generateShapes( text, parameters.size, parameters.curveSegments );
  23276. // translate parameters to ExtrudeGeometry API
  23277. parameters.amount = parameters.height !== undefined ? parameters.height : 50;
  23278. // defaults
  23279. if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
  23280. if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
  23281. if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
  23282. THREE.ExtrudeGeometry.call( this, shapes, parameters );
  23283. this.type = 'TextGeometry';
  23284. };
  23285. THREE.TextGeometry.prototype = Object.create( THREE.ExtrudeGeometry.prototype );
  23286. THREE.TextGeometry.prototype.constructor = THREE.TextGeometry;
  23287. // File:src/extras/geometries/TorusBufferGeometry.js
  23288. /**
  23289. * @author Mugen87 / https://github.com/Mugen87
  23290. */
  23291. THREE.TorusBufferGeometry = function ( radius, tube, radialSegments, tubularSegments, arc ) {
  23292. THREE.BufferGeometry.call( this );
  23293. this.type = 'TorusBufferGeometry';
  23294. this.parameters = {
  23295. radius: radius,
  23296. tube: tube,
  23297. radialSegments: radialSegments,
  23298. tubularSegments: tubularSegments,
  23299. arc: arc
  23300. };
  23301. radius = radius || 100;
  23302. tube = tube || 40;
  23303. radialSegments = Math.floor( radialSegments ) || 8;
  23304. tubularSegments = Math.floor( tubularSegments ) || 6;
  23305. arc = arc || Math.PI * 2;
  23306. // used to calculate buffer length
  23307. var vertexCount = ( ( radialSegments + 1 ) * ( tubularSegments + 1 ) );
  23308. var indexCount = radialSegments * tubularSegments * 2 * 3;
  23309. // buffers
  23310. var indices = new ( indexCount > 65535 ? Uint32Array : Uint16Array )( indexCount );
  23311. var vertices = new Float32Array( vertexCount * 3 );
  23312. var normals = new Float32Array( vertexCount * 3 );
  23313. var uvs = new Float32Array( vertexCount * 2 );
  23314. // offset variables
  23315. var vertexBufferOffset = 0;
  23316. var uvBufferOffset = 0;
  23317. var indexBufferOffset = 0;
  23318. // helper variables
  23319. var center = new THREE.Vector3();
  23320. var vertex = new THREE.Vector3();
  23321. var normal = new THREE.Vector3();
  23322. var j, i;
  23323. // generate vertices, normals and uvs
  23324. for ( j = 0; j <= radialSegments; j ++ ) {
  23325. for ( i = 0; i <= tubularSegments; i ++ ) {
  23326. var u = i / tubularSegments * arc;
  23327. var v = j / radialSegments * Math.PI * 2;
  23328. // vertex
  23329. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  23330. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  23331. vertex.z = tube * Math.sin( v );
  23332. vertices[ vertexBufferOffset ] = vertex.x;
  23333. vertices[ vertexBufferOffset + 1 ] = vertex.y;
  23334. vertices[ vertexBufferOffset + 2 ] = vertex.z;
  23335. // this vector is used to calculate the normal
  23336. center.x = radius * Math.cos( u );
  23337. center.y = radius * Math.sin( u );
  23338. // normal
  23339. normal.subVectors( vertex, center ).normalize();
  23340. normals[ vertexBufferOffset ] = normal.x;
  23341. normals[ vertexBufferOffset + 1 ] = normal.y;
  23342. normals[ vertexBufferOffset + 2 ] = normal.z;
  23343. // uv
  23344. uvs[ uvBufferOffset ] = i / tubularSegments;
  23345. uvs[ uvBufferOffset + 1 ] = j / radialSegments;
  23346. // update offsets
  23347. vertexBufferOffset += 3;
  23348. uvBufferOffset += 2;
  23349. }
  23350. }
  23351. // generate indices
  23352. for ( j = 1; j <= radialSegments; j ++ ) {
  23353. for ( i = 1; i <= tubularSegments; i ++ ) {
  23354. // indices
  23355. var a = ( tubularSegments + 1 ) * j + i - 1;
  23356. var b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  23357. var c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  23358. var d = ( tubularSegments + 1 ) * j + i;
  23359. // face one
  23360. indices[ indexBufferOffset ] = a;
  23361. indices[ indexBufferOffset + 1 ] = b;
  23362. indices[ indexBufferOffset + 2 ] = d;
  23363. // face two
  23364. indices[ indexBufferOffset + 3 ] = b;
  23365. indices[ indexBufferOffset + 4 ] = c;
  23366. indices[ indexBufferOffset + 5 ] = d;
  23367. // update offset
  23368. indexBufferOffset += 6;
  23369. }
  23370. }
  23371. // build geometry
  23372. this.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  23373. this.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  23374. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  23375. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  23376. };
  23377. THREE.TorusBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  23378. THREE.TorusBufferGeometry.prototype.constructor = THREE.TorusBufferGeometry;
  23379. // File:src/extras/geometries/TorusGeometry.js
  23380. /**
  23381. * @author oosmoxiecode
  23382. * @author mrdoob / http://mrdoob.com/
  23383. * based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3DLite/src/away3dlite/primitives/Torus.as?r=2888
  23384. */
  23385. THREE.TorusGeometry = function ( radius, tube, radialSegments, tubularSegments, arc ) {
  23386. THREE.Geometry.call( this );
  23387. this.type = 'TorusGeometry';
  23388. this.parameters = {
  23389. radius: radius,
  23390. tube: tube,
  23391. radialSegments: radialSegments,
  23392. tubularSegments: tubularSegments,
  23393. arc: arc
  23394. };
  23395. this.fromBufferGeometry( new THREE.TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) );
  23396. };
  23397. THREE.TorusGeometry.prototype = Object.create( THREE.Geometry.prototype );
  23398. THREE.TorusGeometry.prototype.constructor = THREE.TorusGeometry;
  23399. // File:src/extras/geometries/TorusKnotBufferGeometry.js
  23400. /**
  23401. * @author Mugen87 / https://github.com/Mugen87
  23402. *
  23403. * see: http://www.blackpawn.com/texts/pqtorus/
  23404. */
  23405. THREE.TorusKnotBufferGeometry = function ( radius, tube, tubularSegments, radialSegments, p, q ) {
  23406. THREE.BufferGeometry.call( this );
  23407. this.type = 'TorusKnotBufferGeometry';
  23408. this.parameters = {
  23409. radius: radius,
  23410. tube: tube,
  23411. tubularSegments: tubularSegments,
  23412. radialSegments: radialSegments,
  23413. p: p,
  23414. q: q
  23415. };
  23416. radius = radius || 100;
  23417. tube = tube || 40;
  23418. tubularSegments = Math.floor( tubularSegments ) || 64;
  23419. radialSegments = Math.floor( radialSegments ) || 8;
  23420. p = p || 2;
  23421. q = q || 3;
  23422. // used to calculate buffer length
  23423. var vertexCount = ( ( radialSegments + 1 ) * ( tubularSegments + 1 ) );
  23424. var indexCount = radialSegments * tubularSegments * 2 * 3;
  23425. // buffers
  23426. var indices = new THREE.BufferAttribute( new ( indexCount > 65535 ? Uint32Array : Uint16Array )( indexCount ) , 1 );
  23427. var vertices = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  23428. var normals = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  23429. var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
  23430. // helper variables
  23431. var i, j, index = 0, indexOffset = 0;
  23432. var vertex = new THREE.Vector3();
  23433. var normal = new THREE.Vector3();
  23434. var uv = new THREE.Vector2();
  23435. var P1 = new THREE.Vector3();
  23436. var P2 = new THREE.Vector3();
  23437. var B = new THREE.Vector3();
  23438. var T = new THREE.Vector3();
  23439. var N = new THREE.Vector3();
  23440. // generate vertices, normals and uvs
  23441. for ( i = 0; i <= tubularSegments; ++ i ) {
  23442. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  23443. var u = i / tubularSegments * p * Math.PI * 2;
  23444. // now we calculate two points. P1 is our current position on the curve, P2 is a little farther ahead.
  23445. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  23446. calculatePositionOnCurve( u, p, q, radius, P1 );
  23447. calculatePositionOnCurve( u + 0.01, p, q, radius, P2 );
  23448. // calculate orthonormal basis
  23449. T.subVectors( P2, P1 );
  23450. N.addVectors( P2, P1 );
  23451. B.crossVectors( T, N );
  23452. N.crossVectors( B, T );
  23453. // normalize B, N. T can be ignored, we don't use it
  23454. B.normalize();
  23455. N.normalize();
  23456. for ( j = 0; j <= radialSegments; ++ j ) {
  23457. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  23458. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  23459. var v = j / radialSegments * Math.PI * 2;
  23460. var cx = - tube * Math.cos( v );
  23461. var cy = tube * Math.sin( v );
  23462. // now calculate the final vertex position.
  23463. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  23464. vertex.x = P1.x + ( cx * N.x + cy * B.x );
  23465. vertex.y = P1.y + ( cx * N.y + cy * B.y );
  23466. vertex.z = P1.z + ( cx * N.z + cy * B.z );
  23467. // vertex
  23468. vertices.setXYZ( index, vertex.x, vertex.y, vertex.z );
  23469. // normal (P1 is always the center/origin of the extrusion, thus we can use it to calculate the normal)
  23470. normal.subVectors( vertex, P1 ).normalize();
  23471. normals.setXYZ( index, normal.x, normal.y, normal.z );
  23472. // uv
  23473. uv.x = i / tubularSegments;
  23474. uv.y = j / radialSegments;
  23475. uvs.setXY( index, uv.x, uv.y );
  23476. // increase index
  23477. index ++;
  23478. }
  23479. }
  23480. // generate indices
  23481. for ( j = 1; j <= tubularSegments; j ++ ) {
  23482. for ( i = 1; i <= radialSegments; i ++ ) {
  23483. // indices
  23484. var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  23485. var b = ( radialSegments + 1 ) * j + ( i - 1 );
  23486. var c = ( radialSegments + 1 ) * j + i;
  23487. var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  23488. // face one
  23489. indices.setX( indexOffset, a ); indexOffset++;
  23490. indices.setX( indexOffset, b ); indexOffset++;
  23491. indices.setX( indexOffset, d ); indexOffset++;
  23492. // face two
  23493. indices.setX( indexOffset, b ); indexOffset++;
  23494. indices.setX( indexOffset, c ); indexOffset++;
  23495. indices.setX( indexOffset, d ); indexOffset++;
  23496. }
  23497. }
  23498. // build geometry
  23499. this.setIndex( indices );
  23500. this.addAttribute( 'position', vertices );
  23501. this.addAttribute( 'normal', normals );
  23502. this.addAttribute( 'uv', uvs );
  23503. // this function calculates the current position on the torus curve
  23504. function calculatePositionOnCurve( u, p, q, radius, position ) {
  23505. var cu = Math.cos( u );
  23506. var su = Math.sin( u );
  23507. var quOverP = q / p * u;
  23508. var cs = Math.cos( quOverP );
  23509. position.x = radius * ( 2 + cs ) * 0.5 * cu;
  23510. position.y = radius * ( 2 + cs ) * su * 0.5;
  23511. position.z = radius * Math.sin( quOverP ) * 0.5;
  23512. }
  23513. };
  23514. THREE.TorusKnotBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  23515. THREE.TorusKnotBufferGeometry.prototype.constructor = THREE.TorusKnotBufferGeometry;
  23516. // File:src/extras/geometries/TorusKnotGeometry.js
  23517. /**
  23518. * @author oosmoxiecode
  23519. */
  23520. THREE.TorusKnotGeometry = function ( radius, tube, tubularSegments, radialSegments, p, q, heightScale ) {
  23521. THREE.Geometry.call( this );
  23522. this.type = 'TorusKnotGeometry';
  23523. this.parameters = {
  23524. radius: radius,
  23525. tube: tube,
  23526. tubularSegments: tubularSegments,
  23527. radialSegments: radialSegments,
  23528. p: p,
  23529. q: q
  23530. };
  23531. if( heightScale !== undefined ) console.warn( 'THREE.TorusKnotGeometry: heightScale has been deprecated. Use .scale( x, y, z ) instead.' );
  23532. this.fromBufferGeometry( new THREE.TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) );
  23533. this.mergeVertices();
  23534. };
  23535. THREE.TorusKnotGeometry.prototype = Object.create( THREE.Geometry.prototype );
  23536. THREE.TorusKnotGeometry.prototype.constructor = THREE.TorusKnotGeometry;
  23537. // File:src/extras/geometries/TubeGeometry.js
  23538. /**
  23539. * @author WestLangley / https://github.com/WestLangley
  23540. * @author zz85 / https://github.com/zz85
  23541. * @author miningold / https://github.com/miningold
  23542. * @author jonobr1 / https://github.com/jonobr1
  23543. *
  23544. * Modified from the TorusKnotGeometry by @oosmoxiecode
  23545. *
  23546. * Creates a tube which extrudes along a 3d spline
  23547. *
  23548. * Uses parallel transport frames as described in
  23549. * http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  23550. */
  23551. THREE.TubeGeometry = function ( path, segments, radius, radialSegments, closed, taper ) {
  23552. THREE.Geometry.call( this );
  23553. this.type = 'TubeGeometry';
  23554. this.parameters = {
  23555. path: path,
  23556. segments: segments,
  23557. radius: radius,
  23558. radialSegments: radialSegments,
  23559. closed: closed,
  23560. taper: taper
  23561. };
  23562. segments = segments || 64;
  23563. radius = radius || 1;
  23564. radialSegments = radialSegments || 8;
  23565. closed = closed || false;
  23566. taper = taper || THREE.TubeGeometry.NoTaper;
  23567. var grid = [];
  23568. var scope = this,
  23569. tangent,
  23570. normal,
  23571. binormal,
  23572. numpoints = segments + 1,
  23573. u, v, r,
  23574. cx, cy,
  23575. pos, pos2 = new THREE.Vector3(),
  23576. i, j,
  23577. ip, jp,
  23578. a, b, c, d,
  23579. uva, uvb, uvc, uvd;
  23580. var frames = new THREE.TubeGeometry.FrenetFrames( path, segments, closed ),
  23581. tangents = frames.tangents,
  23582. normals = frames.normals,
  23583. binormals = frames.binormals;
  23584. // proxy internals
  23585. this.tangents = tangents;
  23586. this.normals = normals;
  23587. this.binormals = binormals;
  23588. function vert( x, y, z ) {
  23589. return scope.vertices.push( new THREE.Vector3( x, y, z ) ) - 1;
  23590. }
  23591. // construct the grid
  23592. for ( i = 0; i < numpoints; i ++ ) {
  23593. grid[ i ] = [];
  23594. u = i / ( numpoints - 1 );
  23595. pos = path.getPointAt( u );
  23596. tangent = tangents[ i ];
  23597. normal = normals[ i ];
  23598. binormal = binormals[ i ];
  23599. r = radius * taper( u );
  23600. for ( j = 0; j < radialSegments; j ++ ) {
  23601. v = j / radialSegments * 2 * Math.PI;
  23602. cx = - r * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
  23603. cy = r * Math.sin( v );
  23604. pos2.copy( pos );
  23605. pos2.x += cx * normal.x + cy * binormal.x;
  23606. pos2.y += cx * normal.y + cy * binormal.y;
  23607. pos2.z += cx * normal.z + cy * binormal.z;
  23608. grid[ i ][ j ] = vert( pos2.x, pos2.y, pos2.z );
  23609. }
  23610. }
  23611. // construct the mesh
  23612. for ( i = 0; i < segments; i ++ ) {
  23613. for ( j = 0; j < radialSegments; j ++ ) {
  23614. ip = ( closed ) ? ( i + 1 ) % segments : i + 1;
  23615. jp = ( j + 1 ) % radialSegments;
  23616. a = grid[ i ][ j ]; // *** NOT NECESSARILY PLANAR ! ***
  23617. b = grid[ ip ][ j ];
  23618. c = grid[ ip ][ jp ];
  23619. d = grid[ i ][ jp ];
  23620. uva = new THREE.Vector2( i / segments, j / radialSegments );
  23621. uvb = new THREE.Vector2( ( i + 1 ) / segments, j / radialSegments );
  23622. uvc = new THREE.Vector2( ( i + 1 ) / segments, ( j + 1 ) / radialSegments );
  23623. uvd = new THREE.Vector2( i / segments, ( j + 1 ) / radialSegments );
  23624. this.faces.push( new THREE.Face3( a, b, d ) );
  23625. this.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  23626. this.faces.push( new THREE.Face3( b, c, d ) );
  23627. this.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  23628. }
  23629. }
  23630. this.computeFaceNormals();
  23631. this.computeVertexNormals();
  23632. };
  23633. THREE.TubeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  23634. THREE.TubeGeometry.prototype.constructor = THREE.TubeGeometry;
  23635. THREE.TubeGeometry.NoTaper = function ( u ) {
  23636. return 1;
  23637. };
  23638. THREE.TubeGeometry.SinusoidalTaper = function ( u ) {
  23639. return Math.sin( Math.PI * u );
  23640. };
  23641. // For computing of Frenet frames, exposing the tangents, normals and binormals the spline
  23642. THREE.TubeGeometry.FrenetFrames = function ( path, segments, closed ) {
  23643. var normal = new THREE.Vector3(),
  23644. tangents = [],
  23645. normals = [],
  23646. binormals = [],
  23647. vec = new THREE.Vector3(),
  23648. mat = new THREE.Matrix4(),
  23649. numpoints = segments + 1,
  23650. theta,
  23651. smallest,
  23652. tx, ty, tz,
  23653. i, u;
  23654. // expose internals
  23655. this.tangents = tangents;
  23656. this.normals = normals;
  23657. this.binormals = binormals;
  23658. // compute the tangent vectors for each segment on the path
  23659. for ( i = 0; i < numpoints; i ++ ) {
  23660. u = i / ( numpoints - 1 );
  23661. tangents[ i ] = path.getTangentAt( u );
  23662. tangents[ i ].normalize();
  23663. }
  23664. initialNormal3();
  23665. /*
  23666. function initialNormal1(lastBinormal) {
  23667. // fixed start binormal. Has dangers of 0 vectors
  23668. normals[ 0 ] = new THREE.Vector3();
  23669. binormals[ 0 ] = new THREE.Vector3();
  23670. if (lastBinormal===undefined) lastBinormal = new THREE.Vector3( 0, 0, 1 );
  23671. normals[ 0 ].crossVectors( lastBinormal, tangents[ 0 ] ).normalize();
  23672. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] ).normalize();
  23673. }
  23674. function initialNormal2() {
  23675. // This uses the Frenet-Serret formula for deriving binormal
  23676. var t2 = path.getTangentAt( epsilon );
  23677. normals[ 0 ] = new THREE.Vector3().subVectors( t2, tangents[ 0 ] ).normalize();
  23678. binormals[ 0 ] = new THREE.Vector3().crossVectors( tangents[ 0 ], normals[ 0 ] );
  23679. normals[ 0 ].crossVectors( binormals[ 0 ], tangents[ 0 ] ).normalize(); // last binormal x tangent
  23680. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] ).normalize();
  23681. }
  23682. */
  23683. function initialNormal3() {
  23684. // select an initial normal vector perpendicular to the first tangent vector,
  23685. // and in the direction of the smallest tangent xyz component
  23686. normals[ 0 ] = new THREE.Vector3();
  23687. binormals[ 0 ] = new THREE.Vector3();
  23688. smallest = Number.MAX_VALUE;
  23689. tx = Math.abs( tangents[ 0 ].x );
  23690. ty = Math.abs( tangents[ 0 ].y );
  23691. tz = Math.abs( tangents[ 0 ].z );
  23692. if ( tx <= smallest ) {
  23693. smallest = tx;
  23694. normal.set( 1, 0, 0 );
  23695. }
  23696. if ( ty <= smallest ) {
  23697. smallest = ty;
  23698. normal.set( 0, 1, 0 );
  23699. }
  23700. if ( tz <= smallest ) {
  23701. normal.set( 0, 0, 1 );
  23702. }
  23703. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  23704. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  23705. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  23706. }
  23707. // compute the slowly-varying normal and binormal vectors for each segment on the path
  23708. for ( i = 1; i < numpoints; i ++ ) {
  23709. normals[ i ] = normals[ i - 1 ].clone();
  23710. binormals[ i ] = binormals[ i - 1 ].clone();
  23711. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  23712. if ( vec.length() > Number.EPSILON ) {
  23713. vec.normalize();
  23714. theta = Math.acos( THREE.Math.clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  23715. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  23716. }
  23717. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  23718. }
  23719. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  23720. if ( closed ) {
  23721. theta = Math.acos( THREE.Math.clamp( normals[ 0 ].dot( normals[ numpoints - 1 ] ), - 1, 1 ) );
  23722. theta /= ( numpoints - 1 );
  23723. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ numpoints - 1 ] ) ) > 0 ) {
  23724. theta = - theta;
  23725. }
  23726. for ( i = 1; i < numpoints; i ++ ) {
  23727. // twist a little...
  23728. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  23729. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  23730. }
  23731. }
  23732. };
  23733. // File:src/extras/geometries/PolyhedronGeometry.js
  23734. /**
  23735. * @author clockworkgeek / https://github.com/clockworkgeek
  23736. * @author timothypratley / https://github.com/timothypratley
  23737. * @author WestLangley / http://github.com/WestLangley
  23738. */
  23739. THREE.PolyhedronGeometry = function ( vertices, indices, radius, detail ) {
  23740. THREE.Geometry.call( this );
  23741. this.type = 'PolyhedronGeometry';
  23742. this.parameters = {
  23743. vertices: vertices,
  23744. indices: indices,
  23745. radius: radius,
  23746. detail: detail
  23747. };
  23748. radius = radius || 1;
  23749. detail = detail || 0;
  23750. var that = this;
  23751. for ( var i = 0, l = vertices.length; i < l; i += 3 ) {
  23752. prepare( new THREE.Vector3( vertices[ i ], vertices[ i + 1 ], vertices[ i + 2 ] ) );
  23753. }
  23754. var p = this.vertices;
  23755. var faces = [];
  23756. for ( var i = 0, j = 0, l = indices.length; i < l; i += 3, j ++ ) {
  23757. var v1 = p[ indices[ i ] ];
  23758. var v2 = p[ indices[ i + 1 ] ];
  23759. var v3 = p[ indices[ i + 2 ] ];
  23760. faces[ j ] = new THREE.Face3( v1.index, v2.index, v3.index, [ v1.clone(), v2.clone(), v3.clone() ], undefined, j );
  23761. }
  23762. var centroid = new THREE.Vector3();
  23763. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  23764. subdivide( faces[ i ], detail );
  23765. }
  23766. // Handle case when face straddles the seam
  23767. for ( var i = 0, l = this.faceVertexUvs[ 0 ].length; i < l; i ++ ) {
  23768. var uvs = this.faceVertexUvs[ 0 ][ i ];
  23769. var x0 = uvs[ 0 ].x;
  23770. var x1 = uvs[ 1 ].x;
  23771. var x2 = uvs[ 2 ].x;
  23772. var max = Math.max( x0, x1, x2 );
  23773. var min = Math.min( x0, x1, x2 );
  23774. if ( max > 0.9 && min < 0.1 ) {
  23775. // 0.9 is somewhat arbitrary
  23776. if ( x0 < 0.2 ) uvs[ 0 ].x += 1;
  23777. if ( x1 < 0.2 ) uvs[ 1 ].x += 1;
  23778. if ( x2 < 0.2 ) uvs[ 2 ].x += 1;
  23779. }
  23780. }
  23781. // Apply radius
  23782. for ( var i = 0, l = this.vertices.length; i < l; i ++ ) {
  23783. this.vertices[ i ].multiplyScalar( radius );
  23784. }
  23785. // Merge vertices
  23786. this.mergeVertices();
  23787. this.computeFaceNormals();
  23788. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  23789. // Project vector onto sphere's surface
  23790. function prepare( vector ) {
  23791. var vertex = vector.normalize().clone();
  23792. vertex.index = that.vertices.push( vertex ) - 1;
  23793. // Texture coords are equivalent to map coords, calculate angle and convert to fraction of a circle.
  23794. var u = azimuth( vector ) / 2 / Math.PI + 0.5;
  23795. var v = inclination( vector ) / Math.PI + 0.5;
  23796. vertex.uv = new THREE.Vector2( u, 1 - v );
  23797. return vertex;
  23798. }
  23799. // Approximate a curved face with recursively sub-divided triangles.
  23800. function make( v1, v2, v3, materialIndex ) {
  23801. var face = new THREE.Face3( v1.index, v2.index, v3.index, [ v1.clone(), v2.clone(), v3.clone() ], undefined, materialIndex );
  23802. that.faces.push( face );
  23803. centroid.copy( v1 ).add( v2 ).add( v3 ).divideScalar( 3 );
  23804. var azi = azimuth( centroid );
  23805. that.faceVertexUvs[ 0 ].push( [
  23806. correctUV( v1.uv, v1, azi ),
  23807. correctUV( v2.uv, v2, azi ),
  23808. correctUV( v3.uv, v3, azi )
  23809. ] );
  23810. }
  23811. // Analytically subdivide a face to the required detail level.
  23812. function subdivide( face, detail ) {
  23813. var cols = Math.pow( 2, detail );
  23814. var a = prepare( that.vertices[ face.a ] );
  23815. var b = prepare( that.vertices[ face.b ] );
  23816. var c = prepare( that.vertices[ face.c ] );
  23817. var v = [];
  23818. var materialIndex = face.materialIndex;
  23819. // Construct all of the vertices for this subdivision.
  23820. for ( var i = 0 ; i <= cols; i ++ ) {
  23821. v[ i ] = [];
  23822. var aj = prepare( a.clone().lerp( c, i / cols ) );
  23823. var bj = prepare( b.clone().lerp( c, i / cols ) );
  23824. var rows = cols - i;
  23825. for ( var j = 0; j <= rows; j ++ ) {
  23826. if ( j === 0 && i === cols ) {
  23827. v[ i ][ j ] = aj;
  23828. } else {
  23829. v[ i ][ j ] = prepare( aj.clone().lerp( bj, j / rows ) );
  23830. }
  23831. }
  23832. }
  23833. // Construct all of the faces.
  23834. for ( var i = 0; i < cols ; i ++ ) {
  23835. for ( var j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
  23836. var k = Math.floor( j / 2 );
  23837. if ( j % 2 === 0 ) {
  23838. make(
  23839. v[ i ][ k + 1 ],
  23840. v[ i + 1 ][ k ],
  23841. v[ i ][ k ],
  23842. materialIndex
  23843. );
  23844. } else {
  23845. make(
  23846. v[ i ][ k + 1 ],
  23847. v[ i + 1 ][ k + 1 ],
  23848. v[ i + 1 ][ k ],
  23849. materialIndex
  23850. );
  23851. }
  23852. }
  23853. }
  23854. }
  23855. // Angle around the Y axis, counter-clockwise when looking from above.
  23856. function azimuth( vector ) {
  23857. return Math.atan2( vector.z, - vector.x );
  23858. }
  23859. // Angle above the XZ plane.
  23860. function inclination( vector ) {
  23861. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  23862. }
  23863. // Texture fixing helper. Spheres have some odd behaviours.
  23864. function correctUV( uv, vector, azimuth ) {
  23865. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) uv = new THREE.Vector2( uv.x - 1, uv.y );
  23866. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) uv = new THREE.Vector2( azimuth / 2 / Math.PI + 0.5, uv.y );
  23867. return uv.clone();
  23868. }
  23869. };
  23870. THREE.PolyhedronGeometry.prototype = Object.create( THREE.Geometry.prototype );
  23871. THREE.PolyhedronGeometry.prototype.constructor = THREE.PolyhedronGeometry;
  23872. // File:src/extras/geometries/DodecahedronGeometry.js
  23873. /**
  23874. * @author Abe Pazos / https://hamoid.com
  23875. */
  23876. THREE.DodecahedronGeometry = function ( radius, detail ) {
  23877. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  23878. var r = 1 / t;
  23879. var vertices = [
  23880. // (±1, ±1, ±1)
  23881. - 1, - 1, - 1, - 1, - 1, 1,
  23882. - 1, 1, - 1, - 1, 1, 1,
  23883. 1, - 1, - 1, 1, - 1, 1,
  23884. 1, 1, - 1, 1, 1, 1,
  23885. // (0, ±1/φ, ±φ)
  23886. 0, - r, - t, 0, - r, t,
  23887. 0, r, - t, 0, r, t,
  23888. // (±1/φ, ±φ, 0)
  23889. - r, - t, 0, - r, t, 0,
  23890. r, - t, 0, r, t, 0,
  23891. // (±φ, 0, ±1/φ)
  23892. - t, 0, - r, t, 0, - r,
  23893. - t, 0, r, t, 0, r
  23894. ];
  23895. var indices = [
  23896. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  23897. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  23898. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  23899. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  23900. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  23901. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  23902. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  23903. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  23904. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  23905. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  23906. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  23907. 1, 12, 14, 1, 14, 5, 1, 5, 9
  23908. ];
  23909. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  23910. this.type = 'DodecahedronGeometry';
  23911. this.parameters = {
  23912. radius: radius,
  23913. detail: detail
  23914. };
  23915. };
  23916. THREE.DodecahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  23917. THREE.DodecahedronGeometry.prototype.constructor = THREE.DodecahedronGeometry;
  23918. // File:src/extras/geometries/IcosahedronGeometry.js
  23919. /**
  23920. * @author timothypratley / https://github.com/timothypratley
  23921. */
  23922. THREE.IcosahedronGeometry = function ( radius, detail ) {
  23923. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  23924. var vertices = [
  23925. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  23926. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  23927. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  23928. ];
  23929. var indices = [
  23930. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  23931. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  23932. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  23933. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  23934. ];
  23935. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  23936. this.type = 'IcosahedronGeometry';
  23937. this.parameters = {
  23938. radius: radius,
  23939. detail: detail
  23940. };
  23941. };
  23942. THREE.IcosahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  23943. THREE.IcosahedronGeometry.prototype.constructor = THREE.IcosahedronGeometry;
  23944. // File:src/extras/geometries/OctahedronGeometry.js
  23945. /**
  23946. * @author timothypratley / https://github.com/timothypratley
  23947. */
  23948. THREE.OctahedronGeometry = function ( radius, detail ) {
  23949. var vertices = [
  23950. 1, 0, 0, - 1, 0, 0, 0, 1, 0, 0, - 1, 0, 0, 0, 1, 0, 0, - 1
  23951. ];
  23952. var indices = [
  23953. 0, 2, 4, 0, 4, 3, 0, 3, 5, 0, 5, 2, 1, 2, 5, 1, 5, 3, 1, 3, 4, 1, 4, 2
  23954. ];
  23955. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  23956. this.type = 'OctahedronGeometry';
  23957. this.parameters = {
  23958. radius: radius,
  23959. detail: detail
  23960. };
  23961. };
  23962. THREE.OctahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  23963. THREE.OctahedronGeometry.prototype.constructor = THREE.OctahedronGeometry;
  23964. // File:src/extras/geometries/TetrahedronGeometry.js
  23965. /**
  23966. * @author timothypratley / https://github.com/timothypratley
  23967. */
  23968. THREE.TetrahedronGeometry = function ( radius, detail ) {
  23969. var vertices = [
  23970. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  23971. ];
  23972. var indices = [
  23973. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  23974. ];
  23975. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  23976. this.type = 'TetrahedronGeometry';
  23977. this.parameters = {
  23978. radius: radius,
  23979. detail: detail
  23980. };
  23981. };
  23982. THREE.TetrahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  23983. THREE.TetrahedronGeometry.prototype.constructor = THREE.TetrahedronGeometry;
  23984. // File:src/extras/geometries/ParametricGeometry.js
  23985. /**
  23986. * @author zz85 / https://github.com/zz85
  23987. * Parametric Surfaces Geometry
  23988. * based on the brilliant article by @prideout http://prideout.net/blog/?p=44
  23989. *
  23990. * new THREE.ParametricGeometry( parametricFunction, uSegments, ySegements );
  23991. *
  23992. */
  23993. THREE.ParametricGeometry = function ( func, slices, stacks ) {
  23994. THREE.Geometry.call( this );
  23995. this.type = 'ParametricGeometry';
  23996. this.parameters = {
  23997. func: func,
  23998. slices: slices,
  23999. stacks: stacks
  24000. };
  24001. var verts = this.vertices;
  24002. var faces = this.faces;
  24003. var uvs = this.faceVertexUvs[ 0 ];
  24004. var i, j, p;
  24005. var u, v;
  24006. var sliceCount = slices + 1;
  24007. for ( i = 0; i <= stacks; i ++ ) {
  24008. v = i / stacks;
  24009. for ( j = 0; j <= slices; j ++ ) {
  24010. u = j / slices;
  24011. p = func( u, v );
  24012. verts.push( p );
  24013. }
  24014. }
  24015. var a, b, c, d;
  24016. var uva, uvb, uvc, uvd;
  24017. for ( i = 0; i < stacks; i ++ ) {
  24018. for ( j = 0; j < slices; j ++ ) {
  24019. a = i * sliceCount + j;
  24020. b = i * sliceCount + j + 1;
  24021. c = ( i + 1 ) * sliceCount + j + 1;
  24022. d = ( i + 1 ) * sliceCount + j;
  24023. uva = new THREE.Vector2( j / slices, i / stacks );
  24024. uvb = new THREE.Vector2( ( j + 1 ) / slices, i / stacks );
  24025. uvc = new THREE.Vector2( ( j + 1 ) / slices, ( i + 1 ) / stacks );
  24026. uvd = new THREE.Vector2( j / slices, ( i + 1 ) / stacks );
  24027. faces.push( new THREE.Face3( a, b, d ) );
  24028. uvs.push( [ uva, uvb, uvd ] );
  24029. faces.push( new THREE.Face3( b, c, d ) );
  24030. uvs.push( [ uvb.clone(), uvc, uvd.clone() ] );
  24031. }
  24032. }
  24033. // console.log(this);
  24034. // magic bullet
  24035. // var diff = this.mergeVertices();
  24036. // console.log('removed ', diff, ' vertices by merging');
  24037. this.computeFaceNormals();
  24038. this.computeVertexNormals();
  24039. };
  24040. THREE.ParametricGeometry.prototype = Object.create( THREE.Geometry.prototype );
  24041. THREE.ParametricGeometry.prototype.constructor = THREE.ParametricGeometry;
  24042. // File:src/extras/geometries/WireframeGeometry.js
  24043. /**
  24044. * @author mrdoob / http://mrdoob.com/
  24045. */
  24046. THREE.WireframeGeometry = function ( geometry ) {
  24047. THREE.BufferGeometry.call( this );
  24048. var edge = [ 0, 0 ], hash = {};
  24049. function sortFunction( a, b ) {
  24050. return a - b;
  24051. }
  24052. var keys = [ 'a', 'b', 'c' ];
  24053. if ( geometry instanceof THREE.Geometry ) {
  24054. var vertices = geometry.vertices;
  24055. var faces = geometry.faces;
  24056. var numEdges = 0;
  24057. // allocate maximal size
  24058. var edges = new Uint32Array( 6 * faces.length );
  24059. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  24060. var face = faces[ i ];
  24061. for ( var j = 0; j < 3; j ++ ) {
  24062. edge[ 0 ] = face[ keys[ j ] ];
  24063. edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
  24064. edge.sort( sortFunction );
  24065. var key = edge.toString();
  24066. if ( hash[ key ] === undefined ) {
  24067. edges[ 2 * numEdges ] = edge[ 0 ];
  24068. edges[ 2 * numEdges + 1 ] = edge[ 1 ];
  24069. hash[ key ] = true;
  24070. numEdges ++;
  24071. }
  24072. }
  24073. }
  24074. var coords = new Float32Array( numEdges * 2 * 3 );
  24075. for ( var i = 0, l = numEdges; i < l; i ++ ) {
  24076. for ( var j = 0; j < 2; j ++ ) {
  24077. var vertex = vertices[ edges [ 2 * i + j ] ];
  24078. var index = 6 * i + 3 * j;
  24079. coords[ index + 0 ] = vertex.x;
  24080. coords[ index + 1 ] = vertex.y;
  24081. coords[ index + 2 ] = vertex.z;
  24082. }
  24083. }
  24084. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  24085. } else if ( geometry instanceof THREE.BufferGeometry ) {
  24086. if ( geometry.index !== null ) {
  24087. // Indexed BufferGeometry
  24088. var indices = geometry.index.array;
  24089. var vertices = geometry.attributes.position;
  24090. var groups = geometry.groups;
  24091. var numEdges = 0;
  24092. if ( groups.length === 0 ) {
  24093. geometry.addGroup( 0, indices.length );
  24094. }
  24095. // allocate maximal size
  24096. var edges = new Uint32Array( 2 * indices.length );
  24097. for ( var o = 0, ol = groups.length; o < ol; ++ o ) {
  24098. var group = groups[ o ];
  24099. var start = group.start;
  24100. var count = group.count;
  24101. for ( var i = start, il = start + count; i < il; i += 3 ) {
  24102. for ( var j = 0; j < 3; j ++ ) {
  24103. edge[ 0 ] = indices[ i + j ];
  24104. edge[ 1 ] = indices[ i + ( j + 1 ) % 3 ];
  24105. edge.sort( sortFunction );
  24106. var key = edge.toString();
  24107. if ( hash[ key ] === undefined ) {
  24108. edges[ 2 * numEdges ] = edge[ 0 ];
  24109. edges[ 2 * numEdges + 1 ] = edge[ 1 ];
  24110. hash[ key ] = true;
  24111. numEdges ++;
  24112. }
  24113. }
  24114. }
  24115. }
  24116. var coords = new Float32Array( numEdges * 2 * 3 );
  24117. for ( var i = 0, l = numEdges; i < l; i ++ ) {
  24118. for ( var j = 0; j < 2; j ++ ) {
  24119. var index = 6 * i + 3 * j;
  24120. var index2 = edges[ 2 * i + j ];
  24121. coords[ index + 0 ] = vertices.getX( index2 );
  24122. coords[ index + 1 ] = vertices.getY( index2 );
  24123. coords[ index + 2 ] = vertices.getZ( index2 );
  24124. }
  24125. }
  24126. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  24127. } else {
  24128. // non-indexed BufferGeometry
  24129. var vertices = geometry.attributes.position.array;
  24130. var numEdges = vertices.length / 3;
  24131. var numTris = numEdges / 3;
  24132. var coords = new Float32Array( numEdges * 2 * 3 );
  24133. for ( var i = 0, l = numTris; i < l; i ++ ) {
  24134. for ( var j = 0; j < 3; j ++ ) {
  24135. var index = 18 * i + 6 * j;
  24136. var index1 = 9 * i + 3 * j;
  24137. coords[ index + 0 ] = vertices[ index1 ];
  24138. coords[ index + 1 ] = vertices[ index1 + 1 ];
  24139. coords[ index + 2 ] = vertices[ index1 + 2 ];
  24140. var index2 = 9 * i + 3 * ( ( j + 1 ) % 3 );
  24141. coords[ index + 3 ] = vertices[ index2 ];
  24142. coords[ index + 4 ] = vertices[ index2 + 1 ];
  24143. coords[ index + 5 ] = vertices[ index2 + 2 ];
  24144. }
  24145. }
  24146. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  24147. }
  24148. }
  24149. };
  24150. THREE.WireframeGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  24151. THREE.WireframeGeometry.prototype.constructor = THREE.WireframeGeometry;
  24152. // File:src/extras/helpers/AxisHelper.js
  24153. /**
  24154. * @author sroucheray / http://sroucheray.org/
  24155. * @author mrdoob / http://mrdoob.com/
  24156. */
  24157. THREE.AxisHelper = function ( size ) {
  24158. size = size || 1;
  24159. var vertices = new Float32Array( [
  24160. 0, 0, 0, size, 0, 0,
  24161. 0, 0, 0, 0, size, 0,
  24162. 0, 0, 0, 0, 0, size
  24163. ] );
  24164. var colors = new Float32Array( [
  24165. 1, 0, 0, 1, 0.6, 0,
  24166. 0, 1, 0, 0.6, 1, 0,
  24167. 0, 0, 1, 0, 0.6, 1
  24168. ] );
  24169. var geometry = new THREE.BufferGeometry();
  24170. geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  24171. geometry.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ) );
  24172. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
  24173. THREE.LineSegments.call( this, geometry, material );
  24174. };
  24175. THREE.AxisHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24176. THREE.AxisHelper.prototype.constructor = THREE.AxisHelper;
  24177. // File:src/extras/helpers/ArrowHelper.js
  24178. /**
  24179. * @author WestLangley / http://github.com/WestLangley
  24180. * @author zz85 / http://github.com/zz85
  24181. * @author bhouston / http://clara.io
  24182. *
  24183. * Creates an arrow for visualizing directions
  24184. *
  24185. * Parameters:
  24186. * dir - Vector3
  24187. * origin - Vector3
  24188. * length - Number
  24189. * color - color in hex value
  24190. * headLength - Number
  24191. * headWidth - Number
  24192. */
  24193. THREE.ArrowHelper = ( function () {
  24194. var lineGeometry = new THREE.BufferGeometry();
  24195. lineGeometry.addAttribute( 'position', new THREE.Float32Attribute( [ 0, 0, 0, 0, 1, 0 ], 3 ) );
  24196. var coneGeometry = new THREE.CylinderBufferGeometry( 0, 0.5, 1, 5, 1 );
  24197. coneGeometry.translate( 0, - 0.5, 0 );
  24198. return function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
  24199. // dir is assumed to be normalized
  24200. THREE.Object3D.call( this );
  24201. if ( color === undefined ) color = 0xffff00;
  24202. if ( length === undefined ) length = 1;
  24203. if ( headLength === undefined ) headLength = 0.2 * length;
  24204. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  24205. this.position.copy( origin );
  24206. this.line = new THREE.Line( lineGeometry, new THREE.LineBasicMaterial( { color: color } ) );
  24207. this.line.matrixAutoUpdate = false;
  24208. this.add( this.line );
  24209. this.cone = new THREE.Mesh( coneGeometry, new THREE.MeshBasicMaterial( { color: color } ) );
  24210. this.cone.matrixAutoUpdate = false;
  24211. this.add( this.cone );
  24212. this.setDirection( dir );
  24213. this.setLength( length, headLength, headWidth );
  24214. };
  24215. }() );
  24216. THREE.ArrowHelper.prototype = Object.create( THREE.Object3D.prototype );
  24217. THREE.ArrowHelper.prototype.constructor = THREE.ArrowHelper;
  24218. THREE.ArrowHelper.prototype.setDirection = ( function () {
  24219. var axis = new THREE.Vector3();
  24220. var radians;
  24221. return function setDirection( dir ) {
  24222. // dir is assumed to be normalized
  24223. if ( dir.y > 0.99999 ) {
  24224. this.quaternion.set( 0, 0, 0, 1 );
  24225. } else if ( dir.y < - 0.99999 ) {
  24226. this.quaternion.set( 1, 0, 0, 0 );
  24227. } else {
  24228. axis.set( dir.z, 0, - dir.x ).normalize();
  24229. radians = Math.acos( dir.y );
  24230. this.quaternion.setFromAxisAngle( axis, radians );
  24231. }
  24232. };
  24233. }() );
  24234. THREE.ArrowHelper.prototype.setLength = function ( length, headLength, headWidth ) {
  24235. if ( headLength === undefined ) headLength = 0.2 * length;
  24236. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  24237. this.line.scale.set( 1, Math.max( 0, length - headLength ), 1 );
  24238. this.line.updateMatrix();
  24239. this.cone.scale.set( headWidth, headLength, headWidth );
  24240. this.cone.position.y = length;
  24241. this.cone.updateMatrix();
  24242. };
  24243. THREE.ArrowHelper.prototype.setColor = function ( color ) {
  24244. this.line.material.color.copy( color );
  24245. this.cone.material.color.copy( color );
  24246. };
  24247. // File:src/extras/helpers/BoxHelper.js
  24248. /**
  24249. * @author mrdoob / http://mrdoob.com/
  24250. */
  24251. THREE.BoxHelper = function ( object ) {
  24252. 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 ] );
  24253. var positions = new Float32Array( 8 * 3 );
  24254. var geometry = new THREE.BufferGeometry();
  24255. geometry.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  24256. geometry.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
  24257. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: 0xffff00 } ) );
  24258. if ( object !== undefined ) {
  24259. this.update( object );
  24260. }
  24261. };
  24262. THREE.BoxHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24263. THREE.BoxHelper.prototype.constructor = THREE.BoxHelper;
  24264. THREE.BoxHelper.prototype.update = ( function () {
  24265. var box = new THREE.Box3();
  24266. return function ( object ) {
  24267. if ( object instanceof THREE.Box3 ) {
  24268. box.copy( object );
  24269. } else {
  24270. box.setFromObject( object );
  24271. }
  24272. if ( box.isEmpty() ) return;
  24273. var min = box.min;
  24274. var max = box.max;
  24275. /*
  24276. 5____4
  24277. 1/___0/|
  24278. | 6__|_7
  24279. 2/___3/
  24280. 0: max.x, max.y, max.z
  24281. 1: min.x, max.y, max.z
  24282. 2: min.x, min.y, max.z
  24283. 3: max.x, min.y, max.z
  24284. 4: max.x, max.y, min.z
  24285. 5: min.x, max.y, min.z
  24286. 6: min.x, min.y, min.z
  24287. 7: max.x, min.y, min.z
  24288. */
  24289. var position = this.geometry.attributes.position;
  24290. var array = position.array;
  24291. array[ 0 ] = max.x; array[ 1 ] = max.y; array[ 2 ] = max.z;
  24292. array[ 3 ] = min.x; array[ 4 ] = max.y; array[ 5 ] = max.z;
  24293. array[ 6 ] = min.x; array[ 7 ] = min.y; array[ 8 ] = max.z;
  24294. array[ 9 ] = max.x; array[ 10 ] = min.y; array[ 11 ] = max.z;
  24295. array[ 12 ] = max.x; array[ 13 ] = max.y; array[ 14 ] = min.z;
  24296. array[ 15 ] = min.x; array[ 16 ] = max.y; array[ 17 ] = min.z;
  24297. array[ 18 ] = min.x; array[ 19 ] = min.y; array[ 20 ] = min.z;
  24298. array[ 21 ] = max.x; array[ 22 ] = min.y; array[ 23 ] = min.z;
  24299. position.needsUpdate = true;
  24300. this.geometry.computeBoundingSphere();
  24301. };
  24302. } )();
  24303. // File:src/extras/helpers/BoundingBoxHelper.js
  24304. /**
  24305. * @author WestLangley / http://github.com/WestLangley
  24306. */
  24307. // a helper to show the world-axis-aligned bounding box for an object
  24308. THREE.BoundingBoxHelper = function ( object, hex ) {
  24309. var color = ( hex !== undefined ) ? hex : 0x888888;
  24310. this.object = object;
  24311. this.box = new THREE.Box3();
  24312. THREE.Mesh.call( this, new THREE.BoxGeometry( 1, 1, 1 ), new THREE.MeshBasicMaterial( { color: color, wireframe: true } ) );
  24313. };
  24314. THREE.BoundingBoxHelper.prototype = Object.create( THREE.Mesh.prototype );
  24315. THREE.BoundingBoxHelper.prototype.constructor = THREE.BoundingBoxHelper;
  24316. THREE.BoundingBoxHelper.prototype.update = function () {
  24317. this.box.setFromObject( this.object );
  24318. this.box.size( this.scale );
  24319. this.box.center( this.position );
  24320. };
  24321. // File:src/extras/helpers/CameraHelper.js
  24322. /**
  24323. * @author alteredq / http://alteredqualia.com/
  24324. *
  24325. * - shows frustum, line of sight and up of the camera
  24326. * - suitable for fast updates
  24327. * - based on frustum visualization in lightgl.js shadowmap example
  24328. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  24329. */
  24330. THREE.CameraHelper = function ( camera ) {
  24331. var geometry = new THREE.Geometry();
  24332. var material = new THREE.LineBasicMaterial( { color: 0xffffff, vertexColors: THREE.FaceColors } );
  24333. var pointMap = {};
  24334. // colors
  24335. var hexFrustum = 0xffaa00;
  24336. var hexCone = 0xff0000;
  24337. var hexUp = 0x00aaff;
  24338. var hexTarget = 0xffffff;
  24339. var hexCross = 0x333333;
  24340. // near
  24341. addLine( "n1", "n2", hexFrustum );
  24342. addLine( "n2", "n4", hexFrustum );
  24343. addLine( "n4", "n3", hexFrustum );
  24344. addLine( "n3", "n1", hexFrustum );
  24345. // far
  24346. addLine( "f1", "f2", hexFrustum );
  24347. addLine( "f2", "f4", hexFrustum );
  24348. addLine( "f4", "f3", hexFrustum );
  24349. addLine( "f3", "f1", hexFrustum );
  24350. // sides
  24351. addLine( "n1", "f1", hexFrustum );
  24352. addLine( "n2", "f2", hexFrustum );
  24353. addLine( "n3", "f3", hexFrustum );
  24354. addLine( "n4", "f4", hexFrustum );
  24355. // cone
  24356. addLine( "p", "n1", hexCone );
  24357. addLine( "p", "n2", hexCone );
  24358. addLine( "p", "n3", hexCone );
  24359. addLine( "p", "n4", hexCone );
  24360. // up
  24361. addLine( "u1", "u2", hexUp );
  24362. addLine( "u2", "u3", hexUp );
  24363. addLine( "u3", "u1", hexUp );
  24364. // target
  24365. addLine( "c", "t", hexTarget );
  24366. addLine( "p", "c", hexCross );
  24367. // cross
  24368. addLine( "cn1", "cn2", hexCross );
  24369. addLine( "cn3", "cn4", hexCross );
  24370. addLine( "cf1", "cf2", hexCross );
  24371. addLine( "cf3", "cf4", hexCross );
  24372. function addLine( a, b, hex ) {
  24373. addPoint( a, hex );
  24374. addPoint( b, hex );
  24375. }
  24376. function addPoint( id, hex ) {
  24377. geometry.vertices.push( new THREE.Vector3() );
  24378. geometry.colors.push( new THREE.Color( hex ) );
  24379. if ( pointMap[ id ] === undefined ) {
  24380. pointMap[ id ] = [];
  24381. }
  24382. pointMap[ id ].push( geometry.vertices.length - 1 );
  24383. }
  24384. THREE.LineSegments.call( this, geometry, material );
  24385. this.camera = camera;
  24386. this.camera.updateProjectionMatrix();
  24387. this.matrix = camera.matrixWorld;
  24388. this.matrixAutoUpdate = false;
  24389. this.pointMap = pointMap;
  24390. this.update();
  24391. };
  24392. THREE.CameraHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24393. THREE.CameraHelper.prototype.constructor = THREE.CameraHelper;
  24394. THREE.CameraHelper.prototype.update = function () {
  24395. var geometry, pointMap;
  24396. var vector = new THREE.Vector3();
  24397. var camera = new THREE.Camera();
  24398. function setPoint( point, x, y, z ) {
  24399. vector.set( x, y, z ).unproject( camera );
  24400. var points = pointMap[ point ];
  24401. if ( points !== undefined ) {
  24402. for ( var i = 0, il = points.length; i < il; i ++ ) {
  24403. geometry.vertices[ points[ i ] ].copy( vector );
  24404. }
  24405. }
  24406. }
  24407. return function () {
  24408. geometry = this.geometry;
  24409. pointMap = this.pointMap;
  24410. var w = 1, h = 1;
  24411. // we need just camera projection matrix
  24412. // world matrix must be identity
  24413. camera.projectionMatrix.copy( this.camera.projectionMatrix );
  24414. // center / target
  24415. setPoint( "c", 0, 0, - 1 );
  24416. setPoint( "t", 0, 0, 1 );
  24417. // near
  24418. setPoint( "n1", - w, - h, - 1 );
  24419. setPoint( "n2", w, - h, - 1 );
  24420. setPoint( "n3", - w, h, - 1 );
  24421. setPoint( "n4", w, h, - 1 );
  24422. // far
  24423. setPoint( "f1", - w, - h, 1 );
  24424. setPoint( "f2", w, - h, 1 );
  24425. setPoint( "f3", - w, h, 1 );
  24426. setPoint( "f4", w, h, 1 );
  24427. // up
  24428. setPoint( "u1", w * 0.7, h * 1.1, - 1 );
  24429. setPoint( "u2", - w * 0.7, h * 1.1, - 1 );
  24430. setPoint( "u3", 0, h * 2, - 1 );
  24431. // cross
  24432. setPoint( "cf1", - w, 0, 1 );
  24433. setPoint( "cf2", w, 0, 1 );
  24434. setPoint( "cf3", 0, - h, 1 );
  24435. setPoint( "cf4", 0, h, 1 );
  24436. setPoint( "cn1", - w, 0, - 1 );
  24437. setPoint( "cn2", w, 0, - 1 );
  24438. setPoint( "cn3", 0, - h, - 1 );
  24439. setPoint( "cn4", 0, h, - 1 );
  24440. geometry.verticesNeedUpdate = true;
  24441. };
  24442. }();
  24443. // File:src/extras/helpers/DirectionalLightHelper.js
  24444. /**
  24445. * @author alteredq / http://alteredqualia.com/
  24446. * @author mrdoob / http://mrdoob.com/
  24447. * @author WestLangley / http://github.com/WestLangley
  24448. */
  24449. THREE.DirectionalLightHelper = function ( light, size ) {
  24450. THREE.Object3D.call( this );
  24451. this.light = light;
  24452. this.light.updateMatrixWorld();
  24453. this.matrix = light.matrixWorld;
  24454. this.matrixAutoUpdate = false;
  24455. if ( size === undefined ) size = 1;
  24456. var geometry = new THREE.BufferGeometry();
  24457. geometry.addAttribute( 'position', new THREE.Float32Attribute( [
  24458. - size, size, 0,
  24459. size, size, 0,
  24460. size, - size, 0,
  24461. - size, - size, 0,
  24462. - size, size, 0
  24463. ], 3 ) );
  24464. var material = new THREE.LineBasicMaterial( { fog: false } );
  24465. this.add( new THREE.Line( geometry, material ) );
  24466. geometry = new THREE.BufferGeometry();
  24467. geometry.addAttribute( 'position', new THREE.Float32Attribute( [ 0, 0, 0, 0, 0, 1 ], 3 ) );
  24468. this.add( new THREE.Line( geometry, material ));
  24469. this.update();
  24470. };
  24471. THREE.DirectionalLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  24472. THREE.DirectionalLightHelper.prototype.constructor = THREE.DirectionalLightHelper;
  24473. THREE.DirectionalLightHelper.prototype.dispose = function () {
  24474. var lightPlane = this.children[ 0 ];
  24475. var targetLine = this.children[ 1 ];
  24476. lightPlane.geometry.dispose();
  24477. lightPlane.material.dispose();
  24478. targetLine.geometry.dispose();
  24479. targetLine.material.dispose();
  24480. };
  24481. THREE.DirectionalLightHelper.prototype.update = function () {
  24482. var v1 = new THREE.Vector3();
  24483. var v2 = new THREE.Vector3();
  24484. var v3 = new THREE.Vector3();
  24485. return function () {
  24486. v1.setFromMatrixPosition( this.light.matrixWorld );
  24487. v2.setFromMatrixPosition( this.light.target.matrixWorld );
  24488. v3.subVectors( v2, v1 );
  24489. var lightPlane = this.children[ 0 ];
  24490. var targetLine = this.children[ 1 ];
  24491. lightPlane.lookAt( v3 );
  24492. lightPlane.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  24493. targetLine.lookAt( v3 );
  24494. targetLine.scale.z = v3.length();
  24495. };
  24496. }();
  24497. // File:src/extras/helpers/EdgesHelper.js
  24498. /**
  24499. * @author WestLangley / http://github.com/WestLangley
  24500. * @param object THREE.Mesh whose geometry will be used
  24501. * @param hex line color
  24502. * @param thresholdAngle the minimum angle (in degrees),
  24503. * between the face normals of adjacent faces,
  24504. * that is required to render an edge. A value of 10 means
  24505. * an edge is only rendered if the angle is at least 10 degrees.
  24506. */
  24507. THREE.EdgesHelper = function ( object, hex, thresholdAngle ) {
  24508. var color = ( hex !== undefined ) ? hex : 0xffffff;
  24509. THREE.LineSegments.call( this, new THREE.EdgesGeometry( object.geometry, thresholdAngle ), new THREE.LineBasicMaterial( { color: color } ) );
  24510. this.matrix = object.matrixWorld;
  24511. this.matrixAutoUpdate = false;
  24512. };
  24513. THREE.EdgesHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24514. THREE.EdgesHelper.prototype.constructor = THREE.EdgesHelper;
  24515. // File:src/extras/helpers/FaceNormalsHelper.js
  24516. /**
  24517. * @author mrdoob / http://mrdoob.com/
  24518. * @author WestLangley / http://github.com/WestLangley
  24519. */
  24520. THREE.FaceNormalsHelper = function ( object, size, hex, linewidth ) {
  24521. // FaceNormalsHelper only supports THREE.Geometry
  24522. this.object = object;
  24523. this.size = ( size !== undefined ) ? size : 1;
  24524. var color = ( hex !== undefined ) ? hex : 0xffff00;
  24525. var width = ( linewidth !== undefined ) ? linewidth : 1;
  24526. //
  24527. var nNormals = 0;
  24528. var objGeometry = this.object.geometry;
  24529. if ( objGeometry instanceof THREE.Geometry ) {
  24530. nNormals = objGeometry.faces.length;
  24531. } else {
  24532. console.warn( 'THREE.FaceNormalsHelper: only THREE.Geometry is supported. Use THREE.VertexNormalsHelper, instead.' );
  24533. }
  24534. //
  24535. var geometry = new THREE.BufferGeometry();
  24536. var positions = new THREE.Float32Attribute( nNormals * 2 * 3, 3 );
  24537. geometry.addAttribute( 'position', positions );
  24538. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  24539. //
  24540. this.matrixAutoUpdate = false;
  24541. this.update();
  24542. };
  24543. THREE.FaceNormalsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24544. THREE.FaceNormalsHelper.prototype.constructor = THREE.FaceNormalsHelper;
  24545. THREE.FaceNormalsHelper.prototype.update = ( function () {
  24546. var v1 = new THREE.Vector3();
  24547. var v2 = new THREE.Vector3();
  24548. var normalMatrix = new THREE.Matrix3();
  24549. return function update() {
  24550. this.object.updateMatrixWorld( true );
  24551. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  24552. var matrixWorld = this.object.matrixWorld;
  24553. var position = this.geometry.attributes.position;
  24554. //
  24555. var objGeometry = this.object.geometry;
  24556. var vertices = objGeometry.vertices;
  24557. var faces = objGeometry.faces;
  24558. var idx = 0;
  24559. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  24560. var face = faces[ i ];
  24561. var normal = face.normal;
  24562. v1.copy( vertices[ face.a ] )
  24563. .add( vertices[ face.b ] )
  24564. .add( vertices[ face.c ] )
  24565. .divideScalar( 3 )
  24566. .applyMatrix4( matrixWorld );
  24567. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  24568. position.setXYZ( idx, v1.x, v1.y, v1.z );
  24569. idx = idx + 1;
  24570. position.setXYZ( idx, v2.x, v2.y, v2.z );
  24571. idx = idx + 1;
  24572. }
  24573. position.needsUpdate = true;
  24574. return this;
  24575. };
  24576. }() );
  24577. // File:src/extras/helpers/GridHelper.js
  24578. /**
  24579. * @author mrdoob / http://mrdoob.com/
  24580. */
  24581. THREE.GridHelper = function ( size, step, color1, color2 ) {
  24582. color1 = new THREE.Color( color1 !== undefined ? color1 : 0x444444 );
  24583. color2 = new THREE.Color( color2 !== undefined ? color2 : 0x888888 );
  24584. var vertices = [];
  24585. var colors = [];
  24586. for ( var i = - size, j = 0; i <= size; i += step ) {
  24587. vertices.push( - size, 0, i, size, 0, i );
  24588. vertices.push( i, 0, - size, i, 0, size );
  24589. var color = i === 0 ? color1 : color2;
  24590. color.toArray( colors, j ); j += 3;
  24591. color.toArray( colors, j ); j += 3;
  24592. color.toArray( colors, j ); j += 3;
  24593. color.toArray( colors, j ); j += 3;
  24594. }
  24595. var geometry = new THREE.BufferGeometry();
  24596. geometry.addAttribute( 'position', new THREE.Float32Attribute( vertices, 3 ) );
  24597. geometry.addAttribute( 'color', new THREE.Float32Attribute( colors, 3 ) );
  24598. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
  24599. THREE.LineSegments.call( this, geometry, material );
  24600. };
  24601. THREE.GridHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24602. THREE.GridHelper.prototype.constructor = THREE.GridHelper;
  24603. THREE.GridHelper.prototype.setColors = function () {
  24604. console.error( 'THREE.GridHelper: setColors() has been deprecated, pass them in the constructor instead.' );
  24605. };
  24606. // File:src/extras/helpers/HemisphereLightHelper.js
  24607. /**
  24608. * @author alteredq / http://alteredqualia.com/
  24609. * @author mrdoob / http://mrdoob.com/
  24610. */
  24611. THREE.HemisphereLightHelper = function ( light, sphereSize ) {
  24612. THREE.Object3D.call( this );
  24613. this.light = light;
  24614. this.light.updateMatrixWorld();
  24615. this.matrix = light.matrixWorld;
  24616. this.matrixAutoUpdate = false;
  24617. this.colors = [ new THREE.Color(), new THREE.Color() ];
  24618. var geometry = new THREE.SphereGeometry( sphereSize, 4, 2 );
  24619. geometry.rotateX( - Math.PI / 2 );
  24620. for ( var i = 0, il = 8; i < il; i ++ ) {
  24621. geometry.faces[ i ].color = this.colors[ i < 4 ? 0 : 1 ];
  24622. }
  24623. var material = new THREE.MeshBasicMaterial( { vertexColors: THREE.FaceColors, wireframe: true } );
  24624. this.lightSphere = new THREE.Mesh( geometry, material );
  24625. this.add( this.lightSphere );
  24626. this.update();
  24627. };
  24628. THREE.HemisphereLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  24629. THREE.HemisphereLightHelper.prototype.constructor = THREE.HemisphereLightHelper;
  24630. THREE.HemisphereLightHelper.prototype.dispose = function () {
  24631. this.lightSphere.geometry.dispose();
  24632. this.lightSphere.material.dispose();
  24633. };
  24634. THREE.HemisphereLightHelper.prototype.update = function () {
  24635. var vector = new THREE.Vector3();
  24636. return function () {
  24637. this.colors[ 0 ].copy( this.light.color ).multiplyScalar( this.light.intensity );
  24638. this.colors[ 1 ].copy( this.light.groundColor ).multiplyScalar( this.light.intensity );
  24639. this.lightSphere.lookAt( vector.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  24640. this.lightSphere.geometry.colorsNeedUpdate = true;
  24641. };
  24642. }();
  24643. // File:src/extras/helpers/PointLightHelper.js
  24644. /**
  24645. * @author alteredq / http://alteredqualia.com/
  24646. * @author mrdoob / http://mrdoob.com/
  24647. */
  24648. THREE.PointLightHelper = function ( light, sphereSize ) {
  24649. this.light = light;
  24650. this.light.updateMatrixWorld();
  24651. var geometry = new THREE.SphereBufferGeometry( sphereSize, 4, 2 );
  24652. var material = new THREE.MeshBasicMaterial( { wireframe: true, fog: false } );
  24653. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  24654. THREE.Mesh.call( this, geometry, material );
  24655. this.matrix = this.light.matrixWorld;
  24656. this.matrixAutoUpdate = false;
  24657. /*
  24658. var distanceGeometry = new THREE.IcosahedronGeometry( 1, 2 );
  24659. var distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  24660. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  24661. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  24662. var d = light.distance;
  24663. if ( d === 0.0 ) {
  24664. this.lightDistance.visible = false;
  24665. } else {
  24666. this.lightDistance.scale.set( d, d, d );
  24667. }
  24668. this.add( this.lightDistance );
  24669. */
  24670. };
  24671. THREE.PointLightHelper.prototype = Object.create( THREE.Mesh.prototype );
  24672. THREE.PointLightHelper.prototype.constructor = THREE.PointLightHelper;
  24673. THREE.PointLightHelper.prototype.dispose = function () {
  24674. this.geometry.dispose();
  24675. this.material.dispose();
  24676. };
  24677. THREE.PointLightHelper.prototype.update = function () {
  24678. this.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  24679. /*
  24680. var d = this.light.distance;
  24681. if ( d === 0.0 ) {
  24682. this.lightDistance.visible = false;
  24683. } else {
  24684. this.lightDistance.visible = true;
  24685. this.lightDistance.scale.set( d, d, d );
  24686. }
  24687. */
  24688. };
  24689. // File:src/extras/helpers/SkeletonHelper.js
  24690. /**
  24691. * @author Sean Griffin / http://twitter.com/sgrif
  24692. * @author Michael Guerrero / http://realitymeltdown.com
  24693. * @author mrdoob / http://mrdoob.com/
  24694. * @author ikerr / http://verold.com
  24695. */
  24696. THREE.SkeletonHelper = function ( object ) {
  24697. this.bones = this.getBoneList( object );
  24698. var geometry = new THREE.Geometry();
  24699. for ( var i = 0; i < this.bones.length; i ++ ) {
  24700. var bone = this.bones[ i ];
  24701. if ( bone.parent instanceof THREE.Bone ) {
  24702. geometry.vertices.push( new THREE.Vector3() );
  24703. geometry.vertices.push( new THREE.Vector3() );
  24704. geometry.colors.push( new THREE.Color( 0, 0, 1 ) );
  24705. geometry.colors.push( new THREE.Color( 0, 1, 0 ) );
  24706. }
  24707. }
  24708. geometry.dynamic = true;
  24709. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors, depthTest: false, depthWrite: false, transparent: true } );
  24710. THREE.LineSegments.call( this, geometry, material );
  24711. this.root = object;
  24712. this.matrix = object.matrixWorld;
  24713. this.matrixAutoUpdate = false;
  24714. this.update();
  24715. };
  24716. THREE.SkeletonHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24717. THREE.SkeletonHelper.prototype.constructor = THREE.SkeletonHelper;
  24718. THREE.SkeletonHelper.prototype.getBoneList = function( object ) {
  24719. var boneList = [];
  24720. if ( object instanceof THREE.Bone ) {
  24721. boneList.push( object );
  24722. }
  24723. for ( var i = 0; i < object.children.length; i ++ ) {
  24724. boneList.push.apply( boneList, this.getBoneList( object.children[ i ] ) );
  24725. }
  24726. return boneList;
  24727. };
  24728. THREE.SkeletonHelper.prototype.update = function () {
  24729. var geometry = this.geometry;
  24730. var matrixWorldInv = new THREE.Matrix4().getInverse( this.root.matrixWorld );
  24731. var boneMatrix = new THREE.Matrix4();
  24732. var j = 0;
  24733. for ( var i = 0; i < this.bones.length; i ++ ) {
  24734. var bone = this.bones[ i ];
  24735. if ( bone.parent instanceof THREE.Bone ) {
  24736. boneMatrix.multiplyMatrices( matrixWorldInv, bone.matrixWorld );
  24737. geometry.vertices[ j ].setFromMatrixPosition( boneMatrix );
  24738. boneMatrix.multiplyMatrices( matrixWorldInv, bone.parent.matrixWorld );
  24739. geometry.vertices[ j + 1 ].setFromMatrixPosition( boneMatrix );
  24740. j += 2;
  24741. }
  24742. }
  24743. geometry.verticesNeedUpdate = true;
  24744. geometry.computeBoundingSphere();
  24745. };
  24746. // File:src/extras/helpers/SpotLightHelper.js
  24747. /**
  24748. * @author alteredq / http://alteredqualia.com/
  24749. * @author mrdoob / http://mrdoob.com/
  24750. * @author WestLangley / http://github.com/WestLangley
  24751. */
  24752. THREE.SpotLightHelper = function ( light ) {
  24753. THREE.Object3D.call( this );
  24754. this.light = light;
  24755. this.light.updateMatrixWorld();
  24756. this.matrix = light.matrixWorld;
  24757. this.matrixAutoUpdate = false;
  24758. var geometry = new THREE.BufferGeometry();
  24759. var positions = [
  24760. 0, 0, 0, 0, 0, 1,
  24761. 0, 0, 0, 1, 0, 1,
  24762. 0, 0, 0, - 1, 0, 1,
  24763. 0, 0, 0, 0, 1, 1,
  24764. 0, 0, 0, 0, - 1, 1
  24765. ];
  24766. for ( var i = 0, j = 1, l = 32; i < l; i ++, j ++ ) {
  24767. var p1 = ( i / l ) * Math.PI * 2;
  24768. var p2 = ( j / l ) * Math.PI * 2;
  24769. positions.push(
  24770. Math.cos( p1 ), Math.sin( p1 ), 1,
  24771. Math.cos( p2 ), Math.sin( p2 ), 1
  24772. );
  24773. }
  24774. geometry.addAttribute( 'position', new THREE.Float32Attribute( positions, 3 ) );
  24775. var material = new THREE.LineBasicMaterial( { fog: false } );
  24776. this.cone = new THREE.LineSegments( geometry, material );
  24777. this.add( this.cone );
  24778. this.update();
  24779. };
  24780. THREE.SpotLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  24781. THREE.SpotLightHelper.prototype.constructor = THREE.SpotLightHelper;
  24782. THREE.SpotLightHelper.prototype.dispose = function () {
  24783. this.cone.geometry.dispose();
  24784. this.cone.material.dispose();
  24785. };
  24786. THREE.SpotLightHelper.prototype.update = function () {
  24787. var vector = new THREE.Vector3();
  24788. var vector2 = new THREE.Vector3();
  24789. return function () {
  24790. var coneLength = this.light.distance ? this.light.distance : 1000;
  24791. var coneWidth = coneLength * Math.tan( this.light.angle );
  24792. this.cone.scale.set( coneWidth, coneWidth, coneLength );
  24793. vector.setFromMatrixPosition( this.light.matrixWorld );
  24794. vector2.setFromMatrixPosition( this.light.target.matrixWorld );
  24795. this.cone.lookAt( vector2.sub( vector ) );
  24796. this.cone.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  24797. };
  24798. }();
  24799. // File:src/extras/helpers/VertexNormalsHelper.js
  24800. /**
  24801. * @author mrdoob / http://mrdoob.com/
  24802. * @author WestLangley / http://github.com/WestLangley
  24803. */
  24804. THREE.VertexNormalsHelper = function ( object, size, hex, linewidth ) {
  24805. this.object = object;
  24806. this.size = ( size !== undefined ) ? size : 1;
  24807. var color = ( hex !== undefined ) ? hex : 0xff0000;
  24808. var width = ( linewidth !== undefined ) ? linewidth : 1;
  24809. //
  24810. var nNormals = 0;
  24811. var objGeometry = this.object.geometry;
  24812. if ( objGeometry instanceof THREE.Geometry ) {
  24813. nNormals = objGeometry.faces.length * 3;
  24814. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  24815. nNormals = objGeometry.attributes.normal.count;
  24816. }
  24817. //
  24818. var geometry = new THREE.BufferGeometry();
  24819. var positions = new THREE.Float32Attribute( nNormals * 2 * 3, 3 );
  24820. geometry.addAttribute( 'position', positions );
  24821. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  24822. //
  24823. this.matrixAutoUpdate = false;
  24824. this.update();
  24825. };
  24826. THREE.VertexNormalsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24827. THREE.VertexNormalsHelper.prototype.constructor = THREE.VertexNormalsHelper;
  24828. THREE.VertexNormalsHelper.prototype.update = ( function () {
  24829. var v1 = new THREE.Vector3();
  24830. var v2 = new THREE.Vector3();
  24831. var normalMatrix = new THREE.Matrix3();
  24832. return function update() {
  24833. var keys = [ 'a', 'b', 'c' ];
  24834. this.object.updateMatrixWorld( true );
  24835. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  24836. var matrixWorld = this.object.matrixWorld;
  24837. var position = this.geometry.attributes.position;
  24838. //
  24839. var objGeometry = this.object.geometry;
  24840. if ( objGeometry instanceof THREE.Geometry ) {
  24841. var vertices = objGeometry.vertices;
  24842. var faces = objGeometry.faces;
  24843. var idx = 0;
  24844. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  24845. var face = faces[ i ];
  24846. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  24847. var vertex = vertices[ face[ keys[ j ] ] ];
  24848. var normal = face.vertexNormals[ j ];
  24849. v1.copy( vertex ).applyMatrix4( matrixWorld );
  24850. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  24851. position.setXYZ( idx, v1.x, v1.y, v1.z );
  24852. idx = idx + 1;
  24853. position.setXYZ( idx, v2.x, v2.y, v2.z );
  24854. idx = idx + 1;
  24855. }
  24856. }
  24857. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  24858. var objPos = objGeometry.attributes.position;
  24859. var objNorm = objGeometry.attributes.normal;
  24860. var idx = 0;
  24861. // for simplicity, ignore index and drawcalls, and render every normal
  24862. for ( var j = 0, jl = objPos.count; j < jl; j ++ ) {
  24863. v1.set( objPos.getX( j ), objPos.getY( j ), objPos.getZ( j ) ).applyMatrix4( matrixWorld );
  24864. v2.set( objNorm.getX( j ), objNorm.getY( j ), objNorm.getZ( j ) );
  24865. v2.applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  24866. position.setXYZ( idx, v1.x, v1.y, v1.z );
  24867. idx = idx + 1;
  24868. position.setXYZ( idx, v2.x, v2.y, v2.z );
  24869. idx = idx + 1;
  24870. }
  24871. }
  24872. position.needsUpdate = true;
  24873. return this;
  24874. };
  24875. }() );
  24876. // File:src/extras/helpers/WireframeHelper.js
  24877. /**
  24878. * @author mrdoob / http://mrdoob.com/
  24879. */
  24880. THREE.WireframeHelper = function ( object, hex ) {
  24881. var color = ( hex !== undefined ) ? hex : 0xffffff;
  24882. THREE.LineSegments.call( this, new THREE.WireframeGeometry( object.geometry ), new THREE.LineBasicMaterial( { color: color } ) );
  24883. this.matrix = object.matrixWorld;
  24884. this.matrixAutoUpdate = false;
  24885. };
  24886. THREE.WireframeHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24887. THREE.WireframeHelper.prototype.constructor = THREE.WireframeHelper;
  24888. // File:src/extras/objects/ImmediateRenderObject.js
  24889. /**
  24890. * @author alteredq / http://alteredqualia.com/
  24891. */
  24892. THREE.ImmediateRenderObject = function ( material ) {
  24893. THREE.Object3D.call( this );
  24894. this.material = material;
  24895. this.render = function ( renderCallback ) {};
  24896. };
  24897. THREE.ImmediateRenderObject.prototype = Object.create( THREE.Object3D.prototype );
  24898. THREE.ImmediateRenderObject.prototype.constructor = THREE.ImmediateRenderObject;
  24899. // File:src/extras/objects/MorphBlendMesh.js
  24900. /**
  24901. * @author alteredq / http://alteredqualia.com/
  24902. */
  24903. THREE.MorphBlendMesh = function( geometry, material ) {
  24904. THREE.Mesh.call( this, geometry, material );
  24905. this.animationsMap = {};
  24906. this.animationsList = [];
  24907. // prepare default animation
  24908. // (all frames played together in 1 second)
  24909. var numFrames = this.geometry.morphTargets.length;
  24910. var name = "__default";
  24911. var startFrame = 0;
  24912. var endFrame = numFrames - 1;
  24913. var fps = numFrames / 1;
  24914. this.createAnimation( name, startFrame, endFrame, fps );
  24915. this.setAnimationWeight( name, 1 );
  24916. };
  24917. THREE.MorphBlendMesh.prototype = Object.create( THREE.Mesh.prototype );
  24918. THREE.MorphBlendMesh.prototype.constructor = THREE.MorphBlendMesh;
  24919. THREE.MorphBlendMesh.prototype.createAnimation = function ( name, start, end, fps ) {
  24920. var animation = {
  24921. start: start,
  24922. end: end,
  24923. length: end - start + 1,
  24924. fps: fps,
  24925. duration: ( end - start ) / fps,
  24926. lastFrame: 0,
  24927. currentFrame: 0,
  24928. active: false,
  24929. time: 0,
  24930. direction: 1,
  24931. weight: 1,
  24932. directionBackwards: false,
  24933. mirroredLoop: false
  24934. };
  24935. this.animationsMap[ name ] = animation;
  24936. this.animationsList.push( animation );
  24937. };
  24938. THREE.MorphBlendMesh.prototype.autoCreateAnimations = function ( fps ) {
  24939. var pattern = /([a-z]+)_?(\d+)/i;
  24940. var firstAnimation, frameRanges = {};
  24941. var geometry = this.geometry;
  24942. for ( var i = 0, il = geometry.morphTargets.length; i < il; i ++ ) {
  24943. var morph = geometry.morphTargets[ i ];
  24944. var chunks = morph.name.match( pattern );
  24945. if ( chunks && chunks.length > 1 ) {
  24946. var name = chunks[ 1 ];
  24947. if ( ! frameRanges[ name ] ) frameRanges[ name ] = { start: Infinity, end: - Infinity };
  24948. var range = frameRanges[ name ];
  24949. if ( i < range.start ) range.start = i;
  24950. if ( i > range.end ) range.end = i;
  24951. if ( ! firstAnimation ) firstAnimation = name;
  24952. }
  24953. }
  24954. for ( var name in frameRanges ) {
  24955. var range = frameRanges[ name ];
  24956. this.createAnimation( name, range.start, range.end, fps );
  24957. }
  24958. this.firstAnimation = firstAnimation;
  24959. };
  24960. THREE.MorphBlendMesh.prototype.setAnimationDirectionForward = function ( name ) {
  24961. var animation = this.animationsMap[ name ];
  24962. if ( animation ) {
  24963. animation.direction = 1;
  24964. animation.directionBackwards = false;
  24965. }
  24966. };
  24967. THREE.MorphBlendMesh.prototype.setAnimationDirectionBackward = function ( name ) {
  24968. var animation = this.animationsMap[ name ];
  24969. if ( animation ) {
  24970. animation.direction = - 1;
  24971. animation.directionBackwards = true;
  24972. }
  24973. };
  24974. THREE.MorphBlendMesh.prototype.setAnimationFPS = function ( name, fps ) {
  24975. var animation = this.animationsMap[ name ];
  24976. if ( animation ) {
  24977. animation.fps = fps;
  24978. animation.duration = ( animation.end - animation.start ) / animation.fps;
  24979. }
  24980. };
  24981. THREE.MorphBlendMesh.prototype.setAnimationDuration = function ( name, duration ) {
  24982. var animation = this.animationsMap[ name ];
  24983. if ( animation ) {
  24984. animation.duration = duration;
  24985. animation.fps = ( animation.end - animation.start ) / animation.duration;
  24986. }
  24987. };
  24988. THREE.MorphBlendMesh.prototype.setAnimationWeight = function ( name, weight ) {
  24989. var animation = this.animationsMap[ name ];
  24990. if ( animation ) {
  24991. animation.weight = weight;
  24992. }
  24993. };
  24994. THREE.MorphBlendMesh.prototype.setAnimationTime = function ( name, time ) {
  24995. var animation = this.animationsMap[ name ];
  24996. if ( animation ) {
  24997. animation.time = time;
  24998. }
  24999. };
  25000. THREE.MorphBlendMesh.prototype.getAnimationTime = function ( name ) {
  25001. var time = 0;
  25002. var animation = this.animationsMap[ name ];
  25003. if ( animation ) {
  25004. time = animation.time;
  25005. }
  25006. return time;
  25007. };
  25008. THREE.MorphBlendMesh.prototype.getAnimationDuration = function ( name ) {
  25009. var duration = - 1;
  25010. var animation = this.animationsMap[ name ];
  25011. if ( animation ) {
  25012. duration = animation.duration;
  25013. }
  25014. return duration;
  25015. };
  25016. THREE.MorphBlendMesh.prototype.playAnimation = function ( name ) {
  25017. var animation = this.animationsMap[ name ];
  25018. if ( animation ) {
  25019. animation.time = 0;
  25020. animation.active = true;
  25021. } else {
  25022. console.warn( "THREE.MorphBlendMesh: animation[" + name + "] undefined in .playAnimation()" );
  25023. }
  25024. };
  25025. THREE.MorphBlendMesh.prototype.stopAnimation = function ( name ) {
  25026. var animation = this.animationsMap[ name ];
  25027. if ( animation ) {
  25028. animation.active = false;
  25029. }
  25030. };
  25031. THREE.MorphBlendMesh.prototype.update = function ( delta ) {
  25032. for ( var i = 0, il = this.animationsList.length; i < il; i ++ ) {
  25033. var animation = this.animationsList[ i ];
  25034. if ( ! animation.active ) continue;
  25035. var frameTime = animation.duration / animation.length;
  25036. animation.time += animation.direction * delta;
  25037. if ( animation.mirroredLoop ) {
  25038. if ( animation.time > animation.duration || animation.time < 0 ) {
  25039. animation.direction *= - 1;
  25040. if ( animation.time > animation.duration ) {
  25041. animation.time = animation.duration;
  25042. animation.directionBackwards = true;
  25043. }
  25044. if ( animation.time < 0 ) {
  25045. animation.time = 0;
  25046. animation.directionBackwards = false;
  25047. }
  25048. }
  25049. } else {
  25050. animation.time = animation.time % animation.duration;
  25051. if ( animation.time < 0 ) animation.time += animation.duration;
  25052. }
  25053. var keyframe = animation.start + THREE.Math.clamp( Math.floor( animation.time / frameTime ), 0, animation.length - 1 );
  25054. var weight = animation.weight;
  25055. if ( keyframe !== animation.currentFrame ) {
  25056. this.morphTargetInfluences[ animation.lastFrame ] = 0;
  25057. this.morphTargetInfluences[ animation.currentFrame ] = 1 * weight;
  25058. this.morphTargetInfluences[ keyframe ] = 0;
  25059. animation.lastFrame = animation.currentFrame;
  25060. animation.currentFrame = keyframe;
  25061. }
  25062. var mix = ( animation.time % frameTime ) / frameTime;
  25063. if ( animation.directionBackwards ) mix = 1 - mix;
  25064. if ( animation.currentFrame !== animation.lastFrame ) {
  25065. this.morphTargetInfluences[ animation.currentFrame ] = mix * weight;
  25066. this.morphTargetInfluences[ animation.lastFrame ] = ( 1 - mix ) * weight;
  25067. } else {
  25068. this.morphTargetInfluences[ animation.currentFrame ] = weight;
  25069. }
  25070. }
  25071. };
粤ICP备19079148号