three.js 941 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456
  1. // File:src/Three.js
  2. /**
  3. * @author mrdoob / http://mrdoob.com/
  4. */
  5. var THREE = { REVISION: '77dev' };
  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. THREE.DepthFormat = 1026;
  181. // DDS / ST3C Compressed texture formats
  182. THREE.RGB_S3TC_DXT1_Format = 2001;
  183. THREE.RGBA_S3TC_DXT1_Format = 2002;
  184. THREE.RGBA_S3TC_DXT3_Format = 2003;
  185. THREE.RGBA_S3TC_DXT5_Format = 2004;
  186. // PVRTC compressed texture formats
  187. THREE.RGB_PVRTC_4BPPV1_Format = 2100;
  188. THREE.RGB_PVRTC_2BPPV1_Format = 2101;
  189. THREE.RGBA_PVRTC_4BPPV1_Format = 2102;
  190. THREE.RGBA_PVRTC_2BPPV1_Format = 2103;
  191. // ETC compressed texture formats
  192. THREE.RGB_ETC1_Format = 2151;
  193. // Loop styles for AnimationAction
  194. THREE.LoopOnce = 2200;
  195. THREE.LoopRepeat = 2201;
  196. THREE.LoopPingPong = 2202;
  197. // Interpolation
  198. THREE.InterpolateDiscrete = 2300;
  199. THREE.InterpolateLinear = 2301;
  200. THREE.InterpolateSmooth = 2302;
  201. // Interpolant ending modes
  202. THREE.ZeroCurvatureEnding = 2400;
  203. THREE.ZeroSlopeEnding = 2401;
  204. THREE.WrapAroundEnding = 2402;
  205. // Triangle Draw modes
  206. THREE.TrianglesDrawMode = 0;
  207. THREE.TriangleStripDrawMode = 1;
  208. THREE.TriangleFanDrawMode = 2;
  209. // Texture Encodings
  210. THREE.LinearEncoding = 3000; // No encoding at all.
  211. THREE.sRGBEncoding = 3001;
  212. THREE.GammaEncoding = 3007; // uses GAMMA_FACTOR, for backwards compatibility with WebGLRenderer.gammaInput/gammaOutput
  213. // The following Texture Encodings are for RGB-only (no alpha) HDR light emission sources.
  214. // These encodings should not specified as output encodings except in rare situations.
  215. THREE.RGBEEncoding = 3002; // AKA Radiance.
  216. THREE.LogLuvEncoding = 3003;
  217. THREE.RGBM7Encoding = 3004;
  218. THREE.RGBM16Encoding = 3005;
  219. THREE.RGBDEncoding = 3006; // MaxRange is 256.
  220. // Depth packing strategies
  221. THREE.BasicDepthPacking = 3200; // for writing to float textures for high precision or for visualizing results in RGB buffers
  222. THREE.RGBADepthPacking = 3201; // for packing into RGBA buffers.
  223. // File:src/math/Color.js
  224. /**
  225. * @author mrdoob / http://mrdoob.com/
  226. */
  227. THREE.Color = function ( r, g, b ) {
  228. if ( g === undefined && b === undefined ) {
  229. // r is THREE.Color, hex or string
  230. return this.set( r );
  231. }
  232. return this.setRGB( r, g, b );
  233. };
  234. THREE.Color.prototype = {
  235. constructor: THREE.Color,
  236. r: 1, g: 1, b: 1,
  237. set: function ( value ) {
  238. if ( value instanceof THREE.Color ) {
  239. this.copy( value );
  240. } else if ( typeof value === 'number' ) {
  241. this.setHex( value );
  242. } else if ( typeof value === 'string' ) {
  243. this.setStyle( value );
  244. }
  245. return this;
  246. },
  247. setScalar: function ( scalar ) {
  248. this.r = scalar;
  249. this.g = scalar;
  250. this.b = scalar;
  251. },
  252. setHex: function ( hex ) {
  253. hex = Math.floor( hex );
  254. this.r = ( hex >> 16 & 255 ) / 255;
  255. this.g = ( hex >> 8 & 255 ) / 255;
  256. this.b = ( hex & 255 ) / 255;
  257. return this;
  258. },
  259. setRGB: function ( r, g, b ) {
  260. this.r = r;
  261. this.g = g;
  262. this.b = b;
  263. return this;
  264. },
  265. setHSL: function () {
  266. function hue2rgb( p, q, t ) {
  267. if ( t < 0 ) t += 1;
  268. if ( t > 1 ) t -= 1;
  269. if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
  270. if ( t < 1 / 2 ) return q;
  271. if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
  272. return p;
  273. }
  274. return function ( h, s, l ) {
  275. // h,s,l ranges are in 0.0 - 1.0
  276. h = THREE.Math.euclideanModulo( h, 1 );
  277. s = THREE.Math.clamp( s, 0, 1 );
  278. l = THREE.Math.clamp( l, 0, 1 );
  279. if ( s === 0 ) {
  280. this.r = this.g = this.b = l;
  281. } else {
  282. var p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  283. var q = ( 2 * l ) - p;
  284. this.r = hue2rgb( q, p, h + 1 / 3 );
  285. this.g = hue2rgb( q, p, h );
  286. this.b = hue2rgb( q, p, h - 1 / 3 );
  287. }
  288. return this;
  289. };
  290. }(),
  291. setStyle: function ( style ) {
  292. function handleAlpha( string ) {
  293. if ( string === undefined ) return;
  294. if ( parseFloat( string ) < 1 ) {
  295. console.warn( 'THREE.Color: Alpha component of ' + style + ' will be ignored.' );
  296. }
  297. }
  298. var m;
  299. if ( m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec( style ) ) {
  300. // rgb / hsl
  301. var color;
  302. var name = m[ 1 ];
  303. var components = m[ 2 ];
  304. switch ( name ) {
  305. case 'rgb':
  306. case 'rgba':
  307. if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  308. // rgb(255,0,0) rgba(255,0,0,0.5)
  309. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  310. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  311. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  312. handleAlpha( color[ 5 ] );
  313. return this;
  314. }
  315. if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  316. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  317. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  318. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  319. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  320. handleAlpha( color[ 5 ] );
  321. return this;
  322. }
  323. break;
  324. case 'hsl':
  325. case 'hsla':
  326. if ( color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  327. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  328. var h = parseFloat( color[ 1 ] ) / 360;
  329. var s = parseInt( color[ 2 ], 10 ) / 100;
  330. var l = parseInt( color[ 3 ], 10 ) / 100;
  331. handleAlpha( color[ 5 ] );
  332. return this.setHSL( h, s, l );
  333. }
  334. break;
  335. }
  336. } else if ( m = /^\#([A-Fa-f0-9]+)$/.exec( style ) ) {
  337. // hex color
  338. var hex = m[ 1 ];
  339. var size = hex.length;
  340. if ( size === 3 ) {
  341. // #ff0
  342. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 0 ), 16 ) / 255;
  343. this.g = parseInt( hex.charAt( 1 ) + hex.charAt( 1 ), 16 ) / 255;
  344. this.b = parseInt( hex.charAt( 2 ) + hex.charAt( 2 ), 16 ) / 255;
  345. return this;
  346. } else if ( size === 6 ) {
  347. // #ff0000
  348. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 1 ), 16 ) / 255;
  349. this.g = parseInt( hex.charAt( 2 ) + hex.charAt( 3 ), 16 ) / 255;
  350. this.b = parseInt( hex.charAt( 4 ) + hex.charAt( 5 ), 16 ) / 255;
  351. return this;
  352. }
  353. }
  354. if ( style && style.length > 0 ) {
  355. // color keywords
  356. var hex = THREE.ColorKeywords[ style ];
  357. if ( hex !== undefined ) {
  358. // red
  359. this.setHex( hex );
  360. } else {
  361. // unknown color
  362. console.warn( 'THREE.Color: Unknown color ' + style );
  363. }
  364. }
  365. return this;
  366. },
  367. clone: function () {
  368. return new this.constructor( this.r, this.g, this.b );
  369. },
  370. copy: function ( color ) {
  371. this.r = color.r;
  372. this.g = color.g;
  373. this.b = color.b;
  374. return this;
  375. },
  376. copyGammaToLinear: function ( color, gammaFactor ) {
  377. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  378. this.r = Math.pow( color.r, gammaFactor );
  379. this.g = Math.pow( color.g, gammaFactor );
  380. this.b = Math.pow( color.b, gammaFactor );
  381. return this;
  382. },
  383. copyLinearToGamma: function ( color, gammaFactor ) {
  384. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  385. var safeInverse = ( gammaFactor > 0 ) ? ( 1.0 / gammaFactor ) : 1.0;
  386. this.r = Math.pow( color.r, safeInverse );
  387. this.g = Math.pow( color.g, safeInverse );
  388. this.b = Math.pow( color.b, safeInverse );
  389. return this;
  390. },
  391. convertGammaToLinear: function () {
  392. var r = this.r, g = this.g, b = this.b;
  393. this.r = r * r;
  394. this.g = g * g;
  395. this.b = b * b;
  396. return this;
  397. },
  398. convertLinearToGamma: function () {
  399. this.r = Math.sqrt( this.r );
  400. this.g = Math.sqrt( this.g );
  401. this.b = Math.sqrt( this.b );
  402. return this;
  403. },
  404. getHex: function () {
  405. return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
  406. },
  407. getHexString: function () {
  408. return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
  409. },
  410. getHSL: function ( optionalTarget ) {
  411. // h,s,l ranges are in 0.0 - 1.0
  412. var hsl = optionalTarget || { h: 0, s: 0, l: 0 };
  413. var r = this.r, g = this.g, b = this.b;
  414. var max = Math.max( r, g, b );
  415. var min = Math.min( r, g, b );
  416. var hue, saturation;
  417. var lightness = ( min + max ) / 2.0;
  418. if ( min === max ) {
  419. hue = 0;
  420. saturation = 0;
  421. } else {
  422. var delta = max - min;
  423. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  424. switch ( max ) {
  425. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  426. case g: hue = ( b - r ) / delta + 2; break;
  427. case b: hue = ( r - g ) / delta + 4; break;
  428. }
  429. hue /= 6;
  430. }
  431. hsl.h = hue;
  432. hsl.s = saturation;
  433. hsl.l = lightness;
  434. return hsl;
  435. },
  436. getStyle: function () {
  437. return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
  438. },
  439. offsetHSL: function ( h, s, l ) {
  440. var hsl = this.getHSL();
  441. hsl.h += h; hsl.s += s; hsl.l += l;
  442. this.setHSL( hsl.h, hsl.s, hsl.l );
  443. return this;
  444. },
  445. add: function ( color ) {
  446. this.r += color.r;
  447. this.g += color.g;
  448. this.b += color.b;
  449. return this;
  450. },
  451. addColors: function ( color1, color2 ) {
  452. this.r = color1.r + color2.r;
  453. this.g = color1.g + color2.g;
  454. this.b = color1.b + color2.b;
  455. return this;
  456. },
  457. addScalar: function ( s ) {
  458. this.r += s;
  459. this.g += s;
  460. this.b += s;
  461. return this;
  462. },
  463. multiply: function ( color ) {
  464. this.r *= color.r;
  465. this.g *= color.g;
  466. this.b *= color.b;
  467. return this;
  468. },
  469. multiplyScalar: function ( s ) {
  470. this.r *= s;
  471. this.g *= s;
  472. this.b *= s;
  473. return this;
  474. },
  475. lerp: function ( color, alpha ) {
  476. this.r += ( color.r - this.r ) * alpha;
  477. this.g += ( color.g - this.g ) * alpha;
  478. this.b += ( color.b - this.b ) * alpha;
  479. return this;
  480. },
  481. equals: function ( c ) {
  482. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  483. },
  484. fromArray: function ( array, offset ) {
  485. if ( offset === undefined ) offset = 0;
  486. this.r = array[ offset ];
  487. this.g = array[ offset + 1 ];
  488. this.b = array[ offset + 2 ];
  489. return this;
  490. },
  491. toArray: function ( array, offset ) {
  492. if ( array === undefined ) array = [];
  493. if ( offset === undefined ) offset = 0;
  494. array[ offset ] = this.r;
  495. array[ offset + 1 ] = this.g;
  496. array[ offset + 2 ] = this.b;
  497. return array;
  498. }
  499. };
  500. THREE.ColorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  501. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  502. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  503. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  504. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  505. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  506. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  507. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  508. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  509. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  510. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  511. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  512. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  513. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  514. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  515. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  516. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  517. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  518. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  519. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  520. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  521. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  522. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  523. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  524. // File:src/math/Quaternion.js
  525. /**
  526. * @author mikael emtinger / http://gomo.se/
  527. * @author alteredq / http://alteredqualia.com/
  528. * @author WestLangley / http://github.com/WestLangley
  529. * @author bhouston / http://clara.io
  530. */
  531. THREE.Quaternion = function ( x, y, z, w ) {
  532. this._x = x || 0;
  533. this._y = y || 0;
  534. this._z = z || 0;
  535. this._w = ( w !== undefined ) ? w : 1;
  536. };
  537. THREE.Quaternion.prototype = {
  538. constructor: THREE.Quaternion,
  539. get x () {
  540. return this._x;
  541. },
  542. set x ( value ) {
  543. this._x = value;
  544. this.onChangeCallback();
  545. },
  546. get y () {
  547. return this._y;
  548. },
  549. set y ( value ) {
  550. this._y = value;
  551. this.onChangeCallback();
  552. },
  553. get z () {
  554. return this._z;
  555. },
  556. set z ( value ) {
  557. this._z = value;
  558. this.onChangeCallback();
  559. },
  560. get w () {
  561. return this._w;
  562. },
  563. set w ( value ) {
  564. this._w = value;
  565. this.onChangeCallback();
  566. },
  567. set: function ( x, y, z, w ) {
  568. this._x = x;
  569. this._y = y;
  570. this._z = z;
  571. this._w = w;
  572. this.onChangeCallback();
  573. return this;
  574. },
  575. clone: function () {
  576. return new this.constructor( this._x, this._y, this._z, this._w );
  577. },
  578. copy: function ( quaternion ) {
  579. this._x = quaternion.x;
  580. this._y = quaternion.y;
  581. this._z = quaternion.z;
  582. this._w = quaternion.w;
  583. this.onChangeCallback();
  584. return this;
  585. },
  586. setFromEuler: function ( euler, update ) {
  587. if ( euler instanceof THREE.Euler === false ) {
  588. throw new Error( 'THREE.Quaternion: .setFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  589. }
  590. // http://www.mathworks.com/matlabcentral/fileexchange/
  591. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  592. // content/SpinCalc.m
  593. var c1 = Math.cos( euler._x / 2 );
  594. var c2 = Math.cos( euler._y / 2 );
  595. var c3 = Math.cos( euler._z / 2 );
  596. var s1 = Math.sin( euler._x / 2 );
  597. var s2 = Math.sin( euler._y / 2 );
  598. var s3 = Math.sin( euler._z / 2 );
  599. var order = euler.order;
  600. if ( order === 'XYZ' ) {
  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 === 'YXZ' ) {
  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 === 'ZXY' ) {
  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 === 'ZYX' ) {
  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 === 'YZX' ) {
  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. } else if ( order === 'XZY' ) {
  626. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  627. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  628. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  629. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  630. }
  631. if ( update !== false ) this.onChangeCallback();
  632. return this;
  633. },
  634. setFromAxisAngle: function ( axis, angle ) {
  635. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  636. // assumes axis is normalized
  637. var halfAngle = angle / 2, s = Math.sin( halfAngle );
  638. this._x = axis.x * s;
  639. this._y = axis.y * s;
  640. this._z = axis.z * s;
  641. this._w = Math.cos( halfAngle );
  642. this.onChangeCallback();
  643. return this;
  644. },
  645. setFromRotationMatrix: function ( m ) {
  646. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  647. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  648. var te = m.elements,
  649. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  650. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  651. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ],
  652. trace = m11 + m22 + m33,
  653. s;
  654. if ( trace > 0 ) {
  655. s = 0.5 / Math.sqrt( trace + 1.0 );
  656. this._w = 0.25 / s;
  657. this._x = ( m32 - m23 ) * s;
  658. this._y = ( m13 - m31 ) * s;
  659. this._z = ( m21 - m12 ) * s;
  660. } else if ( m11 > m22 && m11 > m33 ) {
  661. s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );
  662. this._w = ( m32 - m23 ) / s;
  663. this._x = 0.25 * s;
  664. this._y = ( m12 + m21 ) / s;
  665. this._z = ( m13 + m31 ) / s;
  666. } else if ( m22 > m33 ) {
  667. s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );
  668. this._w = ( m13 - m31 ) / s;
  669. this._x = ( m12 + m21 ) / s;
  670. this._y = 0.25 * s;
  671. this._z = ( m23 + m32 ) / s;
  672. } else {
  673. s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );
  674. this._w = ( m21 - m12 ) / s;
  675. this._x = ( m13 + m31 ) / s;
  676. this._y = ( m23 + m32 ) / s;
  677. this._z = 0.25 * s;
  678. }
  679. this.onChangeCallback();
  680. return this;
  681. },
  682. setFromUnitVectors: function () {
  683. // http://lolengine.net/blog/2014/02/24/quaternion-from-two-vectors-final
  684. // assumes direction vectors vFrom and vTo are normalized
  685. var v1, r;
  686. var EPS = 0.000001;
  687. return function ( vFrom, vTo ) {
  688. if ( v1 === undefined ) v1 = new THREE.Vector3();
  689. r = vFrom.dot( vTo ) + 1;
  690. if ( r < EPS ) {
  691. r = 0;
  692. if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) {
  693. v1.set( - vFrom.y, vFrom.x, 0 );
  694. } else {
  695. v1.set( 0, - vFrom.z, vFrom.y );
  696. }
  697. } else {
  698. v1.crossVectors( vFrom, vTo );
  699. }
  700. this._x = v1.x;
  701. this._y = v1.y;
  702. this._z = v1.z;
  703. this._w = r;
  704. return this.normalize();
  705. };
  706. }(),
  707. inverse: function () {
  708. return this.conjugate().normalize();
  709. },
  710. conjugate: function () {
  711. this._x *= - 1;
  712. this._y *= - 1;
  713. this._z *= - 1;
  714. this.onChangeCallback();
  715. return this;
  716. },
  717. dot: function ( v ) {
  718. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  719. },
  720. lengthSq: function () {
  721. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  722. },
  723. length: function () {
  724. return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );
  725. },
  726. normalize: function () {
  727. var l = this.length();
  728. if ( l === 0 ) {
  729. this._x = 0;
  730. this._y = 0;
  731. this._z = 0;
  732. this._w = 1;
  733. } else {
  734. l = 1 / l;
  735. this._x = this._x * l;
  736. this._y = this._y * l;
  737. this._z = this._z * l;
  738. this._w = this._w * l;
  739. }
  740. this.onChangeCallback();
  741. return this;
  742. },
  743. multiply: function ( q, p ) {
  744. if ( p !== undefined ) {
  745. console.warn( 'THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.' );
  746. return this.multiplyQuaternions( q, p );
  747. }
  748. return this.multiplyQuaternions( this, q );
  749. },
  750. multiplyQuaternions: function ( a, b ) {
  751. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  752. var qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
  753. var qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
  754. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  755. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  756. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  757. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  758. this.onChangeCallback();
  759. return this;
  760. },
  761. slerp: function ( qb, t ) {
  762. if ( t === 0 ) return this;
  763. if ( t === 1 ) return this.copy( qb );
  764. var x = this._x, y = this._y, z = this._z, w = this._w;
  765. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  766. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  767. if ( cosHalfTheta < 0 ) {
  768. this._w = - qb._w;
  769. this._x = - qb._x;
  770. this._y = - qb._y;
  771. this._z = - qb._z;
  772. cosHalfTheta = - cosHalfTheta;
  773. } else {
  774. this.copy( qb );
  775. }
  776. if ( cosHalfTheta >= 1.0 ) {
  777. this._w = w;
  778. this._x = x;
  779. this._y = y;
  780. this._z = z;
  781. return this;
  782. }
  783. var sinHalfTheta = Math.sqrt( 1.0 - cosHalfTheta * cosHalfTheta );
  784. if ( Math.abs( sinHalfTheta ) < 0.001 ) {
  785. this._w = 0.5 * ( w + this._w );
  786. this._x = 0.5 * ( x + this._x );
  787. this._y = 0.5 * ( y + this._y );
  788. this._z = 0.5 * ( z + this._z );
  789. return this;
  790. }
  791. var halfTheta = Math.atan2( sinHalfTheta, cosHalfTheta );
  792. var ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  793. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  794. this._w = ( w * ratioA + this._w * ratioB );
  795. this._x = ( x * ratioA + this._x * ratioB );
  796. this._y = ( y * ratioA + this._y * ratioB );
  797. this._z = ( z * ratioA + this._z * ratioB );
  798. this.onChangeCallback();
  799. return this;
  800. },
  801. equals: function ( quaternion ) {
  802. return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
  803. },
  804. fromArray: function ( array, offset ) {
  805. if ( offset === undefined ) offset = 0;
  806. this._x = array[ offset ];
  807. this._y = array[ offset + 1 ];
  808. this._z = array[ offset + 2 ];
  809. this._w = array[ offset + 3 ];
  810. this.onChangeCallback();
  811. return this;
  812. },
  813. toArray: function ( array, offset ) {
  814. if ( array === undefined ) array = [];
  815. if ( offset === undefined ) offset = 0;
  816. array[ offset ] = this._x;
  817. array[ offset + 1 ] = this._y;
  818. array[ offset + 2 ] = this._z;
  819. array[ offset + 3 ] = this._w;
  820. return array;
  821. },
  822. onChange: function ( callback ) {
  823. this.onChangeCallback = callback;
  824. return this;
  825. },
  826. onChangeCallback: function () {}
  827. };
  828. Object.assign( THREE.Quaternion, {
  829. slerp: function( qa, qb, qm, t ) {
  830. return qm.copy( qa ).slerp( qb, t );
  831. },
  832. slerpFlat: function(
  833. dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t ) {
  834. // fuzz-free, array-based Quaternion SLERP operation
  835. var x0 = src0[ srcOffset0 + 0 ],
  836. y0 = src0[ srcOffset0 + 1 ],
  837. z0 = src0[ srcOffset0 + 2 ],
  838. w0 = src0[ srcOffset0 + 3 ],
  839. x1 = src1[ srcOffset1 + 0 ],
  840. y1 = src1[ srcOffset1 + 1 ],
  841. z1 = src1[ srcOffset1 + 2 ],
  842. w1 = src1[ srcOffset1 + 3 ];
  843. if ( w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1 ) {
  844. var s = 1 - t,
  845. cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  846. dir = ( cos >= 0 ? 1 : - 1 ),
  847. sqrSin = 1 - cos * cos;
  848. // Skip the Slerp for tiny steps to avoid numeric problems:
  849. if ( sqrSin > Number.EPSILON ) {
  850. var sin = Math.sqrt( sqrSin ),
  851. len = Math.atan2( sin, cos * dir );
  852. s = Math.sin( s * len ) / sin;
  853. t = Math.sin( t * len ) / sin;
  854. }
  855. var tDir = t * dir;
  856. x0 = x0 * s + x1 * tDir;
  857. y0 = y0 * s + y1 * tDir;
  858. z0 = z0 * s + z1 * tDir;
  859. w0 = w0 * s + w1 * tDir;
  860. // Normalize in case we just did a lerp:
  861. if ( s === 1 - t ) {
  862. var f = 1 / Math.sqrt( x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0 );
  863. x0 *= f;
  864. y0 *= f;
  865. z0 *= f;
  866. w0 *= f;
  867. }
  868. }
  869. dst[ dstOffset ] = x0;
  870. dst[ dstOffset + 1 ] = y0;
  871. dst[ dstOffset + 2 ] = z0;
  872. dst[ dstOffset + 3 ] = w0;
  873. }
  874. } );
  875. // File:src/math/Vector2.js
  876. /**
  877. * @author mrdoob / http://mrdoob.com/
  878. * @author philogb / http://blog.thejit.org/
  879. * @author egraether / http://egraether.com/
  880. * @author zz85 / http://www.lab4games.net/zz85/blog
  881. */
  882. THREE.Vector2 = function ( x, y ) {
  883. this.x = x || 0;
  884. this.y = y || 0;
  885. };
  886. THREE.Vector2.prototype = {
  887. constructor: THREE.Vector2,
  888. get width() {
  889. return this.x;
  890. },
  891. set width( value ) {
  892. this.x = value;
  893. },
  894. get height() {
  895. return this.y;
  896. },
  897. set height( value ) {
  898. this.y = value;
  899. },
  900. //
  901. set: function ( x, y ) {
  902. this.x = x;
  903. this.y = y;
  904. return this;
  905. },
  906. setScalar: function ( scalar ) {
  907. this.x = scalar;
  908. this.y = scalar;
  909. return this;
  910. },
  911. setX: function ( x ) {
  912. this.x = x;
  913. return this;
  914. },
  915. setY: function ( y ) {
  916. this.y = y;
  917. return this;
  918. },
  919. setComponent: function ( index, value ) {
  920. switch ( index ) {
  921. case 0: this.x = value; break;
  922. case 1: this.y = value; break;
  923. default: throw new Error( 'index is out of range: ' + index );
  924. }
  925. },
  926. getComponent: function ( index ) {
  927. switch ( index ) {
  928. case 0: return this.x;
  929. case 1: return this.y;
  930. default: throw new Error( 'index is out of range: ' + index );
  931. }
  932. },
  933. clone: function () {
  934. return new this.constructor( this.x, this.y );
  935. },
  936. copy: function ( v ) {
  937. this.x = v.x;
  938. this.y = v.y;
  939. return this;
  940. },
  941. add: function ( v, w ) {
  942. if ( w !== undefined ) {
  943. console.warn( 'THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  944. return this.addVectors( v, w );
  945. }
  946. this.x += v.x;
  947. this.y += v.y;
  948. return this;
  949. },
  950. addScalar: function ( s ) {
  951. this.x += s;
  952. this.y += s;
  953. return this;
  954. },
  955. addVectors: function ( a, b ) {
  956. this.x = a.x + b.x;
  957. this.y = a.y + b.y;
  958. return this;
  959. },
  960. addScaledVector: function ( v, s ) {
  961. this.x += v.x * s;
  962. this.y += v.y * s;
  963. return this;
  964. },
  965. sub: function ( v, w ) {
  966. if ( w !== undefined ) {
  967. console.warn( 'THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  968. return this.subVectors( v, w );
  969. }
  970. this.x -= v.x;
  971. this.y -= v.y;
  972. return this;
  973. },
  974. subScalar: function ( s ) {
  975. this.x -= s;
  976. this.y -= s;
  977. return this;
  978. },
  979. subVectors: function ( a, b ) {
  980. this.x = a.x - b.x;
  981. this.y = a.y - b.y;
  982. return this;
  983. },
  984. multiply: function ( v ) {
  985. this.x *= v.x;
  986. this.y *= v.y;
  987. return this;
  988. },
  989. multiplyScalar: function ( scalar ) {
  990. if ( isFinite( scalar ) ) {
  991. this.x *= scalar;
  992. this.y *= scalar;
  993. } else {
  994. this.x = 0;
  995. this.y = 0;
  996. }
  997. return this;
  998. },
  999. divide: function ( v ) {
  1000. this.x /= v.x;
  1001. this.y /= v.y;
  1002. return this;
  1003. },
  1004. divideScalar: function ( scalar ) {
  1005. return this.multiplyScalar( 1 / scalar );
  1006. },
  1007. min: function ( v ) {
  1008. this.x = Math.min( this.x, v.x );
  1009. this.y = Math.min( this.y, v.y );
  1010. return this;
  1011. },
  1012. max: function ( v ) {
  1013. this.x = Math.max( this.x, v.x );
  1014. this.y = Math.max( this.y, v.y );
  1015. return this;
  1016. },
  1017. clamp: function ( min, max ) {
  1018. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1019. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1020. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1021. return this;
  1022. },
  1023. clampScalar: function () {
  1024. var min, max;
  1025. return function clampScalar( minVal, maxVal ) {
  1026. if ( min === undefined ) {
  1027. min = new THREE.Vector2();
  1028. max = new THREE.Vector2();
  1029. }
  1030. min.set( minVal, minVal );
  1031. max.set( maxVal, maxVal );
  1032. return this.clamp( min, max );
  1033. };
  1034. }(),
  1035. clampLength: function ( min, max ) {
  1036. var length = this.length();
  1037. return this.multiplyScalar( Math.max( min, Math.min( max, length ) ) / length );
  1038. },
  1039. floor: function () {
  1040. this.x = Math.floor( this.x );
  1041. this.y = Math.floor( this.y );
  1042. return this;
  1043. },
  1044. ceil: function () {
  1045. this.x = Math.ceil( this.x );
  1046. this.y = Math.ceil( this.y );
  1047. return this;
  1048. },
  1049. round: function () {
  1050. this.x = Math.round( this.x );
  1051. this.y = Math.round( this.y );
  1052. return this;
  1053. },
  1054. roundToZero: function () {
  1055. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1056. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1057. return this;
  1058. },
  1059. negate: function () {
  1060. this.x = - this.x;
  1061. this.y = - this.y;
  1062. return this;
  1063. },
  1064. dot: function ( v ) {
  1065. return this.x * v.x + this.y * v.y;
  1066. },
  1067. lengthSq: function () {
  1068. return this.x * this.x + this.y * this.y;
  1069. },
  1070. length: function () {
  1071. return Math.sqrt( this.x * this.x + this.y * this.y );
  1072. },
  1073. lengthManhattan: function() {
  1074. return Math.abs( this.x ) + Math.abs( this.y );
  1075. },
  1076. normalize: function () {
  1077. return this.divideScalar( this.length() );
  1078. },
  1079. angle: function () {
  1080. // computes the angle in radians with respect to the positive x-axis
  1081. var angle = Math.atan2( this.y, this.x );
  1082. if ( angle < 0 ) angle += 2 * Math.PI;
  1083. return angle;
  1084. },
  1085. distanceTo: function ( v ) {
  1086. return Math.sqrt( this.distanceToSquared( v ) );
  1087. },
  1088. distanceToSquared: function ( v ) {
  1089. var dx = this.x - v.x, dy = this.y - v.y;
  1090. return dx * dx + dy * dy;
  1091. },
  1092. setLength: function ( length ) {
  1093. return this.multiplyScalar( length / this.length() );
  1094. },
  1095. lerp: function ( v, alpha ) {
  1096. this.x += ( v.x - this.x ) * alpha;
  1097. this.y += ( v.y - this.y ) * alpha;
  1098. return this;
  1099. },
  1100. lerpVectors: function ( v1, v2, alpha ) {
  1101. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1102. },
  1103. equals: function ( v ) {
  1104. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  1105. },
  1106. fromArray: function ( array, offset ) {
  1107. if ( offset === undefined ) offset = 0;
  1108. this.x = array[ offset ];
  1109. this.y = array[ offset + 1 ];
  1110. return this;
  1111. },
  1112. toArray: function ( array, offset ) {
  1113. if ( array === undefined ) array = [];
  1114. if ( offset === undefined ) offset = 0;
  1115. array[ offset ] = this.x;
  1116. array[ offset + 1 ] = this.y;
  1117. return array;
  1118. },
  1119. fromAttribute: function ( attribute, index, offset ) {
  1120. if ( offset === undefined ) offset = 0;
  1121. index = index * attribute.itemSize + offset;
  1122. this.x = attribute.array[ index ];
  1123. this.y = attribute.array[ index + 1 ];
  1124. return this;
  1125. },
  1126. rotateAround: function ( center, angle ) {
  1127. var c = Math.cos( angle ), s = Math.sin( angle );
  1128. var x = this.x - center.x;
  1129. var y = this.y - center.y;
  1130. this.x = x * c - y * s + center.x;
  1131. this.y = x * s + y * c + center.y;
  1132. return this;
  1133. }
  1134. };
  1135. // File:src/math/Vector3.js
  1136. /**
  1137. * @author mrdoob / http://mrdoob.com/
  1138. * @author *kile / http://kile.stravaganza.org/
  1139. * @author philogb / http://blog.thejit.org/
  1140. * @author mikael emtinger / http://gomo.se/
  1141. * @author egraether / http://egraether.com/
  1142. * @author WestLangley / http://github.com/WestLangley
  1143. */
  1144. THREE.Vector3 = function ( x, y, z ) {
  1145. this.x = x || 0;
  1146. this.y = y || 0;
  1147. this.z = z || 0;
  1148. };
  1149. THREE.Vector3.prototype = {
  1150. constructor: THREE.Vector3,
  1151. set: function ( x, y, z ) {
  1152. this.x = x;
  1153. this.y = y;
  1154. this.z = z;
  1155. return this;
  1156. },
  1157. setScalar: function ( scalar ) {
  1158. this.x = scalar;
  1159. this.y = scalar;
  1160. this.z = scalar;
  1161. return this;
  1162. },
  1163. setX: function ( x ) {
  1164. this.x = x;
  1165. return this;
  1166. },
  1167. setY: function ( y ) {
  1168. this.y = y;
  1169. return this;
  1170. },
  1171. setZ: function ( z ) {
  1172. this.z = z;
  1173. return this;
  1174. },
  1175. setComponent: function ( index, value ) {
  1176. switch ( index ) {
  1177. case 0: this.x = value; break;
  1178. case 1: this.y = value; break;
  1179. case 2: this.z = value; break;
  1180. default: throw new Error( 'index is out of range: ' + index );
  1181. }
  1182. },
  1183. getComponent: function ( index ) {
  1184. switch ( index ) {
  1185. case 0: return this.x;
  1186. case 1: return this.y;
  1187. case 2: return this.z;
  1188. default: throw new Error( 'index is out of range: ' + index );
  1189. }
  1190. },
  1191. clone: function () {
  1192. return new this.constructor( this.x, this.y, this.z );
  1193. },
  1194. copy: function ( v ) {
  1195. this.x = v.x;
  1196. this.y = v.y;
  1197. this.z = v.z;
  1198. return this;
  1199. },
  1200. add: function ( v, w ) {
  1201. if ( w !== undefined ) {
  1202. console.warn( 'THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1203. return this.addVectors( v, w );
  1204. }
  1205. this.x += v.x;
  1206. this.y += v.y;
  1207. this.z += v.z;
  1208. return this;
  1209. },
  1210. addScalar: function ( s ) {
  1211. this.x += s;
  1212. this.y += s;
  1213. this.z += s;
  1214. return this;
  1215. },
  1216. addVectors: function ( a, b ) {
  1217. this.x = a.x + b.x;
  1218. this.y = a.y + b.y;
  1219. this.z = a.z + b.z;
  1220. return this;
  1221. },
  1222. addScaledVector: function ( v, s ) {
  1223. this.x += v.x * s;
  1224. this.y += v.y * s;
  1225. this.z += v.z * s;
  1226. return this;
  1227. },
  1228. sub: function ( v, w ) {
  1229. if ( w !== undefined ) {
  1230. console.warn( 'THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1231. return this.subVectors( v, w );
  1232. }
  1233. this.x -= v.x;
  1234. this.y -= v.y;
  1235. this.z -= v.z;
  1236. return this;
  1237. },
  1238. subScalar: function ( s ) {
  1239. this.x -= s;
  1240. this.y -= s;
  1241. this.z -= s;
  1242. return this;
  1243. },
  1244. subVectors: function ( a, b ) {
  1245. this.x = a.x - b.x;
  1246. this.y = a.y - b.y;
  1247. this.z = a.z - b.z;
  1248. return this;
  1249. },
  1250. multiply: function ( v, w ) {
  1251. if ( w !== undefined ) {
  1252. console.warn( 'THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.' );
  1253. return this.multiplyVectors( v, w );
  1254. }
  1255. this.x *= v.x;
  1256. this.y *= v.y;
  1257. this.z *= v.z;
  1258. return this;
  1259. },
  1260. multiplyScalar: function ( scalar ) {
  1261. if ( isFinite( scalar ) ) {
  1262. this.x *= scalar;
  1263. this.y *= scalar;
  1264. this.z *= scalar;
  1265. } else {
  1266. this.x = 0;
  1267. this.y = 0;
  1268. this.z = 0;
  1269. }
  1270. return this;
  1271. },
  1272. multiplyVectors: function ( a, b ) {
  1273. this.x = a.x * b.x;
  1274. this.y = a.y * b.y;
  1275. this.z = a.z * b.z;
  1276. return this;
  1277. },
  1278. applyEuler: function () {
  1279. var quaternion;
  1280. return function applyEuler( euler ) {
  1281. if ( euler instanceof THREE.Euler === false ) {
  1282. console.error( 'THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  1283. }
  1284. if ( quaternion === undefined ) quaternion = new THREE.Quaternion();
  1285. return this.applyQuaternion( quaternion.setFromEuler( euler ) );
  1286. };
  1287. }(),
  1288. applyAxisAngle: function () {
  1289. var quaternion;
  1290. return function applyAxisAngle( axis, angle ) {
  1291. if ( quaternion === undefined ) quaternion = new THREE.Quaternion();
  1292. return this.applyQuaternion( quaternion.setFromAxisAngle( axis, angle ) );
  1293. };
  1294. }(),
  1295. applyMatrix3: function ( m ) {
  1296. var x = this.x, y = this.y, z = this.z;
  1297. var e = m.elements;
  1298. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
  1299. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
  1300. this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
  1301. return this;
  1302. },
  1303. applyMatrix4: function ( m ) {
  1304. // input: THREE.Matrix4 affine matrix
  1305. var x = this.x, y = this.y, z = this.z;
  1306. var e = m.elements;
  1307. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ];
  1308. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ];
  1309. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ];
  1310. return this;
  1311. },
  1312. applyProjection: function ( m ) {
  1313. // input: THREE.Matrix4 projection matrix
  1314. var x = this.x, y = this.y, z = this.z;
  1315. var e = m.elements;
  1316. var d = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] ); // perspective divide
  1317. this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * d;
  1318. this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * d;
  1319. this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * d;
  1320. return this;
  1321. },
  1322. applyQuaternion: function ( q ) {
  1323. var x = this.x, y = this.y, z = this.z;
  1324. var qx = q.x, qy = q.y, qz = q.z, qw = q.w;
  1325. // calculate quat * vector
  1326. var ix = qw * x + qy * z - qz * y;
  1327. var iy = qw * y + qz * x - qx * z;
  1328. var iz = qw * z + qx * y - qy * x;
  1329. var iw = - qx * x - qy * y - qz * z;
  1330. // calculate result * inverse quat
  1331. this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
  1332. this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
  1333. this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
  1334. return this;
  1335. },
  1336. project: function () {
  1337. var matrix;
  1338. return function project( camera ) {
  1339. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  1340. matrix.multiplyMatrices( camera.projectionMatrix, matrix.getInverse( camera.matrixWorld ) );
  1341. return this.applyProjection( matrix );
  1342. };
  1343. }(),
  1344. unproject: function () {
  1345. var matrix;
  1346. return function unproject( camera ) {
  1347. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  1348. matrix.multiplyMatrices( camera.matrixWorld, matrix.getInverse( camera.projectionMatrix ) );
  1349. return this.applyProjection( matrix );
  1350. };
  1351. }(),
  1352. transformDirection: function ( m ) {
  1353. // input: THREE.Matrix4 affine matrix
  1354. // vector interpreted as a direction
  1355. var x = this.x, y = this.y, z = this.z;
  1356. var e = m.elements;
  1357. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
  1358. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
  1359. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
  1360. return this.normalize();
  1361. },
  1362. divide: function ( v ) {
  1363. this.x /= v.x;
  1364. this.y /= v.y;
  1365. this.z /= v.z;
  1366. return this;
  1367. },
  1368. divideScalar: function ( scalar ) {
  1369. return this.multiplyScalar( 1 / scalar );
  1370. },
  1371. min: function ( v ) {
  1372. this.x = Math.min( this.x, v.x );
  1373. this.y = Math.min( this.y, v.y );
  1374. this.z = Math.min( this.z, v.z );
  1375. return this;
  1376. },
  1377. max: function ( v ) {
  1378. this.x = Math.max( this.x, v.x );
  1379. this.y = Math.max( this.y, v.y );
  1380. this.z = Math.max( this.z, v.z );
  1381. return this;
  1382. },
  1383. clamp: function ( min, max ) {
  1384. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1385. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1386. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1387. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  1388. return this;
  1389. },
  1390. clampScalar: function () {
  1391. var min, max;
  1392. return function clampScalar( minVal, maxVal ) {
  1393. if ( min === undefined ) {
  1394. min = new THREE.Vector3();
  1395. max = new THREE.Vector3();
  1396. }
  1397. min.set( minVal, minVal, minVal );
  1398. max.set( maxVal, maxVal, maxVal );
  1399. return this.clamp( min, max );
  1400. };
  1401. }(),
  1402. clampLength: function ( min, max ) {
  1403. var length = this.length();
  1404. return this.multiplyScalar( Math.max( min, Math.min( max, length ) ) / length );
  1405. },
  1406. floor: function () {
  1407. this.x = Math.floor( this.x );
  1408. this.y = Math.floor( this.y );
  1409. this.z = Math.floor( this.z );
  1410. return this;
  1411. },
  1412. ceil: function () {
  1413. this.x = Math.ceil( this.x );
  1414. this.y = Math.ceil( this.y );
  1415. this.z = Math.ceil( this.z );
  1416. return this;
  1417. },
  1418. round: function () {
  1419. this.x = Math.round( this.x );
  1420. this.y = Math.round( this.y );
  1421. this.z = Math.round( this.z );
  1422. return this;
  1423. },
  1424. roundToZero: function () {
  1425. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1426. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1427. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1428. return this;
  1429. },
  1430. negate: function () {
  1431. this.x = - this.x;
  1432. this.y = - this.y;
  1433. this.z = - this.z;
  1434. return this;
  1435. },
  1436. dot: function ( v ) {
  1437. return this.x * v.x + this.y * v.y + this.z * v.z;
  1438. },
  1439. lengthSq: function () {
  1440. return this.x * this.x + this.y * this.y + this.z * this.z;
  1441. },
  1442. length: function () {
  1443. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
  1444. },
  1445. lengthManhattan: function () {
  1446. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  1447. },
  1448. normalize: function () {
  1449. return this.divideScalar( this.length() );
  1450. },
  1451. setLength: function ( length ) {
  1452. return this.multiplyScalar( length / this.length() );
  1453. },
  1454. lerp: function ( v, alpha ) {
  1455. this.x += ( v.x - this.x ) * alpha;
  1456. this.y += ( v.y - this.y ) * alpha;
  1457. this.z += ( v.z - this.z ) * alpha;
  1458. return this;
  1459. },
  1460. lerpVectors: function ( v1, v2, alpha ) {
  1461. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1462. },
  1463. cross: function ( v, w ) {
  1464. if ( w !== undefined ) {
  1465. console.warn( 'THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.' );
  1466. return this.crossVectors( v, w );
  1467. }
  1468. var x = this.x, y = this.y, z = this.z;
  1469. this.x = y * v.z - z * v.y;
  1470. this.y = z * v.x - x * v.z;
  1471. this.z = x * v.y - y * v.x;
  1472. return this;
  1473. },
  1474. crossVectors: function ( a, b ) {
  1475. var ax = a.x, ay = a.y, az = a.z;
  1476. var bx = b.x, by = b.y, bz = b.z;
  1477. this.x = ay * bz - az * by;
  1478. this.y = az * bx - ax * bz;
  1479. this.z = ax * by - ay * bx;
  1480. return this;
  1481. },
  1482. projectOnVector: function () {
  1483. var v1, dot;
  1484. return function projectOnVector( vector ) {
  1485. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1486. v1.copy( vector ).normalize();
  1487. dot = this.dot( v1 );
  1488. return this.copy( v1 ).multiplyScalar( dot );
  1489. };
  1490. }(),
  1491. projectOnPlane: function () {
  1492. var v1;
  1493. return function projectOnPlane( planeNormal ) {
  1494. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1495. v1.copy( this ).projectOnVector( planeNormal );
  1496. return this.sub( v1 );
  1497. };
  1498. }(),
  1499. reflect: function () {
  1500. // reflect incident vector off plane orthogonal to normal
  1501. // normal is assumed to have unit length
  1502. var v1;
  1503. return function reflect( normal ) {
  1504. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1505. return this.sub( v1.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
  1506. };
  1507. }(),
  1508. angleTo: function ( v ) {
  1509. var theta = this.dot( v ) / ( Math.sqrt( this.lengthSq() * v.lengthSq() ) );
  1510. // clamp, to handle numerical problems
  1511. return Math.acos( THREE.Math.clamp( theta, - 1, 1 ) );
  1512. },
  1513. distanceTo: function ( v ) {
  1514. return Math.sqrt( this.distanceToSquared( v ) );
  1515. },
  1516. distanceToSquared: function ( v ) {
  1517. var dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;
  1518. return dx * dx + dy * dy + dz * dz;
  1519. },
  1520. setFromSpherical: function( s ) {
  1521. var sinPhiRadius = Math.sin( s.phi ) * s.radius;
  1522. this.x = sinPhiRadius * Math.sin( s.theta );
  1523. this.y = Math.cos( s.phi ) * s.radius;
  1524. this.z = sinPhiRadius * Math.cos( s.theta );
  1525. return this;
  1526. },
  1527. setFromMatrixPosition: function ( m ) {
  1528. return this.setFromMatrixColumn( m, 3 );
  1529. },
  1530. setFromMatrixScale: function ( m ) {
  1531. var sx = this.setFromMatrixColumn( m, 0 ).length();
  1532. var sy = this.setFromMatrixColumn( m, 1 ).length();
  1533. var sz = this.setFromMatrixColumn( m, 2 ).length();
  1534. this.x = sx;
  1535. this.y = sy;
  1536. this.z = sz;
  1537. return this;
  1538. },
  1539. setFromMatrixColumn: function ( m, index ) {
  1540. if ( typeof m === 'number' ) {
  1541. console.warn( 'THREE.Vector3: setFromMatrixColumn now expects ( matrix, index ).' );
  1542. var temp = m
  1543. m = index;
  1544. index = temp;
  1545. }
  1546. return this.fromArray( m.elements, index * 4 );
  1547. },
  1548. equals: function ( v ) {
  1549. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  1550. },
  1551. fromArray: function ( array, offset ) {
  1552. if ( offset === undefined ) offset = 0;
  1553. this.x = array[ offset ];
  1554. this.y = array[ offset + 1 ];
  1555. this.z = array[ offset + 2 ];
  1556. return this;
  1557. },
  1558. toArray: function ( array, offset ) {
  1559. if ( array === undefined ) array = [];
  1560. if ( offset === undefined ) offset = 0;
  1561. array[ offset ] = this.x;
  1562. array[ offset + 1 ] = this.y;
  1563. array[ offset + 2 ] = this.z;
  1564. return array;
  1565. },
  1566. fromAttribute: function ( attribute, index, offset ) {
  1567. if ( offset === undefined ) offset = 0;
  1568. index = index * attribute.itemSize + offset;
  1569. this.x = attribute.array[ index ];
  1570. this.y = attribute.array[ index + 1 ];
  1571. this.z = attribute.array[ index + 2 ];
  1572. return this;
  1573. }
  1574. };
  1575. // File:src/math/Vector4.js
  1576. /**
  1577. * @author supereggbert / http://www.paulbrunt.co.uk/
  1578. * @author philogb / http://blog.thejit.org/
  1579. * @author mikael emtinger / http://gomo.se/
  1580. * @author egraether / http://egraether.com/
  1581. * @author WestLangley / http://github.com/WestLangley
  1582. */
  1583. THREE.Vector4 = function ( x, y, z, w ) {
  1584. this.x = x || 0;
  1585. this.y = y || 0;
  1586. this.z = z || 0;
  1587. this.w = ( w !== undefined ) ? w : 1;
  1588. };
  1589. THREE.Vector4.prototype = {
  1590. constructor: THREE.Vector4,
  1591. set: function ( x, y, z, w ) {
  1592. this.x = x;
  1593. this.y = y;
  1594. this.z = z;
  1595. this.w = w;
  1596. return this;
  1597. },
  1598. setScalar: function ( scalar ) {
  1599. this.x = scalar;
  1600. this.y = scalar;
  1601. this.z = scalar;
  1602. this.w = scalar;
  1603. return this;
  1604. },
  1605. setX: function ( x ) {
  1606. this.x = x;
  1607. return this;
  1608. },
  1609. setY: function ( y ) {
  1610. this.y = y;
  1611. return this;
  1612. },
  1613. setZ: function ( z ) {
  1614. this.z = z;
  1615. return this;
  1616. },
  1617. setW: function ( w ) {
  1618. this.w = w;
  1619. return this;
  1620. },
  1621. setComponent: function ( index, value ) {
  1622. switch ( index ) {
  1623. case 0: this.x = value; break;
  1624. case 1: this.y = value; break;
  1625. case 2: this.z = value; break;
  1626. case 3: this.w = value; break;
  1627. default: throw new Error( 'index is out of range: ' + index );
  1628. }
  1629. },
  1630. getComponent: function ( index ) {
  1631. switch ( index ) {
  1632. case 0: return this.x;
  1633. case 1: return this.y;
  1634. case 2: return this.z;
  1635. case 3: return this.w;
  1636. default: throw new Error( 'index is out of range: ' + index );
  1637. }
  1638. },
  1639. clone: function () {
  1640. return new this.constructor( this.x, this.y, this.z, this.w );
  1641. },
  1642. copy: function ( v ) {
  1643. this.x = v.x;
  1644. this.y = v.y;
  1645. this.z = v.z;
  1646. this.w = ( v.w !== undefined ) ? v.w : 1;
  1647. return this;
  1648. },
  1649. add: function ( v, w ) {
  1650. if ( w !== undefined ) {
  1651. console.warn( 'THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1652. return this.addVectors( v, w );
  1653. }
  1654. this.x += v.x;
  1655. this.y += v.y;
  1656. this.z += v.z;
  1657. this.w += v.w;
  1658. return this;
  1659. },
  1660. addScalar: function ( s ) {
  1661. this.x += s;
  1662. this.y += s;
  1663. this.z += s;
  1664. this.w += s;
  1665. return this;
  1666. },
  1667. addVectors: function ( a, b ) {
  1668. this.x = a.x + b.x;
  1669. this.y = a.y + b.y;
  1670. this.z = a.z + b.z;
  1671. this.w = a.w + b.w;
  1672. return this;
  1673. },
  1674. addScaledVector: function ( v, s ) {
  1675. this.x += v.x * s;
  1676. this.y += v.y * s;
  1677. this.z += v.z * s;
  1678. this.w += v.w * s;
  1679. return this;
  1680. },
  1681. sub: function ( v, w ) {
  1682. if ( w !== undefined ) {
  1683. console.warn( 'THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1684. return this.subVectors( v, w );
  1685. }
  1686. this.x -= v.x;
  1687. this.y -= v.y;
  1688. this.z -= v.z;
  1689. this.w -= v.w;
  1690. return this;
  1691. },
  1692. subScalar: function ( s ) {
  1693. this.x -= s;
  1694. this.y -= s;
  1695. this.z -= s;
  1696. this.w -= s;
  1697. return this;
  1698. },
  1699. subVectors: function ( a, b ) {
  1700. this.x = a.x - b.x;
  1701. this.y = a.y - b.y;
  1702. this.z = a.z - b.z;
  1703. this.w = a.w - b.w;
  1704. return this;
  1705. },
  1706. multiplyScalar: function ( scalar ) {
  1707. if ( isFinite( scalar ) ) {
  1708. this.x *= scalar;
  1709. this.y *= scalar;
  1710. this.z *= scalar;
  1711. this.w *= scalar;
  1712. } else {
  1713. this.x = 0;
  1714. this.y = 0;
  1715. this.z = 0;
  1716. this.w = 0;
  1717. }
  1718. return this;
  1719. },
  1720. applyMatrix4: function ( m ) {
  1721. var x = this.x, y = this.y, z = this.z, w = this.w;
  1722. var e = m.elements;
  1723. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  1724. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  1725. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  1726. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  1727. return this;
  1728. },
  1729. divideScalar: function ( scalar ) {
  1730. return this.multiplyScalar( 1 / scalar );
  1731. },
  1732. setAxisAngleFromQuaternion: function ( q ) {
  1733. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  1734. // q is assumed to be normalized
  1735. this.w = 2 * Math.acos( q.w );
  1736. var s = Math.sqrt( 1 - q.w * q.w );
  1737. if ( s < 0.0001 ) {
  1738. this.x = 1;
  1739. this.y = 0;
  1740. this.z = 0;
  1741. } else {
  1742. this.x = q.x / s;
  1743. this.y = q.y / s;
  1744. this.z = q.z / s;
  1745. }
  1746. return this;
  1747. },
  1748. setAxisAngleFromRotationMatrix: function ( m ) {
  1749. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  1750. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1751. var angle, x, y, z, // variables for result
  1752. epsilon = 0.01, // margin to allow for rounding errors
  1753. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  1754. te = m.elements,
  1755. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  1756. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  1757. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  1758. if ( ( Math.abs( m12 - m21 ) < epsilon ) &&
  1759. ( Math.abs( m13 - m31 ) < epsilon ) &&
  1760. ( Math.abs( m23 - m32 ) < epsilon ) ) {
  1761. // singularity found
  1762. // first check for identity matrix which must have +1 for all terms
  1763. // in leading diagonal and zero in other terms
  1764. if ( ( Math.abs( m12 + m21 ) < epsilon2 ) &&
  1765. ( Math.abs( m13 + m31 ) < epsilon2 ) &&
  1766. ( Math.abs( m23 + m32 ) < epsilon2 ) &&
  1767. ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  1768. // this singularity is identity matrix so angle = 0
  1769. this.set( 1, 0, 0, 0 );
  1770. return this; // zero angle, arbitrary axis
  1771. }
  1772. // otherwise this singularity is angle = 180
  1773. angle = Math.PI;
  1774. var xx = ( m11 + 1 ) / 2;
  1775. var yy = ( m22 + 1 ) / 2;
  1776. var zz = ( m33 + 1 ) / 2;
  1777. var xy = ( m12 + m21 ) / 4;
  1778. var xz = ( m13 + m31 ) / 4;
  1779. var yz = ( m23 + m32 ) / 4;
  1780. if ( ( xx > yy ) && ( xx > zz ) ) {
  1781. // m11 is the largest diagonal term
  1782. if ( xx < epsilon ) {
  1783. x = 0;
  1784. y = 0.707106781;
  1785. z = 0.707106781;
  1786. } else {
  1787. x = Math.sqrt( xx );
  1788. y = xy / x;
  1789. z = xz / x;
  1790. }
  1791. } else if ( yy > zz ) {
  1792. // m22 is the largest diagonal term
  1793. if ( yy < epsilon ) {
  1794. x = 0.707106781;
  1795. y = 0;
  1796. z = 0.707106781;
  1797. } else {
  1798. y = Math.sqrt( yy );
  1799. x = xy / y;
  1800. z = yz / y;
  1801. }
  1802. } else {
  1803. // m33 is the largest diagonal term so base result on this
  1804. if ( zz < epsilon ) {
  1805. x = 0.707106781;
  1806. y = 0.707106781;
  1807. z = 0;
  1808. } else {
  1809. z = Math.sqrt( zz );
  1810. x = xz / z;
  1811. y = yz / z;
  1812. }
  1813. }
  1814. this.set( x, y, z, angle );
  1815. return this; // return 180 deg rotation
  1816. }
  1817. // as we have reached here there are no singularities so we can handle normally
  1818. var s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 ) +
  1819. ( m13 - m31 ) * ( m13 - m31 ) +
  1820. ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  1821. if ( Math.abs( s ) < 0.001 ) s = 1;
  1822. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  1823. // caught by singularity test above, but I've left it in just in case
  1824. this.x = ( m32 - m23 ) / s;
  1825. this.y = ( m13 - m31 ) / s;
  1826. this.z = ( m21 - m12 ) / s;
  1827. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  1828. return this;
  1829. },
  1830. min: function ( v ) {
  1831. this.x = Math.min( this.x, v.x );
  1832. this.y = Math.min( this.y, v.y );
  1833. this.z = Math.min( this.z, v.z );
  1834. this.w = Math.min( this.w, v.w );
  1835. return this;
  1836. },
  1837. max: function ( v ) {
  1838. this.x = Math.max( this.x, v.x );
  1839. this.y = Math.max( this.y, v.y );
  1840. this.z = Math.max( this.z, v.z );
  1841. this.w = Math.max( this.w, v.w );
  1842. return this;
  1843. },
  1844. clamp: function ( min, max ) {
  1845. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1846. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1847. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1848. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  1849. this.w = Math.max( min.w, Math.min( max.w, this.w ) );
  1850. return this;
  1851. },
  1852. clampScalar: function () {
  1853. var min, max;
  1854. return function clampScalar( minVal, maxVal ) {
  1855. if ( min === undefined ) {
  1856. min = new THREE.Vector4();
  1857. max = new THREE.Vector4();
  1858. }
  1859. min.set( minVal, minVal, minVal, minVal );
  1860. max.set( maxVal, maxVal, maxVal, maxVal );
  1861. return this.clamp( min, max );
  1862. };
  1863. }(),
  1864. floor: function () {
  1865. this.x = Math.floor( this.x );
  1866. this.y = Math.floor( this.y );
  1867. this.z = Math.floor( this.z );
  1868. this.w = Math.floor( this.w );
  1869. return this;
  1870. },
  1871. ceil: function () {
  1872. this.x = Math.ceil( this.x );
  1873. this.y = Math.ceil( this.y );
  1874. this.z = Math.ceil( this.z );
  1875. this.w = Math.ceil( this.w );
  1876. return this;
  1877. },
  1878. round: function () {
  1879. this.x = Math.round( this.x );
  1880. this.y = Math.round( this.y );
  1881. this.z = Math.round( this.z );
  1882. this.w = Math.round( this.w );
  1883. return this;
  1884. },
  1885. roundToZero: function () {
  1886. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1887. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1888. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1889. this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
  1890. return this;
  1891. },
  1892. negate: function () {
  1893. this.x = - this.x;
  1894. this.y = - this.y;
  1895. this.z = - this.z;
  1896. this.w = - this.w;
  1897. return this;
  1898. },
  1899. dot: function ( v ) {
  1900. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  1901. },
  1902. lengthSq: function () {
  1903. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  1904. },
  1905. length: function () {
  1906. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  1907. },
  1908. lengthManhattan: function () {
  1909. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  1910. },
  1911. normalize: function () {
  1912. return this.divideScalar( this.length() );
  1913. },
  1914. setLength: function ( length ) {
  1915. return this.multiplyScalar( length / this.length() );
  1916. },
  1917. lerp: function ( v, alpha ) {
  1918. this.x += ( v.x - this.x ) * alpha;
  1919. this.y += ( v.y - this.y ) * alpha;
  1920. this.z += ( v.z - this.z ) * alpha;
  1921. this.w += ( v.w - this.w ) * alpha;
  1922. return this;
  1923. },
  1924. lerpVectors: function ( v1, v2, alpha ) {
  1925. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1926. },
  1927. equals: function ( v ) {
  1928. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  1929. },
  1930. fromArray: function ( array, offset ) {
  1931. if ( offset === undefined ) offset = 0;
  1932. this.x = array[ offset ];
  1933. this.y = array[ offset + 1 ];
  1934. this.z = array[ offset + 2 ];
  1935. this.w = array[ offset + 3 ];
  1936. return this;
  1937. },
  1938. toArray: function ( array, offset ) {
  1939. if ( array === undefined ) array = [];
  1940. if ( offset === undefined ) offset = 0;
  1941. array[ offset ] = this.x;
  1942. array[ offset + 1 ] = this.y;
  1943. array[ offset + 2 ] = this.z;
  1944. array[ offset + 3 ] = this.w;
  1945. return array;
  1946. },
  1947. fromAttribute: function ( attribute, index, offset ) {
  1948. if ( offset === undefined ) offset = 0;
  1949. index = index * attribute.itemSize + offset;
  1950. this.x = attribute.array[ index ];
  1951. this.y = attribute.array[ index + 1 ];
  1952. this.z = attribute.array[ index + 2 ];
  1953. this.w = attribute.array[ index + 3 ];
  1954. return this;
  1955. }
  1956. };
  1957. // File:src/math/Euler.js
  1958. /**
  1959. * @author mrdoob / http://mrdoob.com/
  1960. * @author WestLangley / http://github.com/WestLangley
  1961. * @author bhouston / http://clara.io
  1962. */
  1963. THREE.Euler = function ( x, y, z, order ) {
  1964. this._x = x || 0;
  1965. this._y = y || 0;
  1966. this._z = z || 0;
  1967. this._order = order || THREE.Euler.DefaultOrder;
  1968. };
  1969. THREE.Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
  1970. THREE.Euler.DefaultOrder = 'XYZ';
  1971. THREE.Euler.prototype = {
  1972. constructor: THREE.Euler,
  1973. get x () {
  1974. return this._x;
  1975. },
  1976. set x ( value ) {
  1977. this._x = value;
  1978. this.onChangeCallback();
  1979. },
  1980. get y () {
  1981. return this._y;
  1982. },
  1983. set y ( value ) {
  1984. this._y = value;
  1985. this.onChangeCallback();
  1986. },
  1987. get z () {
  1988. return this._z;
  1989. },
  1990. set z ( value ) {
  1991. this._z = value;
  1992. this.onChangeCallback();
  1993. },
  1994. get order () {
  1995. return this._order;
  1996. },
  1997. set order ( value ) {
  1998. this._order = value;
  1999. this.onChangeCallback();
  2000. },
  2001. set: function ( x, y, z, order ) {
  2002. this._x = x;
  2003. this._y = y;
  2004. this._z = z;
  2005. this._order = order || this._order;
  2006. this.onChangeCallback();
  2007. return this;
  2008. },
  2009. clone: function () {
  2010. return new this.constructor( this._x, this._y, this._z, this._order );
  2011. },
  2012. copy: function ( euler ) {
  2013. this._x = euler._x;
  2014. this._y = euler._y;
  2015. this._z = euler._z;
  2016. this._order = euler._order;
  2017. this.onChangeCallback();
  2018. return this;
  2019. },
  2020. setFromRotationMatrix: function ( m, order, update ) {
  2021. var clamp = THREE.Math.clamp;
  2022. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2023. var te = m.elements;
  2024. var m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  2025. var m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  2026. var m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  2027. order = order || this._order;
  2028. if ( order === 'XYZ' ) {
  2029. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  2030. if ( Math.abs( m13 ) < 0.99999 ) {
  2031. this._x = Math.atan2( - m23, m33 );
  2032. this._z = Math.atan2( - m12, m11 );
  2033. } else {
  2034. this._x = Math.atan2( m32, m22 );
  2035. this._z = 0;
  2036. }
  2037. } else if ( order === 'YXZ' ) {
  2038. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  2039. if ( Math.abs( m23 ) < 0.99999 ) {
  2040. this._y = Math.atan2( m13, m33 );
  2041. this._z = Math.atan2( m21, m22 );
  2042. } else {
  2043. this._y = Math.atan2( - m31, m11 );
  2044. this._z = 0;
  2045. }
  2046. } else if ( order === 'ZXY' ) {
  2047. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  2048. if ( Math.abs( m32 ) < 0.99999 ) {
  2049. this._y = Math.atan2( - m31, m33 );
  2050. this._z = Math.atan2( - m12, m22 );
  2051. } else {
  2052. this._y = 0;
  2053. this._z = Math.atan2( m21, m11 );
  2054. }
  2055. } else if ( order === 'ZYX' ) {
  2056. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  2057. if ( Math.abs( m31 ) < 0.99999 ) {
  2058. this._x = Math.atan2( m32, m33 );
  2059. this._z = Math.atan2( m21, m11 );
  2060. } else {
  2061. this._x = 0;
  2062. this._z = Math.atan2( - m12, m22 );
  2063. }
  2064. } else if ( order === 'YZX' ) {
  2065. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  2066. if ( Math.abs( m21 ) < 0.99999 ) {
  2067. this._x = Math.atan2( - m23, m22 );
  2068. this._y = Math.atan2( - m31, m11 );
  2069. } else {
  2070. this._x = 0;
  2071. this._y = Math.atan2( m13, m33 );
  2072. }
  2073. } else if ( order === 'XZY' ) {
  2074. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  2075. if ( Math.abs( m12 ) < 0.99999 ) {
  2076. this._x = Math.atan2( m32, m22 );
  2077. this._y = Math.atan2( m13, m11 );
  2078. } else {
  2079. this._x = Math.atan2( - m23, m33 );
  2080. this._y = 0;
  2081. }
  2082. } else {
  2083. console.warn( 'THREE.Euler: .setFromRotationMatrix() given unsupported order: ' + order );
  2084. }
  2085. this._order = order;
  2086. if ( update !== false ) this.onChangeCallback();
  2087. return this;
  2088. },
  2089. setFromQuaternion: function () {
  2090. var matrix;
  2091. return function ( q, order, update ) {
  2092. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  2093. matrix.makeRotationFromQuaternion( q );
  2094. return this.setFromRotationMatrix( matrix, order, update );
  2095. };
  2096. }(),
  2097. setFromVector3: function ( v, order ) {
  2098. return this.set( v.x, v.y, v.z, order || this._order );
  2099. },
  2100. reorder: function () {
  2101. // WARNING: this discards revolution information -bhouston
  2102. var q = new THREE.Quaternion();
  2103. return function ( newOrder ) {
  2104. q.setFromEuler( this );
  2105. return this.setFromQuaternion( q, newOrder );
  2106. };
  2107. }(),
  2108. equals: function ( euler ) {
  2109. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  2110. },
  2111. fromArray: function ( array ) {
  2112. this._x = array[ 0 ];
  2113. this._y = array[ 1 ];
  2114. this._z = array[ 2 ];
  2115. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  2116. this.onChangeCallback();
  2117. return this;
  2118. },
  2119. toArray: function ( array, offset ) {
  2120. if ( array === undefined ) array = [];
  2121. if ( offset === undefined ) offset = 0;
  2122. array[ offset ] = this._x;
  2123. array[ offset + 1 ] = this._y;
  2124. array[ offset + 2 ] = this._z;
  2125. array[ offset + 3 ] = this._order;
  2126. return array;
  2127. },
  2128. toVector3: function ( optionalResult ) {
  2129. if ( optionalResult ) {
  2130. return optionalResult.set( this._x, this._y, this._z );
  2131. } else {
  2132. return new THREE.Vector3( this._x, this._y, this._z );
  2133. }
  2134. },
  2135. onChange: function ( callback ) {
  2136. this.onChangeCallback = callback;
  2137. return this;
  2138. },
  2139. onChangeCallback: function () {}
  2140. };
  2141. // File:src/math/Line3.js
  2142. /**
  2143. * @author bhouston / http://clara.io
  2144. */
  2145. THREE.Line3 = function ( start, end ) {
  2146. this.start = ( start !== undefined ) ? start : new THREE.Vector3();
  2147. this.end = ( end !== undefined ) ? end : new THREE.Vector3();
  2148. };
  2149. THREE.Line3.prototype = {
  2150. constructor: THREE.Line3,
  2151. set: function ( start, end ) {
  2152. this.start.copy( start );
  2153. this.end.copy( end );
  2154. return this;
  2155. },
  2156. clone: function () {
  2157. return new this.constructor().copy( this );
  2158. },
  2159. copy: function ( line ) {
  2160. this.start.copy( line.start );
  2161. this.end.copy( line.end );
  2162. return this;
  2163. },
  2164. center: function ( optionalTarget ) {
  2165. var result = optionalTarget || new THREE.Vector3();
  2166. return result.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  2167. },
  2168. delta: function ( optionalTarget ) {
  2169. var result = optionalTarget || new THREE.Vector3();
  2170. return result.subVectors( this.end, this.start );
  2171. },
  2172. distanceSq: function () {
  2173. return this.start.distanceToSquared( this.end );
  2174. },
  2175. distance: function () {
  2176. return this.start.distanceTo( this.end );
  2177. },
  2178. at: function ( t, optionalTarget ) {
  2179. var result = optionalTarget || new THREE.Vector3();
  2180. return this.delta( result ).multiplyScalar( t ).add( this.start );
  2181. },
  2182. closestPointToPointParameter: function () {
  2183. var startP = new THREE.Vector3();
  2184. var startEnd = new THREE.Vector3();
  2185. return function ( point, clampToLine ) {
  2186. startP.subVectors( point, this.start );
  2187. startEnd.subVectors( this.end, this.start );
  2188. var startEnd2 = startEnd.dot( startEnd );
  2189. var startEnd_startP = startEnd.dot( startP );
  2190. var t = startEnd_startP / startEnd2;
  2191. if ( clampToLine ) {
  2192. t = THREE.Math.clamp( t, 0, 1 );
  2193. }
  2194. return t;
  2195. };
  2196. }(),
  2197. closestPointToPoint: function ( point, clampToLine, optionalTarget ) {
  2198. var t = this.closestPointToPointParameter( point, clampToLine );
  2199. var result = optionalTarget || new THREE.Vector3();
  2200. return this.delta( result ).multiplyScalar( t ).add( this.start );
  2201. },
  2202. applyMatrix4: function ( matrix ) {
  2203. this.start.applyMatrix4( matrix );
  2204. this.end.applyMatrix4( matrix );
  2205. return this;
  2206. },
  2207. equals: function ( line ) {
  2208. return line.start.equals( this.start ) && line.end.equals( this.end );
  2209. }
  2210. };
  2211. // File:src/math/Box2.js
  2212. /**
  2213. * @author bhouston / http://clara.io
  2214. */
  2215. THREE.Box2 = function ( min, max ) {
  2216. this.min = ( min !== undefined ) ? min : new THREE.Vector2( + Infinity, + Infinity );
  2217. this.max = ( max !== undefined ) ? max : new THREE.Vector2( - Infinity, - Infinity );
  2218. };
  2219. THREE.Box2.prototype = {
  2220. constructor: THREE.Box2,
  2221. set: function ( min, max ) {
  2222. this.min.copy( min );
  2223. this.max.copy( max );
  2224. return this;
  2225. },
  2226. setFromPoints: function ( points ) {
  2227. this.makeEmpty();
  2228. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2229. this.expandByPoint( points[ i ] );
  2230. }
  2231. return this;
  2232. },
  2233. setFromCenterAndSize: function () {
  2234. var v1 = new THREE.Vector2();
  2235. return function ( center, size ) {
  2236. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2237. this.min.copy( center ).sub( halfSize );
  2238. this.max.copy( center ).add( halfSize );
  2239. return this;
  2240. };
  2241. }(),
  2242. clone: function () {
  2243. return new this.constructor().copy( this );
  2244. },
  2245. copy: function ( box ) {
  2246. this.min.copy( box.min );
  2247. this.max.copy( box.max );
  2248. return this;
  2249. },
  2250. makeEmpty: function () {
  2251. this.min.x = this.min.y = + Infinity;
  2252. this.max.x = this.max.y = - Infinity;
  2253. return this;
  2254. },
  2255. isEmpty: function () {
  2256. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2257. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  2258. },
  2259. center: function ( optionalTarget ) {
  2260. var result = optionalTarget || new THREE.Vector2();
  2261. return result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2262. },
  2263. size: function ( optionalTarget ) {
  2264. var result = optionalTarget || new THREE.Vector2();
  2265. return result.subVectors( this.max, this.min );
  2266. },
  2267. expandByPoint: function ( point ) {
  2268. this.min.min( point );
  2269. this.max.max( point );
  2270. return this;
  2271. },
  2272. expandByVector: function ( vector ) {
  2273. this.min.sub( vector );
  2274. this.max.add( vector );
  2275. return this;
  2276. },
  2277. expandByScalar: function ( scalar ) {
  2278. this.min.addScalar( - scalar );
  2279. this.max.addScalar( scalar );
  2280. return this;
  2281. },
  2282. containsPoint: function ( point ) {
  2283. if ( point.x < this.min.x || point.x > this.max.x ||
  2284. point.y < this.min.y || point.y > this.max.y ) {
  2285. return false;
  2286. }
  2287. return true;
  2288. },
  2289. containsBox: function ( box ) {
  2290. if ( ( this.min.x <= box.min.x ) && ( box.max.x <= this.max.x ) &&
  2291. ( this.min.y <= box.min.y ) && ( box.max.y <= this.max.y ) ) {
  2292. return true;
  2293. }
  2294. return false;
  2295. },
  2296. getParameter: function ( point, optionalTarget ) {
  2297. // This can potentially have a divide by zero if the box
  2298. // has a size dimension of 0.
  2299. var result = optionalTarget || new THREE.Vector2();
  2300. return result.set(
  2301. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2302. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  2303. );
  2304. },
  2305. intersectsBox: function ( box ) {
  2306. // using 6 splitting planes to rule out intersections.
  2307. if ( box.max.x < this.min.x || box.min.x > this.max.x ||
  2308. box.max.y < this.min.y || box.min.y > this.max.y ) {
  2309. return false;
  2310. }
  2311. return true;
  2312. },
  2313. clampPoint: function ( point, optionalTarget ) {
  2314. var result = optionalTarget || new THREE.Vector2();
  2315. return result.copy( point ).clamp( this.min, this.max );
  2316. },
  2317. distanceToPoint: function () {
  2318. var v1 = new THREE.Vector2();
  2319. return function ( point ) {
  2320. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  2321. return clampedPoint.sub( point ).length();
  2322. };
  2323. }(),
  2324. intersect: function ( box ) {
  2325. this.min.max( box.min );
  2326. this.max.min( box.max );
  2327. return this;
  2328. },
  2329. union: function ( box ) {
  2330. this.min.min( box.min );
  2331. this.max.max( box.max );
  2332. return this;
  2333. },
  2334. translate: function ( offset ) {
  2335. this.min.add( offset );
  2336. this.max.add( offset );
  2337. return this;
  2338. },
  2339. equals: function ( box ) {
  2340. return box.min.equals( this.min ) && box.max.equals( this.max );
  2341. }
  2342. };
  2343. // File:src/math/Box3.js
  2344. /**
  2345. * @author bhouston / http://clara.io
  2346. * @author WestLangley / http://github.com/WestLangley
  2347. */
  2348. THREE.Box3 = function ( min, max ) {
  2349. this.min = ( min !== undefined ) ? min : new THREE.Vector3( + Infinity, + Infinity, + Infinity );
  2350. this.max = ( max !== undefined ) ? max : new THREE.Vector3( - Infinity, - Infinity, - Infinity );
  2351. };
  2352. THREE.Box3.prototype = {
  2353. constructor: THREE.Box3,
  2354. set: function ( min, max ) {
  2355. this.min.copy( min );
  2356. this.max.copy( max );
  2357. return this;
  2358. },
  2359. setFromArray: function ( array ) {
  2360. var minX = + Infinity;
  2361. var minY = + Infinity;
  2362. var minZ = + Infinity;
  2363. var maxX = - Infinity;
  2364. var maxY = - Infinity;
  2365. var maxZ = - Infinity;
  2366. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  2367. var x = array[ i ];
  2368. var y = array[ i + 1 ];
  2369. var z = array[ i + 2 ];
  2370. if ( x < minX ) minX = x;
  2371. if ( y < minY ) minY = y;
  2372. if ( z < minZ ) minZ = z;
  2373. if ( x > maxX ) maxX = x;
  2374. if ( y > maxY ) maxY = y;
  2375. if ( z > maxZ ) maxZ = z;
  2376. }
  2377. this.min.set( minX, minY, minZ );
  2378. this.max.set( maxX, maxY, maxZ );
  2379. },
  2380. setFromPoints: function ( points ) {
  2381. this.makeEmpty();
  2382. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2383. this.expandByPoint( points[ i ] );
  2384. }
  2385. return this;
  2386. },
  2387. setFromCenterAndSize: function () {
  2388. var v1 = new THREE.Vector3();
  2389. return function ( center, size ) {
  2390. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2391. this.min.copy( center ).sub( halfSize );
  2392. this.max.copy( center ).add( halfSize );
  2393. return this;
  2394. };
  2395. }(),
  2396. setFromObject: function () {
  2397. // Computes the world-axis-aligned bounding box of an object (including its children),
  2398. // accounting for both the object's, and children's, world transforms
  2399. var v1 = new THREE.Vector3();
  2400. return function ( object ) {
  2401. var scope = this;
  2402. object.updateMatrixWorld( true );
  2403. this.makeEmpty();
  2404. object.traverse( function ( node ) {
  2405. var geometry = node.geometry;
  2406. if ( geometry !== undefined ) {
  2407. if ( geometry instanceof THREE.Geometry ) {
  2408. var vertices = geometry.vertices;
  2409. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  2410. v1.copy( vertices[ i ] );
  2411. v1.applyMatrix4( node.matrixWorld );
  2412. scope.expandByPoint( v1 );
  2413. }
  2414. } else if ( geometry instanceof THREE.BufferGeometry && geometry.attributes[ 'position' ] !== undefined ) {
  2415. var positions = geometry.attributes[ 'position' ].array;
  2416. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  2417. v1.fromArray( positions, i );
  2418. v1.applyMatrix4( node.matrixWorld );
  2419. scope.expandByPoint( v1 );
  2420. }
  2421. }
  2422. }
  2423. } );
  2424. return this;
  2425. };
  2426. }(),
  2427. clone: function () {
  2428. return new this.constructor().copy( this );
  2429. },
  2430. copy: function ( box ) {
  2431. this.min.copy( box.min );
  2432. this.max.copy( box.max );
  2433. return this;
  2434. },
  2435. makeEmpty: function () {
  2436. this.min.x = this.min.y = this.min.z = + Infinity;
  2437. this.max.x = this.max.y = this.max.z = - Infinity;
  2438. return this;
  2439. },
  2440. isEmpty: function () {
  2441. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2442. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  2443. },
  2444. center: function ( optionalTarget ) {
  2445. var result = optionalTarget || new THREE.Vector3();
  2446. return result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2447. },
  2448. size: function ( optionalTarget ) {
  2449. var result = optionalTarget || new THREE.Vector3();
  2450. return result.subVectors( this.max, this.min );
  2451. },
  2452. expandByPoint: function ( point ) {
  2453. this.min.min( point );
  2454. this.max.max( point );
  2455. return this;
  2456. },
  2457. expandByVector: function ( vector ) {
  2458. this.min.sub( vector );
  2459. this.max.add( vector );
  2460. return this;
  2461. },
  2462. expandByScalar: function ( scalar ) {
  2463. this.min.addScalar( - scalar );
  2464. this.max.addScalar( scalar );
  2465. return this;
  2466. },
  2467. containsPoint: function ( point ) {
  2468. if ( point.x < this.min.x || point.x > this.max.x ||
  2469. point.y < this.min.y || point.y > this.max.y ||
  2470. point.z < this.min.z || point.z > this.max.z ) {
  2471. return false;
  2472. }
  2473. return true;
  2474. },
  2475. containsBox: function ( box ) {
  2476. if ( ( this.min.x <= box.min.x ) && ( box.max.x <= this.max.x ) &&
  2477. ( this.min.y <= box.min.y ) && ( box.max.y <= this.max.y ) &&
  2478. ( this.min.z <= box.min.z ) && ( box.max.z <= this.max.z ) ) {
  2479. return true;
  2480. }
  2481. return false;
  2482. },
  2483. getParameter: function ( point, optionalTarget ) {
  2484. // This can potentially have a divide by zero if the box
  2485. // has a size dimension of 0.
  2486. var result = optionalTarget || new THREE.Vector3();
  2487. return result.set(
  2488. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2489. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  2490. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  2491. );
  2492. },
  2493. intersectsBox: function ( box ) {
  2494. // using 6 splitting planes to rule out intersections.
  2495. if ( box.max.x < this.min.x || box.min.x > this.max.x ||
  2496. box.max.y < this.min.y || box.min.y > this.max.y ||
  2497. box.max.z < this.min.z || box.min.z > this.max.z ) {
  2498. return false;
  2499. }
  2500. return true;
  2501. },
  2502. intersectsSphere: ( function () {
  2503. var closestPoint;
  2504. return function intersectsSphere( sphere ) {
  2505. if ( closestPoint === undefined ) closestPoint = new THREE.Vector3();
  2506. // Find the point on the AABB closest to the sphere center.
  2507. this.clampPoint( sphere.center, closestPoint );
  2508. // If that point is inside the sphere, the AABB and sphere intersect.
  2509. return closestPoint.distanceToSquared( sphere.center ) <= ( sphere.radius * sphere.radius );
  2510. };
  2511. } )(),
  2512. intersectsPlane: function ( plane ) {
  2513. // We compute the minimum and maximum dot product values. If those values
  2514. // are on the same side (back or front) of the plane, then there is no intersection.
  2515. var min, max;
  2516. if ( plane.normal.x > 0 ) {
  2517. min = plane.normal.x * this.min.x;
  2518. max = plane.normal.x * this.max.x;
  2519. } else {
  2520. min = plane.normal.x * this.max.x;
  2521. max = plane.normal.x * this.min.x;
  2522. }
  2523. if ( plane.normal.y > 0 ) {
  2524. min += plane.normal.y * this.min.y;
  2525. max += plane.normal.y * this.max.y;
  2526. } else {
  2527. min += plane.normal.y * this.max.y;
  2528. max += plane.normal.y * this.min.y;
  2529. }
  2530. if ( plane.normal.z > 0 ) {
  2531. min += plane.normal.z * this.min.z;
  2532. max += plane.normal.z * this.max.z;
  2533. } else {
  2534. min += plane.normal.z * this.max.z;
  2535. max += plane.normal.z * this.min.z;
  2536. }
  2537. return ( min <= plane.constant && max >= plane.constant );
  2538. },
  2539. clampPoint: function ( point, optionalTarget ) {
  2540. var result = optionalTarget || new THREE.Vector3();
  2541. return result.copy( point ).clamp( this.min, this.max );
  2542. },
  2543. distanceToPoint: function () {
  2544. var v1 = new THREE.Vector3();
  2545. return function ( point ) {
  2546. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  2547. return clampedPoint.sub( point ).length();
  2548. };
  2549. }(),
  2550. getBoundingSphere: function () {
  2551. var v1 = new THREE.Vector3();
  2552. return function ( optionalTarget ) {
  2553. var result = optionalTarget || new THREE.Sphere();
  2554. result.center = this.center();
  2555. result.radius = this.size( v1 ).length() * 0.5;
  2556. return result;
  2557. };
  2558. }(),
  2559. intersect: function ( box ) {
  2560. this.min.max( box.min );
  2561. this.max.min( box.max );
  2562. // ensure that if there is no overlap, the result is fully empty, not slightly empty with non-inf/+inf values that will cause subsequence intersects to erroneously return valid values.
  2563. if( this.isEmpty() ) this.makeEmpty();
  2564. return this;
  2565. },
  2566. union: function ( box ) {
  2567. this.min.min( box.min );
  2568. this.max.max( box.max );
  2569. return this;
  2570. },
  2571. applyMatrix4: function () {
  2572. var points = [
  2573. new THREE.Vector3(),
  2574. new THREE.Vector3(),
  2575. new THREE.Vector3(),
  2576. new THREE.Vector3(),
  2577. new THREE.Vector3(),
  2578. new THREE.Vector3(),
  2579. new THREE.Vector3(),
  2580. new THREE.Vector3()
  2581. ];
  2582. return function ( matrix ) {
  2583. // transform of empty box is an empty box.
  2584. if( this.isEmpty() ) return this;
  2585. // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  2586. points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
  2587. points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
  2588. points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
  2589. points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
  2590. points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
  2591. points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
  2592. points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
  2593. points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
  2594. this.setFromPoints( points );
  2595. return this;
  2596. };
  2597. }(),
  2598. translate: function ( offset ) {
  2599. this.min.add( offset );
  2600. this.max.add( offset );
  2601. return this;
  2602. },
  2603. equals: function ( box ) {
  2604. return box.min.equals( this.min ) && box.max.equals( this.max );
  2605. }
  2606. };
  2607. // File:src/math/Matrix3.js
  2608. /**
  2609. * @author alteredq / http://alteredqualia.com/
  2610. * @author WestLangley / http://github.com/WestLangley
  2611. * @author bhouston / http://clara.io
  2612. * @author tschw
  2613. */
  2614. THREE.Matrix3 = function () {
  2615. this.elements = new Float32Array( [
  2616. 1, 0, 0,
  2617. 0, 1, 0,
  2618. 0, 0, 1
  2619. ] );
  2620. if ( arguments.length > 0 ) {
  2621. console.error( 'THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.' );
  2622. }
  2623. };
  2624. THREE.Matrix3.prototype = {
  2625. constructor: THREE.Matrix3,
  2626. set: function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  2627. var te = this.elements;
  2628. te[ 0 ] = n11; te[ 1 ] = n21; te[ 2 ] = n31;
  2629. te[ 3 ] = n12; te[ 4 ] = n22; te[ 5 ] = n32;
  2630. te[ 6 ] = n13; te[ 7 ] = n23; te[ 8 ] = n33;
  2631. return this;
  2632. },
  2633. identity: function () {
  2634. this.set(
  2635. 1, 0, 0,
  2636. 0, 1, 0,
  2637. 0, 0, 1
  2638. );
  2639. return this;
  2640. },
  2641. clone: function () {
  2642. return new this.constructor().fromArray( this.elements );
  2643. },
  2644. copy: function ( m ) {
  2645. var me = m.elements;
  2646. this.set(
  2647. me[ 0 ], me[ 3 ], me[ 6 ],
  2648. me[ 1 ], me[ 4 ], me[ 7 ],
  2649. me[ 2 ], me[ 5 ], me[ 8 ]
  2650. );
  2651. return this;
  2652. },
  2653. setFromMatrix4: function( m ) {
  2654. var me = m.elements;
  2655. this.set(
  2656. me[ 0 ], me[ 4 ], me[ 8 ],
  2657. me[ 1 ], me[ 5 ], me[ 9 ],
  2658. me[ 2 ], me[ 6 ], me[ 10 ]
  2659. );
  2660. return this;
  2661. },
  2662. applyToVector3Array: function () {
  2663. var v1;
  2664. return function ( array, offset, length ) {
  2665. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2666. if ( offset === undefined ) offset = 0;
  2667. if ( length === undefined ) length = array.length;
  2668. for ( var i = 0, j = offset; i < length; i += 3, j += 3 ) {
  2669. v1.fromArray( array, j );
  2670. v1.applyMatrix3( this );
  2671. v1.toArray( array, j );
  2672. }
  2673. return array;
  2674. };
  2675. }(),
  2676. applyToBuffer: function () {
  2677. var v1;
  2678. return function applyToBuffer( buffer, offset, length ) {
  2679. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2680. if ( offset === undefined ) offset = 0;
  2681. if ( length === undefined ) length = buffer.length / buffer.itemSize;
  2682. for ( var i = 0, j = offset; i < length; i ++, j ++ ) {
  2683. v1.x = buffer.getX( j );
  2684. v1.y = buffer.getY( j );
  2685. v1.z = buffer.getZ( j );
  2686. v1.applyMatrix3( this );
  2687. buffer.setXYZ( v1.x, v1.y, v1.z );
  2688. }
  2689. return buffer;
  2690. };
  2691. }(),
  2692. multiplyScalar: function ( s ) {
  2693. var te = this.elements;
  2694. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  2695. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  2696. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  2697. return this;
  2698. },
  2699. determinant: function () {
  2700. var te = this.elements;
  2701. var a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  2702. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  2703. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  2704. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  2705. },
  2706. getInverse: function ( matrix, throwOnDegenerate ) {
  2707. if ( matrix instanceof THREE.Matrix4 ) {
  2708. console.error( "THREE.Matrix3.getInverse no longer takes a Matrix4 argument." );
  2709. }
  2710. var me = matrix.elements,
  2711. te = this.elements,
  2712. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ],
  2713. n12 = me[ 3 ], n22 = me[ 4 ], n32 = me[ 5 ],
  2714. n13 = me[ 6 ], n23 = me[ 7 ], n33 = me[ 8 ],
  2715. t11 = n33 * n22 - n32 * n23,
  2716. t12 = n32 * n13 - n33 * n12,
  2717. t13 = n23 * n12 - n22 * n13,
  2718. det = n11 * t11 + n21 * t12 + n31 * t13;
  2719. if ( det === 0 ) {
  2720. var msg = "THREE.Matrix3.getInverse(): can't invert matrix, determinant is 0";
  2721. if ( throwOnDegenerate || false ) {
  2722. throw new Error( msg );
  2723. } else {
  2724. console.warn( msg );
  2725. }
  2726. return this.identity();
  2727. }
  2728. te[ 0 ] = t11;
  2729. te[ 1 ] = n31 * n23 - n33 * n21;
  2730. te[ 2 ] = n32 * n21 - n31 * n22;
  2731. te[ 3 ] = t12;
  2732. te[ 4 ] = n33 * n11 - n31 * n13;
  2733. te[ 5 ] = n31 * n12 - n32 * n11;
  2734. te[ 6 ] = t13;
  2735. te[ 7 ] = n21 * n13 - n23 * n11;
  2736. te[ 8 ] = n22 * n11 - n21 * n12;
  2737. return this.multiplyScalar( 1 / det );
  2738. },
  2739. transpose: function () {
  2740. var tmp, m = this.elements;
  2741. tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
  2742. tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
  2743. tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
  2744. return this;
  2745. },
  2746. flattenToArrayOffset: function ( array, offset ) {
  2747. console.warn( "THREE.Matrix3: .flattenToArrayOffset is deprecated " +
  2748. "- just use .toArray instead." );
  2749. return this.toArray( array, offset );
  2750. },
  2751. getNormalMatrix: function ( matrix4 ) {
  2752. return this.setFromMatrix4( matrix4 ).getInverse( this ).transpose();
  2753. },
  2754. transposeIntoArray: function ( r ) {
  2755. var m = this.elements;
  2756. r[ 0 ] = m[ 0 ];
  2757. r[ 1 ] = m[ 3 ];
  2758. r[ 2 ] = m[ 6 ];
  2759. r[ 3 ] = m[ 1 ];
  2760. r[ 4 ] = m[ 4 ];
  2761. r[ 5 ] = m[ 7 ];
  2762. r[ 6 ] = m[ 2 ];
  2763. r[ 7 ] = m[ 5 ];
  2764. r[ 8 ] = m[ 8 ];
  2765. return this;
  2766. },
  2767. fromArray: function ( array ) {
  2768. this.elements.set( array );
  2769. return this;
  2770. },
  2771. toArray: function ( array, offset ) {
  2772. if ( array === undefined ) array = [];
  2773. if ( offset === undefined ) offset = 0;
  2774. var te = this.elements;
  2775. array[ offset ] = te[ 0 ];
  2776. array[ offset + 1 ] = te[ 1 ];
  2777. array[ offset + 2 ] = te[ 2 ];
  2778. array[ offset + 3 ] = te[ 3 ];
  2779. array[ offset + 4 ] = te[ 4 ];
  2780. array[ offset + 5 ] = te[ 5 ];
  2781. array[ offset + 6 ] = te[ 6 ];
  2782. array[ offset + 7 ] = te[ 7 ];
  2783. array[ offset + 8 ] = te[ 8 ];
  2784. return array;
  2785. }
  2786. };
  2787. // File:src/math/Matrix4.js
  2788. /**
  2789. * @author mrdoob / http://mrdoob.com/
  2790. * @author supereggbert / http://www.paulbrunt.co.uk/
  2791. * @author philogb / http://blog.thejit.org/
  2792. * @author jordi_ros / http://plattsoft.com
  2793. * @author D1plo1d / http://github.com/D1plo1d
  2794. * @author alteredq / http://alteredqualia.com/
  2795. * @author mikael emtinger / http://gomo.se/
  2796. * @author timknip / http://www.floorplanner.com/
  2797. * @author bhouston / http://clara.io
  2798. * @author WestLangley / http://github.com/WestLangley
  2799. */
  2800. THREE.Matrix4 = function () {
  2801. this.elements = new Float32Array( [
  2802. 1, 0, 0, 0,
  2803. 0, 1, 0, 0,
  2804. 0, 0, 1, 0,
  2805. 0, 0, 0, 1
  2806. ] );
  2807. if ( arguments.length > 0 ) {
  2808. console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' );
  2809. }
  2810. };
  2811. THREE.Matrix4.prototype = {
  2812. constructor: THREE.Matrix4,
  2813. set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  2814. var te = this.elements;
  2815. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  2816. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  2817. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  2818. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  2819. return this;
  2820. },
  2821. identity: function () {
  2822. this.set(
  2823. 1, 0, 0, 0,
  2824. 0, 1, 0, 0,
  2825. 0, 0, 1, 0,
  2826. 0, 0, 0, 1
  2827. );
  2828. return this;
  2829. },
  2830. clone: function () {
  2831. return new THREE.Matrix4().fromArray( this.elements );
  2832. },
  2833. copy: function ( m ) {
  2834. this.elements.set( m.elements );
  2835. return this;
  2836. },
  2837. copyPosition: function ( m ) {
  2838. var te = this.elements;
  2839. var me = m.elements;
  2840. te[ 12 ] = me[ 12 ];
  2841. te[ 13 ] = me[ 13 ];
  2842. te[ 14 ] = me[ 14 ];
  2843. return this;
  2844. },
  2845. extractBasis: function ( xAxis, yAxis, zAxis ) {
  2846. xAxis.setFromMatrixColumn( this, 0 );
  2847. yAxis.setFromMatrixColumn( this, 1 );
  2848. zAxis.setFromMatrixColumn( this, 2 );
  2849. return this;
  2850. },
  2851. makeBasis: function ( xAxis, yAxis, zAxis ) {
  2852. this.set(
  2853. xAxis.x, yAxis.x, zAxis.x, 0,
  2854. xAxis.y, yAxis.y, zAxis.y, 0,
  2855. xAxis.z, yAxis.z, zAxis.z, 0,
  2856. 0, 0, 0, 1
  2857. );
  2858. return this;
  2859. },
  2860. extractRotation: function () {
  2861. var v1;
  2862. return function ( m ) {
  2863. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2864. var te = this.elements;
  2865. var me = m.elements;
  2866. var scaleX = 1 / v1.setFromMatrixColumn( m, 0 ).length();
  2867. var scaleY = 1 / v1.setFromMatrixColumn( m, 1 ).length();
  2868. var scaleZ = 1 / v1.setFromMatrixColumn( m, 2 ).length();
  2869. te[ 0 ] = me[ 0 ] * scaleX;
  2870. te[ 1 ] = me[ 1 ] * scaleX;
  2871. te[ 2 ] = me[ 2 ] * scaleX;
  2872. te[ 4 ] = me[ 4 ] * scaleY;
  2873. te[ 5 ] = me[ 5 ] * scaleY;
  2874. te[ 6 ] = me[ 6 ] * scaleY;
  2875. te[ 8 ] = me[ 8 ] * scaleZ;
  2876. te[ 9 ] = me[ 9 ] * scaleZ;
  2877. te[ 10 ] = me[ 10 ] * scaleZ;
  2878. return this;
  2879. };
  2880. }(),
  2881. makeRotationFromEuler: function ( euler ) {
  2882. if ( euler instanceof THREE.Euler === false ) {
  2883. console.error( 'THREE.Matrix: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  2884. }
  2885. var te = this.elements;
  2886. var x = euler.x, y = euler.y, z = euler.z;
  2887. var a = Math.cos( x ), b = Math.sin( x );
  2888. var c = Math.cos( y ), d = Math.sin( y );
  2889. var e = Math.cos( z ), f = Math.sin( z );
  2890. if ( euler.order === 'XYZ' ) {
  2891. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2892. te[ 0 ] = c * e;
  2893. te[ 4 ] = - c * f;
  2894. te[ 8 ] = d;
  2895. te[ 1 ] = af + be * d;
  2896. te[ 5 ] = ae - bf * d;
  2897. te[ 9 ] = - b * c;
  2898. te[ 2 ] = bf - ae * d;
  2899. te[ 6 ] = be + af * d;
  2900. te[ 10 ] = a * c;
  2901. } else if ( euler.order === 'YXZ' ) {
  2902. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2903. te[ 0 ] = ce + df * b;
  2904. te[ 4 ] = de * b - cf;
  2905. te[ 8 ] = a * d;
  2906. te[ 1 ] = a * f;
  2907. te[ 5 ] = a * e;
  2908. te[ 9 ] = - b;
  2909. te[ 2 ] = cf * b - de;
  2910. te[ 6 ] = df + ce * b;
  2911. te[ 10 ] = a * c;
  2912. } else if ( euler.order === 'ZXY' ) {
  2913. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2914. te[ 0 ] = ce - df * b;
  2915. te[ 4 ] = - a * f;
  2916. te[ 8 ] = de + cf * b;
  2917. te[ 1 ] = cf + de * b;
  2918. te[ 5 ] = a * e;
  2919. te[ 9 ] = df - ce * b;
  2920. te[ 2 ] = - a * d;
  2921. te[ 6 ] = b;
  2922. te[ 10 ] = a * c;
  2923. } else if ( euler.order === 'ZYX' ) {
  2924. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2925. te[ 0 ] = c * e;
  2926. te[ 4 ] = be * d - af;
  2927. te[ 8 ] = ae * d + bf;
  2928. te[ 1 ] = c * f;
  2929. te[ 5 ] = bf * d + ae;
  2930. te[ 9 ] = af * d - be;
  2931. te[ 2 ] = - d;
  2932. te[ 6 ] = b * c;
  2933. te[ 10 ] = a * c;
  2934. } else if ( euler.order === 'YZX' ) {
  2935. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2936. te[ 0 ] = c * e;
  2937. te[ 4 ] = bd - ac * f;
  2938. te[ 8 ] = bc * f + ad;
  2939. te[ 1 ] = f;
  2940. te[ 5 ] = a * e;
  2941. te[ 9 ] = - b * e;
  2942. te[ 2 ] = - d * e;
  2943. te[ 6 ] = ad * f + bc;
  2944. te[ 10 ] = ac - bd * f;
  2945. } else if ( euler.order === 'XZY' ) {
  2946. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2947. te[ 0 ] = c * e;
  2948. te[ 4 ] = - f;
  2949. te[ 8 ] = d * e;
  2950. te[ 1 ] = ac * f + bd;
  2951. te[ 5 ] = a * e;
  2952. te[ 9 ] = ad * f - bc;
  2953. te[ 2 ] = bc * f - ad;
  2954. te[ 6 ] = b * e;
  2955. te[ 10 ] = bd * f + ac;
  2956. }
  2957. // last column
  2958. te[ 3 ] = 0;
  2959. te[ 7 ] = 0;
  2960. te[ 11 ] = 0;
  2961. // bottom row
  2962. te[ 12 ] = 0;
  2963. te[ 13 ] = 0;
  2964. te[ 14 ] = 0;
  2965. te[ 15 ] = 1;
  2966. return this;
  2967. },
  2968. makeRotationFromQuaternion: function ( q ) {
  2969. var te = this.elements;
  2970. var x = q.x, y = q.y, z = q.z, w = q.w;
  2971. var x2 = x + x, y2 = y + y, z2 = z + z;
  2972. var xx = x * x2, xy = x * y2, xz = x * z2;
  2973. var yy = y * y2, yz = y * z2, zz = z * z2;
  2974. var wx = w * x2, wy = w * y2, wz = w * z2;
  2975. te[ 0 ] = 1 - ( yy + zz );
  2976. te[ 4 ] = xy - wz;
  2977. te[ 8 ] = xz + wy;
  2978. te[ 1 ] = xy + wz;
  2979. te[ 5 ] = 1 - ( xx + zz );
  2980. te[ 9 ] = yz - wx;
  2981. te[ 2 ] = xz - wy;
  2982. te[ 6 ] = yz + wx;
  2983. te[ 10 ] = 1 - ( xx + yy );
  2984. // last column
  2985. te[ 3 ] = 0;
  2986. te[ 7 ] = 0;
  2987. te[ 11 ] = 0;
  2988. // bottom row
  2989. te[ 12 ] = 0;
  2990. te[ 13 ] = 0;
  2991. te[ 14 ] = 0;
  2992. te[ 15 ] = 1;
  2993. return this;
  2994. },
  2995. lookAt: function () {
  2996. var x, y, z;
  2997. return function ( eye, target, up ) {
  2998. if ( x === undefined ) x = new THREE.Vector3();
  2999. if ( y === undefined ) y = new THREE.Vector3();
  3000. if ( z === undefined ) z = new THREE.Vector3();
  3001. var te = this.elements;
  3002. z.subVectors( eye, target ).normalize();
  3003. if ( z.lengthSq() === 0 ) {
  3004. z.z = 1;
  3005. }
  3006. x.crossVectors( up, z ).normalize();
  3007. if ( x.lengthSq() === 0 ) {
  3008. z.x += 0.0001;
  3009. x.crossVectors( up, z ).normalize();
  3010. }
  3011. y.crossVectors( z, x );
  3012. te[ 0 ] = x.x; te[ 4 ] = y.x; te[ 8 ] = z.x;
  3013. te[ 1 ] = x.y; te[ 5 ] = y.y; te[ 9 ] = z.y;
  3014. te[ 2 ] = x.z; te[ 6 ] = y.z; te[ 10 ] = z.z;
  3015. return this;
  3016. };
  3017. }(),
  3018. multiply: function ( m, n ) {
  3019. if ( n !== undefined ) {
  3020. console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' );
  3021. return this.multiplyMatrices( m, n );
  3022. }
  3023. return this.multiplyMatrices( this, m );
  3024. },
  3025. premultiply: function ( m ) {
  3026. return this.multiplyMatrices( m, this );
  3027. },
  3028. multiplyMatrices: function ( a, b ) {
  3029. var ae = a.elements;
  3030. var be = b.elements;
  3031. var te = this.elements;
  3032. var a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  3033. var a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  3034. var a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  3035. var a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  3036. var b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  3037. var b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  3038. var b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  3039. var b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  3040. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  3041. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  3042. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  3043. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  3044. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  3045. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  3046. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  3047. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  3048. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  3049. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  3050. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  3051. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  3052. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  3053. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  3054. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  3055. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  3056. return this;
  3057. },
  3058. multiplyToArray: function ( a, b, r ) {
  3059. var te = this.elements;
  3060. this.multiplyMatrices( a, b );
  3061. r[ 0 ] = te[ 0 ]; r[ 1 ] = te[ 1 ]; r[ 2 ] = te[ 2 ]; r[ 3 ] = te[ 3 ];
  3062. r[ 4 ] = te[ 4 ]; r[ 5 ] = te[ 5 ]; r[ 6 ] = te[ 6 ]; r[ 7 ] = te[ 7 ];
  3063. r[ 8 ] = te[ 8 ]; r[ 9 ] = te[ 9 ]; r[ 10 ] = te[ 10 ]; r[ 11 ] = te[ 11 ];
  3064. r[ 12 ] = te[ 12 ]; r[ 13 ] = te[ 13 ]; r[ 14 ] = te[ 14 ]; r[ 15 ] = te[ 15 ];
  3065. return this;
  3066. },
  3067. multiplyScalar: function ( s ) {
  3068. var te = this.elements;
  3069. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  3070. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  3071. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  3072. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  3073. return this;
  3074. },
  3075. applyToVector3Array: function () {
  3076. var v1;
  3077. return function ( array, offset, length ) {
  3078. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3079. if ( offset === undefined ) offset = 0;
  3080. if ( length === undefined ) length = array.length;
  3081. for ( var i = 0, j = offset; i < length; i += 3, j += 3 ) {
  3082. v1.fromArray( array, j );
  3083. v1.applyMatrix4( this );
  3084. v1.toArray( array, j );
  3085. }
  3086. return array;
  3087. };
  3088. }(),
  3089. applyToBuffer: function () {
  3090. var v1;
  3091. return function applyToBuffer( buffer, offset, length ) {
  3092. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3093. if ( offset === undefined ) offset = 0;
  3094. if ( length === undefined ) length = buffer.length / buffer.itemSize;
  3095. for ( var i = 0, j = offset; i < length; i ++, j ++ ) {
  3096. v1.x = buffer.getX( j );
  3097. v1.y = buffer.getY( j );
  3098. v1.z = buffer.getZ( j );
  3099. v1.applyMatrix4( this );
  3100. buffer.setXYZ( v1.x, v1.y, v1.z );
  3101. }
  3102. return buffer;
  3103. };
  3104. }(),
  3105. determinant: function () {
  3106. var te = this.elements;
  3107. var n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  3108. var n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  3109. var n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  3110. var n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  3111. //TODO: make this more efficient
  3112. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  3113. return (
  3114. n41 * (
  3115. + n14 * n23 * n32
  3116. - n13 * n24 * n32
  3117. - n14 * n22 * n33
  3118. + n12 * n24 * n33
  3119. + n13 * n22 * n34
  3120. - n12 * n23 * n34
  3121. ) +
  3122. n42 * (
  3123. + n11 * n23 * n34
  3124. - n11 * n24 * n33
  3125. + n14 * n21 * n33
  3126. - n13 * n21 * n34
  3127. + n13 * n24 * n31
  3128. - n14 * n23 * n31
  3129. ) +
  3130. n43 * (
  3131. + n11 * n24 * n32
  3132. - n11 * n22 * n34
  3133. - n14 * n21 * n32
  3134. + n12 * n21 * n34
  3135. + n14 * n22 * n31
  3136. - n12 * n24 * n31
  3137. ) +
  3138. n44 * (
  3139. - n13 * n22 * n31
  3140. - n11 * n23 * n32
  3141. + n11 * n22 * n33
  3142. + n13 * n21 * n32
  3143. - n12 * n21 * n33
  3144. + n12 * n23 * n31
  3145. )
  3146. );
  3147. },
  3148. transpose: function () {
  3149. var te = this.elements;
  3150. var tmp;
  3151. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  3152. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  3153. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  3154. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  3155. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  3156. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  3157. return this;
  3158. },
  3159. flattenToArrayOffset: function ( array, offset ) {
  3160. console.warn( "THREE.Matrix3: .flattenToArrayOffset is deprecated " +
  3161. "- just use .toArray instead." );
  3162. return this.toArray( array, offset );
  3163. },
  3164. getPosition: function () {
  3165. var v1;
  3166. return function () {
  3167. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3168. console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
  3169. return v1.setFromMatrixColumn( this, 3 );
  3170. };
  3171. }(),
  3172. setPosition: function ( v ) {
  3173. var te = this.elements;
  3174. te[ 12 ] = v.x;
  3175. te[ 13 ] = v.y;
  3176. te[ 14 ] = v.z;
  3177. return this;
  3178. },
  3179. getInverse: function ( m, throwOnDegenerate ) {
  3180. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  3181. var te = this.elements,
  3182. me = m.elements,
  3183. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ], n41 = me[ 3 ],
  3184. n12 = me[ 4 ], n22 = me[ 5 ], n32 = me[ 6 ], n42 = me[ 7 ],
  3185. n13 = me[ 8 ], n23 = me[ 9 ], n33 = me[ 10 ], n43 = me[ 11 ],
  3186. n14 = me[ 12 ], n24 = me[ 13 ], n34 = me[ 14 ], n44 = me[ 15 ],
  3187. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  3188. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  3189. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  3190. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  3191. var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  3192. if ( det === 0 ) {
  3193. var msg = "THREE.Matrix4.getInverse(): can't invert matrix, determinant is 0";
  3194. if ( throwOnDegenerate || false ) {
  3195. throw new Error( msg );
  3196. } else {
  3197. console.warn( msg );
  3198. }
  3199. return this.identity();
  3200. }
  3201. te[ 0 ] = t11;
  3202. te[ 1 ] = n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44;
  3203. te[ 2 ] = n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44;
  3204. te[ 3 ] = n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43;
  3205. te[ 4 ] = t12;
  3206. te[ 5 ] = n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44;
  3207. te[ 6 ] = n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44;
  3208. te[ 7 ] = n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43;
  3209. te[ 8 ] = t13;
  3210. te[ 9 ] = n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44;
  3211. te[ 10 ] = n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44;
  3212. te[ 11 ] = n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43;
  3213. te[ 12 ] = t14;
  3214. te[ 13 ] = n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34;
  3215. te[ 14 ] = n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34;
  3216. te[ 15 ] = n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33;
  3217. return this.multiplyScalar( 1 / det );
  3218. },
  3219. scale: function ( v ) {
  3220. var te = this.elements;
  3221. var x = v.x, y = v.y, z = v.z;
  3222. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  3223. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  3224. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  3225. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  3226. return this;
  3227. },
  3228. getMaxScaleOnAxis: function () {
  3229. var te = this.elements;
  3230. var scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  3231. var scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  3232. var scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  3233. return Math.sqrt( Math.max( scaleXSq, scaleYSq, scaleZSq ) );
  3234. },
  3235. makeTranslation: function ( x, y, z ) {
  3236. this.set(
  3237. 1, 0, 0, x,
  3238. 0, 1, 0, y,
  3239. 0, 0, 1, z,
  3240. 0, 0, 0, 1
  3241. );
  3242. return this;
  3243. },
  3244. makeRotationX: function ( theta ) {
  3245. var c = Math.cos( theta ), s = Math.sin( theta );
  3246. this.set(
  3247. 1, 0, 0, 0,
  3248. 0, c, - s, 0,
  3249. 0, s, c, 0,
  3250. 0, 0, 0, 1
  3251. );
  3252. return this;
  3253. },
  3254. makeRotationY: function ( theta ) {
  3255. var c = Math.cos( theta ), s = Math.sin( theta );
  3256. this.set(
  3257. c, 0, s, 0,
  3258. 0, 1, 0, 0,
  3259. - s, 0, c, 0,
  3260. 0, 0, 0, 1
  3261. );
  3262. return this;
  3263. },
  3264. makeRotationZ: function ( theta ) {
  3265. var c = Math.cos( theta ), s = Math.sin( theta );
  3266. this.set(
  3267. c, - s, 0, 0,
  3268. s, c, 0, 0,
  3269. 0, 0, 1, 0,
  3270. 0, 0, 0, 1
  3271. );
  3272. return this;
  3273. },
  3274. makeRotationAxis: function ( axis, angle ) {
  3275. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  3276. var c = Math.cos( angle );
  3277. var s = Math.sin( angle );
  3278. var t = 1 - c;
  3279. var x = axis.x, y = axis.y, z = axis.z;
  3280. var tx = t * x, ty = t * y;
  3281. this.set(
  3282. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  3283. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  3284. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  3285. 0, 0, 0, 1
  3286. );
  3287. return this;
  3288. },
  3289. makeScale: function ( x, y, z ) {
  3290. this.set(
  3291. x, 0, 0, 0,
  3292. 0, y, 0, 0,
  3293. 0, 0, z, 0,
  3294. 0, 0, 0, 1
  3295. );
  3296. return this;
  3297. },
  3298. compose: function ( position, quaternion, scale ) {
  3299. this.makeRotationFromQuaternion( quaternion );
  3300. this.scale( scale );
  3301. this.setPosition( position );
  3302. return this;
  3303. },
  3304. decompose: function () {
  3305. var vector, matrix;
  3306. return function ( position, quaternion, scale ) {
  3307. if ( vector === undefined ) vector = new THREE.Vector3();
  3308. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  3309. var te = this.elements;
  3310. var sx = vector.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  3311. var sy = vector.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  3312. var sz = vector.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  3313. // if determine is negative, we need to invert one scale
  3314. var det = this.determinant();
  3315. if ( det < 0 ) {
  3316. sx = - sx;
  3317. }
  3318. position.x = te[ 12 ];
  3319. position.y = te[ 13 ];
  3320. position.z = te[ 14 ];
  3321. // scale the rotation part
  3322. matrix.elements.set( this.elements ); // at this point matrix is incomplete so we can't use .copy()
  3323. var invSX = 1 / sx;
  3324. var invSY = 1 / sy;
  3325. var invSZ = 1 / sz;
  3326. matrix.elements[ 0 ] *= invSX;
  3327. matrix.elements[ 1 ] *= invSX;
  3328. matrix.elements[ 2 ] *= invSX;
  3329. matrix.elements[ 4 ] *= invSY;
  3330. matrix.elements[ 5 ] *= invSY;
  3331. matrix.elements[ 6 ] *= invSY;
  3332. matrix.elements[ 8 ] *= invSZ;
  3333. matrix.elements[ 9 ] *= invSZ;
  3334. matrix.elements[ 10 ] *= invSZ;
  3335. quaternion.setFromRotationMatrix( matrix );
  3336. scale.x = sx;
  3337. scale.y = sy;
  3338. scale.z = sz;
  3339. return this;
  3340. };
  3341. }(),
  3342. makeFrustum: function ( left, right, bottom, top, near, far ) {
  3343. var te = this.elements;
  3344. var x = 2 * near / ( right - left );
  3345. var y = 2 * near / ( top - bottom );
  3346. var a = ( right + left ) / ( right - left );
  3347. var b = ( top + bottom ) / ( top - bottom );
  3348. var c = - ( far + near ) / ( far - near );
  3349. var d = - 2 * far * near / ( far - near );
  3350. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  3351. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  3352. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  3353. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  3354. return this;
  3355. },
  3356. makePerspective: function ( fov, aspect, near, far ) {
  3357. var ymax = near * Math.tan( THREE.Math.DEG2RAD * fov * 0.5 );
  3358. var ymin = - ymax;
  3359. var xmin = ymin * aspect;
  3360. var xmax = ymax * aspect;
  3361. return this.makeFrustum( xmin, xmax, ymin, ymax, near, far );
  3362. },
  3363. makeOrthographic: function ( left, right, top, bottom, near, far ) {
  3364. var te = this.elements;
  3365. var w = 1.0 / ( right - left );
  3366. var h = 1.0 / ( top - bottom );
  3367. var p = 1.0 / ( far - near );
  3368. var x = ( right + left ) * w;
  3369. var y = ( top + bottom ) * h;
  3370. var z = ( far + near ) * p;
  3371. te[ 0 ] = 2 * w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  3372. te[ 1 ] = 0; te[ 5 ] = 2 * h; te[ 9 ] = 0; te[ 13 ] = - y;
  3373. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 * p; te[ 14 ] = - z;
  3374. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  3375. return this;
  3376. },
  3377. equals: function ( matrix ) {
  3378. var te = this.elements;
  3379. var me = matrix.elements;
  3380. for ( var i = 0; i < 16; i ++ ) {
  3381. if ( te[ i ] !== me[ i ] ) return false;
  3382. }
  3383. return true;
  3384. },
  3385. fromArray: function ( array ) {
  3386. this.elements.set( array );
  3387. return this;
  3388. },
  3389. toArray: function ( array, offset ) {
  3390. if ( array === undefined ) array = [];
  3391. if ( offset === undefined ) offset = 0;
  3392. var te = this.elements;
  3393. array[ offset ] = te[ 0 ];
  3394. array[ offset + 1 ] = te[ 1 ];
  3395. array[ offset + 2 ] = te[ 2 ];
  3396. array[ offset + 3 ] = te[ 3 ];
  3397. array[ offset + 4 ] = te[ 4 ];
  3398. array[ offset + 5 ] = te[ 5 ];
  3399. array[ offset + 6 ] = te[ 6 ];
  3400. array[ offset + 7 ] = te[ 7 ];
  3401. array[ offset + 8 ] = te[ 8 ];
  3402. array[ offset + 9 ] = te[ 9 ];
  3403. array[ offset + 10 ] = te[ 10 ];
  3404. array[ offset + 11 ] = te[ 11 ];
  3405. array[ offset + 12 ] = te[ 12 ];
  3406. array[ offset + 13 ] = te[ 13 ];
  3407. array[ offset + 14 ] = te[ 14 ];
  3408. array[ offset + 15 ] = te[ 15 ];
  3409. return array;
  3410. }
  3411. };
  3412. // File:src/math/Ray.js
  3413. /**
  3414. * @author bhouston / http://clara.io
  3415. */
  3416. THREE.Ray = function ( origin, direction ) {
  3417. this.origin = ( origin !== undefined ) ? origin : new THREE.Vector3();
  3418. this.direction = ( direction !== undefined ) ? direction : new THREE.Vector3();
  3419. };
  3420. THREE.Ray.prototype = {
  3421. constructor: THREE.Ray,
  3422. set: function ( origin, direction ) {
  3423. this.origin.copy( origin );
  3424. this.direction.copy( direction );
  3425. return this;
  3426. },
  3427. clone: function () {
  3428. return new this.constructor().copy( this );
  3429. },
  3430. copy: function ( ray ) {
  3431. this.origin.copy( ray.origin );
  3432. this.direction.copy( ray.direction );
  3433. return this;
  3434. },
  3435. at: function ( t, optionalTarget ) {
  3436. var result = optionalTarget || new THREE.Vector3();
  3437. return result.copy( this.direction ).multiplyScalar( t ).add( this.origin );
  3438. },
  3439. lookAt: function ( v ) {
  3440. this.direction.copy( v ).sub( this.origin ).normalize();
  3441. return this;
  3442. },
  3443. recast: function () {
  3444. var v1 = new THREE.Vector3();
  3445. return function ( t ) {
  3446. this.origin.copy( this.at( t, v1 ) );
  3447. return this;
  3448. };
  3449. }(),
  3450. closestPointToPoint: function ( point, optionalTarget ) {
  3451. var result = optionalTarget || new THREE.Vector3();
  3452. result.subVectors( point, this.origin );
  3453. var directionDistance = result.dot( this.direction );
  3454. if ( directionDistance < 0 ) {
  3455. return result.copy( this.origin );
  3456. }
  3457. return result.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  3458. },
  3459. distanceToPoint: function ( point ) {
  3460. return Math.sqrt( this.distanceSqToPoint( point ) );
  3461. },
  3462. distanceSqToPoint: function () {
  3463. var v1 = new THREE.Vector3();
  3464. return function ( point ) {
  3465. var directionDistance = v1.subVectors( point, this.origin ).dot( this.direction );
  3466. // point behind the ray
  3467. if ( directionDistance < 0 ) {
  3468. return this.origin.distanceToSquared( point );
  3469. }
  3470. v1.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  3471. return v1.distanceToSquared( point );
  3472. };
  3473. }(),
  3474. distanceSqToSegment: function () {
  3475. var segCenter = new THREE.Vector3();
  3476. var segDir = new THREE.Vector3();
  3477. var diff = new THREE.Vector3();
  3478. return function ( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  3479. // from http://www.geometrictools.com/LibMathematics/Distance/Wm5DistRay3Segment3.cpp
  3480. // It returns the min distance between the ray and the segment
  3481. // defined by v0 and v1
  3482. // It can also set two optional targets :
  3483. // - The closest point on the ray
  3484. // - The closest point on the segment
  3485. segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  3486. segDir.copy( v1 ).sub( v0 ).normalize();
  3487. diff.copy( this.origin ).sub( segCenter );
  3488. var segExtent = v0.distanceTo( v1 ) * 0.5;
  3489. var a01 = - this.direction.dot( segDir );
  3490. var b0 = diff.dot( this.direction );
  3491. var b1 = - diff.dot( segDir );
  3492. var c = diff.lengthSq();
  3493. var det = Math.abs( 1 - a01 * a01 );
  3494. var s0, s1, sqrDist, extDet;
  3495. if ( det > 0 ) {
  3496. // The ray and segment are not parallel.
  3497. s0 = a01 * b1 - b0;
  3498. s1 = a01 * b0 - b1;
  3499. extDet = segExtent * det;
  3500. if ( s0 >= 0 ) {
  3501. if ( s1 >= - extDet ) {
  3502. if ( s1 <= extDet ) {
  3503. // region 0
  3504. // Minimum at interior points of ray and segment.
  3505. var invDet = 1 / det;
  3506. s0 *= invDet;
  3507. s1 *= invDet;
  3508. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  3509. } else {
  3510. // region 1
  3511. s1 = segExtent;
  3512. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3513. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3514. }
  3515. } else {
  3516. // region 5
  3517. s1 = - segExtent;
  3518. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3519. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3520. }
  3521. } else {
  3522. if ( s1 <= - extDet ) {
  3523. // region 4
  3524. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  3525. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3526. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3527. } else if ( s1 <= extDet ) {
  3528. // region 3
  3529. s0 = 0;
  3530. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3531. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  3532. } else {
  3533. // region 2
  3534. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  3535. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3536. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3537. }
  3538. }
  3539. } else {
  3540. // Ray and segment are parallel.
  3541. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  3542. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3543. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3544. }
  3545. if ( optionalPointOnRay ) {
  3546. optionalPointOnRay.copy( this.direction ).multiplyScalar( s0 ).add( this.origin );
  3547. }
  3548. if ( optionalPointOnSegment ) {
  3549. optionalPointOnSegment.copy( segDir ).multiplyScalar( s1 ).add( segCenter );
  3550. }
  3551. return sqrDist;
  3552. };
  3553. }(),
  3554. intersectSphere: function () {
  3555. var v1 = new THREE.Vector3();
  3556. return function ( sphere, optionalTarget ) {
  3557. v1.subVectors( sphere.center, this.origin );
  3558. var tca = v1.dot( this.direction );
  3559. var d2 = v1.dot( v1 ) - tca * tca;
  3560. var radius2 = sphere.radius * sphere.radius;
  3561. if ( d2 > radius2 ) return null;
  3562. var thc = Math.sqrt( radius2 - d2 );
  3563. // t0 = first intersect point - entrance on front of sphere
  3564. var t0 = tca - thc;
  3565. // t1 = second intersect point - exit point on back of sphere
  3566. var t1 = tca + thc;
  3567. // test to see if both t0 and t1 are behind the ray - if so, return null
  3568. if ( t0 < 0 && t1 < 0 ) return null;
  3569. // test to see if t0 is behind the ray:
  3570. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  3571. // in order to always return an intersect point that is in front of the ray.
  3572. if ( t0 < 0 ) return this.at( t1, optionalTarget );
  3573. // else t0 is in front of the ray, so return the first collision point scaled by t0
  3574. return this.at( t0, optionalTarget );
  3575. };
  3576. }(),
  3577. intersectsSphere: function ( sphere ) {
  3578. return this.distanceToPoint( sphere.center ) <= sphere.radius;
  3579. },
  3580. distanceToPlane: function ( plane ) {
  3581. var denominator = plane.normal.dot( this.direction );
  3582. if ( denominator === 0 ) {
  3583. // line is coplanar, return origin
  3584. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  3585. return 0;
  3586. }
  3587. // Null is preferable to undefined since undefined means.... it is undefined
  3588. return null;
  3589. }
  3590. var t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  3591. // Return if the ray never intersects the plane
  3592. return t >= 0 ? t : null;
  3593. },
  3594. intersectPlane: function ( plane, optionalTarget ) {
  3595. var t = this.distanceToPlane( plane );
  3596. if ( t === null ) {
  3597. return null;
  3598. }
  3599. return this.at( t, optionalTarget );
  3600. },
  3601. intersectsPlane: function ( plane ) {
  3602. // check if the ray lies on the plane first
  3603. var distToPoint = plane.distanceToPoint( this.origin );
  3604. if ( distToPoint === 0 ) {
  3605. return true;
  3606. }
  3607. var denominator = plane.normal.dot( this.direction );
  3608. if ( denominator * distToPoint < 0 ) {
  3609. return true;
  3610. }
  3611. // ray origin is behind the plane (and is pointing behind it)
  3612. return false;
  3613. },
  3614. intersectBox: function ( box, optionalTarget ) {
  3615. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  3616. var invdirx = 1 / this.direction.x,
  3617. invdiry = 1 / this.direction.y,
  3618. invdirz = 1 / this.direction.z;
  3619. var origin = this.origin;
  3620. if ( invdirx >= 0 ) {
  3621. tmin = ( box.min.x - origin.x ) * invdirx;
  3622. tmax = ( box.max.x - origin.x ) * invdirx;
  3623. } else {
  3624. tmin = ( box.max.x - origin.x ) * invdirx;
  3625. tmax = ( box.min.x - origin.x ) * invdirx;
  3626. }
  3627. if ( invdiry >= 0 ) {
  3628. tymin = ( box.min.y - origin.y ) * invdiry;
  3629. tymax = ( box.max.y - origin.y ) * invdiry;
  3630. } else {
  3631. tymin = ( box.max.y - origin.y ) * invdiry;
  3632. tymax = ( box.min.y - origin.y ) * invdiry;
  3633. }
  3634. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  3635. // These lines also handle the case where tmin or tmax is NaN
  3636. // (result of 0 * Infinity). x !== x returns true if x is NaN
  3637. if ( tymin > tmin || tmin !== tmin ) tmin = tymin;
  3638. if ( tymax < tmax || tmax !== tmax ) tmax = tymax;
  3639. if ( invdirz >= 0 ) {
  3640. tzmin = ( box.min.z - origin.z ) * invdirz;
  3641. tzmax = ( box.max.z - origin.z ) * invdirz;
  3642. } else {
  3643. tzmin = ( box.max.z - origin.z ) * invdirz;
  3644. tzmax = ( box.min.z - origin.z ) * invdirz;
  3645. }
  3646. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  3647. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  3648. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  3649. //return point closest to the ray (positive side)
  3650. if ( tmax < 0 ) return null;
  3651. return this.at( tmin >= 0 ? tmin : tmax, optionalTarget );
  3652. },
  3653. intersectsBox: ( function () {
  3654. var v = new THREE.Vector3();
  3655. return function ( box ) {
  3656. return this.intersectBox( box, v ) !== null;
  3657. };
  3658. } )(),
  3659. intersectTriangle: function () {
  3660. // Compute the offset origin, edges, and normal.
  3661. var diff = new THREE.Vector3();
  3662. var edge1 = new THREE.Vector3();
  3663. var edge2 = new THREE.Vector3();
  3664. var normal = new THREE.Vector3();
  3665. return function ( a, b, c, backfaceCulling, optionalTarget ) {
  3666. // from http://www.geometrictools.com/LibMathematics/Intersection/Wm5IntrRay3Triangle3.cpp
  3667. edge1.subVectors( b, a );
  3668. edge2.subVectors( c, a );
  3669. normal.crossVectors( edge1, edge2 );
  3670. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  3671. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  3672. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  3673. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  3674. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  3675. var DdN = this.direction.dot( normal );
  3676. var sign;
  3677. if ( DdN > 0 ) {
  3678. if ( backfaceCulling ) return null;
  3679. sign = 1;
  3680. } else if ( DdN < 0 ) {
  3681. sign = - 1;
  3682. DdN = - DdN;
  3683. } else {
  3684. return null;
  3685. }
  3686. diff.subVectors( this.origin, a );
  3687. var DdQxE2 = sign * this.direction.dot( edge2.crossVectors( diff, edge2 ) );
  3688. // b1 < 0, no intersection
  3689. if ( DdQxE2 < 0 ) {
  3690. return null;
  3691. }
  3692. var DdE1xQ = sign * this.direction.dot( edge1.cross( diff ) );
  3693. // b2 < 0, no intersection
  3694. if ( DdE1xQ < 0 ) {
  3695. return null;
  3696. }
  3697. // b1+b2 > 1, no intersection
  3698. if ( DdQxE2 + DdE1xQ > DdN ) {
  3699. return null;
  3700. }
  3701. // Line intersects triangle, check if ray does.
  3702. var QdN = - sign * diff.dot( normal );
  3703. // t < 0, no intersection
  3704. if ( QdN < 0 ) {
  3705. return null;
  3706. }
  3707. // Ray intersects triangle.
  3708. return this.at( QdN / DdN, optionalTarget );
  3709. };
  3710. }(),
  3711. applyMatrix4: function ( matrix4 ) {
  3712. this.direction.add( this.origin ).applyMatrix4( matrix4 );
  3713. this.origin.applyMatrix4( matrix4 );
  3714. this.direction.sub( this.origin );
  3715. this.direction.normalize();
  3716. return this;
  3717. },
  3718. equals: function ( ray ) {
  3719. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  3720. }
  3721. };
  3722. // File:src/math/Sphere.js
  3723. /**
  3724. * @author bhouston / http://clara.io
  3725. * @author mrdoob / http://mrdoob.com/
  3726. */
  3727. THREE.Sphere = function ( center, radius ) {
  3728. this.center = ( center !== undefined ) ? center : new THREE.Vector3();
  3729. this.radius = ( radius !== undefined ) ? radius : 0;
  3730. };
  3731. THREE.Sphere.prototype = {
  3732. constructor: THREE.Sphere,
  3733. set: function ( center, radius ) {
  3734. this.center.copy( center );
  3735. this.radius = radius;
  3736. return this;
  3737. },
  3738. setFromPoints: function () {
  3739. var box = new THREE.Box3();
  3740. return function ( points, optionalCenter ) {
  3741. var center = this.center;
  3742. if ( optionalCenter !== undefined ) {
  3743. center.copy( optionalCenter );
  3744. } else {
  3745. box.setFromPoints( points ).center( center );
  3746. }
  3747. var maxRadiusSq = 0;
  3748. for ( var i = 0, il = points.length; i < il; i ++ ) {
  3749. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  3750. }
  3751. this.radius = Math.sqrt( maxRadiusSq );
  3752. return this;
  3753. };
  3754. }(),
  3755. clone: function () {
  3756. return new this.constructor().copy( this );
  3757. },
  3758. copy: function ( sphere ) {
  3759. this.center.copy( sphere.center );
  3760. this.radius = sphere.radius;
  3761. return this;
  3762. },
  3763. empty: function () {
  3764. return ( this.radius <= 0 );
  3765. },
  3766. containsPoint: function ( point ) {
  3767. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  3768. },
  3769. distanceToPoint: function ( point ) {
  3770. return ( point.distanceTo( this.center ) - this.radius );
  3771. },
  3772. intersectsSphere: function ( sphere ) {
  3773. var radiusSum = this.radius + sphere.radius;
  3774. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  3775. },
  3776. intersectsBox: function ( box ) {
  3777. return box.intersectsSphere( this );
  3778. },
  3779. intersectsPlane: function ( plane ) {
  3780. // We use the following equation to compute the signed distance from
  3781. // the center of the sphere to the plane.
  3782. //
  3783. // distance = q * n - d
  3784. //
  3785. // If this distance is greater than the radius of the sphere,
  3786. // then there is no intersection.
  3787. return Math.abs( this.center.dot( plane.normal ) - plane.constant ) <= this.radius;
  3788. },
  3789. clampPoint: function ( point, optionalTarget ) {
  3790. var deltaLengthSq = this.center.distanceToSquared( point );
  3791. var result = optionalTarget || new THREE.Vector3();
  3792. result.copy( point );
  3793. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  3794. result.sub( this.center ).normalize();
  3795. result.multiplyScalar( this.radius ).add( this.center );
  3796. }
  3797. return result;
  3798. },
  3799. getBoundingBox: function ( optionalTarget ) {
  3800. var box = optionalTarget || new THREE.Box3();
  3801. box.set( this.center, this.center );
  3802. box.expandByScalar( this.radius );
  3803. return box;
  3804. },
  3805. applyMatrix4: function ( matrix ) {
  3806. this.center.applyMatrix4( matrix );
  3807. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  3808. return this;
  3809. },
  3810. translate: function ( offset ) {
  3811. this.center.add( offset );
  3812. return this;
  3813. },
  3814. equals: function ( sphere ) {
  3815. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  3816. }
  3817. };
  3818. // File:src/math/Frustum.js
  3819. /**
  3820. * @author mrdoob / http://mrdoob.com/
  3821. * @author alteredq / http://alteredqualia.com/
  3822. * @author bhouston / http://clara.io
  3823. */
  3824. THREE.Frustum = function ( p0, p1, p2, p3, p4, p5 ) {
  3825. this.planes = [
  3826. ( p0 !== undefined ) ? p0 : new THREE.Plane(),
  3827. ( p1 !== undefined ) ? p1 : new THREE.Plane(),
  3828. ( p2 !== undefined ) ? p2 : new THREE.Plane(),
  3829. ( p3 !== undefined ) ? p3 : new THREE.Plane(),
  3830. ( p4 !== undefined ) ? p4 : new THREE.Plane(),
  3831. ( p5 !== undefined ) ? p5 : new THREE.Plane()
  3832. ];
  3833. };
  3834. THREE.Frustum.prototype = {
  3835. constructor: THREE.Frustum,
  3836. set: function ( p0, p1, p2, p3, p4, p5 ) {
  3837. var planes = this.planes;
  3838. planes[ 0 ].copy( p0 );
  3839. planes[ 1 ].copy( p1 );
  3840. planes[ 2 ].copy( p2 );
  3841. planes[ 3 ].copy( p3 );
  3842. planes[ 4 ].copy( p4 );
  3843. planes[ 5 ].copy( p5 );
  3844. return this;
  3845. },
  3846. clone: function () {
  3847. return new this.constructor().copy( this );
  3848. },
  3849. copy: function ( frustum ) {
  3850. var planes = this.planes;
  3851. for ( var i = 0; i < 6; i ++ ) {
  3852. planes[ i ].copy( frustum.planes[ i ] );
  3853. }
  3854. return this;
  3855. },
  3856. setFromMatrix: function ( m ) {
  3857. var planes = this.planes;
  3858. var me = m.elements;
  3859. var me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  3860. var me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  3861. var me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  3862. var me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  3863. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  3864. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  3865. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  3866. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  3867. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  3868. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  3869. return this;
  3870. },
  3871. intersectsObject: function () {
  3872. var sphere = new THREE.Sphere();
  3873. return function ( object ) {
  3874. var geometry = object.geometry;
  3875. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  3876. sphere.copy( geometry.boundingSphere );
  3877. sphere.applyMatrix4( object.matrixWorld );
  3878. return this.intersectsSphere( sphere );
  3879. };
  3880. }(),
  3881. intersectsSphere: function ( sphere ) {
  3882. var planes = this.planes;
  3883. var center = sphere.center;
  3884. var negRadius = - sphere.radius;
  3885. for ( var i = 0; i < 6; i ++ ) {
  3886. var distance = planes[ i ].distanceToPoint( center );
  3887. if ( distance < negRadius ) {
  3888. return false;
  3889. }
  3890. }
  3891. return true;
  3892. },
  3893. intersectsBox: function () {
  3894. var p1 = new THREE.Vector3(),
  3895. p2 = new THREE.Vector3();
  3896. return function ( box ) {
  3897. var planes = this.planes;
  3898. for ( var i = 0; i < 6 ; i ++ ) {
  3899. var plane = planes[ i ];
  3900. p1.x = plane.normal.x > 0 ? box.min.x : box.max.x;
  3901. p2.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  3902. p1.y = plane.normal.y > 0 ? box.min.y : box.max.y;
  3903. p2.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  3904. p1.z = plane.normal.z > 0 ? box.min.z : box.max.z;
  3905. p2.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  3906. var d1 = plane.distanceToPoint( p1 );
  3907. var d2 = plane.distanceToPoint( p2 );
  3908. // if both outside plane, no intersection
  3909. if ( d1 < 0 && d2 < 0 ) {
  3910. return false;
  3911. }
  3912. }
  3913. return true;
  3914. };
  3915. }(),
  3916. containsPoint: function ( point ) {
  3917. var planes = this.planes;
  3918. for ( var i = 0; i < 6; i ++ ) {
  3919. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  3920. return false;
  3921. }
  3922. }
  3923. return true;
  3924. }
  3925. };
  3926. // File:src/math/Plane.js
  3927. /**
  3928. * @author bhouston / http://clara.io
  3929. */
  3930. THREE.Plane = function ( normal, constant ) {
  3931. this.normal = ( normal !== undefined ) ? normal : new THREE.Vector3( 1, 0, 0 );
  3932. this.constant = ( constant !== undefined ) ? constant : 0;
  3933. };
  3934. THREE.Plane.prototype = {
  3935. constructor: THREE.Plane,
  3936. set: function ( normal, constant ) {
  3937. this.normal.copy( normal );
  3938. this.constant = constant;
  3939. return this;
  3940. },
  3941. setComponents: function ( x, y, z, w ) {
  3942. this.normal.set( x, y, z );
  3943. this.constant = w;
  3944. return this;
  3945. },
  3946. setFromNormalAndCoplanarPoint: function ( normal, point ) {
  3947. this.normal.copy( normal );
  3948. this.constant = - point.dot( this.normal ); // must be this.normal, not normal, as this.normal is normalized
  3949. return this;
  3950. },
  3951. setFromCoplanarPoints: function () {
  3952. var v1 = new THREE.Vector3();
  3953. var v2 = new THREE.Vector3();
  3954. return function ( a, b, c ) {
  3955. var normal = v1.subVectors( c, b ).cross( v2.subVectors( a, b ) ).normalize();
  3956. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  3957. this.setFromNormalAndCoplanarPoint( normal, a );
  3958. return this;
  3959. };
  3960. }(),
  3961. clone: function () {
  3962. return new this.constructor().copy( this );
  3963. },
  3964. copy: function ( plane ) {
  3965. this.normal.copy( plane.normal );
  3966. this.constant = plane.constant;
  3967. return this;
  3968. },
  3969. normalize: function () {
  3970. // Note: will lead to a divide by zero if the plane is invalid.
  3971. var inverseNormalLength = 1.0 / this.normal.length();
  3972. this.normal.multiplyScalar( inverseNormalLength );
  3973. this.constant *= inverseNormalLength;
  3974. return this;
  3975. },
  3976. negate: function () {
  3977. this.constant *= - 1;
  3978. this.normal.negate();
  3979. return this;
  3980. },
  3981. distanceToPoint: function ( point ) {
  3982. return this.normal.dot( point ) + this.constant;
  3983. },
  3984. distanceToSphere: function ( sphere ) {
  3985. return this.distanceToPoint( sphere.center ) - sphere.radius;
  3986. },
  3987. projectPoint: function ( point, optionalTarget ) {
  3988. return this.orthoPoint( point, optionalTarget ).sub( point ).negate();
  3989. },
  3990. orthoPoint: function ( point, optionalTarget ) {
  3991. var perpendicularMagnitude = this.distanceToPoint( point );
  3992. var result = optionalTarget || new THREE.Vector3();
  3993. return result.copy( this.normal ).multiplyScalar( perpendicularMagnitude );
  3994. },
  3995. intersectLine: function () {
  3996. var v1 = new THREE.Vector3();
  3997. return function ( line, optionalTarget ) {
  3998. var result = optionalTarget || new THREE.Vector3();
  3999. var direction = line.delta( v1 );
  4000. var denominator = this.normal.dot( direction );
  4001. if ( denominator === 0 ) {
  4002. // line is coplanar, return origin
  4003. if ( this.distanceToPoint( line.start ) === 0 ) {
  4004. return result.copy( line.start );
  4005. }
  4006. // Unsure if this is the correct method to handle this case.
  4007. return undefined;
  4008. }
  4009. var t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  4010. if ( t < 0 || t > 1 ) {
  4011. return undefined;
  4012. }
  4013. return result.copy( direction ).multiplyScalar( t ).add( line.start );
  4014. };
  4015. }(),
  4016. intersectsLine: function ( line ) {
  4017. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  4018. var startSign = this.distanceToPoint( line.start );
  4019. var endSign = this.distanceToPoint( line.end );
  4020. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  4021. },
  4022. intersectsBox: function ( box ) {
  4023. return box.intersectsPlane( this );
  4024. },
  4025. intersectsSphere: function ( sphere ) {
  4026. return sphere.intersectsPlane( this );
  4027. },
  4028. coplanarPoint: function ( optionalTarget ) {
  4029. var result = optionalTarget || new THREE.Vector3();
  4030. return result.copy( this.normal ).multiplyScalar( - this.constant );
  4031. },
  4032. applyMatrix4: function () {
  4033. var v1 = new THREE.Vector3();
  4034. var m1 = new THREE.Matrix3();
  4035. return function ( matrix, optionalNormalMatrix ) {
  4036. var referencePoint = this.coplanarPoint( v1 ).applyMatrix4( matrix );
  4037. // transform normal based on theory here:
  4038. // http://www.songho.ca/opengl/gl_normaltransform.html
  4039. var normalMatrix = optionalNormalMatrix || m1.getNormalMatrix( matrix );
  4040. var normal = this.normal.applyMatrix3( normalMatrix ).normalize();
  4041. // recalculate constant (like in setFromNormalAndCoplanarPoint)
  4042. this.constant = - referencePoint.dot( normal );
  4043. return this;
  4044. };
  4045. }(),
  4046. translate: function ( offset ) {
  4047. this.constant = this.constant - offset.dot( this.normal );
  4048. return this;
  4049. },
  4050. equals: function ( plane ) {
  4051. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  4052. }
  4053. };
  4054. // File:src/math/Spherical.js
  4055. /**
  4056. * @author bhouston / http://clara.io
  4057. * @author WestLangley / http://github.com/WestLangley
  4058. *
  4059. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  4060. *
  4061. * The poles (phi) are at the positive and negative y axis.
  4062. * The equator starts at positive z.
  4063. */
  4064. THREE.Spherical = function ( radius, phi, theta ) {
  4065. this.radius = ( radius !== undefined ) ? radius : 1.0;
  4066. this.phi = ( phi !== undefined ) ? phi : 0; // up / down towards top and bottom pole
  4067. this.theta = ( theta !== undefined ) ? theta : 0; // around the equator of the sphere
  4068. return this;
  4069. };
  4070. THREE.Spherical.prototype = {
  4071. constructor: THREE.Spherical,
  4072. set: function ( radius, phi, theta ) {
  4073. this.radius = radius;
  4074. this.phi = phi;
  4075. this.theta = theta;
  4076. return this;
  4077. },
  4078. clone: function () {
  4079. return new this.constructor().copy( this );
  4080. },
  4081. copy: function ( other ) {
  4082. this.radius.copy( other.radius );
  4083. this.phi.copy( other.phi );
  4084. this.theta.copy( other.theta );
  4085. return this;
  4086. },
  4087. // restrict phi to be betwee EPS and PI-EPS
  4088. makeSafe: function() {
  4089. var EPS = 0.000001;
  4090. this.phi = Math.max( EPS, Math.min( Math.PI - EPS, this.phi ) );
  4091. return this;
  4092. },
  4093. setFromVector3: function( vec3 ) {
  4094. this.radius = vec3.length();
  4095. if ( this.radius === 0 ) {
  4096. this.theta = 0;
  4097. this.phi = 0;
  4098. } else {
  4099. this.theta = Math.atan2( vec3.x, vec3.z ); // equator angle around y-up axis
  4100. this.phi = Math.acos( THREE.Math.clamp( vec3.y / this.radius, - 1, 1 ) ); // polar angle
  4101. }
  4102. return this;
  4103. },
  4104. };
  4105. // File:src/math/Math.js
  4106. /**
  4107. * @author alteredq / http://alteredqualia.com/
  4108. * @author mrdoob / http://mrdoob.com/
  4109. */
  4110. THREE.Math = {
  4111. DEG2RAD: Math.PI / 180,
  4112. RAD2DEG: 180 / Math.PI,
  4113. generateUUID: function () {
  4114. // http://www.broofa.com/Tools/Math.uuid.htm
  4115. var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split( '' );
  4116. var uuid = new Array( 36 );
  4117. var rnd = 0, r;
  4118. return function () {
  4119. for ( var i = 0; i < 36; i ++ ) {
  4120. if ( i === 8 || i === 13 || i === 18 || i === 23 ) {
  4121. uuid[ i ] = '-';
  4122. } else if ( i === 14 ) {
  4123. uuid[ i ] = '4';
  4124. } else {
  4125. if ( rnd <= 0x02 ) rnd = 0x2000000 + ( Math.random() * 0x1000000 ) | 0;
  4126. r = rnd & 0xf;
  4127. rnd = rnd >> 4;
  4128. uuid[ i ] = chars[ ( i === 19 ) ? ( r & 0x3 ) | 0x8 : r ];
  4129. }
  4130. }
  4131. return uuid.join( '' );
  4132. };
  4133. }(),
  4134. clamp: function ( value, min, max ) {
  4135. return Math.max( min, Math.min( max, value ) );
  4136. },
  4137. // compute euclidian modulo of m % n
  4138. // https://en.wikipedia.org/wiki/Modulo_operation
  4139. euclideanModulo: function ( n, m ) {
  4140. return ( ( n % m ) + m ) % m;
  4141. },
  4142. // Linear mapping from range <a1, a2> to range <b1, b2>
  4143. mapLinear: function ( x, a1, a2, b1, b2 ) {
  4144. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  4145. },
  4146. // http://en.wikipedia.org/wiki/Smoothstep
  4147. smoothstep: function ( x, min, max ) {
  4148. if ( x <= min ) return 0;
  4149. if ( x >= max ) return 1;
  4150. x = ( x - min ) / ( max - min );
  4151. return x * x * ( 3 - 2 * x );
  4152. },
  4153. smootherstep: function ( x, min, max ) {
  4154. if ( x <= min ) return 0;
  4155. if ( x >= max ) return 1;
  4156. x = ( x - min ) / ( max - min );
  4157. return x * x * x * ( x * ( x * 6 - 15 ) + 10 );
  4158. },
  4159. random16: function () {
  4160. console.warn( 'THREE.Math.random16() has been deprecated. Use Math.random() instead.' );
  4161. return Math.random();
  4162. },
  4163. // Random integer from <low, high> interval
  4164. randInt: function ( low, high ) {
  4165. return low + Math.floor( Math.random() * ( high - low + 1 ) );
  4166. },
  4167. // Random float from <low, high> interval
  4168. randFloat: function ( low, high ) {
  4169. return low + Math.random() * ( high - low );
  4170. },
  4171. // Random float from <-range/2, range/2> interval
  4172. randFloatSpread: function ( range ) {
  4173. return range * ( 0.5 - Math.random() );
  4174. },
  4175. degToRad: function ( degrees ) {
  4176. return degrees * THREE.Math.DEG2RAD;
  4177. },
  4178. radToDeg: function ( radians ) {
  4179. return radians * THREE.Math.RAD2DEG;
  4180. },
  4181. isPowerOfTwo: function ( value ) {
  4182. return ( value & ( value - 1 ) ) === 0 && value !== 0;
  4183. },
  4184. nearestPowerOfTwo: function ( value ) {
  4185. return Math.pow( 2, Math.round( Math.log( value ) / Math.LN2 ) );
  4186. },
  4187. nextPowerOfTwo: function ( value ) {
  4188. value --;
  4189. value |= value >> 1;
  4190. value |= value >> 2;
  4191. value |= value >> 4;
  4192. value |= value >> 8;
  4193. value |= value >> 16;
  4194. value ++;
  4195. return value;
  4196. }
  4197. };
  4198. // File:src/math/Spline.js
  4199. /**
  4200. * Spline from Tween.js, slightly optimized (and trashed)
  4201. * http://sole.github.com/tween.js/examples/05_spline.html
  4202. *
  4203. * @author mrdoob / http://mrdoob.com/
  4204. * @author alteredq / http://alteredqualia.com/
  4205. */
  4206. THREE.Spline = function ( points ) {
  4207. this.points = points;
  4208. var c = [], v3 = { x: 0, y: 0, z: 0 },
  4209. point, intPoint, weight, w2, w3,
  4210. pa, pb, pc, pd;
  4211. this.initFromArray = function ( a ) {
  4212. this.points = [];
  4213. for ( var i = 0; i < a.length; i ++ ) {
  4214. this.points[ i ] = { x: a[ i ][ 0 ], y: a[ i ][ 1 ], z: a[ i ][ 2 ] };
  4215. }
  4216. };
  4217. this.getPoint = function ( k ) {
  4218. point = ( this.points.length - 1 ) * k;
  4219. intPoint = Math.floor( point );
  4220. weight = point - intPoint;
  4221. c[ 0 ] = intPoint === 0 ? intPoint : intPoint - 1;
  4222. c[ 1 ] = intPoint;
  4223. c[ 2 ] = intPoint > this.points.length - 2 ? this.points.length - 1 : intPoint + 1;
  4224. c[ 3 ] = intPoint > this.points.length - 3 ? this.points.length - 1 : intPoint + 2;
  4225. pa = this.points[ c[ 0 ] ];
  4226. pb = this.points[ c[ 1 ] ];
  4227. pc = this.points[ c[ 2 ] ];
  4228. pd = this.points[ c[ 3 ] ];
  4229. w2 = weight * weight;
  4230. w3 = weight * w2;
  4231. v3.x = interpolate( pa.x, pb.x, pc.x, pd.x, weight, w2, w3 );
  4232. v3.y = interpolate( pa.y, pb.y, pc.y, pd.y, weight, w2, w3 );
  4233. v3.z = interpolate( pa.z, pb.z, pc.z, pd.z, weight, w2, w3 );
  4234. return v3;
  4235. };
  4236. this.getControlPointsArray = function () {
  4237. var i, p, l = this.points.length,
  4238. coords = [];
  4239. for ( i = 0; i < l; i ++ ) {
  4240. p = this.points[ i ];
  4241. coords[ i ] = [ p.x, p.y, p.z ];
  4242. }
  4243. return coords;
  4244. };
  4245. // approximate length by summing linear segments
  4246. this.getLength = function ( nSubDivisions ) {
  4247. var i, index, nSamples, position,
  4248. point = 0, intPoint = 0, oldIntPoint = 0,
  4249. oldPosition = new THREE.Vector3(),
  4250. tmpVec = new THREE.Vector3(),
  4251. chunkLengths = [],
  4252. totalLength = 0;
  4253. // first point has 0 length
  4254. chunkLengths[ 0 ] = 0;
  4255. if ( ! nSubDivisions ) nSubDivisions = 100;
  4256. nSamples = this.points.length * nSubDivisions;
  4257. oldPosition.copy( this.points[ 0 ] );
  4258. for ( i = 1; i < nSamples; i ++ ) {
  4259. index = i / nSamples;
  4260. position = this.getPoint( index );
  4261. tmpVec.copy( position );
  4262. totalLength += tmpVec.distanceTo( oldPosition );
  4263. oldPosition.copy( position );
  4264. point = ( this.points.length - 1 ) * index;
  4265. intPoint = Math.floor( point );
  4266. if ( intPoint !== oldIntPoint ) {
  4267. chunkLengths[ intPoint ] = totalLength;
  4268. oldIntPoint = intPoint;
  4269. }
  4270. }
  4271. // last point ends with total length
  4272. chunkLengths[ chunkLengths.length ] = totalLength;
  4273. return { chunks: chunkLengths, total: totalLength };
  4274. };
  4275. this.reparametrizeByArcLength = function ( samplingCoef ) {
  4276. var i, j,
  4277. index, indexCurrent, indexNext,
  4278. realDistance,
  4279. sampling, position,
  4280. newpoints = [],
  4281. tmpVec = new THREE.Vector3(),
  4282. sl = this.getLength();
  4283. newpoints.push( tmpVec.copy( this.points[ 0 ] ).clone() );
  4284. for ( i = 1; i < this.points.length; i ++ ) {
  4285. //tmpVec.copy( this.points[ i - 1 ] );
  4286. //linearDistance = tmpVec.distanceTo( this.points[ i ] );
  4287. realDistance = sl.chunks[ i ] - sl.chunks[ i - 1 ];
  4288. sampling = Math.ceil( samplingCoef * realDistance / sl.total );
  4289. indexCurrent = ( i - 1 ) / ( this.points.length - 1 );
  4290. indexNext = i / ( this.points.length - 1 );
  4291. for ( j = 1; j < sampling - 1; j ++ ) {
  4292. index = indexCurrent + j * ( 1 / sampling ) * ( indexNext - indexCurrent );
  4293. position = this.getPoint( index );
  4294. newpoints.push( tmpVec.copy( position ).clone() );
  4295. }
  4296. newpoints.push( tmpVec.copy( this.points[ i ] ).clone() );
  4297. }
  4298. this.points = newpoints;
  4299. };
  4300. // Catmull-Rom
  4301. function interpolate( p0, p1, p2, p3, t, t2, t3 ) {
  4302. var v0 = ( p2 - p0 ) * 0.5,
  4303. v1 = ( p3 - p1 ) * 0.5;
  4304. return ( 2 * ( p1 - p2 ) + v0 + v1 ) * t3 + ( - 3 * ( p1 - p2 ) - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  4305. }
  4306. };
  4307. // File:src/math/Triangle.js
  4308. /**
  4309. * @author bhouston / http://clara.io
  4310. * @author mrdoob / http://mrdoob.com/
  4311. */
  4312. THREE.Triangle = function ( a, b, c ) {
  4313. this.a = ( a !== undefined ) ? a : new THREE.Vector3();
  4314. this.b = ( b !== undefined ) ? b : new THREE.Vector3();
  4315. this.c = ( c !== undefined ) ? c : new THREE.Vector3();
  4316. };
  4317. THREE.Triangle.normal = function () {
  4318. var v0 = new THREE.Vector3();
  4319. return function ( a, b, c, optionalTarget ) {
  4320. var result = optionalTarget || new THREE.Vector3();
  4321. result.subVectors( c, b );
  4322. v0.subVectors( a, b );
  4323. result.cross( v0 );
  4324. var resultLengthSq = result.lengthSq();
  4325. if ( resultLengthSq > 0 ) {
  4326. return result.multiplyScalar( 1 / Math.sqrt( resultLengthSq ) );
  4327. }
  4328. return result.set( 0, 0, 0 );
  4329. };
  4330. }();
  4331. // static/instance method to calculate barycentric coordinates
  4332. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  4333. THREE.Triangle.barycoordFromPoint = function () {
  4334. var v0 = new THREE.Vector3();
  4335. var v1 = new THREE.Vector3();
  4336. var v2 = new THREE.Vector3();
  4337. return function ( point, a, b, c, optionalTarget ) {
  4338. v0.subVectors( c, a );
  4339. v1.subVectors( b, a );
  4340. v2.subVectors( point, a );
  4341. var dot00 = v0.dot( v0 );
  4342. var dot01 = v0.dot( v1 );
  4343. var dot02 = v0.dot( v2 );
  4344. var dot11 = v1.dot( v1 );
  4345. var dot12 = v1.dot( v2 );
  4346. var denom = ( dot00 * dot11 - dot01 * dot01 );
  4347. var result = optionalTarget || new THREE.Vector3();
  4348. // collinear or singular triangle
  4349. if ( denom === 0 ) {
  4350. // arbitrary location outside of triangle?
  4351. // not sure if this is the best idea, maybe should be returning undefined
  4352. return result.set( - 2, - 1, - 1 );
  4353. }
  4354. var invDenom = 1 / denom;
  4355. var u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  4356. var v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  4357. // barycentric coordinates must always sum to 1
  4358. return result.set( 1 - u - v, v, u );
  4359. };
  4360. }();
  4361. THREE.Triangle.containsPoint = function () {
  4362. var v1 = new THREE.Vector3();
  4363. return function ( point, a, b, c ) {
  4364. var result = THREE.Triangle.barycoordFromPoint( point, a, b, c, v1 );
  4365. return ( result.x >= 0 ) && ( result.y >= 0 ) && ( ( result.x + result.y ) <= 1 );
  4366. };
  4367. }();
  4368. THREE.Triangle.prototype = {
  4369. constructor: THREE.Triangle,
  4370. set: function ( a, b, c ) {
  4371. this.a.copy( a );
  4372. this.b.copy( b );
  4373. this.c.copy( c );
  4374. return this;
  4375. },
  4376. setFromPointsAndIndices: function ( points, i0, i1, i2 ) {
  4377. this.a.copy( points[ i0 ] );
  4378. this.b.copy( points[ i1 ] );
  4379. this.c.copy( points[ i2 ] );
  4380. return this;
  4381. },
  4382. clone: function () {
  4383. return new this.constructor().copy( this );
  4384. },
  4385. copy: function ( triangle ) {
  4386. this.a.copy( triangle.a );
  4387. this.b.copy( triangle.b );
  4388. this.c.copy( triangle.c );
  4389. return this;
  4390. },
  4391. area: function () {
  4392. var v0 = new THREE.Vector3();
  4393. var v1 = new THREE.Vector3();
  4394. return function () {
  4395. v0.subVectors( this.c, this.b );
  4396. v1.subVectors( this.a, this.b );
  4397. return v0.cross( v1 ).length() * 0.5;
  4398. };
  4399. }(),
  4400. midpoint: function ( optionalTarget ) {
  4401. var result = optionalTarget || new THREE.Vector3();
  4402. return result.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  4403. },
  4404. normal: function ( optionalTarget ) {
  4405. return THREE.Triangle.normal( this.a, this.b, this.c, optionalTarget );
  4406. },
  4407. plane: function ( optionalTarget ) {
  4408. var result = optionalTarget || new THREE.Plane();
  4409. return result.setFromCoplanarPoints( this.a, this.b, this.c );
  4410. },
  4411. barycoordFromPoint: function ( point, optionalTarget ) {
  4412. return THREE.Triangle.barycoordFromPoint( point, this.a, this.b, this.c, optionalTarget );
  4413. },
  4414. containsPoint: function ( point ) {
  4415. return THREE.Triangle.containsPoint( point, this.a, this.b, this.c );
  4416. },
  4417. closestPointToPoint: function () {
  4418. var plane, edgeList, projectedPoint, closestPoint;
  4419. return function closestPointToPoint( point, optionalTarget ) {
  4420. if ( plane === undefined ) {
  4421. plane = new THREE.Plane();
  4422. edgeList = [ new THREE.Line3(), new THREE.Line3(), new THREE.Line3() ];
  4423. projectedPoint = new THREE.Vector3();
  4424. closestPoint = new THREE.Vector3();
  4425. }
  4426. var result = optionalTarget || new THREE.Vector3();
  4427. var minDistance = Infinity;
  4428. // project the point onto the plane of the triangle
  4429. plane.setFromCoplanarPoints( this.a, this.b, this.c );
  4430. plane.projectPoint( point, projectedPoint );
  4431. // check if the projection lies within the triangle
  4432. if( this.containsPoint( projectedPoint ) === true ) {
  4433. // if so, this is the closest point
  4434. result.copy( projectedPoint );
  4435. } else {
  4436. // if not, the point falls outside the triangle. the result is the closest point to the triangle's edges or vertices
  4437. edgeList[ 0 ].set( this.a, this.b );
  4438. edgeList[ 1 ].set( this.b, this.c );
  4439. edgeList[ 2 ].set( this.c, this.a );
  4440. for( var i = 0; i < edgeList.length; i ++ ) {
  4441. edgeList[ i ].closestPointToPoint( projectedPoint, true, closestPoint );
  4442. var distance = projectedPoint.distanceToSquared( closestPoint );
  4443. if( distance < minDistance ) {
  4444. minDistance = distance;
  4445. result.copy( closestPoint );
  4446. }
  4447. }
  4448. }
  4449. return result;
  4450. };
  4451. }(),
  4452. equals: function ( triangle ) {
  4453. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  4454. }
  4455. };
  4456. // File:src/math/Interpolant.js
  4457. /**
  4458. * Abstract base class of interpolants over parametric samples.
  4459. *
  4460. * The parameter domain is one dimensional, typically the time or a path
  4461. * along a curve defined by the data.
  4462. *
  4463. * The sample values can have any dimensionality and derived classes may
  4464. * apply special interpretations to the data.
  4465. *
  4466. * This class provides the interval seek in a Template Method, deferring
  4467. * the actual interpolation to derived classes.
  4468. *
  4469. * Time complexity is O(1) for linear access crossing at most two points
  4470. * and O(log N) for random access, where N is the number of positions.
  4471. *
  4472. * References:
  4473. *
  4474. * http://www.oodesign.com/template-method-pattern.html
  4475. *
  4476. * @author tschw
  4477. */
  4478. THREE.Interpolant = function(
  4479. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4480. this.parameterPositions = parameterPositions;
  4481. this._cachedIndex = 0;
  4482. this.resultBuffer = resultBuffer !== undefined ?
  4483. resultBuffer : new sampleValues.constructor( sampleSize );
  4484. this.sampleValues = sampleValues;
  4485. this.valueSize = sampleSize;
  4486. };
  4487. THREE.Interpolant.prototype = {
  4488. constructor: THREE.Interpolant,
  4489. evaluate: function( t ) {
  4490. var pp = this.parameterPositions,
  4491. i1 = this._cachedIndex,
  4492. t1 = pp[ i1 ],
  4493. t0 = pp[ i1 - 1 ];
  4494. validate_interval: {
  4495. seek: {
  4496. var right;
  4497. linear_scan: {
  4498. //- See http://jsperf.com/comparison-to-undefined/3
  4499. //- slower code:
  4500. //-
  4501. //- if ( t >= t1 || t1 === undefined ) {
  4502. forward_scan: if ( ! ( t < t1 ) ) {
  4503. for ( var giveUpAt = i1 + 2; ;) {
  4504. if ( t1 === undefined ) {
  4505. if ( t < t0 ) break forward_scan;
  4506. // after end
  4507. i1 = pp.length;
  4508. this._cachedIndex = i1;
  4509. return this.afterEnd_( i1 - 1, t, t0 );
  4510. }
  4511. if ( i1 === giveUpAt ) break; // this loop
  4512. t0 = t1;
  4513. t1 = pp[ ++ i1 ];
  4514. if ( t < t1 ) {
  4515. // we have arrived at the sought interval
  4516. break seek;
  4517. }
  4518. }
  4519. // prepare binary search on the right side of the index
  4520. right = pp.length;
  4521. break linear_scan;
  4522. }
  4523. //- slower code:
  4524. //- if ( t < t0 || t0 === undefined ) {
  4525. if ( ! ( t >= t0 ) ) {
  4526. // looping?
  4527. var t1global = pp[ 1 ];
  4528. if ( t < t1global ) {
  4529. i1 = 2; // + 1, using the scan for the details
  4530. t0 = t1global;
  4531. }
  4532. // linear reverse scan
  4533. for ( var giveUpAt = i1 - 2; ;) {
  4534. if ( t0 === undefined ) {
  4535. // before start
  4536. this._cachedIndex = 0;
  4537. return this.beforeStart_( 0, t, t1 );
  4538. }
  4539. if ( i1 === giveUpAt ) break; // this loop
  4540. t1 = t0;
  4541. t0 = pp[ -- i1 - 1 ];
  4542. if ( t >= t0 ) {
  4543. // we have arrived at the sought interval
  4544. break seek;
  4545. }
  4546. }
  4547. // prepare binary search on the left side of the index
  4548. right = i1;
  4549. i1 = 0;
  4550. break linear_scan;
  4551. }
  4552. // the interval is valid
  4553. break validate_interval;
  4554. } // linear scan
  4555. // binary search
  4556. while ( i1 < right ) {
  4557. var mid = ( i1 + right ) >>> 1;
  4558. if ( t < pp[ mid ] ) {
  4559. right = mid;
  4560. } else {
  4561. i1 = mid + 1;
  4562. }
  4563. }
  4564. t1 = pp[ i1 ];
  4565. t0 = pp[ i1 - 1 ];
  4566. // check boundary cases, again
  4567. if ( t0 === undefined ) {
  4568. this._cachedIndex = 0;
  4569. return this.beforeStart_( 0, t, t1 );
  4570. }
  4571. if ( t1 === undefined ) {
  4572. i1 = pp.length;
  4573. this._cachedIndex = i1;
  4574. return this.afterEnd_( i1 - 1, t0, t );
  4575. }
  4576. } // seek
  4577. this._cachedIndex = i1;
  4578. this.intervalChanged_( i1, t0, t1 );
  4579. } // validate_interval
  4580. return this.interpolate_( i1, t0, t, t1 );
  4581. },
  4582. settings: null, // optional, subclass-specific settings structure
  4583. // Note: The indirection allows central control of many interpolants.
  4584. // --- Protected interface
  4585. DefaultSettings_: {},
  4586. getSettings_: function() {
  4587. return this.settings || this.DefaultSettings_;
  4588. },
  4589. copySampleValue_: function( index ) {
  4590. // copies a sample value to the result buffer
  4591. var result = this.resultBuffer,
  4592. values = this.sampleValues,
  4593. stride = this.valueSize,
  4594. offset = index * stride;
  4595. for ( var i = 0; i !== stride; ++ i ) {
  4596. result[ i ] = values[ offset + i ];
  4597. }
  4598. return result;
  4599. },
  4600. // Template methods for derived classes:
  4601. interpolate_: function( i1, t0, t, t1 ) {
  4602. throw new Error( "call to abstract method" );
  4603. // implementations shall return this.resultBuffer
  4604. },
  4605. intervalChanged_: function( i1, t0, t1 ) {
  4606. // empty
  4607. }
  4608. };
  4609. Object.assign( THREE.Interpolant.prototype, {
  4610. beforeStart_: //( 0, t, t0 ), returns this.resultBuffer
  4611. THREE.Interpolant.prototype.copySampleValue_,
  4612. afterEnd_: //( N-1, tN-1, t ), returns this.resultBuffer
  4613. THREE.Interpolant.prototype.copySampleValue_
  4614. } );
  4615. // File:src/math/interpolants/CubicInterpolant.js
  4616. /**
  4617. * Fast and simple cubic spline interpolant.
  4618. *
  4619. * It was derived from a Hermitian construction setting the first derivative
  4620. * at each sample position to the linear slope between neighboring positions
  4621. * over their parameter interval.
  4622. *
  4623. * @author tschw
  4624. */
  4625. THREE.CubicInterpolant = function(
  4626. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4627. THREE.Interpolant.call(
  4628. this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  4629. this._weightPrev = -0;
  4630. this._offsetPrev = -0;
  4631. this._weightNext = -0;
  4632. this._offsetNext = -0;
  4633. };
  4634. THREE.CubicInterpolant.prototype =
  4635. Object.assign( Object.create( THREE.Interpolant.prototype ), {
  4636. constructor: THREE.CubicInterpolant,
  4637. DefaultSettings_: {
  4638. endingStart: THREE.ZeroCurvatureEnding,
  4639. endingEnd: THREE.ZeroCurvatureEnding
  4640. },
  4641. intervalChanged_: function( i1, t0, t1 ) {
  4642. var pp = this.parameterPositions,
  4643. iPrev = i1 - 2,
  4644. iNext = i1 + 1,
  4645. tPrev = pp[ iPrev ],
  4646. tNext = pp[ iNext ];
  4647. if ( tPrev === undefined ) {
  4648. switch ( this.getSettings_().endingStart ) {
  4649. case THREE.ZeroSlopeEnding:
  4650. // f'(t0) = 0
  4651. iPrev = i1;
  4652. tPrev = 2 * t0 - t1;
  4653. break;
  4654. case THREE.WrapAroundEnding:
  4655. // use the other end of the curve
  4656. iPrev = pp.length - 2;
  4657. tPrev = t0 + pp[ iPrev ] - pp[ iPrev + 1 ];
  4658. break;
  4659. default: // ZeroCurvatureEnding
  4660. // f''(t0) = 0 a.k.a. Natural Spline
  4661. iPrev = i1;
  4662. tPrev = t1;
  4663. }
  4664. }
  4665. if ( tNext === undefined ) {
  4666. switch ( this.getSettings_().endingEnd ) {
  4667. case THREE.ZeroSlopeEnding:
  4668. // f'(tN) = 0
  4669. iNext = i1;
  4670. tNext = 2 * t1 - t0;
  4671. break;
  4672. case THREE.WrapAroundEnding:
  4673. // use the other end of the curve
  4674. iNext = 1;
  4675. tNext = t1 + pp[ 1 ] - pp[ 0 ];
  4676. break;
  4677. default: // ZeroCurvatureEnding
  4678. // f''(tN) = 0, a.k.a. Natural Spline
  4679. iNext = i1 - 1;
  4680. tNext = t0;
  4681. }
  4682. }
  4683. var halfDt = ( t1 - t0 ) * 0.5,
  4684. stride = this.valueSize;
  4685. this._weightPrev = halfDt / ( t0 - tPrev );
  4686. this._weightNext = halfDt / ( tNext - t1 );
  4687. this._offsetPrev = iPrev * stride;
  4688. this._offsetNext = iNext * stride;
  4689. },
  4690. interpolate_: function( i1, t0, t, t1 ) {
  4691. var result = this.resultBuffer,
  4692. values = this.sampleValues,
  4693. stride = this.valueSize,
  4694. o1 = i1 * stride, o0 = o1 - stride,
  4695. oP = this._offsetPrev, oN = this._offsetNext,
  4696. wP = this._weightPrev, wN = this._weightNext,
  4697. p = ( t - t0 ) / ( t1 - t0 ),
  4698. pp = p * p,
  4699. ppp = pp * p;
  4700. // evaluate polynomials
  4701. var sP = - wP * ppp + 2 * wP * pp - wP * p;
  4702. var s0 = ( 1 + wP ) * ppp + (-1.5 - 2 * wP ) * pp + ( -0.5 + wP ) * p + 1;
  4703. var s1 = (-1 - wN ) * ppp + ( 1.5 + wN ) * pp + 0.5 * p;
  4704. var sN = wN * ppp - wN * pp;
  4705. // combine data linearly
  4706. for ( var i = 0; i !== stride; ++ i ) {
  4707. result[ i ] =
  4708. sP * values[ oP + i ] +
  4709. s0 * values[ o0 + i ] +
  4710. s1 * values[ o1 + i ] +
  4711. sN * values[ oN + i ];
  4712. }
  4713. return result;
  4714. }
  4715. } );
  4716. // File:src/math/interpolants/DiscreteInterpolant.js
  4717. /**
  4718. *
  4719. * Interpolant that evaluates to the sample value at the position preceeding
  4720. * the parameter.
  4721. *
  4722. * @author tschw
  4723. */
  4724. THREE.DiscreteInterpolant = function(
  4725. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4726. THREE.Interpolant.call(
  4727. this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  4728. };
  4729. THREE.DiscreteInterpolant.prototype =
  4730. Object.assign( Object.create( THREE.Interpolant.prototype ), {
  4731. constructor: THREE.DiscreteInterpolant,
  4732. interpolate_: function( i1, t0, t, t1 ) {
  4733. return this.copySampleValue_( i1 - 1 );
  4734. }
  4735. } );
  4736. // File:src/math/interpolants/LinearInterpolant.js
  4737. /**
  4738. * @author tschw
  4739. */
  4740. THREE.LinearInterpolant = function(
  4741. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4742. THREE.Interpolant.call(
  4743. this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  4744. };
  4745. THREE.LinearInterpolant.prototype =
  4746. Object.assign( Object.create( THREE.Interpolant.prototype ), {
  4747. constructor: THREE.LinearInterpolant,
  4748. interpolate_: function( i1, t0, t, t1 ) {
  4749. var result = this.resultBuffer,
  4750. values = this.sampleValues,
  4751. stride = this.valueSize,
  4752. offset1 = i1 * stride,
  4753. offset0 = offset1 - stride,
  4754. weight1 = ( t - t0 ) / ( t1 - t0 ),
  4755. weight0 = 1 - weight1;
  4756. for ( var i = 0; i !== stride; ++ i ) {
  4757. result[ i ] =
  4758. values[ offset0 + i ] * weight0 +
  4759. values[ offset1 + i ] * weight1;
  4760. }
  4761. return result;
  4762. }
  4763. } );
  4764. // File:src/math/interpolants/QuaternionLinearInterpolant.js
  4765. /**
  4766. * Spherical linear unit quaternion interpolant.
  4767. *
  4768. * @author tschw
  4769. */
  4770. THREE.QuaternionLinearInterpolant = function(
  4771. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4772. THREE.Interpolant.call(
  4773. this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  4774. };
  4775. THREE.QuaternionLinearInterpolant.prototype =
  4776. Object.assign( Object.create( THREE.Interpolant.prototype ), {
  4777. constructor: THREE.QuaternionLinearInterpolant,
  4778. interpolate_: function( i1, t0, t, t1 ) {
  4779. var result = this.resultBuffer,
  4780. values = this.sampleValues,
  4781. stride = this.valueSize,
  4782. offset = i1 * stride,
  4783. alpha = ( t - t0 ) / ( t1 - t0 );
  4784. for ( var end = offset + stride; offset !== end; offset += 4 ) {
  4785. THREE.Quaternion.slerpFlat( result, 0,
  4786. values, offset - stride, values, offset, alpha );
  4787. }
  4788. return result;
  4789. }
  4790. } );
  4791. // File:src/core/Clock.js
  4792. /**
  4793. * @author alteredq / http://alteredqualia.com/
  4794. */
  4795. THREE.Clock = function ( autoStart ) {
  4796. this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
  4797. this.startTime = 0;
  4798. this.oldTime = 0;
  4799. this.elapsedTime = 0;
  4800. this.running = false;
  4801. };
  4802. THREE.Clock.prototype = {
  4803. constructor: THREE.Clock,
  4804. start: function () {
  4805. this.startTime = ( performance || Date ).now();
  4806. this.oldTime = this.startTime;
  4807. this.running = true;
  4808. },
  4809. stop: function () {
  4810. this.getElapsedTime();
  4811. this.running = false;
  4812. },
  4813. getElapsedTime: function () {
  4814. this.getDelta();
  4815. return this.elapsedTime;
  4816. },
  4817. getDelta: function () {
  4818. var diff = 0;
  4819. if ( this.autoStart && ! this.running ) {
  4820. this.start();
  4821. }
  4822. if ( this.running ) {
  4823. var newTime = ( performance || Date ).now();
  4824. diff = ( newTime - this.oldTime ) / 1000;
  4825. this.oldTime = newTime;
  4826. this.elapsedTime += diff;
  4827. }
  4828. return diff;
  4829. }
  4830. };
  4831. // File:src/core/EventDispatcher.js
  4832. /**
  4833. * https://github.com/mrdoob/eventdispatcher.js/
  4834. */
  4835. THREE.EventDispatcher = function () {};
  4836. THREE.EventDispatcher.prototype = {
  4837. constructor: THREE.EventDispatcher,
  4838. apply: function ( object ) {
  4839. object.addEventListener = THREE.EventDispatcher.prototype.addEventListener;
  4840. object.hasEventListener = THREE.EventDispatcher.prototype.hasEventListener;
  4841. object.removeEventListener = THREE.EventDispatcher.prototype.removeEventListener;
  4842. object.dispatchEvent = THREE.EventDispatcher.prototype.dispatchEvent;
  4843. },
  4844. addEventListener: function ( type, listener ) {
  4845. if ( this._listeners === undefined ) this._listeners = {};
  4846. var listeners = this._listeners;
  4847. if ( listeners[ type ] === undefined ) {
  4848. listeners[ type ] = [];
  4849. }
  4850. if ( listeners[ type ].indexOf( listener ) === - 1 ) {
  4851. listeners[ type ].push( listener );
  4852. }
  4853. },
  4854. hasEventListener: function ( type, listener ) {
  4855. if ( this._listeners === undefined ) return false;
  4856. var listeners = this._listeners;
  4857. if ( listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1 ) {
  4858. return true;
  4859. }
  4860. return false;
  4861. },
  4862. removeEventListener: function ( type, listener ) {
  4863. if ( this._listeners === undefined ) return;
  4864. var listeners = this._listeners;
  4865. var listenerArray = listeners[ type ];
  4866. if ( listenerArray !== undefined ) {
  4867. var index = listenerArray.indexOf( listener );
  4868. if ( index !== - 1 ) {
  4869. listenerArray.splice( index, 1 );
  4870. }
  4871. }
  4872. },
  4873. dispatchEvent: function ( event ) {
  4874. if ( this._listeners === undefined ) return;
  4875. var listeners = this._listeners;
  4876. var listenerArray = listeners[ event.type ];
  4877. if ( listenerArray !== undefined ) {
  4878. event.target = this;
  4879. var array = [];
  4880. var length = listenerArray.length;
  4881. for ( var i = 0; i < length; i ++ ) {
  4882. array[ i ] = listenerArray[ i ];
  4883. }
  4884. for ( var i = 0; i < length; i ++ ) {
  4885. array[ i ].call( this, event );
  4886. }
  4887. }
  4888. }
  4889. };
  4890. // File:src/core/Layers.js
  4891. /**
  4892. * @author mrdoob / http://mrdoob.com/
  4893. */
  4894. THREE.Layers = function () {
  4895. this.mask = 1;
  4896. };
  4897. THREE.Layers.prototype = {
  4898. constructor: THREE.Layers,
  4899. set: function ( channel ) {
  4900. this.mask = 1 << channel;
  4901. },
  4902. enable: function ( channel ) {
  4903. this.mask |= 1 << channel;
  4904. },
  4905. toggle: function ( channel ) {
  4906. this.mask ^= 1 << channel;
  4907. },
  4908. disable: function ( channel ) {
  4909. this.mask &= ~ ( 1 << channel );
  4910. },
  4911. test: function ( layers ) {
  4912. return ( this.mask & layers.mask ) !== 0;
  4913. }
  4914. };
  4915. // File:src/core/Raycaster.js
  4916. /**
  4917. * @author mrdoob / http://mrdoob.com/
  4918. * @author bhouston / http://clara.io/
  4919. * @author stephomi / http://stephaneginier.com/
  4920. */
  4921. ( function ( THREE ) {
  4922. THREE.Raycaster = function ( origin, direction, near, far ) {
  4923. this.ray = new THREE.Ray( origin, direction );
  4924. // direction is assumed to be normalized (for accurate distance calculations)
  4925. this.near = near || 0;
  4926. this.far = far || Infinity;
  4927. this.params = {
  4928. Mesh: {},
  4929. Line: {},
  4930. LOD: {},
  4931. Points: { threshold: 1 },
  4932. Sprite: {}
  4933. };
  4934. Object.defineProperties( this.params, {
  4935. PointCloud: {
  4936. get: function () {
  4937. console.warn( 'THREE.Raycaster: params.PointCloud has been renamed to params.Points.' );
  4938. return this.Points;
  4939. }
  4940. }
  4941. } );
  4942. };
  4943. function ascSort( a, b ) {
  4944. return a.distance - b.distance;
  4945. }
  4946. function intersectObject( object, raycaster, intersects, recursive ) {
  4947. if ( object.visible === false ) return;
  4948. object.raycast( raycaster, intersects );
  4949. if ( recursive === true ) {
  4950. var children = object.children;
  4951. for ( var i = 0, l = children.length; i < l; i ++ ) {
  4952. intersectObject( children[ i ], raycaster, intersects, true );
  4953. }
  4954. }
  4955. }
  4956. //
  4957. THREE.Raycaster.prototype = {
  4958. constructor: THREE.Raycaster,
  4959. linePrecision: 1,
  4960. set: function ( origin, direction ) {
  4961. // direction is assumed to be normalized (for accurate distance calculations)
  4962. this.ray.set( origin, direction );
  4963. },
  4964. setFromCamera: function ( coords, camera ) {
  4965. if ( camera instanceof THREE.PerspectiveCamera ) {
  4966. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  4967. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  4968. } else if ( camera instanceof THREE.OrthographicCamera ) {
  4969. this.ray.origin.set( coords.x, coords.y, - 1 ).unproject( camera );
  4970. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  4971. } else {
  4972. console.error( 'THREE.Raycaster: Unsupported camera type.' );
  4973. }
  4974. },
  4975. intersectObject: function ( object, recursive ) {
  4976. var intersects = [];
  4977. intersectObject( object, this, intersects, recursive );
  4978. intersects.sort( ascSort );
  4979. return intersects;
  4980. },
  4981. intersectObjects: function ( objects, recursive ) {
  4982. var intersects = [];
  4983. if ( Array.isArray( objects ) === false ) {
  4984. console.warn( 'THREE.Raycaster.intersectObjects: objects is not an Array.' );
  4985. return intersects;
  4986. }
  4987. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  4988. intersectObject( objects[ i ], this, intersects, recursive );
  4989. }
  4990. intersects.sort( ascSort );
  4991. return intersects;
  4992. }
  4993. };
  4994. }( THREE ) );
  4995. // File:src/core/Object3D.js
  4996. /**
  4997. * @author mrdoob / http://mrdoob.com/
  4998. * @author mikael emtinger / http://gomo.se/
  4999. * @author alteredq / http://alteredqualia.com/
  5000. * @author WestLangley / http://github.com/WestLangley
  5001. * @author elephantatwork / www.elephantatwork.ch
  5002. */
  5003. THREE.Object3D = function () {
  5004. Object.defineProperty( this, 'id', { value: THREE.Object3DIdCount ++ } );
  5005. this.uuid = THREE.Math.generateUUID();
  5006. this.name = '';
  5007. this.type = 'Object3D';
  5008. this.parent = null;
  5009. this.children = [];
  5010. this.up = THREE.Object3D.DefaultUp.clone();
  5011. var position = new THREE.Vector3();
  5012. var rotation = new THREE.Euler();
  5013. var quaternion = new THREE.Quaternion();
  5014. var scale = new THREE.Vector3( 1, 1, 1 );
  5015. function onRotationChange() {
  5016. quaternion.setFromEuler( rotation, false );
  5017. }
  5018. function onQuaternionChange() {
  5019. rotation.setFromQuaternion( quaternion, undefined, false );
  5020. }
  5021. rotation.onChange( onRotationChange );
  5022. quaternion.onChange( onQuaternionChange );
  5023. Object.defineProperties( this, {
  5024. position: {
  5025. enumerable: true,
  5026. value: position
  5027. },
  5028. rotation: {
  5029. enumerable: true,
  5030. value: rotation
  5031. },
  5032. quaternion: {
  5033. enumerable: true,
  5034. value: quaternion
  5035. },
  5036. scale: {
  5037. enumerable: true,
  5038. value: scale
  5039. },
  5040. modelViewMatrix: {
  5041. value: new THREE.Matrix4()
  5042. },
  5043. normalMatrix: {
  5044. value: new THREE.Matrix3()
  5045. }
  5046. } );
  5047. this.rotationAutoUpdate = true;
  5048. this.matrix = new THREE.Matrix4();
  5049. this.matrixWorld = new THREE.Matrix4();
  5050. this.matrixAutoUpdate = THREE.Object3D.DefaultMatrixAutoUpdate;
  5051. this.matrixWorldNeedsUpdate = false;
  5052. this.layers = new THREE.Layers();
  5053. this.visible = true;
  5054. this.castShadow = false;
  5055. this.receiveShadow = false;
  5056. this.frustumCulled = true;
  5057. this.renderOrder = 0;
  5058. this.userData = {};
  5059. };
  5060. THREE.Object3D.DefaultUp = new THREE.Vector3( 0, 1, 0 );
  5061. THREE.Object3D.DefaultMatrixAutoUpdate = true;
  5062. THREE.Object3D.prototype = {
  5063. constructor: THREE.Object3D,
  5064. applyMatrix: function ( matrix ) {
  5065. this.matrix.multiplyMatrices( matrix, this.matrix );
  5066. this.matrix.decompose( this.position, this.quaternion, this.scale );
  5067. },
  5068. setRotationFromAxisAngle: function ( axis, angle ) {
  5069. // assumes axis is normalized
  5070. this.quaternion.setFromAxisAngle( axis, angle );
  5071. },
  5072. setRotationFromEuler: function ( euler ) {
  5073. this.quaternion.setFromEuler( euler, true );
  5074. },
  5075. setRotationFromMatrix: function ( m ) {
  5076. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  5077. this.quaternion.setFromRotationMatrix( m );
  5078. },
  5079. setRotationFromQuaternion: function ( q ) {
  5080. // assumes q is normalized
  5081. this.quaternion.copy( q );
  5082. },
  5083. rotateOnAxis: function () {
  5084. // rotate object on axis in object space
  5085. // axis is assumed to be normalized
  5086. var q1 = new THREE.Quaternion();
  5087. return function ( axis, angle ) {
  5088. q1.setFromAxisAngle( axis, angle );
  5089. this.quaternion.multiply( q1 );
  5090. return this;
  5091. };
  5092. }(),
  5093. rotateX: function () {
  5094. var v1 = new THREE.Vector3( 1, 0, 0 );
  5095. return function ( angle ) {
  5096. return this.rotateOnAxis( v1, angle );
  5097. };
  5098. }(),
  5099. rotateY: function () {
  5100. var v1 = new THREE.Vector3( 0, 1, 0 );
  5101. return function ( angle ) {
  5102. return this.rotateOnAxis( v1, angle );
  5103. };
  5104. }(),
  5105. rotateZ: function () {
  5106. var v1 = new THREE.Vector3( 0, 0, 1 );
  5107. return function ( angle ) {
  5108. return this.rotateOnAxis( v1, angle );
  5109. };
  5110. }(),
  5111. translateOnAxis: function () {
  5112. // translate object by distance along axis in object space
  5113. // axis is assumed to be normalized
  5114. var v1 = new THREE.Vector3();
  5115. return function ( axis, distance ) {
  5116. v1.copy( axis ).applyQuaternion( this.quaternion );
  5117. this.position.add( v1.multiplyScalar( distance ) );
  5118. return this;
  5119. };
  5120. }(),
  5121. translateX: function () {
  5122. var v1 = new THREE.Vector3( 1, 0, 0 );
  5123. return function ( distance ) {
  5124. return this.translateOnAxis( v1, distance );
  5125. };
  5126. }(),
  5127. translateY: function () {
  5128. var v1 = new THREE.Vector3( 0, 1, 0 );
  5129. return function ( distance ) {
  5130. return this.translateOnAxis( v1, distance );
  5131. };
  5132. }(),
  5133. translateZ: function () {
  5134. var v1 = new THREE.Vector3( 0, 0, 1 );
  5135. return function ( distance ) {
  5136. return this.translateOnAxis( v1, distance );
  5137. };
  5138. }(),
  5139. localToWorld: function ( vector ) {
  5140. return vector.applyMatrix4( this.matrixWorld );
  5141. },
  5142. worldToLocal: function () {
  5143. var m1 = new THREE.Matrix4();
  5144. return function ( vector ) {
  5145. return vector.applyMatrix4( m1.getInverse( this.matrixWorld ) );
  5146. };
  5147. }(),
  5148. lookAt: function () {
  5149. // This routine does not support objects with rotated and/or translated parent(s)
  5150. var m1 = new THREE.Matrix4();
  5151. return function ( vector ) {
  5152. m1.lookAt( vector, this.position, this.up );
  5153. this.quaternion.setFromRotationMatrix( m1 );
  5154. };
  5155. }(),
  5156. add: function ( object ) {
  5157. if ( arguments.length > 1 ) {
  5158. for ( var i = 0; i < arguments.length; i ++ ) {
  5159. this.add( arguments[ i ] );
  5160. }
  5161. return this;
  5162. }
  5163. if ( object === this ) {
  5164. console.error( "THREE.Object3D.add: object can't be added as a child of itself.", object );
  5165. return this;
  5166. }
  5167. if ( object instanceof THREE.Object3D ) {
  5168. if ( object.parent !== null ) {
  5169. object.parent.remove( object );
  5170. }
  5171. object.parent = this;
  5172. object.dispatchEvent( { type: 'added' } );
  5173. this.children.push( object );
  5174. } else {
  5175. console.error( "THREE.Object3D.add: object not an instance of THREE.Object3D.", object );
  5176. }
  5177. return this;
  5178. },
  5179. remove: function ( object ) {
  5180. if ( arguments.length > 1 ) {
  5181. for ( var i = 0; i < arguments.length; i ++ ) {
  5182. this.remove( arguments[ i ] );
  5183. }
  5184. }
  5185. var index = this.children.indexOf( object );
  5186. if ( index !== - 1 ) {
  5187. object.parent = null;
  5188. object.dispatchEvent( { type: 'removed' } );
  5189. this.children.splice( index, 1 );
  5190. }
  5191. },
  5192. getObjectById: function ( id ) {
  5193. return this.getObjectByProperty( 'id', id );
  5194. },
  5195. getObjectByName: function ( name ) {
  5196. return this.getObjectByProperty( 'name', name );
  5197. },
  5198. getObjectByProperty: function ( name, value ) {
  5199. if ( this[ name ] === value ) return this;
  5200. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  5201. var child = this.children[ i ];
  5202. var object = child.getObjectByProperty( name, value );
  5203. if ( object !== undefined ) {
  5204. return object;
  5205. }
  5206. }
  5207. return undefined;
  5208. },
  5209. getWorldPosition: function ( optionalTarget ) {
  5210. var result = optionalTarget || new THREE.Vector3();
  5211. this.updateMatrixWorld( true );
  5212. return result.setFromMatrixPosition( this.matrixWorld );
  5213. },
  5214. getWorldQuaternion: function () {
  5215. var position = new THREE.Vector3();
  5216. var scale = new THREE.Vector3();
  5217. return function ( optionalTarget ) {
  5218. var result = optionalTarget || new THREE.Quaternion();
  5219. this.updateMatrixWorld( true );
  5220. this.matrixWorld.decompose( position, result, scale );
  5221. return result;
  5222. };
  5223. }(),
  5224. getWorldRotation: function () {
  5225. var quaternion = new THREE.Quaternion();
  5226. return function ( optionalTarget ) {
  5227. var result = optionalTarget || new THREE.Euler();
  5228. this.getWorldQuaternion( quaternion );
  5229. return result.setFromQuaternion( quaternion, this.rotation.order, false );
  5230. };
  5231. }(),
  5232. getWorldScale: function () {
  5233. var position = new THREE.Vector3();
  5234. var quaternion = new THREE.Quaternion();
  5235. return function ( optionalTarget ) {
  5236. var result = optionalTarget || new THREE.Vector3();
  5237. this.updateMatrixWorld( true );
  5238. this.matrixWorld.decompose( position, quaternion, result );
  5239. return result;
  5240. };
  5241. }(),
  5242. getWorldDirection: function () {
  5243. var quaternion = new THREE.Quaternion();
  5244. return function ( optionalTarget ) {
  5245. var result = optionalTarget || new THREE.Vector3();
  5246. this.getWorldQuaternion( quaternion );
  5247. return result.set( 0, 0, 1 ).applyQuaternion( quaternion );
  5248. };
  5249. }(),
  5250. raycast: function () {},
  5251. traverse: function ( callback ) {
  5252. callback( this );
  5253. var children = this.children;
  5254. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5255. children[ i ].traverse( callback );
  5256. }
  5257. },
  5258. traverseVisible: function ( callback ) {
  5259. if ( this.visible === false ) return;
  5260. callback( this );
  5261. var children = this.children;
  5262. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5263. children[ i ].traverseVisible( callback );
  5264. }
  5265. },
  5266. traverseAncestors: function ( callback ) {
  5267. var parent = this.parent;
  5268. if ( parent !== null ) {
  5269. callback( parent );
  5270. parent.traverseAncestors( callback );
  5271. }
  5272. },
  5273. updateMatrix: function () {
  5274. this.matrix.compose( this.position, this.quaternion, this.scale );
  5275. this.matrixWorldNeedsUpdate = true;
  5276. },
  5277. updateMatrixWorld: function ( force ) {
  5278. if ( this.matrixAutoUpdate === true ) this.updateMatrix();
  5279. if ( this.matrixWorldNeedsUpdate === true || force === true ) {
  5280. if ( this.parent === null ) {
  5281. this.matrixWorld.copy( this.matrix );
  5282. } else {
  5283. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  5284. }
  5285. this.matrixWorldNeedsUpdate = false;
  5286. force = true;
  5287. }
  5288. // update children
  5289. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  5290. this.children[ i ].updateMatrixWorld( force );
  5291. }
  5292. },
  5293. toJSON: function ( meta ) {
  5294. // meta is '' when called from JSON.stringify
  5295. var isRootObject = ( meta === undefined || meta === '' );
  5296. var output = {};
  5297. // meta is a hash used to collect geometries, materials.
  5298. // not providing it implies that this is the root object
  5299. // being serialized.
  5300. if ( isRootObject ) {
  5301. // initialize meta obj
  5302. meta = {
  5303. geometries: {},
  5304. materials: {},
  5305. textures: {},
  5306. images: {}
  5307. };
  5308. output.metadata = {
  5309. version: 4.4,
  5310. type: 'Object',
  5311. generator: 'Object3D.toJSON'
  5312. };
  5313. }
  5314. // standard Object3D serialization
  5315. var object = {};
  5316. object.uuid = this.uuid;
  5317. object.type = this.type;
  5318. if ( this.name !== '' ) object.name = this.name;
  5319. if ( JSON.stringify( this.userData ) !== '{}' ) object.userData = this.userData;
  5320. if ( this.castShadow === true ) object.castShadow = true;
  5321. if ( this.receiveShadow === true ) object.receiveShadow = true;
  5322. if ( this.visible === false ) object.visible = false;
  5323. object.matrix = this.matrix.toArray();
  5324. //
  5325. if ( this.geometry !== undefined ) {
  5326. if ( meta.geometries[ this.geometry.uuid ] === undefined ) {
  5327. meta.geometries[ this.geometry.uuid ] = this.geometry.toJSON( meta );
  5328. }
  5329. object.geometry = this.geometry.uuid;
  5330. }
  5331. if ( this.material !== undefined ) {
  5332. if ( meta.materials[ this.material.uuid ] === undefined ) {
  5333. meta.materials[ this.material.uuid ] = this.material.toJSON( meta );
  5334. }
  5335. object.material = this.material.uuid;
  5336. }
  5337. //
  5338. if ( this.children.length > 0 ) {
  5339. object.children = [];
  5340. for ( var i = 0; i < this.children.length; i ++ ) {
  5341. object.children.push( this.children[ i ].toJSON( meta ).object );
  5342. }
  5343. }
  5344. if ( isRootObject ) {
  5345. var geometries = extractFromCache( meta.geometries );
  5346. var materials = extractFromCache( meta.materials );
  5347. var textures = extractFromCache( meta.textures );
  5348. var images = extractFromCache( meta.images );
  5349. if ( geometries.length > 0 ) output.geometries = geometries;
  5350. if ( materials.length > 0 ) output.materials = materials;
  5351. if ( textures.length > 0 ) output.textures = textures;
  5352. if ( images.length > 0 ) output.images = images;
  5353. }
  5354. output.object = object;
  5355. return output;
  5356. // extract data from the cache hash
  5357. // remove metadata on each item
  5358. // and return as array
  5359. function extractFromCache ( cache ) {
  5360. var values = [];
  5361. for ( var key in cache ) {
  5362. var data = cache[ key ];
  5363. delete data.metadata;
  5364. values.push( data );
  5365. }
  5366. return values;
  5367. }
  5368. },
  5369. clone: function ( recursive ) {
  5370. return new this.constructor().copy( this, recursive );
  5371. },
  5372. copy: function ( source, recursive ) {
  5373. if ( recursive === undefined ) recursive = true;
  5374. this.name = source.name;
  5375. this.up.copy( source.up );
  5376. this.position.copy( source.position );
  5377. this.quaternion.copy( source.quaternion );
  5378. this.scale.copy( source.scale );
  5379. this.rotationAutoUpdate = source.rotationAutoUpdate;
  5380. this.matrix.copy( source.matrix );
  5381. this.matrixWorld.copy( source.matrixWorld );
  5382. this.matrixAutoUpdate = source.matrixAutoUpdate;
  5383. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  5384. this.visible = source.visible;
  5385. this.castShadow = source.castShadow;
  5386. this.receiveShadow = source.receiveShadow;
  5387. this.frustumCulled = source.frustumCulled;
  5388. this.renderOrder = source.renderOrder;
  5389. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  5390. if ( recursive === true ) {
  5391. for ( var i = 0; i < source.children.length; i ++ ) {
  5392. var child = source.children[ i ];
  5393. this.add( child.clone() );
  5394. }
  5395. }
  5396. return this;
  5397. }
  5398. };
  5399. THREE.EventDispatcher.prototype.apply( THREE.Object3D.prototype );
  5400. THREE.Object3DIdCount = 0;
  5401. // File:src/core/Face3.js
  5402. /**
  5403. * @author mrdoob / http://mrdoob.com/
  5404. * @author alteredq / http://alteredqualia.com/
  5405. */
  5406. THREE.Face3 = function ( a, b, c, normal, color, materialIndex ) {
  5407. this.a = a;
  5408. this.b = b;
  5409. this.c = c;
  5410. this.normal = normal instanceof THREE.Vector3 ? normal : new THREE.Vector3();
  5411. this.vertexNormals = Array.isArray( normal ) ? normal : [];
  5412. this.color = color instanceof THREE.Color ? color : new THREE.Color();
  5413. this.vertexColors = Array.isArray( color ) ? color : [];
  5414. this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
  5415. };
  5416. THREE.Face3.prototype = {
  5417. constructor: THREE.Face3,
  5418. clone: function () {
  5419. return new this.constructor().copy( this );
  5420. },
  5421. copy: function ( source ) {
  5422. this.a = source.a;
  5423. this.b = source.b;
  5424. this.c = source.c;
  5425. this.normal.copy( source.normal );
  5426. this.color.copy( source.color );
  5427. this.materialIndex = source.materialIndex;
  5428. for ( var i = 0, il = source.vertexNormals.length; i < il; i ++ ) {
  5429. this.vertexNormals[ i ] = source.vertexNormals[ i ].clone();
  5430. }
  5431. for ( var i = 0, il = source.vertexColors.length; i < il; i ++ ) {
  5432. this.vertexColors[ i ] = source.vertexColors[ i ].clone();
  5433. }
  5434. return this;
  5435. }
  5436. };
  5437. // File:src/core/BufferAttribute.js
  5438. /**
  5439. * @author mrdoob / http://mrdoob.com/
  5440. */
  5441. THREE.BufferAttribute = function ( array, itemSize, normalized ) {
  5442. this.uuid = THREE.Math.generateUUID();
  5443. this.array = array;
  5444. this.itemSize = itemSize;
  5445. this.dynamic = false;
  5446. this.updateRange = { offset: 0, count: - 1 };
  5447. this.version = 0;
  5448. this.normalized = normalized === true;
  5449. };
  5450. THREE.BufferAttribute.prototype = {
  5451. constructor: THREE.BufferAttribute,
  5452. get count() {
  5453. return this.array.length / this.itemSize;
  5454. },
  5455. set needsUpdate( value ) {
  5456. if ( value === true ) this.version ++;
  5457. },
  5458. setDynamic: function ( value ) {
  5459. this.dynamic = value;
  5460. return this;
  5461. },
  5462. copy: function ( source ) {
  5463. this.array = new source.array.constructor( source.array );
  5464. this.itemSize = source.itemSize;
  5465. this.dynamic = source.dynamic;
  5466. return this;
  5467. },
  5468. copyAt: function ( index1, attribute, index2 ) {
  5469. index1 *= this.itemSize;
  5470. index2 *= attribute.itemSize;
  5471. for ( var i = 0, l = this.itemSize; i < l; i ++ ) {
  5472. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5473. }
  5474. return this;
  5475. },
  5476. copyArray: function ( array ) {
  5477. this.array.set( array );
  5478. return this;
  5479. },
  5480. copyColorsArray: function ( colors ) {
  5481. var array = this.array, offset = 0;
  5482. for ( var i = 0, l = colors.length; i < l; i ++ ) {
  5483. var color = colors[ i ];
  5484. if ( color === undefined ) {
  5485. console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
  5486. color = new THREE.Color();
  5487. }
  5488. array[ offset ++ ] = color.r;
  5489. array[ offset ++ ] = color.g;
  5490. array[ offset ++ ] = color.b;
  5491. }
  5492. return this;
  5493. },
  5494. copyIndicesArray: function ( indices ) {
  5495. var array = this.array, offset = 0;
  5496. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  5497. var index = indices[ i ];
  5498. array[ offset ++ ] = index.a;
  5499. array[ offset ++ ] = index.b;
  5500. array[ offset ++ ] = index.c;
  5501. }
  5502. return this;
  5503. },
  5504. copyVector2sArray: function ( vectors ) {
  5505. var array = this.array, offset = 0;
  5506. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5507. var vector = vectors[ i ];
  5508. if ( vector === undefined ) {
  5509. console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
  5510. vector = new THREE.Vector2();
  5511. }
  5512. array[ offset ++ ] = vector.x;
  5513. array[ offset ++ ] = vector.y;
  5514. }
  5515. return this;
  5516. },
  5517. copyVector3sArray: function ( vectors ) {
  5518. var array = this.array, offset = 0;
  5519. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5520. var vector = vectors[ i ];
  5521. if ( vector === undefined ) {
  5522. console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
  5523. vector = new THREE.Vector3();
  5524. }
  5525. array[ offset ++ ] = vector.x;
  5526. array[ offset ++ ] = vector.y;
  5527. array[ offset ++ ] = vector.z;
  5528. }
  5529. return this;
  5530. },
  5531. copyVector4sArray: function ( vectors ) {
  5532. var array = this.array, offset = 0;
  5533. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5534. var vector = vectors[ i ];
  5535. if ( vector === undefined ) {
  5536. console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i );
  5537. vector = new THREE.Vector4();
  5538. }
  5539. array[ offset ++ ] = vector.x;
  5540. array[ offset ++ ] = vector.y;
  5541. array[ offset ++ ] = vector.z;
  5542. array[ offset ++ ] = vector.w;
  5543. }
  5544. return this;
  5545. },
  5546. set: function ( value, offset ) {
  5547. if ( offset === undefined ) offset = 0;
  5548. this.array.set( value, offset );
  5549. return this;
  5550. },
  5551. getX: function ( index ) {
  5552. return this.array[ index * this.itemSize ];
  5553. },
  5554. setX: function ( index, x ) {
  5555. this.array[ index * this.itemSize ] = x;
  5556. return this;
  5557. },
  5558. getY: function ( index ) {
  5559. return this.array[ index * this.itemSize + 1 ];
  5560. },
  5561. setY: function ( index, y ) {
  5562. this.array[ index * this.itemSize + 1 ] = y;
  5563. return this;
  5564. },
  5565. getZ: function ( index ) {
  5566. return this.array[ index * this.itemSize + 2 ];
  5567. },
  5568. setZ: function ( index, z ) {
  5569. this.array[ index * this.itemSize + 2 ] = z;
  5570. return this;
  5571. },
  5572. getW: function ( index ) {
  5573. return this.array[ index * this.itemSize + 3 ];
  5574. },
  5575. setW: function ( index, w ) {
  5576. this.array[ index * this.itemSize + 3 ] = w;
  5577. return this;
  5578. },
  5579. setXY: function ( index, x, y ) {
  5580. index *= this.itemSize;
  5581. this.array[ index + 0 ] = x;
  5582. this.array[ index + 1 ] = y;
  5583. return this;
  5584. },
  5585. setXYZ: function ( index, x, y, z ) {
  5586. index *= this.itemSize;
  5587. this.array[ index + 0 ] = x;
  5588. this.array[ index + 1 ] = y;
  5589. this.array[ index + 2 ] = z;
  5590. return this;
  5591. },
  5592. setXYZW: function ( index, x, y, z, w ) {
  5593. index *= this.itemSize;
  5594. this.array[ index + 0 ] = x;
  5595. this.array[ index + 1 ] = y;
  5596. this.array[ index + 2 ] = z;
  5597. this.array[ index + 3 ] = w;
  5598. return this;
  5599. },
  5600. clone: function () {
  5601. return new this.constructor().copy( this );
  5602. }
  5603. };
  5604. //
  5605. THREE.Int8Attribute = function ( array, itemSize ) {
  5606. return new THREE.BufferAttribute( new Int8Array( array ), itemSize );
  5607. };
  5608. THREE.Uint8Attribute = function ( array, itemSize ) {
  5609. return new THREE.BufferAttribute( new Uint8Array( array ), itemSize );
  5610. };
  5611. THREE.Uint8ClampedAttribute = function ( array, itemSize ) {
  5612. return new THREE.BufferAttribute( new Uint8ClampedArray( array ), itemSize );
  5613. };
  5614. THREE.Int16Attribute = function ( array, itemSize ) {
  5615. return new THREE.BufferAttribute( new Int16Array( array ), itemSize );
  5616. };
  5617. THREE.Uint16Attribute = function ( array, itemSize ) {
  5618. return new THREE.BufferAttribute( new Uint16Array( array ), itemSize );
  5619. };
  5620. THREE.Int32Attribute = function ( array, itemSize ) {
  5621. return new THREE.BufferAttribute( new Int32Array( array ), itemSize );
  5622. };
  5623. THREE.Uint32Attribute = function ( array, itemSize ) {
  5624. return new THREE.BufferAttribute( new Uint32Array( array ), itemSize );
  5625. };
  5626. THREE.Float32Attribute = function ( array, itemSize ) {
  5627. return new THREE.BufferAttribute( new Float32Array( array ), itemSize );
  5628. };
  5629. THREE.Float64Attribute = function ( array, itemSize ) {
  5630. return new THREE.BufferAttribute( new Float64Array( array ), itemSize );
  5631. };
  5632. // Deprecated
  5633. THREE.DynamicBufferAttribute = function ( array, itemSize ) {
  5634. console.warn( 'THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setDynamic( true ) instead.' );
  5635. return new THREE.BufferAttribute( array, itemSize ).setDynamic( true );
  5636. };
  5637. // File:src/core/InstancedBufferAttribute.js
  5638. /**
  5639. * @author benaadams / https://twitter.com/ben_a_adams
  5640. */
  5641. THREE.InstancedBufferAttribute = function ( array, itemSize, meshPerAttribute ) {
  5642. THREE.BufferAttribute.call( this, array, itemSize );
  5643. this.meshPerAttribute = meshPerAttribute || 1;
  5644. };
  5645. THREE.InstancedBufferAttribute.prototype = Object.create( THREE.BufferAttribute.prototype );
  5646. THREE.InstancedBufferAttribute.prototype.constructor = THREE.InstancedBufferAttribute;
  5647. THREE.InstancedBufferAttribute.prototype.copy = function ( source ) {
  5648. THREE.BufferAttribute.prototype.copy.call( this, source );
  5649. this.meshPerAttribute = source.meshPerAttribute;
  5650. return this;
  5651. };
  5652. // File:src/core/InterleavedBuffer.js
  5653. /**
  5654. * @author benaadams / https://twitter.com/ben_a_adams
  5655. */
  5656. THREE.InterleavedBuffer = function ( array, stride ) {
  5657. this.uuid = THREE.Math.generateUUID();
  5658. this.array = array;
  5659. this.stride = stride;
  5660. this.dynamic = false;
  5661. this.updateRange = { offset: 0, count: - 1 };
  5662. this.version = 0;
  5663. };
  5664. THREE.InterleavedBuffer.prototype = {
  5665. constructor: THREE.InterleavedBuffer,
  5666. get length () {
  5667. return this.array.length;
  5668. },
  5669. get count () {
  5670. return this.array.length / this.stride;
  5671. },
  5672. set needsUpdate( value ) {
  5673. if ( value === true ) this.version ++;
  5674. },
  5675. setDynamic: function ( value ) {
  5676. this.dynamic = value;
  5677. return this;
  5678. },
  5679. copy: function ( source ) {
  5680. this.array = new source.array.constructor( source.array );
  5681. this.stride = source.stride;
  5682. this.dynamic = source.dynamic;
  5683. return this;
  5684. },
  5685. copyAt: function ( index1, attribute, index2 ) {
  5686. index1 *= this.stride;
  5687. index2 *= attribute.stride;
  5688. for ( var i = 0, l = this.stride; i < l; i ++ ) {
  5689. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5690. }
  5691. return this;
  5692. },
  5693. set: function ( value, offset ) {
  5694. if ( offset === undefined ) offset = 0;
  5695. this.array.set( value, offset );
  5696. return this;
  5697. },
  5698. clone: function () {
  5699. return new this.constructor().copy( this );
  5700. }
  5701. };
  5702. // File:src/core/InstancedInterleavedBuffer.js
  5703. /**
  5704. * @author benaadams / https://twitter.com/ben_a_adams
  5705. */
  5706. THREE.InstancedInterleavedBuffer = function ( array, stride, meshPerAttribute ) {
  5707. THREE.InterleavedBuffer.call( this, array, stride );
  5708. this.meshPerAttribute = meshPerAttribute || 1;
  5709. };
  5710. THREE.InstancedInterleavedBuffer.prototype = Object.create( THREE.InterleavedBuffer.prototype );
  5711. THREE.InstancedInterleavedBuffer.prototype.constructor = THREE.InstancedInterleavedBuffer;
  5712. THREE.InstancedInterleavedBuffer.prototype.copy = function ( source ) {
  5713. THREE.InterleavedBuffer.prototype.copy.call( this, source );
  5714. this.meshPerAttribute = source.meshPerAttribute;
  5715. return this;
  5716. };
  5717. // File:src/core/InterleavedBufferAttribute.js
  5718. /**
  5719. * @author benaadams / https://twitter.com/ben_a_adams
  5720. */
  5721. THREE.InterleavedBufferAttribute = function ( interleavedBuffer, itemSize, offset ) {
  5722. this.uuid = THREE.Math.generateUUID();
  5723. this.data = interleavedBuffer;
  5724. this.itemSize = itemSize;
  5725. this.offset = offset;
  5726. };
  5727. THREE.InterleavedBufferAttribute.prototype = {
  5728. constructor: THREE.InterleavedBufferAttribute,
  5729. get length() {
  5730. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Please use .count.' );
  5731. return this.array.length;
  5732. },
  5733. get count() {
  5734. return this.data.count;
  5735. },
  5736. setX: function ( index, x ) {
  5737. this.data.array[ index * this.data.stride + this.offset ] = x;
  5738. return this;
  5739. },
  5740. setY: function ( index, y ) {
  5741. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  5742. return this;
  5743. },
  5744. setZ: function ( index, z ) {
  5745. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  5746. return this;
  5747. },
  5748. setW: function ( index, w ) {
  5749. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  5750. return this;
  5751. },
  5752. getX: function ( index ) {
  5753. return this.data.array[ index * this.data.stride + this.offset ];
  5754. },
  5755. getY: function ( index ) {
  5756. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  5757. },
  5758. getZ: function ( index ) {
  5759. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  5760. },
  5761. getW: function ( index ) {
  5762. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  5763. },
  5764. setXY: function ( index, x, y ) {
  5765. index = index * this.data.stride + this.offset;
  5766. this.data.array[ index + 0 ] = x;
  5767. this.data.array[ index + 1 ] = y;
  5768. return this;
  5769. },
  5770. setXYZ: function ( index, x, y, z ) {
  5771. index = index * this.data.stride + this.offset;
  5772. this.data.array[ index + 0 ] = x;
  5773. this.data.array[ index + 1 ] = y;
  5774. this.data.array[ index + 2 ] = z;
  5775. return this;
  5776. },
  5777. setXYZW: function ( index, x, y, z, w ) {
  5778. index = index * this.data.stride + this.offset;
  5779. this.data.array[ index + 0 ] = x;
  5780. this.data.array[ index + 1 ] = y;
  5781. this.data.array[ index + 2 ] = z;
  5782. this.data.array[ index + 3 ] = w;
  5783. return this;
  5784. }
  5785. };
  5786. // File:src/core/Geometry.js
  5787. /**
  5788. * @author mrdoob / http://mrdoob.com/
  5789. * @author kile / http://kile.stravaganza.org/
  5790. * @author alteredq / http://alteredqualia.com/
  5791. * @author mikael emtinger / http://gomo.se/
  5792. * @author zz85 / http://www.lab4games.net/zz85/blog
  5793. * @author bhouston / http://clara.io
  5794. */
  5795. THREE.Geometry = function () {
  5796. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  5797. this.uuid = THREE.Math.generateUUID();
  5798. this.name = '';
  5799. this.type = 'Geometry';
  5800. this.vertices = [];
  5801. this.colors = [];
  5802. this.faces = [];
  5803. this.faceVertexUvs = [ [] ];
  5804. this.morphTargets = [];
  5805. this.morphNormals = [];
  5806. this.skinWeights = [];
  5807. this.skinIndices = [];
  5808. this.lineDistances = [];
  5809. this.boundingBox = null;
  5810. this.boundingSphere = null;
  5811. // update flags
  5812. this.verticesNeedUpdate = false;
  5813. this.elementsNeedUpdate = false;
  5814. this.uvsNeedUpdate = false;
  5815. this.normalsNeedUpdate = false;
  5816. this.colorsNeedUpdate = false;
  5817. this.lineDistancesNeedUpdate = false;
  5818. this.groupsNeedUpdate = false;
  5819. };
  5820. THREE.Geometry.prototype = {
  5821. constructor: THREE.Geometry,
  5822. applyMatrix: function ( matrix ) {
  5823. var normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  5824. for ( var i = 0, il = this.vertices.length; i < il; i ++ ) {
  5825. var vertex = this.vertices[ i ];
  5826. vertex.applyMatrix4( matrix );
  5827. }
  5828. for ( var i = 0, il = this.faces.length; i < il; i ++ ) {
  5829. var face = this.faces[ i ];
  5830. face.normal.applyMatrix3( normalMatrix ).normalize();
  5831. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  5832. face.vertexNormals[ j ].applyMatrix3( normalMatrix ).normalize();
  5833. }
  5834. }
  5835. if ( this.boundingBox !== null ) {
  5836. this.computeBoundingBox();
  5837. }
  5838. if ( this.boundingSphere !== null ) {
  5839. this.computeBoundingSphere();
  5840. }
  5841. this.verticesNeedUpdate = true;
  5842. this.normalsNeedUpdate = true;
  5843. return this;
  5844. },
  5845. rotateX: function () {
  5846. // rotate geometry around world x-axis
  5847. var m1;
  5848. return function rotateX( angle ) {
  5849. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5850. m1.makeRotationX( angle );
  5851. this.applyMatrix( m1 );
  5852. return this;
  5853. };
  5854. }(),
  5855. rotateY: function () {
  5856. // rotate geometry around world y-axis
  5857. var m1;
  5858. return function rotateY( angle ) {
  5859. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5860. m1.makeRotationY( angle );
  5861. this.applyMatrix( m1 );
  5862. return this;
  5863. };
  5864. }(),
  5865. rotateZ: function () {
  5866. // rotate geometry around world z-axis
  5867. var m1;
  5868. return function rotateZ( angle ) {
  5869. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5870. m1.makeRotationZ( angle );
  5871. this.applyMatrix( m1 );
  5872. return this;
  5873. };
  5874. }(),
  5875. translate: function () {
  5876. // translate geometry
  5877. var m1;
  5878. return function translate( x, y, z ) {
  5879. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5880. m1.makeTranslation( x, y, z );
  5881. this.applyMatrix( m1 );
  5882. return this;
  5883. };
  5884. }(),
  5885. scale: function () {
  5886. // scale geometry
  5887. var m1;
  5888. return function scale( x, y, z ) {
  5889. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5890. m1.makeScale( x, y, z );
  5891. this.applyMatrix( m1 );
  5892. return this;
  5893. };
  5894. }(),
  5895. lookAt: function () {
  5896. var obj;
  5897. return function lookAt( vector ) {
  5898. if ( obj === undefined ) obj = new THREE.Object3D();
  5899. obj.lookAt( vector );
  5900. obj.updateMatrix();
  5901. this.applyMatrix( obj.matrix );
  5902. };
  5903. }(),
  5904. fromBufferGeometry: function ( geometry ) {
  5905. var scope = this;
  5906. var indices = geometry.index !== null ? geometry.index.array : undefined;
  5907. var attributes = geometry.attributes;
  5908. var positions = attributes.position.array;
  5909. var normals = attributes.normal !== undefined ? attributes.normal.array : undefined;
  5910. var colors = attributes.color !== undefined ? attributes.color.array : undefined;
  5911. var uvs = attributes.uv !== undefined ? attributes.uv.array : undefined;
  5912. var uvs2 = attributes.uv2 !== undefined ? attributes.uv2.array : undefined;
  5913. if ( uvs2 !== undefined ) this.faceVertexUvs[ 1 ] = [];
  5914. var tempNormals = [];
  5915. var tempUVs = [];
  5916. var tempUVs2 = [];
  5917. for ( var i = 0, j = 0; i < positions.length; i += 3, j += 2 ) {
  5918. scope.vertices.push( new THREE.Vector3( positions[ i ], positions[ i + 1 ], positions[ i + 2 ] ) );
  5919. if ( normals !== undefined ) {
  5920. tempNormals.push( new THREE.Vector3( normals[ i ], normals[ i + 1 ], normals[ i + 2 ] ) );
  5921. }
  5922. if ( colors !== undefined ) {
  5923. scope.colors.push( new THREE.Color( colors[ i ], colors[ i + 1 ], colors[ i + 2 ] ) );
  5924. }
  5925. if ( uvs !== undefined ) {
  5926. tempUVs.push( new THREE.Vector2( uvs[ j ], uvs[ j + 1 ] ) );
  5927. }
  5928. if ( uvs2 !== undefined ) {
  5929. tempUVs2.push( new THREE.Vector2( uvs2[ j ], uvs2[ j + 1 ] ) );
  5930. }
  5931. }
  5932. function addFace( a, b, c, materialIndex ) {
  5933. var vertexNormals = normals !== undefined ? [ tempNormals[ a ].clone(), tempNormals[ b ].clone(), tempNormals[ c ].clone() ] : [];
  5934. var vertexColors = colors !== undefined ? [ scope.colors[ a ].clone(), scope.colors[ b ].clone(), scope.colors[ c ].clone() ] : [];
  5935. var face = new THREE.Face3( a, b, c, vertexNormals, vertexColors, materialIndex );
  5936. scope.faces.push( face );
  5937. if ( uvs !== undefined ) {
  5938. scope.faceVertexUvs[ 0 ].push( [ tempUVs[ a ].clone(), tempUVs[ b ].clone(), tempUVs[ c ].clone() ] );
  5939. }
  5940. if ( uvs2 !== undefined ) {
  5941. scope.faceVertexUvs[ 1 ].push( [ tempUVs2[ a ].clone(), tempUVs2[ b ].clone(), tempUVs2[ c ].clone() ] );
  5942. }
  5943. }
  5944. if ( indices !== undefined ) {
  5945. var groups = geometry.groups;
  5946. if ( groups.length > 0 ) {
  5947. for ( var i = 0; i < groups.length; i ++ ) {
  5948. var group = groups[ i ];
  5949. var start = group.start;
  5950. var count = group.count;
  5951. for ( var j = start, jl = start + count; j < jl; j += 3 ) {
  5952. addFace( indices[ j ], indices[ j + 1 ], indices[ j + 2 ], group.materialIndex );
  5953. }
  5954. }
  5955. } else {
  5956. for ( var i = 0; i < indices.length; i += 3 ) {
  5957. addFace( indices[ i ], indices[ i + 1 ], indices[ i + 2 ] );
  5958. }
  5959. }
  5960. } else {
  5961. for ( var i = 0; i < positions.length / 3; i += 3 ) {
  5962. addFace( i, i + 1, i + 2 );
  5963. }
  5964. }
  5965. this.computeFaceNormals();
  5966. if ( geometry.boundingBox !== null ) {
  5967. this.boundingBox = geometry.boundingBox.clone();
  5968. }
  5969. if ( geometry.boundingSphere !== null ) {
  5970. this.boundingSphere = geometry.boundingSphere.clone();
  5971. }
  5972. return this;
  5973. },
  5974. center: function () {
  5975. this.computeBoundingBox();
  5976. var offset = this.boundingBox.center().negate();
  5977. this.translate( offset.x, offset.y, offset.z );
  5978. return offset;
  5979. },
  5980. normalize: function () {
  5981. this.computeBoundingSphere();
  5982. var center = this.boundingSphere.center;
  5983. var radius = this.boundingSphere.radius;
  5984. var s = radius === 0 ? 1 : 1.0 / radius;
  5985. var matrix = new THREE.Matrix4();
  5986. matrix.set(
  5987. s, 0, 0, - s * center.x,
  5988. 0, s, 0, - s * center.y,
  5989. 0, 0, s, - s * center.z,
  5990. 0, 0, 0, 1
  5991. );
  5992. this.applyMatrix( matrix );
  5993. return this;
  5994. },
  5995. computeFaceNormals: function () {
  5996. var cb = new THREE.Vector3(), ab = new THREE.Vector3();
  5997. for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5998. var face = this.faces[ f ];
  5999. var vA = this.vertices[ face.a ];
  6000. var vB = this.vertices[ face.b ];
  6001. var vC = this.vertices[ face.c ];
  6002. cb.subVectors( vC, vB );
  6003. ab.subVectors( vA, vB );
  6004. cb.cross( ab );
  6005. cb.normalize();
  6006. face.normal.copy( cb );
  6007. }
  6008. },
  6009. computeVertexNormals: function ( areaWeighted ) {
  6010. if ( areaWeighted === undefined ) areaWeighted = true;
  6011. var v, vl, f, fl, face, vertices;
  6012. vertices = new Array( this.vertices.length );
  6013. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  6014. vertices[ v ] = new THREE.Vector3();
  6015. }
  6016. if ( areaWeighted ) {
  6017. // vertex normals weighted by triangle areas
  6018. // http://www.iquilezles.org/www/articles/normals/normals.htm
  6019. var vA, vB, vC;
  6020. var cb = new THREE.Vector3(), ab = new THREE.Vector3();
  6021. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6022. face = this.faces[ f ];
  6023. vA = this.vertices[ face.a ];
  6024. vB = this.vertices[ face.b ];
  6025. vC = this.vertices[ face.c ];
  6026. cb.subVectors( vC, vB );
  6027. ab.subVectors( vA, vB );
  6028. cb.cross( ab );
  6029. vertices[ face.a ].add( cb );
  6030. vertices[ face.b ].add( cb );
  6031. vertices[ face.c ].add( cb );
  6032. }
  6033. } else {
  6034. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6035. face = this.faces[ f ];
  6036. vertices[ face.a ].add( face.normal );
  6037. vertices[ face.b ].add( face.normal );
  6038. vertices[ face.c ].add( face.normal );
  6039. }
  6040. }
  6041. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  6042. vertices[ v ].normalize();
  6043. }
  6044. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6045. face = this.faces[ f ];
  6046. var vertexNormals = face.vertexNormals;
  6047. if ( vertexNormals.length === 3 ) {
  6048. vertexNormals[ 0 ].copy( vertices[ face.a ] );
  6049. vertexNormals[ 1 ].copy( vertices[ face.b ] );
  6050. vertexNormals[ 2 ].copy( vertices[ face.c ] );
  6051. } else {
  6052. vertexNormals[ 0 ] = vertices[ face.a ].clone();
  6053. vertexNormals[ 1 ] = vertices[ face.b ].clone();
  6054. vertexNormals[ 2 ] = vertices[ face.c ].clone();
  6055. }
  6056. }
  6057. if ( this.faces.length > 0 ) {
  6058. this.normalsNeedUpdate = true;
  6059. }
  6060. },
  6061. computeMorphNormals: function () {
  6062. var i, il, f, fl, face;
  6063. // save original normals
  6064. // - create temp variables on first access
  6065. // otherwise just copy (for faster repeated calls)
  6066. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6067. face = this.faces[ f ];
  6068. if ( ! face.__originalFaceNormal ) {
  6069. face.__originalFaceNormal = face.normal.clone();
  6070. } else {
  6071. face.__originalFaceNormal.copy( face.normal );
  6072. }
  6073. if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
  6074. for ( i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
  6075. if ( ! face.__originalVertexNormals[ i ] ) {
  6076. face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
  6077. } else {
  6078. face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
  6079. }
  6080. }
  6081. }
  6082. // use temp geometry to compute face and vertex normals for each morph
  6083. var tmpGeo = new THREE.Geometry();
  6084. tmpGeo.faces = this.faces;
  6085. for ( i = 0, il = this.morphTargets.length; i < il; i ++ ) {
  6086. // create on first access
  6087. if ( ! this.morphNormals[ i ] ) {
  6088. this.morphNormals[ i ] = {};
  6089. this.morphNormals[ i ].faceNormals = [];
  6090. this.morphNormals[ i ].vertexNormals = [];
  6091. var dstNormalsFace = this.morphNormals[ i ].faceNormals;
  6092. var dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
  6093. var faceNormal, vertexNormals;
  6094. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6095. faceNormal = new THREE.Vector3();
  6096. vertexNormals = { a: new THREE.Vector3(), b: new THREE.Vector3(), c: new THREE.Vector3() };
  6097. dstNormalsFace.push( faceNormal );
  6098. dstNormalsVertex.push( vertexNormals );
  6099. }
  6100. }
  6101. var morphNormals = this.morphNormals[ i ];
  6102. // set vertices to morph target
  6103. tmpGeo.vertices = this.morphTargets[ i ].vertices;
  6104. // compute morph normals
  6105. tmpGeo.computeFaceNormals();
  6106. tmpGeo.computeVertexNormals();
  6107. // store morph normals
  6108. var faceNormal, vertexNormals;
  6109. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6110. face = this.faces[ f ];
  6111. faceNormal = morphNormals.faceNormals[ f ];
  6112. vertexNormals = morphNormals.vertexNormals[ f ];
  6113. faceNormal.copy( face.normal );
  6114. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  6115. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  6116. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  6117. }
  6118. }
  6119. // restore original normals
  6120. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6121. face = this.faces[ f ];
  6122. face.normal = face.__originalFaceNormal;
  6123. face.vertexNormals = face.__originalVertexNormals;
  6124. }
  6125. },
  6126. computeTangents: function () {
  6127. console.warn( 'THREE.Geometry: .computeTangents() has been removed.' );
  6128. },
  6129. computeLineDistances: function () {
  6130. var d = 0;
  6131. var vertices = this.vertices;
  6132. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  6133. if ( i > 0 ) {
  6134. d += vertices[ i ].distanceTo( vertices[ i - 1 ] );
  6135. }
  6136. this.lineDistances[ i ] = d;
  6137. }
  6138. },
  6139. computeBoundingBox: function () {
  6140. if ( this.boundingBox === null ) {
  6141. this.boundingBox = new THREE.Box3();
  6142. }
  6143. this.boundingBox.setFromPoints( this.vertices );
  6144. },
  6145. computeBoundingSphere: function () {
  6146. if ( this.boundingSphere === null ) {
  6147. this.boundingSphere = new THREE.Sphere();
  6148. }
  6149. this.boundingSphere.setFromPoints( this.vertices );
  6150. },
  6151. merge: function ( geometry, matrix, materialIndexOffset ) {
  6152. if ( geometry instanceof THREE.Geometry === false ) {
  6153. console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry );
  6154. return;
  6155. }
  6156. var normalMatrix,
  6157. vertexOffset = this.vertices.length,
  6158. vertices1 = this.vertices,
  6159. vertices2 = geometry.vertices,
  6160. faces1 = this.faces,
  6161. faces2 = geometry.faces,
  6162. uvs1 = this.faceVertexUvs[ 0 ],
  6163. uvs2 = geometry.faceVertexUvs[ 0 ];
  6164. if ( materialIndexOffset === undefined ) materialIndexOffset = 0;
  6165. if ( matrix !== undefined ) {
  6166. normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  6167. }
  6168. // vertices
  6169. for ( var i = 0, il = vertices2.length; i < il; i ++ ) {
  6170. var vertex = vertices2[ i ];
  6171. var vertexCopy = vertex.clone();
  6172. if ( matrix !== undefined ) vertexCopy.applyMatrix4( matrix );
  6173. vertices1.push( vertexCopy );
  6174. }
  6175. // faces
  6176. for ( i = 0, il = faces2.length; i < il; i ++ ) {
  6177. var face = faces2[ i ], faceCopy, normal, color,
  6178. faceVertexNormals = face.vertexNormals,
  6179. faceVertexColors = face.vertexColors;
  6180. faceCopy = new THREE.Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset );
  6181. faceCopy.normal.copy( face.normal );
  6182. if ( normalMatrix !== undefined ) {
  6183. faceCopy.normal.applyMatrix3( normalMatrix ).normalize();
  6184. }
  6185. for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
  6186. normal = faceVertexNormals[ j ].clone();
  6187. if ( normalMatrix !== undefined ) {
  6188. normal.applyMatrix3( normalMatrix ).normalize();
  6189. }
  6190. faceCopy.vertexNormals.push( normal );
  6191. }
  6192. faceCopy.color.copy( face.color );
  6193. for ( var j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
  6194. color = faceVertexColors[ j ];
  6195. faceCopy.vertexColors.push( color.clone() );
  6196. }
  6197. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  6198. faces1.push( faceCopy );
  6199. }
  6200. // uvs
  6201. for ( i = 0, il = uvs2.length; i < il; i ++ ) {
  6202. var uv = uvs2[ i ], uvCopy = [];
  6203. if ( uv === undefined ) {
  6204. continue;
  6205. }
  6206. for ( var j = 0, jl = uv.length; j < jl; j ++ ) {
  6207. uvCopy.push( uv[ j ].clone() );
  6208. }
  6209. uvs1.push( uvCopy );
  6210. }
  6211. },
  6212. mergeMesh: function ( mesh ) {
  6213. if ( mesh instanceof THREE.Mesh === false ) {
  6214. console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh );
  6215. return;
  6216. }
  6217. mesh.matrixAutoUpdate && mesh.updateMatrix();
  6218. this.merge( mesh.geometry, mesh.matrix );
  6219. },
  6220. /*
  6221. * Checks for duplicate vertices with hashmap.
  6222. * Duplicated vertices are removed
  6223. * and faces' vertices are updated.
  6224. */
  6225. mergeVertices: function () {
  6226. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  6227. var unique = [], changes = [];
  6228. var v, key;
  6229. var precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001
  6230. var precision = Math.pow( 10, precisionPoints );
  6231. var i, il, face;
  6232. var indices, j, jl;
  6233. for ( i = 0, il = this.vertices.length; i < il; i ++ ) {
  6234. v = this.vertices[ i ];
  6235. key = Math.round( v.x * precision ) + '_' + Math.round( v.y * precision ) + '_' + Math.round( v.z * precision );
  6236. if ( verticesMap[ key ] === undefined ) {
  6237. verticesMap[ key ] = i;
  6238. unique.push( this.vertices[ i ] );
  6239. changes[ i ] = unique.length - 1;
  6240. } else {
  6241. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  6242. changes[ i ] = changes[ verticesMap[ key ] ];
  6243. }
  6244. }
  6245. // if faces are completely degenerate after merging vertices, we
  6246. // have to remove them from the geometry.
  6247. var faceIndicesToRemove = [];
  6248. for ( i = 0, il = this.faces.length; i < il; i ++ ) {
  6249. face = this.faces[ i ];
  6250. face.a = changes[ face.a ];
  6251. face.b = changes[ face.b ];
  6252. face.c = changes[ face.c ];
  6253. indices = [ face.a, face.b, face.c ];
  6254. var dupIndex = - 1;
  6255. // if any duplicate vertices are found in a Face3
  6256. // we have to remove the face as nothing can be saved
  6257. for ( var n = 0; n < 3; n ++ ) {
  6258. if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) {
  6259. dupIndex = n;
  6260. faceIndicesToRemove.push( i );
  6261. break;
  6262. }
  6263. }
  6264. }
  6265. for ( i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
  6266. var idx = faceIndicesToRemove[ i ];
  6267. this.faces.splice( idx, 1 );
  6268. for ( j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {
  6269. this.faceVertexUvs[ j ].splice( idx, 1 );
  6270. }
  6271. }
  6272. // Use unique set of vertices
  6273. var diff = this.vertices.length - unique.length;
  6274. this.vertices = unique;
  6275. return diff;
  6276. },
  6277. sortFacesByMaterialIndex: function () {
  6278. var faces = this.faces;
  6279. var length = faces.length;
  6280. // tag faces
  6281. for ( var i = 0; i < length; i ++ ) {
  6282. faces[ i ]._id = i;
  6283. }
  6284. // sort faces
  6285. function materialIndexSort( a, b ) {
  6286. return a.materialIndex - b.materialIndex;
  6287. }
  6288. faces.sort( materialIndexSort );
  6289. // sort uvs
  6290. var uvs1 = this.faceVertexUvs[ 0 ];
  6291. var uvs2 = this.faceVertexUvs[ 1 ];
  6292. var newUvs1, newUvs2;
  6293. if ( uvs1 && uvs1.length === length ) newUvs1 = [];
  6294. if ( uvs2 && uvs2.length === length ) newUvs2 = [];
  6295. for ( var i = 0; i < length; i ++ ) {
  6296. var id = faces[ i ]._id;
  6297. if ( newUvs1 ) newUvs1.push( uvs1[ id ] );
  6298. if ( newUvs2 ) newUvs2.push( uvs2[ id ] );
  6299. }
  6300. if ( newUvs1 ) this.faceVertexUvs[ 0 ] = newUvs1;
  6301. if ( newUvs2 ) this.faceVertexUvs[ 1 ] = newUvs2;
  6302. },
  6303. toJSON: function () {
  6304. var data = {
  6305. metadata: {
  6306. version: 4.4,
  6307. type: 'Geometry',
  6308. generator: 'Geometry.toJSON'
  6309. }
  6310. };
  6311. // standard Geometry serialization
  6312. data.uuid = this.uuid;
  6313. data.type = this.type;
  6314. if ( this.name !== '' ) data.name = this.name;
  6315. if ( this.parameters !== undefined ) {
  6316. var parameters = this.parameters;
  6317. for ( var key in parameters ) {
  6318. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  6319. }
  6320. return data;
  6321. }
  6322. var vertices = [];
  6323. for ( var i = 0; i < this.vertices.length; i ++ ) {
  6324. var vertex = this.vertices[ i ];
  6325. vertices.push( vertex.x, vertex.y, vertex.z );
  6326. }
  6327. var faces = [];
  6328. var normals = [];
  6329. var normalsHash = {};
  6330. var colors = [];
  6331. var colorsHash = {};
  6332. var uvs = [];
  6333. var uvsHash = {};
  6334. for ( var i = 0; i < this.faces.length; i ++ ) {
  6335. var face = this.faces[ i ];
  6336. var hasMaterial = true;
  6337. var hasFaceUv = false; // deprecated
  6338. var hasFaceVertexUv = this.faceVertexUvs[ 0 ][ i ] !== undefined;
  6339. var hasFaceNormal = face.normal.length() > 0;
  6340. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  6341. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  6342. var hasFaceVertexColor = face.vertexColors.length > 0;
  6343. var faceType = 0;
  6344. faceType = setBit( faceType, 0, 0 ); // isQuad
  6345. faceType = setBit( faceType, 1, hasMaterial );
  6346. faceType = setBit( faceType, 2, hasFaceUv );
  6347. faceType = setBit( faceType, 3, hasFaceVertexUv );
  6348. faceType = setBit( faceType, 4, hasFaceNormal );
  6349. faceType = setBit( faceType, 5, hasFaceVertexNormal );
  6350. faceType = setBit( faceType, 6, hasFaceColor );
  6351. faceType = setBit( faceType, 7, hasFaceVertexColor );
  6352. faces.push( faceType );
  6353. faces.push( face.a, face.b, face.c );
  6354. faces.push( face.materialIndex );
  6355. if ( hasFaceVertexUv ) {
  6356. var faceVertexUvs = this.faceVertexUvs[ 0 ][ i ];
  6357. faces.push(
  6358. getUvIndex( faceVertexUvs[ 0 ] ),
  6359. getUvIndex( faceVertexUvs[ 1 ] ),
  6360. getUvIndex( faceVertexUvs[ 2 ] )
  6361. );
  6362. }
  6363. if ( hasFaceNormal ) {
  6364. faces.push( getNormalIndex( face.normal ) );
  6365. }
  6366. if ( hasFaceVertexNormal ) {
  6367. var vertexNormals = face.vertexNormals;
  6368. faces.push(
  6369. getNormalIndex( vertexNormals[ 0 ] ),
  6370. getNormalIndex( vertexNormals[ 1 ] ),
  6371. getNormalIndex( vertexNormals[ 2 ] )
  6372. );
  6373. }
  6374. if ( hasFaceColor ) {
  6375. faces.push( getColorIndex( face.color ) );
  6376. }
  6377. if ( hasFaceVertexColor ) {
  6378. var vertexColors = face.vertexColors;
  6379. faces.push(
  6380. getColorIndex( vertexColors[ 0 ] ),
  6381. getColorIndex( vertexColors[ 1 ] ),
  6382. getColorIndex( vertexColors[ 2 ] )
  6383. );
  6384. }
  6385. }
  6386. function setBit( value, position, enabled ) {
  6387. return enabled ? value | ( 1 << position ) : value & ( ~ ( 1 << position ) );
  6388. }
  6389. function getNormalIndex( normal ) {
  6390. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  6391. if ( normalsHash[ hash ] !== undefined ) {
  6392. return normalsHash[ hash ];
  6393. }
  6394. normalsHash[ hash ] = normals.length / 3;
  6395. normals.push( normal.x, normal.y, normal.z );
  6396. return normalsHash[ hash ];
  6397. }
  6398. function getColorIndex( color ) {
  6399. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  6400. if ( colorsHash[ hash ] !== undefined ) {
  6401. return colorsHash[ hash ];
  6402. }
  6403. colorsHash[ hash ] = colors.length;
  6404. colors.push( color.getHex() );
  6405. return colorsHash[ hash ];
  6406. }
  6407. function getUvIndex( uv ) {
  6408. var hash = uv.x.toString() + uv.y.toString();
  6409. if ( uvsHash[ hash ] !== undefined ) {
  6410. return uvsHash[ hash ];
  6411. }
  6412. uvsHash[ hash ] = uvs.length / 2;
  6413. uvs.push( uv.x, uv.y );
  6414. return uvsHash[ hash ];
  6415. }
  6416. data.data = {};
  6417. data.data.vertices = vertices;
  6418. data.data.normals = normals;
  6419. if ( colors.length > 0 ) data.data.colors = colors;
  6420. if ( uvs.length > 0 ) data.data.uvs = [ uvs ]; // temporal backward compatibility
  6421. data.data.faces = faces;
  6422. return data;
  6423. },
  6424. clone: function () {
  6425. /*
  6426. // Handle primitives
  6427. var parameters = this.parameters;
  6428. if ( parameters !== undefined ) {
  6429. var values = [];
  6430. for ( var key in parameters ) {
  6431. values.push( parameters[ key ] );
  6432. }
  6433. var geometry = Object.create( this.constructor.prototype );
  6434. this.constructor.apply( geometry, values );
  6435. return geometry;
  6436. }
  6437. return new this.constructor().copy( this );
  6438. */
  6439. return new THREE.Geometry().copy( this );
  6440. },
  6441. copy: function ( source ) {
  6442. this.vertices = [];
  6443. this.faces = [];
  6444. this.faceVertexUvs = [ [] ];
  6445. var vertices = source.vertices;
  6446. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  6447. this.vertices.push( vertices[ i ].clone() );
  6448. }
  6449. var faces = source.faces;
  6450. for ( var i = 0, il = faces.length; i < il; i ++ ) {
  6451. this.faces.push( faces[ i ].clone() );
  6452. }
  6453. for ( var i = 0, il = source.faceVertexUvs.length; i < il; i ++ ) {
  6454. var faceVertexUvs = source.faceVertexUvs[ i ];
  6455. if ( this.faceVertexUvs[ i ] === undefined ) {
  6456. this.faceVertexUvs[ i ] = [];
  6457. }
  6458. for ( var j = 0, jl = faceVertexUvs.length; j < jl; j ++ ) {
  6459. var uvs = faceVertexUvs[ j ], uvsCopy = [];
  6460. for ( var k = 0, kl = uvs.length; k < kl; k ++ ) {
  6461. var uv = uvs[ k ];
  6462. uvsCopy.push( uv.clone() );
  6463. }
  6464. this.faceVertexUvs[ i ].push( uvsCopy );
  6465. }
  6466. }
  6467. return this;
  6468. },
  6469. dispose: function () {
  6470. this.dispatchEvent( { type: 'dispose' } );
  6471. }
  6472. };
  6473. THREE.EventDispatcher.prototype.apply( THREE.Geometry.prototype );
  6474. THREE.GeometryIdCount = 0;
  6475. // File:src/core/DirectGeometry.js
  6476. /**
  6477. * @author mrdoob / http://mrdoob.com/
  6478. */
  6479. THREE.DirectGeometry = function () {
  6480. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  6481. this.uuid = THREE.Math.generateUUID();
  6482. this.name = '';
  6483. this.type = 'DirectGeometry';
  6484. this.indices = [];
  6485. this.vertices = [];
  6486. this.normals = [];
  6487. this.colors = [];
  6488. this.uvs = [];
  6489. this.uvs2 = [];
  6490. this.groups = [];
  6491. this.morphTargets = {};
  6492. this.skinWeights = [];
  6493. this.skinIndices = [];
  6494. // this.lineDistances = [];
  6495. this.boundingBox = null;
  6496. this.boundingSphere = null;
  6497. // update flags
  6498. this.verticesNeedUpdate = false;
  6499. this.normalsNeedUpdate = false;
  6500. this.colorsNeedUpdate = false;
  6501. this.uvsNeedUpdate = false;
  6502. this.groupsNeedUpdate = false;
  6503. };
  6504. THREE.DirectGeometry.prototype = {
  6505. constructor: THREE.DirectGeometry,
  6506. computeBoundingBox: THREE.Geometry.prototype.computeBoundingBox,
  6507. computeBoundingSphere: THREE.Geometry.prototype.computeBoundingSphere,
  6508. computeFaceNormals: function () {
  6509. console.warn( 'THREE.DirectGeometry: computeFaceNormals() is not a method of this type of geometry.' );
  6510. },
  6511. computeVertexNormals: function () {
  6512. console.warn( 'THREE.DirectGeometry: computeVertexNormals() is not a method of this type of geometry.' );
  6513. },
  6514. computeGroups: function ( geometry ) {
  6515. var group;
  6516. var groups = [];
  6517. var materialIndex;
  6518. var faces = geometry.faces;
  6519. for ( var i = 0; i < faces.length; i ++ ) {
  6520. var face = faces[ i ];
  6521. // materials
  6522. if ( face.materialIndex !== materialIndex ) {
  6523. materialIndex = face.materialIndex;
  6524. if ( group !== undefined ) {
  6525. group.count = ( i * 3 ) - group.start;
  6526. groups.push( group );
  6527. }
  6528. group = {
  6529. start: i * 3,
  6530. materialIndex: materialIndex
  6531. };
  6532. }
  6533. }
  6534. if ( group !== undefined ) {
  6535. group.count = ( i * 3 ) - group.start;
  6536. groups.push( group );
  6537. }
  6538. this.groups = groups;
  6539. },
  6540. fromGeometry: function ( geometry ) {
  6541. var faces = geometry.faces;
  6542. var vertices = geometry.vertices;
  6543. var faceVertexUvs = geometry.faceVertexUvs;
  6544. var hasFaceVertexUv = faceVertexUvs[ 0 ] && faceVertexUvs[ 0 ].length > 0;
  6545. var hasFaceVertexUv2 = faceVertexUvs[ 1 ] && faceVertexUvs[ 1 ].length > 0;
  6546. // morphs
  6547. var morphTargets = geometry.morphTargets;
  6548. var morphTargetsLength = morphTargets.length;
  6549. var morphTargetsPosition;
  6550. if ( morphTargetsLength > 0 ) {
  6551. morphTargetsPosition = [];
  6552. for ( var i = 0; i < morphTargetsLength; i ++ ) {
  6553. morphTargetsPosition[ i ] = [];
  6554. }
  6555. this.morphTargets.position = morphTargetsPosition;
  6556. }
  6557. var morphNormals = geometry.morphNormals;
  6558. var morphNormalsLength = morphNormals.length;
  6559. var morphTargetsNormal;
  6560. if ( morphNormalsLength > 0 ) {
  6561. morphTargetsNormal = [];
  6562. for ( var i = 0; i < morphNormalsLength; i ++ ) {
  6563. morphTargetsNormal[ i ] = [];
  6564. }
  6565. this.morphTargets.normal = morphTargetsNormal;
  6566. }
  6567. // skins
  6568. var skinIndices = geometry.skinIndices;
  6569. var skinWeights = geometry.skinWeights;
  6570. var hasSkinIndices = skinIndices.length === vertices.length;
  6571. var hasSkinWeights = skinWeights.length === vertices.length;
  6572. //
  6573. for ( var i = 0; i < faces.length; i ++ ) {
  6574. var face = faces[ i ];
  6575. this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] );
  6576. var vertexNormals = face.vertexNormals;
  6577. if ( vertexNormals.length === 3 ) {
  6578. this.normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
  6579. } else {
  6580. var normal = face.normal;
  6581. this.normals.push( normal, normal, normal );
  6582. }
  6583. var vertexColors = face.vertexColors;
  6584. if ( vertexColors.length === 3 ) {
  6585. this.colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
  6586. } else {
  6587. var color = face.color;
  6588. this.colors.push( color, color, color );
  6589. }
  6590. if ( hasFaceVertexUv === true ) {
  6591. var vertexUvs = faceVertexUvs[ 0 ][ i ];
  6592. if ( vertexUvs !== undefined ) {
  6593. this.uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6594. } else {
  6595. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', i );
  6596. this.uvs.push( new THREE.Vector2(), new THREE.Vector2(), new THREE.Vector2() );
  6597. }
  6598. }
  6599. if ( hasFaceVertexUv2 === true ) {
  6600. var vertexUvs = faceVertexUvs[ 1 ][ i ];
  6601. if ( vertexUvs !== undefined ) {
  6602. this.uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6603. } else {
  6604. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', i );
  6605. this.uvs2.push( new THREE.Vector2(), new THREE.Vector2(), new THREE.Vector2() );
  6606. }
  6607. }
  6608. // morphs
  6609. for ( var j = 0; j < morphTargetsLength; j ++ ) {
  6610. var morphTarget = morphTargets[ j ].vertices;
  6611. morphTargetsPosition[ j ].push( morphTarget[ face.a ], morphTarget[ face.b ], morphTarget[ face.c ] );
  6612. }
  6613. for ( var j = 0; j < morphNormalsLength; j ++ ) {
  6614. var morphNormal = morphNormals[ j ].vertexNormals[ i ];
  6615. morphTargetsNormal[ j ].push( morphNormal.a, morphNormal.b, morphNormal.c );
  6616. }
  6617. // skins
  6618. if ( hasSkinIndices ) {
  6619. this.skinIndices.push( skinIndices[ face.a ], skinIndices[ face.b ], skinIndices[ face.c ] );
  6620. }
  6621. if ( hasSkinWeights ) {
  6622. this.skinWeights.push( skinWeights[ face.a ], skinWeights[ face.b ], skinWeights[ face.c ] );
  6623. }
  6624. }
  6625. this.computeGroups( geometry );
  6626. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6627. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6628. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6629. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6630. this.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6631. return this;
  6632. },
  6633. dispose: function () {
  6634. this.dispatchEvent( { type: 'dispose' } );
  6635. }
  6636. };
  6637. THREE.EventDispatcher.prototype.apply( THREE.DirectGeometry.prototype );
  6638. // File:src/core/BufferGeometry.js
  6639. /**
  6640. * @author alteredq / http://alteredqualia.com/
  6641. * @author mrdoob / http://mrdoob.com/
  6642. */
  6643. THREE.BufferGeometry = function () {
  6644. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  6645. this.uuid = THREE.Math.generateUUID();
  6646. this.name = '';
  6647. this.type = 'BufferGeometry';
  6648. this.index = null;
  6649. this.attributes = {};
  6650. this.morphAttributes = {};
  6651. this.groups = [];
  6652. this.boundingBox = null;
  6653. this.boundingSphere = null;
  6654. this.drawRange = { start: 0, count: Infinity };
  6655. };
  6656. THREE.BufferGeometry.prototype = {
  6657. constructor: THREE.BufferGeometry,
  6658. getIndex: function () {
  6659. return this.index;
  6660. },
  6661. setIndex: function ( index ) {
  6662. this.index = index;
  6663. },
  6664. addAttribute: function ( name, attribute ) {
  6665. if ( attribute instanceof THREE.BufferAttribute === false && attribute instanceof THREE.InterleavedBufferAttribute === false ) {
  6666. console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
  6667. this.addAttribute( name, new THREE.BufferAttribute( arguments[ 1 ], arguments[ 2 ] ) );
  6668. return;
  6669. }
  6670. if ( name === 'index' ) {
  6671. console.warn( 'THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.' );
  6672. this.setIndex( attribute );
  6673. return;
  6674. }
  6675. this.attributes[ name ] = attribute;
  6676. return this;
  6677. },
  6678. getAttribute: function ( name ) {
  6679. return this.attributes[ name ];
  6680. },
  6681. removeAttribute: function ( name ) {
  6682. delete this.attributes[ name ];
  6683. return this;
  6684. },
  6685. addGroup: function ( start, count, materialIndex ) {
  6686. this.groups.push( {
  6687. start: start,
  6688. count: count,
  6689. materialIndex: materialIndex !== undefined ? materialIndex : 0
  6690. } );
  6691. },
  6692. clearGroups: function () {
  6693. this.groups = [];
  6694. },
  6695. setDrawRange: function ( start, count ) {
  6696. this.drawRange.start = start;
  6697. this.drawRange.count = count;
  6698. },
  6699. applyMatrix: function ( matrix ) {
  6700. var position = this.attributes.position;
  6701. if ( position !== undefined ) {
  6702. matrix.applyToVector3Array( position.array );
  6703. position.needsUpdate = true;
  6704. }
  6705. var normal = this.attributes.normal;
  6706. if ( normal !== undefined ) {
  6707. var normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  6708. normalMatrix.applyToVector3Array( normal.array );
  6709. normal.needsUpdate = true;
  6710. }
  6711. if ( this.boundingBox !== null ) {
  6712. this.computeBoundingBox();
  6713. }
  6714. if ( this.boundingSphere !== null ) {
  6715. this.computeBoundingSphere();
  6716. }
  6717. return this;
  6718. },
  6719. rotateX: function () {
  6720. // rotate geometry around world x-axis
  6721. var m1;
  6722. return function rotateX( angle ) {
  6723. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6724. m1.makeRotationX( angle );
  6725. this.applyMatrix( m1 );
  6726. return this;
  6727. };
  6728. }(),
  6729. rotateY: function () {
  6730. // rotate geometry around world y-axis
  6731. var m1;
  6732. return function rotateY( angle ) {
  6733. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6734. m1.makeRotationY( angle );
  6735. this.applyMatrix( m1 );
  6736. return this;
  6737. };
  6738. }(),
  6739. rotateZ: function () {
  6740. // rotate geometry around world z-axis
  6741. var m1;
  6742. return function rotateZ( angle ) {
  6743. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6744. m1.makeRotationZ( angle );
  6745. this.applyMatrix( m1 );
  6746. return this;
  6747. };
  6748. }(),
  6749. translate: function () {
  6750. // translate geometry
  6751. var m1;
  6752. return function translate( x, y, z ) {
  6753. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6754. m1.makeTranslation( x, y, z );
  6755. this.applyMatrix( m1 );
  6756. return this;
  6757. };
  6758. }(),
  6759. scale: function () {
  6760. // scale geometry
  6761. var m1;
  6762. return function scale( x, y, z ) {
  6763. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6764. m1.makeScale( x, y, z );
  6765. this.applyMatrix( m1 );
  6766. return this;
  6767. };
  6768. }(),
  6769. lookAt: function () {
  6770. var obj;
  6771. return function lookAt( vector ) {
  6772. if ( obj === undefined ) obj = new THREE.Object3D();
  6773. obj.lookAt( vector );
  6774. obj.updateMatrix();
  6775. this.applyMatrix( obj.matrix );
  6776. };
  6777. }(),
  6778. center: function () {
  6779. this.computeBoundingBox();
  6780. var offset = this.boundingBox.center().negate();
  6781. this.translate( offset.x, offset.y, offset.z );
  6782. return offset;
  6783. },
  6784. setFromObject: function ( object ) {
  6785. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  6786. var geometry = object.geometry;
  6787. if ( object instanceof THREE.Points || object instanceof THREE.Line ) {
  6788. var positions = new THREE.Float32Attribute( geometry.vertices.length * 3, 3 );
  6789. var colors = new THREE.Float32Attribute( geometry.colors.length * 3, 3 );
  6790. this.addAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) );
  6791. this.addAttribute( 'color', colors.copyColorsArray( geometry.colors ) );
  6792. if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) {
  6793. var lineDistances = new THREE.Float32Attribute( geometry.lineDistances.length, 1 );
  6794. this.addAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) );
  6795. }
  6796. if ( geometry.boundingSphere !== null ) {
  6797. this.boundingSphere = geometry.boundingSphere.clone();
  6798. }
  6799. if ( geometry.boundingBox !== null ) {
  6800. this.boundingBox = geometry.boundingBox.clone();
  6801. }
  6802. } else if ( object instanceof THREE.Mesh ) {
  6803. if ( geometry instanceof THREE.Geometry ) {
  6804. this.fromGeometry( geometry );
  6805. }
  6806. }
  6807. return this;
  6808. },
  6809. updateFromObject: function ( object ) {
  6810. var geometry = object.geometry;
  6811. if ( object instanceof THREE.Mesh ) {
  6812. var direct = geometry.__directGeometry;
  6813. if ( direct === undefined ) {
  6814. return this.fromGeometry( geometry );
  6815. }
  6816. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6817. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6818. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6819. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6820. direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6821. geometry.verticesNeedUpdate = false;
  6822. geometry.normalsNeedUpdate = false;
  6823. geometry.colorsNeedUpdate = false;
  6824. geometry.uvsNeedUpdate = false;
  6825. geometry.groupsNeedUpdate = false;
  6826. geometry = direct;
  6827. }
  6828. if ( geometry.verticesNeedUpdate === true ) {
  6829. var attribute = this.attributes.position;
  6830. if ( attribute !== undefined ) {
  6831. attribute.copyVector3sArray( geometry.vertices );
  6832. attribute.needsUpdate = true;
  6833. }
  6834. geometry.verticesNeedUpdate = false;
  6835. }
  6836. if ( geometry.normalsNeedUpdate === true ) {
  6837. var attribute = this.attributes.normal;
  6838. if ( attribute !== undefined ) {
  6839. attribute.copyVector3sArray( geometry.normals );
  6840. attribute.needsUpdate = true;
  6841. }
  6842. geometry.normalsNeedUpdate = false;
  6843. }
  6844. if ( geometry.colorsNeedUpdate === true ) {
  6845. var attribute = this.attributes.color;
  6846. if ( attribute !== undefined ) {
  6847. attribute.copyColorsArray( geometry.colors );
  6848. attribute.needsUpdate = true;
  6849. }
  6850. geometry.colorsNeedUpdate = false;
  6851. }
  6852. if ( geometry.uvsNeedUpdate ) {
  6853. var attribute = this.attributes.uv;
  6854. if ( attribute !== undefined ) {
  6855. attribute.copyVector2sArray( geometry.uvs );
  6856. attribute.needsUpdate = true;
  6857. }
  6858. geometry.uvsNeedUpdate = false;
  6859. }
  6860. if ( geometry.lineDistancesNeedUpdate ) {
  6861. var attribute = this.attributes.lineDistance;
  6862. if ( attribute !== undefined ) {
  6863. attribute.copyArray( geometry.lineDistances );
  6864. attribute.needsUpdate = true;
  6865. }
  6866. geometry.lineDistancesNeedUpdate = false;
  6867. }
  6868. if ( geometry.groupsNeedUpdate ) {
  6869. geometry.computeGroups( object.geometry );
  6870. this.groups = geometry.groups;
  6871. geometry.groupsNeedUpdate = false;
  6872. }
  6873. return this;
  6874. },
  6875. fromGeometry: function ( geometry ) {
  6876. geometry.__directGeometry = new THREE.DirectGeometry().fromGeometry( geometry );
  6877. return this.fromDirectGeometry( geometry.__directGeometry );
  6878. },
  6879. fromDirectGeometry: function ( geometry ) {
  6880. var positions = new Float32Array( geometry.vertices.length * 3 );
  6881. this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) );
  6882. if ( geometry.normals.length > 0 ) {
  6883. var normals = new Float32Array( geometry.normals.length * 3 );
  6884. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) );
  6885. }
  6886. if ( geometry.colors.length > 0 ) {
  6887. var colors = new Float32Array( geometry.colors.length * 3 );
  6888. this.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors ) );
  6889. }
  6890. if ( geometry.uvs.length > 0 ) {
  6891. var uvs = new Float32Array( geometry.uvs.length * 2 );
  6892. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs ) );
  6893. }
  6894. if ( geometry.uvs2.length > 0 ) {
  6895. var uvs2 = new Float32Array( geometry.uvs2.length * 2 );
  6896. this.addAttribute( 'uv2', new THREE.BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 ) );
  6897. }
  6898. if ( geometry.indices.length > 0 ) {
  6899. var TypeArray = geometry.vertices.length > 65535 ? Uint32Array : Uint16Array;
  6900. var indices = new TypeArray( geometry.indices.length * 3 );
  6901. this.setIndex( new THREE.BufferAttribute( indices, 1 ).copyIndicesArray( geometry.indices ) );
  6902. }
  6903. // groups
  6904. this.groups = geometry.groups;
  6905. // morphs
  6906. for ( var name in geometry.morphTargets ) {
  6907. var array = [];
  6908. var morphTargets = geometry.morphTargets[ name ];
  6909. for ( var i = 0, l = morphTargets.length; i < l; i ++ ) {
  6910. var morphTarget = morphTargets[ i ];
  6911. var attribute = new THREE.Float32Attribute( morphTarget.length * 3, 3 );
  6912. array.push( attribute.copyVector3sArray( morphTarget ) );
  6913. }
  6914. this.morphAttributes[ name ] = array;
  6915. }
  6916. // skinning
  6917. if ( geometry.skinIndices.length > 0 ) {
  6918. var skinIndices = new THREE.Float32Attribute( geometry.skinIndices.length * 4, 4 );
  6919. this.addAttribute( 'skinIndex', skinIndices.copyVector4sArray( geometry.skinIndices ) );
  6920. }
  6921. if ( geometry.skinWeights.length > 0 ) {
  6922. var skinWeights = new THREE.Float32Attribute( geometry.skinWeights.length * 4, 4 );
  6923. this.addAttribute( 'skinWeight', skinWeights.copyVector4sArray( geometry.skinWeights ) );
  6924. }
  6925. //
  6926. if ( geometry.boundingSphere !== null ) {
  6927. this.boundingSphere = geometry.boundingSphere.clone();
  6928. }
  6929. if ( geometry.boundingBox !== null ) {
  6930. this.boundingBox = geometry.boundingBox.clone();
  6931. }
  6932. return this;
  6933. },
  6934. computeBoundingBox: function () {
  6935. if ( this.boundingBox === null ) {
  6936. this.boundingBox = new THREE.Box3();
  6937. }
  6938. var positions = this.attributes.position.array;
  6939. if ( positions !== undefined ) {
  6940. this.boundingBox.setFromArray( positions );
  6941. } else {
  6942. this.boundingBox.makeEmpty();
  6943. }
  6944. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  6945. console.error( 'THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  6946. }
  6947. },
  6948. computeBoundingSphere: function () {
  6949. var box = new THREE.Box3();
  6950. var vector = new THREE.Vector3();
  6951. return function computeBoundingSphere() {
  6952. if ( this.boundingSphere === null ) {
  6953. this.boundingSphere = new THREE.Sphere();
  6954. }
  6955. var positions = this.attributes.position.array;
  6956. if ( positions ) {
  6957. var center = this.boundingSphere.center;
  6958. box.setFromArray( positions );
  6959. box.center( center );
  6960. // hoping to find a boundingSphere with a radius smaller than the
  6961. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  6962. var maxRadiusSq = 0;
  6963. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  6964. vector.fromArray( positions, i );
  6965. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
  6966. }
  6967. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  6968. if ( isNaN( this.boundingSphere.radius ) ) {
  6969. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  6970. }
  6971. }
  6972. };
  6973. }(),
  6974. computeFaceNormals: function () {
  6975. // backwards compatibility
  6976. },
  6977. computeVertexNormals: function () {
  6978. var index = this.index;
  6979. var attributes = this.attributes;
  6980. var groups = this.groups;
  6981. if ( attributes.position ) {
  6982. var positions = attributes.position.array;
  6983. if ( attributes.normal === undefined ) {
  6984. this.addAttribute( 'normal', new THREE.BufferAttribute( new Float32Array( positions.length ), 3 ) );
  6985. } else {
  6986. // reset existing normals to zero
  6987. var array = attributes.normal.array;
  6988. for ( var i = 0, il = array.length; i < il; i ++ ) {
  6989. array[ i ] = 0;
  6990. }
  6991. }
  6992. var normals = attributes.normal.array;
  6993. var vA, vB, vC,
  6994. pA = new THREE.Vector3(),
  6995. pB = new THREE.Vector3(),
  6996. pC = new THREE.Vector3(),
  6997. cb = new THREE.Vector3(),
  6998. ab = new THREE.Vector3();
  6999. // indexed elements
  7000. if ( index ) {
  7001. var indices = index.array;
  7002. if ( groups.length === 0 ) {
  7003. this.addGroup( 0, indices.length );
  7004. }
  7005. for ( var j = 0, jl = groups.length; j < jl; ++ j ) {
  7006. var group = groups[ j ];
  7007. var start = group.start;
  7008. var count = group.count;
  7009. for ( var i = start, il = start + count; i < il; i += 3 ) {
  7010. vA = indices[ i + 0 ] * 3;
  7011. vB = indices[ i + 1 ] * 3;
  7012. vC = indices[ i + 2 ] * 3;
  7013. pA.fromArray( positions, vA );
  7014. pB.fromArray( positions, vB );
  7015. pC.fromArray( positions, vC );
  7016. cb.subVectors( pC, pB );
  7017. ab.subVectors( pA, pB );
  7018. cb.cross( ab );
  7019. normals[ vA ] += cb.x;
  7020. normals[ vA + 1 ] += cb.y;
  7021. normals[ vA + 2 ] += cb.z;
  7022. normals[ vB ] += cb.x;
  7023. normals[ vB + 1 ] += cb.y;
  7024. normals[ vB + 2 ] += cb.z;
  7025. normals[ vC ] += cb.x;
  7026. normals[ vC + 1 ] += cb.y;
  7027. normals[ vC + 2 ] += cb.z;
  7028. }
  7029. }
  7030. } else {
  7031. // non-indexed elements (unconnected triangle soup)
  7032. for ( var i = 0, il = positions.length; i < il; i += 9 ) {
  7033. pA.fromArray( positions, i );
  7034. pB.fromArray( positions, i + 3 );
  7035. pC.fromArray( positions, i + 6 );
  7036. cb.subVectors( pC, pB );
  7037. ab.subVectors( pA, pB );
  7038. cb.cross( ab );
  7039. normals[ i ] = cb.x;
  7040. normals[ i + 1 ] = cb.y;
  7041. normals[ i + 2 ] = cb.z;
  7042. normals[ i + 3 ] = cb.x;
  7043. normals[ i + 4 ] = cb.y;
  7044. normals[ i + 5 ] = cb.z;
  7045. normals[ i + 6 ] = cb.x;
  7046. normals[ i + 7 ] = cb.y;
  7047. normals[ i + 8 ] = cb.z;
  7048. }
  7049. }
  7050. this.normalizeNormals();
  7051. attributes.normal.needsUpdate = true;
  7052. }
  7053. },
  7054. merge: function ( geometry, offset ) {
  7055. if ( geometry instanceof THREE.BufferGeometry === false ) {
  7056. console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
  7057. return;
  7058. }
  7059. if ( offset === undefined ) offset = 0;
  7060. var attributes = this.attributes;
  7061. for ( var key in attributes ) {
  7062. if ( geometry.attributes[ key ] === undefined ) continue;
  7063. var attribute1 = attributes[ key ];
  7064. var attributeArray1 = attribute1.array;
  7065. var attribute2 = geometry.attributes[ key ];
  7066. var attributeArray2 = attribute2.array;
  7067. var attributeSize = attribute2.itemSize;
  7068. for ( var i = 0, j = attributeSize * offset; i < attributeArray2.length; i ++, j ++ ) {
  7069. attributeArray1[ j ] = attributeArray2[ i ];
  7070. }
  7071. }
  7072. return this;
  7073. },
  7074. normalizeNormals: function () {
  7075. var normals = this.attributes.normal.array;
  7076. var x, y, z, n;
  7077. for ( var i = 0, il = normals.length; i < il; i += 3 ) {
  7078. x = normals[ i ];
  7079. y = normals[ i + 1 ];
  7080. z = normals[ i + 2 ];
  7081. n = 1.0 / Math.sqrt( x * x + y * y + z * z );
  7082. normals[ i ] *= n;
  7083. normals[ i + 1 ] *= n;
  7084. normals[ i + 2 ] *= n;
  7085. }
  7086. },
  7087. toNonIndexed: function () {
  7088. if ( this.index === null ) {
  7089. console.warn( 'THREE.BufferGeometry.toNonIndexed(): Geometry is already non-indexed.' );
  7090. return this;
  7091. }
  7092. var geometry2 = new THREE.BufferGeometry();
  7093. var indices = this.index.array;
  7094. var attributes = this.attributes;
  7095. for ( var name in attributes ) {
  7096. var attribute = attributes[ name ];
  7097. var array = attribute.array;
  7098. var itemSize = attribute.itemSize;
  7099. var array2 = new array.constructor( indices.length * itemSize );
  7100. var index = 0, index2 = 0;
  7101. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  7102. index = indices[ i ] * itemSize;
  7103. for ( var j = 0; j < itemSize; j ++ ) {
  7104. array2[ index2 ++ ] = array[ index ++ ];
  7105. }
  7106. }
  7107. geometry2.addAttribute( name, new THREE.BufferAttribute( array2, itemSize ) );
  7108. }
  7109. return geometry2;
  7110. },
  7111. toJSON: function () {
  7112. var data = {
  7113. metadata: {
  7114. version: 4.4,
  7115. type: 'BufferGeometry',
  7116. generator: 'BufferGeometry.toJSON'
  7117. }
  7118. };
  7119. // standard BufferGeometry serialization
  7120. data.uuid = this.uuid;
  7121. data.type = this.type;
  7122. if ( this.name !== '' ) data.name = this.name;
  7123. if ( this.parameters !== undefined ) {
  7124. var parameters = this.parameters;
  7125. for ( var key in parameters ) {
  7126. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  7127. }
  7128. return data;
  7129. }
  7130. data.data = { attributes: {} };
  7131. var index = this.index;
  7132. if ( index !== null ) {
  7133. var array = Array.prototype.slice.call( index.array );
  7134. data.data.index = {
  7135. type: index.array.constructor.name,
  7136. array: array
  7137. };
  7138. }
  7139. var attributes = this.attributes;
  7140. for ( var key in attributes ) {
  7141. var attribute = attributes[ key ];
  7142. var array = Array.prototype.slice.call( attribute.array );
  7143. data.data.attributes[ key ] = {
  7144. itemSize: attribute.itemSize,
  7145. type: attribute.array.constructor.name,
  7146. array: array,
  7147. normalized: attribute.normalized
  7148. };
  7149. }
  7150. var groups = this.groups;
  7151. if ( groups.length > 0 ) {
  7152. data.data.groups = JSON.parse( JSON.stringify( groups ) );
  7153. }
  7154. var boundingSphere = this.boundingSphere;
  7155. if ( boundingSphere !== null ) {
  7156. data.data.boundingSphere = {
  7157. center: boundingSphere.center.toArray(),
  7158. radius: boundingSphere.radius
  7159. };
  7160. }
  7161. return data;
  7162. },
  7163. clone: function () {
  7164. /*
  7165. // Handle primitives
  7166. var parameters = this.parameters;
  7167. if ( parameters !== undefined ) {
  7168. var values = [];
  7169. for ( var key in parameters ) {
  7170. values.push( parameters[ key ] );
  7171. }
  7172. var geometry = Object.create( this.constructor.prototype );
  7173. this.constructor.apply( geometry, values );
  7174. return geometry;
  7175. }
  7176. return new this.constructor().copy( this );
  7177. */
  7178. return new THREE.BufferGeometry().copy( this );
  7179. },
  7180. copy: function ( source ) {
  7181. var index = source.index;
  7182. if ( index !== null ) {
  7183. this.setIndex( index.clone() );
  7184. }
  7185. var attributes = source.attributes;
  7186. for ( var name in attributes ) {
  7187. var attribute = attributes[ name ];
  7188. this.addAttribute( name, attribute.clone() );
  7189. }
  7190. var groups = source.groups;
  7191. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  7192. var group = groups[ i ];
  7193. this.addGroup( group.start, group.count, group.materialIndex );
  7194. }
  7195. return this;
  7196. },
  7197. dispose: function () {
  7198. this.dispatchEvent( { type: 'dispose' } );
  7199. }
  7200. };
  7201. THREE.EventDispatcher.prototype.apply( THREE.BufferGeometry.prototype );
  7202. THREE.BufferGeometry.MaxIndex = 65535;
  7203. // File:src/core/InstancedBufferGeometry.js
  7204. /**
  7205. * @author benaadams / https://twitter.com/ben_a_adams
  7206. */
  7207. THREE.InstancedBufferGeometry = function () {
  7208. THREE.BufferGeometry.call( this );
  7209. this.type = 'InstancedBufferGeometry';
  7210. this.maxInstancedCount = undefined;
  7211. };
  7212. THREE.InstancedBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  7213. THREE.InstancedBufferGeometry.prototype.constructor = THREE.InstancedBufferGeometry;
  7214. THREE.InstancedBufferGeometry.prototype.addGroup = function ( start, count, instances ) {
  7215. this.groups.push( {
  7216. start: start,
  7217. count: count,
  7218. instances: instances
  7219. } );
  7220. };
  7221. THREE.InstancedBufferGeometry.prototype.copy = function ( source ) {
  7222. var index = source.index;
  7223. if ( index !== null ) {
  7224. this.setIndex( index.clone() );
  7225. }
  7226. var attributes = source.attributes;
  7227. for ( var name in attributes ) {
  7228. var attribute = attributes[ name ];
  7229. this.addAttribute( name, attribute.clone() );
  7230. }
  7231. var groups = source.groups;
  7232. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  7233. var group = groups[ i ];
  7234. this.addGroup( group.start, group.count, group.instances );
  7235. }
  7236. return this;
  7237. };
  7238. THREE.EventDispatcher.prototype.apply( THREE.InstancedBufferGeometry.prototype );
  7239. // File:src/core/Uniform.js
  7240. /**
  7241. * @author mrdoob / http://mrdoob.com/
  7242. */
  7243. THREE.Uniform = function ( value ) {
  7244. if ( typeof value === 'string' ) {
  7245. console.warn( 'THREE.Uniform: Type parameter is no longer needed.' );
  7246. value = arguments[ 1 ];
  7247. }
  7248. this.value = value;
  7249. this.dynamic = false;
  7250. };
  7251. THREE.Uniform.prototype = {
  7252. constructor: THREE.Uniform,
  7253. onUpdate: function ( callback ) {
  7254. this.dynamic = true;
  7255. this.onUpdateCallback = callback;
  7256. return this;
  7257. }
  7258. };
  7259. // File:src/animation/AnimationClip.js
  7260. /**
  7261. *
  7262. * Reusable set of Tracks that represent an animation.
  7263. *
  7264. * @author Ben Houston / http://clara.io/
  7265. * @author David Sarno / http://lighthaus.us/
  7266. */
  7267. THREE.AnimationClip = function ( name, duration, tracks ) {
  7268. this.name = name || THREE.Math.generateUUID();
  7269. this.tracks = tracks;
  7270. this.duration = ( duration !== undefined ) ? duration : -1;
  7271. // this means it should figure out its duration by scanning the tracks
  7272. if ( this.duration < 0 ) {
  7273. this.resetDuration();
  7274. }
  7275. // maybe only do these on demand, as doing them here could potentially slow down loading
  7276. // but leaving these here during development as this ensures a lot of testing of these functions
  7277. this.trim();
  7278. this.optimize();
  7279. };
  7280. THREE.AnimationClip.prototype = {
  7281. constructor: THREE.AnimationClip,
  7282. resetDuration: function() {
  7283. var tracks = this.tracks,
  7284. duration = 0;
  7285. for ( var i = 0, n = tracks.length; i !== n; ++ i ) {
  7286. var track = this.tracks[ i ];
  7287. duration = Math.max(
  7288. duration, track.times[ track.times.length - 1 ] );
  7289. }
  7290. this.duration = duration;
  7291. },
  7292. trim: function() {
  7293. for ( var i = 0; i < this.tracks.length; i ++ ) {
  7294. this.tracks[ i ].trim( 0, this.duration );
  7295. }
  7296. return this;
  7297. },
  7298. optimize: function() {
  7299. for ( var i = 0; i < this.tracks.length; i ++ ) {
  7300. this.tracks[ i ].optimize();
  7301. }
  7302. return this;
  7303. }
  7304. };
  7305. // Static methods:
  7306. Object.assign( THREE.AnimationClip, {
  7307. parse: function( json ) {
  7308. var tracks = [],
  7309. jsonTracks = json.tracks,
  7310. frameTime = 1.0 / ( json.fps || 1.0 );
  7311. for ( var i = 0, n = jsonTracks.length; i !== n; ++ i ) {
  7312. tracks.push( THREE.KeyframeTrack.parse( jsonTracks[ i ] ).scale( frameTime ) );
  7313. }
  7314. return new THREE.AnimationClip( json.name, json.duration, tracks );
  7315. },
  7316. toJSON: function( clip ) {
  7317. var tracks = [],
  7318. clipTracks = clip.tracks;
  7319. var json = {
  7320. 'name': clip.name,
  7321. 'duration': clip.duration,
  7322. 'tracks': tracks
  7323. };
  7324. for ( var i = 0, n = clipTracks.length; i !== n; ++ i ) {
  7325. tracks.push( THREE.KeyframeTrack.toJSON( clipTracks[ i ] ) );
  7326. }
  7327. return json;
  7328. },
  7329. CreateFromMorphTargetSequence: function( name, morphTargetSequence, fps, noLoop ) {
  7330. var numMorphTargets = morphTargetSequence.length;
  7331. var tracks = [];
  7332. for ( var i = 0; i < numMorphTargets; i ++ ) {
  7333. var times = [];
  7334. var values = [];
  7335. times.push(
  7336. ( i + numMorphTargets - 1 ) % numMorphTargets,
  7337. i,
  7338. ( i + 1 ) % numMorphTargets );
  7339. values.push( 0, 1, 0 );
  7340. var order = THREE.AnimationUtils.getKeyframeOrder( times );
  7341. times = THREE.AnimationUtils.sortedArray( times, 1, order );
  7342. values = THREE.AnimationUtils.sortedArray( values, 1, order );
  7343. // if there is a key at the first frame, duplicate it as the
  7344. // last frame as well for perfect loop.
  7345. if ( ! noLoop && times[ 0 ] === 0 ) {
  7346. times.push( numMorphTargets );
  7347. values.push( values[ 0 ] );
  7348. }
  7349. tracks.push(
  7350. new THREE.NumberKeyframeTrack(
  7351. '.morphTargetInfluences[' + morphTargetSequence[ i ].name + ']',
  7352. times, values
  7353. ).scale( 1.0 / fps ) );
  7354. }
  7355. return new THREE.AnimationClip( name, -1, tracks );
  7356. },
  7357. findByName: function( clipArray, name ) {
  7358. for ( var i = 0; i < clipArray.length; i ++ ) {
  7359. if ( clipArray[ i ].name === name ) {
  7360. return clipArray[ i ];
  7361. }
  7362. }
  7363. return null;
  7364. },
  7365. CreateClipsFromMorphTargetSequences: function( morphTargets, fps, noLoop ) {
  7366. var animationToMorphTargets = {};
  7367. // tested with https://regex101.com/ on trick sequences
  7368. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  7369. var pattern = /^([\w-]*?)([\d]+)$/;
  7370. // sort morph target names into animation groups based
  7371. // patterns like Walk_001, Walk_002, Run_001, Run_002
  7372. for ( var i = 0, il = morphTargets.length; i < il; i ++ ) {
  7373. var morphTarget = morphTargets[ i ];
  7374. var parts = morphTarget.name.match( pattern );
  7375. if ( parts && parts.length > 1 ) {
  7376. var name = parts[ 1 ];
  7377. var animationMorphTargets = animationToMorphTargets[ name ];
  7378. if ( ! animationMorphTargets ) {
  7379. animationToMorphTargets[ name ] = animationMorphTargets = [];
  7380. }
  7381. animationMorphTargets.push( morphTarget );
  7382. }
  7383. }
  7384. var clips = [];
  7385. for ( var name in animationToMorphTargets ) {
  7386. clips.push( THREE.AnimationClip.CreateFromMorphTargetSequence( name, animationToMorphTargets[ name ], fps, noLoop ) );
  7387. }
  7388. return clips;
  7389. },
  7390. // parse the animation.hierarchy format
  7391. parseAnimation: function( animation, bones, nodeName ) {
  7392. if ( ! animation ) {
  7393. console.error( " no animation in JSONLoader data" );
  7394. return null;
  7395. }
  7396. var addNonemptyTrack = function(
  7397. trackType, trackName, animationKeys, propertyName, destTracks ) {
  7398. // only return track if there are actually keys.
  7399. if ( animationKeys.length !== 0 ) {
  7400. var times = [];
  7401. var values = [];
  7402. THREE.AnimationUtils.flattenJSON(
  7403. animationKeys, times, values, propertyName );
  7404. // empty keys are filtered out, so check again
  7405. if ( times.length !== 0 ) {
  7406. destTracks.push( new trackType( trackName, times, values ) );
  7407. }
  7408. }
  7409. };
  7410. var tracks = [];
  7411. var clipName = animation.name || 'default';
  7412. // automatic length determination in AnimationClip.
  7413. var duration = animation.length || -1;
  7414. var fps = animation.fps || 30;
  7415. var hierarchyTracks = animation.hierarchy || [];
  7416. for ( var h = 0; h < hierarchyTracks.length; h ++ ) {
  7417. var animationKeys = hierarchyTracks[ h ].keys;
  7418. // skip empty tracks
  7419. if ( ! animationKeys || animationKeys.length === 0 ) continue;
  7420. // process morph targets in a way exactly compatible
  7421. // with AnimationHandler.init( animation )
  7422. if ( animationKeys[0].morphTargets ) {
  7423. // figure out all morph targets used in this track
  7424. var morphTargetNames = {};
  7425. for ( var k = 0; k < animationKeys.length; k ++ ) {
  7426. if ( animationKeys[k].morphTargets ) {
  7427. for ( var m = 0; m < animationKeys[k].morphTargets.length; m ++ ) {
  7428. morphTargetNames[ animationKeys[k].morphTargets[m] ] = -1;
  7429. }
  7430. }
  7431. }
  7432. // create a track for each morph target with all zero
  7433. // morphTargetInfluences except for the keys in which
  7434. // the morphTarget is named.
  7435. for ( var morphTargetName in morphTargetNames ) {
  7436. var times = [];
  7437. var values = [];
  7438. for ( var m = 0;
  7439. m !== animationKeys[k].morphTargets.length; ++ m ) {
  7440. var animationKey = animationKeys[k];
  7441. times.push( animationKey.time );
  7442. values.push( ( animationKey.morphTarget === morphTargetName ) ? 1 : 0 );
  7443. }
  7444. tracks.push( new THREE.NumberKeyframeTrack(
  7445. '.morphTargetInfluence[' + morphTargetName + ']', times, values ) );
  7446. }
  7447. duration = morphTargetNames.length * ( fps || 1.0 );
  7448. } else {
  7449. // ...assume skeletal animation
  7450. var boneName = '.bones[' + bones[ h ].name + ']';
  7451. addNonemptyTrack(
  7452. THREE.VectorKeyframeTrack, boneName + '.position',
  7453. animationKeys, 'pos', tracks );
  7454. addNonemptyTrack(
  7455. THREE.QuaternionKeyframeTrack, boneName + '.quaternion',
  7456. animationKeys, 'rot', tracks );
  7457. addNonemptyTrack(
  7458. THREE.VectorKeyframeTrack, boneName + '.scale',
  7459. animationKeys, 'scl', tracks );
  7460. }
  7461. }
  7462. if ( tracks.length === 0 ) {
  7463. return null;
  7464. }
  7465. var clip = new THREE.AnimationClip( clipName, duration, tracks );
  7466. return clip;
  7467. }
  7468. } );
  7469. // File:src/animation/AnimationMixer.js
  7470. /**
  7471. *
  7472. * Player for AnimationClips.
  7473. *
  7474. *
  7475. * @author Ben Houston / http://clara.io/
  7476. * @author David Sarno / http://lighthaus.us/
  7477. * @author tschw
  7478. */
  7479. THREE.AnimationMixer = function( root ) {
  7480. this._root = root;
  7481. this._initMemoryManager();
  7482. this._accuIndex = 0;
  7483. this.time = 0;
  7484. this.timeScale = 1.0;
  7485. };
  7486. THREE.AnimationMixer.prototype = {
  7487. constructor: THREE.AnimationMixer,
  7488. // return an action for a clip optionally using a custom root target
  7489. // object (this method allocates a lot of dynamic memory in case a
  7490. // previously unknown clip/root combination is specified)
  7491. clipAction: function( clip, optionalRoot ) {
  7492. var root = optionalRoot || this._root,
  7493. rootUuid = root.uuid,
  7494. clipName = ( typeof clip === 'string' ) ? clip : clip.name,
  7495. clipObject = ( clip !== clipName ) ? clip : null,
  7496. actionsForClip = this._actionsByClip[ clipName ],
  7497. prototypeAction;
  7498. if ( actionsForClip !== undefined ) {
  7499. var existingAction =
  7500. actionsForClip.actionByRoot[ rootUuid ];
  7501. if ( existingAction !== undefined ) {
  7502. return existingAction;
  7503. }
  7504. // we know the clip, so we don't have to parse all
  7505. // the bindings again but can just copy
  7506. prototypeAction = actionsForClip.knownActions[ 0 ];
  7507. // also, take the clip from the prototype action
  7508. clipObject = prototypeAction._clip;
  7509. if ( clip !== clipName && clip !== clipObject ) {
  7510. throw new Error(
  7511. "Different clips with the same name detected!" );
  7512. }
  7513. }
  7514. // clip must be known when specified via string
  7515. if ( clipObject === null ) return null;
  7516. // allocate all resources required to run it
  7517. var newAction = new THREE.
  7518. AnimationMixer._Action( this, clipObject, optionalRoot );
  7519. this._bindAction( newAction, prototypeAction );
  7520. // and make the action known to the memory manager
  7521. this._addInactiveAction( newAction, clipName, rootUuid );
  7522. return newAction;
  7523. },
  7524. // get an existing action
  7525. existingAction: function( clip, optionalRoot ) {
  7526. var root = optionalRoot || this._root,
  7527. rootUuid = root.uuid,
  7528. clipName = ( typeof clip === 'string' ) ? clip : clip.name,
  7529. actionsForClip = this._actionsByClip[ clipName ];
  7530. if ( actionsForClip !== undefined ) {
  7531. return actionsForClip.actionByRoot[ rootUuid ] || null;
  7532. }
  7533. return null;
  7534. },
  7535. // deactivates all previously scheduled actions
  7536. stopAllAction: function() {
  7537. var actions = this._actions,
  7538. nActions = this._nActiveActions,
  7539. bindings = this._bindings,
  7540. nBindings = this._nActiveBindings;
  7541. this._nActiveActions = 0;
  7542. this._nActiveBindings = 0;
  7543. for ( var i = 0; i !== nActions; ++ i ) {
  7544. actions[ i ].reset();
  7545. }
  7546. for ( var i = 0; i !== nBindings; ++ i ) {
  7547. bindings[ i ].useCount = 0;
  7548. }
  7549. return this;
  7550. },
  7551. // advance the time and update apply the animation
  7552. update: function( deltaTime ) {
  7553. deltaTime *= this.timeScale;
  7554. var actions = this._actions,
  7555. nActions = this._nActiveActions,
  7556. time = this.time += deltaTime,
  7557. timeDirection = Math.sign( deltaTime ),
  7558. accuIndex = this._accuIndex ^= 1;
  7559. // run active actions
  7560. for ( var i = 0; i !== nActions; ++ i ) {
  7561. var action = actions[ i ];
  7562. if ( action.enabled ) {
  7563. action._update( time, deltaTime, timeDirection, accuIndex );
  7564. }
  7565. }
  7566. // update scene graph
  7567. var bindings = this._bindings,
  7568. nBindings = this._nActiveBindings;
  7569. for ( var i = 0; i !== nBindings; ++ i ) {
  7570. bindings[ i ].apply( accuIndex );
  7571. }
  7572. return this;
  7573. },
  7574. // return this mixer's root target object
  7575. getRoot: function() {
  7576. return this._root;
  7577. },
  7578. // free all resources specific to a particular clip
  7579. uncacheClip: function( clip ) {
  7580. var actions = this._actions,
  7581. clipName = clip.name,
  7582. actionsByClip = this._actionsByClip,
  7583. actionsForClip = actionsByClip[ clipName ];
  7584. if ( actionsForClip !== undefined ) {
  7585. // note: just calling _removeInactiveAction would mess up the
  7586. // iteration state and also require updating the state we can
  7587. // just throw away
  7588. var actionsToRemove = actionsForClip.knownActions;
  7589. for ( var i = 0, n = actionsToRemove.length; i !== n; ++ i ) {
  7590. var action = actionsToRemove[ i ];
  7591. this._deactivateAction( action );
  7592. var cacheIndex = action._cacheIndex,
  7593. lastInactiveAction = actions[ actions.length - 1 ];
  7594. action._cacheIndex = null;
  7595. action._byClipCacheIndex = null;
  7596. lastInactiveAction._cacheIndex = cacheIndex;
  7597. actions[ cacheIndex ] = lastInactiveAction;
  7598. actions.pop();
  7599. this._removeInactiveBindingsForAction( action );
  7600. }
  7601. delete actionsByClip[ clipName ];
  7602. }
  7603. },
  7604. // free all resources specific to a particular root target object
  7605. uncacheRoot: function( root ) {
  7606. var rootUuid = root.uuid,
  7607. actionsByClip = this._actionsByClip;
  7608. for ( var clipName in actionsByClip ) {
  7609. var actionByRoot = actionsByClip[ clipName ].actionByRoot,
  7610. action = actionByRoot[ rootUuid ];
  7611. if ( action !== undefined ) {
  7612. this._deactivateAction( action );
  7613. this._removeInactiveAction( action );
  7614. }
  7615. }
  7616. var bindingsByRoot = this._bindingsByRootAndName,
  7617. bindingByName = bindingsByRoot[ rootUuid ];
  7618. if ( bindingByName !== undefined ) {
  7619. for ( var trackName in bindingByName ) {
  7620. var binding = bindingByName[ trackName ];
  7621. binding.restoreOriginalState();
  7622. this._removeInactiveBinding( binding );
  7623. }
  7624. }
  7625. },
  7626. // remove a targeted clip from the cache
  7627. uncacheAction: function( clip, optionalRoot ) {
  7628. var action = this.existingAction( clip, optionalRoot );
  7629. if ( action !== null ) {
  7630. this._deactivateAction( action );
  7631. this._removeInactiveAction( action );
  7632. }
  7633. }
  7634. };
  7635. THREE.EventDispatcher.prototype.apply( THREE.AnimationMixer.prototype );
  7636. THREE.AnimationMixer._Action =
  7637. function( mixer, clip, localRoot ) {
  7638. this._mixer = mixer;
  7639. this._clip = clip;
  7640. this._localRoot = localRoot || null;
  7641. var tracks = clip.tracks,
  7642. nTracks = tracks.length,
  7643. interpolants = new Array( nTracks );
  7644. var interpolantSettings = {
  7645. endingStart: THREE.ZeroCurvatureEnding,
  7646. endingEnd: THREE.ZeroCurvatureEnding
  7647. };
  7648. for ( var i = 0; i !== nTracks; ++ i ) {
  7649. var interpolant = tracks[ i ].createInterpolant( null );
  7650. interpolants[ i ] = interpolant;
  7651. interpolant.settings = interpolantSettings;
  7652. }
  7653. this._interpolantSettings = interpolantSettings;
  7654. this._interpolants = interpolants; // bound by the mixer
  7655. // inside: PropertyMixer (managed by the mixer)
  7656. this._propertyBindings = new Array( nTracks );
  7657. this._cacheIndex = null; // for the memory manager
  7658. this._byClipCacheIndex = null; // for the memory manager
  7659. this._timeScaleInterpolant = null;
  7660. this._weightInterpolant = null;
  7661. this.loop = THREE.LoopRepeat;
  7662. this._loopCount = -1;
  7663. // global mixer time when the action is to be started
  7664. // it's set back to 'null' upon start of the action
  7665. this._startTime = null;
  7666. // scaled local time of the action
  7667. // gets clamped or wrapped to 0..clip.duration according to loop
  7668. this.time = 0;
  7669. this.timeScale = 1;
  7670. this._effectiveTimeScale = 1;
  7671. this.weight = 1;
  7672. this._effectiveWeight = 1;
  7673. this.repetitions = Infinity; // no. of repetitions when looping
  7674. this.paused = false; // false -> zero effective time scale
  7675. this.enabled = true; // true -> zero effective weight
  7676. this.clampWhenFinished = false; // keep feeding the last frame?
  7677. this.zeroSlopeAtStart = true; // for smooth interpolation w/o separate
  7678. this.zeroSlopeAtEnd = true; // clips for start, loop and end
  7679. };
  7680. THREE.AnimationMixer._Action.prototype = {
  7681. constructor: THREE.AnimationMixer._Action,
  7682. // State & Scheduling
  7683. play: function() {
  7684. this._mixer._activateAction( this );
  7685. return this;
  7686. },
  7687. stop: function() {
  7688. this._mixer._deactivateAction( this );
  7689. return this.reset();
  7690. },
  7691. reset: function() {
  7692. this.paused = false;
  7693. this.enabled = true;
  7694. this.time = 0; // restart clip
  7695. this._loopCount = -1; // forget previous loops
  7696. this._startTime = null; // forget scheduling
  7697. return this.stopFading().stopWarping();
  7698. },
  7699. isRunning: function() {
  7700. var start = this._startTime;
  7701. return this.enabled && ! this.paused && this.timeScale !== 0 &&
  7702. this._startTime === null && this._mixer._isActiveAction( this );
  7703. },
  7704. // return true when play has been called
  7705. isScheduled: function() {
  7706. return this._mixer._isActiveAction( this );
  7707. },
  7708. startAt: function( time ) {
  7709. this._startTime = time;
  7710. return this;
  7711. },
  7712. setLoop: function( mode, repetitions ) {
  7713. this.loop = mode;
  7714. this.repetitions = repetitions;
  7715. return this;
  7716. },
  7717. // Weight
  7718. // set the weight stopping any scheduled fading
  7719. // although .enabled = false yields an effective weight of zero, this
  7720. // method does *not* change .enabled, because it would be confusing
  7721. setEffectiveWeight: function( weight ) {
  7722. this.weight = weight;
  7723. // note: same logic as when updated at runtime
  7724. this._effectiveWeight = this.enabled ? weight : 0;
  7725. return this.stopFading();
  7726. },
  7727. // return the weight considering fading and .enabled
  7728. getEffectiveWeight: function() {
  7729. return this._effectiveWeight;
  7730. },
  7731. fadeIn: function( duration ) {
  7732. return this._scheduleFading( duration, 0, 1 );
  7733. },
  7734. fadeOut: function( duration ) {
  7735. return this._scheduleFading( duration, 1, 0 );
  7736. },
  7737. crossFadeFrom: function( fadeOutAction, duration, warp ) {
  7738. var mixer = this._mixer;
  7739. fadeOutAction.fadeOut( duration );
  7740. this.fadeIn( duration );
  7741. if( warp ) {
  7742. var fadeInDuration = this._clip.duration,
  7743. fadeOutDuration = fadeOutAction._clip.duration,
  7744. startEndRatio = fadeOutDuration / fadeInDuration,
  7745. endStartRatio = fadeInDuration / fadeOutDuration;
  7746. fadeOutAction.warp( 1.0, startEndRatio, duration );
  7747. this.warp( endStartRatio, 1.0, duration );
  7748. }
  7749. return this;
  7750. },
  7751. crossFadeTo: function( fadeInAction, duration, warp ) {
  7752. return fadeInAction.crossFadeFrom( this, duration, warp );
  7753. },
  7754. stopFading: function() {
  7755. var weightInterpolant = this._weightInterpolant;
  7756. if ( weightInterpolant !== null ) {
  7757. this._weightInterpolant = null;
  7758. this._mixer._takeBackControlInterpolant( weightInterpolant );
  7759. }
  7760. return this;
  7761. },
  7762. // Time Scale Control
  7763. // set the weight stopping any scheduled warping
  7764. // although .paused = true yields an effective time scale of zero, this
  7765. // method does *not* change .paused, because it would be confusing
  7766. setEffectiveTimeScale: function( timeScale ) {
  7767. this.timeScale = timeScale;
  7768. this._effectiveTimeScale = this.paused ? 0 :timeScale;
  7769. return this.stopWarping();
  7770. },
  7771. // return the time scale considering warping and .paused
  7772. getEffectiveTimeScale: function() {
  7773. return this._effectiveTimeScale;
  7774. },
  7775. setDuration: function( duration ) {
  7776. this.timeScale = this._clip.duration / duration;
  7777. return this.stopWarping();
  7778. },
  7779. syncWith: function( action ) {
  7780. this.time = action.time;
  7781. this.timeScale = action.timeScale;
  7782. return this.stopWarping();
  7783. },
  7784. halt: function( duration ) {
  7785. return this.warp( this._currentTimeScale, 0, duration );
  7786. },
  7787. warp: function( startTimeScale, endTimeScale, duration ) {
  7788. var mixer = this._mixer, now = mixer.time,
  7789. interpolant = this._timeScaleInterpolant,
  7790. timeScale = this.timeScale;
  7791. if ( interpolant === null ) {
  7792. interpolant = mixer._lendControlInterpolant(),
  7793. this._timeScaleInterpolant = interpolant;
  7794. }
  7795. var times = interpolant.parameterPositions,
  7796. values = interpolant.sampleValues;
  7797. times[ 0 ] = now;
  7798. times[ 1 ] = now + duration;
  7799. values[ 0 ] = startTimeScale / timeScale;
  7800. values[ 1 ] = endTimeScale / timeScale;
  7801. return this;
  7802. },
  7803. stopWarping: function() {
  7804. var timeScaleInterpolant = this._timeScaleInterpolant;
  7805. if ( timeScaleInterpolant !== null ) {
  7806. this._timeScaleInterpolant = null;
  7807. this._mixer._takeBackControlInterpolant( timeScaleInterpolant );
  7808. }
  7809. return this;
  7810. },
  7811. // Object Accessors
  7812. getMixer: function() {
  7813. return this._mixer;
  7814. },
  7815. getClip: function() {
  7816. return this._clip;
  7817. },
  7818. getRoot: function() {
  7819. return this._localRoot || this._mixer._root;
  7820. },
  7821. // Interna
  7822. _update: function( time, deltaTime, timeDirection, accuIndex ) {
  7823. // called by the mixer
  7824. var startTime = this._startTime;
  7825. if ( startTime !== null ) {
  7826. // check for scheduled start of action
  7827. var timeRunning = ( time - startTime ) * timeDirection;
  7828. if ( timeRunning < 0 || timeDirection === 0 ) {
  7829. return; // yet to come / don't decide when delta = 0
  7830. }
  7831. // start
  7832. this._startTime = null; // unschedule
  7833. deltaTime = timeDirection * timeRunning;
  7834. }
  7835. // apply time scale and advance time
  7836. deltaTime *= this._updateTimeScale( time );
  7837. var clipTime = this._updateTime( deltaTime );
  7838. // note: _updateTime may disable the action resulting in
  7839. // an effective weight of 0
  7840. var weight = this._updateWeight( time );
  7841. if ( weight > 0 ) {
  7842. var interpolants = this._interpolants;
  7843. var propertyMixers = this._propertyBindings;
  7844. for ( var j = 0, m = interpolants.length; j !== m; ++ j ) {
  7845. interpolants[ j ].evaluate( clipTime );
  7846. propertyMixers[ j ].accumulate( accuIndex, weight );
  7847. }
  7848. }
  7849. },
  7850. _updateWeight: function( time ) {
  7851. var weight = 0;
  7852. if ( this.enabled ) {
  7853. weight = this.weight;
  7854. var interpolant = this._weightInterpolant;
  7855. if ( interpolant !== null ) {
  7856. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  7857. weight *= interpolantValue;
  7858. if ( time > interpolant.parameterPositions[ 1 ] ) {
  7859. this.stopFading();
  7860. if ( interpolantValue === 0 ) {
  7861. // faded out, disable
  7862. this.enabled = false;
  7863. }
  7864. }
  7865. }
  7866. }
  7867. this._effectiveWeight = weight;
  7868. return weight;
  7869. },
  7870. _updateTimeScale: function( time ) {
  7871. var timeScale = 0;
  7872. if ( ! this.paused ) {
  7873. timeScale = this.timeScale;
  7874. var interpolant = this._timeScaleInterpolant;
  7875. if ( interpolant !== null ) {
  7876. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  7877. timeScale *= interpolantValue;
  7878. if ( time > interpolant.parameterPositions[ 1 ] ) {
  7879. this.stopWarping();
  7880. if ( timeScale === 0 ) {
  7881. // motion has halted, pause
  7882. this.pause = true;
  7883. } else {
  7884. // warp done - apply final time scale
  7885. this.timeScale = timeScale;
  7886. }
  7887. }
  7888. }
  7889. }
  7890. this._effectiveTimeScale = timeScale;
  7891. return timeScale;
  7892. },
  7893. _updateTime: function( deltaTime ) {
  7894. var time = this.time + deltaTime;
  7895. if ( deltaTime === 0 ) return time;
  7896. var duration = this._clip.duration,
  7897. loop = this.loop,
  7898. loopCount = this._loopCount;
  7899. if ( loop === THREE.LoopOnce ) {
  7900. if ( loopCount === -1 ) {
  7901. // just started
  7902. this.loopCount = 0;
  7903. this._setEndings( true, true, false );
  7904. }
  7905. handle_stop: {
  7906. if ( time >= duration ) {
  7907. time = duration;
  7908. } else if ( time < 0 ) {
  7909. time = 0;
  7910. } else break handle_stop;
  7911. if ( this.clampWhenFinished ) this.pause = true;
  7912. else this.enabled = false;
  7913. this._mixer.dispatchEvent( {
  7914. type: 'finished', action: this,
  7915. direction: deltaTime < 0 ? -1 : 1
  7916. } );
  7917. }
  7918. } else { // repetitive Repeat or PingPong
  7919. var pingPong = ( loop === THREE.LoopPingPong );
  7920. if ( loopCount === -1 ) {
  7921. // just started
  7922. if ( deltaTime >= 0 ) {
  7923. loopCount = 0;
  7924. this._setEndings(
  7925. true, this.repetitions === 0, pingPong );
  7926. } else {
  7927. // when looping in reverse direction, the initial
  7928. // transition through zero counts as a repetition,
  7929. // so leave loopCount at -1
  7930. this._setEndings(
  7931. this.repetitions === 0, true, pingPong );
  7932. }
  7933. }
  7934. if ( time >= duration || time < 0 ) {
  7935. // wrap around
  7936. var loopDelta = Math.floor( time / duration ); // signed
  7937. time -= duration * loopDelta;
  7938. loopCount += Math.abs( loopDelta );
  7939. var pending = this.repetitions - loopCount;
  7940. if ( pending < 0 ) {
  7941. // have to stop (switch state, clamp time, fire event)
  7942. if ( this.clampWhenFinished ) this.paused = true;
  7943. else this.enabled = false;
  7944. time = deltaTime > 0 ? duration : 0;
  7945. this._mixer.dispatchEvent( {
  7946. type: 'finished', action: this,
  7947. direction: deltaTime > 0 ? 1 : -1
  7948. } );
  7949. } else {
  7950. // keep running
  7951. if ( pending === 0 ) {
  7952. // entering the last round
  7953. var atStart = deltaTime < 0;
  7954. this._setEndings( atStart, ! atStart, pingPong );
  7955. } else {
  7956. this._setEndings( false, false, pingPong );
  7957. }
  7958. this._loopCount = loopCount;
  7959. this._mixer.dispatchEvent( {
  7960. type: 'loop', action: this, loopDelta: loopDelta
  7961. } );
  7962. }
  7963. }
  7964. if ( pingPong && ( loopCount & 1 ) === 1 ) {
  7965. // invert time for the "pong round"
  7966. this.time = time;
  7967. return duration - time;
  7968. }
  7969. }
  7970. this.time = time;
  7971. return time;
  7972. },
  7973. _setEndings: function( atStart, atEnd, pingPong ) {
  7974. var settings = this._interpolantSettings;
  7975. if ( pingPong ) {
  7976. settings.endingStart = THREE.ZeroSlopeEnding;
  7977. settings.endingEnd = THREE.ZeroSlopeEnding;
  7978. } else {
  7979. // assuming for LoopOnce atStart == atEnd == true
  7980. if ( atStart ) {
  7981. settings.endingStart = this.zeroSlopeAtStart ?
  7982. THREE.ZeroSlopeEnding : THREE.ZeroCurvatureEnding;
  7983. } else {
  7984. settings.endingStart = THREE.WrapAroundEnding;
  7985. }
  7986. if ( atEnd ) {
  7987. settings.endingEnd = this.zeroSlopeAtEnd ?
  7988. THREE.ZeroSlopeEnding : THREE.ZeroCurvatureEnding;
  7989. } else {
  7990. settings.endingEnd = THREE.WrapAroundEnding;
  7991. }
  7992. }
  7993. },
  7994. _scheduleFading: function( duration, weightNow, weightThen ) {
  7995. var mixer = this._mixer, now = mixer.time,
  7996. interpolant = this._weightInterpolant;
  7997. if ( interpolant === null ) {
  7998. interpolant = mixer._lendControlInterpolant(),
  7999. this._weightInterpolant = interpolant;
  8000. }
  8001. var times = interpolant.parameterPositions,
  8002. values = interpolant.sampleValues;
  8003. times[ 0 ] = now; values[ 0 ] = weightNow;
  8004. times[ 1 ] = now + duration; values[ 1 ] = weightThen;
  8005. return this;
  8006. }
  8007. };
  8008. // Implementation details:
  8009. Object.assign( THREE.AnimationMixer.prototype, {
  8010. _bindAction: function( action, prototypeAction ) {
  8011. var root = action._localRoot || this._root,
  8012. tracks = action._clip.tracks,
  8013. nTracks = tracks.length,
  8014. bindings = action._propertyBindings,
  8015. interpolants = action._interpolants,
  8016. rootUuid = root.uuid,
  8017. bindingsByRoot = this._bindingsByRootAndName,
  8018. bindingsByName = bindingsByRoot[ rootUuid ];
  8019. if ( bindingsByName === undefined ) {
  8020. bindingsByName = {};
  8021. bindingsByRoot[ rootUuid ] = bindingsByName;
  8022. }
  8023. for ( var i = 0; i !== nTracks; ++ i ) {
  8024. var track = tracks[ i ],
  8025. trackName = track.name,
  8026. binding = bindingsByName[ trackName ];
  8027. if ( binding !== undefined ) {
  8028. bindings[ i ] = binding;
  8029. } else {
  8030. binding = bindings[ i ];
  8031. if ( binding !== undefined ) {
  8032. // existing binding, make sure the cache knows
  8033. if ( binding._cacheIndex === null ) {
  8034. ++ binding.referenceCount;
  8035. this._addInactiveBinding( binding, rootUuid, trackName );
  8036. }
  8037. continue;
  8038. }
  8039. var path = prototypeAction && prototypeAction.
  8040. _propertyBindings[ i ].binding.parsedPath;
  8041. binding = new THREE.PropertyMixer(
  8042. THREE.PropertyBinding.create( root, trackName, path ),
  8043. track.ValueTypeName, track.getValueSize() );
  8044. ++ binding.referenceCount;
  8045. this._addInactiveBinding( binding, rootUuid, trackName );
  8046. bindings[ i ] = binding;
  8047. }
  8048. interpolants[ i ].resultBuffer = binding.buffer;
  8049. }
  8050. },
  8051. _activateAction: function( action ) {
  8052. if ( ! this._isActiveAction( action ) ) {
  8053. if ( action._cacheIndex === null ) {
  8054. // this action has been forgotten by the cache, but the user
  8055. // appears to be still using it -> rebind
  8056. var rootUuid = ( action._localRoot || this._root ).uuid,
  8057. clipName = action._clip.name,
  8058. actionsForClip = this._actionsByClip[ clipName ];
  8059. this._bindAction( action,
  8060. actionsForClip && actionsForClip.knownActions[ 0 ] );
  8061. this._addInactiveAction( action, clipName, rootUuid );
  8062. }
  8063. var bindings = action._propertyBindings;
  8064. // increment reference counts / sort out state
  8065. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  8066. var binding = bindings[ i ];
  8067. if ( binding.useCount ++ === 0 ) {
  8068. this._lendBinding( binding );
  8069. binding.saveOriginalState();
  8070. }
  8071. }
  8072. this._lendAction( action );
  8073. }
  8074. },
  8075. _deactivateAction: function( action ) {
  8076. if ( this._isActiveAction( action ) ) {
  8077. var bindings = action._propertyBindings;
  8078. // decrement reference counts / sort out state
  8079. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  8080. var binding = bindings[ i ];
  8081. if ( -- binding.useCount === 0 ) {
  8082. binding.restoreOriginalState();
  8083. this._takeBackBinding( binding );
  8084. }
  8085. }
  8086. this._takeBackAction( action );
  8087. }
  8088. },
  8089. // Memory manager
  8090. _initMemoryManager: function() {
  8091. this._actions = []; // 'nActiveActions' followed by inactive ones
  8092. this._nActiveActions = 0;
  8093. this._actionsByClip = {};
  8094. // inside:
  8095. // {
  8096. // knownActions: Array< _Action > - used as prototypes
  8097. // actionByRoot: _Action - lookup
  8098. // }
  8099. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  8100. this._nActiveBindings = 0;
  8101. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  8102. this._controlInterpolants = []; // same game as above
  8103. this._nActiveControlInterpolants = 0;
  8104. var scope = this;
  8105. this.stats = {
  8106. actions: {
  8107. get total() { return scope._actions.length; },
  8108. get inUse() { return scope._nActiveActions; }
  8109. },
  8110. bindings: {
  8111. get total() { return scope._bindings.length; },
  8112. get inUse() { return scope._nActiveBindings; }
  8113. },
  8114. controlInterpolants: {
  8115. get total() { return scope._controlInterpolants.length; },
  8116. get inUse() { return scope._nActiveControlInterpolants; }
  8117. }
  8118. };
  8119. },
  8120. // Memory management for _Action objects
  8121. _isActiveAction: function( action ) {
  8122. var index = action._cacheIndex;
  8123. return index !== null && index < this._nActiveActions;
  8124. },
  8125. _addInactiveAction: function( action, clipName, rootUuid ) {
  8126. var actions = this._actions,
  8127. actionsByClip = this._actionsByClip,
  8128. actionsForClip = actionsByClip[ clipName ];
  8129. if ( actionsForClip === undefined ) {
  8130. actionsForClip = {
  8131. knownActions: [ action ],
  8132. actionByRoot: {}
  8133. };
  8134. action._byClipCacheIndex = 0;
  8135. actionsByClip[ clipName ] = actionsForClip;
  8136. } else {
  8137. var knownActions = actionsForClip.knownActions;
  8138. action._byClipCacheIndex = knownActions.length;
  8139. knownActions.push( action );
  8140. }
  8141. action._cacheIndex = actions.length;
  8142. actions.push( action );
  8143. actionsForClip.actionByRoot[ rootUuid ] = action;
  8144. },
  8145. _removeInactiveAction: function( action ) {
  8146. var actions = this._actions,
  8147. lastInactiveAction = actions[ actions.length - 1 ],
  8148. cacheIndex = action._cacheIndex;
  8149. lastInactiveAction._cacheIndex = cacheIndex;
  8150. actions[ cacheIndex ] = lastInactiveAction;
  8151. actions.pop();
  8152. action._cacheIndex = null;
  8153. var clipName = action._clip.name,
  8154. actionsByClip = this._actionsByClip,
  8155. actionsForClip = actionsByClip[ clipName ],
  8156. knownActionsForClip = actionsForClip.knownActions,
  8157. lastKnownAction =
  8158. knownActionsForClip[ knownActionsForClip.length - 1 ],
  8159. byClipCacheIndex = action._byClipCacheIndex;
  8160. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  8161. knownActionsForClip[ byClipCacheIndex ] = lastKnownAction;
  8162. knownActionsForClip.pop();
  8163. action._byClipCacheIndex = null;
  8164. var actionByRoot = actionsForClip.actionByRoot,
  8165. rootUuid = ( actions._localRoot || this._root ).uuid;
  8166. delete actionByRoot[ rootUuid ];
  8167. if ( knownActionsForClip.length === 0 ) {
  8168. delete actionsByClip[ clipName ];
  8169. }
  8170. this._removeInactiveBindingsForAction( action );
  8171. },
  8172. _removeInactiveBindingsForAction: function( action ) {
  8173. var bindings = action._propertyBindings;
  8174. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  8175. var binding = bindings[ i ];
  8176. if ( -- binding.referenceCount === 0 ) {
  8177. this._removeInactiveBinding( binding );
  8178. }
  8179. }
  8180. },
  8181. _lendAction: function( action ) {
  8182. // [ active actions | inactive actions ]
  8183. // [ active actions >| inactive actions ]
  8184. // s a
  8185. // <-swap->
  8186. // a s
  8187. var actions = this._actions,
  8188. prevIndex = action._cacheIndex,
  8189. lastActiveIndex = this._nActiveActions ++,
  8190. firstInactiveAction = actions[ lastActiveIndex ];
  8191. action._cacheIndex = lastActiveIndex;
  8192. actions[ lastActiveIndex ] = action;
  8193. firstInactiveAction._cacheIndex = prevIndex;
  8194. actions[ prevIndex ] = firstInactiveAction;
  8195. },
  8196. _takeBackAction: function( action ) {
  8197. // [ active actions | inactive actions ]
  8198. // [ active actions |< inactive actions ]
  8199. // a s
  8200. // <-swap->
  8201. // s a
  8202. var actions = this._actions,
  8203. prevIndex = action._cacheIndex,
  8204. firstInactiveIndex = -- this._nActiveActions,
  8205. lastActiveAction = actions[ firstInactiveIndex ];
  8206. action._cacheIndex = firstInactiveIndex;
  8207. actions[ firstInactiveIndex ] = action;
  8208. lastActiveAction._cacheIndex = prevIndex;
  8209. actions[ prevIndex ] = lastActiveAction;
  8210. },
  8211. // Memory management for PropertyMixer objects
  8212. _addInactiveBinding: function( binding, rootUuid, trackName ) {
  8213. var bindingsByRoot = this._bindingsByRootAndName,
  8214. bindingByName = bindingsByRoot[ rootUuid ],
  8215. bindings = this._bindings;
  8216. if ( bindingByName === undefined ) {
  8217. bindingByName = {};
  8218. bindingsByRoot[ rootUuid ] = bindingByName;
  8219. }
  8220. bindingByName[ trackName ] = binding;
  8221. binding._cacheIndex = bindings.length;
  8222. bindings.push( binding );
  8223. },
  8224. _removeInactiveBinding: function( binding ) {
  8225. var bindings = this._bindings,
  8226. propBinding = binding.binding,
  8227. rootUuid = propBinding.rootNode.uuid,
  8228. trackName = propBinding.path,
  8229. bindingsByRoot = this._bindingsByRootAndName,
  8230. bindingByName = bindingsByRoot[ rootUuid ],
  8231. lastInactiveBinding = bindings[ bindings.length - 1 ],
  8232. cacheIndex = binding._cacheIndex;
  8233. lastInactiveBinding._cacheIndex = cacheIndex;
  8234. bindings[ cacheIndex ] = lastInactiveBinding;
  8235. bindings.pop();
  8236. delete bindingByName[ trackName ];
  8237. remove_empty_map: {
  8238. for ( var _ in bindingByName ) break remove_empty_map;
  8239. delete bindingsByRoot[ rootUuid ];
  8240. }
  8241. },
  8242. _lendBinding: function( binding ) {
  8243. var bindings = this._bindings,
  8244. prevIndex = binding._cacheIndex,
  8245. lastActiveIndex = this._nActiveBindings ++,
  8246. firstInactiveBinding = bindings[ lastActiveIndex ];
  8247. binding._cacheIndex = lastActiveIndex;
  8248. bindings[ lastActiveIndex ] = binding;
  8249. firstInactiveBinding._cacheIndex = prevIndex;
  8250. bindings[ prevIndex ] = firstInactiveBinding;
  8251. },
  8252. _takeBackBinding: function( binding ) {
  8253. var bindings = this._bindings,
  8254. prevIndex = binding._cacheIndex,
  8255. firstInactiveIndex = -- this._nActiveBindings,
  8256. lastActiveBinding = bindings[ firstInactiveIndex ];
  8257. binding._cacheIndex = firstInactiveIndex;
  8258. bindings[ firstInactiveIndex ] = binding;
  8259. lastActiveBinding._cacheIndex = prevIndex;
  8260. bindings[ prevIndex ] = lastActiveBinding;
  8261. },
  8262. // Memory management of Interpolants for weight and time scale
  8263. _lendControlInterpolant: function() {
  8264. var interpolants = this._controlInterpolants,
  8265. lastActiveIndex = this._nActiveControlInterpolants ++,
  8266. interpolant = interpolants[ lastActiveIndex ];
  8267. if ( interpolant === undefined ) {
  8268. interpolant = new THREE.LinearInterpolant(
  8269. new Float32Array( 2 ), new Float32Array( 2 ),
  8270. 1, this._controlInterpolantsResultBuffer );
  8271. interpolant.__cacheIndex = lastActiveIndex;
  8272. interpolants[ lastActiveIndex ] = interpolant;
  8273. }
  8274. return interpolant;
  8275. },
  8276. _takeBackControlInterpolant: function( interpolant ) {
  8277. var interpolants = this._controlInterpolants,
  8278. prevIndex = interpolant.__cacheIndex,
  8279. firstInactiveIndex = -- this._nActiveControlInterpolants,
  8280. lastActiveInterpolant = interpolants[ firstInactiveIndex ];
  8281. interpolant.__cacheIndex = firstInactiveIndex;
  8282. interpolants[ firstInactiveIndex ] = interpolant;
  8283. lastActiveInterpolant.__cacheIndex = prevIndex;
  8284. interpolants[ prevIndex ] = lastActiveInterpolant;
  8285. },
  8286. _controlInterpolantsResultBuffer: new Float32Array( 1 )
  8287. } );
  8288. // File:src/animation/AnimationObjectGroup.js
  8289. /**
  8290. *
  8291. * A group of objects that receives a shared animation state.
  8292. *
  8293. * Usage:
  8294. *
  8295. * - Add objects you would otherwise pass as 'root' to the
  8296. * constructor or the .clipAction method of AnimationMixer.
  8297. *
  8298. * - Instead pass this object as 'root'.
  8299. *
  8300. * - You can also add and remove objects later when the mixer
  8301. * is running.
  8302. *
  8303. * Note:
  8304. *
  8305. * Objects of this class appear as one object to the mixer,
  8306. * so cache control of the individual objects must be done
  8307. * on the group.
  8308. *
  8309. * Limitation:
  8310. *
  8311. * - The animated properties must be compatible among the
  8312. * all objects in the group.
  8313. *
  8314. * - A single property can either be controlled through a
  8315. * target group or directly, but not both.
  8316. *
  8317. * @author tschw
  8318. */
  8319. THREE.AnimationObjectGroup = function( var_args ) {
  8320. this.uuid = THREE.Math.generateUUID();
  8321. // cached objects followed by the active ones
  8322. this._objects = Array.prototype.slice.call( arguments );
  8323. this.nCachedObjects_ = 0; // threshold
  8324. // note: read by PropertyBinding.Composite
  8325. var indices = {};
  8326. this._indicesByUUID = indices; // for bookkeeping
  8327. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  8328. indices[ arguments[ i ].uuid ] = i;
  8329. }
  8330. this._paths = []; // inside: string
  8331. this._parsedPaths = []; // inside: { we don't care, here }
  8332. this._bindings = []; // inside: Array< PropertyBinding >
  8333. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  8334. var scope = this;
  8335. this.stats = {
  8336. objects: {
  8337. get total() { return scope._objects.length; },
  8338. get inUse() { return this.total - scope.nCachedObjects_; }
  8339. },
  8340. get bindingsPerObject() { return scope._bindings.length; }
  8341. };
  8342. };
  8343. THREE.AnimationObjectGroup.prototype = {
  8344. constructor: THREE.AnimationObjectGroup,
  8345. add: function( var_args ) {
  8346. var objects = this._objects,
  8347. nObjects = objects.length,
  8348. nCachedObjects = this.nCachedObjects_,
  8349. indicesByUUID = this._indicesByUUID,
  8350. paths = this._paths,
  8351. parsedPaths = this._parsedPaths,
  8352. bindings = this._bindings,
  8353. nBindings = bindings.length;
  8354. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  8355. var object = arguments[ i ],
  8356. uuid = object.uuid,
  8357. index = indicesByUUID[ uuid ];
  8358. if ( index === undefined ) {
  8359. // unknown object -> add it to the ACTIVE region
  8360. index = nObjects ++;
  8361. indicesByUUID[ uuid ] = index;
  8362. objects.push( object );
  8363. // accounting is done, now do the same for all bindings
  8364. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8365. bindings[ j ].push(
  8366. new THREE.PropertyBinding(
  8367. object, paths[ j ], parsedPaths[ j ] ) );
  8368. }
  8369. } else if ( index < nCachedObjects ) {
  8370. var knownObject = objects[ index ];
  8371. // move existing object to the ACTIVE region
  8372. var firstActiveIndex = -- nCachedObjects,
  8373. lastCachedObject = objects[ firstActiveIndex ];
  8374. indicesByUUID[ lastCachedObject.uuid ] = index;
  8375. objects[ index ] = lastCachedObject;
  8376. indicesByUUID[ uuid ] = firstActiveIndex;
  8377. objects[ firstActiveIndex ] = object;
  8378. // accounting is done, now do the same for all bindings
  8379. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8380. var bindingsForPath = bindings[ j ],
  8381. lastCached = bindingsForPath[ firstActiveIndex ],
  8382. binding = bindingsForPath[ index ];
  8383. bindingsForPath[ index ] = lastCached;
  8384. if ( binding === undefined ) {
  8385. // since we do not bother to create new bindings
  8386. // for objects that are cached, the binding may
  8387. // or may not exist
  8388. binding = new THREE.PropertyBinding(
  8389. object, paths[ j ], parsedPaths[ j ] );
  8390. }
  8391. bindingsForPath[ firstActiveIndex ] = binding;
  8392. }
  8393. } else if ( objects[ index ] !== knownObject) {
  8394. console.error( "Different objects with the same UUID " +
  8395. "detected. Clean the caches or recreate your " +
  8396. "infrastructure when reloading scenes..." );
  8397. } // else the object is already where we want it to be
  8398. } // for arguments
  8399. this.nCachedObjects_ = nCachedObjects;
  8400. },
  8401. remove: function( var_args ) {
  8402. var objects = this._objects,
  8403. nObjects = objects.length,
  8404. nCachedObjects = this.nCachedObjects_,
  8405. indicesByUUID = this._indicesByUUID,
  8406. bindings = this._bindings,
  8407. nBindings = bindings.length;
  8408. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  8409. var object = arguments[ i ],
  8410. uuid = object.uuid,
  8411. index = indicesByUUID[ uuid ];
  8412. if ( index !== undefined && index >= nCachedObjects ) {
  8413. // move existing object into the CACHED region
  8414. var lastCachedIndex = nCachedObjects ++,
  8415. firstActiveObject = objects[ lastCachedIndex ];
  8416. indicesByUUID[ firstActiveObject.uuid ] = index;
  8417. objects[ index ] = firstActiveObject;
  8418. indicesByUUID[ uuid ] = lastCachedIndex;
  8419. objects[ lastCachedIndex ] = object;
  8420. // accounting is done, now do the same for all bindings
  8421. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8422. var bindingsForPath = bindings[ j ],
  8423. firstActive = bindingsForPath[ lastCachedIndex ],
  8424. binding = bindingsForPath[ index ];
  8425. bindingsForPath[ index ] = firstActive;
  8426. bindingsForPath[ lastCachedIndex ] = binding;
  8427. }
  8428. }
  8429. } // for arguments
  8430. this.nCachedObjects_ = nCachedObjects;
  8431. },
  8432. // remove & forget
  8433. uncache: function( var_args ) {
  8434. var objects = this._objects,
  8435. nObjects = objects.length,
  8436. nCachedObjects = this.nCachedObjects_,
  8437. indicesByUUID = this._indicesByUUID,
  8438. bindings = this._bindings,
  8439. nBindings = bindings.length;
  8440. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  8441. var object = arguments[ i ],
  8442. uuid = object.uuid,
  8443. index = indicesByUUID[ uuid ];
  8444. if ( index !== undefined ) {
  8445. delete indicesByUUID[ uuid ];
  8446. if ( index < nCachedObjects ) {
  8447. // object is cached, shrink the CACHED region
  8448. var firstActiveIndex = -- nCachedObjects,
  8449. lastCachedObject = objects[ firstActiveIndex ],
  8450. lastIndex = -- nObjects,
  8451. lastObject = objects[ lastIndex ];
  8452. // last cached object takes this object's place
  8453. indicesByUUID[ lastCachedObject.uuid ] = index;
  8454. objects[ index ] = lastCachedObject;
  8455. // last object goes to the activated slot and pop
  8456. indicesByUUID[ lastObject.uuid ] = firstActiveIndex;
  8457. objects[ firstActiveIndex ] = lastObject;
  8458. objects.pop();
  8459. // accounting is done, now do the same for all bindings
  8460. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8461. var bindingsForPath = bindings[ j ],
  8462. lastCached = bindingsForPath[ firstActiveIndex ],
  8463. last = bindingsForPath[ lastIndex ];
  8464. bindingsForPath[ index ] = lastCached;
  8465. bindingsForPath[ firstActiveIndex ] = last;
  8466. bindingsForPath.pop();
  8467. }
  8468. } else {
  8469. // object is active, just swap with the last and pop
  8470. var lastIndex = -- nObjects,
  8471. lastObject = objects[ lastIndex ];
  8472. indicesByUUID[ lastObject.uuid ] = index;
  8473. objects[ index ] = lastObject;
  8474. objects.pop();
  8475. // accounting is done, now do the same for all bindings
  8476. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8477. var bindingsForPath = bindings[ j ];
  8478. bindingsForPath[ index ] = bindingsForPath[ lastIndex ];
  8479. bindingsForPath.pop();
  8480. }
  8481. } // cached or active
  8482. } // if object is known
  8483. } // for arguments
  8484. this.nCachedObjects_ = nCachedObjects;
  8485. },
  8486. // Internal interface used by befriended PropertyBinding.Composite:
  8487. subscribe_: function( path, parsedPath ) {
  8488. // returns an array of bindings for the given path that is changed
  8489. // according to the contained objects in the group
  8490. var indicesByPath = this._bindingsIndicesByPath,
  8491. index = indicesByPath[ path ],
  8492. bindings = this._bindings;
  8493. if ( index !== undefined ) return bindings[ index ];
  8494. var paths = this._paths,
  8495. parsedPaths = this._parsedPaths,
  8496. objects = this._objects,
  8497. nObjects = objects.length,
  8498. nCachedObjects = this.nCachedObjects_,
  8499. bindingsForPath = new Array( nObjects );
  8500. index = bindings.length;
  8501. indicesByPath[ path ] = index;
  8502. paths.push( path );
  8503. parsedPaths.push( parsedPath );
  8504. bindings.push( bindingsForPath );
  8505. for ( var i = nCachedObjects,
  8506. n = objects.length; i !== n; ++ i ) {
  8507. var object = objects[ i ];
  8508. bindingsForPath[ i ] =
  8509. new THREE.PropertyBinding( object, path, parsedPath );
  8510. }
  8511. return bindingsForPath;
  8512. },
  8513. unsubscribe_: function( path ) {
  8514. // tells the group to forget about a property path and no longer
  8515. // update the array previously obtained with 'subscribe_'
  8516. var indicesByPath = this._bindingsIndicesByPath,
  8517. index = indicesByPath[ path ];
  8518. if ( index !== undefined ) {
  8519. var paths = this._paths,
  8520. parsedPaths = this._parsedPaths,
  8521. bindings = this._bindings,
  8522. lastBindingsIndex = bindings.length - 1,
  8523. lastBindings = bindings[ lastBindingsIndex ],
  8524. lastBindingsPath = path[ lastBindingsIndex ];
  8525. indicesByPath[ lastBindingsPath ] = index;
  8526. bindings[ index ] = lastBindings;
  8527. bindings.pop();
  8528. parsedPaths[ index ] = parsedPaths[ lastBindingsIndex ];
  8529. parsedPaths.pop();
  8530. paths[ index ] = paths[ lastBindingsIndex ];
  8531. paths.pop();
  8532. }
  8533. }
  8534. };
  8535. // File:src/animation/AnimationUtils.js
  8536. /**
  8537. * @author tschw
  8538. * @author Ben Houston / http://clara.io/
  8539. * @author David Sarno / http://lighthaus.us/
  8540. */
  8541. THREE.AnimationUtils = {
  8542. // same as Array.prototype.slice, but also works on typed arrays
  8543. arraySlice: function( array, from, to ) {
  8544. if ( THREE.AnimationUtils.isTypedArray( array ) ) {
  8545. return new array.constructor( array.subarray( from, to ) );
  8546. }
  8547. return array.slice( from, to );
  8548. },
  8549. // converts an array to a specific type
  8550. convertArray: function( array, type, forceClone ) {
  8551. if ( ! array || // let 'undefined' and 'null' pass
  8552. ! forceClone && array.constructor === type ) return array;
  8553. if ( typeof type.BYTES_PER_ELEMENT === 'number' ) {
  8554. return new type( array ); // create typed array
  8555. }
  8556. return Array.prototype.slice.call( array ); // create Array
  8557. },
  8558. isTypedArray: function( object ) {
  8559. return ArrayBuffer.isView( object ) &&
  8560. ! ( object instanceof DataView );
  8561. },
  8562. // returns an array by which times and values can be sorted
  8563. getKeyframeOrder: function( times ) {
  8564. function compareTime( i, j ) {
  8565. return times[ i ] - times[ j ];
  8566. }
  8567. var n = times.length;
  8568. var result = new Array( n );
  8569. for ( var i = 0; i !== n; ++ i ) result[ i ] = i;
  8570. result.sort( compareTime );
  8571. return result;
  8572. },
  8573. // uses the array previously returned by 'getKeyframeOrder' to sort data
  8574. sortedArray: function( values, stride, order ) {
  8575. var nValues = values.length;
  8576. var result = new values.constructor( nValues );
  8577. for ( var i = 0, dstOffset = 0; dstOffset !== nValues; ++ i ) {
  8578. var srcOffset = order[ i ] * stride;
  8579. for ( var j = 0; j !== stride; ++ j ) {
  8580. result[ dstOffset ++ ] = values[ srcOffset + j ];
  8581. }
  8582. }
  8583. return result;
  8584. },
  8585. // function for parsing AOS keyframe formats
  8586. flattenJSON: function( jsonKeys, times, values, valuePropertyName ) {
  8587. var i = 1, key = jsonKeys[ 0 ];
  8588. while ( key !== undefined && key[ valuePropertyName ] === undefined ) {
  8589. key = jsonKeys[ i ++ ];
  8590. }
  8591. if ( key === undefined ) return; // no data
  8592. var value = key[ valuePropertyName ];
  8593. if ( value === undefined ) return; // no data
  8594. if ( Array.isArray( value ) ) {
  8595. do {
  8596. value = key[ valuePropertyName ];
  8597. if ( value !== undefined ) {
  8598. times.push( key.time );
  8599. values.push.apply( values, value ); // push all elements
  8600. }
  8601. key = jsonKeys[ i ++ ];
  8602. } while ( key !== undefined );
  8603. } else if ( value.toArray !== undefined ) {
  8604. // ...assume THREE.Math-ish
  8605. do {
  8606. value = key[ valuePropertyName ];
  8607. if ( value !== undefined ) {
  8608. times.push( key.time );
  8609. value.toArray( values, values.length );
  8610. }
  8611. key = jsonKeys[ i ++ ];
  8612. } while ( key !== undefined );
  8613. } else {
  8614. // otherwise push as-is
  8615. do {
  8616. value = key[ valuePropertyName ];
  8617. if ( value !== undefined ) {
  8618. times.push( key.time );
  8619. values.push( value );
  8620. }
  8621. key = jsonKeys[ i ++ ];
  8622. } while ( key !== undefined );
  8623. }
  8624. }
  8625. };
  8626. // File:src/animation/KeyframeTrack.js
  8627. /**
  8628. *
  8629. * A timed sequence of keyframes for a specific property.
  8630. *
  8631. *
  8632. * @author Ben Houston / http://clara.io/
  8633. * @author David Sarno / http://lighthaus.us/
  8634. * @author tschw
  8635. */
  8636. THREE.KeyframeTrack = function ( name, times, values, interpolation ) {
  8637. if( name === undefined ) throw new Error( "track name is undefined" );
  8638. if( times === undefined || times.length === 0 ) {
  8639. throw new Error( "no keyframes in track named " + name );
  8640. }
  8641. this.name = name;
  8642. this.times = THREE.AnimationUtils.convertArray( times, this.TimeBufferType );
  8643. this.values = THREE.AnimationUtils.convertArray( values, this.ValueBufferType );
  8644. this.setInterpolation( interpolation || this.DefaultInterpolation );
  8645. this.validate();
  8646. this.optimize();
  8647. };
  8648. THREE.KeyframeTrack.prototype = {
  8649. constructor: THREE.KeyframeTrack,
  8650. TimeBufferType: Float32Array,
  8651. ValueBufferType: Float32Array,
  8652. DefaultInterpolation: THREE.InterpolateLinear,
  8653. InterpolantFactoryMethodDiscrete: function( result ) {
  8654. return new THREE.DiscreteInterpolant(
  8655. this.times, this.values, this.getValueSize(), result );
  8656. },
  8657. InterpolantFactoryMethodLinear: function( result ) {
  8658. return new THREE.LinearInterpolant(
  8659. this.times, this.values, this.getValueSize(), result );
  8660. },
  8661. InterpolantFactoryMethodSmooth: function( result ) {
  8662. return new THREE.CubicInterpolant(
  8663. this.times, this.values, this.getValueSize(), result );
  8664. },
  8665. setInterpolation: function( interpolation ) {
  8666. var factoryMethod;
  8667. switch ( interpolation ) {
  8668. case THREE.InterpolateDiscrete:
  8669. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  8670. break;
  8671. case THREE.InterpolateLinear:
  8672. factoryMethod = this.InterpolantFactoryMethodLinear;
  8673. break;
  8674. case THREE.InterpolateSmooth:
  8675. factoryMethod = this.InterpolantFactoryMethodSmooth;
  8676. break;
  8677. }
  8678. if ( factoryMethod === undefined ) {
  8679. var message = "unsupported interpolation for " +
  8680. this.ValueTypeName + " keyframe track named " + this.name;
  8681. if ( this.createInterpolant === undefined ) {
  8682. // fall back to default, unless the default itself is messed up
  8683. if ( interpolation !== this.DefaultInterpolation ) {
  8684. this.setInterpolation( this.DefaultInterpolation );
  8685. } else {
  8686. throw new Error( message ); // fatal, in this case
  8687. }
  8688. }
  8689. console.warn( message );
  8690. return;
  8691. }
  8692. this.createInterpolant = factoryMethod;
  8693. },
  8694. getInterpolation: function() {
  8695. switch ( this.createInterpolant ) {
  8696. case this.InterpolantFactoryMethodDiscrete:
  8697. return THREE.InterpolateDiscrete;
  8698. case this.InterpolantFactoryMethodLinear:
  8699. return THREE.InterpolateLinear;
  8700. case this.InterpolantFactoryMethodSmooth:
  8701. return THREE.InterpolateSmooth;
  8702. }
  8703. },
  8704. getValueSize: function() {
  8705. return this.values.length / this.times.length;
  8706. },
  8707. // move all keyframes either forwards or backwards in time
  8708. shift: function( timeOffset ) {
  8709. if( timeOffset !== 0.0 ) {
  8710. var times = this.times;
  8711. for( var i = 0, n = times.length; i !== n; ++ i ) {
  8712. times[ i ] += timeOffset;
  8713. }
  8714. }
  8715. return this;
  8716. },
  8717. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  8718. scale: function( timeScale ) {
  8719. if( timeScale !== 1.0 ) {
  8720. var times = this.times;
  8721. for( var i = 0, n = times.length; i !== n; ++ i ) {
  8722. times[ i ] *= timeScale;
  8723. }
  8724. }
  8725. return this;
  8726. },
  8727. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  8728. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  8729. trim: function( startTime, endTime ) {
  8730. var times = this.times,
  8731. nKeys = times.length,
  8732. from = 0,
  8733. to = nKeys - 1;
  8734. while ( from !== nKeys && times[ from ] < startTime ) ++ from;
  8735. while ( to !== -1 && times[ to ] > endTime ) -- to;
  8736. ++ to; // inclusive -> exclusive bound
  8737. if( from !== 0 || to !== nKeys ) {
  8738. // empty tracks are forbidden, so keep at least one keyframe
  8739. if ( from >= to ) to = Math.max( to , 1 ), from = to - 1;
  8740. var stride = this.getValueSize();
  8741. this.times = THREE.AnimationUtils.arraySlice( times, from, to );
  8742. this.values = THREE.AnimationUtils.
  8743. arraySlice( this.values, from * stride, to * stride );
  8744. }
  8745. return this;
  8746. },
  8747. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  8748. validate: function() {
  8749. var valid = true;
  8750. var valueSize = this.getValueSize();
  8751. if ( valueSize - Math.floor( valueSize ) !== 0 ) {
  8752. console.error( "invalid value size in track", this );
  8753. valid = false;
  8754. }
  8755. var times = this.times,
  8756. values = this.values,
  8757. nKeys = times.length;
  8758. if( nKeys === 0 ) {
  8759. console.error( "track is empty", this );
  8760. valid = false;
  8761. }
  8762. var prevTime = null;
  8763. for( var i = 0; i !== nKeys; i ++ ) {
  8764. var currTime = times[ i ];
  8765. if ( typeof currTime === 'number' && isNaN( currTime ) ) {
  8766. console.error( "time is not a valid number", this, i, currTime );
  8767. valid = false;
  8768. break;
  8769. }
  8770. if( prevTime !== null && prevTime > currTime ) {
  8771. console.error( "out of order keys", this, i, currTime, prevTime );
  8772. valid = false;
  8773. break;
  8774. }
  8775. prevTime = currTime;
  8776. }
  8777. if ( values !== undefined ) {
  8778. if ( THREE.AnimationUtils.isTypedArray( values ) ) {
  8779. for ( var i = 0, n = values.length; i !== n; ++ i ) {
  8780. var value = values[ i ];
  8781. if ( isNaN( value ) ) {
  8782. console.error( "value is not a valid number", this, i, value );
  8783. valid = false;
  8784. break;
  8785. }
  8786. }
  8787. }
  8788. }
  8789. return valid;
  8790. },
  8791. // removes equivalent sequential keys as common in morph target sequences
  8792. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  8793. optimize: function() {
  8794. var times = this.times,
  8795. values = this.values,
  8796. stride = this.getValueSize(),
  8797. writeIndex = 1;
  8798. for( var i = 1, n = times.length - 1; i <= n; ++ i ) {
  8799. var keep = false;
  8800. var time = times[ i ];
  8801. var timeNext = times[ i + 1 ];
  8802. // remove adjacent keyframes scheduled at the same time
  8803. if ( time !== timeNext && ( i !== 1 || time !== time[ 0 ] ) ) {
  8804. // remove unnecessary keyframes same as their neighbors
  8805. var offset = i * stride,
  8806. offsetP = offset - stride,
  8807. offsetN = offset + stride;
  8808. for ( var j = 0; j !== stride; ++ j ) {
  8809. var value = values[ offset + j ];
  8810. if ( value !== values[ offsetP + j ] ||
  8811. value !== values[ offsetN + j ] ) {
  8812. keep = true;
  8813. break;
  8814. }
  8815. }
  8816. }
  8817. // in-place compaction
  8818. if ( keep ) {
  8819. if ( i !== writeIndex ) {
  8820. times[ writeIndex ] = times[ i ];
  8821. var readOffset = i * stride,
  8822. writeOffset = writeIndex * stride;
  8823. for ( var j = 0; j !== stride; ++ j ) {
  8824. values[ writeOffset + j ] = values[ readOffset + j ];
  8825. }
  8826. }
  8827. ++ writeIndex;
  8828. }
  8829. }
  8830. if ( writeIndex !== times.length ) {
  8831. this.times = THREE.AnimationUtils.arraySlice( times, 0, writeIndex );
  8832. this.values = THREE.AnimationUtils.arraySlice( values, 0, writeIndex * stride );
  8833. }
  8834. return this;
  8835. }
  8836. };
  8837. // Static methods:
  8838. Object.assign( THREE.KeyframeTrack, {
  8839. // Serialization (in static context, because of constructor invocation
  8840. // and automatic invocation of .toJSON):
  8841. parse: function( json ) {
  8842. if( json.type === undefined ) {
  8843. throw new Error( "track type undefined, can not parse" );
  8844. }
  8845. var trackType = THREE.KeyframeTrack._getTrackTypeForValueTypeName( json.type );
  8846. if ( json.times === undefined ) {
  8847. var times = [], values = [];
  8848. THREE.AnimationUtils.flattenJSON( json.keys, times, values, 'value' );
  8849. json.times = times;
  8850. json.values = values;
  8851. }
  8852. // derived classes can define a static parse method
  8853. if ( trackType.parse !== undefined ) {
  8854. return trackType.parse( json );
  8855. } else {
  8856. // by default, we asssume a constructor compatible with the base
  8857. return new trackType(
  8858. json.name, json.times, json.values, json.interpolation );
  8859. }
  8860. },
  8861. toJSON: function( track ) {
  8862. var trackType = track.constructor;
  8863. var json;
  8864. // derived classes can define a static toJSON method
  8865. if ( trackType.toJSON !== undefined ) {
  8866. json = trackType.toJSON( track );
  8867. } else {
  8868. // by default, we assume the data can be serialized as-is
  8869. json = {
  8870. 'name': track.name,
  8871. 'times': THREE.AnimationUtils.convertArray( track.times, Array ),
  8872. 'values': THREE.AnimationUtils.convertArray( track.values, Array )
  8873. };
  8874. var interpolation = track.getInterpolation();
  8875. if ( interpolation !== track.DefaultInterpolation ) {
  8876. json.interpolation = interpolation;
  8877. }
  8878. }
  8879. json.type = track.ValueTypeName; // mandatory
  8880. return json;
  8881. },
  8882. _getTrackTypeForValueTypeName: function( typeName ) {
  8883. switch( typeName.toLowerCase() ) {
  8884. case "scalar":
  8885. case "double":
  8886. case "float":
  8887. case "number":
  8888. case "integer":
  8889. return THREE.NumberKeyframeTrack;
  8890. case "vector":
  8891. case "vector2":
  8892. case "vector3":
  8893. case "vector4":
  8894. return THREE.VectorKeyframeTrack;
  8895. case "color":
  8896. return THREE.ColorKeyframeTrack;
  8897. case "quaternion":
  8898. return THREE.QuaternionKeyframeTrack;
  8899. case "bool":
  8900. case "boolean":
  8901. return THREE.BooleanKeyframeTrack;
  8902. case "string":
  8903. return THREE.StringKeyframeTrack;
  8904. }
  8905. throw new Error( "Unsupported typeName: " + typeName );
  8906. }
  8907. } );
  8908. // File:src/animation/PropertyBinding.js
  8909. /**
  8910. *
  8911. * A reference to a real property in the scene graph.
  8912. *
  8913. *
  8914. * @author Ben Houston / http://clara.io/
  8915. * @author David Sarno / http://lighthaus.us/
  8916. * @author tschw
  8917. */
  8918. THREE.PropertyBinding = function ( rootNode, path, parsedPath ) {
  8919. this.path = path;
  8920. this.parsedPath = parsedPath ||
  8921. THREE.PropertyBinding.parseTrackName( path );
  8922. this.node = THREE.PropertyBinding.findNode(
  8923. rootNode, this.parsedPath.nodeName ) || rootNode;
  8924. this.rootNode = rootNode;
  8925. };
  8926. THREE.PropertyBinding.prototype = {
  8927. constructor: THREE.PropertyBinding,
  8928. getValue: function getValue_unbound( targetArray, offset ) {
  8929. this.bind();
  8930. this.getValue( targetArray, offset );
  8931. // Note: This class uses a State pattern on a per-method basis:
  8932. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  8933. // prototype version of these methods with one that represents
  8934. // the bound state. When the property is not found, the methods
  8935. // become no-ops.
  8936. },
  8937. setValue: function getValue_unbound( sourceArray, offset ) {
  8938. this.bind();
  8939. this.setValue( sourceArray, offset );
  8940. },
  8941. // create getter / setter pair for a property in the scene graph
  8942. bind: function() {
  8943. var targetObject = this.node,
  8944. parsedPath = this.parsedPath,
  8945. objectName = parsedPath.objectName,
  8946. propertyName = parsedPath.propertyName,
  8947. propertyIndex = parsedPath.propertyIndex;
  8948. if ( ! targetObject ) {
  8949. targetObject = THREE.PropertyBinding.findNode(
  8950. this.rootNode, parsedPath.nodeName ) || this.rootNode;
  8951. this.node = targetObject;
  8952. }
  8953. // set fail state so we can just 'return' on error
  8954. this.getValue = this._getValue_unavailable;
  8955. this.setValue = this._setValue_unavailable;
  8956. // ensure there is a value node
  8957. if ( ! targetObject ) {
  8958. console.error( " trying to update node for track: " + this.path + " but it wasn't found." );
  8959. return;
  8960. }
  8961. if( objectName ) {
  8962. var objectIndex = parsedPath.objectIndex;
  8963. // special cases were we need to reach deeper into the hierarchy to get the face materials....
  8964. switch ( objectName ) {
  8965. case 'materials':
  8966. if( ! targetObject.material ) {
  8967. console.error( ' can not bind to material as node does not have a material', this );
  8968. return;
  8969. }
  8970. if( ! targetObject.material.materials ) {
  8971. console.error( ' can not bind to material.materials as node.material does not have a materials array', this );
  8972. return;
  8973. }
  8974. targetObject = targetObject.material.materials;
  8975. break;
  8976. case 'bones':
  8977. if( ! targetObject.skeleton ) {
  8978. console.error( ' can not bind to bones as node does not have a skeleton', this );
  8979. return;
  8980. }
  8981. // potential future optimization: skip this if propertyIndex is already an integer
  8982. // and convert the integer string to a true integer.
  8983. targetObject = targetObject.skeleton.bones;
  8984. // support resolving morphTarget names into indices.
  8985. for ( var i = 0; i < targetObject.length; i ++ ) {
  8986. if ( targetObject[i].name === objectIndex ) {
  8987. objectIndex = i;
  8988. break;
  8989. }
  8990. }
  8991. break;
  8992. default:
  8993. if ( targetObject[ objectName ] === undefined ) {
  8994. console.error( ' can not bind to objectName of node, undefined', this );
  8995. return;
  8996. }
  8997. targetObject = targetObject[ objectName ];
  8998. }
  8999. if ( objectIndex !== undefined ) {
  9000. if( targetObject[ objectIndex ] === undefined ) {
  9001. console.error( " trying to bind to objectIndex of objectName, but is undefined:", this, targetObject );
  9002. return;
  9003. }
  9004. targetObject = targetObject[ objectIndex ];
  9005. }
  9006. }
  9007. // resolve property
  9008. var nodeProperty = targetObject[ propertyName ];
  9009. if ( ! nodeProperty ) {
  9010. var nodeName = parsedPath.nodeName;
  9011. console.error( " trying to update property for track: " + nodeName +
  9012. '.' + propertyName + " but it wasn't found.", targetObject );
  9013. return;
  9014. }
  9015. // determine versioning scheme
  9016. var versioning = this.Versioning.None;
  9017. if ( targetObject.needsUpdate !== undefined ) { // material
  9018. versioning = this.Versioning.NeedsUpdate;
  9019. this.targetObject = targetObject;
  9020. } else if ( targetObject.matrixWorldNeedsUpdate !== undefined ) { // node transform
  9021. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  9022. this.targetObject = targetObject;
  9023. }
  9024. // determine how the property gets bound
  9025. var bindingType = this.BindingType.Direct;
  9026. if ( propertyIndex !== undefined ) {
  9027. // access a sub element of the property array (only primitives are supported right now)
  9028. if ( propertyName === "morphTargetInfluences" ) {
  9029. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  9030. // support resolving morphTarget names into indices.
  9031. if ( ! targetObject.geometry ) {
  9032. console.error( ' can not bind to morphTargetInfluences becasuse node does not have a geometry', this );
  9033. return;
  9034. }
  9035. if ( ! targetObject.geometry.morphTargets ) {
  9036. console.error( ' can not bind to morphTargetInfluences becasuse node does not have a geometry.morphTargets', this );
  9037. return;
  9038. }
  9039. for ( var i = 0; i < this.node.geometry.morphTargets.length; i ++ ) {
  9040. if ( targetObject.geometry.morphTargets[i].name === propertyIndex ) {
  9041. propertyIndex = i;
  9042. break;
  9043. }
  9044. }
  9045. }
  9046. bindingType = this.BindingType.ArrayElement;
  9047. this.resolvedProperty = nodeProperty;
  9048. this.propertyIndex = propertyIndex;
  9049. } else if ( nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined ) {
  9050. // must use copy for Object3D.Euler/Quaternion
  9051. bindingType = this.BindingType.HasFromToArray;
  9052. this.resolvedProperty = nodeProperty;
  9053. } else if ( nodeProperty.length !== undefined ) {
  9054. bindingType = this.BindingType.EntireArray;
  9055. this.resolvedProperty = nodeProperty;
  9056. } else {
  9057. this.propertyName = propertyName;
  9058. }
  9059. // select getter / setter
  9060. this.getValue = this.GetterByBindingType[ bindingType ];
  9061. this.setValue = this.SetterByBindingTypeAndVersioning[ bindingType ][ versioning ];
  9062. },
  9063. unbind: function() {
  9064. this.node = null;
  9065. // back to the prototype version of getValue / setValue
  9066. // note: avoiding to mutate the shape of 'this' via 'delete'
  9067. this.getValue = this._getValue_unbound;
  9068. this.setValue = this._setValue_unbound;
  9069. }
  9070. };
  9071. Object.assign( THREE.PropertyBinding.prototype, { // prototype, continued
  9072. // these are used to "bind" a nonexistent property
  9073. _getValue_unavailable: function() {},
  9074. _setValue_unavailable: function() {},
  9075. // initial state of these methods that calls 'bind'
  9076. _getValue_unbound: THREE.PropertyBinding.prototype.getValue,
  9077. _setValue_unbound: THREE.PropertyBinding.prototype.setValue,
  9078. BindingType: {
  9079. Direct: 0,
  9080. EntireArray: 1,
  9081. ArrayElement: 2,
  9082. HasFromToArray: 3
  9083. },
  9084. Versioning: {
  9085. None: 0,
  9086. NeedsUpdate: 1,
  9087. MatrixWorldNeedsUpdate: 2
  9088. },
  9089. GetterByBindingType: [
  9090. function getValue_direct( buffer, offset ) {
  9091. buffer[ offset ] = this.node[ this.propertyName ];
  9092. },
  9093. function getValue_array( buffer, offset ) {
  9094. var source = this.resolvedProperty;
  9095. for ( var i = 0, n = source.length; i !== n; ++ i ) {
  9096. buffer[ offset ++ ] = source[ i ];
  9097. }
  9098. },
  9099. function getValue_arrayElement( buffer, offset ) {
  9100. buffer[ offset ] = this.resolvedProperty[ this.propertyIndex ];
  9101. },
  9102. function getValue_toArray( buffer, offset ) {
  9103. this.resolvedProperty.toArray( buffer, offset );
  9104. }
  9105. ],
  9106. SetterByBindingTypeAndVersioning: [
  9107. [
  9108. // Direct
  9109. function setValue_direct( buffer, offset ) {
  9110. this.node[ this.propertyName ] = buffer[ offset ];
  9111. },
  9112. function setValue_direct_setNeedsUpdate( buffer, offset ) {
  9113. this.node[ this.propertyName ] = buffer[ offset ];
  9114. this.targetObject.needsUpdate = true;
  9115. },
  9116. function setValue_direct_setMatrixWorldNeedsUpdate( buffer, offset ) {
  9117. this.node[ this.propertyName ] = buffer[ offset ];
  9118. this.targetObject.matrixWorldNeedsUpdate = true;
  9119. }
  9120. ], [
  9121. // EntireArray
  9122. function setValue_array( buffer, offset ) {
  9123. var dest = this.resolvedProperty;
  9124. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  9125. dest[ i ] = buffer[ offset ++ ];
  9126. }
  9127. },
  9128. function setValue_array_setNeedsUpdate( buffer, offset ) {
  9129. var dest = this.resolvedProperty;
  9130. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  9131. dest[ i ] = buffer[ offset ++ ];
  9132. }
  9133. this.targetObject.needsUpdate = true;
  9134. },
  9135. function setValue_array_setMatrixWorldNeedsUpdate( buffer, offset ) {
  9136. var dest = this.resolvedProperty;
  9137. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  9138. dest[ i ] = buffer[ offset ++ ];
  9139. }
  9140. this.targetObject.matrixWorldNeedsUpdate = true;
  9141. }
  9142. ], [
  9143. // ArrayElement
  9144. function setValue_arrayElement( buffer, offset ) {
  9145. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  9146. },
  9147. function setValue_arrayElement_setNeedsUpdate( buffer, offset ) {
  9148. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  9149. this.targetObject.needsUpdate = true;
  9150. },
  9151. function setValue_arrayElement_setMatrixWorldNeedsUpdate( buffer, offset ) {
  9152. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  9153. this.targetObject.matrixWorldNeedsUpdate = true;
  9154. }
  9155. ], [
  9156. // HasToFromArray
  9157. function setValue_fromArray( buffer, offset ) {
  9158. this.resolvedProperty.fromArray( buffer, offset );
  9159. },
  9160. function setValue_fromArray_setNeedsUpdate( buffer, offset ) {
  9161. this.resolvedProperty.fromArray( buffer, offset );
  9162. this.targetObject.needsUpdate = true;
  9163. },
  9164. function setValue_fromArray_setMatrixWorldNeedsUpdate( buffer, offset ) {
  9165. this.resolvedProperty.fromArray( buffer, offset );
  9166. this.targetObject.matrixWorldNeedsUpdate = true;
  9167. }
  9168. ]
  9169. ]
  9170. } );
  9171. THREE.PropertyBinding.Composite =
  9172. function( targetGroup, path, optionalParsedPath ) {
  9173. var parsedPath = optionalParsedPath ||
  9174. THREE.PropertyBinding.parseTrackName( path );
  9175. this._targetGroup = targetGroup;
  9176. this._bindings = targetGroup.subscribe_( path, parsedPath );
  9177. };
  9178. THREE.PropertyBinding.Composite.prototype = {
  9179. constructor: THREE.PropertyBinding.Composite,
  9180. getValue: function( array, offset ) {
  9181. this.bind(); // bind all binding
  9182. var firstValidIndex = this._targetGroup.nCachedObjects_,
  9183. binding = this._bindings[ firstValidIndex ];
  9184. // and only call .getValue on the first
  9185. if ( binding !== undefined ) binding.getValue( array, offset );
  9186. },
  9187. setValue: function( array, offset ) {
  9188. var bindings = this._bindings;
  9189. for ( var i = this._targetGroup.nCachedObjects_,
  9190. n = bindings.length; i !== n; ++ i ) {
  9191. bindings[ i ].setValue( array, offset );
  9192. }
  9193. },
  9194. bind: function() {
  9195. var bindings = this._bindings;
  9196. for ( var i = this._targetGroup.nCachedObjects_,
  9197. n = bindings.length; i !== n; ++ i ) {
  9198. bindings[ i ].bind();
  9199. }
  9200. },
  9201. unbind: function() {
  9202. var bindings = this._bindings;
  9203. for ( var i = this._targetGroup.nCachedObjects_,
  9204. n = bindings.length; i !== n; ++ i ) {
  9205. bindings[ i ].unbind();
  9206. }
  9207. }
  9208. };
  9209. THREE.PropertyBinding.create = function( root, path, parsedPath ) {
  9210. if ( ! ( root instanceof THREE.AnimationObjectGroup ) ) {
  9211. return new THREE.PropertyBinding( root, path, parsedPath );
  9212. } else {
  9213. return new THREE.PropertyBinding.Composite( root, path, parsedPath );
  9214. }
  9215. };
  9216. THREE.PropertyBinding.parseTrackName = function( trackName ) {
  9217. // matches strings in the form of:
  9218. // nodeName.property
  9219. // nodeName.property[accessor]
  9220. // nodeName.material.property[accessor]
  9221. // uuid.property[accessor]
  9222. // uuid.objectName[objectIndex].propertyName[propertyIndex]
  9223. // parentName/nodeName.property
  9224. // parentName/parentName/nodeName.property[index]
  9225. // .bone[Armature.DEF_cog].position
  9226. // created and tested via https://regex101.com/#javascript
  9227. var re = /^(([\w]+\/)*)([\w-\d]+)?(\.([\w]+)(\[([\w\d\[\]\_.:\- ]+)\])?)?(\.([\w.]+)(\[([\w\d\[\]\_. ]+)\])?)$/;
  9228. var matches = re.exec(trackName);
  9229. if( ! matches ) {
  9230. throw new Error( "cannot parse trackName at all: " + trackName );
  9231. }
  9232. if (matches.index === re.lastIndex) {
  9233. re.lastIndex++;
  9234. }
  9235. var results = {
  9236. // directoryName: matches[1], // (tschw) currently unused
  9237. nodeName: matches[3], // allowed to be null, specified root node.
  9238. objectName: matches[5],
  9239. objectIndex: matches[7],
  9240. propertyName: matches[9],
  9241. propertyIndex: matches[11] // allowed to be null, specifies that the whole property is set.
  9242. };
  9243. if( results.propertyName === null || results.propertyName.length === 0 ) {
  9244. throw new Error( "can not parse propertyName from trackName: " + trackName );
  9245. }
  9246. return results;
  9247. };
  9248. THREE.PropertyBinding.findNode = function( root, nodeName ) {
  9249. if( ! nodeName || nodeName === "" || nodeName === "root" || nodeName === "." || nodeName === -1 || nodeName === root.name || nodeName === root.uuid ) {
  9250. return root;
  9251. }
  9252. // search into skeleton bones.
  9253. if( root.skeleton ) {
  9254. var searchSkeleton = function( skeleton ) {
  9255. for( var i = 0; i < skeleton.bones.length; i ++ ) {
  9256. var bone = skeleton.bones[i];
  9257. if( bone.name === nodeName ) {
  9258. return bone;
  9259. }
  9260. }
  9261. return null;
  9262. };
  9263. var bone = searchSkeleton( root.skeleton );
  9264. if( bone ) {
  9265. return bone;
  9266. }
  9267. }
  9268. // search into node subtree.
  9269. if( root.children ) {
  9270. var searchNodeSubtree = function( children ) {
  9271. for( var i = 0; i < children.length; i ++ ) {
  9272. var childNode = children[i];
  9273. if( childNode.name === nodeName || childNode.uuid === nodeName ) {
  9274. return childNode;
  9275. }
  9276. var result = searchNodeSubtree( childNode.children );
  9277. if( result ) return result;
  9278. }
  9279. return null;
  9280. };
  9281. var subTreeNode = searchNodeSubtree( root.children );
  9282. if( subTreeNode ) {
  9283. return subTreeNode;
  9284. }
  9285. }
  9286. return null;
  9287. };
  9288. // File:src/animation/PropertyMixer.js
  9289. /**
  9290. *
  9291. * Buffered scene graph property that allows weighted accumulation.
  9292. *
  9293. *
  9294. * @author Ben Houston / http://clara.io/
  9295. * @author David Sarno / http://lighthaus.us/
  9296. * @author tschw
  9297. */
  9298. THREE.PropertyMixer = function ( binding, typeName, valueSize ) {
  9299. this.binding = binding;
  9300. this.valueSize = valueSize;
  9301. var bufferType = Float64Array,
  9302. mixFunction;
  9303. switch ( typeName ) {
  9304. case 'quaternion': mixFunction = this._slerp; break;
  9305. case 'string':
  9306. case 'bool':
  9307. bufferType = Array, mixFunction = this._select; break;
  9308. default: mixFunction = this._lerp;
  9309. }
  9310. this.buffer = new bufferType( valueSize * 4 );
  9311. // layout: [ incoming | accu0 | accu1 | orig ]
  9312. //
  9313. // interpolators can use .buffer as their .result
  9314. // the data then goes to 'incoming'
  9315. //
  9316. // 'accu0' and 'accu1' are used frame-interleaved for
  9317. // the cumulative result and are compared to detect
  9318. // changes
  9319. //
  9320. // 'orig' stores the original state of the property
  9321. this._mixBufferRegion = mixFunction;
  9322. this.cumulativeWeight = 0;
  9323. this.useCount = 0;
  9324. this.referenceCount = 0;
  9325. };
  9326. THREE.PropertyMixer.prototype = {
  9327. constructor: THREE.PropertyMixer,
  9328. // accumulate data in the 'incoming' region into 'accu<i>'
  9329. accumulate: function( accuIndex, weight ) {
  9330. // note: happily accumulating nothing when weight = 0, the caller knows
  9331. // the weight and shouldn't have made the call in the first place
  9332. var buffer = this.buffer,
  9333. stride = this.valueSize,
  9334. offset = accuIndex * stride + stride,
  9335. currentWeight = this.cumulativeWeight;
  9336. if ( currentWeight === 0 ) {
  9337. // accuN := incoming * weight
  9338. for ( var i = 0; i !== stride; ++ i ) {
  9339. buffer[ offset + i ] = buffer[ i ];
  9340. }
  9341. currentWeight = weight;
  9342. } else {
  9343. // accuN := accuN + incoming * weight
  9344. currentWeight += weight;
  9345. var mix = weight / currentWeight;
  9346. this._mixBufferRegion( buffer, offset, 0, mix, stride );
  9347. }
  9348. this.cumulativeWeight = currentWeight;
  9349. },
  9350. // apply the state of 'accu<i>' to the binding when accus differ
  9351. apply: function( accuIndex ) {
  9352. var stride = this.valueSize,
  9353. buffer = this.buffer,
  9354. offset = accuIndex * stride + stride,
  9355. weight = this.cumulativeWeight,
  9356. binding = this.binding;
  9357. this.cumulativeWeight = 0;
  9358. if ( weight < 1 ) {
  9359. // accuN := accuN + original * ( 1 - cumulativeWeight )
  9360. var originalValueOffset = stride * 3;
  9361. this._mixBufferRegion(
  9362. buffer, offset, originalValueOffset, 1 - weight, stride );
  9363. }
  9364. for ( var i = stride, e = stride + stride; i !== e; ++ i ) {
  9365. if ( buffer[ i ] !== buffer[ i + stride ] ) {
  9366. // value has changed -> update scene graph
  9367. binding.setValue( buffer, offset );
  9368. break;
  9369. }
  9370. }
  9371. },
  9372. // remember the state of the bound property and copy it to both accus
  9373. saveOriginalState: function() {
  9374. var binding = this.binding;
  9375. var buffer = this.buffer,
  9376. stride = this.valueSize,
  9377. originalValueOffset = stride * 3;
  9378. binding.getValue( buffer, originalValueOffset );
  9379. // accu[0..1] := orig -- initially detect changes against the original
  9380. for ( var i = stride, e = originalValueOffset; i !== e; ++ i ) {
  9381. buffer[ i ] = buffer[ originalValueOffset + ( i % stride ) ];
  9382. }
  9383. this.cumulativeWeight = 0;
  9384. },
  9385. // apply the state previously taken via 'saveOriginalState' to the binding
  9386. restoreOriginalState: function() {
  9387. var originalValueOffset = this.valueSize * 3;
  9388. this.binding.setValue( this.buffer, originalValueOffset );
  9389. },
  9390. // mix functions
  9391. _select: function( buffer, dstOffset, srcOffset, t, stride ) {
  9392. if ( t >= 0.5 ) {
  9393. for ( var i = 0; i !== stride; ++ i ) {
  9394. buffer[ dstOffset + i ] = buffer[ srcOffset + i ];
  9395. }
  9396. }
  9397. },
  9398. _slerp: function( buffer, dstOffset, srcOffset, t, stride ) {
  9399. THREE.Quaternion.slerpFlat( buffer, dstOffset,
  9400. buffer, dstOffset, buffer, srcOffset, t );
  9401. },
  9402. _lerp: function( buffer, dstOffset, srcOffset, t, stride ) {
  9403. var s = 1 - t;
  9404. for ( var i = 0; i !== stride; ++ i ) {
  9405. var j = dstOffset + i;
  9406. buffer[ j ] = buffer[ j ] * s + buffer[ srcOffset + i ] * t;
  9407. }
  9408. }
  9409. };
  9410. // File:src/animation/tracks/BooleanKeyframeTrack.js
  9411. /**
  9412. *
  9413. * A Track of Boolean keyframe values.
  9414. *
  9415. *
  9416. * @author Ben Houston / http://clara.io/
  9417. * @author David Sarno / http://lighthaus.us/
  9418. * @author tschw
  9419. */
  9420. THREE.BooleanKeyframeTrack = function ( name, times, values ) {
  9421. THREE.KeyframeTrack.call( this, name, times, values );
  9422. };
  9423. THREE.BooleanKeyframeTrack.prototype =
  9424. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9425. constructor: THREE.BooleanKeyframeTrack,
  9426. ValueTypeName: 'bool',
  9427. ValueBufferType: Array,
  9428. DefaultInterpolation: THREE.InterpolateDiscrete,
  9429. InterpolantFactoryMethodLinear: undefined,
  9430. InterpolantFactoryMethodSmooth: undefined
  9431. // Note: Actually this track could have a optimized / compressed
  9432. // representation of a single value and a custom interpolant that
  9433. // computes "firstValue ^ isOdd( index )".
  9434. } );
  9435. // File:src/animation/tracks/ColorKeyframeTrack.js
  9436. /**
  9437. *
  9438. * A Track of keyframe values that represent color.
  9439. *
  9440. *
  9441. * @author Ben Houston / http://clara.io/
  9442. * @author David Sarno / http://lighthaus.us/
  9443. * @author tschw
  9444. */
  9445. THREE.ColorKeyframeTrack = function ( name, times, values, interpolation ) {
  9446. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9447. };
  9448. THREE.ColorKeyframeTrack.prototype =
  9449. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9450. constructor: THREE.ColorKeyframeTrack,
  9451. ValueTypeName: 'color'
  9452. // ValueBufferType is inherited
  9453. // DefaultInterpolation is inherited
  9454. // Note: Very basic implementation and nothing special yet.
  9455. // However, this is the place for color space parameterization.
  9456. } );
  9457. // File:src/animation/tracks/NumberKeyframeTrack.js
  9458. /**
  9459. *
  9460. * A Track of numeric keyframe values.
  9461. *
  9462. * @author Ben Houston / http://clara.io/
  9463. * @author David Sarno / http://lighthaus.us/
  9464. * @author tschw
  9465. */
  9466. THREE.NumberKeyframeTrack = function ( name, times, values, interpolation ) {
  9467. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9468. };
  9469. THREE.NumberKeyframeTrack.prototype =
  9470. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9471. constructor: THREE.NumberKeyframeTrack,
  9472. ValueTypeName: 'number',
  9473. // ValueBufferType is inherited
  9474. // DefaultInterpolation is inherited
  9475. } );
  9476. // File:src/animation/tracks/QuaternionKeyframeTrack.js
  9477. /**
  9478. *
  9479. * A Track of quaternion keyframe values.
  9480. *
  9481. * @author Ben Houston / http://clara.io/
  9482. * @author David Sarno / http://lighthaus.us/
  9483. * @author tschw
  9484. */
  9485. THREE.QuaternionKeyframeTrack = function ( name, times, values, interpolation ) {
  9486. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9487. };
  9488. THREE.QuaternionKeyframeTrack.prototype =
  9489. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9490. constructor: THREE.QuaternionKeyframeTrack,
  9491. ValueTypeName: 'quaternion',
  9492. // ValueBufferType is inherited
  9493. DefaultInterpolation: THREE.InterpolateLinear,
  9494. InterpolantFactoryMethodLinear: function( result ) {
  9495. return new THREE.QuaternionLinearInterpolant(
  9496. this.times, this.values, this.getValueSize(), result );
  9497. },
  9498. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  9499. } );
  9500. // File:src/animation/tracks/StringKeyframeTrack.js
  9501. /**
  9502. *
  9503. * A Track that interpolates Strings
  9504. *
  9505. *
  9506. * @author Ben Houston / http://clara.io/
  9507. * @author David Sarno / http://lighthaus.us/
  9508. * @author tschw
  9509. */
  9510. THREE.StringKeyframeTrack = function ( name, times, values, interpolation ) {
  9511. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9512. };
  9513. THREE.StringKeyframeTrack.prototype =
  9514. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9515. constructor: THREE.StringKeyframeTrack,
  9516. ValueTypeName: 'string',
  9517. ValueBufferType: Array,
  9518. DefaultInterpolation: THREE.InterpolateDiscrete,
  9519. InterpolantFactoryMethodLinear: undefined,
  9520. InterpolantFactoryMethodSmooth: undefined
  9521. } );
  9522. // File:src/animation/tracks/VectorKeyframeTrack.js
  9523. /**
  9524. *
  9525. * A Track of vectored keyframe values.
  9526. *
  9527. *
  9528. * @author Ben Houston / http://clara.io/
  9529. * @author David Sarno / http://lighthaus.us/
  9530. * @author tschw
  9531. */
  9532. THREE.VectorKeyframeTrack = function ( name, times, values, interpolation ) {
  9533. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9534. };
  9535. THREE.VectorKeyframeTrack.prototype =
  9536. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9537. constructor: THREE.VectorKeyframeTrack,
  9538. ValueTypeName: 'vector'
  9539. // ValueBufferType is inherited
  9540. // DefaultInterpolation is inherited
  9541. } );
  9542. // File:src/audio/Audio.js
  9543. /**
  9544. * @author mrdoob / http://mrdoob.com/
  9545. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  9546. */
  9547. THREE.Audio = function ( listener ) {
  9548. THREE.Object3D.call( this );
  9549. this.type = 'Audio';
  9550. this.context = listener.context;
  9551. this.source = this.context.createBufferSource();
  9552. this.source.onended = this.onEnded.bind( this );
  9553. this.gain = this.context.createGain();
  9554. this.gain.connect( listener.getInput() );
  9555. this.autoplay = false;
  9556. this.startTime = 0;
  9557. this.playbackRate = 1;
  9558. this.isPlaying = false;
  9559. this.hasPlaybackControl = true;
  9560. this.sourceType = 'empty';
  9561. this.filter = null;
  9562. };
  9563. THREE.Audio.prototype = Object.create( THREE.Object3D.prototype );
  9564. THREE.Audio.prototype.constructor = THREE.Audio;
  9565. THREE.Audio.prototype.getOutput = function () {
  9566. return this.gain;
  9567. };
  9568. THREE.Audio.prototype.setNodeSource = function ( audioNode ) {
  9569. this.hasPlaybackControl = false;
  9570. this.sourceType = 'audioNode';
  9571. this.source = audioNode;
  9572. this.connect();
  9573. return this;
  9574. };
  9575. THREE.Audio.prototype.setBuffer = function ( audioBuffer ) {
  9576. var scope = this;
  9577. scope.source.buffer = audioBuffer;
  9578. scope.sourceType = 'buffer';
  9579. if ( scope.autoplay ) scope.play();
  9580. return this;
  9581. };
  9582. THREE.Audio.prototype.play = function () {
  9583. if ( this.isPlaying === true ) {
  9584. console.warn( 'THREE.Audio: Audio is already playing.' );
  9585. return;
  9586. }
  9587. if ( this.hasPlaybackControl === false ) {
  9588. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9589. return;
  9590. }
  9591. var source = this.context.createBufferSource();
  9592. source.buffer = this.source.buffer;
  9593. source.loop = this.source.loop;
  9594. source.onended = this.source.onended;
  9595. source.start( 0, this.startTime );
  9596. source.playbackRate.value = this.playbackRate;
  9597. this.isPlaying = true;
  9598. this.source = source;
  9599. this.connect();
  9600. };
  9601. THREE.Audio.prototype.pause = function () {
  9602. if ( this.hasPlaybackControl === false ) {
  9603. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9604. return;
  9605. }
  9606. this.source.stop();
  9607. this.startTime = this.context.currentTime;
  9608. };
  9609. THREE.Audio.prototype.stop = function () {
  9610. if ( this.hasPlaybackControl === false ) {
  9611. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9612. return;
  9613. }
  9614. this.source.stop();
  9615. this.startTime = 0;
  9616. };
  9617. THREE.Audio.prototype.connect = function () {
  9618. if ( this.filter !== null ) {
  9619. this.source.connect( this.filter );
  9620. this.filter.connect( this.getOutput() );
  9621. } else {
  9622. this.source.connect( this.getOutput() );
  9623. }
  9624. };
  9625. THREE.Audio.prototype.disconnect = function () {
  9626. if ( this.filter !== null ) {
  9627. this.source.disconnect( this.filter );
  9628. this.filter.disconnect( this.getOutput() );
  9629. } else {
  9630. this.source.disconnect( this.getOutput() );
  9631. }
  9632. };
  9633. THREE.Audio.prototype.getFilter = function () {
  9634. return this.filter;
  9635. };
  9636. THREE.Audio.prototype.setFilter = function ( value ) {
  9637. if ( value === undefined ) value = null;
  9638. if ( this.isPlaying === true ) {
  9639. this.disconnect();
  9640. this.filter = value;
  9641. this.connect();
  9642. } else {
  9643. this.filter = value;
  9644. }
  9645. };
  9646. THREE.Audio.prototype.setPlaybackRate = function ( value ) {
  9647. if ( this.hasPlaybackControl === false ) {
  9648. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9649. return;
  9650. }
  9651. this.playbackRate = value;
  9652. if ( this.isPlaying === true ) {
  9653. this.source.playbackRate.value = this.playbackRate;
  9654. }
  9655. };
  9656. THREE.Audio.prototype.getPlaybackRate = function () {
  9657. return this.playbackRate;
  9658. };
  9659. THREE.Audio.prototype.onEnded = function () {
  9660. this.isPlaying = false;
  9661. };
  9662. THREE.Audio.prototype.setLoop = function ( value ) {
  9663. if ( this.hasPlaybackControl === false ) {
  9664. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9665. return;
  9666. }
  9667. this.source.loop = value;
  9668. };
  9669. THREE.Audio.prototype.getLoop = function () {
  9670. if ( this.hasPlaybackControl === false ) {
  9671. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9672. return false;
  9673. }
  9674. return this.source.loop;
  9675. };
  9676. THREE.Audio.prototype.setVolume = function ( value ) {
  9677. this.gain.gain.value = value;
  9678. };
  9679. THREE.Audio.prototype.getVolume = function () {
  9680. return this.gain.gain.value;
  9681. };
  9682. // File:src/audio/AudioAnalyser.js
  9683. /**
  9684. * @author mrdoob / http://mrdoob.com/
  9685. */
  9686. THREE.AudioAnalyser = function ( audio, fftSize ) {
  9687. this.analyser = audio.context.createAnalyser();
  9688. this.analyser.fftSize = fftSize !== undefined ? fftSize : 2048;
  9689. this.data = new Uint8Array( this.analyser.frequencyBinCount );
  9690. audio.getOutput().connect( this.analyser );
  9691. };
  9692. THREE.AudioAnalyser.prototype = {
  9693. constructor: THREE.AudioAnalyser,
  9694. getData: function () {
  9695. this.analyser.getByteFrequencyData( this.data );
  9696. return this.data;
  9697. }
  9698. };
  9699. // File:src/audio/AudioContext.js
  9700. /**
  9701. * @author mrdoob / http://mrdoob.com/
  9702. */
  9703. Object.defineProperty( THREE, 'AudioContext', {
  9704. get: ( function () {
  9705. var context;
  9706. return function () {
  9707. if ( context === undefined ) {
  9708. context = new ( window.AudioContext || window.webkitAudioContext )();
  9709. }
  9710. return context;
  9711. };
  9712. } )()
  9713. } );
  9714. // File:src/audio/PositionalAudio.js
  9715. /**
  9716. * @author mrdoob / http://mrdoob.com/
  9717. */
  9718. THREE.PositionalAudio = function ( listener ) {
  9719. THREE.Audio.call( this, listener );
  9720. this.panner = this.context.createPanner();
  9721. this.panner.connect( this.gain );
  9722. };
  9723. THREE.PositionalAudio.prototype = Object.create( THREE.Audio.prototype );
  9724. THREE.PositionalAudio.prototype.constructor = THREE.PositionalAudio;
  9725. THREE.PositionalAudio.prototype.getOutput = function () {
  9726. return this.panner;
  9727. };
  9728. THREE.PositionalAudio.prototype.setRefDistance = function ( value ) {
  9729. this.panner.refDistance = value;
  9730. };
  9731. THREE.PositionalAudio.prototype.getRefDistance = function () {
  9732. return this.panner.refDistance;
  9733. };
  9734. THREE.PositionalAudio.prototype.setRolloffFactor = function ( value ) {
  9735. this.panner.rolloffFactor = value;
  9736. };
  9737. THREE.PositionalAudio.prototype.getRolloffFactor = function () {
  9738. return this.panner.rolloffFactor;
  9739. };
  9740. THREE.PositionalAudio.prototype.setDistanceModel = function ( value ) {
  9741. this.panner.distanceModel = value;
  9742. };
  9743. THREE.PositionalAudio.prototype.getDistanceModel = function () {
  9744. return this.panner.distanceModel;
  9745. };
  9746. THREE.PositionalAudio.prototype.setMaxDistance = function ( value ) {
  9747. this.panner.maxDistance = value;
  9748. };
  9749. THREE.PositionalAudio.prototype.getMaxDistance = function () {
  9750. return this.panner.maxDistance;
  9751. };
  9752. THREE.PositionalAudio.prototype.updateMatrixWorld = ( function () {
  9753. var position = new THREE.Vector3();
  9754. return function updateMatrixWorld( force ) {
  9755. THREE.Object3D.prototype.updateMatrixWorld.call( this, force );
  9756. position.setFromMatrixPosition( this.matrixWorld );
  9757. this.panner.setPosition( position.x, position.y, position.z );
  9758. };
  9759. } )();
  9760. // File:src/audio/AudioListener.js
  9761. /**
  9762. * @author mrdoob / http://mrdoob.com/
  9763. */
  9764. THREE.AudioListener = function () {
  9765. THREE.Object3D.call( this );
  9766. this.type = 'AudioListener';
  9767. this.context = THREE.AudioContext;
  9768. this.gain = this.context.createGain();
  9769. this.gain.connect( this.context.destination );
  9770. this.filter = null;
  9771. };
  9772. THREE.AudioListener.prototype = Object.create( THREE.Object3D.prototype );
  9773. THREE.AudioListener.prototype.constructor = THREE.AudioListener;
  9774. THREE.AudioListener.prototype.getInput = function () {
  9775. return this.gain;
  9776. };
  9777. THREE.AudioListener.prototype.removeFilter = function ( ) {
  9778. if ( this.filter !== null ) {
  9779. this.gain.disconnect( this.filter );
  9780. this.filter.disconnect( this.context.destination );
  9781. this.gain.connect( this.context.destination );
  9782. this.filter = null;
  9783. }
  9784. };
  9785. THREE.AudioListener.prototype.setFilter = function ( value ) {
  9786. if ( this.filter !== null ) {
  9787. this.gain.disconnect( this.filter );
  9788. this.filter.disconnect( this.context.destination );
  9789. } else {
  9790. this.gain.disconnect( this.context.destination );
  9791. }
  9792. this.filter = value;
  9793. this.gain.connect( this.filter );
  9794. this.filter.connect( this.context.destination );
  9795. };
  9796. THREE.AudioListener.prototype.getFilter = function () {
  9797. return this.filter;
  9798. };
  9799. THREE.AudioListener.prototype.setMasterVolume = function ( value ) {
  9800. this.gain.gain.value = value;
  9801. };
  9802. THREE.AudioListener.prototype.getMasterVolume = function () {
  9803. return this.gain.gain.value;
  9804. };
  9805. THREE.AudioListener.prototype.updateMatrixWorld = ( function () {
  9806. var position = new THREE.Vector3();
  9807. var quaternion = new THREE.Quaternion();
  9808. var scale = new THREE.Vector3();
  9809. var orientation = new THREE.Vector3();
  9810. return function updateMatrixWorld( force ) {
  9811. THREE.Object3D.prototype.updateMatrixWorld.call( this, force );
  9812. var listener = this.context.listener;
  9813. var up = this.up;
  9814. this.matrixWorld.decompose( position, quaternion, scale );
  9815. orientation.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  9816. listener.setPosition( position.x, position.y, position.z );
  9817. listener.setOrientation( orientation.x, orientation.y, orientation.z, up.x, up.y, up.z );
  9818. };
  9819. } )();
  9820. // File:src/cameras/Camera.js
  9821. /**
  9822. * @author mrdoob / http://mrdoob.com/
  9823. * @author mikael emtinger / http://gomo.se/
  9824. * @author WestLangley / http://github.com/WestLangley
  9825. */
  9826. THREE.Camera = function () {
  9827. THREE.Object3D.call( this );
  9828. this.type = 'Camera';
  9829. this.matrixWorldInverse = new THREE.Matrix4();
  9830. this.projectionMatrix = new THREE.Matrix4();
  9831. };
  9832. THREE.Camera.prototype = Object.create( THREE.Object3D.prototype );
  9833. THREE.Camera.prototype.constructor = THREE.Camera;
  9834. THREE.Camera.prototype.getWorldDirection = function () {
  9835. var quaternion = new THREE.Quaternion();
  9836. return function ( optionalTarget ) {
  9837. var result = optionalTarget || new THREE.Vector3();
  9838. this.getWorldQuaternion( quaternion );
  9839. return result.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  9840. };
  9841. }();
  9842. THREE.Camera.prototype.lookAt = function () {
  9843. // This routine does not support cameras with rotated and/or translated parent(s)
  9844. var m1 = new THREE.Matrix4();
  9845. return function ( vector ) {
  9846. m1.lookAt( this.position, vector, this.up );
  9847. this.quaternion.setFromRotationMatrix( m1 );
  9848. };
  9849. }();
  9850. THREE.Camera.prototype.clone = function () {
  9851. return new this.constructor().copy( this );
  9852. };
  9853. THREE.Camera.prototype.copy = function ( source ) {
  9854. THREE.Object3D.prototype.copy.call( this, source );
  9855. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  9856. this.projectionMatrix.copy( source.projectionMatrix );
  9857. return this;
  9858. };
  9859. // File:src/cameras/CubeCamera.js
  9860. /**
  9861. * Camera for rendering cube maps
  9862. * - renders scene into axis-aligned cube
  9863. *
  9864. * @author alteredq / http://alteredqualia.com/
  9865. */
  9866. THREE.CubeCamera = function ( near, far, cubeResolution ) {
  9867. THREE.Object3D.call( this );
  9868. this.type = 'CubeCamera';
  9869. var fov = 90, aspect = 1;
  9870. var cameraPX = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9871. cameraPX.up.set( 0, - 1, 0 );
  9872. cameraPX.lookAt( new THREE.Vector3( 1, 0, 0 ) );
  9873. this.add( cameraPX );
  9874. var cameraNX = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9875. cameraNX.up.set( 0, - 1, 0 );
  9876. cameraNX.lookAt( new THREE.Vector3( - 1, 0, 0 ) );
  9877. this.add( cameraNX );
  9878. var cameraPY = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9879. cameraPY.up.set( 0, 0, 1 );
  9880. cameraPY.lookAt( new THREE.Vector3( 0, 1, 0 ) );
  9881. this.add( cameraPY );
  9882. var cameraNY = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9883. cameraNY.up.set( 0, 0, - 1 );
  9884. cameraNY.lookAt( new THREE.Vector3( 0, - 1, 0 ) );
  9885. this.add( cameraNY );
  9886. var cameraPZ = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9887. cameraPZ.up.set( 0, - 1, 0 );
  9888. cameraPZ.lookAt( new THREE.Vector3( 0, 0, 1 ) );
  9889. this.add( cameraPZ );
  9890. var cameraNZ = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9891. cameraNZ.up.set( 0, - 1, 0 );
  9892. cameraNZ.lookAt( new THREE.Vector3( 0, 0, - 1 ) );
  9893. this.add( cameraNZ );
  9894. var options = { format: THREE.RGBFormat, magFilter: THREE.LinearFilter, minFilter: THREE.LinearFilter };
  9895. this.renderTarget = new THREE.WebGLRenderTargetCube( cubeResolution, cubeResolution, options );
  9896. this.updateCubeMap = function ( renderer, scene ) {
  9897. if ( this.parent === null ) this.updateMatrixWorld();
  9898. var renderTarget = this.renderTarget;
  9899. var generateMipmaps = renderTarget.texture.generateMipmaps;
  9900. renderTarget.texture.generateMipmaps = false;
  9901. renderTarget.activeCubeFace = 0;
  9902. renderer.render( scene, cameraPX, renderTarget );
  9903. renderTarget.activeCubeFace = 1;
  9904. renderer.render( scene, cameraNX, renderTarget );
  9905. renderTarget.activeCubeFace = 2;
  9906. renderer.render( scene, cameraPY, renderTarget );
  9907. renderTarget.activeCubeFace = 3;
  9908. renderer.render( scene, cameraNY, renderTarget );
  9909. renderTarget.activeCubeFace = 4;
  9910. renderer.render( scene, cameraPZ, renderTarget );
  9911. renderTarget.texture.generateMipmaps = generateMipmaps;
  9912. renderTarget.activeCubeFace = 5;
  9913. renderer.render( scene, cameraNZ, renderTarget );
  9914. renderer.setRenderTarget( null );
  9915. };
  9916. };
  9917. THREE.CubeCamera.prototype = Object.create( THREE.Object3D.prototype );
  9918. THREE.CubeCamera.prototype.constructor = THREE.CubeCamera;
  9919. // File:src/cameras/OrthographicCamera.js
  9920. /**
  9921. * @author alteredq / http://alteredqualia.com/
  9922. */
  9923. THREE.OrthographicCamera = function ( left, right, top, bottom, near, far ) {
  9924. THREE.Camera.call( this );
  9925. this.type = 'OrthographicCamera';
  9926. this.zoom = 1;
  9927. this.left = left;
  9928. this.right = right;
  9929. this.top = top;
  9930. this.bottom = bottom;
  9931. this.near = ( near !== undefined ) ? near : 0.1;
  9932. this.far = ( far !== undefined ) ? far : 2000;
  9933. this.updateProjectionMatrix();
  9934. };
  9935. THREE.OrthographicCamera.prototype = Object.create( THREE.Camera.prototype );
  9936. THREE.OrthographicCamera.prototype.constructor = THREE.OrthographicCamera;
  9937. THREE.OrthographicCamera.prototype.updateProjectionMatrix = function () {
  9938. var dx = ( this.right - this.left ) / ( 2 * this.zoom );
  9939. var dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  9940. var cx = ( this.right + this.left ) / 2;
  9941. var cy = ( this.top + this.bottom ) / 2;
  9942. this.projectionMatrix.makeOrthographic( cx - dx, cx + dx, cy + dy, cy - dy, this.near, this.far );
  9943. };
  9944. THREE.OrthographicCamera.prototype.copy = function ( source ) {
  9945. THREE.Camera.prototype.copy.call( this, source );
  9946. this.left = source.left;
  9947. this.right = source.right;
  9948. this.top = source.top;
  9949. this.bottom = source.bottom;
  9950. this.near = source.near;
  9951. this.far = source.far;
  9952. this.zoom = source.zoom;
  9953. return this;
  9954. };
  9955. THREE.OrthographicCamera.prototype.toJSON = function ( meta ) {
  9956. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  9957. data.object.zoom = this.zoom;
  9958. data.object.left = this.left;
  9959. data.object.right = this.right;
  9960. data.object.top = this.top;
  9961. data.object.bottom = this.bottom;
  9962. data.object.near = this.near;
  9963. data.object.far = this.far;
  9964. return data;
  9965. };
  9966. // File:src/cameras/PerspectiveCamera.js
  9967. /**
  9968. * @author mrdoob / http://mrdoob.com/
  9969. * @author greggman / http://games.greggman.com/
  9970. * @author zz85 / http://www.lab4games.net/zz85/blog
  9971. * @author tschw
  9972. */
  9973. THREE.PerspectiveCamera = function( fov, aspect, near, far ) {
  9974. THREE.Camera.call( this );
  9975. this.type = 'PerspectiveCamera';
  9976. this.fov = fov !== undefined ? fov : 50;
  9977. this.zoom = 1;
  9978. this.near = near !== undefined ? near : 0.1;
  9979. this.far = far !== undefined ? far : 2000;
  9980. this.focus = 10;
  9981. this.aspect = aspect !== undefined ? aspect : 1;
  9982. this.view = null;
  9983. this.filmGauge = 35; // width of the film (default in millimeters)
  9984. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  9985. this.updateProjectionMatrix();
  9986. };
  9987. THREE.PerspectiveCamera.prototype = Object.create( THREE.Camera.prototype );
  9988. THREE.PerspectiveCamera.prototype.constructor = THREE.PerspectiveCamera;
  9989. /**
  9990. * Sets the FOV by focal length (DEPRECATED).
  9991. *
  9992. * Optionally also sets .filmGauge, otherwise uses it. See .setFocalLength.
  9993. */
  9994. THREE.PerspectiveCamera.prototype.setLens = function( focalLength, filmGauge ) {
  9995. console.warn( "THREE.PerspectiveCamera.setLens is deprecated. " +
  9996. "Use .setFocalLength and .filmGauge for a photographic setup." );
  9997. if ( filmGauge !== undefined ) this.filmGauge = filmGauge;
  9998. this.setFocalLength( focalLength );
  9999. };
  10000. /**
  10001. * Sets the FOV by focal length in respect to the current .filmGauge.
  10002. *
  10003. * The default film gauge is 35, so that the focal length can be specified for
  10004. * a 35mm (full frame) camera.
  10005. *
  10006. * Values for focal length and film gauge must have the same unit.
  10007. */
  10008. THREE.PerspectiveCamera.prototype.setFocalLength = function( focalLength ) {
  10009. // see http://www.bobatkins.com/photography/technical/field_of_view.html
  10010. var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  10011. this.fov = THREE.Math.RAD2DEG * 2 * Math.atan( vExtentSlope );
  10012. this.updateProjectionMatrix();
  10013. };
  10014. /**
  10015. * Calculates the focal length from the current .fov and .filmGauge.
  10016. */
  10017. THREE.PerspectiveCamera.prototype.getFocalLength = function() {
  10018. var vExtentSlope = Math.tan( THREE.Math.DEG2RAD * 0.5 * this.fov );
  10019. return 0.5 * this.getFilmHeight() / vExtentSlope;
  10020. };
  10021. THREE.PerspectiveCamera.prototype.getEffectiveFOV = function() {
  10022. return THREE.Math.RAD2DEG * 2 * Math.atan(
  10023. Math.tan( THREE.Math.DEG2RAD * 0.5 * this.fov ) / this.zoom );
  10024. };
  10025. THREE.PerspectiveCamera.prototype.getFilmWidth = function() {
  10026. // film not completely covered in portrait format (aspect < 1)
  10027. return this.filmGauge * Math.min( this.aspect, 1 );
  10028. };
  10029. THREE.PerspectiveCamera.prototype.getFilmHeight = function() {
  10030. // film not completely covered in landscape format (aspect > 1)
  10031. return this.filmGauge / Math.max( this.aspect, 1 );
  10032. };
  10033. /**
  10034. * Sets an offset in a larger frustum. This is useful for multi-window or
  10035. * multi-monitor/multi-machine setups.
  10036. *
  10037. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  10038. * the monitors are in grid like this
  10039. *
  10040. * +---+---+---+
  10041. * | A | B | C |
  10042. * +---+---+---+
  10043. * | D | E | F |
  10044. * +---+---+---+
  10045. *
  10046. * then for each monitor you would call it like this
  10047. *
  10048. * var w = 1920;
  10049. * var h = 1080;
  10050. * var fullWidth = w * 3;
  10051. * var fullHeight = h * 2;
  10052. *
  10053. * --A--
  10054. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  10055. * --B--
  10056. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  10057. * --C--
  10058. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  10059. * --D--
  10060. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  10061. * --E--
  10062. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  10063. * --F--
  10064. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  10065. *
  10066. * Note there is no reason monitors have to be the same size or in a grid.
  10067. */
  10068. THREE.PerspectiveCamera.prototype.setViewOffset = function( fullWidth, fullHeight, x, y, width, height ) {
  10069. this.aspect = fullWidth / fullHeight;
  10070. this.view = {
  10071. fullWidth: fullWidth,
  10072. fullHeight: fullHeight,
  10073. offsetX: x,
  10074. offsetY: y,
  10075. width: width,
  10076. height: height
  10077. };
  10078. this.updateProjectionMatrix();
  10079. };
  10080. THREE.PerspectiveCamera.prototype.updateProjectionMatrix = function() {
  10081. var near = this.near,
  10082. top = near * Math.tan(
  10083. THREE.Math.DEG2RAD * 0.5 * this.fov ) / this.zoom,
  10084. height = 2 * top,
  10085. width = this.aspect * height,
  10086. left = - 0.5 * width,
  10087. view = this.view;
  10088. if ( view !== null ) {
  10089. var fullWidth = view.fullWidth,
  10090. fullHeight = view.fullHeight;
  10091. left += view.offsetX * width / fullWidth;
  10092. top -= view.offsetY * height / fullHeight;
  10093. width *= view.width / fullWidth;
  10094. height *= view.height / fullHeight;
  10095. }
  10096. var skew = this.filmOffset;
  10097. if ( skew !== 0 ) left += near * skew / this.getFilmWidth();
  10098. this.projectionMatrix.makeFrustum(
  10099. left, left + width, top - height, top, near, this.far );
  10100. };
  10101. THREE.PerspectiveCamera.prototype.copy = function( source ) {
  10102. THREE.Camera.prototype.copy.call( this, source );
  10103. this.fov = source.fov;
  10104. this.zoom = source.zoom;
  10105. this.near = source.near;
  10106. this.far = source.far;
  10107. this.focus = source.focus;
  10108. this.aspect = source.aspect;
  10109. this.view = source.view === null ? null : Object.assign( {}, source.view );
  10110. this.filmGauge = source.filmGauge;
  10111. this.filmOffset = source.filmOffset;
  10112. return this;
  10113. };
  10114. THREE.PerspectiveCamera.prototype.toJSON = function( meta ) {
  10115. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  10116. data.object.fov = this.fov;
  10117. data.object.zoom = this.zoom;
  10118. data.object.near = this.near;
  10119. data.object.far = this.far;
  10120. data.object.focus = this.focus;
  10121. data.object.aspect = this.aspect;
  10122. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  10123. data.object.filmGauge = this.filmGauge;
  10124. data.object.filmOffset = this.filmOffset;
  10125. return data;
  10126. };
  10127. // File:src/cameras/StereoCamera.js
  10128. /**
  10129. * @author mrdoob / http://mrdoob.com/
  10130. */
  10131. THREE.StereoCamera = function () {
  10132. this.type = 'StereoCamera';
  10133. this.aspect = 1;
  10134. this.cameraL = new THREE.PerspectiveCamera();
  10135. this.cameraL.layers.enable( 1 );
  10136. this.cameraL.matrixAutoUpdate = false;
  10137. this.cameraR = new THREE.PerspectiveCamera();
  10138. this.cameraR.layers.enable( 2 );
  10139. this.cameraR.matrixAutoUpdate = false;
  10140. };
  10141. THREE.StereoCamera.prototype = {
  10142. constructor: THREE.StereoCamera,
  10143. update: ( function () {
  10144. var focus, fov, aspect, near, far;
  10145. var eyeRight = new THREE.Matrix4();
  10146. var eyeLeft = new THREE.Matrix4();
  10147. return function update ( camera ) {
  10148. var needsUpdate = focus !== camera.focus || fov !== camera.fov ||
  10149. aspect !== camera.aspect * this.aspect || near !== camera.near ||
  10150. far !== camera.far;
  10151. if ( needsUpdate ) {
  10152. focus = camera.focus;
  10153. fov = camera.fov;
  10154. aspect = camera.aspect * this.aspect;
  10155. near = camera.near;
  10156. far = camera.far;
  10157. // Off-axis stereoscopic effect based on
  10158. // http://paulbourke.net/stereographics/stereorender/
  10159. var projectionMatrix = camera.projectionMatrix.clone();
  10160. var eyeSep = 0.064 / 2;
  10161. var eyeSepOnProjection = eyeSep * near / focus;
  10162. var ymax = near * Math.tan( THREE.Math.DEG2RAD * fov * 0.5 );
  10163. var xmin, xmax;
  10164. // translate xOffset
  10165. eyeLeft.elements[ 12 ] = - eyeSep;
  10166. eyeRight.elements[ 12 ] = eyeSep;
  10167. // for left eye
  10168. xmin = - ymax * aspect + eyeSepOnProjection;
  10169. xmax = ymax * aspect + eyeSepOnProjection;
  10170. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  10171. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  10172. this.cameraL.projectionMatrix.copy( projectionMatrix );
  10173. // for right eye
  10174. xmin = - ymax * aspect - eyeSepOnProjection;
  10175. xmax = ymax * aspect - eyeSepOnProjection;
  10176. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  10177. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  10178. this.cameraR.projectionMatrix.copy( projectionMatrix );
  10179. }
  10180. this.cameraL.matrixWorld.copy( camera.matrixWorld ).multiply( eyeLeft );
  10181. this.cameraR.matrixWorld.copy( camera.matrixWorld ).multiply( eyeRight );
  10182. };
  10183. } )()
  10184. };
  10185. // File:src/lights/Light.js
  10186. /**
  10187. * @author mrdoob / http://mrdoob.com/
  10188. * @author alteredq / http://alteredqualia.com/
  10189. */
  10190. THREE.Light = function ( color, intensity ) {
  10191. THREE.Object3D.call( this );
  10192. this.type = 'Light';
  10193. this.color = new THREE.Color( color );
  10194. this.intensity = intensity !== undefined ? intensity : 1;
  10195. this.receiveShadow = undefined;
  10196. };
  10197. THREE.Light.prototype = Object.create( THREE.Object3D.prototype );
  10198. THREE.Light.prototype.constructor = THREE.Light;
  10199. THREE.Light.prototype.copy = function ( source ) {
  10200. THREE.Object3D.prototype.copy.call( this, source );
  10201. this.color.copy( source.color );
  10202. this.intensity = source.intensity;
  10203. return this;
  10204. };
  10205. THREE.Light.prototype.toJSON = function ( meta ) {
  10206. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  10207. data.object.color = this.color.getHex();
  10208. data.object.intensity = this.intensity;
  10209. if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();
  10210. if ( this.distance !== undefined ) data.object.distance = this.distance;
  10211. if ( this.angle !== undefined ) data.object.angle = this.angle;
  10212. if ( this.decay !== undefined ) data.object.decay = this.decay;
  10213. if ( this.penumbra !== undefined ) data.object.penumbra = this.penumbra;
  10214. return data;
  10215. };
  10216. // File:src/lights/LightShadow.js
  10217. /**
  10218. * @author mrdoob / http://mrdoob.com/
  10219. */
  10220. THREE.LightShadow = function ( camera ) {
  10221. this.camera = camera;
  10222. this.bias = 0;
  10223. this.radius = 1;
  10224. this.mapSize = new THREE.Vector2( 512, 512 );
  10225. this.map = null;
  10226. this.matrix = new THREE.Matrix4();
  10227. };
  10228. THREE.LightShadow.prototype = {
  10229. constructor: THREE.LightShadow,
  10230. copy: function ( source ) {
  10231. this.camera = source.camera.clone();
  10232. this.bias = source.bias;
  10233. this.radius = source.radius;
  10234. this.mapSize.copy( source.mapSize );
  10235. return this;
  10236. },
  10237. clone: function () {
  10238. return new this.constructor().copy( this );
  10239. }
  10240. };
  10241. // File:src/lights/AmbientLight.js
  10242. /**
  10243. * @author mrdoob / http://mrdoob.com/
  10244. */
  10245. THREE.AmbientLight = function ( color, intensity ) {
  10246. THREE.Light.call( this, color, intensity );
  10247. this.type = 'AmbientLight';
  10248. this.castShadow = undefined;
  10249. };
  10250. THREE.AmbientLight.prototype = Object.create( THREE.Light.prototype );
  10251. THREE.AmbientLight.prototype.constructor = THREE.AmbientLight;
  10252. // File:src/lights/DirectionalLight.js
  10253. /**
  10254. * @author mrdoob / http://mrdoob.com/
  10255. * @author alteredq / http://alteredqualia.com/
  10256. */
  10257. THREE.DirectionalLight = function ( color, intensity ) {
  10258. THREE.Light.call( this, color, intensity );
  10259. this.type = 'DirectionalLight';
  10260. this.position.set( 0, 1, 0 );
  10261. this.updateMatrix();
  10262. this.target = new THREE.Object3D();
  10263. this.shadow = new THREE.DirectionalLightShadow();
  10264. };
  10265. THREE.DirectionalLight.prototype = Object.create( THREE.Light.prototype );
  10266. THREE.DirectionalLight.prototype.constructor = THREE.DirectionalLight;
  10267. THREE.DirectionalLight.prototype.copy = function ( source ) {
  10268. THREE.Light.prototype.copy.call( this, source );
  10269. this.target = source.target.clone();
  10270. this.shadow = source.shadow.clone();
  10271. return this;
  10272. };
  10273. // File:src/lights/DirectionalLightShadow.js
  10274. /**
  10275. * @author mrdoob / http://mrdoob.com/
  10276. */
  10277. THREE.DirectionalLightShadow = function ( light ) {
  10278. THREE.LightShadow.call( this, new THREE.OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) );
  10279. };
  10280. THREE.DirectionalLightShadow.prototype = Object.create( THREE.LightShadow.prototype );
  10281. THREE.DirectionalLightShadow.prototype.constructor = THREE.DirectionalLightShadow;
  10282. // File:src/lights/HemisphereLight.js
  10283. /**
  10284. * @author alteredq / http://alteredqualia.com/
  10285. */
  10286. THREE.HemisphereLight = function ( skyColor, groundColor, intensity ) {
  10287. THREE.Light.call( this, skyColor, intensity );
  10288. this.type = 'HemisphereLight';
  10289. this.castShadow = undefined;
  10290. this.position.set( 0, 1, 0 );
  10291. this.updateMatrix();
  10292. this.groundColor = new THREE.Color( groundColor );
  10293. };
  10294. THREE.HemisphereLight.prototype = Object.create( THREE.Light.prototype );
  10295. THREE.HemisphereLight.prototype.constructor = THREE.HemisphereLight;
  10296. THREE.HemisphereLight.prototype.copy = function ( source ) {
  10297. THREE.Light.prototype.copy.call( this, source );
  10298. this.groundColor.copy( source.groundColor );
  10299. return this;
  10300. };
  10301. // File:src/lights/PointLight.js
  10302. /**
  10303. * @author mrdoob / http://mrdoob.com/
  10304. */
  10305. THREE.PointLight = function ( color, intensity, distance, decay ) {
  10306. THREE.Light.call( this, color, intensity );
  10307. this.type = 'PointLight';
  10308. this.distance = ( distance !== undefined ) ? distance : 0;
  10309. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  10310. this.shadow = new THREE.LightShadow( new THREE.PerspectiveCamera( 90, 1, 0.5, 500 ) );
  10311. };
  10312. THREE.PointLight.prototype = Object.create( THREE.Light.prototype );
  10313. THREE.PointLight.prototype.constructor = THREE.PointLight;
  10314. Object.defineProperty( THREE.PointLight.prototype, "power", {
  10315. get: function () {
  10316. // intensity = power per solid angle.
  10317. // ref: equation (15) from http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
  10318. return this.intensity * 4 * Math.PI;
  10319. },
  10320. set: function ( power ) {
  10321. // intensity = power per solid angle.
  10322. // ref: equation (15) from http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
  10323. this.intensity = power / ( 4 * Math.PI );
  10324. }
  10325. } );
  10326. THREE.PointLight.prototype.copy = function ( source ) {
  10327. THREE.Light.prototype.copy.call( this, source );
  10328. this.distance = source.distance;
  10329. this.decay = source.decay;
  10330. this.shadow = source.shadow.clone();
  10331. return this;
  10332. };
  10333. // File:src/lights/SpotLight.js
  10334. /**
  10335. * @author alteredq / http://alteredqualia.com/
  10336. */
  10337. THREE.SpotLight = function ( color, intensity, distance, angle, penumbra, decay ) {
  10338. THREE.Light.call( this, color, intensity );
  10339. this.type = 'SpotLight';
  10340. this.position.set( 0, 1, 0 );
  10341. this.updateMatrix();
  10342. this.target = new THREE.Object3D();
  10343. this.distance = ( distance !== undefined ) ? distance : 0;
  10344. this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
  10345. this.penumbra = ( penumbra !== undefined ) ? penumbra : 0;
  10346. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  10347. this.shadow = new THREE.SpotLightShadow();
  10348. };
  10349. THREE.SpotLight.prototype = Object.create( THREE.Light.prototype );
  10350. THREE.SpotLight.prototype.constructor = THREE.SpotLight;
  10351. Object.defineProperty( THREE.SpotLight.prototype, "power", {
  10352. get: function () {
  10353. // intensity = power per solid angle.
  10354. // ref: equation (17) from http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
  10355. return this.intensity * Math.PI;
  10356. },
  10357. set: function ( power ) {
  10358. // intensity = power per solid angle.
  10359. // ref: equation (17) from http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
  10360. this.intensity = power / Math.PI;
  10361. }
  10362. } );
  10363. THREE.SpotLight.prototype.copy = function ( source ) {
  10364. THREE.Light.prototype.copy.call( this, source );
  10365. this.distance = source.distance;
  10366. this.angle = source.angle;
  10367. this.penumbra = source.penumbra;
  10368. this.decay = source.decay;
  10369. this.target = source.target.clone();
  10370. this.shadow = source.shadow.clone();
  10371. return this;
  10372. };
  10373. // File:src/lights/SpotLightShadow.js
  10374. /**
  10375. * @author mrdoob / http://mrdoob.com/
  10376. */
  10377. THREE.SpotLightShadow = function () {
  10378. THREE.LightShadow.call( this, new THREE.PerspectiveCamera( 50, 1, 0.5, 500 ) );
  10379. };
  10380. THREE.SpotLightShadow.prototype = Object.create( THREE.LightShadow.prototype );
  10381. THREE.SpotLightShadow.prototype.constructor = THREE.SpotLightShadow;
  10382. THREE.SpotLightShadow.prototype.update = function ( light ) {
  10383. var fov = THREE.Math.RAD2DEG * 2 * light.angle;
  10384. var aspect = this.mapSize.width / this.mapSize.height;
  10385. var far = light.distance || 500;
  10386. var camera = this.camera;
  10387. if ( fov !== camera.fov || aspect !== camera.aspect || far !== camera.far ) {
  10388. camera.fov = fov;
  10389. camera.aspect = aspect;
  10390. camera.far = far;
  10391. camera.updateProjectionMatrix();
  10392. }
  10393. };
  10394. // File:src/loaders/AudioLoader.js
  10395. /**
  10396. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  10397. */
  10398. THREE.AudioLoader = function ( manager ) {
  10399. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10400. };
  10401. THREE.AudioLoader.prototype = {
  10402. constructor: THREE.AudioLoader,
  10403. load: function ( url, onLoad, onProgress, onError ) {
  10404. var loader = new THREE.XHRLoader( this.manager );
  10405. loader.setResponseType( 'arraybuffer' );
  10406. loader.load( url, function ( buffer ) {
  10407. var context = THREE.AudioContext;
  10408. context.decodeAudioData( buffer, function ( audioBuffer ) {
  10409. onLoad( audioBuffer );
  10410. } );
  10411. }, onProgress, onError );
  10412. }
  10413. };
  10414. // File:src/loaders/Cache.js
  10415. /**
  10416. * @author mrdoob / http://mrdoob.com/
  10417. */
  10418. THREE.Cache = {
  10419. enabled: false,
  10420. files: {},
  10421. add: function ( key, file ) {
  10422. if ( this.enabled === false ) return;
  10423. // console.log( 'THREE.Cache', 'Adding key:', key );
  10424. this.files[ key ] = file;
  10425. },
  10426. get: function ( key ) {
  10427. if ( this.enabled === false ) return;
  10428. // console.log( 'THREE.Cache', 'Checking key:', key );
  10429. return this.files[ key ];
  10430. },
  10431. remove: function ( key ) {
  10432. delete this.files[ key ];
  10433. },
  10434. clear: function () {
  10435. this.files = {};
  10436. }
  10437. };
  10438. // File:src/loaders/Loader.js
  10439. /**
  10440. * @author alteredq / http://alteredqualia.com/
  10441. */
  10442. THREE.Loader = function () {
  10443. this.onLoadStart = function () {};
  10444. this.onLoadProgress = function () {};
  10445. this.onLoadComplete = function () {};
  10446. };
  10447. THREE.Loader.prototype = {
  10448. constructor: THREE.Loader,
  10449. crossOrigin: undefined,
  10450. extractUrlBase: function ( url ) {
  10451. var parts = url.split( '/' );
  10452. if ( parts.length === 1 ) return './';
  10453. parts.pop();
  10454. return parts.join( '/' ) + '/';
  10455. },
  10456. initMaterials: function ( materials, texturePath, crossOrigin ) {
  10457. var array = [];
  10458. for ( var i = 0; i < materials.length; ++ i ) {
  10459. array[ i ] = this.createMaterial( materials[ i ], texturePath, crossOrigin );
  10460. }
  10461. return array;
  10462. },
  10463. createMaterial: ( function () {
  10464. var color, textureLoader, materialLoader;
  10465. return function ( m, texturePath, crossOrigin ) {
  10466. if ( color === undefined ) color = new THREE.Color();
  10467. if ( textureLoader === undefined ) textureLoader = new THREE.TextureLoader();
  10468. if ( materialLoader === undefined ) materialLoader = new THREE.MaterialLoader();
  10469. // convert from old material format
  10470. var textures = {};
  10471. function loadTexture( path, repeat, offset, wrap, anisotropy ) {
  10472. var fullPath = texturePath + path;
  10473. var loader = THREE.Loader.Handlers.get( fullPath );
  10474. var texture;
  10475. if ( loader !== null ) {
  10476. texture = loader.load( fullPath );
  10477. } else {
  10478. textureLoader.setCrossOrigin( crossOrigin );
  10479. texture = textureLoader.load( fullPath );
  10480. }
  10481. if ( repeat !== undefined ) {
  10482. texture.repeat.fromArray( repeat );
  10483. if ( repeat[ 0 ] !== 1 ) texture.wrapS = THREE.RepeatWrapping;
  10484. if ( repeat[ 1 ] !== 1 ) texture.wrapT = THREE.RepeatWrapping;
  10485. }
  10486. if ( offset !== undefined ) {
  10487. texture.offset.fromArray( offset );
  10488. }
  10489. if ( wrap !== undefined ) {
  10490. if ( wrap[ 0 ] === 'repeat' ) texture.wrapS = THREE.RepeatWrapping;
  10491. if ( wrap[ 0 ] === 'mirror' ) texture.wrapS = THREE.MirroredRepeatWrapping;
  10492. if ( wrap[ 1 ] === 'repeat' ) texture.wrapT = THREE.RepeatWrapping;
  10493. if ( wrap[ 1 ] === 'mirror' ) texture.wrapT = THREE.MirroredRepeatWrapping;
  10494. }
  10495. if ( anisotropy !== undefined ) {
  10496. texture.anisotropy = anisotropy;
  10497. }
  10498. var uuid = THREE.Math.generateUUID();
  10499. textures[ uuid ] = texture;
  10500. return uuid;
  10501. }
  10502. //
  10503. var json = {
  10504. uuid: THREE.Math.generateUUID(),
  10505. type: 'MeshLambertMaterial'
  10506. };
  10507. for ( var name in m ) {
  10508. var value = m[ name ];
  10509. switch ( name ) {
  10510. case 'DbgColor':
  10511. case 'DbgIndex':
  10512. case 'opticalDensity':
  10513. case 'illumination':
  10514. break;
  10515. case 'DbgName':
  10516. json.name = value;
  10517. break;
  10518. case 'blending':
  10519. json.blending = THREE[ value ];
  10520. break;
  10521. case 'colorAmbient':
  10522. case 'mapAmbient':
  10523. console.warn( 'THREE.Loader.createMaterial:', name, 'is no longer supported.' );
  10524. break;
  10525. case 'colorDiffuse':
  10526. json.color = color.fromArray( value ).getHex();
  10527. break;
  10528. case 'colorSpecular':
  10529. json.specular = color.fromArray( value ).getHex();
  10530. break;
  10531. case 'colorEmissive':
  10532. json.emissive = color.fromArray( value ).getHex();
  10533. break;
  10534. case 'specularCoef':
  10535. json.shininess = value;
  10536. break;
  10537. case 'shading':
  10538. if ( value.toLowerCase() === 'basic' ) json.type = 'MeshBasicMaterial';
  10539. if ( value.toLowerCase() === 'phong' ) json.type = 'MeshPhongMaterial';
  10540. break;
  10541. case 'mapDiffuse':
  10542. json.map = loadTexture( value, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap, m.mapDiffuseAnisotropy );
  10543. break;
  10544. case 'mapDiffuseRepeat':
  10545. case 'mapDiffuseOffset':
  10546. case 'mapDiffuseWrap':
  10547. case 'mapDiffuseAnisotropy':
  10548. break;
  10549. case 'mapLight':
  10550. json.lightMap = loadTexture( value, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap, m.mapLightAnisotropy );
  10551. break;
  10552. case 'mapLightRepeat':
  10553. case 'mapLightOffset':
  10554. case 'mapLightWrap':
  10555. case 'mapLightAnisotropy':
  10556. break;
  10557. case 'mapAO':
  10558. json.aoMap = loadTexture( value, m.mapAORepeat, m.mapAOOffset, m.mapAOWrap, m.mapAOAnisotropy );
  10559. break;
  10560. case 'mapAORepeat':
  10561. case 'mapAOOffset':
  10562. case 'mapAOWrap':
  10563. case 'mapAOAnisotropy':
  10564. break;
  10565. case 'mapBump':
  10566. json.bumpMap = loadTexture( value, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap, m.mapBumpAnisotropy );
  10567. break;
  10568. case 'mapBumpScale':
  10569. json.bumpScale = value;
  10570. break;
  10571. case 'mapBumpRepeat':
  10572. case 'mapBumpOffset':
  10573. case 'mapBumpWrap':
  10574. case 'mapBumpAnisotropy':
  10575. break;
  10576. case 'mapNormal':
  10577. json.normalMap = loadTexture( value, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap, m.mapNormalAnisotropy );
  10578. break;
  10579. case 'mapNormalFactor':
  10580. json.normalScale = [ value, value ];
  10581. break;
  10582. case 'mapNormalRepeat':
  10583. case 'mapNormalOffset':
  10584. case 'mapNormalWrap':
  10585. case 'mapNormalAnisotropy':
  10586. break;
  10587. case 'mapSpecular':
  10588. json.specularMap = loadTexture( value, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap, m.mapSpecularAnisotropy );
  10589. break;
  10590. case 'mapSpecularRepeat':
  10591. case 'mapSpecularOffset':
  10592. case 'mapSpecularWrap':
  10593. case 'mapSpecularAnisotropy':
  10594. break;
  10595. case 'mapAlpha':
  10596. json.alphaMap = loadTexture( value, m.mapAlphaRepeat, m.mapAlphaOffset, m.mapAlphaWrap, m.mapAlphaAnisotropy );
  10597. break;
  10598. case 'mapAlphaRepeat':
  10599. case 'mapAlphaOffset':
  10600. case 'mapAlphaWrap':
  10601. case 'mapAlphaAnisotropy':
  10602. break;
  10603. case 'flipSided':
  10604. json.side = THREE.BackSide;
  10605. break;
  10606. case 'doubleSided':
  10607. json.side = THREE.DoubleSide;
  10608. break;
  10609. case 'transparency':
  10610. console.warn( 'THREE.Loader.createMaterial: transparency has been renamed to opacity' );
  10611. json.opacity = value;
  10612. break;
  10613. case 'depthTest':
  10614. case 'depthWrite':
  10615. case 'colorWrite':
  10616. case 'opacity':
  10617. case 'reflectivity':
  10618. case 'transparent':
  10619. case 'visible':
  10620. case 'wireframe':
  10621. json[ name ] = value;
  10622. break;
  10623. case 'vertexColors':
  10624. if ( value === true ) json.vertexColors = THREE.VertexColors;
  10625. if ( value === 'face' ) json.vertexColors = THREE.FaceColors;
  10626. break;
  10627. default:
  10628. console.error( 'THREE.Loader.createMaterial: Unsupported', name, value );
  10629. break;
  10630. }
  10631. }
  10632. if ( json.type === 'MeshBasicMaterial' ) delete json.emissive;
  10633. if ( json.type !== 'MeshPhongMaterial' ) delete json.specular;
  10634. if ( json.opacity < 1 ) json.transparent = true;
  10635. materialLoader.setTextures( textures );
  10636. return materialLoader.parse( json );
  10637. };
  10638. } )()
  10639. };
  10640. THREE.Loader.Handlers = {
  10641. handlers: [],
  10642. add: function ( regex, loader ) {
  10643. this.handlers.push( regex, loader );
  10644. },
  10645. get: function ( file ) {
  10646. var handlers = this.handlers;
  10647. for ( var i = 0, l = handlers.length; i < l; i += 2 ) {
  10648. var regex = handlers[ i ];
  10649. var loader = handlers[ i + 1 ];
  10650. if ( regex.test( file ) ) {
  10651. return loader;
  10652. }
  10653. }
  10654. return null;
  10655. }
  10656. };
  10657. // File:src/loaders/XHRLoader.js
  10658. /**
  10659. * @author mrdoob / http://mrdoob.com/
  10660. */
  10661. THREE.XHRLoader = function ( manager ) {
  10662. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10663. };
  10664. THREE.XHRLoader.prototype = {
  10665. constructor: THREE.XHRLoader,
  10666. load: function ( url, onLoad, onProgress, onError ) {
  10667. if ( this.path !== undefined ) url = this.path + url;
  10668. var scope = this;
  10669. var cached = THREE.Cache.get( url );
  10670. if ( cached !== undefined ) {
  10671. if ( onLoad ) {
  10672. setTimeout( function () {
  10673. onLoad( cached );
  10674. }, 0 );
  10675. }
  10676. return cached;
  10677. }
  10678. var request = new XMLHttpRequest();
  10679. request.overrideMimeType( 'text/plain' );
  10680. request.open( 'GET', url, true );
  10681. request.addEventListener( 'load', function ( event ) {
  10682. var response = event.target.response;
  10683. THREE.Cache.add( url, response );
  10684. if ( this.status === 200 ) {
  10685. if ( onLoad ) onLoad( response );
  10686. scope.manager.itemEnd( url );
  10687. } else if ( this.status === 0 ) {
  10688. // Some browsers return HTTP Status 0 when using non-http protocol
  10689. // e.g. 'file://' or 'data://'. Handle as success.
  10690. console.warn( 'THREE.XHRLoader: HTTP Status 0 received.' );
  10691. if ( onLoad ) onLoad( response );
  10692. scope.manager.itemEnd( url );
  10693. } else {
  10694. if ( onError ) onError( event );
  10695. scope.manager.itemError( url );
  10696. }
  10697. }, false );
  10698. if ( onProgress !== undefined ) {
  10699. request.addEventListener( 'progress', function ( event ) {
  10700. onProgress( event );
  10701. }, false );
  10702. }
  10703. request.addEventListener( 'error', function ( event ) {
  10704. if ( onError ) onError( event );
  10705. scope.manager.itemError( url );
  10706. }, false );
  10707. if ( this.responseType !== undefined ) request.responseType = this.responseType;
  10708. if ( this.withCredentials !== undefined ) request.withCredentials = this.withCredentials;
  10709. request.send( null );
  10710. scope.manager.itemStart( url );
  10711. return request;
  10712. },
  10713. setPath: function ( value ) {
  10714. this.path = value;
  10715. },
  10716. setResponseType: function ( value ) {
  10717. this.responseType = value;
  10718. },
  10719. setWithCredentials: function ( value ) {
  10720. this.withCredentials = value;
  10721. }
  10722. };
  10723. // File:src/loaders/FontLoader.js
  10724. /**
  10725. * @author mrdoob / http://mrdoob.com/
  10726. */
  10727. THREE.FontLoader = function ( manager ) {
  10728. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10729. };
  10730. THREE.FontLoader.prototype = {
  10731. constructor: THREE.FontLoader,
  10732. load: function ( url, onLoad, onProgress, onError ) {
  10733. var loader = new THREE.XHRLoader( this.manager );
  10734. loader.load( url, function ( text ) {
  10735. onLoad( new THREE.Font( JSON.parse( text.substring( 65, text.length - 2 ) ) ) );
  10736. }, onProgress, onError );
  10737. }
  10738. };
  10739. // File:src/loaders/ImageLoader.js
  10740. /**
  10741. * @author mrdoob / http://mrdoob.com/
  10742. */
  10743. THREE.ImageLoader = function ( manager ) {
  10744. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10745. };
  10746. THREE.ImageLoader.prototype = {
  10747. constructor: THREE.ImageLoader,
  10748. load: function ( url, onLoad, onProgress, onError ) {
  10749. if ( this.path !== undefined ) url = this.path + url;
  10750. var scope = this;
  10751. var cached = THREE.Cache.get( url );
  10752. if ( cached !== undefined ) {
  10753. scope.manager.itemStart( url );
  10754. if ( onLoad ) {
  10755. setTimeout( function () {
  10756. onLoad( cached );
  10757. scope.manager.itemEnd( url );
  10758. }, 0 );
  10759. } else {
  10760. scope.manager.itemEnd( url );
  10761. }
  10762. return cached;
  10763. }
  10764. var image = document.createElement( 'img' );
  10765. image.addEventListener( 'load', function ( event ) {
  10766. THREE.Cache.add( url, this );
  10767. if ( onLoad ) onLoad( this );
  10768. scope.manager.itemEnd( url );
  10769. }, false );
  10770. if ( onProgress !== undefined ) {
  10771. image.addEventListener( 'progress', function ( event ) {
  10772. onProgress( event );
  10773. }, false );
  10774. }
  10775. image.addEventListener( 'error', function ( event ) {
  10776. if ( onError ) onError( event );
  10777. scope.manager.itemError( url );
  10778. }, false );
  10779. if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
  10780. scope.manager.itemStart( url );
  10781. image.src = url;
  10782. return image;
  10783. },
  10784. setCrossOrigin: function ( value ) {
  10785. this.crossOrigin = value;
  10786. },
  10787. setPath: function ( value ) {
  10788. this.path = value;
  10789. }
  10790. };
  10791. // File:src/loaders/JSONLoader.js
  10792. /**
  10793. * @author mrdoob / http://mrdoob.com/
  10794. * @author alteredq / http://alteredqualia.com/
  10795. */
  10796. THREE.JSONLoader = function ( manager ) {
  10797. if ( typeof manager === 'boolean' ) {
  10798. console.warn( 'THREE.JSONLoader: showStatus parameter has been removed from constructor.' );
  10799. manager = undefined;
  10800. }
  10801. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10802. this.withCredentials = false;
  10803. };
  10804. THREE.JSONLoader.prototype = {
  10805. constructor: THREE.JSONLoader,
  10806. // Deprecated
  10807. get statusDomElement () {
  10808. if ( this._statusDomElement === undefined ) {
  10809. this._statusDomElement = document.createElement( 'div' );
  10810. }
  10811. console.warn( 'THREE.JSONLoader: .statusDomElement has been removed.' );
  10812. return this._statusDomElement;
  10813. },
  10814. load: function( url, onLoad, onProgress, onError ) {
  10815. var scope = this;
  10816. var texturePath = this.texturePath && ( typeof this.texturePath === "string" ) ? this.texturePath : THREE.Loader.prototype.extractUrlBase( url );
  10817. var loader = new THREE.XHRLoader( this.manager );
  10818. loader.setWithCredentials( this.withCredentials );
  10819. loader.load( url, function ( text ) {
  10820. var json = JSON.parse( text );
  10821. var metadata = json.metadata;
  10822. if ( metadata !== undefined ) {
  10823. var type = metadata.type;
  10824. if ( type !== undefined ) {
  10825. if ( type.toLowerCase() === 'object' ) {
  10826. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.ObjectLoader instead.' );
  10827. return;
  10828. }
  10829. if ( type.toLowerCase() === 'scene' ) {
  10830. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.SceneLoader instead.' );
  10831. return;
  10832. }
  10833. }
  10834. }
  10835. var object = scope.parse( json, texturePath );
  10836. onLoad( object.geometry, object.materials );
  10837. }, onProgress, onError );
  10838. },
  10839. setTexturePath: function ( value ) {
  10840. this.texturePath = value;
  10841. },
  10842. parse: function ( json, texturePath ) {
  10843. var geometry = new THREE.Geometry(),
  10844. scale = ( json.scale !== undefined ) ? 1.0 / json.scale : 1.0;
  10845. parseModel( scale );
  10846. parseSkin();
  10847. parseMorphing( scale );
  10848. parseAnimations();
  10849. geometry.computeFaceNormals();
  10850. geometry.computeBoundingSphere();
  10851. function parseModel( scale ) {
  10852. function isBitSet( value, position ) {
  10853. return value & ( 1 << position );
  10854. }
  10855. var i, j, fi,
  10856. offset, zLength,
  10857. colorIndex, normalIndex, uvIndex, materialIndex,
  10858. type,
  10859. isQuad,
  10860. hasMaterial,
  10861. hasFaceVertexUv,
  10862. hasFaceNormal, hasFaceVertexNormal,
  10863. hasFaceColor, hasFaceVertexColor,
  10864. vertex, face, faceA, faceB, hex, normal,
  10865. uvLayer, uv, u, v,
  10866. faces = json.faces,
  10867. vertices = json.vertices,
  10868. normals = json.normals,
  10869. colors = json.colors,
  10870. nUvLayers = 0;
  10871. if ( json.uvs !== undefined ) {
  10872. // disregard empty arrays
  10873. for ( i = 0; i < json.uvs.length; i ++ ) {
  10874. if ( json.uvs[ i ].length ) nUvLayers ++;
  10875. }
  10876. for ( i = 0; i < nUvLayers; i ++ ) {
  10877. geometry.faceVertexUvs[ i ] = [];
  10878. }
  10879. }
  10880. offset = 0;
  10881. zLength = vertices.length;
  10882. while ( offset < zLength ) {
  10883. vertex = new THREE.Vector3();
  10884. vertex.x = vertices[ offset ++ ] * scale;
  10885. vertex.y = vertices[ offset ++ ] * scale;
  10886. vertex.z = vertices[ offset ++ ] * scale;
  10887. geometry.vertices.push( vertex );
  10888. }
  10889. offset = 0;
  10890. zLength = faces.length;
  10891. while ( offset < zLength ) {
  10892. type = faces[ offset ++ ];
  10893. isQuad = isBitSet( type, 0 );
  10894. hasMaterial = isBitSet( type, 1 );
  10895. hasFaceVertexUv = isBitSet( type, 3 );
  10896. hasFaceNormal = isBitSet( type, 4 );
  10897. hasFaceVertexNormal = isBitSet( type, 5 );
  10898. hasFaceColor = isBitSet( type, 6 );
  10899. hasFaceVertexColor = isBitSet( type, 7 );
  10900. // console.log("type", type, "bits", isQuad, hasMaterial, hasFaceVertexUv, hasFaceNormal, hasFaceVertexNormal, hasFaceColor, hasFaceVertexColor);
  10901. if ( isQuad ) {
  10902. faceA = new THREE.Face3();
  10903. faceA.a = faces[ offset ];
  10904. faceA.b = faces[ offset + 1 ];
  10905. faceA.c = faces[ offset + 3 ];
  10906. faceB = new THREE.Face3();
  10907. faceB.a = faces[ offset + 1 ];
  10908. faceB.b = faces[ offset + 2 ];
  10909. faceB.c = faces[ offset + 3 ];
  10910. offset += 4;
  10911. if ( hasMaterial ) {
  10912. materialIndex = faces[ offset ++ ];
  10913. faceA.materialIndex = materialIndex;
  10914. faceB.materialIndex = materialIndex;
  10915. }
  10916. // to get face <=> uv index correspondence
  10917. fi = geometry.faces.length;
  10918. if ( hasFaceVertexUv ) {
  10919. for ( i = 0; i < nUvLayers; i ++ ) {
  10920. uvLayer = json.uvs[ i ];
  10921. geometry.faceVertexUvs[ i ][ fi ] = [];
  10922. geometry.faceVertexUvs[ i ][ fi + 1 ] = [];
  10923. for ( j = 0; j < 4; j ++ ) {
  10924. uvIndex = faces[ offset ++ ];
  10925. u = uvLayer[ uvIndex * 2 ];
  10926. v = uvLayer[ uvIndex * 2 + 1 ];
  10927. uv = new THREE.Vector2( u, v );
  10928. if ( j !== 2 ) geometry.faceVertexUvs[ i ][ fi ].push( uv );
  10929. if ( j !== 0 ) geometry.faceVertexUvs[ i ][ fi + 1 ].push( uv );
  10930. }
  10931. }
  10932. }
  10933. if ( hasFaceNormal ) {
  10934. normalIndex = faces[ offset ++ ] * 3;
  10935. faceA.normal.set(
  10936. normals[ normalIndex ++ ],
  10937. normals[ normalIndex ++ ],
  10938. normals[ normalIndex ]
  10939. );
  10940. faceB.normal.copy( faceA.normal );
  10941. }
  10942. if ( hasFaceVertexNormal ) {
  10943. for ( i = 0; i < 4; i ++ ) {
  10944. normalIndex = faces[ offset ++ ] * 3;
  10945. normal = new THREE.Vector3(
  10946. normals[ normalIndex ++ ],
  10947. normals[ normalIndex ++ ],
  10948. normals[ normalIndex ]
  10949. );
  10950. if ( i !== 2 ) faceA.vertexNormals.push( normal );
  10951. if ( i !== 0 ) faceB.vertexNormals.push( normal );
  10952. }
  10953. }
  10954. if ( hasFaceColor ) {
  10955. colorIndex = faces[ offset ++ ];
  10956. hex = colors[ colorIndex ];
  10957. faceA.color.setHex( hex );
  10958. faceB.color.setHex( hex );
  10959. }
  10960. if ( hasFaceVertexColor ) {
  10961. for ( i = 0; i < 4; i ++ ) {
  10962. colorIndex = faces[ offset ++ ];
  10963. hex = colors[ colorIndex ];
  10964. if ( i !== 2 ) faceA.vertexColors.push( new THREE.Color( hex ) );
  10965. if ( i !== 0 ) faceB.vertexColors.push( new THREE.Color( hex ) );
  10966. }
  10967. }
  10968. geometry.faces.push( faceA );
  10969. geometry.faces.push( faceB );
  10970. } else {
  10971. face = new THREE.Face3();
  10972. face.a = faces[ offset ++ ];
  10973. face.b = faces[ offset ++ ];
  10974. face.c = faces[ offset ++ ];
  10975. if ( hasMaterial ) {
  10976. materialIndex = faces[ offset ++ ];
  10977. face.materialIndex = materialIndex;
  10978. }
  10979. // to get face <=> uv index correspondence
  10980. fi = geometry.faces.length;
  10981. if ( hasFaceVertexUv ) {
  10982. for ( i = 0; i < nUvLayers; i ++ ) {
  10983. uvLayer = json.uvs[ i ];
  10984. geometry.faceVertexUvs[ i ][ fi ] = [];
  10985. for ( j = 0; j < 3; j ++ ) {
  10986. uvIndex = faces[ offset ++ ];
  10987. u = uvLayer[ uvIndex * 2 ];
  10988. v = uvLayer[ uvIndex * 2 + 1 ];
  10989. uv = new THREE.Vector2( u, v );
  10990. geometry.faceVertexUvs[ i ][ fi ].push( uv );
  10991. }
  10992. }
  10993. }
  10994. if ( hasFaceNormal ) {
  10995. normalIndex = faces[ offset ++ ] * 3;
  10996. face.normal.set(
  10997. normals[ normalIndex ++ ],
  10998. normals[ normalIndex ++ ],
  10999. normals[ normalIndex ]
  11000. );
  11001. }
  11002. if ( hasFaceVertexNormal ) {
  11003. for ( i = 0; i < 3; i ++ ) {
  11004. normalIndex = faces[ offset ++ ] * 3;
  11005. normal = new THREE.Vector3(
  11006. normals[ normalIndex ++ ],
  11007. normals[ normalIndex ++ ],
  11008. normals[ normalIndex ]
  11009. );
  11010. face.vertexNormals.push( normal );
  11011. }
  11012. }
  11013. if ( hasFaceColor ) {
  11014. colorIndex = faces[ offset ++ ];
  11015. face.color.setHex( colors[ colorIndex ] );
  11016. }
  11017. if ( hasFaceVertexColor ) {
  11018. for ( i = 0; i < 3; i ++ ) {
  11019. colorIndex = faces[ offset ++ ];
  11020. face.vertexColors.push( new THREE.Color( colors[ colorIndex ] ) );
  11021. }
  11022. }
  11023. geometry.faces.push( face );
  11024. }
  11025. }
  11026. }
  11027. function parseSkin() {
  11028. var influencesPerVertex = ( json.influencesPerVertex !== undefined ) ? json.influencesPerVertex : 2;
  11029. if ( json.skinWeights ) {
  11030. for ( var i = 0, l = json.skinWeights.length; i < l; i += influencesPerVertex ) {
  11031. var x = json.skinWeights[ i ];
  11032. var y = ( influencesPerVertex > 1 ) ? json.skinWeights[ i + 1 ] : 0;
  11033. var z = ( influencesPerVertex > 2 ) ? json.skinWeights[ i + 2 ] : 0;
  11034. var w = ( influencesPerVertex > 3 ) ? json.skinWeights[ i + 3 ] : 0;
  11035. geometry.skinWeights.push( new THREE.Vector4( x, y, z, w ) );
  11036. }
  11037. }
  11038. if ( json.skinIndices ) {
  11039. for ( var i = 0, l = json.skinIndices.length; i < l; i += influencesPerVertex ) {
  11040. var a = json.skinIndices[ i ];
  11041. var b = ( influencesPerVertex > 1 ) ? json.skinIndices[ i + 1 ] : 0;
  11042. var c = ( influencesPerVertex > 2 ) ? json.skinIndices[ i + 2 ] : 0;
  11043. var d = ( influencesPerVertex > 3 ) ? json.skinIndices[ i + 3 ] : 0;
  11044. geometry.skinIndices.push( new THREE.Vector4( a, b, c, d ) );
  11045. }
  11046. }
  11047. geometry.bones = json.bones;
  11048. if ( geometry.bones && geometry.bones.length > 0 && ( geometry.skinWeights.length !== geometry.skinIndices.length || geometry.skinIndices.length !== geometry.vertices.length ) ) {
  11049. console.warn( 'When skinning, number of vertices (' + geometry.vertices.length + '), skinIndices (' +
  11050. geometry.skinIndices.length + '), and skinWeights (' + geometry.skinWeights.length + ') should match.' );
  11051. }
  11052. }
  11053. function parseMorphing( scale ) {
  11054. if ( json.morphTargets !== undefined ) {
  11055. for ( var i = 0, l = json.morphTargets.length; i < l; i ++ ) {
  11056. geometry.morphTargets[ i ] = {};
  11057. geometry.morphTargets[ i ].name = json.morphTargets[ i ].name;
  11058. geometry.morphTargets[ i ].vertices = [];
  11059. var dstVertices = geometry.morphTargets[ i ].vertices;
  11060. var srcVertices = json.morphTargets[ i ].vertices;
  11061. for ( var v = 0, vl = srcVertices.length; v < vl; v += 3 ) {
  11062. var vertex = new THREE.Vector3();
  11063. vertex.x = srcVertices[ v ] * scale;
  11064. vertex.y = srcVertices[ v + 1 ] * scale;
  11065. vertex.z = srcVertices[ v + 2 ] * scale;
  11066. dstVertices.push( vertex );
  11067. }
  11068. }
  11069. }
  11070. if ( json.morphColors !== undefined && json.morphColors.length > 0 ) {
  11071. console.warn( 'THREE.JSONLoader: "morphColors" no longer supported. Using them as face colors.' );
  11072. var faces = geometry.faces;
  11073. var morphColors = json.morphColors[ 0 ].colors;
  11074. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  11075. faces[ i ].color.fromArray( morphColors, i * 3 );
  11076. }
  11077. }
  11078. }
  11079. function parseAnimations() {
  11080. var outputAnimations = [];
  11081. // parse old style Bone/Hierarchy animations
  11082. var animations = [];
  11083. if ( json.animation !== undefined ) {
  11084. animations.push( json.animation );
  11085. }
  11086. if ( json.animations !== undefined ) {
  11087. if ( json.animations.length ) {
  11088. animations = animations.concat( json.animations );
  11089. } else {
  11090. animations.push( json.animations );
  11091. }
  11092. }
  11093. for ( var i = 0; i < animations.length; i ++ ) {
  11094. var clip = THREE.AnimationClip.parseAnimation( animations[ i ], geometry.bones );
  11095. if ( clip ) outputAnimations.push( clip );
  11096. }
  11097. // parse implicit morph animations
  11098. if ( geometry.morphTargets ) {
  11099. // TODO: Figure out what an appropraite FPS is for morph target animations -- defaulting to 10, but really it is completely arbitrary.
  11100. var morphAnimationClips = THREE.AnimationClip.CreateClipsFromMorphTargetSequences( geometry.morphTargets, 10 );
  11101. outputAnimations = outputAnimations.concat( morphAnimationClips );
  11102. }
  11103. if ( outputAnimations.length > 0 ) geometry.animations = outputAnimations;
  11104. }
  11105. if ( json.materials === undefined || json.materials.length === 0 ) {
  11106. return { geometry: geometry };
  11107. } else {
  11108. var materials = THREE.Loader.prototype.initMaterials( json.materials, texturePath, this.crossOrigin );
  11109. return { geometry: geometry, materials: materials };
  11110. }
  11111. }
  11112. };
  11113. // File:src/loaders/LoadingManager.js
  11114. /**
  11115. * @author mrdoob / http://mrdoob.com/
  11116. */
  11117. THREE.LoadingManager = function ( onLoad, onProgress, onError ) {
  11118. var scope = this;
  11119. var isLoading = false, itemsLoaded = 0, itemsTotal = 0;
  11120. this.onStart = undefined;
  11121. this.onLoad = onLoad;
  11122. this.onProgress = onProgress;
  11123. this.onError = onError;
  11124. this.itemStart = function ( url ) {
  11125. itemsTotal ++;
  11126. if ( isLoading === false ) {
  11127. if ( scope.onStart !== undefined ) {
  11128. scope.onStart( url, itemsLoaded, itemsTotal );
  11129. }
  11130. }
  11131. isLoading = true;
  11132. };
  11133. this.itemEnd = function ( url ) {
  11134. itemsLoaded ++;
  11135. if ( scope.onProgress !== undefined ) {
  11136. scope.onProgress( url, itemsLoaded, itemsTotal );
  11137. }
  11138. if ( itemsLoaded === itemsTotal ) {
  11139. isLoading = false;
  11140. if ( scope.onLoad !== undefined ) {
  11141. scope.onLoad();
  11142. }
  11143. }
  11144. };
  11145. this.itemError = function ( url ) {
  11146. if ( scope.onError !== undefined ) {
  11147. scope.onError( url );
  11148. }
  11149. };
  11150. };
  11151. THREE.DefaultLoadingManager = new THREE.LoadingManager();
  11152. // File:src/loaders/BufferGeometryLoader.js
  11153. /**
  11154. * @author mrdoob / http://mrdoob.com/
  11155. */
  11156. THREE.BufferGeometryLoader = function ( manager ) {
  11157. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11158. };
  11159. THREE.BufferGeometryLoader.prototype = {
  11160. constructor: THREE.BufferGeometryLoader,
  11161. load: function ( url, onLoad, onProgress, onError ) {
  11162. var scope = this;
  11163. var loader = new THREE.XHRLoader( scope.manager );
  11164. loader.load( url, function ( text ) {
  11165. onLoad( scope.parse( JSON.parse( text ) ) );
  11166. }, onProgress, onError );
  11167. },
  11168. parse: function ( json ) {
  11169. var geometry = new THREE.BufferGeometry();
  11170. var index = json.data.index;
  11171. var TYPED_ARRAYS = {
  11172. 'Int8Array': Int8Array,
  11173. 'Uint8Array': Uint8Array,
  11174. 'Uint8ClampedArray': Uint8ClampedArray,
  11175. 'Int16Array': Int16Array,
  11176. 'Uint16Array': Uint16Array,
  11177. 'Int32Array': Int32Array,
  11178. 'Uint32Array': Uint32Array,
  11179. 'Float32Array': Float32Array,
  11180. 'Float64Array': Float64Array
  11181. };
  11182. if ( index !== undefined ) {
  11183. var typedArray = new TYPED_ARRAYS[ index.type ]( index.array );
  11184. geometry.setIndex( new THREE.BufferAttribute( typedArray, 1 ) );
  11185. }
  11186. var attributes = json.data.attributes;
  11187. for ( var key in attributes ) {
  11188. var attribute = attributes[ key ];
  11189. var typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
  11190. geometry.addAttribute( key, new THREE.BufferAttribute( typedArray, attribute.itemSize, attribute.normalized ) );
  11191. }
  11192. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  11193. if ( groups !== undefined ) {
  11194. for ( var i = 0, n = groups.length; i !== n; ++ i ) {
  11195. var group = groups[ i ];
  11196. geometry.addGroup( group.start, group.count, group.materialIndex );
  11197. }
  11198. }
  11199. var boundingSphere = json.data.boundingSphere;
  11200. if ( boundingSphere !== undefined ) {
  11201. var center = new THREE.Vector3();
  11202. if ( boundingSphere.center !== undefined ) {
  11203. center.fromArray( boundingSphere.center );
  11204. }
  11205. geometry.boundingSphere = new THREE.Sphere( center, boundingSphere.radius );
  11206. }
  11207. return geometry;
  11208. }
  11209. };
  11210. // File:src/loaders/MaterialLoader.js
  11211. /**
  11212. * @author mrdoob / http://mrdoob.com/
  11213. */
  11214. THREE.MaterialLoader = function ( manager ) {
  11215. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11216. this.textures = {};
  11217. };
  11218. THREE.MaterialLoader.prototype = {
  11219. constructor: THREE.MaterialLoader,
  11220. load: function ( url, onLoad, onProgress, onError ) {
  11221. var scope = this;
  11222. var loader = new THREE.XHRLoader( scope.manager );
  11223. loader.load( url, function ( text ) {
  11224. onLoad( scope.parse( JSON.parse( text ) ) );
  11225. }, onProgress, onError );
  11226. },
  11227. setTextures: function ( value ) {
  11228. this.textures = value;
  11229. },
  11230. getTexture: function ( name ) {
  11231. var textures = this.textures;
  11232. if ( textures[ name ] === undefined ) {
  11233. console.warn( 'THREE.MaterialLoader: Undefined texture', name );
  11234. }
  11235. return textures[ name ];
  11236. },
  11237. parse: function ( json ) {
  11238. var material = new THREE[ json.type ];
  11239. if ( json.uuid !== undefined ) material.uuid = json.uuid;
  11240. if ( json.name !== undefined ) material.name = json.name;
  11241. if ( json.color !== undefined ) material.color.setHex( json.color );
  11242. if ( json.roughness !== undefined ) material.roughness = json.roughness;
  11243. if ( json.metalness !== undefined ) material.metalness = json.metalness;
  11244. if ( json.emissive !== undefined ) material.emissive.setHex( json.emissive );
  11245. if ( json.specular !== undefined ) material.specular.setHex( json.specular );
  11246. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  11247. if ( json.uniforms !== undefined ) material.uniforms = json.uniforms;
  11248. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  11249. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  11250. if ( json.vertexColors !== undefined ) material.vertexColors = json.vertexColors;
  11251. if ( json.shading !== undefined ) material.shading = json.shading;
  11252. if ( json.blending !== undefined ) material.blending = json.blending;
  11253. if ( json.side !== undefined ) material.side = json.side;
  11254. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  11255. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  11256. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  11257. if ( json.depthTest !== undefined ) material.depthTest = json.depthTest;
  11258. if ( json.depthWrite !== undefined ) material.depthWrite = json.depthWrite;
  11259. if ( json.colorWrite !== undefined ) material.colorWrite = json.colorWrite;
  11260. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  11261. if ( json.wireframeLinewidth !== undefined ) material.wireframeLinewidth = json.wireframeLinewidth;
  11262. // for PointsMaterial
  11263. if ( json.size !== undefined ) material.size = json.size;
  11264. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  11265. // maps
  11266. if ( json.map !== undefined ) material.map = this.getTexture( json.map );
  11267. if ( json.alphaMap !== undefined ) {
  11268. material.alphaMap = this.getTexture( json.alphaMap );
  11269. material.transparent = true;
  11270. }
  11271. if ( json.bumpMap !== undefined ) material.bumpMap = this.getTexture( json.bumpMap );
  11272. if ( json.bumpScale !== undefined ) material.bumpScale = json.bumpScale;
  11273. if ( json.normalMap !== undefined ) material.normalMap = this.getTexture( json.normalMap );
  11274. if ( json.normalScale !== undefined ) {
  11275. var normalScale = json.normalScale;
  11276. if ( Array.isArray( normalScale ) === false ) {
  11277. // Blender exporter used to export a scalar. See #7459
  11278. normalScale = [ normalScale, normalScale ];
  11279. }
  11280. material.normalScale = new THREE.Vector2().fromArray( normalScale );
  11281. }
  11282. if ( json.displacementMap !== undefined ) material.displacementMap = this.getTexture( json.displacementMap );
  11283. if ( json.displacementScale !== undefined ) material.displacementScale = json.displacementScale;
  11284. if ( json.displacementBias !== undefined ) material.displacementBias = json.displacementBias;
  11285. if ( json.roughnessMap !== undefined ) material.roughnessMap = this.getTexture( json.roughnessMap );
  11286. if ( json.metalnessMap !== undefined ) material.metalnessMap = this.getTexture( json.metalnessMap );
  11287. if ( json.emissiveMap !== undefined ) material.emissiveMap = this.getTexture( json.emissiveMap );
  11288. if ( json.emissiveIntensity !== undefined ) material.emissiveIntensity = json.emissiveIntensity;
  11289. if ( json.specularMap !== undefined ) material.specularMap = this.getTexture( json.specularMap );
  11290. if ( json.envMap !== undefined ) {
  11291. material.envMap = this.getTexture( json.envMap );
  11292. material.combine = THREE.MultiplyOperation;
  11293. }
  11294. if ( json.reflectivity ) material.reflectivity = json.reflectivity;
  11295. if ( json.lightMap !== undefined ) material.lightMap = this.getTexture( json.lightMap );
  11296. if ( json.lightMapIntensity !== undefined ) material.lightMapIntensity = json.lightMapIntensity;
  11297. if ( json.aoMap !== undefined ) material.aoMap = this.getTexture( json.aoMap );
  11298. if ( json.aoMapIntensity !== undefined ) material.aoMapIntensity = json.aoMapIntensity;
  11299. // MultiMaterial
  11300. if ( json.materials !== undefined ) {
  11301. for ( var i = 0, l = json.materials.length; i < l; i ++ ) {
  11302. material.materials.push( this.parse( json.materials[ i ] ) );
  11303. }
  11304. }
  11305. return material;
  11306. }
  11307. };
  11308. // File:src/loaders/ObjectLoader.js
  11309. /**
  11310. * @author mrdoob / http://mrdoob.com/
  11311. */
  11312. THREE.ObjectLoader = function ( manager ) {
  11313. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11314. this.texturePath = '';
  11315. };
  11316. THREE.ObjectLoader.prototype = {
  11317. constructor: THREE.ObjectLoader,
  11318. load: function ( url, onLoad, onProgress, onError ) {
  11319. if ( this.texturePath === '' ) {
  11320. this.texturePath = url.substring( 0, url.lastIndexOf( '/' ) + 1 );
  11321. }
  11322. var scope = this;
  11323. var loader = new THREE.XHRLoader( scope.manager );
  11324. loader.load( url, function ( text ) {
  11325. scope.parse( JSON.parse( text ), onLoad );
  11326. }, onProgress, onError );
  11327. },
  11328. setTexturePath: function ( value ) {
  11329. this.texturePath = value;
  11330. },
  11331. setCrossOrigin: function ( value ) {
  11332. this.crossOrigin = value;
  11333. },
  11334. parse: function ( json, onLoad ) {
  11335. var geometries = this.parseGeometries( json.geometries );
  11336. var images = this.parseImages( json.images, function () {
  11337. if ( onLoad !== undefined ) onLoad( object );
  11338. } );
  11339. var textures = this.parseTextures( json.textures, images );
  11340. var materials = this.parseMaterials( json.materials, textures );
  11341. var object = this.parseObject( json.object, geometries, materials );
  11342. if ( json.animations ) {
  11343. object.animations = this.parseAnimations( json.animations );
  11344. }
  11345. if ( json.images === undefined || json.images.length === 0 ) {
  11346. if ( onLoad !== undefined ) onLoad( object );
  11347. }
  11348. return object;
  11349. },
  11350. parseGeometries: function ( json ) {
  11351. var geometries = {};
  11352. if ( json !== undefined ) {
  11353. var geometryLoader = new THREE.JSONLoader();
  11354. var bufferGeometryLoader = new THREE.BufferGeometryLoader();
  11355. for ( var i = 0, l = json.length; i < l; i ++ ) {
  11356. var geometry;
  11357. var data = json[ i ];
  11358. switch ( data.type ) {
  11359. case 'PlaneGeometry':
  11360. case 'PlaneBufferGeometry':
  11361. geometry = new THREE[ data.type ](
  11362. data.width,
  11363. data.height,
  11364. data.widthSegments,
  11365. data.heightSegments
  11366. );
  11367. break;
  11368. case 'BoxGeometry':
  11369. case 'BoxBufferGeometry':
  11370. case 'CubeGeometry': // backwards compatible
  11371. geometry = new THREE[ data.type ](
  11372. data.width,
  11373. data.height,
  11374. data.depth,
  11375. data.widthSegments,
  11376. data.heightSegments,
  11377. data.depthSegments
  11378. );
  11379. break;
  11380. case 'CircleGeometry':
  11381. case 'CircleBufferGeometry':
  11382. geometry = new THREE[ data.type ](
  11383. data.radius,
  11384. data.segments,
  11385. data.thetaStart,
  11386. data.thetaLength
  11387. );
  11388. break;
  11389. case 'CylinderGeometry':
  11390. case 'CylinderBufferGeometry':
  11391. geometry = new THREE[ data.type ](
  11392. data.radiusTop,
  11393. data.radiusBottom,
  11394. data.height,
  11395. data.radialSegments,
  11396. data.heightSegments,
  11397. data.openEnded,
  11398. data.thetaStart,
  11399. data.thetaLength
  11400. );
  11401. break;
  11402. case 'SphereGeometry':
  11403. case 'SphereBufferGeometry':
  11404. geometry = new THREE[ data.type ](
  11405. data.radius,
  11406. data.widthSegments,
  11407. data.heightSegments,
  11408. data.phiStart,
  11409. data.phiLength,
  11410. data.thetaStart,
  11411. data.thetaLength
  11412. );
  11413. break;
  11414. case 'DodecahedronGeometry':
  11415. case 'IcosahedronGeometry':
  11416. case 'OctahedronGeometry':
  11417. case 'TetrahedronGeometry':
  11418. geometry = new THREE[ data.type ](
  11419. data.radius,
  11420. data.detail
  11421. );
  11422. break;
  11423. case 'RingGeometry':
  11424. case 'RingBufferGeometry':
  11425. geometry = new THREE[ data.type ](
  11426. data.innerRadius,
  11427. data.outerRadius,
  11428. data.thetaSegments,
  11429. data.phiSegments,
  11430. data.thetaStart,
  11431. data.thetaLength
  11432. );
  11433. break;
  11434. case 'TorusGeometry':
  11435. case 'TorusBufferGeometry':
  11436. geometry = new THREE[ data.type ](
  11437. data.radius,
  11438. data.tube,
  11439. data.radialSegments,
  11440. data.tubularSegments,
  11441. data.arc
  11442. );
  11443. break;
  11444. case 'TorusKnotGeometry':
  11445. case 'TorusKnotBufferGeometry':
  11446. geometry = new THREE[ data.type ](
  11447. data.radius,
  11448. data.tube,
  11449. data.tubularSegments,
  11450. data.radialSegments,
  11451. data.p,
  11452. data.q
  11453. );
  11454. break;
  11455. case 'LatheGeometry':
  11456. case 'LatheBufferGeometry':
  11457. geometry = new THREE[ data.type ](
  11458. data.points,
  11459. data.segments,
  11460. data.phiStart,
  11461. data.phiLength
  11462. );
  11463. break;
  11464. case 'BufferGeometry':
  11465. geometry = bufferGeometryLoader.parse( data );
  11466. break;
  11467. case 'Geometry':
  11468. geometry = geometryLoader.parse( data.data, this.texturePath ).geometry;
  11469. break;
  11470. default:
  11471. console.warn( 'THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"' );
  11472. continue;
  11473. }
  11474. geometry.uuid = data.uuid;
  11475. if ( data.name !== undefined ) geometry.name = data.name;
  11476. geometries[ data.uuid ] = geometry;
  11477. }
  11478. }
  11479. return geometries;
  11480. },
  11481. parseMaterials: function ( json, textures ) {
  11482. var materials = {};
  11483. if ( json !== undefined ) {
  11484. var loader = new THREE.MaterialLoader();
  11485. loader.setTextures( textures );
  11486. for ( var i = 0, l = json.length; i < l; i ++ ) {
  11487. var material = loader.parse( json[ i ] );
  11488. materials[ material.uuid ] = material;
  11489. }
  11490. }
  11491. return materials;
  11492. },
  11493. parseAnimations: function ( json ) {
  11494. var animations = [];
  11495. for ( var i = 0; i < json.length; i ++ ) {
  11496. var clip = THREE.AnimationClip.parse( json[ i ] );
  11497. animations.push( clip );
  11498. }
  11499. return animations;
  11500. },
  11501. parseImages: function ( json, onLoad ) {
  11502. var scope = this;
  11503. var images = {};
  11504. function loadImage( url ) {
  11505. scope.manager.itemStart( url );
  11506. return loader.load( url, function () {
  11507. scope.manager.itemEnd( url );
  11508. } );
  11509. }
  11510. if ( json !== undefined && json.length > 0 ) {
  11511. var manager = new THREE.LoadingManager( onLoad );
  11512. var loader = new THREE.ImageLoader( manager );
  11513. loader.setCrossOrigin( this.crossOrigin );
  11514. for ( var i = 0, l = json.length; i < l; i ++ ) {
  11515. var image = json[ i ];
  11516. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( image.url ) ? image.url : scope.texturePath + image.url;
  11517. images[ image.uuid ] = loadImage( path );
  11518. }
  11519. }
  11520. return images;
  11521. },
  11522. parseTextures: function ( json, images ) {
  11523. function parseConstant( value ) {
  11524. if ( typeof( value ) === 'number' ) return value;
  11525. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  11526. return THREE[ value ];
  11527. }
  11528. var textures = {};
  11529. if ( json !== undefined ) {
  11530. for ( var i = 0, l = json.length; i < l; i ++ ) {
  11531. var data = json[ i ];
  11532. if ( data.image === undefined ) {
  11533. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  11534. }
  11535. if ( images[ data.image ] === undefined ) {
  11536. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  11537. }
  11538. var texture = new THREE.Texture( images[ data.image ] );
  11539. texture.needsUpdate = true;
  11540. texture.uuid = data.uuid;
  11541. if ( data.name !== undefined ) texture.name = data.name;
  11542. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping );
  11543. if ( data.offset !== undefined ) texture.offset = new THREE.Vector2( data.offset[ 0 ], data.offset[ 1 ] );
  11544. if ( data.repeat !== undefined ) texture.repeat = new THREE.Vector2( data.repeat[ 0 ], data.repeat[ 1 ] );
  11545. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter );
  11546. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter );
  11547. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  11548. if ( Array.isArray( data.wrap ) ) {
  11549. texture.wrapS = parseConstant( data.wrap[ 0 ] );
  11550. texture.wrapT = parseConstant( data.wrap[ 1 ] );
  11551. }
  11552. textures[ data.uuid ] = texture;
  11553. }
  11554. }
  11555. return textures;
  11556. },
  11557. parseObject: function () {
  11558. var matrix = new THREE.Matrix4();
  11559. return function ( data, geometries, materials ) {
  11560. var object;
  11561. function getGeometry( name ) {
  11562. if ( geometries[ name ] === undefined ) {
  11563. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  11564. }
  11565. return geometries[ name ];
  11566. }
  11567. function getMaterial( name ) {
  11568. if ( name === undefined ) return undefined;
  11569. if ( materials[ name ] === undefined ) {
  11570. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  11571. }
  11572. return materials[ name ];
  11573. }
  11574. switch ( data.type ) {
  11575. case 'Scene':
  11576. object = new THREE.Scene();
  11577. break;
  11578. case 'PerspectiveCamera':
  11579. object = new THREE.PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  11580. if ( data.focus !== undefined ) object.focus = data.focus;
  11581. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  11582. if ( data.filmGauge !== undefined ) object.filmGauge = data.filmGauge;
  11583. if ( data.filmOffset !== undefined ) object.filmOffset = data.filmOffset;
  11584. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  11585. break;
  11586. case 'OrthographicCamera':
  11587. object = new THREE.OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  11588. break;
  11589. case 'AmbientLight':
  11590. object = new THREE.AmbientLight( data.color, data.intensity );
  11591. break;
  11592. case 'DirectionalLight':
  11593. object = new THREE.DirectionalLight( data.color, data.intensity );
  11594. break;
  11595. case 'PointLight':
  11596. object = new THREE.PointLight( data.color, data.intensity, data.distance, data.decay );
  11597. break;
  11598. case 'SpotLight':
  11599. object = new THREE.SpotLight( data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay );
  11600. break;
  11601. case 'HemisphereLight':
  11602. object = new THREE.HemisphereLight( data.color, data.groundColor, data.intensity );
  11603. break;
  11604. case 'Mesh':
  11605. var geometry = getGeometry( data.geometry );
  11606. var material = getMaterial( data.material );
  11607. if ( geometry.bones && geometry.bones.length > 0 ) {
  11608. object = new THREE.SkinnedMesh( geometry, material );
  11609. } else {
  11610. object = new THREE.Mesh( geometry, material );
  11611. }
  11612. break;
  11613. case 'LOD':
  11614. object = new THREE.LOD();
  11615. break;
  11616. case 'Line':
  11617. object = new THREE.Line( getGeometry( data.geometry ), getMaterial( data.material ), data.mode );
  11618. break;
  11619. case 'PointCloud':
  11620. case 'Points':
  11621. object = new THREE.Points( getGeometry( data.geometry ), getMaterial( data.material ) );
  11622. break;
  11623. case 'Sprite':
  11624. object = new THREE.Sprite( getMaterial( data.material ) );
  11625. break;
  11626. case 'Group':
  11627. object = new THREE.Group();
  11628. break;
  11629. default:
  11630. object = new THREE.Object3D();
  11631. }
  11632. object.uuid = data.uuid;
  11633. if ( data.name !== undefined ) object.name = data.name;
  11634. if ( data.matrix !== undefined ) {
  11635. matrix.fromArray( data.matrix );
  11636. matrix.decompose( object.position, object.quaternion, object.scale );
  11637. } else {
  11638. if ( data.position !== undefined ) object.position.fromArray( data.position );
  11639. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  11640. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  11641. }
  11642. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  11643. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  11644. if ( data.visible !== undefined ) object.visible = data.visible;
  11645. if ( data.userData !== undefined ) object.userData = data.userData;
  11646. if ( data.children !== undefined ) {
  11647. for ( var child in data.children ) {
  11648. object.add( this.parseObject( data.children[ child ], geometries, materials ) );
  11649. }
  11650. }
  11651. if ( data.type === 'LOD' ) {
  11652. var levels = data.levels;
  11653. for ( var l = 0; l < levels.length; l ++ ) {
  11654. var level = levels[ l ];
  11655. var child = object.getObjectByProperty( 'uuid', level.object );
  11656. if ( child !== undefined ) {
  11657. object.addLevel( child, level.distance );
  11658. }
  11659. }
  11660. }
  11661. return object;
  11662. };
  11663. }()
  11664. };
  11665. // File:src/loaders/TextureLoader.js
  11666. /**
  11667. * @author mrdoob / http://mrdoob.com/
  11668. */
  11669. THREE.TextureLoader = function ( manager ) {
  11670. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11671. };
  11672. THREE.TextureLoader.prototype = {
  11673. constructor: THREE.TextureLoader,
  11674. load: function ( url, onLoad, onProgress, onError ) {
  11675. var texture = new THREE.Texture();
  11676. var loader = new THREE.ImageLoader( this.manager );
  11677. loader.setCrossOrigin( this.crossOrigin );
  11678. loader.setPath( this.path );
  11679. loader.load( url, function ( image ) {
  11680. texture.image = image;
  11681. texture.needsUpdate = true;
  11682. if ( onLoad !== undefined ) {
  11683. onLoad( texture );
  11684. }
  11685. }, onProgress, onError );
  11686. return texture;
  11687. },
  11688. setCrossOrigin: function ( value ) {
  11689. this.crossOrigin = value;
  11690. },
  11691. setPath: function ( value ) {
  11692. this.path = value;
  11693. }
  11694. };
  11695. // File:src/loaders/CubeTextureLoader.js
  11696. /**
  11697. * @author mrdoob / http://mrdoob.com/
  11698. */
  11699. THREE.CubeTextureLoader = function ( manager ) {
  11700. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11701. };
  11702. THREE.CubeTextureLoader.prototype = {
  11703. constructor: THREE.CubeTextureLoader,
  11704. load: function ( urls, onLoad, onProgress, onError ) {
  11705. var texture = new THREE.CubeTexture();
  11706. var loader = new THREE.ImageLoader( this.manager );
  11707. loader.setCrossOrigin( this.crossOrigin );
  11708. loader.setPath( this.path );
  11709. var loaded = 0;
  11710. function loadTexture( i ) {
  11711. loader.load( urls[ i ], function ( image ) {
  11712. texture.images[ i ] = image;
  11713. loaded ++;
  11714. if ( loaded === 6 ) {
  11715. texture.needsUpdate = true;
  11716. if ( onLoad ) onLoad( texture );
  11717. }
  11718. }, undefined, onError );
  11719. }
  11720. for ( var i = 0; i < urls.length; ++ i ) {
  11721. loadTexture( i );
  11722. }
  11723. return texture;
  11724. },
  11725. setCrossOrigin: function ( value ) {
  11726. this.crossOrigin = value;
  11727. },
  11728. setPath: function ( value ) {
  11729. this.path = value;
  11730. }
  11731. };
  11732. // File:src/loaders/BinaryTextureLoader.js
  11733. /**
  11734. * @author Nikos M. / https://github.com/foo123/
  11735. *
  11736. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  11737. */
  11738. THREE.DataTextureLoader = THREE.BinaryTextureLoader = function ( manager ) {
  11739. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11740. // override in sub classes
  11741. this._parser = null;
  11742. };
  11743. THREE.BinaryTextureLoader.prototype = {
  11744. constructor: THREE.BinaryTextureLoader,
  11745. load: function ( url, onLoad, onProgress, onError ) {
  11746. var scope = this;
  11747. var texture = new THREE.DataTexture();
  11748. var loader = new THREE.XHRLoader( this.manager );
  11749. loader.setResponseType( 'arraybuffer' );
  11750. loader.load( url, function ( buffer ) {
  11751. var texData = scope._parser( buffer );
  11752. if ( ! texData ) return;
  11753. if ( undefined !== texData.image ) {
  11754. texture.image = texData.image;
  11755. } else if ( undefined !== texData.data ) {
  11756. texture.image.width = texData.width;
  11757. texture.image.height = texData.height;
  11758. texture.image.data = texData.data;
  11759. }
  11760. texture.wrapS = undefined !== texData.wrapS ? texData.wrapS : THREE.ClampToEdgeWrapping;
  11761. texture.wrapT = undefined !== texData.wrapT ? texData.wrapT : THREE.ClampToEdgeWrapping;
  11762. texture.magFilter = undefined !== texData.magFilter ? texData.magFilter : THREE.LinearFilter;
  11763. texture.minFilter = undefined !== texData.minFilter ? texData.minFilter : THREE.LinearMipMapLinearFilter;
  11764. texture.anisotropy = undefined !== texData.anisotropy ? texData.anisotropy : 1;
  11765. if ( undefined !== texData.format ) {
  11766. texture.format = texData.format;
  11767. }
  11768. if ( undefined !== texData.type ) {
  11769. texture.type = texData.type;
  11770. }
  11771. if ( undefined !== texData.mipmaps ) {
  11772. texture.mipmaps = texData.mipmaps;
  11773. }
  11774. if ( 1 === texData.mipmapCount ) {
  11775. texture.minFilter = THREE.LinearFilter;
  11776. }
  11777. texture.needsUpdate = true;
  11778. if ( onLoad ) onLoad( texture, texData );
  11779. }, onProgress, onError );
  11780. return texture;
  11781. }
  11782. };
  11783. // File:src/loaders/CompressedTextureLoader.js
  11784. /**
  11785. * @author mrdoob / http://mrdoob.com/
  11786. *
  11787. * Abstract Base class to block based textures loader (dds, pvr, ...)
  11788. */
  11789. THREE.CompressedTextureLoader = function ( manager ) {
  11790. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11791. // override in sub classes
  11792. this._parser = null;
  11793. };
  11794. THREE.CompressedTextureLoader.prototype = {
  11795. constructor: THREE.CompressedTextureLoader,
  11796. load: function ( url, onLoad, onProgress, onError ) {
  11797. var scope = this;
  11798. var images = [];
  11799. var texture = new THREE.CompressedTexture();
  11800. texture.image = images;
  11801. var loader = new THREE.XHRLoader( this.manager );
  11802. loader.setPath( this.path );
  11803. loader.setResponseType( 'arraybuffer' );
  11804. function loadTexture( i ) {
  11805. loader.load( url[ i ], function ( buffer ) {
  11806. var texDatas = scope._parser( buffer, true );
  11807. images[ i ] = {
  11808. width: texDatas.width,
  11809. height: texDatas.height,
  11810. format: texDatas.format,
  11811. mipmaps: texDatas.mipmaps
  11812. };
  11813. loaded += 1;
  11814. if ( loaded === 6 ) {
  11815. if ( texDatas.mipmapCount === 1 )
  11816. texture.minFilter = THREE.LinearFilter;
  11817. texture.format = texDatas.format;
  11818. texture.needsUpdate = true;
  11819. if ( onLoad ) onLoad( texture );
  11820. }
  11821. }, onProgress, onError );
  11822. }
  11823. if ( Array.isArray( url ) ) {
  11824. var loaded = 0;
  11825. for ( var i = 0, il = url.length; i < il; ++ i ) {
  11826. loadTexture( i );
  11827. }
  11828. } else {
  11829. // compressed cubemap texture stored in a single DDS file
  11830. loader.load( url, function ( buffer ) {
  11831. var texDatas = scope._parser( buffer, true );
  11832. if ( texDatas.isCubemap ) {
  11833. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  11834. for ( var f = 0; f < faces; f ++ ) {
  11835. images[ f ] = { mipmaps : [] };
  11836. for ( var i = 0; i < texDatas.mipmapCount; i ++ ) {
  11837. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  11838. images[ f ].format = texDatas.format;
  11839. images[ f ].width = texDatas.width;
  11840. images[ f ].height = texDatas.height;
  11841. }
  11842. }
  11843. } else {
  11844. texture.image.width = texDatas.width;
  11845. texture.image.height = texDatas.height;
  11846. texture.mipmaps = texDatas.mipmaps;
  11847. }
  11848. if ( texDatas.mipmapCount === 1 ) {
  11849. texture.minFilter = THREE.LinearFilter;
  11850. }
  11851. texture.format = texDatas.format;
  11852. texture.needsUpdate = true;
  11853. if ( onLoad ) onLoad( texture );
  11854. }, onProgress, onError );
  11855. }
  11856. return texture;
  11857. },
  11858. setPath: function ( value ) {
  11859. this.path = value;
  11860. }
  11861. };
  11862. // File:src/materials/Material.js
  11863. /**
  11864. * @author mrdoob / http://mrdoob.com/
  11865. * @author alteredq / http://alteredqualia.com/
  11866. */
  11867. THREE.Material = function () {
  11868. Object.defineProperty( this, 'id', { value: THREE.MaterialIdCount ++ } );
  11869. this.uuid = THREE.Math.generateUUID();
  11870. this.name = '';
  11871. this.type = 'Material';
  11872. this.side = THREE.FrontSide;
  11873. this.opacity = 1;
  11874. this.transparent = false;
  11875. this.blending = THREE.NormalBlending;
  11876. this.blendSrc = THREE.SrcAlphaFactor;
  11877. this.blendDst = THREE.OneMinusSrcAlphaFactor;
  11878. this.blendEquation = THREE.AddEquation;
  11879. this.blendSrcAlpha = null;
  11880. this.blendDstAlpha = null;
  11881. this.blendEquationAlpha = null;
  11882. this.depthFunc = THREE.LessEqualDepth;
  11883. this.depthTest = true;
  11884. this.depthWrite = true;
  11885. this.clippingPlanes = null;
  11886. this.clipShadows = false;
  11887. this.colorWrite = true;
  11888. this.precision = null; // override the renderer's default precision for this material
  11889. this.polygonOffset = false;
  11890. this.polygonOffsetFactor = 0;
  11891. this.polygonOffsetUnits = 0;
  11892. this.alphaTest = 0;
  11893. this.premultipliedAlpha = false;
  11894. this.overdraw = 0; // Overdrawn pixels (typically between 0 and 1) for fixing antialiasing gaps in CanvasRenderer
  11895. this.visible = true;
  11896. this._needsUpdate = true;
  11897. };
  11898. THREE.Material.prototype = {
  11899. constructor: THREE.Material,
  11900. get needsUpdate () {
  11901. return this._needsUpdate;
  11902. },
  11903. set needsUpdate ( value ) {
  11904. if ( value === true ) this.update();
  11905. this._needsUpdate = value;
  11906. },
  11907. setValues: function ( values ) {
  11908. if ( values === undefined ) return;
  11909. for ( var key in values ) {
  11910. var newValue = values[ key ];
  11911. if ( newValue === undefined ) {
  11912. console.warn( "THREE.Material: '" + key + "' parameter is undefined." );
  11913. continue;
  11914. }
  11915. var currentValue = this[ key ];
  11916. if ( currentValue === undefined ) {
  11917. console.warn( "THREE." + this.type + ": '" + key + "' is not a property of this material." );
  11918. continue;
  11919. }
  11920. if ( currentValue instanceof THREE.Color ) {
  11921. currentValue.set( newValue );
  11922. } else if ( currentValue instanceof THREE.Vector3 && newValue instanceof THREE.Vector3 ) {
  11923. currentValue.copy( newValue );
  11924. } else if ( key === 'overdraw' ) {
  11925. // ensure overdraw is backwards-compatible with legacy boolean type
  11926. this[ key ] = Number( newValue );
  11927. } else {
  11928. this[ key ] = newValue;
  11929. }
  11930. }
  11931. },
  11932. toJSON: function ( meta ) {
  11933. var isRoot = meta === undefined;
  11934. if ( isRoot ) {
  11935. meta = {
  11936. textures: {},
  11937. images: {}
  11938. };
  11939. }
  11940. var data = {
  11941. metadata: {
  11942. version: 4.4,
  11943. type: 'Material',
  11944. generator: 'Material.toJSON'
  11945. }
  11946. };
  11947. // standard Material serialization
  11948. data.uuid = this.uuid;
  11949. data.type = this.type;
  11950. if ( this.name !== '' ) data.name = this.name;
  11951. if ( this.color instanceof THREE.Color ) data.color = this.color.getHex();
  11952. if ( this.roughness !== 0.5 ) data.roughness = this.roughness;
  11953. if ( this.metalness !== 0.5 ) data.metalness = this.metalness;
  11954. if ( this.emissive instanceof THREE.Color ) data.emissive = this.emissive.getHex();
  11955. if ( this.specular instanceof THREE.Color ) data.specular = this.specular.getHex();
  11956. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  11957. if ( this.map instanceof THREE.Texture ) data.map = this.map.toJSON( meta ).uuid;
  11958. if ( this.alphaMap instanceof THREE.Texture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  11959. if ( this.lightMap instanceof THREE.Texture ) data.lightMap = this.lightMap.toJSON( meta ).uuid;
  11960. if ( this.bumpMap instanceof THREE.Texture ) {
  11961. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  11962. data.bumpScale = this.bumpScale;
  11963. }
  11964. if ( this.normalMap instanceof THREE.Texture ) {
  11965. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  11966. data.normalScale = this.normalScale.toArray();
  11967. }
  11968. if ( this.displacementMap instanceof THREE.Texture ) {
  11969. data.displacementMap = this.displacementMap.toJSON( meta ).uuid;
  11970. data.displacementScale = this.displacementScale;
  11971. data.displacementBias = this.displacementBias;
  11972. }
  11973. if ( this.roughnessMap instanceof THREE.Texture ) data.roughnessMap = this.roughnessMap.toJSON( meta ).uuid;
  11974. if ( this.metalnessMap instanceof THREE.Texture ) data.metalnessMap = this.metalnessMap.toJSON( meta ).uuid;
  11975. if ( this.emissiveMap instanceof THREE.Texture ) data.emissiveMap = this.emissiveMap.toJSON( meta ).uuid;
  11976. if ( this.specularMap instanceof THREE.Texture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  11977. if ( this.envMap instanceof THREE.Texture ) {
  11978. data.envMap = this.envMap.toJSON( meta ).uuid;
  11979. data.reflectivity = this.reflectivity; // Scale behind envMap
  11980. }
  11981. if ( this.size !== undefined ) data.size = this.size;
  11982. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  11983. if ( this.vertexColors !== undefined && this.vertexColors !== THREE.NoColors ) data.vertexColors = this.vertexColors;
  11984. if ( this.shading !== undefined && this.shading !== THREE.SmoothShading ) data.shading = this.shading;
  11985. if ( this.blending !== undefined && this.blending !== THREE.NormalBlending ) data.blending = this.blending;
  11986. if ( this.side !== undefined && this.side !== THREE.FrontSide ) data.side = this.side;
  11987. if ( this.opacity < 1 ) data.opacity = this.opacity;
  11988. if ( this.transparent === true ) data.transparent = this.transparent;
  11989. if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
  11990. if ( this.premultipliedAlpha === true ) data.premultipliedAlpha = this.premultipliedAlpha;
  11991. if ( this.wireframe === true ) data.wireframe = this.wireframe;
  11992. if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;
  11993. // TODO: Copied from Object3D.toJSON
  11994. function extractFromCache ( cache ) {
  11995. var values = [];
  11996. for ( var key in cache ) {
  11997. var data = cache[ key ];
  11998. delete data.metadata;
  11999. values.push( data );
  12000. }
  12001. return values;
  12002. }
  12003. if ( isRoot ) {
  12004. var textures = extractFromCache( meta.textures );
  12005. var images = extractFromCache( meta.images );
  12006. if ( textures.length > 0 ) data.textures = textures;
  12007. if ( images.length > 0 ) data.images = images;
  12008. }
  12009. return data;
  12010. },
  12011. clone: function () {
  12012. return new this.constructor().copy( this );
  12013. },
  12014. copy: function ( source ) {
  12015. this.name = source.name;
  12016. this.side = source.side;
  12017. this.opacity = source.opacity;
  12018. this.transparent = source.transparent;
  12019. this.blending = source.blending;
  12020. this.blendSrc = source.blendSrc;
  12021. this.blendDst = source.blendDst;
  12022. this.blendEquation = source.blendEquation;
  12023. this.blendSrcAlpha = source.blendSrcAlpha;
  12024. this.blendDstAlpha = source.blendDstAlpha;
  12025. this.blendEquationAlpha = source.blendEquationAlpha;
  12026. this.depthFunc = source.depthFunc;
  12027. this.depthTest = source.depthTest;
  12028. this.depthWrite = source.depthWrite;
  12029. this.colorWrite = source.colorWrite;
  12030. this.precision = source.precision;
  12031. this.polygonOffset = source.polygonOffset;
  12032. this.polygonOffsetFactor = source.polygonOffsetFactor;
  12033. this.polygonOffsetUnits = source.polygonOffsetUnits;
  12034. this.alphaTest = source.alphaTest;
  12035. this.premultipliedAlpha = source.premultipliedAlpha;
  12036. this.overdraw = source.overdraw;
  12037. this.visible = source.visible;
  12038. this.clipShadows = source.clipShadows;
  12039. var srcPlanes = source.clippingPlanes,
  12040. dstPlanes = null;
  12041. if ( srcPlanes !== null ) {
  12042. var n = srcPlanes.length;
  12043. dstPlanes = new Array( n );
  12044. for ( var i = 0; i !== n; ++ i )
  12045. dstPlanes[ i ] = srcPlanes[ i ].clone();
  12046. }
  12047. this.clippingPlanes = dstPlanes;
  12048. return this;
  12049. },
  12050. update: function () {
  12051. this.dispatchEvent( { type: 'update' } );
  12052. },
  12053. dispose: function () {
  12054. this.dispatchEvent( { type: 'dispose' } );
  12055. }
  12056. };
  12057. THREE.EventDispatcher.prototype.apply( THREE.Material.prototype );
  12058. THREE.MaterialIdCount = 0;
  12059. // File:src/materials/LineBasicMaterial.js
  12060. /**
  12061. * @author mrdoob / http://mrdoob.com/
  12062. * @author alteredq / http://alteredqualia.com/
  12063. *
  12064. * parameters = {
  12065. * color: <hex>,
  12066. * opacity: <float>,
  12067. *
  12068. * linewidth: <float>,
  12069. * linecap: "round",
  12070. * linejoin: "round",
  12071. *
  12072. * blending: THREE.NormalBlending,
  12073. * depthTest: <bool>,
  12074. * depthWrite: <bool>,
  12075. *
  12076. * vertexColors: <bool>
  12077. *
  12078. * fog: <bool>
  12079. * }
  12080. */
  12081. THREE.LineBasicMaterial = function ( parameters ) {
  12082. THREE.Material.call( this );
  12083. this.type = 'LineBasicMaterial';
  12084. this.color = new THREE.Color( 0xffffff );
  12085. this.linewidth = 1;
  12086. this.linecap = 'round';
  12087. this.linejoin = 'round';
  12088. this.blending = THREE.NormalBlending;
  12089. this.vertexColors = THREE.NoColors;
  12090. this.fog = true;
  12091. this.setValues( parameters );
  12092. };
  12093. THREE.LineBasicMaterial.prototype = Object.create( THREE.Material.prototype );
  12094. THREE.LineBasicMaterial.prototype.constructor = THREE.LineBasicMaterial;
  12095. THREE.LineBasicMaterial.prototype.copy = function ( source ) {
  12096. THREE.Material.prototype.copy.call( this, source );
  12097. this.color.copy( source.color );
  12098. this.linewidth = source.linewidth;
  12099. this.linecap = source.linecap;
  12100. this.linejoin = source.linejoin;
  12101. this.vertexColors = source.vertexColors;
  12102. this.fog = source.fog;
  12103. return this;
  12104. };
  12105. // File:src/materials/LineDashedMaterial.js
  12106. /**
  12107. * @author alteredq / http://alteredqualia.com/
  12108. *
  12109. * parameters = {
  12110. * color: <hex>,
  12111. * opacity: <float>,
  12112. *
  12113. * linewidth: <float>,
  12114. *
  12115. * scale: <float>,
  12116. * dashSize: <float>,
  12117. * gapSize: <float>,
  12118. *
  12119. * blending: THREE.NormalBlending,
  12120. * depthTest: <bool>,
  12121. * depthWrite: <bool>,
  12122. *
  12123. * vertexColors: THREE.NoColors / THREE.FaceColors / THREE.VertexColors
  12124. *
  12125. * fog: <bool>
  12126. * }
  12127. */
  12128. THREE.LineDashedMaterial = function ( parameters ) {
  12129. THREE.Material.call( this );
  12130. this.type = 'LineDashedMaterial';
  12131. this.color = new THREE.Color( 0xffffff );
  12132. this.linewidth = 1;
  12133. this.scale = 1;
  12134. this.dashSize = 3;
  12135. this.gapSize = 1;
  12136. this.blending = THREE.NormalBlending;
  12137. this.vertexColors = THREE.NoColors;
  12138. this.fog = true;
  12139. this.setValues( parameters );
  12140. };
  12141. THREE.LineDashedMaterial.prototype = Object.create( THREE.Material.prototype );
  12142. THREE.LineDashedMaterial.prototype.constructor = THREE.LineDashedMaterial;
  12143. THREE.LineDashedMaterial.prototype.copy = function ( source ) {
  12144. THREE.Material.prototype.copy.call( this, source );
  12145. this.color.copy( source.color );
  12146. this.linewidth = source.linewidth;
  12147. this.scale = source.scale;
  12148. this.dashSize = source.dashSize;
  12149. this.gapSize = source.gapSize;
  12150. this.vertexColors = source.vertexColors;
  12151. this.fog = source.fog;
  12152. return this;
  12153. };
  12154. // File:src/materials/MeshBasicMaterial.js
  12155. /**
  12156. * @author mrdoob / http://mrdoob.com/
  12157. * @author alteredq / http://alteredqualia.com/
  12158. *
  12159. * parameters = {
  12160. * color: <hex>,
  12161. * opacity: <float>,
  12162. * map: new THREE.Texture( <Image> ),
  12163. *
  12164. * aoMap: new THREE.Texture( <Image> ),
  12165. * aoMapIntensity: <float>
  12166. *
  12167. * specularMap: new THREE.Texture( <Image> ),
  12168. *
  12169. * alphaMap: new THREE.Texture( <Image> ),
  12170. *
  12171. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  12172. * combine: THREE.Multiply,
  12173. * reflectivity: <float>,
  12174. * refractionRatio: <float>,
  12175. *
  12176. * shading: THREE.SmoothShading,
  12177. * blending: THREE.NormalBlending,
  12178. * depthTest: <bool>,
  12179. * depthWrite: <bool>,
  12180. *
  12181. * wireframe: <boolean>,
  12182. * wireframeLinewidth: <float>,
  12183. *
  12184. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  12185. *
  12186. * skinning: <bool>,
  12187. * morphTargets: <bool>,
  12188. *
  12189. * fog: <bool>
  12190. * }
  12191. */
  12192. THREE.MeshBasicMaterial = function ( parameters ) {
  12193. THREE.Material.call( this );
  12194. this.type = 'MeshBasicMaterial';
  12195. this.color = new THREE.Color( 0xffffff ); // emissive
  12196. this.map = null;
  12197. this.aoMap = null;
  12198. this.aoMapIntensity = 1.0;
  12199. this.specularMap = null;
  12200. this.alphaMap = null;
  12201. this.envMap = null;
  12202. this.combine = THREE.MultiplyOperation;
  12203. this.reflectivity = 1;
  12204. this.refractionRatio = 0.98;
  12205. this.fog = true;
  12206. this.shading = THREE.SmoothShading;
  12207. this.blending = THREE.NormalBlending;
  12208. this.wireframe = false;
  12209. this.wireframeLinewidth = 1;
  12210. this.wireframeLinecap = 'round';
  12211. this.wireframeLinejoin = 'round';
  12212. this.vertexColors = THREE.NoColors;
  12213. this.skinning = false;
  12214. this.morphTargets = false;
  12215. this.setValues( parameters );
  12216. };
  12217. THREE.MeshBasicMaterial.prototype = Object.create( THREE.Material.prototype );
  12218. THREE.MeshBasicMaterial.prototype.constructor = THREE.MeshBasicMaterial;
  12219. THREE.MeshBasicMaterial.prototype.copy = function ( source ) {
  12220. THREE.Material.prototype.copy.call( this, source );
  12221. this.color.copy( source.color );
  12222. this.map = source.map;
  12223. this.aoMap = source.aoMap;
  12224. this.aoMapIntensity = source.aoMapIntensity;
  12225. this.specularMap = source.specularMap;
  12226. this.alphaMap = source.alphaMap;
  12227. this.envMap = source.envMap;
  12228. this.combine = source.combine;
  12229. this.reflectivity = source.reflectivity;
  12230. this.refractionRatio = source.refractionRatio;
  12231. this.fog = source.fog;
  12232. this.shading = source.shading;
  12233. this.wireframe = source.wireframe;
  12234. this.wireframeLinewidth = source.wireframeLinewidth;
  12235. this.wireframeLinecap = source.wireframeLinecap;
  12236. this.wireframeLinejoin = source.wireframeLinejoin;
  12237. this.vertexColors = source.vertexColors;
  12238. this.skinning = source.skinning;
  12239. this.morphTargets = source.morphTargets;
  12240. return this;
  12241. };
  12242. // File:src/materials/MeshDepthMaterial.js
  12243. /**
  12244. * @author mrdoob / http://mrdoob.com/
  12245. * @author alteredq / http://alteredqualia.com/
  12246. * @author bhouston / https://clara.io
  12247. * @author WestLangley / http://github.com/WestLangley
  12248. *
  12249. * parameters = {
  12250. *
  12251. * opacity: <float>,
  12252. *
  12253. * map: new THREE.Texture( <Image> ),
  12254. *
  12255. * alphaMap: new THREE.Texture( <Image> ),
  12256. *
  12257. * displacementMap: new THREE.Texture( <Image> ),
  12258. * displacementScale: <float>,
  12259. * displacementBias: <float>,
  12260. *
  12261. * wireframe: <boolean>,
  12262. * wireframeLinewidth: <float>
  12263. * }
  12264. */
  12265. THREE.MeshDepthMaterial = function ( parameters ) {
  12266. THREE.Material.call( this );
  12267. this.type = 'MeshDepthMaterial';
  12268. this.depthPacking = THREE.BasicDepthPacking;
  12269. this.skinning = false;
  12270. this.morphTargets = false;
  12271. this.map = null;
  12272. this.alphaMap = null;
  12273. this.displacementMap = null;
  12274. this.displacementScale = 1;
  12275. this.displacementBias = 0;
  12276. this.wireframe = false;
  12277. this.wireframeLinewidth = 1;
  12278. this.setValues( parameters );
  12279. };
  12280. THREE.MeshDepthMaterial.prototype = Object.create( THREE.Material.prototype );
  12281. THREE.MeshDepthMaterial.prototype.constructor = THREE.MeshDepthMaterial;
  12282. THREE.MeshDepthMaterial.prototype.copy = function ( source ) {
  12283. THREE.Material.prototype.copy.call( this, source );
  12284. this.depthPacking = source.depthPacking;
  12285. this.skinning = source.skinning;
  12286. this.morphTargets = source.morphTargets;
  12287. this.map = source.map;
  12288. this.alphaMap = source.alphaMap;
  12289. this.displacementMap = source.displacementMap;
  12290. this.displacementScale = source.displacementScale;
  12291. this.displacementBias = source.displacementBias;
  12292. this.wireframe = source.wireframe;
  12293. this.wireframeLinewidth = source.wireframeLinewidth;
  12294. return this;
  12295. };
  12296. // File:src/materials/MeshLambertMaterial.js
  12297. /**
  12298. * @author mrdoob / http://mrdoob.com/
  12299. * @author alteredq / http://alteredqualia.com/
  12300. *
  12301. * parameters = {
  12302. * color: <hex>,
  12303. * opacity: <float>,
  12304. *
  12305. * map: new THREE.Texture( <Image> ),
  12306. *
  12307. * lightMap: new THREE.Texture( <Image> ),
  12308. * lightMapIntensity: <float>
  12309. *
  12310. * aoMap: new THREE.Texture( <Image> ),
  12311. * aoMapIntensity: <float>
  12312. *
  12313. * emissive: <hex>,
  12314. * emissiveIntensity: <float>
  12315. * emissiveMap: new THREE.Texture( <Image> ),
  12316. *
  12317. * specularMap: new THREE.Texture( <Image> ),
  12318. *
  12319. * alphaMap: new THREE.Texture( <Image> ),
  12320. *
  12321. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  12322. * combine: THREE.Multiply,
  12323. * reflectivity: <float>,
  12324. * refractionRatio: <float>,
  12325. *
  12326. * blending: THREE.NormalBlending,
  12327. * depthTest: <bool>,
  12328. * depthWrite: <bool>,
  12329. *
  12330. * wireframe: <boolean>,
  12331. * wireframeLinewidth: <float>,
  12332. *
  12333. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  12334. *
  12335. * skinning: <bool>,
  12336. * morphTargets: <bool>,
  12337. * morphNormals: <bool>,
  12338. *
  12339. * fog: <bool>
  12340. * }
  12341. */
  12342. THREE.MeshLambertMaterial = function ( parameters ) {
  12343. THREE.Material.call( this );
  12344. this.type = 'MeshLambertMaterial';
  12345. this.color = new THREE.Color( 0xffffff ); // diffuse
  12346. this.map = null;
  12347. this.lightMap = null;
  12348. this.lightMapIntensity = 1.0;
  12349. this.aoMap = null;
  12350. this.aoMapIntensity = 1.0;
  12351. this.emissive = new THREE.Color( 0x000000 );
  12352. this.emissiveIntensity = 1.0;
  12353. this.emissiveMap = null;
  12354. this.specularMap = null;
  12355. this.alphaMap = null;
  12356. this.envMap = null;
  12357. this.combine = THREE.MultiplyOperation;
  12358. this.reflectivity = 1;
  12359. this.refractionRatio = 0.98;
  12360. this.fog = true;
  12361. this.blending = THREE.NormalBlending;
  12362. this.wireframe = false;
  12363. this.wireframeLinewidth = 1;
  12364. this.wireframeLinecap = 'round';
  12365. this.wireframeLinejoin = 'round';
  12366. this.vertexColors = THREE.NoColors;
  12367. this.skinning = false;
  12368. this.morphTargets = false;
  12369. this.morphNormals = false;
  12370. this.setValues( parameters );
  12371. };
  12372. THREE.MeshLambertMaterial.prototype = Object.create( THREE.Material.prototype );
  12373. THREE.MeshLambertMaterial.prototype.constructor = THREE.MeshLambertMaterial;
  12374. THREE.MeshLambertMaterial.prototype.copy = function ( source ) {
  12375. THREE.Material.prototype.copy.call( this, source );
  12376. this.color.copy( source.color );
  12377. this.map = source.map;
  12378. this.lightMap = source.lightMap;
  12379. this.lightMapIntensity = source.lightMapIntensity;
  12380. this.aoMap = source.aoMap;
  12381. this.aoMapIntensity = source.aoMapIntensity;
  12382. this.emissive.copy( source.emissive );
  12383. this.emissiveMap = source.emissiveMap;
  12384. this.emissiveIntensity = source.emissiveIntensity;
  12385. this.specularMap = source.specularMap;
  12386. this.alphaMap = source.alphaMap;
  12387. this.envMap = source.envMap;
  12388. this.combine = source.combine;
  12389. this.reflectivity = source.reflectivity;
  12390. this.refractionRatio = source.refractionRatio;
  12391. this.fog = source.fog;
  12392. this.wireframe = source.wireframe;
  12393. this.wireframeLinewidth = source.wireframeLinewidth;
  12394. this.wireframeLinecap = source.wireframeLinecap;
  12395. this.wireframeLinejoin = source.wireframeLinejoin;
  12396. this.vertexColors = source.vertexColors;
  12397. this.skinning = source.skinning;
  12398. this.morphTargets = source.morphTargets;
  12399. this.morphNormals = source.morphNormals;
  12400. return this;
  12401. };
  12402. // File:src/materials/MeshNormalMaterial.js
  12403. /**
  12404. * @author mrdoob / http://mrdoob.com/
  12405. *
  12406. * parameters = {
  12407. * opacity: <float>,
  12408. *
  12409. * wireframe: <boolean>,
  12410. * wireframeLinewidth: <float>
  12411. * }
  12412. */
  12413. THREE.MeshNormalMaterial = function ( parameters ) {
  12414. THREE.Material.call( this, parameters );
  12415. this.type = 'MeshNormalMaterial';
  12416. this.wireframe = false;
  12417. this.wireframeLinewidth = 1;
  12418. this.morphTargets = false;
  12419. this.setValues( parameters );
  12420. };
  12421. THREE.MeshNormalMaterial.prototype = Object.create( THREE.Material.prototype );
  12422. THREE.MeshNormalMaterial.prototype.constructor = THREE.MeshNormalMaterial;
  12423. THREE.MeshNormalMaterial.prototype.copy = function ( source ) {
  12424. THREE.Material.prototype.copy.call( this, source );
  12425. this.wireframe = source.wireframe;
  12426. this.wireframeLinewidth = source.wireframeLinewidth;
  12427. return this;
  12428. };
  12429. // File:src/materials/MeshPhongMaterial.js
  12430. /**
  12431. * @author mrdoob / http://mrdoob.com/
  12432. * @author alteredq / http://alteredqualia.com/
  12433. *
  12434. * parameters = {
  12435. * color: <hex>,
  12436. * specular: <hex>,
  12437. * shininess: <float>,
  12438. * opacity: <float>,
  12439. *
  12440. * map: new THREE.Texture( <Image> ),
  12441. *
  12442. * lightMap: new THREE.Texture( <Image> ),
  12443. * lightMapIntensity: <float>
  12444. *
  12445. * aoMap: new THREE.Texture( <Image> ),
  12446. * aoMapIntensity: <float>
  12447. *
  12448. * emissive: <hex>,
  12449. * emissiveIntensity: <float>
  12450. * emissiveMap: new THREE.Texture( <Image> ),
  12451. *
  12452. * bumpMap: new THREE.Texture( <Image> ),
  12453. * bumpScale: <float>,
  12454. *
  12455. * normalMap: new THREE.Texture( <Image> ),
  12456. * normalScale: <Vector2>,
  12457. *
  12458. * displacementMap: new THREE.Texture( <Image> ),
  12459. * displacementScale: <float>,
  12460. * displacementBias: <float>,
  12461. *
  12462. * specularMap: new THREE.Texture( <Image> ),
  12463. *
  12464. * alphaMap: new THREE.Texture( <Image> ),
  12465. *
  12466. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  12467. * combine: THREE.Multiply,
  12468. * reflectivity: <float>,
  12469. * refractionRatio: <float>,
  12470. *
  12471. * shading: THREE.SmoothShading,
  12472. * blending: THREE.NormalBlending,
  12473. * depthTest: <bool>,
  12474. * depthWrite: <bool>,
  12475. *
  12476. * wireframe: <boolean>,
  12477. * wireframeLinewidth: <float>,
  12478. *
  12479. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  12480. *
  12481. * skinning: <bool>,
  12482. * morphTargets: <bool>,
  12483. * morphNormals: <bool>,
  12484. *
  12485. * fog: <bool>
  12486. * }
  12487. */
  12488. THREE.MeshPhongMaterial = function ( parameters ) {
  12489. THREE.Material.call( this );
  12490. this.type = 'MeshPhongMaterial';
  12491. this.color = new THREE.Color( 0xffffff ); // diffuse
  12492. this.specular = new THREE.Color( 0x111111 );
  12493. this.shininess = 30;
  12494. this.map = null;
  12495. this.lightMap = null;
  12496. this.lightMapIntensity = 1.0;
  12497. this.aoMap = null;
  12498. this.aoMapIntensity = 1.0;
  12499. this.emissive = new THREE.Color( 0x000000 );
  12500. this.emissiveIntensity = 1.0;
  12501. this.emissiveMap = null;
  12502. this.bumpMap = null;
  12503. this.bumpScale = 1;
  12504. this.normalMap = null;
  12505. this.normalScale = new THREE.Vector2( 1, 1 );
  12506. this.displacementMap = null;
  12507. this.displacementScale = 1;
  12508. this.displacementBias = 0;
  12509. this.specularMap = null;
  12510. this.alphaMap = null;
  12511. this.envMap = null;
  12512. this.combine = THREE.MultiplyOperation;
  12513. this.reflectivity = 1;
  12514. this.refractionRatio = 0.98;
  12515. this.fog = true;
  12516. this.shading = THREE.SmoothShading;
  12517. this.blending = THREE.NormalBlending;
  12518. this.wireframe = false;
  12519. this.wireframeLinewidth = 1;
  12520. this.wireframeLinecap = 'round';
  12521. this.wireframeLinejoin = 'round';
  12522. this.vertexColors = THREE.NoColors;
  12523. this.skinning = false;
  12524. this.morphTargets = false;
  12525. this.morphNormals = false;
  12526. this.setValues( parameters );
  12527. };
  12528. THREE.MeshPhongMaterial.prototype = Object.create( THREE.Material.prototype );
  12529. THREE.MeshPhongMaterial.prototype.constructor = THREE.MeshPhongMaterial;
  12530. THREE.MeshPhongMaterial.prototype.copy = function ( source ) {
  12531. THREE.Material.prototype.copy.call( this, source );
  12532. this.color.copy( source.color );
  12533. this.specular.copy( source.specular );
  12534. this.shininess = source.shininess;
  12535. this.map = source.map;
  12536. this.lightMap = source.lightMap;
  12537. this.lightMapIntensity = source.lightMapIntensity;
  12538. this.aoMap = source.aoMap;
  12539. this.aoMapIntensity = source.aoMapIntensity;
  12540. this.emissive.copy( source.emissive );
  12541. this.emissiveMap = source.emissiveMap;
  12542. this.emissiveIntensity = source.emissiveIntensity;
  12543. this.bumpMap = source.bumpMap;
  12544. this.bumpScale = source.bumpScale;
  12545. this.normalMap = source.normalMap;
  12546. this.normalScale.copy( source.normalScale );
  12547. this.displacementMap = source.displacementMap;
  12548. this.displacementScale = source.displacementScale;
  12549. this.displacementBias = source.displacementBias;
  12550. this.specularMap = source.specularMap;
  12551. this.alphaMap = source.alphaMap;
  12552. this.envMap = source.envMap;
  12553. this.combine = source.combine;
  12554. this.reflectivity = source.reflectivity;
  12555. this.refractionRatio = source.refractionRatio;
  12556. this.fog = source.fog;
  12557. this.shading = source.shading;
  12558. this.wireframe = source.wireframe;
  12559. this.wireframeLinewidth = source.wireframeLinewidth;
  12560. this.wireframeLinecap = source.wireframeLinecap;
  12561. this.wireframeLinejoin = source.wireframeLinejoin;
  12562. this.vertexColors = source.vertexColors;
  12563. this.skinning = source.skinning;
  12564. this.morphTargets = source.morphTargets;
  12565. this.morphNormals = source.morphNormals;
  12566. return this;
  12567. };
  12568. // File:src/materials/MeshStandardMaterial.js
  12569. /**
  12570. * @author WestLangley / http://github.com/WestLangley
  12571. *
  12572. * parameters = {
  12573. * color: <hex>,
  12574. * roughness: <float>,
  12575. * metalness: <float>,
  12576. * opacity: <float>,
  12577. *
  12578. * map: new THREE.Texture( <Image> ),
  12579. *
  12580. * lightMap: new THREE.Texture( <Image> ),
  12581. * lightMapIntensity: <float>
  12582. *
  12583. * aoMap: new THREE.Texture( <Image> ),
  12584. * aoMapIntensity: <float>
  12585. *
  12586. * emissive: <hex>,
  12587. * emissiveIntensity: <float>
  12588. * emissiveMap: new THREE.Texture( <Image> ),
  12589. *
  12590. * bumpMap: new THREE.Texture( <Image> ),
  12591. * bumpScale: <float>,
  12592. *
  12593. * normalMap: new THREE.Texture( <Image> ),
  12594. * normalScale: <Vector2>,
  12595. *
  12596. * displacementMap: new THREE.Texture( <Image> ),
  12597. * displacementScale: <float>,
  12598. * displacementBias: <float>,
  12599. *
  12600. * roughnessMap: new THREE.Texture( <Image> ),
  12601. *
  12602. * metalnessMap: new THREE.Texture( <Image> ),
  12603. *
  12604. * alphaMap: new THREE.Texture( <Image> ),
  12605. *
  12606. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  12607. * envMapIntensity: <float>
  12608. *
  12609. * refractionRatio: <float>,
  12610. *
  12611. * shading: THREE.SmoothShading,
  12612. * blending: THREE.NormalBlending,
  12613. * depthTest: <bool>,
  12614. * depthWrite: <bool>,
  12615. *
  12616. * wireframe: <boolean>,
  12617. * wireframeLinewidth: <float>,
  12618. *
  12619. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  12620. *
  12621. * skinning: <bool>,
  12622. * morphTargets: <bool>,
  12623. * morphNormals: <bool>,
  12624. *
  12625. * fog: <bool>
  12626. * }
  12627. */
  12628. THREE.MeshStandardMaterial = function ( parameters ) {
  12629. THREE.Material.call( this );
  12630. this.defines = { 'STANDARD': '' };
  12631. this.type = 'MeshStandardMaterial';
  12632. this.color = new THREE.Color( 0xffffff ); // diffuse
  12633. this.roughness = 0.5;
  12634. this.metalness = 0.5;
  12635. this.map = null;
  12636. this.lightMap = null;
  12637. this.lightMapIntensity = 1.0;
  12638. this.aoMap = null;
  12639. this.aoMapIntensity = 1.0;
  12640. this.emissive = new THREE.Color( 0x000000 );
  12641. this.emissiveIntensity = 1.0;
  12642. this.emissiveMap = null;
  12643. this.bumpMap = null;
  12644. this.bumpScale = 1;
  12645. this.normalMap = null;
  12646. this.normalScale = new THREE.Vector2( 1, 1 );
  12647. this.displacementMap = null;
  12648. this.displacementScale = 1;
  12649. this.displacementBias = 0;
  12650. this.roughnessMap = null;
  12651. this.metalnessMap = null;
  12652. this.alphaMap = null;
  12653. this.envMap = null;
  12654. this.envMapIntensity = 1.0;
  12655. this.refractionRatio = 0.98;
  12656. this.fog = true;
  12657. this.shading = THREE.SmoothShading;
  12658. this.blending = THREE.NormalBlending;
  12659. this.wireframe = false;
  12660. this.wireframeLinewidth = 1;
  12661. this.wireframeLinecap = 'round';
  12662. this.wireframeLinejoin = 'round';
  12663. this.vertexColors = THREE.NoColors;
  12664. this.skinning = false;
  12665. this.morphTargets = false;
  12666. this.morphNormals = false;
  12667. this.setValues( parameters );
  12668. };
  12669. THREE.MeshStandardMaterial.prototype = Object.create( THREE.Material.prototype );
  12670. THREE.MeshStandardMaterial.prototype.constructor = THREE.MeshStandardMaterial;
  12671. THREE.MeshStandardMaterial.prototype.copy = function ( source ) {
  12672. THREE.Material.prototype.copy.call( this, source );
  12673. this.defines = { 'STANDARD': '' };
  12674. this.color.copy( source.color );
  12675. this.roughness = source.roughness;
  12676. this.metalness = source.metalness;
  12677. this.map = source.map;
  12678. this.lightMap = source.lightMap;
  12679. this.lightMapIntensity = source.lightMapIntensity;
  12680. this.aoMap = source.aoMap;
  12681. this.aoMapIntensity = source.aoMapIntensity;
  12682. this.emissive.copy( source.emissive );
  12683. this.emissiveMap = source.emissiveMap;
  12684. this.emissiveIntensity = source.emissiveIntensity;
  12685. this.bumpMap = source.bumpMap;
  12686. this.bumpScale = source.bumpScale;
  12687. this.normalMap = source.normalMap;
  12688. this.normalScale.copy( source.normalScale );
  12689. this.displacementMap = source.displacementMap;
  12690. this.displacementScale = source.displacementScale;
  12691. this.displacementBias = source.displacementBias;
  12692. this.roughnessMap = source.roughnessMap;
  12693. this.metalnessMap = source.metalnessMap;
  12694. this.alphaMap = source.alphaMap;
  12695. this.envMap = source.envMap;
  12696. this.envMapIntensity = source.envMapIntensity;
  12697. this.refractionRatio = source.refractionRatio;
  12698. this.fog = source.fog;
  12699. this.shading = source.shading;
  12700. this.wireframe = source.wireframe;
  12701. this.wireframeLinewidth = source.wireframeLinewidth;
  12702. this.wireframeLinecap = source.wireframeLinecap;
  12703. this.wireframeLinejoin = source.wireframeLinejoin;
  12704. this.vertexColors = source.vertexColors;
  12705. this.skinning = source.skinning;
  12706. this.morphTargets = source.morphTargets;
  12707. this.morphNormals = source.morphNormals;
  12708. return this;
  12709. };
  12710. // File:src/materials/MeshPhysicalMaterial.js
  12711. /**
  12712. * @author WestLangley / http://github.com/WestLangley
  12713. *
  12714. * parameters = {
  12715. * reflectivity: <float>
  12716. * }
  12717. */
  12718. THREE.MeshPhysicalMaterial = function ( parameters ) {
  12719. THREE.MeshStandardMaterial.call( this );
  12720. this.defines = { 'PHYSICAL': '' };
  12721. this.type = 'MeshPhysicalMaterial';
  12722. this.reflectivity = 0.5; // maps to F0 = 0.04
  12723. this.setValues( parameters );
  12724. };
  12725. THREE.MeshPhysicalMaterial.prototype = Object.create( THREE.MeshStandardMaterial.prototype );
  12726. THREE.MeshPhysicalMaterial.prototype.constructor = THREE.MeshPhysicalMaterial;
  12727. THREE.MeshPhysicalMaterial.prototype.copy = function ( source ) {
  12728. THREE.MeshStandardMaterial.prototype.copy.call( this, source );
  12729. this.defines = { 'PHYSICAL': '' };
  12730. this.reflectivity = source.reflectivity;
  12731. return this;
  12732. };
  12733. // File:src/materials/MultiMaterial.js
  12734. /**
  12735. * @author mrdoob / http://mrdoob.com/
  12736. */
  12737. THREE.MultiMaterial = function ( materials ) {
  12738. this.uuid = THREE.Math.generateUUID();
  12739. this.type = 'MultiMaterial';
  12740. this.materials = materials instanceof Array ? materials : [];
  12741. this.visible = true;
  12742. };
  12743. THREE.MultiMaterial.prototype = {
  12744. constructor: THREE.MultiMaterial,
  12745. toJSON: function ( meta ) {
  12746. var output = {
  12747. metadata: {
  12748. version: 4.2,
  12749. type: 'material',
  12750. generator: 'MaterialExporter'
  12751. },
  12752. uuid: this.uuid,
  12753. type: this.type,
  12754. materials: []
  12755. };
  12756. var materials = this.materials;
  12757. for ( var i = 0, l = materials.length; i < l; i ++ ) {
  12758. var material = materials[ i ].toJSON( meta );
  12759. delete material.metadata;
  12760. output.materials.push( material );
  12761. }
  12762. output.visible = this.visible;
  12763. return output;
  12764. },
  12765. clone: function () {
  12766. var material = new this.constructor();
  12767. for ( var i = 0; i < this.materials.length; i ++ ) {
  12768. material.materials.push( this.materials[ i ].clone() );
  12769. }
  12770. material.visible = this.visible;
  12771. return material;
  12772. }
  12773. };
  12774. // File:src/materials/PointsMaterial.js
  12775. /**
  12776. * @author mrdoob / http://mrdoob.com/
  12777. * @author alteredq / http://alteredqualia.com/
  12778. *
  12779. * parameters = {
  12780. * color: <hex>,
  12781. * opacity: <float>,
  12782. * map: new THREE.Texture( <Image> ),
  12783. *
  12784. * size: <float>,
  12785. * sizeAttenuation: <bool>,
  12786. *
  12787. * blending: THREE.NormalBlending,
  12788. * depthTest: <bool>,
  12789. * depthWrite: <bool>,
  12790. *
  12791. * vertexColors: <bool>,
  12792. *
  12793. * fog: <bool>
  12794. * }
  12795. */
  12796. THREE.PointsMaterial = function ( parameters ) {
  12797. THREE.Material.call( this );
  12798. this.type = 'PointsMaterial';
  12799. this.color = new THREE.Color( 0xffffff );
  12800. this.map = null;
  12801. this.size = 1;
  12802. this.sizeAttenuation = true;
  12803. this.blending = THREE.NormalBlending;
  12804. this.vertexColors = THREE.NoColors;
  12805. this.fog = true;
  12806. this.setValues( parameters );
  12807. };
  12808. THREE.PointsMaterial.prototype = Object.create( THREE.Material.prototype );
  12809. THREE.PointsMaterial.prototype.constructor = THREE.PointsMaterial;
  12810. THREE.PointsMaterial.prototype.copy = function ( source ) {
  12811. THREE.Material.prototype.copy.call( this, source );
  12812. this.color.copy( source.color );
  12813. this.map = source.map;
  12814. this.size = source.size;
  12815. this.sizeAttenuation = source.sizeAttenuation;
  12816. this.vertexColors = source.vertexColors;
  12817. this.fog = source.fog;
  12818. return this;
  12819. };
  12820. // File:src/materials/ShaderMaterial.js
  12821. /**
  12822. * @author alteredq / http://alteredqualia.com/
  12823. *
  12824. * parameters = {
  12825. * defines: { "label" : "value" },
  12826. * uniforms: { "parameter1": { type: "1f", value: 1.0 }, "parameter2": { type: "1i" value2: 2 } },
  12827. *
  12828. * fragmentShader: <string>,
  12829. * vertexShader: <string>,
  12830. *
  12831. * shading: THREE.SmoothShading,
  12832. *
  12833. * wireframe: <boolean>,
  12834. * wireframeLinewidth: <float>,
  12835. *
  12836. * lights: <bool>,
  12837. *
  12838. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  12839. *
  12840. * skinning: <bool>,
  12841. * morphTargets: <bool>,
  12842. * morphNormals: <bool>,
  12843. *
  12844. * fog: <bool>
  12845. * }
  12846. */
  12847. THREE.ShaderMaterial = function ( parameters ) {
  12848. THREE.Material.call( this );
  12849. this.type = 'ShaderMaterial';
  12850. this.defines = {};
  12851. this.uniforms = {};
  12852. this.vertexShader = 'void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}';
  12853. this.fragmentShader = 'void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}';
  12854. this.shading = THREE.SmoothShading;
  12855. this.linewidth = 1;
  12856. this.wireframe = false;
  12857. this.wireframeLinewidth = 1;
  12858. this.fog = false; // set to use scene fog
  12859. this.lights = false; // set to use scene lights
  12860. this.clipping = false; // set to use user-defined clipping planes
  12861. this.vertexColors = THREE.NoColors; // set to use "color" attribute stream
  12862. this.skinning = false; // set to use skinning attribute streams
  12863. this.morphTargets = false; // set to use morph targets
  12864. this.morphNormals = false; // set to use morph normals
  12865. this.extensions = {
  12866. derivatives: false, // set to use derivatives
  12867. fragDepth: false, // set to use fragment depth values
  12868. drawBuffers: false, // set to use draw buffers
  12869. shaderTextureLOD: false // set to use shader texture LOD
  12870. };
  12871. // When rendered geometry doesn't include these attributes but the material does,
  12872. // use these default values in WebGL. This avoids errors when buffer data is missing.
  12873. this.defaultAttributeValues = {
  12874. 'color': [ 1, 1, 1 ],
  12875. 'uv': [ 0, 0 ],
  12876. 'uv2': [ 0, 0 ]
  12877. };
  12878. this.index0AttributeName = undefined;
  12879. if ( parameters !== undefined ) {
  12880. if ( parameters.attributes !== undefined ) {
  12881. console.error( 'THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.' );
  12882. }
  12883. this.setValues( parameters );
  12884. }
  12885. };
  12886. THREE.ShaderMaterial.prototype = Object.create( THREE.Material.prototype );
  12887. THREE.ShaderMaterial.prototype.constructor = THREE.ShaderMaterial;
  12888. THREE.ShaderMaterial.prototype.copy = function ( source ) {
  12889. THREE.Material.prototype.copy.call( this, source );
  12890. this.fragmentShader = source.fragmentShader;
  12891. this.vertexShader = source.vertexShader;
  12892. this.uniforms = THREE.UniformsUtils.clone( source.uniforms );
  12893. this.defines = source.defines;
  12894. this.shading = source.shading;
  12895. this.wireframe = source.wireframe;
  12896. this.wireframeLinewidth = source.wireframeLinewidth;
  12897. this.fog = source.fog;
  12898. this.lights = source.lights;
  12899. this.clipping = source.clipping;
  12900. this.vertexColors = source.vertexColors;
  12901. this.skinning = source.skinning;
  12902. this.morphTargets = source.morphTargets;
  12903. this.morphNormals = source.morphNormals;
  12904. this.extensions = source.extensions;
  12905. return this;
  12906. };
  12907. THREE.ShaderMaterial.prototype.toJSON = function ( meta ) {
  12908. var data = THREE.Material.prototype.toJSON.call( this, meta );
  12909. data.uniforms = this.uniforms;
  12910. data.vertexShader = this.vertexShader;
  12911. data.fragmentShader = this.fragmentShader;
  12912. return data;
  12913. };
  12914. // File:src/materials/RawShaderMaterial.js
  12915. /**
  12916. * @author mrdoob / http://mrdoob.com/
  12917. */
  12918. THREE.RawShaderMaterial = function ( parameters ) {
  12919. THREE.ShaderMaterial.call( this, parameters );
  12920. this.type = 'RawShaderMaterial';
  12921. };
  12922. THREE.RawShaderMaterial.prototype = Object.create( THREE.ShaderMaterial.prototype );
  12923. THREE.RawShaderMaterial.prototype.constructor = THREE.RawShaderMaterial;
  12924. // File:src/materials/SpriteMaterial.js
  12925. /**
  12926. * @author alteredq / http://alteredqualia.com/
  12927. *
  12928. * parameters = {
  12929. * color: <hex>,
  12930. * opacity: <float>,
  12931. * map: new THREE.Texture( <Image> ),
  12932. *
  12933. * uvOffset: new THREE.Vector2(),
  12934. * uvScale: new THREE.Vector2(),
  12935. *
  12936. * fog: <bool>
  12937. * }
  12938. */
  12939. THREE.SpriteMaterial = function ( parameters ) {
  12940. THREE.Material.call( this );
  12941. this.type = 'SpriteMaterial';
  12942. this.color = new THREE.Color( 0xffffff );
  12943. this.map = null;
  12944. this.rotation = 0;
  12945. this.fog = false;
  12946. // set parameters
  12947. this.setValues( parameters );
  12948. };
  12949. THREE.SpriteMaterial.prototype = Object.create( THREE.Material.prototype );
  12950. THREE.SpriteMaterial.prototype.constructor = THREE.SpriteMaterial;
  12951. THREE.SpriteMaterial.prototype.copy = function ( source ) {
  12952. THREE.Material.prototype.copy.call( this, source );
  12953. this.color.copy( source.color );
  12954. this.map = source.map;
  12955. this.rotation = source.rotation;
  12956. this.fog = source.fog;
  12957. return this;
  12958. };
  12959. // File:src/textures/Texture.js
  12960. /**
  12961. * @author mrdoob / http://mrdoob.com/
  12962. * @author alteredq / http://alteredqualia.com/
  12963. * @author szimek / https://github.com/szimek/
  12964. */
  12965. THREE.Texture = function ( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  12966. Object.defineProperty( this, 'id', { value: THREE.TextureIdCount ++ } );
  12967. this.uuid = THREE.Math.generateUUID();
  12968. this.name = '';
  12969. this.sourceFile = '';
  12970. this.image = image !== undefined ? image : THREE.Texture.DEFAULT_IMAGE;
  12971. this.mipmaps = [];
  12972. this.mapping = mapping !== undefined ? mapping : THREE.Texture.DEFAULT_MAPPING;
  12973. this.wrapS = wrapS !== undefined ? wrapS : THREE.ClampToEdgeWrapping;
  12974. this.wrapT = wrapT !== undefined ? wrapT : THREE.ClampToEdgeWrapping;
  12975. this.magFilter = magFilter !== undefined ? magFilter : THREE.LinearFilter;
  12976. this.minFilter = minFilter !== undefined ? minFilter : THREE.LinearMipMapLinearFilter;
  12977. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  12978. this.format = format !== undefined ? format : THREE.RGBAFormat;
  12979. this.type = type !== undefined ? type : THREE.UnsignedByteType;
  12980. this.offset = new THREE.Vector2( 0, 0 );
  12981. this.repeat = new THREE.Vector2( 1, 1 );
  12982. this.generateMipmaps = true;
  12983. this.premultiplyAlpha = false;
  12984. this.flipY = true;
  12985. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  12986. // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
  12987. //
  12988. // Also changing the encoding after already used by a Material will not automatically make the Material
  12989. // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
  12990. this.encoding = encoding !== undefined ? encoding : THREE.LinearEncoding;
  12991. this.version = 0;
  12992. this.onUpdate = null;
  12993. };
  12994. THREE.Texture.DEFAULT_IMAGE = undefined;
  12995. THREE.Texture.DEFAULT_MAPPING = THREE.UVMapping;
  12996. THREE.Texture.prototype = {
  12997. constructor: THREE.Texture,
  12998. set needsUpdate ( value ) {
  12999. if ( value === true ) this.version ++;
  13000. },
  13001. clone: function () {
  13002. return new this.constructor().copy( this );
  13003. },
  13004. copy: function ( source ) {
  13005. this.image = source.image;
  13006. this.mipmaps = source.mipmaps.slice( 0 );
  13007. this.mapping = source.mapping;
  13008. this.wrapS = source.wrapS;
  13009. this.wrapT = source.wrapT;
  13010. this.magFilter = source.magFilter;
  13011. this.minFilter = source.minFilter;
  13012. this.anisotropy = source.anisotropy;
  13013. this.format = source.format;
  13014. this.type = source.type;
  13015. this.offset.copy( source.offset );
  13016. this.repeat.copy( source.repeat );
  13017. this.generateMipmaps = source.generateMipmaps;
  13018. this.premultiplyAlpha = source.premultiplyAlpha;
  13019. this.flipY = source.flipY;
  13020. this.unpackAlignment = source.unpackAlignment;
  13021. this.encoding = source.encoding;
  13022. return this;
  13023. },
  13024. toJSON: function ( meta ) {
  13025. if ( meta.textures[ this.uuid ] !== undefined ) {
  13026. return meta.textures[ this.uuid ];
  13027. }
  13028. function getDataURL( image ) {
  13029. var canvas;
  13030. if ( image.toDataURL !== undefined ) {
  13031. canvas = image;
  13032. } else {
  13033. canvas = document.createElement( 'canvas' );
  13034. canvas.width = image.width;
  13035. canvas.height = image.height;
  13036. canvas.getContext( '2d' ).drawImage( image, 0, 0, image.width, image.height );
  13037. }
  13038. if ( canvas.width > 2048 || canvas.height > 2048 ) {
  13039. return canvas.toDataURL( 'image/jpeg', 0.6 );
  13040. } else {
  13041. return canvas.toDataURL( 'image/png' );
  13042. }
  13043. }
  13044. var output = {
  13045. metadata: {
  13046. version: 4.4,
  13047. type: 'Texture',
  13048. generator: 'Texture.toJSON'
  13049. },
  13050. uuid: this.uuid,
  13051. name: this.name,
  13052. mapping: this.mapping,
  13053. repeat: [ this.repeat.x, this.repeat.y ],
  13054. offset: [ this.offset.x, this.offset.y ],
  13055. wrap: [ this.wrapS, this.wrapT ],
  13056. minFilter: this.minFilter,
  13057. magFilter: this.magFilter,
  13058. anisotropy: this.anisotropy
  13059. };
  13060. if ( this.image !== undefined ) {
  13061. // TODO: Move to THREE.Image
  13062. var image = this.image;
  13063. if ( image.uuid === undefined ) {
  13064. image.uuid = THREE.Math.generateUUID(); // UGH
  13065. }
  13066. if ( meta.images[ image.uuid ] === undefined ) {
  13067. meta.images[ image.uuid ] = {
  13068. uuid: image.uuid,
  13069. url: getDataURL( image )
  13070. };
  13071. }
  13072. output.image = image.uuid;
  13073. }
  13074. meta.textures[ this.uuid ] = output;
  13075. return output;
  13076. },
  13077. dispose: function () {
  13078. this.dispatchEvent( { type: 'dispose' } );
  13079. },
  13080. transformUv: function ( uv ) {
  13081. if ( this.mapping !== THREE.UVMapping ) return;
  13082. uv.multiply( this.repeat );
  13083. uv.add( this.offset );
  13084. if ( uv.x < 0 || uv.x > 1 ) {
  13085. switch ( this.wrapS ) {
  13086. case THREE.RepeatWrapping:
  13087. uv.x = uv.x - Math.floor( uv.x );
  13088. break;
  13089. case THREE.ClampToEdgeWrapping:
  13090. uv.x = uv.x < 0 ? 0 : 1;
  13091. break;
  13092. case THREE.MirroredRepeatWrapping:
  13093. if ( Math.abs( Math.floor( uv.x ) % 2 ) === 1 ) {
  13094. uv.x = Math.ceil( uv.x ) - uv.x;
  13095. } else {
  13096. uv.x = uv.x - Math.floor( uv.x );
  13097. }
  13098. break;
  13099. }
  13100. }
  13101. if ( uv.y < 0 || uv.y > 1 ) {
  13102. switch ( this.wrapT ) {
  13103. case THREE.RepeatWrapping:
  13104. uv.y = uv.y - Math.floor( uv.y );
  13105. break;
  13106. case THREE.ClampToEdgeWrapping:
  13107. uv.y = uv.y < 0 ? 0 : 1;
  13108. break;
  13109. case THREE.MirroredRepeatWrapping:
  13110. if ( Math.abs( Math.floor( uv.y ) % 2 ) === 1 ) {
  13111. uv.y = Math.ceil( uv.y ) - uv.y;
  13112. } else {
  13113. uv.y = uv.y - Math.floor( uv.y );
  13114. }
  13115. break;
  13116. }
  13117. }
  13118. if ( this.flipY ) {
  13119. uv.y = 1 - uv.y;
  13120. }
  13121. }
  13122. };
  13123. THREE.EventDispatcher.prototype.apply( THREE.Texture.prototype );
  13124. THREE.TextureIdCount = 0;
  13125. // File:src/textures/DepthTexture.js
  13126. /**
  13127. * @author Matt DesLauriers / @mattdesl
  13128. */
  13129. THREE.DepthTexture = function ( width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy ) {
  13130. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, THREE.DepthFormat, type, anisotropy );
  13131. this.image = { width: width, height: height };
  13132. this.type = type !== undefined ? type : THREE.UnsignedShortType;
  13133. this.magFilter = magFilter !== undefined ? magFilter : THREE.NearestFilter;
  13134. this.minFilter = minFilter !== undefined ? minFilter : THREE.NearestFilter;
  13135. this.flipY = false;
  13136. this.generateMipmaps = false;
  13137. };
  13138. THREE.DepthTexture.prototype = Object.create( THREE.Texture.prototype );
  13139. THREE.DepthTexture.prototype.constructor = THREE.DepthTexture;
  13140. // File:src/textures/CanvasTexture.js
  13141. /**
  13142. * @author mrdoob / http://mrdoob.com/
  13143. */
  13144. THREE.CanvasTexture = function ( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  13145. THREE.Texture.call( this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  13146. this.needsUpdate = true;
  13147. };
  13148. THREE.CanvasTexture.prototype = Object.create( THREE.Texture.prototype );
  13149. THREE.CanvasTexture.prototype.constructor = THREE.CanvasTexture;
  13150. // File:src/textures/CubeTexture.js
  13151. /**
  13152. * @author mrdoob / http://mrdoob.com/
  13153. */
  13154. THREE.CubeTexture = function ( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  13155. images = images !== undefined ? images : [];
  13156. mapping = mapping !== undefined ? mapping : THREE.CubeReflectionMapping;
  13157. THREE.Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  13158. this.flipY = false;
  13159. };
  13160. THREE.CubeTexture.prototype = Object.create( THREE.Texture.prototype );
  13161. THREE.CubeTexture.prototype.constructor = THREE.CubeTexture;
  13162. Object.defineProperty( THREE.CubeTexture.prototype, 'images', {
  13163. get: function () {
  13164. return this.image;
  13165. },
  13166. set: function ( value ) {
  13167. this.image = value;
  13168. }
  13169. } );
  13170. // File:src/textures/CompressedTexture.js
  13171. /**
  13172. * @author alteredq / http://alteredqualia.com/
  13173. */
  13174. THREE.CompressedTexture = function ( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  13175. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  13176. this.image = { width: width, height: height };
  13177. this.mipmaps = mipmaps;
  13178. // no flipping for cube textures
  13179. // (also flipping doesn't work for compressed textures )
  13180. this.flipY = false;
  13181. // can't generate mipmaps for compressed textures
  13182. // mips must be embedded in DDS files
  13183. this.generateMipmaps = false;
  13184. };
  13185. THREE.CompressedTexture.prototype = Object.create( THREE.Texture.prototype );
  13186. THREE.CompressedTexture.prototype.constructor = THREE.CompressedTexture;
  13187. // File:src/textures/DataTexture.js
  13188. /**
  13189. * @author alteredq / http://alteredqualia.com/
  13190. */
  13191. THREE.DataTexture = function ( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  13192. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  13193. this.image = { data: data, width: width, height: height };
  13194. this.magFilter = magFilter !== undefined ? magFilter : THREE.NearestFilter;
  13195. this.minFilter = minFilter !== undefined ? minFilter : THREE.NearestFilter;
  13196. this.flipY = false;
  13197. this.generateMipmaps = false;
  13198. };
  13199. THREE.DataTexture.prototype = Object.create( THREE.Texture.prototype );
  13200. THREE.DataTexture.prototype.constructor = THREE.DataTexture;
  13201. // File:src/textures/VideoTexture.js
  13202. /**
  13203. * @author mrdoob / http://mrdoob.com/
  13204. */
  13205. THREE.VideoTexture = function ( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  13206. THREE.Texture.call( this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  13207. this.generateMipmaps = false;
  13208. var scope = this;
  13209. function update() {
  13210. requestAnimationFrame( update );
  13211. if ( video.readyState >= video.HAVE_CURRENT_DATA ) {
  13212. scope.needsUpdate = true;
  13213. }
  13214. }
  13215. update();
  13216. };
  13217. THREE.VideoTexture.prototype = Object.create( THREE.Texture.prototype );
  13218. THREE.VideoTexture.prototype.constructor = THREE.VideoTexture;
  13219. // File:src/objects/Group.js
  13220. /**
  13221. * @author mrdoob / http://mrdoob.com/
  13222. */
  13223. THREE.Group = function () {
  13224. THREE.Object3D.call( this );
  13225. this.type = 'Group';
  13226. };
  13227. THREE.Group.prototype = Object.create( THREE.Object3D.prototype );
  13228. THREE.Group.prototype.constructor = THREE.Group;
  13229. // File:src/objects/Points.js
  13230. /**
  13231. * @author alteredq / http://alteredqualia.com/
  13232. */
  13233. THREE.Points = function ( geometry, material ) {
  13234. THREE.Object3D.call( this );
  13235. this.type = 'Points';
  13236. this.geometry = geometry !== undefined ? geometry : new THREE.BufferGeometry();
  13237. this.material = material !== undefined ? material : new THREE.PointsMaterial( { color: Math.random() * 0xffffff } );
  13238. };
  13239. THREE.Points.prototype = Object.create( THREE.Object3D.prototype );
  13240. THREE.Points.prototype.constructor = THREE.Points;
  13241. THREE.Points.prototype.raycast = ( function () {
  13242. var inverseMatrix = new THREE.Matrix4();
  13243. var ray = new THREE.Ray();
  13244. var sphere = new THREE.Sphere();
  13245. return function raycast( raycaster, intersects ) {
  13246. var object = this;
  13247. var geometry = this.geometry;
  13248. var matrixWorld = this.matrixWorld;
  13249. var threshold = raycaster.params.Points.threshold;
  13250. // Checking boundingSphere distance to ray
  13251. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  13252. sphere.copy( geometry.boundingSphere );
  13253. sphere.applyMatrix4( matrixWorld );
  13254. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  13255. //
  13256. inverseMatrix.getInverse( matrixWorld );
  13257. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  13258. var localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  13259. var localThresholdSq = localThreshold * localThreshold;
  13260. var position = new THREE.Vector3();
  13261. function testPoint( point, index ) {
  13262. var rayPointDistanceSq = ray.distanceSqToPoint( point );
  13263. if ( rayPointDistanceSq < localThresholdSq ) {
  13264. var intersectPoint = ray.closestPointToPoint( point );
  13265. intersectPoint.applyMatrix4( matrixWorld );
  13266. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  13267. if ( distance < raycaster.near || distance > raycaster.far ) return;
  13268. intersects.push( {
  13269. distance: distance,
  13270. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  13271. point: intersectPoint.clone(),
  13272. index: index,
  13273. face: null,
  13274. object: object
  13275. } );
  13276. }
  13277. }
  13278. if ( geometry instanceof THREE.BufferGeometry ) {
  13279. var index = geometry.index;
  13280. var attributes = geometry.attributes;
  13281. var positions = attributes.position.array;
  13282. if ( index !== null ) {
  13283. var indices = index.array;
  13284. for ( var i = 0, il = indices.length; i < il; i ++ ) {
  13285. var a = indices[ i ];
  13286. position.fromArray( positions, a * 3 );
  13287. testPoint( position, a );
  13288. }
  13289. } else {
  13290. for ( var i = 0, l = positions.length / 3; i < l; i ++ ) {
  13291. position.fromArray( positions, i * 3 );
  13292. testPoint( position, i );
  13293. }
  13294. }
  13295. } else {
  13296. var vertices = geometry.vertices;
  13297. for ( var i = 0, l = vertices.length; i < l; i ++ ) {
  13298. testPoint( vertices[ i ], i );
  13299. }
  13300. }
  13301. };
  13302. }() );
  13303. THREE.Points.prototype.clone = function () {
  13304. return new this.constructor( this.geometry, this.material ).copy( this );
  13305. };
  13306. // File:src/objects/Line.js
  13307. /**
  13308. * @author mrdoob / http://mrdoob.com/
  13309. */
  13310. THREE.Line = function ( geometry, material, mode ) {
  13311. if ( mode === 1 ) {
  13312. console.warn( 'THREE.Line: parameter THREE.LinePieces no longer supported. Created THREE.LineSegments instead.' );
  13313. return new THREE.LineSegments( geometry, material );
  13314. }
  13315. THREE.Object3D.call( this );
  13316. this.type = 'Line';
  13317. this.geometry = geometry !== undefined ? geometry : new THREE.BufferGeometry();
  13318. this.material = material !== undefined ? material : new THREE.LineBasicMaterial( { color: Math.random() * 0xffffff } );
  13319. };
  13320. THREE.Line.prototype = Object.create( THREE.Object3D.prototype );
  13321. THREE.Line.prototype.constructor = THREE.Line;
  13322. THREE.Line.prototype.raycast = ( function () {
  13323. var inverseMatrix = new THREE.Matrix4();
  13324. var ray = new THREE.Ray();
  13325. var sphere = new THREE.Sphere();
  13326. return function raycast( raycaster, intersects ) {
  13327. var precision = raycaster.linePrecision;
  13328. var precisionSq = precision * precision;
  13329. var geometry = this.geometry;
  13330. var matrixWorld = this.matrixWorld;
  13331. // Checking boundingSphere distance to ray
  13332. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  13333. sphere.copy( geometry.boundingSphere );
  13334. sphere.applyMatrix4( matrixWorld );
  13335. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  13336. //
  13337. inverseMatrix.getInverse( matrixWorld );
  13338. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  13339. var vStart = new THREE.Vector3();
  13340. var vEnd = new THREE.Vector3();
  13341. var interSegment = new THREE.Vector3();
  13342. var interRay = new THREE.Vector3();
  13343. var step = this instanceof THREE.LineSegments ? 2 : 1;
  13344. if ( geometry instanceof THREE.BufferGeometry ) {
  13345. var index = geometry.index;
  13346. var attributes = geometry.attributes;
  13347. var positions = attributes.position.array;
  13348. if ( index !== null ) {
  13349. var indices = index.array;
  13350. for ( var i = 0, l = indices.length - 1; i < l; i += step ) {
  13351. var a = indices[ i ];
  13352. var b = indices[ i + 1 ];
  13353. vStart.fromArray( positions, a * 3 );
  13354. vEnd.fromArray( positions, b * 3 );
  13355. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  13356. if ( distSq > precisionSq ) continue;
  13357. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  13358. var distance = raycaster.ray.origin.distanceTo( interRay );
  13359. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  13360. intersects.push( {
  13361. distance: distance,
  13362. // What do we want? intersection point on the ray or on the segment??
  13363. // point: raycaster.ray.at( distance ),
  13364. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  13365. index: i,
  13366. face: null,
  13367. faceIndex: null,
  13368. object: this
  13369. } );
  13370. }
  13371. } else {
  13372. for ( var i = 0, l = positions.length / 3 - 1; i < l; i += step ) {
  13373. vStart.fromArray( positions, 3 * i );
  13374. vEnd.fromArray( positions, 3 * i + 3 );
  13375. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  13376. if ( distSq > precisionSq ) continue;
  13377. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  13378. var distance = raycaster.ray.origin.distanceTo( interRay );
  13379. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  13380. intersects.push( {
  13381. distance: distance,
  13382. // What do we want? intersection point on the ray or on the segment??
  13383. // point: raycaster.ray.at( distance ),
  13384. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  13385. index: i,
  13386. face: null,
  13387. faceIndex: null,
  13388. object: this
  13389. } );
  13390. }
  13391. }
  13392. } else if ( geometry instanceof THREE.Geometry ) {
  13393. var vertices = geometry.vertices;
  13394. var nbVertices = vertices.length;
  13395. for ( var i = 0; i < nbVertices - 1; i += step ) {
  13396. var distSq = ray.distanceSqToSegment( vertices[ i ], vertices[ i + 1 ], interRay, interSegment );
  13397. if ( distSq > precisionSq ) continue;
  13398. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  13399. var distance = raycaster.ray.origin.distanceTo( interRay );
  13400. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  13401. intersects.push( {
  13402. distance: distance,
  13403. // What do we want? intersection point on the ray or on the segment??
  13404. // point: raycaster.ray.at( distance ),
  13405. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  13406. index: i,
  13407. face: null,
  13408. faceIndex: null,
  13409. object: this
  13410. } );
  13411. }
  13412. }
  13413. };
  13414. }() );
  13415. THREE.Line.prototype.clone = function () {
  13416. return new this.constructor( this.geometry, this.material ).copy( this );
  13417. };
  13418. // DEPRECATED
  13419. THREE.LineStrip = 0;
  13420. THREE.LinePieces = 1;
  13421. // File:src/objects/LineSegments.js
  13422. /**
  13423. * @author mrdoob / http://mrdoob.com/
  13424. */
  13425. THREE.LineSegments = function ( geometry, material ) {
  13426. THREE.Line.call( this, geometry, material );
  13427. this.type = 'LineSegments';
  13428. };
  13429. THREE.LineSegments.prototype = Object.create( THREE.Line.prototype );
  13430. THREE.LineSegments.prototype.constructor = THREE.LineSegments;
  13431. // File:src/objects/Mesh.js
  13432. /**
  13433. * @author mrdoob / http://mrdoob.com/
  13434. * @author alteredq / http://alteredqualia.com/
  13435. * @author mikael emtinger / http://gomo.se/
  13436. * @author jonobr1 / http://jonobr1.com/
  13437. */
  13438. THREE.Mesh = function ( geometry, material ) {
  13439. THREE.Object3D.call( this );
  13440. this.type = 'Mesh';
  13441. this.geometry = geometry !== undefined ? geometry : new THREE.BufferGeometry();
  13442. this.material = material !== undefined ? material : new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff } );
  13443. this.drawMode = THREE.TrianglesDrawMode;
  13444. this.updateMorphTargets();
  13445. };
  13446. THREE.Mesh.prototype = Object.create( THREE.Object3D.prototype );
  13447. THREE.Mesh.prototype.constructor = THREE.Mesh;
  13448. THREE.Mesh.prototype.setDrawMode = function ( value ) {
  13449. this.drawMode = value;
  13450. };
  13451. THREE.Mesh.prototype.updateMorphTargets = function () {
  13452. if ( this.geometry.morphTargets !== undefined && this.geometry.morphTargets.length > 0 ) {
  13453. this.morphTargetBase = - 1;
  13454. this.morphTargetInfluences = [];
  13455. this.morphTargetDictionary = {};
  13456. for ( var m = 0, ml = this.geometry.morphTargets.length; m < ml; m ++ ) {
  13457. this.morphTargetInfluences.push( 0 );
  13458. this.morphTargetDictionary[ this.geometry.morphTargets[ m ].name ] = m;
  13459. }
  13460. }
  13461. };
  13462. THREE.Mesh.prototype.getMorphTargetIndexByName = function ( name ) {
  13463. if ( this.morphTargetDictionary[ name ] !== undefined ) {
  13464. return this.morphTargetDictionary[ name ];
  13465. }
  13466. console.warn( 'THREE.Mesh.getMorphTargetIndexByName: morph target ' + name + ' does not exist. Returning 0.' );
  13467. return 0;
  13468. };
  13469. THREE.Mesh.prototype.raycast = ( function () {
  13470. var inverseMatrix = new THREE.Matrix4();
  13471. var ray = new THREE.Ray();
  13472. var sphere = new THREE.Sphere();
  13473. var vA = new THREE.Vector3();
  13474. var vB = new THREE.Vector3();
  13475. var vC = new THREE.Vector3();
  13476. var tempA = new THREE.Vector3();
  13477. var tempB = new THREE.Vector3();
  13478. var tempC = new THREE.Vector3();
  13479. var uvA = new THREE.Vector2();
  13480. var uvB = new THREE.Vector2();
  13481. var uvC = new THREE.Vector2();
  13482. var barycoord = new THREE.Vector3();
  13483. var intersectionPoint = new THREE.Vector3();
  13484. var intersectionPointWorld = new THREE.Vector3();
  13485. function uvIntersection( point, p1, p2, p3, uv1, uv2, uv3 ) {
  13486. THREE.Triangle.barycoordFromPoint( point, p1, p2, p3, barycoord );
  13487. uv1.multiplyScalar( barycoord.x );
  13488. uv2.multiplyScalar( barycoord.y );
  13489. uv3.multiplyScalar( barycoord.z );
  13490. uv1.add( uv2 ).add( uv3 );
  13491. return uv1.clone();
  13492. }
  13493. function checkIntersection( object, raycaster, ray, pA, pB, pC, point ) {
  13494. var intersect;
  13495. var material = object.material;
  13496. if ( material.side === THREE.BackSide ) {
  13497. intersect = ray.intersectTriangle( pC, pB, pA, true, point );
  13498. } else {
  13499. intersect = ray.intersectTriangle( pA, pB, pC, material.side !== THREE.DoubleSide, point );
  13500. }
  13501. if ( intersect === null ) return null;
  13502. intersectionPointWorld.copy( point );
  13503. intersectionPointWorld.applyMatrix4( object.matrixWorld );
  13504. var distance = raycaster.ray.origin.distanceTo( intersectionPointWorld );
  13505. if ( distance < raycaster.near || distance > raycaster.far ) return null;
  13506. return {
  13507. distance: distance,
  13508. point: intersectionPointWorld.clone(),
  13509. object: object
  13510. };
  13511. }
  13512. function checkBufferGeometryIntersection( object, raycaster, ray, positions, uvs, a, b, c ) {
  13513. vA.fromArray( positions, a * 3 );
  13514. vB.fromArray( positions, b * 3 );
  13515. vC.fromArray( positions, c * 3 );
  13516. var intersection = checkIntersection( object, raycaster, ray, vA, vB, vC, intersectionPoint );
  13517. if ( intersection ) {
  13518. if ( uvs ) {
  13519. uvA.fromArray( uvs, a * 2 );
  13520. uvB.fromArray( uvs, b * 2 );
  13521. uvC.fromArray( uvs, c * 2 );
  13522. intersection.uv = uvIntersection( intersectionPoint, vA, vB, vC, uvA, uvB, uvC );
  13523. }
  13524. intersection.face = new THREE.Face3( a, b, c, THREE.Triangle.normal( vA, vB, vC ) );
  13525. intersection.faceIndex = a;
  13526. }
  13527. return intersection;
  13528. }
  13529. return function raycast( raycaster, intersects ) {
  13530. var geometry = this.geometry;
  13531. var material = this.material;
  13532. var matrixWorld = this.matrixWorld;
  13533. if ( material === undefined ) return;
  13534. // Checking boundingSphere distance to ray
  13535. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  13536. sphere.copy( geometry.boundingSphere );
  13537. sphere.applyMatrix4( matrixWorld );
  13538. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  13539. //
  13540. inverseMatrix.getInverse( matrixWorld );
  13541. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  13542. // Check boundingBox before continuing
  13543. if ( geometry.boundingBox !== null ) {
  13544. if ( ray.intersectsBox( geometry.boundingBox ) === false ) return;
  13545. }
  13546. var uvs, intersection;
  13547. if ( geometry instanceof THREE.BufferGeometry ) {
  13548. var a, b, c;
  13549. var index = geometry.index;
  13550. var attributes = geometry.attributes;
  13551. var positions = attributes.position.array;
  13552. if ( attributes.uv !== undefined ) {
  13553. uvs = attributes.uv.array;
  13554. }
  13555. if ( index !== null ) {
  13556. var indices = index.array;
  13557. for ( var i = 0, l = indices.length; i < l; i += 3 ) {
  13558. a = indices[ i ];
  13559. b = indices[ i + 1 ];
  13560. c = indices[ i + 2 ];
  13561. intersection = checkBufferGeometryIntersection( this, raycaster, ray, positions, uvs, a, b, c );
  13562. if ( intersection ) {
  13563. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in indices buffer semantics
  13564. intersects.push( intersection );
  13565. }
  13566. }
  13567. } else {
  13568. for ( var i = 0, l = positions.length; i < l; i += 9 ) {
  13569. a = i / 3;
  13570. b = a + 1;
  13571. c = a + 2;
  13572. intersection = checkBufferGeometryIntersection( this, raycaster, ray, positions, uvs, a, b, c );
  13573. if ( intersection ) {
  13574. intersection.index = a; // triangle number in positions buffer semantics
  13575. intersects.push( intersection );
  13576. }
  13577. }
  13578. }
  13579. } else if ( geometry instanceof THREE.Geometry ) {
  13580. var fvA, fvB, fvC;
  13581. var isFaceMaterial = material instanceof THREE.MultiMaterial;
  13582. var materials = isFaceMaterial === true ? material.materials : null;
  13583. var vertices = geometry.vertices;
  13584. var faces = geometry.faces;
  13585. var faceVertexUvs = geometry.faceVertexUvs[ 0 ];
  13586. if ( faceVertexUvs.length > 0 ) uvs = faceVertexUvs;
  13587. for ( var f = 0, fl = faces.length; f < fl; f ++ ) {
  13588. var face = faces[ f ];
  13589. var faceMaterial = isFaceMaterial === true ? materials[ face.materialIndex ] : material;
  13590. if ( faceMaterial === undefined ) continue;
  13591. fvA = vertices[ face.a ];
  13592. fvB = vertices[ face.b ];
  13593. fvC = vertices[ face.c ];
  13594. if ( faceMaterial.morphTargets === true ) {
  13595. var morphTargets = geometry.morphTargets;
  13596. var morphInfluences = this.morphTargetInfluences;
  13597. vA.set( 0, 0, 0 );
  13598. vB.set( 0, 0, 0 );
  13599. vC.set( 0, 0, 0 );
  13600. for ( var t = 0, tl = morphTargets.length; t < tl; t ++ ) {
  13601. var influence = morphInfluences[ t ];
  13602. if ( influence === 0 ) continue;
  13603. var targets = morphTargets[ t ].vertices;
  13604. vA.addScaledVector( tempA.subVectors( targets[ face.a ], fvA ), influence );
  13605. vB.addScaledVector( tempB.subVectors( targets[ face.b ], fvB ), influence );
  13606. vC.addScaledVector( tempC.subVectors( targets[ face.c ], fvC ), influence );
  13607. }
  13608. vA.add( fvA );
  13609. vB.add( fvB );
  13610. vC.add( fvC );
  13611. fvA = vA;
  13612. fvB = vB;
  13613. fvC = vC;
  13614. }
  13615. intersection = checkIntersection( this, raycaster, ray, fvA, fvB, fvC, intersectionPoint );
  13616. if ( intersection ) {
  13617. if ( uvs ) {
  13618. var uvs_f = uvs[ f ];
  13619. uvA.copy( uvs_f[ 0 ] );
  13620. uvB.copy( uvs_f[ 1 ] );
  13621. uvC.copy( uvs_f[ 2 ] );
  13622. intersection.uv = uvIntersection( intersectionPoint, fvA, fvB, fvC, uvA, uvB, uvC );
  13623. }
  13624. intersection.face = face;
  13625. intersection.faceIndex = f;
  13626. intersects.push( intersection );
  13627. }
  13628. }
  13629. }
  13630. };
  13631. }() );
  13632. THREE.Mesh.prototype.clone = function () {
  13633. return new this.constructor( this.geometry, this.material ).copy( this );
  13634. };
  13635. // File:src/objects/Bone.js
  13636. /**
  13637. * @author mikael emtinger / http://gomo.se/
  13638. * @author alteredq / http://alteredqualia.com/
  13639. * @author ikerr / http://verold.com
  13640. */
  13641. THREE.Bone = function ( skin ) {
  13642. THREE.Object3D.call( this );
  13643. this.type = 'Bone';
  13644. this.skin = skin;
  13645. };
  13646. THREE.Bone.prototype = Object.create( THREE.Object3D.prototype );
  13647. THREE.Bone.prototype.constructor = THREE.Bone;
  13648. THREE.Bone.prototype.copy = function ( source ) {
  13649. THREE.Object3D.prototype.copy.call( this, source );
  13650. this.skin = source.skin;
  13651. return this;
  13652. };
  13653. // File:src/objects/Skeleton.js
  13654. /**
  13655. * @author mikael emtinger / http://gomo.se/
  13656. * @author alteredq / http://alteredqualia.com/
  13657. * @author michael guerrero / http://realitymeltdown.com
  13658. * @author ikerr / http://verold.com
  13659. */
  13660. THREE.Skeleton = function ( bones, boneInverses, useVertexTexture ) {
  13661. this.useVertexTexture = useVertexTexture !== undefined ? useVertexTexture : true;
  13662. this.identityMatrix = new THREE.Matrix4();
  13663. // copy the bone array
  13664. bones = bones || [];
  13665. this.bones = bones.slice( 0 );
  13666. // create a bone texture or an array of floats
  13667. if ( this.useVertexTexture ) {
  13668. // layout (1 matrix = 4 pixels)
  13669. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  13670. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  13671. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  13672. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  13673. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  13674. var size = Math.sqrt( this.bones.length * 4 ); // 4 pixels needed for 1 matrix
  13675. size = THREE.Math.nextPowerOfTwo( Math.ceil( size ) );
  13676. size = Math.max( size, 4 );
  13677. this.boneTextureWidth = size;
  13678. this.boneTextureHeight = size;
  13679. this.boneMatrices = new Float32Array( this.boneTextureWidth * this.boneTextureHeight * 4 ); // 4 floats per RGBA pixel
  13680. this.boneTexture = new THREE.DataTexture( this.boneMatrices, this.boneTextureWidth, this.boneTextureHeight, THREE.RGBAFormat, THREE.FloatType );
  13681. } else {
  13682. this.boneMatrices = new Float32Array( 16 * this.bones.length );
  13683. }
  13684. // use the supplied bone inverses or calculate the inverses
  13685. if ( boneInverses === undefined ) {
  13686. this.calculateInverses();
  13687. } else {
  13688. if ( this.bones.length === boneInverses.length ) {
  13689. this.boneInverses = boneInverses.slice( 0 );
  13690. } else {
  13691. console.warn( 'THREE.Skeleton bonInverses is the wrong length.' );
  13692. this.boneInverses = [];
  13693. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13694. this.boneInverses.push( new THREE.Matrix4() );
  13695. }
  13696. }
  13697. }
  13698. };
  13699. THREE.Skeleton.prototype.calculateInverses = function () {
  13700. this.boneInverses = [];
  13701. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13702. var inverse = new THREE.Matrix4();
  13703. if ( this.bones[ b ] ) {
  13704. inverse.getInverse( this.bones[ b ].matrixWorld );
  13705. }
  13706. this.boneInverses.push( inverse );
  13707. }
  13708. };
  13709. THREE.Skeleton.prototype.pose = function () {
  13710. var bone;
  13711. // recover the bind-time world matrices
  13712. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13713. bone = this.bones[ b ];
  13714. if ( bone ) {
  13715. bone.matrixWorld.getInverse( this.boneInverses[ b ] );
  13716. }
  13717. }
  13718. // compute the local matrices, positions, rotations and scales
  13719. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13720. bone = this.bones[ b ];
  13721. if ( bone ) {
  13722. if ( bone.parent ) {
  13723. bone.matrix.getInverse( bone.parent.matrixWorld );
  13724. bone.matrix.multiply( bone.matrixWorld );
  13725. } else {
  13726. bone.matrix.copy( bone.matrixWorld );
  13727. }
  13728. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  13729. }
  13730. }
  13731. };
  13732. THREE.Skeleton.prototype.update = ( function () {
  13733. var offsetMatrix = new THREE.Matrix4();
  13734. return function update() {
  13735. // flatten bone matrices to array
  13736. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13737. // compute the offset between the current and the original transform
  13738. var matrix = this.bones[ b ] ? this.bones[ b ].matrixWorld : this.identityMatrix;
  13739. offsetMatrix.multiplyMatrices( matrix, this.boneInverses[ b ] );
  13740. offsetMatrix.toArray( this.boneMatrices, b * 16 );
  13741. }
  13742. if ( this.useVertexTexture ) {
  13743. this.boneTexture.needsUpdate = true;
  13744. }
  13745. };
  13746. } )();
  13747. THREE.Skeleton.prototype.clone = function () {
  13748. return new THREE.Skeleton( this.bones, this.boneInverses, this.useVertexTexture );
  13749. };
  13750. // File:src/objects/SkinnedMesh.js
  13751. /**
  13752. * @author mikael emtinger / http://gomo.se/
  13753. * @author alteredq / http://alteredqualia.com/
  13754. * @author ikerr / http://verold.com
  13755. */
  13756. THREE.SkinnedMesh = function ( geometry, material, useVertexTexture ) {
  13757. THREE.Mesh.call( this, geometry, material );
  13758. this.type = 'SkinnedMesh';
  13759. this.bindMode = "attached";
  13760. this.bindMatrix = new THREE.Matrix4();
  13761. this.bindMatrixInverse = new THREE.Matrix4();
  13762. // init bones
  13763. // TODO: remove bone creation as there is no reason (other than
  13764. // convenience) for THREE.SkinnedMesh to do this.
  13765. var bones = [];
  13766. if ( this.geometry && this.geometry.bones !== undefined ) {
  13767. var bone, gbone;
  13768. for ( var b = 0, bl = this.geometry.bones.length; b < bl; ++ b ) {
  13769. gbone = this.geometry.bones[ b ];
  13770. bone = new THREE.Bone( this );
  13771. bones.push( bone );
  13772. bone.name = gbone.name;
  13773. bone.position.fromArray( gbone.pos );
  13774. bone.quaternion.fromArray( gbone.rotq );
  13775. if ( gbone.scl !== undefined ) bone.scale.fromArray( gbone.scl );
  13776. }
  13777. for ( var b = 0, bl = this.geometry.bones.length; b < bl; ++ b ) {
  13778. gbone = this.geometry.bones[ b ];
  13779. if ( gbone.parent !== - 1 && gbone.parent !== null &&
  13780. bones[ gbone.parent ] !== undefined ) {
  13781. bones[ gbone.parent ].add( bones[ b ] );
  13782. } else {
  13783. this.add( bones[ b ] );
  13784. }
  13785. }
  13786. }
  13787. this.normalizeSkinWeights();
  13788. this.updateMatrixWorld( true );
  13789. this.bind( new THREE.Skeleton( bones, undefined, useVertexTexture ), this.matrixWorld );
  13790. };
  13791. THREE.SkinnedMesh.prototype = Object.create( THREE.Mesh.prototype );
  13792. THREE.SkinnedMesh.prototype.constructor = THREE.SkinnedMesh;
  13793. THREE.SkinnedMesh.prototype.bind = function( skeleton, bindMatrix ) {
  13794. this.skeleton = skeleton;
  13795. if ( bindMatrix === undefined ) {
  13796. this.updateMatrixWorld( true );
  13797. this.skeleton.calculateInverses();
  13798. bindMatrix = this.matrixWorld;
  13799. }
  13800. this.bindMatrix.copy( bindMatrix );
  13801. this.bindMatrixInverse.getInverse( bindMatrix );
  13802. };
  13803. THREE.SkinnedMesh.prototype.pose = function () {
  13804. this.skeleton.pose();
  13805. };
  13806. THREE.SkinnedMesh.prototype.normalizeSkinWeights = function () {
  13807. if ( this.geometry instanceof THREE.Geometry ) {
  13808. for ( var i = 0; i < this.geometry.skinWeights.length; i ++ ) {
  13809. var sw = this.geometry.skinWeights[ i ];
  13810. var scale = 1.0 / sw.lengthManhattan();
  13811. if ( scale !== Infinity ) {
  13812. sw.multiplyScalar( scale );
  13813. } else {
  13814. sw.set( 1, 0, 0, 0 ); // do something reasonable
  13815. }
  13816. }
  13817. } else if ( this.geometry instanceof THREE.BufferGeometry ) {
  13818. var vec = new THREE.Vector4();
  13819. var skinWeight = this.geometry.attributes.skinWeight;
  13820. for ( var i = 0; i < skinWeight.count; i ++ ) {
  13821. vec.x = skinWeight.getX( i );
  13822. vec.y = skinWeight.getY( i );
  13823. vec.z = skinWeight.getZ( i );
  13824. vec.w = skinWeight.getW( i );
  13825. var scale = 1.0 / vec.lengthManhattan();
  13826. if ( scale !== Infinity ) {
  13827. vec.multiplyScalar( scale );
  13828. } else {
  13829. vec.set( 1, 0, 0, 0 ); // do something reasonable
  13830. }
  13831. skinWeight.setXYZW( i, vec.x, vec.y, vec.z, vec.w );
  13832. }
  13833. }
  13834. };
  13835. THREE.SkinnedMesh.prototype.updateMatrixWorld = function( force ) {
  13836. THREE.Mesh.prototype.updateMatrixWorld.call( this, true );
  13837. if ( this.bindMode === "attached" ) {
  13838. this.bindMatrixInverse.getInverse( this.matrixWorld );
  13839. } else if ( this.bindMode === "detached" ) {
  13840. this.bindMatrixInverse.getInverse( this.bindMatrix );
  13841. } else {
  13842. console.warn( 'THREE.SkinnedMesh unrecognized bindMode: ' + this.bindMode );
  13843. }
  13844. };
  13845. THREE.SkinnedMesh.prototype.clone = function() {
  13846. return new this.constructor( this.geometry, this.material, this.useVertexTexture ).copy( this );
  13847. };
  13848. // File:src/objects/LOD.js
  13849. /**
  13850. * @author mikael emtinger / http://gomo.se/
  13851. * @author alteredq / http://alteredqualia.com/
  13852. * @author mrdoob / http://mrdoob.com/
  13853. */
  13854. THREE.LOD = function () {
  13855. THREE.Object3D.call( this );
  13856. this.type = 'LOD';
  13857. Object.defineProperties( this, {
  13858. levels: {
  13859. enumerable: true,
  13860. value: []
  13861. }
  13862. } );
  13863. };
  13864. THREE.LOD.prototype = Object.create( THREE.Object3D.prototype );
  13865. THREE.LOD.prototype.constructor = THREE.LOD;
  13866. THREE.LOD.prototype.addLevel = function ( object, distance ) {
  13867. if ( distance === undefined ) distance = 0;
  13868. distance = Math.abs( distance );
  13869. var levels = this.levels;
  13870. for ( var l = 0; l < levels.length; l ++ ) {
  13871. if ( distance < levels[ l ].distance ) {
  13872. break;
  13873. }
  13874. }
  13875. levels.splice( l, 0, { distance: distance, object: object } );
  13876. this.add( object );
  13877. };
  13878. THREE.LOD.prototype.getObjectForDistance = function ( distance ) {
  13879. var levels = this.levels;
  13880. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  13881. if ( distance < levels[ i ].distance ) {
  13882. break;
  13883. }
  13884. }
  13885. return levels[ i - 1 ].object;
  13886. };
  13887. THREE.LOD.prototype.raycast = ( function () {
  13888. var matrixPosition = new THREE.Vector3();
  13889. return function raycast( raycaster, intersects ) {
  13890. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  13891. var distance = raycaster.ray.origin.distanceTo( matrixPosition );
  13892. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  13893. };
  13894. }() );
  13895. THREE.LOD.prototype.update = function () {
  13896. var v1 = new THREE.Vector3();
  13897. var v2 = new THREE.Vector3();
  13898. return function update( camera ) {
  13899. var levels = this.levels;
  13900. if ( levels.length > 1 ) {
  13901. v1.setFromMatrixPosition( camera.matrixWorld );
  13902. v2.setFromMatrixPosition( this.matrixWorld );
  13903. var distance = v1.distanceTo( v2 );
  13904. levels[ 0 ].object.visible = true;
  13905. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  13906. if ( distance >= levels[ i ].distance ) {
  13907. levels[ i - 1 ].object.visible = false;
  13908. levels[ i ].object.visible = true;
  13909. } else {
  13910. break;
  13911. }
  13912. }
  13913. for ( ; i < l; i ++ ) {
  13914. levels[ i ].object.visible = false;
  13915. }
  13916. }
  13917. };
  13918. }();
  13919. THREE.LOD.prototype.copy = function ( source ) {
  13920. THREE.Object3D.prototype.copy.call( this, source, false );
  13921. var levels = source.levels;
  13922. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  13923. var level = levels[ i ];
  13924. this.addLevel( level.object.clone(), level.distance );
  13925. }
  13926. return this;
  13927. };
  13928. THREE.LOD.prototype.toJSON = function ( meta ) {
  13929. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  13930. data.object.levels = [];
  13931. var levels = this.levels;
  13932. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  13933. var level = levels[ i ];
  13934. data.object.levels.push( {
  13935. object: level.object.uuid,
  13936. distance: level.distance
  13937. } );
  13938. }
  13939. return data;
  13940. };
  13941. // File:src/objects/Sprite.js
  13942. /**
  13943. * @author mikael emtinger / http://gomo.se/
  13944. * @author alteredq / http://alteredqualia.com/
  13945. */
  13946. THREE.Sprite = ( function () {
  13947. var indices = new Uint16Array( [ 0, 1, 2, 0, 2, 3 ] );
  13948. var vertices = new Float32Array( [ - 0.5, - 0.5, 0, 0.5, - 0.5, 0, 0.5, 0.5, 0, - 0.5, 0.5, 0 ] );
  13949. var uvs = new Float32Array( [ 0, 0, 1, 0, 1, 1, 0, 1 ] );
  13950. var geometry = new THREE.BufferGeometry();
  13951. geometry.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  13952. geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  13953. geometry.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  13954. return function Sprite( material ) {
  13955. THREE.Object3D.call( this );
  13956. this.type = 'Sprite';
  13957. this.geometry = geometry;
  13958. this.material = ( material !== undefined ) ? material : new THREE.SpriteMaterial();
  13959. };
  13960. } )();
  13961. THREE.Sprite.prototype = Object.create( THREE.Object3D.prototype );
  13962. THREE.Sprite.prototype.constructor = THREE.Sprite;
  13963. THREE.Sprite.prototype.raycast = ( function () {
  13964. var matrixPosition = new THREE.Vector3();
  13965. return function raycast( raycaster, intersects ) {
  13966. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  13967. var distanceSq = raycaster.ray.distanceSqToPoint( matrixPosition );
  13968. var guessSizeSq = this.scale.x * this.scale.y / 4;
  13969. if ( distanceSq > guessSizeSq ) {
  13970. return;
  13971. }
  13972. intersects.push( {
  13973. distance: Math.sqrt( distanceSq ),
  13974. point: this.position,
  13975. face: null,
  13976. object: this
  13977. } );
  13978. };
  13979. }() );
  13980. THREE.Sprite.prototype.clone = function () {
  13981. return new this.constructor( this.material ).copy( this );
  13982. };
  13983. // File:src/objects/LensFlare.js
  13984. /**
  13985. * @author mikael emtinger / http://gomo.se/
  13986. * @author alteredq / http://alteredqualia.com/
  13987. */
  13988. THREE.LensFlare = function ( texture, size, distance, blending, color ) {
  13989. THREE.Object3D.call( this );
  13990. this.lensFlares = [];
  13991. this.positionScreen = new THREE.Vector3();
  13992. this.customUpdateCallback = undefined;
  13993. if ( texture !== undefined ) {
  13994. this.add( texture, size, distance, blending, color );
  13995. }
  13996. };
  13997. THREE.LensFlare.prototype = Object.create( THREE.Object3D.prototype );
  13998. THREE.LensFlare.prototype.constructor = THREE.LensFlare;
  13999. /*
  14000. * Add: adds another flare
  14001. */
  14002. THREE.LensFlare.prototype.add = function ( texture, size, distance, blending, color, opacity ) {
  14003. if ( size === undefined ) size = - 1;
  14004. if ( distance === undefined ) distance = 0;
  14005. if ( opacity === undefined ) opacity = 1;
  14006. if ( color === undefined ) color = new THREE.Color( 0xffffff );
  14007. if ( blending === undefined ) blending = THREE.NormalBlending;
  14008. distance = Math.min( distance, Math.max( 0, distance ) );
  14009. this.lensFlares.push( {
  14010. texture: texture, // THREE.Texture
  14011. size: size, // size in pixels (-1 = use texture.width)
  14012. distance: distance, // distance (0-1) from light source (0=at light source)
  14013. x: 0, y: 0, z: 0, // screen position (-1 => 1) z = 0 is in front z = 1 is back
  14014. scale: 1, // scale
  14015. rotation: 0, // rotation
  14016. opacity: opacity, // opacity
  14017. color: color, // color
  14018. blending: blending // blending
  14019. } );
  14020. };
  14021. /*
  14022. * Update lens flares update positions on all flares based on the screen position
  14023. * Set myLensFlare.customUpdateCallback to alter the flares in your project specific way.
  14024. */
  14025. THREE.LensFlare.prototype.updateLensFlares = function () {
  14026. var f, fl = this.lensFlares.length;
  14027. var flare;
  14028. var vecX = - this.positionScreen.x * 2;
  14029. var vecY = - this.positionScreen.y * 2;
  14030. for ( f = 0; f < fl; f ++ ) {
  14031. flare = this.lensFlares[ f ];
  14032. flare.x = this.positionScreen.x + vecX * flare.distance;
  14033. flare.y = this.positionScreen.y + vecY * flare.distance;
  14034. flare.wantedRotation = flare.x * Math.PI * 0.25;
  14035. flare.rotation += ( flare.wantedRotation - flare.rotation ) * 0.25;
  14036. }
  14037. };
  14038. THREE.LensFlare.prototype.copy = function ( source ) {
  14039. THREE.Object3D.prototype.copy.call( this, source );
  14040. this.positionScreen.copy( source.positionScreen );
  14041. this.customUpdateCallback = source.customUpdateCallback;
  14042. for ( var i = 0, l = source.lensFlares.length; i < l; i ++ ) {
  14043. this.lensFlares.push( source.lensFlares[ i ] );
  14044. }
  14045. return this;
  14046. };
  14047. // File:src/scenes/Scene.js
  14048. /**
  14049. * @author mrdoob / http://mrdoob.com/
  14050. */
  14051. THREE.Scene = function () {
  14052. THREE.Object3D.call( this );
  14053. this.type = 'Scene';
  14054. this.fog = null;
  14055. this.overrideMaterial = null;
  14056. this.autoUpdate = true; // checked by the renderer
  14057. };
  14058. THREE.Scene.prototype = Object.create( THREE.Object3D.prototype );
  14059. THREE.Scene.prototype.constructor = THREE.Scene;
  14060. THREE.Scene.prototype.copy = function ( source, recursive ) {
  14061. THREE.Object3D.prototype.copy.call( this, source, recursive );
  14062. if ( source.fog !== null ) this.fog = source.fog.clone();
  14063. if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
  14064. this.autoUpdate = source.autoUpdate;
  14065. this.matrixAutoUpdate = source.matrixAutoUpdate;
  14066. return this;
  14067. };
  14068. // File:src/scenes/Fog.js
  14069. /**
  14070. * @author mrdoob / http://mrdoob.com/
  14071. * @author alteredq / http://alteredqualia.com/
  14072. */
  14073. THREE.Fog = function ( color, near, far ) {
  14074. this.name = '';
  14075. this.color = new THREE.Color( color );
  14076. this.near = ( near !== undefined ) ? near : 1;
  14077. this.far = ( far !== undefined ) ? far : 1000;
  14078. };
  14079. THREE.Fog.prototype.clone = function () {
  14080. return new THREE.Fog( this.color.getHex(), this.near, this.far );
  14081. };
  14082. // File:src/scenes/FogExp2.js
  14083. /**
  14084. * @author mrdoob / http://mrdoob.com/
  14085. * @author alteredq / http://alteredqualia.com/
  14086. */
  14087. THREE.FogExp2 = function ( color, density ) {
  14088. this.name = '';
  14089. this.color = new THREE.Color( color );
  14090. this.density = ( density !== undefined ) ? density : 0.00025;
  14091. };
  14092. THREE.FogExp2.prototype.clone = function () {
  14093. return new THREE.FogExp2( this.color.getHex(), this.density );
  14094. };
  14095. // File:src/renderers/shaders/ShaderChunk.js
  14096. THREE.ShaderChunk = {};
  14097. // File:src/renderers/shaders/ShaderChunk/alphamap_fragment.glsl
  14098. THREE.ShaderChunk[ 'alphamap_fragment' ] = "#ifdef USE_ALPHAMAP\n diffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif\n";
  14099. // File:src/renderers/shaders/ShaderChunk/alphamap_pars_fragment.glsl
  14100. THREE.ShaderChunk[ 'alphamap_pars_fragment' ] = "#ifdef USE_ALPHAMAP\n uniform sampler2D alphaMap;\n#endif\n";
  14101. // File:src/renderers/shaders/ShaderChunk/alphatest_fragment.glsl
  14102. THREE.ShaderChunk[ 'alphatest_fragment' ] = "#ifdef ALPHATEST\n if ( diffuseColor.a < ALPHATEST ) discard;\n#endif\n";
  14103. // File:src/renderers/shaders/ShaderChunk/aomap_fragment.glsl
  14104. THREE.ShaderChunk[ 'aomap_fragment' ] = "#ifdef USE_AOMAP\n float ambientOcclusion = ( texture2D( aoMap, vUv2 ).r - 1.0 ) * aoMapIntensity + 1.0;\n reflectedLight.indirectDiffuse *= ambientOcclusion;\n #if defined( USE_ENVMAP ) && defined( PHYSICAL )\n float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n reflectedLight.indirectSpecular *= computeSpecularOcclusion( dotNV, ambientOcclusion, material.specularRoughness );\n #endif\n#endif\n";
  14105. // File:src/renderers/shaders/ShaderChunk/aomap_pars_fragment.glsl
  14106. THREE.ShaderChunk[ 'aomap_pars_fragment' ] = "#ifdef USE_AOMAP\n uniform sampler2D aoMap;\n uniform float aoMapIntensity;\n#endif";
  14107. // File:src/renderers/shaders/ShaderChunk/begin_vertex.glsl
  14108. THREE.ShaderChunk[ 'begin_vertex' ] = "\nvec3 transformed = vec3( position );\n";
  14109. // File:src/renderers/shaders/ShaderChunk/beginnormal_vertex.glsl
  14110. THREE.ShaderChunk[ 'beginnormal_vertex' ] = "\nvec3 objectNormal = vec3( normal );\n";
  14111. // File:src/renderers/shaders/ShaderChunk/bsdfs.glsl
  14112. 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";
  14113. // File:src/renderers/shaders/ShaderChunk/bumpmap_pars_fragment.glsl
  14114. 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";
  14115. // File:src/renderers/shaders/ShaderChunk/clipping_planes_fragment.glsl
  14116. THREE.ShaderChunk[ 'clipping_planes_fragment' ] = "#if NUM_CLIPPING_PLANES > 0\n for ( int i = 0; i < NUM_CLIPPING_PLANES; ++ i ) {\n vec4 plane = clippingPlanes[ i ];\n if ( dot( vViewPosition, plane.xyz ) > plane.w ) discard;\n }\n#endif\n";
  14117. // File:src/renderers/shaders/ShaderChunk/clipping_planes_pars_fragment.glsl
  14118. THREE.ShaderChunk[ 'clipping_planes_pars_fragment' ] = "#if NUM_CLIPPING_PLANES > 0\n #if ! defined( PHYSICAL ) && ! defined( PHONG )\n varying vec3 vViewPosition;\n #endif\n uniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\n#endif\n";
  14119. // File:src/renderers/shaders/ShaderChunk/clipping_planes_pars_vertex.glsl
  14120. THREE.ShaderChunk[ 'clipping_planes_pars_vertex' ] = "#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG )\n varying vec3 vViewPosition;\n#endif\n";
  14121. // File:src/renderers/shaders/ShaderChunk/clipping_planes_vertex.glsl
  14122. THREE.ShaderChunk[ 'clipping_planes_vertex' ] = "#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG )\n vViewPosition = - mvPosition.xyz;\n#endif\n";
  14123. // File:src/renderers/shaders/ShaderChunk/color_fragment.glsl
  14124. THREE.ShaderChunk[ 'color_fragment' ] = "#ifdef USE_COLOR\n diffuseColor.rgb *= vColor;\n#endif";
  14125. // File:src/renderers/shaders/ShaderChunk/color_pars_fragment.glsl
  14126. THREE.ShaderChunk[ 'color_pars_fragment' ] = "#ifdef USE_COLOR\n varying vec3 vColor;\n#endif\n";
  14127. // File:src/renderers/shaders/ShaderChunk/color_pars_vertex.glsl
  14128. THREE.ShaderChunk[ 'color_pars_vertex' ] = "#ifdef USE_COLOR\n varying vec3 vColor;\n#endif";
  14129. // File:src/renderers/shaders/ShaderChunk/color_vertex.glsl
  14130. THREE.ShaderChunk[ 'color_vertex' ] = "#ifdef USE_COLOR\n vColor.xyz = color.xyz;\n#endif";
  14131. // File:src/renderers/shaders/ShaderChunk/common.glsl
  14132. THREE.ShaderChunk[ 'common' ] = "#define PI 3.14159265359\n#define PI2 6.28318530718\n#define RECIPROCAL_PI 0.31830988618\n#define RECIPROCAL_PI2 0.15915494\n#define LOG2 1.442695\n#define EPSILON 1e-6\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#define whiteCompliment(a) ( 1.0 - saturate( a ) )\nfloat pow2( const in float x ) { return x*x; }\nfloat pow3( const in float x ) { return x*x*x; }\nfloat pow4( const in float x ) { float x2 = x*x; return x2*x2; }\nfloat average( const in vec3 color ) { return dot( color, vec3( 0.3333 ) ); }\nhighp float rand( const in vec2 uv ) {\n const highp float a = 12.9898, b = 78.233, c = 43758.5453;\n highp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );\n return fract(sin(sn) * c);\n}\nstruct IncidentLight {\n vec3 color;\n vec3 direction;\n bool visible;\n};\nstruct ReflectedLight {\n vec3 directDiffuse;\n vec3 directSpecular;\n vec3 indirectDiffuse;\n vec3 indirectSpecular;\n};\nstruct GeometricContext {\n vec3 position;\n vec3 normal;\n vec3 viewDir;\n};\nvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n}\nvec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {\n return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );\n}\nvec3 projectOnPlane(in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n float distance = dot( planeNormal, point - pointOnPlane );\n return - distance * planeNormal + point;\n}\nfloat sideOfPlane( in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n return sign( dot( point - pointOnPlane, planeNormal ) );\n}\nvec3 linePlaneIntersect( in vec3 pointOnLine, in vec3 lineDirection, in vec3 pointOnPlane, in vec3 planeNormal ) {\n return lineDirection * ( dot( planeNormal, pointOnPlane - pointOnLine ) / dot( planeNormal, lineDirection ) ) + pointOnLine;\n}\n";
  14133. // File:src/renderers/shaders/ShaderChunk/cube_uv_reflection_fragment.glsl
  14134. 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";
  14135. // File:src/renderers/shaders/ShaderChunk/defaultnormal_vertex.glsl
  14136. THREE.ShaderChunk[ 'defaultnormal_vertex' ] = "#ifdef FLIP_SIDED\n objectNormal = -objectNormal;\n#endif\nvec3 transformedNormal = normalMatrix * objectNormal;\n";
  14137. // File:src/renderers/shaders/ShaderChunk/displacementmap_vertex.glsl
  14138. THREE.ShaderChunk[ 'displacementmap_vertex' ] = "#ifdef USE_DISPLACEMENTMAP\n transformed += normal * ( texture2D( displacementMap, uv ).x * displacementScale + displacementBias );\n#endif\n";
  14139. // File:src/renderers/shaders/ShaderChunk/displacementmap_pars_vertex.glsl
  14140. THREE.ShaderChunk[ 'displacementmap_pars_vertex' ] = "#ifdef USE_DISPLACEMENTMAP\n uniform sampler2D displacementMap;\n uniform float displacementScale;\n uniform float displacementBias;\n#endif\n";
  14141. // File:src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl
  14142. 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";
  14143. // File:src/renderers/shaders/ShaderChunk/emissivemap_pars_fragment.glsl
  14144. THREE.ShaderChunk[ 'emissivemap_pars_fragment' ] = "#ifdef USE_EMISSIVEMAP\n uniform sampler2D emissiveMap;\n#endif\n";
  14145. // File:src/renderers/shaders/ShaderChunk/encodings_pars_fragment.glsl
  14146. 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";
  14147. // File:src/renderers/shaders/ShaderChunk/encodings_fragment.glsl
  14148. THREE.ShaderChunk[ 'encodings_fragment' ] = " gl_FragColor = linearToOutputTexel( gl_FragColor );\n";
  14149. // File:src/renderers/shaders/ShaderChunk/envmap_fragment.glsl
  14150. 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";
  14151. // File:src/renderers/shaders/ShaderChunk/envmap_pars_fragment.glsl
  14152. THREE.ShaderChunk[ 'envmap_pars_fragment' ] = "#if defined( USE_ENVMAP ) || defined( PHYSICAL )\n uniform float reflectivity;\n uniform float envMapIntenstiy;\n#endif\n#ifdef USE_ENVMAP\n #if ! defined( PHYSICAL ) && ( defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) )\n varying vec3 vWorldPosition;\n #endif\n #ifdef ENVMAP_TYPE_CUBE\n uniform samplerCube envMap;\n #else\n uniform sampler2D envMap;\n #endif\n uniform float flipEnvMap;\n #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( PHYSICAL )\n uniform float refractionRatio;\n #else\n varying vec3 vReflect;\n #endif\n#endif\n";
  14153. // File:src/renderers/shaders/ShaderChunk/envmap_pars_vertex.glsl
  14154. 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";
  14155. // File:src/renderers/shaders/ShaderChunk/envmap_vertex.glsl
  14156. 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";
  14157. // File:src/renderers/shaders/ShaderChunk/fog_fragment.glsl
  14158. 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";
  14159. // File:src/renderers/shaders/ShaderChunk/fog_pars_fragment.glsl
  14160. 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";
  14161. // File:src/renderers/shaders/ShaderChunk/lightmap_fragment.glsl
  14162. THREE.ShaderChunk[ 'lightmap_fragment' ] = "#ifdef USE_LIGHTMAP\n reflectedLight.indirectDiffuse += PI * texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n#endif\n";
  14163. // File:src/renderers/shaders/ShaderChunk/lightmap_pars_fragment.glsl
  14164. THREE.ShaderChunk[ 'lightmap_pars_fragment' ] = "#ifdef USE_LIGHTMAP\n uniform sampler2D lightMap;\n uniform float lightMapIntensity;\n#endif";
  14165. // File:src/renderers/shaders/ShaderChunk/lights_lambert_vertex.glsl
  14166. THREE.ShaderChunk[ 'lights_lambert_vertex' ] = "vec3 diffuse = vec3( 1.0 );\nGeometricContext geometry;\ngeometry.position = mvPosition.xyz;\ngeometry.normal = normalize( transformedNormal );\ngeometry.viewDir = normalize( -mvPosition.xyz );\nGeometricContext backGeometry;\nbackGeometry.position = geometry.position;\nbackGeometry.normal = -geometry.normal;\nbackGeometry.viewDir = geometry.viewDir;\nvLightFront = vec3( 0.0 );\n#ifdef DOUBLE_SIDED\n vLightBack = vec3( 0.0 );\n#endif\nIncidentLight directLight;\nfloat dotNL;\nvec3 directLightColor_Diffuse;\n#if NUM_POINT_LIGHTS > 0\n for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n getPointDirectLightIrradiance( pointLights[ i ], geometry, directLight );\n dotNL = dot( geometry.normal, directLight.direction );\n directLightColor_Diffuse = PI * directLight.color;\n vLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n #ifdef DOUBLE_SIDED\n vLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n #endif\n }\n#endif\n#if NUM_SPOT_LIGHTS > 0\n for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n getSpotDirectLightIrradiance( spotLights[ i ], geometry, directLight );\n dotNL = dot( geometry.normal, directLight.direction );\n directLightColor_Diffuse = PI * directLight.color;\n vLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n #ifdef DOUBLE_SIDED\n vLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n #endif\n }\n#endif\n#if NUM_DIR_LIGHTS > 0\n for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n getDirectionalDirectLightIrradiance( directionalLights[ i ], geometry, directLight );\n dotNL = dot( geometry.normal, directLight.direction );\n directLightColor_Diffuse = PI * directLight.color;\n vLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n #ifdef DOUBLE_SIDED\n vLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n #endif\n }\n#endif\n#if NUM_HEMI_LIGHTS > 0\n for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n vLightFront += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry );\n #ifdef DOUBLE_SIDED\n vLightBack += getHemisphereLightIrradiance( hemisphereLights[ i ], backGeometry );\n #endif\n }\n#endif\n";
  14167. // File:src/renderers/shaders/ShaderChunk/lights_pars.glsl
  14168. THREE.ShaderChunk[ 'lights_pars' ] = "uniform vec3 ambientLightColor;\nvec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {\n vec3 irradiance = ambientLightColor;\n #ifndef PHYSICALLY_CORRECT_LIGHTS\n irradiance *= PI;\n #endif\n return irradiance;\n}\n#if NUM_DIR_LIGHTS > 0\n struct DirectionalLight {\n vec3 direction;\n vec3 color;\n int shadow;\n float shadowBias;\n float shadowRadius;\n vec2 shadowMapSize;\n };\n uniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];\n void getDirectionalDirectLightIrradiance( const in DirectionalLight directionalLight, const in GeometricContext geometry, out IncidentLight directLight ) {\n directLight.color = directionalLight.color;\n directLight.direction = directionalLight.direction;\n directLight.visible = true;\n }\n#endif\n#if NUM_POINT_LIGHTS > 0\n struct PointLight {\n vec3 position;\n vec3 color;\n float distance;\n float decay;\n int shadow;\n float shadowBias;\n float shadowRadius;\n vec2 shadowMapSize;\n };\n uniform PointLight pointLights[ NUM_POINT_LIGHTS ];\n void getPointDirectLightIrradiance( const in PointLight pointLight, const in GeometricContext geometry, out IncidentLight directLight ) {\n vec3 lVector = pointLight.position - geometry.position;\n directLight.direction = normalize( lVector );\n float lightDistance = length( lVector );\n if ( testLightInRange( lightDistance, pointLight.distance ) ) {\n directLight.color = pointLight.color;\n directLight.color *= punctualLightIntensityToIrradianceFactor( lightDistance, pointLight.distance, pointLight.decay );\n directLight.visible = true;\n } else {\n directLight.color = vec3( 0.0 );\n directLight.visible = false;\n }\n }\n#endif\n#if NUM_SPOT_LIGHTS > 0\n struct SpotLight {\n vec3 position;\n vec3 direction;\n vec3 color;\n float distance;\n float decay;\n float coneCos;\n float penumbraCos;\n int shadow;\n float shadowBias;\n float shadowRadius;\n vec2 shadowMapSize;\n };\n uniform SpotLight spotLights[ NUM_SPOT_LIGHTS ];\n void getSpotDirectLightIrradiance( const in SpotLight spotLight, const in GeometricContext geometry, out IncidentLight directLight ) {\n vec3 lVector = spotLight.position - geometry.position;\n directLight.direction = normalize( lVector );\n float lightDistance = length( lVector );\n float angleCos = dot( directLight.direction, spotLight.direction );\n if ( all( bvec2( angleCos > spotLight.coneCos, testLightInRange( lightDistance, spotLight.distance ) ) ) ) {\n float spotEffect = smoothstep( spotLight.coneCos, spotLight.penumbraCos, angleCos );\n directLight.color = spotLight.color;\n directLight.color *= spotEffect * punctualLightIntensityToIrradianceFactor( lightDistance, spotLight.distance, spotLight.decay );\n directLight.visible = true;\n } else {\n directLight.color = vec3( 0.0 );\n directLight.visible = false;\n }\n }\n#endif\n#if NUM_HEMI_LIGHTS > 0\n struct HemisphereLight {\n vec3 direction;\n vec3 skyColor;\n vec3 groundColor;\n };\n uniform HemisphereLight hemisphereLights[ NUM_HEMI_LIGHTS ];\n vec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in GeometricContext geometry ) {\n float dotNL = dot( geometry.normal, hemiLight.direction );\n float hemiDiffuseWeight = 0.5 * dotNL + 0.5;\n vec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );\n #ifndef PHYSICALLY_CORRECT_LIGHTS\n irradiance *= PI;\n #endif\n return irradiance;\n }\n#endif\n#if defined( USE_ENVMAP ) && defined( PHYSICAL )\n vec3 getLightProbeIndirectIrradiance( const in GeometricContext geometry, const in int maxMIPLevel ) {\n #ifdef DOUBLE_SIDED\n float flipNormal = ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n #else\n float flipNormal = 1.0;\n #endif\n vec3 worldNormal = inverseTransformDirection( geometry.normal, viewMatrix );\n #ifdef ENVMAP_TYPE_CUBE\n vec3 queryVec = flipNormal * vec3( flipEnvMap * worldNormal.x, worldNormal.yz );\n #ifdef TEXTURE_LOD_EXT\n vec4 envMapColor = textureCubeLodEXT( envMap, queryVec, float( maxMIPLevel ) );\n #else\n vec4 envMapColor = textureCube( envMap, queryVec, float( maxMIPLevel ) );\n #endif\n envMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\n #elif defined( ENVMAP_TYPE_CUBE_UV )\n vec3 queryVec = flipNormal * vec3( flipEnvMap * worldNormal.x, worldNormal.yz );\n vec4 envMapColor = textureCubeUV( queryVec, 1.0 );\n #else\n vec4 envMapColor = vec4( 0.0 );\n #endif\n return PI * envMapColor.rgb * envMapIntensity;\n }\n float getSpecularMIPLevel( const in float blinnShininessExponent, const in int maxMIPLevel ) {\n float maxMIPLevelScalar = float( maxMIPLevel );\n float desiredMIPLevel = maxMIPLevelScalar - 0.79248 - 0.5 * log2( pow2( blinnShininessExponent ) + 1.0 );\n return clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );\n }\n vec3 getLightProbeIndirectRadiance( const in GeometricContext geometry, const in float blinnShininessExponent, const in int maxMIPLevel ) {\n #ifdef ENVMAP_MODE_REFLECTION\n vec3 reflectVec = reflect( -geometry.viewDir, geometry.normal );\n #else\n vec3 reflectVec = refract( -geometry.viewDir, geometry.normal, refractionRatio );\n #endif\n #ifdef DOUBLE_SIDED\n float flipNormal = ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n #else\n float flipNormal = 1.0;\n #endif\n reflectVec = inverseTransformDirection( reflectVec, viewMatrix );\n float specularMIPLevel = getSpecularMIPLevel( blinnShininessExponent, maxMIPLevel );\n #ifdef ENVMAP_TYPE_CUBE\n vec3 queryReflectVec = flipNormal * vec3( flipEnvMap * reflectVec.x, reflectVec.yz );\n #ifdef TEXTURE_LOD_EXT\n vec4 envMapColor = textureCubeLodEXT( envMap, queryReflectVec, specularMIPLevel );\n #else\n vec4 envMapColor = textureCube( envMap, queryReflectVec, specularMIPLevel );\n #endif\n envMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\n #elif defined( ENVMAP_TYPE_CUBE_UV )\n vec3 queryReflectVec = flipNormal * vec3( flipEnvMap * reflectVec.x, reflectVec.yz );\n vec4 envMapColor = textureCubeUV(queryReflectVec, BlinnExponentToGGXRoughness(blinnShininessExponent));\n #elif defined( ENVMAP_TYPE_EQUIREC )\n vec2 sampleUV;\n sampleUV.y = saturate( flipNormal * reflectVec.y * 0.5 + 0.5 );\n sampleUV.x = atan( flipNormal * reflectVec.z, flipNormal * reflectVec.x ) * RECIPROCAL_PI2 + 0.5;\n #ifdef TEXTURE_LOD_EXT\n vec4 envMapColor = texture2DLodEXT( envMap, sampleUV, specularMIPLevel );\n #else\n vec4 envMapColor = texture2D( envMap, sampleUV, specularMIPLevel );\n #endif\n envMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\n #elif defined( ENVMAP_TYPE_SPHERE )\n vec3 reflectView = flipNormal * normalize((viewMatrix * vec4( reflectVec, 0.0 )).xyz + vec3(0.0,0.0,1.0));\n #ifdef TEXTURE_LOD_EXT\n vec4 envMapColor = texture2DLodEXT( envMap, reflectView.xy * 0.5 + 0.5, specularMIPLevel );\n #else\n vec4 envMapColor = texture2D( envMap, reflectView.xy * 0.5 + 0.5, specularMIPLevel );\n #endif\n envMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\n #endif\n return envMapColor.rgb * envMapIntensity;\n }\n#endif\n";
  14169. // File:src/renderers/shaders/ShaderChunk/lights_phong_fragment.glsl
  14170. THREE.ShaderChunk[ 'lights_phong_fragment' ] = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;\n";
  14171. // File:src/renderers/shaders/ShaderChunk/lights_phong_pars_fragment.glsl
  14172. 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";
  14173. // File:src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl
  14174. THREE.ShaderChunk[ 'lights_physical_fragment' ] = "PhysicalMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );\nmaterial.specularRoughness = clamp( roughnessFactor, 0.04, 1.0 );\n#ifdef STANDARD\n material.specularColor = mix( vec3( 0.04 ), diffuseColor.rgb, metalnessFactor );\n#else\n material.specularColor = mix( vec3( 0.16 * pow2( reflectivity ) ), diffuseColor.rgb, metalnessFactor );\n#endif\n";
  14175. // File:src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl
  14176. THREE.ShaderChunk[ 'lights_physical_pars_fragment' ] = "struct PhysicalMaterial {\n vec3 diffuseColor;\n float specularRoughness;\n vec3 specularColor;\n #ifndef STANDARD\n #endif\n};\nvoid RE_Direct_Physical( const in IncidentLight directLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n float dotNL = saturate( dot( geometry.normal, directLight.direction ) );\n vec3 irradiance = dotNL * directLight.color;\n #ifndef PHYSICALLY_CORRECT_LIGHTS\n irradiance *= PI;\n #endif\n reflectedLight.directDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n reflectedLight.directSpecular += irradiance * BRDF_Specular_GGX( directLight, geometry, material.specularColor, material.specularRoughness );\n}\nvoid RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n reflectedLight.indirectDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectSpecular_Physical( const in vec3 radiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n reflectedLight.indirectSpecular += radiance * BRDF_Specular_GGX_Environment( geometry, material.specularColor, material.specularRoughness );\n}\n#define RE_Direct RE_Direct_Physical\n#define RE_IndirectDiffuse RE_IndirectDiffuse_Physical\n#define RE_IndirectSpecular RE_IndirectSpecular_Physical\n#define Material_BlinnShininessExponent( material ) GGXRoughnessToBlinnExponent( material.specularRoughness )\nfloat computeSpecularOcclusion( const in float dotNV, const in float ambientOcclusion, const in float roughness ) {\n return saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion );\n}\n";
  14177. // File:src/renderers/shaders/ShaderChunk/lights_template.glsl
  14178. THREE.ShaderChunk[ 'lights_template' ] = "\nGeometricContext geometry;\ngeometry.position = - vViewPosition;\ngeometry.normal = normal;\ngeometry.viewDir = normalize( vViewPosition );\nIncidentLight directLight;\n#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )\n PointLight pointLight;\n for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n pointLight = pointLights[ i ];\n getPointDirectLightIrradiance( pointLight, geometry, directLight );\n #ifdef USE_SHADOWMAP\n directLight.color *= all( bvec2( pointLight.shadow, directLight.visible ) ) ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ] ) : 1.0;\n #endif\n RE_Direct( directLight, geometry, material, reflectedLight );\n }\n#endif\n#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )\n SpotLight spotLight;\n for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n spotLight = spotLights[ i ];\n getSpotDirectLightIrradiance( spotLight, geometry, directLight );\n #ifdef USE_SHADOWMAP\n directLight.color *= all( bvec2( spotLight.shadow, directLight.visible ) ) ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowBias, spotLight.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\n #endif\n RE_Direct( directLight, geometry, material, reflectedLight );\n }\n#endif\n#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )\n DirectionalLight directionalLight;\n for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n directionalLight = directionalLights[ i ];\n getDirectionalDirectLightIrradiance( directionalLight, geometry, directLight );\n #ifdef USE_SHADOWMAP\n directLight.color *= all( bvec2( directionalLight.shadow, directLight.visible ) ) ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n #endif\n RE_Direct( directLight, geometry, material, reflectedLight );\n }\n#endif\n#if defined( RE_IndirectDiffuse )\n vec3 irradiance = getAmbientLightIrradiance( ambientLightColor );\n #ifdef USE_LIGHTMAP\n vec3 lightMapIrradiance = texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n #ifndef PHYSICALLY_CORRECT_LIGHTS\n lightMapIrradiance *= PI;\n #endif\n irradiance += lightMapIrradiance;\n #endif\n #if ( NUM_HEMI_LIGHTS > 0 )\n for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry );\n }\n #endif\n #if defined( USE_ENVMAP ) && defined( PHYSICAL ) && defined( ENVMAP_TYPE_CUBE_UV )\n irradiance += getLightProbeIndirectIrradiance( geometry, 8 );\n #endif\n RE_IndirectDiffuse( irradiance, geometry, material, reflectedLight );\n#endif\n#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )\n vec3 radiance = getLightProbeIndirectRadiance( geometry, Material_BlinnShininessExponent( material ), 8 );\n RE_IndirectSpecular( radiance, geometry, material, reflectedLight );\n#endif\n";
  14179. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl
  14180. THREE.ShaderChunk[ 'logdepthbuf_fragment' ] = "#if defined(USE_LOGDEPTHBUF) && defined(USE_LOGDEPTHBUF_EXT)\n gl_FragDepthEXT = log2(vFragDepth) * logDepthBufFC * 0.5;\n#endif";
  14181. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl
  14182. 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";
  14183. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_pars_vertex.glsl
  14184. 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";
  14185. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl
  14186. 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";
  14187. // File:src/renderers/shaders/ShaderChunk/map_fragment.glsl
  14188. THREE.ShaderChunk[ 'map_fragment' ] = "#ifdef USE_MAP\n vec4 texelColor = texture2D( map, vUv );\n texelColor = mapTexelToLinear( texelColor );\n diffuseColor *= texelColor;\n#endif\n";
  14189. // File:src/renderers/shaders/ShaderChunk/map_pars_fragment.glsl
  14190. THREE.ShaderChunk[ 'map_pars_fragment' ] = "#ifdef USE_MAP\n uniform sampler2D map;\n#endif\n";
  14191. // File:src/renderers/shaders/ShaderChunk/map_particle_fragment.glsl
  14192. 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";
  14193. // File:src/renderers/shaders/ShaderChunk/map_particle_pars_fragment.glsl
  14194. THREE.ShaderChunk[ 'map_particle_pars_fragment' ] = "#ifdef USE_MAP\n uniform vec4 offsetRepeat;\n uniform sampler2D map;\n#endif\n";
  14195. // File:src/renderers/shaders/ShaderChunk/metalnessmap_fragment.glsl
  14196. THREE.ShaderChunk[ 'metalnessmap_fragment' ] = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n vec4 texelMetalness = texture2D( metalnessMap, vUv );\n metalnessFactor *= texelMetalness.r;\n#endif\n";
  14197. // File:src/renderers/shaders/ShaderChunk/metalnessmap_pars_fragment.glsl
  14198. THREE.ShaderChunk[ 'metalnessmap_pars_fragment' ] = "#ifdef USE_METALNESSMAP\n uniform sampler2D metalnessMap;\n#endif";
  14199. // File:src/renderers/shaders/ShaderChunk/morphnormal_vertex.glsl
  14200. 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";
  14201. // File:src/renderers/shaders/ShaderChunk/morphtarget_pars_vertex.glsl
  14202. 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";
  14203. // File:src/renderers/shaders/ShaderChunk/morphtarget_vertex.glsl
  14204. 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";
  14205. // File:src/renderers/shaders/ShaderChunk/normal_fragment.glsl
  14206. 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";
  14207. // File:src/renderers/shaders/ShaderChunk/normalmap_pars_fragment.glsl
  14208. 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";
  14209. // File:src/renderers/shaders/ShaderChunk/packing.glsl
  14210. THREE.ShaderChunk[ 'packing' ] = "vec3 packNormalToRGB( const in vec3 normal ) {\n return normalize( normal ) * 0.5 + 0.5;\n}\nvec3 unpackRGBToNormal( const in vec3 rgb ) {\n return 1.0 - 2.0 * rgb.xyz;\n}\nconst float PackUpscale = 256. / 255.;const float UnpackDownscale = 255. / 256.;\nconst vec3 PackFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );\nconst vec4 UnpackFactors = UnpackDownscale / vec4( PackFactors, 1. );\nconst float ShiftRight8 = 1. / 256.;\nvec4 packDepthToRGBA( const in float v ) {\n vec4 r = vec4( fract( v * PackFactors ), v );\n r.yzw -= r.xyz * ShiftRight8; return r * PackUpscale;\n}\nfloat unpackRGBAToDepth( const in vec4 v ) {\n return dot( v, UnpackFactors );\n}\nfloat viewZToOrthoDepth( const in float viewZ, const in float near, const in float far ) {\n return ( viewZ + near ) / ( near - far );\n}\nfloat OrthoDepthToViewZ( const in float linearClipZ, const in float near, const in float far ) {\n return linearClipZ * ( near - far ) - near;\n}\nfloat viewZToPerspectiveDepth( const in float viewZ, const in float near, const in float far ) {\n return (( near + viewZ ) * far ) / (( far - near ) * viewZ );\n}\nfloat perspectiveDepthToViewZ( const in float invClipZ, const in float near, const in float far ) {\n return ( near * far ) / ( ( far - near ) * invClipZ - far );\n}\n";
  14211. // File:src/renderers/shaders/ShaderChunk/premultiplied_alpha_fragment.glsl
  14212. THREE.ShaderChunk[ 'premultiplied_alpha_fragment' ] = "#ifdef PREMULTIPLIED_ALPHA\n gl_FragColor.rgb *= gl_FragColor.a;\n#endif\n";
  14213. // File:src/renderers/shaders/ShaderChunk/project_vertex.glsl
  14214. 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";
  14215. // File:src/renderers/shaders/ShaderChunk/roughnessmap_fragment.glsl
  14216. THREE.ShaderChunk[ 'roughnessmap_fragment' ] = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n vec4 texelRoughness = texture2D( roughnessMap, vUv );\n roughnessFactor *= texelRoughness.r;\n#endif\n";
  14217. // File:src/renderers/shaders/ShaderChunk/roughnessmap_pars_fragment.glsl
  14218. THREE.ShaderChunk[ 'roughnessmap_pars_fragment' ] = "#ifdef USE_ROUGHNESSMAP\n uniform sampler2D roughnessMap;\n#endif";
  14219. // File:src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl
  14220. THREE.ShaderChunk[ 'shadowmap_pars_fragment' ] = "#ifdef USE_SHADOWMAP\n #if NUM_DIR_LIGHTS > 0\n uniform sampler2D directionalShadowMap[ NUM_DIR_LIGHTS ];\n varying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHTS ];\n #endif\n #if NUM_SPOT_LIGHTS > 0\n uniform sampler2D spotShadowMap[ NUM_SPOT_LIGHTS ];\n varying vec4 vSpotShadowCoord[ NUM_SPOT_LIGHTS ];\n #endif\n #if NUM_POINT_LIGHTS > 0\n uniform sampler2D pointShadowMap[ NUM_POINT_LIGHTS ];\n varying vec4 vPointShadowCoord[ NUM_POINT_LIGHTS ];\n #endif\n float texture2DCompare( sampler2D depths, vec2 uv, float compare ) {\n return step( compare, unpackRGBAToDepth( texture2D( depths, uv ) ) );\n }\n float texture2DShadowLerp( sampler2D depths, vec2 size, vec2 uv, float compare ) {\n const vec2 offset = vec2( 0.0, 1.0 );\n vec2 texelSize = vec2( 1.0 ) / size;\n vec2 centroidUV = floor( uv * size + 0.5 ) / size;\n float lb = texture2DCompare( depths, centroidUV + texelSize * offset.xx, compare );\n float lt = texture2DCompare( depths, centroidUV + texelSize * offset.xy, compare );\n float rb = texture2DCompare( depths, centroidUV + texelSize * offset.yx, compare );\n float rt = texture2DCompare( depths, centroidUV + texelSize * offset.yy, compare );\n vec2 f = fract( uv * size + 0.5 );\n float a = mix( lb, lt, f.y );\n float b = mix( rb, rt, f.y );\n float c = mix( a, b, f.x );\n return c;\n }\n float getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord ) {\n shadowCoord.xyz /= shadowCoord.w;\n shadowCoord.z += shadowBias;\n bvec4 inFrustumVec = bvec4 ( shadowCoord.x >= 0.0, shadowCoord.x <= 1.0, shadowCoord.y >= 0.0, shadowCoord.y <= 1.0 );\n bool inFrustum = all( inFrustumVec );\n bvec2 frustumTestVec = bvec2( inFrustum, shadowCoord.z <= 1.0 );\n bool frustumTest = all( frustumTestVec );\n if ( frustumTest ) {\n #if defined( SHADOWMAP_TYPE_PCF )\n vec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n float dx0 = - texelSize.x * shadowRadius;\n float dy0 = - texelSize.y * shadowRadius;\n float dx1 = + texelSize.x * shadowRadius;\n float dy1 = + texelSize.y * shadowRadius;\n return (\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )\n ) * ( 1.0 / 9.0 );\n #elif defined( SHADOWMAP_TYPE_PCF_SOFT )\n vec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n float dx0 = - texelSize.x * shadowRadius;\n float dy0 = - texelSize.y * shadowRadius;\n float dx1 = + texelSize.x * shadowRadius;\n float dy1 = + texelSize.y * shadowRadius;\n return (\n texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +\n texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +\n texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +\n texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +\n texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy, shadowCoord.z ) +\n texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +\n texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +\n texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +\n texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )\n ) * ( 1.0 / 9.0 );\n #else\n return texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z );\n #endif\n }\n return 1.0;\n }\n vec2 cubeToUV( vec3 v, float texelSizeY ) {\n vec3 absV = abs( v );\n float scaleToCube = 1.0 / max( absV.x, max( absV.y, absV.z ) );\n absV *= scaleToCube;\n v *= scaleToCube * ( 1.0 - 2.0 * texelSizeY );\n vec2 planar = v.xy;\n float almostATexel = 1.5 * texelSizeY;\n float almostOne = 1.0 - almostATexel;\n if ( absV.z >= almostOne ) {\n if ( v.z > 0.0 )\n planar.x = 4.0 - v.x;\n } else if ( absV.x >= almostOne ) {\n float signX = sign( v.x );\n planar.x = v.z * signX + 2.0 * signX;\n } else if ( absV.y >= almostOne ) {\n float signY = sign( v.y );\n planar.x = v.x + 2.0 * signY + 2.0;\n planar.y = v.z * signY - 2.0;\n }\n return vec2( 0.125, 0.25 ) * planar + vec2( 0.375, 0.75 );\n }\n float getPointShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord ) {\n vec2 texelSize = vec2( 1.0 ) / ( shadowMapSize * vec2( 4.0, 2.0 ) );\n vec3 lightToPosition = shadowCoord.xyz;\n vec3 bd3D = normalize( lightToPosition );\n float dp = ( length( lightToPosition ) - shadowBias ) / 1000.0;\n #if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT )\n vec2 offset = vec2( - 1, 1 ) * shadowRadius * texelSize.y;\n return (\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyy, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyy, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyx, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyx, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxy, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxy, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxx, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxx, texelSize.y ), dp )\n ) * ( 1.0 / 9.0 );\n #else\n return texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp );\n #endif\n }\n#endif\n";
  14221. // File:src/renderers/shaders/ShaderChunk/shadowmap_pars_vertex.glsl
  14222. 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";
  14223. // File:src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl
  14224. 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";
  14225. // File:src/renderers/shaders/ShaderChunk/shadowmask_pars_fragment.glsl
  14226. 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";
  14227. // File:src/renderers/shaders/ShaderChunk/skinbase_vertex.glsl
  14228. 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";
  14229. // File:src/renderers/shaders/ShaderChunk/skinning_pars_vertex.glsl
  14230. THREE.ShaderChunk[ 'skinning_pars_vertex' ] = "#ifdef USE_SKINNING\n uniform mat4 bindMatrix;\n uniform mat4 bindMatrixInverse;\n #ifdef BONE_TEXTURE\n uniform sampler2D boneTexture;\n uniform int boneTextureWidth;\n uniform int boneTextureHeight;\n mat4 getBoneMatrix( const in float i ) {\n float j = i * 4.0;\n float x = mod( j, float( boneTextureWidth ) );\n float y = floor( j / float( boneTextureWidth ) );\n float dx = 1.0 / float( boneTextureWidth );\n float dy = 1.0 / float( boneTextureHeight );\n y = dy * ( y + 0.5 );\n vec4 v1 = texture2D( boneTexture, vec2( dx * ( x + 0.5 ), y ) );\n vec4 v2 = texture2D( boneTexture, vec2( dx * ( x + 1.5 ), y ) );\n vec4 v3 = texture2D( boneTexture, vec2( dx * ( x + 2.5 ), y ) );\n vec4 v4 = texture2D( boneTexture, vec2( dx * ( x + 3.5 ), y ) );\n mat4 bone = mat4( v1, v2, v3, v4 );\n return bone;\n }\n #else\n uniform mat4 boneMatrices[ MAX_BONES ];\n mat4 getBoneMatrix( const in float i ) {\n mat4 bone = boneMatrices[ int(i) ];\n return bone;\n }\n #endif\n#endif\n";
  14231. // File:src/renderers/shaders/ShaderChunk/skinning_vertex.glsl
  14232. 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";
  14233. // File:src/renderers/shaders/ShaderChunk/skinnormal_vertex.glsl
  14234. 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";
  14235. // File:src/renderers/shaders/ShaderChunk/specularmap_fragment.glsl
  14236. 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";
  14237. // File:src/renderers/shaders/ShaderChunk/specularmap_pars_fragment.glsl
  14238. THREE.ShaderChunk[ 'specularmap_pars_fragment' ] = "#ifdef USE_SPECULARMAP\n uniform sampler2D specularMap;\n#endif";
  14239. // File:src/renderers/shaders/ShaderChunk/tonemapping_fragment.glsl
  14240. THREE.ShaderChunk[ 'tonemapping_fragment' ] = "#if defined( TONE_MAPPING )\n gl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif\n";
  14241. // File:src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl
  14242. 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";
  14243. // File:src/renderers/shaders/ShaderChunk/uv2_pars_fragment.glsl
  14244. THREE.ShaderChunk[ 'uv2_pars_fragment' ] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n varying vec2 vUv2;\n#endif";
  14245. // File:src/renderers/shaders/ShaderChunk/uv2_pars_vertex.glsl
  14246. THREE.ShaderChunk[ 'uv2_pars_vertex' ] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n attribute vec2 uv2;\n varying vec2 vUv2;\n#endif";
  14247. // File:src/renderers/shaders/ShaderChunk/uv2_vertex.glsl
  14248. THREE.ShaderChunk[ 'uv2_vertex' ] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n vUv2 = uv2;\n#endif";
  14249. // File:src/renderers/shaders/ShaderChunk/uv_pars_fragment.glsl
  14250. 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";
  14251. // File:src/renderers/shaders/ShaderChunk/uv_pars_vertex.glsl
  14252. 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";
  14253. // File:src/renderers/shaders/ShaderChunk/uv_vertex.glsl
  14254. 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";
  14255. // File:src/renderers/shaders/ShaderChunk/worldpos_vertex.glsl
  14256. THREE.ShaderChunk[ 'worldpos_vertex' ] = "#if defined( USE_ENVMAP ) || defined( PHONG ) || defined( PHYSICAL ) || defined( LAMBERT ) || defined ( USE_SHADOWMAP )\n #ifdef USE_SKINNING\n vec4 worldPosition = modelMatrix * skinned;\n #else\n vec4 worldPosition = modelMatrix * vec4( transformed, 1.0 );\n #endif\n#endif\n";
  14257. // File:src/renderers/shaders/UniformsUtils.js
  14258. /**
  14259. * Uniform Utilities
  14260. */
  14261. THREE.UniformsUtils = {
  14262. merge: function ( uniforms ) {
  14263. var merged = {};
  14264. for ( var u = 0; u < uniforms.length; u ++ ) {
  14265. var tmp = this.clone( uniforms[ u ] );
  14266. for ( var p in tmp ) {
  14267. merged[ p ] = tmp[ p ];
  14268. }
  14269. }
  14270. return merged;
  14271. },
  14272. clone: function ( uniforms_src ) {
  14273. var uniforms_dst = {};
  14274. for ( var u in uniforms_src ) {
  14275. uniforms_dst[ u ] = {};
  14276. for ( var p in uniforms_src[ u ] ) {
  14277. var parameter_src = uniforms_src[ u ][ p ];
  14278. if ( parameter_src instanceof THREE.Color ||
  14279. parameter_src instanceof THREE.Vector2 ||
  14280. parameter_src instanceof THREE.Vector3 ||
  14281. parameter_src instanceof THREE.Vector4 ||
  14282. parameter_src instanceof THREE.Matrix3 ||
  14283. parameter_src instanceof THREE.Matrix4 ||
  14284. parameter_src instanceof THREE.Texture ) {
  14285. uniforms_dst[ u ][ p ] = parameter_src.clone();
  14286. } else if ( Array.isArray( parameter_src ) ) {
  14287. uniforms_dst[ u ][ p ] = parameter_src.slice();
  14288. } else {
  14289. uniforms_dst[ u ][ p ] = parameter_src;
  14290. }
  14291. }
  14292. }
  14293. return uniforms_dst;
  14294. }
  14295. };
  14296. // File:src/renderers/shaders/UniformsLib.js
  14297. /**
  14298. * Uniforms library for shared webgl shaders
  14299. */
  14300. THREE.UniformsLib = {
  14301. common: {
  14302. "diffuse": { type: "c", value: new THREE.Color( 0xeeeeee ) },
  14303. "opacity": { type: "1f", value: 1.0 },
  14304. "map": { type: "t", value: null },
  14305. "offsetRepeat": { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) },
  14306. "specularMap": { type: "t", value: null },
  14307. "alphaMap": { type: "t", value: null },
  14308. "envMap": { type: "t", value: null },
  14309. "flipEnvMap": { type: "1f", value: - 1 },
  14310. "reflectivity": { type: "1f", value: 1.0 },
  14311. "refractionRatio": { type: "1f", value: 0.98 }
  14312. },
  14313. aomap: {
  14314. "aoMap": { type: "t", value: null },
  14315. "aoMapIntensity": { type: "1f", value: 1 }
  14316. },
  14317. lightmap: {
  14318. "lightMap": { type: "t", value: null },
  14319. "lightMapIntensity": { type: "1f", value: 1 }
  14320. },
  14321. emissivemap: {
  14322. "emissiveMap": { type: "t", value: null }
  14323. },
  14324. bumpmap: {
  14325. "bumpMap": { type: "t", value: null },
  14326. "bumpScale": { type: "1f", value: 1 }
  14327. },
  14328. normalmap: {
  14329. "normalMap": { type: "t", value: null },
  14330. "normalScale": { type: "v2", value: new THREE.Vector2( 1, 1 ) }
  14331. },
  14332. displacementmap: {
  14333. "displacementMap": { type: "t", value: null },
  14334. "displacementScale": { type: "1f", value: 1 },
  14335. "displacementBias": { type: "1f", value: 0 }
  14336. },
  14337. roughnessmap: {
  14338. "roughnessMap": { type: "t", value: null }
  14339. },
  14340. metalnessmap: {
  14341. "metalnessMap": { type: "t", value: null }
  14342. },
  14343. fog: {
  14344. "fogDensity": { type: "1f", value: 0.00025 },
  14345. "fogNear": { type: "1f", value: 1 },
  14346. "fogFar": { type: "1f", value: 2000 },
  14347. "fogColor": { type: "c", value: new THREE.Color( 0xffffff ) }
  14348. },
  14349. lights: {
  14350. "ambientLightColor": { type: "3fv", value: [] },
  14351. "directionalLights": { type: "sa", value: [], properties: {
  14352. "direction": { type: "v3" },
  14353. "color": { type: "c" },
  14354. "shadow": { type: "1i" },
  14355. "shadowBias": { type: "1f" },
  14356. "shadowRadius": { type: "1f" },
  14357. "shadowMapSize": { type: "v2" }
  14358. } },
  14359. "directionalShadowMap": { type: "tv", value: [] },
  14360. "directionalShadowMatrix": { type: "m4v", value: [] },
  14361. "spotLights": { type: "sa", value: [], properties: {
  14362. "color": { type: "c" },
  14363. "position": { type: "v3" },
  14364. "direction": { type: "v3" },
  14365. "distance": { type: "1f" },
  14366. "coneCos": { type: "1f" },
  14367. "penumbraCos": { type: "1f" },
  14368. "decay": { type: "1f" },
  14369. "shadow": { type: "1i" },
  14370. "shadowBias": { type: "1f" },
  14371. "shadowRadius": { type: "1f" },
  14372. "shadowMapSize": { type: "v2" }
  14373. } },
  14374. "spotShadowMap": { type: "tv", value: [] },
  14375. "spotShadowMatrix": { type: "m4v", value: [] },
  14376. "pointLights": { type: "sa", value: [], properties: {
  14377. "color": { type: "c" },
  14378. "position": { type: "v3" },
  14379. "decay": { type: "1f" },
  14380. "distance": { type: "1f" },
  14381. "shadow": { type: "1i" },
  14382. "shadowBias": { type: "1f" },
  14383. "shadowRadius": { type: "1f" },
  14384. "shadowMapSize": { type: "v2" }
  14385. } },
  14386. "pointShadowMap": { type: "tv", value: [] },
  14387. "pointShadowMatrix": { type: "m4v", value: [] },
  14388. "hemisphereLights": { type: "sa", value: [], properties: {
  14389. "direction": { type: "v3" },
  14390. "skyColor": { type: "c" },
  14391. "groundColor": { type: "c" }
  14392. } }
  14393. },
  14394. points: {
  14395. "diffuse": { type: "c", value: new THREE.Color( 0xeeeeee ) },
  14396. "opacity": { type: "1f", value: 1.0 },
  14397. "size": { type: "1f", value: 1.0 },
  14398. "scale": { type: "1f", value: 1.0 },
  14399. "map": { type: "t", value: null },
  14400. "offsetRepeat": { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) }
  14401. }
  14402. };
  14403. // File:src/renderers/shaders/ShaderLib/cube_frag.glsl
  14404. THREE.ShaderChunk[ 'cube_frag' ] = "uniform samplerCube tCube;\nuniform float tFlip;\nvarying vec3 vWorldPosition;\n#include <common>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n #include <clipping_planes_fragment>\n gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );\n #include <logdepthbuf_fragment>\n}\n";
  14405. // File:src/renderers/shaders/ShaderLib/cube_vert.glsl
  14406. THREE.ShaderChunk[ 'cube_vert' ] = "varying vec3 vWorldPosition;\n#include <common>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n vWorldPosition = transformDirection( position, modelMatrix );\n #include <begin_vertex>\n #include <project_vertex>\n #include <logdepthbuf_vertex>\n #include <clipping_planes_vertex>\n}\n";
  14407. // File:src/renderers/shaders/ShaderLib/depth_frag.glsl
  14408. THREE.ShaderChunk[ 'depth_frag' ] = "#if DEPTH_PACKING == 3200\n uniform float opacity;\n#endif\n#include <common>\n#include <packing>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n #include <clipping_planes_fragment>\n vec4 diffuseColor = vec4( 1.0 );\n #if DEPTH_PACKING == 3200\n diffuseColor.a = opacity;\n #endif\n #include <map_fragment>\n #include <alphamap_fragment>\n #include <alphatest_fragment>\n #include <logdepthbuf_fragment>\n #if DEPTH_PACKING == 3200\n gl_FragColor = vec4( vec3( gl_FragCoord.z ), opacity );\n #elif DEPTH_PACKING == 3201\n gl_FragColor = packDepthToRGBA( gl_FragCoord.z );\n #endif\n}\n";
  14409. // File:src/renderers/shaders/ShaderLib/depth_vert.glsl
  14410. THREE.ShaderChunk[ 'depth_vert' ] = "#include <common>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n #include <uv_vertex>\n #include <skinbase_vertex>\n #include <begin_vertex>\n #include <displacementmap_vertex>\n #include <morphtarget_vertex>\n #include <skinning_vertex>\n #include <project_vertex>\n #include <logdepthbuf_vertex>\n #include <clipping_planes_vertex>\n}\n";
  14411. // File:src/renderers/shaders/ShaderLib/distanceRGBA_frag.glsl
  14412. THREE.ShaderChunk[ 'distanceRGBA_frag' ] = "uniform vec3 lightPos;\nvarying vec4 vWorldPosition;\n#include <common>\n#include <packing>\n#include <clipping_planes_pars_fragment>\nvoid main () {\n #include <clipping_planes_fragment>\n gl_FragColor = packDepthToRGBA( length( vWorldPosition.xyz - lightPos.xyz ) / 1000.0 );\n}\n";
  14413. // File:src/renderers/shaders/ShaderLib/distanceRGBA_vert.glsl
  14414. THREE.ShaderChunk[ 'distanceRGBA_vert' ] = "varying vec4 vWorldPosition;\n#include <common>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n #include <skinbase_vertex>\n #include <begin_vertex>\n #include <morphtarget_vertex>\n #include <skinning_vertex>\n #include <project_vertex>\n #include <worldpos_vertex>\n #include <clipping_planes_vertex>\n vWorldPosition = worldPosition;\n}\n";
  14415. // File:src/renderers/shaders/ShaderLib/equirect_frag.glsl
  14416. THREE.ShaderChunk[ 'equirect_frag' ] = "uniform sampler2D tEquirect;\nuniform float tFlip;\nvarying vec3 vWorldPosition;\n#include <common>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n #include <clipping_planes_fragment>\n vec3 direction = normalize( vWorldPosition );\n vec2 sampleUV;\n sampleUV.y = saturate( tFlip * direction.y * -0.5 + 0.5 );\n sampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;\n gl_FragColor = texture2D( tEquirect, sampleUV );\n #include <logdepthbuf_fragment>\n}\n";
  14417. // File:src/renderers/shaders/ShaderLib/equirect_vert.glsl
  14418. THREE.ShaderChunk[ 'equirect_vert' ] = "varying vec3 vWorldPosition;\n#include <common>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n vWorldPosition = transformDirection( position, modelMatrix );\n #include <begin_vertex>\n #include <project_vertex>\n #include <logdepthbuf_vertex>\n #include <clipping_planes_vertex>\n}\n";
  14419. // File:src/renderers/shaders/ShaderLib/linedashed_frag.glsl
  14420. THREE.ShaderChunk[ 'linedashed_frag' ] = "uniform vec3 diffuse;\nuniform float opacity;\nuniform float dashSize;\nuniform float totalSize;\nvarying float vLineDistance;\n#include <common>\n#include <color_pars_fragment>\n#include <fog_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n #include <clipping_planes_fragment>\n if ( mod( vLineDistance, totalSize ) > dashSize ) {\n discard;\n }\n vec3 outgoingLight = vec3( 0.0 );\n vec4 diffuseColor = vec4( diffuse, opacity );\n #include <logdepthbuf_fragment>\n #include <color_fragment>\n outgoingLight = diffuseColor.rgb;\n gl_FragColor = vec4( outgoingLight, diffuseColor.a );\n #include <premultiplied_alpha_fragment>\n #include <tonemapping_fragment>\n #include <encodings_fragment>\n #include <fog_fragment>\n}\n";
  14421. // File:src/renderers/shaders/ShaderLib/linedashed_vert.glsl
  14422. THREE.ShaderChunk[ 'linedashed_vert' ] = "uniform float scale;\nattribute float lineDistance;\nvarying float vLineDistance;\n#include <common>\n#include <color_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n #include <color_vertex>\n vLineDistance = scale * lineDistance;\n vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\n gl_Position = projectionMatrix * mvPosition;\n #include <logdepthbuf_vertex>\n #include <clipping_planes_vertex>\n}\n";
  14423. // File:src/renderers/shaders/ShaderLib/meshbasic_frag.glsl
  14424. THREE.ShaderChunk[ 'meshbasic_frag' ] = "uniform vec3 diffuse;\nuniform float opacity;\n#ifndef FLAT_SHADED\n varying vec3 vNormal;\n#endif\n#include <common>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <envmap_pars_fragment>\n#include <fog_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n #include <clipping_planes_fragment>\n vec4 diffuseColor = vec4( diffuse, opacity );\n #include <logdepthbuf_fragment>\n #include <map_fragment>\n #include <color_fragment>\n #include <alphamap_fragment>\n #include <alphatest_fragment>\n #include <specularmap_fragment>\n ReflectedLight reflectedLight;\n reflectedLight.directDiffuse = vec3( 0.0 );\n reflectedLight.directSpecular = vec3( 0.0 );\n reflectedLight.indirectDiffuse = diffuseColor.rgb;\n reflectedLight.indirectSpecular = vec3( 0.0 );\n #include <aomap_fragment>\n vec3 outgoingLight = reflectedLight.indirectDiffuse;\n #include <envmap_fragment>\n gl_FragColor = vec4( outgoingLight, diffuseColor.a );\n #include <premultiplied_alpha_fragment>\n #include <tonemapping_fragment>\n #include <encodings_fragment>\n #include <fog_fragment>\n}\n";
  14425. // File:src/renderers/shaders/ShaderLib/meshbasic_vert.glsl
  14426. THREE.ShaderChunk[ 'meshbasic_vert' ] = "#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <envmap_pars_vertex>\n#include <color_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n #include <uv_vertex>\n #include <uv2_vertex>\n #include <color_vertex>\n #include <skinbase_vertex>\n #ifdef USE_ENVMAP\n #include <beginnormal_vertex>\n #include <morphnormal_vertex>\n #include <skinnormal_vertex>\n #include <defaultnormal_vertex>\n #endif\n #include <begin_vertex>\n #include <morphtarget_vertex>\n #include <skinning_vertex>\n #include <project_vertex>\n #include <logdepthbuf_vertex>\n #include <worldpos_vertex>\n #include <clipping_planes_vertex>\n #include <envmap_vertex>\n}\n";
  14427. // File:src/renderers/shaders/ShaderLib/meshlambert_frag.glsl
  14428. THREE.ShaderChunk[ 'meshlambert_frag' ] = "uniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\nvarying vec3 vLightFront;\n#ifdef DOUBLE_SIDED\n varying vec3 vLightBack;\n#endif\n#include <common>\n#include <packing>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <envmap_pars_fragment>\n#include <bsdfs>\n#include <lights_pars>\n#include <fog_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <shadowmask_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n #include <clipping_planes_fragment>\n vec4 diffuseColor = vec4( diffuse, opacity );\n ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n vec3 totalEmissiveRadiance = emissive;\n #include <logdepthbuf_fragment>\n #include <map_fragment>\n #include <color_fragment>\n #include <alphamap_fragment>\n #include <alphatest_fragment>\n #include <specularmap_fragment>\n #include <emissivemap_fragment>\n reflectedLight.indirectDiffuse = getAmbientLightIrradiance( ambientLightColor );\n #include <lightmap_fragment>\n reflectedLight.indirectDiffuse *= BRDF_Diffuse_Lambert( diffuseColor.rgb );\n #ifdef DOUBLE_SIDED\n reflectedLight.directDiffuse = ( gl_FrontFacing ) ? vLightFront : vLightBack;\n #else\n reflectedLight.directDiffuse = vLightFront;\n #endif\n reflectedLight.directDiffuse *= BRDF_Diffuse_Lambert( diffuseColor.rgb ) * getShadowMask();\n #include <aomap_fragment>\n vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n #include <envmap_fragment>\n gl_FragColor = vec4( outgoingLight, diffuseColor.a );\n #include <premultiplied_alpha_fragment>\n #include <tonemapping_fragment>\n #include <encodings_fragment>\n #include <fog_fragment>\n}\n";
  14429. // File:src/renderers/shaders/ShaderLib/meshlambert_vert.glsl
  14430. THREE.ShaderChunk[ 'meshlambert_vert' ] = "#define LAMBERT\nvarying vec3 vLightFront;\n#ifdef DOUBLE_SIDED\n varying vec3 vLightBack;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <envmap_pars_vertex>\n#include <bsdfs>\n#include <lights_pars>\n#include <color_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n #include <uv_vertex>\n #include <uv2_vertex>\n #include <color_vertex>\n #include <beginnormal_vertex>\n #include <morphnormal_vertex>\n #include <skinbase_vertex>\n #include <skinnormal_vertex>\n #include <defaultnormal_vertex>\n #include <begin_vertex>\n #include <morphtarget_vertex>\n #include <skinning_vertex>\n #include <project_vertex>\n #include <logdepthbuf_vertex>\n #include <clipping_planes_vertex>\n #include <worldpos_vertex>\n #include <envmap_vertex>\n #include <lights_lambert_vertex>\n #include <shadowmap_vertex>\n}\n";
  14431. // File:src/renderers/shaders/ShaderLib/meshphong_frag.glsl
  14432. THREE.ShaderChunk[ 'meshphong_frag' ] = "#define PHONG\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform vec3 specular;\nuniform float shininess;\nuniform float opacity;\n#include <common>\n#include <packing>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <envmap_pars_fragment>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars>\n#include <lights_phong_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n #include <clipping_planes_fragment>\n vec4 diffuseColor = vec4( diffuse, opacity );\n ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n vec3 totalEmissiveRadiance = emissive;\n #include <logdepthbuf_fragment>\n #include <map_fragment>\n #include <color_fragment>\n #include <alphamap_fragment>\n #include <alphatest_fragment>\n #include <specularmap_fragment>\n #include <normal_fragment>\n #include <emissivemap_fragment>\n #include <lights_phong_fragment>\n #include <lights_template>\n #include <aomap_fragment>\n vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\n #include <envmap_fragment>\n gl_FragColor = vec4( outgoingLight, diffuseColor.a );\n #include <premultiplied_alpha_fragment>\n #include <tonemapping_fragment>\n #include <encodings_fragment>\n #include <fog_fragment>\n}\n";
  14433. // File:src/renderers/shaders/ShaderLib/meshphong_vert.glsl
  14434. THREE.ShaderChunk[ 'meshphong_vert' ] = "#define PHONG\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n varying vec3 vNormal;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <envmap_pars_vertex>\n#include <color_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n #include <uv_vertex>\n #include <uv2_vertex>\n #include <color_vertex>\n #include <beginnormal_vertex>\n #include <morphnormal_vertex>\n #include <skinbase_vertex>\n #include <skinnormal_vertex>\n #include <defaultnormal_vertex>\n#ifndef FLAT_SHADED\n vNormal = normalize( transformedNormal );\n#endif\n #include <begin_vertex>\n #include <displacementmap_vertex>\n #include <morphtarget_vertex>\n #include <skinning_vertex>\n #include <project_vertex>\n #include <logdepthbuf_vertex>\n #include <clipping_planes_vertex>\n vViewPosition = - mvPosition.xyz;\n #include <worldpos_vertex>\n #include <envmap_vertex>\n #include <shadowmap_vertex>\n}\n";
  14435. // File:src/renderers/shaders/ShaderLib/meshphysical_frag.glsl
  14436. THREE.ShaderChunk[ 'meshphysical_frag' ] = "#define PHYSICAL\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float roughness;\nuniform float metalness;\nuniform float opacity;\nuniform float envMapIntensity;\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n varying vec3 vNormal;\n#endif\n#include <common>\n#include <packing>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <envmap_pars_fragment>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <cube_uv_reflection_fragment>\n#include <lights_pars>\n#include <lights_physical_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <roughnessmap_pars_fragment>\n#include <metalnessmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n #include <clipping_planes_fragment>\n vec4 diffuseColor = vec4( diffuse, opacity );\n ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n vec3 totalEmissiveRadiance = emissive;\n #include <logdepthbuf_fragment>\n #include <map_fragment>\n #include <color_fragment>\n #include <alphamap_fragment>\n #include <alphatest_fragment>\n #include <specularmap_fragment>\n #include <roughnessmap_fragment>\n #include <metalnessmap_fragment>\n #include <normal_fragment>\n #include <emissivemap_fragment>\n #include <lights_physical_fragment>\n #include <lights_template>\n #include <aomap_fragment>\n vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\n gl_FragColor = vec4( outgoingLight, diffuseColor.a );\n #include <premultiplied_alpha_fragment>\n #include <tonemapping_fragment>\n #include <encodings_fragment>\n #include <fog_fragment>\n}\n";
  14437. // File:src/renderers/shaders/ShaderLib/meshphysical_vert.glsl
  14438. THREE.ShaderChunk[ 'meshphysical_vert' ] = "#define PHYSICAL\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n varying vec3 vNormal;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <color_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n #include <uv_vertex>\n #include <uv2_vertex>\n #include <color_vertex>\n #include <beginnormal_vertex>\n #include <morphnormal_vertex>\n #include <skinbase_vertex>\n #include <skinnormal_vertex>\n #include <defaultnormal_vertex>\n#ifndef FLAT_SHADED\n vNormal = normalize( transformedNormal );\n#endif\n #include <begin_vertex>\n #include <displacementmap_vertex>\n #include <morphtarget_vertex>\n #include <skinning_vertex>\n #include <project_vertex>\n #include <logdepthbuf_vertex>\n #include <clipping_planes_vertex>\n vViewPosition = - mvPosition.xyz;\n #include <worldpos_vertex>\n #include <shadowmap_vertex>\n}\n";
  14439. // File:src/renderers/shaders/ShaderLib/normal_frag.glsl
  14440. THREE.ShaderChunk[ 'normal_frag' ] = "uniform float opacity;\nvarying vec3 vNormal;\n#include <common>\n#include <packing>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n #include <clipping_planes_fragment>\n gl_FragColor = vec4( packNormalToRGB( vNormal ), opacity );\n #include <logdepthbuf_fragment>\n}\n";
  14441. // File:src/renderers/shaders/ShaderLib/normal_vert.glsl
  14442. THREE.ShaderChunk[ 'normal_vert' ] = "varying vec3 vNormal;\n#include <common>\n#include <morphtarget_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n vNormal = normalize( normalMatrix * normal );\n #include <begin_vertex>\n #include <morphtarget_vertex>\n #include <project_vertex>\n #include <logdepthbuf_vertex>\n #include <clipping_planes_vertex>\n}\n";
  14443. // File:src/renderers/shaders/ShaderLib/points_frag.glsl
  14444. THREE.ShaderChunk[ 'points_frag' ] = "uniform vec3 diffuse;\nuniform float opacity;\n#include <common>\n#include <color_pars_fragment>\n#include <map_particle_pars_fragment>\n#include <fog_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n #include <clipping_planes_fragment>\n vec3 outgoingLight = vec3( 0.0 );\n vec4 diffuseColor = vec4( diffuse, opacity );\n #include <logdepthbuf_fragment>\n #include <map_particle_fragment>\n #include <color_fragment>\n #include <alphatest_fragment>\n outgoingLight = diffuseColor.rgb;\n gl_FragColor = vec4( outgoingLight, diffuseColor.a );\n #include <premultiplied_alpha_fragment>\n #include <tonemapping_fragment>\n #include <encodings_fragment>\n #include <fog_fragment>\n}\n";
  14445. // File:src/renderers/shaders/ShaderLib/points_vert.glsl
  14446. THREE.ShaderChunk[ 'points_vert' ] = "uniform float size;\nuniform float scale;\n#include <common>\n#include <color_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n #include <color_vertex>\n #include <begin_vertex>\n #include <project_vertex>\n #ifdef USE_SIZEATTENUATION\n gl_PointSize = size * ( scale / - mvPosition.z );\n #else\n gl_PointSize = size;\n #endif\n #include <logdepthbuf_vertex>\n #include <clipping_planes_vertex>\n #include <worldpos_vertex>\n #include <shadowmap_vertex>\n}\n";
  14447. // File:src/renderers/shaders/ShaderLib.js
  14448. /**
  14449. * Webgl Shader Library for three.js
  14450. *
  14451. * @author alteredq / http://alteredqualia.com/
  14452. * @author mrdoob / http://mrdoob.com/
  14453. * @author mikael emtinger / http://gomo.se/
  14454. */
  14455. THREE.ShaderLib = {
  14456. 'basic': {
  14457. uniforms: THREE.UniformsUtils.merge( [
  14458. THREE.UniformsLib[ 'common' ],
  14459. THREE.UniformsLib[ 'aomap' ],
  14460. THREE.UniformsLib[ 'fog' ]
  14461. ] ),
  14462. vertexShader: THREE.ShaderChunk[ 'meshbasic_vert' ],
  14463. fragmentShader: THREE.ShaderChunk[ 'meshbasic_frag' ]
  14464. },
  14465. 'lambert': {
  14466. uniforms: THREE.UniformsUtils.merge( [
  14467. THREE.UniformsLib[ 'common' ],
  14468. THREE.UniformsLib[ 'aomap' ],
  14469. THREE.UniformsLib[ 'lightmap' ],
  14470. THREE.UniformsLib[ 'emissivemap' ],
  14471. THREE.UniformsLib[ 'fog' ],
  14472. THREE.UniformsLib[ 'lights' ],
  14473. {
  14474. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) }
  14475. }
  14476. ] ),
  14477. vertexShader: THREE.ShaderChunk[ 'meshlambert_vert' ],
  14478. fragmentShader: THREE.ShaderChunk[ 'meshlambert_frag' ]
  14479. },
  14480. 'phong': {
  14481. uniforms: THREE.UniformsUtils.merge( [
  14482. THREE.UniformsLib[ 'common' ],
  14483. THREE.UniformsLib[ 'aomap' ],
  14484. THREE.UniformsLib[ 'lightmap' ],
  14485. THREE.UniformsLib[ 'emissivemap' ],
  14486. THREE.UniformsLib[ 'bumpmap' ],
  14487. THREE.UniformsLib[ 'normalmap' ],
  14488. THREE.UniformsLib[ 'displacementmap' ],
  14489. THREE.UniformsLib[ 'fog' ],
  14490. THREE.UniformsLib[ 'lights' ],
  14491. {
  14492. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) },
  14493. "specular" : { type: "c", value: new THREE.Color( 0x111111 ) },
  14494. "shininess": { type: "1f", value: 30 }
  14495. }
  14496. ] ),
  14497. vertexShader: THREE.ShaderChunk[ 'meshphong_vert' ],
  14498. fragmentShader: THREE.ShaderChunk[ 'meshphong_frag' ]
  14499. },
  14500. 'standard': {
  14501. uniforms: THREE.UniformsUtils.merge( [
  14502. THREE.UniformsLib[ 'common' ],
  14503. THREE.UniformsLib[ 'aomap' ],
  14504. THREE.UniformsLib[ 'lightmap' ],
  14505. THREE.UniformsLib[ 'emissivemap' ],
  14506. THREE.UniformsLib[ 'bumpmap' ],
  14507. THREE.UniformsLib[ 'normalmap' ],
  14508. THREE.UniformsLib[ 'displacementmap' ],
  14509. THREE.UniformsLib[ 'roughnessmap' ],
  14510. THREE.UniformsLib[ 'metalnessmap' ],
  14511. THREE.UniformsLib[ 'fog' ],
  14512. THREE.UniformsLib[ 'lights' ],
  14513. {
  14514. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) },
  14515. "roughness": { type: "1f", value: 0.5 },
  14516. "metalness": { type: "1f", value: 0 },
  14517. "envMapIntensity" : { type: "1f", value: 1 } // temporary
  14518. }
  14519. ] ),
  14520. vertexShader: THREE.ShaderChunk[ 'meshphysical_vert' ],
  14521. fragmentShader: THREE.ShaderChunk[ 'meshphysical_frag' ]
  14522. },
  14523. 'points': {
  14524. uniforms: THREE.UniformsUtils.merge( [
  14525. THREE.UniformsLib[ 'points' ],
  14526. THREE.UniformsLib[ 'fog' ]
  14527. ] ),
  14528. vertexShader: THREE.ShaderChunk[ 'points_vert' ],
  14529. fragmentShader: THREE.ShaderChunk[ 'points_frag' ]
  14530. },
  14531. 'dashed': {
  14532. uniforms: THREE.UniformsUtils.merge( [
  14533. THREE.UniformsLib[ 'common' ],
  14534. THREE.UniformsLib[ 'fog' ],
  14535. {
  14536. "scale" : { type: "1f", value: 1 },
  14537. "dashSize" : { type: "1f", value: 1 },
  14538. "totalSize": { type: "1f", value: 2 }
  14539. }
  14540. ] ),
  14541. vertexShader: THREE.ShaderChunk[ 'linedashed_vert' ],
  14542. fragmentShader: THREE.ShaderChunk[ 'linedashed_frag' ]
  14543. },
  14544. 'depth': {
  14545. uniforms: THREE.UniformsUtils.merge( [
  14546. THREE.UniformsLib[ 'common' ],
  14547. THREE.UniformsLib[ 'displacementmap' ]
  14548. ] ),
  14549. vertexShader: THREE.ShaderChunk[ 'depth_vert' ],
  14550. fragmentShader: THREE.ShaderChunk[ 'depth_frag' ]
  14551. },
  14552. 'normal': {
  14553. uniforms: {
  14554. "opacity" : { type: "1f", value: 1.0 }
  14555. },
  14556. vertexShader: THREE.ShaderChunk[ 'normal_vert' ],
  14557. fragmentShader: THREE.ShaderChunk[ 'normal_frag' ]
  14558. },
  14559. /* -------------------------------------------------------------------------
  14560. // Cube map shader
  14561. ------------------------------------------------------------------------- */
  14562. 'cube': {
  14563. uniforms: {
  14564. "tCube": { type: "t", value: null },
  14565. "tFlip": { type: "1f", value: - 1 }
  14566. },
  14567. vertexShader: THREE.ShaderChunk[ 'cube_vert' ],
  14568. fragmentShader: THREE.ShaderChunk[ 'cube_frag' ]
  14569. },
  14570. /* -------------------------------------------------------------------------
  14571. // Cube map shader
  14572. ------------------------------------------------------------------------- */
  14573. 'equirect': {
  14574. uniforms: {
  14575. "tEquirect": { type: "t", value: null },
  14576. "tFlip": { type: "1f", value: - 1 }
  14577. },
  14578. vertexShader: THREE.ShaderChunk[ 'equirect_vert' ],
  14579. fragmentShader: THREE.ShaderChunk[ 'equirect_frag' ]
  14580. },
  14581. 'distanceRGBA': {
  14582. uniforms: {
  14583. "lightPos": { type: "v3", value: new THREE.Vector3() }
  14584. },
  14585. vertexShader: THREE.ShaderChunk[ 'distanceRGBA_vert' ],
  14586. fragmentShader: THREE.ShaderChunk[ 'distanceRGBA_frag' ]
  14587. }
  14588. };
  14589. THREE.ShaderLib[ 'physical' ] = {
  14590. uniforms: THREE.UniformsUtils.merge( [
  14591. THREE.ShaderLib[ 'standard' ].uniforms,
  14592. {
  14593. // future
  14594. }
  14595. ] ),
  14596. vertexShader: THREE.ShaderChunk[ 'meshphysical_vert' ],
  14597. fragmentShader: THREE.ShaderChunk[ 'meshphysical_frag' ]
  14598. };
  14599. // File:src/renderers/WebGLRenderer.js
  14600. /**
  14601. * @author supereggbert / http://www.paulbrunt.co.uk/
  14602. * @author mrdoob / http://mrdoob.com/
  14603. * @author alteredq / http://alteredqualia.com/
  14604. * @author szimek / https://github.com/szimek/
  14605. * @author tschw
  14606. */
  14607. THREE.WebGLRenderer = function ( parameters ) {
  14608. console.log( 'THREE.WebGLRenderer', THREE.REVISION );
  14609. parameters = parameters || {};
  14610. var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElement( 'canvas' ),
  14611. _context = parameters.context !== undefined ? parameters.context : null,
  14612. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  14613. _depth = parameters.depth !== undefined ? parameters.depth : true,
  14614. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  14615. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  14616. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  14617. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false;
  14618. var lights = [];
  14619. var opaqueObjects = [];
  14620. var opaqueObjectsLastIndex = - 1;
  14621. var transparentObjects = [];
  14622. var transparentObjectsLastIndex = - 1;
  14623. var morphInfluences = new Float32Array( 8 );
  14624. var sprites = [];
  14625. var lensFlares = [];
  14626. // public properties
  14627. this.domElement = _canvas;
  14628. this.context = null;
  14629. // clearing
  14630. this.autoClear = true;
  14631. this.autoClearColor = true;
  14632. this.autoClearDepth = true;
  14633. this.autoClearStencil = true;
  14634. // scene graph
  14635. this.sortObjects = true;
  14636. // user-defined clipping
  14637. this.clippingPlanes = [];
  14638. this.localClippingEnabled = false;
  14639. // physically based shading
  14640. this.gammaFactor = 2.0; // for backwards compatibility
  14641. this.gammaInput = false;
  14642. this.gammaOutput = false;
  14643. // physical lights
  14644. this.physicallyCorrectLights = false;
  14645. // tone mapping
  14646. this.toneMapping = THREE.LinearToneMapping;
  14647. this.toneMappingExposure = 1.0;
  14648. this.toneMappingWhitePoint = 1.0;
  14649. // morphs
  14650. this.maxMorphTargets = 8;
  14651. this.maxMorphNormals = 4;
  14652. // flags
  14653. this.autoScaleCubemaps = true;
  14654. // internal properties
  14655. var _this = this,
  14656. // internal state cache
  14657. _currentProgram = null,
  14658. _currentRenderTarget = null,
  14659. _currentFramebuffer = null,
  14660. _currentMaterialId = - 1,
  14661. _currentGeometryProgram = '',
  14662. _currentCamera = null,
  14663. _currentScissor = new THREE.Vector4(),
  14664. _currentScissorTest = null,
  14665. _currentViewport = new THREE.Vector4(),
  14666. //
  14667. _usedTextureUnits = 0,
  14668. //
  14669. _clearColor = new THREE.Color( 0x000000 ),
  14670. _clearAlpha = 0,
  14671. _width = _canvas.width,
  14672. _height = _canvas.height,
  14673. _pixelRatio = 1,
  14674. _scissor = new THREE.Vector4( 0, 0, _width, _height ),
  14675. _scissorTest = false,
  14676. _viewport = new THREE.Vector4( 0, 0, _width, _height ),
  14677. // frustum
  14678. _frustum = new THREE.Frustum(),
  14679. // clipping
  14680. _clippingEnabled = false,
  14681. _localClippingEnabled = false,
  14682. _clipRenderingShadows = false,
  14683. _numClippingPlanes = 0,
  14684. _clippingPlanesUniform = {
  14685. type: '4fv', value: null, needsUpdate: false },
  14686. _globalClippingState = null,
  14687. _numGlobalClippingPlanes = 0,
  14688. _matrix3 = new THREE.Matrix3(),
  14689. _sphere = new THREE.Sphere(),
  14690. _plane = new THREE.Plane(),
  14691. // camera matrices cache
  14692. _projScreenMatrix = new THREE.Matrix4(),
  14693. _vector3 = new THREE.Vector3(),
  14694. // light arrays cache
  14695. _lights = {
  14696. hash: '',
  14697. ambient: [ 0, 0, 0 ],
  14698. directional: [],
  14699. directionalShadowMap: [],
  14700. directionalShadowMatrix: [],
  14701. spot: [],
  14702. spotShadowMap: [],
  14703. spotShadowMatrix: [],
  14704. point: [],
  14705. pointShadowMap: [],
  14706. pointShadowMatrix: [],
  14707. hemi: [],
  14708. shadows: []
  14709. },
  14710. // info
  14711. _infoMemory = {
  14712. geometries: 0,
  14713. textures: 0
  14714. },
  14715. _infoRender = {
  14716. calls: 0,
  14717. vertices: 0,
  14718. faces: 0,
  14719. points: 0
  14720. };
  14721. this.info = {
  14722. render: _infoRender,
  14723. memory: _infoMemory,
  14724. programs: null
  14725. };
  14726. // initialize
  14727. var _gl;
  14728. try {
  14729. var attributes = {
  14730. alpha: _alpha,
  14731. depth: _depth,
  14732. stencil: _stencil,
  14733. antialias: _antialias,
  14734. premultipliedAlpha: _premultipliedAlpha,
  14735. preserveDrawingBuffer: _preserveDrawingBuffer
  14736. };
  14737. _gl = _context || _canvas.getContext( 'webgl', attributes ) || _canvas.getContext( 'experimental-webgl', attributes );
  14738. if ( _gl === null ) {
  14739. if ( _canvas.getContext( 'webgl' ) !== null ) {
  14740. throw 'Error creating WebGL context with your selected attributes.';
  14741. } else {
  14742. throw 'Error creating WebGL context.';
  14743. }
  14744. }
  14745. // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  14746. if ( _gl.getShaderPrecisionFormat === undefined ) {
  14747. _gl.getShaderPrecisionFormat = function () {
  14748. return { 'rangeMin': 1, 'rangeMax': 1, 'precision': 1 };
  14749. };
  14750. }
  14751. _canvas.addEventListener( 'webglcontextlost', onContextLost, false );
  14752. } catch ( error ) {
  14753. console.error( 'THREE.WebGLRenderer: ' + error );
  14754. }
  14755. var _isWebGL2 = (typeof WebGL2RenderingContext !== 'undefined' && _gl instanceof WebGL2RenderingContext);
  14756. var extensions = new THREE.WebGLExtensions( _gl );
  14757. extensions.get( 'WEBGL_depth_texture' );
  14758. extensions.get( 'OES_texture_float' );
  14759. extensions.get( 'OES_texture_float_linear' );
  14760. extensions.get( 'OES_texture_half_float' );
  14761. extensions.get( 'OES_texture_half_float_linear' );
  14762. extensions.get( 'OES_standard_derivatives' );
  14763. extensions.get( 'ANGLE_instanced_arrays' );
  14764. if ( extensions.get( 'OES_element_index_uint' ) ) {
  14765. THREE.BufferGeometry.MaxIndex = 4294967296;
  14766. }
  14767. var capabilities = new THREE.WebGLCapabilities( _gl, extensions, parameters );
  14768. var state = new THREE.WebGLState( _gl, extensions, paramThreeToGL );
  14769. var properties = new THREE.WebGLProperties();
  14770. var objects = new THREE.WebGLObjects( _gl, properties, this.info );
  14771. var programCache = new THREE.WebGLPrograms( this, capabilities );
  14772. var lightCache = new THREE.WebGLLights();
  14773. this.info.programs = programCache.programs;
  14774. var bufferRenderer = new THREE.WebGLBufferRenderer( _gl, extensions, _infoRender );
  14775. var indexedBufferRenderer = new THREE.WebGLIndexedBufferRenderer( _gl, extensions, _infoRender );
  14776. //
  14777. function getTargetPixelRatio() {
  14778. return _currentRenderTarget === null ? _pixelRatio : 1;
  14779. }
  14780. function glClearColor( r, g, b, a ) {
  14781. if ( _premultipliedAlpha === true ) {
  14782. r *= a; g *= a; b *= a;
  14783. }
  14784. state.clearColor( r, g, b, a );
  14785. }
  14786. function setDefaultGLState() {
  14787. state.init();
  14788. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ) );
  14789. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ) );
  14790. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  14791. }
  14792. function resetGLState() {
  14793. _currentProgram = null;
  14794. _currentCamera = null;
  14795. _currentGeometryProgram = '';
  14796. _currentMaterialId = - 1;
  14797. state.reset();
  14798. }
  14799. setDefaultGLState();
  14800. this.context = _gl;
  14801. this.capabilities = capabilities;
  14802. this.extensions = extensions;
  14803. this.properties = properties;
  14804. this.state = state;
  14805. // shadow map
  14806. var shadowMap = new THREE.WebGLShadowMap( this, _lights, objects );
  14807. this.shadowMap = shadowMap;
  14808. // Plugins
  14809. var spritePlugin = new THREE.SpritePlugin( this, sprites );
  14810. var lensFlarePlugin = new THREE.LensFlarePlugin( this, lensFlares );
  14811. // API
  14812. this.getContext = function () {
  14813. return _gl;
  14814. };
  14815. this.getContextAttributes = function () {
  14816. return _gl.getContextAttributes();
  14817. };
  14818. this.forceContextLoss = function () {
  14819. extensions.get( 'WEBGL_lose_context' ).loseContext();
  14820. };
  14821. this.getMaxAnisotropy = ( function () {
  14822. var value;
  14823. return function getMaxAnisotropy() {
  14824. if ( value !== undefined ) return value;
  14825. var extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  14826. if ( extension !== null ) {
  14827. value = _gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );
  14828. } else {
  14829. value = 0;
  14830. }
  14831. return value;
  14832. };
  14833. } )();
  14834. this.getPrecision = function () {
  14835. return capabilities.precision;
  14836. };
  14837. this.getPixelRatio = function () {
  14838. return _pixelRatio;
  14839. };
  14840. this.setPixelRatio = function ( value ) {
  14841. if ( value === undefined ) return;
  14842. _pixelRatio = value;
  14843. this.setSize( _viewport.z, _viewport.w, false );
  14844. };
  14845. this.getSize = function () {
  14846. return {
  14847. width: _width,
  14848. height: _height
  14849. };
  14850. };
  14851. this.setSize = function ( width, height, updateStyle ) {
  14852. _width = width;
  14853. _height = height;
  14854. _canvas.width = width * _pixelRatio;
  14855. _canvas.height = height * _pixelRatio;
  14856. if ( updateStyle !== false ) {
  14857. _canvas.style.width = width + 'px';
  14858. _canvas.style.height = height + 'px';
  14859. }
  14860. this.setViewport( 0, 0, width, height );
  14861. };
  14862. this.setViewport = function ( x, y, width, height ) {
  14863. state.viewport( _viewport.set( x, y, width, height ) );
  14864. };
  14865. this.setScissor = function ( x, y, width, height ) {
  14866. state.scissor( _scissor.set( x, y, width, height ) );
  14867. };
  14868. this.setScissorTest = function ( boolean ) {
  14869. state.setScissorTest( _scissorTest = boolean );
  14870. };
  14871. // Clearing
  14872. this.getClearColor = function () {
  14873. return _clearColor;
  14874. };
  14875. this.setClearColor = function ( color, alpha ) {
  14876. _clearColor.set( color );
  14877. _clearAlpha = alpha !== undefined ? alpha : 1;
  14878. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  14879. };
  14880. this.getClearAlpha = function () {
  14881. return _clearAlpha;
  14882. };
  14883. this.setClearAlpha = function ( alpha ) {
  14884. _clearAlpha = alpha;
  14885. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  14886. };
  14887. this.clear = function ( color, depth, stencil ) {
  14888. var bits = 0;
  14889. if ( color === undefined || color ) bits |= _gl.COLOR_BUFFER_BIT;
  14890. if ( depth === undefined || depth ) bits |= _gl.DEPTH_BUFFER_BIT;
  14891. if ( stencil === undefined || stencil ) bits |= _gl.STENCIL_BUFFER_BIT;
  14892. _gl.clear( bits );
  14893. };
  14894. this.clearColor = function () {
  14895. this.clear( true, false, false );
  14896. };
  14897. this.clearDepth = function () {
  14898. this.clear( false, true, false );
  14899. };
  14900. this.clearStencil = function () {
  14901. this.clear( false, false, true );
  14902. };
  14903. this.clearTarget = function ( renderTarget, color, depth, stencil ) {
  14904. this.setRenderTarget( renderTarget );
  14905. this.clear( color, depth, stencil );
  14906. };
  14907. // Reset
  14908. this.resetGLState = resetGLState;
  14909. this.dispose = function() {
  14910. _canvas.removeEventListener( 'webglcontextlost', onContextLost, false );
  14911. };
  14912. // Events
  14913. function onContextLost( event ) {
  14914. event.preventDefault();
  14915. resetGLState();
  14916. setDefaultGLState();
  14917. properties.clear();
  14918. }
  14919. function onTextureDispose( event ) {
  14920. var texture = event.target;
  14921. texture.removeEventListener( 'dispose', onTextureDispose );
  14922. deallocateTexture( texture );
  14923. _infoMemory.textures --;
  14924. }
  14925. function onRenderTargetDispose( event ) {
  14926. var renderTarget = event.target;
  14927. renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
  14928. deallocateRenderTarget( renderTarget );
  14929. _infoMemory.textures --;
  14930. }
  14931. function onMaterialDispose( event ) {
  14932. var material = event.target;
  14933. material.removeEventListener( 'dispose', onMaterialDispose );
  14934. deallocateMaterial( material );
  14935. }
  14936. // Buffer deallocation
  14937. function deallocateTexture( texture ) {
  14938. var textureProperties = properties.get( texture );
  14939. if ( texture.image && textureProperties.__image__webglTextureCube ) {
  14940. // cube texture
  14941. _gl.deleteTexture( textureProperties.__image__webglTextureCube );
  14942. } else {
  14943. // 2D texture
  14944. if ( textureProperties.__webglInit === undefined ) return;
  14945. _gl.deleteTexture( textureProperties.__webglTexture );
  14946. }
  14947. // remove all webgl properties
  14948. properties.delete( texture );
  14949. }
  14950. function deallocateRenderTarget( renderTarget ) {
  14951. var renderTargetProperties = properties.get( renderTarget );
  14952. var textureProperties = properties.get( renderTarget.texture );
  14953. if ( ! renderTarget ) return;
  14954. if ( textureProperties.__webglTexture !== undefined ) {
  14955. _gl.deleteTexture( textureProperties.__webglTexture );
  14956. }
  14957. if ( renderTarget.depthTexture ) {
  14958. renderTarget.depthTexture.dispose();
  14959. }
  14960. if ( renderTarget instanceof THREE.WebGLRenderTargetCube ) {
  14961. for ( var i = 0; i < 6; i ++ ) {
  14962. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] );
  14963. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer[ i ] );
  14964. }
  14965. } else {
  14966. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer );
  14967. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer );
  14968. }
  14969. properties.delete( renderTarget.texture );
  14970. properties.delete( renderTarget );
  14971. }
  14972. function deallocateMaterial( material ) {
  14973. releaseMaterialProgramReference( material );
  14974. properties.delete( material );
  14975. }
  14976. function releaseMaterialProgramReference( material ) {
  14977. var programInfo = properties.get( material ).program;
  14978. material.program = undefined;
  14979. if ( programInfo !== undefined ) {
  14980. programCache.releaseProgram( programInfo );
  14981. }
  14982. }
  14983. // Buffer rendering
  14984. this.renderBufferImmediate = function ( object, program, material ) {
  14985. state.initAttributes();
  14986. var buffers = properties.get( object );
  14987. if ( object.hasPositions && ! buffers.position ) buffers.position = _gl.createBuffer();
  14988. if ( object.hasNormals && ! buffers.normal ) buffers.normal = _gl.createBuffer();
  14989. if ( object.hasUvs && ! buffers.uv ) buffers.uv = _gl.createBuffer();
  14990. if ( object.hasColors && ! buffers.color ) buffers.color = _gl.createBuffer();
  14991. var attributes = program.getAttributes();
  14992. if ( object.hasPositions ) {
  14993. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.position );
  14994. _gl.bufferData( _gl.ARRAY_BUFFER, object.positionArray, _gl.DYNAMIC_DRAW );
  14995. state.enableAttribute( attributes.position );
  14996. _gl.vertexAttribPointer( attributes.position, 3, _gl.FLOAT, false, 0, 0 );
  14997. }
  14998. if ( object.hasNormals ) {
  14999. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.normal );
  15000. if ( material.type !== 'MeshPhongMaterial' && material.type !== 'MeshStandardMaterial' && material.type !== 'MeshPhysicalMaterial' && material.shading === THREE.FlatShading ) {
  15001. for ( var i = 0, l = object.count * 3; i < l; i += 9 ) {
  15002. var array = object.normalArray;
  15003. var nx = ( array[ i + 0 ] + array[ i + 3 ] + array[ i + 6 ] ) / 3;
  15004. var ny = ( array[ i + 1 ] + array[ i + 4 ] + array[ i + 7 ] ) / 3;
  15005. var nz = ( array[ i + 2 ] + array[ i + 5 ] + array[ i + 8 ] ) / 3;
  15006. array[ i + 0 ] = nx;
  15007. array[ i + 1 ] = ny;
  15008. array[ i + 2 ] = nz;
  15009. array[ i + 3 ] = nx;
  15010. array[ i + 4 ] = ny;
  15011. array[ i + 5 ] = nz;
  15012. array[ i + 6 ] = nx;
  15013. array[ i + 7 ] = ny;
  15014. array[ i + 8 ] = nz;
  15015. }
  15016. }
  15017. _gl.bufferData( _gl.ARRAY_BUFFER, object.normalArray, _gl.DYNAMIC_DRAW );
  15018. state.enableAttribute( attributes.normal );
  15019. _gl.vertexAttribPointer( attributes.normal, 3, _gl.FLOAT, false, 0, 0 );
  15020. }
  15021. if ( object.hasUvs && material.map ) {
  15022. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.uv );
  15023. _gl.bufferData( _gl.ARRAY_BUFFER, object.uvArray, _gl.DYNAMIC_DRAW );
  15024. state.enableAttribute( attributes.uv );
  15025. _gl.vertexAttribPointer( attributes.uv, 2, _gl.FLOAT, false, 0, 0 );
  15026. }
  15027. if ( object.hasColors && material.vertexColors !== THREE.NoColors ) {
  15028. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.color );
  15029. _gl.bufferData( _gl.ARRAY_BUFFER, object.colorArray, _gl.DYNAMIC_DRAW );
  15030. state.enableAttribute( attributes.color );
  15031. _gl.vertexAttribPointer( attributes.color, 3, _gl.FLOAT, false, 0, 0 );
  15032. }
  15033. state.disableUnusedAttributes();
  15034. _gl.drawArrays( _gl.TRIANGLES, 0, object.count );
  15035. object.count = 0;
  15036. };
  15037. this.renderBufferDirect = function ( camera, fog, geometry, material, object, group ) {
  15038. setMaterial( material );
  15039. var program = setProgram( camera, fog, material, object );
  15040. var updateBuffers = false;
  15041. var geometryProgram = geometry.id + '_' + program.id + '_' + material.wireframe;
  15042. if ( geometryProgram !== _currentGeometryProgram ) {
  15043. _currentGeometryProgram = geometryProgram;
  15044. updateBuffers = true;
  15045. }
  15046. // morph targets
  15047. var morphTargetInfluences = object.morphTargetInfluences;
  15048. if ( morphTargetInfluences !== undefined ) {
  15049. var activeInfluences = [];
  15050. for ( var i = 0, l = morphTargetInfluences.length; i < l; i ++ ) {
  15051. var influence = morphTargetInfluences[ i ];
  15052. activeInfluences.push( [ influence, i ] );
  15053. }
  15054. activeInfluences.sort( absNumericalSort );
  15055. if ( activeInfluences.length > 8 ) {
  15056. activeInfluences.length = 8;
  15057. }
  15058. var morphAttributes = geometry.morphAttributes;
  15059. for ( var i = 0, l = activeInfluences.length; i < l; i ++ ) {
  15060. var influence = activeInfluences[ i ];
  15061. morphInfluences[ i ] = influence[ 0 ];
  15062. if ( influence[ 0 ] !== 0 ) {
  15063. var index = influence[ 1 ];
  15064. if ( material.morphTargets === true && morphAttributes.position ) geometry.addAttribute( 'morphTarget' + i, morphAttributes.position[ index ] );
  15065. if ( material.morphNormals === true && morphAttributes.normal ) geometry.addAttribute( 'morphNormal' + i, morphAttributes.normal[ index ] );
  15066. } else {
  15067. if ( material.morphTargets === true ) geometry.removeAttribute( 'morphTarget' + i );
  15068. if ( material.morphNormals === true ) geometry.removeAttribute( 'morphNormal' + i );
  15069. }
  15070. }
  15071. program.getUniforms().setValue(
  15072. _gl, 'morphTargetInfluences', morphInfluences );
  15073. updateBuffers = true;
  15074. }
  15075. //
  15076. var index = geometry.index;
  15077. var position = geometry.attributes.position;
  15078. if ( material.wireframe === true ) {
  15079. index = objects.getWireframeAttribute( geometry );
  15080. }
  15081. var renderer;
  15082. if ( index !== null ) {
  15083. renderer = indexedBufferRenderer;
  15084. renderer.setIndex( index );
  15085. } else {
  15086. renderer = bufferRenderer;
  15087. }
  15088. if ( updateBuffers ) {
  15089. setupVertexAttributes( material, program, geometry );
  15090. if ( index !== null ) {
  15091. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, objects.getAttributeBuffer( index ) );
  15092. }
  15093. }
  15094. //
  15095. var dataStart = 0;
  15096. var dataCount = Infinity;
  15097. if ( index !== null ) {
  15098. dataCount = index.count;
  15099. } else if ( position !== undefined ) {
  15100. dataCount = position.count;
  15101. }
  15102. var rangeStart = geometry.drawRange.start;
  15103. var rangeCount = geometry.drawRange.count;
  15104. var groupStart = group !== null ? group.start : 0;
  15105. var groupCount = group !== null ? group.count : Infinity;
  15106. var drawStart = Math.max( dataStart, rangeStart, groupStart );
  15107. var drawEnd = Math.min( dataStart + dataCount, rangeStart + rangeCount, groupStart + groupCount ) - 1;
  15108. var drawCount = Math.max( 0, drawEnd - drawStart + 1 );
  15109. //
  15110. if ( object instanceof THREE.Mesh ) {
  15111. if ( material.wireframe === true ) {
  15112. state.setLineWidth( material.wireframeLinewidth * getTargetPixelRatio() );
  15113. renderer.setMode( _gl.LINES );
  15114. } else {
  15115. switch ( object.drawMode ) {
  15116. case THREE.TrianglesDrawMode:
  15117. renderer.setMode( _gl.TRIANGLES );
  15118. break;
  15119. case THREE.TriangleStripDrawMode:
  15120. renderer.setMode( _gl.TRIANGLE_STRIP );
  15121. break;
  15122. case THREE.TriangleFanDrawMode:
  15123. renderer.setMode( _gl.TRIANGLE_FAN );
  15124. break;
  15125. }
  15126. }
  15127. } else if ( object instanceof THREE.Line ) {
  15128. var lineWidth = material.linewidth;
  15129. if ( lineWidth === undefined ) lineWidth = 1; // Not using Line*Material
  15130. state.setLineWidth( lineWidth * getTargetPixelRatio() );
  15131. if ( object instanceof THREE.LineSegments ) {
  15132. renderer.setMode( _gl.LINES );
  15133. } else {
  15134. renderer.setMode( _gl.LINE_STRIP );
  15135. }
  15136. } else if ( object instanceof THREE.Points ) {
  15137. renderer.setMode( _gl.POINTS );
  15138. }
  15139. if ( geometry instanceof THREE.InstancedBufferGeometry ) {
  15140. if ( geometry.maxInstancedCount > 0 ) {
  15141. renderer.renderInstances( geometry, drawStart, drawCount );
  15142. }
  15143. } else {
  15144. renderer.render( drawStart, drawCount );
  15145. }
  15146. };
  15147. function setupVertexAttributes( material, program, geometry, startIndex ) {
  15148. var extension;
  15149. if ( geometry instanceof THREE.InstancedBufferGeometry ) {
  15150. extension = extensions.get( 'ANGLE_instanced_arrays' );
  15151. if ( extension === null ) {
  15152. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  15153. return;
  15154. }
  15155. }
  15156. if ( startIndex === undefined ) startIndex = 0;
  15157. state.initAttributes();
  15158. var geometryAttributes = geometry.attributes;
  15159. var programAttributes = program.getAttributes();
  15160. var materialDefaultAttributeValues = material.defaultAttributeValues;
  15161. for ( var name in programAttributes ) {
  15162. var programAttribute = programAttributes[ name ];
  15163. if ( programAttribute >= 0 ) {
  15164. var geometryAttribute = geometryAttributes[ name ];
  15165. if ( geometryAttribute !== undefined ) {
  15166. var type = _gl.FLOAT;
  15167. var array = geometryAttribute.array;
  15168. var normalized = geometryAttribute.normalized;
  15169. if ( array instanceof Float32Array ) {
  15170. type = _gl.FLOAT;
  15171. } else if ( array instanceof Float64Array ) {
  15172. console.warn("Unsupported data buffer format: Float64Array");
  15173. } else if ( array instanceof Uint16Array ) {
  15174. type = _gl.UNSIGNED_SHORT;
  15175. } else if ( array instanceof Int16Array ) {
  15176. type = _gl.SHORT;
  15177. } else if ( array instanceof Uint32Array ) {
  15178. type = _gl.UNSIGNED_INT;
  15179. } else if ( array instanceof Int32Array ) {
  15180. type = _gl.INT;
  15181. } else if ( array instanceof Int8Array ) {
  15182. type = _gl.BYTE;
  15183. } else if ( array instanceof Uint8Array ) {
  15184. type = _gl.UNSIGNED_BYTE;
  15185. }
  15186. var size = geometryAttribute.itemSize;
  15187. var buffer = objects.getAttributeBuffer( geometryAttribute );
  15188. if ( geometryAttribute instanceof THREE.InterleavedBufferAttribute ) {
  15189. var data = geometryAttribute.data;
  15190. var stride = data.stride;
  15191. var offset = geometryAttribute.offset;
  15192. if ( data instanceof THREE.InstancedInterleavedBuffer ) {
  15193. state.enableAttributeAndDivisor( programAttribute, data.meshPerAttribute, extension );
  15194. if ( geometry.maxInstancedCount === undefined ) {
  15195. geometry.maxInstancedCount = data.meshPerAttribute * data.count;
  15196. }
  15197. } else {
  15198. state.enableAttribute( programAttribute );
  15199. }
  15200. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  15201. _gl.vertexAttribPointer( programAttribute, size, type, normalized, stride * data.array.BYTES_PER_ELEMENT, ( startIndex * stride + offset ) * data.array.BYTES_PER_ELEMENT );
  15202. } else {
  15203. if ( geometryAttribute instanceof THREE.InstancedBufferAttribute ) {
  15204. state.enableAttributeAndDivisor( programAttribute, geometryAttribute.meshPerAttribute, extension );
  15205. if ( geometry.maxInstancedCount === undefined ) {
  15206. geometry.maxInstancedCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  15207. }
  15208. } else {
  15209. state.enableAttribute( programAttribute );
  15210. }
  15211. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  15212. _gl.vertexAttribPointer( programAttribute, size, type, normalized, 0, startIndex * size * geometryAttribute.array.BYTES_PER_ELEMENT );
  15213. }
  15214. } else if ( materialDefaultAttributeValues !== undefined ) {
  15215. var value = materialDefaultAttributeValues[ name ];
  15216. if ( value !== undefined ) {
  15217. switch ( value.length ) {
  15218. case 2:
  15219. _gl.vertexAttrib2fv( programAttribute, value );
  15220. break;
  15221. case 3:
  15222. _gl.vertexAttrib3fv( programAttribute, value );
  15223. break;
  15224. case 4:
  15225. _gl.vertexAttrib4fv( programAttribute, value );
  15226. break;
  15227. default:
  15228. _gl.vertexAttrib1fv( programAttribute, value );
  15229. }
  15230. }
  15231. }
  15232. }
  15233. }
  15234. state.disableUnusedAttributes();
  15235. }
  15236. // Sorting
  15237. function absNumericalSort( a, b ) {
  15238. return Math.abs( b[ 0 ] ) - Math.abs( a[ 0 ] );
  15239. }
  15240. function painterSortStable ( a, b ) {
  15241. if ( a.object.renderOrder !== b.object.renderOrder ) {
  15242. return a.object.renderOrder - b.object.renderOrder;
  15243. } else if ( a.material.id !== b.material.id ) {
  15244. return a.material.id - b.material.id;
  15245. } else if ( a.z !== b.z ) {
  15246. return a.z - b.z;
  15247. } else {
  15248. return a.id - b.id;
  15249. }
  15250. }
  15251. function reversePainterSortStable ( a, b ) {
  15252. if ( a.object.renderOrder !== b.object.renderOrder ) {
  15253. return a.object.renderOrder - b.object.renderOrder;
  15254. } if ( a.z !== b.z ) {
  15255. return b.z - a.z;
  15256. } else {
  15257. return a.id - b.id;
  15258. }
  15259. }
  15260. // Rendering
  15261. this.render = function ( scene, camera, renderTarget, forceClear ) {
  15262. if ( camera instanceof THREE.Camera === false ) {
  15263. console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
  15264. return;
  15265. }
  15266. var fog = scene.fog;
  15267. // reset caching for this frame
  15268. _currentGeometryProgram = '';
  15269. _currentMaterialId = - 1;
  15270. _currentCamera = null;
  15271. // update scene graph
  15272. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  15273. // update camera matrices and frustum
  15274. if ( camera.parent === null ) camera.updateMatrixWorld();
  15275. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  15276. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  15277. _frustum.setFromMatrix( _projScreenMatrix );
  15278. lights.length = 0;
  15279. opaqueObjectsLastIndex = - 1;
  15280. transparentObjectsLastIndex = - 1;
  15281. sprites.length = 0;
  15282. lensFlares.length = 0;
  15283. setupGlobalClippingPlanes( this.clippingPlanes, camera );
  15284. projectObject( scene, camera );
  15285. opaqueObjects.length = opaqueObjectsLastIndex + 1;
  15286. transparentObjects.length = transparentObjectsLastIndex + 1;
  15287. if ( _this.sortObjects === true ) {
  15288. opaqueObjects.sort( painterSortStable );
  15289. transparentObjects.sort( reversePainterSortStable );
  15290. }
  15291. //
  15292. if ( _clippingEnabled ) {
  15293. _clipRenderingShadows = true;
  15294. setupClippingPlanes( null );
  15295. }
  15296. setupShadows( lights );
  15297. shadowMap.render( scene, camera );
  15298. setupLights( lights, camera );
  15299. if ( _clippingEnabled ) {
  15300. _clipRenderingShadows = false;
  15301. resetGlobalClippingState();
  15302. }
  15303. //
  15304. _infoRender.calls = 0;
  15305. _infoRender.vertices = 0;
  15306. _infoRender.faces = 0;
  15307. _infoRender.points = 0;
  15308. if ( renderTarget === undefined ) {
  15309. renderTarget = null;
  15310. }
  15311. this.setRenderTarget( renderTarget );
  15312. if ( this.autoClear || forceClear ) {
  15313. this.clear( this.autoClearColor, this.autoClearDepth, this.autoClearStencil );
  15314. }
  15315. //
  15316. if ( scene.overrideMaterial ) {
  15317. var overrideMaterial = scene.overrideMaterial;
  15318. renderObjects( opaqueObjects, camera, fog, overrideMaterial );
  15319. renderObjects( transparentObjects, camera, fog, overrideMaterial );
  15320. } else {
  15321. // opaque pass (front-to-back order)
  15322. state.setBlending( THREE.NoBlending );
  15323. renderObjects( opaqueObjects, camera, fog );
  15324. // transparent pass (back-to-front order)
  15325. renderObjects( transparentObjects, camera, fog );
  15326. }
  15327. // custom render plugins (post pass)
  15328. spritePlugin.render( scene, camera );
  15329. lensFlarePlugin.render( scene, camera, _currentViewport );
  15330. // Generate mipmap if we're using any kind of mipmap filtering
  15331. if ( renderTarget ) {
  15332. var texture = renderTarget.texture;
  15333. if ( texture.generateMipmaps && isPowerOfTwo( renderTarget ) &&
  15334. texture.minFilter !== THREE.NearestFilter &&
  15335. texture.minFilter !== THREE.LinearFilter ) {
  15336. updateRenderTargetMipmap( renderTarget );
  15337. }
  15338. }
  15339. // Ensure depth buffer writing is enabled so it can be cleared on next render
  15340. state.setDepthTest( true );
  15341. state.setDepthWrite( true );
  15342. state.setColorWrite( true );
  15343. // _gl.finish();
  15344. };
  15345. function pushRenderItem( object, geometry, material, z, group ) {
  15346. var array, index;
  15347. // allocate the next position in the appropriate array
  15348. if ( material.transparent ) {
  15349. array = transparentObjects;
  15350. index = ++ transparentObjectsLastIndex;
  15351. } else {
  15352. array = opaqueObjects;
  15353. index = ++ opaqueObjectsLastIndex;
  15354. }
  15355. // recycle existing render item or grow the array
  15356. var renderItem = array[ index ];
  15357. if ( renderItem !== undefined ) {
  15358. renderItem.id = object.id;
  15359. renderItem.object = object;
  15360. renderItem.geometry = geometry;
  15361. renderItem.material = material;
  15362. renderItem.z = _vector3.z;
  15363. renderItem.group = group;
  15364. } else {
  15365. renderItem = {
  15366. id: object.id,
  15367. object: object,
  15368. geometry: geometry,
  15369. material: material,
  15370. z: _vector3.z,
  15371. group: group
  15372. };
  15373. // assert( index === array.length );
  15374. array.push( renderItem );
  15375. }
  15376. }
  15377. function isObjectViewable( object ) {
  15378. var geometry = object.geometry;
  15379. if ( geometry.boundingSphere === null )
  15380. geometry.computeBoundingSphere();
  15381. var sphere = _sphere.
  15382. copy( geometry.boundingSphere ).
  15383. applyMatrix4( object.matrixWorld );
  15384. if ( ! _frustum.intersectsSphere( sphere ) ) return false;
  15385. if ( _numClippingPlanes === 0 ) return true;
  15386. var planes = _this.clippingPlanes,
  15387. center = sphere.center,
  15388. negRad = - sphere.radius,
  15389. i = 0;
  15390. do {
  15391. // out when deeper than radius in the negative halfspace
  15392. if ( planes[ i ].distanceToPoint( center ) < negRad ) return false;
  15393. } while ( ++ i !== _numClippingPlanes );
  15394. return true;
  15395. }
  15396. function projectObject( object, camera ) {
  15397. if ( object.visible === false ) return;
  15398. if ( object.layers.test( camera.layers ) ) {
  15399. if ( object instanceof THREE.Light ) {
  15400. lights.push( object );
  15401. } else if ( object instanceof THREE.Sprite ) {
  15402. if ( object.frustumCulled === false || isObjectViewable( object ) === true ) {
  15403. sprites.push( object );
  15404. }
  15405. } else if ( object instanceof THREE.LensFlare ) {
  15406. lensFlares.push( object );
  15407. } else if ( object instanceof THREE.ImmediateRenderObject ) {
  15408. if ( _this.sortObjects === true ) {
  15409. _vector3.setFromMatrixPosition( object.matrixWorld );
  15410. _vector3.applyProjection( _projScreenMatrix );
  15411. }
  15412. pushRenderItem( object, null, object.material, _vector3.z, null );
  15413. } else if ( object instanceof THREE.Mesh || object instanceof THREE.Line || object instanceof THREE.Points ) {
  15414. if ( object instanceof THREE.SkinnedMesh ) {
  15415. object.skeleton.update();
  15416. }
  15417. if ( object.frustumCulled === false || isObjectViewable( object ) === true ) {
  15418. var material = object.material;
  15419. if ( material.visible === true ) {
  15420. if ( _this.sortObjects === true ) {
  15421. _vector3.setFromMatrixPosition( object.matrixWorld );
  15422. _vector3.applyProjection( _projScreenMatrix );
  15423. }
  15424. var geometry = objects.update( object );
  15425. if ( material instanceof THREE.MultiMaterial ) {
  15426. var groups = geometry.groups;
  15427. var materials = material.materials;
  15428. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  15429. var group = groups[ i ];
  15430. var groupMaterial = materials[ group.materialIndex ];
  15431. if ( groupMaterial.visible === true ) {
  15432. pushRenderItem( object, geometry, groupMaterial, _vector3.z, group );
  15433. }
  15434. }
  15435. } else {
  15436. pushRenderItem( object, geometry, material, _vector3.z, null );
  15437. }
  15438. }
  15439. }
  15440. }
  15441. }
  15442. var children = object.children;
  15443. for ( var i = 0, l = children.length; i < l; i ++ ) {
  15444. projectObject( children[ i ], camera );
  15445. }
  15446. }
  15447. function renderObjects( renderList, camera, fog, overrideMaterial ) {
  15448. for ( var i = 0, l = renderList.length; i < l; i ++ ) {
  15449. var renderItem = renderList[ i ];
  15450. var object = renderItem.object;
  15451. var geometry = renderItem.geometry;
  15452. var material = overrideMaterial === undefined ? renderItem.material : overrideMaterial;
  15453. var group = renderItem.group;
  15454. object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  15455. object.normalMatrix.getNormalMatrix( object.modelViewMatrix );
  15456. if ( object instanceof THREE.ImmediateRenderObject ) {
  15457. setMaterial( material );
  15458. var program = setProgram( camera, fog, material, object );
  15459. _currentGeometryProgram = '';
  15460. object.render( function ( object ) {
  15461. _this.renderBufferImmediate( object, program, material );
  15462. } );
  15463. } else {
  15464. _this.renderBufferDirect( camera, fog, geometry, material, object, group );
  15465. }
  15466. }
  15467. }
  15468. function initMaterial( material, fog, object ) {
  15469. var materialProperties = properties.get( material );
  15470. var parameters = programCache.getParameters(
  15471. material, _lights, fog, _numClippingPlanes, object );
  15472. var code = programCache.getProgramCode( material, parameters );
  15473. var program = materialProperties.program;
  15474. var programChange = true;
  15475. if ( program === undefined ) {
  15476. // new material
  15477. material.addEventListener( 'dispose', onMaterialDispose );
  15478. } else if ( program.code !== code ) {
  15479. // changed glsl or parameters
  15480. releaseMaterialProgramReference( material );
  15481. } else if ( parameters.shaderID !== undefined ) {
  15482. // same glsl and uniform list
  15483. return;
  15484. } else {
  15485. // only rebuild uniform list
  15486. programChange = false;
  15487. }
  15488. if ( programChange ) {
  15489. if ( parameters.shaderID ) {
  15490. var shader = THREE.ShaderLib[ parameters.shaderID ];
  15491. materialProperties.__webglShader = {
  15492. name: material.type,
  15493. uniforms: THREE.UniformsUtils.clone( shader.uniforms ),
  15494. vertexShader: shader.vertexShader,
  15495. fragmentShader: shader.fragmentShader
  15496. };
  15497. } else {
  15498. materialProperties.__webglShader = {
  15499. name: material.type,
  15500. uniforms: material.uniforms,
  15501. vertexShader: material.vertexShader,
  15502. fragmentShader: material.fragmentShader
  15503. };
  15504. }
  15505. material.__webglShader = materialProperties.__webglShader;
  15506. program = programCache.acquireProgram( material, parameters, code );
  15507. materialProperties.program = program;
  15508. material.program = program;
  15509. }
  15510. var attributes = program.getAttributes();
  15511. if ( material.morphTargets ) {
  15512. material.numSupportedMorphTargets = 0;
  15513. for ( var i = 0; i < _this.maxMorphTargets; i ++ ) {
  15514. if ( attributes[ 'morphTarget' + i ] >= 0 ) {
  15515. material.numSupportedMorphTargets ++;
  15516. }
  15517. }
  15518. }
  15519. if ( material.morphNormals ) {
  15520. material.numSupportedMorphNormals = 0;
  15521. for ( var i = 0; i < _this.maxMorphNormals; i ++ ) {
  15522. if ( attributes[ 'morphNormal' + i ] >= 0 ) {
  15523. material.numSupportedMorphNormals ++;
  15524. }
  15525. }
  15526. }
  15527. var uniforms = materialProperties.__webglShader.uniforms;
  15528. if ( ! ( material instanceof THREE.ShaderMaterial ) &&
  15529. ! ( material instanceof THREE.RawShaderMaterial ) ||
  15530. material.clipping === true ) {
  15531. materialProperties.numClippingPlanes = _numClippingPlanes;
  15532. uniforms.clippingPlanes = _clippingPlanesUniform;
  15533. }
  15534. if ( material instanceof THREE.MeshPhongMaterial ||
  15535. material instanceof THREE.MeshLambertMaterial ||
  15536. material instanceof THREE.MeshStandardMaterial ||
  15537. material.lights ) {
  15538. // store the light setup it was created for
  15539. materialProperties.lightsHash = _lights.hash;
  15540. // wire up the material to this renderer's lighting state
  15541. uniforms.ambientLightColor.value = _lights.ambient;
  15542. uniforms.directionalLights.value = _lights.directional;
  15543. uniforms.spotLights.value = _lights.spot;
  15544. uniforms.pointLights.value = _lights.point;
  15545. uniforms.hemisphereLights.value = _lights.hemi;
  15546. uniforms.directionalShadowMap.value = _lights.directionalShadowMap;
  15547. uniforms.directionalShadowMatrix.value = _lights.directionalShadowMatrix;
  15548. uniforms.spotShadowMap.value = _lights.spotShadowMap;
  15549. uniforms.spotShadowMatrix.value = _lights.spotShadowMatrix;
  15550. uniforms.pointShadowMap.value = _lights.pointShadowMap;
  15551. uniforms.pointShadowMatrix.value = _lights.pointShadowMatrix;
  15552. }
  15553. var progUniforms = materialProperties.program.getUniforms(),
  15554. uniformsList =
  15555. THREE.WebGLUniforms.seqWithValue( progUniforms.seq, uniforms );
  15556. materialProperties.uniformsList = uniformsList;
  15557. materialProperties.dynamicUniforms =
  15558. THREE.WebGLUniforms.splitDynamic( uniformsList, uniforms );
  15559. }
  15560. function setMaterial( material ) {
  15561. setMaterialFaces( material );
  15562. if ( material.transparent === true ) {
  15563. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.premultipliedAlpha );
  15564. } else {
  15565. state.setBlending( THREE.NoBlending );
  15566. }
  15567. state.setDepthFunc( material.depthFunc );
  15568. state.setDepthTest( material.depthTest );
  15569. state.setDepthWrite( material.depthWrite );
  15570. state.setColorWrite( material.colorWrite );
  15571. state.setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  15572. }
  15573. function setMaterialFaces( material ) {
  15574. material.side !== THREE.DoubleSide ? state.enable( _gl.CULL_FACE ) : state.disable( _gl.CULL_FACE );
  15575. state.setFlipSided( material.side === THREE.BackSide );
  15576. }
  15577. function setProgram( camera, fog, material, object ) {
  15578. _usedTextureUnits = 0;
  15579. var materialProperties = properties.get( material );
  15580. if ( _clippingEnabled ) {
  15581. if ( _localClippingEnabled || camera !== _currentCamera ) {
  15582. var useCache =
  15583. camera === _currentCamera &&
  15584. material.id === _currentMaterialId;
  15585. // we might want to call this function with some ClippingGroup
  15586. // object instead of the material, once it becomes feasible
  15587. // (#8465, #8379)
  15588. setClippingState(
  15589. material.clippingPlanes, material.clipShadows,
  15590. camera, materialProperties, useCache );
  15591. }
  15592. if ( materialProperties.numClippingPlanes !== undefined &&
  15593. materialProperties.numClippingPlanes !== _numClippingPlanes ) {
  15594. material.needsUpdate = true;
  15595. }
  15596. }
  15597. if ( materialProperties.program === undefined ) {
  15598. material.needsUpdate = true;
  15599. }
  15600. if ( materialProperties.lightsHash !== undefined &&
  15601. materialProperties.lightsHash !== _lights.hash ) {
  15602. material.needsUpdate = true;
  15603. }
  15604. if ( material.needsUpdate ) {
  15605. initMaterial( material, fog, object );
  15606. material.needsUpdate = false;
  15607. }
  15608. var refreshProgram = false;
  15609. var refreshMaterial = false;
  15610. var refreshLights = false;
  15611. var program = materialProperties.program,
  15612. p_uniforms = program.getUniforms(),
  15613. m_uniforms = materialProperties.__webglShader.uniforms;
  15614. if ( program.id !== _currentProgram ) {
  15615. _gl.useProgram( program.program );
  15616. _currentProgram = program.id;
  15617. refreshProgram = true;
  15618. refreshMaterial = true;
  15619. refreshLights = true;
  15620. }
  15621. if ( material.id !== _currentMaterialId ) {
  15622. _currentMaterialId = material.id;
  15623. refreshMaterial = true;
  15624. }
  15625. if ( refreshProgram || camera !== _currentCamera ) {
  15626. p_uniforms.set( _gl, camera, 'projectionMatrix' );
  15627. if ( capabilities.logarithmicDepthBuffer ) {
  15628. p_uniforms.setValue( _gl, 'logDepthBufFC',
  15629. 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
  15630. }
  15631. if ( camera !== _currentCamera ) {
  15632. _currentCamera = camera;
  15633. // lighting uniforms depend on the camera so enforce an update
  15634. // now, in case this material supports lights - or later, when
  15635. // the next material that does gets activated:
  15636. refreshMaterial = true; // set to true on material change
  15637. refreshLights = true; // remains set until update done
  15638. }
  15639. // load material specific uniforms
  15640. // (shader material also gets them for the sake of genericity)
  15641. if ( material instanceof THREE.ShaderMaterial ||
  15642. material instanceof THREE.MeshPhongMaterial ||
  15643. material instanceof THREE.MeshStandardMaterial ||
  15644. material.envMap ) {
  15645. var uCamPos = p_uniforms.map.cameraPosition;
  15646. if ( uCamPos !== undefined ) {
  15647. uCamPos.setValue( _gl,
  15648. _vector3.setFromMatrixPosition( camera.matrixWorld ) );
  15649. }
  15650. }
  15651. if ( material instanceof THREE.MeshPhongMaterial ||
  15652. material instanceof THREE.MeshLambertMaterial ||
  15653. material instanceof THREE.MeshBasicMaterial ||
  15654. material instanceof THREE.MeshStandardMaterial ||
  15655. material instanceof THREE.ShaderMaterial ||
  15656. material.skinning ) {
  15657. p_uniforms.setValue( _gl, 'viewMatrix', camera.matrixWorldInverse );
  15658. }
  15659. p_uniforms.set( _gl, _this, 'toneMappingExposure' );
  15660. p_uniforms.set( _gl, _this, 'toneMappingWhitePoint' );
  15661. }
  15662. // skinning uniforms must be set even if material didn't change
  15663. // auto-setting of texture unit for bone texture must go before other textures
  15664. // not sure why, but otherwise weird things happen
  15665. if ( material.skinning ) {
  15666. p_uniforms.setOptional( _gl, object, 'bindMatrix' );
  15667. p_uniforms.setOptional( _gl, object, 'bindMatrixInverse' );
  15668. var skeleton = object.skeleton;
  15669. if ( skeleton ) {
  15670. if ( capabilities.floatVertexTextures && skeleton.useVertexTexture ) {
  15671. p_uniforms.set( _gl, skeleton, 'boneTexture' );
  15672. p_uniforms.set( _gl, skeleton, 'boneTextureWidth' );
  15673. p_uniforms.set( _gl, skeleton, 'boneTextureHeight' );
  15674. } else {
  15675. p_uniforms.setOptional( _gl, skeleton, 'boneMatrices' );
  15676. }
  15677. }
  15678. }
  15679. if ( refreshMaterial ) {
  15680. if ( material instanceof THREE.MeshPhongMaterial ||
  15681. material instanceof THREE.MeshLambertMaterial ||
  15682. material instanceof THREE.MeshStandardMaterial ||
  15683. material.lights ) {
  15684. // the current material requires lighting info
  15685. // note: all lighting uniforms are always set correctly
  15686. // they simply reference the renderer's state for their
  15687. // values
  15688. //
  15689. // use the current material's .needsUpdate flags to set
  15690. // the GL state when required
  15691. markUniformsLightsNeedsUpdate( m_uniforms, refreshLights );
  15692. }
  15693. // refresh uniforms common to several materials
  15694. if ( fog && material.fog ) {
  15695. refreshUniformsFog( m_uniforms, fog );
  15696. }
  15697. if ( material instanceof THREE.MeshBasicMaterial ||
  15698. material instanceof THREE.MeshLambertMaterial ||
  15699. material instanceof THREE.MeshPhongMaterial ||
  15700. material instanceof THREE.MeshStandardMaterial ||
  15701. material instanceof THREE.MeshDepthMaterial ) {
  15702. refreshUniformsCommon( m_uniforms, material );
  15703. }
  15704. // refresh single material specific uniforms
  15705. if ( material instanceof THREE.LineBasicMaterial ) {
  15706. refreshUniformsLine( m_uniforms, material );
  15707. } else if ( material instanceof THREE.LineDashedMaterial ) {
  15708. refreshUniformsLine( m_uniforms, material );
  15709. refreshUniformsDash( m_uniforms, material );
  15710. } else if ( material instanceof THREE.PointsMaterial ) {
  15711. refreshUniformsPoints( m_uniforms, material );
  15712. } else if ( material instanceof THREE.MeshLambertMaterial ) {
  15713. refreshUniformsLambert( m_uniforms, material );
  15714. } else if ( material instanceof THREE.MeshPhongMaterial ) {
  15715. refreshUniformsPhong( m_uniforms, material );
  15716. } else if ( material instanceof THREE.MeshPhysicalMaterial ) {
  15717. refreshUniformsPhysical( m_uniforms, material );
  15718. } else if ( material instanceof THREE.MeshStandardMaterial ) {
  15719. refreshUniformsStandard( m_uniforms, material );
  15720. } else if ( material instanceof THREE.MeshDepthMaterial ) {
  15721. if ( material.displacementMap ) {
  15722. m_uniforms.displacementMap.value = material.displacementMap;
  15723. m_uniforms.displacementScale.value = material.displacementScale;
  15724. m_uniforms.displacementBias.value = material.displacementBias;
  15725. }
  15726. } else if ( material instanceof THREE.MeshNormalMaterial ) {
  15727. m_uniforms.opacity.value = material.opacity;
  15728. }
  15729. THREE.WebGLUniforms.upload(
  15730. _gl, materialProperties.uniformsList, m_uniforms, _this );
  15731. }
  15732. // common matrices
  15733. p_uniforms.set( _gl, object, 'modelViewMatrix' );
  15734. p_uniforms.set( _gl, object, 'normalMatrix' );
  15735. p_uniforms.setValue( _gl, 'modelMatrix', object.matrixWorld );
  15736. // dynamic uniforms
  15737. var dynUniforms = materialProperties.dynamicUniforms;
  15738. if ( dynUniforms !== null ) {
  15739. THREE.WebGLUniforms.evalDynamic(
  15740. dynUniforms, m_uniforms, object, camera );
  15741. THREE.WebGLUniforms.upload( _gl, dynUniforms, m_uniforms, _this );
  15742. }
  15743. return program;
  15744. }
  15745. // Uniforms (refresh uniforms objects)
  15746. function refreshUniformsCommon ( uniforms, material ) {
  15747. uniforms.opacity.value = material.opacity;
  15748. uniforms.diffuse.value = material.color;
  15749. if ( material.emissive ) {
  15750. uniforms.emissive.value.copy( material.emissive ).multiplyScalar( material.emissiveIntensity );
  15751. }
  15752. uniforms.map.value = material.map;
  15753. uniforms.specularMap.value = material.specularMap;
  15754. uniforms.alphaMap.value = material.alphaMap;
  15755. if ( material.aoMap ) {
  15756. uniforms.aoMap.value = material.aoMap;
  15757. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  15758. }
  15759. // uv repeat and offset setting priorities
  15760. // 1. color map
  15761. // 2. specular map
  15762. // 3. normal map
  15763. // 4. bump map
  15764. // 5. alpha map
  15765. // 6. emissive map
  15766. var uvScaleMap;
  15767. if ( material.map ) {
  15768. uvScaleMap = material.map;
  15769. } else if ( material.specularMap ) {
  15770. uvScaleMap = material.specularMap;
  15771. } else if ( material.displacementMap ) {
  15772. uvScaleMap = material.displacementMap;
  15773. } else if ( material.normalMap ) {
  15774. uvScaleMap = material.normalMap;
  15775. } else if ( material.bumpMap ) {
  15776. uvScaleMap = material.bumpMap;
  15777. } else if ( material.roughnessMap ) {
  15778. uvScaleMap = material.roughnessMap;
  15779. } else if ( material.metalnessMap ) {
  15780. uvScaleMap = material.metalnessMap;
  15781. } else if ( material.alphaMap ) {
  15782. uvScaleMap = material.alphaMap;
  15783. } else if ( material.emissiveMap ) {
  15784. uvScaleMap = material.emissiveMap;
  15785. }
  15786. if ( uvScaleMap !== undefined ) {
  15787. if ( uvScaleMap instanceof THREE.WebGLRenderTarget ) {
  15788. uvScaleMap = uvScaleMap.texture;
  15789. }
  15790. var offset = uvScaleMap.offset;
  15791. var repeat = uvScaleMap.repeat;
  15792. uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
  15793. }
  15794. uniforms.envMap.value = material.envMap;
  15795. uniforms.flipEnvMap.value = ( material.envMap instanceof THREE.WebGLRenderTargetCube ) ? 1 : - 1;
  15796. uniforms.reflectivity.value = material.reflectivity;
  15797. uniforms.refractionRatio.value = material.refractionRatio;
  15798. }
  15799. function refreshUniformsLine ( uniforms, material ) {
  15800. uniforms.diffuse.value = material.color;
  15801. uniforms.opacity.value = material.opacity;
  15802. }
  15803. function refreshUniformsDash ( uniforms, material ) {
  15804. uniforms.dashSize.value = material.dashSize;
  15805. uniforms.totalSize.value = material.dashSize + material.gapSize;
  15806. uniforms.scale.value = material.scale;
  15807. }
  15808. function refreshUniformsPoints ( uniforms, material ) {
  15809. uniforms.diffuse.value = material.color;
  15810. uniforms.opacity.value = material.opacity;
  15811. uniforms.size.value = material.size * _pixelRatio;
  15812. uniforms.scale.value = _canvas.clientHeight * 0.5;
  15813. uniforms.map.value = material.map;
  15814. if ( material.map !== null ) {
  15815. var offset = material.map.offset;
  15816. var repeat = material.map.repeat;
  15817. uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
  15818. }
  15819. }
  15820. function refreshUniformsFog ( uniforms, fog ) {
  15821. uniforms.fogColor.value = fog.color;
  15822. if ( fog instanceof THREE.Fog ) {
  15823. uniforms.fogNear.value = fog.near;
  15824. uniforms.fogFar.value = fog.far;
  15825. } else if ( fog instanceof THREE.FogExp2 ) {
  15826. uniforms.fogDensity.value = fog.density;
  15827. }
  15828. }
  15829. function refreshUniformsLambert ( uniforms, material ) {
  15830. if ( material.lightMap ) {
  15831. uniforms.lightMap.value = material.lightMap;
  15832. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  15833. }
  15834. if ( material.emissiveMap ) {
  15835. uniforms.emissiveMap.value = material.emissiveMap;
  15836. }
  15837. }
  15838. function refreshUniformsPhong ( uniforms, material ) {
  15839. uniforms.specular.value = material.specular;
  15840. uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 )
  15841. if ( material.lightMap ) {
  15842. uniforms.lightMap.value = material.lightMap;
  15843. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  15844. }
  15845. if ( material.emissiveMap ) {
  15846. uniforms.emissiveMap.value = material.emissiveMap;
  15847. }
  15848. if ( material.bumpMap ) {
  15849. uniforms.bumpMap.value = material.bumpMap;
  15850. uniforms.bumpScale.value = material.bumpScale;
  15851. }
  15852. if ( material.normalMap ) {
  15853. uniforms.normalMap.value = material.normalMap;
  15854. uniforms.normalScale.value.copy( material.normalScale );
  15855. }
  15856. if ( material.displacementMap ) {
  15857. uniforms.displacementMap.value = material.displacementMap;
  15858. uniforms.displacementScale.value = material.displacementScale;
  15859. uniforms.displacementBias.value = material.displacementBias;
  15860. }
  15861. }
  15862. function refreshUniformsStandard ( uniforms, material ) {
  15863. uniforms.roughness.value = material.roughness;
  15864. uniforms.metalness.value = material.metalness;
  15865. if ( material.roughnessMap ) {
  15866. uniforms.roughnessMap.value = material.roughnessMap;
  15867. }
  15868. if ( material.metalnessMap ) {
  15869. uniforms.metalnessMap.value = material.metalnessMap;
  15870. }
  15871. if ( material.lightMap ) {
  15872. uniforms.lightMap.value = material.lightMap;
  15873. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  15874. }
  15875. if ( material.emissiveMap ) {
  15876. uniforms.emissiveMap.value = material.emissiveMap;
  15877. }
  15878. if ( material.bumpMap ) {
  15879. uniforms.bumpMap.value = material.bumpMap;
  15880. uniforms.bumpScale.value = material.bumpScale;
  15881. }
  15882. if ( material.normalMap ) {
  15883. uniforms.normalMap.value = material.normalMap;
  15884. uniforms.normalScale.value.copy( material.normalScale );
  15885. }
  15886. if ( material.displacementMap ) {
  15887. uniforms.displacementMap.value = material.displacementMap;
  15888. uniforms.displacementScale.value = material.displacementScale;
  15889. uniforms.displacementBias.value = material.displacementBias;
  15890. }
  15891. if ( material.envMap ) {
  15892. //uniforms.envMap.value = material.envMap; // part of uniforms common
  15893. uniforms.envMapIntensity.value = material.envMapIntensity;
  15894. }
  15895. }
  15896. function refreshUniformsPhysical ( uniforms, material ) {
  15897. refreshUniformsStandard( uniforms, material );
  15898. }
  15899. // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  15900. function markUniformsLightsNeedsUpdate ( uniforms, value ) {
  15901. uniforms.ambientLightColor.needsUpdate = value;
  15902. uniforms.directionalLights.needsUpdate = value;
  15903. uniforms.pointLights.needsUpdate = value;
  15904. uniforms.spotLights.needsUpdate = value;
  15905. uniforms.hemisphereLights.needsUpdate = value;
  15906. }
  15907. // Lighting
  15908. function setupShadows ( lights ) {
  15909. var lightShadowsLength = 0;
  15910. for ( var i = 0, l = lights.length; i < l; i ++ ) {
  15911. var light = lights[ i ];
  15912. if ( light.castShadow ) {
  15913. _lights.shadows[ lightShadowsLength ++ ] = light;
  15914. }
  15915. }
  15916. _lights.shadows.length = lightShadowsLength;
  15917. }
  15918. function setupLights ( lights, camera ) {
  15919. var l, ll, light,
  15920. r = 0, g = 0, b = 0,
  15921. color,
  15922. intensity,
  15923. distance,
  15924. viewMatrix = camera.matrixWorldInverse,
  15925. directionalLength = 0,
  15926. pointLength = 0,
  15927. spotLength = 0,
  15928. hemiLength = 0;
  15929. for ( l = 0, ll = lights.length; l < ll; l ++ ) {
  15930. light = lights[ l ];
  15931. color = light.color;
  15932. intensity = light.intensity;
  15933. distance = light.distance;
  15934. if ( light instanceof THREE.AmbientLight ) {
  15935. r += color.r * intensity;
  15936. g += color.g * intensity;
  15937. b += color.b * intensity;
  15938. } else if ( light instanceof THREE.DirectionalLight ) {
  15939. var uniforms = lightCache.get( light );
  15940. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  15941. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  15942. _vector3.setFromMatrixPosition( light.target.matrixWorld );
  15943. uniforms.direction.sub( _vector3 );
  15944. uniforms.direction.transformDirection( viewMatrix );
  15945. uniforms.shadow = light.castShadow;
  15946. if ( light.castShadow ) {
  15947. uniforms.shadowBias = light.shadow.bias;
  15948. uniforms.shadowRadius = light.shadow.radius;
  15949. uniforms.shadowMapSize = light.shadow.mapSize;
  15950. }
  15951. _lights.directionalShadowMap[ directionalLength ] = light.shadow.map;
  15952. _lights.directionalShadowMatrix[ directionalLength ] = light.shadow.matrix;
  15953. _lights.directional[ directionalLength ++ ] = uniforms;
  15954. } else if ( light instanceof THREE.SpotLight ) {
  15955. var uniforms = lightCache.get( light );
  15956. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  15957. uniforms.position.applyMatrix4( viewMatrix );
  15958. uniforms.color.copy( color ).multiplyScalar( intensity );
  15959. uniforms.distance = distance;
  15960. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  15961. _vector3.setFromMatrixPosition( light.target.matrixWorld );
  15962. uniforms.direction.sub( _vector3 );
  15963. uniforms.direction.transformDirection( viewMatrix );
  15964. uniforms.coneCos = Math.cos( light.angle );
  15965. uniforms.penumbraCos = Math.cos( light.angle * ( 1 - light.penumbra ) );
  15966. uniforms.decay = ( light.distance === 0 ) ? 0.0 : light.decay;
  15967. uniforms.shadow = light.castShadow;
  15968. if ( light.castShadow ) {
  15969. uniforms.shadowBias = light.shadow.bias;
  15970. uniforms.shadowRadius = light.shadow.radius;
  15971. uniforms.shadowMapSize = light.shadow.mapSize;
  15972. }
  15973. _lights.spotShadowMap[ spotLength ] = light.shadow.map;
  15974. _lights.spotShadowMatrix[ spotLength ] = light.shadow.matrix;
  15975. _lights.spot[ spotLength ++ ] = uniforms;
  15976. } else if ( light instanceof THREE.PointLight ) {
  15977. var uniforms = lightCache.get( light );
  15978. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  15979. uniforms.position.applyMatrix4( viewMatrix );
  15980. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  15981. uniforms.distance = light.distance;
  15982. uniforms.decay = ( light.distance === 0 ) ? 0.0 : light.decay;
  15983. uniforms.shadow = light.castShadow;
  15984. if ( light.castShadow ) {
  15985. uniforms.shadowBias = light.shadow.bias;
  15986. uniforms.shadowRadius = light.shadow.radius;
  15987. uniforms.shadowMapSize = light.shadow.mapSize;
  15988. }
  15989. _lights.pointShadowMap[ pointLength ] = light.shadow.map;
  15990. if ( _lights.pointShadowMatrix[ pointLength ] === undefined ) {
  15991. _lights.pointShadowMatrix[ pointLength ] = new THREE.Matrix4();
  15992. }
  15993. // for point lights we set the shadow matrix to be a translation-only matrix
  15994. // equal to inverse of the light's position
  15995. _vector3.setFromMatrixPosition( light.matrixWorld ).negate();
  15996. _lights.pointShadowMatrix[ pointLength ].identity().setPosition( _vector3 );
  15997. _lights.point[ pointLength ++ ] = uniforms;
  15998. } else if ( light instanceof THREE.HemisphereLight ) {
  15999. var uniforms = lightCache.get( light );
  16000. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  16001. uniforms.direction.transformDirection( viewMatrix );
  16002. uniforms.direction.normalize();
  16003. uniforms.skyColor.copy( light.color ).multiplyScalar( intensity );
  16004. uniforms.groundColor.copy( light.groundColor ).multiplyScalar( intensity );
  16005. _lights.hemi[ hemiLength ++ ] = uniforms;
  16006. }
  16007. }
  16008. _lights.ambient[ 0 ] = r;
  16009. _lights.ambient[ 1 ] = g;
  16010. _lights.ambient[ 2 ] = b;
  16011. _lights.directional.length = directionalLength;
  16012. _lights.spot.length = spotLength;
  16013. _lights.point.length = pointLength;
  16014. _lights.hemi.length = hemiLength;
  16015. _lights.hash = directionalLength + ',' + pointLength + ',' + spotLength + ',' + hemiLength + ',' + _lights.shadows.length;
  16016. }
  16017. // Clipping
  16018. function setupGlobalClippingPlanes( planes, camera ) {
  16019. _clippingEnabled =
  16020. _this.clippingPlanes.length !== 0 ||
  16021. _this.localClippingEnabled ||
  16022. // enable state of previous frame - the clipping code has to
  16023. // run another frame in order to reset the state:
  16024. _numGlobalClippingPlanes !== 0 ||
  16025. _localClippingEnabled;
  16026. _localClippingEnabled = _this.localClippingEnabled;
  16027. _globalClippingState = setupClippingPlanes( planes, camera, 0 );
  16028. _numGlobalClippingPlanes = planes !== null ? planes.length : 0;
  16029. }
  16030. function setupClippingPlanes( planes, camera, dstOffset, skipTransform ) {
  16031. var nPlanes = planes !== null ? planes.length : 0,
  16032. dstArray = null;
  16033. if ( nPlanes !== 0 ) {
  16034. dstArray = _clippingPlanesUniform.value;
  16035. if ( skipTransform !== true || dstArray === null ) {
  16036. var flatSize = dstOffset + nPlanes * 4,
  16037. viewMatrix = camera.matrixWorldInverse,
  16038. viewNormalMatrix = _matrix3.getNormalMatrix( viewMatrix );
  16039. if ( dstArray === null || dstArray.length < flatSize ) {
  16040. dstArray = new Float32Array( flatSize );
  16041. }
  16042. for ( var i = 0, i4 = dstOffset; i !== nPlanes; ++ i, i4 += 4 ) {
  16043. var plane = _plane.copy( planes[ i ] ).
  16044. applyMatrix4( viewMatrix, viewNormalMatrix );
  16045. plane.normal.toArray( dstArray, i4 );
  16046. dstArray[ i4 + 3 ] = plane.constant;
  16047. }
  16048. }
  16049. _clippingPlanesUniform.value = dstArray;
  16050. _clippingPlanesUniform.needsUpdate = true;
  16051. }
  16052. _numClippingPlanes = nPlanes;
  16053. return dstArray;
  16054. }
  16055. function resetGlobalClippingState() {
  16056. if ( _clippingPlanesUniform.value !== _globalClippingState ) {
  16057. _clippingPlanesUniform.value = _globalClippingState;
  16058. _clippingPlanesUniform.needsUpdate = _numGlobalClippingPlanes > 0;
  16059. }
  16060. _numClippingPlanes = _numGlobalClippingPlanes;
  16061. }
  16062. function setClippingState( planes, clipShadows, camera, cache, fromCache ) {
  16063. if ( ! _localClippingEnabled ||
  16064. planes === null || planes.length === 0 ||
  16065. _clipRenderingShadows && ! clipShadows ) {
  16066. // there's no local clipping
  16067. if ( _clipRenderingShadows ) {
  16068. // there's no global clipping
  16069. setupClippingPlanes( null );
  16070. } else {
  16071. resetGlobalClippingState();
  16072. }
  16073. } else {
  16074. var nGlobal = _clipRenderingShadows ? 0 : _numGlobalClippingPlanes,
  16075. lGlobal = nGlobal * 4,
  16076. dstArray = cache.clippingState || null;
  16077. _clippingPlanesUniform.value = dstArray; // ensure unique state
  16078. dstArray = setupClippingPlanes(
  16079. planes, camera, lGlobal, fromCache );
  16080. for ( var i = 0; i !== lGlobal; ++ i ) {
  16081. dstArray[ i ] = _globalClippingState[ i ];
  16082. }
  16083. cache.clippingState = dstArray;
  16084. _numClippingPlanes += nGlobal;
  16085. }
  16086. }
  16087. // GL state setting
  16088. this.setFaceCulling = function ( cullFace, frontFaceDirection ) {
  16089. if ( cullFace === THREE.CullFaceNone ) {
  16090. state.disable( _gl.CULL_FACE );
  16091. } else {
  16092. if ( frontFaceDirection === THREE.FrontFaceDirectionCW ) {
  16093. _gl.frontFace( _gl.CW );
  16094. } else {
  16095. _gl.frontFace( _gl.CCW );
  16096. }
  16097. if ( cullFace === THREE.CullFaceBack ) {
  16098. _gl.cullFace( _gl.BACK );
  16099. } else if ( cullFace === THREE.CullFaceFront ) {
  16100. _gl.cullFace( _gl.FRONT );
  16101. } else {
  16102. _gl.cullFace( _gl.FRONT_AND_BACK );
  16103. }
  16104. state.enable( _gl.CULL_FACE );
  16105. }
  16106. };
  16107. // Textures
  16108. function allocTextureUnit() {
  16109. var textureUnit = _usedTextureUnits;
  16110. if ( textureUnit >= capabilities.maxTextures ) {
  16111. console.warn( 'WebGLRenderer: trying to use ' + textureUnit + ' texture units while this GPU supports only ' + capabilities.maxTextures );
  16112. }
  16113. _usedTextureUnits += 1;
  16114. return textureUnit;
  16115. }
  16116. function setTextureParameters ( textureType, texture, isPowerOfTwoImage ) {
  16117. var extension;
  16118. if ( isPowerOfTwoImage ) {
  16119. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, paramThreeToGL( texture.wrapS ) );
  16120. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, paramThreeToGL( texture.wrapT ) );
  16121. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, paramThreeToGL( texture.magFilter ) );
  16122. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, paramThreeToGL( texture.minFilter ) );
  16123. } else {
  16124. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, _gl.CLAMP_TO_EDGE );
  16125. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, _gl.CLAMP_TO_EDGE );
  16126. if ( texture.wrapS !== THREE.ClampToEdgeWrapping || texture.wrapT !== THREE.ClampToEdgeWrapping ) {
  16127. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.', texture );
  16128. }
  16129. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, filterFallback( texture.magFilter ) );
  16130. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, filterFallback( texture.minFilter ) );
  16131. if ( texture.minFilter !== THREE.NearestFilter && texture.minFilter !== THREE.LinearFilter ) {
  16132. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.', texture );
  16133. }
  16134. }
  16135. extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  16136. if ( extension ) {
  16137. if ( texture.type === THREE.FloatType && extensions.get( 'OES_texture_float_linear' ) === null ) return;
  16138. if ( texture.type === THREE.HalfFloatType && extensions.get( 'OES_texture_half_float_linear' ) === null ) return;
  16139. if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
  16140. _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, _this.getMaxAnisotropy() ) );
  16141. properties.get( texture ).__currentAnisotropy = texture.anisotropy;
  16142. }
  16143. }
  16144. }
  16145. function uploadTexture( textureProperties, texture, slot ) {
  16146. if ( textureProperties.__webglInit === undefined ) {
  16147. textureProperties.__webglInit = true;
  16148. texture.addEventListener( 'dispose', onTextureDispose );
  16149. textureProperties.__webglTexture = _gl.createTexture();
  16150. _infoMemory.textures ++;
  16151. }
  16152. state.activeTexture( _gl.TEXTURE0 + slot );
  16153. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  16154. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  16155. _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );
  16156. _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
  16157. var image = clampToMaxSize( texture.image, capabilities.maxTextureSize );
  16158. if ( textureNeedsPowerOfTwo( texture ) && isPowerOfTwo( image ) === false ) {
  16159. image = makePowerOfTwo( image );
  16160. }
  16161. var isPowerOfTwoImage = isPowerOfTwo( image ),
  16162. glFormat = paramThreeToGL( texture.format ),
  16163. glType = paramThreeToGL( texture.type );
  16164. setTextureParameters( _gl.TEXTURE_2D, texture, isPowerOfTwoImage );
  16165. var mipmap, mipmaps = texture.mipmaps;
  16166. if ( texture instanceof THREE.DepthTexture ) {
  16167. // populate depth texture with dummy data
  16168. var internalFormat = _gl.DEPTH_COMPONENT;
  16169. if ( texture.type === THREE.FloatType ) {
  16170. if ( !_isWebGL2 ) throw new Error('Float Depth Texture only supported in WebGL2.0');
  16171. internalFormat = _gl.DEPTH_COMPONENT32F;
  16172. } else if ( _isWebGL2 ) {
  16173. // WebGL 2.0 requires signed internalformat for glTexImage2D
  16174. internalFormat = _gl.DEPTH_COMPONENT16;
  16175. }
  16176. state.texImage2D( _gl.TEXTURE_2D, 0, internalFormat, image.width, image.height, 0, glFormat, glType, null );
  16177. } else if ( texture instanceof THREE.DataTexture ) {
  16178. // use manually created mipmaps if available
  16179. // if there are no manual mipmaps
  16180. // set 0 level mipmap and then use GL to generate other mipmap levels
  16181. if ( mipmaps.length > 0 && isPowerOfTwoImage ) {
  16182. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  16183. mipmap = mipmaps[ i ];
  16184. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  16185. }
  16186. texture.generateMipmaps = false;
  16187. } else {
  16188. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, image.width, image.height, 0, glFormat, glType, image.data );
  16189. }
  16190. } else if ( texture instanceof THREE.CompressedTexture ) {
  16191. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  16192. mipmap = mipmaps[ i ];
  16193. if ( texture.format !== THREE.RGBAFormat && texture.format !== THREE.RGBFormat ) {
  16194. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  16195. state.compressedTexImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  16196. } else {
  16197. console.warn( "THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()" );
  16198. }
  16199. } else {
  16200. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  16201. }
  16202. }
  16203. } else {
  16204. // regular Texture (image, video, canvas)
  16205. // use manually created mipmaps if available
  16206. // if there are no manual mipmaps
  16207. // set 0 level mipmap and then use GL to generate other mipmap levels
  16208. if ( mipmaps.length > 0 && isPowerOfTwoImage ) {
  16209. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  16210. mipmap = mipmaps[ i ];
  16211. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, glFormat, glType, mipmap );
  16212. }
  16213. texture.generateMipmaps = false;
  16214. } else {
  16215. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, glFormat, glType, image );
  16216. }
  16217. }
  16218. if ( texture.generateMipmaps && isPowerOfTwoImage ) _gl.generateMipmap( _gl.TEXTURE_2D );
  16219. textureProperties.__version = texture.version;
  16220. if ( texture.onUpdate ) texture.onUpdate( texture );
  16221. }
  16222. function setTexture2D( texture, slot ) {
  16223. if ( texture instanceof THREE.WebGLRenderTarget ) texture = texture.texture;
  16224. var textureProperties = properties.get( texture );
  16225. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  16226. var image = texture.image;
  16227. if ( image === undefined ) {
  16228. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is undefined', texture );
  16229. return;
  16230. }
  16231. if ( image.complete === false ) {
  16232. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete', texture );
  16233. return;
  16234. }
  16235. uploadTexture( textureProperties, texture, slot );
  16236. return;
  16237. }
  16238. state.activeTexture( _gl.TEXTURE0 + slot );
  16239. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  16240. }
  16241. function clampToMaxSize ( image, maxSize ) {
  16242. if ( image.width > maxSize || image.height > maxSize ) {
  16243. // Warning: Scaling through the canvas will only work with images that use
  16244. // premultiplied alpha.
  16245. var scale = maxSize / Math.max( image.width, image.height );
  16246. var canvas = document.createElement( 'canvas' );
  16247. canvas.width = Math.floor( image.width * scale );
  16248. canvas.height = Math.floor( image.height * scale );
  16249. var context = canvas.getContext( '2d' );
  16250. context.drawImage( image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height );
  16251. console.warn( 'THREE.WebGLRenderer: image is too big (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
  16252. return canvas;
  16253. }
  16254. return image;
  16255. }
  16256. function isPowerOfTwo( image ) {
  16257. return THREE.Math.isPowerOfTwo( image.width ) && THREE.Math.isPowerOfTwo( image.height );
  16258. }
  16259. function textureNeedsPowerOfTwo( texture ) {
  16260. if ( texture.wrapS !== THREE.ClampToEdgeWrapping || texture.wrapT !== THREE.ClampToEdgeWrapping ) return true;
  16261. if ( texture.minFilter !== THREE.NearestFilter && texture.minFilter !== THREE.LinearFilter ) return true;
  16262. return false;
  16263. }
  16264. function makePowerOfTwo( image ) {
  16265. if ( image instanceof HTMLImageElement || image instanceof HTMLCanvasElement ) {
  16266. var canvas = document.createElement( 'canvas' );
  16267. canvas.width = THREE.Math.nearestPowerOfTwo( image.width );
  16268. canvas.height = THREE.Math.nearestPowerOfTwo( image.height );
  16269. var context = canvas.getContext( '2d' );
  16270. context.drawImage( image, 0, 0, canvas.width, canvas.height );
  16271. console.warn( 'THREE.WebGLRenderer: image is not power of two (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
  16272. return canvas;
  16273. }
  16274. return image;
  16275. }
  16276. function setCubeTexture ( texture, slot ) {
  16277. var textureProperties = properties.get( texture );
  16278. if ( texture.image.length === 6 ) {
  16279. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  16280. if ( ! textureProperties.__image__webglTextureCube ) {
  16281. texture.addEventListener( 'dispose', onTextureDispose );
  16282. textureProperties.__image__webglTextureCube = _gl.createTexture();
  16283. _infoMemory.textures ++;
  16284. }
  16285. state.activeTexture( _gl.TEXTURE0 + slot );
  16286. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  16287. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  16288. var isCompressed = texture instanceof THREE.CompressedTexture;
  16289. var isDataTexture = texture.image[ 0 ] instanceof THREE.DataTexture;
  16290. var cubeImage = [];
  16291. for ( var i = 0; i < 6; i ++ ) {
  16292. if ( _this.autoScaleCubemaps && ! isCompressed && ! isDataTexture ) {
  16293. cubeImage[ i ] = clampToMaxSize( texture.image[ i ], capabilities.maxCubemapSize );
  16294. } else {
  16295. cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
  16296. }
  16297. }
  16298. var image = cubeImage[ 0 ],
  16299. isPowerOfTwoImage = isPowerOfTwo( image ),
  16300. glFormat = paramThreeToGL( texture.format ),
  16301. glType = paramThreeToGL( texture.type );
  16302. setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture, isPowerOfTwoImage );
  16303. for ( var i = 0; i < 6; i ++ ) {
  16304. if ( ! isCompressed ) {
  16305. if ( isDataTexture ) {
  16306. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
  16307. } else {
  16308. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, glFormat, glType, cubeImage[ i ] );
  16309. }
  16310. } else {
  16311. var mipmap, mipmaps = cubeImage[ i ].mipmaps;
  16312. for ( var j = 0, jl = mipmaps.length; j < jl; j ++ ) {
  16313. mipmap = mipmaps[ j ];
  16314. if ( texture.format !== THREE.RGBAFormat && texture.format !== THREE.RGBFormat ) {
  16315. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  16316. state.compressedTexImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  16317. } else {
  16318. console.warn( "THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setCubeTexture()" );
  16319. }
  16320. } else {
  16321. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  16322. }
  16323. }
  16324. }
  16325. }
  16326. if ( texture.generateMipmaps && isPowerOfTwoImage ) {
  16327. _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  16328. }
  16329. textureProperties.__version = texture.version;
  16330. if ( texture.onUpdate ) texture.onUpdate( texture );
  16331. } else {
  16332. state.activeTexture( _gl.TEXTURE0 + slot );
  16333. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  16334. }
  16335. }
  16336. }
  16337. function setCubeTextureDynamic ( texture, slot ) {
  16338. state.activeTexture( _gl.TEXTURE0 + slot );
  16339. state.bindTexture( _gl.TEXTURE_CUBE_MAP, properties.get( texture ).__webglTexture );
  16340. }
  16341. var setTextureWarned = false;
  16342. this.setTexture = function( texture, slot ) {
  16343. if ( ! setTextureWarned ) {
  16344. console.warn( "THREE.WebGLRenderer: .setTexture is deprecated, " +
  16345. "use setTexture2D instead." );
  16346. setTextureWarned = true;
  16347. }
  16348. setTexture2D( texture, slot );
  16349. };
  16350. this.allocTextureUnit = allocTextureUnit;
  16351. this.setTexture2D = setTexture2D;
  16352. this.setTextureCube = function( texture, slot ) {
  16353. if ( texture instanceof THREE.CubeTexture ||
  16354. ( Array.isArray( texture.image ) && texture.image.length === 6 ) ) {
  16355. // CompressedTexture can have Array in image :/
  16356. setCubeTexture( texture, slot );
  16357. } else {
  16358. // assumed: texture instanceof THREE.WebGLRenderTargetCube
  16359. setCubeTextureDynamic( texture.texture, slot );
  16360. }
  16361. };
  16362. // Render targets
  16363. // Setup storage for target texture and bind it to correct framebuffer
  16364. function setupFrameBufferTexture ( framebuffer, renderTarget, attachment, textureTarget ) {
  16365. var glFormat = paramThreeToGL( renderTarget.texture.format );
  16366. var glType = paramThreeToGL( renderTarget.texture.type );
  16367. state.texImage2D( textureTarget, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  16368. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  16369. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, attachment, textureTarget, properties.get( renderTarget.texture ).__webglTexture, 0 );
  16370. _gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
  16371. }
  16372. // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  16373. function setupRenderBufferStorage ( renderbuffer, renderTarget ) {
  16374. _gl.bindRenderbuffer( _gl.RENDERBUFFER, renderbuffer );
  16375. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  16376. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_COMPONENT16, renderTarget.width, renderTarget.height );
  16377. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  16378. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  16379. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_STENCIL, renderTarget.width, renderTarget.height );
  16380. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  16381. } else {
  16382. // FIXME: We don't support !depth !stencil
  16383. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.RGBA4, renderTarget.width, renderTarget.height );
  16384. }
  16385. _gl.bindRenderbuffer( _gl.RENDERBUFFER, null );
  16386. }
  16387. // Setup resources for a Depth Texture for a FBO (needs an extension)
  16388. function setupDepthTexture ( framebuffer, renderTarget ) {
  16389. var isCube = ( renderTarget instanceof THREE.WebGLRenderTargetCube );
  16390. if ( isCube ) throw new Error('Depth Texture with cube render targets is not supported!');
  16391. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  16392. if ( !( renderTarget.depthTexture instanceof THREE.DepthTexture ) ) {
  16393. throw new Error('renderTarget.depthTexture must be an instance of THREE.DepthTexture');
  16394. }
  16395. // upload an empty depth texture with framebuffer size
  16396. if ( !properties.get( renderTarget.depthTexture ).__webglTexture ||
  16397. renderTarget.depthTexture.image.width !== renderTarget.width ||
  16398. renderTarget.depthTexture.image.height !== renderTarget.height ) {
  16399. renderTarget.depthTexture.image.width = renderTarget.width;
  16400. renderTarget.depthTexture.image.height = renderTarget.height;
  16401. renderTarget.depthTexture.needsUpdate = true;
  16402. }
  16403. _this.setTexture( renderTarget.depthTexture, 0 );
  16404. var webglDepthTexture = properties.get( renderTarget.depthTexture ).__webglTexture;
  16405. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0 );
  16406. }
  16407. // Setup GL resources for a non-texture depth buffer
  16408. function setupDepthRenderbuffer( renderTarget ) {
  16409. var renderTargetProperties = properties.get( renderTarget );
  16410. var isCube = ( renderTarget instanceof THREE.WebGLRenderTargetCube );
  16411. if ( renderTarget.depthTexture ) {
  16412. if ( isCube ) throw new Error('target.depthTexture not supported in Cube render targets');
  16413. setupDepthTexture( renderTargetProperties.__webglFramebuffer, renderTarget );
  16414. } else {
  16415. if ( isCube ) {
  16416. renderTargetProperties.__webglDepthbuffer = [];
  16417. for ( var i = 0; i < 6; i ++ ) {
  16418. _gl.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer[ i ] );
  16419. renderTargetProperties.__webglDepthbuffer[ i ] = _gl.createRenderbuffer();
  16420. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer[ i ], renderTarget );
  16421. }
  16422. } else {
  16423. _gl.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer );
  16424. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  16425. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer, renderTarget );
  16426. }
  16427. }
  16428. _gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
  16429. }
  16430. // Set up GL resources for the render target
  16431. function setupRenderTarget( renderTarget ) {
  16432. var renderTargetProperties = properties.get( renderTarget );
  16433. var textureProperties = properties.get( renderTarget.texture );
  16434. renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
  16435. textureProperties.__webglTexture = _gl.createTexture();
  16436. _infoMemory.textures ++;
  16437. var isCube = ( renderTarget instanceof THREE.WebGLRenderTargetCube );
  16438. var isTargetPowerOfTwo = THREE.Math.isPowerOfTwo( renderTarget.width ) && THREE.Math.isPowerOfTwo( renderTarget.height );
  16439. // Setup framebuffer
  16440. if ( isCube ) {
  16441. renderTargetProperties.__webglFramebuffer = [];
  16442. for ( var i = 0; i < 6; i ++ ) {
  16443. renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer();
  16444. }
  16445. } else {
  16446. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  16447. }
  16448. // Setup color buffer
  16449. if ( isCube ) {
  16450. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__webglTexture );
  16451. setTextureParameters( _gl.TEXTURE_CUBE_MAP, renderTarget.texture, isTargetPowerOfTwo );
  16452. for ( var i = 0; i < 6; i ++ ) {
  16453. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i );
  16454. }
  16455. if ( renderTarget.texture.generateMipmaps && isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  16456. state.bindTexture( _gl.TEXTURE_CUBE_MAP, null );
  16457. } else {
  16458. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  16459. setTextureParameters( _gl.TEXTURE_2D, renderTarget.texture, isTargetPowerOfTwo );
  16460. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_2D );
  16461. if ( renderTarget.texture.generateMipmaps && isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_2D );
  16462. state.bindTexture( _gl.TEXTURE_2D, null );
  16463. }
  16464. // Setup depth and stencil buffers
  16465. if ( renderTarget.depthBuffer ) {
  16466. setupDepthRenderbuffer( renderTarget );
  16467. }
  16468. }
  16469. this.getCurrentRenderTarget = function() {
  16470. return _currentRenderTarget;
  16471. };
  16472. this.setRenderTarget = function ( renderTarget ) {
  16473. _currentRenderTarget = renderTarget;
  16474. if ( renderTarget && properties.get( renderTarget ).__webglFramebuffer === undefined ) {
  16475. setupRenderTarget( renderTarget );
  16476. }
  16477. var isCube = ( renderTarget instanceof THREE.WebGLRenderTargetCube );
  16478. var framebuffer;
  16479. if ( renderTarget ) {
  16480. var renderTargetProperties = properties.get( renderTarget );
  16481. if ( isCube ) {
  16482. framebuffer = renderTargetProperties.__webglFramebuffer[ renderTarget.activeCubeFace ];
  16483. } else {
  16484. framebuffer = renderTargetProperties.__webglFramebuffer;
  16485. }
  16486. _currentScissor.copy( renderTarget.scissor );
  16487. _currentScissorTest = renderTarget.scissorTest;
  16488. _currentViewport.copy( renderTarget.viewport );
  16489. } else {
  16490. framebuffer = null;
  16491. _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio );
  16492. _currentScissorTest = _scissorTest;
  16493. _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio );
  16494. }
  16495. if ( _currentFramebuffer !== framebuffer ) {
  16496. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  16497. _currentFramebuffer = framebuffer;
  16498. }
  16499. state.scissor( _currentScissor );
  16500. state.setScissorTest( _currentScissorTest );
  16501. state.viewport( _currentViewport );
  16502. if ( isCube ) {
  16503. var textureProperties = properties.get( renderTarget.texture );
  16504. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + renderTarget.activeCubeFace, textureProperties.__webglTexture, renderTarget.activeMipMapLevel );
  16505. }
  16506. };
  16507. this.readRenderTargetPixels = function ( renderTarget, x, y, width, height, buffer ) {
  16508. if ( renderTarget instanceof THREE.WebGLRenderTarget === false ) {
  16509. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
  16510. return;
  16511. }
  16512. var framebuffer = properties.get( renderTarget ).__webglFramebuffer;
  16513. if ( framebuffer ) {
  16514. var restore = false;
  16515. if ( framebuffer !== _currentFramebuffer ) {
  16516. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  16517. restore = true;
  16518. }
  16519. try {
  16520. var texture = renderTarget.texture;
  16521. if ( texture.format !== THREE.RGBAFormat && paramThreeToGL( texture.format ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_FORMAT ) ) {
  16522. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
  16523. return;
  16524. }
  16525. if ( texture.type !== THREE.UnsignedByteType &&
  16526. paramThreeToGL( texture.type ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_TYPE ) &&
  16527. ! ( texture.type === THREE.FloatType && extensions.get( 'WEBGL_color_buffer_float' ) ) &&
  16528. ! ( texture.type === THREE.HalfFloatType && extensions.get( 'EXT_color_buffer_half_float' ) ) ) {
  16529. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' );
  16530. return;
  16531. }
  16532. if ( _gl.checkFramebufferStatus( _gl.FRAMEBUFFER ) === _gl.FRAMEBUFFER_COMPLETE ) {
  16533. // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
  16534. if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {
  16535. _gl.readPixels( x, y, width, height, paramThreeToGL( texture.format ), paramThreeToGL( texture.type ), buffer );
  16536. }
  16537. } else {
  16538. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );
  16539. }
  16540. } finally {
  16541. if ( restore ) {
  16542. _gl.bindFramebuffer( _gl.FRAMEBUFFER, _currentFramebuffer );
  16543. }
  16544. }
  16545. }
  16546. };
  16547. function updateRenderTargetMipmap( renderTarget ) {
  16548. var target = renderTarget instanceof THREE.WebGLRenderTargetCube ? _gl.TEXTURE_CUBE_MAP : _gl.TEXTURE_2D;
  16549. var texture = properties.get( renderTarget.texture ).__webglTexture;
  16550. state.bindTexture( target, texture );
  16551. _gl.generateMipmap( target );
  16552. state.bindTexture( target, null );
  16553. }
  16554. // Fallback filters for non-power-of-2 textures
  16555. function filterFallback ( f ) {
  16556. if ( f === THREE.NearestFilter || f === THREE.NearestMipMapNearestFilter || f === THREE.NearestMipMapLinearFilter ) {
  16557. return _gl.NEAREST;
  16558. }
  16559. return _gl.LINEAR;
  16560. }
  16561. // Map three.js constants to WebGL constants
  16562. function paramThreeToGL ( p ) {
  16563. var extension;
  16564. if ( p === THREE.RepeatWrapping ) return _gl.REPEAT;
  16565. if ( p === THREE.ClampToEdgeWrapping ) return _gl.CLAMP_TO_EDGE;
  16566. if ( p === THREE.MirroredRepeatWrapping ) return _gl.MIRRORED_REPEAT;
  16567. if ( p === THREE.NearestFilter ) return _gl.NEAREST;
  16568. if ( p === THREE.NearestMipMapNearestFilter ) return _gl.NEAREST_MIPMAP_NEAREST;
  16569. if ( p === THREE.NearestMipMapLinearFilter ) return _gl.NEAREST_MIPMAP_LINEAR;
  16570. if ( p === THREE.LinearFilter ) return _gl.LINEAR;
  16571. if ( p === THREE.LinearMipMapNearestFilter ) return _gl.LINEAR_MIPMAP_NEAREST;
  16572. if ( p === THREE.LinearMipMapLinearFilter ) return _gl.LINEAR_MIPMAP_LINEAR;
  16573. if ( p === THREE.UnsignedByteType ) return _gl.UNSIGNED_BYTE;
  16574. if ( p === THREE.UnsignedShort4444Type ) return _gl.UNSIGNED_SHORT_4_4_4_4;
  16575. if ( p === THREE.UnsignedShort5551Type ) return _gl.UNSIGNED_SHORT_5_5_5_1;
  16576. if ( p === THREE.UnsignedShort565Type ) return _gl.UNSIGNED_SHORT_5_6_5;
  16577. if ( p === THREE.ByteType ) return _gl.BYTE;
  16578. if ( p === THREE.ShortType ) return _gl.SHORT;
  16579. if ( p === THREE.UnsignedShortType ) return _gl.UNSIGNED_SHORT;
  16580. if ( p === THREE.IntType ) return _gl.INT;
  16581. if ( p === THREE.UnsignedIntType ) return _gl.UNSIGNED_INT;
  16582. if ( p === THREE.FloatType ) return _gl.FLOAT;
  16583. extension = extensions.get( 'OES_texture_half_float' );
  16584. if ( extension !== null ) {
  16585. if ( p === THREE.HalfFloatType ) return extension.HALF_FLOAT_OES;
  16586. }
  16587. if ( p === THREE.AlphaFormat ) return _gl.ALPHA;
  16588. if ( p === THREE.RGBFormat ) return _gl.RGB;
  16589. if ( p === THREE.RGBAFormat ) return _gl.RGBA;
  16590. if ( p === THREE.LuminanceFormat ) return _gl.LUMINANCE;
  16591. if ( p === THREE.LuminanceAlphaFormat ) return _gl.LUMINANCE_ALPHA;
  16592. if ( p === THREE.DepthFormat ) return _gl.DEPTH_COMPONENT;
  16593. if ( p === THREE.AddEquation ) return _gl.FUNC_ADD;
  16594. if ( p === THREE.SubtractEquation ) return _gl.FUNC_SUBTRACT;
  16595. if ( p === THREE.ReverseSubtractEquation ) return _gl.FUNC_REVERSE_SUBTRACT;
  16596. if ( p === THREE.ZeroFactor ) return _gl.ZERO;
  16597. if ( p === THREE.OneFactor ) return _gl.ONE;
  16598. if ( p === THREE.SrcColorFactor ) return _gl.SRC_COLOR;
  16599. if ( p === THREE.OneMinusSrcColorFactor ) return _gl.ONE_MINUS_SRC_COLOR;
  16600. if ( p === THREE.SrcAlphaFactor ) return _gl.SRC_ALPHA;
  16601. if ( p === THREE.OneMinusSrcAlphaFactor ) return _gl.ONE_MINUS_SRC_ALPHA;
  16602. if ( p === THREE.DstAlphaFactor ) return _gl.DST_ALPHA;
  16603. if ( p === THREE.OneMinusDstAlphaFactor ) return _gl.ONE_MINUS_DST_ALPHA;
  16604. if ( p === THREE.DstColorFactor ) return _gl.DST_COLOR;
  16605. if ( p === THREE.OneMinusDstColorFactor ) return _gl.ONE_MINUS_DST_COLOR;
  16606. if ( p === THREE.SrcAlphaSaturateFactor ) return _gl.SRC_ALPHA_SATURATE;
  16607. extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );
  16608. if ( extension !== null ) {
  16609. if ( p === THREE.RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  16610. if ( p === THREE.RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  16611. if ( p === THREE.RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  16612. if ( p === THREE.RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  16613. }
  16614. extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  16615. if ( extension !== null ) {
  16616. if ( p === THREE.RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  16617. if ( p === THREE.RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  16618. if ( p === THREE.RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  16619. if ( p === THREE.RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  16620. }
  16621. extension = extensions.get( 'WEBGL_compressed_texture_etc1' );
  16622. if ( extension !== null ) {
  16623. if ( p === THREE.RGB_ETC1_Format ) return extension.COMPRESSED_RGB_ETC1_WEBGL;
  16624. }
  16625. extension = extensions.get( 'EXT_blend_minmax' );
  16626. if ( extension !== null ) {
  16627. if ( p === THREE.MinEquation ) return extension.MIN_EXT;
  16628. if ( p === THREE.MaxEquation ) return extension.MAX_EXT;
  16629. }
  16630. return 0;
  16631. }
  16632. };
  16633. // File:src/renderers/WebGLRenderTarget.js
  16634. /**
  16635. * @author szimek / https://github.com/szimek/
  16636. * @author alteredq / http://alteredqualia.com/
  16637. * @author Marius Kintel / https://github.com/kintel
  16638. */
  16639. /*
  16640. In options, we can specify:
  16641. * Texture parameters for an auto-generated target texture
  16642. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  16643. */
  16644. THREE.WebGLRenderTarget = function ( width, height, options ) {
  16645. this.uuid = THREE.Math.generateUUID();
  16646. this.width = width;
  16647. this.height = height;
  16648. this.scissor = new THREE.Vector4( 0, 0, width, height );
  16649. this.scissorTest = false;
  16650. this.viewport = new THREE.Vector4( 0, 0, width, height );
  16651. options = options || {};
  16652. if ( options.minFilter === undefined ) options.minFilter = THREE.LinearFilter;
  16653. this.texture = new THREE.Texture( undefined, undefined, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding );
  16654. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  16655. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;
  16656. this.depthTexture = null;
  16657. };
  16658. THREE.WebGLRenderTarget.prototype = {
  16659. constructor: THREE.WebGLRenderTarget,
  16660. setSize: function ( width, height ) {
  16661. if ( this.width !== width || this.height !== height ) {
  16662. this.width = width;
  16663. this.height = height;
  16664. this.dispose();
  16665. }
  16666. this.viewport.set( 0, 0, width, height );
  16667. this.scissor.set( 0, 0, width, height );
  16668. },
  16669. clone: function () {
  16670. return new this.constructor().copy( this );
  16671. },
  16672. copy: function ( source ) {
  16673. this.width = source.width;
  16674. this.height = source.height;
  16675. this.viewport.copy( source.viewport );
  16676. this.texture = source.texture.clone();
  16677. this.depthBuffer = source.depthBuffer;
  16678. this.stencilBuffer = source.stencilBuffer;
  16679. this.depthTexture = source.depthTexture;
  16680. return this;
  16681. },
  16682. dispose: function () {
  16683. this.dispatchEvent( { type: 'dispose' } );
  16684. }
  16685. };
  16686. THREE.EventDispatcher.prototype.apply( THREE.WebGLRenderTarget.prototype );
  16687. // File:src/renderers/WebGLRenderTargetCube.js
  16688. /**
  16689. * @author alteredq / http://alteredqualia.com
  16690. */
  16691. THREE.WebGLRenderTargetCube = function ( width, height, options ) {
  16692. THREE.WebGLRenderTarget.call( this, width, height, options );
  16693. this.activeCubeFace = 0; // PX 0, NX 1, PY 2, NY 3, PZ 4, NZ 5
  16694. this.activeMipMapLevel = 0;
  16695. };
  16696. THREE.WebGLRenderTargetCube.prototype = Object.create( THREE.WebGLRenderTarget.prototype );
  16697. THREE.WebGLRenderTargetCube.prototype.constructor = THREE.WebGLRenderTargetCube;
  16698. // File:src/renderers/webgl/WebGLBufferRenderer.js
  16699. /**
  16700. * @author mrdoob / http://mrdoob.com/
  16701. */
  16702. THREE.WebGLBufferRenderer = function ( _gl, extensions, _infoRender ) {
  16703. var mode;
  16704. function setMode( value ) {
  16705. mode = value;
  16706. }
  16707. function render( start, count ) {
  16708. _gl.drawArrays( mode, start, count );
  16709. _infoRender.calls ++;
  16710. _infoRender.vertices += count;
  16711. if ( mode === _gl.TRIANGLES ) _infoRender.faces += count / 3;
  16712. }
  16713. function renderInstances( geometry ) {
  16714. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  16715. if ( extension === null ) {
  16716. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  16717. return;
  16718. }
  16719. var position = geometry.attributes.position;
  16720. var count = 0;
  16721. if ( position instanceof THREE.InterleavedBufferAttribute ) {
  16722. count = position.data.count;
  16723. extension.drawArraysInstancedANGLE( mode, 0, count, geometry.maxInstancedCount );
  16724. } else {
  16725. count = position.count;
  16726. extension.drawArraysInstancedANGLE( mode, 0, count, geometry.maxInstancedCount );
  16727. }
  16728. _infoRender.calls ++;
  16729. _infoRender.vertices += count * geometry.maxInstancedCount;
  16730. if ( mode === _gl.TRIANGLES ) _infoRender.faces += geometry.maxInstancedCount * count / 3;
  16731. }
  16732. this.setMode = setMode;
  16733. this.render = render;
  16734. this.renderInstances = renderInstances;
  16735. };
  16736. // File:src/renderers/webgl/WebGLIndexedBufferRenderer.js
  16737. /**
  16738. * @author mrdoob / http://mrdoob.com/
  16739. */
  16740. THREE.WebGLIndexedBufferRenderer = function ( _gl, extensions, _infoRender ) {
  16741. var mode;
  16742. function setMode( value ) {
  16743. mode = value;
  16744. }
  16745. var type, size;
  16746. function setIndex( index ) {
  16747. if ( index.array instanceof Uint32Array && extensions.get( 'OES_element_index_uint' ) ) {
  16748. type = _gl.UNSIGNED_INT;
  16749. size = 4;
  16750. } else {
  16751. type = _gl.UNSIGNED_SHORT;
  16752. size = 2;
  16753. }
  16754. }
  16755. function render( start, count ) {
  16756. _gl.drawElements( mode, count, type, start * size );
  16757. _infoRender.calls ++;
  16758. _infoRender.vertices += count;
  16759. if ( mode === _gl.TRIANGLES ) _infoRender.faces += count / 3;
  16760. }
  16761. function renderInstances( geometry, start, count ) {
  16762. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  16763. if ( extension === null ) {
  16764. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  16765. return;
  16766. }
  16767. extension.drawElementsInstancedANGLE( mode, count, type, start * size, geometry.maxInstancedCount );
  16768. _infoRender.calls ++;
  16769. _infoRender.vertices += count * geometry.maxInstancedCount;
  16770. if ( mode === _gl.TRIANGLES ) _infoRender.faces += geometry.maxInstancedCount * count / 3;
  16771. }
  16772. this.setMode = setMode;
  16773. this.setIndex = setIndex;
  16774. this.render = render;
  16775. this.renderInstances = renderInstances;
  16776. };
  16777. // File:src/renderers/webgl/WebGLExtensions.js
  16778. /**
  16779. * @author mrdoob / http://mrdoob.com/
  16780. */
  16781. THREE.WebGLExtensions = function ( gl ) {
  16782. var extensions = {};
  16783. this.get = function ( name ) {
  16784. if ( extensions[ name ] !== undefined ) {
  16785. return extensions[ name ];
  16786. }
  16787. var extension;
  16788. switch ( name ) {
  16789. case 'WEBGL_depth_texture':
  16790. extension = gl.getExtension( 'WEBGL_depth_texture' ) || gl.getExtension( 'MOZ_WEBGL_depth_texture' ) || gl.getExtension( 'WEBKIT_WEBGL_depth_texture' );
  16791. case 'EXT_texture_filter_anisotropic':
  16792. extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' );
  16793. break;
  16794. case 'WEBGL_compressed_texture_s3tc':
  16795. extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' );
  16796. break;
  16797. case 'WEBGL_compressed_texture_pvrtc':
  16798. extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' );
  16799. break;
  16800. case 'WEBGL_compressed_texture_etc1':
  16801. extension = gl.getExtension( 'WEBGL_compressed_texture_etc1' );
  16802. break;
  16803. default:
  16804. extension = gl.getExtension( name );
  16805. }
  16806. if ( extension === null ) {
  16807. console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
  16808. }
  16809. extensions[ name ] = extension;
  16810. return extension;
  16811. };
  16812. };
  16813. // File:src/renderers/webgl/WebGLCapabilities.js
  16814. THREE.WebGLCapabilities = function ( gl, extensions, parameters ) {
  16815. function getMaxPrecision( precision ) {
  16816. if ( precision === 'highp' ) {
  16817. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.HIGH_FLOAT ).precision > 0 &&
  16818. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.HIGH_FLOAT ).precision > 0 ) {
  16819. return 'highp';
  16820. }
  16821. precision = 'mediump';
  16822. }
  16823. if ( precision === 'mediump' ) {
  16824. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.MEDIUM_FLOAT ).precision > 0 &&
  16825. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.MEDIUM_FLOAT ).precision > 0 ) {
  16826. return 'mediump';
  16827. }
  16828. }
  16829. return 'lowp';
  16830. }
  16831. this.getMaxPrecision = getMaxPrecision;
  16832. this.precision = parameters.precision !== undefined ? parameters.precision : 'highp',
  16833. this.logarithmicDepthBuffer = parameters.logarithmicDepthBuffer !== undefined ? parameters.logarithmicDepthBuffer : false;
  16834. this.maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
  16835. this.maxVertexTextures = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS );
  16836. this.maxTextureSize = gl.getParameter( gl.MAX_TEXTURE_SIZE );
  16837. this.maxCubemapSize = gl.getParameter( gl.MAX_CUBE_MAP_TEXTURE_SIZE );
  16838. this.maxAttributes = gl.getParameter( gl.MAX_VERTEX_ATTRIBS );
  16839. this.maxVertexUniforms = gl.getParameter( gl.MAX_VERTEX_UNIFORM_VECTORS );
  16840. this.maxVaryings = gl.getParameter( gl.MAX_VARYING_VECTORS );
  16841. this.maxFragmentUniforms = gl.getParameter( gl.MAX_FRAGMENT_UNIFORM_VECTORS );
  16842. this.vertexTextures = this.maxVertexTextures > 0;
  16843. this.floatFragmentTextures = !! extensions.get( 'OES_texture_float' );
  16844. this.floatVertexTextures = this.vertexTextures && this.floatFragmentTextures;
  16845. var _maxPrecision = getMaxPrecision( this.precision );
  16846. if ( _maxPrecision !== this.precision ) {
  16847. console.warn( 'THREE.WebGLRenderer:', this.precision, 'not supported, using', _maxPrecision, 'instead.' );
  16848. this.precision = _maxPrecision;
  16849. }
  16850. if ( this.logarithmicDepthBuffer ) {
  16851. this.logarithmicDepthBuffer = !! extensions.get( 'EXT_frag_depth' );
  16852. }
  16853. };
  16854. // File:src/renderers/webgl/WebGLGeometries.js
  16855. /**
  16856. * @author mrdoob / http://mrdoob.com/
  16857. */
  16858. THREE.WebGLGeometries = function ( gl, properties, info ) {
  16859. var geometries = {};
  16860. function get( object ) {
  16861. var geometry = object.geometry;
  16862. if ( geometries[ geometry.id ] !== undefined ) {
  16863. return geometries[ geometry.id ];
  16864. }
  16865. geometry.addEventListener( 'dispose', onGeometryDispose );
  16866. var buffergeometry;
  16867. if ( geometry instanceof THREE.BufferGeometry ) {
  16868. buffergeometry = geometry;
  16869. } else if ( geometry instanceof THREE.Geometry ) {
  16870. if ( geometry._bufferGeometry === undefined ) {
  16871. geometry._bufferGeometry = new THREE.BufferGeometry().setFromObject( object );
  16872. }
  16873. buffergeometry = geometry._bufferGeometry;
  16874. }
  16875. geometries[ geometry.id ] = buffergeometry;
  16876. info.memory.geometries ++;
  16877. return buffergeometry;
  16878. }
  16879. function onGeometryDispose( event ) {
  16880. var geometry = event.target;
  16881. var buffergeometry = geometries[ geometry.id ];
  16882. if ( buffergeometry.index !== null ) {
  16883. deleteAttribute( buffergeometry.index );
  16884. }
  16885. deleteAttributes( buffergeometry.attributes );
  16886. geometry.removeEventListener( 'dispose', onGeometryDispose );
  16887. delete geometries[ geometry.id ];
  16888. // TODO
  16889. var property = properties.get( geometry );
  16890. if ( property.wireframe ) {
  16891. deleteAttribute( property.wireframe );
  16892. }
  16893. properties.delete( geometry );
  16894. var bufferproperty = properties.get( buffergeometry );
  16895. if ( bufferproperty.wireframe ) {
  16896. deleteAttribute( bufferproperty.wireframe );
  16897. }
  16898. properties.delete( buffergeometry );
  16899. //
  16900. info.memory.geometries --;
  16901. }
  16902. function getAttributeBuffer( attribute ) {
  16903. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  16904. return properties.get( attribute.data ).__webglBuffer;
  16905. }
  16906. return properties.get( attribute ).__webglBuffer;
  16907. }
  16908. function deleteAttribute( attribute ) {
  16909. var buffer = getAttributeBuffer( attribute );
  16910. if ( buffer !== undefined ) {
  16911. gl.deleteBuffer( buffer );
  16912. removeAttributeBuffer( attribute );
  16913. }
  16914. }
  16915. function deleteAttributes( attributes ) {
  16916. for ( var name in attributes ) {
  16917. deleteAttribute( attributes[ name ] );
  16918. }
  16919. }
  16920. function removeAttributeBuffer( attribute ) {
  16921. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  16922. properties.delete( attribute.data );
  16923. } else {
  16924. properties.delete( attribute );
  16925. }
  16926. }
  16927. this.get = get;
  16928. };
  16929. // File:src/renderers/webgl/WebGLLights.js
  16930. /**
  16931. * @author mrdoob / http://mrdoob.com/
  16932. */
  16933. THREE.WebGLLights = function () {
  16934. var lights = {};
  16935. this.get = function ( light ) {
  16936. if ( lights[ light.id ] !== undefined ) {
  16937. return lights[ light.id ];
  16938. }
  16939. var uniforms;
  16940. switch ( light.type ) {
  16941. case 'DirectionalLight':
  16942. uniforms = {
  16943. direction: new THREE.Vector3(),
  16944. color: new THREE.Color(),
  16945. shadow: false,
  16946. shadowBias: 0,
  16947. shadowRadius: 1,
  16948. shadowMapSize: new THREE.Vector2()
  16949. };
  16950. break;
  16951. case 'SpotLight':
  16952. uniforms = {
  16953. position: new THREE.Vector3(),
  16954. direction: new THREE.Vector3(),
  16955. color: new THREE.Color(),
  16956. distance: 0,
  16957. coneCos: 0,
  16958. penumbraCos: 0,
  16959. decay: 0,
  16960. shadow: false,
  16961. shadowBias: 0,
  16962. shadowRadius: 1,
  16963. shadowMapSize: new THREE.Vector2()
  16964. };
  16965. break;
  16966. case 'PointLight':
  16967. uniforms = {
  16968. position: new THREE.Vector3(),
  16969. color: new THREE.Color(),
  16970. distance: 0,
  16971. decay: 0,
  16972. shadow: false,
  16973. shadowBias: 0,
  16974. shadowRadius: 1,
  16975. shadowMapSize: new THREE.Vector2()
  16976. };
  16977. break;
  16978. case 'HemisphereLight':
  16979. uniforms = {
  16980. direction: new THREE.Vector3(),
  16981. skyColor: new THREE.Color(),
  16982. groundColor: new THREE.Color()
  16983. };
  16984. break;
  16985. }
  16986. lights[ light.id ] = uniforms;
  16987. return uniforms;
  16988. };
  16989. };
  16990. // File:src/renderers/webgl/WebGLObjects.js
  16991. /**
  16992. * @author mrdoob / http://mrdoob.com/
  16993. */
  16994. THREE.WebGLObjects = function ( gl, properties, info ) {
  16995. var geometries = new THREE.WebGLGeometries( gl, properties, info );
  16996. //
  16997. function update( object ) {
  16998. // TODO: Avoid updating twice (when using shadowMap). Maybe add frame counter.
  16999. var geometry = geometries.get( object );
  17000. if ( object.geometry instanceof THREE.Geometry ) {
  17001. geometry.updateFromObject( object );
  17002. }
  17003. var index = geometry.index;
  17004. var attributes = geometry.attributes;
  17005. if ( index !== null ) {
  17006. updateAttribute( index, gl.ELEMENT_ARRAY_BUFFER );
  17007. }
  17008. for ( var name in attributes ) {
  17009. updateAttribute( attributes[ name ], gl.ARRAY_BUFFER );
  17010. }
  17011. // morph targets
  17012. var morphAttributes = geometry.morphAttributes;
  17013. for ( var name in morphAttributes ) {
  17014. var array = morphAttributes[ name ];
  17015. for ( var i = 0, l = array.length; i < l; i ++ ) {
  17016. updateAttribute( array[ i ], gl.ARRAY_BUFFER );
  17017. }
  17018. }
  17019. return geometry;
  17020. }
  17021. function updateAttribute( attribute, bufferType ) {
  17022. var data = ( attribute instanceof THREE.InterleavedBufferAttribute ) ? attribute.data : attribute;
  17023. var attributeProperties = properties.get( data );
  17024. if ( attributeProperties.__webglBuffer === undefined ) {
  17025. createBuffer( attributeProperties, data, bufferType );
  17026. } else if ( attributeProperties.version !== data.version ) {
  17027. updateBuffer( attributeProperties, data, bufferType );
  17028. }
  17029. }
  17030. function createBuffer( attributeProperties, data, bufferType ) {
  17031. attributeProperties.__webglBuffer = gl.createBuffer();
  17032. gl.bindBuffer( bufferType, attributeProperties.__webglBuffer );
  17033. var usage = data.dynamic ? gl.DYNAMIC_DRAW : gl.STATIC_DRAW;
  17034. gl.bufferData( bufferType, data.array, usage );
  17035. attributeProperties.version = data.version;
  17036. }
  17037. function updateBuffer( attributeProperties, data, bufferType ) {
  17038. gl.bindBuffer( bufferType, attributeProperties.__webglBuffer );
  17039. if ( data.dynamic === false || data.updateRange.count === - 1 ) {
  17040. // Not using update ranges
  17041. gl.bufferSubData( bufferType, 0, data.array );
  17042. } else if ( data.updateRange.count === 0 ) {
  17043. 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.' );
  17044. } else {
  17045. gl.bufferSubData( bufferType, data.updateRange.offset * data.array.BYTES_PER_ELEMENT,
  17046. data.array.subarray( data.updateRange.offset, data.updateRange.offset + data.updateRange.count ) );
  17047. data.updateRange.count = 0; // reset range
  17048. }
  17049. attributeProperties.version = data.version;
  17050. }
  17051. function getAttributeBuffer( attribute ) {
  17052. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  17053. return properties.get( attribute.data ).__webglBuffer;
  17054. }
  17055. return properties.get( attribute ).__webglBuffer;
  17056. }
  17057. function getWireframeAttribute( geometry ) {
  17058. var property = properties.get( geometry );
  17059. if ( property.wireframe !== undefined ) {
  17060. return property.wireframe;
  17061. }
  17062. var indices = [];
  17063. var index = geometry.index;
  17064. var attributes = geometry.attributes;
  17065. var position = attributes.position;
  17066. // console.time( 'wireframe' );
  17067. if ( index !== null ) {
  17068. var edges = {};
  17069. var array = index.array;
  17070. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  17071. var a = array[ i + 0 ];
  17072. var b = array[ i + 1 ];
  17073. var c = array[ i + 2 ];
  17074. if ( checkEdge( edges, a, b ) ) indices.push( a, b );
  17075. if ( checkEdge( edges, b, c ) ) indices.push( b, c );
  17076. if ( checkEdge( edges, c, a ) ) indices.push( c, a );
  17077. }
  17078. } else {
  17079. var array = attributes.position.array;
  17080. for ( var i = 0, l = ( array.length / 3 ) - 1; i < l; i += 3 ) {
  17081. var a = i + 0;
  17082. var b = i + 1;
  17083. var c = i + 2;
  17084. indices.push( a, b, b, c, c, a );
  17085. }
  17086. }
  17087. // console.timeEnd( 'wireframe' );
  17088. var TypeArray = position.count > 65535 ? Uint32Array : Uint16Array;
  17089. var attribute = new THREE.BufferAttribute( new TypeArray( indices ), 1 );
  17090. updateAttribute( attribute, gl.ELEMENT_ARRAY_BUFFER );
  17091. property.wireframe = attribute;
  17092. return attribute;
  17093. }
  17094. function checkEdge( edges, a, b ) {
  17095. if ( a > b ) {
  17096. var tmp = a;
  17097. a = b;
  17098. b = tmp;
  17099. }
  17100. var list = edges[ a ];
  17101. if ( list === undefined ) {
  17102. edges[ a ] = [ b ];
  17103. return true;
  17104. } else if ( list.indexOf( b ) === -1 ) {
  17105. list.push( b );
  17106. return true;
  17107. }
  17108. return false;
  17109. }
  17110. this.getAttributeBuffer = getAttributeBuffer;
  17111. this.getWireframeAttribute = getWireframeAttribute;
  17112. this.update = update;
  17113. };
  17114. // File:src/renderers/webgl/WebGLProgram.js
  17115. THREE.WebGLProgram = ( function () {
  17116. var programIdCount = 0;
  17117. function getEncodingComponents( encoding ) {
  17118. switch ( encoding ) {
  17119. case THREE.LinearEncoding:
  17120. return [ 'Linear','( value )' ];
  17121. case THREE.sRGBEncoding:
  17122. return [ 'sRGB','( value )' ];
  17123. case THREE.RGBEEncoding:
  17124. return [ 'RGBE','( value )' ];
  17125. case THREE.RGBM7Encoding:
  17126. return [ 'RGBM','( value, 7.0 )' ];
  17127. case THREE.RGBM16Encoding:
  17128. return [ 'RGBM','( value, 16.0 )' ];
  17129. case THREE.RGBDEncoding:
  17130. return [ 'RGBD','( value, 256.0 )' ];
  17131. case THREE.GammaEncoding:
  17132. return [ 'Gamma','( value, float( GAMMA_FACTOR ) )' ];
  17133. default:
  17134. throw new Error( 'unsupported encoding: ' + encoding );
  17135. }
  17136. }
  17137. function getTexelDecodingFunction( functionName, encoding ) {
  17138. var components = getEncodingComponents( encoding );
  17139. return "vec4 " + functionName + "( vec4 value ) { return " + components[ 0 ] + "ToLinear" + components[ 1 ] + "; }";
  17140. }
  17141. function getTexelEncodingFunction( functionName, encoding ) {
  17142. var components = getEncodingComponents( encoding );
  17143. return "vec4 " + functionName + "( vec4 value ) { return LinearTo" + components[ 0 ] + components[ 1 ] + "; }";
  17144. }
  17145. function getToneMappingFunction( functionName, toneMapping ) {
  17146. var toneMappingName;
  17147. switch ( toneMapping ) {
  17148. case THREE.LinearToneMapping:
  17149. toneMappingName = "Linear";
  17150. break;
  17151. case THREE.ReinhardToneMapping:
  17152. toneMappingName = "Reinhard";
  17153. break;
  17154. case THREE.Uncharted2ToneMapping:
  17155. toneMappingName = "Uncharted2";
  17156. break;
  17157. case THREE.CineonToneMapping:
  17158. toneMappingName = "OptimizedCineon";
  17159. break;
  17160. default:
  17161. throw new Error( 'unsupported toneMapping: ' + toneMapping );
  17162. }
  17163. return "vec3 " + functionName + "( vec3 color ) { return " + toneMappingName + "ToneMapping( color ); }";
  17164. }
  17165. function generateExtensions( extensions, parameters, rendererExtensions ) {
  17166. extensions = extensions || {};
  17167. var chunks = [
  17168. ( extensions.derivatives || parameters.envMapCubeUV || parameters.bumpMap || parameters.normalMap || parameters.flatShading ) ? '#extension GL_OES_standard_derivatives : enable' : '',
  17169. ( extensions.fragDepth || parameters.logarithmicDepthBuffer ) && rendererExtensions.get( 'EXT_frag_depth' ) ? '#extension GL_EXT_frag_depth : enable' : '',
  17170. ( extensions.drawBuffers ) && rendererExtensions.get( 'WEBGL_draw_buffers' ) ? '#extension GL_EXT_draw_buffers : require' : '',
  17171. ( extensions.shaderTextureLOD || parameters.envMap ) && rendererExtensions.get( 'EXT_shader_texture_lod' ) ? '#extension GL_EXT_shader_texture_lod : enable' : '',
  17172. ];
  17173. return chunks.filter( filterEmptyLine ).join( '\n' );
  17174. }
  17175. function generateDefines( defines ) {
  17176. var chunks = [];
  17177. for ( var name in defines ) {
  17178. var value = defines[ name ];
  17179. if ( value === false ) continue;
  17180. chunks.push( '#define ' + name + ' ' + value );
  17181. }
  17182. return chunks.join( '\n' );
  17183. }
  17184. function fetchAttributeLocations( gl, program, identifiers ) {
  17185. var attributes = {};
  17186. var n = gl.getProgramParameter( program, gl.ACTIVE_ATTRIBUTES );
  17187. for ( var i = 0; i < n; i ++ ) {
  17188. var info = gl.getActiveAttrib( program, i );
  17189. var name = info.name;
  17190. // console.log("THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:", name, i );
  17191. attributes[ name ] = gl.getAttribLocation( program, name );
  17192. }
  17193. return attributes;
  17194. }
  17195. function filterEmptyLine( string ) {
  17196. return string !== '';
  17197. }
  17198. function replaceLightNums( string, parameters ) {
  17199. return string
  17200. .replace( /NUM_DIR_LIGHTS/g, parameters.numDirLights )
  17201. .replace( /NUM_SPOT_LIGHTS/g, parameters.numSpotLights )
  17202. .replace( /NUM_POINT_LIGHTS/g, parameters.numPointLights )
  17203. .replace( /NUM_HEMI_LIGHTS/g, parameters.numHemiLights );
  17204. }
  17205. function parseIncludes( string ) {
  17206. var pattern = /#include +<([\w\d.]+)>/g;
  17207. function replace( match, include ) {
  17208. var replace = THREE.ShaderChunk[ include ];
  17209. if ( replace === undefined ) {
  17210. throw new Error( 'Can not resolve #include <' + include + '>' );
  17211. }
  17212. return parseIncludes( replace );
  17213. }
  17214. return string.replace( pattern, replace );
  17215. }
  17216. function unrollLoops( string ) {
  17217. var pattern = /for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  17218. function replace( match, start, end, snippet ) {
  17219. var unroll = '';
  17220. for ( var i = parseInt( start ); i < parseInt( end ); i ++ ) {
  17221. unroll += snippet.replace( /\[ i \]/g, '[ ' + i + ' ]' );
  17222. }
  17223. return unroll;
  17224. }
  17225. return string.replace( pattern, replace );
  17226. }
  17227. return function WebGLProgram( renderer, code, material, parameters ) {
  17228. var gl = renderer.context;
  17229. var extensions = material.extensions;
  17230. var defines = material.defines;
  17231. var vertexShader = material.__webglShader.vertexShader;
  17232. var fragmentShader = material.__webglShader.fragmentShader;
  17233. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  17234. if ( parameters.shadowMapType === THREE.PCFShadowMap ) {
  17235. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  17236. } else if ( parameters.shadowMapType === THREE.PCFSoftShadowMap ) {
  17237. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  17238. }
  17239. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  17240. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  17241. var envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  17242. if ( parameters.envMap ) {
  17243. switch ( material.envMap.mapping ) {
  17244. case THREE.CubeReflectionMapping:
  17245. case THREE.CubeRefractionMapping:
  17246. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  17247. break;
  17248. case THREE.CubeUVReflectionMapping:
  17249. case THREE.CubeUVRefractionMapping:
  17250. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  17251. break;
  17252. case THREE.EquirectangularReflectionMapping:
  17253. case THREE.EquirectangularRefractionMapping:
  17254. envMapTypeDefine = 'ENVMAP_TYPE_EQUIREC';
  17255. break;
  17256. case THREE.SphericalReflectionMapping:
  17257. envMapTypeDefine = 'ENVMAP_TYPE_SPHERE';
  17258. break;
  17259. }
  17260. switch ( material.envMap.mapping ) {
  17261. case THREE.CubeRefractionMapping:
  17262. case THREE.EquirectangularRefractionMapping:
  17263. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  17264. break;
  17265. }
  17266. switch ( material.combine ) {
  17267. case THREE.MultiplyOperation:
  17268. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  17269. break;
  17270. case THREE.MixOperation:
  17271. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  17272. break;
  17273. case THREE.AddOperation:
  17274. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  17275. break;
  17276. }
  17277. }
  17278. var gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
  17279. // console.log( 'building new program ' );
  17280. //
  17281. var customExtensions = generateExtensions( extensions, parameters, renderer.extensions );
  17282. var customDefines = generateDefines( defines );
  17283. //
  17284. var program = gl.createProgram();
  17285. var prefixVertex, prefixFragment;
  17286. if ( material instanceof THREE.RawShaderMaterial ) {
  17287. prefixVertex = '';
  17288. prefixFragment = '';
  17289. } else {
  17290. prefixVertex = [
  17291. 'precision ' + parameters.precision + ' float;',
  17292. 'precision ' + parameters.precision + ' int;',
  17293. '#define SHADER_NAME ' + material.__webglShader.name,
  17294. customDefines,
  17295. parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '',
  17296. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  17297. '#define MAX_BONES ' + parameters.maxBones,
  17298. parameters.map ? '#define USE_MAP' : '',
  17299. parameters.envMap ? '#define USE_ENVMAP' : '',
  17300. parameters.envMap ? '#define ' + envMapModeDefine : '',
  17301. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  17302. parameters.aoMap ? '#define USE_AOMAP' : '',
  17303. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  17304. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  17305. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  17306. parameters.displacementMap && parameters.supportsVertexTextures ? '#define USE_DISPLACEMENTMAP' : '',
  17307. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  17308. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  17309. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  17310. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  17311. parameters.vertexColors ? '#define USE_COLOR' : '',
  17312. parameters.flatShading ? '#define FLAT_SHADED' : '',
  17313. parameters.skinning ? '#define USE_SKINNING' : '',
  17314. parameters.useVertexTexture ? '#define BONE_TEXTURE' : '',
  17315. parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
  17316. parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '',
  17317. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  17318. parameters.flipSided ? '#define FLIP_SIDED' : '',
  17319. '#define NUM_CLIPPING_PLANES ' + parameters.numClippingPlanes,
  17320. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  17321. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  17322. parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
  17323. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  17324. parameters.logarithmicDepthBuffer && renderer.extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  17325. 'uniform mat4 modelMatrix;',
  17326. 'uniform mat4 modelViewMatrix;',
  17327. 'uniform mat4 projectionMatrix;',
  17328. 'uniform mat4 viewMatrix;',
  17329. 'uniform mat3 normalMatrix;',
  17330. 'uniform vec3 cameraPosition;',
  17331. 'attribute vec3 position;',
  17332. 'attribute vec3 normal;',
  17333. 'attribute vec2 uv;',
  17334. '#ifdef USE_COLOR',
  17335. ' attribute vec3 color;',
  17336. '#endif',
  17337. '#ifdef USE_MORPHTARGETS',
  17338. ' attribute vec3 morphTarget0;',
  17339. ' attribute vec3 morphTarget1;',
  17340. ' attribute vec3 morphTarget2;',
  17341. ' attribute vec3 morphTarget3;',
  17342. ' #ifdef USE_MORPHNORMALS',
  17343. ' attribute vec3 morphNormal0;',
  17344. ' attribute vec3 morphNormal1;',
  17345. ' attribute vec3 morphNormal2;',
  17346. ' attribute vec3 morphNormal3;',
  17347. ' #else',
  17348. ' attribute vec3 morphTarget4;',
  17349. ' attribute vec3 morphTarget5;',
  17350. ' attribute vec3 morphTarget6;',
  17351. ' attribute vec3 morphTarget7;',
  17352. ' #endif',
  17353. '#endif',
  17354. '#ifdef USE_SKINNING',
  17355. ' attribute vec4 skinIndex;',
  17356. ' attribute vec4 skinWeight;',
  17357. '#endif',
  17358. '\n'
  17359. ].filter( filterEmptyLine ).join( '\n' );
  17360. prefixFragment = [
  17361. customExtensions,
  17362. 'precision ' + parameters.precision + ' float;',
  17363. 'precision ' + parameters.precision + ' int;',
  17364. '#define SHADER_NAME ' + material.__webglShader.name,
  17365. customDefines,
  17366. parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest : '',
  17367. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  17368. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  17369. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  17370. parameters.map ? '#define USE_MAP' : '',
  17371. parameters.envMap ? '#define USE_ENVMAP' : '',
  17372. parameters.envMap ? '#define ' + envMapTypeDefine : '',
  17373. parameters.envMap ? '#define ' + envMapModeDefine : '',
  17374. parameters.envMap ? '#define ' + envMapBlendingDefine : '',
  17375. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  17376. parameters.aoMap ? '#define USE_AOMAP' : '',
  17377. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  17378. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  17379. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  17380. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  17381. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  17382. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  17383. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  17384. parameters.vertexColors ? '#define USE_COLOR' : '',
  17385. parameters.flatShading ? '#define FLAT_SHADED' : '',
  17386. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  17387. parameters.flipSided ? '#define FLIP_SIDED' : '',
  17388. '#define NUM_CLIPPING_PLANES ' + parameters.numClippingPlanes,
  17389. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  17390. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  17391. parameters.premultipliedAlpha ? "#define PREMULTIPLIED_ALPHA" : '',
  17392. parameters.physicallyCorrectLights ? "#define PHYSICALLY_CORRECT_LIGHTS" : '',
  17393. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  17394. parameters.logarithmicDepthBuffer && renderer.extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  17395. parameters.envMap && renderer.extensions.get( 'EXT_shader_texture_lod' ) ? '#define TEXTURE_LOD_EXT' : '',
  17396. 'uniform mat4 viewMatrix;',
  17397. 'uniform vec3 cameraPosition;',
  17398. ( parameters.toneMapping !== THREE.NoToneMapping ) ? "#define TONE_MAPPING" : '',
  17399. ( parameters.toneMapping !== THREE.NoToneMapping ) ? THREE.ShaderChunk[ 'tonemapping_pars_fragment' ] : '', // this code is required here because it is used by the toneMapping() function defined below
  17400. ( parameters.toneMapping !== THREE.NoToneMapping ) ? getToneMappingFunction( "toneMapping", parameters.toneMapping ) : '',
  17401. ( 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
  17402. parameters.mapEncoding ? getTexelDecodingFunction( 'mapTexelToLinear', parameters.mapEncoding ) : '',
  17403. parameters.envMapEncoding ? getTexelDecodingFunction( 'envMapTexelToLinear', parameters.envMapEncoding ) : '',
  17404. parameters.emissiveMapEncoding ? getTexelDecodingFunction( 'emissiveMapTexelToLinear', parameters.emissiveMapEncoding ) : '',
  17405. parameters.outputEncoding ? getTexelEncodingFunction( "linearToOutputTexel", parameters.outputEncoding ) : '',
  17406. parameters.depthPacking ? "#define DEPTH_PACKING " + material.depthPacking : '',
  17407. '\n'
  17408. ].filter( filterEmptyLine ).join( '\n' );
  17409. }
  17410. vertexShader = parseIncludes( vertexShader, parameters );
  17411. vertexShader = replaceLightNums( vertexShader, parameters );
  17412. fragmentShader = parseIncludes( fragmentShader, parameters );
  17413. fragmentShader = replaceLightNums( fragmentShader, parameters );
  17414. if ( material instanceof THREE.ShaderMaterial === false ) {
  17415. vertexShader = unrollLoops( vertexShader );
  17416. fragmentShader = unrollLoops( fragmentShader );
  17417. }
  17418. var vertexGlsl = prefixVertex + vertexShader;
  17419. var fragmentGlsl = prefixFragment + fragmentShader;
  17420. // console.log( '*VERTEX*', vertexGlsl );
  17421. // console.log( '*FRAGMENT*', fragmentGlsl );
  17422. var glVertexShader = THREE.WebGLShader( gl, gl.VERTEX_SHADER, vertexGlsl );
  17423. var glFragmentShader = THREE.WebGLShader( gl, gl.FRAGMENT_SHADER, fragmentGlsl );
  17424. gl.attachShader( program, glVertexShader );
  17425. gl.attachShader( program, glFragmentShader );
  17426. // Force a particular attribute to index 0.
  17427. if ( material.index0AttributeName !== undefined ) {
  17428. gl.bindAttribLocation( program, 0, material.index0AttributeName );
  17429. } else if ( parameters.morphTargets === true ) {
  17430. // programs with morphTargets displace position out of attribute 0
  17431. gl.bindAttribLocation( program, 0, 'position' );
  17432. }
  17433. gl.linkProgram( program );
  17434. var programLog = gl.getProgramInfoLog( program );
  17435. var vertexLog = gl.getShaderInfoLog( glVertexShader );
  17436. var fragmentLog = gl.getShaderInfoLog( glFragmentShader );
  17437. var runnable = true;
  17438. var haveDiagnostics = true;
  17439. // console.log( '**VERTEX**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( glVertexShader ) );
  17440. // console.log( '**FRAGMENT**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( glFragmentShader ) );
  17441. if ( gl.getProgramParameter( program, gl.LINK_STATUS ) === false ) {
  17442. runnable = false;
  17443. console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), 'gl.VALIDATE_STATUS', gl.getProgramParameter( program, gl.VALIDATE_STATUS ), 'gl.getProgramInfoLog', programLog, vertexLog, fragmentLog );
  17444. } else if ( programLog !== '' ) {
  17445. console.warn( 'THREE.WebGLProgram: gl.getProgramInfoLog()', programLog );
  17446. } else if ( vertexLog === '' || fragmentLog === '' ) {
  17447. haveDiagnostics = false;
  17448. }
  17449. if ( haveDiagnostics ) {
  17450. this.diagnostics = {
  17451. runnable: runnable,
  17452. material: material,
  17453. programLog: programLog,
  17454. vertexShader: {
  17455. log: vertexLog,
  17456. prefix: prefixVertex
  17457. },
  17458. fragmentShader: {
  17459. log: fragmentLog,
  17460. prefix: prefixFragment
  17461. }
  17462. };
  17463. }
  17464. // clean up
  17465. gl.deleteShader( glVertexShader );
  17466. gl.deleteShader( glFragmentShader );
  17467. // set up caching for uniform locations
  17468. var cachedUniforms;
  17469. this.getUniforms = function() {
  17470. if ( cachedUniforms === undefined ) {
  17471. cachedUniforms =
  17472. new THREE.WebGLUniforms( gl, program, renderer );
  17473. }
  17474. return cachedUniforms;
  17475. };
  17476. // set up caching for attribute locations
  17477. var cachedAttributes;
  17478. this.getAttributes = function() {
  17479. if ( cachedAttributes === undefined ) {
  17480. cachedAttributes = fetchAttributeLocations( gl, program );
  17481. }
  17482. return cachedAttributes;
  17483. };
  17484. // free resource
  17485. this.destroy = function() {
  17486. gl.deleteProgram( program );
  17487. this.program = undefined;
  17488. };
  17489. // DEPRECATED
  17490. Object.defineProperties( this, {
  17491. uniforms: {
  17492. get: function() {
  17493. console.warn( 'THREE.WebGLProgram: .uniforms is now .getUniforms().' );
  17494. return this.getUniforms();
  17495. }
  17496. },
  17497. attributes: {
  17498. get: function() {
  17499. console.warn( 'THREE.WebGLProgram: .attributes is now .getAttributes().' );
  17500. return this.getAttributes();
  17501. }
  17502. }
  17503. } );
  17504. //
  17505. this.id = programIdCount ++;
  17506. this.code = code;
  17507. this.usedTimes = 1;
  17508. this.program = program;
  17509. this.vertexShader = glVertexShader;
  17510. this.fragmentShader = glFragmentShader;
  17511. return this;
  17512. };
  17513. } )();
  17514. // File:src/renderers/webgl/WebGLPrograms.js
  17515. THREE.WebGLPrograms = function ( renderer, capabilities ) {
  17516. var programs = [];
  17517. var shaderIDs = {
  17518. MeshDepthMaterial: 'depth',
  17519. MeshNormalMaterial: 'normal',
  17520. MeshBasicMaterial: 'basic',
  17521. MeshLambertMaterial: 'lambert',
  17522. MeshPhongMaterial: 'phong',
  17523. MeshStandardMaterial: 'physical',
  17524. MeshPhysicalMaterial: 'physical',
  17525. LineBasicMaterial: 'basic',
  17526. LineDashedMaterial: 'dashed',
  17527. PointsMaterial: 'points'
  17528. };
  17529. var parameterNames = [
  17530. "precision", "supportsVertexTextures", "map", "mapEncoding", "envMap", "envMapMode", "envMapEncoding",
  17531. "lightMap", "aoMap", "emissiveMap", "emissiveMapEncoding", "bumpMap", "normalMap", "displacementMap", "specularMap",
  17532. "roughnessMap", "metalnessMap",
  17533. "alphaMap", "combine", "vertexColors", "fog", "useFog", "fogExp",
  17534. "flatShading", "sizeAttenuation", "logarithmicDepthBuffer", "skinning",
  17535. "maxBones", "useVertexTexture", "morphTargets", "morphNormals",
  17536. "maxMorphTargets", "maxMorphNormals", "premultipliedAlpha",
  17537. "numDirLights", "numPointLights", "numSpotLights", "numHemiLights",
  17538. "shadowMapEnabled", "shadowMapType", "toneMapping", 'physicallyCorrectLights',
  17539. "alphaTest", "doubleSided", "flipSided", "numClippingPlanes", "depthPacking"
  17540. ];
  17541. function allocateBones ( object ) {
  17542. if ( capabilities.floatVertexTextures && object && object.skeleton && object.skeleton.useVertexTexture ) {
  17543. return 1024;
  17544. } else {
  17545. // default for when object is not specified
  17546. // ( for example when prebuilding shader to be used with multiple objects )
  17547. //
  17548. // - leave some extra space for other uniforms
  17549. // - limit here is ANGLE's 254 max uniform vectors
  17550. // (up to 54 should be safe)
  17551. var nVertexUniforms = capabilities.maxVertexUniforms;
  17552. var nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 );
  17553. var maxBones = nVertexMatrices;
  17554. if ( object !== undefined && object instanceof THREE.SkinnedMesh ) {
  17555. maxBones = Math.min( object.skeleton.bones.length, maxBones );
  17556. if ( maxBones < object.skeleton.bones.length ) {
  17557. console.warn( 'WebGLRenderer: too many bones - ' + object.skeleton.bones.length + ', this GPU supports just ' + maxBones + ' (try OpenGL instead of ANGLE)' );
  17558. }
  17559. }
  17560. return maxBones;
  17561. }
  17562. }
  17563. function getTextureEncodingFromMap( map, gammaOverrideLinear ) {
  17564. var encoding;
  17565. if ( ! map ) {
  17566. encoding = THREE.LinearEncoding;
  17567. } else if ( map instanceof THREE.Texture ) {
  17568. encoding = map.encoding;
  17569. } else if ( map instanceof THREE.WebGLRenderTarget ) {
  17570. encoding = map.texture.encoding;
  17571. }
  17572. // add backwards compatibility for WebGLRenderer.gammaInput/gammaOutput parameter, should probably be removed at some point.
  17573. if ( encoding === THREE.LinearEncoding && gammaOverrideLinear ) {
  17574. encoding = THREE.GammaEncoding;
  17575. }
  17576. return encoding;
  17577. }
  17578. this.getParameters = function ( material, lights, fog, nClipPlanes, object ) {
  17579. var shaderID = shaderIDs[ material.type ];
  17580. // heuristics to create shader parameters according to lights in the scene
  17581. // (not to blow over maxLights budget)
  17582. var maxBones = allocateBones( object );
  17583. var precision = renderer.getPrecision();
  17584. if ( material.precision !== null ) {
  17585. precision = capabilities.getMaxPrecision( material.precision );
  17586. if ( precision !== material.precision ) {
  17587. console.warn( 'THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.' );
  17588. }
  17589. }
  17590. var parameters = {
  17591. shaderID: shaderID,
  17592. precision: precision,
  17593. supportsVertexTextures: capabilities.vertexTextures,
  17594. outputEncoding: getTextureEncodingFromMap( renderer.getCurrentRenderTarget(), renderer.gammaOutput ),
  17595. map: !! material.map,
  17596. mapEncoding: getTextureEncodingFromMap( material.map, renderer.gammaInput ),
  17597. envMap: !! material.envMap,
  17598. envMapMode: material.envMap && material.envMap.mapping,
  17599. envMapEncoding: getTextureEncodingFromMap( material.envMap, renderer.gammaInput ),
  17600. envMapCubeUV: ( !! material.envMap ) && ( ( material.envMap.mapping === THREE.CubeUVReflectionMapping ) || ( material.envMap.mapping === THREE.CubeUVRefractionMapping ) ),
  17601. lightMap: !! material.lightMap,
  17602. aoMap: !! material.aoMap,
  17603. emissiveMap: !! material.emissiveMap,
  17604. emissiveMapEncoding: getTextureEncodingFromMap( material.emissiveMap, renderer.gammaInput ),
  17605. bumpMap: !! material.bumpMap,
  17606. normalMap: !! material.normalMap,
  17607. displacementMap: !! material.displacementMap,
  17608. roughnessMap: !! material.roughnessMap,
  17609. metalnessMap: !! material.metalnessMap,
  17610. specularMap: !! material.specularMap,
  17611. alphaMap: !! material.alphaMap,
  17612. combine: material.combine,
  17613. vertexColors: material.vertexColors,
  17614. fog: fog,
  17615. useFog: material.fog,
  17616. fogExp: fog instanceof THREE.FogExp2,
  17617. flatShading: material.shading === THREE.FlatShading,
  17618. sizeAttenuation: material.sizeAttenuation,
  17619. logarithmicDepthBuffer: capabilities.logarithmicDepthBuffer,
  17620. skinning: material.skinning,
  17621. maxBones: maxBones,
  17622. useVertexTexture: capabilities.floatVertexTextures && object && object.skeleton && object.skeleton.useVertexTexture,
  17623. morphTargets: material.morphTargets,
  17624. morphNormals: material.morphNormals,
  17625. maxMorphTargets: renderer.maxMorphTargets,
  17626. maxMorphNormals: renderer.maxMorphNormals,
  17627. numDirLights: lights.directional.length,
  17628. numPointLights: lights.point.length,
  17629. numSpotLights: lights.spot.length,
  17630. numHemiLights: lights.hemi.length,
  17631. numClippingPlanes: nClipPlanes,
  17632. shadowMapEnabled: renderer.shadowMap.enabled && object.receiveShadow && lights.shadows.length > 0,
  17633. shadowMapType: renderer.shadowMap.type,
  17634. toneMapping: renderer.toneMapping,
  17635. physicallyCorrectLights: renderer.physicallyCorrectLights,
  17636. premultipliedAlpha: material.premultipliedAlpha,
  17637. alphaTest: material.alphaTest,
  17638. doubleSided: material.side === THREE.DoubleSide,
  17639. flipSided: material.side === THREE.BackSide,
  17640. depthPacking: ( material.depthPacking !== undefined ) ? material.depthPacking : false
  17641. };
  17642. return parameters;
  17643. };
  17644. this.getProgramCode = function ( material, parameters ) {
  17645. var array = [];
  17646. if ( parameters.shaderID ) {
  17647. array.push( parameters.shaderID );
  17648. } else {
  17649. array.push( material.fragmentShader );
  17650. array.push( material.vertexShader );
  17651. }
  17652. if ( material.defines !== undefined ) {
  17653. for ( var name in material.defines ) {
  17654. array.push( name );
  17655. array.push( material.defines[ name ] );
  17656. }
  17657. }
  17658. for ( var i = 0; i < parameterNames.length; i ++ ) {
  17659. array.push( parameters[ parameterNames[ i ] ] );
  17660. }
  17661. return array.join();
  17662. };
  17663. this.acquireProgram = function ( material, parameters, code ) {
  17664. var program;
  17665. // Check if code has been already compiled
  17666. for ( var p = 0, pl = programs.length; p < pl; p ++ ) {
  17667. var programInfo = programs[ p ];
  17668. if ( programInfo.code === code ) {
  17669. program = programInfo;
  17670. ++ program.usedTimes;
  17671. break;
  17672. }
  17673. }
  17674. if ( program === undefined ) {
  17675. program = new THREE.WebGLProgram( renderer, code, material, parameters );
  17676. programs.push( program );
  17677. }
  17678. return program;
  17679. };
  17680. this.releaseProgram = function( program ) {
  17681. if ( -- program.usedTimes === 0 ) {
  17682. // Remove from unordered set
  17683. var i = programs.indexOf( program );
  17684. programs[ i ] = programs[ programs.length - 1 ];
  17685. programs.pop();
  17686. // Free WebGL resources
  17687. program.destroy();
  17688. }
  17689. };
  17690. // Exposed for resource monitoring & error feedback via renderer.info:
  17691. this.programs = programs;
  17692. };
  17693. // File:src/renderers/webgl/WebGLProperties.js
  17694. /**
  17695. * @author fordacious / fordacious.github.io
  17696. */
  17697. THREE.WebGLProperties = function () {
  17698. var properties = {};
  17699. this.get = function ( object ) {
  17700. var uuid = object.uuid;
  17701. var map = properties[ uuid ];
  17702. if ( map === undefined ) {
  17703. map = {};
  17704. properties[ uuid ] = map;
  17705. }
  17706. return map;
  17707. };
  17708. this.delete = function ( object ) {
  17709. delete properties[ object.uuid ];
  17710. };
  17711. this.clear = function () {
  17712. properties = {};
  17713. };
  17714. };
  17715. // File:src/renderers/webgl/WebGLShader.js
  17716. THREE.WebGLShader = ( function () {
  17717. function addLineNumbers( string ) {
  17718. var lines = string.split( '\n' );
  17719. for ( var i = 0; i < lines.length; i ++ ) {
  17720. lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
  17721. }
  17722. return lines.join( '\n' );
  17723. }
  17724. return function WebGLShader( gl, type, string ) {
  17725. var shader = gl.createShader( type );
  17726. gl.shaderSource( shader, string );
  17727. gl.compileShader( shader );
  17728. if ( gl.getShaderParameter( shader, gl.COMPILE_STATUS ) === false ) {
  17729. console.error( 'THREE.WebGLShader: Shader couldn\'t compile.' );
  17730. }
  17731. if ( gl.getShaderInfoLog( shader ) !== '' ) {
  17732. console.warn( 'THREE.WebGLShader: gl.getShaderInfoLog()', type === gl.VERTEX_SHADER ? 'vertex' : 'fragment', gl.getShaderInfoLog( shader ), addLineNumbers( string ) );
  17733. }
  17734. // --enable-privileged-webgl-extension
  17735. // console.log( type, gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  17736. return shader;
  17737. };
  17738. } )();
  17739. // File:src/renderers/webgl/WebGLShadowMap.js
  17740. /**
  17741. * @author alteredq / http://alteredqualia.com/
  17742. * @author mrdoob / http://mrdoob.com/
  17743. */
  17744. THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
  17745. var _gl = _renderer.context,
  17746. _state = _renderer.state,
  17747. _frustum = new THREE.Frustum(),
  17748. _projScreenMatrix = new THREE.Matrix4(),
  17749. _lightShadows = _lights.shadows,
  17750. _shadowMapSize = new THREE.Vector2(),
  17751. _lookTarget = new THREE.Vector3(),
  17752. _lightPositionWorld = new THREE.Vector3(),
  17753. _renderList = [],
  17754. _MorphingFlag = 1,
  17755. _SkinningFlag = 2,
  17756. _NumberOfMaterialVariants = ( _MorphingFlag | _SkinningFlag ) + 1,
  17757. _depthMaterials = new Array( _NumberOfMaterialVariants ),
  17758. _distanceMaterials = new Array( _NumberOfMaterialVariants ),
  17759. _materialCache = {};
  17760. var cubeDirections = [
  17761. new THREE.Vector3( 1, 0, 0 ), new THREE.Vector3( - 1, 0, 0 ), new THREE.Vector3( 0, 0, 1 ),
  17762. new THREE.Vector3( 0, 0, - 1 ), new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, - 1, 0 )
  17763. ];
  17764. var cubeUps = [
  17765. new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 1, 0 ),
  17766. new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 0, 1 ), new THREE.Vector3( 0, 0, - 1 )
  17767. ];
  17768. var cube2DViewPorts = [
  17769. new THREE.Vector4(), new THREE.Vector4(), new THREE.Vector4(),
  17770. new THREE.Vector4(), new THREE.Vector4(), new THREE.Vector4()
  17771. ];
  17772. // init
  17773. var depthMaterialTemplate = new THREE.MeshDepthMaterial();
  17774. depthMaterialTemplate.depthPacking = THREE.RGBADepthPacking;
  17775. depthMaterialTemplate.clipping = true;
  17776. var distanceShader = THREE.ShaderLib[ "distanceRGBA" ];
  17777. var distanceUniforms = THREE.UniformsUtils.clone( distanceShader.uniforms );
  17778. for ( var i = 0; i !== _NumberOfMaterialVariants; ++ i ) {
  17779. var useMorphing = ( i & _MorphingFlag ) !== 0;
  17780. var useSkinning = ( i & _SkinningFlag ) !== 0;
  17781. var depthMaterial = depthMaterialTemplate.clone();
  17782. depthMaterial.morphTargets = useMorphing;
  17783. depthMaterial.skinning = useSkinning;
  17784. _depthMaterials[ i ] = depthMaterial;
  17785. var distanceMaterial = new THREE.ShaderMaterial( {
  17786. defines: {
  17787. 'USE_SHADOWMAP': ''
  17788. },
  17789. uniforms: distanceUniforms,
  17790. vertexShader: distanceShader.vertexShader,
  17791. fragmentShader: distanceShader.fragmentShader,
  17792. morphTargets: useMorphing,
  17793. skinning: useSkinning,
  17794. clipping: true
  17795. } );
  17796. _distanceMaterials[ i ] = distanceMaterial;
  17797. }
  17798. //
  17799. var scope = this;
  17800. this.enabled = false;
  17801. this.autoUpdate = true;
  17802. this.needsUpdate = false;
  17803. this.type = THREE.PCFShadowMap;
  17804. this.cullFace = THREE.CullFaceFront;
  17805. this.allowDoubleSided = false;
  17806. this.render = function ( scene, camera ) {
  17807. if ( scope.enabled === false ) return;
  17808. if ( scope.autoUpdate === false && scope.needsUpdate === false ) return;
  17809. if ( _lightShadows.length === 0 ) return;
  17810. // Set GL state for depth map.
  17811. _state.clearColor( 1, 1, 1, 1 );
  17812. _state.disable( _gl.BLEND );
  17813. _state.enable( _gl.CULL_FACE );
  17814. _gl.frontFace( _gl.CCW );
  17815. _gl.cullFace( scope.cullFace === THREE.CullFaceFront ? _gl.FRONT : _gl.BACK );
  17816. _state.setDepthTest( true );
  17817. _state.setScissorTest( false );
  17818. // render depth map
  17819. var faceCount, isPointLight;
  17820. for ( var i = 0, il = _lightShadows.length; i < il; i ++ ) {
  17821. var light = _lightShadows[ i ];
  17822. var shadow = light.shadow;
  17823. var shadowCamera = shadow.camera;
  17824. _shadowMapSize.copy( shadow.mapSize );
  17825. if ( light instanceof THREE.PointLight ) {
  17826. faceCount = 6;
  17827. isPointLight = true;
  17828. var vpWidth = _shadowMapSize.x;
  17829. var vpHeight = _shadowMapSize.y;
  17830. // These viewports map a cube-map onto a 2D texture with the
  17831. // following orientation:
  17832. //
  17833. // xzXZ
  17834. // y Y
  17835. //
  17836. // X - Positive x direction
  17837. // x - Negative x direction
  17838. // Y - Positive y direction
  17839. // y - Negative y direction
  17840. // Z - Positive z direction
  17841. // z - Negative z direction
  17842. // positive X
  17843. cube2DViewPorts[ 0 ].set( vpWidth * 2, vpHeight, vpWidth, vpHeight );
  17844. // negative X
  17845. cube2DViewPorts[ 1 ].set( 0, vpHeight, vpWidth, vpHeight );
  17846. // positive Z
  17847. cube2DViewPorts[ 2 ].set( vpWidth * 3, vpHeight, vpWidth, vpHeight );
  17848. // negative Z
  17849. cube2DViewPorts[ 3 ].set( vpWidth, vpHeight, vpWidth, vpHeight );
  17850. // positive Y
  17851. cube2DViewPorts[ 4 ].set( vpWidth * 3, 0, vpWidth, vpHeight );
  17852. // negative Y
  17853. cube2DViewPorts[ 5 ].set( vpWidth, 0, vpWidth, vpHeight );
  17854. _shadowMapSize.x *= 4.0;
  17855. _shadowMapSize.y *= 2.0;
  17856. } else {
  17857. faceCount = 1;
  17858. isPointLight = false;
  17859. }
  17860. if ( shadow.map === null ) {
  17861. var pars = { minFilter: THREE.NearestFilter, magFilter: THREE.NearestFilter, format: THREE.RGBAFormat };
  17862. shadow.map = new THREE.WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
  17863. shadowCamera.updateProjectionMatrix();
  17864. }
  17865. if ( shadow instanceof THREE.SpotLightShadow ) {
  17866. shadow.update( light );
  17867. }
  17868. var shadowMap = shadow.map;
  17869. var shadowMatrix = shadow.matrix;
  17870. _lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  17871. shadowCamera.position.copy( _lightPositionWorld );
  17872. _renderer.setRenderTarget( shadowMap );
  17873. _renderer.clear();
  17874. // render shadow map for each cube face (if omni-directional) or
  17875. // run a single pass if not
  17876. for ( var face = 0; face < faceCount; face ++ ) {
  17877. if ( isPointLight ) {
  17878. _lookTarget.copy( shadowCamera.position );
  17879. _lookTarget.add( cubeDirections[ face ] );
  17880. shadowCamera.up.copy( cubeUps[ face ] );
  17881. shadowCamera.lookAt( _lookTarget );
  17882. var vpDimensions = cube2DViewPorts[ face ];
  17883. _state.viewport( vpDimensions );
  17884. } else {
  17885. _lookTarget.setFromMatrixPosition( light.target.matrixWorld );
  17886. shadowCamera.lookAt( _lookTarget );
  17887. }
  17888. shadowCamera.updateMatrixWorld();
  17889. shadowCamera.matrixWorldInverse.getInverse( shadowCamera.matrixWorld );
  17890. // compute shadow matrix
  17891. shadowMatrix.set(
  17892. 0.5, 0.0, 0.0, 0.5,
  17893. 0.0, 0.5, 0.0, 0.5,
  17894. 0.0, 0.0, 0.5, 0.5,
  17895. 0.0, 0.0, 0.0, 1.0
  17896. );
  17897. shadowMatrix.multiply( shadowCamera.projectionMatrix );
  17898. shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
  17899. // update camera matrices and frustum
  17900. _projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  17901. _frustum.setFromMatrix( _projScreenMatrix );
  17902. // set object matrices & frustum culling
  17903. _renderList.length = 0;
  17904. projectObject( scene, camera, shadowCamera );
  17905. // render shadow map
  17906. // render regular objects
  17907. for ( var j = 0, jl = _renderList.length; j < jl; j ++ ) {
  17908. var object = _renderList[ j ];
  17909. var geometry = _objects.update( object );
  17910. var material = object.material;
  17911. if ( material instanceof THREE.MultiMaterial ) {
  17912. var groups = geometry.groups;
  17913. var materials = material.materials;
  17914. for ( var k = 0, kl = groups.length; k < kl; k ++ ) {
  17915. var group = groups[ k ];
  17916. var groupMaterial = materials[ group.materialIndex ];
  17917. if ( groupMaterial.visible === true ) {
  17918. var depthMaterial = getDepthMaterial( object, groupMaterial, isPointLight, _lightPositionWorld );
  17919. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, group );
  17920. }
  17921. }
  17922. } else {
  17923. var depthMaterial = getDepthMaterial( object, material, isPointLight, _lightPositionWorld );
  17924. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, null );
  17925. }
  17926. }
  17927. }
  17928. }
  17929. // Restore GL state.
  17930. var clearColor = _renderer.getClearColor(),
  17931. clearAlpha = _renderer.getClearAlpha();
  17932. _renderer.setClearColor( clearColor, clearAlpha );
  17933. _state.enable( _gl.BLEND );
  17934. if ( scope.cullFace === THREE.CullFaceFront ) {
  17935. _gl.cullFace( _gl.BACK );
  17936. }
  17937. scope.needsUpdate = false;
  17938. };
  17939. function getDepthMaterial( object, material, isPointLight, lightPositionWorld ) {
  17940. var geometry = object.geometry;
  17941. var result = null;
  17942. var materialVariants = _depthMaterials;
  17943. var customMaterial = object.customDepthMaterial;
  17944. if ( isPointLight ) {
  17945. materialVariants = _distanceMaterials;
  17946. customMaterial = object.customDistanceMaterial;
  17947. }
  17948. if ( ! customMaterial ) {
  17949. var useMorphing = geometry.morphTargets !== undefined &&
  17950. geometry.morphTargets.length > 0 && material.morphTargets;
  17951. var useSkinning = object instanceof THREE.SkinnedMesh && material.skinning;
  17952. var variantIndex = 0;
  17953. if ( useMorphing ) variantIndex |= _MorphingFlag;
  17954. if ( useSkinning ) variantIndex |= _SkinningFlag;
  17955. result = materialVariants[ variantIndex ];
  17956. } else {
  17957. result = customMaterial;
  17958. }
  17959. if ( _renderer.localClippingEnabled &&
  17960. material.clipShadows === true &&
  17961. material.clippingPlanes.length !== 0 ) {
  17962. // in this case we need a unique material instance reflecting the
  17963. // appropriate state
  17964. var keyA = result.uuid, keyB = material.uuid;
  17965. var materialsForVariant = _materialCache[ keyA ];
  17966. if ( materialsForVariant === undefined ) {
  17967. materialsForVariant = {};
  17968. _materialCache[ keyA ] = materialsForVariant;
  17969. }
  17970. var cachedMaterial = materialsForVariant[ keyB ];
  17971. if ( cachedMaterial === undefined ) {
  17972. cachedMaterial = result.clone();
  17973. materialsForVariant[ keyB ] = cachedMaterial;
  17974. }
  17975. result = cachedMaterial;
  17976. }
  17977. result.visible = material.visible;
  17978. result.wireframe = material.wireframe;
  17979. result.side = scope.allowDoubleSided ? material.side : THREE.FrontSide;
  17980. result.clipShadows = material.clipShadows;
  17981. result.clippingPlanes = material.clippingPlanes;
  17982. result.wireframeLinewidth = material.wireframeLinewidth;
  17983. result.linewidth = material.linewidth;
  17984. if ( isPointLight && result.uniforms.lightPos !== undefined ) {
  17985. result.uniforms.lightPos.value.copy( lightPositionWorld );
  17986. }
  17987. return result;
  17988. }
  17989. function projectObject( object, camera, shadowCamera ) {
  17990. if ( object.visible === false ) return;
  17991. if ( object.layers.test( camera.layers ) && ( object instanceof THREE.Mesh || object instanceof THREE.Line || object instanceof THREE.Points ) ) {
  17992. if ( object.castShadow && ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) ) {
  17993. var material = object.material;
  17994. if ( material.visible === true ) {
  17995. object.modelViewMatrix.multiplyMatrices( shadowCamera.matrixWorldInverse, object.matrixWorld );
  17996. _renderList.push( object );
  17997. }
  17998. }
  17999. }
  18000. var children = object.children;
  18001. for ( var i = 0, l = children.length; i < l; i ++ ) {
  18002. projectObject( children[ i ], camera, shadowCamera );
  18003. }
  18004. }
  18005. };
  18006. // File:src/renderers/webgl/WebGLState.js
  18007. /**
  18008. * @author mrdoob / http://mrdoob.com/
  18009. */
  18010. THREE.WebGLState = function ( gl, extensions, paramThreeToGL ) {
  18011. var _this = this;
  18012. var color = new THREE.Vector4();
  18013. var maxVertexAttributes = gl.getParameter( gl.MAX_VERTEX_ATTRIBS );
  18014. var newAttributes = new Uint8Array( maxVertexAttributes );
  18015. var enabledAttributes = new Uint8Array( maxVertexAttributes );
  18016. var attributeDivisors = new Uint8Array( maxVertexAttributes );
  18017. var capabilities = {};
  18018. var compressedTextureFormats = null;
  18019. var currentBlending = null;
  18020. var currentBlendEquation = null;
  18021. var currentBlendSrc = null;
  18022. var currentBlendDst = null;
  18023. var currentBlendEquationAlpha = null;
  18024. var currentBlendSrcAlpha = null;
  18025. var currentBlendDstAlpha = null;
  18026. var currentPremultipledAlpha = false;
  18027. var currentDepthFunc = null;
  18028. var currentDepthWrite = null;
  18029. var currentColorWrite = null;
  18030. var currentStencilWrite = null;
  18031. var currentStencilFunc = null;
  18032. var currentStencilRef = null;
  18033. var currentStencilMask = null;
  18034. var currentStencilFail = null;
  18035. var currentStencilZFail = null;
  18036. var currentStencilZPass = null;
  18037. var currentFlipSided = null;
  18038. var currentLineWidth = null;
  18039. var currentPolygonOffsetFactor = null;
  18040. var currentPolygonOffsetUnits = null;
  18041. var currentScissorTest = null;
  18042. var maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
  18043. var currentTextureSlot = undefined;
  18044. var currentBoundTextures = {};
  18045. var currentClearColor = new THREE.Vector4();
  18046. var currentClearDepth = null;
  18047. var currentClearStencil = null;
  18048. var currentScissor = new THREE.Vector4();
  18049. var currentViewport = new THREE.Vector4();
  18050. this.init = function () {
  18051. this.clearColor( 0, 0, 0, 1 );
  18052. this.clearDepth( 1 );
  18053. this.clearStencil( 0 );
  18054. this.enable( gl.DEPTH_TEST );
  18055. gl.depthFunc( gl.LEQUAL );
  18056. gl.frontFace( gl.CCW );
  18057. gl.cullFace( gl.BACK );
  18058. this.enable( gl.CULL_FACE );
  18059. this.enable( gl.BLEND );
  18060. gl.blendEquation( gl.FUNC_ADD );
  18061. gl.blendFunc( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA );
  18062. };
  18063. this.initAttributes = function () {
  18064. for ( var i = 0, l = newAttributes.length; i < l; i ++ ) {
  18065. newAttributes[ i ] = 0;
  18066. }
  18067. };
  18068. this.enableAttribute = function ( attribute ) {
  18069. newAttributes[ attribute ] = 1;
  18070. if ( enabledAttributes[ attribute ] === 0 ) {
  18071. gl.enableVertexAttribArray( attribute );
  18072. enabledAttributes[ attribute ] = 1;
  18073. }
  18074. if ( attributeDivisors[ attribute ] !== 0 ) {
  18075. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  18076. extension.vertexAttribDivisorANGLE( attribute, 0 );
  18077. attributeDivisors[ attribute ] = 0;
  18078. }
  18079. };
  18080. this.enableAttributeAndDivisor = function ( attribute, meshPerAttribute, extension ) {
  18081. newAttributes[ attribute ] = 1;
  18082. if ( enabledAttributes[ attribute ] === 0 ) {
  18083. gl.enableVertexAttribArray( attribute );
  18084. enabledAttributes[ attribute ] = 1;
  18085. }
  18086. if ( attributeDivisors[ attribute ] !== meshPerAttribute ) {
  18087. extension.vertexAttribDivisorANGLE( attribute, meshPerAttribute );
  18088. attributeDivisors[ attribute ] = meshPerAttribute;
  18089. }
  18090. };
  18091. this.disableUnusedAttributes = function () {
  18092. for ( var i = 0, l = enabledAttributes.length; i < l; i ++ ) {
  18093. if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
  18094. gl.disableVertexAttribArray( i );
  18095. enabledAttributes[ i ] = 0;
  18096. }
  18097. }
  18098. };
  18099. this.enable = function ( id ) {
  18100. if ( capabilities[ id ] !== true ) {
  18101. gl.enable( id );
  18102. capabilities[ id ] = true;
  18103. }
  18104. };
  18105. this.disable = function ( id ) {
  18106. if ( capabilities[ id ] !== false ) {
  18107. gl.disable( id );
  18108. capabilities[ id ] = false;
  18109. }
  18110. };
  18111. this.getCompressedTextureFormats = function () {
  18112. if ( compressedTextureFormats === null ) {
  18113. compressedTextureFormats = [];
  18114. if ( extensions.get( 'WEBGL_compressed_texture_pvrtc' ) ||
  18115. extensions.get( 'WEBGL_compressed_texture_s3tc' ) ||
  18116. extensions.get( 'WEBGL_compressed_texture_etc1' ) ) {
  18117. var formats = gl.getParameter( gl.COMPRESSED_TEXTURE_FORMATS );
  18118. for ( var i = 0; i < formats.length; i ++ ) {
  18119. compressedTextureFormats.push( formats[ i ] );
  18120. }
  18121. }
  18122. }
  18123. return compressedTextureFormats;
  18124. };
  18125. this.setBlending = function ( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha ) {
  18126. if ( blending === THREE.NoBlending ) {
  18127. this.disable( gl.BLEND );
  18128. } else {
  18129. this.enable( gl.BLEND );
  18130. }
  18131. if ( blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha ) {
  18132. if ( blending === THREE.AdditiveBlending ) {
  18133. if ( premultipliedAlpha ) {
  18134. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  18135. gl.blendFuncSeparate( gl.ONE, gl.ONE, gl.ONE, gl.ONE );
  18136. } else {
  18137. gl.blendEquation( gl.FUNC_ADD );
  18138. gl.blendFunc( gl.SRC_ALPHA, gl.ONE );
  18139. }
  18140. } else if ( blending === THREE.SubtractiveBlending ) {
  18141. if ( premultipliedAlpha ) {
  18142. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  18143. gl.blendFuncSeparate( gl.ZERO, gl.ZERO, gl.ONE_MINUS_SRC_COLOR, gl.ONE_MINUS_SRC_ALPHA );
  18144. } else {
  18145. gl.blendEquation( gl.FUNC_ADD );
  18146. gl.blendFunc( gl.ZERO, gl.ONE_MINUS_SRC_COLOR );
  18147. }
  18148. } else if ( blending === THREE.MultiplyBlending ) {
  18149. if ( premultipliedAlpha ) {
  18150. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  18151. gl.blendFuncSeparate( gl.ZERO, gl.ZERO, gl.SRC_COLOR, gl.SRC_ALPHA );
  18152. } else {
  18153. gl.blendEquation( gl.FUNC_ADD );
  18154. gl.blendFunc( gl.ZERO, gl.SRC_COLOR );
  18155. }
  18156. } else {
  18157. if ( premultipliedAlpha ) {
  18158. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  18159. gl.blendFuncSeparate( gl.ONE, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
  18160. } else {
  18161. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  18162. gl.blendFuncSeparate( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
  18163. }
  18164. }
  18165. currentBlending = blending;
  18166. currentPremultipledAlpha = premultipliedAlpha;
  18167. }
  18168. if ( blending === THREE.CustomBlending ) {
  18169. blendEquationAlpha = blendEquationAlpha || blendEquation;
  18170. blendSrcAlpha = blendSrcAlpha || blendSrc;
  18171. blendDstAlpha = blendDstAlpha || blendDst;
  18172. if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
  18173. gl.blendEquationSeparate( paramThreeToGL( blendEquation ), paramThreeToGL( blendEquationAlpha ) );
  18174. currentBlendEquation = blendEquation;
  18175. currentBlendEquationAlpha = blendEquationAlpha;
  18176. }
  18177. if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
  18178. gl.blendFuncSeparate( paramThreeToGL( blendSrc ), paramThreeToGL( blendDst ), paramThreeToGL( blendSrcAlpha ), paramThreeToGL( blendDstAlpha ) );
  18179. currentBlendSrc = blendSrc;
  18180. currentBlendDst = blendDst;
  18181. currentBlendSrcAlpha = blendSrcAlpha;
  18182. currentBlendDstAlpha = blendDstAlpha;
  18183. }
  18184. } else {
  18185. currentBlendEquation = null;
  18186. currentBlendSrc = null;
  18187. currentBlendDst = null;
  18188. currentBlendEquationAlpha = null;
  18189. currentBlendSrcAlpha = null;
  18190. currentBlendDstAlpha = null;
  18191. }
  18192. };
  18193. this.setDepthFunc = function ( depthFunc ) {
  18194. if ( currentDepthFunc !== depthFunc ) {
  18195. if ( depthFunc ) {
  18196. switch ( depthFunc ) {
  18197. case THREE.NeverDepth:
  18198. gl.depthFunc( gl.NEVER );
  18199. break;
  18200. case THREE.AlwaysDepth:
  18201. gl.depthFunc( gl.ALWAYS );
  18202. break;
  18203. case THREE.LessDepth:
  18204. gl.depthFunc( gl.LESS );
  18205. break;
  18206. case THREE.LessEqualDepth:
  18207. gl.depthFunc( gl.LEQUAL );
  18208. break;
  18209. case THREE.EqualDepth:
  18210. gl.depthFunc( gl.EQUAL );
  18211. break;
  18212. case THREE.GreaterEqualDepth:
  18213. gl.depthFunc( gl.GEQUAL );
  18214. break;
  18215. case THREE.GreaterDepth:
  18216. gl.depthFunc( gl.GREATER );
  18217. break;
  18218. case THREE.NotEqualDepth:
  18219. gl.depthFunc( gl.NOTEQUAL );
  18220. break;
  18221. default:
  18222. gl.depthFunc( gl.LEQUAL );
  18223. }
  18224. } else {
  18225. gl.depthFunc( gl.LEQUAL );
  18226. }
  18227. currentDepthFunc = depthFunc;
  18228. }
  18229. };
  18230. this.setDepthTest = function ( depthTest ) {
  18231. if ( depthTest ) {
  18232. this.enable( gl.DEPTH_TEST );
  18233. } else {
  18234. this.disable( gl.DEPTH_TEST );
  18235. }
  18236. };
  18237. this.setDepthWrite = function ( depthWrite ) {
  18238. // TODO: Rename to setDepthMask
  18239. if ( currentDepthWrite !== depthWrite ) {
  18240. gl.depthMask( depthWrite );
  18241. currentDepthWrite = depthWrite;
  18242. }
  18243. };
  18244. this.setColorWrite = function ( colorWrite ) {
  18245. // TODO: Rename to setColorMask
  18246. if ( currentColorWrite !== colorWrite ) {
  18247. gl.colorMask( colorWrite, colorWrite, colorWrite, colorWrite );
  18248. currentColorWrite = colorWrite;
  18249. }
  18250. };
  18251. this.setStencilFunc = function ( stencilFunc, stencilRef, stencilMask ) {
  18252. if ( currentStencilFunc !== stencilFunc ||
  18253. currentStencilRef !== stencilRef ||
  18254. currentStencilMask !== stencilMask ) {
  18255. gl.stencilFunc( stencilFunc, stencilRef, stencilMask );
  18256. currentStencilFunc = stencilFunc;
  18257. currentStencilRef = stencilRef;
  18258. currentStencilMask = stencilMask;
  18259. }
  18260. };
  18261. this.setStencilOp = function ( stencilFail, stencilZFail, stencilZPass ) {
  18262. if ( currentStencilFail !== stencilFail ||
  18263. currentStencilZFail !== stencilZFail ||
  18264. currentStencilZPass !== stencilZPass ) {
  18265. gl.stencilOp( stencilFail, stencilZFail, stencilZPass );
  18266. currentStencilFail = stencilFail;
  18267. currentStencilZFail = stencilZFail;
  18268. currentStencilZPass = stencilZPass;
  18269. }
  18270. };
  18271. this.setStencilTest = function ( stencilTest ) {
  18272. if ( stencilTest ) {
  18273. this.enable( gl.STENCIL_TEST );
  18274. } else {
  18275. this.disable( gl.STENCIL_TEST );
  18276. }
  18277. };
  18278. this.setStencilWrite = function ( stencilWrite ) {
  18279. // TODO: Rename to setStencilMask
  18280. if ( currentStencilWrite !== stencilWrite ) {
  18281. gl.stencilMask( stencilWrite );
  18282. currentStencilWrite = stencilWrite;
  18283. }
  18284. };
  18285. this.setFlipSided = function ( flipSided ) {
  18286. if ( currentFlipSided !== flipSided ) {
  18287. if ( flipSided ) {
  18288. gl.frontFace( gl.CW );
  18289. } else {
  18290. gl.frontFace( gl.CCW );
  18291. }
  18292. currentFlipSided = flipSided;
  18293. }
  18294. };
  18295. this.setLineWidth = function ( width ) {
  18296. if ( width !== currentLineWidth ) {
  18297. gl.lineWidth( width );
  18298. currentLineWidth = width;
  18299. }
  18300. };
  18301. this.setPolygonOffset = function ( polygonOffset, factor, units ) {
  18302. if ( polygonOffset ) {
  18303. this.enable( gl.POLYGON_OFFSET_FILL );
  18304. } else {
  18305. this.disable( gl.POLYGON_OFFSET_FILL );
  18306. }
  18307. if ( polygonOffset && ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) ) {
  18308. gl.polygonOffset( factor, units );
  18309. currentPolygonOffsetFactor = factor;
  18310. currentPolygonOffsetUnits = units;
  18311. }
  18312. };
  18313. this.getScissorTest = function () {
  18314. return currentScissorTest;
  18315. };
  18316. this.setScissorTest = function ( scissorTest ) {
  18317. currentScissorTest = scissorTest;
  18318. if ( scissorTest ) {
  18319. this.enable( gl.SCISSOR_TEST );
  18320. } else {
  18321. this.disable( gl.SCISSOR_TEST );
  18322. }
  18323. };
  18324. // texture
  18325. this.activeTexture = function ( webglSlot ) {
  18326. if ( webglSlot === undefined ) webglSlot = gl.TEXTURE0 + maxTextures - 1;
  18327. if ( currentTextureSlot !== webglSlot ) {
  18328. gl.activeTexture( webglSlot );
  18329. currentTextureSlot = webglSlot;
  18330. }
  18331. };
  18332. this.bindTexture = function ( webglType, webglTexture ) {
  18333. if ( currentTextureSlot === undefined ) {
  18334. _this.activeTexture();
  18335. }
  18336. var boundTexture = currentBoundTextures[ currentTextureSlot ];
  18337. if ( boundTexture === undefined ) {
  18338. boundTexture = { type: undefined, texture: undefined };
  18339. currentBoundTextures[ currentTextureSlot ] = boundTexture;
  18340. }
  18341. if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
  18342. gl.bindTexture( webglType, webglTexture );
  18343. boundTexture.type = webglType;
  18344. boundTexture.texture = webglTexture;
  18345. }
  18346. };
  18347. this.compressedTexImage2D = function () {
  18348. try {
  18349. gl.compressedTexImage2D.apply( gl, arguments );
  18350. } catch ( error ) {
  18351. console.error( error );
  18352. }
  18353. };
  18354. this.texImage2D = function () {
  18355. try {
  18356. gl.texImage2D.apply( gl, arguments );
  18357. } catch ( error ) {
  18358. console.error( error );
  18359. }
  18360. };
  18361. // clear values
  18362. this.clearColor = function ( r, g, b, a ) {
  18363. color.set( r, g, b, a );
  18364. if ( currentClearColor.equals( color ) === false ) {
  18365. gl.clearColor( r, g, b, a );
  18366. currentClearColor.copy( color );
  18367. }
  18368. };
  18369. this.clearDepth = function ( depth ) {
  18370. if ( currentClearDepth !== depth ) {
  18371. gl.clearDepth( depth );
  18372. currentClearDepth = depth;
  18373. }
  18374. };
  18375. this.clearStencil = function ( stencil ) {
  18376. if ( currentClearStencil !== stencil ) {
  18377. gl.clearStencil( stencil );
  18378. currentClearStencil = stencil;
  18379. }
  18380. };
  18381. //
  18382. this.scissor = function ( scissor ) {
  18383. if ( currentScissor.equals( scissor ) === false ) {
  18384. gl.scissor( scissor.x, scissor.y, scissor.z, scissor.w );
  18385. currentScissor.copy( scissor );
  18386. }
  18387. };
  18388. this.viewport = function ( viewport ) {
  18389. if ( currentViewport.equals( viewport ) === false ) {
  18390. gl.viewport( viewport.x, viewport.y, viewport.z, viewport.w );
  18391. currentViewport.copy( viewport );
  18392. }
  18393. };
  18394. //
  18395. this.reset = function () {
  18396. for ( var i = 0; i < enabledAttributes.length; i ++ ) {
  18397. if ( enabledAttributes[ i ] === 1 ) {
  18398. gl.disableVertexAttribArray( i );
  18399. enabledAttributes[ i ] = 0;
  18400. }
  18401. }
  18402. capabilities = {};
  18403. compressedTextureFormats = null;
  18404. currentTextureSlot = undefined;
  18405. currentBoundTextures = {};
  18406. currentBlending = null;
  18407. currentColorWrite = null;
  18408. currentDepthWrite = null;
  18409. currentStencilWrite = null;
  18410. currentFlipSided = null;
  18411. };
  18412. };
  18413. // File:src/renderers/webgl/WebGLUniforms.js
  18414. /**
  18415. *
  18416. * Uniforms of a program.
  18417. * Those form a tree structure with a special top-level container for the root,
  18418. * which you get by calling 'new WebGLUniforms( gl, program, renderer )'.
  18419. *
  18420. *
  18421. * Properties of inner nodes including the top-level container:
  18422. *
  18423. * .seq - array of nested uniforms
  18424. * .map - nested uniforms by name
  18425. *
  18426. *
  18427. * Methods of all nodes except the top-level container:
  18428. *
  18429. * .setValue( gl, value, [renderer] )
  18430. *
  18431. * uploads a uniform value(s)
  18432. * the 'renderer' parameter is needed for sampler uniforms
  18433. *
  18434. *
  18435. * Static methods of the top-level container (renderer factorizations):
  18436. *
  18437. * .upload( gl, seq, values, renderer )
  18438. *
  18439. * sets uniforms in 'seq' to 'values[id].value'
  18440. *
  18441. * .seqWithValue( seq, values ) : filteredSeq
  18442. *
  18443. * filters 'seq' entries with corresponding entry in values
  18444. *
  18445. * .splitDynamic( seq, values ) : filteredSeq
  18446. *
  18447. * filters 'seq' entries with dynamic entry and removes them from 'seq'
  18448. *
  18449. *
  18450. * Methods of the top-level container (renderer factorizations):
  18451. *
  18452. * .setValue( gl, name, value )
  18453. *
  18454. * sets uniform with name 'name' to 'value'
  18455. *
  18456. * .set( gl, obj, prop )
  18457. *
  18458. * sets uniform from object and property with same name than uniform
  18459. *
  18460. * .setOptional( gl, obj, prop )
  18461. *
  18462. * like .set for an optional property of the object
  18463. *
  18464. *
  18465. * @author tschw
  18466. *
  18467. */
  18468. THREE.WebGLUniforms = ( function() { // scope
  18469. // --- Base for inner nodes (including the root) ---
  18470. var UniformContainer = function() {
  18471. this.seq = [];
  18472. this.map = {};
  18473. },
  18474. // --- Utilities ---
  18475. // Array Caches (provide typed arrays for temporary by size)
  18476. arrayCacheF32 = [],
  18477. arrayCacheI32 = [],
  18478. uncacheTemporaryArrays = function() {
  18479. arrayCacheF32.length = 0;
  18480. arrayCacheI32.length = 0;
  18481. },
  18482. // Flattening for arrays of vectors and matrices
  18483. flatten = function( array, nBlocks, blockSize ) {
  18484. var firstElem = array[ 0 ];
  18485. if ( firstElem <= 0 || firstElem > 0 ) return array;
  18486. // unoptimized: ! isNaN( firstElem )
  18487. // see http://jacksondunstan.com/articles/983
  18488. var n = nBlocks * blockSize,
  18489. r = arrayCacheF32[ n ];
  18490. if ( r === undefined ) {
  18491. r = new Float32Array( n );
  18492. arrayCacheF32[ n ] = r;
  18493. }
  18494. if ( nBlocks !== 0 ) {
  18495. firstElem.toArray( r, 0 );
  18496. for ( var i = 1, offset = 0; i !== nBlocks; ++ i ) {
  18497. offset += blockSize;
  18498. array[ i ].toArray( r, offset );
  18499. }
  18500. }
  18501. return r;
  18502. },
  18503. // Texture unit allocation
  18504. allocTexUnits = function( renderer, n ) {
  18505. var r = arrayCacheI32[ n ];
  18506. if ( r === undefined ) {
  18507. r = new Int32Array( n );
  18508. arrayCacheI32[ n ] = r;
  18509. }
  18510. for ( var i = 0; i !== n; ++ i )
  18511. r[ i ] = renderer.allocTextureUnit();
  18512. return r;
  18513. },
  18514. // --- Setters ---
  18515. // Note: Defining these methods externally, because they come in a bunch
  18516. // and this way their names minify.
  18517. // Single scalar
  18518. setValue1f = function( gl, v ) { gl.uniform1f( this.addr, v ); },
  18519. setValue1i = function( gl, v ) { gl.uniform1i( this.addr, v ); },
  18520. // Single float vector (from flat array or THREE.VectorN)
  18521. setValue2fv = function( gl, v ) {
  18522. if ( v.x === undefined ) gl.uniform2fv( this.addr, v );
  18523. else gl.uniform2f( this.addr, v.x, v.y );
  18524. },
  18525. setValue3fv = function( gl, v ) {
  18526. if ( v.x !== undefined )
  18527. gl.uniform3f( this.addr, v.x, v.y, v.z );
  18528. else if ( v.r !== undefined )
  18529. gl.uniform3f( this.addr, v.r, v.g, v.b );
  18530. else
  18531. gl.uniform3fv( this.addr, v );
  18532. },
  18533. setValue4fv = function( gl, v ) {
  18534. if ( v.x === undefined ) gl.uniform4fv( this.addr, v );
  18535. else gl.uniform4f( this.addr, v.x, v.y, v.z, v.w );
  18536. },
  18537. // Single matrix (from flat array or MatrixN)
  18538. setValue2fm = function( gl, v ) {
  18539. gl.uniformMatrix2fv( this.addr, false, v.elements || v );
  18540. },
  18541. setValue3fm = function( gl, v ) {
  18542. gl.uniformMatrix3fv( this.addr, false, v.elements || v );
  18543. },
  18544. setValue4fm = function( gl, v ) {
  18545. gl.uniformMatrix4fv( this.addr, false, v.elements || v );
  18546. },
  18547. // Single texture (2D / Cube)
  18548. setValueT1 = function( gl, v, renderer ) {
  18549. var unit = renderer.allocTextureUnit();
  18550. gl.uniform1i( this.addr, unit );
  18551. if ( v ) renderer.setTexture2D( v, unit );
  18552. },
  18553. setValueT6 = function( gl, v, renderer ) {
  18554. var unit = renderer.allocTextureUnit();
  18555. gl.uniform1i( this.addr, unit );
  18556. if ( v ) renderer.setTextureCube( v, unit );
  18557. },
  18558. // Integer / Boolean vectors or arrays thereof (always flat arrays)
  18559. setValue2iv = function( gl, v ) { gl.uniform2iv( this.addr, v ); },
  18560. setValue3iv = function( gl, v ) { gl.uniform3iv( this.addr, v ); },
  18561. setValue4iv = function( gl, v ) { gl.uniform4iv( this.addr, v ); },
  18562. // Helper to pick the right setter for the singular case
  18563. getSingularSetter = function( type ) {
  18564. switch ( type ) {
  18565. case 0x1406: return setValue1f; // FLOAT
  18566. case 0x8b50: return setValue2fv; // _VEC2
  18567. case 0x8b51: return setValue3fv; // _VEC3
  18568. case 0x8b52: return setValue4fv; // _VEC4
  18569. case 0x8b5a: return setValue2fm; // _MAT2
  18570. case 0x8b5b: return setValue3fm; // _MAT3
  18571. case 0x8b5c: return setValue4fm; // _MAT4
  18572. case 0x8b5e: return setValueT1; // SAMPLER_2D
  18573. case 0x8b60: return setValueT6; // SAMPLER_CUBE
  18574. case 0x1404: case 0x8b56: return setValue1i; // INT, BOOL
  18575. case 0x8b53: case 0x8b57: return setValue2iv; // _VEC2
  18576. case 0x8b54: case 0x8b58: return setValue3iv; // _VEC3
  18577. case 0x8b55: case 0x8b59: return setValue4iv; // _VEC4
  18578. }
  18579. },
  18580. // Array of scalars
  18581. setValue1fv = function( gl, v ) { gl.uniform1fv( this.addr, v ); },
  18582. setValue1iv = function( gl, v ) { gl.uniform1iv( this.addr, v ); },
  18583. // Array of vectors (flat or from THREE classes)
  18584. setValueV2a = function( gl, v ) {
  18585. gl.uniform2fv( this.addr, flatten( v, this.size, 2 ) );
  18586. },
  18587. setValueV3a = function( gl, v ) {
  18588. gl.uniform3fv( this.addr, flatten( v, this.size, 3 ) );
  18589. },
  18590. setValueV4a = function( gl, v ) {
  18591. gl.uniform4fv( this.addr, flatten( v, this.size, 4 ) );
  18592. },
  18593. // Array of matrices (flat or from THREE clases)
  18594. setValueM2a = function( gl, v ) {
  18595. gl.uniformMatrix2fv( this.addr, false, flatten( v, this.size, 4 ) );
  18596. },
  18597. setValueM3a = function( gl, v ) {
  18598. gl.uniformMatrix3fv( this.addr, false, flatten( v, this.size, 9 ) );
  18599. },
  18600. setValueM4a = function( gl, v ) {
  18601. gl.uniformMatrix4fv( this.addr, false, flatten( v, this.size, 16 ) );
  18602. },
  18603. // Array of textures (2D / Cube)
  18604. setValueT1a = function( gl, v, renderer ) {
  18605. var n = v.length,
  18606. units = allocTexUnits( renderer, n );
  18607. gl.uniform1iv( this.addr, units );
  18608. for ( var i = 0; i !== n; ++ i ) {
  18609. var tex = v[ i ];
  18610. if ( tex ) renderer.setTexture2D( tex, units[ i ] );
  18611. }
  18612. },
  18613. setValueT6a = function( gl, v, renderer ) {
  18614. var n = v.length,
  18615. units = allocTexUnits( renderer, n );
  18616. gl.uniform1iv( this.addr, units );
  18617. for ( var i = 0; i !== n; ++ i ) {
  18618. var tex = v[ i ];
  18619. if ( tex ) renderer.setTextureCube( tex, units[ i ] );
  18620. }
  18621. },
  18622. // Helper to pick the right setter for a pure (bottom-level) array
  18623. getPureArraySetter = function( type ) {
  18624. switch ( type ) {
  18625. case 0x1406: return setValue1fv; // FLOAT
  18626. case 0x8b50: return setValueV2a; // _VEC2
  18627. case 0x8b51: return setValueV3a; // _VEC3
  18628. case 0x8b52: return setValueV4a; // _VEC4
  18629. case 0x8b5a: return setValueM2a; // _MAT2
  18630. case 0x8b5b: return setValueM3a; // _MAT3
  18631. case 0x8b5c: return setValueM4a; // _MAT4
  18632. case 0x8b5e: return setValueT1a; // SAMPLER_2D
  18633. case 0x8b60: return setValueT6a; // SAMPLER_CUBE
  18634. case 0x1404: case 0x8b56: return setValue1iv; // INT, BOOL
  18635. case 0x8b53: case 0x8b57: return setValue2iv; // _VEC2
  18636. case 0x8b54: case 0x8b58: return setValue3iv; // _VEC3
  18637. case 0x8b55: case 0x8b59: return setValue4iv; // _VEC4
  18638. }
  18639. },
  18640. // --- Uniform Classes ---
  18641. SingleUniform = function SingleUniform( id, activeInfo, addr ) {
  18642. this.id = id;
  18643. this.addr = addr;
  18644. this.setValue = getSingularSetter( activeInfo.type );
  18645. // this.path = activeInfo.name; // DEBUG
  18646. },
  18647. PureArrayUniform = function( id, activeInfo, addr ) {
  18648. this.id = id;
  18649. this.addr = addr;
  18650. this.size = activeInfo.size;
  18651. this.setValue = getPureArraySetter( activeInfo.type );
  18652. // this.path = activeInfo.name; // DEBUG
  18653. },
  18654. StructuredUniform = function( id ) {
  18655. this.id = id;
  18656. UniformContainer.call( this ); // mix-in
  18657. };
  18658. StructuredUniform.prototype.setValue = function( gl, value ) {
  18659. // Note: Don't need an extra 'renderer' parameter, since samplers
  18660. // are not allowed in structured uniforms.
  18661. var seq = this.seq;
  18662. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  18663. var u = seq[ i ];
  18664. u.setValue( gl, value[ u.id ] );
  18665. }
  18666. };
  18667. // --- Top-level ---
  18668. // Parser - builds up the property tree from the path strings
  18669. var RePathPart = /([\w\d_]+)(\])?(\[|\.)?/g,
  18670. // extracts
  18671. // - the identifier (member name or array index)
  18672. // - followed by an optional right bracket (found when array index)
  18673. // - followed by an optional left bracket or dot (type of subscript)
  18674. //
  18675. // Note: These portions can be read in a non-overlapping fashion and
  18676. // allow straightforward parsing of the hierarchy that WebGL encodes
  18677. // in the uniform names.
  18678. addUniform = function( container, uniformObject ) {
  18679. container.seq.push( uniformObject );
  18680. container.map[ uniformObject.id ] = uniformObject;
  18681. },
  18682. parseUniform = function( activeInfo, addr, container ) {
  18683. var path = activeInfo.name,
  18684. pathLength = path.length;
  18685. // reset RegExp object, because of the early exit of a previous run
  18686. RePathPart.lastIndex = 0;
  18687. for (; ;) {
  18688. var match = RePathPart.exec( path ),
  18689. matchEnd = RePathPart.lastIndex,
  18690. id = match[ 1 ],
  18691. idIsIndex = match[ 2 ] === ']',
  18692. subscript = match[ 3 ];
  18693. if ( idIsIndex ) id = id | 0; // convert to integer
  18694. if ( subscript === undefined ||
  18695. subscript === '[' && matchEnd + 2 === pathLength ) {
  18696. // bare name or "pure" bottom-level array "[0]" suffix
  18697. addUniform( container, subscript === undefined ?
  18698. new SingleUniform( id, activeInfo, addr ) :
  18699. new PureArrayUniform( id, activeInfo, addr ) );
  18700. break;
  18701. } else {
  18702. // step into inner node / create it in case it doesn't exist
  18703. var map = container.map,
  18704. next = map[ id ];
  18705. if ( next === undefined ) {
  18706. next = new StructuredUniform( id );
  18707. addUniform( container, next );
  18708. }
  18709. container = next;
  18710. }
  18711. }
  18712. },
  18713. // Root Container
  18714. WebGLUniforms = function WebGLUniforms( gl, program, renderer ) {
  18715. UniformContainer.call( this );
  18716. this.renderer = renderer;
  18717. var n = gl.getProgramParameter( program, gl.ACTIVE_UNIFORMS );
  18718. for ( var i = 0; i !== n; ++ i ) {
  18719. var info = gl.getActiveUniform( program, i ),
  18720. path = info.name,
  18721. addr = gl.getUniformLocation( program, path );
  18722. parseUniform( info, addr, this );
  18723. }
  18724. };
  18725. WebGLUniforms.prototype.setValue = function( gl, name, value ) {
  18726. var u = this.map[ name ];
  18727. if ( u !== undefined ) u.setValue( gl, value, this.renderer );
  18728. };
  18729. WebGLUniforms.prototype.set = function( gl, object, name ) {
  18730. var u = this.map[ name ];
  18731. if ( u !== undefined ) u.setValue( gl, object[ name ], this.renderer );
  18732. };
  18733. WebGLUniforms.prototype.setOptional = function( gl, object, name ) {
  18734. var v = object[ name ];
  18735. if ( v !== undefined ) this.setValue( gl, name, v );
  18736. };
  18737. // Static interface
  18738. WebGLUniforms.upload = function( gl, seq, values, renderer ) {
  18739. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  18740. var u = seq[ i ],
  18741. v = values[ u.id ];
  18742. if ( v.needsUpdate !== false ) {
  18743. // note: always updating when .needsUpdate is undefined
  18744. u.setValue( gl, v.value, renderer );
  18745. }
  18746. }
  18747. };
  18748. WebGLUniforms.seqWithValue = function( seq, values ) {
  18749. var r = [];
  18750. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  18751. var u = seq[ i ];
  18752. if ( u.id in values ) r.push( u );
  18753. }
  18754. return r;
  18755. };
  18756. WebGLUniforms.splitDynamic = function( seq, values ) {
  18757. var r = null,
  18758. n = seq.length,
  18759. w = 0;
  18760. for ( var i = 0; i !== n; ++ i ) {
  18761. var u = seq[ i ],
  18762. v = values[ u.id ];
  18763. if ( v && v.dynamic === true ) {
  18764. if ( r === null ) r = [];
  18765. r.push( u );
  18766. } else {
  18767. // in-place compact 'seq', removing the matches
  18768. if ( w < i ) seq[ w ] = u;
  18769. ++ w;
  18770. }
  18771. }
  18772. if ( w < n ) seq.length = w;
  18773. return r;
  18774. };
  18775. WebGLUniforms.evalDynamic = function( seq, values, object, camera ) {
  18776. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  18777. var v = values[ seq[ i ].id ],
  18778. f = v.onUpdateCallback;
  18779. if ( f !== undefined ) f.call( v, object, camera );
  18780. }
  18781. };
  18782. return WebGLUniforms;
  18783. } )();
  18784. // File:src/renderers/webgl/plugins/LensFlarePlugin.js
  18785. /**
  18786. * @author mikael emtinger / http://gomo.se/
  18787. * @author alteredq / http://alteredqualia.com/
  18788. */
  18789. THREE.LensFlarePlugin = function ( renderer, flares ) {
  18790. var gl = renderer.context;
  18791. var state = renderer.state;
  18792. var vertexBuffer, elementBuffer;
  18793. var shader, program, attributes, uniforms;
  18794. var tempTexture, occlusionTexture;
  18795. function init() {
  18796. var vertices = new Float32Array( [
  18797. - 1, - 1, 0, 0,
  18798. 1, - 1, 1, 0,
  18799. 1, 1, 1, 1,
  18800. - 1, 1, 0, 1
  18801. ] );
  18802. var faces = new Uint16Array( [
  18803. 0, 1, 2,
  18804. 0, 2, 3
  18805. ] );
  18806. // buffers
  18807. vertexBuffer = gl.createBuffer();
  18808. elementBuffer = gl.createBuffer();
  18809. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  18810. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  18811. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  18812. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  18813. // textures
  18814. tempTexture = gl.createTexture();
  18815. occlusionTexture = gl.createTexture();
  18816. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  18817. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGB, 16, 16, 0, gl.RGB, gl.UNSIGNED_BYTE, null );
  18818. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  18819. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  18820. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  18821. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  18822. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  18823. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGBA, 16, 16, 0, gl.RGBA, gl.UNSIGNED_BYTE, null );
  18824. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  18825. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  18826. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  18827. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  18828. shader = {
  18829. vertexShader: [
  18830. "uniform lowp int renderType;",
  18831. "uniform vec3 screenPosition;",
  18832. "uniform vec2 scale;",
  18833. "uniform float rotation;",
  18834. "uniform sampler2D occlusionMap;",
  18835. "attribute vec2 position;",
  18836. "attribute vec2 uv;",
  18837. "varying vec2 vUV;",
  18838. "varying float vVisibility;",
  18839. "void main() {",
  18840. "vUV = uv;",
  18841. "vec2 pos = position;",
  18842. "if ( renderType == 2 ) {",
  18843. "vec4 visibility = texture2D( occlusionMap, vec2( 0.1, 0.1 ) );",
  18844. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.1 ) );",
  18845. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.1 ) );",
  18846. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) );",
  18847. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.9 ) );",
  18848. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) );",
  18849. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.9 ) );",
  18850. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) );",
  18851. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.5 ) );",
  18852. "vVisibility = visibility.r / 9.0;",
  18853. "vVisibility *= 1.0 - visibility.g / 9.0;",
  18854. "vVisibility *= visibility.b / 9.0;",
  18855. "vVisibility *= 1.0 - visibility.a / 9.0;",
  18856. "pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
  18857. "pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
  18858. "}",
  18859. "gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
  18860. "}"
  18861. ].join( "\n" ),
  18862. fragmentShader: [
  18863. "uniform lowp int renderType;",
  18864. "uniform sampler2D map;",
  18865. "uniform float opacity;",
  18866. "uniform vec3 color;",
  18867. "varying vec2 vUV;",
  18868. "varying float vVisibility;",
  18869. "void main() {",
  18870. // pink square
  18871. "if ( renderType == 0 ) {",
  18872. "gl_FragColor = vec4( 1.0, 0.0, 1.0, 0.0 );",
  18873. // restore
  18874. "} else if ( renderType == 1 ) {",
  18875. "gl_FragColor = texture2D( map, vUV );",
  18876. // flare
  18877. "} else {",
  18878. "vec4 texture = texture2D( map, vUV );",
  18879. "texture.a *= opacity * vVisibility;",
  18880. "gl_FragColor = texture;",
  18881. "gl_FragColor.rgb *= color;",
  18882. "}",
  18883. "}"
  18884. ].join( "\n" )
  18885. };
  18886. program = createProgram( shader );
  18887. attributes = {
  18888. vertex: gl.getAttribLocation ( program, "position" ),
  18889. uv: gl.getAttribLocation ( program, "uv" )
  18890. };
  18891. uniforms = {
  18892. renderType: gl.getUniformLocation( program, "renderType" ),
  18893. map: gl.getUniformLocation( program, "map" ),
  18894. occlusionMap: gl.getUniformLocation( program, "occlusionMap" ),
  18895. opacity: gl.getUniformLocation( program, "opacity" ),
  18896. color: gl.getUniformLocation( program, "color" ),
  18897. scale: gl.getUniformLocation( program, "scale" ),
  18898. rotation: gl.getUniformLocation( program, "rotation" ),
  18899. screenPosition: gl.getUniformLocation( program, "screenPosition" )
  18900. };
  18901. }
  18902. /*
  18903. * Render lens flares
  18904. * Method: renders 16x16 0xff00ff-colored points scattered over the light source area,
  18905. * reads these back and calculates occlusion.
  18906. */
  18907. this.render = function ( scene, camera, viewport ) {
  18908. if ( flares.length === 0 ) return;
  18909. var tempPosition = new THREE.Vector3();
  18910. var invAspect = viewport.w / viewport.z,
  18911. halfViewportWidth = viewport.z * 0.5,
  18912. halfViewportHeight = viewport.w * 0.5;
  18913. var size = 16 / viewport.w,
  18914. scale = new THREE.Vector2( size * invAspect, size );
  18915. var screenPosition = new THREE.Vector3( 1, 1, 0 ),
  18916. screenPositionPixels = new THREE.Vector2( 1, 1 );
  18917. var validArea = new THREE.Box2();
  18918. validArea.min.set( 0, 0 );
  18919. validArea.max.set( viewport.z - 16, viewport.w - 16 );
  18920. if ( program === undefined ) {
  18921. init();
  18922. }
  18923. gl.useProgram( program );
  18924. state.initAttributes();
  18925. state.enableAttribute( attributes.vertex );
  18926. state.enableAttribute( attributes.uv );
  18927. state.disableUnusedAttributes();
  18928. // loop through all lens flares to update their occlusion and positions
  18929. // setup gl and common used attribs/uniforms
  18930. gl.uniform1i( uniforms.occlusionMap, 0 );
  18931. gl.uniform1i( uniforms.map, 1 );
  18932. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  18933. gl.vertexAttribPointer( attributes.vertex, 2, gl.FLOAT, false, 2 * 8, 0 );
  18934. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  18935. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  18936. state.disable( gl.CULL_FACE );
  18937. state.setDepthWrite( false );
  18938. for ( var i = 0, l = flares.length; i < l; i ++ ) {
  18939. size = 16 / viewport.w;
  18940. scale.set( size * invAspect, size );
  18941. // calc object screen position
  18942. var flare = flares[ i ];
  18943. tempPosition.set( flare.matrixWorld.elements[ 12 ], flare.matrixWorld.elements[ 13 ], flare.matrixWorld.elements[ 14 ] );
  18944. tempPosition.applyMatrix4( camera.matrixWorldInverse );
  18945. tempPosition.applyProjection( camera.projectionMatrix );
  18946. // setup arrays for gl programs
  18947. screenPosition.copy( tempPosition );
  18948. // horizontal and vertical coordinate of the lower left corner of the pixels to copy
  18949. screenPositionPixels.x = viewport.x + ( screenPosition.x * halfViewportWidth ) + halfViewportWidth - 8;
  18950. screenPositionPixels.y = viewport.y + ( screenPosition.y * halfViewportHeight ) + halfViewportHeight - 8;
  18951. // screen cull
  18952. if ( validArea.containsPoint( screenPositionPixels ) === true ) {
  18953. // save current RGB to temp texture
  18954. state.activeTexture( gl.TEXTURE0 );
  18955. state.bindTexture( gl.TEXTURE_2D, null );
  18956. state.activeTexture( gl.TEXTURE1 );
  18957. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  18958. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGB, screenPositionPixels.x, screenPositionPixels.y, 16, 16, 0 );
  18959. // render pink quad
  18960. gl.uniform1i( uniforms.renderType, 0 );
  18961. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  18962. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  18963. state.disable( gl.BLEND );
  18964. state.enable( gl.DEPTH_TEST );
  18965. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  18966. // copy result to occlusionMap
  18967. state.activeTexture( gl.TEXTURE0 );
  18968. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  18969. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGBA, screenPositionPixels.x, screenPositionPixels.y, 16, 16, 0 );
  18970. // restore graphics
  18971. gl.uniform1i( uniforms.renderType, 1 );
  18972. state.disable( gl.DEPTH_TEST );
  18973. state.activeTexture( gl.TEXTURE1 );
  18974. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  18975. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  18976. // update object positions
  18977. flare.positionScreen.copy( screenPosition );
  18978. if ( flare.customUpdateCallback ) {
  18979. flare.customUpdateCallback( flare );
  18980. } else {
  18981. flare.updateLensFlares();
  18982. }
  18983. // render flares
  18984. gl.uniform1i( uniforms.renderType, 2 );
  18985. state.enable( gl.BLEND );
  18986. for ( var j = 0, jl = flare.lensFlares.length; j < jl; j ++ ) {
  18987. var sprite = flare.lensFlares[ j ];
  18988. if ( sprite.opacity > 0.001 && sprite.scale > 0.001 ) {
  18989. screenPosition.x = sprite.x;
  18990. screenPosition.y = sprite.y;
  18991. screenPosition.z = sprite.z;
  18992. size = sprite.size * sprite.scale / viewport.w;
  18993. scale.x = size * invAspect;
  18994. scale.y = size;
  18995. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  18996. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  18997. gl.uniform1f( uniforms.rotation, sprite.rotation );
  18998. gl.uniform1f( uniforms.opacity, sprite.opacity );
  18999. gl.uniform3f( uniforms.color, sprite.color.r, sprite.color.g, sprite.color.b );
  19000. state.setBlending( sprite.blending, sprite.blendEquation, sprite.blendSrc, sprite.blendDst );
  19001. renderer.setTexture2D( sprite.texture, 1 );
  19002. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  19003. }
  19004. }
  19005. }
  19006. }
  19007. // restore gl
  19008. state.enable( gl.CULL_FACE );
  19009. state.enable( gl.DEPTH_TEST );
  19010. state.setDepthWrite( true );
  19011. renderer.resetGLState();
  19012. };
  19013. function createProgram ( shader ) {
  19014. var program = gl.createProgram();
  19015. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  19016. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  19017. var prefix = "precision " + renderer.getPrecision() + " float;\n";
  19018. gl.shaderSource( fragmentShader, prefix + shader.fragmentShader );
  19019. gl.shaderSource( vertexShader, prefix + shader.vertexShader );
  19020. gl.compileShader( fragmentShader );
  19021. gl.compileShader( vertexShader );
  19022. gl.attachShader( program, fragmentShader );
  19023. gl.attachShader( program, vertexShader );
  19024. gl.linkProgram( program );
  19025. return program;
  19026. }
  19027. };
  19028. // File:src/renderers/webgl/plugins/SpritePlugin.js
  19029. /**
  19030. * @author mikael emtinger / http://gomo.se/
  19031. * @author alteredq / http://alteredqualia.com/
  19032. */
  19033. THREE.SpritePlugin = function ( renderer, sprites ) {
  19034. var gl = renderer.context;
  19035. var state = renderer.state;
  19036. var vertexBuffer, elementBuffer;
  19037. var program, attributes, uniforms;
  19038. var texture;
  19039. // decompose matrixWorld
  19040. var spritePosition = new THREE.Vector3();
  19041. var spriteRotation = new THREE.Quaternion();
  19042. var spriteScale = new THREE.Vector3();
  19043. function init() {
  19044. var vertices = new Float32Array( [
  19045. - 0.5, - 0.5, 0, 0,
  19046. 0.5, - 0.5, 1, 0,
  19047. 0.5, 0.5, 1, 1,
  19048. - 0.5, 0.5, 0, 1
  19049. ] );
  19050. var faces = new Uint16Array( [
  19051. 0, 1, 2,
  19052. 0, 2, 3
  19053. ] );
  19054. vertexBuffer = gl.createBuffer();
  19055. elementBuffer = gl.createBuffer();
  19056. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  19057. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  19058. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  19059. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  19060. program = createProgram();
  19061. attributes = {
  19062. position: gl.getAttribLocation ( program, 'position' ),
  19063. uv: gl.getAttribLocation ( program, 'uv' )
  19064. };
  19065. uniforms = {
  19066. uvOffset: gl.getUniformLocation( program, 'uvOffset' ),
  19067. uvScale: gl.getUniformLocation( program, 'uvScale' ),
  19068. rotation: gl.getUniformLocation( program, 'rotation' ),
  19069. scale: gl.getUniformLocation( program, 'scale' ),
  19070. color: gl.getUniformLocation( program, 'color' ),
  19071. map: gl.getUniformLocation( program, 'map' ),
  19072. opacity: gl.getUniformLocation( program, 'opacity' ),
  19073. modelViewMatrix: gl.getUniformLocation( program, 'modelViewMatrix' ),
  19074. projectionMatrix: gl.getUniformLocation( program, 'projectionMatrix' ),
  19075. fogType: gl.getUniformLocation( program, 'fogType' ),
  19076. fogDensity: gl.getUniformLocation( program, 'fogDensity' ),
  19077. fogNear: gl.getUniformLocation( program, 'fogNear' ),
  19078. fogFar: gl.getUniformLocation( program, 'fogFar' ),
  19079. fogColor: gl.getUniformLocation( program, 'fogColor' ),
  19080. alphaTest: gl.getUniformLocation( program, 'alphaTest' )
  19081. };
  19082. var canvas = document.createElement( 'canvas' );
  19083. canvas.width = 8;
  19084. canvas.height = 8;
  19085. var context = canvas.getContext( '2d' );
  19086. context.fillStyle = 'white';
  19087. context.fillRect( 0, 0, 8, 8 );
  19088. texture = new THREE.Texture( canvas );
  19089. texture.needsUpdate = true;
  19090. }
  19091. this.render = function ( scene, camera ) {
  19092. if ( sprites.length === 0 ) return;
  19093. // setup gl
  19094. if ( program === undefined ) {
  19095. init();
  19096. }
  19097. gl.useProgram( program );
  19098. state.initAttributes();
  19099. state.enableAttribute( attributes.position );
  19100. state.enableAttribute( attributes.uv );
  19101. state.disableUnusedAttributes();
  19102. state.disable( gl.CULL_FACE );
  19103. state.enable( gl.BLEND );
  19104. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  19105. gl.vertexAttribPointer( attributes.position, 2, gl.FLOAT, false, 2 * 8, 0 );
  19106. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  19107. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  19108. gl.uniformMatrix4fv( uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
  19109. state.activeTexture( gl.TEXTURE0 );
  19110. gl.uniform1i( uniforms.map, 0 );
  19111. var oldFogType = 0;
  19112. var sceneFogType = 0;
  19113. var fog = scene.fog;
  19114. if ( fog ) {
  19115. gl.uniform3f( uniforms.fogColor, fog.color.r, fog.color.g, fog.color.b );
  19116. if ( fog instanceof THREE.Fog ) {
  19117. gl.uniform1f( uniforms.fogNear, fog.near );
  19118. gl.uniform1f( uniforms.fogFar, fog.far );
  19119. gl.uniform1i( uniforms.fogType, 1 );
  19120. oldFogType = 1;
  19121. sceneFogType = 1;
  19122. } else if ( fog instanceof THREE.FogExp2 ) {
  19123. gl.uniform1f( uniforms.fogDensity, fog.density );
  19124. gl.uniform1i( uniforms.fogType, 2 );
  19125. oldFogType = 2;
  19126. sceneFogType = 2;
  19127. }
  19128. } else {
  19129. gl.uniform1i( uniforms.fogType, 0 );
  19130. oldFogType = 0;
  19131. sceneFogType = 0;
  19132. }
  19133. // update positions and sort
  19134. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  19135. var sprite = sprites[ i ];
  19136. sprite.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, sprite.matrixWorld );
  19137. sprite.z = - sprite.modelViewMatrix.elements[ 14 ];
  19138. }
  19139. sprites.sort( painterSortStable );
  19140. // render all sprites
  19141. var scale = [];
  19142. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  19143. var sprite = sprites[ i ];
  19144. var material = sprite.material;
  19145. gl.uniform1f( uniforms.alphaTest, material.alphaTest );
  19146. gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, sprite.modelViewMatrix.elements );
  19147. sprite.matrixWorld.decompose( spritePosition, spriteRotation, spriteScale );
  19148. scale[ 0 ] = spriteScale.x;
  19149. scale[ 1 ] = spriteScale.y;
  19150. var fogType = 0;
  19151. if ( scene.fog && material.fog ) {
  19152. fogType = sceneFogType;
  19153. }
  19154. if ( oldFogType !== fogType ) {
  19155. gl.uniform1i( uniforms.fogType, fogType );
  19156. oldFogType = fogType;
  19157. }
  19158. if ( material.map !== null ) {
  19159. gl.uniform2f( uniforms.uvOffset, material.map.offset.x, material.map.offset.y );
  19160. gl.uniform2f( uniforms.uvScale, material.map.repeat.x, material.map.repeat.y );
  19161. } else {
  19162. gl.uniform2f( uniforms.uvOffset, 0, 0 );
  19163. gl.uniform2f( uniforms.uvScale, 1, 1 );
  19164. }
  19165. gl.uniform1f( uniforms.opacity, material.opacity );
  19166. gl.uniform3f( uniforms.color, material.color.r, material.color.g, material.color.b );
  19167. gl.uniform1f( uniforms.rotation, material.rotation );
  19168. gl.uniform2fv( uniforms.scale, scale );
  19169. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst );
  19170. state.setDepthTest( material.depthTest );
  19171. state.setDepthWrite( material.depthWrite );
  19172. if ( material.map ) {
  19173. renderer.setTexture2D( material.map, 0 );
  19174. } else {
  19175. renderer.setTexture2D( texture, 0 );
  19176. }
  19177. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  19178. }
  19179. // restore gl
  19180. state.enable( gl.CULL_FACE );
  19181. renderer.resetGLState();
  19182. };
  19183. function createProgram () {
  19184. var program = gl.createProgram();
  19185. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  19186. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  19187. gl.shaderSource( vertexShader, [
  19188. 'precision ' + renderer.getPrecision() + ' float;',
  19189. 'uniform mat4 modelViewMatrix;',
  19190. 'uniform mat4 projectionMatrix;',
  19191. 'uniform float rotation;',
  19192. 'uniform vec2 scale;',
  19193. 'uniform vec2 uvOffset;',
  19194. 'uniform vec2 uvScale;',
  19195. 'attribute vec2 position;',
  19196. 'attribute vec2 uv;',
  19197. 'varying vec2 vUV;',
  19198. 'void main() {',
  19199. 'vUV = uvOffset + uv * uvScale;',
  19200. 'vec2 alignedPosition = position * scale;',
  19201. 'vec2 rotatedPosition;',
  19202. 'rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;',
  19203. 'rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;',
  19204. 'vec4 finalPosition;',
  19205. 'finalPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );',
  19206. 'finalPosition.xy += rotatedPosition;',
  19207. 'finalPosition = projectionMatrix * finalPosition;',
  19208. 'gl_Position = finalPosition;',
  19209. '}'
  19210. ].join( '\n' ) );
  19211. gl.shaderSource( fragmentShader, [
  19212. 'precision ' + renderer.getPrecision() + ' float;',
  19213. 'uniform vec3 color;',
  19214. 'uniform sampler2D map;',
  19215. 'uniform float opacity;',
  19216. 'uniform int fogType;',
  19217. 'uniform vec3 fogColor;',
  19218. 'uniform float fogDensity;',
  19219. 'uniform float fogNear;',
  19220. 'uniform float fogFar;',
  19221. 'uniform float alphaTest;',
  19222. 'varying vec2 vUV;',
  19223. 'void main() {',
  19224. 'vec4 texture = texture2D( map, vUV );',
  19225. 'if ( texture.a < alphaTest ) discard;',
  19226. 'gl_FragColor = vec4( color * texture.xyz, texture.a * opacity );',
  19227. 'if ( fogType > 0 ) {',
  19228. 'float depth = gl_FragCoord.z / gl_FragCoord.w;',
  19229. 'float fogFactor = 0.0;',
  19230. 'if ( fogType == 1 ) {',
  19231. 'fogFactor = smoothstep( fogNear, fogFar, depth );',
  19232. '} else {',
  19233. 'const float LOG2 = 1.442695;',
  19234. 'fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );',
  19235. 'fogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );',
  19236. '}',
  19237. 'gl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );',
  19238. '}',
  19239. '}'
  19240. ].join( '\n' ) );
  19241. gl.compileShader( vertexShader );
  19242. gl.compileShader( fragmentShader );
  19243. gl.attachShader( program, vertexShader );
  19244. gl.attachShader( program, fragmentShader );
  19245. gl.linkProgram( program );
  19246. return program;
  19247. }
  19248. function painterSortStable ( a, b ) {
  19249. if ( a.renderOrder !== b.renderOrder ) {
  19250. return a.renderOrder - b.renderOrder;
  19251. } else if ( a.z !== b.z ) {
  19252. return b.z - a.z;
  19253. } else {
  19254. return b.id - a.id;
  19255. }
  19256. }
  19257. };
  19258. // File:src/Three.Legacy.js
  19259. /**
  19260. * @author mrdoob / http://mrdoob.com/
  19261. */
  19262. Object.defineProperties( THREE.Box2.prototype, {
  19263. empty: {
  19264. value: function () {
  19265. console.warn( 'THREE.Box2: .empty() has been renamed to .isEmpty().' );
  19266. return this.isEmpty();
  19267. }
  19268. },
  19269. isIntersectionBox: {
  19270. value: function ( box ) {
  19271. console.warn( 'THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().' );
  19272. return this.intersectsBox( box );
  19273. }
  19274. }
  19275. } );
  19276. Object.defineProperties( THREE.Box3.prototype, {
  19277. empty: {
  19278. value: function () {
  19279. console.warn( 'THREE.Box3: .empty() has been renamed to .isEmpty().' );
  19280. return this.isEmpty();
  19281. }
  19282. },
  19283. isIntersectionBox: {
  19284. value: function ( box ) {
  19285. console.warn( 'THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().' );
  19286. return this.intersectsBox( box );
  19287. }
  19288. },
  19289. isIntersectionSphere: {
  19290. value: function ( sphere ) {
  19291. console.warn( 'THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  19292. return this.intersectsSphere( sphere );
  19293. }
  19294. }
  19295. } );
  19296. Object.defineProperties( THREE.Matrix3.prototype, {
  19297. multiplyVector3: {
  19298. value: function ( vector ) {
  19299. console.warn( 'THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.' );
  19300. return vector.applyMatrix3( this );
  19301. }
  19302. },
  19303. multiplyVector3Array: {
  19304. value: function ( a ) {
  19305. console.warn( 'THREE.Matrix3: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
  19306. return this.applyToVector3Array( a );
  19307. }
  19308. }
  19309. } );
  19310. Object.defineProperties( THREE.Matrix4.prototype, {
  19311. extractPosition: {
  19312. value: function ( m ) {
  19313. console.warn( 'THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().' );
  19314. return this.copyPosition( m );
  19315. }
  19316. },
  19317. setRotationFromQuaternion: {
  19318. value: function ( q ) {
  19319. console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' );
  19320. return this.makeRotationFromQuaternion( q );
  19321. }
  19322. },
  19323. multiplyVector3: {
  19324. value: function ( vector ) {
  19325. console.warn( 'THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) or vector.applyProjection( matrix ) instead.' );
  19326. return vector.applyProjection( this );
  19327. }
  19328. },
  19329. multiplyVector4: {
  19330. value: function ( vector ) {
  19331. console.warn( 'THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  19332. return vector.applyMatrix4( this );
  19333. }
  19334. },
  19335. multiplyVector3Array: {
  19336. value: function ( a ) {
  19337. console.warn( 'THREE.Matrix4: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
  19338. return this.applyToVector3Array( a );
  19339. }
  19340. },
  19341. rotateAxis: {
  19342. value: function ( v ) {
  19343. console.warn( 'THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.' );
  19344. v.transformDirection( this );
  19345. }
  19346. },
  19347. crossVector: {
  19348. value: function ( vector ) {
  19349. console.warn( 'THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  19350. return vector.applyMatrix4( this );
  19351. }
  19352. },
  19353. translate: {
  19354. value: function ( v ) {
  19355. console.error( 'THREE.Matrix4: .translate() has been removed.' );
  19356. }
  19357. },
  19358. rotateX: {
  19359. value: function ( angle ) {
  19360. console.error( 'THREE.Matrix4: .rotateX() has been removed.' );
  19361. }
  19362. },
  19363. rotateY: {
  19364. value: function ( angle ) {
  19365. console.error( 'THREE.Matrix4: .rotateY() has been removed.' );
  19366. }
  19367. },
  19368. rotateZ: {
  19369. value: function ( angle ) {
  19370. console.error( 'THREE.Matrix4: .rotateZ() has been removed.' );
  19371. }
  19372. },
  19373. rotateByAxis: {
  19374. value: function ( axis, angle ) {
  19375. console.error( 'THREE.Matrix4: .rotateByAxis() has been removed.' );
  19376. }
  19377. }
  19378. } );
  19379. Object.defineProperties( THREE.Plane.prototype, {
  19380. isIntersectionLine: {
  19381. value: function ( line ) {
  19382. console.warn( 'THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().' );
  19383. return this.intersectsLine( line );
  19384. }
  19385. }
  19386. } );
  19387. Object.defineProperties( THREE.Quaternion.prototype, {
  19388. multiplyVector3: {
  19389. value: function ( vector ) {
  19390. console.warn( 'THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.' );
  19391. return vector.applyQuaternion( this );
  19392. }
  19393. }
  19394. } );
  19395. Object.defineProperties( THREE.Ray.prototype, {
  19396. isIntersectionBox: {
  19397. value: function ( box ) {
  19398. console.warn( 'THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().' );
  19399. return this.intersectsBox( box );
  19400. }
  19401. },
  19402. isIntersectionPlane: {
  19403. value: function ( plane ) {
  19404. console.warn( 'THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().' );
  19405. return this.intersectsPlane( plane );
  19406. }
  19407. },
  19408. isIntersectionSphere: {
  19409. value: function ( sphere ) {
  19410. console.warn( 'THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  19411. return this.intersectsSphere( sphere );
  19412. }
  19413. }
  19414. } );
  19415. Object.defineProperties( THREE.Vector3.prototype, {
  19416. setEulerFromRotationMatrix: {
  19417. value: function () {
  19418. console.error( 'THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.' );
  19419. }
  19420. },
  19421. setEulerFromQuaternion: {
  19422. value: function () {
  19423. console.error( 'THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.' );
  19424. }
  19425. },
  19426. getPositionFromMatrix: {
  19427. value: function ( m ) {
  19428. console.warn( 'THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().' );
  19429. return this.setFromMatrixPosition( m );
  19430. }
  19431. },
  19432. getScaleFromMatrix: {
  19433. value: function ( m ) {
  19434. console.warn( 'THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().' );
  19435. return this.setFromMatrixScale( m );
  19436. }
  19437. },
  19438. getColumnFromMatrix: {
  19439. value: function ( index, matrix ) {
  19440. console.warn( 'THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().' );
  19441. return this.setFromMatrixColumn( matrix, index );
  19442. }
  19443. }
  19444. } );
  19445. //
  19446. THREE.Face4 = function ( a, b, c, d, normal, color, materialIndex ) {
  19447. console.warn( 'THREE.Face4 has been removed. A THREE.Face3 will be created instead.' );
  19448. return new THREE.Face3( a, b, c, normal, color, materialIndex );
  19449. };
  19450. THREE.Vertex = function ( x, y, z ) {
  19451. console.warn( 'THREE.Vertex has been removed. Use THREE.Vector3 instead.' );
  19452. return new THREE.Vector3( x, y, z );
  19453. };
  19454. //
  19455. Object.defineProperties( THREE.Object3D.prototype, {
  19456. eulerOrder: {
  19457. get: function () {
  19458. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  19459. return this.rotation.order;
  19460. },
  19461. set: function ( value ) {
  19462. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  19463. this.rotation.order = value;
  19464. }
  19465. },
  19466. getChildByName: {
  19467. value: function ( name ) {
  19468. console.warn( 'THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().' );
  19469. return this.getObjectByName( name );
  19470. }
  19471. },
  19472. renderDepth: {
  19473. set: function ( value ) {
  19474. console.warn( 'THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.' );
  19475. }
  19476. },
  19477. translate: {
  19478. value: function ( distance, axis ) {
  19479. console.warn( 'THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.' );
  19480. return this.translateOnAxis( axis, distance );
  19481. }
  19482. },
  19483. useQuaternion: {
  19484. get: function () {
  19485. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  19486. },
  19487. set: function ( value ) {
  19488. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  19489. }
  19490. }
  19491. } );
  19492. //
  19493. Object.defineProperties( THREE, {
  19494. PointCloud: {
  19495. value: function ( geometry, material ) {
  19496. console.warn( 'THREE.PointCloud has been renamed to THREE.Points.' );
  19497. return new THREE.Points( geometry, material );
  19498. }
  19499. },
  19500. ParticleSystem: {
  19501. value: function ( geometry, material ) {
  19502. console.warn( 'THREE.ParticleSystem has been renamed to THREE.Points.' );
  19503. return new THREE.Points( geometry, material );
  19504. }
  19505. }
  19506. } );
  19507. THREE.Particle = THREE.Sprite;
  19508. //
  19509. Object.defineProperties( THREE.Light.prototype, {
  19510. onlyShadow: {
  19511. set: function ( value ) {
  19512. console.warn( 'THREE.Light: .onlyShadow has been removed.' );
  19513. }
  19514. },
  19515. shadowCameraFov: {
  19516. set: function ( value ) {
  19517. console.warn( 'THREE.Light: .shadowCameraFov is now .shadow.camera.fov.' );
  19518. this.shadow.camera.fov = value;
  19519. }
  19520. },
  19521. shadowCameraLeft: {
  19522. set: function ( value ) {
  19523. console.warn( 'THREE.Light: .shadowCameraLeft is now .shadow.camera.left.' );
  19524. this.shadow.camera.left = value;
  19525. }
  19526. },
  19527. shadowCameraRight: {
  19528. set: function ( value ) {
  19529. console.warn( 'THREE.Light: .shadowCameraRight is now .shadow.camera.right.' );
  19530. this.shadow.camera.right = value;
  19531. }
  19532. },
  19533. shadowCameraTop: {
  19534. set: function ( value ) {
  19535. console.warn( 'THREE.Light: .shadowCameraTop is now .shadow.camera.top.' );
  19536. this.shadow.camera.top = value;
  19537. }
  19538. },
  19539. shadowCameraBottom: {
  19540. set: function ( value ) {
  19541. console.warn( 'THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.' );
  19542. this.shadow.camera.bottom = value;
  19543. }
  19544. },
  19545. shadowCameraNear: {
  19546. set: function ( value ) {
  19547. console.warn( 'THREE.Light: .shadowCameraNear is now .shadow.camera.near.' );
  19548. this.shadow.camera.near = value;
  19549. }
  19550. },
  19551. shadowCameraFar: {
  19552. set: function ( value ) {
  19553. console.warn( 'THREE.Light: .shadowCameraFar is now .shadow.camera.far.' );
  19554. this.shadow.camera.far = value;
  19555. }
  19556. },
  19557. shadowCameraVisible: {
  19558. set: function ( value ) {
  19559. console.warn( 'THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.' );
  19560. }
  19561. },
  19562. shadowBias: {
  19563. set: function ( value ) {
  19564. console.warn( 'THREE.Light: .shadowBias is now .shadow.bias.' );
  19565. this.shadow.bias = value;
  19566. }
  19567. },
  19568. shadowDarkness: {
  19569. set: function ( value ) {
  19570. console.warn( 'THREE.Light: .shadowDarkness has been removed.' );
  19571. }
  19572. },
  19573. shadowMapWidth: {
  19574. set: function ( value ) {
  19575. console.warn( 'THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.' );
  19576. this.shadow.mapSize.width = value;
  19577. }
  19578. },
  19579. shadowMapHeight: {
  19580. set: function ( value ) {
  19581. console.warn( 'THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.' );
  19582. this.shadow.mapSize.height = value;
  19583. }
  19584. }
  19585. } );
  19586. //
  19587. Object.defineProperties( THREE.BufferAttribute.prototype, {
  19588. length: {
  19589. get: function () {
  19590. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Please use .count.' );
  19591. return this.array.length;
  19592. }
  19593. }
  19594. } );
  19595. Object.defineProperties( THREE.BufferGeometry.prototype, {
  19596. drawcalls: {
  19597. get: function () {
  19598. console.error( 'THREE.BufferGeometry: .drawcalls has been renamed to .groups.' );
  19599. return this.groups;
  19600. }
  19601. },
  19602. offsets: {
  19603. get: function () {
  19604. console.warn( 'THREE.BufferGeometry: .offsets has been renamed to .groups.' );
  19605. return this.groups;
  19606. }
  19607. },
  19608. addIndex: {
  19609. value: function ( index ) {
  19610. console.warn( 'THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().' );
  19611. this.setIndex( index );
  19612. }
  19613. },
  19614. addDrawCall: {
  19615. value: function ( start, count, indexOffset ) {
  19616. if ( indexOffset !== undefined ) {
  19617. console.warn( 'THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.' );
  19618. }
  19619. console.warn( 'THREE.BufferGeometry: .addDrawCall() is now .addGroup().' );
  19620. this.addGroup( start, count );
  19621. }
  19622. },
  19623. clearDrawCalls: {
  19624. value: function () {
  19625. console.warn( 'THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().' );
  19626. this.clearGroups();
  19627. }
  19628. },
  19629. computeTangents: {
  19630. value: function () {
  19631. console.warn( 'THREE.BufferGeometry: .computeTangents() has been removed.' );
  19632. }
  19633. },
  19634. computeOffsets: {
  19635. value: function () {
  19636. console.warn( 'THREE.BufferGeometry: .computeOffsets() has been removed.' );
  19637. }
  19638. }
  19639. } );
  19640. //
  19641. Object.defineProperties( THREE.Material.prototype, {
  19642. wrapAround: {
  19643. get: function () {
  19644. console.warn( 'THREE.' + this.type + ': .wrapAround has been removed.' );
  19645. },
  19646. set: function ( value ) {
  19647. console.warn( 'THREE.' + this.type + ': .wrapAround has been removed.' );
  19648. }
  19649. },
  19650. wrapRGB: {
  19651. get: function () {
  19652. console.warn( 'THREE.' + this.type + ': .wrapRGB has been removed.' );
  19653. return new THREE.Color();
  19654. }
  19655. }
  19656. } );
  19657. Object.defineProperties( THREE, {
  19658. PointCloudMaterial: {
  19659. value: function ( parameters ) {
  19660. console.warn( 'THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.' );
  19661. return new THREE.PointsMaterial( parameters );
  19662. }
  19663. },
  19664. ParticleBasicMaterial: {
  19665. value: function ( parameters ) {
  19666. console.warn( 'THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.' );
  19667. return new THREE.PointsMaterial( parameters );
  19668. }
  19669. },
  19670. ParticleSystemMaterial:{
  19671. value: function ( parameters ) {
  19672. console.warn( 'THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.' );
  19673. return new THREE.PointsMaterial( parameters );
  19674. }
  19675. }
  19676. } );
  19677. Object.defineProperties( THREE.MeshPhongMaterial.prototype, {
  19678. metal: {
  19679. get: function () {
  19680. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.' );
  19681. return false;
  19682. },
  19683. set: function ( value ) {
  19684. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead' );
  19685. }
  19686. }
  19687. } );
  19688. Object.defineProperties( THREE.ShaderMaterial.prototype, {
  19689. derivatives: {
  19690. get: function () {
  19691. console.warn( 'THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  19692. return this.extensions.derivatives;
  19693. },
  19694. set: function ( value ) {
  19695. console.warn( 'THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  19696. this.extensions.derivatives = value;
  19697. }
  19698. }
  19699. } );
  19700. //
  19701. Object.defineProperties( THREE.WebGLRenderer.prototype, {
  19702. supportsFloatTextures: {
  19703. value: function () {
  19704. console.warn( 'THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).' );
  19705. return this.extensions.get( 'OES_texture_float' );
  19706. }
  19707. },
  19708. supportsHalfFloatTextures: {
  19709. value: function () {
  19710. console.warn( 'THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).' );
  19711. return this.extensions.get( 'OES_texture_half_float' );
  19712. }
  19713. },
  19714. supportsStandardDerivatives: {
  19715. value: function () {
  19716. console.warn( 'THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).' );
  19717. return this.extensions.get( 'OES_standard_derivatives' );
  19718. }
  19719. },
  19720. supportsCompressedTextureS3TC: {
  19721. value: function () {
  19722. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).' );
  19723. return this.extensions.get( 'WEBGL_compressed_texture_s3tc' );
  19724. }
  19725. },
  19726. supportsCompressedTexturePVRTC: {
  19727. value: function () {
  19728. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).' );
  19729. return this.extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  19730. }
  19731. },
  19732. supportsBlendMinMax: {
  19733. value: function () {
  19734. console.warn( 'THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).' );
  19735. return this.extensions.get( 'EXT_blend_minmax' );
  19736. }
  19737. },
  19738. supportsVertexTextures: {
  19739. value: function () {
  19740. return this.capabilities.vertexTextures;
  19741. }
  19742. },
  19743. supportsInstancedArrays: {
  19744. value: function () {
  19745. console.warn( 'THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).' );
  19746. return this.extensions.get( 'ANGLE_instanced_arrays' );
  19747. }
  19748. },
  19749. enableScissorTest: {
  19750. value: function ( boolean ) {
  19751. console.warn( 'THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().' );
  19752. this.setScissorTest( boolean );
  19753. }
  19754. },
  19755. initMaterial: {
  19756. value: function () {
  19757. console.warn( 'THREE.WebGLRenderer: .initMaterial() has been removed.' );
  19758. }
  19759. },
  19760. addPrePlugin: {
  19761. value: function () {
  19762. console.warn( 'THREE.WebGLRenderer: .addPrePlugin() has been removed.' );
  19763. }
  19764. },
  19765. addPostPlugin: {
  19766. value: function () {
  19767. console.warn( 'THREE.WebGLRenderer: .addPostPlugin() has been removed.' );
  19768. }
  19769. },
  19770. updateShadowMap: {
  19771. value: function () {
  19772. console.warn( 'THREE.WebGLRenderer: .updateShadowMap() has been removed.' );
  19773. }
  19774. },
  19775. shadowMapEnabled: {
  19776. get: function () {
  19777. return this.shadowMap.enabled;
  19778. },
  19779. set: function ( value ) {
  19780. console.warn( 'THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.' );
  19781. this.shadowMap.enabled = value;
  19782. }
  19783. },
  19784. shadowMapType: {
  19785. get: function () {
  19786. return this.shadowMap.type;
  19787. },
  19788. set: function ( value ) {
  19789. console.warn( 'THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.' );
  19790. this.shadowMap.type = value;
  19791. }
  19792. },
  19793. shadowMapCullFace: {
  19794. get: function () {
  19795. return this.shadowMap.cullFace;
  19796. },
  19797. set: function ( value ) {
  19798. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace is now .shadowMap.cullFace.' );
  19799. this.shadowMap.cullFace = value;
  19800. }
  19801. }
  19802. } );
  19803. //
  19804. Object.defineProperties( THREE.WebGLRenderTarget.prototype, {
  19805. wrapS: {
  19806. get: function () {
  19807. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  19808. return this.texture.wrapS;
  19809. },
  19810. set: function ( value ) {
  19811. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  19812. this.texture.wrapS = value;
  19813. }
  19814. },
  19815. wrapT: {
  19816. get: function () {
  19817. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  19818. return this.texture.wrapT;
  19819. },
  19820. set: function ( value ) {
  19821. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  19822. this.texture.wrapT = value;
  19823. }
  19824. },
  19825. magFilter: {
  19826. get: function () {
  19827. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  19828. return this.texture.magFilter;
  19829. },
  19830. set: function ( value ) {
  19831. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  19832. this.texture.magFilter = value;
  19833. }
  19834. },
  19835. minFilter: {
  19836. get: function () {
  19837. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  19838. return this.texture.minFilter;
  19839. },
  19840. set: function ( value ) {
  19841. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  19842. this.texture.minFilter = value;
  19843. }
  19844. },
  19845. anisotropy: {
  19846. get: function () {
  19847. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  19848. return this.texture.anisotropy;
  19849. },
  19850. set: function ( value ) {
  19851. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  19852. this.texture.anisotropy = value;
  19853. }
  19854. },
  19855. offset: {
  19856. get: function () {
  19857. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  19858. return this.texture.offset;
  19859. },
  19860. set: function ( value ) {
  19861. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  19862. this.texture.offset = value;
  19863. }
  19864. },
  19865. repeat: {
  19866. get: function () {
  19867. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  19868. return this.texture.repeat;
  19869. },
  19870. set: function ( value ) {
  19871. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  19872. this.texture.repeat = value;
  19873. }
  19874. },
  19875. format: {
  19876. get: function () {
  19877. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  19878. return this.texture.format;
  19879. },
  19880. set: function ( value ) {
  19881. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  19882. this.texture.format = value;
  19883. }
  19884. },
  19885. type: {
  19886. get: function () {
  19887. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  19888. return this.texture.type;
  19889. },
  19890. set: function ( value ) {
  19891. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  19892. this.texture.type = value;
  19893. }
  19894. },
  19895. generateMipmaps: {
  19896. get: function () {
  19897. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  19898. return this.texture.generateMipmaps;
  19899. },
  19900. set: function ( value ) {
  19901. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  19902. this.texture.generateMipmaps = value;
  19903. }
  19904. }
  19905. } );
  19906. //
  19907. Object.defineProperties( THREE.Audio.prototype, {
  19908. load: {
  19909. value: function ( file ) {
  19910. console.warn( 'THREE.Audio: .load has been deprecated. Please use THREE.AudioLoader.' );
  19911. var scope = this;
  19912. var audioLoader = new THREE.AudioLoader();
  19913. audioLoader.load( file, function ( buffer ) {
  19914. scope.setBuffer( buffer );
  19915. } );
  19916. return this;
  19917. }
  19918. }
  19919. } );
  19920. //
  19921. THREE.GeometryUtils = {
  19922. merge: function ( geometry1, geometry2, materialIndexOffset ) {
  19923. console.warn( 'THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.' );
  19924. var matrix;
  19925. if ( geometry2 instanceof THREE.Mesh ) {
  19926. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  19927. matrix = geometry2.matrix;
  19928. geometry2 = geometry2.geometry;
  19929. }
  19930. geometry1.merge( geometry2, matrix, materialIndexOffset );
  19931. },
  19932. center: function ( geometry ) {
  19933. console.warn( 'THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.' );
  19934. return geometry.center();
  19935. }
  19936. };
  19937. THREE.ImageUtils = {
  19938. crossOrigin: undefined,
  19939. loadTexture: function ( url, mapping, onLoad, onError ) {
  19940. console.warn( 'THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.' );
  19941. var loader = new THREE.TextureLoader();
  19942. loader.setCrossOrigin( this.crossOrigin );
  19943. var texture = loader.load( url, onLoad, undefined, onError );
  19944. if ( mapping ) texture.mapping = mapping;
  19945. return texture;
  19946. },
  19947. loadTextureCube: function ( urls, mapping, onLoad, onError ) {
  19948. console.warn( 'THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.' );
  19949. var loader = new THREE.CubeTextureLoader();
  19950. loader.setCrossOrigin( this.crossOrigin );
  19951. var texture = loader.load( urls, onLoad, undefined, onError );
  19952. if ( mapping ) texture.mapping = mapping;
  19953. return texture;
  19954. },
  19955. loadCompressedTexture: function () {
  19956. console.error( 'THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.' );
  19957. },
  19958. loadCompressedTextureCube: function () {
  19959. console.error( 'THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.' );
  19960. }
  19961. };
  19962. //
  19963. THREE.Projector = function () {
  19964. console.error( 'THREE.Projector has been moved to /examples/js/renderers/Projector.js.' );
  19965. this.projectVector = function ( vector, camera ) {
  19966. console.warn( 'THREE.Projector: .projectVector() is now vector.project().' );
  19967. vector.project( camera );
  19968. };
  19969. this.unprojectVector = function ( vector, camera ) {
  19970. console.warn( 'THREE.Projector: .unprojectVector() is now vector.unproject().' );
  19971. vector.unproject( camera );
  19972. };
  19973. this.pickingRay = function ( vector, camera ) {
  19974. console.error( 'THREE.Projector: .pickingRay() is now raycaster.setFromCamera().' );
  19975. };
  19976. };
  19977. //
  19978. THREE.CanvasRenderer = function () {
  19979. console.error( 'THREE.CanvasRenderer has been moved to /examples/js/renderers/CanvasRenderer.js' );
  19980. this.domElement = document.createElement( 'canvas' );
  19981. this.clear = function () {};
  19982. this.render = function () {};
  19983. this.setClearColor = function () {};
  19984. this.setSize = function () {};
  19985. };
  19986. //
  19987. THREE.MeshFaceMaterial = THREE.MultiMaterial;
  19988. //
  19989. Object.defineProperties( THREE.LOD.prototype, {
  19990. objects: {
  19991. get: function () {
  19992. console.warn( 'THREE.LOD: .objects has been renamed to .levels.' );
  19993. return this.levels;
  19994. }
  19995. }
  19996. } );
  19997. // File:src/extras/CurveUtils.js
  19998. /**
  19999. * @author zz85 / http://www.lab4games.net/zz85/blog
  20000. */
  20001. THREE.CurveUtils = {
  20002. tangentQuadraticBezier: function ( t, p0, p1, p2 ) {
  20003. return 2 * ( 1 - t ) * ( p1 - p0 ) + 2 * t * ( p2 - p1 );
  20004. },
  20005. // Puay Bing, thanks for helping with this derivative!
  20006. tangentCubicBezier: function ( t, p0, p1, p2, p3 ) {
  20007. return - 3 * p0 * ( 1 - t ) * ( 1 - t ) +
  20008. 3 * p1 * ( 1 - t ) * ( 1 - t ) - 6 * t * p1 * ( 1 - t ) +
  20009. 6 * t * p2 * ( 1 - t ) - 3 * t * t * p2 +
  20010. 3 * t * t * p3;
  20011. },
  20012. tangentSpline: function ( t, p0, p1, p2, p3 ) {
  20013. // To check if my formulas are correct
  20014. var h00 = 6 * t * t - 6 * t; // derived from 2t^3 − 3t^2 + 1
  20015. var h10 = 3 * t * t - 4 * t + 1; // t^3 − 2t^2 + t
  20016. var h01 = - 6 * t * t + 6 * t; // − 2t3 + 3t2
  20017. var h11 = 3 * t * t - 2 * t; // t3 − t2
  20018. return h00 + h10 + h01 + h11;
  20019. },
  20020. // Catmull-Rom
  20021. interpolate: function( p0, p1, p2, p3, t ) {
  20022. var v0 = ( p2 - p0 ) * 0.5;
  20023. var v1 = ( p3 - p1 ) * 0.5;
  20024. var t2 = t * t;
  20025. var t3 = t * t2;
  20026. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  20027. }
  20028. };
  20029. // File:src/extras/SceneUtils.js
  20030. /**
  20031. * @author alteredq / http://alteredqualia.com/
  20032. */
  20033. THREE.SceneUtils = {
  20034. createMultiMaterialObject: function ( geometry, materials ) {
  20035. var group = new THREE.Group();
  20036. for ( var i = 0, l = materials.length; i < l; i ++ ) {
  20037. group.add( new THREE.Mesh( geometry, materials[ i ] ) );
  20038. }
  20039. return group;
  20040. },
  20041. detach: function ( child, parent, scene ) {
  20042. child.applyMatrix( parent.matrixWorld );
  20043. parent.remove( child );
  20044. scene.add( child );
  20045. },
  20046. attach: function ( child, scene, parent ) {
  20047. var matrixWorldInverse = new THREE.Matrix4();
  20048. matrixWorldInverse.getInverse( parent.matrixWorld );
  20049. child.applyMatrix( matrixWorldInverse );
  20050. scene.remove( child );
  20051. parent.add( child );
  20052. }
  20053. };
  20054. // File:src/extras/ShapeUtils.js
  20055. /**
  20056. * @author zz85 / http://www.lab4games.net/zz85/blog
  20057. */
  20058. THREE.ShapeUtils = {
  20059. // calculate area of the contour polygon
  20060. area: function ( contour ) {
  20061. var n = contour.length;
  20062. var a = 0.0;
  20063. for ( var p = n - 1, q = 0; q < n; p = q ++ ) {
  20064. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  20065. }
  20066. return a * 0.5;
  20067. },
  20068. triangulate: ( function () {
  20069. /**
  20070. * This code is a quick port of code written in C++ which was submitted to
  20071. * flipcode.com by John W. Ratcliff // July 22, 2000
  20072. * See original code and more information here:
  20073. * http://www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml
  20074. *
  20075. * ported to actionscript by Zevan Rosser
  20076. * www.actionsnippet.com
  20077. *
  20078. * ported to javascript by Joshua Koo
  20079. * http://www.lab4games.net/zz85/blog
  20080. *
  20081. */
  20082. function snip( contour, u, v, w, n, verts ) {
  20083. var p;
  20084. var ax, ay, bx, by;
  20085. var cx, cy, px, py;
  20086. ax = contour[ verts[ u ] ].x;
  20087. ay = contour[ verts[ u ] ].y;
  20088. bx = contour[ verts[ v ] ].x;
  20089. by = contour[ verts[ v ] ].y;
  20090. cx = contour[ verts[ w ] ].x;
  20091. cy = contour[ verts[ w ] ].y;
  20092. if ( Number.EPSILON > ( ( ( bx - ax ) * ( cy - ay ) ) - ( ( by - ay ) * ( cx - ax ) ) ) ) return false;
  20093. var aX, aY, bX, bY, cX, cY;
  20094. var apx, apy, bpx, bpy, cpx, cpy;
  20095. var cCROSSap, bCROSScp, aCROSSbp;
  20096. aX = cx - bx; aY = cy - by;
  20097. bX = ax - cx; bY = ay - cy;
  20098. cX = bx - ax; cY = by - ay;
  20099. for ( p = 0; p < n; p ++ ) {
  20100. px = contour[ verts[ p ] ].x;
  20101. py = contour[ verts[ p ] ].y;
  20102. if ( ( ( px === ax ) && ( py === ay ) ) ||
  20103. ( ( px === bx ) && ( py === by ) ) ||
  20104. ( ( px === cx ) && ( py === cy ) ) ) continue;
  20105. apx = px - ax; apy = py - ay;
  20106. bpx = px - bx; bpy = py - by;
  20107. cpx = px - cx; cpy = py - cy;
  20108. // see if p is inside triangle abc
  20109. aCROSSbp = aX * bpy - aY * bpx;
  20110. cCROSSap = cX * apy - cY * apx;
  20111. bCROSScp = bX * cpy - bY * cpx;
  20112. if ( ( aCROSSbp >= - Number.EPSILON ) && ( bCROSScp >= - Number.EPSILON ) && ( cCROSSap >= - Number.EPSILON ) ) return false;
  20113. }
  20114. return true;
  20115. }
  20116. // takes in an contour array and returns
  20117. return function ( contour, indices ) {
  20118. var n = contour.length;
  20119. if ( n < 3 ) return null;
  20120. var result = [],
  20121. verts = [],
  20122. vertIndices = [];
  20123. /* we want a counter-clockwise polygon in verts */
  20124. var u, v, w;
  20125. if ( THREE.ShapeUtils.area( contour ) > 0.0 ) {
  20126. for ( v = 0; v < n; v ++ ) verts[ v ] = v;
  20127. } else {
  20128. for ( v = 0; v < n; v ++ ) verts[ v ] = ( n - 1 ) - v;
  20129. }
  20130. var nv = n;
  20131. /* remove nv - 2 vertices, creating 1 triangle every time */
  20132. var count = 2 * nv; /* error detection */
  20133. for ( v = nv - 1; nv > 2; ) {
  20134. /* if we loop, it is probably a non-simple polygon */
  20135. if ( ( count -- ) <= 0 ) {
  20136. //** Triangulate: ERROR - probable bad polygon!
  20137. //throw ( "Warning, unable to triangulate polygon!" );
  20138. //return null;
  20139. // Sometimes warning is fine, especially polygons are triangulated in reverse.
  20140. console.warn( 'THREE.ShapeUtils: Unable to triangulate polygon! in triangulate()' );
  20141. if ( indices ) return vertIndices;
  20142. return result;
  20143. }
  20144. /* three consecutive vertices in current polygon, <u,v,w> */
  20145. u = v; if ( nv <= u ) u = 0; /* previous */
  20146. v = u + 1; if ( nv <= v ) v = 0; /* new v */
  20147. w = v + 1; if ( nv <= w ) w = 0; /* next */
  20148. if ( snip( contour, u, v, w, nv, verts ) ) {
  20149. var a, b, c, s, t;
  20150. /* true names of the vertices */
  20151. a = verts[ u ];
  20152. b = verts[ v ];
  20153. c = verts[ w ];
  20154. /* output Triangle */
  20155. result.push( [ contour[ a ],
  20156. contour[ b ],
  20157. contour[ c ] ] );
  20158. vertIndices.push( [ verts[ u ], verts[ v ], verts[ w ] ] );
  20159. /* remove v from the remaining polygon */
  20160. for ( s = v, t = v + 1; t < nv; s ++, t ++ ) {
  20161. verts[ s ] = verts[ t ];
  20162. }
  20163. nv --;
  20164. /* reset error detection counter */
  20165. count = 2 * nv;
  20166. }
  20167. }
  20168. if ( indices ) return vertIndices;
  20169. return result;
  20170. }
  20171. } )(),
  20172. triangulateShape: function ( contour, holes ) {
  20173. function point_in_segment_2D_colin( inSegPt1, inSegPt2, inOtherPt ) {
  20174. // inOtherPt needs to be collinear to the inSegment
  20175. if ( inSegPt1.x !== inSegPt2.x ) {
  20176. if ( inSegPt1.x < inSegPt2.x ) {
  20177. return ( ( inSegPt1.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt2.x ) );
  20178. } else {
  20179. return ( ( inSegPt2.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt1.x ) );
  20180. }
  20181. } else {
  20182. if ( inSegPt1.y < inSegPt2.y ) {
  20183. return ( ( inSegPt1.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt2.y ) );
  20184. } else {
  20185. return ( ( inSegPt2.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt1.y ) );
  20186. }
  20187. }
  20188. }
  20189. function intersect_segments_2D( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1, inSeg2Pt2, inExcludeAdjacentSegs ) {
  20190. var seg1dx = inSeg1Pt2.x - inSeg1Pt1.x, seg1dy = inSeg1Pt2.y - inSeg1Pt1.y;
  20191. var seg2dx = inSeg2Pt2.x - inSeg2Pt1.x, seg2dy = inSeg2Pt2.y - inSeg2Pt1.y;
  20192. var seg1seg2dx = inSeg1Pt1.x - inSeg2Pt1.x;
  20193. var seg1seg2dy = inSeg1Pt1.y - inSeg2Pt1.y;
  20194. var limit = seg1dy * seg2dx - seg1dx * seg2dy;
  20195. var perpSeg1 = seg1dy * seg1seg2dx - seg1dx * seg1seg2dy;
  20196. if ( Math.abs( limit ) > Number.EPSILON ) {
  20197. // not parallel
  20198. var perpSeg2;
  20199. if ( limit > 0 ) {
  20200. if ( ( perpSeg1 < 0 ) || ( perpSeg1 > limit ) ) return [];
  20201. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  20202. if ( ( perpSeg2 < 0 ) || ( perpSeg2 > limit ) ) return [];
  20203. } else {
  20204. if ( ( perpSeg1 > 0 ) || ( perpSeg1 < limit ) ) return [];
  20205. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  20206. if ( ( perpSeg2 > 0 ) || ( perpSeg2 < limit ) ) return [];
  20207. }
  20208. // i.e. to reduce rounding errors
  20209. // intersection at endpoint of segment#1?
  20210. if ( perpSeg2 === 0 ) {
  20211. if ( ( inExcludeAdjacentSegs ) &&
  20212. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  20213. return [ inSeg1Pt1 ];
  20214. }
  20215. if ( perpSeg2 === limit ) {
  20216. if ( ( inExcludeAdjacentSegs ) &&
  20217. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  20218. return [ inSeg1Pt2 ];
  20219. }
  20220. // intersection at endpoint of segment#2?
  20221. if ( perpSeg1 === 0 ) return [ inSeg2Pt1 ];
  20222. if ( perpSeg1 === limit ) return [ inSeg2Pt2 ];
  20223. // return real intersection point
  20224. var factorSeg1 = perpSeg2 / limit;
  20225. return [ { x: inSeg1Pt1.x + factorSeg1 * seg1dx,
  20226. y: inSeg1Pt1.y + factorSeg1 * seg1dy } ];
  20227. } else {
  20228. // parallel or collinear
  20229. if ( ( perpSeg1 !== 0 ) ||
  20230. ( seg2dy * seg1seg2dx !== seg2dx * seg1seg2dy ) ) return [];
  20231. // they are collinear or degenerate
  20232. var seg1Pt = ( ( seg1dx === 0 ) && ( seg1dy === 0 ) ); // segment1 is just a point?
  20233. var seg2Pt = ( ( seg2dx === 0 ) && ( seg2dy === 0 ) ); // segment2 is just a point?
  20234. // both segments are points
  20235. if ( seg1Pt && seg2Pt ) {
  20236. if ( ( inSeg1Pt1.x !== inSeg2Pt1.x ) ||
  20237. ( inSeg1Pt1.y !== inSeg2Pt1.y ) ) return []; // they are distinct points
  20238. return [ inSeg1Pt1 ]; // they are the same point
  20239. }
  20240. // segment#1 is a single point
  20241. if ( seg1Pt ) {
  20242. if ( ! point_in_segment_2D_colin( inSeg2Pt1, inSeg2Pt2, inSeg1Pt1 ) ) return []; // but not in segment#2
  20243. return [ inSeg1Pt1 ];
  20244. }
  20245. // segment#2 is a single point
  20246. if ( seg2Pt ) {
  20247. if ( ! point_in_segment_2D_colin( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1 ) ) return []; // but not in segment#1
  20248. return [ inSeg2Pt1 ];
  20249. }
  20250. // they are collinear segments, which might overlap
  20251. var seg1min, seg1max, seg1minVal, seg1maxVal;
  20252. var seg2min, seg2max, seg2minVal, seg2maxVal;
  20253. if ( seg1dx !== 0 ) {
  20254. // the segments are NOT on a vertical line
  20255. if ( inSeg1Pt1.x < inSeg1Pt2.x ) {
  20256. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.x;
  20257. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.x;
  20258. } else {
  20259. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.x;
  20260. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.x;
  20261. }
  20262. if ( inSeg2Pt1.x < inSeg2Pt2.x ) {
  20263. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.x;
  20264. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.x;
  20265. } else {
  20266. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.x;
  20267. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.x;
  20268. }
  20269. } else {
  20270. // the segments are on a vertical line
  20271. if ( inSeg1Pt1.y < inSeg1Pt2.y ) {
  20272. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.y;
  20273. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.y;
  20274. } else {
  20275. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.y;
  20276. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.y;
  20277. }
  20278. if ( inSeg2Pt1.y < inSeg2Pt2.y ) {
  20279. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.y;
  20280. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.y;
  20281. } else {
  20282. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.y;
  20283. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.y;
  20284. }
  20285. }
  20286. if ( seg1minVal <= seg2minVal ) {
  20287. if ( seg1maxVal < seg2minVal ) return [];
  20288. if ( seg1maxVal === seg2minVal ) {
  20289. if ( inExcludeAdjacentSegs ) return [];
  20290. return [ seg2min ];
  20291. }
  20292. if ( seg1maxVal <= seg2maxVal ) return [ seg2min, seg1max ];
  20293. return [ seg2min, seg2max ];
  20294. } else {
  20295. if ( seg1minVal > seg2maxVal ) return [];
  20296. if ( seg1minVal === seg2maxVal ) {
  20297. if ( inExcludeAdjacentSegs ) return [];
  20298. return [ seg1min ];
  20299. }
  20300. if ( seg1maxVal <= seg2maxVal ) return [ seg1min, seg1max ];
  20301. return [ seg1min, seg2max ];
  20302. }
  20303. }
  20304. }
  20305. function isPointInsideAngle( inVertex, inLegFromPt, inLegToPt, inOtherPt ) {
  20306. // The order of legs is important
  20307. // translation of all points, so that Vertex is at (0,0)
  20308. var legFromPtX = inLegFromPt.x - inVertex.x, legFromPtY = inLegFromPt.y - inVertex.y;
  20309. var legToPtX = inLegToPt.x - inVertex.x, legToPtY = inLegToPt.y - inVertex.y;
  20310. var otherPtX = inOtherPt.x - inVertex.x, otherPtY = inOtherPt.y - inVertex.y;
  20311. // main angle >0: < 180 deg.; 0: 180 deg.; <0: > 180 deg.
  20312. var from2toAngle = legFromPtX * legToPtY - legFromPtY * legToPtX;
  20313. var from2otherAngle = legFromPtX * otherPtY - legFromPtY * otherPtX;
  20314. if ( Math.abs( from2toAngle ) > Number.EPSILON ) {
  20315. // angle != 180 deg.
  20316. var other2toAngle = otherPtX * legToPtY - otherPtY * legToPtX;
  20317. // console.log( "from2to: " + from2toAngle + ", from2other: " + from2otherAngle + ", other2to: " + other2toAngle );
  20318. if ( from2toAngle > 0 ) {
  20319. // main angle < 180 deg.
  20320. return ( ( from2otherAngle >= 0 ) && ( other2toAngle >= 0 ) );
  20321. } else {
  20322. // main angle > 180 deg.
  20323. return ( ( from2otherAngle >= 0 ) || ( other2toAngle >= 0 ) );
  20324. }
  20325. } else {
  20326. // angle == 180 deg.
  20327. // console.log( "from2to: 180 deg., from2other: " + from2otherAngle );
  20328. return ( from2otherAngle > 0 );
  20329. }
  20330. }
  20331. function removeHoles( contour, holes ) {
  20332. var shape = contour.concat(); // work on this shape
  20333. var hole;
  20334. function isCutLineInsideAngles( inShapeIdx, inHoleIdx ) {
  20335. // Check if hole point lies within angle around shape point
  20336. var lastShapeIdx = shape.length - 1;
  20337. var prevShapeIdx = inShapeIdx - 1;
  20338. if ( prevShapeIdx < 0 ) prevShapeIdx = lastShapeIdx;
  20339. var nextShapeIdx = inShapeIdx + 1;
  20340. if ( nextShapeIdx > lastShapeIdx ) nextShapeIdx = 0;
  20341. var insideAngle = isPointInsideAngle( shape[ inShapeIdx ], shape[ prevShapeIdx ], shape[ nextShapeIdx ], hole[ inHoleIdx ] );
  20342. if ( ! insideAngle ) {
  20343. // console.log( "Vertex (Shape): " + inShapeIdx + ", Point: " + hole[inHoleIdx].x + "/" + hole[inHoleIdx].y );
  20344. return false;
  20345. }
  20346. // Check if shape point lies within angle around hole point
  20347. var lastHoleIdx = hole.length - 1;
  20348. var prevHoleIdx = inHoleIdx - 1;
  20349. if ( prevHoleIdx < 0 ) prevHoleIdx = lastHoleIdx;
  20350. var nextHoleIdx = inHoleIdx + 1;
  20351. if ( nextHoleIdx > lastHoleIdx ) nextHoleIdx = 0;
  20352. insideAngle = isPointInsideAngle( hole[ inHoleIdx ], hole[ prevHoleIdx ], hole[ nextHoleIdx ], shape[ inShapeIdx ] );
  20353. if ( ! insideAngle ) {
  20354. // console.log( "Vertex (Hole): " + inHoleIdx + ", Point: " + shape[inShapeIdx].x + "/" + shape[inShapeIdx].y );
  20355. return false;
  20356. }
  20357. return true;
  20358. }
  20359. function intersectsShapeEdge( inShapePt, inHolePt ) {
  20360. // checks for intersections with shape edges
  20361. var sIdx, nextIdx, intersection;
  20362. for ( sIdx = 0; sIdx < shape.length; sIdx ++ ) {
  20363. nextIdx = sIdx + 1; nextIdx %= shape.length;
  20364. intersection = intersect_segments_2D( inShapePt, inHolePt, shape[ sIdx ], shape[ nextIdx ], true );
  20365. if ( intersection.length > 0 ) return true;
  20366. }
  20367. return false;
  20368. }
  20369. var indepHoles = [];
  20370. function intersectsHoleEdge( inShapePt, inHolePt ) {
  20371. // checks for intersections with hole edges
  20372. var ihIdx, chkHole,
  20373. hIdx, nextIdx, intersection;
  20374. for ( ihIdx = 0; ihIdx < indepHoles.length; ihIdx ++ ) {
  20375. chkHole = holes[ indepHoles[ ihIdx ]];
  20376. for ( hIdx = 0; hIdx < chkHole.length; hIdx ++ ) {
  20377. nextIdx = hIdx + 1; nextIdx %= chkHole.length;
  20378. intersection = intersect_segments_2D( inShapePt, inHolePt, chkHole[ hIdx ], chkHole[ nextIdx ], true );
  20379. if ( intersection.length > 0 ) return true;
  20380. }
  20381. }
  20382. return false;
  20383. }
  20384. var holeIndex, shapeIndex,
  20385. shapePt, holePt,
  20386. holeIdx, cutKey, failedCuts = [],
  20387. tmpShape1, tmpShape2,
  20388. tmpHole1, tmpHole2;
  20389. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  20390. indepHoles.push( h );
  20391. }
  20392. var minShapeIndex = 0;
  20393. var counter = indepHoles.length * 2;
  20394. while ( indepHoles.length > 0 ) {
  20395. counter --;
  20396. if ( counter < 0 ) {
  20397. console.log( "Infinite Loop! Holes left:" + indepHoles.length + ", Probably Hole outside Shape!" );
  20398. break;
  20399. }
  20400. // search for shape-vertex and hole-vertex,
  20401. // which can be connected without intersections
  20402. for ( shapeIndex = minShapeIndex; shapeIndex < shape.length; shapeIndex ++ ) {
  20403. shapePt = shape[ shapeIndex ];
  20404. holeIndex = - 1;
  20405. // search for hole which can be reached without intersections
  20406. for ( var h = 0; h < indepHoles.length; h ++ ) {
  20407. holeIdx = indepHoles[ h ];
  20408. // prevent multiple checks
  20409. cutKey = shapePt.x + ":" + shapePt.y + ":" + holeIdx;
  20410. if ( failedCuts[ cutKey ] !== undefined ) continue;
  20411. hole = holes[ holeIdx ];
  20412. for ( var h2 = 0; h2 < hole.length; h2 ++ ) {
  20413. holePt = hole[ h2 ];
  20414. if ( ! isCutLineInsideAngles( shapeIndex, h2 ) ) continue;
  20415. if ( intersectsShapeEdge( shapePt, holePt ) ) continue;
  20416. if ( intersectsHoleEdge( shapePt, holePt ) ) continue;
  20417. holeIndex = h2;
  20418. indepHoles.splice( h, 1 );
  20419. tmpShape1 = shape.slice( 0, shapeIndex + 1 );
  20420. tmpShape2 = shape.slice( shapeIndex );
  20421. tmpHole1 = hole.slice( holeIndex );
  20422. tmpHole2 = hole.slice( 0, holeIndex + 1 );
  20423. shape = tmpShape1.concat( tmpHole1 ).concat( tmpHole2 ).concat( tmpShape2 );
  20424. minShapeIndex = shapeIndex;
  20425. // Debug only, to show the selected cuts
  20426. // glob_CutLines.push( [ shapePt, holePt ] );
  20427. break;
  20428. }
  20429. if ( holeIndex >= 0 ) break; // hole-vertex found
  20430. failedCuts[ cutKey ] = true; // remember failure
  20431. }
  20432. if ( holeIndex >= 0 ) break; // hole-vertex found
  20433. }
  20434. }
  20435. return shape; /* shape with no holes */
  20436. }
  20437. var i, il, f, face,
  20438. key, index,
  20439. allPointsMap = {};
  20440. // 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.
  20441. var allpoints = contour.concat();
  20442. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  20443. Array.prototype.push.apply( allpoints, holes[ h ] );
  20444. }
  20445. //console.log( "allpoints",allpoints, allpoints.length );
  20446. // prepare all points map
  20447. for ( i = 0, il = allpoints.length; i < il; i ++ ) {
  20448. key = allpoints[ i ].x + ":" + allpoints[ i ].y;
  20449. if ( allPointsMap[ key ] !== undefined ) {
  20450. console.warn( "THREE.Shape: Duplicate point", key );
  20451. }
  20452. allPointsMap[ key ] = i;
  20453. }
  20454. // remove holes by cutting paths to holes and adding them to the shape
  20455. var shapeWithoutHoles = removeHoles( contour, holes );
  20456. var triangles = THREE.ShapeUtils.triangulate( shapeWithoutHoles, false ); // True returns indices for points of spooled shape
  20457. //console.log( "triangles",triangles, triangles.length );
  20458. // check all face vertices against all points map
  20459. for ( i = 0, il = triangles.length; i < il; i ++ ) {
  20460. face = triangles[ i ];
  20461. for ( f = 0; f < 3; f ++ ) {
  20462. key = face[ f ].x + ":" + face[ f ].y;
  20463. index = allPointsMap[ key ];
  20464. if ( index !== undefined ) {
  20465. face[ f ] = index;
  20466. }
  20467. }
  20468. }
  20469. return triangles.concat();
  20470. },
  20471. isClockWise: function ( pts ) {
  20472. return THREE.ShapeUtils.area( pts ) < 0;
  20473. },
  20474. // Bezier Curves formulas obtained from
  20475. // http://en.wikipedia.org/wiki/B%C3%A9zier_curve
  20476. // Quad Bezier Functions
  20477. b2: ( function () {
  20478. function b2p0( t, p ) {
  20479. var k = 1 - t;
  20480. return k * k * p;
  20481. }
  20482. function b2p1( t, p ) {
  20483. return 2 * ( 1 - t ) * t * p;
  20484. }
  20485. function b2p2( t, p ) {
  20486. return t * t * p;
  20487. }
  20488. return function ( t, p0, p1, p2 ) {
  20489. return b2p0( t, p0 ) + b2p1( t, p1 ) + b2p2( t, p2 );
  20490. };
  20491. } )(),
  20492. // Cubic Bezier Functions
  20493. b3: ( function () {
  20494. function b3p0( t, p ) {
  20495. var k = 1 - t;
  20496. return k * k * k * p;
  20497. }
  20498. function b3p1( t, p ) {
  20499. var k = 1 - t;
  20500. return 3 * k * k * t * p;
  20501. }
  20502. function b3p2( t, p ) {
  20503. var k = 1 - t;
  20504. return 3 * k * t * t * p;
  20505. }
  20506. function b3p3( t, p ) {
  20507. return t * t * t * p;
  20508. }
  20509. return function ( t, p0, p1, p2, p3 ) {
  20510. return b3p0( t, p0 ) + b3p1( t, p1 ) + b3p2( t, p2 ) + b3p3( t, p3 );
  20511. };
  20512. } )()
  20513. };
  20514. // File:src/extras/core/Curve.js
  20515. /**
  20516. * @author zz85 / http://www.lab4games.net/zz85/blog
  20517. * Extensible curve object
  20518. *
  20519. * Some common of Curve methods
  20520. * .getPoint(t), getTangent(t)
  20521. * .getPointAt(u), getTagentAt(u)
  20522. * .getPoints(), .getSpacedPoints()
  20523. * .getLength()
  20524. * .updateArcLengths()
  20525. *
  20526. * This following classes subclasses THREE.Curve:
  20527. *
  20528. * -- 2d classes --
  20529. * THREE.LineCurve
  20530. * THREE.QuadraticBezierCurve
  20531. * THREE.CubicBezierCurve
  20532. * THREE.SplineCurve
  20533. * THREE.ArcCurve
  20534. * THREE.EllipseCurve
  20535. *
  20536. * -- 3d classes --
  20537. * THREE.LineCurve3
  20538. * THREE.QuadraticBezierCurve3
  20539. * THREE.CubicBezierCurve3
  20540. * THREE.SplineCurve3
  20541. *
  20542. * A series of curves can be represented as a THREE.CurvePath
  20543. *
  20544. **/
  20545. /**************************************************************
  20546. * Abstract Curve base class
  20547. **************************************************************/
  20548. THREE.Curve = function () {
  20549. };
  20550. THREE.Curve.prototype = {
  20551. constructor: THREE.Curve,
  20552. // Virtual base class method to overwrite and implement in subclasses
  20553. // - t [0 .. 1]
  20554. getPoint: function ( t ) {
  20555. console.warn( "THREE.Curve: Warning, getPoint() not implemented!" );
  20556. return null;
  20557. },
  20558. // Get point at relative position in curve according to arc length
  20559. // - u [0 .. 1]
  20560. getPointAt: function ( u ) {
  20561. var t = this.getUtoTmapping( u );
  20562. return this.getPoint( t );
  20563. },
  20564. // Get sequence of points using getPoint( t )
  20565. getPoints: function ( divisions ) {
  20566. if ( ! divisions ) divisions = 5;
  20567. var d, pts = [];
  20568. for ( d = 0; d <= divisions; d ++ ) {
  20569. pts.push( this.getPoint( d / divisions ) );
  20570. }
  20571. return pts;
  20572. },
  20573. // Get sequence of points using getPointAt( u )
  20574. getSpacedPoints: function ( divisions ) {
  20575. if ( ! divisions ) divisions = 5;
  20576. var d, pts = [];
  20577. for ( d = 0; d <= divisions; d ++ ) {
  20578. pts.push( this.getPointAt( d / divisions ) );
  20579. }
  20580. return pts;
  20581. },
  20582. // Get total curve arc length
  20583. getLength: function () {
  20584. var lengths = this.getLengths();
  20585. return lengths[ lengths.length - 1 ];
  20586. },
  20587. // Get list of cumulative segment lengths
  20588. getLengths: function ( divisions ) {
  20589. if ( ! divisions ) divisions = ( this.__arcLengthDivisions ) ? ( this.__arcLengthDivisions ) : 200;
  20590. if ( this.cacheArcLengths
  20591. && ( this.cacheArcLengths.length === divisions + 1 )
  20592. && ! this.needsUpdate ) {
  20593. //console.log( "cached", this.cacheArcLengths );
  20594. return this.cacheArcLengths;
  20595. }
  20596. this.needsUpdate = false;
  20597. var cache = [];
  20598. var current, last = this.getPoint( 0 );
  20599. var p, sum = 0;
  20600. cache.push( 0 );
  20601. for ( p = 1; p <= divisions; p ++ ) {
  20602. current = this.getPoint ( p / divisions );
  20603. sum += current.distanceTo( last );
  20604. cache.push( sum );
  20605. last = current;
  20606. }
  20607. this.cacheArcLengths = cache;
  20608. return cache; // { sums: cache, sum:sum }; Sum is in the last element.
  20609. },
  20610. updateArcLengths: function() {
  20611. this.needsUpdate = true;
  20612. this.getLengths();
  20613. },
  20614. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  20615. getUtoTmapping: function ( u, distance ) {
  20616. var arcLengths = this.getLengths();
  20617. var i = 0, il = arcLengths.length;
  20618. var targetArcLength; // The targeted u distance value to get
  20619. if ( distance ) {
  20620. targetArcLength = distance;
  20621. } else {
  20622. targetArcLength = u * arcLengths[ il - 1 ];
  20623. }
  20624. //var time = Date.now();
  20625. // binary search for the index with largest value smaller than target u distance
  20626. var low = 0, high = il - 1, comparison;
  20627. while ( low <= high ) {
  20628. 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
  20629. comparison = arcLengths[ i ] - targetArcLength;
  20630. if ( comparison < 0 ) {
  20631. low = i + 1;
  20632. } else if ( comparison > 0 ) {
  20633. high = i - 1;
  20634. } else {
  20635. high = i;
  20636. break;
  20637. // DONE
  20638. }
  20639. }
  20640. i = high;
  20641. //console.log('b' , i, low, high, Date.now()- time);
  20642. if ( arcLengths[ i ] === targetArcLength ) {
  20643. var t = i / ( il - 1 );
  20644. return t;
  20645. }
  20646. // we could get finer grain at lengths, or use simple interpolation between two points
  20647. var lengthBefore = arcLengths[ i ];
  20648. var lengthAfter = arcLengths[ i + 1 ];
  20649. var segmentLength = lengthAfter - lengthBefore;
  20650. // determine where we are between the 'before' and 'after' points
  20651. var segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  20652. // add that fractional amount to t
  20653. var t = ( i + segmentFraction ) / ( il - 1 );
  20654. return t;
  20655. },
  20656. // Returns a unit vector tangent at t
  20657. // In case any sub curve does not implement its tangent derivation,
  20658. // 2 points a small delta apart will be used to find its gradient
  20659. // which seems to give a reasonable approximation
  20660. getTangent: function( t ) {
  20661. var delta = 0.0001;
  20662. var t1 = t - delta;
  20663. var t2 = t + delta;
  20664. // Capping in case of danger
  20665. if ( t1 < 0 ) t1 = 0;
  20666. if ( t2 > 1 ) t2 = 1;
  20667. var pt1 = this.getPoint( t1 );
  20668. var pt2 = this.getPoint( t2 );
  20669. var vec = pt2.clone().sub( pt1 );
  20670. return vec.normalize();
  20671. },
  20672. getTangentAt: function ( u ) {
  20673. var t = this.getUtoTmapping( u );
  20674. return this.getTangent( t );
  20675. }
  20676. };
  20677. // TODO: Transformation for Curves?
  20678. /**************************************************************
  20679. * 3D Curves
  20680. **************************************************************/
  20681. // A Factory method for creating new curve subclasses
  20682. THREE.Curve.create = function ( constructor, getPointFunc ) {
  20683. constructor.prototype = Object.create( THREE.Curve.prototype );
  20684. constructor.prototype.constructor = constructor;
  20685. constructor.prototype.getPoint = getPointFunc;
  20686. return constructor;
  20687. };
  20688. // File:src/extras/core/CurvePath.js
  20689. /**
  20690. * @author zz85 / http://www.lab4games.net/zz85/blog
  20691. *
  20692. **/
  20693. /**************************************************************
  20694. * Curved Path - a curve path is simply a array of connected
  20695. * curves, but retains the api of a curve
  20696. **************************************************************/
  20697. THREE.CurvePath = function () {
  20698. this.curves = [];
  20699. this.autoClose = false; // Automatically closes the path
  20700. };
  20701. THREE.CurvePath.prototype = Object.create( THREE.Curve.prototype );
  20702. THREE.CurvePath.prototype.constructor = THREE.CurvePath;
  20703. THREE.CurvePath.prototype.add = function ( curve ) {
  20704. this.curves.push( curve );
  20705. };
  20706. /*
  20707. THREE.CurvePath.prototype.checkConnection = function() {
  20708. // TODO
  20709. // If the ending of curve is not connected to the starting
  20710. // or the next curve, then, this is not a real path
  20711. };
  20712. */
  20713. THREE.CurvePath.prototype.closePath = function() {
  20714. // TODO Test
  20715. // and verify for vector3 (needs to implement equals)
  20716. // Add a line curve if start and end of lines are not connected
  20717. var startPoint = this.curves[ 0 ].getPoint( 0 );
  20718. var endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
  20719. if ( ! startPoint.equals( endPoint ) ) {
  20720. this.curves.push( new THREE.LineCurve( endPoint, startPoint ) );
  20721. }
  20722. };
  20723. // To get accurate point with reference to
  20724. // entire path distance at time t,
  20725. // following has to be done:
  20726. // 1. Length of each sub path have to be known
  20727. // 2. Locate and identify type of curve
  20728. // 3. Get t for the curve
  20729. // 4. Return curve.getPointAt(t')
  20730. THREE.CurvePath.prototype.getPoint = function( t ) {
  20731. var d = t * this.getLength();
  20732. var curveLengths = this.getCurveLengths();
  20733. var i = 0;
  20734. // To think about boundaries points.
  20735. while ( i < curveLengths.length ) {
  20736. if ( curveLengths[ i ] >= d ) {
  20737. var diff = curveLengths[ i ] - d;
  20738. var curve = this.curves[ i ];
  20739. var u = 1 - diff / curve.getLength();
  20740. return curve.getPointAt( u );
  20741. }
  20742. i ++;
  20743. }
  20744. return null;
  20745. // loop where sum != 0, sum > d , sum+1 <d
  20746. };
  20747. /*
  20748. THREE.CurvePath.prototype.getTangent = function( t ) {
  20749. };
  20750. */
  20751. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  20752. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  20753. // getPoint() depends on getLength
  20754. THREE.CurvePath.prototype.getLength = function() {
  20755. var lens = this.getCurveLengths();
  20756. return lens[ lens.length - 1 ];
  20757. };
  20758. // Compute lengths and cache them
  20759. // We cannot overwrite getLengths() because UtoT mapping uses it.
  20760. THREE.CurvePath.prototype.getCurveLengths = function() {
  20761. // We use cache values if curves and cache array are same length
  20762. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  20763. return this.cacheLengths;
  20764. }
  20765. // Get length of sub-curve
  20766. // Push sums into cached array
  20767. var lengths = [], sums = 0;
  20768. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  20769. sums += this.curves[ i ].getLength();
  20770. lengths.push( sums );
  20771. }
  20772. this.cacheLengths = lengths;
  20773. return lengths;
  20774. };
  20775. /**************************************************************
  20776. * Create Geometries Helpers
  20777. **************************************************************/
  20778. /// Generate geometry from path points (for Line or Points objects)
  20779. THREE.CurvePath.prototype.createPointsGeometry = function( divisions ) {
  20780. var pts = this.getPoints( divisions );
  20781. return this.createGeometry( pts );
  20782. };
  20783. // Generate geometry from equidistant sampling along the path
  20784. THREE.CurvePath.prototype.createSpacedPointsGeometry = function( divisions ) {
  20785. var pts = this.getSpacedPoints( divisions );
  20786. return this.createGeometry( pts );
  20787. };
  20788. THREE.CurvePath.prototype.createGeometry = function( points ) {
  20789. var geometry = new THREE.Geometry();
  20790. for ( var i = 0, l = points.length; i < l; i ++ ) {
  20791. var point = points[ i ];
  20792. geometry.vertices.push( new THREE.Vector3( point.x, point.y, point.z || 0 ) );
  20793. }
  20794. return geometry;
  20795. };
  20796. // File:src/extras/core/Font.js
  20797. /**
  20798. * @author zz85 / http://www.lab4games.net/zz85/blog
  20799. * @author mrdoob / http://mrdoob.com/
  20800. */
  20801. THREE.Font = function ( data ) {
  20802. this.data = data;
  20803. };
  20804. THREE.Font.prototype = {
  20805. constructor: THREE.Font,
  20806. generateShapes: function ( text, size, divisions ) {
  20807. function createPaths( text ) {
  20808. var chars = String( text ).split( '' );
  20809. var scale = size / data.resolution;
  20810. var offset = 0;
  20811. var paths = [];
  20812. for ( var i = 0; i < chars.length; i ++ ) {
  20813. var ret = createPath( chars[ i ], scale, offset );
  20814. offset += ret.offset;
  20815. paths.push( ret.path );
  20816. }
  20817. return paths;
  20818. }
  20819. function createPath( c, scale, offset ) {
  20820. var glyph = data.glyphs[ c ] || data.glyphs[ '?' ];
  20821. if ( ! glyph ) return;
  20822. var path = new THREE.Path();
  20823. var pts = [], b2 = THREE.ShapeUtils.b2, b3 = THREE.ShapeUtils.b3;
  20824. var x, y, cpx, cpy, cpx0, cpy0, cpx1, cpy1, cpx2, cpy2, laste;
  20825. if ( glyph.o ) {
  20826. var outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) );
  20827. for ( var i = 0, l = outline.length; i < l; ) {
  20828. var action = outline[ i ++ ];
  20829. switch ( action ) {
  20830. case 'm': // moveTo
  20831. x = outline[ i ++ ] * scale + offset;
  20832. y = outline[ i ++ ] * scale;
  20833. path.moveTo( x, y );
  20834. break;
  20835. case 'l': // lineTo
  20836. x = outline[ i ++ ] * scale + offset;
  20837. y = outline[ i ++ ] * scale;
  20838. path.lineTo( x, y );
  20839. break;
  20840. case 'q': // quadraticCurveTo
  20841. cpx = outline[ i ++ ] * scale + offset;
  20842. cpy = outline[ i ++ ] * scale;
  20843. cpx1 = outline[ i ++ ] * scale + offset;
  20844. cpy1 = outline[ i ++ ] * scale;
  20845. path.quadraticCurveTo( cpx1, cpy1, cpx, cpy );
  20846. laste = pts[ pts.length - 1 ];
  20847. if ( laste ) {
  20848. cpx0 = laste.x;
  20849. cpy0 = laste.y;
  20850. for ( var i2 = 1; i2 <= divisions; i2 ++ ) {
  20851. var t = i2 / divisions;
  20852. b2( t, cpx0, cpx1, cpx );
  20853. b2( t, cpy0, cpy1, cpy );
  20854. }
  20855. }
  20856. break;
  20857. case 'b': // bezierCurveTo
  20858. cpx = outline[ i ++ ] * scale + offset;
  20859. cpy = outline[ i ++ ] * scale;
  20860. cpx1 = outline[ i ++ ] * scale + offset;
  20861. cpy1 = outline[ i ++ ] * scale;
  20862. cpx2 = outline[ i ++ ] * scale + offset;
  20863. cpy2 = outline[ i ++ ] * scale;
  20864. path.bezierCurveTo( cpx1, cpy1, cpx2, cpy2, cpx, cpy );
  20865. laste = pts[ pts.length - 1 ];
  20866. if ( laste ) {
  20867. cpx0 = laste.x;
  20868. cpy0 = laste.y;
  20869. for ( var i2 = 1; i2 <= divisions; i2 ++ ) {
  20870. var t = i2 / divisions;
  20871. b3( t, cpx0, cpx1, cpx2, cpx );
  20872. b3( t, cpy0, cpy1, cpy2, cpy );
  20873. }
  20874. }
  20875. break;
  20876. }
  20877. }
  20878. }
  20879. return { offset: glyph.ha * scale, path: path };
  20880. }
  20881. //
  20882. if ( size === undefined ) size = 100;
  20883. if ( divisions === undefined ) divisions = 4;
  20884. var data = this.data;
  20885. var paths = createPaths( text );
  20886. var shapes = [];
  20887. for ( var p = 0, pl = paths.length; p < pl; p ++ ) {
  20888. Array.prototype.push.apply( shapes, paths[ p ].toShapes() );
  20889. }
  20890. return shapes;
  20891. }
  20892. };
  20893. // File:src/extras/core/Path.js
  20894. /**
  20895. * @author zz85 / http://www.lab4games.net/zz85/blog
  20896. * Creates free form 2d path using series of points, lines or curves.
  20897. *
  20898. **/
  20899. THREE.Path = function ( points ) {
  20900. THREE.CurvePath.call( this );
  20901. this.actions = [];
  20902. if ( points ) {
  20903. this.fromPoints( points );
  20904. }
  20905. };
  20906. THREE.Path.prototype = Object.create( THREE.CurvePath.prototype );
  20907. THREE.Path.prototype.constructor = THREE.Path;
  20908. // TODO Clean up PATH API
  20909. // Create path using straight lines to connect all points
  20910. // - vectors: array of Vector2
  20911. THREE.Path.prototype.fromPoints = function ( vectors ) {
  20912. this.moveTo( vectors[ 0 ].x, vectors[ 0 ].y );
  20913. for ( var i = 1, l = vectors.length; i < l; i ++ ) {
  20914. this.lineTo( vectors[ i ].x, vectors[ i ].y );
  20915. }
  20916. };
  20917. // startPath() endPath()?
  20918. THREE.Path.prototype.moveTo = function ( x, y ) {
  20919. this.actions.push( { action: 'moveTo', args: [ x, y ] } );
  20920. };
  20921. THREE.Path.prototype.lineTo = function ( x, y ) {
  20922. var lastargs = this.actions[ this.actions.length - 1 ].args;
  20923. var x0 = lastargs[ lastargs.length - 2 ];
  20924. var y0 = lastargs[ lastargs.length - 1 ];
  20925. var curve = new THREE.LineCurve( new THREE.Vector2( x0, y0 ), new THREE.Vector2( x, y ) );
  20926. this.curves.push( curve );
  20927. this.actions.push( { action: 'lineTo', args: [ x, y ] } );
  20928. };
  20929. THREE.Path.prototype.quadraticCurveTo = function( aCPx, aCPy, aX, aY ) {
  20930. var lastargs = this.actions[ this.actions.length - 1 ].args;
  20931. var x0 = lastargs[ lastargs.length - 2 ];
  20932. var y0 = lastargs[ lastargs.length - 1 ];
  20933. var curve = new THREE.QuadraticBezierCurve(
  20934. new THREE.Vector2( x0, y0 ),
  20935. new THREE.Vector2( aCPx, aCPy ),
  20936. new THREE.Vector2( aX, aY )
  20937. );
  20938. this.curves.push( curve );
  20939. this.actions.push( { action: 'quadraticCurveTo', args: [ aCPx, aCPy, aX, aY ] } );
  20940. };
  20941. THREE.Path.prototype.bezierCurveTo = function( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  20942. var lastargs = this.actions[ this.actions.length - 1 ].args;
  20943. var x0 = lastargs[ lastargs.length - 2 ];
  20944. var y0 = lastargs[ lastargs.length - 1 ];
  20945. var curve = new THREE.CubicBezierCurve(
  20946. new THREE.Vector2( x0, y0 ),
  20947. new THREE.Vector2( aCP1x, aCP1y ),
  20948. new THREE.Vector2( aCP2x, aCP2y ),
  20949. new THREE.Vector2( aX, aY )
  20950. );
  20951. this.curves.push( curve );
  20952. this.actions.push( { action: 'bezierCurveTo', args: [ aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ] } );
  20953. };
  20954. THREE.Path.prototype.splineThru = function( pts /*Array of Vector*/ ) {
  20955. var args = Array.prototype.slice.call( arguments );
  20956. var lastargs = this.actions[ this.actions.length - 1 ].args;
  20957. var x0 = lastargs[ lastargs.length - 2 ];
  20958. var y0 = lastargs[ lastargs.length - 1 ];
  20959. var npts = [ new THREE.Vector2( x0, y0 ) ];
  20960. Array.prototype.push.apply( npts, pts );
  20961. var curve = new THREE.SplineCurve( npts );
  20962. this.curves.push( curve );
  20963. this.actions.push( { action: 'splineThru', args: args } );
  20964. };
  20965. // FUTURE: Change the API or follow canvas API?
  20966. THREE.Path.prototype.arc = function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  20967. var lastargs = this.actions[ this.actions.length - 1 ].args;
  20968. var x0 = lastargs[ lastargs.length - 2 ];
  20969. var y0 = lastargs[ lastargs.length - 1 ];
  20970. this.absarc( aX + x0, aY + y0, aRadius,
  20971. aStartAngle, aEndAngle, aClockwise );
  20972. };
  20973. THREE.Path.prototype.absarc = function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  20974. this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  20975. };
  20976. THREE.Path.prototype.ellipse = function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  20977. var lastargs = this.actions[ this.actions.length - 1 ].args;
  20978. var x0 = lastargs[ lastargs.length - 2 ];
  20979. var y0 = lastargs[ lastargs.length - 1 ];
  20980. this.absellipse( aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  20981. };
  20982. THREE.Path.prototype.absellipse = function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  20983. var args = [
  20984. aX, aY,
  20985. xRadius, yRadius,
  20986. aStartAngle, aEndAngle,
  20987. aClockwise,
  20988. aRotation || 0 // aRotation is optional.
  20989. ];
  20990. var curve = new THREE.EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  20991. this.curves.push( curve );
  20992. var lastPoint = curve.getPoint( 1 );
  20993. args.push( lastPoint.x );
  20994. args.push( lastPoint.y );
  20995. this.actions.push( { action: 'ellipse', args: args } );
  20996. };
  20997. THREE.Path.prototype.getSpacedPoints = function ( divisions ) {
  20998. if ( ! divisions ) divisions = 40;
  20999. var points = [];
  21000. for ( var i = 0; i < divisions; i ++ ) {
  21001. points.push( this.getPoint( i / divisions ) );
  21002. //if ( !this.getPoint( i / divisions ) ) throw "DIE";
  21003. }
  21004. if ( this.autoClose ) {
  21005. points.push( points[ 0 ] );
  21006. }
  21007. return points;
  21008. };
  21009. /* Return an array of vectors based on contour of the path */
  21010. THREE.Path.prototype.getPoints = function( divisions ) {
  21011. divisions = divisions || 12;
  21012. var b2 = THREE.ShapeUtils.b2;
  21013. var b3 = THREE.ShapeUtils.b3;
  21014. var points = [];
  21015. var cpx, cpy, cpx2, cpy2, cpx1, cpy1, cpx0, cpy0,
  21016. laste, tx, ty;
  21017. for ( var i = 0, l = this.actions.length; i < l; i ++ ) {
  21018. var item = this.actions[ i ];
  21019. var action = item.action;
  21020. var args = item.args;
  21021. switch ( action ) {
  21022. case 'moveTo':
  21023. points.push( new THREE.Vector2( args[ 0 ], args[ 1 ] ) );
  21024. break;
  21025. case 'lineTo':
  21026. points.push( new THREE.Vector2( args[ 0 ], args[ 1 ] ) );
  21027. break;
  21028. case 'quadraticCurveTo':
  21029. cpx = args[ 2 ];
  21030. cpy = args[ 3 ];
  21031. cpx1 = args[ 0 ];
  21032. cpy1 = args[ 1 ];
  21033. if ( points.length > 0 ) {
  21034. laste = points[ points.length - 1 ];
  21035. cpx0 = laste.x;
  21036. cpy0 = laste.y;
  21037. } else {
  21038. laste = this.actions[ i - 1 ].args;
  21039. cpx0 = laste[ laste.length - 2 ];
  21040. cpy0 = laste[ laste.length - 1 ];
  21041. }
  21042. for ( var j = 1; j <= divisions; j ++ ) {
  21043. var t = j / divisions;
  21044. tx = b2( t, cpx0, cpx1, cpx );
  21045. ty = b2( t, cpy0, cpy1, cpy );
  21046. points.push( new THREE.Vector2( tx, ty ) );
  21047. }
  21048. break;
  21049. case 'bezierCurveTo':
  21050. cpx = args[ 4 ];
  21051. cpy = args[ 5 ];
  21052. cpx1 = args[ 0 ];
  21053. cpy1 = args[ 1 ];
  21054. cpx2 = args[ 2 ];
  21055. cpy2 = args[ 3 ];
  21056. if ( points.length > 0 ) {
  21057. laste = points[ points.length - 1 ];
  21058. cpx0 = laste.x;
  21059. cpy0 = laste.y;
  21060. } else {
  21061. laste = this.actions[ i - 1 ].args;
  21062. cpx0 = laste[ laste.length - 2 ];
  21063. cpy0 = laste[ laste.length - 1 ];
  21064. }
  21065. for ( var j = 1; j <= divisions; j ++ ) {
  21066. var t = j / divisions;
  21067. tx = b3( t, cpx0, cpx1, cpx2, cpx );
  21068. ty = b3( t, cpy0, cpy1, cpy2, cpy );
  21069. points.push( new THREE.Vector2( tx, ty ) );
  21070. }
  21071. break;
  21072. case 'splineThru':
  21073. laste = this.actions[ i - 1 ].args;
  21074. var last = new THREE.Vector2( laste[ laste.length - 2 ], laste[ laste.length - 1 ] );
  21075. var spts = [ last ];
  21076. var n = divisions * args[ 0 ].length;
  21077. spts = spts.concat( args[ 0 ] );
  21078. var spline = new THREE.SplineCurve( spts );
  21079. for ( var j = 1; j <= n; j ++ ) {
  21080. points.push( spline.getPointAt( j / n ) );
  21081. }
  21082. break;
  21083. case 'arc':
  21084. var aX = args[ 0 ], aY = args[ 1 ],
  21085. aRadius = args[ 2 ],
  21086. aStartAngle = args[ 3 ], aEndAngle = args[ 4 ],
  21087. aClockwise = !! args[ 5 ];
  21088. var deltaAngle = aEndAngle - aStartAngle;
  21089. var angle;
  21090. var tdivisions = divisions * 2;
  21091. for ( var j = 1; j <= tdivisions; j ++ ) {
  21092. var t = j / tdivisions;
  21093. if ( ! aClockwise ) {
  21094. t = 1 - t;
  21095. }
  21096. angle = aStartAngle + t * deltaAngle;
  21097. tx = aX + aRadius * Math.cos( angle );
  21098. ty = aY + aRadius * Math.sin( angle );
  21099. //console.log('t', t, 'angle', angle, 'tx', tx, 'ty', ty);
  21100. points.push( new THREE.Vector2( tx, ty ) );
  21101. }
  21102. //console.log(points);
  21103. break;
  21104. case 'ellipse':
  21105. var aX = args[ 0 ], aY = args[ 1 ],
  21106. xRadius = args[ 2 ],
  21107. yRadius = args[ 3 ],
  21108. aStartAngle = args[ 4 ], aEndAngle = args[ 5 ],
  21109. aClockwise = !! args[ 6 ],
  21110. aRotation = args[ 7 ];
  21111. var deltaAngle = aEndAngle - aStartAngle;
  21112. var angle;
  21113. var tdivisions = divisions * 2;
  21114. var cos, sin;
  21115. if ( aRotation !== 0 ) {
  21116. cos = Math.cos( aRotation );
  21117. sin = Math.sin( aRotation );
  21118. }
  21119. for ( var j = 1; j <= tdivisions; j ++ ) {
  21120. var t = j / tdivisions;
  21121. if ( ! aClockwise ) {
  21122. t = 1 - t;
  21123. }
  21124. angle = aStartAngle + t * deltaAngle;
  21125. tx = aX + xRadius * Math.cos( angle );
  21126. ty = aY + yRadius * Math.sin( angle );
  21127. if ( aRotation !== 0 ) {
  21128. var x = tx, y = ty;
  21129. // Rotate the point about the center of the ellipse.
  21130. tx = ( x - aX ) * cos - ( y - aY ) * sin + aX;
  21131. ty = ( x - aX ) * sin + ( y - aY ) * cos + aY;
  21132. }
  21133. //console.log('t', t, 'angle', angle, 'tx', tx, 'ty', ty);
  21134. points.push( new THREE.Vector2( tx, ty ) );
  21135. }
  21136. //console.log(points);
  21137. break;
  21138. } // end switch
  21139. }
  21140. // Normalize to remove the closing point by default.
  21141. var lastPoint = points[ points.length - 1 ];
  21142. if ( Math.abs( lastPoint.x - points[ 0 ].x ) < Number.EPSILON &&
  21143. Math.abs( lastPoint.y - points[ 0 ].y ) < Number.EPSILON )
  21144. points.splice( points.length - 1, 1 );
  21145. if ( this.autoClose ) {
  21146. points.push( points[ 0 ] );
  21147. }
  21148. return points;
  21149. };
  21150. //
  21151. // Breaks path into shapes
  21152. //
  21153. // Assumptions (if parameter isCCW==true the opposite holds):
  21154. // - solid shapes are defined clockwise (CW)
  21155. // - holes are defined counterclockwise (CCW)
  21156. //
  21157. // If parameter noHoles==true:
  21158. // - all subPaths are regarded as solid shapes
  21159. // - definition order CW/CCW has no relevance
  21160. //
  21161. THREE.Path.prototype.toShapes = function( isCCW, noHoles ) {
  21162. function extractSubpaths( inActions ) {
  21163. var subPaths = [], lastPath = new THREE.Path();
  21164. for ( var i = 0, l = inActions.length; i < l; i ++ ) {
  21165. var item = inActions[ i ];
  21166. var args = item.args;
  21167. var action = item.action;
  21168. if ( action === 'moveTo' ) {
  21169. if ( lastPath.actions.length !== 0 ) {
  21170. subPaths.push( lastPath );
  21171. lastPath = new THREE.Path();
  21172. }
  21173. }
  21174. lastPath[ action ].apply( lastPath, args );
  21175. }
  21176. if ( lastPath.actions.length !== 0 ) {
  21177. subPaths.push( lastPath );
  21178. }
  21179. // console.log(subPaths);
  21180. return subPaths;
  21181. }
  21182. function toShapesNoHoles( inSubpaths ) {
  21183. var shapes = [];
  21184. for ( var i = 0, l = inSubpaths.length; i < l; i ++ ) {
  21185. var tmpPath = inSubpaths[ i ];
  21186. var tmpShape = new THREE.Shape();
  21187. tmpShape.actions = tmpPath.actions;
  21188. tmpShape.curves = tmpPath.curves;
  21189. shapes.push( tmpShape );
  21190. }
  21191. //console.log("shape", shapes);
  21192. return shapes;
  21193. }
  21194. function isPointInsidePolygon( inPt, inPolygon ) {
  21195. var polyLen = inPolygon.length;
  21196. // inPt on polygon contour => immediate success or
  21197. // toggling of inside/outside at every single! intersection point of an edge
  21198. // with the horizontal line through inPt, left of inPt
  21199. // not counting lowerY endpoints of edges and whole edges on that line
  21200. var inside = false;
  21201. for ( var p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  21202. var edgeLowPt = inPolygon[ p ];
  21203. var edgeHighPt = inPolygon[ q ];
  21204. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  21205. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  21206. if ( Math.abs( edgeDy ) > Number.EPSILON ) {
  21207. // not parallel
  21208. if ( edgeDy < 0 ) {
  21209. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  21210. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  21211. }
  21212. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  21213. if ( inPt.y === edgeLowPt.y ) {
  21214. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  21215. // continue; // no intersection or edgeLowPt => doesn't count !!!
  21216. } else {
  21217. var perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y );
  21218. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  21219. if ( perpEdge < 0 ) continue;
  21220. inside = ! inside; // true intersection left of inPt
  21221. }
  21222. } else {
  21223. // parallel or collinear
  21224. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  21225. // edge lies on the same horizontal line as inPt
  21226. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  21227. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  21228. // continue;
  21229. }
  21230. }
  21231. return inside;
  21232. }
  21233. var isClockWise = THREE.ShapeUtils.isClockWise;
  21234. var subPaths = extractSubpaths( this.actions );
  21235. if ( subPaths.length === 0 ) return [];
  21236. if ( noHoles === true ) return toShapesNoHoles( subPaths );
  21237. var solid, tmpPath, tmpShape, shapes = [];
  21238. if ( subPaths.length === 1 ) {
  21239. tmpPath = subPaths[ 0 ];
  21240. tmpShape = new THREE.Shape();
  21241. tmpShape.actions = tmpPath.actions;
  21242. tmpShape.curves = tmpPath.curves;
  21243. shapes.push( tmpShape );
  21244. return shapes;
  21245. }
  21246. var holesFirst = ! isClockWise( subPaths[ 0 ].getPoints() );
  21247. holesFirst = isCCW ? ! holesFirst : holesFirst;
  21248. // console.log("Holes first", holesFirst);
  21249. var betterShapeHoles = [];
  21250. var newShapes = [];
  21251. var newShapeHoles = [];
  21252. var mainIdx = 0;
  21253. var tmpPoints;
  21254. newShapes[ mainIdx ] = undefined;
  21255. newShapeHoles[ mainIdx ] = [];
  21256. for ( var i = 0, l = subPaths.length; i < l; i ++ ) {
  21257. tmpPath = subPaths[ i ];
  21258. tmpPoints = tmpPath.getPoints();
  21259. solid = isClockWise( tmpPoints );
  21260. solid = isCCW ? ! solid : solid;
  21261. if ( solid ) {
  21262. if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) mainIdx ++;
  21263. newShapes[ mainIdx ] = { s: new THREE.Shape(), p: tmpPoints };
  21264. newShapes[ mainIdx ].s.actions = tmpPath.actions;
  21265. newShapes[ mainIdx ].s.curves = tmpPath.curves;
  21266. if ( holesFirst ) mainIdx ++;
  21267. newShapeHoles[ mainIdx ] = [];
  21268. //console.log('cw', i);
  21269. } else {
  21270. newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } );
  21271. //console.log('ccw', i);
  21272. }
  21273. }
  21274. // only Holes? -> probably all Shapes with wrong orientation
  21275. if ( ! newShapes[ 0 ] ) return toShapesNoHoles( subPaths );
  21276. if ( newShapes.length > 1 ) {
  21277. var ambiguous = false;
  21278. var toChange = [];
  21279. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  21280. betterShapeHoles[ sIdx ] = [];
  21281. }
  21282. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  21283. var sho = newShapeHoles[ sIdx ];
  21284. for ( var hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  21285. var ho = sho[ hIdx ];
  21286. var hole_unassigned = true;
  21287. for ( var s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  21288. if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
  21289. if ( sIdx !== s2Idx ) toChange.push( { froms: sIdx, tos: s2Idx, hole: hIdx } );
  21290. if ( hole_unassigned ) {
  21291. hole_unassigned = false;
  21292. betterShapeHoles[ s2Idx ].push( ho );
  21293. } else {
  21294. ambiguous = true;
  21295. }
  21296. }
  21297. }
  21298. if ( hole_unassigned ) {
  21299. betterShapeHoles[ sIdx ].push( ho );
  21300. }
  21301. }
  21302. }
  21303. // console.log("ambiguous: ", ambiguous);
  21304. if ( toChange.length > 0 ) {
  21305. // console.log("to change: ", toChange);
  21306. if ( ! ambiguous ) newShapeHoles = betterShapeHoles;
  21307. }
  21308. }
  21309. var tmpHoles;
  21310. for ( var i = 0, il = newShapes.length; i < il; i ++ ) {
  21311. tmpShape = newShapes[ i ].s;
  21312. shapes.push( tmpShape );
  21313. tmpHoles = newShapeHoles[ i ];
  21314. for ( var j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  21315. tmpShape.holes.push( tmpHoles[ j ].h );
  21316. }
  21317. }
  21318. //console.log("shape", shapes);
  21319. return shapes;
  21320. };
  21321. // File:src/extras/core/Shape.js
  21322. /**
  21323. * @author zz85 / http://www.lab4games.net/zz85/blog
  21324. * Defines a 2d shape plane using paths.
  21325. **/
  21326. // STEP 1 Create a path.
  21327. // STEP 2 Turn path into shape.
  21328. // STEP 3 ExtrudeGeometry takes in Shape/Shapes
  21329. // STEP 3a - Extract points from each shape, turn to vertices
  21330. // STEP 3b - Triangulate each shape, add faces.
  21331. THREE.Shape = function () {
  21332. THREE.Path.apply( this, arguments );
  21333. this.holes = [];
  21334. };
  21335. THREE.Shape.prototype = Object.create( THREE.Path.prototype );
  21336. THREE.Shape.prototype.constructor = THREE.Shape;
  21337. // Convenience method to return ExtrudeGeometry
  21338. THREE.Shape.prototype.extrude = function ( options ) {
  21339. return new THREE.ExtrudeGeometry( this, options );
  21340. };
  21341. // Convenience method to return ShapeGeometry
  21342. THREE.Shape.prototype.makeGeometry = function ( options ) {
  21343. return new THREE.ShapeGeometry( this, options );
  21344. };
  21345. // Get points of holes
  21346. THREE.Shape.prototype.getPointsHoles = function ( divisions ) {
  21347. var holesPts = [];
  21348. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  21349. holesPts[ i ] = this.holes[ i ].getPoints( divisions );
  21350. }
  21351. return holesPts;
  21352. };
  21353. // Get points of shape and holes (keypoints based on segments parameter)
  21354. THREE.Shape.prototype.extractAllPoints = function ( divisions ) {
  21355. return {
  21356. shape: this.getPoints( divisions ),
  21357. holes: this.getPointsHoles( divisions )
  21358. };
  21359. };
  21360. THREE.Shape.prototype.extractPoints = function ( divisions ) {
  21361. return this.extractAllPoints( divisions );
  21362. };
  21363. // File:src/extras/curves/LineCurve.js
  21364. /**************************************************************
  21365. * Line
  21366. **************************************************************/
  21367. THREE.LineCurve = function ( v1, v2 ) {
  21368. this.v1 = v1;
  21369. this.v2 = v2;
  21370. };
  21371. THREE.LineCurve.prototype = Object.create( THREE.Curve.prototype );
  21372. THREE.LineCurve.prototype.constructor = THREE.LineCurve;
  21373. THREE.LineCurve.prototype.getPoint = function ( t ) {
  21374. var point = this.v2.clone().sub( this.v1 );
  21375. point.multiplyScalar( t ).add( this.v1 );
  21376. return point;
  21377. };
  21378. // Line curve is linear, so we can overwrite default getPointAt
  21379. THREE.LineCurve.prototype.getPointAt = function ( u ) {
  21380. return this.getPoint( u );
  21381. };
  21382. THREE.LineCurve.prototype.getTangent = function( t ) {
  21383. var tangent = this.v2.clone().sub( this.v1 );
  21384. return tangent.normalize();
  21385. };
  21386. // File:src/extras/curves/QuadraticBezierCurve.js
  21387. /**************************************************************
  21388. * Quadratic Bezier curve
  21389. **************************************************************/
  21390. THREE.QuadraticBezierCurve = function ( v0, v1, v2 ) {
  21391. this.v0 = v0;
  21392. this.v1 = v1;
  21393. this.v2 = v2;
  21394. };
  21395. THREE.QuadraticBezierCurve.prototype = Object.create( THREE.Curve.prototype );
  21396. THREE.QuadraticBezierCurve.prototype.constructor = THREE.QuadraticBezierCurve;
  21397. THREE.QuadraticBezierCurve.prototype.getPoint = function ( t ) {
  21398. var b2 = THREE.ShapeUtils.b2;
  21399. return new THREE.Vector2(
  21400. b2( t, this.v0.x, this.v1.x, this.v2.x ),
  21401. b2( t, this.v0.y, this.v1.y, this.v2.y )
  21402. );
  21403. };
  21404. THREE.QuadraticBezierCurve.prototype.getTangent = function( t ) {
  21405. var tangentQuadraticBezier = THREE.CurveUtils.tangentQuadraticBezier;
  21406. return new THREE.Vector2(
  21407. tangentQuadraticBezier( t, this.v0.x, this.v1.x, this.v2.x ),
  21408. tangentQuadraticBezier( t, this.v0.y, this.v1.y, this.v2.y )
  21409. ).normalize();
  21410. };
  21411. // File:src/extras/curves/CubicBezierCurve.js
  21412. /**************************************************************
  21413. * Cubic Bezier curve
  21414. **************************************************************/
  21415. THREE.CubicBezierCurve = function ( v0, v1, v2, v3 ) {
  21416. this.v0 = v0;
  21417. this.v1 = v1;
  21418. this.v2 = v2;
  21419. this.v3 = v3;
  21420. };
  21421. THREE.CubicBezierCurve.prototype = Object.create( THREE.Curve.prototype );
  21422. THREE.CubicBezierCurve.prototype.constructor = THREE.CubicBezierCurve;
  21423. THREE.CubicBezierCurve.prototype.getPoint = function ( t ) {
  21424. var b3 = THREE.ShapeUtils.b3;
  21425. return new THREE.Vector2(
  21426. b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x ),
  21427. b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y )
  21428. );
  21429. };
  21430. THREE.CubicBezierCurve.prototype.getTangent = function( t ) {
  21431. var tangentCubicBezier = THREE.CurveUtils.tangentCubicBezier;
  21432. return new THREE.Vector2(
  21433. tangentCubicBezier( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x ),
  21434. tangentCubicBezier( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y )
  21435. ).normalize();
  21436. };
  21437. // File:src/extras/curves/SplineCurve.js
  21438. /**************************************************************
  21439. * Spline curve
  21440. **************************************************************/
  21441. THREE.SplineCurve = function ( points /* array of Vector2 */ ) {
  21442. this.points = ( points == undefined ) ? [] : points;
  21443. };
  21444. THREE.SplineCurve.prototype = Object.create( THREE.Curve.prototype );
  21445. THREE.SplineCurve.prototype.constructor = THREE.SplineCurve;
  21446. THREE.SplineCurve.prototype.getPoint = function ( t ) {
  21447. var points = this.points;
  21448. var point = ( points.length - 1 ) * t;
  21449. var intPoint = Math.floor( point );
  21450. var weight = point - intPoint;
  21451. var point0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  21452. var point1 = points[ intPoint ];
  21453. var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  21454. var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  21455. var interpolate = THREE.CurveUtils.interpolate;
  21456. return new THREE.Vector2(
  21457. interpolate( point0.x, point1.x, point2.x, point3.x, weight ),
  21458. interpolate( point0.y, point1.y, point2.y, point3.y, weight )
  21459. );
  21460. };
  21461. // File:src/extras/curves/EllipseCurve.js
  21462. /**************************************************************
  21463. * Ellipse curve
  21464. **************************************************************/
  21465. THREE.EllipseCurve = function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  21466. this.aX = aX;
  21467. this.aY = aY;
  21468. this.xRadius = xRadius;
  21469. this.yRadius = yRadius;
  21470. this.aStartAngle = aStartAngle;
  21471. this.aEndAngle = aEndAngle;
  21472. this.aClockwise = aClockwise;
  21473. this.aRotation = aRotation || 0;
  21474. };
  21475. THREE.EllipseCurve.prototype = Object.create( THREE.Curve.prototype );
  21476. THREE.EllipseCurve.prototype.constructor = THREE.EllipseCurve;
  21477. THREE.EllipseCurve.prototype.getPoint = function ( t ) {
  21478. var deltaAngle = this.aEndAngle - this.aStartAngle;
  21479. if ( deltaAngle < 0 ) deltaAngle += Math.PI * 2;
  21480. if ( deltaAngle > Math.PI * 2 ) deltaAngle -= Math.PI * 2;
  21481. var angle;
  21482. if ( this.aClockwise === true ) {
  21483. angle = this.aEndAngle + ( 1 - t ) * ( Math.PI * 2 - deltaAngle );
  21484. } else {
  21485. angle = this.aStartAngle + t * deltaAngle;
  21486. }
  21487. var x = this.aX + this.xRadius * Math.cos( angle );
  21488. var y = this.aY + this.yRadius * Math.sin( angle );
  21489. if ( this.aRotation !== 0 ) {
  21490. var cos = Math.cos( this.aRotation );
  21491. var sin = Math.sin( this.aRotation );
  21492. var tx = x, ty = y;
  21493. // Rotate the point about the center of the ellipse.
  21494. x = ( tx - this.aX ) * cos - ( ty - this.aY ) * sin + this.aX;
  21495. y = ( tx - this.aX ) * sin + ( ty - this.aY ) * cos + this.aY;
  21496. }
  21497. return new THREE.Vector2( x, y );
  21498. };
  21499. // File:src/extras/curves/ArcCurve.js
  21500. /**************************************************************
  21501. * Arc curve
  21502. **************************************************************/
  21503. THREE.ArcCurve = function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  21504. THREE.EllipseCurve.call( this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  21505. };
  21506. THREE.ArcCurve.prototype = Object.create( THREE.EllipseCurve.prototype );
  21507. THREE.ArcCurve.prototype.constructor = THREE.ArcCurve;
  21508. // File:src/extras/curves/LineCurve3.js
  21509. /**************************************************************
  21510. * Line3D
  21511. **************************************************************/
  21512. THREE.LineCurve3 = THREE.Curve.create(
  21513. function ( v1, v2 ) {
  21514. this.v1 = v1;
  21515. this.v2 = v2;
  21516. },
  21517. function ( t ) {
  21518. var vector = new THREE.Vector3();
  21519. vector.subVectors( this.v2, this.v1 ); // diff
  21520. vector.multiplyScalar( t );
  21521. vector.add( this.v1 );
  21522. return vector;
  21523. }
  21524. );
  21525. // File:src/extras/curves/QuadraticBezierCurve3.js
  21526. /**************************************************************
  21527. * Quadratic Bezier 3D curve
  21528. **************************************************************/
  21529. THREE.QuadraticBezierCurve3 = THREE.Curve.create(
  21530. function ( v0, v1, v2 ) {
  21531. this.v0 = v0;
  21532. this.v1 = v1;
  21533. this.v2 = v2;
  21534. },
  21535. function ( t ) {
  21536. var b2 = THREE.ShapeUtils.b2;
  21537. return new THREE.Vector3(
  21538. b2( t, this.v0.x, this.v1.x, this.v2.x ),
  21539. b2( t, this.v0.y, this.v1.y, this.v2.y ),
  21540. b2( t, this.v0.z, this.v1.z, this.v2.z )
  21541. );
  21542. }
  21543. );
  21544. // File:src/extras/curves/CubicBezierCurve3.js
  21545. /**************************************************************
  21546. * Cubic Bezier 3D curve
  21547. **************************************************************/
  21548. THREE.CubicBezierCurve3 = THREE.Curve.create(
  21549. function ( v0, v1, v2, v3 ) {
  21550. this.v0 = v0;
  21551. this.v1 = v1;
  21552. this.v2 = v2;
  21553. this.v3 = v3;
  21554. },
  21555. function ( t ) {
  21556. var b3 = THREE.ShapeUtils.b3;
  21557. return new THREE.Vector3(
  21558. b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x ),
  21559. b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y ),
  21560. b3( t, this.v0.z, this.v1.z, this.v2.z, this.v3.z )
  21561. );
  21562. }
  21563. );
  21564. // File:src/extras/curves/SplineCurve3.js
  21565. /**************************************************************
  21566. * Spline 3D curve
  21567. **************************************************************/
  21568. THREE.SplineCurve3 = THREE.Curve.create(
  21569. function ( points /* array of Vector3 */ ) {
  21570. console.warn( 'THREE.SplineCurve3 will be deprecated. Please use THREE.CatmullRomCurve3' );
  21571. this.points = ( points == undefined ) ? [] : points;
  21572. },
  21573. function ( t ) {
  21574. var points = this.points;
  21575. var point = ( points.length - 1 ) * t;
  21576. var intPoint = Math.floor( point );
  21577. var weight = point - intPoint;
  21578. var point0 = points[ intPoint == 0 ? intPoint : intPoint - 1 ];
  21579. var point1 = points[ intPoint ];
  21580. var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  21581. var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  21582. var interpolate = THREE.CurveUtils.interpolate;
  21583. return new THREE.Vector3(
  21584. interpolate( point0.x, point1.x, point2.x, point3.x, weight ),
  21585. interpolate( point0.y, point1.y, point2.y, point3.y, weight ),
  21586. interpolate( point0.z, point1.z, point2.z, point3.z, weight )
  21587. );
  21588. }
  21589. );
  21590. // File:src/extras/curves/CatmullRomCurve3.js
  21591. /**
  21592. * @author zz85 https://github.com/zz85
  21593. *
  21594. * Centripetal CatmullRom Curve - which is useful for avoiding
  21595. * cusps and self-intersections in non-uniform catmull rom curves.
  21596. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  21597. *
  21598. * curve.type accepts centripetal(default), chordal and catmullrom
  21599. * curve.tension is used for catmullrom which defaults to 0.5
  21600. */
  21601. THREE.CatmullRomCurve3 = ( function() {
  21602. var
  21603. tmp = new THREE.Vector3(),
  21604. px = new CubicPoly(),
  21605. py = new CubicPoly(),
  21606. pz = new CubicPoly();
  21607. /*
  21608. Based on an optimized c++ solution in
  21609. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  21610. - http://ideone.com/NoEbVM
  21611. This CubicPoly class could be used for reusing some variables and calculations,
  21612. but for three.js curve use, it could be possible inlined and flatten into a single function call
  21613. which can be placed in CurveUtils.
  21614. */
  21615. function CubicPoly() {
  21616. }
  21617. /*
  21618. * Compute coefficients for a cubic polynomial
  21619. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  21620. * such that
  21621. * p(0) = x0, p(1) = x1
  21622. * and
  21623. * p'(0) = t0, p'(1) = t1.
  21624. */
  21625. CubicPoly.prototype.init = function( x0, x1, t0, t1 ) {
  21626. this.c0 = x0;
  21627. this.c1 = t0;
  21628. this.c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  21629. this.c3 = 2 * x0 - 2 * x1 + t0 + t1;
  21630. };
  21631. CubicPoly.prototype.initNonuniformCatmullRom = function( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  21632. // compute tangents when parameterized in [t1,t2]
  21633. var t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  21634. var t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  21635. // rescale tangents for parametrization in [0,1]
  21636. t1 *= dt1;
  21637. t2 *= dt1;
  21638. // initCubicPoly
  21639. this.init( x1, x2, t1, t2 );
  21640. };
  21641. // standard Catmull-Rom spline: interpolate between x1 and x2 with previous/following points x1/x4
  21642. CubicPoly.prototype.initCatmullRom = function( x0, x1, x2, x3, tension ) {
  21643. this.init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  21644. };
  21645. CubicPoly.prototype.calc = function( t ) {
  21646. var t2 = t * t;
  21647. var t3 = t2 * t;
  21648. return this.c0 + this.c1 * t + this.c2 * t2 + this.c3 * t3;
  21649. };
  21650. // Subclass Three.js curve
  21651. return THREE.Curve.create(
  21652. function ( p /* array of Vector3 */ ) {
  21653. this.points = p || [];
  21654. this.closed = false;
  21655. },
  21656. function ( t ) {
  21657. var points = this.points,
  21658. point, intPoint, weight, l;
  21659. l = points.length;
  21660. if ( l < 2 ) console.log( 'duh, you need at least 2 points' );
  21661. point = ( l - ( this.closed ? 0 : 1 ) ) * t;
  21662. intPoint = Math.floor( point );
  21663. weight = point - intPoint;
  21664. if ( this.closed ) {
  21665. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / points.length ) + 1 ) * points.length;
  21666. } else if ( weight === 0 && intPoint === l - 1 ) {
  21667. intPoint = l - 2;
  21668. weight = 1;
  21669. }
  21670. var p0, p1, p2, p3; // 4 points
  21671. if ( this.closed || intPoint > 0 ) {
  21672. p0 = points[ ( intPoint - 1 ) % l ];
  21673. } else {
  21674. // extrapolate first point
  21675. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  21676. p0 = tmp;
  21677. }
  21678. p1 = points[ intPoint % l ];
  21679. p2 = points[ ( intPoint + 1 ) % l ];
  21680. if ( this.closed || intPoint + 2 < l ) {
  21681. p3 = points[ ( intPoint + 2 ) % l ];
  21682. } else {
  21683. // extrapolate last point
  21684. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 1 ] );
  21685. p3 = tmp;
  21686. }
  21687. if ( this.type === undefined || this.type === 'centripetal' || this.type === 'chordal' ) {
  21688. // init Centripetal / Chordal Catmull-Rom
  21689. var pow = this.type === 'chordal' ? 0.5 : 0.25;
  21690. var dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  21691. var dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  21692. var dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  21693. // safety check for repeated points
  21694. if ( dt1 < 1e-4 ) dt1 = 1.0;
  21695. if ( dt0 < 1e-4 ) dt0 = dt1;
  21696. if ( dt2 < 1e-4 ) dt2 = dt1;
  21697. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  21698. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  21699. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  21700. } else if ( this.type === 'catmullrom' ) {
  21701. var tension = this.tension !== undefined ? this.tension : 0.5;
  21702. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, tension );
  21703. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, tension );
  21704. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, tension );
  21705. }
  21706. var v = new THREE.Vector3(
  21707. px.calc( weight ),
  21708. py.calc( weight ),
  21709. pz.calc( weight )
  21710. );
  21711. return v;
  21712. }
  21713. );
  21714. } )();
  21715. // File:src/extras/curves/ClosedSplineCurve3.js
  21716. /**************************************************************
  21717. * Closed Spline 3D curve
  21718. **************************************************************/
  21719. THREE.ClosedSplineCurve3 = function ( points ) {
  21720. console.warn( 'THREE.ClosedSplineCurve3 has been deprecated. Please use THREE.CatmullRomCurve3.' );
  21721. THREE.CatmullRomCurve3.call( this, points );
  21722. this.type = 'catmullrom';
  21723. this.closed = true;
  21724. };
  21725. THREE.ClosedSplineCurve3.prototype = Object.create( THREE.CatmullRomCurve3.prototype );
  21726. // File:src/extras/geometries/BoxGeometry.js
  21727. /**
  21728. * @author mrdoob / http://mrdoob.com/
  21729. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Cube.as
  21730. */
  21731. THREE.BoxGeometry = function ( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  21732. THREE.Geometry.call( this );
  21733. this.type = 'BoxGeometry';
  21734. this.parameters = {
  21735. width: width,
  21736. height: height,
  21737. depth: depth,
  21738. widthSegments: widthSegments,
  21739. heightSegments: heightSegments,
  21740. depthSegments: depthSegments
  21741. };
  21742. this.fromBufferGeometry( new THREE.BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) );
  21743. this.mergeVertices();
  21744. };
  21745. THREE.BoxGeometry.prototype = Object.create( THREE.Geometry.prototype );
  21746. THREE.BoxGeometry.prototype.constructor = THREE.BoxGeometry;
  21747. THREE.CubeGeometry = THREE.BoxGeometry;
  21748. // File:src/extras/geometries/BoxBufferGeometry.js
  21749. /**
  21750. * @author Mugen87 / https://github.com/Mugen87
  21751. */
  21752. THREE.BoxBufferGeometry = function ( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  21753. THREE.BufferGeometry.call( this );
  21754. this.type = 'BoxBufferGeometry';
  21755. this.parameters = {
  21756. width: width,
  21757. height: height,
  21758. depth: depth,
  21759. widthSegments: widthSegments,
  21760. heightSegments: heightSegments,
  21761. depthSegments: depthSegments
  21762. };
  21763. var scope = this;
  21764. // segments
  21765. widthSegments = Math.floor( widthSegments ) || 1;
  21766. heightSegments = Math.floor( heightSegments ) || 1;
  21767. depthSegments = Math.floor( depthSegments ) || 1;
  21768. // these are used to calculate buffer length
  21769. var vertexCount = calculateVertexCount( widthSegments, heightSegments, depthSegments );
  21770. var indexCount = calculateIndexCount( widthSegments, heightSegments, depthSegments );
  21771. // buffers
  21772. var indices = new ( indexCount > 65535 ? Uint32Array : Uint16Array )( indexCount );
  21773. var vertices = new Float32Array( vertexCount * 3 );
  21774. var normals = new Float32Array( vertexCount * 3 );
  21775. var uvs = new Float32Array( vertexCount * 2 );
  21776. // offset variables
  21777. var vertexBufferOffset = 0;
  21778. var uvBufferOffset = 0;
  21779. var indexBufferOffset = 0;
  21780. var numberOfVertices = 0;
  21781. // group variables
  21782. var groupStart = 0;
  21783. // build each side of the box geometry
  21784. buildPlane( 'z', 'y', 'x', - 1, - 1, depth, height, width, depthSegments, heightSegments, 0 ); // px
  21785. buildPlane( 'z', 'y', 'x', 1, - 1, depth, height, - width, depthSegments, heightSegments, 1 ); // nx
  21786. buildPlane( 'x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2 ); // py
  21787. buildPlane( 'x', 'z', 'y', 1, - 1, width, depth, - height, widthSegments, depthSegments, 3 ); // ny
  21788. buildPlane( 'x', 'y', 'z', 1, - 1, width, height, depth, widthSegments, heightSegments, 4 ); // pz
  21789. buildPlane( 'x', 'y', 'z', - 1, - 1, width, height, - depth, widthSegments, heightSegments, 5 ); // nz
  21790. // build geometry
  21791. this.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  21792. this.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  21793. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  21794. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  21795. // helper functions
  21796. function calculateVertexCount ( w, h, d ) {
  21797. var vertices = 0;
  21798. // calculate the amount of vertices for each side (plane)
  21799. vertices += (w + 1) * (h + 1) * 2; // xy
  21800. vertices += (w + 1) * (d + 1) * 2; // xz
  21801. vertices += (d + 1) * (h + 1) * 2; // zy
  21802. return vertices;
  21803. }
  21804. function calculateIndexCount ( w, h, d ) {
  21805. var index = 0;
  21806. // calculate the amount of squares for each side
  21807. index += w * h * 2; // xy
  21808. index += w * d * 2; // xz
  21809. index += d * h * 2; // zy
  21810. return index * 6; // two triangles per square => six vertices per square
  21811. }
  21812. function buildPlane ( u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex ) {
  21813. var segmentWidth = width / gridX;
  21814. var segmentHeight = height / gridY;
  21815. var widthHalf = width / 2;
  21816. var heightHalf = height / 2;
  21817. var depthHalf = depth / 2;
  21818. var gridX1 = gridX + 1;
  21819. var gridY1 = gridY + 1;
  21820. var vertexCounter = 0;
  21821. var groupCount = 0;
  21822. var vector = new THREE.Vector3();
  21823. // generate vertices, normals and uvs
  21824. for ( var iy = 0; iy < gridY1; iy ++ ) {
  21825. var y = iy * segmentHeight - heightHalf;
  21826. for ( var ix = 0; ix < gridX1; ix ++ ) {
  21827. var x = ix * segmentWidth - widthHalf;
  21828. // set values to correct vector component
  21829. vector[ u ] = x * udir;
  21830. vector[ v ] = y * vdir;
  21831. vector[ w ] = depthHalf;
  21832. // now apply vector to vertex buffer
  21833. vertices[ vertexBufferOffset ] = vector.x;
  21834. vertices[ vertexBufferOffset + 1 ] = vector.y;
  21835. vertices[ vertexBufferOffset + 2 ] = vector.z;
  21836. // set values to correct vector component
  21837. vector[ u ] = 0;
  21838. vector[ v ] = 0;
  21839. vector[ w ] = depth > 0 ? 1 : - 1;
  21840. // now apply vector to normal buffer
  21841. normals[ vertexBufferOffset ] = vector.x;
  21842. normals[ vertexBufferOffset + 1 ] = vector.y;
  21843. normals[ vertexBufferOffset + 2 ] = vector.z;
  21844. // uvs
  21845. uvs[ uvBufferOffset ] = ix / gridX;
  21846. uvs[ uvBufferOffset + 1 ] = 1 - ( iy / gridY );
  21847. // update offsets and counters
  21848. vertexBufferOffset += 3;
  21849. uvBufferOffset += 2;
  21850. vertexCounter += 1;
  21851. }
  21852. }
  21853. // 1. you need three indices to draw a single face
  21854. // 2. a single segment consists of two faces
  21855. // 3. so we need to generate six (2*3) indices per segment
  21856. for ( iy = 0; iy < gridY; iy ++ ) {
  21857. for ( ix = 0; ix < gridX; ix ++ ) {
  21858. // indices
  21859. var a = numberOfVertices + ix + gridX1 * iy;
  21860. var b = numberOfVertices + ix + gridX1 * ( iy + 1 );
  21861. var c = numberOfVertices + ( ix + 1 ) + gridX1 * ( iy + 1 );
  21862. var d = numberOfVertices + ( ix + 1 ) + gridX1 * iy;
  21863. // face one
  21864. indices[ indexBufferOffset ] = a;
  21865. indices[ indexBufferOffset + 1 ] = b;
  21866. indices[ indexBufferOffset + 2 ] = d;
  21867. // face two
  21868. indices[ indexBufferOffset + 3 ] = b;
  21869. indices[ indexBufferOffset + 4 ] = c;
  21870. indices[ indexBufferOffset + 5 ] = d;
  21871. // update offsets and counters
  21872. indexBufferOffset += 6;
  21873. groupCount += 6;
  21874. }
  21875. }
  21876. // add a group to the geometry. this will ensure multi material support
  21877. scope.addGroup( groupStart, groupCount, materialIndex );
  21878. // calculate new start value for groups
  21879. groupStart += groupCount;
  21880. // update total number of vertices
  21881. numberOfVertices += vertexCounter;
  21882. }
  21883. };
  21884. THREE.BoxBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  21885. THREE.BoxBufferGeometry.prototype.constructor = THREE.BoxBufferGeometry;
  21886. // File:src/extras/geometries/CircleGeometry.js
  21887. /**
  21888. * @author hughes
  21889. */
  21890. THREE.CircleGeometry = function ( radius, segments, thetaStart, thetaLength ) {
  21891. THREE.Geometry.call( this );
  21892. this.type = 'CircleGeometry';
  21893. this.parameters = {
  21894. radius: radius,
  21895. segments: segments,
  21896. thetaStart: thetaStart,
  21897. thetaLength: thetaLength
  21898. };
  21899. this.fromBufferGeometry( new THREE.CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) );
  21900. };
  21901. THREE.CircleGeometry.prototype = Object.create( THREE.Geometry.prototype );
  21902. THREE.CircleGeometry.prototype.constructor = THREE.CircleGeometry;
  21903. // File:src/extras/geometries/CircleBufferGeometry.js
  21904. /**
  21905. * @author benaadams / https://twitter.com/ben_a_adams
  21906. */
  21907. THREE.CircleBufferGeometry = function ( radius, segments, thetaStart, thetaLength ) {
  21908. THREE.BufferGeometry.call( this );
  21909. this.type = 'CircleBufferGeometry';
  21910. this.parameters = {
  21911. radius: radius,
  21912. segments: segments,
  21913. thetaStart: thetaStart,
  21914. thetaLength: thetaLength
  21915. };
  21916. radius = radius || 50;
  21917. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  21918. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  21919. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  21920. var vertices = segments + 2;
  21921. var positions = new Float32Array( vertices * 3 );
  21922. var normals = new Float32Array( vertices * 3 );
  21923. var uvs = new Float32Array( vertices * 2 );
  21924. // center data is already zero, but need to set a few extras
  21925. normals[ 2 ] = 1.0;
  21926. uvs[ 0 ] = 0.5;
  21927. uvs[ 1 ] = 0.5;
  21928. for ( var s = 0, i = 3, ii = 2 ; s <= segments; s ++, i += 3, ii += 2 ) {
  21929. var segment = thetaStart + s / segments * thetaLength;
  21930. positions[ i ] = radius * Math.cos( segment );
  21931. positions[ i + 1 ] = radius * Math.sin( segment );
  21932. normals[ i + 2 ] = 1; // normal z
  21933. uvs[ ii ] = ( positions[ i ] / radius + 1 ) / 2;
  21934. uvs[ ii + 1 ] = ( positions[ i + 1 ] / radius + 1 ) / 2;
  21935. }
  21936. var indices = [];
  21937. for ( var i = 1; i <= segments; i ++ ) {
  21938. indices.push( i, i + 1, 0 );
  21939. }
  21940. this.setIndex( new THREE.BufferAttribute( new Uint16Array( indices ), 1 ) );
  21941. this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
  21942. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  21943. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  21944. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  21945. };
  21946. THREE.CircleBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  21947. THREE.CircleBufferGeometry.prototype.constructor = THREE.CircleBufferGeometry;
  21948. // File:src/extras/geometries/CylinderBufferGeometry.js
  21949. /**
  21950. * @author Mugen87 / https://github.com/Mugen87
  21951. */
  21952. THREE.CylinderBufferGeometry = function( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  21953. THREE.BufferGeometry.call( this );
  21954. this.type = 'CylinderBufferGeometry';
  21955. this.parameters = {
  21956. radiusTop: radiusTop,
  21957. radiusBottom: radiusBottom,
  21958. height: height,
  21959. radialSegments: radialSegments,
  21960. heightSegments: heightSegments,
  21961. openEnded: openEnded,
  21962. thetaStart: thetaStart,
  21963. thetaLength: thetaLength
  21964. };
  21965. var scope = this;
  21966. radiusTop = radiusTop !== undefined ? radiusTop : 20;
  21967. radiusBottom = radiusBottom !== undefined ? radiusBottom : 20;
  21968. height = height !== undefined ? height : 100;
  21969. radialSegments = Math.floor( radialSegments ) || 8;
  21970. heightSegments = Math.floor( heightSegments ) || 1;
  21971. openEnded = openEnded !== undefined ? openEnded : false;
  21972. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  21973. thetaLength = thetaLength !== undefined ? thetaLength : 2 * Math.PI;
  21974. // used to calculate buffer length
  21975. var nbCap = 0;
  21976. if ( openEnded === false ) {
  21977. if ( radiusTop > 0 ) nbCap++;
  21978. if ( radiusBottom > 0 ) nbCap++;
  21979. }
  21980. var vertexCount = calculateVertexCount();
  21981. var indexCount = calculateIndexCount();
  21982. // buffers
  21983. var indices = new THREE.BufferAttribute( new ( indexCount > 65535 ? Uint32Array : Uint16Array )( indexCount ), 1 );
  21984. var vertices = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  21985. var normals = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  21986. var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
  21987. // helper variables
  21988. var index = 0, indexOffset = 0, indexArray = [], halfHeight = height / 2;
  21989. // group variables
  21990. var groupStart = 0;
  21991. // generate geometry
  21992. generateTorso();
  21993. if ( openEnded === false ) {
  21994. if ( radiusTop > 0 ) generateCap( true );
  21995. if ( radiusBottom > 0 ) generateCap( false );
  21996. }
  21997. // build geometry
  21998. this.setIndex( indices );
  21999. this.addAttribute( 'position', vertices );
  22000. this.addAttribute( 'normal', normals );
  22001. this.addAttribute( 'uv', uvs );
  22002. // helper functions
  22003. function calculateVertexCount() {
  22004. var count = ( radialSegments + 1 ) * ( heightSegments + 1 );
  22005. if ( openEnded === false ) {
  22006. count += ( ( radialSegments + 1 ) * nbCap ) + ( radialSegments * nbCap );
  22007. }
  22008. return count;
  22009. }
  22010. function calculateIndexCount() {
  22011. var count = radialSegments * heightSegments * 2 * 3;
  22012. if ( openEnded === false ) {
  22013. count += radialSegments * nbCap * 3;
  22014. }
  22015. return count;
  22016. }
  22017. function generateTorso() {
  22018. var x, y;
  22019. var normal = new THREE.Vector3();
  22020. var vertex = new THREE.Vector3();
  22021. var groupCount = 0;
  22022. // this will be used to calculate the normal
  22023. var tanTheta = ( radiusBottom - radiusTop ) / height;
  22024. // generate vertices, normals and uvs
  22025. for ( y = 0; y <= heightSegments; y ++ ) {
  22026. var indexRow = [];
  22027. var v = y / heightSegments;
  22028. // calculate the radius of the current row
  22029. var radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  22030. for ( x = 0; x <= radialSegments; x ++ ) {
  22031. var u = x / radialSegments;
  22032. // vertex
  22033. vertex.x = radius * Math.sin( u * thetaLength + thetaStart );
  22034. vertex.y = - v * height + halfHeight;
  22035. vertex.z = radius * Math.cos( u * thetaLength + thetaStart );
  22036. vertices.setXYZ( index, vertex.x, vertex.y, vertex.z );
  22037. // normal
  22038. normal.copy( vertex );
  22039. // handle special case if radiusTop/radiusBottom is zero
  22040. if ( ( radiusTop === 0 && y === 0 ) || ( radiusBottom === 0 && y === heightSegments ) ) {
  22041. normal.x = Math.sin( u * thetaLength + thetaStart );
  22042. normal.z = Math.cos( u * thetaLength + thetaStart );
  22043. }
  22044. normal.setY( Math.sqrt( normal.x * normal.x + normal.z * normal.z ) * tanTheta ).normalize();
  22045. normals.setXYZ( index, normal.x, normal.y, normal.z );
  22046. // uv
  22047. uvs.setXY( index, u, 1 - v );
  22048. // save index of vertex in respective row
  22049. indexRow.push( index );
  22050. // increase index
  22051. index ++;
  22052. }
  22053. // now save vertices of the row in our index array
  22054. indexArray.push( indexRow );
  22055. }
  22056. // generate indices
  22057. for ( x = 0; x < radialSegments; x ++ ) {
  22058. for ( y = 0; y < heightSegments; y ++ ) {
  22059. // we use the index array to access the correct indices
  22060. var i1 = indexArray[ y ][ x ];
  22061. var i2 = indexArray[ y + 1 ][ x ];
  22062. var i3 = indexArray[ y + 1 ][ x + 1 ];
  22063. var i4 = indexArray[ y ][ x + 1 ];
  22064. // face one
  22065. indices.setX( indexOffset, i1 ); indexOffset ++;
  22066. indices.setX( indexOffset, i2 ); indexOffset ++;
  22067. indices.setX( indexOffset, i4 ); indexOffset ++;
  22068. // face two
  22069. indices.setX( indexOffset, i2 ); indexOffset ++;
  22070. indices.setX( indexOffset, i3 ); indexOffset ++;
  22071. indices.setX( indexOffset, i4 ); indexOffset ++;
  22072. // update counters
  22073. groupCount += 6;
  22074. }
  22075. }
  22076. // add a group to the geometry. this will ensure multi material support
  22077. scope.addGroup( groupStart, groupCount, 0 );
  22078. // calculate new start value for groups
  22079. groupStart += groupCount;
  22080. }
  22081. function generateCap( top ) {
  22082. var x, centerIndexStart, centerIndexEnd;
  22083. var uv = new THREE.Vector2();
  22084. var vertex = new THREE.Vector3();
  22085. var groupCount = 0;
  22086. var radius = ( top === true ) ? radiusTop : radiusBottom;
  22087. var sign = ( top === true ) ? 1 : - 1;
  22088. // save the index of the first center vertex
  22089. centerIndexStart = index;
  22090. // first we generate the center vertex data of the cap.
  22091. // because the geometry needs one set of uvs per face,
  22092. // we must generate a center vertex per face/segment
  22093. for ( x = 1; x <= radialSegments; x ++ ) {
  22094. // vertex
  22095. vertices.setXYZ( index, 0, halfHeight * sign, 0 );
  22096. // normal
  22097. normals.setXYZ( index, 0, sign, 0 );
  22098. // uv
  22099. if ( top === true ) {
  22100. uv.x = x / radialSegments;
  22101. uv.y = 0;
  22102. } else {
  22103. uv.x = ( x - 1 ) / radialSegments;
  22104. uv.y = 1;
  22105. }
  22106. uvs.setXY( index, uv.x, uv.y );
  22107. // increase index
  22108. index ++;
  22109. }
  22110. // save the index of the last center vertex
  22111. centerIndexEnd = index;
  22112. // now we generate the surrounding vertices, normals and uvs
  22113. for ( x = 0; x <= radialSegments; x ++ ) {
  22114. var u = x / radialSegments;
  22115. // vertex
  22116. vertex.x = radius * Math.sin( u * thetaLength + thetaStart );
  22117. vertex.y = halfHeight * sign;
  22118. vertex.z = radius * Math.cos( u * thetaLength + thetaStart );
  22119. vertices.setXYZ( index, vertex.x, vertex.y, vertex.z );
  22120. // normal
  22121. normals.setXYZ( index, 0, sign, 0 );
  22122. // uv
  22123. uvs.setXY( index, u, ( top === true ) ? 1 : 0 );
  22124. // increase index
  22125. index ++;
  22126. }
  22127. // generate indices
  22128. for ( x = 0; x < radialSegments; x ++ ) {
  22129. var c = centerIndexStart + x;
  22130. var i = centerIndexEnd + x;
  22131. if ( top === true ) {
  22132. // face top
  22133. indices.setX( indexOffset, i ); indexOffset ++;
  22134. indices.setX( indexOffset, i + 1 ); indexOffset ++;
  22135. indices.setX( indexOffset, c ); indexOffset ++;
  22136. } else {
  22137. // face bottom
  22138. indices.setX( indexOffset, i + 1 ); indexOffset ++;
  22139. indices.setX( indexOffset, i ); indexOffset ++;
  22140. indices.setX( indexOffset, c ); indexOffset ++;
  22141. }
  22142. // update counters
  22143. groupCount += 3;
  22144. }
  22145. // add a group to the geometry. this will ensure multi material support
  22146. scope.addGroup( groupStart, groupCount, top === true ? 1 : 2 );
  22147. // calculate new start value for groups
  22148. groupStart += groupCount;
  22149. }
  22150. };
  22151. THREE.CylinderBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  22152. THREE.CylinderBufferGeometry.prototype.constructor = THREE.CylinderBufferGeometry;
  22153. // File:src/extras/geometries/CylinderGeometry.js
  22154. /**
  22155. * @author mrdoob / http://mrdoob.com/
  22156. */
  22157. THREE.CylinderGeometry = function ( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  22158. THREE.Geometry.call( this );
  22159. this.type = 'CylinderGeometry';
  22160. this.parameters = {
  22161. radiusTop: radiusTop,
  22162. radiusBottom: radiusBottom,
  22163. height: height,
  22164. radialSegments: radialSegments,
  22165. heightSegments: heightSegments,
  22166. openEnded: openEnded,
  22167. thetaStart: thetaStart,
  22168. thetaLength: thetaLength
  22169. };
  22170. this.fromBufferGeometry( new THREE.CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) );
  22171. this.mergeVertices();
  22172. };
  22173. THREE.CylinderGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22174. THREE.CylinderGeometry.prototype.constructor = THREE.CylinderGeometry;
  22175. // File:src/extras/geometries/EdgesGeometry.js
  22176. /**
  22177. * @author WestLangley / http://github.com/WestLangley
  22178. */
  22179. THREE.EdgesGeometry = function ( geometry, thresholdAngle ) {
  22180. THREE.BufferGeometry.call( this );
  22181. thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
  22182. var thresholdDot = Math.cos( THREE.Math.DEG2RAD * thresholdAngle );
  22183. var edge = [ 0, 0 ], hash = {};
  22184. function sortFunction( a, b ) {
  22185. return a - b;
  22186. }
  22187. var keys = [ 'a', 'b', 'c' ];
  22188. var geometry2;
  22189. if ( geometry instanceof THREE.BufferGeometry ) {
  22190. geometry2 = new THREE.Geometry();
  22191. geometry2.fromBufferGeometry( geometry );
  22192. } else {
  22193. geometry2 = geometry.clone();
  22194. }
  22195. geometry2.mergeVertices();
  22196. geometry2.computeFaceNormals();
  22197. var vertices = geometry2.vertices;
  22198. var faces = geometry2.faces;
  22199. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  22200. var face = faces[ i ];
  22201. for ( var j = 0; j < 3; j ++ ) {
  22202. edge[ 0 ] = face[ keys[ j ] ];
  22203. edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
  22204. edge.sort( sortFunction );
  22205. var key = edge.toString();
  22206. if ( hash[ key ] === undefined ) {
  22207. hash[ key ] = { vert1: edge[ 0 ], vert2: edge[ 1 ], face1: i, face2: undefined };
  22208. } else {
  22209. hash[ key ].face2 = i;
  22210. }
  22211. }
  22212. }
  22213. var coords = [];
  22214. for ( var key in hash ) {
  22215. var h = hash[ key ];
  22216. if ( h.face2 === undefined || faces[ h.face1 ].normal.dot( faces[ h.face2 ].normal ) <= thresholdDot ) {
  22217. var vertex = vertices[ h.vert1 ];
  22218. coords.push( vertex.x );
  22219. coords.push( vertex.y );
  22220. coords.push( vertex.z );
  22221. vertex = vertices[ h.vert2 ];
  22222. coords.push( vertex.x );
  22223. coords.push( vertex.y );
  22224. coords.push( vertex.z );
  22225. }
  22226. }
  22227. this.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array( coords ), 3 ) );
  22228. };
  22229. THREE.EdgesGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  22230. THREE.EdgesGeometry.prototype.constructor = THREE.EdgesGeometry;
  22231. // File:src/extras/geometries/ExtrudeGeometry.js
  22232. /**
  22233. * @author zz85 / http://www.lab4games.net/zz85/blog
  22234. *
  22235. * Creates extruded geometry from a path shape.
  22236. *
  22237. * parameters = {
  22238. *
  22239. * curveSegments: <int>, // number of points on the curves
  22240. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  22241. * amount: <int>, // Depth to extrude the shape
  22242. *
  22243. * bevelEnabled: <bool>, // turn on bevel
  22244. * bevelThickness: <float>, // how deep into the original shape bevel goes
  22245. * bevelSize: <float>, // how far from shape outline is bevel
  22246. * bevelSegments: <int>, // number of bevel layers
  22247. *
  22248. * extrudePath: <THREE.CurvePath> // 3d spline path to extrude shape along. (creates Frames if .frames aren't defined)
  22249. * frames: <THREE.TubeGeometry.FrenetFrames> // containing arrays of tangents, normals, binormals
  22250. *
  22251. * uvGenerator: <Object> // object that provides UV generator functions
  22252. *
  22253. * }
  22254. **/
  22255. THREE.ExtrudeGeometry = function ( shapes, options ) {
  22256. if ( typeof( shapes ) === "undefined" ) {
  22257. shapes = [];
  22258. return;
  22259. }
  22260. THREE.Geometry.call( this );
  22261. this.type = 'ExtrudeGeometry';
  22262. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  22263. this.addShapeList( shapes, options );
  22264. this.computeFaceNormals();
  22265. // can't really use automatic vertex normals
  22266. // as then front and back sides get smoothed too
  22267. // should do separate smoothing just for sides
  22268. //this.computeVertexNormals();
  22269. //console.log( "took", ( Date.now() - startTime ) );
  22270. };
  22271. THREE.ExtrudeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22272. THREE.ExtrudeGeometry.prototype.constructor = THREE.ExtrudeGeometry;
  22273. THREE.ExtrudeGeometry.prototype.addShapeList = function ( shapes, options ) {
  22274. var sl = shapes.length;
  22275. for ( var s = 0; s < sl; s ++ ) {
  22276. var shape = shapes[ s ];
  22277. this.addShape( shape, options );
  22278. }
  22279. };
  22280. THREE.ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
  22281. var amount = options.amount !== undefined ? options.amount : 100;
  22282. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6; // 10
  22283. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2; // 8
  22284. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  22285. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true; // false
  22286. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  22287. var steps = options.steps !== undefined ? options.steps : 1;
  22288. var extrudePath = options.extrudePath;
  22289. var extrudePts, extrudeByPath = false;
  22290. // Use default WorldUVGenerator if no UV generators are specified.
  22291. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : THREE.ExtrudeGeometry.WorldUVGenerator;
  22292. var splineTube, binormal, normal, position2;
  22293. if ( extrudePath ) {
  22294. extrudePts = extrudePath.getSpacedPoints( steps );
  22295. extrudeByPath = true;
  22296. bevelEnabled = false; // bevels not supported for path extrusion
  22297. // SETUP TNB variables
  22298. // Reuse TNB from TubeGeomtry for now.
  22299. // TODO1 - have a .isClosed in spline?
  22300. splineTube = options.frames !== undefined ? options.frames : new THREE.TubeGeometry.FrenetFrames( extrudePath, steps, false );
  22301. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  22302. binormal = new THREE.Vector3();
  22303. normal = new THREE.Vector3();
  22304. position2 = new THREE.Vector3();
  22305. }
  22306. // Safeguards if bevels are not enabled
  22307. if ( ! bevelEnabled ) {
  22308. bevelSegments = 0;
  22309. bevelThickness = 0;
  22310. bevelSize = 0;
  22311. }
  22312. // Variables initialization
  22313. var ahole, h, hl; // looping of holes
  22314. var scope = this;
  22315. var shapesOffset = this.vertices.length;
  22316. var shapePoints = shape.extractPoints( curveSegments );
  22317. var vertices = shapePoints.shape;
  22318. var holes = shapePoints.holes;
  22319. var reverse = ! THREE.ShapeUtils.isClockWise( vertices );
  22320. if ( reverse ) {
  22321. vertices = vertices.reverse();
  22322. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  22323. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  22324. ahole = holes[ h ];
  22325. if ( THREE.ShapeUtils.isClockWise( ahole ) ) {
  22326. holes[ h ] = ahole.reverse();
  22327. }
  22328. }
  22329. reverse = false; // If vertices are in order now, we shouldn't need to worry about them again (hopefully)!
  22330. }
  22331. var faces = THREE.ShapeUtils.triangulateShape( vertices, holes );
  22332. /* Vertices */
  22333. var contour = vertices; // vertices has all points but contour has only points of circumference
  22334. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  22335. ahole = holes[ h ];
  22336. vertices = vertices.concat( ahole );
  22337. }
  22338. function scalePt2 ( pt, vec, size ) {
  22339. if ( ! vec ) console.error( "THREE.ExtrudeGeometry: vec does not exist" );
  22340. return vec.clone().multiplyScalar( size ).add( pt );
  22341. }
  22342. var b, bs, t, z,
  22343. vert, vlen = vertices.length,
  22344. face, flen = faces.length;
  22345. // Find directions for point movement
  22346. function getBevelVec( inPt, inPrev, inNext ) {
  22347. // computes for inPt the corresponding point inPt' on a new contour
  22348. // shifted by 1 unit (length of normalized vector) to the left
  22349. // if we walk along contour clockwise, this new contour is outside the old one
  22350. //
  22351. // inPt' is the intersection of the two lines parallel to the two
  22352. // adjacent edges of inPt at a distance of 1 unit on the left side.
  22353. var v_trans_x, v_trans_y, shrink_by = 1; // resulting translation vector for inPt
  22354. // good reading for geometry algorithms (here: line-line intersection)
  22355. // http://geomalgorithms.com/a05-_intersect-1.html
  22356. var v_prev_x = inPt.x - inPrev.x, v_prev_y = inPt.y - inPrev.y;
  22357. var v_next_x = inNext.x - inPt.x, v_next_y = inNext.y - inPt.y;
  22358. var v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  22359. // check for collinear edges
  22360. var collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  22361. if ( Math.abs( collinear0 ) > Number.EPSILON ) {
  22362. // not collinear
  22363. // length of vectors for normalizing
  22364. var v_prev_len = Math.sqrt( v_prev_lensq );
  22365. var v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  22366. // shift adjacent points by unit vectors to the left
  22367. var ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  22368. var ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  22369. var ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  22370. var ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  22371. // scaling factor for v_prev to intersection point
  22372. var sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  22373. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  22374. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  22375. // vector from inPt to intersection point
  22376. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  22377. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  22378. // Don't normalize!, otherwise sharp corners become ugly
  22379. // but prevent crazy spikes
  22380. var v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  22381. if ( v_trans_lensq <= 2 ) {
  22382. return new THREE.Vector2( v_trans_x, v_trans_y );
  22383. } else {
  22384. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  22385. }
  22386. } else {
  22387. // handle special case of collinear edges
  22388. var direction_eq = false; // assumes: opposite
  22389. if ( v_prev_x > Number.EPSILON ) {
  22390. if ( v_next_x > Number.EPSILON ) {
  22391. direction_eq = true;
  22392. }
  22393. } else {
  22394. if ( v_prev_x < - Number.EPSILON ) {
  22395. if ( v_next_x < - Number.EPSILON ) {
  22396. direction_eq = true;
  22397. }
  22398. } else {
  22399. if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
  22400. direction_eq = true;
  22401. }
  22402. }
  22403. }
  22404. if ( direction_eq ) {
  22405. // console.log("Warning: lines are a straight sequence");
  22406. v_trans_x = - v_prev_y;
  22407. v_trans_y = v_prev_x;
  22408. shrink_by = Math.sqrt( v_prev_lensq );
  22409. } else {
  22410. // console.log("Warning: lines are a straight spike");
  22411. v_trans_x = v_prev_x;
  22412. v_trans_y = v_prev_y;
  22413. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  22414. }
  22415. }
  22416. return new THREE.Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  22417. }
  22418. var contourMovements = [];
  22419. for ( var i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  22420. if ( j === il ) j = 0;
  22421. if ( k === il ) k = 0;
  22422. // (j)---(i)---(k)
  22423. // console.log('i,j,k', i, j , k)
  22424. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  22425. }
  22426. var holesMovements = [], oneHoleMovements, verticesMovements = contourMovements.concat();
  22427. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  22428. ahole = holes[ h ];
  22429. oneHoleMovements = [];
  22430. for ( i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  22431. if ( j === il ) j = 0;
  22432. if ( k === il ) k = 0;
  22433. // (j)---(i)---(k)
  22434. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  22435. }
  22436. holesMovements.push( oneHoleMovements );
  22437. verticesMovements = verticesMovements.concat( oneHoleMovements );
  22438. }
  22439. // Loop bevelSegments, 1 for the front, 1 for the back
  22440. for ( b = 0; b < bevelSegments; b ++ ) {
  22441. //for ( b = bevelSegments; b > 0; b -- ) {
  22442. t = b / bevelSegments;
  22443. z = bevelThickness * ( 1 - t );
  22444. //z = bevelThickness * t;
  22445. bs = bevelSize * ( Math.sin ( t * Math.PI / 2 ) ); // curved
  22446. //bs = bevelSize * t; // linear
  22447. // contract shape
  22448. for ( i = 0, il = contour.length; i < il; i ++ ) {
  22449. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  22450. v( vert.x, vert.y, - z );
  22451. }
  22452. // expand holes
  22453. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  22454. ahole = holes[ h ];
  22455. oneHoleMovements = holesMovements[ h ];
  22456. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  22457. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  22458. v( vert.x, vert.y, - z );
  22459. }
  22460. }
  22461. }
  22462. bs = bevelSize;
  22463. // Back facing vertices
  22464. for ( i = 0; i < vlen; i ++ ) {
  22465. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  22466. if ( ! extrudeByPath ) {
  22467. v( vert.x, vert.y, 0 );
  22468. } else {
  22469. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  22470. normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x );
  22471. binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y );
  22472. position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
  22473. v( position2.x, position2.y, position2.z );
  22474. }
  22475. }
  22476. // Add stepped vertices...
  22477. // Including front facing vertices
  22478. var s;
  22479. for ( s = 1; s <= steps; s ++ ) {
  22480. for ( i = 0; i < vlen; i ++ ) {
  22481. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  22482. if ( ! extrudeByPath ) {
  22483. v( vert.x, vert.y, amount / steps * s );
  22484. } else {
  22485. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  22486. normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x );
  22487. binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y );
  22488. position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
  22489. v( position2.x, position2.y, position2.z );
  22490. }
  22491. }
  22492. }
  22493. // Add bevel segments planes
  22494. //for ( b = 1; b <= bevelSegments; b ++ ) {
  22495. for ( b = bevelSegments - 1; b >= 0; b -- ) {
  22496. t = b / bevelSegments;
  22497. z = bevelThickness * ( 1 - t );
  22498. //bs = bevelSize * ( 1-Math.sin ( ( 1 - t ) * Math.PI/2 ) );
  22499. bs = bevelSize * Math.sin ( t * Math.PI / 2 );
  22500. // contract shape
  22501. for ( i = 0, il = contour.length; i < il; i ++ ) {
  22502. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  22503. v( vert.x, vert.y, amount + z );
  22504. }
  22505. // expand holes
  22506. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  22507. ahole = holes[ h ];
  22508. oneHoleMovements = holesMovements[ h ];
  22509. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  22510. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  22511. if ( ! extrudeByPath ) {
  22512. v( vert.x, vert.y, amount + z );
  22513. } else {
  22514. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  22515. }
  22516. }
  22517. }
  22518. }
  22519. /* Faces */
  22520. // Top and bottom faces
  22521. buildLidFaces();
  22522. // Sides faces
  22523. buildSideFaces();
  22524. ///// Internal functions
  22525. function buildLidFaces() {
  22526. if ( bevelEnabled ) {
  22527. var layer = 0; // steps + 1
  22528. var offset = vlen * layer;
  22529. // Bottom faces
  22530. for ( i = 0; i < flen; i ++ ) {
  22531. face = faces[ i ];
  22532. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  22533. }
  22534. layer = steps + bevelSegments * 2;
  22535. offset = vlen * layer;
  22536. // Top faces
  22537. for ( i = 0; i < flen; i ++ ) {
  22538. face = faces[ i ];
  22539. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  22540. }
  22541. } else {
  22542. // Bottom faces
  22543. for ( i = 0; i < flen; i ++ ) {
  22544. face = faces[ i ];
  22545. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  22546. }
  22547. // Top faces
  22548. for ( i = 0; i < flen; i ++ ) {
  22549. face = faces[ i ];
  22550. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  22551. }
  22552. }
  22553. }
  22554. // Create faces for the z-sides of the shape
  22555. function buildSideFaces() {
  22556. var layeroffset = 0;
  22557. sidewalls( contour, layeroffset );
  22558. layeroffset += contour.length;
  22559. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  22560. ahole = holes[ h ];
  22561. sidewalls( ahole, layeroffset );
  22562. //, true
  22563. layeroffset += ahole.length;
  22564. }
  22565. }
  22566. function sidewalls( contour, layeroffset ) {
  22567. var j, k;
  22568. i = contour.length;
  22569. while ( -- i >= 0 ) {
  22570. j = i;
  22571. k = i - 1;
  22572. if ( k < 0 ) k = contour.length - 1;
  22573. //console.log('b', i,j, i-1, k,vertices.length);
  22574. var s = 0, sl = steps + bevelSegments * 2;
  22575. for ( s = 0; s < sl; s ++ ) {
  22576. var slen1 = vlen * s;
  22577. var slen2 = vlen * ( s + 1 );
  22578. var a = layeroffset + j + slen1,
  22579. b = layeroffset + k + slen1,
  22580. c = layeroffset + k + slen2,
  22581. d = layeroffset + j + slen2;
  22582. f4( a, b, c, d, contour, s, sl, j, k );
  22583. }
  22584. }
  22585. }
  22586. function v( x, y, z ) {
  22587. scope.vertices.push( new THREE.Vector3( x, y, z ) );
  22588. }
  22589. function f3( a, b, c ) {
  22590. a += shapesOffset;
  22591. b += shapesOffset;
  22592. c += shapesOffset;
  22593. scope.faces.push( new THREE.Face3( a, b, c, null, null, 0 ) );
  22594. var uvs = uvgen.generateTopUV( scope, a, b, c );
  22595. scope.faceVertexUvs[ 0 ].push( uvs );
  22596. }
  22597. function f4( a, b, c, d, wallContour, stepIndex, stepsLength, contourIndex1, contourIndex2 ) {
  22598. a += shapesOffset;
  22599. b += shapesOffset;
  22600. c += shapesOffset;
  22601. d += shapesOffset;
  22602. scope.faces.push( new THREE.Face3( a, b, d, null, null, 1 ) );
  22603. scope.faces.push( new THREE.Face3( b, c, d, null, null, 1 ) );
  22604. var uvs = uvgen.generateSideWallUV( scope, a, b, c, d );
  22605. scope.faceVertexUvs[ 0 ].push( [ uvs[ 0 ], uvs[ 1 ], uvs[ 3 ] ] );
  22606. scope.faceVertexUvs[ 0 ].push( [ uvs[ 1 ], uvs[ 2 ], uvs[ 3 ] ] );
  22607. }
  22608. };
  22609. THREE.ExtrudeGeometry.WorldUVGenerator = {
  22610. generateTopUV: function ( geometry, indexA, indexB, indexC ) {
  22611. var vertices = geometry.vertices;
  22612. var a = vertices[ indexA ];
  22613. var b = vertices[ indexB ];
  22614. var c = vertices[ indexC ];
  22615. return [
  22616. new THREE.Vector2( a.x, a.y ),
  22617. new THREE.Vector2( b.x, b.y ),
  22618. new THREE.Vector2( c.x, c.y )
  22619. ];
  22620. },
  22621. generateSideWallUV: function ( geometry, indexA, indexB, indexC, indexD ) {
  22622. var vertices = geometry.vertices;
  22623. var a = vertices[ indexA ];
  22624. var b = vertices[ indexB ];
  22625. var c = vertices[ indexC ];
  22626. var d = vertices[ indexD ];
  22627. if ( Math.abs( a.y - b.y ) < 0.01 ) {
  22628. return [
  22629. new THREE.Vector2( a.x, 1 - a.z ),
  22630. new THREE.Vector2( b.x, 1 - b.z ),
  22631. new THREE.Vector2( c.x, 1 - c.z ),
  22632. new THREE.Vector2( d.x, 1 - d.z )
  22633. ];
  22634. } else {
  22635. return [
  22636. new THREE.Vector2( a.y, 1 - a.z ),
  22637. new THREE.Vector2( b.y, 1 - b.z ),
  22638. new THREE.Vector2( c.y, 1 - c.z ),
  22639. new THREE.Vector2( d.y, 1 - d.z )
  22640. ];
  22641. }
  22642. }
  22643. };
  22644. // File:src/extras/geometries/ShapeGeometry.js
  22645. /**
  22646. * @author jonobr1 / http://jonobr1.com
  22647. *
  22648. * Creates a one-sided polygonal geometry from a path shape. Similar to
  22649. * ExtrudeGeometry.
  22650. *
  22651. * parameters = {
  22652. *
  22653. * curveSegments: <int>, // number of points on the curves. NOT USED AT THE MOMENT.
  22654. *
  22655. * material: <int> // material index for front and back faces
  22656. * uvGenerator: <Object> // object that provides UV generator functions
  22657. *
  22658. * }
  22659. **/
  22660. THREE.ShapeGeometry = function ( shapes, options ) {
  22661. THREE.Geometry.call( this );
  22662. this.type = 'ShapeGeometry';
  22663. if ( Array.isArray( shapes ) === false ) shapes = [ shapes ];
  22664. this.addShapeList( shapes, options );
  22665. this.computeFaceNormals();
  22666. };
  22667. THREE.ShapeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22668. THREE.ShapeGeometry.prototype.constructor = THREE.ShapeGeometry;
  22669. /**
  22670. * Add an array of shapes to THREE.ShapeGeometry.
  22671. */
  22672. THREE.ShapeGeometry.prototype.addShapeList = function ( shapes, options ) {
  22673. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  22674. this.addShape( shapes[ i ], options );
  22675. }
  22676. return this;
  22677. };
  22678. /**
  22679. * Adds a shape to THREE.ShapeGeometry, based on THREE.ExtrudeGeometry.
  22680. */
  22681. THREE.ShapeGeometry.prototype.addShape = function ( shape, options ) {
  22682. if ( options === undefined ) options = {};
  22683. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  22684. var material = options.material;
  22685. var uvgen = options.UVGenerator === undefined ? THREE.ExtrudeGeometry.WorldUVGenerator : options.UVGenerator;
  22686. //
  22687. var i, l, hole;
  22688. var shapesOffset = this.vertices.length;
  22689. var shapePoints = shape.extractPoints( curveSegments );
  22690. var vertices = shapePoints.shape;
  22691. var holes = shapePoints.holes;
  22692. var reverse = ! THREE.ShapeUtils.isClockWise( vertices );
  22693. if ( reverse ) {
  22694. vertices = vertices.reverse();
  22695. // Maybe we should also check if holes are in the opposite direction, just to be safe...
  22696. for ( i = 0, l = holes.length; i < l; i ++ ) {
  22697. hole = holes[ i ];
  22698. if ( THREE.ShapeUtils.isClockWise( hole ) ) {
  22699. holes[ i ] = hole.reverse();
  22700. }
  22701. }
  22702. reverse = false;
  22703. }
  22704. var faces = THREE.ShapeUtils.triangulateShape( vertices, holes );
  22705. // Vertices
  22706. for ( i = 0, l = holes.length; i < l; i ++ ) {
  22707. hole = holes[ i ];
  22708. vertices = vertices.concat( hole );
  22709. }
  22710. //
  22711. var vert, vlen = vertices.length;
  22712. var face, flen = faces.length;
  22713. for ( i = 0; i < vlen; i ++ ) {
  22714. vert = vertices[ i ];
  22715. this.vertices.push( new THREE.Vector3( vert.x, vert.y, 0 ) );
  22716. }
  22717. for ( i = 0; i < flen; i ++ ) {
  22718. face = faces[ i ];
  22719. var a = face[ 0 ] + shapesOffset;
  22720. var b = face[ 1 ] + shapesOffset;
  22721. var c = face[ 2 ] + shapesOffset;
  22722. this.faces.push( new THREE.Face3( a, b, c, null, null, material ) );
  22723. this.faceVertexUvs[ 0 ].push( uvgen.generateTopUV( this, a, b, c ) );
  22724. }
  22725. };
  22726. // File:src/extras/geometries/LatheBufferGeometry.js
  22727. /**
  22728. * @author Mugen87 / https://github.com/Mugen87
  22729. */
  22730. // points - to create a closed torus, one must use a set of points
  22731. // like so: [ a, b, c, d, a ], see first is the same as last.
  22732. // segments - the number of circumference segments to create
  22733. // phiStart - the starting radian
  22734. // phiLength - the radian (0 to 2PI) range of the lathed section
  22735. // 2PI is a closed lathe, less than 2PI is a portion.
  22736. THREE.LatheBufferGeometry = function ( points, segments, phiStart, phiLength ) {
  22737. THREE.BufferGeometry.call( this );
  22738. this.type = 'LatheBufferGeometry';
  22739. this.parameters = {
  22740. points: points,
  22741. segments: segments,
  22742. phiStart: phiStart,
  22743. phiLength: phiLength
  22744. };
  22745. segments = Math.floor( segments ) || 12;
  22746. phiStart = phiStart || 0;
  22747. phiLength = phiLength || Math.PI * 2;
  22748. // clamp phiLength so it's in range of [ 0, 2PI ]
  22749. phiLength = THREE.Math.clamp( phiLength, 0, Math.PI * 2 );
  22750. // these are used to calculate buffer length
  22751. var vertexCount = ( segments + 1 ) * points.length;
  22752. var indexCount = segments * points.length * 2 * 3;
  22753. // buffers
  22754. var indices = new THREE.BufferAttribute( new ( indexCount > 65535 ? Uint32Array : Uint16Array )( indexCount ) , 1 );
  22755. var vertices = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  22756. var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
  22757. // helper variables
  22758. var index = 0, indexOffset = 0, base;
  22759. var inversePointLength = 1.0 / ( points.length - 1 );
  22760. var inverseSegments = 1.0 / segments;
  22761. var vertex = new THREE.Vector3();
  22762. var uv = new THREE.Vector2();
  22763. var i, j;
  22764. // generate vertices and uvs
  22765. for ( i = 0; i <= segments; i ++ ) {
  22766. var phi = phiStart + i * inverseSegments * phiLength;
  22767. var sin = Math.sin( phi );
  22768. var cos = Math.cos( phi );
  22769. for ( j = 0; j <= ( points.length - 1 ); j ++ ) {
  22770. // vertex
  22771. vertex.x = points[ j ].x * sin;
  22772. vertex.y = points[ j ].y;
  22773. vertex.z = points[ j ].x * cos;
  22774. vertices.setXYZ( index, vertex.x, vertex.y, vertex.z );
  22775. // uv
  22776. uv.x = i / segments;
  22777. uv.y = j / ( points.length - 1 );
  22778. uvs.setXY( index, uv.x, uv.y );
  22779. // increase index
  22780. index ++;
  22781. }
  22782. }
  22783. // generate indices
  22784. for ( i = 0; i < segments; i ++ ) {
  22785. for ( j = 0; j < ( points.length - 1 ); j ++ ) {
  22786. base = j + i * points.length;
  22787. // indices
  22788. var a = base;
  22789. var b = base + points.length;
  22790. var c = base + points.length + 1;
  22791. var d = base + 1;
  22792. // face one
  22793. indices.setX( indexOffset, a ); indexOffset++;
  22794. indices.setX( indexOffset, b ); indexOffset++;
  22795. indices.setX( indexOffset, d ); indexOffset++;
  22796. // face two
  22797. indices.setX( indexOffset, b ); indexOffset++;
  22798. indices.setX( indexOffset, c ); indexOffset++;
  22799. indices.setX( indexOffset, d ); indexOffset++;
  22800. }
  22801. }
  22802. // build geometry
  22803. this.setIndex( indices );
  22804. this.addAttribute( 'position', vertices );
  22805. this.addAttribute( 'uv', uvs );
  22806. // generate normals
  22807. this.computeVertexNormals();
  22808. // if the geometry is closed, we need to average the normals along the seam.
  22809. // because the corresponding vertices are identical (but still have different UVs).
  22810. if( phiLength === Math.PI * 2 ) {
  22811. var normals = this.attributes.normal.array;
  22812. var n1 = new THREE.Vector3();
  22813. var n2 = new THREE.Vector3();
  22814. var n = new THREE.Vector3();
  22815. // this is the buffer offset for the last line of vertices
  22816. base = segments * points.length * 3;
  22817. for( i = 0, j = 0; i < points.length; i ++, j += 3 ) {
  22818. // select the normal of the vertex in the first line
  22819. n1.x = normals[ j + 0 ];
  22820. n1.y = normals[ j + 1 ];
  22821. n1.z = normals[ j + 2 ];
  22822. // select the normal of the vertex in the last line
  22823. n2.x = normals[ base + j + 0 ];
  22824. n2.y = normals[ base + j + 1 ];
  22825. n2.z = normals[ base + j + 2 ];
  22826. // average normals
  22827. n.addVectors( n1, n2 ).normalize();
  22828. // assign the new values to both normals
  22829. normals[ j + 0 ] = normals[ base + j + 0 ] = n.x;
  22830. normals[ j + 1 ] = normals[ base + j + 1 ] = n.y;
  22831. normals[ j + 2 ] = normals[ base + j + 2 ] = n.z;
  22832. } // next row
  22833. }
  22834. };
  22835. THREE.LatheBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  22836. THREE.LatheBufferGeometry.prototype.constructor = THREE.LatheBufferGeometry;
  22837. // File:src/extras/geometries/LatheGeometry.js
  22838. /**
  22839. * @author astrodud / http://astrodud.isgreat.org/
  22840. * @author zz85 / https://github.com/zz85
  22841. * @author bhouston / http://clara.io
  22842. */
  22843. // points - to create a closed torus, one must use a set of points
  22844. // like so: [ a, b, c, d, a ], see first is the same as last.
  22845. // segments - the number of circumference segments to create
  22846. // phiStart - the starting radian
  22847. // phiLength - the radian (0 to 2PI) range of the lathed section
  22848. // 2PI is a closed lathe, less than 2PI is a portion.
  22849. THREE.LatheGeometry = function ( points, segments, phiStart, phiLength ) {
  22850. THREE.Geometry.call( this );
  22851. this.type = 'LatheGeometry';
  22852. this.parameters = {
  22853. points: points,
  22854. segments: segments,
  22855. phiStart: phiStart,
  22856. phiLength: phiLength
  22857. };
  22858. this.fromBufferGeometry( new THREE.LatheBufferGeometry( points, segments, phiStart, phiLength ) );
  22859. this.mergeVertices();
  22860. };
  22861. THREE.LatheGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22862. THREE.LatheGeometry.prototype.constructor = THREE.LatheGeometry;
  22863. // File:src/extras/geometries/PlaneGeometry.js
  22864. /**
  22865. * @author mrdoob / http://mrdoob.com/
  22866. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
  22867. */
  22868. THREE.PlaneGeometry = function ( width, height, widthSegments, heightSegments ) {
  22869. THREE.Geometry.call( this );
  22870. this.type = 'PlaneGeometry';
  22871. this.parameters = {
  22872. width: width,
  22873. height: height,
  22874. widthSegments: widthSegments,
  22875. heightSegments: heightSegments
  22876. };
  22877. this.fromBufferGeometry( new THREE.PlaneBufferGeometry( width, height, widthSegments, heightSegments ) );
  22878. };
  22879. THREE.PlaneGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22880. THREE.PlaneGeometry.prototype.constructor = THREE.PlaneGeometry;
  22881. // File:src/extras/geometries/PlaneBufferGeometry.js
  22882. /**
  22883. * @author mrdoob / http://mrdoob.com/
  22884. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
  22885. */
  22886. THREE.PlaneBufferGeometry = function ( width, height, widthSegments, heightSegments ) {
  22887. THREE.BufferGeometry.call( this );
  22888. this.type = 'PlaneBufferGeometry';
  22889. this.parameters = {
  22890. width: width,
  22891. height: height,
  22892. widthSegments: widthSegments,
  22893. heightSegments: heightSegments
  22894. };
  22895. var width_half = width / 2;
  22896. var height_half = height / 2;
  22897. var gridX = Math.floor( widthSegments ) || 1;
  22898. var gridY = Math.floor( heightSegments ) || 1;
  22899. var gridX1 = gridX + 1;
  22900. var gridY1 = gridY + 1;
  22901. var segment_width = width / gridX;
  22902. var segment_height = height / gridY;
  22903. var vertices = new Float32Array( gridX1 * gridY1 * 3 );
  22904. var normals = new Float32Array( gridX1 * gridY1 * 3 );
  22905. var uvs = new Float32Array( gridX1 * gridY1 * 2 );
  22906. var offset = 0;
  22907. var offset2 = 0;
  22908. for ( var iy = 0; iy < gridY1; iy ++ ) {
  22909. var y = iy * segment_height - height_half;
  22910. for ( var ix = 0; ix < gridX1; ix ++ ) {
  22911. var x = ix * segment_width - width_half;
  22912. vertices[ offset ] = x;
  22913. vertices[ offset + 1 ] = - y;
  22914. normals[ offset + 2 ] = 1;
  22915. uvs[ offset2 ] = ix / gridX;
  22916. uvs[ offset2 + 1 ] = 1 - ( iy / gridY );
  22917. offset += 3;
  22918. offset2 += 2;
  22919. }
  22920. }
  22921. offset = 0;
  22922. var indices = new ( ( vertices.length / 3 ) > 65535 ? Uint32Array : Uint16Array )( gridX * gridY * 6 );
  22923. for ( var iy = 0; iy < gridY; iy ++ ) {
  22924. for ( var ix = 0; ix < gridX; ix ++ ) {
  22925. var a = ix + gridX1 * iy;
  22926. var b = ix + gridX1 * ( iy + 1 );
  22927. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  22928. var d = ( ix + 1 ) + gridX1 * iy;
  22929. indices[ offset ] = a;
  22930. indices[ offset + 1 ] = b;
  22931. indices[ offset + 2 ] = d;
  22932. indices[ offset + 3 ] = b;
  22933. indices[ offset + 4 ] = c;
  22934. indices[ offset + 5 ] = d;
  22935. offset += 6;
  22936. }
  22937. }
  22938. this.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  22939. this.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  22940. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  22941. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  22942. };
  22943. THREE.PlaneBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  22944. THREE.PlaneBufferGeometry.prototype.constructor = THREE.PlaneBufferGeometry;
  22945. // File:src/extras/geometries/RingBufferGeometry.js
  22946. /**
  22947. * @author Mugen87 / https://github.com/Mugen87
  22948. */
  22949. THREE.RingBufferGeometry = function ( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  22950. THREE.BufferGeometry.call( this );
  22951. this.type = 'RingBufferGeometry';
  22952. this.parameters = {
  22953. innerRadius: innerRadius,
  22954. outerRadius: outerRadius,
  22955. thetaSegments: thetaSegments,
  22956. phiSegments: phiSegments,
  22957. thetaStart: thetaStart,
  22958. thetaLength: thetaLength
  22959. };
  22960. innerRadius = innerRadius || 20;
  22961. outerRadius = outerRadius || 50;
  22962. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  22963. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  22964. thetaSegments = thetaSegments !== undefined ? Math.max( 3, thetaSegments ) : 8;
  22965. phiSegments = phiSegments !== undefined ? Math.max( 1, phiSegments ) : 1;
  22966. // these are used to calculate buffer length
  22967. var vertexCount = ( thetaSegments + 1 ) * ( phiSegments + 1 );
  22968. var indexCount = thetaSegments * phiSegments * 2 * 3;
  22969. // buffers
  22970. var indices = new THREE.BufferAttribute( new ( indexCount > 65535 ? Uint32Array : Uint16Array )( indexCount ) , 1 );
  22971. var vertices = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  22972. var normals = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  22973. var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
  22974. // some helper variables
  22975. var index = 0, indexOffset = 0, segment;
  22976. var radius = innerRadius;
  22977. var radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  22978. var vertex = new THREE.Vector3();
  22979. var uv = new THREE.Vector2();
  22980. var j, i;
  22981. // generate vertices, normals and uvs
  22982. // values are generate from the inside of the ring to the outside
  22983. for ( j = 0; j <= phiSegments; j ++ ) {
  22984. for ( i = 0; i <= thetaSegments; i ++ ) {
  22985. segment = thetaStart + i / thetaSegments * thetaLength;
  22986. // vertex
  22987. vertex.x = radius * Math.cos( segment );
  22988. vertex.y = radius * Math.sin( segment );
  22989. vertices.setXYZ( index, vertex.x, vertex.y, vertex.z );
  22990. // normal
  22991. normals.setXYZ( index, 0, 0, 1 );
  22992. // uv
  22993. uv.x = ( vertex.x / outerRadius + 1 ) / 2;
  22994. uv.y = ( vertex.y / outerRadius + 1 ) / 2;
  22995. uvs.setXY( index, uv.x, uv.y );
  22996. // increase index
  22997. index++;
  22998. }
  22999. // increase the radius for next row of vertices
  23000. radius += radiusStep;
  23001. }
  23002. // generate indices
  23003. for ( j = 0; j < phiSegments; j ++ ) {
  23004. var thetaSegmentLevel = j * ( thetaSegments + 1 );
  23005. for ( i = 0; i < thetaSegments; i ++ ) {
  23006. segment = i + thetaSegmentLevel;
  23007. // indices
  23008. var a = segment;
  23009. var b = segment + thetaSegments + 1;
  23010. var c = segment + thetaSegments + 2;
  23011. var d = segment + 1;
  23012. // face one
  23013. indices.setX( indexOffset, a ); indexOffset++;
  23014. indices.setX( indexOffset, b ); indexOffset++;
  23015. indices.setX( indexOffset, c ); indexOffset++;
  23016. // face two
  23017. indices.setX( indexOffset, a ); indexOffset++;
  23018. indices.setX( indexOffset, c ); indexOffset++;
  23019. indices.setX( indexOffset, d ); indexOffset++;
  23020. }
  23021. }
  23022. // build geometry
  23023. this.setIndex( indices );
  23024. this.addAttribute( 'position', vertices );
  23025. this.addAttribute( 'normal', normals );
  23026. this.addAttribute( 'uv', uvs );
  23027. };
  23028. THREE.RingBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  23029. THREE.RingBufferGeometry.prototype.constructor = THREE.RingBufferGeometry;
  23030. // File:src/extras/geometries/RingGeometry.js
  23031. /**
  23032. * @author Kaleb Murphy
  23033. */
  23034. THREE.RingGeometry = function ( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  23035. THREE.Geometry.call( this );
  23036. this.type = 'RingGeometry';
  23037. this.parameters = {
  23038. innerRadius: innerRadius,
  23039. outerRadius: outerRadius,
  23040. thetaSegments: thetaSegments,
  23041. phiSegments: phiSegments,
  23042. thetaStart: thetaStart,
  23043. thetaLength: thetaLength
  23044. };
  23045. this.fromBufferGeometry( new THREE.RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) );
  23046. };
  23047. THREE.RingGeometry.prototype = Object.create( THREE.Geometry.prototype );
  23048. THREE.RingGeometry.prototype.constructor = THREE.RingGeometry;
  23049. // File:src/extras/geometries/SphereGeometry.js
  23050. /**
  23051. * @author mrdoob / http://mrdoob.com/
  23052. */
  23053. THREE.SphereGeometry = function ( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  23054. THREE.Geometry.call( this );
  23055. this.type = 'SphereGeometry';
  23056. this.parameters = {
  23057. radius: radius,
  23058. widthSegments: widthSegments,
  23059. heightSegments: heightSegments,
  23060. phiStart: phiStart,
  23061. phiLength: phiLength,
  23062. thetaStart: thetaStart,
  23063. thetaLength: thetaLength
  23064. };
  23065. this.fromBufferGeometry( new THREE.SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) );
  23066. };
  23067. THREE.SphereGeometry.prototype = Object.create( THREE.Geometry.prototype );
  23068. THREE.SphereGeometry.prototype.constructor = THREE.SphereGeometry;
  23069. // File:src/extras/geometries/SphereBufferGeometry.js
  23070. /**
  23071. * @author benaadams / https://twitter.com/ben_a_adams
  23072. * based on THREE.SphereGeometry
  23073. */
  23074. THREE.SphereBufferGeometry = function ( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  23075. THREE.BufferGeometry.call( this );
  23076. this.type = 'SphereBufferGeometry';
  23077. this.parameters = {
  23078. radius: radius,
  23079. widthSegments: widthSegments,
  23080. heightSegments: heightSegments,
  23081. phiStart: phiStart,
  23082. phiLength: phiLength,
  23083. thetaStart: thetaStart,
  23084. thetaLength: thetaLength
  23085. };
  23086. radius = radius || 50;
  23087. widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
  23088. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  23089. phiStart = phiStart !== undefined ? phiStart : 0;
  23090. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  23091. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  23092. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  23093. var thetaEnd = thetaStart + thetaLength;
  23094. var vertexCount = ( ( widthSegments + 1 ) * ( heightSegments + 1 ) );
  23095. var positions = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  23096. var normals = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  23097. var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
  23098. var index = 0, vertices = [], normal = new THREE.Vector3();
  23099. for ( var y = 0; y <= heightSegments; y ++ ) {
  23100. var verticesRow = [];
  23101. var v = y / heightSegments;
  23102. for ( var x = 0; x <= widthSegments; x ++ ) {
  23103. var u = x / widthSegments;
  23104. var px = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  23105. var py = radius * Math.cos( thetaStart + v * thetaLength );
  23106. var pz = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  23107. normal.set( px, py, pz ).normalize();
  23108. positions.setXYZ( index, px, py, pz );
  23109. normals.setXYZ( index, normal.x, normal.y, normal.z );
  23110. uvs.setXY( index, u, 1 - v );
  23111. verticesRow.push( index );
  23112. index ++;
  23113. }
  23114. vertices.push( verticesRow );
  23115. }
  23116. var indices = [];
  23117. for ( var y = 0; y < heightSegments; y ++ ) {
  23118. for ( var x = 0; x < widthSegments; x ++ ) {
  23119. var v1 = vertices[ y ][ x + 1 ];
  23120. var v2 = vertices[ y ][ x ];
  23121. var v3 = vertices[ y + 1 ][ x ];
  23122. var v4 = vertices[ y + 1 ][ x + 1 ];
  23123. if ( y !== 0 || thetaStart > 0 ) indices.push( v1, v2, v4 );
  23124. if ( y !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( v2, v3, v4 );
  23125. }
  23126. }
  23127. this.setIndex( new ( positions.count > 65535 ? THREE.Uint32Attribute : THREE.Uint16Attribute )( indices, 1 ) );
  23128. this.addAttribute( 'position', positions );
  23129. this.addAttribute( 'normal', normals );
  23130. this.addAttribute( 'uv', uvs );
  23131. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  23132. };
  23133. THREE.SphereBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  23134. THREE.SphereBufferGeometry.prototype.constructor = THREE.SphereBufferGeometry;
  23135. // File:src/extras/geometries/TextGeometry.js
  23136. /**
  23137. * @author zz85 / http://www.lab4games.net/zz85/blog
  23138. * @author alteredq / http://alteredqualia.com/
  23139. *
  23140. * Text = 3D Text
  23141. *
  23142. * parameters = {
  23143. * font: <THREE.Font>, // font
  23144. *
  23145. * size: <float>, // size of the text
  23146. * height: <float>, // thickness to extrude text
  23147. * curveSegments: <int>, // number of points on the curves
  23148. *
  23149. * bevelEnabled: <bool>, // turn on bevel
  23150. * bevelThickness: <float>, // how deep into text bevel goes
  23151. * bevelSize: <float> // how far from text outline is bevel
  23152. * }
  23153. */
  23154. THREE.TextGeometry = function ( text, parameters ) {
  23155. parameters = parameters || {};
  23156. var font = parameters.font;
  23157. if ( font instanceof THREE.Font === false ) {
  23158. console.error( 'THREE.TextGeometry: font parameter is not an instance of THREE.Font.' );
  23159. return new THREE.Geometry();
  23160. }
  23161. var shapes = font.generateShapes( text, parameters.size, parameters.curveSegments );
  23162. // translate parameters to ExtrudeGeometry API
  23163. parameters.amount = parameters.height !== undefined ? parameters.height : 50;
  23164. // defaults
  23165. if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
  23166. if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
  23167. if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
  23168. THREE.ExtrudeGeometry.call( this, shapes, parameters );
  23169. this.type = 'TextGeometry';
  23170. };
  23171. THREE.TextGeometry.prototype = Object.create( THREE.ExtrudeGeometry.prototype );
  23172. THREE.TextGeometry.prototype.constructor = THREE.TextGeometry;
  23173. // File:src/extras/geometries/TorusBufferGeometry.js
  23174. /**
  23175. * @author Mugen87 / https://github.com/Mugen87
  23176. */
  23177. THREE.TorusBufferGeometry = function ( radius, tube, radialSegments, tubularSegments, arc ) {
  23178. THREE.BufferGeometry.call( this );
  23179. this.type = 'TorusBufferGeometry';
  23180. this.parameters = {
  23181. radius: radius,
  23182. tube: tube,
  23183. radialSegments: radialSegments,
  23184. tubularSegments: tubularSegments,
  23185. arc: arc
  23186. };
  23187. radius = radius || 100;
  23188. tube = tube || 40;
  23189. radialSegments = Math.floor( radialSegments ) || 8;
  23190. tubularSegments = Math.floor( tubularSegments ) || 6;
  23191. arc = arc || Math.PI * 2;
  23192. // used to calculate buffer length
  23193. var vertexCount = ( ( radialSegments + 1 ) * ( tubularSegments + 1 ) );
  23194. var indexCount = radialSegments * tubularSegments * 2 * 3;
  23195. // buffers
  23196. var indices = new ( indexCount > 65535 ? Uint32Array : Uint16Array )( indexCount );
  23197. var vertices = new Float32Array( vertexCount * 3 );
  23198. var normals = new Float32Array( vertexCount * 3 );
  23199. var uvs = new Float32Array( vertexCount * 2 );
  23200. // offset variables
  23201. var vertexBufferOffset = 0;
  23202. var uvBufferOffset = 0;
  23203. var indexBufferOffset = 0;
  23204. // helper variables
  23205. var center = new THREE.Vector3();
  23206. var vertex = new THREE.Vector3();
  23207. var normal = new THREE.Vector3();
  23208. var j, i;
  23209. // generate vertices, normals and uvs
  23210. for ( j = 0; j <= radialSegments; j ++ ) {
  23211. for ( i = 0; i <= tubularSegments; i ++ ) {
  23212. var u = i / tubularSegments * arc;
  23213. var v = j / radialSegments * Math.PI * 2;
  23214. // vertex
  23215. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  23216. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  23217. vertex.z = tube * Math.sin( v );
  23218. vertices[ vertexBufferOffset ] = vertex.x;
  23219. vertices[ vertexBufferOffset + 1 ] = vertex.y;
  23220. vertices[ vertexBufferOffset + 2 ] = vertex.z;
  23221. // this vector is used to calculate the normal
  23222. center.x = radius * Math.cos( u );
  23223. center.y = radius * Math.sin( u );
  23224. // normal
  23225. normal.subVectors( vertex, center ).normalize();
  23226. normals[ vertexBufferOffset ] = normal.x;
  23227. normals[ vertexBufferOffset + 1 ] = normal.y;
  23228. normals[ vertexBufferOffset + 2 ] = normal.z;
  23229. // uv
  23230. uvs[ uvBufferOffset ] = i / tubularSegments;
  23231. uvs[ uvBufferOffset + 1 ] = j / radialSegments;
  23232. // update offsets
  23233. vertexBufferOffset += 3;
  23234. uvBufferOffset += 2;
  23235. }
  23236. }
  23237. // generate indices
  23238. for ( j = 1; j <= radialSegments; j ++ ) {
  23239. for ( i = 1; i <= tubularSegments; i ++ ) {
  23240. // indices
  23241. var a = ( tubularSegments + 1 ) * j + i - 1;
  23242. var b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  23243. var c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  23244. var d = ( tubularSegments + 1 ) * j + i;
  23245. // face one
  23246. indices[ indexBufferOffset ] = a;
  23247. indices[ indexBufferOffset + 1 ] = b;
  23248. indices[ indexBufferOffset + 2 ] = d;
  23249. // face two
  23250. indices[ indexBufferOffset + 3 ] = b;
  23251. indices[ indexBufferOffset + 4 ] = c;
  23252. indices[ indexBufferOffset + 5 ] = d;
  23253. // update offset
  23254. indexBufferOffset += 6;
  23255. }
  23256. }
  23257. // build geometry
  23258. this.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  23259. this.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  23260. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  23261. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  23262. };
  23263. THREE.TorusBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  23264. THREE.TorusBufferGeometry.prototype.constructor = THREE.TorusBufferGeometry;
  23265. // File:src/extras/geometries/TorusGeometry.js
  23266. /**
  23267. * @author oosmoxiecode
  23268. * @author mrdoob / http://mrdoob.com/
  23269. * based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3DLite/src/away3dlite/primitives/Torus.as?r=2888
  23270. */
  23271. THREE.TorusGeometry = function ( radius, tube, radialSegments, tubularSegments, arc ) {
  23272. THREE.Geometry.call( this );
  23273. this.type = 'TorusGeometry';
  23274. this.parameters = {
  23275. radius: radius,
  23276. tube: tube,
  23277. radialSegments: radialSegments,
  23278. tubularSegments: tubularSegments,
  23279. arc: arc
  23280. };
  23281. this.fromBufferGeometry( new THREE.TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) );
  23282. };
  23283. THREE.TorusGeometry.prototype = Object.create( THREE.Geometry.prototype );
  23284. THREE.TorusGeometry.prototype.constructor = THREE.TorusGeometry;
  23285. // File:src/extras/geometries/TorusKnotBufferGeometry.js
  23286. /**
  23287. * @author Mugen87 / https://github.com/Mugen87
  23288. *
  23289. * see: http://www.blackpawn.com/texts/pqtorus/
  23290. */
  23291. THREE.TorusKnotBufferGeometry = function ( radius, tube, tubularSegments, radialSegments, p, q ) {
  23292. THREE.BufferGeometry.call( this );
  23293. this.type = 'TorusKnotBufferGeometry';
  23294. this.parameters = {
  23295. radius: radius,
  23296. tube: tube,
  23297. tubularSegments: tubularSegments,
  23298. radialSegments: radialSegments,
  23299. p: p,
  23300. q: q
  23301. };
  23302. radius = radius || 100;
  23303. tube = tube || 40;
  23304. tubularSegments = Math.floor( tubularSegments ) || 64;
  23305. radialSegments = Math.floor( radialSegments ) || 8;
  23306. p = p || 2;
  23307. q = q || 3;
  23308. // used to calculate buffer length
  23309. var vertexCount = ( ( radialSegments + 1 ) * ( tubularSegments + 1 ) );
  23310. var indexCount = radialSegments * tubularSegments * 2 * 3;
  23311. // buffers
  23312. var indices = new THREE.BufferAttribute( new ( indexCount > 65535 ? Uint32Array : Uint16Array )( indexCount ) , 1 );
  23313. var vertices = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  23314. var normals = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  23315. var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
  23316. // helper variables
  23317. var i, j, index = 0, indexOffset = 0;
  23318. var vertex = new THREE.Vector3();
  23319. var normal = new THREE.Vector3();
  23320. var uv = new THREE.Vector2();
  23321. var P1 = new THREE.Vector3();
  23322. var P2 = new THREE.Vector3();
  23323. var B = new THREE.Vector3();
  23324. var T = new THREE.Vector3();
  23325. var N = new THREE.Vector3();
  23326. // generate vertices, normals and uvs
  23327. for ( i = 0; i <= tubularSegments; ++ i ) {
  23328. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  23329. var u = i / tubularSegments * p * Math.PI * 2;
  23330. // now we calculate two points. P1 is our current position on the curve, P2 is a little farther ahead.
  23331. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  23332. calculatePositionOnCurve( u, p, q, radius, P1 );
  23333. calculatePositionOnCurve( u + 0.01, p, q, radius, P2 );
  23334. // calculate orthonormal basis
  23335. T.subVectors( P2, P1 );
  23336. N.addVectors( P2, P1 );
  23337. B.crossVectors( T, N );
  23338. N.crossVectors( B, T );
  23339. // normalize B, N. T can be ignored, we don't use it
  23340. B.normalize();
  23341. N.normalize();
  23342. for ( j = 0; j <= radialSegments; ++ j ) {
  23343. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  23344. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  23345. var v = j / radialSegments * Math.PI * 2;
  23346. var cx = - tube * Math.cos( v );
  23347. var cy = tube * Math.sin( v );
  23348. // now calculate the final vertex position.
  23349. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  23350. vertex.x = P1.x + ( cx * N.x + cy * B.x );
  23351. vertex.y = P1.y + ( cx * N.y + cy * B.y );
  23352. vertex.z = P1.z + ( cx * N.z + cy * B.z );
  23353. // vertex
  23354. vertices.setXYZ( index, vertex.x, vertex.y, vertex.z );
  23355. // normal (P1 is always the center/origin of the extrusion, thus we can use it to calculate the normal)
  23356. normal.subVectors( vertex, P1 ).normalize();
  23357. normals.setXYZ( index, normal.x, normal.y, normal.z );
  23358. // uv
  23359. uv.x = i / tubularSegments;
  23360. uv.y = j / radialSegments;
  23361. uvs.setXY( index, uv.x, uv.y );
  23362. // increase index
  23363. index ++;
  23364. }
  23365. }
  23366. // generate indices
  23367. for ( j = 1; j <= tubularSegments; j ++ ) {
  23368. for ( i = 1; i <= radialSegments; i ++ ) {
  23369. // indices
  23370. var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  23371. var b = ( radialSegments + 1 ) * j + ( i - 1 );
  23372. var c = ( radialSegments + 1 ) * j + i;
  23373. var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  23374. // face one
  23375. indices.setX( indexOffset, a ); indexOffset++;
  23376. indices.setX( indexOffset, b ); indexOffset++;
  23377. indices.setX( indexOffset, d ); indexOffset++;
  23378. // face two
  23379. indices.setX( indexOffset, b ); indexOffset++;
  23380. indices.setX( indexOffset, c ); indexOffset++;
  23381. indices.setX( indexOffset, d ); indexOffset++;
  23382. }
  23383. }
  23384. // build geometry
  23385. this.setIndex( indices );
  23386. this.addAttribute( 'position', vertices );
  23387. this.addAttribute( 'normal', normals );
  23388. this.addAttribute( 'uv', uvs );
  23389. // this function calculates the current position on the torus curve
  23390. function calculatePositionOnCurve( u, p, q, radius, position ) {
  23391. var cu = Math.cos( u );
  23392. var su = Math.sin( u );
  23393. var quOverP = q / p * u;
  23394. var cs = Math.cos( quOverP );
  23395. position.x = radius * ( 2 + cs ) * 0.5 * cu;
  23396. position.y = radius * ( 2 + cs ) * su * 0.5;
  23397. position.z = radius * Math.sin( quOverP ) * 0.5;
  23398. }
  23399. };
  23400. THREE.TorusKnotBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  23401. THREE.TorusKnotBufferGeometry.prototype.constructor = THREE.TorusKnotBufferGeometry;
  23402. // File:src/extras/geometries/TorusKnotGeometry.js
  23403. /**
  23404. * @author oosmoxiecode
  23405. */
  23406. THREE.TorusKnotGeometry = function ( radius, tube, tubularSegments, radialSegments, p, q, heightScale ) {
  23407. THREE.Geometry.call( this );
  23408. this.type = 'TorusKnotGeometry';
  23409. this.parameters = {
  23410. radius: radius,
  23411. tube: tube,
  23412. tubularSegments: tubularSegments,
  23413. radialSegments: radialSegments,
  23414. p: p,
  23415. q: q
  23416. };
  23417. if( heightScale !== undefined ) console.warn( 'THREE.TorusKnotGeometry: heightScale has been deprecated. Use .scale( x, y, z ) instead.' );
  23418. this.fromBufferGeometry( new THREE.TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) );
  23419. this.mergeVertices();
  23420. };
  23421. THREE.TorusKnotGeometry.prototype = Object.create( THREE.Geometry.prototype );
  23422. THREE.TorusKnotGeometry.prototype.constructor = THREE.TorusKnotGeometry;
  23423. // File:src/extras/geometries/TubeGeometry.js
  23424. /**
  23425. * @author WestLangley / https://github.com/WestLangley
  23426. * @author zz85 / https://github.com/zz85
  23427. * @author miningold / https://github.com/miningold
  23428. * @author jonobr1 / https://github.com/jonobr1
  23429. *
  23430. * Modified from the TorusKnotGeometry by @oosmoxiecode
  23431. *
  23432. * Creates a tube which extrudes along a 3d spline
  23433. *
  23434. * Uses parallel transport frames as described in
  23435. * http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  23436. */
  23437. THREE.TubeGeometry = function ( path, segments, radius, radialSegments, closed, taper ) {
  23438. THREE.Geometry.call( this );
  23439. this.type = 'TubeGeometry';
  23440. this.parameters = {
  23441. path: path,
  23442. segments: segments,
  23443. radius: radius,
  23444. radialSegments: radialSegments,
  23445. closed: closed,
  23446. taper: taper
  23447. };
  23448. segments = segments || 64;
  23449. radius = radius || 1;
  23450. radialSegments = radialSegments || 8;
  23451. closed = closed || false;
  23452. taper = taper || THREE.TubeGeometry.NoTaper;
  23453. var grid = [];
  23454. var scope = this,
  23455. tangent,
  23456. normal,
  23457. binormal,
  23458. numpoints = segments + 1,
  23459. u, v, r,
  23460. cx, cy,
  23461. pos, pos2 = new THREE.Vector3(),
  23462. i, j,
  23463. ip, jp,
  23464. a, b, c, d,
  23465. uva, uvb, uvc, uvd;
  23466. var frames = new THREE.TubeGeometry.FrenetFrames( path, segments, closed ),
  23467. tangents = frames.tangents,
  23468. normals = frames.normals,
  23469. binormals = frames.binormals;
  23470. // proxy internals
  23471. this.tangents = tangents;
  23472. this.normals = normals;
  23473. this.binormals = binormals;
  23474. function vert( x, y, z ) {
  23475. return scope.vertices.push( new THREE.Vector3( x, y, z ) ) - 1;
  23476. }
  23477. // construct the grid
  23478. for ( i = 0; i < numpoints; i ++ ) {
  23479. grid[ i ] = [];
  23480. u = i / ( numpoints - 1 );
  23481. pos = path.getPointAt( u );
  23482. tangent = tangents[ i ];
  23483. normal = normals[ i ];
  23484. binormal = binormals[ i ];
  23485. r = radius * taper( u );
  23486. for ( j = 0; j < radialSegments; j ++ ) {
  23487. v = j / radialSegments * 2 * Math.PI;
  23488. cx = - r * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
  23489. cy = r * Math.sin( v );
  23490. pos2.copy( pos );
  23491. pos2.x += cx * normal.x + cy * binormal.x;
  23492. pos2.y += cx * normal.y + cy * binormal.y;
  23493. pos2.z += cx * normal.z + cy * binormal.z;
  23494. grid[ i ][ j ] = vert( pos2.x, pos2.y, pos2.z );
  23495. }
  23496. }
  23497. // construct the mesh
  23498. for ( i = 0; i < segments; i ++ ) {
  23499. for ( j = 0; j < radialSegments; j ++ ) {
  23500. ip = ( closed ) ? ( i + 1 ) % segments : i + 1;
  23501. jp = ( j + 1 ) % radialSegments;
  23502. a = grid[ i ][ j ]; // *** NOT NECESSARILY PLANAR ! ***
  23503. b = grid[ ip ][ j ];
  23504. c = grid[ ip ][ jp ];
  23505. d = grid[ i ][ jp ];
  23506. uva = new THREE.Vector2( i / segments, j / radialSegments );
  23507. uvb = new THREE.Vector2( ( i + 1 ) / segments, j / radialSegments );
  23508. uvc = new THREE.Vector2( ( i + 1 ) / segments, ( j + 1 ) / radialSegments );
  23509. uvd = new THREE.Vector2( i / segments, ( j + 1 ) / radialSegments );
  23510. this.faces.push( new THREE.Face3( a, b, d ) );
  23511. this.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  23512. this.faces.push( new THREE.Face3( b, c, d ) );
  23513. this.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  23514. }
  23515. }
  23516. this.computeFaceNormals();
  23517. this.computeVertexNormals();
  23518. };
  23519. THREE.TubeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  23520. THREE.TubeGeometry.prototype.constructor = THREE.TubeGeometry;
  23521. THREE.TubeGeometry.NoTaper = function ( u ) {
  23522. return 1;
  23523. };
  23524. THREE.TubeGeometry.SinusoidalTaper = function ( u ) {
  23525. return Math.sin( Math.PI * u );
  23526. };
  23527. // For computing of Frenet frames, exposing the tangents, normals and binormals the spline
  23528. THREE.TubeGeometry.FrenetFrames = function ( path, segments, closed ) {
  23529. var normal = new THREE.Vector3(),
  23530. tangents = [],
  23531. normals = [],
  23532. binormals = [],
  23533. vec = new THREE.Vector3(),
  23534. mat = new THREE.Matrix4(),
  23535. numpoints = segments + 1,
  23536. theta,
  23537. smallest,
  23538. tx, ty, tz,
  23539. i, u;
  23540. // expose internals
  23541. this.tangents = tangents;
  23542. this.normals = normals;
  23543. this.binormals = binormals;
  23544. // compute the tangent vectors for each segment on the path
  23545. for ( i = 0; i < numpoints; i ++ ) {
  23546. u = i / ( numpoints - 1 );
  23547. tangents[ i ] = path.getTangentAt( u );
  23548. tangents[ i ].normalize();
  23549. }
  23550. initialNormal3();
  23551. /*
  23552. function initialNormal1(lastBinormal) {
  23553. // fixed start binormal. Has dangers of 0 vectors
  23554. normals[ 0 ] = new THREE.Vector3();
  23555. binormals[ 0 ] = new THREE.Vector3();
  23556. if (lastBinormal===undefined) lastBinormal = new THREE.Vector3( 0, 0, 1 );
  23557. normals[ 0 ].crossVectors( lastBinormal, tangents[ 0 ] ).normalize();
  23558. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] ).normalize();
  23559. }
  23560. function initialNormal2() {
  23561. // This uses the Frenet-Serret formula for deriving binormal
  23562. var t2 = path.getTangentAt( epsilon );
  23563. normals[ 0 ] = new THREE.Vector3().subVectors( t2, tangents[ 0 ] ).normalize();
  23564. binormals[ 0 ] = new THREE.Vector3().crossVectors( tangents[ 0 ], normals[ 0 ] );
  23565. normals[ 0 ].crossVectors( binormals[ 0 ], tangents[ 0 ] ).normalize(); // last binormal x tangent
  23566. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] ).normalize();
  23567. }
  23568. */
  23569. function initialNormal3() {
  23570. // select an initial normal vector perpendicular to the first tangent vector,
  23571. // and in the direction of the smallest tangent xyz component
  23572. normals[ 0 ] = new THREE.Vector3();
  23573. binormals[ 0 ] = new THREE.Vector3();
  23574. smallest = Number.MAX_VALUE;
  23575. tx = Math.abs( tangents[ 0 ].x );
  23576. ty = Math.abs( tangents[ 0 ].y );
  23577. tz = Math.abs( tangents[ 0 ].z );
  23578. if ( tx <= smallest ) {
  23579. smallest = tx;
  23580. normal.set( 1, 0, 0 );
  23581. }
  23582. if ( ty <= smallest ) {
  23583. smallest = ty;
  23584. normal.set( 0, 1, 0 );
  23585. }
  23586. if ( tz <= smallest ) {
  23587. normal.set( 0, 0, 1 );
  23588. }
  23589. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  23590. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  23591. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  23592. }
  23593. // compute the slowly-varying normal and binormal vectors for each segment on the path
  23594. for ( i = 1; i < numpoints; i ++ ) {
  23595. normals[ i ] = normals[ i - 1 ].clone();
  23596. binormals[ i ] = binormals[ i - 1 ].clone();
  23597. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  23598. if ( vec.length() > Number.EPSILON ) {
  23599. vec.normalize();
  23600. theta = Math.acos( THREE.Math.clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  23601. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  23602. }
  23603. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  23604. }
  23605. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  23606. if ( closed ) {
  23607. theta = Math.acos( THREE.Math.clamp( normals[ 0 ].dot( normals[ numpoints - 1 ] ), - 1, 1 ) );
  23608. theta /= ( numpoints - 1 );
  23609. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ numpoints - 1 ] ) ) > 0 ) {
  23610. theta = - theta;
  23611. }
  23612. for ( i = 1; i < numpoints; i ++ ) {
  23613. // twist a little...
  23614. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  23615. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  23616. }
  23617. }
  23618. };
  23619. // File:src/extras/geometries/PolyhedronGeometry.js
  23620. /**
  23621. * @author clockworkgeek / https://github.com/clockworkgeek
  23622. * @author timothypratley / https://github.com/timothypratley
  23623. * @author WestLangley / http://github.com/WestLangley
  23624. */
  23625. THREE.PolyhedronGeometry = function ( vertices, indices, radius, detail ) {
  23626. THREE.Geometry.call( this );
  23627. this.type = 'PolyhedronGeometry';
  23628. this.parameters = {
  23629. vertices: vertices,
  23630. indices: indices,
  23631. radius: radius,
  23632. detail: detail
  23633. };
  23634. radius = radius || 1;
  23635. detail = detail || 0;
  23636. var that = this;
  23637. for ( var i = 0, l = vertices.length; i < l; i += 3 ) {
  23638. prepare( new THREE.Vector3( vertices[ i ], vertices[ i + 1 ], vertices[ i + 2 ] ) );
  23639. }
  23640. var p = this.vertices;
  23641. var faces = [];
  23642. for ( var i = 0, j = 0, l = indices.length; i < l; i += 3, j ++ ) {
  23643. var v1 = p[ indices[ i ] ];
  23644. var v2 = p[ indices[ i + 1 ] ];
  23645. var v3 = p[ indices[ i + 2 ] ];
  23646. faces[ j ] = new THREE.Face3( v1.index, v2.index, v3.index, [ v1.clone(), v2.clone(), v3.clone() ], undefined, j );
  23647. }
  23648. var centroid = new THREE.Vector3();
  23649. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  23650. subdivide( faces[ i ], detail );
  23651. }
  23652. // Handle case when face straddles the seam
  23653. for ( var i = 0, l = this.faceVertexUvs[ 0 ].length; i < l; i ++ ) {
  23654. var uvs = this.faceVertexUvs[ 0 ][ i ];
  23655. var x0 = uvs[ 0 ].x;
  23656. var x1 = uvs[ 1 ].x;
  23657. var x2 = uvs[ 2 ].x;
  23658. var max = Math.max( x0, x1, x2 );
  23659. var min = Math.min( x0, x1, x2 );
  23660. if ( max > 0.9 && min < 0.1 ) {
  23661. // 0.9 is somewhat arbitrary
  23662. if ( x0 < 0.2 ) uvs[ 0 ].x += 1;
  23663. if ( x1 < 0.2 ) uvs[ 1 ].x += 1;
  23664. if ( x2 < 0.2 ) uvs[ 2 ].x += 1;
  23665. }
  23666. }
  23667. // Apply radius
  23668. for ( var i = 0, l = this.vertices.length; i < l; i ++ ) {
  23669. this.vertices[ i ].multiplyScalar( radius );
  23670. }
  23671. // Merge vertices
  23672. this.mergeVertices();
  23673. this.computeFaceNormals();
  23674. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  23675. // Project vector onto sphere's surface
  23676. function prepare( vector ) {
  23677. var vertex = vector.normalize().clone();
  23678. vertex.index = that.vertices.push( vertex ) - 1;
  23679. // Texture coords are equivalent to map coords, calculate angle and convert to fraction of a circle.
  23680. var u = azimuth( vector ) / 2 / Math.PI + 0.5;
  23681. var v = inclination( vector ) / Math.PI + 0.5;
  23682. vertex.uv = new THREE.Vector2( u, 1 - v );
  23683. return vertex;
  23684. }
  23685. // Approximate a curved face with recursively sub-divided triangles.
  23686. function make( v1, v2, v3, materialIndex ) {
  23687. var face = new THREE.Face3( v1.index, v2.index, v3.index, [ v1.clone(), v2.clone(), v3.clone() ], undefined, materialIndex );
  23688. that.faces.push( face );
  23689. centroid.copy( v1 ).add( v2 ).add( v3 ).divideScalar( 3 );
  23690. var azi = azimuth( centroid );
  23691. that.faceVertexUvs[ 0 ].push( [
  23692. correctUV( v1.uv, v1, azi ),
  23693. correctUV( v2.uv, v2, azi ),
  23694. correctUV( v3.uv, v3, azi )
  23695. ] );
  23696. }
  23697. // Analytically subdivide a face to the required detail level.
  23698. function subdivide( face, detail ) {
  23699. var cols = Math.pow( 2, detail );
  23700. var a = prepare( that.vertices[ face.a ] );
  23701. var b = prepare( that.vertices[ face.b ] );
  23702. var c = prepare( that.vertices[ face.c ] );
  23703. var v = [];
  23704. var materialIndex = face.materialIndex;
  23705. // Construct all of the vertices for this subdivision.
  23706. for ( var i = 0 ; i <= cols; i ++ ) {
  23707. v[ i ] = [];
  23708. var aj = prepare( a.clone().lerp( c, i / cols ) );
  23709. var bj = prepare( b.clone().lerp( c, i / cols ) );
  23710. var rows = cols - i;
  23711. for ( var j = 0; j <= rows; j ++ ) {
  23712. if ( j === 0 && i === cols ) {
  23713. v[ i ][ j ] = aj;
  23714. } else {
  23715. v[ i ][ j ] = prepare( aj.clone().lerp( bj, j / rows ) );
  23716. }
  23717. }
  23718. }
  23719. // Construct all of the faces.
  23720. for ( var i = 0; i < cols ; i ++ ) {
  23721. for ( var j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
  23722. var k = Math.floor( j / 2 );
  23723. if ( j % 2 === 0 ) {
  23724. make(
  23725. v[ i ][ k + 1 ],
  23726. v[ i + 1 ][ k ],
  23727. v[ i ][ k ],
  23728. materialIndex
  23729. );
  23730. } else {
  23731. make(
  23732. v[ i ][ k + 1 ],
  23733. v[ i + 1 ][ k + 1 ],
  23734. v[ i + 1 ][ k ],
  23735. materialIndex
  23736. );
  23737. }
  23738. }
  23739. }
  23740. }
  23741. // Angle around the Y axis, counter-clockwise when looking from above.
  23742. function azimuth( vector ) {
  23743. return Math.atan2( vector.z, - vector.x );
  23744. }
  23745. // Angle above the XZ plane.
  23746. function inclination( vector ) {
  23747. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  23748. }
  23749. // Texture fixing helper. Spheres have some odd behaviours.
  23750. function correctUV( uv, vector, azimuth ) {
  23751. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) uv = new THREE.Vector2( uv.x - 1, uv.y );
  23752. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) uv = new THREE.Vector2( azimuth / 2 / Math.PI + 0.5, uv.y );
  23753. return uv.clone();
  23754. }
  23755. };
  23756. THREE.PolyhedronGeometry.prototype = Object.create( THREE.Geometry.prototype );
  23757. THREE.PolyhedronGeometry.prototype.constructor = THREE.PolyhedronGeometry;
  23758. // File:src/extras/geometries/DodecahedronGeometry.js
  23759. /**
  23760. * @author Abe Pazos / https://hamoid.com
  23761. */
  23762. THREE.DodecahedronGeometry = function ( radius, detail ) {
  23763. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  23764. var r = 1 / t;
  23765. var vertices = [
  23766. // (±1, ±1, ±1)
  23767. - 1, - 1, - 1, - 1, - 1, 1,
  23768. - 1, 1, - 1, - 1, 1, 1,
  23769. 1, - 1, - 1, 1, - 1, 1,
  23770. 1, 1, - 1, 1, 1, 1,
  23771. // (0, ±1/φ, ±φ)
  23772. 0, - r, - t, 0, - r, t,
  23773. 0, r, - t, 0, r, t,
  23774. // (±1/φ, ±φ, 0)
  23775. - r, - t, 0, - r, t, 0,
  23776. r, - t, 0, r, t, 0,
  23777. // (±φ, 0, ±1/φ)
  23778. - t, 0, - r, t, 0, - r,
  23779. - t, 0, r, t, 0, r
  23780. ];
  23781. var indices = [
  23782. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  23783. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  23784. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  23785. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  23786. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  23787. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  23788. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  23789. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  23790. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  23791. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  23792. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  23793. 1, 12, 14, 1, 14, 5, 1, 5, 9
  23794. ];
  23795. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  23796. this.type = 'DodecahedronGeometry';
  23797. this.parameters = {
  23798. radius: radius,
  23799. detail: detail
  23800. };
  23801. };
  23802. THREE.DodecahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  23803. THREE.DodecahedronGeometry.prototype.constructor = THREE.DodecahedronGeometry;
  23804. // File:src/extras/geometries/IcosahedronGeometry.js
  23805. /**
  23806. * @author timothypratley / https://github.com/timothypratley
  23807. */
  23808. THREE.IcosahedronGeometry = function ( radius, detail ) {
  23809. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  23810. var vertices = [
  23811. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  23812. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  23813. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  23814. ];
  23815. var indices = [
  23816. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  23817. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  23818. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  23819. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  23820. ];
  23821. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  23822. this.type = 'IcosahedronGeometry';
  23823. this.parameters = {
  23824. radius: radius,
  23825. detail: detail
  23826. };
  23827. };
  23828. THREE.IcosahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  23829. THREE.IcosahedronGeometry.prototype.constructor = THREE.IcosahedronGeometry;
  23830. // File:src/extras/geometries/OctahedronGeometry.js
  23831. /**
  23832. * @author timothypratley / https://github.com/timothypratley
  23833. */
  23834. THREE.OctahedronGeometry = function ( radius, detail ) {
  23835. var vertices = [
  23836. 1, 0, 0, - 1, 0, 0, 0, 1, 0, 0, - 1, 0, 0, 0, 1, 0, 0, - 1
  23837. ];
  23838. var indices = [
  23839. 0, 2, 4, 0, 4, 3, 0, 3, 5, 0, 5, 2, 1, 2, 5, 1, 5, 3, 1, 3, 4, 1, 4, 2
  23840. ];
  23841. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  23842. this.type = 'OctahedronGeometry';
  23843. this.parameters = {
  23844. radius: radius,
  23845. detail: detail
  23846. };
  23847. };
  23848. THREE.OctahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  23849. THREE.OctahedronGeometry.prototype.constructor = THREE.OctahedronGeometry;
  23850. // File:src/extras/geometries/TetrahedronGeometry.js
  23851. /**
  23852. * @author timothypratley / https://github.com/timothypratley
  23853. */
  23854. THREE.TetrahedronGeometry = function ( radius, detail ) {
  23855. var vertices = [
  23856. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  23857. ];
  23858. var indices = [
  23859. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  23860. ];
  23861. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  23862. this.type = 'TetrahedronGeometry';
  23863. this.parameters = {
  23864. radius: radius,
  23865. detail: detail
  23866. };
  23867. };
  23868. THREE.TetrahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  23869. THREE.TetrahedronGeometry.prototype.constructor = THREE.TetrahedronGeometry;
  23870. // File:src/extras/geometries/ParametricGeometry.js
  23871. /**
  23872. * @author zz85 / https://github.com/zz85
  23873. * Parametric Surfaces Geometry
  23874. * based on the brilliant article by @prideout http://prideout.net/blog/?p=44
  23875. *
  23876. * new THREE.ParametricGeometry( parametricFunction, uSegments, ySegements );
  23877. *
  23878. */
  23879. THREE.ParametricGeometry = function ( func, slices, stacks ) {
  23880. THREE.Geometry.call( this );
  23881. this.type = 'ParametricGeometry';
  23882. this.parameters = {
  23883. func: func,
  23884. slices: slices,
  23885. stacks: stacks
  23886. };
  23887. var verts = this.vertices;
  23888. var faces = this.faces;
  23889. var uvs = this.faceVertexUvs[ 0 ];
  23890. var i, j, p;
  23891. var u, v;
  23892. var sliceCount = slices + 1;
  23893. for ( i = 0; i <= stacks; i ++ ) {
  23894. v = i / stacks;
  23895. for ( j = 0; j <= slices; j ++ ) {
  23896. u = j / slices;
  23897. p = func( u, v );
  23898. verts.push( p );
  23899. }
  23900. }
  23901. var a, b, c, d;
  23902. var uva, uvb, uvc, uvd;
  23903. for ( i = 0; i < stacks; i ++ ) {
  23904. for ( j = 0; j < slices; j ++ ) {
  23905. a = i * sliceCount + j;
  23906. b = i * sliceCount + j + 1;
  23907. c = ( i + 1 ) * sliceCount + j + 1;
  23908. d = ( i + 1 ) * sliceCount + j;
  23909. uva = new THREE.Vector2( j / slices, i / stacks );
  23910. uvb = new THREE.Vector2( ( j + 1 ) / slices, i / stacks );
  23911. uvc = new THREE.Vector2( ( j + 1 ) / slices, ( i + 1 ) / stacks );
  23912. uvd = new THREE.Vector2( j / slices, ( i + 1 ) / stacks );
  23913. faces.push( new THREE.Face3( a, b, d ) );
  23914. uvs.push( [ uva, uvb, uvd ] );
  23915. faces.push( new THREE.Face3( b, c, d ) );
  23916. uvs.push( [ uvb.clone(), uvc, uvd.clone() ] );
  23917. }
  23918. }
  23919. // console.log(this);
  23920. // magic bullet
  23921. // var diff = this.mergeVertices();
  23922. // console.log('removed ', diff, ' vertices by merging');
  23923. this.computeFaceNormals();
  23924. this.computeVertexNormals();
  23925. };
  23926. THREE.ParametricGeometry.prototype = Object.create( THREE.Geometry.prototype );
  23927. THREE.ParametricGeometry.prototype.constructor = THREE.ParametricGeometry;
  23928. // File:src/extras/geometries/WireframeGeometry.js
  23929. /**
  23930. * @author mrdoob / http://mrdoob.com/
  23931. */
  23932. THREE.WireframeGeometry = function ( geometry ) {
  23933. THREE.BufferGeometry.call( this );
  23934. var edge = [ 0, 0 ], hash = {};
  23935. function sortFunction( a, b ) {
  23936. return a - b;
  23937. }
  23938. var keys = [ 'a', 'b', 'c' ];
  23939. if ( geometry instanceof THREE.Geometry ) {
  23940. var vertices = geometry.vertices;
  23941. var faces = geometry.faces;
  23942. var numEdges = 0;
  23943. // allocate maximal size
  23944. var edges = new Uint32Array( 6 * faces.length );
  23945. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  23946. var face = faces[ i ];
  23947. for ( var j = 0; j < 3; j ++ ) {
  23948. edge[ 0 ] = face[ keys[ j ] ];
  23949. edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
  23950. edge.sort( sortFunction );
  23951. var key = edge.toString();
  23952. if ( hash[ key ] === undefined ) {
  23953. edges[ 2 * numEdges ] = edge[ 0 ];
  23954. edges[ 2 * numEdges + 1 ] = edge[ 1 ];
  23955. hash[ key ] = true;
  23956. numEdges ++;
  23957. }
  23958. }
  23959. }
  23960. var coords = new Float32Array( numEdges * 2 * 3 );
  23961. for ( var i = 0, l = numEdges; i < l; i ++ ) {
  23962. for ( var j = 0; j < 2; j ++ ) {
  23963. var vertex = vertices[ edges [ 2 * i + j ] ];
  23964. var index = 6 * i + 3 * j;
  23965. coords[ index + 0 ] = vertex.x;
  23966. coords[ index + 1 ] = vertex.y;
  23967. coords[ index + 2 ] = vertex.z;
  23968. }
  23969. }
  23970. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  23971. } else if ( geometry instanceof THREE.BufferGeometry ) {
  23972. if ( geometry.index !== null ) {
  23973. // Indexed BufferGeometry
  23974. var indices = geometry.index.array;
  23975. var vertices = geometry.attributes.position;
  23976. var groups = geometry.groups;
  23977. var numEdges = 0;
  23978. if ( groups.length === 0 ) {
  23979. geometry.addGroup( 0, indices.length );
  23980. }
  23981. // allocate maximal size
  23982. var edges = new Uint32Array( 2 * indices.length );
  23983. for ( var o = 0, ol = groups.length; o < ol; ++ o ) {
  23984. var group = groups[ o ];
  23985. var start = group.start;
  23986. var count = group.count;
  23987. for ( var i = start, il = start + count; i < il; i += 3 ) {
  23988. for ( var j = 0; j < 3; j ++ ) {
  23989. edge[ 0 ] = indices[ i + j ];
  23990. edge[ 1 ] = indices[ i + ( j + 1 ) % 3 ];
  23991. edge.sort( sortFunction );
  23992. var key = edge.toString();
  23993. if ( hash[ key ] === undefined ) {
  23994. edges[ 2 * numEdges ] = edge[ 0 ];
  23995. edges[ 2 * numEdges + 1 ] = edge[ 1 ];
  23996. hash[ key ] = true;
  23997. numEdges ++;
  23998. }
  23999. }
  24000. }
  24001. }
  24002. var coords = new Float32Array( numEdges * 2 * 3 );
  24003. for ( var i = 0, l = numEdges; i < l; i ++ ) {
  24004. for ( var j = 0; j < 2; j ++ ) {
  24005. var index = 6 * i + 3 * j;
  24006. var index2 = edges[ 2 * i + j ];
  24007. coords[ index + 0 ] = vertices.getX( index2 );
  24008. coords[ index + 1 ] = vertices.getY( index2 );
  24009. coords[ index + 2 ] = vertices.getZ( index2 );
  24010. }
  24011. }
  24012. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  24013. } else {
  24014. // non-indexed BufferGeometry
  24015. var vertices = geometry.attributes.position.array;
  24016. var numEdges = vertices.length / 3;
  24017. var numTris = numEdges / 3;
  24018. var coords = new Float32Array( numEdges * 2 * 3 );
  24019. for ( var i = 0, l = numTris; i < l; i ++ ) {
  24020. for ( var j = 0; j < 3; j ++ ) {
  24021. var index = 18 * i + 6 * j;
  24022. var index1 = 9 * i + 3 * j;
  24023. coords[ index + 0 ] = vertices[ index1 ];
  24024. coords[ index + 1 ] = vertices[ index1 + 1 ];
  24025. coords[ index + 2 ] = vertices[ index1 + 2 ];
  24026. var index2 = 9 * i + 3 * ( ( j + 1 ) % 3 );
  24027. coords[ index + 3 ] = vertices[ index2 ];
  24028. coords[ index + 4 ] = vertices[ index2 + 1 ];
  24029. coords[ index + 5 ] = vertices[ index2 + 2 ];
  24030. }
  24031. }
  24032. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  24033. }
  24034. }
  24035. };
  24036. THREE.WireframeGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  24037. THREE.WireframeGeometry.prototype.constructor = THREE.WireframeGeometry;
  24038. // File:src/extras/helpers/AxisHelper.js
  24039. /**
  24040. * @author sroucheray / http://sroucheray.org/
  24041. * @author mrdoob / http://mrdoob.com/
  24042. */
  24043. THREE.AxisHelper = function ( size ) {
  24044. size = size || 1;
  24045. var vertices = new Float32Array( [
  24046. 0, 0, 0, size, 0, 0,
  24047. 0, 0, 0, 0, size, 0,
  24048. 0, 0, 0, 0, 0, size
  24049. ] );
  24050. var colors = new Float32Array( [
  24051. 1, 0, 0, 1, 0.6, 0,
  24052. 0, 1, 0, 0.6, 1, 0,
  24053. 0, 0, 1, 0, 0.6, 1
  24054. ] );
  24055. var geometry = new THREE.BufferGeometry();
  24056. geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  24057. geometry.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ) );
  24058. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
  24059. THREE.LineSegments.call( this, geometry, material );
  24060. };
  24061. THREE.AxisHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24062. THREE.AxisHelper.prototype.constructor = THREE.AxisHelper;
  24063. // File:src/extras/helpers/ArrowHelper.js
  24064. /**
  24065. * @author WestLangley / http://github.com/WestLangley
  24066. * @author zz85 / http://github.com/zz85
  24067. * @author bhouston / http://clara.io
  24068. *
  24069. * Creates an arrow for visualizing directions
  24070. *
  24071. * Parameters:
  24072. * dir - Vector3
  24073. * origin - Vector3
  24074. * length - Number
  24075. * color - color in hex value
  24076. * headLength - Number
  24077. * headWidth - Number
  24078. */
  24079. THREE.ArrowHelper = ( function () {
  24080. var lineGeometry = new THREE.BufferGeometry();
  24081. lineGeometry.addAttribute( 'position', new THREE.Float32Attribute( [ 0, 0, 0, 0, 1, 0 ], 3 ) );
  24082. var coneGeometry = new THREE.CylinderBufferGeometry( 0, 0.5, 1, 5, 1 );
  24083. coneGeometry.translate( 0, - 0.5, 0 );
  24084. return function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
  24085. // dir is assumed to be normalized
  24086. THREE.Object3D.call( this );
  24087. if ( color === undefined ) color = 0xffff00;
  24088. if ( length === undefined ) length = 1;
  24089. if ( headLength === undefined ) headLength = 0.2 * length;
  24090. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  24091. this.position.copy( origin );
  24092. this.line = new THREE.Line( lineGeometry, new THREE.LineBasicMaterial( { color: color } ) );
  24093. this.line.matrixAutoUpdate = false;
  24094. this.add( this.line );
  24095. this.cone = new THREE.Mesh( coneGeometry, new THREE.MeshBasicMaterial( { color: color } ) );
  24096. this.cone.matrixAutoUpdate = false;
  24097. this.add( this.cone );
  24098. this.setDirection( dir );
  24099. this.setLength( length, headLength, headWidth );
  24100. };
  24101. }() );
  24102. THREE.ArrowHelper.prototype = Object.create( THREE.Object3D.prototype );
  24103. THREE.ArrowHelper.prototype.constructor = THREE.ArrowHelper;
  24104. THREE.ArrowHelper.prototype.setDirection = ( function () {
  24105. var axis = new THREE.Vector3();
  24106. var radians;
  24107. return function setDirection( dir ) {
  24108. // dir is assumed to be normalized
  24109. if ( dir.y > 0.99999 ) {
  24110. this.quaternion.set( 0, 0, 0, 1 );
  24111. } else if ( dir.y < - 0.99999 ) {
  24112. this.quaternion.set( 1, 0, 0, 0 );
  24113. } else {
  24114. axis.set( dir.z, 0, - dir.x ).normalize();
  24115. radians = Math.acos( dir.y );
  24116. this.quaternion.setFromAxisAngle( axis, radians );
  24117. }
  24118. };
  24119. }() );
  24120. THREE.ArrowHelper.prototype.setLength = function ( length, headLength, headWidth ) {
  24121. if ( headLength === undefined ) headLength = 0.2 * length;
  24122. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  24123. this.line.scale.set( 1, Math.max( 0, length - headLength ), 1 );
  24124. this.line.updateMatrix();
  24125. this.cone.scale.set( headWidth, headLength, headWidth );
  24126. this.cone.position.y = length;
  24127. this.cone.updateMatrix();
  24128. };
  24129. THREE.ArrowHelper.prototype.setColor = function ( color ) {
  24130. this.line.material.color.copy( color );
  24131. this.cone.material.color.copy( color );
  24132. };
  24133. // File:src/extras/helpers/BoxHelper.js
  24134. /**
  24135. * @author mrdoob / http://mrdoob.com/
  24136. */
  24137. THREE.BoxHelper = function ( object ) {
  24138. 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 ] );
  24139. var positions = new Float32Array( 8 * 3 );
  24140. var geometry = new THREE.BufferGeometry();
  24141. geometry.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  24142. geometry.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
  24143. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: 0xffff00 } ) );
  24144. if ( object !== undefined ) {
  24145. this.update( object );
  24146. }
  24147. };
  24148. THREE.BoxHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24149. THREE.BoxHelper.prototype.constructor = THREE.BoxHelper;
  24150. THREE.BoxHelper.prototype.update = ( function () {
  24151. var box = new THREE.Box3();
  24152. return function ( object ) {
  24153. if ( object instanceof THREE.Box3 ) {
  24154. box.copy( object );
  24155. } else {
  24156. box.setFromObject( object );
  24157. }
  24158. if ( box.isEmpty() ) return;
  24159. var min = box.min;
  24160. var max = box.max;
  24161. /*
  24162. 5____4
  24163. 1/___0/|
  24164. | 6__|_7
  24165. 2/___3/
  24166. 0: max.x, max.y, max.z
  24167. 1: min.x, max.y, max.z
  24168. 2: min.x, min.y, max.z
  24169. 3: max.x, min.y, max.z
  24170. 4: max.x, max.y, min.z
  24171. 5: min.x, max.y, min.z
  24172. 6: min.x, min.y, min.z
  24173. 7: max.x, min.y, min.z
  24174. */
  24175. var position = this.geometry.attributes.position;
  24176. var array = position.array;
  24177. array[ 0 ] = max.x; array[ 1 ] = max.y; array[ 2 ] = max.z;
  24178. array[ 3 ] = min.x; array[ 4 ] = max.y; array[ 5 ] = max.z;
  24179. array[ 6 ] = min.x; array[ 7 ] = min.y; array[ 8 ] = max.z;
  24180. array[ 9 ] = max.x; array[ 10 ] = min.y; array[ 11 ] = max.z;
  24181. array[ 12 ] = max.x; array[ 13 ] = max.y; array[ 14 ] = min.z;
  24182. array[ 15 ] = min.x; array[ 16 ] = max.y; array[ 17 ] = min.z;
  24183. array[ 18 ] = min.x; array[ 19 ] = min.y; array[ 20 ] = min.z;
  24184. array[ 21 ] = max.x; array[ 22 ] = min.y; array[ 23 ] = min.z;
  24185. position.needsUpdate = true;
  24186. this.geometry.computeBoundingSphere();
  24187. };
  24188. } )();
  24189. // File:src/extras/helpers/BoundingBoxHelper.js
  24190. /**
  24191. * @author WestLangley / http://github.com/WestLangley
  24192. */
  24193. // a helper to show the world-axis-aligned bounding box for an object
  24194. THREE.BoundingBoxHelper = function ( object, hex ) {
  24195. var color = ( hex !== undefined ) ? hex : 0x888888;
  24196. this.object = object;
  24197. this.box = new THREE.Box3();
  24198. THREE.Mesh.call( this, new THREE.BoxGeometry( 1, 1, 1 ), new THREE.MeshBasicMaterial( { color: color, wireframe: true } ) );
  24199. };
  24200. THREE.BoundingBoxHelper.prototype = Object.create( THREE.Mesh.prototype );
  24201. THREE.BoundingBoxHelper.prototype.constructor = THREE.BoundingBoxHelper;
  24202. THREE.BoundingBoxHelper.prototype.update = function () {
  24203. this.box.setFromObject( this.object );
  24204. this.box.size( this.scale );
  24205. this.box.center( this.position );
  24206. };
  24207. // File:src/extras/helpers/CameraHelper.js
  24208. /**
  24209. * @author alteredq / http://alteredqualia.com/
  24210. *
  24211. * - shows frustum, line of sight and up of the camera
  24212. * - suitable for fast updates
  24213. * - based on frustum visualization in lightgl.js shadowmap example
  24214. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  24215. */
  24216. THREE.CameraHelper = function ( camera ) {
  24217. var geometry = new THREE.Geometry();
  24218. var material = new THREE.LineBasicMaterial( { color: 0xffffff, vertexColors: THREE.FaceColors } );
  24219. var pointMap = {};
  24220. // colors
  24221. var hexFrustum = 0xffaa00;
  24222. var hexCone = 0xff0000;
  24223. var hexUp = 0x00aaff;
  24224. var hexTarget = 0xffffff;
  24225. var hexCross = 0x333333;
  24226. // near
  24227. addLine( "n1", "n2", hexFrustum );
  24228. addLine( "n2", "n4", hexFrustum );
  24229. addLine( "n4", "n3", hexFrustum );
  24230. addLine( "n3", "n1", hexFrustum );
  24231. // far
  24232. addLine( "f1", "f2", hexFrustum );
  24233. addLine( "f2", "f4", hexFrustum );
  24234. addLine( "f4", "f3", hexFrustum );
  24235. addLine( "f3", "f1", hexFrustum );
  24236. // sides
  24237. addLine( "n1", "f1", hexFrustum );
  24238. addLine( "n2", "f2", hexFrustum );
  24239. addLine( "n3", "f3", hexFrustum );
  24240. addLine( "n4", "f4", hexFrustum );
  24241. // cone
  24242. addLine( "p", "n1", hexCone );
  24243. addLine( "p", "n2", hexCone );
  24244. addLine( "p", "n3", hexCone );
  24245. addLine( "p", "n4", hexCone );
  24246. // up
  24247. addLine( "u1", "u2", hexUp );
  24248. addLine( "u2", "u3", hexUp );
  24249. addLine( "u3", "u1", hexUp );
  24250. // target
  24251. addLine( "c", "t", hexTarget );
  24252. addLine( "p", "c", hexCross );
  24253. // cross
  24254. addLine( "cn1", "cn2", hexCross );
  24255. addLine( "cn3", "cn4", hexCross );
  24256. addLine( "cf1", "cf2", hexCross );
  24257. addLine( "cf3", "cf4", hexCross );
  24258. function addLine( a, b, hex ) {
  24259. addPoint( a, hex );
  24260. addPoint( b, hex );
  24261. }
  24262. function addPoint( id, hex ) {
  24263. geometry.vertices.push( new THREE.Vector3() );
  24264. geometry.colors.push( new THREE.Color( hex ) );
  24265. if ( pointMap[ id ] === undefined ) {
  24266. pointMap[ id ] = [];
  24267. }
  24268. pointMap[ id ].push( geometry.vertices.length - 1 );
  24269. }
  24270. THREE.LineSegments.call( this, geometry, material );
  24271. this.camera = camera;
  24272. this.camera.updateProjectionMatrix();
  24273. this.matrix = camera.matrixWorld;
  24274. this.matrixAutoUpdate = false;
  24275. this.pointMap = pointMap;
  24276. this.update();
  24277. };
  24278. THREE.CameraHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24279. THREE.CameraHelper.prototype.constructor = THREE.CameraHelper;
  24280. THREE.CameraHelper.prototype.update = function () {
  24281. var geometry, pointMap;
  24282. var vector = new THREE.Vector3();
  24283. var camera = new THREE.Camera();
  24284. function setPoint( point, x, y, z ) {
  24285. vector.set( x, y, z ).unproject( camera );
  24286. var points = pointMap[ point ];
  24287. if ( points !== undefined ) {
  24288. for ( var i = 0, il = points.length; i < il; i ++ ) {
  24289. geometry.vertices[ points[ i ] ].copy( vector );
  24290. }
  24291. }
  24292. }
  24293. return function () {
  24294. geometry = this.geometry;
  24295. pointMap = this.pointMap;
  24296. var w = 1, h = 1;
  24297. // we need just camera projection matrix
  24298. // world matrix must be identity
  24299. camera.projectionMatrix.copy( this.camera.projectionMatrix );
  24300. // center / target
  24301. setPoint( "c", 0, 0, - 1 );
  24302. setPoint( "t", 0, 0, 1 );
  24303. // near
  24304. setPoint( "n1", - w, - h, - 1 );
  24305. setPoint( "n2", w, - h, - 1 );
  24306. setPoint( "n3", - w, h, - 1 );
  24307. setPoint( "n4", w, h, - 1 );
  24308. // far
  24309. setPoint( "f1", - w, - h, 1 );
  24310. setPoint( "f2", w, - h, 1 );
  24311. setPoint( "f3", - w, h, 1 );
  24312. setPoint( "f4", w, h, 1 );
  24313. // up
  24314. setPoint( "u1", w * 0.7, h * 1.1, - 1 );
  24315. setPoint( "u2", - w * 0.7, h * 1.1, - 1 );
  24316. setPoint( "u3", 0, h * 2, - 1 );
  24317. // cross
  24318. setPoint( "cf1", - w, 0, 1 );
  24319. setPoint( "cf2", w, 0, 1 );
  24320. setPoint( "cf3", 0, - h, 1 );
  24321. setPoint( "cf4", 0, h, 1 );
  24322. setPoint( "cn1", - w, 0, - 1 );
  24323. setPoint( "cn2", w, 0, - 1 );
  24324. setPoint( "cn3", 0, - h, - 1 );
  24325. setPoint( "cn4", 0, h, - 1 );
  24326. geometry.verticesNeedUpdate = true;
  24327. };
  24328. }();
  24329. // File:src/extras/helpers/DirectionalLightHelper.js
  24330. /**
  24331. * @author alteredq / http://alteredqualia.com/
  24332. * @author mrdoob / http://mrdoob.com/
  24333. * @author WestLangley / http://github.com/WestLangley
  24334. */
  24335. THREE.DirectionalLightHelper = function ( light, size ) {
  24336. THREE.Object3D.call( this );
  24337. this.light = light;
  24338. this.light.updateMatrixWorld();
  24339. this.matrix = light.matrixWorld;
  24340. this.matrixAutoUpdate = false;
  24341. if ( size === undefined ) size = 1;
  24342. var geometry = new THREE.BufferGeometry();
  24343. geometry.addAttribute( 'position', new THREE.Float32Attribute( [
  24344. - size, size, 0,
  24345. size, size, 0,
  24346. size, - size, 0,
  24347. - size, - size, 0,
  24348. - size, size, 0
  24349. ], 3 ) );
  24350. var material = new THREE.LineBasicMaterial( { fog: false } );
  24351. this.add( new THREE.Line( geometry, material ) );
  24352. geometry = new THREE.BufferGeometry();
  24353. geometry.addAttribute( 'position', new THREE.Float32Attribute( [ 0, 0, 0, 0, 0, 1 ], 3 ) );
  24354. this.add( new THREE.Line( geometry, material ));
  24355. this.update();
  24356. };
  24357. THREE.DirectionalLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  24358. THREE.DirectionalLightHelper.prototype.constructor = THREE.DirectionalLightHelper;
  24359. THREE.DirectionalLightHelper.prototype.dispose = function () {
  24360. var lightPlane = this.children[ 0 ];
  24361. var targetLine = this.children[ 1 ];
  24362. lightPlane.geometry.dispose();
  24363. lightPlane.material.dispose();
  24364. targetLine.geometry.dispose();
  24365. targetLine.material.dispose();
  24366. };
  24367. THREE.DirectionalLightHelper.prototype.update = function () {
  24368. var v1 = new THREE.Vector3();
  24369. var v2 = new THREE.Vector3();
  24370. var v3 = new THREE.Vector3();
  24371. return function () {
  24372. v1.setFromMatrixPosition( this.light.matrixWorld );
  24373. v2.setFromMatrixPosition( this.light.target.matrixWorld );
  24374. v3.subVectors( v2, v1 );
  24375. var lightPlane = this.children[ 0 ];
  24376. var targetLine = this.children[ 1 ];
  24377. lightPlane.lookAt( v3 );
  24378. lightPlane.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  24379. targetLine.lookAt( v3 );
  24380. targetLine.scale.z = v3.length();
  24381. };
  24382. }();
  24383. // File:src/extras/helpers/EdgesHelper.js
  24384. /**
  24385. * @author WestLangley / http://github.com/WestLangley
  24386. * @param object THREE.Mesh whose geometry will be used
  24387. * @param hex line color
  24388. * @param thresholdAngle the minimum angle (in degrees),
  24389. * between the face normals of adjacent faces,
  24390. * that is required to render an edge. A value of 10 means
  24391. * an edge is only rendered if the angle is at least 10 degrees.
  24392. */
  24393. THREE.EdgesHelper = function ( object, hex, thresholdAngle ) {
  24394. var color = ( hex !== undefined ) ? hex : 0xffffff;
  24395. THREE.LineSegments.call( this, new THREE.EdgesGeometry( object.geometry, thresholdAngle ), new THREE.LineBasicMaterial( { color: color } ) );
  24396. this.matrix = object.matrixWorld;
  24397. this.matrixAutoUpdate = false;
  24398. };
  24399. THREE.EdgesHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24400. THREE.EdgesHelper.prototype.constructor = THREE.EdgesHelper;
  24401. // File:src/extras/helpers/FaceNormalsHelper.js
  24402. /**
  24403. * @author mrdoob / http://mrdoob.com/
  24404. * @author WestLangley / http://github.com/WestLangley
  24405. */
  24406. THREE.FaceNormalsHelper = function ( object, size, hex, linewidth ) {
  24407. // FaceNormalsHelper only supports THREE.Geometry
  24408. this.object = object;
  24409. this.size = ( size !== undefined ) ? size : 1;
  24410. var color = ( hex !== undefined ) ? hex : 0xffff00;
  24411. var width = ( linewidth !== undefined ) ? linewidth : 1;
  24412. //
  24413. var nNormals = 0;
  24414. var objGeometry = this.object.geometry;
  24415. if ( objGeometry instanceof THREE.Geometry ) {
  24416. nNormals = objGeometry.faces.length;
  24417. } else {
  24418. console.warn( 'THREE.FaceNormalsHelper: only THREE.Geometry is supported. Use THREE.VertexNormalsHelper, instead.' );
  24419. }
  24420. //
  24421. var geometry = new THREE.BufferGeometry();
  24422. var positions = new THREE.Float32Attribute( nNormals * 2 * 3, 3 );
  24423. geometry.addAttribute( 'position', positions );
  24424. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  24425. //
  24426. this.matrixAutoUpdate = false;
  24427. this.update();
  24428. };
  24429. THREE.FaceNormalsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24430. THREE.FaceNormalsHelper.prototype.constructor = THREE.FaceNormalsHelper;
  24431. THREE.FaceNormalsHelper.prototype.update = ( function () {
  24432. var v1 = new THREE.Vector3();
  24433. var v2 = new THREE.Vector3();
  24434. var normalMatrix = new THREE.Matrix3();
  24435. return function update() {
  24436. this.object.updateMatrixWorld( true );
  24437. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  24438. var matrixWorld = this.object.matrixWorld;
  24439. var position = this.geometry.attributes.position;
  24440. //
  24441. var objGeometry = this.object.geometry;
  24442. var vertices = objGeometry.vertices;
  24443. var faces = objGeometry.faces;
  24444. var idx = 0;
  24445. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  24446. var face = faces[ i ];
  24447. var normal = face.normal;
  24448. v1.copy( vertices[ face.a ] )
  24449. .add( vertices[ face.b ] )
  24450. .add( vertices[ face.c ] )
  24451. .divideScalar( 3 )
  24452. .applyMatrix4( matrixWorld );
  24453. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  24454. position.setXYZ( idx, v1.x, v1.y, v1.z );
  24455. idx = idx + 1;
  24456. position.setXYZ( idx, v2.x, v2.y, v2.z );
  24457. idx = idx + 1;
  24458. }
  24459. position.needsUpdate = true;
  24460. return this;
  24461. };
  24462. }() );
  24463. // File:src/extras/helpers/GridHelper.js
  24464. /**
  24465. * @author mrdoob / http://mrdoob.com/
  24466. */
  24467. THREE.GridHelper = function ( size, step, color1, color2 ) {
  24468. color1 = new THREE.Color( color1 !== undefined ? color1 : 0x444444 );
  24469. color2 = new THREE.Color( color2 !== undefined ? color2 : 0x888888 );
  24470. var vertices = [];
  24471. var colors = [];
  24472. for ( var i = - size, j = 0; i <= size; i += step ) {
  24473. vertices.push( - size, 0, i, size, 0, i );
  24474. vertices.push( i, 0, - size, i, 0, size );
  24475. var color = i === 0 ? color1 : color2;
  24476. color.toArray( colors, j ); j += 3;
  24477. color.toArray( colors, j ); j += 3;
  24478. color.toArray( colors, j ); j += 3;
  24479. color.toArray( colors, j ); j += 3;
  24480. }
  24481. var geometry = new THREE.BufferGeometry();
  24482. geometry.addAttribute( 'position', new THREE.Float32Attribute( vertices, 3 ) );
  24483. geometry.addAttribute( 'color', new THREE.Float32Attribute( colors, 3 ) );
  24484. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
  24485. THREE.LineSegments.call( this, geometry, material );
  24486. };
  24487. THREE.GridHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24488. THREE.GridHelper.prototype.constructor = THREE.GridHelper;
  24489. THREE.GridHelper.prototype.setColors = function () {
  24490. console.error( 'THREE.GridHelper: setColors() has been deprecated, pass them in the constructor instead.' );
  24491. };
  24492. // File:src/extras/helpers/HemisphereLightHelper.js
  24493. /**
  24494. * @author alteredq / http://alteredqualia.com/
  24495. * @author mrdoob / http://mrdoob.com/
  24496. */
  24497. THREE.HemisphereLightHelper = function ( light, sphereSize ) {
  24498. THREE.Object3D.call( this );
  24499. this.light = light;
  24500. this.light.updateMatrixWorld();
  24501. this.matrix = light.matrixWorld;
  24502. this.matrixAutoUpdate = false;
  24503. this.colors = [ new THREE.Color(), new THREE.Color() ];
  24504. var geometry = new THREE.SphereGeometry( sphereSize, 4, 2 );
  24505. geometry.rotateX( - Math.PI / 2 );
  24506. for ( var i = 0, il = 8; i < il; i ++ ) {
  24507. geometry.faces[ i ].color = this.colors[ i < 4 ? 0 : 1 ];
  24508. }
  24509. var material = new THREE.MeshBasicMaterial( { vertexColors: THREE.FaceColors, wireframe: true } );
  24510. this.lightSphere = new THREE.Mesh( geometry, material );
  24511. this.add( this.lightSphere );
  24512. this.update();
  24513. };
  24514. THREE.HemisphereLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  24515. THREE.HemisphereLightHelper.prototype.constructor = THREE.HemisphereLightHelper;
  24516. THREE.HemisphereLightHelper.prototype.dispose = function () {
  24517. this.lightSphere.geometry.dispose();
  24518. this.lightSphere.material.dispose();
  24519. };
  24520. THREE.HemisphereLightHelper.prototype.update = function () {
  24521. var vector = new THREE.Vector3();
  24522. return function () {
  24523. this.colors[ 0 ].copy( this.light.color ).multiplyScalar( this.light.intensity );
  24524. this.colors[ 1 ].copy( this.light.groundColor ).multiplyScalar( this.light.intensity );
  24525. this.lightSphere.lookAt( vector.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  24526. this.lightSphere.geometry.colorsNeedUpdate = true;
  24527. };
  24528. }();
  24529. // File:src/extras/helpers/PointLightHelper.js
  24530. /**
  24531. * @author alteredq / http://alteredqualia.com/
  24532. * @author mrdoob / http://mrdoob.com/
  24533. */
  24534. THREE.PointLightHelper = function ( light, sphereSize ) {
  24535. this.light = light;
  24536. this.light.updateMatrixWorld();
  24537. var geometry = new THREE.SphereBufferGeometry( sphereSize, 4, 2 );
  24538. var material = new THREE.MeshBasicMaterial( { wireframe: true, fog: false } );
  24539. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  24540. THREE.Mesh.call( this, geometry, material );
  24541. this.matrix = this.light.matrixWorld;
  24542. this.matrixAutoUpdate = false;
  24543. /*
  24544. var distanceGeometry = new THREE.IcosahedronGeometry( 1, 2 );
  24545. var distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  24546. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  24547. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  24548. var d = light.distance;
  24549. if ( d === 0.0 ) {
  24550. this.lightDistance.visible = false;
  24551. } else {
  24552. this.lightDistance.scale.set( d, d, d );
  24553. }
  24554. this.add( this.lightDistance );
  24555. */
  24556. };
  24557. THREE.PointLightHelper.prototype = Object.create( THREE.Mesh.prototype );
  24558. THREE.PointLightHelper.prototype.constructor = THREE.PointLightHelper;
  24559. THREE.PointLightHelper.prototype.dispose = function () {
  24560. this.geometry.dispose();
  24561. this.material.dispose();
  24562. };
  24563. THREE.PointLightHelper.prototype.update = function () {
  24564. this.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  24565. /*
  24566. var d = this.light.distance;
  24567. if ( d === 0.0 ) {
  24568. this.lightDistance.visible = false;
  24569. } else {
  24570. this.lightDistance.visible = true;
  24571. this.lightDistance.scale.set( d, d, d );
  24572. }
  24573. */
  24574. };
  24575. // File:src/extras/helpers/SkeletonHelper.js
  24576. /**
  24577. * @author Sean Griffin / http://twitter.com/sgrif
  24578. * @author Michael Guerrero / http://realitymeltdown.com
  24579. * @author mrdoob / http://mrdoob.com/
  24580. * @author ikerr / http://verold.com
  24581. */
  24582. THREE.SkeletonHelper = function ( object ) {
  24583. this.bones = this.getBoneList( object );
  24584. var geometry = new THREE.Geometry();
  24585. for ( var i = 0; i < this.bones.length; i ++ ) {
  24586. var bone = this.bones[ i ];
  24587. if ( bone.parent instanceof THREE.Bone ) {
  24588. geometry.vertices.push( new THREE.Vector3() );
  24589. geometry.vertices.push( new THREE.Vector3() );
  24590. geometry.colors.push( new THREE.Color( 0, 0, 1 ) );
  24591. geometry.colors.push( new THREE.Color( 0, 1, 0 ) );
  24592. }
  24593. }
  24594. geometry.dynamic = true;
  24595. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors, depthTest: false, depthWrite: false, transparent: true } );
  24596. THREE.LineSegments.call( this, geometry, material );
  24597. this.root = object;
  24598. this.matrix = object.matrixWorld;
  24599. this.matrixAutoUpdate = false;
  24600. this.update();
  24601. };
  24602. THREE.SkeletonHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24603. THREE.SkeletonHelper.prototype.constructor = THREE.SkeletonHelper;
  24604. THREE.SkeletonHelper.prototype.getBoneList = function( object ) {
  24605. var boneList = [];
  24606. if ( object instanceof THREE.Bone ) {
  24607. boneList.push( object );
  24608. }
  24609. for ( var i = 0; i < object.children.length; i ++ ) {
  24610. boneList.push.apply( boneList, this.getBoneList( object.children[ i ] ) );
  24611. }
  24612. return boneList;
  24613. };
  24614. THREE.SkeletonHelper.prototype.update = function () {
  24615. var geometry = this.geometry;
  24616. var matrixWorldInv = new THREE.Matrix4().getInverse( this.root.matrixWorld );
  24617. var boneMatrix = new THREE.Matrix4();
  24618. var j = 0;
  24619. for ( var i = 0; i < this.bones.length; i ++ ) {
  24620. var bone = this.bones[ i ];
  24621. if ( bone.parent instanceof THREE.Bone ) {
  24622. boneMatrix.multiplyMatrices( matrixWorldInv, bone.matrixWorld );
  24623. geometry.vertices[ j ].setFromMatrixPosition( boneMatrix );
  24624. boneMatrix.multiplyMatrices( matrixWorldInv, bone.parent.matrixWorld );
  24625. geometry.vertices[ j + 1 ].setFromMatrixPosition( boneMatrix );
  24626. j += 2;
  24627. }
  24628. }
  24629. geometry.verticesNeedUpdate = true;
  24630. geometry.computeBoundingSphere();
  24631. };
  24632. // File:src/extras/helpers/SpotLightHelper.js
  24633. /**
  24634. * @author alteredq / http://alteredqualia.com/
  24635. * @author mrdoob / http://mrdoob.com/
  24636. * @author WestLangley / http://github.com/WestLangley
  24637. */
  24638. THREE.SpotLightHelper = function ( light ) {
  24639. THREE.Object3D.call( this );
  24640. this.light = light;
  24641. this.light.updateMatrixWorld();
  24642. this.matrix = light.matrixWorld;
  24643. this.matrixAutoUpdate = false;
  24644. var geometry = new THREE.BufferGeometry();
  24645. var positions = [
  24646. 0, 0, 0, 0, 0, 1,
  24647. 0, 0, 0, 1, 0, 1,
  24648. 0, 0, 0, - 1, 0, 1,
  24649. 0, 0, 0, 0, 1, 1,
  24650. 0, 0, 0, 0, - 1, 1
  24651. ];
  24652. for ( var i = 0, j = 1, l = 32; i < l; i ++, j ++ ) {
  24653. var p1 = ( i / l ) * Math.PI * 2;
  24654. var p2 = ( j / l ) * Math.PI * 2;
  24655. positions.push(
  24656. Math.cos( p1 ), Math.sin( p1 ), 1,
  24657. Math.cos( p2 ), Math.sin( p2 ), 1
  24658. );
  24659. }
  24660. geometry.addAttribute( 'position', new THREE.Float32Attribute( positions, 3 ) );
  24661. var material = new THREE.LineBasicMaterial( { fog: false } );
  24662. this.cone = new THREE.LineSegments( geometry, material );
  24663. this.add( this.cone );
  24664. this.update();
  24665. };
  24666. THREE.SpotLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  24667. THREE.SpotLightHelper.prototype.constructor = THREE.SpotLightHelper;
  24668. THREE.SpotLightHelper.prototype.dispose = function () {
  24669. this.cone.geometry.dispose();
  24670. this.cone.material.dispose();
  24671. };
  24672. THREE.SpotLightHelper.prototype.update = function () {
  24673. var vector = new THREE.Vector3();
  24674. var vector2 = new THREE.Vector3();
  24675. return function () {
  24676. var coneLength = this.light.distance ? this.light.distance : 1000;
  24677. var coneWidth = coneLength * Math.tan( this.light.angle );
  24678. this.cone.scale.set( coneWidth, coneWidth, coneLength );
  24679. vector.setFromMatrixPosition( this.light.matrixWorld );
  24680. vector2.setFromMatrixPosition( this.light.target.matrixWorld );
  24681. this.cone.lookAt( vector2.sub( vector ) );
  24682. this.cone.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  24683. };
  24684. }();
  24685. // File:src/extras/helpers/VertexNormalsHelper.js
  24686. /**
  24687. * @author mrdoob / http://mrdoob.com/
  24688. * @author WestLangley / http://github.com/WestLangley
  24689. */
  24690. THREE.VertexNormalsHelper = function ( object, size, hex, linewidth ) {
  24691. this.object = object;
  24692. this.size = ( size !== undefined ) ? size : 1;
  24693. var color = ( hex !== undefined ) ? hex : 0xff0000;
  24694. var width = ( linewidth !== undefined ) ? linewidth : 1;
  24695. //
  24696. var nNormals = 0;
  24697. var objGeometry = this.object.geometry;
  24698. if ( objGeometry instanceof THREE.Geometry ) {
  24699. nNormals = objGeometry.faces.length * 3;
  24700. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  24701. nNormals = objGeometry.attributes.normal.count;
  24702. }
  24703. //
  24704. var geometry = new THREE.BufferGeometry();
  24705. var positions = new THREE.Float32Attribute( nNormals * 2 * 3, 3 );
  24706. geometry.addAttribute( 'position', positions );
  24707. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  24708. //
  24709. this.matrixAutoUpdate = false;
  24710. this.update();
  24711. };
  24712. THREE.VertexNormalsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24713. THREE.VertexNormalsHelper.prototype.constructor = THREE.VertexNormalsHelper;
  24714. THREE.VertexNormalsHelper.prototype.update = ( function () {
  24715. var v1 = new THREE.Vector3();
  24716. var v2 = new THREE.Vector3();
  24717. var normalMatrix = new THREE.Matrix3();
  24718. return function update() {
  24719. var keys = [ 'a', 'b', 'c' ];
  24720. this.object.updateMatrixWorld( true );
  24721. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  24722. var matrixWorld = this.object.matrixWorld;
  24723. var position = this.geometry.attributes.position;
  24724. //
  24725. var objGeometry = this.object.geometry;
  24726. if ( objGeometry instanceof THREE.Geometry ) {
  24727. var vertices = objGeometry.vertices;
  24728. var faces = objGeometry.faces;
  24729. var idx = 0;
  24730. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  24731. var face = faces[ i ];
  24732. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  24733. var vertex = vertices[ face[ keys[ j ] ] ];
  24734. var normal = face.vertexNormals[ j ];
  24735. v1.copy( vertex ).applyMatrix4( matrixWorld );
  24736. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  24737. position.setXYZ( idx, v1.x, v1.y, v1.z );
  24738. idx = idx + 1;
  24739. position.setXYZ( idx, v2.x, v2.y, v2.z );
  24740. idx = idx + 1;
  24741. }
  24742. }
  24743. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  24744. var objPos = objGeometry.attributes.position;
  24745. var objNorm = objGeometry.attributes.normal;
  24746. var idx = 0;
  24747. // for simplicity, ignore index and drawcalls, and render every normal
  24748. for ( var j = 0, jl = objPos.count; j < jl; j ++ ) {
  24749. v1.set( objPos.getX( j ), objPos.getY( j ), objPos.getZ( j ) ).applyMatrix4( matrixWorld );
  24750. v2.set( objNorm.getX( j ), objNorm.getY( j ), objNorm.getZ( j ) );
  24751. v2.applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  24752. position.setXYZ( idx, v1.x, v1.y, v1.z );
  24753. idx = idx + 1;
  24754. position.setXYZ( idx, v2.x, v2.y, v2.z );
  24755. idx = idx + 1;
  24756. }
  24757. }
  24758. position.needsUpdate = true;
  24759. return this;
  24760. };
  24761. }() );
  24762. // File:src/extras/helpers/WireframeHelper.js
  24763. /**
  24764. * @author mrdoob / http://mrdoob.com/
  24765. */
  24766. THREE.WireframeHelper = function ( object, hex ) {
  24767. var color = ( hex !== undefined ) ? hex : 0xffffff;
  24768. THREE.LineSegments.call( this, new THREE.WireframeGeometry( object.geometry ), new THREE.LineBasicMaterial( { color: color } ) );
  24769. this.matrix = object.matrixWorld;
  24770. this.matrixAutoUpdate = false;
  24771. };
  24772. THREE.WireframeHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24773. THREE.WireframeHelper.prototype.constructor = THREE.WireframeHelper;
  24774. // File:src/extras/objects/ImmediateRenderObject.js
  24775. /**
  24776. * @author alteredq / http://alteredqualia.com/
  24777. */
  24778. THREE.ImmediateRenderObject = function ( material ) {
  24779. THREE.Object3D.call( this );
  24780. this.material = material;
  24781. this.render = function ( renderCallback ) {};
  24782. };
  24783. THREE.ImmediateRenderObject.prototype = Object.create( THREE.Object3D.prototype );
  24784. THREE.ImmediateRenderObject.prototype.constructor = THREE.ImmediateRenderObject;
  24785. // File:src/extras/objects/MorphBlendMesh.js
  24786. /**
  24787. * @author alteredq / http://alteredqualia.com/
  24788. */
  24789. THREE.MorphBlendMesh = function( geometry, material ) {
  24790. THREE.Mesh.call( this, geometry, material );
  24791. this.animationsMap = {};
  24792. this.animationsList = [];
  24793. // prepare default animation
  24794. // (all frames played together in 1 second)
  24795. var numFrames = this.geometry.morphTargets.length;
  24796. var name = "__default";
  24797. var startFrame = 0;
  24798. var endFrame = numFrames - 1;
  24799. var fps = numFrames / 1;
  24800. this.createAnimation( name, startFrame, endFrame, fps );
  24801. this.setAnimationWeight( name, 1 );
  24802. };
  24803. THREE.MorphBlendMesh.prototype = Object.create( THREE.Mesh.prototype );
  24804. THREE.MorphBlendMesh.prototype.constructor = THREE.MorphBlendMesh;
  24805. THREE.MorphBlendMesh.prototype.createAnimation = function ( name, start, end, fps ) {
  24806. var animation = {
  24807. start: start,
  24808. end: end,
  24809. length: end - start + 1,
  24810. fps: fps,
  24811. duration: ( end - start ) / fps,
  24812. lastFrame: 0,
  24813. currentFrame: 0,
  24814. active: false,
  24815. time: 0,
  24816. direction: 1,
  24817. weight: 1,
  24818. directionBackwards: false,
  24819. mirroredLoop: false
  24820. };
  24821. this.animationsMap[ name ] = animation;
  24822. this.animationsList.push( animation );
  24823. };
  24824. THREE.MorphBlendMesh.prototype.autoCreateAnimations = function ( fps ) {
  24825. var pattern = /([a-z]+)_?(\d+)/i;
  24826. var firstAnimation, frameRanges = {};
  24827. var geometry = this.geometry;
  24828. for ( var i = 0, il = geometry.morphTargets.length; i < il; i ++ ) {
  24829. var morph = geometry.morphTargets[ i ];
  24830. var chunks = morph.name.match( pattern );
  24831. if ( chunks && chunks.length > 1 ) {
  24832. var name = chunks[ 1 ];
  24833. if ( ! frameRanges[ name ] ) frameRanges[ name ] = { start: Infinity, end: - Infinity };
  24834. var range = frameRanges[ name ];
  24835. if ( i < range.start ) range.start = i;
  24836. if ( i > range.end ) range.end = i;
  24837. if ( ! firstAnimation ) firstAnimation = name;
  24838. }
  24839. }
  24840. for ( var name in frameRanges ) {
  24841. var range = frameRanges[ name ];
  24842. this.createAnimation( name, range.start, range.end, fps );
  24843. }
  24844. this.firstAnimation = firstAnimation;
  24845. };
  24846. THREE.MorphBlendMesh.prototype.setAnimationDirectionForward = function ( name ) {
  24847. var animation = this.animationsMap[ name ];
  24848. if ( animation ) {
  24849. animation.direction = 1;
  24850. animation.directionBackwards = false;
  24851. }
  24852. };
  24853. THREE.MorphBlendMesh.prototype.setAnimationDirectionBackward = function ( name ) {
  24854. var animation = this.animationsMap[ name ];
  24855. if ( animation ) {
  24856. animation.direction = - 1;
  24857. animation.directionBackwards = true;
  24858. }
  24859. };
  24860. THREE.MorphBlendMesh.prototype.setAnimationFPS = function ( name, fps ) {
  24861. var animation = this.animationsMap[ name ];
  24862. if ( animation ) {
  24863. animation.fps = fps;
  24864. animation.duration = ( animation.end - animation.start ) / animation.fps;
  24865. }
  24866. };
  24867. THREE.MorphBlendMesh.prototype.setAnimationDuration = function ( name, duration ) {
  24868. var animation = this.animationsMap[ name ];
  24869. if ( animation ) {
  24870. animation.duration = duration;
  24871. animation.fps = ( animation.end - animation.start ) / animation.duration;
  24872. }
  24873. };
  24874. THREE.MorphBlendMesh.prototype.setAnimationWeight = function ( name, weight ) {
  24875. var animation = this.animationsMap[ name ];
  24876. if ( animation ) {
  24877. animation.weight = weight;
  24878. }
  24879. };
  24880. THREE.MorphBlendMesh.prototype.setAnimationTime = function ( name, time ) {
  24881. var animation = this.animationsMap[ name ];
  24882. if ( animation ) {
  24883. animation.time = time;
  24884. }
  24885. };
  24886. THREE.MorphBlendMesh.prototype.getAnimationTime = function ( name ) {
  24887. var time = 0;
  24888. var animation = this.animationsMap[ name ];
  24889. if ( animation ) {
  24890. time = animation.time;
  24891. }
  24892. return time;
  24893. };
  24894. THREE.MorphBlendMesh.prototype.getAnimationDuration = function ( name ) {
  24895. var duration = - 1;
  24896. var animation = this.animationsMap[ name ];
  24897. if ( animation ) {
  24898. duration = animation.duration;
  24899. }
  24900. return duration;
  24901. };
  24902. THREE.MorphBlendMesh.prototype.playAnimation = function ( name ) {
  24903. var animation = this.animationsMap[ name ];
  24904. if ( animation ) {
  24905. animation.time = 0;
  24906. animation.active = true;
  24907. } else {
  24908. console.warn( "THREE.MorphBlendMesh: animation[" + name + "] undefined in .playAnimation()" );
  24909. }
  24910. };
  24911. THREE.MorphBlendMesh.prototype.stopAnimation = function ( name ) {
  24912. var animation = this.animationsMap[ name ];
  24913. if ( animation ) {
  24914. animation.active = false;
  24915. }
  24916. };
  24917. THREE.MorphBlendMesh.prototype.update = function ( delta ) {
  24918. for ( var i = 0, il = this.animationsList.length; i < il; i ++ ) {
  24919. var animation = this.animationsList[ i ];
  24920. if ( ! animation.active ) continue;
  24921. var frameTime = animation.duration / animation.length;
  24922. animation.time += animation.direction * delta;
  24923. if ( animation.mirroredLoop ) {
  24924. if ( animation.time > animation.duration || animation.time < 0 ) {
  24925. animation.direction *= - 1;
  24926. if ( animation.time > animation.duration ) {
  24927. animation.time = animation.duration;
  24928. animation.directionBackwards = true;
  24929. }
  24930. if ( animation.time < 0 ) {
  24931. animation.time = 0;
  24932. animation.directionBackwards = false;
  24933. }
  24934. }
  24935. } else {
  24936. animation.time = animation.time % animation.duration;
  24937. if ( animation.time < 0 ) animation.time += animation.duration;
  24938. }
  24939. var keyframe = animation.start + THREE.Math.clamp( Math.floor( animation.time / frameTime ), 0, animation.length - 1 );
  24940. var weight = animation.weight;
  24941. if ( keyframe !== animation.currentFrame ) {
  24942. this.morphTargetInfluences[ animation.lastFrame ] = 0;
  24943. this.morphTargetInfluences[ animation.currentFrame ] = 1 * weight;
  24944. this.morphTargetInfluences[ keyframe ] = 0;
  24945. animation.lastFrame = animation.currentFrame;
  24946. animation.currentFrame = keyframe;
  24947. }
  24948. var mix = ( animation.time % frameTime ) / frameTime;
  24949. if ( animation.directionBackwards ) mix = 1 - mix;
  24950. if ( animation.currentFrame !== animation.lastFrame ) {
  24951. this.morphTargetInfluences[ animation.currentFrame ] = mix * weight;
  24952. this.morphTargetInfluences[ animation.lastFrame ] = ( 1 - mix ) * weight;
  24953. } else {
  24954. this.morphTargetInfluences[ animation.currentFrame ] = weight;
  24955. }
  24956. }
  24957. };