three.js 949 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649306503065130652306533065430655306563065730658306593066030661306623066330664306653066630667306683066930670306713067230673306743067530676306773067830679306803068130682306833068430685306863068730688306893069030691306923069330694306953069630697306983069930700307013070230703307043070530706307073070830709307103071130712307133071430715307163071730718307193072030721307223072330724307253072630727307283072930730307313073230733307343073530736307373073830739307403074130742307433074430745307463074730748307493075030751307523075330754307553075630757307583075930760307613076230763307643076530766307673076830769307703077130772307733077430775307763077730778307793078030781307823078330784307853078630787307883078930790307913079230793307943079530796307973079830799308003080130802308033080430805308063080730808308093081030811308123081330814308153081630817308183081930820308213082230823308243082530826308273082830829308303083130832308333083430835308363083730838308393084030841308423084330844308453084630847308483084930850308513085230853308543085530856308573085830859308603086130862308633086430865308663086730868308693087030871308723087330874308753087630877308783087930880308813088230883308843088530886308873088830889308903089130892308933089430895308963089730898308993090030901309023090330904309053090630907309083090930910309113091230913309143091530916309173091830919309203092130922309233092430925309263092730928309293093030931309323093330934309353093630937309383093930940309413094230943309443094530946309473094830949309503095130952309533095430955309563095730958309593096030961309623096330964309653096630967309683096930970309713097230973309743097530976309773097830979309803098130982309833098430985309863098730988309893099030991309923099330994309953099630997309983099931000310013100231003310043100531006310073100831009310103101131012310133101431015310163101731018310193102031021310223102331024310253102631027310283102931030310313103231033310343103531036310373103831039310403104131042310433104431045310463104731048310493105031051310523105331054310553105631057310583105931060310613106231063310643106531066310673106831069310703107131072310733107431075310763107731078310793108031081310823108331084310853108631087310883108931090310913109231093310943109531096310973109831099311003110131102311033110431105311063110731108311093111031111311123111331114311153111631117311183111931120311213112231123311243112531126311273112831129311303113131132311333113431135311363113731138311393114031141311423114331144311453114631147311483114931150311513115231153311543115531156311573115831159311603116131162311633116431165311663116731168311693117031171311723117331174311753117631177311783117931180311813118231183311843118531186311873118831189311903119131192311933119431195311963119731198311993120031201312023120331204312053120631207312083120931210312113121231213312143121531216312173121831219312203122131222312233122431225312263122731228312293123031231312323123331234312353123631237312383123931240312413124231243312443124531246312473124831249312503125131252312533125431255312563125731258312593126031261312623126331264312653126631267312683126931270312713127231273312743127531276312773127831279312803128131282312833128431285312863128731288312893129031291312923129331294312953129631297312983129931300313013130231303313043130531306313073130831309313103131131312313133131431315313163131731318313193132031321313223132331324313253132631327313283132931330313313133231333313343133531336313373133831339313403134131342313433134431345313463134731348313493135031351313523135331354313553135631357313583135931360313613136231363313643136531366313673136831369313703137131372313733137431375313763137731378313793138031381313823138331384313853138631387313883138931390313913139231393313943139531396313973139831399314003140131402314033140431405314063140731408314093141031411314123141331414314153141631417314183141931420314213142231423314243142531426314273142831429314303143131432314333143431435314363143731438314393144031441314423144331444314453144631447314483144931450314513145231453314543145531456314573145831459314603146131462314633146431465314663146731468314693147031471314723147331474314753147631477314783147931480314813148231483314843148531486314873148831489314903149131492314933149431495314963149731498314993150031501315023150331504315053150631507315083150931510315113151231513315143151531516315173151831519315203152131522315233152431525315263152731528315293153031531315323153331534315353153631537315383153931540315413154231543315443154531546315473154831549315503155131552315533155431555315563155731558315593156031561315623156331564315653156631567315683156931570315713157231573315743157531576315773157831579315803158131582315833158431585315863158731588315893159031591315923159331594315953159631597315983159931600316013160231603316043160531606316073160831609316103161131612316133161431615316163161731618316193162031621316223162331624316253162631627316283162931630316313163231633316343163531636316373163831639316403164131642316433164431645316463164731648316493165031651316523165331654316553165631657316583165931660316613166231663316643166531666316673166831669316703167131672316733167431675316763167731678316793168031681316823168331684316853168631687316883168931690316913169231693316943169531696316973169831699317003170131702317033170431705317063170731708317093171031711317123171331714317153171631717317183171931720317213172231723317243172531726317273172831729317303173131732317333173431735317363173731738317393174031741317423174331744317453174631747317483174931750317513175231753317543175531756317573175831759317603176131762317633176431765317663176731768317693177031771317723177331774317753177631777317783177931780317813178231783317843178531786317873178831789317903179131792317933179431795317963179731798317993180031801318023180331804318053180631807318083180931810318113181231813318143181531816318173181831819318203182131822318233182431825318263182731828318293183031831318323183331834318353183631837318383183931840318413184231843318443184531846318473184831849318503185131852318533185431855318563185731858318593186031861318623186331864318653186631867318683186931870318713187231873318743187531876318773187831879318803188131882318833188431885318863188731888318893189031891318923189331894318953189631897318983189931900319013190231903319043190531906319073190831909319103191131912319133191431915319163191731918319193192031921319223192331924319253192631927319283192931930319313193231933319343193531936319373193831939319403194131942319433194431945319463194731948319493195031951319523195331954319553195631957319583195931960319613196231963319643196531966319673196831969319703197131972319733197431975319763197731978319793198031981319823198331984319853198631987319883198931990319913199231993319943199531996319973199831999320003200132002320033200432005320063200732008320093201032011320123201332014320153201632017320183201932020320213202232023320243202532026320273202832029320303203132032320333203432035320363203732038320393204032041320423204332044320453204632047320483204932050320513205232053320543205532056320573205832059320603206132062320633206432065320663206732068320693207032071320723207332074320753207632077320783207932080320813208232083320843208532086320873208832089320903209132092320933209432095320963209732098320993210032101321023210332104321053210632107321083210932110321113211232113321143211532116321173211832119321203212132122321233212432125321263212732128321293213032131321323213332134321353213632137321383213932140321413214232143321443214532146321473214832149321503215132152321533215432155321563215732158321593216032161321623216332164321653216632167321683216932170321713217232173321743217532176321773217832179321803218132182321833218432185321863218732188321893219032191321923219332194321953219632197321983219932200322013220232203322043220532206322073220832209322103221132212322133221432215322163221732218322193222032221322223222332224322253222632227322283222932230322313223232233322343223532236322373223832239322403224132242322433224432245322463224732248322493225032251322523225332254322553225632257322583225932260322613226232263322643226532266322673226832269322703227132272322733227432275322763227732278322793228032281322823228332284322853228632287322883228932290322913229232293322943229532296322973229832299323003230132302323033230432305323063230732308323093231032311323123231332314323153231632317323183231932320323213232232323323243232532326323273232832329323303233132332323333233432335323363233732338323393234032341323423234332344323453234632347323483234932350323513235232353323543235532356323573235832359323603236132362323633236432365323663236732368323693237032371323723237332374323753237632377323783237932380323813238232383323843238532386323873238832389323903239132392323933239432395323963239732398323993240032401324023240332404324053240632407324083240932410324113241232413324143241532416324173241832419324203242132422324233242432425324263242732428324293243032431324323243332434324353243632437324383243932440324413244232443324443244532446324473244832449324503245132452324533245432455324563245732458324593246032461324623246332464324653246632467324683246932470324713247232473324743247532476324773247832479324803248132482324833248432485324863248732488324893249032491324923249332494324953249632497324983249932500325013250232503325043250532506325073250832509325103251132512325133251432515325163251732518325193252032521325223252332524325253252632527325283252932530325313253232533325343253532536325373253832539325403254132542325433254432545325463254732548325493255032551325523255332554325553255632557325583255932560325613256232563325643256532566325673256832569325703257132572325733257432575325763257732578325793258032581325823258332584325853258632587325883258932590325913259232593325943259532596325973259832599326003260132602326033260432605326063260732608326093261032611326123261332614326153261632617326183261932620326213262232623326243262532626326273262832629326303263132632326333263432635326363263732638326393264032641326423264332644326453264632647326483264932650326513265232653326543265532656326573265832659326603266132662326633266432665326663266732668326693267032671326723267332674326753267632677326783267932680326813268232683326843268532686326873268832689326903269132692326933269432695326963269732698326993270032701327023270332704327053270632707327083270932710327113271232713327143271532716327173271832719327203272132722327233272432725327263272732728327293273032731327323273332734327353273632737327383273932740327413274232743327443274532746327473274832749327503275132752327533275432755327563275732758327593276032761327623276332764327653276632767327683276932770327713277232773327743277532776327773277832779327803278132782327833278432785327863278732788327893279032791327923279332794327953279632797327983279932800328013280232803328043280532806328073280832809328103281132812328133281432815328163281732818328193282032821328223282332824328253282632827328283282932830328313283232833328343283532836328373283832839328403284132842328433284432845328463284732848328493285032851328523285332854328553285632857328583285932860328613286232863328643286532866328673286832869328703287132872328733287432875328763287732878328793288032881328823288332884328853288632887328883288932890328913289232893328943289532896328973289832899329003290132902329033290432905329063290732908329093291032911329123291332914329153291632917329183291932920329213292232923329243292532926329273292832929329303293132932329333293432935329363293732938329393294032941329423294332944329453294632947329483294932950329513295232953329543295532956329573295832959329603296132962329633296432965329663296732968329693297032971329723297332974329753297632977329783297932980329813298232983329843298532986329873298832989329903299132992329933299432995329963299732998329993300033001330023300333004330053300633007330083300933010330113301233013330143301533016330173301833019330203302133022330233302433025330263302733028330293303033031330323303333034330353303633037330383303933040330413304233043330443304533046330473304833049330503305133052330533305433055330563305733058330593306033061330623306333064330653306633067330683306933070330713307233073330743307533076330773307833079330803308133082330833308433085330863308733088330893309033091330923309333094330953309633097330983309933100331013310233103331043310533106331073310833109331103311133112331133311433115331163311733118331193312033121331223312333124331253312633127331283312933130331313313233133331343313533136331373313833139331403314133142331433314433145331463314733148331493315033151331523315333154331553315633157331583315933160331613316233163331643316533166331673316833169331703317133172331733317433175331763317733178331793318033181331823318333184331853318633187331883318933190331913319233193331943319533196331973319833199332003320133202332033320433205332063320733208332093321033211332123321333214332153321633217332183321933220332213322233223332243322533226332273322833229332303323133232332333323433235332363323733238332393324033241332423324333244332453324633247332483324933250332513325233253332543325533256332573325833259332603326133262332633326433265332663326733268332693327033271332723327333274332753327633277332783327933280332813328233283332843328533286332873328833289332903329133292332933329433295332963329733298332993330033301333023330333304333053330633307333083330933310333113331233313333143331533316333173331833319333203332133322333233332433325333263332733328333293333033331333323333333334333353333633337333383333933340333413334233343333443334533346333473334833349333503335133352333533335433355333563335733358333593336033361333623336333364333653336633367333683336933370333713337233373333743337533376333773337833379333803338133382333833338433385333863338733388333893339033391333923339333394333953339633397333983339933400334013340233403334043340533406334073340833409334103341133412334133341433415334163341733418334193342033421334223342333424334253342633427334283342933430334313343233433334343343533436334373343833439334403344133442334433344433445334463344733448334493345033451334523345333454334553345633457334583345933460334613346233463334643346533466334673346833469334703347133472334733347433475334763347733478334793348033481334823348333484334853348633487334883348933490334913349233493334943349533496334973349833499335003350133502335033350433505335063350733508335093351033511335123351333514335153351633517335183351933520335213352233523335243352533526335273352833529335303353133532335333353433535335363353733538335393354033541335423354333544335453354633547335483354933550335513355233553335543355533556335573355833559335603356133562335633356433565335663356733568335693357033571335723357333574335753357633577335783357933580335813358233583335843358533586335873358833589335903359133592335933359433595335963359733598335993360033601336023360333604336053360633607336083360933610336113361233613336143361533616336173361833619336203362133622336233362433625336263362733628336293363033631336323363333634336353363633637336383363933640336413364233643336443364533646336473364833649336503365133652336533365433655336563365733658336593366033661336623366333664336653366633667336683366933670336713367233673336743367533676336773367833679336803368133682336833368433685336863368733688336893369033691336923369333694336953369633697336983369933700337013370233703337043370533706337073370833709337103371133712337133371433715337163371733718337193372033721337223372333724337253372633727337283372933730337313373233733337343373533736337373373833739337403374133742337433374433745337463374733748337493375033751337523375333754337553375633757337583375933760337613376233763337643376533766337673376833769337703377133772337733377433775337763377733778337793378033781337823378333784337853378633787337883378933790337913379233793337943379533796337973379833799338003380133802338033380433805338063380733808338093381033811338123381333814338153381633817338183381933820338213382233823338243382533826338273382833829338303383133832338333383433835338363383733838338393384033841338423384333844338453384633847338483384933850338513385233853338543385533856338573385833859338603386133862338633386433865338663386733868338693387033871338723387333874338753387633877338783387933880338813388233883338843388533886338873388833889338903389133892338933389433895338963389733898338993390033901339023390333904339053390633907339083390933910339113391233913339143391533916339173391833919339203392133922339233392433925339263392733928339293393033931339323393333934339353393633937339383393933940339413394233943339443394533946339473394833949339503395133952339533395433955339563395733958339593396033961339623396333964339653396633967339683396933970339713397233973339743397533976339773397833979339803398133982339833398433985339863398733988339893399033991339923399333994339953399633997339983399934000340013400234003340043400534006340073400834009340103401134012340133401434015340163401734018340193402034021340223402334024340253402634027340283402934030340313403234033340343403534036340373403834039340403404134042340433404434045340463404734048340493405034051340523405334054340553405634057340583405934060340613406234063340643406534066340673406834069340703407134072340733407434075340763407734078340793408034081340823408334084340853408634087340883408934090340913409234093340943409534096340973409834099341003410134102341033410434105341063410734108341093411034111341123411334114341153411634117341183411934120341213412234123341243412534126341273412834129341303413134132341333413434135341363413734138341393414034141341423414334144341453414634147341483414934150341513415234153341543415534156341573415834159341603416134162341633416434165341663416734168341693417034171341723417334174341753417634177341783417934180341813418234183341843418534186341873418834189341903419134192341933419434195341963419734198341993420034201342023420334204342053420634207342083420934210342113421234213342143421534216342173421834219342203422134222342233422434225342263422734228342293423034231342323423334234342353423634237342383423934240342413424234243342443424534246342473424834249342503425134252342533425434255342563425734258342593426034261342623426334264342653426634267342683426934270342713427234273342743427534276342773427834279342803428134282342833428434285342863428734288342893429034291342923429334294342953429634297342983429934300343013430234303343043430534306343073430834309343103431134312343133431434315343163431734318343193432034321343223432334324343253432634327343283432934330343313433234333343343433534336343373433834339343403434134342343433434434345343463434734348343493435034351343523435334354343553435634357343583435934360343613436234363343643436534366343673436834369343703437134372343733437434375343763437734378343793438034381343823438334384343853438634387343883438934390343913439234393343943439534396343973439834399344003440134402344033440434405344063440734408344093441034411344123441334414344153441634417344183441934420344213442234423344243442534426344273442834429344303443134432344333443434435344363443734438344393444034441344423444334444344453444634447344483444934450344513445234453344543445534456344573445834459344603446134462344633446434465344663446734468344693447034471344723447334474344753447634477344783447934480344813448234483344843448534486344873448834489344903449134492344933449434495344963449734498344993450034501345023450334504345053450634507345083450934510345113451234513345143451534516345173451834519345203452134522345233452434525345263452734528345293453034531345323453334534345353453634537345383453934540345413454234543345443454534546345473454834549345503455134552345533455434555345563455734558345593456034561345623456334564345653456634567345683456934570345713457234573345743457534576345773457834579345803458134582345833458434585345863458734588345893459034591345923459334594345953459634597345983459934600346013460234603346043460534606346073460834609346103461134612346133461434615346163461734618346193462034621346223462334624346253462634627346283462934630346313463234633346343463534636346373463834639346403464134642346433464434645346463464734648346493465034651346523465334654346553465634657346583465934660346613466234663346643466534666346673466834669346703467134672346733467434675346763467734678346793468034681346823468334684346853468634687346883468934690346913469234693346943469534696346973469834699347003470134702347033470434705347063470734708347093471034711347123471334714347153471634717347183471934720347213472234723347243472534726347273472834729347303473134732347333473434735347363473734738347393474034741347423474334744347453474634747347483474934750347513475234753347543475534756347573475834759347603476134762347633476434765347663476734768347693477034771347723477334774347753477634777347783477934780347813478234783347843478534786347873478834789347903479134792347933479434795347963479734798347993480034801348023480334804348053480634807348083480934810348113481234813348143481534816348173481834819348203482134822348233482434825348263482734828348293483034831348323483334834348353483634837348383483934840348413484234843348443484534846348473484834849348503485134852348533485434855348563485734858348593486034861348623486334864348653486634867348683486934870348713487234873348743487534876348773487834879348803488134882348833488434885348863488734888348893489034891348923489334894348953489634897348983489934900349013490234903349043490534906349073490834909349103491134912349133491434915349163491734918349193492034921349223492334924349253492634927349283492934930349313493234933349343493534936349373493834939349403494134942349433494434945349463494734948349493495034951349523495334954349553495634957349583495934960349613496234963349643496534966349673496834969349703497134972349733497434975349763497734978349793498034981349823498334984349853498634987349883498934990349913499234993349943499534996349973499834999350003500135002350033500435005350063500735008350093501035011350123501335014350153501635017350183501935020350213502235023350243502535026350273502835029350303503135032350333503435035350363503735038350393504035041350423504335044350453504635047350483504935050350513505235053350543505535056350573505835059350603506135062350633506435065350663506735068350693507035071350723507335074350753507635077350783507935080350813508235083350843508535086350873508835089350903509135092350933509435095350963509735098350993510035101351023510335104351053510635107351083510935110351113511235113351143511535116351173511835119351203512135122351233512435125351263512735128351293513035131351323513335134351353513635137351383513935140351413514235143351443514535146351473514835149351503515135152351533515435155351563515735158351593516035161351623516335164351653516635167351683516935170351713517235173351743517535176351773517835179351803518135182351833518435185351863518735188351893519035191351923519335194351953519635197351983519935200352013520235203352043520535206352073520835209352103521135212352133521435215352163521735218352193522035221352223522335224352253522635227352283522935230352313523235233352343523535236352373523835239352403524135242352433524435245352463524735248352493525035251352523525335254352553525635257352583525935260352613526235263352643526535266352673526835269352703527135272352733527435275352763527735278352793528035281352823528335284352853528635287352883528935290352913529235293352943529535296352973529835299353003530135302353033530435305353063530735308353093531035311353123531335314353153531635317353183531935320353213532235323353243532535326353273532835329353303533135332353333533435335353363533735338353393534035341353423534335344353453534635347353483534935350353513535235353353543535535356353573535835359353603536135362353633536435365353663536735368353693537035371353723537335374353753537635377353783537935380353813538235383353843538535386353873538835389353903539135392353933539435395353963539735398353993540035401354023540335404354053540635407354083540935410354113541235413354143541535416354173541835419354203542135422354233542435425354263542735428354293543035431354323543335434354353543635437354383543935440354413544235443354443544535446354473544835449354503545135452354533545435455354563545735458354593546035461354623546335464354653546635467354683546935470354713547235473354743547535476354773547835479354803548135482354833548435485354863548735488354893549035491354923549335494354953549635497354983549935500355013550235503355043550535506355073550835509355103551135512355133551435515355163551735518355193552035521355223552335524355253552635527355283552935530355313553235533355343553535536355373553835539355403554135542355433554435545355463554735548355493555035551355523555335554355553555635557355583555935560355613556235563355643556535566355673556835569355703557135572355733557435575355763557735578355793558035581355823558335584355853558635587355883558935590355913559235593355943559535596355973559835599356003560135602356033560435605356063560735608356093561035611356123561335614356153561635617356183561935620356213562235623356243562535626356273562835629356303563135632356333563435635356363563735638356393564035641356423564335644356453564635647356483564935650356513565235653356543565535656356573565835659356603566135662356633566435665356663566735668356693567035671356723567335674356753567635677356783567935680356813568235683356843568535686356873568835689356903569135692356933569435695356963569735698356993570035701357023570335704357053570635707357083570935710357113571235713357143571535716357173571835719357203572135722357233572435725357263572735728357293573035731357323573335734357353573635737357383573935740357413574235743357443574535746357473574835749357503575135752357533575435755357563575735758357593576035761357623576335764357653576635767357683576935770357713577235773357743577535776357773577835779357803578135782357833578435785357863578735788357893579035791357923579335794357953579635797357983579935800358013580235803358043580535806358073580835809358103581135812358133581435815358163581735818358193582035821358223582335824358253582635827358283582935830358313583235833358343583535836358373583835839358403584135842358433584435845358463584735848358493585035851358523585335854358553585635857358583585935860358613586235863358643586535866358673586835869358703587135872358733587435875358763587735878358793588035881358823588335884358853588635887358883588935890358913589235893358943589535896358973589835899359003590135902359033590435905359063590735908359093591035911359123591335914359153591635917359183591935920359213592235923359243592535926359273592835929359303593135932359333593435935359363593735938359393594035941359423594335944359453594635947359483594935950359513595235953359543595535956359573595835959359603596135962359633596435965359663596735968359693597035971359723597335974359753597635977359783597935980359813598235983359843598535986359873598835989359903599135992359933599435995359963599735998359993600036001360023600336004360053600636007360083600936010360113601236013360143601536016360173601836019360203602136022360233602436025360263602736028360293603036031360323603336034360353603636037360383603936040360413604236043360443604536046360473604836049360503605136052360533605436055360563605736058360593606036061360623606336064360653606636067360683606936070360713607236073360743607536076360773607836079360803608136082360833608436085360863608736088360893609036091360923609336094360953609636097360983609936100361013610236103361043610536106361073610836109361103611136112361133611436115361163611736118361193612036121361223612336124361253612636127361283612936130361313613236133361343613536136361373613836139361403614136142361433614436145361463614736148361493615036151361523615336154361553615636157361583615936160361613616236163361643616536166361673616836169361703617136172361733617436175361763617736178361793618036181361823618336184361853618636187361883618936190361913619236193361943619536196361973619836199362003620136202362033620436205362063620736208362093621036211362123621336214362153621636217362183621936220362213622236223362243622536226362273622836229362303623136232362333623436235362363623736238362393624036241362423624336244362453624636247362483624936250362513625236253362543625536256362573625836259362603626136262362633626436265362663626736268362693627036271362723627336274362753627636277362783627936280362813628236283362843628536286362873628836289362903629136292362933629436295362963629736298362993630036301363023630336304363053630636307363083630936310363113631236313363143631536316363173631836319363203632136322363233632436325363263632736328363293633036331363323633336334363353633636337363383633936340363413634236343363443634536346363473634836349363503635136352363533635436355363563635736358363593636036361363623636336364363653636636367363683636936370363713637236373363743637536376363773637836379363803638136382363833638436385363863638736388363893639036391363923639336394363953639636397363983639936400364013640236403364043640536406364073640836409364103641136412364133641436415364163641736418364193642036421364223642336424364253642636427364283642936430364313643236433364343643536436364373643836439364403644136442364433644436445364463644736448364493645036451364523645336454364553645636457364583645936460364613646236463364643646536466364673646836469364703647136472364733647436475364763647736478364793648036481364823648336484364853648636487364883648936490364913649236493364943649536496364973649836499365003650136502365033650436505365063650736508365093651036511365123651336514365153651636517365183651936520365213652236523365243652536526365273652836529365303653136532365333653436535365363653736538365393654036541365423654336544365453654636547365483654936550365513655236553365543655536556365573655836559365603656136562365633656436565365663656736568365693657036571365723657336574365753657636577365783657936580365813658236583365843658536586365873658836589365903659136592365933659436595365963659736598365993660036601366023660336604366053660636607366083660936610366113661236613366143661536616366173661836619366203662136622366233662436625366263662736628366293663036631366323663336634366353663636637366383663936640366413664236643366443664536646366473664836649366503665136652366533665436655366563665736658366593666036661366623666336664366653666636667366683666936670366713667236673366743667536676366773667836679366803668136682366833668436685366863668736688366893669036691366923669336694366953669636697366983669936700367013670236703367043670536706367073670836709367103671136712367133671436715367163671736718367193672036721367223672336724367253672636727367283672936730367313673236733367343673536736367373673836739367403674136742367433674436745367463674736748367493675036751367523675336754367553675636757367583675936760367613676236763367643676536766367673676836769367703677136772367733677436775367763677736778367793678036781367823678336784367853678636787367883678936790367913679236793367943679536796367973679836799368003680136802368033680436805368063680736808368093681036811368123681336814368153681636817368183681936820368213682236823368243682536826368273682836829368303683136832368333683436835368363683736838368393684036841368423684336844368453684636847368483684936850368513685236853368543685536856368573685836859368603686136862368633686436865368663686736868368693687036871368723687336874368753687636877368783687936880368813688236883368843688536886368873688836889368903689136892368933689436895368963689736898368993690036901369023690336904369053690636907369083690936910369113691236913369143691536916369173691836919369203692136922369233692436925369263692736928369293693036931369323693336934369353693636937369383693936940369413694236943369443694536946369473694836949369503695136952369533695436955369563695736958369593696036961369623696336964369653696636967369683696936970369713697236973369743697536976369773697836979369803698136982369833698436985369863698736988369893699036991369923699336994369953699636997369983699937000370013700237003370043700537006370073700837009370103701137012370133701437015370163701737018370193702037021370223702337024370253702637027370283702937030370313703237033370343703537036370373703837039370403704137042370433704437045370463704737048370493705037051370523705337054370553705637057370583705937060370613706237063370643706537066370673706837069370703707137072370733707437075370763707737078370793708037081370823708337084370853708637087370883708937090370913709237093370943709537096370973709837099371003710137102371033710437105371063710737108371093711037111371123711337114371153711637117371183711937120371213712237123371243712537126371273712837129371303713137132371333713437135371363713737138371393714037141371423714337144371453714637147371483714937150371513715237153371543715537156371573715837159371603716137162371633716437165371663716737168371693717037171371723717337174371753717637177371783717937180371813718237183371843718537186371873718837189371903719137192371933719437195371963719737198371993720037201372023720337204372053720637207372083720937210372113721237213372143721537216372173721837219372203722137222372233722437225372263722737228372293723037231372323723337234372353723637237372383723937240372413724237243372443724537246372473724837249372503725137252372533725437255372563725737258372593726037261372623726337264372653726637267372683726937270372713727237273372743727537276372773727837279372803728137282372833728437285372863728737288372893729037291372923729337294372953729637297372983729937300373013730237303373043730537306373073730837309373103731137312373133731437315373163731737318373193732037321373223732337324373253732637327373283732937330373313733237333373343733537336373373733837339373403734137342373433734437345373463734737348373493735037351373523735337354373553735637357373583735937360373613736237363373643736537366373673736837369373703737137372373733737437375373763737737378373793738037381373823738337384373853738637387373883738937390373913739237393373943739537396373973739837399374003740137402374033740437405374063740737408374093741037411374123741337414374153741637417374183741937420374213742237423374243742537426374273742837429374303743137432374333743437435374363743737438374393744037441374423744337444374453744637447374483744937450374513745237453374543745537456374573745837459374603746137462374633746437465374663746737468374693747037471374723747337474374753747637477374783747937480374813748237483374843748537486374873748837489374903749137492374933749437495374963749737498374993750037501375023750337504375053750637507375083750937510375113751237513375143751537516375173751837519375203752137522375233752437525375263752737528375293753037531375323753337534375353753637537375383753937540375413754237543375443754537546375473754837549375503755137552375533755437555375563755737558375593756037561375623756337564375653756637567375683756937570375713757237573375743757537576375773757837579375803758137582375833758437585375863758737588375893759037591375923759337594375953759637597375983759937600376013760237603376043760537606376073760837609376103761137612376133761437615376163761737618376193762037621376223762337624376253762637627376283762937630376313763237633376343763537636376373763837639376403764137642376433764437645376463764737648376493765037651376523765337654376553765637657376583765937660376613766237663376643766537666376673766837669376703767137672376733767437675376763767737678376793768037681376823768337684376853768637687376883768937690376913769237693376943769537696376973769837699377003770137702377033770437705377063770737708377093771037711377123771337714377153771637717377183771937720377213772237723377243772537726377273772837729377303773137732377333773437735377363773737738377393774037741377423774337744377453774637747377483774937750377513775237753377543775537756377573775837759377603776137762377633776437765377663776737768377693777037771377723777337774377753777637777377783777937780377813778237783377843778537786377873778837789377903779137792377933779437795377963779737798377993780037801378023780337804378053780637807378083780937810378113781237813378143781537816378173781837819378203782137822378233782437825378263782737828378293783037831378323783337834378353783637837378383783937840378413784237843378443784537846378473784837849378503785137852378533785437855378563785737858378593786037861378623786337864378653786637867378683786937870378713787237873378743787537876378773787837879378803788137882378833788437885378863788737888378893789037891378923789337894378953789637897378983789937900379013790237903379043790537906379073790837909379103791137912379133791437915379163791737918379193792037921379223792337924379253792637927379283792937930379313793237933379343793537936379373793837939379403794137942379433794437945379463794737948379493795037951379523795337954379553795637957379583795937960379613796237963379643796537966379673796837969379703797137972379733797437975379763797737978379793798037981379823798337984379853798637987379883798937990379913799237993379943799537996379973799837999380003800138002380033800438005380063800738008380093801038011380123801338014380153801638017380183801938020380213802238023380243802538026380273802838029380303803138032380333803438035380363803738038380393804038041380423804338044380453804638047380483804938050380513805238053380543805538056380573805838059380603806138062380633806438065380663806738068380693807038071380723807338074380753807638077380783807938080380813808238083380843808538086380873808838089380903809138092380933809438095380963809738098380993810038101381023810338104381053810638107381083810938110381113811238113381143811538116381173811838119381203812138122381233812438125381263812738128381293813038131381323813338134381353813638137381383813938140381413814238143381443814538146381473814838149381503815138152381533815438155381563815738158381593816038161381623816338164381653816638167381683816938170381713817238173381743817538176381773817838179381803818138182381833818438185381863818738188381893819038191381923819338194381953819638197381983819938200382013820238203382043820538206382073820838209382103821138212382133821438215382163821738218382193822038221382223822338224382253822638227382283822938230382313823238233382343823538236382373823838239382403824138242382433824438245382463824738248382493825038251382523825338254382553825638257382583825938260382613826238263382643826538266382673826838269382703827138272382733827438275382763827738278382793828038281382823828338284382853828638287382883828938290382913829238293382943829538296382973829838299383003830138302383033830438305383063830738308383093831038311383123831338314383153831638317383183831938320383213832238323383243832538326383273832838329383303833138332383333833438335383363833738338383393834038341383423834338344383453834638347383483834938350383513835238353383543835538356383573835838359383603836138362383633836438365383663836738368383693837038371383723837338374383753837638377383783837938380383813838238383383843838538386383873838838389383903839138392383933839438395383963839738398383993840038401384023840338404384053840638407384083840938410384113841238413384143841538416384173841838419384203842138422384233842438425384263842738428384293843038431384323843338434384353843638437384383843938440384413844238443384443844538446384473844838449384503845138452384533845438455384563845738458384593846038461384623846338464384653846638467384683846938470384713847238473384743847538476384773847838479384803848138482384833848438485384863848738488384893849038491384923849338494384953849638497384983849938500385013850238503385043850538506385073850838509385103851138512385133851438515385163851738518385193852038521385223852338524385253852638527385283852938530385313853238533385343853538536385373853838539385403854138542385433854438545385463854738548385493855038551385523855338554385553855638557385583855938560385613856238563385643856538566385673856838569385703857138572385733857438575385763857738578385793858038581385823858338584385853858638587385883858938590385913859238593385943859538596385973859838599386003860138602386033860438605386063860738608386093861038611386123861338614386153861638617386183861938620386213862238623386243862538626386273862838629386303863138632386333863438635386363863738638386393864038641386423864338644386453864638647386483864938650386513865238653386543865538656386573865838659386603866138662386633866438665386663866738668386693867038671386723867338674386753867638677386783867938680386813868238683386843868538686386873868838689386903869138692386933869438695386963869738698386993870038701387023870338704387053870638707387083870938710387113871238713387143871538716387173871838719387203872138722387233872438725387263872738728387293873038731387323873338734387353873638737387383873938740387413874238743387443874538746387473874838749387503875138752387533875438755387563875738758387593876038761387623876338764387653876638767387683876938770387713877238773387743877538776387773877838779387803878138782387833878438785387863878738788387893879038791387923879338794387953879638797387983879938800388013880238803388043880538806388073880838809388103881138812388133881438815388163881738818388193882038821388223882338824388253882638827388283882938830388313883238833388343883538836388373883838839388403884138842388433884438845388463884738848388493885038851388523885338854388553885638857388583885938860388613886238863388643886538866388673886838869388703887138872388733887438875388763887738878388793888038881388823888338884388853888638887388883888938890388913889238893388943889538896388973889838899389003890138902389033890438905389063890738908389093891038911389123891338914389153891638917389183891938920389213892238923389243892538926389273892838929389303893138932389333893438935389363893738938389393894038941389423894338944389453894638947389483894938950389513895238953389543895538956389573895838959389603896138962389633896438965389663896738968389693897038971389723897338974389753897638977389783897938980389813898238983389843898538986389873898838989389903899138992389933899438995389963899738998389993900039001390023900339004390053900639007390083900939010390113901239013390143901539016390173901839019390203902139022390233902439025390263902739028390293903039031390323903339034390353903639037390383903939040390413904239043390443904539046390473904839049390503905139052390533905439055390563905739058390593906039061390623906339064390653906639067390683906939070390713907239073390743907539076390773907839079390803908139082390833908439085390863908739088390893909039091390923909339094390953909639097390983909939100391013910239103391043910539106391073910839109391103911139112391133911439115391163911739118391193912039121391223912339124391253912639127391283912939130391313913239133391343913539136391373913839139391403914139142391433914439145391463914739148391493915039151391523915339154391553915639157391583915939160391613916239163391643916539166391673916839169391703917139172391733917439175391763917739178391793918039181391823918339184391853918639187391883918939190391913919239193391943919539196391973919839199392003920139202392033920439205392063920739208392093921039211392123921339214392153921639217392183921939220392213922239223392243922539226392273922839229392303923139232392333923439235392363923739238392393924039241392423924339244392453924639247392483924939250392513925239253392543925539256392573925839259392603926139262392633926439265392663926739268392693927039271392723927339274392753927639277392783927939280392813928239283392843928539286392873928839289392903929139292392933929439295392963929739298392993930039301393023930339304393053930639307393083930939310393113931239313393143931539316393173931839319393203932139322393233932439325393263932739328393293933039331393323933339334393353933639337393383933939340393413934239343393443934539346393473934839349393503935139352393533935439355393563935739358393593936039361393623936339364393653936639367393683936939370393713937239373393743937539376393773937839379393803938139382393833938439385393863938739388393893939039391393923939339394393953939639397393983939939400394013940239403394043940539406394073940839409394103941139412394133941439415394163941739418394193942039421394223942339424394253942639427394283942939430394313943239433394343943539436394373943839439394403944139442394433944439445394463944739448394493945039451394523945339454394553945639457394583945939460394613946239463394643946539466394673946839469394703947139472394733947439475394763947739478394793948039481394823948339484394853948639487394883948939490394913949239493394943949539496394973949839499395003950139502395033950439505395063950739508395093951039511395123951339514395153951639517395183951939520395213952239523395243952539526395273952839529395303953139532395333953439535395363953739538395393954039541395423954339544395453954639547395483954939550395513955239553395543955539556395573955839559395603956139562395633956439565395663956739568395693957039571395723957339574395753957639577395783957939580395813958239583395843958539586395873958839589395903959139592395933959439595395963959739598395993960039601396023960339604396053960639607396083960939610396113961239613396143961539616396173961839619396203962139622396233962439625396263962739628396293963039631396323963339634396353963639637396383963939640396413964239643396443964539646396473964839649396503965139652396533965439655396563965739658396593966039661396623966339664396653966639667396683966939670396713967239673396743967539676396773967839679396803968139682396833968439685396863968739688396893969039691396923969339694396953969639697396983969939700397013970239703397043970539706397073970839709397103971139712397133971439715397163971739718397193972039721397223972339724397253972639727397283972939730397313973239733397343973539736397373973839739397403974139742397433974439745397463974739748397493975039751397523975339754397553975639757397583975939760397613976239763397643976539766397673976839769397703977139772397733977439775397763977739778397793978039781397823978339784397853978639787397883978939790397913979239793397943979539796397973979839799398003980139802398033980439805398063980739808398093981039811398123981339814398153981639817398183981939820398213982239823398243982539826398273982839829398303983139832398333983439835398363983739838398393984039841398423984339844398453984639847398483984939850398513985239853398543985539856398573985839859398603986139862398633986439865398663986739868398693987039871398723987339874398753987639877398783987939880398813988239883398843988539886398873988839889398903989139892398933989439895398963989739898398993990039901399023990339904399053990639907399083990939910399113991239913399143991539916399173991839919399203992139922399233992439925399263992739928399293993039931399323993339934399353993639937399383993939940399413994239943399443994539946399473994839949399503995139952399533995439955399563995739958399593996039961399623996339964399653996639967399683996939970399713997239973399743997539976399773997839979399803998139982399833998439985399863998739988399893999039991399923999339994399953999639997399983999940000400014000240003400044000540006400074000840009400104001140012400134001440015400164001740018400194002040021400224002340024400254002640027400284002940030400314003240033400344003540036400374003840039400404004140042400434004440045400464004740048400494005040051400524005340054400554005640057400584005940060400614006240063400644006540066400674006840069400704007140072400734007440075400764007740078400794008040081400824008340084400854008640087400884008940090400914009240093400944009540096400974009840099401004010140102401034010440105401064010740108401094011040111401124011340114401154011640117401184011940120401214012240123401244012540126401274012840129401304013140132401334013440135401364013740138401394014040141401424014340144401454014640147401484014940150401514015240153401544015540156401574015840159401604016140162401634016440165401664016740168401694017040171401724017340174401754017640177401784017940180401814018240183401844018540186401874018840189401904019140192401934019440195401964019740198401994020040201402024020340204402054020640207402084020940210402114021240213402144021540216402174021840219402204022140222402234022440225402264022740228402294023040231402324023340234402354023640237402384023940240402414024240243402444024540246402474024840249402504025140252402534025440255402564025740258402594026040261402624026340264402654026640267402684026940270402714027240273402744027540276402774027840279402804028140282402834028440285402864028740288402894029040291402924029340294402954029640297402984029940300403014030240303403044030540306403074030840309403104031140312403134031440315403164031740318403194032040321403224032340324403254032640327403284032940330403314033240333403344033540336403374033840339403404034140342403434034440345403464034740348403494035040351403524035340354403554035640357403584035940360403614036240363403644036540366403674036840369403704037140372403734037440375403764037740378403794038040381403824038340384403854038640387403884038940390403914039240393403944039540396403974039840399404004040140402404034040440405404064040740408404094041040411404124041340414404154041640417404184041940420404214042240423404244042540426404274042840429404304043140432404334043440435404364043740438404394044040441404424044340444404454044640447404484044940450404514045240453404544045540456404574045840459404604046140462404634046440465404664046740468404694047040471404724047340474404754047640477404784047940480404814048240483404844048540486404874048840489404904049140492404934049440495404964049740498404994050040501405024050340504405054050640507405084050940510405114051240513405144051540516405174051840519405204052140522405234052440525405264052740528405294053040531405324053340534405354053640537405384053940540405414054240543405444054540546405474054840549405504055140552405534055440555405564055740558405594056040561405624056340564405654056640567405684056940570405714057240573405744057540576405774057840579405804058140582405834058440585405864058740588405894059040591405924059340594405954059640597405984059940600406014060240603406044060540606406074060840609406104061140612406134061440615406164061740618406194062040621406224062340624406254062640627406284062940630406314063240633406344063540636406374063840639406404064140642406434064440645406464064740648406494065040651406524065340654406554065640657406584065940660406614066240663406644066540666406674066840669406704067140672406734067440675406764067740678406794068040681406824068340684406854068640687406884068940690406914069240693406944069540696406974069840699407004070140702407034070440705407064070740708407094071040711407124071340714407154071640717407184071940720407214072240723407244072540726407274072840729407304073140732407334073440735407364073740738407394074040741407424074340744407454074640747407484074940750407514075240753407544075540756407574075840759407604076140762407634076440765407664076740768407694077040771407724077340774407754077640777407784077940780407814078240783407844078540786407874078840789407904079140792407934079440795407964079740798407994080040801408024080340804408054080640807408084080940810408114081240813408144081540816408174081840819408204082140822408234082440825408264082740828408294083040831408324083340834408354083640837408384083940840408414084240843408444084540846408474084840849408504085140852408534085440855408564085740858408594086040861408624086340864408654086640867408684086940870408714087240873408744087540876408774087840879408804088140882408834088440885408864088740888408894089040891408924089340894408954089640897408984089940900409014090240903409044090540906409074090840909409104091140912409134091440915409164091740918409194092040921409224092340924409254092640927409284092940930409314093240933409344093540936409374093840939409404094140942409434094440945409464094740948409494095040951409524095340954409554095640957409584095940960409614096240963409644096540966409674096840969409704097140972409734097440975409764097740978409794098040981409824098340984409854098640987409884098940990409914099240993409944099540996409974099840999410004100141002410034100441005410064100741008410094101041011410124101341014410154101641017410184101941020410214102241023410244102541026410274102841029410304103141032410334103441035410364103741038410394104041041410424104341044410454104641047410484104941050410514105241053410544105541056410574105841059410604106141062410634106441065410664106741068410694107041071410724107341074410754107641077410784107941080410814108241083410844108541086410874108841089410904109141092410934109441095410964109741098410994110041101411024110341104411054110641107411084110941110411114111241113411144111541116411174111841119411204112141122411234112441125411264112741128411294113041131411324113341134411354113641137411384113941140411414114241143411444114541146411474114841149411504115141152411534115441155411564115741158411594116041161411624116341164411654116641167411684116941170411714117241173411744117541176411774117841179411804118141182411834118441185411864118741188411894119041191411924119341194411954119641197411984119941200412014120241203412044120541206412074120841209412104121141212412134121441215412164121741218412194122041221412224122341224412254122641227412284122941230412314123241233412344123541236412374123841239412404124141242412434124441245412464124741248412494125041251412524125341254412554125641257412584125941260412614126241263412644126541266412674126841269412704127141272412734127441275412764127741278412794128041281412824128341284412854128641287412884128941290412914129241293412944129541296412974129841299413004130141302413034130441305413064130741308413094131041311413124131341314413154131641317413184131941320413214132241323413244132541326413274132841329413304133141332413334133441335413364133741338413394134041341413424134341344413454134641347413484134941350413514135241353413544135541356413574135841359413604136141362413634136441365413664136741368413694137041371413724137341374413754137641377413784137941380413814138241383413844138541386413874138841389413904139141392413934139441395413964139741398413994140041401414024140341404414054140641407414084140941410414114141241413414144141541416414174141841419414204142141422414234142441425414264142741428414294143041431414324143341434414354143641437414384143941440414414144241443414444144541446414474144841449414504145141452414534145441455414564145741458414594146041461414624146341464414654146641467414684146941470414714147241473414744147541476414774147841479414804148141482414834148441485414864148741488414894149041491414924149341494414954149641497414984149941500415014150241503415044150541506415074150841509415104151141512415134151441515415164151741518415194152041521415224152341524415254152641527415284152941530415314153241533415344153541536415374153841539415404154141542415434154441545415464154741548415494155041551415524155341554415554155641557415584155941560415614156241563415644156541566415674156841569415704157141572415734157441575415764157741578415794158041581415824158341584415854158641587415884158941590415914159241593415944159541596415974159841599416004160141602416034160441605416064160741608416094161041611416124161341614416154161641617416184161941620416214162241623416244162541626416274162841629416304163141632416334163441635416364163741638416394164041641416424164341644416454164641647416484164941650416514165241653416544165541656416574165841659416604166141662416634166441665416664166741668416694167041671416724167341674416754167641677416784167941680416814168241683416844168541686416874168841689416904169141692416934169441695416964169741698416994170041701417024170341704417054170641707417084170941710417114171241713417144171541716417174171841719417204172141722417234172441725417264172741728417294173041731417324173341734417354173641737417384173941740417414174241743417444174541746417474174841749417504175141752417534175441755417564175741758417594176041761
  1. // File:src/Three.js
  2. /**
  3. * @author mrdoob / http://mrdoob.com/
  4. */
  5. var THREE = { REVISION: '79dev' };
  6. //
  7. if ( typeof define === 'function' && define.amd ) {
  8. define( 'three', THREE );
  9. } else if ( 'undefined' !== typeof exports && 'undefined' !== typeof module ) {
  10. module.exports = THREE;
  11. }
  12. // Polyfills
  13. if ( Number.EPSILON === undefined ) {
  14. Number.EPSILON = Math.pow( 2, - 52 );
  15. }
  16. //
  17. if ( Math.sign === undefined ) {
  18. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
  19. Math.sign = function ( x ) {
  20. return ( x < 0 ) ? - 1 : ( x > 0 ) ? 1 : + x;
  21. };
  22. }
  23. if ( Function.prototype.name === undefined ) {
  24. // Missing in IE9-11.
  25. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
  26. Object.defineProperty( Function.prototype, 'name', {
  27. get: function () {
  28. return this.toString().match( /^\s*function\s*(\S*)\s*\(/ )[ 1 ];
  29. }
  30. } );
  31. }
  32. if ( Object.assign === undefined ) {
  33. // Missing in IE.
  34. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
  35. ( function () {
  36. Object.assign = function ( target ) {
  37. 'use strict';
  38. if ( target === undefined || target === null ) {
  39. throw new TypeError( 'Cannot convert undefined or null to object' );
  40. }
  41. var output = Object( target );
  42. for ( var index = 1; index < arguments.length; index ++ ) {
  43. var source = arguments[ index ];
  44. if ( source !== undefined && source !== null ) {
  45. for ( var nextKey in source ) {
  46. if ( Object.prototype.hasOwnProperty.call( source, nextKey ) ) {
  47. output[ nextKey ] = source[ nextKey ];
  48. }
  49. }
  50. }
  51. }
  52. return output;
  53. };
  54. } )();
  55. }
  56. //
  57. Object.assign( THREE, {
  58. // https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent.button
  59. MOUSE: { LEFT: 0, MIDDLE: 1, RIGHT: 2 },
  60. // GL STATE CONSTANTS
  61. CullFaceNone: 0,
  62. CullFaceBack: 1,
  63. CullFaceFront: 2,
  64. CullFaceFrontBack: 3,
  65. FrontFaceDirectionCW: 0,
  66. FrontFaceDirectionCCW: 1,
  67. // SHADOWING TYPES
  68. BasicShadowMap: 0,
  69. PCFShadowMap: 1,
  70. PCFSoftShadowMap: 2,
  71. // MATERIAL CONSTANTS
  72. // side
  73. FrontSide: 0,
  74. BackSide: 1,
  75. DoubleSide: 2,
  76. // shading
  77. FlatShading: 1,
  78. SmoothShading: 2,
  79. // colors
  80. NoColors: 0,
  81. FaceColors: 1,
  82. VertexColors: 2,
  83. // blending modes
  84. NoBlending: 0,
  85. NormalBlending: 1,
  86. AdditiveBlending: 2,
  87. SubtractiveBlending: 3,
  88. MultiplyBlending: 4,
  89. CustomBlending: 5,
  90. // custom blending equations
  91. // (numbers start from 100 not to clash with other
  92. // mappings to OpenGL constants defined in Texture.js)
  93. AddEquation: 100,
  94. SubtractEquation: 101,
  95. ReverseSubtractEquation: 102,
  96. MinEquation: 103,
  97. MaxEquation: 104,
  98. // custom blending destination factors
  99. ZeroFactor: 200,
  100. OneFactor: 201,
  101. SrcColorFactor: 202,
  102. OneMinusSrcColorFactor: 203,
  103. SrcAlphaFactor: 204,
  104. OneMinusSrcAlphaFactor: 205,
  105. DstAlphaFactor: 206,
  106. OneMinusDstAlphaFactor: 207,
  107. // custom blending source factors
  108. //ZeroFactor: 200,
  109. //OneFactor: 201,
  110. //SrcAlphaFactor: 204,
  111. //OneMinusSrcAlphaFactor: 205,
  112. //DstAlphaFactor: 206,
  113. //OneMinusDstAlphaFactor: 207,
  114. DstColorFactor: 208,
  115. OneMinusDstColorFactor: 209,
  116. SrcAlphaSaturateFactor: 210,
  117. // depth modes
  118. NeverDepth: 0,
  119. AlwaysDepth: 1,
  120. LessDepth: 2,
  121. LessEqualDepth: 3,
  122. EqualDepth: 4,
  123. GreaterEqualDepth: 5,
  124. GreaterDepth: 6,
  125. NotEqualDepth: 7,
  126. // TEXTURE CONSTANTS
  127. MultiplyOperation: 0,
  128. MixOperation: 1,
  129. AddOperation: 2,
  130. // Tone Mapping modes
  131. NoToneMapping: 0, // do not do any tone mapping, not even exposure (required for special purpose passes.)
  132. LinearToneMapping: 1, // only apply exposure.
  133. ReinhardToneMapping: 2,
  134. Uncharted2ToneMapping: 3, // John Hable
  135. CineonToneMapping: 4, // optimized filmic operator by Jim Hejl and Richard Burgess-Dawson
  136. // Mapping modes
  137. UVMapping: 300,
  138. CubeReflectionMapping: 301,
  139. CubeRefractionMapping: 302,
  140. EquirectangularReflectionMapping: 303,
  141. EquirectangularRefractionMapping: 304,
  142. SphericalReflectionMapping: 305,
  143. CubeUVReflectionMapping: 306,
  144. CubeUVRefractionMapping: 307,
  145. // Wrapping modes
  146. RepeatWrapping: 1000,
  147. ClampToEdgeWrapping: 1001,
  148. MirroredRepeatWrapping: 1002,
  149. // Filters
  150. NearestFilter: 1003,
  151. NearestMipMapNearestFilter: 1004,
  152. NearestMipMapLinearFilter: 1005,
  153. LinearFilter: 1006,
  154. LinearMipMapNearestFilter: 1007,
  155. LinearMipMapLinearFilter: 1008,
  156. // Data types
  157. UnsignedByteType: 1009,
  158. ByteType: 1010,
  159. ShortType: 1011,
  160. UnsignedShortType: 1012,
  161. IntType: 1013,
  162. UnsignedIntType: 1014,
  163. FloatType: 1015,
  164. HalfFloatType: 1025,
  165. // Pixel types
  166. //UnsignedByteType: 1009,
  167. UnsignedShort4444Type: 1016,
  168. UnsignedShort5551Type: 1017,
  169. UnsignedShort565Type: 1018,
  170. // Pixel formats
  171. AlphaFormat: 1019,
  172. RGBFormat: 1020,
  173. RGBAFormat: 1021,
  174. LuminanceFormat: 1022,
  175. LuminanceAlphaFormat: 1023,
  176. // THREE.RGBEFormat handled as THREE.RGBAFormat in shaders
  177. RGBEFormat: THREE.RGBAFormat, //1024;
  178. DepthFormat: 1026,
  179. // DDS / ST3C Compressed texture formats
  180. RGB_S3TC_DXT1_Format: 2001,
  181. RGBA_S3TC_DXT1_Format: 2002,
  182. RGBA_S3TC_DXT3_Format: 2003,
  183. RGBA_S3TC_DXT5_Format: 2004,
  184. // PVRTC compressed texture formats
  185. RGB_PVRTC_4BPPV1_Format: 2100,
  186. RGB_PVRTC_2BPPV1_Format: 2101,
  187. RGBA_PVRTC_4BPPV1_Format: 2102,
  188. RGBA_PVRTC_2BPPV1_Format: 2103,
  189. // ETC compressed texture formats
  190. RGB_ETC1_Format: 2151,
  191. // Loop styles for AnimationAction
  192. LoopOnce: 2200,
  193. LoopRepeat: 2201,
  194. LoopPingPong: 2202,
  195. // Interpolation
  196. InterpolateDiscrete: 2300,
  197. InterpolateLinear: 2301,
  198. InterpolateSmooth: 2302,
  199. // Interpolant ending modes
  200. ZeroCurvatureEnding: 2400,
  201. ZeroSlopeEnding: 2401,
  202. WrapAroundEnding: 2402,
  203. // Triangle Draw modes
  204. TrianglesDrawMode: 0,
  205. TriangleStripDrawMode: 1,
  206. TriangleFanDrawMode: 2,
  207. // Texture Encodings
  208. LinearEncoding: 3000, // No encoding at all.
  209. sRGBEncoding: 3001,
  210. GammaEncoding: 3007, // uses GAMMA_FACTOR, for backwards compatibility with WebGLRenderer.gammaInput/gammaOutput
  211. // The following Texture Encodings are for RGB-only (no alpha) HDR light emission sources.
  212. // These encodings should not specified as output encodings except in rare situations.
  213. RGBEEncoding: 3002, // AKA Radiance.
  214. LogLuvEncoding: 3003,
  215. RGBM7Encoding: 3004,
  216. RGBM16Encoding: 3005,
  217. RGBDEncoding: 3006, // MaxRange is 256.
  218. // Depth packing strategies
  219. BasicDepthPacking: 3200, // for writing to float textures for high precision or for visualizing results in RGB buffers
  220. RGBADepthPacking: 3201 // for packing into RGBA buffers.
  221. } );
  222. // File:src/math/Color.js
  223. /**
  224. * @author mrdoob / http://mrdoob.com/
  225. */
  226. THREE.Color = function ( r, g, b ) {
  227. if ( g === undefined && b === undefined ) {
  228. // r is THREE.Color, hex or string
  229. return this.set( r );
  230. }
  231. return this.setRGB( r, g, b );
  232. };
  233. THREE.Color.prototype = {
  234. constructor: THREE.Color,
  235. r: 1, g: 1, b: 1,
  236. set: function ( value ) {
  237. if ( value instanceof THREE.Color ) {
  238. this.copy( value );
  239. } else if ( typeof value === 'number' ) {
  240. this.setHex( value );
  241. } else if ( typeof value === 'string' ) {
  242. this.setStyle( value );
  243. }
  244. return this;
  245. },
  246. setScalar: function ( scalar ) {
  247. this.r = scalar;
  248. this.g = scalar;
  249. this.b = scalar;
  250. },
  251. setHex: function ( hex ) {
  252. hex = Math.floor( hex );
  253. this.r = ( hex >> 16 & 255 ) / 255;
  254. this.g = ( hex >> 8 & 255 ) / 255;
  255. this.b = ( hex & 255 ) / 255;
  256. return this;
  257. },
  258. setRGB: function ( r, g, b ) {
  259. this.r = r;
  260. this.g = g;
  261. this.b = b;
  262. return this;
  263. },
  264. setHSL: function () {
  265. function hue2rgb( p, q, t ) {
  266. if ( t < 0 ) t += 1;
  267. if ( t > 1 ) t -= 1;
  268. if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
  269. if ( t < 1 / 2 ) return q;
  270. if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
  271. return p;
  272. }
  273. return function setHSL( h, s, l ) {
  274. // h,s,l ranges are in 0.0 - 1.0
  275. h = THREE.Math.euclideanModulo( h, 1 );
  276. s = THREE.Math.clamp( s, 0, 1 );
  277. l = THREE.Math.clamp( l, 0, 1 );
  278. if ( s === 0 ) {
  279. this.r = this.g = this.b = l;
  280. } else {
  281. var p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  282. var q = ( 2 * l ) - p;
  283. this.r = hue2rgb( q, p, h + 1 / 3 );
  284. this.g = hue2rgb( q, p, h );
  285. this.b = hue2rgb( q, p, h - 1 / 3 );
  286. }
  287. return this;
  288. };
  289. }(),
  290. setStyle: function ( style ) {
  291. function handleAlpha( string ) {
  292. if ( string === undefined ) return;
  293. if ( parseFloat( string ) < 1 ) {
  294. console.warn( 'THREE.Color: Alpha component of ' + style + ' will be ignored.' );
  295. }
  296. }
  297. var m;
  298. if ( m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec( style ) ) {
  299. // rgb / hsl
  300. var color;
  301. var name = m[ 1 ];
  302. var components = m[ 2 ];
  303. switch ( name ) {
  304. case 'rgb':
  305. case 'rgba':
  306. if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  307. // rgb(255,0,0) rgba(255,0,0,0.5)
  308. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  309. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  310. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  311. handleAlpha( color[ 5 ] );
  312. return this;
  313. }
  314. if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  315. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  316. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  317. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  318. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  319. handleAlpha( color[ 5 ] );
  320. return this;
  321. }
  322. break;
  323. case 'hsl':
  324. case 'hsla':
  325. if ( color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  326. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  327. var h = parseFloat( color[ 1 ] ) / 360;
  328. var s = parseInt( color[ 2 ], 10 ) / 100;
  329. var l = parseInt( color[ 3 ], 10 ) / 100;
  330. handleAlpha( color[ 5 ] );
  331. return this.setHSL( h, s, l );
  332. }
  333. break;
  334. }
  335. } else if ( m = /^\#([A-Fa-f0-9]+)$/.exec( style ) ) {
  336. // hex color
  337. var hex = m[ 1 ];
  338. var size = hex.length;
  339. if ( size === 3 ) {
  340. // #ff0
  341. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 0 ), 16 ) / 255;
  342. this.g = parseInt( hex.charAt( 1 ) + hex.charAt( 1 ), 16 ) / 255;
  343. this.b = parseInt( hex.charAt( 2 ) + hex.charAt( 2 ), 16 ) / 255;
  344. return this;
  345. } else if ( size === 6 ) {
  346. // #ff0000
  347. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 1 ), 16 ) / 255;
  348. this.g = parseInt( hex.charAt( 2 ) + hex.charAt( 3 ), 16 ) / 255;
  349. this.b = parseInt( hex.charAt( 4 ) + hex.charAt( 5 ), 16 ) / 255;
  350. return this;
  351. }
  352. }
  353. if ( style && style.length > 0 ) {
  354. // color keywords
  355. var hex = THREE.ColorKeywords[ style ];
  356. if ( hex !== undefined ) {
  357. // red
  358. this.setHex( hex );
  359. } else {
  360. // unknown color
  361. console.warn( 'THREE.Color: Unknown color ' + style );
  362. }
  363. }
  364. return this;
  365. },
  366. clone: function () {
  367. return new this.constructor( this.r, this.g, this.b );
  368. },
  369. copy: function ( color ) {
  370. this.r = color.r;
  371. this.g = color.g;
  372. this.b = color.b;
  373. return this;
  374. },
  375. copyGammaToLinear: function ( color, gammaFactor ) {
  376. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  377. this.r = Math.pow( color.r, gammaFactor );
  378. this.g = Math.pow( color.g, gammaFactor );
  379. this.b = Math.pow( color.b, gammaFactor );
  380. return this;
  381. },
  382. copyLinearToGamma: function ( color, gammaFactor ) {
  383. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  384. var safeInverse = ( gammaFactor > 0 ) ? ( 1.0 / gammaFactor ) : 1.0;
  385. this.r = Math.pow( color.r, safeInverse );
  386. this.g = Math.pow( color.g, safeInverse );
  387. this.b = Math.pow( color.b, safeInverse );
  388. return this;
  389. },
  390. convertGammaToLinear: function () {
  391. var r = this.r, g = this.g, b = this.b;
  392. this.r = r * r;
  393. this.g = g * g;
  394. this.b = b * b;
  395. return this;
  396. },
  397. convertLinearToGamma: function () {
  398. this.r = Math.sqrt( this.r );
  399. this.g = Math.sqrt( this.g );
  400. this.b = Math.sqrt( this.b );
  401. return this;
  402. },
  403. getHex: function () {
  404. return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
  405. },
  406. getHexString: function () {
  407. return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
  408. },
  409. getHSL: function ( optionalTarget ) {
  410. // h,s,l ranges are in 0.0 - 1.0
  411. var hsl = optionalTarget || { h: 0, s: 0, l: 0 };
  412. var r = this.r, g = this.g, b = this.b;
  413. var max = Math.max( r, g, b );
  414. var min = Math.min( r, g, b );
  415. var hue, saturation;
  416. var lightness = ( min + max ) / 2.0;
  417. if ( min === max ) {
  418. hue = 0;
  419. saturation = 0;
  420. } else {
  421. var delta = max - min;
  422. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  423. switch ( max ) {
  424. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  425. case g: hue = ( b - r ) / delta + 2; break;
  426. case b: hue = ( r - g ) / delta + 4; break;
  427. }
  428. hue /= 6;
  429. }
  430. hsl.h = hue;
  431. hsl.s = saturation;
  432. hsl.l = lightness;
  433. return hsl;
  434. },
  435. getStyle: function () {
  436. return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
  437. },
  438. offsetHSL: function ( h, s, l ) {
  439. var hsl = this.getHSL();
  440. hsl.h += h; hsl.s += s; hsl.l += l;
  441. this.setHSL( hsl.h, hsl.s, hsl.l );
  442. return this;
  443. },
  444. add: function ( color ) {
  445. this.r += color.r;
  446. this.g += color.g;
  447. this.b += color.b;
  448. return this;
  449. },
  450. addColors: function ( color1, color2 ) {
  451. this.r = color1.r + color2.r;
  452. this.g = color1.g + color2.g;
  453. this.b = color1.b + color2.b;
  454. return this;
  455. },
  456. addScalar: function ( s ) {
  457. this.r += s;
  458. this.g += s;
  459. this.b += s;
  460. return this;
  461. },
  462. sub: function( color ) {
  463. this.r = Math.max( 0, this.r - color.r );
  464. this.g = Math.max( 0, this.g - color.g );
  465. this.b = Math.max( 0, this.b - color.b );
  466. return this;
  467. },
  468. multiply: function ( color ) {
  469. this.r *= color.r;
  470. this.g *= color.g;
  471. this.b *= color.b;
  472. return this;
  473. },
  474. multiplyScalar: function ( s ) {
  475. this.r *= s;
  476. this.g *= s;
  477. this.b *= s;
  478. return this;
  479. },
  480. lerp: function ( color, alpha ) {
  481. this.r += ( color.r - this.r ) * alpha;
  482. this.g += ( color.g - this.g ) * alpha;
  483. this.b += ( color.b - this.b ) * alpha;
  484. return this;
  485. },
  486. equals: function ( c ) {
  487. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  488. },
  489. fromArray: function ( array, offset ) {
  490. if ( offset === undefined ) offset = 0;
  491. this.r = array[ offset ];
  492. this.g = array[ offset + 1 ];
  493. this.b = array[ offset + 2 ];
  494. return this;
  495. },
  496. toArray: function ( array, offset ) {
  497. if ( array === undefined ) array = [];
  498. if ( offset === undefined ) offset = 0;
  499. array[ offset ] = this.r;
  500. array[ offset + 1 ] = this.g;
  501. array[ offset + 2 ] = this.b;
  502. return array;
  503. }
  504. };
  505. THREE.ColorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  506. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  507. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  508. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  509. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  510. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  511. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  512. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  513. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  514. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  515. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  516. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  517. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  518. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  519. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  520. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  521. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  522. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  523. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  524. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  525. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  526. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  527. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  528. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  529. // File:src/math/Quaternion.js
  530. /**
  531. * @author mikael emtinger / http://gomo.se/
  532. * @author alteredq / http://alteredqualia.com/
  533. * @author WestLangley / http://github.com/WestLangley
  534. * @author bhouston / http://clara.io
  535. */
  536. THREE.Quaternion = function ( x, y, z, w ) {
  537. this._x = x || 0;
  538. this._y = y || 0;
  539. this._z = z || 0;
  540. this._w = ( w !== undefined ) ? w : 1;
  541. };
  542. THREE.Quaternion.prototype = {
  543. constructor: THREE.Quaternion,
  544. get x () {
  545. return this._x;
  546. },
  547. set x ( value ) {
  548. this._x = value;
  549. this.onChangeCallback();
  550. },
  551. get y () {
  552. return this._y;
  553. },
  554. set y ( value ) {
  555. this._y = value;
  556. this.onChangeCallback();
  557. },
  558. get z () {
  559. return this._z;
  560. },
  561. set z ( value ) {
  562. this._z = value;
  563. this.onChangeCallback();
  564. },
  565. get w () {
  566. return this._w;
  567. },
  568. set w ( value ) {
  569. this._w = value;
  570. this.onChangeCallback();
  571. },
  572. set: function ( x, y, z, w ) {
  573. this._x = x;
  574. this._y = y;
  575. this._z = z;
  576. this._w = w;
  577. this.onChangeCallback();
  578. return this;
  579. },
  580. clone: function () {
  581. return new this.constructor( this._x, this._y, this._z, this._w );
  582. },
  583. copy: function ( quaternion ) {
  584. this._x = quaternion.x;
  585. this._y = quaternion.y;
  586. this._z = quaternion.z;
  587. this._w = quaternion.w;
  588. this.onChangeCallback();
  589. return this;
  590. },
  591. setFromEuler: function ( euler, update ) {
  592. if ( euler instanceof THREE.Euler === false ) {
  593. throw new Error( 'THREE.Quaternion: .setFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  594. }
  595. // http://www.mathworks.com/matlabcentral/fileexchange/
  596. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  597. // content/SpinCalc.m
  598. var c1 = Math.cos( euler._x / 2 );
  599. var c2 = Math.cos( euler._y / 2 );
  600. var c3 = Math.cos( euler._z / 2 );
  601. var s1 = Math.sin( euler._x / 2 );
  602. var s2 = Math.sin( euler._y / 2 );
  603. var s3 = Math.sin( euler._z / 2 );
  604. var order = euler.order;
  605. if ( order === 'XYZ' ) {
  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 === 'YXZ' ) {
  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 === 'ZXY' ) {
  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 === 'ZYX' ) {
  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 === 'YZX' ) {
  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. } else if ( order === 'XZY' ) {
  631. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  632. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  633. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  634. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  635. }
  636. if ( update !== false ) this.onChangeCallback();
  637. return this;
  638. },
  639. setFromAxisAngle: function ( axis, angle ) {
  640. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  641. // assumes axis is normalized
  642. var halfAngle = angle / 2, s = Math.sin( halfAngle );
  643. this._x = axis.x * s;
  644. this._y = axis.y * s;
  645. this._z = axis.z * s;
  646. this._w = Math.cos( halfAngle );
  647. this.onChangeCallback();
  648. return this;
  649. },
  650. setFromRotationMatrix: function ( m ) {
  651. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  652. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  653. var te = m.elements,
  654. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  655. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  656. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ],
  657. trace = m11 + m22 + m33,
  658. s;
  659. if ( trace > 0 ) {
  660. s = 0.5 / Math.sqrt( trace + 1.0 );
  661. this._w = 0.25 / s;
  662. this._x = ( m32 - m23 ) * s;
  663. this._y = ( m13 - m31 ) * s;
  664. this._z = ( m21 - m12 ) * s;
  665. } else if ( m11 > m22 && m11 > m33 ) {
  666. s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );
  667. this._w = ( m32 - m23 ) / s;
  668. this._x = 0.25 * s;
  669. this._y = ( m12 + m21 ) / s;
  670. this._z = ( m13 + m31 ) / s;
  671. } else if ( m22 > m33 ) {
  672. s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );
  673. this._w = ( m13 - m31 ) / s;
  674. this._x = ( m12 + m21 ) / s;
  675. this._y = 0.25 * s;
  676. this._z = ( m23 + m32 ) / s;
  677. } else {
  678. s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );
  679. this._w = ( m21 - m12 ) / s;
  680. this._x = ( m13 + m31 ) / s;
  681. this._y = ( m23 + m32 ) / s;
  682. this._z = 0.25 * s;
  683. }
  684. this.onChangeCallback();
  685. return this;
  686. },
  687. setFromUnitVectors: function () {
  688. // http://lolengine.net/blog/2014/02/24/quaternion-from-two-vectors-final
  689. // assumes direction vectors vFrom and vTo are normalized
  690. var v1, r;
  691. var EPS = 0.000001;
  692. return function setFromUnitVectors( vFrom, vTo ) {
  693. if ( v1 === undefined ) v1 = new THREE.Vector3();
  694. r = vFrom.dot( vTo ) + 1;
  695. if ( r < EPS ) {
  696. r = 0;
  697. if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) {
  698. v1.set( - vFrom.y, vFrom.x, 0 );
  699. } else {
  700. v1.set( 0, - vFrom.z, vFrom.y );
  701. }
  702. } else {
  703. v1.crossVectors( vFrom, vTo );
  704. }
  705. this._x = v1.x;
  706. this._y = v1.y;
  707. this._z = v1.z;
  708. this._w = r;
  709. return this.normalize();
  710. };
  711. }(),
  712. inverse: function () {
  713. return this.conjugate().normalize();
  714. },
  715. conjugate: function () {
  716. this._x *= - 1;
  717. this._y *= - 1;
  718. this._z *= - 1;
  719. this.onChangeCallback();
  720. return this;
  721. },
  722. dot: function ( v ) {
  723. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  724. },
  725. lengthSq: function () {
  726. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  727. },
  728. length: function () {
  729. return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );
  730. },
  731. normalize: function () {
  732. var l = this.length();
  733. if ( l === 0 ) {
  734. this._x = 0;
  735. this._y = 0;
  736. this._z = 0;
  737. this._w = 1;
  738. } else {
  739. l = 1 / l;
  740. this._x = this._x * l;
  741. this._y = this._y * l;
  742. this._z = this._z * l;
  743. this._w = this._w * l;
  744. }
  745. this.onChangeCallback();
  746. return this;
  747. },
  748. multiply: function ( q, p ) {
  749. if ( p !== undefined ) {
  750. console.warn( 'THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.' );
  751. return this.multiplyQuaternions( q, p );
  752. }
  753. return this.multiplyQuaternions( this, q );
  754. },
  755. premultiply: function ( q ) {
  756. return this.multiplyQuaternions( q, this );
  757. },
  758. multiplyQuaternions: function ( a, b ) {
  759. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  760. var qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
  761. var qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
  762. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  763. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  764. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  765. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  766. this.onChangeCallback();
  767. return this;
  768. },
  769. slerp: function ( qb, t ) {
  770. if ( t === 0 ) return this;
  771. if ( t === 1 ) return this.copy( qb );
  772. var x = this._x, y = this._y, z = this._z, w = this._w;
  773. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  774. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  775. if ( cosHalfTheta < 0 ) {
  776. this._w = - qb._w;
  777. this._x = - qb._x;
  778. this._y = - qb._y;
  779. this._z = - qb._z;
  780. cosHalfTheta = - cosHalfTheta;
  781. } else {
  782. this.copy( qb );
  783. }
  784. if ( cosHalfTheta >= 1.0 ) {
  785. this._w = w;
  786. this._x = x;
  787. this._y = y;
  788. this._z = z;
  789. return this;
  790. }
  791. var sinHalfTheta = Math.sqrt( 1.0 - cosHalfTheta * cosHalfTheta );
  792. if ( Math.abs( sinHalfTheta ) < 0.001 ) {
  793. this._w = 0.5 * ( w + this._w );
  794. this._x = 0.5 * ( x + this._x );
  795. this._y = 0.5 * ( y + this._y );
  796. this._z = 0.5 * ( z + this._z );
  797. return this;
  798. }
  799. var halfTheta = Math.atan2( sinHalfTheta, cosHalfTheta );
  800. var ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  801. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  802. this._w = ( w * ratioA + this._w * ratioB );
  803. this._x = ( x * ratioA + this._x * ratioB );
  804. this._y = ( y * ratioA + this._y * ratioB );
  805. this._z = ( z * ratioA + this._z * ratioB );
  806. this.onChangeCallback();
  807. return this;
  808. },
  809. equals: function ( quaternion ) {
  810. return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
  811. },
  812. fromArray: function ( array, offset ) {
  813. if ( offset === undefined ) offset = 0;
  814. this._x = array[ offset ];
  815. this._y = array[ offset + 1 ];
  816. this._z = array[ offset + 2 ];
  817. this._w = array[ offset + 3 ];
  818. this.onChangeCallback();
  819. return this;
  820. },
  821. toArray: function ( array, offset ) {
  822. if ( array === undefined ) array = [];
  823. if ( offset === undefined ) offset = 0;
  824. array[ offset ] = this._x;
  825. array[ offset + 1 ] = this._y;
  826. array[ offset + 2 ] = this._z;
  827. array[ offset + 3 ] = this._w;
  828. return array;
  829. },
  830. onChange: function ( callback ) {
  831. this.onChangeCallback = callback;
  832. return this;
  833. },
  834. onChangeCallback: function () {}
  835. };
  836. Object.assign( THREE.Quaternion, {
  837. slerp: function( qa, qb, qm, t ) {
  838. return qm.copy( qa ).slerp( qb, t );
  839. },
  840. slerpFlat: function(
  841. dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t ) {
  842. // fuzz-free, array-based Quaternion SLERP operation
  843. var x0 = src0[ srcOffset0 + 0 ],
  844. y0 = src0[ srcOffset0 + 1 ],
  845. z0 = src0[ srcOffset0 + 2 ],
  846. w0 = src0[ srcOffset0 + 3 ],
  847. x1 = src1[ srcOffset1 + 0 ],
  848. y1 = src1[ srcOffset1 + 1 ],
  849. z1 = src1[ srcOffset1 + 2 ],
  850. w1 = src1[ srcOffset1 + 3 ];
  851. if ( w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1 ) {
  852. var s = 1 - t,
  853. cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  854. dir = ( cos >= 0 ? 1 : - 1 ),
  855. sqrSin = 1 - cos * cos;
  856. // Skip the Slerp for tiny steps to avoid numeric problems:
  857. if ( sqrSin > Number.EPSILON ) {
  858. var sin = Math.sqrt( sqrSin ),
  859. len = Math.atan2( sin, cos * dir );
  860. s = Math.sin( s * len ) / sin;
  861. t = Math.sin( t * len ) / sin;
  862. }
  863. var tDir = t * dir;
  864. x0 = x0 * s + x1 * tDir;
  865. y0 = y0 * s + y1 * tDir;
  866. z0 = z0 * s + z1 * tDir;
  867. w0 = w0 * s + w1 * tDir;
  868. // Normalize in case we just did a lerp:
  869. if ( s === 1 - t ) {
  870. var f = 1 / Math.sqrt( x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0 );
  871. x0 *= f;
  872. y0 *= f;
  873. z0 *= f;
  874. w0 *= f;
  875. }
  876. }
  877. dst[ dstOffset ] = x0;
  878. dst[ dstOffset + 1 ] = y0;
  879. dst[ dstOffset + 2 ] = z0;
  880. dst[ dstOffset + 3 ] = w0;
  881. }
  882. } );
  883. // File:src/math/Vector2.js
  884. /**
  885. * @author mrdoob / http://mrdoob.com/
  886. * @author philogb / http://blog.thejit.org/
  887. * @author egraether / http://egraether.com/
  888. * @author zz85 / http://www.lab4games.net/zz85/blog
  889. */
  890. THREE.Vector2 = function ( x, y ) {
  891. this.x = x || 0;
  892. this.y = y || 0;
  893. };
  894. THREE.Vector2.prototype = {
  895. constructor: THREE.Vector2,
  896. get width() {
  897. return this.x;
  898. },
  899. set width( value ) {
  900. this.x = value;
  901. },
  902. get height() {
  903. return this.y;
  904. },
  905. set height( value ) {
  906. this.y = value;
  907. },
  908. //
  909. set: function ( x, y ) {
  910. this.x = x;
  911. this.y = y;
  912. return this;
  913. },
  914. setScalar: function ( scalar ) {
  915. this.x = scalar;
  916. this.y = scalar;
  917. return this;
  918. },
  919. setX: function ( x ) {
  920. this.x = x;
  921. return this;
  922. },
  923. setY: function ( y ) {
  924. this.y = y;
  925. return this;
  926. },
  927. setComponent: function ( index, value ) {
  928. switch ( index ) {
  929. case 0: this.x = value; break;
  930. case 1: this.y = value; break;
  931. default: throw new Error( 'index is out of range: ' + index );
  932. }
  933. },
  934. getComponent: function ( index ) {
  935. switch ( index ) {
  936. case 0: return this.x;
  937. case 1: return this.y;
  938. default: throw new Error( 'index is out of range: ' + index );
  939. }
  940. },
  941. clone: function () {
  942. return new this.constructor( this.x, this.y );
  943. },
  944. copy: function ( v ) {
  945. this.x = v.x;
  946. this.y = v.y;
  947. return this;
  948. },
  949. add: function ( v, w ) {
  950. if ( w !== undefined ) {
  951. console.warn( 'THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  952. return this.addVectors( v, w );
  953. }
  954. this.x += v.x;
  955. this.y += v.y;
  956. return this;
  957. },
  958. addScalar: function ( s ) {
  959. this.x += s;
  960. this.y += s;
  961. return this;
  962. },
  963. addVectors: function ( a, b ) {
  964. this.x = a.x + b.x;
  965. this.y = a.y + b.y;
  966. return this;
  967. },
  968. addScaledVector: function ( v, s ) {
  969. this.x += v.x * s;
  970. this.y += v.y * s;
  971. return this;
  972. },
  973. sub: function ( v, w ) {
  974. if ( w !== undefined ) {
  975. console.warn( 'THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  976. return this.subVectors( v, w );
  977. }
  978. this.x -= v.x;
  979. this.y -= v.y;
  980. return this;
  981. },
  982. subScalar: function ( s ) {
  983. this.x -= s;
  984. this.y -= s;
  985. return this;
  986. },
  987. subVectors: function ( a, b ) {
  988. this.x = a.x - b.x;
  989. this.y = a.y - b.y;
  990. return this;
  991. },
  992. multiply: function ( v ) {
  993. this.x *= v.x;
  994. this.y *= v.y;
  995. return this;
  996. },
  997. multiplyScalar: function ( scalar ) {
  998. if ( isFinite( scalar ) ) {
  999. this.x *= scalar;
  1000. this.y *= scalar;
  1001. } else {
  1002. this.x = 0;
  1003. this.y = 0;
  1004. }
  1005. return this;
  1006. },
  1007. divide: function ( v ) {
  1008. this.x /= v.x;
  1009. this.y /= v.y;
  1010. return this;
  1011. },
  1012. divideScalar: function ( scalar ) {
  1013. return this.multiplyScalar( 1 / scalar );
  1014. },
  1015. min: function ( v ) {
  1016. this.x = Math.min( this.x, v.x );
  1017. this.y = Math.min( this.y, v.y );
  1018. return this;
  1019. },
  1020. max: function ( v ) {
  1021. this.x = Math.max( this.x, v.x );
  1022. this.y = Math.max( this.y, v.y );
  1023. return this;
  1024. },
  1025. clamp: function ( min, max ) {
  1026. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1027. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1028. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1029. return this;
  1030. },
  1031. clampScalar: function () {
  1032. var min, max;
  1033. return function clampScalar( minVal, maxVal ) {
  1034. if ( min === undefined ) {
  1035. min = new THREE.Vector2();
  1036. max = new THREE.Vector2();
  1037. }
  1038. min.set( minVal, minVal );
  1039. max.set( maxVal, maxVal );
  1040. return this.clamp( min, max );
  1041. };
  1042. }(),
  1043. clampLength: function ( min, max ) {
  1044. var length = this.length();
  1045. return this.multiplyScalar( Math.max( min, Math.min( max, length ) ) / length );
  1046. },
  1047. floor: function () {
  1048. this.x = Math.floor( this.x );
  1049. this.y = Math.floor( this.y );
  1050. return this;
  1051. },
  1052. ceil: function () {
  1053. this.x = Math.ceil( this.x );
  1054. this.y = Math.ceil( this.y );
  1055. return this;
  1056. },
  1057. round: function () {
  1058. this.x = Math.round( this.x );
  1059. this.y = Math.round( this.y );
  1060. return this;
  1061. },
  1062. roundToZero: function () {
  1063. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1064. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1065. return this;
  1066. },
  1067. negate: function () {
  1068. this.x = - this.x;
  1069. this.y = - this.y;
  1070. return this;
  1071. },
  1072. dot: function ( v ) {
  1073. return this.x * v.x + this.y * v.y;
  1074. },
  1075. lengthSq: function () {
  1076. return this.x * this.x + this.y * this.y;
  1077. },
  1078. length: function () {
  1079. return Math.sqrt( this.x * this.x + this.y * this.y );
  1080. },
  1081. lengthManhattan: function() {
  1082. return Math.abs( this.x ) + Math.abs( this.y );
  1083. },
  1084. normalize: function () {
  1085. return this.divideScalar( this.length() );
  1086. },
  1087. angle: function () {
  1088. // computes the angle in radians with respect to the positive x-axis
  1089. var angle = Math.atan2( this.y, this.x );
  1090. if ( angle < 0 ) angle += 2 * Math.PI;
  1091. return angle;
  1092. },
  1093. distanceTo: function ( v ) {
  1094. return Math.sqrt( this.distanceToSquared( v ) );
  1095. },
  1096. distanceToSquared: function ( v ) {
  1097. var dx = this.x - v.x, dy = this.y - v.y;
  1098. return dx * dx + dy * dy;
  1099. },
  1100. distanceToManhattan: function ( v ) {
  1101. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y );
  1102. },
  1103. setLength: function ( length ) {
  1104. return this.multiplyScalar( length / this.length() );
  1105. },
  1106. lerp: function ( v, alpha ) {
  1107. this.x += ( v.x - this.x ) * alpha;
  1108. this.y += ( v.y - this.y ) * alpha;
  1109. return this;
  1110. },
  1111. lerpVectors: function ( v1, v2, alpha ) {
  1112. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1113. },
  1114. equals: function ( v ) {
  1115. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  1116. },
  1117. fromArray: function ( array, offset ) {
  1118. if ( offset === undefined ) offset = 0;
  1119. this.x = array[ offset ];
  1120. this.y = array[ offset + 1 ];
  1121. return this;
  1122. },
  1123. toArray: function ( array, offset ) {
  1124. if ( array === undefined ) array = [];
  1125. if ( offset === undefined ) offset = 0;
  1126. array[ offset ] = this.x;
  1127. array[ offset + 1 ] = this.y;
  1128. return array;
  1129. },
  1130. fromAttribute: function ( attribute, index, offset ) {
  1131. if ( offset === undefined ) offset = 0;
  1132. index = index * attribute.itemSize + offset;
  1133. this.x = attribute.array[ index ];
  1134. this.y = attribute.array[ index + 1 ];
  1135. return this;
  1136. },
  1137. rotateAround: function ( center, angle ) {
  1138. var c = Math.cos( angle ), s = Math.sin( angle );
  1139. var x = this.x - center.x;
  1140. var y = this.y - center.y;
  1141. this.x = x * c - y * s + center.x;
  1142. this.y = x * s + y * c + center.y;
  1143. return this;
  1144. }
  1145. };
  1146. // File:src/math/Vector3.js
  1147. /**
  1148. * @author mrdoob / http://mrdoob.com/
  1149. * @author *kile / http://kile.stravaganza.org/
  1150. * @author philogb / http://blog.thejit.org/
  1151. * @author mikael emtinger / http://gomo.se/
  1152. * @author egraether / http://egraether.com/
  1153. * @author WestLangley / http://github.com/WestLangley
  1154. */
  1155. THREE.Vector3 = function ( x, y, z ) {
  1156. this.x = x || 0;
  1157. this.y = y || 0;
  1158. this.z = z || 0;
  1159. };
  1160. THREE.Vector3.prototype = {
  1161. constructor: THREE.Vector3,
  1162. set: function ( x, y, z ) {
  1163. this.x = x;
  1164. this.y = y;
  1165. this.z = z;
  1166. return this;
  1167. },
  1168. setScalar: function ( scalar ) {
  1169. this.x = scalar;
  1170. this.y = scalar;
  1171. this.z = scalar;
  1172. return this;
  1173. },
  1174. setX: function ( x ) {
  1175. this.x = x;
  1176. return this;
  1177. },
  1178. setY: function ( y ) {
  1179. this.y = y;
  1180. return this;
  1181. },
  1182. setZ: function ( z ) {
  1183. this.z = z;
  1184. return this;
  1185. },
  1186. setComponent: function ( index, value ) {
  1187. switch ( index ) {
  1188. case 0: this.x = value; break;
  1189. case 1: this.y = value; break;
  1190. case 2: this.z = value; break;
  1191. default: throw new Error( 'index is out of range: ' + index );
  1192. }
  1193. },
  1194. getComponent: function ( index ) {
  1195. switch ( index ) {
  1196. case 0: return this.x;
  1197. case 1: return this.y;
  1198. case 2: return this.z;
  1199. default: throw new Error( 'index is out of range: ' + index );
  1200. }
  1201. },
  1202. clone: function () {
  1203. return new this.constructor( this.x, this.y, this.z );
  1204. },
  1205. copy: function ( v ) {
  1206. this.x = v.x;
  1207. this.y = v.y;
  1208. this.z = v.z;
  1209. return this;
  1210. },
  1211. add: function ( v, w ) {
  1212. if ( w !== undefined ) {
  1213. console.warn( 'THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1214. return this.addVectors( v, w );
  1215. }
  1216. this.x += v.x;
  1217. this.y += v.y;
  1218. this.z += v.z;
  1219. return this;
  1220. },
  1221. addScalar: function ( s ) {
  1222. this.x += s;
  1223. this.y += s;
  1224. this.z += s;
  1225. return this;
  1226. },
  1227. addVectors: function ( a, b ) {
  1228. this.x = a.x + b.x;
  1229. this.y = a.y + b.y;
  1230. this.z = a.z + b.z;
  1231. return this;
  1232. },
  1233. addScaledVector: function ( v, s ) {
  1234. this.x += v.x * s;
  1235. this.y += v.y * s;
  1236. this.z += v.z * s;
  1237. return this;
  1238. },
  1239. sub: function ( v, w ) {
  1240. if ( w !== undefined ) {
  1241. console.warn( 'THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1242. return this.subVectors( v, w );
  1243. }
  1244. this.x -= v.x;
  1245. this.y -= v.y;
  1246. this.z -= v.z;
  1247. return this;
  1248. },
  1249. subScalar: function ( s ) {
  1250. this.x -= s;
  1251. this.y -= s;
  1252. this.z -= s;
  1253. return this;
  1254. },
  1255. subVectors: function ( a, b ) {
  1256. this.x = a.x - b.x;
  1257. this.y = a.y - b.y;
  1258. this.z = a.z - b.z;
  1259. return this;
  1260. },
  1261. multiply: function ( v, w ) {
  1262. if ( w !== undefined ) {
  1263. console.warn( 'THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.' );
  1264. return this.multiplyVectors( v, w );
  1265. }
  1266. this.x *= v.x;
  1267. this.y *= v.y;
  1268. this.z *= v.z;
  1269. return this;
  1270. },
  1271. multiplyScalar: function ( scalar ) {
  1272. if ( isFinite( scalar ) ) {
  1273. this.x *= scalar;
  1274. this.y *= scalar;
  1275. this.z *= scalar;
  1276. } else {
  1277. this.x = 0;
  1278. this.y = 0;
  1279. this.z = 0;
  1280. }
  1281. return this;
  1282. },
  1283. multiplyVectors: function ( a, b ) {
  1284. this.x = a.x * b.x;
  1285. this.y = a.y * b.y;
  1286. this.z = a.z * b.z;
  1287. return this;
  1288. },
  1289. applyEuler: function () {
  1290. var quaternion;
  1291. return function applyEuler( euler ) {
  1292. if ( euler instanceof THREE.Euler === false ) {
  1293. console.error( 'THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  1294. }
  1295. if ( quaternion === undefined ) quaternion = new THREE.Quaternion();
  1296. return this.applyQuaternion( quaternion.setFromEuler( euler ) );
  1297. };
  1298. }(),
  1299. applyAxisAngle: function () {
  1300. var quaternion;
  1301. return function applyAxisAngle( axis, angle ) {
  1302. if ( quaternion === undefined ) quaternion = new THREE.Quaternion();
  1303. return this.applyQuaternion( quaternion.setFromAxisAngle( axis, angle ) );
  1304. };
  1305. }(),
  1306. applyMatrix3: function ( m ) {
  1307. var x = this.x, y = this.y, z = this.z;
  1308. var e = m.elements;
  1309. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
  1310. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
  1311. this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
  1312. return this;
  1313. },
  1314. applyMatrix4: function ( m ) {
  1315. // input: THREE.Matrix4 affine matrix
  1316. var x = this.x, y = this.y, z = this.z;
  1317. var e = m.elements;
  1318. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ];
  1319. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ];
  1320. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ];
  1321. return this;
  1322. },
  1323. applyProjection: function ( m ) {
  1324. // input: THREE.Matrix4 projection matrix
  1325. var x = this.x, y = this.y, z = this.z;
  1326. var e = m.elements;
  1327. var d = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] ); // perspective divide
  1328. this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * d;
  1329. this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * d;
  1330. this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * d;
  1331. return this;
  1332. },
  1333. applyQuaternion: function ( q ) {
  1334. var x = this.x, y = this.y, z = this.z;
  1335. var qx = q.x, qy = q.y, qz = q.z, qw = q.w;
  1336. // calculate quat * vector
  1337. var ix = qw * x + qy * z - qz * y;
  1338. var iy = qw * y + qz * x - qx * z;
  1339. var iz = qw * z + qx * y - qy * x;
  1340. var iw = - qx * x - qy * y - qz * z;
  1341. // calculate result * inverse quat
  1342. this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
  1343. this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
  1344. this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
  1345. return this;
  1346. },
  1347. project: function () {
  1348. var matrix;
  1349. return function project( camera ) {
  1350. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  1351. matrix.multiplyMatrices( camera.projectionMatrix, matrix.getInverse( camera.matrixWorld ) );
  1352. return this.applyProjection( matrix );
  1353. };
  1354. }(),
  1355. unproject: function () {
  1356. var matrix;
  1357. return function unproject( camera ) {
  1358. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  1359. matrix.multiplyMatrices( camera.matrixWorld, matrix.getInverse( camera.projectionMatrix ) );
  1360. return this.applyProjection( matrix );
  1361. };
  1362. }(),
  1363. transformDirection: function ( m ) {
  1364. // input: THREE.Matrix4 affine matrix
  1365. // vector interpreted as a direction
  1366. var x = this.x, y = this.y, z = this.z;
  1367. var e = m.elements;
  1368. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
  1369. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
  1370. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
  1371. return this.normalize();
  1372. },
  1373. divide: function ( v ) {
  1374. this.x /= v.x;
  1375. this.y /= v.y;
  1376. this.z /= v.z;
  1377. return this;
  1378. },
  1379. divideScalar: function ( scalar ) {
  1380. return this.multiplyScalar( 1 / scalar );
  1381. },
  1382. min: function ( v ) {
  1383. this.x = Math.min( this.x, v.x );
  1384. this.y = Math.min( this.y, v.y );
  1385. this.z = Math.min( this.z, v.z );
  1386. return this;
  1387. },
  1388. max: function ( v ) {
  1389. this.x = Math.max( this.x, v.x );
  1390. this.y = Math.max( this.y, v.y );
  1391. this.z = Math.max( this.z, v.z );
  1392. return this;
  1393. },
  1394. clamp: function ( min, max ) {
  1395. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1396. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1397. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1398. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  1399. return this;
  1400. },
  1401. clampScalar: function () {
  1402. var min, max;
  1403. return function clampScalar( minVal, maxVal ) {
  1404. if ( min === undefined ) {
  1405. min = new THREE.Vector3();
  1406. max = new THREE.Vector3();
  1407. }
  1408. min.set( minVal, minVal, minVal );
  1409. max.set( maxVal, maxVal, maxVal );
  1410. return this.clamp( min, max );
  1411. };
  1412. }(),
  1413. clampLength: function ( min, max ) {
  1414. var length = this.length();
  1415. return this.multiplyScalar( Math.max( min, Math.min( max, length ) ) / length );
  1416. },
  1417. floor: function () {
  1418. this.x = Math.floor( this.x );
  1419. this.y = Math.floor( this.y );
  1420. this.z = Math.floor( this.z );
  1421. return this;
  1422. },
  1423. ceil: function () {
  1424. this.x = Math.ceil( this.x );
  1425. this.y = Math.ceil( this.y );
  1426. this.z = Math.ceil( this.z );
  1427. return this;
  1428. },
  1429. round: function () {
  1430. this.x = Math.round( this.x );
  1431. this.y = Math.round( this.y );
  1432. this.z = Math.round( this.z );
  1433. return this;
  1434. },
  1435. roundToZero: function () {
  1436. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1437. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1438. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1439. return this;
  1440. },
  1441. negate: function () {
  1442. this.x = - this.x;
  1443. this.y = - this.y;
  1444. this.z = - this.z;
  1445. return this;
  1446. },
  1447. dot: function ( v ) {
  1448. return this.x * v.x + this.y * v.y + this.z * v.z;
  1449. },
  1450. lengthSq: function () {
  1451. return this.x * this.x + this.y * this.y + this.z * this.z;
  1452. },
  1453. length: function () {
  1454. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
  1455. },
  1456. lengthManhattan: function () {
  1457. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  1458. },
  1459. normalize: function () {
  1460. return this.divideScalar( this.length() );
  1461. },
  1462. setLength: function ( length ) {
  1463. return this.multiplyScalar( length / this.length() );
  1464. },
  1465. lerp: function ( v, alpha ) {
  1466. this.x += ( v.x - this.x ) * alpha;
  1467. this.y += ( v.y - this.y ) * alpha;
  1468. this.z += ( v.z - this.z ) * alpha;
  1469. return this;
  1470. },
  1471. lerpVectors: function ( v1, v2, alpha ) {
  1472. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1473. },
  1474. cross: function ( v, w ) {
  1475. if ( w !== undefined ) {
  1476. console.warn( 'THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.' );
  1477. return this.crossVectors( v, w );
  1478. }
  1479. var x = this.x, y = this.y, z = this.z;
  1480. this.x = y * v.z - z * v.y;
  1481. this.y = z * v.x - x * v.z;
  1482. this.z = x * v.y - y * v.x;
  1483. return this;
  1484. },
  1485. crossVectors: function ( a, b ) {
  1486. var ax = a.x, ay = a.y, az = a.z;
  1487. var bx = b.x, by = b.y, bz = b.z;
  1488. this.x = ay * bz - az * by;
  1489. this.y = az * bx - ax * bz;
  1490. this.z = ax * by - ay * bx;
  1491. return this;
  1492. },
  1493. projectOnVector: function ( vector ) {
  1494. var scalar = vector.dot( this ) / vector.lengthSq();
  1495. return this.copy( vector ).multiplyScalar( scalar );
  1496. },
  1497. projectOnPlane: function () {
  1498. var v1;
  1499. return function projectOnPlane( planeNormal ) {
  1500. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1501. v1.copy( this ).projectOnVector( planeNormal );
  1502. return this.sub( v1 );
  1503. };
  1504. }(),
  1505. reflect: function () {
  1506. // reflect incident vector off plane orthogonal to normal
  1507. // normal is assumed to have unit length
  1508. var v1;
  1509. return function reflect( normal ) {
  1510. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1511. return this.sub( v1.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
  1512. };
  1513. }(),
  1514. angleTo: function ( v ) {
  1515. var theta = this.dot( v ) / ( Math.sqrt( this.lengthSq() * v.lengthSq() ) );
  1516. // clamp, to handle numerical problems
  1517. return Math.acos( THREE.Math.clamp( theta, - 1, 1 ) );
  1518. },
  1519. distanceTo: function ( v ) {
  1520. return Math.sqrt( this.distanceToSquared( v ) );
  1521. },
  1522. distanceToSquared: function ( v ) {
  1523. var dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;
  1524. return dx * dx + dy * dy + dz * dz;
  1525. },
  1526. distanceToManhattan: function ( v ) {
  1527. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y ) + Math.abs( this.z - v.z );
  1528. },
  1529. setFromSpherical: function( s ) {
  1530. var sinPhiRadius = Math.sin( s.phi ) * s.radius;
  1531. this.x = sinPhiRadius * Math.sin( s.theta );
  1532. this.y = Math.cos( s.phi ) * s.radius;
  1533. this.z = sinPhiRadius * Math.cos( s.theta );
  1534. return this;
  1535. },
  1536. setFromMatrixPosition: function ( m ) {
  1537. return this.setFromMatrixColumn( m, 3 );
  1538. },
  1539. setFromMatrixScale: function ( m ) {
  1540. var sx = this.setFromMatrixColumn( m, 0 ).length();
  1541. var sy = this.setFromMatrixColumn( m, 1 ).length();
  1542. var sz = this.setFromMatrixColumn( m, 2 ).length();
  1543. this.x = sx;
  1544. this.y = sy;
  1545. this.z = sz;
  1546. return this;
  1547. },
  1548. setFromMatrixColumn: function ( m, index ) {
  1549. if ( typeof m === 'number' ) {
  1550. console.warn( 'THREE.Vector3: setFromMatrixColumn now expects ( matrix, index ).' );
  1551. var temp = m
  1552. m = index;
  1553. index = temp;
  1554. }
  1555. return this.fromArray( m.elements, index * 4 );
  1556. },
  1557. equals: function ( v ) {
  1558. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  1559. },
  1560. fromArray: function ( array, offset ) {
  1561. if ( offset === undefined ) offset = 0;
  1562. this.x = array[ offset ];
  1563. this.y = array[ offset + 1 ];
  1564. this.z = array[ offset + 2 ];
  1565. return this;
  1566. },
  1567. toArray: function ( array, offset ) {
  1568. if ( array === undefined ) array = [];
  1569. if ( offset === undefined ) offset = 0;
  1570. array[ offset ] = this.x;
  1571. array[ offset + 1 ] = this.y;
  1572. array[ offset + 2 ] = this.z;
  1573. return array;
  1574. },
  1575. fromAttribute: function ( attribute, index, offset ) {
  1576. if ( offset === undefined ) offset = 0;
  1577. index = index * attribute.itemSize + offset;
  1578. this.x = attribute.array[ index ];
  1579. this.y = attribute.array[ index + 1 ];
  1580. this.z = attribute.array[ index + 2 ];
  1581. return this;
  1582. }
  1583. };
  1584. // File:src/math/Vector4.js
  1585. /**
  1586. * @author supereggbert / http://www.paulbrunt.co.uk/
  1587. * @author philogb / http://blog.thejit.org/
  1588. * @author mikael emtinger / http://gomo.se/
  1589. * @author egraether / http://egraether.com/
  1590. * @author WestLangley / http://github.com/WestLangley
  1591. */
  1592. THREE.Vector4 = function ( x, y, z, w ) {
  1593. this.x = x || 0;
  1594. this.y = y || 0;
  1595. this.z = z || 0;
  1596. this.w = ( w !== undefined ) ? w : 1;
  1597. };
  1598. THREE.Vector4.prototype = {
  1599. constructor: THREE.Vector4,
  1600. set: function ( x, y, z, w ) {
  1601. this.x = x;
  1602. this.y = y;
  1603. this.z = z;
  1604. this.w = w;
  1605. return this;
  1606. },
  1607. setScalar: function ( scalar ) {
  1608. this.x = scalar;
  1609. this.y = scalar;
  1610. this.z = scalar;
  1611. this.w = scalar;
  1612. return this;
  1613. },
  1614. setX: function ( x ) {
  1615. this.x = x;
  1616. return this;
  1617. },
  1618. setY: function ( y ) {
  1619. this.y = y;
  1620. return this;
  1621. },
  1622. setZ: function ( z ) {
  1623. this.z = z;
  1624. return this;
  1625. },
  1626. setW: function ( w ) {
  1627. this.w = w;
  1628. return this;
  1629. },
  1630. setComponent: function ( index, value ) {
  1631. switch ( index ) {
  1632. case 0: this.x = value; break;
  1633. case 1: this.y = value; break;
  1634. case 2: this.z = value; break;
  1635. case 3: this.w = value; break;
  1636. default: throw new Error( 'index is out of range: ' + index );
  1637. }
  1638. },
  1639. getComponent: function ( index ) {
  1640. switch ( index ) {
  1641. case 0: return this.x;
  1642. case 1: return this.y;
  1643. case 2: return this.z;
  1644. case 3: return this.w;
  1645. default: throw new Error( 'index is out of range: ' + index );
  1646. }
  1647. },
  1648. clone: function () {
  1649. return new this.constructor( this.x, this.y, this.z, this.w );
  1650. },
  1651. copy: function ( v ) {
  1652. this.x = v.x;
  1653. this.y = v.y;
  1654. this.z = v.z;
  1655. this.w = ( v.w !== undefined ) ? v.w : 1;
  1656. return this;
  1657. },
  1658. add: function ( v, w ) {
  1659. if ( w !== undefined ) {
  1660. console.warn( 'THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1661. return this.addVectors( v, w );
  1662. }
  1663. this.x += v.x;
  1664. this.y += v.y;
  1665. this.z += v.z;
  1666. this.w += v.w;
  1667. return this;
  1668. },
  1669. addScalar: function ( s ) {
  1670. this.x += s;
  1671. this.y += s;
  1672. this.z += s;
  1673. this.w += s;
  1674. return this;
  1675. },
  1676. addVectors: function ( a, b ) {
  1677. this.x = a.x + b.x;
  1678. this.y = a.y + b.y;
  1679. this.z = a.z + b.z;
  1680. this.w = a.w + b.w;
  1681. return this;
  1682. },
  1683. addScaledVector: function ( v, s ) {
  1684. this.x += v.x * s;
  1685. this.y += v.y * s;
  1686. this.z += v.z * s;
  1687. this.w += v.w * s;
  1688. return this;
  1689. },
  1690. sub: function ( v, w ) {
  1691. if ( w !== undefined ) {
  1692. console.warn( 'THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1693. return this.subVectors( v, w );
  1694. }
  1695. this.x -= v.x;
  1696. this.y -= v.y;
  1697. this.z -= v.z;
  1698. this.w -= v.w;
  1699. return this;
  1700. },
  1701. subScalar: function ( s ) {
  1702. this.x -= s;
  1703. this.y -= s;
  1704. this.z -= s;
  1705. this.w -= s;
  1706. return this;
  1707. },
  1708. subVectors: function ( a, b ) {
  1709. this.x = a.x - b.x;
  1710. this.y = a.y - b.y;
  1711. this.z = a.z - b.z;
  1712. this.w = a.w - b.w;
  1713. return this;
  1714. },
  1715. multiplyScalar: function ( scalar ) {
  1716. if ( isFinite( scalar ) ) {
  1717. this.x *= scalar;
  1718. this.y *= scalar;
  1719. this.z *= scalar;
  1720. this.w *= scalar;
  1721. } else {
  1722. this.x = 0;
  1723. this.y = 0;
  1724. this.z = 0;
  1725. this.w = 0;
  1726. }
  1727. return this;
  1728. },
  1729. applyMatrix4: function ( m ) {
  1730. var x = this.x, y = this.y, z = this.z, w = this.w;
  1731. var e = m.elements;
  1732. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  1733. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  1734. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  1735. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  1736. return this;
  1737. },
  1738. divideScalar: function ( scalar ) {
  1739. return this.multiplyScalar( 1 / scalar );
  1740. },
  1741. setAxisAngleFromQuaternion: function ( q ) {
  1742. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  1743. // q is assumed to be normalized
  1744. this.w = 2 * Math.acos( q.w );
  1745. var s = Math.sqrt( 1 - q.w * q.w );
  1746. if ( s < 0.0001 ) {
  1747. this.x = 1;
  1748. this.y = 0;
  1749. this.z = 0;
  1750. } else {
  1751. this.x = q.x / s;
  1752. this.y = q.y / s;
  1753. this.z = q.z / s;
  1754. }
  1755. return this;
  1756. },
  1757. setAxisAngleFromRotationMatrix: function ( m ) {
  1758. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  1759. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1760. var angle, x, y, z, // variables for result
  1761. epsilon = 0.01, // margin to allow for rounding errors
  1762. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  1763. te = m.elements,
  1764. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  1765. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  1766. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  1767. if ( ( Math.abs( m12 - m21 ) < epsilon ) &&
  1768. ( Math.abs( m13 - m31 ) < epsilon ) &&
  1769. ( Math.abs( m23 - m32 ) < epsilon ) ) {
  1770. // singularity found
  1771. // first check for identity matrix which must have +1 for all terms
  1772. // in leading diagonal and zero in other terms
  1773. if ( ( Math.abs( m12 + m21 ) < epsilon2 ) &&
  1774. ( Math.abs( m13 + m31 ) < epsilon2 ) &&
  1775. ( Math.abs( m23 + m32 ) < epsilon2 ) &&
  1776. ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  1777. // this singularity is identity matrix so angle = 0
  1778. this.set( 1, 0, 0, 0 );
  1779. return this; // zero angle, arbitrary axis
  1780. }
  1781. // otherwise this singularity is angle = 180
  1782. angle = Math.PI;
  1783. var xx = ( m11 + 1 ) / 2;
  1784. var yy = ( m22 + 1 ) / 2;
  1785. var zz = ( m33 + 1 ) / 2;
  1786. var xy = ( m12 + m21 ) / 4;
  1787. var xz = ( m13 + m31 ) / 4;
  1788. var yz = ( m23 + m32 ) / 4;
  1789. if ( ( xx > yy ) && ( xx > zz ) ) {
  1790. // m11 is the largest diagonal term
  1791. if ( xx < epsilon ) {
  1792. x = 0;
  1793. y = 0.707106781;
  1794. z = 0.707106781;
  1795. } else {
  1796. x = Math.sqrt( xx );
  1797. y = xy / x;
  1798. z = xz / x;
  1799. }
  1800. } else if ( yy > zz ) {
  1801. // m22 is the largest diagonal term
  1802. if ( yy < epsilon ) {
  1803. x = 0.707106781;
  1804. y = 0;
  1805. z = 0.707106781;
  1806. } else {
  1807. y = Math.sqrt( yy );
  1808. x = xy / y;
  1809. z = yz / y;
  1810. }
  1811. } else {
  1812. // m33 is the largest diagonal term so base result on this
  1813. if ( zz < epsilon ) {
  1814. x = 0.707106781;
  1815. y = 0.707106781;
  1816. z = 0;
  1817. } else {
  1818. z = Math.sqrt( zz );
  1819. x = xz / z;
  1820. y = yz / z;
  1821. }
  1822. }
  1823. this.set( x, y, z, angle );
  1824. return this; // return 180 deg rotation
  1825. }
  1826. // as we have reached here there are no singularities so we can handle normally
  1827. var s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 ) +
  1828. ( m13 - m31 ) * ( m13 - m31 ) +
  1829. ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  1830. if ( Math.abs( s ) < 0.001 ) s = 1;
  1831. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  1832. // caught by singularity test above, but I've left it in just in case
  1833. this.x = ( m32 - m23 ) / s;
  1834. this.y = ( m13 - m31 ) / s;
  1835. this.z = ( m21 - m12 ) / s;
  1836. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  1837. return this;
  1838. },
  1839. min: function ( v ) {
  1840. this.x = Math.min( this.x, v.x );
  1841. this.y = Math.min( this.y, v.y );
  1842. this.z = Math.min( this.z, v.z );
  1843. this.w = Math.min( this.w, v.w );
  1844. return this;
  1845. },
  1846. max: function ( v ) {
  1847. this.x = Math.max( this.x, v.x );
  1848. this.y = Math.max( this.y, v.y );
  1849. this.z = Math.max( this.z, v.z );
  1850. this.w = Math.max( this.w, v.w );
  1851. return this;
  1852. },
  1853. clamp: function ( min, max ) {
  1854. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1855. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1856. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1857. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  1858. this.w = Math.max( min.w, Math.min( max.w, this.w ) );
  1859. return this;
  1860. },
  1861. clampScalar: function () {
  1862. var min, max;
  1863. return function clampScalar( minVal, maxVal ) {
  1864. if ( min === undefined ) {
  1865. min = new THREE.Vector4();
  1866. max = new THREE.Vector4();
  1867. }
  1868. min.set( minVal, minVal, minVal, minVal );
  1869. max.set( maxVal, maxVal, maxVal, maxVal );
  1870. return this.clamp( min, max );
  1871. };
  1872. }(),
  1873. floor: function () {
  1874. this.x = Math.floor( this.x );
  1875. this.y = Math.floor( this.y );
  1876. this.z = Math.floor( this.z );
  1877. this.w = Math.floor( this.w );
  1878. return this;
  1879. },
  1880. ceil: function () {
  1881. this.x = Math.ceil( this.x );
  1882. this.y = Math.ceil( this.y );
  1883. this.z = Math.ceil( this.z );
  1884. this.w = Math.ceil( this.w );
  1885. return this;
  1886. },
  1887. round: function () {
  1888. this.x = Math.round( this.x );
  1889. this.y = Math.round( this.y );
  1890. this.z = Math.round( this.z );
  1891. this.w = Math.round( this.w );
  1892. return this;
  1893. },
  1894. roundToZero: function () {
  1895. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1896. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1897. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1898. this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
  1899. return this;
  1900. },
  1901. negate: function () {
  1902. this.x = - this.x;
  1903. this.y = - this.y;
  1904. this.z = - this.z;
  1905. this.w = - this.w;
  1906. return this;
  1907. },
  1908. dot: function ( v ) {
  1909. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  1910. },
  1911. lengthSq: function () {
  1912. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  1913. },
  1914. length: function () {
  1915. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  1916. },
  1917. lengthManhattan: function () {
  1918. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  1919. },
  1920. normalize: function () {
  1921. return this.divideScalar( this.length() );
  1922. },
  1923. setLength: function ( length ) {
  1924. return this.multiplyScalar( length / this.length() );
  1925. },
  1926. lerp: function ( v, alpha ) {
  1927. this.x += ( v.x - this.x ) * alpha;
  1928. this.y += ( v.y - this.y ) * alpha;
  1929. this.z += ( v.z - this.z ) * alpha;
  1930. this.w += ( v.w - this.w ) * alpha;
  1931. return this;
  1932. },
  1933. lerpVectors: function ( v1, v2, alpha ) {
  1934. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1935. },
  1936. equals: function ( v ) {
  1937. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  1938. },
  1939. fromArray: function ( array, offset ) {
  1940. if ( offset === undefined ) offset = 0;
  1941. this.x = array[ offset ];
  1942. this.y = array[ offset + 1 ];
  1943. this.z = array[ offset + 2 ];
  1944. this.w = array[ offset + 3 ];
  1945. return this;
  1946. },
  1947. toArray: function ( array, offset ) {
  1948. if ( array === undefined ) array = [];
  1949. if ( offset === undefined ) offset = 0;
  1950. array[ offset ] = this.x;
  1951. array[ offset + 1 ] = this.y;
  1952. array[ offset + 2 ] = this.z;
  1953. array[ offset + 3 ] = this.w;
  1954. return array;
  1955. },
  1956. fromAttribute: function ( attribute, index, offset ) {
  1957. if ( offset === undefined ) offset = 0;
  1958. index = index * attribute.itemSize + offset;
  1959. this.x = attribute.array[ index ];
  1960. this.y = attribute.array[ index + 1 ];
  1961. this.z = attribute.array[ index + 2 ];
  1962. this.w = attribute.array[ index + 3 ];
  1963. return this;
  1964. }
  1965. };
  1966. // File:src/math/Euler.js
  1967. /**
  1968. * @author mrdoob / http://mrdoob.com/
  1969. * @author WestLangley / http://github.com/WestLangley
  1970. * @author bhouston / http://clara.io
  1971. */
  1972. THREE.Euler = function ( x, y, z, order ) {
  1973. this._x = x || 0;
  1974. this._y = y || 0;
  1975. this._z = z || 0;
  1976. this._order = order || THREE.Euler.DefaultOrder;
  1977. };
  1978. THREE.Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
  1979. THREE.Euler.DefaultOrder = 'XYZ';
  1980. THREE.Euler.prototype = {
  1981. constructor: THREE.Euler,
  1982. get x () {
  1983. return this._x;
  1984. },
  1985. set x ( value ) {
  1986. this._x = value;
  1987. this.onChangeCallback();
  1988. },
  1989. get y () {
  1990. return this._y;
  1991. },
  1992. set y ( value ) {
  1993. this._y = value;
  1994. this.onChangeCallback();
  1995. },
  1996. get z () {
  1997. return this._z;
  1998. },
  1999. set z ( value ) {
  2000. this._z = value;
  2001. this.onChangeCallback();
  2002. },
  2003. get order () {
  2004. return this._order;
  2005. },
  2006. set order ( value ) {
  2007. this._order = value;
  2008. this.onChangeCallback();
  2009. },
  2010. set: function ( x, y, z, order ) {
  2011. this._x = x;
  2012. this._y = y;
  2013. this._z = z;
  2014. this._order = order || this._order;
  2015. this.onChangeCallback();
  2016. return this;
  2017. },
  2018. clone: function () {
  2019. return new this.constructor( this._x, this._y, this._z, this._order );
  2020. },
  2021. copy: function ( euler ) {
  2022. this._x = euler._x;
  2023. this._y = euler._y;
  2024. this._z = euler._z;
  2025. this._order = euler._order;
  2026. this.onChangeCallback();
  2027. return this;
  2028. },
  2029. setFromRotationMatrix: function ( m, order, update ) {
  2030. var clamp = THREE.Math.clamp;
  2031. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2032. var te = m.elements;
  2033. var m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  2034. var m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  2035. var m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  2036. order = order || this._order;
  2037. if ( order === 'XYZ' ) {
  2038. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  2039. if ( Math.abs( m13 ) < 0.99999 ) {
  2040. this._x = Math.atan2( - m23, m33 );
  2041. this._z = Math.atan2( - m12, m11 );
  2042. } else {
  2043. this._x = Math.atan2( m32, m22 );
  2044. this._z = 0;
  2045. }
  2046. } else if ( order === 'YXZ' ) {
  2047. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  2048. if ( Math.abs( m23 ) < 0.99999 ) {
  2049. this._y = Math.atan2( m13, m33 );
  2050. this._z = Math.atan2( m21, m22 );
  2051. } else {
  2052. this._y = Math.atan2( - m31, m11 );
  2053. this._z = 0;
  2054. }
  2055. } else if ( order === 'ZXY' ) {
  2056. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  2057. if ( Math.abs( m32 ) < 0.99999 ) {
  2058. this._y = Math.atan2( - m31, m33 );
  2059. this._z = Math.atan2( - m12, m22 );
  2060. } else {
  2061. this._y = 0;
  2062. this._z = Math.atan2( m21, m11 );
  2063. }
  2064. } else if ( order === 'ZYX' ) {
  2065. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  2066. if ( Math.abs( m31 ) < 0.99999 ) {
  2067. this._x = Math.atan2( m32, m33 );
  2068. this._z = Math.atan2( m21, m11 );
  2069. } else {
  2070. this._x = 0;
  2071. this._z = Math.atan2( - m12, m22 );
  2072. }
  2073. } else if ( order === 'YZX' ) {
  2074. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  2075. if ( Math.abs( m21 ) < 0.99999 ) {
  2076. this._x = Math.atan2( - m23, m22 );
  2077. this._y = Math.atan2( - m31, m11 );
  2078. } else {
  2079. this._x = 0;
  2080. this._y = Math.atan2( m13, m33 );
  2081. }
  2082. } else if ( order === 'XZY' ) {
  2083. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  2084. if ( Math.abs( m12 ) < 0.99999 ) {
  2085. this._x = Math.atan2( m32, m22 );
  2086. this._y = Math.atan2( m13, m11 );
  2087. } else {
  2088. this._x = Math.atan2( - m23, m33 );
  2089. this._y = 0;
  2090. }
  2091. } else {
  2092. console.warn( 'THREE.Euler: .setFromRotationMatrix() given unsupported order: ' + order );
  2093. }
  2094. this._order = order;
  2095. if ( update !== false ) this.onChangeCallback();
  2096. return this;
  2097. },
  2098. setFromQuaternion: function () {
  2099. var matrix;
  2100. return function setFromQuaternion( q, order, update ) {
  2101. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  2102. matrix.makeRotationFromQuaternion( q );
  2103. return this.setFromRotationMatrix( matrix, order, update );
  2104. };
  2105. }(),
  2106. setFromVector3: function ( v, order ) {
  2107. return this.set( v.x, v.y, v.z, order || this._order );
  2108. },
  2109. reorder: function () {
  2110. // WARNING: this discards revolution information -bhouston
  2111. var q = new THREE.Quaternion();
  2112. return function reorder( newOrder ) {
  2113. q.setFromEuler( this );
  2114. return this.setFromQuaternion( q, newOrder );
  2115. };
  2116. }(),
  2117. equals: function ( euler ) {
  2118. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  2119. },
  2120. fromArray: function ( array ) {
  2121. this._x = array[ 0 ];
  2122. this._y = array[ 1 ];
  2123. this._z = array[ 2 ];
  2124. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  2125. this.onChangeCallback();
  2126. return this;
  2127. },
  2128. toArray: function ( array, offset ) {
  2129. if ( array === undefined ) array = [];
  2130. if ( offset === undefined ) offset = 0;
  2131. array[ offset ] = this._x;
  2132. array[ offset + 1 ] = this._y;
  2133. array[ offset + 2 ] = this._z;
  2134. array[ offset + 3 ] = this._order;
  2135. return array;
  2136. },
  2137. toVector3: function ( optionalResult ) {
  2138. if ( optionalResult ) {
  2139. return optionalResult.set( this._x, this._y, this._z );
  2140. } else {
  2141. return new THREE.Vector3( this._x, this._y, this._z );
  2142. }
  2143. },
  2144. onChange: function ( callback ) {
  2145. this.onChangeCallback = callback;
  2146. return this;
  2147. },
  2148. onChangeCallback: function () {}
  2149. };
  2150. // File:src/math/Line3.js
  2151. /**
  2152. * @author bhouston / http://clara.io
  2153. */
  2154. THREE.Line3 = function ( start, end ) {
  2155. this.start = ( start !== undefined ) ? start : new THREE.Vector3();
  2156. this.end = ( end !== undefined ) ? end : new THREE.Vector3();
  2157. };
  2158. THREE.Line3.prototype = {
  2159. constructor: THREE.Line3,
  2160. set: function ( start, end ) {
  2161. this.start.copy( start );
  2162. this.end.copy( end );
  2163. return this;
  2164. },
  2165. clone: function () {
  2166. return new this.constructor().copy( this );
  2167. },
  2168. copy: function ( line ) {
  2169. this.start.copy( line.start );
  2170. this.end.copy( line.end );
  2171. return this;
  2172. },
  2173. center: function ( optionalTarget ) {
  2174. var result = optionalTarget || new THREE.Vector3();
  2175. return result.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  2176. },
  2177. delta: function ( optionalTarget ) {
  2178. var result = optionalTarget || new THREE.Vector3();
  2179. return result.subVectors( this.end, this.start );
  2180. },
  2181. distanceSq: function () {
  2182. return this.start.distanceToSquared( this.end );
  2183. },
  2184. distance: function () {
  2185. return this.start.distanceTo( this.end );
  2186. },
  2187. at: function ( t, optionalTarget ) {
  2188. var result = optionalTarget || new THREE.Vector3();
  2189. return this.delta( result ).multiplyScalar( t ).add( this.start );
  2190. },
  2191. closestPointToPointParameter: function () {
  2192. var startP = new THREE.Vector3();
  2193. var startEnd = new THREE.Vector3();
  2194. return function closestPointToPointParameter( point, clampToLine ) {
  2195. startP.subVectors( point, this.start );
  2196. startEnd.subVectors( this.end, this.start );
  2197. var startEnd2 = startEnd.dot( startEnd );
  2198. var startEnd_startP = startEnd.dot( startP );
  2199. var t = startEnd_startP / startEnd2;
  2200. if ( clampToLine ) {
  2201. t = THREE.Math.clamp( t, 0, 1 );
  2202. }
  2203. return t;
  2204. };
  2205. }(),
  2206. closestPointToPoint: function ( point, clampToLine, optionalTarget ) {
  2207. var t = this.closestPointToPointParameter( point, clampToLine );
  2208. var result = optionalTarget || new THREE.Vector3();
  2209. return this.delta( result ).multiplyScalar( t ).add( this.start );
  2210. },
  2211. applyMatrix4: function ( matrix ) {
  2212. this.start.applyMatrix4( matrix );
  2213. this.end.applyMatrix4( matrix );
  2214. return this;
  2215. },
  2216. equals: function ( line ) {
  2217. return line.start.equals( this.start ) && line.end.equals( this.end );
  2218. }
  2219. };
  2220. // File:src/math/Box2.js
  2221. /**
  2222. * @author bhouston / http://clara.io
  2223. */
  2224. THREE.Box2 = function ( min, max ) {
  2225. this.min = ( min !== undefined ) ? min : new THREE.Vector2( + Infinity, + Infinity );
  2226. this.max = ( max !== undefined ) ? max : new THREE.Vector2( - Infinity, - Infinity );
  2227. };
  2228. THREE.Box2.prototype = {
  2229. constructor: THREE.Box2,
  2230. set: function ( min, max ) {
  2231. this.min.copy( min );
  2232. this.max.copy( max );
  2233. return this;
  2234. },
  2235. setFromPoints: function ( points ) {
  2236. this.makeEmpty();
  2237. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2238. this.expandByPoint( points[ i ] );
  2239. }
  2240. return this;
  2241. },
  2242. setFromCenterAndSize: function () {
  2243. var v1 = new THREE.Vector2();
  2244. return function setFromCenterAndSize( center, size ) {
  2245. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2246. this.min.copy( center ).sub( halfSize );
  2247. this.max.copy( center ).add( halfSize );
  2248. return this;
  2249. };
  2250. }(),
  2251. clone: function () {
  2252. return new this.constructor().copy( this );
  2253. },
  2254. copy: function ( box ) {
  2255. this.min.copy( box.min );
  2256. this.max.copy( box.max );
  2257. return this;
  2258. },
  2259. makeEmpty: function () {
  2260. this.min.x = this.min.y = + Infinity;
  2261. this.max.x = this.max.y = - Infinity;
  2262. return this;
  2263. },
  2264. isEmpty: function () {
  2265. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2266. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  2267. },
  2268. center: function ( optionalTarget ) {
  2269. var result = optionalTarget || new THREE.Vector2();
  2270. return result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2271. },
  2272. size: function ( optionalTarget ) {
  2273. var result = optionalTarget || new THREE.Vector2();
  2274. return result.subVectors( this.max, this.min );
  2275. },
  2276. expandByPoint: function ( point ) {
  2277. this.min.min( point );
  2278. this.max.max( point );
  2279. return this;
  2280. },
  2281. expandByVector: function ( vector ) {
  2282. this.min.sub( vector );
  2283. this.max.add( vector );
  2284. return this;
  2285. },
  2286. expandByScalar: function ( scalar ) {
  2287. this.min.addScalar( - scalar );
  2288. this.max.addScalar( scalar );
  2289. return this;
  2290. },
  2291. containsPoint: function ( point ) {
  2292. if ( point.x < this.min.x || point.x > this.max.x ||
  2293. point.y < this.min.y || point.y > this.max.y ) {
  2294. return false;
  2295. }
  2296. return true;
  2297. },
  2298. containsBox: function ( box ) {
  2299. if ( ( this.min.x <= box.min.x ) && ( box.max.x <= this.max.x ) &&
  2300. ( this.min.y <= box.min.y ) && ( box.max.y <= this.max.y ) ) {
  2301. return true;
  2302. }
  2303. return false;
  2304. },
  2305. getParameter: function ( point, optionalTarget ) {
  2306. // This can potentially have a divide by zero if the box
  2307. // has a size dimension of 0.
  2308. var result = optionalTarget || new THREE.Vector2();
  2309. return result.set(
  2310. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2311. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  2312. );
  2313. },
  2314. intersectsBox: function ( box ) {
  2315. // using 6 splitting planes to rule out intersections.
  2316. if ( box.max.x < this.min.x || box.min.x > this.max.x ||
  2317. box.max.y < this.min.y || box.min.y > this.max.y ) {
  2318. return false;
  2319. }
  2320. return true;
  2321. },
  2322. clampPoint: function ( point, optionalTarget ) {
  2323. var result = optionalTarget || new THREE.Vector2();
  2324. return result.copy( point ).clamp( this.min, this.max );
  2325. },
  2326. distanceToPoint: function () {
  2327. var v1 = new THREE.Vector2();
  2328. return function distanceToPoint( point ) {
  2329. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  2330. return clampedPoint.sub( point ).length();
  2331. };
  2332. }(),
  2333. intersect: function ( box ) {
  2334. this.min.max( box.min );
  2335. this.max.min( box.max );
  2336. return this;
  2337. },
  2338. union: function ( box ) {
  2339. this.min.min( box.min );
  2340. this.max.max( box.max );
  2341. return this;
  2342. },
  2343. translate: function ( offset ) {
  2344. this.min.add( offset );
  2345. this.max.add( offset );
  2346. return this;
  2347. },
  2348. equals: function ( box ) {
  2349. return box.min.equals( this.min ) && box.max.equals( this.max );
  2350. }
  2351. };
  2352. // File:src/math/Box3.js
  2353. /**
  2354. * @author bhouston / http://clara.io
  2355. * @author WestLangley / http://github.com/WestLangley
  2356. */
  2357. THREE.Box3 = function ( min, max ) {
  2358. this.min = ( min !== undefined ) ? min : new THREE.Vector3( + Infinity, + Infinity, + Infinity );
  2359. this.max = ( max !== undefined ) ? max : new THREE.Vector3( - Infinity, - Infinity, - Infinity );
  2360. };
  2361. THREE.Box3.prototype = {
  2362. constructor: THREE.Box3,
  2363. set: function ( min, max ) {
  2364. this.min.copy( min );
  2365. this.max.copy( max );
  2366. return this;
  2367. },
  2368. setFromArray: function ( array ) {
  2369. var minX = + Infinity;
  2370. var minY = + Infinity;
  2371. var minZ = + Infinity;
  2372. var maxX = - Infinity;
  2373. var maxY = - Infinity;
  2374. var maxZ = - Infinity;
  2375. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  2376. var x = array[ i ];
  2377. var y = array[ i + 1 ];
  2378. var z = array[ i + 2 ];
  2379. if ( x < minX ) minX = x;
  2380. if ( y < minY ) minY = y;
  2381. if ( z < minZ ) minZ = z;
  2382. if ( x > maxX ) maxX = x;
  2383. if ( y > maxY ) maxY = y;
  2384. if ( z > maxZ ) maxZ = z;
  2385. }
  2386. this.min.set( minX, minY, minZ );
  2387. this.max.set( maxX, maxY, maxZ );
  2388. },
  2389. setFromPoints: function ( points ) {
  2390. this.makeEmpty();
  2391. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2392. this.expandByPoint( points[ i ] );
  2393. }
  2394. return this;
  2395. },
  2396. setFromCenterAndSize: function () {
  2397. var v1 = new THREE.Vector3();
  2398. return function setFromCenterAndSize( center, size ) {
  2399. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2400. this.min.copy( center ).sub( halfSize );
  2401. this.max.copy( center ).add( halfSize );
  2402. return this;
  2403. };
  2404. }(),
  2405. setFromObject: function () {
  2406. // Computes the world-axis-aligned bounding box of an object (including its children),
  2407. // accounting for both the object's, and children's, world transforms
  2408. var v1 = new THREE.Vector3();
  2409. return function setFromObject( object ) {
  2410. var scope = this;
  2411. object.updateMatrixWorld( true );
  2412. this.makeEmpty();
  2413. object.traverse( function ( node ) {
  2414. var geometry = node.geometry;
  2415. if ( geometry !== undefined ) {
  2416. if ( geometry instanceof THREE.Geometry ) {
  2417. var vertices = geometry.vertices;
  2418. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  2419. v1.copy( vertices[ i ] );
  2420. v1.applyMatrix4( node.matrixWorld );
  2421. scope.expandByPoint( v1 );
  2422. }
  2423. } else if ( geometry instanceof THREE.BufferGeometry ) {
  2424. var attribute = geometry.attributes.position;
  2425. if ( attribute !== undefined ) {
  2426. var array, offset, stride;
  2427. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  2428. array = attribute.data.array;
  2429. offset = attribute.offset;
  2430. stride = attribute.data.stride;
  2431. } else {
  2432. array = attribute.array;
  2433. offset = 0;
  2434. stride = 3;
  2435. }
  2436. for ( var i = offset, il = array.length; i < il; i += stride ) {
  2437. v1.fromArray( array, i );
  2438. v1.applyMatrix4( node.matrixWorld );
  2439. scope.expandByPoint( v1 );
  2440. }
  2441. }
  2442. }
  2443. }
  2444. } );
  2445. return this;
  2446. };
  2447. }(),
  2448. clone: function () {
  2449. return new this.constructor().copy( this );
  2450. },
  2451. copy: function ( box ) {
  2452. this.min.copy( box.min );
  2453. this.max.copy( box.max );
  2454. return this;
  2455. },
  2456. makeEmpty: function () {
  2457. this.min.x = this.min.y = this.min.z = + Infinity;
  2458. this.max.x = this.max.y = this.max.z = - Infinity;
  2459. return this;
  2460. },
  2461. isEmpty: function () {
  2462. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2463. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  2464. },
  2465. center: function ( optionalTarget ) {
  2466. var result = optionalTarget || new THREE.Vector3();
  2467. return result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2468. },
  2469. size: function ( optionalTarget ) {
  2470. var result = optionalTarget || new THREE.Vector3();
  2471. return result.subVectors( this.max, this.min );
  2472. },
  2473. expandByPoint: function ( point ) {
  2474. this.min.min( point );
  2475. this.max.max( point );
  2476. return this;
  2477. },
  2478. expandByVector: function ( vector ) {
  2479. this.min.sub( vector );
  2480. this.max.add( vector );
  2481. return this;
  2482. },
  2483. expandByScalar: function ( scalar ) {
  2484. this.min.addScalar( - scalar );
  2485. this.max.addScalar( scalar );
  2486. return this;
  2487. },
  2488. containsPoint: function ( point ) {
  2489. if ( point.x < this.min.x || point.x > this.max.x ||
  2490. point.y < this.min.y || point.y > this.max.y ||
  2491. point.z < this.min.z || point.z > this.max.z ) {
  2492. return false;
  2493. }
  2494. return true;
  2495. },
  2496. containsBox: function ( box ) {
  2497. if ( ( this.min.x <= box.min.x ) && ( box.max.x <= this.max.x ) &&
  2498. ( this.min.y <= box.min.y ) && ( box.max.y <= this.max.y ) &&
  2499. ( this.min.z <= box.min.z ) && ( box.max.z <= this.max.z ) ) {
  2500. return true;
  2501. }
  2502. return false;
  2503. },
  2504. getParameter: function ( point, optionalTarget ) {
  2505. // This can potentially have a divide by zero if the box
  2506. // has a size dimension of 0.
  2507. var result = optionalTarget || new THREE.Vector3();
  2508. return result.set(
  2509. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2510. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  2511. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  2512. );
  2513. },
  2514. intersectsBox: function ( box ) {
  2515. // using 6 splitting planes to rule out intersections.
  2516. if ( box.max.x < this.min.x || box.min.x > this.max.x ||
  2517. box.max.y < this.min.y || box.min.y > this.max.y ||
  2518. box.max.z < this.min.z || box.min.z > this.max.z ) {
  2519. return false;
  2520. }
  2521. return true;
  2522. },
  2523. intersectsSphere: ( function () {
  2524. var closestPoint;
  2525. return function intersectsSphere( sphere ) {
  2526. if ( closestPoint === undefined ) closestPoint = new THREE.Vector3();
  2527. // Find the point on the AABB closest to the sphere center.
  2528. this.clampPoint( sphere.center, closestPoint );
  2529. // If that point is inside the sphere, the AABB and sphere intersect.
  2530. return closestPoint.distanceToSquared( sphere.center ) <= ( sphere.radius * sphere.radius );
  2531. };
  2532. } )(),
  2533. intersectsPlane: function ( plane ) {
  2534. // We compute the minimum and maximum dot product values. If those values
  2535. // are on the same side (back or front) of the plane, then there is no intersection.
  2536. var min, max;
  2537. if ( plane.normal.x > 0 ) {
  2538. min = plane.normal.x * this.min.x;
  2539. max = plane.normal.x * this.max.x;
  2540. } else {
  2541. min = plane.normal.x * this.max.x;
  2542. max = plane.normal.x * this.min.x;
  2543. }
  2544. if ( plane.normal.y > 0 ) {
  2545. min += plane.normal.y * this.min.y;
  2546. max += plane.normal.y * this.max.y;
  2547. } else {
  2548. min += plane.normal.y * this.max.y;
  2549. max += plane.normal.y * this.min.y;
  2550. }
  2551. if ( plane.normal.z > 0 ) {
  2552. min += plane.normal.z * this.min.z;
  2553. max += plane.normal.z * this.max.z;
  2554. } else {
  2555. min += plane.normal.z * this.max.z;
  2556. max += plane.normal.z * this.min.z;
  2557. }
  2558. return ( min <= plane.constant && max >= plane.constant );
  2559. },
  2560. clampPoint: function ( point, optionalTarget ) {
  2561. var result = optionalTarget || new THREE.Vector3();
  2562. return result.copy( point ).clamp( this.min, this.max );
  2563. },
  2564. distanceToPoint: function () {
  2565. var v1 = new THREE.Vector3();
  2566. return function distanceToPoint( point ) {
  2567. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  2568. return clampedPoint.sub( point ).length();
  2569. };
  2570. }(),
  2571. getBoundingSphere: function () {
  2572. var v1 = new THREE.Vector3();
  2573. return function getBoundingSphere( optionalTarget ) {
  2574. var result = optionalTarget || new THREE.Sphere();
  2575. result.center = this.center();
  2576. result.radius = this.size( v1 ).length() * 0.5;
  2577. return result;
  2578. };
  2579. }(),
  2580. intersect: function ( box ) {
  2581. this.min.max( box.min );
  2582. this.max.min( box.max );
  2583. // 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.
  2584. if( this.isEmpty() ) this.makeEmpty();
  2585. return this;
  2586. },
  2587. union: function ( box ) {
  2588. this.min.min( box.min );
  2589. this.max.max( box.max );
  2590. return this;
  2591. },
  2592. applyMatrix4: function () {
  2593. var points = [
  2594. new THREE.Vector3(),
  2595. new THREE.Vector3(),
  2596. new THREE.Vector3(),
  2597. new THREE.Vector3(),
  2598. new THREE.Vector3(),
  2599. new THREE.Vector3(),
  2600. new THREE.Vector3(),
  2601. new THREE.Vector3()
  2602. ];
  2603. return function applyMatrix4( matrix ) {
  2604. // transform of empty box is an empty box.
  2605. if( this.isEmpty() ) return this;
  2606. // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  2607. points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
  2608. points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
  2609. points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
  2610. points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
  2611. points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
  2612. points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
  2613. points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
  2614. points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
  2615. this.setFromPoints( points );
  2616. return this;
  2617. };
  2618. }(),
  2619. translate: function ( offset ) {
  2620. this.min.add( offset );
  2621. this.max.add( offset );
  2622. return this;
  2623. },
  2624. equals: function ( box ) {
  2625. return box.min.equals( this.min ) && box.max.equals( this.max );
  2626. }
  2627. };
  2628. // File:src/math/Matrix3.js
  2629. /**
  2630. * @author alteredq / http://alteredqualia.com/
  2631. * @author WestLangley / http://github.com/WestLangley
  2632. * @author bhouston / http://clara.io
  2633. * @author tschw
  2634. */
  2635. THREE.Matrix3 = function () {
  2636. this.elements = new Float32Array( [
  2637. 1, 0, 0,
  2638. 0, 1, 0,
  2639. 0, 0, 1
  2640. ] );
  2641. if ( arguments.length > 0 ) {
  2642. console.error( 'THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.' );
  2643. }
  2644. };
  2645. THREE.Matrix3.prototype = {
  2646. constructor: THREE.Matrix3,
  2647. set: function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  2648. var te = this.elements;
  2649. te[ 0 ] = n11; te[ 1 ] = n21; te[ 2 ] = n31;
  2650. te[ 3 ] = n12; te[ 4 ] = n22; te[ 5 ] = n32;
  2651. te[ 6 ] = n13; te[ 7 ] = n23; te[ 8 ] = n33;
  2652. return this;
  2653. },
  2654. identity: function () {
  2655. this.set(
  2656. 1, 0, 0,
  2657. 0, 1, 0,
  2658. 0, 0, 1
  2659. );
  2660. return this;
  2661. },
  2662. clone: function () {
  2663. return new this.constructor().fromArray( this.elements );
  2664. },
  2665. copy: function ( m ) {
  2666. var me = m.elements;
  2667. this.set(
  2668. me[ 0 ], me[ 3 ], me[ 6 ],
  2669. me[ 1 ], me[ 4 ], me[ 7 ],
  2670. me[ 2 ], me[ 5 ], me[ 8 ]
  2671. );
  2672. return this;
  2673. },
  2674. setFromMatrix4: function( m ) {
  2675. var me = m.elements;
  2676. this.set(
  2677. me[ 0 ], me[ 4 ], me[ 8 ],
  2678. me[ 1 ], me[ 5 ], me[ 9 ],
  2679. me[ 2 ], me[ 6 ], me[ 10 ]
  2680. );
  2681. return this;
  2682. },
  2683. applyToVector3Array: function () {
  2684. var v1;
  2685. return function applyToVector3Array( array, offset, length ) {
  2686. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2687. if ( offset === undefined ) offset = 0;
  2688. if ( length === undefined ) length = array.length;
  2689. for ( var i = 0, j = offset; i < length; i += 3, j += 3 ) {
  2690. v1.fromArray( array, j );
  2691. v1.applyMatrix3( this );
  2692. v1.toArray( array, j );
  2693. }
  2694. return array;
  2695. };
  2696. }(),
  2697. applyToBuffer: function () {
  2698. var v1;
  2699. return function applyToBuffer( buffer, offset, length ) {
  2700. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2701. if ( offset === undefined ) offset = 0;
  2702. if ( length === undefined ) length = buffer.length / buffer.itemSize;
  2703. for ( var i = 0, j = offset; i < length; i ++, j ++ ) {
  2704. v1.x = buffer.getX( j );
  2705. v1.y = buffer.getY( j );
  2706. v1.z = buffer.getZ( j );
  2707. v1.applyMatrix3( this );
  2708. buffer.setXYZ( v1.x, v1.y, v1.z );
  2709. }
  2710. return buffer;
  2711. };
  2712. }(),
  2713. multiplyScalar: function ( s ) {
  2714. var te = this.elements;
  2715. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  2716. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  2717. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  2718. return this;
  2719. },
  2720. determinant: function () {
  2721. var te = this.elements;
  2722. var a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  2723. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  2724. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  2725. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  2726. },
  2727. getInverse: function ( matrix, throwOnDegenerate ) {
  2728. if ( matrix instanceof THREE.Matrix4 ) {
  2729. console.error( "THREE.Matrix3.getInverse no longer takes a Matrix4 argument." );
  2730. }
  2731. var me = matrix.elements,
  2732. te = this.elements,
  2733. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ],
  2734. n12 = me[ 3 ], n22 = me[ 4 ], n32 = me[ 5 ],
  2735. n13 = me[ 6 ], n23 = me[ 7 ], n33 = me[ 8 ],
  2736. t11 = n33 * n22 - n32 * n23,
  2737. t12 = n32 * n13 - n33 * n12,
  2738. t13 = n23 * n12 - n22 * n13,
  2739. det = n11 * t11 + n21 * t12 + n31 * t13;
  2740. if ( det === 0 ) {
  2741. var msg = "THREE.Matrix3.getInverse(): can't invert matrix, determinant is 0";
  2742. if ( throwOnDegenerate || false ) {
  2743. throw new Error( msg );
  2744. } else {
  2745. console.warn( msg );
  2746. }
  2747. return this.identity();
  2748. }
  2749. var detInv = 1 / det;
  2750. te[ 0 ] = t11 * detInv;
  2751. te[ 1 ] = ( n31 * n23 - n33 * n21 ) * detInv;
  2752. te[ 2 ] = ( n32 * n21 - n31 * n22 ) * detInv;
  2753. te[ 3 ] = t12 * detInv;
  2754. te[ 4 ] = ( n33 * n11 - n31 * n13 ) * detInv;
  2755. te[ 5 ] = ( n31 * n12 - n32 * n11 ) * detInv;
  2756. te[ 6 ] = t13 * detInv;
  2757. te[ 7 ] = ( n21 * n13 - n23 * n11 ) * detInv;
  2758. te[ 8 ] = ( n22 * n11 - n21 * n12 ) * detInv;
  2759. return this;
  2760. },
  2761. transpose: function () {
  2762. var tmp, m = this.elements;
  2763. tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
  2764. tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
  2765. tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
  2766. return this;
  2767. },
  2768. flattenToArrayOffset: function ( array, offset ) {
  2769. console.warn( "THREE.Matrix3: .flattenToArrayOffset is deprecated " +
  2770. "- just use .toArray instead." );
  2771. return this.toArray( array, offset );
  2772. },
  2773. getNormalMatrix: function ( matrix4 ) {
  2774. return this.setFromMatrix4( matrix4 ).getInverse( this ).transpose();
  2775. },
  2776. transposeIntoArray: function ( r ) {
  2777. var m = this.elements;
  2778. r[ 0 ] = m[ 0 ];
  2779. r[ 1 ] = m[ 3 ];
  2780. r[ 2 ] = m[ 6 ];
  2781. r[ 3 ] = m[ 1 ];
  2782. r[ 4 ] = m[ 4 ];
  2783. r[ 5 ] = m[ 7 ];
  2784. r[ 6 ] = m[ 2 ];
  2785. r[ 7 ] = m[ 5 ];
  2786. r[ 8 ] = m[ 8 ];
  2787. return this;
  2788. },
  2789. fromArray: function ( array ) {
  2790. this.elements.set( array );
  2791. return this;
  2792. },
  2793. toArray: function ( array, offset ) {
  2794. if ( array === undefined ) array = [];
  2795. if ( offset === undefined ) offset = 0;
  2796. var te = this.elements;
  2797. array[ offset ] = te[ 0 ];
  2798. array[ offset + 1 ] = te[ 1 ];
  2799. array[ offset + 2 ] = te[ 2 ];
  2800. array[ offset + 3 ] = te[ 3 ];
  2801. array[ offset + 4 ] = te[ 4 ];
  2802. array[ offset + 5 ] = te[ 5 ];
  2803. array[ offset + 6 ] = te[ 6 ];
  2804. array[ offset + 7 ] = te[ 7 ];
  2805. array[ offset + 8 ] = te[ 8 ];
  2806. return array;
  2807. }
  2808. };
  2809. // File:src/math/Matrix4.js
  2810. /**
  2811. * @author mrdoob / http://mrdoob.com/
  2812. * @author supereggbert / http://www.paulbrunt.co.uk/
  2813. * @author philogb / http://blog.thejit.org/
  2814. * @author jordi_ros / http://plattsoft.com
  2815. * @author D1plo1d / http://github.com/D1plo1d
  2816. * @author alteredq / http://alteredqualia.com/
  2817. * @author mikael emtinger / http://gomo.se/
  2818. * @author timknip / http://www.floorplanner.com/
  2819. * @author bhouston / http://clara.io
  2820. * @author WestLangley / http://github.com/WestLangley
  2821. */
  2822. THREE.Matrix4 = function () {
  2823. this.elements = new Float32Array( [
  2824. 1, 0, 0, 0,
  2825. 0, 1, 0, 0,
  2826. 0, 0, 1, 0,
  2827. 0, 0, 0, 1
  2828. ] );
  2829. if ( arguments.length > 0 ) {
  2830. console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' );
  2831. }
  2832. };
  2833. THREE.Matrix4.prototype = {
  2834. constructor: THREE.Matrix4,
  2835. set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  2836. var te = this.elements;
  2837. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  2838. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  2839. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  2840. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  2841. return this;
  2842. },
  2843. identity: function () {
  2844. this.set(
  2845. 1, 0, 0, 0,
  2846. 0, 1, 0, 0,
  2847. 0, 0, 1, 0,
  2848. 0, 0, 0, 1
  2849. );
  2850. return this;
  2851. },
  2852. clone: function () {
  2853. return new THREE.Matrix4().fromArray( this.elements );
  2854. },
  2855. copy: function ( m ) {
  2856. this.elements.set( m.elements );
  2857. return this;
  2858. },
  2859. copyPosition: function ( m ) {
  2860. var te = this.elements;
  2861. var me = m.elements;
  2862. te[ 12 ] = me[ 12 ];
  2863. te[ 13 ] = me[ 13 ];
  2864. te[ 14 ] = me[ 14 ];
  2865. return this;
  2866. },
  2867. extractBasis: function ( xAxis, yAxis, zAxis ) {
  2868. xAxis.setFromMatrixColumn( this, 0 );
  2869. yAxis.setFromMatrixColumn( this, 1 );
  2870. zAxis.setFromMatrixColumn( this, 2 );
  2871. return this;
  2872. },
  2873. makeBasis: function ( xAxis, yAxis, zAxis ) {
  2874. this.set(
  2875. xAxis.x, yAxis.x, zAxis.x, 0,
  2876. xAxis.y, yAxis.y, zAxis.y, 0,
  2877. xAxis.z, yAxis.z, zAxis.z, 0,
  2878. 0, 0, 0, 1
  2879. );
  2880. return this;
  2881. },
  2882. extractRotation: function () {
  2883. var v1;
  2884. return function extractRotation( m ) {
  2885. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2886. var te = this.elements;
  2887. var me = m.elements;
  2888. var scaleX = 1 / v1.setFromMatrixColumn( m, 0 ).length();
  2889. var scaleY = 1 / v1.setFromMatrixColumn( m, 1 ).length();
  2890. var scaleZ = 1 / v1.setFromMatrixColumn( m, 2 ).length();
  2891. te[ 0 ] = me[ 0 ] * scaleX;
  2892. te[ 1 ] = me[ 1 ] * scaleX;
  2893. te[ 2 ] = me[ 2 ] * scaleX;
  2894. te[ 4 ] = me[ 4 ] * scaleY;
  2895. te[ 5 ] = me[ 5 ] * scaleY;
  2896. te[ 6 ] = me[ 6 ] * scaleY;
  2897. te[ 8 ] = me[ 8 ] * scaleZ;
  2898. te[ 9 ] = me[ 9 ] * scaleZ;
  2899. te[ 10 ] = me[ 10 ] * scaleZ;
  2900. return this;
  2901. };
  2902. }(),
  2903. makeRotationFromEuler: function ( euler ) {
  2904. if ( euler instanceof THREE.Euler === false ) {
  2905. console.error( 'THREE.Matrix: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  2906. }
  2907. var te = this.elements;
  2908. var x = euler.x, y = euler.y, z = euler.z;
  2909. var a = Math.cos( x ), b = Math.sin( x );
  2910. var c = Math.cos( y ), d = Math.sin( y );
  2911. var e = Math.cos( z ), f = Math.sin( z );
  2912. if ( euler.order === 'XYZ' ) {
  2913. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2914. te[ 0 ] = c * e;
  2915. te[ 4 ] = - c * f;
  2916. te[ 8 ] = d;
  2917. te[ 1 ] = af + be * d;
  2918. te[ 5 ] = ae - bf * d;
  2919. te[ 9 ] = - b * c;
  2920. te[ 2 ] = bf - ae * d;
  2921. te[ 6 ] = be + af * d;
  2922. te[ 10 ] = a * c;
  2923. } else if ( euler.order === 'YXZ' ) {
  2924. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2925. te[ 0 ] = ce + df * b;
  2926. te[ 4 ] = de * b - cf;
  2927. te[ 8 ] = a * d;
  2928. te[ 1 ] = a * f;
  2929. te[ 5 ] = a * e;
  2930. te[ 9 ] = - b;
  2931. te[ 2 ] = cf * b - de;
  2932. te[ 6 ] = df + ce * b;
  2933. te[ 10 ] = a * c;
  2934. } else if ( euler.order === 'ZXY' ) {
  2935. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2936. te[ 0 ] = ce - df * b;
  2937. te[ 4 ] = - a * f;
  2938. te[ 8 ] = de + cf * b;
  2939. te[ 1 ] = cf + de * b;
  2940. te[ 5 ] = a * e;
  2941. te[ 9 ] = df - ce * b;
  2942. te[ 2 ] = - a * d;
  2943. te[ 6 ] = b;
  2944. te[ 10 ] = a * c;
  2945. } else if ( euler.order === 'ZYX' ) {
  2946. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2947. te[ 0 ] = c * e;
  2948. te[ 4 ] = be * d - af;
  2949. te[ 8 ] = ae * d + bf;
  2950. te[ 1 ] = c * f;
  2951. te[ 5 ] = bf * d + ae;
  2952. te[ 9 ] = af * d - be;
  2953. te[ 2 ] = - d;
  2954. te[ 6 ] = b * c;
  2955. te[ 10 ] = a * c;
  2956. } else if ( euler.order === 'YZX' ) {
  2957. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2958. te[ 0 ] = c * e;
  2959. te[ 4 ] = bd - ac * f;
  2960. te[ 8 ] = bc * f + ad;
  2961. te[ 1 ] = f;
  2962. te[ 5 ] = a * e;
  2963. te[ 9 ] = - b * e;
  2964. te[ 2 ] = - d * e;
  2965. te[ 6 ] = ad * f + bc;
  2966. te[ 10 ] = ac - bd * f;
  2967. } else if ( euler.order === 'XZY' ) {
  2968. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2969. te[ 0 ] = c * e;
  2970. te[ 4 ] = - f;
  2971. te[ 8 ] = d * e;
  2972. te[ 1 ] = ac * f + bd;
  2973. te[ 5 ] = a * e;
  2974. te[ 9 ] = ad * f - bc;
  2975. te[ 2 ] = bc * f - ad;
  2976. te[ 6 ] = b * e;
  2977. te[ 10 ] = bd * f + ac;
  2978. }
  2979. // last column
  2980. te[ 3 ] = 0;
  2981. te[ 7 ] = 0;
  2982. te[ 11 ] = 0;
  2983. // bottom row
  2984. te[ 12 ] = 0;
  2985. te[ 13 ] = 0;
  2986. te[ 14 ] = 0;
  2987. te[ 15 ] = 1;
  2988. return this;
  2989. },
  2990. makeRotationFromQuaternion: function ( q ) {
  2991. var te = this.elements;
  2992. var x = q.x, y = q.y, z = q.z, w = q.w;
  2993. var x2 = x + x, y2 = y + y, z2 = z + z;
  2994. var xx = x * x2, xy = x * y2, xz = x * z2;
  2995. var yy = y * y2, yz = y * z2, zz = z * z2;
  2996. var wx = w * x2, wy = w * y2, wz = w * z2;
  2997. te[ 0 ] = 1 - ( yy + zz );
  2998. te[ 4 ] = xy - wz;
  2999. te[ 8 ] = xz + wy;
  3000. te[ 1 ] = xy + wz;
  3001. te[ 5 ] = 1 - ( xx + zz );
  3002. te[ 9 ] = yz - wx;
  3003. te[ 2 ] = xz - wy;
  3004. te[ 6 ] = yz + wx;
  3005. te[ 10 ] = 1 - ( xx + yy );
  3006. // last column
  3007. te[ 3 ] = 0;
  3008. te[ 7 ] = 0;
  3009. te[ 11 ] = 0;
  3010. // bottom row
  3011. te[ 12 ] = 0;
  3012. te[ 13 ] = 0;
  3013. te[ 14 ] = 0;
  3014. te[ 15 ] = 1;
  3015. return this;
  3016. },
  3017. lookAt: function () {
  3018. var x, y, z;
  3019. return function lookAt( eye, target, up ) {
  3020. if ( x === undefined ) {
  3021. x = new THREE.Vector3();
  3022. y = new THREE.Vector3();
  3023. z = new THREE.Vector3();
  3024. }
  3025. var te = this.elements;
  3026. z.subVectors( eye, target ).normalize();
  3027. if ( z.lengthSq() === 0 ) {
  3028. z.z = 1;
  3029. }
  3030. x.crossVectors( up, z ).normalize();
  3031. if ( x.lengthSq() === 0 ) {
  3032. z.z += 0.0001;
  3033. x.crossVectors( up, z ).normalize();
  3034. }
  3035. y.crossVectors( z, x );
  3036. te[ 0 ] = x.x; te[ 4 ] = y.x; te[ 8 ] = z.x;
  3037. te[ 1 ] = x.y; te[ 5 ] = y.y; te[ 9 ] = z.y;
  3038. te[ 2 ] = x.z; te[ 6 ] = y.z; te[ 10 ] = z.z;
  3039. return this;
  3040. };
  3041. }(),
  3042. multiply: function ( m, n ) {
  3043. if ( n !== undefined ) {
  3044. console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' );
  3045. return this.multiplyMatrices( m, n );
  3046. }
  3047. return this.multiplyMatrices( this, m );
  3048. },
  3049. premultiply: function ( m ) {
  3050. return this.multiplyMatrices( m, this );
  3051. },
  3052. multiplyMatrices: function ( a, b ) {
  3053. var ae = a.elements;
  3054. var be = b.elements;
  3055. var te = this.elements;
  3056. var a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  3057. var a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  3058. var a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  3059. var a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  3060. var b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  3061. var b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  3062. var b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  3063. var b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  3064. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  3065. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  3066. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  3067. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  3068. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  3069. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  3070. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  3071. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  3072. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  3073. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  3074. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  3075. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  3076. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  3077. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  3078. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  3079. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  3080. return this;
  3081. },
  3082. multiplyToArray: function ( a, b, r ) {
  3083. var te = this.elements;
  3084. this.multiplyMatrices( a, b );
  3085. r[ 0 ] = te[ 0 ]; r[ 1 ] = te[ 1 ]; r[ 2 ] = te[ 2 ]; r[ 3 ] = te[ 3 ];
  3086. r[ 4 ] = te[ 4 ]; r[ 5 ] = te[ 5 ]; r[ 6 ] = te[ 6 ]; r[ 7 ] = te[ 7 ];
  3087. r[ 8 ] = te[ 8 ]; r[ 9 ] = te[ 9 ]; r[ 10 ] = te[ 10 ]; r[ 11 ] = te[ 11 ];
  3088. r[ 12 ] = te[ 12 ]; r[ 13 ] = te[ 13 ]; r[ 14 ] = te[ 14 ]; r[ 15 ] = te[ 15 ];
  3089. return this;
  3090. },
  3091. multiplyScalar: function ( s ) {
  3092. var te = this.elements;
  3093. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  3094. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  3095. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  3096. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  3097. return this;
  3098. },
  3099. applyToVector3Array: function () {
  3100. var v1;
  3101. return function applyToVector3Array( array, offset, length ) {
  3102. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3103. if ( offset === undefined ) offset = 0;
  3104. if ( length === undefined ) length = array.length;
  3105. for ( var i = 0, j = offset; i < length; i += 3, j += 3 ) {
  3106. v1.fromArray( array, j );
  3107. v1.applyMatrix4( this );
  3108. v1.toArray( array, j );
  3109. }
  3110. return array;
  3111. };
  3112. }(),
  3113. applyToBuffer: function () {
  3114. var v1;
  3115. return function applyToBuffer( buffer, offset, length ) {
  3116. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3117. if ( offset === undefined ) offset = 0;
  3118. if ( length === undefined ) length = buffer.length / buffer.itemSize;
  3119. for ( var i = 0, j = offset; i < length; i ++, j ++ ) {
  3120. v1.x = buffer.getX( j );
  3121. v1.y = buffer.getY( j );
  3122. v1.z = buffer.getZ( j );
  3123. v1.applyMatrix4( this );
  3124. buffer.setXYZ( v1.x, v1.y, v1.z );
  3125. }
  3126. return buffer;
  3127. };
  3128. }(),
  3129. determinant: function () {
  3130. var te = this.elements;
  3131. var n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  3132. var n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  3133. var n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  3134. var n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  3135. //TODO: make this more efficient
  3136. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  3137. return (
  3138. n41 * (
  3139. + n14 * n23 * n32
  3140. - n13 * n24 * n32
  3141. - n14 * n22 * n33
  3142. + n12 * n24 * n33
  3143. + n13 * n22 * n34
  3144. - n12 * n23 * n34
  3145. ) +
  3146. n42 * (
  3147. + n11 * n23 * n34
  3148. - n11 * n24 * n33
  3149. + n14 * n21 * n33
  3150. - n13 * n21 * n34
  3151. + n13 * n24 * n31
  3152. - n14 * n23 * n31
  3153. ) +
  3154. n43 * (
  3155. + n11 * n24 * n32
  3156. - n11 * n22 * n34
  3157. - n14 * n21 * n32
  3158. + n12 * n21 * n34
  3159. + n14 * n22 * n31
  3160. - n12 * n24 * n31
  3161. ) +
  3162. n44 * (
  3163. - n13 * n22 * n31
  3164. - n11 * n23 * n32
  3165. + n11 * n22 * n33
  3166. + n13 * n21 * n32
  3167. - n12 * n21 * n33
  3168. + n12 * n23 * n31
  3169. )
  3170. );
  3171. },
  3172. transpose: function () {
  3173. var te = this.elements;
  3174. var tmp;
  3175. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  3176. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  3177. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  3178. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  3179. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  3180. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  3181. return this;
  3182. },
  3183. flattenToArrayOffset: function ( array, offset ) {
  3184. console.warn( "THREE.Matrix3: .flattenToArrayOffset is deprecated " +
  3185. "- just use .toArray instead." );
  3186. return this.toArray( array, offset );
  3187. },
  3188. getPosition: function () {
  3189. var v1;
  3190. return function getPosition() {
  3191. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3192. console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
  3193. return v1.setFromMatrixColumn( this, 3 );
  3194. };
  3195. }(),
  3196. setPosition: function ( v ) {
  3197. var te = this.elements;
  3198. te[ 12 ] = v.x;
  3199. te[ 13 ] = v.y;
  3200. te[ 14 ] = v.z;
  3201. return this;
  3202. },
  3203. getInverse: function ( m, throwOnDegenerate ) {
  3204. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  3205. var te = this.elements,
  3206. me = m.elements,
  3207. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ], n41 = me[ 3 ],
  3208. n12 = me[ 4 ], n22 = me[ 5 ], n32 = me[ 6 ], n42 = me[ 7 ],
  3209. n13 = me[ 8 ], n23 = me[ 9 ], n33 = me[ 10 ], n43 = me[ 11 ],
  3210. n14 = me[ 12 ], n24 = me[ 13 ], n34 = me[ 14 ], n44 = me[ 15 ],
  3211. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  3212. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  3213. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  3214. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  3215. var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  3216. if ( det === 0 ) {
  3217. var msg = "THREE.Matrix4.getInverse(): can't invert matrix, determinant is 0";
  3218. if ( throwOnDegenerate || false ) {
  3219. throw new Error( msg );
  3220. } else {
  3221. console.warn( msg );
  3222. }
  3223. return this.identity();
  3224. }
  3225. var detInv = 1 / det;
  3226. te[ 0 ] = t11 * detInv;
  3227. te[ 1 ] = ( n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44 ) * detInv;
  3228. te[ 2 ] = ( n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44 ) * detInv;
  3229. te[ 3 ] = ( n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43 ) * detInv;
  3230. te[ 4 ] = t12 * detInv;
  3231. te[ 5 ] = ( n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44 ) * detInv;
  3232. te[ 6 ] = ( n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44 ) * detInv;
  3233. te[ 7 ] = ( n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43 ) * detInv;
  3234. te[ 8 ] = t13 * detInv;
  3235. te[ 9 ] = ( n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44 ) * detInv;
  3236. te[ 10 ] = ( n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44 ) * detInv;
  3237. te[ 11 ] = ( n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43 ) * detInv;
  3238. te[ 12 ] = t14 * detInv;
  3239. te[ 13 ] = ( n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34 ) * detInv;
  3240. te[ 14 ] = ( n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34 ) * detInv;
  3241. te[ 15 ] = ( n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33 ) * detInv;
  3242. return this;
  3243. },
  3244. scale: function ( v ) {
  3245. var te = this.elements;
  3246. var x = v.x, y = v.y, z = v.z;
  3247. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  3248. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  3249. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  3250. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  3251. return this;
  3252. },
  3253. getMaxScaleOnAxis: function () {
  3254. var te = this.elements;
  3255. var scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  3256. var scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  3257. var scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  3258. return Math.sqrt( Math.max( scaleXSq, scaleYSq, scaleZSq ) );
  3259. },
  3260. makeTranslation: function ( x, y, z ) {
  3261. this.set(
  3262. 1, 0, 0, x,
  3263. 0, 1, 0, y,
  3264. 0, 0, 1, z,
  3265. 0, 0, 0, 1
  3266. );
  3267. return this;
  3268. },
  3269. makeRotationX: function ( theta ) {
  3270. var c = Math.cos( theta ), s = Math.sin( theta );
  3271. this.set(
  3272. 1, 0, 0, 0,
  3273. 0, c, - s, 0,
  3274. 0, s, c, 0,
  3275. 0, 0, 0, 1
  3276. );
  3277. return this;
  3278. },
  3279. makeRotationY: function ( theta ) {
  3280. var c = Math.cos( theta ), s = Math.sin( theta );
  3281. this.set(
  3282. c, 0, s, 0,
  3283. 0, 1, 0, 0,
  3284. - s, 0, c, 0,
  3285. 0, 0, 0, 1
  3286. );
  3287. return this;
  3288. },
  3289. makeRotationZ: function ( theta ) {
  3290. var c = Math.cos( theta ), s = Math.sin( theta );
  3291. this.set(
  3292. c, - s, 0, 0,
  3293. s, c, 0, 0,
  3294. 0, 0, 1, 0,
  3295. 0, 0, 0, 1
  3296. );
  3297. return this;
  3298. },
  3299. makeRotationAxis: function ( axis, angle ) {
  3300. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  3301. var c = Math.cos( angle );
  3302. var s = Math.sin( angle );
  3303. var t = 1 - c;
  3304. var x = axis.x, y = axis.y, z = axis.z;
  3305. var tx = t * x, ty = t * y;
  3306. this.set(
  3307. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  3308. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  3309. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  3310. 0, 0, 0, 1
  3311. );
  3312. return this;
  3313. },
  3314. makeScale: function ( x, y, z ) {
  3315. this.set(
  3316. x, 0, 0, 0,
  3317. 0, y, 0, 0,
  3318. 0, 0, z, 0,
  3319. 0, 0, 0, 1
  3320. );
  3321. return this;
  3322. },
  3323. compose: function ( position, quaternion, scale ) {
  3324. this.makeRotationFromQuaternion( quaternion );
  3325. this.scale( scale );
  3326. this.setPosition( position );
  3327. return this;
  3328. },
  3329. decompose: function () {
  3330. var vector, matrix;
  3331. return function decompose( position, quaternion, scale ) {
  3332. if ( vector === undefined ) {
  3333. vector = new THREE.Vector3();
  3334. matrix = new THREE.Matrix4();
  3335. }
  3336. var te = this.elements;
  3337. var sx = vector.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  3338. var sy = vector.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  3339. var sz = vector.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  3340. // if determine is negative, we need to invert one scale
  3341. var det = this.determinant();
  3342. if ( det < 0 ) {
  3343. sx = - sx;
  3344. }
  3345. position.x = te[ 12 ];
  3346. position.y = te[ 13 ];
  3347. position.z = te[ 14 ];
  3348. // scale the rotation part
  3349. matrix.elements.set( this.elements ); // at this point matrix is incomplete so we can't use .copy()
  3350. var invSX = 1 / sx;
  3351. var invSY = 1 / sy;
  3352. var invSZ = 1 / sz;
  3353. matrix.elements[ 0 ] *= invSX;
  3354. matrix.elements[ 1 ] *= invSX;
  3355. matrix.elements[ 2 ] *= invSX;
  3356. matrix.elements[ 4 ] *= invSY;
  3357. matrix.elements[ 5 ] *= invSY;
  3358. matrix.elements[ 6 ] *= invSY;
  3359. matrix.elements[ 8 ] *= invSZ;
  3360. matrix.elements[ 9 ] *= invSZ;
  3361. matrix.elements[ 10 ] *= invSZ;
  3362. quaternion.setFromRotationMatrix( matrix );
  3363. scale.x = sx;
  3364. scale.y = sy;
  3365. scale.z = sz;
  3366. return this;
  3367. };
  3368. }(),
  3369. makeFrustum: function ( left, right, bottom, top, near, far ) {
  3370. var te = this.elements;
  3371. var x = 2 * near / ( right - left );
  3372. var y = 2 * near / ( top - bottom );
  3373. var a = ( right + left ) / ( right - left );
  3374. var b = ( top + bottom ) / ( top - bottom );
  3375. var c = - ( far + near ) / ( far - near );
  3376. var d = - 2 * far * near / ( far - near );
  3377. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  3378. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  3379. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  3380. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  3381. return this;
  3382. },
  3383. makePerspective: function ( fov, aspect, near, far ) {
  3384. var ymax = near * Math.tan( THREE.Math.DEG2RAD * fov * 0.5 );
  3385. var ymin = - ymax;
  3386. var xmin = ymin * aspect;
  3387. var xmax = ymax * aspect;
  3388. return this.makeFrustum( xmin, xmax, ymin, ymax, near, far );
  3389. },
  3390. makeOrthographic: function ( left, right, top, bottom, near, far ) {
  3391. var te = this.elements;
  3392. var w = 1.0 / ( right - left );
  3393. var h = 1.0 / ( top - bottom );
  3394. var p = 1.0 / ( far - near );
  3395. var x = ( right + left ) * w;
  3396. var y = ( top + bottom ) * h;
  3397. var z = ( far + near ) * p;
  3398. te[ 0 ] = 2 * w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  3399. te[ 1 ] = 0; te[ 5 ] = 2 * h; te[ 9 ] = 0; te[ 13 ] = - y;
  3400. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 * p; te[ 14 ] = - z;
  3401. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  3402. return this;
  3403. },
  3404. equals: function ( matrix ) {
  3405. var te = this.elements;
  3406. var me = matrix.elements;
  3407. for ( var i = 0; i < 16; i ++ ) {
  3408. if ( te[ i ] !== me[ i ] ) return false;
  3409. }
  3410. return true;
  3411. },
  3412. fromArray: function ( array ) {
  3413. this.elements.set( array );
  3414. return this;
  3415. },
  3416. toArray: function ( array, offset ) {
  3417. if ( array === undefined ) array = [];
  3418. if ( offset === undefined ) offset = 0;
  3419. var te = this.elements;
  3420. array[ offset ] = te[ 0 ];
  3421. array[ offset + 1 ] = te[ 1 ];
  3422. array[ offset + 2 ] = te[ 2 ];
  3423. array[ offset + 3 ] = te[ 3 ];
  3424. array[ offset + 4 ] = te[ 4 ];
  3425. array[ offset + 5 ] = te[ 5 ];
  3426. array[ offset + 6 ] = te[ 6 ];
  3427. array[ offset + 7 ] = te[ 7 ];
  3428. array[ offset + 8 ] = te[ 8 ];
  3429. array[ offset + 9 ] = te[ 9 ];
  3430. array[ offset + 10 ] = te[ 10 ];
  3431. array[ offset + 11 ] = te[ 11 ];
  3432. array[ offset + 12 ] = te[ 12 ];
  3433. array[ offset + 13 ] = te[ 13 ];
  3434. array[ offset + 14 ] = te[ 14 ];
  3435. array[ offset + 15 ] = te[ 15 ];
  3436. return array;
  3437. }
  3438. };
  3439. // File:src/math/Ray.js
  3440. /**
  3441. * @author bhouston / http://clara.io
  3442. */
  3443. THREE.Ray = function ( origin, direction ) {
  3444. this.origin = ( origin !== undefined ) ? origin : new THREE.Vector3();
  3445. this.direction = ( direction !== undefined ) ? direction : new THREE.Vector3();
  3446. };
  3447. THREE.Ray.prototype = {
  3448. constructor: THREE.Ray,
  3449. set: function ( origin, direction ) {
  3450. this.origin.copy( origin );
  3451. this.direction.copy( direction );
  3452. return this;
  3453. },
  3454. clone: function () {
  3455. return new this.constructor().copy( this );
  3456. },
  3457. copy: function ( ray ) {
  3458. this.origin.copy( ray.origin );
  3459. this.direction.copy( ray.direction );
  3460. return this;
  3461. },
  3462. at: function ( t, optionalTarget ) {
  3463. var result = optionalTarget || new THREE.Vector3();
  3464. return result.copy( this.direction ).multiplyScalar( t ).add( this.origin );
  3465. },
  3466. lookAt: function ( v ) {
  3467. this.direction.copy( v ).sub( this.origin ).normalize();
  3468. return this;
  3469. },
  3470. recast: function () {
  3471. var v1 = new THREE.Vector3();
  3472. return function recast( t ) {
  3473. this.origin.copy( this.at( t, v1 ) );
  3474. return this;
  3475. };
  3476. }(),
  3477. closestPointToPoint: function ( point, optionalTarget ) {
  3478. var result = optionalTarget || new THREE.Vector3();
  3479. result.subVectors( point, this.origin );
  3480. var directionDistance = result.dot( this.direction );
  3481. if ( directionDistance < 0 ) {
  3482. return result.copy( this.origin );
  3483. }
  3484. return result.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  3485. },
  3486. distanceToPoint: function ( point ) {
  3487. return Math.sqrt( this.distanceSqToPoint( point ) );
  3488. },
  3489. distanceSqToPoint: function () {
  3490. var v1 = new THREE.Vector3();
  3491. return function distanceSqToPoint( point ) {
  3492. var directionDistance = v1.subVectors( point, this.origin ).dot( this.direction );
  3493. // point behind the ray
  3494. if ( directionDistance < 0 ) {
  3495. return this.origin.distanceToSquared( point );
  3496. }
  3497. v1.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  3498. return v1.distanceToSquared( point );
  3499. };
  3500. }(),
  3501. distanceSqToSegment: function () {
  3502. var segCenter = new THREE.Vector3();
  3503. var segDir = new THREE.Vector3();
  3504. var diff = new THREE.Vector3();
  3505. return function distanceSqToSegment( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  3506. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h
  3507. // It returns the min distance between the ray and the segment
  3508. // defined by v0 and v1
  3509. // It can also set two optional targets :
  3510. // - The closest point on the ray
  3511. // - The closest point on the segment
  3512. segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  3513. segDir.copy( v1 ).sub( v0 ).normalize();
  3514. diff.copy( this.origin ).sub( segCenter );
  3515. var segExtent = v0.distanceTo( v1 ) * 0.5;
  3516. var a01 = - this.direction.dot( segDir );
  3517. var b0 = diff.dot( this.direction );
  3518. var b1 = - diff.dot( segDir );
  3519. var c = diff.lengthSq();
  3520. var det = Math.abs( 1 - a01 * a01 );
  3521. var s0, s1, sqrDist, extDet;
  3522. if ( det > 0 ) {
  3523. // The ray and segment are not parallel.
  3524. s0 = a01 * b1 - b0;
  3525. s1 = a01 * b0 - b1;
  3526. extDet = segExtent * det;
  3527. if ( s0 >= 0 ) {
  3528. if ( s1 >= - extDet ) {
  3529. if ( s1 <= extDet ) {
  3530. // region 0
  3531. // Minimum at interior points of ray and segment.
  3532. var invDet = 1 / det;
  3533. s0 *= invDet;
  3534. s1 *= invDet;
  3535. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  3536. } else {
  3537. // region 1
  3538. s1 = segExtent;
  3539. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3540. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3541. }
  3542. } else {
  3543. // region 5
  3544. s1 = - segExtent;
  3545. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3546. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3547. }
  3548. } else {
  3549. if ( s1 <= - extDet ) {
  3550. // region 4
  3551. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  3552. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3553. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3554. } else if ( s1 <= extDet ) {
  3555. // region 3
  3556. s0 = 0;
  3557. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3558. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  3559. } else {
  3560. // region 2
  3561. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  3562. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3563. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3564. }
  3565. }
  3566. } else {
  3567. // Ray and segment are parallel.
  3568. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  3569. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3570. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3571. }
  3572. if ( optionalPointOnRay ) {
  3573. optionalPointOnRay.copy( this.direction ).multiplyScalar( s0 ).add( this.origin );
  3574. }
  3575. if ( optionalPointOnSegment ) {
  3576. optionalPointOnSegment.copy( segDir ).multiplyScalar( s1 ).add( segCenter );
  3577. }
  3578. return sqrDist;
  3579. };
  3580. }(),
  3581. intersectSphere: function () {
  3582. var v1 = new THREE.Vector3();
  3583. return function intersectSphere( sphere, optionalTarget ) {
  3584. v1.subVectors( sphere.center, this.origin );
  3585. var tca = v1.dot( this.direction );
  3586. var d2 = v1.dot( v1 ) - tca * tca;
  3587. var radius2 = sphere.radius * sphere.radius;
  3588. if ( d2 > radius2 ) return null;
  3589. var thc = Math.sqrt( radius2 - d2 );
  3590. // t0 = first intersect point - entrance on front of sphere
  3591. var t0 = tca - thc;
  3592. // t1 = second intersect point - exit point on back of sphere
  3593. var t1 = tca + thc;
  3594. // test to see if both t0 and t1 are behind the ray - if so, return null
  3595. if ( t0 < 0 && t1 < 0 ) return null;
  3596. // test to see if t0 is behind the ray:
  3597. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  3598. // in order to always return an intersect point that is in front of the ray.
  3599. if ( t0 < 0 ) return this.at( t1, optionalTarget );
  3600. // else t0 is in front of the ray, so return the first collision point scaled by t0
  3601. return this.at( t0, optionalTarget );
  3602. };
  3603. }(),
  3604. intersectsSphere: function ( sphere ) {
  3605. return this.distanceToPoint( sphere.center ) <= sphere.radius;
  3606. },
  3607. distanceToPlane: function ( plane ) {
  3608. var denominator = plane.normal.dot( this.direction );
  3609. if ( denominator === 0 ) {
  3610. // line is coplanar, return origin
  3611. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  3612. return 0;
  3613. }
  3614. // Null is preferable to undefined since undefined means.... it is undefined
  3615. return null;
  3616. }
  3617. var t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  3618. // Return if the ray never intersects the plane
  3619. return t >= 0 ? t : null;
  3620. },
  3621. intersectPlane: function ( plane, optionalTarget ) {
  3622. var t = this.distanceToPlane( plane );
  3623. if ( t === null ) {
  3624. return null;
  3625. }
  3626. return this.at( t, optionalTarget );
  3627. },
  3628. intersectsPlane: function ( plane ) {
  3629. // check if the ray lies on the plane first
  3630. var distToPoint = plane.distanceToPoint( this.origin );
  3631. if ( distToPoint === 0 ) {
  3632. return true;
  3633. }
  3634. var denominator = plane.normal.dot( this.direction );
  3635. if ( denominator * distToPoint < 0 ) {
  3636. return true;
  3637. }
  3638. // ray origin is behind the plane (and is pointing behind it)
  3639. return false;
  3640. },
  3641. intersectBox: function ( box, optionalTarget ) {
  3642. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  3643. var invdirx = 1 / this.direction.x,
  3644. invdiry = 1 / this.direction.y,
  3645. invdirz = 1 / this.direction.z;
  3646. var origin = this.origin;
  3647. if ( invdirx >= 0 ) {
  3648. tmin = ( box.min.x - origin.x ) * invdirx;
  3649. tmax = ( box.max.x - origin.x ) * invdirx;
  3650. } else {
  3651. tmin = ( box.max.x - origin.x ) * invdirx;
  3652. tmax = ( box.min.x - origin.x ) * invdirx;
  3653. }
  3654. if ( invdiry >= 0 ) {
  3655. tymin = ( box.min.y - origin.y ) * invdiry;
  3656. tymax = ( box.max.y - origin.y ) * invdiry;
  3657. } else {
  3658. tymin = ( box.max.y - origin.y ) * invdiry;
  3659. tymax = ( box.min.y - origin.y ) * invdiry;
  3660. }
  3661. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  3662. // These lines also handle the case where tmin or tmax is NaN
  3663. // (result of 0 * Infinity). x !== x returns true if x is NaN
  3664. if ( tymin > tmin || tmin !== tmin ) tmin = tymin;
  3665. if ( tymax < tmax || tmax !== tmax ) tmax = tymax;
  3666. if ( invdirz >= 0 ) {
  3667. tzmin = ( box.min.z - origin.z ) * invdirz;
  3668. tzmax = ( box.max.z - origin.z ) * invdirz;
  3669. } else {
  3670. tzmin = ( box.max.z - origin.z ) * invdirz;
  3671. tzmax = ( box.min.z - origin.z ) * invdirz;
  3672. }
  3673. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  3674. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  3675. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  3676. //return point closest to the ray (positive side)
  3677. if ( tmax < 0 ) return null;
  3678. return this.at( tmin >= 0 ? tmin : tmax, optionalTarget );
  3679. },
  3680. intersectsBox: ( function () {
  3681. var v = new THREE.Vector3();
  3682. return function intersectsBox( box ) {
  3683. return this.intersectBox( box, v ) !== null;
  3684. };
  3685. } )(),
  3686. intersectTriangle: function () {
  3687. // Compute the offset origin, edges, and normal.
  3688. var diff = new THREE.Vector3();
  3689. var edge1 = new THREE.Vector3();
  3690. var edge2 = new THREE.Vector3();
  3691. var normal = new THREE.Vector3();
  3692. return function intersectTriangle( a, b, c, backfaceCulling, optionalTarget ) {
  3693. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  3694. edge1.subVectors( b, a );
  3695. edge2.subVectors( c, a );
  3696. normal.crossVectors( edge1, edge2 );
  3697. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  3698. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  3699. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  3700. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  3701. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  3702. var DdN = this.direction.dot( normal );
  3703. var sign;
  3704. if ( DdN > 0 ) {
  3705. if ( backfaceCulling ) return null;
  3706. sign = 1;
  3707. } else if ( DdN < 0 ) {
  3708. sign = - 1;
  3709. DdN = - DdN;
  3710. } else {
  3711. return null;
  3712. }
  3713. diff.subVectors( this.origin, a );
  3714. var DdQxE2 = sign * this.direction.dot( edge2.crossVectors( diff, edge2 ) );
  3715. // b1 < 0, no intersection
  3716. if ( DdQxE2 < 0 ) {
  3717. return null;
  3718. }
  3719. var DdE1xQ = sign * this.direction.dot( edge1.cross( diff ) );
  3720. // b2 < 0, no intersection
  3721. if ( DdE1xQ < 0 ) {
  3722. return null;
  3723. }
  3724. // b1+b2 > 1, no intersection
  3725. if ( DdQxE2 + DdE1xQ > DdN ) {
  3726. return null;
  3727. }
  3728. // Line intersects triangle, check if ray does.
  3729. var QdN = - sign * diff.dot( normal );
  3730. // t < 0, no intersection
  3731. if ( QdN < 0 ) {
  3732. return null;
  3733. }
  3734. // Ray intersects triangle.
  3735. return this.at( QdN / DdN, optionalTarget );
  3736. };
  3737. }(),
  3738. applyMatrix4: function ( matrix4 ) {
  3739. this.direction.add( this.origin ).applyMatrix4( matrix4 );
  3740. this.origin.applyMatrix4( matrix4 );
  3741. this.direction.sub( this.origin );
  3742. this.direction.normalize();
  3743. return this;
  3744. },
  3745. equals: function ( ray ) {
  3746. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  3747. }
  3748. };
  3749. // File:src/math/Sphere.js
  3750. /**
  3751. * @author bhouston / http://clara.io
  3752. * @author mrdoob / http://mrdoob.com/
  3753. */
  3754. THREE.Sphere = function ( center, radius ) {
  3755. this.center = ( center !== undefined ) ? center : new THREE.Vector3();
  3756. this.radius = ( radius !== undefined ) ? radius : 0;
  3757. };
  3758. THREE.Sphere.prototype = {
  3759. constructor: THREE.Sphere,
  3760. set: function ( center, radius ) {
  3761. this.center.copy( center );
  3762. this.radius = radius;
  3763. return this;
  3764. },
  3765. setFromPoints: function () {
  3766. var box = new THREE.Box3();
  3767. return function setFromPoints( points, optionalCenter ) {
  3768. var center = this.center;
  3769. if ( optionalCenter !== undefined ) {
  3770. center.copy( optionalCenter );
  3771. } else {
  3772. box.setFromPoints( points ).center( center );
  3773. }
  3774. var maxRadiusSq = 0;
  3775. for ( var i = 0, il = points.length; i < il; i ++ ) {
  3776. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  3777. }
  3778. this.radius = Math.sqrt( maxRadiusSq );
  3779. return this;
  3780. };
  3781. }(),
  3782. clone: function () {
  3783. return new this.constructor().copy( this );
  3784. },
  3785. copy: function ( sphere ) {
  3786. this.center.copy( sphere.center );
  3787. this.radius = sphere.radius;
  3788. return this;
  3789. },
  3790. empty: function () {
  3791. return ( this.radius <= 0 );
  3792. },
  3793. containsPoint: function ( point ) {
  3794. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  3795. },
  3796. distanceToPoint: function ( point ) {
  3797. return ( point.distanceTo( this.center ) - this.radius );
  3798. },
  3799. intersectsSphere: function ( sphere ) {
  3800. var radiusSum = this.radius + sphere.radius;
  3801. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  3802. },
  3803. intersectsBox: function ( box ) {
  3804. return box.intersectsSphere( this );
  3805. },
  3806. intersectsPlane: function ( plane ) {
  3807. // We use the following equation to compute the signed distance from
  3808. // the center of the sphere to the plane.
  3809. //
  3810. // distance = q * n - d
  3811. //
  3812. // If this distance is greater than the radius of the sphere,
  3813. // then there is no intersection.
  3814. return Math.abs( this.center.dot( plane.normal ) - plane.constant ) <= this.radius;
  3815. },
  3816. clampPoint: function ( point, optionalTarget ) {
  3817. var deltaLengthSq = this.center.distanceToSquared( point );
  3818. var result = optionalTarget || new THREE.Vector3();
  3819. result.copy( point );
  3820. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  3821. result.sub( this.center ).normalize();
  3822. result.multiplyScalar( this.radius ).add( this.center );
  3823. }
  3824. return result;
  3825. },
  3826. getBoundingBox: function ( optionalTarget ) {
  3827. var box = optionalTarget || new THREE.Box3();
  3828. box.set( this.center, this.center );
  3829. box.expandByScalar( this.radius );
  3830. return box;
  3831. },
  3832. applyMatrix4: function ( matrix ) {
  3833. this.center.applyMatrix4( matrix );
  3834. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  3835. return this;
  3836. },
  3837. translate: function ( offset ) {
  3838. this.center.add( offset );
  3839. return this;
  3840. },
  3841. equals: function ( sphere ) {
  3842. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  3843. }
  3844. };
  3845. // File:src/math/Frustum.js
  3846. /**
  3847. * @author mrdoob / http://mrdoob.com/
  3848. * @author alteredq / http://alteredqualia.com/
  3849. * @author bhouston / http://clara.io
  3850. */
  3851. THREE.Frustum = function ( p0, p1, p2, p3, p4, p5 ) {
  3852. this.planes = [
  3853. ( p0 !== undefined ) ? p0 : new THREE.Plane(),
  3854. ( p1 !== undefined ) ? p1 : new THREE.Plane(),
  3855. ( p2 !== undefined ) ? p2 : new THREE.Plane(),
  3856. ( p3 !== undefined ) ? p3 : new THREE.Plane(),
  3857. ( p4 !== undefined ) ? p4 : new THREE.Plane(),
  3858. ( p5 !== undefined ) ? p5 : new THREE.Plane()
  3859. ];
  3860. };
  3861. THREE.Frustum.prototype = {
  3862. constructor: THREE.Frustum,
  3863. set: function ( p0, p1, p2, p3, p4, p5 ) {
  3864. var planes = this.planes;
  3865. planes[ 0 ].copy( p0 );
  3866. planes[ 1 ].copy( p1 );
  3867. planes[ 2 ].copy( p2 );
  3868. planes[ 3 ].copy( p3 );
  3869. planes[ 4 ].copy( p4 );
  3870. planes[ 5 ].copy( p5 );
  3871. return this;
  3872. },
  3873. clone: function () {
  3874. return new this.constructor().copy( this );
  3875. },
  3876. copy: function ( frustum ) {
  3877. var planes = this.planes;
  3878. for ( var i = 0; i < 6; i ++ ) {
  3879. planes[ i ].copy( frustum.planes[ i ] );
  3880. }
  3881. return this;
  3882. },
  3883. setFromMatrix: function ( m ) {
  3884. var planes = this.planes;
  3885. var me = m.elements;
  3886. var me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  3887. var me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  3888. var me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  3889. var me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  3890. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  3891. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  3892. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  3893. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  3894. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  3895. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  3896. return this;
  3897. },
  3898. intersectsObject: function () {
  3899. var sphere = new THREE.Sphere();
  3900. return function intersectsObject( object ) {
  3901. var geometry = object.geometry;
  3902. if ( geometry.boundingSphere === null )
  3903. geometry.computeBoundingSphere();
  3904. sphere.copy( geometry.boundingSphere )
  3905. .applyMatrix4( object.matrixWorld );
  3906. return this.intersectsSphere( sphere );
  3907. };
  3908. }(),
  3909. intersectsSprite: function () {
  3910. var sphere = new THREE.Sphere();
  3911. return function intersectsSprite( sprite ) {
  3912. sphere.center.set( 0, 0, 0 );
  3913. sphere.radius = 0.7071067811865476;
  3914. sphere.applyMatrix4( sprite.matrixWorld );
  3915. return this.intersectsSphere( sphere );
  3916. };
  3917. }(),
  3918. intersectsSphere: function ( sphere ) {
  3919. var planes = this.planes;
  3920. var center = sphere.center;
  3921. var negRadius = - sphere.radius;
  3922. for ( var i = 0; i < 6; i ++ ) {
  3923. var distance = planes[ i ].distanceToPoint( center );
  3924. if ( distance < negRadius ) {
  3925. return false;
  3926. }
  3927. }
  3928. return true;
  3929. },
  3930. intersectsBox: function () {
  3931. var p1 = new THREE.Vector3(),
  3932. p2 = new THREE.Vector3();
  3933. return function intersectsBox( box ) {
  3934. var planes = this.planes;
  3935. for ( var i = 0; i < 6 ; i ++ ) {
  3936. var plane = planes[ i ];
  3937. p1.x = plane.normal.x > 0 ? box.min.x : box.max.x;
  3938. p2.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  3939. p1.y = plane.normal.y > 0 ? box.min.y : box.max.y;
  3940. p2.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  3941. p1.z = plane.normal.z > 0 ? box.min.z : box.max.z;
  3942. p2.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  3943. var d1 = plane.distanceToPoint( p1 );
  3944. var d2 = plane.distanceToPoint( p2 );
  3945. // if both outside plane, no intersection
  3946. if ( d1 < 0 && d2 < 0 ) {
  3947. return false;
  3948. }
  3949. }
  3950. return true;
  3951. };
  3952. }(),
  3953. containsPoint: function ( point ) {
  3954. var planes = this.planes;
  3955. for ( var i = 0; i < 6; i ++ ) {
  3956. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  3957. return false;
  3958. }
  3959. }
  3960. return true;
  3961. }
  3962. };
  3963. // File:src/math/Plane.js
  3964. /**
  3965. * @author bhouston / http://clara.io
  3966. */
  3967. THREE.Plane = function ( normal, constant ) {
  3968. this.normal = ( normal !== undefined ) ? normal : new THREE.Vector3( 1, 0, 0 );
  3969. this.constant = ( constant !== undefined ) ? constant : 0;
  3970. };
  3971. THREE.Plane.prototype = {
  3972. constructor: THREE.Plane,
  3973. set: function ( normal, constant ) {
  3974. this.normal.copy( normal );
  3975. this.constant = constant;
  3976. return this;
  3977. },
  3978. setComponents: function ( x, y, z, w ) {
  3979. this.normal.set( x, y, z );
  3980. this.constant = w;
  3981. return this;
  3982. },
  3983. setFromNormalAndCoplanarPoint: function ( normal, point ) {
  3984. this.normal.copy( normal );
  3985. this.constant = - point.dot( this.normal ); // must be this.normal, not normal, as this.normal is normalized
  3986. return this;
  3987. },
  3988. setFromCoplanarPoints: function () {
  3989. var v1 = new THREE.Vector3();
  3990. var v2 = new THREE.Vector3();
  3991. return function setFromCoplanarPoints( a, b, c ) {
  3992. var normal = v1.subVectors( c, b ).cross( v2.subVectors( a, b ) ).normalize();
  3993. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  3994. this.setFromNormalAndCoplanarPoint( normal, a );
  3995. return this;
  3996. };
  3997. }(),
  3998. clone: function () {
  3999. return new this.constructor().copy( this );
  4000. },
  4001. copy: function ( plane ) {
  4002. this.normal.copy( plane.normal );
  4003. this.constant = plane.constant;
  4004. return this;
  4005. },
  4006. normalize: function () {
  4007. // Note: will lead to a divide by zero if the plane is invalid.
  4008. var inverseNormalLength = 1.0 / this.normal.length();
  4009. this.normal.multiplyScalar( inverseNormalLength );
  4010. this.constant *= inverseNormalLength;
  4011. return this;
  4012. },
  4013. negate: function () {
  4014. this.constant *= - 1;
  4015. this.normal.negate();
  4016. return this;
  4017. },
  4018. distanceToPoint: function ( point ) {
  4019. return this.normal.dot( point ) + this.constant;
  4020. },
  4021. distanceToSphere: function ( sphere ) {
  4022. return this.distanceToPoint( sphere.center ) - sphere.radius;
  4023. },
  4024. projectPoint: function ( point, optionalTarget ) {
  4025. return this.orthoPoint( point, optionalTarget ).sub( point ).negate();
  4026. },
  4027. orthoPoint: function ( point, optionalTarget ) {
  4028. var perpendicularMagnitude = this.distanceToPoint( point );
  4029. var result = optionalTarget || new THREE.Vector3();
  4030. return result.copy( this.normal ).multiplyScalar( perpendicularMagnitude );
  4031. },
  4032. intersectLine: function () {
  4033. var v1 = new THREE.Vector3();
  4034. return function intersectLine( line, optionalTarget ) {
  4035. var result = optionalTarget || new THREE.Vector3();
  4036. var direction = line.delta( v1 );
  4037. var denominator = this.normal.dot( direction );
  4038. if ( denominator === 0 ) {
  4039. // line is coplanar, return origin
  4040. if ( this.distanceToPoint( line.start ) === 0 ) {
  4041. return result.copy( line.start );
  4042. }
  4043. // Unsure if this is the correct method to handle this case.
  4044. return undefined;
  4045. }
  4046. var t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  4047. if ( t < 0 || t > 1 ) {
  4048. return undefined;
  4049. }
  4050. return result.copy( direction ).multiplyScalar( t ).add( line.start );
  4051. };
  4052. }(),
  4053. intersectsLine: function ( line ) {
  4054. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  4055. var startSign = this.distanceToPoint( line.start );
  4056. var endSign = this.distanceToPoint( line.end );
  4057. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  4058. },
  4059. intersectsBox: function ( box ) {
  4060. return box.intersectsPlane( this );
  4061. },
  4062. intersectsSphere: function ( sphere ) {
  4063. return sphere.intersectsPlane( this );
  4064. },
  4065. coplanarPoint: function ( optionalTarget ) {
  4066. var result = optionalTarget || new THREE.Vector3();
  4067. return result.copy( this.normal ).multiplyScalar( - this.constant );
  4068. },
  4069. applyMatrix4: function () {
  4070. var v1 = new THREE.Vector3();
  4071. var m1 = new THREE.Matrix3();
  4072. return function applyMatrix4( matrix, optionalNormalMatrix ) {
  4073. var referencePoint = this.coplanarPoint( v1 ).applyMatrix4( matrix );
  4074. // transform normal based on theory here:
  4075. // http://www.songho.ca/opengl/gl_normaltransform.html
  4076. var normalMatrix = optionalNormalMatrix || m1.getNormalMatrix( matrix );
  4077. var normal = this.normal.applyMatrix3( normalMatrix ).normalize();
  4078. // recalculate constant (like in setFromNormalAndCoplanarPoint)
  4079. this.constant = - referencePoint.dot( normal );
  4080. return this;
  4081. };
  4082. }(),
  4083. translate: function ( offset ) {
  4084. this.constant = this.constant - offset.dot( this.normal );
  4085. return this;
  4086. },
  4087. equals: function ( plane ) {
  4088. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  4089. }
  4090. };
  4091. // File:src/math/Spherical.js
  4092. /**
  4093. * @author bhouston / http://clara.io
  4094. * @author WestLangley / http://github.com/WestLangley
  4095. *
  4096. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  4097. *
  4098. * The poles (phi) are at the positive and negative y axis.
  4099. * The equator starts at positive z.
  4100. */
  4101. THREE.Spherical = function ( radius, phi, theta ) {
  4102. this.radius = ( radius !== undefined ) ? radius : 1.0;
  4103. this.phi = ( phi !== undefined ) ? phi : 0; // up / down towards top and bottom pole
  4104. this.theta = ( theta !== undefined ) ? theta : 0; // around the equator of the sphere
  4105. return this;
  4106. };
  4107. THREE.Spherical.prototype = {
  4108. constructor: THREE.Spherical,
  4109. set: function ( radius, phi, theta ) {
  4110. this.radius = radius;
  4111. this.phi = phi;
  4112. this.theta = theta;
  4113. return this;
  4114. },
  4115. clone: function () {
  4116. return new this.constructor().copy( this );
  4117. },
  4118. copy: function ( other ) {
  4119. this.radius.copy( other.radius );
  4120. this.phi.copy( other.phi );
  4121. this.theta.copy( other.theta );
  4122. return this;
  4123. },
  4124. // restrict phi to be betwee EPS and PI-EPS
  4125. makeSafe: function() {
  4126. var EPS = 0.000001;
  4127. this.phi = Math.max( EPS, Math.min( Math.PI - EPS, this.phi ) );
  4128. return this;
  4129. },
  4130. setFromVector3: function( vec3 ) {
  4131. this.radius = vec3.length();
  4132. if ( this.radius === 0 ) {
  4133. this.theta = 0;
  4134. this.phi = 0;
  4135. } else {
  4136. this.theta = Math.atan2( vec3.x, vec3.z ); // equator angle around y-up axis
  4137. this.phi = Math.acos( THREE.Math.clamp( vec3.y / this.radius, - 1, 1 ) ); // polar angle
  4138. }
  4139. return this;
  4140. },
  4141. };
  4142. // File:src/math/Math.js
  4143. /**
  4144. * @author alteredq / http://alteredqualia.com/
  4145. * @author mrdoob / http://mrdoob.com/
  4146. */
  4147. THREE.Math = {
  4148. DEG2RAD: Math.PI / 180,
  4149. RAD2DEG: 180 / Math.PI,
  4150. generateUUID: function () {
  4151. // http://www.broofa.com/Tools/Math.uuid.htm
  4152. var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split( '' );
  4153. var uuid = new Array( 36 );
  4154. var rnd = 0, r;
  4155. return function generateUUID() {
  4156. for ( var i = 0; i < 36; i ++ ) {
  4157. if ( i === 8 || i === 13 || i === 18 || i === 23 ) {
  4158. uuid[ i ] = '-';
  4159. } else if ( i === 14 ) {
  4160. uuid[ i ] = '4';
  4161. } else {
  4162. if ( rnd <= 0x02 ) rnd = 0x2000000 + ( Math.random() * 0x1000000 ) | 0;
  4163. r = rnd & 0xf;
  4164. rnd = rnd >> 4;
  4165. uuid[ i ] = chars[ ( i === 19 ) ? ( r & 0x3 ) | 0x8 : r ];
  4166. }
  4167. }
  4168. return uuid.join( '' );
  4169. };
  4170. }(),
  4171. clamp: function ( value, min, max ) {
  4172. return Math.max( min, Math.min( max, value ) );
  4173. },
  4174. // compute euclidian modulo of m % n
  4175. // https://en.wikipedia.org/wiki/Modulo_operation
  4176. euclideanModulo: function ( n, m ) {
  4177. return ( ( n % m ) + m ) % m;
  4178. },
  4179. // Linear mapping from range <a1, a2> to range <b1, b2>
  4180. mapLinear: function ( x, a1, a2, b1, b2 ) {
  4181. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  4182. },
  4183. // http://en.wikipedia.org/wiki/Smoothstep
  4184. smoothstep: function ( x, min, max ) {
  4185. if ( x <= min ) return 0;
  4186. if ( x >= max ) return 1;
  4187. x = ( x - min ) / ( max - min );
  4188. return x * x * ( 3 - 2 * x );
  4189. },
  4190. smootherstep: function ( x, min, max ) {
  4191. if ( x <= min ) return 0;
  4192. if ( x >= max ) return 1;
  4193. x = ( x - min ) / ( max - min );
  4194. return x * x * x * ( x * ( x * 6 - 15 ) + 10 );
  4195. },
  4196. random16: function () {
  4197. console.warn( 'THREE.Math.random16() has been deprecated. Use Math.random() instead.' );
  4198. return Math.random();
  4199. },
  4200. // Random integer from <low, high> interval
  4201. randInt: function ( low, high ) {
  4202. return low + Math.floor( Math.random() * ( high - low + 1 ) );
  4203. },
  4204. // Random float from <low, high> interval
  4205. randFloat: function ( low, high ) {
  4206. return low + Math.random() * ( high - low );
  4207. },
  4208. // Random float from <-range/2, range/2> interval
  4209. randFloatSpread: function ( range ) {
  4210. return range * ( 0.5 - Math.random() );
  4211. },
  4212. degToRad: function ( degrees ) {
  4213. return degrees * THREE.Math.DEG2RAD;
  4214. },
  4215. radToDeg: function ( radians ) {
  4216. return radians * THREE.Math.RAD2DEG;
  4217. },
  4218. isPowerOfTwo: function ( value ) {
  4219. return ( value & ( value - 1 ) ) === 0 && value !== 0;
  4220. },
  4221. nearestPowerOfTwo: function ( value ) {
  4222. return Math.pow( 2, Math.round( Math.log( value ) / Math.LN2 ) );
  4223. },
  4224. nextPowerOfTwo: function ( value ) {
  4225. value --;
  4226. value |= value >> 1;
  4227. value |= value >> 2;
  4228. value |= value >> 4;
  4229. value |= value >> 8;
  4230. value |= value >> 16;
  4231. value ++;
  4232. return value;
  4233. }
  4234. };
  4235. // File:src/math/Spline.js
  4236. /**
  4237. * Spline from Tween.js, slightly optimized (and trashed)
  4238. * http://sole.github.com/tween.js/examples/05_spline.html
  4239. *
  4240. * @author mrdoob / http://mrdoob.com/
  4241. * @author alteredq / http://alteredqualia.com/
  4242. */
  4243. THREE.Spline = function ( points ) {
  4244. this.points = points;
  4245. var c = [], v3 = { x: 0, y: 0, z: 0 },
  4246. point, intPoint, weight, w2, w3,
  4247. pa, pb, pc, pd;
  4248. this.initFromArray = function ( a ) {
  4249. this.points = [];
  4250. for ( var i = 0; i < a.length; i ++ ) {
  4251. this.points[ i ] = { x: a[ i ][ 0 ], y: a[ i ][ 1 ], z: a[ i ][ 2 ] };
  4252. }
  4253. };
  4254. this.getPoint = function ( k ) {
  4255. point = ( this.points.length - 1 ) * k;
  4256. intPoint = Math.floor( point );
  4257. weight = point - intPoint;
  4258. c[ 0 ] = intPoint === 0 ? intPoint : intPoint - 1;
  4259. c[ 1 ] = intPoint;
  4260. c[ 2 ] = intPoint > this.points.length - 2 ? this.points.length - 1 : intPoint + 1;
  4261. c[ 3 ] = intPoint > this.points.length - 3 ? this.points.length - 1 : intPoint + 2;
  4262. pa = this.points[ c[ 0 ] ];
  4263. pb = this.points[ c[ 1 ] ];
  4264. pc = this.points[ c[ 2 ] ];
  4265. pd = this.points[ c[ 3 ] ];
  4266. w2 = weight * weight;
  4267. w3 = weight * w2;
  4268. v3.x = interpolate( pa.x, pb.x, pc.x, pd.x, weight, w2, w3 );
  4269. v3.y = interpolate( pa.y, pb.y, pc.y, pd.y, weight, w2, w3 );
  4270. v3.z = interpolate( pa.z, pb.z, pc.z, pd.z, weight, w2, w3 );
  4271. return v3;
  4272. };
  4273. this.getControlPointsArray = function () {
  4274. var i, p, l = this.points.length,
  4275. coords = [];
  4276. for ( i = 0; i < l; i ++ ) {
  4277. p = this.points[ i ];
  4278. coords[ i ] = [ p.x, p.y, p.z ];
  4279. }
  4280. return coords;
  4281. };
  4282. // approximate length by summing linear segments
  4283. this.getLength = function ( nSubDivisions ) {
  4284. var i, index, nSamples, position,
  4285. point = 0, intPoint = 0, oldIntPoint = 0,
  4286. oldPosition = new THREE.Vector3(),
  4287. tmpVec = new THREE.Vector3(),
  4288. chunkLengths = [],
  4289. totalLength = 0;
  4290. // first point has 0 length
  4291. chunkLengths[ 0 ] = 0;
  4292. if ( ! nSubDivisions ) nSubDivisions = 100;
  4293. nSamples = this.points.length * nSubDivisions;
  4294. oldPosition.copy( this.points[ 0 ] );
  4295. for ( i = 1; i < nSamples; i ++ ) {
  4296. index = i / nSamples;
  4297. position = this.getPoint( index );
  4298. tmpVec.copy( position );
  4299. totalLength += tmpVec.distanceTo( oldPosition );
  4300. oldPosition.copy( position );
  4301. point = ( this.points.length - 1 ) * index;
  4302. intPoint = Math.floor( point );
  4303. if ( intPoint !== oldIntPoint ) {
  4304. chunkLengths[ intPoint ] = totalLength;
  4305. oldIntPoint = intPoint;
  4306. }
  4307. }
  4308. // last point ends with total length
  4309. chunkLengths[ chunkLengths.length ] = totalLength;
  4310. return { chunks: chunkLengths, total: totalLength };
  4311. };
  4312. this.reparametrizeByArcLength = function ( samplingCoef ) {
  4313. var i, j,
  4314. index, indexCurrent, indexNext,
  4315. realDistance,
  4316. sampling, position,
  4317. newpoints = [],
  4318. tmpVec = new THREE.Vector3(),
  4319. sl = this.getLength();
  4320. newpoints.push( tmpVec.copy( this.points[ 0 ] ).clone() );
  4321. for ( i = 1; i < this.points.length; i ++ ) {
  4322. //tmpVec.copy( this.points[ i - 1 ] );
  4323. //linearDistance = tmpVec.distanceTo( this.points[ i ] );
  4324. realDistance = sl.chunks[ i ] - sl.chunks[ i - 1 ];
  4325. sampling = Math.ceil( samplingCoef * realDistance / sl.total );
  4326. indexCurrent = ( i - 1 ) / ( this.points.length - 1 );
  4327. indexNext = i / ( this.points.length - 1 );
  4328. for ( j = 1; j < sampling - 1; j ++ ) {
  4329. index = indexCurrent + j * ( 1 / sampling ) * ( indexNext - indexCurrent );
  4330. position = this.getPoint( index );
  4331. newpoints.push( tmpVec.copy( position ).clone() );
  4332. }
  4333. newpoints.push( tmpVec.copy( this.points[ i ] ).clone() );
  4334. }
  4335. this.points = newpoints;
  4336. };
  4337. // Catmull-Rom
  4338. function interpolate( p0, p1, p2, p3, t, t2, t3 ) {
  4339. var v0 = ( p2 - p0 ) * 0.5,
  4340. v1 = ( p3 - p1 ) * 0.5;
  4341. return ( 2 * ( p1 - p2 ) + v0 + v1 ) * t3 + ( - 3 * ( p1 - p2 ) - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  4342. }
  4343. };
  4344. // File:src/math/Triangle.js
  4345. /**
  4346. * @author bhouston / http://clara.io
  4347. * @author mrdoob / http://mrdoob.com/
  4348. */
  4349. THREE.Triangle = function ( a, b, c ) {
  4350. this.a = ( a !== undefined ) ? a : new THREE.Vector3();
  4351. this.b = ( b !== undefined ) ? b : new THREE.Vector3();
  4352. this.c = ( c !== undefined ) ? c : new THREE.Vector3();
  4353. };
  4354. THREE.Triangle.normal = function () {
  4355. var v0 = new THREE.Vector3();
  4356. return function normal( a, b, c, optionalTarget ) {
  4357. var result = optionalTarget || new THREE.Vector3();
  4358. result.subVectors( c, b );
  4359. v0.subVectors( a, b );
  4360. result.cross( v0 );
  4361. var resultLengthSq = result.lengthSq();
  4362. if ( resultLengthSq > 0 ) {
  4363. return result.multiplyScalar( 1 / Math.sqrt( resultLengthSq ) );
  4364. }
  4365. return result.set( 0, 0, 0 );
  4366. };
  4367. }();
  4368. // static/instance method to calculate barycentric coordinates
  4369. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  4370. THREE.Triangle.barycoordFromPoint = function () {
  4371. var v0 = new THREE.Vector3();
  4372. var v1 = new THREE.Vector3();
  4373. var v2 = new THREE.Vector3();
  4374. return function barycoordFromPoint( point, a, b, c, optionalTarget ) {
  4375. v0.subVectors( c, a );
  4376. v1.subVectors( b, a );
  4377. v2.subVectors( point, a );
  4378. var dot00 = v0.dot( v0 );
  4379. var dot01 = v0.dot( v1 );
  4380. var dot02 = v0.dot( v2 );
  4381. var dot11 = v1.dot( v1 );
  4382. var dot12 = v1.dot( v2 );
  4383. var denom = ( dot00 * dot11 - dot01 * dot01 );
  4384. var result = optionalTarget || new THREE.Vector3();
  4385. // collinear or singular triangle
  4386. if ( denom === 0 ) {
  4387. // arbitrary location outside of triangle?
  4388. // not sure if this is the best idea, maybe should be returning undefined
  4389. return result.set( - 2, - 1, - 1 );
  4390. }
  4391. var invDenom = 1 / denom;
  4392. var u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  4393. var v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  4394. // barycentric coordinates must always sum to 1
  4395. return result.set( 1 - u - v, v, u );
  4396. };
  4397. }();
  4398. THREE.Triangle.containsPoint = function () {
  4399. var v1 = new THREE.Vector3();
  4400. return function containsPoint( point, a, b, c ) {
  4401. var result = THREE.Triangle.barycoordFromPoint( point, a, b, c, v1 );
  4402. return ( result.x >= 0 ) && ( result.y >= 0 ) && ( ( result.x + result.y ) <= 1 );
  4403. };
  4404. }();
  4405. THREE.Triangle.prototype = {
  4406. constructor: THREE.Triangle,
  4407. set: function ( a, b, c ) {
  4408. this.a.copy( a );
  4409. this.b.copy( b );
  4410. this.c.copy( c );
  4411. return this;
  4412. },
  4413. setFromPointsAndIndices: function ( points, i0, i1, i2 ) {
  4414. this.a.copy( points[ i0 ] );
  4415. this.b.copy( points[ i1 ] );
  4416. this.c.copy( points[ i2 ] );
  4417. return this;
  4418. },
  4419. clone: function () {
  4420. return new this.constructor().copy( this );
  4421. },
  4422. copy: function ( triangle ) {
  4423. this.a.copy( triangle.a );
  4424. this.b.copy( triangle.b );
  4425. this.c.copy( triangle.c );
  4426. return this;
  4427. },
  4428. area: function () {
  4429. var v0 = new THREE.Vector3();
  4430. var v1 = new THREE.Vector3();
  4431. return function area() {
  4432. v0.subVectors( this.c, this.b );
  4433. v1.subVectors( this.a, this.b );
  4434. return v0.cross( v1 ).length() * 0.5;
  4435. };
  4436. }(),
  4437. midpoint: function ( optionalTarget ) {
  4438. var result = optionalTarget || new THREE.Vector3();
  4439. return result.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  4440. },
  4441. normal: function ( optionalTarget ) {
  4442. return THREE.Triangle.normal( this.a, this.b, this.c, optionalTarget );
  4443. },
  4444. plane: function ( optionalTarget ) {
  4445. var result = optionalTarget || new THREE.Plane();
  4446. return result.setFromCoplanarPoints( this.a, this.b, this.c );
  4447. },
  4448. barycoordFromPoint: function ( point, optionalTarget ) {
  4449. return THREE.Triangle.barycoordFromPoint( point, this.a, this.b, this.c, optionalTarget );
  4450. },
  4451. containsPoint: function ( point ) {
  4452. return THREE.Triangle.containsPoint( point, this.a, this.b, this.c );
  4453. },
  4454. closestPointToPoint: function () {
  4455. var plane, edgeList, projectedPoint, closestPoint;
  4456. return function closestPointToPoint( point, optionalTarget ) {
  4457. if ( plane === undefined ) {
  4458. plane = new THREE.Plane();
  4459. edgeList = [ new THREE.Line3(), new THREE.Line3(), new THREE.Line3() ];
  4460. projectedPoint = new THREE.Vector3();
  4461. closestPoint = new THREE.Vector3();
  4462. }
  4463. var result = optionalTarget || new THREE.Vector3();
  4464. var minDistance = Infinity;
  4465. // project the point onto the plane of the triangle
  4466. plane.setFromCoplanarPoints( this.a, this.b, this.c );
  4467. plane.projectPoint( point, projectedPoint );
  4468. // check if the projection lies within the triangle
  4469. if( this.containsPoint( projectedPoint ) === true ) {
  4470. // if so, this is the closest point
  4471. result.copy( projectedPoint );
  4472. } else {
  4473. // if not, the point falls outside the triangle. the result is the closest point to the triangle's edges or vertices
  4474. edgeList[ 0 ].set( this.a, this.b );
  4475. edgeList[ 1 ].set( this.b, this.c );
  4476. edgeList[ 2 ].set( this.c, this.a );
  4477. for( var i = 0; i < edgeList.length; i ++ ) {
  4478. edgeList[ i ].closestPointToPoint( projectedPoint, true, closestPoint );
  4479. var distance = projectedPoint.distanceToSquared( closestPoint );
  4480. if( distance < minDistance ) {
  4481. minDistance = distance;
  4482. result.copy( closestPoint );
  4483. }
  4484. }
  4485. }
  4486. return result;
  4487. };
  4488. }(),
  4489. equals: function ( triangle ) {
  4490. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  4491. }
  4492. };
  4493. // File:src/math/Interpolant.js
  4494. /**
  4495. * Abstract base class of interpolants over parametric samples.
  4496. *
  4497. * The parameter domain is one dimensional, typically the time or a path
  4498. * along a curve defined by the data.
  4499. *
  4500. * The sample values can have any dimensionality and derived classes may
  4501. * apply special interpretations to the data.
  4502. *
  4503. * This class provides the interval seek in a Template Method, deferring
  4504. * the actual interpolation to derived classes.
  4505. *
  4506. * Time complexity is O(1) for linear access crossing at most two points
  4507. * and O(log N) for random access, where N is the number of positions.
  4508. *
  4509. * References:
  4510. *
  4511. * http://www.oodesign.com/template-method-pattern.html
  4512. *
  4513. * @author tschw
  4514. */
  4515. THREE.Interpolant = function(
  4516. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4517. this.parameterPositions = parameterPositions;
  4518. this._cachedIndex = 0;
  4519. this.resultBuffer = resultBuffer !== undefined ?
  4520. resultBuffer : new sampleValues.constructor( sampleSize );
  4521. this.sampleValues = sampleValues;
  4522. this.valueSize = sampleSize;
  4523. };
  4524. THREE.Interpolant.prototype = {
  4525. constructor: THREE.Interpolant,
  4526. evaluate: function( t ) {
  4527. var pp = this.parameterPositions,
  4528. i1 = this._cachedIndex,
  4529. t1 = pp[ i1 ],
  4530. t0 = pp[ i1 - 1 ];
  4531. validate_interval: {
  4532. seek: {
  4533. var right;
  4534. linear_scan: {
  4535. //- See http://jsperf.com/comparison-to-undefined/3
  4536. //- slower code:
  4537. //-
  4538. //- if ( t >= t1 || t1 === undefined ) {
  4539. forward_scan: if ( ! ( t < t1 ) ) {
  4540. for ( var giveUpAt = i1 + 2; ;) {
  4541. if ( t1 === undefined ) {
  4542. if ( t < t0 ) break forward_scan;
  4543. // after end
  4544. i1 = pp.length;
  4545. this._cachedIndex = i1;
  4546. return this.afterEnd_( i1 - 1, t, t0 );
  4547. }
  4548. if ( i1 === giveUpAt ) break; // this loop
  4549. t0 = t1;
  4550. t1 = pp[ ++ i1 ];
  4551. if ( t < t1 ) {
  4552. // we have arrived at the sought interval
  4553. break seek;
  4554. }
  4555. }
  4556. // prepare binary search on the right side of the index
  4557. right = pp.length;
  4558. break linear_scan;
  4559. }
  4560. //- slower code:
  4561. //- if ( t < t0 || t0 === undefined ) {
  4562. if ( ! ( t >= t0 ) ) {
  4563. // looping?
  4564. var t1global = pp[ 1 ];
  4565. if ( t < t1global ) {
  4566. i1 = 2; // + 1, using the scan for the details
  4567. t0 = t1global;
  4568. }
  4569. // linear reverse scan
  4570. for ( var giveUpAt = i1 - 2; ;) {
  4571. if ( t0 === undefined ) {
  4572. // before start
  4573. this._cachedIndex = 0;
  4574. return this.beforeStart_( 0, t, t1 );
  4575. }
  4576. if ( i1 === giveUpAt ) break; // this loop
  4577. t1 = t0;
  4578. t0 = pp[ -- i1 - 1 ];
  4579. if ( t >= t0 ) {
  4580. // we have arrived at the sought interval
  4581. break seek;
  4582. }
  4583. }
  4584. // prepare binary search on the left side of the index
  4585. right = i1;
  4586. i1 = 0;
  4587. break linear_scan;
  4588. }
  4589. // the interval is valid
  4590. break validate_interval;
  4591. } // linear scan
  4592. // binary search
  4593. while ( i1 < right ) {
  4594. var mid = ( i1 + right ) >>> 1;
  4595. if ( t < pp[ mid ] ) {
  4596. right = mid;
  4597. } else {
  4598. i1 = mid + 1;
  4599. }
  4600. }
  4601. t1 = pp[ i1 ];
  4602. t0 = pp[ i1 - 1 ];
  4603. // check boundary cases, again
  4604. if ( t0 === undefined ) {
  4605. this._cachedIndex = 0;
  4606. return this.beforeStart_( 0, t, t1 );
  4607. }
  4608. if ( t1 === undefined ) {
  4609. i1 = pp.length;
  4610. this._cachedIndex = i1;
  4611. return this.afterEnd_( i1 - 1, t0, t );
  4612. }
  4613. } // seek
  4614. this._cachedIndex = i1;
  4615. this.intervalChanged_( i1, t0, t1 );
  4616. } // validate_interval
  4617. return this.interpolate_( i1, t0, t, t1 );
  4618. },
  4619. settings: null, // optional, subclass-specific settings structure
  4620. // Note: The indirection allows central control of many interpolants.
  4621. // --- Protected interface
  4622. DefaultSettings_: {},
  4623. getSettings_: function() {
  4624. return this.settings || this.DefaultSettings_;
  4625. },
  4626. copySampleValue_: function( index ) {
  4627. // copies a sample value to the result buffer
  4628. var result = this.resultBuffer,
  4629. values = this.sampleValues,
  4630. stride = this.valueSize,
  4631. offset = index * stride;
  4632. for ( var i = 0; i !== stride; ++ i ) {
  4633. result[ i ] = values[ offset + i ];
  4634. }
  4635. return result;
  4636. },
  4637. // Template methods for derived classes:
  4638. interpolate_: function( i1, t0, t, t1 ) {
  4639. throw new Error( "call to abstract method" );
  4640. // implementations shall return this.resultBuffer
  4641. },
  4642. intervalChanged_: function( i1, t0, t1 ) {
  4643. // empty
  4644. }
  4645. };
  4646. Object.assign( THREE.Interpolant.prototype, {
  4647. beforeStart_: //( 0, t, t0 ), returns this.resultBuffer
  4648. THREE.Interpolant.prototype.copySampleValue_,
  4649. afterEnd_: //( N-1, tN-1, t ), returns this.resultBuffer
  4650. THREE.Interpolant.prototype.copySampleValue_
  4651. } );
  4652. // File:src/math/interpolants/CubicInterpolant.js
  4653. /**
  4654. * Fast and simple cubic spline interpolant.
  4655. *
  4656. * It was derived from a Hermitian construction setting the first derivative
  4657. * at each sample position to the linear slope between neighboring positions
  4658. * over their parameter interval.
  4659. *
  4660. * @author tschw
  4661. */
  4662. THREE.CubicInterpolant = function(
  4663. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4664. THREE.Interpolant.call(
  4665. this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  4666. this._weightPrev = -0;
  4667. this._offsetPrev = -0;
  4668. this._weightNext = -0;
  4669. this._offsetNext = -0;
  4670. };
  4671. THREE.CubicInterpolant.prototype =
  4672. Object.assign( Object.create( THREE.Interpolant.prototype ), {
  4673. constructor: THREE.CubicInterpolant,
  4674. DefaultSettings_: {
  4675. endingStart: THREE.ZeroCurvatureEnding,
  4676. endingEnd: THREE.ZeroCurvatureEnding
  4677. },
  4678. intervalChanged_: function( i1, t0, t1 ) {
  4679. var pp = this.parameterPositions,
  4680. iPrev = i1 - 2,
  4681. iNext = i1 + 1,
  4682. tPrev = pp[ iPrev ],
  4683. tNext = pp[ iNext ];
  4684. if ( tPrev === undefined ) {
  4685. switch ( this.getSettings_().endingStart ) {
  4686. case THREE.ZeroSlopeEnding:
  4687. // f'(t0) = 0
  4688. iPrev = i1;
  4689. tPrev = 2 * t0 - t1;
  4690. break;
  4691. case THREE.WrapAroundEnding:
  4692. // use the other end of the curve
  4693. iPrev = pp.length - 2;
  4694. tPrev = t0 + pp[ iPrev ] - pp[ iPrev + 1 ];
  4695. break;
  4696. default: // ZeroCurvatureEnding
  4697. // f''(t0) = 0 a.k.a. Natural Spline
  4698. iPrev = i1;
  4699. tPrev = t1;
  4700. }
  4701. }
  4702. if ( tNext === undefined ) {
  4703. switch ( this.getSettings_().endingEnd ) {
  4704. case THREE.ZeroSlopeEnding:
  4705. // f'(tN) = 0
  4706. iNext = i1;
  4707. tNext = 2 * t1 - t0;
  4708. break;
  4709. case THREE.WrapAroundEnding:
  4710. // use the other end of the curve
  4711. iNext = 1;
  4712. tNext = t1 + pp[ 1 ] - pp[ 0 ];
  4713. break;
  4714. default: // ZeroCurvatureEnding
  4715. // f''(tN) = 0, a.k.a. Natural Spline
  4716. iNext = i1 - 1;
  4717. tNext = t0;
  4718. }
  4719. }
  4720. var halfDt = ( t1 - t0 ) * 0.5,
  4721. stride = this.valueSize;
  4722. this._weightPrev = halfDt / ( t0 - tPrev );
  4723. this._weightNext = halfDt / ( tNext - t1 );
  4724. this._offsetPrev = iPrev * stride;
  4725. this._offsetNext = iNext * stride;
  4726. },
  4727. interpolate_: function( i1, t0, t, t1 ) {
  4728. var result = this.resultBuffer,
  4729. values = this.sampleValues,
  4730. stride = this.valueSize,
  4731. o1 = i1 * stride, o0 = o1 - stride,
  4732. oP = this._offsetPrev, oN = this._offsetNext,
  4733. wP = this._weightPrev, wN = this._weightNext,
  4734. p = ( t - t0 ) / ( t1 - t0 ),
  4735. pp = p * p,
  4736. ppp = pp * p;
  4737. // evaluate polynomials
  4738. var sP = - wP * ppp + 2 * wP * pp - wP * p;
  4739. var s0 = ( 1 + wP ) * ppp + (-1.5 - 2 * wP ) * pp + ( -0.5 + wP ) * p + 1;
  4740. var s1 = (-1 - wN ) * ppp + ( 1.5 + wN ) * pp + 0.5 * p;
  4741. var sN = wN * ppp - wN * pp;
  4742. // combine data linearly
  4743. for ( var i = 0; i !== stride; ++ i ) {
  4744. result[ i ] =
  4745. sP * values[ oP + i ] +
  4746. s0 * values[ o0 + i ] +
  4747. s1 * values[ o1 + i ] +
  4748. sN * values[ oN + i ];
  4749. }
  4750. return result;
  4751. }
  4752. } );
  4753. // File:src/math/interpolants/DiscreteInterpolant.js
  4754. /**
  4755. *
  4756. * Interpolant that evaluates to the sample value at the position preceeding
  4757. * the parameter.
  4758. *
  4759. * @author tschw
  4760. */
  4761. THREE.DiscreteInterpolant = function(
  4762. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4763. THREE.Interpolant.call(
  4764. this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  4765. };
  4766. THREE.DiscreteInterpolant.prototype =
  4767. Object.assign( Object.create( THREE.Interpolant.prototype ), {
  4768. constructor: THREE.DiscreteInterpolant,
  4769. interpolate_: function( i1, t0, t, t1 ) {
  4770. return this.copySampleValue_( i1 - 1 );
  4771. }
  4772. } );
  4773. // File:src/math/interpolants/LinearInterpolant.js
  4774. /**
  4775. * @author tschw
  4776. */
  4777. THREE.LinearInterpolant = function(
  4778. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4779. THREE.Interpolant.call(
  4780. this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  4781. };
  4782. THREE.LinearInterpolant.prototype =
  4783. Object.assign( Object.create( THREE.Interpolant.prototype ), {
  4784. constructor: THREE.LinearInterpolant,
  4785. interpolate_: function( i1, t0, t, t1 ) {
  4786. var result = this.resultBuffer,
  4787. values = this.sampleValues,
  4788. stride = this.valueSize,
  4789. offset1 = i1 * stride,
  4790. offset0 = offset1 - stride,
  4791. weight1 = ( t - t0 ) / ( t1 - t0 ),
  4792. weight0 = 1 - weight1;
  4793. for ( var i = 0; i !== stride; ++ i ) {
  4794. result[ i ] =
  4795. values[ offset0 + i ] * weight0 +
  4796. values[ offset1 + i ] * weight1;
  4797. }
  4798. return result;
  4799. }
  4800. } );
  4801. // File:src/math/interpolants/QuaternionLinearInterpolant.js
  4802. /**
  4803. * Spherical linear unit quaternion interpolant.
  4804. *
  4805. * @author tschw
  4806. */
  4807. THREE.QuaternionLinearInterpolant = function(
  4808. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4809. THREE.Interpolant.call(
  4810. this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  4811. };
  4812. THREE.QuaternionLinearInterpolant.prototype =
  4813. Object.assign( Object.create( THREE.Interpolant.prototype ), {
  4814. constructor: THREE.QuaternionLinearInterpolant,
  4815. interpolate_: function( i1, t0, t, t1 ) {
  4816. var result = this.resultBuffer,
  4817. values = this.sampleValues,
  4818. stride = this.valueSize,
  4819. offset = i1 * stride,
  4820. alpha = ( t - t0 ) / ( t1 - t0 );
  4821. for ( var end = offset + stride; offset !== end; offset += 4 ) {
  4822. THREE.Quaternion.slerpFlat( result, 0,
  4823. values, offset - stride, values, offset, alpha );
  4824. }
  4825. return result;
  4826. }
  4827. } );
  4828. // File:src/core/Clock.js
  4829. /**
  4830. * @author alteredq / http://alteredqualia.com/
  4831. */
  4832. THREE.Clock = function ( autoStart ) {
  4833. this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
  4834. this.startTime = 0;
  4835. this.oldTime = 0;
  4836. this.elapsedTime = 0;
  4837. this.running = false;
  4838. };
  4839. THREE.Clock.prototype = {
  4840. constructor: THREE.Clock,
  4841. start: function () {
  4842. this.startTime = ( performance || Date ).now();
  4843. this.oldTime = this.startTime;
  4844. this.running = true;
  4845. },
  4846. stop: function () {
  4847. this.getElapsedTime();
  4848. this.running = false;
  4849. },
  4850. getElapsedTime: function () {
  4851. this.getDelta();
  4852. return this.elapsedTime;
  4853. },
  4854. getDelta: function () {
  4855. var diff = 0;
  4856. if ( this.autoStart && ! this.running ) {
  4857. this.start();
  4858. }
  4859. if ( this.running ) {
  4860. var newTime = ( performance || Date ).now();
  4861. diff = ( newTime - this.oldTime ) / 1000;
  4862. this.oldTime = newTime;
  4863. this.elapsedTime += diff;
  4864. }
  4865. return diff;
  4866. }
  4867. };
  4868. // File:src/core/EventDispatcher.js
  4869. /**
  4870. * https://github.com/mrdoob/eventdispatcher.js/
  4871. */
  4872. THREE.EventDispatcher = function () {};
  4873. Object.assign( THREE.EventDispatcher.prototype, {
  4874. addEventListener: function ( type, listener ) {
  4875. if ( this._listeners === undefined ) this._listeners = {};
  4876. var listeners = this._listeners;
  4877. if ( listeners[ type ] === undefined ) {
  4878. listeners[ type ] = [];
  4879. }
  4880. if ( listeners[ type ].indexOf( listener ) === - 1 ) {
  4881. listeners[ type ].push( listener );
  4882. }
  4883. },
  4884. hasEventListener: function ( type, listener ) {
  4885. if ( this._listeners === undefined ) return false;
  4886. var listeners = this._listeners;
  4887. if ( listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1 ) {
  4888. return true;
  4889. }
  4890. return false;
  4891. },
  4892. removeEventListener: function ( type, listener ) {
  4893. if ( this._listeners === undefined ) return;
  4894. var listeners = this._listeners;
  4895. var listenerArray = listeners[ type ];
  4896. if ( listenerArray !== undefined ) {
  4897. var index = listenerArray.indexOf( listener );
  4898. if ( index !== - 1 ) {
  4899. listenerArray.splice( index, 1 );
  4900. }
  4901. }
  4902. },
  4903. dispatchEvent: function ( event ) {
  4904. if ( this._listeners === undefined ) return;
  4905. var listeners = this._listeners;
  4906. var listenerArray = listeners[ event.type ];
  4907. if ( listenerArray !== undefined ) {
  4908. event.target = this;
  4909. var array = [], i = 0;
  4910. var length = listenerArray.length;
  4911. for ( i = 0; i < length; i ++ ) {
  4912. array[ i ] = listenerArray[ i ];
  4913. }
  4914. for ( i = 0; i < length; i ++ ) {
  4915. array[ i ].call( this, event );
  4916. }
  4917. }
  4918. }
  4919. } );
  4920. // File:src/core/Layers.js
  4921. /**
  4922. * @author mrdoob / http://mrdoob.com/
  4923. */
  4924. THREE.Layers = function () {
  4925. this.mask = 1;
  4926. };
  4927. THREE.Layers.prototype = {
  4928. constructor: THREE.Layers,
  4929. set: function ( channel ) {
  4930. this.mask = 1 << channel;
  4931. },
  4932. enable: function ( channel ) {
  4933. this.mask |= 1 << channel;
  4934. },
  4935. toggle: function ( channel ) {
  4936. this.mask ^= 1 << channel;
  4937. },
  4938. disable: function ( channel ) {
  4939. this.mask &= ~ ( 1 << channel );
  4940. },
  4941. test: function ( layers ) {
  4942. return ( this.mask & layers.mask ) !== 0;
  4943. }
  4944. };
  4945. // File:src/core/Raycaster.js
  4946. /**
  4947. * @author mrdoob / http://mrdoob.com/
  4948. * @author bhouston / http://clara.io/
  4949. * @author stephomi / http://stephaneginier.com/
  4950. */
  4951. ( function ( THREE ) {
  4952. THREE.Raycaster = function ( origin, direction, near, far ) {
  4953. this.ray = new THREE.Ray( origin, direction );
  4954. // direction is assumed to be normalized (for accurate distance calculations)
  4955. this.near = near || 0;
  4956. this.far = far || Infinity;
  4957. this.params = {
  4958. Mesh: {},
  4959. Line: {},
  4960. LOD: {},
  4961. Points: { threshold: 1 },
  4962. Sprite: {}
  4963. };
  4964. Object.defineProperties( this.params, {
  4965. PointCloud: {
  4966. get: function () {
  4967. console.warn( 'THREE.Raycaster: params.PointCloud has been renamed to params.Points.' );
  4968. return this.Points;
  4969. }
  4970. }
  4971. } );
  4972. };
  4973. function ascSort( a, b ) {
  4974. return a.distance - b.distance;
  4975. }
  4976. function intersectObject( object, raycaster, intersects, recursive ) {
  4977. if ( object.visible === false ) return;
  4978. object.raycast( raycaster, intersects );
  4979. if ( recursive === true ) {
  4980. var children = object.children;
  4981. for ( var i = 0, l = children.length; i < l; i ++ ) {
  4982. intersectObject( children[ i ], raycaster, intersects, true );
  4983. }
  4984. }
  4985. }
  4986. //
  4987. THREE.Raycaster.prototype = {
  4988. constructor: THREE.Raycaster,
  4989. linePrecision: 1,
  4990. set: function ( origin, direction ) {
  4991. // direction is assumed to be normalized (for accurate distance calculations)
  4992. this.ray.set( origin, direction );
  4993. },
  4994. setFromCamera: function ( coords, camera ) {
  4995. if ( camera instanceof THREE.PerspectiveCamera ) {
  4996. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  4997. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  4998. } else if ( camera instanceof THREE.OrthographicCamera ) {
  4999. this.ray.origin.set( coords.x, coords.y, ( camera.near + camera.far ) / ( camera.near - camera.far ) ).unproject( camera ); // set origin in plane of camera
  5000. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  5001. } else {
  5002. console.error( 'THREE.Raycaster: Unsupported camera type.' );
  5003. }
  5004. },
  5005. intersectObject: function ( object, recursive ) {
  5006. var intersects = [];
  5007. intersectObject( object, this, intersects, recursive );
  5008. intersects.sort( ascSort );
  5009. return intersects;
  5010. },
  5011. intersectObjects: function ( objects, recursive ) {
  5012. var intersects = [];
  5013. if ( Array.isArray( objects ) === false ) {
  5014. console.warn( 'THREE.Raycaster.intersectObjects: objects is not an Array.' );
  5015. return intersects;
  5016. }
  5017. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  5018. intersectObject( objects[ i ], this, intersects, recursive );
  5019. }
  5020. intersects.sort( ascSort );
  5021. return intersects;
  5022. }
  5023. };
  5024. }( THREE ) );
  5025. // File:src/core/Object3D.js
  5026. /**
  5027. * @author mrdoob / http://mrdoob.com/
  5028. * @author mikael emtinger / http://gomo.se/
  5029. * @author alteredq / http://alteredqualia.com/
  5030. * @author WestLangley / http://github.com/WestLangley
  5031. * @author elephantatwork / www.elephantatwork.ch
  5032. */
  5033. THREE.Object3D = function () {
  5034. Object.defineProperty( this, 'id', { value: THREE.Object3DIdCount ++ } );
  5035. this.uuid = THREE.Math.generateUUID();
  5036. this.name = '';
  5037. this.type = 'Object3D';
  5038. this.parent = null;
  5039. this.children = [];
  5040. this.up = THREE.Object3D.DefaultUp.clone();
  5041. var position = new THREE.Vector3();
  5042. var rotation = new THREE.Euler();
  5043. var quaternion = new THREE.Quaternion();
  5044. var scale = new THREE.Vector3( 1, 1, 1 );
  5045. function onRotationChange() {
  5046. quaternion.setFromEuler( rotation, false );
  5047. }
  5048. function onQuaternionChange() {
  5049. rotation.setFromQuaternion( quaternion, undefined, false );
  5050. }
  5051. rotation.onChange( onRotationChange );
  5052. quaternion.onChange( onQuaternionChange );
  5053. Object.defineProperties( this, {
  5054. position: {
  5055. enumerable: true,
  5056. value: position
  5057. },
  5058. rotation: {
  5059. enumerable: true,
  5060. value: rotation
  5061. },
  5062. quaternion: {
  5063. enumerable: true,
  5064. value: quaternion
  5065. },
  5066. scale: {
  5067. enumerable: true,
  5068. value: scale
  5069. },
  5070. modelViewMatrix: {
  5071. value: new THREE.Matrix4()
  5072. },
  5073. normalMatrix: {
  5074. value: new THREE.Matrix3()
  5075. }
  5076. } );
  5077. this.matrix = new THREE.Matrix4();
  5078. this.matrixWorld = new THREE.Matrix4();
  5079. this.matrixAutoUpdate = THREE.Object3D.DefaultMatrixAutoUpdate;
  5080. this.matrixWorldNeedsUpdate = false;
  5081. this.layers = new THREE.Layers();
  5082. this.visible = true;
  5083. this.castShadow = false;
  5084. this.receiveShadow = false;
  5085. this.frustumCulled = true;
  5086. this.renderOrder = 0;
  5087. this.userData = {};
  5088. };
  5089. THREE.Object3D.DefaultUp = new THREE.Vector3( 0, 1, 0 );
  5090. THREE.Object3D.DefaultMatrixAutoUpdate = true;
  5091. Object.assign( THREE.Object3D.prototype, THREE.EventDispatcher.prototype, {
  5092. applyMatrix: function ( matrix ) {
  5093. this.matrix.multiplyMatrices( matrix, this.matrix );
  5094. this.matrix.decompose( this.position, this.quaternion, this.scale );
  5095. },
  5096. setRotationFromAxisAngle: function ( axis, angle ) {
  5097. // assumes axis is normalized
  5098. this.quaternion.setFromAxisAngle( axis, angle );
  5099. },
  5100. setRotationFromEuler: function ( euler ) {
  5101. this.quaternion.setFromEuler( euler, true );
  5102. },
  5103. setRotationFromMatrix: function ( m ) {
  5104. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  5105. this.quaternion.setFromRotationMatrix( m );
  5106. },
  5107. setRotationFromQuaternion: function ( q ) {
  5108. // assumes q is normalized
  5109. this.quaternion.copy( q );
  5110. },
  5111. rotateOnAxis: function () {
  5112. // rotate object on axis in object space
  5113. // axis is assumed to be normalized
  5114. var q1 = new THREE.Quaternion();
  5115. return function rotateOnAxis( axis, angle ) {
  5116. q1.setFromAxisAngle( axis, angle );
  5117. this.quaternion.multiply( q1 );
  5118. return this;
  5119. };
  5120. }(),
  5121. rotateX: function () {
  5122. var v1 = new THREE.Vector3( 1, 0, 0 );
  5123. return function rotateX( angle ) {
  5124. return this.rotateOnAxis( v1, angle );
  5125. };
  5126. }(),
  5127. rotateY: function () {
  5128. var v1 = new THREE.Vector3( 0, 1, 0 );
  5129. return function rotateY( angle ) {
  5130. return this.rotateOnAxis( v1, angle );
  5131. };
  5132. }(),
  5133. rotateZ: function () {
  5134. var v1 = new THREE.Vector3( 0, 0, 1 );
  5135. return function rotateZ( angle ) {
  5136. return this.rotateOnAxis( v1, angle );
  5137. };
  5138. }(),
  5139. translateOnAxis: function () {
  5140. // translate object by distance along axis in object space
  5141. // axis is assumed to be normalized
  5142. var v1 = new THREE.Vector3();
  5143. return function translateOnAxis( axis, distance ) {
  5144. v1.copy( axis ).applyQuaternion( this.quaternion );
  5145. this.position.add( v1.multiplyScalar( distance ) );
  5146. return this;
  5147. };
  5148. }(),
  5149. translateX: function () {
  5150. var v1 = new THREE.Vector3( 1, 0, 0 );
  5151. return function translateX( distance ) {
  5152. return this.translateOnAxis( v1, distance );
  5153. };
  5154. }(),
  5155. translateY: function () {
  5156. var v1 = new THREE.Vector3( 0, 1, 0 );
  5157. return function translateY( distance ) {
  5158. return this.translateOnAxis( v1, distance );
  5159. };
  5160. }(),
  5161. translateZ: function () {
  5162. var v1 = new THREE.Vector3( 0, 0, 1 );
  5163. return function translateZ( distance ) {
  5164. return this.translateOnAxis( v1, distance );
  5165. };
  5166. }(),
  5167. localToWorld: function ( vector ) {
  5168. return vector.applyMatrix4( this.matrixWorld );
  5169. },
  5170. worldToLocal: function () {
  5171. var m1 = new THREE.Matrix4();
  5172. return function worldToLocal( vector ) {
  5173. return vector.applyMatrix4( m1.getInverse( this.matrixWorld ) );
  5174. };
  5175. }(),
  5176. lookAt: function () {
  5177. // This routine does not support objects with rotated and/or translated parent(s)
  5178. var m1 = new THREE.Matrix4();
  5179. return function lookAt( vector ) {
  5180. m1.lookAt( vector, this.position, this.up );
  5181. this.quaternion.setFromRotationMatrix( m1 );
  5182. };
  5183. }(),
  5184. add: function ( object ) {
  5185. if ( arguments.length > 1 ) {
  5186. for ( var i = 0; i < arguments.length; i ++ ) {
  5187. this.add( arguments[ i ] );
  5188. }
  5189. return this;
  5190. }
  5191. if ( object === this ) {
  5192. console.error( "THREE.Object3D.add: object can't be added as a child of itself.", object );
  5193. return this;
  5194. }
  5195. if ( object instanceof THREE.Object3D ) {
  5196. if ( object.parent !== null ) {
  5197. object.parent.remove( object );
  5198. }
  5199. object.parent = this;
  5200. object.dispatchEvent( { type: 'added' } );
  5201. this.children.push( object );
  5202. } else {
  5203. console.error( "THREE.Object3D.add: object not an instance of THREE.Object3D.", object );
  5204. }
  5205. return this;
  5206. },
  5207. remove: function ( object ) {
  5208. if ( arguments.length > 1 ) {
  5209. for ( var i = 0; i < arguments.length; i ++ ) {
  5210. this.remove( arguments[ i ] );
  5211. }
  5212. }
  5213. var index = this.children.indexOf( object );
  5214. if ( index !== - 1 ) {
  5215. object.parent = null;
  5216. object.dispatchEvent( { type: 'removed' } );
  5217. this.children.splice( index, 1 );
  5218. }
  5219. },
  5220. getObjectById: function ( id ) {
  5221. return this.getObjectByProperty( 'id', id );
  5222. },
  5223. getObjectByName: function ( name ) {
  5224. return this.getObjectByProperty( 'name', name );
  5225. },
  5226. getObjectByProperty: function ( name, value ) {
  5227. if ( this[ name ] === value ) return this;
  5228. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  5229. var child = this.children[ i ];
  5230. var object = child.getObjectByProperty( name, value );
  5231. if ( object !== undefined ) {
  5232. return object;
  5233. }
  5234. }
  5235. return undefined;
  5236. },
  5237. getWorldPosition: function ( optionalTarget ) {
  5238. var result = optionalTarget || new THREE.Vector3();
  5239. this.updateMatrixWorld( true );
  5240. return result.setFromMatrixPosition( this.matrixWorld );
  5241. },
  5242. getWorldQuaternion: function () {
  5243. var position = new THREE.Vector3();
  5244. var scale = new THREE.Vector3();
  5245. return function getWorldQuaternion( optionalTarget ) {
  5246. var result = optionalTarget || new THREE.Quaternion();
  5247. this.updateMatrixWorld( true );
  5248. this.matrixWorld.decompose( position, result, scale );
  5249. return result;
  5250. };
  5251. }(),
  5252. getWorldRotation: function () {
  5253. var quaternion = new THREE.Quaternion();
  5254. return function getWorldRotation( optionalTarget ) {
  5255. var result = optionalTarget || new THREE.Euler();
  5256. this.getWorldQuaternion( quaternion );
  5257. return result.setFromQuaternion( quaternion, this.rotation.order, false );
  5258. };
  5259. }(),
  5260. getWorldScale: function () {
  5261. var position = new THREE.Vector3();
  5262. var quaternion = new THREE.Quaternion();
  5263. return function getWorldScale( optionalTarget ) {
  5264. var result = optionalTarget || new THREE.Vector3();
  5265. this.updateMatrixWorld( true );
  5266. this.matrixWorld.decompose( position, quaternion, result );
  5267. return result;
  5268. };
  5269. }(),
  5270. getWorldDirection: function () {
  5271. var quaternion = new THREE.Quaternion();
  5272. return function getWorldDirection( optionalTarget ) {
  5273. var result = optionalTarget || new THREE.Vector3();
  5274. this.getWorldQuaternion( quaternion );
  5275. return result.set( 0, 0, 1 ).applyQuaternion( quaternion );
  5276. };
  5277. }(),
  5278. raycast: function () {},
  5279. traverse: function ( callback ) {
  5280. callback( this );
  5281. var children = this.children;
  5282. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5283. children[ i ].traverse( callback );
  5284. }
  5285. },
  5286. traverseVisible: function ( callback ) {
  5287. if ( this.visible === false ) return;
  5288. callback( this );
  5289. var children = this.children;
  5290. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5291. children[ i ].traverseVisible( callback );
  5292. }
  5293. },
  5294. traverseAncestors: function ( callback ) {
  5295. var parent = this.parent;
  5296. if ( parent !== null ) {
  5297. callback( parent );
  5298. parent.traverseAncestors( callback );
  5299. }
  5300. },
  5301. updateMatrix: function () {
  5302. this.matrix.compose( this.position, this.quaternion, this.scale );
  5303. this.matrixWorldNeedsUpdate = true;
  5304. },
  5305. updateMatrixWorld: function ( force ) {
  5306. if ( this.matrixAutoUpdate === true ) this.updateMatrix();
  5307. if ( this.matrixWorldNeedsUpdate === true || force === true ) {
  5308. if ( this.parent === null ) {
  5309. this.matrixWorld.copy( this.matrix );
  5310. } else {
  5311. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  5312. }
  5313. this.matrixWorldNeedsUpdate = false;
  5314. force = true;
  5315. }
  5316. // update children
  5317. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  5318. this.children[ i ].updateMatrixWorld( force );
  5319. }
  5320. },
  5321. toJSON: function ( meta ) {
  5322. // meta is '' when called from JSON.stringify
  5323. var isRootObject = ( meta === undefined || meta === '' );
  5324. var output = {};
  5325. // meta is a hash used to collect geometries, materials.
  5326. // not providing it implies that this is the root object
  5327. // being serialized.
  5328. if ( isRootObject ) {
  5329. // initialize meta obj
  5330. meta = {
  5331. geometries: {},
  5332. materials: {},
  5333. textures: {},
  5334. images: {}
  5335. };
  5336. output.metadata = {
  5337. version: 4.4,
  5338. type: 'Object',
  5339. generator: 'Object3D.toJSON'
  5340. };
  5341. }
  5342. // standard Object3D serialization
  5343. var object = {};
  5344. object.uuid = this.uuid;
  5345. object.type = this.type;
  5346. if ( this.name !== '' ) object.name = this.name;
  5347. if ( JSON.stringify( this.userData ) !== '{}' ) object.userData = this.userData;
  5348. if ( this.castShadow === true ) object.castShadow = true;
  5349. if ( this.receiveShadow === true ) object.receiveShadow = true;
  5350. if ( this.visible === false ) object.visible = false;
  5351. object.matrix = this.matrix.toArray();
  5352. //
  5353. if ( this.geometry !== undefined ) {
  5354. if ( meta.geometries[ this.geometry.uuid ] === undefined ) {
  5355. meta.geometries[ this.geometry.uuid ] = this.geometry.toJSON( meta );
  5356. }
  5357. object.geometry = this.geometry.uuid;
  5358. }
  5359. if ( this.material !== undefined ) {
  5360. if ( meta.materials[ this.material.uuid ] === undefined ) {
  5361. meta.materials[ this.material.uuid ] = this.material.toJSON( meta );
  5362. }
  5363. object.material = this.material.uuid;
  5364. }
  5365. //
  5366. if ( this.children.length > 0 ) {
  5367. object.children = [];
  5368. for ( var i = 0; i < this.children.length; i ++ ) {
  5369. object.children.push( this.children[ i ].toJSON( meta ).object );
  5370. }
  5371. }
  5372. if ( isRootObject ) {
  5373. var geometries = extractFromCache( meta.geometries );
  5374. var materials = extractFromCache( meta.materials );
  5375. var textures = extractFromCache( meta.textures );
  5376. var images = extractFromCache( meta.images );
  5377. if ( geometries.length > 0 ) output.geometries = geometries;
  5378. if ( materials.length > 0 ) output.materials = materials;
  5379. if ( textures.length > 0 ) output.textures = textures;
  5380. if ( images.length > 0 ) output.images = images;
  5381. }
  5382. output.object = object;
  5383. return output;
  5384. // extract data from the cache hash
  5385. // remove metadata on each item
  5386. // and return as array
  5387. function extractFromCache ( cache ) {
  5388. var values = [];
  5389. for ( var key in cache ) {
  5390. var data = cache[ key ];
  5391. delete data.metadata;
  5392. values.push( data );
  5393. }
  5394. return values;
  5395. }
  5396. },
  5397. clone: function ( recursive ) {
  5398. return new this.constructor().copy( this, recursive );
  5399. },
  5400. copy: function ( source, recursive ) {
  5401. if ( recursive === undefined ) recursive = true;
  5402. this.name = source.name;
  5403. this.up.copy( source.up );
  5404. this.position.copy( source.position );
  5405. this.quaternion.copy( source.quaternion );
  5406. this.scale.copy( source.scale );
  5407. this.matrix.copy( source.matrix );
  5408. this.matrixWorld.copy( source.matrixWorld );
  5409. this.matrixAutoUpdate = source.matrixAutoUpdate;
  5410. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  5411. this.visible = source.visible;
  5412. this.castShadow = source.castShadow;
  5413. this.receiveShadow = source.receiveShadow;
  5414. this.frustumCulled = source.frustumCulled;
  5415. this.renderOrder = source.renderOrder;
  5416. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  5417. if ( recursive === true ) {
  5418. for ( var i = 0; i < source.children.length; i ++ ) {
  5419. var child = source.children[ i ];
  5420. this.add( child.clone() );
  5421. }
  5422. }
  5423. return this;
  5424. }
  5425. } );
  5426. THREE.Object3DIdCount = 0;
  5427. // File:src/core/Face3.js
  5428. /**
  5429. * @author mrdoob / http://mrdoob.com/
  5430. * @author alteredq / http://alteredqualia.com/
  5431. */
  5432. THREE.Face3 = function ( a, b, c, normal, color, materialIndex ) {
  5433. this.a = a;
  5434. this.b = b;
  5435. this.c = c;
  5436. this.normal = normal instanceof THREE.Vector3 ? normal : new THREE.Vector3();
  5437. this.vertexNormals = Array.isArray( normal ) ? normal : [];
  5438. this.color = color instanceof THREE.Color ? color : new THREE.Color();
  5439. this.vertexColors = Array.isArray( color ) ? color : [];
  5440. this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
  5441. };
  5442. THREE.Face3.prototype = {
  5443. constructor: THREE.Face3,
  5444. clone: function () {
  5445. return new this.constructor().copy( this );
  5446. },
  5447. copy: function ( source ) {
  5448. this.a = source.a;
  5449. this.b = source.b;
  5450. this.c = source.c;
  5451. this.normal.copy( source.normal );
  5452. this.color.copy( source.color );
  5453. this.materialIndex = source.materialIndex;
  5454. for ( var i = 0, il = source.vertexNormals.length; i < il; i ++ ) {
  5455. this.vertexNormals[ i ] = source.vertexNormals[ i ].clone();
  5456. }
  5457. for ( var i = 0, il = source.vertexColors.length; i < il; i ++ ) {
  5458. this.vertexColors[ i ] = source.vertexColors[ i ].clone();
  5459. }
  5460. return this;
  5461. }
  5462. };
  5463. // File:src/core/BufferAttribute.js
  5464. /**
  5465. * @author mrdoob / http://mrdoob.com/
  5466. */
  5467. THREE.BufferAttribute = function ( array, itemSize, normalized ) {
  5468. this.uuid = THREE.Math.generateUUID();
  5469. this.array = array;
  5470. this.itemSize = itemSize;
  5471. this.dynamic = false;
  5472. this.updateRange = { offset: 0, count: - 1 };
  5473. this.version = 0;
  5474. this.normalized = normalized === true;
  5475. };
  5476. THREE.BufferAttribute.prototype = {
  5477. constructor: THREE.BufferAttribute,
  5478. get count() {
  5479. return this.array.length / this.itemSize;
  5480. },
  5481. set needsUpdate( value ) {
  5482. if ( value === true ) this.version ++;
  5483. },
  5484. setDynamic: function ( value ) {
  5485. this.dynamic = value;
  5486. return this;
  5487. },
  5488. copy: function ( source ) {
  5489. this.array = new source.array.constructor( source.array );
  5490. this.itemSize = source.itemSize;
  5491. this.dynamic = source.dynamic;
  5492. return this;
  5493. },
  5494. copyAt: function ( index1, attribute, index2 ) {
  5495. index1 *= this.itemSize;
  5496. index2 *= attribute.itemSize;
  5497. for ( var i = 0, l = this.itemSize; i < l; i ++ ) {
  5498. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5499. }
  5500. return this;
  5501. },
  5502. copyArray: function ( array ) {
  5503. this.array.set( array );
  5504. return this;
  5505. },
  5506. copyColorsArray: function ( colors ) {
  5507. var array = this.array, offset = 0;
  5508. for ( var i = 0, l = colors.length; i < l; i ++ ) {
  5509. var color = colors[ i ];
  5510. if ( color === undefined ) {
  5511. console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
  5512. color = new THREE.Color();
  5513. }
  5514. array[ offset ++ ] = color.r;
  5515. array[ offset ++ ] = color.g;
  5516. array[ offset ++ ] = color.b;
  5517. }
  5518. return this;
  5519. },
  5520. copyIndicesArray: function ( indices ) {
  5521. var array = this.array, offset = 0;
  5522. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  5523. var index = indices[ i ];
  5524. array[ offset ++ ] = index.a;
  5525. array[ offset ++ ] = index.b;
  5526. array[ offset ++ ] = index.c;
  5527. }
  5528. return this;
  5529. },
  5530. copyVector2sArray: function ( vectors ) {
  5531. var array = this.array, offset = 0;
  5532. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5533. var vector = vectors[ i ];
  5534. if ( vector === undefined ) {
  5535. console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
  5536. vector = new THREE.Vector2();
  5537. }
  5538. array[ offset ++ ] = vector.x;
  5539. array[ offset ++ ] = vector.y;
  5540. }
  5541. return this;
  5542. },
  5543. copyVector3sArray: function ( vectors ) {
  5544. var array = this.array, offset = 0;
  5545. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5546. var vector = vectors[ i ];
  5547. if ( vector === undefined ) {
  5548. console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
  5549. vector = new THREE.Vector3();
  5550. }
  5551. array[ offset ++ ] = vector.x;
  5552. array[ offset ++ ] = vector.y;
  5553. array[ offset ++ ] = vector.z;
  5554. }
  5555. return this;
  5556. },
  5557. copyVector4sArray: function ( vectors ) {
  5558. var array = this.array, offset = 0;
  5559. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5560. var vector = vectors[ i ];
  5561. if ( vector === undefined ) {
  5562. console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i );
  5563. vector = new THREE.Vector4();
  5564. }
  5565. array[ offset ++ ] = vector.x;
  5566. array[ offset ++ ] = vector.y;
  5567. array[ offset ++ ] = vector.z;
  5568. array[ offset ++ ] = vector.w;
  5569. }
  5570. return this;
  5571. },
  5572. set: function ( value, offset ) {
  5573. if ( offset === undefined ) offset = 0;
  5574. this.array.set( value, offset );
  5575. return this;
  5576. },
  5577. getX: function ( index ) {
  5578. return this.array[ index * this.itemSize ];
  5579. },
  5580. setX: function ( index, x ) {
  5581. this.array[ index * this.itemSize ] = x;
  5582. return this;
  5583. },
  5584. getY: function ( index ) {
  5585. return this.array[ index * this.itemSize + 1 ];
  5586. },
  5587. setY: function ( index, y ) {
  5588. this.array[ index * this.itemSize + 1 ] = y;
  5589. return this;
  5590. },
  5591. getZ: function ( index ) {
  5592. return this.array[ index * this.itemSize + 2 ];
  5593. },
  5594. setZ: function ( index, z ) {
  5595. this.array[ index * this.itemSize + 2 ] = z;
  5596. return this;
  5597. },
  5598. getW: function ( index ) {
  5599. return this.array[ index * this.itemSize + 3 ];
  5600. },
  5601. setW: function ( index, w ) {
  5602. this.array[ index * this.itemSize + 3 ] = w;
  5603. return this;
  5604. },
  5605. setXY: function ( index, x, y ) {
  5606. index *= this.itemSize;
  5607. this.array[ index + 0 ] = x;
  5608. this.array[ index + 1 ] = y;
  5609. return this;
  5610. },
  5611. setXYZ: function ( index, x, y, z ) {
  5612. index *= this.itemSize;
  5613. this.array[ index + 0 ] = x;
  5614. this.array[ index + 1 ] = y;
  5615. this.array[ index + 2 ] = z;
  5616. return this;
  5617. },
  5618. setXYZW: function ( index, x, y, z, w ) {
  5619. index *= this.itemSize;
  5620. this.array[ index + 0 ] = x;
  5621. this.array[ index + 1 ] = y;
  5622. this.array[ index + 2 ] = z;
  5623. this.array[ index + 3 ] = w;
  5624. return this;
  5625. },
  5626. clone: function () {
  5627. return new this.constructor().copy( this );
  5628. }
  5629. };
  5630. //
  5631. THREE.Int8Attribute = function ( array, itemSize ) {
  5632. return new THREE.BufferAttribute( new Int8Array( array ), itemSize );
  5633. };
  5634. THREE.Uint8Attribute = function ( array, itemSize ) {
  5635. return new THREE.BufferAttribute( new Uint8Array( array ), itemSize );
  5636. };
  5637. THREE.Uint8ClampedAttribute = function ( array, itemSize ) {
  5638. return new THREE.BufferAttribute( new Uint8ClampedArray( array ), itemSize );
  5639. };
  5640. THREE.Int16Attribute = function ( array, itemSize ) {
  5641. return new THREE.BufferAttribute( new Int16Array( array ), itemSize );
  5642. };
  5643. THREE.Uint16Attribute = function ( array, itemSize ) {
  5644. return new THREE.BufferAttribute( new Uint16Array( array ), itemSize );
  5645. };
  5646. THREE.Int32Attribute = function ( array, itemSize ) {
  5647. return new THREE.BufferAttribute( new Int32Array( array ), itemSize );
  5648. };
  5649. THREE.Uint32Attribute = function ( array, itemSize ) {
  5650. return new THREE.BufferAttribute( new Uint32Array( array ), itemSize );
  5651. };
  5652. THREE.Float32Attribute = function ( array, itemSize ) {
  5653. return new THREE.BufferAttribute( new Float32Array( array ), itemSize );
  5654. };
  5655. THREE.Float64Attribute = function ( array, itemSize ) {
  5656. return new THREE.BufferAttribute( new Float64Array( array ), itemSize );
  5657. };
  5658. // Deprecated
  5659. THREE.DynamicBufferAttribute = function ( array, itemSize ) {
  5660. console.warn( 'THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setDynamic( true ) instead.' );
  5661. return new THREE.BufferAttribute( array, itemSize ).setDynamic( true );
  5662. };
  5663. // File:src/core/InstancedBufferAttribute.js
  5664. /**
  5665. * @author benaadams / https://twitter.com/ben_a_adams
  5666. */
  5667. THREE.InstancedBufferAttribute = function ( array, itemSize, meshPerAttribute ) {
  5668. THREE.BufferAttribute.call( this, array, itemSize );
  5669. this.meshPerAttribute = meshPerAttribute || 1;
  5670. };
  5671. THREE.InstancedBufferAttribute.prototype = Object.create( THREE.BufferAttribute.prototype );
  5672. THREE.InstancedBufferAttribute.prototype.constructor = THREE.InstancedBufferAttribute;
  5673. THREE.InstancedBufferAttribute.prototype.copy = function ( source ) {
  5674. THREE.BufferAttribute.prototype.copy.call( this, source );
  5675. this.meshPerAttribute = source.meshPerAttribute;
  5676. return this;
  5677. };
  5678. // File:src/core/InterleavedBuffer.js
  5679. /**
  5680. * @author benaadams / https://twitter.com/ben_a_adams
  5681. */
  5682. THREE.InterleavedBuffer = function ( array, stride ) {
  5683. this.uuid = THREE.Math.generateUUID();
  5684. this.array = array;
  5685. this.stride = stride;
  5686. this.dynamic = false;
  5687. this.updateRange = { offset: 0, count: - 1 };
  5688. this.version = 0;
  5689. };
  5690. THREE.InterleavedBuffer.prototype = {
  5691. constructor: THREE.InterleavedBuffer,
  5692. get length () {
  5693. return this.array.length;
  5694. },
  5695. get count () {
  5696. return this.array.length / this.stride;
  5697. },
  5698. set needsUpdate( value ) {
  5699. if ( value === true ) this.version ++;
  5700. },
  5701. setDynamic: function ( value ) {
  5702. this.dynamic = value;
  5703. return this;
  5704. },
  5705. copy: function ( source ) {
  5706. this.array = new source.array.constructor( source.array );
  5707. this.stride = source.stride;
  5708. this.dynamic = source.dynamic;
  5709. return this;
  5710. },
  5711. copyAt: function ( index1, attribute, index2 ) {
  5712. index1 *= this.stride;
  5713. index2 *= attribute.stride;
  5714. for ( var i = 0, l = this.stride; i < l; i ++ ) {
  5715. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5716. }
  5717. return this;
  5718. },
  5719. set: function ( value, offset ) {
  5720. if ( offset === undefined ) offset = 0;
  5721. this.array.set( value, offset );
  5722. return this;
  5723. },
  5724. clone: function () {
  5725. return new this.constructor().copy( this );
  5726. }
  5727. };
  5728. // File:src/core/InstancedInterleavedBuffer.js
  5729. /**
  5730. * @author benaadams / https://twitter.com/ben_a_adams
  5731. */
  5732. THREE.InstancedInterleavedBuffer = function ( array, stride, meshPerAttribute ) {
  5733. THREE.InterleavedBuffer.call( this, array, stride );
  5734. this.meshPerAttribute = meshPerAttribute || 1;
  5735. };
  5736. THREE.InstancedInterleavedBuffer.prototype = Object.create( THREE.InterleavedBuffer.prototype );
  5737. THREE.InstancedInterleavedBuffer.prototype.constructor = THREE.InstancedInterleavedBuffer;
  5738. THREE.InstancedInterleavedBuffer.prototype.copy = function ( source ) {
  5739. THREE.InterleavedBuffer.prototype.copy.call( this, source );
  5740. this.meshPerAttribute = source.meshPerAttribute;
  5741. return this;
  5742. };
  5743. // File:src/core/InterleavedBufferAttribute.js
  5744. /**
  5745. * @author benaadams / https://twitter.com/ben_a_adams
  5746. */
  5747. THREE.InterleavedBufferAttribute = function ( interleavedBuffer, itemSize, offset, normalized ) {
  5748. this.uuid = THREE.Math.generateUUID();
  5749. this.data = interleavedBuffer;
  5750. this.itemSize = itemSize;
  5751. this.offset = offset;
  5752. this.normalized = normalized === true;
  5753. };
  5754. THREE.InterleavedBufferAttribute.prototype = {
  5755. constructor: THREE.InterleavedBufferAttribute,
  5756. get length() {
  5757. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Please use .count.' );
  5758. return this.array.length;
  5759. },
  5760. get count() {
  5761. return this.data.count;
  5762. },
  5763. get array() {
  5764. return this.data.array;
  5765. },
  5766. setX: function ( index, x ) {
  5767. this.data.array[ index * this.data.stride + this.offset ] = x;
  5768. return this;
  5769. },
  5770. setY: function ( index, y ) {
  5771. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  5772. return this;
  5773. },
  5774. setZ: function ( index, z ) {
  5775. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  5776. return this;
  5777. },
  5778. setW: function ( index, w ) {
  5779. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  5780. return this;
  5781. },
  5782. getX: function ( index ) {
  5783. return this.data.array[ index * this.data.stride + this.offset ];
  5784. },
  5785. getY: function ( index ) {
  5786. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  5787. },
  5788. getZ: function ( index ) {
  5789. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  5790. },
  5791. getW: function ( index ) {
  5792. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  5793. },
  5794. setXY: function ( index, x, y ) {
  5795. index = index * this.data.stride + this.offset;
  5796. this.data.array[ index + 0 ] = x;
  5797. this.data.array[ index + 1 ] = y;
  5798. return this;
  5799. },
  5800. setXYZ: function ( index, x, y, z ) {
  5801. index = index * this.data.stride + this.offset;
  5802. this.data.array[ index + 0 ] = x;
  5803. this.data.array[ index + 1 ] = y;
  5804. this.data.array[ index + 2 ] = z;
  5805. return this;
  5806. },
  5807. setXYZW: function ( index, x, y, z, w ) {
  5808. index = index * this.data.stride + this.offset;
  5809. this.data.array[ index + 0 ] = x;
  5810. this.data.array[ index + 1 ] = y;
  5811. this.data.array[ index + 2 ] = z;
  5812. this.data.array[ index + 3 ] = w;
  5813. return this;
  5814. }
  5815. };
  5816. // File:src/core/Geometry.js
  5817. /**
  5818. * @author mrdoob / http://mrdoob.com/
  5819. * @author kile / http://kile.stravaganza.org/
  5820. * @author alteredq / http://alteredqualia.com/
  5821. * @author mikael emtinger / http://gomo.se/
  5822. * @author zz85 / http://www.lab4games.net/zz85/blog
  5823. * @author bhouston / http://clara.io
  5824. */
  5825. THREE.Geometry = function () {
  5826. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  5827. this.uuid = THREE.Math.generateUUID();
  5828. this.name = '';
  5829. this.type = 'Geometry';
  5830. this.vertices = [];
  5831. this.colors = [];
  5832. this.faces = [];
  5833. this.faceVertexUvs = [ [] ];
  5834. this.morphTargets = [];
  5835. this.morphNormals = [];
  5836. this.skinWeights = [];
  5837. this.skinIndices = [];
  5838. this.lineDistances = [];
  5839. this.boundingBox = null;
  5840. this.boundingSphere = null;
  5841. // update flags
  5842. this.elementsNeedUpdate = false;
  5843. this.verticesNeedUpdate = false;
  5844. this.uvsNeedUpdate = false;
  5845. this.normalsNeedUpdate = false;
  5846. this.colorsNeedUpdate = false;
  5847. this.lineDistancesNeedUpdate = false;
  5848. this.groupsNeedUpdate = false;
  5849. };
  5850. Object.assign( THREE.Geometry.prototype, THREE.EventDispatcher.prototype, {
  5851. applyMatrix: function ( matrix ) {
  5852. var normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  5853. for ( var i = 0, il = this.vertices.length; i < il; i ++ ) {
  5854. var vertex = this.vertices[ i ];
  5855. vertex.applyMatrix4( matrix );
  5856. }
  5857. for ( var i = 0, il = this.faces.length; i < il; i ++ ) {
  5858. var face = this.faces[ i ];
  5859. face.normal.applyMatrix3( normalMatrix ).normalize();
  5860. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  5861. face.vertexNormals[ j ].applyMatrix3( normalMatrix ).normalize();
  5862. }
  5863. }
  5864. if ( this.boundingBox !== null ) {
  5865. this.computeBoundingBox();
  5866. }
  5867. if ( this.boundingSphere !== null ) {
  5868. this.computeBoundingSphere();
  5869. }
  5870. this.verticesNeedUpdate = true;
  5871. this.normalsNeedUpdate = true;
  5872. return this;
  5873. },
  5874. rotateX: function () {
  5875. // rotate geometry around world x-axis
  5876. var m1;
  5877. return function rotateX( angle ) {
  5878. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5879. m1.makeRotationX( angle );
  5880. this.applyMatrix( m1 );
  5881. return this;
  5882. };
  5883. }(),
  5884. rotateY: function () {
  5885. // rotate geometry around world y-axis
  5886. var m1;
  5887. return function rotateY( angle ) {
  5888. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5889. m1.makeRotationY( angle );
  5890. this.applyMatrix( m1 );
  5891. return this;
  5892. };
  5893. }(),
  5894. rotateZ: function () {
  5895. // rotate geometry around world z-axis
  5896. var m1;
  5897. return function rotateZ( angle ) {
  5898. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5899. m1.makeRotationZ( angle );
  5900. this.applyMatrix( m1 );
  5901. return this;
  5902. };
  5903. }(),
  5904. translate: function () {
  5905. // translate geometry
  5906. var m1;
  5907. return function translate( x, y, z ) {
  5908. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5909. m1.makeTranslation( x, y, z );
  5910. this.applyMatrix( m1 );
  5911. return this;
  5912. };
  5913. }(),
  5914. scale: function () {
  5915. // scale geometry
  5916. var m1;
  5917. return function scale( x, y, z ) {
  5918. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5919. m1.makeScale( x, y, z );
  5920. this.applyMatrix( m1 );
  5921. return this;
  5922. };
  5923. }(),
  5924. lookAt: function () {
  5925. var obj;
  5926. return function lookAt( vector ) {
  5927. if ( obj === undefined ) obj = new THREE.Object3D();
  5928. obj.lookAt( vector );
  5929. obj.updateMatrix();
  5930. this.applyMatrix( obj.matrix );
  5931. };
  5932. }(),
  5933. fromBufferGeometry: function ( geometry ) {
  5934. var scope = this;
  5935. var indices = geometry.index !== null ? geometry.index.array : undefined;
  5936. var attributes = geometry.attributes;
  5937. var positions = attributes.position.array;
  5938. var normals = attributes.normal !== undefined ? attributes.normal.array : undefined;
  5939. var colors = attributes.color !== undefined ? attributes.color.array : undefined;
  5940. var uvs = attributes.uv !== undefined ? attributes.uv.array : undefined;
  5941. var uvs2 = attributes.uv2 !== undefined ? attributes.uv2.array : undefined;
  5942. if ( uvs2 !== undefined ) this.faceVertexUvs[ 1 ] = [];
  5943. var tempNormals = [];
  5944. var tempUVs = [];
  5945. var tempUVs2 = [];
  5946. for ( var i = 0, j = 0; i < positions.length; i += 3, j += 2 ) {
  5947. scope.vertices.push( new THREE.Vector3( positions[ i ], positions[ i + 1 ], positions[ i + 2 ] ) );
  5948. if ( normals !== undefined ) {
  5949. tempNormals.push( new THREE.Vector3( normals[ i ], normals[ i + 1 ], normals[ i + 2 ] ) );
  5950. }
  5951. if ( colors !== undefined ) {
  5952. scope.colors.push( new THREE.Color( colors[ i ], colors[ i + 1 ], colors[ i + 2 ] ) );
  5953. }
  5954. if ( uvs !== undefined ) {
  5955. tempUVs.push( new THREE.Vector2( uvs[ j ], uvs[ j + 1 ] ) );
  5956. }
  5957. if ( uvs2 !== undefined ) {
  5958. tempUVs2.push( new THREE.Vector2( uvs2[ j ], uvs2[ j + 1 ] ) );
  5959. }
  5960. }
  5961. function addFace( a, b, c, materialIndex ) {
  5962. var vertexNormals = normals !== undefined ? [ tempNormals[ a ].clone(), tempNormals[ b ].clone(), tempNormals[ c ].clone() ] : [];
  5963. var vertexColors = colors !== undefined ? [ scope.colors[ a ].clone(), scope.colors[ b ].clone(), scope.colors[ c ].clone() ] : [];
  5964. var face = new THREE.Face3( a, b, c, vertexNormals, vertexColors, materialIndex );
  5965. scope.faces.push( face );
  5966. if ( uvs !== undefined ) {
  5967. scope.faceVertexUvs[ 0 ].push( [ tempUVs[ a ].clone(), tempUVs[ b ].clone(), tempUVs[ c ].clone() ] );
  5968. }
  5969. if ( uvs2 !== undefined ) {
  5970. scope.faceVertexUvs[ 1 ].push( [ tempUVs2[ a ].clone(), tempUVs2[ b ].clone(), tempUVs2[ c ].clone() ] );
  5971. }
  5972. }
  5973. if ( indices !== undefined ) {
  5974. var groups = geometry.groups;
  5975. if ( groups.length > 0 ) {
  5976. for ( var i = 0; i < groups.length; i ++ ) {
  5977. var group = groups[ i ];
  5978. var start = group.start;
  5979. var count = group.count;
  5980. for ( var j = start, jl = start + count; j < jl; j += 3 ) {
  5981. addFace( indices[ j ], indices[ j + 1 ], indices[ j + 2 ], group.materialIndex );
  5982. }
  5983. }
  5984. } else {
  5985. for ( var i = 0; i < indices.length; i += 3 ) {
  5986. addFace( indices[ i ], indices[ i + 1 ], indices[ i + 2 ] );
  5987. }
  5988. }
  5989. } else {
  5990. for ( var i = 0; i < positions.length / 3; i += 3 ) {
  5991. addFace( i, i + 1, i + 2 );
  5992. }
  5993. }
  5994. this.computeFaceNormals();
  5995. if ( geometry.boundingBox !== null ) {
  5996. this.boundingBox = geometry.boundingBox.clone();
  5997. }
  5998. if ( geometry.boundingSphere !== null ) {
  5999. this.boundingSphere = geometry.boundingSphere.clone();
  6000. }
  6001. return this;
  6002. },
  6003. center: function () {
  6004. this.computeBoundingBox();
  6005. var offset = this.boundingBox.center().negate();
  6006. this.translate( offset.x, offset.y, offset.z );
  6007. return offset;
  6008. },
  6009. normalize: function () {
  6010. this.computeBoundingSphere();
  6011. var center = this.boundingSphere.center;
  6012. var radius = this.boundingSphere.radius;
  6013. var s = radius === 0 ? 1 : 1.0 / radius;
  6014. var matrix = new THREE.Matrix4();
  6015. matrix.set(
  6016. s, 0, 0, - s * center.x,
  6017. 0, s, 0, - s * center.y,
  6018. 0, 0, s, - s * center.z,
  6019. 0, 0, 0, 1
  6020. );
  6021. this.applyMatrix( matrix );
  6022. return this;
  6023. },
  6024. computeFaceNormals: function () {
  6025. var cb = new THREE.Vector3(), ab = new THREE.Vector3();
  6026. for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6027. var face = this.faces[ f ];
  6028. var vA = this.vertices[ face.a ];
  6029. var vB = this.vertices[ face.b ];
  6030. var vC = this.vertices[ face.c ];
  6031. cb.subVectors( vC, vB );
  6032. ab.subVectors( vA, vB );
  6033. cb.cross( ab );
  6034. cb.normalize();
  6035. face.normal.copy( cb );
  6036. }
  6037. },
  6038. computeVertexNormals: function ( areaWeighted ) {
  6039. if ( areaWeighted === undefined ) areaWeighted = true;
  6040. var v, vl, f, fl, face, vertices;
  6041. vertices = new Array( this.vertices.length );
  6042. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  6043. vertices[ v ] = new THREE.Vector3();
  6044. }
  6045. if ( areaWeighted ) {
  6046. // vertex normals weighted by triangle areas
  6047. // http://www.iquilezles.org/www/articles/normals/normals.htm
  6048. var vA, vB, vC;
  6049. var cb = new THREE.Vector3(), ab = new THREE.Vector3();
  6050. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6051. face = this.faces[ f ];
  6052. vA = this.vertices[ face.a ];
  6053. vB = this.vertices[ face.b ];
  6054. vC = this.vertices[ face.c ];
  6055. cb.subVectors( vC, vB );
  6056. ab.subVectors( vA, vB );
  6057. cb.cross( ab );
  6058. vertices[ face.a ].add( cb );
  6059. vertices[ face.b ].add( cb );
  6060. vertices[ face.c ].add( cb );
  6061. }
  6062. } else {
  6063. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6064. face = this.faces[ f ];
  6065. vertices[ face.a ].add( face.normal );
  6066. vertices[ face.b ].add( face.normal );
  6067. vertices[ face.c ].add( face.normal );
  6068. }
  6069. }
  6070. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  6071. vertices[ v ].normalize();
  6072. }
  6073. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6074. face = this.faces[ f ];
  6075. var vertexNormals = face.vertexNormals;
  6076. if ( vertexNormals.length === 3 ) {
  6077. vertexNormals[ 0 ].copy( vertices[ face.a ] );
  6078. vertexNormals[ 1 ].copy( vertices[ face.b ] );
  6079. vertexNormals[ 2 ].copy( vertices[ face.c ] );
  6080. } else {
  6081. vertexNormals[ 0 ] = vertices[ face.a ].clone();
  6082. vertexNormals[ 1 ] = vertices[ face.b ].clone();
  6083. vertexNormals[ 2 ] = vertices[ face.c ].clone();
  6084. }
  6085. }
  6086. if ( this.faces.length > 0 ) {
  6087. this.normalsNeedUpdate = true;
  6088. }
  6089. },
  6090. computeMorphNormals: function () {
  6091. var i, il, f, fl, face;
  6092. // save original normals
  6093. // - create temp variables on first access
  6094. // otherwise just copy (for faster repeated calls)
  6095. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6096. face = this.faces[ f ];
  6097. if ( ! face.__originalFaceNormal ) {
  6098. face.__originalFaceNormal = face.normal.clone();
  6099. } else {
  6100. face.__originalFaceNormal.copy( face.normal );
  6101. }
  6102. if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
  6103. for ( i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
  6104. if ( ! face.__originalVertexNormals[ i ] ) {
  6105. face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
  6106. } else {
  6107. face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
  6108. }
  6109. }
  6110. }
  6111. // use temp geometry to compute face and vertex normals for each morph
  6112. var tmpGeo = new THREE.Geometry();
  6113. tmpGeo.faces = this.faces;
  6114. for ( i = 0, il = this.morphTargets.length; i < il; i ++ ) {
  6115. // create on first access
  6116. if ( ! this.morphNormals[ i ] ) {
  6117. this.morphNormals[ i ] = {};
  6118. this.morphNormals[ i ].faceNormals = [];
  6119. this.morphNormals[ i ].vertexNormals = [];
  6120. var dstNormalsFace = this.morphNormals[ i ].faceNormals;
  6121. var dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
  6122. var faceNormal, vertexNormals;
  6123. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6124. faceNormal = new THREE.Vector3();
  6125. vertexNormals = { a: new THREE.Vector3(), b: new THREE.Vector3(), c: new THREE.Vector3() };
  6126. dstNormalsFace.push( faceNormal );
  6127. dstNormalsVertex.push( vertexNormals );
  6128. }
  6129. }
  6130. var morphNormals = this.morphNormals[ i ];
  6131. // set vertices to morph target
  6132. tmpGeo.vertices = this.morphTargets[ i ].vertices;
  6133. // compute morph normals
  6134. tmpGeo.computeFaceNormals();
  6135. tmpGeo.computeVertexNormals();
  6136. // store morph normals
  6137. var faceNormal, vertexNormals;
  6138. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6139. face = this.faces[ f ];
  6140. faceNormal = morphNormals.faceNormals[ f ];
  6141. vertexNormals = morphNormals.vertexNormals[ f ];
  6142. faceNormal.copy( face.normal );
  6143. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  6144. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  6145. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  6146. }
  6147. }
  6148. // restore original normals
  6149. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6150. face = this.faces[ f ];
  6151. face.normal = face.__originalFaceNormal;
  6152. face.vertexNormals = face.__originalVertexNormals;
  6153. }
  6154. },
  6155. computeTangents: function () {
  6156. console.warn( 'THREE.Geometry: .computeTangents() has been removed.' );
  6157. },
  6158. computeLineDistances: function () {
  6159. var d = 0;
  6160. var vertices = this.vertices;
  6161. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  6162. if ( i > 0 ) {
  6163. d += vertices[ i ].distanceTo( vertices[ i - 1 ] );
  6164. }
  6165. this.lineDistances[ i ] = d;
  6166. }
  6167. },
  6168. computeBoundingBox: function () {
  6169. if ( this.boundingBox === null ) {
  6170. this.boundingBox = new THREE.Box3();
  6171. }
  6172. this.boundingBox.setFromPoints( this.vertices );
  6173. },
  6174. computeBoundingSphere: function () {
  6175. if ( this.boundingSphere === null ) {
  6176. this.boundingSphere = new THREE.Sphere();
  6177. }
  6178. this.boundingSphere.setFromPoints( this.vertices );
  6179. },
  6180. merge: function ( geometry, matrix, materialIndexOffset ) {
  6181. if ( geometry instanceof THREE.Geometry === false ) {
  6182. console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry );
  6183. return;
  6184. }
  6185. var normalMatrix,
  6186. vertexOffset = this.vertices.length,
  6187. vertices1 = this.vertices,
  6188. vertices2 = geometry.vertices,
  6189. faces1 = this.faces,
  6190. faces2 = geometry.faces,
  6191. uvs1 = this.faceVertexUvs[ 0 ],
  6192. uvs2 = geometry.faceVertexUvs[ 0 ];
  6193. if ( materialIndexOffset === undefined ) materialIndexOffset = 0;
  6194. if ( matrix !== undefined ) {
  6195. normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  6196. }
  6197. // vertices
  6198. for ( var i = 0, il = vertices2.length; i < il; i ++ ) {
  6199. var vertex = vertices2[ i ];
  6200. var vertexCopy = vertex.clone();
  6201. if ( matrix !== undefined ) vertexCopy.applyMatrix4( matrix );
  6202. vertices1.push( vertexCopy );
  6203. }
  6204. // faces
  6205. for ( i = 0, il = faces2.length; i < il; i ++ ) {
  6206. var face = faces2[ i ], faceCopy, normal, color,
  6207. faceVertexNormals = face.vertexNormals,
  6208. faceVertexColors = face.vertexColors;
  6209. faceCopy = new THREE.Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset );
  6210. faceCopy.normal.copy( face.normal );
  6211. if ( normalMatrix !== undefined ) {
  6212. faceCopy.normal.applyMatrix3( normalMatrix ).normalize();
  6213. }
  6214. for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
  6215. normal = faceVertexNormals[ j ].clone();
  6216. if ( normalMatrix !== undefined ) {
  6217. normal.applyMatrix3( normalMatrix ).normalize();
  6218. }
  6219. faceCopy.vertexNormals.push( normal );
  6220. }
  6221. faceCopy.color.copy( face.color );
  6222. for ( var j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
  6223. color = faceVertexColors[ j ];
  6224. faceCopy.vertexColors.push( color.clone() );
  6225. }
  6226. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  6227. faces1.push( faceCopy );
  6228. }
  6229. // uvs
  6230. for ( i = 0, il = uvs2.length; i < il; i ++ ) {
  6231. var uv = uvs2[ i ], uvCopy = [];
  6232. if ( uv === undefined ) {
  6233. continue;
  6234. }
  6235. for ( var j = 0, jl = uv.length; j < jl; j ++ ) {
  6236. uvCopy.push( uv[ j ].clone() );
  6237. }
  6238. uvs1.push( uvCopy );
  6239. }
  6240. },
  6241. mergeMesh: function ( mesh ) {
  6242. if ( mesh instanceof THREE.Mesh === false ) {
  6243. console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh );
  6244. return;
  6245. }
  6246. mesh.matrixAutoUpdate && mesh.updateMatrix();
  6247. this.merge( mesh.geometry, mesh.matrix );
  6248. },
  6249. /*
  6250. * Checks for duplicate vertices with hashmap.
  6251. * Duplicated vertices are removed
  6252. * and faces' vertices are updated.
  6253. */
  6254. mergeVertices: function () {
  6255. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  6256. var unique = [], changes = [];
  6257. var v, key;
  6258. var precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001
  6259. var precision = Math.pow( 10, precisionPoints );
  6260. var i, il, face;
  6261. var indices, j, jl;
  6262. for ( i = 0, il = this.vertices.length; i < il; i ++ ) {
  6263. v = this.vertices[ i ];
  6264. key = Math.round( v.x * precision ) + '_' + Math.round( v.y * precision ) + '_' + Math.round( v.z * precision );
  6265. if ( verticesMap[ key ] === undefined ) {
  6266. verticesMap[ key ] = i;
  6267. unique.push( this.vertices[ i ] );
  6268. changes[ i ] = unique.length - 1;
  6269. } else {
  6270. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  6271. changes[ i ] = changes[ verticesMap[ key ] ];
  6272. }
  6273. }
  6274. // if faces are completely degenerate after merging vertices, we
  6275. // have to remove them from the geometry.
  6276. var faceIndicesToRemove = [];
  6277. for ( i = 0, il = this.faces.length; i < il; i ++ ) {
  6278. face = this.faces[ i ];
  6279. face.a = changes[ face.a ];
  6280. face.b = changes[ face.b ];
  6281. face.c = changes[ face.c ];
  6282. indices = [ face.a, face.b, face.c ];
  6283. var dupIndex = - 1;
  6284. // if any duplicate vertices are found in a Face3
  6285. // we have to remove the face as nothing can be saved
  6286. for ( var n = 0; n < 3; n ++ ) {
  6287. if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) {
  6288. dupIndex = n;
  6289. faceIndicesToRemove.push( i );
  6290. break;
  6291. }
  6292. }
  6293. }
  6294. for ( i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
  6295. var idx = faceIndicesToRemove[ i ];
  6296. this.faces.splice( idx, 1 );
  6297. for ( j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {
  6298. this.faceVertexUvs[ j ].splice( idx, 1 );
  6299. }
  6300. }
  6301. // Use unique set of vertices
  6302. var diff = this.vertices.length - unique.length;
  6303. this.vertices = unique;
  6304. return diff;
  6305. },
  6306. sortFacesByMaterialIndex: function () {
  6307. var faces = this.faces;
  6308. var length = faces.length;
  6309. // tag faces
  6310. for ( var i = 0; i < length; i ++ ) {
  6311. faces[ i ]._id = i;
  6312. }
  6313. // sort faces
  6314. function materialIndexSort( a, b ) {
  6315. return a.materialIndex - b.materialIndex;
  6316. }
  6317. faces.sort( materialIndexSort );
  6318. // sort uvs
  6319. var uvs1 = this.faceVertexUvs[ 0 ];
  6320. var uvs2 = this.faceVertexUvs[ 1 ];
  6321. var newUvs1, newUvs2;
  6322. if ( uvs1 && uvs1.length === length ) newUvs1 = [];
  6323. if ( uvs2 && uvs2.length === length ) newUvs2 = [];
  6324. for ( var i = 0; i < length; i ++ ) {
  6325. var id = faces[ i ]._id;
  6326. if ( newUvs1 ) newUvs1.push( uvs1[ id ] );
  6327. if ( newUvs2 ) newUvs2.push( uvs2[ id ] );
  6328. }
  6329. if ( newUvs1 ) this.faceVertexUvs[ 0 ] = newUvs1;
  6330. if ( newUvs2 ) this.faceVertexUvs[ 1 ] = newUvs2;
  6331. },
  6332. toJSON: function () {
  6333. var data = {
  6334. metadata: {
  6335. version: 4.4,
  6336. type: 'Geometry',
  6337. generator: 'Geometry.toJSON'
  6338. }
  6339. };
  6340. // standard Geometry serialization
  6341. data.uuid = this.uuid;
  6342. data.type = this.type;
  6343. if ( this.name !== '' ) data.name = this.name;
  6344. if ( this.parameters !== undefined ) {
  6345. var parameters = this.parameters;
  6346. for ( var key in parameters ) {
  6347. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  6348. }
  6349. return data;
  6350. }
  6351. var vertices = [];
  6352. for ( var i = 0; i < this.vertices.length; i ++ ) {
  6353. var vertex = this.vertices[ i ];
  6354. vertices.push( vertex.x, vertex.y, vertex.z );
  6355. }
  6356. var faces = [];
  6357. var normals = [];
  6358. var normalsHash = {};
  6359. var colors = [];
  6360. var colorsHash = {};
  6361. var uvs = [];
  6362. var uvsHash = {};
  6363. for ( var i = 0; i < this.faces.length; i ++ ) {
  6364. var face = this.faces[ i ];
  6365. var hasMaterial = true;
  6366. var hasFaceUv = false; // deprecated
  6367. var hasFaceVertexUv = this.faceVertexUvs[ 0 ][ i ] !== undefined;
  6368. var hasFaceNormal = face.normal.length() > 0;
  6369. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  6370. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  6371. var hasFaceVertexColor = face.vertexColors.length > 0;
  6372. var faceType = 0;
  6373. faceType = setBit( faceType, 0, 0 ); // isQuad
  6374. faceType = setBit( faceType, 1, hasMaterial );
  6375. faceType = setBit( faceType, 2, hasFaceUv );
  6376. faceType = setBit( faceType, 3, hasFaceVertexUv );
  6377. faceType = setBit( faceType, 4, hasFaceNormal );
  6378. faceType = setBit( faceType, 5, hasFaceVertexNormal );
  6379. faceType = setBit( faceType, 6, hasFaceColor );
  6380. faceType = setBit( faceType, 7, hasFaceVertexColor );
  6381. faces.push( faceType );
  6382. faces.push( face.a, face.b, face.c );
  6383. faces.push( face.materialIndex );
  6384. if ( hasFaceVertexUv ) {
  6385. var faceVertexUvs = this.faceVertexUvs[ 0 ][ i ];
  6386. faces.push(
  6387. getUvIndex( faceVertexUvs[ 0 ] ),
  6388. getUvIndex( faceVertexUvs[ 1 ] ),
  6389. getUvIndex( faceVertexUvs[ 2 ] )
  6390. );
  6391. }
  6392. if ( hasFaceNormal ) {
  6393. faces.push( getNormalIndex( face.normal ) );
  6394. }
  6395. if ( hasFaceVertexNormal ) {
  6396. var vertexNormals = face.vertexNormals;
  6397. faces.push(
  6398. getNormalIndex( vertexNormals[ 0 ] ),
  6399. getNormalIndex( vertexNormals[ 1 ] ),
  6400. getNormalIndex( vertexNormals[ 2 ] )
  6401. );
  6402. }
  6403. if ( hasFaceColor ) {
  6404. faces.push( getColorIndex( face.color ) );
  6405. }
  6406. if ( hasFaceVertexColor ) {
  6407. var vertexColors = face.vertexColors;
  6408. faces.push(
  6409. getColorIndex( vertexColors[ 0 ] ),
  6410. getColorIndex( vertexColors[ 1 ] ),
  6411. getColorIndex( vertexColors[ 2 ] )
  6412. );
  6413. }
  6414. }
  6415. function setBit( value, position, enabled ) {
  6416. return enabled ? value | ( 1 << position ) : value & ( ~ ( 1 << position ) );
  6417. }
  6418. function getNormalIndex( normal ) {
  6419. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  6420. if ( normalsHash[ hash ] !== undefined ) {
  6421. return normalsHash[ hash ];
  6422. }
  6423. normalsHash[ hash ] = normals.length / 3;
  6424. normals.push( normal.x, normal.y, normal.z );
  6425. return normalsHash[ hash ];
  6426. }
  6427. function getColorIndex( color ) {
  6428. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  6429. if ( colorsHash[ hash ] !== undefined ) {
  6430. return colorsHash[ hash ];
  6431. }
  6432. colorsHash[ hash ] = colors.length;
  6433. colors.push( color.getHex() );
  6434. return colorsHash[ hash ];
  6435. }
  6436. function getUvIndex( uv ) {
  6437. var hash = uv.x.toString() + uv.y.toString();
  6438. if ( uvsHash[ hash ] !== undefined ) {
  6439. return uvsHash[ hash ];
  6440. }
  6441. uvsHash[ hash ] = uvs.length / 2;
  6442. uvs.push( uv.x, uv.y );
  6443. return uvsHash[ hash ];
  6444. }
  6445. data.data = {};
  6446. data.data.vertices = vertices;
  6447. data.data.normals = normals;
  6448. if ( colors.length > 0 ) data.data.colors = colors;
  6449. if ( uvs.length > 0 ) data.data.uvs = [ uvs ]; // temporal backward compatibility
  6450. data.data.faces = faces;
  6451. return data;
  6452. },
  6453. clone: function () {
  6454. /*
  6455. // Handle primitives
  6456. var parameters = this.parameters;
  6457. if ( parameters !== undefined ) {
  6458. var values = [];
  6459. for ( var key in parameters ) {
  6460. values.push( parameters[ key ] );
  6461. }
  6462. var geometry = Object.create( this.constructor.prototype );
  6463. this.constructor.apply( geometry, values );
  6464. return geometry;
  6465. }
  6466. return new this.constructor().copy( this );
  6467. */
  6468. return new THREE.Geometry().copy( this );
  6469. },
  6470. copy: function ( source ) {
  6471. this.vertices = [];
  6472. this.faces = [];
  6473. this.faceVertexUvs = [ [] ];
  6474. var vertices = source.vertices;
  6475. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  6476. this.vertices.push( vertices[ i ].clone() );
  6477. }
  6478. var faces = source.faces;
  6479. for ( var i = 0, il = faces.length; i < il; i ++ ) {
  6480. this.faces.push( faces[ i ].clone() );
  6481. }
  6482. for ( var i = 0, il = source.faceVertexUvs.length; i < il; i ++ ) {
  6483. var faceVertexUvs = source.faceVertexUvs[ i ];
  6484. if ( this.faceVertexUvs[ i ] === undefined ) {
  6485. this.faceVertexUvs[ i ] = [];
  6486. }
  6487. for ( var j = 0, jl = faceVertexUvs.length; j < jl; j ++ ) {
  6488. var uvs = faceVertexUvs[ j ], uvsCopy = [];
  6489. for ( var k = 0, kl = uvs.length; k < kl; k ++ ) {
  6490. var uv = uvs[ k ];
  6491. uvsCopy.push( uv.clone() );
  6492. }
  6493. this.faceVertexUvs[ i ].push( uvsCopy );
  6494. }
  6495. }
  6496. return this;
  6497. },
  6498. dispose: function () {
  6499. this.dispatchEvent( { type: 'dispose' } );
  6500. }
  6501. } );
  6502. THREE.GeometryIdCount = 0;
  6503. // File:src/core/DirectGeometry.js
  6504. /**
  6505. * @author mrdoob / http://mrdoob.com/
  6506. */
  6507. THREE.DirectGeometry = function () {
  6508. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  6509. this.uuid = THREE.Math.generateUUID();
  6510. this.name = '';
  6511. this.type = 'DirectGeometry';
  6512. this.indices = [];
  6513. this.vertices = [];
  6514. this.normals = [];
  6515. this.colors = [];
  6516. this.uvs = [];
  6517. this.uvs2 = [];
  6518. this.groups = [];
  6519. this.morphTargets = {};
  6520. this.skinWeights = [];
  6521. this.skinIndices = [];
  6522. // this.lineDistances = [];
  6523. this.boundingBox = null;
  6524. this.boundingSphere = null;
  6525. // update flags
  6526. this.verticesNeedUpdate = false;
  6527. this.normalsNeedUpdate = false;
  6528. this.colorsNeedUpdate = false;
  6529. this.uvsNeedUpdate = false;
  6530. this.groupsNeedUpdate = false;
  6531. };
  6532. Object.assign( THREE.DirectGeometry.prototype, THREE.EventDispatcher.prototype, {
  6533. computeBoundingBox: THREE.Geometry.prototype.computeBoundingBox,
  6534. computeBoundingSphere: THREE.Geometry.prototype.computeBoundingSphere,
  6535. computeFaceNormals: function () {
  6536. console.warn( 'THREE.DirectGeometry: computeFaceNormals() is not a method of this type of geometry.' );
  6537. },
  6538. computeVertexNormals: function () {
  6539. console.warn( 'THREE.DirectGeometry: computeVertexNormals() is not a method of this type of geometry.' );
  6540. },
  6541. computeGroups: function ( geometry ) {
  6542. var group;
  6543. var groups = [];
  6544. var materialIndex;
  6545. var faces = geometry.faces;
  6546. for ( var i = 0; i < faces.length; i ++ ) {
  6547. var face = faces[ i ];
  6548. // materials
  6549. if ( face.materialIndex !== materialIndex ) {
  6550. materialIndex = face.materialIndex;
  6551. if ( group !== undefined ) {
  6552. group.count = ( i * 3 ) - group.start;
  6553. groups.push( group );
  6554. }
  6555. group = {
  6556. start: i * 3,
  6557. materialIndex: materialIndex
  6558. };
  6559. }
  6560. }
  6561. if ( group !== undefined ) {
  6562. group.count = ( i * 3 ) - group.start;
  6563. groups.push( group );
  6564. }
  6565. this.groups = groups;
  6566. },
  6567. fromGeometry: function ( geometry ) {
  6568. var faces = geometry.faces;
  6569. var vertices = geometry.vertices;
  6570. var faceVertexUvs = geometry.faceVertexUvs;
  6571. var hasFaceVertexUv = faceVertexUvs[ 0 ] && faceVertexUvs[ 0 ].length > 0;
  6572. var hasFaceVertexUv2 = faceVertexUvs[ 1 ] && faceVertexUvs[ 1 ].length > 0;
  6573. // morphs
  6574. var morphTargets = geometry.morphTargets;
  6575. var morphTargetsLength = morphTargets.length;
  6576. var morphTargetsPosition;
  6577. if ( morphTargetsLength > 0 ) {
  6578. morphTargetsPosition = [];
  6579. for ( var i = 0; i < morphTargetsLength; i ++ ) {
  6580. morphTargetsPosition[ i ] = [];
  6581. }
  6582. this.morphTargets.position = morphTargetsPosition;
  6583. }
  6584. var morphNormals = geometry.morphNormals;
  6585. var morphNormalsLength = morphNormals.length;
  6586. var morphTargetsNormal;
  6587. if ( morphNormalsLength > 0 ) {
  6588. morphTargetsNormal = [];
  6589. for ( var i = 0; i < morphNormalsLength; i ++ ) {
  6590. morphTargetsNormal[ i ] = [];
  6591. }
  6592. this.morphTargets.normal = morphTargetsNormal;
  6593. }
  6594. // skins
  6595. var skinIndices = geometry.skinIndices;
  6596. var skinWeights = geometry.skinWeights;
  6597. var hasSkinIndices = skinIndices.length === vertices.length;
  6598. var hasSkinWeights = skinWeights.length === vertices.length;
  6599. //
  6600. for ( var i = 0; i < faces.length; i ++ ) {
  6601. var face = faces[ i ];
  6602. this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] );
  6603. var vertexNormals = face.vertexNormals;
  6604. if ( vertexNormals.length === 3 ) {
  6605. this.normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
  6606. } else {
  6607. var normal = face.normal;
  6608. this.normals.push( normal, normal, normal );
  6609. }
  6610. var vertexColors = face.vertexColors;
  6611. if ( vertexColors.length === 3 ) {
  6612. this.colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
  6613. } else {
  6614. var color = face.color;
  6615. this.colors.push( color, color, color );
  6616. }
  6617. if ( hasFaceVertexUv === true ) {
  6618. var vertexUvs = faceVertexUvs[ 0 ][ i ];
  6619. if ( vertexUvs !== undefined ) {
  6620. this.uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6621. } else {
  6622. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', i );
  6623. this.uvs.push( new THREE.Vector2(), new THREE.Vector2(), new THREE.Vector2() );
  6624. }
  6625. }
  6626. if ( hasFaceVertexUv2 === true ) {
  6627. var vertexUvs = faceVertexUvs[ 1 ][ i ];
  6628. if ( vertexUvs !== undefined ) {
  6629. this.uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6630. } else {
  6631. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', i );
  6632. this.uvs2.push( new THREE.Vector2(), new THREE.Vector2(), new THREE.Vector2() );
  6633. }
  6634. }
  6635. // morphs
  6636. for ( var j = 0; j < morphTargetsLength; j ++ ) {
  6637. var morphTarget = morphTargets[ j ].vertices;
  6638. morphTargetsPosition[ j ].push( morphTarget[ face.a ], morphTarget[ face.b ], morphTarget[ face.c ] );
  6639. }
  6640. for ( var j = 0; j < morphNormalsLength; j ++ ) {
  6641. var morphNormal = morphNormals[ j ].vertexNormals[ i ];
  6642. morphTargetsNormal[ j ].push( morphNormal.a, morphNormal.b, morphNormal.c );
  6643. }
  6644. // skins
  6645. if ( hasSkinIndices ) {
  6646. this.skinIndices.push( skinIndices[ face.a ], skinIndices[ face.b ], skinIndices[ face.c ] );
  6647. }
  6648. if ( hasSkinWeights ) {
  6649. this.skinWeights.push( skinWeights[ face.a ], skinWeights[ face.b ], skinWeights[ face.c ] );
  6650. }
  6651. }
  6652. this.computeGroups( geometry );
  6653. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6654. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6655. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6656. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6657. this.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6658. return this;
  6659. },
  6660. dispose: function () {
  6661. this.dispatchEvent( { type: 'dispose' } );
  6662. }
  6663. } );
  6664. // File:src/core/BufferGeometry.js
  6665. /**
  6666. * @author alteredq / http://alteredqualia.com/
  6667. * @author mrdoob / http://mrdoob.com/
  6668. */
  6669. THREE.BufferGeometry = function () {
  6670. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  6671. this.uuid = THREE.Math.generateUUID();
  6672. this.name = '';
  6673. this.type = 'BufferGeometry';
  6674. this.index = null;
  6675. this.attributes = {};
  6676. this.morphAttributes = {};
  6677. this.groups = [];
  6678. this.boundingBox = null;
  6679. this.boundingSphere = null;
  6680. this.drawRange = { start: 0, count: Infinity };
  6681. };
  6682. Object.assign( THREE.BufferGeometry.prototype, THREE.EventDispatcher.prototype, {
  6683. getIndex: function () {
  6684. return this.index;
  6685. },
  6686. setIndex: function ( index ) {
  6687. this.index = index;
  6688. },
  6689. addAttribute: function ( name, attribute ) {
  6690. if ( attribute instanceof THREE.BufferAttribute === false && attribute instanceof THREE.InterleavedBufferAttribute === false ) {
  6691. console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
  6692. this.addAttribute( name, new THREE.BufferAttribute( arguments[ 1 ], arguments[ 2 ] ) );
  6693. return;
  6694. }
  6695. if ( name === 'index' ) {
  6696. console.warn( 'THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.' );
  6697. this.setIndex( attribute );
  6698. return;
  6699. }
  6700. this.attributes[ name ] = attribute;
  6701. return this;
  6702. },
  6703. getAttribute: function ( name ) {
  6704. return this.attributes[ name ];
  6705. },
  6706. removeAttribute: function ( name ) {
  6707. delete this.attributes[ name ];
  6708. return this;
  6709. },
  6710. addGroup: function ( start, count, materialIndex ) {
  6711. this.groups.push( {
  6712. start: start,
  6713. count: count,
  6714. materialIndex: materialIndex !== undefined ? materialIndex : 0
  6715. } );
  6716. },
  6717. clearGroups: function () {
  6718. this.groups = [];
  6719. },
  6720. setDrawRange: function ( start, count ) {
  6721. this.drawRange.start = start;
  6722. this.drawRange.count = count;
  6723. },
  6724. applyMatrix: function ( matrix ) {
  6725. var position = this.attributes.position;
  6726. if ( position !== undefined ) {
  6727. matrix.applyToVector3Array( position.array );
  6728. position.needsUpdate = true;
  6729. }
  6730. var normal = this.attributes.normal;
  6731. if ( normal !== undefined ) {
  6732. var normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  6733. normalMatrix.applyToVector3Array( normal.array );
  6734. normal.needsUpdate = true;
  6735. }
  6736. if ( this.boundingBox !== null ) {
  6737. this.computeBoundingBox();
  6738. }
  6739. if ( this.boundingSphere !== null ) {
  6740. this.computeBoundingSphere();
  6741. }
  6742. return this;
  6743. },
  6744. rotateX: function () {
  6745. // rotate geometry around world x-axis
  6746. var m1;
  6747. return function rotateX( angle ) {
  6748. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6749. m1.makeRotationX( angle );
  6750. this.applyMatrix( m1 );
  6751. return this;
  6752. };
  6753. }(),
  6754. rotateY: function () {
  6755. // rotate geometry around world y-axis
  6756. var m1;
  6757. return function rotateY( angle ) {
  6758. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6759. m1.makeRotationY( angle );
  6760. this.applyMatrix( m1 );
  6761. return this;
  6762. };
  6763. }(),
  6764. rotateZ: function () {
  6765. // rotate geometry around world z-axis
  6766. var m1;
  6767. return function rotateZ( angle ) {
  6768. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6769. m1.makeRotationZ( angle );
  6770. this.applyMatrix( m1 );
  6771. return this;
  6772. };
  6773. }(),
  6774. translate: function () {
  6775. // translate geometry
  6776. var m1;
  6777. return function translate( x, y, z ) {
  6778. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6779. m1.makeTranslation( x, y, z );
  6780. this.applyMatrix( m1 );
  6781. return this;
  6782. };
  6783. }(),
  6784. scale: function () {
  6785. // scale geometry
  6786. var m1;
  6787. return function scale( x, y, z ) {
  6788. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6789. m1.makeScale( x, y, z );
  6790. this.applyMatrix( m1 );
  6791. return this;
  6792. };
  6793. }(),
  6794. lookAt: function () {
  6795. var obj;
  6796. return function lookAt( vector ) {
  6797. if ( obj === undefined ) obj = new THREE.Object3D();
  6798. obj.lookAt( vector );
  6799. obj.updateMatrix();
  6800. this.applyMatrix( obj.matrix );
  6801. };
  6802. }(),
  6803. center: function () {
  6804. this.computeBoundingBox();
  6805. var offset = this.boundingBox.center().negate();
  6806. this.translate( offset.x, offset.y, offset.z );
  6807. return offset;
  6808. },
  6809. setFromObject: function ( object ) {
  6810. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  6811. var geometry = object.geometry;
  6812. if ( object instanceof THREE.Points || object instanceof THREE.Line ) {
  6813. var positions = new THREE.Float32Attribute( geometry.vertices.length * 3, 3 );
  6814. var colors = new THREE.Float32Attribute( geometry.colors.length * 3, 3 );
  6815. this.addAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) );
  6816. this.addAttribute( 'color', colors.copyColorsArray( geometry.colors ) );
  6817. if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) {
  6818. var lineDistances = new THREE.Float32Attribute( geometry.lineDistances.length, 1 );
  6819. this.addAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) );
  6820. }
  6821. if ( geometry.boundingSphere !== null ) {
  6822. this.boundingSphere = geometry.boundingSphere.clone();
  6823. }
  6824. if ( geometry.boundingBox !== null ) {
  6825. this.boundingBox = geometry.boundingBox.clone();
  6826. }
  6827. } else if ( object instanceof THREE.Mesh ) {
  6828. if ( geometry instanceof THREE.Geometry ) {
  6829. this.fromGeometry( geometry );
  6830. }
  6831. }
  6832. return this;
  6833. },
  6834. updateFromObject: function ( object ) {
  6835. var geometry = object.geometry;
  6836. if ( object instanceof THREE.Mesh ) {
  6837. var direct = geometry.__directGeometry;
  6838. if ( direct === undefined || geometry.elementsNeedUpdate === true ) {
  6839. return this.fromGeometry( geometry );
  6840. }
  6841. direct.verticesNeedUpdate = geometry.verticesNeedUpdate || geometry.elementsNeedUpdate;
  6842. direct.normalsNeedUpdate = geometry.normalsNeedUpdate || geometry.elementsNeedUpdate;
  6843. direct.colorsNeedUpdate = geometry.colorsNeedUpdate || geometry.elementsNeedUpdate;
  6844. direct.uvsNeedUpdate = geometry.uvsNeedUpdate || geometry.elementsNeedUpdate;
  6845. direct.groupsNeedUpdate = geometry.groupsNeedUpdate || geometry.elementsNeedUpdate;
  6846. geometry.elementsNeedUpdate = false;
  6847. geometry.verticesNeedUpdate = false;
  6848. geometry.normalsNeedUpdate = false;
  6849. geometry.colorsNeedUpdate = false;
  6850. geometry.uvsNeedUpdate = false;
  6851. geometry.groupsNeedUpdate = false;
  6852. geometry = direct;
  6853. }
  6854. var attribute;
  6855. if ( geometry.verticesNeedUpdate === true ) {
  6856. attribute = this.attributes.position;
  6857. if ( attribute !== undefined ) {
  6858. attribute.copyVector3sArray( geometry.vertices );
  6859. attribute.needsUpdate = true;
  6860. }
  6861. geometry.verticesNeedUpdate = false;
  6862. }
  6863. if ( geometry.normalsNeedUpdate === true ) {
  6864. attribute = this.attributes.normal;
  6865. if ( attribute !== undefined ) {
  6866. attribute.copyVector3sArray( geometry.normals );
  6867. attribute.needsUpdate = true;
  6868. }
  6869. geometry.normalsNeedUpdate = false;
  6870. }
  6871. if ( geometry.colorsNeedUpdate === true ) {
  6872. attribute = this.attributes.color;
  6873. if ( attribute !== undefined ) {
  6874. attribute.copyColorsArray( geometry.colors );
  6875. attribute.needsUpdate = true;
  6876. }
  6877. geometry.colorsNeedUpdate = false;
  6878. }
  6879. if ( geometry.uvsNeedUpdate ) {
  6880. attribute = this.attributes.uv;
  6881. if ( attribute !== undefined ) {
  6882. attribute.copyVector2sArray( geometry.uvs );
  6883. attribute.needsUpdate = true;
  6884. }
  6885. geometry.uvsNeedUpdate = false;
  6886. }
  6887. if ( geometry.lineDistancesNeedUpdate ) {
  6888. attribute = this.attributes.lineDistance;
  6889. if ( attribute !== undefined ) {
  6890. attribute.copyArray( geometry.lineDistances );
  6891. attribute.needsUpdate = true;
  6892. }
  6893. geometry.lineDistancesNeedUpdate = false;
  6894. }
  6895. if ( geometry.groupsNeedUpdate ) {
  6896. geometry.computeGroups( object.geometry );
  6897. this.groups = geometry.groups;
  6898. geometry.groupsNeedUpdate = false;
  6899. }
  6900. return this;
  6901. },
  6902. fromGeometry: function ( geometry ) {
  6903. geometry.__directGeometry = new THREE.DirectGeometry().fromGeometry( geometry );
  6904. return this.fromDirectGeometry( geometry.__directGeometry );
  6905. },
  6906. fromDirectGeometry: function ( geometry ) {
  6907. var positions = new Float32Array( geometry.vertices.length * 3 );
  6908. this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) );
  6909. if ( geometry.normals.length > 0 ) {
  6910. var normals = new Float32Array( geometry.normals.length * 3 );
  6911. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) );
  6912. }
  6913. if ( geometry.colors.length > 0 ) {
  6914. var colors = new Float32Array( geometry.colors.length * 3 );
  6915. this.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors ) );
  6916. }
  6917. if ( geometry.uvs.length > 0 ) {
  6918. var uvs = new Float32Array( geometry.uvs.length * 2 );
  6919. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs ) );
  6920. }
  6921. if ( geometry.uvs2.length > 0 ) {
  6922. var uvs2 = new Float32Array( geometry.uvs2.length * 2 );
  6923. this.addAttribute( 'uv2', new THREE.BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 ) );
  6924. }
  6925. if ( geometry.indices.length > 0 ) {
  6926. var TypeArray = geometry.vertices.length > 65535 ? Uint32Array : Uint16Array;
  6927. var indices = new TypeArray( geometry.indices.length * 3 );
  6928. this.setIndex( new THREE.BufferAttribute( indices, 1 ).copyIndicesArray( geometry.indices ) );
  6929. }
  6930. // groups
  6931. this.groups = geometry.groups;
  6932. // morphs
  6933. for ( var name in geometry.morphTargets ) {
  6934. var array = [];
  6935. var morphTargets = geometry.morphTargets[ name ];
  6936. for ( var i = 0, l = morphTargets.length; i < l; i ++ ) {
  6937. var morphTarget = morphTargets[ i ];
  6938. var attribute = new THREE.Float32Attribute( morphTarget.length * 3, 3 );
  6939. array.push( attribute.copyVector3sArray( morphTarget ) );
  6940. }
  6941. this.morphAttributes[ name ] = array;
  6942. }
  6943. // skinning
  6944. if ( geometry.skinIndices.length > 0 ) {
  6945. var skinIndices = new THREE.Float32Attribute( geometry.skinIndices.length * 4, 4 );
  6946. this.addAttribute( 'skinIndex', skinIndices.copyVector4sArray( geometry.skinIndices ) );
  6947. }
  6948. if ( geometry.skinWeights.length > 0 ) {
  6949. var skinWeights = new THREE.Float32Attribute( geometry.skinWeights.length * 4, 4 );
  6950. this.addAttribute( 'skinWeight', skinWeights.copyVector4sArray( geometry.skinWeights ) );
  6951. }
  6952. //
  6953. if ( geometry.boundingSphere !== null ) {
  6954. this.boundingSphere = geometry.boundingSphere.clone();
  6955. }
  6956. if ( geometry.boundingBox !== null ) {
  6957. this.boundingBox = geometry.boundingBox.clone();
  6958. }
  6959. return this;
  6960. },
  6961. computeBoundingBox: function () {
  6962. if ( this.boundingBox === null ) {
  6963. this.boundingBox = new THREE.Box3();
  6964. }
  6965. var positions = this.attributes.position.array;
  6966. if ( positions !== undefined ) {
  6967. this.boundingBox.setFromArray( positions );
  6968. } else {
  6969. this.boundingBox.makeEmpty();
  6970. }
  6971. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  6972. console.error( 'THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  6973. }
  6974. },
  6975. computeBoundingSphere: function () {
  6976. var box = new THREE.Box3();
  6977. var vector = new THREE.Vector3();
  6978. return function computeBoundingSphere() {
  6979. if ( this.boundingSphere === null ) {
  6980. this.boundingSphere = new THREE.Sphere();
  6981. }
  6982. var positions = this.attributes.position;
  6983. if ( positions ) {
  6984. var array = positions.array;
  6985. var center = this.boundingSphere.center;
  6986. box.setFromArray( array );
  6987. box.center( center );
  6988. // hoping to find a boundingSphere with a radius smaller than the
  6989. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  6990. var maxRadiusSq = 0;
  6991. for ( var i = 0, il = array.length; i < il; i += 3 ) {
  6992. vector.fromArray( array, i );
  6993. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
  6994. }
  6995. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  6996. if ( isNaN( this.boundingSphere.radius ) ) {
  6997. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  6998. }
  6999. }
  7000. };
  7001. }(),
  7002. computeFaceNormals: function () {
  7003. // backwards compatibility
  7004. },
  7005. computeVertexNormals: function () {
  7006. var index = this.index;
  7007. var attributes = this.attributes;
  7008. var groups = this.groups;
  7009. if ( attributes.position ) {
  7010. var positions = attributes.position.array;
  7011. if ( attributes.normal === undefined ) {
  7012. this.addAttribute( 'normal', new THREE.BufferAttribute( new Float32Array( positions.length ), 3 ) );
  7013. } else {
  7014. // reset existing normals to zero
  7015. var array = attributes.normal.array;
  7016. for ( var i = 0, il = array.length; i < il; i ++ ) {
  7017. array[ i ] = 0;
  7018. }
  7019. }
  7020. var normals = attributes.normal.array;
  7021. var vA, vB, vC,
  7022. pA = new THREE.Vector3(),
  7023. pB = new THREE.Vector3(),
  7024. pC = new THREE.Vector3(),
  7025. cb = new THREE.Vector3(),
  7026. ab = new THREE.Vector3();
  7027. // indexed elements
  7028. if ( index ) {
  7029. var indices = index.array;
  7030. if ( groups.length === 0 ) {
  7031. this.addGroup( 0, indices.length );
  7032. }
  7033. for ( var j = 0, jl = groups.length; j < jl; ++ j ) {
  7034. var group = groups[ j ];
  7035. var start = group.start;
  7036. var count = group.count;
  7037. for ( var i = start, il = start + count; i < il; i += 3 ) {
  7038. vA = indices[ i + 0 ] * 3;
  7039. vB = indices[ i + 1 ] * 3;
  7040. vC = indices[ i + 2 ] * 3;
  7041. pA.fromArray( positions, vA );
  7042. pB.fromArray( positions, vB );
  7043. pC.fromArray( positions, vC );
  7044. cb.subVectors( pC, pB );
  7045. ab.subVectors( pA, pB );
  7046. cb.cross( ab );
  7047. normals[ vA ] += cb.x;
  7048. normals[ vA + 1 ] += cb.y;
  7049. normals[ vA + 2 ] += cb.z;
  7050. normals[ vB ] += cb.x;
  7051. normals[ vB + 1 ] += cb.y;
  7052. normals[ vB + 2 ] += cb.z;
  7053. normals[ vC ] += cb.x;
  7054. normals[ vC + 1 ] += cb.y;
  7055. normals[ vC + 2 ] += cb.z;
  7056. }
  7057. }
  7058. } else {
  7059. // non-indexed elements (unconnected triangle soup)
  7060. for ( var i = 0, il = positions.length; i < il; i += 9 ) {
  7061. pA.fromArray( positions, i );
  7062. pB.fromArray( positions, i + 3 );
  7063. pC.fromArray( positions, i + 6 );
  7064. cb.subVectors( pC, pB );
  7065. ab.subVectors( pA, pB );
  7066. cb.cross( ab );
  7067. normals[ i ] = cb.x;
  7068. normals[ i + 1 ] = cb.y;
  7069. normals[ i + 2 ] = cb.z;
  7070. normals[ i + 3 ] = cb.x;
  7071. normals[ i + 4 ] = cb.y;
  7072. normals[ i + 5 ] = cb.z;
  7073. normals[ i + 6 ] = cb.x;
  7074. normals[ i + 7 ] = cb.y;
  7075. normals[ i + 8 ] = cb.z;
  7076. }
  7077. }
  7078. this.normalizeNormals();
  7079. attributes.normal.needsUpdate = true;
  7080. }
  7081. },
  7082. merge: function ( geometry, offset ) {
  7083. if ( geometry instanceof THREE.BufferGeometry === false ) {
  7084. console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
  7085. return;
  7086. }
  7087. if ( offset === undefined ) offset = 0;
  7088. var attributes = this.attributes;
  7089. for ( var key in attributes ) {
  7090. if ( geometry.attributes[ key ] === undefined ) continue;
  7091. var attribute1 = attributes[ key ];
  7092. var attributeArray1 = attribute1.array;
  7093. var attribute2 = geometry.attributes[ key ];
  7094. var attributeArray2 = attribute2.array;
  7095. var attributeSize = attribute2.itemSize;
  7096. for ( var i = 0, j = attributeSize * offset; i < attributeArray2.length; i ++, j ++ ) {
  7097. attributeArray1[ j ] = attributeArray2[ i ];
  7098. }
  7099. }
  7100. return this;
  7101. },
  7102. normalizeNormals: function () {
  7103. var normals = this.attributes.normal.array;
  7104. var x, y, z, n;
  7105. for ( var i = 0, il = normals.length; i < il; i += 3 ) {
  7106. x = normals[ i ];
  7107. y = normals[ i + 1 ];
  7108. z = normals[ i + 2 ];
  7109. n = 1.0 / Math.sqrt( x * x + y * y + z * z );
  7110. normals[ i ] *= n;
  7111. normals[ i + 1 ] *= n;
  7112. normals[ i + 2 ] *= n;
  7113. }
  7114. },
  7115. toNonIndexed: function () {
  7116. if ( this.index === null ) {
  7117. console.warn( 'THREE.BufferGeometry.toNonIndexed(): Geometry is already non-indexed.' );
  7118. return this;
  7119. }
  7120. var geometry2 = new THREE.BufferGeometry();
  7121. var indices = this.index.array;
  7122. var attributes = this.attributes;
  7123. for ( var name in attributes ) {
  7124. var attribute = attributes[ name ];
  7125. var array = attribute.array;
  7126. var itemSize = attribute.itemSize;
  7127. var array2 = new array.constructor( indices.length * itemSize );
  7128. var index = 0, index2 = 0;
  7129. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  7130. index = indices[ i ] * itemSize;
  7131. for ( var j = 0; j < itemSize; j ++ ) {
  7132. array2[ index2 ++ ] = array[ index ++ ];
  7133. }
  7134. }
  7135. geometry2.addAttribute( name, new THREE.BufferAttribute( array2, itemSize ) );
  7136. }
  7137. return geometry2;
  7138. },
  7139. toJSON: function () {
  7140. var data = {
  7141. metadata: {
  7142. version: 4.4,
  7143. type: 'BufferGeometry',
  7144. generator: 'BufferGeometry.toJSON'
  7145. }
  7146. };
  7147. // standard BufferGeometry serialization
  7148. data.uuid = this.uuid;
  7149. data.type = this.type;
  7150. if ( this.name !== '' ) data.name = this.name;
  7151. if ( this.parameters !== undefined ) {
  7152. var parameters = this.parameters;
  7153. for ( var key in parameters ) {
  7154. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  7155. }
  7156. return data;
  7157. }
  7158. data.data = { attributes: {} };
  7159. var index = this.index;
  7160. if ( index !== null ) {
  7161. var array = Array.prototype.slice.call( index.array );
  7162. data.data.index = {
  7163. type: index.array.constructor.name,
  7164. array: array
  7165. };
  7166. }
  7167. var attributes = this.attributes;
  7168. for ( var key in attributes ) {
  7169. var attribute = attributes[ key ];
  7170. var array = Array.prototype.slice.call( attribute.array );
  7171. data.data.attributes[ key ] = {
  7172. itemSize: attribute.itemSize,
  7173. type: attribute.array.constructor.name,
  7174. array: array,
  7175. normalized: attribute.normalized
  7176. };
  7177. }
  7178. var groups = this.groups;
  7179. if ( groups.length > 0 ) {
  7180. data.data.groups = JSON.parse( JSON.stringify( groups ) );
  7181. }
  7182. var boundingSphere = this.boundingSphere;
  7183. if ( boundingSphere !== null ) {
  7184. data.data.boundingSphere = {
  7185. center: boundingSphere.center.toArray(),
  7186. radius: boundingSphere.radius
  7187. };
  7188. }
  7189. return data;
  7190. },
  7191. clone: function () {
  7192. /*
  7193. // Handle primitives
  7194. var parameters = this.parameters;
  7195. if ( parameters !== undefined ) {
  7196. var values = [];
  7197. for ( var key in parameters ) {
  7198. values.push( parameters[ key ] );
  7199. }
  7200. var geometry = Object.create( this.constructor.prototype );
  7201. this.constructor.apply( geometry, values );
  7202. return geometry;
  7203. }
  7204. return new this.constructor().copy( this );
  7205. */
  7206. return new THREE.BufferGeometry().copy( this );
  7207. },
  7208. copy: function ( source ) {
  7209. var index = source.index;
  7210. if ( index !== null ) {
  7211. this.setIndex( index.clone() );
  7212. }
  7213. var attributes = source.attributes;
  7214. for ( var name in attributes ) {
  7215. var attribute = attributes[ name ];
  7216. this.addAttribute( name, attribute.clone() );
  7217. }
  7218. var groups = source.groups;
  7219. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  7220. var group = groups[ i ];
  7221. this.addGroup( group.start, group.count, group.materialIndex );
  7222. }
  7223. return this;
  7224. },
  7225. dispose: function () {
  7226. this.dispatchEvent( { type: 'dispose' } );
  7227. }
  7228. } );
  7229. THREE.BufferGeometry.MaxIndex = 65535;
  7230. // File:src/core/InstancedBufferGeometry.js
  7231. /**
  7232. * @author benaadams / https://twitter.com/ben_a_adams
  7233. */
  7234. THREE.InstancedBufferGeometry = function () {
  7235. THREE.BufferGeometry.call( this );
  7236. this.type = 'InstancedBufferGeometry';
  7237. this.maxInstancedCount = undefined;
  7238. };
  7239. THREE.InstancedBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  7240. THREE.InstancedBufferGeometry.prototype.constructor = THREE.InstancedBufferGeometry;
  7241. THREE.InstancedBufferGeometry.prototype.addGroup = function ( start, count, instances ) {
  7242. this.groups.push( {
  7243. start: start,
  7244. count: count,
  7245. instances: instances
  7246. } );
  7247. };
  7248. THREE.InstancedBufferGeometry.prototype.copy = function ( source ) {
  7249. var index = source.index;
  7250. if ( index !== null ) {
  7251. this.setIndex( index.clone() );
  7252. }
  7253. var attributes = source.attributes;
  7254. for ( var name in attributes ) {
  7255. var attribute = attributes[ name ];
  7256. this.addAttribute( name, attribute.clone() );
  7257. }
  7258. var groups = source.groups;
  7259. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  7260. var group = groups[ i ];
  7261. this.addGroup( group.start, group.count, group.instances );
  7262. }
  7263. return this;
  7264. };
  7265. // File:src/core/Uniform.js
  7266. /**
  7267. * @author mrdoob / http://mrdoob.com/
  7268. */
  7269. THREE.Uniform = function ( value ) {
  7270. if ( typeof value === 'string' ) {
  7271. console.warn( 'THREE.Uniform: Type parameter is no longer needed.' );
  7272. value = arguments[ 1 ];
  7273. }
  7274. this.value = value;
  7275. this.dynamic = false;
  7276. };
  7277. THREE.Uniform.prototype = {
  7278. constructor: THREE.Uniform,
  7279. onUpdate: function ( callback ) {
  7280. this.dynamic = true;
  7281. this.onUpdateCallback = callback;
  7282. return this;
  7283. }
  7284. };
  7285. // File:src/animation/AnimationAction.js
  7286. /**
  7287. *
  7288. * Action provided by AnimationMixer for scheduling clip playback on specific
  7289. * objects.
  7290. *
  7291. * @author Ben Houston / http://clara.io/
  7292. * @author David Sarno / http://lighthaus.us/
  7293. * @author tschw
  7294. *
  7295. */
  7296. THREE.AnimationAction = function() {
  7297. throw new Error( "THREE.AnimationAction: " +
  7298. "Use mixer.clipAction for construction." );
  7299. };
  7300. THREE.AnimationAction._new =
  7301. function AnimationAction( mixer, clip, localRoot ) {
  7302. this._mixer = mixer;
  7303. this._clip = clip;
  7304. this._localRoot = localRoot || null;
  7305. var tracks = clip.tracks,
  7306. nTracks = tracks.length,
  7307. interpolants = new Array( nTracks );
  7308. var interpolantSettings = {
  7309. endingStart: THREE.ZeroCurvatureEnding,
  7310. endingEnd: THREE.ZeroCurvatureEnding
  7311. };
  7312. for ( var i = 0; i !== nTracks; ++ i ) {
  7313. var interpolant = tracks[ i ].createInterpolant( null );
  7314. interpolants[ i ] = interpolant;
  7315. interpolant.settings = interpolantSettings;
  7316. }
  7317. this._interpolantSettings = interpolantSettings;
  7318. this._interpolants = interpolants; // bound by the mixer
  7319. // inside: PropertyMixer (managed by the mixer)
  7320. this._propertyBindings = new Array( nTracks );
  7321. this._cacheIndex = null; // for the memory manager
  7322. this._byClipCacheIndex = null; // for the memory manager
  7323. this._timeScaleInterpolant = null;
  7324. this._weightInterpolant = null;
  7325. this.loop = THREE.LoopRepeat;
  7326. this._loopCount = -1;
  7327. // global mixer time when the action is to be started
  7328. // it's set back to 'null' upon start of the action
  7329. this._startTime = null;
  7330. // scaled local time of the action
  7331. // gets clamped or wrapped to 0..clip.duration according to loop
  7332. this.time = 0;
  7333. this.timeScale = 1;
  7334. this._effectiveTimeScale = 1;
  7335. this.weight = 1;
  7336. this._effectiveWeight = 1;
  7337. this.repetitions = Infinity; // no. of repetitions when looping
  7338. this.paused = false; // false -> zero effective time scale
  7339. this.enabled = true; // true -> zero effective weight
  7340. this.clampWhenFinished = false; // keep feeding the last frame?
  7341. this.zeroSlopeAtStart = true; // for smooth interpolation w/o separate
  7342. this.zeroSlopeAtEnd = true; // clips for start, loop and end
  7343. };
  7344. THREE.AnimationAction._new.prototype = {
  7345. constructor: THREE.AnimationAction._new,
  7346. // State & Scheduling
  7347. play: function() {
  7348. this._mixer._activateAction( this );
  7349. return this;
  7350. },
  7351. stop: function() {
  7352. this._mixer._deactivateAction( this );
  7353. return this.reset();
  7354. },
  7355. reset: function() {
  7356. this.paused = false;
  7357. this.enabled = true;
  7358. this.time = 0; // restart clip
  7359. this._loopCount = -1; // forget previous loops
  7360. this._startTime = null; // forget scheduling
  7361. return this.stopFading().stopWarping();
  7362. },
  7363. isRunning: function() {
  7364. var start = this._startTime;
  7365. return this.enabled && ! this.paused && this.timeScale !== 0 &&
  7366. this._startTime === null && this._mixer._isActiveAction( this );
  7367. },
  7368. // return true when play has been called
  7369. isScheduled: function() {
  7370. return this._mixer._isActiveAction( this );
  7371. },
  7372. startAt: function( time ) {
  7373. this._startTime = time;
  7374. return this;
  7375. },
  7376. setLoop: function( mode, repetitions ) {
  7377. this.loop = mode;
  7378. this.repetitions = repetitions;
  7379. return this;
  7380. },
  7381. // Weight
  7382. // set the weight stopping any scheduled fading
  7383. // although .enabled = false yields an effective weight of zero, this
  7384. // method does *not* change .enabled, because it would be confusing
  7385. setEffectiveWeight: function( weight ) {
  7386. this.weight = weight;
  7387. // note: same logic as when updated at runtime
  7388. this._effectiveWeight = this.enabled ? weight : 0;
  7389. return this.stopFading();
  7390. },
  7391. // return the weight considering fading and .enabled
  7392. getEffectiveWeight: function() {
  7393. return this._effectiveWeight;
  7394. },
  7395. fadeIn: function( duration ) {
  7396. return this._scheduleFading( duration, 0, 1 );
  7397. },
  7398. fadeOut: function( duration ) {
  7399. return this._scheduleFading( duration, 1, 0 );
  7400. },
  7401. crossFadeFrom: function( fadeOutAction, duration, warp ) {
  7402. var mixer = this._mixer;
  7403. fadeOutAction.fadeOut( duration );
  7404. this.fadeIn( duration );
  7405. if( warp ) {
  7406. var fadeInDuration = this._clip.duration,
  7407. fadeOutDuration = fadeOutAction._clip.duration,
  7408. startEndRatio = fadeOutDuration / fadeInDuration,
  7409. endStartRatio = fadeInDuration / fadeOutDuration;
  7410. fadeOutAction.warp( 1.0, startEndRatio, duration );
  7411. this.warp( endStartRatio, 1.0, duration );
  7412. }
  7413. return this;
  7414. },
  7415. crossFadeTo: function( fadeInAction, duration, warp ) {
  7416. return fadeInAction.crossFadeFrom( this, duration, warp );
  7417. },
  7418. stopFading: function() {
  7419. var weightInterpolant = this._weightInterpolant;
  7420. if ( weightInterpolant !== null ) {
  7421. this._weightInterpolant = null;
  7422. this._mixer._takeBackControlInterpolant( weightInterpolant );
  7423. }
  7424. return this;
  7425. },
  7426. // Time Scale Control
  7427. // set the weight stopping any scheduled warping
  7428. // although .paused = true yields an effective time scale of zero, this
  7429. // method does *not* change .paused, because it would be confusing
  7430. setEffectiveTimeScale: function( timeScale ) {
  7431. this.timeScale = timeScale;
  7432. this._effectiveTimeScale = this.paused ? 0 :timeScale;
  7433. return this.stopWarping();
  7434. },
  7435. // return the time scale considering warping and .paused
  7436. getEffectiveTimeScale: function() {
  7437. return this._effectiveTimeScale;
  7438. },
  7439. setDuration: function( duration ) {
  7440. this.timeScale = this._clip.duration / duration;
  7441. return this.stopWarping();
  7442. },
  7443. syncWith: function( action ) {
  7444. this.time = action.time;
  7445. this.timeScale = action.timeScale;
  7446. return this.stopWarping();
  7447. },
  7448. halt: function( duration ) {
  7449. return this.warp( this._effectiveTimeScale, 0, duration );
  7450. },
  7451. warp: function( startTimeScale, endTimeScale, duration ) {
  7452. var mixer = this._mixer, now = mixer.time,
  7453. interpolant = this._timeScaleInterpolant,
  7454. timeScale = this.timeScale;
  7455. if ( interpolant === null ) {
  7456. interpolant = mixer._lendControlInterpolant(),
  7457. this._timeScaleInterpolant = interpolant;
  7458. }
  7459. var times = interpolant.parameterPositions,
  7460. values = interpolant.sampleValues;
  7461. times[ 0 ] = now;
  7462. times[ 1 ] = now + duration;
  7463. values[ 0 ] = startTimeScale / timeScale;
  7464. values[ 1 ] = endTimeScale / timeScale;
  7465. return this;
  7466. },
  7467. stopWarping: function() {
  7468. var timeScaleInterpolant = this._timeScaleInterpolant;
  7469. if ( timeScaleInterpolant !== null ) {
  7470. this._timeScaleInterpolant = null;
  7471. this._mixer._takeBackControlInterpolant( timeScaleInterpolant );
  7472. }
  7473. return this;
  7474. },
  7475. // Object Accessors
  7476. getMixer: function() {
  7477. return this._mixer;
  7478. },
  7479. getClip: function() {
  7480. return this._clip;
  7481. },
  7482. getRoot: function() {
  7483. return this._localRoot || this._mixer._root;
  7484. },
  7485. // Interna
  7486. _update: function( time, deltaTime, timeDirection, accuIndex ) {
  7487. // called by the mixer
  7488. var startTime = this._startTime;
  7489. if ( startTime !== null ) {
  7490. // check for scheduled start of action
  7491. var timeRunning = ( time - startTime ) * timeDirection;
  7492. if ( timeRunning < 0 || timeDirection === 0 ) {
  7493. return; // yet to come / don't decide when delta = 0
  7494. }
  7495. // start
  7496. this._startTime = null; // unschedule
  7497. deltaTime = timeDirection * timeRunning;
  7498. }
  7499. // apply time scale and advance time
  7500. deltaTime *= this._updateTimeScale( time );
  7501. var clipTime = this._updateTime( deltaTime );
  7502. // note: _updateTime may disable the action resulting in
  7503. // an effective weight of 0
  7504. var weight = this._updateWeight( time );
  7505. if ( weight > 0 ) {
  7506. var interpolants = this._interpolants;
  7507. var propertyMixers = this._propertyBindings;
  7508. for ( var j = 0, m = interpolants.length; j !== m; ++ j ) {
  7509. interpolants[ j ].evaluate( clipTime );
  7510. propertyMixers[ j ].accumulate( accuIndex, weight );
  7511. }
  7512. }
  7513. },
  7514. _updateWeight: function( time ) {
  7515. var weight = 0;
  7516. if ( this.enabled ) {
  7517. weight = this.weight;
  7518. var interpolant = this._weightInterpolant;
  7519. if ( interpolant !== null ) {
  7520. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  7521. weight *= interpolantValue;
  7522. if ( time > interpolant.parameterPositions[ 1 ] ) {
  7523. this.stopFading();
  7524. if ( interpolantValue === 0 ) {
  7525. // faded out, disable
  7526. this.enabled = false;
  7527. }
  7528. }
  7529. }
  7530. }
  7531. this._effectiveWeight = weight;
  7532. return weight;
  7533. },
  7534. _updateTimeScale: function( time ) {
  7535. var timeScale = 0;
  7536. if ( ! this.paused ) {
  7537. timeScale = this.timeScale;
  7538. var interpolant = this._timeScaleInterpolant;
  7539. if ( interpolant !== null ) {
  7540. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  7541. timeScale *= interpolantValue;
  7542. if ( time > interpolant.parameterPositions[ 1 ] ) {
  7543. this.stopWarping();
  7544. if ( timeScale === 0 ) {
  7545. // motion has halted, pause
  7546. this.paused = true;
  7547. } else {
  7548. // warp done - apply final time scale
  7549. this.timeScale = timeScale;
  7550. }
  7551. }
  7552. }
  7553. }
  7554. this._effectiveTimeScale = timeScale;
  7555. return timeScale;
  7556. },
  7557. _updateTime: function( deltaTime ) {
  7558. var time = this.time + deltaTime;
  7559. if ( deltaTime === 0 ) return time;
  7560. var duration = this._clip.duration,
  7561. loop = this.loop,
  7562. loopCount = this._loopCount;
  7563. if ( loop === THREE.LoopOnce ) {
  7564. if ( loopCount === -1 ) {
  7565. // just started
  7566. this.loopCount = 0;
  7567. this._setEndings( true, true, false );
  7568. }
  7569. handle_stop: {
  7570. if ( time >= duration ) {
  7571. time = duration;
  7572. } else if ( time < 0 ) {
  7573. time = 0;
  7574. } else break handle_stop;
  7575. if ( this.clampWhenFinished ) this.paused = true;
  7576. else this.enabled = false;
  7577. this._mixer.dispatchEvent( {
  7578. type: 'finished', action: this,
  7579. direction: deltaTime < 0 ? -1 : 1
  7580. } );
  7581. }
  7582. } else { // repetitive Repeat or PingPong
  7583. var pingPong = ( loop === THREE.LoopPingPong );
  7584. if ( loopCount === -1 ) {
  7585. // just started
  7586. if ( deltaTime >= 0 ) {
  7587. loopCount = 0;
  7588. this._setEndings(
  7589. true, this.repetitions === 0, pingPong );
  7590. } else {
  7591. // when looping in reverse direction, the initial
  7592. // transition through zero counts as a repetition,
  7593. // so leave loopCount at -1
  7594. this._setEndings(
  7595. this.repetitions === 0, true, pingPong );
  7596. }
  7597. }
  7598. if ( time >= duration || time < 0 ) {
  7599. // wrap around
  7600. var loopDelta = Math.floor( time / duration ); // signed
  7601. time -= duration * loopDelta;
  7602. loopCount += Math.abs( loopDelta );
  7603. var pending = this.repetitions - loopCount;
  7604. if ( pending < 0 ) {
  7605. // have to stop (switch state, clamp time, fire event)
  7606. if ( this.clampWhenFinished ) this.paused = true;
  7607. else this.enabled = false;
  7608. time = deltaTime > 0 ? duration : 0;
  7609. this._mixer.dispatchEvent( {
  7610. type: 'finished', action: this,
  7611. direction: deltaTime > 0 ? 1 : -1
  7612. } );
  7613. } else {
  7614. // keep running
  7615. if ( pending === 0 ) {
  7616. // entering the last round
  7617. var atStart = deltaTime < 0;
  7618. this._setEndings( atStart, ! atStart, pingPong );
  7619. } else {
  7620. this._setEndings( false, false, pingPong );
  7621. }
  7622. this._loopCount = loopCount;
  7623. this._mixer.dispatchEvent( {
  7624. type: 'loop', action: this, loopDelta: loopDelta
  7625. } );
  7626. }
  7627. }
  7628. if ( pingPong && ( loopCount & 1 ) === 1 ) {
  7629. // invert time for the "pong round"
  7630. this.time = time;
  7631. return duration - time;
  7632. }
  7633. }
  7634. this.time = time;
  7635. return time;
  7636. },
  7637. _setEndings: function( atStart, atEnd, pingPong ) {
  7638. var settings = this._interpolantSettings;
  7639. if ( pingPong ) {
  7640. settings.endingStart = THREE.ZeroSlopeEnding;
  7641. settings.endingEnd = THREE.ZeroSlopeEnding;
  7642. } else {
  7643. // assuming for LoopOnce atStart == atEnd == true
  7644. if ( atStart ) {
  7645. settings.endingStart = this.zeroSlopeAtStart ?
  7646. THREE.ZeroSlopeEnding : THREE.ZeroCurvatureEnding;
  7647. } else {
  7648. settings.endingStart = THREE.WrapAroundEnding;
  7649. }
  7650. if ( atEnd ) {
  7651. settings.endingEnd = this.zeroSlopeAtEnd ?
  7652. THREE.ZeroSlopeEnding : THREE.ZeroCurvatureEnding;
  7653. } else {
  7654. settings.endingEnd = THREE.WrapAroundEnding;
  7655. }
  7656. }
  7657. },
  7658. _scheduleFading: function( duration, weightNow, weightThen ) {
  7659. var mixer = this._mixer, now = mixer.time,
  7660. interpolant = this._weightInterpolant;
  7661. if ( interpolant === null ) {
  7662. interpolant = mixer._lendControlInterpolant(),
  7663. this._weightInterpolant = interpolant;
  7664. }
  7665. var times = interpolant.parameterPositions,
  7666. values = interpolant.sampleValues;
  7667. times[ 0 ] = now; values[ 0 ] = weightNow;
  7668. times[ 1 ] = now + duration; values[ 1 ] = weightThen;
  7669. return this;
  7670. }
  7671. };
  7672. // File:src/animation/AnimationClip.js
  7673. /**
  7674. *
  7675. * Reusable set of Tracks that represent an animation.
  7676. *
  7677. * @author Ben Houston / http://clara.io/
  7678. * @author David Sarno / http://lighthaus.us/
  7679. */
  7680. THREE.AnimationClip = function ( name, duration, tracks ) {
  7681. this.name = name;
  7682. this.tracks = tracks;
  7683. this.duration = ( duration !== undefined ) ? duration : -1;
  7684. this.uuid = THREE.Math.generateUUID();
  7685. // this means it should figure out its duration by scanning the tracks
  7686. if ( this.duration < 0 ) {
  7687. this.resetDuration();
  7688. }
  7689. // maybe only do these on demand, as doing them here could potentially slow down loading
  7690. // but leaving these here during development as this ensures a lot of testing of these functions
  7691. this.trim();
  7692. this.optimize();
  7693. };
  7694. THREE.AnimationClip.prototype = {
  7695. constructor: THREE.AnimationClip,
  7696. resetDuration: function() {
  7697. var tracks = this.tracks,
  7698. duration = 0;
  7699. for ( var i = 0, n = tracks.length; i !== n; ++ i ) {
  7700. var track = this.tracks[ i ];
  7701. duration = Math.max(
  7702. duration, track.times[ track.times.length - 1 ] );
  7703. }
  7704. this.duration = duration;
  7705. },
  7706. trim: function() {
  7707. for ( var i = 0; i < this.tracks.length; i ++ ) {
  7708. this.tracks[ i ].trim( 0, this.duration );
  7709. }
  7710. return this;
  7711. },
  7712. optimize: function() {
  7713. for ( var i = 0; i < this.tracks.length; i ++ ) {
  7714. this.tracks[ i ].optimize();
  7715. }
  7716. return this;
  7717. }
  7718. };
  7719. // Static methods:
  7720. Object.assign( THREE.AnimationClip, {
  7721. parse: function( json ) {
  7722. var tracks = [],
  7723. jsonTracks = json.tracks,
  7724. frameTime = 1.0 / ( json.fps || 1.0 );
  7725. for ( var i = 0, n = jsonTracks.length; i !== n; ++ i ) {
  7726. tracks.push( THREE.KeyframeTrack.parse( jsonTracks[ i ] ).scale( frameTime ) );
  7727. }
  7728. return new THREE.AnimationClip( json.name, json.duration, tracks );
  7729. },
  7730. toJSON: function( clip ) {
  7731. var tracks = [],
  7732. clipTracks = clip.tracks;
  7733. var json = {
  7734. 'name': clip.name,
  7735. 'duration': clip.duration,
  7736. 'tracks': tracks
  7737. };
  7738. for ( var i = 0, n = clipTracks.length; i !== n; ++ i ) {
  7739. tracks.push( THREE.KeyframeTrack.toJSON( clipTracks[ i ] ) );
  7740. }
  7741. return json;
  7742. },
  7743. CreateFromMorphTargetSequence: function( name, morphTargetSequence, fps, noLoop ) {
  7744. var numMorphTargets = morphTargetSequence.length;
  7745. var tracks = [];
  7746. for ( var i = 0; i < numMorphTargets; i ++ ) {
  7747. var times = [];
  7748. var values = [];
  7749. times.push(
  7750. ( i + numMorphTargets - 1 ) % numMorphTargets,
  7751. i,
  7752. ( i + 1 ) % numMorphTargets );
  7753. values.push( 0, 1, 0 );
  7754. var order = THREE.AnimationUtils.getKeyframeOrder( times );
  7755. times = THREE.AnimationUtils.sortedArray( times, 1, order );
  7756. values = THREE.AnimationUtils.sortedArray( values, 1, order );
  7757. // if there is a key at the first frame, duplicate it as the
  7758. // last frame as well for perfect loop.
  7759. if ( ! noLoop && times[ 0 ] === 0 ) {
  7760. times.push( numMorphTargets );
  7761. values.push( values[ 0 ] );
  7762. }
  7763. tracks.push(
  7764. new THREE.NumberKeyframeTrack(
  7765. '.morphTargetInfluences[' + morphTargetSequence[ i ].name + ']',
  7766. times, values
  7767. ).scale( 1.0 / fps ) );
  7768. }
  7769. return new THREE.AnimationClip( name, -1, tracks );
  7770. },
  7771. findByName: function( objectOrClipArray, name ) {
  7772. var clipArray = objectOrClipArray;
  7773. if ( ! Array.isArray( objectOrClipArray ) ) {
  7774. var o = objectOrClipArray;
  7775. clipArray = o.geometry && o.geometry.animations || o.animations;
  7776. }
  7777. for ( var i = 0; i < clipArray.length; i ++ ) {
  7778. if ( clipArray[ i ].name === name ) {
  7779. return clipArray[ i ];
  7780. }
  7781. }
  7782. return null;
  7783. },
  7784. CreateClipsFromMorphTargetSequences: function( morphTargets, fps, noLoop ) {
  7785. var animationToMorphTargets = {};
  7786. // tested with https://regex101.com/ on trick sequences
  7787. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  7788. var pattern = /^([\w-]*?)([\d]+)$/;
  7789. // sort morph target names into animation groups based
  7790. // patterns like Walk_001, Walk_002, Run_001, Run_002
  7791. for ( var i = 0, il = morphTargets.length; i < il; i ++ ) {
  7792. var morphTarget = morphTargets[ i ];
  7793. var parts = morphTarget.name.match( pattern );
  7794. if ( parts && parts.length > 1 ) {
  7795. var name = parts[ 1 ];
  7796. var animationMorphTargets = animationToMorphTargets[ name ];
  7797. if ( ! animationMorphTargets ) {
  7798. animationToMorphTargets[ name ] = animationMorphTargets = [];
  7799. }
  7800. animationMorphTargets.push( morphTarget );
  7801. }
  7802. }
  7803. var clips = [];
  7804. for ( var name in animationToMorphTargets ) {
  7805. clips.push( THREE.AnimationClip.CreateFromMorphTargetSequence( name, animationToMorphTargets[ name ], fps, noLoop ) );
  7806. }
  7807. return clips;
  7808. },
  7809. // parse the animation.hierarchy format
  7810. parseAnimation: function( animation, bones, nodeName ) {
  7811. if ( ! animation ) {
  7812. console.error( " no animation in JSONLoader data" );
  7813. return null;
  7814. }
  7815. var addNonemptyTrack = function(
  7816. trackType, trackName, animationKeys, propertyName, destTracks ) {
  7817. // only return track if there are actually keys.
  7818. if ( animationKeys.length !== 0 ) {
  7819. var times = [];
  7820. var values = [];
  7821. THREE.AnimationUtils.flattenJSON(
  7822. animationKeys, times, values, propertyName );
  7823. // empty keys are filtered out, so check again
  7824. if ( times.length !== 0 ) {
  7825. destTracks.push( new trackType( trackName, times, values ) );
  7826. }
  7827. }
  7828. };
  7829. var tracks = [];
  7830. var clipName = animation.name || 'default';
  7831. // automatic length determination in AnimationClip.
  7832. var duration = animation.length || -1;
  7833. var fps = animation.fps || 30;
  7834. var hierarchyTracks = animation.hierarchy || [];
  7835. for ( var h = 0; h < hierarchyTracks.length; h ++ ) {
  7836. var animationKeys = hierarchyTracks[ h ].keys;
  7837. // skip empty tracks
  7838. if ( ! animationKeys || animationKeys.length === 0 ) continue;
  7839. // process morph targets in a way exactly compatible
  7840. // with AnimationHandler.init( animation )
  7841. if ( animationKeys[0].morphTargets ) {
  7842. // figure out all morph targets used in this track
  7843. var morphTargetNames = {};
  7844. for ( var k = 0; k < animationKeys.length; k ++ ) {
  7845. if ( animationKeys[k].morphTargets ) {
  7846. for ( var m = 0; m < animationKeys[k].morphTargets.length; m ++ ) {
  7847. morphTargetNames[ animationKeys[k].morphTargets[m] ] = -1;
  7848. }
  7849. }
  7850. }
  7851. // create a track for each morph target with all zero
  7852. // morphTargetInfluences except for the keys in which
  7853. // the morphTarget is named.
  7854. for ( var morphTargetName in morphTargetNames ) {
  7855. var times = [];
  7856. var values = [];
  7857. for ( var m = 0;
  7858. m !== animationKeys[k].morphTargets.length; ++ m ) {
  7859. var animationKey = animationKeys[k];
  7860. times.push( animationKey.time );
  7861. values.push( ( animationKey.morphTarget === morphTargetName ) ? 1 : 0 );
  7862. }
  7863. tracks.push( new THREE.NumberKeyframeTrack(
  7864. '.morphTargetInfluence[' + morphTargetName + ']', times, values ) );
  7865. }
  7866. duration = morphTargetNames.length * ( fps || 1.0 );
  7867. } else {
  7868. // ...assume skeletal animation
  7869. var boneName = '.bones[' + bones[ h ].name + ']';
  7870. addNonemptyTrack(
  7871. THREE.VectorKeyframeTrack, boneName + '.position',
  7872. animationKeys, 'pos', tracks );
  7873. addNonemptyTrack(
  7874. THREE.QuaternionKeyframeTrack, boneName + '.quaternion',
  7875. animationKeys, 'rot', tracks );
  7876. addNonemptyTrack(
  7877. THREE.VectorKeyframeTrack, boneName + '.scale',
  7878. animationKeys, 'scl', tracks );
  7879. }
  7880. }
  7881. if ( tracks.length === 0 ) {
  7882. return null;
  7883. }
  7884. var clip = new THREE.AnimationClip( clipName, duration, tracks );
  7885. return clip;
  7886. }
  7887. } );
  7888. // File:src/animation/AnimationMixer.js
  7889. /**
  7890. *
  7891. * Player for AnimationClips.
  7892. *
  7893. *
  7894. * @author Ben Houston / http://clara.io/
  7895. * @author David Sarno / http://lighthaus.us/
  7896. * @author tschw
  7897. */
  7898. THREE.AnimationMixer = function( root ) {
  7899. this._root = root;
  7900. this._initMemoryManager();
  7901. this._accuIndex = 0;
  7902. this.time = 0;
  7903. this.timeScale = 1.0;
  7904. };
  7905. Object.assign( THREE.AnimationMixer.prototype, THREE.EventDispatcher.prototype, {
  7906. // return an action for a clip optionally using a custom root target
  7907. // object (this method allocates a lot of dynamic memory in case a
  7908. // previously unknown clip/root combination is specified)
  7909. clipAction: function( clip, optionalRoot ) {
  7910. var root = optionalRoot || this._root,
  7911. rootUuid = root.uuid,
  7912. clipObject = typeof clip === 'string' ?
  7913. THREE.AnimationClip.findByName( root, clip ) : clip,
  7914. clipUuid = clipObject !== null ? clipObject.uuid : clip,
  7915. actionsForClip = this._actionsByClip[ clipUuid ],
  7916. prototypeAction = null;
  7917. if ( actionsForClip !== undefined ) {
  7918. var existingAction =
  7919. actionsForClip.actionByRoot[ rootUuid ];
  7920. if ( existingAction !== undefined ) {
  7921. return existingAction;
  7922. }
  7923. // we know the clip, so we don't have to parse all
  7924. // the bindings again but can just copy
  7925. prototypeAction = actionsForClip.knownActions[ 0 ];
  7926. // also, take the clip from the prototype action
  7927. if ( clipObject === null )
  7928. clipObject = prototypeAction._clip;
  7929. }
  7930. // clip must be known when specified via string
  7931. if ( clipObject === null ) return null;
  7932. // allocate all resources required to run it
  7933. var newAction = new THREE.
  7934. AnimationMixer._Action( this, clipObject, optionalRoot );
  7935. this._bindAction( newAction, prototypeAction );
  7936. // and make the action known to the memory manager
  7937. this._addInactiveAction( newAction, clipUuid, rootUuid );
  7938. return newAction;
  7939. },
  7940. // get an existing action
  7941. existingAction: function( clip, optionalRoot ) {
  7942. var root = optionalRoot || this._root,
  7943. rootUuid = root.uuid,
  7944. clipObject = typeof clip === 'string' ?
  7945. THREE.AnimationClip.findByName( root, clip ) : clip,
  7946. clipUuid = clipObject ? clipObject.uuid : clip,
  7947. actionsForClip = this._actionsByClip[ clipUuid ];
  7948. if ( actionsForClip !== undefined ) {
  7949. return actionsForClip.actionByRoot[ rootUuid ] || null;
  7950. }
  7951. return null;
  7952. },
  7953. // deactivates all previously scheduled actions
  7954. stopAllAction: function() {
  7955. var actions = this._actions,
  7956. nActions = this._nActiveActions,
  7957. bindings = this._bindings,
  7958. nBindings = this._nActiveBindings;
  7959. this._nActiveActions = 0;
  7960. this._nActiveBindings = 0;
  7961. for ( var i = 0; i !== nActions; ++ i ) {
  7962. actions[ i ].reset();
  7963. }
  7964. for ( var i = 0; i !== nBindings; ++ i ) {
  7965. bindings[ i ].useCount = 0;
  7966. }
  7967. return this;
  7968. },
  7969. // advance the time and update apply the animation
  7970. update: function( deltaTime ) {
  7971. deltaTime *= this.timeScale;
  7972. var actions = this._actions,
  7973. nActions = this._nActiveActions,
  7974. time = this.time += deltaTime,
  7975. timeDirection = Math.sign( deltaTime ),
  7976. accuIndex = this._accuIndex ^= 1;
  7977. // run active actions
  7978. for ( var i = 0; i !== nActions; ++ i ) {
  7979. var action = actions[ i ];
  7980. if ( action.enabled ) {
  7981. action._update( time, deltaTime, timeDirection, accuIndex );
  7982. }
  7983. }
  7984. // update scene graph
  7985. var bindings = this._bindings,
  7986. nBindings = this._nActiveBindings;
  7987. for ( var i = 0; i !== nBindings; ++ i ) {
  7988. bindings[ i ].apply( accuIndex );
  7989. }
  7990. return this;
  7991. },
  7992. // return this mixer's root target object
  7993. getRoot: function() {
  7994. return this._root;
  7995. },
  7996. // free all resources specific to a particular clip
  7997. uncacheClip: function( clip ) {
  7998. var actions = this._actions,
  7999. clipUuid = clip.uuid,
  8000. actionsByClip = this._actionsByClip,
  8001. actionsForClip = actionsByClip[ clipUuid ];
  8002. if ( actionsForClip !== undefined ) {
  8003. // note: just calling _removeInactiveAction would mess up the
  8004. // iteration state and also require updating the state we can
  8005. // just throw away
  8006. var actionsToRemove = actionsForClip.knownActions;
  8007. for ( var i = 0, n = actionsToRemove.length; i !== n; ++ i ) {
  8008. var action = actionsToRemove[ i ];
  8009. this._deactivateAction( action );
  8010. var cacheIndex = action._cacheIndex,
  8011. lastInactiveAction = actions[ actions.length - 1 ];
  8012. action._cacheIndex = null;
  8013. action._byClipCacheIndex = null;
  8014. lastInactiveAction._cacheIndex = cacheIndex;
  8015. actions[ cacheIndex ] = lastInactiveAction;
  8016. actions.pop();
  8017. this._removeInactiveBindingsForAction( action );
  8018. }
  8019. delete actionsByClip[ clipUuid ];
  8020. }
  8021. },
  8022. // free all resources specific to a particular root target object
  8023. uncacheRoot: function( root ) {
  8024. var rootUuid = root.uuid,
  8025. actionsByClip = this._actionsByClip;
  8026. for ( var clipUuid in actionsByClip ) {
  8027. var actionByRoot = actionsByClip[ clipUuid ].actionByRoot,
  8028. action = actionByRoot[ rootUuid ];
  8029. if ( action !== undefined ) {
  8030. this._deactivateAction( action );
  8031. this._removeInactiveAction( action );
  8032. }
  8033. }
  8034. var bindingsByRoot = this._bindingsByRootAndName,
  8035. bindingByName = bindingsByRoot[ rootUuid ];
  8036. if ( bindingByName !== undefined ) {
  8037. for ( var trackName in bindingByName ) {
  8038. var binding = bindingByName[ trackName ];
  8039. binding.restoreOriginalState();
  8040. this._removeInactiveBinding( binding );
  8041. }
  8042. }
  8043. },
  8044. // remove a targeted clip from the cache
  8045. uncacheAction: function( clip, optionalRoot ) {
  8046. var action = this.existingAction( clip, optionalRoot );
  8047. if ( action !== null ) {
  8048. this._deactivateAction( action );
  8049. this._removeInactiveAction( action );
  8050. }
  8051. }
  8052. } );
  8053. THREE.AnimationMixer._Action = THREE.AnimationAction._new;
  8054. // Implementation details:
  8055. Object.assign( THREE.AnimationMixer.prototype, {
  8056. _bindAction: function( action, prototypeAction ) {
  8057. var root = action._localRoot || this._root,
  8058. tracks = action._clip.tracks,
  8059. nTracks = tracks.length,
  8060. bindings = action._propertyBindings,
  8061. interpolants = action._interpolants,
  8062. rootUuid = root.uuid,
  8063. bindingsByRoot = this._bindingsByRootAndName,
  8064. bindingsByName = bindingsByRoot[ rootUuid ];
  8065. if ( bindingsByName === undefined ) {
  8066. bindingsByName = {};
  8067. bindingsByRoot[ rootUuid ] = bindingsByName;
  8068. }
  8069. for ( var i = 0; i !== nTracks; ++ i ) {
  8070. var track = tracks[ i ],
  8071. trackName = track.name,
  8072. binding = bindingsByName[ trackName ];
  8073. if ( binding !== undefined ) {
  8074. bindings[ i ] = binding;
  8075. } else {
  8076. binding = bindings[ i ];
  8077. if ( binding !== undefined ) {
  8078. // existing binding, make sure the cache knows
  8079. if ( binding._cacheIndex === null ) {
  8080. ++ binding.referenceCount;
  8081. this._addInactiveBinding( binding, rootUuid, trackName );
  8082. }
  8083. continue;
  8084. }
  8085. var path = prototypeAction && prototypeAction.
  8086. _propertyBindings[ i ].binding.parsedPath;
  8087. binding = new THREE.PropertyMixer(
  8088. THREE.PropertyBinding.create( root, trackName, path ),
  8089. track.ValueTypeName, track.getValueSize() );
  8090. ++ binding.referenceCount;
  8091. this._addInactiveBinding( binding, rootUuid, trackName );
  8092. bindings[ i ] = binding;
  8093. }
  8094. interpolants[ i ].resultBuffer = binding.buffer;
  8095. }
  8096. },
  8097. _activateAction: function( action ) {
  8098. if ( ! this._isActiveAction( action ) ) {
  8099. if ( action._cacheIndex === null ) {
  8100. // this action has been forgotten by the cache, but the user
  8101. // appears to be still using it -> rebind
  8102. var rootUuid = ( action._localRoot || this._root ).uuid,
  8103. clipUuid = action._clip.uuid,
  8104. actionsForClip = this._actionsByClip[ clipUuid ];
  8105. this._bindAction( action,
  8106. actionsForClip && actionsForClip.knownActions[ 0 ] );
  8107. this._addInactiveAction( action, clipUuid, rootUuid );
  8108. }
  8109. var bindings = action._propertyBindings;
  8110. // increment reference counts / sort out state
  8111. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  8112. var binding = bindings[ i ];
  8113. if ( binding.useCount ++ === 0 ) {
  8114. this._lendBinding( binding );
  8115. binding.saveOriginalState();
  8116. }
  8117. }
  8118. this._lendAction( action );
  8119. }
  8120. },
  8121. _deactivateAction: function( action ) {
  8122. if ( this._isActiveAction( action ) ) {
  8123. var bindings = action._propertyBindings;
  8124. // decrement reference counts / sort out state
  8125. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  8126. var binding = bindings[ i ];
  8127. if ( -- binding.useCount === 0 ) {
  8128. binding.restoreOriginalState();
  8129. this._takeBackBinding( binding );
  8130. }
  8131. }
  8132. this._takeBackAction( action );
  8133. }
  8134. },
  8135. // Memory manager
  8136. _initMemoryManager: function() {
  8137. this._actions = []; // 'nActiveActions' followed by inactive ones
  8138. this._nActiveActions = 0;
  8139. this._actionsByClip = {};
  8140. // inside:
  8141. // {
  8142. // knownActions: Array< _Action > - used as prototypes
  8143. // actionByRoot: _Action - lookup
  8144. // }
  8145. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  8146. this._nActiveBindings = 0;
  8147. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  8148. this._controlInterpolants = []; // same game as above
  8149. this._nActiveControlInterpolants = 0;
  8150. var scope = this;
  8151. this.stats = {
  8152. actions: {
  8153. get total() { return scope._actions.length; },
  8154. get inUse() { return scope._nActiveActions; }
  8155. },
  8156. bindings: {
  8157. get total() { return scope._bindings.length; },
  8158. get inUse() { return scope._nActiveBindings; }
  8159. },
  8160. controlInterpolants: {
  8161. get total() { return scope._controlInterpolants.length; },
  8162. get inUse() { return scope._nActiveControlInterpolants; }
  8163. }
  8164. };
  8165. },
  8166. // Memory management for _Action objects
  8167. _isActiveAction: function( action ) {
  8168. var index = action._cacheIndex;
  8169. return index !== null && index < this._nActiveActions;
  8170. },
  8171. _addInactiveAction: function( action, clipUuid, rootUuid ) {
  8172. var actions = this._actions,
  8173. actionsByClip = this._actionsByClip,
  8174. actionsForClip = actionsByClip[ clipUuid ];
  8175. if ( actionsForClip === undefined ) {
  8176. actionsForClip = {
  8177. knownActions: [ action ],
  8178. actionByRoot: {}
  8179. };
  8180. action._byClipCacheIndex = 0;
  8181. actionsByClip[ clipUuid ] = actionsForClip;
  8182. } else {
  8183. var knownActions = actionsForClip.knownActions;
  8184. action._byClipCacheIndex = knownActions.length;
  8185. knownActions.push( action );
  8186. }
  8187. action._cacheIndex = actions.length;
  8188. actions.push( action );
  8189. actionsForClip.actionByRoot[ rootUuid ] = action;
  8190. },
  8191. _removeInactiveAction: function( action ) {
  8192. var actions = this._actions,
  8193. lastInactiveAction = actions[ actions.length - 1 ],
  8194. cacheIndex = action._cacheIndex;
  8195. lastInactiveAction._cacheIndex = cacheIndex;
  8196. actions[ cacheIndex ] = lastInactiveAction;
  8197. actions.pop();
  8198. action._cacheIndex = null;
  8199. var clipUuid = action._clip.uuid,
  8200. actionsByClip = this._actionsByClip,
  8201. actionsForClip = actionsByClip[ clipUuid ],
  8202. knownActionsForClip = actionsForClip.knownActions,
  8203. lastKnownAction =
  8204. knownActionsForClip[ knownActionsForClip.length - 1 ],
  8205. byClipCacheIndex = action._byClipCacheIndex;
  8206. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  8207. knownActionsForClip[ byClipCacheIndex ] = lastKnownAction;
  8208. knownActionsForClip.pop();
  8209. action._byClipCacheIndex = null;
  8210. var actionByRoot = actionsForClip.actionByRoot,
  8211. rootUuid = ( actions._localRoot || this._root ).uuid;
  8212. delete actionByRoot[ rootUuid ];
  8213. if ( knownActionsForClip.length === 0 ) {
  8214. delete actionsByClip[ clipUuid ];
  8215. }
  8216. this._removeInactiveBindingsForAction( action );
  8217. },
  8218. _removeInactiveBindingsForAction: function( action ) {
  8219. var bindings = action._propertyBindings;
  8220. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  8221. var binding = bindings[ i ];
  8222. if ( -- binding.referenceCount === 0 ) {
  8223. this._removeInactiveBinding( binding );
  8224. }
  8225. }
  8226. },
  8227. _lendAction: function( action ) {
  8228. // [ active actions | inactive actions ]
  8229. // [ active actions >| inactive actions ]
  8230. // s a
  8231. // <-swap->
  8232. // a s
  8233. var actions = this._actions,
  8234. prevIndex = action._cacheIndex,
  8235. lastActiveIndex = this._nActiveActions ++,
  8236. firstInactiveAction = actions[ lastActiveIndex ];
  8237. action._cacheIndex = lastActiveIndex;
  8238. actions[ lastActiveIndex ] = action;
  8239. firstInactiveAction._cacheIndex = prevIndex;
  8240. actions[ prevIndex ] = firstInactiveAction;
  8241. },
  8242. _takeBackAction: function( action ) {
  8243. // [ active actions | inactive actions ]
  8244. // [ active actions |< inactive actions ]
  8245. // a s
  8246. // <-swap->
  8247. // s a
  8248. var actions = this._actions,
  8249. prevIndex = action._cacheIndex,
  8250. firstInactiveIndex = -- this._nActiveActions,
  8251. lastActiveAction = actions[ firstInactiveIndex ];
  8252. action._cacheIndex = firstInactiveIndex;
  8253. actions[ firstInactiveIndex ] = action;
  8254. lastActiveAction._cacheIndex = prevIndex;
  8255. actions[ prevIndex ] = lastActiveAction;
  8256. },
  8257. // Memory management for PropertyMixer objects
  8258. _addInactiveBinding: function( binding, rootUuid, trackName ) {
  8259. var bindingsByRoot = this._bindingsByRootAndName,
  8260. bindingByName = bindingsByRoot[ rootUuid ],
  8261. bindings = this._bindings;
  8262. if ( bindingByName === undefined ) {
  8263. bindingByName = {};
  8264. bindingsByRoot[ rootUuid ] = bindingByName;
  8265. }
  8266. bindingByName[ trackName ] = binding;
  8267. binding._cacheIndex = bindings.length;
  8268. bindings.push( binding );
  8269. },
  8270. _removeInactiveBinding: function( binding ) {
  8271. var bindings = this._bindings,
  8272. propBinding = binding.binding,
  8273. rootUuid = propBinding.rootNode.uuid,
  8274. trackName = propBinding.path,
  8275. bindingsByRoot = this._bindingsByRootAndName,
  8276. bindingByName = bindingsByRoot[ rootUuid ],
  8277. lastInactiveBinding = bindings[ bindings.length - 1 ],
  8278. cacheIndex = binding._cacheIndex;
  8279. lastInactiveBinding._cacheIndex = cacheIndex;
  8280. bindings[ cacheIndex ] = lastInactiveBinding;
  8281. bindings.pop();
  8282. delete bindingByName[ trackName ];
  8283. remove_empty_map: {
  8284. for ( var _ in bindingByName ) break remove_empty_map;
  8285. delete bindingsByRoot[ rootUuid ];
  8286. }
  8287. },
  8288. _lendBinding: function( binding ) {
  8289. var bindings = this._bindings,
  8290. prevIndex = binding._cacheIndex,
  8291. lastActiveIndex = this._nActiveBindings ++,
  8292. firstInactiveBinding = bindings[ lastActiveIndex ];
  8293. binding._cacheIndex = lastActiveIndex;
  8294. bindings[ lastActiveIndex ] = binding;
  8295. firstInactiveBinding._cacheIndex = prevIndex;
  8296. bindings[ prevIndex ] = firstInactiveBinding;
  8297. },
  8298. _takeBackBinding: function( binding ) {
  8299. var bindings = this._bindings,
  8300. prevIndex = binding._cacheIndex,
  8301. firstInactiveIndex = -- this._nActiveBindings,
  8302. lastActiveBinding = bindings[ firstInactiveIndex ];
  8303. binding._cacheIndex = firstInactiveIndex;
  8304. bindings[ firstInactiveIndex ] = binding;
  8305. lastActiveBinding._cacheIndex = prevIndex;
  8306. bindings[ prevIndex ] = lastActiveBinding;
  8307. },
  8308. // Memory management of Interpolants for weight and time scale
  8309. _lendControlInterpolant: function() {
  8310. var interpolants = this._controlInterpolants,
  8311. lastActiveIndex = this._nActiveControlInterpolants ++,
  8312. interpolant = interpolants[ lastActiveIndex ];
  8313. if ( interpolant === undefined ) {
  8314. interpolant = new THREE.LinearInterpolant(
  8315. new Float32Array( 2 ), new Float32Array( 2 ),
  8316. 1, this._controlInterpolantsResultBuffer );
  8317. interpolant.__cacheIndex = lastActiveIndex;
  8318. interpolants[ lastActiveIndex ] = interpolant;
  8319. }
  8320. return interpolant;
  8321. },
  8322. _takeBackControlInterpolant: function( interpolant ) {
  8323. var interpolants = this._controlInterpolants,
  8324. prevIndex = interpolant.__cacheIndex,
  8325. firstInactiveIndex = -- this._nActiveControlInterpolants,
  8326. lastActiveInterpolant = interpolants[ firstInactiveIndex ];
  8327. interpolant.__cacheIndex = firstInactiveIndex;
  8328. interpolants[ firstInactiveIndex ] = interpolant;
  8329. lastActiveInterpolant.__cacheIndex = prevIndex;
  8330. interpolants[ prevIndex ] = lastActiveInterpolant;
  8331. },
  8332. _controlInterpolantsResultBuffer: new Float32Array( 1 )
  8333. } );
  8334. // File:src/animation/AnimationObjectGroup.js
  8335. /**
  8336. *
  8337. * A group of objects that receives a shared animation state.
  8338. *
  8339. * Usage:
  8340. *
  8341. * - Add objects you would otherwise pass as 'root' to the
  8342. * constructor or the .clipAction method of AnimationMixer.
  8343. *
  8344. * - Instead pass this object as 'root'.
  8345. *
  8346. * - You can also add and remove objects later when the mixer
  8347. * is running.
  8348. *
  8349. * Note:
  8350. *
  8351. * Objects of this class appear as one object to the mixer,
  8352. * so cache control of the individual objects must be done
  8353. * on the group.
  8354. *
  8355. * Limitation:
  8356. *
  8357. * - The animated properties must be compatible among the
  8358. * all objects in the group.
  8359. *
  8360. * - A single property can either be controlled through a
  8361. * target group or directly, but not both.
  8362. *
  8363. * @author tschw
  8364. */
  8365. THREE.AnimationObjectGroup = function( var_args ) {
  8366. this.uuid = THREE.Math.generateUUID();
  8367. // cached objects followed by the active ones
  8368. this._objects = Array.prototype.slice.call( arguments );
  8369. this.nCachedObjects_ = 0; // threshold
  8370. // note: read by PropertyBinding.Composite
  8371. var indices = {};
  8372. this._indicesByUUID = indices; // for bookkeeping
  8373. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  8374. indices[ arguments[ i ].uuid ] = i;
  8375. }
  8376. this._paths = []; // inside: string
  8377. this._parsedPaths = []; // inside: { we don't care, here }
  8378. this._bindings = []; // inside: Array< PropertyBinding >
  8379. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  8380. var scope = this;
  8381. this.stats = {
  8382. objects: {
  8383. get total() { return scope._objects.length; },
  8384. get inUse() { return this.total - scope.nCachedObjects_; }
  8385. },
  8386. get bindingsPerObject() { return scope._bindings.length; }
  8387. };
  8388. };
  8389. THREE.AnimationObjectGroup.prototype = {
  8390. constructor: THREE.AnimationObjectGroup,
  8391. add: function( var_args ) {
  8392. var objects = this._objects,
  8393. nObjects = objects.length,
  8394. nCachedObjects = this.nCachedObjects_,
  8395. indicesByUUID = this._indicesByUUID,
  8396. paths = this._paths,
  8397. parsedPaths = this._parsedPaths,
  8398. bindings = this._bindings,
  8399. nBindings = bindings.length;
  8400. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  8401. var object = arguments[ i ],
  8402. uuid = object.uuid,
  8403. index = indicesByUUID[ uuid ];
  8404. if ( index === undefined ) {
  8405. // unknown object -> add it to the ACTIVE region
  8406. index = nObjects ++;
  8407. indicesByUUID[ uuid ] = index;
  8408. objects.push( object );
  8409. // accounting is done, now do the same for all bindings
  8410. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8411. bindings[ j ].push(
  8412. new THREE.PropertyBinding(
  8413. object, paths[ j ], parsedPaths[ j ] ) );
  8414. }
  8415. } else if ( index < nCachedObjects ) {
  8416. var knownObject = objects[ index ];
  8417. // move existing object to the ACTIVE region
  8418. var firstActiveIndex = -- nCachedObjects,
  8419. lastCachedObject = objects[ firstActiveIndex ];
  8420. indicesByUUID[ lastCachedObject.uuid ] = index;
  8421. objects[ index ] = lastCachedObject;
  8422. indicesByUUID[ uuid ] = firstActiveIndex;
  8423. objects[ firstActiveIndex ] = object;
  8424. // accounting is done, now do the same for all bindings
  8425. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8426. var bindingsForPath = bindings[ j ],
  8427. lastCached = bindingsForPath[ firstActiveIndex ],
  8428. binding = bindingsForPath[ index ];
  8429. bindingsForPath[ index ] = lastCached;
  8430. if ( binding === undefined ) {
  8431. // since we do not bother to create new bindings
  8432. // for objects that are cached, the binding may
  8433. // or may not exist
  8434. binding = new THREE.PropertyBinding(
  8435. object, paths[ j ], parsedPaths[ j ] );
  8436. }
  8437. bindingsForPath[ firstActiveIndex ] = binding;
  8438. }
  8439. } else if ( objects[ index ] !== knownObject) {
  8440. console.error( "Different objects with the same UUID " +
  8441. "detected. Clean the caches or recreate your " +
  8442. "infrastructure when reloading scenes..." );
  8443. } // else the object is already where we want it to be
  8444. } // for arguments
  8445. this.nCachedObjects_ = nCachedObjects;
  8446. },
  8447. remove: function( var_args ) {
  8448. var objects = this._objects,
  8449. nObjects = objects.length,
  8450. nCachedObjects = this.nCachedObjects_,
  8451. indicesByUUID = this._indicesByUUID,
  8452. bindings = this._bindings,
  8453. nBindings = bindings.length;
  8454. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  8455. var object = arguments[ i ],
  8456. uuid = object.uuid,
  8457. index = indicesByUUID[ uuid ];
  8458. if ( index !== undefined && index >= nCachedObjects ) {
  8459. // move existing object into the CACHED region
  8460. var lastCachedIndex = nCachedObjects ++,
  8461. firstActiveObject = objects[ lastCachedIndex ];
  8462. indicesByUUID[ firstActiveObject.uuid ] = index;
  8463. objects[ index ] = firstActiveObject;
  8464. indicesByUUID[ uuid ] = lastCachedIndex;
  8465. objects[ lastCachedIndex ] = object;
  8466. // accounting is done, now do the same for all bindings
  8467. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8468. var bindingsForPath = bindings[ j ],
  8469. firstActive = bindingsForPath[ lastCachedIndex ],
  8470. binding = bindingsForPath[ index ];
  8471. bindingsForPath[ index ] = firstActive;
  8472. bindingsForPath[ lastCachedIndex ] = binding;
  8473. }
  8474. }
  8475. } // for arguments
  8476. this.nCachedObjects_ = nCachedObjects;
  8477. },
  8478. // remove & forget
  8479. uncache: function( var_args ) {
  8480. var objects = this._objects,
  8481. nObjects = objects.length,
  8482. nCachedObjects = this.nCachedObjects_,
  8483. indicesByUUID = this._indicesByUUID,
  8484. bindings = this._bindings,
  8485. nBindings = bindings.length;
  8486. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  8487. var object = arguments[ i ],
  8488. uuid = object.uuid,
  8489. index = indicesByUUID[ uuid ];
  8490. if ( index !== undefined ) {
  8491. delete indicesByUUID[ uuid ];
  8492. if ( index < nCachedObjects ) {
  8493. // object is cached, shrink the CACHED region
  8494. var firstActiveIndex = -- nCachedObjects,
  8495. lastCachedObject = objects[ firstActiveIndex ],
  8496. lastIndex = -- nObjects,
  8497. lastObject = objects[ lastIndex ];
  8498. // last cached object takes this object's place
  8499. indicesByUUID[ lastCachedObject.uuid ] = index;
  8500. objects[ index ] = lastCachedObject;
  8501. // last object goes to the activated slot and pop
  8502. indicesByUUID[ lastObject.uuid ] = firstActiveIndex;
  8503. objects[ firstActiveIndex ] = lastObject;
  8504. objects.pop();
  8505. // accounting is done, now do the same for all bindings
  8506. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8507. var bindingsForPath = bindings[ j ],
  8508. lastCached = bindingsForPath[ firstActiveIndex ],
  8509. last = bindingsForPath[ lastIndex ];
  8510. bindingsForPath[ index ] = lastCached;
  8511. bindingsForPath[ firstActiveIndex ] = last;
  8512. bindingsForPath.pop();
  8513. }
  8514. } else {
  8515. // object is active, just swap with the last and pop
  8516. var lastIndex = -- nObjects,
  8517. lastObject = objects[ lastIndex ];
  8518. indicesByUUID[ lastObject.uuid ] = index;
  8519. objects[ index ] = lastObject;
  8520. objects.pop();
  8521. // accounting is done, now do the same for all bindings
  8522. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8523. var bindingsForPath = bindings[ j ];
  8524. bindingsForPath[ index ] = bindingsForPath[ lastIndex ];
  8525. bindingsForPath.pop();
  8526. }
  8527. } // cached or active
  8528. } // if object is known
  8529. } // for arguments
  8530. this.nCachedObjects_ = nCachedObjects;
  8531. },
  8532. // Internal interface used by befriended PropertyBinding.Composite:
  8533. subscribe_: function( path, parsedPath ) {
  8534. // returns an array of bindings for the given path that is changed
  8535. // according to the contained objects in the group
  8536. var indicesByPath = this._bindingsIndicesByPath,
  8537. index = indicesByPath[ path ],
  8538. bindings = this._bindings;
  8539. if ( index !== undefined ) return bindings[ index ];
  8540. var paths = this._paths,
  8541. parsedPaths = this._parsedPaths,
  8542. objects = this._objects,
  8543. nObjects = objects.length,
  8544. nCachedObjects = this.nCachedObjects_,
  8545. bindingsForPath = new Array( nObjects );
  8546. index = bindings.length;
  8547. indicesByPath[ path ] = index;
  8548. paths.push( path );
  8549. parsedPaths.push( parsedPath );
  8550. bindings.push( bindingsForPath );
  8551. for ( var i = nCachedObjects,
  8552. n = objects.length; i !== n; ++ i ) {
  8553. var object = objects[ i ];
  8554. bindingsForPath[ i ] =
  8555. new THREE.PropertyBinding( object, path, parsedPath );
  8556. }
  8557. return bindingsForPath;
  8558. },
  8559. unsubscribe_: function( path ) {
  8560. // tells the group to forget about a property path and no longer
  8561. // update the array previously obtained with 'subscribe_'
  8562. var indicesByPath = this._bindingsIndicesByPath,
  8563. index = indicesByPath[ path ];
  8564. if ( index !== undefined ) {
  8565. var paths = this._paths,
  8566. parsedPaths = this._parsedPaths,
  8567. bindings = this._bindings,
  8568. lastBindingsIndex = bindings.length - 1,
  8569. lastBindings = bindings[ lastBindingsIndex ],
  8570. lastBindingsPath = path[ lastBindingsIndex ];
  8571. indicesByPath[ lastBindingsPath ] = index;
  8572. bindings[ index ] = lastBindings;
  8573. bindings.pop();
  8574. parsedPaths[ index ] = parsedPaths[ lastBindingsIndex ];
  8575. parsedPaths.pop();
  8576. paths[ index ] = paths[ lastBindingsIndex ];
  8577. paths.pop();
  8578. }
  8579. }
  8580. };
  8581. // File:src/animation/AnimationUtils.js
  8582. /**
  8583. * @author tschw
  8584. * @author Ben Houston / http://clara.io/
  8585. * @author David Sarno / http://lighthaus.us/
  8586. */
  8587. THREE.AnimationUtils = {
  8588. // same as Array.prototype.slice, but also works on typed arrays
  8589. arraySlice: function( array, from, to ) {
  8590. if ( THREE.AnimationUtils.isTypedArray( array ) ) {
  8591. return new array.constructor( array.subarray( from, to ) );
  8592. }
  8593. return array.slice( from, to );
  8594. },
  8595. // converts an array to a specific type
  8596. convertArray: function( array, type, forceClone ) {
  8597. if ( ! array || // let 'undefined' and 'null' pass
  8598. ! forceClone && array.constructor === type ) return array;
  8599. if ( typeof type.BYTES_PER_ELEMENT === 'number' ) {
  8600. return new type( array ); // create typed array
  8601. }
  8602. return Array.prototype.slice.call( array ); // create Array
  8603. },
  8604. isTypedArray: function( object ) {
  8605. return ArrayBuffer.isView( object ) &&
  8606. ! ( object instanceof DataView );
  8607. },
  8608. // returns an array by which times and values can be sorted
  8609. getKeyframeOrder: function( times ) {
  8610. function compareTime( i, j ) {
  8611. return times[ i ] - times[ j ];
  8612. }
  8613. var n = times.length;
  8614. var result = new Array( n );
  8615. for ( var i = 0; i !== n; ++ i ) result[ i ] = i;
  8616. result.sort( compareTime );
  8617. return result;
  8618. },
  8619. // uses the array previously returned by 'getKeyframeOrder' to sort data
  8620. sortedArray: function( values, stride, order ) {
  8621. var nValues = values.length;
  8622. var result = new values.constructor( nValues );
  8623. for ( var i = 0, dstOffset = 0; dstOffset !== nValues; ++ i ) {
  8624. var srcOffset = order[ i ] * stride;
  8625. for ( var j = 0; j !== stride; ++ j ) {
  8626. result[ dstOffset ++ ] = values[ srcOffset + j ];
  8627. }
  8628. }
  8629. return result;
  8630. },
  8631. // function for parsing AOS keyframe formats
  8632. flattenJSON: function( jsonKeys, times, values, valuePropertyName ) {
  8633. var i = 1, key = jsonKeys[ 0 ];
  8634. while ( key !== undefined && key[ valuePropertyName ] === undefined ) {
  8635. key = jsonKeys[ i ++ ];
  8636. }
  8637. if ( key === undefined ) return; // no data
  8638. var value = key[ valuePropertyName ];
  8639. if ( value === undefined ) return; // no data
  8640. if ( Array.isArray( value ) ) {
  8641. do {
  8642. value = key[ valuePropertyName ];
  8643. if ( value !== undefined ) {
  8644. times.push( key.time );
  8645. values.push.apply( values, value ); // push all elements
  8646. }
  8647. key = jsonKeys[ i ++ ];
  8648. } while ( key !== undefined );
  8649. } else if ( value.toArray !== undefined ) {
  8650. // ...assume THREE.Math-ish
  8651. do {
  8652. value = key[ valuePropertyName ];
  8653. if ( value !== undefined ) {
  8654. times.push( key.time );
  8655. value.toArray( values, values.length );
  8656. }
  8657. key = jsonKeys[ i ++ ];
  8658. } while ( key !== undefined );
  8659. } else {
  8660. // otherwise push as-is
  8661. do {
  8662. value = key[ valuePropertyName ];
  8663. if ( value !== undefined ) {
  8664. times.push( key.time );
  8665. values.push( value );
  8666. }
  8667. key = jsonKeys[ i ++ ];
  8668. } while ( key !== undefined );
  8669. }
  8670. }
  8671. };
  8672. // File:src/animation/KeyframeTrack.js
  8673. /**
  8674. *
  8675. * A timed sequence of keyframes for a specific property.
  8676. *
  8677. *
  8678. * @author Ben Houston / http://clara.io/
  8679. * @author David Sarno / http://lighthaus.us/
  8680. * @author tschw
  8681. */
  8682. THREE.KeyframeTrack = function ( name, times, values, interpolation ) {
  8683. if( name === undefined ) throw new Error( "track name is undefined" );
  8684. if( times === undefined || times.length === 0 ) {
  8685. throw new Error( "no keyframes in track named " + name );
  8686. }
  8687. this.name = name;
  8688. this.times = THREE.AnimationUtils.convertArray( times, this.TimeBufferType );
  8689. this.values = THREE.AnimationUtils.convertArray( values, this.ValueBufferType );
  8690. this.setInterpolation( interpolation || this.DefaultInterpolation );
  8691. this.validate();
  8692. this.optimize();
  8693. };
  8694. THREE.KeyframeTrack.prototype = {
  8695. constructor: THREE.KeyframeTrack,
  8696. TimeBufferType: Float32Array,
  8697. ValueBufferType: Float32Array,
  8698. DefaultInterpolation: THREE.InterpolateLinear,
  8699. InterpolantFactoryMethodDiscrete: function( result ) {
  8700. return new THREE.DiscreteInterpolant(
  8701. this.times, this.values, this.getValueSize(), result );
  8702. },
  8703. InterpolantFactoryMethodLinear: function( result ) {
  8704. return new THREE.LinearInterpolant(
  8705. this.times, this.values, this.getValueSize(), result );
  8706. },
  8707. InterpolantFactoryMethodSmooth: function( result ) {
  8708. return new THREE.CubicInterpolant(
  8709. this.times, this.values, this.getValueSize(), result );
  8710. },
  8711. setInterpolation: function( interpolation ) {
  8712. var factoryMethod;
  8713. switch ( interpolation ) {
  8714. case THREE.InterpolateDiscrete:
  8715. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  8716. break;
  8717. case THREE.InterpolateLinear:
  8718. factoryMethod = this.InterpolantFactoryMethodLinear;
  8719. break;
  8720. case THREE.InterpolateSmooth:
  8721. factoryMethod = this.InterpolantFactoryMethodSmooth;
  8722. break;
  8723. }
  8724. if ( factoryMethod === undefined ) {
  8725. var message = "unsupported interpolation for " +
  8726. this.ValueTypeName + " keyframe track named " + this.name;
  8727. if ( this.createInterpolant === undefined ) {
  8728. // fall back to default, unless the default itself is messed up
  8729. if ( interpolation !== this.DefaultInterpolation ) {
  8730. this.setInterpolation( this.DefaultInterpolation );
  8731. } else {
  8732. throw new Error( message ); // fatal, in this case
  8733. }
  8734. }
  8735. console.warn( message );
  8736. return;
  8737. }
  8738. this.createInterpolant = factoryMethod;
  8739. },
  8740. getInterpolation: function() {
  8741. switch ( this.createInterpolant ) {
  8742. case this.InterpolantFactoryMethodDiscrete:
  8743. return THREE.InterpolateDiscrete;
  8744. case this.InterpolantFactoryMethodLinear:
  8745. return THREE.InterpolateLinear;
  8746. case this.InterpolantFactoryMethodSmooth:
  8747. return THREE.InterpolateSmooth;
  8748. }
  8749. },
  8750. getValueSize: function() {
  8751. return this.values.length / this.times.length;
  8752. },
  8753. // move all keyframes either forwards or backwards in time
  8754. shift: function( timeOffset ) {
  8755. if( timeOffset !== 0.0 ) {
  8756. var times = this.times;
  8757. for( var i = 0, n = times.length; i !== n; ++ i ) {
  8758. times[ i ] += timeOffset;
  8759. }
  8760. }
  8761. return this;
  8762. },
  8763. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  8764. scale: function( timeScale ) {
  8765. if( timeScale !== 1.0 ) {
  8766. var times = this.times;
  8767. for( var i = 0, n = times.length; i !== n; ++ i ) {
  8768. times[ i ] *= timeScale;
  8769. }
  8770. }
  8771. return this;
  8772. },
  8773. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  8774. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  8775. trim: function( startTime, endTime ) {
  8776. var times = this.times,
  8777. nKeys = times.length,
  8778. from = 0,
  8779. to = nKeys - 1;
  8780. while ( from !== nKeys && times[ from ] < startTime ) ++ from;
  8781. while ( to !== -1 && times[ to ] > endTime ) -- to;
  8782. ++ to; // inclusive -> exclusive bound
  8783. if( from !== 0 || to !== nKeys ) {
  8784. // empty tracks are forbidden, so keep at least one keyframe
  8785. if ( from >= to ) to = Math.max( to , 1 ), from = to - 1;
  8786. var stride = this.getValueSize();
  8787. this.times = THREE.AnimationUtils.arraySlice( times, from, to );
  8788. this.values = THREE.AnimationUtils.
  8789. arraySlice( this.values, from * stride, to * stride );
  8790. }
  8791. return this;
  8792. },
  8793. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  8794. validate: function() {
  8795. var valid = true;
  8796. var valueSize = this.getValueSize();
  8797. if ( valueSize - Math.floor( valueSize ) !== 0 ) {
  8798. console.error( "invalid value size in track", this );
  8799. valid = false;
  8800. }
  8801. var times = this.times,
  8802. values = this.values,
  8803. nKeys = times.length;
  8804. if( nKeys === 0 ) {
  8805. console.error( "track is empty", this );
  8806. valid = false;
  8807. }
  8808. var prevTime = null;
  8809. for( var i = 0; i !== nKeys; i ++ ) {
  8810. var currTime = times[ i ];
  8811. if ( typeof currTime === 'number' && isNaN( currTime ) ) {
  8812. console.error( "time is not a valid number", this, i, currTime );
  8813. valid = false;
  8814. break;
  8815. }
  8816. if( prevTime !== null && prevTime > currTime ) {
  8817. console.error( "out of order keys", this, i, currTime, prevTime );
  8818. valid = false;
  8819. break;
  8820. }
  8821. prevTime = currTime;
  8822. }
  8823. if ( values !== undefined ) {
  8824. if ( THREE.AnimationUtils.isTypedArray( values ) ) {
  8825. for ( var i = 0, n = values.length; i !== n; ++ i ) {
  8826. var value = values[ i ];
  8827. if ( isNaN( value ) ) {
  8828. console.error( "value is not a valid number", this, i, value );
  8829. valid = false;
  8830. break;
  8831. }
  8832. }
  8833. }
  8834. }
  8835. return valid;
  8836. },
  8837. // removes equivalent sequential keys as common in morph target sequences
  8838. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  8839. optimize: function() {
  8840. var times = this.times,
  8841. values = this.values,
  8842. stride = this.getValueSize(),
  8843. writeIndex = 1;
  8844. for( var i = 1, n = times.length - 1; i <= n; ++ i ) {
  8845. var keep = false;
  8846. var time = times[ i ];
  8847. var timeNext = times[ i + 1 ];
  8848. // remove adjacent keyframes scheduled at the same time
  8849. if ( time !== timeNext && ( i !== 1 || time !== time[ 0 ] ) ) {
  8850. // remove unnecessary keyframes same as their neighbors
  8851. var offset = i * stride,
  8852. offsetP = offset - stride,
  8853. offsetN = offset + stride;
  8854. for ( var j = 0; j !== stride; ++ j ) {
  8855. var value = values[ offset + j ];
  8856. if ( value !== values[ offsetP + j ] ||
  8857. value !== values[ offsetN + j ] ) {
  8858. keep = true;
  8859. break;
  8860. }
  8861. }
  8862. }
  8863. // in-place compaction
  8864. if ( keep ) {
  8865. if ( i !== writeIndex ) {
  8866. times[ writeIndex ] = times[ i ];
  8867. var readOffset = i * stride,
  8868. writeOffset = writeIndex * stride;
  8869. for ( var j = 0; j !== stride; ++ j ) {
  8870. values[ writeOffset + j ] = values[ readOffset + j ];
  8871. }
  8872. }
  8873. ++ writeIndex;
  8874. }
  8875. }
  8876. if ( writeIndex !== times.length ) {
  8877. this.times = THREE.AnimationUtils.arraySlice( times, 0, writeIndex );
  8878. this.values = THREE.AnimationUtils.arraySlice( values, 0, writeIndex * stride );
  8879. }
  8880. return this;
  8881. }
  8882. };
  8883. // Static methods:
  8884. Object.assign( THREE.KeyframeTrack, {
  8885. // Serialization (in static context, because of constructor invocation
  8886. // and automatic invocation of .toJSON):
  8887. parse: function( json ) {
  8888. if( json.type === undefined ) {
  8889. throw new Error( "track type undefined, can not parse" );
  8890. }
  8891. var trackType = THREE.KeyframeTrack._getTrackTypeForValueTypeName( json.type );
  8892. if ( json.times === undefined ) {
  8893. var times = [], values = [];
  8894. THREE.AnimationUtils.flattenJSON( json.keys, times, values, 'value' );
  8895. json.times = times;
  8896. json.values = values;
  8897. }
  8898. // derived classes can define a static parse method
  8899. if ( trackType.parse !== undefined ) {
  8900. return trackType.parse( json );
  8901. } else {
  8902. // by default, we asssume a constructor compatible with the base
  8903. return new trackType(
  8904. json.name, json.times, json.values, json.interpolation );
  8905. }
  8906. },
  8907. toJSON: function( track ) {
  8908. var trackType = track.constructor;
  8909. var json;
  8910. // derived classes can define a static toJSON method
  8911. if ( trackType.toJSON !== undefined ) {
  8912. json = trackType.toJSON( track );
  8913. } else {
  8914. // by default, we assume the data can be serialized as-is
  8915. json = {
  8916. 'name': track.name,
  8917. 'times': THREE.AnimationUtils.convertArray( track.times, Array ),
  8918. 'values': THREE.AnimationUtils.convertArray( track.values, Array )
  8919. };
  8920. var interpolation = track.getInterpolation();
  8921. if ( interpolation !== track.DefaultInterpolation ) {
  8922. json.interpolation = interpolation;
  8923. }
  8924. }
  8925. json.type = track.ValueTypeName; // mandatory
  8926. return json;
  8927. },
  8928. _getTrackTypeForValueTypeName: function( typeName ) {
  8929. switch( typeName.toLowerCase() ) {
  8930. case "scalar":
  8931. case "double":
  8932. case "float":
  8933. case "number":
  8934. case "integer":
  8935. return THREE.NumberKeyframeTrack;
  8936. case "vector":
  8937. case "vector2":
  8938. case "vector3":
  8939. case "vector4":
  8940. return THREE.VectorKeyframeTrack;
  8941. case "color":
  8942. return THREE.ColorKeyframeTrack;
  8943. case "quaternion":
  8944. return THREE.QuaternionKeyframeTrack;
  8945. case "bool":
  8946. case "boolean":
  8947. return THREE.BooleanKeyframeTrack;
  8948. case "string":
  8949. return THREE.StringKeyframeTrack;
  8950. }
  8951. throw new Error( "Unsupported typeName: " + typeName );
  8952. }
  8953. } );
  8954. // File:src/animation/PropertyBinding.js
  8955. /**
  8956. *
  8957. * A reference to a real property in the scene graph.
  8958. *
  8959. *
  8960. * @author Ben Houston / http://clara.io/
  8961. * @author David Sarno / http://lighthaus.us/
  8962. * @author tschw
  8963. */
  8964. THREE.PropertyBinding = function ( rootNode, path, parsedPath ) {
  8965. this.path = path;
  8966. this.parsedPath = parsedPath ||
  8967. THREE.PropertyBinding.parseTrackName( path );
  8968. this.node = THREE.PropertyBinding.findNode(
  8969. rootNode, this.parsedPath.nodeName ) || rootNode;
  8970. this.rootNode = rootNode;
  8971. };
  8972. THREE.PropertyBinding.prototype = {
  8973. constructor: THREE.PropertyBinding,
  8974. getValue: function getValue_unbound( targetArray, offset ) {
  8975. this.bind();
  8976. this.getValue( targetArray, offset );
  8977. // Note: This class uses a State pattern on a per-method basis:
  8978. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  8979. // prototype version of these methods with one that represents
  8980. // the bound state. When the property is not found, the methods
  8981. // become no-ops.
  8982. },
  8983. setValue: function getValue_unbound( sourceArray, offset ) {
  8984. this.bind();
  8985. this.setValue( sourceArray, offset );
  8986. },
  8987. // create getter / setter pair for a property in the scene graph
  8988. bind: function() {
  8989. var targetObject = this.node,
  8990. parsedPath = this.parsedPath,
  8991. objectName = parsedPath.objectName,
  8992. propertyName = parsedPath.propertyName,
  8993. propertyIndex = parsedPath.propertyIndex;
  8994. if ( ! targetObject ) {
  8995. targetObject = THREE.PropertyBinding.findNode(
  8996. this.rootNode, parsedPath.nodeName ) || this.rootNode;
  8997. this.node = targetObject;
  8998. }
  8999. // set fail state so we can just 'return' on error
  9000. this.getValue = this._getValue_unavailable;
  9001. this.setValue = this._setValue_unavailable;
  9002. // ensure there is a value node
  9003. if ( ! targetObject ) {
  9004. console.error( " trying to update node for track: " + this.path + " but it wasn't found." );
  9005. return;
  9006. }
  9007. if ( objectName ) {
  9008. var objectIndex = parsedPath.objectIndex;
  9009. // special cases were we need to reach deeper into the hierarchy to get the face materials....
  9010. switch ( objectName ) {
  9011. case 'materials':
  9012. if ( ! targetObject.material ) {
  9013. console.error( ' can not bind to material as node does not have a material', this );
  9014. return;
  9015. }
  9016. if ( ! targetObject.material.materials ) {
  9017. console.error( ' can not bind to material.materials as node.material does not have a materials array', this );
  9018. return;
  9019. }
  9020. targetObject = targetObject.material.materials;
  9021. break;
  9022. case 'bones':
  9023. if ( ! targetObject.skeleton ) {
  9024. console.error( ' can not bind to bones as node does not have a skeleton', this );
  9025. return;
  9026. }
  9027. // potential future optimization: skip this if propertyIndex is already an integer
  9028. // and convert the integer string to a true integer.
  9029. targetObject = targetObject.skeleton.bones;
  9030. // support resolving morphTarget names into indices.
  9031. for ( var i = 0; i < targetObject.length; i ++ ) {
  9032. if ( targetObject[ i ].name === objectIndex ) {
  9033. objectIndex = i;
  9034. break;
  9035. }
  9036. }
  9037. break;
  9038. default:
  9039. if ( targetObject[ objectName ] === undefined ) {
  9040. console.error( ' can not bind to objectName of node, undefined', this );
  9041. return;
  9042. }
  9043. targetObject = targetObject[ objectName ];
  9044. }
  9045. if ( objectIndex !== undefined ) {
  9046. if ( targetObject[ objectIndex ] === undefined ) {
  9047. console.error( " trying to bind to objectIndex of objectName, but is undefined:", this, targetObject );
  9048. return;
  9049. }
  9050. targetObject = targetObject[ objectIndex ];
  9051. }
  9052. }
  9053. // resolve property
  9054. var nodeProperty = targetObject[ propertyName ];
  9055. if ( nodeProperty === undefined ) {
  9056. var nodeName = parsedPath.nodeName;
  9057. console.error( " trying to update property for track: " + nodeName +
  9058. '.' + propertyName + " but it wasn't found.", targetObject );
  9059. return;
  9060. }
  9061. // determine versioning scheme
  9062. var versioning = this.Versioning.None;
  9063. if ( targetObject.needsUpdate !== undefined ) { // material
  9064. versioning = this.Versioning.NeedsUpdate;
  9065. this.targetObject = targetObject;
  9066. } else if ( targetObject.matrixWorldNeedsUpdate !== undefined ) { // node transform
  9067. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  9068. this.targetObject = targetObject;
  9069. }
  9070. // determine how the property gets bound
  9071. var bindingType = this.BindingType.Direct;
  9072. if ( propertyIndex !== undefined ) {
  9073. // access a sub element of the property array (only primitives are supported right now)
  9074. if ( propertyName === "morphTargetInfluences" ) {
  9075. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  9076. // support resolving morphTarget names into indices.
  9077. if ( ! targetObject.geometry ) {
  9078. console.error( ' can not bind to morphTargetInfluences becasuse node does not have a geometry', this );
  9079. return;
  9080. }
  9081. if ( ! targetObject.geometry.morphTargets ) {
  9082. console.error( ' can not bind to morphTargetInfluences becasuse node does not have a geometry.morphTargets', this );
  9083. return;
  9084. }
  9085. for ( var i = 0; i < this.node.geometry.morphTargets.length; i ++ ) {
  9086. if ( targetObject.geometry.morphTargets[ i ].name === propertyIndex ) {
  9087. propertyIndex = i;
  9088. break;
  9089. }
  9090. }
  9091. }
  9092. bindingType = this.BindingType.ArrayElement;
  9093. this.resolvedProperty = nodeProperty;
  9094. this.propertyIndex = propertyIndex;
  9095. } else if ( nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined ) {
  9096. // must use copy for Object3D.Euler/Quaternion
  9097. bindingType = this.BindingType.HasFromToArray;
  9098. this.resolvedProperty = nodeProperty;
  9099. } else if ( nodeProperty.length !== undefined ) {
  9100. bindingType = this.BindingType.EntireArray;
  9101. this.resolvedProperty = nodeProperty;
  9102. } else {
  9103. this.propertyName = propertyName;
  9104. }
  9105. // select getter / setter
  9106. this.getValue = this.GetterByBindingType[ bindingType ];
  9107. this.setValue = this.SetterByBindingTypeAndVersioning[ bindingType ][ versioning ];
  9108. },
  9109. unbind: function() {
  9110. this.node = null;
  9111. // back to the prototype version of getValue / setValue
  9112. // note: avoiding to mutate the shape of 'this' via 'delete'
  9113. this.getValue = this._getValue_unbound;
  9114. this.setValue = this._setValue_unbound;
  9115. }
  9116. };
  9117. Object.assign( THREE.PropertyBinding.prototype, { // prototype, continued
  9118. // these are used to "bind" a nonexistent property
  9119. _getValue_unavailable: function() {},
  9120. _setValue_unavailable: function() {},
  9121. // initial state of these methods that calls 'bind'
  9122. _getValue_unbound: THREE.PropertyBinding.prototype.getValue,
  9123. _setValue_unbound: THREE.PropertyBinding.prototype.setValue,
  9124. BindingType: {
  9125. Direct: 0,
  9126. EntireArray: 1,
  9127. ArrayElement: 2,
  9128. HasFromToArray: 3
  9129. },
  9130. Versioning: {
  9131. None: 0,
  9132. NeedsUpdate: 1,
  9133. MatrixWorldNeedsUpdate: 2
  9134. },
  9135. GetterByBindingType: [
  9136. function getValue_direct( buffer, offset ) {
  9137. buffer[ offset ] = this.node[ this.propertyName ];
  9138. },
  9139. function getValue_array( buffer, offset ) {
  9140. var source = this.resolvedProperty;
  9141. for ( var i = 0, n = source.length; i !== n; ++ i ) {
  9142. buffer[ offset ++ ] = source[ i ];
  9143. }
  9144. },
  9145. function getValue_arrayElement( buffer, offset ) {
  9146. buffer[ offset ] = this.resolvedProperty[ this.propertyIndex ];
  9147. },
  9148. function getValue_toArray( buffer, offset ) {
  9149. this.resolvedProperty.toArray( buffer, offset );
  9150. }
  9151. ],
  9152. SetterByBindingTypeAndVersioning: [
  9153. [
  9154. // Direct
  9155. function setValue_direct( buffer, offset ) {
  9156. this.node[ this.propertyName ] = buffer[ offset ];
  9157. },
  9158. function setValue_direct_setNeedsUpdate( buffer, offset ) {
  9159. this.node[ this.propertyName ] = buffer[ offset ];
  9160. this.targetObject.needsUpdate = true;
  9161. },
  9162. function setValue_direct_setMatrixWorldNeedsUpdate( buffer, offset ) {
  9163. this.node[ this.propertyName ] = buffer[ offset ];
  9164. this.targetObject.matrixWorldNeedsUpdate = true;
  9165. }
  9166. ], [
  9167. // EntireArray
  9168. function setValue_array( buffer, offset ) {
  9169. var dest = this.resolvedProperty;
  9170. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  9171. dest[ i ] = buffer[ offset ++ ];
  9172. }
  9173. },
  9174. function setValue_array_setNeedsUpdate( buffer, offset ) {
  9175. var dest = this.resolvedProperty;
  9176. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  9177. dest[ i ] = buffer[ offset ++ ];
  9178. }
  9179. this.targetObject.needsUpdate = true;
  9180. },
  9181. function setValue_array_setMatrixWorldNeedsUpdate( buffer, offset ) {
  9182. var dest = this.resolvedProperty;
  9183. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  9184. dest[ i ] = buffer[ offset ++ ];
  9185. }
  9186. this.targetObject.matrixWorldNeedsUpdate = true;
  9187. }
  9188. ], [
  9189. // ArrayElement
  9190. function setValue_arrayElement( buffer, offset ) {
  9191. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  9192. },
  9193. function setValue_arrayElement_setNeedsUpdate( buffer, offset ) {
  9194. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  9195. this.targetObject.needsUpdate = true;
  9196. },
  9197. function setValue_arrayElement_setMatrixWorldNeedsUpdate( buffer, offset ) {
  9198. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  9199. this.targetObject.matrixWorldNeedsUpdate = true;
  9200. }
  9201. ], [
  9202. // HasToFromArray
  9203. function setValue_fromArray( buffer, offset ) {
  9204. this.resolvedProperty.fromArray( buffer, offset );
  9205. },
  9206. function setValue_fromArray_setNeedsUpdate( buffer, offset ) {
  9207. this.resolvedProperty.fromArray( buffer, offset );
  9208. this.targetObject.needsUpdate = true;
  9209. },
  9210. function setValue_fromArray_setMatrixWorldNeedsUpdate( buffer, offset ) {
  9211. this.resolvedProperty.fromArray( buffer, offset );
  9212. this.targetObject.matrixWorldNeedsUpdate = true;
  9213. }
  9214. ]
  9215. ]
  9216. } );
  9217. THREE.PropertyBinding.Composite =
  9218. function( targetGroup, path, optionalParsedPath ) {
  9219. var parsedPath = optionalParsedPath ||
  9220. THREE.PropertyBinding.parseTrackName( path );
  9221. this._targetGroup = targetGroup;
  9222. this._bindings = targetGroup.subscribe_( path, parsedPath );
  9223. };
  9224. THREE.PropertyBinding.Composite.prototype = {
  9225. constructor: THREE.PropertyBinding.Composite,
  9226. getValue: function( array, offset ) {
  9227. this.bind(); // bind all binding
  9228. var firstValidIndex = this._targetGroup.nCachedObjects_,
  9229. binding = this._bindings[ firstValidIndex ];
  9230. // and only call .getValue on the first
  9231. if ( binding !== undefined ) binding.getValue( array, offset );
  9232. },
  9233. setValue: function( array, offset ) {
  9234. var bindings = this._bindings;
  9235. for ( var i = this._targetGroup.nCachedObjects_,
  9236. n = bindings.length; i !== n; ++ i ) {
  9237. bindings[ i ].setValue( array, offset );
  9238. }
  9239. },
  9240. bind: function() {
  9241. var bindings = this._bindings;
  9242. for ( var i = this._targetGroup.nCachedObjects_,
  9243. n = bindings.length; i !== n; ++ i ) {
  9244. bindings[ i ].bind();
  9245. }
  9246. },
  9247. unbind: function() {
  9248. var bindings = this._bindings;
  9249. for ( var i = this._targetGroup.nCachedObjects_,
  9250. n = bindings.length; i !== n; ++ i ) {
  9251. bindings[ i ].unbind();
  9252. }
  9253. }
  9254. };
  9255. THREE.PropertyBinding.create = function( root, path, parsedPath ) {
  9256. if ( ! ( root instanceof THREE.AnimationObjectGroup ) ) {
  9257. return new THREE.PropertyBinding( root, path, parsedPath );
  9258. } else {
  9259. return new THREE.PropertyBinding.Composite( root, path, parsedPath );
  9260. }
  9261. };
  9262. THREE.PropertyBinding.parseTrackName = function( trackName ) {
  9263. // matches strings in the form of:
  9264. // nodeName.property
  9265. // nodeName.property[accessor]
  9266. // nodeName.material.property[accessor]
  9267. // uuid.property[accessor]
  9268. // uuid.objectName[objectIndex].propertyName[propertyIndex]
  9269. // parentName/nodeName.property
  9270. // parentName/parentName/nodeName.property[index]
  9271. // .bone[Armature.DEF_cog].position
  9272. // created and tested via https://regex101.com/#javascript
  9273. var re = /^(([\w]+\/)*)([\w-\d]+)?(\.([\w]+)(\[([\w\d\[\]\_.:\- ]+)\])?)?(\.([\w.]+)(\[([\w\d\[\]\_. ]+)\])?)$/;
  9274. var matches = re.exec( trackName );
  9275. if ( ! matches ) {
  9276. throw new Error( "cannot parse trackName at all: " + trackName );
  9277. }
  9278. if ( matches.index === re.lastIndex ) {
  9279. re.lastIndex++;
  9280. }
  9281. var results = {
  9282. // directoryName: matches[ 1 ], // (tschw) currently unused
  9283. nodeName: matches[ 3 ], // allowed to be null, specified root node.
  9284. objectName: matches[ 5 ],
  9285. objectIndex: matches[ 7 ],
  9286. propertyName: matches[ 9 ],
  9287. propertyIndex: matches[ 11 ] // allowed to be null, specifies that the whole property is set.
  9288. };
  9289. if ( results.propertyName === null || results.propertyName.length === 0 ) {
  9290. throw new Error( "can not parse propertyName from trackName: " + trackName );
  9291. }
  9292. return results;
  9293. };
  9294. THREE.PropertyBinding.findNode = function( root, nodeName ) {
  9295. if ( ! nodeName || nodeName === "" || nodeName === "root" || nodeName === "." || nodeName === -1 || nodeName === root.name || nodeName === root.uuid ) {
  9296. return root;
  9297. }
  9298. // search into skeleton bones.
  9299. if ( root.skeleton ) {
  9300. var searchSkeleton = function( skeleton ) {
  9301. for( var i = 0; i < skeleton.bones.length; i ++ ) {
  9302. var bone = skeleton.bones[ i ];
  9303. if ( bone.name === nodeName ) {
  9304. return bone;
  9305. }
  9306. }
  9307. return null;
  9308. };
  9309. var bone = searchSkeleton( root.skeleton );
  9310. if ( bone ) {
  9311. return bone;
  9312. }
  9313. }
  9314. // search into node subtree.
  9315. if ( root.children ) {
  9316. var searchNodeSubtree = function( children ) {
  9317. for( var i = 0; i < children.length; i ++ ) {
  9318. var childNode = children[ i ];
  9319. if ( childNode.name === nodeName || childNode.uuid === nodeName ) {
  9320. return childNode;
  9321. }
  9322. var result = searchNodeSubtree( childNode.children );
  9323. if ( result ) return result;
  9324. }
  9325. return null;
  9326. };
  9327. var subTreeNode = searchNodeSubtree( root.children );
  9328. if ( subTreeNode ) {
  9329. return subTreeNode;
  9330. }
  9331. }
  9332. return null;
  9333. };
  9334. // File:src/animation/PropertyMixer.js
  9335. /**
  9336. *
  9337. * Buffered scene graph property that allows weighted accumulation.
  9338. *
  9339. *
  9340. * @author Ben Houston / http://clara.io/
  9341. * @author David Sarno / http://lighthaus.us/
  9342. * @author tschw
  9343. */
  9344. THREE.PropertyMixer = function ( binding, typeName, valueSize ) {
  9345. this.binding = binding;
  9346. this.valueSize = valueSize;
  9347. var bufferType = Float64Array,
  9348. mixFunction;
  9349. switch ( typeName ) {
  9350. case 'quaternion': mixFunction = this._slerp; break;
  9351. case 'string':
  9352. case 'bool':
  9353. bufferType = Array, mixFunction = this._select; break;
  9354. default: mixFunction = this._lerp;
  9355. }
  9356. this.buffer = new bufferType( valueSize * 4 );
  9357. // layout: [ incoming | accu0 | accu1 | orig ]
  9358. //
  9359. // interpolators can use .buffer as their .result
  9360. // the data then goes to 'incoming'
  9361. //
  9362. // 'accu0' and 'accu1' are used frame-interleaved for
  9363. // the cumulative result and are compared to detect
  9364. // changes
  9365. //
  9366. // 'orig' stores the original state of the property
  9367. this._mixBufferRegion = mixFunction;
  9368. this.cumulativeWeight = 0;
  9369. this.useCount = 0;
  9370. this.referenceCount = 0;
  9371. };
  9372. THREE.PropertyMixer.prototype = {
  9373. constructor: THREE.PropertyMixer,
  9374. // accumulate data in the 'incoming' region into 'accu<i>'
  9375. accumulate: function( accuIndex, weight ) {
  9376. // note: happily accumulating nothing when weight = 0, the caller knows
  9377. // the weight and shouldn't have made the call in the first place
  9378. var buffer = this.buffer,
  9379. stride = this.valueSize,
  9380. offset = accuIndex * stride + stride,
  9381. currentWeight = this.cumulativeWeight;
  9382. if ( currentWeight === 0 ) {
  9383. // accuN := incoming * weight
  9384. for ( var i = 0; i !== stride; ++ i ) {
  9385. buffer[ offset + i ] = buffer[ i ];
  9386. }
  9387. currentWeight = weight;
  9388. } else {
  9389. // accuN := accuN + incoming * weight
  9390. currentWeight += weight;
  9391. var mix = weight / currentWeight;
  9392. this._mixBufferRegion( buffer, offset, 0, mix, stride );
  9393. }
  9394. this.cumulativeWeight = currentWeight;
  9395. },
  9396. // apply the state of 'accu<i>' to the binding when accus differ
  9397. apply: function( accuIndex ) {
  9398. var stride = this.valueSize,
  9399. buffer = this.buffer,
  9400. offset = accuIndex * stride + stride,
  9401. weight = this.cumulativeWeight,
  9402. binding = this.binding;
  9403. this.cumulativeWeight = 0;
  9404. if ( weight < 1 ) {
  9405. // accuN := accuN + original * ( 1 - cumulativeWeight )
  9406. var originalValueOffset = stride * 3;
  9407. this._mixBufferRegion(
  9408. buffer, offset, originalValueOffset, 1 - weight, stride );
  9409. }
  9410. for ( var i = stride, e = stride + stride; i !== e; ++ i ) {
  9411. if ( buffer[ i ] !== buffer[ i + stride ] ) {
  9412. // value has changed -> update scene graph
  9413. binding.setValue( buffer, offset );
  9414. break;
  9415. }
  9416. }
  9417. },
  9418. // remember the state of the bound property and copy it to both accus
  9419. saveOriginalState: function() {
  9420. var binding = this.binding;
  9421. var buffer = this.buffer,
  9422. stride = this.valueSize,
  9423. originalValueOffset = stride * 3;
  9424. binding.getValue( buffer, originalValueOffset );
  9425. // accu[0..1] := orig -- initially detect changes against the original
  9426. for ( var i = stride, e = originalValueOffset; i !== e; ++ i ) {
  9427. buffer[ i ] = buffer[ originalValueOffset + ( i % stride ) ];
  9428. }
  9429. this.cumulativeWeight = 0;
  9430. },
  9431. // apply the state previously taken via 'saveOriginalState' to the binding
  9432. restoreOriginalState: function() {
  9433. var originalValueOffset = this.valueSize * 3;
  9434. this.binding.setValue( this.buffer, originalValueOffset );
  9435. },
  9436. // mix functions
  9437. _select: function( buffer, dstOffset, srcOffset, t, stride ) {
  9438. if ( t >= 0.5 ) {
  9439. for ( var i = 0; i !== stride; ++ i ) {
  9440. buffer[ dstOffset + i ] = buffer[ srcOffset + i ];
  9441. }
  9442. }
  9443. },
  9444. _slerp: function( buffer, dstOffset, srcOffset, t, stride ) {
  9445. THREE.Quaternion.slerpFlat( buffer, dstOffset,
  9446. buffer, dstOffset, buffer, srcOffset, t );
  9447. },
  9448. _lerp: function( buffer, dstOffset, srcOffset, t, stride ) {
  9449. var s = 1 - t;
  9450. for ( var i = 0; i !== stride; ++ i ) {
  9451. var j = dstOffset + i;
  9452. buffer[ j ] = buffer[ j ] * s + buffer[ srcOffset + i ] * t;
  9453. }
  9454. }
  9455. };
  9456. // File:src/animation/tracks/BooleanKeyframeTrack.js
  9457. /**
  9458. *
  9459. * A Track of Boolean keyframe values.
  9460. *
  9461. *
  9462. * @author Ben Houston / http://clara.io/
  9463. * @author David Sarno / http://lighthaus.us/
  9464. * @author tschw
  9465. */
  9466. THREE.BooleanKeyframeTrack = function ( name, times, values ) {
  9467. THREE.KeyframeTrack.call( this, name, times, values );
  9468. };
  9469. THREE.BooleanKeyframeTrack.prototype =
  9470. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9471. constructor: THREE.BooleanKeyframeTrack,
  9472. ValueTypeName: 'bool',
  9473. ValueBufferType: Array,
  9474. DefaultInterpolation: THREE.InterpolateDiscrete,
  9475. InterpolantFactoryMethodLinear: undefined,
  9476. InterpolantFactoryMethodSmooth: undefined
  9477. // Note: Actually this track could have a optimized / compressed
  9478. // representation of a single value and a custom interpolant that
  9479. // computes "firstValue ^ isOdd( index )".
  9480. } );
  9481. // File:src/animation/tracks/ColorKeyframeTrack.js
  9482. /**
  9483. *
  9484. * A Track of keyframe values that represent color.
  9485. *
  9486. *
  9487. * @author Ben Houston / http://clara.io/
  9488. * @author David Sarno / http://lighthaus.us/
  9489. * @author tschw
  9490. */
  9491. THREE.ColorKeyframeTrack = function ( name, times, values, interpolation ) {
  9492. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9493. };
  9494. THREE.ColorKeyframeTrack.prototype =
  9495. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9496. constructor: THREE.ColorKeyframeTrack,
  9497. ValueTypeName: 'color'
  9498. // ValueBufferType is inherited
  9499. // DefaultInterpolation is inherited
  9500. // Note: Very basic implementation and nothing special yet.
  9501. // However, this is the place for color space parameterization.
  9502. } );
  9503. // File:src/animation/tracks/NumberKeyframeTrack.js
  9504. /**
  9505. *
  9506. * A Track of numeric keyframe values.
  9507. *
  9508. * @author Ben Houston / http://clara.io/
  9509. * @author David Sarno / http://lighthaus.us/
  9510. * @author tschw
  9511. */
  9512. THREE.NumberKeyframeTrack = function ( name, times, values, interpolation ) {
  9513. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9514. };
  9515. THREE.NumberKeyframeTrack.prototype =
  9516. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9517. constructor: THREE.NumberKeyframeTrack,
  9518. ValueTypeName: 'number',
  9519. // ValueBufferType is inherited
  9520. // DefaultInterpolation is inherited
  9521. } );
  9522. // File:src/animation/tracks/QuaternionKeyframeTrack.js
  9523. /**
  9524. *
  9525. * A Track of quaternion keyframe values.
  9526. *
  9527. * @author Ben Houston / http://clara.io/
  9528. * @author David Sarno / http://lighthaus.us/
  9529. * @author tschw
  9530. */
  9531. THREE.QuaternionKeyframeTrack = function ( name, times, values, interpolation ) {
  9532. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9533. };
  9534. THREE.QuaternionKeyframeTrack.prototype =
  9535. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9536. constructor: THREE.QuaternionKeyframeTrack,
  9537. ValueTypeName: 'quaternion',
  9538. // ValueBufferType is inherited
  9539. DefaultInterpolation: THREE.InterpolateLinear,
  9540. InterpolantFactoryMethodLinear: function( result ) {
  9541. return new THREE.QuaternionLinearInterpolant(
  9542. this.times, this.values, this.getValueSize(), result );
  9543. },
  9544. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  9545. } );
  9546. // File:src/animation/tracks/StringKeyframeTrack.js
  9547. /**
  9548. *
  9549. * A Track that interpolates Strings
  9550. *
  9551. *
  9552. * @author Ben Houston / http://clara.io/
  9553. * @author David Sarno / http://lighthaus.us/
  9554. * @author tschw
  9555. */
  9556. THREE.StringKeyframeTrack = function ( name, times, values, interpolation ) {
  9557. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9558. };
  9559. THREE.StringKeyframeTrack.prototype =
  9560. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9561. constructor: THREE.StringKeyframeTrack,
  9562. ValueTypeName: 'string',
  9563. ValueBufferType: Array,
  9564. DefaultInterpolation: THREE.InterpolateDiscrete,
  9565. InterpolantFactoryMethodLinear: undefined,
  9566. InterpolantFactoryMethodSmooth: undefined
  9567. } );
  9568. // File:src/animation/tracks/VectorKeyframeTrack.js
  9569. /**
  9570. *
  9571. * A Track of vectored keyframe values.
  9572. *
  9573. *
  9574. * @author Ben Houston / http://clara.io/
  9575. * @author David Sarno / http://lighthaus.us/
  9576. * @author tschw
  9577. */
  9578. THREE.VectorKeyframeTrack = function ( name, times, values, interpolation ) {
  9579. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9580. };
  9581. THREE.VectorKeyframeTrack.prototype =
  9582. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9583. constructor: THREE.VectorKeyframeTrack,
  9584. ValueTypeName: 'vector'
  9585. // ValueBufferType is inherited
  9586. // DefaultInterpolation is inherited
  9587. } );
  9588. // File:src/audio/Audio.js
  9589. /**
  9590. * @author mrdoob / http://mrdoob.com/
  9591. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  9592. */
  9593. THREE.Audio = function ( listener ) {
  9594. THREE.Object3D.call( this );
  9595. this.type = 'Audio';
  9596. this.context = listener.context;
  9597. this.source = this.context.createBufferSource();
  9598. this.source.onended = this.onEnded.bind( this );
  9599. this.gain = this.context.createGain();
  9600. this.gain.connect( listener.getInput() );
  9601. this.autoplay = false;
  9602. this.startTime = 0;
  9603. this.playbackRate = 1;
  9604. this.isPlaying = false;
  9605. this.hasPlaybackControl = true;
  9606. this.sourceType = 'empty';
  9607. this.filters = [];
  9608. };
  9609. THREE.Audio.prototype = Object.assign( Object.create( THREE.Object3D.prototype ), {
  9610. constructor: THREE.Audio,
  9611. getOutput: function () {
  9612. return this.gain;
  9613. },
  9614. setNodeSource: function ( audioNode ) {
  9615. this.hasPlaybackControl = false;
  9616. this.sourceType = 'audioNode';
  9617. this.source = audioNode;
  9618. this.connect();
  9619. return this;
  9620. },
  9621. setBuffer: function ( audioBuffer ) {
  9622. this.source.buffer = audioBuffer;
  9623. this.sourceType = 'buffer';
  9624. if ( this.autoplay ) this.play();
  9625. return this;
  9626. },
  9627. play: function () {
  9628. if ( this.isPlaying === true ) {
  9629. console.warn( 'THREE.Audio: Audio is already playing.' );
  9630. return;
  9631. }
  9632. if ( this.hasPlaybackControl === false ) {
  9633. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9634. return;
  9635. }
  9636. var source = this.context.createBufferSource();
  9637. source.buffer = this.source.buffer;
  9638. source.loop = this.source.loop;
  9639. source.onended = this.source.onended;
  9640. source.start( 0, this.startTime );
  9641. source.playbackRate.value = this.playbackRate;
  9642. this.isPlaying = true;
  9643. this.source = source;
  9644. return this.connect();
  9645. },
  9646. pause: function () {
  9647. if ( this.hasPlaybackControl === false ) {
  9648. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9649. return;
  9650. }
  9651. this.source.stop();
  9652. this.startTime = this.context.currentTime;
  9653. this.isPlaying = false;
  9654. return this;
  9655. },
  9656. stop: function () {
  9657. if ( this.hasPlaybackControl === false ) {
  9658. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9659. return;
  9660. }
  9661. this.source.stop();
  9662. this.startTime = 0;
  9663. this.isPlaying = false;
  9664. return this;
  9665. },
  9666. connect: function () {
  9667. if ( this.filters.length > 0 ) {
  9668. this.source.connect( this.filters[ 0 ] );
  9669. for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
  9670. this.filters[ i - 1 ].connect( this.filters[ i ] );
  9671. }
  9672. this.filters[ this.filters.length - 1 ].connect( this.getOutput() );
  9673. } else {
  9674. this.source.connect( this.getOutput() );
  9675. }
  9676. return this;
  9677. },
  9678. disconnect: function () {
  9679. if ( this.filters.length > 0 ) {
  9680. this.source.disconnect( this.filters[ 0 ] );
  9681. for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
  9682. this.filters[ i - 1 ].disconnect( this.filters[ i ] );
  9683. }
  9684. this.filters[ this.filters.length - 1 ].disconnect( this.getOutput() );
  9685. } else {
  9686. this.source.disconnect( this.getOutput() );
  9687. }
  9688. return this;
  9689. },
  9690. getFilters: function () {
  9691. return this.filters;
  9692. },
  9693. setFilters: function ( value ) {
  9694. if ( ! value ) value = [];
  9695. if ( this.isPlaying === true ) {
  9696. this.disconnect();
  9697. this.filters = value;
  9698. this.connect();
  9699. } else {
  9700. this.filters = value;
  9701. }
  9702. return this;
  9703. },
  9704. getFilter: function () {
  9705. return this.getFilters()[ 0 ];
  9706. },
  9707. setFilter: function ( filter ) {
  9708. return this.setFilters( filter ? [ filter ] : [] );
  9709. },
  9710. setPlaybackRate: function ( value ) {
  9711. if ( this.hasPlaybackControl === false ) {
  9712. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9713. return;
  9714. }
  9715. this.playbackRate = value;
  9716. if ( this.isPlaying === true ) {
  9717. this.source.playbackRate.value = this.playbackRate;
  9718. }
  9719. return this;
  9720. },
  9721. getPlaybackRate: function () {
  9722. return this.playbackRate;
  9723. },
  9724. onEnded: function () {
  9725. this.isPlaying = false;
  9726. },
  9727. getLoop: function () {
  9728. if ( this.hasPlaybackControl === false ) {
  9729. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9730. return false;
  9731. }
  9732. return this.source.loop;
  9733. },
  9734. setLoop: function ( value ) {
  9735. if ( this.hasPlaybackControl === false ) {
  9736. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9737. return;
  9738. }
  9739. this.source.loop = value;
  9740. },
  9741. getVolume: function () {
  9742. return this.gain.gain.value;
  9743. },
  9744. setVolume: function ( value ) {
  9745. this.gain.gain.value = value;
  9746. return this;
  9747. }
  9748. } );
  9749. // File:src/audio/AudioAnalyser.js
  9750. /**
  9751. * @author mrdoob / http://mrdoob.com/
  9752. */
  9753. THREE.AudioAnalyser = function ( audio, fftSize ) {
  9754. this.analyser = audio.context.createAnalyser();
  9755. this.analyser.fftSize = fftSize !== undefined ? fftSize : 2048;
  9756. this.data = new Uint8Array( this.analyser.frequencyBinCount );
  9757. audio.getOutput().connect( this.analyser );
  9758. };
  9759. Object.assign( THREE.AudioAnalyser.prototype, {
  9760. getFrequencyData: function () {
  9761. this.analyser.getByteFrequencyData( this.data );
  9762. return this.data;
  9763. },
  9764. getAverageFrequency: function () {
  9765. var value = 0, data = this.getFrequencyData();
  9766. for ( var i = 0; i < data.length; i ++ ) {
  9767. value += data[ i ];
  9768. }
  9769. return value / data.length;
  9770. }
  9771. } );
  9772. // File:src/audio/AudioContext.js
  9773. /**
  9774. * @author mrdoob / http://mrdoob.com/
  9775. */
  9776. Object.defineProperty( THREE, 'AudioContext', {
  9777. get: ( function () {
  9778. var context;
  9779. return function get() {
  9780. if ( context === undefined ) {
  9781. context = new ( window.AudioContext || window.webkitAudioContext )();
  9782. }
  9783. return context;
  9784. };
  9785. } )()
  9786. } );
  9787. // File:src/audio/PositionalAudio.js
  9788. /**
  9789. * @author mrdoob / http://mrdoob.com/
  9790. */
  9791. THREE.PositionalAudio = function ( listener ) {
  9792. THREE.Audio.call( this, listener );
  9793. this.panner = this.context.createPanner();
  9794. this.panner.connect( this.gain );
  9795. };
  9796. THREE.PositionalAudio.prototype = Object.assign( Object.create( THREE.Audio.prototype ), {
  9797. constructor: THREE.PositionalAudio,
  9798. getOutput: function () {
  9799. return this.panner;
  9800. },
  9801. getRefDistance: function () {
  9802. return this.panner.refDistance;
  9803. },
  9804. setRefDistance: function ( value ) {
  9805. this.panner.refDistance = value;
  9806. },
  9807. getRolloffFactor: function () {
  9808. return this.panner.rolloffFactor;
  9809. },
  9810. setRolloffFactor: function ( value ) {
  9811. this.panner.rolloffFactor = value;
  9812. },
  9813. getDistanceModel: function () {
  9814. return this.panner.distanceModel;
  9815. },
  9816. setDistanceModel: function ( value ) {
  9817. this.panner.distanceModel = value;
  9818. },
  9819. getMaxDistance: function () {
  9820. return this.panner.maxDistance;
  9821. },
  9822. setMaxDistance: function ( value ) {
  9823. this.panner.maxDistance = value;
  9824. },
  9825. updateMatrixWorld: ( function () {
  9826. var position = new THREE.Vector3();
  9827. return function updateMatrixWorld( force ) {
  9828. THREE.Object3D.prototype.updateMatrixWorld.call( this, force );
  9829. position.setFromMatrixPosition( this.matrixWorld );
  9830. this.panner.setPosition( position.x, position.y, position.z );
  9831. };
  9832. } )()
  9833. } );
  9834. // File:src/audio/AudioListener.js
  9835. /**
  9836. * @author mrdoob / http://mrdoob.com/
  9837. */
  9838. THREE.AudioListener = function () {
  9839. THREE.Object3D.call( this );
  9840. this.type = 'AudioListener';
  9841. this.context = THREE.AudioContext;
  9842. this.gain = this.context.createGain();
  9843. this.gain.connect( this.context.destination );
  9844. this.filter = null;
  9845. };
  9846. THREE.AudioListener.prototype = Object.assign( Object.create( THREE.Object3D.prototype ), {
  9847. constructor: THREE.AudioListener,
  9848. getInput: function () {
  9849. return this.gain;
  9850. },
  9851. removeFilter: function ( ) {
  9852. if ( this.filter !== null ) {
  9853. this.gain.disconnect( this.filter );
  9854. this.filter.disconnect( this.context.destination );
  9855. this.gain.connect( this.context.destination );
  9856. this.filter = null;
  9857. }
  9858. },
  9859. getFilter: function () {
  9860. return this.filter;
  9861. },
  9862. setFilter: function ( value ) {
  9863. if ( this.filter !== null ) {
  9864. this.gain.disconnect( this.filter );
  9865. this.filter.disconnect( this.context.destination );
  9866. } else {
  9867. this.gain.disconnect( this.context.destination );
  9868. }
  9869. this.filter = value;
  9870. this.gain.connect( this.filter );
  9871. this.filter.connect( this.context.destination );
  9872. },
  9873. getMasterVolume: function () {
  9874. return this.gain.gain.value;
  9875. },
  9876. setMasterVolume: function ( value ) {
  9877. this.gain.gain.value = value;
  9878. },
  9879. updateMatrixWorld: ( function () {
  9880. var position = new THREE.Vector3();
  9881. var quaternion = new THREE.Quaternion();
  9882. var scale = new THREE.Vector3();
  9883. var orientation = new THREE.Vector3();
  9884. return function updateMatrixWorld( force ) {
  9885. THREE.Object3D.prototype.updateMatrixWorld.call( this, force );
  9886. var listener = this.context.listener;
  9887. var up = this.up;
  9888. this.matrixWorld.decompose( position, quaternion, scale );
  9889. orientation.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  9890. listener.setPosition( position.x, position.y, position.z );
  9891. listener.setOrientation( orientation.x, orientation.y, orientation.z, up.x, up.y, up.z );
  9892. };
  9893. } )()
  9894. } );
  9895. // File:src/cameras/Camera.js
  9896. /**
  9897. * @author mrdoob / http://mrdoob.com/
  9898. * @author mikael emtinger / http://gomo.se/
  9899. * @author WestLangley / http://github.com/WestLangley
  9900. */
  9901. THREE.Camera = function () {
  9902. THREE.Object3D.call( this );
  9903. this.type = 'Camera';
  9904. this.matrixWorldInverse = new THREE.Matrix4();
  9905. this.projectionMatrix = new THREE.Matrix4();
  9906. };
  9907. THREE.Camera.prototype = Object.create( THREE.Object3D.prototype );
  9908. THREE.Camera.prototype.constructor = THREE.Camera;
  9909. THREE.Camera.prototype.getWorldDirection = function () {
  9910. var quaternion = new THREE.Quaternion();
  9911. return function getWorldDirection( optionalTarget ) {
  9912. var result = optionalTarget || new THREE.Vector3();
  9913. this.getWorldQuaternion( quaternion );
  9914. return result.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  9915. };
  9916. }();
  9917. THREE.Camera.prototype.lookAt = function () {
  9918. // This routine does not support cameras with rotated and/or translated parent(s)
  9919. var m1 = new THREE.Matrix4();
  9920. return function lookAt( vector ) {
  9921. m1.lookAt( this.position, vector, this.up );
  9922. this.quaternion.setFromRotationMatrix( m1 );
  9923. };
  9924. }();
  9925. THREE.Camera.prototype.clone = function () {
  9926. return new this.constructor().copy( this );
  9927. };
  9928. THREE.Camera.prototype.copy = function ( source ) {
  9929. THREE.Object3D.prototype.copy.call( this, source );
  9930. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  9931. this.projectionMatrix.copy( source.projectionMatrix );
  9932. return this;
  9933. };
  9934. // File:src/cameras/CubeCamera.js
  9935. /**
  9936. * Camera for rendering cube maps
  9937. * - renders scene into axis-aligned cube
  9938. *
  9939. * @author alteredq / http://alteredqualia.com/
  9940. */
  9941. THREE.CubeCamera = function ( near, far, cubeResolution ) {
  9942. THREE.Object3D.call( this );
  9943. this.type = 'CubeCamera';
  9944. var fov = 90, aspect = 1;
  9945. var cameraPX = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9946. cameraPX.up.set( 0, - 1, 0 );
  9947. cameraPX.lookAt( new THREE.Vector3( 1, 0, 0 ) );
  9948. this.add( cameraPX );
  9949. var cameraNX = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9950. cameraNX.up.set( 0, - 1, 0 );
  9951. cameraNX.lookAt( new THREE.Vector3( - 1, 0, 0 ) );
  9952. this.add( cameraNX );
  9953. var cameraPY = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9954. cameraPY.up.set( 0, 0, 1 );
  9955. cameraPY.lookAt( new THREE.Vector3( 0, 1, 0 ) );
  9956. this.add( cameraPY );
  9957. var cameraNY = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9958. cameraNY.up.set( 0, 0, - 1 );
  9959. cameraNY.lookAt( new THREE.Vector3( 0, - 1, 0 ) );
  9960. this.add( cameraNY );
  9961. var cameraPZ = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9962. cameraPZ.up.set( 0, - 1, 0 );
  9963. cameraPZ.lookAt( new THREE.Vector3( 0, 0, 1 ) );
  9964. this.add( cameraPZ );
  9965. var cameraNZ = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9966. cameraNZ.up.set( 0, - 1, 0 );
  9967. cameraNZ.lookAt( new THREE.Vector3( 0, 0, - 1 ) );
  9968. this.add( cameraNZ );
  9969. var options = { format: THREE.RGBFormat, magFilter: THREE.LinearFilter, minFilter: THREE.LinearFilter };
  9970. this.renderTarget = new THREE.WebGLRenderTargetCube( cubeResolution, cubeResolution, options );
  9971. this.updateCubeMap = function ( renderer, scene ) {
  9972. if ( this.parent === null ) this.updateMatrixWorld();
  9973. var renderTarget = this.renderTarget;
  9974. var generateMipmaps = renderTarget.texture.generateMipmaps;
  9975. renderTarget.texture.generateMipmaps = false;
  9976. renderTarget.activeCubeFace = 0;
  9977. renderer.render( scene, cameraPX, renderTarget );
  9978. renderTarget.activeCubeFace = 1;
  9979. renderer.render( scene, cameraNX, renderTarget );
  9980. renderTarget.activeCubeFace = 2;
  9981. renderer.render( scene, cameraPY, renderTarget );
  9982. renderTarget.activeCubeFace = 3;
  9983. renderer.render( scene, cameraNY, renderTarget );
  9984. renderTarget.activeCubeFace = 4;
  9985. renderer.render( scene, cameraPZ, renderTarget );
  9986. renderTarget.texture.generateMipmaps = generateMipmaps;
  9987. renderTarget.activeCubeFace = 5;
  9988. renderer.render( scene, cameraNZ, renderTarget );
  9989. renderer.setRenderTarget( null );
  9990. };
  9991. };
  9992. THREE.CubeCamera.prototype = Object.create( THREE.Object3D.prototype );
  9993. THREE.CubeCamera.prototype.constructor = THREE.CubeCamera;
  9994. // File:src/cameras/OrthographicCamera.js
  9995. /**
  9996. * @author alteredq / http://alteredqualia.com/
  9997. * @author arose / http://github.com/arose
  9998. */
  9999. THREE.OrthographicCamera = function ( left, right, top, bottom, near, far ) {
  10000. THREE.Camera.call( this );
  10001. this.type = 'OrthographicCamera';
  10002. this.zoom = 1;
  10003. this.view = null;
  10004. this.left = left;
  10005. this.right = right;
  10006. this.top = top;
  10007. this.bottom = bottom;
  10008. this.near = ( near !== undefined ) ? near : 0.1;
  10009. this.far = ( far !== undefined ) ? far : 2000;
  10010. this.updateProjectionMatrix();
  10011. };
  10012. THREE.OrthographicCamera.prototype = Object.assign( Object.create( THREE.Camera.prototype ), {
  10013. constructor: THREE.OrthographicCamera,
  10014. copy: function ( source ) {
  10015. THREE.Camera.prototype.copy.call( this, source );
  10016. this.left = source.left;
  10017. this.right = source.right;
  10018. this.top = source.top;
  10019. this.bottom = source.bottom;
  10020. this.near = source.near;
  10021. this.far = source.far;
  10022. this.zoom = source.zoom;
  10023. this.view = source.view === null ? null : Object.assign( {}, source.view );
  10024. return this;
  10025. },
  10026. setViewOffset: function( fullWidth, fullHeight, x, y, width, height ) {
  10027. this.view = {
  10028. fullWidth: fullWidth,
  10029. fullHeight: fullHeight,
  10030. offsetX: x,
  10031. offsetY: y,
  10032. width: width,
  10033. height: height
  10034. };
  10035. this.updateProjectionMatrix();
  10036. },
  10037. clearViewOffset: function() {
  10038. this.view = null;
  10039. this.updateProjectionMatrix();
  10040. },
  10041. updateProjectionMatrix: function () {
  10042. var dx = ( this.right - this.left ) / ( 2 * this.zoom );
  10043. var dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  10044. var cx = ( this.right + this.left ) / 2;
  10045. var cy = ( this.top + this.bottom ) / 2;
  10046. var left = cx - dx;
  10047. var right = cx + dx;
  10048. var top = cy + dy;
  10049. var bottom = cy - dy;
  10050. if ( this.view !== null ) {
  10051. var zoomW = this.zoom / ( this.view.width / this.view.fullWidth );
  10052. var zoomH = this.zoom / ( this.view.height / this.view.fullHeight );
  10053. var scaleW = ( this.right - this.left ) / this.view.width;
  10054. var scaleH = ( this.top - this.bottom ) / this.view.height;
  10055. left += scaleW * ( this.view.offsetX / zoomW );
  10056. right = left + scaleW * ( this.view.width / zoomW );
  10057. top -= scaleH * ( this.view.offsetY / zoomH );
  10058. bottom = top - scaleH * ( this.view.height / zoomH );
  10059. }
  10060. this.projectionMatrix.makeOrthographic( left, right, top, bottom, this.near, this.far );
  10061. },
  10062. toJSON: function ( meta ) {
  10063. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  10064. data.object.zoom = this.zoom;
  10065. data.object.left = this.left;
  10066. data.object.right = this.right;
  10067. data.object.top = this.top;
  10068. data.object.bottom = this.bottom;
  10069. data.object.near = this.near;
  10070. data.object.far = this.far;
  10071. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  10072. return data;
  10073. }
  10074. } );
  10075. // File:src/cameras/PerspectiveCamera.js
  10076. /**
  10077. * @author mrdoob / http://mrdoob.com/
  10078. * @author greggman / http://games.greggman.com/
  10079. * @author zz85 / http://www.lab4games.net/zz85/blog
  10080. * @author tschw
  10081. */
  10082. THREE.PerspectiveCamera = function ( fov, aspect, near, far ) {
  10083. THREE.Camera.call( this );
  10084. this.type = 'PerspectiveCamera';
  10085. this.fov = fov !== undefined ? fov : 50;
  10086. this.zoom = 1;
  10087. this.near = near !== undefined ? near : 0.1;
  10088. this.far = far !== undefined ? far : 2000;
  10089. this.focus = 10;
  10090. this.aspect = aspect !== undefined ? aspect : 1;
  10091. this.view = null;
  10092. this.filmGauge = 35; // width of the film (default in millimeters)
  10093. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  10094. this.updateProjectionMatrix();
  10095. };
  10096. THREE.PerspectiveCamera.prototype = Object.assign( Object.create( THREE.Camera.prototype ), {
  10097. constructor: THREE.PerspectiveCamera,
  10098. copy: function ( source ) {
  10099. THREE.Camera.prototype.copy.call( this, source );
  10100. this.fov = source.fov;
  10101. this.zoom = source.zoom;
  10102. this.near = source.near;
  10103. this.far = source.far;
  10104. this.focus = source.focus;
  10105. this.aspect = source.aspect;
  10106. this.view = source.view === null ? null : Object.assign( {}, source.view );
  10107. this.filmGauge = source.filmGauge;
  10108. this.filmOffset = source.filmOffset;
  10109. return this;
  10110. },
  10111. /**
  10112. * Sets the FOV by focal length in respect to the current .filmGauge.
  10113. *
  10114. * The default film gauge is 35, so that the focal length can be specified for
  10115. * a 35mm (full frame) camera.
  10116. *
  10117. * Values for focal length and film gauge must have the same unit.
  10118. */
  10119. setFocalLength: function ( focalLength ) {
  10120. // see http://www.bobatkins.com/photography/technical/field_of_view.html
  10121. var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  10122. this.fov = THREE.Math.RAD2DEG * 2 * Math.atan( vExtentSlope );
  10123. this.updateProjectionMatrix();
  10124. },
  10125. /**
  10126. * Calculates the focal length from the current .fov and .filmGauge.
  10127. */
  10128. getFocalLength: function () {
  10129. var vExtentSlope = Math.tan( THREE.Math.DEG2RAD * 0.5 * this.fov );
  10130. return 0.5 * this.getFilmHeight() / vExtentSlope;
  10131. },
  10132. getEffectiveFOV: function () {
  10133. return THREE.Math.RAD2DEG * 2 * Math.atan(
  10134. Math.tan( THREE.Math.DEG2RAD * 0.5 * this.fov ) / this.zoom );
  10135. },
  10136. getFilmWidth: function () {
  10137. // film not completely covered in portrait format (aspect < 1)
  10138. return this.filmGauge * Math.min( this.aspect, 1 );
  10139. },
  10140. getFilmHeight: function () {
  10141. // film not completely covered in landscape format (aspect > 1)
  10142. return this.filmGauge / Math.max( this.aspect, 1 );
  10143. },
  10144. /**
  10145. * Sets an offset in a larger frustum. This is useful for multi-window or
  10146. * multi-monitor/multi-machine setups.
  10147. *
  10148. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  10149. * the monitors are in grid like this
  10150. *
  10151. * +---+---+---+
  10152. * | A | B | C |
  10153. * +---+---+---+
  10154. * | D | E | F |
  10155. * +---+---+---+
  10156. *
  10157. * then for each monitor you would call it like this
  10158. *
  10159. * var w = 1920;
  10160. * var h = 1080;
  10161. * var fullWidth = w * 3;
  10162. * var fullHeight = h * 2;
  10163. *
  10164. * --A--
  10165. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  10166. * --B--
  10167. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  10168. * --C--
  10169. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  10170. * --D--
  10171. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  10172. * --E--
  10173. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  10174. * --F--
  10175. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  10176. *
  10177. * Note there is no reason monitors have to be the same size or in a grid.
  10178. */
  10179. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  10180. this.aspect = fullWidth / fullHeight;
  10181. this.view = {
  10182. fullWidth: fullWidth,
  10183. fullHeight: fullHeight,
  10184. offsetX: x,
  10185. offsetY: y,
  10186. width: width,
  10187. height: height
  10188. };
  10189. this.updateProjectionMatrix();
  10190. },
  10191. clearViewOffset: function() {
  10192. this.view = null;
  10193. this.updateProjectionMatrix();
  10194. },
  10195. updateProjectionMatrix: function () {
  10196. var near = this.near,
  10197. top = near * Math.tan(
  10198. THREE.Math.DEG2RAD * 0.5 * this.fov ) / this.zoom,
  10199. height = 2 * top,
  10200. width = this.aspect * height,
  10201. left = - 0.5 * width,
  10202. view = this.view;
  10203. if ( view !== null ) {
  10204. var fullWidth = view.fullWidth,
  10205. fullHeight = view.fullHeight;
  10206. left += view.offsetX * width / fullWidth;
  10207. top -= view.offsetY * height / fullHeight;
  10208. width *= view.width / fullWidth;
  10209. height *= view.height / fullHeight;
  10210. }
  10211. var skew = this.filmOffset;
  10212. if ( skew !== 0 ) left += near * skew / this.getFilmWidth();
  10213. this.projectionMatrix.makeFrustum(
  10214. left, left + width, top - height, top, near, this.far );
  10215. },
  10216. toJSON: function ( meta ) {
  10217. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  10218. data.object.fov = this.fov;
  10219. data.object.zoom = this.zoom;
  10220. data.object.near = this.near;
  10221. data.object.far = this.far;
  10222. data.object.focus = this.focus;
  10223. data.object.aspect = this.aspect;
  10224. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  10225. data.object.filmGauge = this.filmGauge;
  10226. data.object.filmOffset = this.filmOffset;
  10227. return data;
  10228. }
  10229. } );
  10230. // File:src/cameras/StereoCamera.js
  10231. /**
  10232. * @author mrdoob / http://mrdoob.com/
  10233. */
  10234. THREE.StereoCamera = function () {
  10235. this.type = 'StereoCamera';
  10236. this.aspect = 1;
  10237. this.cameraL = new THREE.PerspectiveCamera();
  10238. this.cameraL.layers.enable( 1 );
  10239. this.cameraL.matrixAutoUpdate = false;
  10240. this.cameraR = new THREE.PerspectiveCamera();
  10241. this.cameraR.layers.enable( 2 );
  10242. this.cameraR.matrixAutoUpdate = false;
  10243. };
  10244. Object.assign( THREE.StereoCamera.prototype, {
  10245. update: ( function () {
  10246. var focus, fov, aspect, near, far;
  10247. var eyeRight = new THREE.Matrix4();
  10248. var eyeLeft = new THREE.Matrix4();
  10249. return function update( camera ) {
  10250. var needsUpdate = focus !== camera.focus || fov !== camera.fov ||
  10251. aspect !== camera.aspect * this.aspect || near !== camera.near ||
  10252. far !== camera.far;
  10253. if ( needsUpdate ) {
  10254. focus = camera.focus;
  10255. fov = camera.fov;
  10256. aspect = camera.aspect * this.aspect;
  10257. near = camera.near;
  10258. far = camera.far;
  10259. // Off-axis stereoscopic effect based on
  10260. // http://paulbourke.net/stereographics/stereorender/
  10261. var projectionMatrix = camera.projectionMatrix.clone();
  10262. var eyeSep = 0.064 / 2;
  10263. var eyeSepOnProjection = eyeSep * near / focus;
  10264. var ymax = near * Math.tan( THREE.Math.DEG2RAD * fov * 0.5 );
  10265. var xmin, xmax;
  10266. // translate xOffset
  10267. eyeLeft.elements[ 12 ] = - eyeSep;
  10268. eyeRight.elements[ 12 ] = eyeSep;
  10269. // for left eye
  10270. xmin = - ymax * aspect + eyeSepOnProjection;
  10271. xmax = ymax * aspect + eyeSepOnProjection;
  10272. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  10273. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  10274. this.cameraL.projectionMatrix.copy( projectionMatrix );
  10275. // for right eye
  10276. xmin = - ymax * aspect - eyeSepOnProjection;
  10277. xmax = ymax * aspect - eyeSepOnProjection;
  10278. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  10279. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  10280. this.cameraR.projectionMatrix.copy( projectionMatrix );
  10281. }
  10282. this.cameraL.matrixWorld.copy( camera.matrixWorld ).multiply( eyeLeft );
  10283. this.cameraR.matrixWorld.copy( camera.matrixWorld ).multiply( eyeRight );
  10284. };
  10285. } )()
  10286. } );
  10287. // File:src/lights/Light.js
  10288. /**
  10289. * @author mrdoob / http://mrdoob.com/
  10290. * @author alteredq / http://alteredqualia.com/
  10291. */
  10292. THREE.Light = function ( color, intensity ) {
  10293. THREE.Object3D.call( this );
  10294. this.type = 'Light';
  10295. this.color = new THREE.Color( color );
  10296. this.intensity = intensity !== undefined ? intensity : 1;
  10297. this.receiveShadow = undefined;
  10298. };
  10299. THREE.Light.prototype = Object.assign( Object.create( THREE.Object3D.prototype ), {
  10300. constructor: THREE.Light,
  10301. copy: function ( source ) {
  10302. THREE.Object3D.prototype.copy.call( this, source );
  10303. this.color.copy( source.color );
  10304. this.intensity = source.intensity;
  10305. return this;
  10306. },
  10307. toJSON: function ( meta ) {
  10308. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  10309. data.object.color = this.color.getHex();
  10310. data.object.intensity = this.intensity;
  10311. if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();
  10312. if ( this.distance !== undefined ) data.object.distance = this.distance;
  10313. if ( this.angle !== undefined ) data.object.angle = this.angle;
  10314. if ( this.decay !== undefined ) data.object.decay = this.decay;
  10315. if ( this.penumbra !== undefined ) data.object.penumbra = this.penumbra;
  10316. return data;
  10317. }
  10318. } );
  10319. // File:src/lights/LightShadow.js
  10320. /**
  10321. * @author mrdoob / http://mrdoob.com/
  10322. */
  10323. THREE.LightShadow = function ( camera ) {
  10324. this.camera = camera;
  10325. this.bias = 0;
  10326. this.radius = 1;
  10327. this.mapSize = new THREE.Vector2( 512, 512 );
  10328. this.map = null;
  10329. this.matrix = new THREE.Matrix4();
  10330. };
  10331. Object.assign( THREE.LightShadow.prototype, {
  10332. copy: function ( source ) {
  10333. this.camera = source.camera.clone();
  10334. this.bias = source.bias;
  10335. this.radius = source.radius;
  10336. this.mapSize.copy( source.mapSize );
  10337. return this;
  10338. },
  10339. clone: function () {
  10340. return new this.constructor().copy( this );
  10341. }
  10342. } );
  10343. // File:src/lights/AmbientLight.js
  10344. /**
  10345. * @author mrdoob / http://mrdoob.com/
  10346. */
  10347. THREE.AmbientLight = function ( color, intensity ) {
  10348. THREE.Light.call( this, color, intensity );
  10349. this.type = 'AmbientLight';
  10350. this.castShadow = undefined;
  10351. };
  10352. THREE.AmbientLight.prototype = Object.assign( Object.create( THREE.Light.prototype ), {
  10353. constructor: THREE.AmbientLight
  10354. } );
  10355. // File:src/lights/DirectionalLight.js
  10356. /**
  10357. * @author mrdoob / http://mrdoob.com/
  10358. * @author alteredq / http://alteredqualia.com/
  10359. */
  10360. THREE.DirectionalLight = function ( color, intensity ) {
  10361. THREE.Light.call( this, color, intensity );
  10362. this.type = 'DirectionalLight';
  10363. this.position.set( 0, 1, 0 );
  10364. this.updateMatrix();
  10365. this.target = new THREE.Object3D();
  10366. this.shadow = new THREE.DirectionalLightShadow();
  10367. };
  10368. THREE.DirectionalLight.prototype = Object.assign( Object.create( THREE.Light.prototype ), {
  10369. constructor: THREE.DirectionalLight,
  10370. copy: function ( source ) {
  10371. THREE.Light.prototype.copy.call( this, source );
  10372. this.target = source.target.clone();
  10373. this.shadow = source.shadow.clone();
  10374. return this;
  10375. }
  10376. } );
  10377. // File:src/lights/DirectionalLightShadow.js
  10378. /**
  10379. * @author mrdoob / http://mrdoob.com/
  10380. */
  10381. THREE.DirectionalLightShadow = function ( light ) {
  10382. THREE.LightShadow.call( this, new THREE.OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) );
  10383. };
  10384. THREE.DirectionalLightShadow.prototype = Object.assign( Object.create( THREE.LightShadow.prototype ), {
  10385. constructor: THREE.DirectionalLightShadow
  10386. } );
  10387. // File:src/lights/HemisphereLight.js
  10388. /**
  10389. * @author alteredq / http://alteredqualia.com/
  10390. */
  10391. THREE.HemisphereLight = function ( skyColor, groundColor, intensity ) {
  10392. THREE.Light.call( this, skyColor, intensity );
  10393. this.type = 'HemisphereLight';
  10394. this.castShadow = undefined;
  10395. this.position.set( 0, 1, 0 );
  10396. this.updateMatrix();
  10397. this.groundColor = new THREE.Color( groundColor );
  10398. };
  10399. THREE.HemisphereLight.prototype = Object.assign( Object.create( THREE.Light.prototype ), {
  10400. constructor: THREE.HemisphereLight,
  10401. copy: function ( source ) {
  10402. THREE.Light.prototype.copy.call( this, source );
  10403. this.groundColor.copy( source.groundColor );
  10404. return this;
  10405. }
  10406. } );
  10407. // File:src/lights/PointLight.js
  10408. /**
  10409. * @author mrdoob / http://mrdoob.com/
  10410. */
  10411. THREE.PointLight = function ( color, intensity, distance, decay ) {
  10412. THREE.Light.call( this, color, intensity );
  10413. this.type = 'PointLight';
  10414. Object.defineProperty( this, 'power', {
  10415. get: function () {
  10416. // intensity = power per solid angle.
  10417. // ref: equation (15) from http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
  10418. return this.intensity * 4 * Math.PI;
  10419. },
  10420. set: function ( power ) {
  10421. // intensity = power per solid angle.
  10422. // ref: equation (15) from http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
  10423. this.intensity = power / ( 4 * Math.PI );
  10424. }
  10425. } );
  10426. this.distance = ( distance !== undefined ) ? distance : 0;
  10427. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  10428. this.shadow = new THREE.LightShadow( new THREE.PerspectiveCamera( 90, 1, 0.5, 500 ) );
  10429. };
  10430. THREE.PointLight.prototype = Object.assign( Object.create( THREE.Light.prototype ), {
  10431. constructor: THREE.PointLight,
  10432. copy: function ( source ) {
  10433. THREE.Light.prototype.copy.call( this, source );
  10434. this.distance = source.distance;
  10435. this.decay = source.decay;
  10436. this.shadow = source.shadow.clone();
  10437. return this;
  10438. }
  10439. } );
  10440. // File:src/lights/SpotLight.js
  10441. /**
  10442. * @author alteredq / http://alteredqualia.com/
  10443. */
  10444. THREE.SpotLight = function ( color, intensity, distance, angle, penumbra, decay ) {
  10445. THREE.Light.call( this, color, intensity );
  10446. this.type = 'SpotLight';
  10447. this.position.set( 0, 1, 0 );
  10448. this.updateMatrix();
  10449. this.target = new THREE.Object3D();
  10450. Object.defineProperty( this, 'power', {
  10451. get: function () {
  10452. // intensity = power per solid angle.
  10453. // ref: equation (17) from http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
  10454. return this.intensity * Math.PI;
  10455. },
  10456. set: function ( power ) {
  10457. // intensity = power per solid angle.
  10458. // ref: equation (17) from http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
  10459. this.intensity = power / Math.PI;
  10460. }
  10461. } );
  10462. this.distance = ( distance !== undefined ) ? distance : 0;
  10463. this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
  10464. this.penumbra = ( penumbra !== undefined ) ? penumbra : 0;
  10465. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  10466. this.shadow = new THREE.SpotLightShadow();
  10467. };
  10468. THREE.SpotLight.prototype = Object.assign( Object.create( THREE.Light.prototype ), {
  10469. constructor: THREE.SpotLight,
  10470. copy: function ( source ) {
  10471. THREE.Light.prototype.copy.call( this, source );
  10472. this.distance = source.distance;
  10473. this.angle = source.angle;
  10474. this.penumbra = source.penumbra;
  10475. this.decay = source.decay;
  10476. this.target = source.target.clone();
  10477. this.shadow = source.shadow.clone();
  10478. return this;
  10479. }
  10480. } );
  10481. // File:src/lights/SpotLightShadow.js
  10482. /**
  10483. * @author mrdoob / http://mrdoob.com/
  10484. */
  10485. THREE.SpotLightShadow = function () {
  10486. THREE.LightShadow.call( this, new THREE.PerspectiveCamera( 50, 1, 0.5, 500 ) );
  10487. };
  10488. THREE.SpotLightShadow.prototype = Object.assign( Object.create( THREE.LightShadow.prototype ), {
  10489. constructor: THREE.SpotLightShadow,
  10490. update: function ( light ) {
  10491. var fov = THREE.Math.RAD2DEG * 2 * light.angle;
  10492. var aspect = this.mapSize.width / this.mapSize.height;
  10493. var far = light.distance || 500;
  10494. var camera = this.camera;
  10495. if ( fov !== camera.fov || aspect !== camera.aspect || far !== camera.far ) {
  10496. camera.fov = fov;
  10497. camera.aspect = aspect;
  10498. camera.far = far;
  10499. camera.updateProjectionMatrix();
  10500. }
  10501. }
  10502. } );
  10503. // File:src/loaders/AudioLoader.js
  10504. /**
  10505. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  10506. */
  10507. THREE.AudioLoader = function ( manager ) {
  10508. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10509. };
  10510. Object.assign( THREE.AudioLoader.prototype, {
  10511. load: function ( url, onLoad, onProgress, onError ) {
  10512. var loader = new THREE.XHRLoader( this.manager );
  10513. loader.setResponseType( 'arraybuffer' );
  10514. loader.load( url, function ( buffer ) {
  10515. var context = THREE.AudioContext;
  10516. context.decodeAudioData( buffer, function ( audioBuffer ) {
  10517. onLoad( audioBuffer );
  10518. } );
  10519. }, onProgress, onError );
  10520. }
  10521. } );
  10522. // File:src/loaders/Cache.js
  10523. /**
  10524. * @author mrdoob / http://mrdoob.com/
  10525. */
  10526. THREE.Cache = {
  10527. enabled: false,
  10528. files: {},
  10529. add: function ( key, file ) {
  10530. if ( this.enabled === false ) return;
  10531. // console.log( 'THREE.Cache', 'Adding key:', key );
  10532. this.files[ key ] = file;
  10533. },
  10534. get: function ( key ) {
  10535. if ( this.enabled === false ) return;
  10536. // console.log( 'THREE.Cache', 'Checking key:', key );
  10537. return this.files[ key ];
  10538. },
  10539. remove: function ( key ) {
  10540. delete this.files[ key ];
  10541. },
  10542. clear: function () {
  10543. this.files = {};
  10544. }
  10545. };
  10546. // File:src/loaders/Loader.js
  10547. /**
  10548. * @author alteredq / http://alteredqualia.com/
  10549. */
  10550. THREE.Loader = function () {
  10551. this.onLoadStart = function () {};
  10552. this.onLoadProgress = function () {};
  10553. this.onLoadComplete = function () {};
  10554. };
  10555. THREE.Loader.prototype = {
  10556. constructor: THREE.Loader,
  10557. crossOrigin: undefined,
  10558. extractUrlBase: function ( url ) {
  10559. var parts = url.split( '/' );
  10560. if ( parts.length === 1 ) return './';
  10561. parts.pop();
  10562. return parts.join( '/' ) + '/';
  10563. },
  10564. initMaterials: function ( materials, texturePath, crossOrigin ) {
  10565. var array = [];
  10566. for ( var i = 0; i < materials.length; ++ i ) {
  10567. array[ i ] = this.createMaterial( materials[ i ], texturePath, crossOrigin );
  10568. }
  10569. return array;
  10570. },
  10571. createMaterial: ( function () {
  10572. var color, textureLoader, materialLoader;
  10573. return function createMaterial( m, texturePath, crossOrigin ) {
  10574. if ( color === undefined ) color = new THREE.Color();
  10575. if ( textureLoader === undefined ) textureLoader = new THREE.TextureLoader();
  10576. if ( materialLoader === undefined ) materialLoader = new THREE.MaterialLoader();
  10577. // convert from old material format
  10578. var textures = {};
  10579. function loadTexture( path, repeat, offset, wrap, anisotropy ) {
  10580. var fullPath = texturePath + path;
  10581. var loader = THREE.Loader.Handlers.get( fullPath );
  10582. var texture;
  10583. if ( loader !== null ) {
  10584. texture = loader.load( fullPath );
  10585. } else {
  10586. textureLoader.setCrossOrigin( crossOrigin );
  10587. texture = textureLoader.load( fullPath );
  10588. }
  10589. if ( repeat !== undefined ) {
  10590. texture.repeat.fromArray( repeat );
  10591. if ( repeat[ 0 ] !== 1 ) texture.wrapS = THREE.RepeatWrapping;
  10592. if ( repeat[ 1 ] !== 1 ) texture.wrapT = THREE.RepeatWrapping;
  10593. }
  10594. if ( offset !== undefined ) {
  10595. texture.offset.fromArray( offset );
  10596. }
  10597. if ( wrap !== undefined ) {
  10598. if ( wrap[ 0 ] === 'repeat' ) texture.wrapS = THREE.RepeatWrapping;
  10599. if ( wrap[ 0 ] === 'mirror' ) texture.wrapS = THREE.MirroredRepeatWrapping;
  10600. if ( wrap[ 1 ] === 'repeat' ) texture.wrapT = THREE.RepeatWrapping;
  10601. if ( wrap[ 1 ] === 'mirror' ) texture.wrapT = THREE.MirroredRepeatWrapping;
  10602. }
  10603. if ( anisotropy !== undefined ) {
  10604. texture.anisotropy = anisotropy;
  10605. }
  10606. var uuid = THREE.Math.generateUUID();
  10607. textures[ uuid ] = texture;
  10608. return uuid;
  10609. }
  10610. //
  10611. var json = {
  10612. uuid: THREE.Math.generateUUID(),
  10613. type: 'MeshLambertMaterial'
  10614. };
  10615. for ( var name in m ) {
  10616. var value = m[ name ];
  10617. switch ( name ) {
  10618. case 'DbgColor':
  10619. case 'DbgIndex':
  10620. case 'opticalDensity':
  10621. case 'illumination':
  10622. break;
  10623. case 'DbgName':
  10624. json.name = value;
  10625. break;
  10626. case 'blending':
  10627. json.blending = THREE[ value ];
  10628. break;
  10629. case 'colorAmbient':
  10630. case 'mapAmbient':
  10631. console.warn( 'THREE.Loader.createMaterial:', name, 'is no longer supported.' );
  10632. break;
  10633. case 'colorDiffuse':
  10634. json.color = color.fromArray( value ).getHex();
  10635. break;
  10636. case 'colorSpecular':
  10637. json.specular = color.fromArray( value ).getHex();
  10638. break;
  10639. case 'colorEmissive':
  10640. json.emissive = color.fromArray( value ).getHex();
  10641. break;
  10642. case 'specularCoef':
  10643. json.shininess = value;
  10644. break;
  10645. case 'shading':
  10646. if ( value.toLowerCase() === 'basic' ) json.type = 'MeshBasicMaterial';
  10647. if ( value.toLowerCase() === 'phong' ) json.type = 'MeshPhongMaterial';
  10648. if ( value.toLowerCase() === 'standard' ) json.type = 'MeshStandardMaterial';
  10649. break;
  10650. case 'mapDiffuse':
  10651. json.map = loadTexture( value, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap, m.mapDiffuseAnisotropy );
  10652. break;
  10653. case 'mapDiffuseRepeat':
  10654. case 'mapDiffuseOffset':
  10655. case 'mapDiffuseWrap':
  10656. case 'mapDiffuseAnisotropy':
  10657. break;
  10658. case 'mapEmissive':
  10659. json.emissiveMap = loadTexture( value, m.mapEmissiveRepeat, m.mapEmissiveOffset, m.mapEmissiveWrap, m.mapEmissiveAnisotropy );
  10660. break;
  10661. case 'mapEmissiveRepeat':
  10662. case 'mapEmissiveOffset':
  10663. case 'mapEmissiveWrap':
  10664. case 'mapEmissiveAnisotropy':
  10665. break;
  10666. case 'mapLight':
  10667. json.lightMap = loadTexture( value, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap, m.mapLightAnisotropy );
  10668. break;
  10669. case 'mapLightRepeat':
  10670. case 'mapLightOffset':
  10671. case 'mapLightWrap':
  10672. case 'mapLightAnisotropy':
  10673. break;
  10674. case 'mapAO':
  10675. json.aoMap = loadTexture( value, m.mapAORepeat, m.mapAOOffset, m.mapAOWrap, m.mapAOAnisotropy );
  10676. break;
  10677. case 'mapAORepeat':
  10678. case 'mapAOOffset':
  10679. case 'mapAOWrap':
  10680. case 'mapAOAnisotropy':
  10681. break;
  10682. case 'mapBump':
  10683. json.bumpMap = loadTexture( value, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap, m.mapBumpAnisotropy );
  10684. break;
  10685. case 'mapBumpScale':
  10686. json.bumpScale = value;
  10687. break;
  10688. case 'mapBumpRepeat':
  10689. case 'mapBumpOffset':
  10690. case 'mapBumpWrap':
  10691. case 'mapBumpAnisotropy':
  10692. break;
  10693. case 'mapNormal':
  10694. json.normalMap = loadTexture( value, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap, m.mapNormalAnisotropy );
  10695. break;
  10696. case 'mapNormalFactor':
  10697. json.normalScale = [ value, value ];
  10698. break;
  10699. case 'mapNormalRepeat':
  10700. case 'mapNormalOffset':
  10701. case 'mapNormalWrap':
  10702. case 'mapNormalAnisotropy':
  10703. break;
  10704. case 'mapSpecular':
  10705. json.specularMap = loadTexture( value, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap, m.mapSpecularAnisotropy );
  10706. break;
  10707. case 'mapSpecularRepeat':
  10708. case 'mapSpecularOffset':
  10709. case 'mapSpecularWrap':
  10710. case 'mapSpecularAnisotropy':
  10711. break;
  10712. case 'mapMetalness':
  10713. json.metalnessMap = loadTexture( value, m.mapMetalnessRepeat, m.mapMetalnessOffset, m.mapMetalnessWrap, m.mapMetalnessAnisotropy );
  10714. break;
  10715. case 'mapMetalnessRepeat':
  10716. case 'mapMetalnessOffset':
  10717. case 'mapMetalnessWrap':
  10718. case 'mapMetalnessAnisotropy':
  10719. break;
  10720. case 'mapRoughness':
  10721. json.roughnessMap = loadTexture( value, m.mapRoughnessRepeat, m.mapRoughnessOffset, m.mapRoughnessWrap, m.mapRoughnessAnisotropy );
  10722. break;
  10723. case 'mapRoughnessRepeat':
  10724. case 'mapRoughnessOffset':
  10725. case 'mapRoughnessWrap':
  10726. case 'mapRoughnessAnisotropy':
  10727. break;
  10728. case 'mapAlpha':
  10729. json.alphaMap = loadTexture( value, m.mapAlphaRepeat, m.mapAlphaOffset, m.mapAlphaWrap, m.mapAlphaAnisotropy );
  10730. break;
  10731. case 'mapAlphaRepeat':
  10732. case 'mapAlphaOffset':
  10733. case 'mapAlphaWrap':
  10734. case 'mapAlphaAnisotropy':
  10735. break;
  10736. case 'flipSided':
  10737. json.side = THREE.BackSide;
  10738. break;
  10739. case 'doubleSided':
  10740. json.side = THREE.DoubleSide;
  10741. break;
  10742. case 'transparency':
  10743. console.warn( 'THREE.Loader.createMaterial: transparency has been renamed to opacity' );
  10744. json.opacity = value;
  10745. break;
  10746. case 'depthTest':
  10747. case 'depthWrite':
  10748. case 'colorWrite':
  10749. case 'opacity':
  10750. case 'reflectivity':
  10751. case 'transparent':
  10752. case 'visible':
  10753. case 'wireframe':
  10754. json[ name ] = value;
  10755. break;
  10756. case 'vertexColors':
  10757. if ( value === true ) json.vertexColors = THREE.VertexColors;
  10758. if ( value === 'face' ) json.vertexColors = THREE.FaceColors;
  10759. break;
  10760. default:
  10761. console.error( 'THREE.Loader.createMaterial: Unsupported', name, value );
  10762. break;
  10763. }
  10764. }
  10765. if ( json.type === 'MeshBasicMaterial' ) delete json.emissive;
  10766. if ( json.type !== 'MeshPhongMaterial' ) delete json.specular;
  10767. if ( json.opacity < 1 ) json.transparent = true;
  10768. materialLoader.setTextures( textures );
  10769. return materialLoader.parse( json );
  10770. };
  10771. } )()
  10772. };
  10773. THREE.Loader.Handlers = {
  10774. handlers: [],
  10775. add: function ( regex, loader ) {
  10776. this.handlers.push( regex, loader );
  10777. },
  10778. get: function ( file ) {
  10779. var handlers = this.handlers;
  10780. for ( var i = 0, l = handlers.length; i < l; i += 2 ) {
  10781. var regex = handlers[ i ];
  10782. var loader = handlers[ i + 1 ];
  10783. if ( regex.test( file ) ) {
  10784. return loader;
  10785. }
  10786. }
  10787. return null;
  10788. }
  10789. };
  10790. // File:src/loaders/XHRLoader.js
  10791. /**
  10792. * @author mrdoob / http://mrdoob.com/
  10793. */
  10794. THREE.XHRLoader = function ( manager ) {
  10795. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10796. };
  10797. Object.assign( THREE.XHRLoader.prototype, {
  10798. load: function ( url, onLoad, onProgress, onError ) {
  10799. if ( this.path !== undefined ) url = this.path + url;
  10800. var scope = this;
  10801. var cached = THREE.Cache.get( url );
  10802. if ( cached !== undefined ) {
  10803. scope.manager.itemStart( url );
  10804. setTimeout( function () {
  10805. if ( onLoad ) onLoad( cached );
  10806. scope.manager.itemEnd( url );
  10807. }, 0 );
  10808. return cached;
  10809. }
  10810. var request = new XMLHttpRequest();
  10811. request.overrideMimeType( 'text/plain' );
  10812. request.open( 'GET', url, true );
  10813. request.addEventListener( 'load', function ( event ) {
  10814. var response = event.target.response;
  10815. THREE.Cache.add( url, response );
  10816. if ( this.status === 200 ) {
  10817. if ( onLoad ) onLoad( response );
  10818. scope.manager.itemEnd( url );
  10819. } else if ( this.status === 0 ) {
  10820. // Some browsers return HTTP Status 0 when using non-http protocol
  10821. // e.g. 'file://' or 'data://'. Handle as success.
  10822. console.warn( 'THREE.XHRLoader: HTTP Status 0 received.' );
  10823. if ( onLoad ) onLoad( response );
  10824. scope.manager.itemEnd( url );
  10825. } else {
  10826. if ( onError ) onError( event );
  10827. scope.manager.itemError( url );
  10828. }
  10829. }, false );
  10830. if ( onProgress !== undefined ) {
  10831. request.addEventListener( 'progress', function ( event ) {
  10832. onProgress( event );
  10833. }, false );
  10834. }
  10835. request.addEventListener( 'error', function ( event ) {
  10836. if ( onError ) onError( event );
  10837. scope.manager.itemError( url );
  10838. }, false );
  10839. if ( this.responseType !== undefined ) request.responseType = this.responseType;
  10840. if ( this.withCredentials !== undefined ) request.withCredentials = this.withCredentials;
  10841. request.send( null );
  10842. scope.manager.itemStart( url );
  10843. return request;
  10844. },
  10845. setPath: function ( value ) {
  10846. this.path = value;
  10847. return this;
  10848. },
  10849. setResponseType: function ( value ) {
  10850. this.responseType = value;
  10851. return this;
  10852. },
  10853. setWithCredentials: function ( value ) {
  10854. this.withCredentials = value;
  10855. return this;
  10856. }
  10857. } );
  10858. // File:src/loaders/FontLoader.js
  10859. /**
  10860. * @author mrdoob / http://mrdoob.com/
  10861. */
  10862. THREE.FontLoader = function ( manager ) {
  10863. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10864. };
  10865. Object.assign( THREE.FontLoader.prototype, {
  10866. load: function ( url, onLoad, onProgress, onError ) {
  10867. var scope = this;
  10868. var loader = new THREE.XHRLoader( this.manager );
  10869. loader.load( url, function ( text ) {
  10870. var json;
  10871. try {
  10872. json = JSON.parse( text );
  10873. } catch ( e ) {
  10874. console.warn( 'THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.' );
  10875. json = JSON.parse( text.substring( 65, text.length - 2 ) );
  10876. }
  10877. var font = scope.parse( json );
  10878. if ( onLoad ) onLoad( font );
  10879. }, onProgress, onError );
  10880. },
  10881. parse: function ( json ) {
  10882. return new THREE.Font( json );
  10883. }
  10884. } );
  10885. // File:src/loaders/ImageLoader.js
  10886. /**
  10887. * @author mrdoob / http://mrdoob.com/
  10888. */
  10889. THREE.ImageLoader = function ( manager ) {
  10890. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10891. };
  10892. Object.assign( THREE.ImageLoader.prototype, {
  10893. load: function ( url, onLoad, onProgress, onError ) {
  10894. var scope = this;
  10895. var image = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'img' );
  10896. image.onload = function () {
  10897. URL.revokeObjectURL( image.src );
  10898. if ( onLoad ) onLoad( image );
  10899. scope.manager.itemEnd( url );
  10900. };
  10901. if ( url.indexOf( 'data:' ) === 0 ) {
  10902. image.src = url;
  10903. } else {
  10904. var loader = new THREE.XHRLoader();
  10905. loader.setPath( this.path );
  10906. loader.setResponseType( 'blob' );
  10907. loader.load( url, function ( blob ) {
  10908. image.src = URL.createObjectURL( blob );
  10909. }, onProgress, onError );
  10910. }
  10911. scope.manager.itemStart( url );
  10912. return image;
  10913. },
  10914. setCrossOrigin: function ( value ) {
  10915. this.crossOrigin = value;
  10916. return this;
  10917. },
  10918. setPath: function ( value ) {
  10919. this.path = value;
  10920. return this;
  10921. }
  10922. } );
  10923. // File:src/loaders/JSONLoader.js
  10924. /**
  10925. * @author mrdoob / http://mrdoob.com/
  10926. * @author alteredq / http://alteredqualia.com/
  10927. */
  10928. THREE.JSONLoader = function ( manager ) {
  10929. if ( typeof manager === 'boolean' ) {
  10930. console.warn( 'THREE.JSONLoader: showStatus parameter has been removed from constructor.' );
  10931. manager = undefined;
  10932. }
  10933. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10934. this.withCredentials = false;
  10935. };
  10936. Object.assign( THREE.JSONLoader.prototype, {
  10937. load: function( url, onLoad, onProgress, onError ) {
  10938. var scope = this;
  10939. var texturePath = this.texturePath && ( typeof this.texturePath === "string" ) ? this.texturePath : THREE.Loader.prototype.extractUrlBase( url );
  10940. var loader = new THREE.XHRLoader( this.manager );
  10941. loader.setWithCredentials( this.withCredentials );
  10942. loader.load( url, function ( text ) {
  10943. var json = JSON.parse( text );
  10944. var metadata = json.metadata;
  10945. if ( metadata !== undefined ) {
  10946. var type = metadata.type;
  10947. if ( type !== undefined ) {
  10948. if ( type.toLowerCase() === 'object' ) {
  10949. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.ObjectLoader instead.' );
  10950. return;
  10951. }
  10952. if ( type.toLowerCase() === 'scene' ) {
  10953. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.SceneLoader instead.' );
  10954. return;
  10955. }
  10956. }
  10957. }
  10958. var object = scope.parse( json, texturePath );
  10959. onLoad( object.geometry, object.materials );
  10960. }, onProgress, onError );
  10961. },
  10962. setTexturePath: function ( value ) {
  10963. this.texturePath = value;
  10964. },
  10965. parse: function ( json, texturePath ) {
  10966. var geometry = new THREE.Geometry(),
  10967. scale = ( json.scale !== undefined ) ? 1.0 / json.scale : 1.0;
  10968. parseModel( scale );
  10969. parseSkin();
  10970. parseMorphing( scale );
  10971. parseAnimations();
  10972. geometry.computeFaceNormals();
  10973. geometry.computeBoundingSphere();
  10974. function parseModel( scale ) {
  10975. function isBitSet( value, position ) {
  10976. return value & ( 1 << position );
  10977. }
  10978. var i, j, fi,
  10979. offset, zLength,
  10980. colorIndex, normalIndex, uvIndex, materialIndex,
  10981. type,
  10982. isQuad,
  10983. hasMaterial,
  10984. hasFaceVertexUv,
  10985. hasFaceNormal, hasFaceVertexNormal,
  10986. hasFaceColor, hasFaceVertexColor,
  10987. vertex, face, faceA, faceB, hex, normal,
  10988. uvLayer, uv, u, v,
  10989. faces = json.faces,
  10990. vertices = json.vertices,
  10991. normals = json.normals,
  10992. colors = json.colors,
  10993. nUvLayers = 0;
  10994. if ( json.uvs !== undefined ) {
  10995. // disregard empty arrays
  10996. for ( i = 0; i < json.uvs.length; i ++ ) {
  10997. if ( json.uvs[ i ].length ) nUvLayers ++;
  10998. }
  10999. for ( i = 0; i < nUvLayers; i ++ ) {
  11000. geometry.faceVertexUvs[ i ] = [];
  11001. }
  11002. }
  11003. offset = 0;
  11004. zLength = vertices.length;
  11005. while ( offset < zLength ) {
  11006. vertex = new THREE.Vector3();
  11007. vertex.x = vertices[ offset ++ ] * scale;
  11008. vertex.y = vertices[ offset ++ ] * scale;
  11009. vertex.z = vertices[ offset ++ ] * scale;
  11010. geometry.vertices.push( vertex );
  11011. }
  11012. offset = 0;
  11013. zLength = faces.length;
  11014. while ( offset < zLength ) {
  11015. type = faces[ offset ++ ];
  11016. isQuad = isBitSet( type, 0 );
  11017. hasMaterial = isBitSet( type, 1 );
  11018. hasFaceVertexUv = isBitSet( type, 3 );
  11019. hasFaceNormal = isBitSet( type, 4 );
  11020. hasFaceVertexNormal = isBitSet( type, 5 );
  11021. hasFaceColor = isBitSet( type, 6 );
  11022. hasFaceVertexColor = isBitSet( type, 7 );
  11023. // console.log("type", type, "bits", isQuad, hasMaterial, hasFaceVertexUv, hasFaceNormal, hasFaceVertexNormal, hasFaceColor, hasFaceVertexColor);
  11024. if ( isQuad ) {
  11025. faceA = new THREE.Face3();
  11026. faceA.a = faces[ offset ];
  11027. faceA.b = faces[ offset + 1 ];
  11028. faceA.c = faces[ offset + 3 ];
  11029. faceB = new THREE.Face3();
  11030. faceB.a = faces[ offset + 1 ];
  11031. faceB.b = faces[ offset + 2 ];
  11032. faceB.c = faces[ offset + 3 ];
  11033. offset += 4;
  11034. if ( hasMaterial ) {
  11035. materialIndex = faces[ offset ++ ];
  11036. faceA.materialIndex = materialIndex;
  11037. faceB.materialIndex = materialIndex;
  11038. }
  11039. // to get face <=> uv index correspondence
  11040. fi = geometry.faces.length;
  11041. if ( hasFaceVertexUv ) {
  11042. for ( i = 0; i < nUvLayers; i ++ ) {
  11043. uvLayer = json.uvs[ i ];
  11044. geometry.faceVertexUvs[ i ][ fi ] = [];
  11045. geometry.faceVertexUvs[ i ][ fi + 1 ] = [];
  11046. for ( j = 0; j < 4; j ++ ) {
  11047. uvIndex = faces[ offset ++ ];
  11048. u = uvLayer[ uvIndex * 2 ];
  11049. v = uvLayer[ uvIndex * 2 + 1 ];
  11050. uv = new THREE.Vector2( u, v );
  11051. if ( j !== 2 ) geometry.faceVertexUvs[ i ][ fi ].push( uv );
  11052. if ( j !== 0 ) geometry.faceVertexUvs[ i ][ fi + 1 ].push( uv );
  11053. }
  11054. }
  11055. }
  11056. if ( hasFaceNormal ) {
  11057. normalIndex = faces[ offset ++ ] * 3;
  11058. faceA.normal.set(
  11059. normals[ normalIndex ++ ],
  11060. normals[ normalIndex ++ ],
  11061. normals[ normalIndex ]
  11062. );
  11063. faceB.normal.copy( faceA.normal );
  11064. }
  11065. if ( hasFaceVertexNormal ) {
  11066. for ( i = 0; i < 4; i ++ ) {
  11067. normalIndex = faces[ offset ++ ] * 3;
  11068. normal = new THREE.Vector3(
  11069. normals[ normalIndex ++ ],
  11070. normals[ normalIndex ++ ],
  11071. normals[ normalIndex ]
  11072. );
  11073. if ( i !== 2 ) faceA.vertexNormals.push( normal );
  11074. if ( i !== 0 ) faceB.vertexNormals.push( normal );
  11075. }
  11076. }
  11077. if ( hasFaceColor ) {
  11078. colorIndex = faces[ offset ++ ];
  11079. hex = colors[ colorIndex ];
  11080. faceA.color.setHex( hex );
  11081. faceB.color.setHex( hex );
  11082. }
  11083. if ( hasFaceVertexColor ) {
  11084. for ( i = 0; i < 4; i ++ ) {
  11085. colorIndex = faces[ offset ++ ];
  11086. hex = colors[ colorIndex ];
  11087. if ( i !== 2 ) faceA.vertexColors.push( new THREE.Color( hex ) );
  11088. if ( i !== 0 ) faceB.vertexColors.push( new THREE.Color( hex ) );
  11089. }
  11090. }
  11091. geometry.faces.push( faceA );
  11092. geometry.faces.push( faceB );
  11093. } else {
  11094. face = new THREE.Face3();
  11095. face.a = faces[ offset ++ ];
  11096. face.b = faces[ offset ++ ];
  11097. face.c = faces[ offset ++ ];
  11098. if ( hasMaterial ) {
  11099. materialIndex = faces[ offset ++ ];
  11100. face.materialIndex = materialIndex;
  11101. }
  11102. // to get face <=> uv index correspondence
  11103. fi = geometry.faces.length;
  11104. if ( hasFaceVertexUv ) {
  11105. for ( i = 0; i < nUvLayers; i ++ ) {
  11106. uvLayer = json.uvs[ i ];
  11107. geometry.faceVertexUvs[ i ][ fi ] = [];
  11108. for ( j = 0; j < 3; j ++ ) {
  11109. uvIndex = faces[ offset ++ ];
  11110. u = uvLayer[ uvIndex * 2 ];
  11111. v = uvLayer[ uvIndex * 2 + 1 ];
  11112. uv = new THREE.Vector2( u, v );
  11113. geometry.faceVertexUvs[ i ][ fi ].push( uv );
  11114. }
  11115. }
  11116. }
  11117. if ( hasFaceNormal ) {
  11118. normalIndex = faces[ offset ++ ] * 3;
  11119. face.normal.set(
  11120. normals[ normalIndex ++ ],
  11121. normals[ normalIndex ++ ],
  11122. normals[ normalIndex ]
  11123. );
  11124. }
  11125. if ( hasFaceVertexNormal ) {
  11126. for ( i = 0; i < 3; i ++ ) {
  11127. normalIndex = faces[ offset ++ ] * 3;
  11128. normal = new THREE.Vector3(
  11129. normals[ normalIndex ++ ],
  11130. normals[ normalIndex ++ ],
  11131. normals[ normalIndex ]
  11132. );
  11133. face.vertexNormals.push( normal );
  11134. }
  11135. }
  11136. if ( hasFaceColor ) {
  11137. colorIndex = faces[ offset ++ ];
  11138. face.color.setHex( colors[ colorIndex ] );
  11139. }
  11140. if ( hasFaceVertexColor ) {
  11141. for ( i = 0; i < 3; i ++ ) {
  11142. colorIndex = faces[ offset ++ ];
  11143. face.vertexColors.push( new THREE.Color( colors[ colorIndex ] ) );
  11144. }
  11145. }
  11146. geometry.faces.push( face );
  11147. }
  11148. }
  11149. }
  11150. function parseSkin() {
  11151. var influencesPerVertex = ( json.influencesPerVertex !== undefined ) ? json.influencesPerVertex : 2;
  11152. if ( json.skinWeights ) {
  11153. for ( var i = 0, l = json.skinWeights.length; i < l; i += influencesPerVertex ) {
  11154. var x = json.skinWeights[ i ];
  11155. var y = ( influencesPerVertex > 1 ) ? json.skinWeights[ i + 1 ] : 0;
  11156. var z = ( influencesPerVertex > 2 ) ? json.skinWeights[ i + 2 ] : 0;
  11157. var w = ( influencesPerVertex > 3 ) ? json.skinWeights[ i + 3 ] : 0;
  11158. geometry.skinWeights.push( new THREE.Vector4( x, y, z, w ) );
  11159. }
  11160. }
  11161. if ( json.skinIndices ) {
  11162. for ( var i = 0, l = json.skinIndices.length; i < l; i += influencesPerVertex ) {
  11163. var a = json.skinIndices[ i ];
  11164. var b = ( influencesPerVertex > 1 ) ? json.skinIndices[ i + 1 ] : 0;
  11165. var c = ( influencesPerVertex > 2 ) ? json.skinIndices[ i + 2 ] : 0;
  11166. var d = ( influencesPerVertex > 3 ) ? json.skinIndices[ i + 3 ] : 0;
  11167. geometry.skinIndices.push( new THREE.Vector4( a, b, c, d ) );
  11168. }
  11169. }
  11170. geometry.bones = json.bones;
  11171. if ( geometry.bones && geometry.bones.length > 0 && ( geometry.skinWeights.length !== geometry.skinIndices.length || geometry.skinIndices.length !== geometry.vertices.length ) ) {
  11172. console.warn( 'When skinning, number of vertices (' + geometry.vertices.length + '), skinIndices (' +
  11173. geometry.skinIndices.length + '), and skinWeights (' + geometry.skinWeights.length + ') should match.' );
  11174. }
  11175. }
  11176. function parseMorphing( scale ) {
  11177. if ( json.morphTargets !== undefined ) {
  11178. for ( var i = 0, l = json.morphTargets.length; i < l; i ++ ) {
  11179. geometry.morphTargets[ i ] = {};
  11180. geometry.morphTargets[ i ].name = json.morphTargets[ i ].name;
  11181. geometry.morphTargets[ i ].vertices = [];
  11182. var dstVertices = geometry.morphTargets[ i ].vertices;
  11183. var srcVertices = json.morphTargets[ i ].vertices;
  11184. for ( var v = 0, vl = srcVertices.length; v < vl; v += 3 ) {
  11185. var vertex = new THREE.Vector3();
  11186. vertex.x = srcVertices[ v ] * scale;
  11187. vertex.y = srcVertices[ v + 1 ] * scale;
  11188. vertex.z = srcVertices[ v + 2 ] * scale;
  11189. dstVertices.push( vertex );
  11190. }
  11191. }
  11192. }
  11193. if ( json.morphColors !== undefined && json.morphColors.length > 0 ) {
  11194. console.warn( 'THREE.JSONLoader: "morphColors" no longer supported. Using them as face colors.' );
  11195. var faces = geometry.faces;
  11196. var morphColors = json.morphColors[ 0 ].colors;
  11197. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  11198. faces[ i ].color.fromArray( morphColors, i * 3 );
  11199. }
  11200. }
  11201. }
  11202. function parseAnimations() {
  11203. var outputAnimations = [];
  11204. // parse old style Bone/Hierarchy animations
  11205. var animations = [];
  11206. if ( json.animation !== undefined ) {
  11207. animations.push( json.animation );
  11208. }
  11209. if ( json.animations !== undefined ) {
  11210. if ( json.animations.length ) {
  11211. animations = animations.concat( json.animations );
  11212. } else {
  11213. animations.push( json.animations );
  11214. }
  11215. }
  11216. for ( var i = 0; i < animations.length; i ++ ) {
  11217. var clip = THREE.AnimationClip.parseAnimation( animations[ i ], geometry.bones );
  11218. if ( clip ) outputAnimations.push( clip );
  11219. }
  11220. // parse implicit morph animations
  11221. if ( geometry.morphTargets ) {
  11222. // TODO: Figure out what an appropraite FPS is for morph target animations -- defaulting to 10, but really it is completely arbitrary.
  11223. var morphAnimationClips = THREE.AnimationClip.CreateClipsFromMorphTargetSequences( geometry.morphTargets, 10 );
  11224. outputAnimations = outputAnimations.concat( morphAnimationClips );
  11225. }
  11226. if ( outputAnimations.length > 0 ) geometry.animations = outputAnimations;
  11227. }
  11228. if ( json.materials === undefined || json.materials.length === 0 ) {
  11229. return { geometry: geometry };
  11230. } else {
  11231. var materials = THREE.Loader.prototype.initMaterials( json.materials, texturePath, this.crossOrigin );
  11232. return { geometry: geometry, materials: materials };
  11233. }
  11234. }
  11235. } );
  11236. // File:src/loaders/LoadingManager.js
  11237. /**
  11238. * @author mrdoob / http://mrdoob.com/
  11239. */
  11240. THREE.LoadingManager = function ( onLoad, onProgress, onError ) {
  11241. var scope = this;
  11242. var isLoading = false, itemsLoaded = 0, itemsTotal = 0;
  11243. this.onStart = undefined;
  11244. this.onLoad = onLoad;
  11245. this.onProgress = onProgress;
  11246. this.onError = onError;
  11247. this.itemStart = function ( url ) {
  11248. itemsTotal ++;
  11249. if ( isLoading === false ) {
  11250. if ( scope.onStart !== undefined ) {
  11251. scope.onStart( url, itemsLoaded, itemsTotal );
  11252. }
  11253. }
  11254. isLoading = true;
  11255. };
  11256. this.itemEnd = function ( url ) {
  11257. itemsLoaded ++;
  11258. if ( scope.onProgress !== undefined ) {
  11259. scope.onProgress( url, itemsLoaded, itemsTotal );
  11260. }
  11261. if ( itemsLoaded === itemsTotal ) {
  11262. isLoading = false;
  11263. if ( scope.onLoad !== undefined ) {
  11264. scope.onLoad();
  11265. }
  11266. }
  11267. };
  11268. this.itemError = function ( url ) {
  11269. if ( scope.onError !== undefined ) {
  11270. scope.onError( url );
  11271. }
  11272. };
  11273. };
  11274. THREE.DefaultLoadingManager = new THREE.LoadingManager();
  11275. // File:src/loaders/BufferGeometryLoader.js
  11276. /**
  11277. * @author mrdoob / http://mrdoob.com/
  11278. */
  11279. THREE.BufferGeometryLoader = function ( manager ) {
  11280. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11281. };
  11282. Object.assign( THREE.BufferGeometryLoader.prototype, {
  11283. load: function ( url, onLoad, onProgress, onError ) {
  11284. var scope = this;
  11285. var loader = new THREE.XHRLoader( scope.manager );
  11286. loader.load( url, function ( text ) {
  11287. onLoad( scope.parse( JSON.parse( text ) ) );
  11288. }, onProgress, onError );
  11289. },
  11290. parse: function ( json ) {
  11291. var geometry = new THREE.BufferGeometry();
  11292. var index = json.data.index;
  11293. var TYPED_ARRAYS = {
  11294. 'Int8Array': Int8Array,
  11295. 'Uint8Array': Uint8Array,
  11296. 'Uint8ClampedArray': Uint8ClampedArray,
  11297. 'Int16Array': Int16Array,
  11298. 'Uint16Array': Uint16Array,
  11299. 'Int32Array': Int32Array,
  11300. 'Uint32Array': Uint32Array,
  11301. 'Float32Array': Float32Array,
  11302. 'Float64Array': Float64Array
  11303. };
  11304. if ( index !== undefined ) {
  11305. var typedArray = new TYPED_ARRAYS[ index.type ]( index.array );
  11306. geometry.setIndex( new THREE.BufferAttribute( typedArray, 1 ) );
  11307. }
  11308. var attributes = json.data.attributes;
  11309. for ( var key in attributes ) {
  11310. var attribute = attributes[ key ];
  11311. var typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
  11312. geometry.addAttribute( key, new THREE.BufferAttribute( typedArray, attribute.itemSize, attribute.normalized ) );
  11313. }
  11314. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  11315. if ( groups !== undefined ) {
  11316. for ( var i = 0, n = groups.length; i !== n; ++ i ) {
  11317. var group = groups[ i ];
  11318. geometry.addGroup( group.start, group.count, group.materialIndex );
  11319. }
  11320. }
  11321. var boundingSphere = json.data.boundingSphere;
  11322. if ( boundingSphere !== undefined ) {
  11323. var center = new THREE.Vector3();
  11324. if ( boundingSphere.center !== undefined ) {
  11325. center.fromArray( boundingSphere.center );
  11326. }
  11327. geometry.boundingSphere = new THREE.Sphere( center, boundingSphere.radius );
  11328. }
  11329. return geometry;
  11330. }
  11331. } );
  11332. // File:src/loaders/MaterialLoader.js
  11333. /**
  11334. * @author mrdoob / http://mrdoob.com/
  11335. */
  11336. THREE.MaterialLoader = function ( manager ) {
  11337. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11338. this.textures = {};
  11339. };
  11340. Object.assign( THREE.MaterialLoader.prototype, {
  11341. load: function ( url, onLoad, onProgress, onError ) {
  11342. var scope = this;
  11343. var loader = new THREE.XHRLoader( scope.manager );
  11344. loader.load( url, function ( text ) {
  11345. onLoad( scope.parse( JSON.parse( text ) ) );
  11346. }, onProgress, onError );
  11347. },
  11348. setTextures: function ( value ) {
  11349. this.textures = value;
  11350. },
  11351. getTexture: function ( name ) {
  11352. var textures = this.textures;
  11353. if ( textures[ name ] === undefined ) {
  11354. console.warn( 'THREE.MaterialLoader: Undefined texture', name );
  11355. }
  11356. return textures[ name ];
  11357. },
  11358. parse: function ( json ) {
  11359. var material = new THREE[ json.type ];
  11360. if ( json.uuid !== undefined ) material.uuid = json.uuid;
  11361. if ( json.name !== undefined ) material.name = json.name;
  11362. if ( json.color !== undefined ) material.color.setHex( json.color );
  11363. if ( json.roughness !== undefined ) material.roughness = json.roughness;
  11364. if ( json.metalness !== undefined ) material.metalness = json.metalness;
  11365. if ( json.emissive !== undefined ) material.emissive.setHex( json.emissive );
  11366. if ( json.specular !== undefined ) material.specular.setHex( json.specular );
  11367. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  11368. if ( json.uniforms !== undefined ) material.uniforms = json.uniforms;
  11369. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  11370. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  11371. if ( json.vertexColors !== undefined ) material.vertexColors = json.vertexColors;
  11372. if ( json.shading !== undefined ) material.shading = json.shading;
  11373. if ( json.blending !== undefined ) material.blending = json.blending;
  11374. if ( json.side !== undefined ) material.side = json.side;
  11375. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  11376. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  11377. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  11378. if ( json.depthTest !== undefined ) material.depthTest = json.depthTest;
  11379. if ( json.depthWrite !== undefined ) material.depthWrite = json.depthWrite;
  11380. if ( json.colorWrite !== undefined ) material.colorWrite = json.colorWrite;
  11381. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  11382. if ( json.wireframeLinewidth !== undefined ) material.wireframeLinewidth = json.wireframeLinewidth;
  11383. // for PointsMaterial
  11384. if ( json.size !== undefined ) material.size = json.size;
  11385. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  11386. // maps
  11387. if ( json.map !== undefined ) material.map = this.getTexture( json.map );
  11388. if ( json.alphaMap !== undefined ) {
  11389. material.alphaMap = this.getTexture( json.alphaMap );
  11390. material.transparent = true;
  11391. }
  11392. if ( json.bumpMap !== undefined ) material.bumpMap = this.getTexture( json.bumpMap );
  11393. if ( json.bumpScale !== undefined ) material.bumpScale = json.bumpScale;
  11394. if ( json.normalMap !== undefined ) material.normalMap = this.getTexture( json.normalMap );
  11395. if ( json.normalScale !== undefined ) {
  11396. var normalScale = json.normalScale;
  11397. if ( Array.isArray( normalScale ) === false ) {
  11398. // Blender exporter used to export a scalar. See #7459
  11399. normalScale = [ normalScale, normalScale ];
  11400. }
  11401. material.normalScale = new THREE.Vector2().fromArray( normalScale );
  11402. }
  11403. if ( json.displacementMap !== undefined ) material.displacementMap = this.getTexture( json.displacementMap );
  11404. if ( json.displacementScale !== undefined ) material.displacementScale = json.displacementScale;
  11405. if ( json.displacementBias !== undefined ) material.displacementBias = json.displacementBias;
  11406. if ( json.roughnessMap !== undefined ) material.roughnessMap = this.getTexture( json.roughnessMap );
  11407. if ( json.metalnessMap !== undefined ) material.metalnessMap = this.getTexture( json.metalnessMap );
  11408. if ( json.emissiveMap !== undefined ) material.emissiveMap = this.getTexture( json.emissiveMap );
  11409. if ( json.emissiveIntensity !== undefined ) material.emissiveIntensity = json.emissiveIntensity;
  11410. if ( json.specularMap !== undefined ) material.specularMap = this.getTexture( json.specularMap );
  11411. if ( json.envMap !== undefined ) {
  11412. material.envMap = this.getTexture( json.envMap );
  11413. material.combine = THREE.MultiplyOperation;
  11414. }
  11415. if ( json.reflectivity !== undefined ) material.reflectivity = json.reflectivity;
  11416. if ( json.lightMap !== undefined ) material.lightMap = this.getTexture( json.lightMap );
  11417. if ( json.lightMapIntensity !== undefined ) material.lightMapIntensity = json.lightMapIntensity;
  11418. if ( json.aoMap !== undefined ) material.aoMap = this.getTexture( json.aoMap );
  11419. if ( json.aoMapIntensity !== undefined ) material.aoMapIntensity = json.aoMapIntensity;
  11420. // MultiMaterial
  11421. if ( json.materials !== undefined ) {
  11422. for ( var i = 0, l = json.materials.length; i < l; i ++ ) {
  11423. material.materials.push( this.parse( json.materials[ i ] ) );
  11424. }
  11425. }
  11426. return material;
  11427. }
  11428. } );
  11429. // File:src/loaders/ObjectLoader.js
  11430. /**
  11431. * @author mrdoob / http://mrdoob.com/
  11432. */
  11433. THREE.ObjectLoader = function ( manager ) {
  11434. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11435. this.texturePath = '';
  11436. };
  11437. Object.assign( THREE.ObjectLoader.prototype, {
  11438. load: function ( url, onLoad, onProgress, onError ) {
  11439. if ( this.texturePath === '' ) {
  11440. this.texturePath = url.substring( 0, url.lastIndexOf( '/' ) + 1 );
  11441. }
  11442. var scope = this;
  11443. var loader = new THREE.XHRLoader( scope.manager );
  11444. loader.load( url, function ( text ) {
  11445. scope.parse( JSON.parse( text ), onLoad );
  11446. }, onProgress, onError );
  11447. },
  11448. setTexturePath: function ( value ) {
  11449. this.texturePath = value;
  11450. },
  11451. setCrossOrigin: function ( value ) {
  11452. this.crossOrigin = value;
  11453. },
  11454. parse: function ( json, onLoad ) {
  11455. var geometries = this.parseGeometries( json.geometries );
  11456. var images = this.parseImages( json.images, function () {
  11457. if ( onLoad !== undefined ) onLoad( object );
  11458. } );
  11459. var textures = this.parseTextures( json.textures, images );
  11460. var materials = this.parseMaterials( json.materials, textures );
  11461. var object = this.parseObject( json.object, geometries, materials );
  11462. if ( json.animations ) {
  11463. object.animations = this.parseAnimations( json.animations );
  11464. }
  11465. if ( json.images === undefined || json.images.length === 0 ) {
  11466. if ( onLoad !== undefined ) onLoad( object );
  11467. }
  11468. return object;
  11469. },
  11470. parseGeometries: function ( json ) {
  11471. var geometries = {};
  11472. if ( json !== undefined ) {
  11473. var geometryLoader = new THREE.JSONLoader();
  11474. var bufferGeometryLoader = new THREE.BufferGeometryLoader();
  11475. for ( var i = 0, l = json.length; i < l; i ++ ) {
  11476. var geometry;
  11477. var data = json[ i ];
  11478. switch ( data.type ) {
  11479. case 'PlaneGeometry':
  11480. case 'PlaneBufferGeometry':
  11481. geometry = new THREE[ data.type ](
  11482. data.width,
  11483. data.height,
  11484. data.widthSegments,
  11485. data.heightSegments
  11486. );
  11487. break;
  11488. case 'BoxGeometry':
  11489. case 'BoxBufferGeometry':
  11490. case 'CubeGeometry': // backwards compatible
  11491. geometry = new THREE[ data.type ](
  11492. data.width,
  11493. data.height,
  11494. data.depth,
  11495. data.widthSegments,
  11496. data.heightSegments,
  11497. data.depthSegments
  11498. );
  11499. break;
  11500. case 'CircleGeometry':
  11501. case 'CircleBufferGeometry':
  11502. geometry = new THREE[ data.type ](
  11503. data.radius,
  11504. data.segments,
  11505. data.thetaStart,
  11506. data.thetaLength
  11507. );
  11508. break;
  11509. case 'CylinderGeometry':
  11510. case 'CylinderBufferGeometry':
  11511. geometry = new THREE[ data.type ](
  11512. data.radiusTop,
  11513. data.radiusBottom,
  11514. data.height,
  11515. data.radialSegments,
  11516. data.heightSegments,
  11517. data.openEnded,
  11518. data.thetaStart,
  11519. data.thetaLength
  11520. );
  11521. break;
  11522. case 'ConeGeometry':
  11523. case 'ConeBufferGeometry':
  11524. geometry = new THREE [ data.type ](
  11525. data.radius,
  11526. data.height,
  11527. data.radialSegments,
  11528. data.heightSegments,
  11529. data.openEnded,
  11530. data.thetaStart,
  11531. data.thetaLength
  11532. );
  11533. break;
  11534. case 'SphereGeometry':
  11535. case 'SphereBufferGeometry':
  11536. geometry = new THREE[ data.type ](
  11537. data.radius,
  11538. data.widthSegments,
  11539. data.heightSegments,
  11540. data.phiStart,
  11541. data.phiLength,
  11542. data.thetaStart,
  11543. data.thetaLength
  11544. );
  11545. break;
  11546. case 'DodecahedronGeometry':
  11547. case 'IcosahedronGeometry':
  11548. case 'OctahedronGeometry':
  11549. case 'TetrahedronGeometry':
  11550. geometry = new THREE[ data.type ](
  11551. data.radius,
  11552. data.detail
  11553. );
  11554. break;
  11555. case 'RingGeometry':
  11556. case 'RingBufferGeometry':
  11557. geometry = new THREE[ data.type ](
  11558. data.innerRadius,
  11559. data.outerRadius,
  11560. data.thetaSegments,
  11561. data.phiSegments,
  11562. data.thetaStart,
  11563. data.thetaLength
  11564. );
  11565. break;
  11566. case 'TorusGeometry':
  11567. case 'TorusBufferGeometry':
  11568. geometry = new THREE[ data.type ](
  11569. data.radius,
  11570. data.tube,
  11571. data.radialSegments,
  11572. data.tubularSegments,
  11573. data.arc
  11574. );
  11575. break;
  11576. case 'TorusKnotGeometry':
  11577. case 'TorusKnotBufferGeometry':
  11578. geometry = new THREE[ data.type ](
  11579. data.radius,
  11580. data.tube,
  11581. data.tubularSegments,
  11582. data.radialSegments,
  11583. data.p,
  11584. data.q
  11585. );
  11586. break;
  11587. case 'LatheGeometry':
  11588. case 'LatheBufferGeometry':
  11589. geometry = new THREE[ data.type ](
  11590. data.points,
  11591. data.segments,
  11592. data.phiStart,
  11593. data.phiLength
  11594. );
  11595. break;
  11596. case 'BufferGeometry':
  11597. geometry = bufferGeometryLoader.parse( data );
  11598. break;
  11599. case 'Geometry':
  11600. geometry = geometryLoader.parse( data.data, this.texturePath ).geometry;
  11601. break;
  11602. default:
  11603. console.warn( 'THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"' );
  11604. continue;
  11605. }
  11606. geometry.uuid = data.uuid;
  11607. if ( data.name !== undefined ) geometry.name = data.name;
  11608. geometries[ data.uuid ] = geometry;
  11609. }
  11610. }
  11611. return geometries;
  11612. },
  11613. parseMaterials: function ( json, textures ) {
  11614. var materials = {};
  11615. if ( json !== undefined ) {
  11616. var loader = new THREE.MaterialLoader();
  11617. loader.setTextures( textures );
  11618. for ( var i = 0, l = json.length; i < l; i ++ ) {
  11619. var material = loader.parse( json[ i ] );
  11620. materials[ material.uuid ] = material;
  11621. }
  11622. }
  11623. return materials;
  11624. },
  11625. parseAnimations: function ( json ) {
  11626. var animations = [];
  11627. for ( var i = 0; i < json.length; i ++ ) {
  11628. var clip = THREE.AnimationClip.parse( json[ i ] );
  11629. animations.push( clip );
  11630. }
  11631. return animations;
  11632. },
  11633. parseImages: function ( json, onLoad ) {
  11634. var scope = this;
  11635. var images = {};
  11636. function loadImage( url ) {
  11637. scope.manager.itemStart( url );
  11638. return loader.load( url, function () {
  11639. scope.manager.itemEnd( url );
  11640. } );
  11641. }
  11642. if ( json !== undefined && json.length > 0 ) {
  11643. var manager = new THREE.LoadingManager( onLoad );
  11644. var loader = new THREE.ImageLoader( manager );
  11645. loader.setCrossOrigin( this.crossOrigin );
  11646. for ( var i = 0, l = json.length; i < l; i ++ ) {
  11647. var image = json[ i ];
  11648. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( image.url ) ? image.url : scope.texturePath + image.url;
  11649. images[ image.uuid ] = loadImage( path );
  11650. }
  11651. }
  11652. return images;
  11653. },
  11654. parseTextures: function ( json, images ) {
  11655. function parseConstant( value ) {
  11656. if ( typeof( value ) === 'number' ) return value;
  11657. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  11658. return THREE[ value ];
  11659. }
  11660. var textures = {};
  11661. if ( json !== undefined ) {
  11662. for ( var i = 0, l = json.length; i < l; i ++ ) {
  11663. var data = json[ i ];
  11664. if ( data.image === undefined ) {
  11665. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  11666. }
  11667. if ( images[ data.image ] === undefined ) {
  11668. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  11669. }
  11670. var texture = new THREE.Texture( images[ data.image ] );
  11671. texture.needsUpdate = true;
  11672. texture.uuid = data.uuid;
  11673. if ( data.name !== undefined ) texture.name = data.name;
  11674. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping );
  11675. if ( data.offset !== undefined ) texture.offset.fromArray( data.offset );
  11676. if ( data.repeat !== undefined ) texture.repeat.fromArray( data.repeat );
  11677. if ( data.wrap !== undefined ) {
  11678. texture.wrapS = parseConstant( data.wrap[ 0 ] );
  11679. texture.wrapT = parseConstant( data.wrap[ 1 ] );
  11680. }
  11681. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter );
  11682. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter );
  11683. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  11684. if ( data.flipY !== undefined ) texture.flipY = data.flipY;
  11685. textures[ data.uuid ] = texture;
  11686. }
  11687. }
  11688. return textures;
  11689. },
  11690. parseObject: function () {
  11691. var matrix = new THREE.Matrix4();
  11692. return function parseObject( data, geometries, materials ) {
  11693. var object;
  11694. function getGeometry( name ) {
  11695. if ( geometries[ name ] === undefined ) {
  11696. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  11697. }
  11698. return geometries[ name ];
  11699. }
  11700. function getMaterial( name ) {
  11701. if ( name === undefined ) return undefined;
  11702. if ( materials[ name ] === undefined ) {
  11703. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  11704. }
  11705. return materials[ name ];
  11706. }
  11707. switch ( data.type ) {
  11708. case 'Scene':
  11709. object = new THREE.Scene();
  11710. break;
  11711. case 'PerspectiveCamera':
  11712. object = new THREE.PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  11713. if ( data.focus !== undefined ) object.focus = data.focus;
  11714. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  11715. if ( data.filmGauge !== undefined ) object.filmGauge = data.filmGauge;
  11716. if ( data.filmOffset !== undefined ) object.filmOffset = data.filmOffset;
  11717. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  11718. break;
  11719. case 'OrthographicCamera':
  11720. object = new THREE.OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  11721. break;
  11722. case 'AmbientLight':
  11723. object = new THREE.AmbientLight( data.color, data.intensity );
  11724. break;
  11725. case 'DirectionalLight':
  11726. object = new THREE.DirectionalLight( data.color, data.intensity );
  11727. break;
  11728. case 'PointLight':
  11729. object = new THREE.PointLight( data.color, data.intensity, data.distance, data.decay );
  11730. break;
  11731. case 'SpotLight':
  11732. object = new THREE.SpotLight( data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay );
  11733. break;
  11734. case 'HemisphereLight':
  11735. object = new THREE.HemisphereLight( data.color, data.groundColor, data.intensity );
  11736. break;
  11737. case 'Mesh':
  11738. var geometry = getGeometry( data.geometry );
  11739. var material = getMaterial( data.material );
  11740. if ( geometry.bones && geometry.bones.length > 0 ) {
  11741. object = new THREE.SkinnedMesh( geometry, material );
  11742. } else {
  11743. object = new THREE.Mesh( geometry, material );
  11744. }
  11745. break;
  11746. case 'LOD':
  11747. object = new THREE.LOD();
  11748. break;
  11749. case 'Line':
  11750. object = new THREE.Line( getGeometry( data.geometry ), getMaterial( data.material ), data.mode );
  11751. break;
  11752. case 'PointCloud':
  11753. case 'Points':
  11754. object = new THREE.Points( getGeometry( data.geometry ), getMaterial( data.material ) );
  11755. break;
  11756. case 'Sprite':
  11757. object = new THREE.Sprite( getMaterial( data.material ) );
  11758. break;
  11759. case 'Group':
  11760. object = new THREE.Group();
  11761. break;
  11762. default:
  11763. object = new THREE.Object3D();
  11764. }
  11765. object.uuid = data.uuid;
  11766. if ( data.name !== undefined ) object.name = data.name;
  11767. if ( data.matrix !== undefined ) {
  11768. matrix.fromArray( data.matrix );
  11769. matrix.decompose( object.position, object.quaternion, object.scale );
  11770. } else {
  11771. if ( data.position !== undefined ) object.position.fromArray( data.position );
  11772. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  11773. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  11774. }
  11775. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  11776. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  11777. if ( data.visible !== undefined ) object.visible = data.visible;
  11778. if ( data.userData !== undefined ) object.userData = data.userData;
  11779. if ( data.children !== undefined ) {
  11780. for ( var child in data.children ) {
  11781. object.add( this.parseObject( data.children[ child ], geometries, materials ) );
  11782. }
  11783. }
  11784. if ( data.type === 'LOD' ) {
  11785. var levels = data.levels;
  11786. for ( var l = 0; l < levels.length; l ++ ) {
  11787. var level = levels[ l ];
  11788. var child = object.getObjectByProperty( 'uuid', level.object );
  11789. if ( child !== undefined ) {
  11790. object.addLevel( child, level.distance );
  11791. }
  11792. }
  11793. }
  11794. return object;
  11795. };
  11796. }()
  11797. } );
  11798. // File:src/loaders/TextureLoader.js
  11799. /**
  11800. * @author mrdoob / http://mrdoob.com/
  11801. */
  11802. THREE.TextureLoader = function ( manager ) {
  11803. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11804. };
  11805. Object.assign( THREE.TextureLoader.prototype, {
  11806. load: function ( url, onLoad, onProgress, onError ) {
  11807. var texture = new THREE.Texture();
  11808. var loader = new THREE.ImageLoader( this.manager );
  11809. loader.setCrossOrigin( this.crossOrigin );
  11810. loader.setPath( this.path );
  11811. loader.load( url, function ( image ) {
  11812. // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
  11813. var isJPEG = url.search( /\.(jpg|jpeg)$/ ) > 0 || url.search( /^data\:image\/jpeg/ ) === 0;
  11814. texture.format = isJPEG ? THREE.RGBFormat : THREE.RGBAFormat;
  11815. texture.image = image;
  11816. texture.needsUpdate = true;
  11817. if ( onLoad !== undefined ) {
  11818. onLoad( texture );
  11819. }
  11820. }, onProgress, onError );
  11821. return texture;
  11822. },
  11823. setCrossOrigin: function ( value ) {
  11824. this.crossOrigin = value;
  11825. return this;
  11826. },
  11827. setPath: function ( value ) {
  11828. this.path = value;
  11829. return this;
  11830. }
  11831. } );
  11832. // File:src/loaders/CubeTextureLoader.js
  11833. /**
  11834. * @author mrdoob / http://mrdoob.com/
  11835. */
  11836. THREE.CubeTextureLoader = function ( manager ) {
  11837. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11838. };
  11839. Object.assign( THREE.CubeTextureLoader.prototype, {
  11840. load: function ( urls, onLoad, onProgress, onError ) {
  11841. var texture = new THREE.CubeTexture();
  11842. var loader = new THREE.ImageLoader( this.manager );
  11843. loader.setCrossOrigin( this.crossOrigin );
  11844. loader.setPath( this.path );
  11845. var loaded = 0;
  11846. function loadTexture( i ) {
  11847. loader.load( urls[ i ], function ( image ) {
  11848. texture.images[ i ] = image;
  11849. loaded ++;
  11850. if ( loaded === 6 ) {
  11851. texture.needsUpdate = true;
  11852. if ( onLoad ) onLoad( texture );
  11853. }
  11854. }, undefined, onError );
  11855. }
  11856. for ( var i = 0; i < urls.length; ++ i ) {
  11857. loadTexture( i );
  11858. }
  11859. return texture;
  11860. },
  11861. setCrossOrigin: function ( value ) {
  11862. this.crossOrigin = value;
  11863. return this;
  11864. },
  11865. setPath: function ( value ) {
  11866. this.path = value;
  11867. return this;
  11868. }
  11869. } );
  11870. // File:src/loaders/BinaryTextureLoader.js
  11871. /**
  11872. * @author Nikos M. / https://github.com/foo123/
  11873. *
  11874. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  11875. */
  11876. THREE.DataTextureLoader = THREE.BinaryTextureLoader = function ( manager ) {
  11877. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11878. // override in sub classes
  11879. this._parser = null;
  11880. };
  11881. Object.assign( THREE.BinaryTextureLoader.prototype, {
  11882. load: function ( url, onLoad, onProgress, onError ) {
  11883. var scope = this;
  11884. var texture = new THREE.DataTexture();
  11885. var loader = new THREE.XHRLoader( this.manager );
  11886. loader.setResponseType( 'arraybuffer' );
  11887. loader.load( url, function ( buffer ) {
  11888. var texData = scope._parser( buffer );
  11889. if ( ! texData ) return;
  11890. if ( undefined !== texData.image ) {
  11891. texture.image = texData.image;
  11892. } else if ( undefined !== texData.data ) {
  11893. texture.image.width = texData.width;
  11894. texture.image.height = texData.height;
  11895. texture.image.data = texData.data;
  11896. }
  11897. texture.wrapS = undefined !== texData.wrapS ? texData.wrapS : THREE.ClampToEdgeWrapping;
  11898. texture.wrapT = undefined !== texData.wrapT ? texData.wrapT : THREE.ClampToEdgeWrapping;
  11899. texture.magFilter = undefined !== texData.magFilter ? texData.magFilter : THREE.LinearFilter;
  11900. texture.minFilter = undefined !== texData.minFilter ? texData.minFilter : THREE.LinearMipMapLinearFilter;
  11901. texture.anisotropy = undefined !== texData.anisotropy ? texData.anisotropy : 1;
  11902. if ( undefined !== texData.format ) {
  11903. texture.format = texData.format;
  11904. }
  11905. if ( undefined !== texData.type ) {
  11906. texture.type = texData.type;
  11907. }
  11908. if ( undefined !== texData.mipmaps ) {
  11909. texture.mipmaps = texData.mipmaps;
  11910. }
  11911. if ( 1 === texData.mipmapCount ) {
  11912. texture.minFilter = THREE.LinearFilter;
  11913. }
  11914. texture.needsUpdate = true;
  11915. if ( onLoad ) onLoad( texture, texData );
  11916. }, onProgress, onError );
  11917. return texture;
  11918. }
  11919. } );
  11920. // File:src/loaders/CompressedTextureLoader.js
  11921. /**
  11922. * @author mrdoob / http://mrdoob.com/
  11923. *
  11924. * Abstract Base class to block based textures loader (dds, pvr, ...)
  11925. */
  11926. THREE.CompressedTextureLoader = function ( manager ) {
  11927. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11928. // override in sub classes
  11929. this._parser = null;
  11930. };
  11931. Object.assign( THREE.CompressedTextureLoader.prototype, {
  11932. load: function ( url, onLoad, onProgress, onError ) {
  11933. var scope = this;
  11934. var images = [];
  11935. var texture = new THREE.CompressedTexture();
  11936. texture.image = images;
  11937. var loader = new THREE.XHRLoader( this.manager );
  11938. loader.setPath( this.path );
  11939. loader.setResponseType( 'arraybuffer' );
  11940. function loadTexture( i ) {
  11941. loader.load( url[ i ], function ( buffer ) {
  11942. var texDatas = scope._parser( buffer, true );
  11943. images[ i ] = {
  11944. width: texDatas.width,
  11945. height: texDatas.height,
  11946. format: texDatas.format,
  11947. mipmaps: texDatas.mipmaps
  11948. };
  11949. loaded += 1;
  11950. if ( loaded === 6 ) {
  11951. if ( texDatas.mipmapCount === 1 )
  11952. texture.minFilter = THREE.LinearFilter;
  11953. texture.format = texDatas.format;
  11954. texture.needsUpdate = true;
  11955. if ( onLoad ) onLoad( texture );
  11956. }
  11957. }, onProgress, onError );
  11958. }
  11959. if ( Array.isArray( url ) ) {
  11960. var loaded = 0;
  11961. for ( var i = 0, il = url.length; i < il; ++ i ) {
  11962. loadTexture( i );
  11963. }
  11964. } else {
  11965. // compressed cubemap texture stored in a single DDS file
  11966. loader.load( url, function ( buffer ) {
  11967. var texDatas = scope._parser( buffer, true );
  11968. if ( texDatas.isCubemap ) {
  11969. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  11970. for ( var f = 0; f < faces; f ++ ) {
  11971. images[ f ] = { mipmaps : [] };
  11972. for ( var i = 0; i < texDatas.mipmapCount; i ++ ) {
  11973. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  11974. images[ f ].format = texDatas.format;
  11975. images[ f ].width = texDatas.width;
  11976. images[ f ].height = texDatas.height;
  11977. }
  11978. }
  11979. } else {
  11980. texture.image.width = texDatas.width;
  11981. texture.image.height = texDatas.height;
  11982. texture.mipmaps = texDatas.mipmaps;
  11983. }
  11984. if ( texDatas.mipmapCount === 1 ) {
  11985. texture.minFilter = THREE.LinearFilter;
  11986. }
  11987. texture.format = texDatas.format;
  11988. texture.needsUpdate = true;
  11989. if ( onLoad ) onLoad( texture );
  11990. }, onProgress, onError );
  11991. }
  11992. return texture;
  11993. },
  11994. setPath: function ( value ) {
  11995. this.path = value;
  11996. return this;
  11997. }
  11998. } );
  11999. // File:src/materials/Material.js
  12000. /**
  12001. * @author mrdoob / http://mrdoob.com/
  12002. * @author alteredq / http://alteredqualia.com/
  12003. */
  12004. THREE.Material = function () {
  12005. Object.defineProperty( this, 'id', { value: THREE.MaterialIdCount ++ } );
  12006. this.uuid = THREE.Math.generateUUID();
  12007. this.name = '';
  12008. this.type = 'Material';
  12009. this.fog = true;
  12010. this.lights = true;
  12011. this.blending = THREE.NormalBlending;
  12012. this.side = THREE.FrontSide;
  12013. this.shading = THREE.SmoothShading; // THREE.FlatShading, THREE.SmoothShading
  12014. this.vertexColors = THREE.NoColors; // THREE.NoColors, THREE.VertexColors, THREE.FaceColors
  12015. this.opacity = 1;
  12016. this.transparent = false;
  12017. this.blendSrc = THREE.SrcAlphaFactor;
  12018. this.blendDst = THREE.OneMinusSrcAlphaFactor;
  12019. this.blendEquation = THREE.AddEquation;
  12020. this.blendSrcAlpha = null;
  12021. this.blendDstAlpha = null;
  12022. this.blendEquationAlpha = null;
  12023. this.depthFunc = THREE.LessEqualDepth;
  12024. this.depthTest = true;
  12025. this.depthWrite = true;
  12026. this.clippingPlanes = null;
  12027. this.clipShadows = false;
  12028. this.colorWrite = true;
  12029. this.precision = null; // override the renderer's default precision for this material
  12030. this.polygonOffset = false;
  12031. this.polygonOffsetFactor = 0;
  12032. this.polygonOffsetUnits = 0;
  12033. this.alphaTest = 0;
  12034. this.premultipliedAlpha = false;
  12035. this.overdraw = 0; // Overdrawn pixels (typically between 0 and 1) for fixing antialiasing gaps in CanvasRenderer
  12036. this.visible = true;
  12037. this._needsUpdate = true;
  12038. };
  12039. THREE.Material.prototype = {
  12040. constructor: THREE.Material,
  12041. get needsUpdate() {
  12042. return this._needsUpdate;
  12043. },
  12044. set needsUpdate( value ) {
  12045. if ( value === true ) this.update();
  12046. this._needsUpdate = value;
  12047. },
  12048. setValues: function ( values ) {
  12049. if ( values === undefined ) return;
  12050. for ( var key in values ) {
  12051. var newValue = values[ key ];
  12052. if ( newValue === undefined ) {
  12053. console.warn( "THREE.Material: '" + key + "' parameter is undefined." );
  12054. continue;
  12055. }
  12056. var currentValue = this[ key ];
  12057. if ( currentValue === undefined ) {
  12058. console.warn( "THREE." + this.type + ": '" + key + "' is not a property of this material." );
  12059. continue;
  12060. }
  12061. if ( currentValue instanceof THREE.Color ) {
  12062. currentValue.set( newValue );
  12063. } else if ( currentValue instanceof THREE.Vector3 && newValue instanceof THREE.Vector3 ) {
  12064. currentValue.copy( newValue );
  12065. } else if ( key === 'overdraw' ) {
  12066. // ensure overdraw is backwards-compatible with legacy boolean type
  12067. this[ key ] = Number( newValue );
  12068. } else {
  12069. this[ key ] = newValue;
  12070. }
  12071. }
  12072. },
  12073. toJSON: function ( meta ) {
  12074. var isRoot = meta === undefined;
  12075. if ( isRoot ) {
  12076. meta = {
  12077. textures: {},
  12078. images: {}
  12079. };
  12080. }
  12081. var data = {
  12082. metadata: {
  12083. version: 4.4,
  12084. type: 'Material',
  12085. generator: 'Material.toJSON'
  12086. }
  12087. };
  12088. // standard Material serialization
  12089. data.uuid = this.uuid;
  12090. data.type = this.type;
  12091. if ( this.name !== '' ) data.name = this.name;
  12092. if ( this.color instanceof THREE.Color ) data.color = this.color.getHex();
  12093. if ( this.roughness !== undefined ) data.roughness = this.roughness;
  12094. if ( this.metalness !== undefined ) data.metalness = this.metalness;
  12095. if ( this.emissive instanceof THREE.Color ) data.emissive = this.emissive.getHex();
  12096. if ( this.specular instanceof THREE.Color ) data.specular = this.specular.getHex();
  12097. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  12098. if ( this.map instanceof THREE.Texture ) data.map = this.map.toJSON( meta ).uuid;
  12099. if ( this.alphaMap instanceof THREE.Texture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  12100. if ( this.lightMap instanceof THREE.Texture ) data.lightMap = this.lightMap.toJSON( meta ).uuid;
  12101. if ( this.bumpMap instanceof THREE.Texture ) {
  12102. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  12103. data.bumpScale = this.bumpScale;
  12104. }
  12105. if ( this.normalMap instanceof THREE.Texture ) {
  12106. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  12107. data.normalScale = this.normalScale.toArray();
  12108. }
  12109. if ( this.displacementMap instanceof THREE.Texture ) {
  12110. data.displacementMap = this.displacementMap.toJSON( meta ).uuid;
  12111. data.displacementScale = this.displacementScale;
  12112. data.displacementBias = this.displacementBias;
  12113. }
  12114. if ( this.roughnessMap instanceof THREE.Texture ) data.roughnessMap = this.roughnessMap.toJSON( meta ).uuid;
  12115. if ( this.metalnessMap instanceof THREE.Texture ) data.metalnessMap = this.metalnessMap.toJSON( meta ).uuid;
  12116. if ( this.emissiveMap instanceof THREE.Texture ) data.emissiveMap = this.emissiveMap.toJSON( meta ).uuid;
  12117. if ( this.specularMap instanceof THREE.Texture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  12118. if ( this.envMap instanceof THREE.Texture ) {
  12119. data.envMap = this.envMap.toJSON( meta ).uuid;
  12120. data.reflectivity = this.reflectivity; // Scale behind envMap
  12121. }
  12122. if ( this.size !== undefined ) data.size = this.size;
  12123. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  12124. if ( this.blending !== THREE.NormalBlending ) data.blending = this.blending;
  12125. if ( this.shading !== THREE.SmoothShading ) data.shading = this.shading;
  12126. if ( this.side !== THREE.FrontSide ) data.side = this.side;
  12127. if ( this.vertexColors !== THREE.NoColors ) data.vertexColors = this.vertexColors;
  12128. if ( this.opacity < 1 ) data.opacity = this.opacity;
  12129. if ( this.transparent === true ) data.transparent = this.transparent;
  12130. if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
  12131. if ( this.premultipliedAlpha === true ) data.premultipliedAlpha = this.premultipliedAlpha;
  12132. if ( this.wireframe === true ) data.wireframe = this.wireframe;
  12133. if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;
  12134. // TODO: Copied from Object3D.toJSON
  12135. function extractFromCache ( cache ) {
  12136. var values = [];
  12137. for ( var key in cache ) {
  12138. var data = cache[ key ];
  12139. delete data.metadata;
  12140. values.push( data );
  12141. }
  12142. return values;
  12143. }
  12144. if ( isRoot ) {
  12145. var textures = extractFromCache( meta.textures );
  12146. var images = extractFromCache( meta.images );
  12147. if ( textures.length > 0 ) data.textures = textures;
  12148. if ( images.length > 0 ) data.images = images;
  12149. }
  12150. return data;
  12151. },
  12152. clone: function () {
  12153. return new this.constructor().copy( this );
  12154. },
  12155. copy: function ( source ) {
  12156. this.name = source.name;
  12157. this.fog = source.fog;
  12158. this.lights = source.lights;
  12159. this.blending = source.blending;
  12160. this.side = source.side;
  12161. this.shading = source.shading;
  12162. this.vertexColors = source.vertexColors;
  12163. this.opacity = source.opacity;
  12164. this.transparent = source.transparent;
  12165. this.blendSrc = source.blendSrc;
  12166. this.blendDst = source.blendDst;
  12167. this.blendEquation = source.blendEquation;
  12168. this.blendSrcAlpha = source.blendSrcAlpha;
  12169. this.blendDstAlpha = source.blendDstAlpha;
  12170. this.blendEquationAlpha = source.blendEquationAlpha;
  12171. this.depthFunc = source.depthFunc;
  12172. this.depthTest = source.depthTest;
  12173. this.depthWrite = source.depthWrite;
  12174. this.colorWrite = source.colorWrite;
  12175. this.precision = source.precision;
  12176. this.polygonOffset = source.polygonOffset;
  12177. this.polygonOffsetFactor = source.polygonOffsetFactor;
  12178. this.polygonOffsetUnits = source.polygonOffsetUnits;
  12179. this.alphaTest = source.alphaTest;
  12180. this.premultipliedAlpha = source.premultipliedAlpha;
  12181. this.overdraw = source.overdraw;
  12182. this.visible = source.visible;
  12183. this.clipShadows = source.clipShadows;
  12184. var srcPlanes = source.clippingPlanes,
  12185. dstPlanes = null;
  12186. if ( srcPlanes !== null ) {
  12187. var n = srcPlanes.length;
  12188. dstPlanes = new Array( n );
  12189. for ( var i = 0; i !== n; ++ i )
  12190. dstPlanes[ i ] = srcPlanes[ i ].clone();
  12191. }
  12192. this.clippingPlanes = dstPlanes;
  12193. return this;
  12194. },
  12195. update: function () {
  12196. this.dispatchEvent( { type: 'update' } );
  12197. },
  12198. dispose: function () {
  12199. this.dispatchEvent( { type: 'dispose' } );
  12200. }
  12201. };
  12202. Object.assign( THREE.Material.prototype, THREE.EventDispatcher.prototype );
  12203. THREE.MaterialIdCount = 0;
  12204. // File:src/materials/LineBasicMaterial.js
  12205. /**
  12206. * @author mrdoob / http://mrdoob.com/
  12207. * @author alteredq / http://alteredqualia.com/
  12208. *
  12209. * parameters = {
  12210. * color: <hex>,
  12211. * opacity: <float>,
  12212. *
  12213. * linewidth: <float>,
  12214. * linecap: "round",
  12215. * linejoin: "round"
  12216. * }
  12217. */
  12218. THREE.LineBasicMaterial = function ( parameters ) {
  12219. THREE.Material.call( this );
  12220. this.type = 'LineBasicMaterial';
  12221. this.color = new THREE.Color( 0xffffff );
  12222. this.linewidth = 1;
  12223. this.linecap = 'round';
  12224. this.linejoin = 'round';
  12225. this.lights = false;
  12226. this.setValues( parameters );
  12227. };
  12228. THREE.LineBasicMaterial.prototype = Object.create( THREE.Material.prototype );
  12229. THREE.LineBasicMaterial.prototype.constructor = THREE.LineBasicMaterial;
  12230. THREE.LineBasicMaterial.prototype.copy = function ( source ) {
  12231. THREE.Material.prototype.copy.call( this, source );
  12232. this.color.copy( source.color );
  12233. this.linewidth = source.linewidth;
  12234. this.linecap = source.linecap;
  12235. this.linejoin = source.linejoin;
  12236. return this;
  12237. };
  12238. // File:src/materials/LineDashedMaterial.js
  12239. /**
  12240. * @author alteredq / http://alteredqualia.com/
  12241. *
  12242. * parameters = {
  12243. * color: <hex>,
  12244. * opacity: <float>,
  12245. *
  12246. * linewidth: <float>,
  12247. *
  12248. * scale: <float>,
  12249. * dashSize: <float>,
  12250. * gapSize: <float>
  12251. * }
  12252. */
  12253. THREE.LineDashedMaterial = function ( parameters ) {
  12254. THREE.Material.call( this );
  12255. this.type = 'LineDashedMaterial';
  12256. this.color = new THREE.Color( 0xffffff );
  12257. this.linewidth = 1;
  12258. this.scale = 1;
  12259. this.dashSize = 3;
  12260. this.gapSize = 1;
  12261. this.lights = false;
  12262. this.setValues( parameters );
  12263. };
  12264. THREE.LineDashedMaterial.prototype = Object.create( THREE.Material.prototype );
  12265. THREE.LineDashedMaterial.prototype.constructor = THREE.LineDashedMaterial;
  12266. THREE.LineDashedMaterial.prototype.copy = function ( source ) {
  12267. THREE.Material.prototype.copy.call( this, source );
  12268. this.color.copy( source.color );
  12269. this.linewidth = source.linewidth;
  12270. this.scale = source.scale;
  12271. this.dashSize = source.dashSize;
  12272. this.gapSize = source.gapSize;
  12273. return this;
  12274. };
  12275. // File:src/materials/MeshBasicMaterial.js
  12276. /**
  12277. * @author mrdoob / http://mrdoob.com/
  12278. * @author alteredq / http://alteredqualia.com/
  12279. *
  12280. * parameters = {
  12281. * color: <hex>,
  12282. * opacity: <float>,
  12283. * map: new THREE.Texture( <Image> ),
  12284. *
  12285. * aoMap: new THREE.Texture( <Image> ),
  12286. * aoMapIntensity: <float>
  12287. *
  12288. * specularMap: new THREE.Texture( <Image> ),
  12289. *
  12290. * alphaMap: new THREE.Texture( <Image> ),
  12291. *
  12292. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  12293. * combine: THREE.Multiply,
  12294. * reflectivity: <float>,
  12295. * refractionRatio: <float>,
  12296. *
  12297. * shading: THREE.SmoothShading,
  12298. * depthTest: <bool>,
  12299. * depthWrite: <bool>,
  12300. *
  12301. * wireframe: <boolean>,
  12302. * wireframeLinewidth: <float>,
  12303. *
  12304. * skinning: <bool>,
  12305. * morphTargets: <bool>
  12306. * }
  12307. */
  12308. THREE.MeshBasicMaterial = function ( parameters ) {
  12309. THREE.Material.call( this );
  12310. this.type = 'MeshBasicMaterial';
  12311. this.color = new THREE.Color( 0xffffff ); // emissive
  12312. this.map = null;
  12313. this.aoMap = null;
  12314. this.aoMapIntensity = 1.0;
  12315. this.specularMap = null;
  12316. this.alphaMap = null;
  12317. this.envMap = null;
  12318. this.combine = THREE.MultiplyOperation;
  12319. this.reflectivity = 1;
  12320. this.refractionRatio = 0.98;
  12321. this.wireframe = false;
  12322. this.wireframeLinewidth = 1;
  12323. this.wireframeLinecap = 'round';
  12324. this.wireframeLinejoin = 'round';
  12325. this.skinning = false;
  12326. this.morphTargets = false;
  12327. this.lights = false;
  12328. this.setValues( parameters );
  12329. };
  12330. THREE.MeshBasicMaterial.prototype = Object.create( THREE.Material.prototype );
  12331. THREE.MeshBasicMaterial.prototype.constructor = THREE.MeshBasicMaterial;
  12332. THREE.MeshBasicMaterial.prototype.copy = function ( source ) {
  12333. THREE.Material.prototype.copy.call( this, source );
  12334. this.color.copy( source.color );
  12335. this.map = source.map;
  12336. this.aoMap = source.aoMap;
  12337. this.aoMapIntensity = source.aoMapIntensity;
  12338. this.specularMap = source.specularMap;
  12339. this.alphaMap = source.alphaMap;
  12340. this.envMap = source.envMap;
  12341. this.combine = source.combine;
  12342. this.reflectivity = source.reflectivity;
  12343. this.refractionRatio = source.refractionRatio;
  12344. this.wireframe = source.wireframe;
  12345. this.wireframeLinewidth = source.wireframeLinewidth;
  12346. this.wireframeLinecap = source.wireframeLinecap;
  12347. this.wireframeLinejoin = source.wireframeLinejoin;
  12348. this.skinning = source.skinning;
  12349. this.morphTargets = source.morphTargets;
  12350. return this;
  12351. };
  12352. // File:src/materials/MeshDepthMaterial.js
  12353. /**
  12354. * @author mrdoob / http://mrdoob.com/
  12355. * @author alteredq / http://alteredqualia.com/
  12356. * @author bhouston / https://clara.io
  12357. * @author WestLangley / http://github.com/WestLangley
  12358. *
  12359. * parameters = {
  12360. *
  12361. * opacity: <float>,
  12362. *
  12363. * map: new THREE.Texture( <Image> ),
  12364. *
  12365. * alphaMap: new THREE.Texture( <Image> ),
  12366. *
  12367. * displacementMap: new THREE.Texture( <Image> ),
  12368. * displacementScale: <float>,
  12369. * displacementBias: <float>,
  12370. *
  12371. * wireframe: <boolean>,
  12372. * wireframeLinewidth: <float>
  12373. * }
  12374. */
  12375. THREE.MeshDepthMaterial = function ( parameters ) {
  12376. THREE.Material.call( this );
  12377. this.type = 'MeshDepthMaterial';
  12378. this.depthPacking = THREE.BasicDepthPacking;
  12379. this.skinning = false;
  12380. this.morphTargets = false;
  12381. this.map = null;
  12382. this.alphaMap = null;
  12383. this.displacementMap = null;
  12384. this.displacementScale = 1;
  12385. this.displacementBias = 0;
  12386. this.wireframe = false;
  12387. this.wireframeLinewidth = 1;
  12388. this.fog = false;
  12389. this.lights = false;
  12390. this.setValues( parameters );
  12391. };
  12392. THREE.MeshDepthMaterial.prototype = Object.create( THREE.Material.prototype );
  12393. THREE.MeshDepthMaterial.prototype.constructor = THREE.MeshDepthMaterial;
  12394. THREE.MeshDepthMaterial.prototype.copy = function ( source ) {
  12395. THREE.Material.prototype.copy.call( this, source );
  12396. this.depthPacking = source.depthPacking;
  12397. this.skinning = source.skinning;
  12398. this.morphTargets = source.morphTargets;
  12399. this.map = source.map;
  12400. this.alphaMap = source.alphaMap;
  12401. this.displacementMap = source.displacementMap;
  12402. this.displacementScale = source.displacementScale;
  12403. this.displacementBias = source.displacementBias;
  12404. this.wireframe = source.wireframe;
  12405. this.wireframeLinewidth = source.wireframeLinewidth;
  12406. return this;
  12407. };
  12408. // File:src/materials/MeshLambertMaterial.js
  12409. /**
  12410. * @author mrdoob / http://mrdoob.com/
  12411. * @author alteredq / http://alteredqualia.com/
  12412. *
  12413. * parameters = {
  12414. * color: <hex>,
  12415. * opacity: <float>,
  12416. *
  12417. * map: new THREE.Texture( <Image> ),
  12418. *
  12419. * lightMap: new THREE.Texture( <Image> ),
  12420. * lightMapIntensity: <float>
  12421. *
  12422. * aoMap: new THREE.Texture( <Image> ),
  12423. * aoMapIntensity: <float>
  12424. *
  12425. * emissive: <hex>,
  12426. * emissiveIntensity: <float>
  12427. * emissiveMap: new THREE.Texture( <Image> ),
  12428. *
  12429. * specularMap: new THREE.Texture( <Image> ),
  12430. *
  12431. * alphaMap: new THREE.Texture( <Image> ),
  12432. *
  12433. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  12434. * combine: THREE.Multiply,
  12435. * reflectivity: <float>,
  12436. * refractionRatio: <float>,
  12437. *
  12438. * wireframe: <boolean>,
  12439. * wireframeLinewidth: <float>,
  12440. *
  12441. * skinning: <bool>,
  12442. * morphTargets: <bool>,
  12443. * morphNormals: <bool>
  12444. * }
  12445. */
  12446. THREE.MeshLambertMaterial = function ( parameters ) {
  12447. THREE.Material.call( this );
  12448. this.type = 'MeshLambertMaterial';
  12449. this.color = new THREE.Color( 0xffffff ); // diffuse
  12450. this.map = null;
  12451. this.lightMap = null;
  12452. this.lightMapIntensity = 1.0;
  12453. this.aoMap = null;
  12454. this.aoMapIntensity = 1.0;
  12455. this.emissive = new THREE.Color( 0x000000 );
  12456. this.emissiveIntensity = 1.0;
  12457. this.emissiveMap = null;
  12458. this.specularMap = null;
  12459. this.alphaMap = null;
  12460. this.envMap = null;
  12461. this.combine = THREE.MultiplyOperation;
  12462. this.reflectivity = 1;
  12463. this.refractionRatio = 0.98;
  12464. this.wireframe = false;
  12465. this.wireframeLinewidth = 1;
  12466. this.wireframeLinecap = 'round';
  12467. this.wireframeLinejoin = 'round';
  12468. this.skinning = false;
  12469. this.morphTargets = false;
  12470. this.morphNormals = false;
  12471. this.setValues( parameters );
  12472. };
  12473. THREE.MeshLambertMaterial.prototype = Object.create( THREE.Material.prototype );
  12474. THREE.MeshLambertMaterial.prototype.constructor = THREE.MeshLambertMaterial;
  12475. THREE.MeshLambertMaterial.prototype.copy = function ( source ) {
  12476. THREE.Material.prototype.copy.call( this, source );
  12477. this.color.copy( source.color );
  12478. this.map = source.map;
  12479. this.lightMap = source.lightMap;
  12480. this.lightMapIntensity = source.lightMapIntensity;
  12481. this.aoMap = source.aoMap;
  12482. this.aoMapIntensity = source.aoMapIntensity;
  12483. this.emissive.copy( source.emissive );
  12484. this.emissiveMap = source.emissiveMap;
  12485. this.emissiveIntensity = source.emissiveIntensity;
  12486. this.specularMap = source.specularMap;
  12487. this.alphaMap = source.alphaMap;
  12488. this.envMap = source.envMap;
  12489. this.combine = source.combine;
  12490. this.reflectivity = source.reflectivity;
  12491. this.refractionRatio = source.refractionRatio;
  12492. this.wireframe = source.wireframe;
  12493. this.wireframeLinewidth = source.wireframeLinewidth;
  12494. this.wireframeLinecap = source.wireframeLinecap;
  12495. this.wireframeLinejoin = source.wireframeLinejoin;
  12496. this.skinning = source.skinning;
  12497. this.morphTargets = source.morphTargets;
  12498. this.morphNormals = source.morphNormals;
  12499. return this;
  12500. };
  12501. // File:src/materials/MeshNormalMaterial.js
  12502. /**
  12503. * @author mrdoob / http://mrdoob.com/
  12504. *
  12505. * parameters = {
  12506. * opacity: <float>,
  12507. *
  12508. * wireframe: <boolean>,
  12509. * wireframeLinewidth: <float>
  12510. * }
  12511. */
  12512. THREE.MeshNormalMaterial = function ( parameters ) {
  12513. THREE.Material.call( this, parameters );
  12514. this.type = 'MeshNormalMaterial';
  12515. this.wireframe = false;
  12516. this.wireframeLinewidth = 1;
  12517. this.fog = false;
  12518. this.lights = false;
  12519. this.morphTargets = false;
  12520. this.setValues( parameters );
  12521. };
  12522. THREE.MeshNormalMaterial.prototype = Object.create( THREE.Material.prototype );
  12523. THREE.MeshNormalMaterial.prototype.constructor = THREE.MeshNormalMaterial;
  12524. THREE.MeshNormalMaterial.prototype.copy = function ( source ) {
  12525. THREE.Material.prototype.copy.call( this, source );
  12526. this.wireframe = source.wireframe;
  12527. this.wireframeLinewidth = source.wireframeLinewidth;
  12528. return this;
  12529. };
  12530. // File:src/materials/MeshPhongMaterial.js
  12531. /**
  12532. * @author mrdoob / http://mrdoob.com/
  12533. * @author alteredq / http://alteredqualia.com/
  12534. *
  12535. * parameters = {
  12536. * color: <hex>,
  12537. * specular: <hex>,
  12538. * shininess: <float>,
  12539. * opacity: <float>,
  12540. *
  12541. * map: new THREE.Texture( <Image> ),
  12542. *
  12543. * lightMap: new THREE.Texture( <Image> ),
  12544. * lightMapIntensity: <float>
  12545. *
  12546. * aoMap: new THREE.Texture( <Image> ),
  12547. * aoMapIntensity: <float>
  12548. *
  12549. * emissive: <hex>,
  12550. * emissiveIntensity: <float>
  12551. * emissiveMap: new THREE.Texture( <Image> ),
  12552. *
  12553. * bumpMap: new THREE.Texture( <Image> ),
  12554. * bumpScale: <float>,
  12555. *
  12556. * normalMap: new THREE.Texture( <Image> ),
  12557. * normalScale: <Vector2>,
  12558. *
  12559. * displacementMap: new THREE.Texture( <Image> ),
  12560. * displacementScale: <float>,
  12561. * displacementBias: <float>,
  12562. *
  12563. * specularMap: new THREE.Texture( <Image> ),
  12564. *
  12565. * alphaMap: new THREE.Texture( <Image> ),
  12566. *
  12567. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  12568. * combine: THREE.Multiply,
  12569. * reflectivity: <float>,
  12570. * refractionRatio: <float>,
  12571. *
  12572. * wireframe: <boolean>,
  12573. * wireframeLinewidth: <float>,
  12574. *
  12575. * skinning: <bool>,
  12576. * morphTargets: <bool>,
  12577. * morphNormals: <bool>
  12578. * }
  12579. */
  12580. THREE.MeshPhongMaterial = function ( parameters ) {
  12581. THREE.Material.call( this );
  12582. this.type = 'MeshPhongMaterial';
  12583. this.color = new THREE.Color( 0xffffff ); // diffuse
  12584. this.specular = new THREE.Color( 0x111111 );
  12585. this.shininess = 30;
  12586. this.map = null;
  12587. this.lightMap = null;
  12588. this.lightMapIntensity = 1.0;
  12589. this.aoMap = null;
  12590. this.aoMapIntensity = 1.0;
  12591. this.emissive = new THREE.Color( 0x000000 );
  12592. this.emissiveIntensity = 1.0;
  12593. this.emissiveMap = null;
  12594. this.bumpMap = null;
  12595. this.bumpScale = 1;
  12596. this.normalMap = null;
  12597. this.normalScale = new THREE.Vector2( 1, 1 );
  12598. this.displacementMap = null;
  12599. this.displacementScale = 1;
  12600. this.displacementBias = 0;
  12601. this.specularMap = null;
  12602. this.alphaMap = null;
  12603. this.envMap = null;
  12604. this.combine = THREE.MultiplyOperation;
  12605. this.reflectivity = 1;
  12606. this.refractionRatio = 0.98;
  12607. this.wireframe = false;
  12608. this.wireframeLinewidth = 1;
  12609. this.wireframeLinecap = 'round';
  12610. this.wireframeLinejoin = 'round';
  12611. this.skinning = false;
  12612. this.morphTargets = false;
  12613. this.morphNormals = false;
  12614. this.setValues( parameters );
  12615. };
  12616. THREE.MeshPhongMaterial.prototype = Object.create( THREE.Material.prototype );
  12617. THREE.MeshPhongMaterial.prototype.constructor = THREE.MeshPhongMaterial;
  12618. THREE.MeshPhongMaterial.prototype.copy = function ( source ) {
  12619. THREE.Material.prototype.copy.call( this, source );
  12620. this.color.copy( source.color );
  12621. this.specular.copy( source.specular );
  12622. this.shininess = source.shininess;
  12623. this.map = source.map;
  12624. this.lightMap = source.lightMap;
  12625. this.lightMapIntensity = source.lightMapIntensity;
  12626. this.aoMap = source.aoMap;
  12627. this.aoMapIntensity = source.aoMapIntensity;
  12628. this.emissive.copy( source.emissive );
  12629. this.emissiveMap = source.emissiveMap;
  12630. this.emissiveIntensity = source.emissiveIntensity;
  12631. this.bumpMap = source.bumpMap;
  12632. this.bumpScale = source.bumpScale;
  12633. this.normalMap = source.normalMap;
  12634. this.normalScale.copy( source.normalScale );
  12635. this.displacementMap = source.displacementMap;
  12636. this.displacementScale = source.displacementScale;
  12637. this.displacementBias = source.displacementBias;
  12638. this.specularMap = source.specularMap;
  12639. this.alphaMap = source.alphaMap;
  12640. this.envMap = source.envMap;
  12641. this.combine = source.combine;
  12642. this.reflectivity = source.reflectivity;
  12643. this.refractionRatio = source.refractionRatio;
  12644. this.wireframe = source.wireframe;
  12645. this.wireframeLinewidth = source.wireframeLinewidth;
  12646. this.wireframeLinecap = source.wireframeLinecap;
  12647. this.wireframeLinejoin = source.wireframeLinejoin;
  12648. this.skinning = source.skinning;
  12649. this.morphTargets = source.morphTargets;
  12650. this.morphNormals = source.morphNormals;
  12651. return this;
  12652. };
  12653. // File:src/materials/MeshStandardMaterial.js
  12654. /**
  12655. * @author WestLangley / http://github.com/WestLangley
  12656. *
  12657. * parameters = {
  12658. * color: <hex>,
  12659. * roughness: <float>,
  12660. * metalness: <float>,
  12661. * opacity: <float>,
  12662. *
  12663. * map: new THREE.Texture( <Image> ),
  12664. *
  12665. * lightMap: new THREE.Texture( <Image> ),
  12666. * lightMapIntensity: <float>
  12667. *
  12668. * aoMap: new THREE.Texture( <Image> ),
  12669. * aoMapIntensity: <float>
  12670. *
  12671. * emissive: <hex>,
  12672. * emissiveIntensity: <float>
  12673. * emissiveMap: new THREE.Texture( <Image> ),
  12674. *
  12675. * bumpMap: new THREE.Texture( <Image> ),
  12676. * bumpScale: <float>,
  12677. *
  12678. * normalMap: new THREE.Texture( <Image> ),
  12679. * normalScale: <Vector2>,
  12680. *
  12681. * displacementMap: new THREE.Texture( <Image> ),
  12682. * displacementScale: <float>,
  12683. * displacementBias: <float>,
  12684. *
  12685. * roughnessMap: new THREE.Texture( <Image> ),
  12686. *
  12687. * metalnessMap: new THREE.Texture( <Image> ),
  12688. *
  12689. * alphaMap: new THREE.Texture( <Image> ),
  12690. *
  12691. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  12692. * envMapIntensity: <float>
  12693. *
  12694. * refractionRatio: <float>,
  12695. *
  12696. * wireframe: <boolean>,
  12697. * wireframeLinewidth: <float>,
  12698. *
  12699. * skinning: <bool>,
  12700. * morphTargets: <bool>,
  12701. * morphNormals: <bool>
  12702. * }
  12703. */
  12704. THREE.MeshStandardMaterial = function ( parameters ) {
  12705. THREE.Material.call( this );
  12706. this.defines = { 'STANDARD': '' };
  12707. this.type = 'MeshStandardMaterial';
  12708. this.color = new THREE.Color( 0xffffff ); // diffuse
  12709. this.roughness = 0.5;
  12710. this.metalness = 0.5;
  12711. this.map = null;
  12712. this.lightMap = null;
  12713. this.lightMapIntensity = 1.0;
  12714. this.aoMap = null;
  12715. this.aoMapIntensity = 1.0;
  12716. this.emissive = new THREE.Color( 0x000000 );
  12717. this.emissiveIntensity = 1.0;
  12718. this.emissiveMap = null;
  12719. this.bumpMap = null;
  12720. this.bumpScale = 1;
  12721. this.normalMap = null;
  12722. this.normalScale = new THREE.Vector2( 1, 1 );
  12723. this.displacementMap = null;
  12724. this.displacementScale = 1;
  12725. this.displacementBias = 0;
  12726. this.roughnessMap = null;
  12727. this.metalnessMap = null;
  12728. this.alphaMap = null;
  12729. this.envMap = null;
  12730. this.envMapIntensity = 1.0;
  12731. this.refractionRatio = 0.98;
  12732. this.wireframe = false;
  12733. this.wireframeLinewidth = 1;
  12734. this.wireframeLinecap = 'round';
  12735. this.wireframeLinejoin = 'round';
  12736. this.skinning = false;
  12737. this.morphTargets = false;
  12738. this.morphNormals = false;
  12739. this.setValues( parameters );
  12740. };
  12741. THREE.MeshStandardMaterial.prototype = Object.create( THREE.Material.prototype );
  12742. THREE.MeshStandardMaterial.prototype.constructor = THREE.MeshStandardMaterial;
  12743. THREE.MeshStandardMaterial.prototype.copy = function ( source ) {
  12744. THREE.Material.prototype.copy.call( this, source );
  12745. this.defines = { 'STANDARD': '' };
  12746. this.color.copy( source.color );
  12747. this.roughness = source.roughness;
  12748. this.metalness = source.metalness;
  12749. this.map = source.map;
  12750. this.lightMap = source.lightMap;
  12751. this.lightMapIntensity = source.lightMapIntensity;
  12752. this.aoMap = source.aoMap;
  12753. this.aoMapIntensity = source.aoMapIntensity;
  12754. this.emissive.copy( source.emissive );
  12755. this.emissiveMap = source.emissiveMap;
  12756. this.emissiveIntensity = source.emissiveIntensity;
  12757. this.bumpMap = source.bumpMap;
  12758. this.bumpScale = source.bumpScale;
  12759. this.normalMap = source.normalMap;
  12760. this.normalScale.copy( source.normalScale );
  12761. this.displacementMap = source.displacementMap;
  12762. this.displacementScale = source.displacementScale;
  12763. this.displacementBias = source.displacementBias;
  12764. this.roughnessMap = source.roughnessMap;
  12765. this.metalnessMap = source.metalnessMap;
  12766. this.alphaMap = source.alphaMap;
  12767. this.envMap = source.envMap;
  12768. this.envMapIntensity = source.envMapIntensity;
  12769. this.refractionRatio = source.refractionRatio;
  12770. this.wireframe = source.wireframe;
  12771. this.wireframeLinewidth = source.wireframeLinewidth;
  12772. this.wireframeLinecap = source.wireframeLinecap;
  12773. this.wireframeLinejoin = source.wireframeLinejoin;
  12774. this.skinning = source.skinning;
  12775. this.morphTargets = source.morphTargets;
  12776. this.morphNormals = source.morphNormals;
  12777. return this;
  12778. };
  12779. // File:src/materials/MeshPhysicalMaterial.js
  12780. /**
  12781. * @author WestLangley / http://github.com/WestLangley
  12782. *
  12783. * parameters = {
  12784. * reflectivity: <float>
  12785. * }
  12786. */
  12787. THREE.MeshPhysicalMaterial = function ( parameters ) {
  12788. THREE.MeshStandardMaterial.call( this );
  12789. this.defines = { 'PHYSICAL': '' };
  12790. this.type = 'MeshPhysicalMaterial';
  12791. this.reflectivity = 0.5; // maps to F0 = 0.04
  12792. this.clearCoat = 0.0;
  12793. this.clearCoatRoughness = 0.0;
  12794. this.setValues( parameters );
  12795. };
  12796. THREE.MeshPhysicalMaterial.prototype = Object.create( THREE.MeshStandardMaterial.prototype );
  12797. THREE.MeshPhysicalMaterial.prototype.constructor = THREE.MeshPhysicalMaterial;
  12798. THREE.MeshPhysicalMaterial.prototype.copy = function ( source ) {
  12799. THREE.MeshStandardMaterial.prototype.copy.call( this, source );
  12800. this.defines = { 'PHYSICAL': '' };
  12801. this.reflectivity = source.reflectivity;
  12802. this.clearCoat = source.clearCoat;
  12803. this.clearCoatRoughness = source.clearCoatRoughness;
  12804. return this;
  12805. };
  12806. // File:src/materials/MultiMaterial.js
  12807. /**
  12808. * @author mrdoob / http://mrdoob.com/
  12809. */
  12810. THREE.MultiMaterial = function ( materials ) {
  12811. this.uuid = THREE.Math.generateUUID();
  12812. this.type = 'MultiMaterial';
  12813. this.materials = materials instanceof Array ? materials : [];
  12814. this.visible = true;
  12815. };
  12816. THREE.MultiMaterial.prototype = {
  12817. constructor: THREE.MultiMaterial,
  12818. toJSON: function ( meta ) {
  12819. var output = {
  12820. metadata: {
  12821. version: 4.2,
  12822. type: 'material',
  12823. generator: 'MaterialExporter'
  12824. },
  12825. uuid: this.uuid,
  12826. type: this.type,
  12827. materials: []
  12828. };
  12829. var materials = this.materials;
  12830. for ( var i = 0, l = materials.length; i < l; i ++ ) {
  12831. var material = materials[ i ].toJSON( meta );
  12832. delete material.metadata;
  12833. output.materials.push( material );
  12834. }
  12835. output.visible = this.visible;
  12836. return output;
  12837. },
  12838. clone: function () {
  12839. var material = new this.constructor();
  12840. for ( var i = 0; i < this.materials.length; i ++ ) {
  12841. material.materials.push( this.materials[ i ].clone() );
  12842. }
  12843. material.visible = this.visible;
  12844. return material;
  12845. }
  12846. };
  12847. // File:src/materials/PointsMaterial.js
  12848. /**
  12849. * @author mrdoob / http://mrdoob.com/
  12850. * @author alteredq / http://alteredqualia.com/
  12851. *
  12852. * parameters = {
  12853. * color: <hex>,
  12854. * opacity: <float>,
  12855. * map: new THREE.Texture( <Image> ),
  12856. *
  12857. * size: <float>,
  12858. * sizeAttenuation: <bool>
  12859. * }
  12860. */
  12861. THREE.PointsMaterial = function ( parameters ) {
  12862. THREE.Material.call( this );
  12863. this.type = 'PointsMaterial';
  12864. this.color = new THREE.Color( 0xffffff );
  12865. this.map = null;
  12866. this.size = 1;
  12867. this.sizeAttenuation = true;
  12868. this.lights = false;
  12869. this.setValues( parameters );
  12870. };
  12871. THREE.PointsMaterial.prototype = Object.create( THREE.Material.prototype );
  12872. THREE.PointsMaterial.prototype.constructor = THREE.PointsMaterial;
  12873. THREE.PointsMaterial.prototype.copy = function ( source ) {
  12874. THREE.Material.prototype.copy.call( this, source );
  12875. this.color.copy( source.color );
  12876. this.map = source.map;
  12877. this.size = source.size;
  12878. this.sizeAttenuation = source.sizeAttenuation;
  12879. return this;
  12880. };
  12881. // File:src/materials/ShaderMaterial.js
  12882. /**
  12883. * @author alteredq / http://alteredqualia.com/
  12884. *
  12885. * parameters = {
  12886. * defines: { "label" : "value" },
  12887. * uniforms: { "parameter1": { value: 1.0 }, "parameter2": { value2: 2 } },
  12888. *
  12889. * fragmentShader: <string>,
  12890. * vertexShader: <string>,
  12891. *
  12892. * wireframe: <boolean>,
  12893. * wireframeLinewidth: <float>,
  12894. *
  12895. * lights: <bool>,
  12896. *
  12897. * skinning: <bool>,
  12898. * morphTargets: <bool>,
  12899. * morphNormals: <bool>
  12900. * }
  12901. */
  12902. THREE.ShaderMaterial = function ( parameters ) {
  12903. THREE.Material.call( this );
  12904. this.type = 'ShaderMaterial';
  12905. this.defines = {};
  12906. this.uniforms = {};
  12907. this.vertexShader = 'void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}';
  12908. this.fragmentShader = 'void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}';
  12909. this.linewidth = 1;
  12910. this.wireframe = false;
  12911. this.wireframeLinewidth = 1;
  12912. this.fog = false; // set to use scene fog
  12913. this.lights = false; // set to use scene lights
  12914. this.clipping = false; // set to use user-defined clipping planes
  12915. this.skinning = false; // set to use skinning attribute streams
  12916. this.morphTargets = false; // set to use morph targets
  12917. this.morphNormals = false; // set to use morph normals
  12918. this.extensions = {
  12919. derivatives: false, // set to use derivatives
  12920. fragDepth: false, // set to use fragment depth values
  12921. drawBuffers: false, // set to use draw buffers
  12922. shaderTextureLOD: false // set to use shader texture LOD
  12923. };
  12924. // When rendered geometry doesn't include these attributes but the material does,
  12925. // use these default values in WebGL. This avoids errors when buffer data is missing.
  12926. this.defaultAttributeValues = {
  12927. 'color': [ 1, 1, 1 ],
  12928. 'uv': [ 0, 0 ],
  12929. 'uv2': [ 0, 0 ]
  12930. };
  12931. this.index0AttributeName = undefined;
  12932. if ( parameters !== undefined ) {
  12933. if ( parameters.attributes !== undefined ) {
  12934. console.error( 'THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.' );
  12935. }
  12936. this.setValues( parameters );
  12937. }
  12938. };
  12939. THREE.ShaderMaterial.prototype = Object.create( THREE.Material.prototype );
  12940. THREE.ShaderMaterial.prototype.constructor = THREE.ShaderMaterial;
  12941. THREE.ShaderMaterial.prototype.copy = function ( source ) {
  12942. THREE.Material.prototype.copy.call( this, source );
  12943. this.fragmentShader = source.fragmentShader;
  12944. this.vertexShader = source.vertexShader;
  12945. this.uniforms = THREE.UniformsUtils.clone( source.uniforms );
  12946. this.defines = source.defines;
  12947. this.wireframe = source.wireframe;
  12948. this.wireframeLinewidth = source.wireframeLinewidth;
  12949. this.lights = source.lights;
  12950. this.clipping = source.clipping;
  12951. this.skinning = source.skinning;
  12952. this.morphTargets = source.morphTargets;
  12953. this.morphNormals = source.morphNormals;
  12954. this.extensions = source.extensions;
  12955. return this;
  12956. };
  12957. THREE.ShaderMaterial.prototype.toJSON = function ( meta ) {
  12958. var data = THREE.Material.prototype.toJSON.call( this, meta );
  12959. data.uniforms = this.uniforms;
  12960. data.vertexShader = this.vertexShader;
  12961. data.fragmentShader = this.fragmentShader;
  12962. return data;
  12963. };
  12964. // File:src/materials/RawShaderMaterial.js
  12965. /**
  12966. * @author mrdoob / http://mrdoob.com/
  12967. */
  12968. THREE.RawShaderMaterial = function ( parameters ) {
  12969. THREE.ShaderMaterial.call( this, parameters );
  12970. this.type = 'RawShaderMaterial';
  12971. };
  12972. THREE.RawShaderMaterial.prototype = Object.create( THREE.ShaderMaterial.prototype );
  12973. THREE.RawShaderMaterial.prototype.constructor = THREE.RawShaderMaterial;
  12974. // File:src/materials/SpriteMaterial.js
  12975. /**
  12976. * @author alteredq / http://alteredqualia.com/
  12977. *
  12978. * parameters = {
  12979. * color: <hex>,
  12980. * opacity: <float>,
  12981. * map: new THREE.Texture( <Image> ),
  12982. *
  12983. * uvOffset: new THREE.Vector2(),
  12984. * uvScale: new THREE.Vector2()
  12985. * }
  12986. */
  12987. THREE.SpriteMaterial = function ( parameters ) {
  12988. THREE.Material.call( this );
  12989. this.type = 'SpriteMaterial';
  12990. this.color = new THREE.Color( 0xffffff );
  12991. this.map = null;
  12992. this.rotation = 0;
  12993. this.fog = false;
  12994. this.lights = false;
  12995. this.setValues( parameters );
  12996. };
  12997. THREE.SpriteMaterial.prototype = Object.create( THREE.Material.prototype );
  12998. THREE.SpriteMaterial.prototype.constructor = THREE.SpriteMaterial;
  12999. THREE.SpriteMaterial.prototype.copy = function ( source ) {
  13000. THREE.Material.prototype.copy.call( this, source );
  13001. this.color.copy( source.color );
  13002. this.map = source.map;
  13003. this.rotation = source.rotation;
  13004. return this;
  13005. };
  13006. // File:src/materials/ShadowMaterial.js
  13007. /**
  13008. * @author mrdoob / http://mrdoob.com/
  13009. */
  13010. THREE.ShadowMaterial = function () {
  13011. THREE.ShaderMaterial.call( this, {
  13012. uniforms: THREE.UniformsUtils.merge( [
  13013. THREE.UniformsLib[ "lights" ],
  13014. {
  13015. opacity: { value: 1.0 }
  13016. }
  13017. ] ),
  13018. vertexShader: THREE.ShaderChunk[ 'shadow_vert' ],
  13019. fragmentShader: THREE.ShaderChunk[ 'shadow_frag' ]
  13020. } );
  13021. this.lights = true;
  13022. this.transparent = true;
  13023. Object.defineProperties( this, {
  13024. opacity: {
  13025. enumerable: true,
  13026. get: function () {
  13027. return this.uniforms.opacity.value;
  13028. },
  13029. set: function ( value ) {
  13030. this.uniforms.opacity.value = value;
  13031. }
  13032. }
  13033. } );
  13034. };
  13035. THREE.ShadowMaterial.prototype = Object.create( THREE.ShaderMaterial.prototype );
  13036. THREE.ShadowMaterial.prototype.constructor = THREE.ShadowMaterial;
  13037. // File:src/textures/Texture.js
  13038. /**
  13039. * @author mrdoob / http://mrdoob.com/
  13040. * @author alteredq / http://alteredqualia.com/
  13041. * @author szimek / https://github.com/szimek/
  13042. */
  13043. THREE.Texture = function ( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  13044. Object.defineProperty( this, 'id', { value: THREE.TextureIdCount ++ } );
  13045. this.uuid = THREE.Math.generateUUID();
  13046. this.name = '';
  13047. this.sourceFile = '';
  13048. this.image = image !== undefined ? image : THREE.Texture.DEFAULT_IMAGE;
  13049. this.mipmaps = [];
  13050. this.mapping = mapping !== undefined ? mapping : THREE.Texture.DEFAULT_MAPPING;
  13051. this.wrapS = wrapS !== undefined ? wrapS : THREE.ClampToEdgeWrapping;
  13052. this.wrapT = wrapT !== undefined ? wrapT : THREE.ClampToEdgeWrapping;
  13053. this.magFilter = magFilter !== undefined ? magFilter : THREE.LinearFilter;
  13054. this.minFilter = minFilter !== undefined ? minFilter : THREE.LinearMipMapLinearFilter;
  13055. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  13056. this.format = format !== undefined ? format : THREE.RGBAFormat;
  13057. this.type = type !== undefined ? type : THREE.UnsignedByteType;
  13058. this.offset = new THREE.Vector2( 0, 0 );
  13059. this.repeat = new THREE.Vector2( 1, 1 );
  13060. this.generateMipmaps = true;
  13061. this.premultiplyAlpha = false;
  13062. this.flipY = true;
  13063. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  13064. // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
  13065. //
  13066. // Also changing the encoding after already used by a Material will not automatically make the Material
  13067. // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
  13068. this.encoding = encoding !== undefined ? encoding : THREE.LinearEncoding;
  13069. this.version = 0;
  13070. this.onUpdate = null;
  13071. };
  13072. THREE.Texture.DEFAULT_IMAGE = undefined;
  13073. THREE.Texture.DEFAULT_MAPPING = THREE.UVMapping;
  13074. THREE.Texture.prototype = {
  13075. constructor: THREE.Texture,
  13076. set needsUpdate( value ) {
  13077. if ( value === true ) this.version ++;
  13078. },
  13079. clone: function () {
  13080. return new this.constructor().copy( this );
  13081. },
  13082. copy: function ( source ) {
  13083. this.image = source.image;
  13084. this.mipmaps = source.mipmaps.slice( 0 );
  13085. this.mapping = source.mapping;
  13086. this.wrapS = source.wrapS;
  13087. this.wrapT = source.wrapT;
  13088. this.magFilter = source.magFilter;
  13089. this.minFilter = source.minFilter;
  13090. this.anisotropy = source.anisotropy;
  13091. this.format = source.format;
  13092. this.type = source.type;
  13093. this.offset.copy( source.offset );
  13094. this.repeat.copy( source.repeat );
  13095. this.generateMipmaps = source.generateMipmaps;
  13096. this.premultiplyAlpha = source.premultiplyAlpha;
  13097. this.flipY = source.flipY;
  13098. this.unpackAlignment = source.unpackAlignment;
  13099. this.encoding = source.encoding;
  13100. return this;
  13101. },
  13102. toJSON: function ( meta ) {
  13103. if ( meta.textures[ this.uuid ] !== undefined ) {
  13104. return meta.textures[ this.uuid ];
  13105. }
  13106. function getDataURL( image ) {
  13107. var canvas;
  13108. if ( image.toDataURL !== undefined ) {
  13109. canvas = image;
  13110. } else {
  13111. canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  13112. canvas.width = image.width;
  13113. canvas.height = image.height;
  13114. canvas.getContext( '2d' ).drawImage( image, 0, 0, image.width, image.height );
  13115. }
  13116. if ( canvas.width > 2048 || canvas.height > 2048 ) {
  13117. return canvas.toDataURL( 'image/jpeg', 0.6 );
  13118. } else {
  13119. return canvas.toDataURL( 'image/png' );
  13120. }
  13121. }
  13122. var output = {
  13123. metadata: {
  13124. version: 4.4,
  13125. type: 'Texture',
  13126. generator: 'Texture.toJSON'
  13127. },
  13128. uuid: this.uuid,
  13129. name: this.name,
  13130. mapping: this.mapping,
  13131. repeat: [ this.repeat.x, this.repeat.y ],
  13132. offset: [ this.offset.x, this.offset.y ],
  13133. wrap: [ this.wrapS, this.wrapT ],
  13134. minFilter: this.minFilter,
  13135. magFilter: this.magFilter,
  13136. anisotropy: this.anisotropy,
  13137. flipY: this.flipY
  13138. };
  13139. if ( this.image !== undefined ) {
  13140. // TODO: Move to THREE.Image
  13141. var image = this.image;
  13142. if ( image.uuid === undefined ) {
  13143. image.uuid = THREE.Math.generateUUID(); // UGH
  13144. }
  13145. if ( meta.images[ image.uuid ] === undefined ) {
  13146. meta.images[ image.uuid ] = {
  13147. uuid: image.uuid,
  13148. url: getDataURL( image )
  13149. };
  13150. }
  13151. output.image = image.uuid;
  13152. }
  13153. meta.textures[ this.uuid ] = output;
  13154. return output;
  13155. },
  13156. dispose: function () {
  13157. this.dispatchEvent( { type: 'dispose' } );
  13158. },
  13159. transformUv: function ( uv ) {
  13160. if ( this.mapping !== THREE.UVMapping ) return;
  13161. uv.multiply( this.repeat );
  13162. uv.add( this.offset );
  13163. if ( uv.x < 0 || uv.x > 1 ) {
  13164. switch ( this.wrapS ) {
  13165. case THREE.RepeatWrapping:
  13166. uv.x = uv.x - Math.floor( uv.x );
  13167. break;
  13168. case THREE.ClampToEdgeWrapping:
  13169. uv.x = uv.x < 0 ? 0 : 1;
  13170. break;
  13171. case THREE.MirroredRepeatWrapping:
  13172. if ( Math.abs( Math.floor( uv.x ) % 2 ) === 1 ) {
  13173. uv.x = Math.ceil( uv.x ) - uv.x;
  13174. } else {
  13175. uv.x = uv.x - Math.floor( uv.x );
  13176. }
  13177. break;
  13178. }
  13179. }
  13180. if ( uv.y < 0 || uv.y > 1 ) {
  13181. switch ( this.wrapT ) {
  13182. case THREE.RepeatWrapping:
  13183. uv.y = uv.y - Math.floor( uv.y );
  13184. break;
  13185. case THREE.ClampToEdgeWrapping:
  13186. uv.y = uv.y < 0 ? 0 : 1;
  13187. break;
  13188. case THREE.MirroredRepeatWrapping:
  13189. if ( Math.abs( Math.floor( uv.y ) % 2 ) === 1 ) {
  13190. uv.y = Math.ceil( uv.y ) - uv.y;
  13191. } else {
  13192. uv.y = uv.y - Math.floor( uv.y );
  13193. }
  13194. break;
  13195. }
  13196. }
  13197. if ( this.flipY ) {
  13198. uv.y = 1 - uv.y;
  13199. }
  13200. }
  13201. };
  13202. Object.assign( THREE.Texture.prototype, THREE.EventDispatcher.prototype );
  13203. THREE.TextureIdCount = 0;
  13204. // File:src/textures/DepthTexture.js
  13205. /**
  13206. * @author Matt DesLauriers / @mattdesl
  13207. */
  13208. THREE.DepthTexture = function ( width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy ) {
  13209. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, THREE.DepthFormat, type, anisotropy );
  13210. this.image = { width: width, height: height };
  13211. this.type = type !== undefined ? type : THREE.UnsignedShortType;
  13212. this.magFilter = magFilter !== undefined ? magFilter : THREE.NearestFilter;
  13213. this.minFilter = minFilter !== undefined ? minFilter : THREE.NearestFilter;
  13214. this.flipY = false;
  13215. this.generateMipmaps = false;
  13216. };
  13217. THREE.DepthTexture.prototype = Object.create( THREE.Texture.prototype );
  13218. THREE.DepthTexture.prototype.constructor = THREE.DepthTexture;
  13219. // File:src/textures/CanvasTexture.js
  13220. /**
  13221. * @author mrdoob / http://mrdoob.com/
  13222. */
  13223. THREE.CanvasTexture = function ( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  13224. THREE.Texture.call( this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  13225. this.needsUpdate = true;
  13226. };
  13227. THREE.CanvasTexture.prototype = Object.create( THREE.Texture.prototype );
  13228. THREE.CanvasTexture.prototype.constructor = THREE.CanvasTexture;
  13229. // File:src/textures/CubeTexture.js
  13230. /**
  13231. * @author mrdoob / http://mrdoob.com/
  13232. */
  13233. THREE.CubeTexture = function ( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  13234. images = images !== undefined ? images : [];
  13235. mapping = mapping !== undefined ? mapping : THREE.CubeReflectionMapping;
  13236. THREE.Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  13237. this.flipY = false;
  13238. };
  13239. THREE.CubeTexture.prototype = Object.create( THREE.Texture.prototype );
  13240. THREE.CubeTexture.prototype.constructor = THREE.CubeTexture;
  13241. Object.defineProperty( THREE.CubeTexture.prototype, 'images', {
  13242. get: function () {
  13243. return this.image;
  13244. },
  13245. set: function ( value ) {
  13246. this.image = value;
  13247. }
  13248. } );
  13249. // File:src/textures/CompressedTexture.js
  13250. /**
  13251. * @author alteredq / http://alteredqualia.com/
  13252. */
  13253. THREE.CompressedTexture = function ( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  13254. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  13255. this.image = { width: width, height: height };
  13256. this.mipmaps = mipmaps;
  13257. // no flipping for cube textures
  13258. // (also flipping doesn't work for compressed textures )
  13259. this.flipY = false;
  13260. // can't generate mipmaps for compressed textures
  13261. // mips must be embedded in DDS files
  13262. this.generateMipmaps = false;
  13263. };
  13264. THREE.CompressedTexture.prototype = Object.create( THREE.Texture.prototype );
  13265. THREE.CompressedTexture.prototype.constructor = THREE.CompressedTexture;
  13266. // File:src/textures/DataTexture.js
  13267. /**
  13268. * @author alteredq / http://alteredqualia.com/
  13269. */
  13270. THREE.DataTexture = function ( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  13271. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  13272. this.image = { data: data, width: width, height: height };
  13273. this.magFilter = magFilter !== undefined ? magFilter : THREE.NearestFilter;
  13274. this.minFilter = minFilter !== undefined ? minFilter : THREE.NearestFilter;
  13275. this.flipY = false;
  13276. this.generateMipmaps = false;
  13277. };
  13278. THREE.DataTexture.prototype = Object.create( THREE.Texture.prototype );
  13279. THREE.DataTexture.prototype.constructor = THREE.DataTexture;
  13280. // File:src/textures/VideoTexture.js
  13281. /**
  13282. * @author mrdoob / http://mrdoob.com/
  13283. */
  13284. THREE.VideoTexture = function ( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  13285. THREE.Texture.call( this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  13286. this.generateMipmaps = false;
  13287. var scope = this;
  13288. function update() {
  13289. requestAnimationFrame( update );
  13290. if ( video.readyState >= video.HAVE_CURRENT_DATA ) {
  13291. scope.needsUpdate = true;
  13292. }
  13293. }
  13294. update();
  13295. };
  13296. THREE.VideoTexture.prototype = Object.create( THREE.Texture.prototype );
  13297. THREE.VideoTexture.prototype.constructor = THREE.VideoTexture;
  13298. // File:src/objects/Group.js
  13299. /**
  13300. * @author mrdoob / http://mrdoob.com/
  13301. */
  13302. THREE.Group = function () {
  13303. THREE.Object3D.call( this );
  13304. this.type = 'Group';
  13305. };
  13306. THREE.Group.prototype = Object.assign( Object.create( THREE.Object3D.prototype ), {
  13307. constructor: THREE.Group
  13308. } );
  13309. // File:src/objects/Points.js
  13310. /**
  13311. * @author alteredq / http://alteredqualia.com/
  13312. */
  13313. THREE.Points = function ( geometry, material ) {
  13314. THREE.Object3D.call( this );
  13315. this.type = 'Points';
  13316. this.geometry = geometry !== undefined ? geometry : new THREE.BufferGeometry();
  13317. this.material = material !== undefined ? material : new THREE.PointsMaterial( { color: Math.random() * 0xffffff } );
  13318. };
  13319. THREE.Points.prototype = Object.assign( Object.create( THREE.Object3D.prototype ), {
  13320. constructor: THREE.Points,
  13321. raycast: ( function () {
  13322. var inverseMatrix = new THREE.Matrix4();
  13323. var ray = new THREE.Ray();
  13324. var sphere = new THREE.Sphere();
  13325. return function raycast( raycaster, intersects ) {
  13326. var object = this;
  13327. var geometry = this.geometry;
  13328. var matrixWorld = this.matrixWorld;
  13329. var threshold = raycaster.params.Points.threshold;
  13330. // Checking boundingSphere distance to ray
  13331. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  13332. sphere.copy( geometry.boundingSphere );
  13333. sphere.applyMatrix4( matrixWorld );
  13334. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  13335. //
  13336. inverseMatrix.getInverse( matrixWorld );
  13337. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  13338. var localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  13339. var localThresholdSq = localThreshold * localThreshold;
  13340. var position = new THREE.Vector3();
  13341. function testPoint( point, index ) {
  13342. var rayPointDistanceSq = ray.distanceSqToPoint( point );
  13343. if ( rayPointDistanceSq < localThresholdSq ) {
  13344. var intersectPoint = ray.closestPointToPoint( point );
  13345. intersectPoint.applyMatrix4( matrixWorld );
  13346. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  13347. if ( distance < raycaster.near || distance > raycaster.far ) return;
  13348. intersects.push( {
  13349. distance: distance,
  13350. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  13351. point: intersectPoint.clone(),
  13352. index: index,
  13353. face: null,
  13354. object: object
  13355. } );
  13356. }
  13357. }
  13358. if ( geometry instanceof THREE.BufferGeometry ) {
  13359. var index = geometry.index;
  13360. var attributes = geometry.attributes;
  13361. var positions = attributes.position.array;
  13362. if ( index !== null ) {
  13363. var indices = index.array;
  13364. for ( var i = 0, il = indices.length; i < il; i ++ ) {
  13365. var a = indices[ i ];
  13366. position.fromArray( positions, a * 3 );
  13367. testPoint( position, a );
  13368. }
  13369. } else {
  13370. for ( var i = 0, l = positions.length / 3; i < l; i ++ ) {
  13371. position.fromArray( positions, i * 3 );
  13372. testPoint( position, i );
  13373. }
  13374. }
  13375. } else {
  13376. var vertices = geometry.vertices;
  13377. for ( var i = 0, l = vertices.length; i < l; i ++ ) {
  13378. testPoint( vertices[ i ], i );
  13379. }
  13380. }
  13381. };
  13382. }() ),
  13383. clone: function () {
  13384. return new this.constructor( this.geometry, this.material ).copy( this );
  13385. }
  13386. } );
  13387. // File:src/objects/Line.js
  13388. /**
  13389. * @author mrdoob / http://mrdoob.com/
  13390. */
  13391. THREE.Line = function ( geometry, material, mode ) {
  13392. if ( mode === 1 ) {
  13393. console.warn( 'THREE.Line: parameter THREE.LinePieces no longer supported. Created THREE.LineSegments instead.' );
  13394. return new THREE.LineSegments( geometry, material );
  13395. }
  13396. THREE.Object3D.call( this );
  13397. this.type = 'Line';
  13398. this.geometry = geometry !== undefined ? geometry : new THREE.BufferGeometry();
  13399. this.material = material !== undefined ? material : new THREE.LineBasicMaterial( { color: Math.random() * 0xffffff } );
  13400. };
  13401. THREE.Line.prototype = Object.assign( Object.create( THREE.Object3D.prototype ), {
  13402. constructor: THREE.Line,
  13403. raycast: ( function () {
  13404. var inverseMatrix = new THREE.Matrix4();
  13405. var ray = new THREE.Ray();
  13406. var sphere = new THREE.Sphere();
  13407. return function raycast( raycaster, intersects ) {
  13408. var precision = raycaster.linePrecision;
  13409. var precisionSq = precision * precision;
  13410. var geometry = this.geometry;
  13411. var matrixWorld = this.matrixWorld;
  13412. // Checking boundingSphere distance to ray
  13413. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  13414. sphere.copy( geometry.boundingSphere );
  13415. sphere.applyMatrix4( matrixWorld );
  13416. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  13417. //
  13418. inverseMatrix.getInverse( matrixWorld );
  13419. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  13420. var vStart = new THREE.Vector3();
  13421. var vEnd = new THREE.Vector3();
  13422. var interSegment = new THREE.Vector3();
  13423. var interRay = new THREE.Vector3();
  13424. var step = this instanceof THREE.LineSegments ? 2 : 1;
  13425. if ( geometry instanceof THREE.BufferGeometry ) {
  13426. var index = geometry.index;
  13427. var attributes = geometry.attributes;
  13428. var positions = attributes.position.array;
  13429. if ( index !== null ) {
  13430. var indices = index.array;
  13431. for ( var i = 0, l = indices.length - 1; i < l; i += step ) {
  13432. var a = indices[ i ];
  13433. var b = indices[ i + 1 ];
  13434. vStart.fromArray( positions, a * 3 );
  13435. vEnd.fromArray( positions, b * 3 );
  13436. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  13437. if ( distSq > precisionSq ) continue;
  13438. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  13439. var distance = raycaster.ray.origin.distanceTo( interRay );
  13440. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  13441. intersects.push( {
  13442. distance: distance,
  13443. // What do we want? intersection point on the ray or on the segment??
  13444. // point: raycaster.ray.at( distance ),
  13445. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  13446. index: i,
  13447. face: null,
  13448. faceIndex: null,
  13449. object: this
  13450. } );
  13451. }
  13452. } else {
  13453. for ( var i = 0, l = positions.length / 3 - 1; i < l; i += step ) {
  13454. vStart.fromArray( positions, 3 * i );
  13455. vEnd.fromArray( positions, 3 * i + 3 );
  13456. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  13457. if ( distSq > precisionSq ) continue;
  13458. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  13459. var distance = raycaster.ray.origin.distanceTo( interRay );
  13460. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  13461. intersects.push( {
  13462. distance: distance,
  13463. // What do we want? intersection point on the ray or on the segment??
  13464. // point: raycaster.ray.at( distance ),
  13465. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  13466. index: i,
  13467. face: null,
  13468. faceIndex: null,
  13469. object: this
  13470. } );
  13471. }
  13472. }
  13473. } else if ( geometry instanceof THREE.Geometry ) {
  13474. var vertices = geometry.vertices;
  13475. var nbVertices = vertices.length;
  13476. for ( var i = 0; i < nbVertices - 1; i += step ) {
  13477. var distSq = ray.distanceSqToSegment( vertices[ i ], vertices[ i + 1 ], interRay, interSegment );
  13478. if ( distSq > precisionSq ) continue;
  13479. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  13480. var distance = raycaster.ray.origin.distanceTo( interRay );
  13481. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  13482. intersects.push( {
  13483. distance: distance,
  13484. // What do we want? intersection point on the ray or on the segment??
  13485. // point: raycaster.ray.at( distance ),
  13486. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  13487. index: i,
  13488. face: null,
  13489. faceIndex: null,
  13490. object: this
  13491. } );
  13492. }
  13493. }
  13494. };
  13495. }() ),
  13496. clone: function () {
  13497. return new this.constructor( this.geometry, this.material ).copy( this );
  13498. }
  13499. } );
  13500. // File:src/objects/LineSegments.js
  13501. /**
  13502. * @author mrdoob / http://mrdoob.com/
  13503. */
  13504. THREE.LineSegments = function ( geometry, material ) {
  13505. THREE.Line.call( this, geometry, material );
  13506. this.type = 'LineSegments';
  13507. };
  13508. THREE.LineSegments.prototype = Object.assign( Object.create( THREE.Line.prototype ), {
  13509. constructor: THREE.LineSegments
  13510. } );
  13511. // File:src/objects/Mesh.js
  13512. /**
  13513. * @author mrdoob / http://mrdoob.com/
  13514. * @author alteredq / http://alteredqualia.com/
  13515. * @author mikael emtinger / http://gomo.se/
  13516. * @author jonobr1 / http://jonobr1.com/
  13517. */
  13518. THREE.Mesh = function ( geometry, material ) {
  13519. THREE.Object3D.call( this );
  13520. this.type = 'Mesh';
  13521. this.geometry = geometry !== undefined ? geometry : new THREE.BufferGeometry();
  13522. this.material = material !== undefined ? material : new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff } );
  13523. this.drawMode = THREE.TrianglesDrawMode;
  13524. this.updateMorphTargets();
  13525. };
  13526. THREE.Mesh.prototype = Object.assign( Object.create( THREE.Object3D.prototype ), {
  13527. constructor: THREE.Mesh,
  13528. setDrawMode: function ( value ) {
  13529. this.drawMode = value;
  13530. },
  13531. copy: function ( source ) {
  13532. THREE.Object3D.prototype.copy.call( this, source );
  13533. this.drawMode = source.drawMode;
  13534. return this;
  13535. },
  13536. updateMorphTargets: function () {
  13537. if ( this.geometry.morphTargets !== undefined && this.geometry.morphTargets.length > 0 ) {
  13538. this.morphTargetBase = - 1;
  13539. this.morphTargetInfluences = [];
  13540. this.morphTargetDictionary = {};
  13541. for ( var m = 0, ml = this.geometry.morphTargets.length; m < ml; m ++ ) {
  13542. this.morphTargetInfluences.push( 0 );
  13543. this.morphTargetDictionary[ this.geometry.morphTargets[ m ].name ] = m;
  13544. }
  13545. }
  13546. },
  13547. getMorphTargetIndexByName: function ( name ) {
  13548. if ( this.morphTargetDictionary[ name ] !== undefined ) {
  13549. return this.morphTargetDictionary[ name ];
  13550. }
  13551. console.warn( 'THREE.Mesh.getMorphTargetIndexByName: morph target ' + name + ' does not exist. Returning 0.' );
  13552. return 0;
  13553. },
  13554. raycast: ( function () {
  13555. var inverseMatrix = new THREE.Matrix4();
  13556. var ray = new THREE.Ray();
  13557. var sphere = new THREE.Sphere();
  13558. var vA = new THREE.Vector3();
  13559. var vB = new THREE.Vector3();
  13560. var vC = new THREE.Vector3();
  13561. var tempA = new THREE.Vector3();
  13562. var tempB = new THREE.Vector3();
  13563. var tempC = new THREE.Vector3();
  13564. var uvA = new THREE.Vector2();
  13565. var uvB = new THREE.Vector2();
  13566. var uvC = new THREE.Vector2();
  13567. var barycoord = new THREE.Vector3();
  13568. var intersectionPoint = new THREE.Vector3();
  13569. var intersectionPointWorld = new THREE.Vector3();
  13570. function uvIntersection( point, p1, p2, p3, uv1, uv2, uv3 ) {
  13571. THREE.Triangle.barycoordFromPoint( point, p1, p2, p3, barycoord );
  13572. uv1.multiplyScalar( barycoord.x );
  13573. uv2.multiplyScalar( barycoord.y );
  13574. uv3.multiplyScalar( barycoord.z );
  13575. uv1.add( uv2 ).add( uv3 );
  13576. return uv1.clone();
  13577. }
  13578. function checkIntersection( object, raycaster, ray, pA, pB, pC, point ) {
  13579. var intersect;
  13580. var material = object.material;
  13581. if ( material.side === THREE.BackSide ) {
  13582. intersect = ray.intersectTriangle( pC, pB, pA, true, point );
  13583. } else {
  13584. intersect = ray.intersectTriangle( pA, pB, pC, material.side !== THREE.DoubleSide, point );
  13585. }
  13586. if ( intersect === null ) return null;
  13587. intersectionPointWorld.copy( point );
  13588. intersectionPointWorld.applyMatrix4( object.matrixWorld );
  13589. var distance = raycaster.ray.origin.distanceTo( intersectionPointWorld );
  13590. if ( distance < raycaster.near || distance > raycaster.far ) return null;
  13591. return {
  13592. distance: distance,
  13593. point: intersectionPointWorld.clone(),
  13594. object: object
  13595. };
  13596. }
  13597. function checkBufferGeometryIntersection( object, raycaster, ray, positions, uvs, a, b, c ) {
  13598. vA.fromArray( positions, a * 3 );
  13599. vB.fromArray( positions, b * 3 );
  13600. vC.fromArray( positions, c * 3 );
  13601. var intersection = checkIntersection( object, raycaster, ray, vA, vB, vC, intersectionPoint );
  13602. if ( intersection ) {
  13603. if ( uvs ) {
  13604. uvA.fromArray( uvs, a * 2 );
  13605. uvB.fromArray( uvs, b * 2 );
  13606. uvC.fromArray( uvs, c * 2 );
  13607. intersection.uv = uvIntersection( intersectionPoint, vA, vB, vC, uvA, uvB, uvC );
  13608. }
  13609. intersection.face = new THREE.Face3( a, b, c, THREE.Triangle.normal( vA, vB, vC ) );
  13610. intersection.faceIndex = a;
  13611. }
  13612. return intersection;
  13613. }
  13614. return function raycast( raycaster, intersects ) {
  13615. var geometry = this.geometry;
  13616. var material = this.material;
  13617. var matrixWorld = this.matrixWorld;
  13618. if ( material === undefined ) return;
  13619. // Checking boundingSphere distance to ray
  13620. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  13621. sphere.copy( geometry.boundingSphere );
  13622. sphere.applyMatrix4( matrixWorld );
  13623. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  13624. //
  13625. inverseMatrix.getInverse( matrixWorld );
  13626. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  13627. // Check boundingBox before continuing
  13628. if ( geometry.boundingBox !== null ) {
  13629. if ( ray.intersectsBox( geometry.boundingBox ) === false ) return;
  13630. }
  13631. var uvs, intersection;
  13632. if ( geometry instanceof THREE.BufferGeometry ) {
  13633. var a, b, c;
  13634. var index = geometry.index;
  13635. var attributes = geometry.attributes;
  13636. var positions = attributes.position.array;
  13637. if ( attributes.uv !== undefined ) {
  13638. uvs = attributes.uv.array;
  13639. }
  13640. if ( index !== null ) {
  13641. var indices = index.array;
  13642. for ( var i = 0, l = indices.length; i < l; i += 3 ) {
  13643. a = indices[ i ];
  13644. b = indices[ i + 1 ];
  13645. c = indices[ i + 2 ];
  13646. intersection = checkBufferGeometryIntersection( this, raycaster, ray, positions, uvs, a, b, c );
  13647. if ( intersection ) {
  13648. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in indices buffer semantics
  13649. intersects.push( intersection );
  13650. }
  13651. }
  13652. } else {
  13653. for ( var i = 0, l = positions.length; i < l; i += 9 ) {
  13654. a = i / 3;
  13655. b = a + 1;
  13656. c = a + 2;
  13657. intersection = checkBufferGeometryIntersection( this, raycaster, ray, positions, uvs, a, b, c );
  13658. if ( intersection ) {
  13659. intersection.index = a; // triangle number in positions buffer semantics
  13660. intersects.push( intersection );
  13661. }
  13662. }
  13663. }
  13664. } else if ( geometry instanceof THREE.Geometry ) {
  13665. var fvA, fvB, fvC;
  13666. var isFaceMaterial = material instanceof THREE.MultiMaterial;
  13667. var materials = isFaceMaterial === true ? material.materials : null;
  13668. var vertices = geometry.vertices;
  13669. var faces = geometry.faces;
  13670. var faceVertexUvs = geometry.faceVertexUvs[ 0 ];
  13671. if ( faceVertexUvs.length > 0 ) uvs = faceVertexUvs;
  13672. for ( var f = 0, fl = faces.length; f < fl; f ++ ) {
  13673. var face = faces[ f ];
  13674. var faceMaterial = isFaceMaterial === true ? materials[ face.materialIndex ] : material;
  13675. if ( faceMaterial === undefined ) continue;
  13676. fvA = vertices[ face.a ];
  13677. fvB = vertices[ face.b ];
  13678. fvC = vertices[ face.c ];
  13679. if ( faceMaterial.morphTargets === true ) {
  13680. var morphTargets = geometry.morphTargets;
  13681. var morphInfluences = this.morphTargetInfluences;
  13682. vA.set( 0, 0, 0 );
  13683. vB.set( 0, 0, 0 );
  13684. vC.set( 0, 0, 0 );
  13685. for ( var t = 0, tl = morphTargets.length; t < tl; t ++ ) {
  13686. var influence = morphInfluences[ t ];
  13687. if ( influence === 0 ) continue;
  13688. var targets = morphTargets[ t ].vertices;
  13689. vA.addScaledVector( tempA.subVectors( targets[ face.a ], fvA ), influence );
  13690. vB.addScaledVector( tempB.subVectors( targets[ face.b ], fvB ), influence );
  13691. vC.addScaledVector( tempC.subVectors( targets[ face.c ], fvC ), influence );
  13692. }
  13693. vA.add( fvA );
  13694. vB.add( fvB );
  13695. vC.add( fvC );
  13696. fvA = vA;
  13697. fvB = vB;
  13698. fvC = vC;
  13699. }
  13700. intersection = checkIntersection( this, raycaster, ray, fvA, fvB, fvC, intersectionPoint );
  13701. if ( intersection ) {
  13702. if ( uvs ) {
  13703. var uvs_f = uvs[ f ];
  13704. uvA.copy( uvs_f[ 0 ] );
  13705. uvB.copy( uvs_f[ 1 ] );
  13706. uvC.copy( uvs_f[ 2 ] );
  13707. intersection.uv = uvIntersection( intersectionPoint, fvA, fvB, fvC, uvA, uvB, uvC );
  13708. }
  13709. intersection.face = face;
  13710. intersection.faceIndex = f;
  13711. intersects.push( intersection );
  13712. }
  13713. }
  13714. }
  13715. };
  13716. }() ),
  13717. clone: function () {
  13718. return new this.constructor( this.geometry, this.material ).copy( this );
  13719. }
  13720. } );
  13721. // File:src/objects/Bone.js
  13722. /**
  13723. * @author mikael emtinger / http://gomo.se/
  13724. * @author alteredq / http://alteredqualia.com/
  13725. * @author ikerr / http://verold.com
  13726. */
  13727. THREE.Bone = function ( skin ) {
  13728. THREE.Object3D.call( this );
  13729. this.type = 'Bone';
  13730. this.skin = skin;
  13731. };
  13732. THREE.Bone.prototype = Object.assign( Object.create( THREE.Object3D.prototype ), {
  13733. constructor: THREE.Bone,
  13734. copy: function ( source ) {
  13735. THREE.Object3D.prototype.copy.call( this, source );
  13736. this.skin = source.skin;
  13737. return this;
  13738. }
  13739. } );
  13740. // File:src/objects/Skeleton.js
  13741. /**
  13742. * @author mikael emtinger / http://gomo.se/
  13743. * @author alteredq / http://alteredqualia.com/
  13744. * @author michael guerrero / http://realitymeltdown.com
  13745. * @author ikerr / http://verold.com
  13746. */
  13747. THREE.Skeleton = function ( bones, boneInverses, useVertexTexture ) {
  13748. this.useVertexTexture = useVertexTexture !== undefined ? useVertexTexture : true;
  13749. this.identityMatrix = new THREE.Matrix4();
  13750. // copy the bone array
  13751. bones = bones || [];
  13752. this.bones = bones.slice( 0 );
  13753. // create a bone texture or an array of floats
  13754. if ( this.useVertexTexture ) {
  13755. // layout (1 matrix = 4 pixels)
  13756. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  13757. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  13758. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  13759. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  13760. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  13761. var size = Math.sqrt( this.bones.length * 4 ); // 4 pixels needed for 1 matrix
  13762. size = THREE.Math.nextPowerOfTwo( Math.ceil( size ) );
  13763. size = Math.max( size, 4 );
  13764. this.boneTextureWidth = size;
  13765. this.boneTextureHeight = size;
  13766. this.boneMatrices = new Float32Array( this.boneTextureWidth * this.boneTextureHeight * 4 ); // 4 floats per RGBA pixel
  13767. this.boneTexture = new THREE.DataTexture( this.boneMatrices, this.boneTextureWidth, this.boneTextureHeight, THREE.RGBAFormat, THREE.FloatType );
  13768. } else {
  13769. this.boneMatrices = new Float32Array( 16 * this.bones.length );
  13770. }
  13771. // use the supplied bone inverses or calculate the inverses
  13772. if ( boneInverses === undefined ) {
  13773. this.calculateInverses();
  13774. } else {
  13775. if ( this.bones.length === boneInverses.length ) {
  13776. this.boneInverses = boneInverses.slice( 0 );
  13777. } else {
  13778. console.warn( 'THREE.Skeleton bonInverses is the wrong length.' );
  13779. this.boneInverses = [];
  13780. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13781. this.boneInverses.push( new THREE.Matrix4() );
  13782. }
  13783. }
  13784. }
  13785. };
  13786. Object.assign( THREE.Skeleton.prototype, {
  13787. calculateInverses: function () {
  13788. this.boneInverses = [];
  13789. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13790. var inverse = new THREE.Matrix4();
  13791. if ( this.bones[ b ] ) {
  13792. inverse.getInverse( this.bones[ b ].matrixWorld );
  13793. }
  13794. this.boneInverses.push( inverse );
  13795. }
  13796. },
  13797. pose: function () {
  13798. var bone;
  13799. // recover the bind-time world matrices
  13800. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13801. bone = this.bones[ b ];
  13802. if ( bone ) {
  13803. bone.matrixWorld.getInverse( this.boneInverses[ b ] );
  13804. }
  13805. }
  13806. // compute the local matrices, positions, rotations and scales
  13807. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13808. bone = this.bones[ b ];
  13809. if ( bone ) {
  13810. if ( bone.parent instanceof THREE.Bone ) {
  13811. bone.matrix.getInverse( bone.parent.matrixWorld );
  13812. bone.matrix.multiply( bone.matrixWorld );
  13813. } else {
  13814. bone.matrix.copy( bone.matrixWorld );
  13815. }
  13816. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  13817. }
  13818. }
  13819. },
  13820. update: ( function () {
  13821. var offsetMatrix = new THREE.Matrix4();
  13822. return function update() {
  13823. // flatten bone matrices to array
  13824. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13825. // compute the offset between the current and the original transform
  13826. var matrix = this.bones[ b ] ? this.bones[ b ].matrixWorld : this.identityMatrix;
  13827. offsetMatrix.multiplyMatrices( matrix, this.boneInverses[ b ] );
  13828. offsetMatrix.toArray( this.boneMatrices, b * 16 );
  13829. }
  13830. if ( this.useVertexTexture ) {
  13831. this.boneTexture.needsUpdate = true;
  13832. }
  13833. };
  13834. } )(),
  13835. clone: function () {
  13836. return new THREE.Skeleton( this.bones, this.boneInverses, this.useVertexTexture );
  13837. }
  13838. } );
  13839. // File:src/objects/SkinnedMesh.js
  13840. /**
  13841. * @author mikael emtinger / http://gomo.se/
  13842. * @author alteredq / http://alteredqualia.com/
  13843. * @author ikerr / http://verold.com
  13844. */
  13845. THREE.SkinnedMesh = function ( geometry, material, useVertexTexture ) {
  13846. THREE.Mesh.call( this, geometry, material );
  13847. this.type = 'SkinnedMesh';
  13848. this.bindMode = "attached";
  13849. this.bindMatrix = new THREE.Matrix4();
  13850. this.bindMatrixInverse = new THREE.Matrix4();
  13851. // init bones
  13852. // TODO: remove bone creation as there is no reason (other than
  13853. // convenience) for THREE.SkinnedMesh to do this.
  13854. var bones = [];
  13855. if ( this.geometry && this.geometry.bones !== undefined ) {
  13856. var bone, gbone;
  13857. for ( var b = 0, bl = this.geometry.bones.length; b < bl; ++ b ) {
  13858. gbone = this.geometry.bones[ b ];
  13859. bone = new THREE.Bone( this );
  13860. bones.push( bone );
  13861. bone.name = gbone.name;
  13862. bone.position.fromArray( gbone.pos );
  13863. bone.quaternion.fromArray( gbone.rotq );
  13864. if ( gbone.scl !== undefined ) bone.scale.fromArray( gbone.scl );
  13865. }
  13866. for ( var b = 0, bl = this.geometry.bones.length; b < bl; ++ b ) {
  13867. gbone = this.geometry.bones[ b ];
  13868. if ( gbone.parent !== - 1 && gbone.parent !== null &&
  13869. bones[ gbone.parent ] !== undefined ) {
  13870. bones[ gbone.parent ].add( bones[ b ] );
  13871. } else {
  13872. this.add( bones[ b ] );
  13873. }
  13874. }
  13875. }
  13876. this.normalizeSkinWeights();
  13877. this.updateMatrixWorld( true );
  13878. this.bind( new THREE.Skeleton( bones, undefined, useVertexTexture ), this.matrixWorld );
  13879. };
  13880. THREE.SkinnedMesh.prototype = Object.assign( Object.create( THREE.Mesh.prototype ), {
  13881. constructor: THREE.SkinnedMesh,
  13882. bind: function( skeleton, bindMatrix ) {
  13883. this.skeleton = skeleton;
  13884. if ( bindMatrix === undefined ) {
  13885. this.updateMatrixWorld( true );
  13886. this.skeleton.calculateInverses();
  13887. bindMatrix = this.matrixWorld;
  13888. }
  13889. this.bindMatrix.copy( bindMatrix );
  13890. this.bindMatrixInverse.getInverse( bindMatrix );
  13891. },
  13892. pose: function () {
  13893. this.skeleton.pose();
  13894. },
  13895. normalizeSkinWeights: function () {
  13896. if ( this.geometry instanceof THREE.Geometry ) {
  13897. for ( var i = 0; i < this.geometry.skinWeights.length; i ++ ) {
  13898. var sw = this.geometry.skinWeights[ i ];
  13899. var scale = 1.0 / sw.lengthManhattan();
  13900. if ( scale !== Infinity ) {
  13901. sw.multiplyScalar( scale );
  13902. } else {
  13903. sw.set( 1, 0, 0, 0 ); // do something reasonable
  13904. }
  13905. }
  13906. } else if ( this.geometry instanceof THREE.BufferGeometry ) {
  13907. var vec = new THREE.Vector4();
  13908. var skinWeight = this.geometry.attributes.skinWeight;
  13909. for ( var i = 0; i < skinWeight.count; i ++ ) {
  13910. vec.x = skinWeight.getX( i );
  13911. vec.y = skinWeight.getY( i );
  13912. vec.z = skinWeight.getZ( i );
  13913. vec.w = skinWeight.getW( i );
  13914. var scale = 1.0 / vec.lengthManhattan();
  13915. if ( scale !== Infinity ) {
  13916. vec.multiplyScalar( scale );
  13917. } else {
  13918. vec.set( 1, 0, 0, 0 ); // do something reasonable
  13919. }
  13920. skinWeight.setXYZW( i, vec.x, vec.y, vec.z, vec.w );
  13921. }
  13922. }
  13923. },
  13924. updateMatrixWorld: function( force ) {
  13925. THREE.Mesh.prototype.updateMatrixWorld.call( this, true );
  13926. if ( this.bindMode === "attached" ) {
  13927. this.bindMatrixInverse.getInverse( this.matrixWorld );
  13928. } else if ( this.bindMode === "detached" ) {
  13929. this.bindMatrixInverse.getInverse( this.bindMatrix );
  13930. } else {
  13931. console.warn( 'THREE.SkinnedMesh unrecognized bindMode: ' + this.bindMode );
  13932. }
  13933. },
  13934. clone: function() {
  13935. return new this.constructor( this.geometry, this.material, this.skeleton.useVertexTexture ).copy( this );
  13936. }
  13937. } );
  13938. // File:src/objects/LOD.js
  13939. /**
  13940. * @author mikael emtinger / http://gomo.se/
  13941. * @author alteredq / http://alteredqualia.com/
  13942. * @author mrdoob / http://mrdoob.com/
  13943. */
  13944. THREE.LOD = function () {
  13945. THREE.Object3D.call( this );
  13946. this.type = 'LOD';
  13947. Object.defineProperties( this, {
  13948. levels: {
  13949. enumerable: true,
  13950. value: []
  13951. }
  13952. } );
  13953. };
  13954. THREE.LOD.prototype = Object.assign( Object.create( THREE.Object3D.prototype ), {
  13955. constructor: THREE.LOD,
  13956. copy: function ( source ) {
  13957. THREE.Object3D.prototype.copy.call( this, source, false );
  13958. var levels = source.levels;
  13959. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  13960. var level = levels[ i ];
  13961. this.addLevel( level.object.clone(), level.distance );
  13962. }
  13963. return this;
  13964. },
  13965. addLevel: function ( object, distance ) {
  13966. if ( distance === undefined ) distance = 0;
  13967. distance = Math.abs( distance );
  13968. var levels = this.levels;
  13969. for ( var l = 0; l < levels.length; l ++ ) {
  13970. if ( distance < levels[ l ].distance ) {
  13971. break;
  13972. }
  13973. }
  13974. levels.splice( l, 0, { distance: distance, object: object } );
  13975. this.add( object );
  13976. },
  13977. getObjectForDistance: function ( distance ) {
  13978. var levels = this.levels;
  13979. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  13980. if ( distance < levels[ i ].distance ) {
  13981. break;
  13982. }
  13983. }
  13984. return levels[ i - 1 ].object;
  13985. },
  13986. raycast: ( function () {
  13987. var matrixPosition = new THREE.Vector3();
  13988. return function raycast( raycaster, intersects ) {
  13989. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  13990. var distance = raycaster.ray.origin.distanceTo( matrixPosition );
  13991. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  13992. };
  13993. }() ),
  13994. update: function () {
  13995. var v1 = new THREE.Vector3();
  13996. var v2 = new THREE.Vector3();
  13997. return function update( camera ) {
  13998. var levels = this.levels;
  13999. if ( levels.length > 1 ) {
  14000. v1.setFromMatrixPosition( camera.matrixWorld );
  14001. v2.setFromMatrixPosition( this.matrixWorld );
  14002. var distance = v1.distanceTo( v2 );
  14003. levels[ 0 ].object.visible = true;
  14004. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  14005. if ( distance >= levels[ i ].distance ) {
  14006. levels[ i - 1 ].object.visible = false;
  14007. levels[ i ].object.visible = true;
  14008. } else {
  14009. break;
  14010. }
  14011. }
  14012. for ( ; i < l; i ++ ) {
  14013. levels[ i ].object.visible = false;
  14014. }
  14015. }
  14016. };
  14017. }(),
  14018. toJSON: function ( meta ) {
  14019. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  14020. data.object.levels = [];
  14021. var levels = this.levels;
  14022. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  14023. var level = levels[ i ];
  14024. data.object.levels.push( {
  14025. object: level.object.uuid,
  14026. distance: level.distance
  14027. } );
  14028. }
  14029. return data;
  14030. }
  14031. } );
  14032. // File:src/objects/Sprite.js
  14033. /**
  14034. * @author mikael emtinger / http://gomo.se/
  14035. * @author alteredq / http://alteredqualia.com/
  14036. */
  14037. THREE.Sprite = function ( material ) {
  14038. THREE.Object3D.call( this );
  14039. this.type = 'Sprite';
  14040. this.material = ( material !== undefined ) ? material : new THREE.SpriteMaterial();
  14041. };
  14042. THREE.Sprite.prototype = Object.assign( Object.create( THREE.Object3D.prototype ), {
  14043. constructor: THREE.Sprite,
  14044. raycast: ( function () {
  14045. var matrixPosition = new THREE.Vector3();
  14046. return function raycast( raycaster, intersects ) {
  14047. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  14048. var distanceSq = raycaster.ray.distanceSqToPoint( matrixPosition );
  14049. var guessSizeSq = this.scale.x * this.scale.y / 4;
  14050. if ( distanceSq > guessSizeSq ) {
  14051. return;
  14052. }
  14053. intersects.push( {
  14054. distance: Math.sqrt( distanceSq ),
  14055. point: this.position,
  14056. face: null,
  14057. object: this
  14058. } );
  14059. };
  14060. }() ),
  14061. clone: function () {
  14062. return new this.constructor( this.material ).copy( this );
  14063. }
  14064. } );
  14065. // File:src/objects/LensFlare.js
  14066. /**
  14067. * @author mikael emtinger / http://gomo.se/
  14068. * @author alteredq / http://alteredqualia.com/
  14069. */
  14070. THREE.LensFlare = function ( texture, size, distance, blending, color ) {
  14071. THREE.Object3D.call( this );
  14072. this.lensFlares = [];
  14073. this.positionScreen = new THREE.Vector3();
  14074. this.customUpdateCallback = undefined;
  14075. if ( texture !== undefined ) {
  14076. this.add( texture, size, distance, blending, color );
  14077. }
  14078. };
  14079. THREE.LensFlare.prototype = Object.assign( Object.create( THREE.Object3D.prototype ), {
  14080. constructor: THREE.LensFlare,
  14081. copy: function ( source ) {
  14082. THREE.Object3D.prototype.copy.call( this, source );
  14083. this.positionScreen.copy( source.positionScreen );
  14084. this.customUpdateCallback = source.customUpdateCallback;
  14085. for ( var i = 0, l = source.lensFlares.length; i < l; i ++ ) {
  14086. this.lensFlares.push( source.lensFlares[ i ] );
  14087. }
  14088. return this;
  14089. },
  14090. add: function ( texture, size, distance, blending, color, opacity ) {
  14091. if ( size === undefined ) size = - 1;
  14092. if ( distance === undefined ) distance = 0;
  14093. if ( opacity === undefined ) opacity = 1;
  14094. if ( color === undefined ) color = new THREE.Color( 0xffffff );
  14095. if ( blending === undefined ) blending = THREE.NormalBlending;
  14096. distance = Math.min( distance, Math.max( 0, distance ) );
  14097. this.lensFlares.push( {
  14098. texture: texture, // THREE.Texture
  14099. size: size, // size in pixels (-1 = use texture.width)
  14100. distance: distance, // distance (0-1) from light source (0=at light source)
  14101. x: 0, y: 0, z: 0, // screen position (-1 => 1) z = 0 is in front z = 1 is back
  14102. scale: 1, // scale
  14103. rotation: 0, // rotation
  14104. opacity: opacity, // opacity
  14105. color: color, // color
  14106. blending: blending // blending
  14107. } );
  14108. },
  14109. /*
  14110. * Update lens flares update positions on all flares based on the screen position
  14111. * Set myLensFlare.customUpdateCallback to alter the flares in your project specific way.
  14112. */
  14113. updateLensFlares: function () {
  14114. var f, fl = this.lensFlares.length;
  14115. var flare;
  14116. var vecX = - this.positionScreen.x * 2;
  14117. var vecY = - this.positionScreen.y * 2;
  14118. for ( f = 0; f < fl; f ++ ) {
  14119. flare = this.lensFlares[ f ];
  14120. flare.x = this.positionScreen.x + vecX * flare.distance;
  14121. flare.y = this.positionScreen.y + vecY * flare.distance;
  14122. flare.wantedRotation = flare.x * Math.PI * 0.25;
  14123. flare.rotation += ( flare.wantedRotation - flare.rotation ) * 0.25;
  14124. }
  14125. }
  14126. } );
  14127. // File:src/scenes/Scene.js
  14128. /**
  14129. * @author mrdoob / http://mrdoob.com/
  14130. */
  14131. THREE.Scene = function () {
  14132. THREE.Object3D.call( this );
  14133. this.type = 'Scene';
  14134. this.background = null;
  14135. this.fog = null;
  14136. this.overrideMaterial = null;
  14137. this.autoUpdate = true; // checked by the renderer
  14138. };
  14139. THREE.Scene.prototype = Object.create( THREE.Object3D.prototype );
  14140. THREE.Scene.prototype.constructor = THREE.Scene;
  14141. THREE.Scene.prototype.copy = function ( source, recursive ) {
  14142. THREE.Object3D.prototype.copy.call( this, source, recursive );
  14143. if ( source.background !== null ) this.background = source.background.clone();
  14144. if ( source.fog !== null ) this.fog = source.fog.clone();
  14145. if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
  14146. this.autoUpdate = source.autoUpdate;
  14147. this.matrixAutoUpdate = source.matrixAutoUpdate;
  14148. return this;
  14149. };
  14150. // File:src/scenes/Fog.js
  14151. /**
  14152. * @author mrdoob / http://mrdoob.com/
  14153. * @author alteredq / http://alteredqualia.com/
  14154. */
  14155. THREE.Fog = function ( color, near, far ) {
  14156. this.name = '';
  14157. this.color = new THREE.Color( color );
  14158. this.near = ( near !== undefined ) ? near : 1;
  14159. this.far = ( far !== undefined ) ? far : 1000;
  14160. };
  14161. THREE.Fog.prototype.clone = function () {
  14162. return new THREE.Fog( this.color.getHex(), this.near, this.far );
  14163. };
  14164. // File:src/scenes/FogExp2.js
  14165. /**
  14166. * @author mrdoob / http://mrdoob.com/
  14167. * @author alteredq / http://alteredqualia.com/
  14168. */
  14169. THREE.FogExp2 = function ( color, density ) {
  14170. this.name = '';
  14171. this.color = new THREE.Color( color );
  14172. this.density = ( density !== undefined ) ? density : 0.00025;
  14173. };
  14174. THREE.FogExp2.prototype.clone = function () {
  14175. return new THREE.FogExp2( this.color.getHex(), this.density );
  14176. };
  14177. // File:src/renderers/shaders/ShaderChunk.js
  14178. THREE.ShaderChunk = {};
  14179. // File:src/renderers/shaders/ShaderChunk/alphamap_fragment.glsl
  14180. THREE.ShaderChunk[ 'alphamap_fragment' ] = "#ifdef USE_ALPHAMAP\n diffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif\n";
  14181. // File:src/renderers/shaders/ShaderChunk/alphamap_pars_fragment.glsl
  14182. THREE.ShaderChunk[ 'alphamap_pars_fragment' ] = "#ifdef USE_ALPHAMAP\n uniform sampler2D alphaMap;\n#endif\n";
  14183. // File:src/renderers/shaders/ShaderChunk/alphatest_fragment.glsl
  14184. THREE.ShaderChunk[ 'alphatest_fragment' ] = "#ifdef ALPHATEST\n if ( diffuseColor.a < ALPHATEST ) discard;\n#endif\n";
  14185. // File:src/renderers/shaders/ShaderChunk/aomap_fragment.glsl
  14186. 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";
  14187. // File:src/renderers/shaders/ShaderChunk/aomap_pars_fragment.glsl
  14188. THREE.ShaderChunk[ 'aomap_pars_fragment' ] = "#ifdef USE_AOMAP\n uniform sampler2D aoMap;\n uniform float aoMapIntensity;\n#endif";
  14189. // File:src/renderers/shaders/ShaderChunk/begin_vertex.glsl
  14190. THREE.ShaderChunk[ 'begin_vertex' ] = "\nvec3 transformed = vec3( position );\n";
  14191. // File:src/renderers/shaders/ShaderChunk/beginnormal_vertex.glsl
  14192. THREE.ShaderChunk[ 'beginnormal_vertex' ] = "\nvec3 objectNormal = vec3( normal );\n";
  14193. // File:src/renderers/shaders/ShaderChunk/bsdfs.glsl
  14194. 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";
  14195. // File:src/renderers/shaders/ShaderChunk/bumpmap_pars_fragment.glsl
  14196. 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";
  14197. // File:src/renderers/shaders/ShaderChunk/clipping_planes_fragment.glsl
  14198. 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";
  14199. // File:src/renderers/shaders/ShaderChunk/clipping_planes_pars_fragment.glsl
  14200. 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";
  14201. // File:src/renderers/shaders/ShaderChunk/clipping_planes_pars_vertex.glsl
  14202. THREE.ShaderChunk[ 'clipping_planes_pars_vertex' ] = "#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG )\n varying vec3 vViewPosition;\n#endif\n";
  14203. // File:src/renderers/shaders/ShaderChunk/clipping_planes_vertex.glsl
  14204. THREE.ShaderChunk[ 'clipping_planes_vertex' ] = "#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG )\n vViewPosition = - mvPosition.xyz;\n#endif\n";
  14205. // File:src/renderers/shaders/ShaderChunk/color_fragment.glsl
  14206. THREE.ShaderChunk[ 'color_fragment' ] = "#ifdef USE_COLOR\n diffuseColor.rgb *= vColor;\n#endif";
  14207. // File:src/renderers/shaders/ShaderChunk/color_pars_fragment.glsl
  14208. THREE.ShaderChunk[ 'color_pars_fragment' ] = "#ifdef USE_COLOR\n varying vec3 vColor;\n#endif\n";
  14209. // File:src/renderers/shaders/ShaderChunk/color_pars_vertex.glsl
  14210. THREE.ShaderChunk[ 'color_pars_vertex' ] = "#ifdef USE_COLOR\n varying vec3 vColor;\n#endif";
  14211. // File:src/renderers/shaders/ShaderChunk/color_vertex.glsl
  14212. THREE.ShaderChunk[ 'color_vertex' ] = "#ifdef USE_COLOR\n vColor.xyz = color.xyz;\n#endif";
  14213. // File:src/renderers/shaders/ShaderChunk/common.glsl
  14214. 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";
  14215. // File:src/renderers/shaders/ShaderChunk/cube_uv_reflection_fragment.glsl
  14216. THREE.ShaderChunk[ 'cube_uv_reflection_fragment' ] = "#ifdef ENVMAP_TYPE_CUBE_UV\n#define cubeUV_textureSize (1024.0)\nint getFaceFromDirection(vec3 direction) {\n vec3 absDirection = abs(direction);\n int face = -1;\n if( absDirection.x > absDirection.z ) {\n if(absDirection.x > absDirection.y )\n face = direction.x > 0.0 ? 0 : 3;\n else\n face = direction.y > 0.0 ? 1 : 4;\n }\n else {\n if(absDirection.z > absDirection.y )\n face = direction.z > 0.0 ? 2 : 5;\n else\n face = direction.y > 0.0 ? 1 : 4;\n }\n return face;\n}\n#define cubeUV_maxLods1 (log2(cubeUV_textureSize*0.25) - 1.0)\n#define cubeUV_rangeClamp (exp2((6.0 - 1.0) * 2.0))\nvec2 MipLevelInfo( vec3 vec, float roughnessLevel, float roughness ) {\n float scale = exp2(cubeUV_maxLods1 - roughnessLevel);\n float dxRoughness = dFdx(roughness);\n float dyRoughness = dFdy(roughness);\n vec3 dx = dFdx( vec * scale * dxRoughness );\n vec3 dy = dFdy( vec * scale * dyRoughness );\n float d = max( dot( dx, dx ), dot( dy, dy ) );\n d = clamp(d, 1.0, cubeUV_rangeClamp);\n float mipLevel = 0.5 * log2(d);\n return vec2(floor(mipLevel), fract(mipLevel));\n}\n#define cubeUV_maxLods2 (log2(cubeUV_textureSize*0.25) - 2.0)\n#define cubeUV_rcpTextureSize (1.0 / cubeUV_textureSize)\nvec2 getCubeUV(vec3 direction, float roughnessLevel, float mipLevel) {\n mipLevel = roughnessLevel > cubeUV_maxLods2 - 3.0 ? 0.0 : mipLevel;\n float a = 16.0 * cubeUV_rcpTextureSize;\n vec2 exp2_packed = exp2( vec2( roughnessLevel, mipLevel ) );\n vec2 rcp_exp2_packed = vec2( 1.0 ) / exp2_packed;\n float powScale = exp2_packed.x * exp2_packed.y;\n float scale = rcp_exp2_packed.x * rcp_exp2_packed.y * 0.25;\n float mipOffset = 0.75*(1.0 - rcp_exp2_packed.y) * rcp_exp2_packed.x;\n bool bRes = mipLevel == 0.0;\n scale = bRes && (scale < a) ? a : scale;\n vec3 r;\n vec2 offset;\n int face = getFaceFromDirection(direction);\n float rcpPowScale = 1.0 / powScale;\n if( face == 0) {\n r = vec3(direction.x, -direction.z, direction.y);\n offset = vec2(0.0+mipOffset,0.75 * rcpPowScale);\n offset.y = bRes && (offset.y < 2.0*a) ? a : offset.y;\n }\n else if( face == 1) {\n r = vec3(direction.y, direction.x, direction.z);\n offset = vec2(scale+mipOffset, 0.75 * rcpPowScale);\n offset.y = bRes && (offset.y < 2.0*a) ? a : offset.y;\n }\n else if( face == 2) {\n r = vec3(direction.z, direction.x, direction.y);\n offset = vec2(2.0*scale+mipOffset, 0.75 * rcpPowScale);\n offset.y = bRes && (offset.y < 2.0*a) ? a : offset.y;\n }\n else if( face == 3) {\n r = vec3(direction.x, direction.z, direction.y);\n offset = vec2(0.0+mipOffset,0.5 * rcpPowScale);\n offset.y = bRes && (offset.y < 2.0*a) ? 0.0 : offset.y;\n }\n else if( face == 4) {\n r = vec3(direction.y, direction.x, -direction.z);\n offset = vec2(scale+mipOffset, 0.5 * rcpPowScale);\n offset.y = bRes && (offset.y < 2.0*a) ? 0.0 : offset.y;\n }\n else {\n r = vec3(direction.z, -direction.x, direction.y);\n offset = vec2(2.0*scale+mipOffset, 0.5 * rcpPowScale);\n offset.y = bRes && (offset.y < 2.0*a) ? 0.0 : offset.y;\n }\n r = normalize(r);\n float texelOffset = 0.5 * cubeUV_rcpTextureSize;\n vec2 s = ( r.yz / abs( r.x ) + vec2( 1.0 ) ) * 0.5;\n vec2 base = offset + vec2( texelOffset );\n return base + s * ( scale - 2.0 * texelOffset );\n}\n#define cubeUV_maxLods3 (log2(cubeUV_textureSize*0.25) - 3.0)\nvec4 textureCubeUV(vec3 reflectedDirection, float roughness ) {\n float roughnessVal = roughness* cubeUV_maxLods3;\n float r1 = floor(roughnessVal);\n float r2 = r1 + 1.0;\n float t = fract(roughnessVal);\n vec2 mipInfo = MipLevelInfo(reflectedDirection, r1, roughness);\n float s = mipInfo.y;\n float level0 = mipInfo.x;\n float level1 = level0 + 1.0;\n level1 = level1 > 5.0 ? 5.0 : level1;\n level0 += min( floor( s + 0.5 ), 5.0 );\n vec2 uv_10 = getCubeUV(reflectedDirection, r1, level0);\n vec4 color10 = envMapTexelToLinear(texture2D(envMap, uv_10));\n vec2 uv_20 = getCubeUV(reflectedDirection, r2, level0);\n vec4 color20 = envMapTexelToLinear(texture2D(envMap, uv_20));\n vec4 result = mix(color10, color20, t);\n return vec4(result.rgb, 1.0);\n}\n#endif\n";
  14217. // File:src/renderers/shaders/ShaderChunk/defaultnormal_vertex.glsl
  14218. THREE.ShaderChunk[ 'defaultnormal_vertex' ] = "#ifdef FLIP_SIDED\n objectNormal = -objectNormal;\n#endif\nvec3 transformedNormal = normalMatrix * objectNormal;\n";
  14219. // File:src/renderers/shaders/ShaderChunk/displacementmap_vertex.glsl
  14220. THREE.ShaderChunk[ 'displacementmap_vertex' ] = "#ifdef USE_DISPLACEMENTMAP\n transformed += normal * ( texture2D( displacementMap, uv ).x * displacementScale + displacementBias );\n#endif\n";
  14221. // File:src/renderers/shaders/ShaderChunk/displacementmap_pars_vertex.glsl
  14222. THREE.ShaderChunk[ 'displacementmap_pars_vertex' ] = "#ifdef USE_DISPLACEMENTMAP\n uniform sampler2D displacementMap;\n uniform float displacementScale;\n uniform float displacementBias;\n#endif\n";
  14223. // File:src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl
  14224. 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";
  14225. // File:src/renderers/shaders/ShaderChunk/emissivemap_pars_fragment.glsl
  14226. THREE.ShaderChunk[ 'emissivemap_pars_fragment' ] = "#ifdef USE_EMISSIVEMAP\n uniform sampler2D emissiveMap;\n#endif\n";
  14227. // File:src/renderers/shaders/ShaderChunk/encodings_pars_fragment.glsl
  14228. 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";
  14229. // File:src/renderers/shaders/ShaderChunk/encodings_fragment.glsl
  14230. THREE.ShaderChunk[ 'encodings_fragment' ] = " gl_FragColor = linearToOutputTexel( gl_FragColor );\n";
  14231. // File:src/renderers/shaders/ShaderChunk/envmap_fragment.glsl
  14232. 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 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";
  14233. // File:src/renderers/shaders/ShaderChunk/envmap_pars_fragment.glsl
  14234. 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";
  14235. // File:src/renderers/shaders/ShaderChunk/envmap_pars_vertex.glsl
  14236. 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";
  14237. // File:src/renderers/shaders/ShaderChunk/envmap_vertex.glsl
  14238. 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";
  14239. // File:src/renderers/shaders/ShaderChunk/fog_fragment.glsl
  14240. 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";
  14241. // File:src/renderers/shaders/ShaderChunk/fog_pars_fragment.glsl
  14242. 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";
  14243. // File:src/renderers/shaders/ShaderChunk/lightmap_fragment.glsl
  14244. THREE.ShaderChunk[ 'lightmap_fragment' ] = "#ifdef USE_LIGHTMAP\n reflectedLight.indirectDiffuse += PI * texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n#endif\n";
  14245. // File:src/renderers/shaders/ShaderChunk/lightmap_pars_fragment.glsl
  14246. THREE.ShaderChunk[ 'lightmap_pars_fragment' ] = "#ifdef USE_LIGHTMAP\n uniform sampler2D lightMap;\n uniform float lightMapIntensity;\n#endif";
  14247. // File:src/renderers/shaders/ShaderChunk/lights_lambert_vertex.glsl
  14248. 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";
  14249. // File:src/renderers/shaders/ShaderChunk/lights_pars.glsl
  14250. 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 #include <normal_flip>\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 #include <normal_flip>\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";
  14251. // File:src/renderers/shaders/ShaderChunk/lights_phong_fragment.glsl
  14252. THREE.ShaderChunk[ 'lights_phong_fragment' ] = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;\n";
  14253. // File:src/renderers/shaders/ShaderChunk/lights_phong_pars_fragment.glsl
  14254. 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";
  14255. // File:src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl
  14256. 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( DEFAULT_SPECULAR_COEFFICIENT ), diffuseColor.rgb, metalnessFactor );\n#else\n material.specularColor = mix( vec3( MAXIMUM_SPECULAR_COEFFICIENT * pow2( reflectivity ) ), diffuseColor.rgb, metalnessFactor );\n material.clearCoat = saturate( clearCoat ); material.clearCoatRoughness = clamp( clearCoatRoughness, 0.04, 1.0 );\n#endif\n";
  14257. // File:src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl
  14258. THREE.ShaderChunk[ 'lights_physical_pars_fragment' ] = "struct PhysicalMaterial {\n vec3 diffuseColor;\n float specularRoughness;\n vec3 specularColor;\n #ifndef STANDARD\n float clearCoat;\n float clearCoatRoughness;\n #endif\n};\n#define MAXIMUM_SPECULAR_COEFFICIENT 0.16\n#define DEFAULT_SPECULAR_COEFFICIENT 0.04\nfloat clearCoatDHRApprox( const in float roughness, const in float dotNL ) {\n return DEFAULT_SPECULAR_COEFFICIENT + ( 1.0 - DEFAULT_SPECULAR_COEFFICIENT ) * ( pow( 1.0 - dotNL, 5.0 ) * pow( 1.0 - roughness, 2.0 ) );\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 #ifndef STANDARD\n float clearCoatDHR = material.clearCoat * clearCoatDHRApprox( material.clearCoatRoughness, dotNL );\n #else\n float clearCoatDHR = 0.0;\n #endif\n reflectedLight.directSpecular += ( 1.0 - clearCoatDHR ) * irradiance * BRDF_Specular_GGX( directLight, geometry, material.specularColor, material.specularRoughness );\n reflectedLight.directDiffuse += ( 1.0 - clearCoatDHR ) * irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n #ifndef STANDARD\n reflectedLight.directSpecular += irradiance * material.clearCoat * BRDF_Specular_GGX( directLight, geometry, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearCoatRoughness );\n #endif\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 vec3 clearCoatRadiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n #ifndef STANDARD\n float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n float dotNL = dotNV;\n float clearCoatDHR = material.clearCoat * clearCoatDHRApprox( material.clearCoatRoughness, dotNL );\n #else\n float clearCoatDHR = 0.0;\n #endif\n reflectedLight.indirectSpecular += ( 1.0 - clearCoatDHR ) * radiance * BRDF_Specular_GGX_Environment( geometry, material.specularColor, material.specularRoughness );\n #ifndef STANDARD\n reflectedLight.indirectSpecular += clearCoatRadiance * material.clearCoat * BRDF_Specular_GGX_Environment( geometry, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearCoatRoughness );\n #endif\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 )\n#define Material_ClearCoat_BlinnShininessExponent( material ) GGXRoughnessToBlinnExponent( material.clearCoatRoughness )\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";
  14259. // File:src/renderers/shaders/ShaderChunk/lights_template.glsl
  14260. 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 #ifndef STANDARD\n vec3 clearCoatRadiance = getLightProbeIndirectRadiance( geometry, Material_ClearCoat_BlinnShininessExponent( material ), 8 );\n #else\n vec3 clearCoatRadiance = vec3( 0.0 );\n #endif\n \n RE_IndirectSpecular( radiance, clearCoatRadiance, geometry, material, reflectedLight );\n#endif\n";
  14261. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl
  14262. THREE.ShaderChunk[ 'logdepthbuf_fragment' ] = "#if defined(USE_LOGDEPTHBUF) && defined(USE_LOGDEPTHBUF_EXT)\n gl_FragDepthEXT = log2(vFragDepth) * logDepthBufFC * 0.5;\n#endif";
  14263. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl
  14264. 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";
  14265. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_pars_vertex.glsl
  14266. 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";
  14267. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl
  14268. 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";
  14269. // File:src/renderers/shaders/ShaderChunk/map_fragment.glsl
  14270. THREE.ShaderChunk[ 'map_fragment' ] = "#ifdef USE_MAP\n vec4 texelColor = texture2D( map, vUv );\n texelColor = mapTexelToLinear( texelColor );\n diffuseColor *= texelColor;\n#endif\n";
  14271. // File:src/renderers/shaders/ShaderChunk/map_pars_fragment.glsl
  14272. THREE.ShaderChunk[ 'map_pars_fragment' ] = "#ifdef USE_MAP\n uniform sampler2D map;\n#endif\n";
  14273. // File:src/renderers/shaders/ShaderChunk/map_particle_fragment.glsl
  14274. 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";
  14275. // File:src/renderers/shaders/ShaderChunk/map_particle_pars_fragment.glsl
  14276. THREE.ShaderChunk[ 'map_particle_pars_fragment' ] = "#ifdef USE_MAP\n uniform vec4 offsetRepeat;\n uniform sampler2D map;\n#endif\n";
  14277. // File:src/renderers/shaders/ShaderChunk/metalnessmap_fragment.glsl
  14278. THREE.ShaderChunk[ 'metalnessmap_fragment' ] = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n vec4 texelMetalness = texture2D( metalnessMap, vUv );\n metalnessFactor *= texelMetalness.r;\n#endif\n";
  14279. // File:src/renderers/shaders/ShaderChunk/metalnessmap_pars_fragment.glsl
  14280. THREE.ShaderChunk[ 'metalnessmap_pars_fragment' ] = "#ifdef USE_METALNESSMAP\n uniform sampler2D metalnessMap;\n#endif";
  14281. // File:src/renderers/shaders/ShaderChunk/morphnormal_vertex.glsl
  14282. 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";
  14283. // File:src/renderers/shaders/ShaderChunk/morphtarget_pars_vertex.glsl
  14284. 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";
  14285. // File:src/renderers/shaders/ShaderChunk/morphtarget_vertex.glsl
  14286. 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";
  14287. // File:src/renderers/shaders/ShaderChunk/normal_flip.glsl
  14288. THREE.ShaderChunk[ 'normal_flip' ] = "#ifdef DOUBLE_SIDED\n float flipNormal = ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n#else\n float flipNormal = 1.0;\n#endif\n";
  14289. // File:src/renderers/shaders/ShaderChunk/normal_fragment.glsl
  14290. 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 ) * flipNormal;\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";
  14291. // File:src/renderers/shaders/ShaderChunk/normalmap_pars_fragment.glsl
  14292. 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";
  14293. // File:src/renderers/shaders/ShaderChunk/packing.glsl
  14294. 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 viewZToOrthographicDepth( const in float viewZ, const in float near, const in float far ) {\n return ( viewZ + near ) / ( near - far );\n}\nfloat orthographicDepthToViewZ( 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";
  14295. // File:src/renderers/shaders/ShaderChunk/premultiplied_alpha_fragment.glsl
  14296. THREE.ShaderChunk[ 'premultiplied_alpha_fragment' ] = "#ifdef PREMULTIPLIED_ALPHA\n gl_FragColor.rgb *= gl_FragColor.a;\n#endif\n";
  14297. // File:src/renderers/shaders/ShaderChunk/project_vertex.glsl
  14298. 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";
  14299. // File:src/renderers/shaders/ShaderChunk/roughnessmap_fragment.glsl
  14300. THREE.ShaderChunk[ 'roughnessmap_fragment' ] = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n vec4 texelRoughness = texture2D( roughnessMap, vUv );\n roughnessFactor *= texelRoughness.r;\n#endif\n";
  14301. // File:src/renderers/shaders/ShaderChunk/roughnessmap_pars_fragment.glsl
  14302. THREE.ShaderChunk[ 'roughnessmap_pars_fragment' ] = "#ifdef USE_ROUGHNESSMAP\n uniform sampler2D roughnessMap;\n#endif";
  14303. // File:src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl
  14304. 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";
  14305. // File:src/renderers/shaders/ShaderChunk/shadowmap_pars_vertex.glsl
  14306. 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";
  14307. // File:src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl
  14308. 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";
  14309. // File:src/renderers/shaders/ShaderChunk/shadowmask_pars_fragment.glsl
  14310. 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";
  14311. // File:src/renderers/shaders/ShaderChunk/skinbase_vertex.glsl
  14312. 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";
  14313. // File:src/renderers/shaders/ShaderChunk/skinning_pars_vertex.glsl
  14314. 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";
  14315. // File:src/renderers/shaders/ShaderChunk/skinning_vertex.glsl
  14316. 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";
  14317. // File:src/renderers/shaders/ShaderChunk/skinnormal_vertex.glsl
  14318. 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";
  14319. // File:src/renderers/shaders/ShaderChunk/specularmap_fragment.glsl
  14320. 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";
  14321. // File:src/renderers/shaders/ShaderChunk/specularmap_pars_fragment.glsl
  14322. THREE.ShaderChunk[ 'specularmap_pars_fragment' ] = "#ifdef USE_SPECULARMAP\n uniform sampler2D specularMap;\n#endif";
  14323. // File:src/renderers/shaders/ShaderChunk/tonemapping_fragment.glsl
  14324. THREE.ShaderChunk[ 'tonemapping_fragment' ] = "#if defined( TONE_MAPPING )\n gl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif\n";
  14325. // File:src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl
  14326. 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";
  14327. // File:src/renderers/shaders/ShaderChunk/uv2_pars_fragment.glsl
  14328. THREE.ShaderChunk[ 'uv2_pars_fragment' ] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n varying vec2 vUv2;\n#endif";
  14329. // File:src/renderers/shaders/ShaderChunk/uv2_pars_vertex.glsl
  14330. THREE.ShaderChunk[ 'uv2_pars_vertex' ] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n attribute vec2 uv2;\n varying vec2 vUv2;\n#endif";
  14331. // File:src/renderers/shaders/ShaderChunk/uv2_vertex.glsl
  14332. THREE.ShaderChunk[ 'uv2_vertex' ] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n vUv2 = uv2;\n#endif";
  14333. // File:src/renderers/shaders/ShaderChunk/uv_pars_fragment.glsl
  14334. 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";
  14335. // File:src/renderers/shaders/ShaderChunk/uv_pars_vertex.glsl
  14336. 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";
  14337. // File:src/renderers/shaders/ShaderChunk/uv_vertex.glsl
  14338. 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";
  14339. // File:src/renderers/shaders/ShaderChunk/worldpos_vertex.glsl
  14340. 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";
  14341. // File:src/renderers/shaders/UniformsUtils.js
  14342. /**
  14343. * Uniform Utilities
  14344. */
  14345. THREE.UniformsUtils = {
  14346. merge: function ( uniforms ) {
  14347. var merged = {};
  14348. for ( var u = 0; u < uniforms.length; u ++ ) {
  14349. var tmp = this.clone( uniforms[ u ] );
  14350. for ( var p in tmp ) {
  14351. merged[ p ] = tmp[ p ];
  14352. }
  14353. }
  14354. return merged;
  14355. },
  14356. clone: function ( uniforms_src ) {
  14357. var uniforms_dst = {};
  14358. for ( var u in uniforms_src ) {
  14359. uniforms_dst[ u ] = {};
  14360. for ( var p in uniforms_src[ u ] ) {
  14361. var parameter_src = uniforms_src[ u ][ p ];
  14362. if ( parameter_src instanceof THREE.Color ||
  14363. parameter_src instanceof THREE.Vector2 ||
  14364. parameter_src instanceof THREE.Vector3 ||
  14365. parameter_src instanceof THREE.Vector4 ||
  14366. parameter_src instanceof THREE.Matrix3 ||
  14367. parameter_src instanceof THREE.Matrix4 ||
  14368. parameter_src instanceof THREE.Texture ) {
  14369. uniforms_dst[ u ][ p ] = parameter_src.clone();
  14370. } else if ( Array.isArray( parameter_src ) ) {
  14371. uniforms_dst[ u ][ p ] = parameter_src.slice();
  14372. } else {
  14373. uniforms_dst[ u ][ p ] = parameter_src;
  14374. }
  14375. }
  14376. }
  14377. return uniforms_dst;
  14378. }
  14379. };
  14380. // File:src/renderers/shaders/UniformsLib.js
  14381. /**
  14382. * Uniforms library for shared webgl shaders
  14383. */
  14384. THREE.UniformsLib = {
  14385. common: {
  14386. "diffuse": { value: new THREE.Color( 0xeeeeee ) },
  14387. "opacity": { value: 1.0 },
  14388. "map": { value: null },
  14389. "offsetRepeat": { value: new THREE.Vector4( 0, 0, 1, 1 ) },
  14390. "specularMap": { value: null },
  14391. "alphaMap": { value: null },
  14392. "envMap": { value: null },
  14393. "flipEnvMap": { value: - 1 },
  14394. "reflectivity": { value: 1.0 },
  14395. "refractionRatio": { value: 0.98 }
  14396. },
  14397. aomap: {
  14398. "aoMap": { value: null },
  14399. "aoMapIntensity": { value: 1 }
  14400. },
  14401. lightmap: {
  14402. "lightMap": { value: null },
  14403. "lightMapIntensity": { value: 1 }
  14404. },
  14405. emissivemap: {
  14406. "emissiveMap": { value: null }
  14407. },
  14408. bumpmap: {
  14409. "bumpMap": { value: null },
  14410. "bumpScale": { value: 1 }
  14411. },
  14412. normalmap: {
  14413. "normalMap": { value: null },
  14414. "normalScale": { value: new THREE.Vector2( 1, 1 ) }
  14415. },
  14416. displacementmap: {
  14417. "displacementMap": { value: null },
  14418. "displacementScale": { value: 1 },
  14419. "displacementBias": { value: 0 }
  14420. },
  14421. roughnessmap: {
  14422. "roughnessMap": { value: null }
  14423. },
  14424. metalnessmap: {
  14425. "metalnessMap": { value: null }
  14426. },
  14427. fog: {
  14428. "fogDensity": { value: 0.00025 },
  14429. "fogNear": { value: 1 },
  14430. "fogFar": { value: 2000 },
  14431. "fogColor": { value: new THREE.Color( 0xffffff ) }
  14432. },
  14433. lights: {
  14434. "ambientLightColor": { value: [] },
  14435. "directionalLights": { value: [], properties: {
  14436. "direction": {},
  14437. "color": {},
  14438. "shadow": {},
  14439. "shadowBias": {},
  14440. "shadowRadius": {},
  14441. "shadowMapSize": {}
  14442. } },
  14443. "directionalShadowMap": { value: [] },
  14444. "directionalShadowMatrix": { value: [] },
  14445. "spotLights": { value: [], properties: {
  14446. "color": {},
  14447. "position": {},
  14448. "direction": {},
  14449. "distance": {},
  14450. "coneCos": {},
  14451. "penumbraCos": {},
  14452. "decay": {},
  14453. "shadow": {},
  14454. "shadowBias": {},
  14455. "shadowRadius": {},
  14456. "shadowMapSize": {}
  14457. } },
  14458. "spotShadowMap": { value: [] },
  14459. "spotShadowMatrix": { value: [] },
  14460. "pointLights": { value: [], properties: {
  14461. "color": {},
  14462. "position": {},
  14463. "decay": {},
  14464. "distance": {},
  14465. "shadow": {},
  14466. "shadowBias": {},
  14467. "shadowRadius": {},
  14468. "shadowMapSize": {}
  14469. } },
  14470. "pointShadowMap": { value: [] },
  14471. "pointShadowMatrix": { value: [] },
  14472. "hemisphereLights": { value: [], properties: {
  14473. "direction": {},
  14474. "skyColor": {},
  14475. "groundColor": {}
  14476. } }
  14477. },
  14478. points: {
  14479. "diffuse": { value: new THREE.Color( 0xeeeeee ) },
  14480. "opacity": { value: 1.0 },
  14481. "size": { value: 1.0 },
  14482. "scale": { value: 1.0 },
  14483. "map": { value: null },
  14484. "offsetRepeat": { value: new THREE.Vector4( 0, 0, 1, 1 ) }
  14485. }
  14486. };
  14487. // File:src/renderers/shaders/ShaderLib/cube_frag.glsl
  14488. THREE.ShaderChunk[ 'cube_frag' ] = "uniform samplerCube tCube;\nuniform float tFlip;\nuniform float opacity;\nvarying vec3 vWorldPosition;\n#include <common>\nvoid main() {\n gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );\n gl_FragColor.a *= opacity;\n}\n";
  14489. // File:src/renderers/shaders/ShaderLib/cube_vert.glsl
  14490. THREE.ShaderChunk[ 'cube_vert' ] = "varying vec3 vWorldPosition;\n#include <common>\nvoid main() {\n vWorldPosition = transformDirection( position, modelMatrix );\n #include <begin_vertex>\n #include <project_vertex>\n}\n";
  14491. // File:src/renderers/shaders/ShaderLib/depth_frag.glsl
  14492. 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";
  14493. // File:src/renderers/shaders/ShaderLib/depth_vert.glsl
  14494. 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";
  14495. // File:src/renderers/shaders/ShaderLib/distanceRGBA_frag.glsl
  14496. 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";
  14497. // File:src/renderers/shaders/ShaderLib/distanceRGBA_vert.glsl
  14498. 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";
  14499. // File:src/renderers/shaders/ShaderLib/equirect_frag.glsl
  14500. THREE.ShaderChunk[ 'equirect_frag' ] = "uniform sampler2D tEquirect;\nuniform float tFlip;\nvarying vec3 vWorldPosition;\n#include <common>\nvoid main() {\n vec3 direction = normalize( vWorldPosition );\n vec2 sampleUV;\n sampleUV.y = saturate( tFlip * direction.y * -0.5 + 0.5 );\n sampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;\n gl_FragColor = texture2D( tEquirect, sampleUV );\n}\n";
  14501. // File:src/renderers/shaders/ShaderLib/equirect_vert.glsl
  14502. THREE.ShaderChunk[ 'equirect_vert' ] = "varying vec3 vWorldPosition;\n#include <common>\nvoid main() {\n vWorldPosition = transformDirection( position, modelMatrix );\n #include <begin_vertex>\n #include <project_vertex>\n}\n";
  14503. // File:src/renderers/shaders/ShaderLib/linedashed_frag.glsl
  14504. 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";
  14505. // File:src/renderers/shaders/ShaderLib/linedashed_vert.glsl
  14506. 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";
  14507. // File:src/renderers/shaders/ShaderLib/meshbasic_frag.glsl
  14508. 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 <normal_flip>\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";
  14509. // File:src/renderers/shaders/ShaderLib/meshbasic_vert.glsl
  14510. 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";
  14511. // File:src/renderers/shaders/ShaderLib/meshlambert_frag.glsl
  14512. 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 <normal_flip>\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";
  14513. // File:src/renderers/shaders/ShaderLib/meshlambert_vert.glsl
  14514. 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";
  14515. // File:src/renderers/shaders/ShaderLib/meshphong_frag.glsl
  14516. 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_flip>\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";
  14517. // File:src/renderers/shaders/ShaderLib/meshphong_vert.glsl
  14518. 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";
  14519. // File:src/renderers/shaders/ShaderLib/meshphysical_frag.glsl
  14520. THREE.ShaderChunk[ 'meshphysical_frag' ] = "#define PHYSICAL\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float roughness;\nuniform float metalness;\nuniform float opacity;\n#ifndef STANDARD\n uniform float clearCoat;\n uniform float clearCoatRoughness;\n#endif\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_flip>\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";
  14521. // File:src/renderers/shaders/ShaderLib/meshphysical_vert.glsl
  14522. 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";
  14523. // File:src/renderers/shaders/ShaderLib/normal_frag.glsl
  14524. 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";
  14525. // File:src/renderers/shaders/ShaderLib/normal_vert.glsl
  14526. 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";
  14527. // File:src/renderers/shaders/ShaderLib/points_frag.glsl
  14528. 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";
  14529. // File:src/renderers/shaders/ShaderLib/points_vert.glsl
  14530. 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";
  14531. // File:src/renderers/shaders/ShaderLib/shadow_frag.glsl
  14532. THREE.ShaderChunk[ 'shadow_frag' ] = "uniform float opacity;\n#include <common>\n#include <packing>\n#include <bsdfs>\n#include <lights_pars>\n#include <shadowmap_pars_fragment>\n#include <shadowmask_pars_fragment>\nvoid main() {\n gl_FragColor = vec4( 0.0, 0.0, 0.0, opacity * ( 1.0 - getShadowMask() ) );\n}\n";
  14533. // File:src/renderers/shaders/ShaderLib/shadow_vert.glsl
  14534. THREE.ShaderChunk[ 'shadow_vert' ] = "#include <shadowmap_pars_vertex>\nvoid main() {\n #include <begin_vertex>\n #include <project_vertex>\n #include <worldpos_vertex>\n #include <shadowmap_vertex>\n}\n";
  14535. // File:src/renderers/shaders/ShaderLib.js
  14536. /**
  14537. * Webgl Shader Library for three.js
  14538. *
  14539. * @author alteredq / http://alteredqualia.com/
  14540. * @author mrdoob / http://mrdoob.com/
  14541. * @author mikael emtinger / http://gomo.se/
  14542. */
  14543. THREE.ShaderLib = {
  14544. 'basic': {
  14545. uniforms: THREE.UniformsUtils.merge( [
  14546. THREE.UniformsLib[ 'common' ],
  14547. THREE.UniformsLib[ 'aomap' ],
  14548. THREE.UniformsLib[ 'fog' ]
  14549. ] ),
  14550. vertexShader: THREE.ShaderChunk[ 'meshbasic_vert' ],
  14551. fragmentShader: THREE.ShaderChunk[ 'meshbasic_frag' ]
  14552. },
  14553. 'lambert': {
  14554. uniforms: THREE.UniformsUtils.merge( [
  14555. THREE.UniformsLib[ 'common' ],
  14556. THREE.UniformsLib[ 'aomap' ],
  14557. THREE.UniformsLib[ 'lightmap' ],
  14558. THREE.UniformsLib[ 'emissivemap' ],
  14559. THREE.UniformsLib[ 'fog' ],
  14560. THREE.UniformsLib[ 'lights' ],
  14561. {
  14562. "emissive" : { value: new THREE.Color( 0x000000 ) }
  14563. }
  14564. ] ),
  14565. vertexShader: THREE.ShaderChunk[ 'meshlambert_vert' ],
  14566. fragmentShader: THREE.ShaderChunk[ 'meshlambert_frag' ]
  14567. },
  14568. 'phong': {
  14569. uniforms: THREE.UniformsUtils.merge( [
  14570. THREE.UniformsLib[ 'common' ],
  14571. THREE.UniformsLib[ 'aomap' ],
  14572. THREE.UniformsLib[ 'lightmap' ],
  14573. THREE.UniformsLib[ 'emissivemap' ],
  14574. THREE.UniformsLib[ 'bumpmap' ],
  14575. THREE.UniformsLib[ 'normalmap' ],
  14576. THREE.UniformsLib[ 'displacementmap' ],
  14577. THREE.UniformsLib[ 'fog' ],
  14578. THREE.UniformsLib[ 'lights' ],
  14579. {
  14580. "emissive" : { value: new THREE.Color( 0x000000 ) },
  14581. "specular" : { value: new THREE.Color( 0x111111 ) },
  14582. "shininess": { value: 30 }
  14583. }
  14584. ] ),
  14585. vertexShader: THREE.ShaderChunk[ 'meshphong_vert' ],
  14586. fragmentShader: THREE.ShaderChunk[ 'meshphong_frag' ]
  14587. },
  14588. 'standard': {
  14589. uniforms: THREE.UniformsUtils.merge( [
  14590. THREE.UniformsLib[ 'common' ],
  14591. THREE.UniformsLib[ 'aomap' ],
  14592. THREE.UniformsLib[ 'lightmap' ],
  14593. THREE.UniformsLib[ 'emissivemap' ],
  14594. THREE.UniformsLib[ 'bumpmap' ],
  14595. THREE.UniformsLib[ 'normalmap' ],
  14596. THREE.UniformsLib[ 'displacementmap' ],
  14597. THREE.UniformsLib[ 'roughnessmap' ],
  14598. THREE.UniformsLib[ 'metalnessmap' ],
  14599. THREE.UniformsLib[ 'fog' ],
  14600. THREE.UniformsLib[ 'lights' ],
  14601. {
  14602. "emissive" : { value: new THREE.Color( 0x000000 ) },
  14603. "roughness": { value: 0.5 },
  14604. "metalness": { value: 0 },
  14605. "envMapIntensity" : { value: 1 }, // temporary
  14606. }
  14607. ] ),
  14608. vertexShader: THREE.ShaderChunk[ 'meshphysical_vert' ],
  14609. fragmentShader: THREE.ShaderChunk[ 'meshphysical_frag' ]
  14610. },
  14611. 'points': {
  14612. uniforms: THREE.UniformsUtils.merge( [
  14613. THREE.UniformsLib[ 'points' ],
  14614. THREE.UniformsLib[ 'fog' ]
  14615. ] ),
  14616. vertexShader: THREE.ShaderChunk[ 'points_vert' ],
  14617. fragmentShader: THREE.ShaderChunk[ 'points_frag' ]
  14618. },
  14619. 'dashed': {
  14620. uniforms: THREE.UniformsUtils.merge( [
  14621. THREE.UniformsLib[ 'common' ],
  14622. THREE.UniformsLib[ 'fog' ],
  14623. {
  14624. "scale" : { value: 1 },
  14625. "dashSize" : { value: 1 },
  14626. "totalSize": { value: 2 }
  14627. }
  14628. ] ),
  14629. vertexShader: THREE.ShaderChunk[ 'linedashed_vert' ],
  14630. fragmentShader: THREE.ShaderChunk[ 'linedashed_frag' ]
  14631. },
  14632. 'depth': {
  14633. uniforms: THREE.UniformsUtils.merge( [
  14634. THREE.UniformsLib[ 'common' ],
  14635. THREE.UniformsLib[ 'displacementmap' ]
  14636. ] ),
  14637. vertexShader: THREE.ShaderChunk[ 'depth_vert' ],
  14638. fragmentShader: THREE.ShaderChunk[ 'depth_frag' ]
  14639. },
  14640. 'normal': {
  14641. uniforms: {
  14642. "opacity" : { value: 1.0 }
  14643. },
  14644. vertexShader: THREE.ShaderChunk[ 'normal_vert' ],
  14645. fragmentShader: THREE.ShaderChunk[ 'normal_frag' ]
  14646. },
  14647. /* -------------------------------------------------------------------------
  14648. // Cube map shader
  14649. ------------------------------------------------------------------------- */
  14650. 'cube': {
  14651. uniforms: {
  14652. "tCube": { value: null },
  14653. "tFlip": { value: - 1 },
  14654. "opacity": { value: 1.0 }
  14655. },
  14656. vertexShader: THREE.ShaderChunk[ 'cube_vert' ],
  14657. fragmentShader: THREE.ShaderChunk[ 'cube_frag' ]
  14658. },
  14659. /* -------------------------------------------------------------------------
  14660. // Cube map shader
  14661. ------------------------------------------------------------------------- */
  14662. 'equirect': {
  14663. uniforms: {
  14664. "tEquirect": { value: null },
  14665. "tFlip": { value: - 1 }
  14666. },
  14667. vertexShader: THREE.ShaderChunk[ 'equirect_vert' ],
  14668. fragmentShader: THREE.ShaderChunk[ 'equirect_frag' ]
  14669. },
  14670. 'distanceRGBA': {
  14671. uniforms: {
  14672. "lightPos": { value: new THREE.Vector3() }
  14673. },
  14674. vertexShader: THREE.ShaderChunk[ 'distanceRGBA_vert' ],
  14675. fragmentShader: THREE.ShaderChunk[ 'distanceRGBA_frag' ]
  14676. }
  14677. };
  14678. THREE.ShaderLib[ 'physical' ] = {
  14679. uniforms: THREE.UniformsUtils.merge( [
  14680. THREE.ShaderLib[ 'standard' ].uniforms,
  14681. {
  14682. "clearCoat": { value: 0 },
  14683. "clearCoatRoughness": { value: 0 }
  14684. }
  14685. ] ),
  14686. vertexShader: THREE.ShaderChunk[ 'meshphysical_vert' ],
  14687. fragmentShader: THREE.ShaderChunk[ 'meshphysical_frag' ]
  14688. };
  14689. // File:src/renderers/WebGLRenderer.js
  14690. /**
  14691. * @author supereggbert / http://www.paulbrunt.co.uk/
  14692. * @author mrdoob / http://mrdoob.com/
  14693. * @author alteredq / http://alteredqualia.com/
  14694. * @author szimek / https://github.com/szimek/
  14695. * @author tschw
  14696. */
  14697. THREE.WebGLRenderer = function ( parameters ) {
  14698. console.log( 'THREE.WebGLRenderer', THREE.REVISION );
  14699. parameters = parameters || {};
  14700. var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' ),
  14701. _context = parameters.context !== undefined ? parameters.context : null,
  14702. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  14703. _depth = parameters.depth !== undefined ? parameters.depth : true,
  14704. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  14705. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  14706. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  14707. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false;
  14708. var lights = [];
  14709. var opaqueObjects = [];
  14710. var opaqueObjectsLastIndex = - 1;
  14711. var transparentObjects = [];
  14712. var transparentObjectsLastIndex = - 1;
  14713. var morphInfluences = new Float32Array( 8 );
  14714. var sprites = [];
  14715. var lensFlares = [];
  14716. // public properties
  14717. this.domElement = _canvas;
  14718. this.context = null;
  14719. // clearing
  14720. this.autoClear = true;
  14721. this.autoClearColor = true;
  14722. this.autoClearDepth = true;
  14723. this.autoClearStencil = true;
  14724. // scene graph
  14725. this.sortObjects = true;
  14726. // user-defined clipping
  14727. this.clippingPlanes = [];
  14728. this.localClippingEnabled = false;
  14729. // physically based shading
  14730. this.gammaFactor = 2.0; // for backwards compatibility
  14731. this.gammaInput = false;
  14732. this.gammaOutput = false;
  14733. // physical lights
  14734. this.physicallyCorrectLights = false;
  14735. // tone mapping
  14736. this.toneMapping = THREE.LinearToneMapping;
  14737. this.toneMappingExposure = 1.0;
  14738. this.toneMappingWhitePoint = 1.0;
  14739. // morphs
  14740. this.maxMorphTargets = 8;
  14741. this.maxMorphNormals = 4;
  14742. // internal properties
  14743. var _this = this,
  14744. // internal state cache
  14745. _currentProgram = null,
  14746. _currentRenderTarget = null,
  14747. _currentFramebuffer = null,
  14748. _currentMaterialId = - 1,
  14749. _currentGeometryProgram = '',
  14750. _currentCamera = null,
  14751. _currentScissor = new THREE.Vector4(),
  14752. _currentScissorTest = null,
  14753. _currentViewport = new THREE.Vector4(),
  14754. //
  14755. _usedTextureUnits = 0,
  14756. //
  14757. _clearColor = new THREE.Color( 0x000000 ),
  14758. _clearAlpha = 0,
  14759. _width = _canvas.width,
  14760. _height = _canvas.height,
  14761. _pixelRatio = 1,
  14762. _scissor = new THREE.Vector4( 0, 0, _width, _height ),
  14763. _scissorTest = false,
  14764. _viewport = new THREE.Vector4( 0, 0, _width, _height ),
  14765. // frustum
  14766. _frustum = new THREE.Frustum(),
  14767. // clipping
  14768. _clipping = new THREE.WebGLClipping(),
  14769. _clippingEnabled = false,
  14770. _localClippingEnabled = false,
  14771. _sphere = new THREE.Sphere(),
  14772. // camera matrices cache
  14773. _projScreenMatrix = new THREE.Matrix4(),
  14774. _vector3 = new THREE.Vector3(),
  14775. // light arrays cache
  14776. _lights = {
  14777. hash: '',
  14778. ambient: [ 0, 0, 0 ],
  14779. directional: [],
  14780. directionalShadowMap: [],
  14781. directionalShadowMatrix: [],
  14782. spot: [],
  14783. spotShadowMap: [],
  14784. spotShadowMatrix: [],
  14785. point: [],
  14786. pointShadowMap: [],
  14787. pointShadowMatrix: [],
  14788. hemi: [],
  14789. shadows: []
  14790. },
  14791. // info
  14792. _infoRender = {
  14793. calls: 0,
  14794. vertices: 0,
  14795. faces: 0,
  14796. points: 0
  14797. };
  14798. this.info = {
  14799. render: _infoRender,
  14800. memory: {
  14801. geometries: 0,
  14802. textures: 0
  14803. },
  14804. programs: null
  14805. };
  14806. // initialize
  14807. var _gl;
  14808. try {
  14809. var attributes = {
  14810. alpha: _alpha,
  14811. depth: _depth,
  14812. stencil: _stencil,
  14813. antialias: _antialias,
  14814. premultipliedAlpha: _premultipliedAlpha,
  14815. preserveDrawingBuffer: _preserveDrawingBuffer
  14816. };
  14817. _gl = _context || _canvas.getContext( 'webgl', attributes ) || _canvas.getContext( 'experimental-webgl', attributes );
  14818. if ( _gl === null ) {
  14819. if ( _canvas.getContext( 'webgl' ) !== null ) {
  14820. throw 'Error creating WebGL context with your selected attributes.';
  14821. } else {
  14822. throw 'Error creating WebGL context.';
  14823. }
  14824. }
  14825. // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  14826. if ( _gl.getShaderPrecisionFormat === undefined ) {
  14827. _gl.getShaderPrecisionFormat = function () {
  14828. return { 'rangeMin': 1, 'rangeMax': 1, 'precision': 1 };
  14829. };
  14830. }
  14831. _canvas.addEventListener( 'webglcontextlost', onContextLost, false );
  14832. } catch ( error ) {
  14833. console.error( 'THREE.WebGLRenderer: ' + error );
  14834. }
  14835. var extensions = new THREE.WebGLExtensions( _gl );
  14836. extensions.get( 'WEBGL_depth_texture' );
  14837. extensions.get( 'OES_texture_float' );
  14838. extensions.get( 'OES_texture_float_linear' );
  14839. extensions.get( 'OES_texture_half_float' );
  14840. extensions.get( 'OES_texture_half_float_linear' );
  14841. extensions.get( 'OES_standard_derivatives' );
  14842. extensions.get( 'ANGLE_instanced_arrays' );
  14843. if ( extensions.get( 'OES_element_index_uint' ) ) {
  14844. THREE.BufferGeometry.MaxIndex = 4294967296;
  14845. }
  14846. var capabilities = new THREE.WebGLCapabilities( _gl, extensions, parameters );
  14847. var state = new THREE.WebGLState( _gl, extensions, paramThreeToGL );
  14848. var properties = new THREE.WebGLProperties();
  14849. var textures = new THREE.WebGLTextures( _gl, extensions, state, properties, capabilities, paramThreeToGL, this.info );
  14850. var objects = new THREE.WebGLObjects( _gl, properties, this.info );
  14851. var programCache = new THREE.WebGLPrograms( this, capabilities );
  14852. var lightCache = new THREE.WebGLLights();
  14853. this.info.programs = programCache.programs;
  14854. var bufferRenderer = new THREE.WebGLBufferRenderer( _gl, extensions, _infoRender );
  14855. var indexedBufferRenderer = new THREE.WebGLIndexedBufferRenderer( _gl, extensions, _infoRender );
  14856. //
  14857. var backgroundCamera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
  14858. var backgroundCamera2 = new THREE.PerspectiveCamera();
  14859. var backgroundPlaneMesh = new THREE.Mesh(
  14860. new THREE.PlaneBufferGeometry( 2, 2 ),
  14861. new THREE.MeshBasicMaterial( { depthTest: false, depthWrite: false, fog: false } )
  14862. );
  14863. var backgroundBoxShader = THREE.ShaderLib[ 'cube' ];
  14864. var backgroundBoxMesh = new THREE.Mesh(
  14865. new THREE.BoxBufferGeometry( 5, 5, 5 ),
  14866. new THREE.ShaderMaterial( {
  14867. uniforms: backgroundBoxShader.uniforms,
  14868. vertexShader: backgroundBoxShader.vertexShader,
  14869. fragmentShader: backgroundBoxShader.fragmentShader,
  14870. side: THREE.BackSide,
  14871. depthTest: false,
  14872. depthWrite: false,
  14873. fog: false
  14874. } )
  14875. );
  14876. //
  14877. function getTargetPixelRatio() {
  14878. return _currentRenderTarget === null ? _pixelRatio : 1;
  14879. }
  14880. function glClearColor( r, g, b, a ) {
  14881. if ( _premultipliedAlpha === true ) {
  14882. r *= a; g *= a; b *= a;
  14883. }
  14884. state.clearColor( r, g, b, a );
  14885. }
  14886. function setDefaultGLState() {
  14887. state.init();
  14888. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ) );
  14889. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ) );
  14890. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  14891. }
  14892. function resetGLState() {
  14893. _currentProgram = null;
  14894. _currentCamera = null;
  14895. _currentGeometryProgram = '';
  14896. _currentMaterialId = - 1;
  14897. state.reset();
  14898. }
  14899. setDefaultGLState();
  14900. this.context = _gl;
  14901. this.capabilities = capabilities;
  14902. this.extensions = extensions;
  14903. this.properties = properties;
  14904. this.state = state;
  14905. // shadow map
  14906. var shadowMap = new THREE.WebGLShadowMap( this, _lights, objects, capabilities );
  14907. this.shadowMap = shadowMap;
  14908. // Plugins
  14909. var spritePlugin = new THREE.SpritePlugin( this, sprites );
  14910. var lensFlarePlugin = new THREE.LensFlarePlugin( this, lensFlares );
  14911. // API
  14912. this.getContext = function () {
  14913. return _gl;
  14914. };
  14915. this.getContextAttributes = function () {
  14916. return _gl.getContextAttributes();
  14917. };
  14918. this.forceContextLoss = function () {
  14919. extensions.get( 'WEBGL_lose_context' ).loseContext();
  14920. };
  14921. this.getMaxAnisotropy = function () {
  14922. return capabilities.getMaxAnisotropy();
  14923. };
  14924. this.getPrecision = function () {
  14925. return capabilities.precision;
  14926. };
  14927. this.getPixelRatio = function () {
  14928. return _pixelRatio;
  14929. };
  14930. this.setPixelRatio = function ( value ) {
  14931. if ( value === undefined ) return;
  14932. _pixelRatio = value;
  14933. this.setSize( _viewport.z, _viewport.w, false );
  14934. };
  14935. this.getSize = function () {
  14936. return {
  14937. width: _width,
  14938. height: _height
  14939. };
  14940. };
  14941. this.setSize = function ( width, height, updateStyle ) {
  14942. _width = width;
  14943. _height = height;
  14944. _canvas.width = width * _pixelRatio;
  14945. _canvas.height = height * _pixelRatio;
  14946. if ( updateStyle !== false ) {
  14947. _canvas.style.width = width + 'px';
  14948. _canvas.style.height = height + 'px';
  14949. }
  14950. this.setViewport( 0, 0, width, height );
  14951. };
  14952. this.setViewport = function ( x, y, width, height ) {
  14953. state.viewport( _viewport.set( x, y, width, height ) );
  14954. };
  14955. this.setScissor = function ( x, y, width, height ) {
  14956. state.scissor( _scissor.set( x, y, width, height ) );
  14957. };
  14958. this.setScissorTest = function ( boolean ) {
  14959. state.setScissorTest( _scissorTest = boolean );
  14960. };
  14961. // Clearing
  14962. this.getClearColor = function () {
  14963. return _clearColor;
  14964. };
  14965. this.setClearColor = function ( color, alpha ) {
  14966. _clearColor.set( color );
  14967. _clearAlpha = alpha !== undefined ? alpha : 1;
  14968. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  14969. };
  14970. this.getClearAlpha = function () {
  14971. return _clearAlpha;
  14972. };
  14973. this.setClearAlpha = function ( alpha ) {
  14974. _clearAlpha = alpha;
  14975. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  14976. };
  14977. this.clear = function ( color, depth, stencil ) {
  14978. var bits = 0;
  14979. if ( color === undefined || color ) bits |= _gl.COLOR_BUFFER_BIT;
  14980. if ( depth === undefined || depth ) bits |= _gl.DEPTH_BUFFER_BIT;
  14981. if ( stencil === undefined || stencil ) bits |= _gl.STENCIL_BUFFER_BIT;
  14982. _gl.clear( bits );
  14983. };
  14984. this.clearColor = function () {
  14985. this.clear( true, false, false );
  14986. };
  14987. this.clearDepth = function () {
  14988. this.clear( false, true, false );
  14989. };
  14990. this.clearStencil = function () {
  14991. this.clear( false, false, true );
  14992. };
  14993. this.clearTarget = function ( renderTarget, color, depth, stencil ) {
  14994. this.setRenderTarget( renderTarget );
  14995. this.clear( color, depth, stencil );
  14996. };
  14997. // Reset
  14998. this.resetGLState = resetGLState;
  14999. this.dispose = function() {
  15000. transparentObjects = [];
  15001. transparentObjectsLastIndex = -1;
  15002. opaqueObjects = [];
  15003. opaqueObjectsLastIndex = -1;
  15004. _canvas.removeEventListener( 'webglcontextlost', onContextLost, false );
  15005. };
  15006. // Events
  15007. function onContextLost( event ) {
  15008. event.preventDefault();
  15009. resetGLState();
  15010. setDefaultGLState();
  15011. properties.clear();
  15012. }
  15013. function onMaterialDispose( event ) {
  15014. var material = event.target;
  15015. material.removeEventListener( 'dispose', onMaterialDispose );
  15016. deallocateMaterial( material );
  15017. }
  15018. // Buffer deallocation
  15019. function deallocateMaterial( material ) {
  15020. releaseMaterialProgramReference( material );
  15021. properties.delete( material );
  15022. }
  15023. function releaseMaterialProgramReference( material ) {
  15024. var programInfo = properties.get( material ).program;
  15025. material.program = undefined;
  15026. if ( programInfo !== undefined ) {
  15027. programCache.releaseProgram( programInfo );
  15028. }
  15029. }
  15030. // Buffer rendering
  15031. this.renderBufferImmediate = function ( object, program, material ) {
  15032. state.initAttributes();
  15033. var buffers = properties.get( object );
  15034. if ( object.hasPositions && ! buffers.position ) buffers.position = _gl.createBuffer();
  15035. if ( object.hasNormals && ! buffers.normal ) buffers.normal = _gl.createBuffer();
  15036. if ( object.hasUvs && ! buffers.uv ) buffers.uv = _gl.createBuffer();
  15037. if ( object.hasColors && ! buffers.color ) buffers.color = _gl.createBuffer();
  15038. var attributes = program.getAttributes();
  15039. if ( object.hasPositions ) {
  15040. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.position );
  15041. _gl.bufferData( _gl.ARRAY_BUFFER, object.positionArray, _gl.DYNAMIC_DRAW );
  15042. state.enableAttribute( attributes.position );
  15043. _gl.vertexAttribPointer( attributes.position, 3, _gl.FLOAT, false, 0, 0 );
  15044. }
  15045. if ( object.hasNormals ) {
  15046. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.normal );
  15047. if ( material.type !== 'MeshPhongMaterial' && material.type !== 'MeshStandardMaterial' && material.type !== 'MeshPhysicalMaterial' && material.shading === THREE.FlatShading ) {
  15048. for ( var i = 0, l = object.count * 3; i < l; i += 9 ) {
  15049. var array = object.normalArray;
  15050. var nx = ( array[ i + 0 ] + array[ i + 3 ] + array[ i + 6 ] ) / 3;
  15051. var ny = ( array[ i + 1 ] + array[ i + 4 ] + array[ i + 7 ] ) / 3;
  15052. var nz = ( array[ i + 2 ] + array[ i + 5 ] + array[ i + 8 ] ) / 3;
  15053. array[ i + 0 ] = nx;
  15054. array[ i + 1 ] = ny;
  15055. array[ i + 2 ] = nz;
  15056. array[ i + 3 ] = nx;
  15057. array[ i + 4 ] = ny;
  15058. array[ i + 5 ] = nz;
  15059. array[ i + 6 ] = nx;
  15060. array[ i + 7 ] = ny;
  15061. array[ i + 8 ] = nz;
  15062. }
  15063. }
  15064. _gl.bufferData( _gl.ARRAY_BUFFER, object.normalArray, _gl.DYNAMIC_DRAW );
  15065. state.enableAttribute( attributes.normal );
  15066. _gl.vertexAttribPointer( attributes.normal, 3, _gl.FLOAT, false, 0, 0 );
  15067. }
  15068. if ( object.hasUvs && material.map ) {
  15069. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.uv );
  15070. _gl.bufferData( _gl.ARRAY_BUFFER, object.uvArray, _gl.DYNAMIC_DRAW );
  15071. state.enableAttribute( attributes.uv );
  15072. _gl.vertexAttribPointer( attributes.uv, 2, _gl.FLOAT, false, 0, 0 );
  15073. }
  15074. if ( object.hasColors && material.vertexColors !== THREE.NoColors ) {
  15075. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.color );
  15076. _gl.bufferData( _gl.ARRAY_BUFFER, object.colorArray, _gl.DYNAMIC_DRAW );
  15077. state.enableAttribute( attributes.color );
  15078. _gl.vertexAttribPointer( attributes.color, 3, _gl.FLOAT, false, 0, 0 );
  15079. }
  15080. state.disableUnusedAttributes();
  15081. _gl.drawArrays( _gl.TRIANGLES, 0, object.count );
  15082. object.count = 0;
  15083. };
  15084. this.renderBufferDirect = function ( camera, fog, geometry, material, object, group ) {
  15085. setMaterial( material );
  15086. var program = setProgram( camera, fog, material, object );
  15087. var updateBuffers = false;
  15088. var geometryProgram = geometry.id + '_' + program.id + '_' + material.wireframe;
  15089. if ( geometryProgram !== _currentGeometryProgram ) {
  15090. _currentGeometryProgram = geometryProgram;
  15091. updateBuffers = true;
  15092. }
  15093. // morph targets
  15094. var morphTargetInfluences = object.morphTargetInfluences;
  15095. if ( morphTargetInfluences !== undefined ) {
  15096. var activeInfluences = [];
  15097. for ( var i = 0, l = morphTargetInfluences.length; i < l; i ++ ) {
  15098. var influence = morphTargetInfluences[ i ];
  15099. activeInfluences.push( [ influence, i ] );
  15100. }
  15101. activeInfluences.sort( absNumericalSort );
  15102. if ( activeInfluences.length > 8 ) {
  15103. activeInfluences.length = 8;
  15104. }
  15105. var morphAttributes = geometry.morphAttributes;
  15106. for ( var i = 0, l = activeInfluences.length; i < l; i ++ ) {
  15107. var influence = activeInfluences[ i ];
  15108. morphInfluences[ i ] = influence[ 0 ];
  15109. if ( influence[ 0 ] !== 0 ) {
  15110. var index = influence[ 1 ];
  15111. if ( material.morphTargets === true && morphAttributes.position ) geometry.addAttribute( 'morphTarget' + i, morphAttributes.position[ index ] );
  15112. if ( material.morphNormals === true && morphAttributes.normal ) geometry.addAttribute( 'morphNormal' + i, morphAttributes.normal[ index ] );
  15113. } else {
  15114. if ( material.morphTargets === true ) geometry.removeAttribute( 'morphTarget' + i );
  15115. if ( material.morphNormals === true ) geometry.removeAttribute( 'morphNormal' + i );
  15116. }
  15117. }
  15118. program.getUniforms().setValue(
  15119. _gl, 'morphTargetInfluences', morphInfluences );
  15120. updateBuffers = true;
  15121. }
  15122. //
  15123. var index = geometry.index;
  15124. var position = geometry.attributes.position;
  15125. if ( material.wireframe === true ) {
  15126. index = objects.getWireframeAttribute( geometry );
  15127. }
  15128. var renderer;
  15129. if ( index !== null ) {
  15130. renderer = indexedBufferRenderer;
  15131. renderer.setIndex( index );
  15132. } else {
  15133. renderer = bufferRenderer;
  15134. }
  15135. if ( updateBuffers ) {
  15136. setupVertexAttributes( material, program, geometry );
  15137. if ( index !== null ) {
  15138. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, objects.getAttributeBuffer( index ) );
  15139. }
  15140. }
  15141. //
  15142. var dataStart = 0;
  15143. var dataCount = Infinity;
  15144. if ( index !== null ) {
  15145. dataCount = index.count;
  15146. } else if ( position !== undefined ) {
  15147. dataCount = position.count;
  15148. }
  15149. var rangeStart = geometry.drawRange.start;
  15150. var rangeCount = geometry.drawRange.count;
  15151. var groupStart = group !== null ? group.start : 0;
  15152. var groupCount = group !== null ? group.count : Infinity;
  15153. var drawStart = Math.max( dataStart, rangeStart, groupStart );
  15154. var drawEnd = Math.min( dataStart + dataCount, rangeStart + rangeCount, groupStart + groupCount ) - 1;
  15155. var drawCount = Math.max( 0, drawEnd - drawStart + 1 );
  15156. //
  15157. if ( object instanceof THREE.Mesh ) {
  15158. if ( material.wireframe === true ) {
  15159. state.setLineWidth( material.wireframeLinewidth * getTargetPixelRatio() );
  15160. renderer.setMode( _gl.LINES );
  15161. } else {
  15162. switch ( object.drawMode ) {
  15163. case THREE.TrianglesDrawMode:
  15164. renderer.setMode( _gl.TRIANGLES );
  15165. break;
  15166. case THREE.TriangleStripDrawMode:
  15167. renderer.setMode( _gl.TRIANGLE_STRIP );
  15168. break;
  15169. case THREE.TriangleFanDrawMode:
  15170. renderer.setMode( _gl.TRIANGLE_FAN );
  15171. break;
  15172. }
  15173. }
  15174. } else if ( object instanceof THREE.Line ) {
  15175. var lineWidth = material.linewidth;
  15176. if ( lineWidth === undefined ) lineWidth = 1; // Not using Line*Material
  15177. state.setLineWidth( lineWidth * getTargetPixelRatio() );
  15178. if ( object instanceof THREE.LineSegments ) {
  15179. renderer.setMode( _gl.LINES );
  15180. } else {
  15181. renderer.setMode( _gl.LINE_STRIP );
  15182. }
  15183. } else if ( object instanceof THREE.Points ) {
  15184. renderer.setMode( _gl.POINTS );
  15185. }
  15186. if ( geometry instanceof THREE.InstancedBufferGeometry ) {
  15187. if ( geometry.maxInstancedCount > 0 ) {
  15188. renderer.renderInstances( geometry, drawStart, drawCount );
  15189. }
  15190. } else {
  15191. renderer.render( drawStart, drawCount );
  15192. }
  15193. };
  15194. function setupVertexAttributes( material, program, geometry, startIndex ) {
  15195. var extension;
  15196. if ( geometry instanceof THREE.InstancedBufferGeometry ) {
  15197. extension = extensions.get( 'ANGLE_instanced_arrays' );
  15198. if ( extension === null ) {
  15199. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  15200. return;
  15201. }
  15202. }
  15203. if ( startIndex === undefined ) startIndex = 0;
  15204. state.initAttributes();
  15205. var geometryAttributes = geometry.attributes;
  15206. var programAttributes = program.getAttributes();
  15207. var materialDefaultAttributeValues = material.defaultAttributeValues;
  15208. for ( var name in programAttributes ) {
  15209. var programAttribute = programAttributes[ name ];
  15210. if ( programAttribute >= 0 ) {
  15211. var geometryAttribute = geometryAttributes[ name ];
  15212. if ( geometryAttribute !== undefined ) {
  15213. var type = _gl.FLOAT;
  15214. var array = geometryAttribute.array;
  15215. var normalized = geometryAttribute.normalized;
  15216. if ( array instanceof Float32Array ) {
  15217. type = _gl.FLOAT;
  15218. } else if ( array instanceof Float64Array ) {
  15219. console.warn("Unsupported data buffer format: Float64Array");
  15220. } else if ( array instanceof Uint16Array ) {
  15221. type = _gl.UNSIGNED_SHORT;
  15222. } else if ( array instanceof Int16Array ) {
  15223. type = _gl.SHORT;
  15224. } else if ( array instanceof Uint32Array ) {
  15225. type = _gl.UNSIGNED_INT;
  15226. } else if ( array instanceof Int32Array ) {
  15227. type = _gl.INT;
  15228. } else if ( array instanceof Int8Array ) {
  15229. type = _gl.BYTE;
  15230. } else if ( array instanceof Uint8Array ) {
  15231. type = _gl.UNSIGNED_BYTE;
  15232. }
  15233. var size = geometryAttribute.itemSize;
  15234. var buffer = objects.getAttributeBuffer( geometryAttribute );
  15235. if ( geometryAttribute instanceof THREE.InterleavedBufferAttribute ) {
  15236. var data = geometryAttribute.data;
  15237. var stride = data.stride;
  15238. var offset = geometryAttribute.offset;
  15239. if ( data instanceof THREE.InstancedInterleavedBuffer ) {
  15240. state.enableAttributeAndDivisor( programAttribute, data.meshPerAttribute, extension );
  15241. if ( geometry.maxInstancedCount === undefined ) {
  15242. geometry.maxInstancedCount = data.meshPerAttribute * data.count;
  15243. }
  15244. } else {
  15245. state.enableAttribute( programAttribute );
  15246. }
  15247. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  15248. _gl.vertexAttribPointer( programAttribute, size, type, normalized, stride * data.array.BYTES_PER_ELEMENT, ( startIndex * stride + offset ) * data.array.BYTES_PER_ELEMENT );
  15249. } else {
  15250. if ( geometryAttribute instanceof THREE.InstancedBufferAttribute ) {
  15251. state.enableAttributeAndDivisor( programAttribute, geometryAttribute.meshPerAttribute, extension );
  15252. if ( geometry.maxInstancedCount === undefined ) {
  15253. geometry.maxInstancedCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  15254. }
  15255. } else {
  15256. state.enableAttribute( programAttribute );
  15257. }
  15258. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  15259. _gl.vertexAttribPointer( programAttribute, size, type, normalized, 0, startIndex * size * geometryAttribute.array.BYTES_PER_ELEMENT );
  15260. }
  15261. } else if ( materialDefaultAttributeValues !== undefined ) {
  15262. var value = materialDefaultAttributeValues[ name ];
  15263. if ( value !== undefined ) {
  15264. switch ( value.length ) {
  15265. case 2:
  15266. _gl.vertexAttrib2fv( programAttribute, value );
  15267. break;
  15268. case 3:
  15269. _gl.vertexAttrib3fv( programAttribute, value );
  15270. break;
  15271. case 4:
  15272. _gl.vertexAttrib4fv( programAttribute, value );
  15273. break;
  15274. default:
  15275. _gl.vertexAttrib1fv( programAttribute, value );
  15276. }
  15277. }
  15278. }
  15279. }
  15280. }
  15281. state.disableUnusedAttributes();
  15282. }
  15283. // Sorting
  15284. function absNumericalSort( a, b ) {
  15285. return Math.abs( b[ 0 ] ) - Math.abs( a[ 0 ] );
  15286. }
  15287. function painterSortStable ( a, b ) {
  15288. if ( a.object.renderOrder !== b.object.renderOrder ) {
  15289. return a.object.renderOrder - b.object.renderOrder;
  15290. } else if ( a.material.program && b.material.program && a.material.program !== b.material.program ) {
  15291. return a.material.program.id - b.material.program.id;
  15292. } else if ( a.material.id !== b.material.id ) {
  15293. return a.material.id - b.material.id;
  15294. } else if ( a.z !== b.z ) {
  15295. return a.z - b.z;
  15296. } else {
  15297. return a.id - b.id;
  15298. }
  15299. }
  15300. function reversePainterSortStable ( a, b ) {
  15301. if ( a.object.renderOrder !== b.object.renderOrder ) {
  15302. return a.object.renderOrder - b.object.renderOrder;
  15303. } if ( a.z !== b.z ) {
  15304. return b.z - a.z;
  15305. } else {
  15306. return a.id - b.id;
  15307. }
  15308. }
  15309. // Rendering
  15310. this.render = function ( scene, camera, renderTarget, forceClear ) {
  15311. if ( camera instanceof THREE.Camera === false ) {
  15312. console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
  15313. return;
  15314. }
  15315. var fog = scene.fog;
  15316. // reset caching for this frame
  15317. _currentGeometryProgram = '';
  15318. _currentMaterialId = - 1;
  15319. _currentCamera = null;
  15320. // update scene graph
  15321. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  15322. // update camera matrices and frustum
  15323. if ( camera.parent === null ) camera.updateMatrixWorld();
  15324. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  15325. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  15326. _frustum.setFromMatrix( _projScreenMatrix );
  15327. lights.length = 0;
  15328. opaqueObjectsLastIndex = - 1;
  15329. transparentObjectsLastIndex = - 1;
  15330. sprites.length = 0;
  15331. lensFlares.length = 0;
  15332. _localClippingEnabled = this.localClippingEnabled;
  15333. _clippingEnabled = _clipping.init( this.clippingPlanes, _localClippingEnabled, camera );
  15334. projectObject( scene, camera );
  15335. opaqueObjects.length = opaqueObjectsLastIndex + 1;
  15336. transparentObjects.length = transparentObjectsLastIndex + 1;
  15337. if ( _this.sortObjects === true ) {
  15338. opaqueObjects.sort( painterSortStable );
  15339. transparentObjects.sort( reversePainterSortStable );
  15340. }
  15341. //
  15342. if ( _clippingEnabled ) _clipping.beginShadows();
  15343. setupShadows( lights );
  15344. shadowMap.render( scene, camera );
  15345. setupLights( lights, camera );
  15346. if ( _clippingEnabled ) _clipping.endShadows();
  15347. //
  15348. _infoRender.calls = 0;
  15349. _infoRender.vertices = 0;
  15350. _infoRender.faces = 0;
  15351. _infoRender.points = 0;
  15352. if ( renderTarget === undefined ) {
  15353. renderTarget = null;
  15354. }
  15355. this.setRenderTarget( renderTarget );
  15356. //
  15357. var background = scene.background;
  15358. if ( background === null ) {
  15359. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  15360. } else if ( background instanceof THREE.Color ) {
  15361. glClearColor( background.r, background.g, background.b, 1 );
  15362. }
  15363. if ( this.autoClear || forceClear ) {
  15364. this.clear( this.autoClearColor, this.autoClearDepth, this.autoClearStencil );
  15365. }
  15366. if ( background instanceof THREE.CubeTexture ) {
  15367. backgroundCamera2.projectionMatrix.copy( camera.projectionMatrix );
  15368. backgroundCamera2.matrixWorld.extractRotation( camera.matrixWorld );
  15369. backgroundCamera2.matrixWorldInverse.getInverse( backgroundCamera2.matrixWorld );
  15370. backgroundBoxMesh.material.uniforms[ "tCube" ].value = background;
  15371. backgroundBoxMesh.modelViewMatrix.multiplyMatrices( backgroundCamera2.matrixWorldInverse, backgroundBoxMesh.matrixWorld );
  15372. objects.update( backgroundBoxMesh );
  15373. _this.renderBufferDirect( backgroundCamera2, null, backgroundBoxMesh.geometry, backgroundBoxMesh.material, backgroundBoxMesh, null );
  15374. } else if ( background instanceof THREE.Texture ) {
  15375. backgroundPlaneMesh.material.map = background;
  15376. objects.update( backgroundPlaneMesh );
  15377. _this.renderBufferDirect( backgroundCamera, null, backgroundPlaneMesh.geometry, backgroundPlaneMesh.material, backgroundPlaneMesh, null );
  15378. }
  15379. //
  15380. if ( scene.overrideMaterial ) {
  15381. var overrideMaterial = scene.overrideMaterial;
  15382. renderObjects( opaqueObjects, camera, fog, overrideMaterial );
  15383. renderObjects( transparentObjects, camera, fog, overrideMaterial );
  15384. } else {
  15385. // opaque pass (front-to-back order)
  15386. state.setBlending( THREE.NoBlending );
  15387. renderObjects( opaqueObjects, camera, fog );
  15388. // transparent pass (back-to-front order)
  15389. renderObjects( transparentObjects, camera, fog );
  15390. }
  15391. // custom render plugins (post pass)
  15392. spritePlugin.render( scene, camera );
  15393. lensFlarePlugin.render( scene, camera, _currentViewport );
  15394. // Generate mipmap if we're using any kind of mipmap filtering
  15395. if ( renderTarget ) {
  15396. textures.updateRenderTargetMipmap( renderTarget );
  15397. }
  15398. // Ensure depth buffer writing is enabled so it can be cleared on next render
  15399. state.setDepthTest( true );
  15400. state.setDepthWrite( true );
  15401. state.setColorWrite( true );
  15402. // _gl.finish();
  15403. };
  15404. function pushRenderItem( object, geometry, material, z, group ) {
  15405. var array, index;
  15406. // allocate the next position in the appropriate array
  15407. if ( material.transparent ) {
  15408. array = transparentObjects;
  15409. index = ++ transparentObjectsLastIndex;
  15410. } else {
  15411. array = opaqueObjects;
  15412. index = ++ opaqueObjectsLastIndex;
  15413. }
  15414. // recycle existing render item or grow the array
  15415. var renderItem = array[ index ];
  15416. if ( renderItem !== undefined ) {
  15417. renderItem.id = object.id;
  15418. renderItem.object = object;
  15419. renderItem.geometry = geometry;
  15420. renderItem.material = material;
  15421. renderItem.z = _vector3.z;
  15422. renderItem.group = group;
  15423. } else {
  15424. renderItem = {
  15425. id: object.id,
  15426. object: object,
  15427. geometry: geometry,
  15428. material: material,
  15429. z: _vector3.z,
  15430. group: group
  15431. };
  15432. // assert( index === array.length );
  15433. array.push( renderItem );
  15434. }
  15435. }
  15436. // TODO Duplicated code (Frustum)
  15437. function isObjectViewable( object ) {
  15438. var geometry = object.geometry;
  15439. if ( geometry.boundingSphere === null )
  15440. geometry.computeBoundingSphere();
  15441. _sphere.copy( geometry.boundingSphere ).
  15442. applyMatrix4( object.matrixWorld );
  15443. return isSphereViewable( _sphere );
  15444. }
  15445. function isSpriteViewable( sprite ) {
  15446. _sphere.center.set( 0, 0, 0 );
  15447. _sphere.radius = 0.7071067811865476;
  15448. _sphere.applyMatrix4( sprite.matrixWorld );
  15449. return isSphereViewable( _sphere );
  15450. }
  15451. function isSphereViewable( sphere ) {
  15452. if ( ! _frustum.intersectsSphere( sphere ) ) return false;
  15453. var numPlanes = _clipping.numPlanes;
  15454. if ( numPlanes === 0 ) return true;
  15455. var planes = _this.clippingPlanes,
  15456. center = sphere.center,
  15457. negRad = - sphere.radius,
  15458. i = 0;
  15459. do {
  15460. // out when deeper than radius in the negative halfspace
  15461. if ( planes[ i ].distanceToPoint( center ) < negRad ) return false;
  15462. } while ( ++ i !== numPlanes );
  15463. return true;
  15464. }
  15465. function projectObject( object, camera ) {
  15466. if ( object.visible === false ) return;
  15467. if ( object.layers.test( camera.layers ) ) {
  15468. if ( object instanceof THREE.Light ) {
  15469. lights.push( object );
  15470. } else if ( object instanceof THREE.Sprite ) {
  15471. if ( object.frustumCulled === false || isSpriteViewable( object ) === true ) {
  15472. sprites.push( object );
  15473. }
  15474. } else if ( object instanceof THREE.LensFlare ) {
  15475. lensFlares.push( object );
  15476. } else if ( object instanceof THREE.ImmediateRenderObject ) {
  15477. if ( _this.sortObjects === true ) {
  15478. _vector3.setFromMatrixPosition( object.matrixWorld );
  15479. _vector3.applyProjection( _projScreenMatrix );
  15480. }
  15481. pushRenderItem( object, null, object.material, _vector3.z, null );
  15482. } else if ( object instanceof THREE.Mesh || object instanceof THREE.Line || object instanceof THREE.Points ) {
  15483. if ( object instanceof THREE.SkinnedMesh ) {
  15484. object.skeleton.update();
  15485. }
  15486. if ( object.frustumCulled === false || isObjectViewable( object ) === true ) {
  15487. var material = object.material;
  15488. if ( material.visible === true ) {
  15489. if ( _this.sortObjects === true ) {
  15490. _vector3.setFromMatrixPosition( object.matrixWorld );
  15491. _vector3.applyProjection( _projScreenMatrix );
  15492. }
  15493. var geometry = objects.update( object );
  15494. if ( material instanceof THREE.MultiMaterial ) {
  15495. var groups = geometry.groups;
  15496. var materials = material.materials;
  15497. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  15498. var group = groups[ i ];
  15499. var groupMaterial = materials[ group.materialIndex ];
  15500. if ( groupMaterial.visible === true ) {
  15501. pushRenderItem( object, geometry, groupMaterial, _vector3.z, group );
  15502. }
  15503. }
  15504. } else {
  15505. pushRenderItem( object, geometry, material, _vector3.z, null );
  15506. }
  15507. }
  15508. }
  15509. }
  15510. }
  15511. var children = object.children;
  15512. for ( var i = 0, l = children.length; i < l; i ++ ) {
  15513. projectObject( children[ i ], camera );
  15514. }
  15515. }
  15516. function renderObjects( renderList, camera, fog, overrideMaterial ) {
  15517. for ( var i = 0, l = renderList.length; i < l; i ++ ) {
  15518. var renderItem = renderList[ i ];
  15519. var object = renderItem.object;
  15520. var geometry = renderItem.geometry;
  15521. var material = overrideMaterial === undefined ? renderItem.material : overrideMaterial;
  15522. var group = renderItem.group;
  15523. object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  15524. object.normalMatrix.getNormalMatrix( object.modelViewMatrix );
  15525. if ( object instanceof THREE.ImmediateRenderObject ) {
  15526. setMaterial( material );
  15527. var program = setProgram( camera, fog, material, object );
  15528. _currentGeometryProgram = '';
  15529. object.render( function ( object ) {
  15530. _this.renderBufferImmediate( object, program, material );
  15531. } );
  15532. } else {
  15533. _this.renderBufferDirect( camera, fog, geometry, material, object, group );
  15534. }
  15535. }
  15536. }
  15537. function initMaterial( material, fog, object ) {
  15538. var materialProperties = properties.get( material );
  15539. var parameters = programCache.getParameters(
  15540. material, _lights, fog, _clipping.numPlanes, object );
  15541. var code = programCache.getProgramCode( material, parameters );
  15542. var program = materialProperties.program;
  15543. var programChange = true;
  15544. if ( program === undefined ) {
  15545. // new material
  15546. material.addEventListener( 'dispose', onMaterialDispose );
  15547. } else if ( program.code !== code ) {
  15548. // changed glsl or parameters
  15549. releaseMaterialProgramReference( material );
  15550. } else if ( parameters.shaderID !== undefined ) {
  15551. // same glsl and uniform list
  15552. return;
  15553. } else {
  15554. // only rebuild uniform list
  15555. programChange = false;
  15556. }
  15557. if ( programChange ) {
  15558. if ( parameters.shaderID ) {
  15559. var shader = THREE.ShaderLib[ parameters.shaderID ];
  15560. materialProperties.__webglShader = {
  15561. name: material.type,
  15562. uniforms: THREE.UniformsUtils.clone( shader.uniforms ),
  15563. vertexShader: shader.vertexShader,
  15564. fragmentShader: shader.fragmentShader
  15565. };
  15566. } else {
  15567. materialProperties.__webglShader = {
  15568. name: material.type,
  15569. uniforms: material.uniforms,
  15570. vertexShader: material.vertexShader,
  15571. fragmentShader: material.fragmentShader
  15572. };
  15573. }
  15574. material.__webglShader = materialProperties.__webglShader;
  15575. program = programCache.acquireProgram( material, parameters, code );
  15576. materialProperties.program = program;
  15577. material.program = program;
  15578. }
  15579. var attributes = program.getAttributes();
  15580. if ( material.morphTargets ) {
  15581. material.numSupportedMorphTargets = 0;
  15582. for ( var i = 0; i < _this.maxMorphTargets; i ++ ) {
  15583. if ( attributes[ 'morphTarget' + i ] >= 0 ) {
  15584. material.numSupportedMorphTargets ++;
  15585. }
  15586. }
  15587. }
  15588. if ( material.morphNormals ) {
  15589. material.numSupportedMorphNormals = 0;
  15590. for ( var i = 0; i < _this.maxMorphNormals; i ++ ) {
  15591. if ( attributes[ 'morphNormal' + i ] >= 0 ) {
  15592. material.numSupportedMorphNormals ++;
  15593. }
  15594. }
  15595. }
  15596. var uniforms = materialProperties.__webglShader.uniforms;
  15597. if ( ! ( material instanceof THREE.ShaderMaterial ) &&
  15598. ! ( material instanceof THREE.RawShaderMaterial ) ||
  15599. material.clipping === true ) {
  15600. materialProperties.numClippingPlanes = _clipping.numPlanes;
  15601. uniforms.clippingPlanes = _clipping.uniform;
  15602. }
  15603. if ( material.lights ) {
  15604. // store the light setup it was created for
  15605. materialProperties.lightsHash = _lights.hash;
  15606. // wire up the material to this renderer's lighting state
  15607. uniforms.ambientLightColor.value = _lights.ambient;
  15608. uniforms.directionalLights.value = _lights.directional;
  15609. uniforms.spotLights.value = _lights.spot;
  15610. uniforms.pointLights.value = _lights.point;
  15611. uniforms.hemisphereLights.value = _lights.hemi;
  15612. uniforms.directionalShadowMap.value = _lights.directionalShadowMap;
  15613. uniforms.directionalShadowMatrix.value = _lights.directionalShadowMatrix;
  15614. uniforms.spotShadowMap.value = _lights.spotShadowMap;
  15615. uniforms.spotShadowMatrix.value = _lights.spotShadowMatrix;
  15616. uniforms.pointShadowMap.value = _lights.pointShadowMap;
  15617. uniforms.pointShadowMatrix.value = _lights.pointShadowMatrix;
  15618. }
  15619. var progUniforms = materialProperties.program.getUniforms(),
  15620. uniformsList =
  15621. THREE.WebGLUniforms.seqWithValue( progUniforms.seq, uniforms );
  15622. materialProperties.uniformsList = uniformsList;
  15623. materialProperties.dynamicUniforms =
  15624. THREE.WebGLUniforms.splitDynamic( uniformsList, uniforms );
  15625. }
  15626. function setMaterial( material ) {
  15627. if ( material.side !== THREE.DoubleSide )
  15628. state.enable( _gl.CULL_FACE );
  15629. else
  15630. state.disable( _gl.CULL_FACE );
  15631. state.setFlipSided( material.side === THREE.BackSide );
  15632. if ( material.transparent === true ) {
  15633. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.premultipliedAlpha );
  15634. } else {
  15635. state.setBlending( THREE.NoBlending );
  15636. }
  15637. state.setDepthFunc( material.depthFunc );
  15638. state.setDepthTest( material.depthTest );
  15639. state.setDepthWrite( material.depthWrite );
  15640. state.setColorWrite( material.colorWrite );
  15641. state.setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  15642. }
  15643. function setProgram( camera, fog, material, object ) {
  15644. _usedTextureUnits = 0;
  15645. var materialProperties = properties.get( material );
  15646. if ( _clippingEnabled ) {
  15647. if ( _localClippingEnabled || camera !== _currentCamera ) {
  15648. var useCache =
  15649. camera === _currentCamera &&
  15650. material.id === _currentMaterialId;
  15651. // we might want to call this function with some ClippingGroup
  15652. // object instead of the material, once it becomes feasible
  15653. // (#8465, #8379)
  15654. _clipping.setState(
  15655. material.clippingPlanes, material.clipShadows,
  15656. camera, materialProperties, useCache );
  15657. }
  15658. if ( materialProperties.numClippingPlanes !== undefined &&
  15659. materialProperties.numClippingPlanes !== _clipping.numPlanes ) {
  15660. material.needsUpdate = true;
  15661. }
  15662. }
  15663. if ( materialProperties.program === undefined ) {
  15664. material.needsUpdate = true;
  15665. }
  15666. if ( materialProperties.lightsHash !== undefined &&
  15667. materialProperties.lightsHash !== _lights.hash ) {
  15668. material.needsUpdate = true;
  15669. }
  15670. if ( material.needsUpdate ) {
  15671. initMaterial( material, fog, object );
  15672. material.needsUpdate = false;
  15673. }
  15674. var refreshProgram = false;
  15675. var refreshMaterial = false;
  15676. var refreshLights = false;
  15677. var program = materialProperties.program,
  15678. p_uniforms = program.getUniforms(),
  15679. m_uniforms = materialProperties.__webglShader.uniforms;
  15680. if ( program.id !== _currentProgram ) {
  15681. _gl.useProgram( program.program );
  15682. _currentProgram = program.id;
  15683. refreshProgram = true;
  15684. refreshMaterial = true;
  15685. refreshLights = true;
  15686. }
  15687. if ( material.id !== _currentMaterialId ) {
  15688. _currentMaterialId = material.id;
  15689. refreshMaterial = true;
  15690. }
  15691. if ( refreshProgram || camera !== _currentCamera ) {
  15692. p_uniforms.set( _gl, camera, 'projectionMatrix' );
  15693. if ( capabilities.logarithmicDepthBuffer ) {
  15694. p_uniforms.setValue( _gl, 'logDepthBufFC',
  15695. 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
  15696. }
  15697. if ( camera !== _currentCamera ) {
  15698. _currentCamera = camera;
  15699. // lighting uniforms depend on the camera so enforce an update
  15700. // now, in case this material supports lights - or later, when
  15701. // the next material that does gets activated:
  15702. refreshMaterial = true; // set to true on material change
  15703. refreshLights = true; // remains set until update done
  15704. }
  15705. // load material specific uniforms
  15706. // (shader material also gets them for the sake of genericity)
  15707. if ( material instanceof THREE.ShaderMaterial ||
  15708. material instanceof THREE.MeshPhongMaterial ||
  15709. material instanceof THREE.MeshStandardMaterial ||
  15710. material.envMap ) {
  15711. var uCamPos = p_uniforms.map.cameraPosition;
  15712. if ( uCamPos !== undefined ) {
  15713. uCamPos.setValue( _gl,
  15714. _vector3.setFromMatrixPosition( camera.matrixWorld ) );
  15715. }
  15716. }
  15717. if ( material instanceof THREE.MeshPhongMaterial ||
  15718. material instanceof THREE.MeshLambertMaterial ||
  15719. material instanceof THREE.MeshBasicMaterial ||
  15720. material instanceof THREE.MeshStandardMaterial ||
  15721. material instanceof THREE.ShaderMaterial ||
  15722. material.skinning ) {
  15723. p_uniforms.setValue( _gl, 'viewMatrix', camera.matrixWorldInverse );
  15724. }
  15725. p_uniforms.set( _gl, _this, 'toneMappingExposure' );
  15726. p_uniforms.set( _gl, _this, 'toneMappingWhitePoint' );
  15727. }
  15728. // skinning uniforms must be set even if material didn't change
  15729. // auto-setting of texture unit for bone texture must go before other textures
  15730. // not sure why, but otherwise weird things happen
  15731. if ( material.skinning ) {
  15732. p_uniforms.setOptional( _gl, object, 'bindMatrix' );
  15733. p_uniforms.setOptional( _gl, object, 'bindMatrixInverse' );
  15734. var skeleton = object.skeleton;
  15735. if ( skeleton ) {
  15736. if ( capabilities.floatVertexTextures && skeleton.useVertexTexture ) {
  15737. p_uniforms.set( _gl, skeleton, 'boneTexture' );
  15738. p_uniforms.set( _gl, skeleton, 'boneTextureWidth' );
  15739. p_uniforms.set( _gl, skeleton, 'boneTextureHeight' );
  15740. } else {
  15741. p_uniforms.setOptional( _gl, skeleton, 'boneMatrices' );
  15742. }
  15743. }
  15744. }
  15745. if ( refreshMaterial ) {
  15746. if ( material.lights ) {
  15747. // the current material requires lighting info
  15748. // note: all lighting uniforms are always set correctly
  15749. // they simply reference the renderer's state for their
  15750. // values
  15751. //
  15752. // use the current material's .needsUpdate flags to set
  15753. // the GL state when required
  15754. markUniformsLightsNeedsUpdate( m_uniforms, refreshLights );
  15755. }
  15756. // refresh uniforms common to several materials
  15757. if ( fog && material.fog ) {
  15758. refreshUniformsFog( m_uniforms, fog );
  15759. }
  15760. if ( material instanceof THREE.MeshBasicMaterial ||
  15761. material instanceof THREE.MeshLambertMaterial ||
  15762. material instanceof THREE.MeshPhongMaterial ||
  15763. material instanceof THREE.MeshStandardMaterial ||
  15764. material instanceof THREE.MeshDepthMaterial ) {
  15765. refreshUniformsCommon( m_uniforms, material );
  15766. }
  15767. // refresh single material specific uniforms
  15768. if ( material instanceof THREE.LineBasicMaterial ) {
  15769. refreshUniformsLine( m_uniforms, material );
  15770. } else if ( material instanceof THREE.LineDashedMaterial ) {
  15771. refreshUniformsLine( m_uniforms, material );
  15772. refreshUniformsDash( m_uniforms, material );
  15773. } else if ( material instanceof THREE.PointsMaterial ) {
  15774. refreshUniformsPoints( m_uniforms, material );
  15775. } else if ( material instanceof THREE.MeshLambertMaterial ) {
  15776. refreshUniformsLambert( m_uniforms, material );
  15777. } else if ( material instanceof THREE.MeshPhongMaterial ) {
  15778. refreshUniformsPhong( m_uniforms, material );
  15779. } else if ( material instanceof THREE.MeshPhysicalMaterial ) {
  15780. refreshUniformsPhysical( m_uniforms, material );
  15781. } else if ( material instanceof THREE.MeshStandardMaterial ) {
  15782. refreshUniformsStandard( m_uniforms, material );
  15783. } else if ( material instanceof THREE.MeshDepthMaterial ) {
  15784. if ( material.displacementMap ) {
  15785. m_uniforms.displacementMap.value = material.displacementMap;
  15786. m_uniforms.displacementScale.value = material.displacementScale;
  15787. m_uniforms.displacementBias.value = material.displacementBias;
  15788. }
  15789. } else if ( material instanceof THREE.MeshNormalMaterial ) {
  15790. m_uniforms.opacity.value = material.opacity;
  15791. }
  15792. THREE.WebGLUniforms.upload(
  15793. _gl, materialProperties.uniformsList, m_uniforms, _this );
  15794. }
  15795. // common matrices
  15796. p_uniforms.set( _gl, object, 'modelViewMatrix' );
  15797. p_uniforms.set( _gl, object, 'normalMatrix' );
  15798. p_uniforms.setValue( _gl, 'modelMatrix', object.matrixWorld );
  15799. // dynamic uniforms
  15800. var dynUniforms = materialProperties.dynamicUniforms;
  15801. if ( dynUniforms !== null ) {
  15802. THREE.WebGLUniforms.evalDynamic(
  15803. dynUniforms, m_uniforms, object, camera );
  15804. THREE.WebGLUniforms.upload( _gl, dynUniforms, m_uniforms, _this );
  15805. }
  15806. return program;
  15807. }
  15808. // Uniforms (refresh uniforms objects)
  15809. function refreshUniformsCommon ( uniforms, material ) {
  15810. uniforms.opacity.value = material.opacity;
  15811. uniforms.diffuse.value = material.color;
  15812. if ( material.emissive ) {
  15813. uniforms.emissive.value.copy( material.emissive ).multiplyScalar( material.emissiveIntensity );
  15814. }
  15815. uniforms.map.value = material.map;
  15816. uniforms.specularMap.value = material.specularMap;
  15817. uniforms.alphaMap.value = material.alphaMap;
  15818. if ( material.aoMap ) {
  15819. uniforms.aoMap.value = material.aoMap;
  15820. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  15821. }
  15822. // uv repeat and offset setting priorities
  15823. // 1. color map
  15824. // 2. specular map
  15825. // 3. normal map
  15826. // 4. bump map
  15827. // 5. alpha map
  15828. // 6. emissive map
  15829. var uvScaleMap;
  15830. if ( material.map ) {
  15831. uvScaleMap = material.map;
  15832. } else if ( material.specularMap ) {
  15833. uvScaleMap = material.specularMap;
  15834. } else if ( material.displacementMap ) {
  15835. uvScaleMap = material.displacementMap;
  15836. } else if ( material.normalMap ) {
  15837. uvScaleMap = material.normalMap;
  15838. } else if ( material.bumpMap ) {
  15839. uvScaleMap = material.bumpMap;
  15840. } else if ( material.roughnessMap ) {
  15841. uvScaleMap = material.roughnessMap;
  15842. } else if ( material.metalnessMap ) {
  15843. uvScaleMap = material.metalnessMap;
  15844. } else if ( material.alphaMap ) {
  15845. uvScaleMap = material.alphaMap;
  15846. } else if ( material.emissiveMap ) {
  15847. uvScaleMap = material.emissiveMap;
  15848. }
  15849. if ( uvScaleMap !== undefined ) {
  15850. // backwards compatibility
  15851. if ( uvScaleMap instanceof THREE.WebGLRenderTarget ) {
  15852. uvScaleMap = uvScaleMap.texture;
  15853. }
  15854. var offset = uvScaleMap.offset;
  15855. var repeat = uvScaleMap.repeat;
  15856. uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
  15857. }
  15858. uniforms.envMap.value = material.envMap;
  15859. // don't flip CubeTexture envMaps, flip everything else:
  15860. // WebGLRenderTargetCube will be flipped for backwards compatibility
  15861. // WebGLRenderTargetCube.texture will be flipped because it's a Texture and NOT a CubeTexture
  15862. // this check must be handled differently, or removed entirely, if WebGLRenderTargetCube uses a CubeTexture in the future
  15863. uniforms.flipEnvMap.value = ( ! ( material.envMap instanceof THREE.CubeTexture ) ) ? 1 : - 1;
  15864. uniforms.reflectivity.value = material.reflectivity;
  15865. uniforms.refractionRatio.value = material.refractionRatio;
  15866. }
  15867. function refreshUniformsLine ( uniforms, material ) {
  15868. uniforms.diffuse.value = material.color;
  15869. uniforms.opacity.value = material.opacity;
  15870. }
  15871. function refreshUniformsDash ( uniforms, material ) {
  15872. uniforms.dashSize.value = material.dashSize;
  15873. uniforms.totalSize.value = material.dashSize + material.gapSize;
  15874. uniforms.scale.value = material.scale;
  15875. }
  15876. function refreshUniformsPoints ( uniforms, material ) {
  15877. uniforms.diffuse.value = material.color;
  15878. uniforms.opacity.value = material.opacity;
  15879. uniforms.size.value = material.size * _pixelRatio;
  15880. uniforms.scale.value = _canvas.clientHeight * 0.5;
  15881. uniforms.map.value = material.map;
  15882. if ( material.map !== null ) {
  15883. var offset = material.map.offset;
  15884. var repeat = material.map.repeat;
  15885. uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
  15886. }
  15887. }
  15888. function refreshUniformsFog ( uniforms, fog ) {
  15889. uniforms.fogColor.value = fog.color;
  15890. if ( fog instanceof THREE.Fog ) {
  15891. uniforms.fogNear.value = fog.near;
  15892. uniforms.fogFar.value = fog.far;
  15893. } else if ( fog instanceof THREE.FogExp2 ) {
  15894. uniforms.fogDensity.value = fog.density;
  15895. }
  15896. }
  15897. function refreshUniformsLambert ( uniforms, material ) {
  15898. if ( material.lightMap ) {
  15899. uniforms.lightMap.value = material.lightMap;
  15900. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  15901. }
  15902. if ( material.emissiveMap ) {
  15903. uniforms.emissiveMap.value = material.emissiveMap;
  15904. }
  15905. }
  15906. function refreshUniformsPhong ( uniforms, material ) {
  15907. uniforms.specular.value = material.specular;
  15908. uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 )
  15909. if ( material.lightMap ) {
  15910. uniforms.lightMap.value = material.lightMap;
  15911. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  15912. }
  15913. if ( material.emissiveMap ) {
  15914. uniforms.emissiveMap.value = material.emissiveMap;
  15915. }
  15916. if ( material.bumpMap ) {
  15917. uniforms.bumpMap.value = material.bumpMap;
  15918. uniforms.bumpScale.value = material.bumpScale;
  15919. }
  15920. if ( material.normalMap ) {
  15921. uniforms.normalMap.value = material.normalMap;
  15922. uniforms.normalScale.value.copy( material.normalScale );
  15923. }
  15924. if ( material.displacementMap ) {
  15925. uniforms.displacementMap.value = material.displacementMap;
  15926. uniforms.displacementScale.value = material.displacementScale;
  15927. uniforms.displacementBias.value = material.displacementBias;
  15928. }
  15929. }
  15930. function refreshUniformsStandard ( uniforms, material ) {
  15931. uniforms.roughness.value = material.roughness;
  15932. uniforms.metalness.value = material.metalness;
  15933. if ( material.roughnessMap ) {
  15934. uniforms.roughnessMap.value = material.roughnessMap;
  15935. }
  15936. if ( material.metalnessMap ) {
  15937. uniforms.metalnessMap.value = material.metalnessMap;
  15938. }
  15939. if ( material.lightMap ) {
  15940. uniforms.lightMap.value = material.lightMap;
  15941. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  15942. }
  15943. if ( material.emissiveMap ) {
  15944. uniforms.emissiveMap.value = material.emissiveMap;
  15945. }
  15946. if ( material.bumpMap ) {
  15947. uniforms.bumpMap.value = material.bumpMap;
  15948. uniforms.bumpScale.value = material.bumpScale;
  15949. }
  15950. if ( material.normalMap ) {
  15951. uniforms.normalMap.value = material.normalMap;
  15952. uniforms.normalScale.value.copy( material.normalScale );
  15953. }
  15954. if ( material.displacementMap ) {
  15955. uniforms.displacementMap.value = material.displacementMap;
  15956. uniforms.displacementScale.value = material.displacementScale;
  15957. uniforms.displacementBias.value = material.displacementBias;
  15958. }
  15959. if ( material.envMap ) {
  15960. //uniforms.envMap.value = material.envMap; // part of uniforms common
  15961. uniforms.envMapIntensity.value = material.envMapIntensity;
  15962. }
  15963. }
  15964. function refreshUniformsPhysical ( uniforms, material ) {
  15965. uniforms.clearCoat.value = material.clearCoat;
  15966. uniforms.clearCoatRoughness.value = material.clearCoatRoughness;
  15967. refreshUniformsStandard( uniforms, material );
  15968. }
  15969. // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  15970. function markUniformsLightsNeedsUpdate ( uniforms, value ) {
  15971. uniforms.ambientLightColor.needsUpdate = value;
  15972. uniforms.directionalLights.needsUpdate = value;
  15973. uniforms.pointLights.needsUpdate = value;
  15974. uniforms.spotLights.needsUpdate = value;
  15975. uniforms.hemisphereLights.needsUpdate = value;
  15976. }
  15977. // Lighting
  15978. function setupShadows ( lights ) {
  15979. var lightShadowsLength = 0;
  15980. for ( var i = 0, l = lights.length; i < l; i ++ ) {
  15981. var light = lights[ i ];
  15982. if ( light.castShadow ) {
  15983. _lights.shadows[ lightShadowsLength ++ ] = light;
  15984. }
  15985. }
  15986. _lights.shadows.length = lightShadowsLength;
  15987. }
  15988. function setupLights ( lights, camera ) {
  15989. var l, ll, light,
  15990. r = 0, g = 0, b = 0,
  15991. color,
  15992. intensity,
  15993. distance,
  15994. shadowMap,
  15995. viewMatrix = camera.matrixWorldInverse,
  15996. directionalLength = 0,
  15997. pointLength = 0,
  15998. spotLength = 0,
  15999. hemiLength = 0;
  16000. for ( l = 0, ll = lights.length; l < ll; l ++ ) {
  16001. light = lights[ l ];
  16002. color = light.color;
  16003. intensity = light.intensity;
  16004. distance = light.distance;
  16005. shadowMap = ( light.shadow && light.shadow.map ) ? light.shadow.map.texture : null;
  16006. if ( light instanceof THREE.AmbientLight ) {
  16007. r += color.r * intensity;
  16008. g += color.g * intensity;
  16009. b += color.b * intensity;
  16010. } else if ( light instanceof THREE.DirectionalLight ) {
  16011. var uniforms = lightCache.get( light );
  16012. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  16013. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  16014. _vector3.setFromMatrixPosition( light.target.matrixWorld );
  16015. uniforms.direction.sub( _vector3 );
  16016. uniforms.direction.transformDirection( viewMatrix );
  16017. uniforms.shadow = light.castShadow;
  16018. if ( light.castShadow ) {
  16019. uniforms.shadowBias = light.shadow.bias;
  16020. uniforms.shadowRadius = light.shadow.radius;
  16021. uniforms.shadowMapSize = light.shadow.mapSize;
  16022. }
  16023. _lights.directionalShadowMap[ directionalLength ] = shadowMap;
  16024. _lights.directionalShadowMatrix[ directionalLength ] = light.shadow.matrix;
  16025. _lights.directional[ directionalLength ++ ] = uniforms;
  16026. } else if ( light instanceof THREE.SpotLight ) {
  16027. var uniforms = lightCache.get( light );
  16028. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  16029. uniforms.position.applyMatrix4( viewMatrix );
  16030. uniforms.color.copy( color ).multiplyScalar( intensity );
  16031. uniforms.distance = distance;
  16032. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  16033. _vector3.setFromMatrixPosition( light.target.matrixWorld );
  16034. uniforms.direction.sub( _vector3 );
  16035. uniforms.direction.transformDirection( viewMatrix );
  16036. uniforms.coneCos = Math.cos( light.angle );
  16037. uniforms.penumbraCos = Math.cos( light.angle * ( 1 - light.penumbra ) );
  16038. uniforms.decay = ( light.distance === 0 ) ? 0.0 : light.decay;
  16039. uniforms.shadow = light.castShadow;
  16040. if ( light.castShadow ) {
  16041. uniforms.shadowBias = light.shadow.bias;
  16042. uniforms.shadowRadius = light.shadow.radius;
  16043. uniforms.shadowMapSize = light.shadow.mapSize;
  16044. }
  16045. _lights.spotShadowMap[ spotLength ] = shadowMap;
  16046. _lights.spotShadowMatrix[ spotLength ] = light.shadow.matrix;
  16047. _lights.spot[ spotLength ++ ] = uniforms;
  16048. } else if ( light instanceof THREE.PointLight ) {
  16049. var uniforms = lightCache.get( light );
  16050. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  16051. uniforms.position.applyMatrix4( viewMatrix );
  16052. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  16053. uniforms.distance = light.distance;
  16054. uniforms.decay = ( light.distance === 0 ) ? 0.0 : light.decay;
  16055. uniforms.shadow = light.castShadow;
  16056. if ( light.castShadow ) {
  16057. uniforms.shadowBias = light.shadow.bias;
  16058. uniforms.shadowRadius = light.shadow.radius;
  16059. uniforms.shadowMapSize = light.shadow.mapSize;
  16060. }
  16061. _lights.pointShadowMap[ pointLength ] = shadowMap;
  16062. if ( _lights.pointShadowMatrix[ pointLength ] === undefined ) {
  16063. _lights.pointShadowMatrix[ pointLength ] = new THREE.Matrix4();
  16064. }
  16065. // for point lights we set the shadow matrix to be a translation-only matrix
  16066. // equal to inverse of the light's position
  16067. _vector3.setFromMatrixPosition( light.matrixWorld ).negate();
  16068. _lights.pointShadowMatrix[ pointLength ].identity().setPosition( _vector3 );
  16069. _lights.point[ pointLength ++ ] = uniforms;
  16070. } else if ( light instanceof THREE.HemisphereLight ) {
  16071. var uniforms = lightCache.get( light );
  16072. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  16073. uniforms.direction.transformDirection( viewMatrix );
  16074. uniforms.direction.normalize();
  16075. uniforms.skyColor.copy( light.color ).multiplyScalar( intensity );
  16076. uniforms.groundColor.copy( light.groundColor ).multiplyScalar( intensity );
  16077. _lights.hemi[ hemiLength ++ ] = uniforms;
  16078. }
  16079. }
  16080. _lights.ambient[ 0 ] = r;
  16081. _lights.ambient[ 1 ] = g;
  16082. _lights.ambient[ 2 ] = b;
  16083. _lights.directional.length = directionalLength;
  16084. _lights.spot.length = spotLength;
  16085. _lights.point.length = pointLength;
  16086. _lights.hemi.length = hemiLength;
  16087. _lights.hash = directionalLength + ',' + pointLength + ',' + spotLength + ',' + hemiLength + ',' + _lights.shadows.length;
  16088. }
  16089. // GL state setting
  16090. this.setFaceCulling = function ( cullFace, frontFaceDirection ) {
  16091. state.setCullFace( cullFace );
  16092. state.setFlipSided( frontFaceDirection === THREE.FrontFaceDirectionCW );
  16093. };
  16094. // Textures
  16095. function allocTextureUnit() {
  16096. var textureUnit = _usedTextureUnits;
  16097. if ( textureUnit >= capabilities.maxTextures ) {
  16098. console.warn( 'WebGLRenderer: trying to use ' + textureUnit + ' texture units while this GPU supports only ' + capabilities.maxTextures );
  16099. }
  16100. _usedTextureUnits += 1;
  16101. return textureUnit;
  16102. }
  16103. this.allocTextureUnit = allocTextureUnit;
  16104. // this.setTexture2D = setTexture2D;
  16105. this.setTexture2D = ( function() {
  16106. var warned = false;
  16107. // backwards compatibility: peel texture.texture
  16108. return function setTexture2D( texture, slot ) {
  16109. if ( texture instanceof THREE.WebGLRenderTarget ) {
  16110. if ( ! warned ) {
  16111. console.warn( "THREE.WebGLRenderer.setTexture2D: don't use render targets as textures. Use their .texture property instead." );
  16112. warned = true;
  16113. }
  16114. texture = texture.texture;
  16115. }
  16116. textures.setTexture2D( texture, slot );
  16117. };
  16118. }() );
  16119. this.setTexture = ( function() {
  16120. var warned = false;
  16121. return function setTexture( texture, slot ) {
  16122. if ( ! warned ) {
  16123. console.warn( "THREE.WebGLRenderer: .setTexture is deprecated, use setTexture2D instead." );
  16124. warned = true;
  16125. }
  16126. textures.setTexture2D( texture, slot );
  16127. };
  16128. }() );
  16129. this.setTextureCube = ( function() {
  16130. var warned = false;
  16131. return function setTextureCube( texture, slot ) {
  16132. // backwards compatibility: peel texture.texture
  16133. if ( texture instanceof THREE.WebGLRenderTargetCube ) {
  16134. if ( ! warned ) {
  16135. console.warn( "THREE.WebGLRenderer.setTextureCube: don't use cube render targets as textures. Use their .texture property instead." );
  16136. warned = true;
  16137. }
  16138. texture = texture.texture;
  16139. }
  16140. // currently relying on the fact that WebGLRenderTargetCube.texture is a Texture and NOT a CubeTexture
  16141. // TODO: unify these code paths
  16142. if ( texture instanceof THREE.CubeTexture ||
  16143. ( Array.isArray( texture.image ) && texture.image.length === 6 ) ) {
  16144. // CompressedTexture can have Array in image :/
  16145. // this function alone should take care of cube textures
  16146. textures.setTextureCube( texture, slot );
  16147. } else {
  16148. // assumed: texture property of THREE.WebGLRenderTargetCube
  16149. textures.setTextureCubeDynamic( texture, slot );
  16150. }
  16151. };
  16152. }() );
  16153. this.getCurrentRenderTarget = function() {
  16154. return _currentRenderTarget;
  16155. };
  16156. this.setRenderTarget = function ( renderTarget ) {
  16157. _currentRenderTarget = renderTarget;
  16158. if ( renderTarget && properties.get( renderTarget ).__webglFramebuffer === undefined ) {
  16159. textures.setupRenderTarget( renderTarget );
  16160. }
  16161. var isCube = ( renderTarget instanceof THREE.WebGLRenderTargetCube );
  16162. var framebuffer;
  16163. if ( renderTarget ) {
  16164. var renderTargetProperties = properties.get( renderTarget );
  16165. if ( isCube ) {
  16166. framebuffer = renderTargetProperties.__webglFramebuffer[ renderTarget.activeCubeFace ];
  16167. } else {
  16168. framebuffer = renderTargetProperties.__webglFramebuffer;
  16169. }
  16170. _currentScissor.copy( renderTarget.scissor );
  16171. _currentScissorTest = renderTarget.scissorTest;
  16172. _currentViewport.copy( renderTarget.viewport );
  16173. } else {
  16174. framebuffer = null;
  16175. _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio );
  16176. _currentScissorTest = _scissorTest;
  16177. _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio );
  16178. }
  16179. if ( _currentFramebuffer !== framebuffer ) {
  16180. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  16181. _currentFramebuffer = framebuffer;
  16182. }
  16183. state.scissor( _currentScissor );
  16184. state.setScissorTest( _currentScissorTest );
  16185. state.viewport( _currentViewport );
  16186. if ( isCube ) {
  16187. var textureProperties = properties.get( renderTarget.texture );
  16188. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + renderTarget.activeCubeFace, textureProperties.__webglTexture, renderTarget.activeMipMapLevel );
  16189. }
  16190. };
  16191. this.readRenderTargetPixels = function ( renderTarget, x, y, width, height, buffer ) {
  16192. if ( renderTarget instanceof THREE.WebGLRenderTarget === false ) {
  16193. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
  16194. return;
  16195. }
  16196. var framebuffer = properties.get( renderTarget ).__webglFramebuffer;
  16197. if ( framebuffer ) {
  16198. var restore = false;
  16199. if ( framebuffer !== _currentFramebuffer ) {
  16200. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  16201. restore = true;
  16202. }
  16203. try {
  16204. var texture = renderTarget.texture;
  16205. if ( texture.format !== THREE.RGBAFormat && paramThreeToGL( texture.format ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_FORMAT ) ) {
  16206. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
  16207. return;
  16208. }
  16209. if ( texture.type !== THREE.UnsignedByteType &&
  16210. paramThreeToGL( texture.type ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_TYPE ) &&
  16211. ! ( texture.type === THREE.FloatType && extensions.get( 'WEBGL_color_buffer_float' ) ) &&
  16212. ! ( texture.type === THREE.HalfFloatType && extensions.get( 'EXT_color_buffer_half_float' ) ) ) {
  16213. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' );
  16214. return;
  16215. }
  16216. if ( _gl.checkFramebufferStatus( _gl.FRAMEBUFFER ) === _gl.FRAMEBUFFER_COMPLETE ) {
  16217. // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
  16218. if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {
  16219. _gl.readPixels( x, y, width, height, paramThreeToGL( texture.format ), paramThreeToGL( texture.type ), buffer );
  16220. }
  16221. } else {
  16222. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );
  16223. }
  16224. } finally {
  16225. if ( restore ) {
  16226. _gl.bindFramebuffer( _gl.FRAMEBUFFER, _currentFramebuffer );
  16227. }
  16228. }
  16229. }
  16230. };
  16231. // Map three.js constants to WebGL constants
  16232. function paramThreeToGL ( p ) {
  16233. var extension;
  16234. if ( p === THREE.RepeatWrapping ) return _gl.REPEAT;
  16235. if ( p === THREE.ClampToEdgeWrapping ) return _gl.CLAMP_TO_EDGE;
  16236. if ( p === THREE.MirroredRepeatWrapping ) return _gl.MIRRORED_REPEAT;
  16237. if ( p === THREE.NearestFilter ) return _gl.NEAREST;
  16238. if ( p === THREE.NearestMipMapNearestFilter ) return _gl.NEAREST_MIPMAP_NEAREST;
  16239. if ( p === THREE.NearestMipMapLinearFilter ) return _gl.NEAREST_MIPMAP_LINEAR;
  16240. if ( p === THREE.LinearFilter ) return _gl.LINEAR;
  16241. if ( p === THREE.LinearMipMapNearestFilter ) return _gl.LINEAR_MIPMAP_NEAREST;
  16242. if ( p === THREE.LinearMipMapLinearFilter ) return _gl.LINEAR_MIPMAP_LINEAR;
  16243. if ( p === THREE.UnsignedByteType ) return _gl.UNSIGNED_BYTE;
  16244. if ( p === THREE.UnsignedShort4444Type ) return _gl.UNSIGNED_SHORT_4_4_4_4;
  16245. if ( p === THREE.UnsignedShort5551Type ) return _gl.UNSIGNED_SHORT_5_5_5_1;
  16246. if ( p === THREE.UnsignedShort565Type ) return _gl.UNSIGNED_SHORT_5_6_5;
  16247. if ( p === THREE.ByteType ) return _gl.BYTE;
  16248. if ( p === THREE.ShortType ) return _gl.SHORT;
  16249. if ( p === THREE.UnsignedShortType ) return _gl.UNSIGNED_SHORT;
  16250. if ( p === THREE.IntType ) return _gl.INT;
  16251. if ( p === THREE.UnsignedIntType ) return _gl.UNSIGNED_INT;
  16252. if ( p === THREE.FloatType ) return _gl.FLOAT;
  16253. extension = extensions.get( 'OES_texture_half_float' );
  16254. if ( extension !== null ) {
  16255. if ( p === THREE.HalfFloatType ) return extension.HALF_FLOAT_OES;
  16256. }
  16257. if ( p === THREE.AlphaFormat ) return _gl.ALPHA;
  16258. if ( p === THREE.RGBFormat ) return _gl.RGB;
  16259. if ( p === THREE.RGBAFormat ) return _gl.RGBA;
  16260. if ( p === THREE.LuminanceFormat ) return _gl.LUMINANCE;
  16261. if ( p === THREE.LuminanceAlphaFormat ) return _gl.LUMINANCE_ALPHA;
  16262. if ( p === THREE.DepthFormat ) return _gl.DEPTH_COMPONENT;
  16263. if ( p === THREE.AddEquation ) return _gl.FUNC_ADD;
  16264. if ( p === THREE.SubtractEquation ) return _gl.FUNC_SUBTRACT;
  16265. if ( p === THREE.ReverseSubtractEquation ) return _gl.FUNC_REVERSE_SUBTRACT;
  16266. if ( p === THREE.ZeroFactor ) return _gl.ZERO;
  16267. if ( p === THREE.OneFactor ) return _gl.ONE;
  16268. if ( p === THREE.SrcColorFactor ) return _gl.SRC_COLOR;
  16269. if ( p === THREE.OneMinusSrcColorFactor ) return _gl.ONE_MINUS_SRC_COLOR;
  16270. if ( p === THREE.SrcAlphaFactor ) return _gl.SRC_ALPHA;
  16271. if ( p === THREE.OneMinusSrcAlphaFactor ) return _gl.ONE_MINUS_SRC_ALPHA;
  16272. if ( p === THREE.DstAlphaFactor ) return _gl.DST_ALPHA;
  16273. if ( p === THREE.OneMinusDstAlphaFactor ) return _gl.ONE_MINUS_DST_ALPHA;
  16274. if ( p === THREE.DstColorFactor ) return _gl.DST_COLOR;
  16275. if ( p === THREE.OneMinusDstColorFactor ) return _gl.ONE_MINUS_DST_COLOR;
  16276. if ( p === THREE.SrcAlphaSaturateFactor ) return _gl.SRC_ALPHA_SATURATE;
  16277. extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );
  16278. if ( extension !== null ) {
  16279. if ( p === THREE.RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  16280. if ( p === THREE.RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  16281. if ( p === THREE.RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  16282. if ( p === THREE.RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  16283. }
  16284. extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  16285. if ( extension !== null ) {
  16286. if ( p === THREE.RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  16287. if ( p === THREE.RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  16288. if ( p === THREE.RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  16289. if ( p === THREE.RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  16290. }
  16291. extension = extensions.get( 'WEBGL_compressed_texture_etc1' );
  16292. if ( extension !== null ) {
  16293. if ( p === THREE.RGB_ETC1_Format ) return extension.COMPRESSED_RGB_ETC1_WEBGL;
  16294. }
  16295. extension = extensions.get( 'EXT_blend_minmax' );
  16296. if ( extension !== null ) {
  16297. if ( p === THREE.MinEquation ) return extension.MIN_EXT;
  16298. if ( p === THREE.MaxEquation ) return extension.MAX_EXT;
  16299. }
  16300. return 0;
  16301. }
  16302. };
  16303. // File:src/renderers/WebGLRenderTarget.js
  16304. /**
  16305. * @author szimek / https://github.com/szimek/
  16306. * @author alteredq / http://alteredqualia.com/
  16307. * @author Marius Kintel / https://github.com/kintel
  16308. */
  16309. /*
  16310. In options, we can specify:
  16311. * Texture parameters for an auto-generated target texture
  16312. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  16313. */
  16314. THREE.WebGLRenderTarget = function ( width, height, options ) {
  16315. this.uuid = THREE.Math.generateUUID();
  16316. this.width = width;
  16317. this.height = height;
  16318. this.scissor = new THREE.Vector4( 0, 0, width, height );
  16319. this.scissorTest = false;
  16320. this.viewport = new THREE.Vector4( 0, 0, width, height );
  16321. options = options || {};
  16322. if ( options.minFilter === undefined ) options.minFilter = THREE.LinearFilter;
  16323. this.texture = new THREE.Texture( undefined, undefined, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding );
  16324. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  16325. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;
  16326. this.depthTexture = null;
  16327. };
  16328. Object.assign( THREE.WebGLRenderTarget.prototype, THREE.EventDispatcher.prototype, {
  16329. setSize: function ( width, height ) {
  16330. if ( this.width !== width || this.height !== height ) {
  16331. this.width = width;
  16332. this.height = height;
  16333. this.dispose();
  16334. }
  16335. this.viewport.set( 0, 0, width, height );
  16336. this.scissor.set( 0, 0, width, height );
  16337. },
  16338. clone: function () {
  16339. return new this.constructor().copy( this );
  16340. },
  16341. copy: function ( source ) {
  16342. this.width = source.width;
  16343. this.height = source.height;
  16344. this.viewport.copy( source.viewport );
  16345. this.texture = source.texture.clone();
  16346. this.depthBuffer = source.depthBuffer;
  16347. this.stencilBuffer = source.stencilBuffer;
  16348. this.depthTexture = source.depthTexture;
  16349. return this;
  16350. },
  16351. dispose: function () {
  16352. this.dispatchEvent( { type: 'dispose' } );
  16353. }
  16354. } );
  16355. // File:src/renderers/WebGLRenderTargetCube.js
  16356. /**
  16357. * @author alteredq / http://alteredqualia.com
  16358. */
  16359. THREE.WebGLRenderTargetCube = function ( width, height, options ) {
  16360. THREE.WebGLRenderTarget.call( this, width, height, options );
  16361. this.activeCubeFace = 0; // PX 0, NX 1, PY 2, NY 3, PZ 4, NZ 5
  16362. this.activeMipMapLevel = 0;
  16363. };
  16364. THREE.WebGLRenderTargetCube.prototype = Object.create( THREE.WebGLRenderTarget.prototype );
  16365. THREE.WebGLRenderTargetCube.prototype.constructor = THREE.WebGLRenderTargetCube;
  16366. // File:src/renderers/webgl/WebGLBufferRenderer.js
  16367. /**
  16368. * @author mrdoob / http://mrdoob.com/
  16369. */
  16370. THREE.WebGLBufferRenderer = function ( _gl, extensions, _infoRender ) {
  16371. var mode;
  16372. function setMode( value ) {
  16373. mode = value;
  16374. }
  16375. function render( start, count ) {
  16376. _gl.drawArrays( mode, start, count );
  16377. _infoRender.calls ++;
  16378. _infoRender.vertices += count;
  16379. if ( mode === _gl.TRIANGLES ) _infoRender.faces += count / 3;
  16380. }
  16381. function renderInstances( geometry ) {
  16382. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  16383. if ( extension === null ) {
  16384. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  16385. return;
  16386. }
  16387. var position = geometry.attributes.position;
  16388. var count = 0;
  16389. if ( position instanceof THREE.InterleavedBufferAttribute ) {
  16390. count = position.data.count;
  16391. extension.drawArraysInstancedANGLE( mode, 0, count, geometry.maxInstancedCount );
  16392. } else {
  16393. count = position.count;
  16394. extension.drawArraysInstancedANGLE( mode, 0, count, geometry.maxInstancedCount );
  16395. }
  16396. _infoRender.calls ++;
  16397. _infoRender.vertices += count * geometry.maxInstancedCount;
  16398. if ( mode === _gl.TRIANGLES ) _infoRender.faces += geometry.maxInstancedCount * count / 3;
  16399. }
  16400. this.setMode = setMode;
  16401. this.render = render;
  16402. this.renderInstances = renderInstances;
  16403. };
  16404. // File:src/renderers/webgl/WebGLClipping.js
  16405. THREE.WebGLClipping = function() {
  16406. var scope = this,
  16407. globalState = null,
  16408. numGlobalPlanes = 0,
  16409. localClippingEnabled = false,
  16410. renderingShadows = false,
  16411. plane = new THREE.Plane(),
  16412. viewNormalMatrix = new THREE.Matrix3(),
  16413. uniform = { value: null, needsUpdate: false };
  16414. this.uniform = uniform;
  16415. this.numPlanes = 0;
  16416. this.init = function( planes, enableLocalClipping, camera ) {
  16417. var enabled =
  16418. planes.length !== 0 ||
  16419. enableLocalClipping ||
  16420. // enable state of previous frame - the clipping code has to
  16421. // run another frame in order to reset the state:
  16422. numGlobalPlanes !== 0 ||
  16423. localClippingEnabled;
  16424. localClippingEnabled = enableLocalClipping;
  16425. globalState = projectPlanes( planes, camera, 0 );
  16426. numGlobalPlanes = planes.length;
  16427. return enabled;
  16428. };
  16429. this.beginShadows = function() {
  16430. renderingShadows = true;
  16431. projectPlanes( null );
  16432. };
  16433. this.endShadows = function() {
  16434. renderingShadows = false;
  16435. resetGlobalState();
  16436. };
  16437. this.setState = function( planes, clipShadows, camera, cache, fromCache ) {
  16438. if ( ! localClippingEnabled ||
  16439. planes === null || planes.length === 0 ||
  16440. renderingShadows && ! clipShadows ) {
  16441. // there's no local clipping
  16442. if ( renderingShadows ) {
  16443. // there's no global clipping
  16444. projectPlanes( null );
  16445. } else {
  16446. resetGlobalState();
  16447. }
  16448. } else {
  16449. var nGlobal = renderingShadows ? 0 : numGlobalPlanes,
  16450. lGlobal = nGlobal * 4,
  16451. dstArray = cache.clippingState || null;
  16452. uniform.value = dstArray; // ensure unique state
  16453. dstArray = projectPlanes( planes, camera, lGlobal, fromCache );
  16454. for ( var i = 0; i !== lGlobal; ++ i ) {
  16455. dstArray[ i ] = globalState[ i ];
  16456. }
  16457. cache.clippingState = dstArray;
  16458. this.numPlanes += nGlobal;
  16459. }
  16460. };
  16461. function resetGlobalState() {
  16462. if ( uniform.value !== globalState ) {
  16463. uniform.value = globalState;
  16464. uniform.needsUpdate = numGlobalPlanes > 0;
  16465. }
  16466. scope.numPlanes = numGlobalPlanes;
  16467. }
  16468. function projectPlanes( planes, camera, dstOffset, skipTransform ) {
  16469. var nPlanes = planes !== null ? planes.length : 0,
  16470. dstArray = null;
  16471. if ( nPlanes !== 0 ) {
  16472. dstArray = uniform.value;
  16473. if ( skipTransform !== true || dstArray === null ) {
  16474. var flatSize = dstOffset + nPlanes * 4,
  16475. viewMatrix = camera.matrixWorldInverse;
  16476. viewNormalMatrix.getNormalMatrix( viewMatrix );
  16477. if ( dstArray === null || dstArray.length < flatSize ) {
  16478. dstArray = new Float32Array( flatSize );
  16479. }
  16480. for ( var i = 0, i4 = dstOffset;
  16481. i !== nPlanes; ++ i, i4 += 4 ) {
  16482. plane.copy( planes[ i ] ).
  16483. applyMatrix4( viewMatrix, viewNormalMatrix );
  16484. plane.normal.toArray( dstArray, i4 );
  16485. dstArray[ i4 + 3 ] = plane.constant;
  16486. }
  16487. }
  16488. uniform.value = dstArray;
  16489. uniform.needsUpdate = true;
  16490. }
  16491. scope.numPlanes = nPlanes;
  16492. return dstArray;
  16493. }
  16494. };
  16495. // File:src/renderers/webgl/WebGLIndexedBufferRenderer.js
  16496. /**
  16497. * @author mrdoob / http://mrdoob.com/
  16498. */
  16499. THREE.WebGLIndexedBufferRenderer = function ( _gl, extensions, _infoRender ) {
  16500. var mode;
  16501. function setMode( value ) {
  16502. mode = value;
  16503. }
  16504. var type, size;
  16505. function setIndex( index ) {
  16506. if ( index.array instanceof Uint32Array && extensions.get( 'OES_element_index_uint' ) ) {
  16507. type = _gl.UNSIGNED_INT;
  16508. size = 4;
  16509. } else {
  16510. type = _gl.UNSIGNED_SHORT;
  16511. size = 2;
  16512. }
  16513. }
  16514. function render( start, count ) {
  16515. _gl.drawElements( mode, count, type, start * size );
  16516. _infoRender.calls ++;
  16517. _infoRender.vertices += count;
  16518. if ( mode === _gl.TRIANGLES ) _infoRender.faces += count / 3;
  16519. }
  16520. function renderInstances( geometry, start, count ) {
  16521. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  16522. if ( extension === null ) {
  16523. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  16524. return;
  16525. }
  16526. extension.drawElementsInstancedANGLE( mode, count, type, start * size, geometry.maxInstancedCount );
  16527. _infoRender.calls ++;
  16528. _infoRender.vertices += count * geometry.maxInstancedCount;
  16529. if ( mode === _gl.TRIANGLES ) _infoRender.faces += geometry.maxInstancedCount * count / 3;
  16530. }
  16531. this.setMode = setMode;
  16532. this.setIndex = setIndex;
  16533. this.render = render;
  16534. this.renderInstances = renderInstances;
  16535. };
  16536. // File:src/renderers/webgl/WebGLExtensions.js
  16537. /**
  16538. * @author mrdoob / http://mrdoob.com/
  16539. */
  16540. THREE.WebGLExtensions = function ( gl ) {
  16541. var extensions = {};
  16542. this.get = function ( name ) {
  16543. if ( extensions[ name ] !== undefined ) {
  16544. return extensions[ name ];
  16545. }
  16546. var extension;
  16547. switch ( name ) {
  16548. case 'WEBGL_depth_texture':
  16549. extension = gl.getExtension( 'WEBGL_depth_texture' ) || gl.getExtension( 'MOZ_WEBGL_depth_texture' ) || gl.getExtension( 'WEBKIT_WEBGL_depth_texture' );
  16550. break;
  16551. case 'EXT_texture_filter_anisotropic':
  16552. extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' );
  16553. break;
  16554. case 'WEBGL_compressed_texture_s3tc':
  16555. extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' );
  16556. break;
  16557. case 'WEBGL_compressed_texture_pvrtc':
  16558. extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' );
  16559. break;
  16560. case 'WEBGL_compressed_texture_etc1':
  16561. extension = gl.getExtension( 'WEBGL_compressed_texture_etc1' );
  16562. break;
  16563. default:
  16564. extension = gl.getExtension( name );
  16565. }
  16566. if ( extension === null ) {
  16567. console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
  16568. }
  16569. extensions[ name ] = extension;
  16570. return extension;
  16571. };
  16572. };
  16573. // File:src/renderers/webgl/WebGLCapabilities.js
  16574. THREE.WebGLCapabilities = function ( gl, extensions, parameters ) {
  16575. var maxAnisotropy;
  16576. function getMaxAnisotropy() {
  16577. if ( maxAnisotropy !== undefined ) return maxAnisotropy;
  16578. var extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  16579. if ( extension !== null ) {
  16580. maxAnisotropy = gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );
  16581. } else {
  16582. maxAnisotropy = 0;
  16583. }
  16584. return maxAnisotropy;
  16585. }
  16586. function getMaxPrecision( precision ) {
  16587. if ( precision === 'highp' ) {
  16588. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.HIGH_FLOAT ).precision > 0 &&
  16589. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.HIGH_FLOAT ).precision > 0 ) {
  16590. return 'highp';
  16591. }
  16592. precision = 'mediump';
  16593. }
  16594. if ( precision === 'mediump' ) {
  16595. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.MEDIUM_FLOAT ).precision > 0 &&
  16596. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.MEDIUM_FLOAT ).precision > 0 ) {
  16597. return 'mediump';
  16598. }
  16599. }
  16600. return 'lowp';
  16601. }
  16602. this.getMaxAnisotropy = getMaxAnisotropy;
  16603. this.getMaxPrecision = getMaxPrecision;
  16604. this.precision = parameters.precision !== undefined ? parameters.precision : 'highp';
  16605. this.logarithmicDepthBuffer = parameters.logarithmicDepthBuffer !== undefined ? parameters.logarithmicDepthBuffer : false;
  16606. this.maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
  16607. this.maxVertexTextures = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS );
  16608. this.maxTextureSize = gl.getParameter( gl.MAX_TEXTURE_SIZE );
  16609. this.maxCubemapSize = gl.getParameter( gl.MAX_CUBE_MAP_TEXTURE_SIZE );
  16610. this.maxAttributes = gl.getParameter( gl.MAX_VERTEX_ATTRIBS );
  16611. this.maxVertexUniforms = gl.getParameter( gl.MAX_VERTEX_UNIFORM_VECTORS );
  16612. this.maxVaryings = gl.getParameter( gl.MAX_VARYING_VECTORS );
  16613. this.maxFragmentUniforms = gl.getParameter( gl.MAX_FRAGMENT_UNIFORM_VECTORS );
  16614. this.vertexTextures = this.maxVertexTextures > 0;
  16615. this.floatFragmentTextures = !! extensions.get( 'OES_texture_float' );
  16616. this.floatVertexTextures = this.vertexTextures && this.floatFragmentTextures;
  16617. var _maxPrecision = getMaxPrecision( this.precision );
  16618. if ( _maxPrecision !== this.precision ) {
  16619. console.warn( 'THREE.WebGLRenderer:', this.precision, 'not supported, using', _maxPrecision, 'instead.' );
  16620. this.precision = _maxPrecision;
  16621. }
  16622. if ( this.logarithmicDepthBuffer ) {
  16623. this.logarithmicDepthBuffer = !! extensions.get( 'EXT_frag_depth' );
  16624. }
  16625. };
  16626. // File:src/renderers/webgl/WebGLGeometries.js
  16627. /**
  16628. * @author mrdoob / http://mrdoob.com/
  16629. */
  16630. THREE.WebGLGeometries = function ( gl, properties, info ) {
  16631. var geometries = {};
  16632. function get( object ) {
  16633. var geometry = object.geometry;
  16634. if ( geometries[ geometry.id ] !== undefined ) {
  16635. return geometries[ geometry.id ];
  16636. }
  16637. geometry.addEventListener( 'dispose', onGeometryDispose );
  16638. var buffergeometry;
  16639. if ( geometry instanceof THREE.BufferGeometry ) {
  16640. buffergeometry = geometry;
  16641. } else if ( geometry instanceof THREE.Geometry ) {
  16642. if ( geometry._bufferGeometry === undefined ) {
  16643. geometry._bufferGeometry = new THREE.BufferGeometry().setFromObject( object );
  16644. }
  16645. buffergeometry = geometry._bufferGeometry;
  16646. }
  16647. geometries[ geometry.id ] = buffergeometry;
  16648. info.memory.geometries ++;
  16649. return buffergeometry;
  16650. }
  16651. function onGeometryDispose( event ) {
  16652. var geometry = event.target;
  16653. var buffergeometry = geometries[ geometry.id ];
  16654. if ( buffergeometry.index !== null ) {
  16655. deleteAttribute( buffergeometry.index );
  16656. }
  16657. deleteAttributes( buffergeometry.attributes );
  16658. geometry.removeEventListener( 'dispose', onGeometryDispose );
  16659. delete geometries[ geometry.id ];
  16660. // TODO
  16661. var property = properties.get( geometry );
  16662. if ( property.wireframe ) {
  16663. deleteAttribute( property.wireframe );
  16664. }
  16665. properties.delete( geometry );
  16666. var bufferproperty = properties.get( buffergeometry );
  16667. if ( bufferproperty.wireframe ) {
  16668. deleteAttribute( bufferproperty.wireframe );
  16669. }
  16670. properties.delete( buffergeometry );
  16671. //
  16672. info.memory.geometries --;
  16673. }
  16674. function getAttributeBuffer( attribute ) {
  16675. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  16676. return properties.get( attribute.data ).__webglBuffer;
  16677. }
  16678. return properties.get( attribute ).__webglBuffer;
  16679. }
  16680. function deleteAttribute( attribute ) {
  16681. var buffer = getAttributeBuffer( attribute );
  16682. if ( buffer !== undefined ) {
  16683. gl.deleteBuffer( buffer );
  16684. removeAttributeBuffer( attribute );
  16685. }
  16686. }
  16687. function deleteAttributes( attributes ) {
  16688. for ( var name in attributes ) {
  16689. deleteAttribute( attributes[ name ] );
  16690. }
  16691. }
  16692. function removeAttributeBuffer( attribute ) {
  16693. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  16694. properties.delete( attribute.data );
  16695. } else {
  16696. properties.delete( attribute );
  16697. }
  16698. }
  16699. this.get = get;
  16700. };
  16701. // File:src/renderers/webgl/WebGLLights.js
  16702. /**
  16703. * @author mrdoob / http://mrdoob.com/
  16704. */
  16705. THREE.WebGLLights = function () {
  16706. var lights = {};
  16707. this.get = function ( light ) {
  16708. if ( lights[ light.id ] !== undefined ) {
  16709. return lights[ light.id ];
  16710. }
  16711. var uniforms;
  16712. switch ( light.type ) {
  16713. case 'DirectionalLight':
  16714. uniforms = {
  16715. direction: new THREE.Vector3(),
  16716. color: new THREE.Color(),
  16717. shadow: false,
  16718. shadowBias: 0,
  16719. shadowRadius: 1,
  16720. shadowMapSize: new THREE.Vector2()
  16721. };
  16722. break;
  16723. case 'SpotLight':
  16724. uniforms = {
  16725. position: new THREE.Vector3(),
  16726. direction: new THREE.Vector3(),
  16727. color: new THREE.Color(),
  16728. distance: 0,
  16729. coneCos: 0,
  16730. penumbraCos: 0,
  16731. decay: 0,
  16732. shadow: false,
  16733. shadowBias: 0,
  16734. shadowRadius: 1,
  16735. shadowMapSize: new THREE.Vector2()
  16736. };
  16737. break;
  16738. case 'PointLight':
  16739. uniforms = {
  16740. position: new THREE.Vector3(),
  16741. color: new THREE.Color(),
  16742. distance: 0,
  16743. decay: 0,
  16744. shadow: false,
  16745. shadowBias: 0,
  16746. shadowRadius: 1,
  16747. shadowMapSize: new THREE.Vector2()
  16748. };
  16749. break;
  16750. case 'HemisphereLight':
  16751. uniforms = {
  16752. direction: new THREE.Vector3(),
  16753. skyColor: new THREE.Color(),
  16754. groundColor: new THREE.Color()
  16755. };
  16756. break;
  16757. }
  16758. lights[ light.id ] = uniforms;
  16759. return uniforms;
  16760. };
  16761. };
  16762. // File:src/renderers/webgl/WebGLObjects.js
  16763. /**
  16764. * @author mrdoob / http://mrdoob.com/
  16765. */
  16766. THREE.WebGLObjects = function ( gl, properties, info ) {
  16767. var geometries = new THREE.WebGLGeometries( gl, properties, info );
  16768. //
  16769. function update( object ) {
  16770. // TODO: Avoid updating twice (when using shadowMap). Maybe add frame counter.
  16771. var geometry = geometries.get( object );
  16772. if ( object.geometry instanceof THREE.Geometry ) {
  16773. geometry.updateFromObject( object );
  16774. }
  16775. var index = geometry.index;
  16776. var attributes = geometry.attributes;
  16777. if ( index !== null ) {
  16778. updateAttribute( index, gl.ELEMENT_ARRAY_BUFFER );
  16779. }
  16780. for ( var name in attributes ) {
  16781. updateAttribute( attributes[ name ], gl.ARRAY_BUFFER );
  16782. }
  16783. // morph targets
  16784. var morphAttributes = geometry.morphAttributes;
  16785. for ( var name in morphAttributes ) {
  16786. var array = morphAttributes[ name ];
  16787. for ( var i = 0, l = array.length; i < l; i ++ ) {
  16788. updateAttribute( array[ i ], gl.ARRAY_BUFFER );
  16789. }
  16790. }
  16791. return geometry;
  16792. }
  16793. function updateAttribute( attribute, bufferType ) {
  16794. var data = ( attribute instanceof THREE.InterleavedBufferAttribute ) ? attribute.data : attribute;
  16795. var attributeProperties = properties.get( data );
  16796. if ( attributeProperties.__webglBuffer === undefined ) {
  16797. createBuffer( attributeProperties, data, bufferType );
  16798. } else if ( attributeProperties.version !== data.version ) {
  16799. updateBuffer( attributeProperties, data, bufferType );
  16800. }
  16801. }
  16802. function createBuffer( attributeProperties, data, bufferType ) {
  16803. attributeProperties.__webglBuffer = gl.createBuffer();
  16804. gl.bindBuffer( bufferType, attributeProperties.__webglBuffer );
  16805. var usage = data.dynamic ? gl.DYNAMIC_DRAW : gl.STATIC_DRAW;
  16806. gl.bufferData( bufferType, data.array, usage );
  16807. attributeProperties.version = data.version;
  16808. }
  16809. function updateBuffer( attributeProperties, data, bufferType ) {
  16810. gl.bindBuffer( bufferType, attributeProperties.__webglBuffer );
  16811. if ( data.dynamic === false || data.updateRange.count === - 1 ) {
  16812. // Not using update ranges
  16813. gl.bufferSubData( bufferType, 0, data.array );
  16814. } else if ( data.updateRange.count === 0 ) {
  16815. 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.' );
  16816. } else {
  16817. gl.bufferSubData( bufferType, data.updateRange.offset * data.array.BYTES_PER_ELEMENT,
  16818. data.array.subarray( data.updateRange.offset, data.updateRange.offset + data.updateRange.count ) );
  16819. data.updateRange.count = 0; // reset range
  16820. }
  16821. attributeProperties.version = data.version;
  16822. }
  16823. function getAttributeBuffer( attribute ) {
  16824. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  16825. return properties.get( attribute.data ).__webglBuffer;
  16826. }
  16827. return properties.get( attribute ).__webglBuffer;
  16828. }
  16829. function getWireframeAttribute( geometry ) {
  16830. var property = properties.get( geometry );
  16831. if ( property.wireframe !== undefined ) {
  16832. return property.wireframe;
  16833. }
  16834. var indices = [];
  16835. var index = geometry.index;
  16836. var attributes = geometry.attributes;
  16837. var position = attributes.position;
  16838. // console.time( 'wireframe' );
  16839. if ( index !== null ) {
  16840. var edges = {};
  16841. var array = index.array;
  16842. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  16843. var a = array[ i + 0 ];
  16844. var b = array[ i + 1 ];
  16845. var c = array[ i + 2 ];
  16846. if ( checkEdge( edges, a, b ) ) indices.push( a, b );
  16847. if ( checkEdge( edges, b, c ) ) indices.push( b, c );
  16848. if ( checkEdge( edges, c, a ) ) indices.push( c, a );
  16849. }
  16850. } else {
  16851. var array = attributes.position.array;
  16852. for ( var i = 0, l = ( array.length / 3 ) - 1; i < l; i += 3 ) {
  16853. var a = i + 0;
  16854. var b = i + 1;
  16855. var c = i + 2;
  16856. indices.push( a, b, b, c, c, a );
  16857. }
  16858. }
  16859. // console.timeEnd( 'wireframe' );
  16860. var TypeArray = position.count > 65535 ? Uint32Array : Uint16Array;
  16861. var attribute = new THREE.BufferAttribute( new TypeArray( indices ), 1 );
  16862. updateAttribute( attribute, gl.ELEMENT_ARRAY_BUFFER );
  16863. property.wireframe = attribute;
  16864. return attribute;
  16865. }
  16866. function checkEdge( edges, a, b ) {
  16867. if ( a > b ) {
  16868. var tmp = a;
  16869. a = b;
  16870. b = tmp;
  16871. }
  16872. var list = edges[ a ];
  16873. if ( list === undefined ) {
  16874. edges[ a ] = [ b ];
  16875. return true;
  16876. } else if ( list.indexOf( b ) === -1 ) {
  16877. list.push( b );
  16878. return true;
  16879. }
  16880. return false;
  16881. }
  16882. this.getAttributeBuffer = getAttributeBuffer;
  16883. this.getWireframeAttribute = getWireframeAttribute;
  16884. this.update = update;
  16885. };
  16886. // File:src/renderers/webgl/WebGLProgram.js
  16887. THREE.WebGLProgram = ( function () {
  16888. var programIdCount = 0;
  16889. function getEncodingComponents( encoding ) {
  16890. switch ( encoding ) {
  16891. case THREE.LinearEncoding:
  16892. return [ 'Linear','( value )' ];
  16893. case THREE.sRGBEncoding:
  16894. return [ 'sRGB','( value )' ];
  16895. case THREE.RGBEEncoding:
  16896. return [ 'RGBE','( value )' ];
  16897. case THREE.RGBM7Encoding:
  16898. return [ 'RGBM','( value, 7.0 )' ];
  16899. case THREE.RGBM16Encoding:
  16900. return [ 'RGBM','( value, 16.0 )' ];
  16901. case THREE.RGBDEncoding:
  16902. return [ 'RGBD','( value, 256.0 )' ];
  16903. case THREE.GammaEncoding:
  16904. return [ 'Gamma','( value, float( GAMMA_FACTOR ) )' ];
  16905. default:
  16906. throw new Error( 'unsupported encoding: ' + encoding );
  16907. }
  16908. }
  16909. function getTexelDecodingFunction( functionName, encoding ) {
  16910. var components = getEncodingComponents( encoding );
  16911. return "vec4 " + functionName + "( vec4 value ) { return " + components[ 0 ] + "ToLinear" + components[ 1 ] + "; }";
  16912. }
  16913. function getTexelEncodingFunction( functionName, encoding ) {
  16914. var components = getEncodingComponents( encoding );
  16915. return "vec4 " + functionName + "( vec4 value ) { return LinearTo" + components[ 0 ] + components[ 1 ] + "; }";
  16916. }
  16917. function getToneMappingFunction( functionName, toneMapping ) {
  16918. var toneMappingName;
  16919. switch ( toneMapping ) {
  16920. case THREE.LinearToneMapping:
  16921. toneMappingName = "Linear";
  16922. break;
  16923. case THREE.ReinhardToneMapping:
  16924. toneMappingName = "Reinhard";
  16925. break;
  16926. case THREE.Uncharted2ToneMapping:
  16927. toneMappingName = "Uncharted2";
  16928. break;
  16929. case THREE.CineonToneMapping:
  16930. toneMappingName = "OptimizedCineon";
  16931. break;
  16932. default:
  16933. throw new Error( 'unsupported toneMapping: ' + toneMapping );
  16934. }
  16935. return "vec3 " + functionName + "( vec3 color ) { return " + toneMappingName + "ToneMapping( color ); }";
  16936. }
  16937. function generateExtensions( extensions, parameters, rendererExtensions ) {
  16938. extensions = extensions || {};
  16939. var chunks = [
  16940. ( extensions.derivatives || parameters.envMapCubeUV || parameters.bumpMap || parameters.normalMap || parameters.flatShading ) ? '#extension GL_OES_standard_derivatives : enable' : '',
  16941. ( extensions.fragDepth || parameters.logarithmicDepthBuffer ) && rendererExtensions.get( 'EXT_frag_depth' ) ? '#extension GL_EXT_frag_depth : enable' : '',
  16942. ( extensions.drawBuffers ) && rendererExtensions.get( 'WEBGL_draw_buffers' ) ? '#extension GL_EXT_draw_buffers : require' : '',
  16943. ( extensions.shaderTextureLOD || parameters.envMap ) && rendererExtensions.get( 'EXT_shader_texture_lod' ) ? '#extension GL_EXT_shader_texture_lod : enable' : '',
  16944. ];
  16945. return chunks.filter( filterEmptyLine ).join( '\n' );
  16946. }
  16947. function generateDefines( defines ) {
  16948. var chunks = [];
  16949. for ( var name in defines ) {
  16950. var value = defines[ name ];
  16951. if ( value === false ) continue;
  16952. chunks.push( '#define ' + name + ' ' + value );
  16953. }
  16954. return chunks.join( '\n' );
  16955. }
  16956. function fetchAttributeLocations( gl, program, identifiers ) {
  16957. var attributes = {};
  16958. var n = gl.getProgramParameter( program, gl.ACTIVE_ATTRIBUTES );
  16959. for ( var i = 0; i < n; i ++ ) {
  16960. var info = gl.getActiveAttrib( program, i );
  16961. var name = info.name;
  16962. // console.log("THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:", name, i );
  16963. attributes[ name ] = gl.getAttribLocation( program, name );
  16964. }
  16965. return attributes;
  16966. }
  16967. function filterEmptyLine( string ) {
  16968. return string !== '';
  16969. }
  16970. function replaceLightNums( string, parameters ) {
  16971. return string
  16972. .replace( /NUM_DIR_LIGHTS/g, parameters.numDirLights )
  16973. .replace( /NUM_SPOT_LIGHTS/g, parameters.numSpotLights )
  16974. .replace( /NUM_POINT_LIGHTS/g, parameters.numPointLights )
  16975. .replace( /NUM_HEMI_LIGHTS/g, parameters.numHemiLights );
  16976. }
  16977. function parseIncludes( string ) {
  16978. var pattern = /#include +<([\w\d.]+)>/g;
  16979. function replace( match, include ) {
  16980. var replace = THREE.ShaderChunk[ include ];
  16981. if ( replace === undefined ) {
  16982. throw new Error( 'Can not resolve #include <' + include + '>' );
  16983. }
  16984. return parseIncludes( replace );
  16985. }
  16986. return string.replace( pattern, replace );
  16987. }
  16988. function unrollLoops( string ) {
  16989. var pattern = /for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  16990. function replace( match, start, end, snippet ) {
  16991. var unroll = '';
  16992. for ( var i = parseInt( start ); i < parseInt( end ); i ++ ) {
  16993. unroll += snippet.replace( /\[ i \]/g, '[ ' + i + ' ]' );
  16994. }
  16995. return unroll;
  16996. }
  16997. return string.replace( pattern, replace );
  16998. }
  16999. return function WebGLProgram( renderer, code, material, parameters ) {
  17000. var gl = renderer.context;
  17001. var extensions = material.extensions;
  17002. var defines = material.defines;
  17003. var vertexShader = material.__webglShader.vertexShader;
  17004. var fragmentShader = material.__webglShader.fragmentShader;
  17005. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  17006. if ( parameters.shadowMapType === THREE.PCFShadowMap ) {
  17007. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  17008. } else if ( parameters.shadowMapType === THREE.PCFSoftShadowMap ) {
  17009. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  17010. }
  17011. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  17012. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  17013. var envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  17014. if ( parameters.envMap ) {
  17015. switch ( material.envMap.mapping ) {
  17016. case THREE.CubeReflectionMapping:
  17017. case THREE.CubeRefractionMapping:
  17018. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  17019. break;
  17020. case THREE.CubeUVReflectionMapping:
  17021. case THREE.CubeUVRefractionMapping:
  17022. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  17023. break;
  17024. case THREE.EquirectangularReflectionMapping:
  17025. case THREE.EquirectangularRefractionMapping:
  17026. envMapTypeDefine = 'ENVMAP_TYPE_EQUIREC';
  17027. break;
  17028. case THREE.SphericalReflectionMapping:
  17029. envMapTypeDefine = 'ENVMAP_TYPE_SPHERE';
  17030. break;
  17031. }
  17032. switch ( material.envMap.mapping ) {
  17033. case THREE.CubeRefractionMapping:
  17034. case THREE.EquirectangularRefractionMapping:
  17035. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  17036. break;
  17037. }
  17038. switch ( material.combine ) {
  17039. case THREE.MultiplyOperation:
  17040. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  17041. break;
  17042. case THREE.MixOperation:
  17043. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  17044. break;
  17045. case THREE.AddOperation:
  17046. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  17047. break;
  17048. }
  17049. }
  17050. var gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
  17051. // console.log( 'building new program ' );
  17052. //
  17053. var customExtensions = generateExtensions( extensions, parameters, renderer.extensions );
  17054. var customDefines = generateDefines( defines );
  17055. //
  17056. var program = gl.createProgram();
  17057. var prefixVertex, prefixFragment;
  17058. if ( material instanceof THREE.RawShaderMaterial ) {
  17059. prefixVertex = [
  17060. customDefines
  17061. ].filter( filterEmptyLine ).join( '\n' );
  17062. prefixFragment = [
  17063. customDefines
  17064. ].filter( filterEmptyLine ).join( '\n' );
  17065. } else {
  17066. prefixVertex = [
  17067. 'precision ' + parameters.precision + ' float;',
  17068. 'precision ' + parameters.precision + ' int;',
  17069. '#define SHADER_NAME ' + material.__webglShader.name,
  17070. customDefines,
  17071. parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '',
  17072. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  17073. '#define MAX_BONES ' + parameters.maxBones,
  17074. parameters.map ? '#define USE_MAP' : '',
  17075. parameters.envMap ? '#define USE_ENVMAP' : '',
  17076. parameters.envMap ? '#define ' + envMapModeDefine : '',
  17077. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  17078. parameters.aoMap ? '#define USE_AOMAP' : '',
  17079. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  17080. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  17081. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  17082. parameters.displacementMap && parameters.supportsVertexTextures ? '#define USE_DISPLACEMENTMAP' : '',
  17083. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  17084. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  17085. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  17086. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  17087. parameters.vertexColors ? '#define USE_COLOR' : '',
  17088. parameters.flatShading ? '#define FLAT_SHADED' : '',
  17089. parameters.skinning ? '#define USE_SKINNING' : '',
  17090. parameters.useVertexTexture ? '#define BONE_TEXTURE' : '',
  17091. parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
  17092. parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '',
  17093. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  17094. parameters.flipSided ? '#define FLIP_SIDED' : '',
  17095. '#define NUM_CLIPPING_PLANES ' + parameters.numClippingPlanes,
  17096. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  17097. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  17098. parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
  17099. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  17100. parameters.logarithmicDepthBuffer && renderer.extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  17101. 'uniform mat4 modelMatrix;',
  17102. 'uniform mat4 modelViewMatrix;',
  17103. 'uniform mat4 projectionMatrix;',
  17104. 'uniform mat4 viewMatrix;',
  17105. 'uniform mat3 normalMatrix;',
  17106. 'uniform vec3 cameraPosition;',
  17107. 'attribute vec3 position;',
  17108. 'attribute vec3 normal;',
  17109. 'attribute vec2 uv;',
  17110. '#ifdef USE_COLOR',
  17111. ' attribute vec3 color;',
  17112. '#endif',
  17113. '#ifdef USE_MORPHTARGETS',
  17114. ' attribute vec3 morphTarget0;',
  17115. ' attribute vec3 morphTarget1;',
  17116. ' attribute vec3 morphTarget2;',
  17117. ' attribute vec3 morphTarget3;',
  17118. ' #ifdef USE_MORPHNORMALS',
  17119. ' attribute vec3 morphNormal0;',
  17120. ' attribute vec3 morphNormal1;',
  17121. ' attribute vec3 morphNormal2;',
  17122. ' attribute vec3 morphNormal3;',
  17123. ' #else',
  17124. ' attribute vec3 morphTarget4;',
  17125. ' attribute vec3 morphTarget5;',
  17126. ' attribute vec3 morphTarget6;',
  17127. ' attribute vec3 morphTarget7;',
  17128. ' #endif',
  17129. '#endif',
  17130. '#ifdef USE_SKINNING',
  17131. ' attribute vec4 skinIndex;',
  17132. ' attribute vec4 skinWeight;',
  17133. '#endif',
  17134. '\n'
  17135. ].filter( filterEmptyLine ).join( '\n' );
  17136. prefixFragment = [
  17137. customExtensions,
  17138. 'precision ' + parameters.precision + ' float;',
  17139. 'precision ' + parameters.precision + ' int;',
  17140. '#define SHADER_NAME ' + material.__webglShader.name,
  17141. customDefines,
  17142. parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest : '',
  17143. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  17144. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  17145. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  17146. parameters.map ? '#define USE_MAP' : '',
  17147. parameters.envMap ? '#define USE_ENVMAP' : '',
  17148. parameters.envMap ? '#define ' + envMapTypeDefine : '',
  17149. parameters.envMap ? '#define ' + envMapModeDefine : '',
  17150. parameters.envMap ? '#define ' + envMapBlendingDefine : '',
  17151. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  17152. parameters.aoMap ? '#define USE_AOMAP' : '',
  17153. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  17154. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  17155. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  17156. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  17157. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  17158. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  17159. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  17160. parameters.vertexColors ? '#define USE_COLOR' : '',
  17161. parameters.flatShading ? '#define FLAT_SHADED' : '',
  17162. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  17163. parameters.flipSided ? '#define FLIP_SIDED' : '',
  17164. '#define NUM_CLIPPING_PLANES ' + parameters.numClippingPlanes,
  17165. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  17166. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  17167. parameters.premultipliedAlpha ? "#define PREMULTIPLIED_ALPHA" : '',
  17168. parameters.physicallyCorrectLights ? "#define PHYSICALLY_CORRECT_LIGHTS" : '',
  17169. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  17170. parameters.logarithmicDepthBuffer && renderer.extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  17171. parameters.envMap && renderer.extensions.get( 'EXT_shader_texture_lod' ) ? '#define TEXTURE_LOD_EXT' : '',
  17172. 'uniform mat4 viewMatrix;',
  17173. 'uniform vec3 cameraPosition;',
  17174. ( parameters.toneMapping !== THREE.NoToneMapping ) ? "#define TONE_MAPPING" : '',
  17175. ( parameters.toneMapping !== THREE.NoToneMapping ) ? THREE.ShaderChunk[ 'tonemapping_pars_fragment' ] : '', // this code is required here because it is used by the toneMapping() function defined below
  17176. ( parameters.toneMapping !== THREE.NoToneMapping ) ? getToneMappingFunction( "toneMapping", parameters.toneMapping ) : '',
  17177. ( 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
  17178. parameters.mapEncoding ? getTexelDecodingFunction( 'mapTexelToLinear', parameters.mapEncoding ) : '',
  17179. parameters.envMapEncoding ? getTexelDecodingFunction( 'envMapTexelToLinear', parameters.envMapEncoding ) : '',
  17180. parameters.emissiveMapEncoding ? getTexelDecodingFunction( 'emissiveMapTexelToLinear', parameters.emissiveMapEncoding ) : '',
  17181. parameters.outputEncoding ? getTexelEncodingFunction( "linearToOutputTexel", parameters.outputEncoding ) : '',
  17182. parameters.depthPacking ? "#define DEPTH_PACKING " + material.depthPacking : '',
  17183. '\n'
  17184. ].filter( filterEmptyLine ).join( '\n' );
  17185. }
  17186. vertexShader = parseIncludes( vertexShader, parameters );
  17187. vertexShader = replaceLightNums( vertexShader, parameters );
  17188. fragmentShader = parseIncludes( fragmentShader, parameters );
  17189. fragmentShader = replaceLightNums( fragmentShader, parameters );
  17190. if ( material instanceof THREE.ShaderMaterial === false ) {
  17191. vertexShader = unrollLoops( vertexShader );
  17192. fragmentShader = unrollLoops( fragmentShader );
  17193. }
  17194. var vertexGlsl = prefixVertex + vertexShader;
  17195. var fragmentGlsl = prefixFragment + fragmentShader;
  17196. // console.log( '*VERTEX*', vertexGlsl );
  17197. // console.log( '*FRAGMENT*', fragmentGlsl );
  17198. var glVertexShader = THREE.WebGLShader( gl, gl.VERTEX_SHADER, vertexGlsl );
  17199. var glFragmentShader = THREE.WebGLShader( gl, gl.FRAGMENT_SHADER, fragmentGlsl );
  17200. gl.attachShader( program, glVertexShader );
  17201. gl.attachShader( program, glFragmentShader );
  17202. // Force a particular attribute to index 0.
  17203. if ( material.index0AttributeName !== undefined ) {
  17204. gl.bindAttribLocation( program, 0, material.index0AttributeName );
  17205. } else if ( parameters.morphTargets === true ) {
  17206. // programs with morphTargets displace position out of attribute 0
  17207. gl.bindAttribLocation( program, 0, 'position' );
  17208. }
  17209. gl.linkProgram( program );
  17210. var programLog = gl.getProgramInfoLog( program );
  17211. var vertexLog = gl.getShaderInfoLog( glVertexShader );
  17212. var fragmentLog = gl.getShaderInfoLog( glFragmentShader );
  17213. var runnable = true;
  17214. var haveDiagnostics = true;
  17215. // console.log( '**VERTEX**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( glVertexShader ) );
  17216. // console.log( '**FRAGMENT**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( glFragmentShader ) );
  17217. if ( gl.getProgramParameter( program, gl.LINK_STATUS ) === false ) {
  17218. runnable = false;
  17219. console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), 'gl.VALIDATE_STATUS', gl.getProgramParameter( program, gl.VALIDATE_STATUS ), 'gl.getProgramInfoLog', programLog, vertexLog, fragmentLog );
  17220. } else if ( programLog !== '' ) {
  17221. console.warn( 'THREE.WebGLProgram: gl.getProgramInfoLog()', programLog );
  17222. } else if ( vertexLog === '' || fragmentLog === '' ) {
  17223. haveDiagnostics = false;
  17224. }
  17225. if ( haveDiagnostics ) {
  17226. this.diagnostics = {
  17227. runnable: runnable,
  17228. material: material,
  17229. programLog: programLog,
  17230. vertexShader: {
  17231. log: vertexLog,
  17232. prefix: prefixVertex
  17233. },
  17234. fragmentShader: {
  17235. log: fragmentLog,
  17236. prefix: prefixFragment
  17237. }
  17238. };
  17239. }
  17240. // clean up
  17241. gl.deleteShader( glVertexShader );
  17242. gl.deleteShader( glFragmentShader );
  17243. // set up caching for uniform locations
  17244. var cachedUniforms;
  17245. this.getUniforms = function() {
  17246. if ( cachedUniforms === undefined ) {
  17247. cachedUniforms =
  17248. new THREE.WebGLUniforms( gl, program, renderer );
  17249. }
  17250. return cachedUniforms;
  17251. };
  17252. // set up caching for attribute locations
  17253. var cachedAttributes;
  17254. this.getAttributes = function() {
  17255. if ( cachedAttributes === undefined ) {
  17256. cachedAttributes = fetchAttributeLocations( gl, program );
  17257. }
  17258. return cachedAttributes;
  17259. };
  17260. // free resource
  17261. this.destroy = function() {
  17262. gl.deleteProgram( program );
  17263. this.program = undefined;
  17264. };
  17265. // DEPRECATED
  17266. Object.defineProperties( this, {
  17267. uniforms: {
  17268. get: function() {
  17269. console.warn( 'THREE.WebGLProgram: .uniforms is now .getUniforms().' );
  17270. return this.getUniforms();
  17271. }
  17272. },
  17273. attributes: {
  17274. get: function() {
  17275. console.warn( 'THREE.WebGLProgram: .attributes is now .getAttributes().' );
  17276. return this.getAttributes();
  17277. }
  17278. }
  17279. } );
  17280. //
  17281. this.id = programIdCount ++;
  17282. this.code = code;
  17283. this.usedTimes = 1;
  17284. this.program = program;
  17285. this.vertexShader = glVertexShader;
  17286. this.fragmentShader = glFragmentShader;
  17287. return this;
  17288. };
  17289. } )();
  17290. // File:src/renderers/webgl/WebGLPrograms.js
  17291. THREE.WebGLPrograms = function ( renderer, capabilities ) {
  17292. var programs = [];
  17293. var shaderIDs = {
  17294. MeshDepthMaterial: 'depth',
  17295. MeshNormalMaterial: 'normal',
  17296. MeshBasicMaterial: 'basic',
  17297. MeshLambertMaterial: 'lambert',
  17298. MeshPhongMaterial: 'phong',
  17299. MeshStandardMaterial: 'physical',
  17300. MeshPhysicalMaterial: 'physical',
  17301. LineBasicMaterial: 'basic',
  17302. LineDashedMaterial: 'dashed',
  17303. PointsMaterial: 'points'
  17304. };
  17305. var parameterNames = [
  17306. "precision", "supportsVertexTextures", "map", "mapEncoding", "envMap", "envMapMode", "envMapEncoding",
  17307. "lightMap", "aoMap", "emissiveMap", "emissiveMapEncoding", "bumpMap", "normalMap", "displacementMap", "specularMap",
  17308. "roughnessMap", "metalnessMap",
  17309. "alphaMap", "combine", "vertexColors", "fog", "useFog", "fogExp",
  17310. "flatShading", "sizeAttenuation", "logarithmicDepthBuffer", "skinning",
  17311. "maxBones", "useVertexTexture", "morphTargets", "morphNormals",
  17312. "maxMorphTargets", "maxMorphNormals", "premultipliedAlpha",
  17313. "numDirLights", "numPointLights", "numSpotLights", "numHemiLights",
  17314. "shadowMapEnabled", "shadowMapType", "toneMapping", 'physicallyCorrectLights',
  17315. "alphaTest", "doubleSided", "flipSided", "numClippingPlanes", "depthPacking"
  17316. ];
  17317. function allocateBones ( object ) {
  17318. if ( capabilities.floatVertexTextures && object && object.skeleton && object.skeleton.useVertexTexture ) {
  17319. return 1024;
  17320. } else {
  17321. // default for when object is not specified
  17322. // ( for example when prebuilding shader to be used with multiple objects )
  17323. //
  17324. // - leave some extra space for other uniforms
  17325. // - limit here is ANGLE's 254 max uniform vectors
  17326. // (up to 54 should be safe)
  17327. var nVertexUniforms = capabilities.maxVertexUniforms;
  17328. var nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 );
  17329. var maxBones = nVertexMatrices;
  17330. if ( object !== undefined && object instanceof THREE.SkinnedMesh ) {
  17331. maxBones = Math.min( object.skeleton.bones.length, maxBones );
  17332. if ( maxBones < object.skeleton.bones.length ) {
  17333. console.warn( 'WebGLRenderer: too many bones - ' + object.skeleton.bones.length + ', this GPU supports just ' + maxBones + ' (try OpenGL instead of ANGLE)' );
  17334. }
  17335. }
  17336. return maxBones;
  17337. }
  17338. }
  17339. function getTextureEncodingFromMap( map, gammaOverrideLinear ) {
  17340. var encoding;
  17341. if ( ! map ) {
  17342. encoding = THREE.LinearEncoding;
  17343. } else if ( map instanceof THREE.Texture ) {
  17344. encoding = map.encoding;
  17345. } else if ( map instanceof THREE.WebGLRenderTarget ) {
  17346. console.warn( "THREE.WebGLPrograms.getTextureEncodingFromMap: don't use render targets as textures. Use their .texture property instead." );
  17347. encoding = map.texture.encoding;
  17348. }
  17349. // add backwards compatibility for WebGLRenderer.gammaInput/gammaOutput parameter, should probably be removed at some point.
  17350. if ( encoding === THREE.LinearEncoding && gammaOverrideLinear ) {
  17351. encoding = THREE.GammaEncoding;
  17352. }
  17353. return encoding;
  17354. }
  17355. this.getParameters = function ( material, lights, fog, nClipPlanes, object ) {
  17356. var shaderID = shaderIDs[ material.type ];
  17357. // heuristics to create shader parameters according to lights in the scene
  17358. // (not to blow over maxLights budget)
  17359. var maxBones = allocateBones( object );
  17360. var precision = renderer.getPrecision();
  17361. if ( material.precision !== null ) {
  17362. precision = capabilities.getMaxPrecision( material.precision );
  17363. if ( precision !== material.precision ) {
  17364. console.warn( 'THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.' );
  17365. }
  17366. }
  17367. var currentRenderTarget = renderer.getCurrentRenderTarget();
  17368. var parameters = {
  17369. shaderID: shaderID,
  17370. precision: precision,
  17371. supportsVertexTextures: capabilities.vertexTextures,
  17372. outputEncoding: getTextureEncodingFromMap( ( ! currentRenderTarget ) ? null : currentRenderTarget.texture, renderer.gammaOutput ),
  17373. map: !! material.map,
  17374. mapEncoding: getTextureEncodingFromMap( material.map, renderer.gammaInput ),
  17375. envMap: !! material.envMap,
  17376. envMapMode: material.envMap && material.envMap.mapping,
  17377. envMapEncoding: getTextureEncodingFromMap( material.envMap, renderer.gammaInput ),
  17378. envMapCubeUV: ( !! material.envMap ) && ( ( material.envMap.mapping === THREE.CubeUVReflectionMapping ) || ( material.envMap.mapping === THREE.CubeUVRefractionMapping ) ),
  17379. lightMap: !! material.lightMap,
  17380. aoMap: !! material.aoMap,
  17381. emissiveMap: !! material.emissiveMap,
  17382. emissiveMapEncoding: getTextureEncodingFromMap( material.emissiveMap, renderer.gammaInput ),
  17383. bumpMap: !! material.bumpMap,
  17384. normalMap: !! material.normalMap,
  17385. displacementMap: !! material.displacementMap,
  17386. roughnessMap: !! material.roughnessMap,
  17387. metalnessMap: !! material.metalnessMap,
  17388. specularMap: !! material.specularMap,
  17389. alphaMap: !! material.alphaMap,
  17390. combine: material.combine,
  17391. vertexColors: material.vertexColors,
  17392. fog: !! fog,
  17393. useFog: material.fog,
  17394. fogExp: fog instanceof THREE.FogExp2,
  17395. flatShading: material.shading === THREE.FlatShading,
  17396. sizeAttenuation: material.sizeAttenuation,
  17397. logarithmicDepthBuffer: capabilities.logarithmicDepthBuffer,
  17398. skinning: material.skinning,
  17399. maxBones: maxBones,
  17400. useVertexTexture: capabilities.floatVertexTextures && object && object.skeleton && object.skeleton.useVertexTexture,
  17401. morphTargets: material.morphTargets,
  17402. morphNormals: material.morphNormals,
  17403. maxMorphTargets: renderer.maxMorphTargets,
  17404. maxMorphNormals: renderer.maxMorphNormals,
  17405. numDirLights: lights.directional.length,
  17406. numPointLights: lights.point.length,
  17407. numSpotLights: lights.spot.length,
  17408. numHemiLights: lights.hemi.length,
  17409. numClippingPlanes: nClipPlanes,
  17410. shadowMapEnabled: renderer.shadowMap.enabled && object.receiveShadow && lights.shadows.length > 0,
  17411. shadowMapType: renderer.shadowMap.type,
  17412. toneMapping: renderer.toneMapping,
  17413. physicallyCorrectLights: renderer.physicallyCorrectLights,
  17414. premultipliedAlpha: material.premultipliedAlpha,
  17415. alphaTest: material.alphaTest,
  17416. doubleSided: material.side === THREE.DoubleSide,
  17417. flipSided: material.side === THREE.BackSide,
  17418. depthPacking: ( material.depthPacking !== undefined ) ? material.depthPacking : false
  17419. };
  17420. return parameters;
  17421. };
  17422. this.getProgramCode = function ( material, parameters ) {
  17423. var array = [];
  17424. if ( parameters.shaderID ) {
  17425. array.push( parameters.shaderID );
  17426. } else {
  17427. array.push( material.fragmentShader );
  17428. array.push( material.vertexShader );
  17429. }
  17430. if ( material.defines !== undefined ) {
  17431. for ( var name in material.defines ) {
  17432. array.push( name );
  17433. array.push( material.defines[ name ] );
  17434. }
  17435. }
  17436. for ( var i = 0; i < parameterNames.length; i ++ ) {
  17437. array.push( parameters[ parameterNames[ i ] ] );
  17438. }
  17439. return array.join();
  17440. };
  17441. this.acquireProgram = function ( material, parameters, code ) {
  17442. var program;
  17443. // Check if code has been already compiled
  17444. for ( var p = 0, pl = programs.length; p < pl; p ++ ) {
  17445. var programInfo = programs[ p ];
  17446. if ( programInfo.code === code ) {
  17447. program = programInfo;
  17448. ++ program.usedTimes;
  17449. break;
  17450. }
  17451. }
  17452. if ( program === undefined ) {
  17453. program = new THREE.WebGLProgram( renderer, code, material, parameters );
  17454. programs.push( program );
  17455. }
  17456. return program;
  17457. };
  17458. this.releaseProgram = function( program ) {
  17459. if ( -- program.usedTimes === 0 ) {
  17460. // Remove from unordered set
  17461. var i = programs.indexOf( program );
  17462. programs[ i ] = programs[ programs.length - 1 ];
  17463. programs.pop();
  17464. // Free WebGL resources
  17465. program.destroy();
  17466. }
  17467. };
  17468. // Exposed for resource monitoring & error feedback via renderer.info:
  17469. this.programs = programs;
  17470. };
  17471. // File:src/renderers/webgl/WebGLProperties.js
  17472. /**
  17473. * @author fordacious / fordacious.github.io
  17474. */
  17475. THREE.WebGLProperties = function () {
  17476. var properties = {};
  17477. this.get = function ( object ) {
  17478. var uuid = object.uuid;
  17479. var map = properties[ uuid ];
  17480. if ( map === undefined ) {
  17481. map = {};
  17482. properties[ uuid ] = map;
  17483. }
  17484. return map;
  17485. };
  17486. this.delete = function ( object ) {
  17487. delete properties[ object.uuid ];
  17488. };
  17489. this.clear = function () {
  17490. properties = {};
  17491. };
  17492. };
  17493. // File:src/renderers/webgl/WebGLShader.js
  17494. THREE.WebGLShader = ( function () {
  17495. function addLineNumbers( string ) {
  17496. var lines = string.split( '\n' );
  17497. for ( var i = 0; i < lines.length; i ++ ) {
  17498. lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
  17499. }
  17500. return lines.join( '\n' );
  17501. }
  17502. return function WebGLShader( gl, type, string ) {
  17503. var shader = gl.createShader( type );
  17504. gl.shaderSource( shader, string );
  17505. gl.compileShader( shader );
  17506. if ( gl.getShaderParameter( shader, gl.COMPILE_STATUS ) === false ) {
  17507. console.error( 'THREE.WebGLShader: Shader couldn\'t compile.' );
  17508. }
  17509. if ( gl.getShaderInfoLog( shader ) !== '' ) {
  17510. console.warn( 'THREE.WebGLShader: gl.getShaderInfoLog()', type === gl.VERTEX_SHADER ? 'vertex' : 'fragment', gl.getShaderInfoLog( shader ), addLineNumbers( string ) );
  17511. }
  17512. // --enable-privileged-webgl-extension
  17513. // console.log( type, gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  17514. return shader;
  17515. };
  17516. } )();
  17517. // File:src/renderers/webgl/WebGLShadowMap.js
  17518. /**
  17519. * @author alteredq / http://alteredqualia.com/
  17520. * @author mrdoob / http://mrdoob.com/
  17521. */
  17522. THREE.WebGLShadowMap = function ( _renderer, _lights, _objects, capabilities ) {
  17523. var _gl = _renderer.context,
  17524. _state = _renderer.state,
  17525. _frustum = new THREE.Frustum(),
  17526. _projScreenMatrix = new THREE.Matrix4(),
  17527. _lightShadows = _lights.shadows,
  17528. _shadowMapSize = new THREE.Vector2(),
  17529. _maxShadowMapSize = new THREE.Vector2( capabilities.maxTextureSize, capabilities.maxTextureSize ),
  17530. _lookTarget = new THREE.Vector3(),
  17531. _lightPositionWorld = new THREE.Vector3(),
  17532. _renderList = [],
  17533. _MorphingFlag = 1,
  17534. _SkinningFlag = 2,
  17535. _NumberOfMaterialVariants = ( _MorphingFlag | _SkinningFlag ) + 1,
  17536. _depthMaterials = new Array( _NumberOfMaterialVariants ),
  17537. _distanceMaterials = new Array( _NumberOfMaterialVariants ),
  17538. _materialCache = {};
  17539. var cubeDirections = [
  17540. new THREE.Vector3( 1, 0, 0 ), new THREE.Vector3( - 1, 0, 0 ), new THREE.Vector3( 0, 0, 1 ),
  17541. new THREE.Vector3( 0, 0, - 1 ), new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, - 1, 0 )
  17542. ];
  17543. var cubeUps = [
  17544. new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 1, 0 ),
  17545. new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 0, 1 ), new THREE.Vector3( 0, 0, - 1 )
  17546. ];
  17547. var cube2DViewPorts = [
  17548. new THREE.Vector4(), new THREE.Vector4(), new THREE.Vector4(),
  17549. new THREE.Vector4(), new THREE.Vector4(), new THREE.Vector4()
  17550. ];
  17551. // init
  17552. var depthMaterialTemplate = new THREE.MeshDepthMaterial();
  17553. depthMaterialTemplate.depthPacking = THREE.RGBADepthPacking;
  17554. depthMaterialTemplate.clipping = true;
  17555. var distanceShader = THREE.ShaderLib[ "distanceRGBA" ];
  17556. var distanceUniforms = THREE.UniformsUtils.clone( distanceShader.uniforms );
  17557. for ( var i = 0; i !== _NumberOfMaterialVariants; ++ i ) {
  17558. var useMorphing = ( i & _MorphingFlag ) !== 0;
  17559. var useSkinning = ( i & _SkinningFlag ) !== 0;
  17560. var depthMaterial = depthMaterialTemplate.clone();
  17561. depthMaterial.morphTargets = useMorphing;
  17562. depthMaterial.skinning = useSkinning;
  17563. _depthMaterials[ i ] = depthMaterial;
  17564. var distanceMaterial = new THREE.ShaderMaterial( {
  17565. defines: {
  17566. 'USE_SHADOWMAP': ''
  17567. },
  17568. uniforms: distanceUniforms,
  17569. vertexShader: distanceShader.vertexShader,
  17570. fragmentShader: distanceShader.fragmentShader,
  17571. morphTargets: useMorphing,
  17572. skinning: useSkinning,
  17573. clipping: true
  17574. } );
  17575. _distanceMaterials[ i ] = distanceMaterial;
  17576. }
  17577. //
  17578. var scope = this;
  17579. this.enabled = false;
  17580. this.autoUpdate = true;
  17581. this.needsUpdate = false;
  17582. this.type = THREE.PCFShadowMap;
  17583. this.renderReverseSided = true;
  17584. this.renderSingleSided = true;
  17585. this.render = function ( scene, camera ) {
  17586. if ( scope.enabled === false ) return;
  17587. if ( scope.autoUpdate === false && scope.needsUpdate === false ) return;
  17588. if ( _lightShadows.length === 0 ) return;
  17589. // Set GL state for depth map.
  17590. _state.clearColor( 1, 1, 1, 1 );
  17591. _state.disable( _gl.BLEND );
  17592. _state.setDepthTest( true );
  17593. _state.setScissorTest( false );
  17594. // render depth map
  17595. var faceCount, isPointLight;
  17596. for ( var i = 0, il = _lightShadows.length; i < il; i ++ ) {
  17597. var light = _lightShadows[ i ];
  17598. var shadow = light.shadow;
  17599. if ( shadow === undefined ) {
  17600. console.warn( 'THREE.WebGLShadowMap:', light, 'has no shadow.' );
  17601. continue;
  17602. }
  17603. var shadowCamera = shadow.camera;
  17604. _shadowMapSize.copy( shadow.mapSize );
  17605. _shadowMapSize.min( _maxShadowMapSize );
  17606. if ( light instanceof THREE.PointLight ) {
  17607. faceCount = 6;
  17608. isPointLight = true;
  17609. var vpWidth = _shadowMapSize.x;
  17610. var vpHeight = _shadowMapSize.y;
  17611. // These viewports map a cube-map onto a 2D texture with the
  17612. // following orientation:
  17613. //
  17614. // xzXZ
  17615. // y Y
  17616. //
  17617. // X - Positive x direction
  17618. // x - Negative x direction
  17619. // Y - Positive y direction
  17620. // y - Negative y direction
  17621. // Z - Positive z direction
  17622. // z - Negative z direction
  17623. // positive X
  17624. cube2DViewPorts[ 0 ].set( vpWidth * 2, vpHeight, vpWidth, vpHeight );
  17625. // negative X
  17626. cube2DViewPorts[ 1 ].set( 0, vpHeight, vpWidth, vpHeight );
  17627. // positive Z
  17628. cube2DViewPorts[ 2 ].set( vpWidth * 3, vpHeight, vpWidth, vpHeight );
  17629. // negative Z
  17630. cube2DViewPorts[ 3 ].set( vpWidth, vpHeight, vpWidth, vpHeight );
  17631. // positive Y
  17632. cube2DViewPorts[ 4 ].set( vpWidth * 3, 0, vpWidth, vpHeight );
  17633. // negative Y
  17634. cube2DViewPorts[ 5 ].set( vpWidth, 0, vpWidth, vpHeight );
  17635. _shadowMapSize.x *= 4.0;
  17636. _shadowMapSize.y *= 2.0;
  17637. } else {
  17638. faceCount = 1;
  17639. isPointLight = false;
  17640. }
  17641. if ( shadow.map === null ) {
  17642. var pars = { minFilter: THREE.NearestFilter, magFilter: THREE.NearestFilter, format: THREE.RGBAFormat };
  17643. shadow.map = new THREE.WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
  17644. shadowCamera.updateProjectionMatrix();
  17645. }
  17646. if ( shadow instanceof THREE.SpotLightShadow ) {
  17647. shadow.update( light );
  17648. }
  17649. var shadowMap = shadow.map;
  17650. var shadowMatrix = shadow.matrix;
  17651. _lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  17652. shadowCamera.position.copy( _lightPositionWorld );
  17653. _renderer.setRenderTarget( shadowMap );
  17654. _renderer.clear();
  17655. // render shadow map for each cube face (if omni-directional) or
  17656. // run a single pass if not
  17657. for ( var face = 0; face < faceCount; face ++ ) {
  17658. if ( isPointLight ) {
  17659. _lookTarget.copy( shadowCamera.position );
  17660. _lookTarget.add( cubeDirections[ face ] );
  17661. shadowCamera.up.copy( cubeUps[ face ] );
  17662. shadowCamera.lookAt( _lookTarget );
  17663. var vpDimensions = cube2DViewPorts[ face ];
  17664. _state.viewport( vpDimensions );
  17665. } else {
  17666. _lookTarget.setFromMatrixPosition( light.target.matrixWorld );
  17667. shadowCamera.lookAt( _lookTarget );
  17668. }
  17669. shadowCamera.updateMatrixWorld();
  17670. shadowCamera.matrixWorldInverse.getInverse( shadowCamera.matrixWorld );
  17671. // compute shadow matrix
  17672. shadowMatrix.set(
  17673. 0.5, 0.0, 0.0, 0.5,
  17674. 0.0, 0.5, 0.0, 0.5,
  17675. 0.0, 0.0, 0.5, 0.5,
  17676. 0.0, 0.0, 0.0, 1.0
  17677. );
  17678. shadowMatrix.multiply( shadowCamera.projectionMatrix );
  17679. shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
  17680. // update camera matrices and frustum
  17681. _projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  17682. _frustum.setFromMatrix( _projScreenMatrix );
  17683. // set object matrices & frustum culling
  17684. _renderList.length = 0;
  17685. projectObject( scene, camera, shadowCamera );
  17686. // render shadow map
  17687. // render regular objects
  17688. for ( var j = 0, jl = _renderList.length; j < jl; j ++ ) {
  17689. var object = _renderList[ j ];
  17690. var geometry = _objects.update( object );
  17691. var material = object.material;
  17692. if ( material instanceof THREE.MultiMaterial ) {
  17693. var groups = geometry.groups;
  17694. var materials = material.materials;
  17695. for ( var k = 0, kl = groups.length; k < kl; k ++ ) {
  17696. var group = groups[ k ];
  17697. var groupMaterial = materials[ group.materialIndex ];
  17698. if ( groupMaterial.visible === true ) {
  17699. var depthMaterial = getDepthMaterial( object, groupMaterial, isPointLight, _lightPositionWorld );
  17700. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, group );
  17701. }
  17702. }
  17703. } else {
  17704. var depthMaterial = getDepthMaterial( object, material, isPointLight, _lightPositionWorld );
  17705. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, null );
  17706. }
  17707. }
  17708. }
  17709. }
  17710. // Restore GL state.
  17711. var clearColor = _renderer.getClearColor(),
  17712. clearAlpha = _renderer.getClearAlpha();
  17713. _renderer.setClearColor( clearColor, clearAlpha );
  17714. scope.needsUpdate = false;
  17715. };
  17716. function getDepthMaterial( object, material, isPointLight, lightPositionWorld ) {
  17717. var geometry = object.geometry;
  17718. var result = null;
  17719. var materialVariants = _depthMaterials;
  17720. var customMaterial = object.customDepthMaterial;
  17721. if ( isPointLight ) {
  17722. materialVariants = _distanceMaterials;
  17723. customMaterial = object.customDistanceMaterial;
  17724. }
  17725. if ( ! customMaterial ) {
  17726. var useMorphing = false;
  17727. if ( material.morphTargets ) {
  17728. if ( geometry instanceof THREE.BufferGeometry ) {
  17729. useMorphing = geometry.morphAttributes && geometry.morphAttributes.position && geometry.morphAttributes.position.length > 0;
  17730. } else if ( geometry instanceof THREE.Geometry ) {
  17731. useMorphing = geometry.morphTargets && geometry.morphTargets.length > 0;
  17732. }
  17733. }
  17734. var useSkinning = object instanceof THREE.SkinnedMesh && material.skinning;
  17735. var variantIndex = 0;
  17736. if ( useMorphing ) variantIndex |= _MorphingFlag;
  17737. if ( useSkinning ) variantIndex |= _SkinningFlag;
  17738. result = materialVariants[ variantIndex ];
  17739. } else {
  17740. result = customMaterial;
  17741. }
  17742. if ( _renderer.localClippingEnabled &&
  17743. material.clipShadows === true &&
  17744. material.clippingPlanes.length !== 0 ) {
  17745. // in this case we need a unique material instance reflecting the
  17746. // appropriate state
  17747. var keyA = result.uuid, keyB = material.uuid;
  17748. var materialsForVariant = _materialCache[ keyA ];
  17749. if ( materialsForVariant === undefined ) {
  17750. materialsForVariant = {};
  17751. _materialCache[ keyA ] = materialsForVariant;
  17752. }
  17753. var cachedMaterial = materialsForVariant[ keyB ];
  17754. if ( cachedMaterial === undefined ) {
  17755. cachedMaterial = result.clone();
  17756. materialsForVariant[ keyB ] = cachedMaterial;
  17757. }
  17758. result = cachedMaterial;
  17759. }
  17760. result.visible = material.visible;
  17761. result.wireframe = material.wireframe;
  17762. var side = material.side;
  17763. if ( scope.renderSingleSided && side == THREE.DoubleSide ) {
  17764. side = THREE.FrontSide;
  17765. }
  17766. if ( scope.renderReverseSided ) {
  17767. if ( side === THREE.FrontSide ) side = THREE.BackSide;
  17768. else if ( side === THREE.BackSide ) side = THREE.FrontSide;
  17769. }
  17770. result.side = side;
  17771. result.clipShadows = material.clipShadows;
  17772. result.clippingPlanes = material.clippingPlanes;
  17773. result.wireframeLinewidth = material.wireframeLinewidth;
  17774. result.linewidth = material.linewidth;
  17775. if ( isPointLight && result.uniforms.lightPos !== undefined ) {
  17776. result.uniforms.lightPos.value.copy( lightPositionWorld );
  17777. }
  17778. return result;
  17779. }
  17780. function projectObject( object, camera, shadowCamera ) {
  17781. if ( object.visible === false ) return;
  17782. if ( object.layers.test( camera.layers ) && ( object instanceof THREE.Mesh || object instanceof THREE.Line || object instanceof THREE.Points ) ) {
  17783. if ( object.castShadow && ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) ) {
  17784. var material = object.material;
  17785. if ( material.visible === true ) {
  17786. object.modelViewMatrix.multiplyMatrices( shadowCamera.matrixWorldInverse, object.matrixWorld );
  17787. _renderList.push( object );
  17788. }
  17789. }
  17790. }
  17791. var children = object.children;
  17792. for ( var i = 0, l = children.length; i < l; i ++ ) {
  17793. projectObject( children[ i ], camera, shadowCamera );
  17794. }
  17795. }
  17796. };
  17797. // File:src/renderers/webgl/WebGLState.js
  17798. /**
  17799. * @author mrdoob / http://mrdoob.com/
  17800. */
  17801. THREE.WebGLState = function ( gl, extensions, paramThreeToGL ) {
  17802. var _this = this;
  17803. this.buffers = {
  17804. color: new THREE.WebGLColorBuffer( gl, this ),
  17805. depth: new THREE.WebGLDepthBuffer( gl, this ),
  17806. stencil: new THREE.WebGLStencilBuffer( gl, this )
  17807. };
  17808. var maxVertexAttributes = gl.getParameter( gl.MAX_VERTEX_ATTRIBS );
  17809. var newAttributes = new Uint8Array( maxVertexAttributes );
  17810. var enabledAttributes = new Uint8Array( maxVertexAttributes );
  17811. var attributeDivisors = new Uint8Array( maxVertexAttributes );
  17812. var capabilities = {};
  17813. var compressedTextureFormats = null;
  17814. var currentBlending = null;
  17815. var currentBlendEquation = null;
  17816. var currentBlendSrc = null;
  17817. var currentBlendDst = null;
  17818. var currentBlendEquationAlpha = null;
  17819. var currentBlendSrcAlpha = null;
  17820. var currentBlendDstAlpha = null;
  17821. var currentPremultipledAlpha = false;
  17822. var currentFlipSided = null;
  17823. var currentCullFace = null;
  17824. var currentLineWidth = null;
  17825. var currentPolygonOffsetFactor = null;
  17826. var currentPolygonOffsetUnits = null;
  17827. var currentScissorTest = null;
  17828. var maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
  17829. var currentTextureSlot = null;
  17830. var currentBoundTextures = {};
  17831. var currentScissor = new THREE.Vector4();
  17832. var currentViewport = new THREE.Vector4();
  17833. function createTexture( type, target, count ) {
  17834. var data = new Uint8Array( 4 ); // 4 is required to match default unpack alignment of 4.
  17835. var texture = gl.createTexture();
  17836. gl.bindTexture( type, texture );
  17837. gl.texParameteri( type, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  17838. gl.texParameteri( type, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  17839. for ( var i = 0; i < count; i ++ ) {
  17840. gl.texImage2D( target + i, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, data );
  17841. }
  17842. return texture;
  17843. }
  17844. var emptyTextures = {};
  17845. emptyTextures[ gl.TEXTURE_2D ] = createTexture( gl.TEXTURE_2D, gl.TEXTURE_2D, 1 );
  17846. emptyTextures[ gl.TEXTURE_CUBE_MAP ] = createTexture( gl.TEXTURE_CUBE_MAP, gl.TEXTURE_CUBE_MAP_POSITIVE_X, 6 );
  17847. //
  17848. this.init = function () {
  17849. this.clearColor( 0, 0, 0, 1 );
  17850. this.clearDepth( 1 );
  17851. this.clearStencil( 0 );
  17852. this.enable( gl.DEPTH_TEST );
  17853. this.setDepthFunc( THREE.LessEqualDepth );
  17854. this.setFlipSided( false );
  17855. this.setCullFace( THREE.CullFaceBack );
  17856. this.enable( gl.CULL_FACE );
  17857. this.enable( gl.BLEND );
  17858. this.setBlending( THREE.NormalBlending );
  17859. };
  17860. this.initAttributes = function () {
  17861. for ( var i = 0, l = newAttributes.length; i < l; i ++ ) {
  17862. newAttributes[ i ] = 0;
  17863. }
  17864. };
  17865. this.enableAttribute = function ( attribute ) {
  17866. newAttributes[ attribute ] = 1;
  17867. if ( enabledAttributes[ attribute ] === 0 ) {
  17868. gl.enableVertexAttribArray( attribute );
  17869. enabledAttributes[ attribute ] = 1;
  17870. }
  17871. if ( attributeDivisors[ attribute ] !== 0 ) {
  17872. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  17873. extension.vertexAttribDivisorANGLE( attribute, 0 );
  17874. attributeDivisors[ attribute ] = 0;
  17875. }
  17876. };
  17877. this.enableAttributeAndDivisor = function ( attribute, meshPerAttribute, extension ) {
  17878. newAttributes[ attribute ] = 1;
  17879. if ( enabledAttributes[ attribute ] === 0 ) {
  17880. gl.enableVertexAttribArray( attribute );
  17881. enabledAttributes[ attribute ] = 1;
  17882. }
  17883. if ( attributeDivisors[ attribute ] !== meshPerAttribute ) {
  17884. extension.vertexAttribDivisorANGLE( attribute, meshPerAttribute );
  17885. attributeDivisors[ attribute ] = meshPerAttribute;
  17886. }
  17887. };
  17888. this.disableUnusedAttributes = function () {
  17889. for ( var i = 0, l = enabledAttributes.length; i !== l; ++ i ) {
  17890. if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
  17891. gl.disableVertexAttribArray( i );
  17892. enabledAttributes[ i ] = 0;
  17893. }
  17894. }
  17895. };
  17896. this.enable = function ( id ) {
  17897. if ( capabilities[ id ] !== true ) {
  17898. gl.enable( id );
  17899. capabilities[ id ] = true;
  17900. }
  17901. };
  17902. this.disable = function ( id ) {
  17903. if ( capabilities[ id ] !== false ) {
  17904. gl.disable( id );
  17905. capabilities[ id ] = false;
  17906. }
  17907. };
  17908. this.getCompressedTextureFormats = function () {
  17909. if ( compressedTextureFormats === null ) {
  17910. compressedTextureFormats = [];
  17911. if ( extensions.get( 'WEBGL_compressed_texture_pvrtc' ) ||
  17912. extensions.get( 'WEBGL_compressed_texture_s3tc' ) ||
  17913. extensions.get( 'WEBGL_compressed_texture_etc1' ) ) {
  17914. var formats = gl.getParameter( gl.COMPRESSED_TEXTURE_FORMATS );
  17915. for ( var i = 0; i < formats.length; i ++ ) {
  17916. compressedTextureFormats.push( formats[ i ] );
  17917. }
  17918. }
  17919. }
  17920. return compressedTextureFormats;
  17921. };
  17922. this.setBlending = function ( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha ) {
  17923. if ( blending !== THREE.NoBlending ) {
  17924. this.enable( gl.BLEND );
  17925. } else {
  17926. this.disable( gl.BLEND );
  17927. currentBlending = blending; // no blending, that is
  17928. return;
  17929. }
  17930. if ( blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha ) {
  17931. if ( blending === THREE.AdditiveBlending ) {
  17932. if ( premultipliedAlpha ) {
  17933. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  17934. gl.blendFuncSeparate( gl.ONE, gl.ONE, gl.ONE, gl.ONE );
  17935. } else {
  17936. gl.blendEquation( gl.FUNC_ADD );
  17937. gl.blendFunc( gl.SRC_ALPHA, gl.ONE );
  17938. }
  17939. } else if ( blending === THREE.SubtractiveBlending ) {
  17940. if ( premultipliedAlpha ) {
  17941. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  17942. gl.blendFuncSeparate( gl.ZERO, gl.ZERO, gl.ONE_MINUS_SRC_COLOR, gl.ONE_MINUS_SRC_ALPHA );
  17943. } else {
  17944. gl.blendEquation( gl.FUNC_ADD );
  17945. gl.blendFunc( gl.ZERO, gl.ONE_MINUS_SRC_COLOR );
  17946. }
  17947. } else if ( blending === THREE.MultiplyBlending ) {
  17948. if ( premultipliedAlpha ) {
  17949. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  17950. gl.blendFuncSeparate( gl.ZERO, gl.SRC_COLOR, gl.ZERO, gl.SRC_ALPHA );
  17951. } else {
  17952. gl.blendEquation( gl.FUNC_ADD );
  17953. gl.blendFunc( gl.ZERO, gl.SRC_COLOR );
  17954. }
  17955. } else {
  17956. if ( premultipliedAlpha ) {
  17957. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  17958. gl.blendFuncSeparate( gl.ONE, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
  17959. } else {
  17960. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  17961. gl.blendFuncSeparate( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
  17962. }
  17963. }
  17964. currentBlending = blending;
  17965. currentPremultipledAlpha = premultipliedAlpha;
  17966. }
  17967. if ( blending === THREE.CustomBlending ) {
  17968. blendEquationAlpha = blendEquationAlpha || blendEquation;
  17969. blendSrcAlpha = blendSrcAlpha || blendSrc;
  17970. blendDstAlpha = blendDstAlpha || blendDst;
  17971. if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
  17972. gl.blendEquationSeparate( paramThreeToGL( blendEquation ), paramThreeToGL( blendEquationAlpha ) );
  17973. currentBlendEquation = blendEquation;
  17974. currentBlendEquationAlpha = blendEquationAlpha;
  17975. }
  17976. if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
  17977. gl.blendFuncSeparate( paramThreeToGL( blendSrc ), paramThreeToGL( blendDst ), paramThreeToGL( blendSrcAlpha ), paramThreeToGL( blendDstAlpha ) );
  17978. currentBlendSrc = blendSrc;
  17979. currentBlendDst = blendDst;
  17980. currentBlendSrcAlpha = blendSrcAlpha;
  17981. currentBlendDstAlpha = blendDstAlpha;
  17982. }
  17983. } else {
  17984. currentBlendEquation = null;
  17985. currentBlendSrc = null;
  17986. currentBlendDst = null;
  17987. currentBlendEquationAlpha = null;
  17988. currentBlendSrcAlpha = null;
  17989. currentBlendDstAlpha = null;
  17990. }
  17991. };
  17992. // TODO Deprecate
  17993. this.setColorWrite = function ( colorWrite ) {
  17994. this.buffers.color.setMask( colorWrite );
  17995. };
  17996. this.setDepthTest = function ( depthTest ) {
  17997. this.buffers.depth.setTest( depthTest );
  17998. };
  17999. this.setDepthWrite = function ( depthWrite ) {
  18000. this.buffers.depth.setMask( depthWrite );
  18001. };
  18002. this.setDepthFunc = function ( depthFunc ) {
  18003. this.buffers.depth.setFunc( depthFunc );
  18004. };
  18005. this.setStencilTest = function ( stencilTest ) {
  18006. this.buffers.stencil.setTest( stencilTest );
  18007. };
  18008. this.setStencilWrite = function ( stencilWrite ) {
  18009. this.buffers.stencil.setMask( stencilWrite );
  18010. };
  18011. this.setStencilFunc = function ( stencilFunc, stencilRef, stencilMask ) {
  18012. this.buffers.stencil.setFunc( stencilFunc, stencilRef, stencilMask );
  18013. };
  18014. this.setStencilOp = function ( stencilFail, stencilZFail, stencilZPass ) {
  18015. this.buffers.stencil.setOp( stencilFail, stencilZFail, stencilZPass );
  18016. };
  18017. //
  18018. this.setFlipSided = function ( flipSided ) {
  18019. if ( currentFlipSided !== flipSided ) {
  18020. if ( flipSided ) {
  18021. gl.frontFace( gl.CW );
  18022. } else {
  18023. gl.frontFace( gl.CCW );
  18024. }
  18025. currentFlipSided = flipSided;
  18026. }
  18027. };
  18028. this.setCullFace = function ( cullFace ) {
  18029. if ( cullFace !== THREE.CullFaceNone ) {
  18030. this.enable( gl.CULL_FACE );
  18031. if ( cullFace !== currentCullFace ) {
  18032. if ( cullFace === THREE.CullFaceBack ) {
  18033. gl.cullFace( gl.BACK );
  18034. } else if ( cullFace === THREE.CullFaceFront ) {
  18035. gl.cullFace( gl.FRONT );
  18036. } else {
  18037. gl.cullFace( gl.FRONT_AND_BACK );
  18038. }
  18039. }
  18040. } else {
  18041. this.disable( gl.CULL_FACE );
  18042. }
  18043. currentCullFace = cullFace;
  18044. };
  18045. this.setLineWidth = function ( width ) {
  18046. if ( width !== currentLineWidth ) {
  18047. gl.lineWidth( width );
  18048. currentLineWidth = width;
  18049. }
  18050. };
  18051. this.setPolygonOffset = function ( polygonOffset, factor, units ) {
  18052. if ( polygonOffset ) {
  18053. this.enable( gl.POLYGON_OFFSET_FILL );
  18054. if ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) {
  18055. gl.polygonOffset( factor, units );
  18056. currentPolygonOffsetFactor = factor;
  18057. currentPolygonOffsetUnits = units;
  18058. }
  18059. } else {
  18060. this.disable( gl.POLYGON_OFFSET_FILL );
  18061. }
  18062. };
  18063. this.getScissorTest = function () {
  18064. return currentScissorTest;
  18065. };
  18066. this.setScissorTest = function ( scissorTest ) {
  18067. currentScissorTest = scissorTest;
  18068. if ( scissorTest ) {
  18069. this.enable( gl.SCISSOR_TEST );
  18070. } else {
  18071. this.disable( gl.SCISSOR_TEST );
  18072. }
  18073. };
  18074. // texture
  18075. this.activeTexture = function ( webglSlot ) {
  18076. if ( webglSlot === undefined ) webglSlot = gl.TEXTURE0 + maxTextures - 1;
  18077. if ( currentTextureSlot !== webglSlot ) {
  18078. gl.activeTexture( webglSlot );
  18079. currentTextureSlot = webglSlot;
  18080. }
  18081. };
  18082. this.bindTexture = function ( webglType, webglTexture ) {
  18083. if ( currentTextureSlot === null ) {
  18084. _this.activeTexture();
  18085. }
  18086. var boundTexture = currentBoundTextures[ currentTextureSlot ];
  18087. if ( boundTexture === undefined ) {
  18088. boundTexture = { type: undefined, texture: undefined };
  18089. currentBoundTextures[ currentTextureSlot ] = boundTexture;
  18090. }
  18091. if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
  18092. gl.bindTexture( webglType, webglTexture || emptyTextures[ webglType ] );
  18093. boundTexture.type = webglType;
  18094. boundTexture.texture = webglTexture;
  18095. }
  18096. };
  18097. this.compressedTexImage2D = function () {
  18098. try {
  18099. gl.compressedTexImage2D.apply( gl, arguments );
  18100. } catch ( error ) {
  18101. console.error( error );
  18102. }
  18103. };
  18104. this.texImage2D = function () {
  18105. try {
  18106. gl.texImage2D.apply( gl, arguments );
  18107. } catch ( error ) {
  18108. console.error( error );
  18109. }
  18110. };
  18111. // TODO Deprecate
  18112. this.clearColor = function ( r, g, b, a ) {
  18113. this.buffers.color.setClear( r, g, b, a );
  18114. };
  18115. this.clearDepth = function ( depth ) {
  18116. this.buffers.depth.setClear( depth );
  18117. };
  18118. this.clearStencil = function ( stencil ) {
  18119. this.buffers.stencil.setClear( stencil );
  18120. };
  18121. //
  18122. this.scissor = function ( scissor ) {
  18123. if ( currentScissor.equals( scissor ) === false ) {
  18124. gl.scissor( scissor.x, scissor.y, scissor.z, scissor.w );
  18125. currentScissor.copy( scissor );
  18126. }
  18127. };
  18128. this.viewport = function ( viewport ) {
  18129. if ( currentViewport.equals( viewport ) === false ) {
  18130. gl.viewport( viewport.x, viewport.y, viewport.z, viewport.w );
  18131. currentViewport.copy( viewport );
  18132. }
  18133. };
  18134. //
  18135. this.reset = function () {
  18136. for ( var i = 0; i < enabledAttributes.length; i ++ ) {
  18137. if ( enabledAttributes[ i ] === 1 ) {
  18138. gl.disableVertexAttribArray( i );
  18139. enabledAttributes[ i ] = 0;
  18140. }
  18141. }
  18142. capabilities = {};
  18143. compressedTextureFormats = null;
  18144. currentTextureSlot = null;
  18145. currentBoundTextures = {};
  18146. currentBlending = null;
  18147. currentFlipSided = null;
  18148. currentCullFace = null;
  18149. this.buffers.color.reset();
  18150. this.buffers.depth.reset();
  18151. this.buffers.stencil.reset();
  18152. };
  18153. };
  18154. THREE.WebGLColorBuffer = function ( gl, state ) {
  18155. var locked = false;
  18156. var color = new THREE.Vector4();
  18157. var currentColorMask = null;
  18158. var currentColorClear = new THREE.Vector4();
  18159. this.setMask = function ( colorMask ) {
  18160. if ( currentColorMask !== colorMask && ! locked ) {
  18161. gl.colorMask( colorMask, colorMask, colorMask, colorMask );
  18162. currentColorMask = colorMask;
  18163. }
  18164. };
  18165. this.setLocked = function ( lock ) {
  18166. locked = lock;
  18167. };
  18168. this.setClear = function ( r, g, b, a ) {
  18169. color.set( r, g, b, a );
  18170. if ( currentColorClear.equals( color ) === false ) {
  18171. gl.clearColor( r, g, b, a );
  18172. currentColorClear.copy( color );
  18173. }
  18174. };
  18175. this.reset = function () {
  18176. locked = false;
  18177. currentColorMask = null;
  18178. currentColorClear = new THREE.Vector4();
  18179. };
  18180. };
  18181. THREE.WebGLDepthBuffer = function( gl, state ) {
  18182. var locked = false;
  18183. var currentDepthMask = null;
  18184. var currentDepthFunc = null;
  18185. var currentDepthClear = null;
  18186. this.setTest = function ( depthTest ) {
  18187. if ( depthTest ) {
  18188. state.enable( gl.DEPTH_TEST );
  18189. } else {
  18190. state.disable( gl.DEPTH_TEST );
  18191. }
  18192. };
  18193. this.setMask = function( depthMask ){
  18194. if ( currentDepthMask !== depthMask && ! locked ) {
  18195. gl.depthMask( depthMask );
  18196. currentDepthMask = depthMask;
  18197. }
  18198. };
  18199. this.setFunc = function ( depthFunc ) {
  18200. if ( currentDepthFunc !== depthFunc ) {
  18201. if ( depthFunc ) {
  18202. switch ( depthFunc ) {
  18203. case THREE.NeverDepth:
  18204. gl.depthFunc( gl.NEVER );
  18205. break;
  18206. case THREE.AlwaysDepth:
  18207. gl.depthFunc( gl.ALWAYS );
  18208. break;
  18209. case THREE.LessDepth:
  18210. gl.depthFunc( gl.LESS );
  18211. break;
  18212. case THREE.LessEqualDepth:
  18213. gl.depthFunc( gl.LEQUAL );
  18214. break;
  18215. case THREE.EqualDepth:
  18216. gl.depthFunc( gl.EQUAL );
  18217. break;
  18218. case THREE.GreaterEqualDepth:
  18219. gl.depthFunc( gl.GEQUAL );
  18220. break;
  18221. case THREE.GreaterDepth:
  18222. gl.depthFunc( gl.GREATER );
  18223. break;
  18224. case THREE.NotEqualDepth:
  18225. gl.depthFunc( gl.NOTEQUAL );
  18226. break;
  18227. default:
  18228. gl.depthFunc( gl.LEQUAL );
  18229. }
  18230. } else {
  18231. gl.depthFunc( gl.LEQUAL );
  18232. }
  18233. currentDepthFunc = depthFunc;
  18234. }
  18235. };
  18236. this.setLocked = function ( lock ) {
  18237. locked = lock;
  18238. };
  18239. this.setClear = function ( depth ) {
  18240. if ( currentDepthClear !== depth ) {
  18241. gl.clearDepth( depth );
  18242. currentDepthClear = depth;
  18243. }
  18244. };
  18245. this.reset = function () {
  18246. locked = false;
  18247. currentDepthMask = null;
  18248. currentDepthFunc = null;
  18249. currentDepthClear = null;
  18250. };
  18251. };
  18252. THREE.WebGLStencilBuffer = function ( gl, state ) {
  18253. var locked = false;
  18254. var currentStencilMask = null;
  18255. var currentStencilFunc = null;
  18256. var currentStencilRef = null;
  18257. var currentStencilFuncMask = null;
  18258. var currentStencilFail = null;
  18259. var currentStencilZFail = null;
  18260. var currentStencilZPass = null;
  18261. var currentStencilClear = null;
  18262. this.setTest = function ( stencilTest ) {
  18263. if ( stencilTest ) {
  18264. state.enable( gl.STENCIL_TEST );
  18265. } else {
  18266. state.disable( gl.STENCIL_TEST );
  18267. }
  18268. };
  18269. this.setMask = function ( stencilMask ) {
  18270. if ( currentStencilMask !== stencilMask && ! locked ) {
  18271. gl.stencilMask( stencilMask );
  18272. currentStencilMask = stencilMask;
  18273. }
  18274. };
  18275. this.setFunc = function ( stencilFunc, stencilRef, stencilMask ) {
  18276. if ( currentStencilFunc !== stencilFunc ||
  18277. currentStencilRef !== stencilRef ||
  18278. currentStencilFuncMask !== stencilMask ) {
  18279. gl.stencilFunc( stencilFunc, stencilRef, stencilMask );
  18280. currentStencilFunc = stencilFunc;
  18281. currentStencilRef = stencilRef;
  18282. currentStencilFuncMask = stencilMask;
  18283. }
  18284. };
  18285. this.setOp = function ( stencilFail, stencilZFail, stencilZPass ) {
  18286. if ( currentStencilFail !== stencilFail ||
  18287. currentStencilZFail !== stencilZFail ||
  18288. currentStencilZPass !== stencilZPass ) {
  18289. gl.stencilOp( stencilFail, stencilZFail, stencilZPass );
  18290. currentStencilFail = stencilFail;
  18291. currentStencilZFail = stencilZFail;
  18292. currentStencilZPass = stencilZPass;
  18293. }
  18294. };
  18295. this.setLocked = function ( lock ) {
  18296. locked = lock;
  18297. };
  18298. this.setClear = function ( stencil ) {
  18299. if ( currentStencilClear !== stencil ) {
  18300. gl.clearStencil( stencil );
  18301. currentStencilClear = stencil;
  18302. }
  18303. };
  18304. this.reset = function () {
  18305. locked = false;
  18306. currentStencilMask = null;
  18307. currentStencilFunc = null;
  18308. currentStencilRef = null;
  18309. currentStencilFuncMask = null;
  18310. currentStencilFail = null;
  18311. currentStencilZFail = null;
  18312. currentStencilZPass = null;
  18313. currentStencilClear = null;
  18314. };
  18315. };
  18316. // File:src/renderers/webgl/WebGLTextures.js
  18317. /**
  18318. * @author mrdoob / http://mrdoob.com/
  18319. */
  18320. THREE.WebGLTextures = function ( _gl, extensions, state, properties, capabilities, paramThreeToGL, info ) {
  18321. var _infoMemory = info.memory;
  18322. var _isWebGL2 = ( typeof WebGL2RenderingContext !== 'undefined' && _gl instanceof WebGL2RenderingContext );
  18323. //
  18324. function clampToMaxSize ( image, maxSize ) {
  18325. if ( image.width > maxSize || image.height > maxSize ) {
  18326. // Warning: Scaling through the canvas will only work with images that use
  18327. // premultiplied alpha.
  18328. var scale = maxSize / Math.max( image.width, image.height );
  18329. var canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  18330. canvas.width = Math.floor( image.width * scale );
  18331. canvas.height = Math.floor( image.height * scale );
  18332. var context = canvas.getContext( '2d' );
  18333. context.drawImage( image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height );
  18334. console.warn( 'THREE.WebGLRenderer: image is too big (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
  18335. return canvas;
  18336. }
  18337. return image;
  18338. }
  18339. function isPowerOfTwo( image ) {
  18340. return THREE.Math.isPowerOfTwo( image.width ) && THREE.Math.isPowerOfTwo( image.height );
  18341. }
  18342. function makePowerOfTwo( image ) {
  18343. if ( image instanceof HTMLImageElement || image instanceof HTMLCanvasElement ) {
  18344. var canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  18345. canvas.width = THREE.Math.nearestPowerOfTwo( image.width );
  18346. canvas.height = THREE.Math.nearestPowerOfTwo( image.height );
  18347. var context = canvas.getContext( '2d' );
  18348. context.drawImage( image, 0, 0, canvas.width, canvas.height );
  18349. console.warn( 'THREE.WebGLRenderer: image is not power of two (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
  18350. return canvas;
  18351. }
  18352. return image;
  18353. }
  18354. function textureNeedsPowerOfTwo( texture ) {
  18355. if ( texture.wrapS !== THREE.ClampToEdgeWrapping || texture.wrapT !== THREE.ClampToEdgeWrapping ) return true;
  18356. if ( texture.minFilter !== THREE.NearestFilter && texture.minFilter !== THREE.LinearFilter ) return true;
  18357. return false;
  18358. }
  18359. // Fallback filters for non-power-of-2 textures
  18360. function filterFallback ( f ) {
  18361. if ( f === THREE.NearestFilter || f === THREE.NearestMipMapNearestFilter || f === THREE.NearestMipMapLinearFilter ) {
  18362. return _gl.NEAREST;
  18363. }
  18364. return _gl.LINEAR;
  18365. }
  18366. //
  18367. function onTextureDispose( event ) {
  18368. var texture = event.target;
  18369. texture.removeEventListener( 'dispose', onTextureDispose );
  18370. deallocateTexture( texture );
  18371. _infoMemory.textures --;
  18372. }
  18373. function onRenderTargetDispose( event ) {
  18374. var renderTarget = event.target;
  18375. renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
  18376. deallocateRenderTarget( renderTarget );
  18377. _infoMemory.textures --;
  18378. }
  18379. //
  18380. function deallocateTexture( texture ) {
  18381. var textureProperties = properties.get( texture );
  18382. if ( texture.image && textureProperties.__image__webglTextureCube ) {
  18383. // cube texture
  18384. _gl.deleteTexture( textureProperties.__image__webglTextureCube );
  18385. } else {
  18386. // 2D texture
  18387. if ( textureProperties.__webglInit === undefined ) return;
  18388. _gl.deleteTexture( textureProperties.__webglTexture );
  18389. }
  18390. // remove all webgl properties
  18391. properties.delete( texture );
  18392. }
  18393. function deallocateRenderTarget( renderTarget ) {
  18394. var renderTargetProperties = properties.get( renderTarget );
  18395. var textureProperties = properties.get( renderTarget.texture );
  18396. if ( ! renderTarget ) return;
  18397. if ( textureProperties.__webglTexture !== undefined ) {
  18398. _gl.deleteTexture( textureProperties.__webglTexture );
  18399. }
  18400. if ( renderTarget.depthTexture ) {
  18401. renderTarget.depthTexture.dispose();
  18402. }
  18403. if ( renderTarget instanceof THREE.WebGLRenderTargetCube ) {
  18404. for ( var i = 0; i < 6; i ++ ) {
  18405. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] );
  18406. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer[ i ] );
  18407. }
  18408. } else {
  18409. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer );
  18410. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer );
  18411. }
  18412. properties.delete( renderTarget.texture );
  18413. properties.delete( renderTarget );
  18414. }
  18415. //
  18416. function setTexture2D( texture, slot ) {
  18417. var textureProperties = properties.get( texture );
  18418. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  18419. var image = texture.image;
  18420. if ( image === undefined ) {
  18421. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is undefined', texture );
  18422. } else if ( image.complete === false ) {
  18423. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete', texture );
  18424. } else {
  18425. uploadTexture( textureProperties, texture, slot );
  18426. return;
  18427. }
  18428. }
  18429. state.activeTexture( _gl.TEXTURE0 + slot );
  18430. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  18431. }
  18432. function setTextureCube ( texture, slot ) {
  18433. var textureProperties = properties.get( texture );
  18434. if ( texture.image.length === 6 ) {
  18435. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  18436. if ( ! textureProperties.__image__webglTextureCube ) {
  18437. texture.addEventListener( 'dispose', onTextureDispose );
  18438. textureProperties.__image__webglTextureCube = _gl.createTexture();
  18439. _infoMemory.textures ++;
  18440. }
  18441. state.activeTexture( _gl.TEXTURE0 + slot );
  18442. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  18443. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  18444. var isCompressed = texture instanceof THREE.CompressedTexture;
  18445. var isDataTexture = texture.image[ 0 ] instanceof THREE.DataTexture;
  18446. var cubeImage = [];
  18447. for ( var i = 0; i < 6; i ++ ) {
  18448. if ( ! isCompressed && ! isDataTexture ) {
  18449. cubeImage[ i ] = clampToMaxSize( texture.image[ i ], capabilities.maxCubemapSize );
  18450. } else {
  18451. cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
  18452. }
  18453. }
  18454. var image = cubeImage[ 0 ],
  18455. isPowerOfTwoImage = isPowerOfTwo( image ),
  18456. glFormat = paramThreeToGL( texture.format ),
  18457. glType = paramThreeToGL( texture.type );
  18458. setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture, isPowerOfTwoImage );
  18459. for ( var i = 0; i < 6; i ++ ) {
  18460. if ( ! isCompressed ) {
  18461. if ( isDataTexture ) {
  18462. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
  18463. } else {
  18464. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, glFormat, glType, cubeImage[ i ] );
  18465. }
  18466. } else {
  18467. var mipmap, mipmaps = cubeImage[ i ].mipmaps;
  18468. for ( var j = 0, jl = mipmaps.length; j < jl; j ++ ) {
  18469. mipmap = mipmaps[ j ];
  18470. if ( texture.format !== THREE.RGBAFormat && texture.format !== THREE.RGBFormat ) {
  18471. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  18472. state.compressedTexImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  18473. } else {
  18474. console.warn( "THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()" );
  18475. }
  18476. } else {
  18477. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  18478. }
  18479. }
  18480. }
  18481. }
  18482. if ( texture.generateMipmaps && isPowerOfTwoImage ) {
  18483. _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  18484. }
  18485. textureProperties.__version = texture.version;
  18486. if ( texture.onUpdate ) texture.onUpdate( texture );
  18487. } else {
  18488. state.activeTexture( _gl.TEXTURE0 + slot );
  18489. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  18490. }
  18491. }
  18492. }
  18493. function setTextureCubeDynamic ( texture, slot ) {
  18494. state.activeTexture( _gl.TEXTURE0 + slot );
  18495. state.bindTexture( _gl.TEXTURE_CUBE_MAP, properties.get( texture ).__webglTexture );
  18496. }
  18497. function setTextureParameters ( textureType, texture, isPowerOfTwoImage ) {
  18498. var extension;
  18499. if ( isPowerOfTwoImage ) {
  18500. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, paramThreeToGL( texture.wrapS ) );
  18501. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, paramThreeToGL( texture.wrapT ) );
  18502. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, paramThreeToGL( texture.magFilter ) );
  18503. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, paramThreeToGL( texture.minFilter ) );
  18504. } else {
  18505. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, _gl.CLAMP_TO_EDGE );
  18506. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, _gl.CLAMP_TO_EDGE );
  18507. if ( texture.wrapS !== THREE.ClampToEdgeWrapping || texture.wrapT !== THREE.ClampToEdgeWrapping ) {
  18508. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.', texture );
  18509. }
  18510. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, filterFallback( texture.magFilter ) );
  18511. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, filterFallback( texture.minFilter ) );
  18512. if ( texture.minFilter !== THREE.NearestFilter && texture.minFilter !== THREE.LinearFilter ) {
  18513. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.', texture );
  18514. }
  18515. }
  18516. extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  18517. if ( extension ) {
  18518. if ( texture.type === THREE.FloatType && extensions.get( 'OES_texture_float_linear' ) === null ) return;
  18519. if ( texture.type === THREE.HalfFloatType && extensions.get( 'OES_texture_half_float_linear' ) === null ) return;
  18520. if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
  18521. _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, capabilities.getMaxAnisotropy() ) );
  18522. properties.get( texture ).__currentAnisotropy = texture.anisotropy;
  18523. }
  18524. }
  18525. }
  18526. function uploadTexture( textureProperties, texture, slot ) {
  18527. if ( textureProperties.__webglInit === undefined ) {
  18528. textureProperties.__webglInit = true;
  18529. texture.addEventListener( 'dispose', onTextureDispose );
  18530. textureProperties.__webglTexture = _gl.createTexture();
  18531. _infoMemory.textures ++;
  18532. }
  18533. state.activeTexture( _gl.TEXTURE0 + slot );
  18534. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  18535. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  18536. _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );
  18537. _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
  18538. var image = clampToMaxSize( texture.image, capabilities.maxTextureSize );
  18539. if ( textureNeedsPowerOfTwo( texture ) && isPowerOfTwo( image ) === false ) {
  18540. image = makePowerOfTwo( image );
  18541. }
  18542. var isPowerOfTwoImage = isPowerOfTwo( image ),
  18543. glFormat = paramThreeToGL( texture.format ),
  18544. glType = paramThreeToGL( texture.type );
  18545. setTextureParameters( _gl.TEXTURE_2D, texture, isPowerOfTwoImage );
  18546. var mipmap, mipmaps = texture.mipmaps;
  18547. if ( texture instanceof THREE.DepthTexture ) {
  18548. // populate depth texture with dummy data
  18549. var internalFormat = _gl.DEPTH_COMPONENT;
  18550. if ( texture.type === THREE.FloatType ) {
  18551. if ( !_isWebGL2 ) throw new Error('Float Depth Texture only supported in WebGL2.0');
  18552. internalFormat = _gl.DEPTH_COMPONENT32F;
  18553. } else if ( _isWebGL2 ) {
  18554. // WebGL 2.0 requires signed internalformat for glTexImage2D
  18555. internalFormat = _gl.DEPTH_COMPONENT16;
  18556. }
  18557. state.texImage2D( _gl.TEXTURE_2D, 0, internalFormat, image.width, image.height, 0, glFormat, glType, null );
  18558. } else if ( texture instanceof THREE.DataTexture ) {
  18559. // use manually created mipmaps if available
  18560. // if there are no manual mipmaps
  18561. // set 0 level mipmap and then use GL to generate other mipmap levels
  18562. if ( mipmaps.length > 0 && isPowerOfTwoImage ) {
  18563. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  18564. mipmap = mipmaps[ i ];
  18565. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  18566. }
  18567. texture.generateMipmaps = false;
  18568. } else {
  18569. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, image.width, image.height, 0, glFormat, glType, image.data );
  18570. }
  18571. } else if ( texture instanceof THREE.CompressedTexture ) {
  18572. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  18573. mipmap = mipmaps[ i ];
  18574. if ( texture.format !== THREE.RGBAFormat && texture.format !== THREE.RGBFormat ) {
  18575. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  18576. state.compressedTexImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  18577. } else {
  18578. console.warn( "THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()" );
  18579. }
  18580. } else {
  18581. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  18582. }
  18583. }
  18584. } else {
  18585. // regular Texture (image, video, canvas)
  18586. // use manually created mipmaps if available
  18587. // if there are no manual mipmaps
  18588. // set 0 level mipmap and then use GL to generate other mipmap levels
  18589. if ( mipmaps.length > 0 && isPowerOfTwoImage ) {
  18590. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  18591. mipmap = mipmaps[ i ];
  18592. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, glFormat, glType, mipmap );
  18593. }
  18594. texture.generateMipmaps = false;
  18595. } else {
  18596. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, glFormat, glType, image );
  18597. }
  18598. }
  18599. if ( texture.generateMipmaps && isPowerOfTwoImage ) _gl.generateMipmap( _gl.TEXTURE_2D );
  18600. textureProperties.__version = texture.version;
  18601. if ( texture.onUpdate ) texture.onUpdate( texture );
  18602. }
  18603. // Render targets
  18604. // Setup storage for target texture and bind it to correct framebuffer
  18605. function setupFrameBufferTexture ( framebuffer, renderTarget, attachment, textureTarget ) {
  18606. var glFormat = paramThreeToGL( renderTarget.texture.format );
  18607. var glType = paramThreeToGL( renderTarget.texture.type );
  18608. state.texImage2D( textureTarget, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  18609. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  18610. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, attachment, textureTarget, properties.get( renderTarget.texture ).__webglTexture, 0 );
  18611. _gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
  18612. }
  18613. // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  18614. function setupRenderBufferStorage ( renderbuffer, renderTarget ) {
  18615. _gl.bindRenderbuffer( _gl.RENDERBUFFER, renderbuffer );
  18616. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  18617. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_COMPONENT16, renderTarget.width, renderTarget.height );
  18618. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  18619. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  18620. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_STENCIL, renderTarget.width, renderTarget.height );
  18621. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  18622. } else {
  18623. // FIXME: We don't support !depth !stencil
  18624. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.RGBA4, renderTarget.width, renderTarget.height );
  18625. }
  18626. _gl.bindRenderbuffer( _gl.RENDERBUFFER, null );
  18627. }
  18628. // Setup resources for a Depth Texture for a FBO (needs an extension)
  18629. function setupDepthTexture ( framebuffer, renderTarget ) {
  18630. var isCube = ( renderTarget instanceof THREE.WebGLRenderTargetCube );
  18631. if ( isCube ) throw new Error('Depth Texture with cube render targets is not supported!');
  18632. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  18633. if ( !( renderTarget.depthTexture instanceof THREE.DepthTexture ) ) {
  18634. throw new Error('renderTarget.depthTexture must be an instance of THREE.DepthTexture');
  18635. }
  18636. // upload an empty depth texture with framebuffer size
  18637. if ( !properties.get( renderTarget.depthTexture ).__webglTexture ||
  18638. renderTarget.depthTexture.image.width !== renderTarget.width ||
  18639. renderTarget.depthTexture.image.height !== renderTarget.height ) {
  18640. renderTarget.depthTexture.image.width = renderTarget.width;
  18641. renderTarget.depthTexture.image.height = renderTarget.height;
  18642. renderTarget.depthTexture.needsUpdate = true;
  18643. }
  18644. setTexture2D( renderTarget.depthTexture, 0 );
  18645. var webglDepthTexture = properties.get( renderTarget.depthTexture ).__webglTexture;
  18646. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0 );
  18647. }
  18648. // Setup GL resources for a non-texture depth buffer
  18649. function setupDepthRenderbuffer( renderTarget ) {
  18650. var renderTargetProperties = properties.get( renderTarget );
  18651. var isCube = ( renderTarget instanceof THREE.WebGLRenderTargetCube );
  18652. if ( renderTarget.depthTexture ) {
  18653. if ( isCube ) throw new Error('target.depthTexture not supported in Cube render targets');
  18654. setupDepthTexture( renderTargetProperties.__webglFramebuffer, renderTarget );
  18655. } else {
  18656. if ( isCube ) {
  18657. renderTargetProperties.__webglDepthbuffer = [];
  18658. for ( var i = 0; i < 6; i ++ ) {
  18659. _gl.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer[ i ] );
  18660. renderTargetProperties.__webglDepthbuffer[ i ] = _gl.createRenderbuffer();
  18661. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer[ i ], renderTarget );
  18662. }
  18663. } else {
  18664. _gl.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer );
  18665. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  18666. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer, renderTarget );
  18667. }
  18668. }
  18669. _gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
  18670. }
  18671. // Set up GL resources for the render target
  18672. function setupRenderTarget( renderTarget ) {
  18673. var renderTargetProperties = properties.get( renderTarget );
  18674. var textureProperties = properties.get( renderTarget.texture );
  18675. renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
  18676. textureProperties.__webglTexture = _gl.createTexture();
  18677. _infoMemory.textures ++;
  18678. var isCube = ( renderTarget instanceof THREE.WebGLRenderTargetCube );
  18679. var isTargetPowerOfTwo = isPowerOfTwo( renderTarget );
  18680. // Setup framebuffer
  18681. if ( isCube ) {
  18682. renderTargetProperties.__webglFramebuffer = [];
  18683. for ( var i = 0; i < 6; i ++ ) {
  18684. renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer();
  18685. }
  18686. } else {
  18687. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  18688. }
  18689. // Setup color buffer
  18690. if ( isCube ) {
  18691. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__webglTexture );
  18692. setTextureParameters( _gl.TEXTURE_CUBE_MAP, renderTarget.texture, isTargetPowerOfTwo );
  18693. for ( var i = 0; i < 6; i ++ ) {
  18694. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i );
  18695. }
  18696. if ( renderTarget.texture.generateMipmaps && isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  18697. state.bindTexture( _gl.TEXTURE_CUBE_MAP, null );
  18698. } else {
  18699. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  18700. setTextureParameters( _gl.TEXTURE_2D, renderTarget.texture, isTargetPowerOfTwo );
  18701. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_2D );
  18702. if ( renderTarget.texture.generateMipmaps && isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_2D );
  18703. state.bindTexture( _gl.TEXTURE_2D, null );
  18704. }
  18705. // Setup depth and stencil buffers
  18706. if ( renderTarget.depthBuffer ) {
  18707. setupDepthRenderbuffer( renderTarget );
  18708. }
  18709. }
  18710. function updateRenderTargetMipmap( renderTarget ) {
  18711. var texture = renderTarget.texture;
  18712. if ( texture.generateMipmaps && isPowerOfTwo( renderTarget ) &&
  18713. texture.minFilter !== THREE.NearestFilter &&
  18714. texture.minFilter !== THREE.LinearFilter ) {
  18715. var target = renderTarget instanceof THREE.WebGLRenderTargetCube ? _gl.TEXTURE_CUBE_MAP : _gl.TEXTURE_2D;
  18716. var webglTexture = properties.get( texture ).__webglTexture;
  18717. state.bindTexture( target, webglTexture );
  18718. _gl.generateMipmap( target );
  18719. state.bindTexture( target, null );
  18720. }
  18721. }
  18722. this.setTexture2D = setTexture2D;
  18723. this.setTextureCube = setTextureCube;
  18724. this.setTextureCubeDynamic = setTextureCubeDynamic;
  18725. this.setupRenderTarget = setupRenderTarget;
  18726. this.updateRenderTargetMipmap = updateRenderTargetMipmap;
  18727. };
  18728. // File:src/renderers/webgl/WebGLUniforms.js
  18729. /**
  18730. *
  18731. * Uniforms of a program.
  18732. * Those form a tree structure with a special top-level container for the root,
  18733. * which you get by calling 'new WebGLUniforms( gl, program, renderer )'.
  18734. *
  18735. *
  18736. * Properties of inner nodes including the top-level container:
  18737. *
  18738. * .seq - array of nested uniforms
  18739. * .map - nested uniforms by name
  18740. *
  18741. *
  18742. * Methods of all nodes except the top-level container:
  18743. *
  18744. * .setValue( gl, value, [renderer] )
  18745. *
  18746. * uploads a uniform value(s)
  18747. * the 'renderer' parameter is needed for sampler uniforms
  18748. *
  18749. *
  18750. * Static methods of the top-level container (renderer factorizations):
  18751. *
  18752. * .upload( gl, seq, values, renderer )
  18753. *
  18754. * sets uniforms in 'seq' to 'values[id].value'
  18755. *
  18756. * .seqWithValue( seq, values ) : filteredSeq
  18757. *
  18758. * filters 'seq' entries with corresponding entry in values
  18759. *
  18760. * .splitDynamic( seq, values ) : filteredSeq
  18761. *
  18762. * filters 'seq' entries with dynamic entry and removes them from 'seq'
  18763. *
  18764. *
  18765. * Methods of the top-level container (renderer factorizations):
  18766. *
  18767. * .setValue( gl, name, value )
  18768. *
  18769. * sets uniform with name 'name' to 'value'
  18770. *
  18771. * .set( gl, obj, prop )
  18772. *
  18773. * sets uniform from object and property with same name than uniform
  18774. *
  18775. * .setOptional( gl, obj, prop )
  18776. *
  18777. * like .set for an optional property of the object
  18778. *
  18779. *
  18780. * @author tschw
  18781. *
  18782. */
  18783. THREE.WebGLUniforms = ( function() { // scope
  18784. var emptyTexture = new THREE.Texture();
  18785. var emptyCubeTexture = new THREE.CubeTexture();
  18786. // --- Base for inner nodes (including the root) ---
  18787. var UniformContainer = function() {
  18788. this.seq = [];
  18789. this.map = {};
  18790. },
  18791. // --- Utilities ---
  18792. // Array Caches (provide typed arrays for temporary by size)
  18793. arrayCacheF32 = [],
  18794. arrayCacheI32 = [],
  18795. uncacheTemporaryArrays = function() {
  18796. arrayCacheF32.length = 0;
  18797. arrayCacheI32.length = 0;
  18798. },
  18799. // Flattening for arrays of vectors and matrices
  18800. flatten = function( array, nBlocks, blockSize ) {
  18801. var firstElem = array[ 0 ];
  18802. if ( firstElem <= 0 || firstElem > 0 ) return array;
  18803. // unoptimized: ! isNaN( firstElem )
  18804. // see http://jacksondunstan.com/articles/983
  18805. var n = nBlocks * blockSize,
  18806. r = arrayCacheF32[ n ];
  18807. if ( r === undefined ) {
  18808. r = new Float32Array( n );
  18809. arrayCacheF32[ n ] = r;
  18810. }
  18811. if ( nBlocks !== 0 ) {
  18812. firstElem.toArray( r, 0 );
  18813. for ( var i = 1, offset = 0; i !== nBlocks; ++ i ) {
  18814. offset += blockSize;
  18815. array[ i ].toArray( r, offset );
  18816. }
  18817. }
  18818. return r;
  18819. },
  18820. // Texture unit allocation
  18821. allocTexUnits = function( renderer, n ) {
  18822. var r = arrayCacheI32[ n ];
  18823. if ( r === undefined ) {
  18824. r = new Int32Array( n );
  18825. arrayCacheI32[ n ] = r;
  18826. }
  18827. for ( var i = 0; i !== n; ++ i )
  18828. r[ i ] = renderer.allocTextureUnit();
  18829. return r;
  18830. },
  18831. // --- Setters ---
  18832. // Note: Defining these methods externally, because they come in a bunch
  18833. // and this way their names minify.
  18834. // Single scalar
  18835. setValue1f = function( gl, v ) { gl.uniform1f( this.addr, v ); },
  18836. setValue1i = function( gl, v ) { gl.uniform1i( this.addr, v ); },
  18837. // Single float vector (from flat array or THREE.VectorN)
  18838. setValue2fv = function( gl, v ) {
  18839. if ( v.x === undefined ) gl.uniform2fv( this.addr, v );
  18840. else gl.uniform2f( this.addr, v.x, v.y );
  18841. },
  18842. setValue3fv = function( gl, v ) {
  18843. if ( v.x !== undefined )
  18844. gl.uniform3f( this.addr, v.x, v.y, v.z );
  18845. else if ( v.r !== undefined )
  18846. gl.uniform3f( this.addr, v.r, v.g, v.b );
  18847. else
  18848. gl.uniform3fv( this.addr, v );
  18849. },
  18850. setValue4fv = function( gl, v ) {
  18851. if ( v.x === undefined ) gl.uniform4fv( this.addr, v );
  18852. else gl.uniform4f( this.addr, v.x, v.y, v.z, v.w );
  18853. },
  18854. // Single matrix (from flat array or MatrixN)
  18855. setValue2fm = function( gl, v ) {
  18856. gl.uniformMatrix2fv( this.addr, false, v.elements || v );
  18857. },
  18858. setValue3fm = function( gl, v ) {
  18859. gl.uniformMatrix3fv( this.addr, false, v.elements || v );
  18860. },
  18861. setValue4fm = function( gl, v ) {
  18862. gl.uniformMatrix4fv( this.addr, false, v.elements || v );
  18863. },
  18864. // Single texture (2D / Cube)
  18865. setValueT1 = function( gl, v, renderer ) {
  18866. var unit = renderer.allocTextureUnit();
  18867. gl.uniform1i( this.addr, unit );
  18868. renderer.setTexture2D( v || emptyTexture, unit );
  18869. },
  18870. setValueT6 = function( gl, v, renderer ) {
  18871. var unit = renderer.allocTextureUnit();
  18872. gl.uniform1i( this.addr, unit );
  18873. renderer.setTextureCube( v || emptyCubeTexture, unit );
  18874. },
  18875. // Integer / Boolean vectors or arrays thereof (always flat arrays)
  18876. setValue2iv = function( gl, v ) { gl.uniform2iv( this.addr, v ); },
  18877. setValue3iv = function( gl, v ) { gl.uniform3iv( this.addr, v ); },
  18878. setValue4iv = function( gl, v ) { gl.uniform4iv( this.addr, v ); },
  18879. // Helper to pick the right setter for the singular case
  18880. getSingularSetter = function( type ) {
  18881. switch ( type ) {
  18882. case 0x1406: return setValue1f; // FLOAT
  18883. case 0x8b50: return setValue2fv; // _VEC2
  18884. case 0x8b51: return setValue3fv; // _VEC3
  18885. case 0x8b52: return setValue4fv; // _VEC4
  18886. case 0x8b5a: return setValue2fm; // _MAT2
  18887. case 0x8b5b: return setValue3fm; // _MAT3
  18888. case 0x8b5c: return setValue4fm; // _MAT4
  18889. case 0x8b5e: return setValueT1; // SAMPLER_2D
  18890. case 0x8b60: return setValueT6; // SAMPLER_CUBE
  18891. case 0x1404: case 0x8b56: return setValue1i; // INT, BOOL
  18892. case 0x8b53: case 0x8b57: return setValue2iv; // _VEC2
  18893. case 0x8b54: case 0x8b58: return setValue3iv; // _VEC3
  18894. case 0x8b55: case 0x8b59: return setValue4iv; // _VEC4
  18895. }
  18896. },
  18897. // Array of scalars
  18898. setValue1fv = function( gl, v ) { gl.uniform1fv( this.addr, v ); },
  18899. setValue1iv = function( gl, v ) { gl.uniform1iv( this.addr, v ); },
  18900. // Array of vectors (flat or from THREE classes)
  18901. setValueV2a = function( gl, v ) {
  18902. gl.uniform2fv( this.addr, flatten( v, this.size, 2 ) );
  18903. },
  18904. setValueV3a = function( gl, v ) {
  18905. gl.uniform3fv( this.addr, flatten( v, this.size, 3 ) );
  18906. },
  18907. setValueV4a = function( gl, v ) {
  18908. gl.uniform4fv( this.addr, flatten( v, this.size, 4 ) );
  18909. },
  18910. // Array of matrices (flat or from THREE clases)
  18911. setValueM2a = function( gl, v ) {
  18912. gl.uniformMatrix2fv( this.addr, false, flatten( v, this.size, 4 ) );
  18913. },
  18914. setValueM3a = function( gl, v ) {
  18915. gl.uniformMatrix3fv( this.addr, false, flatten( v, this.size, 9 ) );
  18916. },
  18917. setValueM4a = function( gl, v ) {
  18918. gl.uniformMatrix4fv( this.addr, false, flatten( v, this.size, 16 ) );
  18919. },
  18920. // Array of textures (2D / Cube)
  18921. setValueT1a = function( gl, v, renderer ) {
  18922. var n = v.length,
  18923. units = allocTexUnits( renderer, n );
  18924. gl.uniform1iv( this.addr, units );
  18925. for ( var i = 0; i !== n; ++ i ) {
  18926. renderer.setTexture2D( v[ i ] || emptyTexture, units[ i ] );
  18927. }
  18928. },
  18929. setValueT6a = function( gl, v, renderer ) {
  18930. var n = v.length,
  18931. units = allocTexUnits( renderer, n );
  18932. gl.uniform1iv( this.addr, units );
  18933. for ( var i = 0; i !== n; ++ i ) {
  18934. renderer.setTextureCube( v[ i ] || emptyCubeTexture, units[ i ] );
  18935. }
  18936. },
  18937. // Helper to pick the right setter for a pure (bottom-level) array
  18938. getPureArraySetter = function( type ) {
  18939. switch ( type ) {
  18940. case 0x1406: return setValue1fv; // FLOAT
  18941. case 0x8b50: return setValueV2a; // _VEC2
  18942. case 0x8b51: return setValueV3a; // _VEC3
  18943. case 0x8b52: return setValueV4a; // _VEC4
  18944. case 0x8b5a: return setValueM2a; // _MAT2
  18945. case 0x8b5b: return setValueM3a; // _MAT3
  18946. case 0x8b5c: return setValueM4a; // _MAT4
  18947. case 0x8b5e: return setValueT1a; // SAMPLER_2D
  18948. case 0x8b60: return setValueT6a; // SAMPLER_CUBE
  18949. case 0x1404: case 0x8b56: return setValue1iv; // INT, BOOL
  18950. case 0x8b53: case 0x8b57: return setValue2iv; // _VEC2
  18951. case 0x8b54: case 0x8b58: return setValue3iv; // _VEC3
  18952. case 0x8b55: case 0x8b59: return setValue4iv; // _VEC4
  18953. }
  18954. },
  18955. // --- Uniform Classes ---
  18956. SingleUniform = function SingleUniform( id, activeInfo, addr ) {
  18957. this.id = id;
  18958. this.addr = addr;
  18959. this.setValue = getSingularSetter( activeInfo.type );
  18960. // this.path = activeInfo.name; // DEBUG
  18961. },
  18962. PureArrayUniform = function( id, activeInfo, addr ) {
  18963. this.id = id;
  18964. this.addr = addr;
  18965. this.size = activeInfo.size;
  18966. this.setValue = getPureArraySetter( activeInfo.type );
  18967. // this.path = activeInfo.name; // DEBUG
  18968. },
  18969. StructuredUniform = function( id ) {
  18970. this.id = id;
  18971. UniformContainer.call( this ); // mix-in
  18972. };
  18973. StructuredUniform.prototype.setValue = function( gl, value ) {
  18974. // Note: Don't need an extra 'renderer' parameter, since samplers
  18975. // are not allowed in structured uniforms.
  18976. var seq = this.seq;
  18977. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  18978. var u = seq[ i ];
  18979. u.setValue( gl, value[ u.id ] );
  18980. }
  18981. };
  18982. // --- Top-level ---
  18983. // Parser - builds up the property tree from the path strings
  18984. var RePathPart = /([\w\d_]+)(\])?(\[|\.)?/g,
  18985. // extracts
  18986. // - the identifier (member name or array index)
  18987. // - followed by an optional right bracket (found when array index)
  18988. // - followed by an optional left bracket or dot (type of subscript)
  18989. //
  18990. // Note: These portions can be read in a non-overlapping fashion and
  18991. // allow straightforward parsing of the hierarchy that WebGL encodes
  18992. // in the uniform names.
  18993. addUniform = function( container, uniformObject ) {
  18994. container.seq.push( uniformObject );
  18995. container.map[ uniformObject.id ] = uniformObject;
  18996. },
  18997. parseUniform = function( activeInfo, addr, container ) {
  18998. var path = activeInfo.name,
  18999. pathLength = path.length;
  19000. // reset RegExp object, because of the early exit of a previous run
  19001. RePathPart.lastIndex = 0;
  19002. for (; ;) {
  19003. var match = RePathPart.exec( path ),
  19004. matchEnd = RePathPart.lastIndex,
  19005. id = match[ 1 ],
  19006. idIsIndex = match[ 2 ] === ']',
  19007. subscript = match[ 3 ];
  19008. if ( idIsIndex ) id = id | 0; // convert to integer
  19009. if ( subscript === undefined ||
  19010. subscript === '[' && matchEnd + 2 === pathLength ) {
  19011. // bare name or "pure" bottom-level array "[0]" suffix
  19012. addUniform( container, subscript === undefined ?
  19013. new SingleUniform( id, activeInfo, addr ) :
  19014. new PureArrayUniform( id, activeInfo, addr ) );
  19015. break;
  19016. } else {
  19017. // step into inner node / create it in case it doesn't exist
  19018. var map = container.map,
  19019. next = map[ id ];
  19020. if ( next === undefined ) {
  19021. next = new StructuredUniform( id );
  19022. addUniform( container, next );
  19023. }
  19024. container = next;
  19025. }
  19026. }
  19027. },
  19028. // Root Container
  19029. WebGLUniforms = function WebGLUniforms( gl, program, renderer ) {
  19030. UniformContainer.call( this );
  19031. this.renderer = renderer;
  19032. var n = gl.getProgramParameter( program, gl.ACTIVE_UNIFORMS );
  19033. for ( var i = 0; i !== n; ++ i ) {
  19034. var info = gl.getActiveUniform( program, i ),
  19035. path = info.name,
  19036. addr = gl.getUniformLocation( program, path );
  19037. parseUniform( info, addr, this );
  19038. }
  19039. };
  19040. WebGLUniforms.prototype.setValue = function( gl, name, value ) {
  19041. var u = this.map[ name ];
  19042. if ( u !== undefined ) u.setValue( gl, value, this.renderer );
  19043. };
  19044. WebGLUniforms.prototype.set = function( gl, object, name ) {
  19045. var u = this.map[ name ];
  19046. if ( u !== undefined ) u.setValue( gl, object[ name ], this.renderer );
  19047. };
  19048. WebGLUniforms.prototype.setOptional = function( gl, object, name ) {
  19049. var v = object[ name ];
  19050. if ( v !== undefined ) this.setValue( gl, name, v );
  19051. };
  19052. // Static interface
  19053. WebGLUniforms.upload = function( gl, seq, values, renderer ) {
  19054. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  19055. var u = seq[ i ],
  19056. v = values[ u.id ];
  19057. if ( v.needsUpdate !== false ) {
  19058. // note: always updating when .needsUpdate is undefined
  19059. u.setValue( gl, v.value, renderer );
  19060. }
  19061. }
  19062. };
  19063. WebGLUniforms.seqWithValue = function( seq, values ) {
  19064. var r = [];
  19065. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  19066. var u = seq[ i ];
  19067. if ( u.id in values ) r.push( u );
  19068. }
  19069. return r;
  19070. };
  19071. WebGLUniforms.splitDynamic = function( seq, values ) {
  19072. var r = null,
  19073. n = seq.length,
  19074. w = 0;
  19075. for ( var i = 0; i !== n; ++ i ) {
  19076. var u = seq[ i ],
  19077. v = values[ u.id ];
  19078. if ( v && v.dynamic === true ) {
  19079. if ( r === null ) r = [];
  19080. r.push( u );
  19081. } else {
  19082. // in-place compact 'seq', removing the matches
  19083. if ( w < i ) seq[ w ] = u;
  19084. ++ w;
  19085. }
  19086. }
  19087. if ( w < n ) seq.length = w;
  19088. return r;
  19089. };
  19090. WebGLUniforms.evalDynamic = function( seq, values, object, camera ) {
  19091. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  19092. var v = values[ seq[ i ].id ],
  19093. f = v.onUpdateCallback;
  19094. if ( f !== undefined ) f.call( v, object, camera );
  19095. }
  19096. };
  19097. return WebGLUniforms;
  19098. } )();
  19099. // File:src/renderers/webgl/plugins/LensFlarePlugin.js
  19100. /**
  19101. * @author mikael emtinger / http://gomo.se/
  19102. * @author alteredq / http://alteredqualia.com/
  19103. */
  19104. THREE.LensFlarePlugin = function ( renderer, flares ) {
  19105. var gl = renderer.context;
  19106. var state = renderer.state;
  19107. var vertexBuffer, elementBuffer;
  19108. var shader, program, attributes, uniforms;
  19109. var tempTexture, occlusionTexture;
  19110. function init() {
  19111. var vertices = new Float32Array( [
  19112. - 1, - 1, 0, 0,
  19113. 1, - 1, 1, 0,
  19114. 1, 1, 1, 1,
  19115. - 1, 1, 0, 1
  19116. ] );
  19117. var faces = new Uint16Array( [
  19118. 0, 1, 2,
  19119. 0, 2, 3
  19120. ] );
  19121. // buffers
  19122. vertexBuffer = gl.createBuffer();
  19123. elementBuffer = gl.createBuffer();
  19124. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  19125. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  19126. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  19127. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  19128. // textures
  19129. tempTexture = gl.createTexture();
  19130. occlusionTexture = gl.createTexture();
  19131. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  19132. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGB, 16, 16, 0, gl.RGB, gl.UNSIGNED_BYTE, null );
  19133. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  19134. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  19135. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  19136. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  19137. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  19138. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGBA, 16, 16, 0, gl.RGBA, gl.UNSIGNED_BYTE, null );
  19139. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  19140. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  19141. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  19142. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  19143. shader = {
  19144. vertexShader: [
  19145. "uniform lowp int renderType;",
  19146. "uniform vec3 screenPosition;",
  19147. "uniform vec2 scale;",
  19148. "uniform float rotation;",
  19149. "uniform sampler2D occlusionMap;",
  19150. "attribute vec2 position;",
  19151. "attribute vec2 uv;",
  19152. "varying vec2 vUV;",
  19153. "varying float vVisibility;",
  19154. "void main() {",
  19155. "vUV = uv;",
  19156. "vec2 pos = position;",
  19157. "if ( renderType == 2 ) {",
  19158. "vec4 visibility = texture2D( occlusionMap, vec2( 0.1, 0.1 ) );",
  19159. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.1 ) );",
  19160. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.1 ) );",
  19161. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) );",
  19162. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.9 ) );",
  19163. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) );",
  19164. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.9 ) );",
  19165. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) );",
  19166. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.5 ) );",
  19167. "vVisibility = visibility.r / 9.0;",
  19168. "vVisibility *= 1.0 - visibility.g / 9.0;",
  19169. "vVisibility *= visibility.b / 9.0;",
  19170. "vVisibility *= 1.0 - visibility.a / 9.0;",
  19171. "pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
  19172. "pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
  19173. "}",
  19174. "gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
  19175. "}"
  19176. ].join( "\n" ),
  19177. fragmentShader: [
  19178. "uniform lowp int renderType;",
  19179. "uniform sampler2D map;",
  19180. "uniform float opacity;",
  19181. "uniform vec3 color;",
  19182. "varying vec2 vUV;",
  19183. "varying float vVisibility;",
  19184. "void main() {",
  19185. // pink square
  19186. "if ( renderType == 0 ) {",
  19187. "gl_FragColor = vec4( 1.0, 0.0, 1.0, 0.0 );",
  19188. // restore
  19189. "} else if ( renderType == 1 ) {",
  19190. "gl_FragColor = texture2D( map, vUV );",
  19191. // flare
  19192. "} else {",
  19193. "vec4 texture = texture2D( map, vUV );",
  19194. "texture.a *= opacity * vVisibility;",
  19195. "gl_FragColor = texture;",
  19196. "gl_FragColor.rgb *= color;",
  19197. "}",
  19198. "}"
  19199. ].join( "\n" )
  19200. };
  19201. program = createProgram( shader );
  19202. attributes = {
  19203. vertex: gl.getAttribLocation ( program, "position" ),
  19204. uv: gl.getAttribLocation ( program, "uv" )
  19205. };
  19206. uniforms = {
  19207. renderType: gl.getUniformLocation( program, "renderType" ),
  19208. map: gl.getUniformLocation( program, "map" ),
  19209. occlusionMap: gl.getUniformLocation( program, "occlusionMap" ),
  19210. opacity: gl.getUniformLocation( program, "opacity" ),
  19211. color: gl.getUniformLocation( program, "color" ),
  19212. scale: gl.getUniformLocation( program, "scale" ),
  19213. rotation: gl.getUniformLocation( program, "rotation" ),
  19214. screenPosition: gl.getUniformLocation( program, "screenPosition" )
  19215. };
  19216. }
  19217. /*
  19218. * Render lens flares
  19219. * Method: renders 16x16 0xff00ff-colored points scattered over the light source area,
  19220. * reads these back and calculates occlusion.
  19221. */
  19222. this.render = function ( scene, camera, viewport ) {
  19223. if ( flares.length === 0 ) return;
  19224. var tempPosition = new THREE.Vector3();
  19225. var invAspect = viewport.w / viewport.z,
  19226. halfViewportWidth = viewport.z * 0.5,
  19227. halfViewportHeight = viewport.w * 0.5;
  19228. var size = 16 / viewport.w,
  19229. scale = new THREE.Vector2( size * invAspect, size );
  19230. var screenPosition = new THREE.Vector3( 1, 1, 0 ),
  19231. screenPositionPixels = new THREE.Vector2( 1, 1 );
  19232. var validArea = new THREE.Box2();
  19233. validArea.min.set( 0, 0 );
  19234. validArea.max.set( viewport.z - 16, viewport.w - 16 );
  19235. if ( program === undefined ) {
  19236. init();
  19237. }
  19238. gl.useProgram( program );
  19239. state.initAttributes();
  19240. state.enableAttribute( attributes.vertex );
  19241. state.enableAttribute( attributes.uv );
  19242. state.disableUnusedAttributes();
  19243. // loop through all lens flares to update their occlusion and positions
  19244. // setup gl and common used attribs/uniforms
  19245. gl.uniform1i( uniforms.occlusionMap, 0 );
  19246. gl.uniform1i( uniforms.map, 1 );
  19247. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  19248. gl.vertexAttribPointer( attributes.vertex, 2, gl.FLOAT, false, 2 * 8, 0 );
  19249. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  19250. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  19251. state.disable( gl.CULL_FACE );
  19252. state.setDepthWrite( false );
  19253. for ( var i = 0, l = flares.length; i < l; i ++ ) {
  19254. size = 16 / viewport.w;
  19255. scale.set( size * invAspect, size );
  19256. // calc object screen position
  19257. var flare = flares[ i ];
  19258. tempPosition.set( flare.matrixWorld.elements[ 12 ], flare.matrixWorld.elements[ 13 ], flare.matrixWorld.elements[ 14 ] );
  19259. tempPosition.applyMatrix4( camera.matrixWorldInverse );
  19260. tempPosition.applyProjection( camera.projectionMatrix );
  19261. // setup arrays for gl programs
  19262. screenPosition.copy( tempPosition );
  19263. // horizontal and vertical coordinate of the lower left corner of the pixels to copy
  19264. screenPositionPixels.x = viewport.x + ( screenPosition.x * halfViewportWidth ) + halfViewportWidth - 8;
  19265. screenPositionPixels.y = viewport.y + ( screenPosition.y * halfViewportHeight ) + halfViewportHeight - 8;
  19266. // screen cull
  19267. if ( validArea.containsPoint( screenPositionPixels ) === true ) {
  19268. // save current RGB to temp texture
  19269. state.activeTexture( gl.TEXTURE0 );
  19270. state.bindTexture( gl.TEXTURE_2D, null );
  19271. state.activeTexture( gl.TEXTURE1 );
  19272. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  19273. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGB, screenPositionPixels.x, screenPositionPixels.y, 16, 16, 0 );
  19274. // render pink quad
  19275. gl.uniform1i( uniforms.renderType, 0 );
  19276. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  19277. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  19278. state.disable( gl.BLEND );
  19279. state.enable( gl.DEPTH_TEST );
  19280. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  19281. // copy result to occlusionMap
  19282. state.activeTexture( gl.TEXTURE0 );
  19283. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  19284. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGBA, screenPositionPixels.x, screenPositionPixels.y, 16, 16, 0 );
  19285. // restore graphics
  19286. gl.uniform1i( uniforms.renderType, 1 );
  19287. state.disable( gl.DEPTH_TEST );
  19288. state.activeTexture( gl.TEXTURE1 );
  19289. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  19290. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  19291. // update object positions
  19292. flare.positionScreen.copy( screenPosition );
  19293. if ( flare.customUpdateCallback ) {
  19294. flare.customUpdateCallback( flare );
  19295. } else {
  19296. flare.updateLensFlares();
  19297. }
  19298. // render flares
  19299. gl.uniform1i( uniforms.renderType, 2 );
  19300. state.enable( gl.BLEND );
  19301. for ( var j = 0, jl = flare.lensFlares.length; j < jl; j ++ ) {
  19302. var sprite = flare.lensFlares[ j ];
  19303. if ( sprite.opacity > 0.001 && sprite.scale > 0.001 ) {
  19304. screenPosition.x = sprite.x;
  19305. screenPosition.y = sprite.y;
  19306. screenPosition.z = sprite.z;
  19307. size = sprite.size * sprite.scale / viewport.w;
  19308. scale.x = size * invAspect;
  19309. scale.y = size;
  19310. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  19311. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  19312. gl.uniform1f( uniforms.rotation, sprite.rotation );
  19313. gl.uniform1f( uniforms.opacity, sprite.opacity );
  19314. gl.uniform3f( uniforms.color, sprite.color.r, sprite.color.g, sprite.color.b );
  19315. state.setBlending( sprite.blending, sprite.blendEquation, sprite.blendSrc, sprite.blendDst );
  19316. renderer.setTexture2D( sprite.texture, 1 );
  19317. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  19318. }
  19319. }
  19320. }
  19321. }
  19322. // restore gl
  19323. state.enable( gl.CULL_FACE );
  19324. state.enable( gl.DEPTH_TEST );
  19325. state.setDepthWrite( true );
  19326. renderer.resetGLState();
  19327. };
  19328. function createProgram ( shader ) {
  19329. var program = gl.createProgram();
  19330. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  19331. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  19332. var prefix = "precision " + renderer.getPrecision() + " float;\n";
  19333. gl.shaderSource( fragmentShader, prefix + shader.fragmentShader );
  19334. gl.shaderSource( vertexShader, prefix + shader.vertexShader );
  19335. gl.compileShader( fragmentShader );
  19336. gl.compileShader( vertexShader );
  19337. gl.attachShader( program, fragmentShader );
  19338. gl.attachShader( program, vertexShader );
  19339. gl.linkProgram( program );
  19340. return program;
  19341. }
  19342. };
  19343. // File:src/renderers/webgl/plugins/SpritePlugin.js
  19344. /**
  19345. * @author mikael emtinger / http://gomo.se/
  19346. * @author alteredq / http://alteredqualia.com/
  19347. */
  19348. THREE.SpritePlugin = function ( renderer, sprites ) {
  19349. var gl = renderer.context;
  19350. var state = renderer.state;
  19351. var vertexBuffer, elementBuffer;
  19352. var program, attributes, uniforms;
  19353. var texture;
  19354. // decompose matrixWorld
  19355. var spritePosition = new THREE.Vector3();
  19356. var spriteRotation = new THREE.Quaternion();
  19357. var spriteScale = new THREE.Vector3();
  19358. function init() {
  19359. var vertices = new Float32Array( [
  19360. - 0.5, - 0.5, 0, 0,
  19361. 0.5, - 0.5, 1, 0,
  19362. 0.5, 0.5, 1, 1,
  19363. - 0.5, 0.5, 0, 1
  19364. ] );
  19365. var faces = new Uint16Array( [
  19366. 0, 1, 2,
  19367. 0, 2, 3
  19368. ] );
  19369. vertexBuffer = gl.createBuffer();
  19370. elementBuffer = gl.createBuffer();
  19371. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  19372. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  19373. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  19374. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  19375. program = createProgram();
  19376. attributes = {
  19377. position: gl.getAttribLocation ( program, 'position' ),
  19378. uv: gl.getAttribLocation ( program, 'uv' )
  19379. };
  19380. uniforms = {
  19381. uvOffset: gl.getUniformLocation( program, 'uvOffset' ),
  19382. uvScale: gl.getUniformLocation( program, 'uvScale' ),
  19383. rotation: gl.getUniformLocation( program, 'rotation' ),
  19384. scale: gl.getUniformLocation( program, 'scale' ),
  19385. color: gl.getUniformLocation( program, 'color' ),
  19386. map: gl.getUniformLocation( program, 'map' ),
  19387. opacity: gl.getUniformLocation( program, 'opacity' ),
  19388. modelViewMatrix: gl.getUniformLocation( program, 'modelViewMatrix' ),
  19389. projectionMatrix: gl.getUniformLocation( program, 'projectionMatrix' ),
  19390. fogType: gl.getUniformLocation( program, 'fogType' ),
  19391. fogDensity: gl.getUniformLocation( program, 'fogDensity' ),
  19392. fogNear: gl.getUniformLocation( program, 'fogNear' ),
  19393. fogFar: gl.getUniformLocation( program, 'fogFar' ),
  19394. fogColor: gl.getUniformLocation( program, 'fogColor' ),
  19395. alphaTest: gl.getUniformLocation( program, 'alphaTest' )
  19396. };
  19397. var canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  19398. canvas.width = 8;
  19399. canvas.height = 8;
  19400. var context = canvas.getContext( '2d' );
  19401. context.fillStyle = 'white';
  19402. context.fillRect( 0, 0, 8, 8 );
  19403. texture = new THREE.Texture( canvas );
  19404. texture.needsUpdate = true;
  19405. }
  19406. this.render = function ( scene, camera ) {
  19407. if ( sprites.length === 0 ) return;
  19408. // setup gl
  19409. if ( program === undefined ) {
  19410. init();
  19411. }
  19412. gl.useProgram( program );
  19413. state.initAttributes();
  19414. state.enableAttribute( attributes.position );
  19415. state.enableAttribute( attributes.uv );
  19416. state.disableUnusedAttributes();
  19417. state.disable( gl.CULL_FACE );
  19418. state.enable( gl.BLEND );
  19419. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  19420. gl.vertexAttribPointer( attributes.position, 2, gl.FLOAT, false, 2 * 8, 0 );
  19421. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  19422. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  19423. gl.uniformMatrix4fv( uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
  19424. state.activeTexture( gl.TEXTURE0 );
  19425. gl.uniform1i( uniforms.map, 0 );
  19426. var oldFogType = 0;
  19427. var sceneFogType = 0;
  19428. var fog = scene.fog;
  19429. if ( fog ) {
  19430. gl.uniform3f( uniforms.fogColor, fog.color.r, fog.color.g, fog.color.b );
  19431. if ( fog instanceof THREE.Fog ) {
  19432. gl.uniform1f( uniforms.fogNear, fog.near );
  19433. gl.uniform1f( uniforms.fogFar, fog.far );
  19434. gl.uniform1i( uniforms.fogType, 1 );
  19435. oldFogType = 1;
  19436. sceneFogType = 1;
  19437. } else if ( fog instanceof THREE.FogExp2 ) {
  19438. gl.uniform1f( uniforms.fogDensity, fog.density );
  19439. gl.uniform1i( uniforms.fogType, 2 );
  19440. oldFogType = 2;
  19441. sceneFogType = 2;
  19442. }
  19443. } else {
  19444. gl.uniform1i( uniforms.fogType, 0 );
  19445. oldFogType = 0;
  19446. sceneFogType = 0;
  19447. }
  19448. // update positions and sort
  19449. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  19450. var sprite = sprites[ i ];
  19451. sprite.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, sprite.matrixWorld );
  19452. sprite.z = - sprite.modelViewMatrix.elements[ 14 ];
  19453. }
  19454. sprites.sort( painterSortStable );
  19455. // render all sprites
  19456. var scale = [];
  19457. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  19458. var sprite = sprites[ i ];
  19459. var material = sprite.material;
  19460. if ( material.visible === false ) continue;
  19461. gl.uniform1f( uniforms.alphaTest, material.alphaTest );
  19462. gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, sprite.modelViewMatrix.elements );
  19463. sprite.matrixWorld.decompose( spritePosition, spriteRotation, spriteScale );
  19464. scale[ 0 ] = spriteScale.x;
  19465. scale[ 1 ] = spriteScale.y;
  19466. var fogType = 0;
  19467. if ( scene.fog && material.fog ) {
  19468. fogType = sceneFogType;
  19469. }
  19470. if ( oldFogType !== fogType ) {
  19471. gl.uniform1i( uniforms.fogType, fogType );
  19472. oldFogType = fogType;
  19473. }
  19474. if ( material.map !== null ) {
  19475. gl.uniform2f( uniforms.uvOffset, material.map.offset.x, material.map.offset.y );
  19476. gl.uniform2f( uniforms.uvScale, material.map.repeat.x, material.map.repeat.y );
  19477. } else {
  19478. gl.uniform2f( uniforms.uvOffset, 0, 0 );
  19479. gl.uniform2f( uniforms.uvScale, 1, 1 );
  19480. }
  19481. gl.uniform1f( uniforms.opacity, material.opacity );
  19482. gl.uniform3f( uniforms.color, material.color.r, material.color.g, material.color.b );
  19483. gl.uniform1f( uniforms.rotation, material.rotation );
  19484. gl.uniform2fv( uniforms.scale, scale );
  19485. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst );
  19486. state.setDepthTest( material.depthTest );
  19487. state.setDepthWrite( material.depthWrite );
  19488. if ( material.map ) {
  19489. renderer.setTexture2D( material.map, 0 );
  19490. } else {
  19491. renderer.setTexture2D( texture, 0 );
  19492. }
  19493. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  19494. }
  19495. // restore gl
  19496. state.enable( gl.CULL_FACE );
  19497. renderer.resetGLState();
  19498. };
  19499. function createProgram () {
  19500. var program = gl.createProgram();
  19501. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  19502. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  19503. gl.shaderSource( vertexShader, [
  19504. 'precision ' + renderer.getPrecision() + ' float;',
  19505. 'uniform mat4 modelViewMatrix;',
  19506. 'uniform mat4 projectionMatrix;',
  19507. 'uniform float rotation;',
  19508. 'uniform vec2 scale;',
  19509. 'uniform vec2 uvOffset;',
  19510. 'uniform vec2 uvScale;',
  19511. 'attribute vec2 position;',
  19512. 'attribute vec2 uv;',
  19513. 'varying vec2 vUV;',
  19514. 'void main() {',
  19515. 'vUV = uvOffset + uv * uvScale;',
  19516. 'vec2 alignedPosition = position * scale;',
  19517. 'vec2 rotatedPosition;',
  19518. 'rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;',
  19519. 'rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;',
  19520. 'vec4 finalPosition;',
  19521. 'finalPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );',
  19522. 'finalPosition.xy += rotatedPosition;',
  19523. 'finalPosition = projectionMatrix * finalPosition;',
  19524. 'gl_Position = finalPosition;',
  19525. '}'
  19526. ].join( '\n' ) );
  19527. gl.shaderSource( fragmentShader, [
  19528. 'precision ' + renderer.getPrecision() + ' float;',
  19529. 'uniform vec3 color;',
  19530. 'uniform sampler2D map;',
  19531. 'uniform float opacity;',
  19532. 'uniform int fogType;',
  19533. 'uniform vec3 fogColor;',
  19534. 'uniform float fogDensity;',
  19535. 'uniform float fogNear;',
  19536. 'uniform float fogFar;',
  19537. 'uniform float alphaTest;',
  19538. 'varying vec2 vUV;',
  19539. 'void main() {',
  19540. 'vec4 texture = texture2D( map, vUV );',
  19541. 'if ( texture.a < alphaTest ) discard;',
  19542. 'gl_FragColor = vec4( color * texture.xyz, texture.a * opacity );',
  19543. 'if ( fogType > 0 ) {',
  19544. 'float depth = gl_FragCoord.z / gl_FragCoord.w;',
  19545. 'float fogFactor = 0.0;',
  19546. 'if ( fogType == 1 ) {',
  19547. 'fogFactor = smoothstep( fogNear, fogFar, depth );',
  19548. '} else {',
  19549. 'const float LOG2 = 1.442695;',
  19550. 'fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );',
  19551. 'fogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );',
  19552. '}',
  19553. 'gl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );',
  19554. '}',
  19555. '}'
  19556. ].join( '\n' ) );
  19557. gl.compileShader( vertexShader );
  19558. gl.compileShader( fragmentShader );
  19559. gl.attachShader( program, vertexShader );
  19560. gl.attachShader( program, fragmentShader );
  19561. gl.linkProgram( program );
  19562. return program;
  19563. }
  19564. function painterSortStable ( a, b ) {
  19565. if ( a.renderOrder !== b.renderOrder ) {
  19566. return a.renderOrder - b.renderOrder;
  19567. } else if ( a.z !== b.z ) {
  19568. return b.z - a.z;
  19569. } else {
  19570. return b.id - a.id;
  19571. }
  19572. }
  19573. };
  19574. // File:src/Three.Legacy.js
  19575. /**
  19576. * @author mrdoob / http://mrdoob.com/
  19577. */
  19578. Object.assign( THREE, {
  19579. Face4: function ( a, b, c, d, normal, color, materialIndex ) {
  19580. console.warn( 'THREE.Face4 has been removed. A THREE.Face3 will be created instead.' );
  19581. return new THREE.Face3( a, b, c, normal, color, materialIndex );
  19582. },
  19583. LineStrip: 0,
  19584. LinePieces: 1,
  19585. MeshFaceMaterial: THREE.MultiMaterial,
  19586. PointCloud: function ( geometry, material ) {
  19587. console.warn( 'THREE.PointCloud has been renamed to THREE.Points.' );
  19588. return new THREE.Points( geometry, material );
  19589. },
  19590. Particle: THREE.Sprite,
  19591. ParticleSystem: function ( geometry, material ) {
  19592. console.warn( 'THREE.ParticleSystem has been renamed to THREE.Points.' );
  19593. return new THREE.Points( geometry, material );
  19594. },
  19595. PointCloudMaterial: function ( parameters ) {
  19596. console.warn( 'THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.' );
  19597. return new THREE.PointsMaterial( parameters );
  19598. },
  19599. ParticleBasicMaterial: function ( parameters ) {
  19600. console.warn( 'THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.' );
  19601. return new THREE.PointsMaterial( parameters );
  19602. },
  19603. ParticleSystemMaterial: function ( parameters ) {
  19604. console.warn( 'THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.' );
  19605. return new THREE.PointsMaterial( parameters );
  19606. },
  19607. Vertex: function ( x, y, z ) {
  19608. console.warn( 'THREE.Vertex has been removed. Use THREE.Vector3 instead.' );
  19609. return new THREE.Vector3( x, y, z );
  19610. }
  19611. } );
  19612. //
  19613. Object.assign( THREE.Box2.prototype, {
  19614. empty: function () {
  19615. console.warn( 'THREE.Box2: .empty() has been renamed to .isEmpty().' );
  19616. return this.isEmpty();
  19617. },
  19618. isIntersectionBox: function ( box ) {
  19619. console.warn( 'THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().' );
  19620. return this.intersectsBox( box );
  19621. }
  19622. } );
  19623. Object.assign( THREE.Box3.prototype, {
  19624. empty: function () {
  19625. console.warn( 'THREE.Box3: .empty() has been renamed to .isEmpty().' );
  19626. return this.isEmpty();
  19627. },
  19628. isIntersectionBox: function ( box ) {
  19629. console.warn( 'THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().' );
  19630. return this.intersectsBox( box );
  19631. },
  19632. isIntersectionSphere: function ( sphere ) {
  19633. console.warn( 'THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  19634. return this.intersectsSphere( sphere );
  19635. }
  19636. } );
  19637. Object.assign( THREE.Matrix3.prototype, {
  19638. multiplyVector3: function ( vector ) {
  19639. console.warn( 'THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.' );
  19640. return vector.applyMatrix3( this );
  19641. },
  19642. multiplyVector3Array: function ( a ) {
  19643. console.warn( 'THREE.Matrix3: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
  19644. return this.applyToVector3Array( a );
  19645. }
  19646. } );
  19647. Object.assign( THREE.Matrix4.prototype, {
  19648. extractPosition: function ( m ) {
  19649. console.warn( 'THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().' );
  19650. return this.copyPosition( m );
  19651. },
  19652. setRotationFromQuaternion: function ( q ) {
  19653. console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' );
  19654. return this.makeRotationFromQuaternion( q );
  19655. },
  19656. multiplyVector3: function ( vector ) {
  19657. console.warn( 'THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) or vector.applyProjection( matrix ) instead.' );
  19658. return vector.applyProjection( this );
  19659. },
  19660. multiplyVector4: function ( vector ) {
  19661. console.warn( 'THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  19662. return vector.applyMatrix4( this );
  19663. },
  19664. multiplyVector3Array: function ( a ) {
  19665. console.warn( 'THREE.Matrix4: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
  19666. return this.applyToVector3Array( a );
  19667. },
  19668. rotateAxis: function ( v ) {
  19669. console.warn( 'THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.' );
  19670. v.transformDirection( this );
  19671. },
  19672. crossVector: function ( vector ) {
  19673. console.warn( 'THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  19674. return vector.applyMatrix4( this );
  19675. },
  19676. translate: function ( v ) {
  19677. console.error( 'THREE.Matrix4: .translate() has been removed.' );
  19678. },
  19679. rotateX: function ( angle ) {
  19680. console.error( 'THREE.Matrix4: .rotateX() has been removed.' );
  19681. },
  19682. rotateY: function ( angle ) {
  19683. console.error( 'THREE.Matrix4: .rotateY() has been removed.' );
  19684. },
  19685. rotateZ: function ( angle ) {
  19686. console.error( 'THREE.Matrix4: .rotateZ() has been removed.' );
  19687. },
  19688. rotateByAxis: function ( axis, angle ) {
  19689. console.error( 'THREE.Matrix4: .rotateByAxis() has been removed.' );
  19690. }
  19691. } );
  19692. Object.assign( THREE.Plane.prototype, {
  19693. isIntersectionLine: function ( line ) {
  19694. console.warn( 'THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().' );
  19695. return this.intersectsLine( line );
  19696. }
  19697. } );
  19698. Object.assign( THREE.Quaternion.prototype, {
  19699. multiplyVector3: function ( vector ) {
  19700. console.warn( 'THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.' );
  19701. return vector.applyQuaternion( this );
  19702. }
  19703. } );
  19704. Object.assign( THREE.Ray.prototype, {
  19705. isIntersectionBox: function ( box ) {
  19706. console.warn( 'THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().' );
  19707. return this.intersectsBox( box );
  19708. },
  19709. isIntersectionPlane: function ( plane ) {
  19710. console.warn( 'THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().' );
  19711. return this.intersectsPlane( plane );
  19712. },
  19713. isIntersectionSphere: function ( sphere ) {
  19714. console.warn( 'THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  19715. return this.intersectsSphere( sphere );
  19716. }
  19717. } );
  19718. Object.assign( THREE.Vector3.prototype, {
  19719. setEulerFromRotationMatrix: function () {
  19720. console.error( 'THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.' );
  19721. },
  19722. setEulerFromQuaternion: function () {
  19723. console.error( 'THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.' );
  19724. },
  19725. getPositionFromMatrix: function ( m ) {
  19726. console.warn( 'THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().' );
  19727. return this.setFromMatrixPosition( m );
  19728. },
  19729. getScaleFromMatrix: function ( m ) {
  19730. console.warn( 'THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().' );
  19731. return this.setFromMatrixScale( m );
  19732. },
  19733. getColumnFromMatrix: function ( index, matrix ) {
  19734. console.warn( 'THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().' );
  19735. return this.setFromMatrixColumn( matrix, index );
  19736. }
  19737. } );
  19738. //
  19739. Object.assign( THREE.Object3D.prototype, {
  19740. getChildByName: function ( name ) {
  19741. console.warn( 'THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().' );
  19742. return this.getObjectByName( name );
  19743. },
  19744. renderDepth: function ( value ) {
  19745. console.warn( 'THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.' );
  19746. },
  19747. translate: function ( distance, axis ) {
  19748. console.warn( 'THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.' );
  19749. return this.translateOnAxis( axis, distance );
  19750. }
  19751. } );
  19752. Object.defineProperties( THREE.Object3D.prototype, {
  19753. eulerOrder: {
  19754. get: function () {
  19755. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  19756. return this.rotation.order;
  19757. },
  19758. set: function ( value ) {
  19759. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  19760. this.rotation.order = value;
  19761. }
  19762. },
  19763. useQuaternion: {
  19764. get: function () {
  19765. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  19766. },
  19767. set: function ( value ) {
  19768. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  19769. }
  19770. }
  19771. } );
  19772. Object.defineProperties( THREE.LOD.prototype, {
  19773. objects: {
  19774. get: function () {
  19775. console.warn( 'THREE.LOD: .objects has been renamed to .levels.' );
  19776. return this.levels;
  19777. }
  19778. }
  19779. } );
  19780. //
  19781. THREE.PerspectiveCamera.prototype.setLens = function ( focalLength, filmGauge ) {
  19782. console.warn( "THREE.PerspectiveCamera.setLens is deprecated. " +
  19783. "Use .setFocalLength and .filmGauge for a photographic setup." );
  19784. if ( filmGauge !== undefined ) this.filmGauge = filmGauge;
  19785. this.setFocalLength( focalLength );
  19786. };
  19787. //
  19788. Object.defineProperties( THREE.Light.prototype, {
  19789. onlyShadow: {
  19790. set: function ( value ) {
  19791. console.warn( 'THREE.Light: .onlyShadow has been removed.' );
  19792. }
  19793. },
  19794. shadowCameraFov: {
  19795. set: function ( value ) {
  19796. console.warn( 'THREE.Light: .shadowCameraFov is now .shadow.camera.fov.' );
  19797. this.shadow.camera.fov = value;
  19798. }
  19799. },
  19800. shadowCameraLeft: {
  19801. set: function ( value ) {
  19802. console.warn( 'THREE.Light: .shadowCameraLeft is now .shadow.camera.left.' );
  19803. this.shadow.camera.left = value;
  19804. }
  19805. },
  19806. shadowCameraRight: {
  19807. set: function ( value ) {
  19808. console.warn( 'THREE.Light: .shadowCameraRight is now .shadow.camera.right.' );
  19809. this.shadow.camera.right = value;
  19810. }
  19811. },
  19812. shadowCameraTop: {
  19813. set: function ( value ) {
  19814. console.warn( 'THREE.Light: .shadowCameraTop is now .shadow.camera.top.' );
  19815. this.shadow.camera.top = value;
  19816. }
  19817. },
  19818. shadowCameraBottom: {
  19819. set: function ( value ) {
  19820. console.warn( 'THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.' );
  19821. this.shadow.camera.bottom = value;
  19822. }
  19823. },
  19824. shadowCameraNear: {
  19825. set: function ( value ) {
  19826. console.warn( 'THREE.Light: .shadowCameraNear is now .shadow.camera.near.' );
  19827. this.shadow.camera.near = value;
  19828. }
  19829. },
  19830. shadowCameraFar: {
  19831. set: function ( value ) {
  19832. console.warn( 'THREE.Light: .shadowCameraFar is now .shadow.camera.far.' );
  19833. this.shadow.camera.far = value;
  19834. }
  19835. },
  19836. shadowCameraVisible: {
  19837. set: function ( value ) {
  19838. console.warn( 'THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.' );
  19839. }
  19840. },
  19841. shadowBias: {
  19842. set: function ( value ) {
  19843. console.warn( 'THREE.Light: .shadowBias is now .shadow.bias.' );
  19844. this.shadow.bias = value;
  19845. }
  19846. },
  19847. shadowDarkness: {
  19848. set: function ( value ) {
  19849. console.warn( 'THREE.Light: .shadowDarkness has been removed.' );
  19850. }
  19851. },
  19852. shadowMapWidth: {
  19853. set: function ( value ) {
  19854. console.warn( 'THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.' );
  19855. this.shadow.mapSize.width = value;
  19856. }
  19857. },
  19858. shadowMapHeight: {
  19859. set: function ( value ) {
  19860. console.warn( 'THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.' );
  19861. this.shadow.mapSize.height = value;
  19862. }
  19863. }
  19864. } );
  19865. //
  19866. Object.defineProperties( THREE.BufferAttribute.prototype, {
  19867. length: {
  19868. get: function () {
  19869. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Please use .count.' );
  19870. return this.array.length;
  19871. }
  19872. }
  19873. } );
  19874. Object.assign( THREE.BufferGeometry.prototype, {
  19875. addIndex: function ( index ) {
  19876. console.warn( 'THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().' );
  19877. this.setIndex( index );
  19878. },
  19879. addDrawCall: function ( start, count, indexOffset ) {
  19880. if ( indexOffset !== undefined ) {
  19881. console.warn( 'THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.' );
  19882. }
  19883. console.warn( 'THREE.BufferGeometry: .addDrawCall() is now .addGroup().' );
  19884. this.addGroup( start, count );
  19885. },
  19886. clearDrawCalls: function () {
  19887. console.warn( 'THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().' );
  19888. this.clearGroups();
  19889. },
  19890. computeTangents: function () {
  19891. console.warn( 'THREE.BufferGeometry: .computeTangents() has been removed.' );
  19892. },
  19893. computeOffsets: function () {
  19894. console.warn( 'THREE.BufferGeometry: .computeOffsets() has been removed.' );
  19895. }
  19896. } );
  19897. Object.defineProperties( THREE.BufferGeometry.prototype, {
  19898. drawcalls: {
  19899. get: function () {
  19900. console.error( 'THREE.BufferGeometry: .drawcalls has been renamed to .groups.' );
  19901. return this.groups;
  19902. }
  19903. },
  19904. offsets: {
  19905. get: function () {
  19906. console.warn( 'THREE.BufferGeometry: .offsets has been renamed to .groups.' );
  19907. return this.groups;
  19908. }
  19909. }
  19910. } );
  19911. //
  19912. Object.defineProperties( THREE.Material.prototype, {
  19913. wrapAround: {
  19914. get: function () {
  19915. console.warn( 'THREE.' + this.type + ': .wrapAround has been removed.' );
  19916. },
  19917. set: function ( value ) {
  19918. console.warn( 'THREE.' + this.type + ': .wrapAround has been removed.' );
  19919. }
  19920. },
  19921. wrapRGB: {
  19922. get: function () {
  19923. console.warn( 'THREE.' + this.type + ': .wrapRGB has been removed.' );
  19924. return new THREE.Color();
  19925. }
  19926. }
  19927. } );
  19928. Object.defineProperties( THREE.MeshPhongMaterial.prototype, {
  19929. metal: {
  19930. get: function () {
  19931. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.' );
  19932. return false;
  19933. },
  19934. set: function ( value ) {
  19935. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead' );
  19936. }
  19937. }
  19938. } );
  19939. Object.defineProperties( THREE.ShaderMaterial.prototype, {
  19940. derivatives: {
  19941. get: function () {
  19942. console.warn( 'THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  19943. return this.extensions.derivatives;
  19944. },
  19945. set: function ( value ) {
  19946. console.warn( 'THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  19947. this.extensions.derivatives = value;
  19948. }
  19949. }
  19950. } );
  19951. //
  19952. THREE.EventDispatcher.prototype = Object.assign( Object.create( {
  19953. // Note: Extra base ensures these properties are not 'assign'ed.
  19954. constructor: THREE.EventDispatcher,
  19955. apply: function ( target ) {
  19956. console.warn( "THREE.EventDispatcher: .apply is deprecated, " +
  19957. "just inherit or Object.assign the prototype to mix-in." );
  19958. Object.assign( target, this );
  19959. }
  19960. } ), THREE.EventDispatcher.prototype );
  19961. //
  19962. Object.assign( THREE.WebGLRenderer.prototype, {
  19963. supportsFloatTextures: function () {
  19964. console.warn( 'THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).' );
  19965. return this.extensions.get( 'OES_texture_float' );
  19966. },
  19967. supportsHalfFloatTextures: function () {
  19968. console.warn( 'THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).' );
  19969. return this.extensions.get( 'OES_texture_half_float' );
  19970. },
  19971. supportsStandardDerivatives: function () {
  19972. console.warn( 'THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).' );
  19973. return this.extensions.get( 'OES_standard_derivatives' );
  19974. },
  19975. supportsCompressedTextureS3TC: function () {
  19976. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).' );
  19977. return this.extensions.get( 'WEBGL_compressed_texture_s3tc' );
  19978. },
  19979. supportsCompressedTexturePVRTC: function () {
  19980. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).' );
  19981. return this.extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  19982. },
  19983. supportsBlendMinMax: function () {
  19984. console.warn( 'THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).' );
  19985. return this.extensions.get( 'EXT_blend_minmax' );
  19986. },
  19987. supportsVertexTextures: function () {
  19988. return this.capabilities.vertexTextures;
  19989. },
  19990. supportsInstancedArrays: function () {
  19991. console.warn( 'THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).' );
  19992. return this.extensions.get( 'ANGLE_instanced_arrays' );
  19993. },
  19994. enableScissorTest: function ( boolean ) {
  19995. console.warn( 'THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().' );
  19996. this.setScissorTest( boolean );
  19997. },
  19998. initMaterial: function () {
  19999. console.warn( 'THREE.WebGLRenderer: .initMaterial() has been removed.' );
  20000. },
  20001. addPrePlugin: function () {
  20002. console.warn( 'THREE.WebGLRenderer: .addPrePlugin() has been removed.' );
  20003. },
  20004. addPostPlugin: function () {
  20005. console.warn( 'THREE.WebGLRenderer: .addPostPlugin() has been removed.' );
  20006. },
  20007. updateShadowMap: function () {
  20008. console.warn( 'THREE.WebGLRenderer: .updateShadowMap() has been removed.' );
  20009. }
  20010. } );
  20011. Object.defineProperties( THREE.WebGLRenderer.prototype, {
  20012. shadowMapEnabled: {
  20013. get: function () {
  20014. return this.shadowMap.enabled;
  20015. },
  20016. set: function ( value ) {
  20017. console.warn( 'THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.' );
  20018. this.shadowMap.enabled = value;
  20019. }
  20020. },
  20021. shadowMapType: {
  20022. get: function () {
  20023. return this.shadowMap.type;
  20024. },
  20025. set: function ( value ) {
  20026. console.warn( 'THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.' );
  20027. this.shadowMap.type = value;
  20028. }
  20029. },
  20030. shadowMapCullFace: {
  20031. get: function () {
  20032. return this.shadowMap.cullFace;
  20033. },
  20034. set: function ( value ) {
  20035. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace is now .shadowMap.cullFace.' );
  20036. this.shadowMap.cullFace = value;
  20037. }
  20038. }
  20039. } );
  20040. Object.defineProperties( THREE.WebGLShadowMap.prototype, {
  20041. cullFace: {
  20042. get: function () {
  20043. return this.renderReverseSided ? THREE.CullFaceFront : THREE.CullFaceBack;
  20044. },
  20045. set: function ( cullFace ) {
  20046. var value = ( cullFace !== THREE.CullFaceBack );
  20047. console.warn( "WebGLRenderer: .shadowMap.cullFace is deprecated. Set .shadowMap.renderReverseSided to " + value + "." );
  20048. this.renderReverseSided = value;
  20049. }
  20050. }
  20051. } );
  20052. //
  20053. Object.defineProperties( THREE.WebGLRenderTarget.prototype, {
  20054. wrapS: {
  20055. get: function () {
  20056. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  20057. return this.texture.wrapS;
  20058. },
  20059. set: function ( value ) {
  20060. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  20061. this.texture.wrapS = value;
  20062. }
  20063. },
  20064. wrapT: {
  20065. get: function () {
  20066. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  20067. return this.texture.wrapT;
  20068. },
  20069. set: function ( value ) {
  20070. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  20071. this.texture.wrapT = value;
  20072. }
  20073. },
  20074. magFilter: {
  20075. get: function () {
  20076. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  20077. return this.texture.magFilter;
  20078. },
  20079. set: function ( value ) {
  20080. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  20081. this.texture.magFilter = value;
  20082. }
  20083. },
  20084. minFilter: {
  20085. get: function () {
  20086. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  20087. return this.texture.minFilter;
  20088. },
  20089. set: function ( value ) {
  20090. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  20091. this.texture.minFilter = value;
  20092. }
  20093. },
  20094. anisotropy: {
  20095. get: function () {
  20096. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  20097. return this.texture.anisotropy;
  20098. },
  20099. set: function ( value ) {
  20100. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  20101. this.texture.anisotropy = value;
  20102. }
  20103. },
  20104. offset: {
  20105. get: function () {
  20106. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  20107. return this.texture.offset;
  20108. },
  20109. set: function ( value ) {
  20110. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  20111. this.texture.offset = value;
  20112. }
  20113. },
  20114. repeat: {
  20115. get: function () {
  20116. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  20117. return this.texture.repeat;
  20118. },
  20119. set: function ( value ) {
  20120. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  20121. this.texture.repeat = value;
  20122. }
  20123. },
  20124. format: {
  20125. get: function () {
  20126. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  20127. return this.texture.format;
  20128. },
  20129. set: function ( value ) {
  20130. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  20131. this.texture.format = value;
  20132. }
  20133. },
  20134. type: {
  20135. get: function () {
  20136. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  20137. return this.texture.type;
  20138. },
  20139. set: function ( value ) {
  20140. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  20141. this.texture.type = value;
  20142. }
  20143. },
  20144. generateMipmaps: {
  20145. get: function () {
  20146. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  20147. return this.texture.generateMipmaps;
  20148. },
  20149. set: function ( value ) {
  20150. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  20151. this.texture.generateMipmaps = value;
  20152. }
  20153. }
  20154. } );
  20155. //
  20156. Object.assign( THREE.Audio.prototype, {
  20157. load: function ( file ) {
  20158. console.warn( 'THREE.Audio: .load has been deprecated. Please use THREE.AudioLoader.' );
  20159. var scope = this;
  20160. var audioLoader = new THREE.AudioLoader();
  20161. audioLoader.load( file, function ( buffer ) {
  20162. scope.setBuffer( buffer );
  20163. } );
  20164. return this;
  20165. }
  20166. } );
  20167. Object.assign( THREE.AudioAnalyser.prototype, {
  20168. getData: function ( file ) {
  20169. console.warn( 'THREE.AudioAnalyser: .getData() is now .getFrequencyData().' );
  20170. return this.getFrequencyData();
  20171. }
  20172. } );
  20173. //
  20174. THREE.GeometryUtils = {
  20175. merge: function ( geometry1, geometry2, materialIndexOffset ) {
  20176. console.warn( 'THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.' );
  20177. var matrix;
  20178. if ( geometry2 instanceof THREE.Mesh ) {
  20179. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  20180. matrix = geometry2.matrix;
  20181. geometry2 = geometry2.geometry;
  20182. }
  20183. geometry1.merge( geometry2, matrix, materialIndexOffset );
  20184. },
  20185. center: function ( geometry ) {
  20186. console.warn( 'THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.' );
  20187. return geometry.center();
  20188. }
  20189. };
  20190. THREE.ImageUtils = {
  20191. crossOrigin: undefined,
  20192. loadTexture: function ( url, mapping, onLoad, onError ) {
  20193. console.warn( 'THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.' );
  20194. var loader = new THREE.TextureLoader();
  20195. loader.setCrossOrigin( this.crossOrigin );
  20196. var texture = loader.load( url, onLoad, undefined, onError );
  20197. if ( mapping ) texture.mapping = mapping;
  20198. return texture;
  20199. },
  20200. loadTextureCube: function ( urls, mapping, onLoad, onError ) {
  20201. console.warn( 'THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.' );
  20202. var loader = new THREE.CubeTextureLoader();
  20203. loader.setCrossOrigin( this.crossOrigin );
  20204. var texture = loader.load( urls, onLoad, undefined, onError );
  20205. if ( mapping ) texture.mapping = mapping;
  20206. return texture;
  20207. },
  20208. loadCompressedTexture: function () {
  20209. console.error( 'THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.' );
  20210. },
  20211. loadCompressedTextureCube: function () {
  20212. console.error( 'THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.' );
  20213. }
  20214. };
  20215. //
  20216. THREE.Projector = function () {
  20217. console.error( 'THREE.Projector has been moved to /examples/js/renderers/Projector.js.' );
  20218. this.projectVector = function ( vector, camera ) {
  20219. console.warn( 'THREE.Projector: .projectVector() is now vector.project().' );
  20220. vector.project( camera );
  20221. };
  20222. this.unprojectVector = function ( vector, camera ) {
  20223. console.warn( 'THREE.Projector: .unprojectVector() is now vector.unproject().' );
  20224. vector.unproject( camera );
  20225. };
  20226. this.pickingRay = function ( vector, camera ) {
  20227. console.error( 'THREE.Projector: .pickingRay() is now raycaster.setFromCamera().' );
  20228. };
  20229. };
  20230. //
  20231. THREE.CanvasRenderer = function () {
  20232. console.error( 'THREE.CanvasRenderer has been moved to /examples/js/renderers/CanvasRenderer.js' );
  20233. this.domElement = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  20234. this.clear = function () {};
  20235. this.render = function () {};
  20236. this.setClearColor = function () {};
  20237. this.setSize = function () {};
  20238. };
  20239. // File:src/extras/CurveUtils.js
  20240. /**
  20241. * @author zz85 / http://www.lab4games.net/zz85/blog
  20242. */
  20243. THREE.CurveUtils = {
  20244. tangentQuadraticBezier: function ( t, p0, p1, p2 ) {
  20245. return 2 * ( 1 - t ) * ( p1 - p0 ) + 2 * t * ( p2 - p1 );
  20246. },
  20247. // Puay Bing, thanks for helping with this derivative!
  20248. tangentCubicBezier: function ( t, p0, p1, p2, p3 ) {
  20249. return - 3 * p0 * ( 1 - t ) * ( 1 - t ) +
  20250. 3 * p1 * ( 1 - t ) * ( 1 - t ) - 6 * t * p1 * ( 1 - t ) +
  20251. 6 * t * p2 * ( 1 - t ) - 3 * t * t * p2 +
  20252. 3 * t * t * p3;
  20253. },
  20254. tangentSpline: function ( t, p0, p1, p2, p3 ) {
  20255. // To check if my formulas are correct
  20256. var h00 = 6 * t * t - 6 * t; // derived from 2t^3 − 3t^2 + 1
  20257. var h10 = 3 * t * t - 4 * t + 1; // t^3 − 2t^2 + t
  20258. var h01 = - 6 * t * t + 6 * t; // − 2t3 + 3t2
  20259. var h11 = 3 * t * t - 2 * t; // t3 − t2
  20260. return h00 + h10 + h01 + h11;
  20261. },
  20262. // Catmull-Rom
  20263. interpolate: function( p0, p1, p2, p3, t ) {
  20264. var v0 = ( p2 - p0 ) * 0.5;
  20265. var v1 = ( p3 - p1 ) * 0.5;
  20266. var t2 = t * t;
  20267. var t3 = t * t2;
  20268. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  20269. }
  20270. };
  20271. // File:src/extras/SceneUtils.js
  20272. /**
  20273. * @author alteredq / http://alteredqualia.com/
  20274. */
  20275. THREE.SceneUtils = {
  20276. createMultiMaterialObject: function ( geometry, materials ) {
  20277. var group = new THREE.Group();
  20278. for ( var i = 0, l = materials.length; i < l; i ++ ) {
  20279. group.add( new THREE.Mesh( geometry, materials[ i ] ) );
  20280. }
  20281. return group;
  20282. },
  20283. detach: function ( child, parent, scene ) {
  20284. child.applyMatrix( parent.matrixWorld );
  20285. parent.remove( child );
  20286. scene.add( child );
  20287. },
  20288. attach: function ( child, scene, parent ) {
  20289. var matrixWorldInverse = new THREE.Matrix4();
  20290. matrixWorldInverse.getInverse( parent.matrixWorld );
  20291. child.applyMatrix( matrixWorldInverse );
  20292. scene.remove( child );
  20293. parent.add( child );
  20294. }
  20295. };
  20296. // File:src/extras/ShapeUtils.js
  20297. /**
  20298. * @author zz85 / http://www.lab4games.net/zz85/blog
  20299. */
  20300. THREE.ShapeUtils = {
  20301. // calculate area of the contour polygon
  20302. area: function ( contour ) {
  20303. var n = contour.length;
  20304. var a = 0.0;
  20305. for ( var p = n - 1, q = 0; q < n; p = q ++ ) {
  20306. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  20307. }
  20308. return a * 0.5;
  20309. },
  20310. triangulate: ( function () {
  20311. /**
  20312. * This code is a quick port of code written in C++ which was submitted to
  20313. * flipcode.com by John W. Ratcliff // July 22, 2000
  20314. * See original code and more information here:
  20315. * http://www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml
  20316. *
  20317. * ported to actionscript by Zevan Rosser
  20318. * www.actionsnippet.com
  20319. *
  20320. * ported to javascript by Joshua Koo
  20321. * http://www.lab4games.net/zz85/blog
  20322. *
  20323. */
  20324. function snip( contour, u, v, w, n, verts ) {
  20325. var p;
  20326. var ax, ay, bx, by;
  20327. var cx, cy, px, py;
  20328. ax = contour[ verts[ u ] ].x;
  20329. ay = contour[ verts[ u ] ].y;
  20330. bx = contour[ verts[ v ] ].x;
  20331. by = contour[ verts[ v ] ].y;
  20332. cx = contour[ verts[ w ] ].x;
  20333. cy = contour[ verts[ w ] ].y;
  20334. if ( Number.EPSILON > ( ( ( bx - ax ) * ( cy - ay ) ) - ( ( by - ay ) * ( cx - ax ) ) ) ) return false;
  20335. var aX, aY, bX, bY, cX, cY;
  20336. var apx, apy, bpx, bpy, cpx, cpy;
  20337. var cCROSSap, bCROSScp, aCROSSbp;
  20338. aX = cx - bx; aY = cy - by;
  20339. bX = ax - cx; bY = ay - cy;
  20340. cX = bx - ax; cY = by - ay;
  20341. for ( p = 0; p < n; p ++ ) {
  20342. px = contour[ verts[ p ] ].x;
  20343. py = contour[ verts[ p ] ].y;
  20344. if ( ( ( px === ax ) && ( py === ay ) ) ||
  20345. ( ( px === bx ) && ( py === by ) ) ||
  20346. ( ( px === cx ) && ( py === cy ) ) ) continue;
  20347. apx = px - ax; apy = py - ay;
  20348. bpx = px - bx; bpy = py - by;
  20349. cpx = px - cx; cpy = py - cy;
  20350. // see if p is inside triangle abc
  20351. aCROSSbp = aX * bpy - aY * bpx;
  20352. cCROSSap = cX * apy - cY * apx;
  20353. bCROSScp = bX * cpy - bY * cpx;
  20354. if ( ( aCROSSbp >= - Number.EPSILON ) && ( bCROSScp >= - Number.EPSILON ) && ( cCROSSap >= - Number.EPSILON ) ) return false;
  20355. }
  20356. return true;
  20357. }
  20358. // takes in an contour array and returns
  20359. return function triangulate( contour, indices ) {
  20360. var n = contour.length;
  20361. if ( n < 3 ) return null;
  20362. var result = [],
  20363. verts = [],
  20364. vertIndices = [];
  20365. /* we want a counter-clockwise polygon in verts */
  20366. var u, v, w;
  20367. if ( THREE.ShapeUtils.area( contour ) > 0.0 ) {
  20368. for ( v = 0; v < n; v ++ ) verts[ v ] = v;
  20369. } else {
  20370. for ( v = 0; v < n; v ++ ) verts[ v ] = ( n - 1 ) - v;
  20371. }
  20372. var nv = n;
  20373. /* remove nv - 2 vertices, creating 1 triangle every time */
  20374. var count = 2 * nv; /* error detection */
  20375. for ( v = nv - 1; nv > 2; ) {
  20376. /* if we loop, it is probably a non-simple polygon */
  20377. if ( ( count -- ) <= 0 ) {
  20378. //** Triangulate: ERROR - probable bad polygon!
  20379. //throw ( "Warning, unable to triangulate polygon!" );
  20380. //return null;
  20381. // Sometimes warning is fine, especially polygons are triangulated in reverse.
  20382. console.warn( 'THREE.ShapeUtils: Unable to triangulate polygon! in triangulate()' );
  20383. if ( indices ) return vertIndices;
  20384. return result;
  20385. }
  20386. /* three consecutive vertices in current polygon, <u,v,w> */
  20387. u = v; if ( nv <= u ) u = 0; /* previous */
  20388. v = u + 1; if ( nv <= v ) v = 0; /* new v */
  20389. w = v + 1; if ( nv <= w ) w = 0; /* next */
  20390. if ( snip( contour, u, v, w, nv, verts ) ) {
  20391. var a, b, c, s, t;
  20392. /* true names of the vertices */
  20393. a = verts[ u ];
  20394. b = verts[ v ];
  20395. c = verts[ w ];
  20396. /* output Triangle */
  20397. result.push( [ contour[ a ],
  20398. contour[ b ],
  20399. contour[ c ] ] );
  20400. vertIndices.push( [ verts[ u ], verts[ v ], verts[ w ] ] );
  20401. /* remove v from the remaining polygon */
  20402. for ( s = v, t = v + 1; t < nv; s ++, t ++ ) {
  20403. verts[ s ] = verts[ t ];
  20404. }
  20405. nv --;
  20406. /* reset error detection counter */
  20407. count = 2 * nv;
  20408. }
  20409. }
  20410. if ( indices ) return vertIndices;
  20411. return result;
  20412. }
  20413. } )(),
  20414. triangulateShape: function ( contour, holes ) {
  20415. function removeDupEndPts(points) {
  20416. var l = points.length;
  20417. if ( l > 2 && points[ l - 1 ].equals( points[ 0 ] ) ) {
  20418. points.pop();
  20419. }
  20420. }
  20421. removeDupEndPts( contour );
  20422. holes.forEach( removeDupEndPts );
  20423. function point_in_segment_2D_colin( inSegPt1, inSegPt2, inOtherPt ) {
  20424. // inOtherPt needs to be collinear to the inSegment
  20425. if ( inSegPt1.x !== inSegPt2.x ) {
  20426. if ( inSegPt1.x < inSegPt2.x ) {
  20427. return ( ( inSegPt1.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt2.x ) );
  20428. } else {
  20429. return ( ( inSegPt2.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt1.x ) );
  20430. }
  20431. } else {
  20432. if ( inSegPt1.y < inSegPt2.y ) {
  20433. return ( ( inSegPt1.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt2.y ) );
  20434. } else {
  20435. return ( ( inSegPt2.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt1.y ) );
  20436. }
  20437. }
  20438. }
  20439. function intersect_segments_2D( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1, inSeg2Pt2, inExcludeAdjacentSegs ) {
  20440. var seg1dx = inSeg1Pt2.x - inSeg1Pt1.x, seg1dy = inSeg1Pt2.y - inSeg1Pt1.y;
  20441. var seg2dx = inSeg2Pt2.x - inSeg2Pt1.x, seg2dy = inSeg2Pt2.y - inSeg2Pt1.y;
  20442. var seg1seg2dx = inSeg1Pt1.x - inSeg2Pt1.x;
  20443. var seg1seg2dy = inSeg1Pt1.y - inSeg2Pt1.y;
  20444. var limit = seg1dy * seg2dx - seg1dx * seg2dy;
  20445. var perpSeg1 = seg1dy * seg1seg2dx - seg1dx * seg1seg2dy;
  20446. if ( Math.abs( limit ) > Number.EPSILON ) {
  20447. // not parallel
  20448. var perpSeg2;
  20449. if ( limit > 0 ) {
  20450. if ( ( perpSeg1 < 0 ) || ( perpSeg1 > limit ) ) return [];
  20451. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  20452. if ( ( perpSeg2 < 0 ) || ( perpSeg2 > limit ) ) return [];
  20453. } else {
  20454. if ( ( perpSeg1 > 0 ) || ( perpSeg1 < limit ) ) return [];
  20455. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  20456. if ( ( perpSeg2 > 0 ) || ( perpSeg2 < limit ) ) return [];
  20457. }
  20458. // i.e. to reduce rounding errors
  20459. // intersection at endpoint of segment#1?
  20460. if ( perpSeg2 === 0 ) {
  20461. if ( ( inExcludeAdjacentSegs ) &&
  20462. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  20463. return [ inSeg1Pt1 ];
  20464. }
  20465. if ( perpSeg2 === limit ) {
  20466. if ( ( inExcludeAdjacentSegs ) &&
  20467. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  20468. return [ inSeg1Pt2 ];
  20469. }
  20470. // intersection at endpoint of segment#2?
  20471. if ( perpSeg1 === 0 ) return [ inSeg2Pt1 ];
  20472. if ( perpSeg1 === limit ) return [ inSeg2Pt2 ];
  20473. // return real intersection point
  20474. var factorSeg1 = perpSeg2 / limit;
  20475. return [ { x: inSeg1Pt1.x + factorSeg1 * seg1dx,
  20476. y: inSeg1Pt1.y + factorSeg1 * seg1dy } ];
  20477. } else {
  20478. // parallel or collinear
  20479. if ( ( perpSeg1 !== 0 ) ||
  20480. ( seg2dy * seg1seg2dx !== seg2dx * seg1seg2dy ) ) return [];
  20481. // they are collinear or degenerate
  20482. var seg1Pt = ( ( seg1dx === 0 ) && ( seg1dy === 0 ) ); // segment1 is just a point?
  20483. var seg2Pt = ( ( seg2dx === 0 ) && ( seg2dy === 0 ) ); // segment2 is just a point?
  20484. // both segments are points
  20485. if ( seg1Pt && seg2Pt ) {
  20486. if ( ( inSeg1Pt1.x !== inSeg2Pt1.x ) ||
  20487. ( inSeg1Pt1.y !== inSeg2Pt1.y ) ) return []; // they are distinct points
  20488. return [ inSeg1Pt1 ]; // they are the same point
  20489. }
  20490. // segment#1 is a single point
  20491. if ( seg1Pt ) {
  20492. if ( ! point_in_segment_2D_colin( inSeg2Pt1, inSeg2Pt2, inSeg1Pt1 ) ) return []; // but not in segment#2
  20493. return [ inSeg1Pt1 ];
  20494. }
  20495. // segment#2 is a single point
  20496. if ( seg2Pt ) {
  20497. if ( ! point_in_segment_2D_colin( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1 ) ) return []; // but not in segment#1
  20498. return [ inSeg2Pt1 ];
  20499. }
  20500. // they are collinear segments, which might overlap
  20501. var seg1min, seg1max, seg1minVal, seg1maxVal;
  20502. var seg2min, seg2max, seg2minVal, seg2maxVal;
  20503. if ( seg1dx !== 0 ) {
  20504. // the segments are NOT on a vertical line
  20505. if ( inSeg1Pt1.x < inSeg1Pt2.x ) {
  20506. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.x;
  20507. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.x;
  20508. } else {
  20509. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.x;
  20510. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.x;
  20511. }
  20512. if ( inSeg2Pt1.x < inSeg2Pt2.x ) {
  20513. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.x;
  20514. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.x;
  20515. } else {
  20516. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.x;
  20517. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.x;
  20518. }
  20519. } else {
  20520. // the segments are on a vertical line
  20521. if ( inSeg1Pt1.y < inSeg1Pt2.y ) {
  20522. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.y;
  20523. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.y;
  20524. } else {
  20525. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.y;
  20526. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.y;
  20527. }
  20528. if ( inSeg2Pt1.y < inSeg2Pt2.y ) {
  20529. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.y;
  20530. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.y;
  20531. } else {
  20532. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.y;
  20533. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.y;
  20534. }
  20535. }
  20536. if ( seg1minVal <= seg2minVal ) {
  20537. if ( seg1maxVal < seg2minVal ) return [];
  20538. if ( seg1maxVal === seg2minVal ) {
  20539. if ( inExcludeAdjacentSegs ) return [];
  20540. return [ seg2min ];
  20541. }
  20542. if ( seg1maxVal <= seg2maxVal ) return [ seg2min, seg1max ];
  20543. return [ seg2min, seg2max ];
  20544. } else {
  20545. if ( seg1minVal > seg2maxVal ) return [];
  20546. if ( seg1minVal === seg2maxVal ) {
  20547. if ( inExcludeAdjacentSegs ) return [];
  20548. return [ seg1min ];
  20549. }
  20550. if ( seg1maxVal <= seg2maxVal ) return [ seg1min, seg1max ];
  20551. return [ seg1min, seg2max ];
  20552. }
  20553. }
  20554. }
  20555. function isPointInsideAngle( inVertex, inLegFromPt, inLegToPt, inOtherPt ) {
  20556. // The order of legs is important
  20557. // translation of all points, so that Vertex is at (0,0)
  20558. var legFromPtX = inLegFromPt.x - inVertex.x, legFromPtY = inLegFromPt.y - inVertex.y;
  20559. var legToPtX = inLegToPt.x - inVertex.x, legToPtY = inLegToPt.y - inVertex.y;
  20560. var otherPtX = inOtherPt.x - inVertex.x, otherPtY = inOtherPt.y - inVertex.y;
  20561. // main angle >0: < 180 deg.; 0: 180 deg.; <0: > 180 deg.
  20562. var from2toAngle = legFromPtX * legToPtY - legFromPtY * legToPtX;
  20563. var from2otherAngle = legFromPtX * otherPtY - legFromPtY * otherPtX;
  20564. if ( Math.abs( from2toAngle ) > Number.EPSILON ) {
  20565. // angle != 180 deg.
  20566. var other2toAngle = otherPtX * legToPtY - otherPtY * legToPtX;
  20567. // console.log( "from2to: " + from2toAngle + ", from2other: " + from2otherAngle + ", other2to: " + other2toAngle );
  20568. if ( from2toAngle > 0 ) {
  20569. // main angle < 180 deg.
  20570. return ( ( from2otherAngle >= 0 ) && ( other2toAngle >= 0 ) );
  20571. } else {
  20572. // main angle > 180 deg.
  20573. return ( ( from2otherAngle >= 0 ) || ( other2toAngle >= 0 ) );
  20574. }
  20575. } else {
  20576. // angle == 180 deg.
  20577. // console.log( "from2to: 180 deg., from2other: " + from2otherAngle );
  20578. return ( from2otherAngle > 0 );
  20579. }
  20580. }
  20581. function removeHoles( contour, holes ) {
  20582. var shape = contour.concat(); // work on this shape
  20583. var hole;
  20584. function isCutLineInsideAngles( inShapeIdx, inHoleIdx ) {
  20585. // Check if hole point lies within angle around shape point
  20586. var lastShapeIdx = shape.length - 1;
  20587. var prevShapeIdx = inShapeIdx - 1;
  20588. if ( prevShapeIdx < 0 ) prevShapeIdx = lastShapeIdx;
  20589. var nextShapeIdx = inShapeIdx + 1;
  20590. if ( nextShapeIdx > lastShapeIdx ) nextShapeIdx = 0;
  20591. var insideAngle = isPointInsideAngle( shape[ inShapeIdx ], shape[ prevShapeIdx ], shape[ nextShapeIdx ], hole[ inHoleIdx ] );
  20592. if ( ! insideAngle ) {
  20593. // console.log( "Vertex (Shape): " + inShapeIdx + ", Point: " + hole[inHoleIdx].x + "/" + hole[inHoleIdx].y );
  20594. return false;
  20595. }
  20596. // Check if shape point lies within angle around hole point
  20597. var lastHoleIdx = hole.length - 1;
  20598. var prevHoleIdx = inHoleIdx - 1;
  20599. if ( prevHoleIdx < 0 ) prevHoleIdx = lastHoleIdx;
  20600. var nextHoleIdx = inHoleIdx + 1;
  20601. if ( nextHoleIdx > lastHoleIdx ) nextHoleIdx = 0;
  20602. insideAngle = isPointInsideAngle( hole[ inHoleIdx ], hole[ prevHoleIdx ], hole[ nextHoleIdx ], shape[ inShapeIdx ] );
  20603. if ( ! insideAngle ) {
  20604. // console.log( "Vertex (Hole): " + inHoleIdx + ", Point: " + shape[inShapeIdx].x + "/" + shape[inShapeIdx].y );
  20605. return false;
  20606. }
  20607. return true;
  20608. }
  20609. function intersectsShapeEdge( inShapePt, inHolePt ) {
  20610. // checks for intersections with shape edges
  20611. var sIdx, nextIdx, intersection;
  20612. for ( sIdx = 0; sIdx < shape.length; sIdx ++ ) {
  20613. nextIdx = sIdx + 1; nextIdx %= shape.length;
  20614. intersection = intersect_segments_2D( inShapePt, inHolePt, shape[ sIdx ], shape[ nextIdx ], true );
  20615. if ( intersection.length > 0 ) return true;
  20616. }
  20617. return false;
  20618. }
  20619. var indepHoles = [];
  20620. function intersectsHoleEdge( inShapePt, inHolePt ) {
  20621. // checks for intersections with hole edges
  20622. var ihIdx, chkHole,
  20623. hIdx, nextIdx, intersection;
  20624. for ( ihIdx = 0; ihIdx < indepHoles.length; ihIdx ++ ) {
  20625. chkHole = holes[ indepHoles[ ihIdx ]];
  20626. for ( hIdx = 0; hIdx < chkHole.length; hIdx ++ ) {
  20627. nextIdx = hIdx + 1; nextIdx %= chkHole.length;
  20628. intersection = intersect_segments_2D( inShapePt, inHolePt, chkHole[ hIdx ], chkHole[ nextIdx ], true );
  20629. if ( intersection.length > 0 ) return true;
  20630. }
  20631. }
  20632. return false;
  20633. }
  20634. var holeIndex, shapeIndex,
  20635. shapePt, holePt,
  20636. holeIdx, cutKey, failedCuts = [],
  20637. tmpShape1, tmpShape2,
  20638. tmpHole1, tmpHole2;
  20639. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  20640. indepHoles.push( h );
  20641. }
  20642. var minShapeIndex = 0;
  20643. var counter = indepHoles.length * 2;
  20644. while ( indepHoles.length > 0 ) {
  20645. counter --;
  20646. if ( counter < 0 ) {
  20647. console.log( "Infinite Loop! Holes left:" + indepHoles.length + ", Probably Hole outside Shape!" );
  20648. break;
  20649. }
  20650. // search for shape-vertex and hole-vertex,
  20651. // which can be connected without intersections
  20652. for ( shapeIndex = minShapeIndex; shapeIndex < shape.length; shapeIndex ++ ) {
  20653. shapePt = shape[ shapeIndex ];
  20654. holeIndex = - 1;
  20655. // search for hole which can be reached without intersections
  20656. for ( var h = 0; h < indepHoles.length; h ++ ) {
  20657. holeIdx = indepHoles[ h ];
  20658. // prevent multiple checks
  20659. cutKey = shapePt.x + ":" + shapePt.y + ":" + holeIdx;
  20660. if ( failedCuts[ cutKey ] !== undefined ) continue;
  20661. hole = holes[ holeIdx ];
  20662. for ( var h2 = 0; h2 < hole.length; h2 ++ ) {
  20663. holePt = hole[ h2 ];
  20664. if ( ! isCutLineInsideAngles( shapeIndex, h2 ) ) continue;
  20665. if ( intersectsShapeEdge( shapePt, holePt ) ) continue;
  20666. if ( intersectsHoleEdge( shapePt, holePt ) ) continue;
  20667. holeIndex = h2;
  20668. indepHoles.splice( h, 1 );
  20669. tmpShape1 = shape.slice( 0, shapeIndex + 1 );
  20670. tmpShape2 = shape.slice( shapeIndex );
  20671. tmpHole1 = hole.slice( holeIndex );
  20672. tmpHole2 = hole.slice( 0, holeIndex + 1 );
  20673. shape = tmpShape1.concat( tmpHole1 ).concat( tmpHole2 ).concat( tmpShape2 );
  20674. minShapeIndex = shapeIndex;
  20675. // Debug only, to show the selected cuts
  20676. // glob_CutLines.push( [ shapePt, holePt ] );
  20677. break;
  20678. }
  20679. if ( holeIndex >= 0 ) break; // hole-vertex found
  20680. failedCuts[ cutKey ] = true; // remember failure
  20681. }
  20682. if ( holeIndex >= 0 ) break; // hole-vertex found
  20683. }
  20684. }
  20685. return shape; /* shape with no holes */
  20686. }
  20687. var i, il, f, face,
  20688. key, index,
  20689. allPointsMap = {};
  20690. // 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.
  20691. var allpoints = contour.concat();
  20692. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  20693. Array.prototype.push.apply( allpoints, holes[ h ] );
  20694. }
  20695. //console.log( "allpoints",allpoints, allpoints.length );
  20696. // prepare all points map
  20697. for ( i = 0, il = allpoints.length; i < il; i ++ ) {
  20698. key = allpoints[ i ].x + ":" + allpoints[ i ].y;
  20699. if ( allPointsMap[ key ] !== undefined ) {
  20700. console.warn( "THREE.ShapeUtils: Duplicate point", key, i );
  20701. }
  20702. allPointsMap[ key ] = i;
  20703. }
  20704. // remove holes by cutting paths to holes and adding them to the shape
  20705. var shapeWithoutHoles = removeHoles( contour, holes );
  20706. var triangles = THREE.ShapeUtils.triangulate( shapeWithoutHoles, false ); // True returns indices for points of spooled shape
  20707. //console.log( "triangles",triangles, triangles.length );
  20708. // check all face vertices against all points map
  20709. for ( i = 0, il = triangles.length; i < il; i ++ ) {
  20710. face = triangles[ i ];
  20711. for ( f = 0; f < 3; f ++ ) {
  20712. key = face[ f ].x + ":" + face[ f ].y;
  20713. index = allPointsMap[ key ];
  20714. if ( index !== undefined ) {
  20715. face[ f ] = index;
  20716. }
  20717. }
  20718. }
  20719. return triangles.concat();
  20720. },
  20721. isClockWise: function ( pts ) {
  20722. return THREE.ShapeUtils.area( pts ) < 0;
  20723. },
  20724. // Bezier Curves formulas obtained from
  20725. // http://en.wikipedia.org/wiki/B%C3%A9zier_curve
  20726. // Quad Bezier Functions
  20727. b2: ( function () {
  20728. function b2p0( t, p ) {
  20729. var k = 1 - t;
  20730. return k * k * p;
  20731. }
  20732. function b2p1( t, p ) {
  20733. return 2 * ( 1 - t ) * t * p;
  20734. }
  20735. function b2p2( t, p ) {
  20736. return t * t * p;
  20737. }
  20738. return function b2( t, p0, p1, p2 ) {
  20739. return b2p0( t, p0 ) + b2p1( t, p1 ) + b2p2( t, p2 );
  20740. };
  20741. } )(),
  20742. // Cubic Bezier Functions
  20743. b3: ( function () {
  20744. function b3p0( t, p ) {
  20745. var k = 1 - t;
  20746. return k * k * k * p;
  20747. }
  20748. function b3p1( t, p ) {
  20749. var k = 1 - t;
  20750. return 3 * k * k * t * p;
  20751. }
  20752. function b3p2( t, p ) {
  20753. var k = 1 - t;
  20754. return 3 * k * t * t * p;
  20755. }
  20756. function b3p3( t, p ) {
  20757. return t * t * t * p;
  20758. }
  20759. return function b3( t, p0, p1, p2, p3 ) {
  20760. return b3p0( t, p0 ) + b3p1( t, p1 ) + b3p2( t, p2 ) + b3p3( t, p3 );
  20761. };
  20762. } )()
  20763. };
  20764. // File:src/extras/core/Curve.js
  20765. /**
  20766. * @author zz85 / http://www.lab4games.net/zz85/blog
  20767. * Extensible curve object
  20768. *
  20769. * Some common of Curve methods
  20770. * .getPoint(t), getTangent(t)
  20771. * .getPointAt(u), getTagentAt(u)
  20772. * .getPoints(), .getSpacedPoints()
  20773. * .getLength()
  20774. * .updateArcLengths()
  20775. *
  20776. * This following classes subclasses THREE.Curve:
  20777. *
  20778. * -- 2d classes --
  20779. * THREE.LineCurve
  20780. * THREE.QuadraticBezierCurve
  20781. * THREE.CubicBezierCurve
  20782. * THREE.SplineCurve
  20783. * THREE.ArcCurve
  20784. * THREE.EllipseCurve
  20785. *
  20786. * -- 3d classes --
  20787. * THREE.LineCurve3
  20788. * THREE.QuadraticBezierCurve3
  20789. * THREE.CubicBezierCurve3
  20790. * THREE.SplineCurve3
  20791. *
  20792. * A series of curves can be represented as a THREE.CurvePath
  20793. *
  20794. **/
  20795. /**************************************************************
  20796. * Abstract Curve base class
  20797. **************************************************************/
  20798. THREE.Curve = function () {
  20799. };
  20800. THREE.Curve.prototype = {
  20801. constructor: THREE.Curve,
  20802. // Virtual base class method to overwrite and implement in subclasses
  20803. // - t [0 .. 1]
  20804. getPoint: function ( t ) {
  20805. console.warn( "THREE.Curve: Warning, getPoint() not implemented!" );
  20806. return null;
  20807. },
  20808. // Get point at relative position in curve according to arc length
  20809. // - u [0 .. 1]
  20810. getPointAt: function ( u ) {
  20811. var t = this.getUtoTmapping( u );
  20812. return this.getPoint( t );
  20813. },
  20814. // Get sequence of points using getPoint( t )
  20815. getPoints: function ( divisions ) {
  20816. if ( ! divisions ) divisions = 5;
  20817. var points = [];
  20818. for ( var d = 0; d <= divisions; d ++ ) {
  20819. points.push( this.getPoint( d / divisions ) );
  20820. }
  20821. return points;
  20822. },
  20823. // Get sequence of points using getPointAt( u )
  20824. getSpacedPoints: function ( divisions ) {
  20825. if ( ! divisions ) divisions = 5;
  20826. var points = [];
  20827. for ( var d = 0; d <= divisions; d ++ ) {
  20828. points.push( this.getPointAt( d / divisions ) );
  20829. }
  20830. return points;
  20831. },
  20832. // Get total curve arc length
  20833. getLength: function () {
  20834. var lengths = this.getLengths();
  20835. return lengths[ lengths.length - 1 ];
  20836. },
  20837. // Get list of cumulative segment lengths
  20838. getLengths: function ( divisions ) {
  20839. if ( ! divisions ) divisions = ( this.__arcLengthDivisions ) ? ( this.__arcLengthDivisions ) : 200;
  20840. if ( this.cacheArcLengths
  20841. && ( this.cacheArcLengths.length === divisions + 1 )
  20842. && ! this.needsUpdate ) {
  20843. //console.log( "cached", this.cacheArcLengths );
  20844. return this.cacheArcLengths;
  20845. }
  20846. this.needsUpdate = false;
  20847. var cache = [];
  20848. var current, last = this.getPoint( 0 );
  20849. var p, sum = 0;
  20850. cache.push( 0 );
  20851. for ( p = 1; p <= divisions; p ++ ) {
  20852. current = this.getPoint ( p / divisions );
  20853. sum += current.distanceTo( last );
  20854. cache.push( sum );
  20855. last = current;
  20856. }
  20857. this.cacheArcLengths = cache;
  20858. return cache; // { sums: cache, sum:sum }; Sum is in the last element.
  20859. },
  20860. updateArcLengths: function() {
  20861. this.needsUpdate = true;
  20862. this.getLengths();
  20863. },
  20864. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  20865. getUtoTmapping: function ( u, distance ) {
  20866. var arcLengths = this.getLengths();
  20867. var i = 0, il = arcLengths.length;
  20868. var targetArcLength; // The targeted u distance value to get
  20869. if ( distance ) {
  20870. targetArcLength = distance;
  20871. } else {
  20872. targetArcLength = u * arcLengths[ il - 1 ];
  20873. }
  20874. //var time = Date.now();
  20875. // binary search for the index with largest value smaller than target u distance
  20876. var low = 0, high = il - 1, comparison;
  20877. while ( low <= high ) {
  20878. 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
  20879. comparison = arcLengths[ i ] - targetArcLength;
  20880. if ( comparison < 0 ) {
  20881. low = i + 1;
  20882. } else if ( comparison > 0 ) {
  20883. high = i - 1;
  20884. } else {
  20885. high = i;
  20886. break;
  20887. // DONE
  20888. }
  20889. }
  20890. i = high;
  20891. //console.log('b' , i, low, high, Date.now()- time);
  20892. if ( arcLengths[ i ] === targetArcLength ) {
  20893. var t = i / ( il - 1 );
  20894. return t;
  20895. }
  20896. // we could get finer grain at lengths, or use simple interpolation between two points
  20897. var lengthBefore = arcLengths[ i ];
  20898. var lengthAfter = arcLengths[ i + 1 ];
  20899. var segmentLength = lengthAfter - lengthBefore;
  20900. // determine where we are between the 'before' and 'after' points
  20901. var segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  20902. // add that fractional amount to t
  20903. var t = ( i + segmentFraction ) / ( il - 1 );
  20904. return t;
  20905. },
  20906. // Returns a unit vector tangent at t
  20907. // In case any sub curve does not implement its tangent derivation,
  20908. // 2 points a small delta apart will be used to find its gradient
  20909. // which seems to give a reasonable approximation
  20910. getTangent: function( t ) {
  20911. var delta = 0.0001;
  20912. var t1 = t - delta;
  20913. var t2 = t + delta;
  20914. // Capping in case of danger
  20915. if ( t1 < 0 ) t1 = 0;
  20916. if ( t2 > 1 ) t2 = 1;
  20917. var pt1 = this.getPoint( t1 );
  20918. var pt2 = this.getPoint( t2 );
  20919. var vec = pt2.clone().sub( pt1 );
  20920. return vec.normalize();
  20921. },
  20922. getTangentAt: function ( u ) {
  20923. var t = this.getUtoTmapping( u );
  20924. return this.getTangent( t );
  20925. }
  20926. };
  20927. // TODO: Transformation for Curves?
  20928. /**************************************************************
  20929. * 3D Curves
  20930. **************************************************************/
  20931. // A Factory method for creating new curve subclasses
  20932. THREE.Curve.create = function ( constructor, getPointFunc ) {
  20933. constructor.prototype = Object.create( THREE.Curve.prototype );
  20934. constructor.prototype.constructor = constructor;
  20935. constructor.prototype.getPoint = getPointFunc;
  20936. return constructor;
  20937. };
  20938. // File:src/extras/core/CurvePath.js
  20939. /**
  20940. * @author zz85 / http://www.lab4games.net/zz85/blog
  20941. *
  20942. **/
  20943. /**************************************************************
  20944. * Curved Path - a curve path is simply a array of connected
  20945. * curves, but retains the api of a curve
  20946. **************************************************************/
  20947. THREE.CurvePath = function () {
  20948. this.curves = [];
  20949. this.autoClose = false; // Automatically closes the path
  20950. };
  20951. THREE.CurvePath.prototype = Object.assign( Object.create( THREE.Curve.prototype ), {
  20952. constructor: THREE.CurvePath,
  20953. add: function ( curve ) {
  20954. this.curves.push( curve );
  20955. },
  20956. closePath: function () {
  20957. // Add a line curve if start and end of lines are not connected
  20958. var startPoint = this.curves[ 0 ].getPoint( 0 );
  20959. var endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
  20960. if ( ! startPoint.equals( endPoint ) ) {
  20961. this.curves.push( new THREE.LineCurve( endPoint, startPoint ) );
  20962. }
  20963. },
  20964. // To get accurate point with reference to
  20965. // entire path distance at time t,
  20966. // following has to be done:
  20967. // 1. Length of each sub path have to be known
  20968. // 2. Locate and identify type of curve
  20969. // 3. Get t for the curve
  20970. // 4. Return curve.getPointAt(t')
  20971. getPoint: function ( t ) {
  20972. var d = t * this.getLength();
  20973. var curveLengths = this.getCurveLengths();
  20974. var i = 0;
  20975. // To think about boundaries points.
  20976. while ( i < curveLengths.length ) {
  20977. if ( curveLengths[ i ] >= d ) {
  20978. var diff = curveLengths[ i ] - d;
  20979. var curve = this.curves[ i ];
  20980. var segmentLength = curve.getLength();
  20981. var u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
  20982. return curve.getPointAt( u );
  20983. }
  20984. i ++;
  20985. }
  20986. return null;
  20987. // loop where sum != 0, sum > d , sum+1 <d
  20988. },
  20989. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  20990. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  20991. // getPoint() depends on getLength
  20992. getLength: function () {
  20993. var lens = this.getCurveLengths();
  20994. return lens[ lens.length - 1 ];
  20995. },
  20996. // cacheLengths must be recalculated.
  20997. updateArcLengths: function () {
  20998. this.needsUpdate = true;
  20999. this.cacheLengths = null;
  21000. this.getLengths();
  21001. },
  21002. // Compute lengths and cache them
  21003. // We cannot overwrite getLengths() because UtoT mapping uses it.
  21004. getCurveLengths: function () {
  21005. // We use cache values if curves and cache array are same length
  21006. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  21007. return this.cacheLengths;
  21008. }
  21009. // Get length of sub-curve
  21010. // Push sums into cached array
  21011. var lengths = [], sums = 0;
  21012. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  21013. sums += this.curves[ i ].getLength();
  21014. lengths.push( sums );
  21015. }
  21016. this.cacheLengths = lengths;
  21017. return lengths;
  21018. },
  21019. getSpacedPoints: function ( divisions ) {
  21020. if ( ! divisions ) divisions = 40;
  21021. var points = [];
  21022. for ( var i = 0; i <= divisions; i ++ ) {
  21023. points.push( this.getPoint( i / divisions ) );
  21024. }
  21025. if ( this.autoClose ) {
  21026. points.push( points[ 0 ] );
  21027. }
  21028. return points;
  21029. },
  21030. getPoints: function ( divisions ) {
  21031. divisions = divisions || 12;
  21032. var points = [], last;
  21033. for ( var i = 0, curves = this.curves; i < curves.length; i ++ ) {
  21034. var curve = curves[ i ];
  21035. var resolution = curve instanceof THREE.EllipseCurve ? divisions * 2
  21036. : curve instanceof THREE.LineCurve ? 1
  21037. : curve instanceof THREE.SplineCurve ? divisions * curve.points.length
  21038. : divisions;
  21039. var pts = curve.getPoints( resolution );
  21040. for ( var j = 0; j < pts.length; j++ ) {
  21041. var point = pts[ j ];
  21042. if ( last && last.equals( point ) ) continue; // ensures no consecutive points are duplicates
  21043. points.push( point );
  21044. last = point;
  21045. }
  21046. }
  21047. if ( this.autoClose && points.length > 1 && !points[ points.length - 1 ].equals( points[ 0 ] ) ) {
  21048. points.push( points[ 0 ] );
  21049. }
  21050. return points;
  21051. },
  21052. /**************************************************************
  21053. * Create Geometries Helpers
  21054. **************************************************************/
  21055. /// Generate geometry from path points (for Line or Points objects)
  21056. createPointsGeometry: function ( divisions ) {
  21057. var pts = this.getPoints( divisions );
  21058. return this.createGeometry( pts );
  21059. },
  21060. // Generate geometry from equidistant sampling along the path
  21061. createSpacedPointsGeometry: function ( divisions ) {
  21062. var pts = this.getSpacedPoints( divisions );
  21063. return this.createGeometry( pts );
  21064. },
  21065. createGeometry: function ( points ) {
  21066. var geometry = new THREE.Geometry();
  21067. for ( var i = 0, l = points.length; i < l; i ++ ) {
  21068. var point = points[ i ];
  21069. geometry.vertices.push( new THREE.Vector3( point.x, point.y, point.z || 0 ) );
  21070. }
  21071. return geometry;
  21072. }
  21073. } );
  21074. // File:src/extras/core/Font.js
  21075. /**
  21076. * @author zz85 / http://www.lab4games.net/zz85/blog
  21077. * @author mrdoob / http://mrdoob.com/
  21078. */
  21079. THREE.Font = function ( data ) {
  21080. this.data = data;
  21081. };
  21082. Object.assign( THREE.Font.prototype, {
  21083. generateShapes: function ( text, size, divisions ) {
  21084. function createPaths( text ) {
  21085. var chars = String( text ).split( '' );
  21086. var scale = size / data.resolution;
  21087. var offset = 0;
  21088. var paths = [];
  21089. for ( var i = 0; i < chars.length; i ++ ) {
  21090. var ret = createPath( chars[ i ], scale, offset );
  21091. offset += ret.offset;
  21092. paths.push( ret.path );
  21093. }
  21094. return paths;
  21095. }
  21096. function createPath( c, scale, offset ) {
  21097. var glyph = data.glyphs[ c ] || data.glyphs[ '?' ];
  21098. if ( ! glyph ) return;
  21099. var path = new THREE.ShapePath();
  21100. var pts = [], b2 = THREE.ShapeUtils.b2, b3 = THREE.ShapeUtils.b3;
  21101. var x, y, cpx, cpy, cpx0, cpy0, cpx1, cpy1, cpx2, cpy2, laste;
  21102. if ( glyph.o ) {
  21103. var outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) );
  21104. for ( var i = 0, l = outline.length; i < l; ) {
  21105. var action = outline[ i ++ ];
  21106. switch ( action ) {
  21107. case 'm': // moveTo
  21108. x = outline[ i ++ ] * scale + offset;
  21109. y = outline[ i ++ ] * scale;
  21110. path.moveTo( x, y );
  21111. break;
  21112. case 'l': // lineTo
  21113. x = outline[ i ++ ] * scale + offset;
  21114. y = outline[ i ++ ] * scale;
  21115. path.lineTo( x, y );
  21116. break;
  21117. case 'q': // quadraticCurveTo
  21118. cpx = outline[ i ++ ] * scale + offset;
  21119. cpy = outline[ i ++ ] * scale;
  21120. cpx1 = outline[ i ++ ] * scale + offset;
  21121. cpy1 = outline[ i ++ ] * scale;
  21122. path.quadraticCurveTo( cpx1, cpy1, cpx, cpy );
  21123. laste = pts[ pts.length - 1 ];
  21124. if ( laste ) {
  21125. cpx0 = laste.x;
  21126. cpy0 = laste.y;
  21127. for ( var i2 = 1; i2 <= divisions; i2 ++ ) {
  21128. var t = i2 / divisions;
  21129. b2( t, cpx0, cpx1, cpx );
  21130. b2( t, cpy0, cpy1, cpy );
  21131. }
  21132. }
  21133. break;
  21134. case 'b': // bezierCurveTo
  21135. cpx = outline[ i ++ ] * scale + offset;
  21136. cpy = outline[ i ++ ] * scale;
  21137. cpx1 = outline[ i ++ ] * scale + offset;
  21138. cpy1 = outline[ i ++ ] * scale;
  21139. cpx2 = outline[ i ++ ] * scale + offset;
  21140. cpy2 = outline[ i ++ ] * scale;
  21141. path.bezierCurveTo( cpx1, cpy1, cpx2, cpy2, cpx, cpy );
  21142. laste = pts[ pts.length - 1 ];
  21143. if ( laste ) {
  21144. cpx0 = laste.x;
  21145. cpy0 = laste.y;
  21146. for ( var i2 = 1; i2 <= divisions; i2 ++ ) {
  21147. var t = i2 / divisions;
  21148. b3( t, cpx0, cpx1, cpx2, cpx );
  21149. b3( t, cpy0, cpy1, cpy2, cpy );
  21150. }
  21151. }
  21152. break;
  21153. }
  21154. }
  21155. }
  21156. return { offset: glyph.ha * scale, path: path };
  21157. }
  21158. //
  21159. if ( size === undefined ) size = 100;
  21160. if ( divisions === undefined ) divisions = 4;
  21161. var data = this.data;
  21162. var paths = createPaths( text );
  21163. var shapes = [];
  21164. for ( var p = 0, pl = paths.length; p < pl; p ++ ) {
  21165. Array.prototype.push.apply( shapes, paths[ p ].toShapes() );
  21166. }
  21167. return shapes;
  21168. }
  21169. } );
  21170. // File:src/extras/core/Path.js
  21171. /**
  21172. * @author zz85 / http://www.lab4games.net/zz85/blog
  21173. * Creates free form 2d path using series of points, lines or curves.
  21174. *
  21175. **/
  21176. THREE.Path = function ( points ) {
  21177. THREE.CurvePath.call( this );
  21178. this.currentPoint = new THREE.Vector2();
  21179. if ( points ) {
  21180. this.fromPoints( points );
  21181. }
  21182. };
  21183. THREE.Path.prototype = Object.assign( Object.create( THREE.CurvePath.prototype ), {
  21184. constructor: THREE.Path,
  21185. // Create path using straight lines to connect all points
  21186. // - vectors: array of Vector2
  21187. fromPoints: function ( vectors ) {
  21188. this.moveTo( vectors[ 0 ].x, vectors[ 0 ].y );
  21189. for ( var i = 1, l = vectors.length; i < l; i ++ ) {
  21190. this.lineTo( vectors[ i ].x, vectors[ i ].y );
  21191. }
  21192. },
  21193. moveTo: function ( x, y ) {
  21194. this.currentPoint.set( x, y ); // TODO consider referencing vectors instead of copying?
  21195. },
  21196. lineTo: function ( x, y ) {
  21197. var curve = new THREE.LineCurve( this.currentPoint.clone(), new THREE.Vector2( x, y ) );
  21198. this.curves.push( curve );
  21199. this.currentPoint.set( x, y );
  21200. },
  21201. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  21202. var curve = new THREE.QuadraticBezierCurve(
  21203. this.currentPoint.clone(),
  21204. new THREE.Vector2( aCPx, aCPy ),
  21205. new THREE.Vector2( aX, aY )
  21206. );
  21207. this.curves.push( curve );
  21208. this.currentPoint.set( aX, aY );
  21209. },
  21210. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  21211. var curve = new THREE.CubicBezierCurve(
  21212. this.currentPoint.clone(),
  21213. new THREE.Vector2( aCP1x, aCP1y ),
  21214. new THREE.Vector2( aCP2x, aCP2y ),
  21215. new THREE.Vector2( aX, aY )
  21216. );
  21217. this.curves.push( curve );
  21218. this.currentPoint.set( aX, aY );
  21219. },
  21220. splineThru: function ( pts /*Array of Vector*/ ) {
  21221. var npts = [ this.currentPoint.clone() ].concat( pts );
  21222. var curve = new THREE.SplineCurve( npts );
  21223. this.curves.push( curve );
  21224. this.currentPoint.copy( pts[ pts.length - 1 ] );
  21225. },
  21226. arc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  21227. var x0 = this.currentPoint.x;
  21228. var y0 = this.currentPoint.y;
  21229. this.absarc( aX + x0, aY + y0, aRadius,
  21230. aStartAngle, aEndAngle, aClockwise );
  21231. },
  21232. absarc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  21233. this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  21234. },
  21235. ellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  21236. var x0 = this.currentPoint.x;
  21237. var y0 = this.currentPoint.y;
  21238. this.absellipse( aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  21239. },
  21240. absellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  21241. var curve = new THREE.EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  21242. if ( this.curves.length > 0 ) {
  21243. // if a previous curve is present, attempt to join
  21244. var firstPoint = curve.getPoint( 0 );
  21245. if ( ! firstPoint.equals( this.currentPoint ) ) {
  21246. this.lineTo( firstPoint.x, firstPoint.y );
  21247. }
  21248. }
  21249. this.curves.push( curve );
  21250. var lastPoint = curve.getPoint( 1 );
  21251. this.currentPoint.copy( lastPoint );
  21252. }
  21253. } );
  21254. // minimal class for proxing functions to Path. Replaces old "extractSubpaths()"
  21255. THREE.ShapePath = function() {
  21256. this.subPaths = [];
  21257. this.currentPath = null;
  21258. }
  21259. THREE.ShapePath.prototype = {
  21260. moveTo: function ( x, y ) {
  21261. this.currentPath = new THREE.Path();
  21262. this.subPaths.push(this.currentPath);
  21263. this.currentPath.moveTo( x, y );
  21264. },
  21265. lineTo: function ( x, y ) {
  21266. this.currentPath.lineTo( x, y );
  21267. },
  21268. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  21269. this.currentPath.quadraticCurveTo( aCPx, aCPy, aX, aY );
  21270. },
  21271. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  21272. this.currentPath.bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY );
  21273. },
  21274. splineThru: function ( pts ) {
  21275. this.currentPath.splineThru( pts );
  21276. },
  21277. toShapes: function ( isCCW, noHoles ) {
  21278. function toShapesNoHoles( inSubpaths ) {
  21279. var shapes = [];
  21280. for ( var i = 0, l = inSubpaths.length; i < l; i ++ ) {
  21281. var tmpPath = inSubpaths[ i ];
  21282. var tmpShape = new THREE.Shape();
  21283. tmpShape.curves = tmpPath.curves;
  21284. shapes.push( tmpShape );
  21285. }
  21286. return shapes;
  21287. }
  21288. function isPointInsidePolygon( inPt, inPolygon ) {
  21289. var polyLen = inPolygon.length;
  21290. // inPt on polygon contour => immediate success or
  21291. // toggling of inside/outside at every single! intersection point of an edge
  21292. // with the horizontal line through inPt, left of inPt
  21293. // not counting lowerY endpoints of edges and whole edges on that line
  21294. var inside = false;
  21295. for ( var p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  21296. var edgeLowPt = inPolygon[ p ];
  21297. var edgeHighPt = inPolygon[ q ];
  21298. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  21299. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  21300. if ( Math.abs( edgeDy ) > Number.EPSILON ) {
  21301. // not parallel
  21302. if ( edgeDy < 0 ) {
  21303. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  21304. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  21305. }
  21306. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  21307. if ( inPt.y === edgeLowPt.y ) {
  21308. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  21309. // continue; // no intersection or edgeLowPt => doesn't count !!!
  21310. } else {
  21311. var perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y );
  21312. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  21313. if ( perpEdge < 0 ) continue;
  21314. inside = ! inside; // true intersection left of inPt
  21315. }
  21316. } else {
  21317. // parallel or collinear
  21318. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  21319. // edge lies on the same horizontal line as inPt
  21320. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  21321. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  21322. // continue;
  21323. }
  21324. }
  21325. return inside;
  21326. }
  21327. var isClockWise = THREE.ShapeUtils.isClockWise;
  21328. var subPaths = this.subPaths;
  21329. if ( subPaths.length === 0 ) return [];
  21330. if ( noHoles === true ) return toShapesNoHoles( subPaths );
  21331. var solid, tmpPath, tmpShape, shapes = [];
  21332. if ( subPaths.length === 1 ) {
  21333. tmpPath = subPaths[ 0 ];
  21334. tmpShape = new THREE.Shape();
  21335. tmpShape.curves = tmpPath.curves;
  21336. shapes.push( tmpShape );
  21337. return shapes;
  21338. }
  21339. var holesFirst = ! isClockWise( subPaths[ 0 ].getPoints() );
  21340. holesFirst = isCCW ? ! holesFirst : holesFirst;
  21341. // console.log("Holes first", holesFirst);
  21342. var betterShapeHoles = [];
  21343. var newShapes = [];
  21344. var newShapeHoles = [];
  21345. var mainIdx = 0;
  21346. var tmpPoints;
  21347. newShapes[ mainIdx ] = undefined;
  21348. newShapeHoles[ mainIdx ] = [];
  21349. for ( var i = 0, l = subPaths.length; i < l; i ++ ) {
  21350. tmpPath = subPaths[ i ];
  21351. tmpPoints = tmpPath.getPoints();
  21352. solid = isClockWise( tmpPoints );
  21353. solid = isCCW ? ! solid : solid;
  21354. if ( solid ) {
  21355. if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) mainIdx ++;
  21356. newShapes[ mainIdx ] = { s: new THREE.Shape(), p: tmpPoints };
  21357. newShapes[ mainIdx ].s.curves = tmpPath.curves;
  21358. if ( holesFirst ) mainIdx ++;
  21359. newShapeHoles[ mainIdx ] = [];
  21360. //console.log('cw', i);
  21361. } else {
  21362. newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } );
  21363. //console.log('ccw', i);
  21364. }
  21365. }
  21366. // only Holes? -> probably all Shapes with wrong orientation
  21367. if ( ! newShapes[ 0 ] ) return toShapesNoHoles( subPaths );
  21368. if ( newShapes.length > 1 ) {
  21369. var ambiguous = false;
  21370. var toChange = [];
  21371. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  21372. betterShapeHoles[ sIdx ] = [];
  21373. }
  21374. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  21375. var sho = newShapeHoles[ sIdx ];
  21376. for ( var hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  21377. var ho = sho[ hIdx ];
  21378. var hole_unassigned = true;
  21379. for ( var s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  21380. if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
  21381. if ( sIdx !== s2Idx ) toChange.push( { froms: sIdx, tos: s2Idx, hole: hIdx } );
  21382. if ( hole_unassigned ) {
  21383. hole_unassigned = false;
  21384. betterShapeHoles[ s2Idx ].push( ho );
  21385. } else {
  21386. ambiguous = true;
  21387. }
  21388. }
  21389. }
  21390. if ( hole_unassigned ) {
  21391. betterShapeHoles[ sIdx ].push( ho );
  21392. }
  21393. }
  21394. }
  21395. // console.log("ambiguous: ", ambiguous);
  21396. if ( toChange.length > 0 ) {
  21397. // console.log("to change: ", toChange);
  21398. if ( ! ambiguous ) newShapeHoles = betterShapeHoles;
  21399. }
  21400. }
  21401. var tmpHoles;
  21402. for ( var i = 0, il = newShapes.length; i < il; i ++ ) {
  21403. tmpShape = newShapes[ i ].s;
  21404. shapes.push( tmpShape );
  21405. tmpHoles = newShapeHoles[ i ];
  21406. for ( var j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  21407. tmpShape.holes.push( tmpHoles[ j ].h );
  21408. }
  21409. }
  21410. //console.log("shape", shapes);
  21411. return shapes;
  21412. }
  21413. }
  21414. // File:src/extras/core/Shape.js
  21415. /**
  21416. * @author zz85 / http://www.lab4games.net/zz85/blog
  21417. * Defines a 2d shape plane using paths.
  21418. **/
  21419. // STEP 1 Create a path.
  21420. // STEP 2 Turn path into shape.
  21421. // STEP 3 ExtrudeGeometry takes in Shape/Shapes
  21422. // STEP 3a - Extract points from each shape, turn to vertices
  21423. // STEP 3b - Triangulate each shape, add faces.
  21424. THREE.Shape = function () {
  21425. THREE.Path.apply( this, arguments );
  21426. this.holes = [];
  21427. };
  21428. THREE.Shape.prototype = Object.assign( Object.create( THREE.Path.prototype ), {
  21429. constructor: THREE.Shape,
  21430. // Convenience method to return ExtrudeGeometry
  21431. extrude: function ( options ) {
  21432. return new THREE.ExtrudeGeometry( this, options );
  21433. },
  21434. // Convenience method to return ShapeGeometry
  21435. makeGeometry: function ( options ) {
  21436. return new THREE.ShapeGeometry( this, options );
  21437. },
  21438. getPointsHoles: function ( divisions ) {
  21439. var holesPts = [];
  21440. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  21441. holesPts[ i ] = this.holes[ i ].getPoints( divisions );
  21442. }
  21443. return holesPts;
  21444. },
  21445. // Get points of shape and holes (keypoints based on segments parameter)
  21446. extractAllPoints: function ( divisions ) {
  21447. return {
  21448. shape: this.getPoints( divisions ),
  21449. holes: this.getPointsHoles( divisions )
  21450. };
  21451. },
  21452. extractPoints: function ( divisions ) {
  21453. return this.extractAllPoints( divisions );
  21454. }
  21455. } );
  21456. // File:src/extras/curves/LineCurve.js
  21457. /**************************************************************
  21458. * Line
  21459. **************************************************************/
  21460. THREE.LineCurve = function ( v1, v2 ) {
  21461. this.v1 = v1;
  21462. this.v2 = v2;
  21463. };
  21464. THREE.LineCurve.prototype = Object.create( THREE.Curve.prototype );
  21465. THREE.LineCurve.prototype.constructor = THREE.LineCurve;
  21466. THREE.LineCurve.prototype.getPoint = function ( t ) {
  21467. if ( t === 1 ) {
  21468. return this.v2.clone();
  21469. }
  21470. var point = this.v2.clone().sub( this.v1 );
  21471. point.multiplyScalar( t ).add( this.v1 );
  21472. return point;
  21473. };
  21474. // Line curve is linear, so we can overwrite default getPointAt
  21475. THREE.LineCurve.prototype.getPointAt = function ( u ) {
  21476. return this.getPoint( u );
  21477. };
  21478. THREE.LineCurve.prototype.getTangent = function( t ) {
  21479. var tangent = this.v2.clone().sub( this.v1 );
  21480. return tangent.normalize();
  21481. };
  21482. // File:src/extras/curves/QuadraticBezierCurve.js
  21483. /**************************************************************
  21484. * Quadratic Bezier curve
  21485. **************************************************************/
  21486. THREE.QuadraticBezierCurve = function ( v0, v1, v2 ) {
  21487. this.v0 = v0;
  21488. this.v1 = v1;
  21489. this.v2 = v2;
  21490. };
  21491. THREE.QuadraticBezierCurve.prototype = Object.create( THREE.Curve.prototype );
  21492. THREE.QuadraticBezierCurve.prototype.constructor = THREE.QuadraticBezierCurve;
  21493. THREE.QuadraticBezierCurve.prototype.getPoint = function ( t ) {
  21494. var b2 = THREE.ShapeUtils.b2;
  21495. return new THREE.Vector2(
  21496. b2( t, this.v0.x, this.v1.x, this.v2.x ),
  21497. b2( t, this.v0.y, this.v1.y, this.v2.y )
  21498. );
  21499. };
  21500. THREE.QuadraticBezierCurve.prototype.getTangent = function( t ) {
  21501. var tangentQuadraticBezier = THREE.CurveUtils.tangentQuadraticBezier;
  21502. return new THREE.Vector2(
  21503. tangentQuadraticBezier( t, this.v0.x, this.v1.x, this.v2.x ),
  21504. tangentQuadraticBezier( t, this.v0.y, this.v1.y, this.v2.y )
  21505. ).normalize();
  21506. };
  21507. // File:src/extras/curves/CubicBezierCurve.js
  21508. /**************************************************************
  21509. * Cubic Bezier curve
  21510. **************************************************************/
  21511. THREE.CubicBezierCurve = function ( v0, v1, v2, v3 ) {
  21512. this.v0 = v0;
  21513. this.v1 = v1;
  21514. this.v2 = v2;
  21515. this.v3 = v3;
  21516. };
  21517. THREE.CubicBezierCurve.prototype = Object.create( THREE.Curve.prototype );
  21518. THREE.CubicBezierCurve.prototype.constructor = THREE.CubicBezierCurve;
  21519. THREE.CubicBezierCurve.prototype.getPoint = function ( t ) {
  21520. var b3 = THREE.ShapeUtils.b3;
  21521. return new THREE.Vector2(
  21522. b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x ),
  21523. b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y )
  21524. );
  21525. };
  21526. THREE.CubicBezierCurve.prototype.getTangent = function( t ) {
  21527. var tangentCubicBezier = THREE.CurveUtils.tangentCubicBezier;
  21528. return new THREE.Vector2(
  21529. tangentCubicBezier( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x ),
  21530. tangentCubicBezier( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y )
  21531. ).normalize();
  21532. };
  21533. // File:src/extras/curves/SplineCurve.js
  21534. /**************************************************************
  21535. * Spline curve
  21536. **************************************************************/
  21537. THREE.SplineCurve = function ( points /* array of Vector2 */ ) {
  21538. this.points = ( points == undefined ) ? [] : points;
  21539. };
  21540. THREE.SplineCurve.prototype = Object.create( THREE.Curve.prototype );
  21541. THREE.SplineCurve.prototype.constructor = THREE.SplineCurve;
  21542. THREE.SplineCurve.prototype.getPoint = function ( t ) {
  21543. var points = this.points;
  21544. var point = ( points.length - 1 ) * t;
  21545. var intPoint = Math.floor( point );
  21546. var weight = point - intPoint;
  21547. var point0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  21548. var point1 = points[ intPoint ];
  21549. var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  21550. var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  21551. var interpolate = THREE.CurveUtils.interpolate;
  21552. return new THREE.Vector2(
  21553. interpolate( point0.x, point1.x, point2.x, point3.x, weight ),
  21554. interpolate( point0.y, point1.y, point2.y, point3.y, weight )
  21555. );
  21556. };
  21557. // File:src/extras/curves/EllipseCurve.js
  21558. /**************************************************************
  21559. * Ellipse curve
  21560. **************************************************************/
  21561. THREE.EllipseCurve = function( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  21562. this.aX = aX;
  21563. this.aY = aY;
  21564. this.xRadius = xRadius;
  21565. this.yRadius = yRadius;
  21566. this.aStartAngle = aStartAngle;
  21567. this.aEndAngle = aEndAngle;
  21568. this.aClockwise = aClockwise;
  21569. this.aRotation = aRotation || 0;
  21570. };
  21571. THREE.EllipseCurve.prototype = Object.create( THREE.Curve.prototype );
  21572. THREE.EllipseCurve.prototype.constructor = THREE.EllipseCurve;
  21573. THREE.EllipseCurve.prototype.getPoint = function( t ) {
  21574. var twoPi = Math.PI * 2;
  21575. var deltaAngle = this.aEndAngle - this.aStartAngle;
  21576. var samePoints = Math.abs( deltaAngle ) < Number.EPSILON;
  21577. // ensures that deltaAngle is 0 .. 2 PI
  21578. while ( deltaAngle < 0 ) deltaAngle += twoPi;
  21579. while ( deltaAngle > twoPi ) deltaAngle -= twoPi;
  21580. if ( deltaAngle < Number.EPSILON ) {
  21581. if ( samePoints ) {
  21582. deltaAngle = 0;
  21583. } else {
  21584. deltaAngle = twoPi;
  21585. }
  21586. }
  21587. if ( this.aClockwise === true && ! samePoints ) {
  21588. if ( deltaAngle === twoPi ) {
  21589. deltaAngle = - twoPi;
  21590. } else {
  21591. deltaAngle = deltaAngle - twoPi;
  21592. }
  21593. }
  21594. var angle = this.aStartAngle + t * deltaAngle;
  21595. var x = this.aX + this.xRadius * Math.cos( angle );
  21596. var y = this.aY + this.yRadius * Math.sin( angle );
  21597. if ( this.aRotation !== 0 ) {
  21598. var cos = Math.cos( this.aRotation );
  21599. var sin = Math.sin( this.aRotation );
  21600. var tx = x - this.aX;
  21601. var ty = y - this.aY;
  21602. // Rotate the point about the center of the ellipse.
  21603. x = tx * cos - ty * sin + this.aX;
  21604. y = tx * sin + ty * cos + this.aY;
  21605. }
  21606. return new THREE.Vector2( x, y );
  21607. };
  21608. // File:src/extras/curves/ArcCurve.js
  21609. /**************************************************************
  21610. * Arc curve
  21611. **************************************************************/
  21612. THREE.ArcCurve = function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  21613. THREE.EllipseCurve.call( this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  21614. };
  21615. THREE.ArcCurve.prototype = Object.create( THREE.EllipseCurve.prototype );
  21616. THREE.ArcCurve.prototype.constructor = THREE.ArcCurve;
  21617. // File:src/extras/curves/LineCurve3.js
  21618. /**************************************************************
  21619. * Line3D
  21620. **************************************************************/
  21621. THREE.LineCurve3 = THREE.Curve.create(
  21622. function ( v1, v2 ) {
  21623. this.v1 = v1;
  21624. this.v2 = v2;
  21625. },
  21626. function ( t ) {
  21627. if ( t === 1 ) {
  21628. return this.v2.clone();
  21629. }
  21630. var vector = new THREE.Vector3();
  21631. vector.subVectors( this.v2, this.v1 ); // diff
  21632. vector.multiplyScalar( t );
  21633. vector.add( this.v1 );
  21634. return vector;
  21635. }
  21636. );
  21637. // File:src/extras/curves/QuadraticBezierCurve3.js
  21638. /**************************************************************
  21639. * Quadratic Bezier 3D curve
  21640. **************************************************************/
  21641. THREE.QuadraticBezierCurve3 = THREE.Curve.create(
  21642. function ( v0, v1, v2 ) {
  21643. this.v0 = v0;
  21644. this.v1 = v1;
  21645. this.v2 = v2;
  21646. },
  21647. function ( t ) {
  21648. var b2 = THREE.ShapeUtils.b2;
  21649. return new THREE.Vector3(
  21650. b2( t, this.v0.x, this.v1.x, this.v2.x ),
  21651. b2( t, this.v0.y, this.v1.y, this.v2.y ),
  21652. b2( t, this.v0.z, this.v1.z, this.v2.z )
  21653. );
  21654. }
  21655. );
  21656. // File:src/extras/curves/CubicBezierCurve3.js
  21657. /**************************************************************
  21658. * Cubic Bezier 3D curve
  21659. **************************************************************/
  21660. THREE.CubicBezierCurve3 = THREE.Curve.create(
  21661. function ( v0, v1, v2, v3 ) {
  21662. this.v0 = v0;
  21663. this.v1 = v1;
  21664. this.v2 = v2;
  21665. this.v3 = v3;
  21666. },
  21667. function ( t ) {
  21668. var b3 = THREE.ShapeUtils.b3;
  21669. return new THREE.Vector3(
  21670. b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x ),
  21671. b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y ),
  21672. b3( t, this.v0.z, this.v1.z, this.v2.z, this.v3.z )
  21673. );
  21674. }
  21675. );
  21676. // File:src/extras/curves/SplineCurve3.js
  21677. /**************************************************************
  21678. * Spline 3D curve
  21679. **************************************************************/
  21680. THREE.SplineCurve3 = THREE.Curve.create(
  21681. function ( points /* array of Vector3 */ ) {
  21682. console.warn( 'THREE.SplineCurve3 will be deprecated. Please use THREE.CatmullRomCurve3' );
  21683. this.points = ( points == undefined ) ? [] : points;
  21684. },
  21685. function ( t ) {
  21686. var points = this.points;
  21687. var point = ( points.length - 1 ) * t;
  21688. var intPoint = Math.floor( point );
  21689. var weight = point - intPoint;
  21690. var point0 = points[ intPoint == 0 ? intPoint : intPoint - 1 ];
  21691. var point1 = points[ intPoint ];
  21692. var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  21693. var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  21694. var interpolate = THREE.CurveUtils.interpolate;
  21695. return new THREE.Vector3(
  21696. interpolate( point0.x, point1.x, point2.x, point3.x, weight ),
  21697. interpolate( point0.y, point1.y, point2.y, point3.y, weight ),
  21698. interpolate( point0.z, point1.z, point2.z, point3.z, weight )
  21699. );
  21700. }
  21701. );
  21702. // File:src/extras/curves/CatmullRomCurve3.js
  21703. /**
  21704. * @author zz85 https://github.com/zz85
  21705. *
  21706. * Centripetal CatmullRom Curve - which is useful for avoiding
  21707. * cusps and self-intersections in non-uniform catmull rom curves.
  21708. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  21709. *
  21710. * curve.type accepts centripetal(default), chordal and catmullrom
  21711. * curve.tension is used for catmullrom which defaults to 0.5
  21712. */
  21713. THREE.CatmullRomCurve3 = ( function() {
  21714. var
  21715. tmp = new THREE.Vector3(),
  21716. px = new CubicPoly(),
  21717. py = new CubicPoly(),
  21718. pz = new CubicPoly();
  21719. /*
  21720. Based on an optimized c++ solution in
  21721. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  21722. - http://ideone.com/NoEbVM
  21723. This CubicPoly class could be used for reusing some variables and calculations,
  21724. but for three.js curve use, it could be possible inlined and flatten into a single function call
  21725. which can be placed in CurveUtils.
  21726. */
  21727. function CubicPoly() {
  21728. }
  21729. /*
  21730. * Compute coefficients for a cubic polynomial
  21731. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  21732. * such that
  21733. * p(0) = x0, p(1) = x1
  21734. * and
  21735. * p'(0) = t0, p'(1) = t1.
  21736. */
  21737. CubicPoly.prototype.init = function( x0, x1, t0, t1 ) {
  21738. this.c0 = x0;
  21739. this.c1 = t0;
  21740. this.c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  21741. this.c3 = 2 * x0 - 2 * x1 + t0 + t1;
  21742. };
  21743. CubicPoly.prototype.initNonuniformCatmullRom = function( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  21744. // compute tangents when parameterized in [t1,t2]
  21745. var t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  21746. var t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  21747. // rescale tangents for parametrization in [0,1]
  21748. t1 *= dt1;
  21749. t2 *= dt1;
  21750. // initCubicPoly
  21751. this.init( x1, x2, t1, t2 );
  21752. };
  21753. // standard Catmull-Rom spline: interpolate between x1 and x2 with previous/following points x1/x4
  21754. CubicPoly.prototype.initCatmullRom = function( x0, x1, x2, x3, tension ) {
  21755. this.init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  21756. };
  21757. CubicPoly.prototype.calc = function( t ) {
  21758. var t2 = t * t;
  21759. var t3 = t2 * t;
  21760. return this.c0 + this.c1 * t + this.c2 * t2 + this.c3 * t3;
  21761. };
  21762. // Subclass Three.js curve
  21763. return THREE.Curve.create(
  21764. function ( p /* array of Vector3 */ ) {
  21765. this.points = p || [];
  21766. this.closed = false;
  21767. },
  21768. function ( t ) {
  21769. var points = this.points,
  21770. point, intPoint, weight, l;
  21771. l = points.length;
  21772. if ( l < 2 ) console.log( 'duh, you need at least 2 points' );
  21773. point = ( l - ( this.closed ? 0 : 1 ) ) * t;
  21774. intPoint = Math.floor( point );
  21775. weight = point - intPoint;
  21776. if ( this.closed ) {
  21777. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / points.length ) + 1 ) * points.length;
  21778. } else if ( weight === 0 && intPoint === l - 1 ) {
  21779. intPoint = l - 2;
  21780. weight = 1;
  21781. }
  21782. var p0, p1, p2, p3; // 4 points
  21783. if ( this.closed || intPoint > 0 ) {
  21784. p0 = points[ ( intPoint - 1 ) % l ];
  21785. } else {
  21786. // extrapolate first point
  21787. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  21788. p0 = tmp;
  21789. }
  21790. p1 = points[ intPoint % l ];
  21791. p2 = points[ ( intPoint + 1 ) % l ];
  21792. if ( this.closed || intPoint + 2 < l ) {
  21793. p3 = points[ ( intPoint + 2 ) % l ];
  21794. } else {
  21795. // extrapolate last point
  21796. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 1 ] );
  21797. p3 = tmp;
  21798. }
  21799. if ( this.type === undefined || this.type === 'centripetal' || this.type === 'chordal' ) {
  21800. // init Centripetal / Chordal Catmull-Rom
  21801. var pow = this.type === 'chordal' ? 0.5 : 0.25;
  21802. var dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  21803. var dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  21804. var dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  21805. // safety check for repeated points
  21806. if ( dt1 < 1e-4 ) dt1 = 1.0;
  21807. if ( dt0 < 1e-4 ) dt0 = dt1;
  21808. if ( dt2 < 1e-4 ) dt2 = dt1;
  21809. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  21810. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  21811. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  21812. } else if ( this.type === 'catmullrom' ) {
  21813. var tension = this.tension !== undefined ? this.tension : 0.5;
  21814. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, tension );
  21815. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, tension );
  21816. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, tension );
  21817. }
  21818. var v = new THREE.Vector3(
  21819. px.calc( weight ),
  21820. py.calc( weight ),
  21821. pz.calc( weight )
  21822. );
  21823. return v;
  21824. }
  21825. );
  21826. } )();
  21827. // File:src/extras/curves/ClosedSplineCurve3.js
  21828. /**************************************************************
  21829. * Closed Spline 3D curve
  21830. **************************************************************/
  21831. THREE.ClosedSplineCurve3 = function ( points ) {
  21832. console.warn( 'THREE.ClosedSplineCurve3 has been deprecated. Please use THREE.CatmullRomCurve3.' );
  21833. THREE.CatmullRomCurve3.call( this, points );
  21834. this.type = 'catmullrom';
  21835. this.closed = true;
  21836. };
  21837. THREE.ClosedSplineCurve3.prototype = Object.create( THREE.CatmullRomCurve3.prototype );
  21838. // File:src/extras/geometries/BoxGeometry.js
  21839. /**
  21840. * @author mrdoob / http://mrdoob.com/
  21841. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Cube.as
  21842. */
  21843. THREE.BoxGeometry = function ( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  21844. THREE.Geometry.call( this );
  21845. this.type = 'BoxGeometry';
  21846. this.parameters = {
  21847. width: width,
  21848. height: height,
  21849. depth: depth,
  21850. widthSegments: widthSegments,
  21851. heightSegments: heightSegments,
  21852. depthSegments: depthSegments
  21853. };
  21854. this.fromBufferGeometry( new THREE.BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) );
  21855. this.mergeVertices();
  21856. };
  21857. THREE.BoxGeometry.prototype = Object.create( THREE.Geometry.prototype );
  21858. THREE.BoxGeometry.prototype.constructor = THREE.BoxGeometry;
  21859. THREE.CubeGeometry = THREE.BoxGeometry;
  21860. // File:src/extras/geometries/BoxBufferGeometry.js
  21861. /**
  21862. * @author Mugen87 / https://github.com/Mugen87
  21863. */
  21864. THREE.BoxBufferGeometry = function ( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  21865. THREE.BufferGeometry.call( this );
  21866. this.type = 'BoxBufferGeometry';
  21867. this.parameters = {
  21868. width: width,
  21869. height: height,
  21870. depth: depth,
  21871. widthSegments: widthSegments,
  21872. heightSegments: heightSegments,
  21873. depthSegments: depthSegments
  21874. };
  21875. var scope = this;
  21876. // segments
  21877. widthSegments = Math.floor( widthSegments ) || 1;
  21878. heightSegments = Math.floor( heightSegments ) || 1;
  21879. depthSegments = Math.floor( depthSegments ) || 1;
  21880. // these are used to calculate buffer length
  21881. var vertexCount = calculateVertexCount( widthSegments, heightSegments, depthSegments );
  21882. var indexCount = calculateIndexCount( widthSegments, heightSegments, depthSegments );
  21883. // buffers
  21884. var indices = new ( indexCount > 65535 ? Uint32Array : Uint16Array )( indexCount );
  21885. var vertices = new Float32Array( vertexCount * 3 );
  21886. var normals = new Float32Array( vertexCount * 3 );
  21887. var uvs = new Float32Array( vertexCount * 2 );
  21888. // offset variables
  21889. var vertexBufferOffset = 0;
  21890. var uvBufferOffset = 0;
  21891. var indexBufferOffset = 0;
  21892. var numberOfVertices = 0;
  21893. // group variables
  21894. var groupStart = 0;
  21895. // build each side of the box geometry
  21896. buildPlane( 'z', 'y', 'x', - 1, - 1, depth, height, width, depthSegments, heightSegments, 0 ); // px
  21897. buildPlane( 'z', 'y', 'x', 1, - 1, depth, height, - width, depthSegments, heightSegments, 1 ); // nx
  21898. buildPlane( 'x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2 ); // py
  21899. buildPlane( 'x', 'z', 'y', 1, - 1, width, depth, - height, widthSegments, depthSegments, 3 ); // ny
  21900. buildPlane( 'x', 'y', 'z', 1, - 1, width, height, depth, widthSegments, heightSegments, 4 ); // pz
  21901. buildPlane( 'x', 'y', 'z', - 1, - 1, width, height, - depth, widthSegments, heightSegments, 5 ); // nz
  21902. // build geometry
  21903. this.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  21904. this.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  21905. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  21906. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  21907. // helper functions
  21908. function calculateVertexCount ( w, h, d ) {
  21909. var vertices = 0;
  21910. // calculate the amount of vertices for each side (plane)
  21911. vertices += (w + 1) * (h + 1) * 2; // xy
  21912. vertices += (w + 1) * (d + 1) * 2; // xz
  21913. vertices += (d + 1) * (h + 1) * 2; // zy
  21914. return vertices;
  21915. }
  21916. function calculateIndexCount ( w, h, d ) {
  21917. var index = 0;
  21918. // calculate the amount of squares for each side
  21919. index += w * h * 2; // xy
  21920. index += w * d * 2; // xz
  21921. index += d * h * 2; // zy
  21922. return index * 6; // two triangles per square => six vertices per square
  21923. }
  21924. function buildPlane ( u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex ) {
  21925. var segmentWidth = width / gridX;
  21926. var segmentHeight = height / gridY;
  21927. var widthHalf = width / 2;
  21928. var heightHalf = height / 2;
  21929. var depthHalf = depth / 2;
  21930. var gridX1 = gridX + 1;
  21931. var gridY1 = gridY + 1;
  21932. var vertexCounter = 0;
  21933. var groupCount = 0;
  21934. var vector = new THREE.Vector3();
  21935. // generate vertices, normals and uvs
  21936. for ( var iy = 0; iy < gridY1; iy ++ ) {
  21937. var y = iy * segmentHeight - heightHalf;
  21938. for ( var ix = 0; ix < gridX1; ix ++ ) {
  21939. var x = ix * segmentWidth - widthHalf;
  21940. // set values to correct vector component
  21941. vector[ u ] = x * udir;
  21942. vector[ v ] = y * vdir;
  21943. vector[ w ] = depthHalf;
  21944. // now apply vector to vertex buffer
  21945. vertices[ vertexBufferOffset ] = vector.x;
  21946. vertices[ vertexBufferOffset + 1 ] = vector.y;
  21947. vertices[ vertexBufferOffset + 2 ] = vector.z;
  21948. // set values to correct vector component
  21949. vector[ u ] = 0;
  21950. vector[ v ] = 0;
  21951. vector[ w ] = depth > 0 ? 1 : - 1;
  21952. // now apply vector to normal buffer
  21953. normals[ vertexBufferOffset ] = vector.x;
  21954. normals[ vertexBufferOffset + 1 ] = vector.y;
  21955. normals[ vertexBufferOffset + 2 ] = vector.z;
  21956. // uvs
  21957. uvs[ uvBufferOffset ] = ix / gridX;
  21958. uvs[ uvBufferOffset + 1 ] = 1 - ( iy / gridY );
  21959. // update offsets and counters
  21960. vertexBufferOffset += 3;
  21961. uvBufferOffset += 2;
  21962. vertexCounter += 1;
  21963. }
  21964. }
  21965. // 1. you need three indices to draw a single face
  21966. // 2. a single segment consists of two faces
  21967. // 3. so we need to generate six (2*3) indices per segment
  21968. for ( iy = 0; iy < gridY; iy ++ ) {
  21969. for ( ix = 0; ix < gridX; ix ++ ) {
  21970. // indices
  21971. var a = numberOfVertices + ix + gridX1 * iy;
  21972. var b = numberOfVertices + ix + gridX1 * ( iy + 1 );
  21973. var c = numberOfVertices + ( ix + 1 ) + gridX1 * ( iy + 1 );
  21974. var d = numberOfVertices + ( ix + 1 ) + gridX1 * iy;
  21975. // face one
  21976. indices[ indexBufferOffset ] = a;
  21977. indices[ indexBufferOffset + 1 ] = b;
  21978. indices[ indexBufferOffset + 2 ] = d;
  21979. // face two
  21980. indices[ indexBufferOffset + 3 ] = b;
  21981. indices[ indexBufferOffset + 4 ] = c;
  21982. indices[ indexBufferOffset + 5 ] = d;
  21983. // update offsets and counters
  21984. indexBufferOffset += 6;
  21985. groupCount += 6;
  21986. }
  21987. }
  21988. // add a group to the geometry. this will ensure multi material support
  21989. scope.addGroup( groupStart, groupCount, materialIndex );
  21990. // calculate new start value for groups
  21991. groupStart += groupCount;
  21992. // update total number of vertices
  21993. numberOfVertices += vertexCounter;
  21994. }
  21995. };
  21996. THREE.BoxBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  21997. THREE.BoxBufferGeometry.prototype.constructor = THREE.BoxBufferGeometry;
  21998. // File:src/extras/geometries/CircleGeometry.js
  21999. /**
  22000. * @author hughes
  22001. */
  22002. THREE.CircleGeometry = function ( radius, segments, thetaStart, thetaLength ) {
  22003. THREE.Geometry.call( this );
  22004. this.type = 'CircleGeometry';
  22005. this.parameters = {
  22006. radius: radius,
  22007. segments: segments,
  22008. thetaStart: thetaStart,
  22009. thetaLength: thetaLength
  22010. };
  22011. this.fromBufferGeometry( new THREE.CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) );
  22012. };
  22013. THREE.CircleGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22014. THREE.CircleGeometry.prototype.constructor = THREE.CircleGeometry;
  22015. // File:src/extras/geometries/CircleBufferGeometry.js
  22016. /**
  22017. * @author benaadams / https://twitter.com/ben_a_adams
  22018. */
  22019. THREE.CircleBufferGeometry = function ( radius, segments, thetaStart, thetaLength ) {
  22020. THREE.BufferGeometry.call( this );
  22021. this.type = 'CircleBufferGeometry';
  22022. this.parameters = {
  22023. radius: radius,
  22024. segments: segments,
  22025. thetaStart: thetaStart,
  22026. thetaLength: thetaLength
  22027. };
  22028. radius = radius || 50;
  22029. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  22030. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  22031. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  22032. var vertices = segments + 2;
  22033. var positions = new Float32Array( vertices * 3 );
  22034. var normals = new Float32Array( vertices * 3 );
  22035. var uvs = new Float32Array( vertices * 2 );
  22036. // center data is already zero, but need to set a few extras
  22037. normals[ 2 ] = 1.0;
  22038. uvs[ 0 ] = 0.5;
  22039. uvs[ 1 ] = 0.5;
  22040. for ( var s = 0, i = 3, ii = 2 ; s <= segments; s ++, i += 3, ii += 2 ) {
  22041. var segment = thetaStart + s / segments * thetaLength;
  22042. positions[ i ] = radius * Math.cos( segment );
  22043. positions[ i + 1 ] = radius * Math.sin( segment );
  22044. normals[ i + 2 ] = 1; // normal z
  22045. uvs[ ii ] = ( positions[ i ] / radius + 1 ) / 2;
  22046. uvs[ ii + 1 ] = ( positions[ i + 1 ] / radius + 1 ) / 2;
  22047. }
  22048. var indices = [];
  22049. for ( var i = 1; i <= segments; i ++ ) {
  22050. indices.push( i, i + 1, 0 );
  22051. }
  22052. this.setIndex( new THREE.BufferAttribute( new Uint16Array( indices ), 1 ) );
  22053. this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
  22054. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  22055. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  22056. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  22057. };
  22058. THREE.CircleBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  22059. THREE.CircleBufferGeometry.prototype.constructor = THREE.CircleBufferGeometry;
  22060. // File:src/extras/geometries/CylinderBufferGeometry.js
  22061. /**
  22062. * @author Mugen87 / https://github.com/Mugen87
  22063. */
  22064. THREE.CylinderBufferGeometry = function( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  22065. THREE.BufferGeometry.call( this );
  22066. this.type = 'CylinderBufferGeometry';
  22067. this.parameters = {
  22068. radiusTop: radiusTop,
  22069. radiusBottom: radiusBottom,
  22070. height: height,
  22071. radialSegments: radialSegments,
  22072. heightSegments: heightSegments,
  22073. openEnded: openEnded,
  22074. thetaStart: thetaStart,
  22075. thetaLength: thetaLength
  22076. };
  22077. var scope = this;
  22078. radiusTop = radiusTop !== undefined ? radiusTop : 20;
  22079. radiusBottom = radiusBottom !== undefined ? radiusBottom : 20;
  22080. height = height !== undefined ? height : 100;
  22081. radialSegments = Math.floor( radialSegments ) || 8;
  22082. heightSegments = Math.floor( heightSegments ) || 1;
  22083. openEnded = openEnded !== undefined ? openEnded : false;
  22084. thetaStart = thetaStart !== undefined ? thetaStart : 0.0;
  22085. thetaLength = thetaLength !== undefined ? thetaLength : 2.0 * Math.PI;
  22086. // used to calculate buffer length
  22087. var nbCap = 0;
  22088. if ( openEnded === false ) {
  22089. if ( radiusTop > 0 ) nbCap ++;
  22090. if ( radiusBottom > 0 ) nbCap ++;
  22091. }
  22092. var vertexCount = calculateVertexCount();
  22093. var indexCount = calculateIndexCount();
  22094. // buffers
  22095. var indices = new THREE.BufferAttribute( new ( indexCount > 65535 ? Uint32Array : Uint16Array )( indexCount ), 1 );
  22096. var vertices = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  22097. var normals = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  22098. var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
  22099. // helper variables
  22100. var index = 0,
  22101. indexOffset = 0,
  22102. indexArray = [],
  22103. halfHeight = height / 2;
  22104. // group variables
  22105. var groupStart = 0;
  22106. // generate geometry
  22107. generateTorso();
  22108. if ( openEnded === false ) {
  22109. if ( radiusTop > 0 ) generateCap( true );
  22110. if ( radiusBottom > 0 ) generateCap( false );
  22111. }
  22112. // build geometry
  22113. this.setIndex( indices );
  22114. this.addAttribute( 'position', vertices );
  22115. this.addAttribute( 'normal', normals );
  22116. this.addAttribute( 'uv', uvs );
  22117. // helper functions
  22118. function calculateVertexCount() {
  22119. var count = ( radialSegments + 1 ) * ( heightSegments + 1 );
  22120. if ( openEnded === false ) {
  22121. count += ( ( radialSegments + 1 ) * nbCap ) + ( radialSegments * nbCap );
  22122. }
  22123. return count;
  22124. }
  22125. function calculateIndexCount() {
  22126. var count = radialSegments * heightSegments * 2 * 3;
  22127. if ( openEnded === false ) {
  22128. count += radialSegments * nbCap * 3;
  22129. }
  22130. return count;
  22131. }
  22132. function generateTorso() {
  22133. var x, y;
  22134. var normal = new THREE.Vector3();
  22135. var vertex = new THREE.Vector3();
  22136. var groupCount = 0;
  22137. // this will be used to calculate the normal
  22138. var tanTheta = ( radiusBottom - radiusTop ) / height;
  22139. // generate vertices, normals and uvs
  22140. for ( y = 0; y <= heightSegments; y ++ ) {
  22141. var indexRow = [];
  22142. var v = y / heightSegments;
  22143. // calculate the radius of the current row
  22144. var radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  22145. for ( x = 0; x <= radialSegments; x ++ ) {
  22146. var u = x / radialSegments;
  22147. // vertex
  22148. vertex.x = radius * Math.sin( u * thetaLength + thetaStart );
  22149. vertex.y = - v * height + halfHeight;
  22150. vertex.z = radius * Math.cos( u * thetaLength + thetaStart );
  22151. vertices.setXYZ( index, vertex.x, vertex.y, vertex.z );
  22152. // normal
  22153. normal.copy( vertex );
  22154. // handle special case if radiusTop/radiusBottom is zero
  22155. if ( ( radiusTop === 0 && y === 0 ) || ( radiusBottom === 0 && y === heightSegments ) ) {
  22156. normal.x = Math.sin( u * thetaLength + thetaStart );
  22157. normal.z = Math.cos( u * thetaLength + thetaStart );
  22158. }
  22159. normal.setY( Math.sqrt( normal.x * normal.x + normal.z * normal.z ) * tanTheta ).normalize();
  22160. normals.setXYZ( index, normal.x, normal.y, normal.z );
  22161. // uv
  22162. uvs.setXY( index, u, 1 - v );
  22163. // save index of vertex in respective row
  22164. indexRow.push( index );
  22165. // increase index
  22166. index ++;
  22167. }
  22168. // now save vertices of the row in our index array
  22169. indexArray.push( indexRow );
  22170. }
  22171. // generate indices
  22172. for ( x = 0; x < radialSegments; x ++ ) {
  22173. for ( y = 0; y < heightSegments; y ++ ) {
  22174. // we use the index array to access the correct indices
  22175. var i1 = indexArray[ y ][ x ];
  22176. var i2 = indexArray[ y + 1 ][ x ];
  22177. var i3 = indexArray[ y + 1 ][ x + 1 ];
  22178. var i4 = indexArray[ y ][ x + 1 ];
  22179. // face one
  22180. indices.setX( indexOffset, i1 ); indexOffset ++;
  22181. indices.setX( indexOffset, i2 ); indexOffset ++;
  22182. indices.setX( indexOffset, i4 ); indexOffset ++;
  22183. // face two
  22184. indices.setX( indexOffset, i2 ); indexOffset ++;
  22185. indices.setX( indexOffset, i3 ); indexOffset ++;
  22186. indices.setX( indexOffset, i4 ); indexOffset ++;
  22187. // update counters
  22188. groupCount += 6;
  22189. }
  22190. }
  22191. // add a group to the geometry. this will ensure multi material support
  22192. scope.addGroup( groupStart, groupCount, 0 );
  22193. // calculate new start value for groups
  22194. groupStart += groupCount;
  22195. }
  22196. function generateCap( top ) {
  22197. var x, centerIndexStart, centerIndexEnd;
  22198. var uv = new THREE.Vector2();
  22199. var vertex = new THREE.Vector3();
  22200. var groupCount = 0;
  22201. var radius = ( top === true ) ? radiusTop : radiusBottom;
  22202. var sign = ( top === true ) ? 1 : - 1;
  22203. // save the index of the first center vertex
  22204. centerIndexStart = index;
  22205. // first we generate the center vertex data of the cap.
  22206. // because the geometry needs one set of uvs per face,
  22207. // we must generate a center vertex per face/segment
  22208. for ( x = 1; x <= radialSegments; x ++ ) {
  22209. // vertex
  22210. vertices.setXYZ( index, 0, halfHeight * sign, 0 );
  22211. // normal
  22212. normals.setXYZ( index, 0, sign, 0 );
  22213. // uv
  22214. uv.x = 0.5;
  22215. uv.y = 0.5;
  22216. uvs.setXY( index, uv.x, uv.y );
  22217. // increase index
  22218. index ++;
  22219. }
  22220. // save the index of the last center vertex
  22221. centerIndexEnd = index;
  22222. // now we generate the surrounding vertices, normals and uvs
  22223. for ( x = 0; x <= radialSegments; x ++ ) {
  22224. var u = x / radialSegments;
  22225. var theta = u * thetaLength + thetaStart;
  22226. var cosTheta = Math.cos( theta );
  22227. var sinTheta = Math.sin( theta );
  22228. // vertex
  22229. vertex.x = radius * sinTheta;
  22230. vertex.y = halfHeight * sign;
  22231. vertex.z = radius * cosTheta;
  22232. vertices.setXYZ( index, vertex.x, vertex.y, vertex.z );
  22233. // normal
  22234. normals.setXYZ( index, 0, sign, 0 );
  22235. // uv
  22236. uv.x = ( cosTheta * 0.5 ) + 0.5;
  22237. uv.y = ( sinTheta * 0.5 * sign ) + 0.5;
  22238. uvs.setXY( index, uv.x, uv.y );
  22239. // increase index
  22240. index ++;
  22241. }
  22242. // generate indices
  22243. for ( x = 0; x < radialSegments; x ++ ) {
  22244. var c = centerIndexStart + x;
  22245. var i = centerIndexEnd + x;
  22246. if ( top === true ) {
  22247. // face top
  22248. indices.setX( indexOffset, i ); indexOffset ++;
  22249. indices.setX( indexOffset, i + 1 ); indexOffset ++;
  22250. indices.setX( indexOffset, c ); indexOffset ++;
  22251. } else {
  22252. // face bottom
  22253. indices.setX( indexOffset, i + 1 ); indexOffset ++;
  22254. indices.setX( indexOffset, i ); indexOffset ++;
  22255. indices.setX( indexOffset, c ); indexOffset ++;
  22256. }
  22257. // update counters
  22258. groupCount += 3;
  22259. }
  22260. // add a group to the geometry. this will ensure multi material support
  22261. scope.addGroup( groupStart, groupCount, top === true ? 1 : 2 );
  22262. // calculate new start value for groups
  22263. groupStart += groupCount;
  22264. }
  22265. };
  22266. THREE.CylinderBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  22267. THREE.CylinderBufferGeometry.prototype.constructor = THREE.CylinderBufferGeometry;
  22268. // File:src/extras/geometries/CylinderGeometry.js
  22269. /**
  22270. * @author mrdoob / http://mrdoob.com/
  22271. */
  22272. THREE.CylinderGeometry = function ( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  22273. THREE.Geometry.call( this );
  22274. this.type = 'CylinderGeometry';
  22275. this.parameters = {
  22276. radiusTop: radiusTop,
  22277. radiusBottom: radiusBottom,
  22278. height: height,
  22279. radialSegments: radialSegments,
  22280. heightSegments: heightSegments,
  22281. openEnded: openEnded,
  22282. thetaStart: thetaStart,
  22283. thetaLength: thetaLength
  22284. };
  22285. this.fromBufferGeometry( new THREE.CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) );
  22286. this.mergeVertices();
  22287. };
  22288. THREE.CylinderGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22289. THREE.CylinderGeometry.prototype.constructor = THREE.CylinderGeometry;
  22290. // File:src/extras/geometries/ConeBufferGeometry.js
  22291. /*
  22292. * @author: abelnation / http://github.com/abelnation
  22293. */
  22294. THREE.ConeBufferGeometry = function (
  22295. radius, height,
  22296. radialSegments, heightSegments,
  22297. openEnded, thetaStart, thetaLength ) {
  22298. THREE.CylinderBufferGeometry.call( this,
  22299. 0, radius, height,
  22300. radialSegments, heightSegments,
  22301. openEnded, thetaStart, thetaLength );
  22302. this.type = 'ConeBufferGeometry';
  22303. this.parameters = {
  22304. radius: radius,
  22305. height: height,
  22306. radialSegments: radialSegments,
  22307. heightSegments: heightSegments,
  22308. thetaStart: thetaStart,
  22309. thetaLength: thetaLength
  22310. };
  22311. };
  22312. THREE.ConeBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  22313. THREE.ConeBufferGeometry.prototype.constructor = THREE.ConeBufferGeometry;
  22314. // File:src/extras/geometries/ConeGeometry.js
  22315. /**
  22316. * @author abelnation / http://github.com/abelnation
  22317. */
  22318. THREE.ConeGeometry = function (
  22319. radius, height,
  22320. radialSegments, heightSegments,
  22321. openEnded, thetaStart, thetaLength ) {
  22322. THREE.CylinderGeometry.call( this,
  22323. 0, radius, height,
  22324. radialSegments, heightSegments,
  22325. openEnded, thetaStart, thetaLength );
  22326. this.type = 'ConeGeometry';
  22327. this.parameters = {
  22328. radius: radius,
  22329. height: height,
  22330. radialSegments: radialSegments,
  22331. heightSegments: heightSegments,
  22332. openEnded: openEnded,
  22333. thetaStart: thetaStart,
  22334. thetaLength: thetaLength
  22335. };
  22336. };
  22337. THREE.ConeGeometry.prototype = Object.create( THREE.CylinderGeometry.prototype );
  22338. THREE.ConeGeometry.prototype.constructor = THREE.ConeGeometry;
  22339. // File:src/extras/geometries/EdgesGeometry.js
  22340. /**
  22341. * @author WestLangley / http://github.com/WestLangley
  22342. */
  22343. THREE.EdgesGeometry = function ( geometry, thresholdAngle ) {
  22344. THREE.BufferGeometry.call( this );
  22345. thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
  22346. var thresholdDot = Math.cos( THREE.Math.DEG2RAD * thresholdAngle );
  22347. var edge = [ 0, 0 ], hash = {};
  22348. function sortFunction( a, b ) {
  22349. return a - b;
  22350. }
  22351. var keys = [ 'a', 'b', 'c' ];
  22352. var geometry2;
  22353. if ( geometry instanceof THREE.BufferGeometry ) {
  22354. geometry2 = new THREE.Geometry();
  22355. geometry2.fromBufferGeometry( geometry );
  22356. } else {
  22357. geometry2 = geometry.clone();
  22358. }
  22359. geometry2.mergeVertices();
  22360. geometry2.computeFaceNormals();
  22361. var vertices = geometry2.vertices;
  22362. var faces = geometry2.faces;
  22363. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  22364. var face = faces[ i ];
  22365. for ( var j = 0; j < 3; j ++ ) {
  22366. edge[ 0 ] = face[ keys[ j ] ];
  22367. edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
  22368. edge.sort( sortFunction );
  22369. var key = edge.toString();
  22370. if ( hash[ key ] === undefined ) {
  22371. hash[ key ] = { vert1: edge[ 0 ], vert2: edge[ 1 ], face1: i, face2: undefined };
  22372. } else {
  22373. hash[ key ].face2 = i;
  22374. }
  22375. }
  22376. }
  22377. var coords = [];
  22378. for ( var key in hash ) {
  22379. var h = hash[ key ];
  22380. if ( h.face2 === undefined || faces[ h.face1 ].normal.dot( faces[ h.face2 ].normal ) <= thresholdDot ) {
  22381. var vertex = vertices[ h.vert1 ];
  22382. coords.push( vertex.x );
  22383. coords.push( vertex.y );
  22384. coords.push( vertex.z );
  22385. vertex = vertices[ h.vert2 ];
  22386. coords.push( vertex.x );
  22387. coords.push( vertex.y );
  22388. coords.push( vertex.z );
  22389. }
  22390. }
  22391. this.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array( coords ), 3 ) );
  22392. };
  22393. THREE.EdgesGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  22394. THREE.EdgesGeometry.prototype.constructor = THREE.EdgesGeometry;
  22395. // File:src/extras/geometries/ExtrudeGeometry.js
  22396. /**
  22397. * @author zz85 / http://www.lab4games.net/zz85/blog
  22398. *
  22399. * Creates extruded geometry from a path shape.
  22400. *
  22401. * parameters = {
  22402. *
  22403. * curveSegments: <int>, // number of points on the curves
  22404. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  22405. * amount: <int>, // Depth to extrude the shape
  22406. *
  22407. * bevelEnabled: <bool>, // turn on bevel
  22408. * bevelThickness: <float>, // how deep into the original shape bevel goes
  22409. * bevelSize: <float>, // how far from shape outline is bevel
  22410. * bevelSegments: <int>, // number of bevel layers
  22411. *
  22412. * extrudePath: <THREE.CurvePath> // 3d spline path to extrude shape along. (creates Frames if .frames aren't defined)
  22413. * frames: <THREE.TubeGeometry.FrenetFrames> // containing arrays of tangents, normals, binormals
  22414. *
  22415. * uvGenerator: <Object> // object that provides UV generator functions
  22416. *
  22417. * }
  22418. **/
  22419. THREE.ExtrudeGeometry = function ( shapes, options ) {
  22420. if ( typeof( shapes ) === "undefined" ) {
  22421. shapes = [];
  22422. return;
  22423. }
  22424. THREE.Geometry.call( this );
  22425. this.type = 'ExtrudeGeometry';
  22426. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  22427. this.addShapeList( shapes, options );
  22428. this.computeFaceNormals();
  22429. // can't really use automatic vertex normals
  22430. // as then front and back sides get smoothed too
  22431. // should do separate smoothing just for sides
  22432. //this.computeVertexNormals();
  22433. //console.log( "took", ( Date.now() - startTime ) );
  22434. };
  22435. THREE.ExtrudeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22436. THREE.ExtrudeGeometry.prototype.constructor = THREE.ExtrudeGeometry;
  22437. THREE.ExtrudeGeometry.prototype.addShapeList = function ( shapes, options ) {
  22438. var sl = shapes.length;
  22439. for ( var s = 0; s < sl; s ++ ) {
  22440. var shape = shapes[ s ];
  22441. this.addShape( shape, options );
  22442. }
  22443. };
  22444. THREE.ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
  22445. var amount = options.amount !== undefined ? options.amount : 100;
  22446. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6; // 10
  22447. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2; // 8
  22448. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  22449. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true; // false
  22450. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  22451. var steps = options.steps !== undefined ? options.steps : 1;
  22452. var extrudePath = options.extrudePath;
  22453. var extrudePts, extrudeByPath = false;
  22454. // Use default WorldUVGenerator if no UV generators are specified.
  22455. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : THREE.ExtrudeGeometry.WorldUVGenerator;
  22456. var splineTube, binormal, normal, position2;
  22457. if ( extrudePath ) {
  22458. extrudePts = extrudePath.getSpacedPoints( steps );
  22459. extrudeByPath = true;
  22460. bevelEnabled = false; // bevels not supported for path extrusion
  22461. // SETUP TNB variables
  22462. // Reuse TNB from TubeGeomtry for now.
  22463. // TODO1 - have a .isClosed in spline?
  22464. splineTube = options.frames !== undefined ? options.frames : new THREE.TubeGeometry.FrenetFrames( extrudePath, steps, false );
  22465. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  22466. binormal = new THREE.Vector3();
  22467. normal = new THREE.Vector3();
  22468. position2 = new THREE.Vector3();
  22469. }
  22470. // Safeguards if bevels are not enabled
  22471. if ( ! bevelEnabled ) {
  22472. bevelSegments = 0;
  22473. bevelThickness = 0;
  22474. bevelSize = 0;
  22475. }
  22476. // Variables initialization
  22477. var ahole, h, hl; // looping of holes
  22478. var scope = this;
  22479. var shapesOffset = this.vertices.length;
  22480. var shapePoints = shape.extractPoints( curveSegments );
  22481. var vertices = shapePoints.shape;
  22482. var holes = shapePoints.holes;
  22483. var reverse = ! THREE.ShapeUtils.isClockWise( vertices );
  22484. if ( reverse ) {
  22485. vertices = vertices.reverse();
  22486. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  22487. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  22488. ahole = holes[ h ];
  22489. if ( THREE.ShapeUtils.isClockWise( ahole ) ) {
  22490. holes[ h ] = ahole.reverse();
  22491. }
  22492. }
  22493. reverse = false; // If vertices are in order now, we shouldn't need to worry about them again (hopefully)!
  22494. }
  22495. var faces = THREE.ShapeUtils.triangulateShape( vertices, holes );
  22496. /* Vertices */
  22497. var contour = vertices; // vertices has all points but contour has only points of circumference
  22498. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  22499. ahole = holes[ h ];
  22500. vertices = vertices.concat( ahole );
  22501. }
  22502. function scalePt2 ( pt, vec, size ) {
  22503. if ( ! vec ) console.error( "THREE.ExtrudeGeometry: vec does not exist" );
  22504. return vec.clone().multiplyScalar( size ).add( pt );
  22505. }
  22506. var b, bs, t, z,
  22507. vert, vlen = vertices.length,
  22508. face, flen = faces.length;
  22509. // Find directions for point movement
  22510. function getBevelVec( inPt, inPrev, inNext ) {
  22511. // computes for inPt the corresponding point inPt' on a new contour
  22512. // shifted by 1 unit (length of normalized vector) to the left
  22513. // if we walk along contour clockwise, this new contour is outside the old one
  22514. //
  22515. // inPt' is the intersection of the two lines parallel to the two
  22516. // adjacent edges of inPt at a distance of 1 unit on the left side.
  22517. var v_trans_x, v_trans_y, shrink_by = 1; // resulting translation vector for inPt
  22518. // good reading for geometry algorithms (here: line-line intersection)
  22519. // http://geomalgorithms.com/a05-_intersect-1.html
  22520. var v_prev_x = inPt.x - inPrev.x, v_prev_y = inPt.y - inPrev.y;
  22521. var v_next_x = inNext.x - inPt.x, v_next_y = inNext.y - inPt.y;
  22522. var v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  22523. // check for collinear edges
  22524. var collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  22525. if ( Math.abs( collinear0 ) > Number.EPSILON ) {
  22526. // not collinear
  22527. // length of vectors for normalizing
  22528. var v_prev_len = Math.sqrt( v_prev_lensq );
  22529. var v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  22530. // shift adjacent points by unit vectors to the left
  22531. var ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  22532. var ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  22533. var ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  22534. var ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  22535. // scaling factor for v_prev to intersection point
  22536. var sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  22537. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  22538. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  22539. // vector from inPt to intersection point
  22540. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  22541. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  22542. // Don't normalize!, otherwise sharp corners become ugly
  22543. // but prevent crazy spikes
  22544. var v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  22545. if ( v_trans_lensq <= 2 ) {
  22546. return new THREE.Vector2( v_trans_x, v_trans_y );
  22547. } else {
  22548. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  22549. }
  22550. } else {
  22551. // handle special case of collinear edges
  22552. var direction_eq = false; // assumes: opposite
  22553. if ( v_prev_x > Number.EPSILON ) {
  22554. if ( v_next_x > Number.EPSILON ) {
  22555. direction_eq = true;
  22556. }
  22557. } else {
  22558. if ( v_prev_x < - Number.EPSILON ) {
  22559. if ( v_next_x < - Number.EPSILON ) {
  22560. direction_eq = true;
  22561. }
  22562. } else {
  22563. if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
  22564. direction_eq = true;
  22565. }
  22566. }
  22567. }
  22568. if ( direction_eq ) {
  22569. // console.log("Warning: lines are a straight sequence");
  22570. v_trans_x = - v_prev_y;
  22571. v_trans_y = v_prev_x;
  22572. shrink_by = Math.sqrt( v_prev_lensq );
  22573. } else {
  22574. // console.log("Warning: lines are a straight spike");
  22575. v_trans_x = v_prev_x;
  22576. v_trans_y = v_prev_y;
  22577. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  22578. }
  22579. }
  22580. return new THREE.Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  22581. }
  22582. var contourMovements = [];
  22583. for ( var i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  22584. if ( j === il ) j = 0;
  22585. if ( k === il ) k = 0;
  22586. // (j)---(i)---(k)
  22587. // console.log('i,j,k', i, j , k)
  22588. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  22589. }
  22590. var holesMovements = [], oneHoleMovements, verticesMovements = contourMovements.concat();
  22591. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  22592. ahole = holes[ h ];
  22593. oneHoleMovements = [];
  22594. for ( i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  22595. if ( j === il ) j = 0;
  22596. if ( k === il ) k = 0;
  22597. // (j)---(i)---(k)
  22598. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  22599. }
  22600. holesMovements.push( oneHoleMovements );
  22601. verticesMovements = verticesMovements.concat( oneHoleMovements );
  22602. }
  22603. // Loop bevelSegments, 1 for the front, 1 for the back
  22604. for ( b = 0; b < bevelSegments; b ++ ) {
  22605. //for ( b = bevelSegments; b > 0; b -- ) {
  22606. t = b / bevelSegments;
  22607. z = bevelThickness * ( 1 - t );
  22608. //z = bevelThickness * t;
  22609. bs = bevelSize * ( Math.sin ( t * Math.PI / 2 ) ); // curved
  22610. //bs = bevelSize * t; // linear
  22611. // contract shape
  22612. for ( i = 0, il = contour.length; i < il; i ++ ) {
  22613. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  22614. v( vert.x, vert.y, - z );
  22615. }
  22616. // expand holes
  22617. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  22618. ahole = holes[ h ];
  22619. oneHoleMovements = holesMovements[ h ];
  22620. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  22621. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  22622. v( vert.x, vert.y, - z );
  22623. }
  22624. }
  22625. }
  22626. bs = bevelSize;
  22627. // Back facing vertices
  22628. for ( i = 0; i < vlen; i ++ ) {
  22629. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  22630. if ( ! extrudeByPath ) {
  22631. v( vert.x, vert.y, 0 );
  22632. } else {
  22633. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  22634. normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x );
  22635. binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y );
  22636. position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
  22637. v( position2.x, position2.y, position2.z );
  22638. }
  22639. }
  22640. // Add stepped vertices...
  22641. // Including front facing vertices
  22642. var s;
  22643. for ( s = 1; s <= steps; s ++ ) {
  22644. for ( i = 0; i < vlen; i ++ ) {
  22645. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  22646. if ( ! extrudeByPath ) {
  22647. v( vert.x, vert.y, amount / steps * s );
  22648. } else {
  22649. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  22650. normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x );
  22651. binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y );
  22652. position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
  22653. v( position2.x, position2.y, position2.z );
  22654. }
  22655. }
  22656. }
  22657. // Add bevel segments planes
  22658. //for ( b = 1; b <= bevelSegments; b ++ ) {
  22659. for ( b = bevelSegments - 1; b >= 0; b -- ) {
  22660. t = b / bevelSegments;
  22661. z = bevelThickness * ( 1 - t );
  22662. //bs = bevelSize * ( 1-Math.sin ( ( 1 - t ) * Math.PI/2 ) );
  22663. bs = bevelSize * Math.sin ( t * Math.PI / 2 );
  22664. // contract shape
  22665. for ( i = 0, il = contour.length; i < il; i ++ ) {
  22666. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  22667. v( vert.x, vert.y, amount + z );
  22668. }
  22669. // expand holes
  22670. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  22671. ahole = holes[ h ];
  22672. oneHoleMovements = holesMovements[ h ];
  22673. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  22674. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  22675. if ( ! extrudeByPath ) {
  22676. v( vert.x, vert.y, amount + z );
  22677. } else {
  22678. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  22679. }
  22680. }
  22681. }
  22682. }
  22683. /* Faces */
  22684. // Top and bottom faces
  22685. buildLidFaces();
  22686. // Sides faces
  22687. buildSideFaces();
  22688. ///// Internal functions
  22689. function buildLidFaces() {
  22690. if ( bevelEnabled ) {
  22691. var layer = 0; // steps + 1
  22692. var offset = vlen * layer;
  22693. // Bottom faces
  22694. for ( i = 0; i < flen; i ++ ) {
  22695. face = faces[ i ];
  22696. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  22697. }
  22698. layer = steps + bevelSegments * 2;
  22699. offset = vlen * layer;
  22700. // Top faces
  22701. for ( i = 0; i < flen; i ++ ) {
  22702. face = faces[ i ];
  22703. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  22704. }
  22705. } else {
  22706. // Bottom faces
  22707. for ( i = 0; i < flen; i ++ ) {
  22708. face = faces[ i ];
  22709. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  22710. }
  22711. // Top faces
  22712. for ( i = 0; i < flen; i ++ ) {
  22713. face = faces[ i ];
  22714. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  22715. }
  22716. }
  22717. }
  22718. // Create faces for the z-sides of the shape
  22719. function buildSideFaces() {
  22720. var layeroffset = 0;
  22721. sidewalls( contour, layeroffset );
  22722. layeroffset += contour.length;
  22723. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  22724. ahole = holes[ h ];
  22725. sidewalls( ahole, layeroffset );
  22726. //, true
  22727. layeroffset += ahole.length;
  22728. }
  22729. }
  22730. function sidewalls( contour, layeroffset ) {
  22731. var j, k;
  22732. i = contour.length;
  22733. while ( -- i >= 0 ) {
  22734. j = i;
  22735. k = i - 1;
  22736. if ( k < 0 ) k = contour.length - 1;
  22737. //console.log('b', i,j, i-1, k,vertices.length);
  22738. var s = 0, sl = steps + bevelSegments * 2;
  22739. for ( s = 0; s < sl; s ++ ) {
  22740. var slen1 = vlen * s;
  22741. var slen2 = vlen * ( s + 1 );
  22742. var a = layeroffset + j + slen1,
  22743. b = layeroffset + k + slen1,
  22744. c = layeroffset + k + slen2,
  22745. d = layeroffset + j + slen2;
  22746. f4( a, b, c, d, contour, s, sl, j, k );
  22747. }
  22748. }
  22749. }
  22750. function v( x, y, z ) {
  22751. scope.vertices.push( new THREE.Vector3( x, y, z ) );
  22752. }
  22753. function f3( a, b, c ) {
  22754. a += shapesOffset;
  22755. b += shapesOffset;
  22756. c += shapesOffset;
  22757. scope.faces.push( new THREE.Face3( a, b, c, null, null, 0 ) );
  22758. var uvs = uvgen.generateTopUV( scope, a, b, c );
  22759. scope.faceVertexUvs[ 0 ].push( uvs );
  22760. }
  22761. function f4( a, b, c, d, wallContour, stepIndex, stepsLength, contourIndex1, contourIndex2 ) {
  22762. a += shapesOffset;
  22763. b += shapesOffset;
  22764. c += shapesOffset;
  22765. d += shapesOffset;
  22766. scope.faces.push( new THREE.Face3( a, b, d, null, null, 1 ) );
  22767. scope.faces.push( new THREE.Face3( b, c, d, null, null, 1 ) );
  22768. var uvs = uvgen.generateSideWallUV( scope, a, b, c, d );
  22769. scope.faceVertexUvs[ 0 ].push( [ uvs[ 0 ], uvs[ 1 ], uvs[ 3 ] ] );
  22770. scope.faceVertexUvs[ 0 ].push( [ uvs[ 1 ], uvs[ 2 ], uvs[ 3 ] ] );
  22771. }
  22772. };
  22773. THREE.ExtrudeGeometry.WorldUVGenerator = {
  22774. generateTopUV: function ( geometry, indexA, indexB, indexC ) {
  22775. var vertices = geometry.vertices;
  22776. var a = vertices[ indexA ];
  22777. var b = vertices[ indexB ];
  22778. var c = vertices[ indexC ];
  22779. return [
  22780. new THREE.Vector2( a.x, a.y ),
  22781. new THREE.Vector2( b.x, b.y ),
  22782. new THREE.Vector2( c.x, c.y )
  22783. ];
  22784. },
  22785. generateSideWallUV: function ( geometry, indexA, indexB, indexC, indexD ) {
  22786. var vertices = geometry.vertices;
  22787. var a = vertices[ indexA ];
  22788. var b = vertices[ indexB ];
  22789. var c = vertices[ indexC ];
  22790. var d = vertices[ indexD ];
  22791. if ( Math.abs( a.y - b.y ) < 0.01 ) {
  22792. return [
  22793. new THREE.Vector2( a.x, 1 - a.z ),
  22794. new THREE.Vector2( b.x, 1 - b.z ),
  22795. new THREE.Vector2( c.x, 1 - c.z ),
  22796. new THREE.Vector2( d.x, 1 - d.z )
  22797. ];
  22798. } else {
  22799. return [
  22800. new THREE.Vector2( a.y, 1 - a.z ),
  22801. new THREE.Vector2( b.y, 1 - b.z ),
  22802. new THREE.Vector2( c.y, 1 - c.z ),
  22803. new THREE.Vector2( d.y, 1 - d.z )
  22804. ];
  22805. }
  22806. }
  22807. };
  22808. // File:src/extras/geometries/ShapeGeometry.js
  22809. /**
  22810. * @author jonobr1 / http://jonobr1.com
  22811. *
  22812. * Creates a one-sided polygonal geometry from a path shape. Similar to
  22813. * ExtrudeGeometry.
  22814. *
  22815. * parameters = {
  22816. *
  22817. * curveSegments: <int>, // number of points on the curves. NOT USED AT THE MOMENT.
  22818. *
  22819. * material: <int> // material index for front and back faces
  22820. * uvGenerator: <Object> // object that provides UV generator functions
  22821. *
  22822. * }
  22823. **/
  22824. THREE.ShapeGeometry = function ( shapes, options ) {
  22825. THREE.Geometry.call( this );
  22826. this.type = 'ShapeGeometry';
  22827. if ( Array.isArray( shapes ) === false ) shapes = [ shapes ];
  22828. this.addShapeList( shapes, options );
  22829. this.computeFaceNormals();
  22830. };
  22831. THREE.ShapeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22832. THREE.ShapeGeometry.prototype.constructor = THREE.ShapeGeometry;
  22833. /**
  22834. * Add an array of shapes to THREE.ShapeGeometry.
  22835. */
  22836. THREE.ShapeGeometry.prototype.addShapeList = function ( shapes, options ) {
  22837. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  22838. this.addShape( shapes[ i ], options );
  22839. }
  22840. return this;
  22841. };
  22842. /**
  22843. * Adds a shape to THREE.ShapeGeometry, based on THREE.ExtrudeGeometry.
  22844. */
  22845. THREE.ShapeGeometry.prototype.addShape = function ( shape, options ) {
  22846. if ( options === undefined ) options = {};
  22847. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  22848. var material = options.material;
  22849. var uvgen = options.UVGenerator === undefined ? THREE.ExtrudeGeometry.WorldUVGenerator : options.UVGenerator;
  22850. //
  22851. var i, l, hole;
  22852. var shapesOffset = this.vertices.length;
  22853. var shapePoints = shape.extractPoints( curveSegments );
  22854. var vertices = shapePoints.shape;
  22855. var holes = shapePoints.holes;
  22856. var reverse = ! THREE.ShapeUtils.isClockWise( vertices );
  22857. if ( reverse ) {
  22858. vertices = vertices.reverse();
  22859. // Maybe we should also check if holes are in the opposite direction, just to be safe...
  22860. for ( i = 0, l = holes.length; i < l; i ++ ) {
  22861. hole = holes[ i ];
  22862. if ( THREE.ShapeUtils.isClockWise( hole ) ) {
  22863. holes[ i ] = hole.reverse();
  22864. }
  22865. }
  22866. reverse = false;
  22867. }
  22868. var faces = THREE.ShapeUtils.triangulateShape( vertices, holes );
  22869. // Vertices
  22870. for ( i = 0, l = holes.length; i < l; i ++ ) {
  22871. hole = holes[ i ];
  22872. vertices = vertices.concat( hole );
  22873. }
  22874. //
  22875. var vert, vlen = vertices.length;
  22876. var face, flen = faces.length;
  22877. for ( i = 0; i < vlen; i ++ ) {
  22878. vert = vertices[ i ];
  22879. this.vertices.push( new THREE.Vector3( vert.x, vert.y, 0 ) );
  22880. }
  22881. for ( i = 0; i < flen; i ++ ) {
  22882. face = faces[ i ];
  22883. var a = face[ 0 ] + shapesOffset;
  22884. var b = face[ 1 ] + shapesOffset;
  22885. var c = face[ 2 ] + shapesOffset;
  22886. this.faces.push( new THREE.Face3( a, b, c, null, null, material ) );
  22887. this.faceVertexUvs[ 0 ].push( uvgen.generateTopUV( this, a, b, c ) );
  22888. }
  22889. };
  22890. // File:src/extras/geometries/LatheBufferGeometry.js
  22891. /**
  22892. * @author Mugen87 / https://github.com/Mugen87
  22893. */
  22894. // points - to create a closed torus, one must use a set of points
  22895. // like so: [ a, b, c, d, a ], see first is the same as last.
  22896. // segments - the number of circumference segments to create
  22897. // phiStart - the starting radian
  22898. // phiLength - the radian (0 to 2PI) range of the lathed section
  22899. // 2PI is a closed lathe, less than 2PI is a portion.
  22900. THREE.LatheBufferGeometry = function ( points, segments, phiStart, phiLength ) {
  22901. THREE.BufferGeometry.call( this );
  22902. this.type = 'LatheBufferGeometry';
  22903. this.parameters = {
  22904. points: points,
  22905. segments: segments,
  22906. phiStart: phiStart,
  22907. phiLength: phiLength
  22908. };
  22909. segments = Math.floor( segments ) || 12;
  22910. phiStart = phiStart || 0;
  22911. phiLength = phiLength || Math.PI * 2;
  22912. // clamp phiLength so it's in range of [ 0, 2PI ]
  22913. phiLength = THREE.Math.clamp( phiLength, 0, Math.PI * 2 );
  22914. // these are used to calculate buffer length
  22915. var vertexCount = ( segments + 1 ) * points.length;
  22916. var indexCount = segments * points.length * 2 * 3;
  22917. // buffers
  22918. var indices = new THREE.BufferAttribute( new ( indexCount > 65535 ? Uint32Array : Uint16Array )( indexCount ) , 1 );
  22919. var vertices = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  22920. var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
  22921. // helper variables
  22922. var index = 0, indexOffset = 0, base;
  22923. var inversePointLength = 1.0 / ( points.length - 1 );
  22924. var inverseSegments = 1.0 / segments;
  22925. var vertex = new THREE.Vector3();
  22926. var uv = new THREE.Vector2();
  22927. var i, j;
  22928. // generate vertices and uvs
  22929. for ( i = 0; i <= segments; i ++ ) {
  22930. var phi = phiStart + i * inverseSegments * phiLength;
  22931. var sin = Math.sin( phi );
  22932. var cos = Math.cos( phi );
  22933. for ( j = 0; j <= ( points.length - 1 ); j ++ ) {
  22934. // vertex
  22935. vertex.x = points[ j ].x * sin;
  22936. vertex.y = points[ j ].y;
  22937. vertex.z = points[ j ].x * cos;
  22938. vertices.setXYZ( index, vertex.x, vertex.y, vertex.z );
  22939. // uv
  22940. uv.x = i / segments;
  22941. uv.y = j / ( points.length - 1 );
  22942. uvs.setXY( index, uv.x, uv.y );
  22943. // increase index
  22944. index ++;
  22945. }
  22946. }
  22947. // generate indices
  22948. for ( i = 0; i < segments; i ++ ) {
  22949. for ( j = 0; j < ( points.length - 1 ); j ++ ) {
  22950. base = j + i * points.length;
  22951. // indices
  22952. var a = base;
  22953. var b = base + points.length;
  22954. var c = base + points.length + 1;
  22955. var d = base + 1;
  22956. // face one
  22957. indices.setX( indexOffset, a ); indexOffset++;
  22958. indices.setX( indexOffset, b ); indexOffset++;
  22959. indices.setX( indexOffset, d ); indexOffset++;
  22960. // face two
  22961. indices.setX( indexOffset, b ); indexOffset++;
  22962. indices.setX( indexOffset, c ); indexOffset++;
  22963. indices.setX( indexOffset, d ); indexOffset++;
  22964. }
  22965. }
  22966. // build geometry
  22967. this.setIndex( indices );
  22968. this.addAttribute( 'position', vertices );
  22969. this.addAttribute( 'uv', uvs );
  22970. // generate normals
  22971. this.computeVertexNormals();
  22972. // if the geometry is closed, we need to average the normals along the seam.
  22973. // because the corresponding vertices are identical (but still have different UVs).
  22974. if( phiLength === Math.PI * 2 ) {
  22975. var normals = this.attributes.normal.array;
  22976. var n1 = new THREE.Vector3();
  22977. var n2 = new THREE.Vector3();
  22978. var n = new THREE.Vector3();
  22979. // this is the buffer offset for the last line of vertices
  22980. base = segments * points.length * 3;
  22981. for( i = 0, j = 0; i < points.length; i ++, j += 3 ) {
  22982. // select the normal of the vertex in the first line
  22983. n1.x = normals[ j + 0 ];
  22984. n1.y = normals[ j + 1 ];
  22985. n1.z = normals[ j + 2 ];
  22986. // select the normal of the vertex in the last line
  22987. n2.x = normals[ base + j + 0 ];
  22988. n2.y = normals[ base + j + 1 ];
  22989. n2.z = normals[ base + j + 2 ];
  22990. // average normals
  22991. n.addVectors( n1, n2 ).normalize();
  22992. // assign the new values to both normals
  22993. normals[ j + 0 ] = normals[ base + j + 0 ] = n.x;
  22994. normals[ j + 1 ] = normals[ base + j + 1 ] = n.y;
  22995. normals[ j + 2 ] = normals[ base + j + 2 ] = n.z;
  22996. } // next row
  22997. }
  22998. };
  22999. THREE.LatheBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  23000. THREE.LatheBufferGeometry.prototype.constructor = THREE.LatheBufferGeometry;
  23001. // File:src/extras/geometries/LatheGeometry.js
  23002. /**
  23003. * @author astrodud / http://astrodud.isgreat.org/
  23004. * @author zz85 / https://github.com/zz85
  23005. * @author bhouston / http://clara.io
  23006. */
  23007. // points - to create a closed torus, one must use a set of points
  23008. // like so: [ a, b, c, d, a ], see first is the same as last.
  23009. // segments - the number of circumference segments to create
  23010. // phiStart - the starting radian
  23011. // phiLength - the radian (0 to 2PI) range of the lathed section
  23012. // 2PI is a closed lathe, less than 2PI is a portion.
  23013. THREE.LatheGeometry = function ( points, segments, phiStart, phiLength ) {
  23014. THREE.Geometry.call( this );
  23015. this.type = 'LatheGeometry';
  23016. this.parameters = {
  23017. points: points,
  23018. segments: segments,
  23019. phiStart: phiStart,
  23020. phiLength: phiLength
  23021. };
  23022. this.fromBufferGeometry( new THREE.LatheBufferGeometry( points, segments, phiStart, phiLength ) );
  23023. this.mergeVertices();
  23024. };
  23025. THREE.LatheGeometry.prototype = Object.create( THREE.Geometry.prototype );
  23026. THREE.LatheGeometry.prototype.constructor = THREE.LatheGeometry;
  23027. // File:src/extras/geometries/PlaneGeometry.js
  23028. /**
  23029. * @author mrdoob / http://mrdoob.com/
  23030. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
  23031. */
  23032. THREE.PlaneGeometry = function ( width, height, widthSegments, heightSegments ) {
  23033. THREE.Geometry.call( this );
  23034. this.type = 'PlaneGeometry';
  23035. this.parameters = {
  23036. width: width,
  23037. height: height,
  23038. widthSegments: widthSegments,
  23039. heightSegments: heightSegments
  23040. };
  23041. this.fromBufferGeometry( new THREE.PlaneBufferGeometry( width, height, widthSegments, heightSegments ) );
  23042. };
  23043. THREE.PlaneGeometry.prototype = Object.create( THREE.Geometry.prototype );
  23044. THREE.PlaneGeometry.prototype.constructor = THREE.PlaneGeometry;
  23045. // File:src/extras/geometries/PlaneBufferGeometry.js
  23046. /**
  23047. * @author mrdoob / http://mrdoob.com/
  23048. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
  23049. */
  23050. THREE.PlaneBufferGeometry = function ( width, height, widthSegments, heightSegments ) {
  23051. THREE.BufferGeometry.call( this );
  23052. this.type = 'PlaneBufferGeometry';
  23053. this.parameters = {
  23054. width: width,
  23055. height: height,
  23056. widthSegments: widthSegments,
  23057. heightSegments: heightSegments
  23058. };
  23059. var width_half = width / 2;
  23060. var height_half = height / 2;
  23061. var gridX = Math.floor( widthSegments ) || 1;
  23062. var gridY = Math.floor( heightSegments ) || 1;
  23063. var gridX1 = gridX + 1;
  23064. var gridY1 = gridY + 1;
  23065. var segment_width = width / gridX;
  23066. var segment_height = height / gridY;
  23067. var vertices = new Float32Array( gridX1 * gridY1 * 3 );
  23068. var normals = new Float32Array( gridX1 * gridY1 * 3 );
  23069. var uvs = new Float32Array( gridX1 * gridY1 * 2 );
  23070. var offset = 0;
  23071. var offset2 = 0;
  23072. for ( var iy = 0; iy < gridY1; iy ++ ) {
  23073. var y = iy * segment_height - height_half;
  23074. for ( var ix = 0; ix < gridX1; ix ++ ) {
  23075. var x = ix * segment_width - width_half;
  23076. vertices[ offset ] = x;
  23077. vertices[ offset + 1 ] = - y;
  23078. normals[ offset + 2 ] = 1;
  23079. uvs[ offset2 ] = ix / gridX;
  23080. uvs[ offset2 + 1 ] = 1 - ( iy / gridY );
  23081. offset += 3;
  23082. offset2 += 2;
  23083. }
  23084. }
  23085. offset = 0;
  23086. var indices = new ( ( vertices.length / 3 ) > 65535 ? Uint32Array : Uint16Array )( gridX * gridY * 6 );
  23087. for ( var iy = 0; iy < gridY; iy ++ ) {
  23088. for ( var ix = 0; ix < gridX; ix ++ ) {
  23089. var a = ix + gridX1 * iy;
  23090. var b = ix + gridX1 * ( iy + 1 );
  23091. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  23092. var d = ( ix + 1 ) + gridX1 * iy;
  23093. indices[ offset ] = a;
  23094. indices[ offset + 1 ] = b;
  23095. indices[ offset + 2 ] = d;
  23096. indices[ offset + 3 ] = b;
  23097. indices[ offset + 4 ] = c;
  23098. indices[ offset + 5 ] = d;
  23099. offset += 6;
  23100. }
  23101. }
  23102. this.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  23103. this.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  23104. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  23105. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  23106. };
  23107. THREE.PlaneBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  23108. THREE.PlaneBufferGeometry.prototype.constructor = THREE.PlaneBufferGeometry;
  23109. // File:src/extras/geometries/RingBufferGeometry.js
  23110. /**
  23111. * @author Mugen87 / https://github.com/Mugen87
  23112. */
  23113. THREE.RingBufferGeometry = function ( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  23114. THREE.BufferGeometry.call( this );
  23115. this.type = 'RingBufferGeometry';
  23116. this.parameters = {
  23117. innerRadius: innerRadius,
  23118. outerRadius: outerRadius,
  23119. thetaSegments: thetaSegments,
  23120. phiSegments: phiSegments,
  23121. thetaStart: thetaStart,
  23122. thetaLength: thetaLength
  23123. };
  23124. innerRadius = innerRadius || 20;
  23125. outerRadius = outerRadius || 50;
  23126. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  23127. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  23128. thetaSegments = thetaSegments !== undefined ? Math.max( 3, thetaSegments ) : 8;
  23129. phiSegments = phiSegments !== undefined ? Math.max( 1, phiSegments ) : 1;
  23130. // these are used to calculate buffer length
  23131. var vertexCount = ( thetaSegments + 1 ) * ( phiSegments + 1 );
  23132. var indexCount = thetaSegments * phiSegments * 2 * 3;
  23133. // buffers
  23134. var indices = new THREE.BufferAttribute( new ( indexCount > 65535 ? Uint32Array : Uint16Array )( indexCount ) , 1 );
  23135. var vertices = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  23136. var normals = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  23137. var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
  23138. // some helper variables
  23139. var index = 0, indexOffset = 0, segment;
  23140. var radius = innerRadius;
  23141. var radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  23142. var vertex = new THREE.Vector3();
  23143. var uv = new THREE.Vector2();
  23144. var j, i;
  23145. // generate vertices, normals and uvs
  23146. // values are generate from the inside of the ring to the outside
  23147. for ( j = 0; j <= phiSegments; j ++ ) {
  23148. for ( i = 0; i <= thetaSegments; i ++ ) {
  23149. segment = thetaStart + i / thetaSegments * thetaLength;
  23150. // vertex
  23151. vertex.x = radius * Math.cos( segment );
  23152. vertex.y = radius * Math.sin( segment );
  23153. vertices.setXYZ( index, vertex.x, vertex.y, vertex.z );
  23154. // normal
  23155. normals.setXYZ( index, 0, 0, 1 );
  23156. // uv
  23157. uv.x = ( vertex.x / outerRadius + 1 ) / 2;
  23158. uv.y = ( vertex.y / outerRadius + 1 ) / 2;
  23159. uvs.setXY( index, uv.x, uv.y );
  23160. // increase index
  23161. index++;
  23162. }
  23163. // increase the radius for next row of vertices
  23164. radius += radiusStep;
  23165. }
  23166. // generate indices
  23167. for ( j = 0; j < phiSegments; j ++ ) {
  23168. var thetaSegmentLevel = j * ( thetaSegments + 1 );
  23169. for ( i = 0; i < thetaSegments; i ++ ) {
  23170. segment = i + thetaSegmentLevel;
  23171. // indices
  23172. var a = segment;
  23173. var b = segment + thetaSegments + 1;
  23174. var c = segment + thetaSegments + 2;
  23175. var d = segment + 1;
  23176. // face one
  23177. indices.setX( indexOffset, a ); indexOffset++;
  23178. indices.setX( indexOffset, b ); indexOffset++;
  23179. indices.setX( indexOffset, c ); indexOffset++;
  23180. // face two
  23181. indices.setX( indexOffset, a ); indexOffset++;
  23182. indices.setX( indexOffset, c ); indexOffset++;
  23183. indices.setX( indexOffset, d ); indexOffset++;
  23184. }
  23185. }
  23186. // build geometry
  23187. this.setIndex( indices );
  23188. this.addAttribute( 'position', vertices );
  23189. this.addAttribute( 'normal', normals );
  23190. this.addAttribute( 'uv', uvs );
  23191. };
  23192. THREE.RingBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  23193. THREE.RingBufferGeometry.prototype.constructor = THREE.RingBufferGeometry;
  23194. // File:src/extras/geometries/RingGeometry.js
  23195. /**
  23196. * @author Kaleb Murphy
  23197. */
  23198. THREE.RingGeometry = function ( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  23199. THREE.Geometry.call( this );
  23200. this.type = 'RingGeometry';
  23201. this.parameters = {
  23202. innerRadius: innerRadius,
  23203. outerRadius: outerRadius,
  23204. thetaSegments: thetaSegments,
  23205. phiSegments: phiSegments,
  23206. thetaStart: thetaStart,
  23207. thetaLength: thetaLength
  23208. };
  23209. this.fromBufferGeometry( new THREE.RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) );
  23210. };
  23211. THREE.RingGeometry.prototype = Object.create( THREE.Geometry.prototype );
  23212. THREE.RingGeometry.prototype.constructor = THREE.RingGeometry;
  23213. // File:src/extras/geometries/SphereGeometry.js
  23214. /**
  23215. * @author mrdoob / http://mrdoob.com/
  23216. */
  23217. THREE.SphereGeometry = function ( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  23218. THREE.Geometry.call( this );
  23219. this.type = 'SphereGeometry';
  23220. this.parameters = {
  23221. radius: radius,
  23222. widthSegments: widthSegments,
  23223. heightSegments: heightSegments,
  23224. phiStart: phiStart,
  23225. phiLength: phiLength,
  23226. thetaStart: thetaStart,
  23227. thetaLength: thetaLength
  23228. };
  23229. this.fromBufferGeometry( new THREE.SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) );
  23230. };
  23231. THREE.SphereGeometry.prototype = Object.create( THREE.Geometry.prototype );
  23232. THREE.SphereGeometry.prototype.constructor = THREE.SphereGeometry;
  23233. // File:src/extras/geometries/SphereBufferGeometry.js
  23234. /**
  23235. * @author benaadams / https://twitter.com/ben_a_adams
  23236. * based on THREE.SphereGeometry
  23237. */
  23238. THREE.SphereBufferGeometry = function ( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  23239. THREE.BufferGeometry.call( this );
  23240. this.type = 'SphereBufferGeometry';
  23241. this.parameters = {
  23242. radius: radius,
  23243. widthSegments: widthSegments,
  23244. heightSegments: heightSegments,
  23245. phiStart: phiStart,
  23246. phiLength: phiLength,
  23247. thetaStart: thetaStart,
  23248. thetaLength: thetaLength
  23249. };
  23250. radius = radius || 50;
  23251. widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
  23252. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  23253. phiStart = phiStart !== undefined ? phiStart : 0;
  23254. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  23255. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  23256. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  23257. var thetaEnd = thetaStart + thetaLength;
  23258. var vertexCount = ( ( widthSegments + 1 ) * ( heightSegments + 1 ) );
  23259. var positions = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  23260. var normals = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  23261. var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
  23262. var index = 0, vertices = [], normal = new THREE.Vector3();
  23263. for ( var y = 0; y <= heightSegments; y ++ ) {
  23264. var verticesRow = [];
  23265. var v = y / heightSegments;
  23266. for ( var x = 0; x <= widthSegments; x ++ ) {
  23267. var u = x / widthSegments;
  23268. var px = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  23269. var py = radius * Math.cos( thetaStart + v * thetaLength );
  23270. var pz = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  23271. normal.set( px, py, pz ).normalize();
  23272. positions.setXYZ( index, px, py, pz );
  23273. normals.setXYZ( index, normal.x, normal.y, normal.z );
  23274. uvs.setXY( index, u, 1 - v );
  23275. verticesRow.push( index );
  23276. index ++;
  23277. }
  23278. vertices.push( verticesRow );
  23279. }
  23280. var indices = [];
  23281. for ( var y = 0; y < heightSegments; y ++ ) {
  23282. for ( var x = 0; x < widthSegments; x ++ ) {
  23283. var v1 = vertices[ y ][ x + 1 ];
  23284. var v2 = vertices[ y ][ x ];
  23285. var v3 = vertices[ y + 1 ][ x ];
  23286. var v4 = vertices[ y + 1 ][ x + 1 ];
  23287. if ( y !== 0 || thetaStart > 0 ) indices.push( v1, v2, v4 );
  23288. if ( y !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( v2, v3, v4 );
  23289. }
  23290. }
  23291. this.setIndex( new ( positions.count > 65535 ? THREE.Uint32Attribute : THREE.Uint16Attribute )( indices, 1 ) );
  23292. this.addAttribute( 'position', positions );
  23293. this.addAttribute( 'normal', normals );
  23294. this.addAttribute( 'uv', uvs );
  23295. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  23296. };
  23297. THREE.SphereBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  23298. THREE.SphereBufferGeometry.prototype.constructor = THREE.SphereBufferGeometry;
  23299. // File:src/extras/geometries/TextGeometry.js
  23300. /**
  23301. * @author zz85 / http://www.lab4games.net/zz85/blog
  23302. * @author alteredq / http://alteredqualia.com/
  23303. *
  23304. * Text = 3D Text
  23305. *
  23306. * parameters = {
  23307. * font: <THREE.Font>, // font
  23308. *
  23309. * size: <float>, // size of the text
  23310. * height: <float>, // thickness to extrude text
  23311. * curveSegments: <int>, // number of points on the curves
  23312. *
  23313. * bevelEnabled: <bool>, // turn on bevel
  23314. * bevelThickness: <float>, // how deep into text bevel goes
  23315. * bevelSize: <float> // how far from text outline is bevel
  23316. * }
  23317. */
  23318. THREE.TextGeometry = function ( text, parameters ) {
  23319. parameters = parameters || {};
  23320. var font = parameters.font;
  23321. if ( font instanceof THREE.Font === false ) {
  23322. console.error( 'THREE.TextGeometry: font parameter is not an instance of THREE.Font.' );
  23323. return new THREE.Geometry();
  23324. }
  23325. var shapes = font.generateShapes( text, parameters.size, parameters.curveSegments );
  23326. // translate parameters to ExtrudeGeometry API
  23327. parameters.amount = parameters.height !== undefined ? parameters.height : 50;
  23328. // defaults
  23329. if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
  23330. if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
  23331. if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
  23332. THREE.ExtrudeGeometry.call( this, shapes, parameters );
  23333. this.type = 'TextGeometry';
  23334. };
  23335. THREE.TextGeometry.prototype = Object.create( THREE.ExtrudeGeometry.prototype );
  23336. THREE.TextGeometry.prototype.constructor = THREE.TextGeometry;
  23337. // File:src/extras/geometries/TorusBufferGeometry.js
  23338. /**
  23339. * @author Mugen87 / https://github.com/Mugen87
  23340. */
  23341. THREE.TorusBufferGeometry = function ( radius, tube, radialSegments, tubularSegments, arc ) {
  23342. THREE.BufferGeometry.call( this );
  23343. this.type = 'TorusBufferGeometry';
  23344. this.parameters = {
  23345. radius: radius,
  23346. tube: tube,
  23347. radialSegments: radialSegments,
  23348. tubularSegments: tubularSegments,
  23349. arc: arc
  23350. };
  23351. radius = radius || 100;
  23352. tube = tube || 40;
  23353. radialSegments = Math.floor( radialSegments ) || 8;
  23354. tubularSegments = Math.floor( tubularSegments ) || 6;
  23355. arc = arc || Math.PI * 2;
  23356. // used to calculate buffer length
  23357. var vertexCount = ( ( radialSegments + 1 ) * ( tubularSegments + 1 ) );
  23358. var indexCount = radialSegments * tubularSegments * 2 * 3;
  23359. // buffers
  23360. var indices = new ( indexCount > 65535 ? Uint32Array : Uint16Array )( indexCount );
  23361. var vertices = new Float32Array( vertexCount * 3 );
  23362. var normals = new Float32Array( vertexCount * 3 );
  23363. var uvs = new Float32Array( vertexCount * 2 );
  23364. // offset variables
  23365. var vertexBufferOffset = 0;
  23366. var uvBufferOffset = 0;
  23367. var indexBufferOffset = 0;
  23368. // helper variables
  23369. var center = new THREE.Vector3();
  23370. var vertex = new THREE.Vector3();
  23371. var normal = new THREE.Vector3();
  23372. var j, i;
  23373. // generate vertices, normals and uvs
  23374. for ( j = 0; j <= radialSegments; j ++ ) {
  23375. for ( i = 0; i <= tubularSegments; i ++ ) {
  23376. var u = i / tubularSegments * arc;
  23377. var v = j / radialSegments * Math.PI * 2;
  23378. // vertex
  23379. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  23380. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  23381. vertex.z = tube * Math.sin( v );
  23382. vertices[ vertexBufferOffset ] = vertex.x;
  23383. vertices[ vertexBufferOffset + 1 ] = vertex.y;
  23384. vertices[ vertexBufferOffset + 2 ] = vertex.z;
  23385. // this vector is used to calculate the normal
  23386. center.x = radius * Math.cos( u );
  23387. center.y = radius * Math.sin( u );
  23388. // normal
  23389. normal.subVectors( vertex, center ).normalize();
  23390. normals[ vertexBufferOffset ] = normal.x;
  23391. normals[ vertexBufferOffset + 1 ] = normal.y;
  23392. normals[ vertexBufferOffset + 2 ] = normal.z;
  23393. // uv
  23394. uvs[ uvBufferOffset ] = i / tubularSegments;
  23395. uvs[ uvBufferOffset + 1 ] = j / radialSegments;
  23396. // update offsets
  23397. vertexBufferOffset += 3;
  23398. uvBufferOffset += 2;
  23399. }
  23400. }
  23401. // generate indices
  23402. for ( j = 1; j <= radialSegments; j ++ ) {
  23403. for ( i = 1; i <= tubularSegments; i ++ ) {
  23404. // indices
  23405. var a = ( tubularSegments + 1 ) * j + i - 1;
  23406. var b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  23407. var c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  23408. var d = ( tubularSegments + 1 ) * j + i;
  23409. // face one
  23410. indices[ indexBufferOffset ] = a;
  23411. indices[ indexBufferOffset + 1 ] = b;
  23412. indices[ indexBufferOffset + 2 ] = d;
  23413. // face two
  23414. indices[ indexBufferOffset + 3 ] = b;
  23415. indices[ indexBufferOffset + 4 ] = c;
  23416. indices[ indexBufferOffset + 5 ] = d;
  23417. // update offset
  23418. indexBufferOffset += 6;
  23419. }
  23420. }
  23421. // build geometry
  23422. this.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  23423. this.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  23424. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  23425. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  23426. };
  23427. THREE.TorusBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  23428. THREE.TorusBufferGeometry.prototype.constructor = THREE.TorusBufferGeometry;
  23429. // File:src/extras/geometries/TorusGeometry.js
  23430. /**
  23431. * @author oosmoxiecode
  23432. * @author mrdoob / http://mrdoob.com/
  23433. * based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3DLite/src/away3dlite/primitives/Torus.as?r=2888
  23434. */
  23435. THREE.TorusGeometry = function ( radius, tube, radialSegments, tubularSegments, arc ) {
  23436. THREE.Geometry.call( this );
  23437. this.type = 'TorusGeometry';
  23438. this.parameters = {
  23439. radius: radius,
  23440. tube: tube,
  23441. radialSegments: radialSegments,
  23442. tubularSegments: tubularSegments,
  23443. arc: arc
  23444. };
  23445. this.fromBufferGeometry( new THREE.TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) );
  23446. };
  23447. THREE.TorusGeometry.prototype = Object.create( THREE.Geometry.prototype );
  23448. THREE.TorusGeometry.prototype.constructor = THREE.TorusGeometry;
  23449. // File:src/extras/geometries/TorusKnotBufferGeometry.js
  23450. /**
  23451. * @author Mugen87 / https://github.com/Mugen87
  23452. *
  23453. * see: http://www.blackpawn.com/texts/pqtorus/
  23454. */
  23455. THREE.TorusKnotBufferGeometry = function ( radius, tube, tubularSegments, radialSegments, p, q ) {
  23456. THREE.BufferGeometry.call( this );
  23457. this.type = 'TorusKnotBufferGeometry';
  23458. this.parameters = {
  23459. radius: radius,
  23460. tube: tube,
  23461. tubularSegments: tubularSegments,
  23462. radialSegments: radialSegments,
  23463. p: p,
  23464. q: q
  23465. };
  23466. radius = radius || 100;
  23467. tube = tube || 40;
  23468. tubularSegments = Math.floor( tubularSegments ) || 64;
  23469. radialSegments = Math.floor( radialSegments ) || 8;
  23470. p = p || 2;
  23471. q = q || 3;
  23472. // used to calculate buffer length
  23473. var vertexCount = ( ( radialSegments + 1 ) * ( tubularSegments + 1 ) );
  23474. var indexCount = radialSegments * tubularSegments * 2 * 3;
  23475. // buffers
  23476. var indices = new THREE.BufferAttribute( new ( indexCount > 65535 ? Uint32Array : Uint16Array )( indexCount ) , 1 );
  23477. var vertices = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  23478. var normals = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  23479. var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
  23480. // helper variables
  23481. var i, j, index = 0, indexOffset = 0;
  23482. var vertex = new THREE.Vector3();
  23483. var normal = new THREE.Vector3();
  23484. var uv = new THREE.Vector2();
  23485. var P1 = new THREE.Vector3();
  23486. var P2 = new THREE.Vector3();
  23487. var B = new THREE.Vector3();
  23488. var T = new THREE.Vector3();
  23489. var N = new THREE.Vector3();
  23490. // generate vertices, normals and uvs
  23491. for ( i = 0; i <= tubularSegments; ++ i ) {
  23492. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  23493. var u = i / tubularSegments * p * Math.PI * 2;
  23494. // now we calculate two points. P1 is our current position on the curve, P2 is a little farther ahead.
  23495. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  23496. calculatePositionOnCurve( u, p, q, radius, P1 );
  23497. calculatePositionOnCurve( u + 0.01, p, q, radius, P2 );
  23498. // calculate orthonormal basis
  23499. T.subVectors( P2, P1 );
  23500. N.addVectors( P2, P1 );
  23501. B.crossVectors( T, N );
  23502. N.crossVectors( B, T );
  23503. // normalize B, N. T can be ignored, we don't use it
  23504. B.normalize();
  23505. N.normalize();
  23506. for ( j = 0; j <= radialSegments; ++ j ) {
  23507. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  23508. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  23509. var v = j / radialSegments * Math.PI * 2;
  23510. var cx = - tube * Math.cos( v );
  23511. var cy = tube * Math.sin( v );
  23512. // now calculate the final vertex position.
  23513. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  23514. vertex.x = P1.x + ( cx * N.x + cy * B.x );
  23515. vertex.y = P1.y + ( cx * N.y + cy * B.y );
  23516. vertex.z = P1.z + ( cx * N.z + cy * B.z );
  23517. // vertex
  23518. vertices.setXYZ( index, vertex.x, vertex.y, vertex.z );
  23519. // normal (P1 is always the center/origin of the extrusion, thus we can use it to calculate the normal)
  23520. normal.subVectors( vertex, P1 ).normalize();
  23521. normals.setXYZ( index, normal.x, normal.y, normal.z );
  23522. // uv
  23523. uv.x = i / tubularSegments;
  23524. uv.y = j / radialSegments;
  23525. uvs.setXY( index, uv.x, uv.y );
  23526. // increase index
  23527. index ++;
  23528. }
  23529. }
  23530. // generate indices
  23531. for ( j = 1; j <= tubularSegments; j ++ ) {
  23532. for ( i = 1; i <= radialSegments; i ++ ) {
  23533. // indices
  23534. var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  23535. var b = ( radialSegments + 1 ) * j + ( i - 1 );
  23536. var c = ( radialSegments + 1 ) * j + i;
  23537. var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  23538. // face one
  23539. indices.setX( indexOffset, a ); indexOffset++;
  23540. indices.setX( indexOffset, b ); indexOffset++;
  23541. indices.setX( indexOffset, d ); indexOffset++;
  23542. // face two
  23543. indices.setX( indexOffset, b ); indexOffset++;
  23544. indices.setX( indexOffset, c ); indexOffset++;
  23545. indices.setX( indexOffset, d ); indexOffset++;
  23546. }
  23547. }
  23548. // build geometry
  23549. this.setIndex( indices );
  23550. this.addAttribute( 'position', vertices );
  23551. this.addAttribute( 'normal', normals );
  23552. this.addAttribute( 'uv', uvs );
  23553. // this function calculates the current position on the torus curve
  23554. function calculatePositionOnCurve( u, p, q, radius, position ) {
  23555. var cu = Math.cos( u );
  23556. var su = Math.sin( u );
  23557. var quOverP = q / p * u;
  23558. var cs = Math.cos( quOverP );
  23559. position.x = radius * ( 2 + cs ) * 0.5 * cu;
  23560. position.y = radius * ( 2 + cs ) * su * 0.5;
  23561. position.z = radius * Math.sin( quOverP ) * 0.5;
  23562. }
  23563. };
  23564. THREE.TorusKnotBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  23565. THREE.TorusKnotBufferGeometry.prototype.constructor = THREE.TorusKnotBufferGeometry;
  23566. // File:src/extras/geometries/TorusKnotGeometry.js
  23567. /**
  23568. * @author oosmoxiecode
  23569. */
  23570. THREE.TorusKnotGeometry = function ( radius, tube, tubularSegments, radialSegments, p, q, heightScale ) {
  23571. THREE.Geometry.call( this );
  23572. this.type = 'TorusKnotGeometry';
  23573. this.parameters = {
  23574. radius: radius,
  23575. tube: tube,
  23576. tubularSegments: tubularSegments,
  23577. radialSegments: radialSegments,
  23578. p: p,
  23579. q: q
  23580. };
  23581. if( heightScale !== undefined ) console.warn( 'THREE.TorusKnotGeometry: heightScale has been deprecated. Use .scale( x, y, z ) instead.' );
  23582. this.fromBufferGeometry( new THREE.TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) );
  23583. this.mergeVertices();
  23584. };
  23585. THREE.TorusKnotGeometry.prototype = Object.create( THREE.Geometry.prototype );
  23586. THREE.TorusKnotGeometry.prototype.constructor = THREE.TorusKnotGeometry;
  23587. // File:src/extras/geometries/TubeGeometry.js
  23588. /**
  23589. * @author WestLangley / https://github.com/WestLangley
  23590. * @author zz85 / https://github.com/zz85
  23591. * @author miningold / https://github.com/miningold
  23592. * @author jonobr1 / https://github.com/jonobr1
  23593. *
  23594. * Modified from the TorusKnotGeometry by @oosmoxiecode
  23595. *
  23596. * Creates a tube which extrudes along a 3d spline
  23597. *
  23598. * Uses parallel transport frames as described in
  23599. * http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  23600. */
  23601. THREE.TubeGeometry = function ( path, segments, radius, radialSegments, closed, taper ) {
  23602. THREE.Geometry.call( this );
  23603. this.type = 'TubeGeometry';
  23604. this.parameters = {
  23605. path: path,
  23606. segments: segments,
  23607. radius: radius,
  23608. radialSegments: radialSegments,
  23609. closed: closed,
  23610. taper: taper
  23611. };
  23612. segments = segments || 64;
  23613. radius = radius || 1;
  23614. radialSegments = radialSegments || 8;
  23615. closed = closed || false;
  23616. taper = taper || THREE.TubeGeometry.NoTaper;
  23617. var grid = [];
  23618. var scope = this,
  23619. tangent,
  23620. normal,
  23621. binormal,
  23622. numpoints = segments + 1,
  23623. u, v, r,
  23624. cx, cy,
  23625. pos, pos2 = new THREE.Vector3(),
  23626. i, j,
  23627. ip, jp,
  23628. a, b, c, d,
  23629. uva, uvb, uvc, uvd;
  23630. var frames = new THREE.TubeGeometry.FrenetFrames( path, segments, closed ),
  23631. tangents = frames.tangents,
  23632. normals = frames.normals,
  23633. binormals = frames.binormals;
  23634. // proxy internals
  23635. this.tangents = tangents;
  23636. this.normals = normals;
  23637. this.binormals = binormals;
  23638. function vert( x, y, z ) {
  23639. return scope.vertices.push( new THREE.Vector3( x, y, z ) ) - 1;
  23640. }
  23641. // construct the grid
  23642. for ( i = 0; i < numpoints; i ++ ) {
  23643. grid[ i ] = [];
  23644. u = i / ( numpoints - 1 );
  23645. pos = path.getPointAt( u );
  23646. tangent = tangents[ i ];
  23647. normal = normals[ i ];
  23648. binormal = binormals[ i ];
  23649. r = radius * taper( u );
  23650. for ( j = 0; j < radialSegments; j ++ ) {
  23651. v = j / radialSegments * 2 * Math.PI;
  23652. cx = - r * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
  23653. cy = r * Math.sin( v );
  23654. pos2.copy( pos );
  23655. pos2.x += cx * normal.x + cy * binormal.x;
  23656. pos2.y += cx * normal.y + cy * binormal.y;
  23657. pos2.z += cx * normal.z + cy * binormal.z;
  23658. grid[ i ][ j ] = vert( pos2.x, pos2.y, pos2.z );
  23659. }
  23660. }
  23661. // construct the mesh
  23662. for ( i = 0; i < segments; i ++ ) {
  23663. for ( j = 0; j < radialSegments; j ++ ) {
  23664. ip = ( closed ) ? ( i + 1 ) % segments : i + 1;
  23665. jp = ( j + 1 ) % radialSegments;
  23666. a = grid[ i ][ j ]; // *** NOT NECESSARILY PLANAR ! ***
  23667. b = grid[ ip ][ j ];
  23668. c = grid[ ip ][ jp ];
  23669. d = grid[ i ][ jp ];
  23670. uva = new THREE.Vector2( i / segments, j / radialSegments );
  23671. uvb = new THREE.Vector2( ( i + 1 ) / segments, j / radialSegments );
  23672. uvc = new THREE.Vector2( ( i + 1 ) / segments, ( j + 1 ) / radialSegments );
  23673. uvd = new THREE.Vector2( i / segments, ( j + 1 ) / radialSegments );
  23674. this.faces.push( new THREE.Face3( a, b, d ) );
  23675. this.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  23676. this.faces.push( new THREE.Face3( b, c, d ) );
  23677. this.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  23678. }
  23679. }
  23680. this.computeFaceNormals();
  23681. this.computeVertexNormals();
  23682. };
  23683. THREE.TubeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  23684. THREE.TubeGeometry.prototype.constructor = THREE.TubeGeometry;
  23685. THREE.TubeGeometry.NoTaper = function ( u ) {
  23686. return 1;
  23687. };
  23688. THREE.TubeGeometry.SinusoidalTaper = function ( u ) {
  23689. return Math.sin( Math.PI * u );
  23690. };
  23691. // For computing of Frenet frames, exposing the tangents, normals and binormals the spline
  23692. THREE.TubeGeometry.FrenetFrames = function ( path, segments, closed ) {
  23693. var normal = new THREE.Vector3(),
  23694. tangents = [],
  23695. normals = [],
  23696. binormals = [],
  23697. vec = new THREE.Vector3(),
  23698. mat = new THREE.Matrix4(),
  23699. numpoints = segments + 1,
  23700. theta,
  23701. smallest,
  23702. tx, ty, tz,
  23703. i, u;
  23704. // expose internals
  23705. this.tangents = tangents;
  23706. this.normals = normals;
  23707. this.binormals = binormals;
  23708. // compute the tangent vectors for each segment on the path
  23709. for ( i = 0; i < numpoints; i ++ ) {
  23710. u = i / ( numpoints - 1 );
  23711. tangents[ i ] = path.getTangentAt( u );
  23712. tangents[ i ].normalize();
  23713. }
  23714. initialNormal3();
  23715. /*
  23716. function initialNormal1(lastBinormal) {
  23717. // fixed start binormal. Has dangers of 0 vectors
  23718. normals[ 0 ] = new THREE.Vector3();
  23719. binormals[ 0 ] = new THREE.Vector3();
  23720. if (lastBinormal===undefined) lastBinormal = new THREE.Vector3( 0, 0, 1 );
  23721. normals[ 0 ].crossVectors( lastBinormal, tangents[ 0 ] ).normalize();
  23722. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] ).normalize();
  23723. }
  23724. function initialNormal2() {
  23725. // This uses the Frenet-Serret formula for deriving binormal
  23726. var t2 = path.getTangentAt( epsilon );
  23727. normals[ 0 ] = new THREE.Vector3().subVectors( t2, tangents[ 0 ] ).normalize();
  23728. binormals[ 0 ] = new THREE.Vector3().crossVectors( tangents[ 0 ], normals[ 0 ] );
  23729. normals[ 0 ].crossVectors( binormals[ 0 ], tangents[ 0 ] ).normalize(); // last binormal x tangent
  23730. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] ).normalize();
  23731. }
  23732. */
  23733. function initialNormal3() {
  23734. // select an initial normal vector perpendicular to the first tangent vector,
  23735. // and in the direction of the smallest tangent xyz component
  23736. normals[ 0 ] = new THREE.Vector3();
  23737. binormals[ 0 ] = new THREE.Vector3();
  23738. smallest = Number.MAX_VALUE;
  23739. tx = Math.abs( tangents[ 0 ].x );
  23740. ty = Math.abs( tangents[ 0 ].y );
  23741. tz = Math.abs( tangents[ 0 ].z );
  23742. if ( tx <= smallest ) {
  23743. smallest = tx;
  23744. normal.set( 1, 0, 0 );
  23745. }
  23746. if ( ty <= smallest ) {
  23747. smallest = ty;
  23748. normal.set( 0, 1, 0 );
  23749. }
  23750. if ( tz <= smallest ) {
  23751. normal.set( 0, 0, 1 );
  23752. }
  23753. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  23754. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  23755. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  23756. }
  23757. // compute the slowly-varying normal and binormal vectors for each segment on the path
  23758. for ( i = 1; i < numpoints; i ++ ) {
  23759. normals[ i ] = normals[ i - 1 ].clone();
  23760. binormals[ i ] = binormals[ i - 1 ].clone();
  23761. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  23762. if ( vec.length() > Number.EPSILON ) {
  23763. vec.normalize();
  23764. theta = Math.acos( THREE.Math.clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  23765. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  23766. }
  23767. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  23768. }
  23769. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  23770. if ( closed ) {
  23771. theta = Math.acos( THREE.Math.clamp( normals[ 0 ].dot( normals[ numpoints - 1 ] ), - 1, 1 ) );
  23772. theta /= ( numpoints - 1 );
  23773. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ numpoints - 1 ] ) ) > 0 ) {
  23774. theta = - theta;
  23775. }
  23776. for ( i = 1; i < numpoints; i ++ ) {
  23777. // twist a little...
  23778. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  23779. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  23780. }
  23781. }
  23782. };
  23783. // File:src/extras/geometries/PolyhedronGeometry.js
  23784. /**
  23785. * @author clockworkgeek / https://github.com/clockworkgeek
  23786. * @author timothypratley / https://github.com/timothypratley
  23787. * @author WestLangley / http://github.com/WestLangley
  23788. */
  23789. THREE.PolyhedronGeometry = function ( vertices, indices, radius, detail ) {
  23790. THREE.Geometry.call( this );
  23791. this.type = 'PolyhedronGeometry';
  23792. this.parameters = {
  23793. vertices: vertices,
  23794. indices: indices,
  23795. radius: radius,
  23796. detail: detail
  23797. };
  23798. radius = radius || 1;
  23799. detail = detail || 0;
  23800. var that = this;
  23801. for ( var i = 0, l = vertices.length; i < l; i += 3 ) {
  23802. prepare( new THREE.Vector3( vertices[ i ], vertices[ i + 1 ], vertices[ i + 2 ] ) );
  23803. }
  23804. var p = this.vertices;
  23805. var faces = [];
  23806. for ( var i = 0, j = 0, l = indices.length; i < l; i += 3, j ++ ) {
  23807. var v1 = p[ indices[ i ] ];
  23808. var v2 = p[ indices[ i + 1 ] ];
  23809. var v3 = p[ indices[ i + 2 ] ];
  23810. faces[ j ] = new THREE.Face3( v1.index, v2.index, v3.index, [ v1.clone(), v2.clone(), v3.clone() ] );
  23811. }
  23812. var centroid = new THREE.Vector3();
  23813. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  23814. subdivide( faces[ i ], detail );
  23815. }
  23816. // Handle case when face straddles the seam
  23817. for ( var i = 0, l = this.faceVertexUvs[ 0 ].length; i < l; i ++ ) {
  23818. var uvs = this.faceVertexUvs[ 0 ][ i ];
  23819. var x0 = uvs[ 0 ].x;
  23820. var x1 = uvs[ 1 ].x;
  23821. var x2 = uvs[ 2 ].x;
  23822. var max = Math.max( x0, x1, x2 );
  23823. var min = Math.min( x0, x1, x2 );
  23824. if ( max > 0.9 && min < 0.1 ) {
  23825. // 0.9 is somewhat arbitrary
  23826. if ( x0 < 0.2 ) uvs[ 0 ].x += 1;
  23827. if ( x1 < 0.2 ) uvs[ 1 ].x += 1;
  23828. if ( x2 < 0.2 ) uvs[ 2 ].x += 1;
  23829. }
  23830. }
  23831. // Apply radius
  23832. for ( var i = 0, l = this.vertices.length; i < l; i ++ ) {
  23833. this.vertices[ i ].multiplyScalar( radius );
  23834. }
  23835. // Merge vertices
  23836. this.mergeVertices();
  23837. this.computeFaceNormals();
  23838. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  23839. // Project vector onto sphere's surface
  23840. function prepare( vector ) {
  23841. var vertex = vector.normalize().clone();
  23842. vertex.index = that.vertices.push( vertex ) - 1;
  23843. // Texture coords are equivalent to map coords, calculate angle and convert to fraction of a circle.
  23844. var u = azimuth( vector ) / 2 / Math.PI + 0.5;
  23845. var v = inclination( vector ) / Math.PI + 0.5;
  23846. vertex.uv = new THREE.Vector2( u, 1 - v );
  23847. return vertex;
  23848. }
  23849. // Approximate a curved face with recursively sub-divided triangles.
  23850. function make( v1, v2, v3 ) {
  23851. var face = new THREE.Face3( v1.index, v2.index, v3.index, [ v1.clone(), v2.clone(), v3.clone() ] );
  23852. that.faces.push( face );
  23853. centroid.copy( v1 ).add( v2 ).add( v3 ).divideScalar( 3 );
  23854. var azi = azimuth( centroid );
  23855. that.faceVertexUvs[ 0 ].push( [
  23856. correctUV( v1.uv, v1, azi ),
  23857. correctUV( v2.uv, v2, azi ),
  23858. correctUV( v3.uv, v3, azi )
  23859. ] );
  23860. }
  23861. // Analytically subdivide a face to the required detail level.
  23862. function subdivide( face, detail ) {
  23863. var cols = Math.pow( 2, detail );
  23864. var a = prepare( that.vertices[ face.a ] );
  23865. var b = prepare( that.vertices[ face.b ] );
  23866. var c = prepare( that.vertices[ face.c ] );
  23867. var v = [];
  23868. // Construct all of the vertices for this subdivision.
  23869. for ( var i = 0 ; i <= cols; i ++ ) {
  23870. v[ i ] = [];
  23871. var aj = prepare( a.clone().lerp( c, i / cols ) );
  23872. var bj = prepare( b.clone().lerp( c, i / cols ) );
  23873. var rows = cols - i;
  23874. for ( var j = 0; j <= rows; j ++ ) {
  23875. if ( j === 0 && i === cols ) {
  23876. v[ i ][ j ] = aj;
  23877. } else {
  23878. v[ i ][ j ] = prepare( aj.clone().lerp( bj, j / rows ) );
  23879. }
  23880. }
  23881. }
  23882. // Construct all of the faces.
  23883. for ( var i = 0; i < cols ; i ++ ) {
  23884. for ( var j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
  23885. var k = Math.floor( j / 2 );
  23886. if ( j % 2 === 0 ) {
  23887. make(
  23888. v[ i ][ k + 1 ],
  23889. v[ i + 1 ][ k ],
  23890. v[ i ][ k ]
  23891. );
  23892. } else {
  23893. make(
  23894. v[ i ][ k + 1 ],
  23895. v[ i + 1 ][ k + 1 ],
  23896. v[ i + 1 ][ k ]
  23897. );
  23898. }
  23899. }
  23900. }
  23901. }
  23902. // Angle around the Y axis, counter-clockwise when looking from above.
  23903. function azimuth( vector ) {
  23904. return Math.atan2( vector.z, - vector.x );
  23905. }
  23906. // Angle above the XZ plane.
  23907. function inclination( vector ) {
  23908. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  23909. }
  23910. // Texture fixing helper. Spheres have some odd behaviours.
  23911. function correctUV( uv, vector, azimuth ) {
  23912. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) uv = new THREE.Vector2( uv.x - 1, uv.y );
  23913. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) uv = new THREE.Vector2( azimuth / 2 / Math.PI + 0.5, uv.y );
  23914. return uv.clone();
  23915. }
  23916. };
  23917. THREE.PolyhedronGeometry.prototype = Object.create( THREE.Geometry.prototype );
  23918. THREE.PolyhedronGeometry.prototype.constructor = THREE.PolyhedronGeometry;
  23919. // File:src/extras/geometries/DodecahedronGeometry.js
  23920. /**
  23921. * @author Abe Pazos / https://hamoid.com
  23922. */
  23923. THREE.DodecahedronGeometry = function ( radius, detail ) {
  23924. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  23925. var r = 1 / t;
  23926. var vertices = [
  23927. // (±1, ±1, ±1)
  23928. - 1, - 1, - 1, - 1, - 1, 1,
  23929. - 1, 1, - 1, - 1, 1, 1,
  23930. 1, - 1, - 1, 1, - 1, 1,
  23931. 1, 1, - 1, 1, 1, 1,
  23932. // (0, ±1/φ, ±φ)
  23933. 0, - r, - t, 0, - r, t,
  23934. 0, r, - t, 0, r, t,
  23935. // (±1/φ, ±φ, 0)
  23936. - r, - t, 0, - r, t, 0,
  23937. r, - t, 0, r, t, 0,
  23938. // (±φ, 0, ±1/φ)
  23939. - t, 0, - r, t, 0, - r,
  23940. - t, 0, r, t, 0, r
  23941. ];
  23942. var indices = [
  23943. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  23944. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  23945. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  23946. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  23947. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  23948. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  23949. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  23950. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  23951. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  23952. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  23953. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  23954. 1, 12, 14, 1, 14, 5, 1, 5, 9
  23955. ];
  23956. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  23957. this.type = 'DodecahedronGeometry';
  23958. this.parameters = {
  23959. radius: radius,
  23960. detail: detail
  23961. };
  23962. };
  23963. THREE.DodecahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  23964. THREE.DodecahedronGeometry.prototype.constructor = THREE.DodecahedronGeometry;
  23965. // File:src/extras/geometries/IcosahedronGeometry.js
  23966. /**
  23967. * @author timothypratley / https://github.com/timothypratley
  23968. */
  23969. THREE.IcosahedronGeometry = function ( radius, detail ) {
  23970. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  23971. var vertices = [
  23972. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  23973. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  23974. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  23975. ];
  23976. var indices = [
  23977. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  23978. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  23979. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  23980. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  23981. ];
  23982. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  23983. this.type = 'IcosahedronGeometry';
  23984. this.parameters = {
  23985. radius: radius,
  23986. detail: detail
  23987. };
  23988. };
  23989. THREE.IcosahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  23990. THREE.IcosahedronGeometry.prototype.constructor = THREE.IcosahedronGeometry;
  23991. // File:src/extras/geometries/OctahedronGeometry.js
  23992. /**
  23993. * @author timothypratley / https://github.com/timothypratley
  23994. */
  23995. THREE.OctahedronGeometry = function ( radius, detail ) {
  23996. var vertices = [
  23997. 1, 0, 0, - 1, 0, 0, 0, 1, 0, 0, - 1, 0, 0, 0, 1, 0, 0, - 1
  23998. ];
  23999. var indices = [
  24000. 0, 2, 4, 0, 4, 3, 0, 3, 5, 0, 5, 2, 1, 2, 5, 1, 5, 3, 1, 3, 4, 1, 4, 2
  24001. ];
  24002. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  24003. this.type = 'OctahedronGeometry';
  24004. this.parameters = {
  24005. radius: radius,
  24006. detail: detail
  24007. };
  24008. };
  24009. THREE.OctahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  24010. THREE.OctahedronGeometry.prototype.constructor = THREE.OctahedronGeometry;
  24011. // File:src/extras/geometries/TetrahedronGeometry.js
  24012. /**
  24013. * @author timothypratley / https://github.com/timothypratley
  24014. */
  24015. THREE.TetrahedronGeometry = function ( radius, detail ) {
  24016. var vertices = [
  24017. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  24018. ];
  24019. var indices = [
  24020. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  24021. ];
  24022. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  24023. this.type = 'TetrahedronGeometry';
  24024. this.parameters = {
  24025. radius: radius,
  24026. detail: detail
  24027. };
  24028. };
  24029. THREE.TetrahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  24030. THREE.TetrahedronGeometry.prototype.constructor = THREE.TetrahedronGeometry;
  24031. // File:src/extras/geometries/ParametricGeometry.js
  24032. /**
  24033. * @author zz85 / https://github.com/zz85
  24034. * Parametric Surfaces Geometry
  24035. * based on the brilliant article by @prideout http://prideout.net/blog/?p=44
  24036. *
  24037. * new THREE.ParametricGeometry( parametricFunction, uSegments, ySegements );
  24038. *
  24039. */
  24040. THREE.ParametricGeometry = function ( func, slices, stacks ) {
  24041. THREE.Geometry.call( this );
  24042. this.type = 'ParametricGeometry';
  24043. this.parameters = {
  24044. func: func,
  24045. slices: slices,
  24046. stacks: stacks
  24047. };
  24048. var verts = this.vertices;
  24049. var faces = this.faces;
  24050. var uvs = this.faceVertexUvs[ 0 ];
  24051. var i, j, p;
  24052. var u, v;
  24053. var sliceCount = slices + 1;
  24054. for ( i = 0; i <= stacks; i ++ ) {
  24055. v = i / stacks;
  24056. for ( j = 0; j <= slices; j ++ ) {
  24057. u = j / slices;
  24058. p = func( u, v );
  24059. verts.push( p );
  24060. }
  24061. }
  24062. var a, b, c, d;
  24063. var uva, uvb, uvc, uvd;
  24064. for ( i = 0; i < stacks; i ++ ) {
  24065. for ( j = 0; j < slices; j ++ ) {
  24066. a = i * sliceCount + j;
  24067. b = i * sliceCount + j + 1;
  24068. c = ( i + 1 ) * sliceCount + j + 1;
  24069. d = ( i + 1 ) * sliceCount + j;
  24070. uva = new THREE.Vector2( j / slices, i / stacks );
  24071. uvb = new THREE.Vector2( ( j + 1 ) / slices, i / stacks );
  24072. uvc = new THREE.Vector2( ( j + 1 ) / slices, ( i + 1 ) / stacks );
  24073. uvd = new THREE.Vector2( j / slices, ( i + 1 ) / stacks );
  24074. faces.push( new THREE.Face3( a, b, d ) );
  24075. uvs.push( [ uva, uvb, uvd ] );
  24076. faces.push( new THREE.Face3( b, c, d ) );
  24077. uvs.push( [ uvb.clone(), uvc, uvd.clone() ] );
  24078. }
  24079. }
  24080. // console.log(this);
  24081. // magic bullet
  24082. // var diff = this.mergeVertices();
  24083. // console.log('removed ', diff, ' vertices by merging');
  24084. this.computeFaceNormals();
  24085. this.computeVertexNormals();
  24086. };
  24087. THREE.ParametricGeometry.prototype = Object.create( THREE.Geometry.prototype );
  24088. THREE.ParametricGeometry.prototype.constructor = THREE.ParametricGeometry;
  24089. // File:src/extras/geometries/WireframeGeometry.js
  24090. /**
  24091. * @author mrdoob / http://mrdoob.com/
  24092. */
  24093. THREE.WireframeGeometry = function ( geometry ) {
  24094. THREE.BufferGeometry.call( this );
  24095. var edge = [ 0, 0 ], hash = {};
  24096. function sortFunction( a, b ) {
  24097. return a - b;
  24098. }
  24099. var keys = [ 'a', 'b', 'c' ];
  24100. if ( geometry instanceof THREE.Geometry ) {
  24101. var vertices = geometry.vertices;
  24102. var faces = geometry.faces;
  24103. var numEdges = 0;
  24104. // allocate maximal size
  24105. var edges = new Uint32Array( 6 * faces.length );
  24106. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  24107. var face = faces[ i ];
  24108. for ( var j = 0; j < 3; j ++ ) {
  24109. edge[ 0 ] = face[ keys[ j ] ];
  24110. edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
  24111. edge.sort( sortFunction );
  24112. var key = edge.toString();
  24113. if ( hash[ key ] === undefined ) {
  24114. edges[ 2 * numEdges ] = edge[ 0 ];
  24115. edges[ 2 * numEdges + 1 ] = edge[ 1 ];
  24116. hash[ key ] = true;
  24117. numEdges ++;
  24118. }
  24119. }
  24120. }
  24121. var coords = new Float32Array( numEdges * 2 * 3 );
  24122. for ( var i = 0, l = numEdges; i < l; i ++ ) {
  24123. for ( var j = 0; j < 2; j ++ ) {
  24124. var vertex = vertices[ edges [ 2 * i + j ] ];
  24125. var index = 6 * i + 3 * j;
  24126. coords[ index + 0 ] = vertex.x;
  24127. coords[ index + 1 ] = vertex.y;
  24128. coords[ index + 2 ] = vertex.z;
  24129. }
  24130. }
  24131. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  24132. } else if ( geometry instanceof THREE.BufferGeometry ) {
  24133. if ( geometry.index !== null ) {
  24134. // Indexed BufferGeometry
  24135. var indices = geometry.index.array;
  24136. var vertices = geometry.attributes.position;
  24137. var groups = geometry.groups;
  24138. var numEdges = 0;
  24139. if ( groups.length === 0 ) {
  24140. geometry.addGroup( 0, indices.length );
  24141. }
  24142. // allocate maximal size
  24143. var edges = new Uint32Array( 2 * indices.length );
  24144. for ( var o = 0, ol = groups.length; o < ol; ++ o ) {
  24145. var group = groups[ o ];
  24146. var start = group.start;
  24147. var count = group.count;
  24148. for ( var i = start, il = start + count; i < il; i += 3 ) {
  24149. for ( var j = 0; j < 3; j ++ ) {
  24150. edge[ 0 ] = indices[ i + j ];
  24151. edge[ 1 ] = indices[ i + ( j + 1 ) % 3 ];
  24152. edge.sort( sortFunction );
  24153. var key = edge.toString();
  24154. if ( hash[ key ] === undefined ) {
  24155. edges[ 2 * numEdges ] = edge[ 0 ];
  24156. edges[ 2 * numEdges + 1 ] = edge[ 1 ];
  24157. hash[ key ] = true;
  24158. numEdges ++;
  24159. }
  24160. }
  24161. }
  24162. }
  24163. var coords = new Float32Array( numEdges * 2 * 3 );
  24164. for ( var i = 0, l = numEdges; i < l; i ++ ) {
  24165. for ( var j = 0; j < 2; j ++ ) {
  24166. var index = 6 * i + 3 * j;
  24167. var index2 = edges[ 2 * i + j ];
  24168. coords[ index + 0 ] = vertices.getX( index2 );
  24169. coords[ index + 1 ] = vertices.getY( index2 );
  24170. coords[ index + 2 ] = vertices.getZ( index2 );
  24171. }
  24172. }
  24173. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  24174. } else {
  24175. // non-indexed BufferGeometry
  24176. var vertices = geometry.attributes.position.array;
  24177. var numEdges = vertices.length / 3;
  24178. var numTris = numEdges / 3;
  24179. var coords = new Float32Array( numEdges * 2 * 3 );
  24180. for ( var i = 0, l = numTris; i < l; i ++ ) {
  24181. for ( var j = 0; j < 3; j ++ ) {
  24182. var index = 18 * i + 6 * j;
  24183. var index1 = 9 * i + 3 * j;
  24184. coords[ index + 0 ] = vertices[ index1 ];
  24185. coords[ index + 1 ] = vertices[ index1 + 1 ];
  24186. coords[ index + 2 ] = vertices[ index1 + 2 ];
  24187. var index2 = 9 * i + 3 * ( ( j + 1 ) % 3 );
  24188. coords[ index + 3 ] = vertices[ index2 ];
  24189. coords[ index + 4 ] = vertices[ index2 + 1 ];
  24190. coords[ index + 5 ] = vertices[ index2 + 2 ];
  24191. }
  24192. }
  24193. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  24194. }
  24195. }
  24196. };
  24197. THREE.WireframeGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  24198. THREE.WireframeGeometry.prototype.constructor = THREE.WireframeGeometry;
  24199. // File:src/extras/helpers/AxisHelper.js
  24200. /**
  24201. * @author sroucheray / http://sroucheray.org/
  24202. * @author mrdoob / http://mrdoob.com/
  24203. */
  24204. THREE.AxisHelper = function ( size ) {
  24205. size = size || 1;
  24206. var vertices = new Float32Array( [
  24207. 0, 0, 0, size, 0, 0,
  24208. 0, 0, 0, 0, size, 0,
  24209. 0, 0, 0, 0, 0, size
  24210. ] );
  24211. var colors = new Float32Array( [
  24212. 1, 0, 0, 1, 0.6, 0,
  24213. 0, 1, 0, 0.6, 1, 0,
  24214. 0, 0, 1, 0, 0.6, 1
  24215. ] );
  24216. var geometry = new THREE.BufferGeometry();
  24217. geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  24218. geometry.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ) );
  24219. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
  24220. THREE.LineSegments.call( this, geometry, material );
  24221. };
  24222. THREE.AxisHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24223. THREE.AxisHelper.prototype.constructor = THREE.AxisHelper;
  24224. // File:src/extras/helpers/ArrowHelper.js
  24225. /**
  24226. * @author WestLangley / http://github.com/WestLangley
  24227. * @author zz85 / http://github.com/zz85
  24228. * @author bhouston / http://clara.io
  24229. *
  24230. * Creates an arrow for visualizing directions
  24231. *
  24232. * Parameters:
  24233. * dir - Vector3
  24234. * origin - Vector3
  24235. * length - Number
  24236. * color - color in hex value
  24237. * headLength - Number
  24238. * headWidth - Number
  24239. */
  24240. THREE.ArrowHelper = ( function () {
  24241. var lineGeometry = new THREE.BufferGeometry();
  24242. lineGeometry.addAttribute( 'position', new THREE.Float32Attribute( [ 0, 0, 0, 0, 1, 0 ], 3 ) );
  24243. var coneGeometry = new THREE.CylinderBufferGeometry( 0, 0.5, 1, 5, 1 );
  24244. coneGeometry.translate( 0, - 0.5, 0 );
  24245. return function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
  24246. // dir is assumed to be normalized
  24247. THREE.Object3D.call( this );
  24248. if ( color === undefined ) color = 0xffff00;
  24249. if ( length === undefined ) length = 1;
  24250. if ( headLength === undefined ) headLength = 0.2 * length;
  24251. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  24252. this.position.copy( origin );
  24253. this.line = new THREE.Line( lineGeometry, new THREE.LineBasicMaterial( { color: color } ) );
  24254. this.line.matrixAutoUpdate = false;
  24255. this.add( this.line );
  24256. this.cone = new THREE.Mesh( coneGeometry, new THREE.MeshBasicMaterial( { color: color } ) );
  24257. this.cone.matrixAutoUpdate = false;
  24258. this.add( this.cone );
  24259. this.setDirection( dir );
  24260. this.setLength( length, headLength, headWidth );
  24261. };
  24262. }() );
  24263. THREE.ArrowHelper.prototype = Object.create( THREE.Object3D.prototype );
  24264. THREE.ArrowHelper.prototype.constructor = THREE.ArrowHelper;
  24265. THREE.ArrowHelper.prototype.setDirection = ( function () {
  24266. var axis = new THREE.Vector3();
  24267. var radians;
  24268. return function setDirection( dir ) {
  24269. // dir is assumed to be normalized
  24270. if ( dir.y > 0.99999 ) {
  24271. this.quaternion.set( 0, 0, 0, 1 );
  24272. } else if ( dir.y < - 0.99999 ) {
  24273. this.quaternion.set( 1, 0, 0, 0 );
  24274. } else {
  24275. axis.set( dir.z, 0, - dir.x ).normalize();
  24276. radians = Math.acos( dir.y );
  24277. this.quaternion.setFromAxisAngle( axis, radians );
  24278. }
  24279. };
  24280. }() );
  24281. THREE.ArrowHelper.prototype.setLength = function ( length, headLength, headWidth ) {
  24282. if ( headLength === undefined ) headLength = 0.2 * length;
  24283. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  24284. this.line.scale.set( 1, Math.max( 0, length - headLength ), 1 );
  24285. this.line.updateMatrix();
  24286. this.cone.scale.set( headWidth, headLength, headWidth );
  24287. this.cone.position.y = length;
  24288. this.cone.updateMatrix();
  24289. };
  24290. THREE.ArrowHelper.prototype.setColor = function ( color ) {
  24291. this.line.material.color.copy( color );
  24292. this.cone.material.color.copy( color );
  24293. };
  24294. // File:src/extras/helpers/BoxHelper.js
  24295. /**
  24296. * @author mrdoob / http://mrdoob.com/
  24297. */
  24298. THREE.BoxHelper = function ( object, color ) {
  24299. if ( color === undefined ) color = 0xffff00;
  24300. 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 ] );
  24301. var positions = new Float32Array( 8 * 3 );
  24302. var geometry = new THREE.BufferGeometry();
  24303. geometry.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  24304. geometry.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
  24305. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color } ) );
  24306. if ( object !== undefined ) {
  24307. this.update( object );
  24308. }
  24309. };
  24310. THREE.BoxHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24311. THREE.BoxHelper.prototype.constructor = THREE.BoxHelper;
  24312. THREE.BoxHelper.prototype.update = ( function () {
  24313. var box = new THREE.Box3();
  24314. return function update( object ) {
  24315. if ( object instanceof THREE.Box3 ) {
  24316. box.copy( object );
  24317. } else {
  24318. box.setFromObject( object );
  24319. }
  24320. if ( box.isEmpty() ) return;
  24321. var min = box.min;
  24322. var max = box.max;
  24323. /*
  24324. 5____4
  24325. 1/___0/|
  24326. | 6__|_7
  24327. 2/___3/
  24328. 0: max.x, max.y, max.z
  24329. 1: min.x, max.y, max.z
  24330. 2: min.x, min.y, max.z
  24331. 3: max.x, min.y, max.z
  24332. 4: max.x, max.y, min.z
  24333. 5: min.x, max.y, min.z
  24334. 6: min.x, min.y, min.z
  24335. 7: max.x, min.y, min.z
  24336. */
  24337. var position = this.geometry.attributes.position;
  24338. var array = position.array;
  24339. array[ 0 ] = max.x; array[ 1 ] = max.y; array[ 2 ] = max.z;
  24340. array[ 3 ] = min.x; array[ 4 ] = max.y; array[ 5 ] = max.z;
  24341. array[ 6 ] = min.x; array[ 7 ] = min.y; array[ 8 ] = max.z;
  24342. array[ 9 ] = max.x; array[ 10 ] = min.y; array[ 11 ] = max.z;
  24343. array[ 12 ] = max.x; array[ 13 ] = max.y; array[ 14 ] = min.z;
  24344. array[ 15 ] = min.x; array[ 16 ] = max.y; array[ 17 ] = min.z;
  24345. array[ 18 ] = min.x; array[ 19 ] = min.y; array[ 20 ] = min.z;
  24346. array[ 21 ] = max.x; array[ 22 ] = min.y; array[ 23 ] = min.z;
  24347. position.needsUpdate = true;
  24348. this.geometry.computeBoundingSphere();
  24349. };
  24350. } )();
  24351. // File:src/extras/helpers/BoundingBoxHelper.js
  24352. /**
  24353. * @author WestLangley / http://github.com/WestLangley
  24354. */
  24355. // a helper to show the world-axis-aligned bounding box for an object
  24356. THREE.BoundingBoxHelper = function ( object, hex ) {
  24357. var color = ( hex !== undefined ) ? hex : 0x888888;
  24358. this.object = object;
  24359. this.box = new THREE.Box3();
  24360. THREE.Mesh.call( this, new THREE.BoxGeometry( 1, 1, 1 ), new THREE.MeshBasicMaterial( { color: color, wireframe: true } ) );
  24361. };
  24362. THREE.BoundingBoxHelper.prototype = Object.create( THREE.Mesh.prototype );
  24363. THREE.BoundingBoxHelper.prototype.constructor = THREE.BoundingBoxHelper;
  24364. THREE.BoundingBoxHelper.prototype.update = function () {
  24365. this.box.setFromObject( this.object );
  24366. this.box.size( this.scale );
  24367. this.box.center( this.position );
  24368. };
  24369. // File:src/extras/helpers/CameraHelper.js
  24370. /**
  24371. * @author alteredq / http://alteredqualia.com/
  24372. *
  24373. * - shows frustum, line of sight and up of the camera
  24374. * - suitable for fast updates
  24375. * - based on frustum visualization in lightgl.js shadowmap example
  24376. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  24377. */
  24378. THREE.CameraHelper = function ( camera ) {
  24379. var geometry = new THREE.Geometry();
  24380. var material = new THREE.LineBasicMaterial( { color: 0xffffff, vertexColors: THREE.FaceColors } );
  24381. var pointMap = {};
  24382. // colors
  24383. var hexFrustum = 0xffaa00;
  24384. var hexCone = 0xff0000;
  24385. var hexUp = 0x00aaff;
  24386. var hexTarget = 0xffffff;
  24387. var hexCross = 0x333333;
  24388. // near
  24389. addLine( "n1", "n2", hexFrustum );
  24390. addLine( "n2", "n4", hexFrustum );
  24391. addLine( "n4", "n3", hexFrustum );
  24392. addLine( "n3", "n1", hexFrustum );
  24393. // far
  24394. addLine( "f1", "f2", hexFrustum );
  24395. addLine( "f2", "f4", hexFrustum );
  24396. addLine( "f4", "f3", hexFrustum );
  24397. addLine( "f3", "f1", hexFrustum );
  24398. // sides
  24399. addLine( "n1", "f1", hexFrustum );
  24400. addLine( "n2", "f2", hexFrustum );
  24401. addLine( "n3", "f3", hexFrustum );
  24402. addLine( "n4", "f4", hexFrustum );
  24403. // cone
  24404. addLine( "p", "n1", hexCone );
  24405. addLine( "p", "n2", hexCone );
  24406. addLine( "p", "n3", hexCone );
  24407. addLine( "p", "n4", hexCone );
  24408. // up
  24409. addLine( "u1", "u2", hexUp );
  24410. addLine( "u2", "u3", hexUp );
  24411. addLine( "u3", "u1", hexUp );
  24412. // target
  24413. addLine( "c", "t", hexTarget );
  24414. addLine( "p", "c", hexCross );
  24415. // cross
  24416. addLine( "cn1", "cn2", hexCross );
  24417. addLine( "cn3", "cn4", hexCross );
  24418. addLine( "cf1", "cf2", hexCross );
  24419. addLine( "cf3", "cf4", hexCross );
  24420. function addLine( a, b, hex ) {
  24421. addPoint( a, hex );
  24422. addPoint( b, hex );
  24423. }
  24424. function addPoint( id, hex ) {
  24425. geometry.vertices.push( new THREE.Vector3() );
  24426. geometry.colors.push( new THREE.Color( hex ) );
  24427. if ( pointMap[ id ] === undefined ) {
  24428. pointMap[ id ] = [];
  24429. }
  24430. pointMap[ id ].push( geometry.vertices.length - 1 );
  24431. }
  24432. THREE.LineSegments.call( this, geometry, material );
  24433. this.camera = camera;
  24434. if( this.camera.updateProjectionMatrix ) this.camera.updateProjectionMatrix();
  24435. this.matrix = camera.matrixWorld;
  24436. this.matrixAutoUpdate = false;
  24437. this.pointMap = pointMap;
  24438. this.update();
  24439. };
  24440. THREE.CameraHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24441. THREE.CameraHelper.prototype.constructor = THREE.CameraHelper;
  24442. THREE.CameraHelper.prototype.update = function () {
  24443. var geometry, pointMap;
  24444. var vector = new THREE.Vector3();
  24445. var camera = new THREE.Camera();
  24446. function setPoint( point, x, y, z ) {
  24447. vector.set( x, y, z ).unproject( camera );
  24448. var points = pointMap[ point ];
  24449. if ( points !== undefined ) {
  24450. for ( var i = 0, il = points.length; i < il; i ++ ) {
  24451. geometry.vertices[ points[ i ] ].copy( vector );
  24452. }
  24453. }
  24454. }
  24455. return function update() {
  24456. geometry = this.geometry;
  24457. pointMap = this.pointMap;
  24458. var w = 1, h = 1;
  24459. // we need just camera projection matrix
  24460. // world matrix must be identity
  24461. camera.projectionMatrix.copy( this.camera.projectionMatrix );
  24462. // center / target
  24463. setPoint( "c", 0, 0, - 1 );
  24464. setPoint( "t", 0, 0, 1 );
  24465. // near
  24466. setPoint( "n1", - w, - h, - 1 );
  24467. setPoint( "n2", w, - h, - 1 );
  24468. setPoint( "n3", - w, h, - 1 );
  24469. setPoint( "n4", w, h, - 1 );
  24470. // far
  24471. setPoint( "f1", - w, - h, 1 );
  24472. setPoint( "f2", w, - h, 1 );
  24473. setPoint( "f3", - w, h, 1 );
  24474. setPoint( "f4", w, h, 1 );
  24475. // up
  24476. setPoint( "u1", w * 0.7, h * 1.1, - 1 );
  24477. setPoint( "u2", - w * 0.7, h * 1.1, - 1 );
  24478. setPoint( "u3", 0, h * 2, - 1 );
  24479. // cross
  24480. setPoint( "cf1", - w, 0, 1 );
  24481. setPoint( "cf2", w, 0, 1 );
  24482. setPoint( "cf3", 0, - h, 1 );
  24483. setPoint( "cf4", 0, h, 1 );
  24484. setPoint( "cn1", - w, 0, - 1 );
  24485. setPoint( "cn2", w, 0, - 1 );
  24486. setPoint( "cn3", 0, - h, - 1 );
  24487. setPoint( "cn4", 0, h, - 1 );
  24488. geometry.verticesNeedUpdate = true;
  24489. };
  24490. }();
  24491. // File:src/extras/helpers/DirectionalLightHelper.js
  24492. /**
  24493. * @author alteredq / http://alteredqualia.com/
  24494. * @author mrdoob / http://mrdoob.com/
  24495. * @author WestLangley / http://github.com/WestLangley
  24496. */
  24497. THREE.DirectionalLightHelper = function ( light, size ) {
  24498. THREE.Object3D.call( this );
  24499. this.light = light;
  24500. this.light.updateMatrixWorld();
  24501. this.matrix = light.matrixWorld;
  24502. this.matrixAutoUpdate = false;
  24503. if ( size === undefined ) size = 1;
  24504. var geometry = new THREE.BufferGeometry();
  24505. geometry.addAttribute( 'position', new THREE.Float32Attribute( [
  24506. - size, size, 0,
  24507. size, size, 0,
  24508. size, - size, 0,
  24509. - size, - size, 0,
  24510. - size, size, 0
  24511. ], 3 ) );
  24512. var material = new THREE.LineBasicMaterial( { fog: false } );
  24513. this.add( new THREE.Line( geometry, material ) );
  24514. geometry = new THREE.BufferGeometry();
  24515. geometry.addAttribute( 'position', new THREE.Float32Attribute( [ 0, 0, 0, 0, 0, 1 ], 3 ) );
  24516. this.add( new THREE.Line( geometry, material ));
  24517. this.update();
  24518. };
  24519. THREE.DirectionalLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  24520. THREE.DirectionalLightHelper.prototype.constructor = THREE.DirectionalLightHelper;
  24521. THREE.DirectionalLightHelper.prototype.dispose = function () {
  24522. var lightPlane = this.children[ 0 ];
  24523. var targetLine = this.children[ 1 ];
  24524. lightPlane.geometry.dispose();
  24525. lightPlane.material.dispose();
  24526. targetLine.geometry.dispose();
  24527. targetLine.material.dispose();
  24528. };
  24529. THREE.DirectionalLightHelper.prototype.update = function () {
  24530. var v1 = new THREE.Vector3();
  24531. var v2 = new THREE.Vector3();
  24532. var v3 = new THREE.Vector3();
  24533. return function update() {
  24534. v1.setFromMatrixPosition( this.light.matrixWorld );
  24535. v2.setFromMatrixPosition( this.light.target.matrixWorld );
  24536. v3.subVectors( v2, v1 );
  24537. var lightPlane = this.children[ 0 ];
  24538. var targetLine = this.children[ 1 ];
  24539. lightPlane.lookAt( v3 );
  24540. lightPlane.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  24541. targetLine.lookAt( v3 );
  24542. targetLine.scale.z = v3.length();
  24543. };
  24544. }();
  24545. // File:src/extras/helpers/EdgesHelper.js
  24546. /**
  24547. * @author WestLangley / http://github.com/WestLangley
  24548. * @param object THREE.Mesh whose geometry will be used
  24549. * @param hex line color
  24550. * @param thresholdAngle the minimum angle (in degrees),
  24551. * between the face normals of adjacent faces,
  24552. * that is required to render an edge. A value of 10 means
  24553. * an edge is only rendered if the angle is at least 10 degrees.
  24554. */
  24555. THREE.EdgesHelper = function ( object, hex, thresholdAngle ) {
  24556. var color = ( hex !== undefined ) ? hex : 0xffffff;
  24557. THREE.LineSegments.call( this, new THREE.EdgesGeometry( object.geometry, thresholdAngle ), new THREE.LineBasicMaterial( { color: color } ) );
  24558. this.matrix = object.matrixWorld;
  24559. this.matrixAutoUpdate = false;
  24560. };
  24561. THREE.EdgesHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24562. THREE.EdgesHelper.prototype.constructor = THREE.EdgesHelper;
  24563. // File:src/extras/helpers/FaceNormalsHelper.js
  24564. /**
  24565. * @author mrdoob / http://mrdoob.com/
  24566. * @author WestLangley / http://github.com/WestLangley
  24567. */
  24568. THREE.FaceNormalsHelper = function ( object, size, hex, linewidth ) {
  24569. // FaceNormalsHelper only supports THREE.Geometry
  24570. this.object = object;
  24571. this.size = ( size !== undefined ) ? size : 1;
  24572. var color = ( hex !== undefined ) ? hex : 0xffff00;
  24573. var width = ( linewidth !== undefined ) ? linewidth : 1;
  24574. //
  24575. var nNormals = 0;
  24576. var objGeometry = this.object.geometry;
  24577. if ( objGeometry instanceof THREE.Geometry ) {
  24578. nNormals = objGeometry.faces.length;
  24579. } else {
  24580. console.warn( 'THREE.FaceNormalsHelper: only THREE.Geometry is supported. Use THREE.VertexNormalsHelper, instead.' );
  24581. }
  24582. //
  24583. var geometry = new THREE.BufferGeometry();
  24584. var positions = new THREE.Float32Attribute( nNormals * 2 * 3, 3 );
  24585. geometry.addAttribute( 'position', positions );
  24586. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  24587. //
  24588. this.matrixAutoUpdate = false;
  24589. this.update();
  24590. };
  24591. THREE.FaceNormalsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24592. THREE.FaceNormalsHelper.prototype.constructor = THREE.FaceNormalsHelper;
  24593. THREE.FaceNormalsHelper.prototype.update = ( function () {
  24594. var v1 = new THREE.Vector3();
  24595. var v2 = new THREE.Vector3();
  24596. var normalMatrix = new THREE.Matrix3();
  24597. return function update() {
  24598. this.object.updateMatrixWorld( true );
  24599. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  24600. var matrixWorld = this.object.matrixWorld;
  24601. var position = this.geometry.attributes.position;
  24602. //
  24603. var objGeometry = this.object.geometry;
  24604. var vertices = objGeometry.vertices;
  24605. var faces = objGeometry.faces;
  24606. var idx = 0;
  24607. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  24608. var face = faces[ i ];
  24609. var normal = face.normal;
  24610. v1.copy( vertices[ face.a ] )
  24611. .add( vertices[ face.b ] )
  24612. .add( vertices[ face.c ] )
  24613. .divideScalar( 3 )
  24614. .applyMatrix4( matrixWorld );
  24615. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  24616. position.setXYZ( idx, v1.x, v1.y, v1.z );
  24617. idx = idx + 1;
  24618. position.setXYZ( idx, v2.x, v2.y, v2.z );
  24619. idx = idx + 1;
  24620. }
  24621. position.needsUpdate = true;
  24622. return this;
  24623. };
  24624. }() );
  24625. // File:src/extras/helpers/GridHelper.js
  24626. /**
  24627. * @author mrdoob / http://mrdoob.com/
  24628. */
  24629. THREE.GridHelper = function ( size, divisions, color1, color2 ) {
  24630. divisions = divisions || 1;
  24631. color1 = new THREE.Color( color1 !== undefined ? color1 : 0x444444 );
  24632. color2 = new THREE.Color( color2 !== undefined ? color2 : 0x888888 );
  24633. var center = divisions / 2;
  24634. var step = ( size * 2 ) / divisions;
  24635. var vertices = [], colors = [];
  24636. for ( var i = 0, j = 0, k = - size; i <= divisions; i ++, k += step ) {
  24637. vertices.push( - size, 0, k, size, 0, k );
  24638. vertices.push( k, 0, - size, k, 0, size );
  24639. var color = i === center ? color1 : color2;
  24640. color.toArray( colors, j ); j += 3;
  24641. color.toArray( colors, j ); j += 3;
  24642. color.toArray( colors, j ); j += 3;
  24643. color.toArray( colors, j ); j += 3;
  24644. }
  24645. var geometry = new THREE.BufferGeometry();
  24646. geometry.addAttribute( 'position', new THREE.Float32Attribute( vertices, 3 ) );
  24647. geometry.addAttribute( 'color', new THREE.Float32Attribute( colors, 3 ) );
  24648. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
  24649. THREE.LineSegments.call( this, geometry, material );
  24650. };
  24651. THREE.GridHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24652. THREE.GridHelper.prototype.constructor = THREE.GridHelper;
  24653. THREE.GridHelper.prototype.setColors = function () {
  24654. console.error( 'THREE.GridHelper: setColors() has been deprecated, pass them in the constructor instead.' );
  24655. };
  24656. // File:src/extras/helpers/HemisphereLightHelper.js
  24657. /**
  24658. * @author alteredq / http://alteredqualia.com/
  24659. * @author mrdoob / http://mrdoob.com/
  24660. */
  24661. THREE.HemisphereLightHelper = function ( light, sphereSize ) {
  24662. THREE.Object3D.call( this );
  24663. this.light = light;
  24664. this.light.updateMatrixWorld();
  24665. this.matrix = light.matrixWorld;
  24666. this.matrixAutoUpdate = false;
  24667. this.colors = [ new THREE.Color(), new THREE.Color() ];
  24668. var geometry = new THREE.SphereGeometry( sphereSize, 4, 2 );
  24669. geometry.rotateX( - Math.PI / 2 );
  24670. for ( var i = 0, il = 8; i < il; i ++ ) {
  24671. geometry.faces[ i ].color = this.colors[ i < 4 ? 0 : 1 ];
  24672. }
  24673. var material = new THREE.MeshBasicMaterial( { vertexColors: THREE.FaceColors, wireframe: true } );
  24674. this.lightSphere = new THREE.Mesh( geometry, material );
  24675. this.add( this.lightSphere );
  24676. this.update();
  24677. };
  24678. THREE.HemisphereLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  24679. THREE.HemisphereLightHelper.prototype.constructor = THREE.HemisphereLightHelper;
  24680. THREE.HemisphereLightHelper.prototype.dispose = function () {
  24681. this.lightSphere.geometry.dispose();
  24682. this.lightSphere.material.dispose();
  24683. };
  24684. THREE.HemisphereLightHelper.prototype.update = function () {
  24685. var vector = new THREE.Vector3();
  24686. return function update() {
  24687. this.colors[ 0 ].copy( this.light.color ).multiplyScalar( this.light.intensity );
  24688. this.colors[ 1 ].copy( this.light.groundColor ).multiplyScalar( this.light.intensity );
  24689. this.lightSphere.lookAt( vector.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  24690. this.lightSphere.geometry.colorsNeedUpdate = true;
  24691. };
  24692. }();
  24693. // File:src/extras/helpers/PointLightHelper.js
  24694. /**
  24695. * @author alteredq / http://alteredqualia.com/
  24696. * @author mrdoob / http://mrdoob.com/
  24697. */
  24698. THREE.PointLightHelper = function ( light, sphereSize ) {
  24699. this.light = light;
  24700. this.light.updateMatrixWorld();
  24701. var geometry = new THREE.SphereBufferGeometry( sphereSize, 4, 2 );
  24702. var material = new THREE.MeshBasicMaterial( { wireframe: true, fog: false } );
  24703. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  24704. THREE.Mesh.call( this, geometry, material );
  24705. this.matrix = this.light.matrixWorld;
  24706. this.matrixAutoUpdate = false;
  24707. /*
  24708. var distanceGeometry = new THREE.IcosahedronGeometry( 1, 2 );
  24709. var distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  24710. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  24711. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  24712. var d = light.distance;
  24713. if ( d === 0.0 ) {
  24714. this.lightDistance.visible = false;
  24715. } else {
  24716. this.lightDistance.scale.set( d, d, d );
  24717. }
  24718. this.add( this.lightDistance );
  24719. */
  24720. };
  24721. THREE.PointLightHelper.prototype = Object.create( THREE.Mesh.prototype );
  24722. THREE.PointLightHelper.prototype.constructor = THREE.PointLightHelper;
  24723. THREE.PointLightHelper.prototype.dispose = function () {
  24724. this.geometry.dispose();
  24725. this.material.dispose();
  24726. };
  24727. THREE.PointLightHelper.prototype.update = function () {
  24728. this.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  24729. /*
  24730. var d = this.light.distance;
  24731. if ( d === 0.0 ) {
  24732. this.lightDistance.visible = false;
  24733. } else {
  24734. this.lightDistance.visible = true;
  24735. this.lightDistance.scale.set( d, d, d );
  24736. }
  24737. */
  24738. };
  24739. // File:src/extras/helpers/SkeletonHelper.js
  24740. /**
  24741. * @author Sean Griffin / http://twitter.com/sgrif
  24742. * @author Michael Guerrero / http://realitymeltdown.com
  24743. * @author mrdoob / http://mrdoob.com/
  24744. * @author ikerr / http://verold.com
  24745. */
  24746. THREE.SkeletonHelper = function ( object ) {
  24747. this.bones = this.getBoneList( object );
  24748. var geometry = new THREE.Geometry();
  24749. for ( var i = 0; i < this.bones.length; i ++ ) {
  24750. var bone = this.bones[ i ];
  24751. if ( bone.parent instanceof THREE.Bone ) {
  24752. geometry.vertices.push( new THREE.Vector3() );
  24753. geometry.vertices.push( new THREE.Vector3() );
  24754. geometry.colors.push( new THREE.Color( 0, 0, 1 ) );
  24755. geometry.colors.push( new THREE.Color( 0, 1, 0 ) );
  24756. }
  24757. }
  24758. geometry.dynamic = true;
  24759. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors, depthTest: false, depthWrite: false, transparent: true } );
  24760. THREE.LineSegments.call( this, geometry, material );
  24761. this.root = object;
  24762. this.matrix = object.matrixWorld;
  24763. this.matrixAutoUpdate = false;
  24764. this.update();
  24765. };
  24766. THREE.SkeletonHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24767. THREE.SkeletonHelper.prototype.constructor = THREE.SkeletonHelper;
  24768. THREE.SkeletonHelper.prototype.getBoneList = function( object ) {
  24769. var boneList = [];
  24770. if ( object instanceof THREE.Bone ) {
  24771. boneList.push( object );
  24772. }
  24773. for ( var i = 0; i < object.children.length; i ++ ) {
  24774. boneList.push.apply( boneList, this.getBoneList( object.children[ i ] ) );
  24775. }
  24776. return boneList;
  24777. };
  24778. THREE.SkeletonHelper.prototype.update = function () {
  24779. var geometry = this.geometry;
  24780. var matrixWorldInv = new THREE.Matrix4().getInverse( this.root.matrixWorld );
  24781. var boneMatrix = new THREE.Matrix4();
  24782. var j = 0;
  24783. for ( var i = 0; i < this.bones.length; i ++ ) {
  24784. var bone = this.bones[ i ];
  24785. if ( bone.parent instanceof THREE.Bone ) {
  24786. boneMatrix.multiplyMatrices( matrixWorldInv, bone.matrixWorld );
  24787. geometry.vertices[ j ].setFromMatrixPosition( boneMatrix );
  24788. boneMatrix.multiplyMatrices( matrixWorldInv, bone.parent.matrixWorld );
  24789. geometry.vertices[ j + 1 ].setFromMatrixPosition( boneMatrix );
  24790. j += 2;
  24791. }
  24792. }
  24793. geometry.verticesNeedUpdate = true;
  24794. geometry.computeBoundingSphere();
  24795. };
  24796. // File:src/extras/helpers/SpotLightHelper.js
  24797. /**
  24798. * @author alteredq / http://alteredqualia.com/
  24799. * @author mrdoob / http://mrdoob.com/
  24800. * @author WestLangley / http://github.com/WestLangley
  24801. */
  24802. THREE.SpotLightHelper = function ( light ) {
  24803. THREE.Object3D.call( this );
  24804. this.light = light;
  24805. this.light.updateMatrixWorld();
  24806. this.matrix = light.matrixWorld;
  24807. this.matrixAutoUpdate = false;
  24808. var geometry = new THREE.BufferGeometry();
  24809. var positions = [
  24810. 0, 0, 0, 0, 0, 1,
  24811. 0, 0, 0, 1, 0, 1,
  24812. 0, 0, 0, - 1, 0, 1,
  24813. 0, 0, 0, 0, 1, 1,
  24814. 0, 0, 0, 0, - 1, 1
  24815. ];
  24816. for ( var i = 0, j = 1, l = 32; i < l; i ++, j ++ ) {
  24817. var p1 = ( i / l ) * Math.PI * 2;
  24818. var p2 = ( j / l ) * Math.PI * 2;
  24819. positions.push(
  24820. Math.cos( p1 ), Math.sin( p1 ), 1,
  24821. Math.cos( p2 ), Math.sin( p2 ), 1
  24822. );
  24823. }
  24824. geometry.addAttribute( 'position', new THREE.Float32Attribute( positions, 3 ) );
  24825. var material = new THREE.LineBasicMaterial( { fog: false } );
  24826. this.cone = new THREE.LineSegments( geometry, material );
  24827. this.add( this.cone );
  24828. this.update();
  24829. };
  24830. THREE.SpotLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  24831. THREE.SpotLightHelper.prototype.constructor = THREE.SpotLightHelper;
  24832. THREE.SpotLightHelper.prototype.dispose = function () {
  24833. this.cone.geometry.dispose();
  24834. this.cone.material.dispose();
  24835. };
  24836. THREE.SpotLightHelper.prototype.update = function () {
  24837. var vector = new THREE.Vector3();
  24838. var vector2 = new THREE.Vector3();
  24839. return function update() {
  24840. var coneLength = this.light.distance ? this.light.distance : 1000;
  24841. var coneWidth = coneLength * Math.tan( this.light.angle );
  24842. this.cone.scale.set( coneWidth, coneWidth, coneLength );
  24843. vector.setFromMatrixPosition( this.light.matrixWorld );
  24844. vector2.setFromMatrixPosition( this.light.target.matrixWorld );
  24845. this.cone.lookAt( vector2.sub( vector ) );
  24846. this.cone.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  24847. };
  24848. }();
  24849. // File:src/extras/helpers/VertexNormalsHelper.js
  24850. /**
  24851. * @author mrdoob / http://mrdoob.com/
  24852. * @author WestLangley / http://github.com/WestLangley
  24853. */
  24854. THREE.VertexNormalsHelper = function ( object, size, hex, linewidth ) {
  24855. this.object = object;
  24856. this.size = ( size !== undefined ) ? size : 1;
  24857. var color = ( hex !== undefined ) ? hex : 0xff0000;
  24858. var width = ( linewidth !== undefined ) ? linewidth : 1;
  24859. //
  24860. var nNormals = 0;
  24861. var objGeometry = this.object.geometry;
  24862. if ( objGeometry instanceof THREE.Geometry ) {
  24863. nNormals = objGeometry.faces.length * 3;
  24864. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  24865. nNormals = objGeometry.attributes.normal.count;
  24866. }
  24867. //
  24868. var geometry = new THREE.BufferGeometry();
  24869. var positions = new THREE.Float32Attribute( nNormals * 2 * 3, 3 );
  24870. geometry.addAttribute( 'position', positions );
  24871. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  24872. //
  24873. this.matrixAutoUpdate = false;
  24874. this.update();
  24875. };
  24876. THREE.VertexNormalsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24877. THREE.VertexNormalsHelper.prototype.constructor = THREE.VertexNormalsHelper;
  24878. THREE.VertexNormalsHelper.prototype.update = ( function () {
  24879. var v1 = new THREE.Vector3();
  24880. var v2 = new THREE.Vector3();
  24881. var normalMatrix = new THREE.Matrix3();
  24882. return function update() {
  24883. var keys = [ 'a', 'b', 'c' ];
  24884. this.object.updateMatrixWorld( true );
  24885. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  24886. var matrixWorld = this.object.matrixWorld;
  24887. var position = this.geometry.attributes.position;
  24888. //
  24889. var objGeometry = this.object.geometry;
  24890. if ( objGeometry instanceof THREE.Geometry ) {
  24891. var vertices = objGeometry.vertices;
  24892. var faces = objGeometry.faces;
  24893. var idx = 0;
  24894. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  24895. var face = faces[ i ];
  24896. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  24897. var vertex = vertices[ face[ keys[ j ] ] ];
  24898. var normal = face.vertexNormals[ j ];
  24899. v1.copy( vertex ).applyMatrix4( matrixWorld );
  24900. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  24901. position.setXYZ( idx, v1.x, v1.y, v1.z );
  24902. idx = idx + 1;
  24903. position.setXYZ( idx, v2.x, v2.y, v2.z );
  24904. idx = idx + 1;
  24905. }
  24906. }
  24907. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  24908. var objPos = objGeometry.attributes.position;
  24909. var objNorm = objGeometry.attributes.normal;
  24910. var idx = 0;
  24911. // for simplicity, ignore index and drawcalls, and render every normal
  24912. for ( var j = 0, jl = objPos.count; j < jl; j ++ ) {
  24913. v1.set( objPos.getX( j ), objPos.getY( j ), objPos.getZ( j ) ).applyMatrix4( matrixWorld );
  24914. v2.set( objNorm.getX( j ), objNorm.getY( j ), objNorm.getZ( j ) );
  24915. v2.applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  24916. position.setXYZ( idx, v1.x, v1.y, v1.z );
  24917. idx = idx + 1;
  24918. position.setXYZ( idx, v2.x, v2.y, v2.z );
  24919. idx = idx + 1;
  24920. }
  24921. }
  24922. position.needsUpdate = true;
  24923. return this;
  24924. };
  24925. }() );
  24926. // File:src/extras/helpers/WireframeHelper.js
  24927. /**
  24928. * @author mrdoob / http://mrdoob.com/
  24929. */
  24930. THREE.WireframeHelper = function ( object, hex ) {
  24931. var color = ( hex !== undefined ) ? hex : 0xffffff;
  24932. THREE.LineSegments.call( this, new THREE.WireframeGeometry( object.geometry ), new THREE.LineBasicMaterial( { color: color } ) );
  24933. this.matrix = object.matrixWorld;
  24934. this.matrixAutoUpdate = false;
  24935. };
  24936. THREE.WireframeHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24937. THREE.WireframeHelper.prototype.constructor = THREE.WireframeHelper;
  24938. // File:src/extras/objects/ImmediateRenderObject.js
  24939. /**
  24940. * @author alteredq / http://alteredqualia.com/
  24941. */
  24942. THREE.ImmediateRenderObject = function ( material ) {
  24943. THREE.Object3D.call( this );
  24944. this.material = material;
  24945. this.render = function ( renderCallback ) {};
  24946. };
  24947. THREE.ImmediateRenderObject.prototype = Object.create( THREE.Object3D.prototype );
  24948. THREE.ImmediateRenderObject.prototype.constructor = THREE.ImmediateRenderObject;
  24949. // File:src/extras/objects/MorphBlendMesh.js
  24950. /**
  24951. * @author alteredq / http://alteredqualia.com/
  24952. */
  24953. THREE.MorphBlendMesh = function( geometry, material ) {
  24954. THREE.Mesh.call( this, geometry, material );
  24955. this.animationsMap = {};
  24956. this.animationsList = [];
  24957. // prepare default animation
  24958. // (all frames played together in 1 second)
  24959. var numFrames = this.geometry.morphTargets.length;
  24960. var name = "__default";
  24961. var startFrame = 0;
  24962. var endFrame = numFrames - 1;
  24963. var fps = numFrames / 1;
  24964. this.createAnimation( name, startFrame, endFrame, fps );
  24965. this.setAnimationWeight( name, 1 );
  24966. };
  24967. THREE.MorphBlendMesh.prototype = Object.create( THREE.Mesh.prototype );
  24968. THREE.MorphBlendMesh.prototype.constructor = THREE.MorphBlendMesh;
  24969. THREE.MorphBlendMesh.prototype.createAnimation = function ( name, start, end, fps ) {
  24970. var animation = {
  24971. start: start,
  24972. end: end,
  24973. length: end - start + 1,
  24974. fps: fps,
  24975. duration: ( end - start ) / fps,
  24976. lastFrame: 0,
  24977. currentFrame: 0,
  24978. active: false,
  24979. time: 0,
  24980. direction: 1,
  24981. weight: 1,
  24982. directionBackwards: false,
  24983. mirroredLoop: false
  24984. };
  24985. this.animationsMap[ name ] = animation;
  24986. this.animationsList.push( animation );
  24987. };
  24988. THREE.MorphBlendMesh.prototype.autoCreateAnimations = function ( fps ) {
  24989. var pattern = /([a-z]+)_?(\d+)/i;
  24990. var firstAnimation, frameRanges = {};
  24991. var geometry = this.geometry;
  24992. for ( var i = 0, il = geometry.morphTargets.length; i < il; i ++ ) {
  24993. var morph = geometry.morphTargets[ i ];
  24994. var chunks = morph.name.match( pattern );
  24995. if ( chunks && chunks.length > 1 ) {
  24996. var name = chunks[ 1 ];
  24997. if ( ! frameRanges[ name ] ) frameRanges[ name ] = { start: Infinity, end: - Infinity };
  24998. var range = frameRanges[ name ];
  24999. if ( i < range.start ) range.start = i;
  25000. if ( i > range.end ) range.end = i;
  25001. if ( ! firstAnimation ) firstAnimation = name;
  25002. }
  25003. }
  25004. for ( var name in frameRanges ) {
  25005. var range = frameRanges[ name ];
  25006. this.createAnimation( name, range.start, range.end, fps );
  25007. }
  25008. this.firstAnimation = firstAnimation;
  25009. };
  25010. THREE.MorphBlendMesh.prototype.setAnimationDirectionForward = function ( name ) {
  25011. var animation = this.animationsMap[ name ];
  25012. if ( animation ) {
  25013. animation.direction = 1;
  25014. animation.directionBackwards = false;
  25015. }
  25016. };
  25017. THREE.MorphBlendMesh.prototype.setAnimationDirectionBackward = function ( name ) {
  25018. var animation = this.animationsMap[ name ];
  25019. if ( animation ) {
  25020. animation.direction = - 1;
  25021. animation.directionBackwards = true;
  25022. }
  25023. };
  25024. THREE.MorphBlendMesh.prototype.setAnimationFPS = function ( name, fps ) {
  25025. var animation = this.animationsMap[ name ];
  25026. if ( animation ) {
  25027. animation.fps = fps;
  25028. animation.duration = ( animation.end - animation.start ) / animation.fps;
  25029. }
  25030. };
  25031. THREE.MorphBlendMesh.prototype.setAnimationDuration = function ( name, duration ) {
  25032. var animation = this.animationsMap[ name ];
  25033. if ( animation ) {
  25034. animation.duration = duration;
  25035. animation.fps = ( animation.end - animation.start ) / animation.duration;
  25036. }
  25037. };
  25038. THREE.MorphBlendMesh.prototype.setAnimationWeight = function ( name, weight ) {
  25039. var animation = this.animationsMap[ name ];
  25040. if ( animation ) {
  25041. animation.weight = weight;
  25042. }
  25043. };
  25044. THREE.MorphBlendMesh.prototype.setAnimationTime = function ( name, time ) {
  25045. var animation = this.animationsMap[ name ];
  25046. if ( animation ) {
  25047. animation.time = time;
  25048. }
  25049. };
  25050. THREE.MorphBlendMesh.prototype.getAnimationTime = function ( name ) {
  25051. var time = 0;
  25052. var animation = this.animationsMap[ name ];
  25053. if ( animation ) {
  25054. time = animation.time;
  25055. }
  25056. return time;
  25057. };
  25058. THREE.MorphBlendMesh.prototype.getAnimationDuration = function ( name ) {
  25059. var duration = - 1;
  25060. var animation = this.animationsMap[ name ];
  25061. if ( animation ) {
  25062. duration = animation.duration;
  25063. }
  25064. return duration;
  25065. };
  25066. THREE.MorphBlendMesh.prototype.playAnimation = function ( name ) {
  25067. var animation = this.animationsMap[ name ];
  25068. if ( animation ) {
  25069. animation.time = 0;
  25070. animation.active = true;
  25071. } else {
  25072. console.warn( "THREE.MorphBlendMesh: animation[" + name + "] undefined in .playAnimation()" );
  25073. }
  25074. };
  25075. THREE.MorphBlendMesh.prototype.stopAnimation = function ( name ) {
  25076. var animation = this.animationsMap[ name ];
  25077. if ( animation ) {
  25078. animation.active = false;
  25079. }
  25080. };
  25081. THREE.MorphBlendMesh.prototype.update = function ( delta ) {
  25082. for ( var i = 0, il = this.animationsList.length; i < il; i ++ ) {
  25083. var animation = this.animationsList[ i ];
  25084. if ( ! animation.active ) continue;
  25085. var frameTime = animation.duration / animation.length;
  25086. animation.time += animation.direction * delta;
  25087. if ( animation.mirroredLoop ) {
  25088. if ( animation.time > animation.duration || animation.time < 0 ) {
  25089. animation.direction *= - 1;
  25090. if ( animation.time > animation.duration ) {
  25091. animation.time = animation.duration;
  25092. animation.directionBackwards = true;
  25093. }
  25094. if ( animation.time < 0 ) {
  25095. animation.time = 0;
  25096. animation.directionBackwards = false;
  25097. }
  25098. }
  25099. } else {
  25100. animation.time = animation.time % animation.duration;
  25101. if ( animation.time < 0 ) animation.time += animation.duration;
  25102. }
  25103. var keyframe = animation.start + THREE.Math.clamp( Math.floor( animation.time / frameTime ), 0, animation.length - 1 );
  25104. var weight = animation.weight;
  25105. if ( keyframe !== animation.currentFrame ) {
  25106. this.morphTargetInfluences[ animation.lastFrame ] = 0;
  25107. this.morphTargetInfluences[ animation.currentFrame ] = 1 * weight;
  25108. this.morphTargetInfluences[ keyframe ] = 0;
  25109. animation.lastFrame = animation.currentFrame;
  25110. animation.currentFrame = keyframe;
  25111. }
  25112. var mix = ( animation.time % frameTime ) / frameTime;
  25113. if ( animation.directionBackwards ) mix = 1 - mix;
  25114. if ( animation.currentFrame !== animation.lastFrame ) {
  25115. this.morphTargetInfluences[ animation.currentFrame ] = mix * weight;
  25116. this.morphTargetInfluences[ animation.lastFrame ] = ( 1 - mix ) * weight;
  25117. } else {
  25118. this.morphTargetInfluences[ animation.currentFrame ] = weight;
  25119. }
  25120. }
  25121. };