three.js 918 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685
  1. // File:src/Three.js
  2. /**
  3. * @author mrdoob / http://mrdoob.com/
  4. */
  5. var THREE = { REVISION: '76dev' };
  6. //
  7. if ( typeof define === 'function' && define.amd ) {
  8. define( 'three', THREE );
  9. } else if ( 'undefined' !== typeof exports && 'undefined' !== typeof module ) {
  10. module.exports = THREE;
  11. }
  12. //
  13. if ( Number.EPSILON === undefined ) {
  14. Number.EPSILON = Math.pow( 2, - 52 );
  15. }
  16. //
  17. if ( Math.sign === undefined ) {
  18. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
  19. Math.sign = function ( x ) {
  20. return ( x < 0 ) ? - 1 : ( x > 0 ) ? 1 : + x;
  21. };
  22. }
  23. if ( Function.prototype.name === undefined && Object.defineProperty !== undefined ) {
  24. // Missing in IE9-11.
  25. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
  26. Object.defineProperty( Function.prototype, 'name', {
  27. get: function () {
  28. return this.toString().match( /^\s*function\s*(\S*)\s*\(/ )[ 1 ];
  29. }
  30. } );
  31. }
  32. if ( Object.assign === undefined ) {
  33. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
  34. Object.defineProperty( Object, 'assign', {
  35. writable: true,
  36. configurable: true,
  37. value: function ( target ) {
  38. 'use strict';
  39. if ( target === undefined || target === null ) {
  40. throw new TypeError( "Cannot convert first argument to object" );
  41. }
  42. var to = Object( target );
  43. for ( var i = 1, n = arguments.length; i !== n; ++ i ) {
  44. var nextSource = arguments[ i ];
  45. if ( nextSource === undefined || nextSource === null ) continue;
  46. nextSource = Object( nextSource );
  47. var keysArray = Object.keys( nextSource );
  48. for ( var nextIndex = 0, len = keysArray.length; nextIndex !== len; ++ nextIndex ) {
  49. var nextKey = keysArray[ nextIndex ];
  50. var desc = Object.getOwnPropertyDescriptor( nextSource, nextKey );
  51. if ( desc !== undefined && desc.enumerable ) {
  52. to[ nextKey ] = nextSource[ nextKey ];
  53. }
  54. }
  55. }
  56. return to;
  57. }
  58. } );
  59. }
  60. // https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent.button
  61. THREE.MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2 };
  62. // GL STATE CONSTANTS
  63. THREE.CullFaceNone = 0;
  64. THREE.CullFaceBack = 1;
  65. THREE.CullFaceFront = 2;
  66. THREE.CullFaceFrontBack = 3;
  67. THREE.FrontFaceDirectionCW = 0;
  68. THREE.FrontFaceDirectionCCW = 1;
  69. // SHADOWING TYPES
  70. THREE.BasicShadowMap = 0;
  71. THREE.PCFShadowMap = 1;
  72. THREE.PCFSoftShadowMap = 2;
  73. // MATERIAL CONSTANTS
  74. // side
  75. THREE.FrontSide = 0;
  76. THREE.BackSide = 1;
  77. THREE.DoubleSide = 2;
  78. // shading
  79. THREE.FlatShading = 1;
  80. THREE.SmoothShading = 2;
  81. // colors
  82. THREE.NoColors = 0;
  83. THREE.FaceColors = 1;
  84. THREE.VertexColors = 2;
  85. // blending modes
  86. THREE.NoBlending = 0;
  87. THREE.NormalBlending = 1;
  88. THREE.AdditiveBlending = 2;
  89. THREE.SubtractiveBlending = 3;
  90. THREE.MultiplyBlending = 4;
  91. THREE.CustomBlending = 5;
  92. // custom blending equations
  93. // (numbers start from 100 not to clash with other
  94. // mappings to OpenGL constants defined in Texture.js)
  95. THREE.AddEquation = 100;
  96. THREE.SubtractEquation = 101;
  97. THREE.ReverseSubtractEquation = 102;
  98. THREE.MinEquation = 103;
  99. THREE.MaxEquation = 104;
  100. // custom blending destination factors
  101. THREE.ZeroFactor = 200;
  102. THREE.OneFactor = 201;
  103. THREE.SrcColorFactor = 202;
  104. THREE.OneMinusSrcColorFactor = 203;
  105. THREE.SrcAlphaFactor = 204;
  106. THREE.OneMinusSrcAlphaFactor = 205;
  107. THREE.DstAlphaFactor = 206;
  108. THREE.OneMinusDstAlphaFactor = 207;
  109. // custom blending source factors
  110. //THREE.ZeroFactor = 200;
  111. //THREE.OneFactor = 201;
  112. //THREE.SrcAlphaFactor = 204;
  113. //THREE.OneMinusSrcAlphaFactor = 205;
  114. //THREE.DstAlphaFactor = 206;
  115. //THREE.OneMinusDstAlphaFactor = 207;
  116. THREE.DstColorFactor = 208;
  117. THREE.OneMinusDstColorFactor = 209;
  118. THREE.SrcAlphaSaturateFactor = 210;
  119. // depth modes
  120. THREE.NeverDepth = 0;
  121. THREE.AlwaysDepth = 1;
  122. THREE.LessDepth = 2;
  123. THREE.LessEqualDepth = 3;
  124. THREE.EqualDepth = 4;
  125. THREE.GreaterEqualDepth = 5;
  126. THREE.GreaterDepth = 6;
  127. THREE.NotEqualDepth = 7;
  128. // TEXTURE CONSTANTS
  129. THREE.MultiplyOperation = 0;
  130. THREE.MixOperation = 1;
  131. THREE.AddOperation = 2;
  132. // Tone Mapping modes
  133. THREE.NoToneMapping = 0; // do not do any tone mapping, not even exposure (required for special purpose passes.)
  134. THREE.LinearToneMapping = 1; // only apply exposure.
  135. THREE.ReinhardToneMapping = 2;
  136. THREE.Uncharted2ToneMapping = 3; // John Hable
  137. THREE.CineonToneMapping = 4; // optimized filmic operator by Jim Hejl and Richard Burgess-Dawson
  138. // Mapping modes
  139. THREE.UVMapping = 300;
  140. THREE.CubeReflectionMapping = 301;
  141. THREE.CubeRefractionMapping = 302;
  142. THREE.EquirectangularReflectionMapping = 303;
  143. THREE.EquirectangularRefractionMapping = 304;
  144. THREE.SphericalReflectionMapping = 305;
  145. THREE.CubeUVReflectionMapping = 306;
  146. THREE.CubeUVRefractionMapping = 307;
  147. // Wrapping modes
  148. THREE.RepeatWrapping = 1000;
  149. THREE.ClampToEdgeWrapping = 1001;
  150. THREE.MirroredRepeatWrapping = 1002;
  151. // Filters
  152. THREE.NearestFilter = 1003;
  153. THREE.NearestMipMapNearestFilter = 1004;
  154. THREE.NearestMipMapLinearFilter = 1005;
  155. THREE.LinearFilter = 1006;
  156. THREE.LinearMipMapNearestFilter = 1007;
  157. THREE.LinearMipMapLinearFilter = 1008;
  158. // Data types
  159. THREE.UnsignedByteType = 1009;
  160. THREE.ByteType = 1010;
  161. THREE.ShortType = 1011;
  162. THREE.UnsignedShortType = 1012;
  163. THREE.IntType = 1013;
  164. THREE.UnsignedIntType = 1014;
  165. THREE.FloatType = 1015;
  166. THREE.HalfFloatType = 1025;
  167. // Pixel types
  168. //THREE.UnsignedByteType = 1009;
  169. THREE.UnsignedShort4444Type = 1016;
  170. THREE.UnsignedShort5551Type = 1017;
  171. THREE.UnsignedShort565Type = 1018;
  172. // Pixel formats
  173. THREE.AlphaFormat = 1019;
  174. THREE.RGBFormat = 1020;
  175. THREE.RGBAFormat = 1021;
  176. THREE.LuminanceFormat = 1022;
  177. THREE.LuminanceAlphaFormat = 1023;
  178. // THREE.RGBEFormat handled as THREE.RGBAFormat in shaders
  179. THREE.RGBEFormat = THREE.RGBAFormat; //1024;
  180. // DDS / ST3C Compressed texture formats
  181. THREE.RGB_S3TC_DXT1_Format = 2001;
  182. THREE.RGBA_S3TC_DXT1_Format = 2002;
  183. THREE.RGBA_S3TC_DXT3_Format = 2003;
  184. THREE.RGBA_S3TC_DXT5_Format = 2004;
  185. // PVRTC compressed texture formats
  186. THREE.RGB_PVRTC_4BPPV1_Format = 2100;
  187. THREE.RGB_PVRTC_2BPPV1_Format = 2101;
  188. THREE.RGBA_PVRTC_4BPPV1_Format = 2102;
  189. THREE.RGBA_PVRTC_2BPPV1_Format = 2103;
  190. // ETC compressed texture formats
  191. THREE.RGB_ETC1_Format = 2151;
  192. // Loop styles for AnimationAction
  193. THREE.LoopOnce = 2200;
  194. THREE.LoopRepeat = 2201;
  195. THREE.LoopPingPong = 2202;
  196. // Interpolation
  197. THREE.InterpolateDiscrete = 2300;
  198. THREE.InterpolateLinear = 2301;
  199. THREE.InterpolateSmooth = 2302;
  200. // Interpolant ending modes
  201. THREE.ZeroCurvatureEnding = 2400;
  202. THREE.ZeroSlopeEnding = 2401;
  203. THREE.WrapAroundEnding = 2402;
  204. // Triangle Draw modes
  205. THREE.TrianglesDrawMode = 0;
  206. THREE.TriangleStripDrawMode = 1;
  207. THREE.TriangleFanDrawMode = 2;
  208. // Texture Encodings
  209. THREE.LinearEncoding = 3000; // No encoding at all.
  210. THREE.sRGBEncoding = 3001;
  211. THREE.GammaEncoding = 3007; // uses GAMMA_FACTOR, for backwards compatibility with WebGLRenderer.gammaInput/gammaOutput
  212. // The following Texture Encodings are for RGB-only (no alpha) HDR light emission sources.
  213. // These encodings should not specified as output encodings except in rare situations.
  214. THREE.RGBEEncoding = 3002; // AKA Radiance.
  215. THREE.LogLuvEncoding = 3003;
  216. THREE.RGBM7Encoding = 3004;
  217. THREE.RGBM16Encoding = 3005;
  218. THREE.RGBDEncoding = 3006; // MaxRange is 256.
  219. // File:src/math/Color.js
  220. /**
  221. * @author mrdoob / http://mrdoob.com/
  222. */
  223. THREE.Color = function ( color ) {
  224. if ( arguments.length === 3 ) {
  225. return this.fromArray( arguments );
  226. }
  227. return this.set( color );
  228. };
  229. THREE.Color.prototype = {
  230. constructor: THREE.Color,
  231. r: 1, g: 1, b: 1,
  232. set: function ( value ) {
  233. if ( value instanceof THREE.Color ) {
  234. this.copy( value );
  235. } else if ( typeof value === 'number' ) {
  236. this.setHex( value );
  237. } else if ( typeof value === 'string' ) {
  238. this.setStyle( value );
  239. }
  240. return this;
  241. },
  242. setScalar: function ( scalar ) {
  243. this.r = scalar;
  244. this.g = scalar;
  245. this.b = scalar;
  246. },
  247. setHex: function ( hex ) {
  248. hex = Math.floor( hex );
  249. this.r = ( hex >> 16 & 255 ) / 255;
  250. this.g = ( hex >> 8 & 255 ) / 255;
  251. this.b = ( hex & 255 ) / 255;
  252. return this;
  253. },
  254. setRGB: function ( r, g, b ) {
  255. this.r = r;
  256. this.g = g;
  257. this.b = b;
  258. return this;
  259. },
  260. setHSL: function () {
  261. function hue2rgb( p, q, t ) {
  262. if ( t < 0 ) t += 1;
  263. if ( t > 1 ) t -= 1;
  264. if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
  265. if ( t < 1 / 2 ) return q;
  266. if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
  267. return p;
  268. }
  269. return function ( h, s, l ) {
  270. // h,s,l ranges are in 0.0 - 1.0
  271. h = THREE.Math.euclideanModulo( h, 1 );
  272. s = THREE.Math.clamp( s, 0, 1 );
  273. l = THREE.Math.clamp( l, 0, 1 );
  274. if ( s === 0 ) {
  275. this.r = this.g = this.b = l;
  276. } else {
  277. var p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  278. var q = ( 2 * l ) - p;
  279. this.r = hue2rgb( q, p, h + 1 / 3 );
  280. this.g = hue2rgb( q, p, h );
  281. this.b = hue2rgb( q, p, h - 1 / 3 );
  282. }
  283. return this;
  284. };
  285. }(),
  286. setStyle: function ( style ) {
  287. function handleAlpha( string ) {
  288. if ( string === undefined ) return;
  289. if ( parseFloat( string ) < 1 ) {
  290. console.warn( 'THREE.Color: Alpha component of ' + style + ' will be ignored.' );
  291. }
  292. }
  293. var m;
  294. if ( m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec( style ) ) {
  295. // rgb / hsl
  296. var color;
  297. var name = m[ 1 ];
  298. var components = m[ 2 ];
  299. switch ( name ) {
  300. case 'rgb':
  301. case 'rgba':
  302. if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  303. // rgb(255,0,0) rgba(255,0,0,0.5)
  304. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  305. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  306. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  307. handleAlpha( color[ 5 ] );
  308. return this;
  309. }
  310. if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  311. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  312. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  313. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  314. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  315. handleAlpha( color[ 5 ] );
  316. return this;
  317. }
  318. break;
  319. case 'hsl':
  320. case 'hsla':
  321. if ( color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  322. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  323. var h = parseFloat( color[ 1 ] ) / 360;
  324. var s = parseInt( color[ 2 ], 10 ) / 100;
  325. var l = parseInt( color[ 3 ], 10 ) / 100;
  326. handleAlpha( color[ 5 ] );
  327. return this.setHSL( h, s, l );
  328. }
  329. break;
  330. }
  331. } else if ( m = /^\#([A-Fa-f0-9]+)$/.exec( style ) ) {
  332. // hex color
  333. var hex = m[ 1 ];
  334. var size = hex.length;
  335. if ( size === 3 ) {
  336. // #ff0
  337. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 0 ), 16 ) / 255;
  338. this.g = parseInt( hex.charAt( 1 ) + hex.charAt( 1 ), 16 ) / 255;
  339. this.b = parseInt( hex.charAt( 2 ) + hex.charAt( 2 ), 16 ) / 255;
  340. return this;
  341. } else if ( size === 6 ) {
  342. // #ff0000
  343. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 1 ), 16 ) / 255;
  344. this.g = parseInt( hex.charAt( 2 ) + hex.charAt( 3 ), 16 ) / 255;
  345. this.b = parseInt( hex.charAt( 4 ) + hex.charAt( 5 ), 16 ) / 255;
  346. return this;
  347. }
  348. }
  349. if ( style && style.length > 0 ) {
  350. // color keywords
  351. var hex = THREE.ColorKeywords[ style ];
  352. if ( hex !== undefined ) {
  353. // red
  354. this.setHex( hex );
  355. } else {
  356. // unknown color
  357. console.warn( 'THREE.Color: Unknown color ' + style );
  358. }
  359. }
  360. return this;
  361. },
  362. clone: function () {
  363. return new this.constructor( this.r, this.g, this.b );
  364. },
  365. copy: function ( color ) {
  366. this.r = color.r;
  367. this.g = color.g;
  368. this.b = color.b;
  369. return this;
  370. },
  371. copyGammaToLinear: function ( color, gammaFactor ) {
  372. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  373. this.r = Math.pow( color.r, gammaFactor );
  374. this.g = Math.pow( color.g, gammaFactor );
  375. this.b = Math.pow( color.b, gammaFactor );
  376. return this;
  377. },
  378. copyLinearToGamma: function ( color, gammaFactor ) {
  379. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  380. var safeInverse = ( gammaFactor > 0 ) ? ( 1.0 / gammaFactor ) : 1.0;
  381. this.r = Math.pow( color.r, safeInverse );
  382. this.g = Math.pow( color.g, safeInverse );
  383. this.b = Math.pow( color.b, safeInverse );
  384. return this;
  385. },
  386. convertGammaToLinear: function () {
  387. var r = this.r, g = this.g, b = this.b;
  388. this.r = r * r;
  389. this.g = g * g;
  390. this.b = b * b;
  391. return this;
  392. },
  393. convertLinearToGamma: function () {
  394. this.r = Math.sqrt( this.r );
  395. this.g = Math.sqrt( this.g );
  396. this.b = Math.sqrt( this.b );
  397. return this;
  398. },
  399. getHex: function () {
  400. return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
  401. },
  402. getHexString: function () {
  403. return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
  404. },
  405. getHSL: function ( optionalTarget ) {
  406. // h,s,l ranges are in 0.0 - 1.0
  407. var hsl = optionalTarget || { h: 0, s: 0, l: 0 };
  408. var r = this.r, g = this.g, b = this.b;
  409. var max = Math.max( r, g, b );
  410. var min = Math.min( r, g, b );
  411. var hue, saturation;
  412. var lightness = ( min + max ) / 2.0;
  413. if ( min === max ) {
  414. hue = 0;
  415. saturation = 0;
  416. } else {
  417. var delta = max - min;
  418. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  419. switch ( max ) {
  420. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  421. case g: hue = ( b - r ) / delta + 2; break;
  422. case b: hue = ( r - g ) / delta + 4; break;
  423. }
  424. hue /= 6;
  425. }
  426. hsl.h = hue;
  427. hsl.s = saturation;
  428. hsl.l = lightness;
  429. return hsl;
  430. },
  431. getStyle: function () {
  432. return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
  433. },
  434. offsetHSL: function ( h, s, l ) {
  435. var hsl = this.getHSL();
  436. hsl.h += h; hsl.s += s; hsl.l += l;
  437. this.setHSL( hsl.h, hsl.s, hsl.l );
  438. return this;
  439. },
  440. add: function ( color ) {
  441. this.r += color.r;
  442. this.g += color.g;
  443. this.b += color.b;
  444. return this;
  445. },
  446. addColors: function ( color1, color2 ) {
  447. this.r = color1.r + color2.r;
  448. this.g = color1.g + color2.g;
  449. this.b = color1.b + color2.b;
  450. return this;
  451. },
  452. addScalar: function ( s ) {
  453. this.r += s;
  454. this.g += s;
  455. this.b += s;
  456. return this;
  457. },
  458. multiply: function ( color ) {
  459. this.r *= color.r;
  460. this.g *= color.g;
  461. this.b *= color.b;
  462. return this;
  463. },
  464. multiplyScalar: function ( s ) {
  465. this.r *= s;
  466. this.g *= s;
  467. this.b *= s;
  468. return this;
  469. },
  470. lerp: function ( color, alpha ) {
  471. this.r += ( color.r - this.r ) * alpha;
  472. this.g += ( color.g - this.g ) * alpha;
  473. this.b += ( color.b - this.b ) * alpha;
  474. return this;
  475. },
  476. equals: function ( c ) {
  477. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  478. },
  479. fromArray: function ( array, offset ) {
  480. if ( offset === undefined ) offset = 0;
  481. this.r = array[ offset ];
  482. this.g = array[ offset + 1 ];
  483. this.b = array[ offset + 2 ];
  484. return this;
  485. },
  486. toArray: function ( array, offset ) {
  487. if ( array === undefined ) array = [];
  488. if ( offset === undefined ) offset = 0;
  489. array[ offset ] = this.r;
  490. array[ offset + 1 ] = this.g;
  491. array[ offset + 2 ] = this.b;
  492. return array;
  493. }
  494. };
  495. THREE.ColorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  496. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  497. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  498. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  499. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  500. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  501. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  502. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  503. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  504. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  505. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  506. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  507. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  508. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  509. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  510. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  511. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  512. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  513. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  514. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  515. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  516. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  517. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  518. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  519. // File:src/math/Quaternion.js
  520. /**
  521. * @author mikael emtinger / http://gomo.se/
  522. * @author alteredq / http://alteredqualia.com/
  523. * @author WestLangley / http://github.com/WestLangley
  524. * @author bhouston / http://clara.io
  525. */
  526. THREE.Quaternion = function ( x, y, z, w ) {
  527. this._x = x || 0;
  528. this._y = y || 0;
  529. this._z = z || 0;
  530. this._w = ( w !== undefined ) ? w : 1;
  531. };
  532. THREE.Quaternion.prototype = {
  533. constructor: THREE.Quaternion,
  534. get x () {
  535. return this._x;
  536. },
  537. set x ( value ) {
  538. this._x = value;
  539. this.onChangeCallback();
  540. },
  541. get y () {
  542. return this._y;
  543. },
  544. set y ( value ) {
  545. this._y = value;
  546. this.onChangeCallback();
  547. },
  548. get z () {
  549. return this._z;
  550. },
  551. set z ( value ) {
  552. this._z = value;
  553. this.onChangeCallback();
  554. },
  555. get w () {
  556. return this._w;
  557. },
  558. set w ( value ) {
  559. this._w = value;
  560. this.onChangeCallback();
  561. },
  562. set: function ( x, y, z, w ) {
  563. this._x = x;
  564. this._y = y;
  565. this._z = z;
  566. this._w = w;
  567. this.onChangeCallback();
  568. return this;
  569. },
  570. clone: function () {
  571. return new this.constructor( this._x, this._y, this._z, this._w );
  572. },
  573. copy: function ( quaternion ) {
  574. this._x = quaternion.x;
  575. this._y = quaternion.y;
  576. this._z = quaternion.z;
  577. this._w = quaternion.w;
  578. this.onChangeCallback();
  579. return this;
  580. },
  581. setFromEuler: function ( euler, update ) {
  582. if ( euler instanceof THREE.Euler === false ) {
  583. throw new Error( 'THREE.Quaternion: .setFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  584. }
  585. // http://www.mathworks.com/matlabcentral/fileexchange/
  586. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  587. // content/SpinCalc.m
  588. var c1 = Math.cos( euler._x / 2 );
  589. var c2 = Math.cos( euler._y / 2 );
  590. var c3 = Math.cos( euler._z / 2 );
  591. var s1 = Math.sin( euler._x / 2 );
  592. var s2 = Math.sin( euler._y / 2 );
  593. var s3 = Math.sin( euler._z / 2 );
  594. var order = euler.order;
  595. if ( order === 'XYZ' ) {
  596. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  597. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  598. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  599. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  600. } else if ( order === 'YXZ' ) {
  601. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  602. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  603. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  604. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  605. } else if ( order === 'ZXY' ) {
  606. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  607. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  608. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  609. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  610. } else if ( order === 'ZYX' ) {
  611. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  612. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  613. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  614. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  615. } else if ( order === 'YZX' ) {
  616. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  617. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  618. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  619. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  620. } else if ( order === 'XZY' ) {
  621. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  622. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  623. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  624. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  625. }
  626. if ( update !== false ) this.onChangeCallback();
  627. return this;
  628. },
  629. setFromAxisAngle: function ( axis, angle ) {
  630. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  631. // assumes axis is normalized
  632. var halfAngle = angle / 2, s = Math.sin( halfAngle );
  633. this._x = axis.x * s;
  634. this._y = axis.y * s;
  635. this._z = axis.z * s;
  636. this._w = Math.cos( halfAngle );
  637. this.onChangeCallback();
  638. return this;
  639. },
  640. setFromRotationMatrix: function ( m ) {
  641. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  642. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  643. var te = m.elements,
  644. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  645. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  646. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ],
  647. trace = m11 + m22 + m33,
  648. s;
  649. if ( trace > 0 ) {
  650. s = 0.5 / Math.sqrt( trace + 1.0 );
  651. this._w = 0.25 / s;
  652. this._x = ( m32 - m23 ) * s;
  653. this._y = ( m13 - m31 ) * s;
  654. this._z = ( m21 - m12 ) * s;
  655. } else if ( m11 > m22 && m11 > m33 ) {
  656. s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );
  657. this._w = ( m32 - m23 ) / s;
  658. this._x = 0.25 * s;
  659. this._y = ( m12 + m21 ) / s;
  660. this._z = ( m13 + m31 ) / s;
  661. } else if ( m22 > m33 ) {
  662. s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );
  663. this._w = ( m13 - m31 ) / s;
  664. this._x = ( m12 + m21 ) / s;
  665. this._y = 0.25 * s;
  666. this._z = ( m23 + m32 ) / s;
  667. } else {
  668. s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );
  669. this._w = ( m21 - m12 ) / s;
  670. this._x = ( m13 + m31 ) / s;
  671. this._y = ( m23 + m32 ) / s;
  672. this._z = 0.25 * s;
  673. }
  674. this.onChangeCallback();
  675. return this;
  676. },
  677. setFromUnitVectors: function () {
  678. // http://lolengine.net/blog/2014/02/24/quaternion-from-two-vectors-final
  679. // assumes direction vectors vFrom and vTo are normalized
  680. var v1, r;
  681. var EPS = 0.000001;
  682. return function ( vFrom, vTo ) {
  683. if ( v1 === undefined ) v1 = new THREE.Vector3();
  684. r = vFrom.dot( vTo ) + 1;
  685. if ( r < EPS ) {
  686. r = 0;
  687. if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) {
  688. v1.set( - vFrom.y, vFrom.x, 0 );
  689. } else {
  690. v1.set( 0, - vFrom.z, vFrom.y );
  691. }
  692. } else {
  693. v1.crossVectors( vFrom, vTo );
  694. }
  695. this._x = v1.x;
  696. this._y = v1.y;
  697. this._z = v1.z;
  698. this._w = r;
  699. this.normalize();
  700. return this;
  701. };
  702. }(),
  703. inverse: function () {
  704. this.conjugate().normalize();
  705. return this;
  706. },
  707. conjugate: function () {
  708. this._x *= - 1;
  709. this._y *= - 1;
  710. this._z *= - 1;
  711. this.onChangeCallback();
  712. return this;
  713. },
  714. dot: function ( v ) {
  715. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  716. },
  717. lengthSq: function () {
  718. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  719. },
  720. length: function () {
  721. return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );
  722. },
  723. normalize: function () {
  724. var l = this.length();
  725. if ( l === 0 ) {
  726. this._x = 0;
  727. this._y = 0;
  728. this._z = 0;
  729. this._w = 1;
  730. } else {
  731. l = 1 / l;
  732. this._x = this._x * l;
  733. this._y = this._y * l;
  734. this._z = this._z * l;
  735. this._w = this._w * l;
  736. }
  737. this.onChangeCallback();
  738. return this;
  739. },
  740. multiply: function ( q, p ) {
  741. if ( p !== undefined ) {
  742. console.warn( 'THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.' );
  743. return this.multiplyQuaternions( q, p );
  744. }
  745. return this.multiplyQuaternions( this, q );
  746. },
  747. multiplyQuaternions: function ( a, b ) {
  748. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  749. var qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
  750. var qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
  751. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  752. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  753. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  754. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  755. this.onChangeCallback();
  756. return this;
  757. },
  758. slerp: function ( qb, t ) {
  759. if ( t === 0 ) return this;
  760. if ( t === 1 ) return this.copy( qb );
  761. var x = this._x, y = this._y, z = this._z, w = this._w;
  762. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  763. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  764. if ( cosHalfTheta < 0 ) {
  765. this._w = - qb._w;
  766. this._x = - qb._x;
  767. this._y = - qb._y;
  768. this._z = - qb._z;
  769. cosHalfTheta = - cosHalfTheta;
  770. } else {
  771. this.copy( qb );
  772. }
  773. if ( cosHalfTheta >= 1.0 ) {
  774. this._w = w;
  775. this._x = x;
  776. this._y = y;
  777. this._z = z;
  778. return this;
  779. }
  780. var sinHalfTheta = Math.sqrt( 1.0 - cosHalfTheta * cosHalfTheta );
  781. if ( Math.abs( sinHalfTheta ) < 0.001 ) {
  782. this._w = 0.5 * ( w + this._w );
  783. this._x = 0.5 * ( x + this._x );
  784. this._y = 0.5 * ( y + this._y );
  785. this._z = 0.5 * ( z + this._z );
  786. return this;
  787. }
  788. var halfTheta = Math.atan2( sinHalfTheta, cosHalfTheta );
  789. var ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  790. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  791. this._w = ( w * ratioA + this._w * ratioB );
  792. this._x = ( x * ratioA + this._x * ratioB );
  793. this._y = ( y * ratioA + this._y * ratioB );
  794. this._z = ( z * ratioA + this._z * ratioB );
  795. this.onChangeCallback();
  796. return this;
  797. },
  798. equals: function ( quaternion ) {
  799. return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
  800. },
  801. fromArray: function ( array, offset ) {
  802. if ( offset === undefined ) offset = 0;
  803. this._x = array[ offset ];
  804. this._y = array[ offset + 1 ];
  805. this._z = array[ offset + 2 ];
  806. this._w = array[ offset + 3 ];
  807. this.onChangeCallback();
  808. return this;
  809. },
  810. toArray: function ( array, offset ) {
  811. if ( array === undefined ) array = [];
  812. if ( offset === undefined ) offset = 0;
  813. array[ offset ] = this._x;
  814. array[ offset + 1 ] = this._y;
  815. array[ offset + 2 ] = this._z;
  816. array[ offset + 3 ] = this._w;
  817. return array;
  818. },
  819. onChange: function ( callback ) {
  820. this.onChangeCallback = callback;
  821. return this;
  822. },
  823. onChangeCallback: function () {}
  824. };
  825. Object.assign( THREE.Quaternion, {
  826. slerp: function( qa, qb, qm, t ) {
  827. return qm.copy( qa ).slerp( qb, t );
  828. },
  829. slerpFlat: function(
  830. dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t ) {
  831. // fuzz-free, array-based Quaternion SLERP operation
  832. var x0 = src0[ srcOffset0 + 0 ],
  833. y0 = src0[ srcOffset0 + 1 ],
  834. z0 = src0[ srcOffset0 + 2 ],
  835. w0 = src0[ srcOffset0 + 3 ],
  836. x1 = src1[ srcOffset1 + 0 ],
  837. y1 = src1[ srcOffset1 + 1 ],
  838. z1 = src1[ srcOffset1 + 2 ],
  839. w1 = src1[ srcOffset1 + 3 ];
  840. if ( w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1 ) {
  841. var s = 1 - t,
  842. cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  843. dir = ( cos >= 0 ? 1 : - 1 ),
  844. sqrSin = 1 - cos * cos;
  845. // Skip the Slerp for tiny steps to avoid numeric problems:
  846. if ( sqrSin > Number.EPSILON ) {
  847. var sin = Math.sqrt( sqrSin ),
  848. len = Math.atan2( sin, cos * dir );
  849. s = Math.sin( s * len ) / sin;
  850. t = Math.sin( t * len ) / sin;
  851. }
  852. var tDir = t * dir;
  853. x0 = x0 * s + x1 * tDir;
  854. y0 = y0 * s + y1 * tDir;
  855. z0 = z0 * s + z1 * tDir;
  856. w0 = w0 * s + w1 * tDir;
  857. // Normalize in case we just did a lerp:
  858. if ( s === 1 - t ) {
  859. var f = 1 / Math.sqrt( x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0 );
  860. x0 *= f;
  861. y0 *= f;
  862. z0 *= f;
  863. w0 *= f;
  864. }
  865. }
  866. dst[ dstOffset ] = x0;
  867. dst[ dstOffset + 1 ] = y0;
  868. dst[ dstOffset + 2 ] = z0;
  869. dst[ dstOffset + 3 ] = w0;
  870. }
  871. } );
  872. // File:src/math/Vector2.js
  873. /**
  874. * @author mrdoob / http://mrdoob.com/
  875. * @author philogb / http://blog.thejit.org/
  876. * @author egraether / http://egraether.com/
  877. * @author zz85 / http://www.lab4games.net/zz85/blog
  878. */
  879. THREE.Vector2 = function ( x, y ) {
  880. this.x = x || 0;
  881. this.y = y || 0;
  882. };
  883. THREE.Vector2.prototype = {
  884. constructor: THREE.Vector2,
  885. get width() {
  886. return this.x;
  887. },
  888. set width( value ) {
  889. this.x = value;
  890. },
  891. get height() {
  892. return this.y;
  893. },
  894. set height( value ) {
  895. this.y = value;
  896. },
  897. //
  898. set: function ( x, y ) {
  899. this.x = x;
  900. this.y = y;
  901. return this;
  902. },
  903. setScalar: function ( scalar ) {
  904. this.x = scalar;
  905. this.y = scalar;
  906. return this;
  907. },
  908. setX: function ( x ) {
  909. this.x = x;
  910. return this;
  911. },
  912. setY: function ( y ) {
  913. this.y = y;
  914. return this;
  915. },
  916. setComponent: function ( index, value ) {
  917. switch ( index ) {
  918. case 0: this.x = value; break;
  919. case 1: this.y = value; break;
  920. default: throw new Error( 'index is out of range: ' + index );
  921. }
  922. },
  923. getComponent: function ( index ) {
  924. switch ( index ) {
  925. case 0: return this.x;
  926. case 1: return this.y;
  927. default: throw new Error( 'index is out of range: ' + index );
  928. }
  929. },
  930. clone: function () {
  931. return new this.constructor( this.x, this.y );
  932. },
  933. copy: function ( v ) {
  934. this.x = v.x;
  935. this.y = v.y;
  936. return this;
  937. },
  938. add: function ( v, w ) {
  939. if ( w !== undefined ) {
  940. console.warn( 'THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  941. return this.addVectors( v, w );
  942. }
  943. this.x += v.x;
  944. this.y += v.y;
  945. return this;
  946. },
  947. addScalar: function ( s ) {
  948. this.x += s;
  949. this.y += s;
  950. return this;
  951. },
  952. addVectors: function ( a, b ) {
  953. this.x = a.x + b.x;
  954. this.y = a.y + b.y;
  955. return this;
  956. },
  957. addScaledVector: function ( v, s ) {
  958. this.x += v.x * s;
  959. this.y += v.y * s;
  960. return this;
  961. },
  962. sub: function ( v, w ) {
  963. if ( w !== undefined ) {
  964. console.warn( 'THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  965. return this.subVectors( v, w );
  966. }
  967. this.x -= v.x;
  968. this.y -= v.y;
  969. return this;
  970. },
  971. subScalar: function ( s ) {
  972. this.x -= s;
  973. this.y -= s;
  974. return this;
  975. },
  976. subVectors: function ( a, b ) {
  977. this.x = a.x - b.x;
  978. this.y = a.y - b.y;
  979. return this;
  980. },
  981. multiply: function ( v ) {
  982. this.x *= v.x;
  983. this.y *= v.y;
  984. return this;
  985. },
  986. multiplyScalar: function ( scalar ) {
  987. if ( isFinite( scalar ) ) {
  988. this.x *= scalar;
  989. this.y *= scalar;
  990. } else {
  991. this.x = 0;
  992. this.y = 0;
  993. }
  994. return this;
  995. },
  996. divide: function ( v ) {
  997. this.x /= v.x;
  998. this.y /= v.y;
  999. return this;
  1000. },
  1001. divideScalar: function ( scalar ) {
  1002. return this.multiplyScalar( 1 / scalar );
  1003. },
  1004. min: function ( v ) {
  1005. this.x = Math.min( this.x, v.x );
  1006. this.y = Math.min( this.y, v.y );
  1007. return this;
  1008. },
  1009. max: function ( v ) {
  1010. this.x = Math.max( this.x, v.x );
  1011. this.y = Math.max( this.y, v.y );
  1012. return this;
  1013. },
  1014. clamp: function ( min, max ) {
  1015. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1016. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1017. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1018. return this;
  1019. },
  1020. clampScalar: function () {
  1021. var min, max;
  1022. return function clampScalar( minVal, maxVal ) {
  1023. if ( min === undefined ) {
  1024. min = new THREE.Vector2();
  1025. max = new THREE.Vector2();
  1026. }
  1027. min.set( minVal, minVal );
  1028. max.set( maxVal, maxVal );
  1029. return this.clamp( min, max );
  1030. };
  1031. }(),
  1032. clampLength: function ( min, max ) {
  1033. var length = this.length();
  1034. this.multiplyScalar( Math.max( min, Math.min( max, length ) ) / length );
  1035. return this;
  1036. },
  1037. floor: function () {
  1038. this.x = Math.floor( this.x );
  1039. this.y = Math.floor( this.y );
  1040. return this;
  1041. },
  1042. ceil: function () {
  1043. this.x = Math.ceil( this.x );
  1044. this.y = Math.ceil( this.y );
  1045. return this;
  1046. },
  1047. round: function () {
  1048. this.x = Math.round( this.x );
  1049. this.y = Math.round( this.y );
  1050. return this;
  1051. },
  1052. roundToZero: function () {
  1053. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1054. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1055. return this;
  1056. },
  1057. negate: function () {
  1058. this.x = - this.x;
  1059. this.y = - this.y;
  1060. return this;
  1061. },
  1062. dot: function ( v ) {
  1063. return this.x * v.x + this.y * v.y;
  1064. },
  1065. lengthSq: function () {
  1066. return this.x * this.x + this.y * this.y;
  1067. },
  1068. length: function () {
  1069. return Math.sqrt( this.x * this.x + this.y * this.y );
  1070. },
  1071. lengthManhattan: function() {
  1072. return Math.abs( this.x ) + Math.abs( this.y );
  1073. },
  1074. normalize: function () {
  1075. return this.divideScalar( this.length() );
  1076. },
  1077. angle: function () {
  1078. // computes the angle in radians with respect to the positive x-axis
  1079. var angle = Math.atan2( this.y, this.x );
  1080. if ( angle < 0 ) angle += 2 * Math.PI;
  1081. return angle;
  1082. },
  1083. distanceTo: function ( v ) {
  1084. return Math.sqrt( this.distanceToSquared( v ) );
  1085. },
  1086. distanceToSquared: function ( v ) {
  1087. var dx = this.x - v.x, dy = this.y - v.y;
  1088. return dx * dx + dy * dy;
  1089. },
  1090. setLength: function ( length ) {
  1091. return this.multiplyScalar( length / this.length() );
  1092. },
  1093. lerp: function ( v, alpha ) {
  1094. this.x += ( v.x - this.x ) * alpha;
  1095. this.y += ( v.y - this.y ) * alpha;
  1096. return this;
  1097. },
  1098. lerpVectors: function ( v1, v2, alpha ) {
  1099. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1100. return this;
  1101. },
  1102. equals: function ( v ) {
  1103. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  1104. },
  1105. fromArray: function ( array, offset ) {
  1106. if ( offset === undefined ) offset = 0;
  1107. this.x = array[ offset ];
  1108. this.y = array[ offset + 1 ];
  1109. return this;
  1110. },
  1111. toArray: function ( array, offset ) {
  1112. if ( array === undefined ) array = [];
  1113. if ( offset === undefined ) offset = 0;
  1114. array[ offset ] = this.x;
  1115. array[ offset + 1 ] = this.y;
  1116. return array;
  1117. },
  1118. fromAttribute: function ( attribute, index, offset ) {
  1119. if ( offset === undefined ) offset = 0;
  1120. index = index * attribute.itemSize + offset;
  1121. this.x = attribute.array[ index ];
  1122. this.y = attribute.array[ index + 1 ];
  1123. return this;
  1124. },
  1125. rotateAround: function ( center, angle ) {
  1126. var c = Math.cos( angle ), s = Math.sin( angle );
  1127. var x = this.x - center.x;
  1128. var y = this.y - center.y;
  1129. this.x = x * c - y * s + center.x;
  1130. this.y = x * s + y * c + center.y;
  1131. return this;
  1132. }
  1133. };
  1134. // File:src/math/Vector3.js
  1135. /**
  1136. * @author mrdoob / http://mrdoob.com/
  1137. * @author *kile / http://kile.stravaganza.org/
  1138. * @author philogb / http://blog.thejit.org/
  1139. * @author mikael emtinger / http://gomo.se/
  1140. * @author egraether / http://egraether.com/
  1141. * @author WestLangley / http://github.com/WestLangley
  1142. */
  1143. THREE.Vector3 = function ( x, y, z ) {
  1144. this.x = x || 0;
  1145. this.y = y || 0;
  1146. this.z = z || 0;
  1147. };
  1148. THREE.Vector3.prototype = {
  1149. constructor: THREE.Vector3,
  1150. set: function ( x, y, z ) {
  1151. this.x = x;
  1152. this.y = y;
  1153. this.z = z;
  1154. return this;
  1155. },
  1156. setScalar: function ( scalar ) {
  1157. this.x = scalar;
  1158. this.y = scalar;
  1159. this.z = scalar;
  1160. return this;
  1161. },
  1162. setX: function ( x ) {
  1163. this.x = x;
  1164. return this;
  1165. },
  1166. setY: function ( y ) {
  1167. this.y = y;
  1168. return this;
  1169. },
  1170. setZ: function ( z ) {
  1171. this.z = z;
  1172. return this;
  1173. },
  1174. setComponent: function ( index, value ) {
  1175. switch ( index ) {
  1176. case 0: this.x = value; break;
  1177. case 1: this.y = value; break;
  1178. case 2: this.z = value; break;
  1179. default: throw new Error( 'index is out of range: ' + index );
  1180. }
  1181. },
  1182. getComponent: function ( index ) {
  1183. switch ( index ) {
  1184. case 0: return this.x;
  1185. case 1: return this.y;
  1186. case 2: return this.z;
  1187. default: throw new Error( 'index is out of range: ' + index );
  1188. }
  1189. },
  1190. clone: function () {
  1191. return new this.constructor( this.x, this.y, this.z );
  1192. },
  1193. copy: function ( v ) {
  1194. this.x = v.x;
  1195. this.y = v.y;
  1196. this.z = v.z;
  1197. return this;
  1198. },
  1199. add: function ( v, w ) {
  1200. if ( w !== undefined ) {
  1201. console.warn( 'THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1202. return this.addVectors( v, w );
  1203. }
  1204. this.x += v.x;
  1205. this.y += v.y;
  1206. this.z += v.z;
  1207. return this;
  1208. },
  1209. addScalar: function ( s ) {
  1210. this.x += s;
  1211. this.y += s;
  1212. this.z += s;
  1213. return this;
  1214. },
  1215. addVectors: function ( a, b ) {
  1216. this.x = a.x + b.x;
  1217. this.y = a.y + b.y;
  1218. this.z = a.z + b.z;
  1219. return this;
  1220. },
  1221. addScaledVector: function ( v, s ) {
  1222. this.x += v.x * s;
  1223. this.y += v.y * s;
  1224. this.z += v.z * s;
  1225. return this;
  1226. },
  1227. sub: function ( v, w ) {
  1228. if ( w !== undefined ) {
  1229. console.warn( 'THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1230. return this.subVectors( v, w );
  1231. }
  1232. this.x -= v.x;
  1233. this.y -= v.y;
  1234. this.z -= v.z;
  1235. return this;
  1236. },
  1237. subScalar: function ( s ) {
  1238. this.x -= s;
  1239. this.y -= s;
  1240. this.z -= s;
  1241. return this;
  1242. },
  1243. subVectors: function ( a, b ) {
  1244. this.x = a.x - b.x;
  1245. this.y = a.y - b.y;
  1246. this.z = a.z - b.z;
  1247. return this;
  1248. },
  1249. multiply: function ( v, w ) {
  1250. if ( w !== undefined ) {
  1251. console.warn( 'THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.' );
  1252. return this.multiplyVectors( v, w );
  1253. }
  1254. this.x *= v.x;
  1255. this.y *= v.y;
  1256. this.z *= v.z;
  1257. return this;
  1258. },
  1259. multiplyScalar: function ( scalar ) {
  1260. if ( isFinite( scalar ) ) {
  1261. this.x *= scalar;
  1262. this.y *= scalar;
  1263. this.z *= scalar;
  1264. } else {
  1265. this.x = 0;
  1266. this.y = 0;
  1267. this.z = 0;
  1268. }
  1269. return this;
  1270. },
  1271. multiplyVectors: function ( a, b ) {
  1272. this.x = a.x * b.x;
  1273. this.y = a.y * b.y;
  1274. this.z = a.z * b.z;
  1275. return this;
  1276. },
  1277. applyEuler: function () {
  1278. var quaternion;
  1279. return function applyEuler( euler ) {
  1280. if ( euler instanceof THREE.Euler === false ) {
  1281. console.error( 'THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  1282. }
  1283. if ( quaternion === undefined ) quaternion = new THREE.Quaternion();
  1284. this.applyQuaternion( quaternion.setFromEuler( euler ) );
  1285. return this;
  1286. };
  1287. }(),
  1288. applyAxisAngle: function () {
  1289. var quaternion;
  1290. return function applyAxisAngle( axis, angle ) {
  1291. if ( quaternion === undefined ) quaternion = new THREE.Quaternion();
  1292. this.applyQuaternion( quaternion.setFromAxisAngle( axis, angle ) );
  1293. return this;
  1294. };
  1295. }(),
  1296. applyMatrix3: function ( m ) {
  1297. var x = this.x;
  1298. var y = this.y;
  1299. var z = this.z;
  1300. var e = m.elements;
  1301. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
  1302. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
  1303. this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
  1304. return this;
  1305. },
  1306. applyMatrix4: function ( m ) {
  1307. // input: THREE.Matrix4 affine matrix
  1308. var x = this.x, y = this.y, z = this.z;
  1309. var e = m.elements;
  1310. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ];
  1311. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ];
  1312. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ];
  1313. return this;
  1314. },
  1315. applyProjection: function ( m ) {
  1316. // input: THREE.Matrix4 projection matrix
  1317. var x = this.x, y = this.y, z = this.z;
  1318. var e = m.elements;
  1319. var d = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] ); // perspective divide
  1320. this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * d;
  1321. this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * d;
  1322. this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * d;
  1323. return this;
  1324. },
  1325. applyQuaternion: function ( q ) {
  1326. var x = this.x;
  1327. var y = this.y;
  1328. var z = this.z;
  1329. var qx = q.x;
  1330. var qy = q.y;
  1331. var qz = q.z;
  1332. var qw = q.w;
  1333. // calculate quat * vector
  1334. var ix = qw * x + qy * z - qz * y;
  1335. var iy = qw * y + qz * x - qx * z;
  1336. var iz = qw * z + qx * y - qy * x;
  1337. var iw = - qx * x - qy * y - qz * z;
  1338. // calculate result * inverse quat
  1339. this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
  1340. this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
  1341. this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
  1342. return this;
  1343. },
  1344. project: function () {
  1345. var matrix;
  1346. return function project( camera ) {
  1347. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  1348. matrix.multiplyMatrices( camera.projectionMatrix, matrix.getInverse( camera.matrixWorld ) );
  1349. return this.applyProjection( matrix );
  1350. };
  1351. }(),
  1352. unproject: function () {
  1353. var matrix;
  1354. return function unproject( camera ) {
  1355. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  1356. matrix.multiplyMatrices( camera.matrixWorld, matrix.getInverse( camera.projectionMatrix ) );
  1357. return this.applyProjection( matrix );
  1358. };
  1359. }(),
  1360. transformDirection: function ( m ) {
  1361. // input: THREE.Matrix4 affine matrix
  1362. // vector interpreted as a direction
  1363. var x = this.x, y = this.y, z = this.z;
  1364. var e = m.elements;
  1365. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
  1366. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
  1367. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
  1368. this.normalize();
  1369. return this;
  1370. },
  1371. divide: function ( v ) {
  1372. this.x /= v.x;
  1373. this.y /= v.y;
  1374. this.z /= v.z;
  1375. return this;
  1376. },
  1377. divideScalar: function ( scalar ) {
  1378. return this.multiplyScalar( 1 / scalar );
  1379. },
  1380. min: function ( v ) {
  1381. this.x = Math.min( this.x, v.x );
  1382. this.y = Math.min( this.y, v.y );
  1383. this.z = Math.min( this.z, v.z );
  1384. return this;
  1385. },
  1386. max: function ( v ) {
  1387. this.x = Math.max( this.x, v.x );
  1388. this.y = Math.max( this.y, v.y );
  1389. this.z = Math.max( this.z, v.z );
  1390. return this;
  1391. },
  1392. clamp: function ( min, max ) {
  1393. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1394. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1395. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1396. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  1397. return this;
  1398. },
  1399. clampScalar: function () {
  1400. var min, max;
  1401. return function clampScalar( minVal, maxVal ) {
  1402. if ( min === undefined ) {
  1403. min = new THREE.Vector3();
  1404. max = new THREE.Vector3();
  1405. }
  1406. min.set( minVal, minVal, minVal );
  1407. max.set( maxVal, maxVal, maxVal );
  1408. return this.clamp( min, max );
  1409. };
  1410. }(),
  1411. clampLength: function ( min, max ) {
  1412. var length = this.length();
  1413. this.multiplyScalar( Math.max( min, Math.min( max, length ) ) / length );
  1414. return this;
  1415. },
  1416. floor: function () {
  1417. this.x = Math.floor( this.x );
  1418. this.y = Math.floor( this.y );
  1419. this.z = Math.floor( this.z );
  1420. return this;
  1421. },
  1422. ceil: function () {
  1423. this.x = Math.ceil( this.x );
  1424. this.y = Math.ceil( this.y );
  1425. this.z = Math.ceil( this.z );
  1426. return this;
  1427. },
  1428. round: function () {
  1429. this.x = Math.round( this.x );
  1430. this.y = Math.round( this.y );
  1431. this.z = Math.round( this.z );
  1432. return this;
  1433. },
  1434. roundToZero: function () {
  1435. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1436. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1437. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1438. return this;
  1439. },
  1440. negate: function () {
  1441. this.x = - this.x;
  1442. this.y = - this.y;
  1443. this.z = - this.z;
  1444. return this;
  1445. },
  1446. dot: function ( v ) {
  1447. return this.x * v.x + this.y * v.y + this.z * v.z;
  1448. },
  1449. lengthSq: function () {
  1450. return this.x * this.x + this.y * this.y + this.z * this.z;
  1451. },
  1452. length: function () {
  1453. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
  1454. },
  1455. lengthManhattan: function () {
  1456. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  1457. },
  1458. normalize: function () {
  1459. return this.divideScalar( this.length() );
  1460. },
  1461. setLength: function ( length ) {
  1462. return this.multiplyScalar( length / this.length() );
  1463. },
  1464. lerp: function ( v, alpha ) {
  1465. this.x += ( v.x - this.x ) * alpha;
  1466. this.y += ( v.y - this.y ) * alpha;
  1467. this.z += ( v.z - this.z ) * alpha;
  1468. return this;
  1469. },
  1470. lerpVectors: function ( v1, v2, alpha ) {
  1471. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1472. return this;
  1473. },
  1474. cross: function ( v, w ) {
  1475. if ( w !== undefined ) {
  1476. console.warn( 'THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.' );
  1477. return this.crossVectors( v, w );
  1478. }
  1479. var x = this.x, y = this.y, z = this.z;
  1480. this.x = y * v.z - z * v.y;
  1481. this.y = z * v.x - x * v.z;
  1482. this.z = x * v.y - y * v.x;
  1483. return this;
  1484. },
  1485. crossVectors: function ( a, b ) {
  1486. var ax = a.x, ay = a.y, az = a.z;
  1487. var bx = b.x, by = b.y, bz = b.z;
  1488. this.x = ay * bz - az * by;
  1489. this.y = az * bx - ax * bz;
  1490. this.z = ax * by - ay * bx;
  1491. return this;
  1492. },
  1493. projectOnVector: function () {
  1494. var v1, dot;
  1495. return function projectOnVector( vector ) {
  1496. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1497. v1.copy( vector ).normalize();
  1498. dot = this.dot( v1 );
  1499. return this.copy( v1 ).multiplyScalar( dot );
  1500. };
  1501. }(),
  1502. projectOnPlane: function () {
  1503. var v1;
  1504. return function projectOnPlane( planeNormal ) {
  1505. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1506. v1.copy( this ).projectOnVector( planeNormal );
  1507. return this.sub( v1 );
  1508. };
  1509. }(),
  1510. reflect: function () {
  1511. // reflect incident vector off plane orthogonal to normal
  1512. // normal is assumed to have unit length
  1513. var v1;
  1514. return function reflect( normal ) {
  1515. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1516. return this.sub( v1.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
  1517. };
  1518. }(),
  1519. angleTo: function ( v ) {
  1520. var theta = this.dot( v ) / ( Math.sqrt( this.lengthSq() * v.lengthSq() ) );
  1521. // clamp, to handle numerical problems
  1522. return Math.acos( THREE.Math.clamp( theta, - 1, 1 ) );
  1523. },
  1524. distanceTo: function ( v ) {
  1525. return Math.sqrt( this.distanceToSquared( v ) );
  1526. },
  1527. distanceToSquared: function ( v ) {
  1528. var dx = this.x - v.x;
  1529. var dy = this.y - v.y;
  1530. var dz = this.z - v.z;
  1531. return dx * dx + dy * dy + dz * dz;
  1532. },
  1533. setFromSpherical: function( s ) {
  1534. var sinPhiRadius = Math.sin( s.phi ) * s.radius;
  1535. this.x = sinPhiRadius * Math.sin( s.theta );
  1536. this.y = Math.cos( s.phi ) * s.radius;
  1537. this.z = sinPhiRadius * Math.cos( s.theta );
  1538. return this;
  1539. },
  1540. setFromMatrixPosition: function ( m ) {
  1541. return this.setFromMatrixColumn( m, 3 );
  1542. },
  1543. setFromMatrixScale: function ( m ) {
  1544. var sx = this.setFromMatrixColumn( m, 0 ).length();
  1545. var sy = this.setFromMatrixColumn( m, 1 ).length();
  1546. var sz = this.setFromMatrixColumn( m, 2 ).length();
  1547. this.x = sx;
  1548. this.y = sy;
  1549. this.z = sz;
  1550. return this;
  1551. },
  1552. setFromMatrixColumn: function ( m, index ) {
  1553. if ( typeof m === 'number' ) {
  1554. console.warn( 'THREE.Vector3: setFromMatrixColumn now expects ( matrix, index ).' );
  1555. m = arguments[ 1 ];
  1556. index = arguments[ 0 ];
  1557. }
  1558. return this.fromArray( m.elements, index * 4 );
  1559. },
  1560. equals: function ( v ) {
  1561. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  1562. },
  1563. fromArray: function ( array, offset ) {
  1564. if ( offset === undefined ) offset = 0;
  1565. this.x = array[ offset ];
  1566. this.y = array[ offset + 1 ];
  1567. this.z = array[ offset + 2 ];
  1568. return this;
  1569. },
  1570. toArray: function ( array, offset ) {
  1571. if ( array === undefined ) array = [];
  1572. if ( offset === undefined ) offset = 0;
  1573. array[ offset ] = this.x;
  1574. array[ offset + 1 ] = this.y;
  1575. array[ offset + 2 ] = this.z;
  1576. return array;
  1577. },
  1578. fromAttribute: function ( attribute, index, offset ) {
  1579. if ( offset === undefined ) offset = 0;
  1580. index = index * attribute.itemSize + offset;
  1581. this.x = attribute.array[ index ];
  1582. this.y = attribute.array[ index + 1 ];
  1583. this.z = attribute.array[ index + 2 ];
  1584. return this;
  1585. }
  1586. };
  1587. // File:src/math/Vector4.js
  1588. /**
  1589. * @author supereggbert / http://www.paulbrunt.co.uk/
  1590. * @author philogb / http://blog.thejit.org/
  1591. * @author mikael emtinger / http://gomo.se/
  1592. * @author egraether / http://egraether.com/
  1593. * @author WestLangley / http://github.com/WestLangley
  1594. */
  1595. THREE.Vector4 = function ( x, y, z, w ) {
  1596. this.x = x || 0;
  1597. this.y = y || 0;
  1598. this.z = z || 0;
  1599. this.w = ( w !== undefined ) ? w : 1;
  1600. };
  1601. THREE.Vector4.prototype = {
  1602. constructor: THREE.Vector4,
  1603. set: function ( x, y, z, w ) {
  1604. this.x = x;
  1605. this.y = y;
  1606. this.z = z;
  1607. this.w = w;
  1608. return this;
  1609. },
  1610. setScalar: function ( scalar ) {
  1611. this.x = scalar;
  1612. this.y = scalar;
  1613. this.z = scalar;
  1614. this.w = scalar;
  1615. return this;
  1616. },
  1617. setX: function ( x ) {
  1618. this.x = x;
  1619. return this;
  1620. },
  1621. setY: function ( y ) {
  1622. this.y = y;
  1623. return this;
  1624. },
  1625. setZ: function ( z ) {
  1626. this.z = z;
  1627. return this;
  1628. },
  1629. setW: function ( w ) {
  1630. this.w = w;
  1631. return this;
  1632. },
  1633. setComponent: function ( index, value ) {
  1634. switch ( index ) {
  1635. case 0: this.x = value; break;
  1636. case 1: this.y = value; break;
  1637. case 2: this.z = value; break;
  1638. case 3: this.w = value; break;
  1639. default: throw new Error( 'index is out of range: ' + index );
  1640. }
  1641. },
  1642. getComponent: function ( index ) {
  1643. switch ( index ) {
  1644. case 0: return this.x;
  1645. case 1: return this.y;
  1646. case 2: return this.z;
  1647. case 3: return this.w;
  1648. default: throw new Error( 'index is out of range: ' + index );
  1649. }
  1650. },
  1651. clone: function () {
  1652. return new this.constructor( this.x, this.y, this.z, this.w );
  1653. },
  1654. copy: function ( v ) {
  1655. this.x = v.x;
  1656. this.y = v.y;
  1657. this.z = v.z;
  1658. this.w = ( v.w !== undefined ) ? v.w : 1;
  1659. return this;
  1660. },
  1661. add: function ( v, w ) {
  1662. if ( w !== undefined ) {
  1663. console.warn( 'THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1664. return this.addVectors( v, w );
  1665. }
  1666. this.x += v.x;
  1667. this.y += v.y;
  1668. this.z += v.z;
  1669. this.w += v.w;
  1670. return this;
  1671. },
  1672. addScalar: function ( s ) {
  1673. this.x += s;
  1674. this.y += s;
  1675. this.z += s;
  1676. this.w += s;
  1677. return this;
  1678. },
  1679. addVectors: function ( a, b ) {
  1680. this.x = a.x + b.x;
  1681. this.y = a.y + b.y;
  1682. this.z = a.z + b.z;
  1683. this.w = a.w + b.w;
  1684. return this;
  1685. },
  1686. addScaledVector: function ( v, s ) {
  1687. this.x += v.x * s;
  1688. this.y += v.y * s;
  1689. this.z += v.z * s;
  1690. this.w += v.w * s;
  1691. return this;
  1692. },
  1693. sub: function ( v, w ) {
  1694. if ( w !== undefined ) {
  1695. console.warn( 'THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1696. return this.subVectors( v, w );
  1697. }
  1698. this.x -= v.x;
  1699. this.y -= v.y;
  1700. this.z -= v.z;
  1701. this.w -= v.w;
  1702. return this;
  1703. },
  1704. subScalar: function ( s ) {
  1705. this.x -= s;
  1706. this.y -= s;
  1707. this.z -= s;
  1708. this.w -= s;
  1709. return this;
  1710. },
  1711. subVectors: function ( a, b ) {
  1712. this.x = a.x - b.x;
  1713. this.y = a.y - b.y;
  1714. this.z = a.z - b.z;
  1715. this.w = a.w - b.w;
  1716. return this;
  1717. },
  1718. multiplyScalar: function ( scalar ) {
  1719. if ( isFinite( scalar ) ) {
  1720. this.x *= scalar;
  1721. this.y *= scalar;
  1722. this.z *= scalar;
  1723. this.w *= scalar;
  1724. } else {
  1725. this.x = 0;
  1726. this.y = 0;
  1727. this.z = 0;
  1728. this.w = 0;
  1729. }
  1730. return this;
  1731. },
  1732. applyMatrix4: function ( m ) {
  1733. var x = this.x;
  1734. var y = this.y;
  1735. var z = this.z;
  1736. var w = this.w;
  1737. var e = m.elements;
  1738. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  1739. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  1740. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  1741. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  1742. return this;
  1743. },
  1744. divideScalar: function ( scalar ) {
  1745. return this.multiplyScalar( 1 / scalar );
  1746. },
  1747. setAxisAngleFromQuaternion: function ( q ) {
  1748. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  1749. // q is assumed to be normalized
  1750. this.w = 2 * Math.acos( q.w );
  1751. var s = Math.sqrt( 1 - q.w * q.w );
  1752. if ( s < 0.0001 ) {
  1753. this.x = 1;
  1754. this.y = 0;
  1755. this.z = 0;
  1756. } else {
  1757. this.x = q.x / s;
  1758. this.y = q.y / s;
  1759. this.z = q.z / s;
  1760. }
  1761. return this;
  1762. },
  1763. setAxisAngleFromRotationMatrix: function ( m ) {
  1764. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  1765. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1766. var angle, x, y, z, // variables for result
  1767. epsilon = 0.01, // margin to allow for rounding errors
  1768. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  1769. te = m.elements,
  1770. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  1771. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  1772. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  1773. if ( ( Math.abs( m12 - m21 ) < epsilon )
  1774. && ( Math.abs( m13 - m31 ) < epsilon )
  1775. && ( Math.abs( m23 - m32 ) < epsilon ) ) {
  1776. // singularity found
  1777. // first check for identity matrix which must have +1 for all terms
  1778. // in leading diagonal and zero in other terms
  1779. if ( ( Math.abs( m12 + m21 ) < epsilon2 )
  1780. && ( Math.abs( m13 + m31 ) < epsilon2 )
  1781. && ( Math.abs( m23 + m32 ) < epsilon2 )
  1782. && ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  1783. // this singularity is identity matrix so angle = 0
  1784. this.set( 1, 0, 0, 0 );
  1785. return this; // zero angle, arbitrary axis
  1786. }
  1787. // otherwise this singularity is angle = 180
  1788. angle = Math.PI;
  1789. var xx = ( m11 + 1 ) / 2;
  1790. var yy = ( m22 + 1 ) / 2;
  1791. var zz = ( m33 + 1 ) / 2;
  1792. var xy = ( m12 + m21 ) / 4;
  1793. var xz = ( m13 + m31 ) / 4;
  1794. var yz = ( m23 + m32 ) / 4;
  1795. if ( ( xx > yy ) && ( xx > zz ) ) {
  1796. // m11 is the largest diagonal term
  1797. if ( xx < epsilon ) {
  1798. x = 0;
  1799. y = 0.707106781;
  1800. z = 0.707106781;
  1801. } else {
  1802. x = Math.sqrt( xx );
  1803. y = xy / x;
  1804. z = xz / x;
  1805. }
  1806. } else if ( yy > zz ) {
  1807. // m22 is the largest diagonal term
  1808. if ( yy < epsilon ) {
  1809. x = 0.707106781;
  1810. y = 0;
  1811. z = 0.707106781;
  1812. } else {
  1813. y = Math.sqrt( yy );
  1814. x = xy / y;
  1815. z = yz / y;
  1816. }
  1817. } else {
  1818. // m33 is the largest diagonal term so base result on this
  1819. if ( zz < epsilon ) {
  1820. x = 0.707106781;
  1821. y = 0.707106781;
  1822. z = 0;
  1823. } else {
  1824. z = Math.sqrt( zz );
  1825. x = xz / z;
  1826. y = yz / z;
  1827. }
  1828. }
  1829. this.set( x, y, z, angle );
  1830. return this; // return 180 deg rotation
  1831. }
  1832. // as we have reached here there are no singularities so we can handle normally
  1833. var s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 )
  1834. + ( m13 - m31 ) * ( m13 - m31 )
  1835. + ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  1836. if ( Math.abs( s ) < 0.001 ) s = 1;
  1837. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  1838. // caught by singularity test above, but I've left it in just in case
  1839. this.x = ( m32 - m23 ) / s;
  1840. this.y = ( m13 - m31 ) / s;
  1841. this.z = ( m21 - m12 ) / s;
  1842. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  1843. return this;
  1844. },
  1845. min: function ( v ) {
  1846. this.x = Math.min( this.x, v.x );
  1847. this.y = Math.min( this.y, v.y );
  1848. this.z = Math.min( this.z, v.z );
  1849. this.w = Math.min( this.w, v.w );
  1850. return this;
  1851. },
  1852. max: function ( v ) {
  1853. this.x = Math.max( this.x, v.x );
  1854. this.y = Math.max( this.y, v.y );
  1855. this.z = Math.max( this.z, v.z );
  1856. this.w = Math.max( this.w, v.w );
  1857. return this;
  1858. },
  1859. clamp: function ( min, max ) {
  1860. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1861. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1862. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1863. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  1864. this.w = Math.max( min.w, Math.min( max.w, this.w ) );
  1865. return this;
  1866. },
  1867. clampScalar: function () {
  1868. var min, max;
  1869. return function clampScalar( minVal, maxVal ) {
  1870. if ( min === undefined ) {
  1871. min = new THREE.Vector4();
  1872. max = new THREE.Vector4();
  1873. }
  1874. min.set( minVal, minVal, minVal, minVal );
  1875. max.set( maxVal, maxVal, maxVal, maxVal );
  1876. return this.clamp( min, max );
  1877. };
  1878. }(),
  1879. floor: function () {
  1880. this.x = Math.floor( this.x );
  1881. this.y = Math.floor( this.y );
  1882. this.z = Math.floor( this.z );
  1883. this.w = Math.floor( this.w );
  1884. return this;
  1885. },
  1886. ceil: function () {
  1887. this.x = Math.ceil( this.x );
  1888. this.y = Math.ceil( this.y );
  1889. this.z = Math.ceil( this.z );
  1890. this.w = Math.ceil( this.w );
  1891. return this;
  1892. },
  1893. round: function () {
  1894. this.x = Math.round( this.x );
  1895. this.y = Math.round( this.y );
  1896. this.z = Math.round( this.z );
  1897. this.w = Math.round( this.w );
  1898. return this;
  1899. },
  1900. roundToZero: function () {
  1901. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1902. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1903. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1904. this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
  1905. return this;
  1906. },
  1907. negate: function () {
  1908. this.x = - this.x;
  1909. this.y = - this.y;
  1910. this.z = - this.z;
  1911. this.w = - this.w;
  1912. return this;
  1913. },
  1914. dot: function ( v ) {
  1915. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  1916. },
  1917. lengthSq: function () {
  1918. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  1919. },
  1920. length: function () {
  1921. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  1922. },
  1923. lengthManhattan: function () {
  1924. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  1925. },
  1926. normalize: function () {
  1927. return this.divideScalar( this.length() );
  1928. },
  1929. setLength: function ( length ) {
  1930. return this.multiplyScalar( length / this.length() );
  1931. },
  1932. lerp: function ( v, alpha ) {
  1933. this.x += ( v.x - this.x ) * alpha;
  1934. this.y += ( v.y - this.y ) * alpha;
  1935. this.z += ( v.z - this.z ) * alpha;
  1936. this.w += ( v.w - this.w ) * alpha;
  1937. return this;
  1938. },
  1939. lerpVectors: function ( v1, v2, alpha ) {
  1940. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1941. return this;
  1942. },
  1943. equals: function ( v ) {
  1944. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  1945. },
  1946. fromArray: function ( array, offset ) {
  1947. if ( offset === undefined ) offset = 0;
  1948. this.x = array[ offset ];
  1949. this.y = array[ offset + 1 ];
  1950. this.z = array[ offset + 2 ];
  1951. this.w = array[ offset + 3 ];
  1952. return this;
  1953. },
  1954. toArray: function ( array, offset ) {
  1955. if ( array === undefined ) array = [];
  1956. if ( offset === undefined ) offset = 0;
  1957. array[ offset ] = this.x;
  1958. array[ offset + 1 ] = this.y;
  1959. array[ offset + 2 ] = this.z;
  1960. array[ offset + 3 ] = this.w;
  1961. return array;
  1962. },
  1963. fromAttribute: function ( attribute, index, offset ) {
  1964. if ( offset === undefined ) offset = 0;
  1965. index = index * attribute.itemSize + offset;
  1966. this.x = attribute.array[ index ];
  1967. this.y = attribute.array[ index + 1 ];
  1968. this.z = attribute.array[ index + 2 ];
  1969. this.w = attribute.array[ index + 3 ];
  1970. return this;
  1971. }
  1972. };
  1973. // File:src/math/Euler.js
  1974. /**
  1975. * @author mrdoob / http://mrdoob.com/
  1976. * @author WestLangley / http://github.com/WestLangley
  1977. * @author bhouston / http://clara.io
  1978. */
  1979. THREE.Euler = function ( x, y, z, order ) {
  1980. this._x = x || 0;
  1981. this._y = y || 0;
  1982. this._z = z || 0;
  1983. this._order = order || THREE.Euler.DefaultOrder;
  1984. };
  1985. THREE.Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
  1986. THREE.Euler.DefaultOrder = 'XYZ';
  1987. THREE.Euler.prototype = {
  1988. constructor: THREE.Euler,
  1989. get x () {
  1990. return this._x;
  1991. },
  1992. set x ( value ) {
  1993. this._x = value;
  1994. this.onChangeCallback();
  1995. },
  1996. get y () {
  1997. return this._y;
  1998. },
  1999. set y ( value ) {
  2000. this._y = value;
  2001. this.onChangeCallback();
  2002. },
  2003. get z () {
  2004. return this._z;
  2005. },
  2006. set z ( value ) {
  2007. this._z = value;
  2008. this.onChangeCallback();
  2009. },
  2010. get order () {
  2011. return this._order;
  2012. },
  2013. set order ( value ) {
  2014. this._order = value;
  2015. this.onChangeCallback();
  2016. },
  2017. set: function ( x, y, z, order ) {
  2018. this._x = x;
  2019. this._y = y;
  2020. this._z = z;
  2021. this._order = order || this._order;
  2022. this.onChangeCallback();
  2023. return this;
  2024. },
  2025. clone: function () {
  2026. return new this.constructor( this._x, this._y, this._z, this._order );
  2027. },
  2028. copy: function ( euler ) {
  2029. this._x = euler._x;
  2030. this._y = euler._y;
  2031. this._z = euler._z;
  2032. this._order = euler._order;
  2033. this.onChangeCallback();
  2034. return this;
  2035. },
  2036. setFromRotationMatrix: function ( m, order, update ) {
  2037. var clamp = THREE.Math.clamp;
  2038. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2039. var te = m.elements;
  2040. var m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  2041. var m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  2042. var m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  2043. order = order || this._order;
  2044. if ( order === 'XYZ' ) {
  2045. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  2046. if ( Math.abs( m13 ) < 0.99999 ) {
  2047. this._x = Math.atan2( - m23, m33 );
  2048. this._z = Math.atan2( - m12, m11 );
  2049. } else {
  2050. this._x = Math.atan2( m32, m22 );
  2051. this._z = 0;
  2052. }
  2053. } else if ( order === 'YXZ' ) {
  2054. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  2055. if ( Math.abs( m23 ) < 0.99999 ) {
  2056. this._y = Math.atan2( m13, m33 );
  2057. this._z = Math.atan2( m21, m22 );
  2058. } else {
  2059. this._y = Math.atan2( - m31, m11 );
  2060. this._z = 0;
  2061. }
  2062. } else if ( order === 'ZXY' ) {
  2063. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  2064. if ( Math.abs( m32 ) < 0.99999 ) {
  2065. this._y = Math.atan2( - m31, m33 );
  2066. this._z = Math.atan2( - m12, m22 );
  2067. } else {
  2068. this._y = 0;
  2069. this._z = Math.atan2( m21, m11 );
  2070. }
  2071. } else if ( order === 'ZYX' ) {
  2072. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  2073. if ( Math.abs( m31 ) < 0.99999 ) {
  2074. this._x = Math.atan2( m32, m33 );
  2075. this._z = Math.atan2( m21, m11 );
  2076. } else {
  2077. this._x = 0;
  2078. this._z = Math.atan2( - m12, m22 );
  2079. }
  2080. } else if ( order === 'YZX' ) {
  2081. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  2082. if ( Math.abs( m21 ) < 0.99999 ) {
  2083. this._x = Math.atan2( - m23, m22 );
  2084. this._y = Math.atan2( - m31, m11 );
  2085. } else {
  2086. this._x = 0;
  2087. this._y = Math.atan2( m13, m33 );
  2088. }
  2089. } else if ( order === 'XZY' ) {
  2090. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  2091. if ( Math.abs( m12 ) < 0.99999 ) {
  2092. this._x = Math.atan2( m32, m22 );
  2093. this._y = Math.atan2( m13, m11 );
  2094. } else {
  2095. this._x = Math.atan2( - m23, m33 );
  2096. this._y = 0;
  2097. }
  2098. } else {
  2099. console.warn( 'THREE.Euler: .setFromRotationMatrix() given unsupported order: ' + order )
  2100. }
  2101. this._order = order;
  2102. if ( update !== false ) this.onChangeCallback();
  2103. return this;
  2104. },
  2105. setFromQuaternion: function () {
  2106. var matrix;
  2107. return function ( q, order, update ) {
  2108. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  2109. matrix.makeRotationFromQuaternion( q );
  2110. this.setFromRotationMatrix( matrix, order, update );
  2111. return this;
  2112. };
  2113. }(),
  2114. setFromVector3: function ( v, order ) {
  2115. return this.set( v.x, v.y, v.z, order || this._order );
  2116. },
  2117. reorder: function () {
  2118. // WARNING: this discards revolution information -bhouston
  2119. var q = new THREE.Quaternion();
  2120. return function ( newOrder ) {
  2121. q.setFromEuler( this );
  2122. this.setFromQuaternion( q, newOrder );
  2123. };
  2124. }(),
  2125. equals: function ( euler ) {
  2126. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  2127. },
  2128. fromArray: function ( array ) {
  2129. this._x = array[ 0 ];
  2130. this._y = array[ 1 ];
  2131. this._z = array[ 2 ];
  2132. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  2133. this.onChangeCallback();
  2134. return this;
  2135. },
  2136. toArray: function ( array, offset ) {
  2137. if ( array === undefined ) array = [];
  2138. if ( offset === undefined ) offset = 0;
  2139. array[ offset ] = this._x;
  2140. array[ offset + 1 ] = this._y;
  2141. array[ offset + 2 ] = this._z;
  2142. array[ offset + 3 ] = this._order;
  2143. return array;
  2144. },
  2145. toVector3: function ( optionalResult ) {
  2146. if ( optionalResult ) {
  2147. return optionalResult.set( this._x, this._y, this._z );
  2148. } else {
  2149. return new THREE.Vector3( this._x, this._y, this._z );
  2150. }
  2151. },
  2152. onChange: function ( callback ) {
  2153. this.onChangeCallback = callback;
  2154. return this;
  2155. },
  2156. onChangeCallback: function () {}
  2157. };
  2158. // File:src/math/Line3.js
  2159. /**
  2160. * @author bhouston / http://clara.io
  2161. */
  2162. THREE.Line3 = function ( start, end ) {
  2163. this.start = ( start !== undefined ) ? start : new THREE.Vector3();
  2164. this.end = ( end !== undefined ) ? end : new THREE.Vector3();
  2165. };
  2166. THREE.Line3.prototype = {
  2167. constructor: THREE.Line3,
  2168. set: function ( start, end ) {
  2169. this.start.copy( start );
  2170. this.end.copy( end );
  2171. return this;
  2172. },
  2173. clone: function () {
  2174. return new this.constructor().copy( this );
  2175. },
  2176. copy: function ( line ) {
  2177. this.start.copy( line.start );
  2178. this.end.copy( line.end );
  2179. return this;
  2180. },
  2181. center: function ( optionalTarget ) {
  2182. var result = optionalTarget || new THREE.Vector3();
  2183. return result.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  2184. },
  2185. delta: function ( optionalTarget ) {
  2186. var result = optionalTarget || new THREE.Vector3();
  2187. return result.subVectors( this.end, this.start );
  2188. },
  2189. distanceSq: function () {
  2190. return this.start.distanceToSquared( this.end );
  2191. },
  2192. distance: function () {
  2193. return this.start.distanceTo( this.end );
  2194. },
  2195. at: function ( t, optionalTarget ) {
  2196. var result = optionalTarget || new THREE.Vector3();
  2197. return this.delta( result ).multiplyScalar( t ).add( this.start );
  2198. },
  2199. closestPointToPointParameter: function () {
  2200. var startP = new THREE.Vector3();
  2201. var startEnd = new THREE.Vector3();
  2202. return function ( point, clampToLine ) {
  2203. startP.subVectors( point, this.start );
  2204. startEnd.subVectors( this.end, this.start );
  2205. var startEnd2 = startEnd.dot( startEnd );
  2206. var startEnd_startP = startEnd.dot( startP );
  2207. var t = startEnd_startP / startEnd2;
  2208. if ( clampToLine ) {
  2209. t = THREE.Math.clamp( t, 0, 1 );
  2210. }
  2211. return t;
  2212. };
  2213. }(),
  2214. closestPointToPoint: function ( point, clampToLine, optionalTarget ) {
  2215. var t = this.closestPointToPointParameter( point, clampToLine );
  2216. var result = optionalTarget || new THREE.Vector3();
  2217. return this.delta( result ).multiplyScalar( t ).add( this.start );
  2218. },
  2219. applyMatrix4: function ( matrix ) {
  2220. this.start.applyMatrix4( matrix );
  2221. this.end.applyMatrix4( matrix );
  2222. return this;
  2223. },
  2224. equals: function ( line ) {
  2225. return line.start.equals( this.start ) && line.end.equals( this.end );
  2226. }
  2227. };
  2228. // File:src/math/Box2.js
  2229. /**
  2230. * @author bhouston / http://clara.io
  2231. */
  2232. THREE.Box2 = function ( min, max ) {
  2233. this.min = ( min !== undefined ) ? min : new THREE.Vector2( + Infinity, + Infinity );
  2234. this.max = ( max !== undefined ) ? max : new THREE.Vector2( - Infinity, - Infinity );
  2235. };
  2236. THREE.Box2.prototype = {
  2237. constructor: THREE.Box2,
  2238. set: function ( min, max ) {
  2239. this.min.copy( min );
  2240. this.max.copy( max );
  2241. return this;
  2242. },
  2243. setFromPoints: function ( points ) {
  2244. this.makeEmpty();
  2245. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2246. this.expandByPoint( points[ i ] );
  2247. }
  2248. return this;
  2249. },
  2250. setFromCenterAndSize: function () {
  2251. var v1 = new THREE.Vector2();
  2252. return function ( center, size ) {
  2253. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2254. this.min.copy( center ).sub( halfSize );
  2255. this.max.copy( center ).add( halfSize );
  2256. return this;
  2257. };
  2258. }(),
  2259. clone: function () {
  2260. return new this.constructor().copy( this );
  2261. },
  2262. copy: function ( box ) {
  2263. this.min.copy( box.min );
  2264. this.max.copy( box.max );
  2265. return this;
  2266. },
  2267. makeEmpty: function () {
  2268. this.min.x = this.min.y = + Infinity;
  2269. this.max.x = this.max.y = - Infinity;
  2270. return this;
  2271. },
  2272. isEmpty: function () {
  2273. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2274. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  2275. },
  2276. center: function ( optionalTarget ) {
  2277. var result = optionalTarget || new THREE.Vector2();
  2278. return result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2279. },
  2280. size: function ( optionalTarget ) {
  2281. var result = optionalTarget || new THREE.Vector2();
  2282. return result.subVectors( this.max, this.min );
  2283. },
  2284. expandByPoint: function ( point ) {
  2285. this.min.min( point );
  2286. this.max.max( point );
  2287. return this;
  2288. },
  2289. expandByVector: function ( vector ) {
  2290. this.min.sub( vector );
  2291. this.max.add( vector );
  2292. return this;
  2293. },
  2294. expandByScalar: function ( scalar ) {
  2295. this.min.addScalar( - scalar );
  2296. this.max.addScalar( scalar );
  2297. return this;
  2298. },
  2299. containsPoint: function ( point ) {
  2300. if ( point.x < this.min.x || point.x > this.max.x ||
  2301. point.y < this.min.y || point.y > this.max.y ) {
  2302. return false;
  2303. }
  2304. return true;
  2305. },
  2306. containsBox: function ( box ) {
  2307. if ( ( this.min.x <= box.min.x ) && ( box.max.x <= this.max.x ) &&
  2308. ( this.min.y <= box.min.y ) && ( box.max.y <= this.max.y ) ) {
  2309. return true;
  2310. }
  2311. return false;
  2312. },
  2313. getParameter: function ( point, optionalTarget ) {
  2314. // This can potentially have a divide by zero if the box
  2315. // has a size dimension of 0.
  2316. var result = optionalTarget || new THREE.Vector2();
  2317. return result.set(
  2318. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2319. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  2320. );
  2321. },
  2322. intersectsBox: function ( box ) {
  2323. // using 6 splitting planes to rule out intersections.
  2324. if ( box.max.x < this.min.x || box.min.x > this.max.x ||
  2325. box.max.y < this.min.y || box.min.y > this.max.y ) {
  2326. return false;
  2327. }
  2328. return true;
  2329. },
  2330. clampPoint: function ( point, optionalTarget ) {
  2331. var result = optionalTarget || new THREE.Vector2();
  2332. return result.copy( point ).clamp( this.min, this.max );
  2333. },
  2334. distanceToPoint: function () {
  2335. var v1 = new THREE.Vector2();
  2336. return function ( point ) {
  2337. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  2338. return clampedPoint.sub( point ).length();
  2339. };
  2340. }(),
  2341. intersect: function ( box ) {
  2342. this.min.max( box.min );
  2343. this.max.min( box.max );
  2344. return this;
  2345. },
  2346. union: function ( box ) {
  2347. this.min.min( box.min );
  2348. this.max.max( box.max );
  2349. return this;
  2350. },
  2351. translate: function ( offset ) {
  2352. this.min.add( offset );
  2353. this.max.add( offset );
  2354. return this;
  2355. },
  2356. equals: function ( box ) {
  2357. return box.min.equals( this.min ) && box.max.equals( this.max );
  2358. }
  2359. };
  2360. // File:src/math/Box3.js
  2361. /**
  2362. * @author bhouston / http://clara.io
  2363. * @author WestLangley / http://github.com/WestLangley
  2364. */
  2365. THREE.Box3 = function ( min, max ) {
  2366. this.min = ( min !== undefined ) ? min : new THREE.Vector3( + Infinity, + Infinity, + Infinity );
  2367. this.max = ( max !== undefined ) ? max : new THREE.Vector3( - Infinity, - Infinity, - Infinity );
  2368. };
  2369. THREE.Box3.prototype = {
  2370. constructor: THREE.Box3,
  2371. set: function ( min, max ) {
  2372. this.min.copy( min );
  2373. this.max.copy( max );
  2374. return this;
  2375. },
  2376. setFromArray: function ( array ) {
  2377. this.makeEmpty();
  2378. var minX = + Infinity;
  2379. var minY = + Infinity;
  2380. var minZ = + Infinity;
  2381. var maxX = - Infinity;
  2382. var maxY = - Infinity;
  2383. var maxZ = - Infinity;
  2384. for ( var i = 0, il = array.length; i < il; i += 3 ) {
  2385. var x = array[ i ];
  2386. var y = array[ i + 1 ];
  2387. var z = array[ i + 2 ];
  2388. if ( x < minX ) minX = x;
  2389. if ( y < minY ) minY = y;
  2390. if ( z < minZ ) minZ = z;
  2391. if ( x > maxX ) maxX = x;
  2392. if ( y > maxY ) maxY = y;
  2393. if ( z > maxZ ) maxZ = z;
  2394. }
  2395. this.min.set( minX, minY, minZ );
  2396. this.max.set( maxX, maxY, maxZ );
  2397. },
  2398. setFromPoints: function ( points ) {
  2399. this.makeEmpty();
  2400. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2401. this.expandByPoint( points[ i ] );
  2402. }
  2403. return this;
  2404. },
  2405. setFromCenterAndSize: function () {
  2406. var v1 = new THREE.Vector3();
  2407. return function ( center, size ) {
  2408. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2409. this.min.copy( center ).sub( halfSize );
  2410. this.max.copy( center ).add( halfSize );
  2411. return this;
  2412. };
  2413. }(),
  2414. setFromObject: function () {
  2415. // Computes the world-axis-aligned bounding box of an object (including its children),
  2416. // accounting for both the object's, and children's, world transforms
  2417. var v1 = new THREE.Vector3();
  2418. return function ( object ) {
  2419. var scope = this;
  2420. object.updateMatrixWorld( true );
  2421. this.makeEmpty();
  2422. object.traverse( function ( node ) {
  2423. var geometry = node.geometry;
  2424. if ( geometry !== undefined ) {
  2425. if ( geometry instanceof THREE.Geometry ) {
  2426. var vertices = geometry.vertices;
  2427. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  2428. v1.copy( vertices[ i ] );
  2429. v1.applyMatrix4( node.matrixWorld );
  2430. scope.expandByPoint( v1 );
  2431. }
  2432. } else if ( geometry instanceof THREE.BufferGeometry && geometry.attributes[ 'position' ] !== undefined ) {
  2433. var positions = geometry.attributes[ 'position' ].array;
  2434. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  2435. v1.fromArray( positions, i );
  2436. v1.applyMatrix4( node.matrixWorld );
  2437. scope.expandByPoint( v1 );
  2438. }
  2439. }
  2440. }
  2441. } );
  2442. return this;
  2443. };
  2444. }(),
  2445. clone: function () {
  2446. return new this.constructor().copy( this );
  2447. },
  2448. copy: function ( box ) {
  2449. this.min.copy( box.min );
  2450. this.max.copy( box.max );
  2451. return this;
  2452. },
  2453. makeEmpty: function () {
  2454. this.min.x = this.min.y = this.min.z = + Infinity;
  2455. this.max.x = this.max.y = this.max.z = - Infinity;
  2456. return this;
  2457. },
  2458. isEmpty: function () {
  2459. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2460. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  2461. },
  2462. center: function ( optionalTarget ) {
  2463. var result = optionalTarget || new THREE.Vector3();
  2464. return result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2465. },
  2466. size: function ( optionalTarget ) {
  2467. var result = optionalTarget || new THREE.Vector3();
  2468. return result.subVectors( this.max, this.min );
  2469. },
  2470. expandByPoint: function ( point ) {
  2471. this.min.min( point );
  2472. this.max.max( point );
  2473. return this;
  2474. },
  2475. expandByVector: function ( vector ) {
  2476. this.min.sub( vector );
  2477. this.max.add( vector );
  2478. return this;
  2479. },
  2480. expandByScalar: function ( scalar ) {
  2481. this.min.addScalar( - scalar );
  2482. this.max.addScalar( scalar );
  2483. return this;
  2484. },
  2485. containsPoint: function ( point ) {
  2486. if ( point.x < this.min.x || point.x > this.max.x ||
  2487. point.y < this.min.y || point.y > this.max.y ||
  2488. point.z < this.min.z || point.z > this.max.z ) {
  2489. return false;
  2490. }
  2491. return true;
  2492. },
  2493. containsBox: function ( box ) {
  2494. if ( ( this.min.x <= box.min.x ) && ( box.max.x <= this.max.x ) &&
  2495. ( this.min.y <= box.min.y ) && ( box.max.y <= this.max.y ) &&
  2496. ( this.min.z <= box.min.z ) && ( box.max.z <= this.max.z ) ) {
  2497. return true;
  2498. }
  2499. return false;
  2500. },
  2501. getParameter: function ( point, optionalTarget ) {
  2502. // This can potentially have a divide by zero if the box
  2503. // has a size dimension of 0.
  2504. var result = optionalTarget || new THREE.Vector3();
  2505. return result.set(
  2506. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2507. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  2508. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  2509. );
  2510. },
  2511. intersectsBox: function ( box ) {
  2512. // using 6 splitting planes to rule out intersections.
  2513. if ( box.max.x < this.min.x || box.min.x > this.max.x ||
  2514. box.max.y < this.min.y || box.min.y > this.max.y ||
  2515. box.max.z < this.min.z || box.min.z > this.max.z ) {
  2516. return false;
  2517. }
  2518. return true;
  2519. },
  2520. intersectsSphere: ( function () {
  2521. var closestPoint;
  2522. return function intersectsSphere( sphere ) {
  2523. if ( closestPoint === undefined ) closestPoint = new THREE.Vector3();
  2524. // Find the point on the AABB closest to the sphere center.
  2525. this.clampPoint( sphere.center, closestPoint );
  2526. // If that point is inside the sphere, the AABB and sphere intersect.
  2527. return closestPoint.distanceToSquared( sphere.center ) <= ( sphere.radius * sphere.radius );
  2528. };
  2529. } )(),
  2530. intersectsPlane: function ( plane ) {
  2531. // We compute the minimum and maximum dot product values. If those values
  2532. // are on the same side (back or front) of the plane, then there is no intersection.
  2533. var min, max;
  2534. if ( plane.normal.x > 0 ) {
  2535. min = plane.normal.x * this.min.x;
  2536. max = plane.normal.x * this.max.x;
  2537. } else {
  2538. min = plane.normal.x * this.max.x;
  2539. max = plane.normal.x * this.min.x;
  2540. }
  2541. if ( plane.normal.y > 0 ) {
  2542. min += plane.normal.y * this.min.y;
  2543. max += plane.normal.y * this.max.y;
  2544. } else {
  2545. min += plane.normal.y * this.max.y;
  2546. max += plane.normal.y * this.min.y;
  2547. }
  2548. if ( plane.normal.z > 0 ) {
  2549. min += plane.normal.z * this.min.z;
  2550. max += plane.normal.z * this.max.z;
  2551. } else {
  2552. min += plane.normal.z * this.max.z;
  2553. max += plane.normal.z * this.min.z;
  2554. }
  2555. return ( min <= plane.constant && max >= plane.constant );
  2556. },
  2557. clampPoint: function ( point, optionalTarget ) {
  2558. var result = optionalTarget || new THREE.Vector3();
  2559. return result.copy( point ).clamp( this.min, this.max );
  2560. },
  2561. distanceToPoint: function () {
  2562. var v1 = new THREE.Vector3();
  2563. return function ( point ) {
  2564. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  2565. return clampedPoint.sub( point ).length();
  2566. };
  2567. }(),
  2568. getBoundingSphere: function () {
  2569. var v1 = new THREE.Vector3();
  2570. return function ( optionalTarget ) {
  2571. var result = optionalTarget || new THREE.Sphere();
  2572. result.center = this.center();
  2573. result.radius = this.size( v1 ).length() * 0.5;
  2574. return result;
  2575. };
  2576. }(),
  2577. intersect: function ( box ) {
  2578. this.min.max( box.min );
  2579. this.max.min( box.max );
  2580. return this;
  2581. },
  2582. union: function ( box ) {
  2583. this.min.min( box.min );
  2584. this.max.max( box.max );
  2585. return this;
  2586. },
  2587. applyMatrix4: function () {
  2588. var points = [
  2589. new THREE.Vector3(),
  2590. new THREE.Vector3(),
  2591. new THREE.Vector3(),
  2592. new THREE.Vector3(),
  2593. new THREE.Vector3(),
  2594. new THREE.Vector3(),
  2595. new THREE.Vector3(),
  2596. new THREE.Vector3()
  2597. ];
  2598. return function ( matrix ) {
  2599. // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  2600. points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
  2601. points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
  2602. points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
  2603. points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
  2604. points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
  2605. points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
  2606. points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
  2607. points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
  2608. this.makeEmpty();
  2609. this.setFromPoints( points );
  2610. return this;
  2611. };
  2612. }(),
  2613. translate: function ( offset ) {
  2614. this.min.add( offset );
  2615. this.max.add( offset );
  2616. return this;
  2617. },
  2618. equals: function ( box ) {
  2619. return box.min.equals( this.min ) && box.max.equals( this.max );
  2620. }
  2621. };
  2622. // File:src/math/Matrix3.js
  2623. /**
  2624. * @author alteredq / http://alteredqualia.com/
  2625. * @author WestLangley / http://github.com/WestLangley
  2626. * @author bhouston / http://clara.io
  2627. * @author tschw
  2628. */
  2629. THREE.Matrix3 = function () {
  2630. this.elements = new Float32Array( [
  2631. 1, 0, 0,
  2632. 0, 1, 0,
  2633. 0, 0, 1
  2634. ] );
  2635. if ( arguments.length > 0 ) {
  2636. console.error( 'THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.' );
  2637. }
  2638. };
  2639. THREE.Matrix3.prototype = {
  2640. constructor: THREE.Matrix3,
  2641. set: function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  2642. var te = this.elements;
  2643. te[ 0 ] = n11; te[ 1 ] = n21; te[ 2 ] = n31;
  2644. te[ 3 ] = n12; te[ 4 ] = n22; te[ 5 ] = n32;
  2645. te[ 6 ] = n13; te[ 7 ] = n23; te[ 8 ] = n33;
  2646. return this;
  2647. },
  2648. identity: function () {
  2649. this.set(
  2650. 1, 0, 0,
  2651. 0, 1, 0,
  2652. 0, 0, 1
  2653. );
  2654. return this;
  2655. },
  2656. clone: function () {
  2657. return new this.constructor().fromArray( this.elements );
  2658. },
  2659. copy: function ( m ) {
  2660. var me = m.elements;
  2661. this.set(
  2662. me[ 0 ], me[ 3 ], me[ 6 ],
  2663. me[ 1 ], me[ 4 ], me[ 7 ],
  2664. me[ 2 ], me[ 5 ], me[ 8 ]
  2665. );
  2666. return this;
  2667. },
  2668. setFromMatrix4: function( m ) {
  2669. var me = m.elements;
  2670. this.set(
  2671. me[ 0 ], me[ 4 ], me[ 8 ],
  2672. me[ 1 ], me[ 5 ], me[ 9 ],
  2673. me[ 2 ], me[ 6 ], me[ 10 ]
  2674. );
  2675. return this;
  2676. },
  2677. applyToVector3Array: function () {
  2678. var v1;
  2679. return function ( array, offset, length ) {
  2680. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2681. if ( offset === undefined ) offset = 0;
  2682. if ( length === undefined ) length = array.length;
  2683. for ( var i = 0, j = offset; i < length; i += 3, j += 3 ) {
  2684. v1.fromArray( array, j );
  2685. v1.applyMatrix3( this );
  2686. v1.toArray( array, j );
  2687. }
  2688. return array;
  2689. };
  2690. }(),
  2691. applyToBuffer: function () {
  2692. var v1;
  2693. return function applyToBuffer( buffer, offset, length ) {
  2694. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2695. if ( offset === undefined ) offset = 0;
  2696. if ( length === undefined ) length = buffer.length / buffer.itemSize;
  2697. for ( var i = 0, j = offset; i < length; i ++, j ++ ) {
  2698. v1.x = buffer.getX( j );
  2699. v1.y = buffer.getY( j );
  2700. v1.z = buffer.getZ( j );
  2701. v1.applyMatrix3( this );
  2702. buffer.setXYZ( v1.x, v1.y, v1.z );
  2703. }
  2704. return buffer;
  2705. };
  2706. }(),
  2707. multiplyScalar: function ( s ) {
  2708. var te = this.elements;
  2709. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  2710. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  2711. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  2712. return this;
  2713. },
  2714. determinant: function () {
  2715. var te = this.elements;
  2716. var a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  2717. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  2718. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  2719. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  2720. },
  2721. getInverse: function ( matrix, throwOnDegenerate ) {
  2722. if ( matrix instanceof THREE.Matrix4 ) {
  2723. console.warn( "THREE.Matrix3.getInverse no longer takes a Matrix4 argument." );
  2724. }
  2725. var me = matrix.elements,
  2726. te = this.elements,
  2727. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ],
  2728. n12 = me[ 3 ], n22 = me[ 4 ], n32 = me[ 5 ],
  2729. n13 = me[ 6 ], n23 = me[ 7 ], n33 = me[ 8 ],
  2730. t11 = n33 * n22 - n32 * n23,
  2731. t12 = n32 * n13 - n33 * n12,
  2732. t13 = n23 * n12 - n22 * n13,
  2733. det = n11 * t11 + n21 * t12 + n31 * t13;
  2734. if ( det === 0 ) {
  2735. var msg = "THREE.Matrix3.getInverse(): can't invert matrix, determinant is 0";
  2736. if ( throwOnDegenerate || false ) {
  2737. throw new Error( msg );
  2738. } else {
  2739. console.warn( msg );
  2740. }
  2741. return this.identity();
  2742. }
  2743. te[ 0 ] = t11;
  2744. te[ 1 ] = n31 * n23 - n33 * n21;
  2745. te[ 2 ] = n32 * n21 - n31 * n22;
  2746. te[ 3 ] = t12;
  2747. te[ 4 ] = n33 * n11 - n31 * n13;
  2748. te[ 5 ] = n31 * n12 - n32 * n11;
  2749. te[ 6 ] = t13;
  2750. te[ 7 ] = n21 * n13 - n23 * n11;
  2751. te[ 8 ] = n22 * n11 - n21 * n12;
  2752. return this.multiplyScalar( 1 / det );
  2753. },
  2754. transpose: function () {
  2755. var tmp, m = this.elements;
  2756. tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
  2757. tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
  2758. tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
  2759. return this;
  2760. },
  2761. flattenToArrayOffset: function ( array, offset ) {
  2762. var te = this.elements;
  2763. array[ offset ] = te[ 0 ];
  2764. array[ offset + 1 ] = te[ 1 ];
  2765. array[ offset + 2 ] = te[ 2 ];
  2766. array[ offset + 3 ] = te[ 3 ];
  2767. array[ offset + 4 ] = te[ 4 ];
  2768. array[ offset + 5 ] = te[ 5 ];
  2769. array[ offset + 6 ] = te[ 6 ];
  2770. array[ offset + 7 ] = te[ 7 ];
  2771. array[ offset + 8 ] = te[ 8 ];
  2772. return array;
  2773. },
  2774. getNormalMatrix: function ( matrix4 ) {
  2775. return this.setFromMatrix4( matrix4 ).getInverse( this ).transpose();
  2776. },
  2777. transposeIntoArray: function ( r ) {
  2778. var m = this.elements;
  2779. r[ 0 ] = m[ 0 ];
  2780. r[ 1 ] = m[ 3 ];
  2781. r[ 2 ] = m[ 6 ];
  2782. r[ 3 ] = m[ 1 ];
  2783. r[ 4 ] = m[ 4 ];
  2784. r[ 5 ] = m[ 7 ];
  2785. r[ 6 ] = m[ 2 ];
  2786. r[ 7 ] = m[ 5 ];
  2787. r[ 8 ] = m[ 8 ];
  2788. return this;
  2789. },
  2790. fromArray: function ( array ) {
  2791. this.elements.set( array );
  2792. return this;
  2793. },
  2794. toArray: function () {
  2795. var te = this.elements;
  2796. return [
  2797. te[ 0 ], te[ 1 ], te[ 2 ],
  2798. te[ 3 ], te[ 4 ], te[ 5 ],
  2799. te[ 6 ], te[ 7 ], te[ 8 ]
  2800. ];
  2801. }
  2802. };
  2803. // File:src/math/Matrix4.js
  2804. /**
  2805. * @author mrdoob / http://mrdoob.com/
  2806. * @author supereggbert / http://www.paulbrunt.co.uk/
  2807. * @author philogb / http://blog.thejit.org/
  2808. * @author jordi_ros / http://plattsoft.com
  2809. * @author D1plo1d / http://github.com/D1plo1d
  2810. * @author alteredq / http://alteredqualia.com/
  2811. * @author mikael emtinger / http://gomo.se/
  2812. * @author timknip / http://www.floorplanner.com/
  2813. * @author bhouston / http://clara.io
  2814. * @author WestLangley / http://github.com/WestLangley
  2815. */
  2816. THREE.Matrix4 = function () {
  2817. this.elements = new Float32Array( [
  2818. 1, 0, 0, 0,
  2819. 0, 1, 0, 0,
  2820. 0, 0, 1, 0,
  2821. 0, 0, 0, 1
  2822. ] );
  2823. if ( arguments.length > 0 ) {
  2824. console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' );
  2825. }
  2826. };
  2827. THREE.Matrix4.prototype = {
  2828. constructor: THREE.Matrix4,
  2829. set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  2830. var te = this.elements;
  2831. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  2832. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  2833. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  2834. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  2835. return this;
  2836. },
  2837. identity: function () {
  2838. this.set(
  2839. 1, 0, 0, 0,
  2840. 0, 1, 0, 0,
  2841. 0, 0, 1, 0,
  2842. 0, 0, 0, 1
  2843. );
  2844. return this;
  2845. },
  2846. clone: function () {
  2847. return new THREE.Matrix4().fromArray( this.elements );
  2848. },
  2849. copy: function ( m ) {
  2850. this.elements.set( m.elements );
  2851. return this;
  2852. },
  2853. copyPosition: function ( m ) {
  2854. var te = this.elements;
  2855. var me = m.elements;
  2856. te[ 12 ] = me[ 12 ];
  2857. te[ 13 ] = me[ 13 ];
  2858. te[ 14 ] = me[ 14 ];
  2859. return this;
  2860. },
  2861. extractBasis: function ( xAxis, yAxis, zAxis ) {
  2862. xAxis.setFromMatrixColumn( this, 0 );
  2863. yAxis.setFromMatrixColumn( this, 1 );
  2864. zAxis.setFromMatrixColumn( this, 2 );
  2865. return this;
  2866. },
  2867. makeBasis: function ( xAxis, yAxis, zAxis ) {
  2868. this.set(
  2869. xAxis.x, yAxis.x, zAxis.x, 0,
  2870. xAxis.y, yAxis.y, zAxis.y, 0,
  2871. xAxis.z, yAxis.z, zAxis.z, 0,
  2872. 0, 0, 0, 1
  2873. );
  2874. return this;
  2875. },
  2876. extractRotation: function () {
  2877. var v1;
  2878. return function ( m ) {
  2879. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2880. var te = this.elements;
  2881. var me = m.elements;
  2882. var scaleX = 1 / v1.setFromMatrixColumn( m, 0 ).length();
  2883. var scaleY = 1 / v1.setFromMatrixColumn( m, 1 ).length();
  2884. var scaleZ = 1 / v1.setFromMatrixColumn( m, 2 ).length();
  2885. te[ 0 ] = me[ 0 ] * scaleX;
  2886. te[ 1 ] = me[ 1 ] * scaleX;
  2887. te[ 2 ] = me[ 2 ] * scaleX;
  2888. te[ 4 ] = me[ 4 ] * scaleY;
  2889. te[ 5 ] = me[ 5 ] * scaleY;
  2890. te[ 6 ] = me[ 6 ] * scaleY;
  2891. te[ 8 ] = me[ 8 ] * scaleZ;
  2892. te[ 9 ] = me[ 9 ] * scaleZ;
  2893. te[ 10 ] = me[ 10 ] * scaleZ;
  2894. return this;
  2895. };
  2896. }(),
  2897. makeRotationFromEuler: function ( euler ) {
  2898. if ( euler instanceof THREE.Euler === false ) {
  2899. console.error( 'THREE.Matrix: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  2900. }
  2901. var te = this.elements;
  2902. var x = euler.x, y = euler.y, z = euler.z;
  2903. var a = Math.cos( x ), b = Math.sin( x );
  2904. var c = Math.cos( y ), d = Math.sin( y );
  2905. var e = Math.cos( z ), f = Math.sin( z );
  2906. if ( euler.order === 'XYZ' ) {
  2907. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2908. te[ 0 ] = c * e;
  2909. te[ 4 ] = - c * f;
  2910. te[ 8 ] = d;
  2911. te[ 1 ] = af + be * d;
  2912. te[ 5 ] = ae - bf * d;
  2913. te[ 9 ] = - b * c;
  2914. te[ 2 ] = bf - ae * d;
  2915. te[ 6 ] = be + af * d;
  2916. te[ 10 ] = a * c;
  2917. } else if ( euler.order === 'YXZ' ) {
  2918. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2919. te[ 0 ] = ce + df * b;
  2920. te[ 4 ] = de * b - cf;
  2921. te[ 8 ] = a * d;
  2922. te[ 1 ] = a * f;
  2923. te[ 5 ] = a * e;
  2924. te[ 9 ] = - b;
  2925. te[ 2 ] = cf * b - de;
  2926. te[ 6 ] = df + ce * b;
  2927. te[ 10 ] = a * c;
  2928. } else if ( euler.order === 'ZXY' ) {
  2929. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2930. te[ 0 ] = ce - df * b;
  2931. te[ 4 ] = - a * f;
  2932. te[ 8 ] = de + cf * b;
  2933. te[ 1 ] = cf + de * b;
  2934. te[ 5 ] = a * e;
  2935. te[ 9 ] = df - ce * b;
  2936. te[ 2 ] = - a * d;
  2937. te[ 6 ] = b;
  2938. te[ 10 ] = a * c;
  2939. } else if ( euler.order === 'ZYX' ) {
  2940. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2941. te[ 0 ] = c * e;
  2942. te[ 4 ] = be * d - af;
  2943. te[ 8 ] = ae * d + bf;
  2944. te[ 1 ] = c * f;
  2945. te[ 5 ] = bf * d + ae;
  2946. te[ 9 ] = af * d - be;
  2947. te[ 2 ] = - d;
  2948. te[ 6 ] = b * c;
  2949. te[ 10 ] = a * c;
  2950. } else if ( euler.order === 'YZX' ) {
  2951. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2952. te[ 0 ] = c * e;
  2953. te[ 4 ] = bd - ac * f;
  2954. te[ 8 ] = bc * f + ad;
  2955. te[ 1 ] = f;
  2956. te[ 5 ] = a * e;
  2957. te[ 9 ] = - b * e;
  2958. te[ 2 ] = - d * e;
  2959. te[ 6 ] = ad * f + bc;
  2960. te[ 10 ] = ac - bd * f;
  2961. } else if ( euler.order === 'XZY' ) {
  2962. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2963. te[ 0 ] = c * e;
  2964. te[ 4 ] = - f;
  2965. te[ 8 ] = d * e;
  2966. te[ 1 ] = ac * f + bd;
  2967. te[ 5 ] = a * e;
  2968. te[ 9 ] = ad * f - bc;
  2969. te[ 2 ] = bc * f - ad;
  2970. te[ 6 ] = b * e;
  2971. te[ 10 ] = bd * f + ac;
  2972. }
  2973. // last column
  2974. te[ 3 ] = 0;
  2975. te[ 7 ] = 0;
  2976. te[ 11 ] = 0;
  2977. // bottom row
  2978. te[ 12 ] = 0;
  2979. te[ 13 ] = 0;
  2980. te[ 14 ] = 0;
  2981. te[ 15 ] = 1;
  2982. return this;
  2983. },
  2984. makeRotationFromQuaternion: function ( q ) {
  2985. var te = this.elements;
  2986. var x = q.x, y = q.y, z = q.z, w = q.w;
  2987. var x2 = x + x, y2 = y + y, z2 = z + z;
  2988. var xx = x * x2, xy = x * y2, xz = x * z2;
  2989. var yy = y * y2, yz = y * z2, zz = z * z2;
  2990. var wx = w * x2, wy = w * y2, wz = w * z2;
  2991. te[ 0 ] = 1 - ( yy + zz );
  2992. te[ 4 ] = xy - wz;
  2993. te[ 8 ] = xz + wy;
  2994. te[ 1 ] = xy + wz;
  2995. te[ 5 ] = 1 - ( xx + zz );
  2996. te[ 9 ] = yz - wx;
  2997. te[ 2 ] = xz - wy;
  2998. te[ 6 ] = yz + wx;
  2999. te[ 10 ] = 1 - ( xx + yy );
  3000. // last column
  3001. te[ 3 ] = 0;
  3002. te[ 7 ] = 0;
  3003. te[ 11 ] = 0;
  3004. // bottom row
  3005. te[ 12 ] = 0;
  3006. te[ 13 ] = 0;
  3007. te[ 14 ] = 0;
  3008. te[ 15 ] = 1;
  3009. return this;
  3010. },
  3011. lookAt: function () {
  3012. var x, y, z;
  3013. return function ( eye, target, up ) {
  3014. if ( x === undefined ) x = new THREE.Vector3();
  3015. if ( y === undefined ) y = new THREE.Vector3();
  3016. if ( z === undefined ) z = new THREE.Vector3();
  3017. var te = this.elements;
  3018. z.subVectors( eye, target ).normalize();
  3019. if ( z.lengthSq() === 0 ) {
  3020. z.z = 1;
  3021. }
  3022. x.crossVectors( up, z ).normalize();
  3023. if ( x.lengthSq() === 0 ) {
  3024. z.x += 0.0001;
  3025. x.crossVectors( up, z ).normalize();
  3026. }
  3027. y.crossVectors( z, x );
  3028. te[ 0 ] = x.x; te[ 4 ] = y.x; te[ 8 ] = z.x;
  3029. te[ 1 ] = x.y; te[ 5 ] = y.y; te[ 9 ] = z.y;
  3030. te[ 2 ] = x.z; te[ 6 ] = y.z; te[ 10 ] = z.z;
  3031. return this;
  3032. };
  3033. }(),
  3034. multiply: function ( m, n ) {
  3035. if ( n !== undefined ) {
  3036. console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' );
  3037. return this.multiplyMatrices( m, n );
  3038. }
  3039. return this.multiplyMatrices( this, m );
  3040. },
  3041. multiplyMatrices: function ( a, b ) {
  3042. var ae = a.elements;
  3043. var be = b.elements;
  3044. var te = this.elements;
  3045. var a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  3046. var a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  3047. var a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  3048. var a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  3049. var b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  3050. var b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  3051. var b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  3052. var b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  3053. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  3054. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  3055. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  3056. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  3057. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  3058. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  3059. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  3060. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  3061. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  3062. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  3063. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  3064. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  3065. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  3066. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  3067. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  3068. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  3069. return this;
  3070. },
  3071. multiplyToArray: function ( a, b, r ) {
  3072. var te = this.elements;
  3073. this.multiplyMatrices( a, b );
  3074. r[ 0 ] = te[ 0 ]; r[ 1 ] = te[ 1 ]; r[ 2 ] = te[ 2 ]; r[ 3 ] = te[ 3 ];
  3075. r[ 4 ] = te[ 4 ]; r[ 5 ] = te[ 5 ]; r[ 6 ] = te[ 6 ]; r[ 7 ] = te[ 7 ];
  3076. r[ 8 ] = te[ 8 ]; r[ 9 ] = te[ 9 ]; r[ 10 ] = te[ 10 ]; r[ 11 ] = te[ 11 ];
  3077. r[ 12 ] = te[ 12 ]; r[ 13 ] = te[ 13 ]; r[ 14 ] = te[ 14 ]; r[ 15 ] = te[ 15 ];
  3078. return this;
  3079. },
  3080. multiplyScalar: function ( s ) {
  3081. var te = this.elements;
  3082. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  3083. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  3084. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  3085. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  3086. return this;
  3087. },
  3088. applyToVector3Array: function () {
  3089. var v1;
  3090. return function ( array, offset, length ) {
  3091. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3092. if ( offset === undefined ) offset = 0;
  3093. if ( length === undefined ) length = array.length;
  3094. for ( var i = 0, j = offset; i < length; i += 3, j += 3 ) {
  3095. v1.fromArray( array, j );
  3096. v1.applyMatrix4( this );
  3097. v1.toArray( array, j );
  3098. }
  3099. return array;
  3100. };
  3101. }(),
  3102. applyToBuffer: function () {
  3103. var v1;
  3104. return function applyToBuffer( buffer, offset, length ) {
  3105. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3106. if ( offset === undefined ) offset = 0;
  3107. if ( length === undefined ) length = buffer.length / buffer.itemSize;
  3108. for ( var i = 0, j = offset; i < length; i ++, j ++ ) {
  3109. v1.x = buffer.getX( j );
  3110. v1.y = buffer.getY( j );
  3111. v1.z = buffer.getZ( j );
  3112. v1.applyMatrix4( this );
  3113. buffer.setXYZ( v1.x, v1.y, v1.z );
  3114. }
  3115. return buffer;
  3116. };
  3117. }(),
  3118. determinant: function () {
  3119. var te = this.elements;
  3120. var n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  3121. var n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  3122. var n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  3123. var n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  3124. //TODO: make this more efficient
  3125. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  3126. return (
  3127. n41 * (
  3128. + n14 * n23 * n32
  3129. - n13 * n24 * n32
  3130. - n14 * n22 * n33
  3131. + n12 * n24 * n33
  3132. + n13 * n22 * n34
  3133. - n12 * n23 * n34
  3134. ) +
  3135. n42 * (
  3136. + n11 * n23 * n34
  3137. - n11 * n24 * n33
  3138. + n14 * n21 * n33
  3139. - n13 * n21 * n34
  3140. + n13 * n24 * n31
  3141. - n14 * n23 * n31
  3142. ) +
  3143. n43 * (
  3144. + n11 * n24 * n32
  3145. - n11 * n22 * n34
  3146. - n14 * n21 * n32
  3147. + n12 * n21 * n34
  3148. + n14 * n22 * n31
  3149. - n12 * n24 * n31
  3150. ) +
  3151. n44 * (
  3152. - n13 * n22 * n31
  3153. - n11 * n23 * n32
  3154. + n11 * n22 * n33
  3155. + n13 * n21 * n32
  3156. - n12 * n21 * n33
  3157. + n12 * n23 * n31
  3158. )
  3159. );
  3160. },
  3161. transpose: function () {
  3162. var te = this.elements;
  3163. var tmp;
  3164. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  3165. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  3166. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  3167. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  3168. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  3169. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  3170. return this;
  3171. },
  3172. flattenToArrayOffset: function ( array, offset ) {
  3173. var te = this.elements;
  3174. array[ offset ] = te[ 0 ];
  3175. array[ offset + 1 ] = te[ 1 ];
  3176. array[ offset + 2 ] = te[ 2 ];
  3177. array[ offset + 3 ] = te[ 3 ];
  3178. array[ offset + 4 ] = te[ 4 ];
  3179. array[ offset + 5 ] = te[ 5 ];
  3180. array[ offset + 6 ] = te[ 6 ];
  3181. array[ offset + 7 ] = te[ 7 ];
  3182. array[ offset + 8 ] = te[ 8 ];
  3183. array[ offset + 9 ] = te[ 9 ];
  3184. array[ offset + 10 ] = te[ 10 ];
  3185. array[ offset + 11 ] = te[ 11 ];
  3186. array[ offset + 12 ] = te[ 12 ];
  3187. array[ offset + 13 ] = te[ 13 ];
  3188. array[ offset + 14 ] = te[ 14 ];
  3189. array[ offset + 15 ] = te[ 15 ];
  3190. return array;
  3191. },
  3192. getPosition: function () {
  3193. var v1;
  3194. return function () {
  3195. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3196. console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
  3197. return v1.setFromMatrixColumn( this, 3 );
  3198. };
  3199. }(),
  3200. setPosition: function ( v ) {
  3201. var te = this.elements;
  3202. te[ 12 ] = v.x;
  3203. te[ 13 ] = v.y;
  3204. te[ 14 ] = v.z;
  3205. return this;
  3206. },
  3207. getInverse: function ( m, throwOnDegenerate ) {
  3208. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  3209. var te = this.elements,
  3210. me = m.elements,
  3211. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ], n41 = me[ 3 ],
  3212. n12 = me[ 4 ], n22 = me[ 5 ], n32 = me[ 6 ], n42 = me[ 7 ],
  3213. n13 = me[ 8 ], n23 = me[ 9 ], n33 = me[ 10 ], n43 = me[ 11 ],
  3214. n14 = me[ 12 ], n24 = me[ 13 ], n34 = me[ 14 ], n44 = me[ 15 ],
  3215. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  3216. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  3217. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  3218. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  3219. var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  3220. if ( det === 0 ) {
  3221. var msg = "THREE.Matrix4.getInverse(): can't invert matrix, determinant is 0";
  3222. if ( throwOnDegenerate || false ) {
  3223. throw new Error( msg );
  3224. } else {
  3225. console.warn( msg );
  3226. }
  3227. return this.identity();
  3228. }
  3229. te[ 0 ] = t11;
  3230. te[ 1 ] = n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44;
  3231. te[ 2 ] = n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44;
  3232. te[ 3 ] = n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43;
  3233. te[ 4 ] = t12;
  3234. te[ 5 ] = n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44;
  3235. te[ 6 ] = n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44;
  3236. te[ 7 ] = n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43;
  3237. te[ 8 ] = t13;
  3238. te[ 9 ] = n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44;
  3239. te[ 10 ] = n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44;
  3240. te[ 11 ] = n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43;
  3241. te[ 12 ] = t14;
  3242. te[ 13 ] = n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34;
  3243. te[ 14 ] = n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34;
  3244. te[ 15 ] = n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33;
  3245. return this.multiplyScalar( 1 / det );
  3246. },
  3247. scale: function ( v ) {
  3248. var te = this.elements;
  3249. var x = v.x, y = v.y, z = v.z;
  3250. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  3251. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  3252. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  3253. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  3254. return this;
  3255. },
  3256. getMaxScaleOnAxis: function () {
  3257. var te = this.elements;
  3258. var scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  3259. var scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  3260. var scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  3261. return Math.sqrt( Math.max( scaleXSq, scaleYSq, scaleZSq ) );
  3262. },
  3263. makeTranslation: function ( x, y, z ) {
  3264. this.set(
  3265. 1, 0, 0, x,
  3266. 0, 1, 0, y,
  3267. 0, 0, 1, z,
  3268. 0, 0, 0, 1
  3269. );
  3270. return this;
  3271. },
  3272. makeRotationX: function ( theta ) {
  3273. var c = Math.cos( theta ), s = Math.sin( theta );
  3274. this.set(
  3275. 1, 0, 0, 0,
  3276. 0, c, - s, 0,
  3277. 0, s, c, 0,
  3278. 0, 0, 0, 1
  3279. );
  3280. return this;
  3281. },
  3282. makeRotationY: function ( theta ) {
  3283. var c = Math.cos( theta ), s = Math.sin( theta );
  3284. this.set(
  3285. c, 0, s, 0,
  3286. 0, 1, 0, 0,
  3287. - s, 0, c, 0,
  3288. 0, 0, 0, 1
  3289. );
  3290. return this;
  3291. },
  3292. makeRotationZ: function ( theta ) {
  3293. var c = Math.cos( theta ), s = Math.sin( theta );
  3294. this.set(
  3295. c, - s, 0, 0,
  3296. s, c, 0, 0,
  3297. 0, 0, 1, 0,
  3298. 0, 0, 0, 1
  3299. );
  3300. return this;
  3301. },
  3302. makeRotationAxis: function ( axis, angle ) {
  3303. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  3304. var c = Math.cos( angle );
  3305. var s = Math.sin( angle );
  3306. var t = 1 - c;
  3307. var x = axis.x, y = axis.y, z = axis.z;
  3308. var tx = t * x, ty = t * y;
  3309. this.set(
  3310. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  3311. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  3312. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  3313. 0, 0, 0, 1
  3314. );
  3315. return this;
  3316. },
  3317. makeScale: function ( x, y, z ) {
  3318. this.set(
  3319. x, 0, 0, 0,
  3320. 0, y, 0, 0,
  3321. 0, 0, z, 0,
  3322. 0, 0, 0, 1
  3323. );
  3324. return this;
  3325. },
  3326. compose: function ( position, quaternion, scale ) {
  3327. this.makeRotationFromQuaternion( quaternion );
  3328. this.scale( scale );
  3329. this.setPosition( position );
  3330. return this;
  3331. },
  3332. decompose: function () {
  3333. var vector, matrix;
  3334. return function ( position, quaternion, scale ) {
  3335. if ( vector === undefined ) vector = new THREE.Vector3();
  3336. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  3337. var te = this.elements;
  3338. var sx = vector.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  3339. var sy = vector.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  3340. var sz = vector.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  3341. // if determine is negative, we need to invert one scale
  3342. var det = this.determinant();
  3343. if ( det < 0 ) {
  3344. sx = - sx;
  3345. }
  3346. position.x = te[ 12 ];
  3347. position.y = te[ 13 ];
  3348. position.z = te[ 14 ];
  3349. // scale the rotation part
  3350. matrix.elements.set( this.elements ); // at this point matrix is incomplete so we can't use .copy()
  3351. var invSX = 1 / sx;
  3352. var invSY = 1 / sy;
  3353. var invSZ = 1 / sz;
  3354. matrix.elements[ 0 ] *= invSX;
  3355. matrix.elements[ 1 ] *= invSX;
  3356. matrix.elements[ 2 ] *= invSX;
  3357. matrix.elements[ 4 ] *= invSY;
  3358. matrix.elements[ 5 ] *= invSY;
  3359. matrix.elements[ 6 ] *= invSY;
  3360. matrix.elements[ 8 ] *= invSZ;
  3361. matrix.elements[ 9 ] *= invSZ;
  3362. matrix.elements[ 10 ] *= invSZ;
  3363. quaternion.setFromRotationMatrix( matrix );
  3364. scale.x = sx;
  3365. scale.y = sy;
  3366. scale.z = sz;
  3367. return this;
  3368. };
  3369. }(),
  3370. makeFrustum: function ( left, right, bottom, top, near, far ) {
  3371. var te = this.elements;
  3372. var x = 2 * near / ( right - left );
  3373. var y = 2 * near / ( top - bottom );
  3374. var a = ( right + left ) / ( right - left );
  3375. var b = ( top + bottom ) / ( top - bottom );
  3376. var c = - ( far + near ) / ( far - near );
  3377. var d = - 2 * far * near / ( far - near );
  3378. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  3379. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  3380. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  3381. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  3382. return this;
  3383. },
  3384. makePerspective: function ( fov, aspect, near, far ) {
  3385. var ymax = near * Math.tan( THREE.Math.degToRad( fov * 0.5 ) );
  3386. var ymin = - ymax;
  3387. var xmin = ymin * aspect;
  3388. var xmax = ymax * aspect;
  3389. return this.makeFrustum( xmin, xmax, ymin, ymax, near, far );
  3390. },
  3391. makeOrthographic: function ( left, right, top, bottom, near, far ) {
  3392. var te = this.elements;
  3393. var w = 1.0 / ( right - left );
  3394. var h = 1.0 / ( top - bottom );
  3395. var p = 1.0 / ( far - near );
  3396. var x = ( right + left ) * w;
  3397. var y = ( top + bottom ) * h;
  3398. var z = ( far + near ) * p;
  3399. te[ 0 ] = 2 * w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  3400. te[ 1 ] = 0; te[ 5 ] = 2 * h; te[ 9 ] = 0; te[ 13 ] = - y;
  3401. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 * p; te[ 14 ] = - z;
  3402. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  3403. return this;
  3404. },
  3405. equals: function ( matrix ) {
  3406. var te = this.elements;
  3407. var me = matrix.elements;
  3408. for ( var i = 0; i < 16; i ++ ) {
  3409. if ( te[ i ] !== me[ i ] ) return false;
  3410. }
  3411. return true;
  3412. },
  3413. fromArray: function ( array ) {
  3414. this.elements.set( array );
  3415. return this;
  3416. },
  3417. toArray: function () {
  3418. var te = this.elements;
  3419. return [
  3420. te[ 0 ], te[ 1 ], te[ 2 ], te[ 3 ],
  3421. te[ 4 ], te[ 5 ], te[ 6 ], te[ 7 ],
  3422. te[ 8 ], te[ 9 ], te[ 10 ], te[ 11 ],
  3423. te[ 12 ], te[ 13 ], te[ 14 ], te[ 15 ]
  3424. ];
  3425. }
  3426. };
  3427. // File:src/math/Ray.js
  3428. /**
  3429. * @author bhouston / http://clara.io
  3430. */
  3431. THREE.Ray = function ( origin, direction ) {
  3432. this.origin = ( origin !== undefined ) ? origin : new THREE.Vector3();
  3433. this.direction = ( direction !== undefined ) ? direction : new THREE.Vector3();
  3434. };
  3435. THREE.Ray.prototype = {
  3436. constructor: THREE.Ray,
  3437. set: function ( origin, direction ) {
  3438. this.origin.copy( origin );
  3439. this.direction.copy( direction );
  3440. return this;
  3441. },
  3442. clone: function () {
  3443. return new this.constructor().copy( this );
  3444. },
  3445. copy: function ( ray ) {
  3446. this.origin.copy( ray.origin );
  3447. this.direction.copy( ray.direction );
  3448. return this;
  3449. },
  3450. at: function ( t, optionalTarget ) {
  3451. var result = optionalTarget || new THREE.Vector3();
  3452. return result.copy( this.direction ).multiplyScalar( t ).add( this.origin );
  3453. },
  3454. lookAt: function ( v ) {
  3455. this.direction.copy( v ).sub( this.origin ).normalize();
  3456. },
  3457. recast: function () {
  3458. var v1 = new THREE.Vector3();
  3459. return function ( t ) {
  3460. this.origin.copy( this.at( t, v1 ) );
  3461. return this;
  3462. };
  3463. }(),
  3464. closestPointToPoint: function ( point, optionalTarget ) {
  3465. var result = optionalTarget || new THREE.Vector3();
  3466. result.subVectors( point, this.origin );
  3467. var directionDistance = result.dot( this.direction );
  3468. if ( directionDistance < 0 ) {
  3469. return result.copy( this.origin );
  3470. }
  3471. return result.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  3472. },
  3473. distanceToPoint: function ( point ) {
  3474. return Math.sqrt( this.distanceSqToPoint( point ) );
  3475. },
  3476. distanceSqToPoint: function () {
  3477. var v1 = new THREE.Vector3();
  3478. return function ( point ) {
  3479. var directionDistance = v1.subVectors( point, this.origin ).dot( this.direction );
  3480. // point behind the ray
  3481. if ( directionDistance < 0 ) {
  3482. return this.origin.distanceToSquared( point );
  3483. }
  3484. v1.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  3485. return v1.distanceToSquared( point );
  3486. };
  3487. }(),
  3488. distanceSqToSegment: function () {
  3489. var segCenter = new THREE.Vector3();
  3490. var segDir = new THREE.Vector3();
  3491. var diff = new THREE.Vector3();
  3492. return function ( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  3493. // from http://www.geometrictools.com/LibMathematics/Distance/Wm5DistRay3Segment3.cpp
  3494. // It returns the min distance between the ray and the segment
  3495. // defined by v0 and v1
  3496. // It can also set two optional targets :
  3497. // - The closest point on the ray
  3498. // - The closest point on the segment
  3499. segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  3500. segDir.copy( v1 ).sub( v0 ).normalize();
  3501. diff.copy( this.origin ).sub( segCenter );
  3502. var segExtent = v0.distanceTo( v1 ) * 0.5;
  3503. var a01 = - this.direction.dot( segDir );
  3504. var b0 = diff.dot( this.direction );
  3505. var b1 = - diff.dot( segDir );
  3506. var c = diff.lengthSq();
  3507. var det = Math.abs( 1 - a01 * a01 );
  3508. var s0, s1, sqrDist, extDet;
  3509. if ( det > 0 ) {
  3510. // The ray and segment are not parallel.
  3511. s0 = a01 * b1 - b0;
  3512. s1 = a01 * b0 - b1;
  3513. extDet = segExtent * det;
  3514. if ( s0 >= 0 ) {
  3515. if ( s1 >= - extDet ) {
  3516. if ( s1 <= extDet ) {
  3517. // region 0
  3518. // Minimum at interior points of ray and segment.
  3519. var invDet = 1 / det;
  3520. s0 *= invDet;
  3521. s1 *= invDet;
  3522. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  3523. } else {
  3524. // region 1
  3525. s1 = segExtent;
  3526. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3527. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3528. }
  3529. } else {
  3530. // region 5
  3531. s1 = - segExtent;
  3532. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3533. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3534. }
  3535. } else {
  3536. if ( s1 <= - extDet ) {
  3537. // region 4
  3538. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  3539. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3540. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3541. } else if ( s1 <= extDet ) {
  3542. // region 3
  3543. s0 = 0;
  3544. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3545. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  3546. } else {
  3547. // region 2
  3548. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  3549. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3550. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3551. }
  3552. }
  3553. } else {
  3554. // Ray and segment are parallel.
  3555. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  3556. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3557. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3558. }
  3559. if ( optionalPointOnRay ) {
  3560. optionalPointOnRay.copy( this.direction ).multiplyScalar( s0 ).add( this.origin );
  3561. }
  3562. if ( optionalPointOnSegment ) {
  3563. optionalPointOnSegment.copy( segDir ).multiplyScalar( s1 ).add( segCenter );
  3564. }
  3565. return sqrDist;
  3566. };
  3567. }(),
  3568. intersectSphere: function () {
  3569. var v1 = new THREE.Vector3();
  3570. return function ( sphere, optionalTarget ) {
  3571. v1.subVectors( sphere.center, this.origin );
  3572. var tca = v1.dot( this.direction );
  3573. var d2 = v1.dot( v1 ) - tca * tca;
  3574. var radius2 = sphere.radius * sphere.radius;
  3575. if ( d2 > radius2 ) return null;
  3576. var thc = Math.sqrt( radius2 - d2 );
  3577. // t0 = first intersect point - entrance on front of sphere
  3578. var t0 = tca - thc;
  3579. // t1 = second intersect point - exit point on back of sphere
  3580. var t1 = tca + thc;
  3581. // test to see if both t0 and t1 are behind the ray - if so, return null
  3582. if ( t0 < 0 && t1 < 0 ) return null;
  3583. // test to see if t0 is behind the ray:
  3584. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  3585. // in order to always return an intersect point that is in front of the ray.
  3586. if ( t0 < 0 ) return this.at( t1, optionalTarget );
  3587. // else t0 is in front of the ray, so return the first collision point scaled by t0
  3588. return this.at( t0, optionalTarget );
  3589. }
  3590. }(),
  3591. intersectsSphere: function ( sphere ) {
  3592. return this.distanceToPoint( sphere.center ) <= sphere.radius;
  3593. },
  3594. distanceToPlane: function ( plane ) {
  3595. var denominator = plane.normal.dot( this.direction );
  3596. if ( denominator === 0 ) {
  3597. // line is coplanar, return origin
  3598. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  3599. return 0;
  3600. }
  3601. // Null is preferable to undefined since undefined means.... it is undefined
  3602. return null;
  3603. }
  3604. var t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  3605. // Return if the ray never intersects the plane
  3606. return t >= 0 ? t : null;
  3607. },
  3608. intersectPlane: function ( plane, optionalTarget ) {
  3609. var t = this.distanceToPlane( plane );
  3610. if ( t === null ) {
  3611. return null;
  3612. }
  3613. return this.at( t, optionalTarget );
  3614. },
  3615. intersectsPlane: function ( plane ) {
  3616. // check if the ray lies on the plane first
  3617. var distToPoint = plane.distanceToPoint( this.origin );
  3618. if ( distToPoint === 0 ) {
  3619. return true;
  3620. }
  3621. var denominator = plane.normal.dot( this.direction );
  3622. if ( denominator * distToPoint < 0 ) {
  3623. return true;
  3624. }
  3625. // ray origin is behind the plane (and is pointing behind it)
  3626. return false;
  3627. },
  3628. intersectBox: function ( box, optionalTarget ) {
  3629. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  3630. var invdirx = 1 / this.direction.x,
  3631. invdiry = 1 / this.direction.y,
  3632. invdirz = 1 / this.direction.z;
  3633. var origin = this.origin;
  3634. if ( invdirx >= 0 ) {
  3635. tmin = ( box.min.x - origin.x ) * invdirx;
  3636. tmax = ( box.max.x - origin.x ) * invdirx;
  3637. } else {
  3638. tmin = ( box.max.x - origin.x ) * invdirx;
  3639. tmax = ( box.min.x - origin.x ) * invdirx;
  3640. }
  3641. if ( invdiry >= 0 ) {
  3642. tymin = ( box.min.y - origin.y ) * invdiry;
  3643. tymax = ( box.max.y - origin.y ) * invdiry;
  3644. } else {
  3645. tymin = ( box.max.y - origin.y ) * invdiry;
  3646. tymax = ( box.min.y - origin.y ) * invdiry;
  3647. }
  3648. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  3649. // These lines also handle the case where tmin or tmax is NaN
  3650. // (result of 0 * Infinity). x !== x returns true if x is NaN
  3651. if ( tymin > tmin || tmin !== tmin ) tmin = tymin;
  3652. if ( tymax < tmax || tmax !== tmax ) tmax = tymax;
  3653. if ( invdirz >= 0 ) {
  3654. tzmin = ( box.min.z - origin.z ) * invdirz;
  3655. tzmax = ( box.max.z - origin.z ) * invdirz;
  3656. } else {
  3657. tzmin = ( box.max.z - origin.z ) * invdirz;
  3658. tzmax = ( box.min.z - origin.z ) * invdirz;
  3659. }
  3660. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  3661. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  3662. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  3663. //return point closest to the ray (positive side)
  3664. if ( tmax < 0 ) return null;
  3665. return this.at( tmin >= 0 ? tmin : tmax, optionalTarget );
  3666. },
  3667. intersectsBox: ( function () {
  3668. var v = new THREE.Vector3();
  3669. return function ( box ) {
  3670. return this.intersectBox( box, v ) !== null;
  3671. };
  3672. } )(),
  3673. intersectTriangle: function () {
  3674. // Compute the offset origin, edges, and normal.
  3675. var diff = new THREE.Vector3();
  3676. var edge1 = new THREE.Vector3();
  3677. var edge2 = new THREE.Vector3();
  3678. var normal = new THREE.Vector3();
  3679. return function ( a, b, c, backfaceCulling, optionalTarget ) {
  3680. // from http://www.geometrictools.com/LibMathematics/Intersection/Wm5IntrRay3Triangle3.cpp
  3681. edge1.subVectors( b, a );
  3682. edge2.subVectors( c, a );
  3683. normal.crossVectors( edge1, edge2 );
  3684. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  3685. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  3686. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  3687. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  3688. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  3689. var DdN = this.direction.dot( normal );
  3690. var sign;
  3691. if ( DdN > 0 ) {
  3692. if ( backfaceCulling ) return null;
  3693. sign = 1;
  3694. } else if ( DdN < 0 ) {
  3695. sign = - 1;
  3696. DdN = - DdN;
  3697. } else {
  3698. return null;
  3699. }
  3700. diff.subVectors( this.origin, a );
  3701. var DdQxE2 = sign * this.direction.dot( edge2.crossVectors( diff, edge2 ) );
  3702. // b1 < 0, no intersection
  3703. if ( DdQxE2 < 0 ) {
  3704. return null;
  3705. }
  3706. var DdE1xQ = sign * this.direction.dot( edge1.cross( diff ) );
  3707. // b2 < 0, no intersection
  3708. if ( DdE1xQ < 0 ) {
  3709. return null;
  3710. }
  3711. // b1+b2 > 1, no intersection
  3712. if ( DdQxE2 + DdE1xQ > DdN ) {
  3713. return null;
  3714. }
  3715. // Line intersects triangle, check if ray does.
  3716. var QdN = - sign * diff.dot( normal );
  3717. // t < 0, no intersection
  3718. if ( QdN < 0 ) {
  3719. return null;
  3720. }
  3721. // Ray intersects triangle.
  3722. return this.at( QdN / DdN, optionalTarget );
  3723. };
  3724. }(),
  3725. applyMatrix4: function ( matrix4 ) {
  3726. this.direction.add( this.origin ).applyMatrix4( matrix4 );
  3727. this.origin.applyMatrix4( matrix4 );
  3728. this.direction.sub( this.origin );
  3729. this.direction.normalize();
  3730. return this;
  3731. },
  3732. equals: function ( ray ) {
  3733. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  3734. }
  3735. };
  3736. // File:src/math/Sphere.js
  3737. /**
  3738. * @author bhouston / http://clara.io
  3739. * @author mrdoob / http://mrdoob.com/
  3740. */
  3741. THREE.Sphere = function ( center, radius ) {
  3742. this.center = ( center !== undefined ) ? center : new THREE.Vector3();
  3743. this.radius = ( radius !== undefined ) ? radius : 0;
  3744. };
  3745. THREE.Sphere.prototype = {
  3746. constructor: THREE.Sphere,
  3747. set: function ( center, radius ) {
  3748. this.center.copy( center );
  3749. this.radius = radius;
  3750. return this;
  3751. },
  3752. setFromPoints: function () {
  3753. var box = new THREE.Box3();
  3754. return function ( points, optionalCenter ) {
  3755. var center = this.center;
  3756. if ( optionalCenter !== undefined ) {
  3757. center.copy( optionalCenter );
  3758. } else {
  3759. box.setFromPoints( points ).center( center );
  3760. }
  3761. var maxRadiusSq = 0;
  3762. for ( var i = 0, il = points.length; i < il; i ++ ) {
  3763. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  3764. }
  3765. this.radius = Math.sqrt( maxRadiusSq );
  3766. return this;
  3767. };
  3768. }(),
  3769. clone: function () {
  3770. return new this.constructor().copy( this );
  3771. },
  3772. copy: function ( sphere ) {
  3773. this.center.copy( sphere.center );
  3774. this.radius = sphere.radius;
  3775. return this;
  3776. },
  3777. empty: function () {
  3778. return ( this.radius <= 0 );
  3779. },
  3780. containsPoint: function ( point ) {
  3781. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  3782. },
  3783. distanceToPoint: function ( point ) {
  3784. return ( point.distanceTo( this.center ) - this.radius );
  3785. },
  3786. intersectsSphere: function ( sphere ) {
  3787. var radiusSum = this.radius + sphere.radius;
  3788. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  3789. },
  3790. intersectsBox: function ( box ) {
  3791. return box.intersectsSphere( this );
  3792. },
  3793. intersectsPlane: function ( plane ) {
  3794. // We use the following equation to compute the signed distance from
  3795. // the center of the sphere to the plane.
  3796. //
  3797. // distance = q * n - d
  3798. //
  3799. // If this distance is greater than the radius of the sphere,
  3800. // then there is no intersection.
  3801. return Math.abs( this.center.dot( plane.normal ) - plane.constant ) <= this.radius;
  3802. },
  3803. clampPoint: function ( point, optionalTarget ) {
  3804. var deltaLengthSq = this.center.distanceToSquared( point );
  3805. var result = optionalTarget || new THREE.Vector3();
  3806. result.copy( point );
  3807. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  3808. result.sub( this.center ).normalize();
  3809. result.multiplyScalar( this.radius ).add( this.center );
  3810. }
  3811. return result;
  3812. },
  3813. getBoundingBox: function ( optionalTarget ) {
  3814. var box = optionalTarget || new THREE.Box3();
  3815. box.set( this.center, this.center );
  3816. box.expandByScalar( this.radius );
  3817. return box;
  3818. },
  3819. applyMatrix4: function ( matrix ) {
  3820. this.center.applyMatrix4( matrix );
  3821. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  3822. return this;
  3823. },
  3824. translate: function ( offset ) {
  3825. this.center.add( offset );
  3826. return this;
  3827. },
  3828. equals: function ( sphere ) {
  3829. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  3830. }
  3831. };
  3832. // File:src/math/Frustum.js
  3833. /**
  3834. * @author mrdoob / http://mrdoob.com/
  3835. * @author alteredq / http://alteredqualia.com/
  3836. * @author bhouston / http://clara.io
  3837. */
  3838. THREE.Frustum = function ( p0, p1, p2, p3, p4, p5 ) {
  3839. this.planes = [
  3840. ( p0 !== undefined ) ? p0 : new THREE.Plane(),
  3841. ( p1 !== undefined ) ? p1 : new THREE.Plane(),
  3842. ( p2 !== undefined ) ? p2 : new THREE.Plane(),
  3843. ( p3 !== undefined ) ? p3 : new THREE.Plane(),
  3844. ( p4 !== undefined ) ? p4 : new THREE.Plane(),
  3845. ( p5 !== undefined ) ? p5 : new THREE.Plane()
  3846. ];
  3847. };
  3848. THREE.Frustum.prototype = {
  3849. constructor: THREE.Frustum,
  3850. set: function ( p0, p1, p2, p3, p4, p5 ) {
  3851. var planes = this.planes;
  3852. planes[ 0 ].copy( p0 );
  3853. planes[ 1 ].copy( p1 );
  3854. planes[ 2 ].copy( p2 );
  3855. planes[ 3 ].copy( p3 );
  3856. planes[ 4 ].copy( p4 );
  3857. planes[ 5 ].copy( p5 );
  3858. return this;
  3859. },
  3860. clone: function () {
  3861. return new this.constructor().copy( this );
  3862. },
  3863. copy: function ( frustum ) {
  3864. var planes = this.planes;
  3865. for ( var i = 0; i < 6; i ++ ) {
  3866. planes[ i ].copy( frustum.planes[ i ] );
  3867. }
  3868. return this;
  3869. },
  3870. setFromMatrix: function ( m ) {
  3871. var planes = this.planes;
  3872. var me = m.elements;
  3873. var me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  3874. var me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  3875. var me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  3876. var me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  3877. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  3878. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  3879. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  3880. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  3881. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  3882. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  3883. return this;
  3884. },
  3885. intersectsObject: function () {
  3886. var sphere = new THREE.Sphere();
  3887. return function ( object ) {
  3888. var geometry = object.geometry;
  3889. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  3890. sphere.copy( geometry.boundingSphere );
  3891. sphere.applyMatrix4( object.matrixWorld );
  3892. return this.intersectsSphere( sphere );
  3893. };
  3894. }(),
  3895. intersectsSphere: function ( sphere ) {
  3896. var planes = this.planes;
  3897. var center = sphere.center;
  3898. var negRadius = - sphere.radius;
  3899. for ( var i = 0; i < 6; i ++ ) {
  3900. var distance = planes[ i ].distanceToPoint( center );
  3901. if ( distance < negRadius ) {
  3902. return false;
  3903. }
  3904. }
  3905. return true;
  3906. },
  3907. intersectsBox: function () {
  3908. var p1 = new THREE.Vector3(),
  3909. p2 = new THREE.Vector3();
  3910. return function ( box ) {
  3911. var planes = this.planes;
  3912. for ( var i = 0; i < 6 ; i ++ ) {
  3913. var plane = planes[ i ];
  3914. p1.x = plane.normal.x > 0 ? box.min.x : box.max.x;
  3915. p2.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  3916. p1.y = plane.normal.y > 0 ? box.min.y : box.max.y;
  3917. p2.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  3918. p1.z = plane.normal.z > 0 ? box.min.z : box.max.z;
  3919. p2.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  3920. var d1 = plane.distanceToPoint( p1 );
  3921. var d2 = plane.distanceToPoint( p2 );
  3922. // if both outside plane, no intersection
  3923. if ( d1 < 0 && d2 < 0 ) {
  3924. return false;
  3925. }
  3926. }
  3927. return true;
  3928. };
  3929. }(),
  3930. containsPoint: function ( point ) {
  3931. var planes = this.planes;
  3932. for ( var i = 0; i < 6; i ++ ) {
  3933. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  3934. return false;
  3935. }
  3936. }
  3937. return true;
  3938. }
  3939. };
  3940. // File:src/math/Plane.js
  3941. /**
  3942. * @author bhouston / http://clara.io
  3943. */
  3944. THREE.Plane = function ( normal, constant ) {
  3945. this.normal = ( normal !== undefined ) ? normal : new THREE.Vector3( 1, 0, 0 );
  3946. this.constant = ( constant !== undefined ) ? constant : 0;
  3947. };
  3948. THREE.Plane.prototype = {
  3949. constructor: THREE.Plane,
  3950. set: function ( normal, constant ) {
  3951. this.normal.copy( normal );
  3952. this.constant = constant;
  3953. return this;
  3954. },
  3955. setComponents: function ( x, y, z, w ) {
  3956. this.normal.set( x, y, z );
  3957. this.constant = w;
  3958. return this;
  3959. },
  3960. setFromNormalAndCoplanarPoint: function ( normal, point ) {
  3961. this.normal.copy( normal );
  3962. this.constant = - point.dot( this.normal ); // must be this.normal, not normal, as this.normal is normalized
  3963. return this;
  3964. },
  3965. setFromCoplanarPoints: function () {
  3966. var v1 = new THREE.Vector3();
  3967. var v2 = new THREE.Vector3();
  3968. return function ( a, b, c ) {
  3969. var normal = v1.subVectors( c, b ).cross( v2.subVectors( a, b ) ).normalize();
  3970. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  3971. this.setFromNormalAndCoplanarPoint( normal, a );
  3972. return this;
  3973. };
  3974. }(),
  3975. clone: function () {
  3976. return new this.constructor().copy( this );
  3977. },
  3978. copy: function ( plane ) {
  3979. this.normal.copy( plane.normal );
  3980. this.constant = plane.constant;
  3981. return this;
  3982. },
  3983. normalize: function () {
  3984. // Note: will lead to a divide by zero if the plane is invalid.
  3985. var inverseNormalLength = 1.0 / this.normal.length();
  3986. this.normal.multiplyScalar( inverseNormalLength );
  3987. this.constant *= inverseNormalLength;
  3988. return this;
  3989. },
  3990. negate: function () {
  3991. this.constant *= - 1;
  3992. this.normal.negate();
  3993. return this;
  3994. },
  3995. distanceToPoint: function ( point ) {
  3996. return this.normal.dot( point ) + this.constant;
  3997. },
  3998. distanceToSphere: function ( sphere ) {
  3999. return this.distanceToPoint( sphere.center ) - sphere.radius;
  4000. },
  4001. projectPoint: function ( point, optionalTarget ) {
  4002. return this.orthoPoint( point, optionalTarget ).sub( point ).negate();
  4003. },
  4004. orthoPoint: function ( point, optionalTarget ) {
  4005. var perpendicularMagnitude = this.distanceToPoint( point );
  4006. var result = optionalTarget || new THREE.Vector3();
  4007. return result.copy( this.normal ).multiplyScalar( perpendicularMagnitude );
  4008. },
  4009. intersectLine: function () {
  4010. var v1 = new THREE.Vector3();
  4011. return function ( line, optionalTarget ) {
  4012. var result = optionalTarget || new THREE.Vector3();
  4013. var direction = line.delta( v1 );
  4014. var denominator = this.normal.dot( direction );
  4015. if ( denominator === 0 ) {
  4016. // line is coplanar, return origin
  4017. if ( this.distanceToPoint( line.start ) === 0 ) {
  4018. return result.copy( line.start );
  4019. }
  4020. // Unsure if this is the correct method to handle this case.
  4021. return undefined;
  4022. }
  4023. var t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  4024. if ( t < 0 || t > 1 ) {
  4025. return undefined;
  4026. }
  4027. return result.copy( direction ).multiplyScalar( t ).add( line.start );
  4028. };
  4029. }(),
  4030. intersectsLine: function ( line ) {
  4031. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  4032. var startSign = this.distanceToPoint( line.start );
  4033. var endSign = this.distanceToPoint( line.end );
  4034. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  4035. },
  4036. intersectsBox: function ( box ) {
  4037. return box.intersectsPlane( this );
  4038. },
  4039. intersectsSphere: function ( sphere ) {
  4040. return sphere.intersectsPlane( this );
  4041. },
  4042. coplanarPoint: function ( optionalTarget ) {
  4043. var result = optionalTarget || new THREE.Vector3();
  4044. return result.copy( this.normal ).multiplyScalar( - this.constant );
  4045. },
  4046. applyMatrix4: function () {
  4047. var v1 = new THREE.Vector3();
  4048. var v2 = new THREE.Vector3();
  4049. var m1 = new THREE.Matrix3();
  4050. return function ( matrix, optionalNormalMatrix ) {
  4051. // compute new normal based on theory here:
  4052. // http://www.songho.ca/opengl/gl_normaltransform.html
  4053. var normalMatrix = optionalNormalMatrix || m1.getNormalMatrix( matrix );
  4054. var newNormal = v1.copy( this.normal ).applyMatrix3( normalMatrix );
  4055. var newCoplanarPoint = this.coplanarPoint( v2 );
  4056. newCoplanarPoint.applyMatrix4( matrix );
  4057. this.setFromNormalAndCoplanarPoint( newNormal, newCoplanarPoint );
  4058. return this;
  4059. };
  4060. }(),
  4061. translate: function ( offset ) {
  4062. this.constant = this.constant - offset.dot( this.normal );
  4063. return this;
  4064. },
  4065. equals: function ( plane ) {
  4066. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  4067. }
  4068. };
  4069. // File:src/math/Spherical.js
  4070. /**
  4071. * @author bhouston / http://clara.io
  4072. * @author WestLangley / http://github.com/WestLangley
  4073. *
  4074. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  4075. *
  4076. * The poles (phi) are at the positive and negative y axis.
  4077. * The equator starts at positive z.
  4078. */
  4079. THREE.Spherical = function ( radius, phi, theta ) {
  4080. this.radius = ( radius !== undefined ) ? radius : 1.0;
  4081. this.phi = ( phi !== undefined ) ? phi : 0; // up / down towards top and bottom pole
  4082. this.theta = ( theta !== undefined ) ? theta : 0; // around the equator of the sphere
  4083. return this;
  4084. };
  4085. THREE.Spherical.prototype = {
  4086. constructor: THREE.Spherical,
  4087. set: function ( radius, phi, theta ) {
  4088. this.radius = radius;
  4089. this.phi = phi;
  4090. this.theta = theta;
  4091. },
  4092. clone: function () {
  4093. return new this.constructor().copy( this );
  4094. },
  4095. copy: function ( other ) {
  4096. this.radius.copy( other.radius );
  4097. this.phi.copy( other.phi );
  4098. this.theta.copy( other.theta );
  4099. return this;
  4100. },
  4101. // restrict phi to be betwee EPS and PI-EPS
  4102. makeSafe: function() {
  4103. var EPS = 0.000001;
  4104. this.phi = Math.max( EPS, Math.min( Math.PI - EPS, this.phi ) );
  4105. },
  4106. setFromVector3: function( vec3 ) {
  4107. this.radius = vec3.length();
  4108. if ( this.radius === 0 ) {
  4109. this.theta = 0;
  4110. this.phi = 0;
  4111. } else {
  4112. this.theta = Math.atan2( vec3.x, vec3.z ); // equator angle around y-up axis
  4113. this.phi = Math.acos( THREE.Math.clamp( vec3.y / this.radius, - 1, 1 ) ); // polar angle
  4114. }
  4115. return this;
  4116. },
  4117. };
  4118. // File:src/math/Math.js
  4119. /**
  4120. * @author alteredq / http://alteredqualia.com/
  4121. * @author mrdoob / http://mrdoob.com/
  4122. */
  4123. THREE.Math = {
  4124. generateUUID: function () {
  4125. // http://www.broofa.com/Tools/Math.uuid.htm
  4126. var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split( '' );
  4127. var uuid = new Array( 36 );
  4128. var rnd = 0, r;
  4129. return function () {
  4130. for ( var i = 0; i < 36; i ++ ) {
  4131. if ( i === 8 || i === 13 || i === 18 || i === 23 ) {
  4132. uuid[ i ] = '-';
  4133. } else if ( i === 14 ) {
  4134. uuid[ i ] = '4';
  4135. } else {
  4136. if ( rnd <= 0x02 ) rnd = 0x2000000 + ( Math.random() * 0x1000000 ) | 0;
  4137. r = rnd & 0xf;
  4138. rnd = rnd >> 4;
  4139. uuid[ i ] = chars[ ( i === 19 ) ? ( r & 0x3 ) | 0x8 : r ];
  4140. }
  4141. }
  4142. return uuid.join( '' );
  4143. };
  4144. }(),
  4145. clamp: function ( value, min, max ) {
  4146. return Math.max( min, Math.min( max, value ) );
  4147. },
  4148. // compute euclidian modulo of m % n
  4149. // https://en.wikipedia.org/wiki/Modulo_operation
  4150. euclideanModulo: function ( n, m ) {
  4151. return ( ( n % m ) + m ) % m;
  4152. },
  4153. // Linear mapping from range <a1, a2> to range <b1, b2>
  4154. mapLinear: function ( x, a1, a2, b1, b2 ) {
  4155. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  4156. },
  4157. // http://en.wikipedia.org/wiki/Smoothstep
  4158. smoothstep: function ( x, min, max ) {
  4159. if ( x <= min ) return 0;
  4160. if ( x >= max ) return 1;
  4161. x = ( x - min ) / ( max - min );
  4162. return x * x * ( 3 - 2 * x );
  4163. },
  4164. smootherstep: function ( x, min, max ) {
  4165. if ( x <= min ) return 0;
  4166. if ( x >= max ) return 1;
  4167. x = ( x - min ) / ( max - min );
  4168. return x * x * x * ( x * ( x * 6 - 15 ) + 10 );
  4169. },
  4170. random16: function () {
  4171. console.warn( 'THREE.Math.random16() has been deprecated. Use Math.random() instead.' );
  4172. return Math.random();
  4173. },
  4174. // Random integer from <low, high> interval
  4175. randInt: function ( low, high ) {
  4176. return low + Math.floor( Math.random() * ( high - low + 1 ) );
  4177. },
  4178. // Random float from <low, high> interval
  4179. randFloat: function ( low, high ) {
  4180. return low + Math.random() * ( high - low );
  4181. },
  4182. // Random float from <-range/2, range/2> interval
  4183. randFloatSpread: function ( range ) {
  4184. return range * ( 0.5 - Math.random() );
  4185. },
  4186. degToRad: function () {
  4187. var degreeToRadiansFactor = Math.PI / 180;
  4188. return function ( degrees ) {
  4189. return degrees * degreeToRadiansFactor;
  4190. };
  4191. }(),
  4192. radToDeg: function () {
  4193. var radianToDegreesFactor = 180 / Math.PI;
  4194. return function ( radians ) {
  4195. return radians * radianToDegreesFactor;
  4196. };
  4197. }(),
  4198. isPowerOfTwo: function ( value ) {
  4199. return ( value & ( value - 1 ) ) === 0 && value !== 0;
  4200. },
  4201. nearestPowerOfTwo: function ( value ) {
  4202. return Math.pow( 2, Math.round( Math.log( value ) / Math.LN2 ) );
  4203. },
  4204. nextPowerOfTwo: function ( value ) {
  4205. value --;
  4206. value |= value >> 1;
  4207. value |= value >> 2;
  4208. value |= value >> 4;
  4209. value |= value >> 8;
  4210. value |= value >> 16;
  4211. value ++;
  4212. return value;
  4213. }
  4214. };
  4215. // File:src/math/Spline.js
  4216. /**
  4217. * Spline from Tween.js, slightly optimized (and trashed)
  4218. * http://sole.github.com/tween.js/examples/05_spline.html
  4219. *
  4220. * @author mrdoob / http://mrdoob.com/
  4221. * @author alteredq / http://alteredqualia.com/
  4222. */
  4223. THREE.Spline = function ( points ) {
  4224. this.points = points;
  4225. var c = [], v3 = { x: 0, y: 0, z: 0 },
  4226. point, intPoint, weight, w2, w3,
  4227. pa, pb, pc, pd;
  4228. this.initFromArray = function ( a ) {
  4229. this.points = [];
  4230. for ( var i = 0; i < a.length; i ++ ) {
  4231. this.points[ i ] = { x: a[ i ][ 0 ], y: a[ i ][ 1 ], z: a[ i ][ 2 ] };
  4232. }
  4233. };
  4234. this.getPoint = function ( k ) {
  4235. point = ( this.points.length - 1 ) * k;
  4236. intPoint = Math.floor( point );
  4237. weight = point - intPoint;
  4238. c[ 0 ] = intPoint === 0 ? intPoint : intPoint - 1;
  4239. c[ 1 ] = intPoint;
  4240. c[ 2 ] = intPoint > this.points.length - 2 ? this.points.length - 1 : intPoint + 1;
  4241. c[ 3 ] = intPoint > this.points.length - 3 ? this.points.length - 1 : intPoint + 2;
  4242. pa = this.points[ c[ 0 ] ];
  4243. pb = this.points[ c[ 1 ] ];
  4244. pc = this.points[ c[ 2 ] ];
  4245. pd = this.points[ c[ 3 ] ];
  4246. w2 = weight * weight;
  4247. w3 = weight * w2;
  4248. v3.x = interpolate( pa.x, pb.x, pc.x, pd.x, weight, w2, w3 );
  4249. v3.y = interpolate( pa.y, pb.y, pc.y, pd.y, weight, w2, w3 );
  4250. v3.z = interpolate( pa.z, pb.z, pc.z, pd.z, weight, w2, w3 );
  4251. return v3;
  4252. };
  4253. this.getControlPointsArray = function () {
  4254. var i, p, l = this.points.length,
  4255. coords = [];
  4256. for ( i = 0; i < l; i ++ ) {
  4257. p = this.points[ i ];
  4258. coords[ i ] = [ p.x, p.y, p.z ];
  4259. }
  4260. return coords;
  4261. };
  4262. // approximate length by summing linear segments
  4263. this.getLength = function ( nSubDivisions ) {
  4264. var i, index, nSamples, position,
  4265. point = 0, intPoint = 0, oldIntPoint = 0,
  4266. oldPosition = new THREE.Vector3(),
  4267. tmpVec = new THREE.Vector3(),
  4268. chunkLengths = [],
  4269. totalLength = 0;
  4270. // first point has 0 length
  4271. chunkLengths[ 0 ] = 0;
  4272. if ( ! nSubDivisions ) nSubDivisions = 100;
  4273. nSamples = this.points.length * nSubDivisions;
  4274. oldPosition.copy( this.points[ 0 ] );
  4275. for ( i = 1; i < nSamples; i ++ ) {
  4276. index = i / nSamples;
  4277. position = this.getPoint( index );
  4278. tmpVec.copy( position );
  4279. totalLength += tmpVec.distanceTo( oldPosition );
  4280. oldPosition.copy( position );
  4281. point = ( this.points.length - 1 ) * index;
  4282. intPoint = Math.floor( point );
  4283. if ( intPoint !== oldIntPoint ) {
  4284. chunkLengths[ intPoint ] = totalLength;
  4285. oldIntPoint = intPoint;
  4286. }
  4287. }
  4288. // last point ends with total length
  4289. chunkLengths[ chunkLengths.length ] = totalLength;
  4290. return { chunks: chunkLengths, total: totalLength };
  4291. };
  4292. this.reparametrizeByArcLength = function ( samplingCoef ) {
  4293. var i, j,
  4294. index, indexCurrent, indexNext,
  4295. realDistance,
  4296. sampling, position,
  4297. newpoints = [],
  4298. tmpVec = new THREE.Vector3(),
  4299. sl = this.getLength();
  4300. newpoints.push( tmpVec.copy( this.points[ 0 ] ).clone() );
  4301. for ( i = 1; i < this.points.length; i ++ ) {
  4302. //tmpVec.copy( this.points[ i - 1 ] );
  4303. //linearDistance = tmpVec.distanceTo( this.points[ i ] );
  4304. realDistance = sl.chunks[ i ] - sl.chunks[ i - 1 ];
  4305. sampling = Math.ceil( samplingCoef * realDistance / sl.total );
  4306. indexCurrent = ( i - 1 ) / ( this.points.length - 1 );
  4307. indexNext = i / ( this.points.length - 1 );
  4308. for ( j = 1; j < sampling - 1; j ++ ) {
  4309. index = indexCurrent + j * ( 1 / sampling ) * ( indexNext - indexCurrent );
  4310. position = this.getPoint( index );
  4311. newpoints.push( tmpVec.copy( position ).clone() );
  4312. }
  4313. newpoints.push( tmpVec.copy( this.points[ i ] ).clone() );
  4314. }
  4315. this.points = newpoints;
  4316. };
  4317. // Catmull-Rom
  4318. function interpolate( p0, p1, p2, p3, t, t2, t3 ) {
  4319. var v0 = ( p2 - p0 ) * 0.5,
  4320. v1 = ( p3 - p1 ) * 0.5;
  4321. return ( 2 * ( p1 - p2 ) + v0 + v1 ) * t3 + ( - 3 * ( p1 - p2 ) - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  4322. }
  4323. };
  4324. // File:src/math/Triangle.js
  4325. /**
  4326. * @author bhouston / http://clara.io
  4327. * @author mrdoob / http://mrdoob.com/
  4328. */
  4329. THREE.Triangle = function ( a, b, c ) {
  4330. this.a = ( a !== undefined ) ? a : new THREE.Vector3();
  4331. this.b = ( b !== undefined ) ? b : new THREE.Vector3();
  4332. this.c = ( c !== undefined ) ? c : new THREE.Vector3();
  4333. };
  4334. THREE.Triangle.normal = function () {
  4335. var v0 = new THREE.Vector3();
  4336. return function ( a, b, c, optionalTarget ) {
  4337. var result = optionalTarget || new THREE.Vector3();
  4338. result.subVectors( c, b );
  4339. v0.subVectors( a, b );
  4340. result.cross( v0 );
  4341. var resultLengthSq = result.lengthSq();
  4342. if ( resultLengthSq > 0 ) {
  4343. return result.multiplyScalar( 1 / Math.sqrt( resultLengthSq ) );
  4344. }
  4345. return result.set( 0, 0, 0 );
  4346. };
  4347. }();
  4348. // static/instance method to calculate barycentric coordinates
  4349. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  4350. THREE.Triangle.barycoordFromPoint = function () {
  4351. var v0 = new THREE.Vector3();
  4352. var v1 = new THREE.Vector3();
  4353. var v2 = new THREE.Vector3();
  4354. return function ( point, a, b, c, optionalTarget ) {
  4355. v0.subVectors( c, a );
  4356. v1.subVectors( b, a );
  4357. v2.subVectors( point, a );
  4358. var dot00 = v0.dot( v0 );
  4359. var dot01 = v0.dot( v1 );
  4360. var dot02 = v0.dot( v2 );
  4361. var dot11 = v1.dot( v1 );
  4362. var dot12 = v1.dot( v2 );
  4363. var denom = ( dot00 * dot11 - dot01 * dot01 );
  4364. var result = optionalTarget || new THREE.Vector3();
  4365. // collinear or singular triangle
  4366. if ( denom === 0 ) {
  4367. // arbitrary location outside of triangle?
  4368. // not sure if this is the best idea, maybe should be returning undefined
  4369. return result.set( - 2, - 1, - 1 );
  4370. }
  4371. var invDenom = 1 / denom;
  4372. var u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  4373. var v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  4374. // barycentric coordinates must always sum to 1
  4375. return result.set( 1 - u - v, v, u );
  4376. };
  4377. }();
  4378. THREE.Triangle.containsPoint = function () {
  4379. var v1 = new THREE.Vector3();
  4380. return function ( point, a, b, c ) {
  4381. var result = THREE.Triangle.barycoordFromPoint( point, a, b, c, v1 );
  4382. return ( result.x >= 0 ) && ( result.y >= 0 ) && ( ( result.x + result.y ) <= 1 );
  4383. };
  4384. }();
  4385. THREE.Triangle.prototype = {
  4386. constructor: THREE.Triangle,
  4387. set: function ( a, b, c ) {
  4388. this.a.copy( a );
  4389. this.b.copy( b );
  4390. this.c.copy( c );
  4391. return this;
  4392. },
  4393. setFromPointsAndIndices: function ( points, i0, i1, i2 ) {
  4394. this.a.copy( points[ i0 ] );
  4395. this.b.copy( points[ i1 ] );
  4396. this.c.copy( points[ i2 ] );
  4397. return this;
  4398. },
  4399. clone: function () {
  4400. return new this.constructor().copy( this );
  4401. },
  4402. copy: function ( triangle ) {
  4403. this.a.copy( triangle.a );
  4404. this.b.copy( triangle.b );
  4405. this.c.copy( triangle.c );
  4406. return this;
  4407. },
  4408. area: function () {
  4409. var v0 = new THREE.Vector3();
  4410. var v1 = new THREE.Vector3();
  4411. return function () {
  4412. v0.subVectors( this.c, this.b );
  4413. v1.subVectors( this.a, this.b );
  4414. return v0.cross( v1 ).length() * 0.5;
  4415. };
  4416. }(),
  4417. midpoint: function ( optionalTarget ) {
  4418. var result = optionalTarget || new THREE.Vector3();
  4419. return result.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  4420. },
  4421. normal: function ( optionalTarget ) {
  4422. return THREE.Triangle.normal( this.a, this.b, this.c, optionalTarget );
  4423. },
  4424. plane: function ( optionalTarget ) {
  4425. var result = optionalTarget || new THREE.Plane();
  4426. return result.setFromCoplanarPoints( this.a, this.b, this.c );
  4427. },
  4428. barycoordFromPoint: function ( point, optionalTarget ) {
  4429. return THREE.Triangle.barycoordFromPoint( point, this.a, this.b, this.c, optionalTarget );
  4430. },
  4431. containsPoint: function ( point ) {
  4432. return THREE.Triangle.containsPoint( point, this.a, this.b, this.c );
  4433. },
  4434. equals: function ( triangle ) {
  4435. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  4436. }
  4437. };
  4438. // File:src/math/Interpolant.js
  4439. /**
  4440. * Abstract base class of interpolants over parametric samples.
  4441. *
  4442. * The parameter domain is one dimensional, typically the time or a path
  4443. * along a curve defined by the data.
  4444. *
  4445. * The sample values can have any dimensionality and derived classes may
  4446. * apply special interpretations to the data.
  4447. *
  4448. * This class provides the interval seek in a Template Method, deferring
  4449. * the actual interpolation to derived classes.
  4450. *
  4451. * Time complexity is O(1) for linear access crossing at most two points
  4452. * and O(log N) for random access, where N is the number of positions.
  4453. *
  4454. * References:
  4455. *
  4456. * http://www.oodesign.com/template-method-pattern.html
  4457. *
  4458. * @author tschw
  4459. */
  4460. THREE.Interpolant = function(
  4461. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4462. this.parameterPositions = parameterPositions;
  4463. this._cachedIndex = 0;
  4464. this.resultBuffer = resultBuffer !== undefined ?
  4465. resultBuffer : new sampleValues.constructor( sampleSize );
  4466. this.sampleValues = sampleValues;
  4467. this.valueSize = sampleSize;
  4468. };
  4469. THREE.Interpolant.prototype = {
  4470. constructor: THREE.Interpolant,
  4471. evaluate: function( t ) {
  4472. var pp = this.parameterPositions,
  4473. i1 = this._cachedIndex,
  4474. t1 = pp[ i1 ],
  4475. t0 = pp[ i1 - 1 ];
  4476. validate_interval: {
  4477. seek: {
  4478. var right;
  4479. linear_scan: {
  4480. //- See http://jsperf.com/comparison-to-undefined/3
  4481. //- slower code:
  4482. //-
  4483. //- if ( t >= t1 || t1 === undefined ) {
  4484. forward_scan: if ( ! ( t < t1 ) ) {
  4485. for ( var giveUpAt = i1 + 2; ;) {
  4486. if ( t1 === undefined ) {
  4487. if ( t < t0 ) break forward_scan;
  4488. // after end
  4489. i1 = pp.length;
  4490. this._cachedIndex = i1;
  4491. return this.afterEnd_( i1 - 1, t, t0 );
  4492. }
  4493. if ( i1 === giveUpAt ) break; // this loop
  4494. t0 = t1;
  4495. t1 = pp[ ++ i1 ];
  4496. if ( t < t1 ) {
  4497. // we have arrived at the sought interval
  4498. break seek;
  4499. }
  4500. }
  4501. // prepare binary search on the right side of the index
  4502. right = pp.length;
  4503. break linear_scan;
  4504. }
  4505. //- slower code:
  4506. //- if ( t < t0 || t0 === undefined ) {
  4507. if ( ! ( t >= t0 ) ) {
  4508. // looping?
  4509. var t1global = pp[ 1 ];
  4510. if ( t < t1global ) {
  4511. i1 = 2; // + 1, using the scan for the details
  4512. t0 = t1global;
  4513. }
  4514. // linear reverse scan
  4515. for ( var giveUpAt = i1 - 2; ;) {
  4516. if ( t0 === undefined ) {
  4517. // before start
  4518. this._cachedIndex = 0;
  4519. return this.beforeStart_( 0, t, t1 );
  4520. }
  4521. if ( i1 === giveUpAt ) break; // this loop
  4522. t1 = t0;
  4523. t0 = pp[ -- i1 - 1 ];
  4524. if ( t >= t0 ) {
  4525. // we have arrived at the sought interval
  4526. break seek;
  4527. }
  4528. }
  4529. // prepare binary search on the left side of the index
  4530. right = i1;
  4531. i1 = 0;
  4532. break linear_scan;
  4533. }
  4534. // the interval is valid
  4535. break validate_interval;
  4536. } // linear scan
  4537. // binary search
  4538. while ( i1 < right ) {
  4539. var mid = ( i1 + right ) >>> 1;
  4540. if ( t < pp[ mid ] ) {
  4541. right = mid;
  4542. } else {
  4543. i1 = mid + 1;
  4544. }
  4545. }
  4546. t1 = pp[ i1 ];
  4547. t0 = pp[ i1 - 1 ];
  4548. // check boundary cases, again
  4549. if ( t0 === undefined ) {
  4550. this._cachedIndex = 0;
  4551. return this.beforeStart_( 0, t, t1 );
  4552. }
  4553. if ( t1 === undefined ) {
  4554. i1 = pp.length;
  4555. this._cachedIndex = i1;
  4556. return this.afterEnd_( i1 - 1, t0, t );
  4557. }
  4558. } // seek
  4559. this._cachedIndex = i1;
  4560. this.intervalChanged_( i1, t0, t1 );
  4561. } // validate_interval
  4562. return this.interpolate_( i1, t0, t, t1 );
  4563. },
  4564. settings: null, // optional, subclass-specific settings structure
  4565. // Note: The indirection allows central control of many interpolants.
  4566. // --- Protected interface
  4567. DefaultSettings_: {},
  4568. getSettings_: function() {
  4569. return this.settings || this.DefaultSettings_;
  4570. },
  4571. copySampleValue_: function( index ) {
  4572. // copies a sample value to the result buffer
  4573. var result = this.resultBuffer,
  4574. values = this.sampleValues,
  4575. stride = this.valueSize,
  4576. offset = index * stride;
  4577. for ( var i = 0; i !== stride; ++ i ) {
  4578. result[ i ] = values[ offset + i ];
  4579. }
  4580. return result;
  4581. },
  4582. // Template methods for derived classes:
  4583. interpolate_: function( i1, t0, t, t1 ) {
  4584. throw new Error( "call to abstract method" );
  4585. // implementations shall return this.resultBuffer
  4586. },
  4587. intervalChanged_: function( i1, t0, t1 ) {
  4588. // empty
  4589. }
  4590. };
  4591. Object.assign( THREE.Interpolant.prototype, {
  4592. beforeStart_: //( 0, t, t0 ), returns this.resultBuffer
  4593. THREE.Interpolant.prototype.copySampleValue_,
  4594. afterEnd_: //( N-1, tN-1, t ), returns this.resultBuffer
  4595. THREE.Interpolant.prototype.copySampleValue_
  4596. } );
  4597. // File:src/math/interpolants/CubicInterpolant.js
  4598. /**
  4599. * Fast and simple cubic spline interpolant.
  4600. *
  4601. * It was derived from a Hermitian construction setting the first derivative
  4602. * at each sample position to the linear slope between neighboring positions
  4603. * over their parameter interval.
  4604. *
  4605. * @author tschw
  4606. */
  4607. THREE.CubicInterpolant = function(
  4608. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4609. THREE.Interpolant.call(
  4610. this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  4611. this._weightPrev = -0;
  4612. this._offsetPrev = -0;
  4613. this._weightNext = -0;
  4614. this._offsetNext = -0;
  4615. };
  4616. THREE.CubicInterpolant.prototype =
  4617. Object.assign( Object.create( THREE.Interpolant.prototype ), {
  4618. constructor: THREE.CubicInterpolant,
  4619. DefaultSettings_: {
  4620. endingStart: THREE.ZeroCurvatureEnding,
  4621. endingEnd: THREE.ZeroCurvatureEnding
  4622. },
  4623. intervalChanged_: function( i1, t0, t1 ) {
  4624. var pp = this.parameterPositions,
  4625. iPrev = i1 - 2,
  4626. iNext = i1 + 1,
  4627. tPrev = pp[ iPrev ],
  4628. tNext = pp[ iNext ];
  4629. if ( tPrev === undefined ) {
  4630. switch ( this.getSettings_().endingStart ) {
  4631. case THREE.ZeroSlopeEnding:
  4632. // f'(t0) = 0
  4633. iPrev = i1;
  4634. tPrev = 2 * t0 - t1;
  4635. break;
  4636. case THREE.WrapAroundEnding:
  4637. // use the other end of the curve
  4638. iPrev = pp.length - 2;
  4639. tPrev = t0 + pp[ iPrev ] - pp[ iPrev + 1 ];
  4640. break;
  4641. default: // ZeroCurvatureEnding
  4642. // f''(t0) = 0 a.k.a. Natural Spline
  4643. iPrev = i1;
  4644. tPrev = t1;
  4645. }
  4646. }
  4647. if ( tNext === undefined ) {
  4648. switch ( this.getSettings_().endingEnd ) {
  4649. case THREE.ZeroSlopeEnding:
  4650. // f'(tN) = 0
  4651. iNext = i1;
  4652. tNext = 2 * t1 - t0;
  4653. break;
  4654. case THREE.WrapAroundEnding:
  4655. // use the other end of the curve
  4656. iNext = 1;
  4657. tNext = t1 + pp[ 1 ] - pp[ 0 ];
  4658. break;
  4659. default: // ZeroCurvatureEnding
  4660. // f''(tN) = 0, a.k.a. Natural Spline
  4661. iNext = i1 - 1;
  4662. tNext = t0;
  4663. }
  4664. }
  4665. var halfDt = ( t1 - t0 ) * 0.5,
  4666. stride = this.valueSize;
  4667. this._weightPrev = halfDt / ( t0 - tPrev );
  4668. this._weightNext = halfDt / ( tNext - t1 );
  4669. this._offsetPrev = iPrev * stride;
  4670. this._offsetNext = iNext * stride;
  4671. },
  4672. interpolate_: function( i1, t0, t, t1 ) {
  4673. var result = this.resultBuffer,
  4674. values = this.sampleValues,
  4675. stride = this.valueSize,
  4676. o1 = i1 * stride, o0 = o1 - stride,
  4677. oP = this._offsetPrev, oN = this._offsetNext,
  4678. wP = this._weightPrev, wN = this._weightNext,
  4679. p = ( t - t0 ) / ( t1 - t0 ),
  4680. pp = p * p,
  4681. ppp = pp * p;
  4682. // evaluate polynomials
  4683. var sP = - wP * ppp + 2 * wP * pp - wP * p;
  4684. var s0 = ( 1 + wP ) * ppp + (-1.5 - 2 * wP ) * pp + ( -0.5 + wP ) * p + 1;
  4685. var s1 = (-1 - wN ) * ppp + ( 1.5 + wN ) * pp + 0.5 * p;
  4686. var sN = wN * ppp - wN * pp;
  4687. // combine data linearly
  4688. for ( var i = 0; i !== stride; ++ i ) {
  4689. result[ i ] =
  4690. sP * values[ oP + i ] +
  4691. s0 * values[ o0 + i ] +
  4692. s1 * values[ o1 + i ] +
  4693. sN * values[ oN + i ];
  4694. }
  4695. return result;
  4696. }
  4697. } );
  4698. // File:src/math/interpolants/DiscreteInterpolant.js
  4699. /**
  4700. *
  4701. * Interpolant that evaluates to the sample value at the position preceeding
  4702. * the parameter.
  4703. *
  4704. * @author tschw
  4705. */
  4706. THREE.DiscreteInterpolant = function(
  4707. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4708. THREE.Interpolant.call(
  4709. this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  4710. };
  4711. THREE.DiscreteInterpolant.prototype =
  4712. Object.assign( Object.create( THREE.Interpolant.prototype ), {
  4713. constructor: THREE.DiscreteInterpolant,
  4714. interpolate_: function( i1, t0, t, t1 ) {
  4715. return this.copySampleValue_( i1 - 1 );
  4716. }
  4717. } );
  4718. // File:src/math/interpolants/LinearInterpolant.js
  4719. /**
  4720. * @author tschw
  4721. */
  4722. THREE.LinearInterpolant = function(
  4723. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4724. THREE.Interpolant.call(
  4725. this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  4726. };
  4727. THREE.LinearInterpolant.prototype =
  4728. Object.assign( Object.create( THREE.Interpolant.prototype ), {
  4729. constructor: THREE.LinearInterpolant,
  4730. interpolate_: function( i1, t0, t, t1 ) {
  4731. var result = this.resultBuffer,
  4732. values = this.sampleValues,
  4733. stride = this.valueSize,
  4734. offset1 = i1 * stride,
  4735. offset0 = offset1 - stride,
  4736. weight1 = ( t - t0 ) / ( t1 - t0 ),
  4737. weight0 = 1 - weight1;
  4738. for ( var i = 0; i !== stride; ++ i ) {
  4739. result[ i ] =
  4740. values[ offset0 + i ] * weight0 +
  4741. values[ offset1 + i ] * weight1;
  4742. }
  4743. return result;
  4744. }
  4745. } );
  4746. // File:src/math/interpolants/QuaternionLinearInterpolant.js
  4747. /**
  4748. * Spherical linear unit quaternion interpolant.
  4749. *
  4750. * @author tschw
  4751. */
  4752. THREE.QuaternionLinearInterpolant = function(
  4753. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4754. THREE.Interpolant.call(
  4755. this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  4756. };
  4757. THREE.QuaternionLinearInterpolant.prototype =
  4758. Object.assign( Object.create( THREE.Interpolant.prototype ), {
  4759. constructor: THREE.QuaternionLinearInterpolant,
  4760. interpolate_: function( i1, t0, t, t1 ) {
  4761. var result = this.resultBuffer,
  4762. values = this.sampleValues,
  4763. stride = this.valueSize,
  4764. offset = i1 * stride,
  4765. alpha = ( t - t0 ) / ( t1 - t0 );
  4766. for ( var end = offset + stride; offset !== end; offset += 4 ) {
  4767. THREE.Quaternion.slerpFlat( result, 0,
  4768. values, offset - stride, values, offset, alpha );
  4769. }
  4770. return result;
  4771. }
  4772. } );
  4773. // File:src/core/Clock.js
  4774. /**
  4775. * @author alteredq / http://alteredqualia.com/
  4776. */
  4777. THREE.Clock = function ( autoStart ) {
  4778. this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
  4779. this.startTime = 0;
  4780. this.oldTime = 0;
  4781. this.elapsedTime = 0;
  4782. this.running = false;
  4783. };
  4784. THREE.Clock.prototype = {
  4785. constructor: THREE.Clock,
  4786. start: function () {
  4787. this.startTime = performance.now();
  4788. this.oldTime = this.startTime;
  4789. this.running = true;
  4790. },
  4791. stop: function () {
  4792. this.getElapsedTime();
  4793. this.running = false;
  4794. },
  4795. getElapsedTime: function () {
  4796. this.getDelta();
  4797. return this.elapsedTime;
  4798. },
  4799. getDelta: function () {
  4800. var diff = 0;
  4801. if ( this.autoStart && ! this.running ) {
  4802. this.start();
  4803. }
  4804. if ( this.running ) {
  4805. var newTime = performance.now();
  4806. diff = 0.001 * ( newTime - this.oldTime );
  4807. this.oldTime = newTime;
  4808. this.elapsedTime += diff;
  4809. }
  4810. return diff;
  4811. }
  4812. };
  4813. // File:src/core/EventDispatcher.js
  4814. /**
  4815. * https://github.com/mrdoob/eventdispatcher.js/
  4816. */
  4817. THREE.EventDispatcher = function () {};
  4818. THREE.EventDispatcher.prototype = {
  4819. constructor: THREE.EventDispatcher,
  4820. apply: function ( object ) {
  4821. object.addEventListener = THREE.EventDispatcher.prototype.addEventListener;
  4822. object.hasEventListener = THREE.EventDispatcher.prototype.hasEventListener;
  4823. object.removeEventListener = THREE.EventDispatcher.prototype.removeEventListener;
  4824. object.dispatchEvent = THREE.EventDispatcher.prototype.dispatchEvent;
  4825. },
  4826. addEventListener: function ( type, listener ) {
  4827. if ( this._listeners === undefined ) this._listeners = {};
  4828. var listeners = this._listeners;
  4829. if ( listeners[ type ] === undefined ) {
  4830. listeners[ type ] = [];
  4831. }
  4832. if ( listeners[ type ].indexOf( listener ) === - 1 ) {
  4833. listeners[ type ].push( listener );
  4834. }
  4835. },
  4836. hasEventListener: function ( type, listener ) {
  4837. if ( this._listeners === undefined ) return false;
  4838. var listeners = this._listeners;
  4839. if ( listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1 ) {
  4840. return true;
  4841. }
  4842. return false;
  4843. },
  4844. removeEventListener: function ( type, listener ) {
  4845. if ( this._listeners === undefined ) return;
  4846. var listeners = this._listeners;
  4847. var listenerArray = listeners[ type ];
  4848. if ( listenerArray !== undefined ) {
  4849. var index = listenerArray.indexOf( listener );
  4850. if ( index !== - 1 ) {
  4851. listenerArray.splice( index, 1 );
  4852. }
  4853. }
  4854. },
  4855. dispatchEvent: function ( event ) {
  4856. if ( this._listeners === undefined ) return;
  4857. var listeners = this._listeners;
  4858. var listenerArray = listeners[ event.type ];
  4859. if ( listenerArray !== undefined ) {
  4860. event.target = this;
  4861. var array = [];
  4862. var length = listenerArray.length;
  4863. for ( var i = 0; i < length; i ++ ) {
  4864. array[ i ] = listenerArray[ i ];
  4865. }
  4866. for ( var i = 0; i < length; i ++ ) {
  4867. array[ i ].call( this, event );
  4868. }
  4869. }
  4870. }
  4871. };
  4872. // File:src/core/Layers.js
  4873. /**
  4874. * @author mrdoob / http://mrdoob.com/
  4875. */
  4876. THREE.Layers = function () {
  4877. this.mask = 1;
  4878. };
  4879. THREE.Layers.prototype = {
  4880. constructor: THREE.Layers,
  4881. set: function ( channel ) {
  4882. this.mask = 1 << channel;
  4883. },
  4884. enable: function ( channel ) {
  4885. this.mask |= 1 << channel;
  4886. },
  4887. toggle: function ( channel ) {
  4888. this.mask ^= 1 << channel;
  4889. },
  4890. disable: function ( channel ) {
  4891. this.mask &= ~ ( 1 << channel );
  4892. },
  4893. test: function ( layers ) {
  4894. return ( this.mask & layers.mask ) !== 0;
  4895. }
  4896. };
  4897. // File:src/core/Raycaster.js
  4898. /**
  4899. * @author mrdoob / http://mrdoob.com/
  4900. * @author bhouston / http://clara.io/
  4901. * @author stephomi / http://stephaneginier.com/
  4902. */
  4903. ( function ( THREE ) {
  4904. THREE.Raycaster = function ( origin, direction, near, far ) {
  4905. this.ray = new THREE.Ray( origin, direction );
  4906. // direction is assumed to be normalized (for accurate distance calculations)
  4907. this.near = near || 0;
  4908. this.far = far || Infinity;
  4909. this.params = {
  4910. Mesh: {},
  4911. Line: {},
  4912. LOD: {},
  4913. Points: { threshold: 1 },
  4914. Sprite: {}
  4915. };
  4916. Object.defineProperties( this.params, {
  4917. PointCloud: {
  4918. get: function () {
  4919. console.warn( 'THREE.Raycaster: params.PointCloud has been renamed to params.Points.' );
  4920. return this.Points;
  4921. }
  4922. }
  4923. } );
  4924. };
  4925. function ascSort( a, b ) {
  4926. return a.distance - b.distance;
  4927. }
  4928. function intersectObject( object, raycaster, intersects, recursive ) {
  4929. if ( object.visible === false ) return;
  4930. object.raycast( raycaster, intersects );
  4931. if ( recursive === true ) {
  4932. var children = object.children;
  4933. for ( var i = 0, l = children.length; i < l; i ++ ) {
  4934. intersectObject( children[ i ], raycaster, intersects, true );
  4935. }
  4936. }
  4937. }
  4938. //
  4939. THREE.Raycaster.prototype = {
  4940. constructor: THREE.Raycaster,
  4941. linePrecision: 1,
  4942. set: function ( origin, direction ) {
  4943. // direction is assumed to be normalized (for accurate distance calculations)
  4944. this.ray.set( origin, direction );
  4945. },
  4946. setFromCamera: function ( coords, camera ) {
  4947. if ( camera instanceof THREE.PerspectiveCamera ) {
  4948. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  4949. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  4950. } else if ( camera instanceof THREE.OrthographicCamera ) {
  4951. this.ray.origin.set( coords.x, coords.y, - 1 ).unproject( camera );
  4952. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  4953. } else {
  4954. console.error( 'THREE.Raycaster: Unsupported camera type.' );
  4955. }
  4956. },
  4957. intersectObject: function ( object, recursive ) {
  4958. var intersects = [];
  4959. intersectObject( object, this, intersects, recursive );
  4960. intersects.sort( ascSort );
  4961. return intersects;
  4962. },
  4963. intersectObjects: function ( objects, recursive ) {
  4964. var intersects = [];
  4965. if ( Array.isArray( objects ) === false ) {
  4966. console.warn( 'THREE.Raycaster.intersectObjects: objects is not an Array.' );
  4967. return intersects;
  4968. }
  4969. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  4970. intersectObject( objects[ i ], this, intersects, recursive );
  4971. }
  4972. intersects.sort( ascSort );
  4973. return intersects;
  4974. }
  4975. };
  4976. }( THREE ) );
  4977. // File:src/core/Object3D.js
  4978. /**
  4979. * @author mrdoob / http://mrdoob.com/
  4980. * @author mikael emtinger / http://gomo.se/
  4981. * @author alteredq / http://alteredqualia.com/
  4982. * @author WestLangley / http://github.com/WestLangley
  4983. * @author elephantatwork / www.elephantatwork.ch
  4984. */
  4985. THREE.Object3D = function () {
  4986. Object.defineProperty( this, 'id', { value: THREE.Object3DIdCount ++ } );
  4987. this.uuid = THREE.Math.generateUUID();
  4988. this.name = '';
  4989. this.type = 'Object3D';
  4990. this.parent = null;
  4991. this.children = [];
  4992. this.up = THREE.Object3D.DefaultUp.clone();
  4993. var position = new THREE.Vector3();
  4994. var rotation = new THREE.Euler();
  4995. var quaternion = new THREE.Quaternion();
  4996. var scale = new THREE.Vector3( 1, 1, 1 );
  4997. function onRotationChange() {
  4998. quaternion.setFromEuler( rotation, false );
  4999. }
  5000. function onQuaternionChange() {
  5001. rotation.setFromQuaternion( quaternion, undefined, false );
  5002. }
  5003. rotation.onChange( onRotationChange );
  5004. quaternion.onChange( onQuaternionChange );
  5005. Object.defineProperties( this, {
  5006. position: {
  5007. enumerable: true,
  5008. value: position
  5009. },
  5010. rotation: {
  5011. enumerable: true,
  5012. value: rotation
  5013. },
  5014. quaternion: {
  5015. enumerable: true,
  5016. value: quaternion
  5017. },
  5018. scale: {
  5019. enumerable: true,
  5020. value: scale
  5021. },
  5022. modelViewMatrix: {
  5023. value: new THREE.Matrix4()
  5024. },
  5025. normalMatrix: {
  5026. value: new THREE.Matrix3()
  5027. }
  5028. } );
  5029. this.rotationAutoUpdate = true;
  5030. this.matrix = new THREE.Matrix4();
  5031. this.matrixWorld = new THREE.Matrix4();
  5032. this.matrixAutoUpdate = THREE.Object3D.DefaultMatrixAutoUpdate;
  5033. this.matrixWorldNeedsUpdate = false;
  5034. this.layers = new THREE.Layers();
  5035. this.visible = true;
  5036. this.castShadow = false;
  5037. this.receiveShadow = false;
  5038. this.frustumCulled = true;
  5039. this.renderOrder = 0;
  5040. this.userData = {};
  5041. };
  5042. THREE.Object3D.DefaultUp = new THREE.Vector3( 0, 1, 0 );
  5043. THREE.Object3D.DefaultMatrixAutoUpdate = true;
  5044. THREE.Object3D.prototype = {
  5045. constructor: THREE.Object3D,
  5046. applyMatrix: function ( matrix ) {
  5047. this.matrix.multiplyMatrices( matrix, this.matrix );
  5048. this.matrix.decompose( this.position, this.quaternion, this.scale );
  5049. },
  5050. setRotationFromAxisAngle: function ( axis, angle ) {
  5051. // assumes axis is normalized
  5052. this.quaternion.setFromAxisAngle( axis, angle );
  5053. },
  5054. setRotationFromEuler: function ( euler ) {
  5055. this.quaternion.setFromEuler( euler, true );
  5056. },
  5057. setRotationFromMatrix: function ( m ) {
  5058. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  5059. this.quaternion.setFromRotationMatrix( m );
  5060. },
  5061. setRotationFromQuaternion: function ( q ) {
  5062. // assumes q is normalized
  5063. this.quaternion.copy( q );
  5064. },
  5065. rotateOnAxis: function () {
  5066. // rotate object on axis in object space
  5067. // axis is assumed to be normalized
  5068. var q1 = new THREE.Quaternion();
  5069. return function ( axis, angle ) {
  5070. q1.setFromAxisAngle( axis, angle );
  5071. this.quaternion.multiply( q1 );
  5072. return this;
  5073. };
  5074. }(),
  5075. rotateX: function () {
  5076. var v1 = new THREE.Vector3( 1, 0, 0 );
  5077. return function ( angle ) {
  5078. return this.rotateOnAxis( v1, angle );
  5079. };
  5080. }(),
  5081. rotateY: function () {
  5082. var v1 = new THREE.Vector3( 0, 1, 0 );
  5083. return function ( angle ) {
  5084. return this.rotateOnAxis( v1, angle );
  5085. };
  5086. }(),
  5087. rotateZ: function () {
  5088. var v1 = new THREE.Vector3( 0, 0, 1 );
  5089. return function ( angle ) {
  5090. return this.rotateOnAxis( v1, angle );
  5091. };
  5092. }(),
  5093. translateOnAxis: function () {
  5094. // translate object by distance along axis in object space
  5095. // axis is assumed to be normalized
  5096. var v1 = new THREE.Vector3();
  5097. return function ( axis, distance ) {
  5098. v1.copy( axis ).applyQuaternion( this.quaternion );
  5099. this.position.add( v1.multiplyScalar( distance ) );
  5100. return this;
  5101. };
  5102. }(),
  5103. translateX: function () {
  5104. var v1 = new THREE.Vector3( 1, 0, 0 );
  5105. return function ( distance ) {
  5106. return this.translateOnAxis( v1, distance );
  5107. };
  5108. }(),
  5109. translateY: function () {
  5110. var v1 = new THREE.Vector3( 0, 1, 0 );
  5111. return function ( distance ) {
  5112. return this.translateOnAxis( v1, distance );
  5113. };
  5114. }(),
  5115. translateZ: function () {
  5116. var v1 = new THREE.Vector3( 0, 0, 1 );
  5117. return function ( distance ) {
  5118. return this.translateOnAxis( v1, distance );
  5119. };
  5120. }(),
  5121. localToWorld: function ( vector ) {
  5122. return vector.applyMatrix4( this.matrixWorld );
  5123. },
  5124. worldToLocal: function () {
  5125. var m1 = new THREE.Matrix4();
  5126. return function ( vector ) {
  5127. return vector.applyMatrix4( m1.getInverse( this.matrixWorld ) );
  5128. };
  5129. }(),
  5130. lookAt: function () {
  5131. // This routine does not support objects with rotated and/or translated parent(s)
  5132. var m1 = new THREE.Matrix4();
  5133. return function ( vector ) {
  5134. m1.lookAt( vector, this.position, this.up );
  5135. this.quaternion.setFromRotationMatrix( m1 );
  5136. };
  5137. }(),
  5138. add: function ( object ) {
  5139. if ( arguments.length > 1 ) {
  5140. for ( var i = 0; i < arguments.length; i ++ ) {
  5141. this.add( arguments[ i ] );
  5142. }
  5143. return this;
  5144. }
  5145. if ( object === this ) {
  5146. console.error( "THREE.Object3D.add: object can't be added as a child of itself.", object );
  5147. return this;
  5148. }
  5149. if ( object instanceof THREE.Object3D ) {
  5150. if ( object.parent !== null ) {
  5151. object.parent.remove( object );
  5152. }
  5153. object.parent = this;
  5154. object.dispatchEvent( { type: 'added' } );
  5155. this.children.push( object );
  5156. } else {
  5157. console.error( "THREE.Object3D.add: object not an instance of THREE.Object3D.", object );
  5158. }
  5159. return this;
  5160. },
  5161. remove: function ( object ) {
  5162. if ( arguments.length > 1 ) {
  5163. for ( var i = 0; i < arguments.length; i ++ ) {
  5164. this.remove( arguments[ i ] );
  5165. }
  5166. }
  5167. var index = this.children.indexOf( object );
  5168. if ( index !== - 1 ) {
  5169. object.parent = null;
  5170. object.dispatchEvent( { type: 'removed' } );
  5171. this.children.splice( index, 1 );
  5172. }
  5173. },
  5174. getObjectById: function ( id ) {
  5175. return this.getObjectByProperty( 'id', id );
  5176. },
  5177. getObjectByName: function ( name ) {
  5178. return this.getObjectByProperty( 'name', name );
  5179. },
  5180. getObjectByProperty: function ( name, value ) {
  5181. if ( this[ name ] === value ) return this;
  5182. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  5183. var child = this.children[ i ];
  5184. var object = child.getObjectByProperty( name, value );
  5185. if ( object !== undefined ) {
  5186. return object;
  5187. }
  5188. }
  5189. return undefined;
  5190. },
  5191. getWorldPosition: function ( optionalTarget ) {
  5192. var result = optionalTarget || new THREE.Vector3();
  5193. this.updateMatrixWorld( true );
  5194. return result.setFromMatrixPosition( this.matrixWorld );
  5195. },
  5196. getWorldQuaternion: function () {
  5197. var position = new THREE.Vector3();
  5198. var scale = new THREE.Vector3();
  5199. return function ( optionalTarget ) {
  5200. var result = optionalTarget || new THREE.Quaternion();
  5201. this.updateMatrixWorld( true );
  5202. this.matrixWorld.decompose( position, result, scale );
  5203. return result;
  5204. };
  5205. }(),
  5206. getWorldRotation: function () {
  5207. var quaternion = new THREE.Quaternion();
  5208. return function ( optionalTarget ) {
  5209. var result = optionalTarget || new THREE.Euler();
  5210. this.getWorldQuaternion( quaternion );
  5211. return result.setFromQuaternion( quaternion, this.rotation.order, false );
  5212. };
  5213. }(),
  5214. getWorldScale: function () {
  5215. var position = new THREE.Vector3();
  5216. var quaternion = new THREE.Quaternion();
  5217. return function ( optionalTarget ) {
  5218. var result = optionalTarget || new THREE.Vector3();
  5219. this.updateMatrixWorld( true );
  5220. this.matrixWorld.decompose( position, quaternion, result );
  5221. return result;
  5222. };
  5223. }(),
  5224. getWorldDirection: function () {
  5225. var quaternion = new THREE.Quaternion();
  5226. return function ( optionalTarget ) {
  5227. var result = optionalTarget || new THREE.Vector3();
  5228. this.getWorldQuaternion( quaternion );
  5229. return result.set( 0, 0, 1 ).applyQuaternion( quaternion );
  5230. };
  5231. }(),
  5232. raycast: function () {},
  5233. traverse: function ( callback ) {
  5234. callback( this );
  5235. var children = this.children;
  5236. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5237. children[ i ].traverse( callback );
  5238. }
  5239. },
  5240. traverseVisible: function ( callback ) {
  5241. if ( this.visible === false ) return;
  5242. callback( this );
  5243. var children = this.children;
  5244. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5245. children[ i ].traverseVisible( callback );
  5246. }
  5247. },
  5248. traverseAncestors: function ( callback ) {
  5249. var parent = this.parent;
  5250. if ( parent !== null ) {
  5251. callback( parent );
  5252. parent.traverseAncestors( callback );
  5253. }
  5254. },
  5255. updateMatrix: function () {
  5256. this.matrix.compose( this.position, this.quaternion, this.scale );
  5257. this.matrixWorldNeedsUpdate = true;
  5258. },
  5259. updateMatrixWorld: function ( force ) {
  5260. if ( this.matrixAutoUpdate === true ) this.updateMatrix();
  5261. if ( this.matrixWorldNeedsUpdate === true || force === true ) {
  5262. if ( this.parent === null ) {
  5263. this.matrixWorld.copy( this.matrix );
  5264. } else {
  5265. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  5266. }
  5267. this.matrixWorldNeedsUpdate = false;
  5268. force = true;
  5269. }
  5270. // update children
  5271. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  5272. this.children[ i ].updateMatrixWorld( force );
  5273. }
  5274. },
  5275. toJSON: function ( meta ) {
  5276. var isRootObject = ( meta === undefined );
  5277. var output = {};
  5278. // meta is a hash used to collect geometries, materials.
  5279. // not providing it implies that this is the root object
  5280. // being serialized.
  5281. if ( isRootObject ) {
  5282. // initialize meta obj
  5283. meta = {
  5284. geometries: {},
  5285. materials: {},
  5286. textures: {},
  5287. images: {}
  5288. };
  5289. output.metadata = {
  5290. version: 4.4,
  5291. type: 'Object',
  5292. generator: 'Object3D.toJSON'
  5293. };
  5294. }
  5295. // standard Object3D serialization
  5296. var object = {};
  5297. object.uuid = this.uuid;
  5298. object.type = this.type;
  5299. if ( this.name !== '' ) object.name = this.name;
  5300. if ( JSON.stringify( this.userData ) !== '{}' ) object.userData = this.userData;
  5301. if ( this.castShadow === true ) object.castShadow = true;
  5302. if ( this.receiveShadow === true ) object.receiveShadow = true;
  5303. if ( this.visible === false ) object.visible = false;
  5304. object.matrix = this.matrix.toArray();
  5305. //
  5306. if ( this.geometry !== undefined ) {
  5307. if ( meta.geometries[ this.geometry.uuid ] === undefined ) {
  5308. meta.geometries[ this.geometry.uuid ] = this.geometry.toJSON( meta );
  5309. }
  5310. object.geometry = this.geometry.uuid;
  5311. }
  5312. if ( this.material !== undefined ) {
  5313. if ( meta.materials[ this.material.uuid ] === undefined ) {
  5314. meta.materials[ this.material.uuid ] = this.material.toJSON( meta );
  5315. }
  5316. object.material = this.material.uuid;
  5317. }
  5318. //
  5319. if ( this.children.length > 0 ) {
  5320. object.children = [];
  5321. for ( var i = 0; i < this.children.length; i ++ ) {
  5322. object.children.push( this.children[ i ].toJSON( meta ).object );
  5323. }
  5324. }
  5325. if ( isRootObject ) {
  5326. var geometries = extractFromCache( meta.geometries );
  5327. var materials = extractFromCache( meta.materials );
  5328. var textures = extractFromCache( meta.textures );
  5329. var images = extractFromCache( meta.images );
  5330. if ( geometries.length > 0 ) output.geometries = geometries;
  5331. if ( materials.length > 0 ) output.materials = materials;
  5332. if ( textures.length > 0 ) output.textures = textures;
  5333. if ( images.length > 0 ) output.images = images;
  5334. }
  5335. output.object = object;
  5336. return output;
  5337. // extract data from the cache hash
  5338. // remove metadata on each item
  5339. // and return as array
  5340. function extractFromCache ( cache ) {
  5341. var values = [];
  5342. for ( var key in cache ) {
  5343. var data = cache[ key ];
  5344. delete data.metadata;
  5345. values.push( data );
  5346. }
  5347. return values;
  5348. }
  5349. },
  5350. clone: function ( recursive ) {
  5351. return new this.constructor().copy( this, recursive );
  5352. },
  5353. copy: function ( source, recursive ) {
  5354. if ( recursive === undefined ) recursive = true;
  5355. this.name = source.name;
  5356. this.up.copy( source.up );
  5357. this.position.copy( source.position );
  5358. this.quaternion.copy( source.quaternion );
  5359. this.scale.copy( source.scale );
  5360. this.rotationAutoUpdate = source.rotationAutoUpdate;
  5361. this.matrix.copy( source.matrix );
  5362. this.matrixWorld.copy( source.matrixWorld );
  5363. this.matrixAutoUpdate = source.matrixAutoUpdate;
  5364. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  5365. this.visible = source.visible;
  5366. this.castShadow = source.castShadow;
  5367. this.receiveShadow = source.receiveShadow;
  5368. this.frustumCulled = source.frustumCulled;
  5369. this.renderOrder = source.renderOrder;
  5370. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  5371. if ( recursive === true ) {
  5372. for ( var i = 0; i < source.children.length; i ++ ) {
  5373. var child = source.children[ i ];
  5374. this.add( child.clone() );
  5375. }
  5376. }
  5377. return this;
  5378. }
  5379. };
  5380. THREE.EventDispatcher.prototype.apply( THREE.Object3D.prototype );
  5381. THREE.Object3DIdCount = 0;
  5382. // File:src/core/Face3.js
  5383. /**
  5384. * @author mrdoob / http://mrdoob.com/
  5385. * @author alteredq / http://alteredqualia.com/
  5386. */
  5387. THREE.Face3 = function ( a, b, c, normal, color, materialIndex ) {
  5388. this.a = a;
  5389. this.b = b;
  5390. this.c = c;
  5391. this.normal = normal instanceof THREE.Vector3 ? normal : new THREE.Vector3();
  5392. this.vertexNormals = Array.isArray( normal ) ? normal : [];
  5393. this.color = color instanceof THREE.Color ? color : new THREE.Color();
  5394. this.vertexColors = Array.isArray( color ) ? color : [];
  5395. this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
  5396. };
  5397. THREE.Face3.prototype = {
  5398. constructor: THREE.Face3,
  5399. clone: function () {
  5400. return new this.constructor().copy( this );
  5401. },
  5402. copy: function ( source ) {
  5403. this.a = source.a;
  5404. this.b = source.b;
  5405. this.c = source.c;
  5406. this.normal.copy( source.normal );
  5407. this.color.copy( source.color );
  5408. this.materialIndex = source.materialIndex;
  5409. for ( var i = 0, il = source.vertexNormals.length; i < il; i ++ ) {
  5410. this.vertexNormals[ i ] = source.vertexNormals[ i ].clone();
  5411. }
  5412. for ( var i = 0, il = source.vertexColors.length; i < il; i ++ ) {
  5413. this.vertexColors[ i ] = source.vertexColors[ i ].clone();
  5414. }
  5415. return this;
  5416. }
  5417. };
  5418. // File:src/core/BufferAttribute.js
  5419. /**
  5420. * @author mrdoob / http://mrdoob.com/
  5421. */
  5422. THREE.BufferAttribute = function ( array, itemSize ) {
  5423. this.uuid = THREE.Math.generateUUID();
  5424. this.array = array;
  5425. this.itemSize = itemSize;
  5426. this.dynamic = false;
  5427. this.updateRange = { offset: 0, count: - 1 };
  5428. this.version = 0;
  5429. };
  5430. THREE.BufferAttribute.prototype = {
  5431. constructor: THREE.BufferAttribute,
  5432. get count() {
  5433. return this.array.length / this.itemSize;
  5434. },
  5435. set needsUpdate( value ) {
  5436. if ( value === true ) this.version ++;
  5437. },
  5438. setDynamic: function ( value ) {
  5439. this.dynamic = value;
  5440. return this;
  5441. },
  5442. copy: function ( source ) {
  5443. this.array = new source.array.constructor( source.array );
  5444. this.itemSize = source.itemSize;
  5445. this.dynamic = source.dynamic;
  5446. return this;
  5447. },
  5448. copyAt: function ( index1, attribute, index2 ) {
  5449. index1 *= this.itemSize;
  5450. index2 *= attribute.itemSize;
  5451. for ( var i = 0, l = this.itemSize; i < l; i ++ ) {
  5452. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5453. }
  5454. return this;
  5455. },
  5456. copyArray: function ( array ) {
  5457. this.array.set( array );
  5458. return this;
  5459. },
  5460. copyColorsArray: function ( colors ) {
  5461. var array = this.array, offset = 0;
  5462. for ( var i = 0, l = colors.length; i < l; i ++ ) {
  5463. var color = colors[ i ];
  5464. if ( color === undefined ) {
  5465. console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
  5466. color = new THREE.Color();
  5467. }
  5468. array[ offset ++ ] = color.r;
  5469. array[ offset ++ ] = color.g;
  5470. array[ offset ++ ] = color.b;
  5471. }
  5472. return this;
  5473. },
  5474. copyIndicesArray: function ( indices ) {
  5475. var array = this.array, offset = 0;
  5476. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  5477. var index = indices[ i ];
  5478. array[ offset ++ ] = index.a;
  5479. array[ offset ++ ] = index.b;
  5480. array[ offset ++ ] = index.c;
  5481. }
  5482. return this;
  5483. },
  5484. copyVector2sArray: function ( vectors ) {
  5485. var array = this.array, offset = 0;
  5486. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5487. var vector = vectors[ i ];
  5488. if ( vector === undefined ) {
  5489. console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
  5490. vector = new THREE.Vector2();
  5491. }
  5492. array[ offset ++ ] = vector.x;
  5493. array[ offset ++ ] = vector.y;
  5494. }
  5495. return this;
  5496. },
  5497. copyVector3sArray: function ( vectors ) {
  5498. var array = this.array, offset = 0;
  5499. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5500. var vector = vectors[ i ];
  5501. if ( vector === undefined ) {
  5502. console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
  5503. vector = new THREE.Vector3();
  5504. }
  5505. array[ offset ++ ] = vector.x;
  5506. array[ offset ++ ] = vector.y;
  5507. array[ offset ++ ] = vector.z;
  5508. }
  5509. return this;
  5510. },
  5511. copyVector4sArray: 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.copyVector4sArray(): vector is undefined', i );
  5517. vector = new THREE.Vector4();
  5518. }
  5519. array[ offset ++ ] = vector.x;
  5520. array[ offset ++ ] = vector.y;
  5521. array[ offset ++ ] = vector.z;
  5522. array[ offset ++ ] = vector.w;
  5523. }
  5524. return this;
  5525. },
  5526. set: function ( value, offset ) {
  5527. if ( offset === undefined ) offset = 0;
  5528. this.array.set( value, offset );
  5529. return this;
  5530. },
  5531. getX: function ( index ) {
  5532. return this.array[ index * this.itemSize ];
  5533. },
  5534. setX: function ( index, x ) {
  5535. this.array[ index * this.itemSize ] = x;
  5536. return this;
  5537. },
  5538. getY: function ( index ) {
  5539. return this.array[ index * this.itemSize + 1 ];
  5540. },
  5541. setY: function ( index, y ) {
  5542. this.array[ index * this.itemSize + 1 ] = y;
  5543. return this;
  5544. },
  5545. getZ: function ( index ) {
  5546. return this.array[ index * this.itemSize + 2 ];
  5547. },
  5548. setZ: function ( index, z ) {
  5549. this.array[ index * this.itemSize + 2 ] = z;
  5550. return this;
  5551. },
  5552. getW: function ( index ) {
  5553. return this.array[ index * this.itemSize + 3 ];
  5554. },
  5555. setW: function ( index, w ) {
  5556. this.array[ index * this.itemSize + 3 ] = w;
  5557. return this;
  5558. },
  5559. setXY: function ( index, x, y ) {
  5560. index *= this.itemSize;
  5561. this.array[ index + 0 ] = x;
  5562. this.array[ index + 1 ] = y;
  5563. return this;
  5564. },
  5565. setXYZ: function ( index, x, y, z ) {
  5566. index *= this.itemSize;
  5567. this.array[ index + 0 ] = x;
  5568. this.array[ index + 1 ] = y;
  5569. this.array[ index + 2 ] = z;
  5570. return this;
  5571. },
  5572. setXYZW: function ( index, x, y, z, w ) {
  5573. index *= this.itemSize;
  5574. this.array[ index + 0 ] = x;
  5575. this.array[ index + 1 ] = y;
  5576. this.array[ index + 2 ] = z;
  5577. this.array[ index + 3 ] = w;
  5578. return this;
  5579. },
  5580. clone: function () {
  5581. return new this.constructor().copy( this );
  5582. }
  5583. };
  5584. //
  5585. THREE.Int8Attribute = function ( array, itemSize ) {
  5586. return new THREE.BufferAttribute( new Int8Array( array ), itemSize );
  5587. };
  5588. THREE.Uint8Attribute = function ( array, itemSize ) {
  5589. return new THREE.BufferAttribute( new Uint8Array( array ), itemSize );
  5590. };
  5591. THREE.Uint8ClampedAttribute = function ( array, itemSize ) {
  5592. return new THREE.BufferAttribute( new Uint8ClampedArray( array ), itemSize );
  5593. };
  5594. THREE.Int16Attribute = function ( array, itemSize ) {
  5595. return new THREE.BufferAttribute( new Int16Array( array ), itemSize );
  5596. };
  5597. THREE.Uint16Attribute = function ( array, itemSize ) {
  5598. return new THREE.BufferAttribute( new Uint16Array( array ), itemSize );
  5599. };
  5600. THREE.Int32Attribute = function ( array, itemSize ) {
  5601. return new THREE.BufferAttribute( new Int32Array( array ), itemSize );
  5602. };
  5603. THREE.Uint32Attribute = function ( array, itemSize ) {
  5604. return new THREE.BufferAttribute( new Uint32Array( array ), itemSize );
  5605. };
  5606. THREE.Float32Attribute = function ( array, itemSize ) {
  5607. return new THREE.BufferAttribute( new Float32Array( array ), itemSize );
  5608. };
  5609. THREE.Float64Attribute = function ( array, itemSize ) {
  5610. return new THREE.BufferAttribute( new Float64Array( array ), itemSize );
  5611. };
  5612. // Deprecated
  5613. THREE.DynamicBufferAttribute = function ( array, itemSize ) {
  5614. console.warn( 'THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setDynamic( true ) instead.' );
  5615. return new THREE.BufferAttribute( array, itemSize ).setDynamic( true );
  5616. };
  5617. // File:src/core/InstancedBufferAttribute.js
  5618. /**
  5619. * @author benaadams / https://twitter.com/ben_a_adams
  5620. */
  5621. THREE.InstancedBufferAttribute = function ( array, itemSize, meshPerAttribute ) {
  5622. THREE.BufferAttribute.call( this, array, itemSize );
  5623. this.meshPerAttribute = meshPerAttribute || 1;
  5624. };
  5625. THREE.InstancedBufferAttribute.prototype = Object.create( THREE.BufferAttribute.prototype );
  5626. THREE.InstancedBufferAttribute.prototype.constructor = THREE.InstancedBufferAttribute;
  5627. THREE.InstancedBufferAttribute.prototype.copy = function ( source ) {
  5628. THREE.BufferAttribute.prototype.copy.call( this, source );
  5629. this.meshPerAttribute = source.meshPerAttribute;
  5630. return this;
  5631. };
  5632. // File:src/core/InterleavedBuffer.js
  5633. /**
  5634. * @author benaadams / https://twitter.com/ben_a_adams
  5635. */
  5636. THREE.InterleavedBuffer = function ( array, stride ) {
  5637. this.uuid = THREE.Math.generateUUID();
  5638. this.array = array;
  5639. this.stride = stride;
  5640. this.dynamic = false;
  5641. this.updateRange = { offset: 0, count: - 1 };
  5642. this.version = 0;
  5643. };
  5644. THREE.InterleavedBuffer.prototype = {
  5645. constructor: THREE.InterleavedBuffer,
  5646. get length () {
  5647. return this.array.length;
  5648. },
  5649. get count () {
  5650. return this.array.length / this.stride;
  5651. },
  5652. set needsUpdate( value ) {
  5653. if ( value === true ) this.version ++;
  5654. },
  5655. setDynamic: function ( value ) {
  5656. this.dynamic = value;
  5657. return this;
  5658. },
  5659. copy: function ( source ) {
  5660. this.array = new source.array.constructor( source.array );
  5661. this.stride = source.stride;
  5662. this.dynamic = source.dynamic;
  5663. return this;
  5664. },
  5665. copyAt: function ( index1, attribute, index2 ) {
  5666. index1 *= this.stride;
  5667. index2 *= attribute.stride;
  5668. for ( var i = 0, l = this.stride; i < l; i ++ ) {
  5669. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5670. }
  5671. return this;
  5672. },
  5673. set: function ( value, offset ) {
  5674. if ( offset === undefined ) offset = 0;
  5675. this.array.set( value, offset );
  5676. return this;
  5677. },
  5678. clone: function () {
  5679. return new this.constructor().copy( this );
  5680. }
  5681. };
  5682. // File:src/core/InstancedInterleavedBuffer.js
  5683. /**
  5684. * @author benaadams / https://twitter.com/ben_a_adams
  5685. */
  5686. THREE.InstancedInterleavedBuffer = function ( array, stride, meshPerAttribute ) {
  5687. THREE.InterleavedBuffer.call( this, array, stride );
  5688. this.meshPerAttribute = meshPerAttribute || 1;
  5689. };
  5690. THREE.InstancedInterleavedBuffer.prototype = Object.create( THREE.InterleavedBuffer.prototype );
  5691. THREE.InstancedInterleavedBuffer.prototype.constructor = THREE.InstancedInterleavedBuffer;
  5692. THREE.InstancedInterleavedBuffer.prototype.copy = function ( source ) {
  5693. THREE.InterleavedBuffer.prototype.copy.call( this, source );
  5694. this.meshPerAttribute = source.meshPerAttribute;
  5695. return this;
  5696. };
  5697. // File:src/core/InterleavedBufferAttribute.js
  5698. /**
  5699. * @author benaadams / https://twitter.com/ben_a_adams
  5700. */
  5701. THREE.InterleavedBufferAttribute = function ( interleavedBuffer, itemSize, offset ) {
  5702. this.uuid = THREE.Math.generateUUID();
  5703. this.data = interleavedBuffer;
  5704. this.itemSize = itemSize;
  5705. this.offset = offset;
  5706. };
  5707. THREE.InterleavedBufferAttribute.prototype = {
  5708. constructor: THREE.InterleavedBufferAttribute,
  5709. get length() {
  5710. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Please use .count.' );
  5711. return this.array.length;
  5712. },
  5713. get count() {
  5714. return this.data.count;
  5715. },
  5716. setX: function ( index, x ) {
  5717. this.data.array[ index * this.data.stride + this.offset ] = x;
  5718. return this;
  5719. },
  5720. setY: function ( index, y ) {
  5721. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  5722. return this;
  5723. },
  5724. setZ: function ( index, z ) {
  5725. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  5726. return this;
  5727. },
  5728. setW: function ( index, w ) {
  5729. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  5730. return this;
  5731. },
  5732. getX: function ( index ) {
  5733. return this.data.array[ index * this.data.stride + this.offset ];
  5734. },
  5735. getY: function ( index ) {
  5736. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  5737. },
  5738. getZ: function ( index ) {
  5739. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  5740. },
  5741. getW: function ( index ) {
  5742. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  5743. },
  5744. setXY: function ( index, x, y ) {
  5745. index = index * this.data.stride + this.offset;
  5746. this.data.array[ index + 0 ] = x;
  5747. this.data.array[ index + 1 ] = y;
  5748. return this;
  5749. },
  5750. setXYZ: function ( index, x, y, z ) {
  5751. index = index * this.data.stride + this.offset;
  5752. this.data.array[ index + 0 ] = x;
  5753. this.data.array[ index + 1 ] = y;
  5754. this.data.array[ index + 2 ] = z;
  5755. return this;
  5756. },
  5757. setXYZW: function ( index, x, y, z, w ) {
  5758. index = index * this.data.stride + this.offset;
  5759. this.data.array[ index + 0 ] = x;
  5760. this.data.array[ index + 1 ] = y;
  5761. this.data.array[ index + 2 ] = z;
  5762. this.data.array[ index + 3 ] = w;
  5763. return this;
  5764. }
  5765. };
  5766. // File:src/core/Geometry.js
  5767. /**
  5768. * @author mrdoob / http://mrdoob.com/
  5769. * @author kile / http://kile.stravaganza.org/
  5770. * @author alteredq / http://alteredqualia.com/
  5771. * @author mikael emtinger / http://gomo.se/
  5772. * @author zz85 / http://www.lab4games.net/zz85/blog
  5773. * @author bhouston / http://clara.io
  5774. */
  5775. THREE.Geometry = function () {
  5776. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  5777. this.uuid = THREE.Math.generateUUID();
  5778. this.name = '';
  5779. this.type = 'Geometry';
  5780. this.vertices = [];
  5781. this.colors = [];
  5782. this.faces = [];
  5783. this.faceVertexUvs = [ [] ];
  5784. this.morphTargets = [];
  5785. this.morphNormals = [];
  5786. this.skinWeights = [];
  5787. this.skinIndices = [];
  5788. this.lineDistances = [];
  5789. this.boundingBox = null;
  5790. this.boundingSphere = null;
  5791. // update flags
  5792. this.verticesNeedUpdate = false;
  5793. this.elementsNeedUpdate = false;
  5794. this.uvsNeedUpdate = false;
  5795. this.normalsNeedUpdate = false;
  5796. this.colorsNeedUpdate = false;
  5797. this.lineDistancesNeedUpdate = false;
  5798. this.groupsNeedUpdate = false;
  5799. };
  5800. THREE.Geometry.prototype = {
  5801. constructor: THREE.Geometry,
  5802. applyMatrix: function ( matrix ) {
  5803. var normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  5804. for ( var i = 0, il = this.vertices.length; i < il; i ++ ) {
  5805. var vertex = this.vertices[ i ];
  5806. vertex.applyMatrix4( matrix );
  5807. }
  5808. for ( var i = 0, il = this.faces.length; i < il; i ++ ) {
  5809. var face = this.faces[ i ];
  5810. face.normal.applyMatrix3( normalMatrix ).normalize();
  5811. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  5812. face.vertexNormals[ j ].applyMatrix3( normalMatrix ).normalize();
  5813. }
  5814. }
  5815. if ( this.boundingBox !== null ) {
  5816. this.computeBoundingBox();
  5817. }
  5818. if ( this.boundingSphere !== null ) {
  5819. this.computeBoundingSphere();
  5820. }
  5821. this.verticesNeedUpdate = true;
  5822. this.normalsNeedUpdate = true;
  5823. return this;
  5824. },
  5825. rotateX: function () {
  5826. // rotate geometry around world x-axis
  5827. var m1;
  5828. return function rotateX( angle ) {
  5829. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5830. m1.makeRotationX( angle );
  5831. this.applyMatrix( m1 );
  5832. return this;
  5833. };
  5834. }(),
  5835. rotateY: function () {
  5836. // rotate geometry around world y-axis
  5837. var m1;
  5838. return function rotateY( angle ) {
  5839. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5840. m1.makeRotationY( angle );
  5841. this.applyMatrix( m1 );
  5842. return this;
  5843. };
  5844. }(),
  5845. rotateZ: function () {
  5846. // rotate geometry around world z-axis
  5847. var m1;
  5848. return function rotateZ( angle ) {
  5849. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5850. m1.makeRotationZ( angle );
  5851. this.applyMatrix( m1 );
  5852. return this;
  5853. };
  5854. }(),
  5855. translate: function () {
  5856. // translate geometry
  5857. var m1;
  5858. return function translate( x, y, z ) {
  5859. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5860. m1.makeTranslation( x, y, z );
  5861. this.applyMatrix( m1 );
  5862. return this;
  5863. };
  5864. }(),
  5865. scale: function () {
  5866. // scale geometry
  5867. var m1;
  5868. return function scale( x, y, z ) {
  5869. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5870. m1.makeScale( x, y, z );
  5871. this.applyMatrix( m1 );
  5872. return this;
  5873. };
  5874. }(),
  5875. lookAt: function () {
  5876. var obj;
  5877. return function lookAt( vector ) {
  5878. if ( obj === undefined ) obj = new THREE.Object3D();
  5879. obj.lookAt( vector );
  5880. obj.updateMatrix();
  5881. this.applyMatrix( obj.matrix );
  5882. };
  5883. }(),
  5884. fromBufferGeometry: function ( geometry ) {
  5885. var scope = this;
  5886. var indices = geometry.index !== null ? geometry.index.array : undefined;
  5887. var attributes = geometry.attributes;
  5888. var positions = attributes.position.array;
  5889. var normals = attributes.normal !== undefined ? attributes.normal.array : undefined;
  5890. var colors = attributes.color !== undefined ? attributes.color.array : undefined;
  5891. var uvs = attributes.uv !== undefined ? attributes.uv.array : undefined;
  5892. var uvs2 = attributes.uv2 !== undefined ? attributes.uv2.array : undefined;
  5893. if ( uvs2 !== undefined ) this.faceVertexUvs[ 1 ] = [];
  5894. var tempNormals = [];
  5895. var tempUVs = [];
  5896. var tempUVs2 = [];
  5897. for ( var i = 0, j = 0; i < positions.length; i += 3, j += 2 ) {
  5898. scope.vertices.push( new THREE.Vector3( positions[ i ], positions[ i + 1 ], positions[ i + 2 ] ) );
  5899. if ( normals !== undefined ) {
  5900. tempNormals.push( new THREE.Vector3( normals[ i ], normals[ i + 1 ], normals[ i + 2 ] ) );
  5901. }
  5902. if ( colors !== undefined ) {
  5903. scope.colors.push( new THREE.Color( colors[ i ], colors[ i + 1 ], colors[ i + 2 ] ) );
  5904. }
  5905. if ( uvs !== undefined ) {
  5906. tempUVs.push( new THREE.Vector2( uvs[ j ], uvs[ j + 1 ] ) );
  5907. }
  5908. if ( uvs2 !== undefined ) {
  5909. tempUVs2.push( new THREE.Vector2( uvs2[ j ], uvs2[ j + 1 ] ) );
  5910. }
  5911. }
  5912. function addFace( a, b, c, materialIndex ) {
  5913. var vertexNormals = normals !== undefined ? [ tempNormals[ a ].clone(), tempNormals[ b ].clone(), tempNormals[ c ].clone() ] : [];
  5914. var vertexColors = colors !== undefined ? [ scope.colors[ a ].clone(), scope.colors[ b ].clone(), scope.colors[ c ].clone() ] : [];
  5915. var face = new THREE.Face3( a, b, c, vertexNormals, vertexColors, materialIndex );
  5916. scope.faces.push( face );
  5917. if ( uvs !== undefined ) {
  5918. scope.faceVertexUvs[ 0 ].push( [ tempUVs[ a ].clone(), tempUVs[ b ].clone(), tempUVs[ c ].clone() ] );
  5919. }
  5920. if ( uvs2 !== undefined ) {
  5921. scope.faceVertexUvs[ 1 ].push( [ tempUVs2[ a ].clone(), tempUVs2[ b ].clone(), tempUVs2[ c ].clone() ] );
  5922. }
  5923. }
  5924. if ( indices !== undefined ) {
  5925. var groups = geometry.groups;
  5926. if ( groups.length > 0 ) {
  5927. for ( var i = 0; i < groups.length; i ++ ) {
  5928. var group = groups[ i ];
  5929. var start = group.start;
  5930. var count = group.count;
  5931. for ( var j = start, jl = start + count; j < jl; j += 3 ) {
  5932. addFace( indices[ j ], indices[ j + 1 ], indices[ j + 2 ], group.materialIndex );
  5933. }
  5934. }
  5935. } else {
  5936. for ( var i = 0; i < indices.length; i += 3 ) {
  5937. addFace( indices[ i ], indices[ i + 1 ], indices[ i + 2 ] );
  5938. }
  5939. }
  5940. } else {
  5941. for ( var i = 0; i < positions.length / 3; i += 3 ) {
  5942. addFace( i, i + 1, i + 2 );
  5943. }
  5944. }
  5945. this.computeFaceNormals();
  5946. if ( geometry.boundingBox !== null ) {
  5947. this.boundingBox = geometry.boundingBox.clone();
  5948. }
  5949. if ( geometry.boundingSphere !== null ) {
  5950. this.boundingSphere = geometry.boundingSphere.clone();
  5951. }
  5952. return this;
  5953. },
  5954. center: function () {
  5955. this.computeBoundingBox();
  5956. var offset = this.boundingBox.center().negate();
  5957. this.translate( offset.x, offset.y, offset.z );
  5958. return offset;
  5959. },
  5960. normalize: function () {
  5961. this.computeBoundingSphere();
  5962. var center = this.boundingSphere.center;
  5963. var radius = this.boundingSphere.radius;
  5964. var s = radius === 0 ? 1 : 1.0 / radius;
  5965. var matrix = new THREE.Matrix4();
  5966. matrix.set(
  5967. s, 0, 0, - s * center.x,
  5968. 0, s, 0, - s * center.y,
  5969. 0, 0, s, - s * center.z,
  5970. 0, 0, 0, 1
  5971. );
  5972. this.applyMatrix( matrix );
  5973. return this;
  5974. },
  5975. computeFaceNormals: function () {
  5976. var cb = new THREE.Vector3(), ab = new THREE.Vector3();
  5977. for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5978. var face = this.faces[ f ];
  5979. var vA = this.vertices[ face.a ];
  5980. var vB = this.vertices[ face.b ];
  5981. var vC = this.vertices[ face.c ];
  5982. cb.subVectors( vC, vB );
  5983. ab.subVectors( vA, vB );
  5984. cb.cross( ab );
  5985. cb.normalize();
  5986. face.normal.copy( cb );
  5987. }
  5988. },
  5989. computeVertexNormals: function ( areaWeighted ) {
  5990. if ( areaWeighted === undefined ) areaWeighted = true;
  5991. var v, vl, f, fl, face, vertices;
  5992. vertices = new Array( this.vertices.length );
  5993. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5994. vertices[ v ] = new THREE.Vector3();
  5995. }
  5996. if ( areaWeighted ) {
  5997. // vertex normals weighted by triangle areas
  5998. // http://www.iquilezles.org/www/articles/normals/normals.htm
  5999. var vA, vB, vC;
  6000. var cb = new THREE.Vector3(), ab = new THREE.Vector3();
  6001. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6002. face = this.faces[ f ];
  6003. vA = this.vertices[ face.a ];
  6004. vB = this.vertices[ face.b ];
  6005. vC = this.vertices[ face.c ];
  6006. cb.subVectors( vC, vB );
  6007. ab.subVectors( vA, vB );
  6008. cb.cross( ab );
  6009. vertices[ face.a ].add( cb );
  6010. vertices[ face.b ].add( cb );
  6011. vertices[ face.c ].add( cb );
  6012. }
  6013. } else {
  6014. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6015. face = this.faces[ f ];
  6016. vertices[ face.a ].add( face.normal );
  6017. vertices[ face.b ].add( face.normal );
  6018. vertices[ face.c ].add( face.normal );
  6019. }
  6020. }
  6021. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  6022. vertices[ v ].normalize();
  6023. }
  6024. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6025. face = this.faces[ f ];
  6026. var vertexNormals = face.vertexNormals;
  6027. if ( vertexNormals.length === 3 ) {
  6028. vertexNormals[ 0 ].copy( vertices[ face.a ] );
  6029. vertexNormals[ 1 ].copy( vertices[ face.b ] );
  6030. vertexNormals[ 2 ].copy( vertices[ face.c ] );
  6031. } else {
  6032. vertexNormals[ 0 ] = vertices[ face.a ].clone();
  6033. vertexNormals[ 1 ] = vertices[ face.b ].clone();
  6034. vertexNormals[ 2 ] = vertices[ face.c ].clone();
  6035. }
  6036. }
  6037. if ( this.faces.length > 0 ) {
  6038. this.normalsNeedUpdate = true;
  6039. }
  6040. },
  6041. computeMorphNormals: function () {
  6042. var i, il, f, fl, face;
  6043. // save original normals
  6044. // - create temp variables on first access
  6045. // otherwise just copy (for faster repeated calls)
  6046. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6047. face = this.faces[ f ];
  6048. if ( ! face.__originalFaceNormal ) {
  6049. face.__originalFaceNormal = face.normal.clone();
  6050. } else {
  6051. face.__originalFaceNormal.copy( face.normal );
  6052. }
  6053. if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
  6054. for ( i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
  6055. if ( ! face.__originalVertexNormals[ i ] ) {
  6056. face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
  6057. } else {
  6058. face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
  6059. }
  6060. }
  6061. }
  6062. // use temp geometry to compute face and vertex normals for each morph
  6063. var tmpGeo = new THREE.Geometry();
  6064. tmpGeo.faces = this.faces;
  6065. for ( i = 0, il = this.morphTargets.length; i < il; i ++ ) {
  6066. // create on first access
  6067. if ( ! this.morphNormals[ i ] ) {
  6068. this.morphNormals[ i ] = {};
  6069. this.morphNormals[ i ].faceNormals = [];
  6070. this.morphNormals[ i ].vertexNormals = [];
  6071. var dstNormalsFace = this.morphNormals[ i ].faceNormals;
  6072. var dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
  6073. var faceNormal, vertexNormals;
  6074. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6075. faceNormal = new THREE.Vector3();
  6076. vertexNormals = { a: new THREE.Vector3(), b: new THREE.Vector3(), c: new THREE.Vector3() };
  6077. dstNormalsFace.push( faceNormal );
  6078. dstNormalsVertex.push( vertexNormals );
  6079. }
  6080. }
  6081. var morphNormals = this.morphNormals[ i ];
  6082. // set vertices to morph target
  6083. tmpGeo.vertices = this.morphTargets[ i ].vertices;
  6084. // compute morph normals
  6085. tmpGeo.computeFaceNormals();
  6086. tmpGeo.computeVertexNormals();
  6087. // store morph normals
  6088. var faceNormal, vertexNormals;
  6089. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6090. face = this.faces[ f ];
  6091. faceNormal = morphNormals.faceNormals[ f ];
  6092. vertexNormals = morphNormals.vertexNormals[ f ];
  6093. faceNormal.copy( face.normal );
  6094. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  6095. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  6096. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  6097. }
  6098. }
  6099. // restore original normals
  6100. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6101. face = this.faces[ f ];
  6102. face.normal = face.__originalFaceNormal;
  6103. face.vertexNormals = face.__originalVertexNormals;
  6104. }
  6105. },
  6106. computeTangents: function () {
  6107. console.warn( 'THREE.Geometry: .computeTangents() has been removed.' );
  6108. },
  6109. computeLineDistances: function () {
  6110. var d = 0;
  6111. var vertices = this.vertices;
  6112. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  6113. if ( i > 0 ) {
  6114. d += vertices[ i ].distanceTo( vertices[ i - 1 ] );
  6115. }
  6116. this.lineDistances[ i ] = d;
  6117. }
  6118. },
  6119. computeBoundingBox: function () {
  6120. if ( this.boundingBox === null ) {
  6121. this.boundingBox = new THREE.Box3();
  6122. }
  6123. this.boundingBox.setFromPoints( this.vertices );
  6124. },
  6125. computeBoundingSphere: function () {
  6126. if ( this.boundingSphere === null ) {
  6127. this.boundingSphere = new THREE.Sphere();
  6128. }
  6129. this.boundingSphere.setFromPoints( this.vertices );
  6130. },
  6131. merge: function ( geometry, matrix, materialIndexOffset ) {
  6132. if ( geometry instanceof THREE.Geometry === false ) {
  6133. console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry );
  6134. return;
  6135. }
  6136. var normalMatrix,
  6137. vertexOffset = this.vertices.length,
  6138. vertices1 = this.vertices,
  6139. vertices2 = geometry.vertices,
  6140. faces1 = this.faces,
  6141. faces2 = geometry.faces,
  6142. uvs1 = this.faceVertexUvs[ 0 ],
  6143. uvs2 = geometry.faceVertexUvs[ 0 ];
  6144. if ( materialIndexOffset === undefined ) materialIndexOffset = 0;
  6145. if ( matrix !== undefined ) {
  6146. normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  6147. }
  6148. // vertices
  6149. for ( var i = 0, il = vertices2.length; i < il; i ++ ) {
  6150. var vertex = vertices2[ i ];
  6151. var vertexCopy = vertex.clone();
  6152. if ( matrix !== undefined ) vertexCopy.applyMatrix4( matrix );
  6153. vertices1.push( vertexCopy );
  6154. }
  6155. // faces
  6156. for ( i = 0, il = faces2.length; i < il; i ++ ) {
  6157. var face = faces2[ i ], faceCopy, normal, color,
  6158. faceVertexNormals = face.vertexNormals,
  6159. faceVertexColors = face.vertexColors;
  6160. faceCopy = new THREE.Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset );
  6161. faceCopy.normal.copy( face.normal );
  6162. if ( normalMatrix !== undefined ) {
  6163. faceCopy.normal.applyMatrix3( normalMatrix ).normalize();
  6164. }
  6165. for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
  6166. normal = faceVertexNormals[ j ].clone();
  6167. if ( normalMatrix !== undefined ) {
  6168. normal.applyMatrix3( normalMatrix ).normalize();
  6169. }
  6170. faceCopy.vertexNormals.push( normal );
  6171. }
  6172. faceCopy.color.copy( face.color );
  6173. for ( var j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
  6174. color = faceVertexColors[ j ];
  6175. faceCopy.vertexColors.push( color.clone() );
  6176. }
  6177. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  6178. faces1.push( faceCopy );
  6179. }
  6180. // uvs
  6181. for ( i = 0, il = uvs2.length; i < il; i ++ ) {
  6182. var uv = uvs2[ i ], uvCopy = [];
  6183. if ( uv === undefined ) {
  6184. continue;
  6185. }
  6186. for ( var j = 0, jl = uv.length; j < jl; j ++ ) {
  6187. uvCopy.push( uv[ j ].clone() );
  6188. }
  6189. uvs1.push( uvCopy );
  6190. }
  6191. },
  6192. mergeMesh: function ( mesh ) {
  6193. if ( mesh instanceof THREE.Mesh === false ) {
  6194. console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh );
  6195. return;
  6196. }
  6197. mesh.matrixAutoUpdate && mesh.updateMatrix();
  6198. this.merge( mesh.geometry, mesh.matrix );
  6199. },
  6200. /*
  6201. * Checks for duplicate vertices with hashmap.
  6202. * Duplicated vertices are removed
  6203. * and faces' vertices are updated.
  6204. */
  6205. mergeVertices: function () {
  6206. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  6207. var unique = [], changes = [];
  6208. var v, key;
  6209. var precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001
  6210. var precision = Math.pow( 10, precisionPoints );
  6211. var i, il, face;
  6212. var indices, j, jl;
  6213. for ( i = 0, il = this.vertices.length; i < il; i ++ ) {
  6214. v = this.vertices[ i ];
  6215. key = Math.round( v.x * precision ) + '_' + Math.round( v.y * precision ) + '_' + Math.round( v.z * precision );
  6216. if ( verticesMap[ key ] === undefined ) {
  6217. verticesMap[ key ] = i;
  6218. unique.push( this.vertices[ i ] );
  6219. changes[ i ] = unique.length - 1;
  6220. } else {
  6221. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  6222. changes[ i ] = changes[ verticesMap[ key ] ];
  6223. }
  6224. }
  6225. // if faces are completely degenerate after merging vertices, we
  6226. // have to remove them from the geometry.
  6227. var faceIndicesToRemove = [];
  6228. for ( i = 0, il = this.faces.length; i < il; i ++ ) {
  6229. face = this.faces[ i ];
  6230. face.a = changes[ face.a ];
  6231. face.b = changes[ face.b ];
  6232. face.c = changes[ face.c ];
  6233. indices = [ face.a, face.b, face.c ];
  6234. var dupIndex = - 1;
  6235. // if any duplicate vertices are found in a Face3
  6236. // we have to remove the face as nothing can be saved
  6237. for ( var n = 0; n < 3; n ++ ) {
  6238. if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) {
  6239. dupIndex = n;
  6240. faceIndicesToRemove.push( i );
  6241. break;
  6242. }
  6243. }
  6244. }
  6245. for ( i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
  6246. var idx = faceIndicesToRemove[ i ];
  6247. this.faces.splice( idx, 1 );
  6248. for ( j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {
  6249. this.faceVertexUvs[ j ].splice( idx, 1 );
  6250. }
  6251. }
  6252. // Use unique set of vertices
  6253. var diff = this.vertices.length - unique.length;
  6254. this.vertices = unique;
  6255. return diff;
  6256. },
  6257. sortFacesByMaterialIndex: function () {
  6258. var faces = this.faces;
  6259. var length = faces.length;
  6260. // tag faces
  6261. for ( var i = 0; i < length; i ++ ) {
  6262. faces[ i ]._id = i;
  6263. }
  6264. // sort faces
  6265. function materialIndexSort( a, b ) {
  6266. return a.materialIndex - b.materialIndex;
  6267. }
  6268. faces.sort( materialIndexSort );
  6269. // sort uvs
  6270. var uvs1 = this.faceVertexUvs[ 0 ];
  6271. var uvs2 = this.faceVertexUvs[ 1 ];
  6272. var newUvs1, newUvs2;
  6273. if ( uvs1 && uvs1.length === length ) newUvs1 = [];
  6274. if ( uvs2 && uvs2.length === length ) newUvs2 = [];
  6275. for ( var i = 0; i < length; i ++ ) {
  6276. var id = faces[ i ]._id;
  6277. if ( newUvs1 ) newUvs1.push( uvs1[ id ] );
  6278. if ( newUvs2 ) newUvs2.push( uvs2[ id ] );
  6279. }
  6280. if ( newUvs1 ) this.faceVertexUvs[ 0 ] = newUvs1;
  6281. if ( newUvs2 ) this.faceVertexUvs[ 1 ] = newUvs2;
  6282. },
  6283. toJSON: function () {
  6284. var data = {
  6285. metadata: {
  6286. version: 4.4,
  6287. type: 'Geometry',
  6288. generator: 'Geometry.toJSON'
  6289. }
  6290. };
  6291. // standard Geometry serialization
  6292. data.uuid = this.uuid;
  6293. data.type = this.type;
  6294. if ( this.name !== '' ) data.name = this.name;
  6295. if ( this.parameters !== undefined ) {
  6296. var parameters = this.parameters;
  6297. for ( var key in parameters ) {
  6298. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  6299. }
  6300. return data;
  6301. }
  6302. var vertices = [];
  6303. for ( var i = 0; i < this.vertices.length; i ++ ) {
  6304. var vertex = this.vertices[ i ];
  6305. vertices.push( vertex.x, vertex.y, vertex.z );
  6306. }
  6307. var faces = [];
  6308. var normals = [];
  6309. var normalsHash = {};
  6310. var colors = [];
  6311. var colorsHash = {};
  6312. var uvs = [];
  6313. var uvsHash = {};
  6314. for ( var i = 0; i < this.faces.length; i ++ ) {
  6315. var face = this.faces[ i ];
  6316. var hasMaterial = true;
  6317. var hasFaceUv = false; // deprecated
  6318. var hasFaceVertexUv = this.faceVertexUvs[ 0 ][ i ] !== undefined;
  6319. var hasFaceNormal = face.normal.length() > 0;
  6320. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  6321. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  6322. var hasFaceVertexColor = face.vertexColors.length > 0;
  6323. var faceType = 0;
  6324. faceType = setBit( faceType, 0, 0 ); // isQuad
  6325. faceType = setBit( faceType, 1, hasMaterial );
  6326. faceType = setBit( faceType, 2, hasFaceUv );
  6327. faceType = setBit( faceType, 3, hasFaceVertexUv );
  6328. faceType = setBit( faceType, 4, hasFaceNormal );
  6329. faceType = setBit( faceType, 5, hasFaceVertexNormal );
  6330. faceType = setBit( faceType, 6, hasFaceColor );
  6331. faceType = setBit( faceType, 7, hasFaceVertexColor );
  6332. faces.push( faceType );
  6333. faces.push( face.a, face.b, face.c );
  6334. faces.push( face.materialIndex );
  6335. if ( hasFaceVertexUv ) {
  6336. var faceVertexUvs = this.faceVertexUvs[ 0 ][ i ];
  6337. faces.push(
  6338. getUvIndex( faceVertexUvs[ 0 ] ),
  6339. getUvIndex( faceVertexUvs[ 1 ] ),
  6340. getUvIndex( faceVertexUvs[ 2 ] )
  6341. );
  6342. }
  6343. if ( hasFaceNormal ) {
  6344. faces.push( getNormalIndex( face.normal ) );
  6345. }
  6346. if ( hasFaceVertexNormal ) {
  6347. var vertexNormals = face.vertexNormals;
  6348. faces.push(
  6349. getNormalIndex( vertexNormals[ 0 ] ),
  6350. getNormalIndex( vertexNormals[ 1 ] ),
  6351. getNormalIndex( vertexNormals[ 2 ] )
  6352. );
  6353. }
  6354. if ( hasFaceColor ) {
  6355. faces.push( getColorIndex( face.color ) );
  6356. }
  6357. if ( hasFaceVertexColor ) {
  6358. var vertexColors = face.vertexColors;
  6359. faces.push(
  6360. getColorIndex( vertexColors[ 0 ] ),
  6361. getColorIndex( vertexColors[ 1 ] ),
  6362. getColorIndex( vertexColors[ 2 ] )
  6363. );
  6364. }
  6365. }
  6366. function setBit( value, position, enabled ) {
  6367. return enabled ? value | ( 1 << position ) : value & ( ~ ( 1 << position ) );
  6368. }
  6369. function getNormalIndex( normal ) {
  6370. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  6371. if ( normalsHash[ hash ] !== undefined ) {
  6372. return normalsHash[ hash ];
  6373. }
  6374. normalsHash[ hash ] = normals.length / 3;
  6375. normals.push( normal.x, normal.y, normal.z );
  6376. return normalsHash[ hash ];
  6377. }
  6378. function getColorIndex( color ) {
  6379. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  6380. if ( colorsHash[ hash ] !== undefined ) {
  6381. return colorsHash[ hash ];
  6382. }
  6383. colorsHash[ hash ] = colors.length;
  6384. colors.push( color.getHex() );
  6385. return colorsHash[ hash ];
  6386. }
  6387. function getUvIndex( uv ) {
  6388. var hash = uv.x.toString() + uv.y.toString();
  6389. if ( uvsHash[ hash ] !== undefined ) {
  6390. return uvsHash[ hash ];
  6391. }
  6392. uvsHash[ hash ] = uvs.length / 2;
  6393. uvs.push( uv.x, uv.y );
  6394. return uvsHash[ hash ];
  6395. }
  6396. data.data = {};
  6397. data.data.vertices = vertices;
  6398. data.data.normals = normals;
  6399. if ( colors.length > 0 ) data.data.colors = colors;
  6400. if ( uvs.length > 0 ) data.data.uvs = [ uvs ]; // temporal backward compatibility
  6401. data.data.faces = faces;
  6402. return data;
  6403. },
  6404. clone: function () {
  6405. /*
  6406. // Handle primitives
  6407. var parameters = this.parameters;
  6408. if ( parameters !== undefined ) {
  6409. var values = [];
  6410. for ( var key in parameters ) {
  6411. values.push( parameters[ key ] );
  6412. }
  6413. var geometry = Object.create( this.constructor.prototype );
  6414. this.constructor.apply( geometry, values );
  6415. return geometry;
  6416. }
  6417. return new this.constructor().copy( this );
  6418. */
  6419. return new THREE.Geometry().copy( this );
  6420. },
  6421. copy: function ( source ) {
  6422. this.vertices = [];
  6423. this.faces = [];
  6424. this.faceVertexUvs = [ [] ];
  6425. var vertices = source.vertices;
  6426. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  6427. this.vertices.push( vertices[ i ].clone() );
  6428. }
  6429. var faces = source.faces;
  6430. for ( var i = 0, il = faces.length; i < il; i ++ ) {
  6431. this.faces.push( faces[ i ].clone() );
  6432. }
  6433. for ( var i = 0, il = source.faceVertexUvs.length; i < il; i ++ ) {
  6434. var faceVertexUvs = source.faceVertexUvs[ i ];
  6435. if ( this.faceVertexUvs[ i ] === undefined ) {
  6436. this.faceVertexUvs[ i ] = [];
  6437. }
  6438. for ( var j = 0, jl = faceVertexUvs.length; j < jl; j ++ ) {
  6439. var uvs = faceVertexUvs[ j ], uvsCopy = [];
  6440. for ( var k = 0, kl = uvs.length; k < kl; k ++ ) {
  6441. var uv = uvs[ k ];
  6442. uvsCopy.push( uv.clone() );
  6443. }
  6444. this.faceVertexUvs[ i ].push( uvsCopy );
  6445. }
  6446. }
  6447. return this;
  6448. },
  6449. dispose: function () {
  6450. this.dispatchEvent( { type: 'dispose' } );
  6451. }
  6452. };
  6453. THREE.EventDispatcher.prototype.apply( THREE.Geometry.prototype );
  6454. THREE.GeometryIdCount = 0;
  6455. // File:src/core/DirectGeometry.js
  6456. /**
  6457. * @author mrdoob / http://mrdoob.com/
  6458. */
  6459. THREE.DirectGeometry = function () {
  6460. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  6461. this.uuid = THREE.Math.generateUUID();
  6462. this.name = '';
  6463. this.type = 'DirectGeometry';
  6464. this.indices = [];
  6465. this.vertices = [];
  6466. this.normals = [];
  6467. this.colors = [];
  6468. this.uvs = [];
  6469. this.uvs2 = [];
  6470. this.groups = [];
  6471. this.morphTargets = {};
  6472. this.skinWeights = [];
  6473. this.skinIndices = [];
  6474. // this.lineDistances = [];
  6475. this.boundingBox = null;
  6476. this.boundingSphere = null;
  6477. // update flags
  6478. this.verticesNeedUpdate = false;
  6479. this.normalsNeedUpdate = false;
  6480. this.colorsNeedUpdate = false;
  6481. this.uvsNeedUpdate = false;
  6482. this.groupsNeedUpdate = false;
  6483. };
  6484. THREE.DirectGeometry.prototype = {
  6485. constructor: THREE.DirectGeometry,
  6486. computeBoundingBox: THREE.Geometry.prototype.computeBoundingBox,
  6487. computeBoundingSphere: THREE.Geometry.prototype.computeBoundingSphere,
  6488. computeFaceNormals: function () {
  6489. console.warn( 'THREE.DirectGeometry: computeFaceNormals() is not a method of this type of geometry.' );
  6490. },
  6491. computeVertexNormals: function () {
  6492. console.warn( 'THREE.DirectGeometry: computeVertexNormals() is not a method of this type of geometry.' );
  6493. },
  6494. computeGroups: function ( geometry ) {
  6495. var group;
  6496. var groups = [];
  6497. var materialIndex;
  6498. var faces = geometry.faces;
  6499. for ( var i = 0; i < faces.length; i ++ ) {
  6500. var face = faces[ i ];
  6501. // materials
  6502. if ( face.materialIndex !== materialIndex ) {
  6503. materialIndex = face.materialIndex;
  6504. if ( group !== undefined ) {
  6505. group.count = ( i * 3 ) - group.start;
  6506. groups.push( group );
  6507. }
  6508. group = {
  6509. start: i * 3,
  6510. materialIndex: materialIndex
  6511. };
  6512. }
  6513. }
  6514. if ( group !== undefined ) {
  6515. group.count = ( i * 3 ) - group.start;
  6516. groups.push( group );
  6517. }
  6518. this.groups = groups;
  6519. },
  6520. fromGeometry: function ( geometry ) {
  6521. var faces = geometry.faces;
  6522. var vertices = geometry.vertices;
  6523. var faceVertexUvs = geometry.faceVertexUvs;
  6524. var hasFaceVertexUv = faceVertexUvs[ 0 ] && faceVertexUvs[ 0 ].length > 0;
  6525. var hasFaceVertexUv2 = faceVertexUvs[ 1 ] && faceVertexUvs[ 1 ].length > 0;
  6526. // morphs
  6527. var morphTargets = geometry.morphTargets;
  6528. var morphTargetsLength = morphTargets.length;
  6529. var morphTargetsPosition;
  6530. if ( morphTargetsLength > 0 ) {
  6531. morphTargetsPosition = [];
  6532. for ( var i = 0; i < morphTargetsLength; i ++ ) {
  6533. morphTargetsPosition[ i ] = [];
  6534. }
  6535. this.morphTargets.position = morphTargetsPosition;
  6536. }
  6537. var morphNormals = geometry.morphNormals;
  6538. var morphNormalsLength = morphNormals.length;
  6539. var morphTargetsNormal;
  6540. if ( morphNormalsLength > 0 ) {
  6541. morphTargetsNormal = [];
  6542. for ( var i = 0; i < morphNormalsLength; i ++ ) {
  6543. morphTargetsNormal[ i ] = [];
  6544. }
  6545. this.morphTargets.normal = morphTargetsNormal;
  6546. }
  6547. // skins
  6548. var skinIndices = geometry.skinIndices;
  6549. var skinWeights = geometry.skinWeights;
  6550. var hasSkinIndices = skinIndices.length === vertices.length;
  6551. var hasSkinWeights = skinWeights.length === vertices.length;
  6552. //
  6553. for ( var i = 0; i < faces.length; i ++ ) {
  6554. var face = faces[ i ];
  6555. this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] );
  6556. var vertexNormals = face.vertexNormals;
  6557. if ( vertexNormals.length === 3 ) {
  6558. this.normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
  6559. } else {
  6560. var normal = face.normal;
  6561. this.normals.push( normal, normal, normal );
  6562. }
  6563. var vertexColors = face.vertexColors;
  6564. if ( vertexColors.length === 3 ) {
  6565. this.colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
  6566. } else {
  6567. var color = face.color;
  6568. this.colors.push( color, color, color );
  6569. }
  6570. if ( hasFaceVertexUv === true ) {
  6571. var vertexUvs = faceVertexUvs[ 0 ][ i ];
  6572. if ( vertexUvs !== undefined ) {
  6573. this.uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6574. } else {
  6575. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', i );
  6576. this.uvs.push( new THREE.Vector2(), new THREE.Vector2(), new THREE.Vector2() );
  6577. }
  6578. }
  6579. if ( hasFaceVertexUv2 === true ) {
  6580. var vertexUvs = faceVertexUvs[ 1 ][ i ];
  6581. if ( vertexUvs !== undefined ) {
  6582. this.uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6583. } else {
  6584. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', i );
  6585. this.uvs2.push( new THREE.Vector2(), new THREE.Vector2(), new THREE.Vector2() );
  6586. }
  6587. }
  6588. // morphs
  6589. for ( var j = 0; j < morphTargetsLength; j ++ ) {
  6590. var morphTarget = morphTargets[ j ].vertices;
  6591. morphTargetsPosition[ j ].push( morphTarget[ face.a ], morphTarget[ face.b ], morphTarget[ face.c ] );
  6592. }
  6593. for ( var j = 0; j < morphNormalsLength; j ++ ) {
  6594. var morphNormal = morphNormals[ j ].vertexNormals[ i ];
  6595. morphTargetsNormal[ j ].push( morphNormal.a, morphNormal.b, morphNormal.c );
  6596. }
  6597. // skins
  6598. if ( hasSkinIndices ) {
  6599. this.skinIndices.push( skinIndices[ face.a ], skinIndices[ face.b ], skinIndices[ face.c ] );
  6600. }
  6601. if ( hasSkinWeights ) {
  6602. this.skinWeights.push( skinWeights[ face.a ], skinWeights[ face.b ], skinWeights[ face.c ] );
  6603. }
  6604. }
  6605. this.computeGroups( geometry );
  6606. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6607. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6608. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6609. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6610. this.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6611. return this;
  6612. },
  6613. dispose: function () {
  6614. this.dispatchEvent( { type: 'dispose' } );
  6615. }
  6616. };
  6617. THREE.EventDispatcher.prototype.apply( THREE.DirectGeometry.prototype );
  6618. // File:src/core/BufferGeometry.js
  6619. /**
  6620. * @author alteredq / http://alteredqualia.com/
  6621. * @author mrdoob / http://mrdoob.com/
  6622. */
  6623. THREE.BufferGeometry = function () {
  6624. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  6625. this.uuid = THREE.Math.generateUUID();
  6626. this.name = '';
  6627. this.type = 'BufferGeometry';
  6628. this.index = null;
  6629. this.attributes = {};
  6630. this.morphAttributes = {};
  6631. this.groups = [];
  6632. this.boundingBox = null;
  6633. this.boundingSphere = null;
  6634. this.drawRange = { start: 0, count: Infinity };
  6635. };
  6636. THREE.BufferGeometry.prototype = {
  6637. constructor: THREE.BufferGeometry,
  6638. getIndex: function () {
  6639. return this.index;
  6640. },
  6641. setIndex: function ( index ) {
  6642. this.index = index;
  6643. },
  6644. addAttribute: function ( name, attribute ) {
  6645. if ( attribute instanceof THREE.BufferAttribute === false && attribute instanceof THREE.InterleavedBufferAttribute === false ) {
  6646. console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
  6647. this.addAttribute( name, new THREE.BufferAttribute( arguments[ 1 ], arguments[ 2 ] ) );
  6648. return;
  6649. }
  6650. if ( name === 'index' ) {
  6651. console.warn( 'THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.' );
  6652. this.setIndex( attribute );
  6653. return;
  6654. }
  6655. this.attributes[ name ] = attribute;
  6656. return this;
  6657. },
  6658. getAttribute: function ( name ) {
  6659. return this.attributes[ name ];
  6660. },
  6661. removeAttribute: function ( name ) {
  6662. delete this.attributes[ name ];
  6663. return this;
  6664. },
  6665. addGroup: function ( start, count, materialIndex ) {
  6666. this.groups.push( {
  6667. start: start,
  6668. count: count,
  6669. materialIndex: materialIndex !== undefined ? materialIndex : 0
  6670. } );
  6671. },
  6672. clearGroups: function () {
  6673. this.groups = [];
  6674. },
  6675. setDrawRange: function ( start, count ) {
  6676. this.drawRange.start = start;
  6677. this.drawRange.count = count;
  6678. },
  6679. applyMatrix: function ( matrix ) {
  6680. var position = this.attributes.position;
  6681. if ( position !== undefined ) {
  6682. matrix.applyToVector3Array( position.array );
  6683. position.needsUpdate = true;
  6684. }
  6685. var normal = this.attributes.normal;
  6686. if ( normal !== undefined ) {
  6687. var normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  6688. normalMatrix.applyToVector3Array( normal.array );
  6689. normal.needsUpdate = true;
  6690. }
  6691. if ( this.boundingBox !== null ) {
  6692. this.computeBoundingBox();
  6693. }
  6694. if ( this.boundingSphere !== null ) {
  6695. this.computeBoundingSphere();
  6696. }
  6697. return this;
  6698. },
  6699. rotateX: function () {
  6700. // rotate geometry around world x-axis
  6701. var m1;
  6702. return function rotateX( angle ) {
  6703. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6704. m1.makeRotationX( angle );
  6705. this.applyMatrix( m1 );
  6706. return this;
  6707. };
  6708. }(),
  6709. rotateY: function () {
  6710. // rotate geometry around world y-axis
  6711. var m1;
  6712. return function rotateY( angle ) {
  6713. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6714. m1.makeRotationY( angle );
  6715. this.applyMatrix( m1 );
  6716. return this;
  6717. };
  6718. }(),
  6719. rotateZ: function () {
  6720. // rotate geometry around world z-axis
  6721. var m1;
  6722. return function rotateZ( angle ) {
  6723. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6724. m1.makeRotationZ( angle );
  6725. this.applyMatrix( m1 );
  6726. return this;
  6727. };
  6728. }(),
  6729. translate: function () {
  6730. // translate geometry
  6731. var m1;
  6732. return function translate( x, y, z ) {
  6733. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6734. m1.makeTranslation( x, y, z );
  6735. this.applyMatrix( m1 );
  6736. return this;
  6737. };
  6738. }(),
  6739. scale: function () {
  6740. // scale geometry
  6741. var m1;
  6742. return function scale( x, y, z ) {
  6743. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6744. m1.makeScale( x, y, z );
  6745. this.applyMatrix( m1 );
  6746. return this;
  6747. };
  6748. }(),
  6749. lookAt: function () {
  6750. var obj;
  6751. return function lookAt( vector ) {
  6752. if ( obj === undefined ) obj = new THREE.Object3D();
  6753. obj.lookAt( vector );
  6754. obj.updateMatrix();
  6755. this.applyMatrix( obj.matrix );
  6756. };
  6757. }(),
  6758. center: function () {
  6759. this.computeBoundingBox();
  6760. var offset = this.boundingBox.center().negate();
  6761. this.translate( offset.x, offset.y, offset.z );
  6762. return offset;
  6763. },
  6764. setFromObject: function ( object ) {
  6765. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  6766. var geometry = object.geometry;
  6767. if ( object instanceof THREE.Points || object instanceof THREE.Line ) {
  6768. var positions = new THREE.Float32Attribute( geometry.vertices.length * 3, 3 );
  6769. var colors = new THREE.Float32Attribute( geometry.colors.length * 3, 3 );
  6770. this.addAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) );
  6771. this.addAttribute( 'color', colors.copyColorsArray( geometry.colors ) );
  6772. if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) {
  6773. var lineDistances = new THREE.Float32Attribute( geometry.lineDistances.length, 1 );
  6774. this.addAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) );
  6775. }
  6776. if ( geometry.boundingSphere !== null ) {
  6777. this.boundingSphere = geometry.boundingSphere.clone();
  6778. }
  6779. if ( geometry.boundingBox !== null ) {
  6780. this.boundingBox = geometry.boundingBox.clone();
  6781. }
  6782. } else if ( object instanceof THREE.Mesh ) {
  6783. if ( geometry instanceof THREE.Geometry ) {
  6784. this.fromGeometry( geometry );
  6785. }
  6786. }
  6787. return this;
  6788. },
  6789. updateFromObject: function ( object ) {
  6790. var geometry = object.geometry;
  6791. if ( object instanceof THREE.Mesh ) {
  6792. var direct = geometry.__directGeometry;
  6793. if ( direct === undefined ) {
  6794. return this.fromGeometry( geometry );
  6795. }
  6796. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6797. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6798. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6799. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6800. direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6801. geometry.verticesNeedUpdate = false;
  6802. geometry.normalsNeedUpdate = false;
  6803. geometry.colorsNeedUpdate = false;
  6804. geometry.uvsNeedUpdate = false;
  6805. geometry.groupsNeedUpdate = false;
  6806. geometry = direct;
  6807. }
  6808. if ( geometry.verticesNeedUpdate === true ) {
  6809. var attribute = this.attributes.position;
  6810. if ( attribute !== undefined ) {
  6811. attribute.copyVector3sArray( geometry.vertices );
  6812. attribute.needsUpdate = true;
  6813. }
  6814. geometry.verticesNeedUpdate = false;
  6815. }
  6816. if ( geometry.normalsNeedUpdate === true ) {
  6817. var attribute = this.attributes.normal;
  6818. if ( attribute !== undefined ) {
  6819. attribute.copyVector3sArray( geometry.normals );
  6820. attribute.needsUpdate = true;
  6821. }
  6822. geometry.normalsNeedUpdate = false;
  6823. }
  6824. if ( geometry.colorsNeedUpdate === true ) {
  6825. var attribute = this.attributes.color;
  6826. if ( attribute !== undefined ) {
  6827. attribute.copyColorsArray( geometry.colors );
  6828. attribute.needsUpdate = true;
  6829. }
  6830. geometry.colorsNeedUpdate = false;
  6831. }
  6832. if ( geometry.uvsNeedUpdate ) {
  6833. var attribute = this.attributes.uv;
  6834. if ( attribute !== undefined ) {
  6835. attribute.copyVector2sArray( geometry.uvs );
  6836. attribute.needsUpdate = true;
  6837. }
  6838. geometry.uvsNeedUpdate = false;
  6839. }
  6840. if ( geometry.lineDistancesNeedUpdate ) {
  6841. var attribute = this.attributes.lineDistance;
  6842. if ( attribute !== undefined ) {
  6843. attribute.copyArray( geometry.lineDistances );
  6844. attribute.needsUpdate = true;
  6845. }
  6846. geometry.lineDistancesNeedUpdate = false;
  6847. }
  6848. if ( geometry.groupsNeedUpdate ) {
  6849. geometry.computeGroups( object.geometry );
  6850. this.groups = geometry.groups;
  6851. geometry.groupsNeedUpdate = false;
  6852. }
  6853. return this;
  6854. },
  6855. fromGeometry: function ( geometry ) {
  6856. geometry.__directGeometry = new THREE.DirectGeometry().fromGeometry( geometry );
  6857. return this.fromDirectGeometry( geometry.__directGeometry );
  6858. },
  6859. fromDirectGeometry: function ( geometry ) {
  6860. var positions = new Float32Array( geometry.vertices.length * 3 );
  6861. this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) );
  6862. if ( geometry.normals.length > 0 ) {
  6863. var normals = new Float32Array( geometry.normals.length * 3 );
  6864. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) );
  6865. }
  6866. if ( geometry.colors.length > 0 ) {
  6867. var colors = new Float32Array( geometry.colors.length * 3 );
  6868. this.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors ) );
  6869. }
  6870. if ( geometry.uvs.length > 0 ) {
  6871. var uvs = new Float32Array( geometry.uvs.length * 2 );
  6872. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs ) );
  6873. }
  6874. if ( geometry.uvs2.length > 0 ) {
  6875. var uvs2 = new Float32Array( geometry.uvs2.length * 2 );
  6876. this.addAttribute( 'uv2', new THREE.BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 ) );
  6877. }
  6878. if ( geometry.indices.length > 0 ) {
  6879. var TypeArray = geometry.vertices.length > 65535 ? Uint32Array : Uint16Array;
  6880. var indices = new TypeArray( geometry.indices.length * 3 );
  6881. this.setIndex( new THREE.BufferAttribute( indices, 1 ).copyIndicesArray( geometry.indices ) );
  6882. }
  6883. // groups
  6884. this.groups = geometry.groups;
  6885. // morphs
  6886. for ( var name in geometry.morphTargets ) {
  6887. var array = [];
  6888. var morphTargets = geometry.morphTargets[ name ];
  6889. for ( var i = 0, l = morphTargets.length; i < l; i ++ ) {
  6890. var morphTarget = morphTargets[ i ];
  6891. var attribute = new THREE.Float32Attribute( morphTarget.length * 3, 3 );
  6892. array.push( attribute.copyVector3sArray( morphTarget ) );
  6893. }
  6894. this.morphAttributes[ name ] = array;
  6895. }
  6896. // skinning
  6897. if ( geometry.skinIndices.length > 0 ) {
  6898. var skinIndices = new THREE.Float32Attribute( geometry.skinIndices.length * 4, 4 );
  6899. this.addAttribute( 'skinIndex', skinIndices.copyVector4sArray( geometry.skinIndices ) );
  6900. }
  6901. if ( geometry.skinWeights.length > 0 ) {
  6902. var skinWeights = new THREE.Float32Attribute( geometry.skinWeights.length * 4, 4 );
  6903. this.addAttribute( 'skinWeight', skinWeights.copyVector4sArray( geometry.skinWeights ) );
  6904. }
  6905. //
  6906. if ( geometry.boundingSphere !== null ) {
  6907. this.boundingSphere = geometry.boundingSphere.clone();
  6908. }
  6909. if ( geometry.boundingBox !== null ) {
  6910. this.boundingBox = geometry.boundingBox.clone();
  6911. }
  6912. return this;
  6913. },
  6914. computeBoundingBox: function () {
  6915. var vector = new THREE.Vector3();
  6916. return function () {
  6917. if ( this.boundingBox === null ) {
  6918. this.boundingBox = new THREE.Box3();
  6919. }
  6920. var positions = this.attributes.position.array;
  6921. if ( positions ) {
  6922. this.boundingBox.setFromArray( positions );
  6923. }
  6924. if ( positions === undefined || positions.length === 0 ) {
  6925. this.boundingBox.min.set( 0, 0, 0 );
  6926. this.boundingBox.max.set( 0, 0, 0 );
  6927. }
  6928. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  6929. console.error( 'THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  6930. }
  6931. };
  6932. }(),
  6933. computeBoundingSphere: function () {
  6934. var box = new THREE.Box3();
  6935. var vector = new THREE.Vector3();
  6936. return function () {
  6937. if ( this.boundingSphere === null ) {
  6938. this.boundingSphere = new THREE.Sphere();
  6939. }
  6940. var positions = this.attributes.position.array;
  6941. if ( positions ) {
  6942. var center = this.boundingSphere.center;
  6943. box.setFromArray( positions );
  6944. box.center( center );
  6945. // hoping to find a boundingSphere with a radius smaller than the
  6946. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  6947. var maxRadiusSq = 0;
  6948. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  6949. vector.fromArray( positions, i );
  6950. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
  6951. }
  6952. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  6953. if ( isNaN( this.boundingSphere.radius ) ) {
  6954. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  6955. }
  6956. }
  6957. };
  6958. }(),
  6959. computeFaceNormals: function () {
  6960. // backwards compatibility
  6961. },
  6962. computeVertexNormals: function () {
  6963. var index = this.index;
  6964. var attributes = this.attributes;
  6965. var groups = this.groups;
  6966. if ( attributes.position ) {
  6967. var positions = attributes.position.array;
  6968. if ( attributes.normal === undefined ) {
  6969. this.addAttribute( 'normal', new THREE.BufferAttribute( new Float32Array( positions.length ), 3 ) );
  6970. } else {
  6971. // reset existing normals to zero
  6972. var array = attributes.normal.array;
  6973. for ( var i = 0, il = array.length; i < il; i ++ ) {
  6974. array[ i ] = 0;
  6975. }
  6976. }
  6977. var normals = attributes.normal.array;
  6978. var vA, vB, vC,
  6979. pA = new THREE.Vector3(),
  6980. pB = new THREE.Vector3(),
  6981. pC = new THREE.Vector3(),
  6982. cb = new THREE.Vector3(),
  6983. ab = new THREE.Vector3();
  6984. // indexed elements
  6985. if ( index ) {
  6986. var indices = index.array;
  6987. if ( groups.length === 0 ) {
  6988. this.addGroup( 0, indices.length );
  6989. }
  6990. for ( var j = 0, jl = groups.length; j < jl; ++ j ) {
  6991. var group = groups[ j ];
  6992. var start = group.start;
  6993. var count = group.count;
  6994. for ( var i = start, il = start + count; i < il; i += 3 ) {
  6995. vA = indices[ i + 0 ] * 3;
  6996. vB = indices[ i + 1 ] * 3;
  6997. vC = indices[ i + 2 ] * 3;
  6998. pA.fromArray( positions, vA );
  6999. pB.fromArray( positions, vB );
  7000. pC.fromArray( positions, vC );
  7001. cb.subVectors( pC, pB );
  7002. ab.subVectors( pA, pB );
  7003. cb.cross( ab );
  7004. normals[ vA ] += cb.x;
  7005. normals[ vA + 1 ] += cb.y;
  7006. normals[ vA + 2 ] += cb.z;
  7007. normals[ vB ] += cb.x;
  7008. normals[ vB + 1 ] += cb.y;
  7009. normals[ vB + 2 ] += cb.z;
  7010. normals[ vC ] += cb.x;
  7011. normals[ vC + 1 ] += cb.y;
  7012. normals[ vC + 2 ] += cb.z;
  7013. }
  7014. }
  7015. } else {
  7016. // non-indexed elements (unconnected triangle soup)
  7017. for ( var i = 0, il = positions.length; i < il; i += 9 ) {
  7018. pA.fromArray( positions, i );
  7019. pB.fromArray( positions, i + 3 );
  7020. pC.fromArray( positions, i + 6 );
  7021. cb.subVectors( pC, pB );
  7022. ab.subVectors( pA, pB );
  7023. cb.cross( ab );
  7024. normals[ i ] = cb.x;
  7025. normals[ i + 1 ] = cb.y;
  7026. normals[ i + 2 ] = cb.z;
  7027. normals[ i + 3 ] = cb.x;
  7028. normals[ i + 4 ] = cb.y;
  7029. normals[ i + 5 ] = cb.z;
  7030. normals[ i + 6 ] = cb.x;
  7031. normals[ i + 7 ] = cb.y;
  7032. normals[ i + 8 ] = cb.z;
  7033. }
  7034. }
  7035. this.normalizeNormals();
  7036. attributes.normal.needsUpdate = true;
  7037. }
  7038. },
  7039. merge: function ( geometry, offset ) {
  7040. if ( geometry instanceof THREE.BufferGeometry === false ) {
  7041. console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
  7042. return;
  7043. }
  7044. if ( offset === undefined ) offset = 0;
  7045. var attributes = this.attributes;
  7046. for ( var key in attributes ) {
  7047. if ( geometry.attributes[ key ] === undefined ) continue;
  7048. var attribute1 = attributes[ key ];
  7049. var attributeArray1 = attribute1.array;
  7050. var attribute2 = geometry.attributes[ key ];
  7051. var attributeArray2 = attribute2.array;
  7052. var attributeSize = attribute2.itemSize;
  7053. for ( var i = 0, j = attributeSize * offset; i < attributeArray2.length; i ++, j ++ ) {
  7054. attributeArray1[ j ] = attributeArray2[ i ];
  7055. }
  7056. }
  7057. return this;
  7058. },
  7059. normalizeNormals: function () {
  7060. var normals = this.attributes.normal.array;
  7061. var x, y, z, n;
  7062. for ( var i = 0, il = normals.length; i < il; i += 3 ) {
  7063. x = normals[ i ];
  7064. y = normals[ i + 1 ];
  7065. z = normals[ i + 2 ];
  7066. n = 1.0 / Math.sqrt( x * x + y * y + z * z );
  7067. normals[ i ] *= n;
  7068. normals[ i + 1 ] *= n;
  7069. normals[ i + 2 ] *= n;
  7070. }
  7071. },
  7072. toNonIndexed: function () {
  7073. if ( this.index === null ) {
  7074. console.warn( 'THREE.BufferGeometry.toNonIndexed(): Geometry is already non-indexed.' );
  7075. return this;
  7076. }
  7077. var geometry2 = new THREE.BufferGeometry();
  7078. var indices = this.index.array;
  7079. var attributes = this.attributes;
  7080. for ( var name in attributes ) {
  7081. var attribute = attributes[ name ];
  7082. var array = attribute.array;
  7083. var itemSize = attribute.itemSize;
  7084. var array2 = new array.constructor( indices.length * itemSize );
  7085. var index = 0, index2 = 0;
  7086. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  7087. index = indices[ i ] * itemSize;
  7088. for ( var j = 0; j < itemSize; j ++ ) {
  7089. array2[ index2 ++ ] = array[ index ++ ];
  7090. }
  7091. }
  7092. geometry2.addAttribute( name, new THREE.BufferAttribute( array2, itemSize ) );
  7093. }
  7094. return geometry2;
  7095. },
  7096. toJSON: function () {
  7097. var data = {
  7098. metadata: {
  7099. version: 4.4,
  7100. type: 'BufferGeometry',
  7101. generator: 'BufferGeometry.toJSON'
  7102. }
  7103. };
  7104. // standard BufferGeometry serialization
  7105. data.uuid = this.uuid;
  7106. data.type = this.type;
  7107. if ( this.name !== '' ) data.name = this.name;
  7108. if ( this.parameters !== undefined ) {
  7109. var parameters = this.parameters;
  7110. for ( var key in parameters ) {
  7111. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  7112. }
  7113. return data;
  7114. }
  7115. data.data = { attributes: {} };
  7116. var index = this.index;
  7117. if ( index !== null ) {
  7118. var array = Array.prototype.slice.call( index.array );
  7119. data.data.index = {
  7120. type: index.array.constructor.name,
  7121. array: array
  7122. };
  7123. }
  7124. var attributes = this.attributes;
  7125. for ( var key in attributes ) {
  7126. var attribute = attributes[ key ];
  7127. var array = Array.prototype.slice.call( attribute.array );
  7128. data.data.attributes[ key ] = {
  7129. itemSize: attribute.itemSize,
  7130. type: attribute.array.constructor.name,
  7131. array: array
  7132. };
  7133. }
  7134. var groups = this.groups;
  7135. if ( groups.length > 0 ) {
  7136. data.data.groups = JSON.parse( JSON.stringify( groups ) );
  7137. }
  7138. var boundingSphere = this.boundingSphere;
  7139. if ( boundingSphere !== null ) {
  7140. data.data.boundingSphere = {
  7141. center: boundingSphere.center.toArray(),
  7142. radius: boundingSphere.radius
  7143. };
  7144. }
  7145. return data;
  7146. },
  7147. clone: function () {
  7148. /*
  7149. // Handle primitives
  7150. var parameters = this.parameters;
  7151. if ( parameters !== undefined ) {
  7152. var values = [];
  7153. for ( var key in parameters ) {
  7154. values.push( parameters[ key ] );
  7155. }
  7156. var geometry = Object.create( this.constructor.prototype );
  7157. this.constructor.apply( geometry, values );
  7158. return geometry;
  7159. }
  7160. return new this.constructor().copy( this );
  7161. */
  7162. return new THREE.BufferGeometry().copy( this );
  7163. },
  7164. copy: function ( source ) {
  7165. var index = source.index;
  7166. if ( index !== null ) {
  7167. this.setIndex( index.clone() );
  7168. }
  7169. var attributes = source.attributes;
  7170. for ( var name in attributes ) {
  7171. var attribute = attributes[ name ];
  7172. this.addAttribute( name, attribute.clone() );
  7173. }
  7174. var groups = source.groups;
  7175. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  7176. var group = groups[ i ];
  7177. this.addGroup( group.start, group.count );
  7178. }
  7179. return this;
  7180. },
  7181. dispose: function () {
  7182. this.dispatchEvent( { type: 'dispose' } );
  7183. }
  7184. };
  7185. THREE.EventDispatcher.prototype.apply( THREE.BufferGeometry.prototype );
  7186. THREE.BufferGeometry.MaxIndex = 65535;
  7187. // File:src/core/InstancedBufferGeometry.js
  7188. /**
  7189. * @author benaadams / https://twitter.com/ben_a_adams
  7190. */
  7191. THREE.InstancedBufferGeometry = function () {
  7192. THREE.BufferGeometry.call( this );
  7193. this.type = 'InstancedBufferGeometry';
  7194. this.maxInstancedCount = undefined;
  7195. };
  7196. THREE.InstancedBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  7197. THREE.InstancedBufferGeometry.prototype.constructor = THREE.InstancedBufferGeometry;
  7198. THREE.InstancedBufferGeometry.prototype.addGroup = function ( start, count, instances ) {
  7199. this.groups.push( {
  7200. start: start,
  7201. count: count,
  7202. instances: instances
  7203. } );
  7204. };
  7205. THREE.InstancedBufferGeometry.prototype.copy = function ( source ) {
  7206. var index = source.index;
  7207. if ( index !== null ) {
  7208. this.setIndex( index.clone() );
  7209. }
  7210. var attributes = source.attributes;
  7211. for ( var name in attributes ) {
  7212. var attribute = attributes[ name ];
  7213. this.addAttribute( name, attribute.clone() );
  7214. }
  7215. var groups = source.groups;
  7216. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  7217. var group = groups[ i ];
  7218. this.addGroup( group.start, group.count, group.instances );
  7219. }
  7220. return this;
  7221. };
  7222. THREE.EventDispatcher.prototype.apply( THREE.InstancedBufferGeometry.prototype );
  7223. // File:src/core/Uniform.js
  7224. /**
  7225. * @author mrdoob / http://mrdoob.com/
  7226. */
  7227. THREE.Uniform = function ( type, value ) {
  7228. this.type = type;
  7229. this.value = value;
  7230. this.dynamic = false;
  7231. };
  7232. THREE.Uniform.prototype = {
  7233. constructor: THREE.Uniform,
  7234. onUpdate: function ( callback ) {
  7235. this.dynamic = true;
  7236. this.onUpdateCallback = callback;
  7237. return this;
  7238. }
  7239. };
  7240. // File:src/animation/AnimationClip.js
  7241. /**
  7242. *
  7243. * Reusable set of Tracks that represent an animation.
  7244. *
  7245. * @author Ben Houston / http://clara.io/
  7246. * @author David Sarno / http://lighthaus.us/
  7247. */
  7248. THREE.AnimationClip = function ( name, duration, tracks ) {
  7249. this.name = name || THREE.Math.generateUUID();
  7250. this.tracks = tracks;
  7251. this.duration = ( duration !== undefined ) ? duration : -1;
  7252. // this means it should figure out its duration by scanning the tracks
  7253. if ( this.duration < 0 ) {
  7254. this.resetDuration();
  7255. }
  7256. // maybe only do these on demand, as doing them here could potentially slow down loading
  7257. // but leaving these here during development as this ensures a lot of testing of these functions
  7258. this.trim();
  7259. this.optimize();
  7260. };
  7261. THREE.AnimationClip.prototype = {
  7262. constructor: THREE.AnimationClip,
  7263. resetDuration: function() {
  7264. var tracks = this.tracks,
  7265. duration = 0;
  7266. for ( var i = 0, n = tracks.length; i !== n; ++ i ) {
  7267. var track = this.tracks[ i ];
  7268. duration = Math.max(
  7269. duration, track.times[ track.times.length - 1 ] );
  7270. }
  7271. this.duration = duration;
  7272. },
  7273. trim: function() {
  7274. for ( var i = 0; i < this.tracks.length; i ++ ) {
  7275. this.tracks[ i ].trim( 0, this.duration );
  7276. }
  7277. return this;
  7278. },
  7279. optimize: function() {
  7280. for ( var i = 0; i < this.tracks.length; i ++ ) {
  7281. this.tracks[ i ].optimize();
  7282. }
  7283. return this;
  7284. }
  7285. };
  7286. // Static methods:
  7287. Object.assign( THREE.AnimationClip, {
  7288. parse: function( json ) {
  7289. var tracks = [],
  7290. jsonTracks = json.tracks,
  7291. frameTime = 1.0 / ( json.fps || 1.0 );
  7292. for ( var i = 0, n = jsonTracks.length; i !== n; ++ i ) {
  7293. tracks.push( THREE.KeyframeTrack.parse( jsonTracks[ i ] ).scale( frameTime ) );
  7294. }
  7295. return new THREE.AnimationClip( json.name, json.duration, tracks );
  7296. },
  7297. toJSON: function( clip ) {
  7298. var tracks = [],
  7299. clipTracks = clip.tracks;
  7300. var json = {
  7301. 'name': clip.name,
  7302. 'duration': clip.duration,
  7303. 'tracks': tracks
  7304. };
  7305. for ( var i = 0, n = clipTracks.length; i !== n; ++ i ) {
  7306. tracks.push( THREE.KeyframeTrack.toJSON( clipTracks[ i ] ) );
  7307. }
  7308. return json;
  7309. },
  7310. CreateFromMorphTargetSequence: function( name, morphTargetSequence, fps ) {
  7311. var numMorphTargets = morphTargetSequence.length;
  7312. var tracks = [];
  7313. for ( var i = 0; i < numMorphTargets; i ++ ) {
  7314. var times = [];
  7315. var values = [];
  7316. times.push(
  7317. ( i + numMorphTargets - 1 ) % numMorphTargets,
  7318. i,
  7319. ( i + 1 ) % numMorphTargets );
  7320. values.push( 0, 1, 0 );
  7321. var order = THREE.AnimationUtils.getKeyframeOrder( times );
  7322. times = THREE.AnimationUtils.sortedArray( times, 1, order );
  7323. values = THREE.AnimationUtils.sortedArray( values, 1, order );
  7324. // if there is a key at the first frame, duplicate it as the
  7325. // last frame as well for perfect loop.
  7326. if ( times[ 0 ] === 0 ) {
  7327. times.push( numMorphTargets );
  7328. values.push( values[ 0 ] );
  7329. }
  7330. tracks.push(
  7331. new THREE.NumberKeyframeTrack(
  7332. '.morphTargetInfluences[' + morphTargetSequence[ i ].name + ']',
  7333. times, values
  7334. ).scale( 1.0 / fps ) );
  7335. }
  7336. return new THREE.AnimationClip( name, -1, tracks );
  7337. },
  7338. findByName: function( clipArray, name ) {
  7339. for ( var i = 0; i < clipArray.length; i ++ ) {
  7340. if ( clipArray[ i ].name === name ) {
  7341. return clipArray[ i ];
  7342. }
  7343. }
  7344. return null;
  7345. },
  7346. CreateClipsFromMorphTargetSequences: function( morphTargets, fps ) {
  7347. var animationToMorphTargets = {};
  7348. // tested with https://regex101.com/ on trick sequences
  7349. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  7350. var pattern = /^([\w-]*?)([\d]+)$/;
  7351. // sort morph target names into animation groups based
  7352. // patterns like Walk_001, Walk_002, Run_001, Run_002
  7353. for ( var i = 0, il = morphTargets.length; i < il; i ++ ) {
  7354. var morphTarget = morphTargets[ i ];
  7355. var parts = morphTarget.name.match( pattern );
  7356. if ( parts && parts.length > 1 ) {
  7357. var name = parts[ 1 ];
  7358. var animationMorphTargets = animationToMorphTargets[ name ];
  7359. if ( ! animationMorphTargets ) {
  7360. animationToMorphTargets[ name ] = animationMorphTargets = [];
  7361. }
  7362. animationMorphTargets.push( morphTarget );
  7363. }
  7364. }
  7365. var clips = [];
  7366. for ( var name in animationToMorphTargets ) {
  7367. clips.push( THREE.AnimationClip.CreateFromMorphTargetSequence( name, animationToMorphTargets[ name ], fps ) );
  7368. }
  7369. return clips;
  7370. },
  7371. // parse the animation.hierarchy format
  7372. parseAnimation: function( animation, bones, nodeName ) {
  7373. if ( ! animation ) {
  7374. console.error( " no animation in JSONLoader data" );
  7375. return null;
  7376. }
  7377. var addNonemptyTrack = function(
  7378. trackType, trackName, animationKeys, propertyName, destTracks ) {
  7379. // only return track if there are actually keys.
  7380. if ( animationKeys.length !== 0 ) {
  7381. var times = [];
  7382. var values = [];
  7383. THREE.AnimationUtils.flattenJSON(
  7384. animationKeys, times, values, propertyName );
  7385. // empty keys are filtered out, so check again
  7386. if ( times.length !== 0 ) {
  7387. destTracks.push( new trackType( trackName, times, values ) );
  7388. }
  7389. }
  7390. };
  7391. var tracks = [];
  7392. var clipName = animation.name || 'default';
  7393. // automatic length determination in AnimationClip.
  7394. var duration = animation.length || -1;
  7395. var fps = animation.fps || 30;
  7396. var hierarchyTracks = animation.hierarchy || [];
  7397. for ( var h = 0; h < hierarchyTracks.length; h ++ ) {
  7398. var animationKeys = hierarchyTracks[ h ].keys;
  7399. // skip empty tracks
  7400. if ( ! animationKeys || animationKeys.length == 0 ) continue;
  7401. // process morph targets in a way exactly compatible
  7402. // with AnimationHandler.init( animation )
  7403. if ( animationKeys[0].morphTargets ) {
  7404. // figure out all morph targets used in this track
  7405. var morphTargetNames = {};
  7406. for ( var k = 0; k < animationKeys.length; k ++ ) {
  7407. if ( animationKeys[k].morphTargets ) {
  7408. for ( var m = 0; m < animationKeys[k].morphTargets.length; m ++ ) {
  7409. morphTargetNames[ animationKeys[k].morphTargets[m] ] = -1;
  7410. }
  7411. }
  7412. }
  7413. // create a track for each morph target with all zero
  7414. // morphTargetInfluences except for the keys in which
  7415. // the morphTarget is named.
  7416. for ( var morphTargetName in morphTargetNames ) {
  7417. var times = [];
  7418. var values = [];
  7419. for ( var m = 0;
  7420. m !== animationKeys[k].morphTargets.length; ++ m ) {
  7421. var animationKey = animationKeys[k];
  7422. times.push( animationKey.time );
  7423. values.push( ( animationKey.morphTarget === morphTargetName ) ? 1 : 0 )
  7424. }
  7425. tracks.push( new THREE.NumberKeyframeTrack(
  7426. '.morphTargetInfluence[' + morphTargetName + ']', times, values ) );
  7427. }
  7428. duration = morphTargetNames.length * ( fps || 1.0 );
  7429. } else {
  7430. // ...assume skeletal animation
  7431. var boneName = '.bones[' + bones[ h ].name + ']';
  7432. addNonemptyTrack(
  7433. THREE.VectorKeyframeTrack, boneName + '.position',
  7434. animationKeys, 'pos', tracks );
  7435. addNonemptyTrack(
  7436. THREE.QuaternionKeyframeTrack, boneName + '.quaternion',
  7437. animationKeys, 'rot', tracks );
  7438. addNonemptyTrack(
  7439. THREE.VectorKeyframeTrack, boneName + '.scale',
  7440. animationKeys, 'scl', tracks );
  7441. }
  7442. }
  7443. if ( tracks.length === 0 ) {
  7444. return null;
  7445. }
  7446. var clip = new THREE.AnimationClip( clipName, duration, tracks );
  7447. return clip;
  7448. }
  7449. } );
  7450. // File:src/animation/AnimationMixer.js
  7451. /**
  7452. *
  7453. * Player for AnimationClips.
  7454. *
  7455. *
  7456. * @author Ben Houston / http://clara.io/
  7457. * @author David Sarno / http://lighthaus.us/
  7458. * @author tschw
  7459. */
  7460. THREE.AnimationMixer = function( root ) {
  7461. this._root = root;
  7462. this._initMemoryManager();
  7463. this._accuIndex = 0;
  7464. this.time = 0;
  7465. this.timeScale = 1.0;
  7466. };
  7467. THREE.AnimationMixer.prototype = {
  7468. constructor: THREE.AnimationMixer,
  7469. // return an action for a clip optionally using a custom root target
  7470. // object (this method allocates a lot of dynamic memory in case a
  7471. // previously unknown clip/root combination is specified)
  7472. clipAction: function( clip, optionalRoot ) {
  7473. var root = optionalRoot || this._root,
  7474. rootUuid = root.uuid,
  7475. clipName = ( typeof clip === 'string' ) ? clip : clip.name,
  7476. clipObject = ( clip !== clipName ) ? clip : null,
  7477. actionsForClip = this._actionsByClip[ clipName ],
  7478. prototypeAction;
  7479. if ( actionsForClip !== undefined ) {
  7480. var existingAction =
  7481. actionsForClip.actionByRoot[ rootUuid ];
  7482. if ( existingAction !== undefined ) {
  7483. return existingAction;
  7484. }
  7485. // we know the clip, so we don't have to parse all
  7486. // the bindings again but can just copy
  7487. prototypeAction = actionsForClip.knownActions[ 0 ];
  7488. // also, take the clip from the prototype action
  7489. clipObject = prototypeAction._clip;
  7490. if ( clip !== clipName && clip !== clipObject ) {
  7491. throw new Error(
  7492. "Different clips with the same name detected!" );
  7493. }
  7494. }
  7495. // clip must be known when specified via string
  7496. if ( clipObject === null ) return null;
  7497. // allocate all resources required to run it
  7498. var newAction = new THREE.
  7499. AnimationMixer._Action( this, clipObject, optionalRoot );
  7500. this._bindAction( newAction, prototypeAction );
  7501. // and make the action known to the memory manager
  7502. this._addInactiveAction( newAction, clipName, rootUuid );
  7503. return newAction;
  7504. },
  7505. // get an existing action
  7506. existingAction: function( clip, optionalRoot ) {
  7507. var root = optionalRoot || this._root,
  7508. rootUuid = root.uuid,
  7509. clipName = ( typeof clip === 'string' ) ? clip : clip.name,
  7510. actionsForClip = this._actionsByClip[ clipName ];
  7511. if ( actionsForClip !== undefined ) {
  7512. return actionsForClip.actionByRoot[ rootUuid ] || null;
  7513. }
  7514. return null;
  7515. },
  7516. // deactivates all previously scheduled actions
  7517. stopAllAction: function() {
  7518. var actions = this._actions,
  7519. nActions = this._nActiveActions,
  7520. bindings = this._bindings,
  7521. nBindings = this._nActiveBindings;
  7522. this._nActiveActions = 0;
  7523. this._nActiveBindings = 0;
  7524. for ( var i = 0; i !== nActions; ++ i ) {
  7525. actions[ i ].reset();
  7526. }
  7527. for ( var i = 0; i !== nBindings; ++ i ) {
  7528. bindings[ i ].useCount = 0;
  7529. }
  7530. return this;
  7531. },
  7532. // advance the time and update apply the animation
  7533. update: function( deltaTime ) {
  7534. deltaTime *= this.timeScale;
  7535. var actions = this._actions,
  7536. nActions = this._nActiveActions,
  7537. time = this.time += deltaTime,
  7538. timeDirection = Math.sign( deltaTime ),
  7539. accuIndex = this._accuIndex ^= 1;
  7540. // run active actions
  7541. for ( var i = 0; i !== nActions; ++ i ) {
  7542. var action = actions[ i ];
  7543. if ( action.enabled ) {
  7544. action._update( time, deltaTime, timeDirection, accuIndex );
  7545. }
  7546. }
  7547. // update scene graph
  7548. var bindings = this._bindings,
  7549. nBindings = this._nActiveBindings;
  7550. for ( var i = 0; i !== nBindings; ++ i ) {
  7551. bindings[ i ].apply( accuIndex );
  7552. }
  7553. return this;
  7554. },
  7555. // return this mixer's root target object
  7556. getRoot: function() {
  7557. return this._root;
  7558. },
  7559. // free all resources specific to a particular clip
  7560. uncacheClip: function( clip ) {
  7561. var actions = this._actions,
  7562. clipName = clip.name,
  7563. actionsByClip = this._actionsByClip,
  7564. actionsForClip = actionsByClip[ clipName ];
  7565. if ( actionsForClip !== undefined ) {
  7566. // note: just calling _removeInactiveAction would mess up the
  7567. // iteration state and also require updating the state we can
  7568. // just throw away
  7569. var actionsToRemove = actionsForClip.knownActions;
  7570. for ( var i = 0, n = actionsToRemove.length; i !== n; ++ i ) {
  7571. var action = actionsToRemove[ i ];
  7572. this._deactivateAction( action );
  7573. var cacheIndex = action._cacheIndex,
  7574. lastInactiveAction = actions[ actions.length - 1 ];
  7575. action._cacheIndex = null;
  7576. action._byClipCacheIndex = null;
  7577. lastInactiveAction._cacheIndex = cacheIndex;
  7578. actions[ cacheIndex ] = lastInactiveAction;
  7579. actions.pop();
  7580. this._removeInactiveBindingsForAction( action );
  7581. }
  7582. delete actionsByClip[ clipName ];
  7583. }
  7584. },
  7585. // free all resources specific to a particular root target object
  7586. uncacheRoot: function( root ) {
  7587. var rootUuid = root.uuid,
  7588. actionsByClip = this._actionsByClip;
  7589. for ( var clipName in actionsByClip ) {
  7590. var actionByRoot = actionsByClip[ clipName ].actionByRoot,
  7591. action = actionByRoot[ rootUuid ];
  7592. if ( action !== undefined ) {
  7593. this._deactivateAction( action );
  7594. this._removeInactiveAction( action );
  7595. }
  7596. }
  7597. var bindingsByRoot = this._bindingsByRootAndName,
  7598. bindingByName = bindingsByRoot[ rootUuid ];
  7599. if ( bindingByName !== undefined ) {
  7600. for ( var trackName in bindingByName ) {
  7601. var binding = bindingByName[ trackName ];
  7602. binding.restoreOriginalState();
  7603. this._removeInactiveBinding( binding );
  7604. }
  7605. }
  7606. },
  7607. // remove a targeted clip from the cache
  7608. uncacheAction: function( clip, optionalRoot ) {
  7609. var action = this.existingAction( clip, optionalRoot );
  7610. if ( action !== null ) {
  7611. this._deactivateAction( action );
  7612. this._removeInactiveAction( action );
  7613. }
  7614. }
  7615. };
  7616. THREE.EventDispatcher.prototype.apply( THREE.AnimationMixer.prototype );
  7617. THREE.AnimationMixer._Action =
  7618. function( mixer, clip, localRoot ) {
  7619. this._mixer = mixer;
  7620. this._clip = clip;
  7621. this._localRoot = localRoot || null;
  7622. var tracks = clip.tracks,
  7623. nTracks = tracks.length,
  7624. interpolants = new Array( nTracks );
  7625. var interpolantSettings = {
  7626. endingStart: THREE.ZeroCurvatureEnding,
  7627. endingEnd: THREE.ZeroCurvatureEnding
  7628. };
  7629. for ( var i = 0; i !== nTracks; ++ i ) {
  7630. var interpolant = tracks[ i ].createInterpolant( null );
  7631. interpolants[ i ] = interpolant;
  7632. interpolant.settings = interpolantSettings
  7633. }
  7634. this._interpolantSettings = interpolantSettings;
  7635. this._interpolants = interpolants; // bound by the mixer
  7636. // inside: PropertyMixer (managed by the mixer)
  7637. this._propertyBindings = new Array( nTracks );
  7638. this._cacheIndex = null; // for the memory manager
  7639. this._byClipCacheIndex = null; // for the memory manager
  7640. this._timeScaleInterpolant = null;
  7641. this._weightInterpolant = null;
  7642. this.loop = THREE.LoopRepeat;
  7643. this._loopCount = -1;
  7644. // global mixer time when the action is to be started
  7645. // it's set back to 'null' upon start of the action
  7646. this._startTime = null;
  7647. // scaled local time of the action
  7648. // gets clamped or wrapped to 0..clip.duration according to loop
  7649. this.time = 0;
  7650. this.timeScale = 1;
  7651. this._effectiveTimeScale = 1;
  7652. this.weight = 1;
  7653. this._effectiveWeight = 1;
  7654. this.repetitions = Infinity; // no. of repetitions when looping
  7655. this.paused = false; // false -> zero effective time scale
  7656. this.enabled = true; // true -> zero effective weight
  7657. this.clampWhenFinished = false; // keep feeding the last frame?
  7658. this.zeroSlopeAtStart = true; // for smooth interpolation w/o separate
  7659. this.zeroSlopeAtEnd = true; // clips for start, loop and end
  7660. };
  7661. THREE.AnimationMixer._Action.prototype = {
  7662. constructor: THREE.AnimationMixer._Action,
  7663. // State & Scheduling
  7664. play: function() {
  7665. this._mixer._activateAction( this );
  7666. return this;
  7667. },
  7668. stop: function() {
  7669. this._mixer._deactivateAction( this );
  7670. return this.reset();
  7671. },
  7672. reset: function() {
  7673. this.paused = false;
  7674. this.enabled = true;
  7675. this.time = 0; // restart clip
  7676. this._loopCount = -1; // forget previous loops
  7677. this._startTime = null; // forget scheduling
  7678. return this.stopFading().stopWarping();
  7679. },
  7680. isRunning: function() {
  7681. var start = this._startTime;
  7682. return this.enabled && ! this.paused && this.timeScale !== 0 &&
  7683. this._startTime === null && this._mixer._isActiveAction( this )
  7684. },
  7685. // return true when play has been called
  7686. isScheduled: function() {
  7687. return this._mixer._isActiveAction( this );
  7688. },
  7689. startAt: function( time ) {
  7690. this._startTime = time;
  7691. return this;
  7692. },
  7693. setLoop: function( mode, repetitions ) {
  7694. this.loop = mode;
  7695. this.repetitions = repetitions;
  7696. return this;
  7697. },
  7698. // Weight
  7699. // set the weight stopping any scheduled fading
  7700. // although .enabled = false yields an effective weight of zero, this
  7701. // method does *not* change .enabled, because it would be confusing
  7702. setEffectiveWeight: function( weight ) {
  7703. this.weight = weight;
  7704. // note: same logic as when updated at runtime
  7705. this._effectiveWeight = this.enabled ? weight : 0;
  7706. return this.stopFading();
  7707. },
  7708. // return the weight considering fading and .enabled
  7709. getEffectiveWeight: function() {
  7710. return this._effectiveWeight;
  7711. },
  7712. fadeIn: function( duration ) {
  7713. return this._scheduleFading( duration, 0, 1 );
  7714. },
  7715. fadeOut: function( duration ) {
  7716. return this._scheduleFading( duration, 1, 0 );
  7717. },
  7718. crossFadeFrom: function( fadeOutAction, duration, warp ) {
  7719. var mixer = this._mixer;
  7720. fadeOutAction.fadeOut( duration );
  7721. this.fadeIn( duration );
  7722. if( warp ) {
  7723. var fadeInDuration = this._clip.duration,
  7724. fadeOutDuration = fadeOutAction._clip.duration,
  7725. startEndRatio = fadeOutDuration / fadeInDuration,
  7726. endStartRatio = fadeInDuration / fadeOutDuration;
  7727. fadeOutAction.warp( 1.0, startEndRatio, duration );
  7728. this.warp( endStartRatio, 1.0, duration );
  7729. }
  7730. return this;
  7731. },
  7732. crossFadeTo: function( fadeInAction, duration, warp ) {
  7733. return fadeInAction.crossFadeFrom( this, duration, warp );
  7734. },
  7735. stopFading: function() {
  7736. var weightInterpolant = this._weightInterpolant;
  7737. if ( weightInterpolant !== null ) {
  7738. this._weightInterpolant = null;
  7739. this._mixer._takeBackControlInterpolant( weightInterpolant );
  7740. }
  7741. return this;
  7742. },
  7743. // Time Scale Control
  7744. // set the weight stopping any scheduled warping
  7745. // although .paused = true yields an effective time scale of zero, this
  7746. // method does *not* change .paused, because it would be confusing
  7747. setEffectiveTimeScale: function( timeScale ) {
  7748. this.timeScale = timeScale;
  7749. this._effectiveTimeScale = this.paused ? 0 :timeScale;
  7750. return this.stopWarping();
  7751. },
  7752. // return the time scale considering warping and .paused
  7753. getEffectiveTimeScale: function() {
  7754. return this._effectiveTimeScale;
  7755. },
  7756. setDuration: function( duration ) {
  7757. this.timeScale = this._clip.duration / duration;
  7758. return this.stopWarping();
  7759. },
  7760. syncWith: function( action ) {
  7761. this.time = action.time;
  7762. this.timeScale = action.timeScale;
  7763. return this.stopWarping();
  7764. },
  7765. halt: function( duration ) {
  7766. return this.warp( this._currentTimeScale, 0, duration );
  7767. },
  7768. warp: function( startTimeScale, endTimeScale, duration ) {
  7769. var mixer = this._mixer, now = mixer.time,
  7770. interpolant = this._timeScaleInterpolant,
  7771. timeScale = this.timeScale;
  7772. if ( interpolant === null ) {
  7773. interpolant = mixer._lendControlInterpolant(),
  7774. this._timeScaleInterpolant = interpolant;
  7775. }
  7776. var times = interpolant.parameterPositions,
  7777. values = interpolant.sampleValues;
  7778. times[ 0 ] = now;
  7779. times[ 1 ] = now + duration;
  7780. values[ 0 ] = startTimeScale / timeScale;
  7781. values[ 1 ] = endTimeScale / timeScale;
  7782. return this;
  7783. },
  7784. stopWarping: function() {
  7785. var timeScaleInterpolant = this._timeScaleInterpolant;
  7786. if ( timeScaleInterpolant !== null ) {
  7787. this._timeScaleInterpolant = null;
  7788. this._mixer._takeBackControlInterpolant( timeScaleInterpolant );
  7789. }
  7790. return this;
  7791. },
  7792. // Object Accessors
  7793. getMixer: function() {
  7794. return this._mixer;
  7795. },
  7796. getClip: function() {
  7797. return this._clip;
  7798. },
  7799. getRoot: function() {
  7800. return this._localRoot || this._mixer._root;
  7801. },
  7802. // Interna
  7803. _update: function( time, deltaTime, timeDirection, accuIndex ) {
  7804. // called by the mixer
  7805. var startTime = this._startTime;
  7806. if ( startTime !== null ) {
  7807. // check for scheduled start of action
  7808. var timeRunning = ( time - startTime ) * timeDirection;
  7809. if ( timeRunning < 0 || timeDirection === 0 ) {
  7810. return; // yet to come / don't decide when delta = 0
  7811. }
  7812. // start
  7813. this._startTime = null; // unschedule
  7814. deltaTime = timeDirection * timeRunning;
  7815. }
  7816. // apply time scale and advance time
  7817. deltaTime *= this._updateTimeScale( time );
  7818. var clipTime = this._updateTime( deltaTime );
  7819. // note: _updateTime may disable the action resulting in
  7820. // an effective weight of 0
  7821. var weight = this._updateWeight( time );
  7822. if ( weight > 0 ) {
  7823. var interpolants = this._interpolants;
  7824. var propertyMixers = this._propertyBindings;
  7825. for ( var j = 0, m = interpolants.length; j !== m; ++ j ) {
  7826. interpolants[ j ].evaluate( clipTime );
  7827. propertyMixers[ j ].accumulate( accuIndex, weight );
  7828. }
  7829. }
  7830. },
  7831. _updateWeight: function( time ) {
  7832. var weight = 0;
  7833. if ( this.enabled ) {
  7834. weight = this.weight;
  7835. var interpolant = this._weightInterpolant;
  7836. if ( interpolant !== null ) {
  7837. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  7838. weight *= interpolantValue;
  7839. if ( time > interpolant.parameterPositions[ 1 ] ) {
  7840. this.stopFading();
  7841. if ( interpolantValue === 0 ) {
  7842. // faded out, disable
  7843. this.enabled = false;
  7844. }
  7845. }
  7846. }
  7847. }
  7848. this._effectiveWeight = weight;
  7849. return weight;
  7850. },
  7851. _updateTimeScale: function( time ) {
  7852. var timeScale = 0;
  7853. if ( ! this.paused ) {
  7854. timeScale = this.timeScale;
  7855. var interpolant = this._timeScaleInterpolant;
  7856. if ( interpolant !== null ) {
  7857. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  7858. timeScale *= interpolantValue;
  7859. if ( time > interpolant.parameterPositions[ 1 ] ) {
  7860. this.stopWarping();
  7861. if ( timeScale === 0 ) {
  7862. // motion has halted, pause
  7863. this.pause = true;
  7864. } else {
  7865. // warp done - apply final time scale
  7866. this.timeScale = timeScale;
  7867. }
  7868. }
  7869. }
  7870. }
  7871. this._effectiveTimeScale = timeScale;
  7872. return timeScale;
  7873. },
  7874. _updateTime: function( deltaTime ) {
  7875. var time = this.time + deltaTime;
  7876. if ( deltaTime === 0 ) return time;
  7877. var duration = this._clip.duration,
  7878. loop = this.loop,
  7879. loopCount = this._loopCount,
  7880. pingPong = false;
  7881. switch ( loop ) {
  7882. case THREE.LoopOnce:
  7883. if ( loopCount === -1 ) {
  7884. // just started
  7885. this.loopCount = 0;
  7886. this._setEndings( true, true, false );
  7887. }
  7888. if ( time >= duration ) {
  7889. time = duration;
  7890. } else if ( time < 0 ) {
  7891. time = 0;
  7892. } else break;
  7893. // reached the end
  7894. if ( this.clampWhenFinished ) this.pause = true;
  7895. else this.enabled = false;
  7896. this._mixer.dispatchEvent( {
  7897. type: 'finished', action: this,
  7898. direction: deltaTime < 0 ? -1 : 1
  7899. } );
  7900. break;
  7901. case THREE.LoopPingPong:
  7902. pingPong = true;
  7903. case THREE.LoopRepeat:
  7904. if ( loopCount === -1 ) {
  7905. // just started
  7906. if ( deltaTime > 0 ) {
  7907. loopCount = 0;
  7908. this._setEndings(
  7909. true, this.repetitions === 0, pingPong );
  7910. } else {
  7911. // when looping in reverse direction, the initial
  7912. // transition through zero counts as a repetition,
  7913. // so leave loopCount at -1
  7914. this._setEndings(
  7915. this.repetitions === 0, true, pingPong );
  7916. }
  7917. }
  7918. if ( time >= duration || time < 0 ) {
  7919. // wrap around
  7920. var loopDelta = Math.floor( time / duration ); // signed
  7921. time -= duration * loopDelta;
  7922. loopCount += Math.abs( loopDelta );
  7923. var pending = this.repetitions - loopCount;
  7924. if ( pending < 0 ) {
  7925. // stop (switch state, clamp time, fire event)
  7926. if ( this.clampWhenFinished ) this.paused = true;
  7927. else this.enabled = false;
  7928. time = deltaTime > 0 ? duration : 0;
  7929. this._mixer.dispatchEvent( {
  7930. type: 'finished', action: this,
  7931. direction: deltaTime > 0 ? 1 : -1
  7932. } );
  7933. break;
  7934. } else if ( pending === 0 ) {
  7935. // transition to last round
  7936. var atStart = deltaTime < 0;
  7937. this._setEndings( atStart, ! atStart, pingPong );
  7938. } else {
  7939. this._setEndings( false, false, pingPong );
  7940. }
  7941. this._loopCount = loopCount;
  7942. this._mixer.dispatchEvent( {
  7943. type: 'loop', action: this, loopDelta: loopDelta
  7944. } );
  7945. }
  7946. if ( loop === THREE.LoopPingPong && ( loopCount & 1 ) === 1 ) {
  7947. // invert time for the "pong round"
  7948. this.time = time;
  7949. return duration - time;
  7950. }
  7951. break;
  7952. }
  7953. this.time = time;
  7954. return time;
  7955. },
  7956. _setEndings: function( atStart, atEnd, pingPong ) {
  7957. var settings = this._interpolantSettings;
  7958. if ( pingPong ) {
  7959. settings.endingStart = THREE.ZeroSlopeEnding;
  7960. settings.endingEnd = THREE.ZeroSlopeEnding;
  7961. } else {
  7962. // assuming for LoopOnce atStart == atEnd == true
  7963. if ( atStart ) {
  7964. settings.endingStart = this.zeroSlopeAtStart ?
  7965. THREE.ZeroSlopeEnding : THREE.ZeroCurvatureEnding;
  7966. } else {
  7967. settings.endingStart = THREE.WrapAroundEnding;
  7968. }
  7969. if ( atEnd ) {
  7970. settings.endingEnd = this.zeroSlopeAtEnd ?
  7971. THREE.ZeroSlopeEnding : THREE.ZeroCurvatureEnding;
  7972. } else {
  7973. settings.endingEnd = THREE.WrapAroundEnding;
  7974. }
  7975. }
  7976. },
  7977. _scheduleFading: function( duration, weightNow, weightThen ) {
  7978. var mixer = this._mixer, now = mixer.time,
  7979. interpolant = this._weightInterpolant;
  7980. if ( interpolant === null ) {
  7981. interpolant = mixer._lendControlInterpolant(),
  7982. this._weightInterpolant = interpolant;
  7983. }
  7984. var times = interpolant.parameterPositions,
  7985. values = interpolant.sampleValues;
  7986. times[ 0 ] = now; values[ 0 ] = weightNow;
  7987. times[ 1 ] = now + duration; values[ 1 ] = weightThen;
  7988. return this;
  7989. }
  7990. };
  7991. // Implementation details:
  7992. Object.assign( THREE.AnimationMixer.prototype, {
  7993. _bindAction: function( action, prototypeAction ) {
  7994. var root = action._localRoot || this._root,
  7995. tracks = action._clip.tracks,
  7996. nTracks = tracks.length,
  7997. bindings = action._propertyBindings,
  7998. interpolants = action._interpolants,
  7999. rootUuid = root.uuid,
  8000. bindingsByRoot = this._bindingsByRootAndName,
  8001. bindingsByName = bindingsByRoot[ rootUuid ];
  8002. if ( bindingsByName === undefined ) {
  8003. bindingsByName = {};
  8004. bindingsByRoot[ rootUuid ] = bindingsByName;
  8005. }
  8006. for ( var i = 0; i !== nTracks; ++ i ) {
  8007. var track = tracks[ i ],
  8008. trackName = track.name,
  8009. binding = bindingsByName[ trackName ];
  8010. if ( binding !== undefined ) {
  8011. bindings[ i ] = binding;
  8012. } else {
  8013. binding = bindings[ i ];
  8014. if ( binding !== undefined ) {
  8015. // existing binding, make sure the cache knows
  8016. if ( binding._cacheIndex === null ) {
  8017. ++ binding.referenceCount;
  8018. this._addInactiveBinding( binding, rootUuid, trackName );
  8019. }
  8020. continue;
  8021. }
  8022. var path = prototypeAction && prototypeAction.
  8023. _propertyBindings[ i ].binding.parsedPath;
  8024. binding = new THREE.PropertyMixer(
  8025. THREE.PropertyBinding.create( root, trackName, path ),
  8026. track.ValueTypeName, track.getValueSize() );
  8027. ++ binding.referenceCount;
  8028. this._addInactiveBinding( binding, rootUuid, trackName );
  8029. bindings[ i ] = binding;
  8030. }
  8031. interpolants[ i ].resultBuffer = binding.buffer;
  8032. }
  8033. },
  8034. _activateAction: function( action ) {
  8035. if ( ! this._isActiveAction( action ) ) {
  8036. if ( action._cacheIndex === null ) {
  8037. // this action has been forgotten by the cache, but the user
  8038. // appears to be still using it -> rebind
  8039. var rootUuid = ( action._localRoot || this._root ).uuid,
  8040. clipName = action._clip.name,
  8041. actionsForClip = this._actionsByClip[ clipName ];
  8042. this._bindAction( action,
  8043. actionsForClip && actionsForClip.knownActions[ 0 ] );
  8044. this._addInactiveAction( action, clipName, rootUuid );
  8045. }
  8046. var bindings = action._propertyBindings;
  8047. // increment reference counts / sort out state
  8048. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  8049. var binding = bindings[ i ];
  8050. if ( binding.useCount ++ === 0 ) {
  8051. this._lendBinding( binding );
  8052. binding.saveOriginalState();
  8053. }
  8054. }
  8055. this._lendAction( action );
  8056. }
  8057. },
  8058. _deactivateAction: function( action ) {
  8059. if ( this._isActiveAction( action ) ) {
  8060. var bindings = action._propertyBindings;
  8061. // decrement reference counts / sort out state
  8062. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  8063. var binding = bindings[ i ];
  8064. if ( -- binding.useCount === 0 ) {
  8065. binding.restoreOriginalState();
  8066. this._takeBackBinding( binding );
  8067. }
  8068. }
  8069. this._takeBackAction( action );
  8070. }
  8071. },
  8072. // Memory manager
  8073. _initMemoryManager: function() {
  8074. this._actions = []; // 'nActiveActions' followed by inactive ones
  8075. this._nActiveActions = 0;
  8076. this._actionsByClip = {};
  8077. // inside:
  8078. // {
  8079. // knownActions: Array< _Action > - used as prototypes
  8080. // actionByRoot: _Action - lookup
  8081. // }
  8082. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  8083. this._nActiveBindings = 0;
  8084. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  8085. this._controlInterpolants = []; // same game as above
  8086. this._nActiveControlInterpolants = 0;
  8087. var scope = this;
  8088. this.stats = {
  8089. actions: {
  8090. get total() { return scope._actions.length; },
  8091. get inUse() { return scope._nActiveActions; }
  8092. },
  8093. bindings: {
  8094. get total() { return scope._bindings.length; },
  8095. get inUse() { return scope._nActiveBindings; }
  8096. },
  8097. controlInterpolants: {
  8098. get total() { return scope._controlInterpolants.length; },
  8099. get inUse() { return scope._nActiveControlInterpolants; }
  8100. }
  8101. };
  8102. },
  8103. // Memory management for _Action objects
  8104. _isActiveAction: function( action ) {
  8105. var index = action._cacheIndex;
  8106. return index !== null && index < this._nActiveActions;
  8107. },
  8108. _addInactiveAction: function( action, clipName, rootUuid ) {
  8109. var actions = this._actions,
  8110. actionsByClip = this._actionsByClip,
  8111. actionsForClip = actionsByClip[ clipName ];
  8112. if ( actionsForClip === undefined ) {
  8113. actionsForClip = {
  8114. knownActions: [ action ],
  8115. actionByRoot: {}
  8116. };
  8117. action._byClipCacheIndex = 0;
  8118. actionsByClip[ clipName ] = actionsForClip;
  8119. } else {
  8120. var knownActions = actionsForClip.knownActions;
  8121. action._byClipCacheIndex = knownActions.length;
  8122. knownActions.push( action );
  8123. }
  8124. action._cacheIndex = actions.length;
  8125. actions.push( action );
  8126. actionsForClip.actionByRoot[ rootUuid ] = action;
  8127. },
  8128. _removeInactiveAction: function( action ) {
  8129. var actions = this._actions,
  8130. lastInactiveAction = actions[ actions.length - 1 ],
  8131. cacheIndex = action._cacheIndex;
  8132. lastInactiveAction._cacheIndex = cacheIndex;
  8133. actions[ cacheIndex ] = lastInactiveAction;
  8134. actions.pop();
  8135. action._cacheIndex = null;
  8136. var clipName = action._clip.name,
  8137. actionsByClip = this._actionsByClip,
  8138. actionsForClip = actionsByClip[ clipName ],
  8139. knownActionsForClip = actionsForClip.knownActions,
  8140. lastKnownAction =
  8141. knownActionsForClip[ knownActionsForClip.length - 1 ],
  8142. byClipCacheIndex = action._byClipCacheIndex;
  8143. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  8144. knownActionsForClip[ byClipCacheIndex ] = lastKnownAction;
  8145. knownActionsForClip.pop();
  8146. action._byClipCacheIndex = null;
  8147. var actionByRoot = actionsForClip.actionByRoot,
  8148. rootUuid = ( actions._localRoot || this._root ).uuid;
  8149. delete actionByRoot[ rootUuid ];
  8150. if ( knownActionsForClip.length === 0 ) {
  8151. delete actionsByClip[ clipName ];
  8152. }
  8153. this._removeInactiveBindingsForAction( action );
  8154. },
  8155. _removeInactiveBindingsForAction: function( action ) {
  8156. var bindings = action._propertyBindings;
  8157. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  8158. var binding = bindings[ i ];
  8159. if ( -- binding.referenceCount === 0 ) {
  8160. this._removeInactiveBinding( binding );
  8161. }
  8162. }
  8163. },
  8164. _lendAction: function( action ) {
  8165. // [ active actions | inactive actions ]
  8166. // [ active actions >| inactive actions ]
  8167. // s a
  8168. // <-swap->
  8169. // a s
  8170. var actions = this._actions,
  8171. prevIndex = action._cacheIndex,
  8172. lastActiveIndex = this._nActiveActions ++,
  8173. firstInactiveAction = actions[ lastActiveIndex ];
  8174. action._cacheIndex = lastActiveIndex;
  8175. actions[ lastActiveIndex ] = action;
  8176. firstInactiveAction._cacheIndex = prevIndex;
  8177. actions[ prevIndex ] = firstInactiveAction;
  8178. },
  8179. _takeBackAction: function( action ) {
  8180. // [ active actions | inactive actions ]
  8181. // [ active actions |< inactive actions ]
  8182. // a s
  8183. // <-swap->
  8184. // s a
  8185. var actions = this._actions,
  8186. prevIndex = action._cacheIndex,
  8187. firstInactiveIndex = -- this._nActiveActions,
  8188. lastActiveAction = actions[ firstInactiveIndex ];
  8189. action._cacheIndex = firstInactiveIndex;
  8190. actions[ firstInactiveIndex ] = action;
  8191. lastActiveAction._cacheIndex = prevIndex;
  8192. actions[ prevIndex ] = lastActiveAction;
  8193. },
  8194. // Memory management for PropertyMixer objects
  8195. _addInactiveBinding: function( binding, rootUuid, trackName ) {
  8196. var bindingsByRoot = this._bindingsByRootAndName,
  8197. bindingByName = bindingsByRoot[ rootUuid ],
  8198. bindings = this._bindings;
  8199. if ( bindingByName === undefined ) {
  8200. bindingByName = {};
  8201. bindingsByRoot[ rootUuid ] = bindingByName;
  8202. }
  8203. bindingByName[ trackName ] = binding;
  8204. binding._cacheIndex = bindings.length;
  8205. bindings.push( binding );
  8206. },
  8207. _removeInactiveBinding: function( binding ) {
  8208. var bindings = this._bindings,
  8209. propBinding = binding.binding,
  8210. rootUuid = propBinding.rootNode.uuid,
  8211. trackName = propBinding.path,
  8212. bindingsByRoot = this._bindingsByRootAndName,
  8213. bindingByName = bindingsByRoot[ rootUuid ],
  8214. lastInactiveBinding = bindings[ bindings.length - 1 ],
  8215. cacheIndex = binding._cacheIndex;
  8216. lastInactiveBinding._cacheIndex = cacheIndex;
  8217. bindings[ cacheIndex ] = lastInactiveBinding;
  8218. bindings.pop();
  8219. delete bindingByName[ trackName ];
  8220. remove_empty_map: {
  8221. for ( var _ in bindingByName ) break remove_empty_map;
  8222. delete bindingsByRoot[ rootUuid ];
  8223. }
  8224. },
  8225. _lendBinding: function( binding ) {
  8226. var bindings = this._bindings,
  8227. prevIndex = binding._cacheIndex,
  8228. lastActiveIndex = this._nActiveBindings ++,
  8229. firstInactiveBinding = bindings[ lastActiveIndex ];
  8230. binding._cacheIndex = lastActiveIndex;
  8231. bindings[ lastActiveIndex ] = binding;
  8232. firstInactiveBinding._cacheIndex = prevIndex;
  8233. bindings[ prevIndex ] = firstInactiveBinding;
  8234. },
  8235. _takeBackBinding: function( binding ) {
  8236. var bindings = this._bindings,
  8237. prevIndex = binding._cacheIndex,
  8238. firstInactiveIndex = -- this._nActiveBindings,
  8239. lastActiveBinding = bindings[ firstInactiveIndex ];
  8240. binding._cacheIndex = firstInactiveIndex;
  8241. bindings[ firstInactiveIndex ] = binding;
  8242. lastActiveBinding._cacheIndex = prevIndex;
  8243. bindings[ prevIndex ] = lastActiveBinding;
  8244. },
  8245. // Memory management of Interpolants for weight and time scale
  8246. _lendControlInterpolant: function() {
  8247. var interpolants = this._controlInterpolants,
  8248. lastActiveIndex = this._nActiveControlInterpolants ++,
  8249. interpolant = interpolants[ lastActiveIndex ];
  8250. if ( interpolant === undefined ) {
  8251. interpolant = new THREE.LinearInterpolant(
  8252. new Float32Array( 2 ), new Float32Array( 2 ),
  8253. 1, this._controlInterpolantsResultBuffer );
  8254. interpolant.__cacheIndex = lastActiveIndex;
  8255. interpolants[ lastActiveIndex ] = interpolant;
  8256. }
  8257. return interpolant;
  8258. },
  8259. _takeBackControlInterpolant: function( interpolant ) {
  8260. var interpolants = this._controlInterpolants,
  8261. prevIndex = interpolant.__cacheIndex,
  8262. firstInactiveIndex = -- this._nActiveControlInterpolants,
  8263. lastActiveInterpolant = interpolants[ firstInactiveIndex ];
  8264. interpolant.__cacheIndex = firstInactiveIndex;
  8265. interpolants[ firstInactiveIndex ] = interpolant;
  8266. lastActiveInterpolant.__cacheIndex = prevIndex;
  8267. interpolants[ prevIndex ] = lastActiveInterpolant;
  8268. },
  8269. _controlInterpolantsResultBuffer: new Float32Array( 1 )
  8270. } );
  8271. // File:src/animation/AnimationObjectGroup.js
  8272. /**
  8273. *
  8274. * A group of objects that receives a shared animation state.
  8275. *
  8276. * Usage:
  8277. *
  8278. * - Add objects you would otherwise pass as 'root' to the
  8279. * constructor or the .clipAction method of AnimationMixer.
  8280. *
  8281. * - Instead pass this object as 'root'.
  8282. *
  8283. * - You can also add and remove objects later when the mixer
  8284. * is running.
  8285. *
  8286. * Note:
  8287. *
  8288. * Objects of this class appear as one object to the mixer,
  8289. * so cache control of the individual objects must be done
  8290. * on the group.
  8291. *
  8292. * Limitation:
  8293. *
  8294. * - The animated properties must be compatible among the
  8295. * all objects in the group.
  8296. *
  8297. * - A single property can either be controlled through a
  8298. * target group or directly, but not both.
  8299. *
  8300. * @author tschw
  8301. */
  8302. THREE.AnimationObjectGroup = function( var_args ) {
  8303. this.uuid = THREE.Math.generateUUID();
  8304. // cached objects followed by the active ones
  8305. this._objects = Array.prototype.slice.call( arguments );
  8306. this.nCachedObjects_ = 0; // threshold
  8307. // note: read by PropertyBinding.Composite
  8308. var indices = {};
  8309. this._indicesByUUID = indices; // for bookkeeping
  8310. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  8311. indices[ arguments[ i ].uuid ] = i;
  8312. }
  8313. this._paths = []; // inside: string
  8314. this._parsedPaths = []; // inside: { we don't care, here }
  8315. this._bindings = []; // inside: Array< PropertyBinding >
  8316. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  8317. var scope = this;
  8318. this.stats = {
  8319. objects: {
  8320. get total() { return scope._objects.length; },
  8321. get inUse() { return this.total - scope.nCachedObjects_; }
  8322. },
  8323. get bindingsPerObject() { return scope._bindings.length; }
  8324. };
  8325. };
  8326. THREE.AnimationObjectGroup.prototype = {
  8327. constructor: THREE.AnimationObjectGroup,
  8328. add: function( var_args ) {
  8329. var objects = this._objects,
  8330. nObjects = objects.length,
  8331. nCachedObjects = this.nCachedObjects_,
  8332. indicesByUUID = this._indicesByUUID,
  8333. paths = this._paths,
  8334. parsedPaths = this._parsedPaths,
  8335. bindings = this._bindings,
  8336. nBindings = bindings.length;
  8337. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  8338. var object = arguments[ i ],
  8339. uuid = object.uuid,
  8340. index = indicesByUUID[ uuid ];
  8341. if ( index === undefined ) {
  8342. // unknown object -> add it to the ACTIVE region
  8343. index = nObjects ++;
  8344. indicesByUUID[ uuid ] = index;
  8345. objects.push( object );
  8346. // accounting is done, now do the same for all bindings
  8347. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8348. bindings[ j ].push(
  8349. new THREE.PropertyBinding(
  8350. object, paths[ j ], parsedPaths[ j ] ) );
  8351. }
  8352. } else if ( index < nCachedObjects ) {
  8353. var knownObject = objects[ index ];
  8354. // move existing object to the ACTIVE region
  8355. var firstActiveIndex = -- nCachedObjects,
  8356. lastCachedObject = objects[ firstActiveIndex ];
  8357. indicesByUUID[ lastCachedObject.uuid ] = index;
  8358. objects[ index ] = lastCachedObject;
  8359. indicesByUUID[ uuid ] = firstActiveIndex;
  8360. objects[ firstActiveIndex ] = object;
  8361. // accounting is done, now do the same for all bindings
  8362. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8363. var bindingsForPath = bindings[ j ],
  8364. lastCached = bindingsForPath[ firstActiveIndex ],
  8365. binding = bindingsForPath[ index ];
  8366. bindingsForPath[ index ] = lastCached;
  8367. if ( binding === undefined ) {
  8368. // since we do not bother to create new bindings
  8369. // for objects that are cached, the binding may
  8370. // or may not exist
  8371. binding = new THREE.PropertyBinding(
  8372. object, paths[ j ], parsedPaths[ j ] );
  8373. }
  8374. bindingsForPath[ firstActiveIndex ] = binding;
  8375. }
  8376. } else if ( objects[ index ] !== knownObject) {
  8377. console.error( "Different objects with the same UUID " +
  8378. "detected. Clean the caches or recreate your " +
  8379. "infrastructure when reloading scenes..." );
  8380. } // else the object is already where we want it to be
  8381. } // for arguments
  8382. this.nCachedObjects_ = nCachedObjects;
  8383. },
  8384. remove: function( var_args ) {
  8385. var objects = this._objects,
  8386. nObjects = objects.length,
  8387. nCachedObjects = this.nCachedObjects_,
  8388. indicesByUUID = this._indicesByUUID,
  8389. bindings = this._bindings,
  8390. nBindings = bindings.length;
  8391. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  8392. var object = arguments[ i ],
  8393. uuid = object.uuid,
  8394. index = indicesByUUID[ uuid ];
  8395. if ( index !== undefined && index >= nCachedObjects ) {
  8396. // move existing object into the CACHED region
  8397. var lastCachedIndex = nCachedObjects ++,
  8398. firstActiveObject = objects[ lastCachedIndex ];
  8399. indicesByUUID[ firstActiveObject.uuid ] = index;
  8400. objects[ index ] = firstActiveObject;
  8401. indicesByUUID[ uuid ] = lastCachedIndex;
  8402. objects[ lastCachedIndex ] = object;
  8403. // accounting is done, now do the same for all bindings
  8404. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8405. var bindingsForPath = bindings[ j ],
  8406. firstActive = bindingsForPath[ lastCachedIndex ],
  8407. binding = bindingsForPath[ index ];
  8408. bindingsForPath[ index ] = firstActive;
  8409. bindingsForPath[ lastCachedIndex ] = binding;
  8410. }
  8411. }
  8412. } // for arguments
  8413. this.nCachedObjects_ = nCachedObjects;
  8414. },
  8415. // remove & forget
  8416. uncache: function( var_args ) {
  8417. var objects = this._objects,
  8418. nObjects = objects.length,
  8419. nCachedObjects = this.nCachedObjects_,
  8420. indicesByUUID = this._indicesByUUID,
  8421. bindings = this._bindings,
  8422. nBindings = bindings.length;
  8423. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  8424. var object = arguments[ i ],
  8425. uuid = object.uuid,
  8426. index = indicesByUUID[ uuid ];
  8427. if ( index !== undefined ) {
  8428. delete indicesByUUID[ uuid ];
  8429. if ( index < nCachedObjects ) {
  8430. // object is cached, shrink the CACHED region
  8431. var firstActiveIndex = -- nCachedObjects,
  8432. lastCachedObject = objects[ firstActiveIndex ],
  8433. lastIndex = -- nObjects,
  8434. lastObject = objects[ lastIndex ];
  8435. // last cached object takes this object's place
  8436. indicesByUUID[ lastCachedObject.uuid ] = index;
  8437. objects[ index ] = lastCachedObject;
  8438. // last object goes to the activated slot and pop
  8439. indicesByUUID[ lastObject.uuid ] = firstActiveIndex;
  8440. objects[ firstActiveIndex ] = lastObject;
  8441. objects.pop();
  8442. // accounting is done, now do the same for all bindings
  8443. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8444. var bindingsForPath = bindings[ j ],
  8445. lastCached = bindingsForPath[ firstActiveIndex ],
  8446. last = bindingsForPath[ lastIndex ];
  8447. bindingsForPath[ index ] = lastCached;
  8448. bindingsForPath[ firstActiveIndex ] = last;
  8449. bindingsForPath.pop();
  8450. }
  8451. } else {
  8452. // object is active, just swap with the last and pop
  8453. var lastIndex = -- nObjects,
  8454. lastObject = objects[ lastIndex ];
  8455. indicesByUUID[ lastObject.uuid ] = index;
  8456. objects[ index ] = lastObject;
  8457. objects.pop();
  8458. // accounting is done, now do the same for all bindings
  8459. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8460. var bindingsForPath = bindings[ j ];
  8461. bindingsForPath[ index ] = bindingsForPath[ lastIndex ];
  8462. bindingsForPath.pop();
  8463. }
  8464. } // cached or active
  8465. } // if object is known
  8466. } // for arguments
  8467. this.nCachedObjects_ = nCachedObjects;
  8468. },
  8469. // Internal interface used by befriended PropertyBinding.Composite:
  8470. subscribe_: function( path, parsedPath ) {
  8471. // returns an array of bindings for the given path that is changed
  8472. // according to the contained objects in the group
  8473. var indicesByPath = this._bindingsIndicesByPath,
  8474. index = indicesByPath[ path ],
  8475. bindings = this._bindings;
  8476. if ( index !== undefined ) return bindings[ index ];
  8477. var paths = this._paths,
  8478. parsedPaths = this._parsedPaths,
  8479. objects = this._objects,
  8480. nObjects = objects.length,
  8481. nCachedObjects = this.nCachedObjects_,
  8482. bindingsForPath = new Array( nObjects );
  8483. index = bindings.length;
  8484. indicesByPath[ path ] = index;
  8485. paths.push( path );
  8486. parsedPaths.push( parsedPath );
  8487. bindings.push( bindingsForPath );
  8488. for ( var i = nCachedObjects,
  8489. n = objects.length; i !== n; ++ i ) {
  8490. var object = objects[ i ];
  8491. bindingsForPath[ i ] =
  8492. new THREE.PropertyBinding( object, path, parsedPath );
  8493. }
  8494. return bindingsForPath;
  8495. },
  8496. unsubscribe_: function( path ) {
  8497. // tells the group to forget about a property path and no longer
  8498. // update the array previously obtained with 'subscribe_'
  8499. var indicesByPath = this._bindingsIndicesByPath,
  8500. index = indicesByPath[ path ];
  8501. if ( index !== undefined ) {
  8502. var paths = this._paths,
  8503. parsedPaths = this._parsedPaths,
  8504. bindings = this._bindings,
  8505. lastBindingsIndex = bindings.length - 1,
  8506. lastBindings = bindings[ lastBindingsIndex ],
  8507. lastBindingsPath = path[ lastBindingsIndex ];
  8508. indicesByPath[ lastBindingsPath ] = index;
  8509. bindings[ index ] = lastBindings;
  8510. bindings.pop();
  8511. parsedPaths[ index ] = parsedPaths[ lastBindingsIndex ];
  8512. parsedPaths.pop();
  8513. paths[ index ] = paths[ lastBindingsIndex ];
  8514. paths.pop();
  8515. }
  8516. }
  8517. };
  8518. // File:src/animation/AnimationUtils.js
  8519. /**
  8520. * @author tschw
  8521. * @author Ben Houston / http://clara.io/
  8522. * @author David Sarno / http://lighthaus.us/
  8523. */
  8524. THREE.AnimationUtils = {
  8525. // same as Array.prototype.slice, but also works on typed arrays
  8526. arraySlice: function( array, from, to ) {
  8527. if ( THREE.AnimationUtils.isTypedArray( array ) ) {
  8528. return new array.constructor( array.subarray( from, to ) );
  8529. }
  8530. return array.slice( from, to );
  8531. },
  8532. // converts an array to a specific type
  8533. convertArray: function( array, type, forceClone ) {
  8534. if ( ! array || // let 'undefined' and 'null' pass
  8535. ! forceClone && array.constructor === type ) return array;
  8536. if ( typeof type.BYTES_PER_ELEMENT === 'number' ) {
  8537. return new type( array ); // create typed array
  8538. }
  8539. return Array.prototype.slice.call( array ); // create Array
  8540. },
  8541. isTypedArray: function( object ) {
  8542. return ArrayBuffer.isView( object ) &&
  8543. ! ( object instanceof DataView );
  8544. },
  8545. // returns an array by which times and values can be sorted
  8546. getKeyframeOrder: function( times ) {
  8547. function compareTime( i, j ) {
  8548. return times[ i ] - times[ j ];
  8549. }
  8550. var n = times.length;
  8551. var result = new Array( n );
  8552. for ( var i = 0; i !== n; ++ i ) result[ i ] = i;
  8553. result.sort( compareTime );
  8554. return result;
  8555. },
  8556. // uses the array previously returned by 'getKeyframeOrder' to sort data
  8557. sortedArray: function( values, stride, order ) {
  8558. var nValues = values.length;
  8559. var result = new values.constructor( nValues );
  8560. for ( var i = 0, dstOffset = 0; dstOffset !== nValues; ++ i ) {
  8561. var srcOffset = order[ i ] * stride;
  8562. for ( var j = 0; j !== stride; ++ j ) {
  8563. result[ dstOffset ++ ] = values[ srcOffset + j ];
  8564. }
  8565. }
  8566. return result;
  8567. },
  8568. // function for parsing AOS keyframe formats
  8569. flattenJSON: function( jsonKeys, times, values, valuePropertyName ) {
  8570. var i = 1, key = jsonKeys[ 0 ];
  8571. while ( key !== undefined && key[ valuePropertyName ] === undefined ) {
  8572. key = jsonKeys[ i ++ ];
  8573. }
  8574. if ( key === undefined ) return; // no data
  8575. var value = key[ valuePropertyName ];
  8576. if ( value === undefined ) return; // no data
  8577. if ( Array.isArray( value ) ) {
  8578. do {
  8579. value = key[ valuePropertyName ];
  8580. if ( value !== undefined ) {
  8581. times.push( key.time );
  8582. values.push.apply( values, value ); // push all elements
  8583. }
  8584. key = jsonKeys[ i ++ ];
  8585. } while ( key !== undefined );
  8586. } else if ( value.toArray !== undefined ) {
  8587. // ...assume THREE.Math-ish
  8588. do {
  8589. value = key[ valuePropertyName ];
  8590. if ( value !== undefined ) {
  8591. times.push( key.time );
  8592. value.toArray( values, values.length );
  8593. }
  8594. key = jsonKeys[ i ++ ];
  8595. } while ( key !== undefined );
  8596. } else {
  8597. // otherwise push as-is
  8598. do {
  8599. value = key[ valuePropertyName ];
  8600. if ( value !== undefined ) {
  8601. times.push( key.time );
  8602. values.push( value );
  8603. }
  8604. key = jsonKeys[ i ++ ];
  8605. } while ( key !== undefined );
  8606. }
  8607. }
  8608. };
  8609. // File:src/animation/KeyframeTrack.js
  8610. /**
  8611. *
  8612. * A timed sequence of keyframes for a specific property.
  8613. *
  8614. *
  8615. * @author Ben Houston / http://clara.io/
  8616. * @author David Sarno / http://lighthaus.us/
  8617. * @author tschw
  8618. */
  8619. THREE.KeyframeTrack = function ( name, times, values, interpolation ) {
  8620. if( name === undefined ) throw new Error( "track name is undefined" );
  8621. if( times === undefined || times.length === 0 ) {
  8622. throw new Error( "no keyframes in track named " + name );
  8623. }
  8624. this.name = name;
  8625. this.times = THREE.AnimationUtils.convertArray( times, this.TimeBufferType );
  8626. this.values = THREE.AnimationUtils.convertArray( values, this.ValueBufferType );
  8627. this.setInterpolation( interpolation || this.DefaultInterpolation );
  8628. this.validate();
  8629. this.optimize();
  8630. };
  8631. THREE.KeyframeTrack.prototype = {
  8632. constructor: THREE.KeyframeTrack,
  8633. TimeBufferType: Float32Array,
  8634. ValueBufferType: Float32Array,
  8635. DefaultInterpolation: THREE.InterpolateLinear,
  8636. InterpolantFactoryMethodDiscrete: function( result ) {
  8637. return new THREE.DiscreteInterpolant(
  8638. this.times, this.values, this.getValueSize(), result );
  8639. },
  8640. InterpolantFactoryMethodLinear: function( result ) {
  8641. return new THREE.LinearInterpolant(
  8642. this.times, this.values, this.getValueSize(), result );
  8643. },
  8644. InterpolantFactoryMethodSmooth: function( result ) {
  8645. return new THREE.CubicInterpolant(
  8646. this.times, this.values, this.getValueSize(), result );
  8647. },
  8648. setInterpolation: function( interpolation ) {
  8649. var factoryMethod = undefined;
  8650. switch ( interpolation ) {
  8651. case THREE.InterpolateDiscrete:
  8652. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  8653. break;
  8654. case THREE.InterpolateLinear:
  8655. factoryMethod = this.InterpolantFactoryMethodLinear;
  8656. break;
  8657. case THREE.InterpolateSmooth:
  8658. factoryMethod = this.InterpolantFactoryMethodSmooth;
  8659. break;
  8660. }
  8661. if ( factoryMethod === undefined ) {
  8662. var message = "unsupported interpolation for " +
  8663. this.ValueTypeName + " keyframe track named " + this.name;
  8664. if ( this.createInterpolant === undefined ) {
  8665. // fall back to default, unless the default itself is messed up
  8666. if ( interpolation !== this.DefaultInterpolation ) {
  8667. this.setInterpolation( this.DefaultInterpolation );
  8668. } else {
  8669. throw new Error( message ); // fatal, in this case
  8670. }
  8671. }
  8672. console.warn( message );
  8673. return;
  8674. }
  8675. this.createInterpolant = factoryMethod;
  8676. },
  8677. getInterpolation: function() {
  8678. switch ( this.createInterpolant ) {
  8679. case this.InterpolantFactoryMethodDiscrete:
  8680. return THREE.InterpolateDiscrete;
  8681. case this.InterpolantFactoryMethodLinear:
  8682. return THREE.InterpolateLinear;
  8683. case this.InterpolantFactoryMethodSmooth:
  8684. return THREE.InterpolateSmooth;
  8685. }
  8686. },
  8687. getValueSize: function() {
  8688. return this.values.length / this.times.length;
  8689. },
  8690. // move all keyframes either forwards or backwards in time
  8691. shift: function( timeOffset ) {
  8692. if( timeOffset !== 0.0 ) {
  8693. var times = this.times;
  8694. for( var i = 0, n = times.length; i !== n; ++ i ) {
  8695. times[ i ] += timeOffset;
  8696. }
  8697. }
  8698. return this;
  8699. },
  8700. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  8701. scale: function( timeScale ) {
  8702. if( timeScale !== 1.0 ) {
  8703. var times = this.times;
  8704. for( var i = 0, n = times.length; i !== n; ++ i ) {
  8705. times[ i ] *= timeScale;
  8706. }
  8707. }
  8708. return this;
  8709. },
  8710. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  8711. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  8712. trim: function( startTime, endTime ) {
  8713. var times = this.times,
  8714. nKeys = times.length,
  8715. from = 0,
  8716. to = nKeys - 1;
  8717. while ( from !== nKeys && times[ from ] < startTime ) ++ from;
  8718. while ( to !== -1 && times[ to ] > endTime ) -- to;
  8719. ++ to; // inclusive -> exclusive bound
  8720. if( from !== 0 || to !== nKeys ) {
  8721. // empty tracks are forbidden, so keep at least one keyframe
  8722. if ( from >= to ) to = Math.max( to , 1 ), from = to - 1;
  8723. var stride = this.getValueSize();
  8724. this.times = THREE.AnimationUtils.arraySlice( times, from, to );
  8725. this.values = THREE.AnimationUtils.
  8726. arraySlice( this.values, from * stride, to * stride );
  8727. }
  8728. return this;
  8729. },
  8730. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  8731. validate: function() {
  8732. var valid = true;
  8733. var valueSize = this.getValueSize();
  8734. if ( valueSize - Math.floor( valueSize ) !== 0 ) {
  8735. console.error( "invalid value size in track", this );
  8736. valid = false;
  8737. }
  8738. var times = this.times,
  8739. values = this.values,
  8740. nKeys = times.length;
  8741. if( nKeys === 0 ) {
  8742. console.error( "track is empty", this );
  8743. valid = false;
  8744. }
  8745. var prevTime = null;
  8746. for( var i = 0; i !== nKeys; i ++ ) {
  8747. var currTime = times[ i ];
  8748. if ( typeof currTime === 'number' && isNaN( currTime ) ) {
  8749. console.error( "time is not a valid number", this, i, currTime );
  8750. valid = false;
  8751. break;
  8752. }
  8753. if( prevTime !== null && prevTime > currTime ) {
  8754. console.error( "out of order keys", this, i, currTime, prevTime );
  8755. valid = false;
  8756. break;
  8757. }
  8758. prevTime = currTime;
  8759. }
  8760. if ( values !== undefined ) {
  8761. if ( THREE.AnimationUtils.isTypedArray( values ) ) {
  8762. for ( var i = 0, n = values.length; i !== n; ++ i ) {
  8763. var value = values[ i ];
  8764. if ( isNaN( value ) ) {
  8765. console.error( "value is not a valid number", this, i, value );
  8766. valid = false;
  8767. break;
  8768. }
  8769. }
  8770. }
  8771. }
  8772. return valid;
  8773. },
  8774. // removes equivalent sequential keys as common in morph target sequences
  8775. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  8776. optimize: function() {
  8777. var times = this.times,
  8778. values = this.values,
  8779. stride = this.getValueSize(),
  8780. writeIndex = 1;
  8781. for( var i = 1, n = times.length - 1; i <= n; ++ i ) {
  8782. var keep = false;
  8783. var time = times[ i ];
  8784. var timeNext = times[ i + 1 ];
  8785. // remove adjacent keyframes scheduled at the same time
  8786. if ( time !== timeNext && ( i !== 1 || time !== time[ 0 ] ) ) {
  8787. // remove unnecessary keyframes same as their neighbors
  8788. var offset = i * stride,
  8789. offsetP = offset - stride,
  8790. offsetN = offset + stride;
  8791. for ( var j = 0; j !== stride; ++ j ) {
  8792. var value = values[ offset + j ];
  8793. if ( value !== values[ offsetP + j ] ||
  8794. value !== values[ offsetN + j ] ) {
  8795. keep = true;
  8796. break;
  8797. }
  8798. }
  8799. }
  8800. // in-place compaction
  8801. if ( keep ) {
  8802. if ( i !== writeIndex ) {
  8803. times[ writeIndex ] = times[ i ];
  8804. var readOffset = i * stride,
  8805. writeOffset = writeIndex * stride;
  8806. for ( var j = 0; j !== stride; ++ j ) {
  8807. values[ writeOffset + j ] = values[ readOffset + j ];
  8808. }
  8809. }
  8810. ++ writeIndex;
  8811. }
  8812. }
  8813. if ( writeIndex !== times.length ) {
  8814. this.times = THREE.AnimationUtils.arraySlice( times, 0, writeIndex );
  8815. this.values = THREE.AnimationUtils.arraySlice( values, 0, writeIndex * stride );
  8816. }
  8817. return this;
  8818. }
  8819. };
  8820. // Static methods:
  8821. Object.assign( THREE.KeyframeTrack, {
  8822. // Serialization (in static context, because of constructor invocation
  8823. // and automatic invocation of .toJSON):
  8824. parse: function( json ) {
  8825. if( json.type === undefined ) {
  8826. throw new Error( "track type undefined, can not parse" );
  8827. }
  8828. var trackType = THREE.KeyframeTrack._getTrackTypeForValueTypeName( json.type );
  8829. if ( json.times === undefined ) {
  8830. console.warn( "legacy JSON format detected, converting" );
  8831. var times = [], values = [];
  8832. THREE.AnimationUtils.flattenJSON( json.keys, times, values, 'value' );
  8833. json.times = times;
  8834. json.values = values;
  8835. }
  8836. // derived classes can define a static parse method
  8837. if ( trackType.parse !== undefined ) {
  8838. return trackType.parse( json );
  8839. } else {
  8840. // by default, we asssume a constructor compatible with the base
  8841. return new trackType(
  8842. json.name, json.times, json.values, json.interpolation );
  8843. }
  8844. },
  8845. toJSON: function( track ) {
  8846. var trackType = track.constructor;
  8847. var json;
  8848. // derived classes can define a static toJSON method
  8849. if ( trackType.toJSON !== undefined ) {
  8850. json = trackType.toJSON( track );
  8851. } else {
  8852. // by default, we assume the data can be serialized as-is
  8853. json = {
  8854. 'name': track.name,
  8855. 'times': THREE.AnimationUtils.convertArray( track.times, Array ),
  8856. 'values': THREE.AnimationUtils.convertArray( track.values, Array )
  8857. };
  8858. var interpolation = track.getInterpolation();
  8859. if ( interpolation !== track.DefaultInterpolation ) {
  8860. json.interpolation = interpolation;
  8861. }
  8862. }
  8863. json.type = track.ValueTypeName; // mandatory
  8864. return json;
  8865. },
  8866. _getTrackTypeForValueTypeName: function( typeName ) {
  8867. switch( typeName.toLowerCase() ) {
  8868. case "scalar":
  8869. case "double":
  8870. case "float":
  8871. case "number":
  8872. case "integer":
  8873. return THREE.NumberKeyframeTrack;
  8874. case "vector":
  8875. case "vector2":
  8876. case "vector3":
  8877. case "vector4":
  8878. return THREE.VectorKeyframeTrack;
  8879. case "color":
  8880. return THREE.ColorKeyframeTrack;
  8881. case "quaternion":
  8882. return THREE.QuaternionKeyframeTrack;
  8883. case "bool":
  8884. case "boolean":
  8885. return THREE.BooleanKeyframeTrack;
  8886. case "string":
  8887. return THREE.StringKeyframeTrack;
  8888. };
  8889. throw new Error( "Unsupported typeName: " + typeName );
  8890. }
  8891. } );
  8892. // File:src/animation/PropertyBinding.js
  8893. /**
  8894. *
  8895. * A reference to a real property in the scene graph.
  8896. *
  8897. *
  8898. * @author Ben Houston / http://clara.io/
  8899. * @author David Sarno / http://lighthaus.us/
  8900. * @author tschw
  8901. */
  8902. THREE.PropertyBinding = function ( rootNode, path, parsedPath ) {
  8903. this.path = path;
  8904. this.parsedPath = parsedPath ||
  8905. THREE.PropertyBinding.parseTrackName( path );
  8906. this.node = THREE.PropertyBinding.findNode(
  8907. rootNode, this.parsedPath.nodeName ) || rootNode;
  8908. this.rootNode = rootNode;
  8909. };
  8910. THREE.PropertyBinding.prototype = {
  8911. constructor: THREE.PropertyBinding,
  8912. getValue: function getValue_unbound( targetArray, offset ) {
  8913. this.bind();
  8914. this.getValue( targetArray, offset );
  8915. // Note: This class uses a State pattern on a per-method basis:
  8916. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  8917. // prototype version of these methods with one that represents
  8918. // the bound state. When the property is not found, the methods
  8919. // become no-ops.
  8920. },
  8921. setValue: function getValue_unbound( sourceArray, offset ) {
  8922. this.bind();
  8923. this.setValue( sourceArray, offset );
  8924. },
  8925. // create getter / setter pair for a property in the scene graph
  8926. bind: function() {
  8927. var targetObject = this.node,
  8928. parsedPath = this.parsedPath,
  8929. objectName = parsedPath.objectName,
  8930. propertyName = parsedPath.propertyName,
  8931. propertyIndex = parsedPath.propertyIndex;
  8932. if ( ! targetObject ) {
  8933. targetObject = THREE.PropertyBinding.findNode(
  8934. this.rootNode, parsedPath.nodeName ) || this.rootNode;
  8935. this.node = targetObject;
  8936. }
  8937. // set fail state so we can just 'return' on error
  8938. this.getValue = this._getValue_unavailable;
  8939. this.setValue = this._setValue_unavailable;
  8940. // ensure there is a value node
  8941. if ( ! targetObject ) {
  8942. console.error( " trying to update node for track: " + this.path + " but it wasn't found." );
  8943. return;
  8944. }
  8945. if( objectName ) {
  8946. var objectIndex = parsedPath.objectIndex;
  8947. // special cases were we need to reach deeper into the hierarchy to get the face materials....
  8948. switch ( objectName ) {
  8949. case 'materials':
  8950. if( ! targetObject.material ) {
  8951. console.error( ' can not bind to material as node does not have a material', this );
  8952. return;
  8953. }
  8954. if( ! targetObject.material.materials ) {
  8955. console.error( ' can not bind to material.materials as node.material does not have a materials array', this );
  8956. return;
  8957. }
  8958. targetObject = targetObject.material.materials;
  8959. break;
  8960. case 'bones':
  8961. if( ! targetObject.skeleton ) {
  8962. console.error( ' can not bind to bones as node does not have a skeleton', this );
  8963. return;
  8964. }
  8965. // potential future optimization: skip this if propertyIndex is already an integer
  8966. // and convert the integer string to a true integer.
  8967. targetObject = targetObject.skeleton.bones;
  8968. // support resolving morphTarget names into indices.
  8969. for ( var i = 0; i < targetObject.length; i ++ ) {
  8970. if ( targetObject[i].name === objectIndex ) {
  8971. objectIndex = i;
  8972. break;
  8973. }
  8974. }
  8975. break;
  8976. default:
  8977. if ( targetObject[ objectName ] === undefined ) {
  8978. console.error( ' can not bind to objectName of node, undefined', this );
  8979. return;
  8980. }
  8981. targetObject = targetObject[ objectName ];
  8982. }
  8983. if ( objectIndex !== undefined ) {
  8984. if( targetObject[ objectIndex ] === undefined ) {
  8985. console.error( " trying to bind to objectIndex of objectName, but is undefined:", this, targetObject );
  8986. return;
  8987. }
  8988. targetObject = targetObject[ objectIndex ];
  8989. }
  8990. }
  8991. // resolve property
  8992. var nodeProperty = targetObject[ propertyName ];
  8993. if ( ! nodeProperty ) {
  8994. var nodeName = parsedPath.nodeName;
  8995. console.error( " trying to update property for track: " + nodeName +
  8996. '.' + propertyName + " but it wasn't found.", targetObject );
  8997. return;
  8998. }
  8999. // determine versioning scheme
  9000. var versioning = this.Versioning.None;
  9001. if ( targetObject.needsUpdate !== undefined ) { // material
  9002. versioning = this.Versioning.NeedsUpdate;
  9003. this.targetObject = targetObject;
  9004. } else if ( targetObject.matrixWorldNeedsUpdate !== undefined ) { // node transform
  9005. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  9006. this.targetObject = targetObject;
  9007. }
  9008. // determine how the property gets bound
  9009. var bindingType = this.BindingType.Direct;
  9010. if ( propertyIndex !== undefined ) {
  9011. // access a sub element of the property array (only primitives are supported right now)
  9012. if ( propertyName === "morphTargetInfluences" ) {
  9013. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  9014. // support resolving morphTarget names into indices.
  9015. if ( ! targetObject.geometry ) {
  9016. console.error( ' can not bind to morphTargetInfluences becasuse node does not have a geometry', this );
  9017. return;
  9018. }
  9019. if ( ! targetObject.geometry.morphTargets ) {
  9020. console.error( ' can not bind to morphTargetInfluences becasuse node does not have a geometry.morphTargets', this );
  9021. return;
  9022. }
  9023. for ( var i = 0; i < this.node.geometry.morphTargets.length; i ++ ) {
  9024. if ( targetObject.geometry.morphTargets[i].name === propertyIndex ) {
  9025. propertyIndex = i;
  9026. break;
  9027. }
  9028. }
  9029. }
  9030. bindingType = this.BindingType.ArrayElement;
  9031. this.resolvedProperty = nodeProperty;
  9032. this.propertyIndex = propertyIndex;
  9033. } else if ( nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined ) {
  9034. // must use copy for Object3D.Euler/Quaternion
  9035. bindingType = this.BindingType.HasFromToArray;
  9036. this.resolvedProperty = nodeProperty;
  9037. } else if ( nodeProperty.length !== undefined ) {
  9038. bindingType = this.BindingType.EntireArray;
  9039. this.resolvedProperty = nodeProperty;
  9040. } else {
  9041. this.propertyName = propertyName;
  9042. }
  9043. // select getter / setter
  9044. this.getValue = this.GetterByBindingType[ bindingType ];
  9045. this.setValue = this.SetterByBindingTypeAndVersioning[ bindingType ][ versioning ];
  9046. },
  9047. unbind: function() {
  9048. this.node = null;
  9049. // back to the prototype version of getValue / setValue
  9050. // note: avoiding to mutate the shape of 'this' via 'delete'
  9051. this.getValue = this._getValue_unbound;
  9052. this.setValue = this._setValue_unbound;
  9053. }
  9054. };
  9055. Object.assign( THREE.PropertyBinding.prototype, { // prototype, continued
  9056. // these are used to "bind" a nonexistent property
  9057. _getValue_unavailable: function() {},
  9058. _setValue_unavailable: function() {},
  9059. // initial state of these methods that calls 'bind'
  9060. _getValue_unbound: THREE.PropertyBinding.prototype.getValue,
  9061. _setValue_unbound: THREE.PropertyBinding.prototype.setValue,
  9062. BindingType: {
  9063. Direct: 0,
  9064. EntireArray: 1,
  9065. ArrayElement: 2,
  9066. HasFromToArray: 3
  9067. },
  9068. Versioning: {
  9069. None: 0,
  9070. NeedsUpdate: 1,
  9071. MatrixWorldNeedsUpdate: 2
  9072. },
  9073. GetterByBindingType: [
  9074. function getValue_direct( buffer, offset ) {
  9075. buffer[ offset ] = this.node[ this.propertyName ];
  9076. },
  9077. function getValue_array( buffer, offset ) {
  9078. var source = this.resolvedProperty;
  9079. for ( var i = 0, n = source.length; i !== n; ++ i ) {
  9080. buffer[ offset ++ ] = source[ i ];
  9081. }
  9082. },
  9083. function getValue_arrayElement( buffer, offset ) {
  9084. buffer[ offset ] = this.resolvedProperty[ this.propertyIndex ];
  9085. },
  9086. function getValue_toArray( buffer, offset ) {
  9087. this.resolvedProperty.toArray( buffer, offset );
  9088. }
  9089. ],
  9090. SetterByBindingTypeAndVersioning: [
  9091. [
  9092. // Direct
  9093. function setValue_direct( buffer, offset ) {
  9094. this.node[ this.propertyName ] = buffer[ offset ];
  9095. },
  9096. function setValue_direct_setNeedsUpdate( buffer, offset ) {
  9097. this.node[ this.propertyName ] = buffer[ offset ];
  9098. this.targetObject.needsUpdate = true;
  9099. },
  9100. function setValue_direct_setMatrixWorldNeedsUpdate( buffer, offset ) {
  9101. this.node[ this.propertyName ] = buffer[ offset ];
  9102. this.targetObject.matrixWorldNeedsUpdate = true;
  9103. }
  9104. ], [
  9105. // EntireArray
  9106. function setValue_array( buffer, offset ) {
  9107. var dest = this.resolvedProperty;
  9108. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  9109. dest[ i ] = buffer[ offset ++ ];
  9110. }
  9111. },
  9112. function setValue_array_setNeedsUpdate( buffer, offset ) {
  9113. var dest = this.resolvedProperty;
  9114. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  9115. dest[ i ] = buffer[ offset ++ ];
  9116. }
  9117. this.targetObject.needsUpdate = true;
  9118. },
  9119. function setValue_array_setMatrixWorldNeedsUpdate( buffer, offset ) {
  9120. var dest = this.resolvedProperty;
  9121. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  9122. dest[ i ] = buffer[ offset ++ ];
  9123. }
  9124. this.targetObject.matrixWorldNeedsUpdate = true;
  9125. }
  9126. ], [
  9127. // ArrayElement
  9128. function setValue_arrayElement( buffer, offset ) {
  9129. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  9130. },
  9131. function setValue_arrayElement_setNeedsUpdate( buffer, offset ) {
  9132. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  9133. this.targetObject.needsUpdate = true;
  9134. },
  9135. function setValue_arrayElement_setMatrixWorldNeedsUpdate( buffer, offset ) {
  9136. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  9137. this.targetObject.matrixWorldNeedsUpdate = true;
  9138. }
  9139. ], [
  9140. // HasToFromArray
  9141. function setValue_fromArray( buffer, offset ) {
  9142. this.resolvedProperty.fromArray( buffer, offset );
  9143. },
  9144. function setValue_fromArray_setNeedsUpdate( buffer, offset ) {
  9145. this.resolvedProperty.fromArray( buffer, offset );
  9146. this.targetObject.needsUpdate = true;
  9147. },
  9148. function setValue_fromArray_setMatrixWorldNeedsUpdate( buffer, offset ) {
  9149. this.resolvedProperty.fromArray( buffer, offset );
  9150. this.targetObject.matrixWorldNeedsUpdate = true;
  9151. }
  9152. ]
  9153. ]
  9154. } );
  9155. THREE.PropertyBinding.Composite =
  9156. function( targetGroup, path, optionalParsedPath ) {
  9157. var parsedPath = optionalParsedPath ||
  9158. THREE.PropertyBinding.parseTrackName( path );
  9159. this._targetGroup = targetGroup;
  9160. this._bindings = targetGroup.subscribe_( path, parsedPath );
  9161. };
  9162. THREE.PropertyBinding.Composite.prototype = {
  9163. constructor: THREE.PropertyBinding.Composite,
  9164. getValue: function( array, offset ) {
  9165. this.bind(); // bind all binding
  9166. var firstValidIndex = this._targetGroup.nCachedObjects_,
  9167. binding = this._bindings[ firstValidIndex ];
  9168. // and only call .getValue on the first
  9169. if ( binding !== undefined ) binding.getValue( array, offset );
  9170. },
  9171. setValue: function( array, offset ) {
  9172. var bindings = this._bindings;
  9173. for ( var i = this._targetGroup.nCachedObjects_,
  9174. n = bindings.length; i !== n; ++ i ) {
  9175. bindings[ i ].setValue( array, offset );
  9176. }
  9177. },
  9178. bind: function() {
  9179. var bindings = this._bindings;
  9180. for ( var i = this._targetGroup.nCachedObjects_,
  9181. n = bindings.length; i !== n; ++ i ) {
  9182. bindings[ i ].bind();
  9183. }
  9184. },
  9185. unbind: function() {
  9186. var bindings = this._bindings;
  9187. for ( var i = this._targetGroup.nCachedObjects_,
  9188. n = bindings.length; i !== n; ++ i ) {
  9189. bindings[ i ].unbind();
  9190. }
  9191. }
  9192. };
  9193. THREE.PropertyBinding.create = function( root, path, parsedPath ) {
  9194. if ( ! ( root instanceof THREE.AnimationObjectGroup ) ) {
  9195. return new THREE.PropertyBinding( root, path, parsedPath );
  9196. } else {
  9197. return new THREE.PropertyBinding.Composite( root, path, parsedPath );
  9198. }
  9199. };
  9200. THREE.PropertyBinding.parseTrackName = function( trackName ) {
  9201. // matches strings in the form of:
  9202. // nodeName.property
  9203. // nodeName.property[accessor]
  9204. // nodeName.material.property[accessor]
  9205. // uuid.property[accessor]
  9206. // uuid.objectName[objectIndex].propertyName[propertyIndex]
  9207. // parentName/nodeName.property
  9208. // parentName/parentName/nodeName.property[index]
  9209. // .bone[Armature.DEF_cog].position
  9210. // created and tested via https://regex101.com/#javascript
  9211. var re = /^(([\w]+\/)*)([\w-\d]+)?(\.([\w]+)(\[([\w\d\[\]\_.:\- ]+)\])?)?(\.([\w.]+)(\[([\w\d\[\]\_. ]+)\])?)$/;
  9212. var matches = re.exec(trackName);
  9213. if( ! matches ) {
  9214. throw new Error( "cannot parse trackName at all: " + trackName );
  9215. }
  9216. if (matches.index === re.lastIndex) {
  9217. re.lastIndex++;
  9218. }
  9219. var results = {
  9220. // directoryName: matches[1], // (tschw) currently unused
  9221. nodeName: matches[3], // allowed to be null, specified root node.
  9222. objectName: matches[5],
  9223. objectIndex: matches[7],
  9224. propertyName: matches[9],
  9225. propertyIndex: matches[11] // allowed to be null, specifies that the whole property is set.
  9226. };
  9227. if( results.propertyName === null || results.propertyName.length === 0 ) {
  9228. throw new Error( "can not parse propertyName from trackName: " + trackName );
  9229. }
  9230. return results;
  9231. };
  9232. THREE.PropertyBinding.findNode = function( root, nodeName ) {
  9233. if( ! nodeName || nodeName === "" || nodeName === "root" || nodeName === "." || nodeName === -1 || nodeName === root.name || nodeName === root.uuid ) {
  9234. return root;
  9235. }
  9236. // search into skeleton bones.
  9237. if( root.skeleton ) {
  9238. var searchSkeleton = function( skeleton ) {
  9239. for( var i = 0; i < skeleton.bones.length; i ++ ) {
  9240. var bone = skeleton.bones[i];
  9241. if( bone.name === nodeName ) {
  9242. return bone;
  9243. }
  9244. }
  9245. return null;
  9246. };
  9247. var bone = searchSkeleton( root.skeleton );
  9248. if( bone ) {
  9249. return bone;
  9250. }
  9251. }
  9252. // search into node subtree.
  9253. if( root.children ) {
  9254. var searchNodeSubtree = function( children ) {
  9255. for( var i = 0; i < children.length; i ++ ) {
  9256. var childNode = children[i];
  9257. if( childNode.name === nodeName || childNode.uuid === nodeName ) {
  9258. return childNode;
  9259. }
  9260. var result = searchNodeSubtree( childNode.children );
  9261. if( result ) return result;
  9262. }
  9263. return null;
  9264. };
  9265. var subTreeNode = searchNodeSubtree( root.children );
  9266. if( subTreeNode ) {
  9267. return subTreeNode;
  9268. }
  9269. }
  9270. return null;
  9271. }
  9272. // File:src/animation/PropertyMixer.js
  9273. /**
  9274. *
  9275. * Buffered scene graph property that allows weighted accumulation.
  9276. *
  9277. *
  9278. * @author Ben Houston / http://clara.io/
  9279. * @author David Sarno / http://lighthaus.us/
  9280. * @author tschw
  9281. */
  9282. THREE.PropertyMixer = function ( binding, typeName, valueSize ) {
  9283. this.binding = binding;
  9284. this.valueSize = valueSize;
  9285. var bufferType = Float64Array,
  9286. mixFunction;
  9287. switch ( typeName ) {
  9288. case 'quaternion': mixFunction = this._slerp; break;
  9289. case 'string':
  9290. case 'bool':
  9291. bufferType = Array, mixFunction = this._select; break;
  9292. default: mixFunction = this._lerp;
  9293. }
  9294. this.buffer = new bufferType( valueSize * 4 );
  9295. // layout: [ incoming | accu0 | accu1 | orig ]
  9296. //
  9297. // interpolators can use .buffer as their .result
  9298. // the data then goes to 'incoming'
  9299. //
  9300. // 'accu0' and 'accu1' are used frame-interleaved for
  9301. // the cumulative result and are compared to detect
  9302. // changes
  9303. //
  9304. // 'orig' stores the original state of the property
  9305. this._mixBufferRegion = mixFunction;
  9306. this.cumulativeWeight = 0;
  9307. this.useCount = 0;
  9308. this.referenceCount = 0;
  9309. };
  9310. THREE.PropertyMixer.prototype = {
  9311. constructor: THREE.PropertyMixer,
  9312. // accumulate data in the 'incoming' region into 'accu<i>'
  9313. accumulate: function( accuIndex, weight ) {
  9314. // note: happily accumulating nothing when weight = 0, the caller knows
  9315. // the weight and shouldn't have made the call in the first place
  9316. var buffer = this.buffer,
  9317. stride = this.valueSize,
  9318. offset = accuIndex * stride + stride,
  9319. currentWeight = this.cumulativeWeight;
  9320. if ( currentWeight === 0 ) {
  9321. // accuN := incoming * weight
  9322. for ( var i = 0; i !== stride; ++ i ) {
  9323. buffer[ offset + i ] = buffer[ i ];
  9324. }
  9325. currentWeight = weight;
  9326. } else {
  9327. // accuN := accuN + incoming * weight
  9328. currentWeight += weight;
  9329. var mix = weight / currentWeight;
  9330. this._mixBufferRegion( buffer, offset, 0, mix, stride );
  9331. }
  9332. this.cumulativeWeight = currentWeight;
  9333. },
  9334. // apply the state of 'accu<i>' to the binding when accus differ
  9335. apply: function( accuIndex ) {
  9336. var stride = this.valueSize,
  9337. buffer = this.buffer,
  9338. offset = accuIndex * stride + stride,
  9339. weight = this.cumulativeWeight,
  9340. binding = this.binding;
  9341. this.cumulativeWeight = 0;
  9342. if ( weight < 1 ) {
  9343. // accuN := accuN + original * ( 1 - cumulativeWeight )
  9344. var originalValueOffset = stride * 3;
  9345. this._mixBufferRegion(
  9346. buffer, offset, originalValueOffset, 1 - weight, stride );
  9347. }
  9348. for ( var i = stride, e = stride + stride; i !== e; ++ i ) {
  9349. if ( buffer[ i ] !== buffer[ i + stride ] ) {
  9350. // value has changed -> update scene graph
  9351. binding.setValue( buffer, offset );
  9352. break;
  9353. }
  9354. }
  9355. },
  9356. // remember the state of the bound property and copy it to both accus
  9357. saveOriginalState: function() {
  9358. var binding = this.binding;
  9359. var buffer = this.buffer,
  9360. stride = this.valueSize,
  9361. originalValueOffset = stride * 3;
  9362. binding.getValue( buffer, originalValueOffset );
  9363. // accu[0..1] := orig -- initially detect changes against the original
  9364. for ( var i = stride, e = originalValueOffset; i !== e; ++ i ) {
  9365. buffer[ i ] = buffer[ originalValueOffset + ( i % stride ) ];
  9366. }
  9367. this.cumulativeWeight = 0;
  9368. },
  9369. // apply the state previously taken via 'saveOriginalState' to the binding
  9370. restoreOriginalState: function() {
  9371. var originalValueOffset = this.valueSize * 3;
  9372. this.binding.setValue( this.buffer, originalValueOffset );
  9373. },
  9374. // mix functions
  9375. _select: function( buffer, dstOffset, srcOffset, t, stride ) {
  9376. if ( t >= 0.5 ) {
  9377. for ( var i = 0; i !== stride; ++ i ) {
  9378. buffer[ dstOffset + i ] = buffer[ srcOffset + i ];
  9379. }
  9380. }
  9381. },
  9382. _slerp: function( buffer, dstOffset, srcOffset, t, stride ) {
  9383. THREE.Quaternion.slerpFlat( buffer, dstOffset,
  9384. buffer, dstOffset, buffer, srcOffset, t );
  9385. },
  9386. _lerp: function( buffer, dstOffset, srcOffset, t, stride ) {
  9387. var s = 1 - t;
  9388. for ( var i = 0; i !== stride; ++ i ) {
  9389. var j = dstOffset + i;
  9390. buffer[ j ] = buffer[ j ] * s + buffer[ srcOffset + i ] * t;
  9391. }
  9392. }
  9393. };
  9394. // File:src/animation/tracks/BooleanKeyframeTrack.js
  9395. /**
  9396. *
  9397. * A Track of Boolean keyframe values.
  9398. *
  9399. *
  9400. * @author Ben Houston / http://clara.io/
  9401. * @author David Sarno / http://lighthaus.us/
  9402. * @author tschw
  9403. */
  9404. THREE.BooleanKeyframeTrack = function ( name, times, values ) {
  9405. THREE.KeyframeTrack.call( this, name, times, values );
  9406. };
  9407. THREE.BooleanKeyframeTrack.prototype =
  9408. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9409. constructor: THREE.BooleanKeyframeTrack,
  9410. ValueTypeName: 'bool',
  9411. ValueBufferType: Array,
  9412. DefaultInterpolation: THREE.IntepolateDiscrete,
  9413. InterpolantFactoryMethodLinear: undefined,
  9414. InterpolantFactoryMethodSmooth: undefined
  9415. // Note: Actually this track could have a optimized / compressed
  9416. // representation of a single value and a custom interpolant that
  9417. // computes "firstValue ^ isOdd( index )".
  9418. } );
  9419. // File:src/animation/tracks/ColorKeyframeTrack.js
  9420. /**
  9421. *
  9422. * A Track of keyframe values that represent color.
  9423. *
  9424. *
  9425. * @author Ben Houston / http://clara.io/
  9426. * @author David Sarno / http://lighthaus.us/
  9427. * @author tschw
  9428. */
  9429. THREE.ColorKeyframeTrack = function ( name, times, values, interpolation ) {
  9430. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9431. };
  9432. THREE.ColorKeyframeTrack.prototype =
  9433. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9434. constructor: THREE.ColorKeyframeTrack,
  9435. ValueTypeName: 'color'
  9436. // ValueBufferType is inherited
  9437. // DefaultInterpolation is inherited
  9438. // Note: Very basic implementation and nothing special yet.
  9439. // However, this is the place for color space parameterization.
  9440. } );
  9441. // File:src/animation/tracks/NumberKeyframeTrack.js
  9442. /**
  9443. *
  9444. * A Track of numeric keyframe values.
  9445. *
  9446. * @author Ben Houston / http://clara.io/
  9447. * @author David Sarno / http://lighthaus.us/
  9448. * @author tschw
  9449. */
  9450. THREE.NumberKeyframeTrack = function ( name, times, values, interpolation ) {
  9451. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9452. };
  9453. THREE.NumberKeyframeTrack.prototype =
  9454. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9455. constructor: THREE.NumberKeyframeTrack,
  9456. ValueTypeName: 'number',
  9457. // ValueBufferType is inherited
  9458. // DefaultInterpolation is inherited
  9459. } );
  9460. // File:src/animation/tracks/QuaternionKeyframeTrack.js
  9461. /**
  9462. *
  9463. * A Track of quaternion keyframe values.
  9464. *
  9465. * @author Ben Houston / http://clara.io/
  9466. * @author David Sarno / http://lighthaus.us/
  9467. * @author tschw
  9468. */
  9469. THREE.QuaternionKeyframeTrack = function ( name, times, values, interpolation ) {
  9470. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9471. };
  9472. THREE.QuaternionKeyframeTrack.prototype =
  9473. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9474. constructor: THREE.QuaternionKeyframeTrack,
  9475. ValueTypeName: 'quaternion',
  9476. // ValueBufferType is inherited
  9477. DefaultInterpolation: THREE.InterpolateLinear,
  9478. InterpolantFactoryMethodLinear: function( result ) {
  9479. return new THREE.QuaternionLinearInterpolant(
  9480. this.times, this.values, this.getValueSize(), result );
  9481. },
  9482. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  9483. } );
  9484. // File:src/animation/tracks/StringKeyframeTrack.js
  9485. /**
  9486. *
  9487. * A Track that interpolates Strings
  9488. *
  9489. *
  9490. * @author Ben Houston / http://clara.io/
  9491. * @author David Sarno / http://lighthaus.us/
  9492. * @author tschw
  9493. */
  9494. THREE.StringKeyframeTrack = function ( name, times, values, interpolation ) {
  9495. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9496. };
  9497. THREE.StringKeyframeTrack.prototype =
  9498. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9499. constructor: THREE.StringKeyframeTrack,
  9500. ValueTypeName: 'string',
  9501. ValueBufferType: Array,
  9502. DefaultInterpolation: THREE.IntepolateDiscrete,
  9503. InterpolantFactoryMethodLinear: undefined,
  9504. InterpolantFactoryMethodSmooth: undefined
  9505. } );
  9506. // File:src/animation/tracks/VectorKeyframeTrack.js
  9507. /**
  9508. *
  9509. * A Track of vectored keyframe values.
  9510. *
  9511. *
  9512. * @author Ben Houston / http://clara.io/
  9513. * @author David Sarno / http://lighthaus.us/
  9514. * @author tschw
  9515. */
  9516. THREE.VectorKeyframeTrack = function ( name, times, values, interpolation ) {
  9517. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9518. };
  9519. THREE.VectorKeyframeTrack.prototype =
  9520. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9521. constructor: THREE.VectorKeyframeTrack,
  9522. ValueTypeName: 'vector'
  9523. // ValueBufferType is inherited
  9524. // DefaultInterpolation is inherited
  9525. } );
  9526. // File:src/audio/Audio.js
  9527. /**
  9528. * @author mrdoob / http://mrdoob.com/
  9529. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  9530. */
  9531. THREE.Audio = function ( listener ) {
  9532. THREE.Object3D.call( this );
  9533. this.type = 'Audio';
  9534. this.context = listener.context;
  9535. this.source = this.context.createBufferSource();
  9536. this.source.onended = this.onEnded.bind( this );
  9537. this.gain = this.context.createGain();
  9538. this.gain.connect( listener.getInput() );
  9539. this.autoplay = false;
  9540. this.startTime = 0;
  9541. this.playbackRate = 1;
  9542. this.isPlaying = false;
  9543. this.hasPlaybackControl = true;
  9544. this.sourceType = 'empty';
  9545. this.filter = null;
  9546. };
  9547. THREE.Audio.prototype = Object.create( THREE.Object3D.prototype );
  9548. THREE.Audio.prototype.constructor = THREE.Audio;
  9549. THREE.Audio.prototype.getOutput = function () {
  9550. return this.gain;
  9551. };
  9552. THREE.Audio.prototype.load = function ( file ) {
  9553. console.warn( 'THREE.Audio: .load has been deprecated. Please use THREE.AudioLoader.' );
  9554. var scope = this;
  9555. var audioLoader = new THREE.AudioLoader();
  9556. audioLoader.load( file, function ( buffer ) {
  9557. scope.setBuffer( buffer );
  9558. } );
  9559. return this;
  9560. };
  9561. THREE.Audio.prototype.setNodeSource = function ( audioNode ) {
  9562. this.hasPlaybackControl = false;
  9563. this.sourceType = 'audioNode';
  9564. this.source = audioNode;
  9565. this.connect();
  9566. return this;
  9567. };
  9568. THREE.Audio.prototype.setBuffer = function ( audioBuffer ) {
  9569. var scope = this;
  9570. scope.source.buffer = audioBuffer;
  9571. scope.sourceType = 'buffer';
  9572. if ( scope.autoplay ) scope.play();
  9573. return this;
  9574. };
  9575. THREE.Audio.prototype.play = function () {
  9576. if ( this.isPlaying === true ) {
  9577. console.warn( 'THREE.Audio: Audio is already playing.' );
  9578. return;
  9579. }
  9580. if ( this.hasPlaybackControl === false ) {
  9581. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9582. return;
  9583. }
  9584. var source = this.context.createBufferSource();
  9585. source.buffer = this.source.buffer;
  9586. source.loop = this.source.loop;
  9587. source.onended = this.source.onended;
  9588. source.start( 0, this.startTime );
  9589. source.playbackRate.value = this.playbackRate;
  9590. this.isPlaying = true;
  9591. this.source = source;
  9592. this.connect();
  9593. };
  9594. THREE.Audio.prototype.pause = function () {
  9595. if ( this.hasPlaybackControl === false ) {
  9596. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9597. return;
  9598. }
  9599. this.source.stop();
  9600. this.startTime = this.context.currentTime;
  9601. };
  9602. THREE.Audio.prototype.stop = function () {
  9603. if ( this.hasPlaybackControl === false ) {
  9604. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9605. return;
  9606. }
  9607. this.source.stop();
  9608. this.startTime = 0;
  9609. };
  9610. THREE.Audio.prototype.connect = function () {
  9611. if ( this.filter !== null ) {
  9612. this.source.connect( this.filter );
  9613. this.filter.connect( this.getOutput() );
  9614. } else {
  9615. this.source.connect( this.getOutput() );
  9616. }
  9617. };
  9618. THREE.Audio.prototype.disconnect = function () {
  9619. if ( this.filter !== null ) {
  9620. this.source.disconnect( this.filter );
  9621. this.filter.disconnect( this.getOutput() );
  9622. } else {
  9623. this.source.disconnect( this.getOutput() );
  9624. }
  9625. };
  9626. THREE.Audio.prototype.getFilter = function () {
  9627. return this.filter;
  9628. };
  9629. THREE.Audio.prototype.setFilter = function ( value ) {
  9630. if ( value === undefined ) value = null;
  9631. if ( this.isPlaying === true ) {
  9632. this.disconnect();
  9633. this.filter = value;
  9634. this.connect();
  9635. } else {
  9636. this.filter = value;
  9637. }
  9638. };
  9639. THREE.Audio.prototype.setPlaybackRate = function ( value ) {
  9640. if ( this.hasPlaybackControl === false ) {
  9641. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9642. return;
  9643. }
  9644. this.playbackRate = value;
  9645. if ( this.isPlaying === true ) {
  9646. this.source.playbackRate.value = this.playbackRate;
  9647. }
  9648. };
  9649. THREE.Audio.prototype.getPlaybackRate = function () {
  9650. return this.playbackRate;
  9651. };
  9652. THREE.Audio.prototype.onEnded = function () {
  9653. this.isPlaying = false;
  9654. };
  9655. THREE.Audio.prototype.setLoop = function ( value ) {
  9656. if ( this.hasPlaybackControl === false ) {
  9657. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9658. return;
  9659. }
  9660. this.source.loop = value;
  9661. };
  9662. THREE.Audio.prototype.getLoop = function () {
  9663. if ( this.hasPlaybackControl === false ) {
  9664. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9665. return false;
  9666. }
  9667. return this.source.loop;
  9668. };
  9669. THREE.Audio.prototype.setVolume = function ( value ) {
  9670. this.gain.gain.value = value;
  9671. };
  9672. THREE.Audio.prototype.getVolume = function () {
  9673. return this.gain.gain.value;
  9674. };
  9675. // File:src/audio/AudioAnalyser.js
  9676. /**
  9677. * @author mrdoob / http://mrdoob.com/
  9678. */
  9679. THREE.AudioAnalyser = function ( audio, fftSize ) {
  9680. this.analyser = audio.context.createAnalyser();
  9681. this.analyser.fftSize = fftSize !== undefined ? fftSize : 2048;
  9682. this.data = new Uint8Array( this.analyser.frequencyBinCount );
  9683. audio.getOutput().connect( this.analyser );
  9684. };
  9685. THREE.AudioAnalyser.prototype = {
  9686. constructor: THREE.AudioAnalyser,
  9687. getData: function () {
  9688. this.analyser.getByteFrequencyData( this.data );
  9689. return this.data;
  9690. }
  9691. };
  9692. // File:src/audio/AudioContext.js
  9693. /**
  9694. * @author mrdoob / http://mrdoob.com/
  9695. */
  9696. Object.defineProperty( THREE, 'AudioContext', {
  9697. get: ( function () {
  9698. var context;
  9699. return function () {
  9700. if ( context === undefined ) {
  9701. context = new ( window.AudioContext || window.webkitAudioContext )();
  9702. }
  9703. return context;
  9704. };
  9705. } )()
  9706. } );
  9707. // File:src/audio/PositionalAudio.js
  9708. /**
  9709. * @author mrdoob / http://mrdoob.com/
  9710. */
  9711. THREE.PositionalAudio = function ( listener ) {
  9712. THREE.Audio.call( this, listener );
  9713. this.panner = this.context.createPanner();
  9714. this.panner.connect( this.gain );
  9715. };
  9716. THREE.PositionalAudio.prototype = Object.create( THREE.Audio.prototype );
  9717. THREE.PositionalAudio.prototype.constructor = THREE.PositionalAudio;
  9718. THREE.PositionalAudio.prototype.getOutput = function () {
  9719. return this.panner;
  9720. };
  9721. THREE.PositionalAudio.prototype.setRefDistance = function ( value ) {
  9722. this.panner.refDistance = value;
  9723. };
  9724. THREE.PositionalAudio.prototype.getRefDistance = function () {
  9725. return this.panner.refDistance;
  9726. };
  9727. THREE.PositionalAudio.prototype.setRolloffFactor = function ( value ) {
  9728. this.panner.rolloffFactor = value;
  9729. };
  9730. THREE.PositionalAudio.prototype.getRolloffFactor = function () {
  9731. return this.panner.rolloffFactor;
  9732. };
  9733. THREE.PositionalAudio.prototype.setDistanceModel = function ( value ) {
  9734. this.panner.distanceModel = value;
  9735. };
  9736. THREE.PositionalAudio.prototype.getDistanceModel = function () {
  9737. return this.panner.distanceModel;
  9738. };
  9739. THREE.PositionalAudio.prototype.setMaxDistance = function ( value ) {
  9740. this.panner.maxDistance = value;
  9741. };
  9742. THREE.PositionalAudio.prototype.getMaxDistance = function () {
  9743. return this.panner.maxDistance;
  9744. };
  9745. THREE.PositionalAudio.prototype.updateMatrixWorld = ( function () {
  9746. var position = new THREE.Vector3();
  9747. return function updateMatrixWorld( force ) {
  9748. THREE.Object3D.prototype.updateMatrixWorld.call( this, force );
  9749. position.setFromMatrixPosition( this.matrixWorld );
  9750. this.panner.setPosition( position.x, position.y, position.z );
  9751. };
  9752. } )();
  9753. // File:src/audio/AudioListener.js
  9754. /**
  9755. * @author mrdoob / http://mrdoob.com/
  9756. */
  9757. THREE.AudioListener = function () {
  9758. THREE.Object3D.call( this );
  9759. this.type = 'AudioListener';
  9760. this.context = THREE.AudioContext;
  9761. this.gain = this.context.createGain();
  9762. this.gain.connect( this.context.destination );
  9763. this.filter = null;
  9764. };
  9765. THREE.AudioListener.prototype = Object.create( THREE.Object3D.prototype );
  9766. THREE.AudioListener.prototype.constructor = THREE.AudioListener;
  9767. THREE.AudioListener.prototype.getInput = function () {
  9768. return this.gain;
  9769. };
  9770. THREE.AudioListener.prototype.removeFilter = function ( ) {
  9771. if ( this.filter !== null ) {
  9772. this.gain.disconnect( this.filter );
  9773. this.filter.disconnect( this.context.destination );
  9774. this.gain.connect( this.context.destination );
  9775. this.filter = null;
  9776. }
  9777. };
  9778. THREE.AudioListener.prototype.setFilter = function ( value ) {
  9779. if ( this.filter !== null ) {
  9780. this.gain.disconnect( this.filter );
  9781. this.filter.disconnect( this.context.destination );
  9782. } else {
  9783. this.gain.disconnect( this.context.destination );
  9784. }
  9785. this.filter = value;
  9786. this.gain.connect( this.filter );
  9787. this.filter.connect( this.context.destination );
  9788. };
  9789. THREE.AudioListener.prototype.getFilter = function () {
  9790. return this.filter;
  9791. };
  9792. THREE.AudioListener.prototype.setMasterVolume = function ( value ) {
  9793. this.gain.gain.value = value;
  9794. };
  9795. THREE.AudioListener.prototype.getMasterVolume = function () {
  9796. return this.gain.gain.value;
  9797. };
  9798. THREE.AudioListener.prototype.updateMatrixWorld = ( function () {
  9799. var position = new THREE.Vector3();
  9800. var quaternion = new THREE.Quaternion();
  9801. var scale = new THREE.Vector3();
  9802. var orientation = new THREE.Vector3();
  9803. return function updateMatrixWorld( force ) {
  9804. THREE.Object3D.prototype.updateMatrixWorld.call( this, force );
  9805. var listener = this.context.listener;
  9806. var up = this.up;
  9807. this.matrixWorld.decompose( position, quaternion, scale );
  9808. orientation.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  9809. listener.setPosition( position.x, position.y, position.z );
  9810. listener.setOrientation( orientation.x, orientation.y, orientation.z, up.x, up.y, up.z );
  9811. };
  9812. } )();
  9813. // File:src/cameras/Camera.js
  9814. /**
  9815. * @author mrdoob / http://mrdoob.com/
  9816. * @author mikael emtinger / http://gomo.se/
  9817. * @author WestLangley / http://github.com/WestLangley
  9818. */
  9819. THREE.Camera = function () {
  9820. THREE.Object3D.call( this );
  9821. this.type = 'Camera';
  9822. this.matrixWorldInverse = new THREE.Matrix4();
  9823. this.projectionMatrix = new THREE.Matrix4();
  9824. };
  9825. THREE.Camera.prototype = Object.create( THREE.Object3D.prototype );
  9826. THREE.Camera.prototype.constructor = THREE.Camera;
  9827. THREE.Camera.prototype.getWorldDirection = function () {
  9828. var quaternion = new THREE.Quaternion();
  9829. return function ( optionalTarget ) {
  9830. var result = optionalTarget || new THREE.Vector3();
  9831. this.getWorldQuaternion( quaternion );
  9832. return result.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  9833. };
  9834. }();
  9835. THREE.Camera.prototype.lookAt = function () {
  9836. // This routine does not support cameras with rotated and/or translated parent(s)
  9837. var m1 = new THREE.Matrix4();
  9838. return function ( vector ) {
  9839. m1.lookAt( this.position, vector, this.up );
  9840. this.quaternion.setFromRotationMatrix( m1 );
  9841. };
  9842. }();
  9843. THREE.Camera.prototype.clone = function () {
  9844. return new this.constructor().copy( this );
  9845. };
  9846. THREE.Camera.prototype.copy = function ( source ) {
  9847. THREE.Object3D.prototype.copy.call( this, source );
  9848. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  9849. this.projectionMatrix.copy( source.projectionMatrix );
  9850. return this;
  9851. };
  9852. // File:src/cameras/CubeCamera.js
  9853. /**
  9854. * Camera for rendering cube maps
  9855. * - renders scene into axis-aligned cube
  9856. *
  9857. * @author alteredq / http://alteredqualia.com/
  9858. */
  9859. THREE.CubeCamera = function ( near, far, cubeResolution ) {
  9860. THREE.Object3D.call( this );
  9861. this.type = 'CubeCamera';
  9862. var fov = 90, aspect = 1;
  9863. var cameraPX = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9864. cameraPX.up.set( 0, - 1, 0 );
  9865. cameraPX.lookAt( new THREE.Vector3( 1, 0, 0 ) );
  9866. this.add( cameraPX );
  9867. var cameraNX = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9868. cameraNX.up.set( 0, - 1, 0 );
  9869. cameraNX.lookAt( new THREE.Vector3( - 1, 0, 0 ) );
  9870. this.add( cameraNX );
  9871. var cameraPY = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9872. cameraPY.up.set( 0, 0, 1 );
  9873. cameraPY.lookAt( new THREE.Vector3( 0, 1, 0 ) );
  9874. this.add( cameraPY );
  9875. var cameraNY = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9876. cameraNY.up.set( 0, 0, - 1 );
  9877. cameraNY.lookAt( new THREE.Vector3( 0, - 1, 0 ) );
  9878. this.add( cameraNY );
  9879. var cameraPZ = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9880. cameraPZ.up.set( 0, - 1, 0 );
  9881. cameraPZ.lookAt( new THREE.Vector3( 0, 0, 1 ) );
  9882. this.add( cameraPZ );
  9883. var cameraNZ = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9884. cameraNZ.up.set( 0, - 1, 0 );
  9885. cameraNZ.lookAt( new THREE.Vector3( 0, 0, - 1 ) );
  9886. this.add( cameraNZ );
  9887. var options = { format: THREE.RGBFormat, magFilter: THREE.LinearFilter, minFilter: THREE.LinearFilter };
  9888. this.renderTarget = new THREE.WebGLRenderTargetCube( cubeResolution, cubeResolution, options );
  9889. this.updateCubeMap = function ( renderer, scene ) {
  9890. if ( this.parent === null ) this.updateMatrixWorld();
  9891. var renderTarget = this.renderTarget;
  9892. var generateMipmaps = renderTarget.texture.generateMipmaps;
  9893. renderTarget.texture.generateMipmaps = false;
  9894. renderTarget.activeCubeFace = 0;
  9895. renderer.render( scene, cameraPX, renderTarget );
  9896. renderTarget.activeCubeFace = 1;
  9897. renderer.render( scene, cameraNX, renderTarget );
  9898. renderTarget.activeCubeFace = 2;
  9899. renderer.render( scene, cameraPY, renderTarget );
  9900. renderTarget.activeCubeFace = 3;
  9901. renderer.render( scene, cameraNY, renderTarget );
  9902. renderTarget.activeCubeFace = 4;
  9903. renderer.render( scene, cameraPZ, renderTarget );
  9904. renderTarget.texture.generateMipmaps = generateMipmaps;
  9905. renderTarget.activeCubeFace = 5;
  9906. renderer.render( scene, cameraNZ, renderTarget );
  9907. renderer.setRenderTarget( null );
  9908. };
  9909. };
  9910. THREE.CubeCamera.prototype = Object.create( THREE.Object3D.prototype );
  9911. THREE.CubeCamera.prototype.constructor = THREE.CubeCamera;
  9912. // File:src/cameras/OrthographicCamera.js
  9913. /**
  9914. * @author alteredq / http://alteredqualia.com/
  9915. */
  9916. THREE.OrthographicCamera = function ( left, right, top, bottom, near, far ) {
  9917. THREE.Camera.call( this );
  9918. this.type = 'OrthographicCamera';
  9919. this.zoom = 1;
  9920. this.left = left;
  9921. this.right = right;
  9922. this.top = top;
  9923. this.bottom = bottom;
  9924. this.near = ( near !== undefined ) ? near : 0.1;
  9925. this.far = ( far !== undefined ) ? far : 2000;
  9926. this.updateProjectionMatrix();
  9927. };
  9928. THREE.OrthographicCamera.prototype = Object.create( THREE.Camera.prototype );
  9929. THREE.OrthographicCamera.prototype.constructor = THREE.OrthographicCamera;
  9930. THREE.OrthographicCamera.prototype.updateProjectionMatrix = function () {
  9931. var dx = ( this.right - this.left ) / ( 2 * this.zoom );
  9932. var dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  9933. var cx = ( this.right + this.left ) / 2;
  9934. var cy = ( this.top + this.bottom ) / 2;
  9935. this.projectionMatrix.makeOrthographic( cx - dx, cx + dx, cy + dy, cy - dy, this.near, this.far );
  9936. };
  9937. THREE.OrthographicCamera.prototype.copy = function ( source ) {
  9938. THREE.Camera.prototype.copy.call( this, source );
  9939. this.left = source.left;
  9940. this.right = source.right;
  9941. this.top = source.top;
  9942. this.bottom = source.bottom;
  9943. this.near = source.near;
  9944. this.far = source.far;
  9945. this.zoom = source.zoom;
  9946. return this;
  9947. };
  9948. THREE.OrthographicCamera.prototype.toJSON = function ( meta ) {
  9949. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  9950. data.object.zoom = this.zoom;
  9951. data.object.left = this.left;
  9952. data.object.right = this.right;
  9953. data.object.top = this.top;
  9954. data.object.bottom = this.bottom;
  9955. data.object.near = this.near;
  9956. data.object.far = this.far;
  9957. return data;
  9958. };
  9959. // File:src/cameras/PerspectiveCamera.js
  9960. /**
  9961. * @author mrdoob / http://mrdoob.com/
  9962. * @author greggman / http://games.greggman.com/
  9963. * @author zz85 / http://www.lab4games.net/zz85/blog
  9964. */
  9965. THREE.PerspectiveCamera = function ( fov, aspect, near, far ) {
  9966. THREE.Camera.call( this );
  9967. this.type = 'PerspectiveCamera';
  9968. this.focalLength = 10;
  9969. this.zoom = 1;
  9970. this.fov = fov !== undefined ? fov : 50;
  9971. this.aspect = aspect !== undefined ? aspect : 1;
  9972. this.near = near !== undefined ? near : 0.1;
  9973. this.far = far !== undefined ? far : 2000;
  9974. this.updateProjectionMatrix();
  9975. };
  9976. THREE.PerspectiveCamera.prototype = Object.create( THREE.Camera.prototype );
  9977. THREE.PerspectiveCamera.prototype.constructor = THREE.PerspectiveCamera;
  9978. /**
  9979. * Uses Focal Length (in mm) to estimate and set FOV
  9980. * 35mm (full-frame) camera is used if frame size is not specified;
  9981. * Formula based on http://www.bobatkins.com/photography/technical/field_of_view.html
  9982. */
  9983. THREE.PerspectiveCamera.prototype.setLens = function ( focalLength, frameHeight ) {
  9984. if ( frameHeight === undefined ) frameHeight = 24;
  9985. this.fov = 2 * THREE.Math.radToDeg( Math.atan( frameHeight / ( focalLength * 2 ) ) );
  9986. this.updateProjectionMatrix();
  9987. };
  9988. /**
  9989. * Sets an offset in a larger frustum. This is useful for multi-window or
  9990. * multi-monitor/multi-machine setups.
  9991. *
  9992. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  9993. * the monitors are in grid like this
  9994. *
  9995. * +---+---+---+
  9996. * | A | B | C |
  9997. * +---+---+---+
  9998. * | D | E | F |
  9999. * +---+---+---+
  10000. *
  10001. * then for each monitor you would call it like this
  10002. *
  10003. * var w = 1920;
  10004. * var h = 1080;
  10005. * var fullWidth = w * 3;
  10006. * var fullHeight = h * 2;
  10007. *
  10008. * --A--
  10009. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  10010. * --B--
  10011. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  10012. * --C--
  10013. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  10014. * --D--
  10015. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  10016. * --E--
  10017. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  10018. * --F--
  10019. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  10020. *
  10021. * Note there is no reason monitors have to be the same size or in a grid.
  10022. */
  10023. THREE.PerspectiveCamera.prototype.setViewOffset = function ( fullWidth, fullHeight, x, y, width, height ) {
  10024. this.fullWidth = fullWidth;
  10025. this.fullHeight = fullHeight;
  10026. this.x = x;
  10027. this.y = y;
  10028. this.width = width;
  10029. this.height = height;
  10030. this.updateProjectionMatrix();
  10031. };
  10032. THREE.PerspectiveCamera.prototype.updateProjectionMatrix = function () {
  10033. var fov = THREE.Math.radToDeg( 2 * Math.atan( Math.tan( THREE.Math.degToRad( this.fov ) * 0.5 ) / this.zoom ) );
  10034. if ( this.fullWidth ) {
  10035. var aspect = this.fullWidth / this.fullHeight;
  10036. var top = Math.tan( THREE.Math.degToRad( fov * 0.5 ) ) * this.near;
  10037. var bottom = - top;
  10038. var left = aspect * bottom;
  10039. var right = aspect * top;
  10040. var width = Math.abs( right - left );
  10041. var height = Math.abs( top - bottom );
  10042. this.projectionMatrix.makeFrustum(
  10043. left + this.x * width / this.fullWidth,
  10044. left + ( this.x + this.width ) * width / this.fullWidth,
  10045. top - ( this.y + this.height ) * height / this.fullHeight,
  10046. top - this.y * height / this.fullHeight,
  10047. this.near,
  10048. this.far
  10049. );
  10050. } else {
  10051. this.projectionMatrix.makePerspective( fov, this.aspect, this.near, this.far );
  10052. }
  10053. };
  10054. THREE.PerspectiveCamera.prototype.copy = function ( source ) {
  10055. THREE.Camera.prototype.copy.call( this, source );
  10056. this.focalLength = source.focalLength;
  10057. this.zoom = source.zoom;
  10058. this.fov = source.fov;
  10059. this.aspect = source.aspect;
  10060. this.near = source.near;
  10061. this.far = source.far;
  10062. return this;
  10063. };
  10064. THREE.PerspectiveCamera.prototype.toJSON = function ( meta ) {
  10065. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  10066. data.object.focalLength = this.focalLength;
  10067. data.object.zoom = this.zoom;
  10068. data.object.fov = this.fov;
  10069. data.object.aspect = this.aspect;
  10070. data.object.near = this.near;
  10071. data.object.far = this.far;
  10072. return data;
  10073. };
  10074. // File:src/cameras/StereoCamera.js
  10075. /**
  10076. * @author mrdoob / http://mrdoob.com/
  10077. */
  10078. THREE.StereoCamera = function () {
  10079. this.type = 'StereoCamera';
  10080. this.aspect = 1;
  10081. this.cameraL = new THREE.PerspectiveCamera();
  10082. this.cameraL.layers.enable( 1 );
  10083. this.cameraL.matrixAutoUpdate = false;
  10084. this.cameraR = new THREE.PerspectiveCamera();
  10085. this.cameraR.layers.enable( 2 );
  10086. this.cameraR.matrixAutoUpdate = false;
  10087. };
  10088. THREE.StereoCamera.prototype = {
  10089. constructor: THREE.StereoCamera,
  10090. update: ( function () {
  10091. var focalLength, fov, aspect, near, far;
  10092. var eyeRight = new THREE.Matrix4();
  10093. var eyeLeft = new THREE.Matrix4();
  10094. return function update ( camera ) {
  10095. var needsUpdate = focalLength !== camera.focalLength || fov !== camera.fov ||
  10096. aspect !== camera.aspect * this.aspect || near !== camera.near ||
  10097. far !== camera.far;
  10098. if ( needsUpdate ) {
  10099. focalLength = camera.focalLength;
  10100. fov = camera.fov;
  10101. aspect = camera.aspect * this.aspect;
  10102. near = camera.near;
  10103. far = camera.far;
  10104. // Off-axis stereoscopic effect based on
  10105. // http://paulbourke.net/stereographics/stereorender/
  10106. var projectionMatrix = camera.projectionMatrix.clone();
  10107. var eyeSep = 0.064 / 2;
  10108. var eyeSepOnProjection = eyeSep * near / focalLength;
  10109. var ymax = near * Math.tan( THREE.Math.degToRad( fov * 0.5 ) );
  10110. var xmin, xmax;
  10111. // translate xOffset
  10112. eyeLeft.elements[ 12 ] = - eyeSep;
  10113. eyeRight.elements[ 12 ] = eyeSep;
  10114. // for left eye
  10115. xmin = - ymax * aspect + eyeSepOnProjection;
  10116. xmax = ymax * aspect + eyeSepOnProjection;
  10117. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  10118. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  10119. this.cameraL.projectionMatrix.copy( projectionMatrix );
  10120. // for right eye
  10121. xmin = - ymax * aspect - eyeSepOnProjection;
  10122. xmax = ymax * aspect - eyeSepOnProjection;
  10123. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  10124. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  10125. this.cameraR.projectionMatrix.copy( projectionMatrix );
  10126. }
  10127. this.cameraL.matrixWorld.copy( camera.matrixWorld ).multiply( eyeLeft );
  10128. this.cameraR.matrixWorld.copy( camera.matrixWorld ).multiply( eyeRight );
  10129. };
  10130. } )()
  10131. };
  10132. // File:src/lights/Light.js
  10133. /**
  10134. * @author mrdoob / http://mrdoob.com/
  10135. * @author alteredq / http://alteredqualia.com/
  10136. */
  10137. THREE.Light = function ( color, intensity ) {
  10138. THREE.Object3D.call( this );
  10139. this.type = 'Light';
  10140. this.color = new THREE.Color( color );
  10141. this.intensity = intensity !== undefined ? intensity : 1;
  10142. this.receiveShadow = undefined;
  10143. };
  10144. THREE.Light.prototype = Object.create( THREE.Object3D.prototype );
  10145. THREE.Light.prototype.constructor = THREE.Light;
  10146. THREE.Light.prototype.copy = function ( source ) {
  10147. THREE.Object3D.prototype.copy.call( this, source );
  10148. this.color.copy( source.color );
  10149. this.intensity = source.intensity;
  10150. return this;
  10151. };
  10152. THREE.Light.prototype.toJSON = function ( meta ) {
  10153. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  10154. data.object.color = this.color.getHex();
  10155. data.object.intensity = this.intensity;
  10156. if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();
  10157. if ( this.distance !== undefined ) data.object.distance = this.distance;
  10158. if ( this.angle !== undefined ) data.object.angle = this.angle;
  10159. if ( this.decay !== undefined ) data.object.decay = this.decay;
  10160. if ( this.penumbra !== undefined ) data.object.penumbra = this.penumbra;
  10161. return data;
  10162. };
  10163. // File:src/lights/LightShadow.js
  10164. /**
  10165. * @author mrdoob / http://mrdoob.com/
  10166. */
  10167. THREE.LightShadow = function ( camera ) {
  10168. this.camera = camera;
  10169. this.bias = 0;
  10170. this.radius = 1;
  10171. this.mapSize = new THREE.Vector2( 512, 512 );
  10172. this.map = null;
  10173. this.matrix = new THREE.Matrix4();
  10174. };
  10175. THREE.LightShadow.prototype = {
  10176. constructor: THREE.LightShadow,
  10177. copy: function ( source ) {
  10178. this.camera = source.camera.clone();
  10179. this.bias = source.bias;
  10180. this.radius = source.radius;
  10181. this.mapSize.copy( source.mapSize );
  10182. return this;
  10183. },
  10184. clone: function () {
  10185. return new this.constructor().copy( this );
  10186. }
  10187. };
  10188. // File:src/lights/AmbientLight.js
  10189. /**
  10190. * @author mrdoob / http://mrdoob.com/
  10191. */
  10192. THREE.AmbientLight = function ( color, intensity ) {
  10193. THREE.Light.call( this, color, intensity );
  10194. this.type = 'AmbientLight';
  10195. this.castShadow = undefined;
  10196. };
  10197. THREE.AmbientLight.prototype = Object.create( THREE.Light.prototype );
  10198. THREE.AmbientLight.prototype.constructor = THREE.AmbientLight;
  10199. // File:src/lights/DirectionalLight.js
  10200. /**
  10201. * @author mrdoob / http://mrdoob.com/
  10202. * @author alteredq / http://alteredqualia.com/
  10203. */
  10204. THREE.DirectionalLight = function ( color, intensity ) {
  10205. THREE.Light.call( this, color, intensity );
  10206. this.type = 'DirectionalLight';
  10207. this.position.set( 0, 1, 0 );
  10208. this.updateMatrix();
  10209. this.target = new THREE.Object3D();
  10210. this.shadow = new THREE.DirectionalLightShadow();
  10211. };
  10212. THREE.DirectionalLight.prototype = Object.create( THREE.Light.prototype );
  10213. THREE.DirectionalLight.prototype.constructor = THREE.DirectionalLight;
  10214. THREE.DirectionalLight.prototype.copy = function ( source ) {
  10215. THREE.Light.prototype.copy.call( this, source );
  10216. this.target = source.target.clone();
  10217. this.shadow = source.shadow.clone();
  10218. return this;
  10219. };
  10220. // File:src/lights/DirectionalLightShadow.js
  10221. /**
  10222. * @author mrdoob / http://mrdoob.com/
  10223. */
  10224. THREE.DirectionalLightShadow = function ( light ) {
  10225. THREE.LightShadow.call( this, new THREE.OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) );
  10226. };
  10227. // File:src/lights/HemisphereLight.js
  10228. /**
  10229. * @author alteredq / http://alteredqualia.com/
  10230. */
  10231. THREE.HemisphereLight = function ( skyColor, groundColor, intensity ) {
  10232. THREE.Light.call( this, skyColor, intensity );
  10233. this.type = 'HemisphereLight';
  10234. this.castShadow = undefined;
  10235. this.position.set( 0, 1, 0 );
  10236. this.updateMatrix();
  10237. this.groundColor = new THREE.Color( groundColor );
  10238. };
  10239. THREE.HemisphereLight.prototype = Object.create( THREE.Light.prototype );
  10240. THREE.HemisphereLight.prototype.constructor = THREE.HemisphereLight;
  10241. THREE.HemisphereLight.prototype.copy = function ( source ) {
  10242. THREE.Light.prototype.copy.call( this, source );
  10243. this.groundColor.copy( source.groundColor );
  10244. return this;
  10245. };
  10246. // File:src/lights/PointLight.js
  10247. /**
  10248. * @author mrdoob / http://mrdoob.com/
  10249. */
  10250. THREE.PointLight = function ( color, intensity, distance, decay ) {
  10251. THREE.Light.call( this, color, intensity );
  10252. this.type = 'PointLight';
  10253. this.distance = ( distance !== undefined ) ? distance : 0;
  10254. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  10255. this.shadow = new THREE.LightShadow( new THREE.PerspectiveCamera( 90, 1, 0.5, 500 ) );
  10256. };
  10257. THREE.PointLight.prototype = Object.create( THREE.Light.prototype );
  10258. THREE.PointLight.prototype.constructor = THREE.PointLight;
  10259. Object.defineProperty( THREE.PointLight.prototype, "power", {
  10260. get: function () {
  10261. // intensity = power per solid angle.
  10262. // ref: equation (15) from http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
  10263. return this.intensity * 4 * Math.PI;
  10264. },
  10265. set: function ( power ) {
  10266. // intensity = power per solid angle.
  10267. // ref: equation (15) from http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
  10268. this.intensity = power / ( 4 * Math.PI );
  10269. }
  10270. } );
  10271. THREE.PointLight.prototype.copy = function ( source ) {
  10272. THREE.Light.prototype.copy.call( this, source );
  10273. this.distance = source.distance;
  10274. this.decay = source.decay;
  10275. this.shadow = source.shadow.clone();
  10276. return this;
  10277. };
  10278. // File:src/lights/SpotLight.js
  10279. /**
  10280. * @author alteredq / http://alteredqualia.com/
  10281. */
  10282. THREE.SpotLight = function ( color, intensity, distance, angle, penumbra, decay ) {
  10283. THREE.Light.call( this, color, intensity );
  10284. this.type = 'SpotLight';
  10285. this.position.set( 0, 1, 0 );
  10286. this.updateMatrix();
  10287. this.target = new THREE.Object3D();
  10288. this.distance = ( distance !== undefined ) ? distance : 0;
  10289. this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
  10290. this.penumbra = ( penumbra !== undefined ) ? penumbra : 0;
  10291. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  10292. this.shadow = new THREE.SpotLightShadow();
  10293. };
  10294. THREE.SpotLight.prototype = Object.create( THREE.Light.prototype );
  10295. THREE.SpotLight.prototype.constructor = THREE.SpotLight;
  10296. Object.defineProperty( THREE.SpotLight.prototype, "power", {
  10297. get: function () {
  10298. // intensity = power per solid angle.
  10299. // ref: equation (17) from http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
  10300. return this.intensity * Math.PI;
  10301. },
  10302. set: function ( power ) {
  10303. // intensity = power per solid angle.
  10304. // ref: equation (17) from http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
  10305. this.intensity = power / Math.PI;
  10306. }
  10307. } );
  10308. THREE.SpotLight.prototype.copy = function ( source ) {
  10309. THREE.Light.prototype.copy.call( this, source );
  10310. this.distance = source.distance;
  10311. this.angle = source.angle;
  10312. this.penumbra = source.penumbra;
  10313. this.decay = source.decay;
  10314. this.target = source.target.clone();
  10315. this.shadow = source.shadow.clone();
  10316. return this;
  10317. };
  10318. // File:src/lights/SpotLightShadow.js
  10319. /**
  10320. * @author mrdoob / http://mrdoob.com/
  10321. */
  10322. THREE.SpotLightShadow = function () {
  10323. THREE.LightShadow.call( this, new THREE.PerspectiveCamera( 50, 1, 0.5, 500 ) );
  10324. };
  10325. THREE.SpotLightShadow.prototype = {
  10326. constructor: THREE.SpotLightShadow,
  10327. update: function ( light ) {
  10328. var fov = THREE.Math.radToDeg( 2 * light.angle );
  10329. var aspect = this.mapSize.width / this.mapSize.height;
  10330. var far = light.distance || 500;
  10331. var camera = this.camera;
  10332. if ( fov !== camera.fov || aspect !== camera.aspect || far !== camera.far ) {
  10333. camera.fov = fov;
  10334. camera.aspect = aspect;
  10335. camera.far = far;
  10336. camera.updateProjectionMatrix();
  10337. }
  10338. }
  10339. };
  10340. // File:src/loaders/AudioLoader.js
  10341. /**
  10342. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  10343. */
  10344. THREE.AudioLoader = function ( manager ) {
  10345. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10346. };
  10347. THREE.AudioLoader.prototype = {
  10348. constructor: THREE.AudioLoader,
  10349. load: function ( url, onLoad, onProgress, onError ) {
  10350. var loader = new THREE.XHRLoader( this.manager );
  10351. loader.setResponseType( 'arraybuffer' );
  10352. loader.load( url, function ( buffer ) {
  10353. var context = THREE.AudioContext;
  10354. context.decodeAudioData( buffer, function ( audioBuffer ) {
  10355. onLoad( audioBuffer );
  10356. } );
  10357. }, onProgress, onError );
  10358. }
  10359. };
  10360. // File:src/loaders/Cache.js
  10361. /**
  10362. * @author mrdoob / http://mrdoob.com/
  10363. */
  10364. THREE.Cache = {
  10365. enabled: false,
  10366. files: {},
  10367. add: function ( key, file ) {
  10368. if ( this.enabled === false ) return;
  10369. // console.log( 'THREE.Cache', 'Adding key:', key );
  10370. this.files[ key ] = file;
  10371. },
  10372. get: function ( key ) {
  10373. if ( this.enabled === false ) return;
  10374. // console.log( 'THREE.Cache', 'Checking key:', key );
  10375. return this.files[ key ];
  10376. },
  10377. remove: function ( key ) {
  10378. delete this.files[ key ];
  10379. },
  10380. clear: function () {
  10381. this.files = {};
  10382. }
  10383. };
  10384. // File:src/loaders/Loader.js
  10385. /**
  10386. * @author alteredq / http://alteredqualia.com/
  10387. */
  10388. THREE.Loader = function () {
  10389. this.onLoadStart = function () {};
  10390. this.onLoadProgress = function () {};
  10391. this.onLoadComplete = function () {};
  10392. };
  10393. THREE.Loader.prototype = {
  10394. constructor: THREE.Loader,
  10395. crossOrigin: undefined,
  10396. extractUrlBase: function ( url ) {
  10397. var parts = url.split( '/' );
  10398. if ( parts.length === 1 ) return './';
  10399. parts.pop();
  10400. return parts.join( '/' ) + '/';
  10401. },
  10402. initMaterials: function ( materials, texturePath, crossOrigin ) {
  10403. var array = [];
  10404. for ( var i = 0; i < materials.length; ++ i ) {
  10405. array[ i ] = this.createMaterial( materials[ i ], texturePath, crossOrigin );
  10406. }
  10407. return array;
  10408. },
  10409. createMaterial: ( function () {
  10410. var color, textureLoader, materialLoader;
  10411. return function ( m, texturePath, crossOrigin ) {
  10412. if ( color === undefined ) color = new THREE.Color();
  10413. if ( textureLoader === undefined ) textureLoader = new THREE.TextureLoader();
  10414. if ( materialLoader === undefined ) materialLoader = new THREE.MaterialLoader();
  10415. // convert from old material format
  10416. var textures = {};
  10417. function loadTexture( path, repeat, offset, wrap, anisotropy ) {
  10418. var fullPath = texturePath + path;
  10419. var loader = THREE.Loader.Handlers.get( fullPath );
  10420. var texture;
  10421. if ( loader !== null ) {
  10422. texture = loader.load( fullPath );
  10423. } else {
  10424. textureLoader.setCrossOrigin( crossOrigin );
  10425. texture = textureLoader.load( fullPath );
  10426. }
  10427. if ( repeat !== undefined ) {
  10428. texture.repeat.fromArray( repeat );
  10429. if ( repeat[ 0 ] !== 1 ) texture.wrapS = THREE.RepeatWrapping;
  10430. if ( repeat[ 1 ] !== 1 ) texture.wrapT = THREE.RepeatWrapping;
  10431. }
  10432. if ( offset !== undefined ) {
  10433. texture.offset.fromArray( offset );
  10434. }
  10435. if ( wrap !== undefined ) {
  10436. if ( wrap[ 0 ] === 'repeat' ) texture.wrapS = THREE.RepeatWrapping;
  10437. if ( wrap[ 0 ] === 'mirror' ) texture.wrapS = THREE.MirroredRepeatWrapping;
  10438. if ( wrap[ 1 ] === 'repeat' ) texture.wrapT = THREE.RepeatWrapping;
  10439. if ( wrap[ 1 ] === 'mirror' ) texture.wrapT = THREE.MirroredRepeatWrapping;
  10440. }
  10441. if ( anisotropy !== undefined ) {
  10442. texture.anisotropy = anisotropy;
  10443. }
  10444. var uuid = THREE.Math.generateUUID();
  10445. textures[ uuid ] = texture;
  10446. return uuid;
  10447. }
  10448. //
  10449. var json = {
  10450. uuid: THREE.Math.generateUUID(),
  10451. type: 'MeshLambertMaterial'
  10452. };
  10453. for ( var name in m ) {
  10454. var value = m[ name ];
  10455. switch ( name ) {
  10456. case 'DbgColor':
  10457. case 'DbgIndex':
  10458. case 'opticalDensity':
  10459. case 'illumination':
  10460. break;
  10461. case 'DbgName':
  10462. json.name = value;
  10463. break;
  10464. case 'blending':
  10465. json.blending = THREE[ value ];
  10466. break;
  10467. case 'colorAmbient':
  10468. case 'mapAmbient':
  10469. console.warn( 'THREE.Loader.createMaterial:', name, 'is no longer supported.' );
  10470. break;
  10471. case 'colorDiffuse':
  10472. json.color = color.fromArray( value ).getHex();
  10473. break;
  10474. case 'colorSpecular':
  10475. json.specular = color.fromArray( value ).getHex();
  10476. break;
  10477. case 'colorEmissive':
  10478. json.emissive = color.fromArray( value ).getHex();
  10479. break;
  10480. case 'specularCoef':
  10481. json.shininess = value;
  10482. break;
  10483. case 'shading':
  10484. if ( value.toLowerCase() === 'basic' ) json.type = 'MeshBasicMaterial';
  10485. if ( value.toLowerCase() === 'phong' ) json.type = 'MeshPhongMaterial';
  10486. break;
  10487. case 'mapDiffuse':
  10488. json.map = loadTexture( value, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap, m.mapDiffuseAnisotropy );
  10489. break;
  10490. case 'mapDiffuseRepeat':
  10491. case 'mapDiffuseOffset':
  10492. case 'mapDiffuseWrap':
  10493. case 'mapDiffuseAnisotropy':
  10494. break;
  10495. case 'mapLight':
  10496. json.lightMap = loadTexture( value, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap, m.mapLightAnisotropy );
  10497. break;
  10498. case 'mapLightRepeat':
  10499. case 'mapLightOffset':
  10500. case 'mapLightWrap':
  10501. case 'mapLightAnisotropy':
  10502. break;
  10503. case 'mapAO':
  10504. json.aoMap = loadTexture( value, m.mapAORepeat, m.mapAOOffset, m.mapAOWrap, m.mapAOAnisotropy );
  10505. break;
  10506. case 'mapAORepeat':
  10507. case 'mapAOOffset':
  10508. case 'mapAOWrap':
  10509. case 'mapAOAnisotropy':
  10510. break;
  10511. case 'mapBump':
  10512. json.bumpMap = loadTexture( value, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap, m.mapBumpAnisotropy );
  10513. break;
  10514. case 'mapBumpScale':
  10515. json.bumpScale = value;
  10516. break;
  10517. case 'mapBumpRepeat':
  10518. case 'mapBumpOffset':
  10519. case 'mapBumpWrap':
  10520. case 'mapBumpAnisotropy':
  10521. break;
  10522. case 'mapNormal':
  10523. json.normalMap = loadTexture( value, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap, m.mapNormalAnisotropy );
  10524. break;
  10525. case 'mapNormalFactor':
  10526. json.normalScale = [ value, value ];
  10527. break;
  10528. case 'mapNormalRepeat':
  10529. case 'mapNormalOffset':
  10530. case 'mapNormalWrap':
  10531. case 'mapNormalAnisotropy':
  10532. break;
  10533. case 'mapSpecular':
  10534. json.specularMap = loadTexture( value, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap, m.mapSpecularAnisotropy );
  10535. break;
  10536. case 'mapSpecularRepeat':
  10537. case 'mapSpecularOffset':
  10538. case 'mapSpecularWrap':
  10539. case 'mapSpecularAnisotropy':
  10540. break;
  10541. case 'mapAlpha':
  10542. json.alphaMap = loadTexture( value, m.mapAlphaRepeat, m.mapAlphaOffset, m.mapAlphaWrap, m.mapAlphaAnisotropy );
  10543. break;
  10544. case 'mapAlphaRepeat':
  10545. case 'mapAlphaOffset':
  10546. case 'mapAlphaWrap':
  10547. case 'mapAlphaAnisotropy':
  10548. break;
  10549. case 'flipSided':
  10550. json.side = THREE.BackSide;
  10551. break;
  10552. case 'doubleSided':
  10553. json.side = THREE.DoubleSide;
  10554. break;
  10555. case 'transparency':
  10556. console.warn( 'THREE.Loader.createMaterial: transparency has been renamed to opacity' );
  10557. json.opacity = value;
  10558. break;
  10559. case 'depthTest':
  10560. case 'depthWrite':
  10561. case 'colorWrite':
  10562. case 'opacity':
  10563. case 'reflectivity':
  10564. case 'transparent':
  10565. case 'visible':
  10566. case 'wireframe':
  10567. json[ name ] = value;
  10568. break;
  10569. case 'vertexColors':
  10570. if ( value === true ) json.vertexColors = THREE.VertexColors;
  10571. if ( value === 'face' ) json.vertexColors = THREE.FaceColors;
  10572. break;
  10573. default:
  10574. console.error( 'THREE.Loader.createMaterial: Unsupported', name, value );
  10575. break;
  10576. }
  10577. }
  10578. if ( json.type === 'MeshBasicMaterial' ) delete json.emissive;
  10579. if ( json.type !== 'MeshPhongMaterial' ) delete json.specular;
  10580. if ( json.opacity < 1 ) json.transparent = true;
  10581. materialLoader.setTextures( textures );
  10582. return materialLoader.parse( json );
  10583. };
  10584. } )()
  10585. };
  10586. THREE.Loader.Handlers = {
  10587. handlers: [],
  10588. add: function ( regex, loader ) {
  10589. this.handlers.push( regex, loader );
  10590. },
  10591. get: function ( file ) {
  10592. var handlers = this.handlers;
  10593. for ( var i = 0, l = handlers.length; i < l; i += 2 ) {
  10594. var regex = handlers[ i ];
  10595. var loader = handlers[ i + 1 ];
  10596. if ( regex.test( file ) ) {
  10597. return loader;
  10598. }
  10599. }
  10600. return null;
  10601. }
  10602. };
  10603. // File:src/loaders/XHRLoader.js
  10604. /**
  10605. * @author mrdoob / http://mrdoob.com/
  10606. */
  10607. THREE.XHRLoader = function ( manager ) {
  10608. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10609. };
  10610. THREE.XHRLoader.prototype = {
  10611. constructor: THREE.XHRLoader,
  10612. load: function ( url, onLoad, onProgress, onError ) {
  10613. if ( this.path !== undefined ) url = this.path + url;
  10614. var scope = this;
  10615. var cached = THREE.Cache.get( url );
  10616. if ( cached !== undefined ) {
  10617. if ( onLoad ) {
  10618. setTimeout( function () {
  10619. onLoad( cached );
  10620. }, 0 );
  10621. }
  10622. return cached;
  10623. }
  10624. var request = new XMLHttpRequest();
  10625. request.overrideMimeType( 'text/plain' );
  10626. request.open( 'GET', url, true );
  10627. request.addEventListener( 'load', function ( event ) {
  10628. var response = event.target.response;
  10629. THREE.Cache.add( url, response );
  10630. if ( this.status === 200 ) {
  10631. if ( onLoad ) onLoad( response );
  10632. scope.manager.itemEnd( url );
  10633. } else if ( this.status === 0 ) {
  10634. // Some browsers return HTTP Status 0 when using non-http protocol
  10635. // e.g. 'file://' or 'data://'. Handle as success.
  10636. console.warn( 'THREE.XHRLoader: HTTP Status 0 received.' );
  10637. if ( onLoad ) onLoad( response );
  10638. scope.manager.itemEnd( url );
  10639. } else {
  10640. if ( onError ) onError( event );
  10641. scope.manager.itemError( url );
  10642. }
  10643. }, false );
  10644. if ( onProgress !== undefined ) {
  10645. request.addEventListener( 'progress', function ( event ) {
  10646. onProgress( event );
  10647. }, false );
  10648. }
  10649. request.addEventListener( 'error', function ( event ) {
  10650. if ( onError ) onError( event );
  10651. scope.manager.itemError( url );
  10652. }, false );
  10653. if ( this.responseType !== undefined ) request.responseType = this.responseType;
  10654. if ( this.withCredentials !== undefined ) request.withCredentials = this.withCredentials;
  10655. request.send( null );
  10656. scope.manager.itemStart( url );
  10657. return request;
  10658. },
  10659. setPath: function ( value ) {
  10660. this.path = value;
  10661. },
  10662. setResponseType: function ( value ) {
  10663. this.responseType = value;
  10664. },
  10665. setWithCredentials: function ( value ) {
  10666. this.withCredentials = value;
  10667. }
  10668. };
  10669. // File:src/loaders/FontLoader.js
  10670. /**
  10671. * @author mrdoob / http://mrdoob.com/
  10672. */
  10673. THREE.FontLoader = function ( manager ) {
  10674. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10675. };
  10676. THREE.FontLoader.prototype = {
  10677. constructor: THREE.FontLoader,
  10678. load: function ( url, onLoad, onProgress, onError ) {
  10679. var loader = new THREE.XHRLoader( this.manager );
  10680. loader.load( url, function ( text ) {
  10681. onLoad( new THREE.Font( JSON.parse( text.substring( 65, text.length - 2 ) ) ) );
  10682. }, onProgress, onError );
  10683. }
  10684. };
  10685. // File:src/loaders/ImageLoader.js
  10686. /**
  10687. * @author mrdoob / http://mrdoob.com/
  10688. */
  10689. THREE.ImageLoader = function ( manager ) {
  10690. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10691. };
  10692. THREE.ImageLoader.prototype = {
  10693. constructor: THREE.ImageLoader,
  10694. load: function ( url, onLoad, onProgress, onError ) {
  10695. if ( this.path !== undefined ) url = this.path + url;
  10696. var scope = this;
  10697. var cached = THREE.Cache.get( url );
  10698. if ( cached !== undefined ) {
  10699. scope.manager.itemStart( url );
  10700. if ( onLoad ) {
  10701. setTimeout( function () {
  10702. onLoad( cached );
  10703. scope.manager.itemEnd( url );
  10704. }, 0 );
  10705. } else {
  10706. scope.manager.itemEnd( url );
  10707. }
  10708. return cached;
  10709. }
  10710. var image = document.createElement( 'img' );
  10711. image.addEventListener( 'load', function ( event ) {
  10712. THREE.Cache.add( url, this );
  10713. if ( onLoad ) onLoad( this );
  10714. scope.manager.itemEnd( url );
  10715. }, false );
  10716. if ( onProgress !== undefined ) {
  10717. image.addEventListener( 'progress', function ( event ) {
  10718. onProgress( event );
  10719. }, false );
  10720. }
  10721. image.addEventListener( 'error', function ( event ) {
  10722. if ( onError ) onError( event );
  10723. scope.manager.itemError( url );
  10724. }, false );
  10725. if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
  10726. scope.manager.itemStart( url );
  10727. image.src = url;
  10728. return image;
  10729. },
  10730. setCrossOrigin: function ( value ) {
  10731. this.crossOrigin = value;
  10732. },
  10733. setPath: function ( value ) {
  10734. this.path = value;
  10735. }
  10736. };
  10737. // File:src/loaders/JSONLoader.js
  10738. /**
  10739. * @author mrdoob / http://mrdoob.com/
  10740. * @author alteredq / http://alteredqualia.com/
  10741. */
  10742. THREE.JSONLoader = function ( manager ) {
  10743. if ( typeof manager === 'boolean' ) {
  10744. console.warn( 'THREE.JSONLoader: showStatus parameter has been removed from constructor.' );
  10745. manager = undefined;
  10746. }
  10747. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10748. this.withCredentials = false;
  10749. };
  10750. THREE.JSONLoader.prototype = {
  10751. constructor: THREE.JSONLoader,
  10752. // Deprecated
  10753. get statusDomElement () {
  10754. if ( this._statusDomElement === undefined ) {
  10755. this._statusDomElement = document.createElement( 'div' );
  10756. }
  10757. console.warn( 'THREE.JSONLoader: .statusDomElement has been removed.' );
  10758. return this._statusDomElement;
  10759. },
  10760. load: function( url, onLoad, onProgress, onError ) {
  10761. var scope = this;
  10762. var texturePath = this.texturePath && ( typeof this.texturePath === "string" ) ? this.texturePath : THREE.Loader.prototype.extractUrlBase( url );
  10763. var loader = new THREE.XHRLoader( this.manager );
  10764. loader.setWithCredentials( this.withCredentials );
  10765. loader.load( url, function ( text ) {
  10766. var json = JSON.parse( text );
  10767. var metadata = json.metadata;
  10768. if ( metadata !== undefined ) {
  10769. var type = metadata.type;
  10770. if ( type !== undefined ) {
  10771. if ( type.toLowerCase() === 'object' ) {
  10772. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.ObjectLoader instead.' );
  10773. return;
  10774. }
  10775. if ( type.toLowerCase() === 'scene' ) {
  10776. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.SceneLoader instead.' );
  10777. return;
  10778. }
  10779. }
  10780. }
  10781. var object = scope.parse( json, texturePath );
  10782. onLoad( object.geometry, object.materials );
  10783. }, onProgress, onError );
  10784. },
  10785. setTexturePath: function ( value ) {
  10786. this.texturePath = value;
  10787. },
  10788. parse: function ( json, texturePath ) {
  10789. var geometry = new THREE.Geometry(),
  10790. scale = ( json.scale !== undefined ) ? 1.0 / json.scale : 1.0;
  10791. parseModel( scale );
  10792. parseSkin();
  10793. parseMorphing( scale );
  10794. parseAnimations();
  10795. geometry.computeFaceNormals();
  10796. geometry.computeBoundingSphere();
  10797. function parseModel( scale ) {
  10798. function isBitSet( value, position ) {
  10799. return value & ( 1 << position );
  10800. }
  10801. var i, j, fi,
  10802. offset, zLength,
  10803. colorIndex, normalIndex, uvIndex, materialIndex,
  10804. type,
  10805. isQuad,
  10806. hasMaterial,
  10807. hasFaceVertexUv,
  10808. hasFaceNormal, hasFaceVertexNormal,
  10809. hasFaceColor, hasFaceVertexColor,
  10810. vertex, face, faceA, faceB, hex, normal,
  10811. uvLayer, uv, u, v,
  10812. faces = json.faces,
  10813. vertices = json.vertices,
  10814. normals = json.normals,
  10815. colors = json.colors,
  10816. nUvLayers = 0;
  10817. if ( json.uvs !== undefined ) {
  10818. // disregard empty arrays
  10819. for ( i = 0; i < json.uvs.length; i ++ ) {
  10820. if ( json.uvs[ i ].length ) nUvLayers ++;
  10821. }
  10822. for ( i = 0; i < nUvLayers; i ++ ) {
  10823. geometry.faceVertexUvs[ i ] = [];
  10824. }
  10825. }
  10826. offset = 0;
  10827. zLength = vertices.length;
  10828. while ( offset < zLength ) {
  10829. vertex = new THREE.Vector3();
  10830. vertex.x = vertices[ offset ++ ] * scale;
  10831. vertex.y = vertices[ offset ++ ] * scale;
  10832. vertex.z = vertices[ offset ++ ] * scale;
  10833. geometry.vertices.push( vertex );
  10834. }
  10835. offset = 0;
  10836. zLength = faces.length;
  10837. while ( offset < zLength ) {
  10838. type = faces[ offset ++ ];
  10839. isQuad = isBitSet( type, 0 );
  10840. hasMaterial = isBitSet( type, 1 );
  10841. hasFaceVertexUv = isBitSet( type, 3 );
  10842. hasFaceNormal = isBitSet( type, 4 );
  10843. hasFaceVertexNormal = isBitSet( type, 5 );
  10844. hasFaceColor = isBitSet( type, 6 );
  10845. hasFaceVertexColor = isBitSet( type, 7 );
  10846. // console.log("type", type, "bits", isQuad, hasMaterial, hasFaceVertexUv, hasFaceNormal, hasFaceVertexNormal, hasFaceColor, hasFaceVertexColor);
  10847. if ( isQuad ) {
  10848. faceA = new THREE.Face3();
  10849. faceA.a = faces[ offset ];
  10850. faceA.b = faces[ offset + 1 ];
  10851. faceA.c = faces[ offset + 3 ];
  10852. faceB = new THREE.Face3();
  10853. faceB.a = faces[ offset + 1 ];
  10854. faceB.b = faces[ offset + 2 ];
  10855. faceB.c = faces[ offset + 3 ];
  10856. offset += 4;
  10857. if ( hasMaterial ) {
  10858. materialIndex = faces[ offset ++ ];
  10859. faceA.materialIndex = materialIndex;
  10860. faceB.materialIndex = materialIndex;
  10861. }
  10862. // to get face <=> uv index correspondence
  10863. fi = geometry.faces.length;
  10864. if ( hasFaceVertexUv ) {
  10865. for ( i = 0; i < nUvLayers; i ++ ) {
  10866. uvLayer = json.uvs[ i ];
  10867. geometry.faceVertexUvs[ i ][ fi ] = [];
  10868. geometry.faceVertexUvs[ i ][ fi + 1 ] = [];
  10869. for ( j = 0; j < 4; j ++ ) {
  10870. uvIndex = faces[ offset ++ ];
  10871. u = uvLayer[ uvIndex * 2 ];
  10872. v = uvLayer[ uvIndex * 2 + 1 ];
  10873. uv = new THREE.Vector2( u, v );
  10874. if ( j !== 2 ) geometry.faceVertexUvs[ i ][ fi ].push( uv );
  10875. if ( j !== 0 ) geometry.faceVertexUvs[ i ][ fi + 1 ].push( uv );
  10876. }
  10877. }
  10878. }
  10879. if ( hasFaceNormal ) {
  10880. normalIndex = faces[ offset ++ ] * 3;
  10881. faceA.normal.set(
  10882. normals[ normalIndex ++ ],
  10883. normals[ normalIndex ++ ],
  10884. normals[ normalIndex ]
  10885. );
  10886. faceB.normal.copy( faceA.normal );
  10887. }
  10888. if ( hasFaceVertexNormal ) {
  10889. for ( i = 0; i < 4; i ++ ) {
  10890. normalIndex = faces[ offset ++ ] * 3;
  10891. normal = new THREE.Vector3(
  10892. normals[ normalIndex ++ ],
  10893. normals[ normalIndex ++ ],
  10894. normals[ normalIndex ]
  10895. );
  10896. if ( i !== 2 ) faceA.vertexNormals.push( normal );
  10897. if ( i !== 0 ) faceB.vertexNormals.push( normal );
  10898. }
  10899. }
  10900. if ( hasFaceColor ) {
  10901. colorIndex = faces[ offset ++ ];
  10902. hex = colors[ colorIndex ];
  10903. faceA.color.setHex( hex );
  10904. faceB.color.setHex( hex );
  10905. }
  10906. if ( hasFaceVertexColor ) {
  10907. for ( i = 0; i < 4; i ++ ) {
  10908. colorIndex = faces[ offset ++ ];
  10909. hex = colors[ colorIndex ];
  10910. if ( i !== 2 ) faceA.vertexColors.push( new THREE.Color( hex ) );
  10911. if ( i !== 0 ) faceB.vertexColors.push( new THREE.Color( hex ) );
  10912. }
  10913. }
  10914. geometry.faces.push( faceA );
  10915. geometry.faces.push( faceB );
  10916. } else {
  10917. face = new THREE.Face3();
  10918. face.a = faces[ offset ++ ];
  10919. face.b = faces[ offset ++ ];
  10920. face.c = faces[ offset ++ ];
  10921. if ( hasMaterial ) {
  10922. materialIndex = faces[ offset ++ ];
  10923. face.materialIndex = materialIndex;
  10924. }
  10925. // to get face <=> uv index correspondence
  10926. fi = geometry.faces.length;
  10927. if ( hasFaceVertexUv ) {
  10928. for ( i = 0; i < nUvLayers; i ++ ) {
  10929. uvLayer = json.uvs[ i ];
  10930. geometry.faceVertexUvs[ i ][ fi ] = [];
  10931. for ( j = 0; j < 3; j ++ ) {
  10932. uvIndex = faces[ offset ++ ];
  10933. u = uvLayer[ uvIndex * 2 ];
  10934. v = uvLayer[ uvIndex * 2 + 1 ];
  10935. uv = new THREE.Vector2( u, v );
  10936. geometry.faceVertexUvs[ i ][ fi ].push( uv );
  10937. }
  10938. }
  10939. }
  10940. if ( hasFaceNormal ) {
  10941. normalIndex = faces[ offset ++ ] * 3;
  10942. face.normal.set(
  10943. normals[ normalIndex ++ ],
  10944. normals[ normalIndex ++ ],
  10945. normals[ normalIndex ]
  10946. );
  10947. }
  10948. if ( hasFaceVertexNormal ) {
  10949. for ( i = 0; i < 3; i ++ ) {
  10950. normalIndex = faces[ offset ++ ] * 3;
  10951. normal = new THREE.Vector3(
  10952. normals[ normalIndex ++ ],
  10953. normals[ normalIndex ++ ],
  10954. normals[ normalIndex ]
  10955. );
  10956. face.vertexNormals.push( normal );
  10957. }
  10958. }
  10959. if ( hasFaceColor ) {
  10960. colorIndex = faces[ offset ++ ];
  10961. face.color.setHex( colors[ colorIndex ] );
  10962. }
  10963. if ( hasFaceVertexColor ) {
  10964. for ( i = 0; i < 3; i ++ ) {
  10965. colorIndex = faces[ offset ++ ];
  10966. face.vertexColors.push( new THREE.Color( colors[ colorIndex ] ) );
  10967. }
  10968. }
  10969. geometry.faces.push( face );
  10970. }
  10971. }
  10972. };
  10973. function parseSkin() {
  10974. var influencesPerVertex = ( json.influencesPerVertex !== undefined ) ? json.influencesPerVertex : 2;
  10975. if ( json.skinWeights ) {
  10976. for ( var i = 0, l = json.skinWeights.length; i < l; i += influencesPerVertex ) {
  10977. var x = json.skinWeights[ i ];
  10978. var y = ( influencesPerVertex > 1 ) ? json.skinWeights[ i + 1 ] : 0;
  10979. var z = ( influencesPerVertex > 2 ) ? json.skinWeights[ i + 2 ] : 0;
  10980. var w = ( influencesPerVertex > 3 ) ? json.skinWeights[ i + 3 ] : 0;
  10981. geometry.skinWeights.push( new THREE.Vector4( x, y, z, w ) );
  10982. }
  10983. }
  10984. if ( json.skinIndices ) {
  10985. for ( var i = 0, l = json.skinIndices.length; i < l; i += influencesPerVertex ) {
  10986. var a = json.skinIndices[ i ];
  10987. var b = ( influencesPerVertex > 1 ) ? json.skinIndices[ i + 1 ] : 0;
  10988. var c = ( influencesPerVertex > 2 ) ? json.skinIndices[ i + 2 ] : 0;
  10989. var d = ( influencesPerVertex > 3 ) ? json.skinIndices[ i + 3 ] : 0;
  10990. geometry.skinIndices.push( new THREE.Vector4( a, b, c, d ) );
  10991. }
  10992. }
  10993. geometry.bones = json.bones;
  10994. if ( geometry.bones && geometry.bones.length > 0 && ( geometry.skinWeights.length !== geometry.skinIndices.length || geometry.skinIndices.length !== geometry.vertices.length ) ) {
  10995. console.warn( 'When skinning, number of vertices (' + geometry.vertices.length + '), skinIndices (' +
  10996. geometry.skinIndices.length + '), and skinWeights (' + geometry.skinWeights.length + ') should match.' );
  10997. }
  10998. };
  10999. function parseMorphing( scale ) {
  11000. if ( json.morphTargets !== undefined ) {
  11001. for ( var i = 0, l = json.morphTargets.length; i < l; i ++ ) {
  11002. geometry.morphTargets[ i ] = {};
  11003. geometry.morphTargets[ i ].name = json.morphTargets[ i ].name;
  11004. geometry.morphTargets[ i ].vertices = [];
  11005. var dstVertices = geometry.morphTargets[ i ].vertices;
  11006. var srcVertices = json.morphTargets[ i ].vertices;
  11007. for ( var v = 0, vl = srcVertices.length; v < vl; v += 3 ) {
  11008. var vertex = new THREE.Vector3();
  11009. vertex.x = srcVertices[ v ] * scale;
  11010. vertex.y = srcVertices[ v + 1 ] * scale;
  11011. vertex.z = srcVertices[ v + 2 ] * scale;
  11012. dstVertices.push( vertex );
  11013. }
  11014. }
  11015. }
  11016. if ( json.morphColors !== undefined && json.morphColors.length > 0 ) {
  11017. console.warn( 'THREE.JSONLoader: "morphColors" no longer supported. Using them as face colors.' );
  11018. var faces = geometry.faces;
  11019. var morphColors = json.morphColors[ 0 ].colors;
  11020. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  11021. faces[ i ].color.fromArray( morphColors, i * 3 );
  11022. }
  11023. }
  11024. }
  11025. function parseAnimations() {
  11026. var outputAnimations = [];
  11027. // parse old style Bone/Hierarchy animations
  11028. var animations = [];
  11029. if ( json.animation !== undefined ) {
  11030. animations.push( json.animation );
  11031. }
  11032. if ( json.animations !== undefined ) {
  11033. if ( json.animations.length ) {
  11034. animations = animations.concat( json.animations );
  11035. } else {
  11036. animations.push( json.animations );
  11037. }
  11038. }
  11039. for ( var i = 0; i < animations.length; i ++ ) {
  11040. var clip = THREE.AnimationClip.parseAnimation( animations[ i ], geometry.bones );
  11041. if ( clip ) outputAnimations.push( clip );
  11042. }
  11043. // parse implicit morph animations
  11044. if ( geometry.morphTargets ) {
  11045. // TODO: Figure out what an appropraite FPS is for morph target animations -- defaulting to 10, but really it is completely arbitrary.
  11046. var morphAnimationClips = THREE.AnimationClip.CreateClipsFromMorphTargetSequences( geometry.morphTargets, 10 );
  11047. outputAnimations = outputAnimations.concat( morphAnimationClips );
  11048. }
  11049. if ( outputAnimations.length > 0 ) geometry.animations = outputAnimations;
  11050. };
  11051. if ( json.materials === undefined || json.materials.length === 0 ) {
  11052. return { geometry: geometry };
  11053. } else {
  11054. var materials = THREE.Loader.prototype.initMaterials( json.materials, texturePath, this.crossOrigin );
  11055. return { geometry: geometry, materials: materials };
  11056. }
  11057. }
  11058. };
  11059. // File:src/loaders/LoadingManager.js
  11060. /**
  11061. * @author mrdoob / http://mrdoob.com/
  11062. */
  11063. THREE.LoadingManager = function ( onLoad, onProgress, onError ) {
  11064. var scope = this;
  11065. var isLoading = false, itemsLoaded = 0, itemsTotal = 0;
  11066. this.onStart = undefined;
  11067. this.onLoad = onLoad;
  11068. this.onProgress = onProgress;
  11069. this.onError = onError;
  11070. this.itemStart = function ( url ) {
  11071. itemsTotal ++;
  11072. if ( isLoading === false ) {
  11073. if ( scope.onStart !== undefined ) {
  11074. scope.onStart( url, itemsLoaded, itemsTotal );
  11075. }
  11076. }
  11077. isLoading = true;
  11078. };
  11079. this.itemEnd = function ( url ) {
  11080. itemsLoaded ++;
  11081. if ( scope.onProgress !== undefined ) {
  11082. scope.onProgress( url, itemsLoaded, itemsTotal );
  11083. }
  11084. if ( itemsLoaded === itemsTotal ) {
  11085. isLoading = false;
  11086. if ( scope.onLoad !== undefined ) {
  11087. scope.onLoad();
  11088. }
  11089. }
  11090. };
  11091. this.itemError = function ( url ) {
  11092. if ( scope.onError !== undefined ) {
  11093. scope.onError( url );
  11094. }
  11095. };
  11096. };
  11097. THREE.DefaultLoadingManager = new THREE.LoadingManager();
  11098. // File:src/loaders/BufferGeometryLoader.js
  11099. /**
  11100. * @author mrdoob / http://mrdoob.com/
  11101. */
  11102. THREE.BufferGeometryLoader = function ( manager ) {
  11103. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11104. };
  11105. THREE.BufferGeometryLoader.prototype = {
  11106. constructor: THREE.BufferGeometryLoader,
  11107. load: function ( url, onLoad, onProgress, onError ) {
  11108. var scope = this;
  11109. var loader = new THREE.XHRLoader( scope.manager );
  11110. loader.load( url, function ( text ) {
  11111. onLoad( scope.parse( JSON.parse( text ) ) );
  11112. }, onProgress, onError );
  11113. },
  11114. parse: function ( json ) {
  11115. var geometry = new THREE.BufferGeometry();
  11116. var index = json.data.index;
  11117. var TYPED_ARRAYS = {
  11118. 'Int8Array': Int8Array,
  11119. 'Uint8Array': Uint8Array,
  11120. 'Uint8ClampedArray': Uint8ClampedArray,
  11121. 'Int16Array': Int16Array,
  11122. 'Uint16Array': Uint16Array,
  11123. 'Int32Array': Int32Array,
  11124. 'Uint32Array': Uint32Array,
  11125. 'Float32Array': Float32Array,
  11126. 'Float64Array': Float64Array
  11127. };
  11128. if ( index !== undefined ) {
  11129. var typedArray = new TYPED_ARRAYS[ index.type ]( index.array );
  11130. geometry.setIndex( new THREE.BufferAttribute( typedArray, 1 ) );
  11131. }
  11132. var attributes = json.data.attributes;
  11133. for ( var key in attributes ) {
  11134. var attribute = attributes[ key ];
  11135. var typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
  11136. geometry.addAttribute( key, new THREE.BufferAttribute( typedArray, attribute.itemSize ) );
  11137. }
  11138. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  11139. if ( groups !== undefined ) {
  11140. for ( var i = 0, n = groups.length; i !== n; ++ i ) {
  11141. var group = groups[ i ];
  11142. geometry.addGroup( group.start, group.count, group.materialIndex );
  11143. }
  11144. }
  11145. var boundingSphere = json.data.boundingSphere;
  11146. if ( boundingSphere !== undefined ) {
  11147. var center = new THREE.Vector3();
  11148. if ( boundingSphere.center !== undefined ) {
  11149. center.fromArray( boundingSphere.center );
  11150. }
  11151. geometry.boundingSphere = new THREE.Sphere( center, boundingSphere.radius );
  11152. }
  11153. return geometry;
  11154. }
  11155. };
  11156. // File:src/loaders/MaterialLoader.js
  11157. /**
  11158. * @author mrdoob / http://mrdoob.com/
  11159. */
  11160. THREE.MaterialLoader = function ( manager ) {
  11161. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11162. this.textures = {};
  11163. };
  11164. THREE.MaterialLoader.prototype = {
  11165. constructor: THREE.MaterialLoader,
  11166. load: function ( url, onLoad, onProgress, onError ) {
  11167. var scope = this;
  11168. var loader = new THREE.XHRLoader( scope.manager );
  11169. loader.load( url, function ( text ) {
  11170. onLoad( scope.parse( JSON.parse( text ) ) );
  11171. }, onProgress, onError );
  11172. },
  11173. setTextures: function ( value ) {
  11174. this.textures = value;
  11175. },
  11176. getTexture: function ( name ) {
  11177. var textures = this.textures;
  11178. if ( textures[ name ] === undefined ) {
  11179. console.warn( 'THREE.MaterialLoader: Undefined texture', name );
  11180. }
  11181. return textures[ name ];
  11182. },
  11183. parse: function ( json ) {
  11184. var material = new THREE[ json.type ];
  11185. if ( json.uuid !== undefined ) material.uuid = json.uuid;
  11186. if ( json.name !== undefined ) material.name = json.name;
  11187. if ( json.color !== undefined ) material.color.setHex( json.color );
  11188. if ( json.roughness !== undefined ) material.roughness = json.roughness;
  11189. if ( json.metalness !== undefined ) material.metalness = json.metalness;
  11190. if ( json.emissive !== undefined ) material.emissive.setHex( json.emissive );
  11191. if ( json.specular !== undefined ) material.specular.setHex( json.specular );
  11192. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  11193. if ( json.uniforms !== undefined ) material.uniforms = json.uniforms;
  11194. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  11195. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  11196. if ( json.vertexColors !== undefined ) material.vertexColors = json.vertexColors;
  11197. if ( json.shading !== undefined ) material.shading = json.shading;
  11198. if ( json.blending !== undefined ) material.blending = json.blending;
  11199. if ( json.side !== undefined ) material.side = json.side;
  11200. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  11201. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  11202. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  11203. if ( json.depthTest !== undefined ) material.depthTest = json.depthTest;
  11204. if ( json.depthWrite !== undefined ) material.depthWrite = json.depthWrite;
  11205. if ( json.colorWrite !== undefined ) material.colorWrite = json.colorWrite;
  11206. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  11207. if ( json.wireframeLinewidth !== undefined ) material.wireframeLinewidth = json.wireframeLinewidth;
  11208. // for PointsMaterial
  11209. if ( json.size !== undefined ) material.size = json.size;
  11210. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  11211. // maps
  11212. if ( json.map !== undefined ) material.map = this.getTexture( json.map );
  11213. if ( json.alphaMap !== undefined ) {
  11214. material.alphaMap = this.getTexture( json.alphaMap );
  11215. material.transparent = true;
  11216. }
  11217. if ( json.bumpMap !== undefined ) material.bumpMap = this.getTexture( json.bumpMap );
  11218. if ( json.bumpScale !== undefined ) material.bumpScale = json.bumpScale;
  11219. if ( json.normalMap !== undefined ) material.normalMap = this.getTexture( json.normalMap );
  11220. if ( json.normalScale !== undefined ) {
  11221. var normalScale = json.normalScale;
  11222. if ( Array.isArray( normalScale ) === false ) {
  11223. // Blender exporter used to export a scalar. See #7459
  11224. normalScale = [ normalScale, normalScale ];
  11225. }
  11226. material.normalScale = new THREE.Vector2().fromArray( normalScale );
  11227. }
  11228. if ( json.displacementMap !== undefined ) material.displacementMap = this.getTexture( json.displacementMap );
  11229. if ( json.displacementScale !== undefined ) material.displacementScale = json.displacementScale;
  11230. if ( json.displacementBias !== undefined ) material.displacementBias = json.displacementBias;
  11231. if ( json.roughnessMap !== undefined ) material.roughnessMap = this.getTexture( json.roughnessMap );
  11232. if ( json.metalnessMap !== undefined ) material.metalnessMap = this.getTexture( json.metalnessMap );
  11233. if ( json.emissiveMap !== undefined ) material.emissiveMap = this.getTexture( json.emissiveMap );
  11234. if ( json.emissiveIntensity !== undefined ) material.emissiveIntensity = json.emissiveIntensity;
  11235. if ( json.specularMap !== undefined ) material.specularMap = this.getTexture( json.specularMap );
  11236. if ( json.envMap !== undefined ) {
  11237. material.envMap = this.getTexture( json.envMap );
  11238. material.combine = THREE.MultiplyOperation;
  11239. }
  11240. if ( json.reflectivity ) material.reflectivity = json.reflectivity;
  11241. if ( json.lightMap !== undefined ) material.lightMap = this.getTexture( json.lightMap );
  11242. if ( json.lightMapIntensity !== undefined ) material.lightMapIntensity = json.lightMapIntensity;
  11243. if ( json.aoMap !== undefined ) material.aoMap = this.getTexture( json.aoMap );
  11244. if ( json.aoMapIntensity !== undefined ) material.aoMapIntensity = json.aoMapIntensity;
  11245. // MultiMaterial
  11246. if ( json.materials !== undefined ) {
  11247. for ( var i = 0, l = json.materials.length; i < l; i ++ ) {
  11248. material.materials.push( this.parse( json.materials[ i ] ) );
  11249. }
  11250. }
  11251. return material;
  11252. }
  11253. };
  11254. // File:src/loaders/ObjectLoader.js
  11255. /**
  11256. * @author mrdoob / http://mrdoob.com/
  11257. */
  11258. THREE.ObjectLoader = function ( manager ) {
  11259. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11260. this.texturePath = '';
  11261. };
  11262. THREE.ObjectLoader.prototype = {
  11263. constructor: THREE.ObjectLoader,
  11264. load: function ( url, onLoad, onProgress, onError ) {
  11265. if ( this.texturePath === '' ) {
  11266. this.texturePath = url.substring( 0, url.lastIndexOf( '/' ) + 1 );
  11267. }
  11268. var scope = this;
  11269. var loader = new THREE.XHRLoader( scope.manager );
  11270. loader.load( url, function ( text ) {
  11271. scope.parse( JSON.parse( text ), onLoad );
  11272. }, onProgress, onError );
  11273. },
  11274. setTexturePath: function ( value ) {
  11275. this.texturePath = value;
  11276. },
  11277. setCrossOrigin: function ( value ) {
  11278. this.crossOrigin = value;
  11279. },
  11280. parse: function ( json, onLoad ) {
  11281. var geometries = this.parseGeometries( json.geometries );
  11282. var images = this.parseImages( json.images, function () {
  11283. if ( onLoad !== undefined ) onLoad( object );
  11284. } );
  11285. var textures = this.parseTextures( json.textures, images );
  11286. var materials = this.parseMaterials( json.materials, textures );
  11287. var object = this.parseObject( json.object, geometries, materials );
  11288. if ( json.animations ) {
  11289. object.animations = this.parseAnimations( json.animations );
  11290. }
  11291. if ( json.images === undefined || json.images.length === 0 ) {
  11292. if ( onLoad !== undefined ) onLoad( object );
  11293. }
  11294. return object;
  11295. },
  11296. parseGeometries: function ( json ) {
  11297. var geometries = {};
  11298. if ( json !== undefined ) {
  11299. var geometryLoader = new THREE.JSONLoader();
  11300. var bufferGeometryLoader = new THREE.BufferGeometryLoader();
  11301. for ( var i = 0, l = json.length; i < l; i ++ ) {
  11302. var geometry;
  11303. var data = json[ i ];
  11304. switch ( data.type ) {
  11305. case 'PlaneGeometry':
  11306. case 'PlaneBufferGeometry':
  11307. geometry = new THREE[ data.type ](
  11308. data.width,
  11309. data.height,
  11310. data.widthSegments,
  11311. data.heightSegments
  11312. );
  11313. break;
  11314. case 'BoxGeometry':
  11315. case 'BoxBufferGeometry':
  11316. case 'CubeGeometry': // backwards compatible
  11317. geometry = new THREE[ data.type ](
  11318. data.width,
  11319. data.height,
  11320. data.depth,
  11321. data.widthSegments,
  11322. data.heightSegments,
  11323. data.depthSegments
  11324. );
  11325. break;
  11326. case 'CircleGeometry':
  11327. case 'CircleBufferGeometry':
  11328. geometry = new THREE[ data.type ](
  11329. data.radius,
  11330. data.segments,
  11331. data.thetaStart,
  11332. data.thetaLength
  11333. );
  11334. break;
  11335. case 'CylinderGeometry':
  11336. case 'CylinderBufferGeometry':
  11337. geometry = new THREE[ data.type ](
  11338. data.radiusTop,
  11339. data.radiusBottom,
  11340. data.height,
  11341. data.radialSegments,
  11342. data.heightSegments,
  11343. data.openEnded,
  11344. data.thetaStart,
  11345. data.thetaLength
  11346. );
  11347. break;
  11348. case 'SphereGeometry':
  11349. case 'SphereBufferGeometry':
  11350. geometry = new THREE[ data.type ](
  11351. data.radius,
  11352. data.widthSegments,
  11353. data.heightSegments,
  11354. data.phiStart,
  11355. data.phiLength,
  11356. data.thetaStart,
  11357. data.thetaLength
  11358. );
  11359. break;
  11360. case 'DodecahedronGeometry':
  11361. geometry = new THREE.DodecahedronGeometry(
  11362. data.radius,
  11363. data.detail
  11364. );
  11365. break;
  11366. case 'IcosahedronGeometry':
  11367. geometry = new THREE.IcosahedronGeometry(
  11368. data.radius,
  11369. data.detail
  11370. );
  11371. break;
  11372. case 'OctahedronGeometry':
  11373. geometry = new THREE.OctahedronGeometry(
  11374. data.radius,
  11375. data.detail
  11376. );
  11377. break;
  11378. case 'TetrahedronGeometry':
  11379. geometry = new THREE.TetrahedronGeometry(
  11380. data.radius,
  11381. data.detail
  11382. );
  11383. break;
  11384. case 'RingGeometry':
  11385. case 'RingBufferGeometry':
  11386. geometry = new THREE[ data.type ](
  11387. data.innerRadius,
  11388. data.outerRadius,
  11389. data.thetaSegments,
  11390. data.phiSegments,
  11391. data.thetaStart,
  11392. data.thetaLength
  11393. );
  11394. break;
  11395. case 'TorusGeometry':
  11396. case 'TorusBufferGeometry':
  11397. geometry = new THREE[ data.type ](
  11398. data.radius,
  11399. data.tube,
  11400. data.radialSegments,
  11401. data.tubularSegments,
  11402. data.arc
  11403. );
  11404. break;
  11405. case 'TorusKnotGeometry':
  11406. case 'TorusKnotBufferGeometry':
  11407. geometry = new THREE[ data.type ](
  11408. data.radius,
  11409. data.tube,
  11410. data.tubularSegments,
  11411. data.radialSegments,
  11412. data.p,
  11413. data.q
  11414. );
  11415. break;
  11416. case 'LatheGeometry':
  11417. case 'LatheBufferGeometry':
  11418. geometry = new THREE[ data.type ](
  11419. data.points,
  11420. data.segments,
  11421. data.phiStart,
  11422. data.phiLength
  11423. );
  11424. break;
  11425. case 'BufferGeometry':
  11426. geometry = bufferGeometryLoader.parse( data );
  11427. break;
  11428. case 'Geometry':
  11429. geometry = geometryLoader.parse( data.data, this.texturePath ).geometry;
  11430. break;
  11431. default:
  11432. console.warn( 'THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"' );
  11433. continue;
  11434. }
  11435. geometry.uuid = data.uuid;
  11436. if ( data.name !== undefined ) geometry.name = data.name;
  11437. geometries[ data.uuid ] = geometry;
  11438. }
  11439. }
  11440. return geometries;
  11441. },
  11442. parseMaterials: function ( json, textures ) {
  11443. var materials = {};
  11444. if ( json !== undefined ) {
  11445. var loader = new THREE.MaterialLoader();
  11446. loader.setTextures( textures );
  11447. for ( var i = 0, l = json.length; i < l; i ++ ) {
  11448. var material = loader.parse( json[ i ] );
  11449. materials[ material.uuid ] = material;
  11450. }
  11451. }
  11452. return materials;
  11453. },
  11454. parseAnimations: function ( json ) {
  11455. var animations = [];
  11456. for ( var i = 0; i < json.length; i ++ ) {
  11457. var clip = THREE.AnimationClip.parse( json[ i ] );
  11458. animations.push( clip );
  11459. }
  11460. return animations;
  11461. },
  11462. parseImages: function ( json, onLoad ) {
  11463. var scope = this;
  11464. var images = {};
  11465. function loadImage( url ) {
  11466. scope.manager.itemStart( url );
  11467. return loader.load( url, function () {
  11468. scope.manager.itemEnd( url );
  11469. } );
  11470. }
  11471. if ( json !== undefined && json.length > 0 ) {
  11472. var manager = new THREE.LoadingManager( onLoad );
  11473. var loader = new THREE.ImageLoader( manager );
  11474. loader.setCrossOrigin( this.crossOrigin );
  11475. for ( var i = 0, l = json.length; i < l; i ++ ) {
  11476. var image = json[ i ];
  11477. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( image.url ) ? image.url : scope.texturePath + image.url;
  11478. images[ image.uuid ] = loadImage( path );
  11479. }
  11480. }
  11481. return images;
  11482. },
  11483. parseTextures: function ( json, images ) {
  11484. function parseConstant( value ) {
  11485. if ( typeof( value ) === 'number' ) return value;
  11486. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  11487. return THREE[ value ];
  11488. }
  11489. var textures = {};
  11490. if ( json !== undefined ) {
  11491. for ( var i = 0, l = json.length; i < l; i ++ ) {
  11492. var data = json[ i ];
  11493. if ( data.image === undefined ) {
  11494. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  11495. }
  11496. if ( images[ data.image ] === undefined ) {
  11497. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  11498. }
  11499. var texture = new THREE.Texture( images[ data.image ] );
  11500. texture.needsUpdate = true;
  11501. texture.uuid = data.uuid;
  11502. if ( data.name !== undefined ) texture.name = data.name;
  11503. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping );
  11504. if ( data.offset !== undefined ) texture.offset = new THREE.Vector2( data.offset[ 0 ], data.offset[ 1 ] );
  11505. if ( data.repeat !== undefined ) texture.repeat = new THREE.Vector2( data.repeat[ 0 ], data.repeat[ 1 ] );
  11506. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter );
  11507. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter );
  11508. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  11509. if ( Array.isArray( data.wrap ) ) {
  11510. texture.wrapS = parseConstant( data.wrap[ 0 ] );
  11511. texture.wrapT = parseConstant( data.wrap[ 1 ] );
  11512. }
  11513. textures[ data.uuid ] = texture;
  11514. }
  11515. }
  11516. return textures;
  11517. },
  11518. parseObject: function () {
  11519. var matrix = new THREE.Matrix4();
  11520. return function ( data, geometries, materials ) {
  11521. var object;
  11522. function getGeometry( name ) {
  11523. if ( geometries[ name ] === undefined ) {
  11524. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  11525. }
  11526. return geometries[ name ];
  11527. }
  11528. function getMaterial( name ) {
  11529. if ( name === undefined ) return undefined;
  11530. if ( materials[ name ] === undefined ) {
  11531. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  11532. }
  11533. return materials[ name ];
  11534. }
  11535. switch ( data.type ) {
  11536. case 'Scene':
  11537. object = new THREE.Scene();
  11538. break;
  11539. case 'PerspectiveCamera':
  11540. object = new THREE.PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  11541. break;
  11542. case 'OrthographicCamera':
  11543. object = new THREE.OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  11544. break;
  11545. case 'AmbientLight':
  11546. object = new THREE.AmbientLight( data.color, data.intensity );
  11547. break;
  11548. case 'DirectionalLight':
  11549. object = new THREE.DirectionalLight( data.color, data.intensity );
  11550. break;
  11551. case 'PointLight':
  11552. object = new THREE.PointLight( data.color, data.intensity, data.distance, data.decay );
  11553. break;
  11554. case 'SpotLight':
  11555. object = new THREE.SpotLight( data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay );
  11556. break;
  11557. case 'HemisphereLight':
  11558. object = new THREE.HemisphereLight( data.color, data.groundColor, data.intensity );
  11559. break;
  11560. case 'Mesh':
  11561. var geometry = getGeometry( data.geometry );
  11562. var material = getMaterial( data.material );
  11563. if ( geometry.bones && geometry.bones.length > 0 ) {
  11564. object = new THREE.SkinnedMesh( geometry, material );
  11565. } else {
  11566. object = new THREE.Mesh( geometry, material );
  11567. }
  11568. break;
  11569. case 'LOD':
  11570. object = new THREE.LOD();
  11571. break;
  11572. case 'Line':
  11573. object = new THREE.Line( getGeometry( data.geometry ), getMaterial( data.material ), data.mode );
  11574. break;
  11575. case 'PointCloud':
  11576. case 'Points':
  11577. object = new THREE.Points( getGeometry( data.geometry ), getMaterial( data.material ) );
  11578. break;
  11579. case 'Sprite':
  11580. object = new THREE.Sprite( getMaterial( data.material ) );
  11581. break;
  11582. case 'Group':
  11583. object = new THREE.Group();
  11584. break;
  11585. default:
  11586. object = new THREE.Object3D();
  11587. }
  11588. object.uuid = data.uuid;
  11589. if ( data.name !== undefined ) object.name = data.name;
  11590. if ( data.matrix !== undefined ) {
  11591. matrix.fromArray( data.matrix );
  11592. matrix.decompose( object.position, object.quaternion, object.scale );
  11593. } else {
  11594. if ( data.position !== undefined ) object.position.fromArray( data.position );
  11595. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  11596. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  11597. }
  11598. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  11599. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  11600. if ( data.visible !== undefined ) object.visible = data.visible;
  11601. if ( data.userData !== undefined ) object.userData = data.userData;
  11602. if ( data.children !== undefined ) {
  11603. for ( var child in data.children ) {
  11604. object.add( this.parseObject( data.children[ child ], geometries, materials ) );
  11605. }
  11606. }
  11607. if ( data.type === 'LOD' ) {
  11608. var levels = data.levels;
  11609. for ( var l = 0; l < levels.length; l ++ ) {
  11610. var level = levels[ l ];
  11611. var child = object.getObjectByProperty( 'uuid', level.object );
  11612. if ( child !== undefined ) {
  11613. object.addLevel( child, level.distance );
  11614. }
  11615. }
  11616. }
  11617. return object;
  11618. };
  11619. }()
  11620. };
  11621. // File:src/loaders/TextureLoader.js
  11622. /**
  11623. * @author mrdoob / http://mrdoob.com/
  11624. */
  11625. THREE.TextureLoader = function ( manager ) {
  11626. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11627. };
  11628. THREE.TextureLoader.prototype = {
  11629. constructor: THREE.TextureLoader,
  11630. load: function ( url, onLoad, onProgress, onError ) {
  11631. var texture = new THREE.Texture();
  11632. var loader = new THREE.ImageLoader( this.manager );
  11633. loader.setCrossOrigin( this.crossOrigin );
  11634. loader.setPath( this.path );
  11635. loader.load( url, function ( image ) {
  11636. texture.image = image;
  11637. texture.needsUpdate = true;
  11638. if ( onLoad !== undefined ) {
  11639. onLoad( texture );
  11640. }
  11641. }, onProgress, onError );
  11642. return texture;
  11643. },
  11644. setCrossOrigin: function ( value ) {
  11645. this.crossOrigin = value;
  11646. },
  11647. setPath: function ( value ) {
  11648. this.path = value;
  11649. }
  11650. };
  11651. // File:src/loaders/CubeTextureLoader.js
  11652. /**
  11653. * @author mrdoob / http://mrdoob.com/
  11654. */
  11655. THREE.CubeTextureLoader = function ( manager ) {
  11656. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11657. };
  11658. THREE.CubeTextureLoader.prototype = {
  11659. constructor: THREE.CubeTextureLoader,
  11660. load: function ( urls, onLoad, onProgress, onError ) {
  11661. var texture = new THREE.CubeTexture();
  11662. var loader = new THREE.ImageLoader( this.manager );
  11663. loader.setCrossOrigin( this.crossOrigin );
  11664. loader.setPath( this.path );
  11665. var loaded = 0;
  11666. function loadTexture( i ) {
  11667. loader.load( urls[ i ], function ( image ) {
  11668. texture.images[ i ] = image;
  11669. loaded ++;
  11670. if ( loaded === 6 ) {
  11671. texture.needsUpdate = true;
  11672. if ( onLoad ) onLoad( texture );
  11673. }
  11674. }, undefined, onError );
  11675. }
  11676. for ( var i = 0; i < urls.length; ++ i ) {
  11677. loadTexture( i );
  11678. }
  11679. return texture;
  11680. },
  11681. setCrossOrigin: function ( value ) {
  11682. this.crossOrigin = value;
  11683. },
  11684. setPath: function ( value ) {
  11685. this.path = value;
  11686. }
  11687. };
  11688. // File:src/loaders/BinaryTextureLoader.js
  11689. /**
  11690. * @author Nikos M. / https://github.com/foo123/
  11691. *
  11692. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  11693. */
  11694. THREE.DataTextureLoader = THREE.BinaryTextureLoader = function ( manager ) {
  11695. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11696. // override in sub classes
  11697. this._parser = null;
  11698. };
  11699. THREE.BinaryTextureLoader.prototype = {
  11700. constructor: THREE.BinaryTextureLoader,
  11701. load: function ( url, onLoad, onProgress, onError ) {
  11702. var scope = this;
  11703. var texture = new THREE.DataTexture();
  11704. var loader = new THREE.XHRLoader( this.manager );
  11705. loader.setResponseType( 'arraybuffer' );
  11706. loader.load( url, function ( buffer ) {
  11707. var texData = scope._parser( buffer );
  11708. if ( ! texData ) return;
  11709. if ( undefined !== texData.image ) {
  11710. texture.image = texData.image;
  11711. } else if ( undefined !== texData.data ) {
  11712. texture.image.width = texData.width;
  11713. texture.image.height = texData.height;
  11714. texture.image.data = texData.data;
  11715. }
  11716. texture.wrapS = undefined !== texData.wrapS ? texData.wrapS : THREE.ClampToEdgeWrapping;
  11717. texture.wrapT = undefined !== texData.wrapT ? texData.wrapT : THREE.ClampToEdgeWrapping;
  11718. texture.magFilter = undefined !== texData.magFilter ? texData.magFilter : THREE.LinearFilter;
  11719. texture.minFilter = undefined !== texData.minFilter ? texData.minFilter : THREE.LinearMipMapLinearFilter;
  11720. texture.anisotropy = undefined !== texData.anisotropy ? texData.anisotropy : 1;
  11721. if ( undefined !== texData.format ) {
  11722. texture.format = texData.format;
  11723. }
  11724. if ( undefined !== texData.type ) {
  11725. texture.type = texData.type;
  11726. }
  11727. if ( undefined !== texData.mipmaps ) {
  11728. texture.mipmaps = texData.mipmaps;
  11729. }
  11730. if ( 1 === texData.mipmapCount ) {
  11731. texture.minFilter = THREE.LinearFilter;
  11732. }
  11733. texture.needsUpdate = true;
  11734. if ( onLoad ) onLoad( texture, texData );
  11735. }, onProgress, onError );
  11736. return texture;
  11737. }
  11738. };
  11739. // File:src/loaders/CompressedTextureLoader.js
  11740. /**
  11741. * @author mrdoob / http://mrdoob.com/
  11742. *
  11743. * Abstract Base class to block based textures loader (dds, pvr, ...)
  11744. */
  11745. THREE.CompressedTextureLoader = function ( manager ) {
  11746. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11747. // override in sub classes
  11748. this._parser = null;
  11749. };
  11750. THREE.CompressedTextureLoader.prototype = {
  11751. constructor: THREE.CompressedTextureLoader,
  11752. load: function ( url, onLoad, onProgress, onError ) {
  11753. var scope = this;
  11754. var images = [];
  11755. var texture = new THREE.CompressedTexture();
  11756. texture.image = images;
  11757. var loader = new THREE.XHRLoader( this.manager );
  11758. loader.setPath( this.path );
  11759. loader.setResponseType( 'arraybuffer' );
  11760. function loadTexture( i ) {
  11761. loader.load( url[ i ], function ( buffer ) {
  11762. var texDatas = scope._parser( buffer, true );
  11763. images[ i ] = {
  11764. width: texDatas.width,
  11765. height: texDatas.height,
  11766. format: texDatas.format,
  11767. mipmaps: texDatas.mipmaps
  11768. };
  11769. loaded += 1;
  11770. if ( loaded === 6 ) {
  11771. if ( texDatas.mipmapCount === 1 )
  11772. texture.minFilter = THREE.LinearFilter;
  11773. texture.format = texDatas.format;
  11774. texture.needsUpdate = true;
  11775. if ( onLoad ) onLoad( texture );
  11776. }
  11777. }, onProgress, onError );
  11778. }
  11779. if ( Array.isArray( url ) ) {
  11780. var loaded = 0;
  11781. for ( var i = 0, il = url.length; i < il; ++ i ) {
  11782. loadTexture( i );
  11783. }
  11784. } else {
  11785. // compressed cubemap texture stored in a single DDS file
  11786. loader.load( url, function ( buffer ) {
  11787. var texDatas = scope._parser( buffer, true );
  11788. if ( texDatas.isCubemap ) {
  11789. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  11790. for ( var f = 0; f < faces; f ++ ) {
  11791. images[ f ] = { mipmaps : [] };
  11792. for ( var i = 0; i < texDatas.mipmapCount; i ++ ) {
  11793. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  11794. images[ f ].format = texDatas.format;
  11795. images[ f ].width = texDatas.width;
  11796. images[ f ].height = texDatas.height;
  11797. }
  11798. }
  11799. } else {
  11800. texture.image.width = texDatas.width;
  11801. texture.image.height = texDatas.height;
  11802. texture.mipmaps = texDatas.mipmaps;
  11803. }
  11804. if ( texDatas.mipmapCount === 1 ) {
  11805. texture.minFilter = THREE.LinearFilter;
  11806. }
  11807. texture.format = texDatas.format;
  11808. texture.needsUpdate = true;
  11809. if ( onLoad ) onLoad( texture );
  11810. }, onProgress, onError );
  11811. }
  11812. return texture;
  11813. },
  11814. setPath: function ( value ) {
  11815. this.path = value;
  11816. }
  11817. };
  11818. // File:src/materials/Material.js
  11819. /**
  11820. * @author mrdoob / http://mrdoob.com/
  11821. * @author alteredq / http://alteredqualia.com/
  11822. */
  11823. THREE.Material = function () {
  11824. Object.defineProperty( this, 'id', { value: THREE.MaterialIdCount ++ } );
  11825. this.uuid = THREE.Math.generateUUID();
  11826. this.name = '';
  11827. this.type = 'Material';
  11828. this.side = THREE.FrontSide;
  11829. this.opacity = 1;
  11830. this.transparent = false;
  11831. this.blending = THREE.NormalBlending;
  11832. this.blendSrc = THREE.SrcAlphaFactor;
  11833. this.blendDst = THREE.OneMinusSrcAlphaFactor;
  11834. this.blendEquation = THREE.AddEquation;
  11835. this.blendSrcAlpha = null;
  11836. this.blendDstAlpha = null;
  11837. this.blendEquationAlpha = null;
  11838. this.depthFunc = THREE.LessEqualDepth;
  11839. this.depthTest = true;
  11840. this.depthWrite = true;
  11841. this.colorWrite = true;
  11842. this.precision = null; // override the renderer's default precision for this material
  11843. this.polygonOffset = false;
  11844. this.polygonOffsetFactor = 0;
  11845. this.polygonOffsetUnits = 0;
  11846. this.alphaTest = 0;
  11847. this.premultipliedAlpha = false;
  11848. this.overdraw = 0; // Overdrawn pixels (typically between 0 and 1) for fixing antialiasing gaps in CanvasRenderer
  11849. this.visible = true;
  11850. this._needsUpdate = true;
  11851. };
  11852. THREE.Material.prototype = {
  11853. constructor: THREE.Material,
  11854. get needsUpdate () {
  11855. return this._needsUpdate;
  11856. },
  11857. set needsUpdate ( value ) {
  11858. if ( value === true ) this.update();
  11859. this._needsUpdate = value;
  11860. },
  11861. setValues: function ( values ) {
  11862. if ( values === undefined ) return;
  11863. for ( var key in values ) {
  11864. var newValue = values[ key ];
  11865. if ( newValue === undefined ) {
  11866. console.warn( "THREE.Material: '" + key + "' parameter is undefined." );
  11867. continue;
  11868. }
  11869. var currentValue = this[ key ];
  11870. if ( currentValue === undefined ) {
  11871. console.warn( "THREE." + this.type + ": '" + key + "' is not a property of this material." );
  11872. continue;
  11873. }
  11874. if ( currentValue instanceof THREE.Color ) {
  11875. currentValue.set( newValue );
  11876. } else if ( currentValue instanceof THREE.Vector3 && newValue instanceof THREE.Vector3 ) {
  11877. currentValue.copy( newValue );
  11878. } else if ( key === 'overdraw' ) {
  11879. // ensure overdraw is backwards-compatible with legacy boolean type
  11880. this[ key ] = Number( newValue );
  11881. } else {
  11882. this[ key ] = newValue;
  11883. }
  11884. }
  11885. },
  11886. toJSON: function ( meta ) {
  11887. var isRoot = meta === undefined;
  11888. if ( isRoot ) {
  11889. meta = {
  11890. textures: {},
  11891. images: {}
  11892. };
  11893. }
  11894. var data = {
  11895. metadata: {
  11896. version: 4.4,
  11897. type: 'Material',
  11898. generator: 'Material.toJSON'
  11899. }
  11900. };
  11901. // standard Material serialization
  11902. data.uuid = this.uuid;
  11903. data.type = this.type;
  11904. if ( this.name !== '' ) data.name = this.name;
  11905. if ( this.color instanceof THREE.Color ) data.color = this.color.getHex();
  11906. if ( this.roughness !== 0.5 ) data.roughness = this.roughness;
  11907. if ( this.metalness !== 0.5 ) data.metalness = this.metalness;
  11908. if ( this.emissive instanceof THREE.Color ) data.emissive = this.emissive.getHex();
  11909. if ( this.specular instanceof THREE.Color ) data.specular = this.specular.getHex();
  11910. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  11911. if ( this.map instanceof THREE.Texture ) data.map = this.map.toJSON( meta ).uuid;
  11912. if ( this.alphaMap instanceof THREE.Texture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  11913. if ( this.lightMap instanceof THREE.Texture ) data.lightMap = this.lightMap.toJSON( meta ).uuid;
  11914. if ( this.bumpMap instanceof THREE.Texture ) {
  11915. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  11916. data.bumpScale = this.bumpScale;
  11917. }
  11918. if ( this.normalMap instanceof THREE.Texture ) {
  11919. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  11920. data.normalScale = this.normalScale.toArray();
  11921. }
  11922. if ( this.displacementMap instanceof THREE.Texture ) {
  11923. data.displacementMap = this.displacementMap.toJSON( meta ).uuid;
  11924. data.displacementScale = this.displacementScale;
  11925. data.displacementBias = this.displacementBias;
  11926. }
  11927. if ( this.roughnessMap instanceof THREE.Texture ) data.roughnessMap = this.roughnessMap.toJSON( meta ).uuid;
  11928. if ( this.metalnessMap instanceof THREE.Texture ) data.metalnessMap = this.metalnessMap.toJSON( meta ).uuid;
  11929. if ( this.emissiveMap instanceof THREE.Texture ) data.emissiveMap = this.emissiveMap.toJSON( meta ).uuid;
  11930. if ( this.specularMap instanceof THREE.Texture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  11931. if ( this.envMap instanceof THREE.Texture ) {
  11932. data.envMap = this.envMap.toJSON( meta ).uuid;
  11933. data.reflectivity = this.reflectivity; // Scale behind envMap
  11934. }
  11935. if ( this.size !== undefined ) data.size = this.size;
  11936. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  11937. if ( this.vertexColors !== undefined && this.vertexColors !== THREE.NoColors ) data.vertexColors = this.vertexColors;
  11938. if ( this.shading !== undefined && this.shading !== THREE.SmoothShading ) data.shading = this.shading;
  11939. if ( this.blending !== undefined && this.blending !== THREE.NormalBlending ) data.blending = this.blending;
  11940. if ( this.side !== undefined && this.side !== THREE.FrontSide ) data.side = this.side;
  11941. if ( this.opacity < 1 ) data.opacity = this.opacity;
  11942. if ( this.transparent === true ) data.transparent = this.transparent;
  11943. if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
  11944. if ( this.premultipliedAlpha === true ) data.premultipliedAlpha = this.premultipliedAlpha;
  11945. if ( this.wireframe === true ) data.wireframe = this.wireframe;
  11946. if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;
  11947. // TODO: Copied from Object3D.toJSON
  11948. function extractFromCache ( cache ) {
  11949. var values = [];
  11950. for ( var key in cache ) {
  11951. var data = cache[ key ];
  11952. delete data.metadata;
  11953. values.push( data );
  11954. }
  11955. return values;
  11956. }
  11957. if ( isRoot ) {
  11958. var textures = extractFromCache( meta.textures );
  11959. var images = extractFromCache( meta.images );
  11960. if ( textures.length > 0 ) data.textures = textures;
  11961. if ( images.length > 0 ) data.images = images;
  11962. }
  11963. return data;
  11964. },
  11965. clone: function () {
  11966. return new this.constructor().copy( this );
  11967. },
  11968. copy: function ( source ) {
  11969. this.name = source.name;
  11970. this.side = source.side;
  11971. this.opacity = source.opacity;
  11972. this.transparent = source.transparent;
  11973. this.blending = source.blending;
  11974. this.blendSrc = source.blendSrc;
  11975. this.blendDst = source.blendDst;
  11976. this.blendEquation = source.blendEquation;
  11977. this.blendSrcAlpha = source.blendSrcAlpha;
  11978. this.blendDstAlpha = source.blendDstAlpha;
  11979. this.blendEquationAlpha = source.blendEquationAlpha;
  11980. this.depthFunc = source.depthFunc;
  11981. this.depthTest = source.depthTest;
  11982. this.depthWrite = source.depthWrite;
  11983. this.colorWrite = source.colorWrite;
  11984. this.precision = source.precision;
  11985. this.polygonOffset = source.polygonOffset;
  11986. this.polygonOffsetFactor = source.polygonOffsetFactor;
  11987. this.polygonOffsetUnits = source.polygonOffsetUnits;
  11988. this.alphaTest = source.alphaTest;
  11989. this.premultipliedAlpha = source.premultipliedAlpha;
  11990. this.overdraw = source.overdraw;
  11991. this.visible = source.visible;
  11992. return this;
  11993. },
  11994. update: function () {
  11995. this.dispatchEvent( { type: 'update' } );
  11996. },
  11997. dispose: function () {
  11998. this.dispatchEvent( { type: 'dispose' } );
  11999. }
  12000. };
  12001. THREE.EventDispatcher.prototype.apply( THREE.Material.prototype );
  12002. THREE.MaterialIdCount = 0;
  12003. // File:src/materials/LineBasicMaterial.js
  12004. /**
  12005. * @author mrdoob / http://mrdoob.com/
  12006. * @author alteredq / http://alteredqualia.com/
  12007. *
  12008. * parameters = {
  12009. * color: <hex>,
  12010. * opacity: <float>,
  12011. *
  12012. * linewidth: <float>,
  12013. * linecap: "round",
  12014. * linejoin: "round",
  12015. *
  12016. * blending: THREE.NormalBlending,
  12017. * depthTest: <bool>,
  12018. * depthWrite: <bool>,
  12019. *
  12020. * vertexColors: <bool>
  12021. *
  12022. * fog: <bool>
  12023. * }
  12024. */
  12025. THREE.LineBasicMaterial = function ( parameters ) {
  12026. THREE.Material.call( this );
  12027. this.type = 'LineBasicMaterial';
  12028. this.color = new THREE.Color( 0xffffff );
  12029. this.linewidth = 1;
  12030. this.linecap = 'round';
  12031. this.linejoin = 'round';
  12032. this.blending = THREE.NormalBlending;
  12033. this.vertexColors = THREE.NoColors;
  12034. this.fog = true;
  12035. this.setValues( parameters );
  12036. };
  12037. THREE.LineBasicMaterial.prototype = Object.create( THREE.Material.prototype );
  12038. THREE.LineBasicMaterial.prototype.constructor = THREE.LineBasicMaterial;
  12039. THREE.LineBasicMaterial.prototype.copy = function ( source ) {
  12040. THREE.Material.prototype.copy.call( this, source );
  12041. this.color.copy( source.color );
  12042. this.linewidth = source.linewidth;
  12043. this.linecap = source.linecap;
  12044. this.linejoin = source.linejoin;
  12045. this.vertexColors = source.vertexColors;
  12046. this.fog = source.fog;
  12047. return this;
  12048. };
  12049. // File:src/materials/LineDashedMaterial.js
  12050. /**
  12051. * @author alteredq / http://alteredqualia.com/
  12052. *
  12053. * parameters = {
  12054. * color: <hex>,
  12055. * opacity: <float>,
  12056. *
  12057. * linewidth: <float>,
  12058. *
  12059. * scale: <float>,
  12060. * dashSize: <float>,
  12061. * gapSize: <float>,
  12062. *
  12063. * blending: THREE.NormalBlending,
  12064. * depthTest: <bool>,
  12065. * depthWrite: <bool>,
  12066. *
  12067. * vertexColors: THREE.NoColors / THREE.FaceColors / THREE.VertexColors
  12068. *
  12069. * fog: <bool>
  12070. * }
  12071. */
  12072. THREE.LineDashedMaterial = function ( parameters ) {
  12073. THREE.Material.call( this );
  12074. this.type = 'LineDashedMaterial';
  12075. this.color = new THREE.Color( 0xffffff );
  12076. this.linewidth = 1;
  12077. this.scale = 1;
  12078. this.dashSize = 3;
  12079. this.gapSize = 1;
  12080. this.blending = THREE.NormalBlending;
  12081. this.vertexColors = THREE.NoColors;
  12082. this.fog = true;
  12083. this.setValues( parameters );
  12084. };
  12085. THREE.LineDashedMaterial.prototype = Object.create( THREE.Material.prototype );
  12086. THREE.LineDashedMaterial.prototype.constructor = THREE.LineDashedMaterial;
  12087. THREE.LineDashedMaterial.prototype.copy = function ( source ) {
  12088. THREE.Material.prototype.copy.call( this, source );
  12089. this.color.copy( source.color );
  12090. this.linewidth = source.linewidth;
  12091. this.scale = source.scale;
  12092. this.dashSize = source.dashSize;
  12093. this.gapSize = source.gapSize;
  12094. this.vertexColors = source.vertexColors;
  12095. this.fog = source.fog;
  12096. return this;
  12097. };
  12098. // File:src/materials/MeshBasicMaterial.js
  12099. /**
  12100. * @author mrdoob / http://mrdoob.com/
  12101. * @author alteredq / http://alteredqualia.com/
  12102. *
  12103. * parameters = {
  12104. * color: <hex>,
  12105. * opacity: <float>,
  12106. * map: new THREE.Texture( <Image> ),
  12107. *
  12108. * aoMap: new THREE.Texture( <Image> ),
  12109. * aoMapIntensity: <float>
  12110. *
  12111. * specularMap: new THREE.Texture( <Image> ),
  12112. *
  12113. * alphaMap: new THREE.Texture( <Image> ),
  12114. *
  12115. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  12116. * combine: THREE.Multiply,
  12117. * reflectivity: <float>,
  12118. * refractionRatio: <float>,
  12119. *
  12120. * shading: THREE.SmoothShading,
  12121. * blending: THREE.NormalBlending,
  12122. * depthTest: <bool>,
  12123. * depthWrite: <bool>,
  12124. *
  12125. * wireframe: <boolean>,
  12126. * wireframeLinewidth: <float>,
  12127. *
  12128. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  12129. *
  12130. * skinning: <bool>,
  12131. * morphTargets: <bool>,
  12132. *
  12133. * fog: <bool>
  12134. * }
  12135. */
  12136. THREE.MeshBasicMaterial = function ( parameters ) {
  12137. THREE.Material.call( this );
  12138. this.type = 'MeshBasicMaterial';
  12139. this.color = new THREE.Color( 0xffffff ); // emissive
  12140. this.map = null;
  12141. this.aoMap = null;
  12142. this.aoMapIntensity = 1.0;
  12143. this.specularMap = null;
  12144. this.alphaMap = null;
  12145. this.envMap = null;
  12146. this.combine = THREE.MultiplyOperation;
  12147. this.reflectivity = 1;
  12148. this.refractionRatio = 0.98;
  12149. this.fog = true;
  12150. this.shading = THREE.SmoothShading;
  12151. this.blending = THREE.NormalBlending;
  12152. this.wireframe = false;
  12153. this.wireframeLinewidth = 1;
  12154. this.wireframeLinecap = 'round';
  12155. this.wireframeLinejoin = 'round';
  12156. this.vertexColors = THREE.NoColors;
  12157. this.skinning = false;
  12158. this.morphTargets = false;
  12159. this.setValues( parameters );
  12160. };
  12161. THREE.MeshBasicMaterial.prototype = Object.create( THREE.Material.prototype );
  12162. THREE.MeshBasicMaterial.prototype.constructor = THREE.MeshBasicMaterial;
  12163. THREE.MeshBasicMaterial.prototype.copy = function ( source ) {
  12164. THREE.Material.prototype.copy.call( this, source );
  12165. this.color.copy( source.color );
  12166. this.map = source.map;
  12167. this.aoMap = source.aoMap;
  12168. this.aoMapIntensity = source.aoMapIntensity;
  12169. this.specularMap = source.specularMap;
  12170. this.alphaMap = source.alphaMap;
  12171. this.envMap = source.envMap;
  12172. this.combine = source.combine;
  12173. this.reflectivity = source.reflectivity;
  12174. this.refractionRatio = source.refractionRatio;
  12175. this.fog = source.fog;
  12176. this.shading = source.shading;
  12177. this.wireframe = source.wireframe;
  12178. this.wireframeLinewidth = source.wireframeLinewidth;
  12179. this.wireframeLinecap = source.wireframeLinecap;
  12180. this.wireframeLinejoin = source.wireframeLinejoin;
  12181. this.vertexColors = source.vertexColors;
  12182. this.skinning = source.skinning;
  12183. this.morphTargets = source.morphTargets;
  12184. return this;
  12185. };
  12186. // File:src/materials/MeshLambertMaterial.js
  12187. /**
  12188. * @author mrdoob / http://mrdoob.com/
  12189. * @author alteredq / http://alteredqualia.com/
  12190. *
  12191. * parameters = {
  12192. * color: <hex>,
  12193. * opacity: <float>,
  12194. *
  12195. * map: new THREE.Texture( <Image> ),
  12196. *
  12197. * lightMap: new THREE.Texture( <Image> ),
  12198. * lightMapIntensity: <float>
  12199. *
  12200. * aoMap: new THREE.Texture( <Image> ),
  12201. * aoMapIntensity: <float>
  12202. *
  12203. * emissive: <hex>,
  12204. * emissiveIntensity: <float>
  12205. * emissiveMap: new THREE.Texture( <Image> ),
  12206. *
  12207. * specularMap: new THREE.Texture( <Image> ),
  12208. *
  12209. * alphaMap: new THREE.Texture( <Image> ),
  12210. *
  12211. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  12212. * combine: THREE.Multiply,
  12213. * reflectivity: <float>,
  12214. * refractionRatio: <float>,
  12215. *
  12216. * blending: THREE.NormalBlending,
  12217. * depthTest: <bool>,
  12218. * depthWrite: <bool>,
  12219. *
  12220. * wireframe: <boolean>,
  12221. * wireframeLinewidth: <float>,
  12222. *
  12223. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  12224. *
  12225. * skinning: <bool>,
  12226. * morphTargets: <bool>,
  12227. * morphNormals: <bool>,
  12228. *
  12229. * fog: <bool>
  12230. * }
  12231. */
  12232. THREE.MeshLambertMaterial = function ( parameters ) {
  12233. THREE.Material.call( this );
  12234. this.type = 'MeshLambertMaterial';
  12235. this.color = new THREE.Color( 0xffffff ); // diffuse
  12236. this.map = null;
  12237. this.lightMap = null;
  12238. this.lightMapIntensity = 1.0;
  12239. this.aoMap = null;
  12240. this.aoMapIntensity = 1.0;
  12241. this.emissive = new THREE.Color( 0x000000 );
  12242. this.emissiveIntensity = 1.0;
  12243. this.emissiveMap = null;
  12244. this.specularMap = null;
  12245. this.alphaMap = null;
  12246. this.envMap = null;
  12247. this.combine = THREE.MultiplyOperation;
  12248. this.reflectivity = 1;
  12249. this.refractionRatio = 0.98;
  12250. this.fog = true;
  12251. this.blending = THREE.NormalBlending;
  12252. this.wireframe = false;
  12253. this.wireframeLinewidth = 1;
  12254. this.wireframeLinecap = 'round';
  12255. this.wireframeLinejoin = 'round';
  12256. this.vertexColors = THREE.NoColors;
  12257. this.skinning = false;
  12258. this.morphTargets = false;
  12259. this.morphNormals = false;
  12260. this.setValues( parameters );
  12261. };
  12262. THREE.MeshLambertMaterial.prototype = Object.create( THREE.Material.prototype );
  12263. THREE.MeshLambertMaterial.prototype.constructor = THREE.MeshLambertMaterial;
  12264. THREE.MeshLambertMaterial.prototype.copy = function ( source ) {
  12265. THREE.Material.prototype.copy.call( this, source );
  12266. this.color.copy( source.color );
  12267. this.map = source.map;
  12268. this.lightMap = source.lightMap;
  12269. this.lightMapIntensity = source.lightMapIntensity;
  12270. this.aoMap = source.aoMap;
  12271. this.aoMapIntensity = source.aoMapIntensity;
  12272. this.emissive.copy( source.emissive );
  12273. this.emissiveMap = source.emissiveMap;
  12274. this.emissiveIntensity = source.emissiveIntensity;
  12275. this.specularMap = source.specularMap;
  12276. this.alphaMap = source.alphaMap;
  12277. this.envMap = source.envMap;
  12278. this.combine = source.combine;
  12279. this.reflectivity = source.reflectivity;
  12280. this.refractionRatio = source.refractionRatio;
  12281. this.fog = source.fog;
  12282. this.wireframe = source.wireframe;
  12283. this.wireframeLinewidth = source.wireframeLinewidth;
  12284. this.wireframeLinecap = source.wireframeLinecap;
  12285. this.wireframeLinejoin = source.wireframeLinejoin;
  12286. this.vertexColors = source.vertexColors;
  12287. this.skinning = source.skinning;
  12288. this.morphTargets = source.morphTargets;
  12289. this.morphNormals = source.morphNormals;
  12290. return this;
  12291. };
  12292. // File:src/materials/MeshPhongMaterial.js
  12293. /**
  12294. * @author mrdoob / http://mrdoob.com/
  12295. * @author alteredq / http://alteredqualia.com/
  12296. *
  12297. * parameters = {
  12298. * color: <hex>,
  12299. * specular: <hex>,
  12300. * shininess: <float>,
  12301. * opacity: <float>,
  12302. *
  12303. * map: new THREE.Texture( <Image> ),
  12304. *
  12305. * lightMap: new THREE.Texture( <Image> ),
  12306. * lightMapIntensity: <float>
  12307. *
  12308. * aoMap: new THREE.Texture( <Image> ),
  12309. * aoMapIntensity: <float>
  12310. *
  12311. * emissive: <hex>,
  12312. * emissiveIntensity: <float>
  12313. * emissiveMap: new THREE.Texture( <Image> ),
  12314. *
  12315. * bumpMap: new THREE.Texture( <Image> ),
  12316. * bumpScale: <float>,
  12317. *
  12318. * normalMap: new THREE.Texture( <Image> ),
  12319. * normalScale: <Vector2>,
  12320. *
  12321. * displacementMap: new THREE.Texture( <Image> ),
  12322. * displacementScale: <float>,
  12323. * displacementBias: <float>,
  12324. *
  12325. * specularMap: new THREE.Texture( <Image> ),
  12326. *
  12327. * alphaMap: new THREE.Texture( <Image> ),
  12328. *
  12329. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  12330. * combine: THREE.Multiply,
  12331. * reflectivity: <float>,
  12332. * refractionRatio: <float>,
  12333. *
  12334. * shading: THREE.SmoothShading,
  12335. * blending: THREE.NormalBlending,
  12336. * depthTest: <bool>,
  12337. * depthWrite: <bool>,
  12338. *
  12339. * wireframe: <boolean>,
  12340. * wireframeLinewidth: <float>,
  12341. *
  12342. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  12343. *
  12344. * skinning: <bool>,
  12345. * morphTargets: <bool>,
  12346. * morphNormals: <bool>,
  12347. *
  12348. * fog: <bool>
  12349. * }
  12350. */
  12351. THREE.MeshPhongMaterial = function ( parameters ) {
  12352. THREE.Material.call( this );
  12353. this.type = 'MeshPhongMaterial';
  12354. this.color = new THREE.Color( 0xffffff ); // diffuse
  12355. this.specular = new THREE.Color( 0x111111 );
  12356. this.shininess = 30;
  12357. this.map = null;
  12358. this.lightMap = null;
  12359. this.lightMapIntensity = 1.0;
  12360. this.aoMap = null;
  12361. this.aoMapIntensity = 1.0;
  12362. this.emissive = new THREE.Color( 0x000000 );
  12363. this.emissiveIntensity = 1.0;
  12364. this.emissiveMap = null;
  12365. this.bumpMap = null;
  12366. this.bumpScale = 1;
  12367. this.normalMap = null;
  12368. this.normalScale = new THREE.Vector2( 1, 1 );
  12369. this.displacementMap = null;
  12370. this.displacementScale = 1;
  12371. this.displacementBias = 0;
  12372. this.specularMap = null;
  12373. this.alphaMap = null;
  12374. this.envMap = null;
  12375. this.combine = THREE.MultiplyOperation;
  12376. this.reflectivity = 1;
  12377. this.refractionRatio = 0.98;
  12378. this.fog = true;
  12379. this.shading = THREE.SmoothShading;
  12380. this.blending = THREE.NormalBlending;
  12381. this.wireframe = false;
  12382. this.wireframeLinewidth = 1;
  12383. this.wireframeLinecap = 'round';
  12384. this.wireframeLinejoin = 'round';
  12385. this.vertexColors = THREE.NoColors;
  12386. this.skinning = false;
  12387. this.morphTargets = false;
  12388. this.morphNormals = false;
  12389. this.setValues( parameters );
  12390. };
  12391. THREE.MeshPhongMaterial.prototype = Object.create( THREE.Material.prototype );
  12392. THREE.MeshPhongMaterial.prototype.constructor = THREE.MeshPhongMaterial;
  12393. THREE.MeshPhongMaterial.prototype.copy = function ( source ) {
  12394. THREE.Material.prototype.copy.call( this, source );
  12395. this.color.copy( source.color );
  12396. this.specular.copy( source.specular );
  12397. this.shininess = source.shininess;
  12398. this.map = source.map;
  12399. this.lightMap = source.lightMap;
  12400. this.lightMapIntensity = source.lightMapIntensity;
  12401. this.aoMap = source.aoMap;
  12402. this.aoMapIntensity = source.aoMapIntensity;
  12403. this.emissive.copy( source.emissive );
  12404. this.emissiveMap = source.emissiveMap;
  12405. this.emissiveIntensity = source.emissiveIntensity;
  12406. this.bumpMap = source.bumpMap;
  12407. this.bumpScale = source.bumpScale;
  12408. this.normalMap = source.normalMap;
  12409. this.normalScale.copy( source.normalScale );
  12410. this.displacementMap = source.displacementMap;
  12411. this.displacementScale = source.displacementScale;
  12412. this.displacementBias = source.displacementBias;
  12413. this.specularMap = source.specularMap;
  12414. this.alphaMap = source.alphaMap;
  12415. this.envMap = source.envMap;
  12416. this.combine = source.combine;
  12417. this.reflectivity = source.reflectivity;
  12418. this.refractionRatio = source.refractionRatio;
  12419. this.fog = source.fog;
  12420. this.shading = source.shading;
  12421. this.wireframe = source.wireframe;
  12422. this.wireframeLinewidth = source.wireframeLinewidth;
  12423. this.wireframeLinecap = source.wireframeLinecap;
  12424. this.wireframeLinejoin = source.wireframeLinejoin;
  12425. this.vertexColors = source.vertexColors;
  12426. this.skinning = source.skinning;
  12427. this.morphTargets = source.morphTargets;
  12428. this.morphNormals = source.morphNormals;
  12429. return this;
  12430. };
  12431. // File:src/materials/MeshStandardMaterial.js
  12432. /**
  12433. * @author WestLangley / http://github.com/WestLangley
  12434. *
  12435. * parameters = {
  12436. * color: <hex>,
  12437. * roughness: <float>,
  12438. * metalness: <float>,
  12439. * opacity: <float>,
  12440. *
  12441. * map: new THREE.Texture( <Image> ),
  12442. *
  12443. * lightMap: new THREE.Texture( <Image> ),
  12444. * lightMapIntensity: <float>
  12445. *
  12446. * aoMap: new THREE.Texture( <Image> ),
  12447. * aoMapIntensity: <float>
  12448. *
  12449. * emissive: <hex>,
  12450. * emissiveIntensity: <float>
  12451. * emissiveMap: new THREE.Texture( <Image> ),
  12452. *
  12453. * bumpMap: new THREE.Texture( <Image> ),
  12454. * bumpScale: <float>,
  12455. *
  12456. * normalMap: new THREE.Texture( <Image> ),
  12457. * normalScale: <Vector2>,
  12458. *
  12459. * displacementMap: new THREE.Texture( <Image> ),
  12460. * displacementScale: <float>,
  12461. * displacementBias: <float>,
  12462. *
  12463. * roughnessMap: new THREE.Texture( <Image> ),
  12464. *
  12465. * metalnessMap: new THREE.Texture( <Image> ),
  12466. *
  12467. * alphaMap: new THREE.Texture( <Image> ),
  12468. *
  12469. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  12470. * envMapIntensity: <float>
  12471. *
  12472. * refractionRatio: <float>,
  12473. *
  12474. * shading: THREE.SmoothShading,
  12475. * blending: THREE.NormalBlending,
  12476. * depthTest: <bool>,
  12477. * depthWrite: <bool>,
  12478. *
  12479. * wireframe: <boolean>,
  12480. * wireframeLinewidth: <float>,
  12481. *
  12482. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  12483. *
  12484. * skinning: <bool>,
  12485. * morphTargets: <bool>,
  12486. * morphNormals: <bool>,
  12487. *
  12488. * fog: <bool>
  12489. * }
  12490. */
  12491. THREE.MeshStandardMaterial = function ( parameters ) {
  12492. THREE.Material.call( this );
  12493. this.type = 'MeshStandardMaterial';
  12494. this.color = new THREE.Color( 0xffffff ); // diffuse
  12495. this.roughness = 0.5;
  12496. this.metalness = 0.5;
  12497. this.map = null;
  12498. this.lightMap = null;
  12499. this.lightMapIntensity = 1.0;
  12500. this.aoMap = null;
  12501. this.aoMapIntensity = 1.0;
  12502. this.emissive = new THREE.Color( 0x000000 );
  12503. this.emissiveIntensity = 1.0;
  12504. this.emissiveMap = null;
  12505. this.bumpMap = null;
  12506. this.bumpScale = 1;
  12507. this.normalMap = null;
  12508. this.normalScale = new THREE.Vector2( 1, 1 );
  12509. this.displacementMap = null;
  12510. this.displacementScale = 1;
  12511. this.displacementBias = 0;
  12512. this.roughnessMap = null;
  12513. this.metalnessMap = null;
  12514. this.alphaMap = null;
  12515. this.envMap = null;
  12516. this.envMapIntensity = 1.0;
  12517. this.refractionRatio = 0.98;
  12518. this.fog = true;
  12519. this.shading = THREE.SmoothShading;
  12520. this.blending = THREE.NormalBlending;
  12521. this.wireframe = false;
  12522. this.wireframeLinewidth = 1;
  12523. this.wireframeLinecap = 'round';
  12524. this.wireframeLinejoin = 'round';
  12525. this.vertexColors = THREE.NoColors;
  12526. this.skinning = false;
  12527. this.morphTargets = false;
  12528. this.morphNormals = false;
  12529. this.setValues( parameters );
  12530. };
  12531. THREE.MeshStandardMaterial.prototype = Object.create( THREE.Material.prototype );
  12532. THREE.MeshStandardMaterial.prototype.constructor = THREE.MeshStandardMaterial;
  12533. THREE.MeshStandardMaterial.prototype.copy = function ( source ) {
  12534. THREE.Material.prototype.copy.call( this, source );
  12535. this.color.copy( source.color );
  12536. this.roughness = source.roughness;
  12537. this.metalness = source.metalness;
  12538. this.map = source.map;
  12539. this.lightMap = source.lightMap;
  12540. this.lightMapIntensity = source.lightMapIntensity;
  12541. this.aoMap = source.aoMap;
  12542. this.aoMapIntensity = source.aoMapIntensity;
  12543. this.emissive.copy( source.emissive );
  12544. this.emissiveMap = source.emissiveMap;
  12545. this.emissiveIntensity = source.emissiveIntensity;
  12546. this.bumpMap = source.bumpMap;
  12547. this.bumpScale = source.bumpScale;
  12548. this.normalMap = source.normalMap;
  12549. this.normalScale.copy( source.normalScale );
  12550. this.displacementMap = source.displacementMap;
  12551. this.displacementScale = source.displacementScale;
  12552. this.displacementBias = source.displacementBias;
  12553. this.roughnessMap = source.roughnessMap;
  12554. this.metalnessMap = source.metalnessMap;
  12555. this.alphaMap = source.alphaMap;
  12556. this.envMap = source.envMap;
  12557. this.envMapIntensity = source.envMapIntensity;
  12558. this.refractionRatio = source.refractionRatio;
  12559. this.fog = source.fog;
  12560. this.shading = source.shading;
  12561. this.wireframe = source.wireframe;
  12562. this.wireframeLinewidth = source.wireframeLinewidth;
  12563. this.wireframeLinecap = source.wireframeLinecap;
  12564. this.wireframeLinejoin = source.wireframeLinejoin;
  12565. this.vertexColors = source.vertexColors;
  12566. this.skinning = source.skinning;
  12567. this.morphTargets = source.morphTargets;
  12568. this.morphNormals = source.morphNormals;
  12569. return this;
  12570. };
  12571. // File:src/materials/MeshDepthMaterial.js
  12572. /**
  12573. * @author mrdoob / http://mrdoob.com/
  12574. * @author alteredq / http://alteredqualia.com/
  12575. *
  12576. * parameters = {
  12577. * opacity: <float>,
  12578. *
  12579. * wireframe: <boolean>,
  12580. * wireframeLinewidth: <float>
  12581. * }
  12582. */
  12583. THREE.MeshDepthMaterial = function ( parameters ) {
  12584. THREE.Material.call( this );
  12585. this.type = 'MeshDepthMaterial';
  12586. this.morphTargets = false;
  12587. this.wireframe = false;
  12588. this.wireframeLinewidth = 1;
  12589. this.setValues( parameters );
  12590. };
  12591. THREE.MeshDepthMaterial.prototype = Object.create( THREE.Material.prototype );
  12592. THREE.MeshDepthMaterial.prototype.constructor = THREE.MeshDepthMaterial;
  12593. THREE.MeshDepthMaterial.prototype.copy = function ( source ) {
  12594. THREE.Material.prototype.copy.call( this, source );
  12595. this.wireframe = source.wireframe;
  12596. this.wireframeLinewidth = source.wireframeLinewidth;
  12597. return this;
  12598. };
  12599. // File:src/materials/MeshNormalMaterial.js
  12600. /**
  12601. * @author mrdoob / http://mrdoob.com/
  12602. *
  12603. * parameters = {
  12604. * opacity: <float>,
  12605. *
  12606. * wireframe: <boolean>,
  12607. * wireframeLinewidth: <float>
  12608. * }
  12609. */
  12610. THREE.MeshNormalMaterial = function ( parameters ) {
  12611. THREE.Material.call( this, parameters );
  12612. this.type = 'MeshNormalMaterial';
  12613. this.wireframe = false;
  12614. this.wireframeLinewidth = 1;
  12615. this.morphTargets = false;
  12616. this.setValues( parameters );
  12617. };
  12618. THREE.MeshNormalMaterial.prototype = Object.create( THREE.Material.prototype );
  12619. THREE.MeshNormalMaterial.prototype.constructor = THREE.MeshNormalMaterial;
  12620. THREE.MeshNormalMaterial.prototype.copy = function ( source ) {
  12621. THREE.Material.prototype.copy.call( this, source );
  12622. this.wireframe = source.wireframe;
  12623. this.wireframeLinewidth = source.wireframeLinewidth;
  12624. return this;
  12625. };
  12626. // File:src/materials/MultiMaterial.js
  12627. /**
  12628. * @author mrdoob / http://mrdoob.com/
  12629. */
  12630. THREE.MultiMaterial = function ( materials ) {
  12631. this.uuid = THREE.Math.generateUUID();
  12632. this.type = 'MultiMaterial';
  12633. this.materials = materials instanceof Array ? materials : [];
  12634. this.visible = true;
  12635. };
  12636. THREE.MultiMaterial.prototype = {
  12637. constructor: THREE.MultiMaterial,
  12638. toJSON: function ( meta ) {
  12639. var output = {
  12640. metadata: {
  12641. version: 4.2,
  12642. type: 'material',
  12643. generator: 'MaterialExporter'
  12644. },
  12645. uuid: this.uuid,
  12646. type: this.type,
  12647. materials: []
  12648. };
  12649. var materials = this.materials;
  12650. for ( var i = 0, l = materials.length; i < l; i ++ ) {
  12651. var material = materials[ i ].toJSON( meta );
  12652. delete material.metadata;
  12653. output.materials.push( material );
  12654. }
  12655. output.visible = this.visible;
  12656. return output;
  12657. },
  12658. clone: function () {
  12659. var material = new this.constructor();
  12660. for ( var i = 0; i < this.materials.length; i ++ ) {
  12661. material.materials.push( this.materials[ i ].clone() );
  12662. }
  12663. material.visible = this.visible;
  12664. return material;
  12665. }
  12666. };
  12667. // File:src/materials/PointsMaterial.js
  12668. /**
  12669. * @author mrdoob / http://mrdoob.com/
  12670. * @author alteredq / http://alteredqualia.com/
  12671. *
  12672. * parameters = {
  12673. * color: <hex>,
  12674. * opacity: <float>,
  12675. * map: new THREE.Texture( <Image> ),
  12676. *
  12677. * size: <float>,
  12678. * sizeAttenuation: <bool>,
  12679. *
  12680. * blending: THREE.NormalBlending,
  12681. * depthTest: <bool>,
  12682. * depthWrite: <bool>,
  12683. *
  12684. * vertexColors: <bool>,
  12685. *
  12686. * fog: <bool>
  12687. * }
  12688. */
  12689. THREE.PointsMaterial = function ( parameters ) {
  12690. THREE.Material.call( this );
  12691. this.type = 'PointsMaterial';
  12692. this.color = new THREE.Color( 0xffffff );
  12693. this.map = null;
  12694. this.size = 1;
  12695. this.sizeAttenuation = true;
  12696. this.blending = THREE.NormalBlending;
  12697. this.vertexColors = THREE.NoColors;
  12698. this.fog = true;
  12699. this.setValues( parameters );
  12700. };
  12701. THREE.PointsMaterial.prototype = Object.create( THREE.Material.prototype );
  12702. THREE.PointsMaterial.prototype.constructor = THREE.PointsMaterial;
  12703. THREE.PointsMaterial.prototype.copy = function ( source ) {
  12704. THREE.Material.prototype.copy.call( this, source );
  12705. this.color.copy( source.color );
  12706. this.map = source.map;
  12707. this.size = source.size;
  12708. this.sizeAttenuation = source.sizeAttenuation;
  12709. this.vertexColors = source.vertexColors;
  12710. this.fog = source.fog;
  12711. return this;
  12712. };
  12713. // File:src/materials/ShaderMaterial.js
  12714. /**
  12715. * @author alteredq / http://alteredqualia.com/
  12716. *
  12717. * parameters = {
  12718. * defines: { "label" : "value" },
  12719. * uniforms: { "parameter1": { type: "1f", value: 1.0 }, "parameter2": { type: "1i" value2: 2 } },
  12720. *
  12721. * fragmentShader: <string>,
  12722. * vertexShader: <string>,
  12723. *
  12724. * shading: THREE.SmoothShading,
  12725. *
  12726. * wireframe: <boolean>,
  12727. * wireframeLinewidth: <float>,
  12728. *
  12729. * lights: <bool>,
  12730. *
  12731. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  12732. *
  12733. * skinning: <bool>,
  12734. * morphTargets: <bool>,
  12735. * morphNormals: <bool>,
  12736. *
  12737. * fog: <bool>
  12738. * }
  12739. */
  12740. THREE.ShaderMaterial = function ( parameters ) {
  12741. THREE.Material.call( this );
  12742. this.type = 'ShaderMaterial';
  12743. this.defines = {};
  12744. this.uniforms = {};
  12745. this.vertexShader = 'void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}';
  12746. this.fragmentShader = 'void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}';
  12747. this.shading = THREE.SmoothShading;
  12748. this.linewidth = 1;
  12749. this.wireframe = false;
  12750. this.wireframeLinewidth = 1;
  12751. this.fog = false; // set to use scene fog
  12752. this.lights = false; // set to use scene lights
  12753. this.vertexColors = THREE.NoColors; // set to use "color" attribute stream
  12754. this.skinning = false; // set to use skinning attribute streams
  12755. this.morphTargets = false; // set to use morph targets
  12756. this.morphNormals = false; // set to use morph normals
  12757. this.extensions = {
  12758. derivatives: false, // set to use derivatives
  12759. fragDepth: false, // set to use fragment depth values
  12760. drawBuffers: false, // set to use draw buffers
  12761. shaderTextureLOD: false // set to use shader texture LOD
  12762. };
  12763. // When rendered geometry doesn't include these attributes but the material does,
  12764. // use these default values in WebGL. This avoids errors when buffer data is missing.
  12765. this.defaultAttributeValues = {
  12766. 'color': [ 1, 1, 1 ],
  12767. 'uv': [ 0, 0 ],
  12768. 'uv2': [ 0, 0 ]
  12769. };
  12770. this.index0AttributeName = undefined;
  12771. if ( parameters !== undefined ) {
  12772. if ( parameters.attributes !== undefined ) {
  12773. console.error( 'THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.' );
  12774. }
  12775. this.setValues( parameters );
  12776. }
  12777. };
  12778. THREE.ShaderMaterial.prototype = Object.create( THREE.Material.prototype );
  12779. THREE.ShaderMaterial.prototype.constructor = THREE.ShaderMaterial;
  12780. THREE.ShaderMaterial.prototype.copy = function ( source ) {
  12781. THREE.Material.prototype.copy.call( this, source );
  12782. this.fragmentShader = source.fragmentShader;
  12783. this.vertexShader = source.vertexShader;
  12784. this.uniforms = THREE.UniformsUtils.clone( source.uniforms );
  12785. this.defines = source.defines;
  12786. this.shading = source.shading;
  12787. this.wireframe = source.wireframe;
  12788. this.wireframeLinewidth = source.wireframeLinewidth;
  12789. this.fog = source.fog;
  12790. this.lights = source.lights;
  12791. this.vertexColors = source.vertexColors;
  12792. this.skinning = source.skinning;
  12793. this.morphTargets = source.morphTargets;
  12794. this.morphNormals = source.morphNormals;
  12795. this.extensions = source.extensions;
  12796. return this;
  12797. };
  12798. THREE.ShaderMaterial.prototype.toJSON = function ( meta ) {
  12799. var data = THREE.Material.prototype.toJSON.call( this, meta );
  12800. data.uniforms = this.uniforms;
  12801. data.vertexShader = this.vertexShader;
  12802. data.fragmentShader = this.fragmentShader;
  12803. return data;
  12804. };
  12805. // File:src/materials/RawShaderMaterial.js
  12806. /**
  12807. * @author mrdoob / http://mrdoob.com/
  12808. */
  12809. THREE.RawShaderMaterial = function ( parameters ) {
  12810. THREE.ShaderMaterial.call( this, parameters );
  12811. this.type = 'RawShaderMaterial';
  12812. };
  12813. THREE.RawShaderMaterial.prototype = Object.create( THREE.ShaderMaterial.prototype );
  12814. THREE.RawShaderMaterial.prototype.constructor = THREE.RawShaderMaterial;
  12815. // File:src/materials/SpriteMaterial.js
  12816. /**
  12817. * @author alteredq / http://alteredqualia.com/
  12818. *
  12819. * parameters = {
  12820. * color: <hex>,
  12821. * opacity: <float>,
  12822. * map: new THREE.Texture( <Image> ),
  12823. *
  12824. * uvOffset: new THREE.Vector2(),
  12825. * uvScale: new THREE.Vector2(),
  12826. *
  12827. * fog: <bool>
  12828. * }
  12829. */
  12830. THREE.SpriteMaterial = function ( parameters ) {
  12831. THREE.Material.call( this );
  12832. this.type = 'SpriteMaterial';
  12833. this.color = new THREE.Color( 0xffffff );
  12834. this.map = null;
  12835. this.rotation = 0;
  12836. this.fog = false;
  12837. // set parameters
  12838. this.setValues( parameters );
  12839. };
  12840. THREE.SpriteMaterial.prototype = Object.create( THREE.Material.prototype );
  12841. THREE.SpriteMaterial.prototype.constructor = THREE.SpriteMaterial;
  12842. THREE.SpriteMaterial.prototype.copy = function ( source ) {
  12843. THREE.Material.prototype.copy.call( this, source );
  12844. this.color.copy( source.color );
  12845. this.map = source.map;
  12846. this.rotation = source.rotation;
  12847. this.fog = source.fog;
  12848. return this;
  12849. };
  12850. // File:src/textures/Texture.js
  12851. /**
  12852. * @author mrdoob / http://mrdoob.com/
  12853. * @author alteredq / http://alteredqualia.com/
  12854. * @author szimek / https://github.com/szimek/
  12855. */
  12856. THREE.Texture = function ( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  12857. Object.defineProperty( this, 'id', { value: THREE.TextureIdCount ++ } );
  12858. this.uuid = THREE.Math.generateUUID();
  12859. this.name = '';
  12860. this.sourceFile = '';
  12861. this.image = image !== undefined ? image : THREE.Texture.DEFAULT_IMAGE;
  12862. this.mipmaps = [];
  12863. this.mapping = mapping !== undefined ? mapping : THREE.Texture.DEFAULT_MAPPING;
  12864. this.wrapS = wrapS !== undefined ? wrapS : THREE.ClampToEdgeWrapping;
  12865. this.wrapT = wrapT !== undefined ? wrapT : THREE.ClampToEdgeWrapping;
  12866. this.magFilter = magFilter !== undefined ? magFilter : THREE.LinearFilter;
  12867. this.minFilter = minFilter !== undefined ? minFilter : THREE.LinearMipMapLinearFilter;
  12868. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  12869. this.format = format !== undefined ? format : THREE.RGBAFormat;
  12870. this.type = type !== undefined ? type : THREE.UnsignedByteType;
  12871. this.offset = new THREE.Vector2( 0, 0 );
  12872. this.repeat = new THREE.Vector2( 1, 1 );
  12873. this.generateMipmaps = true;
  12874. this.premultiplyAlpha = false;
  12875. this.flipY = true;
  12876. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  12877. // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
  12878. //
  12879. // Also changing the encoding after already used by a Material will not automatically make the Material
  12880. // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
  12881. this.encoding = THREE.LinearEncoding;
  12882. this.version = 0;
  12883. this.onUpdate = null;
  12884. };
  12885. THREE.Texture.DEFAULT_IMAGE = undefined;
  12886. THREE.Texture.DEFAULT_MAPPING = THREE.UVMapping;
  12887. THREE.Texture.prototype = {
  12888. constructor: THREE.Texture,
  12889. set needsUpdate ( value ) {
  12890. if ( value === true ) this.version ++;
  12891. },
  12892. clone: function () {
  12893. return new this.constructor().copy( this );
  12894. },
  12895. copy: function ( source ) {
  12896. this.image = source.image;
  12897. this.mipmaps = source.mipmaps.slice( 0 );
  12898. this.mapping = source.mapping;
  12899. this.wrapS = source.wrapS;
  12900. this.wrapT = source.wrapT;
  12901. this.magFilter = source.magFilter;
  12902. this.minFilter = source.minFilter;
  12903. this.anisotropy = source.anisotropy;
  12904. this.format = source.format;
  12905. this.type = source.type;
  12906. this.offset.copy( source.offset );
  12907. this.repeat.copy( source.repeat );
  12908. this.generateMipmaps = source.generateMipmaps;
  12909. this.premultiplyAlpha = source.premultiplyAlpha;
  12910. this.flipY = source.flipY;
  12911. this.unpackAlignment = source.unpackAlignment;
  12912. this.encoding = source.encoding;
  12913. return this;
  12914. },
  12915. toJSON: function ( meta ) {
  12916. if ( meta.textures[ this.uuid ] !== undefined ) {
  12917. return meta.textures[ this.uuid ];
  12918. }
  12919. function getDataURL( image ) {
  12920. var canvas;
  12921. if ( image.toDataURL !== undefined ) {
  12922. canvas = image;
  12923. } else {
  12924. canvas = document.createElement( 'canvas' );
  12925. canvas.width = image.width;
  12926. canvas.height = image.height;
  12927. canvas.getContext( '2d' ).drawImage( image, 0, 0, image.width, image.height );
  12928. }
  12929. if ( canvas.width > 2048 || canvas.height > 2048 ) {
  12930. return canvas.toDataURL( 'image/jpeg', 0.6 );
  12931. } else {
  12932. return canvas.toDataURL( 'image/png' );
  12933. }
  12934. }
  12935. var output = {
  12936. metadata: {
  12937. version: 4.4,
  12938. type: 'Texture',
  12939. generator: 'Texture.toJSON'
  12940. },
  12941. uuid: this.uuid,
  12942. name: this.name,
  12943. mapping: this.mapping,
  12944. repeat: [ this.repeat.x, this.repeat.y ],
  12945. offset: [ this.offset.x, this.offset.y ],
  12946. wrap: [ this.wrapS, this.wrapT ],
  12947. minFilter: this.minFilter,
  12948. magFilter: this.magFilter,
  12949. anisotropy: this.anisotropy
  12950. };
  12951. if ( this.image !== undefined ) {
  12952. // TODO: Move to THREE.Image
  12953. var image = this.image;
  12954. if ( image.uuid === undefined ) {
  12955. image.uuid = THREE.Math.generateUUID(); // UGH
  12956. }
  12957. if ( meta.images[ image.uuid ] === undefined ) {
  12958. meta.images[ image.uuid ] = {
  12959. uuid: image.uuid,
  12960. url: getDataURL( image )
  12961. };
  12962. }
  12963. output.image = image.uuid;
  12964. }
  12965. meta.textures[ this.uuid ] = output;
  12966. return output;
  12967. },
  12968. dispose: function () {
  12969. this.dispatchEvent( { type: 'dispose' } );
  12970. },
  12971. transformUv: function ( uv ) {
  12972. if ( this.mapping !== THREE.UVMapping ) return;
  12973. uv.multiply( this.repeat );
  12974. uv.add( this.offset );
  12975. if ( uv.x < 0 || uv.x > 1 ) {
  12976. switch ( this.wrapS ) {
  12977. case THREE.RepeatWrapping:
  12978. uv.x = uv.x - Math.floor( uv.x );
  12979. break;
  12980. case THREE.ClampToEdgeWrapping:
  12981. uv.x = uv.x < 0 ? 0 : 1;
  12982. break;
  12983. case THREE.MirroredRepeatWrapping:
  12984. if ( Math.abs( Math.floor( uv.x ) % 2 ) === 1 ) {
  12985. uv.x = Math.ceil( uv.x ) - uv.x;
  12986. } else {
  12987. uv.x = uv.x - Math.floor( uv.x );
  12988. }
  12989. break;
  12990. }
  12991. }
  12992. if ( uv.y < 0 || uv.y > 1 ) {
  12993. switch ( this.wrapT ) {
  12994. case THREE.RepeatWrapping:
  12995. uv.y = uv.y - Math.floor( uv.y );
  12996. break;
  12997. case THREE.ClampToEdgeWrapping:
  12998. uv.y = uv.y < 0 ? 0 : 1;
  12999. break;
  13000. case THREE.MirroredRepeatWrapping:
  13001. if ( Math.abs( Math.floor( uv.y ) % 2 ) === 1 ) {
  13002. uv.y = Math.ceil( uv.y ) - uv.y;
  13003. } else {
  13004. uv.y = uv.y - Math.floor( uv.y );
  13005. }
  13006. break;
  13007. }
  13008. }
  13009. if ( this.flipY ) {
  13010. uv.y = 1 - uv.y;
  13011. }
  13012. }
  13013. };
  13014. THREE.EventDispatcher.prototype.apply( THREE.Texture.prototype );
  13015. THREE.TextureIdCount = 0;
  13016. // File:src/textures/CanvasTexture.js
  13017. /**
  13018. * @author mrdoob / http://mrdoob.com/
  13019. */
  13020. THREE.CanvasTexture = function ( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  13021. THREE.Texture.call( this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  13022. this.needsUpdate = true;
  13023. };
  13024. THREE.CanvasTexture.prototype = Object.create( THREE.Texture.prototype );
  13025. THREE.CanvasTexture.prototype.constructor = THREE.CanvasTexture;
  13026. // File:src/textures/CubeTexture.js
  13027. /**
  13028. * @author mrdoob / http://mrdoob.com/
  13029. */
  13030. THREE.CubeTexture = function ( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  13031. images = images !== undefined ? images : [];
  13032. mapping = mapping !== undefined ? mapping : THREE.CubeReflectionMapping;
  13033. THREE.Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  13034. this.flipY = false;
  13035. };
  13036. THREE.CubeTexture.prototype = Object.create( THREE.Texture.prototype );
  13037. THREE.CubeTexture.prototype.constructor = THREE.CubeTexture;
  13038. Object.defineProperty( THREE.CubeTexture.prototype, 'images', {
  13039. get: function () {
  13040. return this.image;
  13041. },
  13042. set: function ( value ) {
  13043. this.image = value;
  13044. }
  13045. } );
  13046. // File:src/textures/CompressedTexture.js
  13047. /**
  13048. * @author alteredq / http://alteredqualia.com/
  13049. */
  13050. THREE.CompressedTexture = function ( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy ) {
  13051. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  13052. this.image = { width: width, height: height };
  13053. this.mipmaps = mipmaps;
  13054. // no flipping for cube textures
  13055. // (also flipping doesn't work for compressed textures )
  13056. this.flipY = false;
  13057. // can't generate mipmaps for compressed textures
  13058. // mips must be embedded in DDS files
  13059. this.generateMipmaps = false;
  13060. };
  13061. THREE.CompressedTexture.prototype = Object.create( THREE.Texture.prototype );
  13062. THREE.CompressedTexture.prototype.constructor = THREE.CompressedTexture;
  13063. // File:src/textures/DataTexture.js
  13064. /**
  13065. * @author alteredq / http://alteredqualia.com/
  13066. */
  13067. THREE.DataTexture = function ( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy ) {
  13068. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  13069. this.image = { data: data, width: width, height: height };
  13070. this.magFilter = magFilter !== undefined ? magFilter : THREE.NearestFilter;
  13071. this.minFilter = minFilter !== undefined ? minFilter : THREE.NearestFilter;
  13072. this.flipY = false;
  13073. this.generateMipmaps = false;
  13074. };
  13075. THREE.DataTexture.prototype = Object.create( THREE.Texture.prototype );
  13076. THREE.DataTexture.prototype.constructor = THREE.DataTexture;
  13077. // File:src/textures/VideoTexture.js
  13078. /**
  13079. * @author mrdoob / http://mrdoob.com/
  13080. */
  13081. THREE.VideoTexture = function ( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  13082. THREE.Texture.call( this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  13083. this.generateMipmaps = false;
  13084. var scope = this;
  13085. function update() {
  13086. requestAnimationFrame( update );
  13087. if ( video.readyState === video.HAVE_ENOUGH_DATA ) {
  13088. scope.needsUpdate = true;
  13089. }
  13090. }
  13091. update();
  13092. };
  13093. THREE.VideoTexture.prototype = Object.create( THREE.Texture.prototype );
  13094. THREE.VideoTexture.prototype.constructor = THREE.VideoTexture;
  13095. // File:src/objects/Group.js
  13096. /**
  13097. * @author mrdoob / http://mrdoob.com/
  13098. */
  13099. THREE.Group = function () {
  13100. THREE.Object3D.call( this );
  13101. this.type = 'Group';
  13102. };
  13103. THREE.Group.prototype = Object.create( THREE.Object3D.prototype );
  13104. THREE.Group.prototype.constructor = THREE.Group;
  13105. // File:src/objects/Points.js
  13106. /**
  13107. * @author alteredq / http://alteredqualia.com/
  13108. */
  13109. THREE.Points = function ( geometry, material ) {
  13110. THREE.Object3D.call( this );
  13111. this.type = 'Points';
  13112. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  13113. this.material = material !== undefined ? material : new THREE.PointsMaterial( { color: Math.random() * 0xffffff } );
  13114. };
  13115. THREE.Points.prototype = Object.create( THREE.Object3D.prototype );
  13116. THREE.Points.prototype.constructor = THREE.Points;
  13117. THREE.Points.prototype.raycast = ( function () {
  13118. var inverseMatrix = new THREE.Matrix4();
  13119. var ray = new THREE.Ray();
  13120. var sphere = new THREE.Sphere();
  13121. return function raycast( raycaster, intersects ) {
  13122. var object = this;
  13123. var geometry = this.geometry;
  13124. var matrixWorld = this.matrixWorld;
  13125. var threshold = raycaster.params.Points.threshold;
  13126. // Checking boundingSphere distance to ray
  13127. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  13128. sphere.copy( geometry.boundingSphere );
  13129. sphere.applyMatrix4( matrixWorld );
  13130. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  13131. //
  13132. inverseMatrix.getInverse( matrixWorld );
  13133. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  13134. var localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  13135. var localThresholdSq = localThreshold * localThreshold;
  13136. var position = new THREE.Vector3();
  13137. function testPoint( point, index ) {
  13138. var rayPointDistanceSq = ray.distanceSqToPoint( point );
  13139. if ( rayPointDistanceSq < localThresholdSq ) {
  13140. var intersectPoint = ray.closestPointToPoint( point );
  13141. intersectPoint.applyMatrix4( matrixWorld );
  13142. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  13143. if ( distance < raycaster.near || distance > raycaster.far ) return;
  13144. intersects.push( {
  13145. distance: distance,
  13146. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  13147. point: intersectPoint.clone(),
  13148. index: index,
  13149. face: null,
  13150. object: object
  13151. } );
  13152. }
  13153. }
  13154. if ( geometry instanceof THREE.BufferGeometry ) {
  13155. var index = geometry.index;
  13156. var attributes = geometry.attributes;
  13157. var positions = attributes.position.array;
  13158. if ( index !== null ) {
  13159. var indices = index.array;
  13160. for ( var i = 0, il = indices.length; i < il; i ++ ) {
  13161. var a = indices[ i ];
  13162. position.fromArray( positions, a * 3 );
  13163. testPoint( position, a );
  13164. }
  13165. } else {
  13166. for ( var i = 0, l = positions.length / 3; i < l; i ++ ) {
  13167. position.fromArray( positions, i * 3 );
  13168. testPoint( position, i );
  13169. }
  13170. }
  13171. } else {
  13172. var vertices = geometry.vertices;
  13173. for ( var i = 0, l = vertices.length; i < l; i ++ ) {
  13174. testPoint( vertices[ i ], i );
  13175. }
  13176. }
  13177. };
  13178. }() );
  13179. THREE.Points.prototype.clone = function () {
  13180. return new this.constructor( this.geometry, this.material ).copy( this );
  13181. };
  13182. // File:src/objects/Line.js
  13183. /**
  13184. * @author mrdoob / http://mrdoob.com/
  13185. */
  13186. THREE.Line = function ( geometry, material, mode ) {
  13187. if ( mode === 1 ) {
  13188. console.warn( 'THREE.Line: parameter THREE.LinePieces no longer supported. Created THREE.LineSegments instead.' );
  13189. return new THREE.LineSegments( geometry, material );
  13190. }
  13191. THREE.Object3D.call( this );
  13192. this.type = 'Line';
  13193. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  13194. this.material = material !== undefined ? material : new THREE.LineBasicMaterial( { color: Math.random() * 0xffffff } );
  13195. };
  13196. THREE.Line.prototype = Object.create( THREE.Object3D.prototype );
  13197. THREE.Line.prototype.constructor = THREE.Line;
  13198. THREE.Line.prototype.raycast = ( function () {
  13199. var inverseMatrix = new THREE.Matrix4();
  13200. var ray = new THREE.Ray();
  13201. var sphere = new THREE.Sphere();
  13202. return function raycast( raycaster, intersects ) {
  13203. var precision = raycaster.linePrecision;
  13204. var precisionSq = precision * precision;
  13205. var geometry = this.geometry;
  13206. var matrixWorld = this.matrixWorld;
  13207. // Checking boundingSphere distance to ray
  13208. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  13209. sphere.copy( geometry.boundingSphere );
  13210. sphere.applyMatrix4( matrixWorld );
  13211. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  13212. //
  13213. inverseMatrix.getInverse( matrixWorld );
  13214. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  13215. var vStart = new THREE.Vector3();
  13216. var vEnd = new THREE.Vector3();
  13217. var interSegment = new THREE.Vector3();
  13218. var interRay = new THREE.Vector3();
  13219. var step = this instanceof THREE.LineSegments ? 2 : 1;
  13220. if ( geometry instanceof THREE.BufferGeometry ) {
  13221. var index = geometry.index;
  13222. var attributes = geometry.attributes;
  13223. var positions = attributes.position.array;
  13224. if ( index !== null ) {
  13225. var indices = index.array;
  13226. for ( var i = 0, l = indices.length - 1; i < l; i += step ) {
  13227. var a = indices[ i ];
  13228. var b = indices[ i + 1 ];
  13229. vStart.fromArray( positions, a * 3 );
  13230. vEnd.fromArray( positions, b * 3 );
  13231. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  13232. if ( distSq > precisionSq ) continue;
  13233. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  13234. var distance = raycaster.ray.origin.distanceTo( interRay );
  13235. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  13236. intersects.push( {
  13237. distance: distance,
  13238. // What do we want? intersection point on the ray or on the segment??
  13239. // point: raycaster.ray.at( distance ),
  13240. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  13241. index: i,
  13242. face: null,
  13243. faceIndex: null,
  13244. object: this
  13245. } );
  13246. }
  13247. } else {
  13248. for ( var i = 0, l = positions.length / 3 - 1; i < l; i += step ) {
  13249. vStart.fromArray( positions, 3 * i );
  13250. vEnd.fromArray( positions, 3 * i + 3 );
  13251. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  13252. if ( distSq > precisionSq ) continue;
  13253. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  13254. var distance = raycaster.ray.origin.distanceTo( interRay );
  13255. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  13256. intersects.push( {
  13257. distance: distance,
  13258. // What do we want? intersection point on the ray or on the segment??
  13259. // point: raycaster.ray.at( distance ),
  13260. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  13261. index: i,
  13262. face: null,
  13263. faceIndex: null,
  13264. object: this
  13265. } );
  13266. }
  13267. }
  13268. } else if ( geometry instanceof THREE.Geometry ) {
  13269. var vertices = geometry.vertices;
  13270. var nbVertices = vertices.length;
  13271. for ( var i = 0; i < nbVertices - 1; i += step ) {
  13272. var distSq = ray.distanceSqToSegment( vertices[ i ], vertices[ i + 1 ], interRay, interSegment );
  13273. if ( distSq > precisionSq ) continue;
  13274. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  13275. var distance = raycaster.ray.origin.distanceTo( interRay );
  13276. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  13277. intersects.push( {
  13278. distance: distance,
  13279. // What do we want? intersection point on the ray or on the segment??
  13280. // point: raycaster.ray.at( distance ),
  13281. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  13282. index: i,
  13283. face: null,
  13284. faceIndex: null,
  13285. object: this
  13286. } );
  13287. }
  13288. }
  13289. };
  13290. }() );
  13291. THREE.Line.prototype.clone = function () {
  13292. return new this.constructor( this.geometry, this.material ).copy( this );
  13293. };
  13294. // DEPRECATED
  13295. THREE.LineStrip = 0;
  13296. THREE.LinePieces = 1;
  13297. // File:src/objects/LineSegments.js
  13298. /**
  13299. * @author mrdoob / http://mrdoob.com/
  13300. */
  13301. THREE.LineSegments = function ( geometry, material ) {
  13302. THREE.Line.call( this, geometry, material );
  13303. this.type = 'LineSegments';
  13304. };
  13305. THREE.LineSegments.prototype = Object.create( THREE.Line.prototype );
  13306. THREE.LineSegments.prototype.constructor = THREE.LineSegments;
  13307. // File:src/objects/Mesh.js
  13308. /**
  13309. * @author mrdoob / http://mrdoob.com/
  13310. * @author alteredq / http://alteredqualia.com/
  13311. * @author mikael emtinger / http://gomo.se/
  13312. * @author jonobr1 / http://jonobr1.com/
  13313. */
  13314. THREE.Mesh = function ( geometry, material ) {
  13315. THREE.Object3D.call( this );
  13316. this.type = 'Mesh';
  13317. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  13318. this.material = material !== undefined ? material : new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff } );
  13319. this.drawMode = THREE.TrianglesDrawMode;
  13320. this.updateMorphTargets();
  13321. };
  13322. THREE.Mesh.prototype = Object.create( THREE.Object3D.prototype );
  13323. THREE.Mesh.prototype.constructor = THREE.Mesh;
  13324. THREE.Mesh.prototype.setDrawMode = function ( value ) {
  13325. this.drawMode = value;
  13326. };
  13327. THREE.Mesh.prototype.updateMorphTargets = function () {
  13328. if ( this.geometry.morphTargets !== undefined && this.geometry.morphTargets.length > 0 ) {
  13329. this.morphTargetBase = - 1;
  13330. this.morphTargetInfluences = [];
  13331. this.morphTargetDictionary = {};
  13332. for ( var m = 0, ml = this.geometry.morphTargets.length; m < ml; m ++ ) {
  13333. this.morphTargetInfluences.push( 0 );
  13334. this.morphTargetDictionary[ this.geometry.morphTargets[ m ].name ] = m;
  13335. }
  13336. }
  13337. };
  13338. THREE.Mesh.prototype.getMorphTargetIndexByName = function ( name ) {
  13339. if ( this.morphTargetDictionary[ name ] !== undefined ) {
  13340. return this.morphTargetDictionary[ name ];
  13341. }
  13342. console.warn( 'THREE.Mesh.getMorphTargetIndexByName: morph target ' + name + ' does not exist. Returning 0.' );
  13343. return 0;
  13344. };
  13345. THREE.Mesh.prototype.raycast = ( function () {
  13346. var inverseMatrix = new THREE.Matrix4();
  13347. var ray = new THREE.Ray();
  13348. var sphere = new THREE.Sphere();
  13349. var vA = new THREE.Vector3();
  13350. var vB = new THREE.Vector3();
  13351. var vC = new THREE.Vector3();
  13352. var tempA = new THREE.Vector3();
  13353. var tempB = new THREE.Vector3();
  13354. var tempC = new THREE.Vector3();
  13355. var uvA = new THREE.Vector2();
  13356. var uvB = new THREE.Vector2();
  13357. var uvC = new THREE.Vector2();
  13358. var barycoord = new THREE.Vector3();
  13359. var intersectionPoint = new THREE.Vector3();
  13360. var intersectionPointWorld = new THREE.Vector3();
  13361. function uvIntersection( point, p1, p2, p3, uv1, uv2, uv3 ) {
  13362. THREE.Triangle.barycoordFromPoint( point, p1, p2, p3, barycoord );
  13363. uv1.multiplyScalar( barycoord.x );
  13364. uv2.multiplyScalar( barycoord.y );
  13365. uv3.multiplyScalar( barycoord.z );
  13366. uv1.add( uv2 ).add( uv3 );
  13367. return uv1.clone();
  13368. }
  13369. function checkIntersection( object, raycaster, ray, pA, pB, pC, point ) {
  13370. var intersect;
  13371. var material = object.material;
  13372. if ( material.side === THREE.BackSide ) {
  13373. intersect = ray.intersectTriangle( pC, pB, pA, true, point );
  13374. } else {
  13375. intersect = ray.intersectTriangle( pA, pB, pC, material.side !== THREE.DoubleSide, point );
  13376. }
  13377. if ( intersect === null ) return null;
  13378. intersectionPointWorld.copy( point );
  13379. intersectionPointWorld.applyMatrix4( object.matrixWorld );
  13380. var distance = raycaster.ray.origin.distanceTo( intersectionPointWorld );
  13381. if ( distance < raycaster.near || distance > raycaster.far ) return null;
  13382. return {
  13383. distance: distance,
  13384. point: intersectionPointWorld.clone(),
  13385. object: object
  13386. };
  13387. }
  13388. function checkBufferGeometryIntersection( object, raycaster, ray, positions, uvs, a, b, c ) {
  13389. vA.fromArray( positions, a * 3 );
  13390. vB.fromArray( positions, b * 3 );
  13391. vC.fromArray( positions, c * 3 );
  13392. var intersection = checkIntersection( object, raycaster, ray, vA, vB, vC, intersectionPoint );
  13393. if ( intersection ) {
  13394. if ( uvs ) {
  13395. uvA.fromArray( uvs, a * 2 );
  13396. uvB.fromArray( uvs, b * 2 );
  13397. uvC.fromArray( uvs, c * 2 );
  13398. intersection.uv = uvIntersection( intersectionPoint, vA, vB, vC, uvA, uvB, uvC );
  13399. }
  13400. intersection.face = new THREE.Face3( a, b, c, THREE.Triangle.normal( vA, vB, vC ) );
  13401. intersection.faceIndex = a;
  13402. }
  13403. return intersection;
  13404. }
  13405. return function raycast( raycaster, intersects ) {
  13406. var geometry = this.geometry;
  13407. var material = this.material;
  13408. var matrixWorld = this.matrixWorld;
  13409. if ( material === undefined ) return;
  13410. // Checking boundingSphere distance to ray
  13411. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  13412. sphere.copy( geometry.boundingSphere );
  13413. sphere.applyMatrix4( matrixWorld );
  13414. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  13415. //
  13416. inverseMatrix.getInverse( matrixWorld );
  13417. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  13418. // Check boundingBox before continuing
  13419. if ( geometry.boundingBox !== null ) {
  13420. if ( ray.intersectsBox( geometry.boundingBox ) === false ) return;
  13421. }
  13422. var uvs, intersection;
  13423. if ( geometry instanceof THREE.BufferGeometry ) {
  13424. var a, b, c;
  13425. var index = geometry.index;
  13426. var attributes = geometry.attributes;
  13427. var positions = attributes.position.array;
  13428. if ( attributes.uv !== undefined ) {
  13429. uvs = attributes.uv.array;
  13430. }
  13431. if ( index !== null ) {
  13432. var indices = index.array;
  13433. for ( var i = 0, l = indices.length; i < l; i += 3 ) {
  13434. a = indices[ i ];
  13435. b = indices[ i + 1 ];
  13436. c = indices[ i + 2 ];
  13437. intersection = checkBufferGeometryIntersection( this, raycaster, ray, positions, uvs, a, b, c );
  13438. if ( intersection ) {
  13439. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in indices buffer semantics
  13440. intersects.push( intersection );
  13441. }
  13442. }
  13443. } else {
  13444. for ( var i = 0, l = positions.length; i < l; i += 9 ) {
  13445. a = i / 3;
  13446. b = a + 1;
  13447. c = a + 2;
  13448. intersection = checkBufferGeometryIntersection( this, raycaster, ray, positions, uvs, a, b, c );
  13449. if ( intersection ) {
  13450. intersection.index = a; // triangle number in positions buffer semantics
  13451. intersects.push( intersection );
  13452. }
  13453. }
  13454. }
  13455. } else if ( geometry instanceof THREE.Geometry ) {
  13456. var fvA, fvB, fvC;
  13457. var isFaceMaterial = material instanceof THREE.MultiMaterial;
  13458. var materials = isFaceMaterial === true ? material.materials : null;
  13459. var vertices = geometry.vertices;
  13460. var faces = geometry.faces;
  13461. var faceVertexUvs = geometry.faceVertexUvs[ 0 ];
  13462. if ( faceVertexUvs.length > 0 ) uvs = faceVertexUvs;
  13463. for ( var f = 0, fl = faces.length; f < fl; f ++ ) {
  13464. var face = faces[ f ];
  13465. var faceMaterial = isFaceMaterial === true ? materials[ face.materialIndex ] : material;
  13466. if ( faceMaterial === undefined ) continue;
  13467. fvA = vertices[ face.a ];
  13468. fvB = vertices[ face.b ];
  13469. fvC = vertices[ face.c ];
  13470. if ( faceMaterial.morphTargets === true ) {
  13471. var morphTargets = geometry.morphTargets;
  13472. var morphInfluences = this.morphTargetInfluences;
  13473. vA.set( 0, 0, 0 );
  13474. vB.set( 0, 0, 0 );
  13475. vC.set( 0, 0, 0 );
  13476. for ( var t = 0, tl = morphTargets.length; t < tl; t ++ ) {
  13477. var influence = morphInfluences[ t ];
  13478. if ( influence === 0 ) continue;
  13479. var targets = morphTargets[ t ].vertices;
  13480. vA.addScaledVector( tempA.subVectors( targets[ face.a ], fvA ), influence );
  13481. vB.addScaledVector( tempB.subVectors( targets[ face.b ], fvB ), influence );
  13482. vC.addScaledVector( tempC.subVectors( targets[ face.c ], fvC ), influence );
  13483. }
  13484. vA.add( fvA );
  13485. vB.add( fvB );
  13486. vC.add( fvC );
  13487. fvA = vA;
  13488. fvB = vB;
  13489. fvC = vC;
  13490. }
  13491. intersection = checkIntersection( this, raycaster, ray, fvA, fvB, fvC, intersectionPoint );
  13492. if ( intersection ) {
  13493. if ( uvs ) {
  13494. var uvs_f = uvs[ f ];
  13495. uvA.copy( uvs_f[ 0 ] );
  13496. uvB.copy( uvs_f[ 1 ] );
  13497. uvC.copy( uvs_f[ 2 ] );
  13498. intersection.uv = uvIntersection( intersectionPoint, fvA, fvB, fvC, uvA, uvB, uvC );
  13499. }
  13500. intersection.face = face;
  13501. intersection.faceIndex = f;
  13502. intersects.push( intersection );
  13503. }
  13504. }
  13505. }
  13506. };
  13507. }() );
  13508. THREE.Mesh.prototype.clone = function () {
  13509. return new this.constructor( this.geometry, this.material ).copy( this );
  13510. };
  13511. // File:src/objects/Bone.js
  13512. /**
  13513. * @author mikael emtinger / http://gomo.se/
  13514. * @author alteredq / http://alteredqualia.com/
  13515. * @author ikerr / http://verold.com
  13516. */
  13517. THREE.Bone = function ( skin ) {
  13518. THREE.Object3D.call( this );
  13519. this.type = 'Bone';
  13520. this.skin = skin;
  13521. };
  13522. THREE.Bone.prototype = Object.create( THREE.Object3D.prototype );
  13523. THREE.Bone.prototype.constructor = THREE.Bone;
  13524. THREE.Bone.prototype.copy = function ( source ) {
  13525. THREE.Object3D.prototype.copy.call( this, source );
  13526. this.skin = source.skin;
  13527. return this;
  13528. };
  13529. // File:src/objects/Skeleton.js
  13530. /**
  13531. * @author mikael emtinger / http://gomo.se/
  13532. * @author alteredq / http://alteredqualia.com/
  13533. * @author michael guerrero / http://realitymeltdown.com
  13534. * @author ikerr / http://verold.com
  13535. */
  13536. THREE.Skeleton = function ( bones, boneInverses, useVertexTexture ) {
  13537. this.useVertexTexture = useVertexTexture !== undefined ? useVertexTexture : true;
  13538. this.identityMatrix = new THREE.Matrix4();
  13539. // copy the bone array
  13540. bones = bones || [];
  13541. this.bones = bones.slice( 0 );
  13542. // create a bone texture or an array of floats
  13543. if ( this.useVertexTexture ) {
  13544. // layout (1 matrix = 4 pixels)
  13545. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  13546. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  13547. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  13548. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  13549. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  13550. var size = Math.sqrt( this.bones.length * 4 ); // 4 pixels needed for 1 matrix
  13551. size = THREE.Math.nextPowerOfTwo( Math.ceil( size ) );
  13552. size = Math.max( size, 4 );
  13553. this.boneTextureWidth = size;
  13554. this.boneTextureHeight = size;
  13555. this.boneMatrices = new Float32Array( this.boneTextureWidth * this.boneTextureHeight * 4 ); // 4 floats per RGBA pixel
  13556. this.boneTexture = new THREE.DataTexture( this.boneMatrices, this.boneTextureWidth, this.boneTextureHeight, THREE.RGBAFormat, THREE.FloatType );
  13557. } else {
  13558. this.boneMatrices = new Float32Array( 16 * this.bones.length );
  13559. }
  13560. // use the supplied bone inverses or calculate the inverses
  13561. if ( boneInverses === undefined ) {
  13562. this.calculateInverses();
  13563. } else {
  13564. if ( this.bones.length === boneInverses.length ) {
  13565. this.boneInverses = boneInverses.slice( 0 );
  13566. } else {
  13567. console.warn( 'THREE.Skeleton bonInverses is the wrong length.' );
  13568. this.boneInverses = [];
  13569. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13570. this.boneInverses.push( new THREE.Matrix4() );
  13571. }
  13572. }
  13573. }
  13574. };
  13575. THREE.Skeleton.prototype.calculateInverses = function () {
  13576. this.boneInverses = [];
  13577. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13578. var inverse = new THREE.Matrix4();
  13579. if ( this.bones[ b ] ) {
  13580. inverse.getInverse( this.bones[ b ].matrixWorld );
  13581. }
  13582. this.boneInverses.push( inverse );
  13583. }
  13584. };
  13585. THREE.Skeleton.prototype.pose = function () {
  13586. var bone;
  13587. // recover the bind-time world matrices
  13588. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13589. bone = this.bones[ b ];
  13590. if ( bone ) {
  13591. bone.matrixWorld.getInverse( this.boneInverses[ b ] );
  13592. }
  13593. }
  13594. // compute the local matrices, positions, rotations and scales
  13595. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13596. bone = this.bones[ b ];
  13597. if ( bone ) {
  13598. if ( bone.parent ) {
  13599. bone.matrix.getInverse( bone.parent.matrixWorld );
  13600. bone.matrix.multiply( bone.matrixWorld );
  13601. } else {
  13602. bone.matrix.copy( bone.matrixWorld );
  13603. }
  13604. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  13605. }
  13606. }
  13607. };
  13608. THREE.Skeleton.prototype.update = ( function () {
  13609. var offsetMatrix = new THREE.Matrix4();
  13610. return function update() {
  13611. // flatten bone matrices to array
  13612. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13613. // compute the offset between the current and the original transform
  13614. var matrix = this.bones[ b ] ? this.bones[ b ].matrixWorld : this.identityMatrix;
  13615. offsetMatrix.multiplyMatrices( matrix, this.boneInverses[ b ] );
  13616. offsetMatrix.flattenToArrayOffset( this.boneMatrices, b * 16 );
  13617. }
  13618. if ( this.useVertexTexture ) {
  13619. this.boneTexture.needsUpdate = true;
  13620. }
  13621. };
  13622. } )();
  13623. THREE.Skeleton.prototype.clone = function () {
  13624. return new THREE.Skeleton( this.bones, this.boneInverses, this.useVertexTexture );
  13625. };
  13626. // File:src/objects/SkinnedMesh.js
  13627. /**
  13628. * @author mikael emtinger / http://gomo.se/
  13629. * @author alteredq / http://alteredqualia.com/
  13630. * @author ikerr / http://verold.com
  13631. */
  13632. THREE.SkinnedMesh = function ( geometry, material, useVertexTexture ) {
  13633. THREE.Mesh.call( this, geometry, material );
  13634. this.type = 'SkinnedMesh';
  13635. this.bindMode = "attached";
  13636. this.bindMatrix = new THREE.Matrix4();
  13637. this.bindMatrixInverse = new THREE.Matrix4();
  13638. // init bones
  13639. // TODO: remove bone creation as there is no reason (other than
  13640. // convenience) for THREE.SkinnedMesh to do this.
  13641. var bones = [];
  13642. if ( this.geometry && this.geometry.bones !== undefined ) {
  13643. var bone, gbone;
  13644. for ( var b = 0, bl = this.geometry.bones.length; b < bl; ++ b ) {
  13645. gbone = this.geometry.bones[ b ];
  13646. bone = new THREE.Bone( this );
  13647. bones.push( bone );
  13648. bone.name = gbone.name;
  13649. bone.position.fromArray( gbone.pos );
  13650. bone.quaternion.fromArray( gbone.rotq );
  13651. if ( gbone.scl !== undefined ) bone.scale.fromArray( gbone.scl );
  13652. }
  13653. for ( var b = 0, bl = this.geometry.bones.length; b < bl; ++ b ) {
  13654. gbone = this.geometry.bones[ b ];
  13655. if ( gbone.parent !== - 1 && gbone.parent !== null ) {
  13656. bones[ gbone.parent ].add( bones[ b ] );
  13657. } else {
  13658. this.add( bones[ b ] );
  13659. }
  13660. }
  13661. }
  13662. this.normalizeSkinWeights();
  13663. this.updateMatrixWorld( true );
  13664. this.bind( new THREE.Skeleton( bones, undefined, useVertexTexture ), this.matrixWorld );
  13665. };
  13666. THREE.SkinnedMesh.prototype = Object.create( THREE.Mesh.prototype );
  13667. THREE.SkinnedMesh.prototype.constructor = THREE.SkinnedMesh;
  13668. THREE.SkinnedMesh.prototype.bind = function( skeleton, bindMatrix ) {
  13669. this.skeleton = skeleton;
  13670. if ( bindMatrix === undefined ) {
  13671. this.updateMatrixWorld( true );
  13672. this.skeleton.calculateInverses();
  13673. bindMatrix = this.matrixWorld;
  13674. }
  13675. this.bindMatrix.copy( bindMatrix );
  13676. this.bindMatrixInverse.getInverse( bindMatrix );
  13677. };
  13678. THREE.SkinnedMesh.prototype.pose = function () {
  13679. this.skeleton.pose();
  13680. };
  13681. THREE.SkinnedMesh.prototype.normalizeSkinWeights = function () {
  13682. if ( this.geometry instanceof THREE.Geometry ) {
  13683. for ( var i = 0; i < this.geometry.skinWeights.length; i ++ ) {
  13684. var sw = this.geometry.skinWeights[ i ];
  13685. var scale = 1.0 / sw.lengthManhattan();
  13686. if ( scale !== Infinity ) {
  13687. sw.multiplyScalar( scale );
  13688. } else {
  13689. sw.set( 1, 0, 0, 0 ); // do something reasonable
  13690. }
  13691. }
  13692. } else if ( this.geometry instanceof THREE.BufferGeometry ) {
  13693. var vec = new THREE.Vector4();
  13694. var skinWeight = this.geometry.attributes.skinWeight;
  13695. for ( var i = 0; i < skinWeight.count; i ++ ) {
  13696. vec.x = skinWeight.getX( i );
  13697. vec.y = skinWeight.getY( i );
  13698. vec.z = skinWeight.getZ( i );
  13699. vec.w = skinWeight.getW( i );
  13700. var scale = 1.0 / vec.lengthManhattan();
  13701. if ( scale !== Infinity ) {
  13702. vec.multiplyScalar( scale );
  13703. } else {
  13704. vec.set( 1, 0, 0, 0 ); // do something reasonable
  13705. }
  13706. skinWeight.setXYZW( i, vec.x, vec.y, vec.z, vec.w );
  13707. }
  13708. }
  13709. };
  13710. THREE.SkinnedMesh.prototype.updateMatrixWorld = function( force ) {
  13711. THREE.Mesh.prototype.updateMatrixWorld.call( this, true );
  13712. if ( this.bindMode === "attached" ) {
  13713. this.bindMatrixInverse.getInverse( this.matrixWorld );
  13714. } else if ( this.bindMode === "detached" ) {
  13715. this.bindMatrixInverse.getInverse( this.bindMatrix );
  13716. } else {
  13717. console.warn( 'THREE.SkinnedMesh unrecognized bindMode: ' + this.bindMode );
  13718. }
  13719. };
  13720. THREE.SkinnedMesh.prototype.clone = function() {
  13721. return new this.constructor( this.geometry, this.material, this.useVertexTexture ).copy( this );
  13722. };
  13723. // File:src/objects/LOD.js
  13724. /**
  13725. * @author mikael emtinger / http://gomo.se/
  13726. * @author alteredq / http://alteredqualia.com/
  13727. * @author mrdoob / http://mrdoob.com/
  13728. */
  13729. THREE.LOD = function () {
  13730. THREE.Object3D.call( this );
  13731. this.type = 'LOD';
  13732. Object.defineProperties( this, {
  13733. levels: {
  13734. enumerable: true,
  13735. value: []
  13736. },
  13737. objects: {
  13738. get: function () {
  13739. console.warn( 'THREE.LOD: .objects has been renamed to .levels.' );
  13740. return this.levels;
  13741. }
  13742. }
  13743. } );
  13744. };
  13745. THREE.LOD.prototype = Object.create( THREE.Object3D.prototype );
  13746. THREE.LOD.prototype.constructor = THREE.LOD;
  13747. THREE.LOD.prototype.addLevel = function ( object, distance ) {
  13748. if ( distance === undefined ) distance = 0;
  13749. distance = Math.abs( distance );
  13750. var levels = this.levels;
  13751. for ( var l = 0; l < levels.length; l ++ ) {
  13752. if ( distance < levels[ l ].distance ) {
  13753. break;
  13754. }
  13755. }
  13756. levels.splice( l, 0, { distance: distance, object: object } );
  13757. this.add( object );
  13758. };
  13759. THREE.LOD.prototype.getObjectForDistance = function ( distance ) {
  13760. var levels = this.levels;
  13761. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  13762. if ( distance < levels[ i ].distance ) {
  13763. break;
  13764. }
  13765. }
  13766. return levels[ i - 1 ].object;
  13767. };
  13768. THREE.LOD.prototype.raycast = ( function () {
  13769. var matrixPosition = new THREE.Vector3();
  13770. return function raycast( raycaster, intersects ) {
  13771. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  13772. var distance = raycaster.ray.origin.distanceTo( matrixPosition );
  13773. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  13774. };
  13775. }() );
  13776. THREE.LOD.prototype.update = function () {
  13777. var v1 = new THREE.Vector3();
  13778. var v2 = new THREE.Vector3();
  13779. return function update( camera ) {
  13780. var levels = this.levels;
  13781. if ( levels.length > 1 ) {
  13782. v1.setFromMatrixPosition( camera.matrixWorld );
  13783. v2.setFromMatrixPosition( this.matrixWorld );
  13784. var distance = v1.distanceTo( v2 );
  13785. levels[ 0 ].object.visible = true;
  13786. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  13787. if ( distance >= levels[ i ].distance ) {
  13788. levels[ i - 1 ].object.visible = false;
  13789. levels[ i ].object.visible = true;
  13790. } else {
  13791. break;
  13792. }
  13793. }
  13794. for ( ; i < l; i ++ ) {
  13795. levels[ i ].object.visible = false;
  13796. }
  13797. }
  13798. };
  13799. }();
  13800. THREE.LOD.prototype.copy = function ( source ) {
  13801. THREE.Object3D.prototype.copy.call( this, source, false );
  13802. var levels = source.levels;
  13803. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  13804. var level = levels[ i ];
  13805. this.addLevel( level.object.clone(), level.distance );
  13806. }
  13807. return this;
  13808. };
  13809. THREE.LOD.prototype.toJSON = function ( meta ) {
  13810. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  13811. data.object.levels = [];
  13812. var levels = this.levels;
  13813. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  13814. var level = levels[ i ];
  13815. data.object.levels.push( {
  13816. object: level.object.uuid,
  13817. distance: level.distance
  13818. } );
  13819. }
  13820. return data;
  13821. };
  13822. // File:src/objects/Sprite.js
  13823. /**
  13824. * @author mikael emtinger / http://gomo.se/
  13825. * @author alteredq / http://alteredqualia.com/
  13826. */
  13827. THREE.Sprite = ( function () {
  13828. var indices = new Uint16Array( [ 0, 1, 2, 0, 2, 3 ] );
  13829. var vertices = new Float32Array( [ - 0.5, - 0.5, 0, 0.5, - 0.5, 0, 0.5, 0.5, 0, - 0.5, 0.5, 0 ] );
  13830. var uvs = new Float32Array( [ 0, 0, 1, 0, 1, 1, 0, 1 ] );
  13831. var geometry = new THREE.BufferGeometry();
  13832. geometry.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  13833. geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  13834. geometry.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  13835. return function Sprite( material ) {
  13836. THREE.Object3D.call( this );
  13837. this.type = 'Sprite';
  13838. this.geometry = geometry;
  13839. this.material = ( material !== undefined ) ? material : new THREE.SpriteMaterial();
  13840. };
  13841. } )();
  13842. THREE.Sprite.prototype = Object.create( THREE.Object3D.prototype );
  13843. THREE.Sprite.prototype.constructor = THREE.Sprite;
  13844. THREE.Sprite.prototype.raycast = ( function () {
  13845. var matrixPosition = new THREE.Vector3();
  13846. return function raycast( raycaster, intersects ) {
  13847. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  13848. var distanceSq = raycaster.ray.distanceSqToPoint( matrixPosition );
  13849. var guessSizeSq = this.scale.x * this.scale.y / 4;
  13850. if ( distanceSq > guessSizeSq ) {
  13851. return;
  13852. }
  13853. intersects.push( {
  13854. distance: Math.sqrt( distanceSq ),
  13855. point: this.position,
  13856. face: null,
  13857. object: this
  13858. } );
  13859. };
  13860. }() );
  13861. THREE.Sprite.prototype.clone = function () {
  13862. return new this.constructor( this.material ).copy( this );
  13863. };
  13864. // Backwards compatibility
  13865. THREE.Particle = THREE.Sprite;
  13866. // File:src/objects/LensFlare.js
  13867. /**
  13868. * @author mikael emtinger / http://gomo.se/
  13869. * @author alteredq / http://alteredqualia.com/
  13870. */
  13871. THREE.LensFlare = function ( texture, size, distance, blending, color ) {
  13872. THREE.Object3D.call( this );
  13873. this.lensFlares = [];
  13874. this.positionScreen = new THREE.Vector3();
  13875. this.customUpdateCallback = undefined;
  13876. if ( texture !== undefined ) {
  13877. this.add( texture, size, distance, blending, color );
  13878. }
  13879. };
  13880. THREE.LensFlare.prototype = Object.create( THREE.Object3D.prototype );
  13881. THREE.LensFlare.prototype.constructor = THREE.LensFlare;
  13882. /*
  13883. * Add: adds another flare
  13884. */
  13885. THREE.LensFlare.prototype.add = function ( texture, size, distance, blending, color, opacity ) {
  13886. if ( size === undefined ) size = - 1;
  13887. if ( distance === undefined ) distance = 0;
  13888. if ( opacity === undefined ) opacity = 1;
  13889. if ( color === undefined ) color = new THREE.Color( 0xffffff );
  13890. if ( blending === undefined ) blending = THREE.NormalBlending;
  13891. distance = Math.min( distance, Math.max( 0, distance ) );
  13892. this.lensFlares.push( {
  13893. texture: texture, // THREE.Texture
  13894. size: size, // size in pixels (-1 = use texture.width)
  13895. distance: distance, // distance (0-1) from light source (0=at light source)
  13896. x: 0, y: 0, z: 0, // screen position (-1 => 1) z = 0 is in front z = 1 is back
  13897. scale: 1, // scale
  13898. rotation: 0, // rotation
  13899. opacity: opacity, // opacity
  13900. color: color, // color
  13901. blending: blending // blending
  13902. } );
  13903. };
  13904. /*
  13905. * Update lens flares update positions on all flares based on the screen position
  13906. * Set myLensFlare.customUpdateCallback to alter the flares in your project specific way.
  13907. */
  13908. THREE.LensFlare.prototype.updateLensFlares = function () {
  13909. var f, fl = this.lensFlares.length;
  13910. var flare;
  13911. var vecX = - this.positionScreen.x * 2;
  13912. var vecY = - this.positionScreen.y * 2;
  13913. for ( f = 0; f < fl; f ++ ) {
  13914. flare = this.lensFlares[ f ];
  13915. flare.x = this.positionScreen.x + vecX * flare.distance;
  13916. flare.y = this.positionScreen.y + vecY * flare.distance;
  13917. flare.wantedRotation = flare.x * Math.PI * 0.25;
  13918. flare.rotation += ( flare.wantedRotation - flare.rotation ) * 0.25;
  13919. }
  13920. };
  13921. THREE.LensFlare.prototype.copy = function ( source ) {
  13922. THREE.Object3D.prototype.copy.call( this, source );
  13923. this.positionScreen.copy( source.positionScreen );
  13924. this.customUpdateCallback = source.customUpdateCallback;
  13925. for ( var i = 0, l = source.lensFlares.length; i < l; i ++ ) {
  13926. this.lensFlares.push( source.lensFlares[ i ] );
  13927. }
  13928. return this;
  13929. };
  13930. // File:src/scenes/Scene.js
  13931. /**
  13932. * @author mrdoob / http://mrdoob.com/
  13933. */
  13934. THREE.Scene = function () {
  13935. THREE.Object3D.call( this );
  13936. this.type = 'Scene';
  13937. this.fog = null;
  13938. this.overrideMaterial = null;
  13939. this.autoUpdate = true; // checked by the renderer
  13940. };
  13941. THREE.Scene.prototype = Object.create( THREE.Object3D.prototype );
  13942. THREE.Scene.prototype.constructor = THREE.Scene;
  13943. THREE.Scene.prototype.copy = function ( source, recursive ) {
  13944. THREE.Object3D.prototype.copy.call( this, source, recursive );
  13945. if ( source.fog !== null ) this.fog = source.fog.clone();
  13946. if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
  13947. this.autoUpdate = source.autoUpdate;
  13948. this.matrixAutoUpdate = source.matrixAutoUpdate;
  13949. return this;
  13950. };
  13951. // File:src/scenes/Fog.js
  13952. /**
  13953. * @author mrdoob / http://mrdoob.com/
  13954. * @author alteredq / http://alteredqualia.com/
  13955. */
  13956. THREE.Fog = function ( color, near, far ) {
  13957. this.name = '';
  13958. this.color = new THREE.Color( color );
  13959. this.near = ( near !== undefined ) ? near : 1;
  13960. this.far = ( far !== undefined ) ? far : 1000;
  13961. };
  13962. THREE.Fog.prototype.clone = function () {
  13963. return new THREE.Fog( this.color.getHex(), this.near, this.far );
  13964. };
  13965. // File:src/scenes/FogExp2.js
  13966. /**
  13967. * @author mrdoob / http://mrdoob.com/
  13968. * @author alteredq / http://alteredqualia.com/
  13969. */
  13970. THREE.FogExp2 = function ( color, density ) {
  13971. this.name = '';
  13972. this.color = new THREE.Color( color );
  13973. this.density = ( density !== undefined ) ? density : 0.00025;
  13974. };
  13975. THREE.FogExp2.prototype.clone = function () {
  13976. return new THREE.FogExp2( this.color.getHex(), this.density );
  13977. };
  13978. // File:src/renderers/shaders/ShaderChunk.js
  13979. THREE.ShaderChunk = {};
  13980. // File:src/renderers/shaders/ShaderChunk/alphamap_fragment.glsl
  13981. THREE.ShaderChunk[ 'alphamap_fragment' ] = "#ifdef USE_ALPHAMAP\n diffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif\n";
  13982. // File:src/renderers/shaders/ShaderChunk/alphamap_pars_fragment.glsl
  13983. THREE.ShaderChunk[ 'alphamap_pars_fragment' ] = "#ifdef USE_ALPHAMAP\n uniform sampler2D alphaMap;\n#endif\n";
  13984. // File:src/renderers/shaders/ShaderChunk/alphatest_fragment.glsl
  13985. THREE.ShaderChunk[ 'alphatest_fragment' ] = "#ifdef ALPHATEST\n if ( diffuseColor.a < ALPHATEST ) discard;\n#endif\n";
  13986. // File:src/renderers/shaders/ShaderChunk/aomap_fragment.glsl
  13987. THREE.ShaderChunk[ 'aomap_fragment' ] = "#ifdef USE_AOMAP\n float ambientOcclusion = ( texture2D( aoMap, vUv2 ).r - 1.0 ) * aoMapIntensity + 1.0;\n reflectedLight.indirectDiffuse *= ambientOcclusion;\n #if defined( USE_ENVMAP ) && defined( STANDARD )\n float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n reflectedLight.indirectSpecular *= computeSpecularOcclusion( dotNV, ambientOcclusion, material.specularRoughness );\n #endif\n#endif\n";
  13988. // File:src/renderers/shaders/ShaderChunk/aomap_pars_fragment.glsl
  13989. THREE.ShaderChunk[ 'aomap_pars_fragment' ] = "#ifdef USE_AOMAP\n uniform sampler2D aoMap;\n uniform float aoMapIntensity;\n#endif";
  13990. // File:src/renderers/shaders/ShaderChunk/begin_vertex.glsl
  13991. THREE.ShaderChunk[ 'begin_vertex' ] = "\nvec3 transformed = vec3( position );\n";
  13992. // File:src/renderers/shaders/ShaderChunk/beginnormal_vertex.glsl
  13993. THREE.ShaderChunk[ 'beginnormal_vertex' ] = "\nvec3 objectNormal = vec3( normal );\n";
  13994. // File:src/renderers/shaders/ShaderChunk/bsdfs.glsl
  13995. 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";
  13996. // File:src/renderers/shaders/ShaderChunk/bumpmap_pars_fragment.glsl
  13997. 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";
  13998. // File:src/renderers/shaders/ShaderChunk/color_fragment.glsl
  13999. THREE.ShaderChunk[ 'color_fragment' ] = "#ifdef USE_COLOR\n diffuseColor.rgb *= vColor;\n#endif";
  14000. // File:src/renderers/shaders/ShaderChunk/color_pars_fragment.glsl
  14001. THREE.ShaderChunk[ 'color_pars_fragment' ] = "#ifdef USE_COLOR\n varying vec3 vColor;\n#endif\n";
  14002. // File:src/renderers/shaders/ShaderChunk/color_pars_vertex.glsl
  14003. THREE.ShaderChunk[ 'color_pars_vertex' ] = "#ifdef USE_COLOR\n varying vec3 vColor;\n#endif";
  14004. // File:src/renderers/shaders/ShaderChunk/color_vertex.glsl
  14005. THREE.ShaderChunk[ 'color_vertex' ] = "#ifdef USE_COLOR\n vColor.xyz = color.xyz;\n#endif";
  14006. // File:src/renderers/shaders/ShaderChunk/common.glsl
  14007. THREE.ShaderChunk[ 'common' ] = "#define PI 3.14159\n#define PI2 6.28318\n#define RECIPROCAL_PI 0.31830988618\n#define RECIPROCAL_PI2 0.15915494\n#define LOG2 1.442695\n#define EPSILON 1e-6\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#define whiteCompliment(a) ( 1.0 - saturate( a ) )\nfloat pow2( const in float x ) { return x*x; }\nfloat pow3( const in float x ) { return x*x*x; }\nfloat pow4( const in float x ) { float x2 = x*x; return x2*x2; }\nfloat average( const in vec3 color ) { return dot( color, vec3( 0.3333 ) ); }\nstruct IncidentLight {\n vec3 color;\n vec3 direction;\n bool visible;\n};\nstruct ReflectedLight {\n vec3 directDiffuse;\n vec3 directSpecular;\n vec3 indirectDiffuse;\n vec3 indirectSpecular;\n};\nstruct GeometricContext {\n vec3 position;\n vec3 normal;\n vec3 viewDir;\n};\nvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n}\nvec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {\n return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );\n}\nvec3 projectOnPlane(in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n float distance = dot( planeNormal, point - pointOnPlane );\n return - distance * planeNormal + point;\n}\nfloat sideOfPlane( in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n return sign( dot( point - pointOnPlane, planeNormal ) );\n}\nvec3 linePlaneIntersect( in vec3 pointOnLine, in vec3 lineDirection, in vec3 pointOnPlane, in vec3 planeNormal ) {\n return lineDirection * ( dot( planeNormal, pointOnPlane - pointOnLine ) / dot( planeNormal, lineDirection ) ) + pointOnLine;\n}\n";
  14008. // File:src/renderers/shaders/ShaderChunk/cube_uv_reflection_fragment.glsl
  14009. THREE.ShaderChunk[ 'cube_uv_reflection_fragment' ] = "#ifdef ENVMAP_TYPE_CUBE_UV\nconst float cubeUV_textureSize = 1024.0;\nint getFaceFromDirection(vec3 direction) {\n vec3 absDirection = abs(direction);\n int face = -1;\n if( absDirection.x > absDirection.z ) {\n if(absDirection.x > absDirection.y )\n face = direction.x > 0.0 ? 0 : 3;\n else\n face = direction.y > 0.0 ? 1 : 4;\n }\n else {\n if(absDirection.z > absDirection.y )\n face = direction.z > 0.0 ? 2 : 5;\n else\n face = direction.y > 0.0 ? 1 : 4;\n }\n return face;\n}\nfloat cubeUV_maxLods1 = log2(cubeUV_textureSize*0.25) - 1.0;\nfloat 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}\nfloat cubeUV_maxLods2 = log2(cubeUV_textureSize*0.25) - 2.0;\nconst float cubeUV_rcpTextureSize = 1.0 / cubeUV_textureSize;\nvec2 getCubeUV(vec3 direction, float roughnessLevel, float mipLevel) {\n mipLevel = roughnessLevel > cubeUV_maxLods2 - 3.0 ? 0.0 : mipLevel;\n float a = 16.0 * cubeUV_rcpTextureSize;\n vec2 exp2_packed = exp2( vec2( roughnessLevel, mipLevel ) );\n vec2 rcp_exp2_packed = vec2( 1.0 ) / exp2_packed;\n float powScale = exp2_packed.x * exp2_packed.y;\n float scale = rcp_exp2_packed.x * rcp_exp2_packed.y * 0.25;\n float mipOffset = 0.75*(1.0 - rcp_exp2_packed.y) * rcp_exp2_packed.x;\n bool bRes = mipLevel == 0.0;\n scale = bRes && (scale < a) ? a : scale;\n vec3 r;\n vec2 offset;\n int face = getFaceFromDirection(direction);\n float rcpPowScale = 1.0 / powScale;\n if( face == 0) {\n r = vec3(direction.x, -direction.z, direction.y);\n offset = vec2(0.0+mipOffset,0.75 * rcpPowScale);\n offset.y = bRes && (offset.y < 2.0*a) ? a : offset.y;\n }\n else if( face == 1) {\n r = vec3(direction.y, direction.x, direction.z);\n offset = vec2(scale+mipOffset, 0.75 * rcpPowScale);\n offset.y = bRes && (offset.y < 2.0*a) ? a : offset.y;\n }\n else if( face == 2) {\n r = vec3(direction.z, direction.x, direction.y);\n offset = vec2(2.0*scale+mipOffset, 0.75 * rcpPowScale);\n offset.y = bRes && (offset.y < 2.0*a) ? a : offset.y;\n }\n else if( face == 3) {\n r = vec3(direction.x, direction.z, direction.y);\n offset = vec2(0.0+mipOffset,0.5 * rcpPowScale);\n offset.y = bRes && (offset.y < 2.0*a) ? 0.0 : offset.y;\n }\n else if( face == 4) {\n r = vec3(direction.y, direction.x, -direction.z);\n offset = vec2(scale+mipOffset, 0.5 * rcpPowScale);\n offset.y = bRes && (offset.y < 2.0*a) ? 0.0 : offset.y;\n }\n else {\n r = vec3(direction.z, -direction.x, direction.y);\n offset = vec2(2.0*scale+mipOffset, 0.5 * rcpPowScale);\n offset.y = bRes && (offset.y < 2.0*a) ? 0.0 : offset.y;\n }\n r = normalize(r);\n float texelOffset = 0.5 * cubeUV_rcpTextureSize;\n vec2 s = ( r.yz / abs( r.x ) + vec2( 1.0 ) ) * 0.5;\n vec2 base = offset + vec2( texelOffset );\n return base + s * ( scale - 2.0 * texelOffset );\n}\nfloat 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";
  14010. // File:src/renderers/shaders/ShaderChunk/defaultnormal_vertex.glsl
  14011. THREE.ShaderChunk[ 'defaultnormal_vertex' ] = "#ifdef FLIP_SIDED\n objectNormal = -objectNormal;\n#endif\nvec3 transformedNormal = normalMatrix * objectNormal;\n";
  14012. // File:src/renderers/shaders/ShaderChunk/displacementmap_vertex.glsl
  14013. THREE.ShaderChunk[ 'displacementmap_vertex' ] = "#ifdef USE_DISPLACEMENTMAP\n transformed += normal * ( texture2D( displacementMap, uv ).x * displacementScale + displacementBias );\n#endif\n";
  14014. // File:src/renderers/shaders/ShaderChunk/displacementmap_pars_vertex.glsl
  14015. THREE.ShaderChunk[ 'displacementmap_pars_vertex' ] = "#ifdef USE_DISPLACEMENTMAP\n uniform sampler2D displacementMap;\n uniform float displacementScale;\n uniform float displacementBias;\n#endif\n";
  14016. // File:src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl
  14017. 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";
  14018. // File:src/renderers/shaders/ShaderChunk/emissivemap_pars_fragment.glsl
  14019. THREE.ShaderChunk[ 'emissivemap_pars_fragment' ] = "#ifdef USE_EMISSIVEMAP\n uniform sampler2D emissiveMap;\n#endif\n";
  14020. // File:src/renderers/shaders/ShaderChunk/encodings_pars_fragment.glsl
  14021. 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";
  14022. // File:src/renderers/shaders/ShaderChunk/encodings_fragment.glsl
  14023. THREE.ShaderChunk[ 'encodings_fragment' ] = " gl_FragColor = linearToOutputTexel( gl_FragColor );\n";
  14024. // File:src/renderers/shaders/ShaderChunk/envmap_fragment.glsl
  14025. 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";
  14026. // File:src/renderers/shaders/ShaderChunk/envmap_pars_fragment.glsl
  14027. THREE.ShaderChunk[ 'envmap_pars_fragment' ] = "#if defined( USE_ENVMAP ) || defined( STANDARD )\n uniform float reflectivity;\n uniform float envMapIntenstiy;\n#endif\n#ifdef USE_ENVMAP\n #if ! defined( STANDARD ) && ( 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( STANDARD )\n uniform float refractionRatio;\n #else\n varying vec3 vReflect;\n #endif\n#endif\n";
  14028. // File:src/renderers/shaders/ShaderChunk/envmap_pars_vertex.glsl
  14029. 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";
  14030. // File:src/renderers/shaders/ShaderChunk/envmap_vertex.glsl
  14031. 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";
  14032. // File:src/renderers/shaders/ShaderChunk/fog_fragment.glsl
  14033. 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";
  14034. // File:src/renderers/shaders/ShaderChunk/fog_pars_fragment.glsl
  14035. 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";
  14036. // File:src/renderers/shaders/ShaderChunk/lightmap_fragment.glsl
  14037. THREE.ShaderChunk[ 'lightmap_fragment' ] = "#ifdef USE_LIGHTMAP\n reflectedLight.indirectDiffuse += PI * texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n#endif\n";
  14038. // File:src/renderers/shaders/ShaderChunk/lightmap_pars_fragment.glsl
  14039. THREE.ShaderChunk[ 'lightmap_pars_fragment' ] = "#ifdef USE_LIGHTMAP\n uniform sampler2D lightMap;\n uniform float lightMapIntensity;\n#endif";
  14040. // File:src/renderers/shaders/ShaderChunk/lights_lambert_vertex.glsl
  14041. THREE.ShaderChunk[ 'lights_lambert_vertex' ] = "vec3 diffuse = vec3( 1.0 );\nGeometricContext geometry;\ngeometry.position = mvPosition.xyz;\ngeometry.normal = normalize( transformedNormal );\ngeometry.viewDir = normalize( -mvPosition.xyz );\nGeometricContext backGeometry;\nbackGeometry.position = geometry.position;\nbackGeometry.normal = -geometry.normal;\nbackGeometry.viewDir = geometry.viewDir;\nvLightFront = vec3( 0.0 );\n#ifdef DOUBLE_SIDED\n vLightBack = vec3( 0.0 );\n#endif\nIncidentLight directLight;\nfloat dotNL;\nvec3 directLightColor_Diffuse;\n#if NUM_POINT_LIGHTS > 0\n for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n directLight = getPointDirectLightIrradiance( pointLights[ i ], geometry );\n dotNL = dot( geometry.normal, directLight.direction );\n directLightColor_Diffuse = PI * directLight.color;\n vLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n #ifdef DOUBLE_SIDED\n vLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n #endif\n }\n#endif\n#if NUM_SPOT_LIGHTS > 0\n for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n directLight = getSpotDirectLightIrradiance( spotLights[ i ], geometry );\n dotNL = dot( geometry.normal, directLight.direction );\n directLightColor_Diffuse = PI * directLight.color;\n vLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n #ifdef DOUBLE_SIDED\n vLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n #endif\n }\n#endif\n#if NUM_DIR_LIGHTS > 0\n for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n directLight = getDirectionalDirectLightIrradiance( directionalLights[ i ], geometry );\n dotNL = dot( geometry.normal, directLight.direction );\n directLightColor_Diffuse = PI * directLight.color;\n vLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n #ifdef DOUBLE_SIDED\n vLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n #endif\n }\n#endif\n#if NUM_HEMI_LIGHTS > 0\n for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n vLightFront += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry );\n #ifdef DOUBLE_SIDED\n vLightBack += getHemisphereLightIrradiance( hemisphereLights[ i ], backGeometry );\n #endif\n }\n#endif\n";
  14042. // File:src/renderers/shaders/ShaderChunk/lights_pars.glsl
  14043. THREE.ShaderChunk[ 'lights_pars' ] = "uniform vec3 ambientLightColor;\nvec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {\n vec3 irradiance = ambientLightColor;\n #ifndef PHYSICALLY_CORRECT_LIGHTS\n irradiance *= PI;\n #endif\n return irradiance;\n}\n#if NUM_DIR_LIGHTS > 0\n struct DirectionalLight {\n vec3 direction;\n vec3 color;\n int shadow;\n float shadowBias;\n float shadowRadius;\n vec2 shadowMapSize;\n };\n uniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];\n IncidentLight getDirectionalDirectLightIrradiance( const in DirectionalLight directionalLight, const in GeometricContext geometry ) {\n IncidentLight directLight;\n directLight.color = directionalLight.color;\n directLight.direction = directionalLight.direction;\n directLight.visible = true;\n return directLight;\n }\n#endif\n#if NUM_POINT_LIGHTS > 0\n struct PointLight {\n vec3 position;\n vec3 color;\n float distance;\n float decay;\n int shadow;\n float shadowBias;\n float shadowRadius;\n vec2 shadowMapSize;\n };\n uniform PointLight pointLights[ NUM_POINT_LIGHTS ];\n IncidentLight getPointDirectLightIrradiance( const in PointLight pointLight, const in GeometricContext geometry ) {\n IncidentLight directLight;\n vec3 lVector = pointLight.position - geometry.position;\n directLight.direction = normalize( lVector );\n float lightDistance = length( lVector );\n if ( testLightInRange( lightDistance, pointLight.distance ) ) {\n directLight.color = pointLight.color;\n directLight.color *= punctualLightIntensityToIrradianceFactor( lightDistance, pointLight.distance, pointLight.decay );\n directLight.visible = true;\n } else {\n directLight.color = vec3( 0.0 );\n directLight.visible = false;\n }\n return directLight;\n }\n#endif\n#if NUM_SPOT_LIGHTS > 0\n struct SpotLight {\n vec3 position;\n vec3 direction;\n vec3 color;\n float distance;\n float decay;\n float coneCos;\n float penumbraCos;\n int shadow;\n float shadowBias;\n float shadowRadius;\n vec2 shadowMapSize;\n };\n uniform SpotLight spotLights[ NUM_SPOT_LIGHTS ];\n IncidentLight getSpotDirectLightIrradiance( const in SpotLight spotLight, const in GeometricContext geometry ) {\n IncidentLight directLight;\n vec3 lVector = spotLight.position - geometry.position;\n directLight.direction = normalize( lVector );\n float lightDistance = length( lVector );\n float angleCos = dot( directLight.direction, spotLight.direction );\n if ( all( bvec2( angleCos > spotLight.coneCos, testLightInRange( lightDistance, spotLight.distance ) ) ) ) {\n float spotEffect = smoothstep( spotLight.coneCos, spotLight.penumbraCos, angleCos );\n directLight.color = spotLight.color;\n directLight.color *= spotEffect * punctualLightIntensityToIrradianceFactor( lightDistance, spotLight.distance, spotLight.decay );\n directLight.visible = true;\n } else {\n directLight.color = vec3( 0.0 );\n directLight.visible = false;\n }\n return directLight;\n }\n#endif\n#if NUM_HEMI_LIGHTS > 0\n struct HemisphereLight {\n vec3 direction;\n vec3 skyColor;\n vec3 groundColor;\n };\n uniform HemisphereLight hemisphereLights[ NUM_HEMI_LIGHTS ];\n vec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in GeometricContext geometry ) {\n float dotNL = dot( geometry.normal, hemiLight.direction );\n float hemiDiffuseWeight = 0.5 * dotNL + 0.5;\n vec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );\n #ifndef PHYSICALLY_CORRECT_LIGHTS\n irradiance *= PI;\n #endif\n return irradiance;\n }\n#endif\n#if defined( USE_ENVMAP ) && defined( STANDARD )\n vec3 getLightProbeIndirectIrradiance( const in GeometricContext geometry, const in int maxMIPLevel ) {\n #ifdef DOUBLE_SIDED\n float flipNormal = ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n #else\n float flipNormal = 1.0;\n #endif\n vec3 worldNormal = inverseTransformDirection( geometry.normal, viewMatrix );\n #ifdef ENVMAP_TYPE_CUBE\n vec3 queryVec = flipNormal * vec3( flipEnvMap * worldNormal.x, worldNormal.yz );\n #ifdef TEXTURE_LOD_EXT\n vec4 envMapColor = textureCubeLodEXT( envMap, queryVec, float( maxMIPLevel ) );\n #else\n vec4 envMapColor = textureCube( envMap, queryVec, float( maxMIPLevel ) );\n #endif\n #elif defined( ENVMAP_TYPE_CUBE_UV )\n vec3 queryVec = flipNormal * vec3( flipEnvMap * worldNormal.x, worldNormal.yz );\n vec4 envMapColor = textureCubeUV( queryVec, 1.0 );\n #else\n vec4 envMapColor = vec4( 0.0 );\n #endif\n envMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\n return PI * envMapColor.rgb * envMapIntensity;\n }\n float getSpecularMIPLevel( const in float blinnShininessExponent, const in int maxMIPLevel ) {\n float maxMIPLevelScalar = float( maxMIPLevel );\n float desiredMIPLevel = maxMIPLevelScalar - 0.79248 - 0.5 * log2( pow2( blinnShininessExponent ) + 1.0 );\n return clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );\n }\n vec3 getLightProbeIndirectRadiance( const in GeometricContext geometry, const in float blinnShininessExponent, const in int maxMIPLevel ) {\n #ifdef ENVMAP_MODE_REFLECTION\n vec3 reflectVec = reflect( -geometry.viewDir, geometry.normal );\n #else\n vec3 reflectVec = refract( -geometry.viewDir, geometry.normal, refractionRatio );\n #endif\n #ifdef DOUBLE_SIDED\n float flipNormal = ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n #else\n float flipNormal = 1.0;\n #endif\n reflectVec = inverseTransformDirection( reflectVec, viewMatrix );\n float specularMIPLevel = getSpecularMIPLevel( blinnShininessExponent, maxMIPLevel );\n #ifdef ENVMAP_TYPE_CUBE\n vec3 queryReflectVec = flipNormal * vec3( flipEnvMap * reflectVec.x, reflectVec.yz );\n #ifdef TEXTURE_LOD_EXT\n vec4 envMapColor = textureCubeLodEXT( envMap, queryReflectVec, specularMIPLevel );\n #else\n vec4 envMapColor = textureCube( envMap, queryReflectVec, specularMIPLevel );\n #endif\n #elif defined( ENVMAP_TYPE_CUBE_UV )\n vec3 queryReflectVec = flipNormal * vec3( flipEnvMap * reflectVec.x, reflectVec.yz );\n vec4 envMapColor = textureCubeUV(queryReflectVec, BlinnExponentToGGXRoughness(blinnShininessExponent));\n #elif defined( ENVMAP_TYPE_EQUIREC )\n vec2 sampleUV;\n sampleUV.y = saturate( flipNormal * reflectVec.y * 0.5 + 0.5 );\n sampleUV.x = atan( flipNormal * reflectVec.z, flipNormal * reflectVec.x ) * RECIPROCAL_PI2 + 0.5;\n #ifdef TEXTURE_LOD_EXT\n vec4 envMapColor = texture2DLodEXT( envMap, sampleUV, specularMIPLevel );\n #else\n vec4 envMapColor = texture2D( envMap, sampleUV, specularMIPLevel );\n #endif\n #elif defined( ENVMAP_TYPE_SPHERE )\n vec3 reflectView = flipNormal * normalize((viewMatrix * vec4( reflectVec, 0.0 )).xyz + vec3(0.0,0.0,1.0));\n #ifdef TEXTURE_LOD_EXT\n vec4 envMapColor = texture2DLodEXT( envMap, reflectView.xy * 0.5 + 0.5, specularMIPLevel );\n #else\n vec4 envMapColor = texture2D( envMap, reflectView.xy * 0.5 + 0.5, specularMIPLevel );\n #endif\n #endif\n envMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\n return envMapColor.rgb * envMapIntensity;\n }\n#endif\n";
  14044. // File:src/renderers/shaders/ShaderChunk/lights_phong_fragment.glsl
  14045. THREE.ShaderChunk[ 'lights_phong_fragment' ] = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;\n";
  14046. // File:src/renderers/shaders/ShaderChunk/lights_phong_pars_fragment.glsl
  14047. 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";
  14048. // File:src/renderers/shaders/ShaderChunk/lights_standard_fragment.glsl
  14049. THREE.ShaderChunk[ 'lights_standard_fragment' ] = "StandardMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );\nmaterial.specularRoughness = clamp( roughnessFactor, 0.04, 1.0 );\nmaterial.specularColor = mix( vec3( 0.04 ), diffuseColor.rgb, metalnessFactor );\n";
  14050. // File:src/renderers/shaders/ShaderChunk/lights_standard_pars_fragment.glsl
  14051. THREE.ShaderChunk[ 'lights_standard_pars_fragment' ] = "struct StandardMaterial {\n vec3 diffuseColor;\n float specularRoughness;\n vec3 specularColor;\n};\nvoid RE_Direct_Standard( const in IncidentLight directLight, const in GeometricContext geometry, const in StandardMaterial material, inout ReflectedLight reflectedLight ) {\n float dotNL = saturate( dot( geometry.normal, directLight.direction ) );\n vec3 irradiance = dotNL * directLight.color;\n #ifndef PHYSICALLY_CORRECT_LIGHTS\n irradiance *= PI;\n #endif\n reflectedLight.directDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n reflectedLight.directSpecular += irradiance * BRDF_Specular_GGX( directLight, geometry, material.specularColor, material.specularRoughness );\n}\nvoid RE_IndirectDiffuse_Standard( const in vec3 irradiance, const in GeometricContext geometry, const in StandardMaterial material, inout ReflectedLight reflectedLight ) {\n reflectedLight.indirectDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectSpecular_Standard( const in vec3 radiance, const in GeometricContext geometry, const in StandardMaterial material, inout ReflectedLight reflectedLight ) {\n reflectedLight.indirectSpecular += radiance * BRDF_Specular_GGX_Environment( geometry, material.specularColor, material.specularRoughness );\n}\n#define RE_Direct RE_Direct_Standard\n#define RE_IndirectDiffuse RE_IndirectDiffuse_Standard\n#define RE_IndirectSpecular RE_IndirectSpecular_Standard\n#define Material_BlinnShininessExponent( material ) GGXRoughnessToBlinnExponent( material.specularRoughness )\nfloat computeSpecularOcclusion( const in float dotNV, const in float ambientOcclusion, const in float roughness ) {\n return saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion );\n}\n";
  14052. // File:src/renderers/shaders/ShaderChunk/lights_template.glsl
  14053. THREE.ShaderChunk[ 'lights_template' ] = "\nGeometricContext geometry;\ngeometry.position = - vViewPosition;\ngeometry.normal = normal;\ngeometry.viewDir = normalize( vViewPosition );\nIncidentLight directLight;\n#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )\n PointLight pointLight;\n for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n pointLight = pointLights[ i ];\n directLight = getPointDirectLightIrradiance( pointLight, geometry );\n #ifdef USE_SHADOWMAP\n directLight.color *= all( bvec2( pointLight.shadow, directLight.visible ) ) ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ] ) : 1.0;\n #endif\n RE_Direct( directLight, geometry, material, reflectedLight );\n }\n#endif\n#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )\n SpotLight spotLight;\n for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n spotLight = spotLights[ i ];\n directLight = getSpotDirectLightIrradiance( spotLight, geometry );\n #ifdef USE_SHADOWMAP\n directLight.color *= all( bvec2( spotLight.shadow, directLight.visible ) ) ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowBias, spotLight.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\n #endif\n RE_Direct( directLight, geometry, material, reflectedLight );\n }\n#endif\n#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )\n DirectionalLight directionalLight;\n for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n directionalLight = directionalLights[ i ];\n directLight = getDirectionalDirectLightIrradiance( directionalLight, geometry );\n #ifdef USE_SHADOWMAP\n directLight.color *= all( bvec2( directionalLight.shadow, directLight.visible ) ) ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n #endif\n RE_Direct( directLight, geometry, material, reflectedLight );\n }\n#endif\n#if defined( RE_IndirectDiffuse )\n vec3 irradiance = getAmbientLightIrradiance( ambientLightColor );\n #ifdef USE_LIGHTMAP\n vec3 lightMapIrradiance = texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n #ifndef PHYSICALLY_CORRECT_LIGHTS\n lightMapIrradiance *= PI;\n #endif\n irradiance += lightMapIrradiance;\n #endif\n #if ( NUM_HEMI_LIGHTS > 0 )\n for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry );\n }\n #endif\n #if defined( USE_ENVMAP ) && defined( STANDARD ) && defined( ENVMAP_TYPE_CUBE_UV )\n irradiance += getLightProbeIndirectIrradiance( geometry, 8 );\n #endif\n RE_IndirectDiffuse( irradiance, geometry, material, reflectedLight );\n#endif\n#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )\n vec3 radiance = getLightProbeIndirectRadiance( geometry, Material_BlinnShininessExponent( material ), 8 );\n RE_IndirectSpecular( radiance, geometry, material, reflectedLight );\n#endif\n";
  14054. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl
  14055. THREE.ShaderChunk[ 'logdepthbuf_fragment' ] = "#if defined(USE_LOGDEPTHBUF) && defined(USE_LOGDEPTHBUF_EXT)\n gl_FragDepthEXT = log2(vFragDepth) * logDepthBufFC * 0.5;\n#endif";
  14056. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl
  14057. 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";
  14058. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_pars_vertex.glsl
  14059. 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";
  14060. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl
  14061. 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";
  14062. // File:src/renderers/shaders/ShaderChunk/map_fragment.glsl
  14063. THREE.ShaderChunk[ 'map_fragment' ] = "#ifdef USE_MAP\n vec4 texelColor = texture2D( map, vUv );\n texelColor = mapTexelToLinear( texelColor );\n diffuseColor *= texelColor;\n#endif\n";
  14064. // File:src/renderers/shaders/ShaderChunk/map_pars_fragment.glsl
  14065. THREE.ShaderChunk[ 'map_pars_fragment' ] = "#ifdef USE_MAP\n uniform sampler2D map;\n#endif\n";
  14066. // File:src/renderers/shaders/ShaderChunk/map_particle_fragment.glsl
  14067. 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";
  14068. // File:src/renderers/shaders/ShaderChunk/map_particle_pars_fragment.glsl
  14069. THREE.ShaderChunk[ 'map_particle_pars_fragment' ] = "#ifdef USE_MAP\n uniform vec4 offsetRepeat;\n uniform sampler2D map;\n#endif\n";
  14070. // File:src/renderers/shaders/ShaderChunk/metalnessmap_fragment.glsl
  14071. THREE.ShaderChunk[ 'metalnessmap_fragment' ] = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n vec4 texelMetalness = texture2D( metalnessMap, vUv );\n metalnessFactor *= texelMetalness.r;\n#endif\n";
  14072. // File:src/renderers/shaders/ShaderChunk/metalnessmap_pars_fragment.glsl
  14073. THREE.ShaderChunk[ 'metalnessmap_pars_fragment' ] = "#ifdef USE_METALNESSMAP\n uniform sampler2D metalnessMap;\n#endif";
  14074. // File:src/renderers/shaders/ShaderChunk/morphnormal_vertex.glsl
  14075. 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";
  14076. // File:src/renderers/shaders/ShaderChunk/morphtarget_pars_vertex.glsl
  14077. 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";
  14078. // File:src/renderers/shaders/ShaderChunk/morphtarget_vertex.glsl
  14079. 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";
  14080. // File:src/renderers/shaders/ShaderChunk/normal_fragment.glsl
  14081. 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";
  14082. // File:src/renderers/shaders/ShaderChunk/normalmap_pars_fragment.glsl
  14083. 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";
  14084. // File:src/renderers/shaders/ShaderChunk/premultiplied_alpha_fragment.glsl
  14085. THREE.ShaderChunk[ 'premultiplied_alpha_fragment' ] = "#ifdef PREMULTIPLIED_ALPHA\n gl_FragColor.rgb *= gl_FragColor.a;\n#endif\n";
  14086. // File:src/renderers/shaders/ShaderChunk/project_vertex.glsl
  14087. 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";
  14088. // File:src/renderers/shaders/ShaderChunk/roughnessmap_fragment.glsl
  14089. THREE.ShaderChunk[ 'roughnessmap_fragment' ] = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n vec4 texelRoughness = texture2D( roughnessMap, vUv );\n roughnessFactor *= texelRoughness.r;\n#endif\n";
  14090. // File:src/renderers/shaders/ShaderChunk/roughnessmap_pars_fragment.glsl
  14091. THREE.ShaderChunk[ 'roughnessmap_pars_fragment' ] = "#ifdef USE_ROUGHNESSMAP\n uniform sampler2D roughnessMap;\n#endif";
  14092. // File:src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl
  14093. THREE.ShaderChunk[ 'shadowmap_pars_fragment' ] = "#ifdef USE_SHADOWMAP\n #if NUM_DIR_LIGHTS > 0\n uniform sampler2D directionalShadowMap[ NUM_DIR_LIGHTS ];\n varying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHTS ];\n #endif\n #if NUM_SPOT_LIGHTS > 0\n uniform sampler2D spotShadowMap[ NUM_SPOT_LIGHTS ];\n varying vec4 vSpotShadowCoord[ NUM_SPOT_LIGHTS ];\n #endif\n #if NUM_POINT_LIGHTS > 0\n uniform sampler2D pointShadowMap[ NUM_POINT_LIGHTS ];\n varying vec4 vPointShadowCoord[ NUM_POINT_LIGHTS ];\n #endif\n float unpackDepth( const in vec4 rgba_depth ) {\n const vec4 bit_shift = vec4( 1.0 / ( 256.0 * 256.0 * 256.0 ), 1.0 / ( 256.0 * 256.0 ), 1.0 / 256.0, 1.0 );\n return dot( rgba_depth, bit_shift );\n }\n float texture2DCompare( sampler2D depths, vec2 uv, float compare ) {\n return step( compare, unpackDepth( texture2D( depths, uv ) ) );\n }\n float texture2DShadowLerp( sampler2D depths, vec2 size, vec2 uv, float compare ) {\n const vec2 offset = vec2( 0.0, 1.0 );\n vec2 texelSize = vec2( 1.0 ) / size;\n vec2 centroidUV = floor( uv * size + 0.5 ) / size;\n float lb = texture2DCompare( depths, centroidUV + texelSize * offset.xx, compare );\n float lt = texture2DCompare( depths, centroidUV + texelSize * offset.xy, compare );\n float rb = texture2DCompare( depths, centroidUV + texelSize * offset.yx, compare );\n float rt = texture2DCompare( depths, centroidUV + texelSize * offset.yy, compare );\n vec2 f = fract( uv * size + 0.5 );\n float a = mix( lb, lt, f.y );\n float b = mix( rb, rt, f.y );\n float c = mix( a, b, f.x );\n return c;\n }\n float getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord ) {\n shadowCoord.xyz /= shadowCoord.w;\n shadowCoord.z += shadowBias;\n bvec4 inFrustumVec = bvec4 ( shadowCoord.x >= 0.0, shadowCoord.x <= 1.0, shadowCoord.y >= 0.0, shadowCoord.y <= 1.0 );\n bool inFrustum = all( inFrustumVec );\n bvec2 frustumTestVec = bvec2( inFrustum, shadowCoord.z <= 1.0 );\n bool frustumTest = all( frustumTestVec );\n if ( frustumTest ) {\n #if defined( SHADOWMAP_TYPE_PCF )\n vec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n float dx0 = - texelSize.x * shadowRadius;\n float dy0 = - texelSize.y * shadowRadius;\n float dx1 = + texelSize.x * shadowRadius;\n float dy1 = + texelSize.y * shadowRadius;\n return (\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )\n ) * ( 1.0 / 9.0 );\n #elif defined( SHADOWMAP_TYPE_PCF_SOFT )\n vec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n float dx0 = - texelSize.x * shadowRadius;\n float dy0 = - texelSize.y * shadowRadius;\n float dx1 = + texelSize.x * shadowRadius;\n float dy1 = + texelSize.y * shadowRadius;\n return (\n texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +\n texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +\n texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +\n texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +\n texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy, shadowCoord.z ) +\n texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +\n texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +\n texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +\n texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )\n ) * ( 1.0 / 9.0 );\n #else\n return texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z );\n #endif\n }\n return 1.0;\n }\n vec2 cubeToUV( vec3 v, float texelSizeY ) {\n vec3 absV = abs( v );\n float scaleToCube = 1.0 / max( absV.x, max( absV.y, absV.z ) );\n absV *= scaleToCube;\n v *= scaleToCube * ( 1.0 - 2.0 * texelSizeY );\n vec2 planar = v.xy;\n float almostATexel = 1.5 * texelSizeY;\n float almostOne = 1.0 - almostATexel;\n if ( absV.z >= almostOne ) {\n if ( v.z > 0.0 )\n planar.x = 4.0 - v.x;\n } else if ( absV.x >= almostOne ) {\n float signX = sign( v.x );\n planar.x = v.z * signX + 2.0 * signX;\n } else if ( absV.y >= almostOne ) {\n float signY = sign( v.y );\n planar.x = v.x + 2.0 * signY + 2.0;\n planar.y = v.z * signY - 2.0;\n }\n return vec2( 0.125, 0.25 ) * planar + vec2( 0.375, 0.75 );\n }\n float getPointShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord ) {\n vec2 texelSize = vec2( 1.0 ) / ( shadowMapSize * vec2( 4.0, 2.0 ) );\n vec3 lightToPosition = shadowCoord.xyz;\n vec3 bd3D = normalize( lightToPosition );\n float dp = ( length( lightToPosition ) - shadowBias ) / 1000.0;\n #if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT )\n vec2 offset = vec2( - 1, 1 ) * shadowRadius * texelSize.y;\n return (\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyy, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyy, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyx, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyx, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxy, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxy, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxx, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxx, texelSize.y ), dp )\n ) * ( 1.0 / 9.0 );\n #else\n return texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp );\n #endif\n }\n#endif\n";
  14094. // File:src/renderers/shaders/ShaderChunk/shadowmap_pars_vertex.glsl
  14095. 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";
  14096. // File:src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl
  14097. 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";
  14098. // File:src/renderers/shaders/ShaderChunk/shadowmask_pars_fragment.glsl
  14099. 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";
  14100. // File:src/renderers/shaders/ShaderChunk/skinbase_vertex.glsl
  14101. 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";
  14102. // File:src/renderers/shaders/ShaderChunk/skinning_pars_vertex.glsl
  14103. THREE.ShaderChunk[ 'skinning_pars_vertex' ] = "#ifdef USE_SKINNING\n uniform mat4 bindMatrix;\n uniform mat4 bindMatrixInverse;\n #ifdef BONE_TEXTURE\n uniform sampler2D boneTexture;\n uniform int boneTextureWidth;\n uniform int boneTextureHeight;\n mat4 getBoneMatrix( const in float i ) {\n float j = i * 4.0;\n float x = mod( j, float( boneTextureWidth ) );\n float y = floor( j / float( boneTextureWidth ) );\n float dx = 1.0 / float( boneTextureWidth );\n float dy = 1.0 / float( boneTextureHeight );\n y = dy * ( y + 0.5 );\n vec4 v1 = texture2D( boneTexture, vec2( dx * ( x + 0.5 ), y ) );\n vec4 v2 = texture2D( boneTexture, vec2( dx * ( x + 1.5 ), y ) );\n vec4 v3 = texture2D( boneTexture, vec2( dx * ( x + 2.5 ), y ) );\n vec4 v4 = texture2D( boneTexture, vec2( dx * ( x + 3.5 ), y ) );\n mat4 bone = mat4( v1, v2, v3, v4 );\n return bone;\n }\n #else\n uniform mat4 boneGlobalMatrices[ MAX_BONES ];\n mat4 getBoneMatrix( const in float i ) {\n mat4 bone = boneGlobalMatrices[ int(i) ];\n return bone;\n }\n #endif\n#endif\n";
  14104. // File:src/renderers/shaders/ShaderChunk/skinning_vertex.glsl
  14105. 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";
  14106. // File:src/renderers/shaders/ShaderChunk/skinnormal_vertex.glsl
  14107. 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";
  14108. // File:src/renderers/shaders/ShaderChunk/specularmap_fragment.glsl
  14109. 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";
  14110. // File:src/renderers/shaders/ShaderChunk/specularmap_pars_fragment.glsl
  14111. THREE.ShaderChunk[ 'specularmap_pars_fragment' ] = "#ifdef USE_SPECULARMAP\n uniform sampler2D specularMap;\n#endif";
  14112. // File:src/renderers/shaders/ShaderChunk/tonemapping_fragment.glsl
  14113. THREE.ShaderChunk[ 'tonemapping_fragment' ] = "#if defined( TONE_MAPPING )\n gl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif\n";
  14114. // File:src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl
  14115. 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";
  14116. // File:src/renderers/shaders/ShaderChunk/uv2_pars_fragment.glsl
  14117. THREE.ShaderChunk[ 'uv2_pars_fragment' ] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n varying vec2 vUv2;\n#endif";
  14118. // File:src/renderers/shaders/ShaderChunk/uv2_pars_vertex.glsl
  14119. THREE.ShaderChunk[ 'uv2_pars_vertex' ] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n attribute vec2 uv2;\n varying vec2 vUv2;\n#endif";
  14120. // File:src/renderers/shaders/ShaderChunk/uv2_vertex.glsl
  14121. THREE.ShaderChunk[ 'uv2_vertex' ] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n vUv2 = uv2;\n#endif";
  14122. // File:src/renderers/shaders/ShaderChunk/uv_pars_fragment.glsl
  14123. 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";
  14124. // File:src/renderers/shaders/ShaderChunk/uv_pars_vertex.glsl
  14125. 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";
  14126. // File:src/renderers/shaders/ShaderChunk/uv_vertex.glsl
  14127. 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";
  14128. // File:src/renderers/shaders/ShaderChunk/worldpos_vertex.glsl
  14129. THREE.ShaderChunk[ 'worldpos_vertex' ] = "#if defined( USE_ENVMAP ) || defined( PHONG ) || defined( STANDARD ) || defined( LAMBERT ) || defined ( USE_SHADOWMAP )\n #ifdef USE_SKINNING\n vec4 worldPosition = modelMatrix * skinned;\n #else\n vec4 worldPosition = modelMatrix * vec4( transformed, 1.0 );\n #endif\n#endif\n";
  14130. // File:src/renderers/shaders/UniformsUtils.js
  14131. /**
  14132. * Uniform Utilities
  14133. */
  14134. THREE.UniformsUtils = {
  14135. merge: function ( uniforms ) {
  14136. var merged = {};
  14137. for ( var u = 0; u < uniforms.length; u ++ ) {
  14138. var tmp = this.clone( uniforms[ u ] );
  14139. for ( var p in tmp ) {
  14140. merged[ p ] = tmp[ p ];
  14141. }
  14142. }
  14143. return merged;
  14144. },
  14145. clone: function ( uniforms_src ) {
  14146. var uniforms_dst = {};
  14147. for ( var u in uniforms_src ) {
  14148. uniforms_dst[ u ] = {};
  14149. for ( var p in uniforms_src[ u ] ) {
  14150. var parameter_src = uniforms_src[ u ][ p ];
  14151. if ( parameter_src instanceof THREE.Color ||
  14152. parameter_src instanceof THREE.Vector2 ||
  14153. parameter_src instanceof THREE.Vector3 ||
  14154. parameter_src instanceof THREE.Vector4 ||
  14155. parameter_src instanceof THREE.Matrix3 ||
  14156. parameter_src instanceof THREE.Matrix4 ||
  14157. parameter_src instanceof THREE.Texture ) {
  14158. uniforms_dst[ u ][ p ] = parameter_src.clone();
  14159. } else if ( Array.isArray( parameter_src ) ) {
  14160. uniforms_dst[ u ][ p ] = parameter_src.slice();
  14161. } else {
  14162. uniforms_dst[ u ][ p ] = parameter_src;
  14163. }
  14164. }
  14165. }
  14166. return uniforms_dst;
  14167. }
  14168. };
  14169. // File:src/renderers/shaders/UniformsLib.js
  14170. /**
  14171. * Uniforms library for shared webgl shaders
  14172. */
  14173. THREE.UniformsLib = {
  14174. common: {
  14175. "diffuse": { type: "c", value: new THREE.Color( 0xeeeeee ) },
  14176. "opacity": { type: "1f", value: 1.0 },
  14177. "map": { type: "t", value: null },
  14178. "offsetRepeat": { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) },
  14179. "specularMap": { type: "t", value: null },
  14180. "alphaMap": { type: "t", value: null },
  14181. "envMap": { type: "t", value: null },
  14182. "flipEnvMap": { type: "1f", value: - 1 },
  14183. "reflectivity": { type: "1f", value: 1.0 },
  14184. "refractionRatio": { type: "1f", value: 0.98 }
  14185. },
  14186. aomap: {
  14187. "aoMap": { type: "t", value: null },
  14188. "aoMapIntensity": { type: "1f", value: 1 }
  14189. },
  14190. lightmap: {
  14191. "lightMap": { type: "t", value: null },
  14192. "lightMapIntensity": { type: "1f", value: 1 }
  14193. },
  14194. emissivemap: {
  14195. "emissiveMap": { type: "t", value: null }
  14196. },
  14197. bumpmap: {
  14198. "bumpMap": { type: "t", value: null },
  14199. "bumpScale": { type: "1f", value: 1 }
  14200. },
  14201. normalmap: {
  14202. "normalMap": { type: "t", value: null },
  14203. "normalScale": { type: "v2", value: new THREE.Vector2( 1, 1 ) }
  14204. },
  14205. displacementmap: {
  14206. "displacementMap": { type: "t", value: null },
  14207. "displacementScale": { type: "1f", value: 1 },
  14208. "displacementBias": { type: "1f", value: 0 }
  14209. },
  14210. roughnessmap: {
  14211. "roughnessMap": { type: "t", value: null }
  14212. },
  14213. metalnessmap: {
  14214. "metalnessMap": { type: "t", value: null }
  14215. },
  14216. fog: {
  14217. "fogDensity": { type: "1f", value: 0.00025 },
  14218. "fogNear": { type: "1f", value: 1 },
  14219. "fogFar": { type: "1f", value: 2000 },
  14220. "fogColor": { type: "c", value: new THREE.Color( 0xffffff ) }
  14221. },
  14222. lights: {
  14223. "ambientLightColor": { type: "3fv", value: [] },
  14224. "directionalLights": { type: "sa", value: [], properties: {
  14225. "direction": { type: "v3" },
  14226. "color": { type: "c" },
  14227. "shadow": { type: "1i" },
  14228. "shadowBias": { type: "1f" },
  14229. "shadowRadius": { type: "1f" },
  14230. "shadowMapSize": { type: "v2" }
  14231. } },
  14232. "directionalShadowMap": { type: "tv", value: [] },
  14233. "directionalShadowMatrix": { type: "m4v", value: [] },
  14234. "spotLights": { type: "sa", value: [], properties: {
  14235. "color": { type: "c" },
  14236. "position": { type: "v3" },
  14237. "direction": { type: "v3" },
  14238. "distance": { type: "1f" },
  14239. "coneCos": { type: "1f" },
  14240. "penumbraCos": { type: "1f" },
  14241. "decay": { type: "1f" },
  14242. "shadow": { type: "1i" },
  14243. "shadowBias": { type: "1f" },
  14244. "shadowRadius": { type: "1f" },
  14245. "shadowMapSize": { type: "v2" }
  14246. } },
  14247. "spotShadowMap": { type: "tv", value: [] },
  14248. "spotShadowMatrix": { type: "m4v", value: [] },
  14249. "pointLights": { type: "sa", value: [], properties: {
  14250. "color": { type: "c" },
  14251. "position": { type: "v3" },
  14252. "decay": { type: "1f" },
  14253. "distance": { type: "1f" },
  14254. "shadow": { type: "1i" },
  14255. "shadowBias": { type: "1f" },
  14256. "shadowRadius": { type: "1f" },
  14257. "shadowMapSize": { type: "v2" }
  14258. } },
  14259. "pointShadowMap": { type: "tv", value: [] },
  14260. "pointShadowMatrix": { type: "m4v", value: [] },
  14261. "hemisphereLights": { type: "sa", value: [], properties: {
  14262. "direction": { type: "v3" },
  14263. "skyColor": { type: "c" },
  14264. "groundColor": { type: "c" }
  14265. } }
  14266. },
  14267. points: {
  14268. "diffuse": { type: "c", value: new THREE.Color( 0xeeeeee ) },
  14269. "opacity": { type: "1f", value: 1.0 },
  14270. "size": { type: "1f", value: 1.0 },
  14271. "scale": { type: "1f", value: 1.0 },
  14272. "map": { type: "t", value: null },
  14273. "offsetRepeat": { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) }
  14274. }
  14275. };
  14276. // File:src/renderers/shaders/ShaderLib/cube_frag.glsl
  14277. THREE.ShaderChunk[ 'cube_frag' ] = "uniform samplerCube tCube;\nuniform float tFlip;\nvarying vec3 vWorldPosition;\n#include <common>\n#include <logdepthbuf_pars_fragment>\nvoid main() {\n gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );\n #include <logdepthbuf_fragment>\n}\n";
  14278. // File:src/renderers/shaders/ShaderLib/cube_vert.glsl
  14279. THREE.ShaderChunk[ 'cube_vert' ] = "varying vec3 vWorldPosition;\n#include <common>\n#include <logdepthbuf_pars_vertex>\nvoid main() {\n vWorldPosition = transformDirection( position, modelMatrix );\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n #include <logdepthbuf_vertex>\n}\n";
  14280. // File:src/renderers/shaders/ShaderLib/depth_frag.glsl
  14281. THREE.ShaderChunk[ 'depth_frag' ] = "uniform float mNear;\nuniform float mFar;\nuniform float opacity;\n#include <common>\n#include <logdepthbuf_pars_fragment>\nvoid main() {\n #include <logdepthbuf_fragment>\n #ifdef USE_LOGDEPTHBUF_EXT\n float depth = gl_FragDepthEXT / gl_FragCoord.w;\n #else\n float depth = gl_FragCoord.z / gl_FragCoord.w;\n #endif\n float color = 1.0 - smoothstep( mNear, mFar, depth );\n gl_FragColor = vec4( vec3( color ), opacity );\n}\n";
  14282. // File:src/renderers/shaders/ShaderLib/depth_vert.glsl
  14283. THREE.ShaderChunk[ 'depth_vert' ] = "#include <common>\n#include <morphtarget_pars_vertex>\n#include <logdepthbuf_pars_vertex>\nvoid main() {\n #include <begin_vertex>\n #include <morphtarget_vertex>\n #include <project_vertex>\n #include <logdepthbuf_vertex>\n}\n";
  14284. // File:src/renderers/shaders/ShaderLib/depthRGBA_frag.glsl
  14285. THREE.ShaderChunk[ 'depthRGBA_frag' ] = "#include <common>\n#include <logdepthbuf_pars_fragment>\nvec4 pack_depth( const in float depth ) {\n const vec4 bit_shift = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );\n const vec4 bit_mask = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );\n vec4 res = mod( depth * bit_shift * vec4( 255 ), vec4( 256 ) ) / vec4( 255 );\n res -= res.xxyz * bit_mask;\n return res;\n}\nvoid main() {\n #include <logdepthbuf_fragment>\n #ifdef USE_LOGDEPTHBUF_EXT\n gl_FragData[ 0 ] = pack_depth( gl_FragDepthEXT );\n #else\n gl_FragData[ 0 ] = pack_depth( gl_FragCoord.z );\n #endif\n}\n";
  14286. // File:src/renderers/shaders/ShaderLib/depthRGBA_vert.glsl
  14287. THREE.ShaderChunk[ 'depthRGBA_vert' ] = "#include <common>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\nvoid main() {\n #include <skinbase_vertex>\n #include <begin_vertex>\n #include <morphtarget_vertex>\n #include <skinning_vertex>\n #include <project_vertex>\n #include <logdepthbuf_vertex>\n}\n";
  14288. // File:src/renderers/shaders/ShaderLib/distanceRGBA_frag.glsl
  14289. THREE.ShaderChunk[ 'distanceRGBA_frag' ] = "uniform vec3 lightPos;\nvarying vec4 vWorldPosition;\n#include <common>\nvec4 pack1K ( float depth ) {\n depth /= 1000.0;\n const vec4 bitSh = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );\n const vec4 bitMsk = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );\n vec4 res = mod( depth * bitSh * vec4( 255 ), vec4( 256 ) ) / vec4( 255 );\n res -= res.xxyz * bitMsk;\n return res;\n}\nfloat unpack1K ( vec4 color ) {\n const vec4 bitSh = vec4( 1.0 / ( 256.0 * 256.0 * 256.0 ), 1.0 / ( 256.0 * 256.0 ), 1.0 / 256.0, 1.0 );\n return dot( color, bitSh ) * 1000.0;\n}\nvoid main () {\n gl_FragColor = pack1K( length( vWorldPosition.xyz - lightPos.xyz ) );\n}\n";
  14290. // File:src/renderers/shaders/ShaderLib/distanceRGBA_vert.glsl
  14291. THREE.ShaderChunk[ 'distanceRGBA_vert' ] = "varying vec4 vWorldPosition;\n#include <common>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\nvoid main() {\n #include <skinbase_vertex>\n #include <begin_vertex>\n #include <morphtarget_vertex>\n #include <skinning_vertex>\n #include <project_vertex>\n #include <worldpos_vertex>\n vWorldPosition = worldPosition;\n}\n";
  14292. // File:src/renderers/shaders/ShaderLib/equirect_frag.glsl
  14293. THREE.ShaderChunk[ 'equirect_frag' ] = "uniform sampler2D tEquirect;\nuniform float tFlip;\nvarying vec3 vWorldPosition;\n#include <common>\n#include <logdepthbuf_pars_fragment>\nvoid main() {\n vec3 direction = normalize( vWorldPosition );\n vec2 sampleUV;\n sampleUV.y = saturate( tFlip * direction.y * -0.5 + 0.5 );\n sampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;\n gl_FragColor = texture2D( tEquirect, sampleUV );\n #include <logdepthbuf_fragment>\n}\n";
  14294. // File:src/renderers/shaders/ShaderLib/equirect_vert.glsl
  14295. THREE.ShaderChunk[ 'equirect_vert' ] = "varying vec3 vWorldPosition;\n#include <common>\n#include <logdepthbuf_pars_vertex>\nvoid main() {\n vWorldPosition = transformDirection( position, modelMatrix );\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n #include <logdepthbuf_vertex>\n}\n";
  14296. // File:src/renderers/shaders/ShaderLib/linedashed_frag.glsl
  14297. THREE.ShaderChunk[ 'linedashed_frag' ] = "uniform vec3 diffuse;\nuniform float opacity;\nuniform float dashSize;\nuniform float totalSize;\nvarying float vLineDistance;\n#include <common>\n#include <color_pars_fragment>\n#include <fog_pars_fragment>\n#include <logdepthbuf_pars_fragment>\nvoid main() {\n if ( mod( vLineDistance, totalSize ) > dashSize ) {\n discard;\n }\n vec3 outgoingLight = vec3( 0.0 );\n vec4 diffuseColor = vec4( diffuse, opacity );\n #include <logdepthbuf_fragment>\n #include <color_fragment>\n outgoingLight = diffuseColor.rgb;\n gl_FragColor = vec4( outgoingLight, diffuseColor.a );\n #include <premultiplied_alpha_fragment>\n #include <tonemapping_fragment>\n #include <encodings_fragment>\n #include <fog_fragment>\n}\n";
  14298. // File:src/renderers/shaders/ShaderLib/linedashed_vert.glsl
  14299. THREE.ShaderChunk[ 'linedashed_vert' ] = "uniform float scale;\nattribute float lineDistance;\nvarying float vLineDistance;\n#include <common>\n#include <color_pars_vertex>\n#include <logdepthbuf_pars_vertex>\nvoid main() {\n #include <color_vertex>\n vLineDistance = scale * lineDistance;\n vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\n gl_Position = projectionMatrix * mvPosition;\n #include <logdepthbuf_vertex>\n}\n";
  14300. // File:src/renderers/shaders/ShaderLib/meshbasic_frag.glsl
  14301. THREE.ShaderChunk[ 'meshbasic_frag' ] = "uniform vec3 diffuse;\nuniform float opacity;\n#ifndef FLAT_SHADED\n varying vec3 vNormal;\n#endif\n#include <common>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <envmap_pars_fragment>\n#include <fog_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\nvoid main() {\n vec4 diffuseColor = vec4( diffuse, opacity );\n #include <logdepthbuf_fragment>\n #include <map_fragment>\n #include <color_fragment>\n #include <alphamap_fragment>\n #include <alphatest_fragment>\n #include <specularmap_fragment>\n ReflectedLight reflectedLight;\n reflectedLight.directDiffuse = vec3( 0.0 );\n reflectedLight.directSpecular = vec3( 0.0 );\n reflectedLight.indirectDiffuse = diffuseColor.rgb;\n reflectedLight.indirectSpecular = vec3( 0.0 );\n #include <aomap_fragment>\n vec3 outgoingLight = reflectedLight.indirectDiffuse;\n #include <envmap_fragment>\n gl_FragColor = vec4( outgoingLight, diffuseColor.a );\n #include <premultiplied_alpha_fragment>\n #include <tonemapping_fragment>\n #include <encodings_fragment>\n #include <fog_fragment>\n}\n";
  14302. // File:src/renderers/shaders/ShaderLib/meshbasic_vert.glsl
  14303. THREE.ShaderChunk[ 'meshbasic_vert' ] = "#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <envmap_pars_vertex>\n#include <color_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\nvoid main() {\n #include <uv_vertex>\n #include <uv2_vertex>\n #include <color_vertex>\n #include <skinbase_vertex>\n #ifdef USE_ENVMAP\n #include <beginnormal_vertex>\n #include <morphnormal_vertex>\n #include <skinnormal_vertex>\n #include <defaultnormal_vertex>\n #endif\n #include <begin_vertex>\n #include <morphtarget_vertex>\n #include <skinning_vertex>\n #include <project_vertex>\n #include <logdepthbuf_vertex>\n #include <worldpos_vertex>\n #include <envmap_vertex>\n}\n";
  14304. // File:src/renderers/shaders/ShaderLib/meshlambert_frag.glsl
  14305. THREE.ShaderChunk[ 'meshlambert_frag' ] = "uniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\nvarying vec3 vLightFront;\n#ifdef DOUBLE_SIDED\n varying vec3 vLightBack;\n#endif\n#include <common>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <envmap_pars_fragment>\n#include <bsdfs>\n#include <lights_pars>\n#include <fog_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <shadowmask_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\nvoid main() {\n vec4 diffuseColor = vec4( diffuse, opacity );\n ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n vec3 totalEmissiveRadiance = emissive;\n #include <logdepthbuf_fragment>\n #include <map_fragment>\n #include <color_fragment>\n #include <alphamap_fragment>\n #include <alphatest_fragment>\n #include <specularmap_fragment>\n #include <emissivemap_fragment>\n reflectedLight.indirectDiffuse = getAmbientLightIrradiance( ambientLightColor );\n #include <lightmap_fragment>\n reflectedLight.indirectDiffuse *= BRDF_Diffuse_Lambert( diffuseColor.rgb );\n #ifdef DOUBLE_SIDED\n reflectedLight.directDiffuse = ( gl_FrontFacing ) ? vLightFront : vLightBack;\n #else\n reflectedLight.directDiffuse = vLightFront;\n #endif\n reflectedLight.directDiffuse *= BRDF_Diffuse_Lambert( diffuseColor.rgb ) * getShadowMask();\n #include <aomap_fragment>\n vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n #include <envmap_fragment>\n gl_FragColor = vec4( outgoingLight, diffuseColor.a );\n #include <premultiplied_alpha_fragment>\n #include <tonemapping_fragment>\n #include <encodings_fragment>\n #include <fog_fragment>\n}\n";
  14306. // File:src/renderers/shaders/ShaderLib/meshlambert_vert.glsl
  14307. THREE.ShaderChunk[ 'meshlambert_vert' ] = "#define LAMBERT\nvarying vec3 vLightFront;\n#ifdef DOUBLE_SIDED\n varying vec3 vLightBack;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <envmap_pars_vertex>\n#include <bsdfs>\n#include <lights_pars>\n#include <color_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\nvoid main() {\n #include <uv_vertex>\n #include <uv2_vertex>\n #include <color_vertex>\n #include <beginnormal_vertex>\n #include <morphnormal_vertex>\n #include <skinbase_vertex>\n #include <skinnormal_vertex>\n #include <defaultnormal_vertex>\n #include <begin_vertex>\n #include <morphtarget_vertex>\n #include <skinning_vertex>\n #include <project_vertex>\n #include <logdepthbuf_vertex>\n #include <worldpos_vertex>\n #include <envmap_vertex>\n #include <lights_lambert_vertex>\n #include <shadowmap_vertex>\n}\n";
  14308. // File:src/renderers/shaders/ShaderLib/meshphong_frag.glsl
  14309. THREE.ShaderChunk[ 'meshphong_frag' ] = "#define PHONG\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform vec3 specular;\nuniform float shininess;\nuniform float opacity;\n#include <common>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <envmap_pars_fragment>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars>\n#include <lights_phong_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\nvoid main() {\n vec4 diffuseColor = vec4( diffuse, opacity );\n ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n vec3 totalEmissiveRadiance = emissive;\n #include <logdepthbuf_fragment>\n #include <map_fragment>\n #include <color_fragment>\n #include <alphamap_fragment>\n #include <alphatest_fragment>\n #include <specularmap_fragment>\n #include <normal_fragment>\n #include <emissivemap_fragment>\n #include <lights_phong_fragment>\n #include <lights_template>\n #include <aomap_fragment>\n vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\n #include <envmap_fragment>\n gl_FragColor = vec4( outgoingLight, diffuseColor.a );\n #include <premultiplied_alpha_fragment>\n #include <tonemapping_fragment>\n #include <encodings_fragment>\n #include <fog_fragment>\n}\n";
  14310. // File:src/renderers/shaders/ShaderLib/meshphong_vert.glsl
  14311. 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>\nvoid main() {\n #include <uv_vertex>\n #include <uv2_vertex>\n #include <color_vertex>\n #include <beginnormal_vertex>\n #include <morphnormal_vertex>\n #include <skinbase_vertex>\n #include <skinnormal_vertex>\n #include <defaultnormal_vertex>\n#ifndef FLAT_SHADED\n vNormal = normalize( transformedNormal );\n#endif\n #include <begin_vertex>\n #include <displacementmap_vertex>\n #include <morphtarget_vertex>\n #include <skinning_vertex>\n #include <project_vertex>\n #include <logdepthbuf_vertex>\n vViewPosition = - mvPosition.xyz;\n #include <worldpos_vertex>\n #include <envmap_vertex>\n #include <shadowmap_vertex>\n}\n";
  14312. // File:src/renderers/shaders/ShaderLib/meshstandard_frag.glsl
  14313. THREE.ShaderChunk[ 'meshstandard_frag' ] = "#define STANDARD\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float roughness;\nuniform float metalness;\nuniform float opacity;\nuniform float envMapIntensity;\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n varying vec3 vNormal;\n#endif\n#include <common>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <envmap_pars_fragment>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <cube_uv_reflection_fragment>\n#include <lights_pars>\n#include <lights_standard_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <roughnessmap_pars_fragment>\n#include <metalnessmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\nvoid main() {\n vec4 diffuseColor = vec4( diffuse, opacity );\n ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n vec3 totalEmissiveRadiance = emissive;\n #include <logdepthbuf_fragment>\n #include <map_fragment>\n #include <color_fragment>\n #include <alphamap_fragment>\n #include <alphatest_fragment>\n #include <specularmap_fragment>\n #include <roughnessmap_fragment>\n #include <metalnessmap_fragment>\n #include <normal_fragment>\n #include <emissivemap_fragment>\n #include <lights_standard_fragment>\n #include <lights_template>\n #include <aomap_fragment>\n vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\n gl_FragColor = vec4( outgoingLight, diffuseColor.a );\n #include <premultiplied_alpha_fragment>\n #include <tonemapping_fragment>\n #include <encodings_fragment>\n #include <fog_fragment>\n}\n";
  14314. // File:src/renderers/shaders/ShaderLib/meshstandard_vert.glsl
  14315. THREE.ShaderChunk[ 'meshstandard_vert' ] = "#define STANDARD\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n varying vec3 vNormal;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <color_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_vertex>\nvoid main() {\n #include <uv_vertex>\n #include <uv2_vertex>\n #include <color_vertex>\n #include <beginnormal_vertex>\n #include <morphnormal_vertex>\n #include <skinbase_vertex>\n #include <skinnormal_vertex>\n #include <defaultnormal_vertex>\n#ifndef FLAT_SHADED\n vNormal = normalize( transformedNormal );\n#endif\n #include <begin_vertex>\n #include <displacementmap_vertex>\n #include <morphtarget_vertex>\n #include <skinning_vertex>\n #include <project_vertex>\n #include <logdepthbuf_vertex>\n vViewPosition = - mvPosition.xyz;\n #include <worldpos_vertex>\n #include <shadowmap_vertex>\n}\n";
  14316. // File:src/renderers/shaders/ShaderLib/normal_frag.glsl
  14317. THREE.ShaderChunk[ 'normal_frag' ] = "uniform float opacity;\nvarying vec3 vNormal;\n#include <common>\n#include <logdepthbuf_pars_fragment>\nvoid main() {\n gl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, opacity );\n #include <logdepthbuf_fragment>\n}\n";
  14318. // File:src/renderers/shaders/ShaderLib/normal_vert.glsl
  14319. THREE.ShaderChunk[ 'normal_vert' ] = "varying vec3 vNormal;\n#include <common>\n#include <morphtarget_pars_vertex>\n#include <logdepthbuf_pars_vertex>\nvoid main() {\n vNormal = normalize( normalMatrix * normal );\n #include <begin_vertex>\n #include <morphtarget_vertex>\n #include <project_vertex>\n #include <logdepthbuf_vertex>\n}\n";
  14320. // File:src/renderers/shaders/ShaderLib/points_frag.glsl
  14321. THREE.ShaderChunk[ 'points_frag' ] = "uniform vec3 diffuse;\nuniform float opacity;\n#include <common>\n#include <color_pars_fragment>\n#include <map_particle_pars_fragment>\n#include <fog_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\nvoid main() {\n vec3 outgoingLight = vec3( 0.0 );\n vec4 diffuseColor = vec4( diffuse, opacity );\n #include <logdepthbuf_fragment>\n #include <map_particle_fragment>\n #include <color_fragment>\n #include <alphatest_fragment>\n outgoingLight = diffuseColor.rgb;\n gl_FragColor = vec4( outgoingLight, diffuseColor.a );\n #include <premultiplied_alpha_fragment>\n #include <tonemapping_fragment>\n #include <encodings_fragment>\n #include <fog_fragment>\n}\n";
  14322. // File:src/renderers/shaders/ShaderLib/points_vert.glsl
  14323. THREE.ShaderChunk[ 'points_vert' ] = "uniform float size;\nuniform float scale;\n#include <common>\n#include <color_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\nvoid main() {\n #include <color_vertex>\n #include <begin_vertex>\n #include <project_vertex>\n #ifdef USE_SIZEATTENUATION\n gl_PointSize = size * ( scale / - mvPosition.z );\n #else\n gl_PointSize = size;\n #endif\n #include <logdepthbuf_vertex>\n #include <worldpos_vertex>\n #include <shadowmap_vertex>\n}\n";
  14324. // File:src/renderers/shaders/ShaderLib.js
  14325. /**
  14326. * Webgl Shader Library for three.js
  14327. *
  14328. * @author alteredq / http://alteredqualia.com/
  14329. * @author mrdoob / http://mrdoob.com/
  14330. * @author mikael emtinger / http://gomo.se/
  14331. */
  14332. THREE.ShaderLib = {
  14333. 'basic': {
  14334. uniforms: THREE.UniformsUtils.merge( [
  14335. THREE.UniformsLib[ 'common' ],
  14336. THREE.UniformsLib[ 'aomap' ],
  14337. THREE.UniformsLib[ 'fog' ]
  14338. ] ),
  14339. vertexShader: THREE.ShaderChunk[ 'meshbasic_vert' ],
  14340. fragmentShader: THREE.ShaderChunk[ 'meshbasic_frag' ]
  14341. },
  14342. 'lambert': {
  14343. uniforms: THREE.UniformsUtils.merge( [
  14344. THREE.UniformsLib[ 'common' ],
  14345. THREE.UniformsLib[ 'aomap' ],
  14346. THREE.UniformsLib[ 'lightmap' ],
  14347. THREE.UniformsLib[ 'emissivemap' ],
  14348. THREE.UniformsLib[ 'fog' ],
  14349. THREE.UniformsLib[ 'lights' ],
  14350. {
  14351. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) }
  14352. }
  14353. ] ),
  14354. vertexShader: THREE.ShaderChunk[ 'meshlambert_vert' ],
  14355. fragmentShader: THREE.ShaderChunk[ 'meshlambert_frag' ]
  14356. },
  14357. 'phong': {
  14358. uniforms: THREE.UniformsUtils.merge( [
  14359. THREE.UniformsLib[ 'common' ],
  14360. THREE.UniformsLib[ 'aomap' ],
  14361. THREE.UniformsLib[ 'lightmap' ],
  14362. THREE.UniformsLib[ 'emissivemap' ],
  14363. THREE.UniformsLib[ 'bumpmap' ],
  14364. THREE.UniformsLib[ 'normalmap' ],
  14365. THREE.UniformsLib[ 'displacementmap' ],
  14366. THREE.UniformsLib[ 'fog' ],
  14367. THREE.UniformsLib[ 'lights' ],
  14368. {
  14369. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) },
  14370. "specular" : { type: "c", value: new THREE.Color( 0x111111 ) },
  14371. "shininess": { type: "1f", value: 30 }
  14372. }
  14373. ] ),
  14374. vertexShader: THREE.ShaderChunk[ 'meshphong_vert' ],
  14375. fragmentShader: THREE.ShaderChunk[ 'meshphong_frag' ]
  14376. },
  14377. 'standard': {
  14378. uniforms: THREE.UniformsUtils.merge( [
  14379. THREE.UniformsLib[ 'common' ],
  14380. THREE.UniformsLib[ 'aomap' ],
  14381. THREE.UniformsLib[ 'lightmap' ],
  14382. THREE.UniformsLib[ 'emissivemap' ],
  14383. THREE.UniformsLib[ 'bumpmap' ],
  14384. THREE.UniformsLib[ 'normalmap' ],
  14385. THREE.UniformsLib[ 'displacementmap' ],
  14386. THREE.UniformsLib[ 'roughnessmap' ],
  14387. THREE.UniformsLib[ 'metalnessmap' ],
  14388. THREE.UniformsLib[ 'fog' ],
  14389. THREE.UniformsLib[ 'lights' ],
  14390. {
  14391. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) },
  14392. "roughness": { type: "1f", value: 0.5 },
  14393. "metalness": { type: "1f", value: 0 },
  14394. "envMapIntensity" : { type: "1f", value: 1 } // temporary
  14395. }
  14396. ] ),
  14397. vertexShader: THREE.ShaderChunk[ 'meshstandard_vert' ],
  14398. fragmentShader: THREE.ShaderChunk[ 'meshstandard_frag' ]
  14399. },
  14400. 'points': {
  14401. uniforms: THREE.UniformsUtils.merge( [
  14402. THREE.UniformsLib[ 'points' ],
  14403. THREE.UniformsLib[ 'fog' ]
  14404. ] ),
  14405. vertexShader: THREE.ShaderChunk[ 'points_vert' ],
  14406. fragmentShader: THREE.ShaderChunk[ 'points_frag' ]
  14407. },
  14408. 'dashed': {
  14409. uniforms: THREE.UniformsUtils.merge( [
  14410. THREE.UniformsLib[ 'common' ],
  14411. THREE.UniformsLib[ 'fog' ],
  14412. {
  14413. "scale" : { type: "1f", value: 1 },
  14414. "dashSize" : { type: "1f", value: 1 },
  14415. "totalSize": { type: "1f", value: 2 }
  14416. }
  14417. ] ),
  14418. vertexShader: THREE.ShaderChunk[ 'linedashed_vert' ],
  14419. fragmentShader: THREE.ShaderChunk[ 'linedashed_frag' ]
  14420. },
  14421. 'depth': {
  14422. uniforms: {
  14423. "mNear": { type: "1f", value: 1.0 },
  14424. "mFar" : { type: "1f", value: 2000.0 },
  14425. "opacity" : { type: "1f", value: 1.0 }
  14426. },
  14427. vertexShader: THREE.ShaderChunk[ 'depth_vert' ],
  14428. fragmentShader: THREE.ShaderChunk[ 'depth_frag' ]
  14429. },
  14430. 'normal': {
  14431. uniforms: {
  14432. "opacity" : { type: "1f", value: 1.0 }
  14433. },
  14434. vertexShader: THREE.ShaderChunk[ 'normal_vert' ],
  14435. fragmentShader: THREE.ShaderChunk[ 'normal_frag' ]
  14436. },
  14437. /* -------------------------------------------------------------------------
  14438. // Cube map shader
  14439. ------------------------------------------------------------------------- */
  14440. 'cube': {
  14441. uniforms: {
  14442. "tCube": { type: "t", value: null },
  14443. "tFlip": { type: "1f", value: - 1 }
  14444. },
  14445. vertexShader: THREE.ShaderChunk[ 'cube_vert' ],
  14446. fragmentShader: THREE.ShaderChunk[ 'cube_frag' ]
  14447. },
  14448. /* -------------------------------------------------------------------------
  14449. // Cube map shader
  14450. ------------------------------------------------------------------------- */
  14451. 'equirect': {
  14452. uniforms: {
  14453. "tEquirect": { type: "t", value: null },
  14454. "tFlip": { type: "1f", value: - 1 }
  14455. },
  14456. vertexShader: THREE.ShaderChunk[ 'equirect_vert' ],
  14457. fragmentShader: THREE.ShaderChunk[ 'equirect_frag' ]
  14458. },
  14459. /* Depth encoding into RGBA texture
  14460. *
  14461. * based on SpiderGL shadow map example
  14462. * http://spidergl.org/example.php?id=6
  14463. *
  14464. * originally from
  14465. * http://www.gamedev.net/topic/442138-packing-a-float-into-a-a8r8g8b8-texture-shader/page__whichpage__1%25EF%25BF%25BD
  14466. *
  14467. * see also
  14468. * http://aras-p.info/blog/2009/07/30/encoding-floats-to-rgba-the-final/
  14469. */
  14470. 'depthRGBA': {
  14471. uniforms: {},
  14472. vertexShader: THREE.ShaderChunk[ 'depthRGBA_vert' ],
  14473. fragmentShader: THREE.ShaderChunk[ 'depthRGBA_frag' ]
  14474. },
  14475. 'distanceRGBA': {
  14476. uniforms: {
  14477. "lightPos": { type: "v3", value: new THREE.Vector3() }
  14478. },
  14479. vertexShader: THREE.ShaderChunk[ 'distanceRGBA_vert' ],
  14480. fragmentShader: THREE.ShaderChunk[ 'distanceRGBA_frag' ]
  14481. }
  14482. };
  14483. // File:src/renderers/WebGLRenderer.js
  14484. /**
  14485. * @author supereggbert / http://www.paulbrunt.co.uk/
  14486. * @author mrdoob / http://mrdoob.com/
  14487. * @author alteredq / http://alteredqualia.com/
  14488. * @author szimek / https://github.com/szimek/
  14489. */
  14490. THREE.WebGLRenderer = function ( parameters ) {
  14491. console.log( 'THREE.WebGLRenderer', THREE.REVISION );
  14492. parameters = parameters || {};
  14493. var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElement( 'canvas' ),
  14494. _context = parameters.context !== undefined ? parameters.context : null,
  14495. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  14496. _depth = parameters.depth !== undefined ? parameters.depth : true,
  14497. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  14498. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  14499. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  14500. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false;
  14501. var lights = [];
  14502. var opaqueObjects = [];
  14503. var opaqueObjectsLastIndex = - 1;
  14504. var transparentObjects = [];
  14505. var transparentObjectsLastIndex = - 1;
  14506. var morphInfluences = new Float32Array( 8 );
  14507. var sprites = [];
  14508. var lensFlares = [];
  14509. // public properties
  14510. this.domElement = _canvas;
  14511. this.context = null;
  14512. // clearing
  14513. this.autoClear = true;
  14514. this.autoClearColor = true;
  14515. this.autoClearDepth = true;
  14516. this.autoClearStencil = true;
  14517. // scene graph
  14518. this.sortObjects = true;
  14519. // physically based shading
  14520. this.gammaFactor = 2.0; // for backwards compatibility
  14521. this.gammaInput = false;
  14522. this.gammaOutput = false;
  14523. // physical lights
  14524. this.physicallyCorrectLights = false;
  14525. // tone mapping
  14526. this.toneMapping = THREE.LinearToneMapping;
  14527. this.toneMappingExposure = 1.0;
  14528. this.toneMappingWhitePoint = 1.0;
  14529. // morphs
  14530. this.maxMorphTargets = 8;
  14531. this.maxMorphNormals = 4;
  14532. // flags
  14533. this.autoScaleCubemaps = true;
  14534. // internal properties
  14535. var _this = this,
  14536. // internal state cache
  14537. _currentProgram = null,
  14538. _currentRenderTarget = null,
  14539. _currentFramebuffer = null,
  14540. _currentMaterialId = - 1,
  14541. _currentGeometryProgram = '',
  14542. _currentCamera = null,
  14543. _currentScissor = new THREE.Vector4(),
  14544. _currentScissorTest = null,
  14545. _currentViewport = new THREE.Vector4(),
  14546. //
  14547. _usedTextureUnits = 0,
  14548. //
  14549. _clearColor = new THREE.Color( 0x000000 ),
  14550. _clearAlpha = 0,
  14551. _width = _canvas.width,
  14552. _height = _canvas.height,
  14553. _pixelRatio = 1,
  14554. _scissor = new THREE.Vector4( 0, 0, _width, _height ),
  14555. _scissorTest = false,
  14556. _viewport = new THREE.Vector4( 0, 0, _width, _height ),
  14557. // frustum
  14558. _frustum = new THREE.Frustum(),
  14559. // camera matrices cache
  14560. _projScreenMatrix = new THREE.Matrix4(),
  14561. _vector3 = new THREE.Vector3(),
  14562. // light arrays cache
  14563. _lights = {
  14564. hash: '',
  14565. ambient: [ 0, 0, 0 ],
  14566. directional: [],
  14567. directionalShadowMap: [],
  14568. directionalShadowMatrix: [],
  14569. spot: [],
  14570. spotShadowMap: [],
  14571. spotShadowMatrix: [],
  14572. point: [],
  14573. pointShadowMap: [],
  14574. pointShadowMatrix: [],
  14575. hemi: [],
  14576. shadows: []
  14577. },
  14578. // info
  14579. _infoMemory = {
  14580. geometries: 0,
  14581. textures: 0
  14582. },
  14583. _infoRender = {
  14584. calls: 0,
  14585. vertices: 0,
  14586. faces: 0,
  14587. points: 0
  14588. };
  14589. this.info = {
  14590. render: _infoRender,
  14591. memory: _infoMemory,
  14592. programs: null
  14593. };
  14594. // initialize
  14595. var _gl;
  14596. try {
  14597. var attributes = {
  14598. alpha: _alpha,
  14599. depth: _depth,
  14600. stencil: _stencil,
  14601. antialias: _antialias,
  14602. premultipliedAlpha: _premultipliedAlpha,
  14603. preserveDrawingBuffer: _preserveDrawingBuffer
  14604. };
  14605. _gl = _context || _canvas.getContext( 'webgl', attributes ) || _canvas.getContext( 'experimental-webgl', attributes );
  14606. if ( _gl === null ) {
  14607. if ( _canvas.getContext( 'webgl' ) !== null ) {
  14608. throw 'Error creating WebGL context with your selected attributes.';
  14609. } else {
  14610. throw 'Error creating WebGL context.';
  14611. }
  14612. }
  14613. // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  14614. if ( _gl.getShaderPrecisionFormat === undefined ) {
  14615. _gl.getShaderPrecisionFormat = function () {
  14616. return { 'rangeMin': 1, 'rangeMax': 1, 'precision': 1 };
  14617. };
  14618. }
  14619. _canvas.addEventListener( 'webglcontextlost', onContextLost, false );
  14620. } catch ( error ) {
  14621. console.error( 'THREE.WebGLRenderer: ' + error );
  14622. }
  14623. var extensions = new THREE.WebGLExtensions( _gl );
  14624. extensions.get( 'OES_texture_float' );
  14625. extensions.get( 'OES_texture_float_linear' );
  14626. extensions.get( 'OES_texture_half_float' );
  14627. extensions.get( 'OES_texture_half_float_linear' );
  14628. extensions.get( 'OES_standard_derivatives' );
  14629. extensions.get( 'ANGLE_instanced_arrays' );
  14630. if ( extensions.get( 'OES_element_index_uint' ) ) {
  14631. THREE.BufferGeometry.MaxIndex = 4294967296;
  14632. }
  14633. var capabilities = new THREE.WebGLCapabilities( _gl, extensions, parameters );
  14634. var state = new THREE.WebGLState( _gl, extensions, paramThreeToGL );
  14635. var properties = new THREE.WebGLProperties();
  14636. var objects = new THREE.WebGLObjects( _gl, properties, this.info );
  14637. var programCache = new THREE.WebGLPrograms( this, capabilities );
  14638. var lightCache = new THREE.WebGLLights();
  14639. this.info.programs = programCache.programs;
  14640. var bufferRenderer = new THREE.WebGLBufferRenderer( _gl, extensions, _infoRender );
  14641. var indexedBufferRenderer = new THREE.WebGLIndexedBufferRenderer( _gl, extensions, _infoRender );
  14642. //
  14643. function getTargetPixelRatio() {
  14644. return _currentRenderTarget === null ? _pixelRatio : 1;
  14645. }
  14646. function glClearColor( r, g, b, a ) {
  14647. if ( _premultipliedAlpha === true ) {
  14648. r *= a; g *= a; b *= a;
  14649. }
  14650. state.clearColor( r, g, b, a );
  14651. }
  14652. function setDefaultGLState() {
  14653. state.init();
  14654. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ) );
  14655. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ) );
  14656. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  14657. }
  14658. function resetGLState() {
  14659. _currentProgram = null;
  14660. _currentCamera = null;
  14661. _currentGeometryProgram = '';
  14662. _currentMaterialId = - 1;
  14663. state.reset();
  14664. }
  14665. setDefaultGLState();
  14666. this.context = _gl;
  14667. this.capabilities = capabilities;
  14668. this.extensions = extensions;
  14669. this.properties = properties;
  14670. this.state = state;
  14671. // shadow map
  14672. var shadowMap = new THREE.WebGLShadowMap( this, _lights, objects );
  14673. this.shadowMap = shadowMap;
  14674. // Plugins
  14675. var spritePlugin = new THREE.SpritePlugin( this, sprites );
  14676. var lensFlarePlugin = new THREE.LensFlarePlugin( this, lensFlares );
  14677. // API
  14678. this.getContext = function () {
  14679. return _gl;
  14680. };
  14681. this.getContextAttributes = function () {
  14682. return _gl.getContextAttributes();
  14683. };
  14684. this.forceContextLoss = function () {
  14685. extensions.get( 'WEBGL_lose_context' ).loseContext();
  14686. };
  14687. this.getMaxAnisotropy = ( function () {
  14688. var value;
  14689. return function getMaxAnisotropy() {
  14690. if ( value !== undefined ) return value;
  14691. var extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  14692. if ( extension !== null ) {
  14693. value = _gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );
  14694. } else {
  14695. value = 0;
  14696. }
  14697. return value;
  14698. };
  14699. } )();
  14700. this.getPrecision = function () {
  14701. return capabilities.precision;
  14702. };
  14703. this.getPixelRatio = function () {
  14704. return _pixelRatio;
  14705. };
  14706. this.setPixelRatio = function ( value ) {
  14707. if ( value === undefined ) return;
  14708. _pixelRatio = value;
  14709. this.setSize( _viewport.z, _viewport.w, false );
  14710. };
  14711. this.getSize = function () {
  14712. return {
  14713. width: _width,
  14714. height: _height
  14715. };
  14716. };
  14717. this.setSize = function ( width, height, updateStyle ) {
  14718. _width = width;
  14719. _height = height;
  14720. _canvas.width = width * _pixelRatio;
  14721. _canvas.height = height * _pixelRatio;
  14722. if ( updateStyle !== false ) {
  14723. _canvas.style.width = width + 'px';
  14724. _canvas.style.height = height + 'px';
  14725. }
  14726. this.setViewport( 0, 0, width, height );
  14727. };
  14728. this.setViewport = function ( x, y, width, height ) {
  14729. state.viewport( _viewport.set( x, y, width, height ) );
  14730. };
  14731. this.setScissor = function ( x, y, width, height ) {
  14732. state.scissor( _scissor.set( x, y, width, height ) );
  14733. };
  14734. this.setScissorTest = function ( boolean ) {
  14735. state.setScissorTest( _scissorTest = boolean );
  14736. };
  14737. // Clearing
  14738. this.getClearColor = function () {
  14739. return _clearColor;
  14740. };
  14741. this.setClearColor = function ( color, alpha ) {
  14742. _clearColor.set( color );
  14743. _clearAlpha = alpha !== undefined ? alpha : 1;
  14744. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  14745. };
  14746. this.getClearAlpha = function () {
  14747. return _clearAlpha;
  14748. };
  14749. this.setClearAlpha = function ( alpha ) {
  14750. _clearAlpha = alpha;
  14751. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  14752. };
  14753. this.clear = function ( color, depth, stencil ) {
  14754. var bits = 0;
  14755. if ( color === undefined || color ) bits |= _gl.COLOR_BUFFER_BIT;
  14756. if ( depth === undefined || depth ) bits |= _gl.DEPTH_BUFFER_BIT;
  14757. if ( stencil === undefined || stencil ) bits |= _gl.STENCIL_BUFFER_BIT;
  14758. _gl.clear( bits );
  14759. };
  14760. this.clearColor = function () {
  14761. this.clear( true, false, false );
  14762. };
  14763. this.clearDepth = function () {
  14764. this.clear( false, true, false );
  14765. };
  14766. this.clearStencil = function () {
  14767. this.clear( false, false, true );
  14768. };
  14769. this.clearTarget = function ( renderTarget, color, depth, stencil ) {
  14770. this.setRenderTarget( renderTarget );
  14771. this.clear( color, depth, stencil );
  14772. };
  14773. // Reset
  14774. this.resetGLState = resetGLState;
  14775. this.dispose = function() {
  14776. _canvas.removeEventListener( 'webglcontextlost', onContextLost, false );
  14777. };
  14778. // Events
  14779. function onContextLost( event ) {
  14780. event.preventDefault();
  14781. resetGLState();
  14782. setDefaultGLState();
  14783. properties.clear();
  14784. }
  14785. function onTextureDispose( event ) {
  14786. var texture = event.target;
  14787. texture.removeEventListener( 'dispose', onTextureDispose );
  14788. deallocateTexture( texture );
  14789. _infoMemory.textures --;
  14790. }
  14791. function onRenderTargetDispose( event ) {
  14792. var renderTarget = event.target;
  14793. renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
  14794. deallocateRenderTarget( renderTarget );
  14795. _infoMemory.textures --;
  14796. }
  14797. function onMaterialDispose( event ) {
  14798. var material = event.target;
  14799. material.removeEventListener( 'dispose', onMaterialDispose );
  14800. deallocateMaterial( material );
  14801. }
  14802. // Buffer deallocation
  14803. function deallocateTexture( texture ) {
  14804. var textureProperties = properties.get( texture );
  14805. if ( texture.image && textureProperties.__image__webglTextureCube ) {
  14806. // cube texture
  14807. _gl.deleteTexture( textureProperties.__image__webglTextureCube );
  14808. } else {
  14809. // 2D texture
  14810. if ( textureProperties.__webglInit === undefined ) return;
  14811. _gl.deleteTexture( textureProperties.__webglTexture );
  14812. }
  14813. // remove all webgl properties
  14814. properties.delete( texture );
  14815. }
  14816. function deallocateRenderTarget( renderTarget ) {
  14817. var renderTargetProperties = properties.get( renderTarget );
  14818. var textureProperties = properties.get( renderTarget.texture );
  14819. if ( ! renderTarget || textureProperties.__webglTexture === undefined ) return;
  14820. _gl.deleteTexture( textureProperties.__webglTexture );
  14821. if ( renderTarget instanceof THREE.WebGLRenderTargetCube ) {
  14822. for ( var i = 0; i < 6; i ++ ) {
  14823. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] );
  14824. _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer[ i ] );
  14825. }
  14826. } else {
  14827. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer );
  14828. _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer );
  14829. }
  14830. properties.delete( renderTarget.texture );
  14831. properties.delete( renderTarget );
  14832. }
  14833. function deallocateMaterial( material ) {
  14834. releaseMaterialProgramReference( material );
  14835. properties.delete( material );
  14836. }
  14837. function releaseMaterialProgramReference( material ) {
  14838. var programInfo = properties.get( material ).program;
  14839. material.program = undefined;
  14840. if ( programInfo !== undefined ) {
  14841. programCache.releaseProgram( programInfo );
  14842. }
  14843. }
  14844. // Buffer rendering
  14845. this.renderBufferImmediate = function ( object, program, material ) {
  14846. state.initAttributes();
  14847. var buffers = properties.get( object );
  14848. if ( object.hasPositions && ! buffers.position ) buffers.position = _gl.createBuffer();
  14849. if ( object.hasNormals && ! buffers.normal ) buffers.normal = _gl.createBuffer();
  14850. if ( object.hasUvs && ! buffers.uv ) buffers.uv = _gl.createBuffer();
  14851. if ( object.hasColors && ! buffers.color ) buffers.color = _gl.createBuffer();
  14852. var attributes = program.getAttributes();
  14853. if ( object.hasPositions ) {
  14854. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.position );
  14855. _gl.bufferData( _gl.ARRAY_BUFFER, object.positionArray, _gl.DYNAMIC_DRAW );
  14856. state.enableAttribute( attributes.position );
  14857. _gl.vertexAttribPointer( attributes.position, 3, _gl.FLOAT, false, 0, 0 );
  14858. }
  14859. if ( object.hasNormals ) {
  14860. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.normal );
  14861. if ( material.type !== 'MeshPhongMaterial' && material.type !== 'MeshStandardMaterial' && material.shading === THREE.FlatShading ) {
  14862. for ( var i = 0, l = object.count * 3; i < l; i += 9 ) {
  14863. var array = object.normalArray;
  14864. var nx = ( array[ i + 0 ] + array[ i + 3 ] + array[ i + 6 ] ) / 3;
  14865. var ny = ( array[ i + 1 ] + array[ i + 4 ] + array[ i + 7 ] ) / 3;
  14866. var nz = ( array[ i + 2 ] + array[ i + 5 ] + array[ i + 8 ] ) / 3;
  14867. array[ i + 0 ] = nx;
  14868. array[ i + 1 ] = ny;
  14869. array[ i + 2 ] = nz;
  14870. array[ i + 3 ] = nx;
  14871. array[ i + 4 ] = ny;
  14872. array[ i + 5 ] = nz;
  14873. array[ i + 6 ] = nx;
  14874. array[ i + 7 ] = ny;
  14875. array[ i + 8 ] = nz;
  14876. }
  14877. }
  14878. _gl.bufferData( _gl.ARRAY_BUFFER, object.normalArray, _gl.DYNAMIC_DRAW );
  14879. state.enableAttribute( attributes.normal );
  14880. _gl.vertexAttribPointer( attributes.normal, 3, _gl.FLOAT, false, 0, 0 );
  14881. }
  14882. if ( object.hasUvs && material.map ) {
  14883. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.uv );
  14884. _gl.bufferData( _gl.ARRAY_BUFFER, object.uvArray, _gl.DYNAMIC_DRAW );
  14885. state.enableAttribute( attributes.uv );
  14886. _gl.vertexAttribPointer( attributes.uv, 2, _gl.FLOAT, false, 0, 0 );
  14887. }
  14888. if ( object.hasColors && material.vertexColors !== THREE.NoColors ) {
  14889. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.color );
  14890. _gl.bufferData( _gl.ARRAY_BUFFER, object.colorArray, _gl.DYNAMIC_DRAW );
  14891. state.enableAttribute( attributes.color );
  14892. _gl.vertexAttribPointer( attributes.color, 3, _gl.FLOAT, false, 0, 0 );
  14893. }
  14894. state.disableUnusedAttributes();
  14895. _gl.drawArrays( _gl.TRIANGLES, 0, object.count );
  14896. object.count = 0;
  14897. };
  14898. this.renderBufferDirect = function ( camera, fog, geometry, material, object, group ) {
  14899. setMaterial( material );
  14900. var program = setProgram( camera, fog, material, object );
  14901. var updateBuffers = false;
  14902. var geometryProgram = geometry.id + '_' + program.id + '_' + material.wireframe;
  14903. if ( geometryProgram !== _currentGeometryProgram ) {
  14904. _currentGeometryProgram = geometryProgram;
  14905. updateBuffers = true;
  14906. }
  14907. // morph targets
  14908. var morphTargetInfluences = object.morphTargetInfluences;
  14909. if ( morphTargetInfluences !== undefined ) {
  14910. var activeInfluences = [];
  14911. for ( var i = 0, l = morphTargetInfluences.length; i < l; i ++ ) {
  14912. var influence = morphTargetInfluences[ i ];
  14913. activeInfluences.push( [ influence, i ] );
  14914. }
  14915. activeInfluences.sort( absNumericalSort );
  14916. if ( activeInfluences.length > 8 ) {
  14917. activeInfluences.length = 8;
  14918. }
  14919. var morphAttributes = geometry.morphAttributes;
  14920. for ( var i = 0, l = activeInfluences.length; i < l; i ++ ) {
  14921. var influence = activeInfluences[ i ];
  14922. morphInfluences[ i ] = influence[ 0 ];
  14923. if ( influence[ 0 ] !== 0 ) {
  14924. var index = influence[ 1 ];
  14925. if ( material.morphTargets === true && morphAttributes.position ) geometry.addAttribute( 'morphTarget' + i, morphAttributes.position[ index ] );
  14926. if ( material.morphNormals === true && morphAttributes.normal ) geometry.addAttribute( 'morphNormal' + i, morphAttributes.normal[ index ] );
  14927. } else {
  14928. if ( material.morphTargets === true ) geometry.removeAttribute( 'morphTarget' + i );
  14929. if ( material.morphNormals === true ) geometry.removeAttribute( 'morphNormal' + i );
  14930. }
  14931. }
  14932. var uniforms = program.getUniforms();
  14933. if ( uniforms.morphTargetInfluences !== null ) {
  14934. _gl.uniform1fv( uniforms.morphTargetInfluences, morphInfluences );
  14935. }
  14936. updateBuffers = true;
  14937. }
  14938. //
  14939. var index = geometry.index;
  14940. var position = geometry.attributes.position;
  14941. if ( material.wireframe === true ) {
  14942. index = objects.getWireframeAttribute( geometry );
  14943. }
  14944. var renderer;
  14945. if ( index !== null ) {
  14946. renderer = indexedBufferRenderer;
  14947. renderer.setIndex( index );
  14948. } else {
  14949. renderer = bufferRenderer;
  14950. }
  14951. if ( updateBuffers ) {
  14952. setupVertexAttributes( material, program, geometry );
  14953. if ( index !== null ) {
  14954. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, objects.getAttributeBuffer( index ) );
  14955. }
  14956. }
  14957. //
  14958. var dataStart = 0;
  14959. var dataCount = Infinity;
  14960. if ( index !== null ) {
  14961. dataCount = index.count;
  14962. } else if ( position !== undefined ) {
  14963. dataCount = position.count;
  14964. }
  14965. var rangeStart = geometry.drawRange.start;
  14966. var rangeCount = geometry.drawRange.count;
  14967. var groupStart = group !== null ? group.start : 0;
  14968. var groupCount = group !== null ? group.count : Infinity;
  14969. var drawStart = Math.max( dataStart, rangeStart, groupStart );
  14970. var drawEnd = Math.min( dataStart + dataCount, rangeStart + rangeCount, groupStart + groupCount ) - 1;
  14971. var drawCount = Math.max( 0, drawEnd - drawStart + 1 );
  14972. //
  14973. if ( object instanceof THREE.Mesh ) {
  14974. if ( material.wireframe === true ) {
  14975. state.setLineWidth( material.wireframeLinewidth * getTargetPixelRatio() );
  14976. renderer.setMode( _gl.LINES );
  14977. } else {
  14978. switch ( object.drawMode ) {
  14979. case THREE.TrianglesDrawMode:
  14980. renderer.setMode( _gl.TRIANGLES );
  14981. break;
  14982. case THREE.TriangleStripDrawMode:
  14983. renderer.setMode( _gl.TRIANGLE_STRIP );
  14984. break;
  14985. case THREE.TriangleFanDrawMode:
  14986. renderer.setMode( _gl.TRIANGLE_FAN );
  14987. break;
  14988. }
  14989. }
  14990. } else if ( object instanceof THREE.Line ) {
  14991. var lineWidth = material.linewidth;
  14992. if ( lineWidth === undefined ) lineWidth = 1; // Not using Line*Material
  14993. state.setLineWidth( lineWidth * getTargetPixelRatio() );
  14994. if ( object instanceof THREE.LineSegments ) {
  14995. renderer.setMode( _gl.LINES );
  14996. } else {
  14997. renderer.setMode( _gl.LINE_STRIP );
  14998. }
  14999. } else if ( object instanceof THREE.Points ) {
  15000. renderer.setMode( _gl.POINTS );
  15001. }
  15002. if ( geometry instanceof THREE.InstancedBufferGeometry ) {
  15003. if ( geometry.maxInstancedCount > 0 ) {
  15004. renderer.renderInstances( geometry, drawStart, drawCount );
  15005. }
  15006. } else {
  15007. renderer.render( drawStart, drawCount );
  15008. }
  15009. };
  15010. function setupVertexAttributes( material, program, geometry, startIndex ) {
  15011. var extension;
  15012. if ( geometry instanceof THREE.InstancedBufferGeometry ) {
  15013. extension = extensions.get( 'ANGLE_instanced_arrays' );
  15014. if ( extension === null ) {
  15015. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  15016. return;
  15017. }
  15018. }
  15019. if ( startIndex === undefined ) startIndex = 0;
  15020. state.initAttributes();
  15021. var geometryAttributes = geometry.attributes;
  15022. var programAttributes = program.getAttributes();
  15023. var materialDefaultAttributeValues = material.defaultAttributeValues;
  15024. for ( var name in programAttributes ) {
  15025. var programAttribute = programAttributes[ name ];
  15026. if ( programAttribute >= 0 ) {
  15027. var geometryAttribute = geometryAttributes[ name ];
  15028. if ( geometryAttribute !== undefined ) {
  15029. var size = geometryAttribute.itemSize;
  15030. var buffer = objects.getAttributeBuffer( geometryAttribute );
  15031. if ( geometryAttribute instanceof THREE.InterleavedBufferAttribute ) {
  15032. var data = geometryAttribute.data;
  15033. var stride = data.stride;
  15034. var offset = geometryAttribute.offset;
  15035. if ( data instanceof THREE.InstancedInterleavedBuffer ) {
  15036. state.enableAttributeAndDivisor( programAttribute, data.meshPerAttribute, extension );
  15037. if ( geometry.maxInstancedCount === undefined ) {
  15038. geometry.maxInstancedCount = data.meshPerAttribute * data.count;
  15039. }
  15040. } else {
  15041. state.enableAttribute( programAttribute );
  15042. }
  15043. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  15044. _gl.vertexAttribPointer( programAttribute, size, _gl.FLOAT, false, stride * data.array.BYTES_PER_ELEMENT, ( startIndex * stride + offset ) * data.array.BYTES_PER_ELEMENT );
  15045. } else {
  15046. if ( geometryAttribute instanceof THREE.InstancedBufferAttribute ) {
  15047. state.enableAttributeAndDivisor( programAttribute, geometryAttribute.meshPerAttribute, extension );
  15048. if ( geometry.maxInstancedCount === undefined ) {
  15049. geometry.maxInstancedCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  15050. }
  15051. } else {
  15052. state.enableAttribute( programAttribute );
  15053. }
  15054. var type = _gl.FLOAT;
  15055. var normalized = false;
  15056. var array = geometryAttribute.array;
  15057. if ( array instanceof Uint8Array ) {
  15058. type = _gl.UNSIGNED_BYTE;
  15059. normalized = true;
  15060. }
  15061. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  15062. _gl.vertexAttribPointer( programAttribute, size, type, normalized, 0, startIndex * size * array.BYTES_PER_ELEMENT );
  15063. }
  15064. } else if ( materialDefaultAttributeValues !== undefined ) {
  15065. var value = materialDefaultAttributeValues[ name ];
  15066. if ( value !== undefined ) {
  15067. switch ( value.length ) {
  15068. case 2:
  15069. _gl.vertexAttrib2fv( programAttribute, value );
  15070. break;
  15071. case 3:
  15072. _gl.vertexAttrib3fv( programAttribute, value );
  15073. break;
  15074. case 4:
  15075. _gl.vertexAttrib4fv( programAttribute, value );
  15076. break;
  15077. default:
  15078. _gl.vertexAttrib1fv( programAttribute, value );
  15079. }
  15080. }
  15081. }
  15082. }
  15083. }
  15084. state.disableUnusedAttributes();
  15085. }
  15086. // Sorting
  15087. function absNumericalSort( a, b ) {
  15088. return Math.abs( b[ 0 ] ) - Math.abs( a[ 0 ] );
  15089. }
  15090. function painterSortStable ( a, b ) {
  15091. if ( a.object.renderOrder !== b.object.renderOrder ) {
  15092. return a.object.renderOrder - b.object.renderOrder;
  15093. } else if ( a.material.id !== b.material.id ) {
  15094. return a.material.id - b.material.id;
  15095. } else if ( a.z !== b.z ) {
  15096. return a.z - b.z;
  15097. } else {
  15098. return a.id - b.id;
  15099. }
  15100. }
  15101. function reversePainterSortStable ( a, b ) {
  15102. if ( a.object.renderOrder !== b.object.renderOrder ) {
  15103. return a.object.renderOrder - b.object.renderOrder;
  15104. } if ( a.z !== b.z ) {
  15105. return b.z - a.z;
  15106. } else {
  15107. return a.id - b.id;
  15108. }
  15109. }
  15110. // Rendering
  15111. this.render = function ( scene, camera, renderTarget, forceClear ) {
  15112. if ( camera instanceof THREE.Camera === false ) {
  15113. console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
  15114. return;
  15115. }
  15116. var fog = scene.fog;
  15117. // reset caching for this frame
  15118. _currentGeometryProgram = '';
  15119. _currentMaterialId = - 1;
  15120. _currentCamera = null;
  15121. // update scene graph
  15122. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  15123. // update camera matrices and frustum
  15124. if ( camera.parent === null ) camera.updateMatrixWorld();
  15125. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  15126. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  15127. _frustum.setFromMatrix( _projScreenMatrix );
  15128. lights.length = 0;
  15129. opaqueObjectsLastIndex = - 1;
  15130. transparentObjectsLastIndex = - 1;
  15131. sprites.length = 0;
  15132. lensFlares.length = 0;
  15133. projectObject( scene, camera );
  15134. opaqueObjects.length = opaqueObjectsLastIndex + 1;
  15135. transparentObjects.length = transparentObjectsLastIndex + 1;
  15136. if ( _this.sortObjects === true ) {
  15137. opaqueObjects.sort( painterSortStable );
  15138. transparentObjects.sort( reversePainterSortStable );
  15139. }
  15140. //
  15141. setupShadows( lights );
  15142. shadowMap.render( scene, camera );
  15143. setupLights( lights, camera );
  15144. //
  15145. _infoRender.calls = 0;
  15146. _infoRender.vertices = 0;
  15147. _infoRender.faces = 0;
  15148. _infoRender.points = 0;
  15149. if ( renderTarget === undefined ) {
  15150. renderTarget = null;
  15151. }
  15152. this.setRenderTarget( renderTarget );
  15153. if ( this.autoClear || forceClear ) {
  15154. this.clear( this.autoClearColor, this.autoClearDepth, this.autoClearStencil );
  15155. }
  15156. //
  15157. if ( scene.overrideMaterial ) {
  15158. var overrideMaterial = scene.overrideMaterial;
  15159. renderObjects( opaqueObjects, camera, fog, overrideMaterial );
  15160. renderObjects( transparentObjects, camera, fog, overrideMaterial );
  15161. } else {
  15162. // opaque pass (front-to-back order)
  15163. state.setBlending( THREE.NoBlending );
  15164. renderObjects( opaqueObjects, camera, fog );
  15165. // transparent pass (back-to-front order)
  15166. renderObjects( transparentObjects, camera, fog );
  15167. }
  15168. // custom render plugins (post pass)
  15169. spritePlugin.render( scene, camera );
  15170. lensFlarePlugin.render( scene, camera, _currentViewport );
  15171. // Generate mipmap if we're using any kind of mipmap filtering
  15172. if ( renderTarget ) {
  15173. var texture = renderTarget.texture;
  15174. if ( texture.generateMipmaps && isPowerOfTwo( renderTarget ) &&
  15175. texture.minFilter !== THREE.NearestFilter &&
  15176. texture.minFilter !== THREE.LinearFilter ) {
  15177. updateRenderTargetMipmap( renderTarget );
  15178. }
  15179. }
  15180. // Ensure depth buffer writing is enabled so it can be cleared on next render
  15181. state.setDepthTest( true );
  15182. state.setDepthWrite( true );
  15183. state.setColorWrite( true );
  15184. // _gl.finish();
  15185. };
  15186. function pushRenderItem( object, geometry, material, z, group ) {
  15187. var array, index;
  15188. // allocate the next position in the appropriate array
  15189. if ( material.transparent ) {
  15190. array = transparentObjects;
  15191. index = ++ transparentObjectsLastIndex;
  15192. } else {
  15193. array = opaqueObjects;
  15194. index = ++ opaqueObjectsLastIndex;
  15195. }
  15196. // recycle existing render item or grow the array
  15197. var renderItem = array[ index ];
  15198. if ( renderItem !== undefined ) {
  15199. renderItem.id = object.id;
  15200. renderItem.object = object;
  15201. renderItem.geometry = geometry;
  15202. renderItem.material = material;
  15203. renderItem.z = _vector3.z;
  15204. renderItem.group = group;
  15205. } else {
  15206. renderItem = {
  15207. id: object.id,
  15208. object: object,
  15209. geometry: geometry,
  15210. material: material,
  15211. z: _vector3.z,
  15212. group: group
  15213. };
  15214. // assert( index === array.length );
  15215. array.push( renderItem );
  15216. }
  15217. }
  15218. function projectObject( object, camera ) {
  15219. if ( object.visible === false ) return;
  15220. if ( object.layers.test( camera.layers ) ) {
  15221. if ( object instanceof THREE.Light ) {
  15222. lights.push( object );
  15223. } else if ( object instanceof THREE.Sprite ) {
  15224. if ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) {
  15225. sprites.push( object );
  15226. }
  15227. } else if ( object instanceof THREE.LensFlare ) {
  15228. lensFlares.push( object );
  15229. } else if ( object instanceof THREE.ImmediateRenderObject ) {
  15230. if ( _this.sortObjects === true ) {
  15231. _vector3.setFromMatrixPosition( object.matrixWorld );
  15232. _vector3.applyProjection( _projScreenMatrix );
  15233. }
  15234. pushRenderItem( object, null, object.material, _vector3.z, null );
  15235. } else if ( object instanceof THREE.Mesh || object instanceof THREE.Line || object instanceof THREE.Points ) {
  15236. if ( object instanceof THREE.SkinnedMesh ) {
  15237. object.skeleton.update();
  15238. }
  15239. if ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) {
  15240. var material = object.material;
  15241. if ( material.visible === true ) {
  15242. if ( _this.sortObjects === true ) {
  15243. _vector3.setFromMatrixPosition( object.matrixWorld );
  15244. _vector3.applyProjection( _projScreenMatrix );
  15245. }
  15246. var geometry = objects.update( object );
  15247. if ( material instanceof THREE.MultiMaterial ) {
  15248. var groups = geometry.groups;
  15249. var materials = material.materials;
  15250. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  15251. var group = groups[ i ];
  15252. var groupMaterial = materials[ group.materialIndex ];
  15253. if ( groupMaterial.visible === true ) {
  15254. pushRenderItem( object, geometry, groupMaterial, _vector3.z, group );
  15255. }
  15256. }
  15257. } else {
  15258. pushRenderItem( object, geometry, material, _vector3.z, null );
  15259. }
  15260. }
  15261. }
  15262. }
  15263. }
  15264. var children = object.children;
  15265. for ( var i = 0, l = children.length; i < l; i ++ ) {
  15266. projectObject( children[ i ], camera );
  15267. }
  15268. }
  15269. function renderObjects( renderList, camera, fog, overrideMaterial ) {
  15270. for ( var i = 0, l = renderList.length; i < l; i ++ ) {
  15271. var renderItem = renderList[ i ];
  15272. var object = renderItem.object;
  15273. var geometry = renderItem.geometry;
  15274. var material = overrideMaterial === undefined ? renderItem.material : overrideMaterial;
  15275. var group = renderItem.group;
  15276. object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  15277. object.normalMatrix.getNormalMatrix( object.modelViewMatrix );
  15278. if ( object instanceof THREE.ImmediateRenderObject ) {
  15279. setMaterial( material );
  15280. var program = setProgram( camera, fog, material, object );
  15281. _currentGeometryProgram = '';
  15282. object.render( function ( object ) {
  15283. _this.renderBufferImmediate( object, program, material );
  15284. } );
  15285. } else {
  15286. _this.renderBufferDirect( camera, fog, geometry, material, object, group );
  15287. }
  15288. }
  15289. }
  15290. function initMaterial( material, fog, object ) {
  15291. var materialProperties = properties.get( material );
  15292. var parameters = programCache.getParameters( material, _lights, fog, object );
  15293. var code = programCache.getProgramCode( material, parameters );
  15294. var program = materialProperties.program;
  15295. var programChange = true;
  15296. if ( program === undefined ) {
  15297. // new material
  15298. material.addEventListener( 'dispose', onMaterialDispose );
  15299. } else if ( program.code !== code ) {
  15300. // changed glsl or parameters
  15301. releaseMaterialProgramReference( material );
  15302. } else if ( parameters.shaderID !== undefined ) {
  15303. // same glsl and uniform list
  15304. return;
  15305. } else {
  15306. // only rebuild uniform list
  15307. programChange = false;
  15308. }
  15309. if ( programChange ) {
  15310. if ( parameters.shaderID ) {
  15311. var shader = THREE.ShaderLib[ parameters.shaderID ];
  15312. materialProperties.__webglShader = {
  15313. name: material.type,
  15314. uniforms: THREE.UniformsUtils.clone( shader.uniforms ),
  15315. vertexShader: shader.vertexShader,
  15316. fragmentShader: shader.fragmentShader
  15317. };
  15318. } else {
  15319. materialProperties.__webglShader = {
  15320. name: material.type,
  15321. uniforms: material.uniforms,
  15322. vertexShader: material.vertexShader,
  15323. fragmentShader: material.fragmentShader
  15324. };
  15325. }
  15326. material.__webglShader = materialProperties.__webglShader;
  15327. program = programCache.acquireProgram( material, parameters, code );
  15328. materialProperties.program = program;
  15329. material.program = program;
  15330. }
  15331. var attributes = program.getAttributes();
  15332. if ( material.morphTargets ) {
  15333. material.numSupportedMorphTargets = 0;
  15334. for ( var i = 0; i < _this.maxMorphTargets; i ++ ) {
  15335. if ( attributes[ 'morphTarget' + i ] >= 0 ) {
  15336. material.numSupportedMorphTargets ++;
  15337. }
  15338. }
  15339. }
  15340. if ( material.morphNormals ) {
  15341. material.numSupportedMorphNormals = 0;
  15342. for ( var i = 0; i < _this.maxMorphNormals; i ++ ) {
  15343. if ( attributes[ 'morphNormal' + i ] >= 0 ) {
  15344. material.numSupportedMorphNormals ++;
  15345. }
  15346. }
  15347. }
  15348. materialProperties.uniformsList = [];
  15349. var uniforms = materialProperties.__webglShader.uniforms,
  15350. uniformLocations = materialProperties.program.getUniforms();
  15351. for ( var u in uniforms ) {
  15352. var location = uniformLocations[ u ];
  15353. if ( location ) {
  15354. materialProperties.uniformsList.push( [ materialProperties.__webglShader.uniforms[ u ], location ] );
  15355. }
  15356. }
  15357. if ( material instanceof THREE.MeshPhongMaterial ||
  15358. material instanceof THREE.MeshLambertMaterial ||
  15359. material instanceof THREE.MeshStandardMaterial ||
  15360. material.lights ) {
  15361. // store the light setup it was created for
  15362. materialProperties.lightsHash = _lights.hash;
  15363. // wire up the material to this renderer's lighting state
  15364. uniforms.ambientLightColor.value = _lights.ambient;
  15365. uniforms.directionalLights.value = _lights.directional;
  15366. uniforms.spotLights.value = _lights.spot;
  15367. uniforms.pointLights.value = _lights.point;
  15368. uniforms.hemisphereLights.value = _lights.hemi;
  15369. uniforms.directionalShadowMap.value = _lights.directionalShadowMap;
  15370. uniforms.directionalShadowMatrix.value = _lights.directionalShadowMatrix;
  15371. uniforms.spotShadowMap.value = _lights.spotShadowMap;
  15372. uniforms.spotShadowMatrix.value = _lights.spotShadowMatrix;
  15373. uniforms.pointShadowMap.value = _lights.pointShadowMap;
  15374. uniforms.pointShadowMatrix.value = _lights.pointShadowMatrix;
  15375. }
  15376. // detect dynamic uniforms
  15377. materialProperties.hasDynamicUniforms = false;
  15378. for ( var j = 0, jl = materialProperties.uniformsList.length; j < jl; j ++ ) {
  15379. var uniform = materialProperties.uniformsList[ j ][ 0 ];
  15380. if ( uniform.dynamic === true ) {
  15381. materialProperties.hasDynamicUniforms = true;
  15382. break;
  15383. }
  15384. }
  15385. }
  15386. function setMaterial( material ) {
  15387. setMaterialFaces( material );
  15388. if ( material.transparent === true ) {
  15389. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.premultipliedAlpha );
  15390. } else {
  15391. state.setBlending( THREE.NoBlending );
  15392. }
  15393. state.setDepthFunc( material.depthFunc );
  15394. state.setDepthTest( material.depthTest );
  15395. state.setDepthWrite( material.depthWrite );
  15396. state.setColorWrite( material.colorWrite );
  15397. state.setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  15398. }
  15399. function setMaterialFaces( material ) {
  15400. material.side !== THREE.DoubleSide ? state.enable( _gl.CULL_FACE ) : state.disable( _gl.CULL_FACE );
  15401. state.setFlipSided( material.side === THREE.BackSide );
  15402. }
  15403. function setProgram( camera, fog, material, object ) {
  15404. _usedTextureUnits = 0;
  15405. var materialProperties = properties.get( material );
  15406. if ( materialProperties.program === undefined ) {
  15407. material.needsUpdate = true;
  15408. }
  15409. if ( materialProperties.lightsHash !== undefined &&
  15410. materialProperties.lightsHash !== _lights.hash ) {
  15411. material.needsUpdate = true;
  15412. }
  15413. if ( material.needsUpdate ) {
  15414. initMaterial( material, fog, object );
  15415. material.needsUpdate = false;
  15416. }
  15417. var refreshProgram = false;
  15418. var refreshMaterial = false;
  15419. var refreshLights = false;
  15420. var program = materialProperties.program,
  15421. p_uniforms = program.getUniforms(),
  15422. m_uniforms = materialProperties.__webglShader.uniforms;
  15423. if ( program.id !== _currentProgram ) {
  15424. _gl.useProgram( program.program );
  15425. _currentProgram = program.id;
  15426. refreshProgram = true;
  15427. refreshMaterial = true;
  15428. refreshLights = true;
  15429. }
  15430. if ( material.id !== _currentMaterialId ) {
  15431. _currentMaterialId = material.id;
  15432. refreshMaterial = true;
  15433. }
  15434. if ( refreshProgram || camera !== _currentCamera ) {
  15435. _gl.uniformMatrix4fv( p_uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
  15436. if ( capabilities.logarithmicDepthBuffer ) {
  15437. _gl.uniform1f( p_uniforms.logDepthBufFC, 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
  15438. }
  15439. if ( camera !== _currentCamera ) {
  15440. _currentCamera = camera;
  15441. // lighting uniforms depend on the camera so enforce an update
  15442. // now, in case this material supports lights - or later, when
  15443. // the next material that does gets activated:
  15444. refreshMaterial = true; // set to true on material change
  15445. refreshLights = true; // remains set until update done
  15446. }
  15447. // load material specific uniforms
  15448. // (shader material also gets them for the sake of genericity)
  15449. if ( material instanceof THREE.ShaderMaterial ||
  15450. material instanceof THREE.MeshPhongMaterial ||
  15451. material instanceof THREE.MeshStandardMaterial ||
  15452. material.envMap ) {
  15453. if ( p_uniforms.cameraPosition !== undefined ) {
  15454. _vector3.setFromMatrixPosition( camera.matrixWorld );
  15455. _gl.uniform3f( p_uniforms.cameraPosition, _vector3.x, _vector3.y, _vector3.z );
  15456. }
  15457. }
  15458. if ( material instanceof THREE.MeshPhongMaterial ||
  15459. material instanceof THREE.MeshLambertMaterial ||
  15460. material instanceof THREE.MeshBasicMaterial ||
  15461. material instanceof THREE.MeshStandardMaterial ||
  15462. material instanceof THREE.ShaderMaterial ||
  15463. material.skinning ) {
  15464. if ( p_uniforms.viewMatrix !== undefined ) {
  15465. _gl.uniformMatrix4fv( p_uniforms.viewMatrix, false, camera.matrixWorldInverse.elements );
  15466. }
  15467. }
  15468. if ( p_uniforms.toneMappingExposure !== undefined ) {
  15469. _gl.uniform1f( p_uniforms.toneMappingExposure, _this.toneMappingExposure );
  15470. }
  15471. if ( p_uniforms.toneMappingWhitePoint !== undefined ) {
  15472. _gl.uniform1f( p_uniforms.toneMappingWhitePoint, _this.toneMappingWhitePoint );
  15473. }
  15474. }
  15475. // skinning uniforms must be set even if material didn't change
  15476. // auto-setting of texture unit for bone texture must go before other textures
  15477. // not sure why, but otherwise weird things happen
  15478. if ( material.skinning ) {
  15479. if ( object.bindMatrix && p_uniforms.bindMatrix !== undefined ) {
  15480. _gl.uniformMatrix4fv( p_uniforms.bindMatrix, false, object.bindMatrix.elements );
  15481. }
  15482. if ( object.bindMatrixInverse && p_uniforms.bindMatrixInverse !== undefined ) {
  15483. _gl.uniformMatrix4fv( p_uniforms.bindMatrixInverse, false, object.bindMatrixInverse.elements );
  15484. }
  15485. if ( capabilities.floatVertexTextures && object.skeleton && object.skeleton.useVertexTexture ) {
  15486. if ( p_uniforms.boneTexture !== undefined ) {
  15487. var textureUnit = getTextureUnit();
  15488. _gl.uniform1i( p_uniforms.boneTexture, textureUnit );
  15489. _this.setTexture( object.skeleton.boneTexture, textureUnit );
  15490. }
  15491. if ( p_uniforms.boneTextureWidth !== undefined ) {
  15492. _gl.uniform1i( p_uniforms.boneTextureWidth, object.skeleton.boneTextureWidth );
  15493. }
  15494. if ( p_uniforms.boneTextureHeight !== undefined ) {
  15495. _gl.uniform1i( p_uniforms.boneTextureHeight, object.skeleton.boneTextureHeight );
  15496. }
  15497. } else if ( object.skeleton && object.skeleton.boneMatrices ) {
  15498. if ( p_uniforms.boneGlobalMatrices !== undefined ) {
  15499. _gl.uniformMatrix4fv( p_uniforms.boneGlobalMatrices, false, object.skeleton.boneMatrices );
  15500. }
  15501. }
  15502. }
  15503. if ( refreshMaterial ) {
  15504. if ( material instanceof THREE.MeshPhongMaterial ||
  15505. material instanceof THREE.MeshLambertMaterial ||
  15506. material instanceof THREE.MeshStandardMaterial ||
  15507. material.lights ) {
  15508. // the current material requires lighting info
  15509. // note: all lighting uniforms are always set correctly
  15510. // they simply reference the renderer's state for their
  15511. // values
  15512. //
  15513. // use the current material's .needsUpdate flags to set
  15514. // the GL state when required
  15515. markUniformsLightsNeedsUpdate( m_uniforms, refreshLights );
  15516. }
  15517. // refresh uniforms common to several materials
  15518. if ( fog && material.fog ) {
  15519. refreshUniformsFog( m_uniforms, fog );
  15520. }
  15521. if ( material instanceof THREE.MeshBasicMaterial ||
  15522. material instanceof THREE.MeshLambertMaterial ||
  15523. material instanceof THREE.MeshPhongMaterial ||
  15524. material instanceof THREE.MeshStandardMaterial ) {
  15525. refreshUniformsCommon( m_uniforms, material );
  15526. }
  15527. // refresh single material specific uniforms
  15528. if ( material instanceof THREE.LineBasicMaterial ) {
  15529. refreshUniformsLine( m_uniforms, material );
  15530. } else if ( material instanceof THREE.LineDashedMaterial ) {
  15531. refreshUniformsLine( m_uniforms, material );
  15532. refreshUniformsDash( m_uniforms, material );
  15533. } else if ( material instanceof THREE.PointsMaterial ) {
  15534. refreshUniformsPoints( m_uniforms, material );
  15535. } else if ( material instanceof THREE.MeshLambertMaterial ) {
  15536. refreshUniformsLambert( m_uniforms, material );
  15537. } else if ( material instanceof THREE.MeshPhongMaterial ) {
  15538. refreshUniformsPhong( m_uniforms, material );
  15539. } else if ( material instanceof THREE.MeshStandardMaterial ) {
  15540. refreshUniformsStandard( m_uniforms, material );
  15541. } else if ( material instanceof THREE.MeshDepthMaterial ) {
  15542. m_uniforms.mNear.value = camera.near;
  15543. m_uniforms.mFar.value = camera.far;
  15544. m_uniforms.opacity.value = material.opacity;
  15545. } else if ( material instanceof THREE.MeshNormalMaterial ) {
  15546. m_uniforms.opacity.value = material.opacity;
  15547. }
  15548. // load common uniforms
  15549. loadUniformsGeneric( materialProperties.uniformsList );
  15550. }
  15551. loadUniformsMatrices( p_uniforms, object );
  15552. if ( p_uniforms.modelMatrix !== undefined ) {
  15553. _gl.uniformMatrix4fv( p_uniforms.modelMatrix, false, object.matrixWorld.elements );
  15554. }
  15555. if ( materialProperties.hasDynamicUniforms === true ) {
  15556. updateDynamicUniforms( materialProperties.uniformsList, object, camera );
  15557. }
  15558. return program;
  15559. }
  15560. function updateDynamicUniforms ( uniforms, object, camera ) {
  15561. var dynamicUniforms = [];
  15562. for ( var j = 0, jl = uniforms.length; j < jl; j ++ ) {
  15563. var uniform = uniforms[ j ][ 0 ];
  15564. var onUpdateCallback = uniform.onUpdateCallback;
  15565. if ( onUpdateCallback !== undefined ) {
  15566. onUpdateCallback.bind( uniform )( object, camera );
  15567. dynamicUniforms.push( uniforms[ j ] );
  15568. }
  15569. }
  15570. loadUniformsGeneric( dynamicUniforms );
  15571. }
  15572. // Uniforms (refresh uniforms objects)
  15573. function refreshUniformsCommon ( uniforms, material ) {
  15574. uniforms.opacity.value = material.opacity;
  15575. uniforms.diffuse.value = material.color;
  15576. if ( material.emissive ) {
  15577. uniforms.emissive.value.copy( material.emissive ).multiplyScalar( material.emissiveIntensity );
  15578. }
  15579. uniforms.map.value = material.map;
  15580. uniforms.specularMap.value = material.specularMap;
  15581. uniforms.alphaMap.value = material.alphaMap;
  15582. if ( material.aoMap ) {
  15583. uniforms.aoMap.value = material.aoMap;
  15584. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  15585. }
  15586. // uv repeat and offset setting priorities
  15587. // 1. color map
  15588. // 2. specular map
  15589. // 3. normal map
  15590. // 4. bump map
  15591. // 5. alpha map
  15592. // 6. emissive map
  15593. var uvScaleMap;
  15594. if ( material.map ) {
  15595. uvScaleMap = material.map;
  15596. } else if ( material.specularMap ) {
  15597. uvScaleMap = material.specularMap;
  15598. } else if ( material.displacementMap ) {
  15599. uvScaleMap = material.displacementMap;
  15600. } else if ( material.normalMap ) {
  15601. uvScaleMap = material.normalMap;
  15602. } else if ( material.bumpMap ) {
  15603. uvScaleMap = material.bumpMap;
  15604. } else if ( material.roughnessMap ) {
  15605. uvScaleMap = material.roughnessMap;
  15606. } else if ( material.metalnessMap ) {
  15607. uvScaleMap = material.metalnessMap;
  15608. } else if ( material.alphaMap ) {
  15609. uvScaleMap = material.alphaMap;
  15610. } else if ( material.emissiveMap ) {
  15611. uvScaleMap = material.emissiveMap;
  15612. }
  15613. if ( uvScaleMap !== undefined ) {
  15614. if ( uvScaleMap instanceof THREE.WebGLRenderTarget ) {
  15615. uvScaleMap = uvScaleMap.texture;
  15616. }
  15617. var offset = uvScaleMap.offset;
  15618. var repeat = uvScaleMap.repeat;
  15619. uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
  15620. }
  15621. uniforms.envMap.value = material.envMap;
  15622. uniforms.flipEnvMap.value = ( material.envMap instanceof THREE.WebGLRenderTargetCube ) ? 1 : - 1;
  15623. uniforms.reflectivity.value = material.reflectivity;
  15624. uniforms.refractionRatio.value = material.refractionRatio;
  15625. }
  15626. function refreshUniformsLine ( uniforms, material ) {
  15627. uniforms.diffuse.value = material.color;
  15628. uniforms.opacity.value = material.opacity;
  15629. }
  15630. function refreshUniformsDash ( uniforms, material ) {
  15631. uniforms.dashSize.value = material.dashSize;
  15632. uniforms.totalSize.value = material.dashSize + material.gapSize;
  15633. uniforms.scale.value = material.scale;
  15634. }
  15635. function refreshUniformsPoints ( uniforms, material ) {
  15636. uniforms.diffuse.value = material.color;
  15637. uniforms.opacity.value = material.opacity;
  15638. uniforms.size.value = material.size * _pixelRatio;
  15639. uniforms.scale.value = _canvas.clientHeight / 2.0; // TODO: Cache this.
  15640. uniforms.map.value = material.map;
  15641. if ( material.map !== null ) {
  15642. var offset = material.map.offset;
  15643. var repeat = material.map.repeat;
  15644. uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
  15645. }
  15646. }
  15647. function refreshUniformsFog ( uniforms, fog ) {
  15648. uniforms.fogColor.value = fog.color;
  15649. if ( fog instanceof THREE.Fog ) {
  15650. uniforms.fogNear.value = fog.near;
  15651. uniforms.fogFar.value = fog.far;
  15652. } else if ( fog instanceof THREE.FogExp2 ) {
  15653. uniforms.fogDensity.value = fog.density;
  15654. }
  15655. }
  15656. function refreshUniformsLambert ( uniforms, material ) {
  15657. if ( material.lightMap ) {
  15658. uniforms.lightMap.value = material.lightMap;
  15659. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  15660. }
  15661. if ( material.emissiveMap ) {
  15662. uniforms.emissiveMap.value = material.emissiveMap;
  15663. }
  15664. }
  15665. function refreshUniformsPhong ( uniforms, material ) {
  15666. uniforms.specular.value = material.specular;
  15667. uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 )
  15668. if ( material.lightMap ) {
  15669. uniforms.lightMap.value = material.lightMap;
  15670. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  15671. }
  15672. if ( material.emissiveMap ) {
  15673. uniforms.emissiveMap.value = material.emissiveMap;
  15674. }
  15675. if ( material.bumpMap ) {
  15676. uniforms.bumpMap.value = material.bumpMap;
  15677. uniforms.bumpScale.value = material.bumpScale;
  15678. }
  15679. if ( material.normalMap ) {
  15680. uniforms.normalMap.value = material.normalMap;
  15681. uniforms.normalScale.value.copy( material.normalScale );
  15682. }
  15683. if ( material.displacementMap ) {
  15684. uniforms.displacementMap.value = material.displacementMap;
  15685. uniforms.displacementScale.value = material.displacementScale;
  15686. uniforms.displacementBias.value = material.displacementBias;
  15687. }
  15688. }
  15689. function refreshUniformsStandard ( uniforms, material ) {
  15690. uniforms.roughness.value = material.roughness;
  15691. uniforms.metalness.value = material.metalness;
  15692. if ( material.roughnessMap ) {
  15693. uniforms.roughnessMap.value = material.roughnessMap;
  15694. }
  15695. if ( material.metalnessMap ) {
  15696. uniforms.metalnessMap.value = material.metalnessMap;
  15697. }
  15698. if ( material.lightMap ) {
  15699. uniforms.lightMap.value = material.lightMap;
  15700. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  15701. }
  15702. if ( material.emissiveMap ) {
  15703. uniforms.emissiveMap.value = material.emissiveMap;
  15704. }
  15705. if ( material.bumpMap ) {
  15706. uniforms.bumpMap.value = material.bumpMap;
  15707. uniforms.bumpScale.value = material.bumpScale;
  15708. }
  15709. if ( material.normalMap ) {
  15710. uniforms.normalMap.value = material.normalMap;
  15711. uniforms.normalScale.value.copy( material.normalScale );
  15712. }
  15713. if ( material.displacementMap ) {
  15714. uniforms.displacementMap.value = material.displacementMap;
  15715. uniforms.displacementScale.value = material.displacementScale;
  15716. uniforms.displacementBias.value = material.displacementBias;
  15717. }
  15718. if ( material.envMap ) {
  15719. //uniforms.envMap.value = material.envMap; // part of uniforms common
  15720. uniforms.envMapIntensity.value = material.envMapIntensity;
  15721. }
  15722. }
  15723. // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  15724. function markUniformsLightsNeedsUpdate ( uniforms, value ) {
  15725. uniforms.ambientLightColor.needsUpdate = value;
  15726. uniforms.directionalLights.needsUpdate = value;
  15727. uniforms.pointLights.needsUpdate = value;
  15728. uniforms.spotLights.needsUpdate = value;
  15729. uniforms.hemisphereLights.needsUpdate = value;
  15730. }
  15731. // Uniforms (load to GPU)
  15732. function loadUniformsMatrices ( uniforms, object ) {
  15733. _gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, object.modelViewMatrix.elements );
  15734. if ( uniforms.normalMatrix ) {
  15735. _gl.uniformMatrix3fv( uniforms.normalMatrix, false, object.normalMatrix.elements );
  15736. }
  15737. }
  15738. function getTextureUnit() {
  15739. var textureUnit = _usedTextureUnits;
  15740. if ( textureUnit >= capabilities.maxTextures ) {
  15741. console.warn( 'WebGLRenderer: trying to use ' + textureUnit + ' texture units while this GPU supports only ' + capabilities.maxTextures );
  15742. }
  15743. _usedTextureUnits += 1;
  15744. return textureUnit;
  15745. }
  15746. function loadUniform( uniform, type, location, value ) {
  15747. var texture, textureUnit;
  15748. if ( type === '1i' ) {
  15749. _gl.uniform1i( location, value );
  15750. } else if ( type === '1f' ) {
  15751. _gl.uniform1f( location, value );
  15752. } else if ( type === '2f' ) {
  15753. _gl.uniform2f( location, value[ 0 ], value[ 1 ] );
  15754. } else if ( type === '3f' ) {
  15755. _gl.uniform3f( location, value[ 0 ], value[ 1 ], value[ 2 ] );
  15756. } else if ( type === '4f' ) {
  15757. _gl.uniform4f( location, value[ 0 ], value[ 1 ], value[ 2 ], value[ 3 ] );
  15758. } else if ( type === '1iv' ) {
  15759. _gl.uniform1iv( location, value );
  15760. } else if ( type === '3iv' ) {
  15761. _gl.uniform3iv( location, value );
  15762. } else if ( type === '1fv' ) {
  15763. _gl.uniform1fv( location, value );
  15764. } else if ( type === '2fv' ) {
  15765. _gl.uniform2fv( location, value );
  15766. } else if ( type === '3fv' ) {
  15767. _gl.uniform3fv( location, value );
  15768. } else if ( type === '4fv' ) {
  15769. _gl.uniform4fv( location, value );
  15770. } else if ( type === 'Matrix2fv' ) {
  15771. _gl.uniformMatrix2fv( location, false, value );
  15772. } else if ( type === 'Matrix3fv' ) {
  15773. _gl.uniformMatrix3fv( location, false, value );
  15774. } else if ( type === 'Matrix4fv' ) {
  15775. _gl.uniformMatrix4fv( location, false, value );
  15776. //
  15777. } else if ( type === 'i' ) {
  15778. // console.warn( 'THREE.WebGLRenderer: Uniform "i" is now "1i".' );
  15779. _gl.uniform1i( location, value );
  15780. } else if ( type === 'f' ) {
  15781. // console.warn( 'THREE.WebGLRenderer: Uniform "f" is now "1f".' );
  15782. _gl.uniform1f( location, value );
  15783. } else if ( type === 'iv1' ) {
  15784. // console.warn( 'THREE.WebGLRenderer: Uniform "iv1" is now "1iv".' );
  15785. _gl.uniform1iv( location, value );
  15786. } else if ( type === 'iv' ) {
  15787. // console.warn( 'THREE.WebGLRenderer: Uniform "iv" is now "3iv".' );
  15788. _gl.uniform3iv( location, value );
  15789. } else if ( type === 'fv1' ) {
  15790. // console.warn( 'THREE.WebGLRenderer: Uniform "fv1" is now "1fv".' );
  15791. _gl.uniform1fv( location, value );
  15792. } else if ( type === 'fv' ) {
  15793. // console.warn( 'THREE.WebGLRenderer: Uniform "fv" is now "3fv".' );
  15794. _gl.uniform3fv( location, value );
  15795. } else if ( type === 'v2' ) {
  15796. // single THREE.Vector2
  15797. _gl.uniform2f( location, value.x, value.y );
  15798. } else if ( type === 'v3' ) {
  15799. // single THREE.Vector3
  15800. _gl.uniform3f( location, value.x, value.y, value.z );
  15801. } else if ( type === 'v4' ) {
  15802. // single THREE.Vector4
  15803. _gl.uniform4f( location, value.x, value.y, value.z, value.w );
  15804. } else if ( type === 'c' ) {
  15805. // single THREE.Color
  15806. _gl.uniform3f( location, value.r, value.g, value.b );
  15807. } else if ( type === 's' ) {
  15808. // TODO: Optimize this
  15809. var properties = uniform.properties;
  15810. for ( var name in properties ) {
  15811. var property = properties[ name ];
  15812. var locationProperty = location[ name ];
  15813. var valueProperty = value[ name ];
  15814. loadUniform( property, property.type, locationProperty, valueProperty );
  15815. }
  15816. } else if ( type === 'sa' ) {
  15817. // TODO: Optimize this
  15818. var properties = uniform.properties;
  15819. for ( var i = 0, l = value.length; i < l; i ++ ) {
  15820. for ( var name in properties ) {
  15821. var property = properties[ name ];
  15822. var locationProperty = location[ i ][ name ];
  15823. var valueProperty = value[ i ][ name ];
  15824. loadUniform( property, property.type, locationProperty, valueProperty );
  15825. }
  15826. }
  15827. } else if ( type === 'v2v' ) {
  15828. // array of THREE.Vector2
  15829. if ( uniform._array === undefined ) {
  15830. uniform._array = new Float32Array( 2 * value.length );
  15831. }
  15832. for ( var i = 0, i2 = 0, il = value.length; i < il; i ++, i2 += 2 ) {
  15833. uniform._array[ i2 + 0 ] = value[ i ].x;
  15834. uniform._array[ i2 + 1 ] = value[ i ].y;
  15835. }
  15836. _gl.uniform2fv( location, uniform._array );
  15837. } else if ( type === 'v3v' ) {
  15838. // array of THREE.Vector3
  15839. if ( uniform._array === undefined ) {
  15840. uniform._array = new Float32Array( 3 * value.length );
  15841. }
  15842. for ( var i = 0, i3 = 0, il = value.length; i < il; i ++, i3 += 3 ) {
  15843. uniform._array[ i3 + 0 ] = value[ i ].x;
  15844. uniform._array[ i3 + 1 ] = value[ i ].y;
  15845. uniform._array[ i3 + 2 ] = value[ i ].z;
  15846. }
  15847. _gl.uniform3fv( location, uniform._array );
  15848. } else if ( type === 'v4v' ) {
  15849. // array of THREE.Vector4
  15850. if ( uniform._array === undefined ) {
  15851. uniform._array = new Float32Array( 4 * value.length );
  15852. }
  15853. for ( var i = 0, i4 = 0, il = value.length; i < il; i ++, i4 += 4 ) {
  15854. uniform._array[ i4 + 0 ] = value[ i ].x;
  15855. uniform._array[ i4 + 1 ] = value[ i ].y;
  15856. uniform._array[ i4 + 2 ] = value[ i ].z;
  15857. uniform._array[ i4 + 3 ] = value[ i ].w;
  15858. }
  15859. _gl.uniform4fv( location, uniform._array );
  15860. } else if ( type === 'm2' ) {
  15861. // single THREE.Matrix2
  15862. _gl.uniformMatrix2fv( location, false, value.elements );
  15863. } else if ( type === 'm3' ) {
  15864. // single THREE.Matrix3
  15865. _gl.uniformMatrix3fv( location, false, value.elements );
  15866. } else if ( type === 'm3v' ) {
  15867. // array of THREE.Matrix3
  15868. if ( uniform._array === undefined ) {
  15869. uniform._array = new Float32Array( 9 * value.length );
  15870. }
  15871. for ( var i = 0, il = value.length; i < il; i ++ ) {
  15872. value[ i ].flattenToArrayOffset( uniform._array, i * 9 );
  15873. }
  15874. _gl.uniformMatrix3fv( location, false, uniform._array );
  15875. } else if ( type === 'm4' ) {
  15876. // single THREE.Matrix4
  15877. _gl.uniformMatrix4fv( location, false, value.elements );
  15878. } else if ( type === 'm4v' ) {
  15879. // array of THREE.Matrix4
  15880. if ( uniform._array === undefined ) {
  15881. uniform._array = new Float32Array( 16 * value.length );
  15882. }
  15883. for ( var i = 0, il = value.length; i < il; i ++ ) {
  15884. value[ i ].flattenToArrayOffset( uniform._array, i * 16 );
  15885. }
  15886. _gl.uniformMatrix4fv( location, false, uniform._array );
  15887. } else if ( type === 't' ) {
  15888. // single THREE.Texture (2d or cube)
  15889. texture = value;
  15890. textureUnit = getTextureUnit();
  15891. _gl.uniform1i( location, textureUnit );
  15892. if ( ! texture ) return;
  15893. if ( texture instanceof THREE.CubeTexture ||
  15894. ( Array.isArray( texture.image ) && texture.image.length === 6 ) ) {
  15895. // CompressedTexture can have Array in image :/
  15896. setCubeTexture( texture, textureUnit );
  15897. } else if ( texture instanceof THREE.WebGLRenderTargetCube ) {
  15898. setCubeTextureDynamic( texture.texture, textureUnit );
  15899. } else if ( texture instanceof THREE.WebGLRenderTarget ) {
  15900. _this.setTexture( texture.texture, textureUnit );
  15901. } else {
  15902. _this.setTexture( texture, textureUnit );
  15903. }
  15904. } else if ( type === 'tv' ) {
  15905. // array of THREE.Texture (2d or cube)
  15906. if ( uniform._array === undefined ) {
  15907. uniform._array = [];
  15908. }
  15909. for ( var i = 0, il = uniform.value.length; i < il; i ++ ) {
  15910. uniform._array[ i ] = getTextureUnit();
  15911. }
  15912. _gl.uniform1iv( location, uniform._array );
  15913. for ( var i = 0, il = uniform.value.length; i < il; i ++ ) {
  15914. texture = uniform.value[ i ];
  15915. textureUnit = uniform._array[ i ];
  15916. if ( ! texture ) continue;
  15917. if ( texture instanceof THREE.CubeTexture ||
  15918. ( texture.image instanceof Array && texture.image.length === 6 ) ) {
  15919. // CompressedTexture can have Array in image :/
  15920. setCubeTexture( texture, textureUnit );
  15921. } else if ( texture instanceof THREE.WebGLRenderTarget ) {
  15922. _this.setTexture( texture.texture, textureUnit );
  15923. } else if ( texture instanceof THREE.WebGLRenderTargetCube ) {
  15924. setCubeTextureDynamic( texture.texture, textureUnit );
  15925. } else {
  15926. _this.setTexture( texture, textureUnit );
  15927. }
  15928. }
  15929. } else {
  15930. console.warn( 'THREE.WebGLRenderer: Unknown uniform type: ' + type );
  15931. }
  15932. }
  15933. function loadUniformsGeneric( uniforms ) {
  15934. for ( var i = 0, l = uniforms.length; i < l; i ++ ) {
  15935. var uniform = uniforms[ i ][ 0 ];
  15936. // needsUpdate property is not added to all uniforms.
  15937. if ( uniform.needsUpdate === false ) continue;
  15938. var type = uniform.type;
  15939. var location = uniforms[ i ][ 1 ];
  15940. var value = uniform.value;
  15941. loadUniform( uniform, type, location, value );
  15942. }
  15943. }
  15944. function setupShadows ( lights ) {
  15945. var lightShadowsLength = 0;
  15946. for ( var i = 0, l = lights.length; i < l; i ++ ) {
  15947. var light = lights[ i ];
  15948. if ( light.castShadow ) {
  15949. _lights.shadows[ lightShadowsLength ++ ] = light;
  15950. }
  15951. }
  15952. _lights.shadows.length = lightShadowsLength;
  15953. }
  15954. function setupLights ( lights, camera ) {
  15955. var l, ll, light,
  15956. r = 0, g = 0, b = 0,
  15957. color,
  15958. intensity,
  15959. distance,
  15960. viewMatrix = camera.matrixWorldInverse,
  15961. directionalLength = 0,
  15962. pointLength = 0,
  15963. spotLength = 0,
  15964. hemiLength = 0;
  15965. for ( l = 0, ll = lights.length; l < ll; l ++ ) {
  15966. light = lights[ l ];
  15967. color = light.color;
  15968. intensity = light.intensity;
  15969. distance = light.distance;
  15970. if ( light instanceof THREE.AmbientLight ) {
  15971. r += color.r * intensity;
  15972. g += color.g * intensity;
  15973. b += color.b * intensity;
  15974. } else if ( light instanceof THREE.DirectionalLight ) {
  15975. var uniforms = lightCache.get( light );
  15976. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  15977. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  15978. _vector3.setFromMatrixPosition( light.target.matrixWorld );
  15979. uniforms.direction.sub( _vector3 );
  15980. uniforms.direction.transformDirection( viewMatrix );
  15981. uniforms.shadow = light.castShadow;
  15982. if ( light.castShadow ) {
  15983. uniforms.shadowBias = light.shadow.bias;
  15984. uniforms.shadowRadius = light.shadow.radius;
  15985. uniforms.shadowMapSize = light.shadow.mapSize;
  15986. }
  15987. _lights.directionalShadowMap[ directionalLength ] = light.shadow.map;
  15988. _lights.directionalShadowMatrix[ directionalLength ] = light.shadow.matrix;
  15989. _lights.directional[ directionalLength ++ ] = uniforms;
  15990. } else if ( light instanceof THREE.SpotLight ) {
  15991. var uniforms = lightCache.get( light );
  15992. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  15993. uniforms.position.applyMatrix4( viewMatrix );
  15994. uniforms.color.copy( color ).multiplyScalar( intensity );
  15995. uniforms.distance = distance;
  15996. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  15997. _vector3.setFromMatrixPosition( light.target.matrixWorld );
  15998. uniforms.direction.sub( _vector3 );
  15999. uniforms.direction.transformDirection( viewMatrix );
  16000. uniforms.coneCos = Math.cos( light.angle );
  16001. uniforms.penumbraCos = Math.cos( light.angle * ( 1 - light.penumbra ) );
  16002. uniforms.decay = ( light.distance === 0 ) ? 0.0 : light.decay;
  16003. uniforms.shadow = light.castShadow;
  16004. if ( light.castShadow ) {
  16005. uniforms.shadowBias = light.shadow.bias;
  16006. uniforms.shadowRadius = light.shadow.radius;
  16007. uniforms.shadowMapSize = light.shadow.mapSize;
  16008. }
  16009. _lights.spotShadowMap[ spotLength ] = light.shadow.map;
  16010. _lights.spotShadowMatrix[ spotLength ] = light.shadow.matrix;
  16011. _lights.spot[ spotLength ++ ] = uniforms;
  16012. } else if ( light instanceof THREE.PointLight ) {
  16013. var uniforms = lightCache.get( light );
  16014. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  16015. uniforms.position.applyMatrix4( viewMatrix );
  16016. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  16017. uniforms.distance = light.distance;
  16018. uniforms.decay = ( light.distance === 0 ) ? 0.0 : light.decay;
  16019. uniforms.shadow = light.castShadow;
  16020. if ( light.castShadow ) {
  16021. uniforms.shadowBias = light.shadow.bias;
  16022. uniforms.shadowRadius = light.shadow.radius;
  16023. uniforms.shadowMapSize = light.shadow.mapSize;
  16024. }
  16025. _lights.pointShadowMap[ pointLength ] = light.shadow.map;
  16026. if ( _lights.pointShadowMatrix[ pointLength ] === undefined ) {
  16027. _lights.pointShadowMatrix[ pointLength ] = new THREE.Matrix4();
  16028. }
  16029. // for point lights we set the shadow matrix to be a translation-only matrix
  16030. // equal to inverse of the light's position
  16031. _vector3.setFromMatrixPosition( light.matrixWorld ).negate();
  16032. _lights.pointShadowMatrix[ pointLength ].identity().setPosition( _vector3 );
  16033. _lights.point[ pointLength ++ ] = uniforms;
  16034. } else if ( light instanceof THREE.HemisphereLight ) {
  16035. var uniforms = lightCache.get( light );
  16036. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  16037. uniforms.direction.transformDirection( viewMatrix );
  16038. uniforms.direction.normalize();
  16039. uniforms.skyColor.copy( light.color ).multiplyScalar( intensity );
  16040. uniforms.groundColor.copy( light.groundColor ).multiplyScalar( intensity );
  16041. _lights.hemi[ hemiLength ++ ] = uniforms;
  16042. }
  16043. }
  16044. _lights.ambient[ 0 ] = r;
  16045. _lights.ambient[ 1 ] = g;
  16046. _lights.ambient[ 2 ] = b;
  16047. _lights.directional.length = directionalLength;
  16048. _lights.spot.length = spotLength;
  16049. _lights.point.length = pointLength;
  16050. _lights.hemi.length = hemiLength;
  16051. _lights.hash = directionalLength + ',' + pointLength + ',' + spotLength + ',' + hemiLength + ',' + _lights.shadows.length;
  16052. }
  16053. // GL state setting
  16054. this.setFaceCulling = function ( cullFace, frontFaceDirection ) {
  16055. if ( cullFace === THREE.CullFaceNone ) {
  16056. state.disable( _gl.CULL_FACE );
  16057. } else {
  16058. if ( frontFaceDirection === THREE.FrontFaceDirectionCW ) {
  16059. _gl.frontFace( _gl.CW );
  16060. } else {
  16061. _gl.frontFace( _gl.CCW );
  16062. }
  16063. if ( cullFace === THREE.CullFaceBack ) {
  16064. _gl.cullFace( _gl.BACK );
  16065. } else if ( cullFace === THREE.CullFaceFront ) {
  16066. _gl.cullFace( _gl.FRONT );
  16067. } else {
  16068. _gl.cullFace( _gl.FRONT_AND_BACK );
  16069. }
  16070. state.enable( _gl.CULL_FACE );
  16071. }
  16072. };
  16073. // Textures
  16074. function setTextureParameters ( textureType, texture, isPowerOfTwoImage ) {
  16075. var extension;
  16076. if ( isPowerOfTwoImage ) {
  16077. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, paramThreeToGL( texture.wrapS ) );
  16078. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, paramThreeToGL( texture.wrapT ) );
  16079. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, paramThreeToGL( texture.magFilter ) );
  16080. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, paramThreeToGL( texture.minFilter ) );
  16081. } else {
  16082. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, _gl.CLAMP_TO_EDGE );
  16083. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, _gl.CLAMP_TO_EDGE );
  16084. if ( texture.wrapS !== THREE.ClampToEdgeWrapping || texture.wrapT !== THREE.ClampToEdgeWrapping ) {
  16085. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.', texture );
  16086. }
  16087. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, filterFallback( texture.magFilter ) );
  16088. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, filterFallback( texture.minFilter ) );
  16089. if ( texture.minFilter !== THREE.NearestFilter && texture.minFilter !== THREE.LinearFilter ) {
  16090. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.', texture );
  16091. }
  16092. }
  16093. extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  16094. if ( extension ) {
  16095. if ( texture.type === THREE.FloatType && extensions.get( 'OES_texture_float_linear' ) === null ) return;
  16096. if ( texture.type === THREE.HalfFloatType && extensions.get( 'OES_texture_half_float_linear' ) === null ) return;
  16097. if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
  16098. _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, _this.getMaxAnisotropy() ) );
  16099. properties.get( texture ).__currentAnisotropy = texture.anisotropy;
  16100. }
  16101. }
  16102. }
  16103. function uploadTexture( textureProperties, texture, slot ) {
  16104. if ( textureProperties.__webglInit === undefined ) {
  16105. textureProperties.__webglInit = true;
  16106. texture.addEventListener( 'dispose', onTextureDispose );
  16107. textureProperties.__webglTexture = _gl.createTexture();
  16108. _infoMemory.textures ++;
  16109. }
  16110. state.activeTexture( _gl.TEXTURE0 + slot );
  16111. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  16112. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  16113. _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );
  16114. _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
  16115. var image = clampToMaxSize( texture.image, capabilities.maxTextureSize );
  16116. if ( textureNeedsPowerOfTwo( texture ) && isPowerOfTwo( image ) === false ) {
  16117. image = makePowerOfTwo( image );
  16118. }
  16119. var isPowerOfTwoImage = isPowerOfTwo( image ),
  16120. glFormat = paramThreeToGL( texture.format ),
  16121. glType = paramThreeToGL( texture.type );
  16122. setTextureParameters( _gl.TEXTURE_2D, texture, isPowerOfTwoImage );
  16123. var mipmap, mipmaps = texture.mipmaps;
  16124. if ( texture instanceof THREE.DataTexture ) {
  16125. // use manually created mipmaps if available
  16126. // if there are no manual mipmaps
  16127. // set 0 level mipmap and then use GL to generate other mipmap levels
  16128. if ( mipmaps.length > 0 && isPowerOfTwoImage ) {
  16129. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  16130. mipmap = mipmaps[ i ];
  16131. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  16132. }
  16133. texture.generateMipmaps = false;
  16134. } else {
  16135. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, image.width, image.height, 0, glFormat, glType, image.data );
  16136. }
  16137. } else if ( texture instanceof THREE.CompressedTexture ) {
  16138. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  16139. mipmap = mipmaps[ i ];
  16140. if ( texture.format !== THREE.RGBAFormat && texture.format !== THREE.RGBFormat ) {
  16141. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  16142. state.compressedTexImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  16143. } else {
  16144. console.warn( "THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()" );
  16145. }
  16146. } else {
  16147. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  16148. }
  16149. }
  16150. } else {
  16151. // regular Texture (image, video, canvas)
  16152. // use manually created mipmaps if available
  16153. // if there are no manual mipmaps
  16154. // set 0 level mipmap and then use GL to generate other mipmap levels
  16155. if ( mipmaps.length > 0 && isPowerOfTwoImage ) {
  16156. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  16157. mipmap = mipmaps[ i ];
  16158. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, glFormat, glType, mipmap );
  16159. }
  16160. texture.generateMipmaps = false;
  16161. } else {
  16162. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, glFormat, glType, image );
  16163. }
  16164. }
  16165. if ( texture.generateMipmaps && isPowerOfTwoImage ) _gl.generateMipmap( _gl.TEXTURE_2D );
  16166. textureProperties.__version = texture.version;
  16167. if ( texture.onUpdate ) texture.onUpdate( texture );
  16168. }
  16169. this.setTexture = function ( texture, slot ) {
  16170. var textureProperties = properties.get( texture );
  16171. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  16172. var image = texture.image;
  16173. if ( image === undefined ) {
  16174. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is undefined', texture );
  16175. return;
  16176. }
  16177. if ( image.complete === false ) {
  16178. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete', texture );
  16179. return;
  16180. }
  16181. uploadTexture( textureProperties, texture, slot );
  16182. return;
  16183. }
  16184. state.activeTexture( _gl.TEXTURE0 + slot );
  16185. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  16186. };
  16187. function clampToMaxSize ( image, maxSize ) {
  16188. if ( image.width > maxSize || image.height > maxSize ) {
  16189. // Warning: Scaling through the canvas will only work with images that use
  16190. // premultiplied alpha.
  16191. var scale = maxSize / Math.max( image.width, image.height );
  16192. var canvas = document.createElement( 'canvas' );
  16193. canvas.width = Math.floor( image.width * scale );
  16194. canvas.height = Math.floor( image.height * scale );
  16195. var context = canvas.getContext( '2d' );
  16196. context.drawImage( image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height );
  16197. console.warn( 'THREE.WebGLRenderer: image is too big (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
  16198. return canvas;
  16199. }
  16200. return image;
  16201. }
  16202. function isPowerOfTwo( image ) {
  16203. return THREE.Math.isPowerOfTwo( image.width ) && THREE.Math.isPowerOfTwo( image.height );
  16204. }
  16205. function textureNeedsPowerOfTwo( texture ) {
  16206. if ( texture.wrapS !== THREE.ClampToEdgeWrapping || texture.wrapT !== THREE.ClampToEdgeWrapping ) return true;
  16207. if ( texture.minFilter !== THREE.NearestFilter && texture.minFilter !== THREE.LinearFilter ) return true;
  16208. return false;
  16209. }
  16210. function makePowerOfTwo( image ) {
  16211. if ( image instanceof HTMLImageElement || image instanceof HTMLCanvasElement ) {
  16212. var canvas = document.createElement( 'canvas' );
  16213. canvas.width = THREE.Math.nearestPowerOfTwo( image.width );
  16214. canvas.height = THREE.Math.nearestPowerOfTwo( image.height );
  16215. var context = canvas.getContext( '2d' );
  16216. context.drawImage( image, 0, 0, canvas.width, canvas.height );
  16217. console.warn( 'THREE.WebGLRenderer: image is not power of two (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
  16218. return canvas;
  16219. }
  16220. return image;
  16221. }
  16222. function setCubeTexture ( texture, slot ) {
  16223. var textureProperties = properties.get( texture );
  16224. if ( texture.image.length === 6 ) {
  16225. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  16226. if ( ! textureProperties.__image__webglTextureCube ) {
  16227. texture.addEventListener( 'dispose', onTextureDispose );
  16228. textureProperties.__image__webglTextureCube = _gl.createTexture();
  16229. _infoMemory.textures ++;
  16230. }
  16231. state.activeTexture( _gl.TEXTURE0 + slot );
  16232. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  16233. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  16234. var isCompressed = texture instanceof THREE.CompressedTexture;
  16235. var isDataTexture = texture.image[ 0 ] instanceof THREE.DataTexture;
  16236. var cubeImage = [];
  16237. for ( var i = 0; i < 6; i ++ ) {
  16238. if ( _this.autoScaleCubemaps && ! isCompressed && ! isDataTexture ) {
  16239. cubeImage[ i ] = clampToMaxSize( texture.image[ i ], capabilities.maxCubemapSize );
  16240. } else {
  16241. cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
  16242. }
  16243. }
  16244. var image = cubeImage[ 0 ],
  16245. isPowerOfTwoImage = isPowerOfTwo( image ),
  16246. glFormat = paramThreeToGL( texture.format ),
  16247. glType = paramThreeToGL( texture.type );
  16248. setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture, isPowerOfTwoImage );
  16249. for ( var i = 0; i < 6; i ++ ) {
  16250. if ( ! isCompressed ) {
  16251. if ( isDataTexture ) {
  16252. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
  16253. } else {
  16254. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, glFormat, glType, cubeImage[ i ] );
  16255. }
  16256. } else {
  16257. var mipmap, mipmaps = cubeImage[ i ].mipmaps;
  16258. for ( var j = 0, jl = mipmaps.length; j < jl; j ++ ) {
  16259. mipmap = mipmaps[ j ];
  16260. if ( texture.format !== THREE.RGBAFormat && texture.format !== THREE.RGBFormat ) {
  16261. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  16262. state.compressedTexImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  16263. } else {
  16264. console.warn( "THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setCubeTexture()" );
  16265. }
  16266. } else {
  16267. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  16268. }
  16269. }
  16270. }
  16271. }
  16272. if ( texture.generateMipmaps && isPowerOfTwoImage ) {
  16273. _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  16274. }
  16275. textureProperties.__version = texture.version;
  16276. if ( texture.onUpdate ) texture.onUpdate( texture );
  16277. } else {
  16278. state.activeTexture( _gl.TEXTURE0 + slot );
  16279. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  16280. }
  16281. }
  16282. }
  16283. function setCubeTextureDynamic ( texture, slot ) {
  16284. state.activeTexture( _gl.TEXTURE0 + slot );
  16285. state.bindTexture( _gl.TEXTURE_CUBE_MAP, properties.get( texture ).__webglTexture );
  16286. }
  16287. // Render targets
  16288. // Setup storage for target texture and bind it to correct framebuffer
  16289. function setupFrameBufferTexture ( framebuffer, renderTarget, attachment, textureTarget ) {
  16290. var glFormat = paramThreeToGL( renderTarget.texture.format );
  16291. var glType = paramThreeToGL( renderTarget.texture.type );
  16292. state.texImage2D( textureTarget, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  16293. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  16294. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, attachment, textureTarget, properties.get( renderTarget.texture ).__webglTexture, 0 );
  16295. _gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
  16296. }
  16297. // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  16298. function setupRenderBufferStorage ( renderbuffer, renderTarget ) {
  16299. _gl.bindRenderbuffer( _gl.RENDERBUFFER, renderbuffer );
  16300. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  16301. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_COMPONENT16, renderTarget.width, renderTarget.height );
  16302. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  16303. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  16304. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_STENCIL, renderTarget.width, renderTarget.height );
  16305. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  16306. } else {
  16307. // FIXME: We don't support !depth !stencil
  16308. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.RGBA4, renderTarget.width, renderTarget.height );
  16309. }
  16310. _gl.bindRenderbuffer( _gl.RENDERBUFFER, null );
  16311. }
  16312. // Setup GL resources for a non-texture depth buffer
  16313. function setupDepthRenderbuffer( renderTarget ) {
  16314. var renderTargetProperties = properties.get( renderTarget );
  16315. var isCube = ( renderTarget instanceof THREE.WebGLRenderTargetCube );
  16316. if ( isCube ) {
  16317. renderTargetProperties.__webglDepthbuffer = [];
  16318. for ( var i = 0; i < 6; i ++ ) {
  16319. _gl.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer[ i ] );
  16320. renderTargetProperties.__webglDepthbuffer[ i ] = _gl.createRenderbuffer();
  16321. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer[ i ], renderTarget );
  16322. }
  16323. } else {
  16324. _gl.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer );
  16325. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  16326. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer, renderTarget );
  16327. }
  16328. _gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
  16329. }
  16330. // Set up GL resources for the render target
  16331. function setupRenderTarget( renderTarget ) {
  16332. var renderTargetProperties = properties.get( renderTarget );
  16333. var textureProperties = properties.get( renderTarget.texture );
  16334. renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
  16335. textureProperties.__webglTexture = _gl.createTexture();
  16336. _infoMemory.textures ++;
  16337. var isCube = ( renderTarget instanceof THREE.WebGLRenderTargetCube );
  16338. var isTargetPowerOfTwo = THREE.Math.isPowerOfTwo( renderTarget.width ) && THREE.Math.isPowerOfTwo( renderTarget.height );
  16339. // Setup framebuffer
  16340. if ( isCube ) {
  16341. renderTargetProperties.__webglFramebuffer = [];
  16342. for ( var i = 0; i < 6; i ++ ) {
  16343. renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer();
  16344. }
  16345. } else {
  16346. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  16347. }
  16348. // Setup color buffer
  16349. if ( isCube ) {
  16350. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__webglTexture );
  16351. setTextureParameters( _gl.TEXTURE_CUBE_MAP, renderTarget.texture, isTargetPowerOfTwo );
  16352. for ( var i = 0; i < 6; i ++ ) {
  16353. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i );
  16354. }
  16355. if ( renderTarget.texture.generateMipmaps && isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  16356. state.bindTexture( _gl.TEXTURE_CUBE_MAP, null );
  16357. } else {
  16358. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  16359. setTextureParameters( _gl.TEXTURE_2D, renderTarget.texture, isTargetPowerOfTwo );
  16360. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_2D );
  16361. if ( renderTarget.texture.generateMipmaps && isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_2D );
  16362. state.bindTexture( _gl.TEXTURE_2D, null );
  16363. }
  16364. // Setup depth and stencil buffers
  16365. if ( renderTarget.depthBuffer ) {
  16366. setupDepthRenderbuffer( renderTarget );
  16367. }
  16368. }
  16369. this.getCurrentRenderTarget = function() {
  16370. return _currentRenderTarget;
  16371. }
  16372. this.setRenderTarget = function ( renderTarget ) {
  16373. _currentRenderTarget = renderTarget;
  16374. if ( renderTarget && properties.get( renderTarget ).__webglFramebuffer === undefined ) {
  16375. setupRenderTarget( renderTarget );
  16376. }
  16377. var isCube = ( renderTarget instanceof THREE.WebGLRenderTargetCube );
  16378. var framebuffer;
  16379. if ( renderTarget ) {
  16380. var renderTargetProperties = properties.get( renderTarget );
  16381. if ( isCube ) {
  16382. framebuffer = renderTargetProperties.__webglFramebuffer[ renderTarget.activeCubeFace ];
  16383. } else {
  16384. framebuffer = renderTargetProperties.__webglFramebuffer;
  16385. }
  16386. _currentScissor.copy( renderTarget.scissor );
  16387. _currentScissorTest = renderTarget.scissorTest;
  16388. _currentViewport.copy( renderTarget.viewport );
  16389. } else {
  16390. framebuffer = null;
  16391. _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio );
  16392. _currentScissorTest = _scissorTest;
  16393. _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio );
  16394. }
  16395. if ( _currentFramebuffer !== framebuffer ) {
  16396. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  16397. _currentFramebuffer = framebuffer;
  16398. }
  16399. state.scissor( _currentScissor );
  16400. state.setScissorTest( _currentScissorTest );
  16401. state.viewport( _currentViewport );
  16402. if ( isCube ) {
  16403. var textureProperties = properties.get( renderTarget.texture );
  16404. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + renderTarget.activeCubeFace, textureProperties.__webglTexture, renderTarget.activeMipMapLevel );
  16405. }
  16406. };
  16407. this.readRenderTargetPixels = function ( renderTarget, x, y, width, height, buffer ) {
  16408. if ( renderTarget instanceof THREE.WebGLRenderTarget === false ) {
  16409. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
  16410. return;
  16411. }
  16412. var framebuffer = properties.get( renderTarget ).__webglFramebuffer;
  16413. if ( framebuffer ) {
  16414. var restore = false;
  16415. if ( framebuffer !== _currentFramebuffer ) {
  16416. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  16417. restore = true;
  16418. }
  16419. try {
  16420. var texture = renderTarget.texture;
  16421. if ( texture.format !== THREE.RGBAFormat
  16422. && paramThreeToGL( texture.format ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_FORMAT ) ) {
  16423. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
  16424. return;
  16425. }
  16426. if ( texture.type !== THREE.UnsignedByteType
  16427. && paramThreeToGL( texture.type ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_TYPE )
  16428. && ! ( texture.type === THREE.FloatType && extensions.get( 'WEBGL_color_buffer_float' ) )
  16429. && ! ( texture.type === THREE.HalfFloatType && extensions.get( 'EXT_color_buffer_half_float' ) ) ) {
  16430. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' );
  16431. return;
  16432. }
  16433. if ( _gl.checkFramebufferStatus( _gl.FRAMEBUFFER ) === _gl.FRAMEBUFFER_COMPLETE ) {
  16434. _gl.readPixels( x, y, width, height, paramThreeToGL( texture.format ), paramThreeToGL( texture.type ), buffer );
  16435. } else {
  16436. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );
  16437. }
  16438. } finally {
  16439. if ( restore ) {
  16440. _gl.bindFramebuffer( _gl.FRAMEBUFFER, _currentFramebuffer );
  16441. }
  16442. }
  16443. }
  16444. };
  16445. function updateRenderTargetMipmap( renderTarget ) {
  16446. var target = renderTarget instanceof THREE.WebGLRenderTargetCube ? _gl.TEXTURE_CUBE_MAP : _gl.TEXTURE_2D;
  16447. var texture = properties.get( renderTarget.texture ).__webglTexture;
  16448. state.bindTexture( target, texture );
  16449. _gl.generateMipmap( target );
  16450. state.bindTexture( target, null );
  16451. }
  16452. // Fallback filters for non-power-of-2 textures
  16453. function filterFallback ( f ) {
  16454. if ( f === THREE.NearestFilter || f === THREE.NearestMipMapNearestFilter || f === THREE.NearestMipMapLinearFilter ) {
  16455. return _gl.NEAREST;
  16456. }
  16457. return _gl.LINEAR;
  16458. }
  16459. // Map three.js constants to WebGL constants
  16460. function paramThreeToGL ( p ) {
  16461. var extension;
  16462. if ( p === THREE.RepeatWrapping ) return _gl.REPEAT;
  16463. if ( p === THREE.ClampToEdgeWrapping ) return _gl.CLAMP_TO_EDGE;
  16464. if ( p === THREE.MirroredRepeatWrapping ) return _gl.MIRRORED_REPEAT;
  16465. if ( p === THREE.NearestFilter ) return _gl.NEAREST;
  16466. if ( p === THREE.NearestMipMapNearestFilter ) return _gl.NEAREST_MIPMAP_NEAREST;
  16467. if ( p === THREE.NearestMipMapLinearFilter ) return _gl.NEAREST_MIPMAP_LINEAR;
  16468. if ( p === THREE.LinearFilter ) return _gl.LINEAR;
  16469. if ( p === THREE.LinearMipMapNearestFilter ) return _gl.LINEAR_MIPMAP_NEAREST;
  16470. if ( p === THREE.LinearMipMapLinearFilter ) return _gl.LINEAR_MIPMAP_LINEAR;
  16471. if ( p === THREE.UnsignedByteType ) return _gl.UNSIGNED_BYTE;
  16472. if ( p === THREE.UnsignedShort4444Type ) return _gl.UNSIGNED_SHORT_4_4_4_4;
  16473. if ( p === THREE.UnsignedShort5551Type ) return _gl.UNSIGNED_SHORT_5_5_5_1;
  16474. if ( p === THREE.UnsignedShort565Type ) return _gl.UNSIGNED_SHORT_5_6_5;
  16475. if ( p === THREE.ByteType ) return _gl.BYTE;
  16476. if ( p === THREE.ShortType ) return _gl.SHORT;
  16477. if ( p === THREE.UnsignedShortType ) return _gl.UNSIGNED_SHORT;
  16478. if ( p === THREE.IntType ) return _gl.INT;
  16479. if ( p === THREE.UnsignedIntType ) return _gl.UNSIGNED_INT;
  16480. if ( p === THREE.FloatType ) return _gl.FLOAT;
  16481. extension = extensions.get( 'OES_texture_half_float' );
  16482. if ( extension !== null ) {
  16483. if ( p === THREE.HalfFloatType ) return extension.HALF_FLOAT_OES;
  16484. }
  16485. if ( p === THREE.AlphaFormat ) return _gl.ALPHA;
  16486. if ( p === THREE.RGBFormat ) return _gl.RGB;
  16487. if ( p === THREE.RGBAFormat ) return _gl.RGBA;
  16488. if ( p === THREE.LuminanceFormat ) return _gl.LUMINANCE;
  16489. if ( p === THREE.LuminanceAlphaFormat ) return _gl.LUMINANCE_ALPHA;
  16490. if ( p === THREE.AddEquation ) return _gl.FUNC_ADD;
  16491. if ( p === THREE.SubtractEquation ) return _gl.FUNC_SUBTRACT;
  16492. if ( p === THREE.ReverseSubtractEquation ) return _gl.FUNC_REVERSE_SUBTRACT;
  16493. if ( p === THREE.ZeroFactor ) return _gl.ZERO;
  16494. if ( p === THREE.OneFactor ) return _gl.ONE;
  16495. if ( p === THREE.SrcColorFactor ) return _gl.SRC_COLOR;
  16496. if ( p === THREE.OneMinusSrcColorFactor ) return _gl.ONE_MINUS_SRC_COLOR;
  16497. if ( p === THREE.SrcAlphaFactor ) return _gl.SRC_ALPHA;
  16498. if ( p === THREE.OneMinusSrcAlphaFactor ) return _gl.ONE_MINUS_SRC_ALPHA;
  16499. if ( p === THREE.DstAlphaFactor ) return _gl.DST_ALPHA;
  16500. if ( p === THREE.OneMinusDstAlphaFactor ) return _gl.ONE_MINUS_DST_ALPHA;
  16501. if ( p === THREE.DstColorFactor ) return _gl.DST_COLOR;
  16502. if ( p === THREE.OneMinusDstColorFactor ) return _gl.ONE_MINUS_DST_COLOR;
  16503. if ( p === THREE.SrcAlphaSaturateFactor ) return _gl.SRC_ALPHA_SATURATE;
  16504. extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );
  16505. if ( extension !== null ) {
  16506. if ( p === THREE.RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  16507. if ( p === THREE.RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  16508. if ( p === THREE.RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  16509. if ( p === THREE.RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  16510. }
  16511. extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  16512. if ( extension !== null ) {
  16513. if ( p === THREE.RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  16514. if ( p === THREE.RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  16515. if ( p === THREE.RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  16516. if ( p === THREE.RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  16517. }
  16518. extension = extensions.get( 'WEBGL_compressed_texture_etc1' );
  16519. if ( extension !== null ) {
  16520. if ( p === THREE.RGB_ETC1_Format ) return extension.COMPRESSED_RGB_ETC1_WEBGL;
  16521. }
  16522. extension = extensions.get( 'EXT_blend_minmax' );
  16523. if ( extension !== null ) {
  16524. if ( p === THREE.MinEquation ) return extension.MIN_EXT;
  16525. if ( p === THREE.MaxEquation ) return extension.MAX_EXT;
  16526. }
  16527. return 0;
  16528. }
  16529. };
  16530. // File:src/renderers/WebGLRenderTarget.js
  16531. /**
  16532. * @author szimek / https://github.com/szimek/
  16533. * @author alteredq / http://alteredqualia.com/
  16534. * @author Marius Kintel / https://github.com/kintel
  16535. */
  16536. /*
  16537. In options, we can specify:
  16538. * Texture parameters for an auto-generated target texture
  16539. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  16540. */
  16541. THREE.WebGLRenderTarget = function ( width, height, options ) {
  16542. this.uuid = THREE.Math.generateUUID();
  16543. this.width = width;
  16544. this.height = height;
  16545. this.scissor = new THREE.Vector4( 0, 0, width, height );
  16546. this.scissorTest = false;
  16547. this.viewport = new THREE.Vector4( 0, 0, width, height );
  16548. options = options || {};
  16549. if ( options.minFilter === undefined ) options.minFilter = THREE.LinearFilter;
  16550. this.texture = new THREE.Texture( undefined, undefined, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy );
  16551. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  16552. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;
  16553. };
  16554. THREE.WebGLRenderTarget.prototype = {
  16555. constructor: THREE.WebGLRenderTarget,
  16556. setSize: function ( width, height ) {
  16557. if ( this.width !== width || this.height !== height ) {
  16558. this.width = width;
  16559. this.height = height;
  16560. this.dispose();
  16561. }
  16562. this.viewport.set( 0, 0, width, height );
  16563. this.scissor.set( 0, 0, width, height );
  16564. },
  16565. clone: function () {
  16566. return new this.constructor().copy( this );
  16567. },
  16568. copy: function ( source ) {
  16569. this.width = source.width;
  16570. this.height = source.height;
  16571. this.viewport.copy( source.viewport );
  16572. this.texture = source.texture.clone();
  16573. this.depthBuffer = source.depthBuffer;
  16574. this.stencilBuffer = source.stencilBuffer;
  16575. return this;
  16576. },
  16577. dispose: function () {
  16578. this.dispatchEvent( { type: 'dispose' } );
  16579. }
  16580. };
  16581. THREE.EventDispatcher.prototype.apply( THREE.WebGLRenderTarget.prototype );
  16582. // File:src/renderers/WebGLRenderTargetCube.js
  16583. /**
  16584. * @author alteredq / http://alteredqualia.com
  16585. */
  16586. THREE.WebGLRenderTargetCube = function ( width, height, options ) {
  16587. THREE.WebGLRenderTarget.call( this, width, height, options );
  16588. this.activeCubeFace = 0; // PX 0, NX 1, PY 2, NY 3, PZ 4, NZ 5
  16589. this.activeMipMapLevel = 0;
  16590. };
  16591. THREE.WebGLRenderTargetCube.prototype = Object.create( THREE.WebGLRenderTarget.prototype );
  16592. THREE.WebGLRenderTargetCube.prototype.constructor = THREE.WebGLRenderTargetCube;
  16593. // File:src/renderers/webgl/WebGLBufferRenderer.js
  16594. /**
  16595. * @author mrdoob / http://mrdoob.com/
  16596. */
  16597. THREE.WebGLBufferRenderer = function ( _gl, extensions, _infoRender ) {
  16598. var mode;
  16599. function setMode( value ) {
  16600. mode = value;
  16601. }
  16602. function render( start, count ) {
  16603. _gl.drawArrays( mode, start, count );
  16604. _infoRender.calls ++;
  16605. _infoRender.vertices += count;
  16606. if ( mode === _gl.TRIANGLES ) _infoRender.faces += count / 3;
  16607. }
  16608. function renderInstances( geometry ) {
  16609. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  16610. if ( extension === null ) {
  16611. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  16612. return;
  16613. }
  16614. var position = geometry.attributes.position;
  16615. var count = 0;
  16616. if ( position instanceof THREE.InterleavedBufferAttribute ) {
  16617. count = position.data.count;
  16618. extension.drawArraysInstancedANGLE( mode, 0, count, geometry.maxInstancedCount );
  16619. } else {
  16620. count = position.count;
  16621. extension.drawArraysInstancedANGLE( mode, 0, count, geometry.maxInstancedCount );
  16622. }
  16623. _infoRender.calls ++;
  16624. _infoRender.vertices += count * geometry.maxInstancedCount;
  16625. if ( mode === _gl.TRIANGLES ) _infoRender.faces += geometry.maxInstancedCount * count / 3;
  16626. }
  16627. this.setMode = setMode;
  16628. this.render = render;
  16629. this.renderInstances = renderInstances;
  16630. };
  16631. // File:src/renderers/webgl/WebGLIndexedBufferRenderer.js
  16632. /**
  16633. * @author mrdoob / http://mrdoob.com/
  16634. */
  16635. THREE.WebGLIndexedBufferRenderer = function ( _gl, extensions, _infoRender ) {
  16636. var mode;
  16637. function setMode( value ) {
  16638. mode = value;
  16639. }
  16640. var type, size;
  16641. function setIndex( index ) {
  16642. if ( index.array instanceof Uint32Array && extensions.get( 'OES_element_index_uint' ) ) {
  16643. type = _gl.UNSIGNED_INT;
  16644. size = 4;
  16645. } else {
  16646. type = _gl.UNSIGNED_SHORT;
  16647. size = 2;
  16648. }
  16649. }
  16650. function render( start, count ) {
  16651. _gl.drawElements( mode, count, type, start * size );
  16652. _infoRender.calls ++;
  16653. _infoRender.vertices += count;
  16654. if ( mode === _gl.TRIANGLES ) _infoRender.faces += count / 3;
  16655. }
  16656. function renderInstances( geometry, start, count ) {
  16657. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  16658. if ( extension === null ) {
  16659. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  16660. return;
  16661. }
  16662. extension.drawElementsInstancedANGLE( mode, count, type, start * size, geometry.maxInstancedCount );
  16663. _infoRender.calls ++;
  16664. _infoRender.vertices += count * geometry.maxInstancedCount;
  16665. if ( mode === _gl.TRIANGLES ) _infoRender.faces += geometry.maxInstancedCount * count / 3;
  16666. }
  16667. this.setMode = setMode;
  16668. this.setIndex = setIndex;
  16669. this.render = render;
  16670. this.renderInstances = renderInstances;
  16671. };
  16672. // File:src/renderers/webgl/WebGLExtensions.js
  16673. /**
  16674. * @author mrdoob / http://mrdoob.com/
  16675. */
  16676. THREE.WebGLExtensions = function ( gl ) {
  16677. var extensions = {};
  16678. this.get = function ( name ) {
  16679. if ( extensions[ name ] !== undefined ) {
  16680. return extensions[ name ];
  16681. }
  16682. var extension;
  16683. switch ( name ) {
  16684. case 'EXT_texture_filter_anisotropic':
  16685. extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' );
  16686. break;
  16687. case 'WEBGL_compressed_texture_s3tc':
  16688. extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' );
  16689. break;
  16690. case 'WEBGL_compressed_texture_pvrtc':
  16691. extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' );
  16692. break;
  16693. case 'WEBGL_compressed_texture_etc1':
  16694. extension = gl.getExtension( 'WEBGL_compressed_texture_etc1' );
  16695. break;
  16696. default:
  16697. extension = gl.getExtension( name );
  16698. }
  16699. if ( extension === null ) {
  16700. console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
  16701. }
  16702. extensions[ name ] = extension;
  16703. return extension;
  16704. };
  16705. };
  16706. // File:src/renderers/webgl/WebGLCapabilities.js
  16707. THREE.WebGLCapabilities = function ( gl, extensions, parameters ) {
  16708. function getMaxPrecision( precision ) {
  16709. if ( precision === 'highp' ) {
  16710. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.HIGH_FLOAT ).precision > 0 &&
  16711. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.HIGH_FLOAT ).precision > 0 ) {
  16712. return 'highp';
  16713. }
  16714. precision = 'mediump';
  16715. }
  16716. if ( precision === 'mediump' ) {
  16717. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.MEDIUM_FLOAT ).precision > 0 &&
  16718. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.MEDIUM_FLOAT ).precision > 0 ) {
  16719. return 'mediump';
  16720. }
  16721. }
  16722. return 'lowp';
  16723. }
  16724. this.getMaxPrecision = getMaxPrecision;
  16725. this.precision = parameters.precision !== undefined ? parameters.precision : 'highp',
  16726. this.logarithmicDepthBuffer = parameters.logarithmicDepthBuffer !== undefined ? parameters.logarithmicDepthBuffer : false;
  16727. this.maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
  16728. this.maxVertexTextures = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS );
  16729. this.maxTextureSize = gl.getParameter( gl.MAX_TEXTURE_SIZE );
  16730. this.maxCubemapSize = gl.getParameter( gl.MAX_CUBE_MAP_TEXTURE_SIZE );
  16731. this.maxAttributes = gl.getParameter( gl.MAX_VERTEX_ATTRIBS );
  16732. this.maxVertexUniforms = gl.getParameter( gl.MAX_VERTEX_UNIFORM_VECTORS );
  16733. this.maxVaryings = gl.getParameter( gl.MAX_VARYING_VECTORS );
  16734. this.maxFragmentUniforms = gl.getParameter( gl.MAX_FRAGMENT_UNIFORM_VECTORS );
  16735. this.vertexTextures = this.maxVertexTextures > 0;
  16736. this.floatFragmentTextures = !! extensions.get( 'OES_texture_float' );
  16737. this.floatVertexTextures = this.vertexTextures && this.floatFragmentTextures;
  16738. var _maxPrecision = getMaxPrecision( this.precision );
  16739. if ( _maxPrecision !== this.precision ) {
  16740. console.warn( 'THREE.WebGLRenderer:', this.precision, 'not supported, using', _maxPrecision, 'instead.' );
  16741. this.precision = _maxPrecision;
  16742. }
  16743. if ( this.logarithmicDepthBuffer ) {
  16744. this.logarithmicDepthBuffer = !! extensions.get( 'EXT_frag_depth' );
  16745. }
  16746. };
  16747. // File:src/renderers/webgl/WebGLGeometries.js
  16748. /**
  16749. * @author mrdoob / http://mrdoob.com/
  16750. */
  16751. THREE.WebGLGeometries = function ( gl, properties, info ) {
  16752. var geometries = {};
  16753. function get( object ) {
  16754. var geometry = object.geometry;
  16755. if ( geometries[ geometry.id ] !== undefined ) {
  16756. return geometries[ geometry.id ];
  16757. }
  16758. geometry.addEventListener( 'dispose', onGeometryDispose );
  16759. var buffergeometry;
  16760. if ( geometry instanceof THREE.BufferGeometry ) {
  16761. buffergeometry = geometry;
  16762. } else if ( geometry instanceof THREE.Geometry ) {
  16763. if ( geometry._bufferGeometry === undefined ) {
  16764. geometry._bufferGeometry = new THREE.BufferGeometry().setFromObject( object );
  16765. }
  16766. buffergeometry = geometry._bufferGeometry;
  16767. }
  16768. geometries[ geometry.id ] = buffergeometry;
  16769. info.memory.geometries ++;
  16770. return buffergeometry;
  16771. }
  16772. function onGeometryDispose( event ) {
  16773. var geometry = event.target;
  16774. var buffergeometry = geometries[ geometry.id ];
  16775. if ( buffergeometry.index !== null ) {
  16776. deleteAttribute( buffergeometry.index );
  16777. }
  16778. deleteAttributes( buffergeometry.attributes );
  16779. geometry.removeEventListener( 'dispose', onGeometryDispose );
  16780. delete geometries[ geometry.id ];
  16781. // TODO
  16782. var property = properties.get( geometry );
  16783. if ( property.wireframe ) {
  16784. deleteAttribute( property.wireframe );
  16785. }
  16786. properties.delete( geometry );
  16787. var bufferproperty = properties.get( buffergeometry );
  16788. if ( bufferproperty.wireframe ) {
  16789. deleteAttribute( bufferproperty.wireframe );
  16790. }
  16791. properties.delete( buffergeometry );
  16792. //
  16793. info.memory.geometries --;
  16794. }
  16795. function getAttributeBuffer( attribute ) {
  16796. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  16797. return properties.get( attribute.data ).__webglBuffer;
  16798. }
  16799. return properties.get( attribute ).__webglBuffer;
  16800. }
  16801. function deleteAttribute( attribute ) {
  16802. var buffer = getAttributeBuffer( attribute );
  16803. if ( buffer !== undefined ) {
  16804. gl.deleteBuffer( buffer );
  16805. removeAttributeBuffer( attribute );
  16806. }
  16807. }
  16808. function deleteAttributes( attributes ) {
  16809. for ( var name in attributes ) {
  16810. deleteAttribute( attributes[ name ] );
  16811. }
  16812. }
  16813. function removeAttributeBuffer( attribute ) {
  16814. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  16815. properties.delete( attribute.data );
  16816. } else {
  16817. properties.delete( attribute );
  16818. }
  16819. }
  16820. this.get = get;
  16821. };
  16822. // File:src/renderers/webgl/WebGLLights.js
  16823. /**
  16824. * @author mrdoob / http://mrdoob.com/
  16825. */
  16826. THREE.WebGLLights = function () {
  16827. var lights = {};
  16828. this.get = function ( light ) {
  16829. if ( lights[ light.id ] !== undefined ) {
  16830. return lights[ light.id ];
  16831. }
  16832. var uniforms;
  16833. switch ( light.type ) {
  16834. case 'DirectionalLight':
  16835. uniforms = {
  16836. direction: new THREE.Vector3(),
  16837. color: new THREE.Color(),
  16838. shadow: false,
  16839. shadowBias: 0,
  16840. shadowRadius: 1,
  16841. shadowMapSize: new THREE.Vector2()
  16842. };
  16843. break;
  16844. case 'SpotLight':
  16845. uniforms = {
  16846. position: new THREE.Vector3(),
  16847. direction: new THREE.Vector3(),
  16848. color: new THREE.Color(),
  16849. distance: 0,
  16850. coneCos: 0,
  16851. penumbraCos: 0,
  16852. decay: 0,
  16853. shadow: false,
  16854. shadowBias: 0,
  16855. shadowRadius: 1,
  16856. shadowMapSize: new THREE.Vector2()
  16857. };
  16858. break;
  16859. case 'PointLight':
  16860. uniforms = {
  16861. position: new THREE.Vector3(),
  16862. color: new THREE.Color(),
  16863. distance: 0,
  16864. decay: 0,
  16865. shadow: false,
  16866. shadowBias: 0,
  16867. shadowRadius: 1,
  16868. shadowMapSize: new THREE.Vector2()
  16869. };
  16870. break;
  16871. case 'HemisphereLight':
  16872. uniforms = {
  16873. direction: new THREE.Vector3(),
  16874. skyColor: new THREE.Color(),
  16875. groundColor: new THREE.Color()
  16876. };
  16877. break;
  16878. }
  16879. lights[ light.id ] = uniforms;
  16880. return uniforms;
  16881. };
  16882. };
  16883. // File:src/renderers/webgl/WebGLObjects.js
  16884. /**
  16885. * @author mrdoob / http://mrdoob.com/
  16886. */
  16887. THREE.WebGLObjects = function ( gl, properties, info ) {
  16888. var geometries = new THREE.WebGLGeometries( gl, properties, info );
  16889. //
  16890. function update( object ) {
  16891. // TODO: Avoid updating twice (when using shadowMap). Maybe add frame counter.
  16892. var geometry = geometries.get( object );
  16893. if ( object.geometry instanceof THREE.Geometry ) {
  16894. geometry.updateFromObject( object );
  16895. }
  16896. var index = geometry.index;
  16897. var attributes = geometry.attributes;
  16898. if ( index !== null ) {
  16899. updateAttribute( index, gl.ELEMENT_ARRAY_BUFFER );
  16900. }
  16901. for ( var name in attributes ) {
  16902. updateAttribute( attributes[ name ], gl.ARRAY_BUFFER );
  16903. }
  16904. // morph targets
  16905. var morphAttributes = geometry.morphAttributes;
  16906. for ( var name in morphAttributes ) {
  16907. var array = morphAttributes[ name ];
  16908. for ( var i = 0, l = array.length; i < l; i ++ ) {
  16909. updateAttribute( array[ i ], gl.ARRAY_BUFFER );
  16910. }
  16911. }
  16912. return geometry;
  16913. }
  16914. function updateAttribute( attribute, bufferType ) {
  16915. var data = ( attribute instanceof THREE.InterleavedBufferAttribute ) ? attribute.data : attribute;
  16916. var attributeProperties = properties.get( data );
  16917. if ( attributeProperties.__webglBuffer === undefined ) {
  16918. createBuffer( attributeProperties, data, bufferType );
  16919. } else if ( attributeProperties.version !== data.version ) {
  16920. updateBuffer( attributeProperties, data, bufferType );
  16921. }
  16922. }
  16923. function createBuffer( attributeProperties, data, bufferType ) {
  16924. attributeProperties.__webglBuffer = gl.createBuffer();
  16925. gl.bindBuffer( bufferType, attributeProperties.__webglBuffer );
  16926. var usage = data.dynamic ? gl.DYNAMIC_DRAW : gl.STATIC_DRAW;
  16927. gl.bufferData( bufferType, data.array, usage );
  16928. attributeProperties.version = data.version;
  16929. }
  16930. function updateBuffer( attributeProperties, data, bufferType ) {
  16931. gl.bindBuffer( bufferType, attributeProperties.__webglBuffer );
  16932. if ( data.dynamic === false || data.updateRange.count === - 1 ) {
  16933. // Not using update ranges
  16934. gl.bufferSubData( bufferType, 0, data.array );
  16935. } else if ( data.updateRange.count === 0 ) {
  16936. 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.' );
  16937. } else {
  16938. gl.bufferSubData( bufferType, data.updateRange.offset * data.array.BYTES_PER_ELEMENT,
  16939. data.array.subarray( data.updateRange.offset, data.updateRange.offset + data.updateRange.count ) );
  16940. data.updateRange.count = 0; // reset range
  16941. }
  16942. attributeProperties.version = data.version;
  16943. }
  16944. function getAttributeBuffer( attribute ) {
  16945. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  16946. return properties.get( attribute.data ).__webglBuffer;
  16947. }
  16948. return properties.get( attribute ).__webglBuffer;
  16949. }
  16950. function getWireframeAttribute( geometry ) {
  16951. var property = properties.get( geometry );
  16952. if ( property.wireframe !== undefined ) {
  16953. return property.wireframe;
  16954. }
  16955. var indices = [];
  16956. var index = geometry.index;
  16957. var attributes = geometry.attributes;
  16958. var position = attributes.position;
  16959. // console.time( 'wireframe' );
  16960. if ( index !== null ) {
  16961. var edges = {};
  16962. var array = index.array;
  16963. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  16964. var a = array[ i + 0 ];
  16965. var b = array[ i + 1 ];
  16966. var c = array[ i + 2 ];
  16967. if ( checkEdge( edges, a, b ) ) indices.push( a, b );
  16968. if ( checkEdge( edges, b, c ) ) indices.push( b, c );
  16969. if ( checkEdge( edges, c, a ) ) indices.push( c, a );
  16970. }
  16971. } else {
  16972. var array = attributes.position.array;
  16973. for ( var i = 0, l = ( array.length / 3 ) - 1; i < l; i += 3 ) {
  16974. var a = i + 0;
  16975. var b = i + 1;
  16976. var c = i + 2;
  16977. indices.push( a, b, b, c, c, a );
  16978. }
  16979. }
  16980. // console.timeEnd( 'wireframe' );
  16981. var TypeArray = position.count > 65535 ? Uint32Array : Uint16Array;
  16982. var attribute = new THREE.BufferAttribute( new TypeArray( indices ), 1 );
  16983. updateAttribute( attribute, gl.ELEMENT_ARRAY_BUFFER );
  16984. property.wireframe = attribute;
  16985. return attribute;
  16986. }
  16987. function checkEdge( edges, a, b ) {
  16988. if ( a > b ) {
  16989. var tmp = a;
  16990. a = b;
  16991. b = tmp;
  16992. }
  16993. var list = edges[ a ];
  16994. if ( list === undefined ) {
  16995. edges[ a ] = [ b ];
  16996. return true;
  16997. } else if ( list.indexOf( b ) === -1 ) {
  16998. list.push( b );
  16999. return true;
  17000. }
  17001. return false;
  17002. }
  17003. this.getAttributeBuffer = getAttributeBuffer;
  17004. this.getWireframeAttribute = getWireframeAttribute;
  17005. this.update = update;
  17006. };
  17007. // File:src/renderers/webgl/WebGLProgram.js
  17008. THREE.WebGLProgram = ( function () {
  17009. var programIdCount = 0;
  17010. // TODO: Combine the regex
  17011. var structRe = /^([\w\d_]+)\.([\w\d_]+)$/;
  17012. var arrayStructRe = /^([\w\d_]+)\[(\d+)\]\.([\w\d_]+)$/;
  17013. var arrayRe = /^([\w\d_]+)\[0\]$/;
  17014. function getEncodingComponents( encoding ) {
  17015. switch ( encoding ) {
  17016. case THREE.LinearEncoding:
  17017. return [ 'Linear','( value )' ];
  17018. case THREE.sRGBEncoding:
  17019. return [ 'sRGB','( value )' ];
  17020. case THREE.RGBEEncoding:
  17021. return [ 'RGBE','( value )' ];
  17022. case THREE.RGBM7Encoding:
  17023. return [ 'RGBM','( value, 7.0 )' ];
  17024. case THREE.RGBM16Encoding:
  17025. return [ 'RGBM','( value, 16.0 )' ];
  17026. case THREE.RGBDEncoding:
  17027. return [ 'RGBD','( value, 256.0 )' ];
  17028. case THREE.GammaEncoding:
  17029. return [ 'Gamma','( value, float( GAMMA_FACTOR ) )' ];
  17030. default:
  17031. throw new Error( 'unsupported encoding: ' + encoding );
  17032. }
  17033. }
  17034. function getTexelDecodingFunction( functionName, encoding ) {
  17035. var components = getEncodingComponents( encoding );
  17036. return "vec4 " + functionName + "( vec4 value ) { return " + components[ 0 ] + "ToLinear" + components[ 1 ] + "; }";
  17037. }
  17038. function getTexelEncodingFunction( functionName, encoding ) {
  17039. var components = getEncodingComponents( encoding );
  17040. return "vec4 " + functionName + "( vec4 value ) { return LinearTo" + components[ 0 ] + components[ 1 ] + "; }";
  17041. }
  17042. function getToneMappingFunction( functionName, toneMapping ) {
  17043. var toneMappingName;
  17044. switch ( toneMapping ) {
  17045. case THREE.LinearToneMapping:
  17046. toneMappingName = "Linear";
  17047. break;
  17048. case THREE.ReinhardToneMapping:
  17049. toneMappingName = "Reinhard";
  17050. break;
  17051. case THREE.Uncharted2ToneMapping:
  17052. toneMappingName = "Uncharted2";
  17053. break;
  17054. case THREE.CineonToneMapping:
  17055. toneMappingName = "OptimizedCineon";
  17056. break;
  17057. default:
  17058. throw new Error( 'unsupported toneMapping: ' + toneMapping );
  17059. }
  17060. return "vec3 " + functionName + "( vec3 color ) { return " + toneMappingName + "ToneMapping( color ); }";
  17061. }
  17062. function generateExtensions( extensions, parameters, rendererExtensions ) {
  17063. extensions = extensions || {};
  17064. var chunks = [
  17065. ( extensions.derivatives || parameters.envMapCubeUV || parameters.bumpMap || parameters.normalMap || parameters.flatShading ) ? '#extension GL_OES_standard_derivatives : enable' : '',
  17066. ( extensions.fragDepth || parameters.logarithmicDepthBuffer ) && rendererExtensions.get( 'EXT_frag_depth' ) ? '#extension GL_EXT_frag_depth : enable' : '',
  17067. ( extensions.drawBuffers ) && rendererExtensions.get( 'WEBGL_draw_buffers' ) ? '#extension GL_EXT_draw_buffers : require' : '',
  17068. ( extensions.shaderTextureLOD || parameters.envMap ) && rendererExtensions.get( 'EXT_shader_texture_lod' ) ? '#extension GL_EXT_shader_texture_lod : enable' : '',
  17069. ];
  17070. return chunks.filter( filterEmptyLine ).join( '\n' );
  17071. }
  17072. function generateDefines( defines ) {
  17073. var chunks = [];
  17074. for ( var name in defines ) {
  17075. var value = defines[ name ];
  17076. if ( value === false ) continue;
  17077. chunks.push( '#define ' + name + ' ' + value );
  17078. }
  17079. return chunks.join( '\n' );
  17080. }
  17081. function fetchUniformLocations( gl, program, identifiers ) {
  17082. var uniforms = {};
  17083. var n = gl.getProgramParameter( program, gl.ACTIVE_UNIFORMS );
  17084. for ( var i = 0; i < n; i ++ ) {
  17085. var info = gl.getActiveUniform( program, i );
  17086. var name = info.name;
  17087. var location = gl.getUniformLocation( program, name );
  17088. //console.log("THREE.WebGLProgram: ACTIVE UNIFORM:", name);
  17089. var matches = structRe.exec( name );
  17090. if ( matches ) {
  17091. var structName = matches[ 1 ];
  17092. var structProperty = matches[ 2 ];
  17093. var uniformsStruct = uniforms[ structName ];
  17094. if ( ! uniformsStruct ) {
  17095. uniformsStruct = uniforms[ structName ] = {};
  17096. }
  17097. uniformsStruct[ structProperty ] = location;
  17098. continue;
  17099. }
  17100. matches = arrayStructRe.exec( name );
  17101. if ( matches ) {
  17102. var arrayName = matches[ 1 ];
  17103. var arrayIndex = matches[ 2 ];
  17104. var arrayProperty = matches[ 3 ];
  17105. var uniformsArray = uniforms[ arrayName ];
  17106. if ( ! uniformsArray ) {
  17107. uniformsArray = uniforms[ arrayName ] = [];
  17108. }
  17109. var uniformsArrayIndex = uniformsArray[ arrayIndex ];
  17110. if ( ! uniformsArrayIndex ) {
  17111. uniformsArrayIndex = uniformsArray[ arrayIndex ] = {};
  17112. }
  17113. uniformsArrayIndex[ arrayProperty ] = location;
  17114. continue;
  17115. }
  17116. matches = arrayRe.exec( name );
  17117. if ( matches ) {
  17118. var arrayName = matches[ 1 ];
  17119. uniforms[ arrayName ] = location;
  17120. continue;
  17121. }
  17122. uniforms[ name ] = location;
  17123. }
  17124. return uniforms;
  17125. }
  17126. function fetchAttributeLocations( gl, program, identifiers ) {
  17127. var attributes = {};
  17128. var n = gl.getProgramParameter( program, gl.ACTIVE_ATTRIBUTES );
  17129. for ( var i = 0; i < n; i ++ ) {
  17130. var info = gl.getActiveAttrib( program, i );
  17131. var name = info.name;
  17132. // console.log("THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:", name, i );
  17133. attributes[ name ] = gl.getAttribLocation( program, name );
  17134. }
  17135. return attributes;
  17136. }
  17137. function filterEmptyLine( string ) {
  17138. return string !== '';
  17139. }
  17140. function replaceLightNums( string, parameters ) {
  17141. return string
  17142. .replace( /NUM_DIR_LIGHTS/g, parameters.numDirLights )
  17143. .replace( /NUM_SPOT_LIGHTS/g, parameters.numSpotLights )
  17144. .replace( /NUM_POINT_LIGHTS/g, parameters.numPointLights )
  17145. .replace( /NUM_HEMI_LIGHTS/g, parameters.numHemiLights );
  17146. }
  17147. function parseIncludes( string ) {
  17148. var pattern = /#include +<([\w\d.]+)>/g;
  17149. function replace( match, include ) {
  17150. var replace = THREE.ShaderChunk[ include ];
  17151. if ( replace === undefined ) {
  17152. throw new Error( 'Can not resolve #include <' + include + '>' );
  17153. }
  17154. return parseIncludes( replace );
  17155. }
  17156. return string.replace( pattern, replace );
  17157. }
  17158. function unrollLoops( string ) {
  17159. var pattern = /for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  17160. function replace( match, start, end, snippet ) {
  17161. var unroll = '';
  17162. for ( var i = parseInt( start ); i < parseInt( end ); i ++ ) {
  17163. unroll += snippet.replace( /\[ i \]/g, '[ ' + i + ' ]' );
  17164. }
  17165. return unroll;
  17166. }
  17167. return string.replace( pattern, replace );
  17168. }
  17169. return function WebGLProgram( renderer, code, material, parameters ) {
  17170. var gl = renderer.context;
  17171. var extensions = material.extensions;
  17172. var defines = material.defines;
  17173. var vertexShader = material.__webglShader.vertexShader;
  17174. var fragmentShader = material.__webglShader.fragmentShader;
  17175. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  17176. if ( parameters.shadowMapType === THREE.PCFShadowMap ) {
  17177. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  17178. } else if ( parameters.shadowMapType === THREE.PCFSoftShadowMap ) {
  17179. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  17180. }
  17181. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  17182. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  17183. var envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  17184. if ( parameters.envMap ) {
  17185. switch ( material.envMap.mapping ) {
  17186. case THREE.CubeReflectionMapping:
  17187. case THREE.CubeRefractionMapping:
  17188. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  17189. break;
  17190. case THREE.CubeUVReflectionMapping:
  17191. case THREE.CubeUVRefractionMapping:
  17192. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  17193. break;
  17194. case THREE.EquirectangularReflectionMapping:
  17195. case THREE.EquirectangularRefractionMapping:
  17196. envMapTypeDefine = 'ENVMAP_TYPE_EQUIREC';
  17197. break;
  17198. case THREE.SphericalReflectionMapping:
  17199. envMapTypeDefine = 'ENVMAP_TYPE_SPHERE';
  17200. break;
  17201. }
  17202. switch ( material.envMap.mapping ) {
  17203. case THREE.CubeRefractionMapping:
  17204. case THREE.EquirectangularRefractionMapping:
  17205. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  17206. break;
  17207. }
  17208. switch ( material.combine ) {
  17209. case THREE.MultiplyOperation:
  17210. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  17211. break;
  17212. case THREE.MixOperation:
  17213. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  17214. break;
  17215. case THREE.AddOperation:
  17216. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  17217. break;
  17218. }
  17219. }
  17220. var gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
  17221. // console.log( 'building new program ' );
  17222. //
  17223. var customExtensions = generateExtensions( extensions, parameters, renderer.extensions );
  17224. var customDefines = generateDefines( defines );
  17225. //
  17226. var program = gl.createProgram();
  17227. var prefixVertex, prefixFragment;
  17228. if ( material instanceof THREE.RawShaderMaterial ) {
  17229. prefixVertex = '';
  17230. prefixFragment = '';
  17231. } else {
  17232. prefixVertex = [
  17233. 'precision ' + parameters.precision + ' float;',
  17234. 'precision ' + parameters.precision + ' int;',
  17235. '#define SHADER_NAME ' + material.__webglShader.name,
  17236. customDefines,
  17237. parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '',
  17238. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  17239. '#define MAX_BONES ' + parameters.maxBones,
  17240. parameters.map ? '#define USE_MAP' : '',
  17241. parameters.envMap ? '#define USE_ENVMAP' : '',
  17242. parameters.envMap ? '#define ' + envMapModeDefine : '',
  17243. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  17244. parameters.aoMap ? '#define USE_AOMAP' : '',
  17245. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  17246. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  17247. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  17248. parameters.displacementMap && parameters.supportsVertexTextures ? '#define USE_DISPLACEMENTMAP' : '',
  17249. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  17250. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  17251. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  17252. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  17253. parameters.vertexColors ? '#define USE_COLOR' : '',
  17254. parameters.flatShading ? '#define FLAT_SHADED' : '',
  17255. parameters.skinning ? '#define USE_SKINNING' : '',
  17256. parameters.useVertexTexture ? '#define BONE_TEXTURE' : '',
  17257. parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
  17258. parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '',
  17259. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  17260. parameters.flipSided ? '#define FLIP_SIDED' : '',
  17261. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  17262. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  17263. parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
  17264. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  17265. parameters.logarithmicDepthBuffer && renderer.extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  17266. 'uniform mat4 modelMatrix;',
  17267. 'uniform mat4 modelViewMatrix;',
  17268. 'uniform mat4 projectionMatrix;',
  17269. 'uniform mat4 viewMatrix;',
  17270. 'uniform mat3 normalMatrix;',
  17271. 'uniform vec3 cameraPosition;',
  17272. 'attribute vec3 position;',
  17273. 'attribute vec3 normal;',
  17274. 'attribute vec2 uv;',
  17275. '#ifdef USE_COLOR',
  17276. ' attribute vec3 color;',
  17277. '#endif',
  17278. '#ifdef USE_MORPHTARGETS',
  17279. ' attribute vec3 morphTarget0;',
  17280. ' attribute vec3 morphTarget1;',
  17281. ' attribute vec3 morphTarget2;',
  17282. ' attribute vec3 morphTarget3;',
  17283. ' #ifdef USE_MORPHNORMALS',
  17284. ' attribute vec3 morphNormal0;',
  17285. ' attribute vec3 morphNormal1;',
  17286. ' attribute vec3 morphNormal2;',
  17287. ' attribute vec3 morphNormal3;',
  17288. ' #else',
  17289. ' attribute vec3 morphTarget4;',
  17290. ' attribute vec3 morphTarget5;',
  17291. ' attribute vec3 morphTarget6;',
  17292. ' attribute vec3 morphTarget7;',
  17293. ' #endif',
  17294. '#endif',
  17295. '#ifdef USE_SKINNING',
  17296. ' attribute vec4 skinIndex;',
  17297. ' attribute vec4 skinWeight;',
  17298. '#endif',
  17299. '\n'
  17300. ].filter( filterEmptyLine ).join( '\n' );
  17301. prefixFragment = [
  17302. customExtensions,
  17303. 'precision ' + parameters.precision + ' float;',
  17304. 'precision ' + parameters.precision + ' int;',
  17305. '#define SHADER_NAME ' + material.__webglShader.name,
  17306. customDefines,
  17307. parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest : '',
  17308. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  17309. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  17310. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  17311. parameters.map ? '#define USE_MAP' : '',
  17312. parameters.envMap ? '#define USE_ENVMAP' : '',
  17313. parameters.envMap ? '#define ' + envMapTypeDefine : '',
  17314. parameters.envMap ? '#define ' + envMapModeDefine : '',
  17315. parameters.envMap ? '#define ' + envMapBlendingDefine : '',
  17316. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  17317. parameters.aoMap ? '#define USE_AOMAP' : '',
  17318. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  17319. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  17320. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  17321. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  17322. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  17323. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  17324. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  17325. parameters.vertexColors ? '#define USE_COLOR' : '',
  17326. parameters.flatShading ? '#define FLAT_SHADED' : '',
  17327. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  17328. parameters.flipSided ? '#define FLIP_SIDED' : '',
  17329. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  17330. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  17331. parameters.premultipliedAlpha ? "#define PREMULTIPLIED_ALPHA" : '',
  17332. parameters.physicallyCorrectLights ? "#define PHYSICALLY_CORRECT_LIGHTS" : '',
  17333. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  17334. parameters.logarithmicDepthBuffer && renderer.extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  17335. parameters.envMap && renderer.extensions.get( 'EXT_shader_texture_lod' ) ? '#define TEXTURE_LOD_EXT' : '',
  17336. 'uniform mat4 viewMatrix;',
  17337. 'uniform vec3 cameraPosition;',
  17338. ( parameters.toneMapping !== THREE.NoToneMapping ) ? "#define TONE_MAPPING" : '',
  17339. ( parameters.toneMapping !== THREE.NoToneMapping ) ? THREE.ShaderChunk[ 'tonemapping_pars_fragment' ] : '', // this code is required here because it is used by the toneMapping() function defined below
  17340. ( parameters.toneMapping !== THREE.NoToneMapping ) ? getToneMappingFunction( "toneMapping", parameters.toneMapping ) : '',
  17341. ( 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
  17342. parameters.mapEncoding ? getTexelDecodingFunction( 'mapTexelToLinear', parameters.mapEncoding ) : '',
  17343. parameters.envMapEncoding ? getTexelDecodingFunction( 'envMapTexelToLinear', parameters.envMapEncoding ) : '',
  17344. parameters.emissiveMapEncoding ? getTexelDecodingFunction( 'emissiveMapTexelToLinear', parameters.emissiveMapEncoding ) : '',
  17345. parameters.outputEncoding ? getTexelEncodingFunction( "linearToOutputTexel", parameters.outputEncoding ) : '',
  17346. '\n'
  17347. ].filter( filterEmptyLine ).join( '\n' );
  17348. }
  17349. vertexShader = parseIncludes( vertexShader, parameters );
  17350. vertexShader = replaceLightNums( vertexShader, parameters );
  17351. fragmentShader = parseIncludes( fragmentShader, parameters );
  17352. fragmentShader = replaceLightNums( fragmentShader, parameters );
  17353. if ( material instanceof THREE.ShaderMaterial === false ) {
  17354. vertexShader = unrollLoops( vertexShader );
  17355. fragmentShader = unrollLoops( fragmentShader );
  17356. }
  17357. var vertexGlsl = prefixVertex + vertexShader;
  17358. var fragmentGlsl = prefixFragment + fragmentShader;
  17359. // console.log( '*VERTEX*', vertexGlsl );
  17360. // console.log( '*FRAGMENT*', fragmentGlsl );
  17361. var glVertexShader = THREE.WebGLShader( gl, gl.VERTEX_SHADER, vertexGlsl );
  17362. var glFragmentShader = THREE.WebGLShader( gl, gl.FRAGMENT_SHADER, fragmentGlsl );
  17363. gl.attachShader( program, glVertexShader );
  17364. gl.attachShader( program, glFragmentShader );
  17365. // Force a particular attribute to index 0.
  17366. if ( material.index0AttributeName !== undefined ) {
  17367. gl.bindAttribLocation( program, 0, material.index0AttributeName );
  17368. } else if ( parameters.morphTargets === true ) {
  17369. // programs with morphTargets displace position out of attribute 0
  17370. gl.bindAttribLocation( program, 0, 'position' );
  17371. }
  17372. gl.linkProgram( program );
  17373. var programLog = gl.getProgramInfoLog( program );
  17374. var vertexLog = gl.getShaderInfoLog( glVertexShader );
  17375. var fragmentLog = gl.getShaderInfoLog( glFragmentShader );
  17376. var runnable = true;
  17377. var haveDiagnostics = true;
  17378. // console.log( '**VERTEX**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( glVertexShader ) );
  17379. // console.log( '**FRAGMENT**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( glFragmentShader ) );
  17380. if ( gl.getProgramParameter( program, gl.LINK_STATUS ) === false ) {
  17381. runnable = false;
  17382. console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), 'gl.VALIDATE_STATUS', gl.getProgramParameter( program, gl.VALIDATE_STATUS ), 'gl.getProgramInfoLog', programLog, vertexLog, fragmentLog );
  17383. } else if ( programLog !== '' ) {
  17384. console.warn( 'THREE.WebGLProgram: gl.getProgramInfoLog()', programLog );
  17385. } else if ( vertexLog === '' || fragmentLog === '' ) {
  17386. haveDiagnostics = false;
  17387. }
  17388. if ( haveDiagnostics ) {
  17389. this.diagnostics = {
  17390. runnable: runnable,
  17391. material: material,
  17392. programLog: programLog,
  17393. vertexShader: {
  17394. log: vertexLog,
  17395. prefix: prefixVertex
  17396. },
  17397. fragmentShader: {
  17398. log: fragmentLog,
  17399. prefix: prefixFragment
  17400. }
  17401. };
  17402. }
  17403. // clean up
  17404. gl.deleteShader( glVertexShader );
  17405. gl.deleteShader( glFragmentShader );
  17406. // set up caching for uniform locations
  17407. var cachedUniforms;
  17408. this.getUniforms = function() {
  17409. if ( cachedUniforms === undefined ) {
  17410. cachedUniforms = fetchUniformLocations( gl, program );
  17411. }
  17412. return cachedUniforms;
  17413. };
  17414. // set up caching for attribute locations
  17415. var cachedAttributes;
  17416. this.getAttributes = function() {
  17417. if ( cachedAttributes === undefined ) {
  17418. cachedAttributes = fetchAttributeLocations( gl, program );
  17419. }
  17420. return cachedAttributes;
  17421. };
  17422. // free resource
  17423. this.destroy = function() {
  17424. gl.deleteProgram( program );
  17425. this.program = undefined;
  17426. };
  17427. // DEPRECATED
  17428. Object.defineProperties( this, {
  17429. uniforms: {
  17430. get: function() {
  17431. console.warn( 'THREE.WebGLProgram: .uniforms is now .getUniforms().' );
  17432. return this.getUniforms();
  17433. }
  17434. },
  17435. attributes: {
  17436. get: function() {
  17437. console.warn( 'THREE.WebGLProgram: .attributes is now .getAttributes().' );
  17438. return this.getAttributes();
  17439. }
  17440. }
  17441. } );
  17442. //
  17443. this.id = programIdCount ++;
  17444. this.code = code;
  17445. this.usedTimes = 1;
  17446. this.program = program;
  17447. this.vertexShader = glVertexShader;
  17448. this.fragmentShader = glFragmentShader;
  17449. return this;
  17450. };
  17451. } )();
  17452. // File:src/renderers/webgl/WebGLPrograms.js
  17453. THREE.WebGLPrograms = function ( renderer, capabilities ) {
  17454. var programs = [];
  17455. var shaderIDs = {
  17456. MeshDepthMaterial: 'depth',
  17457. MeshNormalMaterial: 'normal',
  17458. MeshBasicMaterial: 'basic',
  17459. MeshLambertMaterial: 'lambert',
  17460. MeshPhongMaterial: 'phong',
  17461. MeshStandardMaterial: 'standard',
  17462. LineBasicMaterial: 'basic',
  17463. LineDashedMaterial: 'dashed',
  17464. PointsMaterial: 'points'
  17465. };
  17466. var parameterNames = [
  17467. "precision", "supportsVertexTextures", "map", "mapEncoding", "envMap", "envMapMode", "envMapEncoding",
  17468. "lightMap", "aoMap", "emissiveMap", "emissiveMapEncoding", "bumpMap", "normalMap", "displacementMap", "specularMap",
  17469. "roughnessMap", "metalnessMap",
  17470. "alphaMap", "combine", "vertexColors", "fog", "useFog", "fogExp",
  17471. "flatShading", "sizeAttenuation", "logarithmicDepthBuffer", "skinning",
  17472. "maxBones", "useVertexTexture", "morphTargets", "morphNormals",
  17473. "maxMorphTargets", "maxMorphNormals", "premultipliedAlpha",
  17474. "numDirLights", "numPointLights", "numSpotLights", "numHemiLights",
  17475. "shadowMapEnabled", "shadowMapType", "toneMapping", 'physicallyCorrectLights',
  17476. "alphaTest", "doubleSided", "flipSided"
  17477. ];
  17478. function allocateBones ( object ) {
  17479. if ( capabilities.floatVertexTextures && object && object.skeleton && object.skeleton.useVertexTexture ) {
  17480. return 1024;
  17481. } else {
  17482. // default for when object is not specified
  17483. // ( for example when prebuilding shader to be used with multiple objects )
  17484. //
  17485. // - leave some extra space for other uniforms
  17486. // - limit here is ANGLE's 254 max uniform vectors
  17487. // (up to 54 should be safe)
  17488. var nVertexUniforms = capabilities.maxVertexUniforms;
  17489. var nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 );
  17490. var maxBones = nVertexMatrices;
  17491. if ( object !== undefined && object instanceof THREE.SkinnedMesh ) {
  17492. maxBones = Math.min( object.skeleton.bones.length, maxBones );
  17493. if ( maxBones < object.skeleton.bones.length ) {
  17494. console.warn( 'WebGLRenderer: too many bones - ' + object.skeleton.bones.length + ', this GPU supports just ' + maxBones + ' (try OpenGL instead of ANGLE)' );
  17495. }
  17496. }
  17497. return maxBones;
  17498. }
  17499. }
  17500. function getTextureEncodingFromMap( map, gammaOverrideLinear ) {
  17501. var encoding;
  17502. if ( ! map ) {
  17503. encoding = THREE.LinearEncoding;
  17504. } else if ( map instanceof THREE.Texture ) {
  17505. encoding = map.encoding;
  17506. } else if ( map instanceof THREE.WebGLRenderTarget ) {
  17507. encoding = map.texture.encoding;
  17508. }
  17509. // add backwards compatibility for WebGLRenderer.gammaInput/gammaOutput parameter, should probably be removed at some point.
  17510. if ( encoding === THREE.LinearEncoding && gammaOverrideLinear ) {
  17511. encoding = THREE.GammaEncoding;
  17512. }
  17513. return encoding;
  17514. }
  17515. this.getParameters = function ( material, lights, fog, object ) {
  17516. var shaderID = shaderIDs[ material.type ];
  17517. // heuristics to create shader parameters according to lights in the scene
  17518. // (not to blow over maxLights budget)
  17519. var maxBones = allocateBones( object );
  17520. var precision = renderer.getPrecision();
  17521. if ( material.precision !== null ) {
  17522. precision = capabilities.getMaxPrecision( material.precision );
  17523. if ( precision !== material.precision ) {
  17524. console.warn( 'THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.' );
  17525. }
  17526. }
  17527. var parameters = {
  17528. shaderID: shaderID,
  17529. precision: precision,
  17530. supportsVertexTextures: capabilities.vertexTextures,
  17531. outputEncoding: getTextureEncodingFromMap( renderer.getCurrentRenderTarget(), renderer.gammaOutput ),
  17532. map: !! material.map,
  17533. mapEncoding: getTextureEncodingFromMap( material.map, renderer.gammaInput ),
  17534. envMap: !! material.envMap,
  17535. envMapMode: material.envMap && material.envMap.mapping,
  17536. envMapEncoding: getTextureEncodingFromMap( material.envMap, renderer.gammaInput ),
  17537. envMapCubeUV: ( !! material.envMap ) && ( ( material.envMap.mapping === THREE.CubeUVReflectionMapping ) || ( material.envMap.mapping === THREE.CubeUVRefractionMapping ) ),
  17538. lightMap: !! material.lightMap,
  17539. aoMap: !! material.aoMap,
  17540. emissiveMap: !! material.emissiveMap,
  17541. emissiveMapEncoding: getTextureEncodingFromMap( material.emissiveMap, renderer.gammaInput ),
  17542. bumpMap: !! material.bumpMap,
  17543. normalMap: !! material.normalMap,
  17544. displacementMap: !! material.displacementMap,
  17545. roughnessMap: !! material.roughnessMap,
  17546. metalnessMap: !! material.metalnessMap,
  17547. specularMap: !! material.specularMap,
  17548. alphaMap: !! material.alphaMap,
  17549. combine: material.combine,
  17550. vertexColors: material.vertexColors,
  17551. fog: fog,
  17552. useFog: material.fog,
  17553. fogExp: fog instanceof THREE.FogExp2,
  17554. flatShading: material.shading === THREE.FlatShading,
  17555. sizeAttenuation: material.sizeAttenuation,
  17556. logarithmicDepthBuffer: capabilities.logarithmicDepthBuffer,
  17557. skinning: material.skinning,
  17558. maxBones: maxBones,
  17559. useVertexTexture: capabilities.floatVertexTextures && object && object.skeleton && object.skeleton.useVertexTexture,
  17560. morphTargets: material.morphTargets,
  17561. morphNormals: material.morphNormals,
  17562. maxMorphTargets: renderer.maxMorphTargets,
  17563. maxMorphNormals: renderer.maxMorphNormals,
  17564. numDirLights: lights.directional.length,
  17565. numPointLights: lights.point.length,
  17566. numSpotLights: lights.spot.length,
  17567. numHemiLights: lights.hemi.length,
  17568. shadowMapEnabled: renderer.shadowMap.enabled && object.receiveShadow && lights.shadows.length > 0,
  17569. shadowMapType: renderer.shadowMap.type,
  17570. toneMapping: renderer.toneMapping,
  17571. physicallyCorrectLights: renderer.physicallyCorrectLights,
  17572. premultipliedAlpha: material.premultipliedAlpha,
  17573. alphaTest: material.alphaTest,
  17574. doubleSided: material.side === THREE.DoubleSide,
  17575. flipSided: material.side === THREE.BackSide
  17576. };
  17577. return parameters;
  17578. };
  17579. this.getProgramCode = function ( material, parameters ) {
  17580. var array = [];
  17581. if ( parameters.shaderID ) {
  17582. array.push( parameters.shaderID );
  17583. } else {
  17584. array.push( material.fragmentShader );
  17585. array.push( material.vertexShader );
  17586. }
  17587. if ( material.defines !== undefined ) {
  17588. for ( var name in material.defines ) {
  17589. array.push( name );
  17590. array.push( material.defines[ name ] );
  17591. }
  17592. }
  17593. for ( var i = 0; i < parameterNames.length; i ++ ) {
  17594. array.push( parameters[ parameterNames[ i ] ] );
  17595. }
  17596. return array.join();
  17597. };
  17598. this.acquireProgram = function ( material, parameters, code ) {
  17599. var program;
  17600. // Check if code has been already compiled
  17601. for ( var p = 0, pl = programs.length; p < pl; p ++ ) {
  17602. var programInfo = programs[ p ];
  17603. if ( programInfo.code === code ) {
  17604. program = programInfo;
  17605. ++ program.usedTimes;
  17606. break;
  17607. }
  17608. }
  17609. if ( program === undefined ) {
  17610. program = new THREE.WebGLProgram( renderer, code, material, parameters );
  17611. programs.push( program );
  17612. }
  17613. return program;
  17614. };
  17615. this.releaseProgram = function( program ) {
  17616. if ( -- program.usedTimes === 0 ) {
  17617. // Remove from unordered set
  17618. var i = programs.indexOf( program );
  17619. programs[ i ] = programs[ programs.length - 1 ];
  17620. programs.pop();
  17621. // Free WebGL resources
  17622. program.destroy();
  17623. }
  17624. };
  17625. // Exposed for resource monitoring & error feedback via renderer.info:
  17626. this.programs = programs;
  17627. };
  17628. // File:src/renderers/webgl/WebGLProperties.js
  17629. /**
  17630. * @author fordacious / fordacious.github.io
  17631. */
  17632. THREE.WebGLProperties = function () {
  17633. var properties = {};
  17634. this.get = function ( object ) {
  17635. var uuid = object.uuid;
  17636. var map = properties[ uuid ];
  17637. if ( map === undefined ) {
  17638. map = {};
  17639. properties[ uuid ] = map;
  17640. }
  17641. return map;
  17642. };
  17643. this.delete = function ( object ) {
  17644. delete properties[ object.uuid ];
  17645. };
  17646. this.clear = function () {
  17647. properties = {};
  17648. };
  17649. };
  17650. // File:src/renderers/webgl/WebGLShader.js
  17651. THREE.WebGLShader = ( function () {
  17652. function addLineNumbers( string ) {
  17653. var lines = string.split( '\n' );
  17654. for ( var i = 0; i < lines.length; i ++ ) {
  17655. lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
  17656. }
  17657. return lines.join( '\n' );
  17658. }
  17659. return function WebGLShader( gl, type, string ) {
  17660. var shader = gl.createShader( type );
  17661. gl.shaderSource( shader, string );
  17662. gl.compileShader( shader );
  17663. if ( gl.getShaderParameter( shader, gl.COMPILE_STATUS ) === false ) {
  17664. console.error( 'THREE.WebGLShader: Shader couldn\'t compile.' );
  17665. }
  17666. if ( gl.getShaderInfoLog( shader ) !== '' ) {
  17667. console.warn( 'THREE.WebGLShader: gl.getShaderInfoLog()', type === gl.VERTEX_SHADER ? 'vertex' : 'fragment', gl.getShaderInfoLog( shader ), addLineNumbers( string ) );
  17668. }
  17669. // --enable-privileged-webgl-extension
  17670. // console.log( type, gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  17671. return shader;
  17672. };
  17673. } )();
  17674. // File:src/renderers/webgl/WebGLShadowMap.js
  17675. /**
  17676. * @author alteredq / http://alteredqualia.com/
  17677. * @author mrdoob / http://mrdoob.com/
  17678. */
  17679. THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
  17680. var _gl = _renderer.context,
  17681. _state = _renderer.state,
  17682. _frustum = new THREE.Frustum(),
  17683. _projScreenMatrix = new THREE.Matrix4(),
  17684. _lightShadows = _lights.shadows,
  17685. _shadowMapSize = new THREE.Vector2(),
  17686. _lookTarget = new THREE.Vector3(),
  17687. _lightPositionWorld = new THREE.Vector3(),
  17688. _renderList = [],
  17689. _MorphingFlag = 1,
  17690. _SkinningFlag = 2,
  17691. _NumberOfMaterialVariants = ( _MorphingFlag | _SkinningFlag ) + 1,
  17692. _depthMaterials = new Array( _NumberOfMaterialVariants ),
  17693. _distanceMaterials = new Array( _NumberOfMaterialVariants );
  17694. var cubeDirections = [
  17695. new THREE.Vector3( 1, 0, 0 ), new THREE.Vector3( - 1, 0, 0 ), new THREE.Vector3( 0, 0, 1 ),
  17696. new THREE.Vector3( 0, 0, - 1 ), new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, - 1, 0 )
  17697. ];
  17698. var cubeUps = [
  17699. new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 1, 0 ),
  17700. new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 0, 1 ), new THREE.Vector3( 0, 0, - 1 )
  17701. ];
  17702. var cube2DViewPorts = [
  17703. new THREE.Vector4(), new THREE.Vector4(), new THREE.Vector4(),
  17704. new THREE.Vector4(), new THREE.Vector4(), new THREE.Vector4()
  17705. ];
  17706. // init
  17707. var depthShader = THREE.ShaderLib[ "depthRGBA" ];
  17708. var depthUniforms = THREE.UniformsUtils.clone( depthShader.uniforms );
  17709. var distanceShader = THREE.ShaderLib[ "distanceRGBA" ];
  17710. var distanceUniforms = THREE.UniformsUtils.clone( distanceShader.uniforms );
  17711. for ( var i = 0; i !== _NumberOfMaterialVariants; ++ i ) {
  17712. var useMorphing = ( i & _MorphingFlag ) !== 0;
  17713. var useSkinning = ( i & _SkinningFlag ) !== 0;
  17714. var depthMaterial = new THREE.ShaderMaterial( {
  17715. uniforms: depthUniforms,
  17716. vertexShader: depthShader.vertexShader,
  17717. fragmentShader: depthShader.fragmentShader,
  17718. morphTargets: useMorphing,
  17719. skinning: useSkinning
  17720. } );
  17721. _depthMaterials[ i ] = depthMaterial;
  17722. var distanceMaterial = new THREE.ShaderMaterial( {
  17723. defines: {
  17724. 'USE_SHADOWMAP': ''
  17725. },
  17726. uniforms: distanceUniforms,
  17727. vertexShader: distanceShader.vertexShader,
  17728. fragmentShader: distanceShader.fragmentShader,
  17729. morphTargets: useMorphing,
  17730. skinning: useSkinning
  17731. } );
  17732. _distanceMaterials[ i ] = distanceMaterial;
  17733. }
  17734. //
  17735. var scope = this;
  17736. this.enabled = false;
  17737. this.autoUpdate = true;
  17738. this.needsUpdate = false;
  17739. this.type = THREE.PCFShadowMap;
  17740. this.cullFace = THREE.CullFaceFront;
  17741. this.render = function ( scene, camera ) {
  17742. if ( scope.enabled === false ) return;
  17743. if ( scope.autoUpdate === false && scope.needsUpdate === false ) return;
  17744. if ( _lightShadows.length === 0 ) return;
  17745. // Set GL state for depth map.
  17746. _state.clearColor( 1, 1, 1, 1 );
  17747. _state.disable( _gl.BLEND );
  17748. _state.enable( _gl.CULL_FACE );
  17749. _gl.frontFace( _gl.CCW );
  17750. _gl.cullFace( scope.cullFace === THREE.CullFaceFront ? _gl.FRONT : _gl.BACK );
  17751. _state.setDepthTest( true );
  17752. _state.setScissorTest( false );
  17753. // render depth map
  17754. var faceCount, isPointLight;
  17755. for ( var i = 0, il = _lightShadows.length; i < il; i ++ ) {
  17756. var light = _lightShadows[ i ];
  17757. var shadow = light.shadow;
  17758. var shadowCamera = shadow.camera;
  17759. _shadowMapSize.copy( shadow.mapSize );
  17760. if ( light instanceof THREE.PointLight ) {
  17761. faceCount = 6;
  17762. isPointLight = true;
  17763. var vpWidth = _shadowMapSize.x;
  17764. var vpHeight = _shadowMapSize.y;
  17765. // These viewports map a cube-map onto a 2D texture with the
  17766. // following orientation:
  17767. //
  17768. // xzXZ
  17769. // y Y
  17770. //
  17771. // X - Positive x direction
  17772. // x - Negative x direction
  17773. // Y - Positive y direction
  17774. // y - Negative y direction
  17775. // Z - Positive z direction
  17776. // z - Negative z direction
  17777. // positive X
  17778. cube2DViewPorts[ 0 ].set( vpWidth * 2, vpHeight, vpWidth, vpHeight );
  17779. // negative X
  17780. cube2DViewPorts[ 1 ].set( 0, vpHeight, vpWidth, vpHeight );
  17781. // positive Z
  17782. cube2DViewPorts[ 2 ].set( vpWidth * 3, vpHeight, vpWidth, vpHeight );
  17783. // negative Z
  17784. cube2DViewPorts[ 3 ].set( vpWidth, vpHeight, vpWidth, vpHeight );
  17785. // positive Y
  17786. cube2DViewPorts[ 4 ].set( vpWidth * 3, 0, vpWidth, vpHeight );
  17787. // negative Y
  17788. cube2DViewPorts[ 5 ].set( vpWidth, 0, vpWidth, vpHeight );
  17789. _shadowMapSize.x *= 4.0;
  17790. _shadowMapSize.y *= 2.0;
  17791. } else {
  17792. faceCount = 1;
  17793. isPointLight = false;
  17794. }
  17795. if ( shadow.map === null ) {
  17796. var pars = { minFilter: THREE.NearestFilter, magFilter: THREE.NearestFilter, format: THREE.RGBAFormat };
  17797. shadow.map = new THREE.WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
  17798. shadowCamera.updateProjectionMatrix();
  17799. }
  17800. if ( shadow instanceof THREE.SpotLightShadow ) {
  17801. shadow.update( light );
  17802. }
  17803. var shadowMap = shadow.map;
  17804. var shadowMatrix = shadow.matrix;
  17805. _lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  17806. shadowCamera.position.copy( _lightPositionWorld );
  17807. _renderer.setRenderTarget( shadowMap );
  17808. _renderer.clear();
  17809. // render shadow map for each cube face (if omni-directional) or
  17810. // run a single pass if not
  17811. for ( var face = 0; face < faceCount; face ++ ) {
  17812. if ( isPointLight ) {
  17813. _lookTarget.copy( shadowCamera.position );
  17814. _lookTarget.add( cubeDirections[ face ] );
  17815. shadowCamera.up.copy( cubeUps[ face ] );
  17816. shadowCamera.lookAt( _lookTarget );
  17817. var vpDimensions = cube2DViewPorts[ face ];
  17818. _state.viewport( vpDimensions );
  17819. } else {
  17820. _lookTarget.setFromMatrixPosition( light.target.matrixWorld );
  17821. shadowCamera.lookAt( _lookTarget );
  17822. }
  17823. shadowCamera.updateMatrixWorld();
  17824. shadowCamera.matrixWorldInverse.getInverse( shadowCamera.matrixWorld );
  17825. // compute shadow matrix
  17826. shadowMatrix.set(
  17827. 0.5, 0.0, 0.0, 0.5,
  17828. 0.0, 0.5, 0.0, 0.5,
  17829. 0.0, 0.0, 0.5, 0.5,
  17830. 0.0, 0.0, 0.0, 1.0
  17831. );
  17832. shadowMatrix.multiply( shadowCamera.projectionMatrix );
  17833. shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
  17834. // update camera matrices and frustum
  17835. _projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  17836. _frustum.setFromMatrix( _projScreenMatrix );
  17837. // set object matrices & frustum culling
  17838. _renderList.length = 0;
  17839. projectObject( scene, camera, shadowCamera );
  17840. // render shadow map
  17841. // render regular objects
  17842. for ( var j = 0, jl = _renderList.length; j < jl; j ++ ) {
  17843. var object = _renderList[ j ];
  17844. var geometry = _objects.update( object );
  17845. var material = object.material;
  17846. if ( material instanceof THREE.MultiMaterial ) {
  17847. var groups = geometry.groups;
  17848. var materials = material.materials;
  17849. for ( var k = 0, kl = groups.length; k < kl; k ++ ) {
  17850. var group = groups[ k ];
  17851. var groupMaterial = materials[ group.materialIndex ];
  17852. if ( groupMaterial.visible === true ) {
  17853. var depthMaterial = getDepthMaterial( object, groupMaterial, isPointLight, _lightPositionWorld );
  17854. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, group );
  17855. }
  17856. }
  17857. } else {
  17858. var depthMaterial = getDepthMaterial( object, material, isPointLight, _lightPositionWorld );
  17859. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, null );
  17860. }
  17861. }
  17862. }
  17863. }
  17864. // Restore GL state.
  17865. var clearColor = _renderer.getClearColor(),
  17866. clearAlpha = _renderer.getClearAlpha();
  17867. _renderer.setClearColor( clearColor, clearAlpha );
  17868. _state.enable( _gl.BLEND );
  17869. if ( scope.cullFace === THREE.CullFaceFront ) {
  17870. _gl.cullFace( _gl.BACK );
  17871. }
  17872. scope.needsUpdate = false;
  17873. };
  17874. function getDepthMaterial( object, material, isPointLight, lightPositionWorld ) {
  17875. var geometry = object.geometry;
  17876. var newMaterial = null;
  17877. var materialVariants = _depthMaterials;
  17878. var customMaterial = object.customDepthMaterial;
  17879. if ( isPointLight ) {
  17880. materialVariants = _distanceMaterials;
  17881. customMaterial = object.customDistanceMaterial;
  17882. }
  17883. if ( ! customMaterial ) {
  17884. var useMorphing = geometry.morphTargets !== undefined &&
  17885. geometry.morphTargets.length > 0 && material.morphTargets;
  17886. var useSkinning = object instanceof THREE.SkinnedMesh && material.skinning;
  17887. var variantIndex = 0;
  17888. if ( useMorphing ) variantIndex |= _MorphingFlag;
  17889. if ( useSkinning ) variantIndex |= _SkinningFlag;
  17890. newMaterial = materialVariants[ variantIndex ];
  17891. } else {
  17892. newMaterial = customMaterial;
  17893. }
  17894. newMaterial.visible = material.visible;
  17895. newMaterial.wireframe = material.wireframe;
  17896. newMaterial.wireframeLinewidth = material.wireframeLinewidth;
  17897. if ( isPointLight && newMaterial.uniforms.lightPos !== undefined ) {
  17898. newMaterial.uniforms.lightPos.value.copy( lightPositionWorld );
  17899. }
  17900. return newMaterial;
  17901. }
  17902. function projectObject( object, camera, shadowCamera ) {
  17903. if ( object.visible === false ) return;
  17904. if ( object.layers.test( camera.layers ) && ( object instanceof THREE.Mesh || object instanceof THREE.Line || object instanceof THREE.Points ) ) {
  17905. if ( object.castShadow && ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) ) {
  17906. var material = object.material;
  17907. if ( material.visible === true ) {
  17908. object.modelViewMatrix.multiplyMatrices( shadowCamera.matrixWorldInverse, object.matrixWorld );
  17909. _renderList.push( object );
  17910. }
  17911. }
  17912. }
  17913. var children = object.children;
  17914. for ( var i = 0, l = children.length; i < l; i ++ ) {
  17915. projectObject( children[ i ], camera, shadowCamera );
  17916. }
  17917. }
  17918. };
  17919. // File:src/renderers/webgl/WebGLState.js
  17920. /**
  17921. * @author mrdoob / http://mrdoob.com/
  17922. */
  17923. THREE.WebGLState = function ( gl, extensions, paramThreeToGL ) {
  17924. var _this = this;
  17925. var color = new THREE.Vector4();
  17926. var newAttributes = new Uint8Array( 16 );
  17927. var enabledAttributes = new Uint8Array( 16 );
  17928. var attributeDivisors = new Uint8Array( 16 );
  17929. var capabilities = {};
  17930. var compressedTextureFormats = null;
  17931. var currentBlending = null;
  17932. var currentBlendEquation = null;
  17933. var currentBlendSrc = null;
  17934. var currentBlendDst = null;
  17935. var currentBlendEquationAlpha = null;
  17936. var currentBlendSrcAlpha = null;
  17937. var currentBlendDstAlpha = null;
  17938. var currentPremultipledAlpha = false;
  17939. var currentDepthFunc = null;
  17940. var currentDepthWrite = null;
  17941. var currentColorWrite = null;
  17942. var currentStencilWrite = null;
  17943. var currentStencilFunc = null;
  17944. var currentStencilRef = null;
  17945. var currentStencilMask = null;
  17946. var currentStencilFail = null;
  17947. var currentStencilZFail = null;
  17948. var currentStencilZPass = null;
  17949. var currentFlipSided = null;
  17950. var currentLineWidth = null;
  17951. var currentPolygonOffsetFactor = null;
  17952. var currentPolygonOffsetUnits = null;
  17953. var currentScissorTest = null;
  17954. var maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
  17955. var currentTextureSlot = undefined;
  17956. var currentBoundTextures = {};
  17957. var currentClearColor = new THREE.Vector4();
  17958. var currentClearDepth = null;
  17959. var currentClearStencil = null;
  17960. var currentScissor = new THREE.Vector4();
  17961. var currentViewport = new THREE.Vector4();
  17962. var emptyTexture = gl.createTexture();
  17963. gl.bindTexture( gl.TEXTURE_2D, emptyTexture );
  17964. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR );
  17965. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGB, 1, 1, 0, gl.RGB, gl.UNSIGNED_BYTE, new Uint8Array( 3 ) );
  17966. this.init = function () {
  17967. this.clearColor( 0, 0, 0, 1 );
  17968. this.clearDepth( 1 );
  17969. this.clearStencil( 0 );
  17970. this.enable( gl.DEPTH_TEST );
  17971. gl.depthFunc( gl.LEQUAL );
  17972. gl.frontFace( gl.CCW );
  17973. gl.cullFace( gl.BACK );
  17974. this.enable( gl.CULL_FACE );
  17975. this.enable( gl.BLEND );
  17976. gl.blendEquation( gl.FUNC_ADD );
  17977. gl.blendFunc( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA );
  17978. };
  17979. this.initAttributes = function () {
  17980. for ( var i = 0, l = newAttributes.length; i < l; i ++ ) {
  17981. newAttributes[ i ] = 0;
  17982. }
  17983. };
  17984. this.enableAttribute = function ( attribute ) {
  17985. newAttributes[ attribute ] = 1;
  17986. if ( enabledAttributes[ attribute ] === 0 ) {
  17987. gl.enableVertexAttribArray( attribute );
  17988. enabledAttributes[ attribute ] = 1;
  17989. }
  17990. if ( attributeDivisors[ attribute ] !== 0 ) {
  17991. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  17992. extension.vertexAttribDivisorANGLE( attribute, 0 );
  17993. attributeDivisors[ attribute ] = 0;
  17994. }
  17995. };
  17996. this.enableAttributeAndDivisor = function ( attribute, meshPerAttribute, extension ) {
  17997. newAttributes[ attribute ] = 1;
  17998. if ( enabledAttributes[ attribute ] === 0 ) {
  17999. gl.enableVertexAttribArray( attribute );
  18000. enabledAttributes[ attribute ] = 1;
  18001. }
  18002. if ( attributeDivisors[ attribute ] !== meshPerAttribute ) {
  18003. extension.vertexAttribDivisorANGLE( attribute, meshPerAttribute );
  18004. attributeDivisors[ attribute ] = meshPerAttribute;
  18005. }
  18006. };
  18007. this.disableUnusedAttributes = function () {
  18008. for ( var i = 0, l = enabledAttributes.length; i < l; i ++ ) {
  18009. if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
  18010. gl.disableVertexAttribArray( i );
  18011. enabledAttributes[ i ] = 0;
  18012. }
  18013. }
  18014. };
  18015. this.enable = function ( id ) {
  18016. if ( capabilities[ id ] !== true ) {
  18017. gl.enable( id );
  18018. capabilities[ id ] = true;
  18019. }
  18020. };
  18021. this.disable = function ( id ) {
  18022. if ( capabilities[ id ] !== false ) {
  18023. gl.disable( id );
  18024. capabilities[ id ] = false;
  18025. }
  18026. };
  18027. this.getCompressedTextureFormats = function () {
  18028. if ( compressedTextureFormats === null ) {
  18029. compressedTextureFormats = [];
  18030. if ( extensions.get( 'WEBGL_compressed_texture_pvrtc' ) ||
  18031. extensions.get( 'WEBGL_compressed_texture_s3tc' ) ||
  18032. extensions.get( 'WEBGL_compressed_texture_etc1' ) ) {
  18033. var formats = gl.getParameter( gl.COMPRESSED_TEXTURE_FORMATS );
  18034. for ( var i = 0; i < formats.length; i ++ ) {
  18035. compressedTextureFormats.push( formats[ i ] );
  18036. }
  18037. }
  18038. }
  18039. return compressedTextureFormats;
  18040. };
  18041. this.setBlending = function ( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha ) {
  18042. if ( blending === THREE.NoBlending ) {
  18043. this.disable( gl.BLEND );
  18044. } else {
  18045. this.enable( gl.BLEND );
  18046. }
  18047. if ( blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha ) {
  18048. if ( blending === THREE.AdditiveBlending ) {
  18049. if ( premultipliedAlpha ) {
  18050. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  18051. gl.blendFuncSeparate( gl.ONE, gl.ONE, gl.ONE, gl.ONE );
  18052. } else {
  18053. gl.blendEquation( gl.FUNC_ADD );
  18054. gl.blendFunc( gl.SRC_ALPHA, gl.ONE );
  18055. }
  18056. } else if ( blending === THREE.SubtractiveBlending ) {
  18057. if ( premultipliedAlpha ) {
  18058. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  18059. gl.blendFuncSeparate( gl.ZERO, gl.ZERO, gl.ONE_MINUS_SRC_COLOR, gl.ONE_MINUS_SRC_ALPHA );
  18060. } else {
  18061. gl.blendEquation( gl.FUNC_ADD );
  18062. gl.blendFunc( gl.ZERO, gl.ONE_MINUS_SRC_COLOR );
  18063. }
  18064. } else if ( blending === THREE.MultiplyBlending ) {
  18065. if ( premultipliedAlpha ) {
  18066. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  18067. gl.blendFuncSeparate( gl.ZERO, gl.ZERO, gl.SRC_COLOR, gl.SRC_ALPHA );
  18068. } else {
  18069. gl.blendEquation( gl.FUNC_ADD );
  18070. gl.blendFunc( gl.ZERO, gl.SRC_COLOR );
  18071. }
  18072. } else {
  18073. if ( premultipliedAlpha ) {
  18074. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  18075. gl.blendFuncSeparate( gl.ONE, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
  18076. } else {
  18077. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  18078. gl.blendFuncSeparate( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
  18079. }
  18080. }
  18081. currentBlending = blending;
  18082. currentPremultipledAlpha = premultipliedAlpha;
  18083. }
  18084. if ( blending === THREE.CustomBlending ) {
  18085. blendEquationAlpha = blendEquationAlpha || blendEquation;
  18086. blendSrcAlpha = blendSrcAlpha || blendSrc;
  18087. blendDstAlpha = blendDstAlpha || blendDst;
  18088. if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
  18089. gl.blendEquationSeparate( paramThreeToGL( blendEquation ), paramThreeToGL( blendEquationAlpha ) );
  18090. currentBlendEquation = blendEquation;
  18091. currentBlendEquationAlpha = blendEquationAlpha;
  18092. }
  18093. if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
  18094. gl.blendFuncSeparate( paramThreeToGL( blendSrc ), paramThreeToGL( blendDst ), paramThreeToGL( blendSrcAlpha ), paramThreeToGL( blendDstAlpha ) );
  18095. currentBlendSrc = blendSrc;
  18096. currentBlendDst = blendDst;
  18097. currentBlendSrcAlpha = blendSrcAlpha;
  18098. currentBlendDstAlpha = blendDstAlpha;
  18099. }
  18100. } else {
  18101. currentBlendEquation = null;
  18102. currentBlendSrc = null;
  18103. currentBlendDst = null;
  18104. currentBlendEquationAlpha = null;
  18105. currentBlendSrcAlpha = null;
  18106. currentBlendDstAlpha = null;
  18107. }
  18108. };
  18109. this.setDepthFunc = function ( depthFunc ) {
  18110. if ( currentDepthFunc !== depthFunc ) {
  18111. if ( depthFunc ) {
  18112. switch ( depthFunc ) {
  18113. case THREE.NeverDepth:
  18114. gl.depthFunc( gl.NEVER );
  18115. break;
  18116. case THREE.AlwaysDepth:
  18117. gl.depthFunc( gl.ALWAYS );
  18118. break;
  18119. case THREE.LessDepth:
  18120. gl.depthFunc( gl.LESS );
  18121. break;
  18122. case THREE.LessEqualDepth:
  18123. gl.depthFunc( gl.LEQUAL );
  18124. break;
  18125. case THREE.EqualDepth:
  18126. gl.depthFunc( gl.EQUAL );
  18127. break;
  18128. case THREE.GreaterEqualDepth:
  18129. gl.depthFunc( gl.GEQUAL );
  18130. break;
  18131. case THREE.GreaterDepth:
  18132. gl.depthFunc( gl.GREATER );
  18133. break;
  18134. case THREE.NotEqualDepth:
  18135. gl.depthFunc( gl.NOTEQUAL );
  18136. break;
  18137. default:
  18138. gl.depthFunc( gl.LEQUAL );
  18139. }
  18140. } else {
  18141. gl.depthFunc( gl.LEQUAL );
  18142. }
  18143. currentDepthFunc = depthFunc;
  18144. }
  18145. };
  18146. this.setDepthTest = function ( depthTest ) {
  18147. if ( depthTest ) {
  18148. this.enable( gl.DEPTH_TEST );
  18149. } else {
  18150. this.disable( gl.DEPTH_TEST );
  18151. }
  18152. };
  18153. this.setDepthWrite = function ( depthWrite ) {
  18154. // TODO: Rename to setDepthMask
  18155. if ( currentDepthWrite !== depthWrite ) {
  18156. gl.depthMask( depthWrite );
  18157. currentDepthWrite = depthWrite;
  18158. }
  18159. };
  18160. this.setColorWrite = function ( colorWrite ) {
  18161. // TODO: Rename to setColorMask
  18162. if ( currentColorWrite !== colorWrite ) {
  18163. gl.colorMask( colorWrite, colorWrite, colorWrite, colorWrite );
  18164. currentColorWrite = colorWrite;
  18165. }
  18166. };
  18167. this.setStencilFunc = function ( stencilFunc, stencilRef, stencilMask ) {
  18168. if ( currentStencilFunc !== stencilFunc ||
  18169. currentStencilRef !== stencilRef ||
  18170. currentStencilMask !== stencilMask ) {
  18171. gl.stencilFunc( stencilFunc, stencilRef, stencilMask );
  18172. currentStencilFunc = stencilFunc;
  18173. currentStencilRef = stencilRef;
  18174. currentStencilMask = stencilMask;
  18175. }
  18176. };
  18177. this.setStencilOp = function ( stencilFail, stencilZFail, stencilZPass ) {
  18178. if ( currentStencilFail !== stencilFail ||
  18179. currentStencilZFail !== stencilZFail ||
  18180. currentStencilZPass !== stencilZPass ) {
  18181. gl.stencilOp( stencilFail, stencilZFail, stencilZPass );
  18182. currentStencilFail = stencilFail;
  18183. currentStencilZFail = stencilZFail;
  18184. currentStencilZPass = stencilZPass;
  18185. }
  18186. };
  18187. this.setStencilTest = function ( stencilTest ) {
  18188. if ( stencilTest ) {
  18189. this.enable( gl.STENCIL_TEST );
  18190. } else {
  18191. this.disable( gl.STENCIL_TEST );
  18192. }
  18193. };
  18194. this.setStencilWrite = function ( stencilWrite ) {
  18195. // TODO: Rename to setStencilMask
  18196. if ( currentStencilWrite !== stencilWrite ) {
  18197. gl.stencilMask( stencilWrite );
  18198. currentStencilWrite = stencilWrite;
  18199. }
  18200. };
  18201. this.setFlipSided = function ( flipSided ) {
  18202. if ( currentFlipSided !== flipSided ) {
  18203. if ( flipSided ) {
  18204. gl.frontFace( gl.CW );
  18205. } else {
  18206. gl.frontFace( gl.CCW );
  18207. }
  18208. currentFlipSided = flipSided;
  18209. }
  18210. };
  18211. this.setLineWidth = function ( width ) {
  18212. if ( width !== currentLineWidth ) {
  18213. gl.lineWidth( width );
  18214. currentLineWidth = width;
  18215. }
  18216. };
  18217. this.setPolygonOffset = function ( polygonOffset, factor, units ) {
  18218. if ( polygonOffset ) {
  18219. this.enable( gl.POLYGON_OFFSET_FILL );
  18220. } else {
  18221. this.disable( gl.POLYGON_OFFSET_FILL );
  18222. }
  18223. if ( polygonOffset && ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) ) {
  18224. gl.polygonOffset( factor, units );
  18225. currentPolygonOffsetFactor = factor;
  18226. currentPolygonOffsetUnits = units;
  18227. }
  18228. };
  18229. this.getScissorTest = function () {
  18230. return currentScissorTest;
  18231. };
  18232. this.setScissorTest = function ( scissorTest ) {
  18233. currentScissorTest = scissorTest;
  18234. if ( scissorTest ) {
  18235. this.enable( gl.SCISSOR_TEST );
  18236. } else {
  18237. this.disable( gl.SCISSOR_TEST );
  18238. }
  18239. };
  18240. // texture
  18241. this.activeTexture = function ( webglSlot ) {
  18242. if ( webglSlot === undefined ) webglSlot = gl.TEXTURE0 + maxTextures - 1;
  18243. if ( currentTextureSlot !== webglSlot ) {
  18244. gl.activeTexture( webglSlot );
  18245. currentTextureSlot = webglSlot;
  18246. }
  18247. };
  18248. this.bindTexture = function ( webglType, webglTexture ) {
  18249. if ( currentTextureSlot === undefined ) {
  18250. _this.activeTexture();
  18251. }
  18252. var boundTexture = currentBoundTextures[ currentTextureSlot ];
  18253. if ( boundTexture === undefined ) {
  18254. boundTexture = { type: undefined, texture: undefined };
  18255. currentBoundTextures[ currentTextureSlot ] = boundTexture;
  18256. }
  18257. if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
  18258. gl.bindTexture( webglType, webglTexture || emptyTexture );
  18259. boundTexture.type = webglType;
  18260. boundTexture.texture = webglTexture;
  18261. }
  18262. };
  18263. this.compressedTexImage2D = function () {
  18264. try {
  18265. gl.compressedTexImage2D.apply( gl, arguments );
  18266. } catch ( error ) {
  18267. console.error( error );
  18268. }
  18269. };
  18270. this.texImage2D = function () {
  18271. try {
  18272. gl.texImage2D.apply( gl, arguments );
  18273. } catch ( error ) {
  18274. console.error( error );
  18275. }
  18276. };
  18277. // clear values
  18278. this.clearColor = function ( r, g, b, a ) {
  18279. color.set( r, g, b, a );
  18280. if ( currentClearColor.equals( color ) === false ) {
  18281. gl.clearColor( r, g, b, a );
  18282. currentClearColor.copy( color );
  18283. }
  18284. };
  18285. this.clearDepth = function ( depth ) {
  18286. if ( currentClearDepth !== depth ) {
  18287. gl.clearDepth( depth );
  18288. currentClearDepth = depth;
  18289. }
  18290. };
  18291. this.clearStencil = function ( stencil ) {
  18292. if ( currentClearStencil !== stencil ) {
  18293. gl.clearStencil( stencil );
  18294. currentClearStencil = stencil;
  18295. }
  18296. };
  18297. //
  18298. this.scissor = function ( scissor ) {
  18299. if ( currentScissor.equals( scissor ) === false ) {
  18300. gl.scissor( scissor.x, scissor.y, scissor.z, scissor.w );
  18301. currentScissor.copy( scissor );
  18302. }
  18303. };
  18304. this.viewport = function ( viewport ) {
  18305. if ( currentViewport.equals( viewport ) === false ) {
  18306. gl.viewport( viewport.x, viewport.y, viewport.z, viewport.w );
  18307. currentViewport.copy( viewport );
  18308. }
  18309. };
  18310. //
  18311. this.reset = function () {
  18312. for ( var i = 0; i < enabledAttributes.length; i ++ ) {
  18313. if ( enabledAttributes[ i ] === 1 ) {
  18314. gl.disableVertexAttribArray( i );
  18315. enabledAttributes[ i ] = 0;
  18316. }
  18317. }
  18318. capabilities = {};
  18319. compressedTextureFormats = null;
  18320. currentTextureSlot = undefined;
  18321. currentBoundTextures = {};
  18322. currentBlending = null;
  18323. currentColorWrite = null;
  18324. currentDepthWrite = null;
  18325. currentStencilWrite = null;
  18326. currentFlipSided = null;
  18327. };
  18328. };
  18329. // File:src/renderers/webgl/plugins/LensFlarePlugin.js
  18330. /**
  18331. * @author mikael emtinger / http://gomo.se/
  18332. * @author alteredq / http://alteredqualia.com/
  18333. */
  18334. THREE.LensFlarePlugin = function ( renderer, flares ) {
  18335. var gl = renderer.context;
  18336. var state = renderer.state;
  18337. var vertexBuffer, elementBuffer;
  18338. var shader, program, attributes, uniforms;
  18339. var tempTexture, occlusionTexture;
  18340. function init() {
  18341. var vertices = new Float32Array( [
  18342. - 1, - 1, 0, 0,
  18343. 1, - 1, 1, 0,
  18344. 1, 1, 1, 1,
  18345. - 1, 1, 0, 1
  18346. ] );
  18347. var faces = new Uint16Array( [
  18348. 0, 1, 2,
  18349. 0, 2, 3
  18350. ] );
  18351. // buffers
  18352. vertexBuffer = gl.createBuffer();
  18353. elementBuffer = gl.createBuffer();
  18354. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  18355. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  18356. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  18357. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  18358. // textures
  18359. tempTexture = gl.createTexture();
  18360. occlusionTexture = gl.createTexture();
  18361. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  18362. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGB, 16, 16, 0, gl.RGB, gl.UNSIGNED_BYTE, null );
  18363. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  18364. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  18365. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  18366. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  18367. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  18368. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGBA, 16, 16, 0, gl.RGBA, gl.UNSIGNED_BYTE, null );
  18369. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  18370. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  18371. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  18372. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  18373. shader = {
  18374. vertexShader: [
  18375. "uniform lowp int renderType;",
  18376. "uniform vec3 screenPosition;",
  18377. "uniform vec2 scale;",
  18378. "uniform float rotation;",
  18379. "uniform sampler2D occlusionMap;",
  18380. "attribute vec2 position;",
  18381. "attribute vec2 uv;",
  18382. "varying vec2 vUV;",
  18383. "varying float vVisibility;",
  18384. "void main() {",
  18385. "vUV = uv;",
  18386. "vec2 pos = position;",
  18387. "if ( renderType == 2 ) {",
  18388. "vec4 visibility = texture2D( occlusionMap, vec2( 0.1, 0.1 ) );",
  18389. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.1 ) );",
  18390. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.1 ) );",
  18391. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) );",
  18392. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.9 ) );",
  18393. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) );",
  18394. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.9 ) );",
  18395. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) );",
  18396. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.5 ) );",
  18397. "vVisibility = visibility.r / 9.0;",
  18398. "vVisibility *= 1.0 - visibility.g / 9.0;",
  18399. "vVisibility *= visibility.b / 9.0;",
  18400. "vVisibility *= 1.0 - visibility.a / 9.0;",
  18401. "pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
  18402. "pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
  18403. "}",
  18404. "gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
  18405. "}"
  18406. ].join( "\n" ),
  18407. fragmentShader: [
  18408. "uniform lowp int renderType;",
  18409. "uniform sampler2D map;",
  18410. "uniform float opacity;",
  18411. "uniform vec3 color;",
  18412. "varying vec2 vUV;",
  18413. "varying float vVisibility;",
  18414. "void main() {",
  18415. // pink square
  18416. "if ( renderType == 0 ) {",
  18417. "gl_FragColor = vec4( 1.0, 0.0, 1.0, 0.0 );",
  18418. // restore
  18419. "} else if ( renderType == 1 ) {",
  18420. "gl_FragColor = texture2D( map, vUV );",
  18421. // flare
  18422. "} else {",
  18423. "vec4 texture = texture2D( map, vUV );",
  18424. "texture.a *= opacity * vVisibility;",
  18425. "gl_FragColor = texture;",
  18426. "gl_FragColor.rgb *= color;",
  18427. "}",
  18428. "}"
  18429. ].join( "\n" )
  18430. };
  18431. program = createProgram( shader );
  18432. attributes = {
  18433. vertex: gl.getAttribLocation ( program, "position" ),
  18434. uv: gl.getAttribLocation ( program, "uv" )
  18435. };
  18436. uniforms = {
  18437. renderType: gl.getUniformLocation( program, "renderType" ),
  18438. map: gl.getUniformLocation( program, "map" ),
  18439. occlusionMap: gl.getUniformLocation( program, "occlusionMap" ),
  18440. opacity: gl.getUniformLocation( program, "opacity" ),
  18441. color: gl.getUniformLocation( program, "color" ),
  18442. scale: gl.getUniformLocation( program, "scale" ),
  18443. rotation: gl.getUniformLocation( program, "rotation" ),
  18444. screenPosition: gl.getUniformLocation( program, "screenPosition" )
  18445. };
  18446. }
  18447. /*
  18448. * Render lens flares
  18449. * Method: renders 16x16 0xff00ff-colored points scattered over the light source area,
  18450. * reads these back and calculates occlusion.
  18451. */
  18452. this.render = function ( scene, camera, viewport ) {
  18453. if ( flares.length === 0 ) return;
  18454. var tempPosition = new THREE.Vector3();
  18455. var invAspect = viewport.w / viewport.z,
  18456. halfViewportWidth = viewport.z * 0.5,
  18457. halfViewportHeight = viewport.w * 0.5;
  18458. var size = 16 / viewport.w,
  18459. scale = new THREE.Vector2( size * invAspect, size );
  18460. var screenPosition = new THREE.Vector3( 1, 1, 0 ),
  18461. screenPositionPixels = new THREE.Vector2( 1, 1 );
  18462. var validArea = new THREE.Box2();
  18463. validArea.min.set( 0, 0 );
  18464. validArea.max.set( viewport.z - 16, viewport.w - 16 );
  18465. if ( program === undefined ) {
  18466. init();
  18467. }
  18468. gl.useProgram( program );
  18469. state.initAttributes();
  18470. state.enableAttribute( attributes.vertex );
  18471. state.enableAttribute( attributes.uv );
  18472. state.disableUnusedAttributes();
  18473. // loop through all lens flares to update their occlusion and positions
  18474. // setup gl and common used attribs/uniforms
  18475. gl.uniform1i( uniforms.occlusionMap, 0 );
  18476. gl.uniform1i( uniforms.map, 1 );
  18477. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  18478. gl.vertexAttribPointer( attributes.vertex, 2, gl.FLOAT, false, 2 * 8, 0 );
  18479. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  18480. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  18481. state.disable( gl.CULL_FACE );
  18482. state.setDepthWrite( false );
  18483. for ( var i = 0, l = flares.length; i < l; i ++ ) {
  18484. size = 16 / viewport.w;
  18485. scale.set( size * invAspect, size );
  18486. // calc object screen position
  18487. var flare = flares[ i ];
  18488. tempPosition.set( flare.matrixWorld.elements[ 12 ], flare.matrixWorld.elements[ 13 ], flare.matrixWorld.elements[ 14 ] );
  18489. tempPosition.applyMatrix4( camera.matrixWorldInverse );
  18490. tempPosition.applyProjection( camera.projectionMatrix );
  18491. // setup arrays for gl programs
  18492. screenPosition.copy( tempPosition );
  18493. // horizontal and vertical coordinate of the lower left corner of the pixels to copy
  18494. screenPositionPixels.x = viewport.x + ( screenPosition.x * halfViewportWidth ) + halfViewportWidth - 8;
  18495. screenPositionPixels.y = viewport.y + ( screenPosition.y * halfViewportHeight ) + halfViewportHeight - 8;
  18496. // screen cull
  18497. if ( validArea.containsPoint( screenPositionPixels ) === true ) {
  18498. // save current RGB to temp texture
  18499. state.activeTexture( gl.TEXTURE0 );
  18500. state.bindTexture( gl.TEXTURE_2D, null );
  18501. state.activeTexture( gl.TEXTURE1 );
  18502. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  18503. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGB, screenPositionPixels.x, screenPositionPixels.y, 16, 16, 0 );
  18504. // render pink quad
  18505. gl.uniform1i( uniforms.renderType, 0 );
  18506. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  18507. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  18508. state.disable( gl.BLEND );
  18509. state.enable( gl.DEPTH_TEST );
  18510. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  18511. // copy result to occlusionMap
  18512. state.activeTexture( gl.TEXTURE0 );
  18513. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  18514. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGBA, screenPositionPixels.x, screenPositionPixels.y, 16, 16, 0 );
  18515. // restore graphics
  18516. gl.uniform1i( uniforms.renderType, 1 );
  18517. state.disable( gl.DEPTH_TEST );
  18518. state.activeTexture( gl.TEXTURE1 );
  18519. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  18520. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  18521. // update object positions
  18522. flare.positionScreen.copy( screenPosition );
  18523. if ( flare.customUpdateCallback ) {
  18524. flare.customUpdateCallback( flare );
  18525. } else {
  18526. flare.updateLensFlares();
  18527. }
  18528. // render flares
  18529. gl.uniform1i( uniforms.renderType, 2 );
  18530. state.enable( gl.BLEND );
  18531. for ( var j = 0, jl = flare.lensFlares.length; j < jl; j ++ ) {
  18532. var sprite = flare.lensFlares[ j ];
  18533. if ( sprite.opacity > 0.001 && sprite.scale > 0.001 ) {
  18534. screenPosition.x = sprite.x;
  18535. screenPosition.y = sprite.y;
  18536. screenPosition.z = sprite.z;
  18537. size = sprite.size * sprite.scale / viewport.w;
  18538. scale.x = size * invAspect;
  18539. scale.y = size;
  18540. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  18541. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  18542. gl.uniform1f( uniforms.rotation, sprite.rotation );
  18543. gl.uniform1f( uniforms.opacity, sprite.opacity );
  18544. gl.uniform3f( uniforms.color, sprite.color.r, sprite.color.g, sprite.color.b );
  18545. state.setBlending( sprite.blending, sprite.blendEquation, sprite.blendSrc, sprite.blendDst );
  18546. renderer.setTexture( sprite.texture, 1 );
  18547. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  18548. }
  18549. }
  18550. }
  18551. }
  18552. // restore gl
  18553. state.enable( gl.CULL_FACE );
  18554. state.enable( gl.DEPTH_TEST );
  18555. state.setDepthWrite( true );
  18556. renderer.resetGLState();
  18557. };
  18558. function createProgram ( shader ) {
  18559. var program = gl.createProgram();
  18560. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  18561. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  18562. var prefix = "precision " + renderer.getPrecision() + " float;\n";
  18563. gl.shaderSource( fragmentShader, prefix + shader.fragmentShader );
  18564. gl.shaderSource( vertexShader, prefix + shader.vertexShader );
  18565. gl.compileShader( fragmentShader );
  18566. gl.compileShader( vertexShader );
  18567. gl.attachShader( program, fragmentShader );
  18568. gl.attachShader( program, vertexShader );
  18569. gl.linkProgram( program );
  18570. return program;
  18571. }
  18572. };
  18573. // File:src/renderers/webgl/plugins/SpritePlugin.js
  18574. /**
  18575. * @author mikael emtinger / http://gomo.se/
  18576. * @author alteredq / http://alteredqualia.com/
  18577. */
  18578. THREE.SpritePlugin = function ( renderer, sprites ) {
  18579. var gl = renderer.context;
  18580. var state = renderer.state;
  18581. var vertexBuffer, elementBuffer;
  18582. var program, attributes, uniforms;
  18583. var texture;
  18584. // decompose matrixWorld
  18585. var spritePosition = new THREE.Vector3();
  18586. var spriteRotation = new THREE.Quaternion();
  18587. var spriteScale = new THREE.Vector3();
  18588. function init() {
  18589. var vertices = new Float32Array( [
  18590. - 0.5, - 0.5, 0, 0,
  18591. 0.5, - 0.5, 1, 0,
  18592. 0.5, 0.5, 1, 1,
  18593. - 0.5, 0.5, 0, 1
  18594. ] );
  18595. var faces = new Uint16Array( [
  18596. 0, 1, 2,
  18597. 0, 2, 3
  18598. ] );
  18599. vertexBuffer = gl.createBuffer();
  18600. elementBuffer = gl.createBuffer();
  18601. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  18602. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  18603. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  18604. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  18605. program = createProgram();
  18606. attributes = {
  18607. position: gl.getAttribLocation ( program, 'position' ),
  18608. uv: gl.getAttribLocation ( program, 'uv' )
  18609. };
  18610. uniforms = {
  18611. uvOffset: gl.getUniformLocation( program, 'uvOffset' ),
  18612. uvScale: gl.getUniformLocation( program, 'uvScale' ),
  18613. rotation: gl.getUniformLocation( program, 'rotation' ),
  18614. scale: gl.getUniformLocation( program, 'scale' ),
  18615. color: gl.getUniformLocation( program, 'color' ),
  18616. map: gl.getUniformLocation( program, 'map' ),
  18617. opacity: gl.getUniformLocation( program, 'opacity' ),
  18618. modelViewMatrix: gl.getUniformLocation( program, 'modelViewMatrix' ),
  18619. projectionMatrix: gl.getUniformLocation( program, 'projectionMatrix' ),
  18620. fogType: gl.getUniformLocation( program, 'fogType' ),
  18621. fogDensity: gl.getUniformLocation( program, 'fogDensity' ),
  18622. fogNear: gl.getUniformLocation( program, 'fogNear' ),
  18623. fogFar: gl.getUniformLocation( program, 'fogFar' ),
  18624. fogColor: gl.getUniformLocation( program, 'fogColor' ),
  18625. alphaTest: gl.getUniformLocation( program, 'alphaTest' )
  18626. };
  18627. var canvas = document.createElement( 'canvas' );
  18628. canvas.width = 8;
  18629. canvas.height = 8;
  18630. var context = canvas.getContext( '2d' );
  18631. context.fillStyle = 'white';
  18632. context.fillRect( 0, 0, 8, 8 );
  18633. texture = new THREE.Texture( canvas );
  18634. texture.needsUpdate = true;
  18635. }
  18636. this.render = function ( scene, camera ) {
  18637. if ( sprites.length === 0 ) return;
  18638. // setup gl
  18639. if ( program === undefined ) {
  18640. init();
  18641. }
  18642. gl.useProgram( program );
  18643. state.initAttributes();
  18644. state.enableAttribute( attributes.position );
  18645. state.enableAttribute( attributes.uv );
  18646. state.disableUnusedAttributes();
  18647. state.disable( gl.CULL_FACE );
  18648. state.enable( gl.BLEND );
  18649. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  18650. gl.vertexAttribPointer( attributes.position, 2, gl.FLOAT, false, 2 * 8, 0 );
  18651. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  18652. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  18653. gl.uniformMatrix4fv( uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
  18654. state.activeTexture( gl.TEXTURE0 );
  18655. gl.uniform1i( uniforms.map, 0 );
  18656. var oldFogType = 0;
  18657. var sceneFogType = 0;
  18658. var fog = scene.fog;
  18659. if ( fog ) {
  18660. gl.uniform3f( uniforms.fogColor, fog.color.r, fog.color.g, fog.color.b );
  18661. if ( fog instanceof THREE.Fog ) {
  18662. gl.uniform1f( uniforms.fogNear, fog.near );
  18663. gl.uniform1f( uniforms.fogFar, fog.far );
  18664. gl.uniform1i( uniforms.fogType, 1 );
  18665. oldFogType = 1;
  18666. sceneFogType = 1;
  18667. } else if ( fog instanceof THREE.FogExp2 ) {
  18668. gl.uniform1f( uniforms.fogDensity, fog.density );
  18669. gl.uniform1i( uniforms.fogType, 2 );
  18670. oldFogType = 2;
  18671. sceneFogType = 2;
  18672. }
  18673. } else {
  18674. gl.uniform1i( uniforms.fogType, 0 );
  18675. oldFogType = 0;
  18676. sceneFogType = 0;
  18677. }
  18678. // update positions and sort
  18679. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  18680. var sprite = sprites[ i ];
  18681. sprite.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, sprite.matrixWorld );
  18682. sprite.z = - sprite.modelViewMatrix.elements[ 14 ];
  18683. }
  18684. sprites.sort( painterSortStable );
  18685. // render all sprites
  18686. var scale = [];
  18687. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  18688. var sprite = sprites[ i ];
  18689. var material = sprite.material;
  18690. gl.uniform1f( uniforms.alphaTest, material.alphaTest );
  18691. gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, sprite.modelViewMatrix.elements );
  18692. sprite.matrixWorld.decompose( spritePosition, spriteRotation, spriteScale );
  18693. scale[ 0 ] = spriteScale.x;
  18694. scale[ 1 ] = spriteScale.y;
  18695. var fogType = 0;
  18696. if ( scene.fog && material.fog ) {
  18697. fogType = sceneFogType;
  18698. }
  18699. if ( oldFogType !== fogType ) {
  18700. gl.uniform1i( uniforms.fogType, fogType );
  18701. oldFogType = fogType;
  18702. }
  18703. if ( material.map !== null ) {
  18704. gl.uniform2f( uniforms.uvOffset, material.map.offset.x, material.map.offset.y );
  18705. gl.uniform2f( uniforms.uvScale, material.map.repeat.x, material.map.repeat.y );
  18706. } else {
  18707. gl.uniform2f( uniforms.uvOffset, 0, 0 );
  18708. gl.uniform2f( uniforms.uvScale, 1, 1 );
  18709. }
  18710. gl.uniform1f( uniforms.opacity, material.opacity );
  18711. gl.uniform3f( uniforms.color, material.color.r, material.color.g, material.color.b );
  18712. gl.uniform1f( uniforms.rotation, material.rotation );
  18713. gl.uniform2fv( uniforms.scale, scale );
  18714. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst );
  18715. state.setDepthTest( material.depthTest );
  18716. state.setDepthWrite( material.depthWrite );
  18717. if ( material.map && material.map.image && material.map.image.width ) {
  18718. renderer.setTexture( material.map, 0 );
  18719. } else {
  18720. renderer.setTexture( texture, 0 );
  18721. }
  18722. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  18723. }
  18724. // restore gl
  18725. state.enable( gl.CULL_FACE );
  18726. renderer.resetGLState();
  18727. };
  18728. function createProgram () {
  18729. var program = gl.createProgram();
  18730. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  18731. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  18732. gl.shaderSource( vertexShader, [
  18733. 'precision ' + renderer.getPrecision() + ' float;',
  18734. 'uniform mat4 modelViewMatrix;',
  18735. 'uniform mat4 projectionMatrix;',
  18736. 'uniform float rotation;',
  18737. 'uniform vec2 scale;',
  18738. 'uniform vec2 uvOffset;',
  18739. 'uniform vec2 uvScale;',
  18740. 'attribute vec2 position;',
  18741. 'attribute vec2 uv;',
  18742. 'varying vec2 vUV;',
  18743. 'void main() {',
  18744. 'vUV = uvOffset + uv * uvScale;',
  18745. 'vec2 alignedPosition = position * scale;',
  18746. 'vec2 rotatedPosition;',
  18747. 'rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;',
  18748. 'rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;',
  18749. 'vec4 finalPosition;',
  18750. 'finalPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );',
  18751. 'finalPosition.xy += rotatedPosition;',
  18752. 'finalPosition = projectionMatrix * finalPosition;',
  18753. 'gl_Position = finalPosition;',
  18754. '}'
  18755. ].join( '\n' ) );
  18756. gl.shaderSource( fragmentShader, [
  18757. 'precision ' + renderer.getPrecision() + ' float;',
  18758. 'uniform vec3 color;',
  18759. 'uniform sampler2D map;',
  18760. 'uniform float opacity;',
  18761. 'uniform int fogType;',
  18762. 'uniform vec3 fogColor;',
  18763. 'uniform float fogDensity;',
  18764. 'uniform float fogNear;',
  18765. 'uniform float fogFar;',
  18766. 'uniform float alphaTest;',
  18767. 'varying vec2 vUV;',
  18768. 'void main() {',
  18769. 'vec4 texture = texture2D( map, vUV );',
  18770. 'if ( texture.a < alphaTest ) discard;',
  18771. 'gl_FragColor = vec4( color * texture.xyz, texture.a * opacity );',
  18772. 'if ( fogType > 0 ) {',
  18773. 'float depth = gl_FragCoord.z / gl_FragCoord.w;',
  18774. 'float fogFactor = 0.0;',
  18775. 'if ( fogType == 1 ) {',
  18776. 'fogFactor = smoothstep( fogNear, fogFar, depth );',
  18777. '} else {',
  18778. 'const float LOG2 = 1.442695;',
  18779. 'fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );',
  18780. 'fogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );',
  18781. '}',
  18782. 'gl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );',
  18783. '}',
  18784. '}'
  18785. ].join( '\n' ) );
  18786. gl.compileShader( vertexShader );
  18787. gl.compileShader( fragmentShader );
  18788. gl.attachShader( program, vertexShader );
  18789. gl.attachShader( program, fragmentShader );
  18790. gl.linkProgram( program );
  18791. return program;
  18792. }
  18793. function painterSortStable ( a, b ) {
  18794. if ( a.renderOrder !== b.renderOrder ) {
  18795. return a.renderOrder - b.renderOrder;
  18796. } else if ( a.z !== b.z ) {
  18797. return b.z - a.z;
  18798. } else {
  18799. return b.id - a.id;
  18800. }
  18801. }
  18802. };
  18803. // File:src/Three.Legacy.js
  18804. /**
  18805. * @author mrdoob / http://mrdoob.com/
  18806. */
  18807. Object.defineProperties( THREE.Box2.prototype, {
  18808. empty: {
  18809. value: function () {
  18810. console.warn( 'THREE.Box2: .empty() has been renamed to .isEmpty().' );
  18811. return this.isEmpty();
  18812. }
  18813. },
  18814. isIntersectionBox: {
  18815. value: function ( box ) {
  18816. console.warn( 'THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().' );
  18817. return this.intersectsBox( box );
  18818. }
  18819. }
  18820. } );
  18821. Object.defineProperties( THREE.Box3.prototype, {
  18822. empty: {
  18823. value: function () {
  18824. console.warn( 'THREE.Box3: .empty() has been renamed to .isEmpty().' );
  18825. return this.isEmpty();
  18826. }
  18827. },
  18828. isIntersectionBox: {
  18829. value: function ( box ) {
  18830. console.warn( 'THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().' );
  18831. return this.intersectsBox( box );
  18832. }
  18833. },
  18834. isIntersectionSphere: {
  18835. value: function ( sphere ) {
  18836. console.warn( 'THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  18837. return this.intersectsSphere( sphere );
  18838. }
  18839. }
  18840. } );
  18841. Object.defineProperties( THREE.Matrix3.prototype, {
  18842. multiplyVector3: {
  18843. value: function ( vector ) {
  18844. console.warn( 'THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.' );
  18845. return vector.applyMatrix3( this );
  18846. }
  18847. },
  18848. multiplyVector3Array: {
  18849. value: function ( a ) {
  18850. console.warn( 'THREE.Matrix3: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
  18851. return this.applyToVector3Array( a );
  18852. }
  18853. }
  18854. } );
  18855. Object.defineProperties( THREE.Matrix4.prototype, {
  18856. extractPosition: {
  18857. value: function ( m ) {
  18858. console.warn( 'THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().' );
  18859. return this.copyPosition( m );
  18860. }
  18861. },
  18862. setRotationFromQuaternion: {
  18863. value: function ( q ) {
  18864. console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' );
  18865. return this.makeRotationFromQuaternion( q );
  18866. }
  18867. },
  18868. multiplyVector3: {
  18869. value: function ( vector ) {
  18870. console.warn( 'THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) or vector.applyProjection( matrix ) instead.' );
  18871. return vector.applyProjection( this );
  18872. }
  18873. },
  18874. multiplyVector4: {
  18875. value: function ( vector ) {
  18876. console.warn( 'THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  18877. return vector.applyMatrix4( this );
  18878. }
  18879. },
  18880. multiplyVector3Array: {
  18881. value: function ( a ) {
  18882. console.warn( 'THREE.Matrix4: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
  18883. return this.applyToVector3Array( a );
  18884. }
  18885. },
  18886. rotateAxis: {
  18887. value: function ( v ) {
  18888. console.warn( 'THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.' );
  18889. v.transformDirection( this );
  18890. }
  18891. },
  18892. crossVector: {
  18893. value: function ( vector ) {
  18894. console.warn( 'THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  18895. return vector.applyMatrix4( this );
  18896. }
  18897. },
  18898. translate: {
  18899. value: function ( v ) {
  18900. console.error( 'THREE.Matrix4: .translate() has been removed.' );
  18901. }
  18902. },
  18903. rotateX: {
  18904. value: function ( angle ) {
  18905. console.error( 'THREE.Matrix4: .rotateX() has been removed.' );
  18906. }
  18907. },
  18908. rotateY: {
  18909. value: function ( angle ) {
  18910. console.error( 'THREE.Matrix4: .rotateY() has been removed.' );
  18911. }
  18912. },
  18913. rotateZ: {
  18914. value: function ( angle ) {
  18915. console.error( 'THREE.Matrix4: .rotateZ() has been removed.' );
  18916. }
  18917. },
  18918. rotateByAxis: {
  18919. value: function ( axis, angle ) {
  18920. console.error( 'THREE.Matrix4: .rotateByAxis() has been removed.' );
  18921. }
  18922. }
  18923. } );
  18924. Object.defineProperties( THREE.Plane.prototype, {
  18925. isIntersectionLine: {
  18926. value: function ( line ) {
  18927. console.warn( 'THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().' );
  18928. return this.intersectsLine( line );
  18929. }
  18930. }
  18931. } );
  18932. Object.defineProperties( THREE.Quaternion.prototype, {
  18933. multiplyVector3: {
  18934. value: function ( vector ) {
  18935. console.warn( 'THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.' );
  18936. return vector.applyQuaternion( this );
  18937. }
  18938. }
  18939. } );
  18940. Object.defineProperties( THREE.Ray.prototype, {
  18941. isIntersectionBox: {
  18942. value: function ( box ) {
  18943. console.warn( 'THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().' );
  18944. return this.intersectsBox( box );
  18945. }
  18946. },
  18947. isIntersectionPlane: {
  18948. value: function ( plane ) {
  18949. console.warn( 'THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().' );
  18950. return this.intersectsPlane( plane );
  18951. }
  18952. },
  18953. isIntersectionSphere: {
  18954. value: function ( sphere ) {
  18955. console.warn( 'THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  18956. return this.intersectsSphere( sphere );
  18957. }
  18958. }
  18959. } );
  18960. Object.defineProperties( THREE.Vector3.prototype, {
  18961. setEulerFromRotationMatrix: {
  18962. value: function () {
  18963. console.error( 'THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.' );
  18964. }
  18965. },
  18966. setEulerFromQuaternion: {
  18967. value: function () {
  18968. console.error( 'THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.' );
  18969. }
  18970. },
  18971. getPositionFromMatrix: {
  18972. value: function ( m ) {
  18973. console.warn( 'THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().' );
  18974. return this.setFromMatrixPosition( m );
  18975. }
  18976. },
  18977. getScaleFromMatrix: {
  18978. value: function ( m ) {
  18979. console.warn( 'THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().' );
  18980. return this.setFromMatrixScale( m );
  18981. }
  18982. },
  18983. getColumnFromMatrix: {
  18984. value: function ( index, matrix ) {
  18985. console.warn( 'THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().' );
  18986. return this.setFromMatrixColumn( index, matrix );
  18987. }
  18988. }
  18989. } );
  18990. //
  18991. THREE.Face4 = function ( a, b, c, d, normal, color, materialIndex ) {
  18992. console.warn( 'THREE.Face4 has been removed. A THREE.Face3 will be created instead.' );
  18993. return new THREE.Face3( a, b, c, normal, color, materialIndex );
  18994. };
  18995. THREE.Vertex = function ( x, y, z ) {
  18996. console.warn( 'THREE.Vertex has been removed. Use THREE.Vector3 instead.' );
  18997. return new THREE.Vector3( x, y, z );
  18998. };
  18999. //
  19000. Object.defineProperties( THREE.Object3D.prototype, {
  19001. eulerOrder: {
  19002. get: function () {
  19003. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  19004. return this.rotation.order;
  19005. },
  19006. set: function ( value ) {
  19007. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  19008. this.rotation.order = value;
  19009. }
  19010. },
  19011. getChildByName: {
  19012. value: function ( name ) {
  19013. console.warn( 'THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().' );
  19014. return this.getObjectByName( name );
  19015. }
  19016. },
  19017. renderDepth: {
  19018. set: function ( value ) {
  19019. console.warn( 'THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.' );
  19020. }
  19021. },
  19022. translate: {
  19023. value: function ( distance, axis ) {
  19024. console.warn( 'THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.' );
  19025. return this.translateOnAxis( axis, distance );
  19026. }
  19027. },
  19028. useQuaternion: {
  19029. get: function () {
  19030. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  19031. },
  19032. set: function ( value ) {
  19033. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  19034. }
  19035. }
  19036. } );
  19037. //
  19038. Object.defineProperties( THREE, {
  19039. PointCloud: {
  19040. value: function ( geometry, material ) {
  19041. console.warn( 'THREE.PointCloud has been renamed to THREE.Points.' );
  19042. return new THREE.Points( geometry, material );
  19043. }
  19044. },
  19045. ParticleSystem: {
  19046. value: function ( geometry, material ) {
  19047. console.warn( 'THREE.ParticleSystem has been renamed to THREE.Points.' );
  19048. return new THREE.Points( geometry, material );
  19049. }
  19050. }
  19051. } );
  19052. //
  19053. Object.defineProperties( THREE.Light.prototype, {
  19054. onlyShadow: {
  19055. set: function ( value ) {
  19056. console.warn( 'THREE.Light: .onlyShadow has been removed.' );
  19057. }
  19058. },
  19059. shadowCameraFov: {
  19060. set: function ( value ) {
  19061. console.warn( 'THREE.Light: .shadowCameraFov is now .shadow.camera.fov.' );
  19062. this.shadow.camera.fov = value;
  19063. }
  19064. },
  19065. shadowCameraLeft: {
  19066. set: function ( value ) {
  19067. console.warn( 'THREE.Light: .shadowCameraLeft is now .shadow.camera.left.' );
  19068. this.shadow.camera.left = value;
  19069. }
  19070. },
  19071. shadowCameraRight: {
  19072. set: function ( value ) {
  19073. console.warn( 'THREE.Light: .shadowCameraRight is now .shadow.camera.right.' );
  19074. this.shadow.camera.right = value;
  19075. }
  19076. },
  19077. shadowCameraTop: {
  19078. set: function ( value ) {
  19079. console.warn( 'THREE.Light: .shadowCameraTop is now .shadow.camera.top.' );
  19080. this.shadow.camera.top = value;
  19081. }
  19082. },
  19083. shadowCameraBottom: {
  19084. set: function ( value ) {
  19085. console.warn( 'THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.' );
  19086. this.shadow.camera.bottom = value;
  19087. }
  19088. },
  19089. shadowCameraNear: {
  19090. set: function ( value ) {
  19091. console.warn( 'THREE.Light: .shadowCameraNear is now .shadow.camera.near.' );
  19092. this.shadow.camera.near = value;
  19093. }
  19094. },
  19095. shadowCameraFar: {
  19096. set: function ( value ) {
  19097. console.warn( 'THREE.Light: .shadowCameraFar is now .shadow.camera.far.' );
  19098. this.shadow.camera.far = value;
  19099. }
  19100. },
  19101. shadowCameraVisible: {
  19102. set: function ( value ) {
  19103. console.warn( 'THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.' );
  19104. }
  19105. },
  19106. shadowBias: {
  19107. set: function ( value ) {
  19108. console.warn( 'THREE.Light: .shadowBias is now .shadow.bias.' );
  19109. this.shadow.bias = value;
  19110. }
  19111. },
  19112. shadowDarkness: {
  19113. set: function ( value ) {
  19114. console.warn( 'THREE.Light: .shadowDarkness has been removed.' );
  19115. }
  19116. },
  19117. shadowMapWidth: {
  19118. set: function ( value ) {
  19119. console.warn( 'THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.' );
  19120. this.shadow.mapSize.width = value;
  19121. }
  19122. },
  19123. shadowMapHeight: {
  19124. set: function ( value ) {
  19125. console.warn( 'THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.' );
  19126. this.shadow.mapSize.height = value;
  19127. }
  19128. }
  19129. } );
  19130. //
  19131. Object.defineProperties( THREE.BufferAttribute.prototype, {
  19132. length: {
  19133. get: function () {
  19134. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Please use .count.' );
  19135. return this.array.length;
  19136. }
  19137. }
  19138. } );
  19139. Object.defineProperties( THREE.BufferGeometry.prototype, {
  19140. drawcalls: {
  19141. get: function () {
  19142. console.error( 'THREE.BufferGeometry: .drawcalls has been renamed to .groups.' );
  19143. return this.groups;
  19144. }
  19145. },
  19146. offsets: {
  19147. get: function () {
  19148. console.warn( 'THREE.BufferGeometry: .offsets has been renamed to .groups.' );
  19149. return this.groups;
  19150. }
  19151. },
  19152. addIndex: {
  19153. value: function ( index ) {
  19154. console.warn( 'THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().' );
  19155. this.setIndex( index );
  19156. }
  19157. },
  19158. addDrawCall: {
  19159. value: function ( start, count, indexOffset ) {
  19160. if ( indexOffset !== undefined ) {
  19161. console.warn( 'THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.' );
  19162. }
  19163. console.warn( 'THREE.BufferGeometry: .addDrawCall() is now .addGroup().' );
  19164. this.addGroup( start, count );
  19165. }
  19166. },
  19167. clearDrawCalls: {
  19168. value: function () {
  19169. console.warn( 'THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().' );
  19170. this.clearGroups();
  19171. }
  19172. },
  19173. computeTangents: {
  19174. value: function () {
  19175. console.warn( 'THREE.BufferGeometry: .computeTangents() has been removed.' );
  19176. }
  19177. },
  19178. computeOffsets: {
  19179. value: function () {
  19180. console.warn( 'THREE.BufferGeometry: .computeOffsets() has been removed.' );
  19181. }
  19182. }
  19183. } );
  19184. //
  19185. Object.defineProperties( THREE.Material.prototype, {
  19186. wrapAround: {
  19187. get: function () {
  19188. console.warn( 'THREE.' + this.type + ': .wrapAround has been removed.' );
  19189. },
  19190. set: function ( value ) {
  19191. console.warn( 'THREE.' + this.type + ': .wrapAround has been removed.' );
  19192. }
  19193. },
  19194. wrapRGB: {
  19195. get: function () {
  19196. console.warn( 'THREE.' + this.type + ': .wrapRGB has been removed.' );
  19197. return new THREE.Color();
  19198. }
  19199. }
  19200. } );
  19201. Object.defineProperties( THREE, {
  19202. PointCloudMaterial: {
  19203. value: function ( parameters ) {
  19204. console.warn( 'THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.' );
  19205. return new THREE.PointsMaterial( parameters );
  19206. }
  19207. },
  19208. ParticleBasicMaterial: {
  19209. value: function ( parameters ) {
  19210. console.warn( 'THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.' );
  19211. return new THREE.PointsMaterial( parameters );
  19212. }
  19213. },
  19214. ParticleSystemMaterial:{
  19215. value: function ( parameters ) {
  19216. console.warn( 'THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.' );
  19217. return new THREE.PointsMaterial( parameters );
  19218. }
  19219. }
  19220. } );
  19221. Object.defineProperties( THREE.MeshPhongMaterial.prototype, {
  19222. metal: {
  19223. get: function () {
  19224. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.' );
  19225. return false;
  19226. },
  19227. set: function ( value ) {
  19228. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead' );
  19229. }
  19230. }
  19231. } );
  19232. Object.defineProperties( THREE.ShaderMaterial.prototype, {
  19233. derivatives: {
  19234. get: function () {
  19235. console.warn( 'THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  19236. return this.extensions.derivatives;
  19237. },
  19238. set: function ( value ) {
  19239. console.warn( 'THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  19240. this.extensions.derivatives = value;
  19241. }
  19242. }
  19243. } );
  19244. //
  19245. Object.defineProperties( THREE.WebGLRenderer.prototype, {
  19246. supportsFloatTextures: {
  19247. value: function () {
  19248. console.warn( 'THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).' );
  19249. return this.extensions.get( 'OES_texture_float' );
  19250. }
  19251. },
  19252. supportsHalfFloatTextures: {
  19253. value: function () {
  19254. console.warn( 'THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).' );
  19255. return this.extensions.get( 'OES_texture_half_float' );
  19256. }
  19257. },
  19258. supportsStandardDerivatives: {
  19259. value: function () {
  19260. console.warn( 'THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).' );
  19261. return this.extensions.get( 'OES_standard_derivatives' );
  19262. }
  19263. },
  19264. supportsCompressedTextureS3TC: {
  19265. value: function () {
  19266. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).' );
  19267. return this.extensions.get( 'WEBGL_compressed_texture_s3tc' );
  19268. }
  19269. },
  19270. supportsCompressedTexturePVRTC: {
  19271. value: function () {
  19272. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).' );
  19273. return this.extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  19274. }
  19275. },
  19276. supportsBlendMinMax: {
  19277. value: function () {
  19278. console.warn( 'THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).' );
  19279. return this.extensions.get( 'EXT_blend_minmax' );
  19280. }
  19281. },
  19282. supportsVertexTextures: {
  19283. value: function () {
  19284. return this.capabilities.vertexTextures;
  19285. }
  19286. },
  19287. supportsInstancedArrays: {
  19288. value: function () {
  19289. console.warn( 'THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).' );
  19290. return this.extensions.get( 'ANGLE_instanced_arrays' );
  19291. }
  19292. },
  19293. enableScissorTest: {
  19294. value: function ( boolean ) {
  19295. console.warn( 'THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().' );
  19296. this.setScissorTest( boolean );
  19297. }
  19298. },
  19299. initMaterial: {
  19300. value: function () {
  19301. console.warn( 'THREE.WebGLRenderer: .initMaterial() has been removed.' );
  19302. }
  19303. },
  19304. addPrePlugin: {
  19305. value: function () {
  19306. console.warn( 'THREE.WebGLRenderer: .addPrePlugin() has been removed.' );
  19307. }
  19308. },
  19309. addPostPlugin: {
  19310. value: function () {
  19311. console.warn( 'THREE.WebGLRenderer: .addPostPlugin() has been removed.' );
  19312. }
  19313. },
  19314. updateShadowMap: {
  19315. value: function () {
  19316. console.warn( 'THREE.WebGLRenderer: .updateShadowMap() has been removed.' );
  19317. }
  19318. },
  19319. shadowMapEnabled: {
  19320. get: function () {
  19321. return this.shadowMap.enabled;
  19322. },
  19323. set: function ( value ) {
  19324. console.warn( 'THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.' );
  19325. this.shadowMap.enabled = value;
  19326. }
  19327. },
  19328. shadowMapType: {
  19329. get: function () {
  19330. return this.shadowMap.type;
  19331. },
  19332. set: function ( value ) {
  19333. console.warn( 'THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.' );
  19334. this.shadowMap.type = value;
  19335. }
  19336. },
  19337. shadowMapCullFace: {
  19338. get: function () {
  19339. return this.shadowMap.cullFace;
  19340. },
  19341. set: function ( value ) {
  19342. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace is now .shadowMap.cullFace.' );
  19343. this.shadowMap.cullFace = value;
  19344. }
  19345. }
  19346. } );
  19347. //
  19348. Object.defineProperties( THREE.WebGLRenderTarget.prototype, {
  19349. wrapS: {
  19350. get: function () {
  19351. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  19352. return this.texture.wrapS;
  19353. },
  19354. set: function ( value ) {
  19355. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  19356. this.texture.wrapS = value;
  19357. }
  19358. },
  19359. wrapT: {
  19360. get: function () {
  19361. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  19362. return this.texture.wrapT;
  19363. },
  19364. set: function ( value ) {
  19365. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  19366. this.texture.wrapT = value;
  19367. }
  19368. },
  19369. magFilter: {
  19370. get: function () {
  19371. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  19372. return this.texture.magFilter;
  19373. },
  19374. set: function ( value ) {
  19375. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  19376. this.texture.magFilter = value;
  19377. }
  19378. },
  19379. minFilter: {
  19380. get: function () {
  19381. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  19382. return this.texture.minFilter;
  19383. },
  19384. set: function ( value ) {
  19385. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  19386. this.texture.minFilter = value;
  19387. }
  19388. },
  19389. anisotropy: {
  19390. get: function () {
  19391. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  19392. return this.texture.anisotropy;
  19393. },
  19394. set: function ( value ) {
  19395. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  19396. this.texture.anisotropy = value;
  19397. }
  19398. },
  19399. offset: {
  19400. get: function () {
  19401. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  19402. return this.texture.offset;
  19403. },
  19404. set: function ( value ) {
  19405. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  19406. this.texture.offset = value;
  19407. }
  19408. },
  19409. repeat: {
  19410. get: function () {
  19411. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  19412. return this.texture.repeat;
  19413. },
  19414. set: function ( value ) {
  19415. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  19416. this.texture.repeat = value;
  19417. }
  19418. },
  19419. format: {
  19420. get: function () {
  19421. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  19422. return this.texture.format;
  19423. },
  19424. set: function ( value ) {
  19425. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  19426. this.texture.format = value;
  19427. }
  19428. },
  19429. type: {
  19430. get: function () {
  19431. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  19432. return this.texture.type;
  19433. },
  19434. set: function ( value ) {
  19435. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  19436. this.texture.type = value;
  19437. }
  19438. },
  19439. generateMipmaps: {
  19440. get: function () {
  19441. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  19442. return this.texture.generateMipmaps;
  19443. },
  19444. set: function ( value ) {
  19445. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  19446. this.texture.generateMipmaps = value;
  19447. }
  19448. }
  19449. } );
  19450. //
  19451. THREE.GeometryUtils = {
  19452. merge: function ( geometry1, geometry2, materialIndexOffset ) {
  19453. console.warn( 'THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.' );
  19454. var matrix;
  19455. if ( geometry2 instanceof THREE.Mesh ) {
  19456. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  19457. matrix = geometry2.matrix;
  19458. geometry2 = geometry2.geometry;
  19459. }
  19460. geometry1.merge( geometry2, matrix, materialIndexOffset );
  19461. },
  19462. center: function ( geometry ) {
  19463. console.warn( 'THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.' );
  19464. return geometry.center();
  19465. }
  19466. };
  19467. THREE.ImageUtils = {
  19468. crossOrigin: undefined,
  19469. loadTexture: function ( url, mapping, onLoad, onError ) {
  19470. console.warn( 'THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.' );
  19471. var loader = new THREE.TextureLoader();
  19472. loader.setCrossOrigin( this.crossOrigin );
  19473. var texture = loader.load( url, onLoad, undefined, onError );
  19474. if ( mapping ) texture.mapping = mapping;
  19475. return texture;
  19476. },
  19477. loadTextureCube: function ( urls, mapping, onLoad, onError ) {
  19478. console.warn( 'THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.' );
  19479. var loader = new THREE.CubeTextureLoader();
  19480. loader.setCrossOrigin( this.crossOrigin );
  19481. var texture = loader.load( urls, onLoad, undefined, onError );
  19482. if ( mapping ) texture.mapping = mapping;
  19483. return texture;
  19484. },
  19485. loadCompressedTexture: function () {
  19486. console.error( 'THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.' );
  19487. },
  19488. loadCompressedTextureCube: function () {
  19489. console.error( 'THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.' );
  19490. }
  19491. };
  19492. //
  19493. THREE.Projector = function () {
  19494. console.error( 'THREE.Projector has been moved to /examples/js/renderers/Projector.js.' );
  19495. this.projectVector = function ( vector, camera ) {
  19496. console.warn( 'THREE.Projector: .projectVector() is now vector.project().' );
  19497. vector.project( camera );
  19498. };
  19499. this.unprojectVector = function ( vector, camera ) {
  19500. console.warn( 'THREE.Projector: .unprojectVector() is now vector.unproject().' );
  19501. vector.unproject( camera );
  19502. };
  19503. this.pickingRay = function ( vector, camera ) {
  19504. console.error( 'THREE.Projector: .pickingRay() is now raycaster.setFromCamera().' );
  19505. };
  19506. };
  19507. //
  19508. THREE.CanvasRenderer = function () {
  19509. console.error( 'THREE.CanvasRenderer has been moved to /examples/js/renderers/CanvasRenderer.js' );
  19510. this.domElement = document.createElement( 'canvas' );
  19511. this.clear = function () {};
  19512. this.render = function () {};
  19513. this.setClearColor = function () {};
  19514. this.setSize = function () {};
  19515. };
  19516. //
  19517. THREE.MeshFaceMaterial = THREE.MultiMaterial;
  19518. // File:src/extras/CurveUtils.js
  19519. /**
  19520. * @author zz85 / http://www.lab4games.net/zz85/blog
  19521. */
  19522. THREE.CurveUtils = {
  19523. tangentQuadraticBezier: function ( t, p0, p1, p2 ) {
  19524. return 2 * ( 1 - t ) * ( p1 - p0 ) + 2 * t * ( p2 - p1 );
  19525. },
  19526. // Puay Bing, thanks for helping with this derivative!
  19527. tangentCubicBezier: function ( t, p0, p1, p2, p3 ) {
  19528. return - 3 * p0 * ( 1 - t ) * ( 1 - t ) +
  19529. 3 * p1 * ( 1 - t ) * ( 1 - t ) - 6 * t * p1 * ( 1 - t ) +
  19530. 6 * t * p2 * ( 1 - t ) - 3 * t * t * p2 +
  19531. 3 * t * t * p3;
  19532. },
  19533. tangentSpline: function ( t, p0, p1, p2, p3 ) {
  19534. // To check if my formulas are correct
  19535. var h00 = 6 * t * t - 6 * t; // derived from 2t^3 − 3t^2 + 1
  19536. var h10 = 3 * t * t - 4 * t + 1; // t^3 − 2t^2 + t
  19537. var h01 = - 6 * t * t + 6 * t; // − 2t3 + 3t2
  19538. var h11 = 3 * t * t - 2 * t; // t3 − t2
  19539. return h00 + h10 + h01 + h11;
  19540. },
  19541. // Catmull-Rom
  19542. interpolate: function( p0, p1, p2, p3, t ) {
  19543. var v0 = ( p2 - p0 ) * 0.5;
  19544. var v1 = ( p3 - p1 ) * 0.5;
  19545. var t2 = t * t;
  19546. var t3 = t * t2;
  19547. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  19548. }
  19549. };
  19550. // File:src/extras/SceneUtils.js
  19551. /**
  19552. * @author alteredq / http://alteredqualia.com/
  19553. */
  19554. THREE.SceneUtils = {
  19555. createMultiMaterialObject: function ( geometry, materials ) {
  19556. var group = new THREE.Group();
  19557. for ( var i = 0, l = materials.length; i < l; i ++ ) {
  19558. group.add( new THREE.Mesh( geometry, materials[ i ] ) );
  19559. }
  19560. return group;
  19561. },
  19562. detach: function ( child, parent, scene ) {
  19563. child.applyMatrix( parent.matrixWorld );
  19564. parent.remove( child );
  19565. scene.add( child );
  19566. },
  19567. attach: function ( child, scene, parent ) {
  19568. var matrixWorldInverse = new THREE.Matrix4();
  19569. matrixWorldInverse.getInverse( parent.matrixWorld );
  19570. child.applyMatrix( matrixWorldInverse );
  19571. scene.remove( child );
  19572. parent.add( child );
  19573. }
  19574. };
  19575. // File:src/extras/ShapeUtils.js
  19576. /**
  19577. * @author zz85 / http://www.lab4games.net/zz85/blog
  19578. */
  19579. THREE.ShapeUtils = {
  19580. // calculate area of the contour polygon
  19581. area: function ( contour ) {
  19582. var n = contour.length;
  19583. var a = 0.0;
  19584. for ( var p = n - 1, q = 0; q < n; p = q ++ ) {
  19585. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  19586. }
  19587. return a * 0.5;
  19588. },
  19589. triangulate: ( function () {
  19590. /**
  19591. * This code is a quick port of code written in C++ which was submitted to
  19592. * flipcode.com by John W. Ratcliff // July 22, 2000
  19593. * See original code and more information here:
  19594. * http://www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml
  19595. *
  19596. * ported to actionscript by Zevan Rosser
  19597. * www.actionsnippet.com
  19598. *
  19599. * ported to javascript by Joshua Koo
  19600. * http://www.lab4games.net/zz85/blog
  19601. *
  19602. */
  19603. function snip( contour, u, v, w, n, verts ) {
  19604. var p;
  19605. var ax, ay, bx, by;
  19606. var cx, cy, px, py;
  19607. ax = contour[ verts[ u ] ].x;
  19608. ay = contour[ verts[ u ] ].y;
  19609. bx = contour[ verts[ v ] ].x;
  19610. by = contour[ verts[ v ] ].y;
  19611. cx = contour[ verts[ w ] ].x;
  19612. cy = contour[ verts[ w ] ].y;
  19613. if ( Number.EPSILON > ( ( ( bx - ax ) * ( cy - ay ) ) - ( ( by - ay ) * ( cx - ax ) ) ) ) return false;
  19614. var aX, aY, bX, bY, cX, cY;
  19615. var apx, apy, bpx, bpy, cpx, cpy;
  19616. var cCROSSap, bCROSScp, aCROSSbp;
  19617. aX = cx - bx; aY = cy - by;
  19618. bX = ax - cx; bY = ay - cy;
  19619. cX = bx - ax; cY = by - ay;
  19620. for ( p = 0; p < n; p ++ ) {
  19621. px = contour[ verts[ p ] ].x;
  19622. py = contour[ verts[ p ] ].y;
  19623. if ( ( ( px === ax ) && ( py === ay ) ) ||
  19624. ( ( px === bx ) && ( py === by ) ) ||
  19625. ( ( px === cx ) && ( py === cy ) ) ) continue;
  19626. apx = px - ax; apy = py - ay;
  19627. bpx = px - bx; bpy = py - by;
  19628. cpx = px - cx; cpy = py - cy;
  19629. // see if p is inside triangle abc
  19630. aCROSSbp = aX * bpy - aY * bpx;
  19631. cCROSSap = cX * apy - cY * apx;
  19632. bCROSScp = bX * cpy - bY * cpx;
  19633. if ( ( aCROSSbp >= - Number.EPSILON ) && ( bCROSScp >= - Number.EPSILON ) && ( cCROSSap >= - Number.EPSILON ) ) return false;
  19634. }
  19635. return true;
  19636. }
  19637. // takes in an contour array and returns
  19638. return function ( contour, indices ) {
  19639. var n = contour.length;
  19640. if ( n < 3 ) return null;
  19641. var result = [],
  19642. verts = [],
  19643. vertIndices = [];
  19644. /* we want a counter-clockwise polygon in verts */
  19645. var u, v, w;
  19646. if ( THREE.ShapeUtils.area( contour ) > 0.0 ) {
  19647. for ( v = 0; v < n; v ++ ) verts[ v ] = v;
  19648. } else {
  19649. for ( v = 0; v < n; v ++ ) verts[ v ] = ( n - 1 ) - v;
  19650. }
  19651. var nv = n;
  19652. /* remove nv - 2 vertices, creating 1 triangle every time */
  19653. var count = 2 * nv; /* error detection */
  19654. for ( v = nv - 1; nv > 2; ) {
  19655. /* if we loop, it is probably a non-simple polygon */
  19656. if ( ( count -- ) <= 0 ) {
  19657. //** Triangulate: ERROR - probable bad polygon!
  19658. //throw ( "Warning, unable to triangulate polygon!" );
  19659. //return null;
  19660. // Sometimes warning is fine, especially polygons are triangulated in reverse.
  19661. console.warn( 'THREE.ShapeUtils: Unable to triangulate polygon! in triangulate()' );
  19662. if ( indices ) return vertIndices;
  19663. return result;
  19664. }
  19665. /* three consecutive vertices in current polygon, <u,v,w> */
  19666. u = v; if ( nv <= u ) u = 0; /* previous */
  19667. v = u + 1; if ( nv <= v ) v = 0; /* new v */
  19668. w = v + 1; if ( nv <= w ) w = 0; /* next */
  19669. if ( snip( contour, u, v, w, nv, verts ) ) {
  19670. var a, b, c, s, t;
  19671. /* true names of the vertices */
  19672. a = verts[ u ];
  19673. b = verts[ v ];
  19674. c = verts[ w ];
  19675. /* output Triangle */
  19676. result.push( [ contour[ a ],
  19677. contour[ b ],
  19678. contour[ c ] ] );
  19679. vertIndices.push( [ verts[ u ], verts[ v ], verts[ w ] ] );
  19680. /* remove v from the remaining polygon */
  19681. for ( s = v, t = v + 1; t < nv; s ++, t ++ ) {
  19682. verts[ s ] = verts[ t ];
  19683. }
  19684. nv --;
  19685. /* reset error detection counter */
  19686. count = 2 * nv;
  19687. }
  19688. }
  19689. if ( indices ) return vertIndices;
  19690. return result;
  19691. }
  19692. } )(),
  19693. triangulateShape: function ( contour, holes ) {
  19694. function point_in_segment_2D_colin( inSegPt1, inSegPt2, inOtherPt ) {
  19695. // inOtherPt needs to be collinear to the inSegment
  19696. if ( inSegPt1.x !== inSegPt2.x ) {
  19697. if ( inSegPt1.x < inSegPt2.x ) {
  19698. return ( ( inSegPt1.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt2.x ) );
  19699. } else {
  19700. return ( ( inSegPt2.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt1.x ) );
  19701. }
  19702. } else {
  19703. if ( inSegPt1.y < inSegPt2.y ) {
  19704. return ( ( inSegPt1.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt2.y ) );
  19705. } else {
  19706. return ( ( inSegPt2.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt1.y ) );
  19707. }
  19708. }
  19709. }
  19710. function intersect_segments_2D( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1, inSeg2Pt2, inExcludeAdjacentSegs ) {
  19711. var seg1dx = inSeg1Pt2.x - inSeg1Pt1.x, seg1dy = inSeg1Pt2.y - inSeg1Pt1.y;
  19712. var seg2dx = inSeg2Pt2.x - inSeg2Pt1.x, seg2dy = inSeg2Pt2.y - inSeg2Pt1.y;
  19713. var seg1seg2dx = inSeg1Pt1.x - inSeg2Pt1.x;
  19714. var seg1seg2dy = inSeg1Pt1.y - inSeg2Pt1.y;
  19715. var limit = seg1dy * seg2dx - seg1dx * seg2dy;
  19716. var perpSeg1 = seg1dy * seg1seg2dx - seg1dx * seg1seg2dy;
  19717. if ( Math.abs( limit ) > Number.EPSILON ) {
  19718. // not parallel
  19719. var perpSeg2;
  19720. if ( limit > 0 ) {
  19721. if ( ( perpSeg1 < 0 ) || ( perpSeg1 > limit ) ) return [];
  19722. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  19723. if ( ( perpSeg2 < 0 ) || ( perpSeg2 > limit ) ) return [];
  19724. } else {
  19725. if ( ( perpSeg1 > 0 ) || ( perpSeg1 < limit ) ) return [];
  19726. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  19727. if ( ( perpSeg2 > 0 ) || ( perpSeg2 < limit ) ) return [];
  19728. }
  19729. // i.e. to reduce rounding errors
  19730. // intersection at endpoint of segment#1?
  19731. if ( perpSeg2 === 0 ) {
  19732. if ( ( inExcludeAdjacentSegs ) &&
  19733. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  19734. return [ inSeg1Pt1 ];
  19735. }
  19736. if ( perpSeg2 === limit ) {
  19737. if ( ( inExcludeAdjacentSegs ) &&
  19738. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  19739. return [ inSeg1Pt2 ];
  19740. }
  19741. // intersection at endpoint of segment#2?
  19742. if ( perpSeg1 === 0 ) return [ inSeg2Pt1 ];
  19743. if ( perpSeg1 === limit ) return [ inSeg2Pt2 ];
  19744. // return real intersection point
  19745. var factorSeg1 = perpSeg2 / limit;
  19746. return [ { x: inSeg1Pt1.x + factorSeg1 * seg1dx,
  19747. y: inSeg1Pt1.y + factorSeg1 * seg1dy } ];
  19748. } else {
  19749. // parallel or collinear
  19750. if ( ( perpSeg1 !== 0 ) ||
  19751. ( seg2dy * seg1seg2dx !== seg2dx * seg1seg2dy ) ) return [];
  19752. // they are collinear or degenerate
  19753. var seg1Pt = ( ( seg1dx === 0 ) && ( seg1dy === 0 ) ); // segment1 is just a point?
  19754. var seg2Pt = ( ( seg2dx === 0 ) && ( seg2dy === 0 ) ); // segment2 is just a point?
  19755. // both segments are points
  19756. if ( seg1Pt && seg2Pt ) {
  19757. if ( ( inSeg1Pt1.x !== inSeg2Pt1.x ) ||
  19758. ( inSeg1Pt1.y !== inSeg2Pt1.y ) ) return []; // they are distinct points
  19759. return [ inSeg1Pt1 ]; // they are the same point
  19760. }
  19761. // segment#1 is a single point
  19762. if ( seg1Pt ) {
  19763. if ( ! point_in_segment_2D_colin( inSeg2Pt1, inSeg2Pt2, inSeg1Pt1 ) ) return []; // but not in segment#2
  19764. return [ inSeg1Pt1 ];
  19765. }
  19766. // segment#2 is a single point
  19767. if ( seg2Pt ) {
  19768. if ( ! point_in_segment_2D_colin( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1 ) ) return []; // but not in segment#1
  19769. return [ inSeg2Pt1 ];
  19770. }
  19771. // they are collinear segments, which might overlap
  19772. var seg1min, seg1max, seg1minVal, seg1maxVal;
  19773. var seg2min, seg2max, seg2minVal, seg2maxVal;
  19774. if ( seg1dx !== 0 ) {
  19775. // the segments are NOT on a vertical line
  19776. if ( inSeg1Pt1.x < inSeg1Pt2.x ) {
  19777. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.x;
  19778. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.x;
  19779. } else {
  19780. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.x;
  19781. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.x;
  19782. }
  19783. if ( inSeg2Pt1.x < inSeg2Pt2.x ) {
  19784. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.x;
  19785. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.x;
  19786. } else {
  19787. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.x;
  19788. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.x;
  19789. }
  19790. } else {
  19791. // the segments are on a vertical line
  19792. if ( inSeg1Pt1.y < inSeg1Pt2.y ) {
  19793. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.y;
  19794. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.y;
  19795. } else {
  19796. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.y;
  19797. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.y;
  19798. }
  19799. if ( inSeg2Pt1.y < inSeg2Pt2.y ) {
  19800. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.y;
  19801. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.y;
  19802. } else {
  19803. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.y;
  19804. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.y;
  19805. }
  19806. }
  19807. if ( seg1minVal <= seg2minVal ) {
  19808. if ( seg1maxVal < seg2minVal ) return [];
  19809. if ( seg1maxVal === seg2minVal ) {
  19810. if ( inExcludeAdjacentSegs ) return [];
  19811. return [ seg2min ];
  19812. }
  19813. if ( seg1maxVal <= seg2maxVal ) return [ seg2min, seg1max ];
  19814. return [ seg2min, seg2max ];
  19815. } else {
  19816. if ( seg1minVal > seg2maxVal ) return [];
  19817. if ( seg1minVal === seg2maxVal ) {
  19818. if ( inExcludeAdjacentSegs ) return [];
  19819. return [ seg1min ];
  19820. }
  19821. if ( seg1maxVal <= seg2maxVal ) return [ seg1min, seg1max ];
  19822. return [ seg1min, seg2max ];
  19823. }
  19824. }
  19825. }
  19826. function isPointInsideAngle( inVertex, inLegFromPt, inLegToPt, inOtherPt ) {
  19827. // The order of legs is important
  19828. // translation of all points, so that Vertex is at (0,0)
  19829. var legFromPtX = inLegFromPt.x - inVertex.x, legFromPtY = inLegFromPt.y - inVertex.y;
  19830. var legToPtX = inLegToPt.x - inVertex.x, legToPtY = inLegToPt.y - inVertex.y;
  19831. var otherPtX = inOtherPt.x - inVertex.x, otherPtY = inOtherPt.y - inVertex.y;
  19832. // main angle >0: < 180 deg.; 0: 180 deg.; <0: > 180 deg.
  19833. var from2toAngle = legFromPtX * legToPtY - legFromPtY * legToPtX;
  19834. var from2otherAngle = legFromPtX * otherPtY - legFromPtY * otherPtX;
  19835. if ( Math.abs( from2toAngle ) > Number.EPSILON ) {
  19836. // angle != 180 deg.
  19837. var other2toAngle = otherPtX * legToPtY - otherPtY * legToPtX;
  19838. // console.log( "from2to: " + from2toAngle + ", from2other: " + from2otherAngle + ", other2to: " + other2toAngle );
  19839. if ( from2toAngle > 0 ) {
  19840. // main angle < 180 deg.
  19841. return ( ( from2otherAngle >= 0 ) && ( other2toAngle >= 0 ) );
  19842. } else {
  19843. // main angle > 180 deg.
  19844. return ( ( from2otherAngle >= 0 ) || ( other2toAngle >= 0 ) );
  19845. }
  19846. } else {
  19847. // angle == 180 deg.
  19848. // console.log( "from2to: 180 deg., from2other: " + from2otherAngle );
  19849. return ( from2otherAngle > 0 );
  19850. }
  19851. }
  19852. function removeHoles( contour, holes ) {
  19853. var shape = contour.concat(); // work on this shape
  19854. var hole;
  19855. function isCutLineInsideAngles( inShapeIdx, inHoleIdx ) {
  19856. // Check if hole point lies within angle around shape point
  19857. var lastShapeIdx = shape.length - 1;
  19858. var prevShapeIdx = inShapeIdx - 1;
  19859. if ( prevShapeIdx < 0 ) prevShapeIdx = lastShapeIdx;
  19860. var nextShapeIdx = inShapeIdx + 1;
  19861. if ( nextShapeIdx > lastShapeIdx ) nextShapeIdx = 0;
  19862. var insideAngle = isPointInsideAngle( shape[ inShapeIdx ], shape[ prevShapeIdx ], shape[ nextShapeIdx ], hole[ inHoleIdx ] );
  19863. if ( ! insideAngle ) {
  19864. // console.log( "Vertex (Shape): " + inShapeIdx + ", Point: " + hole[inHoleIdx].x + "/" + hole[inHoleIdx].y );
  19865. return false;
  19866. }
  19867. // Check if shape point lies within angle around hole point
  19868. var lastHoleIdx = hole.length - 1;
  19869. var prevHoleIdx = inHoleIdx - 1;
  19870. if ( prevHoleIdx < 0 ) prevHoleIdx = lastHoleIdx;
  19871. var nextHoleIdx = inHoleIdx + 1;
  19872. if ( nextHoleIdx > lastHoleIdx ) nextHoleIdx = 0;
  19873. insideAngle = isPointInsideAngle( hole[ inHoleIdx ], hole[ prevHoleIdx ], hole[ nextHoleIdx ], shape[ inShapeIdx ] );
  19874. if ( ! insideAngle ) {
  19875. // console.log( "Vertex (Hole): " + inHoleIdx + ", Point: " + shape[inShapeIdx].x + "/" + shape[inShapeIdx].y );
  19876. return false;
  19877. }
  19878. return true;
  19879. }
  19880. function intersectsShapeEdge( inShapePt, inHolePt ) {
  19881. // checks for intersections with shape edges
  19882. var sIdx, nextIdx, intersection;
  19883. for ( sIdx = 0; sIdx < shape.length; sIdx ++ ) {
  19884. nextIdx = sIdx + 1; nextIdx %= shape.length;
  19885. intersection = intersect_segments_2D( inShapePt, inHolePt, shape[ sIdx ], shape[ nextIdx ], true );
  19886. if ( intersection.length > 0 ) return true;
  19887. }
  19888. return false;
  19889. }
  19890. var indepHoles = [];
  19891. function intersectsHoleEdge( inShapePt, inHolePt ) {
  19892. // checks for intersections with hole edges
  19893. var ihIdx, chkHole,
  19894. hIdx, nextIdx, intersection;
  19895. for ( ihIdx = 0; ihIdx < indepHoles.length; ihIdx ++ ) {
  19896. chkHole = holes[ indepHoles[ ihIdx ]];
  19897. for ( hIdx = 0; hIdx < chkHole.length; hIdx ++ ) {
  19898. nextIdx = hIdx + 1; nextIdx %= chkHole.length;
  19899. intersection = intersect_segments_2D( inShapePt, inHolePt, chkHole[ hIdx ], chkHole[ nextIdx ], true );
  19900. if ( intersection.length > 0 ) return true;
  19901. }
  19902. }
  19903. return false;
  19904. }
  19905. var holeIndex, shapeIndex,
  19906. shapePt, holePt,
  19907. holeIdx, cutKey, failedCuts = [],
  19908. tmpShape1, tmpShape2,
  19909. tmpHole1, tmpHole2;
  19910. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  19911. indepHoles.push( h );
  19912. }
  19913. var minShapeIndex = 0;
  19914. var counter = indepHoles.length * 2;
  19915. while ( indepHoles.length > 0 ) {
  19916. counter --;
  19917. if ( counter < 0 ) {
  19918. console.log( "Infinite Loop! Holes left:" + indepHoles.length + ", Probably Hole outside Shape!" );
  19919. break;
  19920. }
  19921. // search for shape-vertex and hole-vertex,
  19922. // which can be connected without intersections
  19923. for ( shapeIndex = minShapeIndex; shapeIndex < shape.length; shapeIndex ++ ) {
  19924. shapePt = shape[ shapeIndex ];
  19925. holeIndex = - 1;
  19926. // search for hole which can be reached without intersections
  19927. for ( var h = 0; h < indepHoles.length; h ++ ) {
  19928. holeIdx = indepHoles[ h ];
  19929. // prevent multiple checks
  19930. cutKey = shapePt.x + ":" + shapePt.y + ":" + holeIdx;
  19931. if ( failedCuts[ cutKey ] !== undefined ) continue;
  19932. hole = holes[ holeIdx ];
  19933. for ( var h2 = 0; h2 < hole.length; h2 ++ ) {
  19934. holePt = hole[ h2 ];
  19935. if ( ! isCutLineInsideAngles( shapeIndex, h2 ) ) continue;
  19936. if ( intersectsShapeEdge( shapePt, holePt ) ) continue;
  19937. if ( intersectsHoleEdge( shapePt, holePt ) ) continue;
  19938. holeIndex = h2;
  19939. indepHoles.splice( h, 1 );
  19940. tmpShape1 = shape.slice( 0, shapeIndex + 1 );
  19941. tmpShape2 = shape.slice( shapeIndex );
  19942. tmpHole1 = hole.slice( holeIndex );
  19943. tmpHole2 = hole.slice( 0, holeIndex + 1 );
  19944. shape = tmpShape1.concat( tmpHole1 ).concat( tmpHole2 ).concat( tmpShape2 );
  19945. minShapeIndex = shapeIndex;
  19946. // Debug only, to show the selected cuts
  19947. // glob_CutLines.push( [ shapePt, holePt ] );
  19948. break;
  19949. }
  19950. if ( holeIndex >= 0 ) break; // hole-vertex found
  19951. failedCuts[ cutKey ] = true; // remember failure
  19952. }
  19953. if ( holeIndex >= 0 ) break; // hole-vertex found
  19954. }
  19955. }
  19956. return shape; /* shape with no holes */
  19957. }
  19958. var i, il, f, face,
  19959. key, index,
  19960. allPointsMap = {};
  19961. // 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.
  19962. var allpoints = contour.concat();
  19963. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  19964. Array.prototype.push.apply( allpoints, holes[ h ] );
  19965. }
  19966. //console.log( "allpoints",allpoints, allpoints.length );
  19967. // prepare all points map
  19968. for ( i = 0, il = allpoints.length; i < il; i ++ ) {
  19969. key = allpoints[ i ].x + ":" + allpoints[ i ].y;
  19970. if ( allPointsMap[ key ] !== undefined ) {
  19971. console.warn( "THREE.Shape: Duplicate point", key );
  19972. }
  19973. allPointsMap[ key ] = i;
  19974. }
  19975. // remove holes by cutting paths to holes and adding them to the shape
  19976. var shapeWithoutHoles = removeHoles( contour, holes );
  19977. var triangles = THREE.ShapeUtils.triangulate( shapeWithoutHoles, false ); // True returns indices for points of spooled shape
  19978. //console.log( "triangles",triangles, triangles.length );
  19979. // check all face vertices against all points map
  19980. for ( i = 0, il = triangles.length; i < il; i ++ ) {
  19981. face = triangles[ i ];
  19982. for ( f = 0; f < 3; f ++ ) {
  19983. key = face[ f ].x + ":" + face[ f ].y;
  19984. index = allPointsMap[ key ];
  19985. if ( index !== undefined ) {
  19986. face[ f ] = index;
  19987. }
  19988. }
  19989. }
  19990. return triangles.concat();
  19991. },
  19992. isClockWise: function ( pts ) {
  19993. return THREE.ShapeUtils.area( pts ) < 0;
  19994. },
  19995. // Bezier Curves formulas obtained from
  19996. // http://en.wikipedia.org/wiki/B%C3%A9zier_curve
  19997. // Quad Bezier Functions
  19998. b2: ( function () {
  19999. function b2p0( t, p ) {
  20000. var k = 1 - t;
  20001. return k * k * p;
  20002. }
  20003. function b2p1( t, p ) {
  20004. return 2 * ( 1 - t ) * t * p;
  20005. }
  20006. function b2p2( t, p ) {
  20007. return t * t * p;
  20008. }
  20009. return function ( t, p0, p1, p2 ) {
  20010. return b2p0( t, p0 ) + b2p1( t, p1 ) + b2p2( t, p2 );
  20011. };
  20012. } )(),
  20013. // Cubic Bezier Functions
  20014. b3: ( function () {
  20015. function b3p0( t, p ) {
  20016. var k = 1 - t;
  20017. return k * k * k * p;
  20018. }
  20019. function b3p1( t, p ) {
  20020. var k = 1 - t;
  20021. return 3 * k * k * t * p;
  20022. }
  20023. function b3p2( t, p ) {
  20024. var k = 1 - t;
  20025. return 3 * k * t * t * p;
  20026. }
  20027. function b3p3( t, p ) {
  20028. return t * t * t * p;
  20029. }
  20030. return function ( t, p0, p1, p2, p3 ) {
  20031. return b3p0( t, p0 ) + b3p1( t, p1 ) + b3p2( t, p2 ) + b3p3( t, p3 );
  20032. };
  20033. } )()
  20034. };
  20035. // File:src/extras/core/Curve.js
  20036. /**
  20037. * @author zz85 / http://www.lab4games.net/zz85/blog
  20038. * Extensible curve object
  20039. *
  20040. * Some common of Curve methods
  20041. * .getPoint(t), getTangent(t)
  20042. * .getPointAt(u), getTagentAt(u)
  20043. * .getPoints(), .getSpacedPoints()
  20044. * .getLength()
  20045. * .updateArcLengths()
  20046. *
  20047. * This following classes subclasses THREE.Curve:
  20048. *
  20049. * -- 2d classes --
  20050. * THREE.LineCurve
  20051. * THREE.QuadraticBezierCurve
  20052. * THREE.CubicBezierCurve
  20053. * THREE.SplineCurve
  20054. * THREE.ArcCurve
  20055. * THREE.EllipseCurve
  20056. *
  20057. * -- 3d classes --
  20058. * THREE.LineCurve3
  20059. * THREE.QuadraticBezierCurve3
  20060. * THREE.CubicBezierCurve3
  20061. * THREE.SplineCurve3
  20062. * THREE.ClosedSplineCurve3
  20063. *
  20064. * A series of curves can be represented as a THREE.CurvePath
  20065. *
  20066. **/
  20067. /**************************************************************
  20068. * Abstract Curve base class
  20069. **************************************************************/
  20070. THREE.Curve = function () {
  20071. };
  20072. THREE.Curve.prototype = {
  20073. constructor: THREE.Curve,
  20074. // Virtual base class method to overwrite and implement in subclasses
  20075. // - t [0 .. 1]
  20076. getPoint: function ( t ) {
  20077. console.warn( "THREE.Curve: Warning, getPoint() not implemented!" );
  20078. return null;
  20079. },
  20080. // Get point at relative position in curve according to arc length
  20081. // - u [0 .. 1]
  20082. getPointAt: function ( u ) {
  20083. var t = this.getUtoTmapping( u );
  20084. return this.getPoint( t );
  20085. },
  20086. // Get sequence of points using getPoint( t )
  20087. getPoints: function ( divisions ) {
  20088. if ( ! divisions ) divisions = 5;
  20089. var d, pts = [];
  20090. for ( d = 0; d <= divisions; d ++ ) {
  20091. pts.push( this.getPoint( d / divisions ) );
  20092. }
  20093. return pts;
  20094. },
  20095. // Get sequence of points using getPointAt( u )
  20096. getSpacedPoints: function ( divisions ) {
  20097. if ( ! divisions ) divisions = 5;
  20098. var d, pts = [];
  20099. for ( d = 0; d <= divisions; d ++ ) {
  20100. pts.push( this.getPointAt( d / divisions ) );
  20101. }
  20102. return pts;
  20103. },
  20104. // Get total curve arc length
  20105. getLength: function () {
  20106. var lengths = this.getLengths();
  20107. return lengths[ lengths.length - 1 ];
  20108. },
  20109. // Get list of cumulative segment lengths
  20110. getLengths: function ( divisions ) {
  20111. if ( ! divisions ) divisions = ( this.__arcLengthDivisions ) ? ( this.__arcLengthDivisions ) : 200;
  20112. if ( this.cacheArcLengths
  20113. && ( this.cacheArcLengths.length === divisions + 1 )
  20114. && ! this.needsUpdate ) {
  20115. //console.log( "cached", this.cacheArcLengths );
  20116. return this.cacheArcLengths;
  20117. }
  20118. this.needsUpdate = false;
  20119. var cache = [];
  20120. var current, last = this.getPoint( 0 );
  20121. var p, sum = 0;
  20122. cache.push( 0 );
  20123. for ( p = 1; p <= divisions; p ++ ) {
  20124. current = this.getPoint ( p / divisions );
  20125. sum += current.distanceTo( last );
  20126. cache.push( sum );
  20127. last = current;
  20128. }
  20129. this.cacheArcLengths = cache;
  20130. return cache; // { sums: cache, sum:sum }; Sum is in the last element.
  20131. },
  20132. updateArcLengths: function() {
  20133. this.needsUpdate = true;
  20134. this.getLengths();
  20135. },
  20136. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  20137. getUtoTmapping: function ( u, distance ) {
  20138. var arcLengths = this.getLengths();
  20139. var i = 0, il = arcLengths.length;
  20140. var targetArcLength; // The targeted u distance value to get
  20141. if ( distance ) {
  20142. targetArcLength = distance;
  20143. } else {
  20144. targetArcLength = u * arcLengths[ il - 1 ];
  20145. }
  20146. //var time = Date.now();
  20147. // binary search for the index with largest value smaller than target u distance
  20148. var low = 0, high = il - 1, comparison;
  20149. while ( low <= high ) {
  20150. 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
  20151. comparison = arcLengths[ i ] - targetArcLength;
  20152. if ( comparison < 0 ) {
  20153. low = i + 1;
  20154. } else if ( comparison > 0 ) {
  20155. high = i - 1;
  20156. } else {
  20157. high = i;
  20158. break;
  20159. // DONE
  20160. }
  20161. }
  20162. i = high;
  20163. //console.log('b' , i, low, high, Date.now()- time);
  20164. if ( arcLengths[ i ] === targetArcLength ) {
  20165. var t = i / ( il - 1 );
  20166. return t;
  20167. }
  20168. // we could get finer grain at lengths, or use simple interpolation between two points
  20169. var lengthBefore = arcLengths[ i ];
  20170. var lengthAfter = arcLengths[ i + 1 ];
  20171. var segmentLength = lengthAfter - lengthBefore;
  20172. // determine where we are between the 'before' and 'after' points
  20173. var segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  20174. // add that fractional amount to t
  20175. var t = ( i + segmentFraction ) / ( il - 1 );
  20176. return t;
  20177. },
  20178. // Returns a unit vector tangent at t
  20179. // In case any sub curve does not implement its tangent derivation,
  20180. // 2 points a small delta apart will be used to find its gradient
  20181. // which seems to give a reasonable approximation
  20182. getTangent: function( t ) {
  20183. var delta = 0.0001;
  20184. var t1 = t - delta;
  20185. var t2 = t + delta;
  20186. // Capping in case of danger
  20187. if ( t1 < 0 ) t1 = 0;
  20188. if ( t2 > 1 ) t2 = 1;
  20189. var pt1 = this.getPoint( t1 );
  20190. var pt2 = this.getPoint( t2 );
  20191. var vec = pt2.clone().sub( pt1 );
  20192. return vec.normalize();
  20193. },
  20194. getTangentAt: function ( u ) {
  20195. var t = this.getUtoTmapping( u );
  20196. return this.getTangent( t );
  20197. }
  20198. };
  20199. // TODO: Transformation for Curves?
  20200. /**************************************************************
  20201. * 3D Curves
  20202. **************************************************************/
  20203. // A Factory method for creating new curve subclasses
  20204. THREE.Curve.create = function ( constructor, getPointFunc ) {
  20205. constructor.prototype = Object.create( THREE.Curve.prototype );
  20206. constructor.prototype.constructor = constructor;
  20207. constructor.prototype.getPoint = getPointFunc;
  20208. return constructor;
  20209. };
  20210. // File:src/extras/core/CurvePath.js
  20211. /**
  20212. * @author zz85 / http://www.lab4games.net/zz85/blog
  20213. *
  20214. **/
  20215. /**************************************************************
  20216. * Curved Path - a curve path is simply a array of connected
  20217. * curves, but retains the api of a curve
  20218. **************************************************************/
  20219. THREE.CurvePath = function () {
  20220. this.curves = [];
  20221. this.autoClose = false; // Automatically closes the path
  20222. };
  20223. THREE.CurvePath.prototype = Object.create( THREE.Curve.prototype );
  20224. THREE.CurvePath.prototype.constructor = THREE.CurvePath;
  20225. THREE.CurvePath.prototype.add = function ( curve ) {
  20226. this.curves.push( curve );
  20227. };
  20228. /*
  20229. THREE.CurvePath.prototype.checkConnection = function() {
  20230. // TODO
  20231. // If the ending of curve is not connected to the starting
  20232. // or the next curve, then, this is not a real path
  20233. };
  20234. */
  20235. THREE.CurvePath.prototype.closePath = function() {
  20236. // TODO Test
  20237. // and verify for vector3 (needs to implement equals)
  20238. // Add a line curve if start and end of lines are not connected
  20239. var startPoint = this.curves[ 0 ].getPoint( 0 );
  20240. var endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
  20241. if ( ! startPoint.equals( endPoint ) ) {
  20242. this.curves.push( new THREE.LineCurve( endPoint, startPoint ) );
  20243. }
  20244. };
  20245. // To get accurate point with reference to
  20246. // entire path distance at time t,
  20247. // following has to be done:
  20248. // 1. Length of each sub path have to be known
  20249. // 2. Locate and identify type of curve
  20250. // 3. Get t for the curve
  20251. // 4. Return curve.getPointAt(t')
  20252. THREE.CurvePath.prototype.getPoint = function( t ) {
  20253. var d = t * this.getLength();
  20254. var curveLengths = this.getCurveLengths();
  20255. var i = 0;
  20256. // To think about boundaries points.
  20257. while ( i < curveLengths.length ) {
  20258. if ( curveLengths[ i ] >= d ) {
  20259. var diff = curveLengths[ i ] - d;
  20260. var curve = this.curves[ i ];
  20261. var u = 1 - diff / curve.getLength();
  20262. return curve.getPointAt( u );
  20263. }
  20264. i ++;
  20265. }
  20266. return null;
  20267. // loop where sum != 0, sum > d , sum+1 <d
  20268. };
  20269. /*
  20270. THREE.CurvePath.prototype.getTangent = function( t ) {
  20271. };
  20272. */
  20273. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  20274. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  20275. // getPoint() depends on getLength
  20276. THREE.CurvePath.prototype.getLength = function() {
  20277. var lens = this.getCurveLengths();
  20278. return lens[ lens.length - 1 ];
  20279. };
  20280. // Compute lengths and cache them
  20281. // We cannot overwrite getLengths() because UtoT mapping uses it.
  20282. THREE.CurvePath.prototype.getCurveLengths = function() {
  20283. // We use cache values if curves and cache array are same length
  20284. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  20285. return this.cacheLengths;
  20286. }
  20287. // Get length of sub-curve
  20288. // Push sums into cached array
  20289. var lengths = [], sums = 0;
  20290. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  20291. sums += this.curves[ i ].getLength();
  20292. lengths.push( sums );
  20293. }
  20294. this.cacheLengths = lengths;
  20295. return lengths;
  20296. };
  20297. /**************************************************************
  20298. * Create Geometries Helpers
  20299. **************************************************************/
  20300. /// Generate geometry from path points (for Line or Points objects)
  20301. THREE.CurvePath.prototype.createPointsGeometry = function( divisions ) {
  20302. var pts = this.getPoints( divisions );
  20303. return this.createGeometry( pts );
  20304. };
  20305. // Generate geometry from equidistant sampling along the path
  20306. THREE.CurvePath.prototype.createSpacedPointsGeometry = function( divisions ) {
  20307. var pts = this.getSpacedPoints( divisions );
  20308. return this.createGeometry( pts );
  20309. };
  20310. THREE.CurvePath.prototype.createGeometry = function( points ) {
  20311. var geometry = new THREE.Geometry();
  20312. for ( var i = 0, l = points.length; i < l; i ++ ) {
  20313. var point = points[ i ];
  20314. geometry.vertices.push( new THREE.Vector3( point.x, point.y, point.z || 0 ) );
  20315. }
  20316. return geometry;
  20317. };
  20318. // File:src/extras/core/Font.js
  20319. /**
  20320. * @author zz85 / http://www.lab4games.net/zz85/blog
  20321. * @author mrdoob / http://mrdoob.com/
  20322. */
  20323. THREE.Font = function ( data ) {
  20324. this.data = data;
  20325. };
  20326. THREE.Font.prototype = {
  20327. constructor: THREE.Font,
  20328. generateShapes: function ( text, size, divisions ) {
  20329. function createPaths( text ) {
  20330. var chars = String( text ).split( '' );
  20331. var scale = size / data.resolution;
  20332. var offset = 0;
  20333. var paths = [];
  20334. for ( var i = 0; i < chars.length; i ++ ) {
  20335. var ret = createPath( chars[ i ], scale, offset );
  20336. offset += ret.offset;
  20337. paths.push( ret.path );
  20338. }
  20339. return paths;
  20340. }
  20341. function createPath( c, scale, offset ) {
  20342. var glyph = data.glyphs[ c ] || data.glyphs[ '?' ];
  20343. if ( ! glyph ) return;
  20344. var path = new THREE.Path();
  20345. var pts = [], b2 = THREE.ShapeUtils.b2, b3 = THREE.ShapeUtils.b3;
  20346. var x, y, cpx, cpy, cpx0, cpy0, cpx1, cpy1, cpx2, cpy2, laste;
  20347. if ( glyph.o ) {
  20348. var outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) );
  20349. for ( var i = 0, l = outline.length; i < l; ) {
  20350. var action = outline[ i ++ ];
  20351. switch ( action ) {
  20352. case 'm': // moveTo
  20353. x = outline[ i ++ ] * scale + offset;
  20354. y = outline[ i ++ ] * scale;
  20355. path.moveTo( x, y );
  20356. break;
  20357. case 'l': // lineTo
  20358. x = outline[ i ++ ] * scale + offset;
  20359. y = outline[ i ++ ] * scale;
  20360. path.lineTo( x, y );
  20361. break;
  20362. case 'q': // quadraticCurveTo
  20363. cpx = outline[ i ++ ] * scale + offset;
  20364. cpy = outline[ i ++ ] * scale;
  20365. cpx1 = outline[ i ++ ] * scale + offset;
  20366. cpy1 = outline[ i ++ ] * scale;
  20367. path.quadraticCurveTo( cpx1, cpy1, cpx, cpy );
  20368. laste = pts[ pts.length - 1 ];
  20369. if ( laste ) {
  20370. cpx0 = laste.x;
  20371. cpy0 = laste.y;
  20372. for ( var i2 = 1; i2 <= divisions; i2 ++ ) {
  20373. var t = i2 / divisions;
  20374. b2( t, cpx0, cpx1, cpx );
  20375. b2( t, cpy0, cpy1, cpy );
  20376. }
  20377. }
  20378. break;
  20379. case 'b': // bezierCurveTo
  20380. cpx = outline[ i ++ ] * scale + offset;
  20381. cpy = outline[ i ++ ] * scale;
  20382. cpx1 = outline[ i ++ ] * scale + offset;
  20383. cpy1 = outline[ i ++ ] * scale;
  20384. cpx2 = outline[ i ++ ] * scale + offset;
  20385. cpy2 = outline[ i ++ ] * scale;
  20386. path.bezierCurveTo( cpx1, cpy1, cpx2, cpy2, cpx, cpy );
  20387. laste = pts[ pts.length - 1 ];
  20388. if ( laste ) {
  20389. cpx0 = laste.x;
  20390. cpy0 = laste.y;
  20391. for ( var i2 = 1; i2 <= divisions; i2 ++ ) {
  20392. var t = i2 / divisions;
  20393. b3( t, cpx0, cpx1, cpx2, cpx );
  20394. b3( t, cpy0, cpy1, cpy2, cpy );
  20395. }
  20396. }
  20397. break;
  20398. }
  20399. }
  20400. }
  20401. return { offset: glyph.ha * scale, path: path };
  20402. }
  20403. //
  20404. if ( size === undefined ) size = 100;
  20405. if ( divisions === undefined ) divisions = 4;
  20406. var data = this.data;
  20407. var paths = createPaths( text );
  20408. var shapes = [];
  20409. for ( var p = 0, pl = paths.length; p < pl; p ++ ) {
  20410. Array.prototype.push.apply( shapes, paths[ p ].toShapes() );
  20411. }
  20412. return shapes;
  20413. }
  20414. };
  20415. // File:src/extras/core/Path.js
  20416. /**
  20417. * @author zz85 / http://www.lab4games.net/zz85/blog
  20418. * Creates free form 2d path using series of points, lines or curves.
  20419. *
  20420. **/
  20421. THREE.Path = function ( points ) {
  20422. THREE.CurvePath.call( this );
  20423. this.actions = [];
  20424. if ( points ) {
  20425. this.fromPoints( points );
  20426. }
  20427. };
  20428. THREE.Path.prototype = Object.create( THREE.CurvePath.prototype );
  20429. THREE.Path.prototype.constructor = THREE.Path;
  20430. // TODO Clean up PATH API
  20431. // Create path using straight lines to connect all points
  20432. // - vectors: array of Vector2
  20433. THREE.Path.prototype.fromPoints = function ( vectors ) {
  20434. this.moveTo( vectors[ 0 ].x, vectors[ 0 ].y );
  20435. for ( var i = 1, l = vectors.length; i < l; i ++ ) {
  20436. this.lineTo( vectors[ i ].x, vectors[ i ].y );
  20437. }
  20438. };
  20439. // startPath() endPath()?
  20440. THREE.Path.prototype.moveTo = function ( x, y ) {
  20441. this.actions.push( { action: 'moveTo', args: [ x, y ] } );
  20442. };
  20443. THREE.Path.prototype.lineTo = function ( x, y ) {
  20444. var lastargs = this.actions[ this.actions.length - 1 ].args;
  20445. var x0 = lastargs[ lastargs.length - 2 ];
  20446. var y0 = lastargs[ lastargs.length - 1 ];
  20447. var curve = new THREE.LineCurve( new THREE.Vector2( x0, y0 ), new THREE.Vector2( x, y ) );
  20448. this.curves.push( curve );
  20449. this.actions.push( { action: 'lineTo', args: [ x, y ] } );
  20450. };
  20451. THREE.Path.prototype.quadraticCurveTo = function( aCPx, aCPy, aX, aY ) {
  20452. var lastargs = this.actions[ this.actions.length - 1 ].args;
  20453. var x0 = lastargs[ lastargs.length - 2 ];
  20454. var y0 = lastargs[ lastargs.length - 1 ];
  20455. var curve = new THREE.QuadraticBezierCurve(
  20456. new THREE.Vector2( x0, y0 ),
  20457. new THREE.Vector2( aCPx, aCPy ),
  20458. new THREE.Vector2( aX, aY )
  20459. );
  20460. this.curves.push( curve );
  20461. this.actions.push( { action: 'quadraticCurveTo', args: [ aCPx, aCPy, aX, aY ] } );
  20462. };
  20463. THREE.Path.prototype.bezierCurveTo = function( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  20464. var lastargs = this.actions[ this.actions.length - 1 ].args;
  20465. var x0 = lastargs[ lastargs.length - 2 ];
  20466. var y0 = lastargs[ lastargs.length - 1 ];
  20467. var curve = new THREE.CubicBezierCurve(
  20468. new THREE.Vector2( x0, y0 ),
  20469. new THREE.Vector2( aCP1x, aCP1y ),
  20470. new THREE.Vector2( aCP2x, aCP2y ),
  20471. new THREE.Vector2( aX, aY )
  20472. );
  20473. this.curves.push( curve );
  20474. this.actions.push( { action: 'bezierCurveTo', args: [ aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ] } );
  20475. };
  20476. THREE.Path.prototype.splineThru = function( pts /*Array of Vector*/ ) {
  20477. var args = Array.prototype.slice.call( arguments );
  20478. var lastargs = this.actions[ this.actions.length - 1 ].args;
  20479. var x0 = lastargs[ lastargs.length - 2 ];
  20480. var y0 = lastargs[ lastargs.length - 1 ];
  20481. var npts = [ new THREE.Vector2( x0, y0 ) ];
  20482. Array.prototype.push.apply( npts, pts );
  20483. var curve = new THREE.SplineCurve( npts );
  20484. this.curves.push( curve );
  20485. this.actions.push( { action: 'splineThru', args: args } );
  20486. };
  20487. // FUTURE: Change the API or follow canvas API?
  20488. THREE.Path.prototype.arc = function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  20489. var lastargs = this.actions[ this.actions.length - 1 ].args;
  20490. var x0 = lastargs[ lastargs.length - 2 ];
  20491. var y0 = lastargs[ lastargs.length - 1 ];
  20492. this.absarc( aX + x0, aY + y0, aRadius,
  20493. aStartAngle, aEndAngle, aClockwise );
  20494. };
  20495. THREE.Path.prototype.absarc = function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  20496. this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  20497. };
  20498. THREE.Path.prototype.ellipse = function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  20499. var lastargs = this.actions[ this.actions.length - 1 ].args;
  20500. var x0 = lastargs[ lastargs.length - 2 ];
  20501. var y0 = lastargs[ lastargs.length - 1 ];
  20502. this.absellipse( aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  20503. };
  20504. THREE.Path.prototype.absellipse = function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  20505. var args = [
  20506. aX, aY,
  20507. xRadius, yRadius,
  20508. aStartAngle, aEndAngle,
  20509. aClockwise,
  20510. aRotation || 0 // aRotation is optional.
  20511. ];
  20512. var curve = new THREE.EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  20513. this.curves.push( curve );
  20514. var lastPoint = curve.getPoint( 1 );
  20515. args.push( lastPoint.x );
  20516. args.push( lastPoint.y );
  20517. this.actions.push( { action: 'ellipse', args: args } );
  20518. };
  20519. THREE.Path.prototype.getSpacedPoints = function ( divisions ) {
  20520. if ( ! divisions ) divisions = 40;
  20521. var points = [];
  20522. for ( var i = 0; i < divisions; i ++ ) {
  20523. points.push( this.getPoint( i / divisions ) );
  20524. //if ( !this.getPoint( i / divisions ) ) throw "DIE";
  20525. }
  20526. if ( this.autoClose ) {
  20527. points.push( points[ 0 ] );
  20528. }
  20529. return points;
  20530. };
  20531. /* Return an array of vectors based on contour of the path */
  20532. THREE.Path.prototype.getPoints = function( divisions ) {
  20533. divisions = divisions || 12;
  20534. var b2 = THREE.ShapeUtils.b2;
  20535. var b3 = THREE.ShapeUtils.b3;
  20536. var points = [];
  20537. var cpx, cpy, cpx2, cpy2, cpx1, cpy1, cpx0, cpy0,
  20538. laste, tx, ty;
  20539. for ( var i = 0, l = this.actions.length; i < l; i ++ ) {
  20540. var item = this.actions[ i ];
  20541. var action = item.action;
  20542. var args = item.args;
  20543. switch ( action ) {
  20544. case 'moveTo':
  20545. points.push( new THREE.Vector2( args[ 0 ], args[ 1 ] ) );
  20546. break;
  20547. case 'lineTo':
  20548. points.push( new THREE.Vector2( args[ 0 ], args[ 1 ] ) );
  20549. break;
  20550. case 'quadraticCurveTo':
  20551. cpx = args[ 2 ];
  20552. cpy = args[ 3 ];
  20553. cpx1 = args[ 0 ];
  20554. cpy1 = args[ 1 ];
  20555. if ( points.length > 0 ) {
  20556. laste = points[ points.length - 1 ];
  20557. cpx0 = laste.x;
  20558. cpy0 = laste.y;
  20559. } else {
  20560. laste = this.actions[ i - 1 ].args;
  20561. cpx0 = laste[ laste.length - 2 ];
  20562. cpy0 = laste[ laste.length - 1 ];
  20563. }
  20564. for ( var j = 1; j <= divisions; j ++ ) {
  20565. var t = j / divisions;
  20566. tx = b2( t, cpx0, cpx1, cpx );
  20567. ty = b2( t, cpy0, cpy1, cpy );
  20568. points.push( new THREE.Vector2( tx, ty ) );
  20569. }
  20570. break;
  20571. case 'bezierCurveTo':
  20572. cpx = args[ 4 ];
  20573. cpy = args[ 5 ];
  20574. cpx1 = args[ 0 ];
  20575. cpy1 = args[ 1 ];
  20576. cpx2 = args[ 2 ];
  20577. cpy2 = args[ 3 ];
  20578. if ( points.length > 0 ) {
  20579. laste = points[ points.length - 1 ];
  20580. cpx0 = laste.x;
  20581. cpy0 = laste.y;
  20582. } else {
  20583. laste = this.actions[ i - 1 ].args;
  20584. cpx0 = laste[ laste.length - 2 ];
  20585. cpy0 = laste[ laste.length - 1 ];
  20586. }
  20587. for ( var j = 1; j <= divisions; j ++ ) {
  20588. var t = j / divisions;
  20589. tx = b3( t, cpx0, cpx1, cpx2, cpx );
  20590. ty = b3( t, cpy0, cpy1, cpy2, cpy );
  20591. points.push( new THREE.Vector2( tx, ty ) );
  20592. }
  20593. break;
  20594. case 'splineThru':
  20595. laste = this.actions[ i - 1 ].args;
  20596. var last = new THREE.Vector2( laste[ laste.length - 2 ], laste[ laste.length - 1 ] );
  20597. var spts = [ last ];
  20598. var n = divisions * args[ 0 ].length;
  20599. spts = spts.concat( args[ 0 ] );
  20600. var spline = new THREE.SplineCurve( spts );
  20601. for ( var j = 1; j <= n; j ++ ) {
  20602. points.push( spline.getPointAt( j / n ) );
  20603. }
  20604. break;
  20605. case 'arc':
  20606. var aX = args[ 0 ], aY = args[ 1 ],
  20607. aRadius = args[ 2 ],
  20608. aStartAngle = args[ 3 ], aEndAngle = args[ 4 ],
  20609. aClockwise = !! args[ 5 ];
  20610. var deltaAngle = aEndAngle - aStartAngle;
  20611. var angle;
  20612. var tdivisions = divisions * 2;
  20613. for ( var j = 1; j <= tdivisions; j ++ ) {
  20614. var t = j / tdivisions;
  20615. if ( ! aClockwise ) {
  20616. t = 1 - t;
  20617. }
  20618. angle = aStartAngle + t * deltaAngle;
  20619. tx = aX + aRadius * Math.cos( angle );
  20620. ty = aY + aRadius * Math.sin( angle );
  20621. //console.log('t', t, 'angle', angle, 'tx', tx, 'ty', ty);
  20622. points.push( new THREE.Vector2( tx, ty ) );
  20623. }
  20624. //console.log(points);
  20625. break;
  20626. case 'ellipse':
  20627. var aX = args[ 0 ], aY = args[ 1 ],
  20628. xRadius = args[ 2 ],
  20629. yRadius = args[ 3 ],
  20630. aStartAngle = args[ 4 ], aEndAngle = args[ 5 ],
  20631. aClockwise = !! args[ 6 ],
  20632. aRotation = args[ 7 ];
  20633. var deltaAngle = aEndAngle - aStartAngle;
  20634. var angle;
  20635. var tdivisions = divisions * 2;
  20636. var cos, sin;
  20637. if ( aRotation !== 0 ) {
  20638. cos = Math.cos( aRotation );
  20639. sin = Math.sin( aRotation );
  20640. }
  20641. for ( var j = 1; j <= tdivisions; j ++ ) {
  20642. var t = j / tdivisions;
  20643. if ( ! aClockwise ) {
  20644. t = 1 - t;
  20645. }
  20646. angle = aStartAngle + t * deltaAngle;
  20647. tx = aX + xRadius * Math.cos( angle );
  20648. ty = aY + yRadius * Math.sin( angle );
  20649. if ( aRotation !== 0 ) {
  20650. var x = tx, y = ty;
  20651. // Rotate the point about the center of the ellipse.
  20652. tx = ( x - aX ) * cos - ( y - aY ) * sin + aX;
  20653. ty = ( x - aX ) * sin + ( y - aY ) * cos + aY;
  20654. }
  20655. //console.log('t', t, 'angle', angle, 'tx', tx, 'ty', ty);
  20656. points.push( new THREE.Vector2( tx, ty ) );
  20657. }
  20658. //console.log(points);
  20659. break;
  20660. } // end switch
  20661. }
  20662. // Normalize to remove the closing point by default.
  20663. var lastPoint = points[ points.length - 1 ];
  20664. if ( Math.abs( lastPoint.x - points[ 0 ].x ) < Number.EPSILON &&
  20665. Math.abs( lastPoint.y - points[ 0 ].y ) < Number.EPSILON )
  20666. points.splice( points.length - 1, 1 );
  20667. if ( this.autoClose ) {
  20668. points.push( points[ 0 ] );
  20669. }
  20670. return points;
  20671. };
  20672. //
  20673. // Breaks path into shapes
  20674. //
  20675. // Assumptions (if parameter isCCW==true the opposite holds):
  20676. // - solid shapes are defined clockwise (CW)
  20677. // - holes are defined counterclockwise (CCW)
  20678. //
  20679. // If parameter noHoles==true:
  20680. // - all subPaths are regarded as solid shapes
  20681. // - definition order CW/CCW has no relevance
  20682. //
  20683. THREE.Path.prototype.toShapes = function( isCCW, noHoles ) {
  20684. function extractSubpaths( inActions ) {
  20685. var subPaths = [], lastPath = new THREE.Path();
  20686. for ( var i = 0, l = inActions.length; i < l; i ++ ) {
  20687. var item = inActions[ i ];
  20688. var args = item.args;
  20689. var action = item.action;
  20690. if ( action === 'moveTo' ) {
  20691. if ( lastPath.actions.length !== 0 ) {
  20692. subPaths.push( lastPath );
  20693. lastPath = new THREE.Path();
  20694. }
  20695. }
  20696. lastPath[ action ].apply( lastPath, args );
  20697. }
  20698. if ( lastPath.actions.length !== 0 ) {
  20699. subPaths.push( lastPath );
  20700. }
  20701. // console.log(subPaths);
  20702. return subPaths;
  20703. }
  20704. function toShapesNoHoles( inSubpaths ) {
  20705. var shapes = [];
  20706. for ( var i = 0, l = inSubpaths.length; i < l; i ++ ) {
  20707. var tmpPath = inSubpaths[ i ];
  20708. var tmpShape = new THREE.Shape();
  20709. tmpShape.actions = tmpPath.actions;
  20710. tmpShape.curves = tmpPath.curves;
  20711. shapes.push( tmpShape );
  20712. }
  20713. //console.log("shape", shapes);
  20714. return shapes;
  20715. }
  20716. function isPointInsidePolygon( inPt, inPolygon ) {
  20717. var polyLen = inPolygon.length;
  20718. // inPt on polygon contour => immediate success or
  20719. // toggling of inside/outside at every single! intersection point of an edge
  20720. // with the horizontal line through inPt, left of inPt
  20721. // not counting lowerY endpoints of edges and whole edges on that line
  20722. var inside = false;
  20723. for ( var p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  20724. var edgeLowPt = inPolygon[ p ];
  20725. var edgeHighPt = inPolygon[ q ];
  20726. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  20727. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  20728. if ( Math.abs( edgeDy ) > Number.EPSILON ) {
  20729. // not parallel
  20730. if ( edgeDy < 0 ) {
  20731. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  20732. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  20733. }
  20734. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  20735. if ( inPt.y === edgeLowPt.y ) {
  20736. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  20737. // continue; // no intersection or edgeLowPt => doesn't count !!!
  20738. } else {
  20739. var perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y );
  20740. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  20741. if ( perpEdge < 0 ) continue;
  20742. inside = ! inside; // true intersection left of inPt
  20743. }
  20744. } else {
  20745. // parallel or collinear
  20746. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  20747. // edge lies on the same horizontal line as inPt
  20748. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  20749. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  20750. // continue;
  20751. }
  20752. }
  20753. return inside;
  20754. }
  20755. var isClockWise = THREE.ShapeUtils.isClockWise;
  20756. var subPaths = extractSubpaths( this.actions );
  20757. if ( subPaths.length === 0 ) return [];
  20758. if ( noHoles === true ) return toShapesNoHoles( subPaths );
  20759. var solid, tmpPath, tmpShape, shapes = [];
  20760. if ( subPaths.length === 1 ) {
  20761. tmpPath = subPaths[ 0 ];
  20762. tmpShape = new THREE.Shape();
  20763. tmpShape.actions = tmpPath.actions;
  20764. tmpShape.curves = tmpPath.curves;
  20765. shapes.push( tmpShape );
  20766. return shapes;
  20767. }
  20768. var holesFirst = ! isClockWise( subPaths[ 0 ].getPoints() );
  20769. holesFirst = isCCW ? ! holesFirst : holesFirst;
  20770. // console.log("Holes first", holesFirst);
  20771. var betterShapeHoles = [];
  20772. var newShapes = [];
  20773. var newShapeHoles = [];
  20774. var mainIdx = 0;
  20775. var tmpPoints;
  20776. newShapes[ mainIdx ] = undefined;
  20777. newShapeHoles[ mainIdx ] = [];
  20778. for ( var i = 0, l = subPaths.length; i < l; i ++ ) {
  20779. tmpPath = subPaths[ i ];
  20780. tmpPoints = tmpPath.getPoints();
  20781. solid = isClockWise( tmpPoints );
  20782. solid = isCCW ? ! solid : solid;
  20783. if ( solid ) {
  20784. if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) mainIdx ++;
  20785. newShapes[ mainIdx ] = { s: new THREE.Shape(), p: tmpPoints };
  20786. newShapes[ mainIdx ].s.actions = tmpPath.actions;
  20787. newShapes[ mainIdx ].s.curves = tmpPath.curves;
  20788. if ( holesFirst ) mainIdx ++;
  20789. newShapeHoles[ mainIdx ] = [];
  20790. //console.log('cw', i);
  20791. } else {
  20792. newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } );
  20793. //console.log('ccw', i);
  20794. }
  20795. }
  20796. // only Holes? -> probably all Shapes with wrong orientation
  20797. if ( ! newShapes[ 0 ] ) return toShapesNoHoles( subPaths );
  20798. if ( newShapes.length > 1 ) {
  20799. var ambiguous = false;
  20800. var toChange = [];
  20801. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  20802. betterShapeHoles[ sIdx ] = [];
  20803. }
  20804. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  20805. var sho = newShapeHoles[ sIdx ];
  20806. for ( var hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  20807. var ho = sho[ hIdx ];
  20808. var hole_unassigned = true;
  20809. for ( var s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  20810. if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
  20811. if ( sIdx !== s2Idx ) toChange.push( { froms: sIdx, tos: s2Idx, hole: hIdx } );
  20812. if ( hole_unassigned ) {
  20813. hole_unassigned = false;
  20814. betterShapeHoles[ s2Idx ].push( ho );
  20815. } else {
  20816. ambiguous = true;
  20817. }
  20818. }
  20819. }
  20820. if ( hole_unassigned ) {
  20821. betterShapeHoles[ sIdx ].push( ho );
  20822. }
  20823. }
  20824. }
  20825. // console.log("ambiguous: ", ambiguous);
  20826. if ( toChange.length > 0 ) {
  20827. // console.log("to change: ", toChange);
  20828. if ( ! ambiguous ) newShapeHoles = betterShapeHoles;
  20829. }
  20830. }
  20831. var tmpHoles;
  20832. for ( var i = 0, il = newShapes.length; i < il; i ++ ) {
  20833. tmpShape = newShapes[ i ].s;
  20834. shapes.push( tmpShape );
  20835. tmpHoles = newShapeHoles[ i ];
  20836. for ( var j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  20837. tmpShape.holes.push( tmpHoles[ j ].h );
  20838. }
  20839. }
  20840. //console.log("shape", shapes);
  20841. return shapes;
  20842. };
  20843. // File:src/extras/core/Shape.js
  20844. /**
  20845. * @author zz85 / http://www.lab4games.net/zz85/blog
  20846. * Defines a 2d shape plane using paths.
  20847. **/
  20848. // STEP 1 Create a path.
  20849. // STEP 2 Turn path into shape.
  20850. // STEP 3 ExtrudeGeometry takes in Shape/Shapes
  20851. // STEP 3a - Extract points from each shape, turn to vertices
  20852. // STEP 3b - Triangulate each shape, add faces.
  20853. THREE.Shape = function () {
  20854. THREE.Path.apply( this, arguments );
  20855. this.holes = [];
  20856. };
  20857. THREE.Shape.prototype = Object.create( THREE.Path.prototype );
  20858. THREE.Shape.prototype.constructor = THREE.Shape;
  20859. // Convenience method to return ExtrudeGeometry
  20860. THREE.Shape.prototype.extrude = function ( options ) {
  20861. return new THREE.ExtrudeGeometry( this, options );
  20862. };
  20863. // Convenience method to return ShapeGeometry
  20864. THREE.Shape.prototype.makeGeometry = function ( options ) {
  20865. return new THREE.ShapeGeometry( this, options );
  20866. };
  20867. // Get points of holes
  20868. THREE.Shape.prototype.getPointsHoles = function ( divisions ) {
  20869. var holesPts = [];
  20870. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  20871. holesPts[ i ] = this.holes[ i ].getPoints( divisions );
  20872. }
  20873. return holesPts;
  20874. };
  20875. // Get points of shape and holes (keypoints based on segments parameter)
  20876. THREE.Shape.prototype.extractAllPoints = function ( divisions ) {
  20877. return {
  20878. shape: this.getPoints( divisions ),
  20879. holes: this.getPointsHoles( divisions )
  20880. };
  20881. };
  20882. THREE.Shape.prototype.extractPoints = function ( divisions ) {
  20883. return this.extractAllPoints( divisions );
  20884. };
  20885. // File:src/extras/curves/LineCurve.js
  20886. /**************************************************************
  20887. * Line
  20888. **************************************************************/
  20889. THREE.LineCurve = function ( v1, v2 ) {
  20890. this.v1 = v1;
  20891. this.v2 = v2;
  20892. };
  20893. THREE.LineCurve.prototype = Object.create( THREE.Curve.prototype );
  20894. THREE.LineCurve.prototype.constructor = THREE.LineCurve;
  20895. THREE.LineCurve.prototype.getPoint = function ( t ) {
  20896. var point = this.v2.clone().sub( this.v1 );
  20897. point.multiplyScalar( t ).add( this.v1 );
  20898. return point;
  20899. };
  20900. // Line curve is linear, so we can overwrite default getPointAt
  20901. THREE.LineCurve.prototype.getPointAt = function ( u ) {
  20902. return this.getPoint( u );
  20903. };
  20904. THREE.LineCurve.prototype.getTangent = function( t ) {
  20905. var tangent = this.v2.clone().sub( this.v1 );
  20906. return tangent.normalize();
  20907. };
  20908. // File:src/extras/curves/QuadraticBezierCurve.js
  20909. /**************************************************************
  20910. * Quadratic Bezier curve
  20911. **************************************************************/
  20912. THREE.QuadraticBezierCurve = function ( v0, v1, v2 ) {
  20913. this.v0 = v0;
  20914. this.v1 = v1;
  20915. this.v2 = v2;
  20916. };
  20917. THREE.QuadraticBezierCurve.prototype = Object.create( THREE.Curve.prototype );
  20918. THREE.QuadraticBezierCurve.prototype.constructor = THREE.QuadraticBezierCurve;
  20919. THREE.QuadraticBezierCurve.prototype.getPoint = function ( t ) {
  20920. var b2 = THREE.ShapeUtils.b2;
  20921. return new THREE.Vector2(
  20922. b2( t, this.v0.x, this.v1.x, this.v2.x ),
  20923. b2( t, this.v0.y, this.v1.y, this.v2.y )
  20924. );
  20925. };
  20926. THREE.QuadraticBezierCurve.prototype.getTangent = function( t ) {
  20927. var tangentQuadraticBezier = THREE.CurveUtils.tangentQuadraticBezier;
  20928. return new THREE.Vector2(
  20929. tangentQuadraticBezier( t, this.v0.x, this.v1.x, this.v2.x ),
  20930. tangentQuadraticBezier( t, this.v0.y, this.v1.y, this.v2.y )
  20931. ).normalize();
  20932. };
  20933. // File:src/extras/curves/CubicBezierCurve.js
  20934. /**************************************************************
  20935. * Cubic Bezier curve
  20936. **************************************************************/
  20937. THREE.CubicBezierCurve = function ( v0, v1, v2, v3 ) {
  20938. this.v0 = v0;
  20939. this.v1 = v1;
  20940. this.v2 = v2;
  20941. this.v3 = v3;
  20942. };
  20943. THREE.CubicBezierCurve.prototype = Object.create( THREE.Curve.prototype );
  20944. THREE.CubicBezierCurve.prototype.constructor = THREE.CubicBezierCurve;
  20945. THREE.CubicBezierCurve.prototype.getPoint = function ( t ) {
  20946. var b3 = THREE.ShapeUtils.b3;
  20947. return new THREE.Vector2(
  20948. b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x ),
  20949. b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y )
  20950. );
  20951. };
  20952. THREE.CubicBezierCurve.prototype.getTangent = function( t ) {
  20953. var tangentCubicBezier = THREE.CurveUtils.tangentCubicBezier;
  20954. return new THREE.Vector2(
  20955. tangentCubicBezier( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x ),
  20956. tangentCubicBezier( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y )
  20957. ).normalize();
  20958. };
  20959. // File:src/extras/curves/SplineCurve.js
  20960. /**************************************************************
  20961. * Spline curve
  20962. **************************************************************/
  20963. THREE.SplineCurve = function ( points /* array of Vector2 */ ) {
  20964. this.points = ( points == undefined ) ? [] : points;
  20965. };
  20966. THREE.SplineCurve.prototype = Object.create( THREE.Curve.prototype );
  20967. THREE.SplineCurve.prototype.constructor = THREE.SplineCurve;
  20968. THREE.SplineCurve.prototype.getPoint = function ( t ) {
  20969. var points = this.points;
  20970. var point = ( points.length - 1 ) * t;
  20971. var intPoint = Math.floor( point );
  20972. var weight = point - intPoint;
  20973. var point0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  20974. var point1 = points[ intPoint ];
  20975. var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  20976. var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  20977. var interpolate = THREE.CurveUtils.interpolate;
  20978. return new THREE.Vector2(
  20979. interpolate( point0.x, point1.x, point2.x, point3.x, weight ),
  20980. interpolate( point0.y, point1.y, point2.y, point3.y, weight )
  20981. );
  20982. };
  20983. // File:src/extras/curves/EllipseCurve.js
  20984. /**************************************************************
  20985. * Ellipse curve
  20986. **************************************************************/
  20987. THREE.EllipseCurve = function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  20988. this.aX = aX;
  20989. this.aY = aY;
  20990. this.xRadius = xRadius;
  20991. this.yRadius = yRadius;
  20992. this.aStartAngle = aStartAngle;
  20993. this.aEndAngle = aEndAngle;
  20994. this.aClockwise = aClockwise;
  20995. this.aRotation = aRotation || 0;
  20996. };
  20997. THREE.EllipseCurve.prototype = Object.create( THREE.Curve.prototype );
  20998. THREE.EllipseCurve.prototype.constructor = THREE.EllipseCurve;
  20999. THREE.EllipseCurve.prototype.getPoint = function ( t ) {
  21000. var deltaAngle = this.aEndAngle - this.aStartAngle;
  21001. if ( deltaAngle < 0 ) deltaAngle += Math.PI * 2;
  21002. if ( deltaAngle > Math.PI * 2 ) deltaAngle -= Math.PI * 2;
  21003. var angle;
  21004. if ( this.aClockwise === true ) {
  21005. angle = this.aEndAngle + ( 1 - t ) * ( Math.PI * 2 - deltaAngle );
  21006. } else {
  21007. angle = this.aStartAngle + t * deltaAngle;
  21008. }
  21009. var x = this.aX + this.xRadius * Math.cos( angle );
  21010. var y = this.aY + this.yRadius * Math.sin( angle );
  21011. if ( this.aRotation !== 0 ) {
  21012. var cos = Math.cos( this.aRotation );
  21013. var sin = Math.sin( this.aRotation );
  21014. var tx = x, ty = y;
  21015. // Rotate the point about the center of the ellipse.
  21016. x = ( tx - this.aX ) * cos - ( ty - this.aY ) * sin + this.aX;
  21017. y = ( tx - this.aX ) * sin + ( ty - this.aY ) * cos + this.aY;
  21018. }
  21019. return new THREE.Vector2( x, y );
  21020. };
  21021. // File:src/extras/curves/ArcCurve.js
  21022. /**************************************************************
  21023. * Arc curve
  21024. **************************************************************/
  21025. THREE.ArcCurve = function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  21026. THREE.EllipseCurve.call( this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  21027. };
  21028. THREE.ArcCurve.prototype = Object.create( THREE.EllipseCurve.prototype );
  21029. THREE.ArcCurve.prototype.constructor = THREE.ArcCurve;
  21030. // File:src/extras/curves/LineCurve3.js
  21031. /**************************************************************
  21032. * Line3D
  21033. **************************************************************/
  21034. THREE.LineCurve3 = THREE.Curve.create(
  21035. function ( v1, v2 ) {
  21036. this.v1 = v1;
  21037. this.v2 = v2;
  21038. },
  21039. function ( t ) {
  21040. var vector = new THREE.Vector3();
  21041. vector.subVectors( this.v2, this.v1 ); // diff
  21042. vector.multiplyScalar( t );
  21043. vector.add( this.v1 );
  21044. return vector;
  21045. }
  21046. );
  21047. // File:src/extras/curves/QuadraticBezierCurve3.js
  21048. /**************************************************************
  21049. * Quadratic Bezier 3D curve
  21050. **************************************************************/
  21051. THREE.QuadraticBezierCurve3 = THREE.Curve.create(
  21052. function ( v0, v1, v2 ) {
  21053. this.v0 = v0;
  21054. this.v1 = v1;
  21055. this.v2 = v2;
  21056. },
  21057. function ( t ) {
  21058. var b2 = THREE.ShapeUtils.b2;
  21059. return new THREE.Vector3(
  21060. b2( t, this.v0.x, this.v1.x, this.v2.x ),
  21061. b2( t, this.v0.y, this.v1.y, this.v2.y ),
  21062. b2( t, this.v0.z, this.v1.z, this.v2.z )
  21063. );
  21064. }
  21065. );
  21066. // File:src/extras/curves/CubicBezierCurve3.js
  21067. /**************************************************************
  21068. * Cubic Bezier 3D curve
  21069. **************************************************************/
  21070. THREE.CubicBezierCurve3 = THREE.Curve.create(
  21071. function ( v0, v1, v2, v3 ) {
  21072. this.v0 = v0;
  21073. this.v1 = v1;
  21074. this.v2 = v2;
  21075. this.v3 = v3;
  21076. },
  21077. function ( t ) {
  21078. var b3 = THREE.ShapeUtils.b3;
  21079. return new THREE.Vector3(
  21080. b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x ),
  21081. b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y ),
  21082. b3( t, this.v0.z, this.v1.z, this.v2.z, this.v3.z )
  21083. );
  21084. }
  21085. );
  21086. // File:src/extras/curves/SplineCurve3.js
  21087. /**************************************************************
  21088. * Spline 3D curve
  21089. **************************************************************/
  21090. THREE.SplineCurve3 = THREE.Curve.create(
  21091. function ( points /* array of Vector3 */ ) {
  21092. console.warn( 'THREE.SplineCurve3 will be deprecated. Please use THREE.CatmullRomCurve3' );
  21093. this.points = ( points == undefined ) ? [] : points;
  21094. },
  21095. function ( t ) {
  21096. var points = this.points;
  21097. var point = ( points.length - 1 ) * t;
  21098. var intPoint = Math.floor( point );
  21099. var weight = point - intPoint;
  21100. var point0 = points[ intPoint == 0 ? intPoint : intPoint - 1 ];
  21101. var point1 = points[ intPoint ];
  21102. var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  21103. var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  21104. var interpolate = THREE.CurveUtils.interpolate;
  21105. return new THREE.Vector3(
  21106. interpolate( point0.x, point1.x, point2.x, point3.x, weight ),
  21107. interpolate( point0.y, point1.y, point2.y, point3.y, weight ),
  21108. interpolate( point0.z, point1.z, point2.z, point3.z, weight )
  21109. );
  21110. }
  21111. );
  21112. // File:src/extras/curves/CatmullRomCurve3.js
  21113. /**
  21114. * @author zz85 https://github.com/zz85
  21115. *
  21116. * Centripetal CatmullRom Curve - which is useful for avoiding
  21117. * cusps and self-intersections in non-uniform catmull rom curves.
  21118. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  21119. *
  21120. * curve.type accepts centripetal(default), chordal and catmullrom
  21121. * curve.tension is used for catmullrom which defaults to 0.5
  21122. */
  21123. THREE.CatmullRomCurve3 = ( function() {
  21124. var
  21125. tmp = new THREE.Vector3(),
  21126. px = new CubicPoly(),
  21127. py = new CubicPoly(),
  21128. pz = new CubicPoly();
  21129. /*
  21130. Based on an optimized c++ solution in
  21131. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  21132. - http://ideone.com/NoEbVM
  21133. This CubicPoly class could be used for reusing some variables and calculations,
  21134. but for three.js curve use, it could be possible inlined and flatten into a single function call
  21135. which can be placed in CurveUtils.
  21136. */
  21137. function CubicPoly() {
  21138. }
  21139. /*
  21140. * Compute coefficients for a cubic polynomial
  21141. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  21142. * such that
  21143. * p(0) = x0, p(1) = x1
  21144. * and
  21145. * p'(0) = t0, p'(1) = t1.
  21146. */
  21147. CubicPoly.prototype.init = function( x0, x1, t0, t1 ) {
  21148. this.c0 = x0;
  21149. this.c1 = t0;
  21150. this.c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  21151. this.c3 = 2 * x0 - 2 * x1 + t0 + t1;
  21152. };
  21153. CubicPoly.prototype.initNonuniformCatmullRom = function( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  21154. // compute tangents when parameterized in [t1,t2]
  21155. var t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  21156. var t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  21157. // rescale tangents for parametrization in [0,1]
  21158. t1 *= dt1;
  21159. t2 *= dt1;
  21160. // initCubicPoly
  21161. this.init( x1, x2, t1, t2 );
  21162. };
  21163. // standard Catmull-Rom spline: interpolate between x1 and x2 with previous/following points x1/x4
  21164. CubicPoly.prototype.initCatmullRom = function( x0, x1, x2, x3, tension ) {
  21165. this.init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  21166. };
  21167. CubicPoly.prototype.calc = function( t ) {
  21168. var t2 = t * t;
  21169. var t3 = t2 * t;
  21170. return this.c0 + this.c1 * t + this.c2 * t2 + this.c3 * t3;
  21171. };
  21172. // Subclass Three.js curve
  21173. return THREE.Curve.create(
  21174. function ( p /* array of Vector3 */ ) {
  21175. this.points = p || [];
  21176. this.closed = false;
  21177. },
  21178. function ( t ) {
  21179. var points = this.points,
  21180. point, intPoint, weight, l;
  21181. l = points.length;
  21182. if ( l < 2 ) console.log( 'duh, you need at least 2 points' );
  21183. point = ( l - ( this.closed ? 0 : 1 ) ) * t;
  21184. intPoint = Math.floor( point );
  21185. weight = point - intPoint;
  21186. if ( this.closed ) {
  21187. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / points.length ) + 1 ) * points.length;
  21188. } else if ( weight === 0 && intPoint === l - 1 ) {
  21189. intPoint = l - 2;
  21190. weight = 1;
  21191. }
  21192. var p0, p1, p2, p3; // 4 points
  21193. if ( this.closed || intPoint > 0 ) {
  21194. p0 = points[ ( intPoint - 1 ) % l ];
  21195. } else {
  21196. // extrapolate first point
  21197. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  21198. p0 = tmp;
  21199. }
  21200. p1 = points[ intPoint % l ];
  21201. p2 = points[ ( intPoint + 1 ) % l ];
  21202. if ( this.closed || intPoint + 2 < l ) {
  21203. p3 = points[ ( intPoint + 2 ) % l ];
  21204. } else {
  21205. // extrapolate last point
  21206. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 1 ] );
  21207. p3 = tmp;
  21208. }
  21209. if ( this.type === undefined || this.type === 'centripetal' || this.type === 'chordal' ) {
  21210. // init Centripetal / Chordal Catmull-Rom
  21211. var pow = this.type === 'chordal' ? 0.5 : 0.25;
  21212. var dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  21213. var dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  21214. var dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  21215. // safety check for repeated points
  21216. if ( dt1 < 1e-4 ) dt1 = 1.0;
  21217. if ( dt0 < 1e-4 ) dt0 = dt1;
  21218. if ( dt2 < 1e-4 ) dt2 = dt1;
  21219. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  21220. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  21221. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  21222. } else if ( this.type === 'catmullrom' ) {
  21223. var tension = this.tension !== undefined ? this.tension : 0.5;
  21224. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, tension );
  21225. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, tension );
  21226. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, tension );
  21227. }
  21228. var v = new THREE.Vector3(
  21229. px.calc( weight ),
  21230. py.calc( weight ),
  21231. pz.calc( weight )
  21232. );
  21233. return v;
  21234. }
  21235. );
  21236. } )();
  21237. // File:src/extras/curves/ClosedSplineCurve3.js
  21238. /**************************************************************
  21239. * Closed Spline 3D curve
  21240. **************************************************************/
  21241. THREE.ClosedSplineCurve3 = function ( points ) {
  21242. console.warn( 'THREE.ClosedSplineCurve3 has been deprecated. Please use THREE.CatmullRomCurve3.' );
  21243. THREE.CatmullRomCurve3.call( this, points );
  21244. this.type = 'catmullrom';
  21245. this.closed = true;
  21246. };
  21247. THREE.ClosedSplineCurve3.prototype = Object.create( THREE.CatmullRomCurve3.prototype );
  21248. // File:src/extras/geometries/BoxGeometry.js
  21249. /**
  21250. * @author mrdoob / http://mrdoob.com/
  21251. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Cube.as
  21252. */
  21253. THREE.BoxGeometry = function ( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  21254. THREE.Geometry.call( this );
  21255. this.type = 'BoxGeometry';
  21256. this.parameters = {
  21257. width: width,
  21258. height: height,
  21259. depth: depth,
  21260. widthSegments: widthSegments,
  21261. heightSegments: heightSegments,
  21262. depthSegments: depthSegments
  21263. };
  21264. this.fromBufferGeometry( new THREE.BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) );
  21265. this.mergeVertices();
  21266. };
  21267. THREE.BoxGeometry.prototype = Object.create( THREE.Geometry.prototype );
  21268. THREE.BoxGeometry.prototype.constructor = THREE.BoxGeometry;
  21269. THREE.CubeGeometry = THREE.BoxGeometry;
  21270. // File:src/extras/geometries/BoxBufferGeometry.js
  21271. /**
  21272. * @author Mugen87 / https://github.com/Mugen87
  21273. */
  21274. THREE.BoxBufferGeometry = function ( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  21275. THREE.BufferGeometry.call( this );
  21276. this.type = 'BoxBufferGeometry';
  21277. this.parameters = {
  21278. width: width,
  21279. height: height,
  21280. depth: depth,
  21281. widthSegments: widthSegments,
  21282. heightSegments: heightSegments,
  21283. depthSegments: depthSegments
  21284. };
  21285. var scope = this;
  21286. // segments
  21287. widthSegments = Math.floor( widthSegments ) || 1;
  21288. heightSegments = Math.floor( heightSegments ) || 1;
  21289. depthSegments = Math.floor( depthSegments ) || 1;
  21290. // these are used to calculate buffer length
  21291. var vertexCount = calculateVertexCount( widthSegments, heightSegments, depthSegments );
  21292. var indexCount = ( vertexCount / 4 ) * 6;
  21293. // buffers
  21294. var indices = new ( indexCount > 65535 ? Uint32Array : Uint16Array )( indexCount );
  21295. var vertices = new Float32Array( vertexCount * 3 );
  21296. var normals = new Float32Array( vertexCount * 3 );
  21297. var uvs = new Float32Array( vertexCount * 2 );
  21298. // offset variables
  21299. var vertexBufferOffset = 0;
  21300. var uvBufferOffset = 0;
  21301. var indexBufferOffset = 0;
  21302. var numberOfVertices = 0;
  21303. // group variables
  21304. var groupStart = 0;
  21305. // build each side of the box geometry
  21306. buildPlane( 'z', 'y', 'x', - 1, - 1, depth, height, width, depthSegments, heightSegments, 0 ); // px
  21307. buildPlane( 'z', 'y', 'x', 1, - 1, depth, height, - width, depthSegments, heightSegments, 1 ); // nx
  21308. buildPlane( 'x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2 ); // py
  21309. buildPlane( 'x', 'z', 'y', 1, - 1, width, depth, - height, widthSegments, depthSegments, 3 ); // ny
  21310. buildPlane( 'x', 'y', 'z', 1, - 1, width, height, depth, widthSegments, heightSegments, 4 ); // pz
  21311. buildPlane( 'x', 'y', 'z', - 1, - 1, width, height, - depth, widthSegments, heightSegments, 5 ); // nz
  21312. // build geometry
  21313. this.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  21314. this.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  21315. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  21316. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  21317. // helper functions
  21318. function calculateVertexCount ( w, h, d ) {
  21319. var segments = 0;
  21320. // calculate the amount of segments for each side
  21321. segments += w * h * 2; // xy
  21322. segments += w * d * 2; // xz
  21323. segments += d * h * 2; // zy
  21324. return segments * 4; // four vertices per segments
  21325. }
  21326. function buildPlane ( u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex ) {
  21327. var segmentWidth = width / gridX;
  21328. var segmentHeight = height / gridY;
  21329. var widthHalf = width / 2;
  21330. var heightHalf = height / 2;
  21331. var depthHalf = depth / 2;
  21332. var gridX1 = gridX + 1;
  21333. var gridY1 = gridY + 1;
  21334. var vertexCounter = 0;
  21335. var groupCount = 0;
  21336. var vector = new THREE.Vector3();
  21337. // generate vertices, normals and uvs
  21338. for ( var iy = 0; iy < gridY1; iy ++ ) {
  21339. var y = iy * segmentHeight - heightHalf;
  21340. for ( var ix = 0; ix < gridX1; ix ++ ) {
  21341. var x = ix * segmentWidth - widthHalf;
  21342. // set values to correct vector component
  21343. vector[ u ] = x * udir;
  21344. vector[ v ] = y * vdir;
  21345. vector[ w ] = depthHalf;
  21346. // now apply vector to vertex buffer
  21347. vertices[ vertexBufferOffset ] = vector.x;
  21348. vertices[ vertexBufferOffset + 1 ] = vector.y;
  21349. vertices[ vertexBufferOffset + 2 ] = vector.z;
  21350. // set values to correct vector component
  21351. vector[ u ] = 0;
  21352. vector[ v ] = 0;
  21353. vector[ w ] = depth > 0 ? 1 : - 1;
  21354. // now apply vector to normal buffer
  21355. normals[ vertexBufferOffset ] = vector.x;
  21356. normals[ vertexBufferOffset + 1 ] = vector.y;
  21357. normals[ vertexBufferOffset + 2 ] = vector.z;
  21358. // uvs
  21359. uvs[ uvBufferOffset ] = ix / gridX;
  21360. uvs[ uvBufferOffset + 1 ] = 1 - ( iy / gridY );
  21361. // update offsets and counters
  21362. vertexBufferOffset += 3;
  21363. uvBufferOffset += 2;
  21364. vertexCounter += 1;
  21365. }
  21366. }
  21367. // 1. you need three indices to draw a single face
  21368. // 2. a single segment consists of two faces
  21369. // 3. so we need to generate six (2*3) indices per segment
  21370. for ( iy = 0; iy < gridY; iy ++ ) {
  21371. for ( ix = 0; ix < gridX; ix ++ ) {
  21372. // indices
  21373. var a = numberOfVertices + ix + gridX1 * iy;
  21374. var b = numberOfVertices + ix + gridX1 * ( iy + 1 );
  21375. var c = numberOfVertices + ( ix + 1 ) + gridX1 * ( iy + 1 );
  21376. var d = numberOfVertices + ( ix + 1 ) + gridX1 * iy;
  21377. // face one
  21378. indices[ indexBufferOffset ] = a;
  21379. indices[ indexBufferOffset + 1 ] = b;
  21380. indices[ indexBufferOffset + 2 ] = d;
  21381. // face two
  21382. indices[ indexBufferOffset + 3 ] = b;
  21383. indices[ indexBufferOffset + 4 ] = c;
  21384. indices[ indexBufferOffset + 5 ] = d;
  21385. // update offsets and counters
  21386. indexBufferOffset += 6;
  21387. groupCount += 6;
  21388. }
  21389. }
  21390. // add a group to the geometry. this will ensure multi material support
  21391. scope.addGroup( groupStart, groupCount, materialIndex );
  21392. // calculate new start value for groups
  21393. groupStart += groupCount;
  21394. // update total number of vertices
  21395. numberOfVertices += vertexCounter;
  21396. }
  21397. };
  21398. THREE.BoxBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  21399. THREE.BoxBufferGeometry.prototype.constructor = THREE.BoxBufferGeometry;
  21400. // File:src/extras/geometries/CircleGeometry.js
  21401. /**
  21402. * @author hughes
  21403. */
  21404. THREE.CircleGeometry = function ( radius, segments, thetaStart, thetaLength ) {
  21405. THREE.Geometry.call( this );
  21406. this.type = 'CircleGeometry';
  21407. this.parameters = {
  21408. radius: radius,
  21409. segments: segments,
  21410. thetaStart: thetaStart,
  21411. thetaLength: thetaLength
  21412. };
  21413. this.fromBufferGeometry( new THREE.CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) );
  21414. };
  21415. THREE.CircleGeometry.prototype = Object.create( THREE.Geometry.prototype );
  21416. THREE.CircleGeometry.prototype.constructor = THREE.CircleGeometry;
  21417. // File:src/extras/geometries/CircleBufferGeometry.js
  21418. /**
  21419. * @author benaadams / https://twitter.com/ben_a_adams
  21420. */
  21421. THREE.CircleBufferGeometry = function ( radius, segments, thetaStart, thetaLength ) {
  21422. THREE.BufferGeometry.call( this );
  21423. this.type = 'CircleBufferGeometry';
  21424. this.parameters = {
  21425. radius: radius,
  21426. segments: segments,
  21427. thetaStart: thetaStart,
  21428. thetaLength: thetaLength
  21429. };
  21430. radius = radius || 50;
  21431. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  21432. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  21433. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  21434. var vertices = segments + 2;
  21435. var positions = new Float32Array( vertices * 3 );
  21436. var normals = new Float32Array( vertices * 3 );
  21437. var uvs = new Float32Array( vertices * 2 );
  21438. // center data is already zero, but need to set a few extras
  21439. normals[ 2 ] = 1.0;
  21440. uvs[ 0 ] = 0.5;
  21441. uvs[ 1 ] = 0.5;
  21442. for ( var s = 0, i = 3, ii = 2 ; s <= segments; s ++, i += 3, ii += 2 ) {
  21443. var segment = thetaStart + s / segments * thetaLength;
  21444. positions[ i ] = radius * Math.cos( segment );
  21445. positions[ i + 1 ] = radius * Math.sin( segment );
  21446. normals[ i + 2 ] = 1; // normal z
  21447. uvs[ ii ] = ( positions[ i ] / radius + 1 ) / 2;
  21448. uvs[ ii + 1 ] = ( positions[ i + 1 ] / radius + 1 ) / 2;
  21449. }
  21450. var indices = [];
  21451. for ( var i = 1; i <= segments; i ++ ) {
  21452. indices.push( i, i + 1, 0 );
  21453. }
  21454. this.setIndex( new THREE.BufferAttribute( new Uint16Array( indices ), 1 ) );
  21455. this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
  21456. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  21457. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  21458. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  21459. };
  21460. THREE.CircleBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  21461. THREE.CircleBufferGeometry.prototype.constructor = THREE.CircleBufferGeometry;
  21462. // File:src/extras/geometries/CylinderBufferGeometry.js
  21463. /**
  21464. * @author Mugen87 / https://github.com/Mugen87
  21465. */
  21466. THREE.CylinderBufferGeometry = function ( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  21467. THREE.BufferGeometry.call( this );
  21468. this.type = 'CylinderBufferGeometry';
  21469. this.parameters = {
  21470. radiusTop: radiusTop,
  21471. radiusBottom: radiusBottom,
  21472. height: height,
  21473. radialSegments: radialSegments,
  21474. heightSegments: heightSegments,
  21475. openEnded: openEnded,
  21476. thetaStart: thetaStart,
  21477. thetaLength: thetaLength
  21478. };
  21479. radiusTop = radiusTop !== undefined ? radiusTop : 20;
  21480. radiusBottom = radiusBottom !== undefined ? radiusBottom : 20;
  21481. height = height !== undefined ? height : 100;
  21482. radialSegments = Math.floor( radialSegments ) || 8;
  21483. heightSegments = Math.floor( heightSegments ) || 1;
  21484. openEnded = openEnded !== undefined ? openEnded : false;
  21485. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  21486. thetaLength = thetaLength !== undefined ? thetaLength : 2 * Math.PI;
  21487. // used to calculate buffer length
  21488. var vertexCount = calculateVertexCount();
  21489. var indexCount = calculateIndexCount();
  21490. // buffers
  21491. var indices = new THREE.BufferAttribute( new ( indexCount > 65535 ? Uint32Array : Uint16Array )( indexCount ) , 1 );
  21492. var vertices = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  21493. var normals = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  21494. var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
  21495. // helper variables
  21496. var index = 0, indexOffset = 0, indexArray = [], halfHeight = height / 2;
  21497. // generate geometry
  21498. generateTorso();
  21499. if( openEnded === false ) {
  21500. if( radiusTop > 0 ) {
  21501. generateCap( true );
  21502. }
  21503. if( radiusBottom > 0 ) {
  21504. generateCap( false );
  21505. }
  21506. }
  21507. // build geometry
  21508. this.setIndex( indices );
  21509. this.addAttribute( 'position', vertices );
  21510. this.addAttribute( 'normal', normals );
  21511. this.addAttribute( 'uv', uvs );
  21512. // helper functions
  21513. function calculateVertexCount () {
  21514. var count = ( radialSegments + 1 ) * ( heightSegments + 1 );
  21515. if ( openEnded === false ) {
  21516. count += ( ( radialSegments + 1 ) * 2 ) + ( radialSegments * 2 );
  21517. }
  21518. return count;
  21519. }
  21520. function calculateIndexCount () {
  21521. var count = radialSegments * heightSegments * 2 * 3;
  21522. if ( openEnded === false ) {
  21523. count += radialSegments * 2 * 3;
  21524. }
  21525. return count;
  21526. }
  21527. function generateTorso () {
  21528. var x, y;
  21529. var normal = new THREE.Vector3();
  21530. var vertex = new THREE.Vector3();
  21531. // this will be used to calculate the normal
  21532. var tanTheta = ( radiusBottom - radiusTop ) / height;
  21533. // generate vertices, normals and uvs
  21534. for ( y = 0; y <= heightSegments; y ++ ) {
  21535. var indexRow = [];
  21536. var v = y / heightSegments;
  21537. // calculate the radius of the current row
  21538. var radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  21539. for ( x = 0; x <= radialSegments; x ++ ) {
  21540. var u = x / radialSegments;
  21541. // vertex
  21542. vertex.x = radius * Math.sin( u * thetaLength + thetaStart );
  21543. vertex.y = - v * height + halfHeight;
  21544. vertex.z = radius * Math.cos( u * thetaLength + thetaStart );
  21545. vertices.setXYZ( index, vertex.x, vertex.y, vertex.z );
  21546. // normal
  21547. normal.copy( vertex );
  21548. // handle special case if radiusTop/radiusBottom is zero
  21549. if( ( radiusTop === 0 && y === 0 ) || ( radiusBottom === 0 && y === heightSegments ) ) {
  21550. normal.x = Math.sin( u * thetaLength + thetaStart );
  21551. normal.z = Math.cos( u * thetaLength + thetaStart );
  21552. }
  21553. normal.setY( Math.sqrt( normal.x * normal.x + normal.z * normal.z ) * tanTheta ).normalize();
  21554. normals.setXYZ( index, normal.x, normal.y, normal.z );
  21555. // uv
  21556. uvs.setXY( index, u, 1 - v );
  21557. // save index of vertex in respective row
  21558. indexRow.push( index );
  21559. // increase index
  21560. index ++;
  21561. }
  21562. // now save vertices of the row in our index array
  21563. indexArray.push( indexRow );
  21564. }
  21565. // generate indices
  21566. for ( x = 0; x < radialSegments; x ++ ) {
  21567. for ( y = 0; y < heightSegments; y ++ ) {
  21568. // we use the index array to access the correct indices
  21569. var i1 = indexArray[ y ][ x ];
  21570. var i2 = indexArray[ y + 1 ][ x ];
  21571. var i3 = indexArray[ y + 1 ][ x + 1 ];
  21572. var i4 = indexArray[ y ][ x + 1 ];
  21573. // face one
  21574. indices.setX( indexOffset, i1 ); indexOffset++;
  21575. indices.setX( indexOffset, i2 ); indexOffset++;
  21576. indices.setX( indexOffset, i4 ); indexOffset++;
  21577. // face two
  21578. indices.setX( indexOffset, i2 ); indexOffset++;
  21579. indices.setX( indexOffset, i3 ); indexOffset++;
  21580. indices.setX( indexOffset, i4 ); indexOffset++;
  21581. }
  21582. }
  21583. }
  21584. function generateCap ( top ) {
  21585. var x, centerIndexStart, centerIndexEnd;
  21586. var uv = new THREE.Vector2();
  21587. var vertex = new THREE.Vector3();
  21588. var radius = ( top === true ) ? radiusTop : radiusBottom;
  21589. var sign = ( top === true ) ? 1 : - 1;
  21590. // save the index of the first center vertex
  21591. centerIndexStart = index;
  21592. // first we generate the center vertex data of the cap.
  21593. // because the geometry needs one set of uvs per face,
  21594. // we must generate a center vertex per face/segment
  21595. for ( x = 1; x <= radialSegments; x ++ ) {
  21596. // vertex
  21597. vertices.setXYZ( index, 0, halfHeight * sign, 0 );
  21598. // normal
  21599. normals.setXYZ( index, 0, sign, 0 );
  21600. // uv
  21601. if( top === true ) {
  21602. uv.x = x / radialSegments;
  21603. uv.y = 0;
  21604. } else {
  21605. uv.x = ( x - 1 ) / radialSegments;
  21606. uv.y = 1;
  21607. }
  21608. uvs.setXY( index, uv.x, uv.y );
  21609. // increase index
  21610. index++;
  21611. }
  21612. // save the index of the last center vertex
  21613. centerIndexEnd = index;
  21614. // now we generate the surrounding vertices, normals and uvs
  21615. for ( x = 0; x <= radialSegments; x ++ ) {
  21616. var u = x / radialSegments;
  21617. // vertex
  21618. vertex.x = radius * Math.sin( u * thetaLength + thetaStart );
  21619. vertex.y = halfHeight * sign;
  21620. vertex.z = radius * Math.cos( u * thetaLength + thetaStart );
  21621. vertices.setXYZ( index, vertex.x, vertex.y, vertex.z );
  21622. // normal
  21623. normals.setXYZ( index, 0, sign, 0 );
  21624. // uv
  21625. uvs.setXY( index, u, ( top === true ) ? 1 : 0 );
  21626. // increase index
  21627. index ++;
  21628. }
  21629. // generate indices
  21630. for ( x = 0; x < radialSegments; x ++ ) {
  21631. var c = centerIndexStart + x;
  21632. var i = centerIndexEnd + x;
  21633. if( top === true ) {
  21634. // face top
  21635. indices.setX( indexOffset, i ); indexOffset++;
  21636. indices.setX( indexOffset, i + 1 ); indexOffset++;
  21637. indices.setX( indexOffset, c ); indexOffset++;
  21638. } else {
  21639. // face bottom
  21640. indices.setX( indexOffset, i + 1); indexOffset++;
  21641. indices.setX( indexOffset, i ); indexOffset++;
  21642. indices.setX( indexOffset, c ); indexOffset++;
  21643. }
  21644. }
  21645. }
  21646. };
  21647. THREE.CylinderBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  21648. THREE.CylinderBufferGeometry.prototype.constructor = THREE.CylinderBufferGeometry;
  21649. // File:src/extras/geometries/CylinderGeometry.js
  21650. /**
  21651. * @author mrdoob / http://mrdoob.com/
  21652. */
  21653. THREE.CylinderGeometry = function ( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  21654. THREE.Geometry.call( this );
  21655. this.type = 'CylinderGeometry';
  21656. this.parameters = {
  21657. radiusTop: radiusTop,
  21658. radiusBottom: radiusBottom,
  21659. height: height,
  21660. radialSegments: radialSegments,
  21661. heightSegments: heightSegments,
  21662. openEnded: openEnded,
  21663. thetaStart: thetaStart,
  21664. thetaLength: thetaLength
  21665. };
  21666. this.fromBufferGeometry( new THREE.CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) );
  21667. this.mergeVertices();
  21668. };
  21669. THREE.CylinderGeometry.prototype = Object.create( THREE.Geometry.prototype );
  21670. THREE.CylinderGeometry.prototype.constructor = THREE.CylinderGeometry;
  21671. // File:src/extras/geometries/EdgesGeometry.js
  21672. /**
  21673. * @author WestLangley / http://github.com/WestLangley
  21674. */
  21675. THREE.EdgesGeometry = function ( geometry, thresholdAngle ) {
  21676. THREE.BufferGeometry.call( this );
  21677. thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
  21678. var thresholdDot = Math.cos( THREE.Math.degToRad( thresholdAngle ) );
  21679. var edge = [ 0, 0 ], hash = {};
  21680. function sortFunction( a, b ) {
  21681. return a - b;
  21682. }
  21683. var keys = [ 'a', 'b', 'c' ];
  21684. var geometry2;
  21685. if ( geometry instanceof THREE.BufferGeometry ) {
  21686. geometry2 = new THREE.Geometry();
  21687. geometry2.fromBufferGeometry( geometry );
  21688. } else {
  21689. geometry2 = geometry.clone();
  21690. }
  21691. geometry2.mergeVertices();
  21692. geometry2.computeFaceNormals();
  21693. var vertices = geometry2.vertices;
  21694. var faces = geometry2.faces;
  21695. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  21696. var face = faces[ i ];
  21697. for ( var j = 0; j < 3; j ++ ) {
  21698. edge[ 0 ] = face[ keys[ j ] ];
  21699. edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
  21700. edge.sort( sortFunction );
  21701. var key = edge.toString();
  21702. if ( hash[ key ] === undefined ) {
  21703. hash[ key ] = { vert1: edge[ 0 ], vert2: edge[ 1 ], face1: i, face2: undefined };
  21704. } else {
  21705. hash[ key ].face2 = i;
  21706. }
  21707. }
  21708. }
  21709. var coords = [];
  21710. for ( var key in hash ) {
  21711. var h = hash[ key ];
  21712. if ( h.face2 === undefined || faces[ h.face1 ].normal.dot( faces[ h.face2 ].normal ) <= thresholdDot ) {
  21713. var vertex = vertices[ h.vert1 ];
  21714. coords.push( vertex.x );
  21715. coords.push( vertex.y );
  21716. coords.push( vertex.z );
  21717. vertex = vertices[ h.vert2 ];
  21718. coords.push( vertex.x );
  21719. coords.push( vertex.y );
  21720. coords.push( vertex.z );
  21721. }
  21722. }
  21723. this.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array( coords ), 3 ) );
  21724. };
  21725. THREE.EdgesGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  21726. THREE.EdgesGeometry.prototype.constructor = THREE.EdgesGeometry;
  21727. // File:src/extras/geometries/ExtrudeGeometry.js
  21728. /**
  21729. * @author zz85 / http://www.lab4games.net/zz85/blog
  21730. *
  21731. * Creates extruded geometry from a path shape.
  21732. *
  21733. * parameters = {
  21734. *
  21735. * curveSegments: <int>, // number of points on the curves
  21736. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  21737. * amount: <int>, // Depth to extrude the shape
  21738. *
  21739. * bevelEnabled: <bool>, // turn on bevel
  21740. * bevelThickness: <float>, // how deep into the original shape bevel goes
  21741. * bevelSize: <float>, // how far from shape outline is bevel
  21742. * bevelSegments: <int>, // number of bevel layers
  21743. *
  21744. * extrudePath: <THREE.CurvePath> // 3d spline path to extrude shape along. (creates Frames if .frames aren't defined)
  21745. * frames: <THREE.TubeGeometry.FrenetFrames> // containing arrays of tangents, normals, binormals
  21746. *
  21747. * uvGenerator: <Object> // object that provides UV generator functions
  21748. *
  21749. * }
  21750. **/
  21751. THREE.ExtrudeGeometry = function ( shapes, options ) {
  21752. if ( typeof( shapes ) === "undefined" ) {
  21753. shapes = [];
  21754. return;
  21755. }
  21756. THREE.Geometry.call( this );
  21757. this.type = 'ExtrudeGeometry';
  21758. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  21759. this.addShapeList( shapes, options );
  21760. this.computeFaceNormals();
  21761. // can't really use automatic vertex normals
  21762. // as then front and back sides get smoothed too
  21763. // should do separate smoothing just for sides
  21764. //this.computeVertexNormals();
  21765. //console.log( "took", ( Date.now() - startTime ) );
  21766. };
  21767. THREE.ExtrudeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  21768. THREE.ExtrudeGeometry.prototype.constructor = THREE.ExtrudeGeometry;
  21769. THREE.ExtrudeGeometry.prototype.addShapeList = function ( shapes, options ) {
  21770. var sl = shapes.length;
  21771. for ( var s = 0; s < sl; s ++ ) {
  21772. var shape = shapes[ s ];
  21773. this.addShape( shape, options );
  21774. }
  21775. };
  21776. THREE.ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
  21777. var amount = options.amount !== undefined ? options.amount : 100;
  21778. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6; // 10
  21779. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2; // 8
  21780. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  21781. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true; // false
  21782. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  21783. var steps = options.steps !== undefined ? options.steps : 1;
  21784. var extrudePath = options.extrudePath;
  21785. var extrudePts, extrudeByPath = false;
  21786. // Use default WorldUVGenerator if no UV generators are specified.
  21787. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : THREE.ExtrudeGeometry.WorldUVGenerator;
  21788. var splineTube, binormal, normal, position2;
  21789. if ( extrudePath ) {
  21790. extrudePts = extrudePath.getSpacedPoints( steps );
  21791. extrudeByPath = true;
  21792. bevelEnabled = false; // bevels not supported for path extrusion
  21793. // SETUP TNB variables
  21794. // Reuse TNB from TubeGeomtry for now.
  21795. // TODO1 - have a .isClosed in spline?
  21796. splineTube = options.frames !== undefined ? options.frames : new THREE.TubeGeometry.FrenetFrames( extrudePath, steps, false );
  21797. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  21798. binormal = new THREE.Vector3();
  21799. normal = new THREE.Vector3();
  21800. position2 = new THREE.Vector3();
  21801. }
  21802. // Safeguards if bevels are not enabled
  21803. if ( ! bevelEnabled ) {
  21804. bevelSegments = 0;
  21805. bevelThickness = 0;
  21806. bevelSize = 0;
  21807. }
  21808. // Variables initialization
  21809. var ahole, h, hl; // looping of holes
  21810. var scope = this;
  21811. var shapesOffset = this.vertices.length;
  21812. var shapePoints = shape.extractPoints( curveSegments );
  21813. var vertices = shapePoints.shape;
  21814. var holes = shapePoints.holes;
  21815. var reverse = ! THREE.ShapeUtils.isClockWise( vertices );
  21816. if ( reverse ) {
  21817. vertices = vertices.reverse();
  21818. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  21819. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  21820. ahole = holes[ h ];
  21821. if ( THREE.ShapeUtils.isClockWise( ahole ) ) {
  21822. holes[ h ] = ahole.reverse();
  21823. }
  21824. }
  21825. reverse = false; // If vertices are in order now, we shouldn't need to worry about them again (hopefully)!
  21826. }
  21827. var faces = THREE.ShapeUtils.triangulateShape( vertices, holes );
  21828. /* Vertices */
  21829. var contour = vertices; // vertices has all points but contour has only points of circumference
  21830. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  21831. ahole = holes[ h ];
  21832. vertices = vertices.concat( ahole );
  21833. }
  21834. function scalePt2 ( pt, vec, size ) {
  21835. if ( ! vec ) console.error( "THREE.ExtrudeGeometry: vec does not exist" );
  21836. return vec.clone().multiplyScalar( size ).add( pt );
  21837. }
  21838. var b, bs, t, z,
  21839. vert, vlen = vertices.length,
  21840. face, flen = faces.length;
  21841. // Find directions for point movement
  21842. function getBevelVec( inPt, inPrev, inNext ) {
  21843. // computes for inPt the corresponding point inPt' on a new contour
  21844. // shifted by 1 unit (length of normalized vector) to the left
  21845. // if we walk along contour clockwise, this new contour is outside the old one
  21846. //
  21847. // inPt' is the intersection of the two lines parallel to the two
  21848. // adjacent edges of inPt at a distance of 1 unit on the left side.
  21849. var v_trans_x, v_trans_y, shrink_by = 1; // resulting translation vector for inPt
  21850. // good reading for geometry algorithms (here: line-line intersection)
  21851. // http://geomalgorithms.com/a05-_intersect-1.html
  21852. var v_prev_x = inPt.x - inPrev.x, v_prev_y = inPt.y - inPrev.y;
  21853. var v_next_x = inNext.x - inPt.x, v_next_y = inNext.y - inPt.y;
  21854. var v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  21855. // check for collinear edges
  21856. var collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  21857. if ( Math.abs( collinear0 ) > Number.EPSILON ) {
  21858. // not collinear
  21859. // length of vectors for normalizing
  21860. var v_prev_len = Math.sqrt( v_prev_lensq );
  21861. var v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  21862. // shift adjacent points by unit vectors to the left
  21863. var ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  21864. var ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  21865. var ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  21866. var ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  21867. // scaling factor for v_prev to intersection point
  21868. var sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  21869. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  21870. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  21871. // vector from inPt to intersection point
  21872. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  21873. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  21874. // Don't normalize!, otherwise sharp corners become ugly
  21875. // but prevent crazy spikes
  21876. var v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  21877. if ( v_trans_lensq <= 2 ) {
  21878. return new THREE.Vector2( v_trans_x, v_trans_y );
  21879. } else {
  21880. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  21881. }
  21882. } else {
  21883. // handle special case of collinear edges
  21884. var direction_eq = false; // assumes: opposite
  21885. if ( v_prev_x > Number.EPSILON ) {
  21886. if ( v_next_x > Number.EPSILON ) {
  21887. direction_eq = true;
  21888. }
  21889. } else {
  21890. if ( v_prev_x < - Number.EPSILON ) {
  21891. if ( v_next_x < - Number.EPSILON ) {
  21892. direction_eq = true;
  21893. }
  21894. } else {
  21895. if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
  21896. direction_eq = true;
  21897. }
  21898. }
  21899. }
  21900. if ( direction_eq ) {
  21901. // console.log("Warning: lines are a straight sequence");
  21902. v_trans_x = - v_prev_y;
  21903. v_trans_y = v_prev_x;
  21904. shrink_by = Math.sqrt( v_prev_lensq );
  21905. } else {
  21906. // console.log("Warning: lines are a straight spike");
  21907. v_trans_x = v_prev_x;
  21908. v_trans_y = v_prev_y;
  21909. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  21910. }
  21911. }
  21912. return new THREE.Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  21913. }
  21914. var contourMovements = [];
  21915. for ( var i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  21916. if ( j === il ) j = 0;
  21917. if ( k === il ) k = 0;
  21918. // (j)---(i)---(k)
  21919. // console.log('i,j,k', i, j , k)
  21920. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  21921. }
  21922. var holesMovements = [], oneHoleMovements, verticesMovements = contourMovements.concat();
  21923. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  21924. ahole = holes[ h ];
  21925. oneHoleMovements = [];
  21926. for ( i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  21927. if ( j === il ) j = 0;
  21928. if ( k === il ) k = 0;
  21929. // (j)---(i)---(k)
  21930. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  21931. }
  21932. holesMovements.push( oneHoleMovements );
  21933. verticesMovements = verticesMovements.concat( oneHoleMovements );
  21934. }
  21935. // Loop bevelSegments, 1 for the front, 1 for the back
  21936. for ( b = 0; b < bevelSegments; b ++ ) {
  21937. //for ( b = bevelSegments; b > 0; b -- ) {
  21938. t = b / bevelSegments;
  21939. z = bevelThickness * ( 1 - t );
  21940. //z = bevelThickness * t;
  21941. bs = bevelSize * ( Math.sin ( t * Math.PI / 2 ) ); // curved
  21942. //bs = bevelSize * t; // linear
  21943. // contract shape
  21944. for ( i = 0, il = contour.length; i < il; i ++ ) {
  21945. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  21946. v( vert.x, vert.y, - z );
  21947. }
  21948. // expand holes
  21949. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  21950. ahole = holes[ h ];
  21951. oneHoleMovements = holesMovements[ h ];
  21952. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  21953. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  21954. v( vert.x, vert.y, - z );
  21955. }
  21956. }
  21957. }
  21958. bs = bevelSize;
  21959. // Back facing vertices
  21960. for ( i = 0; i < vlen; i ++ ) {
  21961. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  21962. if ( ! extrudeByPath ) {
  21963. v( vert.x, vert.y, 0 );
  21964. } else {
  21965. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  21966. normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x );
  21967. binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y );
  21968. position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
  21969. v( position2.x, position2.y, position2.z );
  21970. }
  21971. }
  21972. // Add stepped vertices...
  21973. // Including front facing vertices
  21974. var s;
  21975. for ( s = 1; s <= steps; s ++ ) {
  21976. for ( i = 0; i < vlen; i ++ ) {
  21977. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  21978. if ( ! extrudeByPath ) {
  21979. v( vert.x, vert.y, amount / steps * s );
  21980. } else {
  21981. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  21982. normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x );
  21983. binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y );
  21984. position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
  21985. v( position2.x, position2.y, position2.z );
  21986. }
  21987. }
  21988. }
  21989. // Add bevel segments planes
  21990. //for ( b = 1; b <= bevelSegments; b ++ ) {
  21991. for ( b = bevelSegments - 1; b >= 0; b -- ) {
  21992. t = b / bevelSegments;
  21993. z = bevelThickness * ( 1 - t );
  21994. //bs = bevelSize * ( 1-Math.sin ( ( 1 - t ) * Math.PI/2 ) );
  21995. bs = bevelSize * Math.sin ( t * Math.PI / 2 );
  21996. // contract shape
  21997. for ( i = 0, il = contour.length; i < il; i ++ ) {
  21998. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  21999. v( vert.x, vert.y, amount + z );
  22000. }
  22001. // expand holes
  22002. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  22003. ahole = holes[ h ];
  22004. oneHoleMovements = holesMovements[ h ];
  22005. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  22006. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  22007. if ( ! extrudeByPath ) {
  22008. v( vert.x, vert.y, amount + z );
  22009. } else {
  22010. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  22011. }
  22012. }
  22013. }
  22014. }
  22015. /* Faces */
  22016. // Top and bottom faces
  22017. buildLidFaces();
  22018. // Sides faces
  22019. buildSideFaces();
  22020. ///// Internal functions
  22021. function buildLidFaces() {
  22022. if ( bevelEnabled ) {
  22023. var layer = 0; // steps + 1
  22024. var offset = vlen * layer;
  22025. // Bottom faces
  22026. for ( i = 0; i < flen; i ++ ) {
  22027. face = faces[ i ];
  22028. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  22029. }
  22030. layer = steps + bevelSegments * 2;
  22031. offset = vlen * layer;
  22032. // Top faces
  22033. for ( i = 0; i < flen; i ++ ) {
  22034. face = faces[ i ];
  22035. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  22036. }
  22037. } else {
  22038. // Bottom faces
  22039. for ( i = 0; i < flen; i ++ ) {
  22040. face = faces[ i ];
  22041. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  22042. }
  22043. // Top faces
  22044. for ( i = 0; i < flen; i ++ ) {
  22045. face = faces[ i ];
  22046. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  22047. }
  22048. }
  22049. }
  22050. // Create faces for the z-sides of the shape
  22051. function buildSideFaces() {
  22052. var layeroffset = 0;
  22053. sidewalls( contour, layeroffset );
  22054. layeroffset += contour.length;
  22055. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  22056. ahole = holes[ h ];
  22057. sidewalls( ahole, layeroffset );
  22058. //, true
  22059. layeroffset += ahole.length;
  22060. }
  22061. }
  22062. function sidewalls( contour, layeroffset ) {
  22063. var j, k;
  22064. i = contour.length;
  22065. while ( -- i >= 0 ) {
  22066. j = i;
  22067. k = i - 1;
  22068. if ( k < 0 ) k = contour.length - 1;
  22069. //console.log('b', i,j, i-1, k,vertices.length);
  22070. var s = 0, sl = steps + bevelSegments * 2;
  22071. for ( s = 0; s < sl; s ++ ) {
  22072. var slen1 = vlen * s;
  22073. var slen2 = vlen * ( s + 1 );
  22074. var a = layeroffset + j + slen1,
  22075. b = layeroffset + k + slen1,
  22076. c = layeroffset + k + slen2,
  22077. d = layeroffset + j + slen2;
  22078. f4( a, b, c, d, contour, s, sl, j, k );
  22079. }
  22080. }
  22081. }
  22082. function v( x, y, z ) {
  22083. scope.vertices.push( new THREE.Vector3( x, y, z ) );
  22084. }
  22085. function f3( a, b, c ) {
  22086. a += shapesOffset;
  22087. b += shapesOffset;
  22088. c += shapesOffset;
  22089. scope.faces.push( new THREE.Face3( a, b, c, null, null, 0 ) );
  22090. var uvs = uvgen.generateTopUV( scope, a, b, c );
  22091. scope.faceVertexUvs[ 0 ].push( uvs );
  22092. }
  22093. function f4( a, b, c, d, wallContour, stepIndex, stepsLength, contourIndex1, contourIndex2 ) {
  22094. a += shapesOffset;
  22095. b += shapesOffset;
  22096. c += shapesOffset;
  22097. d += shapesOffset;
  22098. scope.faces.push( new THREE.Face3( a, b, d, null, null, 1 ) );
  22099. scope.faces.push( new THREE.Face3( b, c, d, null, null, 1 ) );
  22100. var uvs = uvgen.generateSideWallUV( scope, a, b, c, d );
  22101. scope.faceVertexUvs[ 0 ].push( [ uvs[ 0 ], uvs[ 1 ], uvs[ 3 ] ] );
  22102. scope.faceVertexUvs[ 0 ].push( [ uvs[ 1 ], uvs[ 2 ], uvs[ 3 ] ] );
  22103. }
  22104. };
  22105. THREE.ExtrudeGeometry.WorldUVGenerator = {
  22106. generateTopUV: function ( geometry, indexA, indexB, indexC ) {
  22107. var vertices = geometry.vertices;
  22108. var a = vertices[ indexA ];
  22109. var b = vertices[ indexB ];
  22110. var c = vertices[ indexC ];
  22111. return [
  22112. new THREE.Vector2( a.x, a.y ),
  22113. new THREE.Vector2( b.x, b.y ),
  22114. new THREE.Vector2( c.x, c.y )
  22115. ];
  22116. },
  22117. generateSideWallUV: function ( geometry, indexA, indexB, indexC, indexD ) {
  22118. var vertices = geometry.vertices;
  22119. var a = vertices[ indexA ];
  22120. var b = vertices[ indexB ];
  22121. var c = vertices[ indexC ];
  22122. var d = vertices[ indexD ];
  22123. if ( Math.abs( a.y - b.y ) < 0.01 ) {
  22124. return [
  22125. new THREE.Vector2( a.x, 1 - a.z ),
  22126. new THREE.Vector2( b.x, 1 - b.z ),
  22127. new THREE.Vector2( c.x, 1 - c.z ),
  22128. new THREE.Vector2( d.x, 1 - d.z )
  22129. ];
  22130. } else {
  22131. return [
  22132. new THREE.Vector2( a.y, 1 - a.z ),
  22133. new THREE.Vector2( b.y, 1 - b.z ),
  22134. new THREE.Vector2( c.y, 1 - c.z ),
  22135. new THREE.Vector2( d.y, 1 - d.z )
  22136. ];
  22137. }
  22138. }
  22139. };
  22140. // File:src/extras/geometries/ShapeGeometry.js
  22141. /**
  22142. * @author jonobr1 / http://jonobr1.com
  22143. *
  22144. * Creates a one-sided polygonal geometry from a path shape. Similar to
  22145. * ExtrudeGeometry.
  22146. *
  22147. * parameters = {
  22148. *
  22149. * curveSegments: <int>, // number of points on the curves. NOT USED AT THE MOMENT.
  22150. *
  22151. * material: <int> // material index for front and back faces
  22152. * uvGenerator: <Object> // object that provides UV generator functions
  22153. *
  22154. * }
  22155. **/
  22156. THREE.ShapeGeometry = function ( shapes, options ) {
  22157. THREE.Geometry.call( this );
  22158. this.type = 'ShapeGeometry';
  22159. if ( Array.isArray( shapes ) === false ) shapes = [ shapes ];
  22160. this.addShapeList( shapes, options );
  22161. this.computeFaceNormals();
  22162. };
  22163. THREE.ShapeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22164. THREE.ShapeGeometry.prototype.constructor = THREE.ShapeGeometry;
  22165. /**
  22166. * Add an array of shapes to THREE.ShapeGeometry.
  22167. */
  22168. THREE.ShapeGeometry.prototype.addShapeList = function ( shapes, options ) {
  22169. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  22170. this.addShape( shapes[ i ], options );
  22171. }
  22172. return this;
  22173. };
  22174. /**
  22175. * Adds a shape to THREE.ShapeGeometry, based on THREE.ExtrudeGeometry.
  22176. */
  22177. THREE.ShapeGeometry.prototype.addShape = function ( shape, options ) {
  22178. if ( options === undefined ) options = {};
  22179. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  22180. var material = options.material;
  22181. var uvgen = options.UVGenerator === undefined ? THREE.ExtrudeGeometry.WorldUVGenerator : options.UVGenerator;
  22182. //
  22183. var i, l, hole;
  22184. var shapesOffset = this.vertices.length;
  22185. var shapePoints = shape.extractPoints( curveSegments );
  22186. var vertices = shapePoints.shape;
  22187. var holes = shapePoints.holes;
  22188. var reverse = ! THREE.ShapeUtils.isClockWise( vertices );
  22189. if ( reverse ) {
  22190. vertices = vertices.reverse();
  22191. // Maybe we should also check if holes are in the opposite direction, just to be safe...
  22192. for ( i = 0, l = holes.length; i < l; i ++ ) {
  22193. hole = holes[ i ];
  22194. if ( THREE.ShapeUtils.isClockWise( hole ) ) {
  22195. holes[ i ] = hole.reverse();
  22196. }
  22197. }
  22198. reverse = false;
  22199. }
  22200. var faces = THREE.ShapeUtils.triangulateShape( vertices, holes );
  22201. // Vertices
  22202. for ( i = 0, l = holes.length; i < l; i ++ ) {
  22203. hole = holes[ i ];
  22204. vertices = vertices.concat( hole );
  22205. }
  22206. //
  22207. var vert, vlen = vertices.length;
  22208. var face, flen = faces.length;
  22209. for ( i = 0; i < vlen; i ++ ) {
  22210. vert = vertices[ i ];
  22211. this.vertices.push( new THREE.Vector3( vert.x, vert.y, 0 ) );
  22212. }
  22213. for ( i = 0; i < flen; i ++ ) {
  22214. face = faces[ i ];
  22215. var a = face[ 0 ] + shapesOffset;
  22216. var b = face[ 1 ] + shapesOffset;
  22217. var c = face[ 2 ] + shapesOffset;
  22218. this.faces.push( new THREE.Face3( a, b, c, null, null, material ) );
  22219. this.faceVertexUvs[ 0 ].push( uvgen.generateTopUV( this, a, b, c ) );
  22220. }
  22221. };
  22222. // File:src/extras/geometries/LatheBufferGeometry.js
  22223. /**
  22224. * @author Mugen87 / https://github.com/Mugen87
  22225. */
  22226. // points - to create a closed torus, one must use a set of points
  22227. // like so: [ a, b, c, d, a ], see first is the same as last.
  22228. // segments - the number of circumference segments to create
  22229. // phiStart - the starting radian
  22230. // phiLength - the radian (0 to 2PI) range of the lathed section
  22231. // 2PI is a closed lathe, less than 2PI is a portion.
  22232. THREE.LatheBufferGeometry = function ( points, segments, phiStart, phiLength ) {
  22233. THREE.BufferGeometry.call( this );
  22234. this.type = 'LatheBufferGeometry';
  22235. this.parameters = {
  22236. points: points,
  22237. segments: segments,
  22238. phiStart: phiStart,
  22239. phiLength: phiLength
  22240. };
  22241. segments = Math.floor( segments ) || 12;
  22242. phiStart = phiStart || 0;
  22243. phiLength = phiLength || Math.PI * 2;
  22244. // clamp phiLength so it's in range of [ 0, 2PI ]
  22245. phiLength = THREE.Math.clamp( phiLength, 0, Math.PI * 2 );
  22246. // these are used to calculate buffer length
  22247. var vertexCount = ( segments + 1 ) * points.length;
  22248. var indexCount = segments * points.length * 2 * 3;
  22249. // buffers
  22250. var indices = new THREE.BufferAttribute( new ( indexCount > 65535 ? Uint32Array : Uint16Array )( indexCount ) , 1 );
  22251. var vertices = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  22252. var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
  22253. // helper variables
  22254. var index = 0, indexOffset = 0, base;
  22255. var inversePointLength = 1.0 / ( points.length - 1 );
  22256. var inverseSegments = 1.0 / segments;
  22257. var vertex = new THREE.Vector3();
  22258. var uv = new THREE.Vector2();
  22259. var i, j;
  22260. // generate vertices and uvs
  22261. for ( i = 0; i <= segments; i ++ ) {
  22262. var phi = phiStart + i * inverseSegments * phiLength;
  22263. var sin = Math.sin( phi );
  22264. var cos = Math.cos( phi );
  22265. for ( j = 0; j <= ( points.length - 1 ); j ++ ) {
  22266. // vertex
  22267. vertex.x = points[ j ].x * sin;
  22268. vertex.y = points[ j ].y;
  22269. vertex.z = points[ j ].x * cos;
  22270. vertices.setXYZ( index, vertex.x, vertex.y, vertex.z );
  22271. // uv
  22272. uv.x = i / segments;
  22273. uv.y = j / ( points.length - 1 );
  22274. uvs.setXY( index, uv.x, uv.y );
  22275. // increase index
  22276. index ++;
  22277. }
  22278. }
  22279. // generate indices
  22280. for ( i = 0; i < segments; i ++ ) {
  22281. for ( j = 0; j < ( points.length - 1 ); j ++ ) {
  22282. base = j + i * points.length;
  22283. // indices
  22284. var a = base;
  22285. var b = base + points.length;
  22286. var c = base + points.length + 1;
  22287. var d = base + 1;
  22288. // face one
  22289. indices.setX( indexOffset, a ); indexOffset++;
  22290. indices.setX( indexOffset, b ); indexOffset++;
  22291. indices.setX( indexOffset, d ); indexOffset++;
  22292. // face two
  22293. indices.setX( indexOffset, b ); indexOffset++;
  22294. indices.setX( indexOffset, c ); indexOffset++;
  22295. indices.setX( indexOffset, d ); indexOffset++;
  22296. }
  22297. }
  22298. // build geometry
  22299. this.setIndex( indices );
  22300. this.addAttribute( 'position', vertices );
  22301. this.addAttribute( 'uv', uvs );
  22302. // generate normals
  22303. this.computeVertexNormals();
  22304. // if the geometry is closed, we need to average the normals along the seam.
  22305. // because the corresponding vertices are identical (but still have different UVs).
  22306. if( phiLength === Math.PI * 2 ) {
  22307. var normals = this.attributes.normal.array;
  22308. var n1 = new THREE.Vector3();
  22309. var n2 = new THREE.Vector3();
  22310. var n = new THREE.Vector3();
  22311. // this is the buffer offset for the last line of vertices
  22312. base = segments * points.length * 3;
  22313. for( i = 0, j = 0; i < points.length; i ++, j += 3 ) {
  22314. // select the normal of the vertex in the first line
  22315. n1.x = normals[ j + 0 ];
  22316. n1.y = normals[ j + 1 ];
  22317. n1.z = normals[ j + 2 ];
  22318. // select the normal of the vertex in the last line
  22319. n2.x = normals[ base + j + 0 ];
  22320. n2.y = normals[ base + j + 1 ];
  22321. n2.z = normals[ base + j + 2 ];
  22322. // average normals
  22323. n.addVectors( n1, n2 ).normalize();
  22324. // assign the new values to both normals
  22325. normals[ j + 0 ] = normals[ base + j + 0 ] = n.x;
  22326. normals[ j + 1 ] = normals[ base + j + 1 ] = n.y;
  22327. normals[ j + 2 ] = normals[ base + j + 2 ] = n.z;
  22328. } // next row
  22329. }
  22330. };
  22331. THREE.LatheBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  22332. THREE.LatheBufferGeometry.prototype.constructor = THREE.LatheBufferGeometry;
  22333. // File:src/extras/geometries/LatheGeometry.js
  22334. /**
  22335. * @author astrodud / http://astrodud.isgreat.org/
  22336. * @author zz85 / https://github.com/zz85
  22337. * @author bhouston / http://clara.io
  22338. */
  22339. // points - to create a closed torus, one must use a set of points
  22340. // like so: [ a, b, c, d, a ], see first is the same as last.
  22341. // segments - the number of circumference segments to create
  22342. // phiStart - the starting radian
  22343. // phiLength - the radian (0 to 2PI) range of the lathed section
  22344. // 2PI is a closed lathe, less than 2PI is a portion.
  22345. THREE.LatheGeometry = function ( points, segments, phiStart, phiLength ) {
  22346. THREE.Geometry.call( this );
  22347. this.type = 'LatheGeometry';
  22348. this.parameters = {
  22349. points: points,
  22350. segments: segments,
  22351. phiStart: phiStart,
  22352. phiLength: phiLength
  22353. };
  22354. this.fromBufferGeometry( new THREE.LatheBufferGeometry( points, segments, phiStart, phiLength ) );
  22355. this.mergeVertices();
  22356. };
  22357. THREE.LatheGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22358. THREE.LatheGeometry.prototype.constructor = THREE.LatheGeometry;
  22359. // File:src/extras/geometries/PlaneGeometry.js
  22360. /**
  22361. * @author mrdoob / http://mrdoob.com/
  22362. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
  22363. */
  22364. THREE.PlaneGeometry = function ( width, height, widthSegments, heightSegments ) {
  22365. THREE.Geometry.call( this );
  22366. this.type = 'PlaneGeometry';
  22367. this.parameters = {
  22368. width: width,
  22369. height: height,
  22370. widthSegments: widthSegments,
  22371. heightSegments: heightSegments
  22372. };
  22373. this.fromBufferGeometry( new THREE.PlaneBufferGeometry( width, height, widthSegments, heightSegments ) );
  22374. };
  22375. THREE.PlaneGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22376. THREE.PlaneGeometry.prototype.constructor = THREE.PlaneGeometry;
  22377. // File:src/extras/geometries/PlaneBufferGeometry.js
  22378. /**
  22379. * @author mrdoob / http://mrdoob.com/
  22380. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
  22381. */
  22382. THREE.PlaneBufferGeometry = function ( width, height, widthSegments, heightSegments ) {
  22383. THREE.BufferGeometry.call( this );
  22384. this.type = 'PlaneBufferGeometry';
  22385. this.parameters = {
  22386. width: width,
  22387. height: height,
  22388. widthSegments: widthSegments,
  22389. heightSegments: heightSegments
  22390. };
  22391. var width_half = width / 2;
  22392. var height_half = height / 2;
  22393. var gridX = Math.floor( widthSegments ) || 1;
  22394. var gridY = Math.floor( heightSegments ) || 1;
  22395. var gridX1 = gridX + 1;
  22396. var gridY1 = gridY + 1;
  22397. var segment_width = width / gridX;
  22398. var segment_height = height / gridY;
  22399. var vertices = new Float32Array( gridX1 * gridY1 * 3 );
  22400. var normals = new Float32Array( gridX1 * gridY1 * 3 );
  22401. var uvs = new Float32Array( gridX1 * gridY1 * 2 );
  22402. var offset = 0;
  22403. var offset2 = 0;
  22404. for ( var iy = 0; iy < gridY1; iy ++ ) {
  22405. var y = iy * segment_height - height_half;
  22406. for ( var ix = 0; ix < gridX1; ix ++ ) {
  22407. var x = ix * segment_width - width_half;
  22408. vertices[ offset ] = x;
  22409. vertices[ offset + 1 ] = - y;
  22410. normals[ offset + 2 ] = 1;
  22411. uvs[ offset2 ] = ix / gridX;
  22412. uvs[ offset2 + 1 ] = 1 - ( iy / gridY );
  22413. offset += 3;
  22414. offset2 += 2;
  22415. }
  22416. }
  22417. offset = 0;
  22418. var indices = new ( ( vertices.length / 3 ) > 65535 ? Uint32Array : Uint16Array )( gridX * gridY * 6 );
  22419. for ( var iy = 0; iy < gridY; iy ++ ) {
  22420. for ( var ix = 0; ix < gridX; ix ++ ) {
  22421. var a = ix + gridX1 * iy;
  22422. var b = ix + gridX1 * ( iy + 1 );
  22423. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  22424. var d = ( ix + 1 ) + gridX1 * iy;
  22425. indices[ offset ] = a;
  22426. indices[ offset + 1 ] = b;
  22427. indices[ offset + 2 ] = d;
  22428. indices[ offset + 3 ] = b;
  22429. indices[ offset + 4 ] = c;
  22430. indices[ offset + 5 ] = d;
  22431. offset += 6;
  22432. }
  22433. }
  22434. this.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  22435. this.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  22436. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  22437. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  22438. };
  22439. THREE.PlaneBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  22440. THREE.PlaneBufferGeometry.prototype.constructor = THREE.PlaneBufferGeometry;
  22441. // File:src/extras/geometries/RingBufferGeometry.js
  22442. /**
  22443. * @author Mugen87 / https://github.com/Mugen87
  22444. */
  22445. THREE.RingBufferGeometry = function ( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  22446. THREE.BufferGeometry.call( this );
  22447. this.type = 'RingBufferGeometry';
  22448. this.parameters = {
  22449. innerRadius: innerRadius,
  22450. outerRadius: outerRadius,
  22451. thetaSegments: thetaSegments,
  22452. phiSegments: phiSegments,
  22453. thetaStart: thetaStart,
  22454. thetaLength: thetaLength
  22455. };
  22456. innerRadius = innerRadius || 20;
  22457. outerRadius = outerRadius || 50;
  22458. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  22459. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  22460. thetaSegments = thetaSegments !== undefined ? Math.max( 3, thetaSegments ) : 8;
  22461. phiSegments = phiSegments !== undefined ? Math.max( 1, phiSegments ) : 1;
  22462. // these are used to calculate buffer length
  22463. var vertexCount = ( thetaSegments + 1 ) * ( phiSegments + 1 );
  22464. var indexCount = thetaSegments * phiSegments * 2 * 3;
  22465. // buffers
  22466. var indices = new THREE.BufferAttribute( new ( indexCount > 65535 ? Uint32Array : Uint16Array )( indexCount ) , 1 );
  22467. var vertices = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  22468. var normals = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  22469. var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
  22470. // some helper variables
  22471. var index = 0, indexOffset = 0, segment;
  22472. var radius = innerRadius;
  22473. var radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  22474. var vertex = new THREE.Vector3();
  22475. var uv = new THREE.Vector2();
  22476. var j, i;
  22477. // generate vertices, normals and uvs
  22478. // values are generate from the inside of the ring to the outside
  22479. for ( j = 0; j <= phiSegments; j ++ ) {
  22480. for ( i = 0; i <= thetaSegments; i ++ ) {
  22481. segment = thetaStart + i / thetaSegments * thetaLength;
  22482. // vertex
  22483. vertex.x = radius * Math.cos( segment );
  22484. vertex.y = radius * Math.sin( segment );
  22485. vertices.setXYZ( index, vertex.x, vertex.y, vertex.z );
  22486. // normal
  22487. normals.setXYZ( index, 0, 0, 1 );
  22488. // uv
  22489. uv.x = ( vertex.x / outerRadius + 1 ) / 2;
  22490. uv.y = ( vertex.y / outerRadius + 1 ) / 2;
  22491. uvs.setXY( index, uv.x, uv.y );
  22492. // increase index
  22493. index++;
  22494. }
  22495. // increase the radius for next row of vertices
  22496. radius += radiusStep;
  22497. }
  22498. // generate indices
  22499. for ( j = 0; j < phiSegments; j ++ ) {
  22500. var thetaSegmentLevel = j * ( thetaSegments + 1 );
  22501. for ( i = 0; i < thetaSegments; i ++ ) {
  22502. segment = i + thetaSegmentLevel;
  22503. // indices
  22504. var a = segment;
  22505. var b = segment + thetaSegments + 1;
  22506. var c = segment + thetaSegments + 2;
  22507. var d = segment + 1;
  22508. // face one
  22509. indices.setX( indexOffset, a ); indexOffset++;
  22510. indices.setX( indexOffset, b ); indexOffset++;
  22511. indices.setX( indexOffset, c ); indexOffset++;
  22512. // face two
  22513. indices.setX( indexOffset, a ); indexOffset++;
  22514. indices.setX( indexOffset, c ); indexOffset++;
  22515. indices.setX( indexOffset, d ); indexOffset++;
  22516. }
  22517. }
  22518. // build geometry
  22519. this.setIndex( indices );
  22520. this.addAttribute( 'position', vertices );
  22521. this.addAttribute( 'normal', normals );
  22522. this.addAttribute( 'uv', uvs );
  22523. };
  22524. THREE.RingBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  22525. THREE.RingBufferGeometry.prototype.constructor = THREE.RingBufferGeometry;
  22526. // File:src/extras/geometries/RingGeometry.js
  22527. /**
  22528. * @author Kaleb Murphy
  22529. */
  22530. THREE.RingGeometry = function ( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  22531. THREE.Geometry.call( this );
  22532. this.type = 'RingGeometry';
  22533. this.parameters = {
  22534. innerRadius: innerRadius,
  22535. outerRadius: outerRadius,
  22536. thetaSegments: thetaSegments,
  22537. phiSegments: phiSegments,
  22538. thetaStart: thetaStart,
  22539. thetaLength: thetaLength
  22540. };
  22541. this.fromBufferGeometry( new THREE.RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) );
  22542. };
  22543. THREE.RingGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22544. THREE.RingGeometry.prototype.constructor = THREE.RingGeometry;
  22545. // File:src/extras/geometries/SphereGeometry.js
  22546. /**
  22547. * @author mrdoob / http://mrdoob.com/
  22548. */
  22549. THREE.SphereGeometry = function ( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  22550. THREE.Geometry.call( this );
  22551. this.type = 'SphereGeometry';
  22552. this.parameters = {
  22553. radius: radius,
  22554. widthSegments: widthSegments,
  22555. heightSegments: heightSegments,
  22556. phiStart: phiStart,
  22557. phiLength: phiLength,
  22558. thetaStart: thetaStart,
  22559. thetaLength: thetaLength
  22560. };
  22561. this.fromBufferGeometry( new THREE.SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) );
  22562. };
  22563. THREE.SphereGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22564. THREE.SphereGeometry.prototype.constructor = THREE.SphereGeometry;
  22565. // File:src/extras/geometries/SphereBufferGeometry.js
  22566. /**
  22567. * @author benaadams / https://twitter.com/ben_a_adams
  22568. * based on THREE.SphereGeometry
  22569. */
  22570. THREE.SphereBufferGeometry = function ( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  22571. THREE.BufferGeometry.call( this );
  22572. this.type = 'SphereBufferGeometry';
  22573. this.parameters = {
  22574. radius: radius,
  22575. widthSegments: widthSegments,
  22576. heightSegments: heightSegments,
  22577. phiStart: phiStart,
  22578. phiLength: phiLength,
  22579. thetaStart: thetaStart,
  22580. thetaLength: thetaLength
  22581. };
  22582. radius = radius || 50;
  22583. widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
  22584. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  22585. phiStart = phiStart !== undefined ? phiStart : 0;
  22586. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  22587. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  22588. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  22589. var thetaEnd = thetaStart + thetaLength;
  22590. var vertexCount = ( ( widthSegments + 1 ) * ( heightSegments + 1 ) );
  22591. var positions = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  22592. var normals = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  22593. var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
  22594. var index = 0, vertices = [], normal = new THREE.Vector3();
  22595. for ( var y = 0; y <= heightSegments; y ++ ) {
  22596. var verticesRow = [];
  22597. var v = y / heightSegments;
  22598. for ( var x = 0; x <= widthSegments; x ++ ) {
  22599. var u = x / widthSegments;
  22600. var px = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  22601. var py = radius * Math.cos( thetaStart + v * thetaLength );
  22602. var pz = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  22603. normal.set( px, py, pz ).normalize();
  22604. positions.setXYZ( index, px, py, pz );
  22605. normals.setXYZ( index, normal.x, normal.y, normal.z );
  22606. uvs.setXY( index, u, 1 - v );
  22607. verticesRow.push( index );
  22608. index ++;
  22609. }
  22610. vertices.push( verticesRow );
  22611. }
  22612. var indices = [];
  22613. for ( var y = 0; y < heightSegments; y ++ ) {
  22614. for ( var x = 0; x < widthSegments; x ++ ) {
  22615. var v1 = vertices[ y ][ x + 1 ];
  22616. var v2 = vertices[ y ][ x ];
  22617. var v3 = vertices[ y + 1 ][ x ];
  22618. var v4 = vertices[ y + 1 ][ x + 1 ];
  22619. if ( y !== 0 || thetaStart > 0 ) indices.push( v1, v2, v4 );
  22620. if ( y !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( v2, v3, v4 );
  22621. }
  22622. }
  22623. this.setIndex( new ( positions.count > 65535 ? THREE.Uint32Attribute : THREE.Uint16Attribute )( indices, 1 ) );
  22624. this.addAttribute( 'position', positions );
  22625. this.addAttribute( 'normal', normals );
  22626. this.addAttribute( 'uv', uvs );
  22627. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  22628. };
  22629. THREE.SphereBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  22630. THREE.SphereBufferGeometry.prototype.constructor = THREE.SphereBufferGeometry;
  22631. // File:src/extras/geometries/TextGeometry.js
  22632. /**
  22633. * @author zz85 / http://www.lab4games.net/zz85/blog
  22634. * @author alteredq / http://alteredqualia.com/
  22635. *
  22636. * Text = 3D Text
  22637. *
  22638. * parameters = {
  22639. * font: <THREE.Font>, // font
  22640. *
  22641. * size: <float>, // size of the text
  22642. * height: <float>, // thickness to extrude text
  22643. * curveSegments: <int>, // number of points on the curves
  22644. *
  22645. * bevelEnabled: <bool>, // turn on bevel
  22646. * bevelThickness: <float>, // how deep into text bevel goes
  22647. * bevelSize: <float> // how far from text outline is bevel
  22648. * }
  22649. */
  22650. THREE.TextGeometry = function ( text, parameters ) {
  22651. parameters = parameters || {};
  22652. var font = parameters.font;
  22653. if ( font instanceof THREE.Font === false ) {
  22654. console.error( 'THREE.TextGeometry: font parameter is not an instance of THREE.Font.' );
  22655. return new THREE.Geometry();
  22656. }
  22657. var shapes = font.generateShapes( text, parameters.size, parameters.curveSegments );
  22658. // translate parameters to ExtrudeGeometry API
  22659. parameters.amount = parameters.height !== undefined ? parameters.height : 50;
  22660. // defaults
  22661. if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
  22662. if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
  22663. if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
  22664. THREE.ExtrudeGeometry.call( this, shapes, parameters );
  22665. this.type = 'TextGeometry';
  22666. };
  22667. THREE.TextGeometry.prototype = Object.create( THREE.ExtrudeGeometry.prototype );
  22668. THREE.TextGeometry.prototype.constructor = THREE.TextGeometry;
  22669. // File:src/extras/geometries/TorusBufferGeometry.js
  22670. /**
  22671. * @author Mugen87 / https://github.com/Mugen87
  22672. */
  22673. THREE.TorusBufferGeometry = function ( radius, tube, radialSegments, tubularSegments, arc ) {
  22674. THREE.BufferGeometry.call( this );
  22675. this.type = 'TorusBufferGeometry';
  22676. this.parameters = {
  22677. radius: radius,
  22678. tube: tube,
  22679. radialSegments: radialSegments,
  22680. tubularSegments: tubularSegments,
  22681. arc: arc
  22682. };
  22683. radius = radius || 100;
  22684. tube = tube || 40;
  22685. radialSegments = Math.floor( radialSegments ) || 8;
  22686. tubularSegments = Math.floor( tubularSegments ) || 6;
  22687. arc = arc || Math.PI * 2;
  22688. // used to calculate buffer length
  22689. var vertexCount = ( ( radialSegments + 1 ) * ( tubularSegments + 1 ) );
  22690. var indexCount = radialSegments * tubularSegments * 2 * 3;
  22691. // buffers
  22692. var indices = new ( indexCount > 65535 ? Uint32Array : Uint16Array )( indexCount );
  22693. var vertices = new Float32Array( vertexCount * 3 );
  22694. var normals = new Float32Array( vertexCount * 3 );
  22695. var uvs = new Float32Array( vertexCount * 2 );
  22696. // offset variables
  22697. var vertexBufferOffset = 0;
  22698. var uvBufferOffset = 0;
  22699. var indexBufferOffset = 0;
  22700. // helper variables
  22701. var center = new THREE.Vector3();
  22702. var vertex = new THREE.Vector3();
  22703. var normal = new THREE.Vector3();
  22704. var j, i;
  22705. // generate vertices, normals and uvs
  22706. for ( j = 0; j <= radialSegments; j ++ ) {
  22707. for ( i = 0; i <= tubularSegments; i ++ ) {
  22708. var u = i / tubularSegments * arc;
  22709. var v = j / radialSegments * Math.PI * 2;
  22710. // vertex
  22711. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  22712. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  22713. vertex.z = tube * Math.sin( v );
  22714. vertices[ vertexBufferOffset ] = vertex.x;
  22715. vertices[ vertexBufferOffset + 1 ] = vertex.y;
  22716. vertices[ vertexBufferOffset + 2 ] = vertex.z;
  22717. // this vector is used to calculate the normal
  22718. center.x = radius * Math.cos( u );
  22719. center.y = radius * Math.sin( u );
  22720. // normal
  22721. normal.subVectors( vertex, center ).normalize();
  22722. normals[ vertexBufferOffset ] = normal.x;
  22723. normals[ vertexBufferOffset + 1 ] = normal.y;
  22724. normals[ vertexBufferOffset + 2 ] = normal.z;
  22725. // uv
  22726. uvs[ uvBufferOffset ] = i / tubularSegments;
  22727. uvs[ uvBufferOffset + 1 ] = j / radialSegments;
  22728. // update offsets
  22729. vertexBufferOffset += 3;
  22730. uvBufferOffset += 2;
  22731. }
  22732. }
  22733. // generate indices
  22734. for ( j = 1; j <= radialSegments; j ++ ) {
  22735. for ( i = 1; i <= tubularSegments; i ++ ) {
  22736. // indices
  22737. var a = ( tubularSegments + 1 ) * j + i - 1;
  22738. var b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  22739. var c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  22740. var d = ( tubularSegments + 1 ) * j + i;
  22741. // face one
  22742. indices[ indexBufferOffset ] = a;
  22743. indices[ indexBufferOffset + 1 ] = b;
  22744. indices[ indexBufferOffset + 2 ] = d;
  22745. // face two
  22746. indices[ indexBufferOffset + 3 ] = b;
  22747. indices[ indexBufferOffset + 4 ] = c;
  22748. indices[ indexBufferOffset + 5 ] = d;
  22749. // update offset
  22750. indexBufferOffset += 6;
  22751. }
  22752. }
  22753. // build geometry
  22754. this.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  22755. this.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  22756. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  22757. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  22758. };
  22759. THREE.TorusBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  22760. THREE.TorusBufferGeometry.prototype.constructor = THREE.TorusBufferGeometry;
  22761. // File:src/extras/geometries/TorusGeometry.js
  22762. /**
  22763. * @author oosmoxiecode
  22764. * @author mrdoob / http://mrdoob.com/
  22765. * based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3DLite/src/away3dlite/primitives/Torus.as?r=2888
  22766. */
  22767. THREE.TorusGeometry = function ( radius, tube, radialSegments, tubularSegments, arc ) {
  22768. THREE.Geometry.call( this );
  22769. this.type = 'TorusGeometry';
  22770. this.parameters = {
  22771. radius: radius,
  22772. tube: tube,
  22773. radialSegments: radialSegments,
  22774. tubularSegments: tubularSegments,
  22775. arc: arc
  22776. };
  22777. this.fromBufferGeometry( new THREE.TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) );
  22778. };
  22779. THREE.TorusGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22780. THREE.TorusGeometry.prototype.constructor = THREE.TorusGeometry;
  22781. // File:src/extras/geometries/TorusKnotBufferGeometry.js
  22782. /**
  22783. * @author Mugen87 / https://github.com/Mugen87
  22784. *
  22785. * see: http://www.blackpawn.com/texts/pqtorus/
  22786. */
  22787. THREE.TorusKnotBufferGeometry = function ( radius, tube, tubularSegments, radialSegments, p, q ) {
  22788. THREE.BufferGeometry.call( this );
  22789. this.type = 'TorusKnotBufferGeometry';
  22790. this.parameters = {
  22791. radius: radius,
  22792. tube: tube,
  22793. tubularSegments: tubularSegments,
  22794. radialSegments: radialSegments,
  22795. p: p,
  22796. q: q
  22797. };
  22798. radius = radius || 100;
  22799. tube = tube || 40;
  22800. tubularSegments = Math.floor( tubularSegments ) || 64;
  22801. radialSegments = Math.floor( radialSegments ) || 8;
  22802. p = p || 2;
  22803. q = q || 3;
  22804. // used to calculate buffer length
  22805. var vertexCount = ( ( radialSegments + 1 ) * ( tubularSegments + 1 ) );
  22806. var indexCount = radialSegments * tubularSegments * 2 * 3;
  22807. // buffers
  22808. var indices = new THREE.BufferAttribute( new ( indexCount > 65535 ? Uint32Array : Uint16Array )( indexCount ) , 1 );
  22809. var vertices = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  22810. var normals = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  22811. var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
  22812. // helper variables
  22813. var i, j, index = 0, indexOffset = 0;
  22814. var vertex = new THREE.Vector3();
  22815. var normal = new THREE.Vector3();
  22816. var uv = new THREE.Vector2();
  22817. var P1 = new THREE.Vector3();
  22818. var P2 = new THREE.Vector3();
  22819. var B = new THREE.Vector3();
  22820. var T = new THREE.Vector3();
  22821. var N = new THREE.Vector3();
  22822. // generate vertices, normals and uvs
  22823. for ( i = 0; i <= tubularSegments; ++ i ) {
  22824. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  22825. var u = i / tubularSegments * p * Math.PI * 2;
  22826. // now we calculate two points. P1 is our current position on the curve, P2 is a little farther ahead.
  22827. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  22828. calculatePositionOnCurve( u, p, q, radius, P1 );
  22829. calculatePositionOnCurve( u + 0.01, p, q, radius, P2 );
  22830. // calculate orthonormal basis
  22831. T.subVectors( P2, P1 );
  22832. N.addVectors( P2, P1 );
  22833. B.crossVectors( T, N );
  22834. N.crossVectors( B, T );
  22835. // normalize B, N. T can be ignored, we don't use it
  22836. B.normalize();
  22837. N.normalize();
  22838. for ( j = 0; j <= radialSegments; ++ j ) {
  22839. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  22840. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  22841. var v = j / radialSegments * Math.PI * 2;
  22842. var cx = - tube * Math.cos( v );
  22843. var cy = tube * Math.sin( v );
  22844. // now calculate the final vertex position.
  22845. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  22846. vertex.x = P1.x + ( cx * N.x + cy * B.x );
  22847. vertex.y = P1.y + ( cx * N.y + cy * B.y );
  22848. vertex.z = P1.z + ( cx * N.z + cy * B.z );
  22849. // vertex
  22850. vertices.setXYZ( index, vertex.x, vertex.y, vertex.z );
  22851. // normal (P1 is always the center/origin of the extrusion, thus we can use it to calculate the normal)
  22852. normal.subVectors( vertex, P1 ).normalize();
  22853. normals.setXYZ( index, normal.x, normal.y, normal.z );
  22854. // uv
  22855. uv.x = i / tubularSegments;
  22856. uv.y = j / radialSegments;
  22857. uvs.setXY( index, uv.x, uv.y );
  22858. // increase index
  22859. index ++;
  22860. }
  22861. }
  22862. // generate indices
  22863. for ( j = 1; j <= tubularSegments; j ++ ) {
  22864. for ( i = 1; i <= radialSegments; i ++ ) {
  22865. // indices
  22866. var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  22867. var b = ( radialSegments + 1 ) * j + ( i - 1 );
  22868. var c = ( radialSegments + 1 ) * j + i;
  22869. var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  22870. // face one
  22871. indices.setX( indexOffset, a ); indexOffset++;
  22872. indices.setX( indexOffset, b ); indexOffset++;
  22873. indices.setX( indexOffset, d ); indexOffset++;
  22874. // face two
  22875. indices.setX( indexOffset, b ); indexOffset++;
  22876. indices.setX( indexOffset, c ); indexOffset++;
  22877. indices.setX( indexOffset, d ); indexOffset++;
  22878. }
  22879. }
  22880. // build geometry
  22881. this.setIndex( indices );
  22882. this.addAttribute( 'position', vertices );
  22883. this.addAttribute( 'normal', normals );
  22884. this.addAttribute( 'uv', uvs );
  22885. // this function calculates the current position on the torus curve
  22886. function calculatePositionOnCurve( u, p, q, radius, position ) {
  22887. var cu = Math.cos( u );
  22888. var su = Math.sin( u );
  22889. var quOverP = q / p * u;
  22890. var cs = Math.cos( quOverP );
  22891. position.x = radius * ( 2 + cs ) * 0.5 * cu;
  22892. position.y = radius * ( 2 + cs ) * su * 0.5;
  22893. position.z = radius * Math.sin( quOverP ) * 0.5;
  22894. }
  22895. };
  22896. THREE.TorusKnotBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  22897. THREE.TorusKnotBufferGeometry.prototype.constructor = THREE.TorusKnotBufferGeometry;
  22898. // File:src/extras/geometries/TorusKnotGeometry.js
  22899. /**
  22900. * @author oosmoxiecode
  22901. */
  22902. THREE.TorusKnotGeometry = function ( radius, tube, tubularSegments, radialSegments, p, q, heightScale ) {
  22903. THREE.Geometry.call( this );
  22904. this.type = 'TorusKnotGeometry';
  22905. this.parameters = {
  22906. radius: radius,
  22907. tube: tube,
  22908. tubularSegments: tubularSegments,
  22909. radialSegments: radialSegments,
  22910. p: p,
  22911. q: q
  22912. };
  22913. if( heightScale !== undefined ) console.warn( 'THREE.TorusKnotGeometry: heightScale has been deprecated. Use .scale( x, y, z ) instead.' );
  22914. this.fromBufferGeometry( new THREE.TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) );
  22915. this.mergeVertices();
  22916. };
  22917. THREE.TorusKnotGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22918. THREE.TorusKnotGeometry.prototype.constructor = THREE.TorusKnotGeometry;
  22919. // File:src/extras/geometries/TubeGeometry.js
  22920. /**
  22921. * @author WestLangley / https://github.com/WestLangley
  22922. * @author zz85 / https://github.com/zz85
  22923. * @author miningold / https://github.com/miningold
  22924. * @author jonobr1 / https://github.com/jonobr1
  22925. *
  22926. * Modified from the TorusKnotGeometry by @oosmoxiecode
  22927. *
  22928. * Creates a tube which extrudes along a 3d spline
  22929. *
  22930. * Uses parallel transport frames as described in
  22931. * http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  22932. */
  22933. THREE.TubeGeometry = function ( path, segments, radius, radialSegments, closed, taper ) {
  22934. THREE.Geometry.call( this );
  22935. this.type = 'TubeGeometry';
  22936. this.parameters = {
  22937. path: path,
  22938. segments: segments,
  22939. radius: radius,
  22940. radialSegments: radialSegments,
  22941. closed: closed,
  22942. taper: taper
  22943. };
  22944. segments = segments || 64;
  22945. radius = radius || 1;
  22946. radialSegments = radialSegments || 8;
  22947. closed = closed || false;
  22948. taper = taper || THREE.TubeGeometry.NoTaper;
  22949. var grid = [];
  22950. var scope = this,
  22951. tangent,
  22952. normal,
  22953. binormal,
  22954. numpoints = segments + 1,
  22955. u, v, r,
  22956. cx, cy,
  22957. pos, pos2 = new THREE.Vector3(),
  22958. i, j,
  22959. ip, jp,
  22960. a, b, c, d,
  22961. uva, uvb, uvc, uvd;
  22962. var frames = new THREE.TubeGeometry.FrenetFrames( path, segments, closed ),
  22963. tangents = frames.tangents,
  22964. normals = frames.normals,
  22965. binormals = frames.binormals;
  22966. // proxy internals
  22967. this.tangents = tangents;
  22968. this.normals = normals;
  22969. this.binormals = binormals;
  22970. function vert( x, y, z ) {
  22971. return scope.vertices.push( new THREE.Vector3( x, y, z ) ) - 1;
  22972. }
  22973. // construct the grid
  22974. for ( i = 0; i < numpoints; i ++ ) {
  22975. grid[ i ] = [];
  22976. u = i / ( numpoints - 1 );
  22977. pos = path.getPointAt( u );
  22978. tangent = tangents[ i ];
  22979. normal = normals[ i ];
  22980. binormal = binormals[ i ];
  22981. r = radius * taper( u );
  22982. for ( j = 0; j < radialSegments; j ++ ) {
  22983. v = j / radialSegments * 2 * Math.PI;
  22984. cx = - r * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
  22985. cy = r * Math.sin( v );
  22986. pos2.copy( pos );
  22987. pos2.x += cx * normal.x + cy * binormal.x;
  22988. pos2.y += cx * normal.y + cy * binormal.y;
  22989. pos2.z += cx * normal.z + cy * binormal.z;
  22990. grid[ i ][ j ] = vert( pos2.x, pos2.y, pos2.z );
  22991. }
  22992. }
  22993. // construct the mesh
  22994. for ( i = 0; i < segments; i ++ ) {
  22995. for ( j = 0; j < radialSegments; j ++ ) {
  22996. ip = ( closed ) ? ( i + 1 ) % segments : i + 1;
  22997. jp = ( j + 1 ) % radialSegments;
  22998. a = grid[ i ][ j ]; // *** NOT NECESSARILY PLANAR ! ***
  22999. b = grid[ ip ][ j ];
  23000. c = grid[ ip ][ jp ];
  23001. d = grid[ i ][ jp ];
  23002. uva = new THREE.Vector2( i / segments, j / radialSegments );
  23003. uvb = new THREE.Vector2( ( i + 1 ) / segments, j / radialSegments );
  23004. uvc = new THREE.Vector2( ( i + 1 ) / segments, ( j + 1 ) / radialSegments );
  23005. uvd = new THREE.Vector2( i / segments, ( j + 1 ) / radialSegments );
  23006. this.faces.push( new THREE.Face3( a, b, d ) );
  23007. this.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  23008. this.faces.push( new THREE.Face3( b, c, d ) );
  23009. this.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  23010. }
  23011. }
  23012. this.computeFaceNormals();
  23013. this.computeVertexNormals();
  23014. };
  23015. THREE.TubeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  23016. THREE.TubeGeometry.prototype.constructor = THREE.TubeGeometry;
  23017. THREE.TubeGeometry.NoTaper = function ( u ) {
  23018. return 1;
  23019. };
  23020. THREE.TubeGeometry.SinusoidalTaper = function ( u ) {
  23021. return Math.sin( Math.PI * u );
  23022. };
  23023. // For computing of Frenet frames, exposing the tangents, normals and binormals the spline
  23024. THREE.TubeGeometry.FrenetFrames = function ( path, segments, closed ) {
  23025. var normal = new THREE.Vector3(),
  23026. tangents = [],
  23027. normals = [],
  23028. binormals = [],
  23029. vec = new THREE.Vector3(),
  23030. mat = new THREE.Matrix4(),
  23031. numpoints = segments + 1,
  23032. theta,
  23033. smallest,
  23034. tx, ty, tz,
  23035. i, u;
  23036. // expose internals
  23037. this.tangents = tangents;
  23038. this.normals = normals;
  23039. this.binormals = binormals;
  23040. // compute the tangent vectors for each segment on the path
  23041. for ( i = 0; i < numpoints; i ++ ) {
  23042. u = i / ( numpoints - 1 );
  23043. tangents[ i ] = path.getTangentAt( u );
  23044. tangents[ i ].normalize();
  23045. }
  23046. initialNormal3();
  23047. /*
  23048. function initialNormal1(lastBinormal) {
  23049. // fixed start binormal. Has dangers of 0 vectors
  23050. normals[ 0 ] = new THREE.Vector3();
  23051. binormals[ 0 ] = new THREE.Vector3();
  23052. if (lastBinormal===undefined) lastBinormal = new THREE.Vector3( 0, 0, 1 );
  23053. normals[ 0 ].crossVectors( lastBinormal, tangents[ 0 ] ).normalize();
  23054. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] ).normalize();
  23055. }
  23056. function initialNormal2() {
  23057. // This uses the Frenet-Serret formula for deriving binormal
  23058. var t2 = path.getTangentAt( epsilon );
  23059. normals[ 0 ] = new THREE.Vector3().subVectors( t2, tangents[ 0 ] ).normalize();
  23060. binormals[ 0 ] = new THREE.Vector3().crossVectors( tangents[ 0 ], normals[ 0 ] );
  23061. normals[ 0 ].crossVectors( binormals[ 0 ], tangents[ 0 ] ).normalize(); // last binormal x tangent
  23062. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] ).normalize();
  23063. }
  23064. */
  23065. function initialNormal3() {
  23066. // select an initial normal vector perpendicular to the first tangent vector,
  23067. // and in the direction of the smallest tangent xyz component
  23068. normals[ 0 ] = new THREE.Vector3();
  23069. binormals[ 0 ] = new THREE.Vector3();
  23070. smallest = Number.MAX_VALUE;
  23071. tx = Math.abs( tangents[ 0 ].x );
  23072. ty = Math.abs( tangents[ 0 ].y );
  23073. tz = Math.abs( tangents[ 0 ].z );
  23074. if ( tx <= smallest ) {
  23075. smallest = tx;
  23076. normal.set( 1, 0, 0 );
  23077. }
  23078. if ( ty <= smallest ) {
  23079. smallest = ty;
  23080. normal.set( 0, 1, 0 );
  23081. }
  23082. if ( tz <= smallest ) {
  23083. normal.set( 0, 0, 1 );
  23084. }
  23085. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  23086. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  23087. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  23088. }
  23089. // compute the slowly-varying normal and binormal vectors for each segment on the path
  23090. for ( i = 1; i < numpoints; i ++ ) {
  23091. normals[ i ] = normals[ i - 1 ].clone();
  23092. binormals[ i ] = binormals[ i - 1 ].clone();
  23093. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  23094. if ( vec.length() > Number.EPSILON ) {
  23095. vec.normalize();
  23096. theta = Math.acos( THREE.Math.clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  23097. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  23098. }
  23099. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  23100. }
  23101. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  23102. if ( closed ) {
  23103. theta = Math.acos( THREE.Math.clamp( normals[ 0 ].dot( normals[ numpoints - 1 ] ), - 1, 1 ) );
  23104. theta /= ( numpoints - 1 );
  23105. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ numpoints - 1 ] ) ) > 0 ) {
  23106. theta = - theta;
  23107. }
  23108. for ( i = 1; i < numpoints; i ++ ) {
  23109. // twist a little...
  23110. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  23111. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  23112. }
  23113. }
  23114. };
  23115. // File:src/extras/geometries/PolyhedronGeometry.js
  23116. /**
  23117. * @author clockworkgeek / https://github.com/clockworkgeek
  23118. * @author timothypratley / https://github.com/timothypratley
  23119. * @author WestLangley / http://github.com/WestLangley
  23120. */
  23121. THREE.PolyhedronGeometry = function ( vertices, indices, radius, detail ) {
  23122. THREE.Geometry.call( this );
  23123. this.type = 'PolyhedronGeometry';
  23124. this.parameters = {
  23125. vertices: vertices,
  23126. indices: indices,
  23127. radius: radius,
  23128. detail: detail
  23129. };
  23130. radius = radius || 1;
  23131. detail = detail || 0;
  23132. var that = this;
  23133. for ( var i = 0, l = vertices.length; i < l; i += 3 ) {
  23134. prepare( new THREE.Vector3( vertices[ i ], vertices[ i + 1 ], vertices[ i + 2 ] ) );
  23135. }
  23136. var p = this.vertices;
  23137. var faces = [];
  23138. for ( var i = 0, j = 0, l = indices.length; i < l; i += 3, j ++ ) {
  23139. var v1 = p[ indices[ i ] ];
  23140. var v2 = p[ indices[ i + 1 ] ];
  23141. var v3 = p[ indices[ i + 2 ] ];
  23142. faces[ j ] = new THREE.Face3( v1.index, v2.index, v3.index, [ v1.clone(), v2.clone(), v3.clone() ], undefined, j );
  23143. }
  23144. var centroid = new THREE.Vector3();
  23145. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  23146. subdivide( faces[ i ], detail );
  23147. }
  23148. // Handle case when face straddles the seam
  23149. for ( var i = 0, l = this.faceVertexUvs[ 0 ].length; i < l; i ++ ) {
  23150. var uvs = this.faceVertexUvs[ 0 ][ i ];
  23151. var x0 = uvs[ 0 ].x;
  23152. var x1 = uvs[ 1 ].x;
  23153. var x2 = uvs[ 2 ].x;
  23154. var max = Math.max( x0, x1, x2 );
  23155. var min = Math.min( x0, x1, x2 );
  23156. if ( max > 0.9 && min < 0.1 ) {
  23157. // 0.9 is somewhat arbitrary
  23158. if ( x0 < 0.2 ) uvs[ 0 ].x += 1;
  23159. if ( x1 < 0.2 ) uvs[ 1 ].x += 1;
  23160. if ( x2 < 0.2 ) uvs[ 2 ].x += 1;
  23161. }
  23162. }
  23163. // Apply radius
  23164. for ( var i = 0, l = this.vertices.length; i < l; i ++ ) {
  23165. this.vertices[ i ].multiplyScalar( radius );
  23166. }
  23167. // Merge vertices
  23168. this.mergeVertices();
  23169. this.computeFaceNormals();
  23170. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  23171. // Project vector onto sphere's surface
  23172. function prepare( vector ) {
  23173. var vertex = vector.normalize().clone();
  23174. vertex.index = that.vertices.push( vertex ) - 1;
  23175. // Texture coords are equivalent to map coords, calculate angle and convert to fraction of a circle.
  23176. var u = azimuth( vector ) / 2 / Math.PI + 0.5;
  23177. var v = inclination( vector ) / Math.PI + 0.5;
  23178. vertex.uv = new THREE.Vector2( u, 1 - v );
  23179. return vertex;
  23180. }
  23181. // Approximate a curved face with recursively sub-divided triangles.
  23182. function make( v1, v2, v3, materialIndex ) {
  23183. var face = new THREE.Face3( v1.index, v2.index, v3.index, [ v1.clone(), v2.clone(), v3.clone() ], undefined, materialIndex );
  23184. that.faces.push( face );
  23185. centroid.copy( v1 ).add( v2 ).add( v3 ).divideScalar( 3 );
  23186. var azi = azimuth( centroid );
  23187. that.faceVertexUvs[ 0 ].push( [
  23188. correctUV( v1.uv, v1, azi ),
  23189. correctUV( v2.uv, v2, azi ),
  23190. correctUV( v3.uv, v3, azi )
  23191. ] );
  23192. }
  23193. // Analytically subdivide a face to the required detail level.
  23194. function subdivide( face, detail ) {
  23195. var cols = Math.pow( 2, detail );
  23196. var a = prepare( that.vertices[ face.a ] );
  23197. var b = prepare( that.vertices[ face.b ] );
  23198. var c = prepare( that.vertices[ face.c ] );
  23199. var v = [];
  23200. var materialIndex = face.materialIndex;
  23201. // Construct all of the vertices for this subdivision.
  23202. for ( var i = 0 ; i <= cols; i ++ ) {
  23203. v[ i ] = [];
  23204. var aj = prepare( a.clone().lerp( c, i / cols ) );
  23205. var bj = prepare( b.clone().lerp( c, i / cols ) );
  23206. var rows = cols - i;
  23207. for ( var j = 0; j <= rows; j ++ ) {
  23208. if ( j === 0 && i === cols ) {
  23209. v[ i ][ j ] = aj;
  23210. } else {
  23211. v[ i ][ j ] = prepare( aj.clone().lerp( bj, j / rows ) );
  23212. }
  23213. }
  23214. }
  23215. // Construct all of the faces.
  23216. for ( var i = 0; i < cols ; i ++ ) {
  23217. for ( var j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
  23218. var k = Math.floor( j / 2 );
  23219. if ( j % 2 === 0 ) {
  23220. make(
  23221. v[ i ][ k + 1 ],
  23222. v[ i + 1 ][ k ],
  23223. v[ i ][ k ],
  23224. materialIndex
  23225. );
  23226. } else {
  23227. make(
  23228. v[ i ][ k + 1 ],
  23229. v[ i + 1 ][ k + 1 ],
  23230. v[ i + 1 ][ k ],
  23231. materialIndex
  23232. );
  23233. }
  23234. }
  23235. }
  23236. }
  23237. // Angle around the Y axis, counter-clockwise when looking from above.
  23238. function azimuth( vector ) {
  23239. return Math.atan2( vector.z, - vector.x );
  23240. }
  23241. // Angle above the XZ plane.
  23242. function inclination( vector ) {
  23243. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  23244. }
  23245. // Texture fixing helper. Spheres have some odd behaviours.
  23246. function correctUV( uv, vector, azimuth ) {
  23247. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) uv = new THREE.Vector2( uv.x - 1, uv.y );
  23248. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) uv = new THREE.Vector2( azimuth / 2 / Math.PI + 0.5, uv.y );
  23249. return uv.clone();
  23250. }
  23251. };
  23252. THREE.PolyhedronGeometry.prototype = Object.create( THREE.Geometry.prototype );
  23253. THREE.PolyhedronGeometry.prototype.constructor = THREE.PolyhedronGeometry;
  23254. // File:src/extras/geometries/DodecahedronGeometry.js
  23255. /**
  23256. * @author Abe Pazos / https://hamoid.com
  23257. */
  23258. THREE.DodecahedronGeometry = function ( radius, detail ) {
  23259. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  23260. var r = 1 / t;
  23261. var vertices = [
  23262. // (±1, ±1, ±1)
  23263. - 1, - 1, - 1, - 1, - 1, 1,
  23264. - 1, 1, - 1, - 1, 1, 1,
  23265. 1, - 1, - 1, 1, - 1, 1,
  23266. 1, 1, - 1, 1, 1, 1,
  23267. // (0, ±1/φ, ±φ)
  23268. 0, - r, - t, 0, - r, t,
  23269. 0, r, - t, 0, r, t,
  23270. // (±1/φ, ±φ, 0)
  23271. - r, - t, 0, - r, t, 0,
  23272. r, - t, 0, r, t, 0,
  23273. // (±φ, 0, ±1/φ)
  23274. - t, 0, - r, t, 0, - r,
  23275. - t, 0, r, t, 0, r
  23276. ];
  23277. var indices = [
  23278. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  23279. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  23280. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  23281. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  23282. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  23283. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  23284. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  23285. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  23286. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  23287. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  23288. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  23289. 1, 12, 14, 1, 14, 5, 1, 5, 9
  23290. ];
  23291. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  23292. this.type = 'DodecahedronGeometry';
  23293. this.parameters = {
  23294. radius: radius,
  23295. detail: detail
  23296. };
  23297. };
  23298. THREE.DodecahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  23299. THREE.DodecahedronGeometry.prototype.constructor = THREE.DodecahedronGeometry;
  23300. // File:src/extras/geometries/IcosahedronGeometry.js
  23301. /**
  23302. * @author timothypratley / https://github.com/timothypratley
  23303. */
  23304. THREE.IcosahedronGeometry = function ( radius, detail ) {
  23305. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  23306. var vertices = [
  23307. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  23308. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  23309. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  23310. ];
  23311. var indices = [
  23312. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  23313. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  23314. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  23315. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  23316. ];
  23317. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  23318. this.type = 'IcosahedronGeometry';
  23319. this.parameters = {
  23320. radius: radius,
  23321. detail: detail
  23322. };
  23323. };
  23324. THREE.IcosahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  23325. THREE.IcosahedronGeometry.prototype.constructor = THREE.IcosahedronGeometry;
  23326. // File:src/extras/geometries/OctahedronGeometry.js
  23327. /**
  23328. * @author timothypratley / https://github.com/timothypratley
  23329. */
  23330. THREE.OctahedronGeometry = function ( radius, detail ) {
  23331. var vertices = [
  23332. 1, 0, 0, - 1, 0, 0, 0, 1, 0, 0, - 1, 0, 0, 0, 1, 0, 0, - 1
  23333. ];
  23334. var indices = [
  23335. 0, 2, 4, 0, 4, 3, 0, 3, 5, 0, 5, 2, 1, 2, 5, 1, 5, 3, 1, 3, 4, 1, 4, 2
  23336. ];
  23337. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  23338. this.type = 'OctahedronGeometry';
  23339. this.parameters = {
  23340. radius: radius,
  23341. detail: detail
  23342. };
  23343. };
  23344. THREE.OctahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  23345. THREE.OctahedronGeometry.prototype.constructor = THREE.OctahedronGeometry;
  23346. // File:src/extras/geometries/TetrahedronGeometry.js
  23347. /**
  23348. * @author timothypratley / https://github.com/timothypratley
  23349. */
  23350. THREE.TetrahedronGeometry = function ( radius, detail ) {
  23351. var vertices = [
  23352. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  23353. ];
  23354. var indices = [
  23355. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  23356. ];
  23357. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  23358. this.type = 'TetrahedronGeometry';
  23359. this.parameters = {
  23360. radius: radius,
  23361. detail: detail
  23362. };
  23363. };
  23364. THREE.TetrahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  23365. THREE.TetrahedronGeometry.prototype.constructor = THREE.TetrahedronGeometry;
  23366. // File:src/extras/geometries/ParametricGeometry.js
  23367. /**
  23368. * @author zz85 / https://github.com/zz85
  23369. * Parametric Surfaces Geometry
  23370. * based on the brilliant article by @prideout http://prideout.net/blog/?p=44
  23371. *
  23372. * new THREE.ParametricGeometry( parametricFunction, uSegments, ySegements );
  23373. *
  23374. */
  23375. THREE.ParametricGeometry = function ( func, slices, stacks ) {
  23376. THREE.Geometry.call( this );
  23377. this.type = 'ParametricGeometry';
  23378. this.parameters = {
  23379. func: func,
  23380. slices: slices,
  23381. stacks: stacks
  23382. };
  23383. var verts = this.vertices;
  23384. var faces = this.faces;
  23385. var uvs = this.faceVertexUvs[ 0 ];
  23386. var i, j, p;
  23387. var u, v;
  23388. var sliceCount = slices + 1;
  23389. for ( i = 0; i <= stacks; i ++ ) {
  23390. v = i / stacks;
  23391. for ( j = 0; j <= slices; j ++ ) {
  23392. u = j / slices;
  23393. p = func( u, v );
  23394. verts.push( p );
  23395. }
  23396. }
  23397. var a, b, c, d;
  23398. var uva, uvb, uvc, uvd;
  23399. for ( i = 0; i < stacks; i ++ ) {
  23400. for ( j = 0; j < slices; j ++ ) {
  23401. a = i * sliceCount + j;
  23402. b = i * sliceCount + j + 1;
  23403. c = ( i + 1 ) * sliceCount + j + 1;
  23404. d = ( i + 1 ) * sliceCount + j;
  23405. uva = new THREE.Vector2( j / slices, i / stacks );
  23406. uvb = new THREE.Vector2( ( j + 1 ) / slices, i / stacks );
  23407. uvc = new THREE.Vector2( ( j + 1 ) / slices, ( i + 1 ) / stacks );
  23408. uvd = new THREE.Vector2( j / slices, ( i + 1 ) / stacks );
  23409. faces.push( new THREE.Face3( a, b, d ) );
  23410. uvs.push( [ uva, uvb, uvd ] );
  23411. faces.push( new THREE.Face3( b, c, d ) );
  23412. uvs.push( [ uvb.clone(), uvc, uvd.clone() ] );
  23413. }
  23414. }
  23415. // console.log(this);
  23416. // magic bullet
  23417. // var diff = this.mergeVertices();
  23418. // console.log('removed ', diff, ' vertices by merging');
  23419. this.computeFaceNormals();
  23420. this.computeVertexNormals();
  23421. };
  23422. THREE.ParametricGeometry.prototype = Object.create( THREE.Geometry.prototype );
  23423. THREE.ParametricGeometry.prototype.constructor = THREE.ParametricGeometry;
  23424. // File:src/extras/geometries/WireframeGeometry.js
  23425. /**
  23426. * @author mrdoob / http://mrdoob.com/
  23427. */
  23428. THREE.WireframeGeometry = function ( geometry ) {
  23429. THREE.BufferGeometry.call( this );
  23430. var edge = [ 0, 0 ], hash = {};
  23431. function sortFunction( a, b ) {
  23432. return a - b;
  23433. }
  23434. var keys = [ 'a', 'b', 'c' ];
  23435. if ( geometry instanceof THREE.Geometry ) {
  23436. var vertices = geometry.vertices;
  23437. var faces = geometry.faces;
  23438. var numEdges = 0;
  23439. // allocate maximal size
  23440. var edges = new Uint32Array( 6 * faces.length );
  23441. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  23442. var face = faces[ i ];
  23443. for ( var j = 0; j < 3; j ++ ) {
  23444. edge[ 0 ] = face[ keys[ j ] ];
  23445. edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
  23446. edge.sort( sortFunction );
  23447. var key = edge.toString();
  23448. if ( hash[ key ] === undefined ) {
  23449. edges[ 2 * numEdges ] = edge[ 0 ];
  23450. edges[ 2 * numEdges + 1 ] = edge[ 1 ];
  23451. hash[ key ] = true;
  23452. numEdges ++;
  23453. }
  23454. }
  23455. }
  23456. var coords = new Float32Array( numEdges * 2 * 3 );
  23457. for ( var i = 0, l = numEdges; i < l; i ++ ) {
  23458. for ( var j = 0; j < 2; j ++ ) {
  23459. var vertex = vertices[ edges [ 2 * i + j ] ];
  23460. var index = 6 * i + 3 * j;
  23461. coords[ index + 0 ] = vertex.x;
  23462. coords[ index + 1 ] = vertex.y;
  23463. coords[ index + 2 ] = vertex.z;
  23464. }
  23465. }
  23466. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  23467. } else if ( geometry instanceof THREE.BufferGeometry ) {
  23468. if ( geometry.index !== null ) {
  23469. // Indexed BufferGeometry
  23470. var indices = geometry.index.array;
  23471. var vertices = geometry.attributes.position;
  23472. var groups = geometry.groups;
  23473. var numEdges = 0;
  23474. if ( groups.length === 0 ) {
  23475. geometry.addGroup( 0, indices.length );
  23476. }
  23477. // allocate maximal size
  23478. var edges = new Uint32Array( 2 * indices.length );
  23479. for ( var o = 0, ol = groups.length; o < ol; ++ o ) {
  23480. var group = groups[ o ];
  23481. var start = group.start;
  23482. var count = group.count;
  23483. for ( var i = start, il = start + count; i < il; i += 3 ) {
  23484. for ( var j = 0; j < 3; j ++ ) {
  23485. edge[ 0 ] = indices[ i + j ];
  23486. edge[ 1 ] = indices[ i + ( j + 1 ) % 3 ];
  23487. edge.sort( sortFunction );
  23488. var key = edge.toString();
  23489. if ( hash[ key ] === undefined ) {
  23490. edges[ 2 * numEdges ] = edge[ 0 ];
  23491. edges[ 2 * numEdges + 1 ] = edge[ 1 ];
  23492. hash[ key ] = true;
  23493. numEdges ++;
  23494. }
  23495. }
  23496. }
  23497. }
  23498. var coords = new Float32Array( numEdges * 2 * 3 );
  23499. for ( var i = 0, l = numEdges; i < l; i ++ ) {
  23500. for ( var j = 0; j < 2; j ++ ) {
  23501. var index = 6 * i + 3 * j;
  23502. var index2 = edges[ 2 * i + j ];
  23503. coords[ index + 0 ] = vertices.getX( index2 );
  23504. coords[ index + 1 ] = vertices.getY( index2 );
  23505. coords[ index + 2 ] = vertices.getZ( index2 );
  23506. }
  23507. }
  23508. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  23509. } else {
  23510. // non-indexed BufferGeometry
  23511. var vertices = geometry.attributes.position.array;
  23512. var numEdges = vertices.length / 3;
  23513. var numTris = numEdges / 3;
  23514. var coords = new Float32Array( numEdges * 2 * 3 );
  23515. for ( var i = 0, l = numTris; i < l; i ++ ) {
  23516. for ( var j = 0; j < 3; j ++ ) {
  23517. var index = 18 * i + 6 * j;
  23518. var index1 = 9 * i + 3 * j;
  23519. coords[ index + 0 ] = vertices[ index1 ];
  23520. coords[ index + 1 ] = vertices[ index1 + 1 ];
  23521. coords[ index + 2 ] = vertices[ index1 + 2 ];
  23522. var index2 = 9 * i + 3 * ( ( j + 1 ) % 3 );
  23523. coords[ index + 3 ] = vertices[ index2 ];
  23524. coords[ index + 4 ] = vertices[ index2 + 1 ];
  23525. coords[ index + 5 ] = vertices[ index2 + 2 ];
  23526. }
  23527. }
  23528. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  23529. }
  23530. }
  23531. };
  23532. THREE.WireframeGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  23533. THREE.WireframeGeometry.prototype.constructor = THREE.WireframeGeometry;
  23534. // File:src/extras/helpers/AxisHelper.js
  23535. /**
  23536. * @author sroucheray / http://sroucheray.org/
  23537. * @author mrdoob / http://mrdoob.com/
  23538. */
  23539. THREE.AxisHelper = function ( size ) {
  23540. size = size || 1;
  23541. var vertices = new Float32Array( [
  23542. 0, 0, 0, size, 0, 0,
  23543. 0, 0, 0, 0, size, 0,
  23544. 0, 0, 0, 0, 0, size
  23545. ] );
  23546. var colors = new Float32Array( [
  23547. 1, 0, 0, 1, 0.6, 0,
  23548. 0, 1, 0, 0.6, 1, 0,
  23549. 0, 0, 1, 0, 0.6, 1
  23550. ] );
  23551. var geometry = new THREE.BufferGeometry();
  23552. geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  23553. geometry.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ) );
  23554. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
  23555. THREE.LineSegments.call( this, geometry, material );
  23556. };
  23557. THREE.AxisHelper.prototype = Object.create( THREE.LineSegments.prototype );
  23558. THREE.AxisHelper.prototype.constructor = THREE.AxisHelper;
  23559. // File:src/extras/helpers/ArrowHelper.js
  23560. /**
  23561. * @author WestLangley / http://github.com/WestLangley
  23562. * @author zz85 / http://github.com/zz85
  23563. * @author bhouston / http://clara.io
  23564. *
  23565. * Creates an arrow for visualizing directions
  23566. *
  23567. * Parameters:
  23568. * dir - Vector3
  23569. * origin - Vector3
  23570. * length - Number
  23571. * color - color in hex value
  23572. * headLength - Number
  23573. * headWidth - Number
  23574. */
  23575. THREE.ArrowHelper = ( function () {
  23576. var lineGeometry = new THREE.Geometry();
  23577. lineGeometry.vertices.push( new THREE.Vector3( 0, 0, 0 ), new THREE.Vector3( 0, 1, 0 ) );
  23578. var coneGeometry = new THREE.CylinderGeometry( 0, 0.5, 1, 5, 1 );
  23579. coneGeometry.translate( 0, - 0.5, 0 );
  23580. return function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
  23581. // dir is assumed to be normalized
  23582. THREE.Object3D.call( this );
  23583. if ( color === undefined ) color = 0xffff00;
  23584. if ( length === undefined ) length = 1;
  23585. if ( headLength === undefined ) headLength = 0.2 * length;
  23586. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  23587. this.position.copy( origin );
  23588. this.line = new THREE.Line( lineGeometry, new THREE.LineBasicMaterial( { color: color } ) );
  23589. this.line.matrixAutoUpdate = false;
  23590. this.add( this.line );
  23591. this.cone = new THREE.Mesh( coneGeometry, new THREE.MeshBasicMaterial( { color: color } ) );
  23592. this.cone.matrixAutoUpdate = false;
  23593. this.add( this.cone );
  23594. this.setDirection( dir );
  23595. this.setLength( length, headLength, headWidth );
  23596. }
  23597. }() );
  23598. THREE.ArrowHelper.prototype = Object.create( THREE.Object3D.prototype );
  23599. THREE.ArrowHelper.prototype.constructor = THREE.ArrowHelper;
  23600. THREE.ArrowHelper.prototype.setDirection = ( function () {
  23601. var axis = new THREE.Vector3();
  23602. var radians;
  23603. return function setDirection( dir ) {
  23604. // dir is assumed to be normalized
  23605. if ( dir.y > 0.99999 ) {
  23606. this.quaternion.set( 0, 0, 0, 1 );
  23607. } else if ( dir.y < - 0.99999 ) {
  23608. this.quaternion.set( 1, 0, 0, 0 );
  23609. } else {
  23610. axis.set( dir.z, 0, - dir.x ).normalize();
  23611. radians = Math.acos( dir.y );
  23612. this.quaternion.setFromAxisAngle( axis, radians );
  23613. }
  23614. };
  23615. }() );
  23616. THREE.ArrowHelper.prototype.setLength = function ( length, headLength, headWidth ) {
  23617. if ( headLength === undefined ) headLength = 0.2 * length;
  23618. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  23619. this.line.scale.set( 1, Math.max( 0, length - headLength ), 1 );
  23620. this.line.updateMatrix();
  23621. this.cone.scale.set( headWidth, headLength, headWidth );
  23622. this.cone.position.y = length;
  23623. this.cone.updateMatrix();
  23624. };
  23625. THREE.ArrowHelper.prototype.setColor = function ( color ) {
  23626. this.line.material.color.set( color );
  23627. this.cone.material.color.set( color );
  23628. };
  23629. // File:src/extras/helpers/BoxHelper.js
  23630. /**
  23631. * @author mrdoob / http://mrdoob.com/
  23632. */
  23633. THREE.BoxHelper = function ( object ) {
  23634. 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 ] );
  23635. var positions = new Float32Array( 8 * 3 );
  23636. var geometry = new THREE.BufferGeometry();
  23637. geometry.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  23638. geometry.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
  23639. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: 0xffff00 } ) );
  23640. if ( object !== undefined ) {
  23641. this.update( object );
  23642. }
  23643. };
  23644. THREE.BoxHelper.prototype = Object.create( THREE.LineSegments.prototype );
  23645. THREE.BoxHelper.prototype.constructor = THREE.BoxHelper;
  23646. THREE.BoxHelper.prototype.update = ( function () {
  23647. var box = new THREE.Box3();
  23648. return function ( object ) {
  23649. box.setFromObject( object );
  23650. if ( box.isEmpty() ) return;
  23651. var min = box.min;
  23652. var max = box.max;
  23653. /*
  23654. 5____4
  23655. 1/___0/|
  23656. | 6__|_7
  23657. 2/___3/
  23658. 0: max.x, max.y, max.z
  23659. 1: min.x, max.y, max.z
  23660. 2: min.x, min.y, max.z
  23661. 3: max.x, min.y, max.z
  23662. 4: max.x, max.y, min.z
  23663. 5: min.x, max.y, min.z
  23664. 6: min.x, min.y, min.z
  23665. 7: max.x, min.y, min.z
  23666. */
  23667. var position = this.geometry.attributes.position;
  23668. var array = position.array;
  23669. array[ 0 ] = max.x; array[ 1 ] = max.y; array[ 2 ] = max.z;
  23670. array[ 3 ] = min.x; array[ 4 ] = max.y; array[ 5 ] = max.z;
  23671. array[ 6 ] = min.x; array[ 7 ] = min.y; array[ 8 ] = max.z;
  23672. array[ 9 ] = max.x; array[ 10 ] = min.y; array[ 11 ] = max.z;
  23673. array[ 12 ] = max.x; array[ 13 ] = max.y; array[ 14 ] = min.z;
  23674. array[ 15 ] = min.x; array[ 16 ] = max.y; array[ 17 ] = min.z;
  23675. array[ 18 ] = min.x; array[ 19 ] = min.y; array[ 20 ] = min.z;
  23676. array[ 21 ] = max.x; array[ 22 ] = min.y; array[ 23 ] = min.z;
  23677. position.needsUpdate = true;
  23678. this.geometry.computeBoundingSphere();
  23679. };
  23680. } )();
  23681. // File:src/extras/helpers/BoundingBoxHelper.js
  23682. /**
  23683. * @author WestLangley / http://github.com/WestLangley
  23684. */
  23685. // a helper to show the world-axis-aligned bounding box for an object
  23686. THREE.BoundingBoxHelper = function ( object, hex ) {
  23687. var color = ( hex !== undefined ) ? hex : 0x888888;
  23688. this.object = object;
  23689. this.box = new THREE.Box3();
  23690. THREE.Mesh.call( this, new THREE.BoxGeometry( 1, 1, 1 ), new THREE.MeshBasicMaterial( { color: color, wireframe: true } ) );
  23691. };
  23692. THREE.BoundingBoxHelper.prototype = Object.create( THREE.Mesh.prototype );
  23693. THREE.BoundingBoxHelper.prototype.constructor = THREE.BoundingBoxHelper;
  23694. THREE.BoundingBoxHelper.prototype.update = function () {
  23695. this.box.setFromObject( this.object );
  23696. this.box.size( this.scale );
  23697. this.box.center( this.position );
  23698. };
  23699. // File:src/extras/helpers/CameraHelper.js
  23700. /**
  23701. * @author alteredq / http://alteredqualia.com/
  23702. *
  23703. * - shows frustum, line of sight and up of the camera
  23704. * - suitable for fast updates
  23705. * - based on frustum visualization in lightgl.js shadowmap example
  23706. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  23707. */
  23708. THREE.CameraHelper = function ( camera ) {
  23709. var geometry = new THREE.Geometry();
  23710. var material = new THREE.LineBasicMaterial( { color: 0xffffff, vertexColors: THREE.FaceColors } );
  23711. var pointMap = {};
  23712. // colors
  23713. var hexFrustum = 0xffaa00;
  23714. var hexCone = 0xff0000;
  23715. var hexUp = 0x00aaff;
  23716. var hexTarget = 0xffffff;
  23717. var hexCross = 0x333333;
  23718. // near
  23719. addLine( "n1", "n2", hexFrustum );
  23720. addLine( "n2", "n4", hexFrustum );
  23721. addLine( "n4", "n3", hexFrustum );
  23722. addLine( "n3", "n1", hexFrustum );
  23723. // far
  23724. addLine( "f1", "f2", hexFrustum );
  23725. addLine( "f2", "f4", hexFrustum );
  23726. addLine( "f4", "f3", hexFrustum );
  23727. addLine( "f3", "f1", hexFrustum );
  23728. // sides
  23729. addLine( "n1", "f1", hexFrustum );
  23730. addLine( "n2", "f2", hexFrustum );
  23731. addLine( "n3", "f3", hexFrustum );
  23732. addLine( "n4", "f4", hexFrustum );
  23733. // cone
  23734. addLine( "p", "n1", hexCone );
  23735. addLine( "p", "n2", hexCone );
  23736. addLine( "p", "n3", hexCone );
  23737. addLine( "p", "n4", hexCone );
  23738. // up
  23739. addLine( "u1", "u2", hexUp );
  23740. addLine( "u2", "u3", hexUp );
  23741. addLine( "u3", "u1", hexUp );
  23742. // target
  23743. addLine( "c", "t", hexTarget );
  23744. addLine( "p", "c", hexCross );
  23745. // cross
  23746. addLine( "cn1", "cn2", hexCross );
  23747. addLine( "cn3", "cn4", hexCross );
  23748. addLine( "cf1", "cf2", hexCross );
  23749. addLine( "cf3", "cf4", hexCross );
  23750. function addLine( a, b, hex ) {
  23751. addPoint( a, hex );
  23752. addPoint( b, hex );
  23753. }
  23754. function addPoint( id, hex ) {
  23755. geometry.vertices.push( new THREE.Vector3() );
  23756. geometry.colors.push( new THREE.Color( hex ) );
  23757. if ( pointMap[ id ] === undefined ) {
  23758. pointMap[ id ] = [];
  23759. }
  23760. pointMap[ id ].push( geometry.vertices.length - 1 );
  23761. }
  23762. THREE.LineSegments.call( this, geometry, material );
  23763. this.camera = camera;
  23764. this.camera.updateProjectionMatrix();
  23765. this.matrix = camera.matrixWorld;
  23766. this.matrixAutoUpdate = false;
  23767. this.pointMap = pointMap;
  23768. this.update();
  23769. };
  23770. THREE.CameraHelper.prototype = Object.create( THREE.LineSegments.prototype );
  23771. THREE.CameraHelper.prototype.constructor = THREE.CameraHelper;
  23772. THREE.CameraHelper.prototype.update = function () {
  23773. var geometry, pointMap;
  23774. var vector = new THREE.Vector3();
  23775. var camera = new THREE.Camera();
  23776. function setPoint( point, x, y, z ) {
  23777. vector.set( x, y, z ).unproject( camera );
  23778. var points = pointMap[ point ];
  23779. if ( points !== undefined ) {
  23780. for ( var i = 0, il = points.length; i < il; i ++ ) {
  23781. geometry.vertices[ points[ i ] ].copy( vector );
  23782. }
  23783. }
  23784. }
  23785. return function () {
  23786. geometry = this.geometry;
  23787. pointMap = this.pointMap;
  23788. var w = 1, h = 1;
  23789. // we need just camera projection matrix
  23790. // world matrix must be identity
  23791. camera.projectionMatrix.copy( this.camera.projectionMatrix );
  23792. // center / target
  23793. setPoint( "c", 0, 0, - 1 );
  23794. setPoint( "t", 0, 0, 1 );
  23795. // near
  23796. setPoint( "n1", - w, - h, - 1 );
  23797. setPoint( "n2", w, - h, - 1 );
  23798. setPoint( "n3", - w, h, - 1 );
  23799. setPoint( "n4", w, h, - 1 );
  23800. // far
  23801. setPoint( "f1", - w, - h, 1 );
  23802. setPoint( "f2", w, - h, 1 );
  23803. setPoint( "f3", - w, h, 1 );
  23804. setPoint( "f4", w, h, 1 );
  23805. // up
  23806. setPoint( "u1", w * 0.7, h * 1.1, - 1 );
  23807. setPoint( "u2", - w * 0.7, h * 1.1, - 1 );
  23808. setPoint( "u3", 0, h * 2, - 1 );
  23809. // cross
  23810. setPoint( "cf1", - w, 0, 1 );
  23811. setPoint( "cf2", w, 0, 1 );
  23812. setPoint( "cf3", 0, - h, 1 );
  23813. setPoint( "cf4", 0, h, 1 );
  23814. setPoint( "cn1", - w, 0, - 1 );
  23815. setPoint( "cn2", w, 0, - 1 );
  23816. setPoint( "cn3", 0, - h, - 1 );
  23817. setPoint( "cn4", 0, h, - 1 );
  23818. geometry.verticesNeedUpdate = true;
  23819. };
  23820. }();
  23821. // File:src/extras/helpers/DirectionalLightHelper.js
  23822. /**
  23823. * @author alteredq / http://alteredqualia.com/
  23824. * @author mrdoob / http://mrdoob.com/
  23825. * @author WestLangley / http://github.com/WestLangley
  23826. */
  23827. THREE.DirectionalLightHelper = function ( light, size ) {
  23828. THREE.Object3D.call( this );
  23829. this.light = light;
  23830. this.light.updateMatrixWorld();
  23831. this.matrix = light.matrixWorld;
  23832. this.matrixAutoUpdate = false;
  23833. size = size || 1;
  23834. var geometry = new THREE.Geometry();
  23835. geometry.vertices.push(
  23836. new THREE.Vector3( - size, size, 0 ),
  23837. new THREE.Vector3( size, size, 0 ),
  23838. new THREE.Vector3( size, - size, 0 ),
  23839. new THREE.Vector3( - size, - size, 0 ),
  23840. new THREE.Vector3( - size, size, 0 )
  23841. );
  23842. var material = new THREE.LineBasicMaterial( { fog: false } );
  23843. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  23844. this.lightPlane = new THREE.Line( geometry, material );
  23845. this.add( this.lightPlane );
  23846. geometry = new THREE.Geometry();
  23847. geometry.vertices.push(
  23848. new THREE.Vector3(),
  23849. new THREE.Vector3()
  23850. );
  23851. material = new THREE.LineBasicMaterial( { fog: false } );
  23852. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  23853. this.targetLine = new THREE.Line( geometry, material );
  23854. this.add( this.targetLine );
  23855. this.update();
  23856. };
  23857. THREE.DirectionalLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  23858. THREE.DirectionalLightHelper.prototype.constructor = THREE.DirectionalLightHelper;
  23859. THREE.DirectionalLightHelper.prototype.dispose = function () {
  23860. this.lightPlane.geometry.dispose();
  23861. this.lightPlane.material.dispose();
  23862. this.targetLine.geometry.dispose();
  23863. this.targetLine.material.dispose();
  23864. };
  23865. THREE.DirectionalLightHelper.prototype.update = function () {
  23866. var v1 = new THREE.Vector3();
  23867. var v2 = new THREE.Vector3();
  23868. var v3 = new THREE.Vector3();
  23869. return function () {
  23870. v1.setFromMatrixPosition( this.light.matrixWorld );
  23871. v2.setFromMatrixPosition( this.light.target.matrixWorld );
  23872. v3.subVectors( v2, v1 );
  23873. this.lightPlane.lookAt( v3 );
  23874. this.lightPlane.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  23875. this.targetLine.geometry.vertices[ 1 ].copy( v3 );
  23876. this.targetLine.geometry.verticesNeedUpdate = true;
  23877. this.targetLine.material.color.copy( this.lightPlane.material.color );
  23878. };
  23879. }();
  23880. // File:src/extras/helpers/EdgesHelper.js
  23881. /**
  23882. * @author WestLangley / http://github.com/WestLangley
  23883. * @param object THREE.Mesh whose geometry will be used
  23884. * @param hex line color
  23885. * @param thresholdAngle the minimum angle (in degrees),
  23886. * between the face normals of adjacent faces,
  23887. * that is required to render an edge. A value of 10 means
  23888. * an edge is only rendered if the angle is at least 10 degrees.
  23889. */
  23890. THREE.EdgesHelper = function ( object, hex, thresholdAngle ) {
  23891. var color = ( hex !== undefined ) ? hex : 0xffffff;
  23892. THREE.LineSegments.call( this, new THREE.EdgesGeometry( object.geometry, thresholdAngle ), new THREE.LineBasicMaterial( { color: color } ) );
  23893. this.matrix = object.matrixWorld;
  23894. this.matrixAutoUpdate = false;
  23895. };
  23896. THREE.EdgesHelper.prototype = Object.create( THREE.LineSegments.prototype );
  23897. THREE.EdgesHelper.prototype.constructor = THREE.EdgesHelper;
  23898. // File:src/extras/helpers/FaceNormalsHelper.js
  23899. /**
  23900. * @author mrdoob / http://mrdoob.com/
  23901. * @author WestLangley / http://github.com/WestLangley
  23902. */
  23903. THREE.FaceNormalsHelper = function ( object, size, hex, linewidth ) {
  23904. // FaceNormalsHelper only supports THREE.Geometry
  23905. this.object = object;
  23906. this.size = ( size !== undefined ) ? size : 1;
  23907. var color = ( hex !== undefined ) ? hex : 0xffff00;
  23908. var width = ( linewidth !== undefined ) ? linewidth : 1;
  23909. //
  23910. var nNormals = 0;
  23911. var objGeometry = this.object.geometry;
  23912. if ( objGeometry instanceof THREE.Geometry ) {
  23913. nNormals = objGeometry.faces.length;
  23914. } else {
  23915. console.warn( 'THREE.FaceNormalsHelper: only THREE.Geometry is supported. Use THREE.VertexNormalsHelper, instead.' );
  23916. }
  23917. //
  23918. var geometry = new THREE.BufferGeometry();
  23919. var positions = new THREE.Float32Attribute( nNormals * 2 * 3, 3 );
  23920. geometry.addAttribute( 'position', positions );
  23921. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  23922. //
  23923. this.matrixAutoUpdate = false;
  23924. this.update();
  23925. };
  23926. THREE.FaceNormalsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  23927. THREE.FaceNormalsHelper.prototype.constructor = THREE.FaceNormalsHelper;
  23928. THREE.FaceNormalsHelper.prototype.update = ( function () {
  23929. var v1 = new THREE.Vector3();
  23930. var v2 = new THREE.Vector3();
  23931. var normalMatrix = new THREE.Matrix3();
  23932. return function update() {
  23933. this.object.updateMatrixWorld( true );
  23934. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  23935. var matrixWorld = this.object.matrixWorld;
  23936. var position = this.geometry.attributes.position;
  23937. //
  23938. var objGeometry = this.object.geometry;
  23939. var vertices = objGeometry.vertices;
  23940. var faces = objGeometry.faces;
  23941. var idx = 0;
  23942. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  23943. var face = faces[ i ];
  23944. var normal = face.normal;
  23945. v1.copy( vertices[ face.a ] )
  23946. .add( vertices[ face.b ] )
  23947. .add( vertices[ face.c ] )
  23948. .divideScalar( 3 )
  23949. .applyMatrix4( matrixWorld );
  23950. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  23951. position.setXYZ( idx, v1.x, v1.y, v1.z );
  23952. idx = idx + 1;
  23953. position.setXYZ( idx, v2.x, v2.y, v2.z );
  23954. idx = idx + 1;
  23955. }
  23956. position.needsUpdate = true;
  23957. return this;
  23958. }
  23959. }() );
  23960. // File:src/extras/helpers/GridHelper.js
  23961. /**
  23962. * @author mrdoob / http://mrdoob.com/
  23963. */
  23964. THREE.GridHelper = function ( size, step ) {
  23965. var geometry = new THREE.Geometry();
  23966. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
  23967. this.color1 = new THREE.Color( 0x444444 );
  23968. this.color2 = new THREE.Color( 0x888888 );
  23969. for ( var i = - size; i <= size; i += step ) {
  23970. geometry.vertices.push(
  23971. new THREE.Vector3( - size, 0, i ), new THREE.Vector3( size, 0, i ),
  23972. new THREE.Vector3( i, 0, - size ), new THREE.Vector3( i, 0, size )
  23973. );
  23974. var color = i === 0 ? this.color1 : this.color2;
  23975. geometry.colors.push( color, color, color, color );
  23976. }
  23977. THREE.LineSegments.call( this, geometry, material );
  23978. };
  23979. THREE.GridHelper.prototype = Object.create( THREE.LineSegments.prototype );
  23980. THREE.GridHelper.prototype.constructor = THREE.GridHelper;
  23981. THREE.GridHelper.prototype.setColors = function( colorCenterLine, colorGrid ) {
  23982. this.color1.set( colorCenterLine );
  23983. this.color2.set( colorGrid );
  23984. this.geometry.colorsNeedUpdate = true;
  23985. };
  23986. // File:src/extras/helpers/HemisphereLightHelper.js
  23987. /**
  23988. * @author alteredq / http://alteredqualia.com/
  23989. * @author mrdoob / http://mrdoob.com/
  23990. */
  23991. THREE.HemisphereLightHelper = function ( light, sphereSize ) {
  23992. THREE.Object3D.call( this );
  23993. this.light = light;
  23994. this.light.updateMatrixWorld();
  23995. this.matrix = light.matrixWorld;
  23996. this.matrixAutoUpdate = false;
  23997. this.colors = [ new THREE.Color(), new THREE.Color() ];
  23998. var geometry = new THREE.SphereGeometry( sphereSize, 4, 2 );
  23999. geometry.rotateX( - Math.PI / 2 );
  24000. for ( var i = 0, il = 8; i < il; i ++ ) {
  24001. geometry.faces[ i ].color = this.colors[ i < 4 ? 0 : 1 ];
  24002. }
  24003. var material = new THREE.MeshBasicMaterial( { vertexColors: THREE.FaceColors, wireframe: true } );
  24004. this.lightSphere = new THREE.Mesh( geometry, material );
  24005. this.add( this.lightSphere );
  24006. this.update();
  24007. };
  24008. THREE.HemisphereLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  24009. THREE.HemisphereLightHelper.prototype.constructor = THREE.HemisphereLightHelper;
  24010. THREE.HemisphereLightHelper.prototype.dispose = function () {
  24011. this.lightSphere.geometry.dispose();
  24012. this.lightSphere.material.dispose();
  24013. };
  24014. THREE.HemisphereLightHelper.prototype.update = function () {
  24015. var vector = new THREE.Vector3();
  24016. return function () {
  24017. this.colors[ 0 ].copy( this.light.color ).multiplyScalar( this.light.intensity );
  24018. this.colors[ 1 ].copy( this.light.groundColor ).multiplyScalar( this.light.intensity );
  24019. this.lightSphere.lookAt( vector.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  24020. this.lightSphere.geometry.colorsNeedUpdate = true;
  24021. }
  24022. }();
  24023. // File:src/extras/helpers/PointLightHelper.js
  24024. /**
  24025. * @author alteredq / http://alteredqualia.com/
  24026. * @author mrdoob / http://mrdoob.com/
  24027. */
  24028. THREE.PointLightHelper = function ( light, sphereSize ) {
  24029. this.light = light;
  24030. this.light.updateMatrixWorld();
  24031. var geometry = new THREE.SphereGeometry( sphereSize, 4, 2 );
  24032. var material = new THREE.MeshBasicMaterial( { wireframe: true, fog: false } );
  24033. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  24034. THREE.Mesh.call( this, geometry, material );
  24035. this.matrix = this.light.matrixWorld;
  24036. this.matrixAutoUpdate = false;
  24037. /*
  24038. var distanceGeometry = new THREE.IcosahedronGeometry( 1, 2 );
  24039. var distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  24040. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  24041. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  24042. var d = light.distance;
  24043. if ( d === 0.0 ) {
  24044. this.lightDistance.visible = false;
  24045. } else {
  24046. this.lightDistance.scale.set( d, d, d );
  24047. }
  24048. this.add( this.lightDistance );
  24049. */
  24050. };
  24051. THREE.PointLightHelper.prototype = Object.create( THREE.Mesh.prototype );
  24052. THREE.PointLightHelper.prototype.constructor = THREE.PointLightHelper;
  24053. THREE.PointLightHelper.prototype.dispose = function () {
  24054. this.geometry.dispose();
  24055. this.material.dispose();
  24056. };
  24057. THREE.PointLightHelper.prototype.update = function () {
  24058. this.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  24059. /*
  24060. var d = this.light.distance;
  24061. if ( d === 0.0 ) {
  24062. this.lightDistance.visible = false;
  24063. } else {
  24064. this.lightDistance.visible = true;
  24065. this.lightDistance.scale.set( d, d, d );
  24066. }
  24067. */
  24068. };
  24069. // File:src/extras/helpers/SkeletonHelper.js
  24070. /**
  24071. * @author Sean Griffin / http://twitter.com/sgrif
  24072. * @author Michael Guerrero / http://realitymeltdown.com
  24073. * @author mrdoob / http://mrdoob.com/
  24074. * @author ikerr / http://verold.com
  24075. */
  24076. THREE.SkeletonHelper = function ( object ) {
  24077. this.bones = this.getBoneList( object );
  24078. var geometry = new THREE.Geometry();
  24079. for ( var i = 0; i < this.bones.length; i ++ ) {
  24080. var bone = this.bones[ i ];
  24081. if ( bone.parent instanceof THREE.Bone ) {
  24082. geometry.vertices.push( new THREE.Vector3() );
  24083. geometry.vertices.push( new THREE.Vector3() );
  24084. geometry.colors.push( new THREE.Color( 0, 0, 1 ) );
  24085. geometry.colors.push( new THREE.Color( 0, 1, 0 ) );
  24086. }
  24087. }
  24088. geometry.dynamic = true;
  24089. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors, depthTest: false, depthWrite: false, transparent: true } );
  24090. THREE.LineSegments.call( this, geometry, material );
  24091. this.root = object;
  24092. this.matrix = object.matrixWorld;
  24093. this.matrixAutoUpdate = false;
  24094. this.update();
  24095. };
  24096. THREE.SkeletonHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24097. THREE.SkeletonHelper.prototype.constructor = THREE.SkeletonHelper;
  24098. THREE.SkeletonHelper.prototype.getBoneList = function( object ) {
  24099. var boneList = [];
  24100. if ( object instanceof THREE.Bone ) {
  24101. boneList.push( object );
  24102. }
  24103. for ( var i = 0; i < object.children.length; i ++ ) {
  24104. boneList.push.apply( boneList, this.getBoneList( object.children[ i ] ) );
  24105. }
  24106. return boneList;
  24107. };
  24108. THREE.SkeletonHelper.prototype.update = function () {
  24109. var geometry = this.geometry;
  24110. var matrixWorldInv = new THREE.Matrix4().getInverse( this.root.matrixWorld );
  24111. var boneMatrix = new THREE.Matrix4();
  24112. var j = 0;
  24113. for ( var i = 0; i < this.bones.length; i ++ ) {
  24114. var bone = this.bones[ i ];
  24115. if ( bone.parent instanceof THREE.Bone ) {
  24116. boneMatrix.multiplyMatrices( matrixWorldInv, bone.matrixWorld );
  24117. geometry.vertices[ j ].setFromMatrixPosition( boneMatrix );
  24118. boneMatrix.multiplyMatrices( matrixWorldInv, bone.parent.matrixWorld );
  24119. geometry.vertices[ j + 1 ].setFromMatrixPosition( boneMatrix );
  24120. j += 2;
  24121. }
  24122. }
  24123. geometry.verticesNeedUpdate = true;
  24124. geometry.computeBoundingSphere();
  24125. };
  24126. // File:src/extras/helpers/SpotLightHelper.js
  24127. /**
  24128. * @author alteredq / http://alteredqualia.com/
  24129. * @author mrdoob / http://mrdoob.com/
  24130. * @author WestLangley / http://github.com/WestLangley
  24131. */
  24132. THREE.SpotLightHelper = function ( light ) {
  24133. THREE.Object3D.call( this );
  24134. this.light = light;
  24135. this.light.updateMatrixWorld();
  24136. this.matrix = light.matrixWorld;
  24137. this.matrixAutoUpdate = false;
  24138. var geometry = new THREE.CylinderGeometry( 0, 1, 1, 8, 1, true );
  24139. geometry.translate( 0, - 0.5, 0 );
  24140. geometry.rotateX( - Math.PI / 2 );
  24141. var material = new THREE.MeshBasicMaterial( { wireframe: true, fog: false } );
  24142. this.cone = new THREE.Mesh( geometry, material );
  24143. this.add( this.cone );
  24144. this.update();
  24145. };
  24146. THREE.SpotLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  24147. THREE.SpotLightHelper.prototype.constructor = THREE.SpotLightHelper;
  24148. THREE.SpotLightHelper.prototype.dispose = function () {
  24149. this.cone.geometry.dispose();
  24150. this.cone.material.dispose();
  24151. };
  24152. THREE.SpotLightHelper.prototype.update = function () {
  24153. var vector = new THREE.Vector3();
  24154. var vector2 = new THREE.Vector3();
  24155. return function () {
  24156. var coneLength = this.light.distance ? this.light.distance : 10000;
  24157. var coneWidth = coneLength * Math.tan( this.light.angle );
  24158. this.cone.scale.set( coneWidth, coneWidth, coneLength );
  24159. vector.setFromMatrixPosition( this.light.matrixWorld );
  24160. vector2.setFromMatrixPosition( this.light.target.matrixWorld );
  24161. this.cone.lookAt( vector2.sub( vector ) );
  24162. this.cone.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  24163. };
  24164. }();
  24165. // File:src/extras/helpers/VertexNormalsHelper.js
  24166. /**
  24167. * @author mrdoob / http://mrdoob.com/
  24168. * @author WestLangley / http://github.com/WestLangley
  24169. */
  24170. THREE.VertexNormalsHelper = function ( object, size, hex, linewidth ) {
  24171. this.object = object;
  24172. this.size = ( size !== undefined ) ? size : 1;
  24173. var color = ( hex !== undefined ) ? hex : 0xff0000;
  24174. var width = ( linewidth !== undefined ) ? linewidth : 1;
  24175. //
  24176. var nNormals = 0;
  24177. var objGeometry = this.object.geometry;
  24178. if ( objGeometry instanceof THREE.Geometry ) {
  24179. nNormals = objGeometry.faces.length * 3;
  24180. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  24181. nNormals = objGeometry.attributes.normal.count
  24182. }
  24183. //
  24184. var geometry = new THREE.BufferGeometry();
  24185. var positions = new THREE.Float32Attribute( nNormals * 2 * 3, 3 );
  24186. geometry.addAttribute( 'position', positions );
  24187. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  24188. //
  24189. this.matrixAutoUpdate = false;
  24190. this.update();
  24191. };
  24192. THREE.VertexNormalsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24193. THREE.VertexNormalsHelper.prototype.constructor = THREE.VertexNormalsHelper;
  24194. THREE.VertexNormalsHelper.prototype.update = ( function () {
  24195. var v1 = new THREE.Vector3();
  24196. var v2 = new THREE.Vector3();
  24197. var normalMatrix = new THREE.Matrix3();
  24198. return function update() {
  24199. var keys = [ 'a', 'b', 'c' ];
  24200. this.object.updateMatrixWorld( true );
  24201. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  24202. var matrixWorld = this.object.matrixWorld;
  24203. var position = this.geometry.attributes.position;
  24204. //
  24205. var objGeometry = this.object.geometry;
  24206. if ( objGeometry instanceof THREE.Geometry ) {
  24207. var vertices = objGeometry.vertices;
  24208. var faces = objGeometry.faces;
  24209. var idx = 0;
  24210. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  24211. var face = faces[ i ];
  24212. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  24213. var vertex = vertices[ face[ keys[ j ] ] ];
  24214. var normal = face.vertexNormals[ j ];
  24215. v1.copy( vertex ).applyMatrix4( matrixWorld );
  24216. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  24217. position.setXYZ( idx, v1.x, v1.y, v1.z );
  24218. idx = idx + 1;
  24219. position.setXYZ( idx, v2.x, v2.y, v2.z );
  24220. idx = idx + 1;
  24221. }
  24222. }
  24223. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  24224. var objPos = objGeometry.attributes.position;
  24225. var objNorm = objGeometry.attributes.normal;
  24226. var idx = 0;
  24227. // for simplicity, ignore index and drawcalls, and render every normal
  24228. for ( var j = 0, jl = objPos.count; j < jl; j ++ ) {
  24229. v1.set( objPos.getX( j ), objPos.getY( j ), objPos.getZ( j ) ).applyMatrix4( matrixWorld );
  24230. v2.set( objNorm.getX( j ), objNorm.getY( j ), objNorm.getZ( j ) );
  24231. v2.applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  24232. position.setXYZ( idx, v1.x, v1.y, v1.z );
  24233. idx = idx + 1;
  24234. position.setXYZ( idx, v2.x, v2.y, v2.z );
  24235. idx = idx + 1;
  24236. }
  24237. }
  24238. position.needsUpdate = true;
  24239. return this;
  24240. }
  24241. }() );
  24242. // File:src/extras/helpers/WireframeHelper.js
  24243. /**
  24244. * @author mrdoob / http://mrdoob.com/
  24245. */
  24246. THREE.WireframeHelper = function ( object, hex ) {
  24247. var color = ( hex !== undefined ) ? hex : 0xffffff;
  24248. THREE.LineSegments.call( this, new THREE.WireframeGeometry( object.geometry ), new THREE.LineBasicMaterial( { color: color } ) );
  24249. this.matrix = object.matrixWorld;
  24250. this.matrixAutoUpdate = false;
  24251. };
  24252. THREE.WireframeHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24253. THREE.WireframeHelper.prototype.constructor = THREE.WireframeHelper;
  24254. // File:src/extras/objects/ImmediateRenderObject.js
  24255. /**
  24256. * @author alteredq / http://alteredqualia.com/
  24257. */
  24258. THREE.ImmediateRenderObject = function ( material ) {
  24259. THREE.Object3D.call( this );
  24260. this.material = material;
  24261. this.render = function ( renderCallback ) {};
  24262. };
  24263. THREE.ImmediateRenderObject.prototype = Object.create( THREE.Object3D.prototype );
  24264. THREE.ImmediateRenderObject.prototype.constructor = THREE.ImmediateRenderObject;
  24265. // File:src/extras/objects/MorphBlendMesh.js
  24266. /**
  24267. * @author alteredq / http://alteredqualia.com/
  24268. */
  24269. THREE.MorphBlendMesh = function( geometry, material ) {
  24270. THREE.Mesh.call( this, geometry, material );
  24271. this.animationsMap = {};
  24272. this.animationsList = [];
  24273. // prepare default animation
  24274. // (all frames played together in 1 second)
  24275. var numFrames = this.geometry.morphTargets.length;
  24276. var name = "__default";
  24277. var startFrame = 0;
  24278. var endFrame = numFrames - 1;
  24279. var fps = numFrames / 1;
  24280. this.createAnimation( name, startFrame, endFrame, fps );
  24281. this.setAnimationWeight( name, 1 );
  24282. };
  24283. THREE.MorphBlendMesh.prototype = Object.create( THREE.Mesh.prototype );
  24284. THREE.MorphBlendMesh.prototype.constructor = THREE.MorphBlendMesh;
  24285. THREE.MorphBlendMesh.prototype.createAnimation = function ( name, start, end, fps ) {
  24286. var animation = {
  24287. start: start,
  24288. end: end,
  24289. length: end - start + 1,
  24290. fps: fps,
  24291. duration: ( end - start ) / fps,
  24292. lastFrame: 0,
  24293. currentFrame: 0,
  24294. active: false,
  24295. time: 0,
  24296. direction: 1,
  24297. weight: 1,
  24298. directionBackwards: false,
  24299. mirroredLoop: false
  24300. };
  24301. this.animationsMap[ name ] = animation;
  24302. this.animationsList.push( animation );
  24303. };
  24304. THREE.MorphBlendMesh.prototype.autoCreateAnimations = function ( fps ) {
  24305. var pattern = /([a-z]+)_?(\d+)/i;
  24306. var firstAnimation, frameRanges = {};
  24307. var geometry = this.geometry;
  24308. for ( var i = 0, il = geometry.morphTargets.length; i < il; i ++ ) {
  24309. var morph = geometry.morphTargets[ i ];
  24310. var chunks = morph.name.match( pattern );
  24311. if ( chunks && chunks.length > 1 ) {
  24312. var name = chunks[ 1 ];
  24313. if ( ! frameRanges[ name ] ) frameRanges[ name ] = { start: Infinity, end: - Infinity };
  24314. var range = frameRanges[ name ];
  24315. if ( i < range.start ) range.start = i;
  24316. if ( i > range.end ) range.end = i;
  24317. if ( ! firstAnimation ) firstAnimation = name;
  24318. }
  24319. }
  24320. for ( var name in frameRanges ) {
  24321. var range = frameRanges[ name ];
  24322. this.createAnimation( name, range.start, range.end, fps );
  24323. }
  24324. this.firstAnimation = firstAnimation;
  24325. };
  24326. THREE.MorphBlendMesh.prototype.setAnimationDirectionForward = function ( name ) {
  24327. var animation = this.animationsMap[ name ];
  24328. if ( animation ) {
  24329. animation.direction = 1;
  24330. animation.directionBackwards = false;
  24331. }
  24332. };
  24333. THREE.MorphBlendMesh.prototype.setAnimationDirectionBackward = function ( name ) {
  24334. var animation = this.animationsMap[ name ];
  24335. if ( animation ) {
  24336. animation.direction = - 1;
  24337. animation.directionBackwards = true;
  24338. }
  24339. };
  24340. THREE.MorphBlendMesh.prototype.setAnimationFPS = function ( name, fps ) {
  24341. var animation = this.animationsMap[ name ];
  24342. if ( animation ) {
  24343. animation.fps = fps;
  24344. animation.duration = ( animation.end - animation.start ) / animation.fps;
  24345. }
  24346. };
  24347. THREE.MorphBlendMesh.prototype.setAnimationDuration = function ( name, duration ) {
  24348. var animation = this.animationsMap[ name ];
  24349. if ( animation ) {
  24350. animation.duration = duration;
  24351. animation.fps = ( animation.end - animation.start ) / animation.duration;
  24352. }
  24353. };
  24354. THREE.MorphBlendMesh.prototype.setAnimationWeight = function ( name, weight ) {
  24355. var animation = this.animationsMap[ name ];
  24356. if ( animation ) {
  24357. animation.weight = weight;
  24358. }
  24359. };
  24360. THREE.MorphBlendMesh.prototype.setAnimationTime = function ( name, time ) {
  24361. var animation = this.animationsMap[ name ];
  24362. if ( animation ) {
  24363. animation.time = time;
  24364. }
  24365. };
  24366. THREE.MorphBlendMesh.prototype.getAnimationTime = function ( name ) {
  24367. var time = 0;
  24368. var animation = this.animationsMap[ name ];
  24369. if ( animation ) {
  24370. time = animation.time;
  24371. }
  24372. return time;
  24373. };
  24374. THREE.MorphBlendMesh.prototype.getAnimationDuration = function ( name ) {
  24375. var duration = - 1;
  24376. var animation = this.animationsMap[ name ];
  24377. if ( animation ) {
  24378. duration = animation.duration;
  24379. }
  24380. return duration;
  24381. };
  24382. THREE.MorphBlendMesh.prototype.playAnimation = function ( name ) {
  24383. var animation = this.animationsMap[ name ];
  24384. if ( animation ) {
  24385. animation.time = 0;
  24386. animation.active = true;
  24387. } else {
  24388. console.warn( "THREE.MorphBlendMesh: animation[" + name + "] undefined in .playAnimation()" );
  24389. }
  24390. };
  24391. THREE.MorphBlendMesh.prototype.stopAnimation = function ( name ) {
  24392. var animation = this.animationsMap[ name ];
  24393. if ( animation ) {
  24394. animation.active = false;
  24395. }
  24396. };
  24397. THREE.MorphBlendMesh.prototype.update = function ( delta ) {
  24398. for ( var i = 0, il = this.animationsList.length; i < il; i ++ ) {
  24399. var animation = this.animationsList[ i ];
  24400. if ( ! animation.active ) continue;
  24401. var frameTime = animation.duration / animation.length;
  24402. animation.time += animation.direction * delta;
  24403. if ( animation.mirroredLoop ) {
  24404. if ( animation.time > animation.duration || animation.time < 0 ) {
  24405. animation.direction *= - 1;
  24406. if ( animation.time > animation.duration ) {
  24407. animation.time = animation.duration;
  24408. animation.directionBackwards = true;
  24409. }
  24410. if ( animation.time < 0 ) {
  24411. animation.time = 0;
  24412. animation.directionBackwards = false;
  24413. }
  24414. }
  24415. } else {
  24416. animation.time = animation.time % animation.duration;
  24417. if ( animation.time < 0 ) animation.time += animation.duration;
  24418. }
  24419. var keyframe = animation.start + THREE.Math.clamp( Math.floor( animation.time / frameTime ), 0, animation.length - 1 );
  24420. var weight = animation.weight;
  24421. if ( keyframe !== animation.currentFrame ) {
  24422. this.morphTargetInfluences[ animation.lastFrame ] = 0;
  24423. this.morphTargetInfluences[ animation.currentFrame ] = 1 * weight;
  24424. this.morphTargetInfluences[ keyframe ] = 0;
  24425. animation.lastFrame = animation.currentFrame;
  24426. animation.currentFrame = keyframe;
  24427. }
  24428. var mix = ( animation.time % frameTime ) / frameTime;
  24429. if ( animation.directionBackwards ) mix = 1 - mix;
  24430. if ( animation.currentFrame !== animation.lastFrame ) {
  24431. this.morphTargetInfluences[ animation.currentFrame ] = mix * weight;
  24432. this.morphTargetInfluences[ animation.lastFrame ] = ( 1 - mix ) * weight;
  24433. } else {
  24434. this.morphTargetInfluences[ animation.currentFrame ] = weight;
  24435. }
  24436. }
  24437. };